]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: fix for crash when no neighbor A.B.C.D remote-as AS_NUM with orr config
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_attr_evpn.h"
45 #include "bgpd/bgp_advertise.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_community_alias.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_debug.h"
54 #include "bgpd/bgp_errors.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_nht.h"
57 #include "bgpd/bgp_nexthop.h"
58 #include "bgpd/bgp_network.h"
59 #include "bgpd/bgp_open.h"
60 #include "bgpd/bgp_regex.h"
61 #include "bgpd/bgp_route.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_zebra.h"
64 #include "bgpd/bgp_table.h"
65 #include "bgpd/bgp_vty.h"
66 #include "bgpd/bgp_mpath.h"
67 #include "bgpd/bgp_packet.h"
68 #include "bgpd/bgp_updgrp.h"
69 #include "bgpd/bgp_bfd.h"
70 #include "bgpd/bgp_io.h"
71 #include "bgpd/bgp_evpn.h"
72 #include "bgpd/bgp_evpn_vty.h"
73 #include "bgpd/bgp_evpn_mh.h"
74 #include "bgpd/bgp_addpath.h"
75 #include "bgpd/bgp_mac.h"
76 #include "bgpd/bgp_flowspec.h"
77 #include "bgpd/bgp_conditional_adv.h"
78 #ifdef ENABLE_BGP_VNC
79 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
80 #endif
81 #include "bgpd/bgp_orr.h"
82
83
84 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
85 {
86 .val_bool = false,
87 .match_profile = "traditional",
88 .match_version = "< 7.4",
89 },
90 { .val_bool = true },
91 );
92 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
95 );
96 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
99 );
100 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
103 );
104 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
105 { .val_bool = true, .match_profile = "datacenter", },
106 { .val_bool = false },
107 );
108 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
109 { .val_ulong = 10, .match_profile = "datacenter", },
110 { .val_ulong = 120 },
111 );
112 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
113 { .val_ulong = 9, .match_profile = "datacenter", },
114 { .val_ulong = 180 },
115 );
116 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
117 { .val_ulong = 3, .match_profile = "datacenter", },
118 { .val_ulong = 60 },
119 );
120 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
121 { .val_bool = false, .match_profile = "datacenter", },
122 { .val_bool = false, .match_version = "< 7.4", },
123 { .val_bool = true },
124 );
125 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
126 { .val_bool = false, .match_version = "< 7.6", },
127 { .val_bool = true },
128 );
129 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
130 { .val_bool = false, .match_version = "< 8.3", },
131 { .val_bool = true },
132 );
133 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
134 { .val_bool = false, .match_version = "< 8.3", },
135 { .val_bool = true },
136 );
137
138 DEFINE_HOOK(bgp_inst_config_write,
139 (struct bgp *bgp, struct vty *vty),
140 (bgp, vty));
141 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
142 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
143
144 static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
146
147 /* Show BGP peer's information. */
148 enum show_type {
149 show_all,
150 show_peer,
151 show_ipv4_all,
152 show_ipv6_all,
153 show_ipv4_peer,
154 show_ipv6_peer
155 };
156
157 static struct peer_group *listen_range_exists(struct bgp *bgp,
158 struct prefix *range, int exact);
159
160 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
161 struct bgp *bgp,
162 bool use_json,
163 json_object *json);
164
165 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
166 enum show_type type,
167 const char *ip_str,
168 afi_t afi, bool use_json);
169
170 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
171 {
172 switch (afi) {
173 case AFI_IP:
174 switch (safi) {
175 case SAFI_UNICAST:
176 return BGP_IPV4_NODE;
177 case SAFI_MULTICAST:
178 return BGP_IPV4M_NODE;
179 case SAFI_LABELED_UNICAST:
180 return BGP_IPV4L_NODE;
181 case SAFI_MPLS_VPN:
182 return BGP_VPNV4_NODE;
183 case SAFI_FLOWSPEC:
184 return BGP_FLOWSPECV4_NODE;
185 default:
186 /* not expected */
187 return BGP_IPV4_NODE;
188 }
189 case AFI_IP6:
190 switch (safi) {
191 case SAFI_UNICAST:
192 return BGP_IPV6_NODE;
193 case SAFI_MULTICAST:
194 return BGP_IPV6M_NODE;
195 case SAFI_LABELED_UNICAST:
196 return BGP_IPV6L_NODE;
197 case SAFI_MPLS_VPN:
198 return BGP_VPNV6_NODE;
199 case SAFI_FLOWSPEC:
200 return BGP_FLOWSPECV6_NODE;
201 default:
202 /* not expected */
203 return BGP_IPV4_NODE;
204 }
205 case AFI_L2VPN:
206 return BGP_EVPN_NODE;
207 case AFI_UNSPEC:
208 case AFI_MAX:
209 // We should never be here but to clarify the switch statement..
210 return BGP_IPV4_NODE;
211 }
212
213 // Impossible to happen
214 return BGP_IPV4_NODE;
215 }
216
217 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
218 {
219 if (afi == AFI_IP) {
220 if (safi == SAFI_UNICAST)
221 return "IPv4 Unicast";
222 if (safi == SAFI_MULTICAST)
223 return "IPv4 Multicast";
224 if (safi == SAFI_LABELED_UNICAST)
225 return "IPv4 Labeled Unicast";
226 if (safi == SAFI_MPLS_VPN)
227 return "IPv4 VPN";
228 if (safi == SAFI_ENCAP)
229 return "IPv4 Encap";
230 if (safi == SAFI_FLOWSPEC)
231 return "IPv4 Flowspec";
232 } else if (afi == AFI_IP6) {
233 if (safi == SAFI_UNICAST)
234 return "IPv6 Unicast";
235 if (safi == SAFI_MULTICAST)
236 return "IPv6 Multicast";
237 if (safi == SAFI_LABELED_UNICAST)
238 return "IPv6 Labeled Unicast";
239 if (safi == SAFI_MPLS_VPN)
240 return "IPv6 VPN";
241 if (safi == SAFI_ENCAP)
242 return "IPv6 Encap";
243 if (safi == SAFI_FLOWSPEC)
244 return "IPv6 Flowspec";
245 } else if (afi == AFI_L2VPN) {
246 if (safi == SAFI_EVPN)
247 return "L2VPN EVPN";
248 }
249
250 return "Unknown";
251 }
252
253 /*
254 * Please note that we have intentionally camelCased
255 * the return strings here. So if you want
256 * to use this function, please ensure you
257 * are doing this within json output
258 */
259 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
260 {
261 if (afi == AFI_IP) {
262 if (safi == SAFI_UNICAST)
263 return "ipv4Unicast";
264 if (safi == SAFI_MULTICAST)
265 return "ipv4Multicast";
266 if (safi == SAFI_LABELED_UNICAST)
267 return "ipv4LabeledUnicast";
268 if (safi == SAFI_MPLS_VPN)
269 return "ipv4Vpn";
270 if (safi == SAFI_ENCAP)
271 return "ipv4Encap";
272 if (safi == SAFI_FLOWSPEC)
273 return "ipv4Flowspec";
274 } else if (afi == AFI_IP6) {
275 if (safi == SAFI_UNICAST)
276 return "ipv6Unicast";
277 if (safi == SAFI_MULTICAST)
278 return "ipv6Multicast";
279 if (safi == SAFI_LABELED_UNICAST)
280 return "ipv6LabeledUnicast";
281 if (safi == SAFI_MPLS_VPN)
282 return "ipv6Vpn";
283 if (safi == SAFI_ENCAP)
284 return "ipv6Encap";
285 if (safi == SAFI_FLOWSPEC)
286 return "ipv6Flowspec";
287 } else if (afi == AFI_L2VPN) {
288 if (safi == SAFI_EVPN)
289 return "l2VpnEvpn";
290 }
291
292 return "Unknown";
293 }
294
295 /* unset srv6 locator */
296 static int bgp_srv6_locator_unset(struct bgp *bgp)
297 {
298 int ret;
299 struct listnode *node, *nnode;
300 struct srv6_locator_chunk *chunk;
301 struct bgp_srv6_function *func;
302 struct bgp *bgp_vrf;
303
304 /* release chunk notification via ZAPI */
305 ret = bgp_zebra_srv6_manager_release_locator_chunk(
306 bgp->srv6_locator_name);
307 if (ret < 0)
308 return -1;
309
310 /* refresh chunks */
311 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
312 listnode_delete(bgp->srv6_locator_chunks, chunk);
313 srv6_locator_chunk_free(chunk);
314 }
315
316 /* refresh functions */
317 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
318 listnode_delete(bgp->srv6_functions, func);
319 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
320 }
321
322 /* refresh tovpn_sid */
323 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
324 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
325 continue;
326
327 /* refresh vpnv4 tovpn_sid */
328 XFREE(MTYPE_BGP_SRV6_SID,
329 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
330
331 /* refresh vpnv6 tovpn_sid */
332 XFREE(MTYPE_BGP_SRV6_SID,
333 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
334 }
335
336 /* update vpn bgp processes */
337 vpn_leak_postchange_all();
338
339 /* refresh tovpn_sid_locator */
340 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
341 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
342 continue;
343
344 /* refresh vpnv4 tovpn_sid_locator */
345 XFREE(MTYPE_BGP_SRV6_SID,
346 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
347
348 /* refresh vpnv6 tovpn_sid_locator */
349 XFREE(MTYPE_BGP_SRV6_SID,
350 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
351 }
352
353 /* clear locator name */
354 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
355
356 return 0;
357 }
358
359 /* Utility function to get address family from current node. */
360 afi_t bgp_node_afi(struct vty *vty)
361 {
362 afi_t afi;
363 switch (vty->node) {
364 case BGP_IPV6_NODE:
365 case BGP_IPV6M_NODE:
366 case BGP_IPV6L_NODE:
367 case BGP_VPNV6_NODE:
368 case BGP_FLOWSPECV6_NODE:
369 afi = AFI_IP6;
370 break;
371 case BGP_EVPN_NODE:
372 afi = AFI_L2VPN;
373 break;
374 default:
375 afi = AFI_IP;
376 break;
377 }
378 return afi;
379 }
380
381 /* Utility function to get subsequent address family from current
382 node. */
383 safi_t bgp_node_safi(struct vty *vty)
384 {
385 safi_t safi;
386 switch (vty->node) {
387 case BGP_VPNV4_NODE:
388 case BGP_VPNV6_NODE:
389 safi = SAFI_MPLS_VPN;
390 break;
391 case BGP_IPV4M_NODE:
392 case BGP_IPV6M_NODE:
393 safi = SAFI_MULTICAST;
394 break;
395 case BGP_EVPN_NODE:
396 safi = SAFI_EVPN;
397 break;
398 case BGP_IPV4L_NODE:
399 case BGP_IPV6L_NODE:
400 safi = SAFI_LABELED_UNICAST;
401 break;
402 case BGP_FLOWSPECV4_NODE:
403 case BGP_FLOWSPECV6_NODE:
404 safi = SAFI_FLOWSPEC;
405 break;
406 default:
407 safi = SAFI_UNICAST;
408 break;
409 }
410 return safi;
411 }
412
413 /**
414 * Converts an AFI in string form to afi_t
415 *
416 * @param afi string, one of
417 * - "ipv4"
418 * - "ipv6"
419 * - "l2vpn"
420 * @return the corresponding afi_t
421 */
422 afi_t bgp_vty_afi_from_str(const char *afi_str)
423 {
424 afi_t afi = AFI_MAX; /* unknown */
425 if (strmatch(afi_str, "ipv4"))
426 afi = AFI_IP;
427 else if (strmatch(afi_str, "ipv6"))
428 afi = AFI_IP6;
429 else if (strmatch(afi_str, "l2vpn"))
430 afi = AFI_L2VPN;
431 return afi;
432 }
433
434 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
435 afi_t *afi)
436 {
437 int ret = 0;
438 if (argv_find(argv, argc, "ipv4", index)) {
439 ret = 1;
440 if (afi)
441 *afi = AFI_IP;
442 } else if (argv_find(argv, argc, "ipv6", index)) {
443 ret = 1;
444 if (afi)
445 *afi = AFI_IP6;
446 } else if (argv_find(argv, argc, "l2vpn", index)) {
447 ret = 1;
448 if (afi)
449 *afi = AFI_L2VPN;
450 }
451 return ret;
452 }
453
454 /* supports <unicast|multicast|vpn|labeled-unicast> */
455 safi_t bgp_vty_safi_from_str(const char *safi_str)
456 {
457 safi_t safi = SAFI_MAX; /* unknown */
458 if (strmatch(safi_str, "multicast"))
459 safi = SAFI_MULTICAST;
460 else if (strmatch(safi_str, "unicast"))
461 safi = SAFI_UNICAST;
462 else if (strmatch(safi_str, "vpn"))
463 safi = SAFI_MPLS_VPN;
464 else if (strmatch(safi_str, "evpn"))
465 safi = SAFI_EVPN;
466 else if (strmatch(safi_str, "labeled-unicast"))
467 safi = SAFI_LABELED_UNICAST;
468 else if (strmatch(safi_str, "flowspec"))
469 safi = SAFI_FLOWSPEC;
470 return safi;
471 }
472
473 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
474 safi_t *safi)
475 {
476 int ret = 0;
477 if (argv_find(argv, argc, "unicast", index)) {
478 ret = 1;
479 if (safi)
480 *safi = SAFI_UNICAST;
481 } else if (argv_find(argv, argc, "multicast", index)) {
482 ret = 1;
483 if (safi)
484 *safi = SAFI_MULTICAST;
485 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
486 ret = 1;
487 if (safi)
488 *safi = SAFI_LABELED_UNICAST;
489 } else if (argv_find(argv, argc, "vpn", index)) {
490 ret = 1;
491 if (safi)
492 *safi = SAFI_MPLS_VPN;
493 } else if (argv_find(argv, argc, "evpn", index)) {
494 ret = 1;
495 if (safi)
496 *safi = SAFI_EVPN;
497 } else if (argv_find(argv, argc, "flowspec", index)) {
498 ret = 1;
499 if (safi)
500 *safi = SAFI_FLOWSPEC;
501 }
502 return ret;
503 }
504
505 /*
506 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
507 *
508 * afi
509 * address-family identifier
510 *
511 * safi
512 * subsequent address-family identifier
513 *
514 * Returns:
515 * default_af string corresponding to the supplied afi/safi pair.
516 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
517 * return -1.
518 */
519 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
520 {
521 switch (afi) {
522 case AFI_IP:
523 switch (safi) {
524 case SAFI_UNICAST:
525 return "ipv4-unicast";
526 case SAFI_MULTICAST:
527 return "ipv4-multicast";
528 case SAFI_MPLS_VPN:
529 return "ipv4-vpn";
530 case SAFI_ENCAP:
531 return "ipv4-encap";
532 case SAFI_LABELED_UNICAST:
533 return "ipv4-labeled-unicast";
534 case SAFI_FLOWSPEC:
535 return "ipv4-flowspec";
536 default:
537 return "unknown-afi/safi";
538 }
539 break;
540 case AFI_IP6:
541 switch (safi) {
542 case SAFI_UNICAST:
543 return "ipv6-unicast";
544 case SAFI_MULTICAST:
545 return "ipv6-multicast";
546 case SAFI_MPLS_VPN:
547 return "ipv6-vpn";
548 case SAFI_ENCAP:
549 return "ipv6-encap";
550 case SAFI_LABELED_UNICAST:
551 return "ipv6-labeled-unicast";
552 case SAFI_FLOWSPEC:
553 return "ipv6-flowspec";
554 default:
555 return "unknown-afi/safi";
556 }
557 break;
558 case AFI_L2VPN:
559 switch (safi) {
560 case SAFI_EVPN:
561 return "l2vpn-evpn";
562 default:
563 return "unknown-afi/safi";
564 }
565 case AFI_UNSPEC:
566 case AFI_MAX:
567 return "unknown-afi/safi";
568 }
569 /* all AFIs are accounted for above, so this shouldn't happen */
570 return "unknown-afi/safi";
571 }
572
573 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
574 enum bgp_instance_type inst_type)
575 {
576 int ret = bgp_get(bgp, as, name, inst_type);
577
578 if (ret == BGP_CREATED) {
579 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
580 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
581
582 if (DFLT_BGP_IMPORT_CHECK)
583 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
584 if (DFLT_BGP_SHOW_HOSTNAME)
585 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
586 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
587 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
588 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
589 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
590 if (DFLT_BGP_DETERMINISTIC_MED)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
592 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
594 if (DFLT_BGP_SUPPRESS_DUPLICATES)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
596 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
598 if (DFLT_BGP_HARD_ADMIN_RESET)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
600
601 ret = BGP_SUCCESS;
602 }
603 return ret;
604 }
605
606 /*
607 * bgp_vty_find_and_parse_afi_safi_bgp
608 *
609 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
610 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
611 * to appropriate values for the calling function. This is to allow the
612 * calling function to make decisions appropriate for the show command
613 * that is being parsed.
614 *
615 * The show commands are generally of the form:
616 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
617 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
618 *
619 * Since we use argv_find if the show command in particular doesn't have:
620 * [ip]
621 * [<view|vrf> VIEWVRFNAME]
622 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
623 * The command parsing should still be ok.
624 *
625 * vty -> The vty for the command so we can output some useful data in
626 * the event of a parse error in the vrf.
627 * argv -> The command tokens
628 * argc -> How many command tokens we have
629 * idx -> The current place in the command, generally should be 0 for this
630 * function
631 * afi -> The parsed afi if it was included in the show command, returned here
632 * safi -> The parsed safi if it was included in the show command, returned here
633 * bgp -> Pointer to the bgp data structure we need to fill in.
634 * use_json -> json is configured or not
635 *
636 * The function returns the correct location in the parse tree for the
637 * last token found.
638 *
639 * Returns 0 for failure to parse correctly, else the idx position of where
640 * it found the last token.
641 */
642 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
643 struct cmd_token **argv, int argc,
644 int *idx, afi_t *afi, safi_t *safi,
645 struct bgp **bgp, bool use_json)
646 {
647 char *vrf_name = NULL;
648
649 assert(afi);
650 assert(safi);
651 assert(bgp);
652
653 if (argv_find(argv, argc, "ip", idx))
654 *afi = AFI_IP;
655
656 if (argv_find(argv, argc, "view", idx))
657 vrf_name = argv[*idx + 1]->arg;
658 else if (argv_find(argv, argc, "vrf", idx)) {
659 vrf_name = argv[*idx + 1]->arg;
660 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
661 vrf_name = NULL;
662 }
663 if (vrf_name) {
664 if (strmatch(vrf_name, "all"))
665 *bgp = NULL;
666 else {
667 *bgp = bgp_lookup_by_name(vrf_name);
668 if (!*bgp) {
669 if (use_json) {
670 json_object *json = NULL;
671 json = json_object_new_object();
672 json_object_string_add(
673 json, "warning",
674 "View/Vrf is unknown");
675 vty_json(vty, json);
676 }
677 else
678 vty_out(vty, "View/Vrf %s is unknown\n",
679 vrf_name);
680 *idx = 0;
681 return 0;
682 }
683 }
684 } else {
685 *bgp = bgp_get_default();
686 if (!*bgp) {
687 if (use_json) {
688 json_object *json = NULL;
689 json = json_object_new_object();
690 json_object_string_add(
691 json, "warning",
692 "Default BGP instance not found");
693 vty_json(vty, json);
694 }
695 else
696 vty_out(vty,
697 "Default BGP instance not found\n");
698 *idx = 0;
699 return 0;
700 }
701 }
702
703 if (argv_find_and_parse_afi(argv, argc, idx, afi))
704 argv_find_and_parse_safi(argv, argc, idx, safi);
705
706 *idx += 1;
707 return *idx;
708 }
709
710 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
711 {
712 struct interface *ifp = NULL;
713 struct listnode *node;
714 struct bgp_listener *listener;
715 union sockunion all_su;
716
717 if (su->sa.sa_family == AF_INET) {
718 (void)str2sockunion("0.0.0.0", &all_su);
719 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
720 } else if (su->sa.sa_family == AF_INET6) {
721 (void)str2sockunion("::", &all_su);
722 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
723 su->sin6.sin6_scope_id,
724 bgp->vrf_id);
725 }
726
727 if (ifp) {
728 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
729 if (sockunion_family(su) !=
730 sockunion_family(&listener->su))
731 continue;
732
733 /* If 0.0.0.0/:: is a listener, then treat as self and
734 * reject.
735 */
736 if (!sockunion_cmp(&listener->su, su) ||
737 !sockunion_cmp(&listener->su, &all_su))
738 return true;
739 }
740 }
741
742 return false;
743 }
744
745 /* Utility function for looking up peer from VTY. */
746 /* This is used only for configuration, so disallow if attempted on
747 * a dynamic neighbor.
748 */
749 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
750 {
751 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
752 int ret;
753 union sockunion su;
754 struct peer *peer;
755
756 if (!bgp) {
757 return NULL;
758 }
759
760 ret = str2sockunion(ip_str, &su);
761 if (ret < 0) {
762 peer = peer_lookup_by_conf_if(bgp, ip_str);
763 if (!peer) {
764 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
765 == NULL) {
766 vty_out(vty,
767 "%% Malformed address or name: %s\n",
768 ip_str);
769 return NULL;
770 }
771 }
772 } else {
773 peer = peer_lookup(bgp, &su);
774 if (!peer) {
775 vty_out(vty,
776 "%% Specify remote-as or peer-group commands first\n");
777 return NULL;
778 }
779 if (peer_dynamic_neighbor(peer)) {
780 vty_out(vty,
781 "%% Operation not allowed on a dynamic neighbor\n");
782 return NULL;
783 }
784 }
785 return peer;
786 }
787
788 /* Utility function for looking up peer or peer group. */
789 /* This is used only for configuration, so disallow if attempted on
790 * a dynamic neighbor.
791 */
792 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
793 {
794 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
795 int ret;
796 union sockunion su;
797 struct peer *peer = NULL;
798 struct peer_group *group = NULL;
799
800 if (!bgp) {
801 return NULL;
802 }
803
804 ret = str2sockunion(peer_str, &su);
805 if (ret == 0) {
806 /* IP address, locate peer. */
807 peer = peer_lookup(bgp, &su);
808 } else {
809 /* Not IP, could match either peer configured on interface or a
810 * group. */
811 peer = peer_lookup_by_conf_if(bgp, peer_str);
812 if (!peer)
813 group = peer_group_lookup(bgp, peer_str);
814 }
815
816 if (peer) {
817 if (peer_dynamic_neighbor(peer)) {
818 vty_out(vty,
819 "%% Operation not allowed on a dynamic neighbor\n");
820 return NULL;
821 }
822
823 return peer;
824 }
825
826 if (group)
827 return group->conf;
828
829 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
830
831 return NULL;
832 }
833
834 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
835 {
836 const char *str = NULL;
837
838 switch (ret) {
839 case BGP_SUCCESS:
840 case BGP_CREATED:
841 case BGP_GR_NO_OPERATION:
842 break;
843 case BGP_ERR_INVALID_VALUE:
844 str = "Invalid value";
845 break;
846 case BGP_ERR_INVALID_FLAG:
847 str = "Invalid flag";
848 break;
849 case BGP_ERR_PEER_GROUP_SHUTDOWN:
850 str = "Peer-group has been shutdown. Activate the peer-group first";
851 break;
852 case BGP_ERR_PEER_FLAG_CONFLICT:
853 str = "Can't set override-capability and strict-capability-match at the same time";
854 break;
855 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
856 str = "Specify remote-as or peer-group remote AS first";
857 break;
858 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
859 str = "Cannot change the peer-group. Deconfigure first";
860 break;
861 case BGP_ERR_PEER_GROUP_MISMATCH:
862 str = "Peer is not a member of this peer-group";
863 break;
864 case BGP_ERR_PEER_FILTER_CONFLICT:
865 str = "Prefix/distribute list can not co-exist";
866 break;
867 case BGP_ERR_NOT_INTERNAL_PEER:
868 str = "Invalid command. Not an internal neighbor";
869 break;
870 case BGP_ERR_REMOVE_PRIVATE_AS:
871 str = "remove-private-AS cannot be configured for IBGP peers";
872 break;
873 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
874 str = "Cannot have local-as same as BGP AS number";
875 break;
876 case BGP_ERR_TCPSIG_FAILED:
877 str = "Error while applying TCP-Sig to session(s)";
878 break;
879 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
880 str = "ebgp-multihop and ttl-security cannot be configured together";
881 break;
882 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
883 str = "ttl-security only allowed for EBGP peers";
884 break;
885 case BGP_ERR_AS_OVERRIDE:
886 str = "as-override cannot be configured for IBGP peers";
887 break;
888 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
889 str = "Invalid limit for number of dynamic neighbors";
890 break;
891 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
892 str = "Dynamic neighbor listen range already exists";
893 break;
894 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
895 str = "Operation not allowed on a dynamic neighbor";
896 break;
897 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
898 str = "Operation not allowed on a directly connected neighbor";
899 break;
900 case BGP_ERR_PEER_SAFI_CONFLICT:
901 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
902 break;
903 case BGP_ERR_GR_INVALID_CMD:
904 str = "The Graceful Restart command used is not valid at this moment.";
905 break;
906 case BGP_ERR_GR_OPERATION_FAILED:
907 str = "The Graceful Restart Operation failed due to an err.";
908 break;
909 case BGP_ERR_PEER_GROUP_MEMBER:
910 str = "Peer-group member cannot override remote-as of peer-group.";
911 break;
912 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
913 str = "Peer-group members must be all internal or all external.";
914 break;
915 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
916 str = "Range specified cannot be deleted because it is not part of current config.";
917 break;
918 case BGP_ERR_INSTANCE_MISMATCH:
919 str = "Instance specified does not match the current instance.";
920 break;
921 case BGP_ERR_NO_INTERFACE_CONFIG:
922 str = "Interface specified is not being used for interface based peer.";
923 break;
924 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
925 str = "No configuration already specified for soft reconfiguration.";
926 break;
927 case BGP_ERR_AS_MISMATCH:
928 str = "BGP is already running.";
929 break;
930 case BGP_ERR_AF_UNCONFIGURED:
931 str = "AFI/SAFI specified is not currently configured.";
932 break;
933 case BGP_ERR_INVALID_AS:
934 str = "Confederation AS specified is the same AS as our AS.";
935 break;
936 case BGP_ERR_INVALID_ROLE_NAME:
937 str = "Invalid role name";
938 break;
939 case BGP_ERR_INVALID_INTERNAL_ROLE:
940 str = "External roles can be set only on eBGP session";
941 break;
942 case BGP_ERR_PEER_ORR_CONFIGURED:
943 str = "Deconfigure optimal-route-reflection on this peer first";
944 break;
945 }
946 if (str) {
947 vty_out(vty, "%% %s\n", str);
948 return CMD_WARNING_CONFIG_FAILED;
949 }
950 return CMD_SUCCESS;
951 }
952
953 /* BGP clear sort. */
954 enum clear_sort {
955 clear_all,
956 clear_peer,
957 clear_group,
958 clear_external,
959 clear_as
960 };
961
962 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
963 safi_t safi, int error)
964 {
965 switch (error) {
966 case BGP_ERR_AF_UNCONFIGURED:
967 if (vty)
968 vty_out(vty,
969 "%% BGP: Enable %s address family for the neighbor %s\n",
970 get_afi_safi_str(afi, safi, false), peer->host);
971 else
972 zlog_warn(
973 "%% BGP: Enable %s address family for the neighbor %s",
974 get_afi_safi_str(afi, safi, false), peer->host);
975 break;
976 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
977 if (vty)
978 vty_out(vty,
979 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
980 peer->host);
981 else
982 zlog_warn(
983 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
984 peer->host);
985 break;
986 default:
987 break;
988 }
989 }
990
991 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
992 struct listnode **nnode, enum bgp_clear_type stype)
993 {
994 int ret = 0;
995 struct peer_af *paf;
996
997 /* if afi/.safi not specified, spin thru all of them */
998 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
999 afi_t tmp_afi;
1000 safi_t tmp_safi;
1001 enum bgp_af_index index;
1002
1003 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1004 paf = peer->peer_af_array[index];
1005 if (!paf)
1006 continue;
1007
1008 if (paf && paf->subgroup)
1009 SET_FLAG(paf->subgroup->sflags,
1010 SUBGRP_STATUS_FORCE_UPDATES);
1011
1012 tmp_afi = paf->afi;
1013 tmp_safi = paf->safi;
1014 if (!peer->afc[tmp_afi][tmp_safi])
1015 continue;
1016
1017 if (stype == BGP_CLEAR_SOFT_NONE)
1018 ret = peer_clear(peer, nnode);
1019 else
1020 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1021 stype);
1022 }
1023 /* if afi specified and safi not, spin thru safis on this afi */
1024 } else if (safi == SAFI_UNSPEC) {
1025 safi_t tmp_safi;
1026
1027 for (tmp_safi = SAFI_UNICAST;
1028 tmp_safi < SAFI_MAX; tmp_safi++) {
1029 if (!peer->afc[afi][tmp_safi])
1030 continue;
1031
1032 paf = peer_af_find(peer, afi, tmp_safi);
1033 if (paf && paf->subgroup)
1034 SET_FLAG(paf->subgroup->sflags,
1035 SUBGRP_STATUS_FORCE_UPDATES);
1036
1037 if (stype == BGP_CLEAR_SOFT_NONE)
1038 ret = peer_clear(peer, nnode);
1039 else
1040 ret = peer_clear_soft(peer, afi,
1041 tmp_safi, stype);
1042 }
1043 /* both afi/safi specified, let the caller know if not defined */
1044 } else {
1045 if (!peer->afc[afi][safi])
1046 return 1;
1047
1048 paf = peer_af_find(peer, afi, safi);
1049 if (paf && paf->subgroup)
1050 SET_FLAG(paf->subgroup->sflags,
1051 SUBGRP_STATUS_FORCE_UPDATES);
1052
1053 if (stype == BGP_CLEAR_SOFT_NONE)
1054 ret = peer_clear(peer, nnode);
1055 else
1056 ret = peer_clear_soft(peer, afi, safi, stype);
1057 }
1058
1059 return ret;
1060 }
1061
1062 /* `clear ip bgp' functions. */
1063 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1064 enum clear_sort sort, enum bgp_clear_type stype,
1065 const char *arg)
1066 {
1067 int ret = 0;
1068 bool found = false;
1069 struct peer *peer;
1070
1071 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1072
1073 /* Clear all neighbors. */
1074 /*
1075 * Pass along pointer to next node to peer_clear() when walking all
1076 * nodes on the BGP instance as that may get freed if it is a
1077 * doppelganger
1078 */
1079 if (sort == clear_all) {
1080 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1081
1082 bgp_peer_gr_flags_update(peer);
1083
1084 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1085 gr_router_detected = true;
1086
1087 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1088 stype);
1089
1090 if (ret < 0)
1091 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1092 }
1093
1094 if (gr_router_detected
1095 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1096 bgp_zebra_send_capabilities(bgp, false);
1097 } else if (!gr_router_detected
1098 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1099 bgp_zebra_send_capabilities(bgp, true);
1100 }
1101
1102 /* This is to apply read-only mode on this clear. */
1103 if (stype == BGP_CLEAR_SOFT_NONE)
1104 bgp->update_delay_over = 0;
1105
1106 return CMD_SUCCESS;
1107 }
1108
1109 /* Clear specified neighbor. */
1110 if (sort == clear_peer) {
1111 union sockunion su;
1112
1113 /* Make sockunion for lookup. */
1114 ret = str2sockunion(arg, &su);
1115 if (ret < 0) {
1116 peer = peer_lookup_by_conf_if(bgp, arg);
1117 if (!peer) {
1118 peer = peer_lookup_by_hostname(bgp, arg);
1119 if (!peer) {
1120 vty_out(vty,
1121 "Malformed address or name: %s\n",
1122 arg);
1123 return CMD_WARNING;
1124 }
1125 }
1126 } else {
1127 peer = peer_lookup(bgp, &su);
1128 if (!peer) {
1129 vty_out(vty,
1130 "%% BGP: Unknown neighbor - \"%s\"\n",
1131 arg);
1132 return CMD_WARNING;
1133 }
1134 }
1135
1136 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1137 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1138
1139 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1140
1141 /* if afi/safi not defined for this peer, let caller know */
1142 if (ret == 1)
1143 ret = BGP_ERR_AF_UNCONFIGURED;
1144
1145 if (ret < 0)
1146 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1147
1148 return CMD_SUCCESS;
1149 }
1150
1151 /* Clear all neighbors belonging to a specific peer-group. */
1152 if (sort == clear_group) {
1153 struct peer_group *group;
1154
1155 group = peer_group_lookup(bgp, arg);
1156 if (!group) {
1157 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1158 return CMD_WARNING;
1159 }
1160
1161 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1162 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1163
1164 if (ret < 0)
1165 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1166 else
1167 found = true;
1168 }
1169
1170 if (!found)
1171 vty_out(vty,
1172 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1173 get_afi_safi_str(afi, safi, false), arg);
1174
1175 return CMD_SUCCESS;
1176 }
1177
1178 /* Clear all external (eBGP) neighbors. */
1179 if (sort == clear_external) {
1180 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1181 if (peer->sort == BGP_PEER_IBGP)
1182 continue;
1183
1184 bgp_peer_gr_flags_update(peer);
1185
1186 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1187 gr_router_detected = true;
1188
1189 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1190
1191 if (ret < 0)
1192 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1193 else
1194 found = true;
1195 }
1196
1197 if (gr_router_detected
1198 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1199 bgp_zebra_send_capabilities(bgp, false);
1200 } else if (!gr_router_detected
1201 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1202 bgp_zebra_send_capabilities(bgp, true);
1203 }
1204
1205 if (!found)
1206 vty_out(vty,
1207 "%% BGP: No external %s peer is configured\n",
1208 get_afi_safi_str(afi, safi, false));
1209
1210 return CMD_SUCCESS;
1211 }
1212
1213 /* Clear all neighbors belonging to a specific AS. */
1214 if (sort == clear_as) {
1215 as_t as = strtoul(arg, NULL, 10);
1216
1217 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1218 if (peer->as != as)
1219 continue;
1220
1221 bgp_peer_gr_flags_update(peer);
1222
1223 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1224 gr_router_detected = true;
1225
1226 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1227
1228 if (ret < 0)
1229 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1230 else
1231 found = true;
1232 }
1233
1234 if (gr_router_detected
1235 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1236 bgp_zebra_send_capabilities(bgp, false);
1237 } else if (!gr_router_detected
1238 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1239 bgp_zebra_send_capabilities(bgp, true);
1240 }
1241
1242 if (!found)
1243 vty_out(vty,
1244 "%% BGP: No %s peer is configured with AS %s\n",
1245 get_afi_safi_str(afi, safi, false), arg);
1246
1247 return CMD_SUCCESS;
1248 }
1249
1250 return CMD_SUCCESS;
1251 }
1252
1253 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1254 safi_t safi, enum clear_sort sort,
1255 enum bgp_clear_type stype, const char *arg)
1256 {
1257 struct bgp *bgp;
1258
1259 /* BGP structure lookup. */
1260 if (name) {
1261 bgp = bgp_lookup_by_name(name);
1262 if (bgp == NULL) {
1263 vty_out(vty, "Can't find BGP instance %s\n", name);
1264 return CMD_WARNING;
1265 }
1266 } else {
1267 bgp = bgp_get_default();
1268 if (bgp == NULL) {
1269 vty_out(vty, "No BGP process is configured\n");
1270 return CMD_WARNING;
1271 }
1272 }
1273
1274 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1275 }
1276
1277 /* clear soft inbound */
1278 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1279 {
1280 afi_t afi;
1281 safi_t safi;
1282
1283 FOREACH_AFI_SAFI (afi, safi)
1284 bgp_clear_vty(vty, name, afi, safi, clear_all,
1285 BGP_CLEAR_SOFT_IN, NULL);
1286 }
1287
1288 /* clear soft outbound */
1289 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1290 {
1291 afi_t afi;
1292 safi_t safi;
1293
1294 FOREACH_AFI_SAFI (afi, safi)
1295 bgp_clear_vty(vty, name, afi, safi, clear_all,
1296 BGP_CLEAR_SOFT_OUT, NULL);
1297 }
1298
1299
1300 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1301 {
1302 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1303 }
1304
1305 #ifndef VTYSH_EXTRACT_PL
1306 #include "bgpd/bgp_vty_clippy.c"
1307 #endif
1308
1309 DEFUN_HIDDEN (bgp_local_mac,
1310 bgp_local_mac_cmd,
1311 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1312 BGP_STR
1313 "Local MAC config\n"
1314 "VxLAN Network Identifier\n"
1315 "VNI number\n"
1316 "local mac\n"
1317 "mac address\n"
1318 "mac-mobility sequence\n"
1319 "seq number\n")
1320 {
1321 int rv;
1322 vni_t vni;
1323 struct ethaddr mac;
1324 struct ipaddr ip;
1325 uint32_t seq;
1326 struct bgp *bgp;
1327
1328 vni = strtoul(argv[3]->arg, NULL, 10);
1329 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1330 vty_out(vty, "%% Malformed MAC address\n");
1331 return CMD_WARNING;
1332 }
1333 memset(&ip, 0, sizeof(ip));
1334 seq = strtoul(argv[7]->arg, NULL, 10);
1335
1336 bgp = bgp_get_default();
1337 if (!bgp) {
1338 vty_out(vty, "Default BGP instance is not there\n");
1339 return CMD_WARNING;
1340 }
1341
1342 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1343 zero_esi);
1344 if (rv < 0) {
1345 vty_out(vty, "Internal error\n");
1346 return CMD_WARNING;
1347 }
1348
1349 return CMD_SUCCESS;
1350 }
1351
1352 DEFUN_HIDDEN (no_bgp_local_mac,
1353 no_bgp_local_mac_cmd,
1354 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1355 NO_STR
1356 BGP_STR
1357 "Local MAC config\n"
1358 "VxLAN Network Identifier\n"
1359 "VNI number\n"
1360 "local mac\n"
1361 "mac address\n")
1362 {
1363 int rv;
1364 vni_t vni;
1365 struct ethaddr mac;
1366 struct ipaddr ip;
1367 struct bgp *bgp;
1368
1369 vni = strtoul(argv[4]->arg, NULL, 10);
1370 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1371 vty_out(vty, "%% Malformed MAC address\n");
1372 return CMD_WARNING;
1373 }
1374 memset(&ip, 0, sizeof(ip));
1375
1376 bgp = bgp_get_default();
1377 if (!bgp) {
1378 vty_out(vty, "Default BGP instance is not there\n");
1379 return CMD_WARNING;
1380 }
1381
1382 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1383 if (rv < 0) {
1384 vty_out(vty, "Internal error\n");
1385 return CMD_WARNING;
1386 }
1387
1388 return CMD_SUCCESS;
1389 }
1390
1391 DEFUN (no_synchronization,
1392 no_synchronization_cmd,
1393 "no synchronization",
1394 NO_STR
1395 "Perform IGP synchronization\n")
1396 {
1397 return CMD_SUCCESS;
1398 }
1399
1400 DEFUN (no_auto_summary,
1401 no_auto_summary_cmd,
1402 "no auto-summary",
1403 NO_STR
1404 "Enable automatic network number summarization\n")
1405 {
1406 return CMD_SUCCESS;
1407 }
1408
1409 /* "router bgp" commands. */
1410 DEFUN_NOSH (router_bgp,
1411 router_bgp_cmd,
1412 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1413 ROUTER_STR
1414 BGP_STR
1415 AS_STR
1416 BGP_INSTANCE_HELP_STR)
1417 {
1418 int idx_asn = 2;
1419 int idx_view_vrf = 3;
1420 int idx_vrf = 4;
1421 int is_new_bgp = 0;
1422 int ret;
1423 as_t as;
1424 struct bgp *bgp;
1425 const char *name = NULL;
1426 enum bgp_instance_type inst_type;
1427
1428 // "router bgp" without an ASN
1429 if (argc == 2) {
1430 // Pending: Make VRF option available for ASN less config
1431 bgp = bgp_get_default();
1432
1433 if (bgp == NULL) {
1434 vty_out(vty, "%% No BGP process is configured\n");
1435 return CMD_WARNING_CONFIG_FAILED;
1436 }
1437
1438 if (listcount(bm->bgp) > 1) {
1439 vty_out(vty, "%% Please specify ASN and VRF\n");
1440 return CMD_WARNING_CONFIG_FAILED;
1441 }
1442 }
1443
1444 // "router bgp X"
1445 else {
1446 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1447
1448 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1449 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1450 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1451
1452 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1453 if (argc > 3) {
1454 name = argv[idx_vrf]->arg;
1455
1456 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1457 if (strmatch(name, VRF_DEFAULT_NAME))
1458 name = NULL;
1459 else
1460 inst_type = BGP_INSTANCE_TYPE_VRF;
1461 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1462 inst_type = BGP_INSTANCE_TYPE_VIEW;
1463 }
1464
1465 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1466 is_new_bgp = (bgp_lookup(as, name) == NULL);
1467
1468 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1469 switch (ret) {
1470 case BGP_ERR_AS_MISMATCH:
1471 vty_out(vty, "BGP is already running; AS is %u\n", as);
1472 return CMD_WARNING_CONFIG_FAILED;
1473 case BGP_ERR_INSTANCE_MISMATCH:
1474 vty_out(vty,
1475 "BGP instance name and AS number mismatch\n");
1476 vty_out(vty,
1477 "BGP instance is already running; AS is %u\n",
1478 as);
1479 return CMD_WARNING_CONFIG_FAILED;
1480 }
1481
1482 /*
1483 * If we just instantiated the default instance, complete
1484 * any pending VRF-VPN leaking that was configured via
1485 * earlier "router bgp X vrf FOO" blocks.
1486 */
1487 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1488 vpn_leak_postchange_all();
1489
1490 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1491 bgp_vpn_leak_export(bgp);
1492 /* Pending: handle when user tries to change a view to vrf n vv.
1493 */
1494 }
1495
1496 /* unset the auto created flag as the user config is now present */
1497 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1498 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1499
1500 return CMD_SUCCESS;
1501 }
1502
1503 /* "no router bgp" commands. */
1504 DEFUN (no_router_bgp,
1505 no_router_bgp_cmd,
1506 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1507 NO_STR
1508 ROUTER_STR
1509 BGP_STR
1510 AS_STR
1511 BGP_INSTANCE_HELP_STR)
1512 {
1513 int idx_asn = 3;
1514 int idx_vrf = 5;
1515 as_t as;
1516 struct bgp *bgp;
1517 const char *name = NULL;
1518
1519 // "no router bgp" without an ASN
1520 if (argc == 3) {
1521 // Pending: Make VRF option available for ASN less config
1522 bgp = bgp_get_default();
1523
1524 if (bgp == NULL) {
1525 vty_out(vty, "%% No BGP process is configured\n");
1526 return CMD_WARNING_CONFIG_FAILED;
1527 }
1528
1529 if (listcount(bm->bgp) > 1) {
1530 vty_out(vty, "%% Please specify ASN and VRF\n");
1531 return CMD_WARNING_CONFIG_FAILED;
1532 }
1533
1534 if (bgp->l3vni) {
1535 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1536 bgp->l3vni);
1537 return CMD_WARNING_CONFIG_FAILED;
1538 }
1539 } else {
1540 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1541
1542 if (argc > 4) {
1543 name = argv[idx_vrf]->arg;
1544 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1545 && strmatch(name, VRF_DEFAULT_NAME))
1546 name = NULL;
1547 }
1548
1549 /* Lookup bgp structure. */
1550 bgp = bgp_lookup(as, name);
1551 if (!bgp) {
1552 vty_out(vty, "%% Can't find BGP instance\n");
1553 return CMD_WARNING_CONFIG_FAILED;
1554 }
1555
1556 if (bgp->l3vni) {
1557 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1558 bgp->l3vni);
1559 return CMD_WARNING_CONFIG_FAILED;
1560 }
1561
1562 /* Cannot delete default instance if vrf instances exist */
1563 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1564 struct listnode *node;
1565 struct bgp *tmp_bgp;
1566
1567 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1568 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1569 continue;
1570 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1571 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1572 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1573 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1574 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1575 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1576 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1577 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1578 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1579 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1580 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1581 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1582 (bgp == bgp_get_evpn() &&
1583 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1584 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1585 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1586 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1587 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1588 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1589 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1590 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1591 (hashcount(tmp_bgp->vnihash))) {
1592 vty_out(vty,
1593 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1594 return CMD_WARNING_CONFIG_FAILED;
1595 }
1596 }
1597 }
1598 }
1599
1600 bgp_delete(bgp);
1601
1602 return CMD_SUCCESS;
1603 }
1604
1605 /* bgp session-dscp */
1606
1607 DEFPY (bgp_session_dscp,
1608 bgp_session_dscp_cmd,
1609 "bgp session-dscp (0-63)$dscp",
1610 BGP_STR
1611 "Override default (C6) bgp TCP session DSCP value\n"
1612 "Manually configured dscp parameter\n")
1613 {
1614 bm->tcp_dscp = dscp << 2;
1615
1616 return CMD_SUCCESS;
1617 }
1618
1619 DEFPY (no_bgp_session_dscp,
1620 no_bgp_session_dscp_cmd,
1621 "no bgp session-dscp [(0-63)]",
1622 NO_STR
1623 BGP_STR
1624 "Override default (C6) bgp TCP session DSCP value\n"
1625 "Manually configured dscp parameter\n")
1626 {
1627 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1628
1629 return CMD_SUCCESS;
1630 }
1631
1632 /* BGP router-id. */
1633
1634 DEFPY (bgp_router_id,
1635 bgp_router_id_cmd,
1636 "bgp router-id A.B.C.D",
1637 BGP_STR
1638 "Override configured router identifier\n"
1639 "Manually configured router identifier\n")
1640 {
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642 bgp_router_id_static_set(bgp, router_id);
1643 return CMD_SUCCESS;
1644 }
1645
1646 DEFPY (no_bgp_router_id,
1647 no_bgp_router_id_cmd,
1648 "no bgp router-id [A.B.C.D]",
1649 NO_STR
1650 BGP_STR
1651 "Override configured router identifier\n"
1652 "Manually configured router identifier\n")
1653 {
1654 VTY_DECLVAR_CONTEXT(bgp, bgp);
1655
1656 if (router_id_str) {
1657 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1658 vty_out(vty, "%% BGP router-id doesn't match\n");
1659 return CMD_WARNING_CONFIG_FAILED;
1660 }
1661 }
1662
1663 router_id.s_addr = 0;
1664 bgp_router_id_static_set(bgp, router_id);
1665
1666 return CMD_SUCCESS;
1667 }
1668
1669 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1670 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1671 NO_STR BGP_STR
1672 "Add community specific parameters\n"
1673 "Create an alias for a community\n"
1674 "Community (AA:BB or AA:BB:CC)\n"
1675 "Alias name\n")
1676 {
1677 struct community_alias ca = {};
1678 struct community_alias *lookup_community;
1679 struct community_alias *lookup_alias;
1680 struct community *comm;
1681 struct lcommunity *lcomm;
1682 uint8_t invalid = 0;
1683
1684 comm = community_str2com(community);
1685 if (!comm)
1686 invalid++;
1687 community_free(&comm);
1688
1689 lcomm = lcommunity_str2com(community);
1690 if (!lcomm)
1691 invalid++;
1692 lcommunity_free(&lcomm);
1693
1694 if (invalid > 1) {
1695 vty_out(vty, "Invalid community format\n");
1696 return CMD_WARNING;
1697 }
1698
1699 strlcpy(ca.community, community, sizeof(ca.community));
1700 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1701
1702 lookup_community = bgp_ca_community_lookup(&ca);
1703 lookup_alias = bgp_ca_alias_lookup(&ca);
1704
1705 if (no) {
1706 bgp_ca_alias_delete(&ca);
1707 bgp_ca_community_delete(&ca);
1708 } else {
1709 if (lookup_alias) {
1710 /* Lookup if community hash table has an item
1711 * with the same alias name.
1712 */
1713 strlcpy(ca.community, lookup_alias->community,
1714 sizeof(ca.community));
1715 if (bgp_ca_community_lookup(&ca)) {
1716 vty_out(vty,
1717 "community (%s) already has this alias (%s)\n",
1718 lookup_alias->community,
1719 lookup_alias->alias);
1720 return CMD_WARNING;
1721 }
1722 bgp_ca_alias_delete(&ca);
1723 }
1724
1725 if (lookup_community) {
1726 /* Lookup if alias hash table has an item
1727 * with the same community.
1728 */
1729 strlcpy(ca.alias, lookup_community->alias,
1730 sizeof(ca.alias));
1731 if (bgp_ca_alias_lookup(&ca)) {
1732 vty_out(vty,
1733 "alias (%s) already has this community (%s)\n",
1734 lookup_community->alias,
1735 lookup_community->community);
1736 return CMD_WARNING;
1737 }
1738 bgp_ca_community_delete(&ca);
1739 }
1740
1741 bgp_ca_alias_insert(&ca);
1742 bgp_ca_community_insert(&ca);
1743 }
1744
1745 return CMD_SUCCESS;
1746 }
1747
1748 DEFPY (bgp_global_suppress_fib_pending,
1749 bgp_global_suppress_fib_pending_cmd,
1750 "[no] bgp suppress-fib-pending",
1751 NO_STR
1752 BGP_STR
1753 "Advertise only routes that are programmed in kernel to peers globally\n")
1754 {
1755 bm_wait_for_fib_set(!no);
1756
1757 return CMD_SUCCESS;
1758 }
1759
1760 DEFPY (bgp_suppress_fib_pending,
1761 bgp_suppress_fib_pending_cmd,
1762 "[no] bgp suppress-fib-pending",
1763 NO_STR
1764 BGP_STR
1765 "Advertise only routes that are programmed in kernel to peers\n")
1766 {
1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768
1769 bgp_suppress_fib_pending_set(bgp, !no);
1770 return CMD_SUCCESS;
1771 }
1772
1773
1774 /* BGP Cluster ID. */
1775 DEFUN (bgp_cluster_id,
1776 bgp_cluster_id_cmd,
1777 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1778 BGP_STR
1779 "Configure Route-Reflector Cluster-id\n"
1780 "Route-Reflector Cluster-id in IP address format\n"
1781 "Route-Reflector Cluster-id as 32 bit quantity\n")
1782 {
1783 VTY_DECLVAR_CONTEXT(bgp, bgp);
1784 int idx_ipv4 = 2;
1785 int ret;
1786 struct in_addr cluster;
1787
1788 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1789 if (!ret) {
1790 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1791 return CMD_WARNING_CONFIG_FAILED;
1792 }
1793
1794 bgp_cluster_id_set(bgp, &cluster);
1795 bgp_clear_star_soft_out(vty, bgp->name);
1796
1797 return CMD_SUCCESS;
1798 }
1799
1800 DEFUN (no_bgp_cluster_id,
1801 no_bgp_cluster_id_cmd,
1802 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1803 NO_STR
1804 BGP_STR
1805 "Configure Route-Reflector Cluster-id\n"
1806 "Route-Reflector Cluster-id in IP address format\n"
1807 "Route-Reflector Cluster-id as 32 bit quantity\n")
1808 {
1809 VTY_DECLVAR_CONTEXT(bgp, bgp);
1810 bgp_cluster_id_unset(bgp);
1811 bgp_clear_star_soft_out(vty, bgp->name);
1812
1813 return CMD_SUCCESS;
1814 }
1815
1816 DEFPY (bgp_norib,
1817 bgp_norib_cmd,
1818 "bgp no-rib",
1819 BGP_STR
1820 "Disable BGP route installation to RIB (Zebra)\n")
1821 {
1822 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1823 vty_out(vty,
1824 "%% No-RIB option is already set, nothing to do here.\n");
1825 return CMD_SUCCESS;
1826 }
1827
1828 bgp_option_norib_set_runtime();
1829
1830 return CMD_SUCCESS;
1831 }
1832
1833 DEFPY (no_bgp_norib,
1834 no_bgp_norib_cmd,
1835 "no bgp no-rib",
1836 NO_STR
1837 BGP_STR
1838 "Disable BGP route installation to RIB (Zebra)\n")
1839 {
1840 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1841 vty_out(vty,
1842 "%% No-RIB option is not set, nothing to do here.\n");
1843 return CMD_SUCCESS;
1844 }
1845
1846 bgp_option_norib_unset_runtime();
1847
1848 return CMD_SUCCESS;
1849 }
1850
1851 DEFPY (no_bgp_send_extra_data,
1852 no_bgp_send_extra_data_cmd,
1853 "[no] bgp send-extra-data zebra",
1854 NO_STR
1855 BGP_STR
1856 "Extra data to Zebra for display/use\n"
1857 "To zebra\n")
1858 {
1859 if (no)
1860 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1861 else
1862 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1863
1864 return CMD_SUCCESS;
1865 }
1866
1867 DEFUN (bgp_confederation_identifier,
1868 bgp_confederation_identifier_cmd,
1869 "bgp confederation identifier (1-4294967295)",
1870 BGP_STR
1871 "AS confederation parameters\n"
1872 "AS number\n"
1873 "Set routing domain confederation AS\n")
1874 {
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876 int idx_number = 3;
1877 as_t as;
1878
1879 as = strtoul(argv[idx_number]->arg, NULL, 10);
1880
1881 bgp_confederation_id_set(bgp, as);
1882
1883 return CMD_SUCCESS;
1884 }
1885
1886 DEFUN (no_bgp_confederation_identifier,
1887 no_bgp_confederation_identifier_cmd,
1888 "no bgp confederation identifier [(1-4294967295)]",
1889 NO_STR
1890 BGP_STR
1891 "AS confederation parameters\n"
1892 "AS number\n"
1893 "Set routing domain confederation AS\n")
1894 {
1895 VTY_DECLVAR_CONTEXT(bgp, bgp);
1896 bgp_confederation_id_unset(bgp);
1897
1898 return CMD_SUCCESS;
1899 }
1900
1901 DEFUN (bgp_confederation_peers,
1902 bgp_confederation_peers_cmd,
1903 "bgp confederation peers (1-4294967295)...",
1904 BGP_STR
1905 "AS confederation parameters\n"
1906 "Peer ASs in BGP confederation\n"
1907 AS_STR)
1908 {
1909 VTY_DECLVAR_CONTEXT(bgp, bgp);
1910 int idx_asn = 3;
1911 as_t as;
1912 int i;
1913
1914 for (i = idx_asn; i < argc; i++) {
1915 as = strtoul(argv[i]->arg, NULL, 10);
1916
1917 if (bgp->as == as) {
1918 vty_out(vty,
1919 "%% Local member-AS not allowed in confed peer list\n");
1920 continue;
1921 }
1922
1923 bgp_confederation_peers_add(bgp, as);
1924 }
1925 return CMD_SUCCESS;
1926 }
1927
1928 DEFUN (no_bgp_confederation_peers,
1929 no_bgp_confederation_peers_cmd,
1930 "no bgp confederation peers (1-4294967295)...",
1931 NO_STR
1932 BGP_STR
1933 "AS confederation parameters\n"
1934 "Peer ASs in BGP confederation\n"
1935 AS_STR)
1936 {
1937 VTY_DECLVAR_CONTEXT(bgp, bgp);
1938 int idx_asn = 4;
1939 as_t as;
1940 int i;
1941
1942 for (i = idx_asn; i < argc; i++) {
1943 as = strtoul(argv[i]->arg, NULL, 10);
1944
1945 bgp_confederation_peers_remove(bgp, as);
1946 }
1947 return CMD_SUCCESS;
1948 }
1949
1950 /**
1951 * Central routine for maximum-paths configuration.
1952 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1953 * @set: 1 for setting values, 0 for removing the max-paths config.
1954 */
1955 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1956 const char *mpaths, uint16_t options,
1957 int set)
1958 {
1959 VTY_DECLVAR_CONTEXT(bgp, bgp);
1960 uint16_t maxpaths = 0;
1961 int ret;
1962 afi_t afi;
1963 safi_t safi;
1964
1965 afi = bgp_node_afi(vty);
1966 safi = bgp_node_safi(vty);
1967
1968 if (set) {
1969 maxpaths = strtol(mpaths, NULL, 10);
1970 if (maxpaths > multipath_num) {
1971 vty_out(vty,
1972 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1973 maxpaths, multipath_num);
1974 return CMD_WARNING_CONFIG_FAILED;
1975 }
1976 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1977 options);
1978 } else
1979 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1980
1981 if (ret < 0) {
1982 vty_out(vty,
1983 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1984 (set == 1) ? "" : "un",
1985 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1986 maxpaths, afi, safi);
1987 return CMD_WARNING_CONFIG_FAILED;
1988 }
1989
1990 bgp_recalculate_all_bestpaths(bgp);
1991
1992 return CMD_SUCCESS;
1993 }
1994
1995 DEFUN (bgp_maxmed_admin,
1996 bgp_maxmed_admin_cmd,
1997 "bgp max-med administrative ",
1998 BGP_STR
1999 "Advertise routes with max-med\n"
2000 "Administratively applied, for an indefinite period\n")
2001 {
2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003
2004 bgp->v_maxmed_admin = 1;
2005 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2006
2007 bgp_maxmed_update(bgp);
2008
2009 return CMD_SUCCESS;
2010 }
2011
2012 DEFUN (bgp_maxmed_admin_medv,
2013 bgp_maxmed_admin_medv_cmd,
2014 "bgp max-med administrative (0-4294967295)",
2015 BGP_STR
2016 "Advertise routes with max-med\n"
2017 "Administratively applied, for an indefinite period\n"
2018 "Max MED value to be used\n")
2019 {
2020 VTY_DECLVAR_CONTEXT(bgp, bgp);
2021 int idx_number = 3;
2022
2023 bgp->v_maxmed_admin = 1;
2024 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2025
2026 bgp_maxmed_update(bgp);
2027
2028 return CMD_SUCCESS;
2029 }
2030
2031 DEFUN (no_bgp_maxmed_admin,
2032 no_bgp_maxmed_admin_cmd,
2033 "no bgp max-med administrative [(0-4294967295)]",
2034 NO_STR
2035 BGP_STR
2036 "Advertise routes with max-med\n"
2037 "Administratively applied, for an indefinite period\n"
2038 "Max MED value to be used\n")
2039 {
2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2042 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2043 bgp_maxmed_update(bgp);
2044
2045 return CMD_SUCCESS;
2046 }
2047
2048 DEFUN (bgp_maxmed_onstartup,
2049 bgp_maxmed_onstartup_cmd,
2050 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2051 BGP_STR
2052 "Advertise routes with max-med\n"
2053 "Effective on a startup\n"
2054 "Time (seconds) period for max-med\n"
2055 "Max MED value to be used\n")
2056 {
2057 VTY_DECLVAR_CONTEXT(bgp, bgp);
2058 int idx = 0;
2059
2060 if (argv_find(argv, argc, "(5-86400)", &idx))
2061 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2062 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2063 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2064 else
2065 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2066
2067 bgp_maxmed_update(bgp);
2068
2069 return CMD_SUCCESS;
2070 }
2071
2072 DEFUN (no_bgp_maxmed_onstartup,
2073 no_bgp_maxmed_onstartup_cmd,
2074 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2075 NO_STR
2076 BGP_STR
2077 "Advertise routes with max-med\n"
2078 "Effective on a startup\n"
2079 "Time (seconds) period for max-med\n"
2080 "Max MED value to be used\n")
2081 {
2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083
2084 /* Cancel max-med onstartup if its on */
2085 if (bgp->t_maxmed_onstartup) {
2086 THREAD_OFF(bgp->t_maxmed_onstartup);
2087 bgp->maxmed_onstartup_over = 1;
2088 }
2089
2090 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2091 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2092
2093 bgp_maxmed_update(bgp);
2094
2095 return CMD_SUCCESS;
2096 }
2097
2098 static int bgp_global_update_delay_config_vty(struct vty *vty,
2099 uint16_t update_delay,
2100 uint16_t establish_wait)
2101 {
2102 struct listnode *node, *nnode;
2103 struct bgp *bgp;
2104 bool vrf_cfg = false;
2105
2106 /*
2107 * See if update-delay is set per-vrf and warn user to delete it
2108 * Note that we only need to check this if this is the first time
2109 * setting the global config.
2110 */
2111 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2112 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2113 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2114 vty_out(vty,
2115 "%% update-delay configuration found in vrf %s\n",
2116 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2117 ? VRF_DEFAULT_NAME
2118 : bgp->name);
2119 vrf_cfg = true;
2120 }
2121 }
2122 }
2123
2124 if (vrf_cfg) {
2125 vty_out(vty,
2126 "%%Failed: global update-delay config not permitted\n");
2127 return CMD_WARNING;
2128 }
2129
2130 if (!establish_wait) { /* update-delay <delay> */
2131 bm->v_update_delay = update_delay;
2132 bm->v_establish_wait = bm->v_update_delay;
2133 } else {
2134 /* update-delay <delay> <establish-wait> */
2135 if (update_delay < establish_wait) {
2136 vty_out(vty,
2137 "%%Failed: update-delay less than the establish-wait!\n");
2138 return CMD_WARNING_CONFIG_FAILED;
2139 }
2140
2141 bm->v_update_delay = update_delay;
2142 bm->v_establish_wait = establish_wait;
2143 }
2144
2145 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2146 bgp->v_update_delay = bm->v_update_delay;
2147 bgp->v_establish_wait = bm->v_establish_wait;
2148 }
2149
2150 return CMD_SUCCESS;
2151 }
2152
2153 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2154 {
2155 struct listnode *node, *nnode;
2156 struct bgp *bgp;
2157
2158 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2159 bm->v_establish_wait = bm->v_update_delay;
2160
2161 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2162 bgp->v_update_delay = bm->v_update_delay;
2163 bgp->v_establish_wait = bm->v_establish_wait;
2164 }
2165
2166 return CMD_SUCCESS;
2167 }
2168
2169 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2170 uint16_t establish_wait)
2171 {
2172 VTY_DECLVAR_CONTEXT(bgp, bgp);
2173
2174 /* if configured globally, per-instance config is not allowed */
2175 if (bm->v_update_delay) {
2176 vty_out(vty,
2177 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2178 return CMD_WARNING_CONFIG_FAILED;
2179 }
2180
2181
2182 if (!establish_wait) /* update-delay <delay> */
2183 {
2184 bgp->v_update_delay = update_delay;
2185 bgp->v_establish_wait = bgp->v_update_delay;
2186 return CMD_SUCCESS;
2187 }
2188
2189 /* update-delay <delay> <establish-wait> */
2190 if (update_delay < establish_wait) {
2191 vty_out(vty,
2192 "%%Failed: update-delay less than the establish-wait!\n");
2193 return CMD_WARNING_CONFIG_FAILED;
2194 }
2195
2196 bgp->v_update_delay = update_delay;
2197 bgp->v_establish_wait = establish_wait;
2198
2199 return CMD_SUCCESS;
2200 }
2201
2202 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2203 {
2204 VTY_DECLVAR_CONTEXT(bgp, bgp);
2205
2206 /* If configured globally, cannot remove from one bgp instance */
2207 if (bm->v_update_delay) {
2208 vty_out(vty,
2209 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2210 return CMD_WARNING_CONFIG_FAILED;
2211 }
2212 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2213 bgp->v_establish_wait = bgp->v_update_delay;
2214
2215 return CMD_SUCCESS;
2216 }
2217
2218 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2219 {
2220 /* If configured globally, no need to display per-instance value */
2221 if (bgp->v_update_delay != bm->v_update_delay) {
2222 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2223 if (bgp->v_update_delay != bgp->v_establish_wait)
2224 vty_out(vty, " %d", bgp->v_establish_wait);
2225 vty_out(vty, "\n");
2226 }
2227 }
2228
2229 /* Global update-delay configuration */
2230 DEFPY (bgp_global_update_delay,
2231 bgp_global_update_delay_cmd,
2232 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2233 BGP_STR
2234 "Force initial delay for best-path and updates for all bgp instances\n"
2235 "Max delay in seconds\n"
2236 "Establish wait in seconds\n")
2237 {
2238 return bgp_global_update_delay_config_vty(vty, delay, wait);
2239 }
2240
2241 /* Global update-delay deconfiguration */
2242 DEFPY (no_bgp_global_update_delay,
2243 no_bgp_global_update_delay_cmd,
2244 "no bgp update-delay [(0-3600) [(1-3600)]]",
2245 NO_STR
2246 BGP_STR
2247 "Force initial delay for best-path and updates\n"
2248 "Max delay in seconds\n"
2249 "Establish wait in seconds\n")
2250 {
2251 return bgp_global_update_delay_deconfig_vty(vty);
2252 }
2253
2254 /* Update-delay configuration */
2255
2256 DEFPY (bgp_update_delay,
2257 bgp_update_delay_cmd,
2258 "update-delay (0-3600)$delay [(1-3600)$wait]",
2259 "Force initial delay for best-path and updates\n"
2260 "Max delay in seconds\n"
2261 "Establish wait in seconds\n")
2262 {
2263 return bgp_update_delay_config_vty(vty, delay, wait);
2264 }
2265
2266 /* Update-delay deconfiguration */
2267 DEFPY (no_bgp_update_delay,
2268 no_bgp_update_delay_cmd,
2269 "no update-delay [(0-3600) [(1-3600)]]",
2270 NO_STR
2271 "Force initial delay for best-path and updates\n"
2272 "Max delay in seconds\n"
2273 "Establish wait in seconds\n")
2274 {
2275 return bgp_update_delay_deconfig_vty(vty);
2276 }
2277
2278
2279 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2280 bool set)
2281 {
2282 VTY_DECLVAR_CONTEXT(bgp, bgp);
2283
2284 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2285 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2286
2287 return CMD_SUCCESS;
2288 }
2289
2290 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2291 bool set)
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294
2295 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2296 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2297
2298 return CMD_SUCCESS;
2299 }
2300
2301 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2302 {
2303 uint32_t quanta =
2304 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2305 if (quanta != BGP_WRITE_PACKET_MAX)
2306 vty_out(vty, " write-quanta %d\n", quanta);
2307 }
2308
2309 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2310 {
2311 uint32_t quanta =
2312 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2313 if (quanta != BGP_READ_PACKET_MAX)
2314 vty_out(vty, " read-quanta %d\n", quanta);
2315 }
2316
2317 /* Packet quanta configuration
2318 *
2319 * XXX: The value set here controls the size of a stack buffer in the IO
2320 * thread. When changing these limits be careful to prevent stack overflow.
2321 *
2322 * Furthermore, the maximums used here should correspond to
2323 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2324 */
2325 DEFPY (bgp_wpkt_quanta,
2326 bgp_wpkt_quanta_cmd,
2327 "[no] write-quanta (1-64)$quanta",
2328 NO_STR
2329 "How many packets to write to peer socket per run\n"
2330 "Number of packets\n")
2331 {
2332 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2333 }
2334
2335 DEFPY (bgp_rpkt_quanta,
2336 bgp_rpkt_quanta_cmd,
2337 "[no] read-quanta (1-10)$quanta",
2338 NO_STR
2339 "How many packets to read from peer socket per I/O cycle\n"
2340 "Number of packets\n")
2341 {
2342 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2343 }
2344
2345 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2346 {
2347 if (!bgp->heuristic_coalesce)
2348 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2349 }
2350
2351 /* BGP TCP keepalive */
2352 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2353 {
2354 if (bgp->tcp_keepalive_idle) {
2355 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2356 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2357 bgp->tcp_keepalive_probes);
2358 }
2359 }
2360
2361 DEFUN (bgp_coalesce_time,
2362 bgp_coalesce_time_cmd,
2363 "coalesce-time (0-4294967295)",
2364 "Subgroup coalesce timer\n"
2365 "Subgroup coalesce timer value (in ms)\n")
2366 {
2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
2368
2369 int idx = 0;
2370
2371 bgp->heuristic_coalesce = false;
2372
2373 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2374 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2375
2376 return CMD_SUCCESS;
2377 }
2378
2379 DEFUN (no_bgp_coalesce_time,
2380 no_bgp_coalesce_time_cmd,
2381 "no coalesce-time (0-4294967295)",
2382 NO_STR
2383 "Subgroup coalesce timer\n"
2384 "Subgroup coalesce timer value (in ms)\n")
2385 {
2386 VTY_DECLVAR_CONTEXT(bgp, bgp);
2387
2388 bgp->heuristic_coalesce = true;
2389 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2390 return CMD_SUCCESS;
2391 }
2392
2393 /* Maximum-paths configuration */
2394 DEFUN (bgp_maxpaths,
2395 bgp_maxpaths_cmd,
2396 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2397 "Forward packets over multiple paths\n"
2398 "Number of paths\n")
2399 {
2400 int idx_number = 1;
2401 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2402 argv[idx_number]->arg, 0, 1);
2403 }
2404
2405 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2406 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2407 "Forward packets over multiple paths\n"
2408 "Number of paths\n")
2409
2410 DEFUN (bgp_maxpaths_ibgp,
2411 bgp_maxpaths_ibgp_cmd,
2412 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2413 "Forward packets over multiple paths\n"
2414 "iBGP-multipath\n"
2415 "Number of paths\n")
2416 {
2417 int idx_number = 2;
2418 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2419 argv[idx_number]->arg, 0, 1);
2420 }
2421
2422 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2423 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2424 "Forward packets over multiple paths\n"
2425 "iBGP-multipath\n"
2426 "Number of paths\n")
2427
2428 DEFUN (bgp_maxpaths_ibgp_cluster,
2429 bgp_maxpaths_ibgp_cluster_cmd,
2430 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2431 "Forward packets over multiple paths\n"
2432 "iBGP-multipath\n"
2433 "Number of paths\n"
2434 "Match the cluster length\n")
2435 {
2436 int idx_number = 2;
2437 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2438 argv[idx_number]->arg, true, 1);
2439 }
2440
2441 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2442 "maximum-paths ibgp " CMD_RANGE_STR(
2443 1, MULTIPATH_NUM) " equal-cluster-length",
2444 "Forward packets over multiple paths\n"
2445 "iBGP-multipath\n"
2446 "Number of paths\n"
2447 "Match the cluster length\n")
2448
2449 DEFUN (no_bgp_maxpaths,
2450 no_bgp_maxpaths_cmd,
2451 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2452 NO_STR
2453 "Forward packets over multiple paths\n"
2454 "Number of paths\n")
2455 {
2456 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2457 }
2458
2459 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2460 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2461 "Forward packets over multiple paths\n"
2462 "Number of paths\n")
2463
2464 DEFUN (no_bgp_maxpaths_ibgp,
2465 no_bgp_maxpaths_ibgp_cmd,
2466 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2467 NO_STR
2468 "Forward packets over multiple paths\n"
2469 "iBGP-multipath\n"
2470 "Number of paths\n"
2471 "Match the cluster length\n")
2472 {
2473 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2474 }
2475
2476 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2477 "no maximum-paths ibgp [" CMD_RANGE_STR(
2478 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2479 NO_STR
2480 "Forward packets over multiple paths\n"
2481 "iBGP-multipath\n"
2482 "Number of paths\n"
2483 "Match the cluster length\n")
2484
2485 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2486 afi_t afi, safi_t safi)
2487 {
2488 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2489 vty_out(vty, " maximum-paths %d\n",
2490 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2491 }
2492
2493 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2494 vty_out(vty, " maximum-paths ibgp %d",
2495 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2496 if (bgp->maxpaths[afi][safi].same_clusterlen)
2497 vty_out(vty, " equal-cluster-length");
2498 vty_out(vty, "\n");
2499 }
2500 }
2501
2502 /* BGP timers. */
2503
2504 DEFUN (bgp_timers,
2505 bgp_timers_cmd,
2506 "timers bgp (0-65535) (0-65535)",
2507 "Adjust routing timers\n"
2508 "BGP timers\n"
2509 "Keepalive interval\n"
2510 "Holdtime\n")
2511 {
2512 VTY_DECLVAR_CONTEXT(bgp, bgp);
2513 int idx_number = 2;
2514 int idx_number_2 = 3;
2515 unsigned long keepalive = 0;
2516 unsigned long holdtime = 0;
2517
2518 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2519 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2520
2521 /* Holdtime value check. */
2522 if (holdtime < 3 && holdtime != 0) {
2523 vty_out(vty,
2524 "%% hold time value must be either 0 or greater than 3\n");
2525 return CMD_WARNING_CONFIG_FAILED;
2526 }
2527
2528 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2529 BGP_DEFAULT_DELAYOPEN);
2530
2531 return CMD_SUCCESS;
2532 }
2533
2534 DEFUN (no_bgp_timers,
2535 no_bgp_timers_cmd,
2536 "no timers bgp [(0-65535) (0-65535)]",
2537 NO_STR
2538 "Adjust routing timers\n"
2539 "BGP timers\n"
2540 "Keepalive interval\n"
2541 "Holdtime\n")
2542 {
2543 VTY_DECLVAR_CONTEXT(bgp, bgp);
2544 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2545 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2546
2547 return CMD_SUCCESS;
2548 }
2549
2550 /* BGP minimum holdtime. */
2551
2552 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2553 "bgp minimum-holdtime (1-65535)",
2554 "BGP specific commands\n"
2555 "BGP minimum holdtime\n"
2556 "Seconds\n")
2557 {
2558 VTY_DECLVAR_CONTEXT(bgp, bgp);
2559 int idx_number = 2;
2560 unsigned long min_holdtime;
2561
2562 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2563
2564 bgp->default_min_holdtime = min_holdtime;
2565
2566 return CMD_SUCCESS;
2567 }
2568
2569 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2570 "no bgp minimum-holdtime [(1-65535)]",
2571 NO_STR
2572 "BGP specific commands\n"
2573 "BGP minimum holdtime\n"
2574 "Seconds\n")
2575 {
2576 VTY_DECLVAR_CONTEXT(bgp, bgp);
2577
2578 bgp->default_min_holdtime = 0;
2579
2580 return CMD_SUCCESS;
2581 }
2582
2583 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2584 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2585 BGP_STR
2586 "TCP keepalive parameters\n"
2587 "TCP keepalive idle time (seconds)\n"
2588 "TCP keepalive interval (seconds)\n"
2589 "TCP keepalive maximum probes\n")
2590 {
2591 VTY_DECLVAR_CONTEXT(bgp, bgp);
2592
2593 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2594 (uint16_t)probes);
2595
2596 return CMD_SUCCESS;
2597 }
2598
2599 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2600 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2601 NO_STR
2602 BGP_STR
2603 "TCP keepalive parameters\n"
2604 "TCP keepalive idle time (seconds)\n"
2605 "TCP keepalive interval (seconds)\n"
2606 "TCP keepalive maximum probes\n")
2607 {
2608 VTY_DECLVAR_CONTEXT(bgp, bgp);
2609
2610 bgp_tcp_keepalive_unset(bgp);
2611
2612 return CMD_SUCCESS;
2613 }
2614
2615 DEFUN (bgp_client_to_client_reflection,
2616 bgp_client_to_client_reflection_cmd,
2617 "bgp client-to-client reflection",
2618 BGP_STR
2619 "Configure client to client route reflection\n"
2620 "reflection of routes allowed\n")
2621 {
2622 VTY_DECLVAR_CONTEXT(bgp, bgp);
2623 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2624 bgp_clear_star_soft_out(vty, bgp->name);
2625
2626 return CMD_SUCCESS;
2627 }
2628
2629 DEFUN (no_bgp_client_to_client_reflection,
2630 no_bgp_client_to_client_reflection_cmd,
2631 "no bgp client-to-client reflection",
2632 NO_STR
2633 BGP_STR
2634 "Configure client to client route reflection\n"
2635 "reflection of routes allowed\n")
2636 {
2637 VTY_DECLVAR_CONTEXT(bgp, bgp);
2638 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2639 bgp_clear_star_soft_out(vty, bgp->name);
2640
2641 return CMD_SUCCESS;
2642 }
2643
2644 /* "bgp always-compare-med" configuration. */
2645 DEFUN (bgp_always_compare_med,
2646 bgp_always_compare_med_cmd,
2647 "bgp always-compare-med",
2648 BGP_STR
2649 "Allow comparing MED from different neighbors\n")
2650 {
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2653 bgp_recalculate_all_bestpaths(bgp);
2654
2655 return CMD_SUCCESS;
2656 }
2657
2658 DEFUN (no_bgp_always_compare_med,
2659 no_bgp_always_compare_med_cmd,
2660 "no bgp always-compare-med",
2661 NO_STR
2662 BGP_STR
2663 "Allow comparing MED from different neighbors\n")
2664 {
2665 VTY_DECLVAR_CONTEXT(bgp, bgp);
2666 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2667 bgp_recalculate_all_bestpaths(bgp);
2668
2669 return CMD_SUCCESS;
2670 }
2671
2672
2673 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2674 "bgp ebgp-requires-policy",
2675 BGP_STR
2676 "Require in and out policy for eBGP peers (RFC8212)\n")
2677 {
2678 VTY_DECLVAR_CONTEXT(bgp, bgp);
2679 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2680 return CMD_SUCCESS;
2681 }
2682
2683 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2684 "no bgp ebgp-requires-policy",
2685 NO_STR
2686 BGP_STR
2687 "Require in and out policy for eBGP peers (RFC8212)\n")
2688 {
2689 VTY_DECLVAR_CONTEXT(bgp, bgp);
2690 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2691 return CMD_SUCCESS;
2692 }
2693
2694 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2695 "bgp suppress-duplicates",
2696 BGP_STR
2697 "Suppress duplicate updates if the route actually not changed\n")
2698 {
2699 VTY_DECLVAR_CONTEXT(bgp, bgp);
2700 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2701 return CMD_SUCCESS;
2702 }
2703
2704 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2705 "no bgp suppress-duplicates",
2706 NO_STR
2707 BGP_STR
2708 "Suppress duplicate updates if the route actually not changed\n")
2709 {
2710 VTY_DECLVAR_CONTEXT(bgp, bgp);
2711 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2712 return CMD_SUCCESS;
2713 }
2714
2715 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2716 "bgp reject-as-sets",
2717 BGP_STR
2718 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2719 {
2720 VTY_DECLVAR_CONTEXT(bgp, bgp);
2721 struct listnode *node, *nnode;
2722 struct peer *peer;
2723
2724 bgp->reject_as_sets = true;
2725
2726 /* Reset existing BGP sessions to reject routes
2727 * with aspath containing AS_SET or AS_CONFED_SET.
2728 */
2729 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2730 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2731 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2732 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2733 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2734 }
2735 }
2736
2737 return CMD_SUCCESS;
2738 }
2739
2740 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2741 "no bgp reject-as-sets",
2742 NO_STR
2743 BGP_STR
2744 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2745 {
2746 VTY_DECLVAR_CONTEXT(bgp, bgp);
2747 struct listnode *node, *nnode;
2748 struct peer *peer;
2749
2750 bgp->reject_as_sets = false;
2751
2752 /* Reset existing BGP sessions to reject routes
2753 * with aspath containing AS_SET or AS_CONFED_SET.
2754 */
2755 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2756 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2757 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2758 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2759 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2760 }
2761 }
2762
2763 return CMD_SUCCESS;
2764 }
2765
2766 /* "bgp deterministic-med" configuration. */
2767 DEFUN (bgp_deterministic_med,
2768 bgp_deterministic_med_cmd,
2769 "bgp deterministic-med",
2770 BGP_STR
2771 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2772 {
2773 VTY_DECLVAR_CONTEXT(bgp, bgp);
2774
2775 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2776 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2777 bgp_recalculate_all_bestpaths(bgp);
2778 }
2779
2780 return CMD_SUCCESS;
2781 }
2782
2783 DEFUN (no_bgp_deterministic_med,
2784 no_bgp_deterministic_med_cmd,
2785 "no bgp deterministic-med",
2786 NO_STR
2787 BGP_STR
2788 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2789 {
2790 VTY_DECLVAR_CONTEXT(bgp, bgp);
2791 int bestpath_per_as_used;
2792 afi_t afi;
2793 safi_t safi;
2794 struct peer *peer;
2795 struct listnode *node, *nnode;
2796
2797 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2798 bestpath_per_as_used = 0;
2799
2800 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2801 FOREACH_AFI_SAFI (afi, safi)
2802 if (bgp_addpath_dmed_required(
2803 peer->addpath_type[afi][safi])) {
2804 bestpath_per_as_used = 1;
2805 break;
2806 }
2807
2808 if (bestpath_per_as_used)
2809 break;
2810 }
2811
2812 if (bestpath_per_as_used) {
2813 vty_out(vty,
2814 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2815 return CMD_WARNING_CONFIG_FAILED;
2816 } else {
2817 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2818 bgp_recalculate_all_bestpaths(bgp);
2819 }
2820 }
2821
2822 return CMD_SUCCESS;
2823 }
2824
2825 /* "bgp graceful-restart mode" configuration. */
2826 DEFUN (bgp_graceful_restart,
2827 bgp_graceful_restart_cmd,
2828 "bgp graceful-restart",
2829 BGP_STR
2830 GR_CMD
2831 )
2832 {
2833 int ret = BGP_GR_FAILURE;
2834
2835 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2836 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2837
2838 VTY_DECLVAR_CONTEXT(bgp, bgp);
2839
2840 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2841
2842 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2843 ret);
2844
2845 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2846 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2847 vty_out(vty,
2848 "Graceful restart configuration changed, reset all peers to take effect\n");
2849 return bgp_vty_return(vty, ret);
2850 }
2851
2852 DEFUN (no_bgp_graceful_restart,
2853 no_bgp_graceful_restart_cmd,
2854 "no bgp graceful-restart",
2855 NO_STR
2856 BGP_STR
2857 NO_GR_CMD
2858 )
2859 {
2860 VTY_DECLVAR_CONTEXT(bgp, bgp);
2861
2862 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2863 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2864
2865 int ret = BGP_GR_FAILURE;
2866
2867 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2868
2869 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2870 ret);
2871
2872 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2873 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2874 vty_out(vty,
2875 "Graceful restart configuration changed, reset all peers to take effect\n");
2876
2877 return bgp_vty_return(vty, ret);
2878 }
2879
2880 DEFUN (bgp_graceful_restart_stalepath_time,
2881 bgp_graceful_restart_stalepath_time_cmd,
2882 "bgp graceful-restart stalepath-time (1-4095)",
2883 BGP_STR
2884 "Graceful restart capability parameters\n"
2885 "Set the max time to hold onto restarting peer's stale paths\n"
2886 "Delay value (seconds)\n")
2887 {
2888 VTY_DECLVAR_CONTEXT(bgp, bgp);
2889 int idx_number = 3;
2890 uint32_t stalepath;
2891
2892 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2893 bgp->stalepath_time = stalepath;
2894 return CMD_SUCCESS;
2895 }
2896
2897 DEFUN (bgp_graceful_restart_restart_time,
2898 bgp_graceful_restart_restart_time_cmd,
2899 "bgp graceful-restart restart-time (0-4095)",
2900 BGP_STR
2901 "Graceful restart capability parameters\n"
2902 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2903 "Delay value (seconds)\n")
2904 {
2905 VTY_DECLVAR_CONTEXT(bgp, bgp);
2906 int idx_number = 3;
2907 uint32_t restart;
2908
2909 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2910 bgp->restart_time = restart;
2911 return CMD_SUCCESS;
2912 }
2913
2914 DEFUN (bgp_graceful_restart_select_defer_time,
2915 bgp_graceful_restart_select_defer_time_cmd,
2916 "bgp graceful-restart select-defer-time (0-3600)",
2917 BGP_STR
2918 "Graceful restart capability parameters\n"
2919 "Set the time to defer the BGP route selection after restart\n"
2920 "Delay value (seconds, 0 - disable)\n")
2921 {
2922 VTY_DECLVAR_CONTEXT(bgp, bgp);
2923 int idx_number = 3;
2924 uint32_t defer_time;
2925
2926 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2927 bgp->select_defer_time = defer_time;
2928 if (defer_time == 0)
2929 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2930 else
2931 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2932
2933 return CMD_SUCCESS;
2934 }
2935
2936 DEFUN (no_bgp_graceful_restart_stalepath_time,
2937 no_bgp_graceful_restart_stalepath_time_cmd,
2938 "no bgp graceful-restart stalepath-time [(1-4095)]",
2939 NO_STR
2940 BGP_STR
2941 "Graceful restart capability parameters\n"
2942 "Set the max time to hold onto restarting peer's stale paths\n"
2943 "Delay value (seconds)\n")
2944 {
2945 VTY_DECLVAR_CONTEXT(bgp, bgp);
2946
2947 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2948 return CMD_SUCCESS;
2949 }
2950
2951 DEFUN (no_bgp_graceful_restart_restart_time,
2952 no_bgp_graceful_restart_restart_time_cmd,
2953 "no bgp graceful-restart restart-time [(0-4095)]",
2954 NO_STR
2955 BGP_STR
2956 "Graceful restart capability parameters\n"
2957 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2958 "Delay value (seconds)\n")
2959 {
2960 VTY_DECLVAR_CONTEXT(bgp, bgp);
2961
2962 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2963 return CMD_SUCCESS;
2964 }
2965
2966 DEFUN (no_bgp_graceful_restart_select_defer_time,
2967 no_bgp_graceful_restart_select_defer_time_cmd,
2968 "no bgp graceful-restart select-defer-time [(0-3600)]",
2969 NO_STR
2970 BGP_STR
2971 "Graceful restart capability parameters\n"
2972 "Set the time to defer the BGP route selection after restart\n"
2973 "Delay value (seconds)\n")
2974 {
2975 VTY_DECLVAR_CONTEXT(bgp, bgp);
2976
2977 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2978 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2979
2980 return CMD_SUCCESS;
2981 }
2982
2983 DEFUN (bgp_graceful_restart_preserve_fw,
2984 bgp_graceful_restart_preserve_fw_cmd,
2985 "bgp graceful-restart preserve-fw-state",
2986 BGP_STR
2987 "Graceful restart capability parameters\n"
2988 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2989 {
2990 VTY_DECLVAR_CONTEXT(bgp, bgp);
2991 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2992 return CMD_SUCCESS;
2993 }
2994
2995 DEFUN (no_bgp_graceful_restart_preserve_fw,
2996 no_bgp_graceful_restart_preserve_fw_cmd,
2997 "no bgp graceful-restart preserve-fw-state",
2998 NO_STR
2999 BGP_STR
3000 "Graceful restart capability parameters\n"
3001 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3002 {
3003 VTY_DECLVAR_CONTEXT(bgp, bgp);
3004 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3005 return CMD_SUCCESS;
3006 }
3007
3008 DEFPY (bgp_graceful_restart_notification,
3009 bgp_graceful_restart_notification_cmd,
3010 "[no$no] bgp graceful-restart notification",
3011 NO_STR
3012 BGP_STR
3013 "Graceful restart capability parameters\n"
3014 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3015 {
3016 VTY_DECLVAR_CONTEXT(bgp, bgp);
3017
3018 if (no)
3019 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3020 else
3021 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3022
3023 return CMD_SUCCESS;
3024 }
3025
3026 DEFPY (bgp_administrative_reset,
3027 bgp_administrative_reset_cmd,
3028 "[no$no] bgp hard-administrative-reset",
3029 NO_STR
3030 BGP_STR
3031 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3032 {
3033 VTY_DECLVAR_CONTEXT(bgp, bgp);
3034
3035 if (no)
3036 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3037 else
3038 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3039
3040 return CMD_SUCCESS;
3041 }
3042
3043 DEFUN (bgp_graceful_restart_disable,
3044 bgp_graceful_restart_disable_cmd,
3045 "bgp graceful-restart-disable",
3046 BGP_STR
3047 GR_DISABLE)
3048 {
3049 int ret = BGP_GR_FAILURE;
3050
3051 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3052 zlog_debug(
3053 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3054
3055 VTY_DECLVAR_CONTEXT(bgp, bgp);
3056
3057 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3058
3059 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3060 bgp->peer, ret);
3061
3062 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3063 zlog_debug(
3064 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3065 vty_out(vty,
3066 "Graceful restart configuration changed, reset all peers to take effect\n");
3067
3068 return bgp_vty_return(vty, ret);
3069 }
3070
3071 DEFUN (no_bgp_graceful_restart_disable,
3072 no_bgp_graceful_restart_disable_cmd,
3073 "no bgp graceful-restart-disable",
3074 NO_STR
3075 BGP_STR
3076 NO_GR_DISABLE
3077 )
3078 {
3079 VTY_DECLVAR_CONTEXT(bgp, bgp);
3080
3081 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3082 zlog_debug(
3083 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3084
3085 int ret = BGP_GR_FAILURE;
3086
3087 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3088
3089 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3090 ret);
3091
3092 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3093 zlog_debug(
3094 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3095 vty_out(vty,
3096 "Graceful restart configuration changed, reset all peers to take effect\n");
3097
3098 return bgp_vty_return(vty, ret);
3099 }
3100
3101 DEFUN (bgp_neighbor_graceful_restart_set,
3102 bgp_neighbor_graceful_restart_set_cmd,
3103 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3104 NEIGHBOR_STR
3105 NEIGHBOR_ADDR_STR2
3106 GR_NEIGHBOR_CMD
3107 )
3108 {
3109 int idx_peer = 1;
3110 struct peer *peer;
3111 int ret = BGP_GR_FAILURE;
3112
3113 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3114
3115 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3116 zlog_debug(
3117 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3118
3119 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3120 if (!peer)
3121 return CMD_WARNING_CONFIG_FAILED;
3122
3123 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3124
3125 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3126 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3127
3128 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3129 zlog_debug(
3130 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3131 vty_out(vty,
3132 "Graceful restart configuration changed, reset this peer to take effect\n");
3133
3134 return bgp_vty_return(vty, ret);
3135 }
3136
3137 DEFUN (no_bgp_neighbor_graceful_restart,
3138 no_bgp_neighbor_graceful_restart_set_cmd,
3139 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3140 NO_STR
3141 NEIGHBOR_STR
3142 NEIGHBOR_ADDR_STR2
3143 NO_GR_NEIGHBOR_CMD
3144 )
3145 {
3146 int idx_peer = 2;
3147 int ret = BGP_GR_FAILURE;
3148 struct peer *peer;
3149
3150 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3151
3152 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3153 if (!peer)
3154 return CMD_WARNING_CONFIG_FAILED;
3155
3156 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3157 zlog_debug(
3158 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3159
3160 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3161
3162 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3163 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3164
3165 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3166 zlog_debug(
3167 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3168 vty_out(vty,
3169 "Graceful restart configuration changed, reset this peer to take effect\n");
3170
3171 return bgp_vty_return(vty, ret);
3172 }
3173
3174 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3175 bgp_neighbor_graceful_restart_helper_set_cmd,
3176 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3177 NEIGHBOR_STR
3178 NEIGHBOR_ADDR_STR2
3179 GR_NEIGHBOR_HELPER_CMD
3180 )
3181 {
3182 int idx_peer = 1;
3183 struct peer *peer;
3184 int ret = BGP_GR_FAILURE;
3185
3186 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3187
3188 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3189 zlog_debug(
3190 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3191
3192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3193
3194 if (!peer)
3195 return CMD_WARNING_CONFIG_FAILED;
3196
3197
3198 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3199
3200 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3201 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3202
3203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3204 zlog_debug(
3205 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3206 vty_out(vty,
3207 "Graceful restart configuration changed, reset this peer to take effect\n");
3208
3209 return bgp_vty_return(vty, ret);
3210 }
3211
3212 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3213 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3214 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3215 NO_STR
3216 NEIGHBOR_STR
3217 NEIGHBOR_ADDR_STR2
3218 NO_GR_NEIGHBOR_HELPER_CMD
3219 )
3220 {
3221 int idx_peer = 2;
3222 int ret = BGP_GR_FAILURE;
3223 struct peer *peer;
3224
3225 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3226
3227 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3228 if (!peer)
3229 return CMD_WARNING_CONFIG_FAILED;
3230
3231 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3232 zlog_debug(
3233 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3234
3235 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3236
3237 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3238 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3239
3240 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3241 zlog_debug(
3242 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3243 vty_out(vty,
3244 "Graceful restart configuration changed, reset this peer to take effect\n");
3245
3246 return bgp_vty_return(vty, ret);
3247 }
3248
3249 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3250 bgp_neighbor_graceful_restart_disable_set_cmd,
3251 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3252 NEIGHBOR_STR
3253 NEIGHBOR_ADDR_STR2
3254 GR_NEIGHBOR_DISABLE_CMD
3255 )
3256 {
3257 int idx_peer = 1;
3258 struct peer *peer;
3259 int ret = BGP_GR_FAILURE;
3260
3261 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3262
3263 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3264 zlog_debug(
3265 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3266
3267 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3268 if (!peer)
3269 return CMD_WARNING_CONFIG_FAILED;
3270
3271 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3272
3273 if (peer->bgp->t_startup)
3274 bgp_peer_gr_flags_update(peer);
3275
3276 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3277 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3278
3279 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3280 zlog_debug(
3281 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3282 vty_out(vty,
3283 "Graceful restart configuration changed, reset this peer to take effect\n");
3284
3285 return bgp_vty_return(vty, ret);
3286 }
3287
3288 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3289 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3290 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3291 NO_STR
3292 NEIGHBOR_STR
3293 NEIGHBOR_ADDR_STR2
3294 NO_GR_NEIGHBOR_DISABLE_CMD
3295 )
3296 {
3297 int idx_peer = 2;
3298 int ret = BGP_GR_FAILURE;
3299 struct peer *peer;
3300
3301 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3302
3303 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3304 if (!peer)
3305 return CMD_WARNING_CONFIG_FAILED;
3306
3307 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3308 zlog_debug(
3309 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3310
3311 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3312
3313 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3314 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3315
3316 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3317 zlog_debug(
3318 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3319 vty_out(vty,
3320 "Graceful restart configuration changed, reset this peer to take effect\n");
3321
3322 return bgp_vty_return(vty, ret);
3323 }
3324
3325 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3326 bgp_graceful_restart_disable_eor_cmd,
3327 "bgp graceful-restart disable-eor",
3328 BGP_STR
3329 "Graceful restart configuration parameters\n"
3330 "Disable EOR Check\n")
3331 {
3332 VTY_DECLVAR_CONTEXT(bgp, bgp);
3333 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3334
3335 return CMD_SUCCESS;
3336 }
3337
3338 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3339 no_bgp_graceful_restart_disable_eor_cmd,
3340 "no bgp graceful-restart disable-eor",
3341 NO_STR
3342 BGP_STR
3343 "Graceful restart configuration parameters\n"
3344 "Disable EOR Check\n")
3345 {
3346 VTY_DECLVAR_CONTEXT(bgp, bgp);
3347 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3348
3349 return CMD_SUCCESS;
3350 }
3351
3352 DEFUN (bgp_graceful_restart_rib_stale_time,
3353 bgp_graceful_restart_rib_stale_time_cmd,
3354 "bgp graceful-restart rib-stale-time (1-3600)",
3355 BGP_STR
3356 "Graceful restart configuration parameters\n"
3357 "Specify the stale route removal timer in rib\n"
3358 "Delay value (seconds)\n")
3359 {
3360 VTY_DECLVAR_CONTEXT(bgp, bgp);
3361 int idx_number = 3;
3362 uint32_t stale_time;
3363
3364 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3365 bgp->rib_stale_time = stale_time;
3366 /* Send the stale timer update message to RIB */
3367 if (bgp_zebra_stale_timer_update(bgp))
3368 return CMD_WARNING;
3369
3370 return CMD_SUCCESS;
3371 }
3372
3373 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3374 no_bgp_graceful_restart_rib_stale_time_cmd,
3375 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3376 NO_STR
3377 BGP_STR
3378 "Graceful restart configuration parameters\n"
3379 "Specify the stale route removal timer in rib\n"
3380 "Delay value (seconds)\n")
3381 {
3382 VTY_DECLVAR_CONTEXT(bgp, bgp);
3383
3384 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3385 /* Send the stale timer update message to RIB */
3386 if (bgp_zebra_stale_timer_update(bgp))
3387 return CMD_WARNING;
3388
3389 return CMD_SUCCESS;
3390 }
3391
3392 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3393 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3394 BGP_STR
3395 "Enable Long-lived Graceful Restart\n"
3396 "Specifies maximum time to wait before purging long-lived stale routes\n"
3397 "Stale time value (seconds)\n")
3398 {
3399 VTY_DECLVAR_CONTEXT(bgp, bgp);
3400
3401 uint32_t llgr_stale_time;
3402
3403 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3404 bgp->llgr_stale_time = llgr_stale_time;
3405
3406 return CMD_SUCCESS;
3407 }
3408
3409 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3410 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3411 NO_STR BGP_STR
3412 "Enable Long-lived Graceful Restart\n"
3413 "Specifies maximum time to wait before purging long-lived stale routes\n"
3414 "Stale time value (seconds)\n")
3415 {
3416 VTY_DECLVAR_CONTEXT(bgp, bgp);
3417
3418 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3419
3420 return CMD_SUCCESS;
3421 }
3422
3423 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3424 struct bgp *bgp)
3425 {
3426 bgp_static_redo_import_check(bgp);
3427 bgp_redistribute_redo(bgp);
3428 bgp_clear_star_soft_out(vty, bgp->name);
3429 bgp_clear_star_soft_in(vty, bgp->name);
3430 }
3431
3432 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3433 {
3434 struct listnode *node, *nnode;
3435 struct bgp *bgp;
3436 bool vrf_cfg = false;
3437
3438 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3439 return CMD_SUCCESS;
3440
3441 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3442 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3443 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3444 vty_out(vty,
3445 "%% graceful-shutdown configuration found in vrf %s\n",
3446 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3447 VRF_DEFAULT_NAME : bgp->name);
3448 vrf_cfg = true;
3449 }
3450 }
3451
3452 if (vrf_cfg) {
3453 vty_out(vty,
3454 "%%Failed: global graceful-shutdown not permitted\n");
3455 return CMD_WARNING;
3456 }
3457
3458 /* Set flag globally */
3459 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3460
3461 /* Initiate processing for all BGP instances. */
3462 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3463 bgp_initiate_graceful_shut_unshut(vty, bgp);
3464
3465 return CMD_SUCCESS;
3466 }
3467
3468 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3469 {
3470 struct listnode *node, *nnode;
3471 struct bgp *bgp;
3472
3473 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3474 return CMD_SUCCESS;
3475
3476 /* Unset flag globally */
3477 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3478
3479 /* Initiate processing for all BGP instances. */
3480 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3481 bgp_initiate_graceful_shut_unshut(vty, bgp);
3482
3483 return CMD_SUCCESS;
3484 }
3485
3486 /* "bgp graceful-shutdown" configuration */
3487 DEFUN (bgp_graceful_shutdown,
3488 bgp_graceful_shutdown_cmd,
3489 "bgp graceful-shutdown",
3490 BGP_STR
3491 "Graceful shutdown parameters\n")
3492 {
3493 if (vty->node == CONFIG_NODE)
3494 return bgp_global_graceful_shutdown_config_vty(vty);
3495
3496 VTY_DECLVAR_CONTEXT(bgp, bgp);
3497
3498 /* if configured globally, per-instance config is not allowed */
3499 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3500 vty_out(vty,
3501 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3502 return CMD_WARNING_CONFIG_FAILED;
3503 }
3504
3505 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3506 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3507 bgp_initiate_graceful_shut_unshut(vty, bgp);
3508 }
3509
3510 return CMD_SUCCESS;
3511 }
3512
3513 DEFUN (no_bgp_graceful_shutdown,
3514 no_bgp_graceful_shutdown_cmd,
3515 "no bgp graceful-shutdown",
3516 NO_STR
3517 BGP_STR
3518 "Graceful shutdown parameters\n")
3519 {
3520 if (vty->node == CONFIG_NODE)
3521 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3522
3523 VTY_DECLVAR_CONTEXT(bgp, bgp);
3524
3525 /* If configured globally, cannot remove from one bgp instance */
3526 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3527 vty_out(vty,
3528 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3529 return CMD_WARNING_CONFIG_FAILED;
3530 }
3531
3532 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3533 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3534 bgp_initiate_graceful_shut_unshut(vty, bgp);
3535 }
3536
3537 return CMD_SUCCESS;
3538 }
3539
3540 /* "bgp fast-external-failover" configuration. */
3541 DEFUN (bgp_fast_external_failover,
3542 bgp_fast_external_failover_cmd,
3543 "bgp fast-external-failover",
3544 BGP_STR
3545 "Immediately reset session if a link to a directly connected external peer goes down\n")
3546 {
3547 VTY_DECLVAR_CONTEXT(bgp, bgp);
3548 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3549 return CMD_SUCCESS;
3550 }
3551
3552 DEFUN (no_bgp_fast_external_failover,
3553 no_bgp_fast_external_failover_cmd,
3554 "no bgp fast-external-failover",
3555 NO_STR
3556 BGP_STR
3557 "Immediately reset session if a link to a directly connected external peer goes down\n")
3558 {
3559 VTY_DECLVAR_CONTEXT(bgp, bgp);
3560 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3561 return CMD_SUCCESS;
3562 }
3563
3564 /* "bgp bestpath compare-routerid" configuration. */
3565 DEFUN (bgp_bestpath_compare_router_id,
3566 bgp_bestpath_compare_router_id_cmd,
3567 "bgp bestpath compare-routerid",
3568 BGP_STR
3569 "Change the default bestpath selection\n"
3570 "Compare router-id for identical EBGP paths\n")
3571 {
3572 VTY_DECLVAR_CONTEXT(bgp, bgp);
3573 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3574 bgp_recalculate_all_bestpaths(bgp);
3575
3576 return CMD_SUCCESS;
3577 }
3578
3579 DEFUN (no_bgp_bestpath_compare_router_id,
3580 no_bgp_bestpath_compare_router_id_cmd,
3581 "no bgp bestpath compare-routerid",
3582 NO_STR
3583 BGP_STR
3584 "Change the default bestpath selection\n"
3585 "Compare router-id for identical EBGP paths\n")
3586 {
3587 VTY_DECLVAR_CONTEXT(bgp, bgp);
3588 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3589 bgp_recalculate_all_bestpaths(bgp);
3590
3591 return CMD_SUCCESS;
3592 }
3593
3594 /* "bgp bestpath as-path ignore" configuration. */
3595 DEFUN (bgp_bestpath_aspath_ignore,
3596 bgp_bestpath_aspath_ignore_cmd,
3597 "bgp bestpath as-path ignore",
3598 BGP_STR
3599 "Change the default bestpath selection\n"
3600 "AS-path attribute\n"
3601 "Ignore as-path length in selecting a route\n")
3602 {
3603 VTY_DECLVAR_CONTEXT(bgp, bgp);
3604 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3605 bgp_recalculate_all_bestpaths(bgp);
3606
3607 return CMD_SUCCESS;
3608 }
3609
3610 DEFUN (no_bgp_bestpath_aspath_ignore,
3611 no_bgp_bestpath_aspath_ignore_cmd,
3612 "no bgp bestpath as-path ignore",
3613 NO_STR
3614 BGP_STR
3615 "Change the default bestpath selection\n"
3616 "AS-path attribute\n"
3617 "Ignore as-path length in selecting a route\n")
3618 {
3619 VTY_DECLVAR_CONTEXT(bgp, bgp);
3620 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3621 bgp_recalculate_all_bestpaths(bgp);
3622
3623 return CMD_SUCCESS;
3624 }
3625
3626 /* "bgp bestpath as-path confed" configuration. */
3627 DEFUN (bgp_bestpath_aspath_confed,
3628 bgp_bestpath_aspath_confed_cmd,
3629 "bgp bestpath as-path confed",
3630 BGP_STR
3631 "Change the default bestpath selection\n"
3632 "AS-path attribute\n"
3633 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3634 {
3635 VTY_DECLVAR_CONTEXT(bgp, bgp);
3636 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3637 bgp_recalculate_all_bestpaths(bgp);
3638
3639 return CMD_SUCCESS;
3640 }
3641
3642 DEFUN (no_bgp_bestpath_aspath_confed,
3643 no_bgp_bestpath_aspath_confed_cmd,
3644 "no bgp bestpath as-path confed",
3645 NO_STR
3646 BGP_STR
3647 "Change the default bestpath selection\n"
3648 "AS-path attribute\n"
3649 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3650 {
3651 VTY_DECLVAR_CONTEXT(bgp, bgp);
3652 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3653 bgp_recalculate_all_bestpaths(bgp);
3654
3655 return CMD_SUCCESS;
3656 }
3657
3658 /* "bgp bestpath as-path multipath-relax" configuration. */
3659 DEFUN (bgp_bestpath_aspath_multipath_relax,
3660 bgp_bestpath_aspath_multipath_relax_cmd,
3661 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3662 BGP_STR
3663 "Change the default bestpath selection\n"
3664 "AS-path attribute\n"
3665 "Allow load sharing across routes that have different AS paths (but same length)\n"
3666 "Generate an AS_SET\n"
3667 "Do not generate an AS_SET\n")
3668 {
3669 VTY_DECLVAR_CONTEXT(bgp, bgp);
3670 int idx = 0;
3671 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3672
3673 /* no-as-set is now the default behavior so we can silently
3674 * ignore it */
3675 if (argv_find(argv, argc, "as-set", &idx))
3676 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3677 else
3678 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3679
3680 bgp_recalculate_all_bestpaths(bgp);
3681
3682 return CMD_SUCCESS;
3683 }
3684
3685 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3686 no_bgp_bestpath_aspath_multipath_relax_cmd,
3687 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3688 NO_STR
3689 BGP_STR
3690 "Change the default bestpath selection\n"
3691 "AS-path attribute\n"
3692 "Allow load sharing across routes that have different AS paths (but same length)\n"
3693 "Generate an AS_SET\n"
3694 "Do not generate an AS_SET\n")
3695 {
3696 VTY_DECLVAR_CONTEXT(bgp, bgp);
3697 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3698 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3699 bgp_recalculate_all_bestpaths(bgp);
3700
3701 return CMD_SUCCESS;
3702 }
3703
3704 /* "bgp bestpath peer-type multipath-relax" configuration. */
3705 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3706 bgp_bestpath_peer_type_multipath_relax_cmd,
3707 "bgp bestpath peer-type multipath-relax",
3708 BGP_STR
3709 "Change the default bestpath selection\n"
3710 "Peer type\n"
3711 "Allow load sharing across routes learned from different peer types\n")
3712 {
3713 VTY_DECLVAR_CONTEXT(bgp, bgp);
3714 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3715 bgp_recalculate_all_bestpaths(bgp);
3716
3717 return CMD_SUCCESS;
3718 }
3719
3720 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3721 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3722 "no bgp bestpath peer-type multipath-relax",
3723 NO_STR BGP_STR
3724 "Change the default bestpath selection\n"
3725 "Peer type\n"
3726 "Allow load sharing across routes learned from different peer types\n")
3727 {
3728 VTY_DECLVAR_CONTEXT(bgp, bgp);
3729 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3730 bgp_recalculate_all_bestpaths(bgp);
3731
3732 return CMD_SUCCESS;
3733 }
3734
3735 /* "bgp log-neighbor-changes" configuration. */
3736 DEFUN (bgp_log_neighbor_changes,
3737 bgp_log_neighbor_changes_cmd,
3738 "bgp log-neighbor-changes",
3739 BGP_STR
3740 "Log neighbor up/down and reset reason\n")
3741 {
3742 VTY_DECLVAR_CONTEXT(bgp, bgp);
3743 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3744 return CMD_SUCCESS;
3745 }
3746
3747 DEFUN (no_bgp_log_neighbor_changes,
3748 no_bgp_log_neighbor_changes_cmd,
3749 "no bgp log-neighbor-changes",
3750 NO_STR
3751 BGP_STR
3752 "Log neighbor up/down and reset reason\n")
3753 {
3754 VTY_DECLVAR_CONTEXT(bgp, bgp);
3755 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3756 return CMD_SUCCESS;
3757 }
3758
3759 /* "bgp bestpath med" configuration. */
3760 DEFUN (bgp_bestpath_med,
3761 bgp_bestpath_med_cmd,
3762 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3763 BGP_STR
3764 "Change the default bestpath selection\n"
3765 "MED attribute\n"
3766 "Compare MED among confederation paths\n"
3767 "Treat missing MED as the least preferred one\n"
3768 "Treat missing MED as the least preferred one\n"
3769 "Compare MED among confederation paths\n")
3770 {
3771 VTY_DECLVAR_CONTEXT(bgp, bgp);
3772
3773 int idx = 0;
3774 if (argv_find(argv, argc, "confed", &idx))
3775 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3776 idx = 0;
3777 if (argv_find(argv, argc, "missing-as-worst", &idx))
3778 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3779
3780 bgp_recalculate_all_bestpaths(bgp);
3781
3782 return CMD_SUCCESS;
3783 }
3784
3785 DEFUN (no_bgp_bestpath_med,
3786 no_bgp_bestpath_med_cmd,
3787 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3788 NO_STR
3789 BGP_STR
3790 "Change the default bestpath selection\n"
3791 "MED attribute\n"
3792 "Compare MED among confederation paths\n"
3793 "Treat missing MED as the least preferred one\n"
3794 "Treat missing MED as the least preferred one\n"
3795 "Compare MED among confederation paths\n")
3796 {
3797 VTY_DECLVAR_CONTEXT(bgp, bgp);
3798
3799 int idx = 0;
3800 if (argv_find(argv, argc, "confed", &idx))
3801 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3802 idx = 0;
3803 if (argv_find(argv, argc, "missing-as-worst", &idx))
3804 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3805
3806 bgp_recalculate_all_bestpaths(bgp);
3807
3808 return CMD_SUCCESS;
3809 }
3810
3811 /* "bgp bestpath bandwidth" configuration. */
3812 DEFPY (bgp_bestpath_bw,
3813 bgp_bestpath_bw_cmd,
3814 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3815 BGP_STR
3816 "Change the default bestpath selection\n"
3817 "Link Bandwidth attribute\n"
3818 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3819 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3820 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3821 {
3822 VTY_DECLVAR_CONTEXT(bgp, bgp);
3823 afi_t afi;
3824 safi_t safi;
3825
3826 if (!bw_cfg) {
3827 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3828 return CMD_ERR_INCOMPLETE;
3829 }
3830 if (!strcmp(bw_cfg, "ignore"))
3831 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3832 else if (!strcmp(bw_cfg, "skip-missing"))
3833 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3834 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3835 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3836 else
3837 return CMD_ERR_NO_MATCH;
3838
3839 /* This config is used in route install, so redo that. */
3840 FOREACH_AFI_SAFI (afi, safi) {
3841 if (!bgp_fibupd_safi(safi))
3842 continue;
3843 bgp_zebra_announce_table(bgp, afi, safi);
3844 }
3845
3846 return CMD_SUCCESS;
3847 }
3848
3849 DEFPY (no_bgp_bestpath_bw,
3850 no_bgp_bestpath_bw_cmd,
3851 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3852 NO_STR
3853 BGP_STR
3854 "Change the default bestpath selection\n"
3855 "Link Bandwidth attribute\n"
3856 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3857 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3858 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3859 {
3860 VTY_DECLVAR_CONTEXT(bgp, bgp);
3861 afi_t afi;
3862 safi_t safi;
3863
3864 bgp->lb_handling = BGP_LINK_BW_ECMP;
3865
3866 /* This config is used in route install, so redo that. */
3867 FOREACH_AFI_SAFI (afi, safi) {
3868 if (!bgp_fibupd_safi(safi))
3869 continue;
3870 bgp_zebra_announce_table(bgp, afi, safi);
3871 }
3872 return CMD_SUCCESS;
3873 }
3874
3875 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3876 "[no] bgp default <ipv4-unicast|"
3877 "ipv4-multicast|"
3878 "ipv4-vpn|"
3879 "ipv4-labeled-unicast|"
3880 "ipv4-flowspec|"
3881 "ipv6-unicast|"
3882 "ipv6-multicast|"
3883 "ipv6-vpn|"
3884 "ipv6-labeled-unicast|"
3885 "ipv6-flowspec|"
3886 "l2vpn-evpn>$afi_safi",
3887 NO_STR
3888 BGP_STR
3889 "Configure BGP defaults\n"
3890 "Activate ipv4-unicast for a peer by default\n"
3891 "Activate ipv4-multicast for a peer by default\n"
3892 "Activate ipv4-vpn for a peer by default\n"
3893 "Activate ipv4-labeled-unicast for a peer by default\n"
3894 "Activate ipv4-flowspec for a peer by default\n"
3895 "Activate ipv6-unicast for a peer by default\n"
3896 "Activate ipv6-multicast for a peer by default\n"
3897 "Activate ipv6-vpn for a peer by default\n"
3898 "Activate ipv6-labeled-unicast for a peer by default\n"
3899 "Activate ipv6-flowspec for a peer by default\n"
3900 "Activate l2vpn-evpn for a peer by default\n")
3901 {
3902 VTY_DECLVAR_CONTEXT(bgp, bgp);
3903 char afi_safi_str[strlen(afi_safi) + 1];
3904 char *afi_safi_str_tok;
3905
3906 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3907 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3908 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3909 afi_t afi = bgp_vty_afi_from_str(afi_str);
3910 safi_t safi;
3911
3912 /*
3913 * Impossible situation but making coverity happy
3914 */
3915 assert(afi != AFI_MAX);
3916
3917 if (strmatch(safi_str, "labeled"))
3918 safi = bgp_vty_safi_from_str("labeled-unicast");
3919 else
3920 safi = bgp_vty_safi_from_str(safi_str);
3921
3922 assert(safi != SAFI_MAX);
3923 if (no)
3924 bgp->default_af[afi][safi] = false;
3925 else {
3926 if ((safi == SAFI_LABELED_UNICAST
3927 && bgp->default_af[afi][SAFI_UNICAST])
3928 || (safi == SAFI_UNICAST
3929 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3930 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3931 else
3932 bgp->default_af[afi][safi] = true;
3933 }
3934
3935 return CMD_SUCCESS;
3936 }
3937
3938 /* Display hostname in certain command outputs */
3939 DEFUN (bgp_default_show_hostname,
3940 bgp_default_show_hostname_cmd,
3941 "bgp default show-hostname",
3942 BGP_STR
3943 "Configure BGP defaults\n"
3944 "Show hostname in certain command outputs\n")
3945 {
3946 VTY_DECLVAR_CONTEXT(bgp, bgp);
3947 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3948 return CMD_SUCCESS;
3949 }
3950
3951 DEFUN (no_bgp_default_show_hostname,
3952 no_bgp_default_show_hostname_cmd,
3953 "no bgp default show-hostname",
3954 NO_STR
3955 BGP_STR
3956 "Configure BGP defaults\n"
3957 "Show hostname in certain command outputs\n")
3958 {
3959 VTY_DECLVAR_CONTEXT(bgp, bgp);
3960 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3961 return CMD_SUCCESS;
3962 }
3963
3964 /* Display hostname in certain command outputs */
3965 DEFUN (bgp_default_show_nexthop_hostname,
3966 bgp_default_show_nexthop_hostname_cmd,
3967 "bgp default show-nexthop-hostname",
3968 BGP_STR
3969 "Configure BGP defaults\n"
3970 "Show hostname for nexthop in certain command outputs\n")
3971 {
3972 VTY_DECLVAR_CONTEXT(bgp, bgp);
3973 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3974 return CMD_SUCCESS;
3975 }
3976
3977 DEFUN (no_bgp_default_show_nexthop_hostname,
3978 no_bgp_default_show_nexthop_hostname_cmd,
3979 "no bgp default show-nexthop-hostname",
3980 NO_STR
3981 BGP_STR
3982 "Configure BGP defaults\n"
3983 "Show hostname for nexthop in certain command outputs\n")
3984 {
3985 VTY_DECLVAR_CONTEXT(bgp, bgp);
3986 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3987 return CMD_SUCCESS;
3988 }
3989
3990 /* "bgp network import-check" configuration. */
3991 DEFUN (bgp_network_import_check,
3992 bgp_network_import_check_cmd,
3993 "bgp network import-check",
3994 BGP_STR
3995 "BGP network command\n"
3996 "Check BGP network route exists in IGP\n")
3997 {
3998 VTY_DECLVAR_CONTEXT(bgp, bgp);
3999 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4000 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4001 bgp_static_redo_import_check(bgp);
4002 }
4003
4004 return CMD_SUCCESS;
4005 }
4006
4007 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4008 "bgp network import-check exact",
4009 BGP_STR
4010 "BGP network command\n"
4011 "Check BGP network route exists in IGP\n"
4012 "Match route precisely\n")
4013
4014 DEFUN (no_bgp_network_import_check,
4015 no_bgp_network_import_check_cmd,
4016 "no bgp network import-check",
4017 NO_STR
4018 BGP_STR
4019 "BGP network command\n"
4020 "Check BGP network route exists in IGP\n")
4021 {
4022 VTY_DECLVAR_CONTEXT(bgp, bgp);
4023 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4024 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4025 bgp_static_redo_import_check(bgp);
4026 }
4027
4028 return CMD_SUCCESS;
4029 }
4030
4031 DEFUN (bgp_default_local_preference,
4032 bgp_default_local_preference_cmd,
4033 "bgp default local-preference (0-4294967295)",
4034 BGP_STR
4035 "Configure BGP defaults\n"
4036 "local preference (higher=more preferred)\n"
4037 "Configure default local preference value\n")
4038 {
4039 VTY_DECLVAR_CONTEXT(bgp, bgp);
4040 int idx_number = 3;
4041 uint32_t local_pref;
4042
4043 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4044
4045 bgp_default_local_preference_set(bgp, local_pref);
4046 bgp_clear_star_soft_in(vty, bgp->name);
4047
4048 return CMD_SUCCESS;
4049 }
4050
4051 DEFUN (no_bgp_default_local_preference,
4052 no_bgp_default_local_preference_cmd,
4053 "no bgp default local-preference [(0-4294967295)]",
4054 NO_STR
4055 BGP_STR
4056 "Configure BGP defaults\n"
4057 "local preference (higher=more preferred)\n"
4058 "Configure default local preference value\n")
4059 {
4060 VTY_DECLVAR_CONTEXT(bgp, bgp);
4061 bgp_default_local_preference_unset(bgp);
4062 bgp_clear_star_soft_in(vty, bgp->name);
4063
4064 return CMD_SUCCESS;
4065 }
4066
4067
4068 DEFUN (bgp_default_subgroup_pkt_queue_max,
4069 bgp_default_subgroup_pkt_queue_max_cmd,
4070 "bgp default subgroup-pkt-queue-max (20-100)",
4071 BGP_STR
4072 "Configure BGP defaults\n"
4073 "subgroup-pkt-queue-max\n"
4074 "Configure subgroup packet queue max\n")
4075 {
4076 VTY_DECLVAR_CONTEXT(bgp, bgp);
4077 int idx_number = 3;
4078 uint32_t max_size;
4079
4080 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4081
4082 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4083
4084 return CMD_SUCCESS;
4085 }
4086
4087 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4088 no_bgp_default_subgroup_pkt_queue_max_cmd,
4089 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4090 NO_STR
4091 BGP_STR
4092 "Configure BGP defaults\n"
4093 "subgroup-pkt-queue-max\n"
4094 "Configure subgroup packet queue max\n")
4095 {
4096 VTY_DECLVAR_CONTEXT(bgp, bgp);
4097 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4098 return CMD_SUCCESS;
4099 }
4100
4101
4102 DEFUN (bgp_rr_allow_outbound_policy,
4103 bgp_rr_allow_outbound_policy_cmd,
4104 "bgp route-reflector allow-outbound-policy",
4105 BGP_STR
4106 "Allow modifications made by out route-map\n"
4107 "on ibgp neighbors\n")
4108 {
4109 VTY_DECLVAR_CONTEXT(bgp, bgp);
4110
4111 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4112 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4113 update_group_announce_rrclients(bgp);
4114 bgp_clear_star_soft_out(vty, bgp->name);
4115 }
4116
4117 return CMD_SUCCESS;
4118 }
4119
4120 DEFUN (no_bgp_rr_allow_outbound_policy,
4121 no_bgp_rr_allow_outbound_policy_cmd,
4122 "no bgp route-reflector allow-outbound-policy",
4123 NO_STR
4124 BGP_STR
4125 "Allow modifications made by out route-map\n"
4126 "on ibgp neighbors\n")
4127 {
4128 VTY_DECLVAR_CONTEXT(bgp, bgp);
4129
4130 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4131 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4132 update_group_announce_rrclients(bgp);
4133 bgp_clear_star_soft_out(vty, bgp->name);
4134 }
4135
4136 return CMD_SUCCESS;
4137 }
4138
4139 DEFUN (bgp_listen_limit,
4140 bgp_listen_limit_cmd,
4141 "bgp listen limit (1-65535)",
4142 BGP_STR
4143 "BGP Dynamic Neighbors listen commands\n"
4144 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4145 "Configure Dynamic Neighbors listen limit value\n")
4146 {
4147 VTY_DECLVAR_CONTEXT(bgp, bgp);
4148 int idx_number = 3;
4149 int listen_limit;
4150
4151 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4152
4153 bgp_listen_limit_set(bgp, listen_limit);
4154
4155 return CMD_SUCCESS;
4156 }
4157
4158 DEFUN (no_bgp_listen_limit,
4159 no_bgp_listen_limit_cmd,
4160 "no bgp listen limit [(1-65535)]",
4161 NO_STR
4162 BGP_STR
4163 "BGP Dynamic Neighbors listen commands\n"
4164 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4165 "Configure Dynamic Neighbors listen limit value\n")
4166 {
4167 VTY_DECLVAR_CONTEXT(bgp, bgp);
4168 bgp_listen_limit_unset(bgp);
4169 return CMD_SUCCESS;
4170 }
4171
4172
4173 /*
4174 * Check if this listen range is already configured. Check for exact
4175 * match or overlap based on input.
4176 */
4177 static struct peer_group *listen_range_exists(struct bgp *bgp,
4178 struct prefix *range, int exact)
4179 {
4180 struct listnode *node, *nnode;
4181 struct listnode *node1, *nnode1;
4182 struct peer_group *group;
4183 struct prefix *lr;
4184 afi_t afi;
4185 int match;
4186
4187 afi = family2afi(range->family);
4188 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4189 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4190 lr)) {
4191 if (exact)
4192 match = prefix_same(range, lr);
4193 else
4194 match = (prefix_match(range, lr)
4195 || prefix_match(lr, range));
4196 if (match)
4197 return group;
4198 }
4199 }
4200
4201 return NULL;
4202 }
4203
4204 DEFUN (bgp_listen_range,
4205 bgp_listen_range_cmd,
4206 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4207 BGP_STR
4208 "Configure BGP dynamic neighbors listen range\n"
4209 "Configure BGP dynamic neighbors listen range\n"
4210 NEIGHBOR_ADDR_STR
4211 "Member of the peer-group\n"
4212 "Peer-group name\n")
4213 {
4214 VTY_DECLVAR_CONTEXT(bgp, bgp);
4215 struct prefix range;
4216 struct peer_group *group, *existing_group;
4217 afi_t afi;
4218 int ret;
4219 int idx = 0;
4220
4221 argv_find(argv, argc, "A.B.C.D/M", &idx);
4222 argv_find(argv, argc, "X:X::X:X/M", &idx);
4223 char *prefix = argv[idx]->arg;
4224 argv_find(argv, argc, "PGNAME", &idx);
4225 char *peergroup = argv[idx]->arg;
4226
4227 /* Convert IP prefix string to struct prefix. */
4228 ret = str2prefix(prefix, &range);
4229 if (!ret) {
4230 vty_out(vty, "%% Malformed listen range\n");
4231 return CMD_WARNING_CONFIG_FAILED;
4232 }
4233
4234 afi = family2afi(range.family);
4235
4236 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4237 vty_out(vty,
4238 "%% Malformed listen range (link-local address)\n");
4239 return CMD_WARNING_CONFIG_FAILED;
4240 }
4241
4242 apply_mask(&range);
4243
4244 /* Check if same listen range is already configured. */
4245 existing_group = listen_range_exists(bgp, &range, 1);
4246 if (existing_group) {
4247 if (strcmp(existing_group->name, peergroup) == 0)
4248 return CMD_SUCCESS;
4249 else {
4250 vty_out(vty,
4251 "%% Same listen range is attached to peer-group %s\n",
4252 existing_group->name);
4253 return CMD_WARNING_CONFIG_FAILED;
4254 }
4255 }
4256
4257 /* Check if an overlapping listen range exists. */
4258 if (listen_range_exists(bgp, &range, 0)) {
4259 vty_out(vty,
4260 "%% Listen range overlaps with existing listen range\n");
4261 return CMD_WARNING_CONFIG_FAILED;
4262 }
4263
4264 group = peer_group_lookup(bgp, peergroup);
4265 if (!group) {
4266 vty_out(vty, "%% Configure the peer-group first\n");
4267 return CMD_WARNING_CONFIG_FAILED;
4268 }
4269
4270 ret = peer_group_listen_range_add(group, &range);
4271 return bgp_vty_return(vty, ret);
4272 }
4273
4274 DEFUN (no_bgp_listen_range,
4275 no_bgp_listen_range_cmd,
4276 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4277 NO_STR
4278 BGP_STR
4279 "Unconfigure BGP dynamic neighbors listen range\n"
4280 "Unconfigure BGP dynamic neighbors listen range\n"
4281 NEIGHBOR_ADDR_STR
4282 "Member of the peer-group\n"
4283 "Peer-group name\n")
4284 {
4285 VTY_DECLVAR_CONTEXT(bgp, bgp);
4286 struct prefix range;
4287 struct peer_group *group;
4288 afi_t afi;
4289 int ret;
4290 int idx = 0;
4291
4292 argv_find(argv, argc, "A.B.C.D/M", &idx);
4293 argv_find(argv, argc, "X:X::X:X/M", &idx);
4294 char *prefix = argv[idx]->arg;
4295 argv_find(argv, argc, "PGNAME", &idx);
4296 char *peergroup = argv[idx]->arg;
4297
4298 /* Convert IP prefix string to struct prefix. */
4299 ret = str2prefix(prefix, &range);
4300 if (!ret) {
4301 vty_out(vty, "%% Malformed listen range\n");
4302 return CMD_WARNING_CONFIG_FAILED;
4303 }
4304
4305 afi = family2afi(range.family);
4306
4307 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4308 vty_out(vty,
4309 "%% Malformed listen range (link-local address)\n");
4310 return CMD_WARNING_CONFIG_FAILED;
4311 }
4312
4313 apply_mask(&range);
4314
4315 group = peer_group_lookup(bgp, peergroup);
4316 if (!group) {
4317 vty_out(vty, "%% Peer-group does not exist\n");
4318 return CMD_WARNING_CONFIG_FAILED;
4319 }
4320
4321 ret = peer_group_listen_range_del(group, &range);
4322 return bgp_vty_return(vty, ret);
4323 }
4324
4325 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4326 {
4327 struct peer_group *group;
4328 struct listnode *node, *nnode, *rnode, *nrnode;
4329 struct prefix *range;
4330 afi_t afi;
4331
4332 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4333 vty_out(vty, " bgp listen limit %d\n",
4334 bgp->dynamic_neighbors_limit);
4335
4336 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4337 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4338 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4339 nrnode, range)) {
4340 vty_out(vty,
4341 " bgp listen range %pFX peer-group %s\n",
4342 range, group->name);
4343 }
4344 }
4345 }
4346 }
4347
4348
4349 DEFUN (bgp_disable_connected_route_check,
4350 bgp_disable_connected_route_check_cmd,
4351 "bgp disable-ebgp-connected-route-check",
4352 BGP_STR
4353 "Disable checking if nexthop is connected on ebgp sessions\n")
4354 {
4355 VTY_DECLVAR_CONTEXT(bgp, bgp);
4356 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4357 bgp_clear_star_soft_in(vty, bgp->name);
4358
4359 return CMD_SUCCESS;
4360 }
4361
4362 DEFUN (no_bgp_disable_connected_route_check,
4363 no_bgp_disable_connected_route_check_cmd,
4364 "no bgp disable-ebgp-connected-route-check",
4365 NO_STR
4366 BGP_STR
4367 "Disable checking if nexthop is connected on ebgp sessions\n")
4368 {
4369 VTY_DECLVAR_CONTEXT(bgp, bgp);
4370 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4371 bgp_clear_star_soft_in(vty, bgp->name);
4372
4373 return CMD_SUCCESS;
4374 }
4375
4376
4377 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4378 const char *as_str)
4379 {
4380 VTY_DECLVAR_CONTEXT(bgp, bgp);
4381 int ret;
4382 as_t as;
4383 int as_type = AS_SPECIFIED;
4384 union sockunion su;
4385
4386 if (as_str[0] == 'i') {
4387 as = 0;
4388 as_type = AS_INTERNAL;
4389 } else if (as_str[0] == 'e') {
4390 as = 0;
4391 as_type = AS_EXTERNAL;
4392 } else {
4393 /* Get AS number. */
4394 as = strtoul(as_str, NULL, 10);
4395 }
4396
4397 /* If peer is peer group or interface peer, call proper function. */
4398 ret = str2sockunion(peer_str, &su);
4399 if (ret < 0) {
4400 struct peer *peer;
4401
4402 /* Check if existing interface peer */
4403 peer = peer_lookup_by_conf_if(bgp, peer_str);
4404
4405 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4406
4407 /* if not interface peer, check peer-group settings */
4408 if (ret < 0 && !peer) {
4409 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4410 if (ret < 0) {
4411 vty_out(vty,
4412 "%% Create the peer-group or interface first\n");
4413 return CMD_WARNING_CONFIG_FAILED;
4414 }
4415 return CMD_SUCCESS;
4416 }
4417 } else {
4418 if (peer_address_self_check(bgp, &su)) {
4419 vty_out(vty,
4420 "%% Can not configure the local system as neighbor\n");
4421 return CMD_WARNING_CONFIG_FAILED;
4422 }
4423 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4424 }
4425
4426 return bgp_vty_return(vty, ret);
4427 }
4428
4429 DEFUN (bgp_default_shutdown,
4430 bgp_default_shutdown_cmd,
4431 "[no] bgp default shutdown",
4432 NO_STR
4433 BGP_STR
4434 "Configure BGP defaults\n"
4435 "Apply administrative shutdown to newly configured peers\n")
4436 {
4437 VTY_DECLVAR_CONTEXT(bgp, bgp);
4438 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4439 return CMD_SUCCESS;
4440 }
4441
4442 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4443 BGP_STR
4444 "Administrative shutdown of the BGP instance\n"
4445 "Add a shutdown message (RFC 8203)\n"
4446 "Shutdown message\n")
4447 {
4448 char *msgstr = NULL;
4449
4450 VTY_DECLVAR_CONTEXT(bgp, bgp);
4451
4452 if (argc > 3)
4453 msgstr = argv_concat(argv, argc, 3);
4454
4455 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4456 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4457 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4458 return CMD_WARNING_CONFIG_FAILED;
4459 }
4460
4461 bgp_shutdown_enable(bgp, msgstr);
4462 XFREE(MTYPE_TMP, msgstr);
4463
4464 return CMD_SUCCESS;
4465 }
4466
4467 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4468 BGP_STR "Administrative shutdown of the BGP instance\n")
4469 {
4470 VTY_DECLVAR_CONTEXT(bgp, bgp);
4471
4472 bgp_shutdown_enable(bgp, NULL);
4473
4474 return CMD_SUCCESS;
4475 }
4476
4477 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4478 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4479 {
4480 VTY_DECLVAR_CONTEXT(bgp, bgp);
4481
4482 bgp_shutdown_disable(bgp);
4483
4484 return CMD_SUCCESS;
4485 }
4486
4487 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4488 "no bgp shutdown message MSG...", NO_STR BGP_STR
4489 "Administrative shutdown of the BGP instance\n"
4490 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4491
4492 DEFUN (neighbor_remote_as,
4493 neighbor_remote_as_cmd,
4494 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4495 NEIGHBOR_STR
4496 NEIGHBOR_ADDR_STR2
4497 "Specify a BGP neighbor\n"
4498 AS_STR
4499 "Internal BGP peer\n"
4500 "External BGP peer\n")
4501 {
4502 int idx_peer = 1;
4503 int idx_remote_as = 3;
4504 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4505 argv[idx_remote_as]->arg);
4506 }
4507
4508 DEFPY (bgp_allow_martian,
4509 bgp_allow_martian_cmd,
4510 "[no]$no bgp allow-martian-nexthop",
4511 NO_STR
4512 BGP_STR
4513 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4514 {
4515 VTY_DECLVAR_CONTEXT(bgp, bgp);
4516
4517 if (no)
4518 bgp->allow_martian = false;
4519 else
4520 bgp->allow_martian = true;
4521
4522 return CMD_SUCCESS;
4523 }
4524
4525 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4526 * sessions do not wait for hold timer expiry to bring down the sessions
4527 * when nexthop becomes unreachable
4528 */
4529 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4530 BGP_STR "Fast convergence for bgp sessions\n")
4531 {
4532 VTY_DECLVAR_CONTEXT(bgp, bgp);
4533 bgp->fast_convergence = true;
4534
4535 return CMD_SUCCESS;
4536 }
4537
4538 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4539 "no bgp fast-convergence",
4540 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4541 {
4542 VTY_DECLVAR_CONTEXT(bgp, bgp);
4543 bgp->fast_convergence = false;
4544
4545 return CMD_SUCCESS;
4546 }
4547
4548 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4549 int v6only,
4550 const char *peer_group_name,
4551 const char *as_str)
4552 {
4553 VTY_DECLVAR_CONTEXT(bgp, bgp);
4554 as_t as = 0;
4555 int as_type = AS_UNSPECIFIED;
4556 struct peer *peer;
4557 struct peer_group *group;
4558 int ret = 0;
4559
4560 group = peer_group_lookup(bgp, conf_if);
4561
4562 if (group) {
4563 vty_out(vty, "%% Name conflict with peer-group \n");
4564 return CMD_WARNING_CONFIG_FAILED;
4565 }
4566
4567 if (as_str) {
4568 if (as_str[0] == 'i') {
4569 as_type = AS_INTERNAL;
4570 } else if (as_str[0] == 'e') {
4571 as_type = AS_EXTERNAL;
4572 } else {
4573 /* Get AS number. */
4574 as = strtoul(as_str, NULL, 10);
4575 as_type = AS_SPECIFIED;
4576 }
4577 }
4578
4579 peer = peer_lookup_by_conf_if(bgp, conf_if);
4580 if (peer) {
4581 if (as_str)
4582 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4583 } else {
4584 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4585 NULL);
4586
4587 if (!peer) {
4588 vty_out(vty, "%% BGP failed to create peer\n");
4589 return CMD_WARNING_CONFIG_FAILED;
4590 }
4591
4592 if (v6only)
4593 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4594
4595 /* Request zebra to initiate IPv6 RAs on this interface. We do
4596 * this
4597 * any unnumbered peer in order to not worry about run-time
4598 * transitions
4599 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4600 * address
4601 * gets deleted later etc.)
4602 */
4603 if (peer->ifp)
4604 bgp_zebra_initiate_radv(bgp, peer);
4605 }
4606
4607 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4608 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4609 if (v6only)
4610 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4611 else
4612 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4613
4614 /* v6only flag changed. Reset bgp seesion */
4615 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4616 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4617 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4618 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4619 } else
4620 bgp_session_reset(peer);
4621 }
4622
4623 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4624 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4625 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4626 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4627 }
4628
4629 if (peer_group_name) {
4630 group = peer_group_lookup(bgp, peer_group_name);
4631 if (!group) {
4632 vty_out(vty, "%% Configure the peer-group first\n");
4633 return CMD_WARNING_CONFIG_FAILED;
4634 }
4635
4636 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4637 }
4638
4639 return bgp_vty_return(vty, ret);
4640 }
4641
4642 DEFUN (neighbor_interface_config,
4643 neighbor_interface_config_cmd,
4644 "neighbor WORD interface [peer-group PGNAME]",
4645 NEIGHBOR_STR
4646 "Interface name or neighbor tag\n"
4647 "Enable BGP on interface\n"
4648 "Member of the peer-group\n"
4649 "Peer-group name\n")
4650 {
4651 int idx_word = 1;
4652 int idx_peer_group_word = 4;
4653
4654 if (argc > idx_peer_group_word)
4655 return peer_conf_interface_get(
4656 vty, argv[idx_word]->arg, 0,
4657 argv[idx_peer_group_word]->arg, NULL);
4658 else
4659 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4660 NULL, NULL);
4661 }
4662
4663 DEFUN (neighbor_interface_config_v6only,
4664 neighbor_interface_config_v6only_cmd,
4665 "neighbor WORD interface v6only [peer-group PGNAME]",
4666 NEIGHBOR_STR
4667 "Interface name or neighbor tag\n"
4668 "Enable BGP on interface\n"
4669 "Enable BGP with v6 link-local only\n"
4670 "Member of the peer-group\n"
4671 "Peer-group name\n")
4672 {
4673 int idx_word = 1;
4674 int idx_peer_group_word = 5;
4675
4676 if (argc > idx_peer_group_word)
4677 return peer_conf_interface_get(
4678 vty, argv[idx_word]->arg, 1,
4679 argv[idx_peer_group_word]->arg, NULL);
4680
4681 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4682 }
4683
4684
4685 DEFUN (neighbor_interface_config_remote_as,
4686 neighbor_interface_config_remote_as_cmd,
4687 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4688 NEIGHBOR_STR
4689 "Interface name or neighbor tag\n"
4690 "Enable BGP on interface\n"
4691 "Specify a BGP neighbor\n"
4692 AS_STR
4693 "Internal BGP peer\n"
4694 "External BGP peer\n")
4695 {
4696 int idx_word = 1;
4697 int idx_remote_as = 4;
4698 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4699 argv[idx_remote_as]->arg);
4700 }
4701
4702 DEFUN (neighbor_interface_v6only_config_remote_as,
4703 neighbor_interface_v6only_config_remote_as_cmd,
4704 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4705 NEIGHBOR_STR
4706 "Interface name or neighbor tag\n"
4707 "Enable BGP with v6 link-local only\n"
4708 "Enable BGP on interface\n"
4709 "Specify a BGP neighbor\n"
4710 AS_STR
4711 "Internal BGP peer\n"
4712 "External BGP peer\n")
4713 {
4714 int idx_word = 1;
4715 int idx_remote_as = 5;
4716 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4717 argv[idx_remote_as]->arg);
4718 }
4719
4720 DEFUN (neighbor_peer_group,
4721 neighbor_peer_group_cmd,
4722 "neighbor WORD peer-group",
4723 NEIGHBOR_STR
4724 "Interface name or neighbor tag\n"
4725 "Configure peer-group\n")
4726 {
4727 VTY_DECLVAR_CONTEXT(bgp, bgp);
4728 int idx_word = 1;
4729 struct peer *peer;
4730 struct peer_group *group;
4731
4732 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4733 if (peer) {
4734 vty_out(vty, "%% Name conflict with interface: \n");
4735 return CMD_WARNING_CONFIG_FAILED;
4736 }
4737
4738 group = peer_group_get(bgp, argv[idx_word]->arg);
4739 if (!group) {
4740 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4741 return CMD_WARNING_CONFIG_FAILED;
4742 }
4743
4744 return CMD_SUCCESS;
4745 }
4746
4747 DEFUN (no_neighbor,
4748 no_neighbor_cmd,
4749 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4750 NO_STR
4751 NEIGHBOR_STR
4752 NEIGHBOR_ADDR_STR2
4753 "Specify a BGP neighbor\n"
4754 AS_STR
4755 "Internal BGP peer\n"
4756 "External BGP peer\n")
4757 {
4758 VTY_DECLVAR_CONTEXT(bgp, bgp);
4759 int idx_peer = 2;
4760 int ret;
4761 union sockunion su;
4762 struct peer_group *group;
4763 struct peer *peer;
4764 struct peer *other;
4765
4766 ret = str2sockunion(argv[idx_peer]->arg, &su);
4767 if (ret < 0) {
4768 /* look up for neighbor by interface name config. */
4769 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4770 if (peer) {
4771 /* Request zebra to terminate IPv6 RAs on this
4772 * interface. */
4773 if (peer->ifp)
4774 bgp_zebra_terminate_radv(peer->bgp, peer);
4775 peer_notify_unconfig(peer);
4776 peer_delete(peer);
4777 return CMD_SUCCESS;
4778 }
4779
4780 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4781 if (group) {
4782 peer_group_notify_unconfig(group);
4783 peer_group_delete(group);
4784 } else {
4785 vty_out(vty, "%% Create the peer-group first\n");
4786 return CMD_WARNING_CONFIG_FAILED;
4787 }
4788 } else {
4789 peer = peer_lookup(bgp, &su);
4790 if (peer) {
4791 if (peer_dynamic_neighbor(peer)) {
4792 vty_out(vty,
4793 "%% Operation not allowed on a dynamic neighbor\n");
4794 return CMD_WARNING_CONFIG_FAILED;
4795 }
4796
4797 other = peer->doppelganger;
4798
4799 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4800 bgp_zebra_terminate_radv(peer->bgp, peer);
4801
4802 peer_notify_unconfig(peer);
4803 peer_delete(peer);
4804 if (other && other->status != Deleted) {
4805 peer_notify_unconfig(other);
4806 peer_delete(other);
4807 }
4808 }
4809 }
4810
4811 return CMD_SUCCESS;
4812 }
4813
4814 DEFUN (no_neighbor_interface_config,
4815 no_neighbor_interface_config_cmd,
4816 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4817 NO_STR
4818 NEIGHBOR_STR
4819 "Interface name\n"
4820 "Configure BGP on interface\n"
4821 "Enable BGP with v6 link-local only\n"
4822 "Member of the peer-group\n"
4823 "Peer-group name\n"
4824 "Specify a BGP neighbor\n"
4825 AS_STR
4826 "Internal BGP peer\n"
4827 "External BGP peer\n")
4828 {
4829 VTY_DECLVAR_CONTEXT(bgp, bgp);
4830 int idx_word = 2;
4831 struct peer *peer;
4832
4833 /* look up for neighbor by interface name config. */
4834 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4835 if (peer) {
4836 /* Request zebra to terminate IPv6 RAs on this interface. */
4837 if (peer->ifp)
4838 bgp_zebra_terminate_radv(peer->bgp, peer);
4839 peer_notify_unconfig(peer);
4840 peer_delete(peer);
4841 } else {
4842 vty_out(vty, "%% Create the bgp interface first\n");
4843 return CMD_WARNING_CONFIG_FAILED;
4844 }
4845 return CMD_SUCCESS;
4846 }
4847
4848 DEFUN (no_neighbor_peer_group,
4849 no_neighbor_peer_group_cmd,
4850 "no neighbor WORD peer-group",
4851 NO_STR
4852 NEIGHBOR_STR
4853 "Neighbor tag\n"
4854 "Configure peer-group\n")
4855 {
4856 VTY_DECLVAR_CONTEXT(bgp, bgp);
4857 int idx_word = 2;
4858 struct peer_group *group;
4859
4860 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4861 if (group) {
4862 peer_group_notify_unconfig(group);
4863 peer_group_delete(group);
4864 } else {
4865 vty_out(vty, "%% Create the peer-group first\n");
4866 return CMD_WARNING_CONFIG_FAILED;
4867 }
4868 return CMD_SUCCESS;
4869 }
4870
4871 DEFUN (no_neighbor_interface_peer_group_remote_as,
4872 no_neighbor_interface_peer_group_remote_as_cmd,
4873 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4874 NO_STR
4875 NEIGHBOR_STR
4876 "Interface name or neighbor tag\n"
4877 "Specify a BGP neighbor\n"
4878 AS_STR
4879 "Internal BGP peer\n"
4880 "External BGP peer\n")
4881 {
4882 VTY_DECLVAR_CONTEXT(bgp, bgp);
4883 int idx_word = 2;
4884 struct peer_group *group;
4885 struct peer *peer;
4886
4887 /* look up for neighbor by interface name config. */
4888 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4889 if (peer) {
4890 peer_as_change(peer, 0, AS_UNSPECIFIED);
4891 return CMD_SUCCESS;
4892 }
4893
4894 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4895 if (group)
4896 peer_group_remote_as_delete(group);
4897 else {
4898 vty_out(vty, "%% Create the peer-group or interface first\n");
4899 return CMD_WARNING_CONFIG_FAILED;
4900 }
4901 return CMD_SUCCESS;
4902 }
4903
4904 DEFUN (neighbor_local_as,
4905 neighbor_local_as_cmd,
4906 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4907 NEIGHBOR_STR
4908 NEIGHBOR_ADDR_STR2
4909 "Specify a local-as number\n"
4910 "AS number used as local AS\n")
4911 {
4912 int idx_peer = 1;
4913 int idx_number = 3;
4914 struct peer *peer;
4915 int ret;
4916 as_t as;
4917
4918 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4919 if (!peer)
4920 return CMD_WARNING_CONFIG_FAILED;
4921
4922 as = strtoul(argv[idx_number]->arg, NULL, 10);
4923 ret = peer_local_as_set(peer, as, 0, 0);
4924 return bgp_vty_return(vty, ret);
4925 }
4926
4927 DEFUN (neighbor_local_as_no_prepend,
4928 neighbor_local_as_no_prepend_cmd,
4929 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4930 NEIGHBOR_STR
4931 NEIGHBOR_ADDR_STR2
4932 "Specify a local-as number\n"
4933 "AS number used as local AS\n"
4934 "Do not prepend local-as to updates from ebgp peers\n")
4935 {
4936 int idx_peer = 1;
4937 int idx_number = 3;
4938 struct peer *peer;
4939 int ret;
4940 as_t as;
4941
4942 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4943 if (!peer)
4944 return CMD_WARNING_CONFIG_FAILED;
4945
4946 as = strtoul(argv[idx_number]->arg, NULL, 10);
4947 ret = peer_local_as_set(peer, as, 1, 0);
4948 return bgp_vty_return(vty, ret);
4949 }
4950
4951 DEFUN (neighbor_local_as_no_prepend_replace_as,
4952 neighbor_local_as_no_prepend_replace_as_cmd,
4953 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4954 NEIGHBOR_STR
4955 NEIGHBOR_ADDR_STR2
4956 "Specify a local-as number\n"
4957 "AS number used as local AS\n"
4958 "Do not prepend local-as to updates from ebgp peers\n"
4959 "Do not prepend local-as to updates from ibgp peers\n")
4960 {
4961 int idx_peer = 1;
4962 int idx_number = 3;
4963 struct peer *peer;
4964 int ret;
4965 as_t as;
4966
4967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4968 if (!peer)
4969 return CMD_WARNING_CONFIG_FAILED;
4970
4971 as = strtoul(argv[idx_number]->arg, NULL, 10);
4972 ret = peer_local_as_set(peer, as, 1, 1);
4973 return bgp_vty_return(vty, ret);
4974 }
4975
4976 DEFUN (no_neighbor_local_as,
4977 no_neighbor_local_as_cmd,
4978 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4979 NO_STR
4980 NEIGHBOR_STR
4981 NEIGHBOR_ADDR_STR2
4982 "Specify a local-as number\n"
4983 "AS number used as local AS\n"
4984 "Do not prepend local-as to updates from ebgp peers\n"
4985 "Do not prepend local-as to updates from ibgp peers\n")
4986 {
4987 int idx_peer = 2;
4988 struct peer *peer;
4989 int ret;
4990
4991 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4992 if (!peer)
4993 return CMD_WARNING_CONFIG_FAILED;
4994
4995 ret = peer_local_as_unset(peer);
4996 return bgp_vty_return(vty, ret);
4997 }
4998
4999
5000 DEFUN (neighbor_solo,
5001 neighbor_solo_cmd,
5002 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5003 NEIGHBOR_STR
5004 NEIGHBOR_ADDR_STR2
5005 "Solo peer - part of its own update group\n")
5006 {
5007 int idx_peer = 1;
5008 struct peer *peer;
5009 int ret;
5010
5011 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5012 if (!peer)
5013 return CMD_WARNING_CONFIG_FAILED;
5014
5015 ret = update_group_adjust_soloness(peer, 1);
5016 return bgp_vty_return(vty, ret);
5017 }
5018
5019 DEFUN (no_neighbor_solo,
5020 no_neighbor_solo_cmd,
5021 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5022 NO_STR
5023 NEIGHBOR_STR
5024 NEIGHBOR_ADDR_STR2
5025 "Solo peer - part of its own update group\n")
5026 {
5027 int idx_peer = 2;
5028 struct peer *peer;
5029 int ret;
5030
5031 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
5034
5035 ret = update_group_adjust_soloness(peer, 0);
5036 return bgp_vty_return(vty, ret);
5037 }
5038
5039 DEFUN (neighbor_password,
5040 neighbor_password_cmd,
5041 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5042 NEIGHBOR_STR
5043 NEIGHBOR_ADDR_STR2
5044 "Set a password\n"
5045 "The password\n")
5046 {
5047 int idx_peer = 1;
5048 int idx_line = 3;
5049 struct peer *peer;
5050 int ret;
5051
5052 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5053 if (!peer)
5054 return CMD_WARNING_CONFIG_FAILED;
5055
5056 ret = peer_password_set(peer, argv[idx_line]->arg);
5057 return bgp_vty_return(vty, ret);
5058 }
5059
5060 DEFUN (no_neighbor_password,
5061 no_neighbor_password_cmd,
5062 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5063 NO_STR
5064 NEIGHBOR_STR
5065 NEIGHBOR_ADDR_STR2
5066 "Set a password\n"
5067 "The password\n")
5068 {
5069 int idx_peer = 2;
5070 struct peer *peer;
5071 int ret;
5072
5073 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5074 if (!peer)
5075 return CMD_WARNING_CONFIG_FAILED;
5076
5077 ret = peer_password_unset(peer);
5078 return bgp_vty_return(vty, ret);
5079 }
5080
5081 DEFUN (neighbor_activate,
5082 neighbor_activate_cmd,
5083 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5084 NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Enable the Address Family for this Neighbor\n")
5087 {
5088 int idx_peer = 1;
5089 int ret;
5090 struct peer *peer;
5091
5092 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5093 if (!peer)
5094 return CMD_WARNING_CONFIG_FAILED;
5095
5096 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5097 return bgp_vty_return(vty, ret);
5098 }
5099
5100 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5101 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5102 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5103 "Enable the Address Family for this Neighbor\n")
5104
5105 DEFUN (no_neighbor_activate,
5106 no_neighbor_activate_cmd,
5107 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5108 NO_STR
5109 NEIGHBOR_STR
5110 NEIGHBOR_ADDR_STR2
5111 "Enable the Address Family for this Neighbor\n")
5112 {
5113 int idx_peer = 2;
5114 int ret;
5115 struct peer *peer;
5116
5117 /* Lookup peer. */
5118 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5119 if (!peer)
5120 return CMD_WARNING_CONFIG_FAILED;
5121
5122 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5123 return bgp_vty_return(vty, ret);
5124 }
5125
5126 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5127 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5128 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5129 "Enable the Address Family for this Neighbor\n")
5130
5131 DEFUN (neighbor_set_peer_group,
5132 neighbor_set_peer_group_cmd,
5133 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "Member of the peer-group\n"
5137 "Peer-group name\n")
5138 {
5139 VTY_DECLVAR_CONTEXT(bgp, bgp);
5140 int idx_peer = 1;
5141 int idx_word = 3;
5142 int ret;
5143 as_t as;
5144 union sockunion su;
5145 struct peer *peer;
5146 struct peer_group *group;
5147
5148 ret = str2sockunion(argv[idx_peer]->arg, &su);
5149 if (ret < 0) {
5150 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5151 if (!peer) {
5152 vty_out(vty, "%% Malformed address or name: %s\n",
5153 argv[idx_peer]->arg);
5154 return CMD_WARNING_CONFIG_FAILED;
5155 }
5156 } else {
5157 if (peer_address_self_check(bgp, &su)) {
5158 vty_out(vty,
5159 "%% Can not configure the local system as neighbor\n");
5160 return CMD_WARNING_CONFIG_FAILED;
5161 }
5162
5163 /* Disallow for dynamic neighbor. */
5164 peer = peer_lookup(bgp, &su);
5165 if (peer && peer_dynamic_neighbor(peer)) {
5166 vty_out(vty,
5167 "%% Operation not allowed on a dynamic neighbor\n");
5168 return CMD_WARNING_CONFIG_FAILED;
5169 }
5170 }
5171
5172 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5173 if (!group) {
5174 vty_out(vty, "%% Configure the peer-group first\n");
5175 return CMD_WARNING_CONFIG_FAILED;
5176 }
5177
5178 ret = peer_group_bind(bgp, &su, peer, group, &as);
5179
5180 return bgp_vty_return(vty, ret);
5181 }
5182
5183 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5184 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5186 "Member of the peer-group\n"
5187 "Peer-group name\n")
5188
5189 DEFUN (no_neighbor_set_peer_group,
5190 no_neighbor_set_peer_group_cmd,
5191 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5192 NO_STR
5193 NEIGHBOR_STR
5194 NEIGHBOR_ADDR_STR2
5195 "Member of the peer-group\n"
5196 "Peer-group name\n")
5197 {
5198 VTY_DECLVAR_CONTEXT(bgp, bgp);
5199 int idx_peer = 2;
5200 int idx_word = 4;
5201 int ret;
5202 struct peer *peer;
5203 struct peer_group *group;
5204
5205 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5206 if (!peer)
5207 return CMD_WARNING_CONFIG_FAILED;
5208
5209 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5210 if (!group) {
5211 vty_out(vty, "%% Configure the peer-group first\n");
5212 return CMD_WARNING_CONFIG_FAILED;
5213 }
5214
5215 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5216 bgp_zebra_terminate_radv(peer->bgp, peer);
5217
5218 peer_notify_unconfig(peer);
5219 ret = peer_delete(peer);
5220
5221 return bgp_vty_return(vty, ret);
5222 }
5223
5224 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5225 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5227 "Member of the peer-group\n"
5228 "Peer-group name\n")
5229
5230 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5231 uint64_t flag, int set)
5232 {
5233 int ret;
5234 struct peer *peer;
5235
5236 peer = peer_and_group_lookup_vty(vty, ip_str);
5237 if (!peer)
5238 return CMD_WARNING_CONFIG_FAILED;
5239
5240 /*
5241 * If 'neighbor <interface>', then this is for directly connected peers,
5242 * we should not accept disable-connected-check.
5243 */
5244 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5245 vty_out(vty,
5246 "%s is directly connected peer, cannot accept disable-connected-check\n",
5247 ip_str);
5248 return CMD_WARNING_CONFIG_FAILED;
5249 }
5250
5251 if (!set && flag == PEER_FLAG_SHUTDOWN)
5252 peer_tx_shutdown_message_unset(peer);
5253
5254 if (set)
5255 ret = peer_flag_set(peer, flag);
5256 else
5257 ret = peer_flag_unset(peer, flag);
5258
5259 return bgp_vty_return(vty, ret);
5260 }
5261
5262 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5263 {
5264 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5265 }
5266
5267 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5268 uint64_t flag)
5269 {
5270 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5271 }
5272
5273 /* neighbor passive. */
5274 DEFUN (neighbor_passive,
5275 neighbor_passive_cmd,
5276 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5277 NEIGHBOR_STR
5278 NEIGHBOR_ADDR_STR2
5279 "Don't send open messages to this neighbor\n")
5280 {
5281 int idx_peer = 1;
5282 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5283 }
5284
5285 DEFUN (no_neighbor_passive,
5286 no_neighbor_passive_cmd,
5287 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5288 NO_STR
5289 NEIGHBOR_STR
5290 NEIGHBOR_ADDR_STR2
5291 "Don't send open messages to this neighbor\n")
5292 {
5293 int idx_peer = 2;
5294 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5295 }
5296
5297 /* neighbor shutdown. */
5298 DEFUN (neighbor_shutdown_msg,
5299 neighbor_shutdown_msg_cmd,
5300 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5301 NEIGHBOR_STR
5302 NEIGHBOR_ADDR_STR2
5303 "Administratively shut down this neighbor\n"
5304 "Add a shutdown message (RFC 8203)\n"
5305 "Shutdown message\n")
5306 {
5307 int idx_peer = 1;
5308
5309 if (argc >= 5) {
5310 struct peer *peer =
5311 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5312 char *message;
5313
5314 if (!peer)
5315 return CMD_WARNING_CONFIG_FAILED;
5316 message = argv_concat(argv, argc, 4);
5317 peer_tx_shutdown_message_set(peer, message);
5318 XFREE(MTYPE_TMP, message);
5319 }
5320
5321 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5322 }
5323
5324 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5325 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5327 "Administratively shut down this neighbor\n")
5328
5329 DEFUN (no_neighbor_shutdown_msg,
5330 no_neighbor_shutdown_msg_cmd,
5331 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5332 NO_STR
5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Administratively shut down this neighbor\n"
5336 "Remove a shutdown message (RFC 8203)\n"
5337 "Shutdown message\n")
5338 {
5339 int idx_peer = 2;
5340
5341 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5342 PEER_FLAG_SHUTDOWN);
5343 }
5344
5345 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5346 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5347 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5348 "Administratively shut down this neighbor\n")
5349
5350 DEFUN(neighbor_shutdown_rtt,
5351 neighbor_shutdown_rtt_cmd,
5352 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5353 NEIGHBOR_STR
5354 NEIGHBOR_ADDR_STR2
5355 "Administratively shut down this neighbor\n"
5356 "Shutdown if round-trip-time is higher than expected\n"
5357 "Round-trip-time in milliseconds\n"
5358 "Specify the number of keepalives before shutdown\n"
5359 "The number of keepalives with higher RTT to shutdown\n")
5360 {
5361 int idx_peer = 1;
5362 int idx_rtt = 4;
5363 int idx_count = 0;
5364 struct peer *peer;
5365
5366 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5367
5368 if (!peer)
5369 return CMD_WARNING_CONFIG_FAILED;
5370
5371 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5372
5373 if (argv_find(argv, argc, "count", &idx_count))
5374 peer->rtt_keepalive_conf =
5375 strtol(argv[idx_count + 1]->arg, NULL, 10);
5376
5377 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5378 PEER_FLAG_RTT_SHUTDOWN);
5379 }
5380
5381 DEFUN(no_neighbor_shutdown_rtt,
5382 no_neighbor_shutdown_rtt_cmd,
5383 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5384 NO_STR
5385 NEIGHBOR_STR
5386 NEIGHBOR_ADDR_STR2
5387 "Administratively shut down this neighbor\n"
5388 "Shutdown if round-trip-time is higher than expected\n"
5389 "Round-trip-time in milliseconds\n"
5390 "Specify the number of keepalives before shutdown\n"
5391 "The number of keepalives with higher RTT to shutdown\n")
5392 {
5393 int idx_peer = 2;
5394 struct peer *peer;
5395
5396 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5397
5398 if (!peer)
5399 return CMD_WARNING_CONFIG_FAILED;
5400
5401 peer->rtt_expected = 0;
5402 peer->rtt_keepalive_conf = 1;
5403
5404 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5405 PEER_FLAG_RTT_SHUTDOWN);
5406 }
5407
5408 /* neighbor capability dynamic. */
5409 DEFUN (neighbor_capability_dynamic,
5410 neighbor_capability_dynamic_cmd,
5411 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5412 NEIGHBOR_STR
5413 NEIGHBOR_ADDR_STR2
5414 "Advertise capability to the peer\n"
5415 "Advertise dynamic capability to this neighbor\n")
5416 {
5417 int idx_peer = 1;
5418 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5419 PEER_FLAG_DYNAMIC_CAPABILITY);
5420 }
5421
5422 DEFUN (no_neighbor_capability_dynamic,
5423 no_neighbor_capability_dynamic_cmd,
5424 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5425 NO_STR
5426 NEIGHBOR_STR
5427 NEIGHBOR_ADDR_STR2
5428 "Advertise capability to the peer\n"
5429 "Advertise dynamic capability to this neighbor\n")
5430 {
5431 int idx_peer = 2;
5432 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5433 PEER_FLAG_DYNAMIC_CAPABILITY);
5434 }
5435
5436 /* neighbor dont-capability-negotiate */
5437 DEFUN (neighbor_dont_capability_negotiate,
5438 neighbor_dont_capability_negotiate_cmd,
5439 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5440 NEIGHBOR_STR
5441 NEIGHBOR_ADDR_STR2
5442 "Do not perform capability negotiation\n")
5443 {
5444 int idx_peer = 1;
5445 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5446 PEER_FLAG_DONT_CAPABILITY);
5447 }
5448
5449 DEFUN (no_neighbor_dont_capability_negotiate,
5450 no_neighbor_dont_capability_negotiate_cmd,
5451 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5452 NO_STR
5453 NEIGHBOR_STR
5454 NEIGHBOR_ADDR_STR2
5455 "Do not perform capability negotiation\n")
5456 {
5457 int idx_peer = 2;
5458 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5459 PEER_FLAG_DONT_CAPABILITY);
5460 }
5461
5462 /* neighbor capability extended next hop encoding */
5463 DEFUN (neighbor_capability_enhe,
5464 neighbor_capability_enhe_cmd,
5465 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5466 NEIGHBOR_STR
5467 NEIGHBOR_ADDR_STR2
5468 "Advertise capability to the peer\n"
5469 "Advertise extended next-hop capability to the peer\n")
5470 {
5471 int idx_peer = 1;
5472 struct peer *peer;
5473
5474 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5475 if (peer && peer->conf_if)
5476 return CMD_SUCCESS;
5477
5478 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5479 PEER_FLAG_CAPABILITY_ENHE);
5480 }
5481
5482 DEFUN (no_neighbor_capability_enhe,
5483 no_neighbor_capability_enhe_cmd,
5484 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5485 NO_STR
5486 NEIGHBOR_STR
5487 NEIGHBOR_ADDR_STR2
5488 "Advertise capability to the peer\n"
5489 "Advertise extended next-hop capability to the peer\n")
5490 {
5491 int idx_peer = 2;
5492 struct peer *peer;
5493
5494 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5495 if (peer && peer->conf_if) {
5496 vty_out(vty,
5497 "Peer %s cannot have capability extended-nexthop turned off\n",
5498 argv[idx_peer]->arg);
5499 return CMD_WARNING_CONFIG_FAILED;
5500 }
5501
5502 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5503 PEER_FLAG_CAPABILITY_ENHE);
5504 }
5505
5506 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5507 afi_t afi, safi_t safi, uint32_t flag,
5508 int set)
5509 {
5510 int ret;
5511 struct peer *peer;
5512
5513 peer = peer_and_group_lookup_vty(vty, peer_str);
5514 if (!peer)
5515 return CMD_WARNING_CONFIG_FAILED;
5516
5517 if (set)
5518 ret = peer_af_flag_set(peer, afi, safi, flag);
5519 else
5520 ret = peer_af_flag_unset(peer, afi, safi, flag);
5521
5522 return bgp_vty_return(vty, ret);
5523 }
5524
5525 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5526 afi_t afi, safi_t safi, uint32_t flag)
5527 {
5528 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5529 }
5530
5531 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5532 afi_t afi, safi_t safi, uint32_t flag)
5533 {
5534 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5535 }
5536
5537 /* neighbor capability orf prefix-list. */
5538 DEFUN (neighbor_capability_orf_prefix,
5539 neighbor_capability_orf_prefix_cmd,
5540 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Advertise capability to the peer\n"
5544 "Advertise ORF capability to the peer\n"
5545 "Advertise prefixlist ORF capability to this neighbor\n"
5546 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5547 "Capability to RECEIVE the ORF from this neighbor\n"
5548 "Capability to SEND the ORF to this neighbor\n")
5549 {
5550 int idx_send_recv = 5;
5551 char *peer_str = argv[1]->arg;
5552 struct peer *peer;
5553 afi_t afi = bgp_node_afi(vty);
5554 safi_t safi = bgp_node_safi(vty);
5555
5556 peer = peer_and_group_lookup_vty(vty, peer_str);
5557 if (!peer)
5558 return CMD_WARNING_CONFIG_FAILED;
5559
5560 if (strmatch(argv[idx_send_recv]->text, "send"))
5561 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5562 PEER_FLAG_ORF_PREFIX_SM);
5563
5564 if (strmatch(argv[idx_send_recv]->text, "receive"))
5565 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5566 PEER_FLAG_ORF_PREFIX_RM);
5567
5568 if (strmatch(argv[idx_send_recv]->text, "both"))
5569 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5570 PEER_FLAG_ORF_PREFIX_SM)
5571 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5572 PEER_FLAG_ORF_PREFIX_RM);
5573
5574 return CMD_WARNING_CONFIG_FAILED;
5575 }
5576
5577 ALIAS_HIDDEN(
5578 neighbor_capability_orf_prefix,
5579 neighbor_capability_orf_prefix_hidden_cmd,
5580 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5582 "Advertise capability to the peer\n"
5583 "Advertise ORF capability to the peer\n"
5584 "Advertise prefixlist ORF capability to this neighbor\n"
5585 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5586 "Capability to RECEIVE the ORF from this neighbor\n"
5587 "Capability to SEND the ORF to this neighbor\n")
5588
5589 DEFUN (no_neighbor_capability_orf_prefix,
5590 no_neighbor_capability_orf_prefix_cmd,
5591 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5592 NO_STR
5593 NEIGHBOR_STR
5594 NEIGHBOR_ADDR_STR2
5595 "Advertise capability to the peer\n"
5596 "Advertise ORF capability to the peer\n"
5597 "Advertise prefixlist ORF capability to this neighbor\n"
5598 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5599 "Capability to RECEIVE the ORF from this neighbor\n"
5600 "Capability to SEND the ORF to this neighbor\n")
5601 {
5602 int idx_send_recv = 6;
5603 char *peer_str = argv[2]->arg;
5604 struct peer *peer;
5605 afi_t afi = bgp_node_afi(vty);
5606 safi_t safi = bgp_node_safi(vty);
5607
5608 peer = peer_and_group_lookup_vty(vty, peer_str);
5609 if (!peer)
5610 return CMD_WARNING_CONFIG_FAILED;
5611
5612 if (strmatch(argv[idx_send_recv]->text, "send"))
5613 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5614 PEER_FLAG_ORF_PREFIX_SM);
5615
5616 if (strmatch(argv[idx_send_recv]->text, "receive"))
5617 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5618 PEER_FLAG_ORF_PREFIX_RM);
5619
5620 if (strmatch(argv[idx_send_recv]->text, "both"))
5621 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5622 PEER_FLAG_ORF_PREFIX_SM)
5623 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5624 PEER_FLAG_ORF_PREFIX_RM);
5625
5626 return CMD_WARNING_CONFIG_FAILED;
5627 }
5628
5629 ALIAS_HIDDEN(
5630 no_neighbor_capability_orf_prefix,
5631 no_neighbor_capability_orf_prefix_hidden_cmd,
5632 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5633 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5634 "Advertise capability to the peer\n"
5635 "Advertise ORF capability to the peer\n"
5636 "Advertise prefixlist ORF capability to this neighbor\n"
5637 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5638 "Capability to RECEIVE the ORF from this neighbor\n"
5639 "Capability to SEND the ORF to this neighbor\n")
5640
5641 /* neighbor next-hop-self. */
5642 DEFUN (neighbor_nexthop_self,
5643 neighbor_nexthop_self_cmd,
5644 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5645 NEIGHBOR_STR
5646 NEIGHBOR_ADDR_STR2
5647 "Disable the next hop calculation for this neighbor\n")
5648 {
5649 int idx_peer = 1;
5650 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5651 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5652 }
5653
5654 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5655 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5656 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5657 "Disable the next hop calculation for this neighbor\n")
5658
5659 /* neighbor next-hop-self. */
5660 DEFUN (neighbor_nexthop_self_force,
5661 neighbor_nexthop_self_force_cmd,
5662 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5663 NEIGHBOR_STR
5664 NEIGHBOR_ADDR_STR2
5665 "Disable the next hop calculation for this neighbor\n"
5666 "Set the next hop to self for reflected routes\n")
5667 {
5668 int idx_peer = 1;
5669 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5670 bgp_node_safi(vty),
5671 PEER_FLAG_FORCE_NEXTHOP_SELF);
5672 }
5673
5674 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5675 neighbor_nexthop_self_force_hidden_cmd,
5676 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5677 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5678 "Disable the next hop calculation for this neighbor\n"
5679 "Set the next hop to self for reflected routes\n")
5680
5681 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5682 neighbor_nexthop_self_all_hidden_cmd,
5683 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5684 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5685 "Disable the next hop calculation for this neighbor\n"
5686 "Set the next hop to self for reflected routes\n")
5687
5688 DEFUN (no_neighbor_nexthop_self,
5689 no_neighbor_nexthop_self_cmd,
5690 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5691 NO_STR
5692 NEIGHBOR_STR
5693 NEIGHBOR_ADDR_STR2
5694 "Disable the next hop calculation for this neighbor\n")
5695 {
5696 int idx_peer = 2;
5697 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5698 bgp_node_afi(vty), bgp_node_safi(vty),
5699 PEER_FLAG_NEXTHOP_SELF);
5700 }
5701
5702 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5703 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5704 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5705 "Disable the next hop calculation for this neighbor\n")
5706
5707 DEFUN (no_neighbor_nexthop_self_force,
5708 no_neighbor_nexthop_self_force_cmd,
5709 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5710 NO_STR
5711 NEIGHBOR_STR
5712 NEIGHBOR_ADDR_STR2
5713 "Disable the next hop calculation for this neighbor\n"
5714 "Set the next hop to self for reflected routes\n")
5715 {
5716 int idx_peer = 2;
5717 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5718 bgp_node_afi(vty), bgp_node_safi(vty),
5719 PEER_FLAG_FORCE_NEXTHOP_SELF);
5720 }
5721
5722 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5723 no_neighbor_nexthop_self_force_hidden_cmd,
5724 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5725 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5726 "Disable the next hop calculation for this neighbor\n"
5727 "Set the next hop to self for reflected routes\n")
5728
5729 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5730 no_neighbor_nexthop_self_all_hidden_cmd,
5731 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5732 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5733 "Disable the next hop calculation for this neighbor\n"
5734 "Set the next hop to self for reflected routes\n")
5735
5736 /* neighbor as-override */
5737 DEFUN (neighbor_as_override,
5738 neighbor_as_override_cmd,
5739 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5740 NEIGHBOR_STR
5741 NEIGHBOR_ADDR_STR2
5742 "Override ASNs in outbound updates if aspath equals remote-as\n")
5743 {
5744 int idx_peer = 1;
5745 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5746 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5747 }
5748
5749 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5750 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5751 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5752 "Override ASNs in outbound updates if aspath equals remote-as\n")
5753
5754 DEFUN (no_neighbor_as_override,
5755 no_neighbor_as_override_cmd,
5756 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5757 NO_STR
5758 NEIGHBOR_STR
5759 NEIGHBOR_ADDR_STR2
5760 "Override ASNs in outbound updates if aspath equals remote-as\n")
5761 {
5762 int idx_peer = 2;
5763 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5764 bgp_node_afi(vty), bgp_node_safi(vty),
5765 PEER_FLAG_AS_OVERRIDE);
5766 }
5767
5768 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5769 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5770 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5771 "Override ASNs in outbound updates if aspath equals remote-as\n")
5772
5773 /* neighbor remove-private-AS. */
5774 DEFUN (neighbor_remove_private_as,
5775 neighbor_remove_private_as_cmd,
5776 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5777 NEIGHBOR_STR
5778 NEIGHBOR_ADDR_STR2
5779 "Remove private ASNs in outbound updates\n")
5780 {
5781 int idx_peer = 1;
5782 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5783 bgp_node_safi(vty),
5784 PEER_FLAG_REMOVE_PRIVATE_AS);
5785 }
5786
5787 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5788 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5789 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5790 "Remove private ASNs in outbound updates\n")
5791
5792 DEFUN (neighbor_remove_private_as_all,
5793 neighbor_remove_private_as_all_cmd,
5794 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5795 NEIGHBOR_STR
5796 NEIGHBOR_ADDR_STR2
5797 "Remove private ASNs in outbound updates\n"
5798 "Apply to all AS numbers\n")
5799 {
5800 int idx_peer = 1;
5801 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5802 bgp_node_safi(vty),
5803 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5804 }
5805
5806 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5807 neighbor_remove_private_as_all_hidden_cmd,
5808 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5809 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5810 "Remove private ASNs in outbound updates\n"
5811 "Apply to all AS numbers")
5812
5813 DEFUN (neighbor_remove_private_as_replace_as,
5814 neighbor_remove_private_as_replace_as_cmd,
5815 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
5818 "Remove private ASNs in outbound updates\n"
5819 "Replace private ASNs with our ASN in outbound updates\n")
5820 {
5821 int idx_peer = 1;
5822 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5823 bgp_node_safi(vty),
5824 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5825 }
5826
5827 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5828 neighbor_remove_private_as_replace_as_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Remove private ASNs in outbound updates\n"
5832 "Replace private ASNs with our ASN in outbound updates\n")
5833
5834 DEFUN (neighbor_remove_private_as_all_replace_as,
5835 neighbor_remove_private_as_all_replace_as_cmd,
5836 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5837 NEIGHBOR_STR
5838 NEIGHBOR_ADDR_STR2
5839 "Remove private ASNs in outbound updates\n"
5840 "Apply to all AS numbers\n"
5841 "Replace private ASNs with our ASN in outbound updates\n")
5842 {
5843 int idx_peer = 1;
5844 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5845 bgp_node_safi(vty),
5846 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5847 }
5848
5849 ALIAS_HIDDEN(
5850 neighbor_remove_private_as_all_replace_as,
5851 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5852 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5853 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5854 "Remove private ASNs in outbound updates\n"
5855 "Apply to all AS numbers\n"
5856 "Replace private ASNs with our ASN in outbound updates\n")
5857
5858 DEFUN (no_neighbor_remove_private_as,
5859 no_neighbor_remove_private_as_cmd,
5860 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5861 NO_STR
5862 NEIGHBOR_STR
5863 NEIGHBOR_ADDR_STR2
5864 "Remove private ASNs in outbound updates\n")
5865 {
5866 int idx_peer = 2;
5867 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5868 bgp_node_afi(vty), bgp_node_safi(vty),
5869 PEER_FLAG_REMOVE_PRIVATE_AS);
5870 }
5871
5872 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5873 no_neighbor_remove_private_as_hidden_cmd,
5874 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5875 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5876 "Remove private ASNs in outbound updates\n")
5877
5878 DEFUN (no_neighbor_remove_private_as_all,
5879 no_neighbor_remove_private_as_all_cmd,
5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
5884 "Remove private ASNs in outbound updates\n"
5885 "Apply to all AS numbers\n")
5886 {
5887 int idx_peer = 2;
5888 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5889 bgp_node_afi(vty), bgp_node_safi(vty),
5890 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5891 }
5892
5893 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5894 no_neighbor_remove_private_as_all_hidden_cmd,
5895 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5896 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5897 "Remove private ASNs in outbound updates\n"
5898 "Apply to all AS numbers\n")
5899
5900 DEFUN (no_neighbor_remove_private_as_replace_as,
5901 no_neighbor_remove_private_as_replace_as_cmd,
5902 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5903 NO_STR
5904 NEIGHBOR_STR
5905 NEIGHBOR_ADDR_STR2
5906 "Remove private ASNs in outbound updates\n"
5907 "Replace private ASNs with our ASN in outbound updates\n")
5908 {
5909 int idx_peer = 2;
5910 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5911 bgp_node_afi(vty), bgp_node_safi(vty),
5912 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5913 }
5914
5915 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5916 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5917 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5918 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5919 "Remove private ASNs in outbound updates\n"
5920 "Replace private ASNs with our ASN in outbound updates\n")
5921
5922 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5923 no_neighbor_remove_private_as_all_replace_as_cmd,
5924 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5925 NO_STR
5926 NEIGHBOR_STR
5927 NEIGHBOR_ADDR_STR2
5928 "Remove private ASNs in outbound updates\n"
5929 "Apply to all AS numbers\n"
5930 "Replace private ASNs with our ASN in outbound updates\n")
5931 {
5932 int idx_peer = 2;
5933 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5934 bgp_node_afi(vty), bgp_node_safi(vty),
5935 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5936 }
5937
5938 ALIAS_HIDDEN(
5939 no_neighbor_remove_private_as_all_replace_as,
5940 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5941 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5942 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5943 "Remove private ASNs in outbound updates\n"
5944 "Apply to all AS numbers\n"
5945 "Replace private ASNs with our ASN in outbound updates\n")
5946
5947
5948 /* neighbor send-community. */
5949 DEFUN (neighbor_send_community,
5950 neighbor_send_community_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Send Community attribute to this neighbor\n")
5955 {
5956 int idx_peer = 1;
5957
5958 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5959 bgp_node_safi(vty),
5960 PEER_FLAG_SEND_COMMUNITY);
5961 }
5962
5963 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5964 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5966 "Send Community attribute to this neighbor\n")
5967
5968 DEFUN (no_neighbor_send_community,
5969 no_neighbor_send_community_cmd,
5970 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5971 NO_STR
5972 NEIGHBOR_STR
5973 NEIGHBOR_ADDR_STR2
5974 "Send Community attribute to this neighbor\n")
5975 {
5976 int idx_peer = 2;
5977
5978 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5979 bgp_node_afi(vty), bgp_node_safi(vty),
5980 PEER_FLAG_SEND_COMMUNITY);
5981 }
5982
5983 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5984 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5985 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5986 "Send Community attribute to this neighbor\n")
5987
5988 /* neighbor send-community extended. */
5989 DEFUN (neighbor_send_community_type,
5990 neighbor_send_community_type_cmd,
5991 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5992 NEIGHBOR_STR
5993 NEIGHBOR_ADDR_STR2
5994 "Send Community attribute to this neighbor\n"
5995 "Send Standard and Extended Community attributes\n"
5996 "Send Standard, Large and Extended Community attributes\n"
5997 "Send Extended Community attributes\n"
5998 "Send Standard Community attributes\n"
5999 "Send Large Community attributes\n")
6000 {
6001 const char *type = argv[argc - 1]->text;
6002 char *peer_str = argv[1]->arg;
6003 struct peer *peer;
6004 afi_t afi = bgp_node_afi(vty);
6005 safi_t safi = bgp_node_safi(vty);
6006
6007 peer = peer_and_group_lookup_vty(vty, peer_str);
6008 if (!peer)
6009 return CMD_WARNING_CONFIG_FAILED;
6010
6011 if (strmatch(type, "standard"))
6012 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6013 PEER_FLAG_SEND_COMMUNITY);
6014
6015 if (strmatch(type, "extended"))
6016 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6017 PEER_FLAG_SEND_EXT_COMMUNITY);
6018
6019 if (strmatch(type, "large"))
6020 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6021 PEER_FLAG_SEND_LARGE_COMMUNITY);
6022
6023 if (strmatch(type, "both")) {
6024 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6025 PEER_FLAG_SEND_COMMUNITY)
6026 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6027 PEER_FLAG_SEND_EXT_COMMUNITY);
6028 }
6029 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6030 PEER_FLAG_SEND_COMMUNITY)
6031 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6032 PEER_FLAG_SEND_EXT_COMMUNITY)
6033 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6034 PEER_FLAG_SEND_LARGE_COMMUNITY);
6035 }
6036
6037 ALIAS_HIDDEN(
6038 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6039 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6040 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6041 "Send Community attribute to this neighbor\n"
6042 "Send Standard and Extended Community attributes\n"
6043 "Send Standard, Large and Extended Community attributes\n"
6044 "Send Extended Community attributes\n"
6045 "Send Standard Community attributes\n"
6046 "Send Large Community attributes\n")
6047
6048 DEFUN (no_neighbor_send_community_type,
6049 no_neighbor_send_community_type_cmd,
6050 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6051 NO_STR
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Send Community attribute to this neighbor\n"
6055 "Send Standard and Extended Community attributes\n"
6056 "Send Standard, Large and Extended Community attributes\n"
6057 "Send Extended Community attributes\n"
6058 "Send Standard Community attributes\n"
6059 "Send Large Community attributes\n")
6060 {
6061 const char *type = argv[argc - 1]->text;
6062 char *peer_str = argv[2]->arg;
6063 struct peer *peer;
6064 afi_t afi = bgp_node_afi(vty);
6065 safi_t safi = bgp_node_safi(vty);
6066
6067 peer = peer_and_group_lookup_vty(vty, peer_str);
6068 if (!peer)
6069 return CMD_WARNING_CONFIG_FAILED;
6070
6071 if (strmatch(type, "standard"))
6072 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6073 PEER_FLAG_SEND_COMMUNITY);
6074
6075 if (strmatch(type, "extended"))
6076 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6077 PEER_FLAG_SEND_EXT_COMMUNITY);
6078
6079 if (strmatch(type, "large"))
6080 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6081 PEER_FLAG_SEND_LARGE_COMMUNITY);
6082
6083 if (strmatch(type, "both")) {
6084
6085 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6086 PEER_FLAG_SEND_COMMUNITY)
6087 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6088 PEER_FLAG_SEND_EXT_COMMUNITY);
6089 }
6090
6091 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6092 PEER_FLAG_SEND_COMMUNITY)
6093 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6094 PEER_FLAG_SEND_EXT_COMMUNITY)
6095 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6096 PEER_FLAG_SEND_LARGE_COMMUNITY);
6097 }
6098
6099 ALIAS_HIDDEN(
6100 no_neighbor_send_community_type,
6101 no_neighbor_send_community_type_hidden_cmd,
6102 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6103 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6104 "Send Community attribute to this neighbor\n"
6105 "Send Standard and Extended Community attributes\n"
6106 "Send Standard, Large and Extended Community attributes\n"
6107 "Send Extended Community attributes\n"
6108 "Send Standard Community attributes\n"
6109 "Send Large Community attributes\n")
6110
6111 /* neighbor soft-reconfig. */
6112 DEFUN (neighbor_soft_reconfiguration,
6113 neighbor_soft_reconfiguration_cmd,
6114 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6115 NEIGHBOR_STR
6116 NEIGHBOR_ADDR_STR2
6117 "Per neighbor soft reconfiguration\n"
6118 "Allow inbound soft reconfiguration for this neighbor\n")
6119 {
6120 int idx_peer = 1;
6121 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6122 bgp_node_safi(vty),
6123 PEER_FLAG_SOFT_RECONFIG);
6124 }
6125
6126 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6127 neighbor_soft_reconfiguration_hidden_cmd,
6128 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6130 "Per neighbor soft reconfiguration\n"
6131 "Allow inbound soft reconfiguration for this neighbor\n")
6132
6133 DEFUN (no_neighbor_soft_reconfiguration,
6134 no_neighbor_soft_reconfiguration_cmd,
6135 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6136 NO_STR
6137 NEIGHBOR_STR
6138 NEIGHBOR_ADDR_STR2
6139 "Per neighbor soft reconfiguration\n"
6140 "Allow inbound soft reconfiguration for this neighbor\n")
6141 {
6142 int idx_peer = 2;
6143 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6144 bgp_node_afi(vty), bgp_node_safi(vty),
6145 PEER_FLAG_SOFT_RECONFIG);
6146 }
6147
6148 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6149 no_neighbor_soft_reconfiguration_hidden_cmd,
6150 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6152 "Per neighbor soft reconfiguration\n"
6153 "Allow inbound soft reconfiguration for this neighbor\n")
6154
6155 DEFUN (neighbor_route_reflector_client,
6156 neighbor_route_reflector_client_cmd,
6157 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6158 NEIGHBOR_STR
6159 NEIGHBOR_ADDR_STR2
6160 "Configure a neighbor as Route Reflector client\n")
6161 {
6162 int idx_peer = 1;
6163 struct peer *peer;
6164
6165
6166 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6167 if (!peer)
6168 return CMD_WARNING_CONFIG_FAILED;
6169
6170 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6171 bgp_node_safi(vty),
6172 PEER_FLAG_REFLECTOR_CLIENT);
6173 }
6174
6175 ALIAS_HIDDEN(neighbor_route_reflector_client,
6176 neighbor_route_reflector_client_hidden_cmd,
6177 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6178 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6179 "Configure a neighbor as Route Reflector client\n")
6180
6181 DEFUN (no_neighbor_route_reflector_client,
6182 no_neighbor_route_reflector_client_cmd,
6183 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6184 NO_STR
6185 NEIGHBOR_STR
6186 NEIGHBOR_ADDR_STR2
6187 "Configure a neighbor as Route Reflector client\n")
6188 {
6189 int idx_peer = 2;
6190 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6191 bgp_node_afi(vty), bgp_node_safi(vty),
6192 PEER_FLAG_REFLECTOR_CLIENT);
6193 }
6194
6195 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6196 no_neighbor_route_reflector_client_hidden_cmd,
6197 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6198 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6199 "Configure a neighbor as Route Reflector client\n")
6200
6201 /* optimal-route-reflection Root Routers configuration */
6202 DEFPY (optimal_route_reflection,
6203 optimal_route_reflection_cmd,
6204 "[no$no] optimal-route-reflection WORD$orr_group [<A.B.C.D|X:X::X:X>$primary [<A.B.C.D|X:X::X:X>$secondary [<A.B.C.D|X:X::X:X>$tertiary]]]",
6205 NO_STR
6206 "Create ORR group and assign root router(s)\n"
6207 "ORR Group name\n"
6208 "Primary Root address\n"
6209 "Primary Root IPv6 address\n"
6210 "Secondary Root address\n"
6211 "Secondary Root IPv6 address\n"
6212 "Tertiary Root address\n"
6213 "Tertiary Root IPv6 address\n")
6214 {
6215 if (!no && !primary) {
6216 vty_out(vty, "%% Specify Primary Root address\n");
6217 return CMD_WARNING_CONFIG_FAILED;
6218 }
6219 return bgp_afi_safi_orr_group_set_vty(
6220 vty, bgp_node_afi(vty), bgp_node_safi(vty), orr_group,
6221 primary_str, secondary_str, tertiary_str, !no);
6222 }
6223
6224 /* neighbor optimal-route-reflection group*/
6225 DEFPY (neighbor_optimal_route_reflection,
6226 neighbor_optimal_route_reflection_cmd,
6227 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor optimal-route-reflection WORD$orr_group",
6228 NO_STR
6229 NEIGHBOR_STR
6230 NEIGHBOR_ADDR_STR2
6231 "Apply ORR group configuration to the neighbor\n"
6232 "ORR group name\n")
6233 {
6234 return peer_orr_group_set_vty(vty, neighbor, bgp_node_afi(vty),
6235 bgp_node_safi(vty), orr_group, !no);
6236 }
6237
6238 /* neighbor route-server-client. */
6239 DEFUN (neighbor_route_server_client,
6240 neighbor_route_server_client_cmd,
6241 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6242 NEIGHBOR_STR
6243 NEIGHBOR_ADDR_STR2
6244 "Configure a neighbor as Route Server client\n")
6245 {
6246 int idx_peer = 1;
6247 struct peer *peer;
6248
6249 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6250 if (!peer)
6251 return CMD_WARNING_CONFIG_FAILED;
6252 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6253 bgp_node_safi(vty),
6254 PEER_FLAG_RSERVER_CLIENT);
6255 }
6256
6257 ALIAS_HIDDEN(neighbor_route_server_client,
6258 neighbor_route_server_client_hidden_cmd,
6259 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6260 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6261 "Configure a neighbor as Route Server client\n")
6262
6263 DEFUN (no_neighbor_route_server_client,
6264 no_neighbor_route_server_client_cmd,
6265 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6266 NO_STR
6267 NEIGHBOR_STR
6268 NEIGHBOR_ADDR_STR2
6269 "Configure a neighbor as Route Server client\n")
6270 {
6271 int idx_peer = 2;
6272 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6273 bgp_node_afi(vty), bgp_node_safi(vty),
6274 PEER_FLAG_RSERVER_CLIENT);
6275 }
6276
6277 ALIAS_HIDDEN(no_neighbor_route_server_client,
6278 no_neighbor_route_server_client_hidden_cmd,
6279 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6280 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6281 "Configure a neighbor as Route Server client\n")
6282
6283 DEFUN (neighbor_nexthop_local_unchanged,
6284 neighbor_nexthop_local_unchanged_cmd,
6285 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6286 NEIGHBOR_STR
6287 NEIGHBOR_ADDR_STR2
6288 "Configure treatment of outgoing link-local nexthop attribute\n"
6289 "Leave link-local nexthop unchanged for this peer\n")
6290 {
6291 int idx_peer = 1;
6292 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6293 bgp_node_safi(vty),
6294 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6295 }
6296
6297 DEFUN (no_neighbor_nexthop_local_unchanged,
6298 no_neighbor_nexthop_local_unchanged_cmd,
6299 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6300 NO_STR
6301 NEIGHBOR_STR
6302 NEIGHBOR_ADDR_STR2
6303 "Configure treatment of outgoing link-local-nexthop attribute\n"
6304 "Leave link-local nexthop unchanged for this peer\n")
6305 {
6306 int idx_peer = 2;
6307 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6308 bgp_node_afi(vty), bgp_node_safi(vty),
6309 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6310 }
6311
6312 DEFUN (neighbor_attr_unchanged,
6313 neighbor_attr_unchanged_cmd,
6314 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6315 NEIGHBOR_STR
6316 NEIGHBOR_ADDR_STR2
6317 "BGP attribute is propagated unchanged to this neighbor\n"
6318 "As-path attribute\n"
6319 "Nexthop attribute\n"
6320 "Med attribute\n")
6321 {
6322 int idx = 0;
6323 char *peer_str = argv[1]->arg;
6324 struct peer *peer;
6325 bool aspath = false;
6326 bool nexthop = false;
6327 bool med = false;
6328 afi_t afi = bgp_node_afi(vty);
6329 safi_t safi = bgp_node_safi(vty);
6330 int ret = 0;
6331
6332 peer = peer_and_group_lookup_vty(vty, peer_str);
6333 if (!peer)
6334 return CMD_WARNING_CONFIG_FAILED;
6335
6336 if (argv_find(argv, argc, "as-path", &idx))
6337 aspath = true;
6338
6339 idx = 0;
6340 if (argv_find(argv, argc, "next-hop", &idx))
6341 nexthop = true;
6342
6343 idx = 0;
6344 if (argv_find(argv, argc, "med", &idx))
6345 med = true;
6346
6347 /* no flags means all of them! */
6348 if (!aspath && !nexthop && !med) {
6349 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6350 PEER_FLAG_AS_PATH_UNCHANGED);
6351 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6352 PEER_FLAG_NEXTHOP_UNCHANGED);
6353 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6354 PEER_FLAG_MED_UNCHANGED);
6355 } else {
6356 if (!aspath) {
6357 if (peer_af_flag_check(peer, afi, safi,
6358 PEER_FLAG_AS_PATH_UNCHANGED)) {
6359 ret |= peer_af_flag_unset_vty(
6360 vty, peer_str, afi, safi,
6361 PEER_FLAG_AS_PATH_UNCHANGED);
6362 }
6363 } else
6364 ret |= peer_af_flag_set_vty(
6365 vty, peer_str, afi, safi,
6366 PEER_FLAG_AS_PATH_UNCHANGED);
6367
6368 if (!nexthop) {
6369 if (peer_af_flag_check(peer, afi, safi,
6370 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6371 ret |= peer_af_flag_unset_vty(
6372 vty, peer_str, afi, safi,
6373 PEER_FLAG_NEXTHOP_UNCHANGED);
6374 }
6375 } else
6376 ret |= peer_af_flag_set_vty(
6377 vty, peer_str, afi, safi,
6378 PEER_FLAG_NEXTHOP_UNCHANGED);
6379
6380 if (!med) {
6381 if (peer_af_flag_check(peer, afi, safi,
6382 PEER_FLAG_MED_UNCHANGED)) {
6383 ret |= peer_af_flag_unset_vty(
6384 vty, peer_str, afi, safi,
6385 PEER_FLAG_MED_UNCHANGED);
6386 }
6387 } else
6388 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6389 PEER_FLAG_MED_UNCHANGED);
6390 }
6391
6392 return ret;
6393 }
6394
6395 ALIAS_HIDDEN(
6396 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6397 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6398 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6399 "BGP attribute is propagated unchanged to this neighbor\n"
6400 "As-path attribute\n"
6401 "Nexthop attribute\n"
6402 "Med attribute\n")
6403
6404 DEFUN (no_neighbor_attr_unchanged,
6405 no_neighbor_attr_unchanged_cmd,
6406 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6407 NO_STR
6408 NEIGHBOR_STR
6409 NEIGHBOR_ADDR_STR2
6410 "BGP attribute is propagated unchanged to this neighbor\n"
6411 "As-path attribute\n"
6412 "Nexthop attribute\n"
6413 "Med attribute\n")
6414 {
6415 int idx = 0;
6416 char *peer_str = argv[2]->arg;
6417 struct peer *peer;
6418 bool aspath = false;
6419 bool nexthop = false;
6420 bool med = false;
6421 afi_t afi = bgp_node_afi(vty);
6422 safi_t safi = bgp_node_safi(vty);
6423 int ret = 0;
6424
6425 peer = peer_and_group_lookup_vty(vty, peer_str);
6426 if (!peer)
6427 return CMD_WARNING_CONFIG_FAILED;
6428
6429 if (argv_find(argv, argc, "as-path", &idx))
6430 aspath = true;
6431
6432 idx = 0;
6433 if (argv_find(argv, argc, "next-hop", &idx))
6434 nexthop = true;
6435
6436 idx = 0;
6437 if (argv_find(argv, argc, "med", &idx))
6438 med = true;
6439
6440 if (!aspath && !nexthop && !med) // no flags means all of them!
6441 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6442 PEER_FLAG_AS_PATH_UNCHANGED)
6443 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6444 PEER_FLAG_NEXTHOP_UNCHANGED)
6445 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6446 PEER_FLAG_MED_UNCHANGED);
6447
6448 if (aspath)
6449 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6450 PEER_FLAG_AS_PATH_UNCHANGED);
6451
6452 if (nexthop)
6453 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6454 PEER_FLAG_NEXTHOP_UNCHANGED);
6455
6456 if (med)
6457 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6458 PEER_FLAG_MED_UNCHANGED);
6459
6460 return ret;
6461 }
6462
6463 ALIAS_HIDDEN(
6464 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6465 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6466 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6467 "BGP attribute is propagated unchanged to this neighbor\n"
6468 "As-path attribute\n"
6469 "Nexthop attribute\n"
6470 "Med attribute\n")
6471
6472 /* EBGP multihop configuration. */
6473 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6474 const char *ttl_str)
6475 {
6476 struct peer *peer;
6477 unsigned int ttl;
6478
6479 peer = peer_and_group_lookup_vty(vty, ip_str);
6480 if (!peer)
6481 return CMD_WARNING_CONFIG_FAILED;
6482
6483 if (peer->conf_if)
6484 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6485
6486 if (!ttl_str)
6487 ttl = MAXTTL;
6488 else
6489 ttl = strtoul(ttl_str, NULL, 10);
6490
6491 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6492 }
6493
6494 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6495 {
6496 struct peer *peer;
6497
6498 peer = peer_and_group_lookup_vty(vty, ip_str);
6499 if (!peer)
6500 return CMD_WARNING_CONFIG_FAILED;
6501
6502 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6503 }
6504
6505 /* neighbor ebgp-multihop. */
6506 DEFUN (neighbor_ebgp_multihop,
6507 neighbor_ebgp_multihop_cmd,
6508 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6509 NEIGHBOR_STR
6510 NEIGHBOR_ADDR_STR2
6511 "Allow EBGP neighbors not on directly connected networks\n")
6512 {
6513 int idx_peer = 1;
6514 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6515 }
6516
6517 DEFUN (neighbor_ebgp_multihop_ttl,
6518 neighbor_ebgp_multihop_ttl_cmd,
6519 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6520 NEIGHBOR_STR
6521 NEIGHBOR_ADDR_STR2
6522 "Allow EBGP neighbors not on directly connected networks\n"
6523 "maximum hop count\n")
6524 {
6525 int idx_peer = 1;
6526 int idx_number = 3;
6527 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6528 argv[idx_number]->arg);
6529 }
6530
6531 DEFUN (no_neighbor_ebgp_multihop,
6532 no_neighbor_ebgp_multihop_cmd,
6533 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6534 NO_STR
6535 NEIGHBOR_STR
6536 NEIGHBOR_ADDR_STR2
6537 "Allow EBGP neighbors not on directly connected networks\n"
6538 "maximum hop count\n")
6539 {
6540 int idx_peer = 2;
6541 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6542 }
6543
6544 static uint8_t get_role_by_name(const char *role_str)
6545 {
6546 if (strncmp(role_str, "peer", 2) == 0)
6547 return ROLE_PEER;
6548 if (strncmp(role_str, "provider", 2) == 0)
6549 return ROLE_PROVIDER;
6550 if (strncmp(role_str, "customer", 2) == 0)
6551 return ROLE_CUSTOMER;
6552 if (strncmp(role_str, "rs-server", 4) == 0)
6553 return ROLE_RS_SERVER;
6554 if (strncmp(role_str, "rs-client", 4) == 0)
6555 return ROLE_RS_CLIENT;
6556 return ROLE_UNDEFINED;
6557 }
6558
6559 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6560 const char *role_str, bool strict_mode)
6561 {
6562 struct peer *peer;
6563
6564 peer = peer_and_group_lookup_vty(vty, ip_str);
6565 if (!peer)
6566 return CMD_WARNING_CONFIG_FAILED;
6567 uint8_t role = get_role_by_name(role_str);
6568
6569 if (role == ROLE_UNDEFINED)
6570 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6571 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6572 }
6573
6574 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6575 {
6576 struct peer *peer;
6577
6578 peer = peer_and_group_lookup_vty(vty, ip_str);
6579 if (!peer)
6580 return CMD_WARNING_CONFIG_FAILED;
6581 return bgp_vty_return(vty, peer_role_unset(peer));
6582 }
6583
6584 DEFPY(neighbor_role,
6585 neighbor_role_cmd,
6586 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6587 NEIGHBOR_STR
6588 NEIGHBOR_ADDR_STR2
6589 "Set session role\n"
6590 ROLE_STR)
6591 {
6592 int idx_peer = 1;
6593 int idx_role = 3;
6594
6595 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6596 false);
6597 }
6598
6599 DEFPY(neighbor_role_strict,
6600 neighbor_role_strict_cmd,
6601 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6602 NEIGHBOR_STR
6603 NEIGHBOR_ADDR_STR2
6604 "Set session role\n"
6605 ROLE_STR
6606 "Use additional restriction on peer\n")
6607 {
6608 int idx_peer = 1;
6609 int idx_role = 3;
6610
6611 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6612 true);
6613 }
6614
6615 DEFPY(no_neighbor_role,
6616 no_neighbor_role_cmd,
6617 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6618 NO_STR
6619 NEIGHBOR_STR
6620 NEIGHBOR_ADDR_STR2
6621 "Set session role\n"
6622 ROLE_STR
6623 "Use additional restriction on peer\n")
6624 {
6625 int idx_peer = 2;
6626
6627 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6628 }
6629
6630 /* disable-connected-check */
6631 DEFUN (neighbor_disable_connected_check,
6632 neighbor_disable_connected_check_cmd,
6633 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6634 NEIGHBOR_STR
6635 NEIGHBOR_ADDR_STR2
6636 "one-hop away EBGP peer using loopback address\n"
6637 "Enforce EBGP neighbors perform multihop\n")
6638 {
6639 int idx_peer = 1;
6640 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6641 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6642 }
6643
6644 DEFUN (no_neighbor_disable_connected_check,
6645 no_neighbor_disable_connected_check_cmd,
6646 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6647 NO_STR
6648 NEIGHBOR_STR
6649 NEIGHBOR_ADDR_STR2
6650 "one-hop away EBGP peer using loopback address\n"
6651 "Enforce EBGP neighbors perform multihop\n")
6652 {
6653 int idx_peer = 2;
6654 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6655 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6656 }
6657
6658 /* disable-link-bw-encoding-ieee */
6659 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6660 neighbor_disable_link_bw_encoding_ieee_cmd,
6661 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6662 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6663 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6664 {
6665 int idx_peer = 1;
6666
6667 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6668 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6669 }
6670
6671 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6672 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6673 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6674 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6675 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6676 {
6677 int idx_peer = 2;
6678
6679 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6680 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6681 }
6682
6683 /* extended-optional-parameters */
6684 DEFUN(neighbor_extended_optional_parameters,
6685 neighbor_extended_optional_parameters_cmd,
6686 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6687 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6688 "Force the extended optional parameters format for OPEN messages\n")
6689 {
6690 int idx_peer = 1;
6691
6692 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6693 PEER_FLAG_EXTENDED_OPT_PARAMS);
6694 }
6695
6696 DEFUN(no_neighbor_extended_optional_parameters,
6697 no_neighbor_extended_optional_parameters_cmd,
6698 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6699 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6700 "Force the extended optional parameters format for OPEN messages\n")
6701 {
6702 int idx_peer = 2;
6703
6704 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6705 PEER_FLAG_EXTENDED_OPT_PARAMS);
6706 }
6707
6708 /* enforce-first-as */
6709 DEFUN (neighbor_enforce_first_as,
6710 neighbor_enforce_first_as_cmd,
6711 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6712 NEIGHBOR_STR
6713 NEIGHBOR_ADDR_STR2
6714 "Enforce the first AS for EBGP routes\n")
6715 {
6716 int idx_peer = 1;
6717
6718 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6719 PEER_FLAG_ENFORCE_FIRST_AS);
6720 }
6721
6722 DEFUN (no_neighbor_enforce_first_as,
6723 no_neighbor_enforce_first_as_cmd,
6724 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6725 NO_STR
6726 NEIGHBOR_STR
6727 NEIGHBOR_ADDR_STR2
6728 "Enforce the first AS for EBGP routes\n")
6729 {
6730 int idx_peer = 2;
6731
6732 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6733 PEER_FLAG_ENFORCE_FIRST_AS);
6734 }
6735
6736
6737 DEFUN (neighbor_description,
6738 neighbor_description_cmd,
6739 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6740 NEIGHBOR_STR
6741 NEIGHBOR_ADDR_STR2
6742 "Neighbor specific description\n"
6743 "Up to 80 characters describing this neighbor\n")
6744 {
6745 int idx_peer = 1;
6746 int idx_line = 3;
6747 struct peer *peer;
6748 char *str;
6749
6750 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6751 if (!peer)
6752 return CMD_WARNING_CONFIG_FAILED;
6753
6754 str = argv_concat(argv, argc, idx_line);
6755
6756 peer_description_set(peer, str);
6757
6758 XFREE(MTYPE_TMP, str);
6759
6760 return CMD_SUCCESS;
6761 }
6762
6763 DEFUN (no_neighbor_description,
6764 no_neighbor_description_cmd,
6765 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6766 NO_STR
6767 NEIGHBOR_STR
6768 NEIGHBOR_ADDR_STR2
6769 "Neighbor specific description\n")
6770 {
6771 int idx_peer = 2;
6772 struct peer *peer;
6773
6774 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6775 if (!peer)
6776 return CMD_WARNING_CONFIG_FAILED;
6777
6778 peer_description_unset(peer);
6779
6780 return CMD_SUCCESS;
6781 }
6782
6783 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6784 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6785 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6786 "Neighbor specific description\n"
6787 "Up to 80 characters describing this neighbor\n")
6788
6789 /* Neighbor update-source. */
6790 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6791 const char *source_str)
6792 {
6793 struct peer *peer;
6794 struct prefix p;
6795 union sockunion su;
6796
6797 peer = peer_and_group_lookup_vty(vty, peer_str);
6798 if (!peer)
6799 return CMD_WARNING_CONFIG_FAILED;
6800
6801 if (peer->conf_if)
6802 return CMD_WARNING;
6803
6804 if (source_str) {
6805 if (str2sockunion(source_str, &su) == 0)
6806 peer_update_source_addr_set(peer, &su);
6807 else {
6808 if (str2prefix(source_str, &p)) {
6809 vty_out(vty,
6810 "%% Invalid update-source, remove prefix length \n");
6811 return CMD_WARNING_CONFIG_FAILED;
6812 } else
6813 peer_update_source_if_set(peer, source_str);
6814 }
6815 } else
6816 peer_update_source_unset(peer);
6817
6818 return CMD_SUCCESS;
6819 }
6820
6821 #define BGP_UPDATE_SOURCE_HELP_STR \
6822 "IPv4 address\n" \
6823 "IPv6 address\n" \
6824 "Interface name (requires zebra to be running)\n"
6825
6826 DEFUN (neighbor_update_source,
6827 neighbor_update_source_cmd,
6828 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6829 NEIGHBOR_STR
6830 NEIGHBOR_ADDR_STR2
6831 "Source of routing updates\n"
6832 BGP_UPDATE_SOURCE_HELP_STR)
6833 {
6834 int idx_peer = 1;
6835 int idx_peer_2 = 3;
6836 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6837 argv[idx_peer_2]->arg);
6838 }
6839
6840 DEFUN (no_neighbor_update_source,
6841 no_neighbor_update_source_cmd,
6842 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6843 NO_STR
6844 NEIGHBOR_STR
6845 NEIGHBOR_ADDR_STR2
6846 "Source of routing updates\n"
6847 BGP_UPDATE_SOURCE_HELP_STR)
6848 {
6849 int idx_peer = 2;
6850 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6851 }
6852
6853 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6854 afi_t afi, safi_t safi,
6855 const char *rmap, int set)
6856 {
6857 int ret;
6858 struct peer *peer;
6859 struct route_map *route_map = NULL;
6860
6861 peer = peer_and_group_lookup_vty(vty, peer_str);
6862 if (!peer)
6863 return CMD_WARNING_CONFIG_FAILED;
6864
6865 if (set) {
6866 if (rmap)
6867 route_map = route_map_lookup_warn_noexist(vty, rmap);
6868 ret = peer_default_originate_set(peer, afi, safi,
6869 rmap, route_map);
6870 } else
6871 ret = peer_default_originate_unset(peer, afi, safi);
6872
6873 return bgp_vty_return(vty, ret);
6874 }
6875
6876 /* neighbor default-originate. */
6877 DEFUN (neighbor_default_originate,
6878 neighbor_default_originate_cmd,
6879 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6880 NEIGHBOR_STR
6881 NEIGHBOR_ADDR_STR2
6882 "Originate default route to this neighbor\n")
6883 {
6884 int idx_peer = 1;
6885 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6886 bgp_node_afi(vty),
6887 bgp_node_safi(vty), NULL, 1);
6888 }
6889
6890 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6891 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6892 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6893 "Originate default route to this neighbor\n")
6894
6895 DEFUN (neighbor_default_originate_rmap,
6896 neighbor_default_originate_rmap_cmd,
6897 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6898 NEIGHBOR_STR
6899 NEIGHBOR_ADDR_STR2
6900 "Originate default route to this neighbor\n"
6901 "Route-map to specify criteria to originate default\n"
6902 "route-map name\n")
6903 {
6904 int idx_peer = 1;
6905 int idx_word = 4;
6906 return peer_default_originate_set_vty(
6907 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6908 argv[idx_word]->arg, 1);
6909 }
6910
6911 ALIAS_HIDDEN(
6912 neighbor_default_originate_rmap,
6913 neighbor_default_originate_rmap_hidden_cmd,
6914 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6915 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6916 "Originate default route to this neighbor\n"
6917 "Route-map to specify criteria to originate default\n"
6918 "route-map name\n")
6919
6920 DEFUN (no_neighbor_default_originate,
6921 no_neighbor_default_originate_cmd,
6922 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6923 NO_STR
6924 NEIGHBOR_STR
6925 NEIGHBOR_ADDR_STR2
6926 "Originate default route to this neighbor\n"
6927 "Route-map to specify criteria to originate default\n"
6928 "route-map name\n")
6929 {
6930 int idx_peer = 2;
6931 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6932 bgp_node_afi(vty),
6933 bgp_node_safi(vty), NULL, 0);
6934 }
6935
6936 ALIAS_HIDDEN(
6937 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6938 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6939 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6940 "Originate default route to this neighbor\n"
6941 "Route-map to specify criteria to originate default\n"
6942 "route-map name\n")
6943
6944
6945 /* Set neighbor's BGP port. */
6946 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6947 const char *port_str)
6948 {
6949 struct peer *peer;
6950 uint16_t port;
6951 struct servent *sp;
6952
6953 peer = peer_and_group_lookup_vty(vty, ip_str);
6954 if (!peer)
6955 return CMD_WARNING_CONFIG_FAILED;
6956
6957 if (!port_str) {
6958 sp = getservbyname("bgp", "tcp");
6959 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6960 } else {
6961 port = strtoul(port_str, NULL, 10);
6962 }
6963
6964 peer_port_set(peer, port);
6965
6966 return CMD_SUCCESS;
6967 }
6968
6969 /* Set specified peer's BGP port. */
6970 DEFUN (neighbor_port,
6971 neighbor_port_cmd,
6972 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6973 NEIGHBOR_STR
6974 NEIGHBOR_ADDR_STR2
6975 "Neighbor's BGP port\n"
6976 "TCP port number\n")
6977 {
6978 int idx_ip = 1;
6979 int idx_number = 3;
6980 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6981 argv[idx_number]->arg);
6982 }
6983
6984 DEFUN (no_neighbor_port,
6985 no_neighbor_port_cmd,
6986 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6987 NO_STR
6988 NEIGHBOR_STR
6989 NEIGHBOR_ADDR_STR2
6990 "Neighbor's BGP port\n"
6991 "TCP port number\n")
6992 {
6993 int idx_ip = 2;
6994 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6995 }
6996
6997
6998 /* neighbor weight. */
6999 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7000 safi_t safi, const char *weight_str)
7001 {
7002 int ret;
7003 struct peer *peer;
7004 unsigned long weight;
7005
7006 peer = peer_and_group_lookup_vty(vty, ip_str);
7007 if (!peer)
7008 return CMD_WARNING_CONFIG_FAILED;
7009
7010 weight = strtoul(weight_str, NULL, 10);
7011
7012 ret = peer_weight_set(peer, afi, safi, weight);
7013 return bgp_vty_return(vty, ret);
7014 }
7015
7016 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7017 safi_t safi)
7018 {
7019 int ret;
7020 struct peer *peer;
7021
7022 peer = peer_and_group_lookup_vty(vty, ip_str);
7023 if (!peer)
7024 return CMD_WARNING_CONFIG_FAILED;
7025
7026 ret = peer_weight_unset(peer, afi, safi);
7027 return bgp_vty_return(vty, ret);
7028 }
7029
7030 DEFUN (neighbor_weight,
7031 neighbor_weight_cmd,
7032 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7033 NEIGHBOR_STR
7034 NEIGHBOR_ADDR_STR2
7035 "Set default weight for routes from this neighbor\n"
7036 "default weight\n")
7037 {
7038 int idx_peer = 1;
7039 int idx_number = 3;
7040 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7041 bgp_node_safi(vty), argv[idx_number]->arg);
7042 }
7043
7044 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7045 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7046 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7047 "Set default weight for routes from this neighbor\n"
7048 "default weight\n")
7049
7050 DEFUN (no_neighbor_weight,
7051 no_neighbor_weight_cmd,
7052 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7053 NO_STR
7054 NEIGHBOR_STR
7055 NEIGHBOR_ADDR_STR2
7056 "Set default weight for routes from this neighbor\n"
7057 "default weight\n")
7058 {
7059 int idx_peer = 2;
7060 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7061 bgp_node_afi(vty), bgp_node_safi(vty));
7062 }
7063
7064 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7065 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7066 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7067 "Set default weight for routes from this neighbor\n"
7068 "default weight\n")
7069
7070
7071 /* Override capability negotiation. */
7072 DEFUN (neighbor_override_capability,
7073 neighbor_override_capability_cmd,
7074 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7075 NEIGHBOR_STR
7076 NEIGHBOR_ADDR_STR2
7077 "Override capability negotiation result\n")
7078 {
7079 int idx_peer = 1;
7080 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7081 PEER_FLAG_OVERRIDE_CAPABILITY);
7082 }
7083
7084 DEFUN (no_neighbor_override_capability,
7085 no_neighbor_override_capability_cmd,
7086 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7087 NO_STR
7088 NEIGHBOR_STR
7089 NEIGHBOR_ADDR_STR2
7090 "Override capability negotiation result\n")
7091 {
7092 int idx_peer = 2;
7093 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7094 PEER_FLAG_OVERRIDE_CAPABILITY);
7095 }
7096
7097 DEFUN (neighbor_strict_capability,
7098 neighbor_strict_capability_cmd,
7099 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7100 NEIGHBOR_STR
7101 NEIGHBOR_ADDR_STR2
7102 "Strict capability negotiation match\n")
7103 {
7104 int idx_peer = 1;
7105
7106 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7107 PEER_FLAG_STRICT_CAP_MATCH);
7108 }
7109
7110 DEFUN (no_neighbor_strict_capability,
7111 no_neighbor_strict_capability_cmd,
7112 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7113 NO_STR
7114 NEIGHBOR_STR
7115 NEIGHBOR_ADDR_STR2
7116 "Strict capability negotiation match\n")
7117 {
7118 int idx_peer = 2;
7119
7120 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7121 PEER_FLAG_STRICT_CAP_MATCH);
7122 }
7123
7124 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7125 const char *keep_str, const char *hold_str)
7126 {
7127 int ret;
7128 struct peer *peer;
7129 uint32_t keepalive;
7130 uint32_t holdtime;
7131
7132 peer = peer_and_group_lookup_vty(vty, ip_str);
7133 if (!peer)
7134 return CMD_WARNING_CONFIG_FAILED;
7135
7136 keepalive = strtoul(keep_str, NULL, 10);
7137 holdtime = strtoul(hold_str, NULL, 10);
7138
7139 ret = peer_timers_set(peer, keepalive, holdtime);
7140
7141 return bgp_vty_return(vty, ret);
7142 }
7143
7144 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7145 {
7146 int ret;
7147 struct peer *peer;
7148
7149 peer = peer_and_group_lookup_vty(vty, ip_str);
7150 if (!peer)
7151 return CMD_WARNING_CONFIG_FAILED;
7152
7153 ret = peer_timers_unset(peer);
7154
7155 return bgp_vty_return(vty, ret);
7156 }
7157
7158 DEFUN (neighbor_timers,
7159 neighbor_timers_cmd,
7160 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7161 NEIGHBOR_STR
7162 NEIGHBOR_ADDR_STR2
7163 "BGP per neighbor timers\n"
7164 "Keepalive interval\n"
7165 "Holdtime\n")
7166 {
7167 int idx_peer = 1;
7168 int idx_number = 3;
7169 int idx_number_2 = 4;
7170 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7171 argv[idx_number]->arg,
7172 argv[idx_number_2]->arg);
7173 }
7174
7175 DEFUN (no_neighbor_timers,
7176 no_neighbor_timers_cmd,
7177 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7178 NO_STR
7179 NEIGHBOR_STR
7180 NEIGHBOR_ADDR_STR2
7181 "BGP per neighbor timers\n"
7182 "Keepalive interval\n"
7183 "Holdtime\n")
7184 {
7185 int idx_peer = 2;
7186 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7187 }
7188
7189
7190 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7191 const char *time_str)
7192 {
7193 int ret;
7194 struct peer *peer;
7195 uint32_t connect;
7196
7197 peer = peer_and_group_lookup_vty(vty, ip_str);
7198 if (!peer)
7199 return CMD_WARNING_CONFIG_FAILED;
7200
7201 connect = strtoul(time_str, NULL, 10);
7202
7203 ret = peer_timers_connect_set(peer, connect);
7204
7205 return bgp_vty_return(vty, ret);
7206 }
7207
7208 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7209 {
7210 int ret;
7211 struct peer *peer;
7212
7213 peer = peer_and_group_lookup_vty(vty, ip_str);
7214 if (!peer)
7215 return CMD_WARNING_CONFIG_FAILED;
7216
7217 ret = peer_timers_connect_unset(peer);
7218
7219 return bgp_vty_return(vty, ret);
7220 }
7221
7222 DEFUN (neighbor_timers_connect,
7223 neighbor_timers_connect_cmd,
7224 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7225 NEIGHBOR_STR
7226 NEIGHBOR_ADDR_STR2
7227 "BGP per neighbor timers\n"
7228 "BGP connect timer\n"
7229 "Connect timer\n")
7230 {
7231 int idx_peer = 1;
7232 int idx_number = 4;
7233 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7234 argv[idx_number]->arg);
7235 }
7236
7237 DEFUN (no_neighbor_timers_connect,
7238 no_neighbor_timers_connect_cmd,
7239 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7240 NO_STR
7241 NEIGHBOR_STR
7242 NEIGHBOR_ADDR_STR2
7243 "BGP per neighbor timers\n"
7244 "BGP connect timer\n"
7245 "Connect timer\n")
7246 {
7247 int idx_peer = 2;
7248 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7249 }
7250
7251 DEFPY (neighbor_timers_delayopen,
7252 neighbor_timers_delayopen_cmd,
7253 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7254 NEIGHBOR_STR
7255 NEIGHBOR_ADDR_STR2
7256 "BGP per neighbor timers\n"
7257 "RFC 4271 DelayOpenTimer\n"
7258 "DelayOpenTime timer interval\n")
7259 {
7260 struct peer *peer;
7261
7262 peer = peer_and_group_lookup_vty(vty, neighbor);
7263 if (!peer)
7264 return CMD_WARNING_CONFIG_FAILED;
7265
7266 if (!interval) {
7267 if (peer_timers_delayopen_unset(peer))
7268 return CMD_WARNING_CONFIG_FAILED;
7269 } else {
7270 if (peer_timers_delayopen_set(peer, interval))
7271 return CMD_WARNING_CONFIG_FAILED;
7272 }
7273
7274 return CMD_SUCCESS;
7275 }
7276
7277 DEFPY (no_neighbor_timers_delayopen,
7278 no_neighbor_timers_delayopen_cmd,
7279 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7280 NO_STR
7281 NEIGHBOR_STR
7282 NEIGHBOR_ADDR_STR2
7283 "BGP per neighbor timers\n"
7284 "RFC 4271 DelayOpenTimer\n"
7285 "DelayOpenTime timer interval\n")
7286 {
7287 struct peer *peer;
7288
7289 peer = peer_and_group_lookup_vty(vty, neighbor);
7290 if (!peer)
7291 return CMD_WARNING_CONFIG_FAILED;
7292
7293 if (peer_timers_delayopen_unset(peer))
7294 return CMD_WARNING_CONFIG_FAILED;
7295
7296 return CMD_SUCCESS;
7297 }
7298
7299 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7300 const char *time_str, int set)
7301 {
7302 int ret;
7303 struct peer *peer;
7304 uint32_t routeadv = 0;
7305
7306 peer = peer_and_group_lookup_vty(vty, ip_str);
7307 if (!peer)
7308 return CMD_WARNING_CONFIG_FAILED;
7309
7310 if (time_str)
7311 routeadv = strtoul(time_str, NULL, 10);
7312
7313 if (set)
7314 ret = peer_advertise_interval_set(peer, routeadv);
7315 else
7316 ret = peer_advertise_interval_unset(peer);
7317
7318 return bgp_vty_return(vty, ret);
7319 }
7320
7321 DEFUN (neighbor_advertise_interval,
7322 neighbor_advertise_interval_cmd,
7323 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7324 NEIGHBOR_STR
7325 NEIGHBOR_ADDR_STR2
7326 "Minimum interval between sending BGP routing updates\n"
7327 "time in seconds\n")
7328 {
7329 int idx_peer = 1;
7330 int idx_number = 3;
7331 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7332 argv[idx_number]->arg, 1);
7333 }
7334
7335 DEFUN (no_neighbor_advertise_interval,
7336 no_neighbor_advertise_interval_cmd,
7337 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7338 NO_STR
7339 NEIGHBOR_STR
7340 NEIGHBOR_ADDR_STR2
7341 "Minimum interval between sending BGP routing updates\n"
7342 "time in seconds\n")
7343 {
7344 int idx_peer = 2;
7345 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7346 }
7347
7348
7349 /* Time to wait before processing route-map updates */
7350 DEFUN (bgp_set_route_map_delay_timer,
7351 bgp_set_route_map_delay_timer_cmd,
7352 "bgp route-map delay-timer (0-600)",
7353 SET_STR
7354 "BGP route-map delay timer\n"
7355 "Time in secs to wait before processing route-map changes\n"
7356 "0 disables the timer, no route updates happen when route-maps change\n")
7357 {
7358 int idx_number = 3;
7359 uint32_t rmap_delay_timer;
7360
7361 if (argv[idx_number]->arg) {
7362 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7363 bm->rmap_update_timer = rmap_delay_timer;
7364
7365 /* if the dynamic update handling is being disabled, and a timer
7366 * is
7367 * running, stop the timer and act as if the timer has already
7368 * fired.
7369 */
7370 if (!rmap_delay_timer && bm->t_rmap_update) {
7371 THREAD_OFF(bm->t_rmap_update);
7372 thread_execute(bm->master, bgp_route_map_update_timer,
7373 NULL, 0);
7374 }
7375 return CMD_SUCCESS;
7376 } else {
7377 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7378 return CMD_WARNING_CONFIG_FAILED;
7379 }
7380 }
7381
7382 DEFUN (no_bgp_set_route_map_delay_timer,
7383 no_bgp_set_route_map_delay_timer_cmd,
7384 "no bgp route-map delay-timer [(0-600)]",
7385 NO_STR
7386 BGP_STR
7387 "Default BGP route-map delay timer\n"
7388 "Reset to default time to wait for processing route-map changes\n"
7389 "0 disables the timer, no route updates happen when route-maps change\n")
7390 {
7391
7392 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7393
7394 return CMD_SUCCESS;
7395 }
7396
7397 /* neighbor interface */
7398 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7399 const char *str)
7400 {
7401 struct peer *peer;
7402
7403 peer = peer_lookup_vty(vty, ip_str);
7404 if (!peer || peer->conf_if) {
7405 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7406 return CMD_WARNING_CONFIG_FAILED;
7407 }
7408
7409 if (str)
7410 peer_interface_set(peer, str);
7411 else
7412 peer_interface_unset(peer);
7413
7414 return CMD_SUCCESS;
7415 }
7416
7417 DEFUN (neighbor_interface,
7418 neighbor_interface_cmd,
7419 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7420 NEIGHBOR_STR
7421 NEIGHBOR_ADDR_STR
7422 "Interface\n"
7423 "Interface name\n")
7424 {
7425 int idx_ip = 1;
7426 int idx_word = 3;
7427
7428 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7429 }
7430
7431 DEFUN (no_neighbor_interface,
7432 no_neighbor_interface_cmd,
7433 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7434 NO_STR
7435 NEIGHBOR_STR
7436 NEIGHBOR_ADDR_STR
7437 "Interface\n"
7438 "Interface name\n")
7439 {
7440 int idx_peer = 2;
7441
7442 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7443 }
7444
7445 DEFUN (neighbor_distribute_list,
7446 neighbor_distribute_list_cmd,
7447 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7448 NEIGHBOR_STR
7449 NEIGHBOR_ADDR_STR2
7450 "Filter updates to/from this neighbor\n"
7451 "IP Access-list name\n"
7452 "Filter incoming updates\n"
7453 "Filter outgoing updates\n")
7454 {
7455 int idx_peer = 1;
7456 int idx_acl = 3;
7457 int direct, ret;
7458 struct peer *peer;
7459
7460 const char *pstr = argv[idx_peer]->arg;
7461 const char *acl = argv[idx_acl]->arg;
7462 const char *inout = argv[argc - 1]->text;
7463
7464 peer = peer_and_group_lookup_vty(vty, pstr);
7465 if (!peer)
7466 return CMD_WARNING_CONFIG_FAILED;
7467
7468 /* Check filter direction. */
7469 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7470 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7471 direct, acl);
7472
7473 return bgp_vty_return(vty, ret);
7474 }
7475
7476 ALIAS_HIDDEN(
7477 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7478 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7479 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7480 "Filter updates to/from this neighbor\n"
7481 "IP Access-list name\n"
7482 "Filter incoming updates\n"
7483 "Filter outgoing updates\n")
7484
7485 DEFUN (no_neighbor_distribute_list,
7486 no_neighbor_distribute_list_cmd,
7487 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7488 NO_STR
7489 NEIGHBOR_STR
7490 NEIGHBOR_ADDR_STR2
7491 "Filter updates to/from this neighbor\n"
7492 "IP Access-list name\n"
7493 "Filter incoming updates\n"
7494 "Filter outgoing updates\n")
7495 {
7496 int idx_peer = 2;
7497 int direct, ret;
7498 struct peer *peer;
7499
7500 const char *pstr = argv[idx_peer]->arg;
7501 const char *inout = argv[argc - 1]->text;
7502
7503 peer = peer_and_group_lookup_vty(vty, pstr);
7504 if (!peer)
7505 return CMD_WARNING_CONFIG_FAILED;
7506
7507 /* Check filter direction. */
7508 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7509 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7510 direct);
7511
7512 return bgp_vty_return(vty, ret);
7513 }
7514
7515 ALIAS_HIDDEN(
7516 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7517 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7518 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7519 "Filter updates to/from this neighbor\n"
7520 "IP Access-list name\n"
7521 "Filter incoming updates\n"
7522 "Filter outgoing updates\n")
7523
7524 /* Set prefix list to the peer. */
7525 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7526 afi_t afi, safi_t safi,
7527 const char *name_str,
7528 const char *direct_str)
7529 {
7530 int ret;
7531 int direct = FILTER_IN;
7532 struct peer *peer;
7533
7534 peer = peer_and_group_lookup_vty(vty, ip_str);
7535 if (!peer)
7536 return CMD_WARNING_CONFIG_FAILED;
7537
7538 /* Check filter direction. */
7539 if (strncmp(direct_str, "i", 1) == 0)
7540 direct = FILTER_IN;
7541 else if (strncmp(direct_str, "o", 1) == 0)
7542 direct = FILTER_OUT;
7543
7544 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7545
7546 return bgp_vty_return(vty, ret);
7547 }
7548
7549 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7550 afi_t afi, safi_t safi,
7551 const char *direct_str)
7552 {
7553 int ret;
7554 struct peer *peer;
7555 int direct = FILTER_IN;
7556
7557 peer = peer_and_group_lookup_vty(vty, ip_str);
7558 if (!peer)
7559 return CMD_WARNING_CONFIG_FAILED;
7560
7561 /* Check filter direction. */
7562 if (strncmp(direct_str, "i", 1) == 0)
7563 direct = FILTER_IN;
7564 else if (strncmp(direct_str, "o", 1) == 0)
7565 direct = FILTER_OUT;
7566
7567 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7568
7569 return bgp_vty_return(vty, ret);
7570 }
7571
7572 DEFUN (neighbor_prefix_list,
7573 neighbor_prefix_list_cmd,
7574 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7575 NEIGHBOR_STR
7576 NEIGHBOR_ADDR_STR2
7577 "Filter updates to/from this neighbor\n"
7578 "Name of a prefix list\n"
7579 "Filter incoming updates\n"
7580 "Filter outgoing updates\n")
7581 {
7582 int idx_peer = 1;
7583 int idx_word = 3;
7584 int idx_in_out = 4;
7585 return peer_prefix_list_set_vty(
7586 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7587 argv[idx_word]->arg, argv[idx_in_out]->arg);
7588 }
7589
7590 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7591 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7592 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7593 "Filter updates to/from this neighbor\n"
7594 "Name of a prefix list\n"
7595 "Filter incoming updates\n"
7596 "Filter outgoing updates\n")
7597
7598 DEFUN (no_neighbor_prefix_list,
7599 no_neighbor_prefix_list_cmd,
7600 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7601 NO_STR
7602 NEIGHBOR_STR
7603 NEIGHBOR_ADDR_STR2
7604 "Filter updates to/from this neighbor\n"
7605 "Name of a prefix list\n"
7606 "Filter incoming updates\n"
7607 "Filter outgoing updates\n")
7608 {
7609 int idx_peer = 2;
7610 int idx_in_out = 5;
7611 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7612 bgp_node_afi(vty), bgp_node_safi(vty),
7613 argv[idx_in_out]->arg);
7614 }
7615
7616 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7617 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7618 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7619 "Filter updates to/from this neighbor\n"
7620 "Name of a prefix list\n"
7621 "Filter incoming updates\n"
7622 "Filter outgoing updates\n")
7623
7624 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7625 safi_t safi, const char *name_str,
7626 const char *direct_str)
7627 {
7628 int ret;
7629 struct peer *peer;
7630 int direct = FILTER_IN;
7631
7632 peer = peer_and_group_lookup_vty(vty, ip_str);
7633 if (!peer)
7634 return CMD_WARNING_CONFIG_FAILED;
7635
7636 /* Check filter direction. */
7637 if (strncmp(direct_str, "i", 1) == 0)
7638 direct = FILTER_IN;
7639 else if (strncmp(direct_str, "o", 1) == 0)
7640 direct = FILTER_OUT;
7641
7642 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7643
7644 return bgp_vty_return(vty, ret);
7645 }
7646
7647 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7648 safi_t safi, const char *direct_str)
7649 {
7650 int ret;
7651 struct peer *peer;
7652 int direct = FILTER_IN;
7653
7654 peer = peer_and_group_lookup_vty(vty, ip_str);
7655 if (!peer)
7656 return CMD_WARNING_CONFIG_FAILED;
7657
7658 /* Check filter direction. */
7659 if (strncmp(direct_str, "i", 1) == 0)
7660 direct = FILTER_IN;
7661 else if (strncmp(direct_str, "o", 1) == 0)
7662 direct = FILTER_OUT;
7663
7664 ret = peer_aslist_unset(peer, afi, safi, direct);
7665
7666 return bgp_vty_return(vty, ret);
7667 }
7668
7669 DEFUN (neighbor_filter_list,
7670 neighbor_filter_list_cmd,
7671 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7672 NEIGHBOR_STR
7673 NEIGHBOR_ADDR_STR2
7674 "Establish BGP filters\n"
7675 "AS path access-list name\n"
7676 "Filter incoming routes\n"
7677 "Filter outgoing routes\n")
7678 {
7679 int idx_peer = 1;
7680 int idx_word = 3;
7681 int idx_in_out = 4;
7682 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7683 bgp_node_safi(vty), argv[idx_word]->arg,
7684 argv[idx_in_out]->arg);
7685 }
7686
7687 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7688 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7689 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7690 "Establish BGP filters\n"
7691 "AS path access-list name\n"
7692 "Filter incoming routes\n"
7693 "Filter outgoing routes\n")
7694
7695 DEFUN (no_neighbor_filter_list,
7696 no_neighbor_filter_list_cmd,
7697 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7698 NO_STR
7699 NEIGHBOR_STR
7700 NEIGHBOR_ADDR_STR2
7701 "Establish BGP filters\n"
7702 "AS path access-list name\n"
7703 "Filter incoming routes\n"
7704 "Filter outgoing routes\n")
7705 {
7706 int idx_peer = 2;
7707 int idx_in_out = 5;
7708 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7709 bgp_node_afi(vty), bgp_node_safi(vty),
7710 argv[idx_in_out]->arg);
7711 }
7712
7713 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7714 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7715 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7716 "Establish BGP filters\n"
7717 "AS path access-list name\n"
7718 "Filter incoming routes\n"
7719 "Filter outgoing routes\n")
7720
7721 /* Set advertise-map to the peer. */
7722 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7723 afi_t afi, safi_t safi,
7724 const char *advertise_str,
7725 const char *condition_str, bool condition,
7726 bool set)
7727 {
7728 int ret = CMD_WARNING_CONFIG_FAILED;
7729 struct peer *peer;
7730 struct route_map *advertise_map;
7731 struct route_map *condition_map;
7732
7733 peer = peer_and_group_lookup_vty(vty, ip_str);
7734 if (!peer)
7735 return ret;
7736
7737 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7738 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7739
7740 if (set)
7741 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7742 advertise_map, condition_str,
7743 condition_map, condition);
7744 else
7745 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7746 advertise_map, condition_str,
7747 condition_map, condition);
7748
7749 return bgp_vty_return(vty, ret);
7750 }
7751
7752 DEFPY (bgp_condadv_period,
7753 bgp_condadv_period_cmd,
7754 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7755 NO_STR
7756 BGP_STR
7757 "Conditional advertisement settings\n"
7758 "Set period to rescan BGP table to check if condition is met\n"
7759 "Period between BGP table scans, in seconds; default 60\n")
7760 {
7761 VTY_DECLVAR_CONTEXT(bgp, bgp);
7762
7763 bgp->condition_check_period =
7764 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7765
7766 return CMD_SUCCESS;
7767 }
7768
7769 DEFPY (neighbor_advertise_map,
7770 neighbor_advertise_map_cmd,
7771 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7772 NO_STR
7773 NEIGHBOR_STR
7774 NEIGHBOR_ADDR_STR2
7775 "Route-map to conditionally advertise routes\n"
7776 "Name of advertise map\n"
7777 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7778 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7779 "Name of the exist or non exist map\n")
7780 {
7781 bool condition = CONDITION_EXIST;
7782
7783 if (!strcmp(exist, "non-exist-map"))
7784 condition = CONDITION_NON_EXIST;
7785
7786 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7787 bgp_node_safi(vty), advertise_str,
7788 condition_str, condition, !no);
7789 }
7790
7791 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7792 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7793 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7794 "Route-map to conditionally advertise routes\n"
7795 "Name of advertise map\n"
7796 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7797 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7798 "Name of the exist or non exist map\n")
7799
7800 /* Set route-map to the peer. */
7801 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7802 afi_t afi, safi_t safi, const char *name_str,
7803 const char *direct_str)
7804 {
7805 int ret;
7806 struct peer *peer;
7807 int direct = RMAP_IN;
7808 struct route_map *route_map;
7809
7810 peer = peer_and_group_lookup_vty(vty, ip_str);
7811 if (!peer)
7812 return CMD_WARNING_CONFIG_FAILED;
7813
7814 /* Check filter direction. */
7815 if (strncmp(direct_str, "in", 2) == 0)
7816 direct = RMAP_IN;
7817 else if (strncmp(direct_str, "o", 1) == 0)
7818 direct = RMAP_OUT;
7819
7820 route_map = route_map_lookup_warn_noexist(vty, name_str);
7821 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7822
7823 return bgp_vty_return(vty, ret);
7824 }
7825
7826 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7827 afi_t afi, safi_t safi,
7828 const char *direct_str)
7829 {
7830 int ret;
7831 struct peer *peer;
7832 int direct = RMAP_IN;
7833
7834 peer = peer_and_group_lookup_vty(vty, ip_str);
7835 if (!peer)
7836 return CMD_WARNING_CONFIG_FAILED;
7837
7838 /* Check filter direction. */
7839 if (strncmp(direct_str, "in", 2) == 0)
7840 direct = RMAP_IN;
7841 else if (strncmp(direct_str, "o", 1) == 0)
7842 direct = RMAP_OUT;
7843
7844 ret = peer_route_map_unset(peer, afi, safi, direct);
7845
7846 return bgp_vty_return(vty, ret);
7847 }
7848
7849 DEFUN (neighbor_route_map,
7850 neighbor_route_map_cmd,
7851 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7852 NEIGHBOR_STR
7853 NEIGHBOR_ADDR_STR2
7854 "Apply route map to neighbor\n"
7855 "Name of route map\n"
7856 "Apply map to incoming routes\n"
7857 "Apply map to outbound routes\n")
7858 {
7859 int idx_peer = 1;
7860 int idx_word = 3;
7861 int idx_in_out = 4;
7862 return peer_route_map_set_vty(
7863 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7864 argv[idx_word]->arg, argv[idx_in_out]->arg);
7865 }
7866
7867 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7868 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7869 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7870 "Apply route map to neighbor\n"
7871 "Name of route map\n"
7872 "Apply map to incoming routes\n"
7873 "Apply map to outbound routes\n")
7874
7875 DEFUN (no_neighbor_route_map,
7876 no_neighbor_route_map_cmd,
7877 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7878 NO_STR
7879 NEIGHBOR_STR
7880 NEIGHBOR_ADDR_STR2
7881 "Apply route map to neighbor\n"
7882 "Name of route map\n"
7883 "Apply map to incoming routes\n"
7884 "Apply map to outbound routes\n")
7885 {
7886 int idx_peer = 2;
7887 int idx_in_out = 5;
7888 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7889 bgp_node_afi(vty), bgp_node_safi(vty),
7890 argv[idx_in_out]->arg);
7891 }
7892
7893 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7894 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7895 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7896 "Apply route map to neighbor\n"
7897 "Name of route map\n"
7898 "Apply map to incoming routes\n"
7899 "Apply map to outbound routes\n")
7900
7901 /* Set unsuppress-map to the peer. */
7902 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7903 afi_t afi, safi_t safi,
7904 const char *name_str)
7905 {
7906 int ret;
7907 struct peer *peer;
7908 struct route_map *route_map;
7909
7910 peer = peer_and_group_lookup_vty(vty, ip_str);
7911 if (!peer)
7912 return CMD_WARNING_CONFIG_FAILED;
7913
7914 route_map = route_map_lookup_warn_noexist(vty, name_str);
7915 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7916
7917 return bgp_vty_return(vty, ret);
7918 }
7919
7920 /* Unset route-map from the peer. */
7921 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7922 afi_t afi, safi_t safi)
7923 {
7924 int ret;
7925 struct peer *peer;
7926
7927 peer = peer_and_group_lookup_vty(vty, ip_str);
7928 if (!peer)
7929 return CMD_WARNING_CONFIG_FAILED;
7930
7931 ret = peer_unsuppress_map_unset(peer, afi, safi);
7932
7933 return bgp_vty_return(vty, ret);
7934 }
7935
7936 DEFUN (neighbor_unsuppress_map,
7937 neighbor_unsuppress_map_cmd,
7938 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7939 NEIGHBOR_STR
7940 NEIGHBOR_ADDR_STR2
7941 "Route-map to selectively unsuppress suppressed routes\n"
7942 "Name of route map\n")
7943 {
7944 int idx_peer = 1;
7945 int idx_word = 3;
7946 return peer_unsuppress_map_set_vty(
7947 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7948 argv[idx_word]->arg);
7949 }
7950
7951 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7952 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7953 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7954 "Route-map to selectively unsuppress suppressed routes\n"
7955 "Name of route map\n")
7956
7957 DEFUN (no_neighbor_unsuppress_map,
7958 no_neighbor_unsuppress_map_cmd,
7959 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7960 NO_STR
7961 NEIGHBOR_STR
7962 NEIGHBOR_ADDR_STR2
7963 "Route-map to selectively unsuppress suppressed routes\n"
7964 "Name of route map\n")
7965 {
7966 int idx_peer = 2;
7967 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7968 bgp_node_afi(vty),
7969 bgp_node_safi(vty));
7970 }
7971
7972 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7973 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7974 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7975 "Route-map to selectively unsuppress suppressed routes\n"
7976 "Name of route map\n")
7977
7978 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7979 afi_t afi, safi_t safi,
7980 const char *num_str,
7981 const char *threshold_str, int warning,
7982 const char *restart_str,
7983 const char *force_str)
7984 {
7985 int ret;
7986 struct peer *peer;
7987 uint32_t max;
7988 uint8_t threshold;
7989 uint16_t restart;
7990
7991 peer = peer_and_group_lookup_vty(vty, ip_str);
7992 if (!peer)
7993 return CMD_WARNING_CONFIG_FAILED;
7994
7995 max = strtoul(num_str, NULL, 10);
7996 if (threshold_str)
7997 threshold = atoi(threshold_str);
7998 else
7999 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8000
8001 if (restart_str)
8002 restart = atoi(restart_str);
8003 else
8004 restart = 0;
8005
8006 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8007 restart, force_str ? true : false);
8008
8009 return bgp_vty_return(vty, ret);
8010 }
8011
8012 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8013 afi_t afi, safi_t safi)
8014 {
8015 int ret;
8016 struct peer *peer;
8017
8018 peer = peer_and_group_lookup_vty(vty, ip_str);
8019 if (!peer)
8020 return CMD_WARNING_CONFIG_FAILED;
8021
8022 ret = peer_maximum_prefix_unset(peer, afi, safi);
8023
8024 return bgp_vty_return(vty, ret);
8025 }
8026
8027 /* Maximum number of prefix to be sent to the neighbor. */
8028 DEFUN(neighbor_maximum_prefix_out,
8029 neighbor_maximum_prefix_out_cmd,
8030 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8031 NEIGHBOR_STR
8032 NEIGHBOR_ADDR_STR2
8033 "Maximum number of prefixes to be sent to this peer\n"
8034 "Maximum no. of prefix limit\n")
8035 {
8036 int ret;
8037 int idx_peer = 1;
8038 int idx_number = 3;
8039 struct peer *peer;
8040 uint32_t max;
8041 afi_t afi = bgp_node_afi(vty);
8042 safi_t safi = bgp_node_safi(vty);
8043
8044 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8045 if (!peer)
8046 return CMD_WARNING_CONFIG_FAILED;
8047
8048 max = strtoul(argv[idx_number]->arg, NULL, 10);
8049
8050 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8051
8052 return bgp_vty_return(vty, ret);
8053 }
8054
8055 DEFUN(no_neighbor_maximum_prefix_out,
8056 no_neighbor_maximum_prefix_out_cmd,
8057 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8058 NO_STR
8059 NEIGHBOR_STR
8060 NEIGHBOR_ADDR_STR2
8061 "Maximum number of prefixes to be sent to this peer\n"
8062 "Maximum no. of prefix limit\n")
8063 {
8064 int ret;
8065 int idx_peer = 2;
8066 struct peer *peer;
8067 afi_t afi = bgp_node_afi(vty);
8068 safi_t safi = bgp_node_safi(vty);
8069
8070 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8071 if (!peer)
8072 return CMD_WARNING_CONFIG_FAILED;
8073
8074 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8075
8076 return bgp_vty_return(vty, ret);
8077 }
8078
8079 /* Maximum number of prefix configuration. Prefix count is different
8080 for each peer configuration. So this configuration can be set for
8081 each peer configuration. */
8082 DEFUN (neighbor_maximum_prefix,
8083 neighbor_maximum_prefix_cmd,
8084 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8085 NEIGHBOR_STR
8086 NEIGHBOR_ADDR_STR2
8087 "Maximum number of prefix accept from this peer\n"
8088 "maximum no. of prefix limit\n"
8089 "Force checking all received routes not only accepted\n")
8090 {
8091 int idx_peer = 1;
8092 int idx_number = 3;
8093 int idx_force = 0;
8094 char *force = NULL;
8095
8096 if (argv_find(argv, argc, "force", &idx_force))
8097 force = argv[idx_force]->arg;
8098
8099 return peer_maximum_prefix_set_vty(
8100 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8101 argv[idx_number]->arg, NULL, 0, NULL, force);
8102 }
8103
8104 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8105 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8106 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8107 "Maximum number of prefix accept from this peer\n"
8108 "maximum no. of prefix limit\n"
8109 "Force checking all received routes not only accepted\n")
8110
8111 DEFUN (neighbor_maximum_prefix_threshold,
8112 neighbor_maximum_prefix_threshold_cmd,
8113 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8114 NEIGHBOR_STR
8115 NEIGHBOR_ADDR_STR2
8116 "Maximum number of prefix accept from this peer\n"
8117 "maximum no. of prefix limit\n"
8118 "Threshold value (%) at which to generate a warning msg\n"
8119 "Force checking all received routes not only accepted\n")
8120 {
8121 int idx_peer = 1;
8122 int idx_number = 3;
8123 int idx_number_2 = 4;
8124 int idx_force = 0;
8125 char *force = NULL;
8126
8127 if (argv_find(argv, argc, "force", &idx_force))
8128 force = argv[idx_force]->arg;
8129
8130 return peer_maximum_prefix_set_vty(
8131 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8132 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8133 }
8134
8135 ALIAS_HIDDEN(
8136 neighbor_maximum_prefix_threshold,
8137 neighbor_maximum_prefix_threshold_hidden_cmd,
8138 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8139 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8140 "Maximum number of prefix accept from this peer\n"
8141 "maximum no. of prefix limit\n"
8142 "Threshold value (%) at which to generate a warning msg\n"
8143 "Force checking all received routes not only accepted\n")
8144
8145 DEFUN (neighbor_maximum_prefix_warning,
8146 neighbor_maximum_prefix_warning_cmd,
8147 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8148 NEIGHBOR_STR
8149 NEIGHBOR_ADDR_STR2
8150 "Maximum number of prefix accept from this peer\n"
8151 "maximum no. of prefix limit\n"
8152 "Only give warning message when limit is exceeded\n"
8153 "Force checking all received routes not only accepted\n")
8154 {
8155 int idx_peer = 1;
8156 int idx_number = 3;
8157 int idx_force = 0;
8158 char *force = NULL;
8159
8160 if (argv_find(argv, argc, "force", &idx_force))
8161 force = argv[idx_force]->arg;
8162
8163 return peer_maximum_prefix_set_vty(
8164 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8165 argv[idx_number]->arg, NULL, 1, NULL, force);
8166 }
8167
8168 ALIAS_HIDDEN(
8169 neighbor_maximum_prefix_warning,
8170 neighbor_maximum_prefix_warning_hidden_cmd,
8171 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8172 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8173 "Maximum number of prefix accept from this peer\n"
8174 "maximum no. of prefix limit\n"
8175 "Only give warning message when limit is exceeded\n"
8176 "Force checking all received routes not only accepted\n")
8177
8178 DEFUN (neighbor_maximum_prefix_threshold_warning,
8179 neighbor_maximum_prefix_threshold_warning_cmd,
8180 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8181 NEIGHBOR_STR
8182 NEIGHBOR_ADDR_STR2
8183 "Maximum number of prefix accept from this peer\n"
8184 "maximum no. of prefix limit\n"
8185 "Threshold value (%) at which to generate a warning msg\n"
8186 "Only give warning message when limit is exceeded\n"
8187 "Force checking all received routes not only accepted\n")
8188 {
8189 int idx_peer = 1;
8190 int idx_number = 3;
8191 int idx_number_2 = 4;
8192 int idx_force = 0;
8193 char *force = NULL;
8194
8195 if (argv_find(argv, argc, "force", &idx_force))
8196 force = argv[idx_force]->arg;
8197
8198 return peer_maximum_prefix_set_vty(
8199 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8200 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8201 }
8202
8203 ALIAS_HIDDEN(
8204 neighbor_maximum_prefix_threshold_warning,
8205 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8206 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8207 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8208 "Maximum number of prefix accept from this peer\n"
8209 "maximum no. of prefix limit\n"
8210 "Threshold value (%) at which to generate a warning msg\n"
8211 "Only give warning message when limit is exceeded\n"
8212 "Force checking all received routes not only accepted\n")
8213
8214 DEFUN (neighbor_maximum_prefix_restart,
8215 neighbor_maximum_prefix_restart_cmd,
8216 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8217 NEIGHBOR_STR
8218 NEIGHBOR_ADDR_STR2
8219 "Maximum number of prefix accept from this peer\n"
8220 "maximum no. of prefix limit\n"
8221 "Restart bgp connection after limit is exceeded\n"
8222 "Restart interval in minutes\n"
8223 "Force checking all received routes not only accepted\n")
8224 {
8225 int idx_peer = 1;
8226 int idx_number = 3;
8227 int idx_number_2 = 5;
8228 int idx_force = 0;
8229 char *force = NULL;
8230
8231 if (argv_find(argv, argc, "force", &idx_force))
8232 force = argv[idx_force]->arg;
8233
8234 return peer_maximum_prefix_set_vty(
8235 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8236 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8237 }
8238
8239 ALIAS_HIDDEN(
8240 neighbor_maximum_prefix_restart,
8241 neighbor_maximum_prefix_restart_hidden_cmd,
8242 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8243 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8244 "Maximum number of prefix accept from this peer\n"
8245 "maximum no. of prefix limit\n"
8246 "Restart bgp connection after limit is exceeded\n"
8247 "Restart interval in minutes\n"
8248 "Force checking all received routes not only accepted\n")
8249
8250 DEFUN (neighbor_maximum_prefix_threshold_restart,
8251 neighbor_maximum_prefix_threshold_restart_cmd,
8252 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8253 NEIGHBOR_STR
8254 NEIGHBOR_ADDR_STR2
8255 "Maximum number of prefixes to accept from this peer\n"
8256 "maximum no. of prefix limit\n"
8257 "Threshold value (%) at which to generate a warning msg\n"
8258 "Restart bgp connection after limit is exceeded\n"
8259 "Restart interval in minutes\n"
8260 "Force checking all received routes not only accepted\n")
8261 {
8262 int idx_peer = 1;
8263 int idx_number = 3;
8264 int idx_number_2 = 4;
8265 int idx_number_3 = 6;
8266 int idx_force = 0;
8267 char *force = NULL;
8268
8269 if (argv_find(argv, argc, "force", &idx_force))
8270 force = argv[idx_force]->arg;
8271
8272 return peer_maximum_prefix_set_vty(
8273 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8274 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8275 argv[idx_number_3]->arg, force);
8276 }
8277
8278 ALIAS_HIDDEN(
8279 neighbor_maximum_prefix_threshold_restart,
8280 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8281 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8282 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8283 "Maximum number of prefixes to accept from this peer\n"
8284 "maximum no. of prefix limit\n"
8285 "Threshold value (%) at which to generate a warning msg\n"
8286 "Restart bgp connection after limit is exceeded\n"
8287 "Restart interval in minutes\n"
8288 "Force checking all received routes not only accepted\n")
8289
8290 DEFUN (no_neighbor_maximum_prefix,
8291 no_neighbor_maximum_prefix_cmd,
8292 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8293 NO_STR
8294 NEIGHBOR_STR
8295 NEIGHBOR_ADDR_STR2
8296 "Maximum number of prefixes to accept from this peer\n"
8297 "maximum no. of prefix limit\n"
8298 "Threshold value (%) at which to generate a warning msg\n"
8299 "Restart bgp connection after limit is exceeded\n"
8300 "Restart interval in minutes\n"
8301 "Only give warning message when limit is exceeded\n"
8302 "Force checking all received routes not only accepted\n")
8303 {
8304 int idx_peer = 2;
8305 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8306 bgp_node_afi(vty),
8307 bgp_node_safi(vty));
8308 }
8309
8310 ALIAS_HIDDEN(
8311 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8312 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8313 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8314 "Maximum number of prefixes to accept from this peer\n"
8315 "maximum no. of prefix limit\n"
8316 "Threshold value (%) at which to generate a warning msg\n"
8317 "Restart bgp connection after limit is exceeded\n"
8318 "Restart interval in minutes\n"
8319 "Only give warning message when limit is exceeded\n"
8320 "Force checking all received routes not only accepted\n")
8321
8322 /* "neighbor soo" */
8323 DEFPY (neighbor_soo,
8324 neighbor_soo_cmd,
8325 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8326 NEIGHBOR_STR
8327 NEIGHBOR_ADDR_STR2
8328 "Set the Site-of-Origin (SoO) extended community\n"
8329 "VPN extended community\n")
8330 {
8331 struct peer *peer;
8332 afi_t afi = bgp_node_afi(vty);
8333 safi_t safi = bgp_node_safi(vty);
8334 struct ecommunity *ecomm_soo;
8335
8336 peer = peer_and_group_lookup_vty(vty, neighbor);
8337 if (!peer)
8338 return CMD_WARNING_CONFIG_FAILED;
8339
8340 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8341 if (!ecomm_soo) {
8342 vty_out(vty, "%% Malformed SoO extended community\n");
8343 return CMD_WARNING;
8344 }
8345 ecommunity_str(ecomm_soo);
8346
8347 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8348 ecommunity_free(&peer->soo[afi][safi]);
8349 peer->soo[afi][safi] = ecomm_soo;
8350 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8351 }
8352
8353 return bgp_vty_return(vty,
8354 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8355 }
8356
8357 DEFPY (no_neighbor_soo,
8358 no_neighbor_soo_cmd,
8359 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8360 NO_STR
8361 NEIGHBOR_STR
8362 NEIGHBOR_ADDR_STR2
8363 "Set the Site-of-Origin (SoO) extended community\n"
8364 "VPN extended community\n")
8365 {
8366 struct peer *peer;
8367 afi_t afi = bgp_node_afi(vty);
8368 safi_t safi = bgp_node_safi(vty);
8369
8370 peer = peer_and_group_lookup_vty(vty, neighbor);
8371 if (!peer)
8372 return CMD_WARNING_CONFIG_FAILED;
8373
8374 ecommunity_free(&peer->soo[afi][safi]);
8375
8376 return bgp_vty_return(
8377 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8378 }
8379
8380 /* "neighbor allowas-in" */
8381 DEFUN (neighbor_allowas_in,
8382 neighbor_allowas_in_cmd,
8383 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8384 NEIGHBOR_STR
8385 NEIGHBOR_ADDR_STR2
8386 "Accept as-path with my AS present in it\n"
8387 "Number of occurrences of AS number\n"
8388 "Only accept my AS in the as-path if the route was originated in my AS\n")
8389 {
8390 int idx_peer = 1;
8391 int idx_number_origin = 3;
8392 int ret;
8393 int origin = 0;
8394 struct peer *peer;
8395 int allow_num = 0;
8396
8397 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8398 if (!peer)
8399 return CMD_WARNING_CONFIG_FAILED;
8400
8401 if (argc <= idx_number_origin)
8402 allow_num = 3;
8403 else {
8404 if (argv[idx_number_origin]->type == WORD_TKN)
8405 origin = 1;
8406 else
8407 allow_num = atoi(argv[idx_number_origin]->arg);
8408 }
8409
8410 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8411 allow_num, origin);
8412
8413 return bgp_vty_return(vty, ret);
8414 }
8415
8416 ALIAS_HIDDEN(
8417 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8418 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8419 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8420 "Accept as-path with my AS present in it\n"
8421 "Number of occurrences of AS number\n"
8422 "Only accept my AS in the as-path if the route was originated in my AS\n")
8423
8424 DEFUN (no_neighbor_allowas_in,
8425 no_neighbor_allowas_in_cmd,
8426 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8427 NO_STR
8428 NEIGHBOR_STR
8429 NEIGHBOR_ADDR_STR2
8430 "allow local ASN appears in aspath attribute\n"
8431 "Number of occurrences of AS number\n"
8432 "Only accept my AS in the as-path if the route was originated in my AS\n")
8433 {
8434 int idx_peer = 2;
8435 int ret;
8436 struct peer *peer;
8437
8438 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8439 if (!peer)
8440 return CMD_WARNING_CONFIG_FAILED;
8441
8442 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8443 bgp_node_safi(vty));
8444
8445 return bgp_vty_return(vty, ret);
8446 }
8447
8448 ALIAS_HIDDEN(
8449 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8450 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8451 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8452 "allow local ASN appears in aspath attribute\n"
8453 "Number of occurrences of AS number\n"
8454 "Only accept my AS in the as-path if the route was originated in my AS\n")
8455
8456 DEFUN (neighbor_ttl_security,
8457 neighbor_ttl_security_cmd,
8458 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8459 NEIGHBOR_STR
8460 NEIGHBOR_ADDR_STR2
8461 "BGP ttl-security parameters\n"
8462 "Specify the maximum number of hops to the BGP peer\n"
8463 "Number of hops to BGP peer\n")
8464 {
8465 int idx_peer = 1;
8466 int idx_number = 4;
8467 struct peer *peer;
8468 int gtsm_hops;
8469
8470 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8471 if (!peer)
8472 return CMD_WARNING_CONFIG_FAILED;
8473
8474 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8475
8476 /*
8477 * If 'neighbor swpX', then this is for directly connected peers,
8478 * we should not accept a ttl-security hops value greater than 1.
8479 */
8480 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8481 vty_out(vty,
8482 "%s is directly connected peer, hops cannot exceed 1\n",
8483 argv[idx_peer]->arg);
8484 return CMD_WARNING_CONFIG_FAILED;
8485 }
8486
8487 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8488 }
8489
8490 DEFUN (no_neighbor_ttl_security,
8491 no_neighbor_ttl_security_cmd,
8492 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8493 NO_STR
8494 NEIGHBOR_STR
8495 NEIGHBOR_ADDR_STR2
8496 "BGP ttl-security parameters\n"
8497 "Specify the maximum number of hops to the BGP peer\n"
8498 "Number of hops to BGP peer\n")
8499 {
8500 int idx_peer = 2;
8501 struct peer *peer;
8502
8503 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8504 if (!peer)
8505 return CMD_WARNING_CONFIG_FAILED;
8506
8507 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8508 }
8509
8510 /* disable-addpath-rx */
8511 DEFUN(neighbor_disable_addpath_rx,
8512 neighbor_disable_addpath_rx_cmd,
8513 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8514 NEIGHBOR_STR
8515 NEIGHBOR_ADDR_STR2
8516 "Do not accept additional paths\n")
8517 {
8518 char *peer_str = argv[1]->arg;
8519 struct peer *peer;
8520 afi_t afi = bgp_node_afi(vty);
8521 safi_t safi = bgp_node_safi(vty);
8522
8523 peer = peer_and_group_lookup_vty(vty, peer_str);
8524 if (!peer)
8525 return CMD_WARNING_CONFIG_FAILED;
8526
8527 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8528 PEER_FLAG_DISABLE_ADDPATH_RX);
8529 }
8530
8531 DEFUN(no_neighbor_disable_addpath_rx,
8532 no_neighbor_disable_addpath_rx_cmd,
8533 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8534 NO_STR
8535 NEIGHBOR_STR
8536 NEIGHBOR_ADDR_STR2
8537 "Do not accept additional paths\n")
8538 {
8539 char *peer_str = argv[2]->arg;
8540 struct peer *peer;
8541 afi_t afi = bgp_node_afi(vty);
8542 safi_t safi = bgp_node_safi(vty);
8543
8544 peer = peer_and_group_lookup_vty(vty, peer_str);
8545 if (!peer)
8546 return CMD_WARNING_CONFIG_FAILED;
8547
8548 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8549 PEER_FLAG_DISABLE_ADDPATH_RX);
8550 }
8551
8552 DEFUN (neighbor_addpath_tx_all_paths,
8553 neighbor_addpath_tx_all_paths_cmd,
8554 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8555 NEIGHBOR_STR
8556 NEIGHBOR_ADDR_STR2
8557 "Use addpath to advertise all paths to a neighbor\n")
8558 {
8559 int idx_peer = 1;
8560 struct peer *peer;
8561
8562 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8563 if (!peer)
8564 return CMD_WARNING_CONFIG_FAILED;
8565
8566 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8567 BGP_ADDPATH_ALL);
8568 return CMD_SUCCESS;
8569 }
8570
8571 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8572 neighbor_addpath_tx_all_paths_hidden_cmd,
8573 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8574 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8575 "Use addpath to advertise all paths to a neighbor\n")
8576
8577 DEFUN (no_neighbor_addpath_tx_all_paths,
8578 no_neighbor_addpath_tx_all_paths_cmd,
8579 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8580 NO_STR
8581 NEIGHBOR_STR
8582 NEIGHBOR_ADDR_STR2
8583 "Use addpath to advertise all paths to a neighbor\n")
8584 {
8585 int idx_peer = 2;
8586 struct peer *peer;
8587
8588 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8589 if (!peer)
8590 return CMD_WARNING_CONFIG_FAILED;
8591
8592 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8593 != BGP_ADDPATH_ALL) {
8594 vty_out(vty,
8595 "%% Peer not currently configured to transmit all paths.");
8596 return CMD_WARNING_CONFIG_FAILED;
8597 }
8598
8599 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8600 BGP_ADDPATH_NONE);
8601
8602 return CMD_SUCCESS;
8603 }
8604
8605 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8606 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8607 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8608 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8609 "Use addpath to advertise all paths to a neighbor\n")
8610
8611 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8612 neighbor_addpath_tx_bestpath_per_as_cmd,
8613 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8614 NEIGHBOR_STR
8615 NEIGHBOR_ADDR_STR2
8616 "Use addpath to advertise the bestpath per each neighboring AS\n")
8617 {
8618 int idx_peer = 1;
8619 struct peer *peer;
8620
8621 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8622 if (!peer)
8623 return CMD_WARNING_CONFIG_FAILED;
8624
8625 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8626 BGP_ADDPATH_BEST_PER_AS);
8627
8628 return CMD_SUCCESS;
8629 }
8630
8631 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8632 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8633 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8634 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8635 "Use addpath to advertise the bestpath per each neighboring AS\n")
8636
8637 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8638 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8639 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8640 NO_STR
8641 NEIGHBOR_STR
8642 NEIGHBOR_ADDR_STR2
8643 "Use addpath to advertise the bestpath per each neighboring AS\n")
8644 {
8645 int idx_peer = 2;
8646 struct peer *peer;
8647
8648 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8649 if (!peer)
8650 return CMD_WARNING_CONFIG_FAILED;
8651
8652 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8653 != BGP_ADDPATH_BEST_PER_AS) {
8654 vty_out(vty,
8655 "%% Peer not currently configured to transmit all best path per as.");
8656 return CMD_WARNING_CONFIG_FAILED;
8657 }
8658
8659 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8660 BGP_ADDPATH_NONE);
8661
8662 return CMD_SUCCESS;
8663 }
8664
8665 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8666 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8667 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8669 "Use addpath to advertise the bestpath per each neighboring AS\n")
8670
8671 DEFPY(
8672 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8673 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8674 NEIGHBOR_STR
8675 NEIGHBOR_ADDR_STR2
8676 "Detect AS loops before sending to neighbor\n")
8677 {
8678 struct peer *peer;
8679
8680 peer = peer_and_group_lookup_vty(vty, neighbor);
8681 if (!peer)
8682 return CMD_WARNING_CONFIG_FAILED;
8683
8684 peer->as_path_loop_detection = true;
8685
8686 return CMD_SUCCESS;
8687 }
8688
8689 DEFPY(
8690 no_neighbor_aspath_loop_detection,
8691 no_neighbor_aspath_loop_detection_cmd,
8692 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8693 NO_STR
8694 NEIGHBOR_STR
8695 NEIGHBOR_ADDR_STR2
8696 "Detect AS loops before sending to neighbor\n")
8697 {
8698 struct peer *peer;
8699
8700 peer = peer_and_group_lookup_vty(vty, neighbor);
8701 if (!peer)
8702 return CMD_WARNING_CONFIG_FAILED;
8703
8704 peer->as_path_loop_detection = false;
8705
8706 return CMD_SUCCESS;
8707 }
8708
8709 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8710 struct ecommunity **list, bool is_rt6)
8711 {
8712 struct ecommunity *ecom = NULL;
8713 struct ecommunity *ecomadd;
8714
8715 for (; argc; --argc, ++argv) {
8716 if (is_rt6)
8717 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8718 ECOMMUNITY_ROUTE_TARGET,
8719 0);
8720 else
8721 ecomadd = ecommunity_str2com(argv[0]->arg,
8722 ECOMMUNITY_ROUTE_TARGET,
8723 0);
8724 if (!ecomadd) {
8725 vty_out(vty, "Malformed community-list value\n");
8726 if (ecom)
8727 ecommunity_free(&ecom);
8728 return CMD_WARNING_CONFIG_FAILED;
8729 }
8730
8731 if (ecom) {
8732 ecommunity_merge(ecom, ecomadd);
8733 ecommunity_free(&ecomadd);
8734 } else {
8735 ecom = ecomadd;
8736 }
8737 }
8738
8739 if (*list) {
8740 ecommunity_free(&*list);
8741 }
8742 *list = ecom;
8743
8744 return CMD_SUCCESS;
8745 }
8746
8747 /*
8748 * v2vimport is true if we are handling a `import vrf ...` command
8749 */
8750 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8751 {
8752 afi_t afi;
8753
8754 switch (vty->node) {
8755 case BGP_IPV4_NODE:
8756 afi = AFI_IP;
8757 break;
8758 case BGP_IPV6_NODE:
8759 afi = AFI_IP6;
8760 break;
8761 default:
8762 vty_out(vty,
8763 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8764 return AFI_MAX;
8765 }
8766
8767 if (!v2vimport) {
8768 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8769 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8770 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8771 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8772 vty_out(vty,
8773 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8774 return AFI_MAX;
8775 }
8776 } else {
8777 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8778 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8779 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8780 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8781 vty_out(vty,
8782 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8783 return AFI_MAX;
8784 }
8785 }
8786 return afi;
8787 }
8788
8789 DEFPY (af_rd_vpn_export,
8790 af_rd_vpn_export_cmd,
8791 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8792 NO_STR
8793 "Specify route distinguisher\n"
8794 "Between current address-family and vpn\n"
8795 "For routes leaked from current address-family to vpn\n"
8796 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8797 {
8798 VTY_DECLVAR_CONTEXT(bgp, bgp);
8799 struct prefix_rd prd;
8800 int ret;
8801 afi_t afi;
8802 int idx = 0;
8803 bool yes = true;
8804
8805 if (argv_find(argv, argc, "no", &idx))
8806 yes = false;
8807
8808 if (yes) {
8809 ret = str2prefix_rd(rd_str, &prd);
8810 if (!ret) {
8811 vty_out(vty, "%% Malformed rd\n");
8812 return CMD_WARNING_CONFIG_FAILED;
8813 }
8814 }
8815
8816 afi = vpn_policy_getafi(vty, bgp, false);
8817 if (afi == AFI_MAX)
8818 return CMD_WARNING_CONFIG_FAILED;
8819
8820 /*
8821 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8822 */
8823 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8824 bgp_get_default(), bgp);
8825
8826 if (yes) {
8827 bgp->vpn_policy[afi].tovpn_rd = prd;
8828 SET_FLAG(bgp->vpn_policy[afi].flags,
8829 BGP_VPN_POLICY_TOVPN_RD_SET);
8830 } else {
8831 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8832 BGP_VPN_POLICY_TOVPN_RD_SET);
8833 }
8834
8835 /* post-change: re-export vpn routes */
8836 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8837 bgp_get_default(), bgp);
8838
8839 return CMD_SUCCESS;
8840 }
8841
8842 ALIAS (af_rd_vpn_export,
8843 af_no_rd_vpn_export_cmd,
8844 "no rd vpn export",
8845 NO_STR
8846 "Specify route distinguisher\n"
8847 "Between current address-family and vpn\n"
8848 "For routes leaked from current address-family to vpn\n")
8849
8850 DEFPY (af_label_vpn_export,
8851 af_label_vpn_export_cmd,
8852 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8853 NO_STR
8854 "label value for VRF\n"
8855 "Between current address-family and vpn\n"
8856 "For routes leaked from current address-family to vpn\n"
8857 "Label Value <0-1048575>\n"
8858 "Automatically assign a label\n")
8859 {
8860 VTY_DECLVAR_CONTEXT(bgp, bgp);
8861 mpls_label_t label = MPLS_LABEL_NONE;
8862 afi_t afi;
8863 int idx = 0;
8864 bool yes = true;
8865
8866 if (argv_find(argv, argc, "no", &idx))
8867 yes = false;
8868
8869 /* If "no ...", squash trailing parameter */
8870 if (!yes)
8871 label_auto = NULL;
8872
8873 if (yes) {
8874 if (!label_auto)
8875 label = label_val; /* parser should force unsigned */
8876 }
8877
8878 afi = vpn_policy_getafi(vty, bgp, false);
8879 if (afi == AFI_MAX)
8880 return CMD_WARNING_CONFIG_FAILED;
8881
8882
8883 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8884 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8885 /* no change */
8886 return CMD_SUCCESS;
8887
8888 /*
8889 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8890 */
8891 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8892 bgp_get_default(), bgp);
8893
8894 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8895 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8896
8897 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8898
8899 /*
8900 * label has previously been automatically
8901 * assigned by labelpool: release it
8902 *
8903 * NB if tovpn_label == MPLS_LABEL_NONE it
8904 * means the automatic assignment is in flight
8905 * and therefore the labelpool callback must
8906 * detect that the auto label is not needed.
8907 */
8908
8909 bgp_lp_release(LP_TYPE_VRF,
8910 &bgp->vpn_policy[afi],
8911 bgp->vpn_policy[afi].tovpn_label);
8912 }
8913 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8914 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8915 }
8916
8917 bgp->vpn_policy[afi].tovpn_label = label;
8918 if (label_auto) {
8919 SET_FLAG(bgp->vpn_policy[afi].flags,
8920 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8921 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8922 vpn_leak_label_callback);
8923 }
8924
8925 /* post-change: re-export vpn routes */
8926 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8927 bgp_get_default(), bgp);
8928
8929 hook_call(bgp_snmp_update_last_changed, bgp);
8930 return CMD_SUCCESS;
8931 }
8932
8933 DEFPY (af_sid_vpn_export,
8934 af_sid_vpn_export_cmd,
8935 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8936 NO_STR
8937 "sid value for VRF\n"
8938 "Between current address-family and vpn\n"
8939 "For routes leaked from current address-family to vpn\n"
8940 "Sid allocation index\n"
8941 "Automatically assign a label\n")
8942 {
8943 VTY_DECLVAR_CONTEXT(bgp, bgp);
8944 afi_t afi;
8945 int debug = 0;
8946 int idx = 0;
8947 bool yes = true;
8948
8949 if (argv_find(argv, argc, "no", &idx))
8950 yes = false;
8951 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8952 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8953
8954 afi = vpn_policy_getafi(vty, bgp, false);
8955 if (afi == AFI_MAX)
8956 return CMD_WARNING_CONFIG_FAILED;
8957
8958 if (!yes) {
8959 /* implement me */
8960 vty_out(vty, "It's not implemented\n");
8961 return CMD_WARNING_CONFIG_FAILED;
8962 }
8963
8964 /* skip when it's already configured */
8965 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8966 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8967 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8968 return CMD_SUCCESS;
8969
8970 /*
8971 * mode change between sid_idx and sid_auto isn't supported.
8972 * user must negate sid vpn export when they want to change the mode
8973 */
8974 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8975 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8976 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8977 vty_out(vty, "it's already configured as %s.\n",
8978 sid_auto ? "auto-mode" : "idx-mode");
8979 return CMD_WARNING_CONFIG_FAILED;
8980 }
8981
8982 /* pre-change */
8983 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8984 bgp_get_default(), bgp);
8985
8986 if (sid_auto) {
8987 /* SID allocation auto-mode */
8988 if (debug)
8989 zlog_debug("%s: auto sid alloc.", __func__);
8990 SET_FLAG(bgp->vpn_policy[afi].flags,
8991 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8992 } else {
8993 /* SID allocation index-mode */
8994 if (debug)
8995 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8996 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8997 }
8998
8999 /* post-change */
9000 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9001 bgp_get_default(), bgp);
9002 return CMD_SUCCESS;
9003 }
9004
9005 ALIAS (af_label_vpn_export,
9006 af_no_label_vpn_export_cmd,
9007 "no label vpn export",
9008 NO_STR
9009 "label value for VRF\n"
9010 "Between current address-family and vpn\n"
9011 "For routes leaked from current address-family to vpn\n")
9012
9013 DEFPY (af_nexthop_vpn_export,
9014 af_nexthop_vpn_export_cmd,
9015 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9016 NO_STR
9017 "Specify next hop to use for VRF advertised prefixes\n"
9018 "Between current address-family and vpn\n"
9019 "For routes leaked from current address-family to vpn\n"
9020 "IPv4 prefix\n"
9021 "IPv6 prefix\n")
9022 {
9023 VTY_DECLVAR_CONTEXT(bgp, bgp);
9024 afi_t afi;
9025 struct prefix p;
9026
9027 if (!no) {
9028 if (!nexthop_su) {
9029 vty_out(vty, "%% Nexthop required\n");
9030 return CMD_WARNING_CONFIG_FAILED;
9031 }
9032 if (!sockunion2hostprefix(nexthop_su, &p))
9033 return CMD_WARNING_CONFIG_FAILED;
9034 }
9035
9036 afi = vpn_policy_getafi(vty, bgp, false);
9037 if (afi == AFI_MAX)
9038 return CMD_WARNING_CONFIG_FAILED;
9039
9040 /*
9041 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9042 */
9043 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9044 bgp_get_default(), bgp);
9045
9046 if (!no) {
9047 bgp->vpn_policy[afi].tovpn_nexthop = p;
9048 SET_FLAG(bgp->vpn_policy[afi].flags,
9049 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9050 } else {
9051 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9052 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9053 }
9054
9055 /* post-change: re-export vpn routes */
9056 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9057 bgp_get_default(), bgp);
9058
9059 return CMD_SUCCESS;
9060 }
9061
9062 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9063 {
9064 if (!strcmp(dstr, "import")) {
9065 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9066 } else if (!strcmp(dstr, "export")) {
9067 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9068 } else if (!strcmp(dstr, "both")) {
9069 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9070 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9071 } else {
9072 vty_out(vty, "%% direction parse error\n");
9073 return CMD_WARNING_CONFIG_FAILED;
9074 }
9075 return CMD_SUCCESS;
9076 }
9077
9078 DEFPY (af_rt_vpn_imexport,
9079 af_rt_vpn_imexport_cmd,
9080 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9081 NO_STR
9082 "Specify route target list\n"
9083 "Specify route target list\n"
9084 "Between current address-family and vpn\n"
9085 "For routes leaked from vpn to current address-family: match any\n"
9086 "For routes leaked from current address-family to vpn: set\n"
9087 "both import: match any and export: set\n"
9088 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9089 {
9090 VTY_DECLVAR_CONTEXT(bgp, bgp);
9091 int ret;
9092 struct ecommunity *ecom = NULL;
9093 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9094 enum vpn_policy_direction dir;
9095 afi_t afi;
9096 int idx = 0;
9097 bool yes = true;
9098
9099 if (argv_find(argv, argc, "no", &idx))
9100 yes = false;
9101
9102 afi = vpn_policy_getafi(vty, bgp, false);
9103 if (afi == AFI_MAX)
9104 return CMD_WARNING_CONFIG_FAILED;
9105
9106 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9107 if (ret != CMD_SUCCESS)
9108 return ret;
9109
9110 if (yes) {
9111 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9112 vty_out(vty, "%% Missing RTLIST\n");
9113 return CMD_WARNING_CONFIG_FAILED;
9114 }
9115 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9116 if (ret != CMD_SUCCESS) {
9117 return ret;
9118 }
9119 }
9120
9121 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9122 if (!dodir[dir])
9123 continue;
9124
9125 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9126
9127 if (yes) {
9128 if (bgp->vpn_policy[afi].rtlist[dir])
9129 ecommunity_free(
9130 &bgp->vpn_policy[afi].rtlist[dir]);
9131 bgp->vpn_policy[afi].rtlist[dir] =
9132 ecommunity_dup(ecom);
9133 } else {
9134 if (bgp->vpn_policy[afi].rtlist[dir])
9135 ecommunity_free(
9136 &bgp->vpn_policy[afi].rtlist[dir]);
9137 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9138 }
9139
9140 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9141 }
9142
9143 if (ecom)
9144 ecommunity_free(&ecom);
9145
9146 return CMD_SUCCESS;
9147 }
9148
9149 ALIAS (af_rt_vpn_imexport,
9150 af_no_rt_vpn_imexport_cmd,
9151 "no <rt|route-target> vpn <import|export|both>$direction_str",
9152 NO_STR
9153 "Specify route target list\n"
9154 "Specify route target list\n"
9155 "Between current address-family and vpn\n"
9156 "For routes leaked from vpn to current address-family\n"
9157 "For routes leaked from current address-family to vpn\n"
9158 "both import and export\n")
9159
9160 DEFPY (af_route_map_vpn_imexport,
9161 af_route_map_vpn_imexport_cmd,
9162 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9163 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9164 NO_STR
9165 "Specify route map\n"
9166 "Between current address-family and vpn\n"
9167 "For routes leaked from vpn to current address-family\n"
9168 "For routes leaked from current address-family to vpn\n"
9169 "name of route-map\n")
9170 {
9171 VTY_DECLVAR_CONTEXT(bgp, bgp);
9172 int ret;
9173 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9174 enum vpn_policy_direction dir;
9175 afi_t afi;
9176 int idx = 0;
9177 bool yes = true;
9178
9179 if (argv_find(argv, argc, "no", &idx))
9180 yes = false;
9181
9182 afi = vpn_policy_getafi(vty, bgp, false);
9183 if (afi == AFI_MAX)
9184 return CMD_WARNING_CONFIG_FAILED;
9185
9186 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9187 if (ret != CMD_SUCCESS)
9188 return ret;
9189
9190 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9191 if (!dodir[dir])
9192 continue;
9193
9194 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9195
9196 if (yes) {
9197 if (bgp->vpn_policy[afi].rmap_name[dir])
9198 XFREE(MTYPE_ROUTE_MAP_NAME,
9199 bgp->vpn_policy[afi].rmap_name[dir]);
9200 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9201 MTYPE_ROUTE_MAP_NAME, rmap_str);
9202 bgp->vpn_policy[afi].rmap[dir] =
9203 route_map_lookup_warn_noexist(vty, rmap_str);
9204 if (!bgp->vpn_policy[afi].rmap[dir])
9205 return CMD_SUCCESS;
9206 } else {
9207 if (bgp->vpn_policy[afi].rmap_name[dir])
9208 XFREE(MTYPE_ROUTE_MAP_NAME,
9209 bgp->vpn_policy[afi].rmap_name[dir]);
9210 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9211 bgp->vpn_policy[afi].rmap[dir] = NULL;
9212 }
9213
9214 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9215 }
9216
9217 return CMD_SUCCESS;
9218 }
9219
9220 ALIAS (af_route_map_vpn_imexport,
9221 af_no_route_map_vpn_imexport_cmd,
9222 "no route-map vpn <import|export>$direction_str",
9223 NO_STR
9224 "Specify route map\n"
9225 "Between current address-family and vpn\n"
9226 "For routes leaked from vpn to current address-family\n"
9227 "For routes leaked from current address-family to vpn\n")
9228
9229 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9230 "import vrf route-map RMAP$rmap_str",
9231 "Import routes from another VRF\n"
9232 "Vrf routes being filtered\n"
9233 "Specify route map\n"
9234 "name of route-map\n")
9235 {
9236 VTY_DECLVAR_CONTEXT(bgp, bgp);
9237 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9238 afi_t afi;
9239 struct bgp *bgp_default;
9240
9241 afi = vpn_policy_getafi(vty, bgp, true);
9242 if (afi == AFI_MAX)
9243 return CMD_WARNING_CONFIG_FAILED;
9244
9245 bgp_default = bgp_get_default();
9246 if (!bgp_default) {
9247 int32_t ret;
9248 as_t as = bgp->as;
9249
9250 /* Auto-create assuming the same AS */
9251 ret = bgp_get_vty(&bgp_default, &as, NULL,
9252 BGP_INSTANCE_TYPE_DEFAULT);
9253
9254 if (ret) {
9255 vty_out(vty,
9256 "VRF default is not configured as a bgp instance\n");
9257 return CMD_WARNING;
9258 }
9259 }
9260
9261 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9262
9263 if (bgp->vpn_policy[afi].rmap_name[dir])
9264 XFREE(MTYPE_ROUTE_MAP_NAME,
9265 bgp->vpn_policy[afi].rmap_name[dir]);
9266 bgp->vpn_policy[afi].rmap_name[dir] =
9267 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9268 bgp->vpn_policy[afi].rmap[dir] =
9269 route_map_lookup_warn_noexist(vty, rmap_str);
9270 if (!bgp->vpn_policy[afi].rmap[dir])
9271 return CMD_SUCCESS;
9272
9273 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9274 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9275
9276 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9277
9278 return CMD_SUCCESS;
9279 }
9280
9281 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9282 "no import vrf route-map [RMAP$rmap_str]",
9283 NO_STR
9284 "Import routes from another VRF\n"
9285 "Vrf routes being filtered\n"
9286 "Specify route map\n"
9287 "name of route-map\n")
9288 {
9289 VTY_DECLVAR_CONTEXT(bgp, bgp);
9290 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9291 afi_t afi;
9292
9293 afi = vpn_policy_getafi(vty, bgp, true);
9294 if (afi == AFI_MAX)
9295 return CMD_WARNING_CONFIG_FAILED;
9296
9297 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9298
9299 if (bgp->vpn_policy[afi].rmap_name[dir])
9300 XFREE(MTYPE_ROUTE_MAP_NAME,
9301 bgp->vpn_policy[afi].rmap_name[dir]);
9302 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9303 bgp->vpn_policy[afi].rmap[dir] = NULL;
9304
9305 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9306 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9307 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9308
9309 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9310
9311 return CMD_SUCCESS;
9312 }
9313
9314 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9315 "[no] import vrf VIEWVRFNAME$import_name",
9316 NO_STR
9317 "Import routes from another VRF\n"
9318 "VRF to import from\n"
9319 "The name of the VRF\n")
9320 {
9321 VTY_DECLVAR_CONTEXT(bgp, bgp);
9322 struct listnode *node;
9323 struct bgp *vrf_bgp, *bgp_default;
9324 int32_t ret = 0;
9325 as_t as = bgp->as;
9326 bool remove = false;
9327 int32_t idx = 0;
9328 char *vname;
9329 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9330 safi_t safi;
9331 afi_t afi;
9332
9333 if (import_name == NULL) {
9334 vty_out(vty, "%% Missing import name\n");
9335 return CMD_WARNING;
9336 }
9337
9338 if (strcmp(import_name, "route-map") == 0) {
9339 vty_out(vty, "%% Must include route-map name\n");
9340 return CMD_WARNING;
9341 }
9342
9343 if (argv_find(argv, argc, "no", &idx))
9344 remove = true;
9345
9346 afi = vpn_policy_getafi(vty, bgp, true);
9347 if (afi == AFI_MAX)
9348 return CMD_WARNING_CONFIG_FAILED;
9349
9350 safi = bgp_node_safi(vty);
9351
9352 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9353 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9354 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9355 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9356 remove ? "unimport" : "import", import_name);
9357 return CMD_WARNING;
9358 }
9359
9360 bgp_default = bgp_get_default();
9361 if (!bgp_default) {
9362 /* Auto-create assuming the same AS */
9363 ret = bgp_get_vty(&bgp_default, &as, NULL,
9364 BGP_INSTANCE_TYPE_DEFAULT);
9365
9366 if (ret) {
9367 vty_out(vty,
9368 "VRF default is not configured as a bgp instance\n");
9369 return CMD_WARNING;
9370 }
9371 }
9372
9373 vrf_bgp = bgp_lookup_by_name(import_name);
9374 if (!vrf_bgp) {
9375 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9376 vrf_bgp = bgp_default;
9377 else
9378 /* Auto-create assuming the same AS */
9379 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9380
9381 if (ret) {
9382 vty_out(vty,
9383 "VRF %s is not configured as a bgp instance\n",
9384 import_name);
9385 return CMD_WARNING;
9386 }
9387 }
9388
9389 if (remove) {
9390 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9391 } else {
9392 /* Already importing from "import_vrf"? */
9393 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9394 vname)) {
9395 if (strcmp(vname, import_name) == 0)
9396 return CMD_WARNING;
9397 }
9398
9399 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9400 }
9401
9402 return CMD_SUCCESS;
9403 }
9404
9405 /* This command is valid only in a bgp vrf instance or the default instance */
9406 DEFPY (bgp_imexport_vpn,
9407 bgp_imexport_vpn_cmd,
9408 "[no] <import|export>$direction_str vpn",
9409 NO_STR
9410 "Import routes to this address-family\n"
9411 "Export routes from this address-family\n"
9412 "to/from default instance VPN RIB\n")
9413 {
9414 VTY_DECLVAR_CONTEXT(bgp, bgp);
9415 int previous_state;
9416 afi_t afi;
9417 safi_t safi;
9418 int idx = 0;
9419 bool yes = true;
9420 int flag;
9421 enum vpn_policy_direction dir;
9422
9423 if (argv_find(argv, argc, "no", &idx))
9424 yes = false;
9425
9426 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9427 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9428
9429 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9430 return CMD_WARNING_CONFIG_FAILED;
9431 }
9432
9433 afi = bgp_node_afi(vty);
9434 safi = bgp_node_safi(vty);
9435 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9436 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9437 return CMD_WARNING_CONFIG_FAILED;
9438 }
9439
9440 if (!strcmp(direction_str, "import")) {
9441 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9442 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9443 } else if (!strcmp(direction_str, "export")) {
9444 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9445 dir = BGP_VPN_POLICY_DIR_TOVPN;
9446 } else {
9447 vty_out(vty, "%% unknown direction %s\n", direction_str);
9448 return CMD_WARNING_CONFIG_FAILED;
9449 }
9450
9451 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9452
9453 if (yes) {
9454 SET_FLAG(bgp->af_flags[afi][safi], flag);
9455 if (!previous_state) {
9456 /* trigger export current vrf */
9457 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9458 }
9459 } else {
9460 if (previous_state) {
9461 /* trigger un-export current vrf */
9462 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9463 }
9464 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9465 }
9466
9467 hook_call(bgp_snmp_init_stats, bgp);
9468
9469 return CMD_SUCCESS;
9470 }
9471
9472 DEFPY (af_routetarget_import,
9473 af_routetarget_import_cmd,
9474 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9475 NO_STR
9476 "Specify route target list\n"
9477 "Specify route target list\n"
9478 "Specify route target list\n"
9479 "Specify route target list\n"
9480 "Flow-spec redirect type route target\n"
9481 "Import routes to this address-family\n"
9482 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9483 {
9484 VTY_DECLVAR_CONTEXT(bgp, bgp);
9485 int ret;
9486 struct ecommunity *ecom = NULL;
9487 afi_t afi;
9488 int idx = 0, idx_unused = 0;
9489 bool yes = true;
9490 bool rt6 = false;
9491
9492 if (argv_find(argv, argc, "no", &idx))
9493 yes = false;
9494
9495 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9496 argv_find(argv, argc, "route-target6", &idx_unused))
9497 rt6 = true;
9498
9499 afi = vpn_policy_getafi(vty, bgp, false);
9500 if (afi == AFI_MAX)
9501 return CMD_WARNING_CONFIG_FAILED;
9502
9503 if (rt6 && afi != AFI_IP6)
9504 return CMD_WARNING_CONFIG_FAILED;
9505
9506 if (yes) {
9507 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9508 vty_out(vty, "%% Missing RTLIST\n");
9509 return CMD_WARNING_CONFIG_FAILED;
9510 }
9511 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9512 if (ret != CMD_SUCCESS)
9513 return ret;
9514 }
9515
9516 if (yes) {
9517 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9518 ecommunity_free(&bgp->vpn_policy[afi]
9519 .import_redirect_rtlist);
9520 bgp->vpn_policy[afi].import_redirect_rtlist =
9521 ecommunity_dup(ecom);
9522 } else {
9523 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9524 ecommunity_free(&bgp->vpn_policy[afi]
9525 .import_redirect_rtlist);
9526 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9527 }
9528
9529 if (ecom)
9530 ecommunity_free(&ecom);
9531
9532 return CMD_SUCCESS;
9533 }
9534
9535 DEFUN_NOSH (address_family_ipv4_safi,
9536 address_family_ipv4_safi_cmd,
9537 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9538 "Enter Address Family command mode\n"
9539 BGP_AF_STR
9540 BGP_SAFI_WITH_LABEL_HELP_STR)
9541 {
9542
9543 if (argc == 3) {
9544 VTY_DECLVAR_CONTEXT(bgp, bgp);
9545 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9546 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9547 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9548 && safi != SAFI_EVPN) {
9549 vty_out(vty,
9550 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9551 return CMD_WARNING_CONFIG_FAILED;
9552 }
9553 vty->node = bgp_node_type(AFI_IP, safi);
9554 } else
9555 vty->node = BGP_IPV4_NODE;
9556
9557 return CMD_SUCCESS;
9558 }
9559
9560 DEFUN_NOSH (address_family_ipv6_safi,
9561 address_family_ipv6_safi_cmd,
9562 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9563 "Enter Address Family command mode\n"
9564 BGP_AF_STR
9565 BGP_SAFI_WITH_LABEL_HELP_STR)
9566 {
9567 if (argc == 3) {
9568 VTY_DECLVAR_CONTEXT(bgp, bgp);
9569 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9570 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9571 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9572 && safi != SAFI_EVPN) {
9573 vty_out(vty,
9574 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9575 return CMD_WARNING_CONFIG_FAILED;
9576 }
9577 vty->node = bgp_node_type(AFI_IP6, safi);
9578 } else
9579 vty->node = BGP_IPV6_NODE;
9580
9581 return CMD_SUCCESS;
9582 }
9583
9584 #ifdef KEEP_OLD_VPN_COMMANDS
9585 DEFUN_NOSH (address_family_vpnv4,
9586 address_family_vpnv4_cmd,
9587 "address-family vpnv4 [unicast]",
9588 "Enter Address Family command mode\n"
9589 BGP_AF_STR
9590 BGP_AF_MODIFIER_STR)
9591 {
9592 vty->node = BGP_VPNV4_NODE;
9593 return CMD_SUCCESS;
9594 }
9595
9596 DEFUN_NOSH (address_family_vpnv6,
9597 address_family_vpnv6_cmd,
9598 "address-family vpnv6 [unicast]",
9599 "Enter Address Family command mode\n"
9600 BGP_AF_STR
9601 BGP_AF_MODIFIER_STR)
9602 {
9603 vty->node = BGP_VPNV6_NODE;
9604 return CMD_SUCCESS;
9605 }
9606 #endif /* KEEP_OLD_VPN_COMMANDS */
9607
9608 DEFUN_NOSH (address_family_evpn,
9609 address_family_evpn_cmd,
9610 "address-family l2vpn evpn",
9611 "Enter Address Family command mode\n"
9612 BGP_AF_STR
9613 BGP_AF_MODIFIER_STR)
9614 {
9615 VTY_DECLVAR_CONTEXT(bgp, bgp);
9616 vty->node = BGP_EVPN_NODE;
9617 return CMD_SUCCESS;
9618 }
9619
9620 DEFUN_NOSH (bgp_segment_routing_srv6,
9621 bgp_segment_routing_srv6_cmd,
9622 "segment-routing srv6",
9623 "Segment-Routing configuration\n"
9624 "Segment-Routing SRv6 configuration\n")
9625 {
9626 VTY_DECLVAR_CONTEXT(bgp, bgp);
9627 bgp->srv6_enabled = true;
9628 vty->node = BGP_SRV6_NODE;
9629 return CMD_SUCCESS;
9630 }
9631
9632 DEFUN (no_bgp_segment_routing_srv6,
9633 no_bgp_segment_routing_srv6_cmd,
9634 "no segment-routing srv6",
9635 NO_STR
9636 "Segment-Routing configuration\n"
9637 "Segment-Routing SRv6 configuration\n")
9638 {
9639 VTY_DECLVAR_CONTEXT(bgp, bgp);
9640
9641 if (strlen(bgp->srv6_locator_name) > 0)
9642 if (bgp_srv6_locator_unset(bgp) < 0)
9643 return CMD_WARNING_CONFIG_FAILED;
9644
9645 bgp->srv6_enabled = false;
9646 return CMD_SUCCESS;
9647 }
9648
9649 DEFPY (bgp_srv6_locator,
9650 bgp_srv6_locator_cmd,
9651 "locator NAME$name",
9652 "Specify SRv6 locator\n"
9653 "Specify SRv6 locator\n")
9654 {
9655 VTY_DECLVAR_CONTEXT(bgp, bgp);
9656 int ret;
9657
9658 if (strlen(bgp->srv6_locator_name) > 0
9659 && strcmp(name, bgp->srv6_locator_name) != 0) {
9660 vty_out(vty, "srv6 locator is already configured\n");
9661 return CMD_WARNING_CONFIG_FAILED;
9662 }
9663
9664 snprintf(bgp->srv6_locator_name,
9665 sizeof(bgp->srv6_locator_name), "%s", name);
9666
9667 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9668 if (ret < 0)
9669 return CMD_WARNING_CONFIG_FAILED;
9670
9671 return CMD_SUCCESS;
9672 }
9673
9674 DEFPY (no_bgp_srv6_locator,
9675 no_bgp_srv6_locator_cmd,
9676 "no locator NAME$name",
9677 NO_STR
9678 "Specify SRv6 locator\n"
9679 "Specify SRv6 locator\n")
9680 {
9681 VTY_DECLVAR_CONTEXT(bgp, bgp);
9682
9683 /* when locator isn't configured, do nothing */
9684 if (strlen(bgp->srv6_locator_name) < 1)
9685 return CMD_SUCCESS;
9686
9687 /* name validation */
9688 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9689 vty_out(vty, "%% No srv6 locator is configured\n");
9690 return CMD_WARNING_CONFIG_FAILED;
9691 }
9692
9693 /* unset locator */
9694 if (bgp_srv6_locator_unset(bgp) < 0)
9695 return CMD_WARNING_CONFIG_FAILED;
9696
9697 return CMD_SUCCESS;
9698 }
9699
9700 DEFPY (show_bgp_srv6,
9701 show_bgp_srv6_cmd,
9702 "show bgp segment-routing srv6",
9703 SHOW_STR
9704 BGP_STR
9705 "BGP Segment Routing\n"
9706 "BGP Segment Routing SRv6\n")
9707 {
9708 struct bgp *bgp;
9709 struct listnode *node;
9710 struct srv6_locator_chunk *chunk;
9711 struct bgp_srv6_function *func;
9712 char buf[256];
9713
9714 bgp = bgp_get_default();
9715 if (!bgp)
9716 return CMD_SUCCESS;
9717
9718 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9719 vty_out(vty, "locator_chunks:\n");
9720 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk))
9721 vty_out(vty, "- %pFX\n", &chunk->prefix);
9722
9723 vty_out(vty, "functions:\n");
9724 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9725 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9726 vty_out(vty, "- sid: %s\n", buf);
9727 vty_out(vty, " locator: %s\n", func->locator_name);
9728 }
9729
9730 vty_out(vty, "bgps:\n");
9731 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9732 vty_out(vty, "- name: %s\n",
9733 bgp->name ? bgp->name : "default");
9734
9735 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9736 bgp->vpn_policy[AFI_IP].tovpn_sid);
9737 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9738 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9739 }
9740
9741 return CMD_SUCCESS;
9742 }
9743
9744 DEFUN_NOSH (exit_address_family,
9745 exit_address_family_cmd,
9746 "exit-address-family",
9747 "Exit from Address Family configuration mode\n")
9748 {
9749 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9750 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9751 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9752 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9753 || vty->node == BGP_EVPN_NODE
9754 || vty->node == BGP_FLOWSPECV4_NODE
9755 || vty->node == BGP_FLOWSPECV6_NODE)
9756 vty->node = BGP_NODE;
9757 return CMD_SUCCESS;
9758 }
9759
9760 /* Recalculate bestpath and re-advertise a prefix */
9761 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9762 const char *ip_str, afi_t afi, safi_t safi,
9763 struct prefix_rd *prd)
9764 {
9765 int ret;
9766 struct prefix match;
9767 struct bgp_dest *dest;
9768 struct bgp_dest *rm;
9769 struct bgp *bgp;
9770 struct bgp_table *table;
9771 struct bgp_table *rib;
9772
9773 /* BGP structure lookup. */
9774 if (view_name) {
9775 bgp = bgp_lookup_by_name(view_name);
9776 if (bgp == NULL) {
9777 vty_out(vty, "%% Can't find BGP instance %s\n",
9778 view_name);
9779 return CMD_WARNING;
9780 }
9781 } else {
9782 bgp = bgp_get_default();
9783 if (bgp == NULL) {
9784 vty_out(vty, "%% No BGP process is configured\n");
9785 return CMD_WARNING;
9786 }
9787 }
9788
9789 /* Check IP address argument. */
9790 ret = str2prefix(ip_str, &match);
9791 if (!ret) {
9792 vty_out(vty, "%% address is malformed\n");
9793 return CMD_WARNING;
9794 }
9795
9796 match.family = afi2family(afi);
9797 rib = bgp->rib[afi][safi];
9798
9799 if (safi == SAFI_MPLS_VPN) {
9800 for (dest = bgp_table_top(rib); dest;
9801 dest = bgp_route_next(dest)) {
9802 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9803
9804 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9805 continue;
9806
9807 table = bgp_dest_get_bgp_table_info(dest);
9808 if (table == NULL)
9809 continue;
9810
9811 rm = bgp_node_match(table, &match);
9812 if (rm != NULL) {
9813 const struct prefix *rm_p =
9814 bgp_dest_get_prefix(rm);
9815
9816 if (rm_p->prefixlen == match.prefixlen) {
9817 SET_FLAG(rm->flags,
9818 BGP_NODE_USER_CLEAR);
9819 bgp_process(bgp, rm, afi, safi);
9820 }
9821 bgp_dest_unlock_node(rm);
9822 }
9823 }
9824 } else {
9825 dest = bgp_node_match(rib, &match);
9826 if (dest != NULL) {
9827 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9828
9829 if (dest_p->prefixlen == match.prefixlen) {
9830 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9831 bgp_process(bgp, dest, afi, safi);
9832 }
9833 bgp_dest_unlock_node(dest);
9834 }
9835 }
9836
9837 return CMD_SUCCESS;
9838 }
9839
9840 /* one clear bgp command to rule them all */
9841 DEFUN (clear_ip_bgp_all,
9842 clear_ip_bgp_all_cmd,
9843 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
9844 CLEAR_STR
9845 IP_STR
9846 BGP_STR
9847 BGP_INSTANCE_HELP_STR
9848 BGP_AFI_HELP_STR
9849 BGP_AF_STR
9850 BGP_SAFI_WITH_LABEL_HELP_STR
9851 BGP_AF_MODIFIER_STR
9852 "Clear all peers\n"
9853 "BGP IPv4 neighbor to clear\n"
9854 "BGP IPv6 neighbor to clear\n"
9855 "BGP neighbor on interface to clear\n"
9856 "Clear peers with the AS number\n"
9857 "Clear all external peers\n"
9858 "Clear all members of peer-group\n"
9859 "BGP peer-group name\n"
9860 BGP_SOFT_STR
9861 BGP_SOFT_IN_STR
9862 BGP_SOFT_OUT_STR
9863 BGP_SOFT_IN_STR
9864 "Push out prefix-list ORF and do inbound soft reconfig\n"
9865 BGP_SOFT_OUT_STR
9866 "Reset message statistics\n")
9867 {
9868 char *vrf = NULL;
9869
9870 afi_t afi = AFI_UNSPEC;
9871 safi_t safi = SAFI_UNSPEC;
9872 enum clear_sort clr_sort = clear_peer;
9873 enum bgp_clear_type clr_type;
9874 char *clr_arg = NULL;
9875
9876 int idx = 0;
9877
9878 /* clear [ip] bgp */
9879 if (argv_find(argv, argc, "ip", &idx))
9880 afi = AFI_IP;
9881
9882 /* [<vrf> VIEWVRFNAME] */
9883 if (argv_find(argv, argc, "vrf", &idx)) {
9884 vrf = argv[idx + 1]->arg;
9885 idx += 2;
9886 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9887 vrf = NULL;
9888 } else if (argv_find(argv, argc, "view", &idx)) {
9889 /* [<view> VIEWVRFNAME] */
9890 vrf = argv[idx + 1]->arg;
9891 idx += 2;
9892 }
9893 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9894 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9895 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9896
9897 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9898 if (argv_find(argv, argc, "*", &idx)) {
9899 clr_sort = clear_all;
9900 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9901 clr_sort = clear_peer;
9902 clr_arg = argv[idx]->arg;
9903 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9904 clr_sort = clear_peer;
9905 clr_arg = argv[idx]->arg;
9906 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9907 clr_sort = clear_group;
9908 idx++;
9909 clr_arg = argv[idx]->arg;
9910 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9911 clr_sort = clear_peer;
9912 clr_arg = argv[idx]->arg;
9913 } else if (argv_find(argv, argc, "WORD", &idx)) {
9914 clr_sort = clear_peer;
9915 clr_arg = argv[idx]->arg;
9916 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9917 clr_sort = clear_as;
9918 clr_arg = argv[idx]->arg;
9919 } else if (argv_find(argv, argc, "external", &idx)) {
9920 clr_sort = clear_external;
9921 }
9922
9923 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9924 if (argv_find(argv, argc, "soft", &idx)) {
9925 if (argv_find(argv, argc, "in", &idx)
9926 || argv_find(argv, argc, "out", &idx))
9927 clr_type = strmatch(argv[idx]->text, "in")
9928 ? BGP_CLEAR_SOFT_IN
9929 : BGP_CLEAR_SOFT_OUT;
9930 else
9931 clr_type = BGP_CLEAR_SOFT_BOTH;
9932 } else if (argv_find(argv, argc, "in", &idx)) {
9933 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9934 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9935 : BGP_CLEAR_SOFT_IN;
9936 } else if (argv_find(argv, argc, "out", &idx)) {
9937 clr_type = BGP_CLEAR_SOFT_OUT;
9938 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9939 clr_type = BGP_CLEAR_MESSAGE_STATS;
9940 } else
9941 clr_type = BGP_CLEAR_SOFT_NONE;
9942
9943 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9944 }
9945
9946 DEFUN (clear_ip_bgp_prefix,
9947 clear_ip_bgp_prefix_cmd,
9948 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9949 CLEAR_STR
9950 IP_STR
9951 BGP_STR
9952 BGP_INSTANCE_HELP_STR
9953 "Clear bestpath and re-advertise\n"
9954 "IPv4 prefix\n")
9955 {
9956 char *vrf = NULL;
9957 char *prefix = NULL;
9958
9959 int idx = 0;
9960
9961 /* [<view|vrf> VIEWVRFNAME] */
9962 if (argv_find(argv, argc, "vrf", &idx)) {
9963 vrf = argv[idx + 1]->arg;
9964 idx += 2;
9965 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9966 vrf = NULL;
9967 } else if (argv_find(argv, argc, "view", &idx)) {
9968 /* [<view> VIEWVRFNAME] */
9969 vrf = argv[idx + 1]->arg;
9970 idx += 2;
9971 }
9972
9973 prefix = argv[argc - 1]->arg;
9974
9975 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9976 }
9977
9978 DEFUN (clear_bgp_ipv6_safi_prefix,
9979 clear_bgp_ipv6_safi_prefix_cmd,
9980 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9981 CLEAR_STR
9982 IP_STR
9983 BGP_STR
9984 BGP_AF_STR
9985 BGP_SAFI_HELP_STR
9986 "Clear bestpath and re-advertise\n"
9987 "IPv6 prefix\n")
9988 {
9989 int idx_safi = 0;
9990 int idx_ipv6_prefix = 0;
9991 safi_t safi = SAFI_UNICAST;
9992 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9993 argv[idx_ipv6_prefix]->arg : NULL;
9994
9995 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9996 return bgp_clear_prefix(
9997 vty, NULL, prefix, AFI_IP6,
9998 safi, NULL);
9999 }
10000
10001 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10002 clear_bgp_instance_ipv6_safi_prefix_cmd,
10003 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10004 CLEAR_STR
10005 IP_STR
10006 BGP_STR
10007 BGP_INSTANCE_HELP_STR
10008 BGP_AF_STR
10009 BGP_SAFI_HELP_STR
10010 "Clear bestpath and re-advertise\n"
10011 "IPv6 prefix\n")
10012 {
10013 int idx_safi = 0;
10014 int idx_vrfview = 0;
10015 int idx_ipv6_prefix = 0;
10016 safi_t safi = SAFI_UNICAST;
10017 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10018 argv[idx_ipv6_prefix]->arg : NULL;
10019 char *vrfview = NULL;
10020
10021 /* [<view|vrf> VIEWVRFNAME] */
10022 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10023 vrfview = argv[idx_vrfview + 1]->arg;
10024 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10025 vrfview = NULL;
10026 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10027 /* [<view> VIEWVRFNAME] */
10028 vrfview = argv[idx_vrfview + 1]->arg;
10029 }
10030 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10031
10032 return bgp_clear_prefix(
10033 vty, vrfview, prefix,
10034 AFI_IP6, safi, NULL);
10035 }
10036
10037 DEFUN (show_bgp_views,
10038 show_bgp_views_cmd,
10039 "show [ip] bgp views",
10040 SHOW_STR
10041 IP_STR
10042 BGP_STR
10043 "Show the defined BGP views\n")
10044 {
10045 struct list *inst = bm->bgp;
10046 struct listnode *node;
10047 struct bgp *bgp;
10048
10049 vty_out(vty, "Defined BGP views:\n");
10050 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10051 /* Skip VRFs. */
10052 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10053 continue;
10054 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10055 bgp->as);
10056 }
10057
10058 return CMD_SUCCESS;
10059 }
10060
10061 DEFUN (show_bgp_vrfs,
10062 show_bgp_vrfs_cmd,
10063 "show [ip] bgp vrfs [json]",
10064 SHOW_STR
10065 IP_STR
10066 BGP_STR
10067 "Show BGP VRFs\n"
10068 JSON_STR)
10069 {
10070 char buf[ETHER_ADDR_STRLEN];
10071 struct list *inst = bm->bgp;
10072 struct listnode *node;
10073 struct bgp *bgp;
10074 bool uj = use_json(argc, argv);
10075 json_object *json = NULL;
10076 json_object *json_vrfs = NULL;
10077 int count = 0;
10078
10079 if (uj) {
10080 json = json_object_new_object();
10081 json_vrfs = json_object_new_object();
10082 }
10083
10084 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10085 const char *name, *type;
10086 struct peer *peer;
10087 struct listnode *node2, *nnode2;
10088 int peers_cfg, peers_estb;
10089 json_object *json_vrf = NULL;
10090
10091 /* Skip Views. */
10092 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10093 continue;
10094
10095 count++;
10096 if (!uj && count == 1) {
10097 vty_out(vty,
10098 "%4s %-5s %-16s %9s %10s %-37s\n",
10099 "Type", "Id", "routerId", "#PeersCfg",
10100 "#PeersEstb", "Name");
10101 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10102 "L3-VNI", "RouterMAC", "Interface");
10103 }
10104
10105 peers_cfg = peers_estb = 0;
10106 if (uj)
10107 json_vrf = json_object_new_object();
10108
10109
10110 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10111 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10112 continue;
10113 peers_cfg++;
10114 if (peer_established(peer))
10115 peers_estb++;
10116 }
10117
10118 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10119 name = VRF_DEFAULT_NAME;
10120 type = "DFLT";
10121 } else {
10122 name = bgp->name;
10123 type = "VRF";
10124 }
10125
10126
10127 if (uj) {
10128 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10129 ? -1
10130 : (int64_t)bgp->vrf_id;
10131 char buf[BUFSIZ] = {0};
10132
10133 json_object_string_add(json_vrf, "type", type);
10134 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10135 json_object_string_addf(json_vrf, "routerId", "%pI4",
10136 &bgp->router_id);
10137 json_object_int_add(json_vrf, "numConfiguredPeers",
10138 peers_cfg);
10139 json_object_int_add(json_vrf, "numEstablishedPeers",
10140 peers_estb);
10141
10142 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10143 json_object_string_add(
10144 json_vrf, "rmac",
10145 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10146 json_object_string_add(json_vrf, "interface",
10147 ifindex2ifname(bgp->l3vni_svi_ifindex,
10148 bgp->vrf_id));
10149 json_object_object_add(json_vrfs, name, json_vrf);
10150 } else {
10151 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10152 type,
10153 bgp->vrf_id == VRF_UNKNOWN ? -1
10154 : (int)bgp->vrf_id,
10155 &bgp->router_id, peers_cfg, peers_estb, name);
10156 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10157 bgp->l3vni,
10158 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10159 ifindex2ifname(bgp->l3vni_svi_ifindex,
10160 bgp->vrf_id));
10161 }
10162 }
10163
10164 if (uj) {
10165 json_object_object_add(json, "vrfs", json_vrfs);
10166
10167 json_object_int_add(json, "totalVrfs", count);
10168
10169 vty_json(vty, json);
10170 } else {
10171 if (count)
10172 vty_out(vty,
10173 "\nTotal number of VRFs (including default): %d\n",
10174 count);
10175 }
10176
10177 return CMD_SUCCESS;
10178 }
10179
10180 DEFUN (show_bgp_mac_hash,
10181 show_bgp_mac_hash_cmd,
10182 "show bgp mac hash",
10183 SHOW_STR
10184 BGP_STR
10185 "Mac Address\n"
10186 "Mac Address database\n")
10187 {
10188 bgp_mac_dump_table(vty);
10189
10190 return CMD_SUCCESS;
10191 }
10192
10193 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10194 {
10195 struct vty *vty = (struct vty *)args;
10196 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10197
10198 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10199 }
10200
10201 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10202 {
10203 vty_out(vty, "self nexthop database:\n");
10204 bgp_nexthop_show_address_hash(vty, bgp);
10205
10206 vty_out(vty, "Tunnel-ip database:\n");
10207 hash_iterate(bgp->tip_hash,
10208 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10209 vty);
10210 }
10211
10212 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10213 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10214 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10215 "martian next-hops\n"
10216 "martian next-hop database\n")
10217 {
10218 struct bgp *bgp = NULL;
10219 int idx = 0;
10220 char *name = NULL;
10221
10222 /* [<vrf> VIEWVRFNAME] */
10223 if (argv_find(argv, argc, "vrf", &idx)) {
10224 name = argv[idx + 1]->arg;
10225 if (name && strmatch(name, VRF_DEFAULT_NAME))
10226 name = NULL;
10227 } else if (argv_find(argv, argc, "view", &idx))
10228 /* [<view> VIEWVRFNAME] */
10229 name = argv[idx + 1]->arg;
10230 if (name)
10231 bgp = bgp_lookup_by_name(name);
10232 else
10233 bgp = bgp_get_default();
10234
10235 if (!bgp) {
10236 vty_out(vty, "%% No BGP process is configured\n");
10237 return CMD_WARNING;
10238 }
10239 bgp_show_martian_nexthops(vty, bgp);
10240
10241 return CMD_SUCCESS;
10242 }
10243
10244 DEFUN (show_bgp_memory,
10245 show_bgp_memory_cmd,
10246 "show [ip] bgp memory",
10247 SHOW_STR
10248 IP_STR
10249 BGP_STR
10250 "Global BGP memory statistics\n")
10251 {
10252 char memstrbuf[MTYPE_MEMSTR_LEN];
10253 unsigned long count;
10254
10255 /* RIB related usage stats */
10256 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10257 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10258 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10259 count * sizeof(struct bgp_dest)));
10260
10261 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10262 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10263 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10264 count * sizeof(struct bgp_path_info)));
10265 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10266 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10267 count,
10268 mtype_memstr(
10269 memstrbuf, sizeof(memstrbuf),
10270 count * sizeof(struct bgp_path_info_extra)));
10271
10272 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10273 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10274 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10275 count * sizeof(struct bgp_static)));
10276
10277 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10278 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10279 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10280 count * sizeof(struct bpacket)));
10281
10282 /* Adj-In/Out */
10283 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10284 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10285 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10286 count * sizeof(struct bgp_adj_in)));
10287 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10288 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10289 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10290 count * sizeof(struct bgp_adj_out)));
10291
10292 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10293 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10294 count,
10295 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10296 count * sizeof(struct bgp_nexthop_cache)));
10297
10298 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10299 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10300 count,
10301 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10302 count * sizeof(struct bgp_damp_info)));
10303
10304 /* Attributes */
10305 count = attr_count();
10306 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10307 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10308 count * sizeof(struct attr)));
10309
10310 if ((count = attr_unknown_count()))
10311 vty_out(vty, "%ld unknown attributes\n", count);
10312
10313 /* AS_PATH attributes */
10314 count = aspath_count();
10315 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10316 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10317 count * sizeof(struct aspath)));
10318
10319 count = mtype_stats_alloc(MTYPE_AS_SEG);
10320 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10321 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10322 count * sizeof(struct assegment)));
10323
10324 /* Other attributes */
10325 if ((count = community_count()))
10326 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10327 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10328 count * sizeof(struct community)));
10329 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10330 vty_out(vty,
10331 "%ld BGP ext-community entries, using %s of memory\n",
10332 count,
10333 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10334 count * sizeof(struct ecommunity)));
10335 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10336 vty_out(vty,
10337 "%ld BGP large-community entries, using %s of memory\n",
10338 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10339 count * sizeof(struct lcommunity)));
10340
10341 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10342 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10343 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10344 count * sizeof(struct cluster_list)));
10345
10346 /* Peer related usage */
10347 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10348 vty_out(vty, "%ld peers, using %s of memory\n", count,
10349 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10350 count * sizeof(struct peer)));
10351
10352 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10353 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10354 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10355 count * sizeof(struct peer_group)));
10356
10357 /* Other */
10358 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10359 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10360 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10361 count * sizeof(regex_t)));
10362 return CMD_SUCCESS;
10363 }
10364
10365 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10366 {
10367 json_object *bestpath = json_object_new_object();
10368
10369 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10370 json_object_string_add(bestpath, "asPath", "ignore");
10371
10372 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10373 json_object_string_add(bestpath, "asPath", "confed");
10374
10375 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10376 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10377 json_object_string_add(bestpath, "multiPathRelax",
10378 "as-set");
10379 else
10380 json_object_string_add(bestpath, "multiPathRelax",
10381 "true");
10382 } else
10383 json_object_string_add(bestpath, "multiPathRelax", "false");
10384
10385 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10386 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10387
10388 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10389 json_object_string_add(bestpath, "compareRouterId", "true");
10390 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10391 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10392 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10393 json_object_string_add(bestpath, "med", "confed");
10394 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10395 json_object_string_add(bestpath, "med",
10396 "missing-as-worst");
10397 else
10398 json_object_string_add(bestpath, "med", "true");
10399 }
10400
10401 json_object_object_add(json, "bestPath", bestpath);
10402 }
10403
10404 /* Print the error code/subcode for why the peer is down */
10405 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10406 json_object *json_peer, bool use_json)
10407 {
10408 const char *code_str;
10409 const char *subcode_str;
10410
10411 if (use_json) {
10412 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10413 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10414 char errorcodesubcode_hexstr[5];
10415 char errorcodesubcode_str[256];
10416
10417 code_str = bgp_notify_code_str(peer->notify.code);
10418 subcode_str = bgp_notify_subcode_str(
10419 peer->notify.code,
10420 peer->notify.subcode);
10421
10422 snprintf(errorcodesubcode_hexstr,
10423 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10424 peer->notify.code, peer->notify.subcode);
10425 json_object_string_add(json_peer,
10426 "lastErrorCodeSubcode",
10427 errorcodesubcode_hexstr);
10428 snprintf(errorcodesubcode_str, 255, "%s%s",
10429 code_str, subcode_str);
10430 json_object_string_add(json_peer,
10431 "lastNotificationReason",
10432 errorcodesubcode_str);
10433 json_object_boolean_add(json_peer,
10434 "lastNotificationHardReset",
10435 peer->notify.hard_reset);
10436 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10437 && peer->notify.code == BGP_NOTIFY_CEASE
10438 && (peer->notify.subcode
10439 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10440 || peer->notify.subcode
10441 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10442 && peer->notify.length) {
10443 char msgbuf[1024];
10444 const char *msg_str;
10445
10446 msg_str = bgp_notify_admin_message(
10447 msgbuf, sizeof(msgbuf),
10448 (uint8_t *)peer->notify.data,
10449 peer->notify.length);
10450 if (msg_str)
10451 json_object_string_add(
10452 json_peer,
10453 "lastShutdownDescription",
10454 msg_str);
10455 }
10456
10457 }
10458 json_object_string_add(json_peer, "lastResetDueTo",
10459 peer_down_str[(int)peer->last_reset]);
10460 json_object_int_add(json_peer, "lastResetCode",
10461 peer->last_reset);
10462 } else {
10463 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10464 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10465 code_str = bgp_notify_code_str(peer->notify.code);
10466 subcode_str =
10467 bgp_notify_subcode_str(peer->notify.code,
10468 peer->notify.subcode);
10469 vty_out(vty, " Notification %s (%s%s%s)\n",
10470 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10471 ? "sent"
10472 : "received",
10473 code_str, subcode_str,
10474 peer->notify.hard_reset
10475 ? bgp_notify_subcode_str(
10476 BGP_NOTIFY_CEASE,
10477 BGP_NOTIFY_CEASE_HARD_RESET)
10478 : "");
10479 } else {
10480 vty_out(vty, " %s\n",
10481 peer_down_str[(int)peer->last_reset]);
10482 }
10483 }
10484 }
10485
10486 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10487 safi_t safi)
10488 {
10489 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10490 }
10491
10492 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10493 struct peer *peer, json_object *json_peer,
10494 int max_neighbor_width, bool use_json)
10495 {
10496 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10497 int len;
10498
10499 if (use_json) {
10500 if (peer_dynamic_neighbor(peer))
10501 json_object_boolean_true_add(json_peer,
10502 "dynamicPeer");
10503 if (peer->hostname)
10504 json_object_string_add(json_peer, "hostname",
10505 peer->hostname);
10506
10507 if (peer->domainname)
10508 json_object_string_add(json_peer, "domainname",
10509 peer->domainname);
10510 json_object_int_add(json_peer, "connectionsEstablished",
10511 peer->established);
10512 json_object_int_add(json_peer, "connectionsDropped",
10513 peer->dropped);
10514 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10515 use_json, json_peer);
10516 if (peer_established(peer))
10517 json_object_string_add(json_peer, "lastResetDueTo",
10518 "AFI/SAFI Not Negotiated");
10519 else
10520 bgp_show_peer_reset(NULL, peer, json_peer, true);
10521 } else {
10522 dn_flag[1] = '\0';
10523 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10524 if (peer->hostname
10525 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10526 len = vty_out(vty, "%s%s(%s)", dn_flag,
10527 peer->hostname, peer->host);
10528 else
10529 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10530
10531 /* pad the neighbor column with spaces */
10532 if (len < max_neighbor_width)
10533 vty_out(vty, "%*s", max_neighbor_width - len,
10534 " ");
10535 vty_out(vty, "%7d %7d %9s", peer->established,
10536 peer->dropped,
10537 peer_uptime(peer->uptime, timebuf,
10538 BGP_UPTIME_LEN, 0, NULL));
10539 if (peer_established(peer))
10540 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10541 else
10542 bgp_show_peer_reset(vty, peer, NULL,
10543 false);
10544 }
10545 }
10546
10547 /* Strip peer's description to the given size. */
10548 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10549 {
10550 static char stripped[BUFSIZ];
10551 uint32_t i = 0;
10552 uint32_t last_space = 0;
10553
10554 while (i < size) {
10555 if (*(desc + i) == 0) {
10556 stripped[i] = '\0';
10557 return stripped;
10558 }
10559 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10560 last_space = i;
10561 stripped[i] = *(desc + i);
10562 i++;
10563 }
10564
10565 if (last_space > size)
10566 stripped[size + 1] = '\0';
10567 else
10568 stripped[last_space] = '\0';
10569
10570 return stripped;
10571 }
10572
10573 /* Determine whether var peer should be filtered out of the summary. */
10574 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10575 struct peer *fpeer, int as_type,
10576 as_t as)
10577 {
10578
10579 /* filter neighbor XXXX */
10580 if (fpeer && fpeer != peer)
10581 return true;
10582
10583 /* filter remote-as (internal|external) */
10584 if (as_type != AS_UNSPECIFIED) {
10585 if (peer->as_type == AS_SPECIFIED) {
10586 if (as_type == AS_INTERNAL) {
10587 if (peer->as != peer->local_as)
10588 return true;
10589 } else if (peer->as == peer->local_as)
10590 return true;
10591 } else if (as_type != peer->as_type)
10592 return true;
10593 } else if (as && as != peer->as) /* filter remote-as XXX */
10594 return true;
10595
10596 return false;
10597 }
10598
10599 /* Show BGP peer's summary information.
10600 *
10601 * Peer's description is stripped according to if `wide` option is given
10602 * or not.
10603 *
10604 * When adding new columns to `show bgp summary` output, please make
10605 * sure `Desc` is the lastest column to show because it can contain
10606 * whitespaces and the whole output will be tricky.
10607 */
10608 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10609 struct peer *fpeer, int as_type, as_t as,
10610 uint16_t show_flags)
10611 {
10612 struct peer *peer;
10613 struct listnode *node, *nnode;
10614 unsigned int count = 0, dn_count = 0;
10615 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10616 char neighbor_buf[VTY_BUFSIZ];
10617 int neighbor_col_default_width = 16;
10618 int len, failed_count = 0;
10619 unsigned int filtered_count = 0;
10620 int max_neighbor_width = 0;
10621 int pfx_rcd_safi;
10622 json_object *json = NULL;
10623 json_object *json_peer = NULL;
10624 json_object *json_peers = NULL;
10625 struct peer_af *paf;
10626 struct bgp_filter *filter;
10627 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10628 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10629 bool show_established =
10630 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10631 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10632 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10633
10634 /* labeled-unicast routes are installed in the unicast table so in order
10635 * to
10636 * display the correct PfxRcd value we must look at SAFI_UNICAST
10637 */
10638
10639 if (safi == SAFI_LABELED_UNICAST)
10640 pfx_rcd_safi = SAFI_UNICAST;
10641 else
10642 pfx_rcd_safi = safi;
10643
10644 if (use_json) {
10645 json = json_object_new_object();
10646 json_peers = json_object_new_object();
10647 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10648 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10649 as_type, as)) {
10650 filtered_count++;
10651 count++;
10652 continue;
10653 }
10654
10655 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10656 continue;
10657
10658 if (peer->afc[afi][safi]) {
10659 /* See if we have at least a single failed peer */
10660 if (bgp_has_peer_failed(peer, afi, safi))
10661 failed_count++;
10662 count++;
10663 }
10664 if (peer_dynamic_neighbor(peer))
10665 dn_count++;
10666 }
10667
10668 } else {
10669 /* Loop over all neighbors that will be displayed to determine
10670 * how many
10671 * characters are needed for the Neighbor column
10672 */
10673 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10674 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10675 as_type, as)) {
10676 filtered_count++;
10677 count++;
10678 continue;
10679 }
10680
10681 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10682 continue;
10683
10684 if (peer->afc[afi][safi]) {
10685 memset(dn_flag, '\0', sizeof(dn_flag));
10686 if (peer_dynamic_neighbor(peer))
10687 dn_flag[0] = '*';
10688
10689 if (peer->hostname
10690 && CHECK_FLAG(bgp->flags,
10691 BGP_FLAG_SHOW_HOSTNAME))
10692 snprintf(neighbor_buf,
10693 sizeof(neighbor_buf),
10694 "%s%s(%s) ", dn_flag,
10695 peer->hostname, peer->host);
10696 else
10697 snprintf(neighbor_buf,
10698 sizeof(neighbor_buf), "%s%s ",
10699 dn_flag, peer->host);
10700
10701 len = strlen(neighbor_buf);
10702
10703 if (len > max_neighbor_width)
10704 max_neighbor_width = len;
10705
10706 /* See if we have at least a single failed peer */
10707 if (bgp_has_peer_failed(peer, afi, safi))
10708 failed_count++;
10709 count++;
10710 }
10711 }
10712
10713 /* Originally we displayed the Neighbor column as 16
10714 * characters wide so make that the default
10715 */
10716 if (max_neighbor_width < neighbor_col_default_width)
10717 max_neighbor_width = neighbor_col_default_width;
10718 }
10719
10720 if (show_failed && !failed_count) {
10721 if (use_json) {
10722 json_object_int_add(json, "failedPeersCount", 0);
10723 json_object_int_add(json, "dynamicPeers", dn_count);
10724 json_object_int_add(json, "totalPeers", count);
10725
10726 vty_json(vty, json);
10727 } else {
10728 vty_out(vty, "%% No failed BGP neighbors found\n");
10729 }
10730 return CMD_SUCCESS;
10731 }
10732
10733 count = 0; /* Reset the value as its used again */
10734 filtered_count = 0;
10735 dn_count = 0;
10736 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10737 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10738 continue;
10739
10740 if (!peer->afc[afi][safi])
10741 continue;
10742
10743 if (!count) {
10744 unsigned long ents;
10745 char memstrbuf[MTYPE_MEMSTR_LEN];
10746 int64_t vrf_id_ui;
10747
10748 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10749 ? -1
10750 : (int64_t)bgp->vrf_id;
10751
10752 /* Usage summary and header */
10753 if (use_json) {
10754 json_object_string_addf(json, "routerId",
10755 "%pI4",
10756 &bgp->router_id);
10757 json_object_int_add(json, "as", bgp->as);
10758 json_object_int_add(json, "vrfId", vrf_id_ui);
10759 json_object_string_add(
10760 json, "vrfName",
10761 (bgp->inst_type
10762 == BGP_INSTANCE_TYPE_DEFAULT)
10763 ? VRF_DEFAULT_NAME
10764 : bgp->name);
10765 } else {
10766 vty_out(vty,
10767 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10768 &bgp->router_id, bgp->as,
10769 bgp->vrf_id == VRF_UNKNOWN
10770 ? -1
10771 : (int)bgp->vrf_id);
10772 vty_out(vty, "\n");
10773 }
10774
10775 if (bgp_update_delay_configured(bgp)) {
10776 if (use_json) {
10777 json_object_int_add(
10778 json, "updateDelayLimit",
10779 bgp->v_update_delay);
10780
10781 if (bgp->v_update_delay
10782 != bgp->v_establish_wait)
10783 json_object_int_add(
10784 json,
10785 "updateDelayEstablishWait",
10786 bgp->v_establish_wait);
10787
10788 if (bgp_update_delay_active(bgp)) {
10789 json_object_string_add(
10790 json,
10791 "updateDelayFirstNeighbor",
10792 bgp->update_delay_begin_time);
10793 json_object_boolean_true_add(
10794 json,
10795 "updateDelayInProgress");
10796 } else {
10797 if (bgp->update_delay_over) {
10798 json_object_string_add(
10799 json,
10800 "updateDelayFirstNeighbor",
10801 bgp->update_delay_begin_time);
10802 json_object_string_add(
10803 json,
10804 "updateDelayBestpathResumed",
10805 bgp->update_delay_end_time);
10806 json_object_string_add(
10807 json,
10808 "updateDelayZebraUpdateResume",
10809 bgp->update_delay_zebra_resume_time);
10810 json_object_string_add(
10811 json,
10812 "updateDelayPeerUpdateResume",
10813 bgp->update_delay_peers_resume_time);
10814 }
10815 }
10816 } else {
10817 vty_out(vty,
10818 "Read-only mode update-delay limit: %d seconds\n",
10819 bgp->v_update_delay);
10820 if (bgp->v_update_delay
10821 != bgp->v_establish_wait)
10822 vty_out(vty,
10823 " Establish wait: %d seconds\n",
10824 bgp->v_establish_wait);
10825
10826 if (bgp_update_delay_active(bgp)) {
10827 vty_out(vty,
10828 " First neighbor established: %s\n",
10829 bgp->update_delay_begin_time);
10830 vty_out(vty,
10831 " Delay in progress\n");
10832 } else {
10833 if (bgp->update_delay_over) {
10834 vty_out(vty,
10835 " First neighbor established: %s\n",
10836 bgp->update_delay_begin_time);
10837 vty_out(vty,
10838 " Best-paths resumed: %s\n",
10839 bgp->update_delay_end_time);
10840 vty_out(vty,
10841 " zebra update resumed: %s\n",
10842 bgp->update_delay_zebra_resume_time);
10843 vty_out(vty,
10844 " peers update resumed: %s\n",
10845 bgp->update_delay_peers_resume_time);
10846 }
10847 }
10848 }
10849 }
10850
10851 if (use_json) {
10852 if (bgp_maxmed_onstartup_configured(bgp)
10853 && bgp->maxmed_active)
10854 json_object_boolean_true_add(
10855 json, "maxMedOnStartup");
10856 if (bgp->v_maxmed_admin)
10857 json_object_boolean_true_add(
10858 json, "maxMedAdministrative");
10859
10860 json_object_int_add(
10861 json, "tableVersion",
10862 bgp_table_version(bgp->rib[afi][safi]));
10863
10864 ents = bgp_table_count(bgp->rib[afi][safi]);
10865 json_object_int_add(json, "ribCount", ents);
10866 json_object_int_add(
10867 json, "ribMemory",
10868 ents * sizeof(struct bgp_dest));
10869
10870 ents = bgp->af_peer_count[afi][safi];
10871 json_object_int_add(json, "peerCount", ents);
10872 json_object_int_add(json, "peerMemory",
10873 ents * sizeof(struct peer));
10874
10875 if ((ents = listcount(bgp->group))) {
10876 json_object_int_add(
10877 json, "peerGroupCount", ents);
10878 json_object_int_add(
10879 json, "peerGroupMemory",
10880 ents * sizeof(struct
10881 peer_group));
10882 }
10883
10884 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10885 BGP_CONFIG_DAMPENING))
10886 json_object_boolean_true_add(
10887 json, "dampeningEnabled");
10888 } else {
10889 if (!show_terse) {
10890 if (bgp_maxmed_onstartup_configured(bgp)
10891 && bgp->maxmed_active)
10892 vty_out(vty,
10893 "Max-med on-startup active\n");
10894 if (bgp->v_maxmed_admin)
10895 vty_out(vty,
10896 "Max-med administrative active\n");
10897
10898 vty_out(vty,
10899 "BGP table version %" PRIu64
10900 "\n",
10901 bgp_table_version(
10902 bgp->rib[afi][safi]));
10903
10904 ents = bgp_table_count(
10905 bgp->rib[afi][safi]);
10906 vty_out(vty,
10907 "RIB entries %ld, using %s of memory\n",
10908 ents,
10909 mtype_memstr(
10910 memstrbuf,
10911 sizeof(memstrbuf),
10912 ents
10913 * sizeof(
10914 struct
10915 bgp_dest)));
10916
10917 /* Peer related usage */
10918 ents = bgp->af_peer_count[afi][safi];
10919 vty_out(vty,
10920 "Peers %ld, using %s of memory\n",
10921 ents,
10922 mtype_memstr(
10923 memstrbuf,
10924 sizeof(memstrbuf),
10925 ents
10926 * sizeof(
10927 struct
10928 peer)));
10929
10930 if ((ents = listcount(bgp->group)))
10931 vty_out(vty,
10932 "Peer groups %ld, using %s of memory\n",
10933 ents,
10934 mtype_memstr(
10935 memstrbuf,
10936 sizeof(memstrbuf),
10937 ents
10938 * sizeof(
10939 struct
10940 peer_group)));
10941
10942 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10943 BGP_CONFIG_DAMPENING))
10944 vty_out(vty,
10945 "Dampening enabled.\n");
10946 }
10947 if (show_failed) {
10948 vty_out(vty, "\n");
10949
10950 /* Subtract 8 here because 'Neighbor' is
10951 * 8 characters */
10952 vty_out(vty, "Neighbor");
10953 vty_out(vty, "%*s",
10954 max_neighbor_width - 8, " ");
10955 vty_out(vty,
10956 BGP_SHOW_SUMMARY_HEADER_FAILED);
10957 }
10958 }
10959 }
10960
10961 paf = peer_af_find(peer, afi, safi);
10962 filter = &peer->filter[afi][safi];
10963
10964 count++;
10965 /* Works for both failed & successful cases */
10966 if (peer_dynamic_neighbor(peer))
10967 dn_count++;
10968
10969 if (use_json) {
10970 json_peer = NULL;
10971 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10972 as_type, as)) {
10973 filtered_count++;
10974 continue;
10975 }
10976 if (show_failed &&
10977 bgp_has_peer_failed(peer, afi, safi)) {
10978 json_peer = json_object_new_object();
10979 bgp_show_failed_summary(vty, bgp, peer,
10980 json_peer, 0, use_json);
10981 } else if (!show_failed) {
10982 if (show_established
10983 && bgp_has_peer_failed(peer, afi, safi)) {
10984 filtered_count++;
10985 continue;
10986 }
10987
10988 json_peer = json_object_new_object();
10989 if (peer_dynamic_neighbor(peer)) {
10990 json_object_boolean_true_add(json_peer,
10991 "dynamicPeer");
10992 }
10993
10994 if (peer->hostname)
10995 json_object_string_add(json_peer, "hostname",
10996 peer->hostname);
10997
10998 if (peer->domainname)
10999 json_object_string_add(json_peer, "domainname",
11000 peer->domainname);
11001
11002 json_object_int_add(json_peer, "remoteAs", peer->as);
11003 json_object_int_add(
11004 json_peer, "localAs",
11005 peer->change_local_as
11006 ? peer->change_local_as
11007 : peer->local_as);
11008 json_object_int_add(json_peer, "version", 4);
11009 json_object_int_add(json_peer, "msgRcvd",
11010 PEER_TOTAL_RX(peer));
11011 json_object_int_add(json_peer, "msgSent",
11012 PEER_TOTAL_TX(peer));
11013
11014 atomic_size_t outq_count, inq_count;
11015 outq_count = atomic_load_explicit(
11016 &peer->obuf->count,
11017 memory_order_relaxed);
11018 inq_count = atomic_load_explicit(
11019 &peer->ibuf->count,
11020 memory_order_relaxed);
11021
11022 json_object_int_add(json_peer, "tableVersion",
11023 peer->version[afi][safi]);
11024 json_object_int_add(json_peer, "outq",
11025 outq_count);
11026 json_object_int_add(json_peer, "inq",
11027 inq_count);
11028 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11029 use_json, json_peer);
11030
11031 json_object_int_add(json_peer, "pfxRcd",
11032 peer->pcount[afi][pfx_rcd_safi]);
11033
11034 if (paf && PAF_SUBGRP(paf))
11035 json_object_int_add(
11036 json_peer, "pfxSnt",
11037 (PAF_SUBGRP(paf))->scount);
11038 else
11039 json_object_int_add(json_peer, "pfxSnt",
11040 0);
11041
11042 /* BGP FSM state */
11043 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11044 || CHECK_FLAG(peer->bgp->flags,
11045 BGP_FLAG_SHUTDOWN))
11046 json_object_string_add(json_peer,
11047 "state",
11048 "Idle (Admin)");
11049 else if (peer->afc_recv[afi][safi])
11050 json_object_string_add(
11051 json_peer, "state",
11052 lookup_msg(bgp_status_msg,
11053 peer->status, NULL));
11054 else if (CHECK_FLAG(
11055 peer->sflags,
11056 PEER_STATUS_PREFIX_OVERFLOW))
11057 json_object_string_add(json_peer,
11058 "state",
11059 "Idle (PfxCt)");
11060 else
11061 json_object_string_add(
11062 json_peer, "state",
11063 lookup_msg(bgp_status_msg,
11064 peer->status, NULL));
11065
11066 /* BGP peer state */
11067 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11068 || CHECK_FLAG(peer->bgp->flags,
11069 BGP_FLAG_SHUTDOWN))
11070 json_object_string_add(json_peer,
11071 "peerState",
11072 "Admin");
11073 else if (CHECK_FLAG(
11074 peer->sflags,
11075 PEER_STATUS_PREFIX_OVERFLOW))
11076 json_object_string_add(json_peer,
11077 "peerState",
11078 "PfxCt");
11079 else if (CHECK_FLAG(peer->flags,
11080 PEER_FLAG_PASSIVE))
11081 json_object_string_add(json_peer,
11082 "peerState",
11083 "Passive");
11084 else if (CHECK_FLAG(peer->sflags,
11085 PEER_STATUS_NSF_WAIT))
11086 json_object_string_add(json_peer,
11087 "peerState",
11088 "NSF passive");
11089 else if (CHECK_FLAG(
11090 peer->bgp->flags,
11091 BGP_FLAG_EBGP_REQUIRES_POLICY)
11092 && (!bgp_inbound_policy_exists(peer,
11093 filter)
11094 || !bgp_outbound_policy_exists(
11095 peer, filter)))
11096 json_object_string_add(json_peer,
11097 "peerState",
11098 "Policy");
11099 else
11100 json_object_string_add(
11101 json_peer, "peerState", "OK");
11102
11103 json_object_int_add(json_peer, "connectionsEstablished",
11104 peer->established);
11105 json_object_int_add(json_peer, "connectionsDropped",
11106 peer->dropped);
11107 if (peer->desc)
11108 json_object_string_add(
11109 json_peer, "desc", peer->desc);
11110 }
11111 /* Avoid creating empty peer dicts in JSON */
11112 if (json_peer == NULL)
11113 continue;
11114
11115 if (peer->conf_if)
11116 json_object_string_add(json_peer, "idType",
11117 "interface");
11118 else if (peer->su.sa.sa_family == AF_INET)
11119 json_object_string_add(json_peer, "idType",
11120 "ipv4");
11121 else if (peer->su.sa.sa_family == AF_INET6)
11122 json_object_string_add(json_peer, "idType",
11123 "ipv6");
11124 json_object_object_add(json_peers, peer->host,
11125 json_peer);
11126 } else {
11127 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11128 as_type, as)) {
11129 filtered_count++;
11130 continue;
11131 }
11132 if (show_failed &&
11133 bgp_has_peer_failed(peer, afi, safi)) {
11134 bgp_show_failed_summary(vty, bgp, peer, NULL,
11135 max_neighbor_width,
11136 use_json);
11137 } else if (!show_failed) {
11138 if (show_established
11139 && bgp_has_peer_failed(peer, afi, safi)) {
11140 filtered_count++;
11141 continue;
11142 }
11143
11144 if ((count - filtered_count) == 1) {
11145 /* display headline before the first
11146 * neighbor line */
11147 vty_out(vty, "\n");
11148
11149 /* Subtract 8 here because 'Neighbor' is
11150 * 8 characters */
11151 vty_out(vty, "Neighbor");
11152 vty_out(vty, "%*s",
11153 max_neighbor_width - 8, " ");
11154 vty_out(vty,
11155 show_wide
11156 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11157 : BGP_SHOW_SUMMARY_HEADER_ALL);
11158 }
11159
11160 memset(dn_flag, '\0', sizeof(dn_flag));
11161 if (peer_dynamic_neighbor(peer)) {
11162 dn_flag[0] = '*';
11163 }
11164
11165 if (peer->hostname
11166 && CHECK_FLAG(bgp->flags,
11167 BGP_FLAG_SHOW_HOSTNAME))
11168 len = vty_out(vty, "%s%s(%s)", dn_flag,
11169 peer->hostname,
11170 peer->host);
11171 else
11172 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11173
11174 /* pad the neighbor column with spaces */
11175 if (len < max_neighbor_width)
11176 vty_out(vty, "%*s", max_neighbor_width - len,
11177 " ");
11178
11179 atomic_size_t outq_count, inq_count;
11180 outq_count = atomic_load_explicit(
11181 &peer->obuf->count,
11182 memory_order_relaxed);
11183 inq_count = atomic_load_explicit(
11184 &peer->ibuf->count,
11185 memory_order_relaxed);
11186
11187 if (show_wide)
11188 vty_out(vty,
11189 "4 %10u %10u %9u %9u %8" PRIu64
11190 " %4zu %4zu %8s",
11191 peer->as,
11192 peer->change_local_as
11193 ? peer->change_local_as
11194 : peer->local_as,
11195 PEER_TOTAL_RX(peer),
11196 PEER_TOTAL_TX(peer),
11197 peer->version[afi][safi],
11198 inq_count, outq_count,
11199 peer_uptime(peer->uptime,
11200 timebuf,
11201 BGP_UPTIME_LEN, 0,
11202 NULL));
11203 else
11204 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11205 " %4zu %4zu %8s",
11206 peer->as, PEER_TOTAL_RX(peer),
11207 PEER_TOTAL_TX(peer),
11208 peer->version[afi][safi],
11209 inq_count, outq_count,
11210 peer_uptime(peer->uptime,
11211 timebuf,
11212 BGP_UPTIME_LEN, 0,
11213 NULL));
11214
11215 if (peer_established(peer)) {
11216 if (peer->afc_recv[afi][safi]) {
11217 if (CHECK_FLAG(
11218 bgp->flags,
11219 BGP_FLAG_EBGP_REQUIRES_POLICY)
11220 && !bgp_inbound_policy_exists(
11221 peer, filter))
11222 vty_out(vty, " %12s",
11223 "(Policy)");
11224 else
11225 vty_out(vty,
11226 " %12u",
11227 peer->pcount
11228 [afi]
11229 [pfx_rcd_safi]);
11230 } else {
11231 vty_out(vty, " NoNeg");
11232 }
11233
11234 if (paf && PAF_SUBGRP(paf)) {
11235 if (CHECK_FLAG(
11236 bgp->flags,
11237 BGP_FLAG_EBGP_REQUIRES_POLICY)
11238 && !bgp_outbound_policy_exists(
11239 peer, filter))
11240 vty_out(vty, " %8s",
11241 "(Policy)");
11242 else
11243 vty_out(vty,
11244 " %8u",
11245 (PAF_SUBGRP(
11246 paf))
11247 ->scount);
11248 } else {
11249 vty_out(vty, " NoNeg");
11250 }
11251 } else {
11252 if (CHECK_FLAG(peer->flags,
11253 PEER_FLAG_SHUTDOWN)
11254 || CHECK_FLAG(peer->bgp->flags,
11255 BGP_FLAG_SHUTDOWN))
11256 vty_out(vty, " Idle (Admin)");
11257 else if (CHECK_FLAG(
11258 peer->sflags,
11259 PEER_STATUS_PREFIX_OVERFLOW))
11260 vty_out(vty, " Idle (PfxCt)");
11261 else
11262 vty_out(vty, " %12s",
11263 lookup_msg(bgp_status_msg,
11264 peer->status, NULL));
11265
11266 vty_out(vty, " %8u", 0);
11267 }
11268 /* Make sure `Desc` column is the lastest in
11269 * the output.
11270 */
11271 if (peer->desc)
11272 vty_out(vty, " %s",
11273 bgp_peer_description_stripped(
11274 peer->desc,
11275 show_wide ? 64 : 20));
11276 else
11277 vty_out(vty, " N/A");
11278 vty_out(vty, "\n");
11279 }
11280
11281 }
11282 }
11283
11284 if (use_json) {
11285 json_object_object_add(json, "peers", json_peers);
11286 json_object_int_add(json, "failedPeers", failed_count);
11287 json_object_int_add(json, "displayedPeers",
11288 count - filtered_count);
11289 json_object_int_add(json, "totalPeers", count);
11290 json_object_int_add(json, "dynamicPeers", dn_count);
11291
11292 if (!show_failed)
11293 bgp_show_bestpath_json(bgp, json);
11294
11295 vty_json(vty, json);
11296 } else {
11297 if (count) {
11298 if (filtered_count == count)
11299 vty_out(vty, "\n%% No matching neighbor\n");
11300 else {
11301 if (show_failed)
11302 vty_out(vty, "\nDisplayed neighbors %d",
11303 failed_count);
11304 else if (as_type != AS_UNSPECIFIED || as
11305 || fpeer || show_established)
11306 vty_out(vty, "\nDisplayed neighbors %d",
11307 count - filtered_count);
11308
11309 vty_out(vty, "\nTotal number of neighbors %d\n",
11310 count);
11311 }
11312 } else {
11313 vty_out(vty, "No %s neighbor is configured\n",
11314 get_afi_safi_str(afi, safi, false));
11315 }
11316
11317 if (dn_count) {
11318 vty_out(vty, "* - dynamic neighbor\n");
11319 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11320 dn_count, bgp->dynamic_neighbors_limit);
11321 }
11322 }
11323
11324 return CMD_SUCCESS;
11325 }
11326
11327 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11328 int safi, struct peer *fpeer, int as_type,
11329 as_t as, uint16_t show_flags)
11330 {
11331 int is_first = 1;
11332 int afi_wildcard = (afi == AFI_MAX);
11333 int safi_wildcard = (safi == SAFI_MAX);
11334 int is_wildcard = (afi_wildcard || safi_wildcard);
11335 bool nbr_output = false;
11336 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11337
11338 if (use_json && is_wildcard)
11339 vty_out(vty, "{\n");
11340 if (afi_wildcard)
11341 afi = 1; /* AFI_IP */
11342 while (afi < AFI_MAX) {
11343 if (safi_wildcard)
11344 safi = 1; /* SAFI_UNICAST */
11345 while (safi < SAFI_MAX) {
11346 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11347 nbr_output = true;
11348
11349 if (is_wildcard) {
11350 /*
11351 * So limit output to those afi/safi
11352 * pairs that
11353 * actualy have something interesting in
11354 * them
11355 */
11356 if (use_json) {
11357 if (!is_first)
11358 vty_out(vty, ",\n");
11359 else
11360 is_first = 0;
11361
11362 vty_out(vty, "\"%s\":",
11363 get_afi_safi_str(afi,
11364 safi,
11365 true));
11366 } else {
11367 vty_out(vty,
11368 "\n%s Summary (%s):\n",
11369 get_afi_safi_str(afi,
11370 safi,
11371 false),
11372 bgp->name_pretty);
11373 }
11374 }
11375 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11376 as_type, as, show_flags);
11377 }
11378 safi++;
11379 if (!safi_wildcard)
11380 safi = SAFI_MAX;
11381 }
11382 afi++;
11383 if (!afi_wildcard)
11384 afi = AFI_MAX;
11385 }
11386
11387 if (use_json && is_wildcard)
11388 vty_out(vty, "}\n");
11389 else if (!nbr_output) {
11390 if (use_json)
11391 vty_out(vty, "{}\n");
11392 else
11393 vty_out(vty, "%% No BGP neighbors found in %s\n",
11394 bgp->name_pretty);
11395 }
11396 }
11397
11398 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11399 safi_t safi,
11400 const char *neighbor,
11401 int as_type, as_t as,
11402 uint16_t show_flags)
11403 {
11404 struct listnode *node, *nnode;
11405 struct bgp *bgp;
11406 struct peer *fpeer = NULL;
11407 int is_first = 1;
11408 bool nbr_output = false;
11409 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11410
11411 if (use_json)
11412 vty_out(vty, "{\n");
11413
11414 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11415 nbr_output = true;
11416 if (use_json) {
11417 if (!is_first)
11418 vty_out(vty, ",\n");
11419 else
11420 is_first = 0;
11421
11422 vty_out(vty, "\"%s\":",
11423 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11424 ? VRF_DEFAULT_NAME
11425 : bgp->name);
11426 }
11427 if (neighbor) {
11428 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11429 use_json);
11430 if (!fpeer)
11431 continue;
11432 }
11433 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11434 as, show_flags);
11435 }
11436
11437 if (use_json)
11438 vty_out(vty, "}\n");
11439 else if (!nbr_output)
11440 vty_out(vty, "%% BGP instance not found\n");
11441 }
11442
11443 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11444 safi_t safi, const char *neighbor, int as_type,
11445 as_t as, uint16_t show_flags)
11446 {
11447 struct bgp *bgp;
11448 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11449 struct peer *fpeer = NULL;
11450
11451 if (name) {
11452 if (strmatch(name, "all")) {
11453 bgp_show_all_instances_summary_vty(vty, afi, safi,
11454 neighbor, as_type,
11455 as, show_flags);
11456 return CMD_SUCCESS;
11457 } else {
11458 bgp = bgp_lookup_by_name(name);
11459
11460 if (!bgp) {
11461 if (use_json)
11462 vty_out(vty, "{}\n");
11463 else
11464 vty_out(vty,
11465 "%% BGP instance not found\n");
11466 return CMD_WARNING;
11467 }
11468
11469 if (neighbor) {
11470 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11471 use_json);
11472 if (!fpeer)
11473 return CMD_WARNING;
11474 }
11475 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11476 as_type, as, show_flags);
11477 return CMD_SUCCESS;
11478 }
11479 }
11480
11481 bgp = bgp_get_default();
11482
11483 if (bgp) {
11484 if (neighbor) {
11485 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11486 use_json);
11487 if (!fpeer)
11488 return CMD_WARNING;
11489 }
11490 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11491 as, show_flags);
11492 } else {
11493 if (use_json)
11494 vty_out(vty, "{}\n");
11495 else
11496 vty_out(vty, "%% BGP instance not found\n");
11497 return CMD_WARNING;
11498 }
11499
11500 return CMD_SUCCESS;
11501 }
11502
11503 /* `show [ip] bgp summary' commands. */
11504 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11505 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11506 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11507 "]] [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]",
11508 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11509 BGP_SAFI_WITH_LABEL_HELP_STR
11510 "Display the entries for all address families\n"
11511 "Summary of BGP neighbor status\n"
11512 "Show only sessions in Established state\n"
11513 "Show only sessions not in Established state\n"
11514 "Show only the specified neighbor session\n"
11515 "Neighbor to display information about\n"
11516 "Neighbor to display information about\n"
11517 "Neighbor on BGP configured interface\n"
11518 "Show only the specified remote AS sessions\n"
11519 "AS number\n"
11520 "Internal (iBGP) AS sessions\n"
11521 "External (eBGP) AS sessions\n"
11522 "Shorten the information on BGP instances\n"
11523 "Increase table width for longer output\n" JSON_STR)
11524 {
11525 char *vrf = NULL;
11526 afi_t afi = AFI_MAX;
11527 safi_t safi = SAFI_MAX;
11528 as_t as = 0; /* 0 means AS filter not set */
11529 int as_type = AS_UNSPECIFIED;
11530 uint16_t show_flags = 0;
11531
11532 int idx = 0;
11533
11534 /* show [ip] bgp */
11535 if (!all && argv_find(argv, argc, "ip", &idx))
11536 afi = AFI_IP;
11537 /* [<vrf> VIEWVRFNAME] */
11538 if (argv_find(argv, argc, "vrf", &idx)) {
11539 vrf = argv[idx + 1]->arg;
11540 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11541 vrf = NULL;
11542 } else if (argv_find(argv, argc, "view", &idx))
11543 /* [<view> VIEWVRFNAME] */
11544 vrf = argv[idx + 1]->arg;
11545 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11546 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11547 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11548 }
11549
11550 if (argv_find(argv, argc, "failed", &idx))
11551 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11552
11553 if (argv_find(argv, argc, "established", &idx))
11554 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11555
11556 if (argv_find(argv, argc, "remote-as", &idx)) {
11557 if (argv[idx + 1]->arg[0] == 'i')
11558 as_type = AS_INTERNAL;
11559 else if (argv[idx + 1]->arg[0] == 'e')
11560 as_type = AS_EXTERNAL;
11561 else
11562 as = (as_t)atoi(argv[idx + 1]->arg);
11563 }
11564
11565 if (argv_find(argv, argc, "terse", &idx))
11566 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11567
11568 if (argv_find(argv, argc, "wide", &idx))
11569 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11570
11571 if (argv_find(argv, argc, "json", &idx))
11572 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11573
11574 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11575 show_flags);
11576 }
11577
11578 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11579 {
11580 if (for_json)
11581 return get_afi_safi_json_str(afi, safi);
11582 else
11583 return get_afi_safi_vty_str(afi, safi);
11584 }
11585
11586
11587 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11588 afi_t afi, safi_t safi,
11589 uint16_t adv_smcap, uint16_t adv_rmcap,
11590 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11591 bool use_json, json_object *json_pref)
11592 {
11593 /* Send-Mode */
11594 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11595 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11596 if (use_json) {
11597 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11598 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11599 json_object_string_add(json_pref, "sendMode",
11600 "advertisedAndReceived");
11601 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11602 json_object_string_add(json_pref, "sendMode",
11603 "advertised");
11604 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11605 json_object_string_add(json_pref, "sendMode",
11606 "received");
11607 } else {
11608 vty_out(vty, " Send-mode: ");
11609 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11610 vty_out(vty, "advertised");
11611 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11612 vty_out(vty, "%sreceived",
11613 CHECK_FLAG(p->af_cap[afi][safi],
11614 adv_smcap)
11615 ? ", "
11616 : "");
11617 vty_out(vty, "\n");
11618 }
11619 }
11620
11621 /* Receive-Mode */
11622 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11623 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11624 if (use_json) {
11625 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11626 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11627 json_object_string_add(json_pref, "recvMode",
11628 "advertisedAndReceived");
11629 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11630 json_object_string_add(json_pref, "recvMode",
11631 "advertised");
11632 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11633 json_object_string_add(json_pref, "recvMode",
11634 "received");
11635 } else {
11636 vty_out(vty, " Receive-mode: ");
11637 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11638 vty_out(vty, "advertised");
11639 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11640 vty_out(vty, "%sreceived",
11641 CHECK_FLAG(p->af_cap[afi][safi],
11642 adv_rmcap)
11643 ? ", "
11644 : "");
11645 vty_out(vty, "\n");
11646 }
11647 }
11648 }
11649
11650 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11651 struct peer *p,
11652 bool use_json,
11653 json_object *json)
11654 {
11655 bool rbit = false;
11656 bool nbit = false;
11657
11658 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11659 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11660 && (peer_established(p))) {
11661 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11662 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11663 }
11664
11665 if (use_json) {
11666 json_object_boolean_add(json, "rBit", rbit);
11667 json_object_boolean_add(json, "nBit", nbit);
11668 } else {
11669 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11670 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11671 }
11672 }
11673
11674 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11675 struct peer *peer,
11676 bool use_json,
11677 json_object *json)
11678 {
11679 const char *mode = "NotApplicable";
11680
11681 if (!use_json)
11682 vty_out(vty, "\n Remote GR Mode: ");
11683
11684 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11685 && (peer_established(peer))) {
11686
11687 if ((peer->nsf_af_count == 0)
11688 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11689
11690 mode = "Disable";
11691
11692 } else if (peer->nsf_af_count == 0
11693 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11694
11695 mode = "Helper";
11696
11697 } else if (peer->nsf_af_count != 0
11698 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11699
11700 mode = "Restart";
11701 }
11702 }
11703
11704 if (use_json) {
11705 json_object_string_add(json, "remoteGrMode", mode);
11706 } else
11707 vty_out(vty, mode, "\n");
11708 }
11709
11710 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11711 struct peer *p,
11712 bool use_json,
11713 json_object *json)
11714 {
11715 const char *mode = "Invalid";
11716
11717 if (!use_json)
11718 vty_out(vty, " Local GR Mode: ");
11719
11720 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11721 mode = "Helper";
11722 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11723 mode = "Restart";
11724 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11725 mode = "Disable";
11726 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11727 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11728 mode = "Helper*";
11729 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11730 mode = "Restart*";
11731 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11732 mode = "Disable*";
11733 else
11734 mode = "Invalid*";
11735 }
11736
11737 if (use_json) {
11738 json_object_string_add(json, "localGrMode", mode);
11739 } else {
11740 vty_out(vty, mode, "\n");
11741 }
11742 }
11743
11744 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11745 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11746 {
11747 afi_t afi;
11748 safi_t safi;
11749 json_object *json_afi_safi = NULL;
11750 json_object *json_timer = NULL;
11751 json_object *json_endofrib_status = NULL;
11752 bool eor_flag = false;
11753
11754 FOREACH_AFI_SAFI_NSF (afi, safi) {
11755 if (!peer->afc[afi][safi])
11756 continue;
11757
11758 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11759 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11760 continue;
11761
11762 if (use_json) {
11763 json_afi_safi = json_object_new_object();
11764 json_endofrib_status = json_object_new_object();
11765 json_timer = json_object_new_object();
11766 }
11767
11768 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11769 eor_flag = true;
11770 else
11771 eor_flag = false;
11772
11773 if (!use_json) {
11774 vty_out(vty, " %s:\n",
11775 get_afi_safi_str(afi, safi, false));
11776
11777 vty_out(vty, " F bit: ");
11778 }
11779
11780 if (peer->nsf[afi][safi] &&
11781 CHECK_FLAG(peer->af_cap[afi][safi],
11782 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11783
11784 if (use_json) {
11785 json_object_boolean_true_add(json_afi_safi,
11786 "fBit");
11787 } else
11788 vty_out(vty, "True\n");
11789 } else {
11790 if (use_json)
11791 json_object_boolean_false_add(json_afi_safi,
11792 "fBit");
11793 else
11794 vty_out(vty, "False\n");
11795 }
11796
11797 if (!use_json)
11798 vty_out(vty, " End-of-RIB sent: ");
11799
11800 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11801 PEER_STATUS_EOR_SEND)) {
11802 if (use_json) {
11803 json_object_boolean_true_add(
11804 json_endofrib_status, "endOfRibSend");
11805
11806 PRINT_EOR_JSON(eor_flag);
11807 } else {
11808 vty_out(vty, "Yes\n");
11809 vty_out(vty,
11810 " End-of-RIB sent after update: ");
11811
11812 PRINT_EOR(eor_flag);
11813 }
11814 } else {
11815 if (use_json) {
11816 json_object_boolean_false_add(
11817 json_endofrib_status, "endOfRibSend");
11818 json_object_boolean_false_add(
11819 json_endofrib_status,
11820 "endOfRibSentAfterUpdate");
11821 } else {
11822 vty_out(vty, "No\n");
11823 vty_out(vty,
11824 " End-of-RIB sent after update: ");
11825 vty_out(vty, "No\n");
11826 }
11827 }
11828
11829 if (!use_json)
11830 vty_out(vty, " End-of-RIB received: ");
11831
11832 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11833 PEER_STATUS_EOR_RECEIVED)) {
11834 if (use_json)
11835 json_object_boolean_true_add(
11836 json_endofrib_status, "endOfRibRecv");
11837 else
11838 vty_out(vty, "Yes\n");
11839 } else {
11840 if (use_json)
11841 json_object_boolean_false_add(
11842 json_endofrib_status, "endOfRibRecv");
11843 else
11844 vty_out(vty, "No\n");
11845 }
11846
11847 if (use_json) {
11848 json_object_int_add(json_timer, "stalePathTimer",
11849 peer->bgp->stalepath_time);
11850
11851 if (peer->t_gr_stale != NULL) {
11852 json_object_int_add(json_timer,
11853 "stalePathTimerRemaining",
11854 thread_timer_remain_second(
11855 peer->t_gr_stale));
11856 }
11857
11858 /* Display Configured Selection
11859 * Deferral only when when
11860 * Gr mode is enabled.
11861 */
11862 if (CHECK_FLAG(peer->flags,
11863 PEER_FLAG_GRACEFUL_RESTART)) {
11864 json_object_int_add(json_timer,
11865 "selectionDeferralTimer",
11866 peer->bgp->stalepath_time);
11867 }
11868
11869 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11870 NULL) {
11871
11872 json_object_int_add(
11873 json_timer,
11874 "selectionDeferralTimerRemaining",
11875 thread_timer_remain_second(
11876 peer->bgp->gr_info[afi][safi]
11877 .t_select_deferral));
11878 }
11879 } else {
11880 vty_out(vty, " Timers:\n");
11881 vty_out(vty,
11882 " Configured Stale Path Time(sec): %u\n",
11883 peer->bgp->stalepath_time);
11884
11885 if (peer->t_gr_stale != NULL)
11886 vty_out(vty,
11887 " Stale Path Remaining(sec): %ld\n",
11888 thread_timer_remain_second(
11889 peer->t_gr_stale));
11890 /* Display Configured Selection
11891 * Deferral only when when
11892 * Gr mode is enabled.
11893 */
11894 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11895 vty_out(vty,
11896 " Configured Selection Deferral Time(sec): %u\n",
11897 peer->bgp->select_defer_time);
11898
11899 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11900 NULL)
11901 vty_out(vty,
11902 " Selection Deferral Time Remaining(sec): %ld\n",
11903 thread_timer_remain_second(
11904 peer->bgp->gr_info[afi][safi]
11905 .t_select_deferral));
11906 }
11907 if (use_json) {
11908 json_object_object_add(json_afi_safi, "endOfRibStatus",
11909 json_endofrib_status);
11910 json_object_object_add(json_afi_safi, "timers",
11911 json_timer);
11912 json_object_object_add(
11913 json, get_afi_safi_str(afi, safi, true),
11914 json_afi_safi);
11915 }
11916 }
11917 }
11918
11919 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11920 struct peer *p,
11921 bool use_json,
11922 json_object *json)
11923 {
11924 if (use_json) {
11925 json_object *json_timer = NULL;
11926
11927 json_timer = json_object_new_object();
11928
11929 json_object_int_add(json_timer, "configuredRestartTimer",
11930 p->bgp->restart_time);
11931
11932 json_object_int_add(json_timer, "receivedRestartTimer",
11933 p->v_gr_restart);
11934
11935 if (p->t_gr_restart != NULL)
11936 json_object_int_add(
11937 json_timer, "restartTimerRemaining",
11938 thread_timer_remain_second(p->t_gr_restart));
11939
11940 json_object_object_add(json, "timers", json_timer);
11941 } else {
11942
11943 vty_out(vty, " Timers:\n");
11944 vty_out(vty, " Configured Restart Time(sec): %u\n",
11945 p->bgp->restart_time);
11946
11947 vty_out(vty, " Received Restart Time(sec): %u\n",
11948 p->v_gr_restart);
11949 if (p->t_gr_restart != NULL)
11950 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11951 thread_timer_remain_second(p->t_gr_restart));
11952 if (p->t_gr_restart != NULL) {
11953 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11954 thread_timer_remain_second(p->t_gr_restart));
11955 }
11956 }
11957 }
11958
11959 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11960 bool use_json, json_object *json)
11961 {
11962 char dn_flag[2] = {0};
11963 /* '*' + v6 address of neighbor */
11964 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11965
11966 if (!p->conf_if && peer_dynamic_neighbor(p))
11967 dn_flag[0] = '*';
11968
11969 if (p->conf_if) {
11970 if (use_json)
11971 json_object_string_addf(json, "neighborAddr", "%pSU",
11972 &p->su);
11973 else
11974 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11975 &p->su);
11976 } else {
11977 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11978 p->host);
11979
11980 if (use_json)
11981 json_object_string_add(json, "neighborAddr",
11982 neighborAddr);
11983 else
11984 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11985 }
11986
11987 /* more gr info in new format */
11988 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11989 }
11990
11991 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11992 safi_t safi, bool use_json,
11993 json_object *json_neigh)
11994 {
11995 struct bgp_filter *filter;
11996 struct peer_af *paf;
11997 char orf_pfx_name[BUFSIZ];
11998 int orf_pfx_count;
11999 json_object *json_af = NULL;
12000 json_object *json_prefA = NULL;
12001 json_object *json_prefB = NULL;
12002 json_object *json_addr = NULL;
12003 json_object *json_advmap = NULL;
12004
12005 if (use_json) {
12006 json_addr = json_object_new_object();
12007 json_af = json_object_new_object();
12008 filter = &p->filter[afi][safi];
12009
12010 if (peer_group_active(p))
12011 json_object_string_add(json_addr, "peerGroupMember",
12012 p->group->name);
12013
12014 paf = peer_af_find(p, afi, safi);
12015 if (paf && PAF_SUBGRP(paf)) {
12016 json_object_int_add(json_addr, "updateGroupId",
12017 PAF_UPDGRP(paf)->id);
12018 json_object_int_add(json_addr, "subGroupId",
12019 PAF_SUBGRP(paf)->id);
12020 json_object_int_add(json_addr, "packetQueueLength",
12021 bpacket_queue_virtual_length(paf));
12022 }
12023
12024 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12025 || CHECK_FLAG(p->af_cap[afi][safi],
12026 PEER_CAP_ORF_PREFIX_SM_RCV)
12027 || CHECK_FLAG(p->af_cap[afi][safi],
12028 PEER_CAP_ORF_PREFIX_RM_ADV)
12029 || CHECK_FLAG(p->af_cap[afi][safi],
12030 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12031 json_object_int_add(json_af, "orfType",
12032 ORF_TYPE_PREFIX);
12033 json_prefA = json_object_new_object();
12034 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12035 PEER_CAP_ORF_PREFIX_SM_ADV,
12036 PEER_CAP_ORF_PREFIX_RM_ADV,
12037 PEER_CAP_ORF_PREFIX_SM_RCV,
12038 PEER_CAP_ORF_PREFIX_RM_RCV,
12039 use_json, json_prefA);
12040 json_object_object_add(json_af, "orfPrefixList",
12041 json_prefA);
12042 }
12043
12044 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12045 || CHECK_FLAG(p->af_cap[afi][safi],
12046 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12047 || CHECK_FLAG(p->af_cap[afi][safi],
12048 PEER_CAP_ORF_PREFIX_RM_ADV)
12049 || CHECK_FLAG(p->af_cap[afi][safi],
12050 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12051 json_object_int_add(json_af, "orfOldType",
12052 ORF_TYPE_PREFIX_OLD);
12053 json_prefB = json_object_new_object();
12054 bgp_show_peer_afi_orf_cap(
12055 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12056 PEER_CAP_ORF_PREFIX_RM_ADV,
12057 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12058 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12059 json_prefB);
12060 json_object_object_add(json_af, "orfOldPrefixList",
12061 json_prefB);
12062 }
12063
12064 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12065 || CHECK_FLAG(p->af_cap[afi][safi],
12066 PEER_CAP_ORF_PREFIX_SM_RCV)
12067 || CHECK_FLAG(p->af_cap[afi][safi],
12068 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12069 || CHECK_FLAG(p->af_cap[afi][safi],
12070 PEER_CAP_ORF_PREFIX_RM_ADV)
12071 || CHECK_FLAG(p->af_cap[afi][safi],
12072 PEER_CAP_ORF_PREFIX_RM_RCV)
12073 || CHECK_FLAG(p->af_cap[afi][safi],
12074 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12075 json_object_object_add(json_addr, "afDependentCap",
12076 json_af);
12077 else
12078 json_object_free(json_af);
12079
12080 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12081 p->host, afi, safi);
12082 orf_pfx_count = prefix_bgp_show_prefix_list(
12083 NULL, afi, orf_pfx_name, use_json);
12084
12085 if (CHECK_FLAG(p->af_sflags[afi][safi],
12086 PEER_STATUS_ORF_PREFIX_SEND)
12087 || orf_pfx_count) {
12088 if (CHECK_FLAG(p->af_sflags[afi][safi],
12089 PEER_STATUS_ORF_PREFIX_SEND))
12090 json_object_boolean_true_add(json_neigh,
12091 "orfSent");
12092 if (orf_pfx_count)
12093 json_object_int_add(json_addr, "orfRecvCounter",
12094 orf_pfx_count);
12095 }
12096 if (CHECK_FLAG(p->af_sflags[afi][safi],
12097 PEER_STATUS_ORF_WAIT_REFRESH))
12098 json_object_string_add(
12099 json_addr, "orfFirstUpdate",
12100 "deferredUntilORFOrRouteRefreshRecvd");
12101
12102 if (CHECK_FLAG(p->af_flags[afi][safi],
12103 PEER_FLAG_REFLECTOR_CLIENT))
12104 json_object_boolean_true_add(json_addr,
12105 "routeReflectorClient");
12106 if (CHECK_FLAG(p->af_flags[afi][safi],
12107 PEER_FLAG_RSERVER_CLIENT))
12108 json_object_boolean_true_add(json_addr,
12109 "routeServerClient");
12110 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12111 json_object_boolean_true_add(json_addr,
12112 "inboundSoftConfigPermit");
12113
12114 if (CHECK_FLAG(p->af_flags[afi][safi],
12115 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12116 json_object_boolean_true_add(
12117 json_addr,
12118 "privateAsNumsAllReplacedInUpdatesToNbr");
12119 else if (CHECK_FLAG(p->af_flags[afi][safi],
12120 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12121 json_object_boolean_true_add(
12122 json_addr,
12123 "privateAsNumsReplacedInUpdatesToNbr");
12124 else if (CHECK_FLAG(p->af_flags[afi][safi],
12125 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12126 json_object_boolean_true_add(
12127 json_addr,
12128 "privateAsNumsAllRemovedInUpdatesToNbr");
12129 else if (CHECK_FLAG(p->af_flags[afi][safi],
12130 PEER_FLAG_REMOVE_PRIVATE_AS))
12131 json_object_boolean_true_add(
12132 json_addr,
12133 "privateAsNumsRemovedInUpdatesToNbr");
12134
12135 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12136 json_object_boolean_true_add(
12137 json_addr,
12138 bgp_addpath_names(p->addpath_type[afi][safi])
12139 ->type_json_name);
12140
12141 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12142 json_object_string_add(json_addr,
12143 "overrideASNsInOutboundUpdates",
12144 "ifAspathEqualRemoteAs");
12145
12146 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12147 || CHECK_FLAG(p->af_flags[afi][safi],
12148 PEER_FLAG_FORCE_NEXTHOP_SELF))
12149 json_object_boolean_true_add(json_addr,
12150 "routerAlwaysNextHop");
12151 if (CHECK_FLAG(p->af_flags[afi][safi],
12152 PEER_FLAG_AS_PATH_UNCHANGED))
12153 json_object_boolean_true_add(
12154 json_addr, "unchangedAsPathPropogatedToNbr");
12155 if (CHECK_FLAG(p->af_flags[afi][safi],
12156 PEER_FLAG_NEXTHOP_UNCHANGED))
12157 json_object_boolean_true_add(
12158 json_addr, "unchangedNextHopPropogatedToNbr");
12159 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12160 json_object_boolean_true_add(
12161 json_addr, "unchangedMedPropogatedToNbr");
12162 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12163 || CHECK_FLAG(p->af_flags[afi][safi],
12164 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12165 if (CHECK_FLAG(p->af_flags[afi][safi],
12166 PEER_FLAG_SEND_COMMUNITY)
12167 && CHECK_FLAG(p->af_flags[afi][safi],
12168 PEER_FLAG_SEND_EXT_COMMUNITY))
12169 json_object_string_add(json_addr,
12170 "commAttriSentToNbr",
12171 "extendedAndStandard");
12172 else if (CHECK_FLAG(p->af_flags[afi][safi],
12173 PEER_FLAG_SEND_EXT_COMMUNITY))
12174 json_object_string_add(json_addr,
12175 "commAttriSentToNbr",
12176 "extended");
12177 else
12178 json_object_string_add(json_addr,
12179 "commAttriSentToNbr",
12180 "standard");
12181 }
12182 if (CHECK_FLAG(p->af_flags[afi][safi],
12183 PEER_FLAG_DEFAULT_ORIGINATE)) {
12184 if (p->default_rmap[afi][safi].name)
12185 json_object_string_add(
12186 json_addr, "defaultRouteMap",
12187 p->default_rmap[afi][safi].name);
12188
12189 if (paf && PAF_SUBGRP(paf)
12190 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12191 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12192 json_object_boolean_true_add(json_addr,
12193 "defaultSent");
12194 else
12195 json_object_boolean_true_add(json_addr,
12196 "defaultNotSent");
12197 }
12198
12199 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12200 if (is_evpn_enabled())
12201 json_object_boolean_true_add(
12202 json_addr, "advertiseAllVnis");
12203 }
12204
12205 if (filter->plist[FILTER_IN].name
12206 || filter->dlist[FILTER_IN].name
12207 || filter->aslist[FILTER_IN].name
12208 || filter->map[RMAP_IN].name)
12209 json_object_boolean_true_add(json_addr,
12210 "inboundPathPolicyConfig");
12211 if (filter->plist[FILTER_OUT].name
12212 || filter->dlist[FILTER_OUT].name
12213 || filter->aslist[FILTER_OUT].name
12214 || filter->map[RMAP_OUT].name || filter->usmap.name)
12215 json_object_boolean_true_add(
12216 json_addr, "outboundPathPolicyConfig");
12217
12218 /* prefix-list */
12219 if (filter->plist[FILTER_IN].name)
12220 json_object_string_add(json_addr,
12221 "incomingUpdatePrefixFilterList",
12222 filter->plist[FILTER_IN].name);
12223 if (filter->plist[FILTER_OUT].name)
12224 json_object_string_add(json_addr,
12225 "outgoingUpdatePrefixFilterList",
12226 filter->plist[FILTER_OUT].name);
12227
12228 /* distribute-list */
12229 if (filter->dlist[FILTER_IN].name)
12230 json_object_string_add(
12231 json_addr, "incomingUpdateNetworkFilterList",
12232 filter->dlist[FILTER_IN].name);
12233 if (filter->dlist[FILTER_OUT].name)
12234 json_object_string_add(
12235 json_addr, "outgoingUpdateNetworkFilterList",
12236 filter->dlist[FILTER_OUT].name);
12237
12238 /* filter-list. */
12239 if (filter->aslist[FILTER_IN].name)
12240 json_object_string_add(json_addr,
12241 "incomingUpdateAsPathFilterList",
12242 filter->aslist[FILTER_IN].name);
12243 if (filter->aslist[FILTER_OUT].name)
12244 json_object_string_add(json_addr,
12245 "outgoingUpdateAsPathFilterList",
12246 filter->aslist[FILTER_OUT].name);
12247
12248 /* route-map. */
12249 if (filter->map[RMAP_IN].name)
12250 json_object_string_add(
12251 json_addr, "routeMapForIncomingAdvertisements",
12252 filter->map[RMAP_IN].name);
12253 if (filter->map[RMAP_OUT].name)
12254 json_object_string_add(
12255 json_addr, "routeMapForOutgoingAdvertisements",
12256 filter->map[RMAP_OUT].name);
12257
12258 /* ebgp-requires-policy (inbound) */
12259 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12260 && !bgp_inbound_policy_exists(p, filter))
12261 json_object_string_add(
12262 json_addr, "inboundEbgpRequiresPolicy",
12263 "Inbound updates discarded due to missing policy");
12264
12265 /* ebgp-requires-policy (outbound) */
12266 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12267 && (!bgp_outbound_policy_exists(p, filter)))
12268 json_object_string_add(
12269 json_addr, "outboundEbgpRequiresPolicy",
12270 "Outbound updates discarded due to missing policy");
12271
12272 /* unsuppress-map */
12273 if (filter->usmap.name)
12274 json_object_string_add(json_addr,
12275 "selectiveUnsuppressRouteMap",
12276 filter->usmap.name);
12277
12278 /* advertise-map */
12279 if (filter->advmap.aname) {
12280 json_advmap = json_object_new_object();
12281 json_object_string_add(json_advmap, "condition",
12282 filter->advmap.condition
12283 ? "EXIST"
12284 : "NON_EXIST");
12285 json_object_string_add(json_advmap, "conditionMap",
12286 filter->advmap.cname);
12287 json_object_string_add(json_advmap, "advertiseMap",
12288 filter->advmap.aname);
12289 json_object_string_add(
12290 json_advmap, "advertiseStatus",
12291 filter->advmap.update_type ==
12292 UPDATE_TYPE_ADVERTISE
12293 ? "Advertise"
12294 : "Withdraw");
12295 json_object_object_add(json_addr, "advertiseMap",
12296 json_advmap);
12297 }
12298
12299 /* Receive prefix count */
12300 json_object_int_add(json_addr, "acceptedPrefixCounter",
12301 p->pcount[afi][safi]);
12302 if (paf && PAF_SUBGRP(paf))
12303 json_object_int_add(json_addr, "sentPrefixCounter",
12304 (PAF_SUBGRP(paf))->scount);
12305
12306 /* Maximum prefix */
12307 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12308 json_object_int_add(json_addr, "prefixOutAllowedMax",
12309 p->pmax_out[afi][safi]);
12310
12311 /* Maximum prefix */
12312 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12313 json_object_int_add(json_addr, "prefixAllowedMax",
12314 p->pmax[afi][safi]);
12315 if (CHECK_FLAG(p->af_flags[afi][safi],
12316 PEER_FLAG_MAX_PREFIX_WARNING))
12317 json_object_boolean_true_add(
12318 json_addr, "prefixAllowedMaxWarning");
12319 json_object_int_add(json_addr,
12320 "prefixAllowedWarningThresh",
12321 p->pmax_threshold[afi][safi]);
12322 if (p->pmax_restart[afi][safi])
12323 json_object_int_add(
12324 json_addr,
12325 "prefixAllowedRestartIntervalMsecs",
12326 p->pmax_restart[afi][safi] * 60000);
12327 }
12328 json_object_object_add(json_neigh,
12329 get_afi_safi_str(afi, safi, true),
12330 json_addr);
12331
12332 } else {
12333 filter = &p->filter[afi][safi];
12334
12335 vty_out(vty, " For address family: %s\n",
12336 get_afi_safi_str(afi, safi, false));
12337
12338 if (peer_group_active(p))
12339 vty_out(vty, " %s peer-group member\n",
12340 p->group->name);
12341
12342 paf = peer_af_find(p, afi, safi);
12343 if (paf && PAF_SUBGRP(paf)) {
12344 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12345 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12346 vty_out(vty, " Packet Queue length %d\n",
12347 bpacket_queue_virtual_length(paf));
12348 } else {
12349 vty_out(vty, " Not part of any update group\n");
12350 }
12351 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12352 || CHECK_FLAG(p->af_cap[afi][safi],
12353 PEER_CAP_ORF_PREFIX_SM_RCV)
12354 || CHECK_FLAG(p->af_cap[afi][safi],
12355 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12356 || CHECK_FLAG(p->af_cap[afi][safi],
12357 PEER_CAP_ORF_PREFIX_RM_ADV)
12358 || CHECK_FLAG(p->af_cap[afi][safi],
12359 PEER_CAP_ORF_PREFIX_RM_RCV)
12360 || CHECK_FLAG(p->af_cap[afi][safi],
12361 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12362 vty_out(vty, " AF-dependant capabilities:\n");
12363
12364 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12365 || CHECK_FLAG(p->af_cap[afi][safi],
12366 PEER_CAP_ORF_PREFIX_SM_RCV)
12367 || CHECK_FLAG(p->af_cap[afi][safi],
12368 PEER_CAP_ORF_PREFIX_RM_ADV)
12369 || CHECK_FLAG(p->af_cap[afi][safi],
12370 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12371 vty_out(vty,
12372 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12373 ORF_TYPE_PREFIX);
12374 bgp_show_peer_afi_orf_cap(
12375 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12376 PEER_CAP_ORF_PREFIX_RM_ADV,
12377 PEER_CAP_ORF_PREFIX_SM_RCV,
12378 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12379 }
12380 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12381 || CHECK_FLAG(p->af_cap[afi][safi],
12382 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12383 || CHECK_FLAG(p->af_cap[afi][safi],
12384 PEER_CAP_ORF_PREFIX_RM_ADV)
12385 || CHECK_FLAG(p->af_cap[afi][safi],
12386 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12387 vty_out(vty,
12388 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12389 ORF_TYPE_PREFIX_OLD);
12390 bgp_show_peer_afi_orf_cap(
12391 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12392 PEER_CAP_ORF_PREFIX_RM_ADV,
12393 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12394 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12395 }
12396
12397 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12398 p->host, afi, safi);
12399 orf_pfx_count = prefix_bgp_show_prefix_list(
12400 NULL, afi, orf_pfx_name, use_json);
12401
12402 if (CHECK_FLAG(p->af_sflags[afi][safi],
12403 PEER_STATUS_ORF_PREFIX_SEND)
12404 || orf_pfx_count) {
12405 vty_out(vty, " Outbound Route Filter (ORF):");
12406 if (CHECK_FLAG(p->af_sflags[afi][safi],
12407 PEER_STATUS_ORF_PREFIX_SEND))
12408 vty_out(vty, " sent;");
12409 if (orf_pfx_count)
12410 vty_out(vty, " received (%d entries)",
12411 orf_pfx_count);
12412 vty_out(vty, "\n");
12413 }
12414 if (CHECK_FLAG(p->af_sflags[afi][safi],
12415 PEER_STATUS_ORF_WAIT_REFRESH))
12416 vty_out(vty,
12417 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12418
12419 if (CHECK_FLAG(p->af_flags[afi][safi],
12420 PEER_FLAG_REFLECTOR_CLIENT))
12421 vty_out(vty, " Route-Reflector Client\n");
12422 if (CHECK_FLAG(p->af_flags[afi][safi],
12423 PEER_FLAG_RSERVER_CLIENT))
12424 vty_out(vty, " Route-Server Client\n");
12425
12426 if (peer_af_flag_check(p, afi, safi, PEER_FLAG_ORR_GROUP))
12427 vty_out(vty, " ORR group (configured) : %s\n",
12428 p->orr_group_name[afi][safi]);
12429
12430 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12431 vty_out(vty,
12432 " Inbound soft reconfiguration allowed\n");
12433
12434 if (CHECK_FLAG(p->af_flags[afi][safi],
12435 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12436 vty_out(vty,
12437 " Private AS numbers (all) replaced in updates to this neighbor\n");
12438 else if (CHECK_FLAG(p->af_flags[afi][safi],
12439 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12440 vty_out(vty,
12441 " Private AS numbers replaced in updates to this neighbor\n");
12442 else if (CHECK_FLAG(p->af_flags[afi][safi],
12443 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12444 vty_out(vty,
12445 " Private AS numbers (all) removed in updates to this neighbor\n");
12446 else if (CHECK_FLAG(p->af_flags[afi][safi],
12447 PEER_FLAG_REMOVE_PRIVATE_AS))
12448 vty_out(vty,
12449 " Private AS numbers removed in updates to this neighbor\n");
12450
12451 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12452 vty_out(vty, " %s\n",
12453 bgp_addpath_names(p->addpath_type[afi][safi])
12454 ->human_description);
12455
12456 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12457 vty_out(vty,
12458 " Override ASNs in outbound updates if aspath equals remote-as\n");
12459
12460 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12461 || CHECK_FLAG(p->af_flags[afi][safi],
12462 PEER_FLAG_FORCE_NEXTHOP_SELF))
12463 vty_out(vty, " NEXT_HOP is always this router\n");
12464 if (CHECK_FLAG(p->af_flags[afi][safi],
12465 PEER_FLAG_AS_PATH_UNCHANGED))
12466 vty_out(vty,
12467 " AS_PATH is propagated unchanged to this neighbor\n");
12468 if (CHECK_FLAG(p->af_flags[afi][safi],
12469 PEER_FLAG_NEXTHOP_UNCHANGED))
12470 vty_out(vty,
12471 " NEXT_HOP is propagated unchanged to this neighbor\n");
12472 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12473 vty_out(vty,
12474 " MED is propagated unchanged to this neighbor\n");
12475 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12476 || CHECK_FLAG(p->af_flags[afi][safi],
12477 PEER_FLAG_SEND_EXT_COMMUNITY)
12478 || CHECK_FLAG(p->af_flags[afi][safi],
12479 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12480 vty_out(vty,
12481 " Community attribute sent to this neighbor");
12482 if (CHECK_FLAG(p->af_flags[afi][safi],
12483 PEER_FLAG_SEND_COMMUNITY)
12484 && CHECK_FLAG(p->af_flags[afi][safi],
12485 PEER_FLAG_SEND_EXT_COMMUNITY)
12486 && CHECK_FLAG(p->af_flags[afi][safi],
12487 PEER_FLAG_SEND_LARGE_COMMUNITY))
12488 vty_out(vty, "(all)\n");
12489 else if (CHECK_FLAG(p->af_flags[afi][safi],
12490 PEER_FLAG_SEND_LARGE_COMMUNITY))
12491 vty_out(vty, "(large)\n");
12492 else if (CHECK_FLAG(p->af_flags[afi][safi],
12493 PEER_FLAG_SEND_EXT_COMMUNITY))
12494 vty_out(vty, "(extended)\n");
12495 else
12496 vty_out(vty, "(standard)\n");
12497 }
12498 if (CHECK_FLAG(p->af_flags[afi][safi],
12499 PEER_FLAG_DEFAULT_ORIGINATE)) {
12500 vty_out(vty, " Default information originate,");
12501
12502 if (p->default_rmap[afi][safi].name)
12503 vty_out(vty, " default route-map %s%s,",
12504 p->default_rmap[afi][safi].map ? "*"
12505 : "",
12506 p->default_rmap[afi][safi].name);
12507 if (paf && PAF_SUBGRP(paf)
12508 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12509 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12510 vty_out(vty, " default sent\n");
12511 else
12512 vty_out(vty, " default not sent\n");
12513 }
12514
12515 /* advertise-vni-all */
12516 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12517 if (is_evpn_enabled())
12518 vty_out(vty, " advertise-all-vni\n");
12519 }
12520
12521 if (filter->plist[FILTER_IN].name
12522 || filter->dlist[FILTER_IN].name
12523 || filter->aslist[FILTER_IN].name
12524 || filter->map[RMAP_IN].name)
12525 vty_out(vty, " Inbound path policy configured\n");
12526 if (filter->plist[FILTER_OUT].name
12527 || filter->dlist[FILTER_OUT].name
12528 || filter->aslist[FILTER_OUT].name
12529 || filter->map[RMAP_OUT].name || filter->usmap.name)
12530 vty_out(vty, " Outbound path policy configured\n");
12531
12532 /* prefix-list */
12533 if (filter->plist[FILTER_IN].name)
12534 vty_out(vty,
12535 " Incoming update prefix filter list is %s%s\n",
12536 filter->plist[FILTER_IN].plist ? "*" : "",
12537 filter->plist[FILTER_IN].name);
12538 if (filter->plist[FILTER_OUT].name)
12539 vty_out(vty,
12540 " Outgoing update prefix filter list is %s%s\n",
12541 filter->plist[FILTER_OUT].plist ? "*" : "",
12542 filter->plist[FILTER_OUT].name);
12543
12544 /* distribute-list */
12545 if (filter->dlist[FILTER_IN].name)
12546 vty_out(vty,
12547 " Incoming update network filter list is %s%s\n",
12548 filter->dlist[FILTER_IN].alist ? "*" : "",
12549 filter->dlist[FILTER_IN].name);
12550 if (filter->dlist[FILTER_OUT].name)
12551 vty_out(vty,
12552 " Outgoing update network filter list is %s%s\n",
12553 filter->dlist[FILTER_OUT].alist ? "*" : "",
12554 filter->dlist[FILTER_OUT].name);
12555
12556 /* filter-list. */
12557 if (filter->aslist[FILTER_IN].name)
12558 vty_out(vty,
12559 " Incoming update AS path filter list is %s%s\n",
12560 filter->aslist[FILTER_IN].aslist ? "*" : "",
12561 filter->aslist[FILTER_IN].name);
12562 if (filter->aslist[FILTER_OUT].name)
12563 vty_out(vty,
12564 " Outgoing update AS path filter list is %s%s\n",
12565 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12566 filter->aslist[FILTER_OUT].name);
12567
12568 /* route-map. */
12569 if (filter->map[RMAP_IN].name)
12570 vty_out(vty,
12571 " Route map for incoming advertisements is %s%s\n",
12572 filter->map[RMAP_IN].map ? "*" : "",
12573 filter->map[RMAP_IN].name);
12574 if (filter->map[RMAP_OUT].name)
12575 vty_out(vty,
12576 " Route map for outgoing advertisements is %s%s\n",
12577 filter->map[RMAP_OUT].map ? "*" : "",
12578 filter->map[RMAP_OUT].name);
12579
12580 /* ebgp-requires-policy (inbound) */
12581 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12582 && !bgp_inbound_policy_exists(p, filter))
12583 vty_out(vty,
12584 " Inbound updates discarded due to missing policy\n");
12585
12586 /* ebgp-requires-policy (outbound) */
12587 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12588 && !bgp_outbound_policy_exists(p, filter))
12589 vty_out(vty,
12590 " Outbound updates discarded due to missing policy\n");
12591
12592 /* unsuppress-map */
12593 if (filter->usmap.name)
12594 vty_out(vty,
12595 " Route map for selective unsuppress is %s%s\n",
12596 filter->usmap.map ? "*" : "",
12597 filter->usmap.name);
12598
12599 /* advertise-map */
12600 if (filter->advmap.aname && filter->advmap.cname)
12601 vty_out(vty,
12602 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12603 filter->advmap.condition ? "EXIST"
12604 : "NON_EXIST",
12605 filter->advmap.cmap ? "*" : "",
12606 filter->advmap.cname,
12607 filter->advmap.amap ? "*" : "",
12608 filter->advmap.aname,
12609 filter->advmap.update_type ==
12610 UPDATE_TYPE_ADVERTISE
12611 ? "Advertise"
12612 : "Withdraw");
12613
12614 /* Receive prefix count */
12615 vty_out(vty, " %u accepted prefixes\n",
12616 p->pcount[afi][safi]);
12617
12618 /* maximum-prefix-out */
12619 if (CHECK_FLAG(p->af_flags[afi][safi],
12620 PEER_FLAG_MAX_PREFIX_OUT))
12621 vty_out(vty,
12622 " Maximum allowed prefixes sent %u\n",
12623 p->pmax_out[afi][safi]);
12624
12625 /* Maximum prefix */
12626 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12627 vty_out(vty,
12628 " Maximum prefixes allowed %u%s\n",
12629 p->pmax[afi][safi],
12630 CHECK_FLAG(p->af_flags[afi][safi],
12631 PEER_FLAG_MAX_PREFIX_WARNING)
12632 ? " (warning-only)"
12633 : "");
12634 vty_out(vty, " Threshold for warning message %d%%",
12635 p->pmax_threshold[afi][safi]);
12636 if (p->pmax_restart[afi][safi])
12637 vty_out(vty, ", restart interval %d min",
12638 p->pmax_restart[afi][safi]);
12639 vty_out(vty, "\n");
12640 }
12641
12642 vty_out(vty, "\n");
12643 }
12644 }
12645
12646 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12647 json_object *json)
12648 {
12649 struct bgp *bgp;
12650 char buf1[PREFIX2STR_BUFFER];
12651 char timebuf[BGP_UPTIME_LEN];
12652 char dn_flag[2];
12653 afi_t afi;
12654 safi_t safi;
12655 uint16_t i;
12656 uint8_t *msg;
12657 json_object *json_neigh = NULL;
12658 time_t epoch_tbuf;
12659 uint32_t sync_tcp_mss;
12660
12661 bgp = p->bgp;
12662
12663 if (use_json)
12664 json_neigh = json_object_new_object();
12665
12666 memset(dn_flag, '\0', sizeof(dn_flag));
12667 if (!p->conf_if && peer_dynamic_neighbor(p))
12668 dn_flag[0] = '*';
12669
12670 if (!use_json) {
12671 if (p->conf_if) /* Configured interface name. */
12672 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12673 &p->su);
12674 else /* Configured IP address. */
12675 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12676 p->host);
12677 }
12678
12679 if (use_json) {
12680 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12681 json_object_string_add(json_neigh, "bgpNeighborAddr",
12682 "none");
12683 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12684 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12685 "%pSU", &p->su);
12686
12687 json_object_int_add(json_neigh, "remoteAs", p->as);
12688
12689 if (p->change_local_as)
12690 json_object_int_add(json_neigh, "localAs",
12691 p->change_local_as);
12692 else
12693 json_object_int_add(json_neigh, "localAs", p->local_as);
12694
12695 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12696 json_object_boolean_true_add(json_neigh,
12697 "localAsNoPrepend");
12698
12699 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12700 json_object_boolean_true_add(json_neigh,
12701 "localAsReplaceAs");
12702 } else {
12703 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12704 || (p->as_type == AS_INTERNAL))
12705 vty_out(vty, "remote AS %u, ", p->as);
12706 else
12707 vty_out(vty, "remote AS Unspecified, ");
12708 vty_out(vty, "local AS %u%s%s, ",
12709 p->change_local_as ? p->change_local_as : p->local_as,
12710 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12711 ? " no-prepend"
12712 : "",
12713 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12714 ? " replace-as"
12715 : "");
12716 }
12717 /* peer type internal or confed-internal */
12718 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12719 if (use_json) {
12720 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12721 json_object_boolean_true_add(
12722 json_neigh, "nbrConfedInternalLink");
12723 else
12724 json_object_boolean_true_add(json_neigh,
12725 "nbrInternalLink");
12726 } else {
12727 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12728 vty_out(vty, "confed-internal link\n");
12729 else
12730 vty_out(vty, "internal link\n");
12731 }
12732 /* peer type external or confed-external */
12733 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12734 if (use_json) {
12735 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12736 json_object_boolean_true_add(
12737 json_neigh, "nbrConfedExternalLink");
12738 else
12739 json_object_boolean_true_add(json_neigh,
12740 "nbrExternalLink");
12741 } else {
12742 if (bgp_confederation_peers_check(bgp, p->as))
12743 vty_out(vty, "confed-external link\n");
12744 else
12745 vty_out(vty, "external link\n");
12746 }
12747 } else {
12748 if (use_json)
12749 json_object_boolean_true_add(json_neigh,
12750 "nbrUnspecifiedLink");
12751 else
12752 vty_out(vty, "unspecified link\n");
12753 }
12754
12755 /* Roles */
12756 if (use_json) {
12757 json_object_string_add(json_neigh, "localRole",
12758 bgp_get_name_by_role(p->local_role));
12759 json_object_string_add(json_neigh, "remoteRole",
12760 bgp_get_name_by_role(p->remote_role));
12761 } else {
12762 vty_out(vty, " Local Role: %s\n",
12763 bgp_get_name_by_role(p->local_role));
12764 vty_out(vty, " Remote Role: %s\n",
12765 bgp_get_name_by_role(p->remote_role));
12766 }
12767
12768
12769 /* Description. */
12770 if (p->desc) {
12771 if (use_json)
12772 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12773 else
12774 vty_out(vty, " Description: %s\n", p->desc);
12775 }
12776
12777 if (p->hostname) {
12778 if (use_json) {
12779 if (p->hostname)
12780 json_object_string_add(json_neigh, "hostname",
12781 p->hostname);
12782
12783 if (p->domainname)
12784 json_object_string_add(json_neigh, "domainname",
12785 p->domainname);
12786 } else {
12787 if (p->domainname && (p->domainname[0] != '\0'))
12788 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12789 p->domainname);
12790 else
12791 vty_out(vty, "Hostname: %s\n", p->hostname);
12792 }
12793 }
12794
12795 /* Peer-group */
12796 if (p->group) {
12797 if (use_json) {
12798 json_object_string_add(json_neigh, "peerGroup",
12799 p->group->name);
12800
12801 if (dn_flag[0]) {
12802 struct prefix prefix, *range = NULL;
12803
12804 if (sockunion2hostprefix(&(p->su), &prefix))
12805 range = peer_group_lookup_dynamic_neighbor_range(
12806 p->group, &prefix);
12807
12808 if (range) {
12809 json_object_string_addf(
12810 json_neigh,
12811 "peerSubnetRangeGroup", "%pFX",
12812 range);
12813 }
12814 }
12815 } else {
12816 vty_out(vty,
12817 " Member of peer-group %s for session parameters\n",
12818 p->group->name);
12819
12820 if (dn_flag[0]) {
12821 struct prefix prefix, *range = NULL;
12822
12823 if (sockunion2hostprefix(&(p->su), &prefix))
12824 range = peer_group_lookup_dynamic_neighbor_range(
12825 p->group, &prefix);
12826
12827 if (range) {
12828 vty_out(vty,
12829 " Belongs to the subnet range group: %pFX\n",
12830 range);
12831 }
12832 }
12833 }
12834 }
12835
12836 if (use_json) {
12837 /* Administrative shutdown. */
12838 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12839 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12840 json_object_boolean_true_add(json_neigh,
12841 "adminShutDown");
12842
12843 /* BGP Version. */
12844 json_object_int_add(json_neigh, "bgpVersion", 4);
12845 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12846 &p->remote_id);
12847 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12848 &bgp->router_id);
12849
12850 /* Confederation */
12851 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12852 && bgp_confederation_peers_check(bgp, p->as))
12853 json_object_boolean_true_add(json_neigh,
12854 "nbrCommonAdmin");
12855
12856 /* Status. */
12857 json_object_string_add(
12858 json_neigh, "bgpState",
12859 lookup_msg(bgp_status_msg, p->status, NULL));
12860
12861 if (peer_established(p)) {
12862 time_t uptime;
12863
12864 uptime = monotime(NULL);
12865 uptime -= p->uptime;
12866 epoch_tbuf = time(NULL) - uptime;
12867
12868 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12869 uptime * 1000);
12870 json_object_string_add(json_neigh, "bgpTimerUpString",
12871 peer_uptime(p->uptime, timebuf,
12872 BGP_UPTIME_LEN, 0,
12873 NULL));
12874 json_object_int_add(json_neigh,
12875 "bgpTimerUpEstablishedEpoch",
12876 epoch_tbuf);
12877 }
12878
12879 else if (p->status == Active) {
12880 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12881 json_object_string_add(json_neigh, "bgpStateIs",
12882 "passive");
12883 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12884 json_object_string_add(json_neigh, "bgpStateIs",
12885 "passiveNSF");
12886 }
12887
12888 /* read timer */
12889 time_t uptime;
12890 struct tm tm;
12891
12892 uptime = monotime(NULL);
12893 uptime -= p->readtime;
12894 gmtime_r(&uptime, &tm);
12895
12896 json_object_int_add(json_neigh, "bgpTimerLastRead",
12897 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12898 + (tm.tm_hour * 3600000));
12899
12900 uptime = monotime(NULL);
12901 uptime -= p->last_write;
12902 gmtime_r(&uptime, &tm);
12903
12904 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12905 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12906 + (tm.tm_hour * 3600000));
12907
12908 uptime = monotime(NULL);
12909 uptime -= p->update_time;
12910 gmtime_r(&uptime, &tm);
12911
12912 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12913 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12914 + (tm.tm_hour * 3600000));
12915
12916 /* Configured timer values. */
12917 json_object_int_add(json_neigh,
12918 "bgpTimerConfiguredHoldTimeMsecs",
12919 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12920 ? p->holdtime * 1000
12921 : bgp->default_holdtime * 1000);
12922 json_object_int_add(json_neigh,
12923 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12924 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12925 ? p->keepalive * 1000
12926 : bgp->default_keepalive * 1000);
12927 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12928 p->v_holdtime * 1000);
12929 json_object_int_add(json_neigh,
12930 "bgpTimerKeepAliveIntervalMsecs",
12931 p->v_keepalive * 1000);
12932 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12933 json_object_int_add(json_neigh,
12934 "bgpTimerDelayOpenTimeMsecs",
12935 p->v_delayopen * 1000);
12936 }
12937
12938 /* Configured and Synced tcp-mss value for peer */
12939 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12940 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12941 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12942 p->tcp_mss);
12943 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12944 sync_tcp_mss);
12945 }
12946
12947 /* Extended Optional Parameters Length for BGP OPEN Message */
12948 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12949 json_object_boolean_true_add(
12950 json_neigh, "extendedOptionalParametersLength");
12951 else
12952 json_object_boolean_false_add(
12953 json_neigh, "extendedOptionalParametersLength");
12954
12955 /* Conditional advertisements */
12956 json_object_int_add(
12957 json_neigh,
12958 "bgpTimerConfiguredConditionalAdvertisementsSec",
12959 bgp->condition_check_period);
12960 if (thread_is_scheduled(bgp->t_condition_check))
12961 json_object_int_add(
12962 json_neigh,
12963 "bgpTimerUntilConditionalAdvertisementsSec",
12964 thread_timer_remain_second(
12965 bgp->t_condition_check));
12966 } else {
12967 /* Administrative shutdown. */
12968 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12969 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12970 vty_out(vty, " Administratively shut down\n");
12971
12972 /* BGP Version. */
12973 vty_out(vty, " BGP version 4");
12974 vty_out(vty, ", remote router ID %s",
12975 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12976 vty_out(vty, ", local router ID %s\n",
12977 inet_ntop(AF_INET, &bgp->router_id, buf1,
12978 sizeof(buf1)));
12979
12980 /* Confederation */
12981 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12982 && bgp_confederation_peers_check(bgp, p->as))
12983 vty_out(vty,
12984 " Neighbor under common administration\n");
12985
12986 /* Status. */
12987 vty_out(vty, " BGP state = %s",
12988 lookup_msg(bgp_status_msg, p->status, NULL));
12989
12990 if (peer_established(p))
12991 vty_out(vty, ", up for %8s",
12992 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12993 0, NULL));
12994
12995 else if (p->status == Active) {
12996 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12997 vty_out(vty, " (passive)");
12998 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12999 vty_out(vty, " (NSF passive)");
13000 }
13001 vty_out(vty, "\n");
13002
13003 /* read timer */
13004 vty_out(vty, " Last read %s",
13005 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13006 NULL));
13007 vty_out(vty, ", Last write %s\n",
13008 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13009 NULL));
13010
13011 /* Configured timer values. */
13012 vty_out(vty,
13013 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13014 p->v_holdtime, p->v_keepalive);
13015 vty_out(vty, " Configured hold time is %d seconds",
13016 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13017 ? p->holdtime
13018 : bgp->default_holdtime);
13019 vty_out(vty, ", keepalive interval is %d seconds\n",
13020 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13021 ? p->keepalive
13022 : bgp->default_keepalive);
13023 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13024 vty_out(vty,
13025 " Configured DelayOpenTime is %d seconds\n",
13026 p->delayopen);
13027
13028 /* Configured and synced tcp-mss value for peer */
13029 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13030 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13031 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13032 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13033 }
13034
13035 /* Extended Optional Parameters Length for BGP OPEN Message */
13036 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13037 vty_out(vty,
13038 " Extended Optional Parameters Length is enabled\n");
13039
13040 /* Conditional advertisements */
13041 vty_out(vty,
13042 " Configured conditional advertisements interval is %d seconds\n",
13043 bgp->condition_check_period);
13044 if (thread_is_scheduled(bgp->t_condition_check))
13045 vty_out(vty,
13046 " Time until conditional advertisements begin is %lu seconds\n",
13047 thread_timer_remain_second(
13048 bgp->t_condition_check));
13049 }
13050 /* Capability. */
13051 if (peer_established(p) &&
13052 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13053 if (use_json) {
13054 json_object *json_cap = NULL;
13055
13056 json_cap = json_object_new_object();
13057
13058 /* AS4 */
13059 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13060 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13061 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13062 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13063 json_object_string_add(
13064 json_cap, "4byteAs",
13065 "advertisedAndReceived");
13066 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13067 json_object_string_add(json_cap,
13068 "4byteAs",
13069 "advertised");
13070 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13071 json_object_string_add(json_cap,
13072 "4byteAs",
13073 "received");
13074 }
13075
13076 /* Extended Message Support */
13077 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13078 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13079 json_object_string_add(json_cap,
13080 "extendedMessage",
13081 "advertisedAndReceived");
13082 else if (CHECK_FLAG(p->cap,
13083 PEER_CAP_EXTENDED_MESSAGE_ADV))
13084 json_object_string_add(json_cap,
13085 "extendedMessage",
13086 "advertised");
13087 else if (CHECK_FLAG(p->cap,
13088 PEER_CAP_EXTENDED_MESSAGE_RCV))
13089 json_object_string_add(json_cap,
13090 "extendedMessage",
13091 "received");
13092
13093 /* AddPath */
13094 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13095 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13096 json_object *json_add = NULL;
13097 const char *print_store;
13098
13099 json_add = json_object_new_object();
13100
13101 FOREACH_AFI_SAFI (afi, safi) {
13102 json_object *json_sub = NULL;
13103 json_sub = json_object_new_object();
13104 print_store = get_afi_safi_str(
13105 afi, safi, true);
13106
13107 if (CHECK_FLAG(
13108 p->af_cap[afi][safi],
13109 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13110 CHECK_FLAG(
13111 p->af_cap[afi][safi],
13112 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13113 if (CHECK_FLAG(
13114 p->af_cap[afi]
13115 [safi],
13116 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13117 CHECK_FLAG(
13118 p->af_cap[afi]
13119 [safi],
13120 PEER_CAP_ADDPATH_AF_TX_RCV))
13121 json_object_boolean_true_add(
13122 json_sub,
13123 "txAdvertisedAndReceived");
13124 else if (
13125 CHECK_FLAG(
13126 p->af_cap[afi]
13127 [safi],
13128 PEER_CAP_ADDPATH_AF_TX_ADV))
13129 json_object_boolean_true_add(
13130 json_sub,
13131 "txAdvertised");
13132 else if (
13133 CHECK_FLAG(
13134 p->af_cap[afi]
13135 [safi],
13136 PEER_CAP_ADDPATH_AF_TX_RCV))
13137 json_object_boolean_true_add(
13138 json_sub,
13139 "txReceived");
13140 }
13141
13142 if (CHECK_FLAG(
13143 p->af_cap[afi][safi],
13144 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13145 CHECK_FLAG(
13146 p->af_cap[afi][safi],
13147 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13148 if (CHECK_FLAG(
13149 p->af_cap[afi]
13150 [safi],
13151 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13152 CHECK_FLAG(
13153 p->af_cap[afi]
13154 [safi],
13155 PEER_CAP_ADDPATH_AF_RX_RCV))
13156 json_object_boolean_true_add(
13157 json_sub,
13158 "rxAdvertisedAndReceived");
13159 else if (
13160 CHECK_FLAG(
13161 p->af_cap[afi]
13162 [safi],
13163 PEER_CAP_ADDPATH_AF_RX_ADV))
13164 json_object_boolean_true_add(
13165 json_sub,
13166 "rxAdvertised");
13167 else if (
13168 CHECK_FLAG(
13169 p->af_cap[afi]
13170 [safi],
13171 PEER_CAP_ADDPATH_AF_RX_RCV))
13172 json_object_boolean_true_add(
13173 json_sub,
13174 "rxReceived");
13175 }
13176
13177 if (CHECK_FLAG(
13178 p->af_cap[afi][safi],
13179 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13180 CHECK_FLAG(
13181 p->af_cap[afi][safi],
13182 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13183 CHECK_FLAG(
13184 p->af_cap[afi][safi],
13185 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13186 CHECK_FLAG(
13187 p->af_cap[afi][safi],
13188 PEER_CAP_ADDPATH_AF_RX_RCV))
13189 json_object_object_add(
13190 json_add, print_store,
13191 json_sub);
13192 else
13193 json_object_free(json_sub);
13194 }
13195
13196 json_object_object_add(json_cap, "addPath",
13197 json_add);
13198 }
13199
13200 /* Dynamic */
13201 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13202 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13203 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13204 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13205 json_object_string_add(
13206 json_cap, "dynamic",
13207 "advertisedAndReceived");
13208 else if (CHECK_FLAG(p->cap,
13209 PEER_CAP_DYNAMIC_ADV))
13210 json_object_string_add(json_cap,
13211 "dynamic",
13212 "advertised");
13213 else if (CHECK_FLAG(p->cap,
13214 PEER_CAP_DYNAMIC_RCV))
13215 json_object_string_add(json_cap,
13216 "dynamic",
13217 "received");
13218 }
13219
13220 /* Role */
13221 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13222 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13223 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13224 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13225 json_object_string_add(
13226 json_cap, "role",
13227 "advertisedAndReceived");
13228 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13229 json_object_string_add(json_cap, "role",
13230 "advertised");
13231 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13232 json_object_string_add(json_cap, "role",
13233 "received");
13234 }
13235
13236 /* Extended nexthop */
13237 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13238 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13239 json_object *json_nxt = NULL;
13240 const char *print_store;
13241
13242
13243 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13244 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13245 json_object_string_add(
13246 json_cap, "extendedNexthop",
13247 "advertisedAndReceived");
13248 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13249 json_object_string_add(
13250 json_cap, "extendedNexthop",
13251 "advertised");
13252 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13253 json_object_string_add(
13254 json_cap, "extendedNexthop",
13255 "received");
13256
13257 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13258 json_nxt = json_object_new_object();
13259
13260 for (safi = SAFI_UNICAST;
13261 safi < SAFI_MAX; safi++) {
13262 if (CHECK_FLAG(
13263 p->af_cap[AFI_IP]
13264 [safi],
13265 PEER_CAP_ENHE_AF_RCV)) {
13266 print_store =
13267 get_afi_safi_str(
13268 AFI_IP,
13269 safi,
13270 true);
13271 json_object_string_add(
13272 json_nxt,
13273 print_store,
13274 "recieved"); /* misspelled for compatibility */
13275 }
13276 }
13277 json_object_object_add(
13278 json_cap,
13279 "extendedNexthopFamililesByPeer",
13280 json_nxt);
13281 }
13282 }
13283
13284 /* Long-lived Graceful Restart */
13285 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13286 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13287 json_object *json_llgr = NULL;
13288 const char *afi_safi_str;
13289
13290 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13291 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13292 json_object_string_add(
13293 json_cap,
13294 "longLivedGracefulRestart",
13295 "advertisedAndReceived");
13296 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13297 json_object_string_add(
13298 json_cap,
13299 "longLivedGracefulRestart",
13300 "advertised");
13301 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13302 json_object_string_add(
13303 json_cap,
13304 "longLivedGracefulRestart",
13305 "received");
13306
13307 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13308 json_llgr = json_object_new_object();
13309
13310 FOREACH_AFI_SAFI (afi, safi) {
13311 if (CHECK_FLAG(
13312 p->af_cap[afi]
13313 [safi],
13314 PEER_CAP_ENHE_AF_RCV)) {
13315 afi_safi_str =
13316 get_afi_safi_str(
13317 afi,
13318 safi,
13319 true);
13320 json_object_string_add(
13321 json_llgr,
13322 afi_safi_str,
13323 "received");
13324 }
13325 }
13326 json_object_object_add(
13327 json_cap,
13328 "longLivedGracefulRestartByPeer",
13329 json_llgr);
13330 }
13331 }
13332
13333 /* Route Refresh */
13334 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13335 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13336 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13337 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13338 (CHECK_FLAG(p->cap,
13339 PEER_CAP_REFRESH_NEW_RCV) ||
13340 CHECK_FLAG(p->cap,
13341 PEER_CAP_REFRESH_OLD_RCV))) {
13342 if (CHECK_FLAG(
13343 p->cap,
13344 PEER_CAP_REFRESH_OLD_RCV) &&
13345 CHECK_FLAG(
13346 p->cap,
13347 PEER_CAP_REFRESH_NEW_RCV))
13348 json_object_string_add(
13349 json_cap,
13350 "routeRefresh",
13351 "advertisedAndReceivedOldNew");
13352 else {
13353 if (CHECK_FLAG(
13354 p->cap,
13355 PEER_CAP_REFRESH_OLD_RCV))
13356 json_object_string_add(
13357 json_cap,
13358 "routeRefresh",
13359 "advertisedAndReceivedOld");
13360 else
13361 json_object_string_add(
13362 json_cap,
13363 "routeRefresh",
13364 "advertisedAndReceivedNew");
13365 }
13366 } else if (CHECK_FLAG(p->cap,
13367 PEER_CAP_REFRESH_ADV))
13368 json_object_string_add(json_cap,
13369 "routeRefresh",
13370 "advertised");
13371 else if (CHECK_FLAG(p->cap,
13372 PEER_CAP_REFRESH_NEW_RCV) ||
13373 CHECK_FLAG(p->cap,
13374 PEER_CAP_REFRESH_OLD_RCV))
13375 json_object_string_add(json_cap,
13376 "routeRefresh",
13377 "received");
13378 }
13379
13380 /* Enhanced Route Refresh */
13381 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13382 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13383 if (CHECK_FLAG(p->cap,
13384 PEER_CAP_ENHANCED_RR_ADV) &&
13385 CHECK_FLAG(p->cap,
13386 PEER_CAP_ENHANCED_RR_RCV))
13387 json_object_string_add(
13388 json_cap,
13389 "enhancedRouteRefresh",
13390 "advertisedAndReceived");
13391 else if (CHECK_FLAG(p->cap,
13392 PEER_CAP_ENHANCED_RR_ADV))
13393 json_object_string_add(
13394 json_cap,
13395 "enhancedRouteRefresh",
13396 "advertised");
13397 else if (CHECK_FLAG(p->cap,
13398 PEER_CAP_ENHANCED_RR_RCV))
13399 json_object_string_add(
13400 json_cap,
13401 "enhancedRouteRefresh",
13402 "received");
13403 }
13404
13405 /* Multiprotocol Extensions */
13406 json_object *json_multi = NULL;
13407
13408 json_multi = json_object_new_object();
13409
13410 FOREACH_AFI_SAFI (afi, safi) {
13411 if (p->afc_adv[afi][safi] ||
13412 p->afc_recv[afi][safi]) {
13413 json_object *json_exten = NULL;
13414 json_exten = json_object_new_object();
13415
13416 if (p->afc_adv[afi][safi] &&
13417 p->afc_recv[afi][safi])
13418 json_object_boolean_true_add(
13419 json_exten,
13420 "advertisedAndReceived");
13421 else if (p->afc_adv[afi][safi])
13422 json_object_boolean_true_add(
13423 json_exten,
13424 "advertised");
13425 else if (p->afc_recv[afi][safi])
13426 json_object_boolean_true_add(
13427 json_exten, "received");
13428
13429 json_object_object_add(
13430 json_multi,
13431 get_afi_safi_str(afi, safi,
13432 true),
13433 json_exten);
13434 }
13435 }
13436 json_object_object_add(json_cap,
13437 "multiprotocolExtensions",
13438 json_multi);
13439
13440 /* Hostname capabilities */
13441 json_object *json_hname = NULL;
13442
13443 json_hname = json_object_new_object();
13444
13445 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13446 json_object_string_add(
13447 json_hname, "advHostName",
13448 bgp->peer_self->hostname
13449 ? bgp->peer_self->hostname
13450 : "n/a");
13451 json_object_string_add(
13452 json_hname, "advDomainName",
13453 bgp->peer_self->domainname
13454 ? bgp->peer_self->domainname
13455 : "n/a");
13456 }
13457
13458
13459 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13460 json_object_string_add(
13461 json_hname, "rcvHostName",
13462 p->hostname ? p->hostname : "n/a");
13463 json_object_string_add(
13464 json_hname, "rcvDomainName",
13465 p->domainname ? p->domainname : "n/a");
13466 }
13467
13468 json_object_object_add(json_cap, "hostName",
13469 json_hname);
13470
13471 /* Graceful Restart */
13472 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13473 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13474 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13475 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13476 json_object_string_add(
13477 json_cap, "gracefulRestart",
13478 "advertisedAndReceived");
13479 else if (CHECK_FLAG(p->cap,
13480 PEER_CAP_RESTART_ADV))
13481 json_object_string_add(
13482 json_cap,
13483 "gracefulRestartCapability",
13484 "advertised");
13485 else if (CHECK_FLAG(p->cap,
13486 PEER_CAP_RESTART_RCV))
13487 json_object_string_add(
13488 json_cap,
13489 "gracefulRestartCapability",
13490 "received");
13491
13492 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13493 int restart_af_count = 0;
13494 json_object *json_restart = NULL;
13495 json_restart = json_object_new_object();
13496
13497 json_object_int_add(
13498 json_cap,
13499 "gracefulRestartRemoteTimerMsecs",
13500 p->v_gr_restart * 1000);
13501
13502 FOREACH_AFI_SAFI (afi, safi) {
13503 if (CHECK_FLAG(
13504 p->af_cap[afi]
13505 [safi],
13506 PEER_CAP_RESTART_AF_RCV)) {
13507 json_object *json_sub =
13508 NULL;
13509 json_sub =
13510 json_object_new_object();
13511
13512 if (CHECK_FLAG(
13513 p->af_cap
13514 [afi]
13515 [safi],
13516 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13517 json_object_boolean_true_add(
13518 json_sub,
13519 "preserved");
13520 restart_af_count++;
13521 json_object_object_add(
13522 json_restart,
13523 get_afi_safi_str(
13524 afi,
13525 safi,
13526 true),
13527 json_sub);
13528 }
13529 }
13530 if (!restart_af_count) {
13531 json_object_string_add(
13532 json_cap,
13533 "addressFamiliesByPeer",
13534 "none");
13535 json_object_free(json_restart);
13536 } else
13537 json_object_object_add(
13538 json_cap,
13539 "addressFamiliesByPeer",
13540 json_restart);
13541 }
13542 }
13543 json_object_object_add(
13544 json_neigh, "neighborCapabilities", json_cap);
13545 } else {
13546 vty_out(vty, " Neighbor capabilities:\n");
13547
13548 /* AS4 */
13549 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13550 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13551 vty_out(vty, " 4 Byte AS:");
13552 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13553 vty_out(vty, " advertised");
13554 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13555 vty_out(vty, " %sreceived",
13556 CHECK_FLAG(p->cap,
13557 PEER_CAP_AS4_ADV)
13558 ? "and "
13559 : "");
13560 vty_out(vty, "\n");
13561 }
13562
13563 /* Extended Message Support */
13564 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13565 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13566 vty_out(vty, " Extended Message:");
13567 if (CHECK_FLAG(p->cap,
13568 PEER_CAP_EXTENDED_MESSAGE_ADV))
13569 vty_out(vty, " advertised");
13570 if (CHECK_FLAG(p->cap,
13571 PEER_CAP_EXTENDED_MESSAGE_RCV))
13572 vty_out(vty, " %sreceived",
13573 CHECK_FLAG(
13574 p->cap,
13575 PEER_CAP_EXTENDED_MESSAGE_ADV)
13576 ? "and "
13577 : "");
13578 vty_out(vty, "\n");
13579 }
13580
13581 /* AddPath */
13582 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13583 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13584 vty_out(vty, " AddPath:\n");
13585
13586 FOREACH_AFI_SAFI (afi, safi) {
13587 if (CHECK_FLAG(
13588 p->af_cap[afi][safi],
13589 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13590 CHECK_FLAG(
13591 p->af_cap[afi][safi],
13592 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13593 vty_out(vty, " %s: TX ",
13594 get_afi_safi_str(
13595 afi, safi,
13596 false));
13597
13598 if (CHECK_FLAG(
13599 p->af_cap[afi]
13600 [safi],
13601 PEER_CAP_ADDPATH_AF_TX_ADV))
13602 vty_out(vty,
13603 "advertised");
13604
13605 if (CHECK_FLAG(
13606 p->af_cap[afi]
13607 [safi],
13608 PEER_CAP_ADDPATH_AF_TX_RCV))
13609 vty_out(vty,
13610 "%sreceived",
13611 CHECK_FLAG(
13612 p->af_cap
13613 [afi]
13614 [safi],
13615 PEER_CAP_ADDPATH_AF_TX_ADV)
13616 ? " and "
13617 : "");
13618
13619 vty_out(vty, "\n");
13620 }
13621
13622 if (CHECK_FLAG(
13623 p->af_cap[afi][safi],
13624 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13625 CHECK_FLAG(
13626 p->af_cap[afi][safi],
13627 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13628 vty_out(vty, " %s: RX ",
13629 get_afi_safi_str(
13630 afi, safi,
13631 false));
13632
13633 if (CHECK_FLAG(
13634 p->af_cap[afi]
13635 [safi],
13636 PEER_CAP_ADDPATH_AF_RX_ADV))
13637 vty_out(vty,
13638 "advertised");
13639
13640 if (CHECK_FLAG(
13641 p->af_cap[afi]
13642 [safi],
13643 PEER_CAP_ADDPATH_AF_RX_RCV))
13644 vty_out(vty,
13645 "%sreceived",
13646 CHECK_FLAG(
13647 p->af_cap
13648 [afi]
13649 [safi],
13650 PEER_CAP_ADDPATH_AF_RX_ADV)
13651 ? " and "
13652 : "");
13653
13654 vty_out(vty, "\n");
13655 }
13656 }
13657 }
13658
13659 /* Dynamic */
13660 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13661 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13662 vty_out(vty, " Dynamic:");
13663 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13664 vty_out(vty, " advertised");
13665 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13666 vty_out(vty, " %sreceived",
13667 CHECK_FLAG(p->cap,
13668 PEER_CAP_DYNAMIC_ADV)
13669 ? "and "
13670 : "");
13671 vty_out(vty, "\n");
13672 }
13673
13674 /* Role */
13675 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13676 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13677 vty_out(vty, " Role:");
13678 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13679 vty_out(vty, " advertised");
13680 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13681 vty_out(vty, " %sreceived",
13682 CHECK_FLAG(p->cap,
13683 PEER_CAP_ROLE_ADV)
13684 ? "and "
13685 : "");
13686 vty_out(vty, "\n");
13687 }
13688
13689 /* Extended nexthop */
13690 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13691 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13692 vty_out(vty, " Extended nexthop:");
13693 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13694 vty_out(vty, " advertised");
13695 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13696 vty_out(vty, " %sreceived",
13697 CHECK_FLAG(p->cap,
13698 PEER_CAP_ENHE_ADV)
13699 ? "and "
13700 : "");
13701 vty_out(vty, "\n");
13702
13703 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13704 vty_out(vty,
13705 " Address families by peer:\n ");
13706 for (safi = SAFI_UNICAST;
13707 safi < SAFI_MAX; safi++)
13708 if (CHECK_FLAG(
13709 p->af_cap[AFI_IP]
13710 [safi],
13711 PEER_CAP_ENHE_AF_RCV))
13712 vty_out(vty,
13713 " %s\n",
13714 get_afi_safi_str(
13715 AFI_IP,
13716 safi,
13717 false));
13718 }
13719 }
13720
13721 /* Long-lived Graceful Restart */
13722 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13723 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13724 vty_out(vty,
13725 " Long-lived Graceful Restart:");
13726 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13727 vty_out(vty, " advertised");
13728 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13729 vty_out(vty, " %sreceived",
13730 CHECK_FLAG(p->cap,
13731 PEER_CAP_LLGR_ADV)
13732 ? "and "
13733 : "");
13734 vty_out(vty, "\n");
13735
13736 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13737 vty_out(vty,
13738 " Address families by peer:\n");
13739 FOREACH_AFI_SAFI (afi, safi)
13740 if (CHECK_FLAG(
13741 p->af_cap[afi]
13742 [safi],
13743 PEER_CAP_LLGR_AF_RCV))
13744 vty_out(vty,
13745 " %s\n",
13746 get_afi_safi_str(
13747 afi,
13748 safi,
13749 false));
13750 }
13751 }
13752
13753 /* Route Refresh */
13754 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13755 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13756 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13757 vty_out(vty, " Route refresh:");
13758 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13759 vty_out(vty, " advertised");
13760 if (CHECK_FLAG(p->cap,
13761 PEER_CAP_REFRESH_NEW_RCV) ||
13762 CHECK_FLAG(p->cap,
13763 PEER_CAP_REFRESH_OLD_RCV))
13764 vty_out(vty, " %sreceived(%s)",
13765 CHECK_FLAG(p->cap,
13766 PEER_CAP_REFRESH_ADV)
13767 ? "and "
13768 : "",
13769 (CHECK_FLAG(
13770 p->cap,
13771 PEER_CAP_REFRESH_OLD_RCV) &&
13772 CHECK_FLAG(
13773 p->cap,
13774 PEER_CAP_REFRESH_NEW_RCV))
13775 ? "old & new"
13776 : CHECK_FLAG(
13777 p->cap,
13778 PEER_CAP_REFRESH_OLD_RCV)
13779 ? "old"
13780 : "new");
13781
13782 vty_out(vty, "\n");
13783 }
13784
13785 /* Enhanced Route Refresh */
13786 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13787 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13788 vty_out(vty, " Enhanced Route Refresh:");
13789 if (CHECK_FLAG(p->cap,
13790 PEER_CAP_ENHANCED_RR_ADV))
13791 vty_out(vty, " advertised");
13792 if (CHECK_FLAG(p->cap,
13793 PEER_CAP_ENHANCED_RR_RCV))
13794 vty_out(vty, " %sreceived",
13795 CHECK_FLAG(p->cap,
13796 PEER_CAP_REFRESH_ADV)
13797 ? "and "
13798 : "");
13799 vty_out(vty, "\n");
13800 }
13801
13802 /* Multiprotocol Extensions */
13803 FOREACH_AFI_SAFI (afi, safi)
13804 if (p->afc_adv[afi][safi] ||
13805 p->afc_recv[afi][safi]) {
13806 vty_out(vty, " Address Family %s:",
13807 get_afi_safi_str(afi, safi,
13808 false));
13809 if (p->afc_adv[afi][safi])
13810 vty_out(vty, " advertised");
13811 if (p->afc_recv[afi][safi])
13812 vty_out(vty, " %sreceived",
13813 p->afc_adv[afi][safi]
13814 ? "and "
13815 : "");
13816 vty_out(vty, "\n");
13817 }
13818
13819 /* Hostname capability */
13820 vty_out(vty, " Hostname Capability:");
13821
13822 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13823 vty_out(vty,
13824 " advertised (name: %s,domain name: %s)",
13825 bgp->peer_self->hostname
13826 ? bgp->peer_self->hostname
13827 : "n/a",
13828 bgp->peer_self->domainname
13829 ? bgp->peer_self->domainname
13830 : "n/a");
13831 } else {
13832 vty_out(vty, " not advertised");
13833 }
13834
13835 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13836 vty_out(vty,
13837 " received (name: %s,domain name: %s)",
13838 p->hostname ? p->hostname : "n/a",
13839 p->domainname ? p->domainname : "n/a");
13840 } else {
13841 vty_out(vty, " not received");
13842 }
13843
13844 vty_out(vty, "\n");
13845
13846 /* Graceful Restart */
13847 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13848 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13849 vty_out(vty,
13850 " Graceful Restart Capability:");
13851 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13852 vty_out(vty, " advertised");
13853 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13854 vty_out(vty, " %sreceived",
13855 CHECK_FLAG(p->cap,
13856 PEER_CAP_RESTART_ADV)
13857 ? "and "
13858 : "");
13859 vty_out(vty, "\n");
13860
13861 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13862 int restart_af_count = 0;
13863
13864 vty_out(vty,
13865 " Remote Restart timer is %d seconds\n",
13866 p->v_gr_restart);
13867 vty_out(vty,
13868 " Address families by peer:\n ");
13869
13870 FOREACH_AFI_SAFI (afi, safi)
13871 if (CHECK_FLAG(
13872 p->af_cap[afi]
13873 [safi],
13874 PEER_CAP_RESTART_AF_RCV)) {
13875 vty_out(vty, "%s%s(%s)",
13876 restart_af_count
13877 ? ", "
13878 : "",
13879 get_afi_safi_str(
13880 afi,
13881 safi,
13882 false),
13883 CHECK_FLAG(
13884 p->af_cap
13885 [afi]
13886 [safi],
13887 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13888 ? "preserved"
13889 : "not preserved");
13890 restart_af_count++;
13891 }
13892 if (!restart_af_count)
13893 vty_out(vty, "none");
13894 vty_out(vty, "\n");
13895 }
13896 } /* Graceful Restart */
13897 }
13898 }
13899
13900 /* graceful restart information */
13901 json_object *json_grace = NULL;
13902 json_object *json_grace_send = NULL;
13903 json_object *json_grace_recv = NULL;
13904 int eor_send_af_count = 0;
13905 int eor_receive_af_count = 0;
13906
13907 if (use_json) {
13908 json_grace = json_object_new_object();
13909 json_grace_send = json_object_new_object();
13910 json_grace_recv = json_object_new_object();
13911
13912 if ((peer_established(p)) &&
13913 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13914 FOREACH_AFI_SAFI (afi, safi) {
13915 if (CHECK_FLAG(p->af_sflags[afi][safi],
13916 PEER_STATUS_EOR_SEND)) {
13917 json_object_boolean_true_add(
13918 json_grace_send,
13919 get_afi_safi_str(afi, safi,
13920 true));
13921 eor_send_af_count++;
13922 }
13923 }
13924 FOREACH_AFI_SAFI (afi, safi) {
13925 if (CHECK_FLAG(p->af_sflags[afi][safi],
13926 PEER_STATUS_EOR_RECEIVED)) {
13927 json_object_boolean_true_add(
13928 json_grace_recv,
13929 get_afi_safi_str(afi, safi,
13930 true));
13931 eor_receive_af_count++;
13932 }
13933 }
13934 }
13935 json_object_object_add(json_grace, "endOfRibSend",
13936 json_grace_send);
13937 json_object_object_add(json_grace, "endOfRibRecv",
13938 json_grace_recv);
13939
13940
13941 if (p->t_gr_restart)
13942 json_object_int_add(
13943 json_grace, "gracefulRestartTimerMsecs",
13944 thread_timer_remain_second(p->t_gr_restart) *
13945 1000);
13946
13947 if (p->t_gr_stale)
13948 json_object_int_add(
13949 json_grace, "gracefulStalepathTimerMsecs",
13950 thread_timer_remain_second(p->t_gr_stale) *
13951 1000);
13952 /* more gr info in new format */
13953 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13954 json_object_object_add(json_neigh, "gracefulRestartInfo",
13955 json_grace);
13956 } else {
13957 vty_out(vty, " Graceful restart information:\n");
13958 if ((peer_established(p)) &&
13959 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13960
13961 vty_out(vty, " End-of-RIB send: ");
13962 FOREACH_AFI_SAFI (afi, safi) {
13963 if (CHECK_FLAG(p->af_sflags[afi][safi],
13964 PEER_STATUS_EOR_SEND)) {
13965 vty_out(vty, "%s%s",
13966 eor_send_af_count ? ", " : "",
13967 get_afi_safi_str(afi, safi,
13968 false));
13969 eor_send_af_count++;
13970 }
13971 }
13972 vty_out(vty, "\n");
13973 vty_out(vty, " End-of-RIB received: ");
13974 FOREACH_AFI_SAFI (afi, safi) {
13975 if (CHECK_FLAG(p->af_sflags[afi][safi],
13976 PEER_STATUS_EOR_RECEIVED)) {
13977 vty_out(vty, "%s%s",
13978 eor_receive_af_count ? ", "
13979 : "",
13980 get_afi_safi_str(afi, safi,
13981 false));
13982 eor_receive_af_count++;
13983 }
13984 }
13985 vty_out(vty, "\n");
13986 }
13987
13988 if (p->t_gr_restart)
13989 vty_out(vty,
13990 " The remaining time of restart timer is %ld\n",
13991 thread_timer_remain_second(p->t_gr_restart));
13992
13993 if (p->t_gr_stale)
13994 vty_out(vty,
13995 " The remaining time of stalepath timer is %ld\n",
13996 thread_timer_remain_second(p->t_gr_stale));
13997
13998 /* more gr info in new format */
13999 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
14000 }
14001
14002 if (use_json) {
14003 json_object *json_stat = NULL;
14004 json_stat = json_object_new_object();
14005 /* Packet counts. */
14006
14007 atomic_size_t outq_count, inq_count;
14008 outq_count = atomic_load_explicit(&p->obuf->count,
14009 memory_order_relaxed);
14010 inq_count = atomic_load_explicit(&p->ibuf->count,
14011 memory_order_relaxed);
14012
14013 json_object_int_add(json_stat, "depthInq",
14014 (unsigned long)inq_count);
14015 json_object_int_add(json_stat, "depthOutq",
14016 (unsigned long)outq_count);
14017 json_object_int_add(json_stat, "opensSent",
14018 atomic_load_explicit(&p->open_out,
14019 memory_order_relaxed));
14020 json_object_int_add(json_stat, "opensRecv",
14021 atomic_load_explicit(&p->open_in,
14022 memory_order_relaxed));
14023 json_object_int_add(json_stat, "notificationsSent",
14024 atomic_load_explicit(&p->notify_out,
14025 memory_order_relaxed));
14026 json_object_int_add(json_stat, "notificationsRecv",
14027 atomic_load_explicit(&p->notify_in,
14028 memory_order_relaxed));
14029 json_object_int_add(json_stat, "updatesSent",
14030 atomic_load_explicit(&p->update_out,
14031 memory_order_relaxed));
14032 json_object_int_add(json_stat, "updatesRecv",
14033 atomic_load_explicit(&p->update_in,
14034 memory_order_relaxed));
14035 json_object_int_add(json_stat, "keepalivesSent",
14036 atomic_load_explicit(&p->keepalive_out,
14037 memory_order_relaxed));
14038 json_object_int_add(json_stat, "keepalivesRecv",
14039 atomic_load_explicit(&p->keepalive_in,
14040 memory_order_relaxed));
14041 json_object_int_add(json_stat, "routeRefreshSent",
14042 atomic_load_explicit(&p->refresh_out,
14043 memory_order_relaxed));
14044 json_object_int_add(json_stat, "routeRefreshRecv",
14045 atomic_load_explicit(&p->refresh_in,
14046 memory_order_relaxed));
14047 json_object_int_add(json_stat, "capabilitySent",
14048 atomic_load_explicit(&p->dynamic_cap_out,
14049 memory_order_relaxed));
14050 json_object_int_add(json_stat, "capabilityRecv",
14051 atomic_load_explicit(&p->dynamic_cap_in,
14052 memory_order_relaxed));
14053 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14054 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14055 json_object_object_add(json_neigh, "messageStats", json_stat);
14056 } else {
14057 atomic_size_t outq_count, inq_count, open_out, open_in,
14058 notify_out, notify_in, update_out, update_in,
14059 keepalive_out, keepalive_in, refresh_out, refresh_in,
14060 dynamic_cap_out, dynamic_cap_in;
14061 outq_count = atomic_load_explicit(&p->obuf->count,
14062 memory_order_relaxed);
14063 inq_count = atomic_load_explicit(&p->ibuf->count,
14064 memory_order_relaxed);
14065 open_out = atomic_load_explicit(&p->open_out,
14066 memory_order_relaxed);
14067 open_in =
14068 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14069 notify_out = atomic_load_explicit(&p->notify_out,
14070 memory_order_relaxed);
14071 notify_in = atomic_load_explicit(&p->notify_in,
14072 memory_order_relaxed);
14073 update_out = atomic_load_explicit(&p->update_out,
14074 memory_order_relaxed);
14075 update_in = atomic_load_explicit(&p->update_in,
14076 memory_order_relaxed);
14077 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14078 memory_order_relaxed);
14079 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14080 memory_order_relaxed);
14081 refresh_out = atomic_load_explicit(&p->refresh_out,
14082 memory_order_relaxed);
14083 refresh_in = atomic_load_explicit(&p->refresh_in,
14084 memory_order_relaxed);
14085 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14086 memory_order_relaxed);
14087 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14088 memory_order_relaxed);
14089
14090 /* Packet counts. */
14091 vty_out(vty, " Message statistics:\n");
14092 vty_out(vty, " Inq depth is %zu\n", inq_count);
14093 vty_out(vty, " Outq depth is %zu\n", outq_count);
14094 vty_out(vty, " Sent Rcvd\n");
14095 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14096 open_in);
14097 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14098 notify_in);
14099 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14100 update_in);
14101 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14102 keepalive_in);
14103 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14104 refresh_in);
14105 vty_out(vty, " Capability: %10zu %10zu\n",
14106 dynamic_cap_out, dynamic_cap_in);
14107 vty_out(vty, " Total: %10u %10u\n",
14108 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14109 }
14110
14111 if (use_json) {
14112 /* advertisement-interval */
14113 json_object_int_add(json_neigh,
14114 "minBtwnAdvertisementRunsTimerMsecs",
14115 p->v_routeadv * 1000);
14116
14117 /* Update-source. */
14118 if (p->update_if || p->update_source) {
14119 if (p->update_if)
14120 json_object_string_add(json_neigh,
14121 "updateSource",
14122 p->update_if);
14123 else if (p->update_source)
14124 json_object_string_addf(json_neigh,
14125 "updateSource", "%pSU",
14126 p->update_source);
14127 }
14128 } else {
14129 /* advertisement-interval */
14130 vty_out(vty,
14131 " Minimum time between advertisement runs is %d seconds\n",
14132 p->v_routeadv);
14133
14134 /* Update-source. */
14135 if (p->update_if || p->update_source) {
14136 vty_out(vty, " Update source is ");
14137 if (p->update_if)
14138 vty_out(vty, "%s", p->update_if);
14139 else if (p->update_source)
14140 vty_out(vty, "%pSU", p->update_source);
14141 vty_out(vty, "\n");
14142 }
14143
14144 vty_out(vty, "\n");
14145 }
14146
14147 /* Address Family Information */
14148 json_object *json_hold = NULL;
14149
14150 if (use_json)
14151 json_hold = json_object_new_object();
14152
14153 FOREACH_AFI_SAFI (afi, safi)
14154 if (p->afc[afi][safi])
14155 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14156 json_hold);
14157
14158 if (use_json) {
14159 json_object_object_add(json_neigh, "addressFamilyInfo",
14160 json_hold);
14161 json_object_int_add(json_neigh, "connectionsEstablished",
14162 p->established);
14163 json_object_int_add(json_neigh, "connectionsDropped",
14164 p->dropped);
14165 } else
14166 vty_out(vty, " Connections established %d; dropped %d\n",
14167 p->established, p->dropped);
14168
14169 if (!p->last_reset) {
14170 if (use_json)
14171 json_object_string_add(json_neigh, "lastReset",
14172 "never");
14173 else
14174 vty_out(vty, " Last reset never\n");
14175 } else {
14176 if (use_json) {
14177 time_t uptime;
14178 struct tm tm;
14179
14180 uptime = monotime(NULL);
14181 uptime -= p->resettime;
14182 gmtime_r(&uptime, &tm);
14183
14184 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14185 (tm.tm_sec * 1000)
14186 + (tm.tm_min * 60000)
14187 + (tm.tm_hour * 3600000));
14188 bgp_show_peer_reset(NULL, p, json_neigh, true);
14189 } else {
14190 vty_out(vty, " Last reset %s, ",
14191 peer_uptime(p->resettime, timebuf,
14192 BGP_UPTIME_LEN, 0, NULL));
14193
14194 bgp_show_peer_reset(vty, p, NULL, false);
14195 if (p->last_reset_cause_size) {
14196 msg = p->last_reset_cause;
14197 vty_out(vty,
14198 " Message received that caused BGP to send a NOTIFICATION:\n ");
14199 for (i = 1; i <= p->last_reset_cause_size;
14200 i++) {
14201 vty_out(vty, "%02X", *msg++);
14202
14203 if (i != p->last_reset_cause_size) {
14204 if (i % 16 == 0) {
14205 vty_out(vty, "\n ");
14206 } else if (i % 4 == 0) {
14207 vty_out(vty, " ");
14208 }
14209 }
14210 }
14211 vty_out(vty, "\n");
14212 }
14213 }
14214 }
14215
14216 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14217 if (use_json)
14218 json_object_boolean_true_add(json_neigh,
14219 "prefixesConfigExceedMax");
14220 else
14221 vty_out(vty,
14222 " Peer had exceeded the max. no. of prefixes configured.\n");
14223
14224 if (p->t_pmax_restart) {
14225 if (use_json) {
14226 json_object_boolean_true_add(
14227 json_neigh, "reducePrefixNumFrom");
14228 json_object_int_add(json_neigh,
14229 "restartInTimerMsec",
14230 thread_timer_remain_second(
14231 p->t_pmax_restart)
14232 * 1000);
14233 } else
14234 vty_out(vty,
14235 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14236 p->host, thread_timer_remain_second(
14237 p->t_pmax_restart));
14238 } else {
14239 if (use_json)
14240 json_object_boolean_true_add(
14241 json_neigh,
14242 "reducePrefixNumAndClearIpBgp");
14243 else
14244 vty_out(vty,
14245 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14246 p->host);
14247 }
14248 }
14249
14250 /* EBGP Multihop and GTSM */
14251 if (p->sort != BGP_PEER_IBGP) {
14252 if (use_json) {
14253 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14254 json_object_int_add(json_neigh,
14255 "externalBgpNbrMaxHopsAway",
14256 p->gtsm_hops);
14257 else
14258 json_object_int_add(json_neigh,
14259 "externalBgpNbrMaxHopsAway",
14260 p->ttl);
14261 } else {
14262 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14263 vty_out(vty,
14264 " External BGP neighbor may be up to %d hops away.\n",
14265 p->gtsm_hops);
14266 else
14267 vty_out(vty,
14268 " External BGP neighbor may be up to %d hops away.\n",
14269 p->ttl);
14270 }
14271 } else {
14272 if (use_json) {
14273 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14274 json_object_int_add(json_neigh,
14275 "internalBgpNbrMaxHopsAway",
14276 p->gtsm_hops);
14277 else
14278 json_object_int_add(json_neigh,
14279 "internalBgpNbrMaxHopsAway",
14280 p->ttl);
14281 } else {
14282 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14283 vty_out(vty,
14284 " Internal BGP neighbor may be up to %d hops away.\n",
14285 p->gtsm_hops);
14286 else
14287 vty_out(vty,
14288 " Internal BGP neighbor may be up to %d hops away.\n",
14289 p->ttl);
14290 }
14291 }
14292
14293 /* Local address. */
14294 if (p->su_local) {
14295 if (use_json) {
14296 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14297 p->su_local);
14298 json_object_int_add(json_neigh, "portLocal",
14299 ntohs(p->su_local->sin.sin_port));
14300 } else
14301 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14302 p->su_local, ntohs(p->su_local->sin.sin_port));
14303 } else {
14304 if (use_json) {
14305 json_object_string_add(json_neigh, "hostLocal",
14306 "Unknown");
14307 json_object_int_add(json_neigh, "portLocal", -1);
14308 }
14309 }
14310
14311 /* Remote address. */
14312 if (p->su_remote) {
14313 if (use_json) {
14314 json_object_string_addf(json_neigh, "hostForeign",
14315 "%pSU", p->su_remote);
14316 json_object_int_add(json_neigh, "portForeign",
14317 ntohs(p->su_remote->sin.sin_port));
14318 } else
14319 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14320 p->su_remote,
14321 ntohs(p->su_remote->sin.sin_port));
14322 } else {
14323 if (use_json) {
14324 json_object_string_add(json_neigh, "hostForeign",
14325 "Unknown");
14326 json_object_int_add(json_neigh, "portForeign", -1);
14327 }
14328 }
14329
14330 /* Nexthop display. */
14331 if (p->su_local) {
14332 if (use_json) {
14333 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14334 &p->nexthop.v4);
14335 json_object_string_addf(json_neigh, "nexthopGlobal",
14336 "%pI6", &p->nexthop.v6_global);
14337 json_object_string_addf(json_neigh, "nexthopLocal",
14338 "%pI6", &p->nexthop.v6_local);
14339 if (p->shared_network)
14340 json_object_string_add(json_neigh,
14341 "bgpConnection",
14342 "sharedNetwork");
14343 else
14344 json_object_string_add(json_neigh,
14345 "bgpConnection",
14346 "nonSharedNetwork");
14347 } else {
14348 vty_out(vty, "Nexthop: %s\n",
14349 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14350 sizeof(buf1)));
14351 vty_out(vty, "Nexthop global: %s\n",
14352 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14353 sizeof(buf1)));
14354 vty_out(vty, "Nexthop local: %s\n",
14355 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14356 sizeof(buf1)));
14357 vty_out(vty, "BGP connection: %s\n",
14358 p->shared_network ? "shared network"
14359 : "non shared network");
14360 }
14361 }
14362
14363 /* Timer information. */
14364 if (use_json) {
14365 json_object_int_add(json_neigh, "connectRetryTimer",
14366 p->v_connect);
14367 if (peer_established(p) && p->rtt)
14368 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14369 p->rtt);
14370 if (p->t_start)
14371 json_object_int_add(
14372 json_neigh, "nextStartTimerDueInMsecs",
14373 thread_timer_remain_second(p->t_start) * 1000);
14374 if (p->t_connect)
14375 json_object_int_add(
14376 json_neigh, "nextConnectTimerDueInMsecs",
14377 thread_timer_remain_second(p->t_connect)
14378 * 1000);
14379 if (p->t_routeadv) {
14380 json_object_int_add(json_neigh, "mraiInterval",
14381 p->v_routeadv);
14382 json_object_int_add(
14383 json_neigh, "mraiTimerExpireInMsecs",
14384 thread_timer_remain_second(p->t_routeadv)
14385 * 1000);
14386 }
14387 if (p->password)
14388 json_object_int_add(json_neigh, "authenticationEnabled",
14389 1);
14390
14391 if (p->t_read)
14392 json_object_string_add(json_neigh, "readThread", "on");
14393 else
14394 json_object_string_add(json_neigh, "readThread", "off");
14395
14396 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14397 json_object_string_add(json_neigh, "writeThread", "on");
14398 else
14399 json_object_string_add(json_neigh, "writeThread",
14400 "off");
14401 } else {
14402 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14403 p->v_connect);
14404 if (peer_established(p) && p->rtt)
14405 vty_out(vty, "Estimated round trip time: %d ms\n",
14406 p->rtt);
14407 if (p->t_start)
14408 vty_out(vty, "Next start timer due in %ld seconds\n",
14409 thread_timer_remain_second(p->t_start));
14410 if (p->t_connect)
14411 vty_out(vty, "Next connect timer due in %ld seconds\n",
14412 thread_timer_remain_second(p->t_connect));
14413 if (p->t_routeadv)
14414 vty_out(vty,
14415 "MRAI (interval %u) timer expires in %ld seconds\n",
14416 p->v_routeadv,
14417 thread_timer_remain_second(p->t_routeadv));
14418 if (p->password)
14419 vty_out(vty, "Peer Authentication Enabled\n");
14420
14421 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14422 p->t_read ? "on" : "off",
14423 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14424 ? "on"
14425 : "off", p->fd);
14426 }
14427
14428 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14429 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14430 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14431
14432 if (!use_json)
14433 vty_out(vty, "\n");
14434
14435 /* BFD information. */
14436 if (p->bfd_config)
14437 bgp_bfd_show_info(vty, p, json_neigh);
14438
14439 if (use_json) {
14440 if (p->conf_if) /* Configured interface name. */
14441 json_object_object_add(json, p->conf_if, json_neigh);
14442 else /* Configured IP address. */
14443 json_object_object_add(json, p->host, json_neigh);
14444 }
14445 }
14446
14447 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14448 enum show_type type,
14449 union sockunion *su,
14450 const char *conf_if, afi_t afi,
14451 bool use_json)
14452 {
14453 struct listnode *node, *nnode;
14454 struct peer *peer;
14455 int find = 0;
14456 safi_t safi = SAFI_UNICAST;
14457 json_object *json = NULL;
14458 json_object *json_neighbor = NULL;
14459
14460 if (use_json) {
14461 json = json_object_new_object();
14462 json_neighbor = json_object_new_object();
14463 }
14464
14465 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14466
14467 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14468 continue;
14469
14470 if ((peer->afc[afi][safi]) == 0)
14471 continue;
14472
14473 if (type == show_all) {
14474 bgp_show_peer_gr_status(vty, peer, use_json,
14475 json_neighbor);
14476
14477 if (use_json) {
14478 json_object_object_add(json, peer->host,
14479 json_neighbor);
14480 json_neighbor = NULL;
14481 }
14482
14483 } else if (type == show_peer) {
14484 if (conf_if) {
14485 if ((peer->conf_if
14486 && !strcmp(peer->conf_if, conf_if))
14487 || (peer->hostname
14488 && !strcmp(peer->hostname, conf_if))) {
14489 find = 1;
14490 bgp_show_peer_gr_status(vty, peer,
14491 use_json,
14492 json_neighbor);
14493 }
14494 } else {
14495 if (sockunion_same(&peer->su, su)) {
14496 find = 1;
14497 bgp_show_peer_gr_status(vty, peer,
14498 use_json,
14499 json_neighbor);
14500 }
14501 }
14502 if (use_json && find)
14503 json_object_object_add(json, peer->host,
14504 json_neighbor);
14505 }
14506
14507 if (find) {
14508 json_neighbor = NULL;
14509 break;
14510 }
14511 }
14512
14513 if (type == show_peer && !find) {
14514 if (use_json)
14515 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14516 else
14517 vty_out(vty, "%% No such neighbor\n");
14518 }
14519 if (use_json) {
14520 if (json_neighbor)
14521 json_object_free(json_neighbor);
14522 vty_json(vty, json);
14523 } else {
14524 vty_out(vty, "\n");
14525 }
14526
14527 return CMD_SUCCESS;
14528 }
14529
14530 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14531 enum show_type type, union sockunion *su,
14532 const char *conf_if, bool use_json,
14533 json_object *json)
14534 {
14535 struct listnode *node, *nnode;
14536 struct peer *peer;
14537 int find = 0;
14538 bool nbr_output = false;
14539 afi_t afi = AFI_MAX;
14540 safi_t safi = SAFI_MAX;
14541
14542 if (type == show_ipv4_peer || type == show_ipv4_all) {
14543 afi = AFI_IP;
14544 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14545 afi = AFI_IP6;
14546 }
14547
14548 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14549 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14550 continue;
14551
14552 switch (type) {
14553 case show_all:
14554 bgp_show_peer(vty, peer, use_json, json);
14555 nbr_output = true;
14556 break;
14557 case show_peer:
14558 if (conf_if) {
14559 if ((peer->conf_if
14560 && !strcmp(peer->conf_if, conf_if))
14561 || (peer->hostname
14562 && !strcmp(peer->hostname, conf_if))) {
14563 find = 1;
14564 bgp_show_peer(vty, peer, use_json,
14565 json);
14566 }
14567 } else {
14568 if (sockunion_same(&peer->su, su)) {
14569 find = 1;
14570 bgp_show_peer(vty, peer, use_json,
14571 json);
14572 }
14573 }
14574 break;
14575 case show_ipv4_peer:
14576 case show_ipv6_peer:
14577 FOREACH_SAFI (safi) {
14578 if (peer->afc[afi][safi]) {
14579 if (conf_if) {
14580 if ((peer->conf_if
14581 && !strcmp(peer->conf_if, conf_if))
14582 || (peer->hostname
14583 && !strcmp(peer->hostname, conf_if))) {
14584 find = 1;
14585 bgp_show_peer(vty, peer, use_json,
14586 json);
14587 break;
14588 }
14589 } else {
14590 if (sockunion_same(&peer->su, su)) {
14591 find = 1;
14592 bgp_show_peer(vty, peer, use_json,
14593 json);
14594 break;
14595 }
14596 }
14597 }
14598 }
14599 break;
14600 case show_ipv4_all:
14601 case show_ipv6_all:
14602 FOREACH_SAFI (safi) {
14603 if (peer->afc[afi][safi]) {
14604 bgp_show_peer(vty, peer, use_json, json);
14605 nbr_output = true;
14606 break;
14607 }
14608 }
14609 break;
14610 }
14611 }
14612
14613 if ((type == show_peer || type == show_ipv4_peer ||
14614 type == show_ipv6_peer) && !find) {
14615 if (use_json)
14616 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14617 else
14618 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14619 }
14620
14621 if (type != show_peer && type != show_ipv4_peer &&
14622 type != show_ipv6_peer && !nbr_output && !use_json)
14623 vty_out(vty, "%% No BGP neighbors found\n");
14624
14625 if (use_json) {
14626 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14627 json, JSON_C_TO_STRING_PRETTY));
14628 } else {
14629 vty_out(vty, "\n");
14630 }
14631
14632 return CMD_SUCCESS;
14633 }
14634
14635 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14636 enum show_type type,
14637 const char *ip_str,
14638 afi_t afi, bool use_json)
14639 {
14640
14641 int ret;
14642 struct bgp *bgp;
14643 union sockunion su;
14644
14645 bgp = bgp_get_default();
14646
14647 if (!bgp)
14648 return;
14649
14650 if (!use_json)
14651 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14652 NULL);
14653
14654 if (ip_str) {
14655 ret = str2sockunion(ip_str, &su);
14656 if (ret < 0)
14657 bgp_show_neighbor_graceful_restart(
14658 vty, bgp, type, NULL, ip_str, afi, use_json);
14659 else
14660 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14661 NULL, afi, use_json);
14662 } else
14663 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14664 afi, use_json);
14665 }
14666
14667 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14668 enum show_type type,
14669 const char *ip_str,
14670 bool use_json)
14671 {
14672 struct listnode *node, *nnode;
14673 struct bgp *bgp;
14674 union sockunion su;
14675 json_object *json = NULL;
14676 int ret, is_first = 1;
14677 bool nbr_output = false;
14678
14679 if (use_json)
14680 vty_out(vty, "{\n");
14681
14682 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14683 nbr_output = true;
14684 if (use_json) {
14685 if (!(json = json_object_new_object())) {
14686 flog_err(
14687 EC_BGP_JSON_MEM_ERROR,
14688 "Unable to allocate memory for JSON object");
14689 vty_out(vty,
14690 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14691 return;
14692 }
14693
14694 json_object_int_add(json, "vrfId",
14695 (bgp->vrf_id == VRF_UNKNOWN)
14696 ? -1
14697 : (int64_t)bgp->vrf_id);
14698 json_object_string_add(
14699 json, "vrfName",
14700 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14701 ? VRF_DEFAULT_NAME
14702 : bgp->name);
14703
14704 if (!is_first)
14705 vty_out(vty, ",\n");
14706 else
14707 is_first = 0;
14708
14709 vty_out(vty, "\"%s\":",
14710 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14711 ? VRF_DEFAULT_NAME
14712 : bgp->name);
14713 } else {
14714 vty_out(vty, "\nInstance %s:\n",
14715 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14716 ? VRF_DEFAULT_NAME
14717 : bgp->name);
14718 }
14719
14720 if (type == show_peer || type == show_ipv4_peer ||
14721 type == show_ipv6_peer) {
14722 ret = str2sockunion(ip_str, &su);
14723 if (ret < 0)
14724 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14725 use_json, json);
14726 else
14727 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14728 use_json, json);
14729 } else {
14730 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14731 use_json, json);
14732 }
14733 json_object_free(json);
14734 json = NULL;
14735 }
14736
14737 if (use_json)
14738 vty_out(vty, "}\n");
14739 else if (!nbr_output)
14740 vty_out(vty, "%% BGP instance not found\n");
14741 }
14742
14743 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14744 enum show_type type, const char *ip_str,
14745 bool use_json)
14746 {
14747 int ret;
14748 struct bgp *bgp;
14749 union sockunion su;
14750 json_object *json = NULL;
14751
14752 if (name) {
14753 if (strmatch(name, "all")) {
14754 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14755 use_json);
14756 return CMD_SUCCESS;
14757 } else {
14758 bgp = bgp_lookup_by_name(name);
14759 if (!bgp) {
14760 if (use_json) {
14761 json = json_object_new_object();
14762 vty_json(vty, json);
14763 } else
14764 vty_out(vty,
14765 "%% BGP instance not found\n");
14766
14767 return CMD_WARNING;
14768 }
14769 }
14770 } else {
14771 bgp = bgp_get_default();
14772 }
14773
14774 if (bgp) {
14775 json = json_object_new_object();
14776 if (ip_str) {
14777 ret = str2sockunion(ip_str, &su);
14778 if (ret < 0)
14779 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14780 use_json, json);
14781 else
14782 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14783 use_json, json);
14784 } else {
14785 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14786 json);
14787 }
14788 json_object_free(json);
14789 } else {
14790 if (use_json)
14791 vty_out(vty, "{}\n");
14792 else
14793 vty_out(vty, "%% BGP instance not found\n");
14794 }
14795
14796 return CMD_SUCCESS;
14797 }
14798
14799
14800
14801 /* "show [ip] bgp neighbors graceful-restart" commands. */
14802 DEFUN (show_ip_bgp_neighbors_graceful_restart,
14803 show_ip_bgp_neighbors_graceful_restart_cmd,
14804 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14805 SHOW_STR
14806 BGP_STR
14807 IP_STR
14808 IPV6_STR
14809 NEIGHBOR_STR
14810 "Neighbor to display information about\n"
14811 "Neighbor to display information about\n"
14812 "Neighbor on BGP configured interface\n"
14813 GR_SHOW
14814 JSON_STR)
14815 {
14816 char *sh_arg = NULL;
14817 enum show_type sh_type;
14818 int idx = 0;
14819 afi_t afi = AFI_MAX;
14820 bool uj = use_json(argc, argv);
14821
14822 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14823 afi = AFI_MAX;
14824
14825 idx++;
14826
14827 if (argv_find(argv, argc, "A.B.C.D", &idx)
14828 || argv_find(argv, argc, "X:X::X:X", &idx)
14829 || argv_find(argv, argc, "WORD", &idx)) {
14830 sh_type = show_peer;
14831 sh_arg = argv[idx]->arg;
14832 } else
14833 sh_type = show_all;
14834
14835 if (!argv_find(argv, argc, "graceful-restart", &idx))
14836 return CMD_SUCCESS;
14837
14838
14839 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14840 afi, uj);
14841 }
14842
14843 /* "show [ip] bgp neighbors" commands. */
14844 DEFUN (show_ip_bgp_neighbors,
14845 show_ip_bgp_neighbors_cmd,
14846 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14847 SHOW_STR
14848 IP_STR
14849 BGP_STR
14850 BGP_INSTANCE_HELP_STR
14851 BGP_AF_STR
14852 BGP_AF_STR
14853 "Detailed information on TCP and BGP neighbor connections\n"
14854 "Neighbor to display information about\n"
14855 "Neighbor to display information about\n"
14856 "Neighbor on BGP configured interface\n"
14857 JSON_STR)
14858 {
14859 char *vrf = NULL;
14860 char *sh_arg = NULL;
14861 enum show_type sh_type;
14862 afi_t afi = AFI_MAX;
14863
14864 bool uj = use_json(argc, argv);
14865
14866 int idx = 0;
14867
14868 /* [<vrf> VIEWVRFNAME] */
14869 if (argv_find(argv, argc, "vrf", &idx)) {
14870 vrf = argv[idx + 1]->arg;
14871 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14872 vrf = NULL;
14873 } else if (argv_find(argv, argc, "view", &idx))
14874 /* [<view> VIEWVRFNAME] */
14875 vrf = argv[idx + 1]->arg;
14876
14877 idx++;
14878
14879 if (argv_find(argv, argc, "ipv4", &idx)) {
14880 sh_type = show_ipv4_all;
14881 afi = AFI_IP;
14882 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14883 sh_type = show_ipv6_all;
14884 afi = AFI_IP6;
14885 } else {
14886 sh_type = show_all;
14887 }
14888
14889 if (argv_find(argv, argc, "A.B.C.D", &idx)
14890 || argv_find(argv, argc, "X:X::X:X", &idx)
14891 || argv_find(argv, argc, "WORD", &idx)) {
14892 sh_type = show_peer;
14893 sh_arg = argv[idx]->arg;
14894 }
14895
14896 if (sh_type == show_peer && afi == AFI_IP) {
14897 sh_type = show_ipv4_peer;
14898 } else if (sh_type == show_peer && afi == AFI_IP6) {
14899 sh_type = show_ipv6_peer;
14900 }
14901
14902 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14903 }
14904
14905 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14906 paths' and `show ip mbgp paths'. Those functions results are the
14907 same.*/
14908 DEFUN (show_ip_bgp_paths,
14909 show_ip_bgp_paths_cmd,
14910 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14911 SHOW_STR
14912 IP_STR
14913 BGP_STR
14914 BGP_SAFI_HELP_STR
14915 "Path information\n")
14916 {
14917 vty_out(vty, "Address Refcnt Path\n");
14918 aspath_print_all_vty(vty);
14919 return CMD_SUCCESS;
14920 }
14921
14922 #include "hash.h"
14923
14924 static void community_show_all_iterator(struct hash_bucket *bucket,
14925 struct vty *vty)
14926 {
14927 struct community *com;
14928
14929 com = (struct community *)bucket->data;
14930 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14931 community_str(com, false, false));
14932 }
14933
14934 /* Show BGP's community internal data. */
14935 DEFUN (show_ip_bgp_community_info,
14936 show_ip_bgp_community_info_cmd,
14937 "show [ip] bgp community-info",
14938 SHOW_STR
14939 IP_STR
14940 BGP_STR
14941 "List all bgp community information\n")
14942 {
14943 vty_out(vty, "Address Refcnt Community\n");
14944
14945 hash_iterate(community_hash(),
14946 (void (*)(struct hash_bucket *,
14947 void *))community_show_all_iterator,
14948 vty);
14949
14950 return CMD_SUCCESS;
14951 }
14952
14953 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14954 struct vty *vty)
14955 {
14956 struct lcommunity *lcom;
14957
14958 lcom = (struct lcommunity *)bucket->data;
14959 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14960 lcommunity_str(lcom, false, false));
14961 }
14962
14963 /* Show BGP's community internal data. */
14964 DEFUN (show_ip_bgp_lcommunity_info,
14965 show_ip_bgp_lcommunity_info_cmd,
14966 "show ip bgp large-community-info",
14967 SHOW_STR
14968 IP_STR
14969 BGP_STR
14970 "List all bgp large-community information\n")
14971 {
14972 vty_out(vty, "Address Refcnt Large-community\n");
14973
14974 hash_iterate(lcommunity_hash(),
14975 (void (*)(struct hash_bucket *,
14976 void *))lcommunity_show_all_iterator,
14977 vty);
14978
14979 return CMD_SUCCESS;
14980 }
14981 /* Graceful Restart */
14982
14983 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14984 struct bgp *bgp,
14985 bool use_json,
14986 json_object *json)
14987 {
14988
14989
14990 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14991
14992 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14993
14994 switch (bgp_global_gr_mode) {
14995
14996 case GLOBAL_HELPER:
14997 vty_out(vty, "Global BGP GR Mode : Helper\n");
14998 break;
14999
15000 case GLOBAL_GR:
15001 vty_out(vty, "Global BGP GR Mode : Restart\n");
15002 break;
15003
15004 case GLOBAL_DISABLE:
15005 vty_out(vty, "Global BGP GR Mode : Disable\n");
15006 break;
15007
15008 case GLOBAL_INVALID:
15009 vty_out(vty,
15010 "Global BGP GR Mode Invalid\n");
15011 break;
15012 }
15013 vty_out(vty, "\n");
15014 }
15015
15016 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15017 enum show_type type,
15018 const char *ip_str,
15019 afi_t afi, bool use_json)
15020 {
15021 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15022 afi = AFI_IP;
15023
15024 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15025
15026 bgp_show_neighbor_graceful_restart_vty(
15027 vty, type, ip_str, afi, use_json);
15028 afi++;
15029 }
15030 } else if (afi != AFI_MAX) {
15031 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15032 use_json);
15033 } else {
15034 return CMD_ERR_INCOMPLETE;
15035 }
15036
15037 return CMD_SUCCESS;
15038 }
15039 /* Graceful Restart */
15040
15041 DEFUN (show_ip_bgp_attr_info,
15042 show_ip_bgp_attr_info_cmd,
15043 "show [ip] bgp attribute-info",
15044 SHOW_STR
15045 IP_STR
15046 BGP_STR
15047 "List all bgp attribute information\n")
15048 {
15049 attr_show_all(vty);
15050 return CMD_SUCCESS;
15051 }
15052
15053 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15054 afi_t afi, safi_t safi,
15055 bool use_json, json_object *json)
15056 {
15057 struct bgp *bgp;
15058 struct listnode *node;
15059 char *vname;
15060 char *ecom_str;
15061 enum vpn_policy_direction dir;
15062
15063 if (json) {
15064 json_object *json_import_vrfs = NULL;
15065 json_object *json_export_vrfs = NULL;
15066
15067 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15068
15069 if (!bgp) {
15070 vty_json(vty, json);
15071
15072 return CMD_WARNING;
15073 }
15074
15075 /* Provide context for the block */
15076 json_object_string_add(json, "vrf", name ? name : "default");
15077 json_object_string_add(json, "afiSafi",
15078 get_afi_safi_str(afi, safi, true));
15079
15080 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15081 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15082 json_object_string_add(json, "importFromVrfs", "none");
15083 json_object_string_add(json, "importRts", "none");
15084 } else {
15085 json_import_vrfs = json_object_new_array();
15086
15087 for (ALL_LIST_ELEMENTS_RO(
15088 bgp->vpn_policy[afi].import_vrf,
15089 node, vname))
15090 json_object_array_add(json_import_vrfs,
15091 json_object_new_string(vname));
15092
15093 json_object_object_add(json, "importFromVrfs",
15094 json_import_vrfs);
15095 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15096 if (bgp->vpn_policy[afi].rtlist[dir]) {
15097 ecom_str = ecommunity_ecom2str(
15098 bgp->vpn_policy[afi].rtlist[dir],
15099 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15100 json_object_string_add(json, "importRts",
15101 ecom_str);
15102 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15103 } else
15104 json_object_string_add(json, "importRts",
15105 "none");
15106 }
15107
15108 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15109 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15110 json_object_string_add(json, "exportToVrfs", "none");
15111 json_object_string_add(json, "routeDistinguisher",
15112 "none");
15113 json_object_string_add(json, "exportRts", "none");
15114 } else {
15115 json_export_vrfs = json_object_new_array();
15116
15117 for (ALL_LIST_ELEMENTS_RO(
15118 bgp->vpn_policy[afi].export_vrf,
15119 node, vname))
15120 json_object_array_add(json_export_vrfs,
15121 json_object_new_string(vname));
15122 json_object_object_add(json, "exportToVrfs",
15123 json_export_vrfs);
15124 json_object_string_addf(json, "routeDistinguisher",
15125 "%pRD",
15126 &bgp->vpn_policy[afi].tovpn_rd);
15127
15128 dir = BGP_VPN_POLICY_DIR_TOVPN;
15129 if (bgp->vpn_policy[afi].rtlist[dir]) {
15130 ecom_str = ecommunity_ecom2str(
15131 bgp->vpn_policy[afi].rtlist[dir],
15132 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15133 json_object_string_add(json, "exportRts",
15134 ecom_str);
15135 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15136 } else
15137 json_object_string_add(json, "exportRts",
15138 "none");
15139 }
15140
15141 if (use_json) {
15142 vty_json(vty, json);
15143 }
15144 } else {
15145 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15146
15147 if (!bgp) {
15148 vty_out(vty, "%% No such BGP instance exist\n");
15149 return CMD_WARNING;
15150 }
15151
15152 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15153 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15154 vty_out(vty,
15155 "This VRF is not importing %s routes from any other VRF\n",
15156 get_afi_safi_str(afi, safi, false));
15157 else {
15158 vty_out(vty,
15159 "This VRF is importing %s routes from the following VRFs:\n",
15160 get_afi_safi_str(afi, safi, false));
15161
15162 for (ALL_LIST_ELEMENTS_RO(
15163 bgp->vpn_policy[afi].import_vrf,
15164 node, vname))
15165 vty_out(vty, " %s\n", vname);
15166
15167 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15168 ecom_str = NULL;
15169 if (bgp->vpn_policy[afi].rtlist[dir]) {
15170 ecom_str = ecommunity_ecom2str(
15171 bgp->vpn_policy[afi].rtlist[dir],
15172 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15173 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15174
15175 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15176 } else
15177 vty_out(vty, "Import RT(s):\n");
15178 }
15179
15180 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15181 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15182 vty_out(vty,
15183 "This VRF is not exporting %s routes to any other VRF\n",
15184 get_afi_safi_str(afi, safi, false));
15185 else {
15186 vty_out(vty,
15187 "This VRF is exporting %s routes to the following VRFs:\n",
15188 get_afi_safi_str(afi, safi, false));
15189
15190 for (ALL_LIST_ELEMENTS_RO(
15191 bgp->vpn_policy[afi].export_vrf,
15192 node, vname))
15193 vty_out(vty, " %s\n", vname);
15194
15195 vty_out(vty, "RD: %pRD\n",
15196 &bgp->vpn_policy[afi].tovpn_rd);
15197
15198 dir = BGP_VPN_POLICY_DIR_TOVPN;
15199 if (bgp->vpn_policy[afi].rtlist[dir]) {
15200 ecom_str = ecommunity_ecom2str(
15201 bgp->vpn_policy[afi].rtlist[dir],
15202 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15203 vty_out(vty, "Export RT: %s\n", ecom_str);
15204 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15205 } else
15206 vty_out(vty, "Import RT(s):\n");
15207 }
15208 }
15209
15210 return CMD_SUCCESS;
15211 }
15212
15213 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15214 safi_t safi, bool use_json)
15215 {
15216 struct listnode *node, *nnode;
15217 struct bgp *bgp;
15218 char *vrf_name = NULL;
15219 json_object *json = NULL;
15220 json_object *json_vrf = NULL;
15221 json_object *json_vrfs = NULL;
15222
15223 if (use_json) {
15224 json = json_object_new_object();
15225 json_vrfs = json_object_new_object();
15226 }
15227
15228 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15229
15230 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15231 vrf_name = bgp->name;
15232
15233 if (use_json) {
15234 json_vrf = json_object_new_object();
15235 } else {
15236 vty_out(vty, "\nInstance %s:\n",
15237 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15238 ? VRF_DEFAULT_NAME : bgp->name);
15239 }
15240 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15241 if (use_json) {
15242 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15243 json_object_object_add(json_vrfs,
15244 VRF_DEFAULT_NAME, json_vrf);
15245 else
15246 json_object_object_add(json_vrfs, vrf_name,
15247 json_vrf);
15248 }
15249 }
15250
15251 if (use_json) {
15252 json_object_object_add(json, "vrfs", json_vrfs);
15253 vty_json(vty, json);
15254 }
15255
15256 return CMD_SUCCESS;
15257 }
15258
15259 /* "show [ip] bgp route-leak" command. */
15260 DEFUN (show_ip_bgp_route_leak,
15261 show_ip_bgp_route_leak_cmd,
15262 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15263 SHOW_STR
15264 IP_STR
15265 BGP_STR
15266 BGP_INSTANCE_HELP_STR
15267 BGP_AFI_HELP_STR
15268 BGP_SAFI_HELP_STR
15269 "Route leaking information\n"
15270 JSON_STR)
15271 {
15272 char *vrf = NULL;
15273 afi_t afi = AFI_MAX;
15274 safi_t safi = SAFI_MAX;
15275
15276 bool uj = use_json(argc, argv);
15277 int idx = 0;
15278 json_object *json = NULL;
15279
15280 /* show [ip] bgp */
15281 if (argv_find(argv, argc, "ip", &idx)) {
15282 afi = AFI_IP;
15283 safi = SAFI_UNICAST;
15284 }
15285 /* [vrf VIEWVRFNAME] */
15286 if (argv_find(argv, argc, "view", &idx)) {
15287 vty_out(vty,
15288 "%% This command is not applicable to BGP views\n");
15289 return CMD_WARNING;
15290 }
15291
15292 if (argv_find(argv, argc, "vrf", &idx)) {
15293 vrf = argv[idx + 1]->arg;
15294 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15295 vrf = NULL;
15296 }
15297 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15298 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15299 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15300
15301 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15302 vty_out(vty,
15303 "%% This command is applicable only for unicast ipv4|ipv6\n");
15304 return CMD_WARNING;
15305 }
15306
15307 if (vrf && strmatch(vrf, "all"))
15308 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15309
15310 if (uj)
15311 json = json_object_new_object();
15312
15313 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15314 }
15315
15316 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15317 safi_t safi)
15318 {
15319 struct listnode *node, *nnode;
15320 struct bgp *bgp;
15321
15322 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15323 vty_out(vty, "\nInstance %s:\n",
15324 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15325 ? VRF_DEFAULT_NAME
15326 : bgp->name);
15327 update_group_show(bgp, afi, safi, vty, 0);
15328 }
15329 }
15330
15331 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15332 int safi, uint64_t subgrp_id)
15333 {
15334 struct bgp *bgp;
15335
15336 if (name) {
15337 if (strmatch(name, "all")) {
15338 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15339 return CMD_SUCCESS;
15340 } else {
15341 bgp = bgp_lookup_by_name(name);
15342 }
15343 } else {
15344 bgp = bgp_get_default();
15345 }
15346
15347 if (bgp)
15348 update_group_show(bgp, afi, safi, vty, subgrp_id);
15349 return CMD_SUCCESS;
15350 }
15351
15352 DEFUN (show_ip_bgp_updgrps,
15353 show_ip_bgp_updgrps_cmd,
15354 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15355 SHOW_STR
15356 IP_STR
15357 BGP_STR
15358 BGP_INSTANCE_HELP_STR
15359 BGP_AFI_HELP_STR
15360 BGP_SAFI_WITH_LABEL_HELP_STR
15361 "Detailed info about dynamic update groups\n"
15362 "Specific subgroup to display detailed info for\n")
15363 {
15364 char *vrf = NULL;
15365 afi_t afi = AFI_IP6;
15366 safi_t safi = SAFI_UNICAST;
15367 uint64_t subgrp_id = 0;
15368
15369 int idx = 0;
15370
15371 /* show [ip] bgp */
15372 if (argv_find(argv, argc, "ip", &idx))
15373 afi = AFI_IP;
15374 /* [<vrf> VIEWVRFNAME] */
15375 if (argv_find(argv, argc, "vrf", &idx)) {
15376 vrf = argv[idx + 1]->arg;
15377 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15378 vrf = NULL;
15379 } else if (argv_find(argv, argc, "view", &idx))
15380 /* [<view> VIEWVRFNAME] */
15381 vrf = argv[idx + 1]->arg;
15382 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15383 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15384 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15385 }
15386
15387 /* get subgroup id, if provided */
15388 idx = argc - 1;
15389 if (argv[idx]->type == VARIABLE_TKN)
15390 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15391
15392 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15393 }
15394
15395 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15396 show_bgp_instance_all_ipv6_updgrps_cmd,
15397 "show [ip] bgp <view|vrf> all update-groups",
15398 SHOW_STR
15399 IP_STR
15400 BGP_STR
15401 BGP_INSTANCE_ALL_HELP_STR
15402 "Detailed info about dynamic update groups\n")
15403 {
15404 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15405 return CMD_SUCCESS;
15406 }
15407
15408 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15409 show_bgp_l2vpn_evpn_updgrps_cmd,
15410 "show [ip] bgp l2vpn evpn update-groups",
15411 SHOW_STR
15412 IP_STR
15413 BGP_STR
15414 "l2vpn address family\n"
15415 "evpn sub-address family\n"
15416 "Detailed info about dynamic update groups\n")
15417 {
15418 char *vrf = NULL;
15419 uint64_t subgrp_id = 0;
15420
15421 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15422 return CMD_SUCCESS;
15423 }
15424
15425 DEFUN (show_bgp_updgrps_stats,
15426 show_bgp_updgrps_stats_cmd,
15427 "show [ip] bgp update-groups statistics",
15428 SHOW_STR
15429 IP_STR
15430 BGP_STR
15431 "Detailed info about dynamic update groups\n"
15432 "Statistics\n")
15433 {
15434 struct bgp *bgp;
15435
15436 bgp = bgp_get_default();
15437 if (bgp)
15438 update_group_show_stats(bgp, vty);
15439
15440 return CMD_SUCCESS;
15441 }
15442
15443 DEFUN (show_bgp_instance_updgrps_stats,
15444 show_bgp_instance_updgrps_stats_cmd,
15445 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15446 SHOW_STR
15447 IP_STR
15448 BGP_STR
15449 BGP_INSTANCE_HELP_STR
15450 "Detailed info about dynamic update groups\n"
15451 "Statistics\n")
15452 {
15453 int idx_word = 3;
15454 struct bgp *bgp;
15455
15456 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15457 if (bgp)
15458 update_group_show_stats(bgp, vty);
15459
15460 return CMD_SUCCESS;
15461 }
15462
15463 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15464 afi_t afi, safi_t safi,
15465 const char *what, uint64_t subgrp_id)
15466 {
15467 struct bgp *bgp;
15468
15469 if (name)
15470 bgp = bgp_lookup_by_name(name);
15471 else
15472 bgp = bgp_get_default();
15473
15474 if (bgp) {
15475 if (!strcmp(what, "advertise-queue"))
15476 update_group_show_adj_queue(bgp, afi, safi, vty,
15477 subgrp_id);
15478 else if (!strcmp(what, "advertised-routes"))
15479 update_group_show_advertised(bgp, afi, safi, vty,
15480 subgrp_id);
15481 else if (!strcmp(what, "packet-queue"))
15482 update_group_show_packet_queue(bgp, afi, safi, vty,
15483 subgrp_id);
15484 }
15485 }
15486
15487 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15488 show_ip_bgp_instance_updgrps_adj_s_cmd,
15489 "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",
15490 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15491 BGP_SAFI_HELP_STR
15492 "Detailed info about dynamic update groups\n"
15493 "Specific subgroup to display info for\n"
15494 "Advertisement queue\n"
15495 "Announced routes\n"
15496 "Packet queue\n")
15497 {
15498 uint64_t subgrp_id = 0;
15499 afi_t afiz;
15500 safi_t safiz;
15501 if (sgid)
15502 subgrp_id = strtoull(sgid, NULL, 10);
15503
15504 if (!ip && !afi)
15505 afiz = AFI_IP6;
15506 if (!ip && afi)
15507 afiz = bgp_vty_afi_from_str(afi);
15508 if (ip && !afi)
15509 afiz = AFI_IP;
15510 if (ip && afi) {
15511 afiz = bgp_vty_afi_from_str(afi);
15512 if (afiz != AFI_IP)
15513 vty_out(vty,
15514 "%% Cannot specify both 'ip' and 'ipv6'\n");
15515 return CMD_WARNING;
15516 }
15517
15518 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15519
15520 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15521 return CMD_SUCCESS;
15522 }
15523
15524 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15525 json_object *json)
15526 {
15527 struct listnode *node, *nnode;
15528 struct prefix *range;
15529 struct peer *conf;
15530 struct peer *peer;
15531 afi_t afi;
15532 safi_t safi;
15533 const char *peer_status;
15534 int lr_count;
15535 int dynamic;
15536 bool af_cfgd;
15537 json_object *json_peer_group = NULL;
15538 json_object *json_peer_group_afc = NULL;
15539 json_object *json_peer_group_members = NULL;
15540 json_object *json_peer_group_dynamic = NULL;
15541 json_object *json_peer_group_dynamic_af = NULL;
15542 json_object *json_peer_group_ranges = NULL;
15543
15544 conf = group->conf;
15545
15546 if (json) {
15547 json_peer_group = json_object_new_object();
15548 json_peer_group_afc = json_object_new_array();
15549 }
15550
15551 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15552 if (json)
15553 json_object_int_add(json_peer_group, "remoteAs",
15554 conf->as);
15555 else
15556 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15557 group->name, conf->as);
15558 } else if (conf->as_type == AS_INTERNAL) {
15559 if (json)
15560 json_object_int_add(json_peer_group, "remoteAs",
15561 group->bgp->as);
15562 else
15563 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15564 group->name, group->bgp->as);
15565 } else {
15566 if (!json)
15567 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15568 }
15569
15570 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15571 if (json)
15572 json_object_string_add(json_peer_group, "type",
15573 "internal");
15574 else
15575 vty_out(vty, " Peer-group type is internal\n");
15576 } else {
15577 if (json)
15578 json_object_string_add(json_peer_group, "type",
15579 "external");
15580 else
15581 vty_out(vty, " Peer-group type is external\n");
15582 }
15583
15584 /* Display AFs configured. */
15585 if (!json)
15586 vty_out(vty, " Configured address-families:");
15587
15588 FOREACH_AFI_SAFI (afi, safi) {
15589 if (conf->afc[afi][safi]) {
15590 af_cfgd = true;
15591 if (json)
15592 json_object_array_add(
15593 json_peer_group_afc,
15594 json_object_new_string(get_afi_safi_str(
15595 afi, safi, false)));
15596 else
15597 vty_out(vty, " %s;",
15598 get_afi_safi_str(afi, safi, false));
15599 }
15600 }
15601
15602 if (json) {
15603 json_object_object_add(json_peer_group,
15604 "addressFamiliesConfigured",
15605 json_peer_group_afc);
15606 } else {
15607 if (!af_cfgd)
15608 vty_out(vty, " none\n");
15609 else
15610 vty_out(vty, "\n");
15611 }
15612
15613 /* Display listen ranges (for dynamic neighbors), if any */
15614 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15615 lr_count = listcount(group->listen_range[afi]);
15616 if (lr_count) {
15617 if (json) {
15618 if (!json_peer_group_dynamic)
15619 json_peer_group_dynamic =
15620 json_object_new_object();
15621
15622 json_peer_group_dynamic_af =
15623 json_object_new_object();
15624 json_peer_group_ranges =
15625 json_object_new_array();
15626 json_object_int_add(json_peer_group_dynamic_af,
15627 "count", lr_count);
15628 } else {
15629 vty_out(vty, " %d %s listen range(s)\n",
15630 lr_count, afi2str(afi));
15631 }
15632
15633 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15634 nnode, range)) {
15635 if (json) {
15636 char buf[BUFSIZ];
15637
15638 snprintfrr(buf, sizeof(buf), "%pFX",
15639 range);
15640
15641 json_object_array_add(
15642 json_peer_group_ranges,
15643 json_object_new_string(buf));
15644 } else {
15645 vty_out(vty, " %pFX\n", range);
15646 }
15647 }
15648
15649 if (json) {
15650 json_object_object_add(
15651 json_peer_group_dynamic_af, "ranges",
15652 json_peer_group_ranges);
15653
15654 json_object_object_add(
15655 json_peer_group_dynamic, afi2str(afi),
15656 json_peer_group_dynamic_af);
15657 }
15658 }
15659 }
15660
15661 if (json_peer_group_dynamic)
15662 json_object_object_add(json_peer_group, "dynamicRanges",
15663 json_peer_group_dynamic);
15664
15665 /* Display group members and their status */
15666 if (listcount(group->peer)) {
15667 if (json)
15668 json_peer_group_members = json_object_new_object();
15669 else
15670 vty_out(vty, " Peer-group members:\n");
15671 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15672 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15673 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15674 peer_status = "Idle (Admin)";
15675 else if (CHECK_FLAG(peer->sflags,
15676 PEER_STATUS_PREFIX_OVERFLOW))
15677 peer_status = "Idle (PfxCt)";
15678 else
15679 peer_status = lookup_msg(bgp_status_msg,
15680 peer->status, NULL);
15681
15682 dynamic = peer_dynamic_neighbor(peer);
15683
15684 if (json) {
15685 json_object *json_peer_group_member =
15686 json_object_new_object();
15687
15688 json_object_string_add(json_peer_group_member,
15689 "status", peer_status);
15690
15691 if (dynamic)
15692 json_object_boolean_true_add(
15693 json_peer_group_member,
15694 "dynamic");
15695
15696 json_object_object_add(json_peer_group_members,
15697 peer->host,
15698 json_peer_group_member);
15699 } else {
15700 vty_out(vty, " %s %s %s \n", peer->host,
15701 dynamic ? "(dynamic)" : "",
15702 peer_status);
15703 }
15704 }
15705 if (json)
15706 json_object_object_add(json_peer_group, "members",
15707 json_peer_group_members);
15708 }
15709
15710 if (json)
15711 json_object_object_add(json, group->name, json_peer_group);
15712
15713 return CMD_SUCCESS;
15714 }
15715
15716 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15717 const char *group_name, bool uj)
15718 {
15719 struct bgp *bgp;
15720 struct listnode *node, *nnode;
15721 struct peer_group *group;
15722 bool found = false;
15723 json_object *json = NULL;
15724
15725 if (uj)
15726 json = json_object_new_object();
15727
15728 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15729
15730 if (!bgp) {
15731 if (uj)
15732 vty_json(vty, json);
15733 else
15734 vty_out(vty, "%% BGP instance not found\n");
15735
15736 return CMD_WARNING;
15737 }
15738
15739 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15740 if (group_name) {
15741 if (strmatch(group->name, group_name)) {
15742 bgp_show_one_peer_group(vty, group, json);
15743 found = true;
15744 break;
15745 }
15746 } else {
15747 bgp_show_one_peer_group(vty, group, json);
15748 }
15749 }
15750
15751 if (group_name && !found && !uj)
15752 vty_out(vty, "%% No such peer-group\n");
15753
15754 if (uj)
15755 vty_json(vty, json);
15756
15757 return CMD_SUCCESS;
15758 }
15759
15760 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15761 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15762 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15763 "Detailed information on BGP peer groups\n"
15764 "Peer group name\n" JSON_STR)
15765 {
15766 char *vrf, *pg;
15767 int idx = 0;
15768 bool uj = use_json(argc, argv);
15769
15770 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15771 : NULL;
15772 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15773
15774 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15775 }
15776
15777
15778 /* Redistribute VTY commands. */
15779
15780 DEFUN (bgp_redistribute_ipv4,
15781 bgp_redistribute_ipv4_cmd,
15782 "redistribute " FRR_IP_REDIST_STR_BGPD,
15783 "Redistribute information from another routing protocol\n"
15784 FRR_IP_REDIST_HELP_STR_BGPD)
15785 {
15786 VTY_DECLVAR_CONTEXT(bgp, bgp);
15787 int idx_protocol = 1;
15788 int type;
15789
15790 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15791 if (type < 0) {
15792 vty_out(vty, "%% Invalid route type\n");
15793 return CMD_WARNING_CONFIG_FAILED;
15794 }
15795
15796 bgp_redist_add(bgp, AFI_IP, type, 0);
15797 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15798 }
15799
15800 ALIAS_HIDDEN(
15801 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15802 "redistribute " FRR_IP_REDIST_STR_BGPD,
15803 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15804
15805 DEFUN (bgp_redistribute_ipv4_rmap,
15806 bgp_redistribute_ipv4_rmap_cmd,
15807 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15808 "Redistribute information from another routing protocol\n"
15809 FRR_IP_REDIST_HELP_STR_BGPD
15810 "Route map reference\n"
15811 "Pointer to route-map entries\n")
15812 {
15813 VTY_DECLVAR_CONTEXT(bgp, bgp);
15814 int idx_protocol = 1;
15815 int idx_word = 3;
15816 int type;
15817 struct bgp_redist *red;
15818 bool changed;
15819 struct route_map *route_map = route_map_lookup_warn_noexist(
15820 vty, argv[idx_word]->arg);
15821
15822 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15823 if (type < 0) {
15824 vty_out(vty, "%% Invalid route type\n");
15825 return CMD_WARNING_CONFIG_FAILED;
15826 }
15827
15828 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15829 changed =
15830 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15831 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15832 }
15833
15834 ALIAS_HIDDEN(
15835 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15836 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15837 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15838 "Route map reference\n"
15839 "Pointer to route-map entries\n")
15840
15841 DEFUN (bgp_redistribute_ipv4_metric,
15842 bgp_redistribute_ipv4_metric_cmd,
15843 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15844 "Redistribute information from another routing protocol\n"
15845 FRR_IP_REDIST_HELP_STR_BGPD
15846 "Metric for redistributed routes\n"
15847 "Default metric\n")
15848 {
15849 VTY_DECLVAR_CONTEXT(bgp, bgp);
15850 int idx_protocol = 1;
15851 int idx_number = 3;
15852 int type;
15853 uint32_t metric;
15854 struct bgp_redist *red;
15855 bool changed;
15856
15857 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15858 if (type < 0) {
15859 vty_out(vty, "%% Invalid route type\n");
15860 return CMD_WARNING_CONFIG_FAILED;
15861 }
15862 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15863
15864 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15865 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15866 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15867 }
15868
15869 ALIAS_HIDDEN(
15870 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15871 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15872 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15873 "Metric for redistributed routes\n"
15874 "Default metric\n")
15875
15876 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15877 bgp_redistribute_ipv4_rmap_metric_cmd,
15878 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15879 "Redistribute information from another routing protocol\n"
15880 FRR_IP_REDIST_HELP_STR_BGPD
15881 "Route map reference\n"
15882 "Pointer to route-map entries\n"
15883 "Metric for redistributed routes\n"
15884 "Default metric\n")
15885 {
15886 VTY_DECLVAR_CONTEXT(bgp, bgp);
15887 int idx_protocol = 1;
15888 int idx_word = 3;
15889 int idx_number = 5;
15890 int type;
15891 uint32_t metric;
15892 struct bgp_redist *red;
15893 bool changed;
15894 struct route_map *route_map =
15895 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15896
15897 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15898 if (type < 0) {
15899 vty_out(vty, "%% Invalid route type\n");
15900 return CMD_WARNING_CONFIG_FAILED;
15901 }
15902 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15903
15904 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15905 changed =
15906 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15907 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15908 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15909 }
15910
15911 ALIAS_HIDDEN(
15912 bgp_redistribute_ipv4_rmap_metric,
15913 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15914 "redistribute " FRR_IP_REDIST_STR_BGPD
15915 " route-map RMAP_NAME metric (0-4294967295)",
15916 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15917 "Route map reference\n"
15918 "Pointer to route-map entries\n"
15919 "Metric for redistributed routes\n"
15920 "Default metric\n")
15921
15922 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15923 bgp_redistribute_ipv4_metric_rmap_cmd,
15924 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15925 "Redistribute information from another routing protocol\n"
15926 FRR_IP_REDIST_HELP_STR_BGPD
15927 "Metric for redistributed routes\n"
15928 "Default metric\n"
15929 "Route map reference\n"
15930 "Pointer to route-map entries\n")
15931 {
15932 VTY_DECLVAR_CONTEXT(bgp, bgp);
15933 int idx_protocol = 1;
15934 int idx_number = 3;
15935 int idx_word = 5;
15936 int type;
15937 uint32_t metric;
15938 struct bgp_redist *red;
15939 bool changed;
15940 struct route_map *route_map =
15941 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15942
15943 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15944 if (type < 0) {
15945 vty_out(vty, "%% Invalid route type\n");
15946 return CMD_WARNING_CONFIG_FAILED;
15947 }
15948 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15949
15950 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15951 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15952 changed |=
15953 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15954 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15955 }
15956
15957 ALIAS_HIDDEN(
15958 bgp_redistribute_ipv4_metric_rmap,
15959 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15960 "redistribute " FRR_IP_REDIST_STR_BGPD
15961 " metric (0-4294967295) route-map RMAP_NAME",
15962 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15963 "Metric for redistributed routes\n"
15964 "Default metric\n"
15965 "Route map reference\n"
15966 "Pointer to route-map entries\n")
15967
15968 DEFUN (bgp_redistribute_ipv4_ospf,
15969 bgp_redistribute_ipv4_ospf_cmd,
15970 "redistribute <ospf|table> (1-65535)",
15971 "Redistribute information from another routing protocol\n"
15972 "Open Shortest Path First (OSPFv2)\n"
15973 "Non-main Kernel Routing Table\n"
15974 "Instance ID/Table ID\n")
15975 {
15976 VTY_DECLVAR_CONTEXT(bgp, bgp);
15977 int idx_ospf_table = 1;
15978 int idx_number = 2;
15979 unsigned short instance;
15980 unsigned short protocol;
15981
15982 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15983
15984 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15985 protocol = ZEBRA_ROUTE_OSPF;
15986 else
15987 protocol = ZEBRA_ROUTE_TABLE;
15988
15989 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15990 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15991 }
15992
15993 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15994 "redistribute <ospf|table> (1-65535)",
15995 "Redistribute information from another routing protocol\n"
15996 "Open Shortest Path First (OSPFv2)\n"
15997 "Non-main Kernel Routing Table\n"
15998 "Instance ID/Table ID\n")
15999
16000 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16001 bgp_redistribute_ipv4_ospf_rmap_cmd,
16002 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16003 "Redistribute information from another routing protocol\n"
16004 "Open Shortest Path First (OSPFv2)\n"
16005 "Non-main Kernel Routing Table\n"
16006 "Instance ID/Table ID\n"
16007 "Route map reference\n"
16008 "Pointer to route-map entries\n")
16009 {
16010 VTY_DECLVAR_CONTEXT(bgp, bgp);
16011 int idx_ospf_table = 1;
16012 int idx_number = 2;
16013 int idx_word = 4;
16014 struct bgp_redist *red;
16015 unsigned short instance;
16016 int protocol;
16017 bool changed;
16018 struct route_map *route_map =
16019 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16020
16021 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16022 protocol = ZEBRA_ROUTE_OSPF;
16023 else
16024 protocol = ZEBRA_ROUTE_TABLE;
16025
16026 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16027 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16028 changed =
16029 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16030 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16031 }
16032
16033 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16034 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16035 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16036 "Redistribute information from another routing protocol\n"
16037 "Open Shortest Path First (OSPFv2)\n"
16038 "Non-main Kernel Routing Table\n"
16039 "Instance ID/Table ID\n"
16040 "Route map reference\n"
16041 "Pointer to route-map entries\n")
16042
16043 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16044 bgp_redistribute_ipv4_ospf_metric_cmd,
16045 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16046 "Redistribute information from another routing protocol\n"
16047 "Open Shortest Path First (OSPFv2)\n"
16048 "Non-main Kernel Routing Table\n"
16049 "Instance ID/Table ID\n"
16050 "Metric for redistributed routes\n"
16051 "Default metric\n")
16052 {
16053 VTY_DECLVAR_CONTEXT(bgp, bgp);
16054 int idx_ospf_table = 1;
16055 int idx_number = 2;
16056 int idx_number_2 = 4;
16057 uint32_t metric;
16058 struct bgp_redist *red;
16059 unsigned short instance;
16060 int protocol;
16061 bool changed;
16062
16063 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16064 protocol = ZEBRA_ROUTE_OSPF;
16065 else
16066 protocol = ZEBRA_ROUTE_TABLE;
16067
16068 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16069 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16070
16071 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16072 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16073 metric);
16074 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16075 }
16076
16077 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16078 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16079 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16080 "Redistribute information from another routing protocol\n"
16081 "Open Shortest Path First (OSPFv2)\n"
16082 "Non-main Kernel Routing Table\n"
16083 "Instance ID/Table ID\n"
16084 "Metric for redistributed routes\n"
16085 "Default metric\n")
16086
16087 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16088 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16089 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16090 "Redistribute information from another routing protocol\n"
16091 "Open Shortest Path First (OSPFv2)\n"
16092 "Non-main Kernel Routing Table\n"
16093 "Instance ID/Table ID\n"
16094 "Route map reference\n"
16095 "Pointer to route-map entries\n"
16096 "Metric for redistributed routes\n"
16097 "Default metric\n")
16098 {
16099 VTY_DECLVAR_CONTEXT(bgp, bgp);
16100 int idx_ospf_table = 1;
16101 int idx_number = 2;
16102 int idx_word = 4;
16103 int idx_number_2 = 6;
16104 uint32_t metric;
16105 struct bgp_redist *red;
16106 unsigned short instance;
16107 int protocol;
16108 bool changed;
16109 struct route_map *route_map =
16110 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16111
16112 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16113 protocol = ZEBRA_ROUTE_OSPF;
16114 else
16115 protocol = ZEBRA_ROUTE_TABLE;
16116
16117 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16118 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16119
16120 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16121 changed =
16122 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16123 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16124 metric);
16125 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16126 }
16127
16128 ALIAS_HIDDEN(
16129 bgp_redistribute_ipv4_ospf_rmap_metric,
16130 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16131 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16132 "Redistribute information from another routing protocol\n"
16133 "Open Shortest Path First (OSPFv2)\n"
16134 "Non-main Kernel Routing Table\n"
16135 "Instance ID/Table ID\n"
16136 "Route map reference\n"
16137 "Pointer to route-map entries\n"
16138 "Metric for redistributed routes\n"
16139 "Default metric\n")
16140
16141 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16142 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16143 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16144 "Redistribute information from another routing protocol\n"
16145 "Open Shortest Path First (OSPFv2)\n"
16146 "Non-main Kernel Routing Table\n"
16147 "Instance ID/Table ID\n"
16148 "Metric for redistributed routes\n"
16149 "Default metric\n"
16150 "Route map reference\n"
16151 "Pointer to route-map entries\n")
16152 {
16153 VTY_DECLVAR_CONTEXT(bgp, bgp);
16154 int idx_ospf_table = 1;
16155 int idx_number = 2;
16156 int idx_number_2 = 4;
16157 int idx_word = 6;
16158 uint32_t metric;
16159 struct bgp_redist *red;
16160 unsigned short instance;
16161 int protocol;
16162 bool changed;
16163 struct route_map *route_map =
16164 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16165
16166 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16167 protocol = ZEBRA_ROUTE_OSPF;
16168 else
16169 protocol = ZEBRA_ROUTE_TABLE;
16170
16171 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16172 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16173
16174 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16175 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16176 metric);
16177 changed |=
16178 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16179 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16180 }
16181
16182 ALIAS_HIDDEN(
16183 bgp_redistribute_ipv4_ospf_metric_rmap,
16184 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16185 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16186 "Redistribute information from another routing protocol\n"
16187 "Open Shortest Path First (OSPFv2)\n"
16188 "Non-main Kernel Routing Table\n"
16189 "Instance ID/Table ID\n"
16190 "Metric for redistributed routes\n"
16191 "Default metric\n"
16192 "Route map reference\n"
16193 "Pointer to route-map entries\n")
16194
16195 DEFUN (no_bgp_redistribute_ipv4_ospf,
16196 no_bgp_redistribute_ipv4_ospf_cmd,
16197 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16198 NO_STR
16199 "Redistribute information from another routing protocol\n"
16200 "Open Shortest Path First (OSPFv2)\n"
16201 "Non-main Kernel Routing Table\n"
16202 "Instance ID/Table ID\n"
16203 "Metric for redistributed routes\n"
16204 "Default metric\n"
16205 "Route map reference\n"
16206 "Pointer to route-map entries\n")
16207 {
16208 VTY_DECLVAR_CONTEXT(bgp, bgp);
16209 int idx_ospf_table = 2;
16210 int idx_number = 3;
16211 unsigned short instance;
16212 int protocol;
16213
16214 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16215 protocol = ZEBRA_ROUTE_OSPF;
16216 else
16217 protocol = ZEBRA_ROUTE_TABLE;
16218
16219 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16220 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16221 }
16222
16223 ALIAS_HIDDEN(
16224 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16225 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16226 NO_STR
16227 "Redistribute information from another routing protocol\n"
16228 "Open Shortest Path First (OSPFv2)\n"
16229 "Non-main Kernel Routing Table\n"
16230 "Instance ID/Table ID\n"
16231 "Metric for redistributed routes\n"
16232 "Default metric\n"
16233 "Route map reference\n"
16234 "Pointer to route-map entries\n")
16235
16236 DEFUN (no_bgp_redistribute_ipv4,
16237 no_bgp_redistribute_ipv4_cmd,
16238 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16239 NO_STR
16240 "Redistribute information from another routing protocol\n"
16241 FRR_IP_REDIST_HELP_STR_BGPD
16242 "Metric for redistributed routes\n"
16243 "Default metric\n"
16244 "Route map reference\n"
16245 "Pointer to route-map entries\n")
16246 {
16247 VTY_DECLVAR_CONTEXT(bgp, bgp);
16248 int idx_protocol = 2;
16249 int type;
16250
16251 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16252 if (type < 0) {
16253 vty_out(vty, "%% Invalid route type\n");
16254 return CMD_WARNING_CONFIG_FAILED;
16255 }
16256 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16257 }
16258
16259 ALIAS_HIDDEN(
16260 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16261 "no redistribute " FRR_IP_REDIST_STR_BGPD
16262 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16263 NO_STR
16264 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16265 "Metric for redistributed routes\n"
16266 "Default metric\n"
16267 "Route map reference\n"
16268 "Pointer to route-map entries\n")
16269
16270 DEFUN (bgp_redistribute_ipv6,
16271 bgp_redistribute_ipv6_cmd,
16272 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16273 "Redistribute information from another routing protocol\n"
16274 FRR_IP6_REDIST_HELP_STR_BGPD)
16275 {
16276 VTY_DECLVAR_CONTEXT(bgp, bgp);
16277 int idx_protocol = 1;
16278 int type;
16279
16280 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16281 if (type < 0) {
16282 vty_out(vty, "%% Invalid route type\n");
16283 return CMD_WARNING_CONFIG_FAILED;
16284 }
16285
16286 bgp_redist_add(bgp, AFI_IP6, type, 0);
16287 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16288 }
16289
16290 DEFUN (bgp_redistribute_ipv6_rmap,
16291 bgp_redistribute_ipv6_rmap_cmd,
16292 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16293 "Redistribute information from another routing protocol\n"
16294 FRR_IP6_REDIST_HELP_STR_BGPD
16295 "Route map reference\n"
16296 "Pointer to route-map entries\n")
16297 {
16298 VTY_DECLVAR_CONTEXT(bgp, bgp);
16299 int idx_protocol = 1;
16300 int idx_word = 3;
16301 int type;
16302 struct bgp_redist *red;
16303 bool changed;
16304 struct route_map *route_map =
16305 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16306
16307 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16308 if (type < 0) {
16309 vty_out(vty, "%% Invalid route type\n");
16310 return CMD_WARNING_CONFIG_FAILED;
16311 }
16312
16313 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16314 changed =
16315 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16316 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16317 }
16318
16319 DEFUN (bgp_redistribute_ipv6_metric,
16320 bgp_redistribute_ipv6_metric_cmd,
16321 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16322 "Redistribute information from another routing protocol\n"
16323 FRR_IP6_REDIST_HELP_STR_BGPD
16324 "Metric for redistributed routes\n"
16325 "Default metric\n")
16326 {
16327 VTY_DECLVAR_CONTEXT(bgp, bgp);
16328 int idx_protocol = 1;
16329 int idx_number = 3;
16330 int type;
16331 uint32_t metric;
16332 struct bgp_redist *red;
16333 bool changed;
16334
16335 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16336 if (type < 0) {
16337 vty_out(vty, "%% Invalid route type\n");
16338 return CMD_WARNING_CONFIG_FAILED;
16339 }
16340 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16341
16342 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16343 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16344 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16345 }
16346
16347 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16348 bgp_redistribute_ipv6_rmap_metric_cmd,
16349 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16350 "Redistribute information from another routing protocol\n"
16351 FRR_IP6_REDIST_HELP_STR_BGPD
16352 "Route map reference\n"
16353 "Pointer to route-map entries\n"
16354 "Metric for redistributed routes\n"
16355 "Default metric\n")
16356 {
16357 VTY_DECLVAR_CONTEXT(bgp, bgp);
16358 int idx_protocol = 1;
16359 int idx_word = 3;
16360 int idx_number = 5;
16361 int type;
16362 uint32_t metric;
16363 struct bgp_redist *red;
16364 bool changed;
16365 struct route_map *route_map =
16366 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16367
16368 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16369 if (type < 0) {
16370 vty_out(vty, "%% Invalid route type\n");
16371 return CMD_WARNING_CONFIG_FAILED;
16372 }
16373 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16374
16375 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16376 changed =
16377 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16378 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16379 metric);
16380 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16381 }
16382
16383 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16384 bgp_redistribute_ipv6_metric_rmap_cmd,
16385 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16386 "Redistribute information from another routing protocol\n"
16387 FRR_IP6_REDIST_HELP_STR_BGPD
16388 "Metric for redistributed routes\n"
16389 "Default metric\n"
16390 "Route map reference\n"
16391 "Pointer to route-map entries\n")
16392 {
16393 VTY_DECLVAR_CONTEXT(bgp, bgp);
16394 int idx_protocol = 1;
16395 int idx_number = 3;
16396 int idx_word = 5;
16397 int type;
16398 uint32_t metric;
16399 struct bgp_redist *red;
16400 bool changed;
16401 struct route_map *route_map =
16402 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16403
16404 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16405 if (type < 0) {
16406 vty_out(vty, "%% Invalid route type\n");
16407 return CMD_WARNING_CONFIG_FAILED;
16408 }
16409 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16410
16411 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16412 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16413 metric);
16414 changed |=
16415 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16416 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16417 }
16418
16419 DEFUN (no_bgp_redistribute_ipv6,
16420 no_bgp_redistribute_ipv6_cmd,
16421 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16422 NO_STR
16423 "Redistribute information from another routing protocol\n"
16424 FRR_IP6_REDIST_HELP_STR_BGPD
16425 "Metric for redistributed routes\n"
16426 "Default metric\n"
16427 "Route map reference\n"
16428 "Pointer to route-map entries\n")
16429 {
16430 VTY_DECLVAR_CONTEXT(bgp, bgp);
16431 int idx_protocol = 2;
16432 int type;
16433
16434 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16435 if (type < 0) {
16436 vty_out(vty, "%% Invalid route type\n");
16437 return CMD_WARNING_CONFIG_FAILED;
16438 }
16439
16440 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16441 }
16442
16443 /* Neighbor update tcp-mss. */
16444 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16445 const char *tcp_mss_str)
16446 {
16447 struct peer *peer;
16448 uint32_t tcp_mss_val = 0;
16449
16450 peer = peer_and_group_lookup_vty(vty, peer_str);
16451 if (!peer)
16452 return CMD_WARNING_CONFIG_FAILED;
16453
16454 if (tcp_mss_str) {
16455 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16456 peer_tcp_mss_set(peer, tcp_mss_val);
16457 } else {
16458 peer_tcp_mss_unset(peer);
16459 }
16460
16461 return CMD_SUCCESS;
16462 }
16463
16464 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16465 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16466 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16467 "TCP max segment size\n"
16468 "TCP MSS value\n")
16469 {
16470 int peer_index = 1;
16471 int mss_index = 3;
16472
16473 vty_out(vty,
16474 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16475 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16476 argv[mss_index]->arg);
16477 }
16478
16479 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16480 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16481 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16482 "TCP max segment size\n"
16483 "TCP MSS value\n")
16484 {
16485 int peer_index = 2;
16486
16487 vty_out(vty,
16488 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16489 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16490 }
16491
16492 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16493 "[no$no] bgp retain route-target all",
16494 NO_STR BGP_STR
16495 "Retain BGP updates\n"
16496 "Retain BGP updates based on route-target values\n"
16497 "Retain all BGP updates\n")
16498 {
16499 bool check;
16500 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16501
16502 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16503 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16504 if (check != !no) {
16505 if (!no)
16506 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16507 [bgp_node_safi(vty)],
16508 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16509 else
16510 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16511 [bgp_node_safi(vty)],
16512 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16513 /* trigger a flush to re-sync with ADJ-RIB-in */
16514 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16515 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16516 }
16517 return CMD_SUCCESS;
16518 }
16519
16520 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16521 afi_t afi, safi_t safi)
16522 {
16523 int i;
16524
16525 /* Unicast redistribution only. */
16526 if (safi != SAFI_UNICAST)
16527 return;
16528
16529 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16530 /* Redistribute BGP does not make sense. */
16531 if (i != ZEBRA_ROUTE_BGP) {
16532 struct list *red_list;
16533 struct listnode *node;
16534 struct bgp_redist *red;
16535
16536 red_list = bgp->redist[afi][i];
16537 if (!red_list)
16538 continue;
16539
16540 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16541 /* "redistribute" configuration. */
16542 vty_out(vty, " redistribute %s",
16543 zebra_route_string(i));
16544 if (red->instance)
16545 vty_out(vty, " %d", red->instance);
16546 if (red->redist_metric_flag)
16547 vty_out(vty, " metric %u",
16548 red->redist_metric);
16549 if (red->rmap.name)
16550 vty_out(vty, " route-map %s",
16551 red->rmap.name);
16552 vty_out(vty, "\n");
16553 }
16554 }
16555 }
16556 }
16557
16558 /* peer-group helpers for config-write */
16559
16560 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16561 {
16562 if (!peer_group_active(peer)) {
16563 if (CHECK_FLAG(peer->flags_invert, flag))
16564 return !CHECK_FLAG(peer->flags, flag);
16565 else
16566 return !!CHECK_FLAG(peer->flags, flag);
16567 }
16568
16569 return !!CHECK_FLAG(peer->flags_override, flag);
16570 }
16571
16572 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16573 uint64_t flag)
16574 {
16575 if (!peer_group_active(peer)) {
16576 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16577 return !peer_af_flag_check(peer, afi, safi, flag);
16578 else
16579 return !!peer_af_flag_check(peer, afi, safi, flag);
16580 }
16581
16582 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16583 }
16584
16585 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16586 uint8_t type, int direct)
16587 {
16588 struct bgp_filter *filter;
16589
16590 if (peer_group_active(peer))
16591 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16592 type);
16593
16594 filter = &peer->filter[afi][safi];
16595 switch (type) {
16596 case PEER_FT_DISTRIBUTE_LIST:
16597 return !!(filter->dlist[direct].name);
16598 case PEER_FT_FILTER_LIST:
16599 return !!(filter->aslist[direct].name);
16600 case PEER_FT_PREFIX_LIST:
16601 return !!(filter->plist[direct].name);
16602 case PEER_FT_ROUTE_MAP:
16603 return !!(filter->map[direct].name);
16604 case PEER_FT_UNSUPPRESS_MAP:
16605 return !!(filter->usmap.name);
16606 case PEER_FT_ADVERTISE_MAP:
16607 return !!(filter->advmap.aname
16608 && ((filter->advmap.condition == direct)
16609 && filter->advmap.cname));
16610 default:
16611 return false;
16612 }
16613 }
16614
16615 /* Return true if the addpath type is set for peer and different from
16616 * peer-group.
16617 */
16618 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16619 safi_t safi)
16620 {
16621 enum bgp_addpath_strat type, g_type;
16622
16623 type = peer->addpath_type[afi][safi];
16624
16625 if (type != BGP_ADDPATH_NONE) {
16626 if (peer_group_active(peer)) {
16627 g_type = peer->group->conf->addpath_type[afi][safi];
16628
16629 if (type != g_type)
16630 return true;
16631 else
16632 return false;
16633 }
16634
16635 return true;
16636 }
16637
16638 return false;
16639 }
16640
16641 /* This is part of the address-family block (unicast only) */
16642 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16643 afi_t afi)
16644 {
16645 int indent = 2;
16646 uint32_t tovpn_sid_index = 0;
16647
16648 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16649 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16650 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16651 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16652 bgp->vpn_policy[afi]
16653 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16654 else
16655 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16656 bgp->vpn_policy[afi]
16657 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16658 }
16659 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16660 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16661 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16662 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16663 return;
16664
16665 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16666 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16667
16668 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16669
16670 } else {
16671 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16672 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16673 bgp->vpn_policy[afi].tovpn_label);
16674 }
16675 }
16676
16677 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16678 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16679 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16680 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16681 } else if (tovpn_sid_index != 0) {
16682 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16683 tovpn_sid_index);
16684 }
16685
16686 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16687 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16688 &bgp->vpn_policy[afi].tovpn_rd);
16689
16690 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16691 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16692
16693 char buf[PREFIX_STRLEN];
16694 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16695 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16696 sizeof(buf))) {
16697
16698 vty_out(vty, "%*snexthop vpn export %s\n",
16699 indent, "", buf);
16700 }
16701 }
16702 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16703 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16704 && ecommunity_cmp(
16705 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16706 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16707
16708 char *b = ecommunity_ecom2str(
16709 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16710 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16711 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16712 XFREE(MTYPE_ECOMMUNITY_STR, b);
16713 } else {
16714 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16715 char *b = ecommunity_ecom2str(
16716 bgp->vpn_policy[afi]
16717 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16718 ECOMMUNITY_FORMAT_ROUTE_MAP,
16719 ECOMMUNITY_ROUTE_TARGET);
16720 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16721 XFREE(MTYPE_ECOMMUNITY_STR, b);
16722 }
16723 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16724 char *b = ecommunity_ecom2str(
16725 bgp->vpn_policy[afi]
16726 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16727 ECOMMUNITY_FORMAT_ROUTE_MAP,
16728 ECOMMUNITY_ROUTE_TARGET);
16729 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16730 XFREE(MTYPE_ECOMMUNITY_STR, b);
16731 }
16732 }
16733
16734 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16735 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16736 bgp->vpn_policy[afi]
16737 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16738
16739 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16740 char *b = ecommunity_ecom2str(
16741 bgp->vpn_policy[afi]
16742 .import_redirect_rtlist,
16743 ECOMMUNITY_FORMAT_ROUTE_MAP,
16744 ECOMMUNITY_ROUTE_TARGET);
16745
16746 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16747 != ECOMMUNITY_SIZE)
16748 vty_out(vty, "%*srt6 redirect import %s\n",
16749 indent, "", b);
16750 else
16751 vty_out(vty, "%*srt redirect import %s\n",
16752 indent, "", b);
16753 XFREE(MTYPE_ECOMMUNITY_STR, b);
16754 }
16755 }
16756
16757 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16758 afi_t afi, safi_t safi)
16759 {
16760 struct bgp_filter *filter;
16761 char *addr;
16762
16763 addr = peer->host;
16764 filter = &peer->filter[afi][safi];
16765
16766 /* distribute-list. */
16767 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16768 FILTER_IN))
16769 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16770 filter->dlist[FILTER_IN].name);
16771
16772 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16773 FILTER_OUT))
16774 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16775 filter->dlist[FILTER_OUT].name);
16776
16777 /* prefix-list. */
16778 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16779 FILTER_IN))
16780 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16781 filter->plist[FILTER_IN].name);
16782
16783 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16784 FILTER_OUT))
16785 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16786 filter->plist[FILTER_OUT].name);
16787
16788 /* route-map. */
16789 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16790 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16791 filter->map[RMAP_IN].name);
16792
16793 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16794 RMAP_OUT))
16795 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16796 filter->map[RMAP_OUT].name);
16797
16798 /* unsuppress-map */
16799 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16800 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16801 filter->usmap.name);
16802
16803 /* advertise-map : always applied in OUT direction*/
16804 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16805 CONDITION_NON_EXIST))
16806 vty_out(vty,
16807 " neighbor %s advertise-map %s non-exist-map %s\n",
16808 addr, filter->advmap.aname, filter->advmap.cname);
16809
16810 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16811 CONDITION_EXIST))
16812 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16813 addr, filter->advmap.aname, filter->advmap.cname);
16814
16815 /* filter-list. */
16816 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16817 FILTER_IN))
16818 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16819 filter->aslist[FILTER_IN].name);
16820
16821 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16822 FILTER_OUT))
16823 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16824 filter->aslist[FILTER_OUT].name);
16825 }
16826
16827 /* BGP peer configuration display function. */
16828 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16829 struct peer *peer)
16830 {
16831 struct peer *g_peer = NULL;
16832 char *addr;
16833 int if_pg_printed = false;
16834 int if_ras_printed = false;
16835
16836 /* Skip dynamic neighbors. */
16837 if (peer_dynamic_neighbor(peer))
16838 return;
16839
16840 if (peer->conf_if)
16841 addr = peer->conf_if;
16842 else
16843 addr = peer->host;
16844
16845 /************************************
16846 ****** Global to the neighbor ******
16847 ************************************/
16848 if (peer->conf_if) {
16849 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16850 vty_out(vty, " neighbor %s interface v6only", addr);
16851 else
16852 vty_out(vty, " neighbor %s interface", addr);
16853
16854 if (peer_group_active(peer)) {
16855 vty_out(vty, " peer-group %s", peer->group->name);
16856 if_pg_printed = true;
16857 } else if (peer->as_type == AS_SPECIFIED) {
16858 vty_out(vty, " remote-as %u", peer->as);
16859 if_ras_printed = true;
16860 } else if (peer->as_type == AS_INTERNAL) {
16861 vty_out(vty, " remote-as internal");
16862 if_ras_printed = true;
16863 } else if (peer->as_type == AS_EXTERNAL) {
16864 vty_out(vty, " remote-as external");
16865 if_ras_printed = true;
16866 }
16867
16868 vty_out(vty, "\n");
16869 }
16870
16871 /* remote-as and peer-group */
16872 /* peer is a member of a peer-group */
16873 if (peer_group_active(peer)) {
16874 g_peer = peer->group->conf;
16875
16876 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16877 if (peer->as_type == AS_SPECIFIED) {
16878 vty_out(vty, " neighbor %s remote-as %u\n",
16879 addr, peer->as);
16880 } else if (peer->as_type == AS_INTERNAL) {
16881 vty_out(vty,
16882 " neighbor %s remote-as internal\n",
16883 addr);
16884 } else if (peer->as_type == AS_EXTERNAL) {
16885 vty_out(vty,
16886 " neighbor %s remote-as external\n",
16887 addr);
16888 }
16889 }
16890
16891 /* For swpX peers we displayed the peer-group
16892 * via 'neighbor swpX interface peer-group PGNAME' */
16893 if (!if_pg_printed)
16894 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16895 peer->group->name);
16896 }
16897
16898 /* peer is NOT a member of a peer-group */
16899 else {
16900 /* peer is a peer-group, declare the peer-group */
16901 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16902 vty_out(vty, " neighbor %s peer-group\n", addr);
16903 }
16904
16905 if (!if_ras_printed) {
16906 if (peer->as_type == AS_SPECIFIED) {
16907 vty_out(vty, " neighbor %s remote-as %u\n",
16908 addr, peer->as);
16909 } else if (peer->as_type == AS_INTERNAL) {
16910 vty_out(vty,
16911 " neighbor %s remote-as internal\n",
16912 addr);
16913 } else if (peer->as_type == AS_EXTERNAL) {
16914 vty_out(vty,
16915 " neighbor %s remote-as external\n",
16916 addr);
16917 }
16918 }
16919 }
16920
16921 /* local-as */
16922 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16923 vty_out(vty, " neighbor %s local-as %u", addr,
16924 peer->change_local_as);
16925 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16926 vty_out(vty, " no-prepend");
16927 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16928 vty_out(vty, " replace-as");
16929 vty_out(vty, "\n");
16930 }
16931
16932 /* description */
16933 if (peer->desc) {
16934 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16935 }
16936
16937 /* shutdown */
16938 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16939 if (peer->tx_shutdown_message)
16940 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16941 peer->tx_shutdown_message);
16942 else
16943 vty_out(vty, " neighbor %s shutdown\n", addr);
16944 }
16945
16946 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16947 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16948 peer->rtt_expected, peer->rtt_keepalive_conf);
16949
16950 /* bfd */
16951 if (peer->bfd_config)
16952 bgp_bfd_peer_config_write(vty, peer, addr);
16953
16954 /* password */
16955 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16956 vty_out(vty, " neighbor %s password %s\n", addr,
16957 peer->password);
16958
16959 /* neighbor solo */
16960 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16961 if (!peer_group_active(peer)) {
16962 vty_out(vty, " neighbor %s solo\n", addr);
16963 }
16964 }
16965
16966 /* BGP port */
16967 if (peer->port != BGP_PORT_DEFAULT) {
16968 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16969 }
16970
16971 /* Local interface name */
16972 if (peer->ifname) {
16973 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16974 }
16975
16976 /* TCP max segment size */
16977 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16978 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16979
16980 /* passive */
16981 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16982 vty_out(vty, " neighbor %s passive\n", addr);
16983
16984 /* ebgp-multihop */
16985 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16986 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16987 && peer->ttl == MAXTTL)) {
16988 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16989 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16990 peer->ttl);
16991 }
16992 }
16993
16994 /* role */
16995 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16996 peer->local_role != ROLE_UNDEFINED)
16997 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16998 bgp_get_name_by_role(peer->local_role),
16999 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17000 ? " strict-mode"
17001 : "");
17002
17003 /* ttl-security hops */
17004 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17005 if (!peer_group_active(peer)
17006 || g_peer->gtsm_hops != peer->gtsm_hops) {
17007 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17008 addr, peer->gtsm_hops);
17009 }
17010 }
17011
17012 /* disable-connected-check */
17013 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17014 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17015
17016 /* link-bw-encoding-ieee */
17017 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17018 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17019 addr);
17020
17021 /* extended-optional-parameters */
17022 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17023 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17024 addr);
17025
17026 /* enforce-first-as */
17027 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17028 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17029
17030 /* update-source */
17031 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17032 if (peer->update_source)
17033 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17034 peer->update_source);
17035 else if (peer->update_if)
17036 vty_out(vty, " neighbor %s update-source %s\n", addr,
17037 peer->update_if);
17038 }
17039
17040 /* advertisement-interval */
17041 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17042 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17043 peer->routeadv);
17044
17045 /* timers */
17046 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17047 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17048 peer->keepalive, peer->holdtime);
17049
17050 /* timers connect */
17051 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17052 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17053 peer->connect);
17054 /* need special-case handling for changed default values due to
17055 * config profile / version (because there is no "timers bgp connect"
17056 * command, we need to save this per-peer :/)
17057 */
17058 else if (!peer_group_active(peer) && !peer->connect &&
17059 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17060 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17061 peer->bgp->default_connect_retry);
17062
17063 /* timers delayopen */
17064 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17065 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17066 peer->delayopen);
17067 /* Save config even though flag is not set if default values have been
17068 * changed
17069 */
17070 else if (!peer_group_active(peer) && !peer->delayopen
17071 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17072 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17073 peer->bgp->default_delayopen);
17074
17075 /* capability dynamic */
17076 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17077 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17078
17079 /* capability extended-nexthop */
17080 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17081 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17082 !peer->conf_if)
17083 vty_out(vty,
17084 " no neighbor %s capability extended-nexthop\n",
17085 addr);
17086 else if (!peer->conf_if)
17087 vty_out(vty,
17088 " neighbor %s capability extended-nexthop\n",
17089 addr);
17090 }
17091
17092 /* dont-capability-negotiation */
17093 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17094 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17095
17096 /* override-capability */
17097 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17098 vty_out(vty, " neighbor %s override-capability\n", addr);
17099
17100 /* strict-capability-match */
17101 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17102 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17103
17104 /* Sender side AS path loop detection. */
17105 if (peer->as_path_loop_detection)
17106 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17107 addr);
17108
17109 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17110 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17111
17112 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17113 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17114 vty_out(vty,
17115 " neighbor %s graceful-restart-helper\n", addr);
17116 } else if (CHECK_FLAG(
17117 peer->peer_gr_new_status_flag,
17118 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17119 vty_out(vty,
17120 " neighbor %s graceful-restart\n", addr);
17121 } else if (
17122 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17123 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17124 && !(CHECK_FLAG(
17125 peer->peer_gr_new_status_flag,
17126 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17127 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17128 addr);
17129 }
17130 }
17131 }
17132
17133 /* BGP peer configuration display function. */
17134 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17135 struct peer *peer, afi_t afi, safi_t safi)
17136 {
17137 struct peer *g_peer = NULL;
17138 char *addr;
17139 bool flag_scomm, flag_secomm, flag_slcomm;
17140
17141 /* Skip dynamic neighbors. */
17142 if (peer_dynamic_neighbor(peer))
17143 return;
17144
17145 if (peer->conf_if)
17146 addr = peer->conf_if;
17147 else
17148 addr = peer->host;
17149
17150 /************************************
17151 ****** Per AF to the neighbor ******
17152 ************************************/
17153 if (peer_group_active(peer)) {
17154 g_peer = peer->group->conf;
17155
17156 /* If the peer-group is active but peer is not, print a 'no
17157 * activate' */
17158 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17159 vty_out(vty, " no neighbor %s activate\n", addr);
17160 }
17161
17162 /* If the peer-group is not active but peer is, print an
17163 'activate' */
17164 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17165 vty_out(vty, " neighbor %s activate\n", addr);
17166 }
17167 } else {
17168 if (peer->afc[afi][safi]) {
17169 if (safi == SAFI_ENCAP)
17170 vty_out(vty, " neighbor %s activate\n", addr);
17171 else if (!bgp->default_af[afi][safi])
17172 vty_out(vty, " neighbor %s activate\n", addr);
17173 } else {
17174 if (bgp->default_af[afi][safi])
17175 vty_out(vty, " no neighbor %s activate\n",
17176 addr);
17177 }
17178 }
17179
17180 /* addpath TX knobs */
17181 if (peergroup_af_addpath_check(peer, afi, safi)) {
17182 switch (peer->addpath_type[afi][safi]) {
17183 case BGP_ADDPATH_ALL:
17184 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17185 addr);
17186 break;
17187 case BGP_ADDPATH_BEST_PER_AS:
17188 vty_out(vty,
17189 " neighbor %s addpath-tx-bestpath-per-AS\n",
17190 addr);
17191 break;
17192 case BGP_ADDPATH_MAX:
17193 case BGP_ADDPATH_NONE:
17194 break;
17195 }
17196 }
17197
17198 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17199 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17200
17201 /* ORF capability. */
17202 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17203 || peergroup_af_flag_check(peer, afi, safi,
17204 PEER_FLAG_ORF_PREFIX_RM)) {
17205 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17206
17207 if (peergroup_af_flag_check(peer, afi, safi,
17208 PEER_FLAG_ORF_PREFIX_SM)
17209 && peergroup_af_flag_check(peer, afi, safi,
17210 PEER_FLAG_ORF_PREFIX_RM))
17211 vty_out(vty, " both");
17212 else if (peergroup_af_flag_check(peer, afi, safi,
17213 PEER_FLAG_ORF_PREFIX_SM))
17214 vty_out(vty, " send");
17215 else
17216 vty_out(vty, " receive");
17217 vty_out(vty, "\n");
17218 }
17219
17220 /* Route reflector client. */
17221 if (peergroup_af_flag_check(peer, afi, safi,
17222 PEER_FLAG_REFLECTOR_CLIENT)) {
17223 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17224 }
17225
17226 /* next-hop-self force */
17227 if (peergroup_af_flag_check(peer, afi, safi,
17228 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17229 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17230 }
17231
17232 /* next-hop-self */
17233 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17234 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17235 }
17236
17237 /* remove-private-AS */
17238 if (peergroup_af_flag_check(peer, afi, safi,
17239 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17240 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17241 addr);
17242 }
17243
17244 else if (peergroup_af_flag_check(peer, afi, safi,
17245 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17246 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17247 addr);
17248 }
17249
17250 else if (peergroup_af_flag_check(peer, afi, safi,
17251 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17252 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17253 }
17254
17255 else if (peergroup_af_flag_check(peer, afi, safi,
17256 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17257 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17258 }
17259
17260 /* as-override */
17261 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17262 vty_out(vty, " neighbor %s as-override\n", addr);
17263 }
17264
17265 /* send-community print. */
17266 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17267 PEER_FLAG_SEND_COMMUNITY);
17268 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17269 PEER_FLAG_SEND_EXT_COMMUNITY);
17270 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17271 PEER_FLAG_SEND_LARGE_COMMUNITY);
17272
17273 if (flag_scomm && flag_secomm && flag_slcomm) {
17274 vty_out(vty, " no neighbor %s send-community all\n", addr);
17275 } else {
17276 if (flag_scomm)
17277 vty_out(vty, " no neighbor %s send-community\n", addr);
17278 if (flag_secomm)
17279 vty_out(vty,
17280 " no neighbor %s send-community extended\n",
17281 addr);
17282
17283 if (flag_slcomm)
17284 vty_out(vty, " no neighbor %s send-community large\n",
17285 addr);
17286 }
17287
17288 /* Default information */
17289 if (peergroup_af_flag_check(peer, afi, safi,
17290 PEER_FLAG_DEFAULT_ORIGINATE)) {
17291 vty_out(vty, " neighbor %s default-originate", addr);
17292
17293 if (peer->default_rmap[afi][safi].name)
17294 vty_out(vty, " route-map %s",
17295 peer->default_rmap[afi][safi].name);
17296
17297 vty_out(vty, "\n");
17298 }
17299
17300 /* Soft reconfiguration inbound. */
17301 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17302 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17303 addr);
17304 }
17305
17306 /* maximum-prefix. */
17307 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17308 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17309 peer->pmax[afi][safi]);
17310
17311 if (peer->pmax_threshold[afi][safi]
17312 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17313 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17314 if (peer_af_flag_check(peer, afi, safi,
17315 PEER_FLAG_MAX_PREFIX_WARNING))
17316 vty_out(vty, " warning-only");
17317 if (peer->pmax_restart[afi][safi])
17318 vty_out(vty, " restart %u",
17319 peer->pmax_restart[afi][safi]);
17320 if (peer_af_flag_check(peer, afi, safi,
17321 PEER_FLAG_MAX_PREFIX_FORCE))
17322 vty_out(vty, " force");
17323
17324 vty_out(vty, "\n");
17325 }
17326
17327 /* maximum-prefix-out */
17328 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17329 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17330 addr, peer->pmax_out[afi][safi]);
17331
17332 /* Route server client. */
17333 if (peergroup_af_flag_check(peer, afi, safi,
17334 PEER_FLAG_RSERVER_CLIENT)) {
17335 vty_out(vty, " neighbor %s route-server-client\n", addr);
17336 }
17337
17338 /* Nexthop-local unchanged. */
17339 if (peergroup_af_flag_check(peer, afi, safi,
17340 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17341 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17342 }
17343
17344 /* allowas-in <1-10> */
17345 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17346 if (peer_af_flag_check(peer, afi, safi,
17347 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17348 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17349 } else if (peer->allowas_in[afi][safi] == 3) {
17350 vty_out(vty, " neighbor %s allowas-in\n", addr);
17351 } else {
17352 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17353 peer->allowas_in[afi][safi]);
17354 }
17355 }
17356
17357 /* soo */
17358 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17359 char *soo_str = ecommunity_ecom2str(
17360 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17361
17362 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17363 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17364 }
17365
17366 /* weight */
17367 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17368 vty_out(vty, " neighbor %s weight %lu\n", addr,
17369 peer->weight[afi][safi]);
17370
17371 /* Filter. */
17372 bgp_config_write_filter(vty, peer, afi, safi);
17373
17374 /* atribute-unchanged. */
17375 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17376 || (safi != SAFI_EVPN
17377 && peer_af_flag_check(peer, afi, safi,
17378 PEER_FLAG_NEXTHOP_UNCHANGED))
17379 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17380
17381 if (!peer_group_active(peer)
17382 || peergroup_af_flag_check(peer, afi, safi,
17383 PEER_FLAG_AS_PATH_UNCHANGED)
17384 || peergroup_af_flag_check(peer, afi, safi,
17385 PEER_FLAG_NEXTHOP_UNCHANGED)
17386 || peergroup_af_flag_check(peer, afi, safi,
17387 PEER_FLAG_MED_UNCHANGED)) {
17388
17389 vty_out(vty,
17390 " neighbor %s attribute-unchanged%s%s%s\n",
17391 addr,
17392 peer_af_flag_check(peer, afi, safi,
17393 PEER_FLAG_AS_PATH_UNCHANGED)
17394 ? " as-path"
17395 : "",
17396 peer_af_flag_check(peer, afi, safi,
17397 PEER_FLAG_NEXTHOP_UNCHANGED)
17398 ? " next-hop"
17399 : "",
17400 peer_af_flag_check(peer, afi, safi,
17401 PEER_FLAG_MED_UNCHANGED)
17402 ? " med"
17403 : "");
17404 }
17405 }
17406
17407 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_ORR_GROUP))
17408 vty_out(vty, " neighbor %s optimal-route-reflection %s\n",
17409 addr, peer->orr_group_name[afi][safi]);
17410 }
17411
17412 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17413 safi_t safi)
17414 {
17415 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17416 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17417 vty_out(vty, " no bgp retain route-target all\n");
17418 }
17419
17420 /* Address family based peer configuration display. */
17421 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17422 safi_t safi)
17423 {
17424 struct peer *peer;
17425 struct peer_group *group;
17426 struct listnode *node, *nnode;
17427
17428
17429 vty_frame(vty, " !\n address-family ");
17430 if (afi == AFI_IP) {
17431 if (safi == SAFI_UNICAST)
17432 vty_frame(vty, "ipv4 unicast");
17433 else if (safi == SAFI_LABELED_UNICAST)
17434 vty_frame(vty, "ipv4 labeled-unicast");
17435 else if (safi == SAFI_MULTICAST)
17436 vty_frame(vty, "ipv4 multicast");
17437 else if (safi == SAFI_MPLS_VPN)
17438 vty_frame(vty, "ipv4 vpn");
17439 else if (safi == SAFI_ENCAP)
17440 vty_frame(vty, "ipv4 encap");
17441 else if (safi == SAFI_FLOWSPEC)
17442 vty_frame(vty, "ipv4 flowspec");
17443 } else if (afi == AFI_IP6) {
17444 if (safi == SAFI_UNICAST)
17445 vty_frame(vty, "ipv6 unicast");
17446 else if (safi == SAFI_LABELED_UNICAST)
17447 vty_frame(vty, "ipv6 labeled-unicast");
17448 else if (safi == SAFI_MULTICAST)
17449 vty_frame(vty, "ipv6 multicast");
17450 else if (safi == SAFI_MPLS_VPN)
17451 vty_frame(vty, "ipv6 vpn");
17452 else if (safi == SAFI_ENCAP)
17453 vty_frame(vty, "ipv6 encap");
17454 else if (safi == SAFI_FLOWSPEC)
17455 vty_frame(vty, "ipv6 flowspec");
17456 } else if (afi == AFI_L2VPN) {
17457 if (safi == SAFI_EVPN)
17458 vty_frame(vty, "l2vpn evpn");
17459 }
17460 vty_frame(vty, "\n");
17461
17462 bgp_config_write_distance(vty, bgp, afi, safi);
17463
17464 bgp_config_write_network(vty, bgp, afi, safi);
17465
17466 bgp_config_write_redistribute(vty, bgp, afi, safi);
17467
17468 /* BGP flag dampening. */
17469 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17470 bgp_config_write_damp(vty, afi, safi);
17471
17472 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17473 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17474
17475 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17476 /* Do not display doppelganger peers */
17477 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17478 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17479 }
17480
17481 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17482 bgp_config_write_table_map(vty, bgp, afi, safi);
17483
17484 if (safi == SAFI_EVPN)
17485 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17486
17487 if (safi == SAFI_FLOWSPEC)
17488 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17489
17490 if (safi == SAFI_MPLS_VPN)
17491 bgp_vpn_config_write(vty, bgp, afi, safi);
17492
17493 if (safi == SAFI_UNICAST) {
17494 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17495 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17496 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17497
17498 vty_out(vty, " export vpn\n");
17499 }
17500 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17501 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17502
17503 vty_out(vty, " import vpn\n");
17504 }
17505 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17506 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17507 char *name;
17508
17509 for (ALL_LIST_ELEMENTS_RO(
17510 bgp->vpn_policy[afi].import_vrf, node,
17511 name))
17512 vty_out(vty, " import vrf %s\n", name);
17513 }
17514 }
17515
17516 /* Optimal Route Reflection */
17517 bgp_config_write_orr(vty, bgp, afi, safi);
17518
17519 vty_endframe(vty, " exit-address-family\n");
17520 }
17521
17522 int bgp_config_write(struct vty *vty)
17523 {
17524 struct bgp *bgp;
17525 struct peer_group *group;
17526 struct peer *peer;
17527 struct listnode *node, *nnode;
17528 struct listnode *mnode, *mnnode;
17529 afi_t afi;
17530 safi_t safi;
17531
17532 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17533 vty_out(vty, "bgp route-map delay-timer %u\n",
17534 bm->rmap_update_timer);
17535
17536 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17537 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17538 if (bm->v_update_delay != bm->v_establish_wait)
17539 vty_out(vty, " %d", bm->v_establish_wait);
17540 vty_out(vty, "\n");
17541 }
17542
17543 if (bm->wait_for_fib)
17544 vty_out(vty, "bgp suppress-fib-pending\n");
17545
17546 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17547 vty_out(vty, "bgp graceful-shutdown\n");
17548
17549 /* No-RIB (Zebra) option flag configuration */
17550 if (bgp_option_check(BGP_OPT_NO_FIB))
17551 vty_out(vty, "bgp no-rib\n");
17552
17553 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17554 vty_out(vty, "bgp send-extra-data zebra\n");
17555
17556 /* BGP session DSCP value */
17557 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17558 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17559
17560 /* BGP configuration. */
17561 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17562
17563 /* skip all auto created vrf as they dont have user config */
17564 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17565 continue;
17566
17567 /* Router bgp ASN */
17568 vty_out(vty, "router bgp %u", bgp->as);
17569
17570 if (bgp->name)
17571 vty_out(vty, " %s %s",
17572 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17573 ? "view" : "vrf", bgp->name);
17574 vty_out(vty, "\n");
17575
17576 /* BGP fast-external-failover. */
17577 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17578 vty_out(vty, " no bgp fast-external-failover\n");
17579
17580 /* BGP router ID. */
17581 if (bgp->router_id_static.s_addr != INADDR_ANY)
17582 vty_out(vty, " bgp router-id %pI4\n",
17583 &bgp->router_id_static);
17584
17585 /* Suppress fib pending */
17586 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17587 vty_out(vty, " bgp suppress-fib-pending\n");
17588
17589 /* BGP log-neighbor-changes. */
17590 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17591 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17592 vty_out(vty, " %sbgp log-neighbor-changes\n",
17593 CHECK_FLAG(bgp->flags,
17594 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17595 ? ""
17596 : "no ");
17597
17598 /* BGP configuration. */
17599 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17600 vty_out(vty, " bgp always-compare-med\n");
17601
17602 /* RFC8212 default eBGP policy. */
17603 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17604 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17605 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17606 CHECK_FLAG(bgp->flags,
17607 BGP_FLAG_EBGP_REQUIRES_POLICY)
17608 ? ""
17609 : "no ");
17610
17611 /* draft-ietf-idr-deprecate-as-set-confed-set */
17612 if (bgp->reject_as_sets)
17613 vty_out(vty, " bgp reject-as-sets\n");
17614
17615 /* Suppress duplicate updates if the route actually not changed
17616 */
17617 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17618 != SAVE_BGP_SUPPRESS_DUPLICATES)
17619 vty_out(vty, " %sbgp suppress-duplicates\n",
17620 CHECK_FLAG(bgp->flags,
17621 BGP_FLAG_SUPPRESS_DUPLICATES)
17622 ? ""
17623 : "no ");
17624
17625 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17626 */
17627 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17628 SAVE_BGP_HARD_ADMIN_RESET)
17629 vty_out(vty, " %sbgp hard-administrative-reset\n",
17630 CHECK_FLAG(bgp->flags,
17631 BGP_FLAG_HARD_ADMIN_RESET)
17632 ? ""
17633 : "no ");
17634
17635 /* BGP default <afi>-<safi> */
17636 FOREACH_AFI_SAFI (afi, safi) {
17637 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17638 if (!bgp->default_af[afi][safi])
17639 vty_out(vty, " no bgp default %s\n",
17640 get_bgp_default_af_flag(afi,
17641 safi));
17642 } else if (bgp->default_af[afi][safi])
17643 vty_out(vty, " bgp default %s\n",
17644 get_bgp_default_af_flag(afi, safi));
17645 }
17646
17647 /* BGP default local-preference. */
17648 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17649 vty_out(vty, " bgp default local-preference %u\n",
17650 bgp->default_local_pref);
17651
17652 /* BGP default show-hostname */
17653 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17654 != SAVE_BGP_SHOW_HOSTNAME)
17655 vty_out(vty, " %sbgp default show-hostname\n",
17656 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17657 ? ""
17658 : "no ");
17659
17660 /* BGP default show-nexthop-hostname */
17661 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17662 != SAVE_BGP_SHOW_HOSTNAME)
17663 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17664 CHECK_FLAG(bgp->flags,
17665 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17666 ? ""
17667 : "no ");
17668
17669 /* BGP default subgroup-pkt-queue-max. */
17670 if (bgp->default_subgroup_pkt_queue_max
17671 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17672 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17673 bgp->default_subgroup_pkt_queue_max);
17674
17675 /* BGP client-to-client reflection. */
17676 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17677 vty_out(vty, " no bgp client-to-client reflection\n");
17678
17679 /* BGP cluster ID. */
17680 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17681 vty_out(vty, " bgp cluster-id %pI4\n",
17682 &bgp->cluster_id);
17683
17684 /* Disable ebgp connected nexthop check */
17685 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17686 vty_out(vty,
17687 " bgp disable-ebgp-connected-route-check\n");
17688
17689 /* Confederation identifier*/
17690 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17691 vty_out(vty, " bgp confederation identifier %u\n",
17692 bgp->confed_id);
17693
17694 /* Confederation peer */
17695 if (bgp->confed_peers_cnt > 0) {
17696 int i;
17697
17698 vty_out(vty, " bgp confederation peers");
17699
17700 for (i = 0; i < bgp->confed_peers_cnt; i++)
17701 vty_out(vty, " %u", bgp->confed_peers[i]);
17702
17703 vty_out(vty, "\n");
17704 }
17705
17706 /* BGP deterministic-med. */
17707 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17708 != SAVE_BGP_DETERMINISTIC_MED)
17709 vty_out(vty, " %sbgp deterministic-med\n",
17710 CHECK_FLAG(bgp->flags,
17711 BGP_FLAG_DETERMINISTIC_MED)
17712 ? ""
17713 : "no ");
17714
17715 /* BGP update-delay. */
17716 bgp_config_write_update_delay(vty, bgp);
17717
17718 if (bgp->v_maxmed_onstartup
17719 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17720 vty_out(vty, " bgp max-med on-startup %u",
17721 bgp->v_maxmed_onstartup);
17722 if (bgp->maxmed_onstartup_value
17723 != BGP_MAXMED_VALUE_DEFAULT)
17724 vty_out(vty, " %u",
17725 bgp->maxmed_onstartup_value);
17726 vty_out(vty, "\n");
17727 }
17728 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17729 vty_out(vty, " bgp max-med administrative");
17730 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17731 vty_out(vty, " %u", bgp->maxmed_admin_value);
17732 vty_out(vty, "\n");
17733 }
17734
17735 /* write quanta */
17736 bgp_config_write_wpkt_quanta(vty, bgp);
17737 /* read quanta */
17738 bgp_config_write_rpkt_quanta(vty, bgp);
17739
17740 /* coalesce time */
17741 bgp_config_write_coalesce_time(vty, bgp);
17742
17743 /* BGP per-instance graceful-shutdown */
17744 /* BGP-wide settings and per-instance settings are mutually
17745 * exclusive.
17746 */
17747 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17748 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17749 vty_out(vty, " bgp graceful-shutdown\n");
17750
17751 /* Long-lived Graceful Restart */
17752 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17753 vty_out(vty,
17754 " bgp long-lived-graceful-restart stale-time %u\n",
17755 bgp->llgr_stale_time);
17756
17757 /* BGP graceful-restart. */
17758 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17759 vty_out(vty,
17760 " bgp graceful-restart stalepath-time %u\n",
17761 bgp->stalepath_time);
17762
17763 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17764 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17765 bgp->restart_time);
17766
17767 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17768 SAVE_BGP_GRACEFUL_NOTIFICATION)
17769 vty_out(vty, " %sbgp graceful-restart notification\n",
17770 CHECK_FLAG(bgp->flags,
17771 BGP_FLAG_GRACEFUL_NOTIFICATION)
17772 ? ""
17773 : "no ");
17774
17775 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17776 vty_out(vty,
17777 " bgp graceful-restart select-defer-time %u\n",
17778 bgp->select_defer_time);
17779
17780 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17781 vty_out(vty, " bgp graceful-restart\n");
17782
17783 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17784 vty_out(vty, " bgp graceful-restart-disable\n");
17785
17786 /* BGP graceful-restart Preserve State F bit. */
17787 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17788 vty_out(vty,
17789 " bgp graceful-restart preserve-fw-state\n");
17790
17791 /* BGP TCP keepalive */
17792 bgp_config_tcp_keepalive(vty, bgp);
17793
17794 /* Stale timer for RIB */
17795 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17796 vty_out(vty,
17797 " bgp graceful-restart rib-stale-time %u\n",
17798 bgp->rib_stale_time);
17799
17800 /* BGP bestpath method. */
17801 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17802 vty_out(vty, " bgp bestpath as-path ignore\n");
17803 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17804 vty_out(vty, " bgp bestpath as-path confed\n");
17805
17806 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17807 if (CHECK_FLAG(bgp->flags,
17808 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17809 vty_out(vty,
17810 " bgp bestpath as-path multipath-relax as-set\n");
17811 } else {
17812 vty_out(vty,
17813 " bgp bestpath as-path multipath-relax\n");
17814 }
17815 }
17816
17817 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17818 vty_out(vty,
17819 " bgp route-reflector allow-outbound-policy\n");
17820 }
17821 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17822 vty_out(vty, " bgp bestpath compare-routerid\n");
17823 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17824 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17825 vty_out(vty, " bgp bestpath med");
17826 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17827 vty_out(vty, " confed");
17828 if (CHECK_FLAG(bgp->flags,
17829 BGP_FLAG_MED_MISSING_AS_WORST))
17830 vty_out(vty, " missing-as-worst");
17831 vty_out(vty, "\n");
17832 }
17833
17834 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17835 vty_out(vty,
17836 " bgp bestpath peer-type multipath-relax\n");
17837
17838 /* Link bandwidth handling. */
17839 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17840 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17841 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17842 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17843 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17844 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17845
17846 /* BGP network import check. */
17847 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17848 != SAVE_BGP_IMPORT_CHECK)
17849 vty_out(vty, " %sbgp network import-check\n",
17850 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17851 ? ""
17852 : "no ");
17853
17854 /* BGP timers configuration. */
17855 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17856 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17857 vty_out(vty, " timers bgp %u %u\n",
17858 bgp->default_keepalive, bgp->default_holdtime);
17859
17860 /* BGP minimum holdtime configuration. */
17861 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17862 && bgp->default_min_holdtime != 0)
17863 vty_out(vty, " bgp minimum-holdtime %u\n",
17864 bgp->default_min_holdtime);
17865
17866 /* Conditional advertisement timer configuration */
17867 if (bgp->condition_check_period
17868 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17869 vty_out(vty,
17870 " bgp conditional-advertisement timer %u\n",
17871 bgp->condition_check_period);
17872
17873 /* peer-group */
17874 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17875 bgp_config_write_peer_global(vty, bgp, group->conf);
17876 }
17877
17878 /* Normal neighbor configuration. */
17879 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17880 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17881 bgp_config_write_peer_global(vty, bgp, peer);
17882 }
17883
17884 /* listen range and limit for dynamic BGP neighbors */
17885 bgp_config_write_listen(vty, bgp);
17886
17887 /*
17888 * BGP default autoshutdown neighbors
17889 *
17890 * This must be placed after any peer and peer-group
17891 * configuration, to avoid setting all peers to shutdown after
17892 * a daemon restart, which is undesired behavior. (see #2286)
17893 */
17894 if (bgp->autoshutdown)
17895 vty_out(vty, " bgp default shutdown\n");
17896
17897 /* BGP instance administrative shutdown */
17898 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17899 vty_out(vty, " bgp shutdown\n");
17900
17901 if (bgp->allow_martian)
17902 vty_out(vty, " bgp allow-martian-nexthop\n");
17903
17904 if (bgp->fast_convergence)
17905 vty_out(vty, " bgp fast-convergence\n");
17906
17907 if (bgp->srv6_enabled) {
17908 vty_frame(vty, " !\n segment-routing srv6\n");
17909 if (strlen(bgp->srv6_locator_name))
17910 vty_out(vty, " locator %s\n",
17911 bgp->srv6_locator_name);
17912 vty_endframe(vty, " exit\n");
17913 }
17914
17915
17916 /* IPv4 unicast configuration. */
17917 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17918
17919 /* IPv4 multicast configuration. */
17920 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17921
17922 /* IPv4 labeled-unicast configuration. */
17923 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17924
17925 /* IPv4 VPN configuration. */
17926 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17927
17928 /* ENCAPv4 configuration. */
17929 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17930
17931 /* FLOWSPEC v4 configuration. */
17932 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17933
17934 /* IPv6 unicast configuration. */
17935 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17936
17937 /* IPv6 multicast configuration. */
17938 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17939
17940 /* IPv6 labeled-unicast configuration. */
17941 bgp_config_write_family(vty, bgp, AFI_IP6,
17942 SAFI_LABELED_UNICAST);
17943
17944 /* IPv6 VPN configuration. */
17945 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17946
17947 /* ENCAPv6 configuration. */
17948 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17949
17950 /* FLOWSPEC v6 configuration. */
17951 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17952
17953 /* EVPN configuration. */
17954 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17955
17956 hook_call(bgp_inst_config_write, bgp, vty);
17957
17958 #ifdef ENABLE_BGP_VNC
17959 bgp_rfapi_cfg_write(vty, bgp);
17960 #endif
17961
17962 vty_out(vty, "exit\n");
17963 vty_out(vty, "!\n");
17964 }
17965 return 0;
17966 }
17967
17968
17969 /* BGP node structure. */
17970 static struct cmd_node bgp_node = {
17971 .name = "bgp",
17972 .node = BGP_NODE,
17973 .parent_node = CONFIG_NODE,
17974 .prompt = "%s(config-router)# ",
17975 .config_write = bgp_config_write,
17976 };
17977
17978 static struct cmd_node bgp_ipv4_unicast_node = {
17979 .name = "bgp ipv4 unicast",
17980 .node = BGP_IPV4_NODE,
17981 .parent_node = BGP_NODE,
17982 .prompt = "%s(config-router-af)# ",
17983 .no_xpath = true,
17984 };
17985
17986 static struct cmd_node bgp_ipv4_multicast_node = {
17987 .name = "bgp ipv4 multicast",
17988 .node = BGP_IPV4M_NODE,
17989 .parent_node = BGP_NODE,
17990 .prompt = "%s(config-router-af)# ",
17991 .no_xpath = true,
17992 };
17993
17994 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17995 .name = "bgp ipv4 labeled unicast",
17996 .node = BGP_IPV4L_NODE,
17997 .parent_node = BGP_NODE,
17998 .prompt = "%s(config-router-af)# ",
17999 .no_xpath = true,
18000 };
18001
18002 static struct cmd_node bgp_ipv6_unicast_node = {
18003 .name = "bgp ipv6 unicast",
18004 .node = BGP_IPV6_NODE,
18005 .parent_node = BGP_NODE,
18006 .prompt = "%s(config-router-af)# ",
18007 .no_xpath = true,
18008 };
18009
18010 static struct cmd_node bgp_ipv6_multicast_node = {
18011 .name = "bgp ipv6 multicast",
18012 .node = BGP_IPV6M_NODE,
18013 .parent_node = BGP_NODE,
18014 .prompt = "%s(config-router-af)# ",
18015 .no_xpath = true,
18016 };
18017
18018 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18019 .name = "bgp ipv6 labeled unicast",
18020 .node = BGP_IPV6L_NODE,
18021 .parent_node = BGP_NODE,
18022 .prompt = "%s(config-router-af)# ",
18023 .no_xpath = true,
18024 };
18025
18026 static struct cmd_node bgp_vpnv4_node = {
18027 .name = "bgp vpnv4",
18028 .node = BGP_VPNV4_NODE,
18029 .parent_node = BGP_NODE,
18030 .prompt = "%s(config-router-af)# ",
18031 .no_xpath = true,
18032 };
18033
18034 static struct cmd_node bgp_vpnv6_node = {
18035 .name = "bgp vpnv6",
18036 .node = BGP_VPNV6_NODE,
18037 .parent_node = BGP_NODE,
18038 .prompt = "%s(config-router-af-vpnv6)# ",
18039 .no_xpath = true,
18040 };
18041
18042 static struct cmd_node bgp_evpn_node = {
18043 .name = "bgp evpn",
18044 .node = BGP_EVPN_NODE,
18045 .parent_node = BGP_NODE,
18046 .prompt = "%s(config-router-evpn)# ",
18047 .no_xpath = true,
18048 };
18049
18050 static struct cmd_node bgp_evpn_vni_node = {
18051 .name = "bgp evpn vni",
18052 .node = BGP_EVPN_VNI_NODE,
18053 .parent_node = BGP_EVPN_NODE,
18054 .prompt = "%s(config-router-af-vni)# ",
18055 };
18056
18057 static struct cmd_node bgp_flowspecv4_node = {
18058 .name = "bgp ipv4 flowspec",
18059 .node = BGP_FLOWSPECV4_NODE,
18060 .parent_node = BGP_NODE,
18061 .prompt = "%s(config-router-af)# ",
18062 .no_xpath = true,
18063 };
18064
18065 static struct cmd_node bgp_flowspecv6_node = {
18066 .name = "bgp ipv6 flowspec",
18067 .node = BGP_FLOWSPECV6_NODE,
18068 .parent_node = BGP_NODE,
18069 .prompt = "%s(config-router-af-vpnv6)# ",
18070 .no_xpath = true,
18071 };
18072
18073 static struct cmd_node bgp_srv6_node = {
18074 .name = "bgp srv6",
18075 .node = BGP_SRV6_NODE,
18076 .parent_node = BGP_NODE,
18077 .prompt = "%s(config-router-srv6)# ",
18078 };
18079
18080 static void community_list_vty(void);
18081
18082 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18083 {
18084 struct bgp *bgp;
18085 struct peer_group *group;
18086 struct listnode *lnbgp, *lnpeer;
18087
18088 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18089 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18090 vector_set(comps,
18091 XSTRDUP(MTYPE_COMPLETION, group->name));
18092 }
18093 }
18094
18095 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18096 {
18097 struct bgp *bgp;
18098 struct peer *peer;
18099 struct listnode *lnbgp, *lnpeer;
18100
18101 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18102 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18103 /* only provide suggestions on the appropriate input
18104 * token type,
18105 * they'll otherwise show up multiple times */
18106 enum cmd_token_type match_type;
18107 char *name = peer->host;
18108
18109 if (peer->conf_if) {
18110 match_type = VARIABLE_TKN;
18111 name = peer->conf_if;
18112 } else if (strchr(peer->host, ':'))
18113 match_type = IPV6_TKN;
18114 else
18115 match_type = IPV4_TKN;
18116
18117 if (token->type != match_type)
18118 continue;
18119
18120 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18121 }
18122 }
18123 }
18124
18125 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18126 {
18127 bgp_ac_peer(comps, token);
18128
18129 if (token->type == VARIABLE_TKN)
18130 bgp_ac_peergroup(comps, token);
18131 }
18132
18133 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18134 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18135 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18136 {.varname = "peer", .completions = bgp_ac_neighbor},
18137 {.completions = NULL}};
18138
18139 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18140 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18141 {.completions = NULL} };
18142
18143 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18144
18145 static struct thread *t_bgp_cfg;
18146
18147 bool bgp_config_inprocess(void)
18148 {
18149 return thread_is_scheduled(t_bgp_cfg);
18150 }
18151
18152 static void bgp_config_finish(struct thread *t)
18153 {
18154 struct listnode *node;
18155 struct bgp *bgp;
18156
18157 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18158 hook_call(bgp_config_end, bgp);
18159 }
18160
18161 static void bgp_config_start(void)
18162 {
18163 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18164 THREAD_OFF(t_bgp_cfg);
18165 thread_add_timer(bm->master, bgp_config_finish, NULL,
18166 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18167 }
18168
18169 /* When we receive a hook the configuration is read,
18170 * we start a timer to make sure we postpone sending
18171 * EoR before route-maps are processed.
18172 * This is especially valid if using `bgp route-map delay-timer`.
18173 */
18174 static void bgp_config_end(void)
18175 {
18176 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18177 uint32_t bgp_post_config_delay =
18178 thread_is_scheduled(bm->t_rmap_update)
18179 ? thread_timer_remain_second(bm->t_rmap_update)
18180 : BGP_POST_CONFIG_DELAY_SECONDS;
18181
18182 /* If BGP config processing thread isn't running, then
18183 * we can return and rely it's properly handled.
18184 */
18185 if (!bgp_config_inprocess())
18186 return;
18187
18188 THREAD_OFF(t_bgp_cfg);
18189
18190 /* Start a new timer to make sure we don't send EoR
18191 * before route-maps are processed.
18192 */
18193 thread_add_timer(bm->master, bgp_config_finish, NULL,
18194 bgp_post_config_delay, &t_bgp_cfg);
18195 }
18196
18197 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18198 {
18199 int write = 0;
18200 struct interface *ifp;
18201 struct bgp_interface *iifp;
18202
18203 FOR_ALL_INTERFACES (vrf, ifp) {
18204 iifp = ifp->info;
18205 if (!iifp)
18206 continue;
18207
18208 if_vty_config_start(vty, ifp);
18209
18210 if (CHECK_FLAG(iifp->flags,
18211 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18212 vty_out(vty, " mpls bgp forwarding\n");
18213 write++;
18214 }
18215
18216 if_vty_config_end(vty);
18217 }
18218
18219 return write;
18220 }
18221
18222 /* Configuration write function for bgpd. */
18223 static int config_write_interface(struct vty *vty)
18224 {
18225 int write = 0;
18226 struct vrf *vrf = NULL;
18227
18228 /* Display all VRF aware OSPF interface configuration */
18229 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18230 write += config_write_interface_one(vty, vrf);
18231 }
18232
18233 return write;
18234 }
18235
18236 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18237 "[no$no] mpls bgp forwarding",
18238 NO_STR MPLS_STR BGP_STR
18239 "Enable MPLS forwarding for eBGP directly connected peers\n")
18240 {
18241 bool check;
18242 struct bgp_interface *iifp;
18243
18244 VTY_DECLVAR_CONTEXT(interface, ifp);
18245 iifp = ifp->info;
18246 if (!iifp) {
18247 vty_out(vty, "Interface %s not available\n", ifp->name);
18248 return CMD_WARNING_CONFIG_FAILED;
18249 }
18250 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18251 if (check != !no) {
18252 if (no)
18253 UNSET_FLAG(iifp->flags,
18254 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18255 else
18256 SET_FLAG(iifp->flags,
18257 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18258 /* trigger a nht update on eBGP sessions */
18259 if (if_is_operative(ifp))
18260 bgp_nht_ifp_up(ifp);
18261 }
18262 return CMD_SUCCESS;
18263 }
18264
18265 /* Initialization of BGP interface. */
18266 static void bgp_vty_if_init(void)
18267 {
18268 /* Install interface node. */
18269 if_cmd_init(config_write_interface);
18270
18271 /* "mpls bgp forwarding" commands. */
18272 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18273 }
18274
18275 void bgp_vty_init(void)
18276 {
18277 cmd_variable_handler_register(bgp_var_neighbor);
18278 cmd_variable_handler_register(bgp_var_peergroup);
18279
18280 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18281
18282 /* Install bgp top node. */
18283 install_node(&bgp_node);
18284 install_node(&bgp_ipv4_unicast_node);
18285 install_node(&bgp_ipv4_multicast_node);
18286 install_node(&bgp_ipv4_labeled_unicast_node);
18287 install_node(&bgp_ipv6_unicast_node);
18288 install_node(&bgp_ipv6_multicast_node);
18289 install_node(&bgp_ipv6_labeled_unicast_node);
18290 install_node(&bgp_vpnv4_node);
18291 install_node(&bgp_vpnv6_node);
18292 install_node(&bgp_evpn_node);
18293 install_node(&bgp_evpn_vni_node);
18294 install_node(&bgp_flowspecv4_node);
18295 install_node(&bgp_flowspecv6_node);
18296 install_node(&bgp_srv6_node);
18297
18298 /* Install default VTY commands to new nodes. */
18299 install_default(BGP_NODE);
18300 install_default(BGP_IPV4_NODE);
18301 install_default(BGP_IPV4M_NODE);
18302 install_default(BGP_IPV4L_NODE);
18303 install_default(BGP_IPV6_NODE);
18304 install_default(BGP_IPV6M_NODE);
18305 install_default(BGP_IPV6L_NODE);
18306 install_default(BGP_VPNV4_NODE);
18307 install_default(BGP_VPNV6_NODE);
18308 install_default(BGP_FLOWSPECV4_NODE);
18309 install_default(BGP_FLOWSPECV6_NODE);
18310 install_default(BGP_EVPN_NODE);
18311 install_default(BGP_EVPN_VNI_NODE);
18312 install_default(BGP_SRV6_NODE);
18313
18314 /* "bgp local-mac" hidden commands. */
18315 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18316 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18317
18318 /* "bgp suppress-fib-pending" global */
18319 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18320
18321 /* bgp route-map delay-timer commands. */
18322 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18323 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18324
18325 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18326
18327 /* bgp fast-convergence command */
18328 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18329 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18330
18331 /* global bgp update-delay command */
18332 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18333 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18334
18335 /* global bgp graceful-shutdown command */
18336 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18337 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18338
18339 /* Dummy commands (Currently not supported) */
18340 install_element(BGP_NODE, &no_synchronization_cmd);
18341 install_element(BGP_NODE, &no_auto_summary_cmd);
18342
18343 /* "router bgp" commands. */
18344 install_element(CONFIG_NODE, &router_bgp_cmd);
18345
18346 /* "no router bgp" commands. */
18347 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18348
18349 /* "bgp session-dscp command */
18350 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18351 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18352
18353 /* "bgp router-id" commands. */
18354 install_element(BGP_NODE, &bgp_router_id_cmd);
18355 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18356
18357 /* "bgp suppress-fib-pending" command */
18358 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18359
18360 /* "bgp cluster-id" commands. */
18361 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18362 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18363
18364 /* "bgp no-rib" commands. */
18365 install_element(CONFIG_NODE, &bgp_norib_cmd);
18366 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18367
18368 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18369
18370 /* "bgp confederation" commands. */
18371 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18372 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18373
18374 /* "bgp confederation peers" commands. */
18375 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18376 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18377
18378 /* bgp max-med command */
18379 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18380 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18381 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18382 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18383 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18384
18385 /* "neighbor role" commands. */
18386 install_element(BGP_NODE, &neighbor_role_cmd);
18387 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18388 install_element(BGP_NODE, &no_neighbor_role_cmd);
18389
18390 /* bgp disable-ebgp-connected-nh-check */
18391 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18392 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18393
18394 /* bgp update-delay command */
18395 install_element(BGP_NODE, &bgp_update_delay_cmd);
18396 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18397
18398 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18399 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18400
18401 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18402 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18403
18404 /* "maximum-paths" commands. */
18405 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18406 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18407 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18408 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18409 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18410 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18411 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18412 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18413 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18414 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18415 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18416 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18417 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18418 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18419 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18420
18421 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18422 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18423 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18424 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18425 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18426 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18427 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18428 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18429 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18430 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18431
18432 /* "timers bgp" commands. */
18433 install_element(BGP_NODE, &bgp_timers_cmd);
18434 install_element(BGP_NODE, &no_bgp_timers_cmd);
18435
18436 /* "minimum-holdtime" commands. */
18437 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18438 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18439
18440 /* route-map delay-timer commands - per instance for backwards compat.
18441 */
18442 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18443 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18444
18445 /* "bgp client-to-client reflection" commands */
18446 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18447 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18448
18449 /* "bgp always-compare-med" commands */
18450 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18451 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18452
18453 /* bgp ebgp-requires-policy */
18454 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18455 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18456
18457 /* bgp suppress-duplicates */
18458 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18459 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18460
18461 /* bgp reject-as-sets */
18462 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18463 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18464
18465 /* "bgp deterministic-med" commands */
18466 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18467 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18468
18469 /* "bgp graceful-restart" command */
18470 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18471 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18472
18473 /* "bgp graceful-restart-disable" command */
18474 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18475 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18476
18477 /* "neighbor a:b:c:d graceful-restart" command */
18478 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18479 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18480
18481 /* "neighbor a:b:c:d graceful-restart-disable" command */
18482 install_element(BGP_NODE,
18483 &bgp_neighbor_graceful_restart_disable_set_cmd);
18484 install_element(BGP_NODE,
18485 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18486
18487 /* "neighbor a:b:c:d graceful-restart-helper" command */
18488 install_element(BGP_NODE,
18489 &bgp_neighbor_graceful_restart_helper_set_cmd);
18490 install_element(BGP_NODE,
18491 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18492
18493 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18494 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18495 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18496 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18497 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18498 install_element(BGP_NODE,
18499 &no_bgp_graceful_restart_select_defer_time_cmd);
18500 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18501 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18502 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18503
18504 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18505 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18506 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18507 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18508
18509 /* "bgp graceful-shutdown" commands */
18510 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18511 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18512
18513 /* "bgp hard-administrative-reset" commands */
18514 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18515
18516 /* "bgp long-lived-graceful-restart" commands */
18517 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18518 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18519
18520 /* "bgp fast-external-failover" commands */
18521 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18522 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18523
18524 /* "bgp bestpath compare-routerid" commands */
18525 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18526 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18527
18528 /* "bgp bestpath as-path ignore" commands */
18529 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18530 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18531
18532 /* "bgp bestpath as-path confed" commands */
18533 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18534 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18535
18536 /* "bgp bestpath as-path multipath-relax" commands */
18537 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18538 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18539
18540 /* "bgp bestpath peer-type multipath-relax" commands */
18541 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18542 install_element(BGP_NODE,
18543 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18544
18545 /* "bgp log-neighbor-changes" commands */
18546 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18547 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18548
18549 /* "bgp bestpath med" commands */
18550 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18551 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18552
18553 /* "bgp bestpath bandwidth" commands */
18554 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18555 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18556
18557 /* "no bgp default <afi>-<safi>" commands. */
18558 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18559
18560 /* "bgp network import-check" commands. */
18561 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18562 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18563 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18564
18565 /* "bgp default local-preference" commands. */
18566 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18567 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18568
18569 /* bgp default show-hostname */
18570 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18571 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18572
18573 /* bgp default show-nexthop-hostname */
18574 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18575 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18576
18577 /* "bgp default subgroup-pkt-queue-max" commands. */
18578 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18579 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18580
18581 /* bgp ibgp-allow-policy-mods command */
18582 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18583 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18584
18585 /* "bgp listen limit" commands. */
18586 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18587 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18588
18589 /* "bgp listen range" commands. */
18590 install_element(BGP_NODE, &bgp_listen_range_cmd);
18591 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18592
18593 /* "bgp default shutdown" command */
18594 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18595
18596 /* "bgp shutdown" commands */
18597 install_element(BGP_NODE, &bgp_shutdown_cmd);
18598 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18599 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18600 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18601
18602 /* "neighbor remote-as" commands. */
18603 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18604 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18605 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18606 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18607 install_element(BGP_NODE,
18608 &neighbor_interface_v6only_config_remote_as_cmd);
18609 install_element(BGP_NODE, &no_neighbor_cmd);
18610 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18611
18612 /* "neighbor peer-group" commands. */
18613 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18614 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18615 install_element(BGP_NODE,
18616 &no_neighbor_interface_peer_group_remote_as_cmd);
18617
18618 /* "neighbor local-as" commands. */
18619 install_element(BGP_NODE, &neighbor_local_as_cmd);
18620 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18621 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18622 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18623
18624 /* "neighbor solo" commands. */
18625 install_element(BGP_NODE, &neighbor_solo_cmd);
18626 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18627
18628 /* "neighbor password" commands. */
18629 install_element(BGP_NODE, &neighbor_password_cmd);
18630 install_element(BGP_NODE, &no_neighbor_password_cmd);
18631
18632 /* "neighbor activate" commands. */
18633 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18634 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18635 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18636 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18637 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18638 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18639 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18640 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18641 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18642 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18643 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18644 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18645
18646 /* "no neighbor activate" commands. */
18647 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18648 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18649 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18650 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18651 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18652 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18653 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18654 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18655 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18656 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18657 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18658 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18659
18660 /* "neighbor peer-group" set commands. */
18661 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18662 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18663 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18664 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18665 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18666 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18667 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18668 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18669 install_element(BGP_FLOWSPECV4_NODE,
18670 &neighbor_set_peer_group_hidden_cmd);
18671 install_element(BGP_FLOWSPECV6_NODE,
18672 &neighbor_set_peer_group_hidden_cmd);
18673
18674 /* "no neighbor peer-group unset" commands. */
18675 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18676 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18677 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18678 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18679 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18680 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18681 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18682 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18683 install_element(BGP_FLOWSPECV4_NODE,
18684 &no_neighbor_set_peer_group_hidden_cmd);
18685 install_element(BGP_FLOWSPECV6_NODE,
18686 &no_neighbor_set_peer_group_hidden_cmd);
18687
18688 /* "neighbor softreconfiguration inbound" commands.*/
18689 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18690 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18691 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18692 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18693 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18694 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18695 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18696 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18697 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18698 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18699 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18700 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18701 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18702 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18703 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18704 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18705 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18706 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18707 install_element(BGP_FLOWSPECV4_NODE,
18708 &neighbor_soft_reconfiguration_cmd);
18709 install_element(BGP_FLOWSPECV4_NODE,
18710 &no_neighbor_soft_reconfiguration_cmd);
18711 install_element(BGP_FLOWSPECV6_NODE,
18712 &neighbor_soft_reconfiguration_cmd);
18713 install_element(BGP_FLOWSPECV6_NODE,
18714 &no_neighbor_soft_reconfiguration_cmd);
18715 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18716 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18717
18718 /* "neighbor attribute-unchanged" commands. */
18719 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18720 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18721 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18722 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18723 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18724 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18725 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18726 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18727 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18728 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18729 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18730 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18731 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18732 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18733 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18734 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18735 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18736 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18737
18738 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18739 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18740
18741 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18742 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18743 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18744 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18745
18746 /* "nexthop-local unchanged" commands */
18747 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18748 install_element(BGP_IPV6_NODE,
18749 &no_neighbor_nexthop_local_unchanged_cmd);
18750
18751 /* "neighbor next-hop-self" commands. */
18752 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18753 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18754 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18755 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18756 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18757 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18758 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18759 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18760 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18761 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18762 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18763 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18764 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18765 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18766 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18767 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18768 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18769 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18770 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18771 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18772
18773 /* "neighbor next-hop-self force" commands. */
18774 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18775 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18776 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18777 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18778 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18779 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18780 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18781 install_element(BGP_IPV4_NODE,
18782 &no_neighbor_nexthop_self_all_hidden_cmd);
18783 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18784 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18785 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18786 install_element(BGP_IPV4M_NODE,
18787 &no_neighbor_nexthop_self_all_hidden_cmd);
18788 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18789 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18790 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18791 install_element(BGP_IPV4L_NODE,
18792 &no_neighbor_nexthop_self_all_hidden_cmd);
18793 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18794 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18795 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18796 install_element(BGP_IPV6_NODE,
18797 &no_neighbor_nexthop_self_all_hidden_cmd);
18798 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18799 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18800 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18801 install_element(BGP_IPV6M_NODE,
18802 &no_neighbor_nexthop_self_all_hidden_cmd);
18803 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18804 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18805 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18806 install_element(BGP_IPV6L_NODE,
18807 &no_neighbor_nexthop_self_all_hidden_cmd);
18808 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18809 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18810 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18811 install_element(BGP_VPNV4_NODE,
18812 &no_neighbor_nexthop_self_all_hidden_cmd);
18813 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18814 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18815 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18816 install_element(BGP_VPNV6_NODE,
18817 &no_neighbor_nexthop_self_all_hidden_cmd);
18818 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18819 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18820
18821 /* "neighbor as-override" commands. */
18822 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18823 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18824 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18825 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18826 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18827 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18828 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18829 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18830 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18831 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18832 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18833 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18834 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18835 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18836 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18837 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18838 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18839 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18840
18841 /* "neighbor remove-private-AS" commands. */
18842 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18843 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18844 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18845 install_element(BGP_NODE,
18846 &no_neighbor_remove_private_as_all_hidden_cmd);
18847 install_element(BGP_NODE,
18848 &neighbor_remove_private_as_replace_as_hidden_cmd);
18849 install_element(BGP_NODE,
18850 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18851 install_element(BGP_NODE,
18852 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18853 install_element(
18854 BGP_NODE,
18855 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18856 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18857 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18858 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18859 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18860 install_element(BGP_IPV4_NODE,
18861 &neighbor_remove_private_as_replace_as_cmd);
18862 install_element(BGP_IPV4_NODE,
18863 &no_neighbor_remove_private_as_replace_as_cmd);
18864 install_element(BGP_IPV4_NODE,
18865 &neighbor_remove_private_as_all_replace_as_cmd);
18866 install_element(BGP_IPV4_NODE,
18867 &no_neighbor_remove_private_as_all_replace_as_cmd);
18868 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18869 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18870 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18871 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18872 install_element(BGP_IPV4M_NODE,
18873 &neighbor_remove_private_as_replace_as_cmd);
18874 install_element(BGP_IPV4M_NODE,
18875 &no_neighbor_remove_private_as_replace_as_cmd);
18876 install_element(BGP_IPV4M_NODE,
18877 &neighbor_remove_private_as_all_replace_as_cmd);
18878 install_element(BGP_IPV4M_NODE,
18879 &no_neighbor_remove_private_as_all_replace_as_cmd);
18880 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18881 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18882 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18883 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18884 install_element(BGP_IPV4L_NODE,
18885 &neighbor_remove_private_as_replace_as_cmd);
18886 install_element(BGP_IPV4L_NODE,
18887 &no_neighbor_remove_private_as_replace_as_cmd);
18888 install_element(BGP_IPV4L_NODE,
18889 &neighbor_remove_private_as_all_replace_as_cmd);
18890 install_element(BGP_IPV4L_NODE,
18891 &no_neighbor_remove_private_as_all_replace_as_cmd);
18892 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18893 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18894 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18895 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18896 install_element(BGP_IPV6_NODE,
18897 &neighbor_remove_private_as_replace_as_cmd);
18898 install_element(BGP_IPV6_NODE,
18899 &no_neighbor_remove_private_as_replace_as_cmd);
18900 install_element(BGP_IPV6_NODE,
18901 &neighbor_remove_private_as_all_replace_as_cmd);
18902 install_element(BGP_IPV6_NODE,
18903 &no_neighbor_remove_private_as_all_replace_as_cmd);
18904 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18905 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18906 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18907 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18908 install_element(BGP_IPV6M_NODE,
18909 &neighbor_remove_private_as_replace_as_cmd);
18910 install_element(BGP_IPV6M_NODE,
18911 &no_neighbor_remove_private_as_replace_as_cmd);
18912 install_element(BGP_IPV6M_NODE,
18913 &neighbor_remove_private_as_all_replace_as_cmd);
18914 install_element(BGP_IPV6M_NODE,
18915 &no_neighbor_remove_private_as_all_replace_as_cmd);
18916 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18917 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18918 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18919 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18920 install_element(BGP_IPV6L_NODE,
18921 &neighbor_remove_private_as_replace_as_cmd);
18922 install_element(BGP_IPV6L_NODE,
18923 &no_neighbor_remove_private_as_replace_as_cmd);
18924 install_element(BGP_IPV6L_NODE,
18925 &neighbor_remove_private_as_all_replace_as_cmd);
18926 install_element(BGP_IPV6L_NODE,
18927 &no_neighbor_remove_private_as_all_replace_as_cmd);
18928 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18929 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18930 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18931 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18932 install_element(BGP_VPNV4_NODE,
18933 &neighbor_remove_private_as_replace_as_cmd);
18934 install_element(BGP_VPNV4_NODE,
18935 &no_neighbor_remove_private_as_replace_as_cmd);
18936 install_element(BGP_VPNV4_NODE,
18937 &neighbor_remove_private_as_all_replace_as_cmd);
18938 install_element(BGP_VPNV4_NODE,
18939 &no_neighbor_remove_private_as_all_replace_as_cmd);
18940 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18941 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18942 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18943 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18944 install_element(BGP_VPNV6_NODE,
18945 &neighbor_remove_private_as_replace_as_cmd);
18946 install_element(BGP_VPNV6_NODE,
18947 &no_neighbor_remove_private_as_replace_as_cmd);
18948 install_element(BGP_VPNV6_NODE,
18949 &neighbor_remove_private_as_all_replace_as_cmd);
18950 install_element(BGP_VPNV6_NODE,
18951 &no_neighbor_remove_private_as_all_replace_as_cmd);
18952
18953 /* "neighbor send-community" commands.*/
18954 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18955 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18956 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18957 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18958 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18959 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18960 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18961 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18962 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18963 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18964 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18965 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18966 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18967 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18968 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18969 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18970 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18971 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18972 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18973 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18974 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18975 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18976 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18977 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18978 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18979 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18980 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18981 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18982 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18983 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18984 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18985 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18986 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18987 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18988 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18989 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18990
18991 /* "neighbor route-reflector" commands.*/
18992 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18993 install_element(BGP_NODE,
18994 &no_neighbor_route_reflector_client_hidden_cmd);
18995 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18996 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18997 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18998 install_element(BGP_IPV4M_NODE,
18999 &no_neighbor_route_reflector_client_cmd);
19000 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19001 install_element(BGP_IPV4L_NODE,
19002 &no_neighbor_route_reflector_client_cmd);
19003 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19004 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19005 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19006 install_element(BGP_IPV6M_NODE,
19007 &no_neighbor_route_reflector_client_cmd);
19008 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19009 install_element(BGP_IPV6L_NODE,
19010 &no_neighbor_route_reflector_client_cmd);
19011 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19012 install_element(BGP_VPNV4_NODE,
19013 &no_neighbor_route_reflector_client_cmd);
19014 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19015 install_element(BGP_VPNV6_NODE,
19016 &no_neighbor_route_reflector_client_cmd);
19017 install_element(BGP_FLOWSPECV4_NODE,
19018 &neighbor_route_reflector_client_cmd);
19019 install_element(BGP_FLOWSPECV4_NODE,
19020 &no_neighbor_route_reflector_client_cmd);
19021 install_element(BGP_FLOWSPECV6_NODE,
19022 &neighbor_route_reflector_client_cmd);
19023 install_element(BGP_FLOWSPECV6_NODE,
19024 &no_neighbor_route_reflector_client_cmd);
19025 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19026 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19027
19028 /* "optimal-route-reflection" commands */
19029 install_element(BGP_IPV4_NODE, &optimal_route_reflection_cmd);
19030 install_element(BGP_IPV4M_NODE, &optimal_route_reflection_cmd);
19031 install_element(BGP_IPV4L_NODE, &optimal_route_reflection_cmd);
19032 install_element(BGP_IPV6_NODE, &optimal_route_reflection_cmd);
19033 install_element(BGP_IPV6M_NODE, &optimal_route_reflection_cmd);
19034 install_element(BGP_IPV6L_NODE, &optimal_route_reflection_cmd);
19035 install_element(BGP_VPNV4_NODE, &optimal_route_reflection_cmd);
19036 install_element(BGP_VPNV6_NODE, &optimal_route_reflection_cmd);
19037 install_element(BGP_FLOWSPECV4_NODE, &optimal_route_reflection_cmd);
19038 install_element(BGP_FLOWSPECV6_NODE, &optimal_route_reflection_cmd);
19039 install_element(BGP_EVPN_NODE, &optimal_route_reflection_cmd);
19040
19041 /* "neighbor optimal-route-reflection" commands */
19042 install_element(BGP_IPV4_NODE, &neighbor_optimal_route_reflection_cmd);
19043 install_element(BGP_IPV4M_NODE, &neighbor_optimal_route_reflection_cmd);
19044 install_element(BGP_IPV4L_NODE, &neighbor_optimal_route_reflection_cmd);
19045 install_element(BGP_IPV6_NODE, &neighbor_optimal_route_reflection_cmd);
19046 install_element(BGP_IPV6M_NODE, &neighbor_optimal_route_reflection_cmd);
19047 install_element(BGP_IPV6L_NODE, &neighbor_optimal_route_reflection_cmd);
19048 install_element(BGP_VPNV4_NODE, &neighbor_optimal_route_reflection_cmd);
19049 install_element(BGP_VPNV6_NODE, &neighbor_optimal_route_reflection_cmd);
19050 install_element(BGP_FLOWSPECV4_NODE,
19051 &neighbor_optimal_route_reflection_cmd);
19052 install_element(BGP_FLOWSPECV6_NODE,
19053 &neighbor_optimal_route_reflection_cmd);
19054 install_element(BGP_EVPN_NODE, &neighbor_optimal_route_reflection_cmd);
19055
19056 /* "neighbor route-server" commands.*/
19057 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19058 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19059 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19060 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19061 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19062 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19063 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19064 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19065 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19066 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19067 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19068 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19069 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19070 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19071 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19072 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19073 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19074 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19075 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19076 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19077 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19078 install_element(BGP_FLOWSPECV4_NODE,
19079 &no_neighbor_route_server_client_cmd);
19080 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19081 install_element(BGP_FLOWSPECV6_NODE,
19082 &no_neighbor_route_server_client_cmd);
19083
19084 /* "neighbor disable-addpath-rx" commands. */
19085 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19086 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19087 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19088 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19089 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19090 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19091 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19092 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19093 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19094 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19095 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19096 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19097 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19098 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19099 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19100 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19101
19102 /* "neighbor addpath-tx-all-paths" commands.*/
19103 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19104 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19105 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19106 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19107 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19108 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19109 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19110 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19111 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19112 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19113 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19114 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19115 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19116 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19117 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19118 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19119 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19120 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19121
19122 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19123 install_element(BGP_NODE,
19124 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19125 install_element(BGP_NODE,
19126 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19127 install_element(BGP_IPV4_NODE,
19128 &neighbor_addpath_tx_bestpath_per_as_cmd);
19129 install_element(BGP_IPV4_NODE,
19130 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19131 install_element(BGP_IPV4M_NODE,
19132 &neighbor_addpath_tx_bestpath_per_as_cmd);
19133 install_element(BGP_IPV4M_NODE,
19134 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19135 install_element(BGP_IPV4L_NODE,
19136 &neighbor_addpath_tx_bestpath_per_as_cmd);
19137 install_element(BGP_IPV4L_NODE,
19138 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19139 install_element(BGP_IPV6_NODE,
19140 &neighbor_addpath_tx_bestpath_per_as_cmd);
19141 install_element(BGP_IPV6_NODE,
19142 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19143 install_element(BGP_IPV6M_NODE,
19144 &neighbor_addpath_tx_bestpath_per_as_cmd);
19145 install_element(BGP_IPV6M_NODE,
19146 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19147 install_element(BGP_IPV6L_NODE,
19148 &neighbor_addpath_tx_bestpath_per_as_cmd);
19149 install_element(BGP_IPV6L_NODE,
19150 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19151 install_element(BGP_VPNV4_NODE,
19152 &neighbor_addpath_tx_bestpath_per_as_cmd);
19153 install_element(BGP_VPNV4_NODE,
19154 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19155 install_element(BGP_VPNV6_NODE,
19156 &neighbor_addpath_tx_bestpath_per_as_cmd);
19157 install_element(BGP_VPNV6_NODE,
19158 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19159
19160 /* "neighbor sender-as-path-loop-detection" commands. */
19161 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19162 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19163
19164 /* "neighbor passive" commands. */
19165 install_element(BGP_NODE, &neighbor_passive_cmd);
19166 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19167
19168
19169 /* "neighbor shutdown" commands. */
19170 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19171 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19172 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19173 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19174 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19175 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19176
19177 /* "neighbor capability extended-nexthop" commands.*/
19178 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19179 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19180
19181 /* "neighbor capability orf prefix-list" commands.*/
19182 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19183 install_element(BGP_NODE,
19184 &no_neighbor_capability_orf_prefix_hidden_cmd);
19185 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19186 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19187 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19188 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19189 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19190 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19191 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19192 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19193 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19194 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19195 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19196 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19197
19198 /* "neighbor capability dynamic" commands.*/
19199 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19200 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19201
19202 /* "neighbor dont-capability-negotiate" commands. */
19203 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19204 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19205
19206 /* "neighbor ebgp-multihop" commands. */
19207 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19208 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19209 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19210
19211 /* "neighbor disable-connected-check" commands. */
19212 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19213 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19214
19215 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19216 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19217 install_element(BGP_NODE,
19218 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19219
19220 /* "neighbor extended-optional-parameters" commands. */
19221 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19222 install_element(BGP_NODE,
19223 &no_neighbor_extended_optional_parameters_cmd);
19224
19225 /* "neighbor enforce-first-as" commands. */
19226 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19227 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19228
19229 /* "neighbor description" commands. */
19230 install_element(BGP_NODE, &neighbor_description_cmd);
19231 install_element(BGP_NODE, &no_neighbor_description_cmd);
19232 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19233
19234 /* "neighbor update-source" commands. "*/
19235 install_element(BGP_NODE, &neighbor_update_source_cmd);
19236 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19237
19238 /* "neighbor default-originate" commands. */
19239 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19240 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19241 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19242 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19243 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19244 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19245 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19246 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19247 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19248 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19249 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19250 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19251 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19252 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19253 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19254 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19255 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19256 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19257 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19258 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19259 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19260
19261 /* "neighbor port" commands. */
19262 install_element(BGP_NODE, &neighbor_port_cmd);
19263 install_element(BGP_NODE, &no_neighbor_port_cmd);
19264
19265 /* "neighbor weight" commands. */
19266 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19267 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19268
19269 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19270 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19271 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19272 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19273 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19274 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19275 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19276 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19277 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19278 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19279 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19280 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19281 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19282 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19283 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19284 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19285
19286 /* "neighbor override-capability" commands. */
19287 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19288 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19289
19290 /* "neighbor strict-capability-match" commands. */
19291 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19292 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19293
19294 /* "neighbor timers" commands. */
19295 install_element(BGP_NODE, &neighbor_timers_cmd);
19296 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19297
19298 /* "neighbor timers connect" commands. */
19299 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19300 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19301
19302 /* "neighbor timers delayopen" commands. */
19303 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19304 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19305
19306 /* "neighbor advertisement-interval" commands. */
19307 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19308 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19309
19310 /* "neighbor interface" commands. */
19311 install_element(BGP_NODE, &neighbor_interface_cmd);
19312 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19313
19314 /* "neighbor distribute" commands. */
19315 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19316 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19317 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19318 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19319 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19320 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19321 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19322 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19323 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19324 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19325 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19326 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19327 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19328 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19329 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19330 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19331 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19332 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19333
19334 /* "neighbor prefix-list" commands. */
19335 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19336 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19337 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19338 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19339 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19340 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19341 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19342 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19343 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19344 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19345 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19346 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19347 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19348 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19349 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19350 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19351 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19352 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19353 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19354 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19355 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19356 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19357
19358 /* "neighbor filter-list" commands. */
19359 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19360 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19361 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19362 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19363 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19364 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19365 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19366 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19367 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19368 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19369 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19370 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19371 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19372 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19373 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19374 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19375 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19376 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19377 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19378 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19379 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19380 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19381
19382 /* "neighbor route-map" commands. */
19383 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19384 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19385 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19386 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19387 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19388 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19389 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19390 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19391 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19392 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19393 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19394 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19395 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19396 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19397 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19398 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19399 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19400 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19401 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19402 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19403 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19404 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19405 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19406 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19407
19408 /* "neighbor unsuppress-map" commands. */
19409 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19410 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19411 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19412 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19413 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19414 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19415 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19416 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19417 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19418 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19419 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19420 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19421 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19422 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19423 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19424 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19425 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19426 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19427
19428 /* "neighbor advertise-map" commands. */
19429 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19430 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19431 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19432 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19433 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19434 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19435 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19436 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19437 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19438 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19439
19440 /* neighbor maximum-prefix-out commands. */
19441 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19442 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19443 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19444 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19445 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19446 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19447 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19448 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19449 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19450 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19451 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19452 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19453 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19454 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19455 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19456 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19457 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19458 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19459
19460 /* "neighbor maximum-prefix" commands. */
19461 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19462 install_element(BGP_NODE,
19463 &neighbor_maximum_prefix_threshold_hidden_cmd);
19464 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19465 install_element(BGP_NODE,
19466 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19467 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19468 install_element(BGP_NODE,
19469 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19470 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19471 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19472 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19473 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19474 install_element(BGP_IPV4_NODE,
19475 &neighbor_maximum_prefix_threshold_warning_cmd);
19476 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19477 install_element(BGP_IPV4_NODE,
19478 &neighbor_maximum_prefix_threshold_restart_cmd);
19479 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19480 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19481 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19482 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19483 install_element(BGP_IPV4M_NODE,
19484 &neighbor_maximum_prefix_threshold_warning_cmd);
19485 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19486 install_element(BGP_IPV4M_NODE,
19487 &neighbor_maximum_prefix_threshold_restart_cmd);
19488 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19489 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19490 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19491 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19492 install_element(BGP_IPV4L_NODE,
19493 &neighbor_maximum_prefix_threshold_warning_cmd);
19494 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19495 install_element(BGP_IPV4L_NODE,
19496 &neighbor_maximum_prefix_threshold_restart_cmd);
19497 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19498 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19499 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19500 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19501 install_element(BGP_IPV6_NODE,
19502 &neighbor_maximum_prefix_threshold_warning_cmd);
19503 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19504 install_element(BGP_IPV6_NODE,
19505 &neighbor_maximum_prefix_threshold_restart_cmd);
19506 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19507 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19508 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19509 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19510 install_element(BGP_IPV6M_NODE,
19511 &neighbor_maximum_prefix_threshold_warning_cmd);
19512 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19513 install_element(BGP_IPV6M_NODE,
19514 &neighbor_maximum_prefix_threshold_restart_cmd);
19515 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19516 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19517 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19518 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19519 install_element(BGP_IPV6L_NODE,
19520 &neighbor_maximum_prefix_threshold_warning_cmd);
19521 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19522 install_element(BGP_IPV6L_NODE,
19523 &neighbor_maximum_prefix_threshold_restart_cmd);
19524 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19525 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19526 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19527 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19528 install_element(BGP_VPNV4_NODE,
19529 &neighbor_maximum_prefix_threshold_warning_cmd);
19530 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19531 install_element(BGP_VPNV4_NODE,
19532 &neighbor_maximum_prefix_threshold_restart_cmd);
19533 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19534 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19535 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19536 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19537 install_element(BGP_VPNV6_NODE,
19538 &neighbor_maximum_prefix_threshold_warning_cmd);
19539 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19540 install_element(BGP_VPNV6_NODE,
19541 &neighbor_maximum_prefix_threshold_restart_cmd);
19542 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19543
19544 /* "neighbor allowas-in" */
19545 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19546 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19547 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19548 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19549 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19550 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19551 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19552 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19553 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19554 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19555 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19556 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19557 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19558 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19559 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19560 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19561 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19562 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19563 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19564 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19565
19566 /* "neighbor soo" */
19567 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19568 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19569 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19570 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19571 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19572 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19573 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19574 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19575 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19576 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19577 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19578 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19579 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19580 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19581 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19582 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19583 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19584 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19585
19586 /* address-family commands. */
19587 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19588 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19589 #ifdef KEEP_OLD_VPN_COMMANDS
19590 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19591 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19592 #endif /* KEEP_OLD_VPN_COMMANDS */
19593
19594 install_element(BGP_NODE, &address_family_evpn_cmd);
19595
19596 /* "exit-address-family" command. */
19597 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19598 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19599 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19600 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19601 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19602 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19603 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19604 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19605 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19606 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19607 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19608
19609 /* BGP retain all route-target */
19610 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19611 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19612
19613 /* "clear ip bgp commands" */
19614 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19615
19616 /* clear ip bgp prefix */
19617 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19618 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19619 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19620
19621 /* "show [ip] bgp summary" commands. */
19622 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19623 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19624 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19625 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19626 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19627 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19628 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19629
19630 /* "show [ip] bgp neighbors" commands. */
19631 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19632
19633 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19634
19635 /* "show [ip] bgp peer-group" commands. */
19636 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19637
19638 /* "show [ip] bgp paths" commands. */
19639 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19640
19641 /* "show [ip] bgp community" commands. */
19642 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19643
19644 /* "show ip bgp large-community" commands. */
19645 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19646 /* "show [ip] bgp attribute-info" commands. */
19647 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19648 /* "show [ip] bgp route-leak" command */
19649 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19650
19651 /* "redistribute" commands. */
19652 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19653 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19654 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19655 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19656 install_element(BGP_NODE,
19657 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19658 install_element(BGP_NODE,
19659 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19660 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19661 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19662 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19663 install_element(BGP_NODE,
19664 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19665 install_element(BGP_NODE,
19666 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19667 install_element(BGP_NODE,
19668 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19669 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19670 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19671 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19672 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19673 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19674 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19675 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19676 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19677 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19678 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19679 install_element(BGP_IPV4_NODE,
19680 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19681 install_element(BGP_IPV4_NODE,
19682 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19683 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19684 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19685 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19686 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19687 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19688 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19689
19690 /* import|export vpn [route-map RMAP_NAME] */
19691 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19692 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19693
19694 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19695 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19696
19697 /* ttl_security commands */
19698 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19699 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19700
19701 /* "bgp tcp-keepalive" commands */
19702 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
19703 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
19704
19705 /* "show [ip] bgp memory" commands. */
19706 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19707
19708 /* "show bgp martian next-hop" */
19709 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19710
19711 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19712
19713 /* "show [ip] bgp views" commands. */
19714 install_element(VIEW_NODE, &show_bgp_views_cmd);
19715
19716 /* "show [ip] bgp vrfs" commands. */
19717 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19718
19719 /* Community-list. */
19720 community_list_vty();
19721
19722 community_alias_vty();
19723
19724 /* vpn-policy commands */
19725 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19726 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19727 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19728 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19729 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19730 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19731 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19732 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19733 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19734 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19735 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19736 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19737
19738 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19739 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19740
19741 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19742 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19743 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19744 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19745 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19746 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19747 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19748 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19749 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19750 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19751
19752 /* tcp-mss command */
19753 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19754 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19755
19756 /* srv6 commands */
19757 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19758 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19759 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19760 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19761 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19762 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19763 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19764
19765 bgp_vty_if_init();
19766 }
19767
19768 #include "memory.h"
19769 #include "bgp_regex.h"
19770 #include "bgp_clist.h"
19771 #include "bgp_ecommunity.h"
19772
19773 /* VTY functions. */
19774
19775 /* Direction value to string conversion. */
19776 static const char *community_direct_str(int direct)
19777 {
19778 switch (direct) {
19779 case COMMUNITY_DENY:
19780 return "deny";
19781 case COMMUNITY_PERMIT:
19782 return "permit";
19783 default:
19784 return "unknown";
19785 }
19786 }
19787
19788 /* Display error string. */
19789 static void community_list_perror(struct vty *vty, int ret)
19790 {
19791 switch (ret) {
19792 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19793 vty_out(vty, "%% Can't find community-list\n");
19794 break;
19795 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19796 vty_out(vty, "%% Malformed community-list value\n");
19797 break;
19798 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19799 vty_out(vty,
19800 "%% Community name conflict, previously defined as standard community\n");
19801 break;
19802 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19803 vty_out(vty,
19804 "%% Community name conflict, previously defined as expanded community\n");
19805 break;
19806 }
19807 }
19808
19809 /* "community-list" keyword help string. */
19810 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19811
19812 /*community-list standard */
19813 DEFUN (community_list_standard,
19814 bgp_community_list_standard_cmd,
19815 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19816 BGP_STR
19817 COMMUNITY_LIST_STR
19818 "Community list number (standard)\n"
19819 "Add an standard community-list entry\n"
19820 "Community list name\n"
19821 "Sequence number of an entry\n"
19822 "Sequence number\n"
19823 "Specify community to reject\n"
19824 "Specify community to accept\n"
19825 COMMUNITY_VAL_STR)
19826 {
19827 char *cl_name_or_number = NULL;
19828 char *seq = NULL;
19829 int direct = 0;
19830 int style = COMMUNITY_LIST_STANDARD;
19831 int idx = 0;
19832
19833 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19834 seq = argv[idx]->arg;
19835
19836 idx = 0;
19837 argv_find(argv, argc, "(1-99)", &idx);
19838 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19839 cl_name_or_number = argv[idx]->arg;
19840 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19841 : COMMUNITY_DENY;
19842 argv_find(argv, argc, "AA:NN", &idx);
19843 char *str = argv_concat(argv, argc, idx);
19844
19845 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19846 direct, style);
19847
19848 XFREE(MTYPE_TMP, str);
19849
19850 if (ret < 0) {
19851 /* Display error string. */
19852 community_list_perror(vty, ret);
19853 return CMD_WARNING_CONFIG_FAILED;
19854 }
19855
19856 return CMD_SUCCESS;
19857 }
19858
19859 DEFUN (no_community_list_standard_all,
19860 no_bgp_community_list_standard_all_cmd,
19861 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19862 NO_STR
19863 BGP_STR
19864 COMMUNITY_LIST_STR
19865 "Community list number (standard)\n"
19866 "Add an standard community-list entry\n"
19867 "Community list name\n"
19868 "Sequence number of an entry\n"
19869 "Sequence number\n"
19870 "Specify community to reject\n"
19871 "Specify community to accept\n"
19872 COMMUNITY_VAL_STR)
19873 {
19874 char *cl_name_or_number = NULL;
19875 char *str = NULL;
19876 int direct = 0;
19877 int style = COMMUNITY_LIST_STANDARD;
19878 char *seq = NULL;
19879 int idx = 0;
19880
19881 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19882 seq = argv[idx]->arg;
19883
19884 idx = 0;
19885 argv_find(argv, argc, "permit", &idx);
19886 argv_find(argv, argc, "deny", &idx);
19887
19888 if (idx) {
19889 direct = argv_find(argv, argc, "permit", &idx)
19890 ? COMMUNITY_PERMIT
19891 : COMMUNITY_DENY;
19892
19893 idx = 0;
19894 argv_find(argv, argc, "AA:NN", &idx);
19895 str = argv_concat(argv, argc, idx);
19896 }
19897
19898 idx = 0;
19899 argv_find(argv, argc, "(1-99)", &idx);
19900 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19901 cl_name_or_number = argv[idx]->arg;
19902
19903 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19904 direct, style);
19905
19906 XFREE(MTYPE_TMP, str);
19907
19908 if (ret < 0) {
19909 community_list_perror(vty, ret);
19910 return CMD_WARNING_CONFIG_FAILED;
19911 }
19912
19913 return CMD_SUCCESS;
19914 }
19915
19916 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19917 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19918 NO_STR BGP_STR COMMUNITY_LIST_STR
19919 "Community list number (standard)\n"
19920 "Add an standard community-list entry\n"
19921 "Community list name\n")
19922
19923 /*community-list expanded */
19924 DEFUN (community_list_expanded_all,
19925 bgp_community_list_expanded_all_cmd,
19926 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19927 BGP_STR
19928 COMMUNITY_LIST_STR
19929 "Community list number (expanded)\n"
19930 "Add an expanded community-list entry\n"
19931 "Community list name\n"
19932 "Sequence number of an entry\n"
19933 "Sequence number\n"
19934 "Specify community to reject\n"
19935 "Specify community to accept\n"
19936 COMMUNITY_VAL_STR)
19937 {
19938 char *cl_name_or_number = NULL;
19939 char *seq = NULL;
19940 int direct = 0;
19941 int style = COMMUNITY_LIST_EXPANDED;
19942 int idx = 0;
19943
19944 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19945 seq = argv[idx]->arg;
19946
19947 idx = 0;
19948
19949 argv_find(argv, argc, "(100-500)", &idx);
19950 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19951 cl_name_or_number = argv[idx]->arg;
19952 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19953 : COMMUNITY_DENY;
19954 argv_find(argv, argc, "AA:NN", &idx);
19955 char *str = argv_concat(argv, argc, idx);
19956
19957 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19958 direct, style);
19959
19960 XFREE(MTYPE_TMP, str);
19961
19962 if (ret < 0) {
19963 /* Display error string. */
19964 community_list_perror(vty, ret);
19965 return CMD_WARNING_CONFIG_FAILED;
19966 }
19967
19968 return CMD_SUCCESS;
19969 }
19970
19971 DEFUN (no_community_list_expanded_all,
19972 no_bgp_community_list_expanded_all_cmd,
19973 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19974 NO_STR
19975 BGP_STR
19976 COMMUNITY_LIST_STR
19977 "Community list number (expanded)\n"
19978 "Add an expanded community-list entry\n"
19979 "Community list name\n"
19980 "Sequence number of an entry\n"
19981 "Sequence number\n"
19982 "Specify community to reject\n"
19983 "Specify community to accept\n"
19984 COMMUNITY_VAL_STR)
19985 {
19986 char *cl_name_or_number = NULL;
19987 char *seq = NULL;
19988 char *str = NULL;
19989 int direct = 0;
19990 int style = COMMUNITY_LIST_EXPANDED;
19991 int idx = 0;
19992
19993 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19994 seq = argv[idx]->arg;
19995
19996 idx = 0;
19997 argv_find(argv, argc, "permit", &idx);
19998 argv_find(argv, argc, "deny", &idx);
19999
20000 if (idx) {
20001 direct = argv_find(argv, argc, "permit", &idx)
20002 ? COMMUNITY_PERMIT
20003 : COMMUNITY_DENY;
20004
20005 idx = 0;
20006 argv_find(argv, argc, "AA:NN", &idx);
20007 str = argv_concat(argv, argc, idx);
20008 }
20009
20010 idx = 0;
20011 argv_find(argv, argc, "(100-500)", &idx);
20012 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20013 cl_name_or_number = argv[idx]->arg;
20014
20015 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20016 direct, style);
20017
20018 XFREE(MTYPE_TMP, str);
20019
20020 if (ret < 0) {
20021 community_list_perror(vty, ret);
20022 return CMD_WARNING_CONFIG_FAILED;
20023 }
20024
20025 return CMD_SUCCESS;
20026 }
20027
20028 ALIAS(no_community_list_expanded_all,
20029 no_bgp_community_list_expanded_all_list_cmd,
20030 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20031 NO_STR BGP_STR COMMUNITY_LIST_STR
20032 "Community list number (expanded)\n"
20033 "Add an expanded community-list entry\n"
20034 "Community list name\n")
20035
20036 /* Return configuration string of community-list entry. */
20037 static const char *community_list_config_str(struct community_entry *entry)
20038 {
20039 const char *str;
20040
20041 if (entry->any)
20042 str = "";
20043 else {
20044 if (entry->style == COMMUNITY_LIST_STANDARD)
20045 str = community_str(entry->u.com, false, false);
20046 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20047 str = lcommunity_str(entry->u.lcom, false, false);
20048 else
20049 str = entry->config;
20050 }
20051 return str;
20052 }
20053
20054 static void community_list_show(struct vty *vty, struct community_list *list)
20055 {
20056 struct community_entry *entry;
20057
20058 for (entry = list->head; entry; entry = entry->next) {
20059 if (entry == list->head) {
20060 if (all_digit(list->name))
20061 vty_out(vty, "Community %s list %s\n",
20062 entry->style == COMMUNITY_LIST_STANDARD
20063 ? "standard"
20064 : "(expanded) access",
20065 list->name);
20066 else
20067 vty_out(vty, "Named Community %s list %s\n",
20068 entry->style == COMMUNITY_LIST_STANDARD
20069 ? "standard"
20070 : "expanded",
20071 list->name);
20072 }
20073 if (entry->any)
20074 vty_out(vty, " %s\n",
20075 community_direct_str(entry->direct));
20076 else
20077 vty_out(vty, " %s %s\n",
20078 community_direct_str(entry->direct),
20079 community_list_config_str(entry));
20080 }
20081 }
20082
20083 DEFUN (show_community_list,
20084 show_bgp_community_list_cmd,
20085 "show bgp community-list",
20086 SHOW_STR
20087 BGP_STR
20088 "List community-list\n")
20089 {
20090 struct community_list *list;
20091 struct community_list_master *cm;
20092
20093 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20094 if (!cm)
20095 return CMD_SUCCESS;
20096
20097 for (list = cm->num.head; list; list = list->next)
20098 community_list_show(vty, list);
20099
20100 for (list = cm->str.head; list; list = list->next)
20101 community_list_show(vty, list);
20102
20103 return CMD_SUCCESS;
20104 }
20105
20106 DEFUN (show_community_list_arg,
20107 show_bgp_community_list_arg_cmd,
20108 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20109 SHOW_STR
20110 BGP_STR
20111 "List community-list\n"
20112 "Community-list number\n"
20113 "Community-list name\n"
20114 "Detailed information on community-list\n")
20115 {
20116 int idx_comm_list = 3;
20117 struct community_list *list;
20118
20119 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20120 COMMUNITY_LIST_MASTER);
20121 if (!list) {
20122 vty_out(vty, "%% Can't find community-list\n");
20123 return CMD_WARNING;
20124 }
20125
20126 community_list_show(vty, list);
20127
20128 return CMD_SUCCESS;
20129 }
20130
20131 /*
20132 * Large Community code.
20133 */
20134 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20135 struct cmd_token **argv, int style,
20136 int reject_all_digit_name)
20137 {
20138 int ret;
20139 int direct;
20140 char *str;
20141 int idx = 0;
20142 char *cl_name;
20143 char *seq = NULL;
20144
20145 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20146 seq = argv[idx]->arg;
20147
20148 idx = 0;
20149 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20150 : COMMUNITY_DENY;
20151
20152 /* All digit name check. */
20153 idx = 0;
20154 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20155 argv_find(argv, argc, "(1-99)", &idx);
20156 argv_find(argv, argc, "(100-500)", &idx);
20157 cl_name = argv[idx]->arg;
20158 if (reject_all_digit_name && all_digit(cl_name)) {
20159 vty_out(vty, "%% Community name cannot have all digits\n");
20160 return CMD_WARNING_CONFIG_FAILED;
20161 }
20162
20163 idx = 0;
20164 argv_find(argv, argc, "AA:BB:CC", &idx);
20165 argv_find(argv, argc, "LINE", &idx);
20166 /* Concat community string argument. */
20167 if (idx)
20168 str = argv_concat(argv, argc, idx);
20169 else
20170 str = NULL;
20171
20172 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20173
20174 /* Free temporary community list string allocated by
20175 argv_concat(). */
20176 XFREE(MTYPE_TMP, str);
20177
20178 if (ret < 0) {
20179 community_list_perror(vty, ret);
20180 return CMD_WARNING_CONFIG_FAILED;
20181 }
20182 return CMD_SUCCESS;
20183 }
20184
20185 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20186 struct cmd_token **argv, int style)
20187 {
20188 int ret;
20189 int direct = 0;
20190 char *str = NULL;
20191 int idx = 0;
20192 char *seq = NULL;
20193
20194 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20195 seq = argv[idx]->arg;
20196
20197 idx = 0;
20198 argv_find(argv, argc, "permit", &idx);
20199 argv_find(argv, argc, "deny", &idx);
20200
20201 if (idx) {
20202 /* Check the list direct. */
20203 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20204 direct = COMMUNITY_PERMIT;
20205 else
20206 direct = COMMUNITY_DENY;
20207
20208 idx = 0;
20209 argv_find(argv, argc, "LINE", &idx);
20210 argv_find(argv, argc, "AA:AA:NN", &idx);
20211 /* Concat community string argument. */
20212 str = argv_concat(argv, argc, idx);
20213 }
20214
20215 idx = 0;
20216 argv_find(argv, argc, "(1-99)", &idx);
20217 argv_find(argv, argc, "(100-500)", &idx);
20218 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20219
20220 /* Unset community list. */
20221 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20222 style);
20223
20224 /* Free temporary community list string allocated by
20225 argv_concat(). */
20226 XFREE(MTYPE_TMP, str);
20227
20228 if (ret < 0) {
20229 community_list_perror(vty, ret);
20230 return CMD_WARNING_CONFIG_FAILED;
20231 }
20232
20233 return CMD_SUCCESS;
20234 }
20235
20236 /* "large-community-list" keyword help string. */
20237 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20238 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20239
20240 DEFUN (lcommunity_list_standard,
20241 bgp_lcommunity_list_standard_cmd,
20242 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20243 BGP_STR
20244 LCOMMUNITY_LIST_STR
20245 "Large Community list number (standard)\n"
20246 "Sequence number of an entry\n"
20247 "Sequence number\n"
20248 "Specify large community to reject\n"
20249 "Specify large community to accept\n"
20250 LCOMMUNITY_VAL_STR)
20251 {
20252 return lcommunity_list_set_vty(vty, argc, argv,
20253 LARGE_COMMUNITY_LIST_STANDARD, 0);
20254 }
20255
20256 DEFUN (lcommunity_list_expanded,
20257 bgp_lcommunity_list_expanded_cmd,
20258 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20259 BGP_STR
20260 LCOMMUNITY_LIST_STR
20261 "Large Community list number (expanded)\n"
20262 "Sequence number of an entry\n"
20263 "Sequence number\n"
20264 "Specify large community to reject\n"
20265 "Specify large community to accept\n"
20266 "An ordered list as a regular-expression\n")
20267 {
20268 return lcommunity_list_set_vty(vty, argc, argv,
20269 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20270 }
20271
20272 DEFUN (lcommunity_list_name_standard,
20273 bgp_lcommunity_list_name_standard_cmd,
20274 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20275 BGP_STR
20276 LCOMMUNITY_LIST_STR
20277 "Specify standard large-community-list\n"
20278 "Large Community list name\n"
20279 "Sequence number of an entry\n"
20280 "Sequence number\n"
20281 "Specify large community to reject\n"
20282 "Specify large community to accept\n"
20283 LCOMMUNITY_VAL_STR)
20284 {
20285 return lcommunity_list_set_vty(vty, argc, argv,
20286 LARGE_COMMUNITY_LIST_STANDARD, 1);
20287 }
20288
20289 DEFUN (lcommunity_list_name_expanded,
20290 bgp_lcommunity_list_name_expanded_cmd,
20291 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20292 BGP_STR
20293 LCOMMUNITY_LIST_STR
20294 "Specify expanded large-community-list\n"
20295 "Large Community list name\n"
20296 "Sequence number of an entry\n"
20297 "Sequence number\n"
20298 "Specify large community to reject\n"
20299 "Specify large community to accept\n"
20300 "An ordered list as a regular-expression\n")
20301 {
20302 return lcommunity_list_set_vty(vty, argc, argv,
20303 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20304 }
20305
20306 DEFUN (no_lcommunity_list_all,
20307 no_bgp_lcommunity_list_all_cmd,
20308 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20309 NO_STR
20310 BGP_STR
20311 LCOMMUNITY_LIST_STR
20312 "Large Community list number (standard)\n"
20313 "Large Community list number (expanded)\n"
20314 "Large Community list name\n")
20315 {
20316 return lcommunity_list_unset_vty(vty, argc, argv,
20317 LARGE_COMMUNITY_LIST_STANDARD);
20318 }
20319
20320 DEFUN (no_lcommunity_list_name_standard_all,
20321 no_bgp_lcommunity_list_name_standard_all_cmd,
20322 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20323 NO_STR
20324 BGP_STR
20325 LCOMMUNITY_LIST_STR
20326 "Specify standard large-community-list\n"
20327 "Large Community list name\n")
20328 {
20329 return lcommunity_list_unset_vty(vty, argc, argv,
20330 LARGE_COMMUNITY_LIST_STANDARD);
20331 }
20332
20333 DEFUN (no_lcommunity_list_name_expanded_all,
20334 no_bgp_lcommunity_list_name_expanded_all_cmd,
20335 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20336 NO_STR
20337 BGP_STR
20338 LCOMMUNITY_LIST_STR
20339 "Specify expanded large-community-list\n"
20340 "Large Community list name\n")
20341 {
20342 return lcommunity_list_unset_vty(vty, argc, argv,
20343 LARGE_COMMUNITY_LIST_EXPANDED);
20344 }
20345
20346 DEFUN (no_lcommunity_list_standard,
20347 no_bgp_lcommunity_list_standard_cmd,
20348 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20349 NO_STR
20350 BGP_STR
20351 LCOMMUNITY_LIST_STR
20352 "Large Community list number (standard)\n"
20353 "Sequence number of an entry\n"
20354 "Sequence number\n"
20355 "Specify large community to reject\n"
20356 "Specify large community to accept\n"
20357 LCOMMUNITY_VAL_STR)
20358 {
20359 return lcommunity_list_unset_vty(vty, argc, argv,
20360 LARGE_COMMUNITY_LIST_STANDARD);
20361 }
20362
20363 DEFUN (no_lcommunity_list_expanded,
20364 no_bgp_lcommunity_list_expanded_cmd,
20365 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20366 NO_STR
20367 BGP_STR
20368 LCOMMUNITY_LIST_STR
20369 "Large Community list number (expanded)\n"
20370 "Sequence number of an entry\n"
20371 "Sequence number\n"
20372 "Specify large community to reject\n"
20373 "Specify large community to accept\n"
20374 "An ordered list as a regular-expression\n")
20375 {
20376 return lcommunity_list_unset_vty(vty, argc, argv,
20377 LARGE_COMMUNITY_LIST_EXPANDED);
20378 }
20379
20380 DEFUN (no_lcommunity_list_name_standard,
20381 no_bgp_lcommunity_list_name_standard_cmd,
20382 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20383 NO_STR
20384 BGP_STR
20385 LCOMMUNITY_LIST_STR
20386 "Specify standard large-community-list\n"
20387 "Large Community list name\n"
20388 "Sequence number of an entry\n"
20389 "Sequence number\n"
20390 "Specify large community to reject\n"
20391 "Specify large community to accept\n"
20392 LCOMMUNITY_VAL_STR)
20393 {
20394 return lcommunity_list_unset_vty(vty, argc, argv,
20395 LARGE_COMMUNITY_LIST_STANDARD);
20396 }
20397
20398 DEFUN (no_lcommunity_list_name_expanded,
20399 no_bgp_lcommunity_list_name_expanded_cmd,
20400 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20401 NO_STR
20402 BGP_STR
20403 LCOMMUNITY_LIST_STR
20404 "Specify expanded large-community-list\n"
20405 "Large community list name\n"
20406 "Sequence number of an entry\n"
20407 "Sequence number\n"
20408 "Specify large community to reject\n"
20409 "Specify large community to accept\n"
20410 "An ordered list as a regular-expression\n")
20411 {
20412 return lcommunity_list_unset_vty(vty, argc, argv,
20413 LARGE_COMMUNITY_LIST_EXPANDED);
20414 }
20415
20416 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20417 {
20418 struct community_entry *entry;
20419
20420 for (entry = list->head; entry; entry = entry->next) {
20421 if (entry == list->head) {
20422 if (all_digit(list->name))
20423 vty_out(vty, "Large community %s list %s\n",
20424 entry->style ==
20425 LARGE_COMMUNITY_LIST_STANDARD
20426 ? "standard"
20427 : "(expanded) access",
20428 list->name);
20429 else
20430 vty_out(vty,
20431 "Named large community %s list %s\n",
20432 entry->style ==
20433 LARGE_COMMUNITY_LIST_STANDARD
20434 ? "standard"
20435 : "expanded",
20436 list->name);
20437 }
20438 if (entry->any)
20439 vty_out(vty, " %s\n",
20440 community_direct_str(entry->direct));
20441 else
20442 vty_out(vty, " %s %s\n",
20443 community_direct_str(entry->direct),
20444 community_list_config_str(entry));
20445 }
20446 }
20447
20448 DEFUN (show_lcommunity_list,
20449 show_bgp_lcommunity_list_cmd,
20450 "show bgp large-community-list",
20451 SHOW_STR
20452 BGP_STR
20453 "List large-community list\n")
20454 {
20455 struct community_list *list;
20456 struct community_list_master *cm;
20457
20458 cm = community_list_master_lookup(bgp_clist,
20459 LARGE_COMMUNITY_LIST_MASTER);
20460 if (!cm)
20461 return CMD_SUCCESS;
20462
20463 for (list = cm->num.head; list; list = list->next)
20464 lcommunity_list_show(vty, list);
20465
20466 for (list = cm->str.head; list; list = list->next)
20467 lcommunity_list_show(vty, list);
20468
20469 return CMD_SUCCESS;
20470 }
20471
20472 DEFUN (show_lcommunity_list_arg,
20473 show_bgp_lcommunity_list_arg_cmd,
20474 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20475 SHOW_STR
20476 BGP_STR
20477 "List large-community list\n"
20478 "Large-community-list number\n"
20479 "Large-community-list name\n"
20480 "Detailed information on large-community-list\n")
20481 {
20482 struct community_list *list;
20483
20484 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20485 LARGE_COMMUNITY_LIST_MASTER);
20486 if (!list) {
20487 vty_out(vty, "%% Can't find large-community-list\n");
20488 return CMD_WARNING;
20489 }
20490
20491 lcommunity_list_show(vty, list);
20492
20493 return CMD_SUCCESS;
20494 }
20495
20496 /* "extcommunity-list" keyword help string. */
20497 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20498 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20499
20500 DEFUN (extcommunity_list_standard,
20501 bgp_extcommunity_list_standard_cmd,
20502 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20503 BGP_STR
20504 EXTCOMMUNITY_LIST_STR
20505 "Extended Community list number (standard)\n"
20506 "Specify standard extcommunity-list\n"
20507 "Community list name\n"
20508 "Sequence number of an entry\n"
20509 "Sequence number\n"
20510 "Specify community to reject\n"
20511 "Specify community to accept\n"
20512 EXTCOMMUNITY_VAL_STR)
20513 {
20514 int style = EXTCOMMUNITY_LIST_STANDARD;
20515 int direct = 0;
20516 char *cl_number_or_name = NULL;
20517 char *seq = NULL;
20518
20519 int idx = 0;
20520
20521 argv_find(argv, argc, "(1-99)", &idx);
20522 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20523 cl_number_or_name = argv[idx]->arg;
20524
20525 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20526 seq = argv[idx]->arg;
20527
20528 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20529 : COMMUNITY_DENY;
20530 argv_find(argv, argc, "AA:NN", &idx);
20531 char *str = argv_concat(argv, argc, idx);
20532
20533 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20534 direct, style);
20535
20536 XFREE(MTYPE_TMP, str);
20537
20538 if (ret < 0) {
20539 community_list_perror(vty, ret);
20540 return CMD_WARNING_CONFIG_FAILED;
20541 }
20542
20543 return CMD_SUCCESS;
20544 }
20545
20546 DEFUN (extcommunity_list_name_expanded,
20547 bgp_extcommunity_list_name_expanded_cmd,
20548 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20549 BGP_STR
20550 EXTCOMMUNITY_LIST_STR
20551 "Extended Community list number (expanded)\n"
20552 "Specify expanded extcommunity-list\n"
20553 "Extended Community list name\n"
20554 "Sequence number of an entry\n"
20555 "Sequence number\n"
20556 "Specify community to reject\n"
20557 "Specify community to accept\n"
20558 "An ordered list as a regular-expression\n")
20559 {
20560 int style = EXTCOMMUNITY_LIST_EXPANDED;
20561 int direct = 0;
20562 char *cl_number_or_name = NULL;
20563 char *seq = NULL;
20564 int idx = 0;
20565
20566 argv_find(argv, argc, "(100-500)", &idx);
20567 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20568 cl_number_or_name = argv[idx]->arg;
20569
20570 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20571 seq = argv[idx]->arg;
20572
20573 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20574 : COMMUNITY_DENY;
20575 argv_find(argv, argc, "LINE", &idx);
20576 char *str = argv_concat(argv, argc, idx);
20577
20578 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20579 direct, style);
20580
20581 XFREE(MTYPE_TMP, str);
20582
20583 if (ret < 0) {
20584 community_list_perror(vty, ret);
20585 return CMD_WARNING_CONFIG_FAILED;
20586 }
20587
20588 return CMD_SUCCESS;
20589 }
20590
20591 DEFUN (no_extcommunity_list_standard_all,
20592 no_bgp_extcommunity_list_standard_all_cmd,
20593 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20594 NO_STR
20595 BGP_STR
20596 EXTCOMMUNITY_LIST_STR
20597 "Extended Community list number (standard)\n"
20598 "Specify standard extcommunity-list\n"
20599 "Community list name\n"
20600 "Sequence number of an entry\n"
20601 "Sequence number\n"
20602 "Specify community to reject\n"
20603 "Specify community to accept\n"
20604 EXTCOMMUNITY_VAL_STR)
20605 {
20606 int style = EXTCOMMUNITY_LIST_STANDARD;
20607 int direct = 0;
20608 char *cl_number_or_name = NULL;
20609 char *str = NULL;
20610 char *seq = NULL;
20611 int idx = 0;
20612
20613 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20614 seq = argv[idx]->arg;
20615
20616 idx = 0;
20617 argv_find(argv, argc, "permit", &idx);
20618 argv_find(argv, argc, "deny", &idx);
20619 if (idx) {
20620 direct = argv_find(argv, argc, "permit", &idx)
20621 ? COMMUNITY_PERMIT
20622 : COMMUNITY_DENY;
20623
20624 idx = 0;
20625 argv_find(argv, argc, "AA:NN", &idx);
20626 str = argv_concat(argv, argc, idx);
20627 }
20628
20629 idx = 0;
20630 argv_find(argv, argc, "(1-99)", &idx);
20631 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20632 cl_number_or_name = argv[idx]->arg;
20633
20634 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20635 seq, direct, style);
20636
20637 XFREE(MTYPE_TMP, str);
20638
20639 if (ret < 0) {
20640 community_list_perror(vty, ret);
20641 return CMD_WARNING_CONFIG_FAILED;
20642 }
20643
20644 return CMD_SUCCESS;
20645 }
20646
20647 ALIAS(no_extcommunity_list_standard_all,
20648 no_bgp_extcommunity_list_standard_all_list_cmd,
20649 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20650 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20651 "Extended Community list number (standard)\n"
20652 "Specify standard extcommunity-list\n"
20653 "Community list name\n")
20654
20655 DEFUN (no_extcommunity_list_expanded_all,
20656 no_bgp_extcommunity_list_expanded_all_cmd,
20657 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20658 NO_STR
20659 BGP_STR
20660 EXTCOMMUNITY_LIST_STR
20661 "Extended Community list number (expanded)\n"
20662 "Specify expanded extcommunity-list\n"
20663 "Extended Community list name\n"
20664 "Sequence number of an entry\n"
20665 "Sequence number\n"
20666 "Specify community to reject\n"
20667 "Specify community to accept\n"
20668 "An ordered list as a regular-expression\n")
20669 {
20670 int style = EXTCOMMUNITY_LIST_EXPANDED;
20671 int direct = 0;
20672 char *cl_number_or_name = NULL;
20673 char *str = NULL;
20674 char *seq = NULL;
20675 int idx = 0;
20676
20677 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20678 seq = argv[idx]->arg;
20679
20680 idx = 0;
20681 argv_find(argv, argc, "permit", &idx);
20682 argv_find(argv, argc, "deny", &idx);
20683
20684 if (idx) {
20685 direct = argv_find(argv, argc, "permit", &idx)
20686 ? COMMUNITY_PERMIT
20687 : COMMUNITY_DENY;
20688
20689 idx = 0;
20690 argv_find(argv, argc, "LINE", &idx);
20691 str = argv_concat(argv, argc, idx);
20692 }
20693
20694 idx = 0;
20695 argv_find(argv, argc, "(100-500)", &idx);
20696 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20697 cl_number_or_name = argv[idx]->arg;
20698
20699 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20700 seq, direct, style);
20701
20702 XFREE(MTYPE_TMP, str);
20703
20704 if (ret < 0) {
20705 community_list_perror(vty, ret);
20706 return CMD_WARNING_CONFIG_FAILED;
20707 }
20708
20709 return CMD_SUCCESS;
20710 }
20711
20712 ALIAS(no_extcommunity_list_expanded_all,
20713 no_bgp_extcommunity_list_expanded_all_list_cmd,
20714 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20715 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20716 "Extended Community list number (expanded)\n"
20717 "Specify expanded extcommunity-list\n"
20718 "Extended Community list name\n")
20719
20720 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20721 {
20722 struct community_entry *entry;
20723
20724 for (entry = list->head; entry; entry = entry->next) {
20725 if (entry == list->head) {
20726 if (all_digit(list->name))
20727 vty_out(vty, "Extended community %s list %s\n",
20728 entry->style == EXTCOMMUNITY_LIST_STANDARD
20729 ? "standard"
20730 : "(expanded) access",
20731 list->name);
20732 else
20733 vty_out(vty,
20734 "Named extended community %s list %s\n",
20735 entry->style == EXTCOMMUNITY_LIST_STANDARD
20736 ? "standard"
20737 : "expanded",
20738 list->name);
20739 }
20740 if (entry->any)
20741 vty_out(vty, " %s\n",
20742 community_direct_str(entry->direct));
20743 else
20744 vty_out(vty, " %s %s\n",
20745 community_direct_str(entry->direct),
20746 community_list_config_str(entry));
20747 }
20748 }
20749
20750 DEFUN (show_extcommunity_list,
20751 show_bgp_extcommunity_list_cmd,
20752 "show bgp extcommunity-list",
20753 SHOW_STR
20754 BGP_STR
20755 "List extended-community list\n")
20756 {
20757 struct community_list *list;
20758 struct community_list_master *cm;
20759
20760 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20761 if (!cm)
20762 return CMD_SUCCESS;
20763
20764 for (list = cm->num.head; list; list = list->next)
20765 extcommunity_list_show(vty, list);
20766
20767 for (list = cm->str.head; list; list = list->next)
20768 extcommunity_list_show(vty, list);
20769
20770 return CMD_SUCCESS;
20771 }
20772
20773 DEFUN (show_extcommunity_list_arg,
20774 show_bgp_extcommunity_list_arg_cmd,
20775 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20776 SHOW_STR
20777 BGP_STR
20778 "List extended-community list\n"
20779 "Extcommunity-list number\n"
20780 "Extcommunity-list name\n"
20781 "Detailed information on extcommunity-list\n")
20782 {
20783 int idx_comm_list = 3;
20784 struct community_list *list;
20785
20786 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20787 EXTCOMMUNITY_LIST_MASTER);
20788 if (!list) {
20789 vty_out(vty, "%% Can't find extcommunity-list\n");
20790 return CMD_WARNING;
20791 }
20792
20793 extcommunity_list_show(vty, list);
20794
20795 return CMD_SUCCESS;
20796 }
20797
20798 /* Display community-list and extcommunity-list configuration. */
20799 static int community_list_config_write(struct vty *vty)
20800 {
20801 struct community_list *list;
20802 struct community_entry *entry;
20803 struct community_list_master *cm;
20804 int write = 0;
20805
20806 /* Community-list. */
20807 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20808
20809 for (list = cm->num.head; list; list = list->next)
20810 for (entry = list->head; entry; entry = entry->next) {
20811 vty_out(vty,
20812 "bgp community-list %s seq %" PRId64 " %s %s\n",
20813 list->name, entry->seq,
20814 community_direct_str(entry->direct),
20815 community_list_config_str(entry));
20816 write++;
20817 }
20818 for (list = cm->str.head; list; list = list->next)
20819 for (entry = list->head; entry; entry = entry->next) {
20820 vty_out(vty,
20821 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20822 entry->style == COMMUNITY_LIST_STANDARD
20823 ? "standard"
20824 : "expanded",
20825 list->name, entry->seq,
20826 community_direct_str(entry->direct),
20827 community_list_config_str(entry));
20828 write++;
20829 }
20830
20831 /* Extcommunity-list. */
20832 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20833
20834 for (list = cm->num.head; list; list = list->next)
20835 for (entry = list->head; entry; entry = entry->next) {
20836 vty_out(vty,
20837 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20838 list->name, entry->seq,
20839 community_direct_str(entry->direct),
20840 community_list_config_str(entry));
20841 write++;
20842 }
20843 for (list = cm->str.head; list; list = list->next)
20844 for (entry = list->head; entry; entry = entry->next) {
20845 vty_out(vty,
20846 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20847 entry->style == EXTCOMMUNITY_LIST_STANDARD
20848 ? "standard"
20849 : "expanded",
20850 list->name, entry->seq,
20851 community_direct_str(entry->direct),
20852 community_list_config_str(entry));
20853 write++;
20854 }
20855
20856
20857 /* lcommunity-list. */
20858 cm = community_list_master_lookup(bgp_clist,
20859 LARGE_COMMUNITY_LIST_MASTER);
20860
20861 for (list = cm->num.head; list; list = list->next)
20862 for (entry = list->head; entry; entry = entry->next) {
20863 vty_out(vty,
20864 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20865 list->name, entry->seq,
20866 community_direct_str(entry->direct),
20867 community_list_config_str(entry));
20868 write++;
20869 }
20870 for (list = cm->str.head; list; list = list->next)
20871 for (entry = list->head; entry; entry = entry->next) {
20872 vty_out(vty,
20873 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20874
20875 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20876 ? "standard"
20877 : "expanded",
20878 list->name, entry->seq, community_direct_str(entry->direct),
20879 community_list_config_str(entry));
20880 write++;
20881 }
20882
20883 return write;
20884 }
20885
20886 static int community_list_config_write(struct vty *vty);
20887 static struct cmd_node community_list_node = {
20888 .name = "community list",
20889 .node = COMMUNITY_LIST_NODE,
20890 .prompt = "",
20891 .config_write = community_list_config_write,
20892 };
20893
20894 static void community_list_vty(void)
20895 {
20896 install_node(&community_list_node);
20897
20898 /* Community-list. */
20899 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20900 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20901 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20902 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20903 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20904 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20905 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20906 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20907
20908 /* Extcommunity-list. */
20909 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20910 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20911 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20912 install_element(CONFIG_NODE,
20913 &no_bgp_extcommunity_list_standard_all_list_cmd);
20914 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20915 install_element(CONFIG_NODE,
20916 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20917 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20918 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20919
20920 /* Large Community List */
20921 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20922 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20923 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20924 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20925 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20926 install_element(CONFIG_NODE,
20927 &no_bgp_lcommunity_list_name_standard_all_cmd);
20928 install_element(CONFIG_NODE,
20929 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20930 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20931 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20932 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20933 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20934 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20935 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20936
20937 bgp_community_list_command_completion_setup();
20938 }
20939
20940 static struct cmd_node community_alias_node = {
20941 .name = "community alias",
20942 .node = COMMUNITY_ALIAS_NODE,
20943 .prompt = "",
20944 .config_write = bgp_community_alias_write,
20945 };
20946
20947 void community_alias_vty(void)
20948 {
20949 install_node(&community_alias_node);
20950
20951 /* Community-list. */
20952 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20953
20954 bgp_community_alias_command_completion_setup();
20955 }