]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12140 from opensourcerouting/fix/watchfrr_dont_givup
[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, *tovpn_sid_locator;
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 tovpn_sid_locator =
346 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator;
347 if (tovpn_sid_locator) {
348 srv6_locator_chunk_free(tovpn_sid_locator);
349 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator = NULL;
350 }
351
352 /* refresh vpnv6 tovpn_sid_locator */
353 tovpn_sid_locator =
354 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator;
355 if (tovpn_sid_locator) {
356 srv6_locator_chunk_free(tovpn_sid_locator);
357 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator = NULL;
358 }
359 }
360
361 /* clear locator name */
362 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
363
364 return 0;
365 }
366
367 /* Utility function to get address family from current node. */
368 afi_t bgp_node_afi(struct vty *vty)
369 {
370 afi_t afi;
371 switch (vty->node) {
372 case BGP_IPV6_NODE:
373 case BGP_IPV6M_NODE:
374 case BGP_IPV6L_NODE:
375 case BGP_VPNV6_NODE:
376 case BGP_FLOWSPECV6_NODE:
377 afi = AFI_IP6;
378 break;
379 case BGP_EVPN_NODE:
380 afi = AFI_L2VPN;
381 break;
382 default:
383 afi = AFI_IP;
384 break;
385 }
386 return afi;
387 }
388
389 /* Utility function to get subsequent address family from current
390 node. */
391 safi_t bgp_node_safi(struct vty *vty)
392 {
393 safi_t safi;
394 switch (vty->node) {
395 case BGP_VPNV4_NODE:
396 case BGP_VPNV6_NODE:
397 safi = SAFI_MPLS_VPN;
398 break;
399 case BGP_IPV4M_NODE:
400 case BGP_IPV6M_NODE:
401 safi = SAFI_MULTICAST;
402 break;
403 case BGP_EVPN_NODE:
404 safi = SAFI_EVPN;
405 break;
406 case BGP_IPV4L_NODE:
407 case BGP_IPV6L_NODE:
408 safi = SAFI_LABELED_UNICAST;
409 break;
410 case BGP_FLOWSPECV4_NODE:
411 case BGP_FLOWSPECV6_NODE:
412 safi = SAFI_FLOWSPEC;
413 break;
414 default:
415 safi = SAFI_UNICAST;
416 break;
417 }
418 return safi;
419 }
420
421 /**
422 * Converts an AFI in string form to afi_t
423 *
424 * @param afi string, one of
425 * - "ipv4"
426 * - "ipv6"
427 * - "l2vpn"
428 * @return the corresponding afi_t
429 */
430 afi_t bgp_vty_afi_from_str(const char *afi_str)
431 {
432 afi_t afi = AFI_MAX; /* unknown */
433 if (strmatch(afi_str, "ipv4"))
434 afi = AFI_IP;
435 else if (strmatch(afi_str, "ipv6"))
436 afi = AFI_IP6;
437 else if (strmatch(afi_str, "l2vpn"))
438 afi = AFI_L2VPN;
439 return afi;
440 }
441
442 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
443 afi_t *afi)
444 {
445 int ret = 0;
446 if (argv_find(argv, argc, "ipv4", index)) {
447 ret = 1;
448 if (afi)
449 *afi = AFI_IP;
450 } else if (argv_find(argv, argc, "ipv6", index)) {
451 ret = 1;
452 if (afi)
453 *afi = AFI_IP6;
454 } else if (argv_find(argv, argc, "l2vpn", index)) {
455 ret = 1;
456 if (afi)
457 *afi = AFI_L2VPN;
458 }
459 return ret;
460 }
461
462 /* supports <unicast|multicast|vpn|labeled-unicast> */
463 safi_t bgp_vty_safi_from_str(const char *safi_str)
464 {
465 safi_t safi = SAFI_MAX; /* unknown */
466 if (strmatch(safi_str, "multicast"))
467 safi = SAFI_MULTICAST;
468 else if (strmatch(safi_str, "unicast"))
469 safi = SAFI_UNICAST;
470 else if (strmatch(safi_str, "vpn"))
471 safi = SAFI_MPLS_VPN;
472 else if (strmatch(safi_str, "evpn"))
473 safi = SAFI_EVPN;
474 else if (strmatch(safi_str, "labeled-unicast"))
475 safi = SAFI_LABELED_UNICAST;
476 else if (strmatch(safi_str, "flowspec"))
477 safi = SAFI_FLOWSPEC;
478 return safi;
479 }
480
481 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
482 safi_t *safi)
483 {
484 int ret = 0;
485 if (argv_find(argv, argc, "unicast", index)) {
486 ret = 1;
487 if (safi)
488 *safi = SAFI_UNICAST;
489 } else if (argv_find(argv, argc, "multicast", index)) {
490 ret = 1;
491 if (safi)
492 *safi = SAFI_MULTICAST;
493 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
494 ret = 1;
495 if (safi)
496 *safi = SAFI_LABELED_UNICAST;
497 } else if (argv_find(argv, argc, "vpn", index)) {
498 ret = 1;
499 if (safi)
500 *safi = SAFI_MPLS_VPN;
501 } else if (argv_find(argv, argc, "evpn", index)) {
502 ret = 1;
503 if (safi)
504 *safi = SAFI_EVPN;
505 } else if (argv_find(argv, argc, "flowspec", index)) {
506 ret = 1;
507 if (safi)
508 *safi = SAFI_FLOWSPEC;
509 }
510 return ret;
511 }
512
513 /*
514 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
515 *
516 * afi
517 * address-family identifier
518 *
519 * safi
520 * subsequent address-family identifier
521 *
522 * Returns:
523 * default_af string corresponding to the supplied afi/safi pair.
524 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
525 * return -1.
526 */
527 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
528 {
529 switch (afi) {
530 case AFI_IP:
531 switch (safi) {
532 case SAFI_UNICAST:
533 return "ipv4-unicast";
534 case SAFI_MULTICAST:
535 return "ipv4-multicast";
536 case SAFI_MPLS_VPN:
537 return "ipv4-vpn";
538 case SAFI_ENCAP:
539 return "ipv4-encap";
540 case SAFI_LABELED_UNICAST:
541 return "ipv4-labeled-unicast";
542 case SAFI_FLOWSPEC:
543 return "ipv4-flowspec";
544 default:
545 return "unknown-afi/safi";
546 }
547 break;
548 case AFI_IP6:
549 switch (safi) {
550 case SAFI_UNICAST:
551 return "ipv6-unicast";
552 case SAFI_MULTICAST:
553 return "ipv6-multicast";
554 case SAFI_MPLS_VPN:
555 return "ipv6-vpn";
556 case SAFI_ENCAP:
557 return "ipv6-encap";
558 case SAFI_LABELED_UNICAST:
559 return "ipv6-labeled-unicast";
560 case SAFI_FLOWSPEC:
561 return "ipv6-flowspec";
562 default:
563 return "unknown-afi/safi";
564 }
565 break;
566 case AFI_L2VPN:
567 switch (safi) {
568 case SAFI_EVPN:
569 return "l2vpn-evpn";
570 default:
571 return "unknown-afi/safi";
572 }
573 case AFI_UNSPEC:
574 case AFI_MAX:
575 return "unknown-afi/safi";
576 }
577 /* all AFIs are accounted for above, so this shouldn't happen */
578 return "unknown-afi/safi";
579 }
580
581 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
582 enum bgp_instance_type inst_type)
583 {
584 int ret = bgp_get(bgp, as, name, inst_type);
585
586 if (ret == BGP_CREATED) {
587 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
588 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
589
590 if (DFLT_BGP_IMPORT_CHECK)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
592 if (DFLT_BGP_SHOW_HOSTNAME)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
594 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
596 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
598 if (DFLT_BGP_DETERMINISTIC_MED)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
600 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
602 if (DFLT_BGP_SUPPRESS_DUPLICATES)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
604 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
605 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
606 if (DFLT_BGP_HARD_ADMIN_RESET)
607 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
608
609 ret = BGP_SUCCESS;
610 }
611 return ret;
612 }
613
614 /*
615 * bgp_vty_find_and_parse_afi_safi_bgp
616 *
617 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
618 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
619 * to appropriate values for the calling function. This is to allow the
620 * calling function to make decisions appropriate for the show command
621 * that is being parsed.
622 *
623 * The show commands are generally of the form:
624 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
625 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
626 *
627 * Since we use argv_find if the show command in particular doesn't have:
628 * [ip]
629 * [<view|vrf> VIEWVRFNAME]
630 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
631 * The command parsing should still be ok.
632 *
633 * vty -> The vty for the command so we can output some useful data in
634 * the event of a parse error in the vrf.
635 * argv -> The command tokens
636 * argc -> How many command tokens we have
637 * idx -> The current place in the command, generally should be 0 for this
638 * function
639 * afi -> The parsed afi if it was included in the show command, returned here
640 * safi -> The parsed safi if it was included in the show command, returned here
641 * bgp -> Pointer to the bgp data structure we need to fill in.
642 * use_json -> json is configured or not
643 *
644 * The function returns the correct location in the parse tree for the
645 * last token found.
646 *
647 * Returns 0 for failure to parse correctly, else the idx position of where
648 * it found the last token.
649 */
650 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
651 struct cmd_token **argv, int argc,
652 int *idx, afi_t *afi, safi_t *safi,
653 struct bgp **bgp, bool use_json)
654 {
655 char *vrf_name = NULL;
656
657 assert(afi);
658 assert(safi);
659 assert(bgp);
660
661 if (argv_find(argv, argc, "ip", idx))
662 *afi = AFI_IP;
663
664 if (argv_find(argv, argc, "view", idx))
665 vrf_name = argv[*idx + 1]->arg;
666 else if (argv_find(argv, argc, "vrf", idx)) {
667 vrf_name = argv[*idx + 1]->arg;
668 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
669 vrf_name = NULL;
670 }
671 if (vrf_name) {
672 if (strmatch(vrf_name, "all"))
673 *bgp = NULL;
674 else {
675 *bgp = bgp_lookup_by_name(vrf_name);
676 if (!*bgp) {
677 if (use_json) {
678 json_object *json = NULL;
679 json = json_object_new_object();
680 json_object_string_add(
681 json, "warning",
682 "View/Vrf is unknown");
683 vty_json(vty, json);
684 }
685 else
686 vty_out(vty, "View/Vrf %s is unknown\n",
687 vrf_name);
688 *idx = 0;
689 return 0;
690 }
691 }
692 } else {
693 *bgp = bgp_get_default();
694 if (!*bgp) {
695 if (use_json) {
696 json_object *json = NULL;
697 json = json_object_new_object();
698 json_object_string_add(
699 json, "warning",
700 "Default BGP instance not found");
701 vty_json(vty, json);
702 }
703 else
704 vty_out(vty,
705 "Default BGP instance not found\n");
706 *idx = 0;
707 return 0;
708 }
709 }
710
711 if (argv_find_and_parse_afi(argv, argc, idx, afi))
712 argv_find_and_parse_safi(argv, argc, idx, safi);
713
714 *idx += 1;
715 return *idx;
716 }
717
718 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
719 {
720 struct interface *ifp = NULL;
721 struct listnode *node;
722 struct bgp_listener *listener;
723 union sockunion all_su;
724
725 if (su->sa.sa_family == AF_INET) {
726 (void)str2sockunion("0.0.0.0", &all_su);
727 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
728 } else if (su->sa.sa_family == AF_INET6) {
729 (void)str2sockunion("::", &all_su);
730 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
731 su->sin6.sin6_scope_id,
732 bgp->vrf_id);
733 }
734
735 if (ifp) {
736 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
737 if (sockunion_family(su) !=
738 sockunion_family(&listener->su))
739 continue;
740
741 /* If 0.0.0.0/:: is a listener, then treat as self and
742 * reject.
743 */
744 if (!sockunion_cmp(&listener->su, su) ||
745 !sockunion_cmp(&listener->su, &all_su))
746 return true;
747 }
748 }
749
750 return false;
751 }
752
753 /* Utility function for looking up peer from VTY. */
754 /* This is used only for configuration, so disallow if attempted on
755 * a dynamic neighbor.
756 */
757 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
758 {
759 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
760 int ret;
761 union sockunion su;
762 struct peer *peer;
763
764 if (!bgp) {
765 return NULL;
766 }
767
768 ret = str2sockunion(ip_str, &su);
769 if (ret < 0) {
770 peer = peer_lookup_by_conf_if(bgp, ip_str);
771 if (!peer) {
772 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
773 == NULL) {
774 vty_out(vty,
775 "%% Malformed address or name: %s\n",
776 ip_str);
777 return NULL;
778 }
779 }
780 } else {
781 peer = peer_lookup(bgp, &su);
782 if (!peer) {
783 vty_out(vty,
784 "%% Specify remote-as or peer-group commands first\n");
785 return NULL;
786 }
787 if (peer_dynamic_neighbor(peer)) {
788 vty_out(vty,
789 "%% Operation not allowed on a dynamic neighbor\n");
790 return NULL;
791 }
792 }
793 return peer;
794 }
795
796 /* Utility function for looking up peer or peer group. */
797 /* This is used only for configuration, so disallow if attempted on
798 * a dynamic neighbor.
799 */
800 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
801 {
802 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
803 int ret;
804 union sockunion su;
805 struct peer *peer = NULL;
806 struct peer_group *group = NULL;
807
808 if (!bgp) {
809 return NULL;
810 }
811
812 ret = str2sockunion(peer_str, &su);
813 if (ret == 0) {
814 /* IP address, locate peer. */
815 peer = peer_lookup(bgp, &su);
816 } else {
817 /* Not IP, could match either peer configured on interface or a
818 * group. */
819 peer = peer_lookup_by_conf_if(bgp, peer_str);
820 if (!peer)
821 group = peer_group_lookup(bgp, peer_str);
822 }
823
824 if (peer) {
825 if (peer_dynamic_neighbor(peer)) {
826 vty_out(vty,
827 "%% Operation not allowed on a dynamic neighbor\n");
828 return NULL;
829 }
830
831 return peer;
832 }
833
834 if (group)
835 return group->conf;
836
837 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
838
839 return NULL;
840 }
841
842 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
843 {
844 const char *str = NULL;
845
846 switch (ret) {
847 case BGP_SUCCESS:
848 case BGP_CREATED:
849 case BGP_GR_NO_OPERATION:
850 break;
851 case BGP_ERR_INVALID_VALUE:
852 str = "Invalid value";
853 break;
854 case BGP_ERR_INVALID_FLAG:
855 str = "Invalid flag";
856 break;
857 case BGP_ERR_PEER_GROUP_SHUTDOWN:
858 str = "Peer-group has been shutdown. Activate the peer-group first";
859 break;
860 case BGP_ERR_PEER_FLAG_CONFLICT:
861 str = "Can't set override-capability and strict-capability-match at the same time";
862 break;
863 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
864 str = "Specify remote-as or peer-group remote AS first";
865 break;
866 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
867 str = "Cannot change the peer-group. Deconfigure first";
868 break;
869 case BGP_ERR_PEER_GROUP_MISMATCH:
870 str = "Peer is not a member of this peer-group";
871 break;
872 case BGP_ERR_PEER_FILTER_CONFLICT:
873 str = "Prefix/distribute list can not co-exist";
874 break;
875 case BGP_ERR_NOT_INTERNAL_PEER:
876 str = "Invalid command. Not an internal neighbor";
877 break;
878 case BGP_ERR_REMOVE_PRIVATE_AS:
879 str = "remove-private-AS cannot be configured for IBGP peers";
880 break;
881 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
882 str = "Cannot have local-as same as BGP AS number";
883 break;
884 case BGP_ERR_TCPSIG_FAILED:
885 str = "Error while applying TCP-Sig to session(s)";
886 break;
887 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
888 str = "ebgp-multihop and ttl-security cannot be configured together";
889 break;
890 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
891 str = "ttl-security only allowed for EBGP peers";
892 break;
893 case BGP_ERR_AS_OVERRIDE:
894 str = "as-override cannot be configured for IBGP peers";
895 break;
896 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
897 str = "Invalid limit for number of dynamic neighbors";
898 break;
899 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
900 str = "Dynamic neighbor listen range already exists";
901 break;
902 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
903 str = "Operation not allowed on a dynamic neighbor";
904 break;
905 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
906 str = "Operation not allowed on a directly connected neighbor";
907 break;
908 case BGP_ERR_PEER_SAFI_CONFLICT:
909 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
910 break;
911 case BGP_ERR_GR_INVALID_CMD:
912 str = "The Graceful Restart command used is not valid at this moment.";
913 break;
914 case BGP_ERR_GR_OPERATION_FAILED:
915 str = "The Graceful Restart Operation failed due to an err.";
916 break;
917 case BGP_ERR_PEER_GROUP_MEMBER:
918 str = "Peer-group member cannot override remote-as of peer-group.";
919 break;
920 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
921 str = "Peer-group members must be all internal or all external.";
922 break;
923 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
924 str = "Range specified cannot be deleted because it is not part of current config.";
925 break;
926 case BGP_ERR_INSTANCE_MISMATCH:
927 str = "Instance specified does not match the current instance.";
928 break;
929 case BGP_ERR_NO_INTERFACE_CONFIG:
930 str = "Interface specified is not being used for interface based peer.";
931 break;
932 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
933 str = "No configuration already specified for soft reconfiguration.";
934 break;
935 case BGP_ERR_AS_MISMATCH:
936 str = "BGP is already running.";
937 break;
938 case BGP_ERR_AF_UNCONFIGURED:
939 str = "AFI/SAFI specified is not currently configured.";
940 break;
941 case BGP_ERR_INVALID_AS:
942 str = "Confederation AS specified is the same AS as our AS.";
943 break;
944 case BGP_ERR_INVALID_ROLE_NAME:
945 str = "Invalid role name";
946 break;
947 case BGP_ERR_INVALID_INTERNAL_ROLE:
948 str = "External roles can be set only on eBGP session";
949 break;
950 case BGP_ERR_PEER_ORR_CONFIGURED:
951 str = "Deconfigure optimal-route-reflection on this peer first";
952 break;
953 }
954 if (str) {
955 vty_out(vty, "%% %s\n", str);
956 return CMD_WARNING_CONFIG_FAILED;
957 }
958 return CMD_SUCCESS;
959 }
960
961 /* BGP clear sort. */
962 enum clear_sort {
963 clear_all,
964 clear_peer,
965 clear_group,
966 clear_external,
967 clear_as
968 };
969
970 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
971 safi_t safi, int error)
972 {
973 switch (error) {
974 case BGP_ERR_AF_UNCONFIGURED:
975 if (vty)
976 vty_out(vty,
977 "%% BGP: Enable %s address family for the neighbor %s\n",
978 get_afi_safi_str(afi, safi, false), peer->host);
979 else
980 zlog_warn(
981 "%% BGP: Enable %s address family for the neighbor %s",
982 get_afi_safi_str(afi, safi, false), peer->host);
983 break;
984 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
985 if (vty)
986 vty_out(vty,
987 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
988 peer->host);
989 else
990 zlog_warn(
991 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
992 peer->host);
993 break;
994 default:
995 break;
996 }
997 }
998
999 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
1000 struct listnode **nnode, enum bgp_clear_type stype)
1001 {
1002 int ret = 0;
1003 struct peer_af *paf;
1004
1005 /* if afi/.safi not specified, spin thru all of them */
1006 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1007 afi_t tmp_afi;
1008 safi_t tmp_safi;
1009 enum bgp_af_index index;
1010
1011 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1012 paf = peer->peer_af_array[index];
1013 if (!paf)
1014 continue;
1015
1016 if (paf && paf->subgroup)
1017 SET_FLAG(paf->subgroup->sflags,
1018 SUBGRP_STATUS_FORCE_UPDATES);
1019
1020 tmp_afi = paf->afi;
1021 tmp_safi = paf->safi;
1022 if (!peer->afc[tmp_afi][tmp_safi])
1023 continue;
1024
1025 if (stype == BGP_CLEAR_SOFT_NONE)
1026 ret = peer_clear(peer, nnode);
1027 else
1028 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1029 stype);
1030 }
1031 /* if afi specified and safi not, spin thru safis on this afi */
1032 } else if (safi == SAFI_UNSPEC) {
1033 safi_t tmp_safi;
1034
1035 for (tmp_safi = SAFI_UNICAST;
1036 tmp_safi < SAFI_MAX; tmp_safi++) {
1037 if (!peer->afc[afi][tmp_safi])
1038 continue;
1039
1040 paf = peer_af_find(peer, afi, tmp_safi);
1041 if (paf && paf->subgroup)
1042 SET_FLAG(paf->subgroup->sflags,
1043 SUBGRP_STATUS_FORCE_UPDATES);
1044
1045 if (stype == BGP_CLEAR_SOFT_NONE)
1046 ret = peer_clear(peer, nnode);
1047 else
1048 ret = peer_clear_soft(peer, afi,
1049 tmp_safi, stype);
1050 }
1051 /* both afi/safi specified, let the caller know if not defined */
1052 } else {
1053 if (!peer->afc[afi][safi])
1054 return 1;
1055
1056 paf = peer_af_find(peer, afi, safi);
1057 if (paf && paf->subgroup)
1058 SET_FLAG(paf->subgroup->sflags,
1059 SUBGRP_STATUS_FORCE_UPDATES);
1060
1061 if (stype == BGP_CLEAR_SOFT_NONE)
1062 ret = peer_clear(peer, nnode);
1063 else
1064 ret = peer_clear_soft(peer, afi, safi, stype);
1065 }
1066
1067 return ret;
1068 }
1069
1070 /* `clear ip bgp' functions. */
1071 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1072 enum clear_sort sort, enum bgp_clear_type stype,
1073 const char *arg)
1074 {
1075 int ret = 0;
1076 bool found = false;
1077 struct peer *peer;
1078
1079 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1080
1081 /* Clear all neighbors. */
1082 /*
1083 * Pass along pointer to next node to peer_clear() when walking all
1084 * nodes on the BGP instance as that may get freed if it is a
1085 * doppelganger
1086 */
1087 if (sort == clear_all) {
1088 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1089
1090 bgp_peer_gr_flags_update(peer);
1091
1092 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1093 gr_router_detected = true;
1094
1095 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1096 stype);
1097
1098 if (ret < 0)
1099 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1100 }
1101
1102 if (gr_router_detected
1103 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1104 bgp_zebra_send_capabilities(bgp, false);
1105 } else if (!gr_router_detected
1106 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1107 bgp_zebra_send_capabilities(bgp, true);
1108 }
1109
1110 /* This is to apply read-only mode on this clear. */
1111 if (stype == BGP_CLEAR_SOFT_NONE)
1112 bgp->update_delay_over = 0;
1113
1114 return CMD_SUCCESS;
1115 }
1116
1117 /* Clear specified neighbor. */
1118 if (sort == clear_peer) {
1119 union sockunion su;
1120
1121 /* Make sockunion for lookup. */
1122 ret = str2sockunion(arg, &su);
1123 if (ret < 0) {
1124 peer = peer_lookup_by_conf_if(bgp, arg);
1125 if (!peer) {
1126 peer = peer_lookup_by_hostname(bgp, arg);
1127 if (!peer) {
1128 vty_out(vty,
1129 "Malformed address or name: %s\n",
1130 arg);
1131 return CMD_WARNING;
1132 }
1133 }
1134 } else {
1135 peer = peer_lookup(bgp, &su);
1136 if (!peer) {
1137 vty_out(vty,
1138 "%% BGP: Unknown neighbor - \"%s\"\n",
1139 arg);
1140 return CMD_WARNING;
1141 }
1142 }
1143
1144 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1145 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1146
1147 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1148
1149 /* if afi/safi not defined for this peer, let caller know */
1150 if (ret == 1)
1151 ret = BGP_ERR_AF_UNCONFIGURED;
1152
1153 if (ret < 0)
1154 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1155
1156 return CMD_SUCCESS;
1157 }
1158
1159 /* Clear all neighbors belonging to a specific peer-group. */
1160 if (sort == clear_group) {
1161 struct peer_group *group;
1162
1163 group = peer_group_lookup(bgp, arg);
1164 if (!group) {
1165 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1166 return CMD_WARNING;
1167 }
1168
1169 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1170 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1171
1172 if (ret < 0)
1173 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1174 else
1175 found = true;
1176 }
1177
1178 if (!found)
1179 vty_out(vty,
1180 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1181 get_afi_safi_str(afi, safi, false), arg);
1182
1183 return CMD_SUCCESS;
1184 }
1185
1186 /* Clear all external (eBGP) neighbors. */
1187 if (sort == clear_external) {
1188 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1189 if (peer->sort == BGP_PEER_IBGP)
1190 continue;
1191
1192 bgp_peer_gr_flags_update(peer);
1193
1194 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1195 gr_router_detected = true;
1196
1197 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1198
1199 if (ret < 0)
1200 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1201 else
1202 found = true;
1203 }
1204
1205 if (gr_router_detected
1206 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1207 bgp_zebra_send_capabilities(bgp, false);
1208 } else if (!gr_router_detected
1209 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1210 bgp_zebra_send_capabilities(bgp, true);
1211 }
1212
1213 if (!found)
1214 vty_out(vty,
1215 "%% BGP: No external %s peer is configured\n",
1216 get_afi_safi_str(afi, safi, false));
1217
1218 return CMD_SUCCESS;
1219 }
1220
1221 /* Clear all neighbors belonging to a specific AS. */
1222 if (sort == clear_as) {
1223 as_t as = strtoul(arg, NULL, 10);
1224
1225 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1226 if (peer->as != as)
1227 continue;
1228
1229 bgp_peer_gr_flags_update(peer);
1230
1231 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1232 gr_router_detected = true;
1233
1234 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1235
1236 if (ret < 0)
1237 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1238 else
1239 found = true;
1240 }
1241
1242 if (gr_router_detected
1243 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1244 bgp_zebra_send_capabilities(bgp, false);
1245 } else if (!gr_router_detected
1246 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1247 bgp_zebra_send_capabilities(bgp, true);
1248 }
1249
1250 if (!found)
1251 vty_out(vty,
1252 "%% BGP: No %s peer is configured with AS %s\n",
1253 get_afi_safi_str(afi, safi, false), arg);
1254
1255 return CMD_SUCCESS;
1256 }
1257
1258 return CMD_SUCCESS;
1259 }
1260
1261 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1262 safi_t safi, enum clear_sort sort,
1263 enum bgp_clear_type stype, const char *arg)
1264 {
1265 struct bgp *bgp;
1266
1267 /* BGP structure lookup. */
1268 if (name) {
1269 bgp = bgp_lookup_by_name(name);
1270 if (bgp == NULL) {
1271 vty_out(vty, "Can't find BGP instance %s\n", name);
1272 return CMD_WARNING;
1273 }
1274 } else {
1275 bgp = bgp_get_default();
1276 if (bgp == NULL) {
1277 vty_out(vty, "No BGP process is configured\n");
1278 return CMD_WARNING;
1279 }
1280 }
1281
1282 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1283 }
1284
1285 /* clear soft inbound */
1286 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1287 {
1288 afi_t afi;
1289 safi_t safi;
1290
1291 FOREACH_AFI_SAFI (afi, safi)
1292 bgp_clear_vty(vty, name, afi, safi, clear_all,
1293 BGP_CLEAR_SOFT_IN, NULL);
1294 }
1295
1296 /* clear soft outbound */
1297 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1298 {
1299 afi_t afi;
1300 safi_t safi;
1301
1302 FOREACH_AFI_SAFI (afi, safi)
1303 bgp_clear_vty(vty, name, afi, safi, clear_all,
1304 BGP_CLEAR_SOFT_OUT, NULL);
1305 }
1306
1307
1308 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1309 {
1310 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1311 }
1312
1313 #ifndef VTYSH_EXTRACT_PL
1314 #include "bgpd/bgp_vty_clippy.c"
1315 #endif
1316
1317 DEFUN_HIDDEN (bgp_local_mac,
1318 bgp_local_mac_cmd,
1319 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1320 BGP_STR
1321 "Local MAC config\n"
1322 "VxLAN Network Identifier\n"
1323 "VNI number\n"
1324 "local mac\n"
1325 "mac address\n"
1326 "mac-mobility sequence\n"
1327 "seq number\n")
1328 {
1329 int rv;
1330 vni_t vni;
1331 struct ethaddr mac;
1332 struct ipaddr ip;
1333 uint32_t seq;
1334 struct bgp *bgp;
1335
1336 vni = strtoul(argv[3]->arg, NULL, 10);
1337 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1338 vty_out(vty, "%% Malformed MAC address\n");
1339 return CMD_WARNING;
1340 }
1341 memset(&ip, 0, sizeof(ip));
1342 seq = strtoul(argv[7]->arg, NULL, 10);
1343
1344 bgp = bgp_get_default();
1345 if (!bgp) {
1346 vty_out(vty, "Default BGP instance is not there\n");
1347 return CMD_WARNING;
1348 }
1349
1350 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1351 zero_esi);
1352 if (rv < 0) {
1353 vty_out(vty, "Internal error\n");
1354 return CMD_WARNING;
1355 }
1356
1357 return CMD_SUCCESS;
1358 }
1359
1360 DEFUN_HIDDEN (no_bgp_local_mac,
1361 no_bgp_local_mac_cmd,
1362 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1363 NO_STR
1364 BGP_STR
1365 "Local MAC config\n"
1366 "VxLAN Network Identifier\n"
1367 "VNI number\n"
1368 "local mac\n"
1369 "mac address\n")
1370 {
1371 int rv;
1372 vni_t vni;
1373 struct ethaddr mac;
1374 struct ipaddr ip;
1375 struct bgp *bgp;
1376
1377 vni = strtoul(argv[4]->arg, NULL, 10);
1378 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1379 vty_out(vty, "%% Malformed MAC address\n");
1380 return CMD_WARNING;
1381 }
1382 memset(&ip, 0, sizeof(ip));
1383
1384 bgp = bgp_get_default();
1385 if (!bgp) {
1386 vty_out(vty, "Default BGP instance is not there\n");
1387 return CMD_WARNING;
1388 }
1389
1390 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1391 if (rv < 0) {
1392 vty_out(vty, "Internal error\n");
1393 return CMD_WARNING;
1394 }
1395
1396 return CMD_SUCCESS;
1397 }
1398
1399 DEFUN (no_synchronization,
1400 no_synchronization_cmd,
1401 "no synchronization",
1402 NO_STR
1403 "Perform IGP synchronization\n")
1404 {
1405 return CMD_SUCCESS;
1406 }
1407
1408 DEFUN (no_auto_summary,
1409 no_auto_summary_cmd,
1410 "no auto-summary",
1411 NO_STR
1412 "Enable automatic network number summarization\n")
1413 {
1414 return CMD_SUCCESS;
1415 }
1416
1417 /* "router bgp" commands. */
1418 DEFUN_NOSH (router_bgp,
1419 router_bgp_cmd,
1420 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1421 ROUTER_STR
1422 BGP_STR
1423 AS_STR
1424 BGP_INSTANCE_HELP_STR)
1425 {
1426 int idx_asn = 2;
1427 int idx_view_vrf = 3;
1428 int idx_vrf = 4;
1429 int is_new_bgp = 0;
1430 int ret;
1431 as_t as;
1432 struct bgp *bgp;
1433 const char *name = NULL;
1434 enum bgp_instance_type inst_type;
1435
1436 // "router bgp" without an ASN
1437 if (argc == 2) {
1438 // Pending: Make VRF option available for ASN less config
1439 bgp = bgp_get_default();
1440
1441 if (bgp == NULL) {
1442 vty_out(vty, "%% No BGP process is configured\n");
1443 return CMD_WARNING_CONFIG_FAILED;
1444 }
1445
1446 if (listcount(bm->bgp) > 1) {
1447 vty_out(vty, "%% Please specify ASN and VRF\n");
1448 return CMD_WARNING_CONFIG_FAILED;
1449 }
1450 }
1451
1452 // "router bgp X"
1453 else {
1454 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1455
1456 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1457 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1458 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1459
1460 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1461 if (argc > 3) {
1462 name = argv[idx_vrf]->arg;
1463
1464 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1465 if (strmatch(name, VRF_DEFAULT_NAME))
1466 name = NULL;
1467 else
1468 inst_type = BGP_INSTANCE_TYPE_VRF;
1469 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1470 inst_type = BGP_INSTANCE_TYPE_VIEW;
1471 }
1472
1473 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1474 is_new_bgp = (bgp_lookup(as, name) == NULL);
1475
1476 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1477 switch (ret) {
1478 case BGP_ERR_AS_MISMATCH:
1479 vty_out(vty, "BGP is already running; AS is %u\n", as);
1480 return CMD_WARNING_CONFIG_FAILED;
1481 case BGP_ERR_INSTANCE_MISMATCH:
1482 vty_out(vty,
1483 "BGP instance name and AS number mismatch\n");
1484 vty_out(vty,
1485 "BGP instance is already running; AS is %u\n",
1486 as);
1487 return CMD_WARNING_CONFIG_FAILED;
1488 }
1489
1490 /*
1491 * If we just instantiated the default instance, complete
1492 * any pending VRF-VPN leaking that was configured via
1493 * earlier "router bgp X vrf FOO" blocks.
1494 */
1495 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1496 vpn_leak_postchange_all();
1497
1498 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1499 bgp_vpn_leak_export(bgp);
1500 /* Pending: handle when user tries to change a view to vrf n vv.
1501 */
1502 }
1503
1504 /* unset the auto created flag as the user config is now present */
1505 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1506 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1507
1508 return CMD_SUCCESS;
1509 }
1510
1511 /* "no router bgp" commands. */
1512 DEFUN (no_router_bgp,
1513 no_router_bgp_cmd,
1514 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1515 NO_STR
1516 ROUTER_STR
1517 BGP_STR
1518 AS_STR
1519 BGP_INSTANCE_HELP_STR)
1520 {
1521 int idx_asn = 3;
1522 int idx_vrf = 5;
1523 as_t as;
1524 struct bgp *bgp;
1525 const char *name = NULL;
1526
1527 // "no router bgp" without an ASN
1528 if (argc == 3) {
1529 // Pending: Make VRF option available for ASN less config
1530 bgp = bgp_get_default();
1531
1532 if (bgp == NULL) {
1533 vty_out(vty, "%% No BGP process is configured\n");
1534 return CMD_WARNING_CONFIG_FAILED;
1535 }
1536
1537 if (listcount(bm->bgp) > 1) {
1538 vty_out(vty, "%% Please specify ASN and VRF\n");
1539 return CMD_WARNING_CONFIG_FAILED;
1540 }
1541
1542 if (bgp->l3vni) {
1543 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1544 bgp->l3vni);
1545 return CMD_WARNING_CONFIG_FAILED;
1546 }
1547 } else {
1548 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1549
1550 if (argc > 4) {
1551 name = argv[idx_vrf]->arg;
1552 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1553 && strmatch(name, VRF_DEFAULT_NAME))
1554 name = NULL;
1555 }
1556
1557 /* Lookup bgp structure. */
1558 bgp = bgp_lookup(as, name);
1559 if (!bgp) {
1560 vty_out(vty, "%% Can't find BGP instance\n");
1561 return CMD_WARNING_CONFIG_FAILED;
1562 }
1563
1564 if (bgp->l3vni) {
1565 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1566 bgp->l3vni);
1567 return CMD_WARNING_CONFIG_FAILED;
1568 }
1569
1570 /* Cannot delete default instance if vrf instances exist */
1571 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1572 struct listnode *node;
1573 struct bgp *tmp_bgp;
1574
1575 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1576 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1577 continue;
1578 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1579 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1580 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1581 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1582 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1583 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1584 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1585 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1586 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1587 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1588 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1589 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1590 (bgp == bgp_get_evpn() &&
1591 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1592 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1593 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1594 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1595 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1596 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1597 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1598 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1599 (hashcount(tmp_bgp->vnihash))) {
1600 vty_out(vty,
1601 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1602 return CMD_WARNING_CONFIG_FAILED;
1603 }
1604 }
1605 }
1606 }
1607
1608 bgp_delete(bgp);
1609
1610 return CMD_SUCCESS;
1611 }
1612
1613 /* bgp session-dscp */
1614
1615 DEFPY (bgp_session_dscp,
1616 bgp_session_dscp_cmd,
1617 "bgp session-dscp (0-63)$dscp",
1618 BGP_STR
1619 "Override default (C6) bgp TCP session DSCP value\n"
1620 "Manually configured dscp parameter\n")
1621 {
1622 bm->tcp_dscp = dscp << 2;
1623
1624 return CMD_SUCCESS;
1625 }
1626
1627 DEFPY (no_bgp_session_dscp,
1628 no_bgp_session_dscp_cmd,
1629 "no bgp session-dscp [(0-63)]",
1630 NO_STR
1631 BGP_STR
1632 "Override default (C6) bgp TCP session DSCP value\n"
1633 "Manually configured dscp parameter\n")
1634 {
1635 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1636
1637 return CMD_SUCCESS;
1638 }
1639
1640 /* BGP router-id. */
1641
1642 DEFPY (bgp_router_id,
1643 bgp_router_id_cmd,
1644 "bgp router-id A.B.C.D",
1645 BGP_STR
1646 "Override configured router identifier\n"
1647 "Manually configured router identifier\n")
1648 {
1649 VTY_DECLVAR_CONTEXT(bgp, bgp);
1650 bgp_router_id_static_set(bgp, router_id);
1651 return CMD_SUCCESS;
1652 }
1653
1654 DEFPY (no_bgp_router_id,
1655 no_bgp_router_id_cmd,
1656 "no bgp router-id [A.B.C.D]",
1657 NO_STR
1658 BGP_STR
1659 "Override configured router identifier\n"
1660 "Manually configured router identifier\n")
1661 {
1662 VTY_DECLVAR_CONTEXT(bgp, bgp);
1663
1664 if (router_id_str) {
1665 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1666 vty_out(vty, "%% BGP router-id doesn't match\n");
1667 return CMD_WARNING_CONFIG_FAILED;
1668 }
1669 }
1670
1671 router_id.s_addr = 0;
1672 bgp_router_id_static_set(bgp, router_id);
1673
1674 return CMD_SUCCESS;
1675 }
1676
1677 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1678 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1679 NO_STR BGP_STR
1680 "Add community specific parameters\n"
1681 "Create an alias for a community\n"
1682 "Community (AA:BB or AA:BB:CC)\n"
1683 "Alias name\n")
1684 {
1685 struct community_alias ca = {};
1686 struct community_alias *lookup_community;
1687 struct community_alias *lookup_alias;
1688 struct community *comm;
1689 struct lcommunity *lcomm;
1690 uint8_t invalid = 0;
1691
1692 comm = community_str2com(community);
1693 if (!comm)
1694 invalid++;
1695 community_free(&comm);
1696
1697 lcomm = lcommunity_str2com(community);
1698 if (!lcomm)
1699 invalid++;
1700 lcommunity_free(&lcomm);
1701
1702 if (invalid > 1) {
1703 vty_out(vty, "Invalid community format\n");
1704 return CMD_WARNING;
1705 }
1706
1707 strlcpy(ca.community, community, sizeof(ca.community));
1708 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1709
1710 lookup_community = bgp_ca_community_lookup(&ca);
1711 lookup_alias = bgp_ca_alias_lookup(&ca);
1712
1713 if (no) {
1714 bgp_ca_alias_delete(&ca);
1715 bgp_ca_community_delete(&ca);
1716 } else {
1717 if (lookup_alias) {
1718 /* Lookup if community hash table has an item
1719 * with the same alias name.
1720 */
1721 strlcpy(ca.community, lookup_alias->community,
1722 sizeof(ca.community));
1723 if (bgp_ca_community_lookup(&ca)) {
1724 vty_out(vty,
1725 "community (%s) already has this alias (%s)\n",
1726 lookup_alias->community,
1727 lookup_alias->alias);
1728 return CMD_WARNING;
1729 }
1730 bgp_ca_alias_delete(&ca);
1731 }
1732
1733 if (lookup_community) {
1734 /* Lookup if alias hash table has an item
1735 * with the same community.
1736 */
1737 strlcpy(ca.alias, lookup_community->alias,
1738 sizeof(ca.alias));
1739 if (bgp_ca_alias_lookup(&ca)) {
1740 vty_out(vty,
1741 "alias (%s) already has this community (%s)\n",
1742 lookup_community->alias,
1743 lookup_community->community);
1744 return CMD_WARNING;
1745 }
1746 bgp_ca_community_delete(&ca);
1747 }
1748
1749 bgp_ca_alias_insert(&ca);
1750 bgp_ca_community_insert(&ca);
1751 }
1752
1753 return CMD_SUCCESS;
1754 }
1755
1756 DEFPY (bgp_global_suppress_fib_pending,
1757 bgp_global_suppress_fib_pending_cmd,
1758 "[no] bgp suppress-fib-pending",
1759 NO_STR
1760 BGP_STR
1761 "Advertise only routes that are programmed in kernel to peers globally\n")
1762 {
1763 bm_wait_for_fib_set(!no);
1764
1765 return CMD_SUCCESS;
1766 }
1767
1768 DEFPY (bgp_suppress_fib_pending,
1769 bgp_suppress_fib_pending_cmd,
1770 "[no] bgp suppress-fib-pending",
1771 NO_STR
1772 BGP_STR
1773 "Advertise only routes that are programmed in kernel to peers\n")
1774 {
1775 VTY_DECLVAR_CONTEXT(bgp, bgp);
1776
1777 bgp_suppress_fib_pending_set(bgp, !no);
1778 return CMD_SUCCESS;
1779 }
1780
1781
1782 /* BGP Cluster ID. */
1783 DEFUN (bgp_cluster_id,
1784 bgp_cluster_id_cmd,
1785 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1786 BGP_STR
1787 "Configure Route-Reflector Cluster-id\n"
1788 "Route-Reflector Cluster-id in IP address format\n"
1789 "Route-Reflector Cluster-id as 32 bit quantity\n")
1790 {
1791 VTY_DECLVAR_CONTEXT(bgp, bgp);
1792 int idx_ipv4 = 2;
1793 int ret;
1794 struct in_addr cluster;
1795
1796 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1797 if (!ret) {
1798 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1799 return CMD_WARNING_CONFIG_FAILED;
1800 }
1801
1802 bgp_cluster_id_set(bgp, &cluster);
1803 bgp_clear_star_soft_out(vty, bgp->name);
1804
1805 return CMD_SUCCESS;
1806 }
1807
1808 DEFUN (no_bgp_cluster_id,
1809 no_bgp_cluster_id_cmd,
1810 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1811 NO_STR
1812 BGP_STR
1813 "Configure Route-Reflector Cluster-id\n"
1814 "Route-Reflector Cluster-id in IP address format\n"
1815 "Route-Reflector Cluster-id as 32 bit quantity\n")
1816 {
1817 VTY_DECLVAR_CONTEXT(bgp, bgp);
1818 bgp_cluster_id_unset(bgp);
1819 bgp_clear_star_soft_out(vty, bgp->name);
1820
1821 return CMD_SUCCESS;
1822 }
1823
1824 DEFPY (bgp_norib,
1825 bgp_norib_cmd,
1826 "bgp no-rib",
1827 BGP_STR
1828 "Disable BGP route installation to RIB (Zebra)\n")
1829 {
1830 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1831 vty_out(vty,
1832 "%% No-RIB option is already set, nothing to do here.\n");
1833 return CMD_SUCCESS;
1834 }
1835
1836 bgp_option_norib_set_runtime();
1837
1838 return CMD_SUCCESS;
1839 }
1840
1841 DEFPY (no_bgp_norib,
1842 no_bgp_norib_cmd,
1843 "no bgp no-rib",
1844 NO_STR
1845 BGP_STR
1846 "Disable BGP route installation to RIB (Zebra)\n")
1847 {
1848 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1849 vty_out(vty,
1850 "%% No-RIB option is not set, nothing to do here.\n");
1851 return CMD_SUCCESS;
1852 }
1853
1854 bgp_option_norib_unset_runtime();
1855
1856 return CMD_SUCCESS;
1857 }
1858
1859 DEFPY (no_bgp_send_extra_data,
1860 no_bgp_send_extra_data_cmd,
1861 "[no] bgp send-extra-data zebra",
1862 NO_STR
1863 BGP_STR
1864 "Extra data to Zebra for display/use\n"
1865 "To zebra\n")
1866 {
1867 if (no)
1868 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1869 else
1870 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1871
1872 return CMD_SUCCESS;
1873 }
1874
1875 DEFUN (bgp_confederation_identifier,
1876 bgp_confederation_identifier_cmd,
1877 "bgp confederation identifier (1-4294967295)",
1878 BGP_STR
1879 "AS confederation parameters\n"
1880 "AS number\n"
1881 "Set routing domain confederation AS\n")
1882 {
1883 VTY_DECLVAR_CONTEXT(bgp, bgp);
1884 int idx_number = 3;
1885 as_t as;
1886
1887 as = strtoul(argv[idx_number]->arg, NULL, 10);
1888
1889 bgp_confederation_id_set(bgp, as);
1890
1891 return CMD_SUCCESS;
1892 }
1893
1894 DEFUN (no_bgp_confederation_identifier,
1895 no_bgp_confederation_identifier_cmd,
1896 "no bgp confederation identifier [(1-4294967295)]",
1897 NO_STR
1898 BGP_STR
1899 "AS confederation parameters\n"
1900 "AS number\n"
1901 "Set routing domain confederation AS\n")
1902 {
1903 VTY_DECLVAR_CONTEXT(bgp, bgp);
1904 bgp_confederation_id_unset(bgp);
1905
1906 return CMD_SUCCESS;
1907 }
1908
1909 DEFUN (bgp_confederation_peers,
1910 bgp_confederation_peers_cmd,
1911 "bgp confederation peers (1-4294967295)...",
1912 BGP_STR
1913 "AS confederation parameters\n"
1914 "Peer ASs in BGP confederation\n"
1915 AS_STR)
1916 {
1917 VTY_DECLVAR_CONTEXT(bgp, bgp);
1918 int idx_asn = 3;
1919 as_t as;
1920 int i;
1921
1922 for (i = idx_asn; i < argc; i++) {
1923 as = strtoul(argv[i]->arg, NULL, 10);
1924
1925 if (bgp->as == as) {
1926 vty_out(vty,
1927 "%% Local member-AS not allowed in confed peer list\n");
1928 continue;
1929 }
1930
1931 bgp_confederation_peers_add(bgp, as);
1932 }
1933 return CMD_SUCCESS;
1934 }
1935
1936 DEFUN (no_bgp_confederation_peers,
1937 no_bgp_confederation_peers_cmd,
1938 "no bgp confederation peers (1-4294967295)...",
1939 NO_STR
1940 BGP_STR
1941 "AS confederation parameters\n"
1942 "Peer ASs in BGP confederation\n"
1943 AS_STR)
1944 {
1945 VTY_DECLVAR_CONTEXT(bgp, bgp);
1946 int idx_asn = 4;
1947 as_t as;
1948 int i;
1949
1950 for (i = idx_asn; i < argc; i++) {
1951 as = strtoul(argv[i]->arg, NULL, 10);
1952
1953 bgp_confederation_peers_remove(bgp, as);
1954 }
1955 return CMD_SUCCESS;
1956 }
1957
1958 /**
1959 * Central routine for maximum-paths configuration.
1960 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1961 * @set: 1 for setting values, 0 for removing the max-paths config.
1962 */
1963 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1964 const char *mpaths, uint16_t options,
1965 int set)
1966 {
1967 VTY_DECLVAR_CONTEXT(bgp, bgp);
1968 uint16_t maxpaths = 0;
1969 int ret;
1970 afi_t afi;
1971 safi_t safi;
1972
1973 afi = bgp_node_afi(vty);
1974 safi = bgp_node_safi(vty);
1975
1976 if (set) {
1977 maxpaths = strtol(mpaths, NULL, 10);
1978 if (maxpaths > multipath_num) {
1979 vty_out(vty,
1980 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1981 maxpaths, multipath_num);
1982 return CMD_WARNING_CONFIG_FAILED;
1983 }
1984 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1985 options);
1986 } else
1987 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1988
1989 if (ret < 0) {
1990 vty_out(vty,
1991 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1992 (set == 1) ? "" : "un",
1993 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1994 maxpaths, afi, safi);
1995 return CMD_WARNING_CONFIG_FAILED;
1996 }
1997
1998 bgp_recalculate_all_bestpaths(bgp);
1999
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (bgp_maxmed_admin,
2004 bgp_maxmed_admin_cmd,
2005 "bgp max-med administrative ",
2006 BGP_STR
2007 "Advertise routes with max-med\n"
2008 "Administratively applied, for an indefinite period\n")
2009 {
2010 VTY_DECLVAR_CONTEXT(bgp, bgp);
2011
2012 bgp->v_maxmed_admin = 1;
2013 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2014
2015 bgp_maxmed_update(bgp);
2016
2017 return CMD_SUCCESS;
2018 }
2019
2020 DEFUN (bgp_maxmed_admin_medv,
2021 bgp_maxmed_admin_medv_cmd,
2022 "bgp max-med administrative (0-4294967295)",
2023 BGP_STR
2024 "Advertise routes with max-med\n"
2025 "Administratively applied, for an indefinite period\n"
2026 "Max MED value to be used\n")
2027 {
2028 VTY_DECLVAR_CONTEXT(bgp, bgp);
2029 int idx_number = 3;
2030
2031 bgp->v_maxmed_admin = 1;
2032 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2033
2034 bgp_maxmed_update(bgp);
2035
2036 return CMD_SUCCESS;
2037 }
2038
2039 DEFUN (no_bgp_maxmed_admin,
2040 no_bgp_maxmed_admin_cmd,
2041 "no bgp max-med administrative [(0-4294967295)]",
2042 NO_STR
2043 BGP_STR
2044 "Advertise routes with max-med\n"
2045 "Administratively applied, for an indefinite period\n"
2046 "Max MED value to be used\n")
2047 {
2048 VTY_DECLVAR_CONTEXT(bgp, bgp);
2049 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2050 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2051 bgp_maxmed_update(bgp);
2052
2053 return CMD_SUCCESS;
2054 }
2055
2056 DEFUN (bgp_maxmed_onstartup,
2057 bgp_maxmed_onstartup_cmd,
2058 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2059 BGP_STR
2060 "Advertise routes with max-med\n"
2061 "Effective on a startup\n"
2062 "Time (seconds) period for max-med\n"
2063 "Max MED value to be used\n")
2064 {
2065 VTY_DECLVAR_CONTEXT(bgp, bgp);
2066 int idx = 0;
2067
2068 if (argv_find(argv, argc, "(5-86400)", &idx))
2069 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2070 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2071 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2072 else
2073 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2074
2075 bgp_maxmed_update(bgp);
2076
2077 return CMD_SUCCESS;
2078 }
2079
2080 DEFUN (no_bgp_maxmed_onstartup,
2081 no_bgp_maxmed_onstartup_cmd,
2082 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2083 NO_STR
2084 BGP_STR
2085 "Advertise routes with max-med\n"
2086 "Effective on a startup\n"
2087 "Time (seconds) period for max-med\n"
2088 "Max MED value to be used\n")
2089 {
2090 VTY_DECLVAR_CONTEXT(bgp, bgp);
2091
2092 /* Cancel max-med onstartup if its on */
2093 if (bgp->t_maxmed_onstartup) {
2094 THREAD_OFF(bgp->t_maxmed_onstartup);
2095 bgp->maxmed_onstartup_over = 1;
2096 }
2097
2098 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2099 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2100
2101 bgp_maxmed_update(bgp);
2102
2103 return CMD_SUCCESS;
2104 }
2105
2106 static int bgp_global_update_delay_config_vty(struct vty *vty,
2107 uint16_t update_delay,
2108 uint16_t establish_wait)
2109 {
2110 struct listnode *node, *nnode;
2111 struct bgp *bgp;
2112 bool vrf_cfg = false;
2113
2114 /*
2115 * See if update-delay is set per-vrf and warn user to delete it
2116 * Note that we only need to check this if this is the first time
2117 * setting the global config.
2118 */
2119 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2120 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2121 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2122 vty_out(vty,
2123 "%% update-delay configuration found in vrf %s\n",
2124 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2125 ? VRF_DEFAULT_NAME
2126 : bgp->name);
2127 vrf_cfg = true;
2128 }
2129 }
2130 }
2131
2132 if (vrf_cfg) {
2133 vty_out(vty,
2134 "%%Failed: global update-delay config not permitted\n");
2135 return CMD_WARNING;
2136 }
2137
2138 if (!establish_wait) { /* update-delay <delay> */
2139 bm->v_update_delay = update_delay;
2140 bm->v_establish_wait = bm->v_update_delay;
2141 } else {
2142 /* update-delay <delay> <establish-wait> */
2143 if (update_delay < establish_wait) {
2144 vty_out(vty,
2145 "%%Failed: update-delay less than the establish-wait!\n");
2146 return CMD_WARNING_CONFIG_FAILED;
2147 }
2148
2149 bm->v_update_delay = update_delay;
2150 bm->v_establish_wait = establish_wait;
2151 }
2152
2153 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2154 bgp->v_update_delay = bm->v_update_delay;
2155 bgp->v_establish_wait = bm->v_establish_wait;
2156 }
2157
2158 return CMD_SUCCESS;
2159 }
2160
2161 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2162 {
2163 struct listnode *node, *nnode;
2164 struct bgp *bgp;
2165
2166 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2167 bm->v_establish_wait = bm->v_update_delay;
2168
2169 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2170 bgp->v_update_delay = bm->v_update_delay;
2171 bgp->v_establish_wait = bm->v_establish_wait;
2172 }
2173
2174 return CMD_SUCCESS;
2175 }
2176
2177 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2178 uint16_t establish_wait)
2179 {
2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
2181
2182 /* if configured globally, per-instance config is not allowed */
2183 if (bm->v_update_delay) {
2184 vty_out(vty,
2185 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2186 return CMD_WARNING_CONFIG_FAILED;
2187 }
2188
2189
2190 if (!establish_wait) /* update-delay <delay> */
2191 {
2192 bgp->v_update_delay = update_delay;
2193 bgp->v_establish_wait = bgp->v_update_delay;
2194 return CMD_SUCCESS;
2195 }
2196
2197 /* update-delay <delay> <establish-wait> */
2198 if (update_delay < establish_wait) {
2199 vty_out(vty,
2200 "%%Failed: update-delay less than the establish-wait!\n");
2201 return CMD_WARNING_CONFIG_FAILED;
2202 }
2203
2204 bgp->v_update_delay = update_delay;
2205 bgp->v_establish_wait = establish_wait;
2206
2207 return CMD_SUCCESS;
2208 }
2209
2210 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2211 {
2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
2213
2214 /* If configured globally, cannot remove from one bgp instance */
2215 if (bm->v_update_delay) {
2216 vty_out(vty,
2217 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2218 return CMD_WARNING_CONFIG_FAILED;
2219 }
2220 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2221 bgp->v_establish_wait = bgp->v_update_delay;
2222
2223 return CMD_SUCCESS;
2224 }
2225
2226 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2227 {
2228 /* If configured globally, no need to display per-instance value */
2229 if (bgp->v_update_delay != bm->v_update_delay) {
2230 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2231 if (bgp->v_update_delay != bgp->v_establish_wait)
2232 vty_out(vty, " %d", bgp->v_establish_wait);
2233 vty_out(vty, "\n");
2234 }
2235 }
2236
2237 /* Global update-delay configuration */
2238 DEFPY (bgp_global_update_delay,
2239 bgp_global_update_delay_cmd,
2240 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2241 BGP_STR
2242 "Force initial delay for best-path and updates for all bgp instances\n"
2243 "Max delay in seconds\n"
2244 "Establish wait in seconds\n")
2245 {
2246 return bgp_global_update_delay_config_vty(vty, delay, wait);
2247 }
2248
2249 /* Global update-delay deconfiguration */
2250 DEFPY (no_bgp_global_update_delay,
2251 no_bgp_global_update_delay_cmd,
2252 "no bgp update-delay [(0-3600) [(1-3600)]]",
2253 NO_STR
2254 BGP_STR
2255 "Force initial delay for best-path and updates\n"
2256 "Max delay in seconds\n"
2257 "Establish wait in seconds\n")
2258 {
2259 return bgp_global_update_delay_deconfig_vty(vty);
2260 }
2261
2262 /* Update-delay configuration */
2263
2264 DEFPY (bgp_update_delay,
2265 bgp_update_delay_cmd,
2266 "update-delay (0-3600)$delay [(1-3600)$wait]",
2267 "Force initial delay for best-path and updates\n"
2268 "Max delay in seconds\n"
2269 "Establish wait in seconds\n")
2270 {
2271 return bgp_update_delay_config_vty(vty, delay, wait);
2272 }
2273
2274 /* Update-delay deconfiguration */
2275 DEFPY (no_bgp_update_delay,
2276 no_bgp_update_delay_cmd,
2277 "no update-delay [(0-3600) [(1-3600)]]",
2278 NO_STR
2279 "Force initial delay for best-path and updates\n"
2280 "Max delay in seconds\n"
2281 "Establish wait in seconds\n")
2282 {
2283 return bgp_update_delay_deconfig_vty(vty);
2284 }
2285
2286
2287 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2288 bool set)
2289 {
2290 VTY_DECLVAR_CONTEXT(bgp, bgp);
2291
2292 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2293 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2294
2295 return CMD_SUCCESS;
2296 }
2297
2298 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2299 bool set)
2300 {
2301 VTY_DECLVAR_CONTEXT(bgp, bgp);
2302
2303 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2304 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2305
2306 return CMD_SUCCESS;
2307 }
2308
2309 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2310 {
2311 uint32_t quanta =
2312 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2313 if (quanta != BGP_WRITE_PACKET_MAX)
2314 vty_out(vty, " write-quanta %d\n", quanta);
2315 }
2316
2317 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2318 {
2319 uint32_t quanta =
2320 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2321 if (quanta != BGP_READ_PACKET_MAX)
2322 vty_out(vty, " read-quanta %d\n", quanta);
2323 }
2324
2325 /* Packet quanta configuration
2326 *
2327 * XXX: The value set here controls the size of a stack buffer in the IO
2328 * thread. When changing these limits be careful to prevent stack overflow.
2329 *
2330 * Furthermore, the maximums used here should correspond to
2331 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2332 */
2333 DEFPY (bgp_wpkt_quanta,
2334 bgp_wpkt_quanta_cmd,
2335 "[no] write-quanta (1-64)$quanta",
2336 NO_STR
2337 "How many packets to write to peer socket per run\n"
2338 "Number of packets\n")
2339 {
2340 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2341 }
2342
2343 DEFPY (bgp_rpkt_quanta,
2344 bgp_rpkt_quanta_cmd,
2345 "[no] read-quanta (1-10)$quanta",
2346 NO_STR
2347 "How many packets to read from peer socket per I/O cycle\n"
2348 "Number of packets\n")
2349 {
2350 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2351 }
2352
2353 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2354 {
2355 if (!bgp->heuristic_coalesce)
2356 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2357 }
2358
2359 /* BGP TCP keepalive */
2360 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2361 {
2362 if (bgp->tcp_keepalive_idle) {
2363 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2364 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2365 bgp->tcp_keepalive_probes);
2366 }
2367 }
2368
2369 DEFUN (bgp_coalesce_time,
2370 bgp_coalesce_time_cmd,
2371 "coalesce-time (0-4294967295)",
2372 "Subgroup coalesce timer\n"
2373 "Subgroup coalesce timer value (in ms)\n")
2374 {
2375 VTY_DECLVAR_CONTEXT(bgp, bgp);
2376
2377 int idx = 0;
2378
2379 bgp->heuristic_coalesce = false;
2380
2381 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2382 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2383
2384 return CMD_SUCCESS;
2385 }
2386
2387 DEFUN (no_bgp_coalesce_time,
2388 no_bgp_coalesce_time_cmd,
2389 "no coalesce-time (0-4294967295)",
2390 NO_STR
2391 "Subgroup coalesce timer\n"
2392 "Subgroup coalesce timer value (in ms)\n")
2393 {
2394 VTY_DECLVAR_CONTEXT(bgp, bgp);
2395
2396 bgp->heuristic_coalesce = true;
2397 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2398 return CMD_SUCCESS;
2399 }
2400
2401 /* Maximum-paths configuration */
2402 DEFUN (bgp_maxpaths,
2403 bgp_maxpaths_cmd,
2404 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2405 "Forward packets over multiple paths\n"
2406 "Number of paths\n")
2407 {
2408 int idx_number = 1;
2409 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2410 argv[idx_number]->arg, 0, 1);
2411 }
2412
2413 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2414 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2415 "Forward packets over multiple paths\n"
2416 "Number of paths\n")
2417
2418 DEFUN (bgp_maxpaths_ibgp,
2419 bgp_maxpaths_ibgp_cmd,
2420 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2421 "Forward packets over multiple paths\n"
2422 "iBGP-multipath\n"
2423 "Number of paths\n")
2424 {
2425 int idx_number = 2;
2426 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2427 argv[idx_number]->arg, 0, 1);
2428 }
2429
2430 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2431 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2432 "Forward packets over multiple paths\n"
2433 "iBGP-multipath\n"
2434 "Number of paths\n")
2435
2436 DEFUN (bgp_maxpaths_ibgp_cluster,
2437 bgp_maxpaths_ibgp_cluster_cmd,
2438 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2439 "Forward packets over multiple paths\n"
2440 "iBGP-multipath\n"
2441 "Number of paths\n"
2442 "Match the cluster length\n")
2443 {
2444 int idx_number = 2;
2445 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2446 argv[idx_number]->arg, true, 1);
2447 }
2448
2449 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2450 "maximum-paths ibgp " CMD_RANGE_STR(
2451 1, MULTIPATH_NUM) " equal-cluster-length",
2452 "Forward packets over multiple paths\n"
2453 "iBGP-multipath\n"
2454 "Number of paths\n"
2455 "Match the cluster length\n")
2456
2457 DEFUN (no_bgp_maxpaths,
2458 no_bgp_maxpaths_cmd,
2459 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2460 NO_STR
2461 "Forward packets over multiple paths\n"
2462 "Number of paths\n")
2463 {
2464 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2465 }
2466
2467 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2468 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2469 "Forward packets over multiple paths\n"
2470 "Number of paths\n")
2471
2472 DEFUN (no_bgp_maxpaths_ibgp,
2473 no_bgp_maxpaths_ibgp_cmd,
2474 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2475 NO_STR
2476 "Forward packets over multiple paths\n"
2477 "iBGP-multipath\n"
2478 "Number of paths\n"
2479 "Match the cluster length\n")
2480 {
2481 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2482 }
2483
2484 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2485 "no maximum-paths ibgp [" CMD_RANGE_STR(
2486 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2487 NO_STR
2488 "Forward packets over multiple paths\n"
2489 "iBGP-multipath\n"
2490 "Number of paths\n"
2491 "Match the cluster length\n")
2492
2493 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2494 afi_t afi, safi_t safi)
2495 {
2496 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2497 vty_out(vty, " maximum-paths %d\n",
2498 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2499 }
2500
2501 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2502 vty_out(vty, " maximum-paths ibgp %d",
2503 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2504 if (bgp->maxpaths[afi][safi].same_clusterlen)
2505 vty_out(vty, " equal-cluster-length");
2506 vty_out(vty, "\n");
2507 }
2508 }
2509
2510 /* BGP timers. */
2511
2512 DEFUN (bgp_timers,
2513 bgp_timers_cmd,
2514 "timers bgp (0-65535) (0-65535)",
2515 "Adjust routing timers\n"
2516 "BGP timers\n"
2517 "Keepalive interval\n"
2518 "Holdtime\n")
2519 {
2520 VTY_DECLVAR_CONTEXT(bgp, bgp);
2521 int idx_number = 2;
2522 int idx_number_2 = 3;
2523 unsigned long keepalive = 0;
2524 unsigned long holdtime = 0;
2525
2526 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2527 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2528
2529 /* Holdtime value check. */
2530 if (holdtime < 3 && holdtime != 0) {
2531 vty_out(vty,
2532 "%% hold time value must be either 0 or greater than 3\n");
2533 return CMD_WARNING_CONFIG_FAILED;
2534 }
2535
2536 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2537 BGP_DEFAULT_DELAYOPEN);
2538
2539 return CMD_SUCCESS;
2540 }
2541
2542 DEFUN (no_bgp_timers,
2543 no_bgp_timers_cmd,
2544 "no timers bgp [(0-65535) (0-65535)]",
2545 NO_STR
2546 "Adjust routing timers\n"
2547 "BGP timers\n"
2548 "Keepalive interval\n"
2549 "Holdtime\n")
2550 {
2551 VTY_DECLVAR_CONTEXT(bgp, bgp);
2552 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2553 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2554
2555 return CMD_SUCCESS;
2556 }
2557
2558 /* BGP minimum holdtime. */
2559
2560 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2561 "bgp minimum-holdtime (1-65535)",
2562 "BGP specific commands\n"
2563 "BGP minimum holdtime\n"
2564 "Seconds\n")
2565 {
2566 VTY_DECLVAR_CONTEXT(bgp, bgp);
2567 int idx_number = 2;
2568 unsigned long min_holdtime;
2569
2570 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2571
2572 bgp->default_min_holdtime = min_holdtime;
2573
2574 return CMD_SUCCESS;
2575 }
2576
2577 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2578 "no bgp minimum-holdtime [(1-65535)]",
2579 NO_STR
2580 "BGP specific commands\n"
2581 "BGP minimum holdtime\n"
2582 "Seconds\n")
2583 {
2584 VTY_DECLVAR_CONTEXT(bgp, bgp);
2585
2586 bgp->default_min_holdtime = 0;
2587
2588 return CMD_SUCCESS;
2589 }
2590
2591 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2592 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2593 BGP_STR
2594 "TCP keepalive parameters\n"
2595 "TCP keepalive idle time (seconds)\n"
2596 "TCP keepalive interval (seconds)\n"
2597 "TCP keepalive maximum probes\n")
2598 {
2599 VTY_DECLVAR_CONTEXT(bgp, bgp);
2600
2601 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2602 (uint16_t)probes);
2603
2604 return CMD_SUCCESS;
2605 }
2606
2607 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2608 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2609 NO_STR
2610 BGP_STR
2611 "TCP keepalive parameters\n"
2612 "TCP keepalive idle time (seconds)\n"
2613 "TCP keepalive interval (seconds)\n"
2614 "TCP keepalive maximum probes\n")
2615 {
2616 VTY_DECLVAR_CONTEXT(bgp, bgp);
2617
2618 bgp_tcp_keepalive_unset(bgp);
2619
2620 return CMD_SUCCESS;
2621 }
2622
2623 DEFUN (bgp_client_to_client_reflection,
2624 bgp_client_to_client_reflection_cmd,
2625 "bgp client-to-client reflection",
2626 BGP_STR
2627 "Configure client to client route reflection\n"
2628 "reflection of routes allowed\n")
2629 {
2630 VTY_DECLVAR_CONTEXT(bgp, bgp);
2631 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2632 bgp_clear_star_soft_out(vty, bgp->name);
2633
2634 return CMD_SUCCESS;
2635 }
2636
2637 DEFUN (no_bgp_client_to_client_reflection,
2638 no_bgp_client_to_client_reflection_cmd,
2639 "no bgp client-to-client reflection",
2640 NO_STR
2641 BGP_STR
2642 "Configure client to client route reflection\n"
2643 "reflection of routes allowed\n")
2644 {
2645 VTY_DECLVAR_CONTEXT(bgp, bgp);
2646 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2647 bgp_clear_star_soft_out(vty, bgp->name);
2648
2649 return CMD_SUCCESS;
2650 }
2651
2652 /* "bgp always-compare-med" configuration. */
2653 DEFUN (bgp_always_compare_med,
2654 bgp_always_compare_med_cmd,
2655 "bgp always-compare-med",
2656 BGP_STR
2657 "Allow comparing MED from different neighbors\n")
2658 {
2659 VTY_DECLVAR_CONTEXT(bgp, bgp);
2660 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2661 bgp_recalculate_all_bestpaths(bgp);
2662
2663 return CMD_SUCCESS;
2664 }
2665
2666 DEFUN (no_bgp_always_compare_med,
2667 no_bgp_always_compare_med_cmd,
2668 "no bgp always-compare-med",
2669 NO_STR
2670 BGP_STR
2671 "Allow comparing MED from different neighbors\n")
2672 {
2673 VTY_DECLVAR_CONTEXT(bgp, bgp);
2674 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2675 bgp_recalculate_all_bestpaths(bgp);
2676
2677 return CMD_SUCCESS;
2678 }
2679
2680
2681 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2682 "bgp ebgp-requires-policy",
2683 BGP_STR
2684 "Require in and out policy for eBGP peers (RFC8212)\n")
2685 {
2686 VTY_DECLVAR_CONTEXT(bgp, bgp);
2687 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2688 return CMD_SUCCESS;
2689 }
2690
2691 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2692 "no bgp ebgp-requires-policy",
2693 NO_STR
2694 BGP_STR
2695 "Require in and out policy for eBGP peers (RFC8212)\n")
2696 {
2697 VTY_DECLVAR_CONTEXT(bgp, bgp);
2698 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2699 return CMD_SUCCESS;
2700 }
2701
2702 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2703 "bgp suppress-duplicates",
2704 BGP_STR
2705 "Suppress duplicate updates if the route actually not changed\n")
2706 {
2707 VTY_DECLVAR_CONTEXT(bgp, bgp);
2708 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2709 return CMD_SUCCESS;
2710 }
2711
2712 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2713 "no bgp suppress-duplicates",
2714 NO_STR
2715 BGP_STR
2716 "Suppress duplicate updates if the route actually not changed\n")
2717 {
2718 VTY_DECLVAR_CONTEXT(bgp, bgp);
2719 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2720 return CMD_SUCCESS;
2721 }
2722
2723 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2724 "bgp reject-as-sets",
2725 BGP_STR
2726 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2727 {
2728 VTY_DECLVAR_CONTEXT(bgp, bgp);
2729 struct listnode *node, *nnode;
2730 struct peer *peer;
2731
2732 bgp->reject_as_sets = true;
2733
2734 /* Reset existing BGP sessions to reject routes
2735 * with aspath containing AS_SET or AS_CONFED_SET.
2736 */
2737 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2738 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2739 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2740 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2741 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2742 }
2743 }
2744
2745 return CMD_SUCCESS;
2746 }
2747
2748 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2749 "no bgp reject-as-sets",
2750 NO_STR
2751 BGP_STR
2752 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2753 {
2754 VTY_DECLVAR_CONTEXT(bgp, bgp);
2755 struct listnode *node, *nnode;
2756 struct peer *peer;
2757
2758 bgp->reject_as_sets = false;
2759
2760 /* Reset existing BGP sessions to reject routes
2761 * with aspath containing AS_SET or AS_CONFED_SET.
2762 */
2763 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2764 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2765 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2766 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2767 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2768 }
2769 }
2770
2771 return CMD_SUCCESS;
2772 }
2773
2774 /* "bgp deterministic-med" configuration. */
2775 DEFUN (bgp_deterministic_med,
2776 bgp_deterministic_med_cmd,
2777 "bgp deterministic-med",
2778 BGP_STR
2779 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2780 {
2781 VTY_DECLVAR_CONTEXT(bgp, bgp);
2782
2783 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2784 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2785 bgp_recalculate_all_bestpaths(bgp);
2786 }
2787
2788 return CMD_SUCCESS;
2789 }
2790
2791 DEFUN (no_bgp_deterministic_med,
2792 no_bgp_deterministic_med_cmd,
2793 "no bgp deterministic-med",
2794 NO_STR
2795 BGP_STR
2796 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2797 {
2798 VTY_DECLVAR_CONTEXT(bgp, bgp);
2799 int bestpath_per_as_used;
2800 afi_t afi;
2801 safi_t safi;
2802 struct peer *peer;
2803 struct listnode *node, *nnode;
2804
2805 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2806 bestpath_per_as_used = 0;
2807
2808 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2809 FOREACH_AFI_SAFI (afi, safi)
2810 if (bgp_addpath_dmed_required(
2811 peer->addpath_type[afi][safi])) {
2812 bestpath_per_as_used = 1;
2813 break;
2814 }
2815
2816 if (bestpath_per_as_used)
2817 break;
2818 }
2819
2820 if (bestpath_per_as_used) {
2821 vty_out(vty,
2822 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2823 return CMD_WARNING_CONFIG_FAILED;
2824 } else {
2825 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2826 bgp_recalculate_all_bestpaths(bgp);
2827 }
2828 }
2829
2830 return CMD_SUCCESS;
2831 }
2832
2833 /* "bgp graceful-restart mode" configuration. */
2834 DEFUN (bgp_graceful_restart,
2835 bgp_graceful_restart_cmd,
2836 "bgp graceful-restart",
2837 BGP_STR
2838 GR_CMD
2839 )
2840 {
2841 int ret = BGP_GR_FAILURE;
2842
2843 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2844 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2845
2846 VTY_DECLVAR_CONTEXT(bgp, bgp);
2847
2848 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2849
2850 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2851 ret);
2852
2853 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2854 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2855 vty_out(vty,
2856 "Graceful restart configuration changed, reset all peers to take effect\n");
2857 return bgp_vty_return(vty, ret);
2858 }
2859
2860 DEFUN (no_bgp_graceful_restart,
2861 no_bgp_graceful_restart_cmd,
2862 "no bgp graceful-restart",
2863 NO_STR
2864 BGP_STR
2865 NO_GR_CMD
2866 )
2867 {
2868 VTY_DECLVAR_CONTEXT(bgp, bgp);
2869
2870 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2871 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2872
2873 int ret = BGP_GR_FAILURE;
2874
2875 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2876
2877 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2878 ret);
2879
2880 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2881 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2882 vty_out(vty,
2883 "Graceful restart configuration changed, reset all peers to take effect\n");
2884
2885 return bgp_vty_return(vty, ret);
2886 }
2887
2888 DEFUN (bgp_graceful_restart_stalepath_time,
2889 bgp_graceful_restart_stalepath_time_cmd,
2890 "bgp graceful-restart stalepath-time (1-4095)",
2891 BGP_STR
2892 "Graceful restart capability parameters\n"
2893 "Set the max time to hold onto restarting peer's stale paths\n"
2894 "Delay value (seconds)\n")
2895 {
2896 VTY_DECLVAR_CONTEXT(bgp, bgp);
2897 int idx_number = 3;
2898 uint32_t stalepath;
2899
2900 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2901 bgp->stalepath_time = stalepath;
2902 return CMD_SUCCESS;
2903 }
2904
2905 DEFUN (bgp_graceful_restart_restart_time,
2906 bgp_graceful_restart_restart_time_cmd,
2907 "bgp graceful-restart restart-time (0-4095)",
2908 BGP_STR
2909 "Graceful restart capability parameters\n"
2910 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2911 "Delay value (seconds)\n")
2912 {
2913 VTY_DECLVAR_CONTEXT(bgp, bgp);
2914 int idx_number = 3;
2915 uint32_t restart;
2916
2917 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2918 bgp->restart_time = restart;
2919 return CMD_SUCCESS;
2920 }
2921
2922 DEFUN (bgp_graceful_restart_select_defer_time,
2923 bgp_graceful_restart_select_defer_time_cmd,
2924 "bgp graceful-restart select-defer-time (0-3600)",
2925 BGP_STR
2926 "Graceful restart capability parameters\n"
2927 "Set the time to defer the BGP route selection after restart\n"
2928 "Delay value (seconds, 0 - disable)\n")
2929 {
2930 VTY_DECLVAR_CONTEXT(bgp, bgp);
2931 int idx_number = 3;
2932 uint32_t defer_time;
2933
2934 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2935 bgp->select_defer_time = defer_time;
2936 if (defer_time == 0)
2937 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2938 else
2939 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2940
2941 return CMD_SUCCESS;
2942 }
2943
2944 DEFUN (no_bgp_graceful_restart_stalepath_time,
2945 no_bgp_graceful_restart_stalepath_time_cmd,
2946 "no bgp graceful-restart stalepath-time [(1-4095)]",
2947 NO_STR
2948 BGP_STR
2949 "Graceful restart capability parameters\n"
2950 "Set the max time to hold onto restarting peer's stale paths\n"
2951 "Delay value (seconds)\n")
2952 {
2953 VTY_DECLVAR_CONTEXT(bgp, bgp);
2954
2955 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2956 return CMD_SUCCESS;
2957 }
2958
2959 DEFUN (no_bgp_graceful_restart_restart_time,
2960 no_bgp_graceful_restart_restart_time_cmd,
2961 "no bgp graceful-restart restart-time [(0-4095)]",
2962 NO_STR
2963 BGP_STR
2964 "Graceful restart capability parameters\n"
2965 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2966 "Delay value (seconds)\n")
2967 {
2968 VTY_DECLVAR_CONTEXT(bgp, bgp);
2969
2970 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2971 return CMD_SUCCESS;
2972 }
2973
2974 DEFUN (no_bgp_graceful_restart_select_defer_time,
2975 no_bgp_graceful_restart_select_defer_time_cmd,
2976 "no bgp graceful-restart select-defer-time [(0-3600)]",
2977 NO_STR
2978 BGP_STR
2979 "Graceful restart capability parameters\n"
2980 "Set the time to defer the BGP route selection after restart\n"
2981 "Delay value (seconds)\n")
2982 {
2983 VTY_DECLVAR_CONTEXT(bgp, bgp);
2984
2985 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2986 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2987
2988 return CMD_SUCCESS;
2989 }
2990
2991 DEFUN (bgp_graceful_restart_preserve_fw,
2992 bgp_graceful_restart_preserve_fw_cmd,
2993 "bgp graceful-restart preserve-fw-state",
2994 BGP_STR
2995 "Graceful restart capability parameters\n"
2996 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2997 {
2998 VTY_DECLVAR_CONTEXT(bgp, bgp);
2999 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3000 return CMD_SUCCESS;
3001 }
3002
3003 DEFUN (no_bgp_graceful_restart_preserve_fw,
3004 no_bgp_graceful_restart_preserve_fw_cmd,
3005 "no bgp graceful-restart preserve-fw-state",
3006 NO_STR
3007 BGP_STR
3008 "Graceful restart capability parameters\n"
3009 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3010 {
3011 VTY_DECLVAR_CONTEXT(bgp, bgp);
3012 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3013 return CMD_SUCCESS;
3014 }
3015
3016 DEFPY (bgp_graceful_restart_notification,
3017 bgp_graceful_restart_notification_cmd,
3018 "[no$no] bgp graceful-restart notification",
3019 NO_STR
3020 BGP_STR
3021 "Graceful restart capability parameters\n"
3022 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3023 {
3024 VTY_DECLVAR_CONTEXT(bgp, bgp);
3025
3026 if (no)
3027 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3028 else
3029 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3030
3031 return CMD_SUCCESS;
3032 }
3033
3034 DEFPY (bgp_administrative_reset,
3035 bgp_administrative_reset_cmd,
3036 "[no$no] bgp hard-administrative-reset",
3037 NO_STR
3038 BGP_STR
3039 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3040 {
3041 VTY_DECLVAR_CONTEXT(bgp, bgp);
3042
3043 if (no)
3044 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3045 else
3046 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3047
3048 return CMD_SUCCESS;
3049 }
3050
3051 DEFUN (bgp_graceful_restart_disable,
3052 bgp_graceful_restart_disable_cmd,
3053 "bgp graceful-restart-disable",
3054 BGP_STR
3055 GR_DISABLE)
3056 {
3057 int ret = BGP_GR_FAILURE;
3058
3059 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3060 zlog_debug(
3061 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3062
3063 VTY_DECLVAR_CONTEXT(bgp, bgp);
3064
3065 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3066
3067 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3068 bgp->peer, ret);
3069
3070 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3071 zlog_debug(
3072 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3073 vty_out(vty,
3074 "Graceful restart configuration changed, reset all peers to take effect\n");
3075
3076 return bgp_vty_return(vty, ret);
3077 }
3078
3079 DEFUN (no_bgp_graceful_restart_disable,
3080 no_bgp_graceful_restart_disable_cmd,
3081 "no bgp graceful-restart-disable",
3082 NO_STR
3083 BGP_STR
3084 NO_GR_DISABLE
3085 )
3086 {
3087 VTY_DECLVAR_CONTEXT(bgp, bgp);
3088
3089 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3090 zlog_debug(
3091 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3092
3093 int ret = BGP_GR_FAILURE;
3094
3095 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3096
3097 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3098 ret);
3099
3100 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3101 zlog_debug(
3102 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3103 vty_out(vty,
3104 "Graceful restart configuration changed, reset all peers to take effect\n");
3105
3106 return bgp_vty_return(vty, ret);
3107 }
3108
3109 DEFUN (bgp_neighbor_graceful_restart_set,
3110 bgp_neighbor_graceful_restart_set_cmd,
3111 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3112 NEIGHBOR_STR
3113 NEIGHBOR_ADDR_STR2
3114 GR_NEIGHBOR_CMD
3115 )
3116 {
3117 int idx_peer = 1;
3118 struct peer *peer;
3119 int ret = BGP_GR_FAILURE;
3120
3121 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3122
3123 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3124 zlog_debug(
3125 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3126
3127 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3128 if (!peer)
3129 return CMD_WARNING_CONFIG_FAILED;
3130
3131 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3132
3133 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3134 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3135
3136 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3137 zlog_debug(
3138 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3139 vty_out(vty,
3140 "Graceful restart configuration changed, reset this peer to take effect\n");
3141
3142 return bgp_vty_return(vty, ret);
3143 }
3144
3145 DEFUN (no_bgp_neighbor_graceful_restart,
3146 no_bgp_neighbor_graceful_restart_set_cmd,
3147 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3148 NO_STR
3149 NEIGHBOR_STR
3150 NEIGHBOR_ADDR_STR2
3151 NO_GR_NEIGHBOR_CMD
3152 )
3153 {
3154 int idx_peer = 2;
3155 int ret = BGP_GR_FAILURE;
3156 struct peer *peer;
3157
3158 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3159
3160 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3161 if (!peer)
3162 return CMD_WARNING_CONFIG_FAILED;
3163
3164 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3165 zlog_debug(
3166 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3167
3168 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3169
3170 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3171 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3172
3173 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3174 zlog_debug(
3175 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3176 vty_out(vty,
3177 "Graceful restart configuration changed, reset this peer to take effect\n");
3178
3179 return bgp_vty_return(vty, ret);
3180 }
3181
3182 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3183 bgp_neighbor_graceful_restart_helper_set_cmd,
3184 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3185 NEIGHBOR_STR
3186 NEIGHBOR_ADDR_STR2
3187 GR_NEIGHBOR_HELPER_CMD
3188 )
3189 {
3190 int idx_peer = 1;
3191 struct peer *peer;
3192 int ret = BGP_GR_FAILURE;
3193
3194 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3195
3196 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3197 zlog_debug(
3198 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3199
3200 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3201
3202 if (!peer)
3203 return CMD_WARNING_CONFIG_FAILED;
3204
3205
3206 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3207
3208 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3209 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3210
3211 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3212 zlog_debug(
3213 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3214 vty_out(vty,
3215 "Graceful restart configuration changed, reset this peer to take effect\n");
3216
3217 return bgp_vty_return(vty, ret);
3218 }
3219
3220 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3221 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3222 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3223 NO_STR
3224 NEIGHBOR_STR
3225 NEIGHBOR_ADDR_STR2
3226 NO_GR_NEIGHBOR_HELPER_CMD
3227 )
3228 {
3229 int idx_peer = 2;
3230 int ret = BGP_GR_FAILURE;
3231 struct peer *peer;
3232
3233 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3234
3235 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3236 if (!peer)
3237 return CMD_WARNING_CONFIG_FAILED;
3238
3239 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3240 zlog_debug(
3241 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3242
3243 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3244
3245 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3246 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3247
3248 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3249 zlog_debug(
3250 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3251 vty_out(vty,
3252 "Graceful restart configuration changed, reset this peer to take effect\n");
3253
3254 return bgp_vty_return(vty, ret);
3255 }
3256
3257 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3258 bgp_neighbor_graceful_restart_disable_set_cmd,
3259 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3260 NEIGHBOR_STR
3261 NEIGHBOR_ADDR_STR2
3262 GR_NEIGHBOR_DISABLE_CMD
3263 )
3264 {
3265 int idx_peer = 1;
3266 struct peer *peer;
3267 int ret = BGP_GR_FAILURE;
3268
3269 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3270
3271 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3272 zlog_debug(
3273 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3274
3275 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3276 if (!peer)
3277 return CMD_WARNING_CONFIG_FAILED;
3278
3279 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3280
3281 if (peer->bgp->t_startup)
3282 bgp_peer_gr_flags_update(peer);
3283
3284 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3285 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3286
3287 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3288 zlog_debug(
3289 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3290 vty_out(vty,
3291 "Graceful restart configuration changed, reset this peer to take effect\n");
3292
3293 return bgp_vty_return(vty, ret);
3294 }
3295
3296 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3297 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3298 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3299 NO_STR
3300 NEIGHBOR_STR
3301 NEIGHBOR_ADDR_STR2
3302 NO_GR_NEIGHBOR_DISABLE_CMD
3303 )
3304 {
3305 int idx_peer = 2;
3306 int ret = BGP_GR_FAILURE;
3307 struct peer *peer;
3308
3309 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3310
3311 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3312 if (!peer)
3313 return CMD_WARNING_CONFIG_FAILED;
3314
3315 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3316 zlog_debug(
3317 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3318
3319 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3320
3321 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3322 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3323
3324 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3325 zlog_debug(
3326 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3327 vty_out(vty,
3328 "Graceful restart configuration changed, reset this peer to take effect\n");
3329
3330 return bgp_vty_return(vty, ret);
3331 }
3332
3333 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3334 bgp_graceful_restart_disable_eor_cmd,
3335 "bgp graceful-restart disable-eor",
3336 BGP_STR
3337 "Graceful restart configuration parameters\n"
3338 "Disable EOR Check\n")
3339 {
3340 VTY_DECLVAR_CONTEXT(bgp, bgp);
3341 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3342
3343 return CMD_SUCCESS;
3344 }
3345
3346 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3347 no_bgp_graceful_restart_disable_eor_cmd,
3348 "no bgp graceful-restart disable-eor",
3349 NO_STR
3350 BGP_STR
3351 "Graceful restart configuration parameters\n"
3352 "Disable EOR Check\n")
3353 {
3354 VTY_DECLVAR_CONTEXT(bgp, bgp);
3355 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3356
3357 return CMD_SUCCESS;
3358 }
3359
3360 DEFUN (bgp_graceful_restart_rib_stale_time,
3361 bgp_graceful_restart_rib_stale_time_cmd,
3362 "bgp graceful-restart rib-stale-time (1-3600)",
3363 BGP_STR
3364 "Graceful restart configuration parameters\n"
3365 "Specify the stale route removal timer in rib\n"
3366 "Delay value (seconds)\n")
3367 {
3368 VTY_DECLVAR_CONTEXT(bgp, bgp);
3369 int idx_number = 3;
3370 uint32_t stale_time;
3371
3372 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3373 bgp->rib_stale_time = stale_time;
3374 /* Send the stale timer update message to RIB */
3375 if (bgp_zebra_stale_timer_update(bgp))
3376 return CMD_WARNING;
3377
3378 return CMD_SUCCESS;
3379 }
3380
3381 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3382 no_bgp_graceful_restart_rib_stale_time_cmd,
3383 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3384 NO_STR
3385 BGP_STR
3386 "Graceful restart configuration parameters\n"
3387 "Specify the stale route removal timer in rib\n"
3388 "Delay value (seconds)\n")
3389 {
3390 VTY_DECLVAR_CONTEXT(bgp, bgp);
3391
3392 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3393 /* Send the stale timer update message to RIB */
3394 if (bgp_zebra_stale_timer_update(bgp))
3395 return CMD_WARNING;
3396
3397 return CMD_SUCCESS;
3398 }
3399
3400 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3401 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3402 BGP_STR
3403 "Enable Long-lived Graceful Restart\n"
3404 "Specifies maximum time to wait before purging long-lived stale routes\n"
3405 "Stale time value (seconds)\n")
3406 {
3407 VTY_DECLVAR_CONTEXT(bgp, bgp);
3408
3409 uint32_t llgr_stale_time;
3410
3411 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3412 bgp->llgr_stale_time = llgr_stale_time;
3413
3414 return CMD_SUCCESS;
3415 }
3416
3417 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3418 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3419 NO_STR BGP_STR
3420 "Enable Long-lived Graceful Restart\n"
3421 "Specifies maximum time to wait before purging long-lived stale routes\n"
3422 "Stale time value (seconds)\n")
3423 {
3424 VTY_DECLVAR_CONTEXT(bgp, bgp);
3425
3426 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3427
3428 return CMD_SUCCESS;
3429 }
3430
3431 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3432 struct bgp *bgp)
3433 {
3434 bgp_static_redo_import_check(bgp);
3435 bgp_redistribute_redo(bgp);
3436 bgp_clear_star_soft_out(vty, bgp->name);
3437 bgp_clear_star_soft_in(vty, bgp->name);
3438 }
3439
3440 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3441 {
3442 struct listnode *node, *nnode;
3443 struct bgp *bgp;
3444 bool vrf_cfg = false;
3445
3446 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3447 return CMD_SUCCESS;
3448
3449 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3450 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3451 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3452 vty_out(vty,
3453 "%% graceful-shutdown configuration found in vrf %s\n",
3454 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3455 VRF_DEFAULT_NAME : bgp->name);
3456 vrf_cfg = true;
3457 }
3458 }
3459
3460 if (vrf_cfg) {
3461 vty_out(vty,
3462 "%%Failed: global graceful-shutdown not permitted\n");
3463 return CMD_WARNING;
3464 }
3465
3466 /* Set flag globally */
3467 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3468
3469 /* Initiate processing for all BGP instances. */
3470 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3471 bgp_initiate_graceful_shut_unshut(vty, bgp);
3472
3473 return CMD_SUCCESS;
3474 }
3475
3476 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3477 {
3478 struct listnode *node, *nnode;
3479 struct bgp *bgp;
3480
3481 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3482 return CMD_SUCCESS;
3483
3484 /* Unset flag globally */
3485 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3486
3487 /* Initiate processing for all BGP instances. */
3488 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3489 bgp_initiate_graceful_shut_unshut(vty, bgp);
3490
3491 return CMD_SUCCESS;
3492 }
3493
3494 /* "bgp graceful-shutdown" configuration */
3495 DEFUN (bgp_graceful_shutdown,
3496 bgp_graceful_shutdown_cmd,
3497 "bgp graceful-shutdown",
3498 BGP_STR
3499 "Graceful shutdown parameters\n")
3500 {
3501 if (vty->node == CONFIG_NODE)
3502 return bgp_global_graceful_shutdown_config_vty(vty);
3503
3504 VTY_DECLVAR_CONTEXT(bgp, bgp);
3505
3506 /* if configured globally, per-instance config is not allowed */
3507 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3508 vty_out(vty,
3509 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3510 return CMD_WARNING_CONFIG_FAILED;
3511 }
3512
3513 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3514 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3515 bgp_initiate_graceful_shut_unshut(vty, bgp);
3516 }
3517
3518 return CMD_SUCCESS;
3519 }
3520
3521 DEFUN (no_bgp_graceful_shutdown,
3522 no_bgp_graceful_shutdown_cmd,
3523 "no bgp graceful-shutdown",
3524 NO_STR
3525 BGP_STR
3526 "Graceful shutdown parameters\n")
3527 {
3528 if (vty->node == CONFIG_NODE)
3529 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3530
3531 VTY_DECLVAR_CONTEXT(bgp, bgp);
3532
3533 /* If configured globally, cannot remove from one bgp instance */
3534 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3535 vty_out(vty,
3536 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3537 return CMD_WARNING_CONFIG_FAILED;
3538 }
3539
3540 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3541 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3542 bgp_initiate_graceful_shut_unshut(vty, bgp);
3543 }
3544
3545 return CMD_SUCCESS;
3546 }
3547
3548 /* "bgp fast-external-failover" configuration. */
3549 DEFUN (bgp_fast_external_failover,
3550 bgp_fast_external_failover_cmd,
3551 "bgp fast-external-failover",
3552 BGP_STR
3553 "Immediately reset session if a link to a directly connected external peer goes down\n")
3554 {
3555 VTY_DECLVAR_CONTEXT(bgp, bgp);
3556 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3557 return CMD_SUCCESS;
3558 }
3559
3560 DEFUN (no_bgp_fast_external_failover,
3561 no_bgp_fast_external_failover_cmd,
3562 "no bgp fast-external-failover",
3563 NO_STR
3564 BGP_STR
3565 "Immediately reset session if a link to a directly connected external peer goes down\n")
3566 {
3567 VTY_DECLVAR_CONTEXT(bgp, bgp);
3568 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3569 return CMD_SUCCESS;
3570 }
3571
3572 /* "bgp bestpath compare-routerid" configuration. */
3573 DEFUN (bgp_bestpath_compare_router_id,
3574 bgp_bestpath_compare_router_id_cmd,
3575 "bgp bestpath compare-routerid",
3576 BGP_STR
3577 "Change the default bestpath selection\n"
3578 "Compare router-id for identical EBGP paths\n")
3579 {
3580 VTY_DECLVAR_CONTEXT(bgp, bgp);
3581 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3582 bgp_recalculate_all_bestpaths(bgp);
3583
3584 return CMD_SUCCESS;
3585 }
3586
3587 DEFUN (no_bgp_bestpath_compare_router_id,
3588 no_bgp_bestpath_compare_router_id_cmd,
3589 "no bgp bestpath compare-routerid",
3590 NO_STR
3591 BGP_STR
3592 "Change the default bestpath selection\n"
3593 "Compare router-id for identical EBGP paths\n")
3594 {
3595 VTY_DECLVAR_CONTEXT(bgp, bgp);
3596 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3597 bgp_recalculate_all_bestpaths(bgp);
3598
3599 return CMD_SUCCESS;
3600 }
3601
3602 /* "bgp bestpath as-path ignore" configuration. */
3603 DEFUN (bgp_bestpath_aspath_ignore,
3604 bgp_bestpath_aspath_ignore_cmd,
3605 "bgp bestpath as-path ignore",
3606 BGP_STR
3607 "Change the default bestpath selection\n"
3608 "AS-path attribute\n"
3609 "Ignore as-path length in selecting a route\n")
3610 {
3611 VTY_DECLVAR_CONTEXT(bgp, bgp);
3612 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3613 bgp_recalculate_all_bestpaths(bgp);
3614
3615 return CMD_SUCCESS;
3616 }
3617
3618 DEFUN (no_bgp_bestpath_aspath_ignore,
3619 no_bgp_bestpath_aspath_ignore_cmd,
3620 "no bgp bestpath as-path ignore",
3621 NO_STR
3622 BGP_STR
3623 "Change the default bestpath selection\n"
3624 "AS-path attribute\n"
3625 "Ignore as-path length in selecting a route\n")
3626 {
3627 VTY_DECLVAR_CONTEXT(bgp, bgp);
3628 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3629 bgp_recalculate_all_bestpaths(bgp);
3630
3631 return CMD_SUCCESS;
3632 }
3633
3634 /* "bgp bestpath as-path confed" configuration. */
3635 DEFUN (bgp_bestpath_aspath_confed,
3636 bgp_bestpath_aspath_confed_cmd,
3637 "bgp bestpath as-path confed",
3638 BGP_STR
3639 "Change the default bestpath selection\n"
3640 "AS-path attribute\n"
3641 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3642 {
3643 VTY_DECLVAR_CONTEXT(bgp, bgp);
3644 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3645 bgp_recalculate_all_bestpaths(bgp);
3646
3647 return CMD_SUCCESS;
3648 }
3649
3650 DEFUN (no_bgp_bestpath_aspath_confed,
3651 no_bgp_bestpath_aspath_confed_cmd,
3652 "no bgp bestpath as-path confed",
3653 NO_STR
3654 BGP_STR
3655 "Change the default bestpath selection\n"
3656 "AS-path attribute\n"
3657 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3658 {
3659 VTY_DECLVAR_CONTEXT(bgp, bgp);
3660 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3661 bgp_recalculate_all_bestpaths(bgp);
3662
3663 return CMD_SUCCESS;
3664 }
3665
3666 /* "bgp bestpath as-path multipath-relax" configuration. */
3667 DEFUN (bgp_bestpath_aspath_multipath_relax,
3668 bgp_bestpath_aspath_multipath_relax_cmd,
3669 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3670 BGP_STR
3671 "Change the default bestpath selection\n"
3672 "AS-path attribute\n"
3673 "Allow load sharing across routes that have different AS paths (but same length)\n"
3674 "Generate an AS_SET\n"
3675 "Do not generate an AS_SET\n")
3676 {
3677 VTY_DECLVAR_CONTEXT(bgp, bgp);
3678 int idx = 0;
3679 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3680
3681 /* no-as-set is now the default behavior so we can silently
3682 * ignore it */
3683 if (argv_find(argv, argc, "as-set", &idx))
3684 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3685 else
3686 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3687
3688 bgp_recalculate_all_bestpaths(bgp);
3689
3690 return CMD_SUCCESS;
3691 }
3692
3693 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3694 no_bgp_bestpath_aspath_multipath_relax_cmd,
3695 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3696 NO_STR
3697 BGP_STR
3698 "Change the default bestpath selection\n"
3699 "AS-path attribute\n"
3700 "Allow load sharing across routes that have different AS paths (but same length)\n"
3701 "Generate an AS_SET\n"
3702 "Do not generate an AS_SET\n")
3703 {
3704 VTY_DECLVAR_CONTEXT(bgp, bgp);
3705 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3706 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3707 bgp_recalculate_all_bestpaths(bgp);
3708
3709 return CMD_SUCCESS;
3710 }
3711
3712 /* "bgp bestpath peer-type multipath-relax" configuration. */
3713 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3714 bgp_bestpath_peer_type_multipath_relax_cmd,
3715 "bgp bestpath peer-type multipath-relax",
3716 BGP_STR
3717 "Change the default bestpath selection\n"
3718 "Peer type\n"
3719 "Allow load sharing across routes learned from different peer types\n")
3720 {
3721 VTY_DECLVAR_CONTEXT(bgp, bgp);
3722 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3723 bgp_recalculate_all_bestpaths(bgp);
3724
3725 return CMD_SUCCESS;
3726 }
3727
3728 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3729 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3730 "no bgp bestpath peer-type multipath-relax",
3731 NO_STR BGP_STR
3732 "Change the default bestpath selection\n"
3733 "Peer type\n"
3734 "Allow load sharing across routes learned from different peer types\n")
3735 {
3736 VTY_DECLVAR_CONTEXT(bgp, bgp);
3737 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3738 bgp_recalculate_all_bestpaths(bgp);
3739
3740 return CMD_SUCCESS;
3741 }
3742
3743 /* "bgp log-neighbor-changes" configuration. */
3744 DEFUN (bgp_log_neighbor_changes,
3745 bgp_log_neighbor_changes_cmd,
3746 "bgp log-neighbor-changes",
3747 BGP_STR
3748 "Log neighbor up/down and reset reason\n")
3749 {
3750 VTY_DECLVAR_CONTEXT(bgp, bgp);
3751 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3752 return CMD_SUCCESS;
3753 }
3754
3755 DEFUN (no_bgp_log_neighbor_changes,
3756 no_bgp_log_neighbor_changes_cmd,
3757 "no bgp log-neighbor-changes",
3758 NO_STR
3759 BGP_STR
3760 "Log neighbor up/down and reset reason\n")
3761 {
3762 VTY_DECLVAR_CONTEXT(bgp, bgp);
3763 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3764 return CMD_SUCCESS;
3765 }
3766
3767 /* "bgp bestpath med" configuration. */
3768 DEFUN (bgp_bestpath_med,
3769 bgp_bestpath_med_cmd,
3770 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3771 BGP_STR
3772 "Change the default bestpath selection\n"
3773 "MED attribute\n"
3774 "Compare MED among confederation paths\n"
3775 "Treat missing MED as the least preferred one\n"
3776 "Treat missing MED as the least preferred one\n"
3777 "Compare MED among confederation paths\n")
3778 {
3779 VTY_DECLVAR_CONTEXT(bgp, bgp);
3780
3781 int idx = 0;
3782 if (argv_find(argv, argc, "confed", &idx))
3783 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3784 idx = 0;
3785 if (argv_find(argv, argc, "missing-as-worst", &idx))
3786 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3787
3788 bgp_recalculate_all_bestpaths(bgp);
3789
3790 return CMD_SUCCESS;
3791 }
3792
3793 DEFUN (no_bgp_bestpath_med,
3794 no_bgp_bestpath_med_cmd,
3795 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3796 NO_STR
3797 BGP_STR
3798 "Change the default bestpath selection\n"
3799 "MED attribute\n"
3800 "Compare MED among confederation paths\n"
3801 "Treat missing MED as the least preferred one\n"
3802 "Treat missing MED as the least preferred one\n"
3803 "Compare MED among confederation paths\n")
3804 {
3805 VTY_DECLVAR_CONTEXT(bgp, bgp);
3806
3807 int idx = 0;
3808 if (argv_find(argv, argc, "confed", &idx))
3809 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3810 idx = 0;
3811 if (argv_find(argv, argc, "missing-as-worst", &idx))
3812 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3813
3814 bgp_recalculate_all_bestpaths(bgp);
3815
3816 return CMD_SUCCESS;
3817 }
3818
3819 /* "bgp bestpath bandwidth" configuration. */
3820 DEFPY (bgp_bestpath_bw,
3821 bgp_bestpath_bw_cmd,
3822 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3823 BGP_STR
3824 "Change the default bestpath selection\n"
3825 "Link Bandwidth attribute\n"
3826 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3827 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3828 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3829 {
3830 VTY_DECLVAR_CONTEXT(bgp, bgp);
3831 afi_t afi;
3832 safi_t safi;
3833
3834 if (!bw_cfg) {
3835 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3836 return CMD_ERR_INCOMPLETE;
3837 }
3838 if (!strcmp(bw_cfg, "ignore"))
3839 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3840 else if (!strcmp(bw_cfg, "skip-missing"))
3841 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3842 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3843 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3844 else
3845 return CMD_ERR_NO_MATCH;
3846
3847 /* This config is used in route install, so redo that. */
3848 FOREACH_AFI_SAFI (afi, safi) {
3849 if (!bgp_fibupd_safi(safi))
3850 continue;
3851 bgp_zebra_announce_table(bgp, afi, safi);
3852 }
3853
3854 return CMD_SUCCESS;
3855 }
3856
3857 DEFPY (no_bgp_bestpath_bw,
3858 no_bgp_bestpath_bw_cmd,
3859 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3860 NO_STR
3861 BGP_STR
3862 "Change the default bestpath selection\n"
3863 "Link Bandwidth attribute\n"
3864 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3865 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3866 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3867 {
3868 VTY_DECLVAR_CONTEXT(bgp, bgp);
3869 afi_t afi;
3870 safi_t safi;
3871
3872 bgp->lb_handling = BGP_LINK_BW_ECMP;
3873
3874 /* This config is used in route install, so redo that. */
3875 FOREACH_AFI_SAFI (afi, safi) {
3876 if (!bgp_fibupd_safi(safi))
3877 continue;
3878 bgp_zebra_announce_table(bgp, afi, safi);
3879 }
3880 return CMD_SUCCESS;
3881 }
3882
3883 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3884 "[no] bgp default <ipv4-unicast|"
3885 "ipv4-multicast|"
3886 "ipv4-vpn|"
3887 "ipv4-labeled-unicast|"
3888 "ipv4-flowspec|"
3889 "ipv6-unicast|"
3890 "ipv6-multicast|"
3891 "ipv6-vpn|"
3892 "ipv6-labeled-unicast|"
3893 "ipv6-flowspec|"
3894 "l2vpn-evpn>$afi_safi",
3895 NO_STR
3896 BGP_STR
3897 "Configure BGP defaults\n"
3898 "Activate ipv4-unicast for a peer by default\n"
3899 "Activate ipv4-multicast for a peer by default\n"
3900 "Activate ipv4-vpn for a peer by default\n"
3901 "Activate ipv4-labeled-unicast for a peer by default\n"
3902 "Activate ipv4-flowspec for a peer by default\n"
3903 "Activate ipv6-unicast for a peer by default\n"
3904 "Activate ipv6-multicast for a peer by default\n"
3905 "Activate ipv6-vpn for a peer by default\n"
3906 "Activate ipv6-labeled-unicast for a peer by default\n"
3907 "Activate ipv6-flowspec for a peer by default\n"
3908 "Activate l2vpn-evpn for a peer by default\n")
3909 {
3910 VTY_DECLVAR_CONTEXT(bgp, bgp);
3911 char afi_safi_str[strlen(afi_safi) + 1];
3912 char *afi_safi_str_tok;
3913
3914 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3915 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3916 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3917 afi_t afi = bgp_vty_afi_from_str(afi_str);
3918 safi_t safi;
3919
3920 /*
3921 * Impossible situation but making coverity happy
3922 */
3923 assert(afi != AFI_MAX);
3924
3925 if (strmatch(safi_str, "labeled"))
3926 safi = bgp_vty_safi_from_str("labeled-unicast");
3927 else
3928 safi = bgp_vty_safi_from_str(safi_str);
3929
3930 assert(safi != SAFI_MAX);
3931 if (no)
3932 bgp->default_af[afi][safi] = false;
3933 else {
3934 if ((safi == SAFI_LABELED_UNICAST
3935 && bgp->default_af[afi][SAFI_UNICAST])
3936 || (safi == SAFI_UNICAST
3937 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3938 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3939 else
3940 bgp->default_af[afi][safi] = true;
3941 }
3942
3943 return CMD_SUCCESS;
3944 }
3945
3946 /* Display hostname in certain command outputs */
3947 DEFUN (bgp_default_show_hostname,
3948 bgp_default_show_hostname_cmd,
3949 "bgp default show-hostname",
3950 BGP_STR
3951 "Configure BGP defaults\n"
3952 "Show hostname in certain command outputs\n")
3953 {
3954 VTY_DECLVAR_CONTEXT(bgp, bgp);
3955 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3956 return CMD_SUCCESS;
3957 }
3958
3959 DEFUN (no_bgp_default_show_hostname,
3960 no_bgp_default_show_hostname_cmd,
3961 "no bgp default show-hostname",
3962 NO_STR
3963 BGP_STR
3964 "Configure BGP defaults\n"
3965 "Show hostname in certain command outputs\n")
3966 {
3967 VTY_DECLVAR_CONTEXT(bgp, bgp);
3968 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3969 return CMD_SUCCESS;
3970 }
3971
3972 /* Display hostname in certain command outputs */
3973 DEFUN (bgp_default_show_nexthop_hostname,
3974 bgp_default_show_nexthop_hostname_cmd,
3975 "bgp default show-nexthop-hostname",
3976 BGP_STR
3977 "Configure BGP defaults\n"
3978 "Show hostname for nexthop in certain command outputs\n")
3979 {
3980 VTY_DECLVAR_CONTEXT(bgp, bgp);
3981 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3982 return CMD_SUCCESS;
3983 }
3984
3985 DEFUN (no_bgp_default_show_nexthop_hostname,
3986 no_bgp_default_show_nexthop_hostname_cmd,
3987 "no bgp default show-nexthop-hostname",
3988 NO_STR
3989 BGP_STR
3990 "Configure BGP defaults\n"
3991 "Show hostname for nexthop in certain command outputs\n")
3992 {
3993 VTY_DECLVAR_CONTEXT(bgp, bgp);
3994 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3995 return CMD_SUCCESS;
3996 }
3997
3998 /* "bgp network import-check" configuration. */
3999 DEFUN (bgp_network_import_check,
4000 bgp_network_import_check_cmd,
4001 "bgp network import-check",
4002 BGP_STR
4003 "BGP network command\n"
4004 "Check BGP network route exists in IGP\n")
4005 {
4006 VTY_DECLVAR_CONTEXT(bgp, bgp);
4007 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4008 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4009 bgp_static_redo_import_check(bgp);
4010 }
4011
4012 return CMD_SUCCESS;
4013 }
4014
4015 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4016 "bgp network import-check exact",
4017 BGP_STR
4018 "BGP network command\n"
4019 "Check BGP network route exists in IGP\n"
4020 "Match route precisely\n")
4021
4022 DEFUN (no_bgp_network_import_check,
4023 no_bgp_network_import_check_cmd,
4024 "no bgp network import-check",
4025 NO_STR
4026 BGP_STR
4027 "BGP network command\n"
4028 "Check BGP network route exists in IGP\n")
4029 {
4030 VTY_DECLVAR_CONTEXT(bgp, bgp);
4031 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4032 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4033 bgp_static_redo_import_check(bgp);
4034 }
4035
4036 return CMD_SUCCESS;
4037 }
4038
4039 DEFUN (bgp_default_local_preference,
4040 bgp_default_local_preference_cmd,
4041 "bgp default local-preference (0-4294967295)",
4042 BGP_STR
4043 "Configure BGP defaults\n"
4044 "local preference (higher=more preferred)\n"
4045 "Configure default local preference value\n")
4046 {
4047 VTY_DECLVAR_CONTEXT(bgp, bgp);
4048 int idx_number = 3;
4049 uint32_t local_pref;
4050
4051 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4052
4053 bgp_default_local_preference_set(bgp, local_pref);
4054 bgp_clear_star_soft_in(vty, bgp->name);
4055
4056 return CMD_SUCCESS;
4057 }
4058
4059 DEFUN (no_bgp_default_local_preference,
4060 no_bgp_default_local_preference_cmd,
4061 "no bgp default local-preference [(0-4294967295)]",
4062 NO_STR
4063 BGP_STR
4064 "Configure BGP defaults\n"
4065 "local preference (higher=more preferred)\n"
4066 "Configure default local preference value\n")
4067 {
4068 VTY_DECLVAR_CONTEXT(bgp, bgp);
4069 bgp_default_local_preference_unset(bgp);
4070 bgp_clear_star_soft_in(vty, bgp->name);
4071
4072 return CMD_SUCCESS;
4073 }
4074
4075
4076 DEFUN (bgp_default_subgroup_pkt_queue_max,
4077 bgp_default_subgroup_pkt_queue_max_cmd,
4078 "bgp default subgroup-pkt-queue-max (20-100)",
4079 BGP_STR
4080 "Configure BGP defaults\n"
4081 "subgroup-pkt-queue-max\n"
4082 "Configure subgroup packet queue max\n")
4083 {
4084 VTY_DECLVAR_CONTEXT(bgp, bgp);
4085 int idx_number = 3;
4086 uint32_t max_size;
4087
4088 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4089
4090 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4091
4092 return CMD_SUCCESS;
4093 }
4094
4095 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4096 no_bgp_default_subgroup_pkt_queue_max_cmd,
4097 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4098 NO_STR
4099 BGP_STR
4100 "Configure BGP defaults\n"
4101 "subgroup-pkt-queue-max\n"
4102 "Configure subgroup packet queue max\n")
4103 {
4104 VTY_DECLVAR_CONTEXT(bgp, bgp);
4105 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4106 return CMD_SUCCESS;
4107 }
4108
4109
4110 DEFUN (bgp_rr_allow_outbound_policy,
4111 bgp_rr_allow_outbound_policy_cmd,
4112 "bgp route-reflector allow-outbound-policy",
4113 BGP_STR
4114 "Allow modifications made by out route-map\n"
4115 "on ibgp neighbors\n")
4116 {
4117 VTY_DECLVAR_CONTEXT(bgp, bgp);
4118
4119 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4120 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4121 update_group_announce_rrclients(bgp);
4122 bgp_clear_star_soft_out(vty, bgp->name);
4123 }
4124
4125 return CMD_SUCCESS;
4126 }
4127
4128 DEFUN (no_bgp_rr_allow_outbound_policy,
4129 no_bgp_rr_allow_outbound_policy_cmd,
4130 "no bgp route-reflector allow-outbound-policy",
4131 NO_STR
4132 BGP_STR
4133 "Allow modifications made by out route-map\n"
4134 "on ibgp neighbors\n")
4135 {
4136 VTY_DECLVAR_CONTEXT(bgp, bgp);
4137
4138 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4139 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4140 update_group_announce_rrclients(bgp);
4141 bgp_clear_star_soft_out(vty, bgp->name);
4142 }
4143
4144 return CMD_SUCCESS;
4145 }
4146
4147 DEFUN (bgp_listen_limit,
4148 bgp_listen_limit_cmd,
4149 "bgp listen limit (1-65535)",
4150 BGP_STR
4151 "BGP Dynamic Neighbors listen commands\n"
4152 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4153 "Configure Dynamic Neighbors listen limit value\n")
4154 {
4155 VTY_DECLVAR_CONTEXT(bgp, bgp);
4156 int idx_number = 3;
4157 int listen_limit;
4158
4159 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4160
4161 bgp_listen_limit_set(bgp, listen_limit);
4162
4163 return CMD_SUCCESS;
4164 }
4165
4166 DEFUN (no_bgp_listen_limit,
4167 no_bgp_listen_limit_cmd,
4168 "no bgp listen limit [(1-65535)]",
4169 NO_STR
4170 BGP_STR
4171 "BGP Dynamic Neighbors listen commands\n"
4172 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4173 "Configure Dynamic Neighbors listen limit value\n")
4174 {
4175 VTY_DECLVAR_CONTEXT(bgp, bgp);
4176 bgp_listen_limit_unset(bgp);
4177 return CMD_SUCCESS;
4178 }
4179
4180
4181 /*
4182 * Check if this listen range is already configured. Check for exact
4183 * match or overlap based on input.
4184 */
4185 static struct peer_group *listen_range_exists(struct bgp *bgp,
4186 struct prefix *range, int exact)
4187 {
4188 struct listnode *node, *nnode;
4189 struct listnode *node1, *nnode1;
4190 struct peer_group *group;
4191 struct prefix *lr;
4192 afi_t afi;
4193 int match;
4194
4195 afi = family2afi(range->family);
4196 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4197 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4198 lr)) {
4199 if (exact)
4200 match = prefix_same(range, lr);
4201 else
4202 match = (prefix_match(range, lr)
4203 || prefix_match(lr, range));
4204 if (match)
4205 return group;
4206 }
4207 }
4208
4209 return NULL;
4210 }
4211
4212 DEFUN (bgp_listen_range,
4213 bgp_listen_range_cmd,
4214 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4215 BGP_STR
4216 "Configure BGP dynamic neighbors listen range\n"
4217 "Configure BGP dynamic neighbors listen range\n"
4218 NEIGHBOR_ADDR_STR
4219 "Member of the peer-group\n"
4220 "Peer-group name\n")
4221 {
4222 VTY_DECLVAR_CONTEXT(bgp, bgp);
4223 struct prefix range;
4224 struct peer_group *group, *existing_group;
4225 afi_t afi;
4226 int ret;
4227 int idx = 0;
4228
4229 argv_find(argv, argc, "A.B.C.D/M", &idx);
4230 argv_find(argv, argc, "X:X::X:X/M", &idx);
4231 char *prefix = argv[idx]->arg;
4232 argv_find(argv, argc, "PGNAME", &idx);
4233 char *peergroup = argv[idx]->arg;
4234
4235 /* Convert IP prefix string to struct prefix. */
4236 ret = str2prefix(prefix, &range);
4237 if (!ret) {
4238 vty_out(vty, "%% Malformed listen range\n");
4239 return CMD_WARNING_CONFIG_FAILED;
4240 }
4241
4242 afi = family2afi(range.family);
4243
4244 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4245 vty_out(vty,
4246 "%% Malformed listen range (link-local address)\n");
4247 return CMD_WARNING_CONFIG_FAILED;
4248 }
4249
4250 apply_mask(&range);
4251
4252 /* Check if same listen range is already configured. */
4253 existing_group = listen_range_exists(bgp, &range, 1);
4254 if (existing_group) {
4255 if (strcmp(existing_group->name, peergroup) == 0)
4256 return CMD_SUCCESS;
4257 else {
4258 vty_out(vty,
4259 "%% Same listen range is attached to peer-group %s\n",
4260 existing_group->name);
4261 return CMD_WARNING_CONFIG_FAILED;
4262 }
4263 }
4264
4265 /* Check if an overlapping listen range exists. */
4266 if (listen_range_exists(bgp, &range, 0)) {
4267 vty_out(vty,
4268 "%% Listen range overlaps with existing listen range\n");
4269 return CMD_WARNING_CONFIG_FAILED;
4270 }
4271
4272 group = peer_group_lookup(bgp, peergroup);
4273 if (!group) {
4274 vty_out(vty, "%% Configure the peer-group first\n");
4275 return CMD_WARNING_CONFIG_FAILED;
4276 }
4277
4278 ret = peer_group_listen_range_add(group, &range);
4279 return bgp_vty_return(vty, ret);
4280 }
4281
4282 DEFUN (no_bgp_listen_range,
4283 no_bgp_listen_range_cmd,
4284 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4285 NO_STR
4286 BGP_STR
4287 "Unconfigure BGP dynamic neighbors listen range\n"
4288 "Unconfigure BGP dynamic neighbors listen range\n"
4289 NEIGHBOR_ADDR_STR
4290 "Member of the peer-group\n"
4291 "Peer-group name\n")
4292 {
4293 VTY_DECLVAR_CONTEXT(bgp, bgp);
4294 struct prefix range;
4295 struct peer_group *group;
4296 afi_t afi;
4297 int ret;
4298 int idx = 0;
4299
4300 argv_find(argv, argc, "A.B.C.D/M", &idx);
4301 argv_find(argv, argc, "X:X::X:X/M", &idx);
4302 char *prefix = argv[idx]->arg;
4303 argv_find(argv, argc, "PGNAME", &idx);
4304 char *peergroup = argv[idx]->arg;
4305
4306 /* Convert IP prefix string to struct prefix. */
4307 ret = str2prefix(prefix, &range);
4308 if (!ret) {
4309 vty_out(vty, "%% Malformed listen range\n");
4310 return CMD_WARNING_CONFIG_FAILED;
4311 }
4312
4313 afi = family2afi(range.family);
4314
4315 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4316 vty_out(vty,
4317 "%% Malformed listen range (link-local address)\n");
4318 return CMD_WARNING_CONFIG_FAILED;
4319 }
4320
4321 apply_mask(&range);
4322
4323 group = peer_group_lookup(bgp, peergroup);
4324 if (!group) {
4325 vty_out(vty, "%% Peer-group does not exist\n");
4326 return CMD_WARNING_CONFIG_FAILED;
4327 }
4328
4329 ret = peer_group_listen_range_del(group, &range);
4330 return bgp_vty_return(vty, ret);
4331 }
4332
4333 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4334 {
4335 struct peer_group *group;
4336 struct listnode *node, *nnode, *rnode, *nrnode;
4337 struct prefix *range;
4338 afi_t afi;
4339
4340 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4341 vty_out(vty, " bgp listen limit %d\n",
4342 bgp->dynamic_neighbors_limit);
4343
4344 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4345 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4346 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4347 nrnode, range)) {
4348 vty_out(vty,
4349 " bgp listen range %pFX peer-group %s\n",
4350 range, group->name);
4351 }
4352 }
4353 }
4354 }
4355
4356
4357 DEFUN (bgp_disable_connected_route_check,
4358 bgp_disable_connected_route_check_cmd,
4359 "bgp disable-ebgp-connected-route-check",
4360 BGP_STR
4361 "Disable checking if nexthop is connected on ebgp sessions\n")
4362 {
4363 VTY_DECLVAR_CONTEXT(bgp, bgp);
4364 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4365 bgp_clear_star_soft_in(vty, bgp->name);
4366
4367 return CMD_SUCCESS;
4368 }
4369
4370 DEFUN (no_bgp_disable_connected_route_check,
4371 no_bgp_disable_connected_route_check_cmd,
4372 "no bgp disable-ebgp-connected-route-check",
4373 NO_STR
4374 BGP_STR
4375 "Disable checking if nexthop is connected on ebgp sessions\n")
4376 {
4377 VTY_DECLVAR_CONTEXT(bgp, bgp);
4378 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4379 bgp_clear_star_soft_in(vty, bgp->name);
4380
4381 return CMD_SUCCESS;
4382 }
4383
4384
4385 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4386 const char *as_str)
4387 {
4388 VTY_DECLVAR_CONTEXT(bgp, bgp);
4389 int ret;
4390 as_t as;
4391 int as_type = AS_SPECIFIED;
4392 union sockunion su;
4393
4394 if (as_str[0] == 'i') {
4395 as = 0;
4396 as_type = AS_INTERNAL;
4397 } else if (as_str[0] == 'e') {
4398 as = 0;
4399 as_type = AS_EXTERNAL;
4400 } else {
4401 /* Get AS number. */
4402 as = strtoul(as_str, NULL, 10);
4403 }
4404
4405 /* If peer is peer group or interface peer, call proper function. */
4406 ret = str2sockunion(peer_str, &su);
4407 if (ret < 0) {
4408 struct peer *peer;
4409
4410 /* Check if existing interface peer */
4411 peer = peer_lookup_by_conf_if(bgp, peer_str);
4412
4413 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4414
4415 /* if not interface peer, check peer-group settings */
4416 if (ret < 0 && !peer) {
4417 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4418 if (ret < 0) {
4419 vty_out(vty,
4420 "%% Create the peer-group or interface first\n");
4421 return CMD_WARNING_CONFIG_FAILED;
4422 }
4423 return CMD_SUCCESS;
4424 }
4425 } else {
4426 if (peer_address_self_check(bgp, &su)) {
4427 vty_out(vty,
4428 "%% Can not configure the local system as neighbor\n");
4429 return CMD_WARNING_CONFIG_FAILED;
4430 }
4431 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4432 }
4433
4434 return bgp_vty_return(vty, ret);
4435 }
4436
4437 DEFUN (bgp_default_shutdown,
4438 bgp_default_shutdown_cmd,
4439 "[no] bgp default shutdown",
4440 NO_STR
4441 BGP_STR
4442 "Configure BGP defaults\n"
4443 "Apply administrative shutdown to newly configured peers\n")
4444 {
4445 VTY_DECLVAR_CONTEXT(bgp, bgp);
4446 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4447 return CMD_SUCCESS;
4448 }
4449
4450 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4451 BGP_STR
4452 "Administrative shutdown of the BGP instance\n"
4453 "Add a shutdown message (RFC 8203)\n"
4454 "Shutdown message\n")
4455 {
4456 char *msgstr = NULL;
4457
4458 VTY_DECLVAR_CONTEXT(bgp, bgp);
4459
4460 if (argc > 3)
4461 msgstr = argv_concat(argv, argc, 3);
4462
4463 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4464 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4465 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4466 return CMD_WARNING_CONFIG_FAILED;
4467 }
4468
4469 bgp_shutdown_enable(bgp, msgstr);
4470 XFREE(MTYPE_TMP, msgstr);
4471
4472 return CMD_SUCCESS;
4473 }
4474
4475 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4476 BGP_STR "Administrative shutdown of the BGP instance\n")
4477 {
4478 VTY_DECLVAR_CONTEXT(bgp, bgp);
4479
4480 bgp_shutdown_enable(bgp, NULL);
4481
4482 return CMD_SUCCESS;
4483 }
4484
4485 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4486 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4487 {
4488 VTY_DECLVAR_CONTEXT(bgp, bgp);
4489
4490 bgp_shutdown_disable(bgp);
4491
4492 return CMD_SUCCESS;
4493 }
4494
4495 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4496 "no bgp shutdown message MSG...", NO_STR BGP_STR
4497 "Administrative shutdown of the BGP instance\n"
4498 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4499
4500 DEFUN (neighbor_remote_as,
4501 neighbor_remote_as_cmd,
4502 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4503 NEIGHBOR_STR
4504 NEIGHBOR_ADDR_STR2
4505 "Specify a BGP neighbor\n"
4506 AS_STR
4507 "Internal BGP peer\n"
4508 "External BGP peer\n")
4509 {
4510 int idx_peer = 1;
4511 int idx_remote_as = 3;
4512 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4513 argv[idx_remote_as]->arg);
4514 }
4515
4516 DEFPY (bgp_allow_martian,
4517 bgp_allow_martian_cmd,
4518 "[no]$no bgp allow-martian-nexthop",
4519 NO_STR
4520 BGP_STR
4521 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4522 {
4523 VTY_DECLVAR_CONTEXT(bgp, bgp);
4524
4525 if (no)
4526 bgp->allow_martian = false;
4527 else
4528 bgp->allow_martian = true;
4529
4530 return CMD_SUCCESS;
4531 }
4532
4533 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4534 * sessions do not wait for hold timer expiry to bring down the sessions
4535 * when nexthop becomes unreachable
4536 */
4537 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4538 BGP_STR "Fast convergence for bgp sessions\n")
4539 {
4540 VTY_DECLVAR_CONTEXT(bgp, bgp);
4541 bgp->fast_convergence = true;
4542
4543 return CMD_SUCCESS;
4544 }
4545
4546 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4547 "no bgp fast-convergence",
4548 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4549 {
4550 VTY_DECLVAR_CONTEXT(bgp, bgp);
4551 bgp->fast_convergence = false;
4552
4553 return CMD_SUCCESS;
4554 }
4555
4556 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4557 int v6only,
4558 const char *peer_group_name,
4559 const char *as_str)
4560 {
4561 VTY_DECLVAR_CONTEXT(bgp, bgp);
4562 as_t as = 0;
4563 int as_type = AS_UNSPECIFIED;
4564 struct peer *peer;
4565 struct peer_group *group;
4566 int ret = 0;
4567
4568 group = peer_group_lookup(bgp, conf_if);
4569
4570 if (group) {
4571 vty_out(vty, "%% Name conflict with peer-group \n");
4572 return CMD_WARNING_CONFIG_FAILED;
4573 }
4574
4575 if (as_str) {
4576 if (as_str[0] == 'i') {
4577 as_type = AS_INTERNAL;
4578 } else if (as_str[0] == 'e') {
4579 as_type = AS_EXTERNAL;
4580 } else {
4581 /* Get AS number. */
4582 as = strtoul(as_str, NULL, 10);
4583 as_type = AS_SPECIFIED;
4584 }
4585 }
4586
4587 peer = peer_lookup_by_conf_if(bgp, conf_if);
4588 if (peer) {
4589 if (as_str)
4590 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4591 } else {
4592 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4593 NULL);
4594
4595 if (!peer) {
4596 vty_out(vty, "%% BGP failed to create peer\n");
4597 return CMD_WARNING_CONFIG_FAILED;
4598 }
4599
4600 if (v6only)
4601 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4602
4603 /* Request zebra to initiate IPv6 RAs on this interface. We do
4604 * this
4605 * any unnumbered peer in order to not worry about run-time
4606 * transitions
4607 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4608 * address
4609 * gets deleted later etc.)
4610 */
4611 if (peer->ifp)
4612 bgp_zebra_initiate_radv(bgp, peer);
4613 }
4614
4615 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4616 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4617 if (v6only)
4618 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4619 else
4620 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4621
4622 /* v6only flag changed. Reset bgp seesion */
4623 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4624 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4625 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4626 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4627 } else
4628 bgp_session_reset(peer);
4629 }
4630
4631 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4632 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4633 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4634 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4635 }
4636
4637 if (peer_group_name) {
4638 group = peer_group_lookup(bgp, peer_group_name);
4639 if (!group) {
4640 vty_out(vty, "%% Configure the peer-group first\n");
4641 return CMD_WARNING_CONFIG_FAILED;
4642 }
4643
4644 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4645 }
4646
4647 return bgp_vty_return(vty, ret);
4648 }
4649
4650 DEFUN (neighbor_interface_config,
4651 neighbor_interface_config_cmd,
4652 "neighbor WORD interface [peer-group PGNAME]",
4653 NEIGHBOR_STR
4654 "Interface name or neighbor tag\n"
4655 "Enable BGP on interface\n"
4656 "Member of the peer-group\n"
4657 "Peer-group name\n")
4658 {
4659 int idx_word = 1;
4660 int idx_peer_group_word = 4;
4661
4662 if (argc > idx_peer_group_word)
4663 return peer_conf_interface_get(
4664 vty, argv[idx_word]->arg, 0,
4665 argv[idx_peer_group_word]->arg, NULL);
4666 else
4667 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4668 NULL, NULL);
4669 }
4670
4671 DEFUN (neighbor_interface_config_v6only,
4672 neighbor_interface_config_v6only_cmd,
4673 "neighbor WORD interface v6only [peer-group PGNAME]",
4674 NEIGHBOR_STR
4675 "Interface name or neighbor tag\n"
4676 "Enable BGP on interface\n"
4677 "Enable BGP with v6 link-local only\n"
4678 "Member of the peer-group\n"
4679 "Peer-group name\n")
4680 {
4681 int idx_word = 1;
4682 int idx_peer_group_word = 5;
4683
4684 if (argc > idx_peer_group_word)
4685 return peer_conf_interface_get(
4686 vty, argv[idx_word]->arg, 1,
4687 argv[idx_peer_group_word]->arg, NULL);
4688
4689 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4690 }
4691
4692
4693 DEFUN (neighbor_interface_config_remote_as,
4694 neighbor_interface_config_remote_as_cmd,
4695 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4696 NEIGHBOR_STR
4697 "Interface name or neighbor tag\n"
4698 "Enable BGP on interface\n"
4699 "Specify a BGP neighbor\n"
4700 AS_STR
4701 "Internal BGP peer\n"
4702 "External BGP peer\n")
4703 {
4704 int idx_word = 1;
4705 int idx_remote_as = 4;
4706 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4707 argv[idx_remote_as]->arg);
4708 }
4709
4710 DEFUN (neighbor_interface_v6only_config_remote_as,
4711 neighbor_interface_v6only_config_remote_as_cmd,
4712 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4713 NEIGHBOR_STR
4714 "Interface name or neighbor tag\n"
4715 "Enable BGP with v6 link-local only\n"
4716 "Enable BGP on interface\n"
4717 "Specify a BGP neighbor\n"
4718 AS_STR
4719 "Internal BGP peer\n"
4720 "External BGP peer\n")
4721 {
4722 int idx_word = 1;
4723 int idx_remote_as = 5;
4724 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4725 argv[idx_remote_as]->arg);
4726 }
4727
4728 DEFUN (neighbor_peer_group,
4729 neighbor_peer_group_cmd,
4730 "neighbor WORD peer-group",
4731 NEIGHBOR_STR
4732 "Interface name or neighbor tag\n"
4733 "Configure peer-group\n")
4734 {
4735 VTY_DECLVAR_CONTEXT(bgp, bgp);
4736 int idx_word = 1;
4737 struct peer *peer;
4738 struct peer_group *group;
4739
4740 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4741 if (peer) {
4742 vty_out(vty, "%% Name conflict with interface: \n");
4743 return CMD_WARNING_CONFIG_FAILED;
4744 }
4745
4746 group = peer_group_get(bgp, argv[idx_word]->arg);
4747 if (!group) {
4748 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4749 return CMD_WARNING_CONFIG_FAILED;
4750 }
4751
4752 return CMD_SUCCESS;
4753 }
4754
4755 DEFUN (no_neighbor,
4756 no_neighbor_cmd,
4757 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4758 NO_STR
4759 NEIGHBOR_STR
4760 NEIGHBOR_ADDR_STR2
4761 "Specify a BGP neighbor\n"
4762 AS_STR
4763 "Internal BGP peer\n"
4764 "External BGP peer\n")
4765 {
4766 VTY_DECLVAR_CONTEXT(bgp, bgp);
4767 int idx_peer = 2;
4768 int ret;
4769 union sockunion su;
4770 struct peer_group *group;
4771 struct peer *peer;
4772 struct peer *other;
4773
4774 ret = str2sockunion(argv[idx_peer]->arg, &su);
4775 if (ret < 0) {
4776 /* look up for neighbor by interface name config. */
4777 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4778 if (peer) {
4779 /* Request zebra to terminate IPv6 RAs on this
4780 * interface. */
4781 if (peer->ifp)
4782 bgp_zebra_terminate_radv(peer->bgp, peer);
4783 peer_notify_unconfig(peer);
4784 peer_delete(peer);
4785 return CMD_SUCCESS;
4786 }
4787
4788 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4789 if (group) {
4790 peer_group_notify_unconfig(group);
4791 peer_group_delete(group);
4792 } else {
4793 vty_out(vty, "%% Create the peer-group first\n");
4794 return CMD_WARNING_CONFIG_FAILED;
4795 }
4796 } else {
4797 peer = peer_lookup(bgp, &su);
4798 if (peer) {
4799 if (peer_dynamic_neighbor(peer)) {
4800 vty_out(vty,
4801 "%% Operation not allowed on a dynamic neighbor\n");
4802 return CMD_WARNING_CONFIG_FAILED;
4803 }
4804
4805 other = peer->doppelganger;
4806
4807 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4808 bgp_zebra_terminate_radv(peer->bgp, peer);
4809
4810 peer_notify_unconfig(peer);
4811 peer_delete(peer);
4812 if (other && other->status != Deleted) {
4813 peer_notify_unconfig(other);
4814 peer_delete(other);
4815 }
4816 }
4817 }
4818
4819 return CMD_SUCCESS;
4820 }
4821
4822 DEFUN (no_neighbor_interface_config,
4823 no_neighbor_interface_config_cmd,
4824 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4825 NO_STR
4826 NEIGHBOR_STR
4827 "Interface name\n"
4828 "Configure BGP on interface\n"
4829 "Enable BGP with v6 link-local only\n"
4830 "Member of the peer-group\n"
4831 "Peer-group name\n"
4832 "Specify a BGP neighbor\n"
4833 AS_STR
4834 "Internal BGP peer\n"
4835 "External BGP peer\n")
4836 {
4837 VTY_DECLVAR_CONTEXT(bgp, bgp);
4838 int idx_word = 2;
4839 struct peer *peer;
4840
4841 /* look up for neighbor by interface name config. */
4842 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4843 if (peer) {
4844 /* Request zebra to terminate IPv6 RAs on this interface. */
4845 if (peer->ifp)
4846 bgp_zebra_terminate_radv(peer->bgp, peer);
4847 peer_notify_unconfig(peer);
4848 peer_delete(peer);
4849 } else {
4850 vty_out(vty, "%% Create the bgp interface first\n");
4851 return CMD_WARNING_CONFIG_FAILED;
4852 }
4853 return CMD_SUCCESS;
4854 }
4855
4856 DEFUN (no_neighbor_peer_group,
4857 no_neighbor_peer_group_cmd,
4858 "no neighbor WORD peer-group",
4859 NO_STR
4860 NEIGHBOR_STR
4861 "Neighbor tag\n"
4862 "Configure peer-group\n")
4863 {
4864 VTY_DECLVAR_CONTEXT(bgp, bgp);
4865 int idx_word = 2;
4866 struct peer_group *group;
4867
4868 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4869 if (group) {
4870 peer_group_notify_unconfig(group);
4871 peer_group_delete(group);
4872 } else {
4873 vty_out(vty, "%% Create the peer-group first\n");
4874 return CMD_WARNING_CONFIG_FAILED;
4875 }
4876 return CMD_SUCCESS;
4877 }
4878
4879 DEFUN (no_neighbor_interface_peer_group_remote_as,
4880 no_neighbor_interface_peer_group_remote_as_cmd,
4881 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4882 NO_STR
4883 NEIGHBOR_STR
4884 "Interface name or neighbor tag\n"
4885 "Specify a BGP neighbor\n"
4886 AS_STR
4887 "Internal BGP peer\n"
4888 "External BGP peer\n")
4889 {
4890 VTY_DECLVAR_CONTEXT(bgp, bgp);
4891 int idx_word = 2;
4892 struct peer_group *group;
4893 struct peer *peer;
4894
4895 /* look up for neighbor by interface name config. */
4896 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4897 if (peer) {
4898 peer_as_change(peer, 0, AS_UNSPECIFIED);
4899 return CMD_SUCCESS;
4900 }
4901
4902 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4903 if (group)
4904 peer_group_remote_as_delete(group);
4905 else {
4906 vty_out(vty, "%% Create the peer-group or interface first\n");
4907 return CMD_WARNING_CONFIG_FAILED;
4908 }
4909 return CMD_SUCCESS;
4910 }
4911
4912 DEFUN (neighbor_local_as,
4913 neighbor_local_as_cmd,
4914 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4915 NEIGHBOR_STR
4916 NEIGHBOR_ADDR_STR2
4917 "Specify a local-as number\n"
4918 "AS number used as local AS\n")
4919 {
4920 int idx_peer = 1;
4921 int idx_number = 3;
4922 struct peer *peer;
4923 int ret;
4924 as_t as;
4925
4926 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4927 if (!peer)
4928 return CMD_WARNING_CONFIG_FAILED;
4929
4930 as = strtoul(argv[idx_number]->arg, NULL, 10);
4931 ret = peer_local_as_set(peer, as, 0, 0);
4932 return bgp_vty_return(vty, ret);
4933 }
4934
4935 DEFUN (neighbor_local_as_no_prepend,
4936 neighbor_local_as_no_prepend_cmd,
4937 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
4940 "Specify a local-as number\n"
4941 "AS number used as local AS\n"
4942 "Do not prepend local-as to updates from ebgp peers\n")
4943 {
4944 int idx_peer = 1;
4945 int idx_number = 3;
4946 struct peer *peer;
4947 int ret;
4948 as_t as;
4949
4950 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4951 if (!peer)
4952 return CMD_WARNING_CONFIG_FAILED;
4953
4954 as = strtoul(argv[idx_number]->arg, NULL, 10);
4955 ret = peer_local_as_set(peer, as, 1, 0);
4956 return bgp_vty_return(vty, ret);
4957 }
4958
4959 DEFUN (neighbor_local_as_no_prepend_replace_as,
4960 neighbor_local_as_no_prepend_replace_as_cmd,
4961 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4962 NEIGHBOR_STR
4963 NEIGHBOR_ADDR_STR2
4964 "Specify a local-as number\n"
4965 "AS number used as local AS\n"
4966 "Do not prepend local-as to updates from ebgp peers\n"
4967 "Do not prepend local-as to updates from ibgp peers\n")
4968 {
4969 int idx_peer = 1;
4970 int idx_number = 3;
4971 struct peer *peer;
4972 int ret;
4973 as_t as;
4974
4975 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4976 if (!peer)
4977 return CMD_WARNING_CONFIG_FAILED;
4978
4979 as = strtoul(argv[idx_number]->arg, NULL, 10);
4980 ret = peer_local_as_set(peer, as, 1, 1);
4981 return bgp_vty_return(vty, ret);
4982 }
4983
4984 DEFUN (no_neighbor_local_as,
4985 no_neighbor_local_as_cmd,
4986 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4987 NO_STR
4988 NEIGHBOR_STR
4989 NEIGHBOR_ADDR_STR2
4990 "Specify a local-as number\n"
4991 "AS number used as local AS\n"
4992 "Do not prepend local-as to updates from ebgp peers\n"
4993 "Do not prepend local-as to updates from ibgp peers\n")
4994 {
4995 int idx_peer = 2;
4996 struct peer *peer;
4997 int ret;
4998
4999 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5000 if (!peer)
5001 return CMD_WARNING_CONFIG_FAILED;
5002
5003 ret = peer_local_as_unset(peer);
5004 return bgp_vty_return(vty, ret);
5005 }
5006
5007
5008 DEFUN (neighbor_solo,
5009 neighbor_solo_cmd,
5010 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5011 NEIGHBOR_STR
5012 NEIGHBOR_ADDR_STR2
5013 "Solo peer - part of its own update group\n")
5014 {
5015 int idx_peer = 1;
5016 struct peer *peer;
5017 int ret;
5018
5019 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5020 if (!peer)
5021 return CMD_WARNING_CONFIG_FAILED;
5022
5023 ret = update_group_adjust_soloness(peer, 1);
5024 return bgp_vty_return(vty, ret);
5025 }
5026
5027 DEFUN (no_neighbor_solo,
5028 no_neighbor_solo_cmd,
5029 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5030 NO_STR
5031 NEIGHBOR_STR
5032 NEIGHBOR_ADDR_STR2
5033 "Solo peer - part of its own update group\n")
5034 {
5035 int idx_peer = 2;
5036 struct peer *peer;
5037 int ret;
5038
5039 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5040 if (!peer)
5041 return CMD_WARNING_CONFIG_FAILED;
5042
5043 ret = update_group_adjust_soloness(peer, 0);
5044 return bgp_vty_return(vty, ret);
5045 }
5046
5047 DEFUN (neighbor_password,
5048 neighbor_password_cmd,
5049 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5050 NEIGHBOR_STR
5051 NEIGHBOR_ADDR_STR2
5052 "Set a password\n"
5053 "The password\n")
5054 {
5055 int idx_peer = 1;
5056 int idx_line = 3;
5057 struct peer *peer;
5058 int ret;
5059
5060 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5061 if (!peer)
5062 return CMD_WARNING_CONFIG_FAILED;
5063
5064 ret = peer_password_set(peer, argv[idx_line]->arg);
5065 return bgp_vty_return(vty, ret);
5066 }
5067
5068 DEFUN (no_neighbor_password,
5069 no_neighbor_password_cmd,
5070 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5071 NO_STR
5072 NEIGHBOR_STR
5073 NEIGHBOR_ADDR_STR2
5074 "Set a password\n"
5075 "The password\n")
5076 {
5077 int idx_peer = 2;
5078 struct peer *peer;
5079 int ret;
5080
5081 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5082 if (!peer)
5083 return CMD_WARNING_CONFIG_FAILED;
5084
5085 ret = peer_password_unset(peer);
5086 return bgp_vty_return(vty, ret);
5087 }
5088
5089 DEFUN (neighbor_activate,
5090 neighbor_activate_cmd,
5091 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5092 NEIGHBOR_STR
5093 NEIGHBOR_ADDR_STR2
5094 "Enable the Address Family for this Neighbor\n")
5095 {
5096 int idx_peer = 1;
5097 int ret;
5098 struct peer *peer;
5099
5100 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5101 if (!peer)
5102 return CMD_WARNING_CONFIG_FAILED;
5103
5104 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5105 return bgp_vty_return(vty, ret);
5106 }
5107
5108 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5109 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5110 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5111 "Enable the Address Family for this Neighbor\n")
5112
5113 DEFUN (no_neighbor_activate,
5114 no_neighbor_activate_cmd,
5115 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5116 NO_STR
5117 NEIGHBOR_STR
5118 NEIGHBOR_ADDR_STR2
5119 "Enable the Address Family for this Neighbor\n")
5120 {
5121 int idx_peer = 2;
5122 int ret;
5123 struct peer *peer;
5124
5125 /* Lookup peer. */
5126 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5127 if (!peer)
5128 return CMD_WARNING_CONFIG_FAILED;
5129
5130 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5131 return bgp_vty_return(vty, ret);
5132 }
5133
5134 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5135 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5136 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5137 "Enable the Address Family for this Neighbor\n")
5138
5139 DEFUN (neighbor_set_peer_group,
5140 neighbor_set_peer_group_cmd,
5141 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5142 NEIGHBOR_STR
5143 NEIGHBOR_ADDR_STR2
5144 "Member of the peer-group\n"
5145 "Peer-group name\n")
5146 {
5147 VTY_DECLVAR_CONTEXT(bgp, bgp);
5148 int idx_peer = 1;
5149 int idx_word = 3;
5150 int ret;
5151 as_t as;
5152 union sockunion su;
5153 struct peer *peer;
5154 struct peer_group *group;
5155
5156 ret = str2sockunion(argv[idx_peer]->arg, &su);
5157 if (ret < 0) {
5158 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5159 if (!peer) {
5160 vty_out(vty, "%% Malformed address or name: %s\n",
5161 argv[idx_peer]->arg);
5162 return CMD_WARNING_CONFIG_FAILED;
5163 }
5164 } else {
5165 if (peer_address_self_check(bgp, &su)) {
5166 vty_out(vty,
5167 "%% Can not configure the local system as neighbor\n");
5168 return CMD_WARNING_CONFIG_FAILED;
5169 }
5170
5171 /* Disallow for dynamic neighbor. */
5172 peer = peer_lookup(bgp, &su);
5173 if (peer && peer_dynamic_neighbor(peer)) {
5174 vty_out(vty,
5175 "%% Operation not allowed on a dynamic neighbor\n");
5176 return CMD_WARNING_CONFIG_FAILED;
5177 }
5178 }
5179
5180 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5181 if (!group) {
5182 vty_out(vty, "%% Configure the peer-group first\n");
5183 return CMD_WARNING_CONFIG_FAILED;
5184 }
5185
5186 ret = peer_group_bind(bgp, &su, peer, group, &as);
5187
5188 return bgp_vty_return(vty, ret);
5189 }
5190
5191 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5192 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5193 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5194 "Member of the peer-group\n"
5195 "Peer-group name\n")
5196
5197 DEFUN (no_neighbor_set_peer_group,
5198 no_neighbor_set_peer_group_cmd,
5199 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5200 NO_STR
5201 NEIGHBOR_STR
5202 NEIGHBOR_ADDR_STR2
5203 "Member of the peer-group\n"
5204 "Peer-group name\n")
5205 {
5206 VTY_DECLVAR_CONTEXT(bgp, bgp);
5207 int idx_peer = 2;
5208 int idx_word = 4;
5209 int ret;
5210 struct peer *peer;
5211 struct peer_group *group;
5212
5213 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5214 if (!peer)
5215 return CMD_WARNING_CONFIG_FAILED;
5216
5217 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5218 if (!group) {
5219 vty_out(vty, "%% Configure the peer-group first\n");
5220 return CMD_WARNING_CONFIG_FAILED;
5221 }
5222
5223 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5224 bgp_zebra_terminate_radv(peer->bgp, peer);
5225
5226 peer_notify_unconfig(peer);
5227 ret = peer_delete(peer);
5228
5229 return bgp_vty_return(vty, ret);
5230 }
5231
5232 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5233 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5234 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5235 "Member of the peer-group\n"
5236 "Peer-group name\n")
5237
5238 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5239 uint64_t flag, int set)
5240 {
5241 int ret;
5242 struct peer *peer;
5243
5244 peer = peer_and_group_lookup_vty(vty, ip_str);
5245 if (!peer)
5246 return CMD_WARNING_CONFIG_FAILED;
5247
5248 /*
5249 * If 'neighbor <interface>', then this is for directly connected peers,
5250 * we should not accept disable-connected-check.
5251 */
5252 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5253 vty_out(vty,
5254 "%s is directly connected peer, cannot accept disable-connected-check\n",
5255 ip_str);
5256 return CMD_WARNING_CONFIG_FAILED;
5257 }
5258
5259 if (!set && flag == PEER_FLAG_SHUTDOWN)
5260 peer_tx_shutdown_message_unset(peer);
5261
5262 if (set)
5263 ret = peer_flag_set(peer, flag);
5264 else
5265 ret = peer_flag_unset(peer, flag);
5266
5267 return bgp_vty_return(vty, ret);
5268 }
5269
5270 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5271 {
5272 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5273 }
5274
5275 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5276 uint64_t flag)
5277 {
5278 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5279 }
5280
5281 /* neighbor passive. */
5282 DEFUN (neighbor_passive,
5283 neighbor_passive_cmd,
5284 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5285 NEIGHBOR_STR
5286 NEIGHBOR_ADDR_STR2
5287 "Don't send open messages to this neighbor\n")
5288 {
5289 int idx_peer = 1;
5290 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5291 }
5292
5293 DEFUN (no_neighbor_passive,
5294 no_neighbor_passive_cmd,
5295 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5296 NO_STR
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Don't send open messages to this neighbor\n")
5300 {
5301 int idx_peer = 2;
5302 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5303 }
5304
5305 /* neighbor shutdown. */
5306 DEFUN (neighbor_shutdown_msg,
5307 neighbor_shutdown_msg_cmd,
5308 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5309 NEIGHBOR_STR
5310 NEIGHBOR_ADDR_STR2
5311 "Administratively shut down this neighbor\n"
5312 "Add a shutdown message (RFC 8203)\n"
5313 "Shutdown message\n")
5314 {
5315 int idx_peer = 1;
5316
5317 if (argc >= 5) {
5318 struct peer *peer =
5319 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5320 char *message;
5321
5322 if (!peer)
5323 return CMD_WARNING_CONFIG_FAILED;
5324 message = argv_concat(argv, argc, 4);
5325 peer_tx_shutdown_message_set(peer, message);
5326 XFREE(MTYPE_TMP, message);
5327 }
5328
5329 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5330 }
5331
5332 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5333 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5334 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5335 "Administratively shut down this neighbor\n")
5336
5337 DEFUN (no_neighbor_shutdown_msg,
5338 no_neighbor_shutdown_msg_cmd,
5339 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5340 NO_STR
5341 NEIGHBOR_STR
5342 NEIGHBOR_ADDR_STR2
5343 "Administratively shut down this neighbor\n"
5344 "Remove a shutdown message (RFC 8203)\n"
5345 "Shutdown message\n")
5346 {
5347 int idx_peer = 2;
5348
5349 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5350 PEER_FLAG_SHUTDOWN);
5351 }
5352
5353 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5354 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5355 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5356 "Administratively shut down this neighbor\n")
5357
5358 DEFUN(neighbor_shutdown_rtt,
5359 neighbor_shutdown_rtt_cmd,
5360 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5361 NEIGHBOR_STR
5362 NEIGHBOR_ADDR_STR2
5363 "Administratively shut down this neighbor\n"
5364 "Shutdown if round-trip-time is higher than expected\n"
5365 "Round-trip-time in milliseconds\n"
5366 "Specify the number of keepalives before shutdown\n"
5367 "The number of keepalives with higher RTT to shutdown\n")
5368 {
5369 int idx_peer = 1;
5370 int idx_rtt = 4;
5371 int idx_count = 0;
5372 struct peer *peer;
5373
5374 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5375
5376 if (!peer)
5377 return CMD_WARNING_CONFIG_FAILED;
5378
5379 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5380
5381 if (argv_find(argv, argc, "count", &idx_count))
5382 peer->rtt_keepalive_conf =
5383 strtol(argv[idx_count + 1]->arg, NULL, 10);
5384
5385 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5386 PEER_FLAG_RTT_SHUTDOWN);
5387 }
5388
5389 DEFUN(no_neighbor_shutdown_rtt,
5390 no_neighbor_shutdown_rtt_cmd,
5391 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5392 NO_STR
5393 NEIGHBOR_STR
5394 NEIGHBOR_ADDR_STR2
5395 "Administratively shut down this neighbor\n"
5396 "Shutdown if round-trip-time is higher than expected\n"
5397 "Round-trip-time in milliseconds\n"
5398 "Specify the number of keepalives before shutdown\n"
5399 "The number of keepalives with higher RTT to shutdown\n")
5400 {
5401 int idx_peer = 2;
5402 struct peer *peer;
5403
5404 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5405
5406 if (!peer)
5407 return CMD_WARNING_CONFIG_FAILED;
5408
5409 peer->rtt_expected = 0;
5410 peer->rtt_keepalive_conf = 1;
5411
5412 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5413 PEER_FLAG_RTT_SHUTDOWN);
5414 }
5415
5416 /* neighbor capability dynamic. */
5417 DEFUN (neighbor_capability_dynamic,
5418 neighbor_capability_dynamic_cmd,
5419 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
5422 "Advertise capability to the peer\n"
5423 "Advertise dynamic capability to this neighbor\n")
5424 {
5425 int idx_peer = 1;
5426 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5427 PEER_FLAG_DYNAMIC_CAPABILITY);
5428 }
5429
5430 DEFUN (no_neighbor_capability_dynamic,
5431 no_neighbor_capability_dynamic_cmd,
5432 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5433 NO_STR
5434 NEIGHBOR_STR
5435 NEIGHBOR_ADDR_STR2
5436 "Advertise capability to the peer\n"
5437 "Advertise dynamic capability to this neighbor\n")
5438 {
5439 int idx_peer = 2;
5440 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5441 PEER_FLAG_DYNAMIC_CAPABILITY);
5442 }
5443
5444 /* neighbor dont-capability-negotiate */
5445 DEFUN (neighbor_dont_capability_negotiate,
5446 neighbor_dont_capability_negotiate_cmd,
5447 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5448 NEIGHBOR_STR
5449 NEIGHBOR_ADDR_STR2
5450 "Do not perform capability negotiation\n")
5451 {
5452 int idx_peer = 1;
5453 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5454 PEER_FLAG_DONT_CAPABILITY);
5455 }
5456
5457 DEFUN (no_neighbor_dont_capability_negotiate,
5458 no_neighbor_dont_capability_negotiate_cmd,
5459 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5460 NO_STR
5461 NEIGHBOR_STR
5462 NEIGHBOR_ADDR_STR2
5463 "Do not perform capability negotiation\n")
5464 {
5465 int idx_peer = 2;
5466 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5467 PEER_FLAG_DONT_CAPABILITY);
5468 }
5469
5470 /* neighbor capability extended next hop encoding */
5471 DEFUN (neighbor_capability_enhe,
5472 neighbor_capability_enhe_cmd,
5473 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5474 NEIGHBOR_STR
5475 NEIGHBOR_ADDR_STR2
5476 "Advertise capability to the peer\n"
5477 "Advertise extended next-hop capability to the peer\n")
5478 {
5479 int idx_peer = 1;
5480 struct peer *peer;
5481
5482 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5483 if (peer && peer->conf_if)
5484 return CMD_SUCCESS;
5485
5486 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5487 PEER_FLAG_CAPABILITY_ENHE);
5488 }
5489
5490 DEFUN (no_neighbor_capability_enhe,
5491 no_neighbor_capability_enhe_cmd,
5492 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5493 NO_STR
5494 NEIGHBOR_STR
5495 NEIGHBOR_ADDR_STR2
5496 "Advertise capability to the peer\n"
5497 "Advertise extended next-hop capability to the peer\n")
5498 {
5499 int idx_peer = 2;
5500 struct peer *peer;
5501
5502 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5503 if (peer && peer->conf_if) {
5504 vty_out(vty,
5505 "Peer %s cannot have capability extended-nexthop turned off\n",
5506 argv[idx_peer]->arg);
5507 return CMD_WARNING_CONFIG_FAILED;
5508 }
5509
5510 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5511 PEER_FLAG_CAPABILITY_ENHE);
5512 }
5513
5514 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5515 afi_t afi, safi_t safi, uint32_t flag,
5516 int set)
5517 {
5518 int ret;
5519 struct peer *peer;
5520
5521 peer = peer_and_group_lookup_vty(vty, peer_str);
5522 if (!peer)
5523 return CMD_WARNING_CONFIG_FAILED;
5524
5525 if (set)
5526 ret = peer_af_flag_set(peer, afi, safi, flag);
5527 else
5528 ret = peer_af_flag_unset(peer, afi, safi, flag);
5529
5530 return bgp_vty_return(vty, ret);
5531 }
5532
5533 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5534 afi_t afi, safi_t safi, uint32_t flag)
5535 {
5536 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5537 }
5538
5539 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5540 afi_t afi, safi_t safi, uint32_t flag)
5541 {
5542 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5543 }
5544
5545 /* neighbor capability orf prefix-list. */
5546 DEFUN (neighbor_capability_orf_prefix,
5547 neighbor_capability_orf_prefix_cmd,
5548 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5549 NEIGHBOR_STR
5550 NEIGHBOR_ADDR_STR2
5551 "Advertise capability to the peer\n"
5552 "Advertise ORF capability to the peer\n"
5553 "Advertise prefixlist ORF capability to this neighbor\n"
5554 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5555 "Capability to RECEIVE the ORF from this neighbor\n"
5556 "Capability to SEND the ORF to this neighbor\n")
5557 {
5558 int idx_send_recv = 5;
5559 char *peer_str = argv[1]->arg;
5560 struct peer *peer;
5561 afi_t afi = bgp_node_afi(vty);
5562 safi_t safi = bgp_node_safi(vty);
5563
5564 peer = peer_and_group_lookup_vty(vty, peer_str);
5565 if (!peer)
5566 return CMD_WARNING_CONFIG_FAILED;
5567
5568 if (strmatch(argv[idx_send_recv]->text, "send"))
5569 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5570 PEER_FLAG_ORF_PREFIX_SM);
5571
5572 if (strmatch(argv[idx_send_recv]->text, "receive"))
5573 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5574 PEER_FLAG_ORF_PREFIX_RM);
5575
5576 if (strmatch(argv[idx_send_recv]->text, "both"))
5577 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5578 PEER_FLAG_ORF_PREFIX_SM)
5579 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5580 PEER_FLAG_ORF_PREFIX_RM);
5581
5582 return CMD_WARNING_CONFIG_FAILED;
5583 }
5584
5585 ALIAS_HIDDEN(
5586 neighbor_capability_orf_prefix,
5587 neighbor_capability_orf_prefix_hidden_cmd,
5588 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5589 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5590 "Advertise capability to the peer\n"
5591 "Advertise ORF capability to the peer\n"
5592 "Advertise prefixlist ORF capability to this neighbor\n"
5593 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5594 "Capability to RECEIVE the ORF from this neighbor\n"
5595 "Capability to SEND the ORF to this neighbor\n")
5596
5597 DEFUN (no_neighbor_capability_orf_prefix,
5598 no_neighbor_capability_orf_prefix_cmd,
5599 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5600 NO_STR
5601 NEIGHBOR_STR
5602 NEIGHBOR_ADDR_STR2
5603 "Advertise capability to the peer\n"
5604 "Advertise ORF capability to the peer\n"
5605 "Advertise prefixlist ORF capability to this neighbor\n"
5606 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5607 "Capability to RECEIVE the ORF from this neighbor\n"
5608 "Capability to SEND the ORF to this neighbor\n")
5609 {
5610 int idx_send_recv = 6;
5611 char *peer_str = argv[2]->arg;
5612 struct peer *peer;
5613 afi_t afi = bgp_node_afi(vty);
5614 safi_t safi = bgp_node_safi(vty);
5615
5616 peer = peer_and_group_lookup_vty(vty, peer_str);
5617 if (!peer)
5618 return CMD_WARNING_CONFIG_FAILED;
5619
5620 if (strmatch(argv[idx_send_recv]->text, "send"))
5621 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5622 PEER_FLAG_ORF_PREFIX_SM);
5623
5624 if (strmatch(argv[idx_send_recv]->text, "receive"))
5625 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5626 PEER_FLAG_ORF_PREFIX_RM);
5627
5628 if (strmatch(argv[idx_send_recv]->text, "both"))
5629 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5630 PEER_FLAG_ORF_PREFIX_SM)
5631 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5632 PEER_FLAG_ORF_PREFIX_RM);
5633
5634 return CMD_WARNING_CONFIG_FAILED;
5635 }
5636
5637 ALIAS_HIDDEN(
5638 no_neighbor_capability_orf_prefix,
5639 no_neighbor_capability_orf_prefix_hidden_cmd,
5640 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5641 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Advertise capability to the peer\n"
5643 "Advertise ORF capability to the peer\n"
5644 "Advertise prefixlist ORF capability to this neighbor\n"
5645 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5646 "Capability to RECEIVE the ORF from this neighbor\n"
5647 "Capability to SEND the ORF to this neighbor\n")
5648
5649 /* neighbor next-hop-self. */
5650 DEFUN (neighbor_nexthop_self,
5651 neighbor_nexthop_self_cmd,
5652 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5653 NEIGHBOR_STR
5654 NEIGHBOR_ADDR_STR2
5655 "Disable the next hop calculation for this neighbor\n")
5656 {
5657 int idx_peer = 1;
5658 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5659 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5660 }
5661
5662 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5663 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5664 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5665 "Disable the next hop calculation for this neighbor\n")
5666
5667 /* neighbor next-hop-self. */
5668 DEFUN (neighbor_nexthop_self_force,
5669 neighbor_nexthop_self_force_cmd,
5670 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5671 NEIGHBOR_STR
5672 NEIGHBOR_ADDR_STR2
5673 "Disable the next hop calculation for this neighbor\n"
5674 "Set the next hop to self for reflected routes\n")
5675 {
5676 int idx_peer = 1;
5677 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5678 bgp_node_safi(vty),
5679 PEER_FLAG_FORCE_NEXTHOP_SELF);
5680 }
5681
5682 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5683 neighbor_nexthop_self_force_hidden_cmd,
5684 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5685 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5686 "Disable the next hop calculation for this neighbor\n"
5687 "Set the next hop to self for reflected routes\n")
5688
5689 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5690 neighbor_nexthop_self_all_hidden_cmd,
5691 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5692 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5693 "Disable the next hop calculation for this neighbor\n"
5694 "Set the next hop to self for reflected routes\n")
5695
5696 DEFUN (no_neighbor_nexthop_self,
5697 no_neighbor_nexthop_self_cmd,
5698 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5699 NO_STR
5700 NEIGHBOR_STR
5701 NEIGHBOR_ADDR_STR2
5702 "Disable the next hop calculation for this neighbor\n")
5703 {
5704 int idx_peer = 2;
5705 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5706 bgp_node_afi(vty), bgp_node_safi(vty),
5707 PEER_FLAG_NEXTHOP_SELF);
5708 }
5709
5710 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5711 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5712 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5713 "Disable the next hop calculation for this neighbor\n")
5714
5715 DEFUN (no_neighbor_nexthop_self_force,
5716 no_neighbor_nexthop_self_force_cmd,
5717 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5718 NO_STR
5719 NEIGHBOR_STR
5720 NEIGHBOR_ADDR_STR2
5721 "Disable the next hop calculation for this neighbor\n"
5722 "Set the next hop to self for reflected routes\n")
5723 {
5724 int idx_peer = 2;
5725 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5726 bgp_node_afi(vty), bgp_node_safi(vty),
5727 PEER_FLAG_FORCE_NEXTHOP_SELF);
5728 }
5729
5730 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5731 no_neighbor_nexthop_self_force_hidden_cmd,
5732 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5733 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5734 "Disable the next hop calculation for this neighbor\n"
5735 "Set the next hop to self for reflected routes\n")
5736
5737 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5738 no_neighbor_nexthop_self_all_hidden_cmd,
5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5741 "Disable the next hop calculation for this neighbor\n"
5742 "Set the next hop to self for reflected routes\n")
5743
5744 /* neighbor as-override */
5745 DEFUN (neighbor_as_override,
5746 neighbor_as_override_cmd,
5747 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5748 NEIGHBOR_STR
5749 NEIGHBOR_ADDR_STR2
5750 "Override ASNs in outbound updates if aspath equals remote-as\n")
5751 {
5752 int idx_peer = 1;
5753 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5754 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5755 }
5756
5757 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5758 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5759 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5760 "Override ASNs in outbound updates if aspath equals remote-as\n")
5761
5762 DEFUN (no_neighbor_as_override,
5763 no_neighbor_as_override_cmd,
5764 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5765 NO_STR
5766 NEIGHBOR_STR
5767 NEIGHBOR_ADDR_STR2
5768 "Override ASNs in outbound updates if aspath equals remote-as\n")
5769 {
5770 int idx_peer = 2;
5771 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5772 bgp_node_afi(vty), bgp_node_safi(vty),
5773 PEER_FLAG_AS_OVERRIDE);
5774 }
5775
5776 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5777 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5778 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5779 "Override ASNs in outbound updates if aspath equals remote-as\n")
5780
5781 /* neighbor remove-private-AS. */
5782 DEFUN (neighbor_remove_private_as,
5783 neighbor_remove_private_as_cmd,
5784 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5785 NEIGHBOR_STR
5786 NEIGHBOR_ADDR_STR2
5787 "Remove private ASNs in outbound updates\n")
5788 {
5789 int idx_peer = 1;
5790 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5791 bgp_node_safi(vty),
5792 PEER_FLAG_REMOVE_PRIVATE_AS);
5793 }
5794
5795 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5796 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5797 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5798 "Remove private ASNs in outbound updates\n")
5799
5800 DEFUN (neighbor_remove_private_as_all,
5801 neighbor_remove_private_as_all_cmd,
5802 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5803 NEIGHBOR_STR
5804 NEIGHBOR_ADDR_STR2
5805 "Remove private ASNs in outbound updates\n"
5806 "Apply to all AS numbers\n")
5807 {
5808 int idx_peer = 1;
5809 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5810 bgp_node_safi(vty),
5811 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5812 }
5813
5814 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5815 neighbor_remove_private_as_all_hidden_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5817 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5818 "Remove private ASNs in outbound updates\n"
5819 "Apply to all AS numbers\n")
5820
5821 DEFUN (neighbor_remove_private_as_replace_as,
5822 neighbor_remove_private_as_replace_as_cmd,
5823 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5824 NEIGHBOR_STR
5825 NEIGHBOR_ADDR_STR2
5826 "Remove private ASNs in outbound updates\n"
5827 "Replace private ASNs with our ASN in outbound updates\n")
5828 {
5829 int idx_peer = 1;
5830 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5831 bgp_node_safi(vty),
5832 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5833 }
5834
5835 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5836 neighbor_remove_private_as_replace_as_hidden_cmd,
5837 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5838 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5839 "Remove private ASNs in outbound updates\n"
5840 "Replace private ASNs with our ASN in outbound updates\n")
5841
5842 DEFUN (neighbor_remove_private_as_all_replace_as,
5843 neighbor_remove_private_as_all_replace_as_cmd,
5844 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5845 NEIGHBOR_STR
5846 NEIGHBOR_ADDR_STR2
5847 "Remove private ASNs in outbound updates\n"
5848 "Apply to all AS numbers\n"
5849 "Replace private ASNs with our ASN in outbound updates\n")
5850 {
5851 int idx_peer = 1;
5852 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5853 bgp_node_safi(vty),
5854 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5855 }
5856
5857 ALIAS_HIDDEN(
5858 neighbor_remove_private_as_all_replace_as,
5859 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5860 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5861 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5862 "Remove private ASNs in outbound updates\n"
5863 "Apply to all AS numbers\n"
5864 "Replace private ASNs with our ASN in outbound updates\n")
5865
5866 DEFUN (no_neighbor_remove_private_as,
5867 no_neighbor_remove_private_as_cmd,
5868 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5869 NO_STR
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Remove private ASNs in outbound updates\n")
5873 {
5874 int idx_peer = 2;
5875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5876 bgp_node_afi(vty), bgp_node_safi(vty),
5877 PEER_FLAG_REMOVE_PRIVATE_AS);
5878 }
5879
5880 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5881 no_neighbor_remove_private_as_hidden_cmd,
5882 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5883 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5884 "Remove private ASNs in outbound updates\n")
5885
5886 DEFUN (no_neighbor_remove_private_as_all,
5887 no_neighbor_remove_private_as_all_cmd,
5888 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5889 NO_STR
5890 NEIGHBOR_STR
5891 NEIGHBOR_ADDR_STR2
5892 "Remove private ASNs in outbound updates\n"
5893 "Apply to all AS numbers\n")
5894 {
5895 int idx_peer = 2;
5896 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5897 bgp_node_afi(vty), bgp_node_safi(vty),
5898 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5899 }
5900
5901 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5902 no_neighbor_remove_private_as_all_hidden_cmd,
5903 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5904 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5905 "Remove private ASNs in outbound updates\n"
5906 "Apply to all AS numbers\n")
5907
5908 DEFUN (no_neighbor_remove_private_as_replace_as,
5909 no_neighbor_remove_private_as_replace_as_cmd,
5910 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5911 NO_STR
5912 NEIGHBOR_STR
5913 NEIGHBOR_ADDR_STR2
5914 "Remove private ASNs in outbound updates\n"
5915 "Replace private ASNs with our ASN in outbound updates\n")
5916 {
5917 int idx_peer = 2;
5918 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5919 bgp_node_afi(vty), bgp_node_safi(vty),
5920 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5921 }
5922
5923 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5924 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5925 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5926 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5927 "Remove private ASNs in outbound updates\n"
5928 "Replace private ASNs with our ASN in outbound updates\n")
5929
5930 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5931 no_neighbor_remove_private_as_all_replace_as_cmd,
5932 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5933 NO_STR
5934 NEIGHBOR_STR
5935 NEIGHBOR_ADDR_STR2
5936 "Remove private ASNs in outbound updates\n"
5937 "Apply to all AS numbers\n"
5938 "Replace private ASNs with our ASN in outbound updates\n")
5939 {
5940 int idx_peer = 2;
5941 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5942 bgp_node_afi(vty), bgp_node_safi(vty),
5943 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5944 }
5945
5946 ALIAS_HIDDEN(
5947 no_neighbor_remove_private_as_all_replace_as,
5948 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5949 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5950 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5951 "Remove private ASNs in outbound updates\n"
5952 "Apply to all AS numbers\n"
5953 "Replace private ASNs with our ASN in outbound updates\n")
5954
5955
5956 /* neighbor send-community. */
5957 DEFUN (neighbor_send_community,
5958 neighbor_send_community_cmd,
5959 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5960 NEIGHBOR_STR
5961 NEIGHBOR_ADDR_STR2
5962 "Send Community attribute to this neighbor\n")
5963 {
5964 int idx_peer = 1;
5965
5966 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5967 bgp_node_safi(vty),
5968 PEER_FLAG_SEND_COMMUNITY);
5969 }
5970
5971 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5972 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5974 "Send Community attribute to this neighbor\n")
5975
5976 DEFUN (no_neighbor_send_community,
5977 no_neighbor_send_community_cmd,
5978 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5979 NO_STR
5980 NEIGHBOR_STR
5981 NEIGHBOR_ADDR_STR2
5982 "Send Community attribute to this neighbor\n")
5983 {
5984 int idx_peer = 2;
5985
5986 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5987 bgp_node_afi(vty), bgp_node_safi(vty),
5988 PEER_FLAG_SEND_COMMUNITY);
5989 }
5990
5991 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5992 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5993 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5994 "Send Community attribute to this neighbor\n")
5995
5996 /* neighbor send-community extended. */
5997 DEFUN (neighbor_send_community_type,
5998 neighbor_send_community_type_cmd,
5999 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6000 NEIGHBOR_STR
6001 NEIGHBOR_ADDR_STR2
6002 "Send Community attribute to this neighbor\n"
6003 "Send Standard and Extended Community attributes\n"
6004 "Send Standard, Large and Extended Community attributes\n"
6005 "Send Extended Community attributes\n"
6006 "Send Standard Community attributes\n"
6007 "Send Large Community attributes\n")
6008 {
6009 const char *type = argv[argc - 1]->text;
6010 char *peer_str = argv[1]->arg;
6011 struct peer *peer;
6012 afi_t afi = bgp_node_afi(vty);
6013 safi_t safi = bgp_node_safi(vty);
6014
6015 peer = peer_and_group_lookup_vty(vty, peer_str);
6016 if (!peer)
6017 return CMD_WARNING_CONFIG_FAILED;
6018
6019 if (strmatch(type, "standard"))
6020 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6021 PEER_FLAG_SEND_COMMUNITY);
6022
6023 if (strmatch(type, "extended"))
6024 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6025 PEER_FLAG_SEND_EXT_COMMUNITY);
6026
6027 if (strmatch(type, "large"))
6028 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6029 PEER_FLAG_SEND_LARGE_COMMUNITY);
6030
6031 if (strmatch(type, "both")) {
6032 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6033 PEER_FLAG_SEND_COMMUNITY)
6034 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6035 PEER_FLAG_SEND_EXT_COMMUNITY);
6036 }
6037 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6038 PEER_FLAG_SEND_COMMUNITY)
6039 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6040 PEER_FLAG_SEND_EXT_COMMUNITY)
6041 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6042 PEER_FLAG_SEND_LARGE_COMMUNITY);
6043 }
6044
6045 ALIAS_HIDDEN(
6046 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6047 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6048 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6049 "Send Community attribute to this neighbor\n"
6050 "Send Standard and Extended Community attributes\n"
6051 "Send Standard, Large and Extended Community attributes\n"
6052 "Send Extended Community attributes\n"
6053 "Send Standard Community attributes\n"
6054 "Send Large Community attributes\n")
6055
6056 DEFUN (no_neighbor_send_community_type,
6057 no_neighbor_send_community_type_cmd,
6058 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6059 NO_STR
6060 NEIGHBOR_STR
6061 NEIGHBOR_ADDR_STR2
6062 "Send Community attribute to this neighbor\n"
6063 "Send Standard and Extended Community attributes\n"
6064 "Send Standard, Large and Extended Community attributes\n"
6065 "Send Extended Community attributes\n"
6066 "Send Standard Community attributes\n"
6067 "Send Large Community attributes\n")
6068 {
6069 const char *type = argv[argc - 1]->text;
6070 char *peer_str = argv[2]->arg;
6071 struct peer *peer;
6072 afi_t afi = bgp_node_afi(vty);
6073 safi_t safi = bgp_node_safi(vty);
6074
6075 peer = peer_and_group_lookup_vty(vty, peer_str);
6076 if (!peer)
6077 return CMD_WARNING_CONFIG_FAILED;
6078
6079 if (strmatch(type, "standard"))
6080 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6081 PEER_FLAG_SEND_COMMUNITY);
6082
6083 if (strmatch(type, "extended"))
6084 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6085 PEER_FLAG_SEND_EXT_COMMUNITY);
6086
6087 if (strmatch(type, "large"))
6088 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6089 PEER_FLAG_SEND_LARGE_COMMUNITY);
6090
6091 if (strmatch(type, "both")) {
6092
6093 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6094 PEER_FLAG_SEND_COMMUNITY)
6095 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6096 PEER_FLAG_SEND_EXT_COMMUNITY);
6097 }
6098
6099 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6100 PEER_FLAG_SEND_COMMUNITY)
6101 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6102 PEER_FLAG_SEND_EXT_COMMUNITY)
6103 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6104 PEER_FLAG_SEND_LARGE_COMMUNITY);
6105 }
6106
6107 ALIAS_HIDDEN(
6108 no_neighbor_send_community_type,
6109 no_neighbor_send_community_type_hidden_cmd,
6110 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6111 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6112 "Send Community attribute to this neighbor\n"
6113 "Send Standard and Extended Community attributes\n"
6114 "Send Standard, Large and Extended Community attributes\n"
6115 "Send Extended Community attributes\n"
6116 "Send Standard Community attributes\n"
6117 "Send Large Community attributes\n")
6118
6119 /* neighbor soft-reconfig. */
6120 DEFUN (neighbor_soft_reconfiguration,
6121 neighbor_soft_reconfiguration_cmd,
6122 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6123 NEIGHBOR_STR
6124 NEIGHBOR_ADDR_STR2
6125 "Per neighbor soft reconfiguration\n"
6126 "Allow inbound soft reconfiguration for this neighbor\n")
6127 {
6128 int idx_peer = 1;
6129 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6130 bgp_node_safi(vty),
6131 PEER_FLAG_SOFT_RECONFIG);
6132 }
6133
6134 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6135 neighbor_soft_reconfiguration_hidden_cmd,
6136 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6138 "Per neighbor soft reconfiguration\n"
6139 "Allow inbound soft reconfiguration for this neighbor\n")
6140
6141 DEFUN (no_neighbor_soft_reconfiguration,
6142 no_neighbor_soft_reconfiguration_cmd,
6143 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6144 NO_STR
6145 NEIGHBOR_STR
6146 NEIGHBOR_ADDR_STR2
6147 "Per neighbor soft reconfiguration\n"
6148 "Allow inbound soft reconfiguration for this neighbor\n")
6149 {
6150 int idx_peer = 2;
6151 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6152 bgp_node_afi(vty), bgp_node_safi(vty),
6153 PEER_FLAG_SOFT_RECONFIG);
6154 }
6155
6156 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6157 no_neighbor_soft_reconfiguration_hidden_cmd,
6158 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6160 "Per neighbor soft reconfiguration\n"
6161 "Allow inbound soft reconfiguration for this neighbor\n")
6162
6163 DEFUN (neighbor_route_reflector_client,
6164 neighbor_route_reflector_client_cmd,
6165 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6166 NEIGHBOR_STR
6167 NEIGHBOR_ADDR_STR2
6168 "Configure a neighbor as Route Reflector client\n")
6169 {
6170 int idx_peer = 1;
6171 struct peer *peer;
6172
6173
6174 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6175 if (!peer)
6176 return CMD_WARNING_CONFIG_FAILED;
6177
6178 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6179 bgp_node_safi(vty),
6180 PEER_FLAG_REFLECTOR_CLIENT);
6181 }
6182
6183 ALIAS_HIDDEN(neighbor_route_reflector_client,
6184 neighbor_route_reflector_client_hidden_cmd,
6185 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6186 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6187 "Configure a neighbor as Route Reflector client\n")
6188
6189 DEFUN (no_neighbor_route_reflector_client,
6190 no_neighbor_route_reflector_client_cmd,
6191 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6192 NO_STR
6193 NEIGHBOR_STR
6194 NEIGHBOR_ADDR_STR2
6195 "Configure a neighbor as Route Reflector client\n")
6196 {
6197 int idx_peer = 2;
6198 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6199 bgp_node_afi(vty), bgp_node_safi(vty),
6200 PEER_FLAG_REFLECTOR_CLIENT);
6201 }
6202
6203 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6204 no_neighbor_route_reflector_client_hidden_cmd,
6205 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6206 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6207 "Configure a neighbor as Route Reflector client\n")
6208
6209 /* optimal-route-reflection Root Routers configuration */
6210 DEFPY (optimal_route_reflection,
6211 optimal_route_reflection_cmd,
6212 "[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]]]",
6213 NO_STR
6214 "Create ORR group and assign root router(s)\n"
6215 "ORR Group name\n"
6216 "Primary Root address\n"
6217 "Primary Root IPv6 address\n"
6218 "Secondary Root address\n"
6219 "Secondary Root IPv6 address\n"
6220 "Tertiary Root address\n"
6221 "Tertiary Root IPv6 address\n")
6222 {
6223 if (!no && !primary) {
6224 vty_out(vty, "%% Specify Primary Root address\n");
6225 return CMD_WARNING_CONFIG_FAILED;
6226 }
6227 return bgp_afi_safi_orr_group_set_vty(
6228 vty, bgp_node_afi(vty), bgp_node_safi(vty), orr_group,
6229 primary_str, secondary_str, tertiary_str, !!no);
6230 }
6231
6232 /* neighbor optimal-route-reflection group*/
6233 DEFPY (neighbor_optimal_route_reflection,
6234 neighbor_optimal_route_reflection_cmd,
6235 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor optimal-route-reflection WORD$orr_group",
6236 NO_STR
6237 NEIGHBOR_STR
6238 NEIGHBOR_ADDR_STR2
6239 "Apply ORR group configuration to the neighbor\n"
6240 "ORR group name\n")
6241 {
6242 return peer_orr_group_set_vty(vty, neighbor, bgp_node_afi(vty),
6243 bgp_node_safi(vty), orr_group, !!no);
6244 }
6245
6246 /* neighbor route-server-client. */
6247 DEFUN (neighbor_route_server_client,
6248 neighbor_route_server_client_cmd,
6249 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6250 NEIGHBOR_STR
6251 NEIGHBOR_ADDR_STR2
6252 "Configure a neighbor as Route Server client\n")
6253 {
6254 int idx_peer = 1;
6255 struct peer *peer;
6256
6257 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6258 if (!peer)
6259 return CMD_WARNING_CONFIG_FAILED;
6260 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6261 bgp_node_safi(vty),
6262 PEER_FLAG_RSERVER_CLIENT);
6263 }
6264
6265 ALIAS_HIDDEN(neighbor_route_server_client,
6266 neighbor_route_server_client_hidden_cmd,
6267 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6268 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6269 "Configure a neighbor as Route Server client\n")
6270
6271 DEFUN (no_neighbor_route_server_client,
6272 no_neighbor_route_server_client_cmd,
6273 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6274 NO_STR
6275 NEIGHBOR_STR
6276 NEIGHBOR_ADDR_STR2
6277 "Configure a neighbor as Route Server client\n")
6278 {
6279 int idx_peer = 2;
6280 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6281 bgp_node_afi(vty), bgp_node_safi(vty),
6282 PEER_FLAG_RSERVER_CLIENT);
6283 }
6284
6285 ALIAS_HIDDEN(no_neighbor_route_server_client,
6286 no_neighbor_route_server_client_hidden_cmd,
6287 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6288 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6289 "Configure a neighbor as Route Server client\n")
6290
6291 DEFUN (neighbor_nexthop_local_unchanged,
6292 neighbor_nexthop_local_unchanged_cmd,
6293 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6294 NEIGHBOR_STR
6295 NEIGHBOR_ADDR_STR2
6296 "Configure treatment of outgoing link-local nexthop attribute\n"
6297 "Leave link-local nexthop unchanged for this peer\n")
6298 {
6299 int idx_peer = 1;
6300 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6301 bgp_node_safi(vty),
6302 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6303 }
6304
6305 DEFUN (no_neighbor_nexthop_local_unchanged,
6306 no_neighbor_nexthop_local_unchanged_cmd,
6307 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6308 NO_STR
6309 NEIGHBOR_STR
6310 NEIGHBOR_ADDR_STR2
6311 "Configure treatment of outgoing link-local-nexthop attribute\n"
6312 "Leave link-local nexthop unchanged for this peer\n")
6313 {
6314 int idx_peer = 2;
6315 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6316 bgp_node_afi(vty), bgp_node_safi(vty),
6317 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6318 }
6319
6320 DEFUN (neighbor_attr_unchanged,
6321 neighbor_attr_unchanged_cmd,
6322 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6323 NEIGHBOR_STR
6324 NEIGHBOR_ADDR_STR2
6325 "BGP attribute is propagated unchanged to this neighbor\n"
6326 "As-path attribute\n"
6327 "Nexthop attribute\n"
6328 "Med attribute\n")
6329 {
6330 int idx = 0;
6331 char *peer_str = argv[1]->arg;
6332 struct peer *peer;
6333 bool aspath = false;
6334 bool nexthop = false;
6335 bool med = false;
6336 afi_t afi = bgp_node_afi(vty);
6337 safi_t safi = bgp_node_safi(vty);
6338 int ret = 0;
6339
6340 peer = peer_and_group_lookup_vty(vty, peer_str);
6341 if (!peer)
6342 return CMD_WARNING_CONFIG_FAILED;
6343
6344 if (argv_find(argv, argc, "as-path", &idx))
6345 aspath = true;
6346
6347 idx = 0;
6348 if (argv_find(argv, argc, "next-hop", &idx))
6349 nexthop = true;
6350
6351 idx = 0;
6352 if (argv_find(argv, argc, "med", &idx))
6353 med = true;
6354
6355 /* no flags means all of them! */
6356 if (!aspath && !nexthop && !med) {
6357 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6358 PEER_FLAG_AS_PATH_UNCHANGED);
6359 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6360 PEER_FLAG_NEXTHOP_UNCHANGED);
6361 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6362 PEER_FLAG_MED_UNCHANGED);
6363 } else {
6364 if (!aspath) {
6365 if (peer_af_flag_check(peer, afi, safi,
6366 PEER_FLAG_AS_PATH_UNCHANGED)) {
6367 ret |= peer_af_flag_unset_vty(
6368 vty, peer_str, afi, safi,
6369 PEER_FLAG_AS_PATH_UNCHANGED);
6370 }
6371 } else
6372 ret |= peer_af_flag_set_vty(
6373 vty, peer_str, afi, safi,
6374 PEER_FLAG_AS_PATH_UNCHANGED);
6375
6376 if (!nexthop) {
6377 if (peer_af_flag_check(peer, afi, safi,
6378 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6379 ret |= peer_af_flag_unset_vty(
6380 vty, peer_str, afi, safi,
6381 PEER_FLAG_NEXTHOP_UNCHANGED);
6382 }
6383 } else
6384 ret |= peer_af_flag_set_vty(
6385 vty, peer_str, afi, safi,
6386 PEER_FLAG_NEXTHOP_UNCHANGED);
6387
6388 if (!med) {
6389 if (peer_af_flag_check(peer, afi, safi,
6390 PEER_FLAG_MED_UNCHANGED)) {
6391 ret |= peer_af_flag_unset_vty(
6392 vty, peer_str, afi, safi,
6393 PEER_FLAG_MED_UNCHANGED);
6394 }
6395 } else
6396 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6397 PEER_FLAG_MED_UNCHANGED);
6398 }
6399
6400 return ret;
6401 }
6402
6403 ALIAS_HIDDEN(
6404 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6405 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6406 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6407 "BGP attribute is propagated unchanged to this neighbor\n"
6408 "As-path attribute\n"
6409 "Nexthop attribute\n"
6410 "Med attribute\n")
6411
6412 DEFUN (no_neighbor_attr_unchanged,
6413 no_neighbor_attr_unchanged_cmd,
6414 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6415 NO_STR
6416 NEIGHBOR_STR
6417 NEIGHBOR_ADDR_STR2
6418 "BGP attribute is propagated unchanged to this neighbor\n"
6419 "As-path attribute\n"
6420 "Nexthop attribute\n"
6421 "Med attribute\n")
6422 {
6423 int idx = 0;
6424 char *peer_str = argv[2]->arg;
6425 struct peer *peer;
6426 bool aspath = false;
6427 bool nexthop = false;
6428 bool med = false;
6429 afi_t afi = bgp_node_afi(vty);
6430 safi_t safi = bgp_node_safi(vty);
6431 int ret = 0;
6432
6433 peer = peer_and_group_lookup_vty(vty, peer_str);
6434 if (!peer)
6435 return CMD_WARNING_CONFIG_FAILED;
6436
6437 if (argv_find(argv, argc, "as-path", &idx))
6438 aspath = true;
6439
6440 idx = 0;
6441 if (argv_find(argv, argc, "next-hop", &idx))
6442 nexthop = true;
6443
6444 idx = 0;
6445 if (argv_find(argv, argc, "med", &idx))
6446 med = true;
6447
6448 if (!aspath && !nexthop && !med) // no flags means all of them!
6449 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6450 PEER_FLAG_AS_PATH_UNCHANGED)
6451 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6452 PEER_FLAG_NEXTHOP_UNCHANGED)
6453 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6454 PEER_FLAG_MED_UNCHANGED);
6455
6456 if (aspath)
6457 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6458 PEER_FLAG_AS_PATH_UNCHANGED);
6459
6460 if (nexthop)
6461 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6462 PEER_FLAG_NEXTHOP_UNCHANGED);
6463
6464 if (med)
6465 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6466 PEER_FLAG_MED_UNCHANGED);
6467
6468 return ret;
6469 }
6470
6471 ALIAS_HIDDEN(
6472 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6473 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6474 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6475 "BGP attribute is propagated unchanged to this neighbor\n"
6476 "As-path attribute\n"
6477 "Nexthop attribute\n"
6478 "Med attribute\n")
6479
6480 /* EBGP multihop configuration. */
6481 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6482 const char *ttl_str)
6483 {
6484 struct peer *peer;
6485 unsigned int ttl;
6486
6487 peer = peer_and_group_lookup_vty(vty, ip_str);
6488 if (!peer)
6489 return CMD_WARNING_CONFIG_FAILED;
6490
6491 if (peer->conf_if)
6492 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6493
6494 if (!ttl_str)
6495 ttl = MAXTTL;
6496 else
6497 ttl = strtoul(ttl_str, NULL, 10);
6498
6499 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6500 }
6501
6502 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6503 {
6504 struct peer *peer;
6505
6506 peer = peer_and_group_lookup_vty(vty, ip_str);
6507 if (!peer)
6508 return CMD_WARNING_CONFIG_FAILED;
6509
6510 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6511 }
6512
6513 /* neighbor ebgp-multihop. */
6514 DEFUN (neighbor_ebgp_multihop,
6515 neighbor_ebgp_multihop_cmd,
6516 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6517 NEIGHBOR_STR
6518 NEIGHBOR_ADDR_STR2
6519 "Allow EBGP neighbors not on directly connected networks\n")
6520 {
6521 int idx_peer = 1;
6522 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6523 }
6524
6525 DEFUN (neighbor_ebgp_multihop_ttl,
6526 neighbor_ebgp_multihop_ttl_cmd,
6527 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6528 NEIGHBOR_STR
6529 NEIGHBOR_ADDR_STR2
6530 "Allow EBGP neighbors not on directly connected networks\n"
6531 "maximum hop count\n")
6532 {
6533 int idx_peer = 1;
6534 int idx_number = 3;
6535 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6536 argv[idx_number]->arg);
6537 }
6538
6539 DEFUN (no_neighbor_ebgp_multihop,
6540 no_neighbor_ebgp_multihop_cmd,
6541 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6542 NO_STR
6543 NEIGHBOR_STR
6544 NEIGHBOR_ADDR_STR2
6545 "Allow EBGP neighbors not on directly connected networks\n"
6546 "maximum hop count\n")
6547 {
6548 int idx_peer = 2;
6549 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6550 }
6551
6552 static uint8_t get_role_by_name(const char *role_str)
6553 {
6554 if (strncmp(role_str, "peer", 2) == 0)
6555 return ROLE_PEER;
6556 if (strncmp(role_str, "provider", 2) == 0)
6557 return ROLE_PROVIDER;
6558 if (strncmp(role_str, "customer", 2) == 0)
6559 return ROLE_CUSTOMER;
6560 if (strncmp(role_str, "rs-server", 4) == 0)
6561 return ROLE_RS_SERVER;
6562 if (strncmp(role_str, "rs-client", 4) == 0)
6563 return ROLE_RS_CLIENT;
6564 return ROLE_UNDEFINED;
6565 }
6566
6567 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6568 const char *role_str, bool strict_mode)
6569 {
6570 struct peer *peer;
6571
6572 peer = peer_and_group_lookup_vty(vty, ip_str);
6573 if (!peer)
6574 return CMD_WARNING_CONFIG_FAILED;
6575 uint8_t role = get_role_by_name(role_str);
6576
6577 if (role == ROLE_UNDEFINED)
6578 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6579 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6580 }
6581
6582 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6583 {
6584 struct peer *peer;
6585
6586 peer = peer_and_group_lookup_vty(vty, ip_str);
6587 if (!peer)
6588 return CMD_WARNING_CONFIG_FAILED;
6589 return bgp_vty_return(vty, peer_role_unset(peer));
6590 }
6591
6592 DEFPY(neighbor_role,
6593 neighbor_role_cmd,
6594 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6595 NEIGHBOR_STR
6596 NEIGHBOR_ADDR_STR2
6597 "Set session role\n"
6598 ROLE_STR)
6599 {
6600 int idx_peer = 1;
6601 int idx_role = 3;
6602
6603 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6604 false);
6605 }
6606
6607 DEFPY(neighbor_role_strict,
6608 neighbor_role_strict_cmd,
6609 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6610 NEIGHBOR_STR
6611 NEIGHBOR_ADDR_STR2
6612 "Set session role\n"
6613 ROLE_STR
6614 "Use additional restriction on peer\n")
6615 {
6616 int idx_peer = 1;
6617 int idx_role = 3;
6618
6619 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6620 true);
6621 }
6622
6623 DEFPY(no_neighbor_role,
6624 no_neighbor_role_cmd,
6625 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6626 NO_STR
6627 NEIGHBOR_STR
6628 NEIGHBOR_ADDR_STR2
6629 "Set session role\n"
6630 ROLE_STR
6631 "Use additional restriction on peer\n")
6632 {
6633 int idx_peer = 2;
6634
6635 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6636 }
6637
6638 /* disable-connected-check */
6639 DEFUN (neighbor_disable_connected_check,
6640 neighbor_disable_connected_check_cmd,
6641 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6642 NEIGHBOR_STR
6643 NEIGHBOR_ADDR_STR2
6644 "one-hop away EBGP peer using loopback address\n"
6645 "Enforce EBGP neighbors perform multihop\n")
6646 {
6647 int idx_peer = 1;
6648 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6649 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6650 }
6651
6652 DEFUN (no_neighbor_disable_connected_check,
6653 no_neighbor_disable_connected_check_cmd,
6654 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6655 NO_STR
6656 NEIGHBOR_STR
6657 NEIGHBOR_ADDR_STR2
6658 "one-hop away EBGP peer using loopback address\n"
6659 "Enforce EBGP neighbors perform multihop\n")
6660 {
6661 int idx_peer = 2;
6662 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6663 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6664 }
6665
6666 /* disable-link-bw-encoding-ieee */
6667 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6668 neighbor_disable_link_bw_encoding_ieee_cmd,
6669 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6671 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6672 {
6673 int idx_peer = 1;
6674
6675 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6676 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6677 }
6678
6679 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6680 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6681 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6682 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6683 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6684 {
6685 int idx_peer = 2;
6686
6687 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6688 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6689 }
6690
6691 /* extended-optional-parameters */
6692 DEFUN(neighbor_extended_optional_parameters,
6693 neighbor_extended_optional_parameters_cmd,
6694 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6695 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6696 "Force the extended optional parameters format for OPEN messages\n")
6697 {
6698 int idx_peer = 1;
6699
6700 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6701 PEER_FLAG_EXTENDED_OPT_PARAMS);
6702 }
6703
6704 DEFUN(no_neighbor_extended_optional_parameters,
6705 no_neighbor_extended_optional_parameters_cmd,
6706 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6707 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6708 "Force the extended optional parameters format for OPEN messages\n")
6709 {
6710 int idx_peer = 2;
6711
6712 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6713 PEER_FLAG_EXTENDED_OPT_PARAMS);
6714 }
6715
6716 /* enforce-first-as */
6717 DEFUN (neighbor_enforce_first_as,
6718 neighbor_enforce_first_as_cmd,
6719 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6720 NEIGHBOR_STR
6721 NEIGHBOR_ADDR_STR2
6722 "Enforce the first AS for EBGP routes\n")
6723 {
6724 int idx_peer = 1;
6725
6726 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6727 PEER_FLAG_ENFORCE_FIRST_AS);
6728 }
6729
6730 DEFUN (no_neighbor_enforce_first_as,
6731 no_neighbor_enforce_first_as_cmd,
6732 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6733 NO_STR
6734 NEIGHBOR_STR
6735 NEIGHBOR_ADDR_STR2
6736 "Enforce the first AS for EBGP routes\n")
6737 {
6738 int idx_peer = 2;
6739
6740 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6741 PEER_FLAG_ENFORCE_FIRST_AS);
6742 }
6743
6744
6745 DEFUN (neighbor_description,
6746 neighbor_description_cmd,
6747 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6748 NEIGHBOR_STR
6749 NEIGHBOR_ADDR_STR2
6750 "Neighbor specific description\n"
6751 "Up to 80 characters describing this neighbor\n")
6752 {
6753 int idx_peer = 1;
6754 int idx_line = 3;
6755 struct peer *peer;
6756 char *str;
6757
6758 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6759 if (!peer)
6760 return CMD_WARNING_CONFIG_FAILED;
6761
6762 str = argv_concat(argv, argc, idx_line);
6763
6764 peer_description_set(peer, str);
6765
6766 XFREE(MTYPE_TMP, str);
6767
6768 return CMD_SUCCESS;
6769 }
6770
6771 DEFUN (no_neighbor_description,
6772 no_neighbor_description_cmd,
6773 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6774 NO_STR
6775 NEIGHBOR_STR
6776 NEIGHBOR_ADDR_STR2
6777 "Neighbor specific description\n")
6778 {
6779 int idx_peer = 2;
6780 struct peer *peer;
6781
6782 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6783 if (!peer)
6784 return CMD_WARNING_CONFIG_FAILED;
6785
6786 peer_description_unset(peer);
6787
6788 return CMD_SUCCESS;
6789 }
6790
6791 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6792 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6793 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6794 "Neighbor specific description\n"
6795 "Up to 80 characters describing this neighbor\n")
6796
6797 /* Neighbor update-source. */
6798 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6799 const char *source_str)
6800 {
6801 struct peer *peer;
6802 struct prefix p;
6803 union sockunion su;
6804
6805 peer = peer_and_group_lookup_vty(vty, peer_str);
6806 if (!peer)
6807 return CMD_WARNING_CONFIG_FAILED;
6808
6809 if (peer->conf_if)
6810 return CMD_WARNING;
6811
6812 if (source_str) {
6813 if (str2sockunion(source_str, &su) == 0)
6814 peer_update_source_addr_set(peer, &su);
6815 else {
6816 if (str2prefix(source_str, &p)) {
6817 vty_out(vty,
6818 "%% Invalid update-source, remove prefix length \n");
6819 return CMD_WARNING_CONFIG_FAILED;
6820 } else
6821 peer_update_source_if_set(peer, source_str);
6822 }
6823 } else
6824 peer_update_source_unset(peer);
6825
6826 return CMD_SUCCESS;
6827 }
6828
6829 #define BGP_UPDATE_SOURCE_HELP_STR \
6830 "IPv4 address\n" \
6831 "IPv6 address\n" \
6832 "Interface name (requires zebra to be running)\n"
6833
6834 DEFUN (neighbor_update_source,
6835 neighbor_update_source_cmd,
6836 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6837 NEIGHBOR_STR
6838 NEIGHBOR_ADDR_STR2
6839 "Source of routing updates\n"
6840 BGP_UPDATE_SOURCE_HELP_STR)
6841 {
6842 int idx_peer = 1;
6843 int idx_peer_2 = 3;
6844 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6845 argv[idx_peer_2]->arg);
6846 }
6847
6848 DEFUN (no_neighbor_update_source,
6849 no_neighbor_update_source_cmd,
6850 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6851 NO_STR
6852 NEIGHBOR_STR
6853 NEIGHBOR_ADDR_STR2
6854 "Source of routing updates\n"
6855 BGP_UPDATE_SOURCE_HELP_STR)
6856 {
6857 int idx_peer = 2;
6858 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6859 }
6860
6861 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6862 afi_t afi, safi_t safi,
6863 const char *rmap, int set)
6864 {
6865 int ret;
6866 struct peer *peer;
6867 struct route_map *route_map = NULL;
6868
6869 peer = peer_and_group_lookup_vty(vty, peer_str);
6870 if (!peer)
6871 return CMD_WARNING_CONFIG_FAILED;
6872
6873 if (set) {
6874 if (rmap)
6875 route_map = route_map_lookup_warn_noexist(vty, rmap);
6876 ret = peer_default_originate_set(peer, afi, safi,
6877 rmap, route_map);
6878 } else
6879 ret = peer_default_originate_unset(peer, afi, safi);
6880
6881 return bgp_vty_return(vty, ret);
6882 }
6883
6884 /* neighbor default-originate. */
6885 DEFUN (neighbor_default_originate,
6886 neighbor_default_originate_cmd,
6887 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6888 NEIGHBOR_STR
6889 NEIGHBOR_ADDR_STR2
6890 "Originate default route to this neighbor\n")
6891 {
6892 int idx_peer = 1;
6893 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6894 bgp_node_afi(vty),
6895 bgp_node_safi(vty), NULL, 1);
6896 }
6897
6898 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6899 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6900 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6901 "Originate default route to this neighbor\n")
6902
6903 DEFUN (neighbor_default_originate_rmap,
6904 neighbor_default_originate_rmap_cmd,
6905 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6906 NEIGHBOR_STR
6907 NEIGHBOR_ADDR_STR2
6908 "Originate default route to this neighbor\n"
6909 "Route-map to specify criteria to originate default\n"
6910 "route-map name\n")
6911 {
6912 int idx_peer = 1;
6913 int idx_word = 4;
6914 return peer_default_originate_set_vty(
6915 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6916 argv[idx_word]->arg, 1);
6917 }
6918
6919 ALIAS_HIDDEN(
6920 neighbor_default_originate_rmap,
6921 neighbor_default_originate_rmap_hidden_cmd,
6922 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6923 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6924 "Originate default route to this neighbor\n"
6925 "Route-map to specify criteria to originate default\n"
6926 "route-map name\n")
6927
6928 DEFUN (no_neighbor_default_originate,
6929 no_neighbor_default_originate_cmd,
6930 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6931 NO_STR
6932 NEIGHBOR_STR
6933 NEIGHBOR_ADDR_STR2
6934 "Originate default route to this neighbor\n"
6935 "Route-map to specify criteria to originate default\n"
6936 "route-map name\n")
6937 {
6938 int idx_peer = 2;
6939 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6940 bgp_node_afi(vty),
6941 bgp_node_safi(vty), NULL, 0);
6942 }
6943
6944 ALIAS_HIDDEN(
6945 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6946 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6947 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6948 "Originate default route to this neighbor\n"
6949 "Route-map to specify criteria to originate default\n"
6950 "route-map name\n")
6951
6952
6953 /* Set neighbor's BGP port. */
6954 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6955 const char *port_str)
6956 {
6957 struct peer *peer;
6958 uint16_t port;
6959 struct servent *sp;
6960
6961 peer = peer_and_group_lookup_vty(vty, ip_str);
6962 if (!peer)
6963 return CMD_WARNING_CONFIG_FAILED;
6964
6965 if (!port_str) {
6966 sp = getservbyname("bgp", "tcp");
6967 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6968 } else {
6969 port = strtoul(port_str, NULL, 10);
6970 }
6971
6972 peer_port_set(peer, port);
6973
6974 return CMD_SUCCESS;
6975 }
6976
6977 /* Set specified peer's BGP port. */
6978 DEFUN (neighbor_port,
6979 neighbor_port_cmd,
6980 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6981 NEIGHBOR_STR
6982 NEIGHBOR_ADDR_STR2
6983 "Neighbor's BGP port\n"
6984 "TCP port number\n")
6985 {
6986 int idx_ip = 1;
6987 int idx_number = 3;
6988 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6989 argv[idx_number]->arg);
6990 }
6991
6992 DEFUN (no_neighbor_port,
6993 no_neighbor_port_cmd,
6994 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6995 NO_STR
6996 NEIGHBOR_STR
6997 NEIGHBOR_ADDR_STR2
6998 "Neighbor's BGP port\n"
6999 "TCP port number\n")
7000 {
7001 int idx_ip = 2;
7002 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7003 }
7004
7005
7006 /* neighbor weight. */
7007 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7008 safi_t safi, const char *weight_str)
7009 {
7010 int ret;
7011 struct peer *peer;
7012 unsigned long weight;
7013
7014 peer = peer_and_group_lookup_vty(vty, ip_str);
7015 if (!peer)
7016 return CMD_WARNING_CONFIG_FAILED;
7017
7018 weight = strtoul(weight_str, NULL, 10);
7019
7020 ret = peer_weight_set(peer, afi, safi, weight);
7021 return bgp_vty_return(vty, ret);
7022 }
7023
7024 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7025 safi_t safi)
7026 {
7027 int ret;
7028 struct peer *peer;
7029
7030 peer = peer_and_group_lookup_vty(vty, ip_str);
7031 if (!peer)
7032 return CMD_WARNING_CONFIG_FAILED;
7033
7034 ret = peer_weight_unset(peer, afi, safi);
7035 return bgp_vty_return(vty, ret);
7036 }
7037
7038 DEFUN (neighbor_weight,
7039 neighbor_weight_cmd,
7040 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7041 NEIGHBOR_STR
7042 NEIGHBOR_ADDR_STR2
7043 "Set default weight for routes from this neighbor\n"
7044 "default weight\n")
7045 {
7046 int idx_peer = 1;
7047 int idx_number = 3;
7048 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7049 bgp_node_safi(vty), argv[idx_number]->arg);
7050 }
7051
7052 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7053 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7054 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7055 "Set default weight for routes from this neighbor\n"
7056 "default weight\n")
7057
7058 DEFUN (no_neighbor_weight,
7059 no_neighbor_weight_cmd,
7060 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7061 NO_STR
7062 NEIGHBOR_STR
7063 NEIGHBOR_ADDR_STR2
7064 "Set default weight for routes from this neighbor\n"
7065 "default weight\n")
7066 {
7067 int idx_peer = 2;
7068 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7069 bgp_node_afi(vty), bgp_node_safi(vty));
7070 }
7071
7072 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7073 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7074 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7075 "Set default weight for routes from this neighbor\n"
7076 "default weight\n")
7077
7078
7079 /* Override capability negotiation. */
7080 DEFUN (neighbor_override_capability,
7081 neighbor_override_capability_cmd,
7082 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7083 NEIGHBOR_STR
7084 NEIGHBOR_ADDR_STR2
7085 "Override capability negotiation result\n")
7086 {
7087 int idx_peer = 1;
7088 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7089 PEER_FLAG_OVERRIDE_CAPABILITY);
7090 }
7091
7092 DEFUN (no_neighbor_override_capability,
7093 no_neighbor_override_capability_cmd,
7094 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7095 NO_STR
7096 NEIGHBOR_STR
7097 NEIGHBOR_ADDR_STR2
7098 "Override capability negotiation result\n")
7099 {
7100 int idx_peer = 2;
7101 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7102 PEER_FLAG_OVERRIDE_CAPABILITY);
7103 }
7104
7105 DEFUN (neighbor_strict_capability,
7106 neighbor_strict_capability_cmd,
7107 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7108 NEIGHBOR_STR
7109 NEIGHBOR_ADDR_STR2
7110 "Strict capability negotiation match\n")
7111 {
7112 int idx_peer = 1;
7113
7114 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7115 PEER_FLAG_STRICT_CAP_MATCH);
7116 }
7117
7118 DEFUN (no_neighbor_strict_capability,
7119 no_neighbor_strict_capability_cmd,
7120 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7121 NO_STR
7122 NEIGHBOR_STR
7123 NEIGHBOR_ADDR_STR2
7124 "Strict capability negotiation match\n")
7125 {
7126 int idx_peer = 2;
7127
7128 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7129 PEER_FLAG_STRICT_CAP_MATCH);
7130 }
7131
7132 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7133 const char *keep_str, const char *hold_str)
7134 {
7135 int ret;
7136 struct peer *peer;
7137 uint32_t keepalive;
7138 uint32_t holdtime;
7139
7140 peer = peer_and_group_lookup_vty(vty, ip_str);
7141 if (!peer)
7142 return CMD_WARNING_CONFIG_FAILED;
7143
7144 keepalive = strtoul(keep_str, NULL, 10);
7145 holdtime = strtoul(hold_str, NULL, 10);
7146
7147 ret = peer_timers_set(peer, keepalive, holdtime);
7148
7149 return bgp_vty_return(vty, ret);
7150 }
7151
7152 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7153 {
7154 int ret;
7155 struct peer *peer;
7156
7157 peer = peer_and_group_lookup_vty(vty, ip_str);
7158 if (!peer)
7159 return CMD_WARNING_CONFIG_FAILED;
7160
7161 ret = peer_timers_unset(peer);
7162
7163 return bgp_vty_return(vty, ret);
7164 }
7165
7166 DEFUN (neighbor_timers,
7167 neighbor_timers_cmd,
7168 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7169 NEIGHBOR_STR
7170 NEIGHBOR_ADDR_STR2
7171 "BGP per neighbor timers\n"
7172 "Keepalive interval\n"
7173 "Holdtime\n")
7174 {
7175 int idx_peer = 1;
7176 int idx_number = 3;
7177 int idx_number_2 = 4;
7178 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7179 argv[idx_number]->arg,
7180 argv[idx_number_2]->arg);
7181 }
7182
7183 DEFUN (no_neighbor_timers,
7184 no_neighbor_timers_cmd,
7185 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7186 NO_STR
7187 NEIGHBOR_STR
7188 NEIGHBOR_ADDR_STR2
7189 "BGP per neighbor timers\n"
7190 "Keepalive interval\n"
7191 "Holdtime\n")
7192 {
7193 int idx_peer = 2;
7194 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7195 }
7196
7197
7198 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7199 const char *time_str)
7200 {
7201 int ret;
7202 struct peer *peer;
7203 uint32_t connect;
7204
7205 peer = peer_and_group_lookup_vty(vty, ip_str);
7206 if (!peer)
7207 return CMD_WARNING_CONFIG_FAILED;
7208
7209 connect = strtoul(time_str, NULL, 10);
7210
7211 ret = peer_timers_connect_set(peer, connect);
7212
7213 return bgp_vty_return(vty, ret);
7214 }
7215
7216 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7217 {
7218 int ret;
7219 struct peer *peer;
7220
7221 peer = peer_and_group_lookup_vty(vty, ip_str);
7222 if (!peer)
7223 return CMD_WARNING_CONFIG_FAILED;
7224
7225 ret = peer_timers_connect_unset(peer);
7226
7227 return bgp_vty_return(vty, ret);
7228 }
7229
7230 DEFUN (neighbor_timers_connect,
7231 neighbor_timers_connect_cmd,
7232 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7233 NEIGHBOR_STR
7234 NEIGHBOR_ADDR_STR2
7235 "BGP per neighbor timers\n"
7236 "BGP connect timer\n"
7237 "Connect timer\n")
7238 {
7239 int idx_peer = 1;
7240 int idx_number = 4;
7241 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7242 argv[idx_number]->arg);
7243 }
7244
7245 DEFUN (no_neighbor_timers_connect,
7246 no_neighbor_timers_connect_cmd,
7247 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7248 NO_STR
7249 NEIGHBOR_STR
7250 NEIGHBOR_ADDR_STR2
7251 "BGP per neighbor timers\n"
7252 "BGP connect timer\n"
7253 "Connect timer\n")
7254 {
7255 int idx_peer = 2;
7256 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7257 }
7258
7259 DEFPY (neighbor_timers_delayopen,
7260 neighbor_timers_delayopen_cmd,
7261 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7262 NEIGHBOR_STR
7263 NEIGHBOR_ADDR_STR2
7264 "BGP per neighbor timers\n"
7265 "RFC 4271 DelayOpenTimer\n"
7266 "DelayOpenTime timer interval\n")
7267 {
7268 struct peer *peer;
7269
7270 peer = peer_and_group_lookup_vty(vty, neighbor);
7271 if (!peer)
7272 return CMD_WARNING_CONFIG_FAILED;
7273
7274 if (!interval) {
7275 if (peer_timers_delayopen_unset(peer))
7276 return CMD_WARNING_CONFIG_FAILED;
7277 } else {
7278 if (peer_timers_delayopen_set(peer, interval))
7279 return CMD_WARNING_CONFIG_FAILED;
7280 }
7281
7282 return CMD_SUCCESS;
7283 }
7284
7285 DEFPY (no_neighbor_timers_delayopen,
7286 no_neighbor_timers_delayopen_cmd,
7287 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7288 NO_STR
7289 NEIGHBOR_STR
7290 NEIGHBOR_ADDR_STR2
7291 "BGP per neighbor timers\n"
7292 "RFC 4271 DelayOpenTimer\n"
7293 "DelayOpenTime timer interval\n")
7294 {
7295 struct peer *peer;
7296
7297 peer = peer_and_group_lookup_vty(vty, neighbor);
7298 if (!peer)
7299 return CMD_WARNING_CONFIG_FAILED;
7300
7301 if (peer_timers_delayopen_unset(peer))
7302 return CMD_WARNING_CONFIG_FAILED;
7303
7304 return CMD_SUCCESS;
7305 }
7306
7307 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7308 const char *time_str, int set)
7309 {
7310 int ret;
7311 struct peer *peer;
7312 uint32_t routeadv = 0;
7313
7314 peer = peer_and_group_lookup_vty(vty, ip_str);
7315 if (!peer)
7316 return CMD_WARNING_CONFIG_FAILED;
7317
7318 if (time_str)
7319 routeadv = strtoul(time_str, NULL, 10);
7320
7321 if (set)
7322 ret = peer_advertise_interval_set(peer, routeadv);
7323 else
7324 ret = peer_advertise_interval_unset(peer);
7325
7326 return bgp_vty_return(vty, ret);
7327 }
7328
7329 DEFUN (neighbor_advertise_interval,
7330 neighbor_advertise_interval_cmd,
7331 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Minimum interval between sending BGP routing updates\n"
7335 "time in seconds\n")
7336 {
7337 int idx_peer = 1;
7338 int idx_number = 3;
7339 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7340 argv[idx_number]->arg, 1);
7341 }
7342
7343 DEFUN (no_neighbor_advertise_interval,
7344 no_neighbor_advertise_interval_cmd,
7345 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7346 NO_STR
7347 NEIGHBOR_STR
7348 NEIGHBOR_ADDR_STR2
7349 "Minimum interval between sending BGP routing updates\n"
7350 "time in seconds\n")
7351 {
7352 int idx_peer = 2;
7353 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7354 }
7355
7356
7357 /* Time to wait before processing route-map updates */
7358 DEFUN (bgp_set_route_map_delay_timer,
7359 bgp_set_route_map_delay_timer_cmd,
7360 "bgp route-map delay-timer (0-600)",
7361 SET_STR
7362 "BGP route-map delay timer\n"
7363 "Time in secs to wait before processing route-map changes\n"
7364 "0 disables the timer, no route updates happen when route-maps change\n")
7365 {
7366 int idx_number = 3;
7367 uint32_t rmap_delay_timer;
7368
7369 if (argv[idx_number]->arg) {
7370 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7371 bm->rmap_update_timer = rmap_delay_timer;
7372
7373 /* if the dynamic update handling is being disabled, and a timer
7374 * is
7375 * running, stop the timer and act as if the timer has already
7376 * fired.
7377 */
7378 if (!rmap_delay_timer && bm->t_rmap_update) {
7379 THREAD_OFF(bm->t_rmap_update);
7380 thread_execute(bm->master, bgp_route_map_update_timer,
7381 NULL, 0);
7382 }
7383 return CMD_SUCCESS;
7384 } else {
7385 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7386 return CMD_WARNING_CONFIG_FAILED;
7387 }
7388 }
7389
7390 DEFUN (no_bgp_set_route_map_delay_timer,
7391 no_bgp_set_route_map_delay_timer_cmd,
7392 "no bgp route-map delay-timer [(0-600)]",
7393 NO_STR
7394 BGP_STR
7395 "Default BGP route-map delay timer\n"
7396 "Reset to default time to wait for processing route-map changes\n"
7397 "0 disables the timer, no route updates happen when route-maps change\n")
7398 {
7399
7400 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7401
7402 return CMD_SUCCESS;
7403 }
7404
7405 /* neighbor interface */
7406 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7407 const char *str)
7408 {
7409 struct peer *peer;
7410
7411 peer = peer_lookup_vty(vty, ip_str);
7412 if (!peer || peer->conf_if) {
7413 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7414 return CMD_WARNING_CONFIG_FAILED;
7415 }
7416
7417 if (str)
7418 peer_interface_set(peer, str);
7419 else
7420 peer_interface_unset(peer);
7421
7422 return CMD_SUCCESS;
7423 }
7424
7425 DEFUN (neighbor_interface,
7426 neighbor_interface_cmd,
7427 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7428 NEIGHBOR_STR
7429 NEIGHBOR_ADDR_STR
7430 "Interface\n"
7431 "Interface name\n")
7432 {
7433 int idx_ip = 1;
7434 int idx_word = 3;
7435
7436 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7437 }
7438
7439 DEFUN (no_neighbor_interface,
7440 no_neighbor_interface_cmd,
7441 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7442 NO_STR
7443 NEIGHBOR_STR
7444 NEIGHBOR_ADDR_STR
7445 "Interface\n"
7446 "Interface name\n")
7447 {
7448 int idx_peer = 2;
7449
7450 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7451 }
7452
7453 DEFUN (neighbor_distribute_list,
7454 neighbor_distribute_list_cmd,
7455 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7456 NEIGHBOR_STR
7457 NEIGHBOR_ADDR_STR2
7458 "Filter updates to/from this neighbor\n"
7459 "IP Access-list name\n"
7460 "Filter incoming updates\n"
7461 "Filter outgoing updates\n")
7462 {
7463 int idx_peer = 1;
7464 int idx_acl = 3;
7465 int direct, ret;
7466 struct peer *peer;
7467
7468 const char *pstr = argv[idx_peer]->arg;
7469 const char *acl = argv[idx_acl]->arg;
7470 const char *inout = argv[argc - 1]->text;
7471
7472 peer = peer_and_group_lookup_vty(vty, pstr);
7473 if (!peer)
7474 return CMD_WARNING_CONFIG_FAILED;
7475
7476 /* Check filter direction. */
7477 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7478 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7479 direct, acl);
7480
7481 return bgp_vty_return(vty, ret);
7482 }
7483
7484 ALIAS_HIDDEN(
7485 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7486 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7487 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7488 "Filter updates to/from this neighbor\n"
7489 "IP Access-list name\n"
7490 "Filter incoming updates\n"
7491 "Filter outgoing updates\n")
7492
7493 DEFUN (no_neighbor_distribute_list,
7494 no_neighbor_distribute_list_cmd,
7495 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7496 NO_STR
7497 NEIGHBOR_STR
7498 NEIGHBOR_ADDR_STR2
7499 "Filter updates to/from this neighbor\n"
7500 "IP Access-list name\n"
7501 "Filter incoming updates\n"
7502 "Filter outgoing updates\n")
7503 {
7504 int idx_peer = 2;
7505 int direct, ret;
7506 struct peer *peer;
7507
7508 const char *pstr = argv[idx_peer]->arg;
7509 const char *inout = argv[argc - 1]->text;
7510
7511 peer = peer_and_group_lookup_vty(vty, pstr);
7512 if (!peer)
7513 return CMD_WARNING_CONFIG_FAILED;
7514
7515 /* Check filter direction. */
7516 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7517 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7518 direct);
7519
7520 return bgp_vty_return(vty, ret);
7521 }
7522
7523 ALIAS_HIDDEN(
7524 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7525 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7526 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7527 "Filter updates to/from this neighbor\n"
7528 "IP Access-list name\n"
7529 "Filter incoming updates\n"
7530 "Filter outgoing updates\n")
7531
7532 /* Set prefix list to the peer. */
7533 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7534 afi_t afi, safi_t safi,
7535 const char *name_str,
7536 const char *direct_str)
7537 {
7538 int ret;
7539 int direct = FILTER_IN;
7540 struct peer *peer;
7541
7542 peer = peer_and_group_lookup_vty(vty, ip_str);
7543 if (!peer)
7544 return CMD_WARNING_CONFIG_FAILED;
7545
7546 /* Check filter direction. */
7547 if (strncmp(direct_str, "i", 1) == 0)
7548 direct = FILTER_IN;
7549 else if (strncmp(direct_str, "o", 1) == 0)
7550 direct = FILTER_OUT;
7551
7552 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7553
7554 return bgp_vty_return(vty, ret);
7555 }
7556
7557 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7558 afi_t afi, safi_t safi,
7559 const char *direct_str)
7560 {
7561 int ret;
7562 struct peer *peer;
7563 int direct = FILTER_IN;
7564
7565 peer = peer_and_group_lookup_vty(vty, ip_str);
7566 if (!peer)
7567 return CMD_WARNING_CONFIG_FAILED;
7568
7569 /* Check filter direction. */
7570 if (strncmp(direct_str, "i", 1) == 0)
7571 direct = FILTER_IN;
7572 else if (strncmp(direct_str, "o", 1) == 0)
7573 direct = FILTER_OUT;
7574
7575 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7576
7577 return bgp_vty_return(vty, ret);
7578 }
7579
7580 DEFUN (neighbor_prefix_list,
7581 neighbor_prefix_list_cmd,
7582 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7583 NEIGHBOR_STR
7584 NEIGHBOR_ADDR_STR2
7585 "Filter updates to/from this neighbor\n"
7586 "Name of a prefix list\n"
7587 "Filter incoming updates\n"
7588 "Filter outgoing updates\n")
7589 {
7590 int idx_peer = 1;
7591 int idx_word = 3;
7592 int idx_in_out = 4;
7593 return peer_prefix_list_set_vty(
7594 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7595 argv[idx_word]->arg, argv[idx_in_out]->arg);
7596 }
7597
7598 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7599 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7600 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7601 "Filter updates to/from this neighbor\n"
7602 "Name of a prefix list\n"
7603 "Filter incoming updates\n"
7604 "Filter outgoing updates\n")
7605
7606 DEFUN (no_neighbor_prefix_list,
7607 no_neighbor_prefix_list_cmd,
7608 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7609 NO_STR
7610 NEIGHBOR_STR
7611 NEIGHBOR_ADDR_STR2
7612 "Filter updates to/from this neighbor\n"
7613 "Name of a prefix list\n"
7614 "Filter incoming updates\n"
7615 "Filter outgoing updates\n")
7616 {
7617 int idx_peer = 2;
7618 int idx_in_out = 5;
7619 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7620 bgp_node_afi(vty), bgp_node_safi(vty),
7621 argv[idx_in_out]->arg);
7622 }
7623
7624 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7625 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7626 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7627 "Filter updates to/from this neighbor\n"
7628 "Name of a prefix list\n"
7629 "Filter incoming updates\n"
7630 "Filter outgoing updates\n")
7631
7632 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7633 safi_t safi, const char *name_str,
7634 const char *direct_str)
7635 {
7636 int ret;
7637 struct peer *peer;
7638 int direct = FILTER_IN;
7639
7640 peer = peer_and_group_lookup_vty(vty, ip_str);
7641 if (!peer)
7642 return CMD_WARNING_CONFIG_FAILED;
7643
7644 /* Check filter direction. */
7645 if (strncmp(direct_str, "i", 1) == 0)
7646 direct = FILTER_IN;
7647 else if (strncmp(direct_str, "o", 1) == 0)
7648 direct = FILTER_OUT;
7649
7650 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7651
7652 return bgp_vty_return(vty, ret);
7653 }
7654
7655 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7656 safi_t safi, const char *direct_str)
7657 {
7658 int ret;
7659 struct peer *peer;
7660 int direct = FILTER_IN;
7661
7662 peer = peer_and_group_lookup_vty(vty, ip_str);
7663 if (!peer)
7664 return CMD_WARNING_CONFIG_FAILED;
7665
7666 /* Check filter direction. */
7667 if (strncmp(direct_str, "i", 1) == 0)
7668 direct = FILTER_IN;
7669 else if (strncmp(direct_str, "o", 1) == 0)
7670 direct = FILTER_OUT;
7671
7672 ret = peer_aslist_unset(peer, afi, safi, direct);
7673
7674 return bgp_vty_return(vty, ret);
7675 }
7676
7677 DEFUN (neighbor_filter_list,
7678 neighbor_filter_list_cmd,
7679 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7680 NEIGHBOR_STR
7681 NEIGHBOR_ADDR_STR2
7682 "Establish BGP filters\n"
7683 "AS path access-list name\n"
7684 "Filter incoming routes\n"
7685 "Filter outgoing routes\n")
7686 {
7687 int idx_peer = 1;
7688 int idx_word = 3;
7689 int idx_in_out = 4;
7690 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7691 bgp_node_safi(vty), argv[idx_word]->arg,
7692 argv[idx_in_out]->arg);
7693 }
7694
7695 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7696 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7697 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7698 "Establish BGP filters\n"
7699 "AS path access-list name\n"
7700 "Filter incoming routes\n"
7701 "Filter outgoing routes\n")
7702
7703 DEFUN (no_neighbor_filter_list,
7704 no_neighbor_filter_list_cmd,
7705 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7706 NO_STR
7707 NEIGHBOR_STR
7708 NEIGHBOR_ADDR_STR2
7709 "Establish BGP filters\n"
7710 "AS path access-list name\n"
7711 "Filter incoming routes\n"
7712 "Filter outgoing routes\n")
7713 {
7714 int idx_peer = 2;
7715 int idx_in_out = 5;
7716 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7717 bgp_node_afi(vty), bgp_node_safi(vty),
7718 argv[idx_in_out]->arg);
7719 }
7720
7721 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7722 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7723 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7724 "Establish BGP filters\n"
7725 "AS path access-list name\n"
7726 "Filter incoming routes\n"
7727 "Filter outgoing routes\n")
7728
7729 /* Set advertise-map to the peer. */
7730 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7731 afi_t afi, safi_t safi,
7732 const char *advertise_str,
7733 const char *condition_str, bool condition,
7734 bool set)
7735 {
7736 int ret = CMD_WARNING_CONFIG_FAILED;
7737 struct peer *peer;
7738 struct route_map *advertise_map;
7739 struct route_map *condition_map;
7740
7741 peer = peer_and_group_lookup_vty(vty, ip_str);
7742 if (!peer)
7743 return ret;
7744
7745 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7746 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7747
7748 if (set)
7749 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7750 advertise_map, condition_str,
7751 condition_map, condition);
7752 else
7753 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7754 advertise_map, condition_str,
7755 condition_map, condition);
7756
7757 return bgp_vty_return(vty, ret);
7758 }
7759
7760 DEFPY (bgp_condadv_period,
7761 bgp_condadv_period_cmd,
7762 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7763 NO_STR
7764 BGP_STR
7765 "Conditional advertisement settings\n"
7766 "Set period to rescan BGP table to check if condition is met\n"
7767 "Period between BGP table scans, in seconds; default 60\n")
7768 {
7769 VTY_DECLVAR_CONTEXT(bgp, bgp);
7770
7771 bgp->condition_check_period =
7772 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7773
7774 return CMD_SUCCESS;
7775 }
7776
7777 DEFPY (neighbor_advertise_map,
7778 neighbor_advertise_map_cmd,
7779 "[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",
7780 NO_STR
7781 NEIGHBOR_STR
7782 NEIGHBOR_ADDR_STR2
7783 "Route-map to conditionally advertise routes\n"
7784 "Name of advertise map\n"
7785 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7786 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7787 "Name of the exist or non exist map\n")
7788 {
7789 bool condition = CONDITION_EXIST;
7790
7791 if (!strcmp(exist, "non-exist-map"))
7792 condition = CONDITION_NON_EXIST;
7793
7794 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7795 bgp_node_safi(vty), advertise_str,
7796 condition_str, condition, !no);
7797 }
7798
7799 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7800 "[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",
7801 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7802 "Route-map to conditionally advertise routes\n"
7803 "Name of advertise map\n"
7804 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7805 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7806 "Name of the exist or non exist map\n")
7807
7808 /* Set route-map to the peer. */
7809 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7810 afi_t afi, safi_t safi, const char *name_str,
7811 const char *direct_str)
7812 {
7813 int ret;
7814 struct peer *peer;
7815 int direct = RMAP_IN;
7816 struct route_map *route_map;
7817
7818 peer = peer_and_group_lookup_vty(vty, ip_str);
7819 if (!peer)
7820 return CMD_WARNING_CONFIG_FAILED;
7821
7822 /* Check filter direction. */
7823 if (strncmp(direct_str, "in", 2) == 0)
7824 direct = RMAP_IN;
7825 else if (strncmp(direct_str, "o", 1) == 0)
7826 direct = RMAP_OUT;
7827
7828 route_map = route_map_lookup_warn_noexist(vty, name_str);
7829 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7830
7831 return bgp_vty_return(vty, ret);
7832 }
7833
7834 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7835 afi_t afi, safi_t safi,
7836 const char *direct_str)
7837 {
7838 int ret;
7839 struct peer *peer;
7840 int direct = RMAP_IN;
7841
7842 peer = peer_and_group_lookup_vty(vty, ip_str);
7843 if (!peer)
7844 return CMD_WARNING_CONFIG_FAILED;
7845
7846 /* Check filter direction. */
7847 if (strncmp(direct_str, "in", 2) == 0)
7848 direct = RMAP_IN;
7849 else if (strncmp(direct_str, "o", 1) == 0)
7850 direct = RMAP_OUT;
7851
7852 ret = peer_route_map_unset(peer, afi, safi, direct);
7853
7854 return bgp_vty_return(vty, ret);
7855 }
7856
7857 DEFUN (neighbor_route_map,
7858 neighbor_route_map_cmd,
7859 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7860 NEIGHBOR_STR
7861 NEIGHBOR_ADDR_STR2
7862 "Apply route map to neighbor\n"
7863 "Name of route map\n"
7864 "Apply map to incoming routes\n"
7865 "Apply map to outbound routes\n")
7866 {
7867 int idx_peer = 1;
7868 int idx_word = 3;
7869 int idx_in_out = 4;
7870 return peer_route_map_set_vty(
7871 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7872 argv[idx_word]->arg, argv[idx_in_out]->arg);
7873 }
7874
7875 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7876 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7877 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7878 "Apply route map to neighbor\n"
7879 "Name of route map\n"
7880 "Apply map to incoming routes\n"
7881 "Apply map to outbound routes\n")
7882
7883 DEFUN (no_neighbor_route_map,
7884 no_neighbor_route_map_cmd,
7885 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7886 NO_STR
7887 NEIGHBOR_STR
7888 NEIGHBOR_ADDR_STR2
7889 "Apply route map to neighbor\n"
7890 "Name of route map\n"
7891 "Apply map to incoming routes\n"
7892 "Apply map to outbound routes\n")
7893 {
7894 int idx_peer = 2;
7895 int idx_in_out = 5;
7896 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7897 bgp_node_afi(vty), bgp_node_safi(vty),
7898 argv[idx_in_out]->arg);
7899 }
7900
7901 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7902 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7903 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7904 "Apply route map to neighbor\n"
7905 "Name of route map\n"
7906 "Apply map to incoming routes\n"
7907 "Apply map to outbound routes\n")
7908
7909 /* Set unsuppress-map to the peer. */
7910 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7911 afi_t afi, safi_t safi,
7912 const char *name_str)
7913 {
7914 int ret;
7915 struct peer *peer;
7916 struct route_map *route_map;
7917
7918 peer = peer_and_group_lookup_vty(vty, ip_str);
7919 if (!peer)
7920 return CMD_WARNING_CONFIG_FAILED;
7921
7922 route_map = route_map_lookup_warn_noexist(vty, name_str);
7923 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7924
7925 return bgp_vty_return(vty, ret);
7926 }
7927
7928 /* Unset route-map from the peer. */
7929 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7930 afi_t afi, safi_t safi)
7931 {
7932 int ret;
7933 struct peer *peer;
7934
7935 peer = peer_and_group_lookup_vty(vty, ip_str);
7936 if (!peer)
7937 return CMD_WARNING_CONFIG_FAILED;
7938
7939 ret = peer_unsuppress_map_unset(peer, afi, safi);
7940
7941 return bgp_vty_return(vty, ret);
7942 }
7943
7944 DEFUN (neighbor_unsuppress_map,
7945 neighbor_unsuppress_map_cmd,
7946 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7947 NEIGHBOR_STR
7948 NEIGHBOR_ADDR_STR2
7949 "Route-map to selectively unsuppress suppressed routes\n"
7950 "Name of route map\n")
7951 {
7952 int idx_peer = 1;
7953 int idx_word = 3;
7954 return peer_unsuppress_map_set_vty(
7955 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7956 argv[idx_word]->arg);
7957 }
7958
7959 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7960 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7962 "Route-map to selectively unsuppress suppressed routes\n"
7963 "Name of route map\n")
7964
7965 DEFUN (no_neighbor_unsuppress_map,
7966 no_neighbor_unsuppress_map_cmd,
7967 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7968 NO_STR
7969 NEIGHBOR_STR
7970 NEIGHBOR_ADDR_STR2
7971 "Route-map to selectively unsuppress suppressed routes\n"
7972 "Name of route map\n")
7973 {
7974 int idx_peer = 2;
7975 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7976 bgp_node_afi(vty),
7977 bgp_node_safi(vty));
7978 }
7979
7980 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7981 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7982 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7983 "Route-map to selectively unsuppress suppressed routes\n"
7984 "Name of route map\n")
7985
7986 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7987 afi_t afi, safi_t safi,
7988 const char *num_str,
7989 const char *threshold_str, int warning,
7990 const char *restart_str,
7991 const char *force_str)
7992 {
7993 int ret;
7994 struct peer *peer;
7995 uint32_t max;
7996 uint8_t threshold;
7997 uint16_t restart;
7998
7999 peer = peer_and_group_lookup_vty(vty, ip_str);
8000 if (!peer)
8001 return CMD_WARNING_CONFIG_FAILED;
8002
8003 max = strtoul(num_str, NULL, 10);
8004 if (threshold_str)
8005 threshold = atoi(threshold_str);
8006 else
8007 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8008
8009 if (restart_str)
8010 restart = atoi(restart_str);
8011 else
8012 restart = 0;
8013
8014 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8015 restart, force_str ? true : false);
8016
8017 return bgp_vty_return(vty, ret);
8018 }
8019
8020 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8021 afi_t afi, safi_t safi)
8022 {
8023 int ret;
8024 struct peer *peer;
8025
8026 peer = peer_and_group_lookup_vty(vty, ip_str);
8027 if (!peer)
8028 return CMD_WARNING_CONFIG_FAILED;
8029
8030 ret = peer_maximum_prefix_unset(peer, afi, safi);
8031
8032 return bgp_vty_return(vty, ret);
8033 }
8034
8035 /* Maximum number of prefix to be sent to the neighbor. */
8036 DEFUN(neighbor_maximum_prefix_out,
8037 neighbor_maximum_prefix_out_cmd,
8038 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8039 NEIGHBOR_STR
8040 NEIGHBOR_ADDR_STR2
8041 "Maximum number of prefixes to be sent to this peer\n"
8042 "Maximum no. of prefix limit\n")
8043 {
8044 int ret;
8045 int idx_peer = 1;
8046 int idx_number = 3;
8047 struct peer *peer;
8048 uint32_t max;
8049 afi_t afi = bgp_node_afi(vty);
8050 safi_t safi = bgp_node_safi(vty);
8051
8052 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8053 if (!peer)
8054 return CMD_WARNING_CONFIG_FAILED;
8055
8056 max = strtoul(argv[idx_number]->arg, NULL, 10);
8057
8058 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8059
8060 return bgp_vty_return(vty, ret);
8061 }
8062
8063 DEFUN(no_neighbor_maximum_prefix_out,
8064 no_neighbor_maximum_prefix_out_cmd,
8065 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8066 NO_STR
8067 NEIGHBOR_STR
8068 NEIGHBOR_ADDR_STR2
8069 "Maximum number of prefixes to be sent to this peer\n"
8070 "Maximum no. of prefix limit\n")
8071 {
8072 int ret;
8073 int idx_peer = 2;
8074 struct peer *peer;
8075 afi_t afi = bgp_node_afi(vty);
8076 safi_t safi = bgp_node_safi(vty);
8077
8078 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8079 if (!peer)
8080 return CMD_WARNING_CONFIG_FAILED;
8081
8082 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8083
8084 return bgp_vty_return(vty, ret);
8085 }
8086
8087 /* Maximum number of prefix configuration. Prefix count is different
8088 for each peer configuration. So this configuration can be set for
8089 each peer configuration. */
8090 DEFUN (neighbor_maximum_prefix,
8091 neighbor_maximum_prefix_cmd,
8092 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8093 NEIGHBOR_STR
8094 NEIGHBOR_ADDR_STR2
8095 "Maximum number of prefix accept from this peer\n"
8096 "maximum no. of prefix limit\n"
8097 "Force checking all received routes not only accepted\n")
8098 {
8099 int idx_peer = 1;
8100 int idx_number = 3;
8101 int idx_force = 0;
8102 char *force = NULL;
8103
8104 if (argv_find(argv, argc, "force", &idx_force))
8105 force = argv[idx_force]->arg;
8106
8107 return peer_maximum_prefix_set_vty(
8108 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8109 argv[idx_number]->arg, NULL, 0, NULL, force);
8110 }
8111
8112 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8113 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8114 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8115 "Maximum number of prefix accept from this peer\n"
8116 "maximum no. of prefix limit\n"
8117 "Force checking all received routes not only accepted\n")
8118
8119 DEFUN (neighbor_maximum_prefix_threshold,
8120 neighbor_maximum_prefix_threshold_cmd,
8121 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8122 NEIGHBOR_STR
8123 NEIGHBOR_ADDR_STR2
8124 "Maximum number of prefix accept from this peer\n"
8125 "maximum no. of prefix limit\n"
8126 "Threshold value (%) at which to generate a warning msg\n"
8127 "Force checking all received routes not only accepted\n")
8128 {
8129 int idx_peer = 1;
8130 int idx_number = 3;
8131 int idx_number_2 = 4;
8132 int idx_force = 0;
8133 char *force = NULL;
8134
8135 if (argv_find(argv, argc, "force", &idx_force))
8136 force = argv[idx_force]->arg;
8137
8138 return peer_maximum_prefix_set_vty(
8139 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8140 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8141 }
8142
8143 ALIAS_HIDDEN(
8144 neighbor_maximum_prefix_threshold,
8145 neighbor_maximum_prefix_threshold_hidden_cmd,
8146 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8147 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8148 "Maximum number of prefix accept from this peer\n"
8149 "maximum no. of prefix limit\n"
8150 "Threshold value (%) at which to generate a warning msg\n"
8151 "Force checking all received routes not only accepted\n")
8152
8153 DEFUN (neighbor_maximum_prefix_warning,
8154 neighbor_maximum_prefix_warning_cmd,
8155 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8156 NEIGHBOR_STR
8157 NEIGHBOR_ADDR_STR2
8158 "Maximum number of prefix accept from this peer\n"
8159 "maximum no. of prefix limit\n"
8160 "Only give warning message when limit is exceeded\n"
8161 "Force checking all received routes not only accepted\n")
8162 {
8163 int idx_peer = 1;
8164 int idx_number = 3;
8165 int idx_force = 0;
8166 char *force = NULL;
8167
8168 if (argv_find(argv, argc, "force", &idx_force))
8169 force = argv[idx_force]->arg;
8170
8171 return peer_maximum_prefix_set_vty(
8172 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8173 argv[idx_number]->arg, NULL, 1, NULL, force);
8174 }
8175
8176 ALIAS_HIDDEN(
8177 neighbor_maximum_prefix_warning,
8178 neighbor_maximum_prefix_warning_hidden_cmd,
8179 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8180 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8181 "Maximum number of prefix accept from this peer\n"
8182 "maximum no. of prefix limit\n"
8183 "Only give warning message when limit is exceeded\n"
8184 "Force checking all received routes not only accepted\n")
8185
8186 DEFUN (neighbor_maximum_prefix_threshold_warning,
8187 neighbor_maximum_prefix_threshold_warning_cmd,
8188 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8189 NEIGHBOR_STR
8190 NEIGHBOR_ADDR_STR2
8191 "Maximum number of prefix accept from this peer\n"
8192 "maximum no. of prefix limit\n"
8193 "Threshold value (%) at which to generate a warning msg\n"
8194 "Only give warning message when limit is exceeded\n"
8195 "Force checking all received routes not only accepted\n")
8196 {
8197 int idx_peer = 1;
8198 int idx_number = 3;
8199 int idx_number_2 = 4;
8200 int idx_force = 0;
8201 char *force = NULL;
8202
8203 if (argv_find(argv, argc, "force", &idx_force))
8204 force = argv[idx_force]->arg;
8205
8206 return peer_maximum_prefix_set_vty(
8207 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8208 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8209 }
8210
8211 ALIAS_HIDDEN(
8212 neighbor_maximum_prefix_threshold_warning,
8213 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8214 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8215 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8216 "Maximum number of prefix accept from this peer\n"
8217 "maximum no. of prefix limit\n"
8218 "Threshold value (%) at which to generate a warning msg\n"
8219 "Only give warning message when limit is exceeded\n"
8220 "Force checking all received routes not only accepted\n")
8221
8222 DEFUN (neighbor_maximum_prefix_restart,
8223 neighbor_maximum_prefix_restart_cmd,
8224 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8225 NEIGHBOR_STR
8226 NEIGHBOR_ADDR_STR2
8227 "Maximum number of prefix accept from this peer\n"
8228 "maximum no. of prefix limit\n"
8229 "Restart bgp connection after limit is exceeded\n"
8230 "Restart interval in minutes\n"
8231 "Force checking all received routes not only accepted\n")
8232 {
8233 int idx_peer = 1;
8234 int idx_number = 3;
8235 int idx_number_2 = 5;
8236 int idx_force = 0;
8237 char *force = NULL;
8238
8239 if (argv_find(argv, argc, "force", &idx_force))
8240 force = argv[idx_force]->arg;
8241
8242 return peer_maximum_prefix_set_vty(
8243 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8244 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8245 }
8246
8247 ALIAS_HIDDEN(
8248 neighbor_maximum_prefix_restart,
8249 neighbor_maximum_prefix_restart_hidden_cmd,
8250 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8252 "Maximum number of prefix accept from this peer\n"
8253 "maximum no. of prefix limit\n"
8254 "Restart bgp connection after limit is exceeded\n"
8255 "Restart interval in minutes\n"
8256 "Force checking all received routes not only accepted\n")
8257
8258 DEFUN (neighbor_maximum_prefix_threshold_restart,
8259 neighbor_maximum_prefix_threshold_restart_cmd,
8260 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8261 NEIGHBOR_STR
8262 NEIGHBOR_ADDR_STR2
8263 "Maximum number of prefixes to accept from this peer\n"
8264 "maximum no. of prefix limit\n"
8265 "Threshold value (%) at which to generate a warning msg\n"
8266 "Restart bgp connection after limit is exceeded\n"
8267 "Restart interval in minutes\n"
8268 "Force checking all received routes not only accepted\n")
8269 {
8270 int idx_peer = 1;
8271 int idx_number = 3;
8272 int idx_number_2 = 4;
8273 int idx_number_3 = 6;
8274 int idx_force = 0;
8275 char *force = NULL;
8276
8277 if (argv_find(argv, argc, "force", &idx_force))
8278 force = argv[idx_force]->arg;
8279
8280 return peer_maximum_prefix_set_vty(
8281 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8282 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8283 argv[idx_number_3]->arg, force);
8284 }
8285
8286 ALIAS_HIDDEN(
8287 neighbor_maximum_prefix_threshold_restart,
8288 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8289 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8290 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8291 "Maximum number of prefixes to accept from this peer\n"
8292 "maximum no. of prefix limit\n"
8293 "Threshold value (%) at which to generate a warning msg\n"
8294 "Restart bgp connection after limit is exceeded\n"
8295 "Restart interval in minutes\n"
8296 "Force checking all received routes not only accepted\n")
8297
8298 DEFUN (no_neighbor_maximum_prefix,
8299 no_neighbor_maximum_prefix_cmd,
8300 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8301 NO_STR
8302 NEIGHBOR_STR
8303 NEIGHBOR_ADDR_STR2
8304 "Maximum number of prefixes to accept from this peer\n"
8305 "maximum no. of prefix limit\n"
8306 "Threshold value (%) at which to generate a warning msg\n"
8307 "Restart bgp connection after limit is exceeded\n"
8308 "Restart interval in minutes\n"
8309 "Only give warning message when limit is exceeded\n"
8310 "Force checking all received routes not only accepted\n")
8311 {
8312 int idx_peer = 2;
8313 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8314 bgp_node_afi(vty),
8315 bgp_node_safi(vty));
8316 }
8317
8318 ALIAS_HIDDEN(
8319 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8320 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8321 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8322 "Maximum number of prefixes to accept from this peer\n"
8323 "maximum no. of prefix limit\n"
8324 "Threshold value (%) at which to generate a warning msg\n"
8325 "Restart bgp connection after limit is exceeded\n"
8326 "Restart interval in minutes\n"
8327 "Only give warning message when limit is exceeded\n"
8328 "Force checking all received routes not only accepted\n")
8329
8330 /* "neighbor accept-own" */
8331 DEFPY (neighbor_accept_own,
8332 neighbor_accept_own_cmd,
8333 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8334 NO_STR
8335 NEIGHBOR_STR
8336 NEIGHBOR_ADDR_STR2
8337 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8338 {
8339 struct peer *peer;
8340 afi_t afi = bgp_node_afi(vty);
8341 safi_t safi = bgp_node_safi(vty);
8342 int ret;
8343
8344 peer = peer_and_group_lookup_vty(vty, neighbor);
8345 if (!peer)
8346 return CMD_WARNING_CONFIG_FAILED;
8347
8348 if (no)
8349 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8350 else
8351 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8352
8353 return bgp_vty_return(vty, ret);
8354 }
8355
8356 /* "neighbor soo" */
8357 DEFPY (neighbor_soo,
8358 neighbor_soo_cmd,
8359 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8360 NEIGHBOR_STR
8361 NEIGHBOR_ADDR_STR2
8362 "Set the Site-of-Origin (SoO) extended community\n"
8363 "VPN extended community\n")
8364 {
8365 struct peer *peer;
8366 afi_t afi = bgp_node_afi(vty);
8367 safi_t safi = bgp_node_safi(vty);
8368 struct ecommunity *ecomm_soo;
8369
8370 peer = peer_and_group_lookup_vty(vty, neighbor);
8371 if (!peer)
8372 return CMD_WARNING_CONFIG_FAILED;
8373
8374 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8375 if (!ecomm_soo) {
8376 vty_out(vty, "%% Malformed SoO extended community\n");
8377 return CMD_WARNING;
8378 }
8379 ecommunity_str(ecomm_soo);
8380
8381 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8382 ecommunity_free(&peer->soo[afi][safi]);
8383 peer->soo[afi][safi] = ecomm_soo;
8384 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8385 }
8386
8387 return bgp_vty_return(vty,
8388 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8389 }
8390
8391 DEFPY (no_neighbor_soo,
8392 no_neighbor_soo_cmd,
8393 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8394 NO_STR
8395 NEIGHBOR_STR
8396 NEIGHBOR_ADDR_STR2
8397 "Set the Site-of-Origin (SoO) extended community\n"
8398 "VPN extended community\n")
8399 {
8400 struct peer *peer;
8401 afi_t afi = bgp_node_afi(vty);
8402 safi_t safi = bgp_node_safi(vty);
8403
8404 peer = peer_and_group_lookup_vty(vty, neighbor);
8405 if (!peer)
8406 return CMD_WARNING_CONFIG_FAILED;
8407
8408 ecommunity_free(&peer->soo[afi][safi]);
8409
8410 return bgp_vty_return(
8411 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8412 }
8413
8414 /* "neighbor allowas-in" */
8415 DEFUN (neighbor_allowas_in,
8416 neighbor_allowas_in_cmd,
8417 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8418 NEIGHBOR_STR
8419 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 int idx_peer = 1;
8425 int idx_number_origin = 3;
8426 int ret;
8427 int origin = 0;
8428 struct peer *peer;
8429 int allow_num = 0;
8430
8431 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8432 if (!peer)
8433 return CMD_WARNING_CONFIG_FAILED;
8434
8435 if (argc <= idx_number_origin)
8436 allow_num = 3;
8437 else {
8438 if (argv[idx_number_origin]->type == WORD_TKN)
8439 origin = 1;
8440 else
8441 allow_num = atoi(argv[idx_number_origin]->arg);
8442 }
8443
8444 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8445 allow_num, origin);
8446
8447 return bgp_vty_return(vty, ret);
8448 }
8449
8450 ALIAS_HIDDEN(
8451 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8452 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8453 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8454 "Accept as-path with my AS present in it\n"
8455 "Number of occurrences of AS number\n"
8456 "Only accept my AS in the as-path if the route was originated in my AS\n")
8457
8458 DEFUN (no_neighbor_allowas_in,
8459 no_neighbor_allowas_in_cmd,
8460 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8461 NO_STR
8462 NEIGHBOR_STR
8463 NEIGHBOR_ADDR_STR2
8464 "allow local ASN appears in aspath attribute\n"
8465 "Number of occurrences of AS number\n"
8466 "Only accept my AS in the as-path if the route was originated in my AS\n")
8467 {
8468 int idx_peer = 2;
8469 int ret;
8470 struct peer *peer;
8471
8472 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8473 if (!peer)
8474 return CMD_WARNING_CONFIG_FAILED;
8475
8476 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8477 bgp_node_safi(vty));
8478
8479 return bgp_vty_return(vty, ret);
8480 }
8481
8482 ALIAS_HIDDEN(
8483 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8484 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8485 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8486 "allow local ASN appears in aspath attribute\n"
8487 "Number of occurrences of AS number\n"
8488 "Only accept my AS in the as-path if the route was originated in my AS\n")
8489
8490 DEFUN (neighbor_ttl_security,
8491 neighbor_ttl_security_cmd,
8492 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8493 NEIGHBOR_STR
8494 NEIGHBOR_ADDR_STR2
8495 "BGP ttl-security parameters\n"
8496 "Specify the maximum number of hops to the BGP peer\n"
8497 "Number of hops to BGP peer\n")
8498 {
8499 int idx_peer = 1;
8500 int idx_number = 4;
8501 struct peer *peer;
8502 int gtsm_hops;
8503
8504 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8505 if (!peer)
8506 return CMD_WARNING_CONFIG_FAILED;
8507
8508 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8509
8510 /*
8511 * If 'neighbor swpX', then this is for directly connected peers,
8512 * we should not accept a ttl-security hops value greater than 1.
8513 */
8514 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8515 vty_out(vty,
8516 "%s is directly connected peer, hops cannot exceed 1\n",
8517 argv[idx_peer]->arg);
8518 return CMD_WARNING_CONFIG_FAILED;
8519 }
8520
8521 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8522 }
8523
8524 DEFUN (no_neighbor_ttl_security,
8525 no_neighbor_ttl_security_cmd,
8526 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8527 NO_STR
8528 NEIGHBOR_STR
8529 NEIGHBOR_ADDR_STR2
8530 "BGP ttl-security parameters\n"
8531 "Specify the maximum number of hops to the BGP peer\n"
8532 "Number of hops to BGP peer\n")
8533 {
8534 int idx_peer = 2;
8535 struct peer *peer;
8536
8537 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8538 if (!peer)
8539 return CMD_WARNING_CONFIG_FAILED;
8540
8541 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8542 }
8543
8544 /* disable-addpath-rx */
8545 DEFUN(neighbor_disable_addpath_rx,
8546 neighbor_disable_addpath_rx_cmd,
8547 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8548 NEIGHBOR_STR
8549 NEIGHBOR_ADDR_STR2
8550 "Do not accept additional paths\n")
8551 {
8552 char *peer_str = argv[1]->arg;
8553 struct peer *peer;
8554 afi_t afi = bgp_node_afi(vty);
8555 safi_t safi = bgp_node_safi(vty);
8556
8557 peer = peer_and_group_lookup_vty(vty, peer_str);
8558 if (!peer)
8559 return CMD_WARNING_CONFIG_FAILED;
8560
8561 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8562 PEER_FLAG_DISABLE_ADDPATH_RX);
8563 }
8564
8565 DEFUN(no_neighbor_disable_addpath_rx,
8566 no_neighbor_disable_addpath_rx_cmd,
8567 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8568 NO_STR
8569 NEIGHBOR_STR
8570 NEIGHBOR_ADDR_STR2
8571 "Do not accept additional paths\n")
8572 {
8573 char *peer_str = argv[2]->arg;
8574 struct peer *peer;
8575 afi_t afi = bgp_node_afi(vty);
8576 safi_t safi = bgp_node_safi(vty);
8577
8578 peer = peer_and_group_lookup_vty(vty, peer_str);
8579 if (!peer)
8580 return CMD_WARNING_CONFIG_FAILED;
8581
8582 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8583 PEER_FLAG_DISABLE_ADDPATH_RX);
8584 }
8585
8586 DEFUN (neighbor_addpath_tx_all_paths,
8587 neighbor_addpath_tx_all_paths_cmd,
8588 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8589 NEIGHBOR_STR
8590 NEIGHBOR_ADDR_STR2
8591 "Use addpath to advertise all paths to a neighbor\n")
8592 {
8593 int idx_peer = 1;
8594 struct peer *peer;
8595
8596 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8597 if (!peer)
8598 return CMD_WARNING_CONFIG_FAILED;
8599
8600 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8601 BGP_ADDPATH_ALL);
8602 return CMD_SUCCESS;
8603 }
8604
8605 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8606 neighbor_addpath_tx_all_paths_hidden_cmd,
8607 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8608 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8609 "Use addpath to advertise all paths to a neighbor\n")
8610
8611 DEFUN (no_neighbor_addpath_tx_all_paths,
8612 no_neighbor_addpath_tx_all_paths_cmd,
8613 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8614 NO_STR
8615 NEIGHBOR_STR
8616 NEIGHBOR_ADDR_STR2
8617 "Use addpath to advertise all paths to a neighbor\n")
8618 {
8619 int idx_peer = 2;
8620 struct peer *peer;
8621
8622 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8623 if (!peer)
8624 return CMD_WARNING_CONFIG_FAILED;
8625
8626 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8627 != BGP_ADDPATH_ALL) {
8628 vty_out(vty,
8629 "%% Peer not currently configured to transmit all paths.");
8630 return CMD_WARNING_CONFIG_FAILED;
8631 }
8632
8633 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8634 BGP_ADDPATH_NONE);
8635
8636 return CMD_SUCCESS;
8637 }
8638
8639 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8640 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8641 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8642 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8643 "Use addpath to advertise all paths to a neighbor\n")
8644
8645 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8646 neighbor_addpath_tx_bestpath_per_as_cmd,
8647 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8648 NEIGHBOR_STR
8649 NEIGHBOR_ADDR_STR2
8650 "Use addpath to advertise the bestpath per each neighboring AS\n")
8651 {
8652 int idx_peer = 1;
8653 struct peer *peer;
8654
8655 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8656 if (!peer)
8657 return CMD_WARNING_CONFIG_FAILED;
8658
8659 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8660 BGP_ADDPATH_BEST_PER_AS);
8661
8662 return CMD_SUCCESS;
8663 }
8664
8665 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8666 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8667 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8668 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8669 "Use addpath to advertise the bestpath per each neighboring AS\n")
8670
8671 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8672 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8673 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8674 NO_STR
8675 NEIGHBOR_STR
8676 NEIGHBOR_ADDR_STR2
8677 "Use addpath to advertise the bestpath per each neighboring AS\n")
8678 {
8679 int idx_peer = 2;
8680 struct peer *peer;
8681
8682 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8683 if (!peer)
8684 return CMD_WARNING_CONFIG_FAILED;
8685
8686 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8687 != BGP_ADDPATH_BEST_PER_AS) {
8688 vty_out(vty,
8689 "%% Peer not currently configured to transmit all best path per as.");
8690 return CMD_WARNING_CONFIG_FAILED;
8691 }
8692
8693 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8694 BGP_ADDPATH_NONE);
8695
8696 return CMD_SUCCESS;
8697 }
8698
8699 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8700 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8701 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8702 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8703 "Use addpath to advertise the bestpath per each neighboring AS\n")
8704
8705 DEFPY(
8706 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8707 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8708 NEIGHBOR_STR
8709 NEIGHBOR_ADDR_STR2
8710 "Detect AS loops before sending to neighbor\n")
8711 {
8712 struct peer *peer;
8713
8714 peer = peer_and_group_lookup_vty(vty, neighbor);
8715 if (!peer)
8716 return CMD_WARNING_CONFIG_FAILED;
8717
8718 peer->as_path_loop_detection = true;
8719
8720 return CMD_SUCCESS;
8721 }
8722
8723 DEFPY(
8724 no_neighbor_aspath_loop_detection,
8725 no_neighbor_aspath_loop_detection_cmd,
8726 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8727 NO_STR
8728 NEIGHBOR_STR
8729 NEIGHBOR_ADDR_STR2
8730 "Detect AS loops before sending to neighbor\n")
8731 {
8732 struct peer *peer;
8733
8734 peer = peer_and_group_lookup_vty(vty, neighbor);
8735 if (!peer)
8736 return CMD_WARNING_CONFIG_FAILED;
8737
8738 peer->as_path_loop_detection = false;
8739
8740 return CMD_SUCCESS;
8741 }
8742
8743 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8744 struct ecommunity **list, bool is_rt6)
8745 {
8746 struct ecommunity *ecom = NULL;
8747 struct ecommunity *ecomadd;
8748
8749 for (; argc; --argc, ++argv) {
8750 if (is_rt6)
8751 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8752 ECOMMUNITY_ROUTE_TARGET,
8753 0);
8754 else
8755 ecomadd = ecommunity_str2com(argv[0]->arg,
8756 ECOMMUNITY_ROUTE_TARGET,
8757 0);
8758 if (!ecomadd) {
8759 vty_out(vty, "Malformed community-list value\n");
8760 if (ecom)
8761 ecommunity_free(&ecom);
8762 return CMD_WARNING_CONFIG_FAILED;
8763 }
8764
8765 if (ecom) {
8766 ecommunity_merge(ecom, ecomadd);
8767 ecommunity_free(&ecomadd);
8768 } else {
8769 ecom = ecomadd;
8770 }
8771 }
8772
8773 if (*list) {
8774 ecommunity_free(&*list);
8775 }
8776 *list = ecom;
8777
8778 return CMD_SUCCESS;
8779 }
8780
8781 /*
8782 * v2vimport is true if we are handling a `import vrf ...` command
8783 */
8784 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8785 {
8786 afi_t afi;
8787
8788 switch (vty->node) {
8789 case BGP_IPV4_NODE:
8790 afi = AFI_IP;
8791 break;
8792 case BGP_IPV6_NODE:
8793 afi = AFI_IP6;
8794 break;
8795 default:
8796 vty_out(vty,
8797 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8798 return AFI_MAX;
8799 }
8800
8801 if (!v2vimport) {
8802 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8803 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8804 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8805 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8806 vty_out(vty,
8807 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8808 return AFI_MAX;
8809 }
8810 } else {
8811 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8812 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8813 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8814 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8815 vty_out(vty,
8816 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8817 return AFI_MAX;
8818 }
8819 }
8820 return afi;
8821 }
8822
8823 DEFPY (af_rd_vpn_export,
8824 af_rd_vpn_export_cmd,
8825 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8826 NO_STR
8827 "Specify route distinguisher\n"
8828 "Between current address-family and vpn\n"
8829 "For routes leaked from current address-family to vpn\n"
8830 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8831 {
8832 VTY_DECLVAR_CONTEXT(bgp, bgp);
8833 struct prefix_rd prd;
8834 int ret;
8835 afi_t afi;
8836 int idx = 0;
8837 bool yes = true;
8838
8839 if (argv_find(argv, argc, "no", &idx))
8840 yes = false;
8841
8842 if (yes) {
8843 ret = str2prefix_rd(rd_str, &prd);
8844 if (!ret) {
8845 vty_out(vty, "%% Malformed rd\n");
8846 return CMD_WARNING_CONFIG_FAILED;
8847 }
8848 }
8849
8850 afi = vpn_policy_getafi(vty, bgp, false);
8851 if (afi == AFI_MAX)
8852 return CMD_WARNING_CONFIG_FAILED;
8853
8854 /*
8855 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8856 */
8857 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8858 bgp_get_default(), bgp);
8859
8860 if (yes) {
8861 bgp->vpn_policy[afi].tovpn_rd = prd;
8862 SET_FLAG(bgp->vpn_policy[afi].flags,
8863 BGP_VPN_POLICY_TOVPN_RD_SET);
8864 } else {
8865 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8866 BGP_VPN_POLICY_TOVPN_RD_SET);
8867 }
8868
8869 /* post-change: re-export vpn routes */
8870 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8871 bgp_get_default(), bgp);
8872
8873 return CMD_SUCCESS;
8874 }
8875
8876 ALIAS (af_rd_vpn_export,
8877 af_no_rd_vpn_export_cmd,
8878 "no rd vpn export",
8879 NO_STR
8880 "Specify route distinguisher\n"
8881 "Between current address-family and vpn\n"
8882 "For routes leaked from current address-family to vpn\n")
8883
8884 DEFPY (af_label_vpn_export,
8885 af_label_vpn_export_cmd,
8886 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8887 NO_STR
8888 "label value for VRF\n"
8889 "Between current address-family and vpn\n"
8890 "For routes leaked from current address-family to vpn\n"
8891 "Label Value <0-1048575>\n"
8892 "Automatically assign a label\n")
8893 {
8894 VTY_DECLVAR_CONTEXT(bgp, bgp);
8895 mpls_label_t label = MPLS_LABEL_NONE;
8896 afi_t afi;
8897 int idx = 0;
8898 bool yes = true;
8899
8900 if (argv_find(argv, argc, "no", &idx))
8901 yes = false;
8902
8903 /* If "no ...", squash trailing parameter */
8904 if (!yes)
8905 label_auto = NULL;
8906
8907 if (yes) {
8908 if (!label_auto)
8909 label = label_val; /* parser should force unsigned */
8910 }
8911
8912 afi = vpn_policy_getafi(vty, bgp, false);
8913 if (afi == AFI_MAX)
8914 return CMD_WARNING_CONFIG_FAILED;
8915
8916
8917 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8918 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8919 /* no change */
8920 return CMD_SUCCESS;
8921
8922 /*
8923 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8924 */
8925 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8926 bgp_get_default(), bgp);
8927
8928 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8929 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8930
8931 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8932
8933 /*
8934 * label has previously been automatically
8935 * assigned by labelpool: release it
8936 *
8937 * NB if tovpn_label == MPLS_LABEL_NONE it
8938 * means the automatic assignment is in flight
8939 * and therefore the labelpool callback must
8940 * detect that the auto label is not needed.
8941 */
8942
8943 bgp_lp_release(LP_TYPE_VRF,
8944 &bgp->vpn_policy[afi],
8945 bgp->vpn_policy[afi].tovpn_label);
8946 }
8947 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8948 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8949 }
8950
8951 bgp->vpn_policy[afi].tovpn_label = label;
8952 if (label_auto) {
8953 SET_FLAG(bgp->vpn_policy[afi].flags,
8954 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8955 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8956 vpn_leak_label_callback);
8957 }
8958
8959 /* post-change: re-export vpn routes */
8960 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8961 bgp_get_default(), bgp);
8962
8963 hook_call(bgp_snmp_update_last_changed, bgp);
8964 return CMD_SUCCESS;
8965 }
8966
8967 DEFPY (af_sid_vpn_export,
8968 af_sid_vpn_export_cmd,
8969 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
8970 NO_STR
8971 "sid value for VRF\n"
8972 "Between current address-family and vpn\n"
8973 "For routes leaked from current address-family to vpn\n"
8974 "Sid allocation index\n"
8975 "Automatically assign a label\n")
8976 {
8977 VTY_DECLVAR_CONTEXT(bgp, bgp);
8978 afi_t afi;
8979 int debug = 0;
8980 int idx = 0;
8981 bool yes = true;
8982
8983 if (argv_find(argv, argc, "no", &idx))
8984 yes = false;
8985 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8986 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8987
8988 afi = vpn_policy_getafi(vty, bgp, false);
8989 if (afi == AFI_MAX)
8990 return CMD_WARNING_CONFIG_FAILED;
8991
8992 if (!yes) {
8993 /* implement me */
8994 vty_out(vty, "It's not implemented\n");
8995 return CMD_WARNING_CONFIG_FAILED;
8996 }
8997
8998 /* skip when it's already configured */
8999 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9000 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9001 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9002 return CMD_SUCCESS;
9003
9004 /*
9005 * mode change between sid_idx and sid_auto isn't supported.
9006 * user must negate sid vpn export when they want to change the mode
9007 */
9008 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9009 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9010 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9011 vty_out(vty, "it's already configured as %s.\n",
9012 sid_auto ? "auto-mode" : "idx-mode");
9013 return CMD_WARNING_CONFIG_FAILED;
9014 }
9015
9016 /* pre-change */
9017 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9018 bgp_get_default(), bgp);
9019
9020 if (sid_auto) {
9021 /* SID allocation auto-mode */
9022 if (debug)
9023 zlog_debug("%s: auto sid alloc.", __func__);
9024 SET_FLAG(bgp->vpn_policy[afi].flags,
9025 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9026 } else {
9027 /* SID allocation index-mode */
9028 if (debug)
9029 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9030 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9031 }
9032
9033 /* post-change */
9034 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9035 bgp_get_default(), bgp);
9036 return CMD_SUCCESS;
9037 }
9038
9039 ALIAS (af_label_vpn_export,
9040 af_no_label_vpn_export_cmd,
9041 "no label vpn export",
9042 NO_STR
9043 "label value for VRF\n"
9044 "Between current address-family and vpn\n"
9045 "For routes leaked from current address-family to vpn\n")
9046
9047 DEFPY (af_nexthop_vpn_export,
9048 af_nexthop_vpn_export_cmd,
9049 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9050 NO_STR
9051 "Specify next hop to use for VRF advertised prefixes\n"
9052 "Between current address-family and vpn\n"
9053 "For routes leaked from current address-family to vpn\n"
9054 "IPv4 prefix\n"
9055 "IPv6 prefix\n")
9056 {
9057 VTY_DECLVAR_CONTEXT(bgp, bgp);
9058 afi_t afi;
9059 struct prefix p;
9060
9061 if (!no) {
9062 if (!nexthop_su) {
9063 vty_out(vty, "%% Nexthop required\n");
9064 return CMD_WARNING_CONFIG_FAILED;
9065 }
9066 if (!sockunion2hostprefix(nexthop_su, &p))
9067 return CMD_WARNING_CONFIG_FAILED;
9068 }
9069
9070 afi = vpn_policy_getafi(vty, bgp, false);
9071 if (afi == AFI_MAX)
9072 return CMD_WARNING_CONFIG_FAILED;
9073
9074 /*
9075 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9076 */
9077 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9078 bgp_get_default(), bgp);
9079
9080 if (!no) {
9081 bgp->vpn_policy[afi].tovpn_nexthop = p;
9082 SET_FLAG(bgp->vpn_policy[afi].flags,
9083 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9084 } else {
9085 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9086 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9087 }
9088
9089 /* post-change: re-export vpn routes */
9090 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9091 bgp_get_default(), bgp);
9092
9093 return CMD_SUCCESS;
9094 }
9095
9096 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9097 {
9098 if (!strcmp(dstr, "import")) {
9099 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9100 } else if (!strcmp(dstr, "export")) {
9101 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9102 } else if (!strcmp(dstr, "both")) {
9103 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9104 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9105 } else {
9106 vty_out(vty, "%% direction parse error\n");
9107 return CMD_WARNING_CONFIG_FAILED;
9108 }
9109 return CMD_SUCCESS;
9110 }
9111
9112 DEFPY (af_rt_vpn_imexport,
9113 af_rt_vpn_imexport_cmd,
9114 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9115 NO_STR
9116 "Specify route target list\n"
9117 "Specify route target list\n"
9118 "Between current address-family and vpn\n"
9119 "For routes leaked from vpn to current address-family: match any\n"
9120 "For routes leaked from current address-family to vpn: set\n"
9121 "both import: match any and export: set\n"
9122 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9123 {
9124 VTY_DECLVAR_CONTEXT(bgp, bgp);
9125 int ret;
9126 struct ecommunity *ecom = NULL;
9127 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9128 enum vpn_policy_direction dir;
9129 afi_t afi;
9130 int idx = 0;
9131 bool yes = true;
9132
9133 if (argv_find(argv, argc, "no", &idx))
9134 yes = false;
9135
9136 afi = vpn_policy_getafi(vty, bgp, false);
9137 if (afi == AFI_MAX)
9138 return CMD_WARNING_CONFIG_FAILED;
9139
9140 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9141 if (ret != CMD_SUCCESS)
9142 return ret;
9143
9144 if (yes) {
9145 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9146 vty_out(vty, "%% Missing RTLIST\n");
9147 return CMD_WARNING_CONFIG_FAILED;
9148 }
9149 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9150 if (ret != CMD_SUCCESS) {
9151 return ret;
9152 }
9153 }
9154
9155 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9156 if (!dodir[dir])
9157 continue;
9158
9159 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9160
9161 if (yes) {
9162 if (bgp->vpn_policy[afi].rtlist[dir])
9163 ecommunity_free(
9164 &bgp->vpn_policy[afi].rtlist[dir]);
9165 bgp->vpn_policy[afi].rtlist[dir] =
9166 ecommunity_dup(ecom);
9167 } else {
9168 if (bgp->vpn_policy[afi].rtlist[dir])
9169 ecommunity_free(
9170 &bgp->vpn_policy[afi].rtlist[dir]);
9171 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9172 }
9173
9174 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9175 }
9176
9177 if (ecom)
9178 ecommunity_free(&ecom);
9179
9180 return CMD_SUCCESS;
9181 }
9182
9183 ALIAS (af_rt_vpn_imexport,
9184 af_no_rt_vpn_imexport_cmd,
9185 "no <rt|route-target> vpn <import|export|both>$direction_str",
9186 NO_STR
9187 "Specify route target list\n"
9188 "Specify route target list\n"
9189 "Between current address-family and vpn\n"
9190 "For routes leaked from vpn to current address-family\n"
9191 "For routes leaked from current address-family to vpn\n"
9192 "both import and export\n")
9193
9194 DEFPY (af_route_map_vpn_imexport,
9195 af_route_map_vpn_imexport_cmd,
9196 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9197 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9198 NO_STR
9199 "Specify route map\n"
9200 "Between current address-family and vpn\n"
9201 "For routes leaked from vpn to current address-family\n"
9202 "For routes leaked from current address-family to vpn\n"
9203 "name of route-map\n")
9204 {
9205 VTY_DECLVAR_CONTEXT(bgp, bgp);
9206 int ret;
9207 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9208 enum vpn_policy_direction dir;
9209 afi_t afi;
9210 int idx = 0;
9211 bool yes = true;
9212
9213 if (argv_find(argv, argc, "no", &idx))
9214 yes = false;
9215
9216 afi = vpn_policy_getafi(vty, bgp, false);
9217 if (afi == AFI_MAX)
9218 return CMD_WARNING_CONFIG_FAILED;
9219
9220 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9221 if (ret != CMD_SUCCESS)
9222 return ret;
9223
9224 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9225 if (!dodir[dir])
9226 continue;
9227
9228 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9229
9230 if (yes) {
9231 if (bgp->vpn_policy[afi].rmap_name[dir])
9232 XFREE(MTYPE_ROUTE_MAP_NAME,
9233 bgp->vpn_policy[afi].rmap_name[dir]);
9234 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9235 MTYPE_ROUTE_MAP_NAME, rmap_str);
9236 bgp->vpn_policy[afi].rmap[dir] =
9237 route_map_lookup_warn_noexist(vty, rmap_str);
9238 if (!bgp->vpn_policy[afi].rmap[dir])
9239 return CMD_SUCCESS;
9240 } else {
9241 if (bgp->vpn_policy[afi].rmap_name[dir])
9242 XFREE(MTYPE_ROUTE_MAP_NAME,
9243 bgp->vpn_policy[afi].rmap_name[dir]);
9244 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9245 bgp->vpn_policy[afi].rmap[dir] = NULL;
9246 }
9247
9248 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9249 }
9250
9251 return CMD_SUCCESS;
9252 }
9253
9254 ALIAS (af_route_map_vpn_imexport,
9255 af_no_route_map_vpn_imexport_cmd,
9256 "no route-map vpn <import|export>$direction_str",
9257 NO_STR
9258 "Specify route map\n"
9259 "Between current address-family and vpn\n"
9260 "For routes leaked from vpn to current address-family\n"
9261 "For routes leaked from current address-family to vpn\n")
9262
9263 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9264 "import vrf route-map RMAP$rmap_str",
9265 "Import routes from another VRF\n"
9266 "Vrf routes being filtered\n"
9267 "Specify route map\n"
9268 "name of route-map\n")
9269 {
9270 VTY_DECLVAR_CONTEXT(bgp, bgp);
9271 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9272 afi_t afi;
9273 struct bgp *bgp_default;
9274
9275 afi = vpn_policy_getafi(vty, bgp, true);
9276 if (afi == AFI_MAX)
9277 return CMD_WARNING_CONFIG_FAILED;
9278
9279 bgp_default = bgp_get_default();
9280 if (!bgp_default) {
9281 int32_t ret;
9282 as_t as = bgp->as;
9283
9284 /* Auto-create assuming the same AS */
9285 ret = bgp_get_vty(&bgp_default, &as, NULL,
9286 BGP_INSTANCE_TYPE_DEFAULT);
9287
9288 if (ret) {
9289 vty_out(vty,
9290 "VRF default is not configured as a bgp instance\n");
9291 return CMD_WARNING;
9292 }
9293 }
9294
9295 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9296
9297 if (bgp->vpn_policy[afi].rmap_name[dir])
9298 XFREE(MTYPE_ROUTE_MAP_NAME,
9299 bgp->vpn_policy[afi].rmap_name[dir]);
9300 bgp->vpn_policy[afi].rmap_name[dir] =
9301 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9302 bgp->vpn_policy[afi].rmap[dir] =
9303 route_map_lookup_warn_noexist(vty, rmap_str);
9304 if (!bgp->vpn_policy[afi].rmap[dir])
9305 return CMD_SUCCESS;
9306
9307 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9308 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9309
9310 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9311
9312 return CMD_SUCCESS;
9313 }
9314
9315 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9316 "no import vrf route-map [RMAP$rmap_str]",
9317 NO_STR
9318 "Import routes from another VRF\n"
9319 "Vrf routes being filtered\n"
9320 "Specify route map\n"
9321 "name of route-map\n")
9322 {
9323 VTY_DECLVAR_CONTEXT(bgp, bgp);
9324 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9325 afi_t afi;
9326
9327 afi = vpn_policy_getafi(vty, bgp, true);
9328 if (afi == AFI_MAX)
9329 return CMD_WARNING_CONFIG_FAILED;
9330
9331 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9332
9333 if (bgp->vpn_policy[afi].rmap_name[dir])
9334 XFREE(MTYPE_ROUTE_MAP_NAME,
9335 bgp->vpn_policy[afi].rmap_name[dir]);
9336 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9337 bgp->vpn_policy[afi].rmap[dir] = NULL;
9338
9339 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9340 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9341 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9342
9343 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9344
9345 return CMD_SUCCESS;
9346 }
9347
9348 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9349 "[no] import vrf VIEWVRFNAME$import_name",
9350 NO_STR
9351 "Import routes from another VRF\n"
9352 "VRF to import from\n"
9353 "The name of the VRF\n")
9354 {
9355 VTY_DECLVAR_CONTEXT(bgp, bgp);
9356 struct listnode *node;
9357 struct bgp *vrf_bgp, *bgp_default;
9358 int32_t ret = 0;
9359 as_t as = bgp->as;
9360 bool remove = false;
9361 int32_t idx = 0;
9362 char *vname;
9363 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9364 safi_t safi;
9365 afi_t afi;
9366
9367 if (import_name == NULL) {
9368 vty_out(vty, "%% Missing import name\n");
9369 return CMD_WARNING;
9370 }
9371
9372 if (strcmp(import_name, "route-map") == 0) {
9373 vty_out(vty, "%% Must include route-map name\n");
9374 return CMD_WARNING;
9375 }
9376
9377 if (argv_find(argv, argc, "no", &idx))
9378 remove = true;
9379
9380 afi = vpn_policy_getafi(vty, bgp, true);
9381 if (afi == AFI_MAX)
9382 return CMD_WARNING_CONFIG_FAILED;
9383
9384 safi = bgp_node_safi(vty);
9385
9386 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9387 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9388 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9389 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9390 remove ? "unimport" : "import", import_name);
9391 return CMD_WARNING;
9392 }
9393
9394 bgp_default = bgp_get_default();
9395 if (!bgp_default) {
9396 /* Auto-create assuming the same AS */
9397 ret = bgp_get_vty(&bgp_default, &as, NULL,
9398 BGP_INSTANCE_TYPE_DEFAULT);
9399
9400 if (ret) {
9401 vty_out(vty,
9402 "VRF default is not configured as a bgp instance\n");
9403 return CMD_WARNING;
9404 }
9405 }
9406
9407 vrf_bgp = bgp_lookup_by_name(import_name);
9408 if (!vrf_bgp) {
9409 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9410 vrf_bgp = bgp_default;
9411 else
9412 /* Auto-create assuming the same AS */
9413 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9414
9415 if (ret) {
9416 vty_out(vty,
9417 "VRF %s is not configured as a bgp instance\n",
9418 import_name);
9419 return CMD_WARNING;
9420 }
9421 }
9422
9423 if (remove) {
9424 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9425 } else {
9426 /* Already importing from "import_vrf"? */
9427 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9428 vname)) {
9429 if (strcmp(vname, import_name) == 0)
9430 return CMD_WARNING;
9431 }
9432
9433 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9434 }
9435
9436 return CMD_SUCCESS;
9437 }
9438
9439 /* This command is valid only in a bgp vrf instance or the default instance */
9440 DEFPY (bgp_imexport_vpn,
9441 bgp_imexport_vpn_cmd,
9442 "[no] <import|export>$direction_str vpn",
9443 NO_STR
9444 "Import routes to this address-family\n"
9445 "Export routes from this address-family\n"
9446 "to/from default instance VPN RIB\n")
9447 {
9448 VTY_DECLVAR_CONTEXT(bgp, bgp);
9449 int previous_state;
9450 afi_t afi;
9451 safi_t safi;
9452 int idx = 0;
9453 bool yes = true;
9454 int flag;
9455 enum vpn_policy_direction dir;
9456
9457 if (argv_find(argv, argc, "no", &idx))
9458 yes = false;
9459
9460 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9461 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9462
9463 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9464 return CMD_WARNING_CONFIG_FAILED;
9465 }
9466
9467 afi = bgp_node_afi(vty);
9468 safi = bgp_node_safi(vty);
9469 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9470 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9471 return CMD_WARNING_CONFIG_FAILED;
9472 }
9473
9474 if (!strcmp(direction_str, "import")) {
9475 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9476 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9477 } else if (!strcmp(direction_str, "export")) {
9478 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9479 dir = BGP_VPN_POLICY_DIR_TOVPN;
9480 } else {
9481 vty_out(vty, "%% unknown direction %s\n", direction_str);
9482 return CMD_WARNING_CONFIG_FAILED;
9483 }
9484
9485 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9486
9487 if (yes) {
9488 SET_FLAG(bgp->af_flags[afi][safi], flag);
9489 if (!previous_state) {
9490 /* trigger export current vrf */
9491 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9492 }
9493 } else {
9494 if (previous_state) {
9495 /* trigger un-export current vrf */
9496 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9497 }
9498 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9499 }
9500
9501 hook_call(bgp_snmp_init_stats, bgp);
9502
9503 return CMD_SUCCESS;
9504 }
9505
9506 DEFPY (af_routetarget_import,
9507 af_routetarget_import_cmd,
9508 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9509 NO_STR
9510 "Specify route target list\n"
9511 "Specify route target list\n"
9512 "Specify route target list\n"
9513 "Specify route target list\n"
9514 "Flow-spec redirect type route target\n"
9515 "Import routes to this address-family\n"
9516 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9517 {
9518 VTY_DECLVAR_CONTEXT(bgp, bgp);
9519 int ret;
9520 struct ecommunity *ecom = NULL;
9521 afi_t afi;
9522 int idx = 0, idx_unused = 0;
9523 bool yes = true;
9524 bool rt6 = false;
9525
9526 if (argv_find(argv, argc, "no", &idx))
9527 yes = false;
9528
9529 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9530 argv_find(argv, argc, "route-target6", &idx_unused))
9531 rt6 = true;
9532
9533 afi = vpn_policy_getafi(vty, bgp, false);
9534 if (afi == AFI_MAX)
9535 return CMD_WARNING_CONFIG_FAILED;
9536
9537 if (rt6 && afi != AFI_IP6)
9538 return CMD_WARNING_CONFIG_FAILED;
9539
9540 if (yes) {
9541 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9542 vty_out(vty, "%% Missing RTLIST\n");
9543 return CMD_WARNING_CONFIG_FAILED;
9544 }
9545 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9546 if (ret != CMD_SUCCESS)
9547 return ret;
9548 }
9549
9550 if (yes) {
9551 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9552 ecommunity_free(&bgp->vpn_policy[afi]
9553 .import_redirect_rtlist);
9554 bgp->vpn_policy[afi].import_redirect_rtlist =
9555 ecommunity_dup(ecom);
9556 } else {
9557 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9558 ecommunity_free(&bgp->vpn_policy[afi]
9559 .import_redirect_rtlist);
9560 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9561 }
9562
9563 if (ecom)
9564 ecommunity_free(&ecom);
9565
9566 return CMD_SUCCESS;
9567 }
9568
9569 DEFUN_NOSH (address_family_ipv4_safi,
9570 address_family_ipv4_safi_cmd,
9571 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9572 "Enter Address Family command mode\n"
9573 BGP_AF_STR
9574 BGP_SAFI_WITH_LABEL_HELP_STR)
9575 {
9576
9577 if (argc == 3) {
9578 VTY_DECLVAR_CONTEXT(bgp, bgp);
9579 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9580 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9581 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9582 && safi != SAFI_EVPN) {
9583 vty_out(vty,
9584 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9585 return CMD_WARNING_CONFIG_FAILED;
9586 }
9587 vty->node = bgp_node_type(AFI_IP, safi);
9588 } else
9589 vty->node = BGP_IPV4_NODE;
9590
9591 return CMD_SUCCESS;
9592 }
9593
9594 DEFUN_NOSH (address_family_ipv6_safi,
9595 address_family_ipv6_safi_cmd,
9596 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9597 "Enter Address Family command mode\n"
9598 BGP_AF_STR
9599 BGP_SAFI_WITH_LABEL_HELP_STR)
9600 {
9601 if (argc == 3) {
9602 VTY_DECLVAR_CONTEXT(bgp, bgp);
9603 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9604 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9605 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9606 && safi != SAFI_EVPN) {
9607 vty_out(vty,
9608 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9609 return CMD_WARNING_CONFIG_FAILED;
9610 }
9611 vty->node = bgp_node_type(AFI_IP6, safi);
9612 } else
9613 vty->node = BGP_IPV6_NODE;
9614
9615 return CMD_SUCCESS;
9616 }
9617
9618 #ifdef KEEP_OLD_VPN_COMMANDS
9619 DEFUN_NOSH (address_family_vpnv4,
9620 address_family_vpnv4_cmd,
9621 "address-family vpnv4 [unicast]",
9622 "Enter Address Family command mode\n"
9623 BGP_AF_STR
9624 BGP_AF_MODIFIER_STR)
9625 {
9626 vty->node = BGP_VPNV4_NODE;
9627 return CMD_SUCCESS;
9628 }
9629
9630 DEFUN_NOSH (address_family_vpnv6,
9631 address_family_vpnv6_cmd,
9632 "address-family vpnv6 [unicast]",
9633 "Enter Address Family command mode\n"
9634 BGP_AF_STR
9635 BGP_AF_MODIFIER_STR)
9636 {
9637 vty->node = BGP_VPNV6_NODE;
9638 return CMD_SUCCESS;
9639 }
9640 #endif /* KEEP_OLD_VPN_COMMANDS */
9641
9642 DEFUN_NOSH (address_family_evpn,
9643 address_family_evpn_cmd,
9644 "address-family l2vpn evpn",
9645 "Enter Address Family command mode\n"
9646 BGP_AF_STR
9647 BGP_AF_MODIFIER_STR)
9648 {
9649 VTY_DECLVAR_CONTEXT(bgp, bgp);
9650 vty->node = BGP_EVPN_NODE;
9651 return CMD_SUCCESS;
9652 }
9653
9654 DEFUN_NOSH (bgp_segment_routing_srv6,
9655 bgp_segment_routing_srv6_cmd,
9656 "segment-routing srv6",
9657 "Segment-Routing configuration\n"
9658 "Segment-Routing SRv6 configuration\n")
9659 {
9660 VTY_DECLVAR_CONTEXT(bgp, bgp);
9661 bgp->srv6_enabled = true;
9662 vty->node = BGP_SRV6_NODE;
9663 return CMD_SUCCESS;
9664 }
9665
9666 DEFUN (no_bgp_segment_routing_srv6,
9667 no_bgp_segment_routing_srv6_cmd,
9668 "no segment-routing srv6",
9669 NO_STR
9670 "Segment-Routing configuration\n"
9671 "Segment-Routing SRv6 configuration\n")
9672 {
9673 VTY_DECLVAR_CONTEXT(bgp, bgp);
9674
9675 if (strlen(bgp->srv6_locator_name) > 0)
9676 if (bgp_srv6_locator_unset(bgp) < 0)
9677 return CMD_WARNING_CONFIG_FAILED;
9678
9679 bgp->srv6_enabled = false;
9680 return CMD_SUCCESS;
9681 }
9682
9683 DEFPY (bgp_srv6_locator,
9684 bgp_srv6_locator_cmd,
9685 "locator NAME$name",
9686 "Specify SRv6 locator\n"
9687 "Specify SRv6 locator\n")
9688 {
9689 VTY_DECLVAR_CONTEXT(bgp, bgp);
9690 int ret;
9691
9692 if (strlen(bgp->srv6_locator_name) > 0
9693 && strcmp(name, bgp->srv6_locator_name) != 0) {
9694 vty_out(vty, "srv6 locator is already configured\n");
9695 return CMD_WARNING_CONFIG_FAILED;
9696 }
9697
9698 snprintf(bgp->srv6_locator_name,
9699 sizeof(bgp->srv6_locator_name), "%s", name);
9700
9701 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9702 if (ret < 0)
9703 return CMD_WARNING_CONFIG_FAILED;
9704
9705 return CMD_SUCCESS;
9706 }
9707
9708 DEFPY (no_bgp_srv6_locator,
9709 no_bgp_srv6_locator_cmd,
9710 "no locator NAME$name",
9711 NO_STR
9712 "Specify SRv6 locator\n"
9713 "Specify SRv6 locator\n")
9714 {
9715 VTY_DECLVAR_CONTEXT(bgp, bgp);
9716
9717 /* when locator isn't configured, do nothing */
9718 if (strlen(bgp->srv6_locator_name) < 1)
9719 return CMD_SUCCESS;
9720
9721 /* name validation */
9722 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9723 vty_out(vty, "%% No srv6 locator is configured\n");
9724 return CMD_WARNING_CONFIG_FAILED;
9725 }
9726
9727 /* unset locator */
9728 if (bgp_srv6_locator_unset(bgp) < 0)
9729 return CMD_WARNING_CONFIG_FAILED;
9730
9731 return CMD_SUCCESS;
9732 }
9733
9734 DEFPY (show_bgp_srv6,
9735 show_bgp_srv6_cmd,
9736 "show bgp segment-routing srv6",
9737 SHOW_STR
9738 BGP_STR
9739 "BGP Segment Routing\n"
9740 "BGP Segment Routing SRv6\n")
9741 {
9742 struct bgp *bgp;
9743 struct listnode *node;
9744 struct srv6_locator_chunk *chunk;
9745 struct bgp_srv6_function *func;
9746 char buf[256];
9747
9748 bgp = bgp_get_default();
9749 if (!bgp)
9750 return CMD_SUCCESS;
9751
9752 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9753 vty_out(vty, "locator_chunks:\n");
9754 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk))
9755 vty_out(vty, "- %pFX\n", &chunk->prefix);
9756
9757 vty_out(vty, "functions:\n");
9758 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9759 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9760 vty_out(vty, "- sid: %s\n", buf);
9761 vty_out(vty, " locator: %s\n", func->locator_name);
9762 }
9763
9764 vty_out(vty, "bgps:\n");
9765 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9766 vty_out(vty, "- name: %s\n",
9767 bgp->name ? bgp->name : "default");
9768
9769 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9770 bgp->vpn_policy[AFI_IP].tovpn_sid);
9771 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9772 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9773 }
9774
9775 return CMD_SUCCESS;
9776 }
9777
9778 DEFUN_NOSH (exit_address_family,
9779 exit_address_family_cmd,
9780 "exit-address-family",
9781 "Exit from Address Family configuration mode\n")
9782 {
9783 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9784 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9785 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9786 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9787 || vty->node == BGP_EVPN_NODE
9788 || vty->node == BGP_FLOWSPECV4_NODE
9789 || vty->node == BGP_FLOWSPECV6_NODE)
9790 vty->node = BGP_NODE;
9791 return CMD_SUCCESS;
9792 }
9793
9794 /* Recalculate bestpath and re-advertise a prefix */
9795 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9796 const char *ip_str, afi_t afi, safi_t safi,
9797 struct prefix_rd *prd)
9798 {
9799 int ret;
9800 struct prefix match;
9801 struct bgp_dest *dest;
9802 struct bgp_dest *rm;
9803 struct bgp *bgp;
9804 struct bgp_table *table;
9805 struct bgp_table *rib;
9806
9807 /* BGP structure lookup. */
9808 if (view_name) {
9809 bgp = bgp_lookup_by_name(view_name);
9810 if (bgp == NULL) {
9811 vty_out(vty, "%% Can't find BGP instance %s\n",
9812 view_name);
9813 return CMD_WARNING;
9814 }
9815 } else {
9816 bgp = bgp_get_default();
9817 if (bgp == NULL) {
9818 vty_out(vty, "%% No BGP process is configured\n");
9819 return CMD_WARNING;
9820 }
9821 }
9822
9823 /* Check IP address argument. */
9824 ret = str2prefix(ip_str, &match);
9825 if (!ret) {
9826 vty_out(vty, "%% address is malformed\n");
9827 return CMD_WARNING;
9828 }
9829
9830 match.family = afi2family(afi);
9831 rib = bgp->rib[afi][safi];
9832
9833 if (safi == SAFI_MPLS_VPN) {
9834 for (dest = bgp_table_top(rib); dest;
9835 dest = bgp_route_next(dest)) {
9836 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9837
9838 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9839 continue;
9840
9841 table = bgp_dest_get_bgp_table_info(dest);
9842 if (table == NULL)
9843 continue;
9844
9845 rm = bgp_node_match(table, &match);
9846 if (rm != NULL) {
9847 const struct prefix *rm_p =
9848 bgp_dest_get_prefix(rm);
9849
9850 if (rm_p->prefixlen == match.prefixlen) {
9851 SET_FLAG(rm->flags,
9852 BGP_NODE_USER_CLEAR);
9853 bgp_process(bgp, rm, afi, safi);
9854 }
9855 bgp_dest_unlock_node(rm);
9856 }
9857 }
9858 } else {
9859 dest = bgp_node_match(rib, &match);
9860 if (dest != NULL) {
9861 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9862
9863 if (dest_p->prefixlen == match.prefixlen) {
9864 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9865 bgp_process(bgp, dest, afi, safi);
9866 }
9867 bgp_dest_unlock_node(dest);
9868 }
9869 }
9870
9871 return CMD_SUCCESS;
9872 }
9873
9874 /* one clear bgp command to rule them all */
9875 DEFUN (clear_ip_bgp_all,
9876 clear_ip_bgp_all_cmd,
9877 "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>]",
9878 CLEAR_STR
9879 IP_STR
9880 BGP_STR
9881 BGP_INSTANCE_HELP_STR
9882 BGP_AFI_HELP_STR
9883 BGP_AF_STR
9884 BGP_SAFI_WITH_LABEL_HELP_STR
9885 BGP_AF_MODIFIER_STR
9886 "Clear all peers\n"
9887 "BGP IPv4 neighbor to clear\n"
9888 "BGP IPv6 neighbor to clear\n"
9889 "BGP neighbor on interface to clear\n"
9890 "Clear peers with the AS number\n"
9891 "Clear all external peers\n"
9892 "Clear all members of peer-group\n"
9893 "BGP peer-group name\n"
9894 BGP_SOFT_STR
9895 BGP_SOFT_IN_STR
9896 BGP_SOFT_OUT_STR
9897 BGP_SOFT_IN_STR
9898 "Push out prefix-list ORF and do inbound soft reconfig\n"
9899 BGP_SOFT_OUT_STR
9900 "Reset message statistics\n")
9901 {
9902 char *vrf = NULL;
9903
9904 afi_t afi = AFI_UNSPEC;
9905 safi_t safi = SAFI_UNSPEC;
9906 enum clear_sort clr_sort = clear_peer;
9907 enum bgp_clear_type clr_type;
9908 char *clr_arg = NULL;
9909
9910 int idx = 0;
9911
9912 /* clear [ip] bgp */
9913 if (argv_find(argv, argc, "ip", &idx))
9914 afi = AFI_IP;
9915
9916 /* [<vrf> VIEWVRFNAME] */
9917 if (argv_find(argv, argc, "vrf", &idx)) {
9918 vrf = argv[idx + 1]->arg;
9919 idx += 2;
9920 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9921 vrf = NULL;
9922 } else if (argv_find(argv, argc, "view", &idx)) {
9923 /* [<view> VIEWVRFNAME] */
9924 vrf = argv[idx + 1]->arg;
9925 idx += 2;
9926 }
9927 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9928 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9929 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9930
9931 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9932 if (argv_find(argv, argc, "*", &idx)) {
9933 clr_sort = clear_all;
9934 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9935 clr_sort = clear_peer;
9936 clr_arg = argv[idx]->arg;
9937 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9938 clr_sort = clear_peer;
9939 clr_arg = argv[idx]->arg;
9940 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9941 clr_sort = clear_group;
9942 idx++;
9943 clr_arg = argv[idx]->arg;
9944 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9945 clr_sort = clear_peer;
9946 clr_arg = argv[idx]->arg;
9947 } else if (argv_find(argv, argc, "WORD", &idx)) {
9948 clr_sort = clear_peer;
9949 clr_arg = argv[idx]->arg;
9950 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9951 clr_sort = clear_as;
9952 clr_arg = argv[idx]->arg;
9953 } else if (argv_find(argv, argc, "external", &idx)) {
9954 clr_sort = clear_external;
9955 }
9956
9957 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9958 if (argv_find(argv, argc, "soft", &idx)) {
9959 if (argv_find(argv, argc, "in", &idx)
9960 || argv_find(argv, argc, "out", &idx))
9961 clr_type = strmatch(argv[idx]->text, "in")
9962 ? BGP_CLEAR_SOFT_IN
9963 : BGP_CLEAR_SOFT_OUT;
9964 else
9965 clr_type = BGP_CLEAR_SOFT_BOTH;
9966 } else if (argv_find(argv, argc, "in", &idx)) {
9967 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9968 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9969 : BGP_CLEAR_SOFT_IN;
9970 } else if (argv_find(argv, argc, "out", &idx)) {
9971 clr_type = BGP_CLEAR_SOFT_OUT;
9972 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9973 clr_type = BGP_CLEAR_MESSAGE_STATS;
9974 } else
9975 clr_type = BGP_CLEAR_SOFT_NONE;
9976
9977 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9978 }
9979
9980 DEFUN (clear_ip_bgp_prefix,
9981 clear_ip_bgp_prefix_cmd,
9982 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9983 CLEAR_STR
9984 IP_STR
9985 BGP_STR
9986 BGP_INSTANCE_HELP_STR
9987 "Clear bestpath and re-advertise\n"
9988 "IPv4 prefix\n")
9989 {
9990 char *vrf = NULL;
9991 char *prefix = NULL;
9992
9993 int idx = 0;
9994
9995 /* [<view|vrf> VIEWVRFNAME] */
9996 if (argv_find(argv, argc, "vrf", &idx)) {
9997 vrf = argv[idx + 1]->arg;
9998 idx += 2;
9999 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10000 vrf = NULL;
10001 } else if (argv_find(argv, argc, "view", &idx)) {
10002 /* [<view> VIEWVRFNAME] */
10003 vrf = argv[idx + 1]->arg;
10004 idx += 2;
10005 }
10006
10007 prefix = argv[argc - 1]->arg;
10008
10009 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10010 }
10011
10012 DEFUN (clear_bgp_ipv6_safi_prefix,
10013 clear_bgp_ipv6_safi_prefix_cmd,
10014 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10015 CLEAR_STR
10016 IP_STR
10017 BGP_STR
10018 BGP_AF_STR
10019 BGP_SAFI_HELP_STR
10020 "Clear bestpath and re-advertise\n"
10021 "IPv6 prefix\n")
10022 {
10023 int idx_safi = 0;
10024 int idx_ipv6_prefix = 0;
10025 safi_t safi = SAFI_UNICAST;
10026 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10027 argv[idx_ipv6_prefix]->arg : NULL;
10028
10029 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10030 return bgp_clear_prefix(
10031 vty, NULL, prefix, AFI_IP6,
10032 safi, NULL);
10033 }
10034
10035 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10036 clear_bgp_instance_ipv6_safi_prefix_cmd,
10037 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10038 CLEAR_STR
10039 IP_STR
10040 BGP_STR
10041 BGP_INSTANCE_HELP_STR
10042 BGP_AF_STR
10043 BGP_SAFI_HELP_STR
10044 "Clear bestpath and re-advertise\n"
10045 "IPv6 prefix\n")
10046 {
10047 int idx_safi = 0;
10048 int idx_vrfview = 0;
10049 int idx_ipv6_prefix = 0;
10050 safi_t safi = SAFI_UNICAST;
10051 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10052 argv[idx_ipv6_prefix]->arg : NULL;
10053 char *vrfview = NULL;
10054
10055 /* [<view|vrf> VIEWVRFNAME] */
10056 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10057 vrfview = argv[idx_vrfview + 1]->arg;
10058 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10059 vrfview = NULL;
10060 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10061 /* [<view> VIEWVRFNAME] */
10062 vrfview = argv[idx_vrfview + 1]->arg;
10063 }
10064 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10065
10066 return bgp_clear_prefix(
10067 vty, vrfview, prefix,
10068 AFI_IP6, safi, NULL);
10069 }
10070
10071 DEFUN (show_bgp_views,
10072 show_bgp_views_cmd,
10073 "show [ip] bgp views",
10074 SHOW_STR
10075 IP_STR
10076 BGP_STR
10077 "Show the defined BGP views\n")
10078 {
10079 struct list *inst = bm->bgp;
10080 struct listnode *node;
10081 struct bgp *bgp;
10082
10083 vty_out(vty, "Defined BGP views:\n");
10084 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10085 /* Skip VRFs. */
10086 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10087 continue;
10088 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10089 bgp->as);
10090 }
10091
10092 return CMD_SUCCESS;
10093 }
10094
10095 DEFUN (show_bgp_vrfs,
10096 show_bgp_vrfs_cmd,
10097 "show [ip] bgp vrfs [json]",
10098 SHOW_STR
10099 IP_STR
10100 BGP_STR
10101 "Show BGP VRFs\n"
10102 JSON_STR)
10103 {
10104 char buf[ETHER_ADDR_STRLEN];
10105 struct list *inst = bm->bgp;
10106 struct listnode *node;
10107 struct bgp *bgp;
10108 bool uj = use_json(argc, argv);
10109 json_object *json = NULL;
10110 json_object *json_vrfs = NULL;
10111 int count = 0;
10112
10113 if (uj) {
10114 json = json_object_new_object();
10115 json_vrfs = json_object_new_object();
10116 }
10117
10118 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10119 const char *name, *type;
10120 struct peer *peer;
10121 struct listnode *node2, *nnode2;
10122 int peers_cfg, peers_estb;
10123 json_object *json_vrf = NULL;
10124
10125 /* Skip Views. */
10126 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10127 continue;
10128
10129 count++;
10130 if (!uj && count == 1) {
10131 vty_out(vty,
10132 "%4s %-5s %-16s %9s %10s %-37s\n",
10133 "Type", "Id", "routerId", "#PeersCfg",
10134 "#PeersEstb", "Name");
10135 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10136 "L3-VNI", "RouterMAC", "Interface");
10137 }
10138
10139 peers_cfg = peers_estb = 0;
10140 if (uj)
10141 json_vrf = json_object_new_object();
10142
10143
10144 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10145 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10146 continue;
10147 peers_cfg++;
10148 if (peer_established(peer))
10149 peers_estb++;
10150 }
10151
10152 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10153 name = VRF_DEFAULT_NAME;
10154 type = "DFLT";
10155 } else {
10156 name = bgp->name;
10157 type = "VRF";
10158 }
10159
10160
10161 if (uj) {
10162 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10163 ? -1
10164 : (int64_t)bgp->vrf_id;
10165 char buf[BUFSIZ] = {0};
10166
10167 json_object_string_add(json_vrf, "type", type);
10168 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10169 json_object_string_addf(json_vrf, "routerId", "%pI4",
10170 &bgp->router_id);
10171 json_object_int_add(json_vrf, "numConfiguredPeers",
10172 peers_cfg);
10173 json_object_int_add(json_vrf, "numEstablishedPeers",
10174 peers_estb);
10175
10176 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10177 json_object_string_add(
10178 json_vrf, "rmac",
10179 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10180 json_object_string_add(json_vrf, "interface",
10181 ifindex2ifname(bgp->l3vni_svi_ifindex,
10182 bgp->vrf_id));
10183 json_object_object_add(json_vrfs, name, json_vrf);
10184 } else {
10185 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10186 type,
10187 bgp->vrf_id == VRF_UNKNOWN ? -1
10188 : (int)bgp->vrf_id,
10189 &bgp->router_id, peers_cfg, peers_estb, name);
10190 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10191 bgp->l3vni,
10192 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10193 ifindex2ifname(bgp->l3vni_svi_ifindex,
10194 bgp->vrf_id));
10195 }
10196 }
10197
10198 if (uj) {
10199 json_object_object_add(json, "vrfs", json_vrfs);
10200
10201 json_object_int_add(json, "totalVrfs", count);
10202
10203 vty_json(vty, json);
10204 } else {
10205 if (count)
10206 vty_out(vty,
10207 "\nTotal number of VRFs (including default): %d\n",
10208 count);
10209 }
10210
10211 return CMD_SUCCESS;
10212 }
10213
10214 DEFUN (show_bgp_mac_hash,
10215 show_bgp_mac_hash_cmd,
10216 "show bgp mac hash",
10217 SHOW_STR
10218 BGP_STR
10219 "Mac Address\n"
10220 "Mac Address database\n")
10221 {
10222 bgp_mac_dump_table(vty);
10223
10224 return CMD_SUCCESS;
10225 }
10226
10227 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10228 {
10229 struct vty *vty = (struct vty *)args;
10230 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10231
10232 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10233 }
10234
10235 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10236 {
10237 vty_out(vty, "self nexthop database:\n");
10238 bgp_nexthop_show_address_hash(vty, bgp);
10239
10240 vty_out(vty, "Tunnel-ip database:\n");
10241 hash_iterate(bgp->tip_hash,
10242 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10243 vty);
10244 }
10245
10246 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10247 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10248 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10249 "martian next-hops\n"
10250 "martian next-hop database\n")
10251 {
10252 struct bgp *bgp = NULL;
10253 int idx = 0;
10254 char *name = NULL;
10255
10256 /* [<vrf> VIEWVRFNAME] */
10257 if (argv_find(argv, argc, "vrf", &idx)) {
10258 name = argv[idx + 1]->arg;
10259 if (name && strmatch(name, VRF_DEFAULT_NAME))
10260 name = NULL;
10261 } else if (argv_find(argv, argc, "view", &idx))
10262 /* [<view> VIEWVRFNAME] */
10263 name = argv[idx + 1]->arg;
10264 if (name)
10265 bgp = bgp_lookup_by_name(name);
10266 else
10267 bgp = bgp_get_default();
10268
10269 if (!bgp) {
10270 vty_out(vty, "%% No BGP process is configured\n");
10271 return CMD_WARNING;
10272 }
10273 bgp_show_martian_nexthops(vty, bgp);
10274
10275 return CMD_SUCCESS;
10276 }
10277
10278 DEFUN (show_bgp_memory,
10279 show_bgp_memory_cmd,
10280 "show [ip] bgp memory",
10281 SHOW_STR
10282 IP_STR
10283 BGP_STR
10284 "Global BGP memory statistics\n")
10285 {
10286 char memstrbuf[MTYPE_MEMSTR_LEN];
10287 unsigned long count;
10288
10289 /* RIB related usage stats */
10290 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10291 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10292 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10293 count * sizeof(struct bgp_dest)));
10294
10295 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10296 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10297 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10298 count * sizeof(struct bgp_path_info)));
10299 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10300 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10301 count,
10302 mtype_memstr(
10303 memstrbuf, sizeof(memstrbuf),
10304 count * sizeof(struct bgp_path_info_extra)));
10305
10306 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10307 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10308 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10309 count * sizeof(struct bgp_static)));
10310
10311 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10312 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10313 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10314 count * sizeof(struct bpacket)));
10315
10316 /* Adj-In/Out */
10317 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10318 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10319 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10320 count * sizeof(struct bgp_adj_in)));
10321 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10322 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10323 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10324 count * sizeof(struct bgp_adj_out)));
10325
10326 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10327 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10328 count,
10329 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10330 count * sizeof(struct bgp_nexthop_cache)));
10331
10332 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10333 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10334 count,
10335 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10336 count * sizeof(struct bgp_damp_info)));
10337
10338 /* Attributes */
10339 count = attr_count();
10340 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10341 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10342 count * sizeof(struct attr)));
10343
10344 if ((count = attr_unknown_count()))
10345 vty_out(vty, "%ld unknown attributes\n", count);
10346
10347 /* AS_PATH attributes */
10348 count = aspath_count();
10349 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10350 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10351 count * sizeof(struct aspath)));
10352
10353 count = mtype_stats_alloc(MTYPE_AS_SEG);
10354 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10355 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10356 count * sizeof(struct assegment)));
10357
10358 /* Other attributes */
10359 if ((count = community_count()))
10360 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10361 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10362 count * sizeof(struct community)));
10363 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10364 vty_out(vty,
10365 "%ld BGP ext-community entries, using %s of memory\n",
10366 count,
10367 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10368 count * sizeof(struct ecommunity)));
10369 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10370 vty_out(vty,
10371 "%ld BGP large-community entries, using %s of memory\n",
10372 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10373 count * sizeof(struct lcommunity)));
10374
10375 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10376 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10377 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10378 count * sizeof(struct cluster_list)));
10379
10380 /* Peer related usage */
10381 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10382 vty_out(vty, "%ld peers, using %s of memory\n", count,
10383 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10384 count * sizeof(struct peer)));
10385
10386 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10387 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10388 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10389 count * sizeof(struct peer_group)));
10390
10391 /* Other */
10392 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10393 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10394 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10395 count * sizeof(regex_t)));
10396 return CMD_SUCCESS;
10397 }
10398
10399 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10400 {
10401 json_object *bestpath = json_object_new_object();
10402
10403 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10404 json_object_string_add(bestpath, "asPath", "ignore");
10405
10406 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10407 json_object_string_add(bestpath, "asPath", "confed");
10408
10409 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10410 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10411 json_object_string_add(bestpath, "multiPathRelax",
10412 "as-set");
10413 else
10414 json_object_string_add(bestpath, "multiPathRelax",
10415 "true");
10416 } else
10417 json_object_string_add(bestpath, "multiPathRelax", "false");
10418
10419 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10420 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10421
10422 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10423 json_object_string_add(bestpath, "compareRouterId", "true");
10424 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10425 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10426 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10427 json_object_string_add(bestpath, "med", "confed");
10428 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10429 json_object_string_add(bestpath, "med",
10430 "missing-as-worst");
10431 else
10432 json_object_string_add(bestpath, "med", "true");
10433 }
10434
10435 json_object_object_add(json, "bestPath", bestpath);
10436 }
10437
10438 /* Print the error code/subcode for why the peer is down */
10439 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10440 json_object *json_peer, bool use_json)
10441 {
10442 const char *code_str;
10443 const char *subcode_str;
10444
10445 if (use_json) {
10446 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10447 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10448 char errorcodesubcode_hexstr[5];
10449 char errorcodesubcode_str[256];
10450
10451 code_str = bgp_notify_code_str(peer->notify.code);
10452 subcode_str = bgp_notify_subcode_str(
10453 peer->notify.code,
10454 peer->notify.subcode);
10455
10456 snprintf(errorcodesubcode_hexstr,
10457 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10458 peer->notify.code, peer->notify.subcode);
10459 json_object_string_add(json_peer,
10460 "lastErrorCodeSubcode",
10461 errorcodesubcode_hexstr);
10462 snprintf(errorcodesubcode_str, 255, "%s%s",
10463 code_str, subcode_str);
10464 json_object_string_add(json_peer,
10465 "lastNotificationReason",
10466 errorcodesubcode_str);
10467 json_object_boolean_add(json_peer,
10468 "lastNotificationHardReset",
10469 peer->notify.hard_reset);
10470 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10471 && peer->notify.code == BGP_NOTIFY_CEASE
10472 && (peer->notify.subcode
10473 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10474 || peer->notify.subcode
10475 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10476 && peer->notify.length) {
10477 char msgbuf[1024];
10478 const char *msg_str;
10479
10480 msg_str = bgp_notify_admin_message(
10481 msgbuf, sizeof(msgbuf),
10482 (uint8_t *)peer->notify.data,
10483 peer->notify.length);
10484 if (msg_str)
10485 json_object_string_add(
10486 json_peer,
10487 "lastShutdownDescription",
10488 msg_str);
10489 }
10490
10491 }
10492 json_object_string_add(json_peer, "lastResetDueTo",
10493 peer_down_str[(int)peer->last_reset]);
10494 json_object_int_add(json_peer, "lastResetCode",
10495 peer->last_reset);
10496 } else {
10497 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10498 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10499 code_str = bgp_notify_code_str(peer->notify.code);
10500 subcode_str =
10501 bgp_notify_subcode_str(peer->notify.code,
10502 peer->notify.subcode);
10503 vty_out(vty, " Notification %s (%s%s%s)\n",
10504 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10505 ? "sent"
10506 : "received",
10507 code_str, subcode_str,
10508 peer->notify.hard_reset
10509 ? bgp_notify_subcode_str(
10510 BGP_NOTIFY_CEASE,
10511 BGP_NOTIFY_CEASE_HARD_RESET)
10512 : "");
10513 } else {
10514 vty_out(vty, " %s\n",
10515 peer_down_str[(int)peer->last_reset]);
10516 }
10517 }
10518 }
10519
10520 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10521 safi_t safi)
10522 {
10523 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10524 }
10525
10526 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10527 struct peer *peer, json_object *json_peer,
10528 int max_neighbor_width, bool use_json)
10529 {
10530 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10531 int len;
10532
10533 if (use_json) {
10534 if (peer_dynamic_neighbor(peer))
10535 json_object_boolean_true_add(json_peer,
10536 "dynamicPeer");
10537 if (peer->hostname)
10538 json_object_string_add(json_peer, "hostname",
10539 peer->hostname);
10540
10541 if (peer->domainname)
10542 json_object_string_add(json_peer, "domainname",
10543 peer->domainname);
10544 json_object_int_add(json_peer, "connectionsEstablished",
10545 peer->established);
10546 json_object_int_add(json_peer, "connectionsDropped",
10547 peer->dropped);
10548 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10549 use_json, json_peer);
10550 if (peer_established(peer))
10551 json_object_string_add(json_peer, "lastResetDueTo",
10552 "AFI/SAFI Not Negotiated");
10553 else
10554 bgp_show_peer_reset(NULL, peer, json_peer, true);
10555 } else {
10556 dn_flag[1] = '\0';
10557 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10558 if (peer->hostname
10559 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10560 len = vty_out(vty, "%s%s(%s)", dn_flag,
10561 peer->hostname, peer->host);
10562 else
10563 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10564
10565 /* pad the neighbor column with spaces */
10566 if (len < max_neighbor_width)
10567 vty_out(vty, "%*s", max_neighbor_width - len,
10568 " ");
10569 vty_out(vty, "%7d %7d %9s", peer->established,
10570 peer->dropped,
10571 peer_uptime(peer->uptime, timebuf,
10572 BGP_UPTIME_LEN, 0, NULL));
10573 if (peer_established(peer))
10574 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10575 else
10576 bgp_show_peer_reset(vty, peer, NULL,
10577 false);
10578 }
10579 }
10580
10581 /* Strip peer's description to the given size. */
10582 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10583 {
10584 static char stripped[BUFSIZ];
10585 uint32_t i = 0;
10586 uint32_t last_space = 0;
10587
10588 while (i < size) {
10589 if (*(desc + i) == 0) {
10590 stripped[i] = '\0';
10591 return stripped;
10592 }
10593 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10594 last_space = i;
10595 stripped[i] = *(desc + i);
10596 i++;
10597 }
10598
10599 if (last_space > size)
10600 stripped[size + 1] = '\0';
10601 else
10602 stripped[last_space] = '\0';
10603
10604 return stripped;
10605 }
10606
10607 /* Determine whether var peer should be filtered out of the summary. */
10608 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10609 struct peer *fpeer, int as_type,
10610 as_t as)
10611 {
10612
10613 /* filter neighbor XXXX */
10614 if (fpeer && fpeer != peer)
10615 return true;
10616
10617 /* filter remote-as (internal|external) */
10618 if (as_type != AS_UNSPECIFIED) {
10619 if (peer->as_type == AS_SPECIFIED) {
10620 if (as_type == AS_INTERNAL) {
10621 if (peer->as != peer->local_as)
10622 return true;
10623 } else if (peer->as == peer->local_as)
10624 return true;
10625 } else if (as_type != peer->as_type)
10626 return true;
10627 } else if (as && as != peer->as) /* filter remote-as XXX */
10628 return true;
10629
10630 return false;
10631 }
10632
10633 /* Show BGP peer's summary information.
10634 *
10635 * Peer's description is stripped according to if `wide` option is given
10636 * or not.
10637 *
10638 * When adding new columns to `show bgp summary` output, please make
10639 * sure `Desc` is the lastest column to show because it can contain
10640 * whitespaces and the whole output will be tricky.
10641 */
10642 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10643 struct peer *fpeer, int as_type, as_t as,
10644 uint16_t show_flags)
10645 {
10646 struct peer *peer;
10647 struct listnode *node, *nnode;
10648 unsigned int count = 0, dn_count = 0;
10649 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10650 char neighbor_buf[VTY_BUFSIZ];
10651 int neighbor_col_default_width = 16;
10652 int len, failed_count = 0;
10653 unsigned int filtered_count = 0;
10654 int max_neighbor_width = 0;
10655 int pfx_rcd_safi;
10656 json_object *json = NULL;
10657 json_object *json_peer = NULL;
10658 json_object *json_peers = NULL;
10659 struct peer_af *paf;
10660 struct bgp_filter *filter;
10661 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10662 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10663 bool show_established =
10664 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10665 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10666 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10667
10668 /* labeled-unicast routes are installed in the unicast table so in order
10669 * to
10670 * display the correct PfxRcd value we must look at SAFI_UNICAST
10671 */
10672
10673 if (safi == SAFI_LABELED_UNICAST)
10674 pfx_rcd_safi = SAFI_UNICAST;
10675 else
10676 pfx_rcd_safi = safi;
10677
10678 if (use_json) {
10679 json = json_object_new_object();
10680 json_peers = json_object_new_object();
10681 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10682 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10683 as_type, as)) {
10684 filtered_count++;
10685 count++;
10686 continue;
10687 }
10688
10689 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10690 continue;
10691
10692 if (peer->afc[afi][safi]) {
10693 /* See if we have at least a single failed peer */
10694 if (bgp_has_peer_failed(peer, afi, safi))
10695 failed_count++;
10696 count++;
10697 }
10698 if (peer_dynamic_neighbor(peer))
10699 dn_count++;
10700 }
10701
10702 } else {
10703 /* Loop over all neighbors that will be displayed to determine
10704 * how many
10705 * characters are needed for the Neighbor column
10706 */
10707 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10708 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10709 as_type, as)) {
10710 filtered_count++;
10711 count++;
10712 continue;
10713 }
10714
10715 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10716 continue;
10717
10718 if (peer->afc[afi][safi]) {
10719 memset(dn_flag, '\0', sizeof(dn_flag));
10720 if (peer_dynamic_neighbor(peer))
10721 dn_flag[0] = '*';
10722
10723 if (peer->hostname
10724 && CHECK_FLAG(bgp->flags,
10725 BGP_FLAG_SHOW_HOSTNAME))
10726 snprintf(neighbor_buf,
10727 sizeof(neighbor_buf),
10728 "%s%s(%s) ", dn_flag,
10729 peer->hostname, peer->host);
10730 else
10731 snprintf(neighbor_buf,
10732 sizeof(neighbor_buf), "%s%s ",
10733 dn_flag, peer->host);
10734
10735 len = strlen(neighbor_buf);
10736
10737 if (len > max_neighbor_width)
10738 max_neighbor_width = len;
10739
10740 /* See if we have at least a single failed peer */
10741 if (bgp_has_peer_failed(peer, afi, safi))
10742 failed_count++;
10743 count++;
10744 }
10745 }
10746
10747 /* Originally we displayed the Neighbor column as 16
10748 * characters wide so make that the default
10749 */
10750 if (max_neighbor_width < neighbor_col_default_width)
10751 max_neighbor_width = neighbor_col_default_width;
10752 }
10753
10754 if (show_failed && !failed_count) {
10755 if (use_json) {
10756 json_object_int_add(json, "failedPeersCount", 0);
10757 json_object_int_add(json, "dynamicPeers", dn_count);
10758 json_object_int_add(json, "totalPeers", count);
10759
10760 vty_json(vty, json);
10761 } else {
10762 vty_out(vty, "%% No failed BGP neighbors found\n");
10763 }
10764 return CMD_SUCCESS;
10765 }
10766
10767 count = 0; /* Reset the value as its used again */
10768 filtered_count = 0;
10769 dn_count = 0;
10770 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10771 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10772 continue;
10773
10774 if (!peer->afc[afi][safi])
10775 continue;
10776
10777 if (!count) {
10778 unsigned long ents;
10779 char memstrbuf[MTYPE_MEMSTR_LEN];
10780 int64_t vrf_id_ui;
10781
10782 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10783 ? -1
10784 : (int64_t)bgp->vrf_id;
10785
10786 /* Usage summary and header */
10787 if (use_json) {
10788 json_object_string_addf(json, "routerId",
10789 "%pI4",
10790 &bgp->router_id);
10791 json_object_int_add(json, "as", bgp->as);
10792 json_object_int_add(json, "vrfId", vrf_id_ui);
10793 json_object_string_add(
10794 json, "vrfName",
10795 (bgp->inst_type
10796 == BGP_INSTANCE_TYPE_DEFAULT)
10797 ? VRF_DEFAULT_NAME
10798 : bgp->name);
10799 } else {
10800 vty_out(vty,
10801 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10802 &bgp->router_id, bgp->as,
10803 bgp->vrf_id == VRF_UNKNOWN
10804 ? -1
10805 : (int)bgp->vrf_id);
10806 vty_out(vty, "\n");
10807 }
10808
10809 if (bgp_update_delay_configured(bgp)) {
10810 if (use_json) {
10811 json_object_int_add(
10812 json, "updateDelayLimit",
10813 bgp->v_update_delay);
10814
10815 if (bgp->v_update_delay
10816 != bgp->v_establish_wait)
10817 json_object_int_add(
10818 json,
10819 "updateDelayEstablishWait",
10820 bgp->v_establish_wait);
10821
10822 if (bgp_update_delay_active(bgp)) {
10823 json_object_string_add(
10824 json,
10825 "updateDelayFirstNeighbor",
10826 bgp->update_delay_begin_time);
10827 json_object_boolean_true_add(
10828 json,
10829 "updateDelayInProgress");
10830 } else {
10831 if (bgp->update_delay_over) {
10832 json_object_string_add(
10833 json,
10834 "updateDelayFirstNeighbor",
10835 bgp->update_delay_begin_time);
10836 json_object_string_add(
10837 json,
10838 "updateDelayBestpathResumed",
10839 bgp->update_delay_end_time);
10840 json_object_string_add(
10841 json,
10842 "updateDelayZebraUpdateResume",
10843 bgp->update_delay_zebra_resume_time);
10844 json_object_string_add(
10845 json,
10846 "updateDelayPeerUpdateResume",
10847 bgp->update_delay_peers_resume_time);
10848 }
10849 }
10850 } else {
10851 vty_out(vty,
10852 "Read-only mode update-delay limit: %d seconds\n",
10853 bgp->v_update_delay);
10854 if (bgp->v_update_delay
10855 != bgp->v_establish_wait)
10856 vty_out(vty,
10857 " Establish wait: %d seconds\n",
10858 bgp->v_establish_wait);
10859
10860 if (bgp_update_delay_active(bgp)) {
10861 vty_out(vty,
10862 " First neighbor established: %s\n",
10863 bgp->update_delay_begin_time);
10864 vty_out(vty,
10865 " Delay in progress\n");
10866 } else {
10867 if (bgp->update_delay_over) {
10868 vty_out(vty,
10869 " First neighbor established: %s\n",
10870 bgp->update_delay_begin_time);
10871 vty_out(vty,
10872 " Best-paths resumed: %s\n",
10873 bgp->update_delay_end_time);
10874 vty_out(vty,
10875 " zebra update resumed: %s\n",
10876 bgp->update_delay_zebra_resume_time);
10877 vty_out(vty,
10878 " peers update resumed: %s\n",
10879 bgp->update_delay_peers_resume_time);
10880 }
10881 }
10882 }
10883 }
10884
10885 if (use_json) {
10886 if (bgp_maxmed_onstartup_configured(bgp)
10887 && bgp->maxmed_active)
10888 json_object_boolean_true_add(
10889 json, "maxMedOnStartup");
10890 if (bgp->v_maxmed_admin)
10891 json_object_boolean_true_add(
10892 json, "maxMedAdministrative");
10893
10894 json_object_int_add(
10895 json, "tableVersion",
10896 bgp_table_version(bgp->rib[afi][safi]));
10897
10898 ents = bgp_table_count(bgp->rib[afi][safi]);
10899 json_object_int_add(json, "ribCount", ents);
10900 json_object_int_add(
10901 json, "ribMemory",
10902 ents * sizeof(struct bgp_dest));
10903
10904 ents = bgp->af_peer_count[afi][safi];
10905 json_object_int_add(json, "peerCount", ents);
10906 json_object_int_add(json, "peerMemory",
10907 ents * sizeof(struct peer));
10908
10909 if ((ents = listcount(bgp->group))) {
10910 json_object_int_add(
10911 json, "peerGroupCount", ents);
10912 json_object_int_add(
10913 json, "peerGroupMemory",
10914 ents * sizeof(struct
10915 peer_group));
10916 }
10917
10918 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10919 BGP_CONFIG_DAMPENING))
10920 json_object_boolean_true_add(
10921 json, "dampeningEnabled");
10922 } else {
10923 if (!show_terse) {
10924 if (bgp_maxmed_onstartup_configured(bgp)
10925 && bgp->maxmed_active)
10926 vty_out(vty,
10927 "Max-med on-startup active\n");
10928 if (bgp->v_maxmed_admin)
10929 vty_out(vty,
10930 "Max-med administrative active\n");
10931
10932 vty_out(vty,
10933 "BGP table version %" PRIu64
10934 "\n",
10935 bgp_table_version(
10936 bgp->rib[afi][safi]));
10937
10938 ents = bgp_table_count(
10939 bgp->rib[afi][safi]);
10940 vty_out(vty,
10941 "RIB entries %ld, using %s of memory\n",
10942 ents,
10943 mtype_memstr(
10944 memstrbuf,
10945 sizeof(memstrbuf),
10946 ents
10947 * sizeof(
10948 struct
10949 bgp_dest)));
10950
10951 /* Peer related usage */
10952 ents = bgp->af_peer_count[afi][safi];
10953 vty_out(vty,
10954 "Peers %ld, using %s of memory\n",
10955 ents,
10956 mtype_memstr(
10957 memstrbuf,
10958 sizeof(memstrbuf),
10959 ents
10960 * sizeof(
10961 struct
10962 peer)));
10963
10964 if ((ents = listcount(bgp->group)))
10965 vty_out(vty,
10966 "Peer groups %ld, using %s of memory\n",
10967 ents,
10968 mtype_memstr(
10969 memstrbuf,
10970 sizeof(memstrbuf),
10971 ents
10972 * sizeof(
10973 struct
10974 peer_group)));
10975
10976 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10977 BGP_CONFIG_DAMPENING))
10978 vty_out(vty,
10979 "Dampening enabled.\n");
10980 }
10981 if (show_failed) {
10982 vty_out(vty, "\n");
10983
10984 /* Subtract 8 here because 'Neighbor' is
10985 * 8 characters */
10986 vty_out(vty, "Neighbor");
10987 vty_out(vty, "%*s",
10988 max_neighbor_width - 8, " ");
10989 vty_out(vty,
10990 BGP_SHOW_SUMMARY_HEADER_FAILED);
10991 }
10992 }
10993 }
10994
10995 paf = peer_af_find(peer, afi, safi);
10996 filter = &peer->filter[afi][safi];
10997
10998 count++;
10999 /* Works for both failed & successful cases */
11000 if (peer_dynamic_neighbor(peer))
11001 dn_count++;
11002
11003 if (use_json) {
11004 json_peer = NULL;
11005 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11006 as_type, as)) {
11007 filtered_count++;
11008 continue;
11009 }
11010 if (show_failed &&
11011 bgp_has_peer_failed(peer, afi, safi)) {
11012 json_peer = json_object_new_object();
11013 bgp_show_failed_summary(vty, bgp, peer,
11014 json_peer, 0, use_json);
11015 } else if (!show_failed) {
11016 if (show_established
11017 && bgp_has_peer_failed(peer, afi, safi)) {
11018 filtered_count++;
11019 continue;
11020 }
11021
11022 json_peer = json_object_new_object();
11023 if (peer_dynamic_neighbor(peer)) {
11024 json_object_boolean_true_add(json_peer,
11025 "dynamicPeer");
11026 }
11027
11028 if (peer->hostname)
11029 json_object_string_add(json_peer, "hostname",
11030 peer->hostname);
11031
11032 if (peer->domainname)
11033 json_object_string_add(json_peer, "domainname",
11034 peer->domainname);
11035
11036 json_object_int_add(json_peer, "remoteAs", peer->as);
11037 json_object_int_add(
11038 json_peer, "localAs",
11039 peer->change_local_as
11040 ? peer->change_local_as
11041 : peer->local_as);
11042 json_object_int_add(json_peer, "version", 4);
11043 json_object_int_add(json_peer, "msgRcvd",
11044 PEER_TOTAL_RX(peer));
11045 json_object_int_add(json_peer, "msgSent",
11046 PEER_TOTAL_TX(peer));
11047
11048 atomic_size_t outq_count, inq_count;
11049 outq_count = atomic_load_explicit(
11050 &peer->obuf->count,
11051 memory_order_relaxed);
11052 inq_count = atomic_load_explicit(
11053 &peer->ibuf->count,
11054 memory_order_relaxed);
11055
11056 json_object_int_add(json_peer, "tableVersion",
11057 peer->version[afi][safi]);
11058 json_object_int_add(json_peer, "outq",
11059 outq_count);
11060 json_object_int_add(json_peer, "inq",
11061 inq_count);
11062 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11063 use_json, json_peer);
11064
11065 json_object_int_add(json_peer, "pfxRcd",
11066 peer->pcount[afi][pfx_rcd_safi]);
11067
11068 if (paf && PAF_SUBGRP(paf))
11069 json_object_int_add(
11070 json_peer, "pfxSnt",
11071 (PAF_SUBGRP(paf))->scount);
11072 else
11073 json_object_int_add(json_peer, "pfxSnt",
11074 0);
11075
11076 /* BGP FSM state */
11077 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11078 || CHECK_FLAG(peer->bgp->flags,
11079 BGP_FLAG_SHUTDOWN))
11080 json_object_string_add(json_peer,
11081 "state",
11082 "Idle (Admin)");
11083 else if (peer->afc_recv[afi][safi])
11084 json_object_string_add(
11085 json_peer, "state",
11086 lookup_msg(bgp_status_msg,
11087 peer->status, NULL));
11088 else if (CHECK_FLAG(
11089 peer->sflags,
11090 PEER_STATUS_PREFIX_OVERFLOW))
11091 json_object_string_add(json_peer,
11092 "state",
11093 "Idle (PfxCt)");
11094 else
11095 json_object_string_add(
11096 json_peer, "state",
11097 lookup_msg(bgp_status_msg,
11098 peer->status, NULL));
11099
11100 /* BGP peer state */
11101 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11102 || CHECK_FLAG(peer->bgp->flags,
11103 BGP_FLAG_SHUTDOWN))
11104 json_object_string_add(json_peer,
11105 "peerState",
11106 "Admin");
11107 else if (CHECK_FLAG(
11108 peer->sflags,
11109 PEER_STATUS_PREFIX_OVERFLOW))
11110 json_object_string_add(json_peer,
11111 "peerState",
11112 "PfxCt");
11113 else if (CHECK_FLAG(peer->flags,
11114 PEER_FLAG_PASSIVE))
11115 json_object_string_add(json_peer,
11116 "peerState",
11117 "Passive");
11118 else if (CHECK_FLAG(peer->sflags,
11119 PEER_STATUS_NSF_WAIT))
11120 json_object_string_add(json_peer,
11121 "peerState",
11122 "NSF passive");
11123 else if (CHECK_FLAG(
11124 peer->bgp->flags,
11125 BGP_FLAG_EBGP_REQUIRES_POLICY)
11126 && (!bgp_inbound_policy_exists(peer,
11127 filter)
11128 || !bgp_outbound_policy_exists(
11129 peer, filter)))
11130 json_object_string_add(json_peer,
11131 "peerState",
11132 "Policy");
11133 else
11134 json_object_string_add(
11135 json_peer, "peerState", "OK");
11136
11137 json_object_int_add(json_peer, "connectionsEstablished",
11138 peer->established);
11139 json_object_int_add(json_peer, "connectionsDropped",
11140 peer->dropped);
11141 if (peer->desc)
11142 json_object_string_add(
11143 json_peer, "desc", peer->desc);
11144 }
11145 /* Avoid creating empty peer dicts in JSON */
11146 if (json_peer == NULL)
11147 continue;
11148
11149 if (peer->conf_if)
11150 json_object_string_add(json_peer, "idType",
11151 "interface");
11152 else if (peer->su.sa.sa_family == AF_INET)
11153 json_object_string_add(json_peer, "idType",
11154 "ipv4");
11155 else if (peer->su.sa.sa_family == AF_INET6)
11156 json_object_string_add(json_peer, "idType",
11157 "ipv6");
11158 json_object_object_add(json_peers, peer->host,
11159 json_peer);
11160 } else {
11161 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11162 as_type, as)) {
11163 filtered_count++;
11164 continue;
11165 }
11166 if (show_failed &&
11167 bgp_has_peer_failed(peer, afi, safi)) {
11168 bgp_show_failed_summary(vty, bgp, peer, NULL,
11169 max_neighbor_width,
11170 use_json);
11171 } else if (!show_failed) {
11172 if (show_established
11173 && bgp_has_peer_failed(peer, afi, safi)) {
11174 filtered_count++;
11175 continue;
11176 }
11177
11178 if ((count - filtered_count) == 1) {
11179 /* display headline before the first
11180 * neighbor line */
11181 vty_out(vty, "\n");
11182
11183 /* Subtract 8 here because 'Neighbor' is
11184 * 8 characters */
11185 vty_out(vty, "Neighbor");
11186 vty_out(vty, "%*s",
11187 max_neighbor_width - 8, " ");
11188 vty_out(vty,
11189 show_wide
11190 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11191 : BGP_SHOW_SUMMARY_HEADER_ALL);
11192 }
11193
11194 memset(dn_flag, '\0', sizeof(dn_flag));
11195 if (peer_dynamic_neighbor(peer)) {
11196 dn_flag[0] = '*';
11197 }
11198
11199 if (peer->hostname
11200 && CHECK_FLAG(bgp->flags,
11201 BGP_FLAG_SHOW_HOSTNAME))
11202 len = vty_out(vty, "%s%s(%s)", dn_flag,
11203 peer->hostname,
11204 peer->host);
11205 else
11206 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11207
11208 /* pad the neighbor column with spaces */
11209 if (len < max_neighbor_width)
11210 vty_out(vty, "%*s", max_neighbor_width - len,
11211 " ");
11212
11213 atomic_size_t outq_count, inq_count;
11214 outq_count = atomic_load_explicit(
11215 &peer->obuf->count,
11216 memory_order_relaxed);
11217 inq_count = atomic_load_explicit(
11218 &peer->ibuf->count,
11219 memory_order_relaxed);
11220
11221 if (show_wide)
11222 vty_out(vty,
11223 "4 %10u %10u %9u %9u %8" PRIu64
11224 " %4zu %4zu %8s",
11225 peer->as,
11226 peer->change_local_as
11227 ? peer->change_local_as
11228 : peer->local_as,
11229 PEER_TOTAL_RX(peer),
11230 PEER_TOTAL_TX(peer),
11231 peer->version[afi][safi],
11232 inq_count, outq_count,
11233 peer_uptime(peer->uptime,
11234 timebuf,
11235 BGP_UPTIME_LEN, 0,
11236 NULL));
11237 else
11238 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11239 " %4zu %4zu %8s",
11240 peer->as, PEER_TOTAL_RX(peer),
11241 PEER_TOTAL_TX(peer),
11242 peer->version[afi][safi],
11243 inq_count, outq_count,
11244 peer_uptime(peer->uptime,
11245 timebuf,
11246 BGP_UPTIME_LEN, 0,
11247 NULL));
11248
11249 if (peer_established(peer)) {
11250 if (peer->afc_recv[afi][safi]) {
11251 if (CHECK_FLAG(
11252 bgp->flags,
11253 BGP_FLAG_EBGP_REQUIRES_POLICY)
11254 && !bgp_inbound_policy_exists(
11255 peer, filter))
11256 vty_out(vty, " %12s",
11257 "(Policy)");
11258 else
11259 vty_out(vty,
11260 " %12u",
11261 peer->pcount
11262 [afi]
11263 [pfx_rcd_safi]);
11264 } else {
11265 vty_out(vty, " NoNeg");
11266 }
11267
11268 if (paf && PAF_SUBGRP(paf)) {
11269 if (CHECK_FLAG(
11270 bgp->flags,
11271 BGP_FLAG_EBGP_REQUIRES_POLICY)
11272 && !bgp_outbound_policy_exists(
11273 peer, filter))
11274 vty_out(vty, " %8s",
11275 "(Policy)");
11276 else
11277 vty_out(vty,
11278 " %8u",
11279 (PAF_SUBGRP(
11280 paf))
11281 ->scount);
11282 } else {
11283 vty_out(vty, " NoNeg");
11284 }
11285 } else {
11286 if (CHECK_FLAG(peer->flags,
11287 PEER_FLAG_SHUTDOWN)
11288 || CHECK_FLAG(peer->bgp->flags,
11289 BGP_FLAG_SHUTDOWN))
11290 vty_out(vty, " Idle (Admin)");
11291 else if (CHECK_FLAG(
11292 peer->sflags,
11293 PEER_STATUS_PREFIX_OVERFLOW))
11294 vty_out(vty, " Idle (PfxCt)");
11295 else
11296 vty_out(vty, " %12s",
11297 lookup_msg(bgp_status_msg,
11298 peer->status, NULL));
11299
11300 vty_out(vty, " %8u", 0);
11301 }
11302 /* Make sure `Desc` column is the lastest in
11303 * the output.
11304 */
11305 if (peer->desc)
11306 vty_out(vty, " %s",
11307 bgp_peer_description_stripped(
11308 peer->desc,
11309 show_wide ? 64 : 20));
11310 else
11311 vty_out(vty, " N/A");
11312 vty_out(vty, "\n");
11313 }
11314
11315 }
11316 }
11317
11318 if (use_json) {
11319 json_object_object_add(json, "peers", json_peers);
11320 json_object_int_add(json, "failedPeers", failed_count);
11321 json_object_int_add(json, "displayedPeers",
11322 count - filtered_count);
11323 json_object_int_add(json, "totalPeers", count);
11324 json_object_int_add(json, "dynamicPeers", dn_count);
11325
11326 if (!show_failed)
11327 bgp_show_bestpath_json(bgp, json);
11328
11329 vty_json(vty, json);
11330 } else {
11331 if (count) {
11332 if (filtered_count == count)
11333 vty_out(vty, "\n%% No matching neighbor\n");
11334 else {
11335 if (show_failed)
11336 vty_out(vty, "\nDisplayed neighbors %d",
11337 failed_count);
11338 else if (as_type != AS_UNSPECIFIED || as
11339 || fpeer || show_established)
11340 vty_out(vty, "\nDisplayed neighbors %d",
11341 count - filtered_count);
11342
11343 vty_out(vty, "\nTotal number of neighbors %d\n",
11344 count);
11345 }
11346 } else {
11347 vty_out(vty, "No %s neighbor is configured\n",
11348 get_afi_safi_str(afi, safi, false));
11349 }
11350
11351 if (dn_count) {
11352 vty_out(vty, "* - dynamic neighbor\n");
11353 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11354 dn_count, bgp->dynamic_neighbors_limit);
11355 }
11356 }
11357
11358 return CMD_SUCCESS;
11359 }
11360
11361 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11362 int safi, struct peer *fpeer, int as_type,
11363 as_t as, uint16_t show_flags)
11364 {
11365 int is_first = 1;
11366 int afi_wildcard = (afi == AFI_MAX);
11367 int safi_wildcard = (safi == SAFI_MAX);
11368 int is_wildcard = (afi_wildcard || safi_wildcard);
11369 bool nbr_output = false;
11370 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11371
11372 if (use_json && is_wildcard)
11373 vty_out(vty, "{\n");
11374 if (afi_wildcard)
11375 afi = 1; /* AFI_IP */
11376 while (afi < AFI_MAX) {
11377 if (safi_wildcard)
11378 safi = 1; /* SAFI_UNICAST */
11379 while (safi < SAFI_MAX) {
11380 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11381 nbr_output = true;
11382
11383 if (is_wildcard) {
11384 /*
11385 * So limit output to those afi/safi
11386 * pairs that
11387 * actualy have something interesting in
11388 * them
11389 */
11390 if (use_json) {
11391 if (!is_first)
11392 vty_out(vty, ",\n");
11393 else
11394 is_first = 0;
11395
11396 vty_out(vty, "\"%s\":",
11397 get_afi_safi_str(afi,
11398 safi,
11399 true));
11400 } else {
11401 vty_out(vty,
11402 "\n%s Summary (%s):\n",
11403 get_afi_safi_str(afi,
11404 safi,
11405 false),
11406 bgp->name_pretty);
11407 }
11408 }
11409 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11410 as_type, as, show_flags);
11411 }
11412 safi++;
11413 if (!safi_wildcard)
11414 safi = SAFI_MAX;
11415 }
11416 afi++;
11417 if (!afi_wildcard)
11418 afi = AFI_MAX;
11419 }
11420
11421 if (use_json && is_wildcard)
11422 vty_out(vty, "}\n");
11423 else if (!nbr_output) {
11424 if (use_json)
11425 vty_out(vty, "{}\n");
11426 else
11427 vty_out(vty, "%% No BGP neighbors found in %s\n",
11428 bgp->name_pretty);
11429 }
11430 }
11431
11432 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11433 safi_t safi,
11434 const char *neighbor,
11435 int as_type, as_t as,
11436 uint16_t show_flags)
11437 {
11438 struct listnode *node, *nnode;
11439 struct bgp *bgp;
11440 struct peer *fpeer = NULL;
11441 int is_first = 1;
11442 bool nbr_output = false;
11443 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11444
11445 if (use_json)
11446 vty_out(vty, "{\n");
11447
11448 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11449 nbr_output = true;
11450 if (use_json) {
11451 if (!is_first)
11452 vty_out(vty, ",\n");
11453 else
11454 is_first = 0;
11455
11456 vty_out(vty, "\"%s\":",
11457 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11458 ? VRF_DEFAULT_NAME
11459 : bgp->name);
11460 }
11461 if (neighbor) {
11462 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11463 use_json);
11464 if (!fpeer)
11465 continue;
11466 }
11467 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11468 as, show_flags);
11469 }
11470
11471 if (use_json)
11472 vty_out(vty, "}\n");
11473 else if (!nbr_output)
11474 vty_out(vty, "%% BGP instance not found\n");
11475 }
11476
11477 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11478 safi_t safi, const char *neighbor, int as_type,
11479 as_t as, uint16_t show_flags)
11480 {
11481 struct bgp *bgp;
11482 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11483 struct peer *fpeer = NULL;
11484
11485 if (name) {
11486 if (strmatch(name, "all")) {
11487 bgp_show_all_instances_summary_vty(vty, afi, safi,
11488 neighbor, as_type,
11489 as, show_flags);
11490 return CMD_SUCCESS;
11491 } else {
11492 bgp = bgp_lookup_by_name(name);
11493
11494 if (!bgp) {
11495 if (use_json)
11496 vty_out(vty, "{}\n");
11497 else
11498 vty_out(vty,
11499 "%% BGP instance not found\n");
11500 return CMD_WARNING;
11501 }
11502
11503 if (neighbor) {
11504 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11505 use_json);
11506 if (!fpeer)
11507 return CMD_WARNING;
11508 }
11509 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11510 as_type, as, show_flags);
11511 return CMD_SUCCESS;
11512 }
11513 }
11514
11515 bgp = bgp_get_default();
11516
11517 if (bgp) {
11518 if (neighbor) {
11519 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11520 use_json);
11521 if (!fpeer)
11522 return CMD_WARNING;
11523 }
11524 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11525 as, show_flags);
11526 } else {
11527 if (use_json)
11528 vty_out(vty, "{}\n");
11529 else
11530 vty_out(vty, "%% BGP instance not found\n");
11531 return CMD_WARNING;
11532 }
11533
11534 return CMD_SUCCESS;
11535 }
11536
11537 /* `show [ip] bgp summary' commands. */
11538 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11539 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11540 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11541 "]] [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]",
11542 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11543 BGP_SAFI_WITH_LABEL_HELP_STR
11544 "Display the entries for all address families\n"
11545 "Summary of BGP neighbor status\n"
11546 "Show only sessions in Established state\n"
11547 "Show only sessions not in Established state\n"
11548 "Show only the specified neighbor session\n"
11549 "Neighbor to display information about\n"
11550 "Neighbor to display information about\n"
11551 "Neighbor on BGP configured interface\n"
11552 "Show only the specified remote AS sessions\n"
11553 "AS number\n"
11554 "Internal (iBGP) AS sessions\n"
11555 "External (eBGP) AS sessions\n"
11556 "Shorten the information on BGP instances\n"
11557 "Increase table width for longer output\n" JSON_STR)
11558 {
11559 char *vrf = NULL;
11560 afi_t afi = AFI_MAX;
11561 safi_t safi = SAFI_MAX;
11562 as_t as = 0; /* 0 means AS filter not set */
11563 int as_type = AS_UNSPECIFIED;
11564 uint16_t show_flags = 0;
11565
11566 int idx = 0;
11567
11568 /* show [ip] bgp */
11569 if (!all && argv_find(argv, argc, "ip", &idx))
11570 afi = AFI_IP;
11571 /* [<vrf> VIEWVRFNAME] */
11572 if (argv_find(argv, argc, "vrf", &idx)) {
11573 vrf = argv[idx + 1]->arg;
11574 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11575 vrf = NULL;
11576 } else if (argv_find(argv, argc, "view", &idx))
11577 /* [<view> VIEWVRFNAME] */
11578 vrf = argv[idx + 1]->arg;
11579 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11580 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11581 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11582 }
11583
11584 if (argv_find(argv, argc, "failed", &idx))
11585 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11586
11587 if (argv_find(argv, argc, "established", &idx))
11588 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11589
11590 if (argv_find(argv, argc, "remote-as", &idx)) {
11591 if (argv[idx + 1]->arg[0] == 'i')
11592 as_type = AS_INTERNAL;
11593 else if (argv[idx + 1]->arg[0] == 'e')
11594 as_type = AS_EXTERNAL;
11595 else
11596 as = (as_t)atoi(argv[idx + 1]->arg);
11597 }
11598
11599 if (argv_find(argv, argc, "terse", &idx))
11600 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11601
11602 if (argv_find(argv, argc, "wide", &idx))
11603 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11604
11605 if (argv_find(argv, argc, "json", &idx))
11606 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11607
11608 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11609 show_flags);
11610 }
11611
11612 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11613 {
11614 if (for_json)
11615 return get_afi_safi_json_str(afi, safi);
11616 else
11617 return get_afi_safi_vty_str(afi, safi);
11618 }
11619
11620
11621 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11622 afi_t afi, safi_t safi,
11623 uint16_t adv_smcap, uint16_t adv_rmcap,
11624 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11625 bool use_json, json_object *json_pref)
11626 {
11627 /* Send-Mode */
11628 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11629 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11630 if (use_json) {
11631 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11632 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11633 json_object_string_add(json_pref, "sendMode",
11634 "advertisedAndReceived");
11635 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11636 json_object_string_add(json_pref, "sendMode",
11637 "advertised");
11638 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11639 json_object_string_add(json_pref, "sendMode",
11640 "received");
11641 } else {
11642 vty_out(vty, " Send-mode: ");
11643 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11644 vty_out(vty, "advertised");
11645 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11646 vty_out(vty, "%sreceived",
11647 CHECK_FLAG(p->af_cap[afi][safi],
11648 adv_smcap)
11649 ? ", "
11650 : "");
11651 vty_out(vty, "\n");
11652 }
11653 }
11654
11655 /* Receive-Mode */
11656 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11657 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11658 if (use_json) {
11659 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11660 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11661 json_object_string_add(json_pref, "recvMode",
11662 "advertisedAndReceived");
11663 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11664 json_object_string_add(json_pref, "recvMode",
11665 "advertised");
11666 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11667 json_object_string_add(json_pref, "recvMode",
11668 "received");
11669 } else {
11670 vty_out(vty, " Receive-mode: ");
11671 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11672 vty_out(vty, "advertised");
11673 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11674 vty_out(vty, "%sreceived",
11675 CHECK_FLAG(p->af_cap[afi][safi],
11676 adv_rmcap)
11677 ? ", "
11678 : "");
11679 vty_out(vty, "\n");
11680 }
11681 }
11682 }
11683
11684 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11685 struct peer *p,
11686 bool use_json,
11687 json_object *json)
11688 {
11689 bool rbit = false;
11690 bool nbit = false;
11691
11692 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11693 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11694 && (peer_established(p))) {
11695 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11696 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11697 }
11698
11699 if (use_json) {
11700 json_object_boolean_add(json, "rBit", rbit);
11701 json_object_boolean_add(json, "nBit", nbit);
11702 } else {
11703 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11704 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11705 }
11706 }
11707
11708 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11709 struct peer *peer,
11710 bool use_json,
11711 json_object *json)
11712 {
11713 const char *mode = "NotApplicable";
11714
11715 if (!use_json)
11716 vty_out(vty, "\n Remote GR Mode: ");
11717
11718 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11719 && (peer_established(peer))) {
11720
11721 if ((peer->nsf_af_count == 0)
11722 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11723
11724 mode = "Disable";
11725
11726 } else if (peer->nsf_af_count == 0
11727 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11728
11729 mode = "Helper";
11730
11731 } else if (peer->nsf_af_count != 0
11732 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11733
11734 mode = "Restart";
11735 }
11736 }
11737
11738 if (use_json) {
11739 json_object_string_add(json, "remoteGrMode", mode);
11740 } else
11741 vty_out(vty, mode, "\n");
11742 }
11743
11744 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11745 struct peer *p,
11746 bool use_json,
11747 json_object *json)
11748 {
11749 const char *mode = "Invalid";
11750
11751 if (!use_json)
11752 vty_out(vty, " Local GR Mode: ");
11753
11754 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11755 mode = "Helper";
11756 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11757 mode = "Restart";
11758 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11759 mode = "Disable";
11760 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11761 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11762 mode = "Helper*";
11763 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11764 mode = "Restart*";
11765 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11766 mode = "Disable*";
11767 else
11768 mode = "Invalid*";
11769 }
11770
11771 if (use_json) {
11772 json_object_string_add(json, "localGrMode", mode);
11773 } else {
11774 vty_out(vty, mode, "\n");
11775 }
11776 }
11777
11778 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11779 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11780 {
11781 afi_t afi;
11782 safi_t safi;
11783 json_object *json_afi_safi = NULL;
11784 json_object *json_timer = NULL;
11785 json_object *json_endofrib_status = NULL;
11786 bool eor_flag = false;
11787
11788 FOREACH_AFI_SAFI_NSF (afi, safi) {
11789 if (!peer->afc[afi][safi])
11790 continue;
11791
11792 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11793 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11794 continue;
11795
11796 if (use_json) {
11797 json_afi_safi = json_object_new_object();
11798 json_endofrib_status = json_object_new_object();
11799 json_timer = json_object_new_object();
11800 }
11801
11802 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11803 eor_flag = true;
11804 else
11805 eor_flag = false;
11806
11807 if (!use_json) {
11808 vty_out(vty, " %s:\n",
11809 get_afi_safi_str(afi, safi, false));
11810
11811 vty_out(vty, " F bit: ");
11812 }
11813
11814 if (peer->nsf[afi][safi] &&
11815 CHECK_FLAG(peer->af_cap[afi][safi],
11816 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11817
11818 if (use_json) {
11819 json_object_boolean_true_add(json_afi_safi,
11820 "fBit");
11821 } else
11822 vty_out(vty, "True\n");
11823 } else {
11824 if (use_json)
11825 json_object_boolean_false_add(json_afi_safi,
11826 "fBit");
11827 else
11828 vty_out(vty, "False\n");
11829 }
11830
11831 if (!use_json)
11832 vty_out(vty, " End-of-RIB sent: ");
11833
11834 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11835 PEER_STATUS_EOR_SEND)) {
11836 if (use_json) {
11837 json_object_boolean_true_add(
11838 json_endofrib_status, "endOfRibSend");
11839
11840 PRINT_EOR_JSON(eor_flag);
11841 } else {
11842 vty_out(vty, "Yes\n");
11843 vty_out(vty,
11844 " End-of-RIB sent after update: ");
11845
11846 PRINT_EOR(eor_flag);
11847 }
11848 } else {
11849 if (use_json) {
11850 json_object_boolean_false_add(
11851 json_endofrib_status, "endOfRibSend");
11852 json_object_boolean_false_add(
11853 json_endofrib_status,
11854 "endOfRibSentAfterUpdate");
11855 } else {
11856 vty_out(vty, "No\n");
11857 vty_out(vty,
11858 " End-of-RIB sent after update: ");
11859 vty_out(vty, "No\n");
11860 }
11861 }
11862
11863 if (!use_json)
11864 vty_out(vty, " End-of-RIB received: ");
11865
11866 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11867 PEER_STATUS_EOR_RECEIVED)) {
11868 if (use_json)
11869 json_object_boolean_true_add(
11870 json_endofrib_status, "endOfRibRecv");
11871 else
11872 vty_out(vty, "Yes\n");
11873 } else {
11874 if (use_json)
11875 json_object_boolean_false_add(
11876 json_endofrib_status, "endOfRibRecv");
11877 else
11878 vty_out(vty, "No\n");
11879 }
11880
11881 if (use_json) {
11882 json_object_int_add(json_timer, "stalePathTimer",
11883 peer->bgp->stalepath_time);
11884
11885 if (peer->t_gr_stale != NULL) {
11886 json_object_int_add(json_timer,
11887 "stalePathTimerRemaining",
11888 thread_timer_remain_second(
11889 peer->t_gr_stale));
11890 }
11891
11892 /* Display Configured Selection
11893 * Deferral only when when
11894 * Gr mode is enabled.
11895 */
11896 if (CHECK_FLAG(peer->flags,
11897 PEER_FLAG_GRACEFUL_RESTART)) {
11898 json_object_int_add(json_timer,
11899 "selectionDeferralTimer",
11900 peer->bgp->stalepath_time);
11901 }
11902
11903 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11904 NULL) {
11905
11906 json_object_int_add(
11907 json_timer,
11908 "selectionDeferralTimerRemaining",
11909 thread_timer_remain_second(
11910 peer->bgp->gr_info[afi][safi]
11911 .t_select_deferral));
11912 }
11913 } else {
11914 vty_out(vty, " Timers:\n");
11915 vty_out(vty,
11916 " Configured Stale Path Time(sec): %u\n",
11917 peer->bgp->stalepath_time);
11918
11919 if (peer->t_gr_stale != NULL)
11920 vty_out(vty,
11921 " Stale Path Remaining(sec): %ld\n",
11922 thread_timer_remain_second(
11923 peer->t_gr_stale));
11924 /* Display Configured Selection
11925 * Deferral only when when
11926 * Gr mode is enabled.
11927 */
11928 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11929 vty_out(vty,
11930 " Configured Selection Deferral Time(sec): %u\n",
11931 peer->bgp->select_defer_time);
11932
11933 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11934 NULL)
11935 vty_out(vty,
11936 " Selection Deferral Time Remaining(sec): %ld\n",
11937 thread_timer_remain_second(
11938 peer->bgp->gr_info[afi][safi]
11939 .t_select_deferral));
11940 }
11941 if (use_json) {
11942 json_object_object_add(json_afi_safi, "endOfRibStatus",
11943 json_endofrib_status);
11944 json_object_object_add(json_afi_safi, "timers",
11945 json_timer);
11946 json_object_object_add(
11947 json, get_afi_safi_str(afi, safi, true),
11948 json_afi_safi);
11949 }
11950 }
11951 }
11952
11953 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11954 struct peer *p,
11955 bool use_json,
11956 json_object *json)
11957 {
11958 if (use_json) {
11959 json_object *json_timer = NULL;
11960
11961 json_timer = json_object_new_object();
11962
11963 json_object_int_add(json_timer, "configuredRestartTimer",
11964 p->bgp->restart_time);
11965
11966 json_object_int_add(json_timer, "receivedRestartTimer",
11967 p->v_gr_restart);
11968
11969 if (p->t_gr_restart != NULL)
11970 json_object_int_add(
11971 json_timer, "restartTimerRemaining",
11972 thread_timer_remain_second(p->t_gr_restart));
11973
11974 json_object_object_add(json, "timers", json_timer);
11975 } else {
11976
11977 vty_out(vty, " Timers:\n");
11978 vty_out(vty, " Configured Restart Time(sec): %u\n",
11979 p->bgp->restart_time);
11980
11981 vty_out(vty, " Received Restart Time(sec): %u\n",
11982 p->v_gr_restart);
11983 if (p->t_gr_restart != NULL)
11984 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11985 thread_timer_remain_second(p->t_gr_restart));
11986 if (p->t_gr_restart != NULL) {
11987 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11988 thread_timer_remain_second(p->t_gr_restart));
11989 }
11990 }
11991 }
11992
11993 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11994 bool use_json, json_object *json)
11995 {
11996 char dn_flag[2] = {0};
11997 /* '*' + v6 address of neighbor */
11998 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11999
12000 if (!p->conf_if && peer_dynamic_neighbor(p))
12001 dn_flag[0] = '*';
12002
12003 if (p->conf_if) {
12004 if (use_json)
12005 json_object_string_addf(json, "neighborAddr", "%pSU",
12006 &p->su);
12007 else
12008 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12009 &p->su);
12010 } else {
12011 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12012 p->host);
12013
12014 if (use_json)
12015 json_object_string_add(json, "neighborAddr",
12016 neighborAddr);
12017 else
12018 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12019 }
12020
12021 /* more gr info in new format */
12022 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12023 }
12024
12025 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12026 safi_t safi, bool use_json,
12027 json_object *json_neigh)
12028 {
12029 struct bgp_filter *filter;
12030 struct peer_af *paf;
12031 char orf_pfx_name[BUFSIZ];
12032 int orf_pfx_count;
12033 json_object *json_af = NULL;
12034 json_object *json_prefA = NULL;
12035 json_object *json_prefB = NULL;
12036 json_object *json_addr = NULL;
12037 json_object *json_advmap = NULL;
12038
12039 if (use_json) {
12040 json_addr = json_object_new_object();
12041 json_af = json_object_new_object();
12042 filter = &p->filter[afi][safi];
12043
12044 if (peer_group_active(p))
12045 json_object_string_add(json_addr, "peerGroupMember",
12046 p->group->name);
12047
12048 paf = peer_af_find(p, afi, safi);
12049 if (paf && PAF_SUBGRP(paf)) {
12050 json_object_int_add(json_addr, "updateGroupId",
12051 PAF_UPDGRP(paf)->id);
12052 json_object_int_add(json_addr, "subGroupId",
12053 PAF_SUBGRP(paf)->id);
12054 json_object_int_add(json_addr, "packetQueueLength",
12055 bpacket_queue_virtual_length(paf));
12056 }
12057
12058 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12059 || CHECK_FLAG(p->af_cap[afi][safi],
12060 PEER_CAP_ORF_PREFIX_SM_RCV)
12061 || CHECK_FLAG(p->af_cap[afi][safi],
12062 PEER_CAP_ORF_PREFIX_RM_ADV)
12063 || CHECK_FLAG(p->af_cap[afi][safi],
12064 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12065 json_object_int_add(json_af, "orfType",
12066 ORF_TYPE_PREFIX);
12067 json_prefA = json_object_new_object();
12068 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12069 PEER_CAP_ORF_PREFIX_SM_ADV,
12070 PEER_CAP_ORF_PREFIX_RM_ADV,
12071 PEER_CAP_ORF_PREFIX_SM_RCV,
12072 PEER_CAP_ORF_PREFIX_RM_RCV,
12073 use_json, json_prefA);
12074 json_object_object_add(json_af, "orfPrefixList",
12075 json_prefA);
12076 }
12077
12078 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12079 || CHECK_FLAG(p->af_cap[afi][safi],
12080 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12081 || CHECK_FLAG(p->af_cap[afi][safi],
12082 PEER_CAP_ORF_PREFIX_RM_ADV)
12083 || CHECK_FLAG(p->af_cap[afi][safi],
12084 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12085 json_object_int_add(json_af, "orfOldType",
12086 ORF_TYPE_PREFIX_OLD);
12087 json_prefB = json_object_new_object();
12088 bgp_show_peer_afi_orf_cap(
12089 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12090 PEER_CAP_ORF_PREFIX_RM_ADV,
12091 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12092 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12093 json_prefB);
12094 json_object_object_add(json_af, "orfOldPrefixList",
12095 json_prefB);
12096 }
12097
12098 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12099 || CHECK_FLAG(p->af_cap[afi][safi],
12100 PEER_CAP_ORF_PREFIX_SM_RCV)
12101 || CHECK_FLAG(p->af_cap[afi][safi],
12102 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12103 || CHECK_FLAG(p->af_cap[afi][safi],
12104 PEER_CAP_ORF_PREFIX_RM_ADV)
12105 || CHECK_FLAG(p->af_cap[afi][safi],
12106 PEER_CAP_ORF_PREFIX_RM_RCV)
12107 || CHECK_FLAG(p->af_cap[afi][safi],
12108 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12109 json_object_object_add(json_addr, "afDependentCap",
12110 json_af);
12111 else
12112 json_object_free(json_af);
12113
12114 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12115 p->host, afi, safi);
12116 orf_pfx_count = prefix_bgp_show_prefix_list(
12117 NULL, afi, orf_pfx_name, use_json);
12118
12119 if (CHECK_FLAG(p->af_sflags[afi][safi],
12120 PEER_STATUS_ORF_PREFIX_SEND)
12121 || orf_pfx_count) {
12122 if (CHECK_FLAG(p->af_sflags[afi][safi],
12123 PEER_STATUS_ORF_PREFIX_SEND))
12124 json_object_boolean_true_add(json_neigh,
12125 "orfSent");
12126 if (orf_pfx_count)
12127 json_object_int_add(json_addr, "orfRecvCounter",
12128 orf_pfx_count);
12129 }
12130 if (CHECK_FLAG(p->af_sflags[afi][safi],
12131 PEER_STATUS_ORF_WAIT_REFRESH))
12132 json_object_string_add(
12133 json_addr, "orfFirstUpdate",
12134 "deferredUntilORFOrRouteRefreshRecvd");
12135
12136 if (CHECK_FLAG(p->af_flags[afi][safi],
12137 PEER_FLAG_REFLECTOR_CLIENT))
12138 json_object_boolean_true_add(json_addr,
12139 "routeReflectorClient");
12140 if (CHECK_FLAG(p->af_flags[afi][safi],
12141 PEER_FLAG_RSERVER_CLIENT))
12142 json_object_boolean_true_add(json_addr,
12143 "routeServerClient");
12144 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12145 json_object_boolean_true_add(json_addr,
12146 "inboundSoftConfigPermit");
12147
12148 if (CHECK_FLAG(p->af_flags[afi][safi],
12149 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12150 json_object_boolean_true_add(
12151 json_addr,
12152 "privateAsNumsAllReplacedInUpdatesToNbr");
12153 else if (CHECK_FLAG(p->af_flags[afi][safi],
12154 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12155 json_object_boolean_true_add(
12156 json_addr,
12157 "privateAsNumsReplacedInUpdatesToNbr");
12158 else if (CHECK_FLAG(p->af_flags[afi][safi],
12159 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12160 json_object_boolean_true_add(
12161 json_addr,
12162 "privateAsNumsAllRemovedInUpdatesToNbr");
12163 else if (CHECK_FLAG(p->af_flags[afi][safi],
12164 PEER_FLAG_REMOVE_PRIVATE_AS))
12165 json_object_boolean_true_add(
12166 json_addr,
12167 "privateAsNumsRemovedInUpdatesToNbr");
12168
12169 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12170 json_object_boolean_true_add(
12171 json_addr,
12172 bgp_addpath_names(p->addpath_type[afi][safi])
12173 ->type_json_name);
12174
12175 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12176 json_object_string_add(json_addr,
12177 "overrideASNsInOutboundUpdates",
12178 "ifAspathEqualRemoteAs");
12179
12180 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12181 || CHECK_FLAG(p->af_flags[afi][safi],
12182 PEER_FLAG_FORCE_NEXTHOP_SELF))
12183 json_object_boolean_true_add(json_addr,
12184 "routerAlwaysNextHop");
12185 if (CHECK_FLAG(p->af_flags[afi][safi],
12186 PEER_FLAG_AS_PATH_UNCHANGED))
12187 json_object_boolean_true_add(
12188 json_addr, "unchangedAsPathPropogatedToNbr");
12189 if (CHECK_FLAG(p->af_flags[afi][safi],
12190 PEER_FLAG_NEXTHOP_UNCHANGED))
12191 json_object_boolean_true_add(
12192 json_addr, "unchangedNextHopPropogatedToNbr");
12193 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12194 json_object_boolean_true_add(
12195 json_addr, "unchangedMedPropogatedToNbr");
12196 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12197 || CHECK_FLAG(p->af_flags[afi][safi],
12198 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12199 if (CHECK_FLAG(p->af_flags[afi][safi],
12200 PEER_FLAG_SEND_COMMUNITY)
12201 && CHECK_FLAG(p->af_flags[afi][safi],
12202 PEER_FLAG_SEND_EXT_COMMUNITY))
12203 json_object_string_add(json_addr,
12204 "commAttriSentToNbr",
12205 "extendedAndStandard");
12206 else if (CHECK_FLAG(p->af_flags[afi][safi],
12207 PEER_FLAG_SEND_EXT_COMMUNITY))
12208 json_object_string_add(json_addr,
12209 "commAttriSentToNbr",
12210 "extended");
12211 else
12212 json_object_string_add(json_addr,
12213 "commAttriSentToNbr",
12214 "standard");
12215 }
12216 if (CHECK_FLAG(p->af_flags[afi][safi],
12217 PEER_FLAG_DEFAULT_ORIGINATE)) {
12218 if (p->default_rmap[afi][safi].name)
12219 json_object_string_add(
12220 json_addr, "defaultRouteMap",
12221 p->default_rmap[afi][safi].name);
12222
12223 if (paf && PAF_SUBGRP(paf)
12224 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12225 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12226 json_object_boolean_true_add(json_addr,
12227 "defaultSent");
12228 else
12229 json_object_boolean_true_add(json_addr,
12230 "defaultNotSent");
12231 }
12232
12233 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12234 if (is_evpn_enabled())
12235 json_object_boolean_true_add(
12236 json_addr, "advertiseAllVnis");
12237 }
12238
12239 if (filter->plist[FILTER_IN].name
12240 || filter->dlist[FILTER_IN].name
12241 || filter->aslist[FILTER_IN].name
12242 || filter->map[RMAP_IN].name)
12243 json_object_boolean_true_add(json_addr,
12244 "inboundPathPolicyConfig");
12245 if (filter->plist[FILTER_OUT].name
12246 || filter->dlist[FILTER_OUT].name
12247 || filter->aslist[FILTER_OUT].name
12248 || filter->map[RMAP_OUT].name || filter->usmap.name)
12249 json_object_boolean_true_add(
12250 json_addr, "outboundPathPolicyConfig");
12251
12252 /* prefix-list */
12253 if (filter->plist[FILTER_IN].name)
12254 json_object_string_add(json_addr,
12255 "incomingUpdatePrefixFilterList",
12256 filter->plist[FILTER_IN].name);
12257 if (filter->plist[FILTER_OUT].name)
12258 json_object_string_add(json_addr,
12259 "outgoingUpdatePrefixFilterList",
12260 filter->plist[FILTER_OUT].name);
12261
12262 /* distribute-list */
12263 if (filter->dlist[FILTER_IN].name)
12264 json_object_string_add(
12265 json_addr, "incomingUpdateNetworkFilterList",
12266 filter->dlist[FILTER_IN].name);
12267 if (filter->dlist[FILTER_OUT].name)
12268 json_object_string_add(
12269 json_addr, "outgoingUpdateNetworkFilterList",
12270 filter->dlist[FILTER_OUT].name);
12271
12272 /* filter-list. */
12273 if (filter->aslist[FILTER_IN].name)
12274 json_object_string_add(json_addr,
12275 "incomingUpdateAsPathFilterList",
12276 filter->aslist[FILTER_IN].name);
12277 if (filter->aslist[FILTER_OUT].name)
12278 json_object_string_add(json_addr,
12279 "outgoingUpdateAsPathFilterList",
12280 filter->aslist[FILTER_OUT].name);
12281
12282 /* route-map. */
12283 if (filter->map[RMAP_IN].name)
12284 json_object_string_add(
12285 json_addr, "routeMapForIncomingAdvertisements",
12286 filter->map[RMAP_IN].name);
12287 if (filter->map[RMAP_OUT].name)
12288 json_object_string_add(
12289 json_addr, "routeMapForOutgoingAdvertisements",
12290 filter->map[RMAP_OUT].name);
12291
12292 /* ebgp-requires-policy (inbound) */
12293 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12294 && !bgp_inbound_policy_exists(p, filter))
12295 json_object_string_add(
12296 json_addr, "inboundEbgpRequiresPolicy",
12297 "Inbound updates discarded due to missing policy");
12298
12299 /* ebgp-requires-policy (outbound) */
12300 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12301 && (!bgp_outbound_policy_exists(p, filter)))
12302 json_object_string_add(
12303 json_addr, "outboundEbgpRequiresPolicy",
12304 "Outbound updates discarded due to missing policy");
12305
12306 /* unsuppress-map */
12307 if (filter->usmap.name)
12308 json_object_string_add(json_addr,
12309 "selectiveUnsuppressRouteMap",
12310 filter->usmap.name);
12311
12312 /* advertise-map */
12313 if (filter->advmap.aname) {
12314 json_advmap = json_object_new_object();
12315 json_object_string_add(json_advmap, "condition",
12316 filter->advmap.condition
12317 ? "EXIST"
12318 : "NON_EXIST");
12319 json_object_string_add(json_advmap, "conditionMap",
12320 filter->advmap.cname);
12321 json_object_string_add(json_advmap, "advertiseMap",
12322 filter->advmap.aname);
12323 json_object_string_add(
12324 json_advmap, "advertiseStatus",
12325 filter->advmap.update_type ==
12326 UPDATE_TYPE_ADVERTISE
12327 ? "Advertise"
12328 : "Withdraw");
12329 json_object_object_add(json_addr, "advertiseMap",
12330 json_advmap);
12331 }
12332
12333 /* Receive prefix count */
12334 json_object_int_add(json_addr, "acceptedPrefixCounter",
12335 p->pcount[afi][safi]);
12336 if (paf && PAF_SUBGRP(paf))
12337 json_object_int_add(json_addr, "sentPrefixCounter",
12338 (PAF_SUBGRP(paf))->scount);
12339
12340 /* Maximum prefix */
12341 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12342 json_object_int_add(json_addr, "prefixOutAllowedMax",
12343 p->pmax_out[afi][safi]);
12344
12345 /* Maximum prefix */
12346 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12347 json_object_int_add(json_addr, "prefixAllowedMax",
12348 p->pmax[afi][safi]);
12349 if (CHECK_FLAG(p->af_flags[afi][safi],
12350 PEER_FLAG_MAX_PREFIX_WARNING))
12351 json_object_boolean_true_add(
12352 json_addr, "prefixAllowedMaxWarning");
12353 json_object_int_add(json_addr,
12354 "prefixAllowedWarningThresh",
12355 p->pmax_threshold[afi][safi]);
12356 if (p->pmax_restart[afi][safi])
12357 json_object_int_add(
12358 json_addr,
12359 "prefixAllowedRestartIntervalMsecs",
12360 p->pmax_restart[afi][safi] * 60000);
12361 }
12362 json_object_object_add(json_neigh,
12363 get_afi_safi_str(afi, safi, true),
12364 json_addr);
12365
12366 } else {
12367 filter = &p->filter[afi][safi];
12368
12369 vty_out(vty, " For address family: %s\n",
12370 get_afi_safi_str(afi, safi, false));
12371
12372 if (peer_group_active(p))
12373 vty_out(vty, " %s peer-group member\n",
12374 p->group->name);
12375
12376 paf = peer_af_find(p, afi, safi);
12377 if (paf && PAF_SUBGRP(paf)) {
12378 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12379 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12380 vty_out(vty, " Packet Queue length %d\n",
12381 bpacket_queue_virtual_length(paf));
12382 } else {
12383 vty_out(vty, " Not part of any update group\n");
12384 }
12385 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12386 || CHECK_FLAG(p->af_cap[afi][safi],
12387 PEER_CAP_ORF_PREFIX_SM_RCV)
12388 || CHECK_FLAG(p->af_cap[afi][safi],
12389 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12390 || CHECK_FLAG(p->af_cap[afi][safi],
12391 PEER_CAP_ORF_PREFIX_RM_ADV)
12392 || CHECK_FLAG(p->af_cap[afi][safi],
12393 PEER_CAP_ORF_PREFIX_RM_RCV)
12394 || CHECK_FLAG(p->af_cap[afi][safi],
12395 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12396 vty_out(vty, " AF-dependant capabilities:\n");
12397
12398 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12399 || CHECK_FLAG(p->af_cap[afi][safi],
12400 PEER_CAP_ORF_PREFIX_SM_RCV)
12401 || CHECK_FLAG(p->af_cap[afi][safi],
12402 PEER_CAP_ORF_PREFIX_RM_ADV)
12403 || CHECK_FLAG(p->af_cap[afi][safi],
12404 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12405 vty_out(vty,
12406 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12407 ORF_TYPE_PREFIX);
12408 bgp_show_peer_afi_orf_cap(
12409 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12410 PEER_CAP_ORF_PREFIX_RM_ADV,
12411 PEER_CAP_ORF_PREFIX_SM_RCV,
12412 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12413 }
12414 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12415 || CHECK_FLAG(p->af_cap[afi][safi],
12416 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12417 || CHECK_FLAG(p->af_cap[afi][safi],
12418 PEER_CAP_ORF_PREFIX_RM_ADV)
12419 || CHECK_FLAG(p->af_cap[afi][safi],
12420 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12421 vty_out(vty,
12422 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12423 ORF_TYPE_PREFIX_OLD);
12424 bgp_show_peer_afi_orf_cap(
12425 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12426 PEER_CAP_ORF_PREFIX_RM_ADV,
12427 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12428 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12429 }
12430
12431 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12432 p->host, afi, safi);
12433 orf_pfx_count = prefix_bgp_show_prefix_list(
12434 NULL, afi, orf_pfx_name, use_json);
12435
12436 if (CHECK_FLAG(p->af_sflags[afi][safi],
12437 PEER_STATUS_ORF_PREFIX_SEND)
12438 || orf_pfx_count) {
12439 vty_out(vty, " Outbound Route Filter (ORF):");
12440 if (CHECK_FLAG(p->af_sflags[afi][safi],
12441 PEER_STATUS_ORF_PREFIX_SEND))
12442 vty_out(vty, " sent;");
12443 if (orf_pfx_count)
12444 vty_out(vty, " received (%d entries)",
12445 orf_pfx_count);
12446 vty_out(vty, "\n");
12447 }
12448 if (CHECK_FLAG(p->af_sflags[afi][safi],
12449 PEER_STATUS_ORF_WAIT_REFRESH))
12450 vty_out(vty,
12451 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12452
12453 if (CHECK_FLAG(p->af_flags[afi][safi],
12454 PEER_FLAG_REFLECTOR_CLIENT))
12455 vty_out(vty, " Route-Reflector Client\n");
12456 if (CHECK_FLAG(p->af_flags[afi][safi],
12457 PEER_FLAG_RSERVER_CLIENT))
12458 vty_out(vty, " Route-Server Client\n");
12459
12460 if (peer_af_flag_check(p, afi, safi, PEER_FLAG_ORR_GROUP))
12461 vty_out(vty, " ORR group (configured) : %s\n",
12462 p->orr_group_name[afi][safi]);
12463
12464 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12465 vty_out(vty,
12466 " Inbound soft reconfiguration allowed\n");
12467
12468 if (CHECK_FLAG(p->af_flags[afi][safi],
12469 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12470 vty_out(vty,
12471 " Private AS numbers (all) replaced in updates to this neighbor\n");
12472 else if (CHECK_FLAG(p->af_flags[afi][safi],
12473 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12474 vty_out(vty,
12475 " Private AS numbers replaced in updates to this neighbor\n");
12476 else if (CHECK_FLAG(p->af_flags[afi][safi],
12477 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12478 vty_out(vty,
12479 " Private AS numbers (all) removed in updates to this neighbor\n");
12480 else if (CHECK_FLAG(p->af_flags[afi][safi],
12481 PEER_FLAG_REMOVE_PRIVATE_AS))
12482 vty_out(vty,
12483 " Private AS numbers removed in updates to this neighbor\n");
12484
12485 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12486 vty_out(vty, " %s\n",
12487 bgp_addpath_names(p->addpath_type[afi][safi])
12488 ->human_description);
12489
12490 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12491 vty_out(vty,
12492 " Override ASNs in outbound updates if aspath equals remote-as\n");
12493
12494 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12495 || CHECK_FLAG(p->af_flags[afi][safi],
12496 PEER_FLAG_FORCE_NEXTHOP_SELF))
12497 vty_out(vty, " NEXT_HOP is always this router\n");
12498 if (CHECK_FLAG(p->af_flags[afi][safi],
12499 PEER_FLAG_AS_PATH_UNCHANGED))
12500 vty_out(vty,
12501 " AS_PATH is propagated unchanged to this neighbor\n");
12502 if (CHECK_FLAG(p->af_flags[afi][safi],
12503 PEER_FLAG_NEXTHOP_UNCHANGED))
12504 vty_out(vty,
12505 " NEXT_HOP is propagated unchanged to this neighbor\n");
12506 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12507 vty_out(vty,
12508 " MED is propagated unchanged to this neighbor\n");
12509 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12510 || CHECK_FLAG(p->af_flags[afi][safi],
12511 PEER_FLAG_SEND_EXT_COMMUNITY)
12512 || CHECK_FLAG(p->af_flags[afi][safi],
12513 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12514 vty_out(vty,
12515 " Community attribute sent to this neighbor");
12516 if (CHECK_FLAG(p->af_flags[afi][safi],
12517 PEER_FLAG_SEND_COMMUNITY)
12518 && CHECK_FLAG(p->af_flags[afi][safi],
12519 PEER_FLAG_SEND_EXT_COMMUNITY)
12520 && CHECK_FLAG(p->af_flags[afi][safi],
12521 PEER_FLAG_SEND_LARGE_COMMUNITY))
12522 vty_out(vty, "(all)\n");
12523 else if (CHECK_FLAG(p->af_flags[afi][safi],
12524 PEER_FLAG_SEND_LARGE_COMMUNITY))
12525 vty_out(vty, "(large)\n");
12526 else if (CHECK_FLAG(p->af_flags[afi][safi],
12527 PEER_FLAG_SEND_EXT_COMMUNITY))
12528 vty_out(vty, "(extended)\n");
12529 else
12530 vty_out(vty, "(standard)\n");
12531 }
12532 if (CHECK_FLAG(p->af_flags[afi][safi],
12533 PEER_FLAG_DEFAULT_ORIGINATE)) {
12534 vty_out(vty, " Default information originate,");
12535
12536 if (p->default_rmap[afi][safi].name)
12537 vty_out(vty, " default route-map %s%s,",
12538 p->default_rmap[afi][safi].map ? "*"
12539 : "",
12540 p->default_rmap[afi][safi].name);
12541 if (paf && PAF_SUBGRP(paf)
12542 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12543 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12544 vty_out(vty, " default sent\n");
12545 else
12546 vty_out(vty, " default not sent\n");
12547 }
12548
12549 /* advertise-vni-all */
12550 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12551 if (is_evpn_enabled())
12552 vty_out(vty, " advertise-all-vni\n");
12553 }
12554
12555 if (filter->plist[FILTER_IN].name
12556 || filter->dlist[FILTER_IN].name
12557 || filter->aslist[FILTER_IN].name
12558 || filter->map[RMAP_IN].name)
12559 vty_out(vty, " Inbound path policy configured\n");
12560 if (filter->plist[FILTER_OUT].name
12561 || filter->dlist[FILTER_OUT].name
12562 || filter->aslist[FILTER_OUT].name
12563 || filter->map[RMAP_OUT].name || filter->usmap.name)
12564 vty_out(vty, " Outbound path policy configured\n");
12565
12566 /* prefix-list */
12567 if (filter->plist[FILTER_IN].name)
12568 vty_out(vty,
12569 " Incoming update prefix filter list is %s%s\n",
12570 filter->plist[FILTER_IN].plist ? "*" : "",
12571 filter->plist[FILTER_IN].name);
12572 if (filter->plist[FILTER_OUT].name)
12573 vty_out(vty,
12574 " Outgoing update prefix filter list is %s%s\n",
12575 filter->plist[FILTER_OUT].plist ? "*" : "",
12576 filter->plist[FILTER_OUT].name);
12577
12578 /* distribute-list */
12579 if (filter->dlist[FILTER_IN].name)
12580 vty_out(vty,
12581 " Incoming update network filter list is %s%s\n",
12582 filter->dlist[FILTER_IN].alist ? "*" : "",
12583 filter->dlist[FILTER_IN].name);
12584 if (filter->dlist[FILTER_OUT].name)
12585 vty_out(vty,
12586 " Outgoing update network filter list is %s%s\n",
12587 filter->dlist[FILTER_OUT].alist ? "*" : "",
12588 filter->dlist[FILTER_OUT].name);
12589
12590 /* filter-list. */
12591 if (filter->aslist[FILTER_IN].name)
12592 vty_out(vty,
12593 " Incoming update AS path filter list is %s%s\n",
12594 filter->aslist[FILTER_IN].aslist ? "*" : "",
12595 filter->aslist[FILTER_IN].name);
12596 if (filter->aslist[FILTER_OUT].name)
12597 vty_out(vty,
12598 " Outgoing update AS path filter list is %s%s\n",
12599 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12600 filter->aslist[FILTER_OUT].name);
12601
12602 /* route-map. */
12603 if (filter->map[RMAP_IN].name)
12604 vty_out(vty,
12605 " Route map for incoming advertisements is %s%s\n",
12606 filter->map[RMAP_IN].map ? "*" : "",
12607 filter->map[RMAP_IN].name);
12608 if (filter->map[RMAP_OUT].name)
12609 vty_out(vty,
12610 " Route map for outgoing advertisements is %s%s\n",
12611 filter->map[RMAP_OUT].map ? "*" : "",
12612 filter->map[RMAP_OUT].name);
12613
12614 /* ebgp-requires-policy (inbound) */
12615 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12616 && !bgp_inbound_policy_exists(p, filter))
12617 vty_out(vty,
12618 " Inbound updates discarded due to missing policy\n");
12619
12620 /* ebgp-requires-policy (outbound) */
12621 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12622 && !bgp_outbound_policy_exists(p, filter))
12623 vty_out(vty,
12624 " Outbound updates discarded due to missing policy\n");
12625
12626 /* unsuppress-map */
12627 if (filter->usmap.name)
12628 vty_out(vty,
12629 " Route map for selective unsuppress is %s%s\n",
12630 filter->usmap.map ? "*" : "",
12631 filter->usmap.name);
12632
12633 /* advertise-map */
12634 if (filter->advmap.aname && filter->advmap.cname)
12635 vty_out(vty,
12636 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12637 filter->advmap.condition ? "EXIST"
12638 : "NON_EXIST",
12639 filter->advmap.cmap ? "*" : "",
12640 filter->advmap.cname,
12641 filter->advmap.amap ? "*" : "",
12642 filter->advmap.aname,
12643 filter->advmap.update_type ==
12644 UPDATE_TYPE_ADVERTISE
12645 ? "Advertise"
12646 : "Withdraw");
12647
12648 /* Receive prefix count */
12649 vty_out(vty, " %u accepted prefixes\n",
12650 p->pcount[afi][safi]);
12651
12652 /* maximum-prefix-out */
12653 if (CHECK_FLAG(p->af_flags[afi][safi],
12654 PEER_FLAG_MAX_PREFIX_OUT))
12655 vty_out(vty,
12656 " Maximum allowed prefixes sent %u\n",
12657 p->pmax_out[afi][safi]);
12658
12659 /* Maximum prefix */
12660 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12661 vty_out(vty,
12662 " Maximum prefixes allowed %u%s\n",
12663 p->pmax[afi][safi],
12664 CHECK_FLAG(p->af_flags[afi][safi],
12665 PEER_FLAG_MAX_PREFIX_WARNING)
12666 ? " (warning-only)"
12667 : "");
12668 vty_out(vty, " Threshold for warning message %d%%",
12669 p->pmax_threshold[afi][safi]);
12670 if (p->pmax_restart[afi][safi])
12671 vty_out(vty, ", restart interval %d min",
12672 p->pmax_restart[afi][safi]);
12673 vty_out(vty, "\n");
12674 }
12675
12676 vty_out(vty, "\n");
12677 }
12678 }
12679
12680 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12681 json_object *json)
12682 {
12683 struct bgp *bgp;
12684 char buf1[PREFIX2STR_BUFFER];
12685 char timebuf[BGP_UPTIME_LEN];
12686 char dn_flag[2];
12687 afi_t afi;
12688 safi_t safi;
12689 uint16_t i;
12690 uint8_t *msg;
12691 json_object *json_neigh = NULL;
12692 time_t epoch_tbuf;
12693 uint32_t sync_tcp_mss;
12694
12695 bgp = p->bgp;
12696
12697 if (use_json)
12698 json_neigh = json_object_new_object();
12699
12700 memset(dn_flag, '\0', sizeof(dn_flag));
12701 if (!p->conf_if && peer_dynamic_neighbor(p))
12702 dn_flag[0] = '*';
12703
12704 if (!use_json) {
12705 if (p->conf_if) /* Configured interface name. */
12706 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12707 &p->su);
12708 else /* Configured IP address. */
12709 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12710 p->host);
12711 }
12712
12713 if (use_json) {
12714 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12715 json_object_string_add(json_neigh, "bgpNeighborAddr",
12716 "none");
12717 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12718 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12719 "%pSU", &p->su);
12720
12721 json_object_int_add(json_neigh, "remoteAs", p->as);
12722
12723 if (p->change_local_as)
12724 json_object_int_add(json_neigh, "localAs",
12725 p->change_local_as);
12726 else
12727 json_object_int_add(json_neigh, "localAs", p->local_as);
12728
12729 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12730 json_object_boolean_true_add(json_neigh,
12731 "localAsNoPrepend");
12732
12733 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12734 json_object_boolean_true_add(json_neigh,
12735 "localAsReplaceAs");
12736 } else {
12737 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12738 || (p->as_type == AS_INTERNAL))
12739 vty_out(vty, "remote AS %u, ", p->as);
12740 else
12741 vty_out(vty, "remote AS Unspecified, ");
12742 vty_out(vty, "local AS %u%s%s, ",
12743 p->change_local_as ? p->change_local_as : p->local_as,
12744 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12745 ? " no-prepend"
12746 : "",
12747 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12748 ? " replace-as"
12749 : "");
12750 }
12751 /* peer type internal or confed-internal */
12752 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12753 if (use_json) {
12754 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12755 json_object_boolean_true_add(
12756 json_neigh, "nbrConfedInternalLink");
12757 else
12758 json_object_boolean_true_add(json_neigh,
12759 "nbrInternalLink");
12760 } else {
12761 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12762 vty_out(vty, "confed-internal link\n");
12763 else
12764 vty_out(vty, "internal link\n");
12765 }
12766 /* peer type external or confed-external */
12767 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12768 if (use_json) {
12769 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12770 json_object_boolean_true_add(
12771 json_neigh, "nbrConfedExternalLink");
12772 else
12773 json_object_boolean_true_add(json_neigh,
12774 "nbrExternalLink");
12775 } else {
12776 if (bgp_confederation_peers_check(bgp, p->as))
12777 vty_out(vty, "confed-external link\n");
12778 else
12779 vty_out(vty, "external link\n");
12780 }
12781 } else {
12782 if (use_json)
12783 json_object_boolean_true_add(json_neigh,
12784 "nbrUnspecifiedLink");
12785 else
12786 vty_out(vty, "unspecified link\n");
12787 }
12788
12789 /* Roles */
12790 if (use_json) {
12791 json_object_string_add(json_neigh, "localRole",
12792 bgp_get_name_by_role(p->local_role));
12793 json_object_string_add(json_neigh, "remoteRole",
12794 bgp_get_name_by_role(p->remote_role));
12795 } else {
12796 vty_out(vty, " Local Role: %s\n",
12797 bgp_get_name_by_role(p->local_role));
12798 vty_out(vty, " Remote Role: %s\n",
12799 bgp_get_name_by_role(p->remote_role));
12800 }
12801
12802
12803 /* Description. */
12804 if (p->desc) {
12805 if (use_json)
12806 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12807 else
12808 vty_out(vty, " Description: %s\n", p->desc);
12809 }
12810
12811 if (p->hostname) {
12812 if (use_json) {
12813 if (p->hostname)
12814 json_object_string_add(json_neigh, "hostname",
12815 p->hostname);
12816
12817 if (p->domainname)
12818 json_object_string_add(json_neigh, "domainname",
12819 p->domainname);
12820 } else {
12821 if (p->domainname && (p->domainname[0] != '\0'))
12822 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12823 p->domainname);
12824 else
12825 vty_out(vty, "Hostname: %s\n", p->hostname);
12826 }
12827 }
12828
12829 /* Peer-group */
12830 if (p->group) {
12831 if (use_json) {
12832 json_object_string_add(json_neigh, "peerGroup",
12833 p->group->name);
12834
12835 if (dn_flag[0]) {
12836 struct prefix prefix, *range = NULL;
12837
12838 if (sockunion2hostprefix(&(p->su), &prefix))
12839 range = peer_group_lookup_dynamic_neighbor_range(
12840 p->group, &prefix);
12841
12842 if (range) {
12843 json_object_string_addf(
12844 json_neigh,
12845 "peerSubnetRangeGroup", "%pFX",
12846 range);
12847 }
12848 }
12849 } else {
12850 vty_out(vty,
12851 " Member of peer-group %s for session parameters\n",
12852 p->group->name);
12853
12854 if (dn_flag[0]) {
12855 struct prefix prefix, *range = NULL;
12856
12857 if (sockunion2hostprefix(&(p->su), &prefix))
12858 range = peer_group_lookup_dynamic_neighbor_range(
12859 p->group, &prefix);
12860
12861 if (range) {
12862 vty_out(vty,
12863 " Belongs to the subnet range group: %pFX\n",
12864 range);
12865 }
12866 }
12867 }
12868 }
12869
12870 if (use_json) {
12871 /* Administrative shutdown. */
12872 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12873 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12874 json_object_boolean_true_add(json_neigh,
12875 "adminShutDown");
12876
12877 /* BGP Version. */
12878 json_object_int_add(json_neigh, "bgpVersion", 4);
12879 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12880 &p->remote_id);
12881 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12882 &bgp->router_id);
12883
12884 /* Confederation */
12885 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12886 && bgp_confederation_peers_check(bgp, p->as))
12887 json_object_boolean_true_add(json_neigh,
12888 "nbrCommonAdmin");
12889
12890 /* Status. */
12891 json_object_string_add(
12892 json_neigh, "bgpState",
12893 lookup_msg(bgp_status_msg, p->status, NULL));
12894
12895 if (peer_established(p)) {
12896 time_t uptime;
12897
12898 uptime = monotime(NULL);
12899 uptime -= p->uptime;
12900 epoch_tbuf = time(NULL) - uptime;
12901
12902 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12903 uptime * 1000);
12904 json_object_string_add(json_neigh, "bgpTimerUpString",
12905 peer_uptime(p->uptime, timebuf,
12906 BGP_UPTIME_LEN, 0,
12907 NULL));
12908 json_object_int_add(json_neigh,
12909 "bgpTimerUpEstablishedEpoch",
12910 epoch_tbuf);
12911 }
12912
12913 else if (p->status == Active) {
12914 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12915 json_object_string_add(json_neigh, "bgpStateIs",
12916 "passive");
12917 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12918 json_object_string_add(json_neigh, "bgpStateIs",
12919 "passiveNSF");
12920 }
12921
12922 /* read timer */
12923 time_t uptime;
12924 struct tm tm;
12925
12926 uptime = monotime(NULL);
12927 uptime -= p->readtime;
12928 gmtime_r(&uptime, &tm);
12929
12930 json_object_int_add(json_neigh, "bgpTimerLastRead",
12931 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12932 + (tm.tm_hour * 3600000));
12933
12934 uptime = monotime(NULL);
12935 uptime -= p->last_write;
12936 gmtime_r(&uptime, &tm);
12937
12938 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12939 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12940 + (tm.tm_hour * 3600000));
12941
12942 uptime = monotime(NULL);
12943 uptime -= p->update_time;
12944 gmtime_r(&uptime, &tm);
12945
12946 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12947 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12948 + (tm.tm_hour * 3600000));
12949
12950 /* Configured timer values. */
12951 json_object_int_add(json_neigh,
12952 "bgpTimerConfiguredHoldTimeMsecs",
12953 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12954 ? p->holdtime * 1000
12955 : bgp->default_holdtime * 1000);
12956 json_object_int_add(json_neigh,
12957 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12958 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12959 ? p->keepalive * 1000
12960 : bgp->default_keepalive * 1000);
12961 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12962 p->v_holdtime * 1000);
12963 json_object_int_add(json_neigh,
12964 "bgpTimerKeepAliveIntervalMsecs",
12965 p->v_keepalive * 1000);
12966 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12967 json_object_int_add(json_neigh,
12968 "bgpTimerDelayOpenTimeMsecs",
12969 p->v_delayopen * 1000);
12970 }
12971
12972 /* Configured and Synced tcp-mss value for peer */
12973 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12974 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12975 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12976 p->tcp_mss);
12977 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12978 sync_tcp_mss);
12979 }
12980
12981 /* Extended Optional Parameters Length for BGP OPEN Message */
12982 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12983 json_object_boolean_true_add(
12984 json_neigh, "extendedOptionalParametersLength");
12985 else
12986 json_object_boolean_false_add(
12987 json_neigh, "extendedOptionalParametersLength");
12988
12989 /* Conditional advertisements */
12990 json_object_int_add(
12991 json_neigh,
12992 "bgpTimerConfiguredConditionalAdvertisementsSec",
12993 bgp->condition_check_period);
12994 if (thread_is_scheduled(bgp->t_condition_check))
12995 json_object_int_add(
12996 json_neigh,
12997 "bgpTimerUntilConditionalAdvertisementsSec",
12998 thread_timer_remain_second(
12999 bgp->t_condition_check));
13000 } else {
13001 /* Administrative shutdown. */
13002 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13003 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13004 vty_out(vty, " Administratively shut down\n");
13005
13006 /* BGP Version. */
13007 vty_out(vty, " BGP version 4");
13008 vty_out(vty, ", remote router ID %s",
13009 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
13010 vty_out(vty, ", local router ID %s\n",
13011 inet_ntop(AF_INET, &bgp->router_id, buf1,
13012 sizeof(buf1)));
13013
13014 /* Confederation */
13015 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13016 && bgp_confederation_peers_check(bgp, p->as))
13017 vty_out(vty,
13018 " Neighbor under common administration\n");
13019
13020 /* Status. */
13021 vty_out(vty, " BGP state = %s",
13022 lookup_msg(bgp_status_msg, p->status, NULL));
13023
13024 if (peer_established(p))
13025 vty_out(vty, ", up for %8s",
13026 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13027 0, NULL));
13028
13029 else if (p->status == Active) {
13030 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13031 vty_out(vty, " (passive)");
13032 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13033 vty_out(vty, " (NSF passive)");
13034 }
13035 vty_out(vty, "\n");
13036
13037 /* read timer */
13038 vty_out(vty, " Last read %s",
13039 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13040 NULL));
13041 vty_out(vty, ", Last write %s\n",
13042 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13043 NULL));
13044
13045 /* Configured timer values. */
13046 vty_out(vty,
13047 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13048 p->v_holdtime, p->v_keepalive);
13049 vty_out(vty, " Configured hold time is %d seconds",
13050 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13051 ? p->holdtime
13052 : bgp->default_holdtime);
13053 vty_out(vty, ", keepalive interval is %d seconds\n",
13054 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13055 ? p->keepalive
13056 : bgp->default_keepalive);
13057 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13058 vty_out(vty,
13059 " Configured DelayOpenTime is %d seconds\n",
13060 p->delayopen);
13061
13062 /* Configured and synced tcp-mss value for peer */
13063 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13064 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13065 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13066 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13067 }
13068
13069 /* Extended Optional Parameters Length for BGP OPEN Message */
13070 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13071 vty_out(vty,
13072 " Extended Optional Parameters Length is enabled\n");
13073
13074 /* Conditional advertisements */
13075 vty_out(vty,
13076 " Configured conditional advertisements interval is %d seconds\n",
13077 bgp->condition_check_period);
13078 if (thread_is_scheduled(bgp->t_condition_check))
13079 vty_out(vty,
13080 " Time until conditional advertisements begin is %lu seconds\n",
13081 thread_timer_remain_second(
13082 bgp->t_condition_check));
13083 }
13084 /* Capability. */
13085 if (peer_established(p) &&
13086 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13087 if (use_json) {
13088 json_object *json_cap = NULL;
13089
13090 json_cap = json_object_new_object();
13091
13092 /* AS4 */
13093 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13094 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13095 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13096 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13097 json_object_string_add(
13098 json_cap, "4byteAs",
13099 "advertisedAndReceived");
13100 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13101 json_object_string_add(json_cap,
13102 "4byteAs",
13103 "advertised");
13104 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13105 json_object_string_add(json_cap,
13106 "4byteAs",
13107 "received");
13108 }
13109
13110 /* Extended Message Support */
13111 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13112 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13113 json_object_string_add(json_cap,
13114 "extendedMessage",
13115 "advertisedAndReceived");
13116 else if (CHECK_FLAG(p->cap,
13117 PEER_CAP_EXTENDED_MESSAGE_ADV))
13118 json_object_string_add(json_cap,
13119 "extendedMessage",
13120 "advertised");
13121 else if (CHECK_FLAG(p->cap,
13122 PEER_CAP_EXTENDED_MESSAGE_RCV))
13123 json_object_string_add(json_cap,
13124 "extendedMessage",
13125 "received");
13126
13127 /* AddPath */
13128 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13129 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13130 json_object *json_add = NULL;
13131 const char *print_store;
13132
13133 json_add = json_object_new_object();
13134
13135 FOREACH_AFI_SAFI (afi, safi) {
13136 json_object *json_sub = NULL;
13137 json_sub = json_object_new_object();
13138 print_store = get_afi_safi_str(
13139 afi, safi, true);
13140
13141 if (CHECK_FLAG(
13142 p->af_cap[afi][safi],
13143 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13144 CHECK_FLAG(
13145 p->af_cap[afi][safi],
13146 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13147 if (CHECK_FLAG(
13148 p->af_cap[afi]
13149 [safi],
13150 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13151 CHECK_FLAG(
13152 p->af_cap[afi]
13153 [safi],
13154 PEER_CAP_ADDPATH_AF_TX_RCV))
13155 json_object_boolean_true_add(
13156 json_sub,
13157 "txAdvertisedAndReceived");
13158 else if (
13159 CHECK_FLAG(
13160 p->af_cap[afi]
13161 [safi],
13162 PEER_CAP_ADDPATH_AF_TX_ADV))
13163 json_object_boolean_true_add(
13164 json_sub,
13165 "txAdvertised");
13166 else if (
13167 CHECK_FLAG(
13168 p->af_cap[afi]
13169 [safi],
13170 PEER_CAP_ADDPATH_AF_TX_RCV))
13171 json_object_boolean_true_add(
13172 json_sub,
13173 "txReceived");
13174 }
13175
13176 if (CHECK_FLAG(
13177 p->af_cap[afi][safi],
13178 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13179 CHECK_FLAG(
13180 p->af_cap[afi][safi],
13181 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13182 if (CHECK_FLAG(
13183 p->af_cap[afi]
13184 [safi],
13185 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13186 CHECK_FLAG(
13187 p->af_cap[afi]
13188 [safi],
13189 PEER_CAP_ADDPATH_AF_RX_RCV))
13190 json_object_boolean_true_add(
13191 json_sub,
13192 "rxAdvertisedAndReceived");
13193 else if (
13194 CHECK_FLAG(
13195 p->af_cap[afi]
13196 [safi],
13197 PEER_CAP_ADDPATH_AF_RX_ADV))
13198 json_object_boolean_true_add(
13199 json_sub,
13200 "rxAdvertised");
13201 else if (
13202 CHECK_FLAG(
13203 p->af_cap[afi]
13204 [safi],
13205 PEER_CAP_ADDPATH_AF_RX_RCV))
13206 json_object_boolean_true_add(
13207 json_sub,
13208 "rxReceived");
13209 }
13210
13211 if (CHECK_FLAG(
13212 p->af_cap[afi][safi],
13213 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13214 CHECK_FLAG(
13215 p->af_cap[afi][safi],
13216 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13217 CHECK_FLAG(
13218 p->af_cap[afi][safi],
13219 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13220 CHECK_FLAG(
13221 p->af_cap[afi][safi],
13222 PEER_CAP_ADDPATH_AF_RX_RCV))
13223 json_object_object_add(
13224 json_add, print_store,
13225 json_sub);
13226 else
13227 json_object_free(json_sub);
13228 }
13229
13230 json_object_object_add(json_cap, "addPath",
13231 json_add);
13232 }
13233
13234 /* Dynamic */
13235 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13236 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13237 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13238 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13239 json_object_string_add(
13240 json_cap, "dynamic",
13241 "advertisedAndReceived");
13242 else if (CHECK_FLAG(p->cap,
13243 PEER_CAP_DYNAMIC_ADV))
13244 json_object_string_add(json_cap,
13245 "dynamic",
13246 "advertised");
13247 else if (CHECK_FLAG(p->cap,
13248 PEER_CAP_DYNAMIC_RCV))
13249 json_object_string_add(json_cap,
13250 "dynamic",
13251 "received");
13252 }
13253
13254 /* Role */
13255 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13256 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13257 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13258 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13259 json_object_string_add(
13260 json_cap, "role",
13261 "advertisedAndReceived");
13262 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13263 json_object_string_add(json_cap, "role",
13264 "advertised");
13265 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13266 json_object_string_add(json_cap, "role",
13267 "received");
13268 }
13269
13270 /* Extended nexthop */
13271 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13272 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13273 json_object *json_nxt = NULL;
13274 const char *print_store;
13275
13276
13277 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13278 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13279 json_object_string_add(
13280 json_cap, "extendedNexthop",
13281 "advertisedAndReceived");
13282 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13283 json_object_string_add(
13284 json_cap, "extendedNexthop",
13285 "advertised");
13286 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13287 json_object_string_add(
13288 json_cap, "extendedNexthop",
13289 "received");
13290
13291 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13292 json_nxt = json_object_new_object();
13293
13294 for (safi = SAFI_UNICAST;
13295 safi < SAFI_MAX; safi++) {
13296 if (CHECK_FLAG(
13297 p->af_cap[AFI_IP]
13298 [safi],
13299 PEER_CAP_ENHE_AF_RCV)) {
13300 print_store =
13301 get_afi_safi_str(
13302 AFI_IP,
13303 safi,
13304 true);
13305 json_object_string_add(
13306 json_nxt,
13307 print_store,
13308 "recieved"); /* misspelled for compatibility */
13309 }
13310 }
13311 json_object_object_add(
13312 json_cap,
13313 "extendedNexthopFamililesByPeer",
13314 json_nxt);
13315 }
13316 }
13317
13318 /* Long-lived Graceful Restart */
13319 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13320 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13321 json_object *json_llgr = NULL;
13322 const char *afi_safi_str;
13323
13324 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13325 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13326 json_object_string_add(
13327 json_cap,
13328 "longLivedGracefulRestart",
13329 "advertisedAndReceived");
13330 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13331 json_object_string_add(
13332 json_cap,
13333 "longLivedGracefulRestart",
13334 "advertised");
13335 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13336 json_object_string_add(
13337 json_cap,
13338 "longLivedGracefulRestart",
13339 "received");
13340
13341 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13342 json_llgr = json_object_new_object();
13343
13344 FOREACH_AFI_SAFI (afi, safi) {
13345 if (CHECK_FLAG(
13346 p->af_cap[afi]
13347 [safi],
13348 PEER_CAP_ENHE_AF_RCV)) {
13349 afi_safi_str =
13350 get_afi_safi_str(
13351 afi,
13352 safi,
13353 true);
13354 json_object_string_add(
13355 json_llgr,
13356 afi_safi_str,
13357 "received");
13358 }
13359 }
13360 json_object_object_add(
13361 json_cap,
13362 "longLivedGracefulRestartByPeer",
13363 json_llgr);
13364 }
13365 }
13366
13367 /* Route Refresh */
13368 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13369 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13370 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13371 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13372 (CHECK_FLAG(p->cap,
13373 PEER_CAP_REFRESH_NEW_RCV) ||
13374 CHECK_FLAG(p->cap,
13375 PEER_CAP_REFRESH_OLD_RCV))) {
13376 if (CHECK_FLAG(
13377 p->cap,
13378 PEER_CAP_REFRESH_OLD_RCV) &&
13379 CHECK_FLAG(
13380 p->cap,
13381 PEER_CAP_REFRESH_NEW_RCV))
13382 json_object_string_add(
13383 json_cap,
13384 "routeRefresh",
13385 "advertisedAndReceivedOldNew");
13386 else {
13387 if (CHECK_FLAG(
13388 p->cap,
13389 PEER_CAP_REFRESH_OLD_RCV))
13390 json_object_string_add(
13391 json_cap,
13392 "routeRefresh",
13393 "advertisedAndReceivedOld");
13394 else
13395 json_object_string_add(
13396 json_cap,
13397 "routeRefresh",
13398 "advertisedAndReceivedNew");
13399 }
13400 } else if (CHECK_FLAG(p->cap,
13401 PEER_CAP_REFRESH_ADV))
13402 json_object_string_add(json_cap,
13403 "routeRefresh",
13404 "advertised");
13405 else if (CHECK_FLAG(p->cap,
13406 PEER_CAP_REFRESH_NEW_RCV) ||
13407 CHECK_FLAG(p->cap,
13408 PEER_CAP_REFRESH_OLD_RCV))
13409 json_object_string_add(json_cap,
13410 "routeRefresh",
13411 "received");
13412 }
13413
13414 /* Enhanced Route Refresh */
13415 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13416 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13417 if (CHECK_FLAG(p->cap,
13418 PEER_CAP_ENHANCED_RR_ADV) &&
13419 CHECK_FLAG(p->cap,
13420 PEER_CAP_ENHANCED_RR_RCV))
13421 json_object_string_add(
13422 json_cap,
13423 "enhancedRouteRefresh",
13424 "advertisedAndReceived");
13425 else if (CHECK_FLAG(p->cap,
13426 PEER_CAP_ENHANCED_RR_ADV))
13427 json_object_string_add(
13428 json_cap,
13429 "enhancedRouteRefresh",
13430 "advertised");
13431 else if (CHECK_FLAG(p->cap,
13432 PEER_CAP_ENHANCED_RR_RCV))
13433 json_object_string_add(
13434 json_cap,
13435 "enhancedRouteRefresh",
13436 "received");
13437 }
13438
13439 /* Multiprotocol Extensions */
13440 json_object *json_multi = NULL;
13441
13442 json_multi = json_object_new_object();
13443
13444 FOREACH_AFI_SAFI (afi, safi) {
13445 if (p->afc_adv[afi][safi] ||
13446 p->afc_recv[afi][safi]) {
13447 json_object *json_exten = NULL;
13448 json_exten = json_object_new_object();
13449
13450 if (p->afc_adv[afi][safi] &&
13451 p->afc_recv[afi][safi])
13452 json_object_boolean_true_add(
13453 json_exten,
13454 "advertisedAndReceived");
13455 else if (p->afc_adv[afi][safi])
13456 json_object_boolean_true_add(
13457 json_exten,
13458 "advertised");
13459 else if (p->afc_recv[afi][safi])
13460 json_object_boolean_true_add(
13461 json_exten, "received");
13462
13463 json_object_object_add(
13464 json_multi,
13465 get_afi_safi_str(afi, safi,
13466 true),
13467 json_exten);
13468 }
13469 }
13470 json_object_object_add(json_cap,
13471 "multiprotocolExtensions",
13472 json_multi);
13473
13474 /* Hostname capabilities */
13475 json_object *json_hname = NULL;
13476
13477 json_hname = json_object_new_object();
13478
13479 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13480 json_object_string_add(
13481 json_hname, "advHostName",
13482 bgp->peer_self->hostname
13483 ? bgp->peer_self->hostname
13484 : "n/a");
13485 json_object_string_add(
13486 json_hname, "advDomainName",
13487 bgp->peer_self->domainname
13488 ? bgp->peer_self->domainname
13489 : "n/a");
13490 }
13491
13492
13493 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13494 json_object_string_add(
13495 json_hname, "rcvHostName",
13496 p->hostname ? p->hostname : "n/a");
13497 json_object_string_add(
13498 json_hname, "rcvDomainName",
13499 p->domainname ? p->domainname : "n/a");
13500 }
13501
13502 json_object_object_add(json_cap, "hostName",
13503 json_hname);
13504
13505 /* Graceful Restart */
13506 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13507 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13508 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13509 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13510 json_object_string_add(
13511 json_cap, "gracefulRestart",
13512 "advertisedAndReceived");
13513 else if (CHECK_FLAG(p->cap,
13514 PEER_CAP_RESTART_ADV))
13515 json_object_string_add(
13516 json_cap,
13517 "gracefulRestartCapability",
13518 "advertised");
13519 else if (CHECK_FLAG(p->cap,
13520 PEER_CAP_RESTART_RCV))
13521 json_object_string_add(
13522 json_cap,
13523 "gracefulRestartCapability",
13524 "received");
13525
13526 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13527 int restart_af_count = 0;
13528 json_object *json_restart = NULL;
13529 json_restart = json_object_new_object();
13530
13531 json_object_int_add(
13532 json_cap,
13533 "gracefulRestartRemoteTimerMsecs",
13534 p->v_gr_restart * 1000);
13535
13536 FOREACH_AFI_SAFI (afi, safi) {
13537 if (CHECK_FLAG(
13538 p->af_cap[afi]
13539 [safi],
13540 PEER_CAP_RESTART_AF_RCV)) {
13541 json_object *json_sub =
13542 NULL;
13543 json_sub =
13544 json_object_new_object();
13545
13546 if (CHECK_FLAG(
13547 p->af_cap
13548 [afi]
13549 [safi],
13550 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13551 json_object_boolean_true_add(
13552 json_sub,
13553 "preserved");
13554 restart_af_count++;
13555 json_object_object_add(
13556 json_restart,
13557 get_afi_safi_str(
13558 afi,
13559 safi,
13560 true),
13561 json_sub);
13562 }
13563 }
13564 if (!restart_af_count) {
13565 json_object_string_add(
13566 json_cap,
13567 "addressFamiliesByPeer",
13568 "none");
13569 json_object_free(json_restart);
13570 } else
13571 json_object_object_add(
13572 json_cap,
13573 "addressFamiliesByPeer",
13574 json_restart);
13575 }
13576 }
13577 json_object_object_add(
13578 json_neigh, "neighborCapabilities", json_cap);
13579 } else {
13580 vty_out(vty, " Neighbor capabilities:\n");
13581
13582 /* AS4 */
13583 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13584 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13585 vty_out(vty, " 4 Byte AS:");
13586 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13587 vty_out(vty, " advertised");
13588 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13589 vty_out(vty, " %sreceived",
13590 CHECK_FLAG(p->cap,
13591 PEER_CAP_AS4_ADV)
13592 ? "and "
13593 : "");
13594 vty_out(vty, "\n");
13595 }
13596
13597 /* Extended Message Support */
13598 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13599 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13600 vty_out(vty, " Extended Message:");
13601 if (CHECK_FLAG(p->cap,
13602 PEER_CAP_EXTENDED_MESSAGE_ADV))
13603 vty_out(vty, " advertised");
13604 if (CHECK_FLAG(p->cap,
13605 PEER_CAP_EXTENDED_MESSAGE_RCV))
13606 vty_out(vty, " %sreceived",
13607 CHECK_FLAG(
13608 p->cap,
13609 PEER_CAP_EXTENDED_MESSAGE_ADV)
13610 ? "and "
13611 : "");
13612 vty_out(vty, "\n");
13613 }
13614
13615 /* AddPath */
13616 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13617 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13618 vty_out(vty, " AddPath:\n");
13619
13620 FOREACH_AFI_SAFI (afi, safi) {
13621 if (CHECK_FLAG(
13622 p->af_cap[afi][safi],
13623 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13624 CHECK_FLAG(
13625 p->af_cap[afi][safi],
13626 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13627 vty_out(vty, " %s: TX ",
13628 get_afi_safi_str(
13629 afi, safi,
13630 false));
13631
13632 if (CHECK_FLAG(
13633 p->af_cap[afi]
13634 [safi],
13635 PEER_CAP_ADDPATH_AF_TX_ADV))
13636 vty_out(vty,
13637 "advertised");
13638
13639 if (CHECK_FLAG(
13640 p->af_cap[afi]
13641 [safi],
13642 PEER_CAP_ADDPATH_AF_TX_RCV))
13643 vty_out(vty,
13644 "%sreceived",
13645 CHECK_FLAG(
13646 p->af_cap
13647 [afi]
13648 [safi],
13649 PEER_CAP_ADDPATH_AF_TX_ADV)
13650 ? " and "
13651 : "");
13652
13653 vty_out(vty, "\n");
13654 }
13655
13656 if (CHECK_FLAG(
13657 p->af_cap[afi][safi],
13658 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13659 CHECK_FLAG(
13660 p->af_cap[afi][safi],
13661 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13662 vty_out(vty, " %s: RX ",
13663 get_afi_safi_str(
13664 afi, safi,
13665 false));
13666
13667 if (CHECK_FLAG(
13668 p->af_cap[afi]
13669 [safi],
13670 PEER_CAP_ADDPATH_AF_RX_ADV))
13671 vty_out(vty,
13672 "advertised");
13673
13674 if (CHECK_FLAG(
13675 p->af_cap[afi]
13676 [safi],
13677 PEER_CAP_ADDPATH_AF_RX_RCV))
13678 vty_out(vty,
13679 "%sreceived",
13680 CHECK_FLAG(
13681 p->af_cap
13682 [afi]
13683 [safi],
13684 PEER_CAP_ADDPATH_AF_RX_ADV)
13685 ? " and "
13686 : "");
13687
13688 vty_out(vty, "\n");
13689 }
13690 }
13691 }
13692
13693 /* Dynamic */
13694 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13695 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13696 vty_out(vty, " Dynamic:");
13697 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13698 vty_out(vty, " advertised");
13699 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13700 vty_out(vty, " %sreceived",
13701 CHECK_FLAG(p->cap,
13702 PEER_CAP_DYNAMIC_ADV)
13703 ? "and "
13704 : "");
13705 vty_out(vty, "\n");
13706 }
13707
13708 /* Role */
13709 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13710 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13711 vty_out(vty, " Role:");
13712 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13713 vty_out(vty, " advertised");
13714 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13715 vty_out(vty, " %sreceived",
13716 CHECK_FLAG(p->cap,
13717 PEER_CAP_ROLE_ADV)
13718 ? "and "
13719 : "");
13720 vty_out(vty, "\n");
13721 }
13722
13723 /* Extended nexthop */
13724 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13725 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13726 vty_out(vty, " Extended nexthop:");
13727 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13728 vty_out(vty, " advertised");
13729 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13730 vty_out(vty, " %sreceived",
13731 CHECK_FLAG(p->cap,
13732 PEER_CAP_ENHE_ADV)
13733 ? "and "
13734 : "");
13735 vty_out(vty, "\n");
13736
13737 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13738 vty_out(vty,
13739 " Address families by peer:\n ");
13740 for (safi = SAFI_UNICAST;
13741 safi < SAFI_MAX; safi++)
13742 if (CHECK_FLAG(
13743 p->af_cap[AFI_IP]
13744 [safi],
13745 PEER_CAP_ENHE_AF_RCV))
13746 vty_out(vty,
13747 " %s\n",
13748 get_afi_safi_str(
13749 AFI_IP,
13750 safi,
13751 false));
13752 }
13753 }
13754
13755 /* Long-lived Graceful Restart */
13756 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13757 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13758 vty_out(vty,
13759 " Long-lived Graceful Restart:");
13760 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13761 vty_out(vty, " advertised");
13762 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13763 vty_out(vty, " %sreceived",
13764 CHECK_FLAG(p->cap,
13765 PEER_CAP_LLGR_ADV)
13766 ? "and "
13767 : "");
13768 vty_out(vty, "\n");
13769
13770 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13771 vty_out(vty,
13772 " Address families by peer:\n");
13773 FOREACH_AFI_SAFI (afi, safi)
13774 if (CHECK_FLAG(
13775 p->af_cap[afi]
13776 [safi],
13777 PEER_CAP_LLGR_AF_RCV))
13778 vty_out(vty,
13779 " %s\n",
13780 get_afi_safi_str(
13781 afi,
13782 safi,
13783 false));
13784 }
13785 }
13786
13787 /* Route Refresh */
13788 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13789 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13790 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13791 vty_out(vty, " Route refresh:");
13792 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13793 vty_out(vty, " advertised");
13794 if (CHECK_FLAG(p->cap,
13795 PEER_CAP_REFRESH_NEW_RCV) ||
13796 CHECK_FLAG(p->cap,
13797 PEER_CAP_REFRESH_OLD_RCV))
13798 vty_out(vty, " %sreceived(%s)",
13799 CHECK_FLAG(p->cap,
13800 PEER_CAP_REFRESH_ADV)
13801 ? "and "
13802 : "",
13803 (CHECK_FLAG(
13804 p->cap,
13805 PEER_CAP_REFRESH_OLD_RCV) &&
13806 CHECK_FLAG(
13807 p->cap,
13808 PEER_CAP_REFRESH_NEW_RCV))
13809 ? "old & new"
13810 : CHECK_FLAG(
13811 p->cap,
13812 PEER_CAP_REFRESH_OLD_RCV)
13813 ? "old"
13814 : "new");
13815
13816 vty_out(vty, "\n");
13817 }
13818
13819 /* Enhanced Route Refresh */
13820 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13821 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13822 vty_out(vty, " Enhanced Route Refresh:");
13823 if (CHECK_FLAG(p->cap,
13824 PEER_CAP_ENHANCED_RR_ADV))
13825 vty_out(vty, " advertised");
13826 if (CHECK_FLAG(p->cap,
13827 PEER_CAP_ENHANCED_RR_RCV))
13828 vty_out(vty, " %sreceived",
13829 CHECK_FLAG(p->cap,
13830 PEER_CAP_REFRESH_ADV)
13831 ? "and "
13832 : "");
13833 vty_out(vty, "\n");
13834 }
13835
13836 /* Multiprotocol Extensions */
13837 FOREACH_AFI_SAFI (afi, safi)
13838 if (p->afc_adv[afi][safi] ||
13839 p->afc_recv[afi][safi]) {
13840 vty_out(vty, " Address Family %s:",
13841 get_afi_safi_str(afi, safi,
13842 false));
13843 if (p->afc_adv[afi][safi])
13844 vty_out(vty, " advertised");
13845 if (p->afc_recv[afi][safi])
13846 vty_out(vty, " %sreceived",
13847 p->afc_adv[afi][safi]
13848 ? "and "
13849 : "");
13850 vty_out(vty, "\n");
13851 }
13852
13853 /* Hostname capability */
13854 vty_out(vty, " Hostname Capability:");
13855
13856 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13857 vty_out(vty,
13858 " advertised (name: %s,domain name: %s)",
13859 bgp->peer_self->hostname
13860 ? bgp->peer_self->hostname
13861 : "n/a",
13862 bgp->peer_self->domainname
13863 ? bgp->peer_self->domainname
13864 : "n/a");
13865 } else {
13866 vty_out(vty, " not advertised");
13867 }
13868
13869 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13870 vty_out(vty,
13871 " received (name: %s,domain name: %s)",
13872 p->hostname ? p->hostname : "n/a",
13873 p->domainname ? p->domainname : "n/a");
13874 } else {
13875 vty_out(vty, " not received");
13876 }
13877
13878 vty_out(vty, "\n");
13879
13880 /* Graceful Restart */
13881 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13882 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13883 vty_out(vty,
13884 " Graceful Restart Capability:");
13885 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13886 vty_out(vty, " advertised");
13887 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13888 vty_out(vty, " %sreceived",
13889 CHECK_FLAG(p->cap,
13890 PEER_CAP_RESTART_ADV)
13891 ? "and "
13892 : "");
13893 vty_out(vty, "\n");
13894
13895 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13896 int restart_af_count = 0;
13897
13898 vty_out(vty,
13899 " Remote Restart timer is %d seconds\n",
13900 p->v_gr_restart);
13901 vty_out(vty,
13902 " Address families by peer:\n ");
13903
13904 FOREACH_AFI_SAFI (afi, safi)
13905 if (CHECK_FLAG(
13906 p->af_cap[afi]
13907 [safi],
13908 PEER_CAP_RESTART_AF_RCV)) {
13909 vty_out(vty, "%s%s(%s)",
13910 restart_af_count
13911 ? ", "
13912 : "",
13913 get_afi_safi_str(
13914 afi,
13915 safi,
13916 false),
13917 CHECK_FLAG(
13918 p->af_cap
13919 [afi]
13920 [safi],
13921 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13922 ? "preserved"
13923 : "not preserved");
13924 restart_af_count++;
13925 }
13926 if (!restart_af_count)
13927 vty_out(vty, "none");
13928 vty_out(vty, "\n");
13929 }
13930 } /* Graceful Restart */
13931 }
13932 }
13933
13934 /* graceful restart information */
13935 json_object *json_grace = NULL;
13936 json_object *json_grace_send = NULL;
13937 json_object *json_grace_recv = NULL;
13938 int eor_send_af_count = 0;
13939 int eor_receive_af_count = 0;
13940
13941 if (use_json) {
13942 json_grace = json_object_new_object();
13943 json_grace_send = json_object_new_object();
13944 json_grace_recv = json_object_new_object();
13945
13946 if ((peer_established(p)) &&
13947 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13948 FOREACH_AFI_SAFI (afi, safi) {
13949 if (CHECK_FLAG(p->af_sflags[afi][safi],
13950 PEER_STATUS_EOR_SEND)) {
13951 json_object_boolean_true_add(
13952 json_grace_send,
13953 get_afi_safi_str(afi, safi,
13954 true));
13955 eor_send_af_count++;
13956 }
13957 }
13958 FOREACH_AFI_SAFI (afi, safi) {
13959 if (CHECK_FLAG(p->af_sflags[afi][safi],
13960 PEER_STATUS_EOR_RECEIVED)) {
13961 json_object_boolean_true_add(
13962 json_grace_recv,
13963 get_afi_safi_str(afi, safi,
13964 true));
13965 eor_receive_af_count++;
13966 }
13967 }
13968 }
13969 json_object_object_add(json_grace, "endOfRibSend",
13970 json_grace_send);
13971 json_object_object_add(json_grace, "endOfRibRecv",
13972 json_grace_recv);
13973
13974
13975 if (p->t_gr_restart)
13976 json_object_int_add(
13977 json_grace, "gracefulRestartTimerMsecs",
13978 thread_timer_remain_second(p->t_gr_restart) *
13979 1000);
13980
13981 if (p->t_gr_stale)
13982 json_object_int_add(
13983 json_grace, "gracefulStalepathTimerMsecs",
13984 thread_timer_remain_second(p->t_gr_stale) *
13985 1000);
13986 /* more gr info in new format */
13987 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13988 json_object_object_add(json_neigh, "gracefulRestartInfo",
13989 json_grace);
13990 } else {
13991 vty_out(vty, " Graceful restart information:\n");
13992 if ((peer_established(p)) &&
13993 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13994
13995 vty_out(vty, " End-of-RIB send: ");
13996 FOREACH_AFI_SAFI (afi, safi) {
13997 if (CHECK_FLAG(p->af_sflags[afi][safi],
13998 PEER_STATUS_EOR_SEND)) {
13999 vty_out(vty, "%s%s",
14000 eor_send_af_count ? ", " : "",
14001 get_afi_safi_str(afi, safi,
14002 false));
14003 eor_send_af_count++;
14004 }
14005 }
14006 vty_out(vty, "\n");
14007 vty_out(vty, " End-of-RIB received: ");
14008 FOREACH_AFI_SAFI (afi, safi) {
14009 if (CHECK_FLAG(p->af_sflags[afi][safi],
14010 PEER_STATUS_EOR_RECEIVED)) {
14011 vty_out(vty, "%s%s",
14012 eor_receive_af_count ? ", "
14013 : "",
14014 get_afi_safi_str(afi, safi,
14015 false));
14016 eor_receive_af_count++;
14017 }
14018 }
14019 vty_out(vty, "\n");
14020 }
14021
14022 if (p->t_gr_restart)
14023 vty_out(vty,
14024 " The remaining time of restart timer is %ld\n",
14025 thread_timer_remain_second(p->t_gr_restart));
14026
14027 if (p->t_gr_stale)
14028 vty_out(vty,
14029 " The remaining time of stalepath timer is %ld\n",
14030 thread_timer_remain_second(p->t_gr_stale));
14031
14032 /* more gr info in new format */
14033 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
14034 }
14035
14036 if (use_json) {
14037 json_object *json_stat = NULL;
14038 json_stat = json_object_new_object();
14039 /* Packet counts. */
14040
14041 atomic_size_t outq_count, inq_count;
14042 outq_count = atomic_load_explicit(&p->obuf->count,
14043 memory_order_relaxed);
14044 inq_count = atomic_load_explicit(&p->ibuf->count,
14045 memory_order_relaxed);
14046
14047 json_object_int_add(json_stat, "depthInq",
14048 (unsigned long)inq_count);
14049 json_object_int_add(json_stat, "depthOutq",
14050 (unsigned long)outq_count);
14051 json_object_int_add(json_stat, "opensSent",
14052 atomic_load_explicit(&p->open_out,
14053 memory_order_relaxed));
14054 json_object_int_add(json_stat, "opensRecv",
14055 atomic_load_explicit(&p->open_in,
14056 memory_order_relaxed));
14057 json_object_int_add(json_stat, "notificationsSent",
14058 atomic_load_explicit(&p->notify_out,
14059 memory_order_relaxed));
14060 json_object_int_add(json_stat, "notificationsRecv",
14061 atomic_load_explicit(&p->notify_in,
14062 memory_order_relaxed));
14063 json_object_int_add(json_stat, "updatesSent",
14064 atomic_load_explicit(&p->update_out,
14065 memory_order_relaxed));
14066 json_object_int_add(json_stat, "updatesRecv",
14067 atomic_load_explicit(&p->update_in,
14068 memory_order_relaxed));
14069 json_object_int_add(json_stat, "keepalivesSent",
14070 atomic_load_explicit(&p->keepalive_out,
14071 memory_order_relaxed));
14072 json_object_int_add(json_stat, "keepalivesRecv",
14073 atomic_load_explicit(&p->keepalive_in,
14074 memory_order_relaxed));
14075 json_object_int_add(json_stat, "routeRefreshSent",
14076 atomic_load_explicit(&p->refresh_out,
14077 memory_order_relaxed));
14078 json_object_int_add(json_stat, "routeRefreshRecv",
14079 atomic_load_explicit(&p->refresh_in,
14080 memory_order_relaxed));
14081 json_object_int_add(json_stat, "capabilitySent",
14082 atomic_load_explicit(&p->dynamic_cap_out,
14083 memory_order_relaxed));
14084 json_object_int_add(json_stat, "capabilityRecv",
14085 atomic_load_explicit(&p->dynamic_cap_in,
14086 memory_order_relaxed));
14087 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14088 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14089 json_object_object_add(json_neigh, "messageStats", json_stat);
14090 } else {
14091 atomic_size_t outq_count, inq_count, open_out, open_in,
14092 notify_out, notify_in, update_out, update_in,
14093 keepalive_out, keepalive_in, refresh_out, refresh_in,
14094 dynamic_cap_out, dynamic_cap_in;
14095 outq_count = atomic_load_explicit(&p->obuf->count,
14096 memory_order_relaxed);
14097 inq_count = atomic_load_explicit(&p->ibuf->count,
14098 memory_order_relaxed);
14099 open_out = atomic_load_explicit(&p->open_out,
14100 memory_order_relaxed);
14101 open_in =
14102 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14103 notify_out = atomic_load_explicit(&p->notify_out,
14104 memory_order_relaxed);
14105 notify_in = atomic_load_explicit(&p->notify_in,
14106 memory_order_relaxed);
14107 update_out = atomic_load_explicit(&p->update_out,
14108 memory_order_relaxed);
14109 update_in = atomic_load_explicit(&p->update_in,
14110 memory_order_relaxed);
14111 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14112 memory_order_relaxed);
14113 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14114 memory_order_relaxed);
14115 refresh_out = atomic_load_explicit(&p->refresh_out,
14116 memory_order_relaxed);
14117 refresh_in = atomic_load_explicit(&p->refresh_in,
14118 memory_order_relaxed);
14119 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14120 memory_order_relaxed);
14121 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14122 memory_order_relaxed);
14123
14124 /* Packet counts. */
14125 vty_out(vty, " Message statistics:\n");
14126 vty_out(vty, " Inq depth is %zu\n", inq_count);
14127 vty_out(vty, " Outq depth is %zu\n", outq_count);
14128 vty_out(vty, " Sent Rcvd\n");
14129 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14130 open_in);
14131 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14132 notify_in);
14133 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14134 update_in);
14135 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14136 keepalive_in);
14137 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14138 refresh_in);
14139 vty_out(vty, " Capability: %10zu %10zu\n",
14140 dynamic_cap_out, dynamic_cap_in);
14141 vty_out(vty, " Total: %10u %10u\n",
14142 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14143 }
14144
14145 if (use_json) {
14146 /* advertisement-interval */
14147 json_object_int_add(json_neigh,
14148 "minBtwnAdvertisementRunsTimerMsecs",
14149 p->v_routeadv * 1000);
14150
14151 /* Update-source. */
14152 if (p->update_if || p->update_source) {
14153 if (p->update_if)
14154 json_object_string_add(json_neigh,
14155 "updateSource",
14156 p->update_if);
14157 else if (p->update_source)
14158 json_object_string_addf(json_neigh,
14159 "updateSource", "%pSU",
14160 p->update_source);
14161 }
14162 } else {
14163 /* advertisement-interval */
14164 vty_out(vty,
14165 " Minimum time between advertisement runs is %d seconds\n",
14166 p->v_routeadv);
14167
14168 /* Update-source. */
14169 if (p->update_if || p->update_source) {
14170 vty_out(vty, " Update source is ");
14171 if (p->update_if)
14172 vty_out(vty, "%s", p->update_if);
14173 else if (p->update_source)
14174 vty_out(vty, "%pSU", p->update_source);
14175 vty_out(vty, "\n");
14176 }
14177
14178 vty_out(vty, "\n");
14179 }
14180
14181 /* Address Family Information */
14182 json_object *json_hold = NULL;
14183
14184 if (use_json)
14185 json_hold = json_object_new_object();
14186
14187 FOREACH_AFI_SAFI (afi, safi)
14188 if (p->afc[afi][safi])
14189 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14190 json_hold);
14191
14192 if (use_json) {
14193 json_object_object_add(json_neigh, "addressFamilyInfo",
14194 json_hold);
14195 json_object_int_add(json_neigh, "connectionsEstablished",
14196 p->established);
14197 json_object_int_add(json_neigh, "connectionsDropped",
14198 p->dropped);
14199 } else
14200 vty_out(vty, " Connections established %d; dropped %d\n",
14201 p->established, p->dropped);
14202
14203 if (!p->last_reset) {
14204 if (use_json)
14205 json_object_string_add(json_neigh, "lastReset",
14206 "never");
14207 else
14208 vty_out(vty, " Last reset never\n");
14209 } else {
14210 if (use_json) {
14211 time_t uptime;
14212 struct tm tm;
14213
14214 uptime = monotime(NULL);
14215 uptime -= p->resettime;
14216 gmtime_r(&uptime, &tm);
14217
14218 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14219 (tm.tm_sec * 1000)
14220 + (tm.tm_min * 60000)
14221 + (tm.tm_hour * 3600000));
14222 bgp_show_peer_reset(NULL, p, json_neigh, true);
14223 } else {
14224 vty_out(vty, " Last reset %s, ",
14225 peer_uptime(p->resettime, timebuf,
14226 BGP_UPTIME_LEN, 0, NULL));
14227
14228 bgp_show_peer_reset(vty, p, NULL, false);
14229 if (p->last_reset_cause_size) {
14230 msg = p->last_reset_cause;
14231 vty_out(vty,
14232 " Message received that caused BGP to send a NOTIFICATION:\n ");
14233 for (i = 1; i <= p->last_reset_cause_size;
14234 i++) {
14235 vty_out(vty, "%02X", *msg++);
14236
14237 if (i != p->last_reset_cause_size) {
14238 if (i % 16 == 0) {
14239 vty_out(vty, "\n ");
14240 } else if (i % 4 == 0) {
14241 vty_out(vty, " ");
14242 }
14243 }
14244 }
14245 vty_out(vty, "\n");
14246 }
14247 }
14248 }
14249
14250 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14251 if (use_json)
14252 json_object_boolean_true_add(json_neigh,
14253 "prefixesConfigExceedMax");
14254 else
14255 vty_out(vty,
14256 " Peer had exceeded the max. no. of prefixes configured.\n");
14257
14258 if (p->t_pmax_restart) {
14259 if (use_json) {
14260 json_object_boolean_true_add(
14261 json_neigh, "reducePrefixNumFrom");
14262 json_object_int_add(json_neigh,
14263 "restartInTimerMsec",
14264 thread_timer_remain_second(
14265 p->t_pmax_restart)
14266 * 1000);
14267 } else
14268 vty_out(vty,
14269 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14270 p->host, thread_timer_remain_second(
14271 p->t_pmax_restart));
14272 } else {
14273 if (use_json)
14274 json_object_boolean_true_add(
14275 json_neigh,
14276 "reducePrefixNumAndClearIpBgp");
14277 else
14278 vty_out(vty,
14279 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14280 p->host);
14281 }
14282 }
14283
14284 /* EBGP Multihop and GTSM */
14285 if (p->sort != BGP_PEER_IBGP) {
14286 if (use_json) {
14287 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14288 json_object_int_add(json_neigh,
14289 "externalBgpNbrMaxHopsAway",
14290 p->gtsm_hops);
14291 else
14292 json_object_int_add(json_neigh,
14293 "externalBgpNbrMaxHopsAway",
14294 p->ttl);
14295 } else {
14296 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14297 vty_out(vty,
14298 " External BGP neighbor may be up to %d hops away.\n",
14299 p->gtsm_hops);
14300 else
14301 vty_out(vty,
14302 " External BGP neighbor may be up to %d hops away.\n",
14303 p->ttl);
14304 }
14305 } else {
14306 if (use_json) {
14307 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14308 json_object_int_add(json_neigh,
14309 "internalBgpNbrMaxHopsAway",
14310 p->gtsm_hops);
14311 else
14312 json_object_int_add(json_neigh,
14313 "internalBgpNbrMaxHopsAway",
14314 p->ttl);
14315 } else {
14316 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14317 vty_out(vty,
14318 " Internal BGP neighbor may be up to %d hops away.\n",
14319 p->gtsm_hops);
14320 else
14321 vty_out(vty,
14322 " Internal BGP neighbor may be up to %d hops away.\n",
14323 p->ttl);
14324 }
14325 }
14326
14327 /* Local address. */
14328 if (p->su_local) {
14329 if (use_json) {
14330 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14331 p->su_local);
14332 json_object_int_add(json_neigh, "portLocal",
14333 ntohs(p->su_local->sin.sin_port));
14334 } else
14335 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14336 p->su_local, ntohs(p->su_local->sin.sin_port));
14337 } else {
14338 if (use_json) {
14339 json_object_string_add(json_neigh, "hostLocal",
14340 "Unknown");
14341 json_object_int_add(json_neigh, "portLocal", -1);
14342 }
14343 }
14344
14345 /* Remote address. */
14346 if (p->su_remote) {
14347 if (use_json) {
14348 json_object_string_addf(json_neigh, "hostForeign",
14349 "%pSU", p->su_remote);
14350 json_object_int_add(json_neigh, "portForeign",
14351 ntohs(p->su_remote->sin.sin_port));
14352 } else
14353 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14354 p->su_remote,
14355 ntohs(p->su_remote->sin.sin_port));
14356 } else {
14357 if (use_json) {
14358 json_object_string_add(json_neigh, "hostForeign",
14359 "Unknown");
14360 json_object_int_add(json_neigh, "portForeign", -1);
14361 }
14362 }
14363
14364 /* Nexthop display. */
14365 if (p->su_local) {
14366 if (use_json) {
14367 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14368 &p->nexthop.v4);
14369 json_object_string_addf(json_neigh, "nexthopGlobal",
14370 "%pI6", &p->nexthop.v6_global);
14371 json_object_string_addf(json_neigh, "nexthopLocal",
14372 "%pI6", &p->nexthop.v6_local);
14373 if (p->shared_network)
14374 json_object_string_add(json_neigh,
14375 "bgpConnection",
14376 "sharedNetwork");
14377 else
14378 json_object_string_add(json_neigh,
14379 "bgpConnection",
14380 "nonSharedNetwork");
14381 } else {
14382 vty_out(vty, "Nexthop: %s\n",
14383 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14384 sizeof(buf1)));
14385 vty_out(vty, "Nexthop global: %s\n",
14386 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14387 sizeof(buf1)));
14388 vty_out(vty, "Nexthop local: %s\n",
14389 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14390 sizeof(buf1)));
14391 vty_out(vty, "BGP connection: %s\n",
14392 p->shared_network ? "shared network"
14393 : "non shared network");
14394 }
14395 }
14396
14397 /* Timer information. */
14398 if (use_json) {
14399 json_object_int_add(json_neigh, "connectRetryTimer",
14400 p->v_connect);
14401 if (peer_established(p) && p->rtt)
14402 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14403 p->rtt);
14404 if (p->t_start)
14405 json_object_int_add(
14406 json_neigh, "nextStartTimerDueInMsecs",
14407 thread_timer_remain_second(p->t_start) * 1000);
14408 if (p->t_connect)
14409 json_object_int_add(
14410 json_neigh, "nextConnectTimerDueInMsecs",
14411 thread_timer_remain_second(p->t_connect)
14412 * 1000);
14413 if (p->t_routeadv) {
14414 json_object_int_add(json_neigh, "mraiInterval",
14415 p->v_routeadv);
14416 json_object_int_add(
14417 json_neigh, "mraiTimerExpireInMsecs",
14418 thread_timer_remain_second(p->t_routeadv)
14419 * 1000);
14420 }
14421 if (p->password)
14422 json_object_int_add(json_neigh, "authenticationEnabled",
14423 1);
14424
14425 if (p->t_read)
14426 json_object_string_add(json_neigh, "readThread", "on");
14427 else
14428 json_object_string_add(json_neigh, "readThread", "off");
14429
14430 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14431 json_object_string_add(json_neigh, "writeThread", "on");
14432 else
14433 json_object_string_add(json_neigh, "writeThread",
14434 "off");
14435 } else {
14436 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14437 p->v_connect);
14438 if (peer_established(p) && p->rtt)
14439 vty_out(vty, "Estimated round trip time: %d ms\n",
14440 p->rtt);
14441 if (p->t_start)
14442 vty_out(vty, "Next start timer due in %ld seconds\n",
14443 thread_timer_remain_second(p->t_start));
14444 if (p->t_connect)
14445 vty_out(vty, "Next connect timer due in %ld seconds\n",
14446 thread_timer_remain_second(p->t_connect));
14447 if (p->t_routeadv)
14448 vty_out(vty,
14449 "MRAI (interval %u) timer expires in %ld seconds\n",
14450 p->v_routeadv,
14451 thread_timer_remain_second(p->t_routeadv));
14452 if (p->password)
14453 vty_out(vty, "Peer Authentication Enabled\n");
14454
14455 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14456 p->t_read ? "on" : "off",
14457 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14458 ? "on"
14459 : "off", p->fd);
14460 }
14461
14462 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14463 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14464 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14465
14466 if (!use_json)
14467 vty_out(vty, "\n");
14468
14469 /* BFD information. */
14470 if (p->bfd_config)
14471 bgp_bfd_show_info(vty, p, json_neigh);
14472
14473 if (use_json) {
14474 if (p->conf_if) /* Configured interface name. */
14475 json_object_object_add(json, p->conf_if, json_neigh);
14476 else /* Configured IP address. */
14477 json_object_object_add(json, p->host, json_neigh);
14478 }
14479 }
14480
14481 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14482 enum show_type type,
14483 union sockunion *su,
14484 const char *conf_if, afi_t afi,
14485 bool use_json)
14486 {
14487 struct listnode *node, *nnode;
14488 struct peer *peer;
14489 int find = 0;
14490 safi_t safi = SAFI_UNICAST;
14491 json_object *json = NULL;
14492 json_object *json_neighbor = NULL;
14493
14494 if (use_json) {
14495 json = json_object_new_object();
14496 json_neighbor = json_object_new_object();
14497 }
14498
14499 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14500
14501 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14502 continue;
14503
14504 if ((peer->afc[afi][safi]) == 0)
14505 continue;
14506
14507 if (type == show_all) {
14508 bgp_show_peer_gr_status(vty, peer, use_json,
14509 json_neighbor);
14510
14511 if (use_json) {
14512 json_object_object_add(json, peer->host,
14513 json_neighbor);
14514 json_neighbor = NULL;
14515 }
14516
14517 } else if (type == show_peer) {
14518 if (conf_if) {
14519 if ((peer->conf_if
14520 && !strcmp(peer->conf_if, conf_if))
14521 || (peer->hostname
14522 && !strcmp(peer->hostname, conf_if))) {
14523 find = 1;
14524 bgp_show_peer_gr_status(vty, peer,
14525 use_json,
14526 json_neighbor);
14527 }
14528 } else {
14529 if (sockunion_same(&peer->su, su)) {
14530 find = 1;
14531 bgp_show_peer_gr_status(vty, peer,
14532 use_json,
14533 json_neighbor);
14534 }
14535 }
14536 if (use_json && find)
14537 json_object_object_add(json, peer->host,
14538 json_neighbor);
14539 }
14540
14541 if (find) {
14542 json_neighbor = NULL;
14543 break;
14544 }
14545 }
14546
14547 if (type == show_peer && !find) {
14548 if (use_json)
14549 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14550 else
14551 vty_out(vty, "%% No such neighbor\n");
14552 }
14553 if (use_json) {
14554 if (json_neighbor)
14555 json_object_free(json_neighbor);
14556 vty_json(vty, json);
14557 } else {
14558 vty_out(vty, "\n");
14559 }
14560
14561 return CMD_SUCCESS;
14562 }
14563
14564 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14565 enum show_type type, union sockunion *su,
14566 const char *conf_if, bool use_json,
14567 json_object *json)
14568 {
14569 struct listnode *node, *nnode;
14570 struct peer *peer;
14571 int find = 0;
14572 bool nbr_output = false;
14573 afi_t afi = AFI_MAX;
14574 safi_t safi = SAFI_MAX;
14575
14576 if (type == show_ipv4_peer || type == show_ipv4_all) {
14577 afi = AFI_IP;
14578 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14579 afi = AFI_IP6;
14580 }
14581
14582 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14583 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14584 continue;
14585
14586 switch (type) {
14587 case show_all:
14588 bgp_show_peer(vty, peer, use_json, json);
14589 nbr_output = true;
14590 break;
14591 case show_peer:
14592 if (conf_if) {
14593 if ((peer->conf_if
14594 && !strcmp(peer->conf_if, conf_if))
14595 || (peer->hostname
14596 && !strcmp(peer->hostname, conf_if))) {
14597 find = 1;
14598 bgp_show_peer(vty, peer, use_json,
14599 json);
14600 }
14601 } else {
14602 if (sockunion_same(&peer->su, su)) {
14603 find = 1;
14604 bgp_show_peer(vty, peer, use_json,
14605 json);
14606 }
14607 }
14608 break;
14609 case show_ipv4_peer:
14610 case show_ipv6_peer:
14611 FOREACH_SAFI (safi) {
14612 if (peer->afc[afi][safi]) {
14613 if (conf_if) {
14614 if ((peer->conf_if
14615 && !strcmp(peer->conf_if, conf_if))
14616 || (peer->hostname
14617 && !strcmp(peer->hostname, conf_if))) {
14618 find = 1;
14619 bgp_show_peer(vty, peer, use_json,
14620 json);
14621 break;
14622 }
14623 } else {
14624 if (sockunion_same(&peer->su, su)) {
14625 find = 1;
14626 bgp_show_peer(vty, peer, use_json,
14627 json);
14628 break;
14629 }
14630 }
14631 }
14632 }
14633 break;
14634 case show_ipv4_all:
14635 case show_ipv6_all:
14636 FOREACH_SAFI (safi) {
14637 if (peer->afc[afi][safi]) {
14638 bgp_show_peer(vty, peer, use_json, json);
14639 nbr_output = true;
14640 break;
14641 }
14642 }
14643 break;
14644 }
14645 }
14646
14647 if ((type == show_peer || type == show_ipv4_peer ||
14648 type == show_ipv6_peer) && !find) {
14649 if (use_json)
14650 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14651 else
14652 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14653 }
14654
14655 if (type != show_peer && type != show_ipv4_peer &&
14656 type != show_ipv6_peer && !nbr_output && !use_json)
14657 vty_out(vty, "%% No BGP neighbors found\n");
14658
14659 if (use_json) {
14660 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14661 json, JSON_C_TO_STRING_PRETTY));
14662 } else {
14663 vty_out(vty, "\n");
14664 }
14665
14666 return CMD_SUCCESS;
14667 }
14668
14669 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14670 enum show_type type,
14671 const char *ip_str,
14672 afi_t afi, bool use_json)
14673 {
14674
14675 int ret;
14676 struct bgp *bgp;
14677 union sockunion su;
14678
14679 bgp = bgp_get_default();
14680
14681 if (!bgp)
14682 return;
14683
14684 if (!use_json)
14685 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14686 NULL);
14687
14688 if (ip_str) {
14689 ret = str2sockunion(ip_str, &su);
14690 if (ret < 0)
14691 bgp_show_neighbor_graceful_restart(
14692 vty, bgp, type, NULL, ip_str, afi, use_json);
14693 else
14694 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14695 NULL, afi, use_json);
14696 } else
14697 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14698 afi, use_json);
14699 }
14700
14701 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14702 enum show_type type,
14703 const char *ip_str,
14704 bool use_json)
14705 {
14706 struct listnode *node, *nnode;
14707 struct bgp *bgp;
14708 union sockunion su;
14709 json_object *json = NULL;
14710 int ret, is_first = 1;
14711 bool nbr_output = false;
14712
14713 if (use_json)
14714 vty_out(vty, "{\n");
14715
14716 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14717 nbr_output = true;
14718 if (use_json) {
14719 if (!(json = json_object_new_object())) {
14720 flog_err(
14721 EC_BGP_JSON_MEM_ERROR,
14722 "Unable to allocate memory for JSON object");
14723 vty_out(vty,
14724 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14725 return;
14726 }
14727
14728 json_object_int_add(json, "vrfId",
14729 (bgp->vrf_id == VRF_UNKNOWN)
14730 ? -1
14731 : (int64_t)bgp->vrf_id);
14732 json_object_string_add(
14733 json, "vrfName",
14734 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14735 ? VRF_DEFAULT_NAME
14736 : bgp->name);
14737
14738 if (!is_first)
14739 vty_out(vty, ",\n");
14740 else
14741 is_first = 0;
14742
14743 vty_out(vty, "\"%s\":",
14744 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14745 ? VRF_DEFAULT_NAME
14746 : bgp->name);
14747 } else {
14748 vty_out(vty, "\nInstance %s:\n",
14749 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14750 ? VRF_DEFAULT_NAME
14751 : bgp->name);
14752 }
14753
14754 if (type == show_peer || type == show_ipv4_peer ||
14755 type == show_ipv6_peer) {
14756 ret = str2sockunion(ip_str, &su);
14757 if (ret < 0)
14758 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14759 use_json, json);
14760 else
14761 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14762 use_json, json);
14763 } else {
14764 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14765 use_json, json);
14766 }
14767 json_object_free(json);
14768 json = NULL;
14769 }
14770
14771 if (use_json)
14772 vty_out(vty, "}\n");
14773 else if (!nbr_output)
14774 vty_out(vty, "%% BGP instance not found\n");
14775 }
14776
14777 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14778 enum show_type type, const char *ip_str,
14779 bool use_json)
14780 {
14781 int ret;
14782 struct bgp *bgp;
14783 union sockunion su;
14784 json_object *json = NULL;
14785
14786 if (name) {
14787 if (strmatch(name, "all")) {
14788 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14789 use_json);
14790 return CMD_SUCCESS;
14791 } else {
14792 bgp = bgp_lookup_by_name(name);
14793 if (!bgp) {
14794 if (use_json) {
14795 json = json_object_new_object();
14796 vty_json(vty, json);
14797 } else
14798 vty_out(vty,
14799 "%% BGP instance not found\n");
14800
14801 return CMD_WARNING;
14802 }
14803 }
14804 } else {
14805 bgp = bgp_get_default();
14806 }
14807
14808 if (bgp) {
14809 json = json_object_new_object();
14810 if (ip_str) {
14811 ret = str2sockunion(ip_str, &su);
14812 if (ret < 0)
14813 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14814 use_json, json);
14815 else
14816 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14817 use_json, json);
14818 } else {
14819 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14820 json);
14821 }
14822 json_object_free(json);
14823 } else {
14824 if (use_json)
14825 vty_out(vty, "{}\n");
14826 else
14827 vty_out(vty, "%% BGP instance not found\n");
14828 }
14829
14830 return CMD_SUCCESS;
14831 }
14832
14833
14834
14835 /* "show [ip] bgp neighbors graceful-restart" commands. */
14836 DEFUN (show_ip_bgp_neighbors_graceful_restart,
14837 show_ip_bgp_neighbors_graceful_restart_cmd,
14838 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14839 SHOW_STR
14840 BGP_STR
14841 IP_STR
14842 IPV6_STR
14843 NEIGHBOR_STR
14844 "Neighbor to display information about\n"
14845 "Neighbor to display information about\n"
14846 "Neighbor on BGP configured interface\n"
14847 GR_SHOW
14848 JSON_STR)
14849 {
14850 char *sh_arg = NULL;
14851 enum show_type sh_type;
14852 int idx = 0;
14853 afi_t afi = AFI_MAX;
14854 bool uj = use_json(argc, argv);
14855
14856 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14857 afi = AFI_MAX;
14858
14859 idx++;
14860
14861 if (argv_find(argv, argc, "A.B.C.D", &idx)
14862 || argv_find(argv, argc, "X:X::X:X", &idx)
14863 || argv_find(argv, argc, "WORD", &idx)) {
14864 sh_type = show_peer;
14865 sh_arg = argv[idx]->arg;
14866 } else
14867 sh_type = show_all;
14868
14869 if (!argv_find(argv, argc, "graceful-restart", &idx))
14870 return CMD_SUCCESS;
14871
14872
14873 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14874 afi, uj);
14875 }
14876
14877 /* "show [ip] bgp neighbors" commands. */
14878 DEFUN (show_ip_bgp_neighbors,
14879 show_ip_bgp_neighbors_cmd,
14880 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14881 SHOW_STR
14882 IP_STR
14883 BGP_STR
14884 BGP_INSTANCE_HELP_STR
14885 BGP_AF_STR
14886 BGP_AF_STR
14887 "Detailed information on TCP and BGP neighbor connections\n"
14888 "Neighbor to display information about\n"
14889 "Neighbor to display information about\n"
14890 "Neighbor on BGP configured interface\n"
14891 JSON_STR)
14892 {
14893 char *vrf = NULL;
14894 char *sh_arg = NULL;
14895 enum show_type sh_type;
14896 afi_t afi = AFI_MAX;
14897
14898 bool uj = use_json(argc, argv);
14899
14900 int idx = 0;
14901
14902 /* [<vrf> VIEWVRFNAME] */
14903 if (argv_find(argv, argc, "vrf", &idx)) {
14904 vrf = argv[idx + 1]->arg;
14905 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14906 vrf = NULL;
14907 } else if (argv_find(argv, argc, "view", &idx))
14908 /* [<view> VIEWVRFNAME] */
14909 vrf = argv[idx + 1]->arg;
14910
14911 idx++;
14912
14913 if (argv_find(argv, argc, "ipv4", &idx)) {
14914 sh_type = show_ipv4_all;
14915 afi = AFI_IP;
14916 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14917 sh_type = show_ipv6_all;
14918 afi = AFI_IP6;
14919 } else {
14920 sh_type = show_all;
14921 }
14922
14923 if (argv_find(argv, argc, "A.B.C.D", &idx)
14924 || argv_find(argv, argc, "X:X::X:X", &idx)
14925 || argv_find(argv, argc, "WORD", &idx)) {
14926 sh_type = show_peer;
14927 sh_arg = argv[idx]->arg;
14928 }
14929
14930 if (sh_type == show_peer && afi == AFI_IP) {
14931 sh_type = show_ipv4_peer;
14932 } else if (sh_type == show_peer && afi == AFI_IP6) {
14933 sh_type = show_ipv6_peer;
14934 }
14935
14936 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14937 }
14938
14939 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14940 paths' and `show ip mbgp paths'. Those functions results are the
14941 same.*/
14942 DEFUN (show_ip_bgp_paths,
14943 show_ip_bgp_paths_cmd,
14944 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14945 SHOW_STR
14946 IP_STR
14947 BGP_STR
14948 BGP_SAFI_HELP_STR
14949 "Path information\n")
14950 {
14951 vty_out(vty, "Address Refcnt Path\n");
14952 aspath_print_all_vty(vty);
14953 return CMD_SUCCESS;
14954 }
14955
14956 #include "hash.h"
14957
14958 static void community_show_all_iterator(struct hash_bucket *bucket,
14959 struct vty *vty)
14960 {
14961 struct community *com;
14962
14963 com = (struct community *)bucket->data;
14964 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14965 community_str(com, false, false));
14966 }
14967
14968 /* Show BGP's community internal data. */
14969 DEFUN (show_ip_bgp_community_info,
14970 show_ip_bgp_community_info_cmd,
14971 "show [ip] bgp community-info",
14972 SHOW_STR
14973 IP_STR
14974 BGP_STR
14975 "List all bgp community information\n")
14976 {
14977 vty_out(vty, "Address Refcnt Community\n");
14978
14979 hash_iterate(community_hash(),
14980 (void (*)(struct hash_bucket *,
14981 void *))community_show_all_iterator,
14982 vty);
14983
14984 return CMD_SUCCESS;
14985 }
14986
14987 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14988 struct vty *vty)
14989 {
14990 struct lcommunity *lcom;
14991
14992 lcom = (struct lcommunity *)bucket->data;
14993 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14994 lcommunity_str(lcom, false, false));
14995 }
14996
14997 /* Show BGP's community internal data. */
14998 DEFUN (show_ip_bgp_lcommunity_info,
14999 show_ip_bgp_lcommunity_info_cmd,
15000 "show ip bgp large-community-info",
15001 SHOW_STR
15002 IP_STR
15003 BGP_STR
15004 "List all bgp large-community information\n")
15005 {
15006 vty_out(vty, "Address Refcnt Large-community\n");
15007
15008 hash_iterate(lcommunity_hash(),
15009 (void (*)(struct hash_bucket *,
15010 void *))lcommunity_show_all_iterator,
15011 vty);
15012
15013 return CMD_SUCCESS;
15014 }
15015 /* Graceful Restart */
15016
15017 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15018 struct bgp *bgp,
15019 bool use_json,
15020 json_object *json)
15021 {
15022
15023
15024 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15025
15026 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15027
15028 switch (bgp_global_gr_mode) {
15029
15030 case GLOBAL_HELPER:
15031 vty_out(vty, "Global BGP GR Mode : Helper\n");
15032 break;
15033
15034 case GLOBAL_GR:
15035 vty_out(vty, "Global BGP GR Mode : Restart\n");
15036 break;
15037
15038 case GLOBAL_DISABLE:
15039 vty_out(vty, "Global BGP GR Mode : Disable\n");
15040 break;
15041
15042 case GLOBAL_INVALID:
15043 vty_out(vty,
15044 "Global BGP GR Mode Invalid\n");
15045 break;
15046 }
15047 vty_out(vty, "\n");
15048 }
15049
15050 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15051 enum show_type type,
15052 const char *ip_str,
15053 afi_t afi, bool use_json)
15054 {
15055 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15056 afi = AFI_IP;
15057
15058 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15059
15060 bgp_show_neighbor_graceful_restart_vty(
15061 vty, type, ip_str, afi, use_json);
15062 afi++;
15063 }
15064 } else if (afi != AFI_MAX) {
15065 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15066 use_json);
15067 } else {
15068 return CMD_ERR_INCOMPLETE;
15069 }
15070
15071 return CMD_SUCCESS;
15072 }
15073 /* Graceful Restart */
15074
15075 DEFUN (show_ip_bgp_attr_info,
15076 show_ip_bgp_attr_info_cmd,
15077 "show [ip] bgp attribute-info",
15078 SHOW_STR
15079 IP_STR
15080 BGP_STR
15081 "List all bgp attribute information\n")
15082 {
15083 attr_show_all(vty);
15084 return CMD_SUCCESS;
15085 }
15086
15087 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15088 afi_t afi, safi_t safi,
15089 bool use_json, json_object *json)
15090 {
15091 struct bgp *bgp;
15092 struct listnode *node;
15093 char *vname;
15094 char *ecom_str;
15095 enum vpn_policy_direction dir;
15096
15097 if (json) {
15098 json_object *json_import_vrfs = NULL;
15099 json_object *json_export_vrfs = NULL;
15100
15101 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15102
15103 if (!bgp) {
15104 vty_json(vty, json);
15105
15106 return CMD_WARNING;
15107 }
15108
15109 /* Provide context for the block */
15110 json_object_string_add(json, "vrf", name ? name : "default");
15111 json_object_string_add(json, "afiSafi",
15112 get_afi_safi_str(afi, safi, true));
15113
15114 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15115 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15116 json_object_string_add(json, "importFromVrfs", "none");
15117 json_object_string_add(json, "importRts", "none");
15118 } else {
15119 json_import_vrfs = json_object_new_array();
15120
15121 for (ALL_LIST_ELEMENTS_RO(
15122 bgp->vpn_policy[afi].import_vrf,
15123 node, vname))
15124 json_object_array_add(json_import_vrfs,
15125 json_object_new_string(vname));
15126
15127 json_object_object_add(json, "importFromVrfs",
15128 json_import_vrfs);
15129 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15130 if (bgp->vpn_policy[afi].rtlist[dir]) {
15131 ecom_str = ecommunity_ecom2str(
15132 bgp->vpn_policy[afi].rtlist[dir],
15133 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15134 json_object_string_add(json, "importRts",
15135 ecom_str);
15136 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15137 } else
15138 json_object_string_add(json, "importRts",
15139 "none");
15140 }
15141
15142 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15143 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15144 json_object_string_add(json, "exportToVrfs", "none");
15145 json_object_string_add(json, "routeDistinguisher",
15146 "none");
15147 json_object_string_add(json, "exportRts", "none");
15148 } else {
15149 json_export_vrfs = json_object_new_array();
15150
15151 for (ALL_LIST_ELEMENTS_RO(
15152 bgp->vpn_policy[afi].export_vrf,
15153 node, vname))
15154 json_object_array_add(json_export_vrfs,
15155 json_object_new_string(vname));
15156 json_object_object_add(json, "exportToVrfs",
15157 json_export_vrfs);
15158 json_object_string_addf(json, "routeDistinguisher",
15159 "%pRD",
15160 &bgp->vpn_policy[afi].tovpn_rd);
15161
15162 dir = BGP_VPN_POLICY_DIR_TOVPN;
15163 if (bgp->vpn_policy[afi].rtlist[dir]) {
15164 ecom_str = ecommunity_ecom2str(
15165 bgp->vpn_policy[afi].rtlist[dir],
15166 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15167 json_object_string_add(json, "exportRts",
15168 ecom_str);
15169 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15170 } else
15171 json_object_string_add(json, "exportRts",
15172 "none");
15173 }
15174
15175 if (use_json) {
15176 vty_json(vty, json);
15177 }
15178 } else {
15179 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15180
15181 if (!bgp) {
15182 vty_out(vty, "%% No such BGP instance exist\n");
15183 return CMD_WARNING;
15184 }
15185
15186 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15187 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15188 vty_out(vty,
15189 "This VRF is not importing %s routes from any other VRF\n",
15190 get_afi_safi_str(afi, safi, false));
15191 else {
15192 vty_out(vty,
15193 "This VRF is importing %s routes from the following VRFs:\n",
15194 get_afi_safi_str(afi, safi, false));
15195
15196 for (ALL_LIST_ELEMENTS_RO(
15197 bgp->vpn_policy[afi].import_vrf,
15198 node, vname))
15199 vty_out(vty, " %s\n", vname);
15200
15201 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15202 ecom_str = NULL;
15203 if (bgp->vpn_policy[afi].rtlist[dir]) {
15204 ecom_str = ecommunity_ecom2str(
15205 bgp->vpn_policy[afi].rtlist[dir],
15206 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15207 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15208
15209 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15210 } else
15211 vty_out(vty, "Import RT(s):\n");
15212 }
15213
15214 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15215 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15216 vty_out(vty,
15217 "This VRF is not exporting %s routes to any other VRF\n",
15218 get_afi_safi_str(afi, safi, false));
15219 else {
15220 vty_out(vty,
15221 "This VRF is exporting %s routes to the following VRFs:\n",
15222 get_afi_safi_str(afi, safi, false));
15223
15224 for (ALL_LIST_ELEMENTS_RO(
15225 bgp->vpn_policy[afi].export_vrf,
15226 node, vname))
15227 vty_out(vty, " %s\n", vname);
15228
15229 vty_out(vty, "RD: %pRD\n",
15230 &bgp->vpn_policy[afi].tovpn_rd);
15231
15232 dir = BGP_VPN_POLICY_DIR_TOVPN;
15233 if (bgp->vpn_policy[afi].rtlist[dir]) {
15234 ecom_str = ecommunity_ecom2str(
15235 bgp->vpn_policy[afi].rtlist[dir],
15236 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15237 vty_out(vty, "Export RT: %s\n", ecom_str);
15238 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15239 } else
15240 vty_out(vty, "Import RT(s):\n");
15241 }
15242 }
15243
15244 return CMD_SUCCESS;
15245 }
15246
15247 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15248 safi_t safi, bool use_json)
15249 {
15250 struct listnode *node, *nnode;
15251 struct bgp *bgp;
15252 char *vrf_name = NULL;
15253 json_object *json = NULL;
15254 json_object *json_vrf = NULL;
15255 json_object *json_vrfs = NULL;
15256
15257 if (use_json) {
15258 json = json_object_new_object();
15259 json_vrfs = json_object_new_object();
15260 }
15261
15262 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15263
15264 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15265 vrf_name = bgp->name;
15266
15267 if (use_json) {
15268 json_vrf = json_object_new_object();
15269 } else {
15270 vty_out(vty, "\nInstance %s:\n",
15271 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15272 ? VRF_DEFAULT_NAME : bgp->name);
15273 }
15274 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15275 if (use_json) {
15276 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15277 json_object_object_add(json_vrfs,
15278 VRF_DEFAULT_NAME, json_vrf);
15279 else
15280 json_object_object_add(json_vrfs, vrf_name,
15281 json_vrf);
15282 }
15283 }
15284
15285 if (use_json) {
15286 json_object_object_add(json, "vrfs", json_vrfs);
15287 vty_json(vty, json);
15288 }
15289
15290 return CMD_SUCCESS;
15291 }
15292
15293 /* "show [ip] bgp route-leak" command. */
15294 DEFUN (show_ip_bgp_route_leak,
15295 show_ip_bgp_route_leak_cmd,
15296 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15297 SHOW_STR
15298 IP_STR
15299 BGP_STR
15300 BGP_INSTANCE_HELP_STR
15301 BGP_AFI_HELP_STR
15302 BGP_SAFI_HELP_STR
15303 "Route leaking information\n"
15304 JSON_STR)
15305 {
15306 char *vrf = NULL;
15307 afi_t afi = AFI_MAX;
15308 safi_t safi = SAFI_MAX;
15309
15310 bool uj = use_json(argc, argv);
15311 int idx = 0;
15312 json_object *json = NULL;
15313
15314 /* show [ip] bgp */
15315 if (argv_find(argv, argc, "ip", &idx)) {
15316 afi = AFI_IP;
15317 safi = SAFI_UNICAST;
15318 }
15319 /* [vrf VIEWVRFNAME] */
15320 if (argv_find(argv, argc, "view", &idx)) {
15321 vty_out(vty,
15322 "%% This command is not applicable to BGP views\n");
15323 return CMD_WARNING;
15324 }
15325
15326 if (argv_find(argv, argc, "vrf", &idx)) {
15327 vrf = argv[idx + 1]->arg;
15328 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15329 vrf = NULL;
15330 }
15331 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15332 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15333 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15334
15335 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15336 vty_out(vty,
15337 "%% This command is applicable only for unicast ipv4|ipv6\n");
15338 return CMD_WARNING;
15339 }
15340
15341 if (vrf && strmatch(vrf, "all"))
15342 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15343
15344 if (uj)
15345 json = json_object_new_object();
15346
15347 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15348 }
15349
15350 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15351 safi_t safi)
15352 {
15353 struct listnode *node, *nnode;
15354 struct bgp *bgp;
15355
15356 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15357 vty_out(vty, "\nInstance %s:\n",
15358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15359 ? VRF_DEFAULT_NAME
15360 : bgp->name);
15361 update_group_show(bgp, afi, safi, vty, 0);
15362 }
15363 }
15364
15365 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15366 int safi, uint64_t subgrp_id)
15367 {
15368 struct bgp *bgp;
15369
15370 if (name) {
15371 if (strmatch(name, "all")) {
15372 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15373 return CMD_SUCCESS;
15374 } else {
15375 bgp = bgp_lookup_by_name(name);
15376 }
15377 } else {
15378 bgp = bgp_get_default();
15379 }
15380
15381 if (bgp)
15382 update_group_show(bgp, afi, safi, vty, subgrp_id);
15383 return CMD_SUCCESS;
15384 }
15385
15386 DEFUN (show_ip_bgp_updgrps,
15387 show_ip_bgp_updgrps_cmd,
15388 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15389 SHOW_STR
15390 IP_STR
15391 BGP_STR
15392 BGP_INSTANCE_HELP_STR
15393 BGP_AFI_HELP_STR
15394 BGP_SAFI_WITH_LABEL_HELP_STR
15395 "Detailed info about dynamic update groups\n"
15396 "Specific subgroup to display detailed info for\n")
15397 {
15398 char *vrf = NULL;
15399 afi_t afi = AFI_IP6;
15400 safi_t safi = SAFI_UNICAST;
15401 uint64_t subgrp_id = 0;
15402
15403 int idx = 0;
15404
15405 /* show [ip] bgp */
15406 if (argv_find(argv, argc, "ip", &idx))
15407 afi = AFI_IP;
15408 /* [<vrf> VIEWVRFNAME] */
15409 if (argv_find(argv, argc, "vrf", &idx)) {
15410 vrf = argv[idx + 1]->arg;
15411 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15412 vrf = NULL;
15413 } else if (argv_find(argv, argc, "view", &idx))
15414 /* [<view> VIEWVRFNAME] */
15415 vrf = argv[idx + 1]->arg;
15416 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15417 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15418 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15419 }
15420
15421 /* get subgroup id, if provided */
15422 idx = argc - 1;
15423 if (argv[idx]->type == VARIABLE_TKN)
15424 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15425
15426 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15427 }
15428
15429 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15430 show_bgp_instance_all_ipv6_updgrps_cmd,
15431 "show [ip] bgp <view|vrf> all update-groups",
15432 SHOW_STR
15433 IP_STR
15434 BGP_STR
15435 BGP_INSTANCE_ALL_HELP_STR
15436 "Detailed info about dynamic update groups\n")
15437 {
15438 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15439 return CMD_SUCCESS;
15440 }
15441
15442 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15443 show_bgp_l2vpn_evpn_updgrps_cmd,
15444 "show [ip] bgp l2vpn evpn update-groups",
15445 SHOW_STR
15446 IP_STR
15447 BGP_STR
15448 "l2vpn address family\n"
15449 "evpn sub-address family\n"
15450 "Detailed info about dynamic update groups\n")
15451 {
15452 char *vrf = NULL;
15453 uint64_t subgrp_id = 0;
15454
15455 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15456 return CMD_SUCCESS;
15457 }
15458
15459 DEFUN (show_bgp_updgrps_stats,
15460 show_bgp_updgrps_stats_cmd,
15461 "show [ip] bgp update-groups statistics",
15462 SHOW_STR
15463 IP_STR
15464 BGP_STR
15465 "Detailed info about dynamic update groups\n"
15466 "Statistics\n")
15467 {
15468 struct bgp *bgp;
15469
15470 bgp = bgp_get_default();
15471 if (bgp)
15472 update_group_show_stats(bgp, vty);
15473
15474 return CMD_SUCCESS;
15475 }
15476
15477 DEFUN (show_bgp_instance_updgrps_stats,
15478 show_bgp_instance_updgrps_stats_cmd,
15479 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15480 SHOW_STR
15481 IP_STR
15482 BGP_STR
15483 BGP_INSTANCE_HELP_STR
15484 "Detailed info about dynamic update groups\n"
15485 "Statistics\n")
15486 {
15487 int idx_word = 3;
15488 struct bgp *bgp;
15489
15490 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15491 if (bgp)
15492 update_group_show_stats(bgp, vty);
15493
15494 return CMD_SUCCESS;
15495 }
15496
15497 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15498 afi_t afi, safi_t safi,
15499 const char *what, uint64_t subgrp_id)
15500 {
15501 struct bgp *bgp;
15502
15503 if (name)
15504 bgp = bgp_lookup_by_name(name);
15505 else
15506 bgp = bgp_get_default();
15507
15508 if (bgp) {
15509 if (!strcmp(what, "advertise-queue"))
15510 update_group_show_adj_queue(bgp, afi, safi, vty,
15511 subgrp_id);
15512 else if (!strcmp(what, "advertised-routes"))
15513 update_group_show_advertised(bgp, afi, safi, vty,
15514 subgrp_id);
15515 else if (!strcmp(what, "packet-queue"))
15516 update_group_show_packet_queue(bgp, afi, safi, vty,
15517 subgrp_id);
15518 }
15519 }
15520
15521 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15522 show_ip_bgp_instance_updgrps_adj_s_cmd,
15523 "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",
15524 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15525 BGP_SAFI_HELP_STR
15526 "Detailed info about dynamic update groups\n"
15527 "Specific subgroup to display info for\n"
15528 "Advertisement queue\n"
15529 "Announced routes\n"
15530 "Packet queue\n")
15531 {
15532 uint64_t subgrp_id = 0;
15533 afi_t afiz;
15534 safi_t safiz;
15535 if (sgid)
15536 subgrp_id = strtoull(sgid, NULL, 10);
15537
15538 if (!ip && !afi)
15539 afiz = AFI_IP6;
15540 if (!ip && afi)
15541 afiz = bgp_vty_afi_from_str(afi);
15542 if (ip && !afi)
15543 afiz = AFI_IP;
15544 if (ip && afi) {
15545 afiz = bgp_vty_afi_from_str(afi);
15546 if (afiz != AFI_IP)
15547 vty_out(vty,
15548 "%% Cannot specify both 'ip' and 'ipv6'\n");
15549 return CMD_WARNING;
15550 }
15551
15552 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15553
15554 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15555 return CMD_SUCCESS;
15556 }
15557
15558 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15559 json_object *json)
15560 {
15561 struct listnode *node, *nnode;
15562 struct prefix *range;
15563 struct peer *conf;
15564 struct peer *peer;
15565 afi_t afi;
15566 safi_t safi;
15567 const char *peer_status;
15568 int lr_count;
15569 int dynamic;
15570 bool af_cfgd;
15571 json_object *json_peer_group = NULL;
15572 json_object *json_peer_group_afc = NULL;
15573 json_object *json_peer_group_members = NULL;
15574 json_object *json_peer_group_dynamic = NULL;
15575 json_object *json_peer_group_dynamic_af = NULL;
15576 json_object *json_peer_group_ranges = NULL;
15577
15578 conf = group->conf;
15579
15580 if (json) {
15581 json_peer_group = json_object_new_object();
15582 json_peer_group_afc = json_object_new_array();
15583 }
15584
15585 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15586 if (json)
15587 json_object_int_add(json_peer_group, "remoteAs",
15588 conf->as);
15589 else
15590 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15591 group->name, conf->as);
15592 } else if (conf->as_type == AS_INTERNAL) {
15593 if (json)
15594 json_object_int_add(json_peer_group, "remoteAs",
15595 group->bgp->as);
15596 else
15597 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15598 group->name, group->bgp->as);
15599 } else {
15600 if (!json)
15601 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15602 }
15603
15604 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15605 if (json)
15606 json_object_string_add(json_peer_group, "type",
15607 "internal");
15608 else
15609 vty_out(vty, " Peer-group type is internal\n");
15610 } else {
15611 if (json)
15612 json_object_string_add(json_peer_group, "type",
15613 "external");
15614 else
15615 vty_out(vty, " Peer-group type is external\n");
15616 }
15617
15618 /* Display AFs configured. */
15619 if (!json)
15620 vty_out(vty, " Configured address-families:");
15621
15622 FOREACH_AFI_SAFI (afi, safi) {
15623 if (conf->afc[afi][safi]) {
15624 af_cfgd = true;
15625 if (json)
15626 json_object_array_add(
15627 json_peer_group_afc,
15628 json_object_new_string(get_afi_safi_str(
15629 afi, safi, false)));
15630 else
15631 vty_out(vty, " %s;",
15632 get_afi_safi_str(afi, safi, false));
15633 }
15634 }
15635
15636 if (json) {
15637 json_object_object_add(json_peer_group,
15638 "addressFamiliesConfigured",
15639 json_peer_group_afc);
15640 } else {
15641 if (!af_cfgd)
15642 vty_out(vty, " none\n");
15643 else
15644 vty_out(vty, "\n");
15645 }
15646
15647 /* Display listen ranges (for dynamic neighbors), if any */
15648 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15649 lr_count = listcount(group->listen_range[afi]);
15650 if (lr_count) {
15651 if (json) {
15652 if (!json_peer_group_dynamic)
15653 json_peer_group_dynamic =
15654 json_object_new_object();
15655
15656 json_peer_group_dynamic_af =
15657 json_object_new_object();
15658 json_peer_group_ranges =
15659 json_object_new_array();
15660 json_object_int_add(json_peer_group_dynamic_af,
15661 "count", lr_count);
15662 } else {
15663 vty_out(vty, " %d %s listen range(s)\n",
15664 lr_count, afi2str(afi));
15665 }
15666
15667 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15668 nnode, range)) {
15669 if (json) {
15670 char buf[BUFSIZ];
15671
15672 snprintfrr(buf, sizeof(buf), "%pFX",
15673 range);
15674
15675 json_object_array_add(
15676 json_peer_group_ranges,
15677 json_object_new_string(buf));
15678 } else {
15679 vty_out(vty, " %pFX\n", range);
15680 }
15681 }
15682
15683 if (json) {
15684 json_object_object_add(
15685 json_peer_group_dynamic_af, "ranges",
15686 json_peer_group_ranges);
15687
15688 json_object_object_add(
15689 json_peer_group_dynamic, afi2str(afi),
15690 json_peer_group_dynamic_af);
15691 }
15692 }
15693 }
15694
15695 if (json_peer_group_dynamic)
15696 json_object_object_add(json_peer_group, "dynamicRanges",
15697 json_peer_group_dynamic);
15698
15699 /* Display group members and their status */
15700 if (listcount(group->peer)) {
15701 if (json)
15702 json_peer_group_members = json_object_new_object();
15703 else
15704 vty_out(vty, " Peer-group members:\n");
15705 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15706 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15707 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15708 peer_status = "Idle (Admin)";
15709 else if (CHECK_FLAG(peer->sflags,
15710 PEER_STATUS_PREFIX_OVERFLOW))
15711 peer_status = "Idle (PfxCt)";
15712 else
15713 peer_status = lookup_msg(bgp_status_msg,
15714 peer->status, NULL);
15715
15716 dynamic = peer_dynamic_neighbor(peer);
15717
15718 if (json) {
15719 json_object *json_peer_group_member =
15720 json_object_new_object();
15721
15722 json_object_string_add(json_peer_group_member,
15723 "status", peer_status);
15724
15725 if (dynamic)
15726 json_object_boolean_true_add(
15727 json_peer_group_member,
15728 "dynamic");
15729
15730 json_object_object_add(json_peer_group_members,
15731 peer->host,
15732 json_peer_group_member);
15733 } else {
15734 vty_out(vty, " %s %s %s \n", peer->host,
15735 dynamic ? "(dynamic)" : "",
15736 peer_status);
15737 }
15738 }
15739 if (json)
15740 json_object_object_add(json_peer_group, "members",
15741 json_peer_group_members);
15742 }
15743
15744 if (json)
15745 json_object_object_add(json, group->name, json_peer_group);
15746
15747 return CMD_SUCCESS;
15748 }
15749
15750 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15751 const char *group_name, bool uj)
15752 {
15753 struct bgp *bgp;
15754 struct listnode *node, *nnode;
15755 struct peer_group *group;
15756 bool found = false;
15757 json_object *json = NULL;
15758
15759 if (uj)
15760 json = json_object_new_object();
15761
15762 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15763
15764 if (!bgp) {
15765 if (uj)
15766 vty_json(vty, json);
15767 else
15768 vty_out(vty, "%% BGP instance not found\n");
15769
15770 return CMD_WARNING;
15771 }
15772
15773 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15774 if (group_name) {
15775 if (strmatch(group->name, group_name)) {
15776 bgp_show_one_peer_group(vty, group, json);
15777 found = true;
15778 break;
15779 }
15780 } else {
15781 bgp_show_one_peer_group(vty, group, json);
15782 }
15783 }
15784
15785 if (group_name && !found && !uj)
15786 vty_out(vty, "%% No such peer-group\n");
15787
15788 if (uj)
15789 vty_json(vty, json);
15790
15791 return CMD_SUCCESS;
15792 }
15793
15794 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15795 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15796 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15797 "Detailed information on BGP peer groups\n"
15798 "Peer group name\n" JSON_STR)
15799 {
15800 char *vrf, *pg;
15801 int idx = 0;
15802 bool uj = use_json(argc, argv);
15803
15804 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15805 : NULL;
15806 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15807
15808 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15809 }
15810
15811
15812 /* Redistribute VTY commands. */
15813
15814 DEFUN (bgp_redistribute_ipv4,
15815 bgp_redistribute_ipv4_cmd,
15816 "redistribute " FRR_IP_REDIST_STR_BGPD,
15817 "Redistribute information from another routing protocol\n"
15818 FRR_IP_REDIST_HELP_STR_BGPD)
15819 {
15820 VTY_DECLVAR_CONTEXT(bgp, bgp);
15821 int idx_protocol = 1;
15822 int type;
15823
15824 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15825 if (type < 0) {
15826 vty_out(vty, "%% Invalid route type\n");
15827 return CMD_WARNING_CONFIG_FAILED;
15828 }
15829
15830 bgp_redist_add(bgp, AFI_IP, type, 0);
15831 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15832 }
15833
15834 ALIAS_HIDDEN(
15835 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15836 "redistribute " FRR_IP_REDIST_STR_BGPD,
15837 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15838
15839 DEFUN (bgp_redistribute_ipv4_rmap,
15840 bgp_redistribute_ipv4_rmap_cmd,
15841 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15842 "Redistribute information from another routing protocol\n"
15843 FRR_IP_REDIST_HELP_STR_BGPD
15844 "Route map reference\n"
15845 "Pointer to route-map entries\n")
15846 {
15847 VTY_DECLVAR_CONTEXT(bgp, bgp);
15848 int idx_protocol = 1;
15849 int idx_word = 3;
15850 int type;
15851 struct bgp_redist *red;
15852 bool changed;
15853 struct route_map *route_map = route_map_lookup_warn_noexist(
15854 vty, argv[idx_word]->arg);
15855
15856 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15857 if (type < 0) {
15858 vty_out(vty, "%% Invalid route type\n");
15859 return CMD_WARNING_CONFIG_FAILED;
15860 }
15861
15862 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15863 changed =
15864 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15865 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15866 }
15867
15868 ALIAS_HIDDEN(
15869 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15870 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15871 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15872 "Route map reference\n"
15873 "Pointer to route-map entries\n")
15874
15875 DEFUN (bgp_redistribute_ipv4_metric,
15876 bgp_redistribute_ipv4_metric_cmd,
15877 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15878 "Redistribute information from another routing protocol\n"
15879 FRR_IP_REDIST_HELP_STR_BGPD
15880 "Metric for redistributed routes\n"
15881 "Default metric\n")
15882 {
15883 VTY_DECLVAR_CONTEXT(bgp, bgp);
15884 int idx_protocol = 1;
15885 int idx_number = 3;
15886 int type;
15887 uint32_t metric;
15888 struct bgp_redist *red;
15889 bool changed;
15890
15891 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15892 if (type < 0) {
15893 vty_out(vty, "%% Invalid route type\n");
15894 return CMD_WARNING_CONFIG_FAILED;
15895 }
15896 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15897
15898 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15899 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15900 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15901 }
15902
15903 ALIAS_HIDDEN(
15904 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15905 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15906 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15907 "Metric for redistributed routes\n"
15908 "Default metric\n")
15909
15910 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15911 bgp_redistribute_ipv4_rmap_metric_cmd,
15912 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15913 "Redistribute information from another routing protocol\n"
15914 FRR_IP_REDIST_HELP_STR_BGPD
15915 "Route map reference\n"
15916 "Pointer to route-map entries\n"
15917 "Metric for redistributed routes\n"
15918 "Default metric\n")
15919 {
15920 VTY_DECLVAR_CONTEXT(bgp, bgp);
15921 int idx_protocol = 1;
15922 int idx_word = 3;
15923 int idx_number = 5;
15924 int type;
15925 uint32_t metric;
15926 struct bgp_redist *red;
15927 bool changed;
15928 struct route_map *route_map =
15929 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15930
15931 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15932 if (type < 0) {
15933 vty_out(vty, "%% Invalid route type\n");
15934 return CMD_WARNING_CONFIG_FAILED;
15935 }
15936 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15937
15938 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15939 changed =
15940 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15941 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15942 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15943 }
15944
15945 ALIAS_HIDDEN(
15946 bgp_redistribute_ipv4_rmap_metric,
15947 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15948 "redistribute " FRR_IP_REDIST_STR_BGPD
15949 " route-map RMAP_NAME metric (0-4294967295)",
15950 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15951 "Route map reference\n"
15952 "Pointer to route-map entries\n"
15953 "Metric for redistributed routes\n"
15954 "Default metric\n")
15955
15956 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15957 bgp_redistribute_ipv4_metric_rmap_cmd,
15958 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15959 "Redistribute information from another routing protocol\n"
15960 FRR_IP_REDIST_HELP_STR_BGPD
15961 "Metric for redistributed routes\n"
15962 "Default metric\n"
15963 "Route map reference\n"
15964 "Pointer to route-map entries\n")
15965 {
15966 VTY_DECLVAR_CONTEXT(bgp, bgp);
15967 int idx_protocol = 1;
15968 int idx_number = 3;
15969 int idx_word = 5;
15970 int type;
15971 uint32_t metric;
15972 struct bgp_redist *red;
15973 bool changed;
15974 struct route_map *route_map =
15975 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15976
15977 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15978 if (type < 0) {
15979 vty_out(vty, "%% Invalid route type\n");
15980 return CMD_WARNING_CONFIG_FAILED;
15981 }
15982 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15983
15984 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15985 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15986 changed |=
15987 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15988 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15989 }
15990
15991 ALIAS_HIDDEN(
15992 bgp_redistribute_ipv4_metric_rmap,
15993 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15994 "redistribute " FRR_IP_REDIST_STR_BGPD
15995 " metric (0-4294967295) route-map RMAP_NAME",
15996 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15997 "Metric for redistributed routes\n"
15998 "Default metric\n"
15999 "Route map reference\n"
16000 "Pointer to route-map entries\n")
16001
16002 DEFUN (bgp_redistribute_ipv4_ospf,
16003 bgp_redistribute_ipv4_ospf_cmd,
16004 "redistribute <ospf|table> (1-65535)",
16005 "Redistribute information from another routing protocol\n"
16006 "Open Shortest Path First (OSPFv2)\n"
16007 "Non-main Kernel Routing Table\n"
16008 "Instance ID/Table ID\n")
16009 {
16010 VTY_DECLVAR_CONTEXT(bgp, bgp);
16011 int idx_ospf_table = 1;
16012 int idx_number = 2;
16013 unsigned short instance;
16014 unsigned short protocol;
16015
16016 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16017
16018 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16019 protocol = ZEBRA_ROUTE_OSPF;
16020 else
16021 protocol = ZEBRA_ROUTE_TABLE;
16022
16023 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16024 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16025 }
16026
16027 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16028 "redistribute <ospf|table> (1-65535)",
16029 "Redistribute information from another routing protocol\n"
16030 "Open Shortest Path First (OSPFv2)\n"
16031 "Non-main Kernel Routing Table\n"
16032 "Instance ID/Table ID\n")
16033
16034 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16035 bgp_redistribute_ipv4_ospf_rmap_cmd,
16036 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16037 "Redistribute information from another routing protocol\n"
16038 "Open Shortest Path First (OSPFv2)\n"
16039 "Non-main Kernel Routing Table\n"
16040 "Instance ID/Table ID\n"
16041 "Route map reference\n"
16042 "Pointer to route-map entries\n")
16043 {
16044 VTY_DECLVAR_CONTEXT(bgp, bgp);
16045 int idx_ospf_table = 1;
16046 int idx_number = 2;
16047 int idx_word = 4;
16048 struct bgp_redist *red;
16049 unsigned short instance;
16050 int protocol;
16051 bool changed;
16052 struct route_map *route_map =
16053 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16054
16055 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16056 protocol = ZEBRA_ROUTE_OSPF;
16057 else
16058 protocol = ZEBRA_ROUTE_TABLE;
16059
16060 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16061 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16062 changed =
16063 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16064 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16065 }
16066
16067 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16068 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16069 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16070 "Redistribute information from another routing protocol\n"
16071 "Open Shortest Path First (OSPFv2)\n"
16072 "Non-main Kernel Routing Table\n"
16073 "Instance ID/Table ID\n"
16074 "Route map reference\n"
16075 "Pointer to route-map entries\n")
16076
16077 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16078 bgp_redistribute_ipv4_ospf_metric_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 VTY_DECLVAR_CONTEXT(bgp, bgp);
16088 int idx_ospf_table = 1;
16089 int idx_number = 2;
16090 int idx_number_2 = 4;
16091 uint32_t metric;
16092 struct bgp_redist *red;
16093 unsigned short instance;
16094 int protocol;
16095 bool changed;
16096
16097 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16098 protocol = ZEBRA_ROUTE_OSPF;
16099 else
16100 protocol = ZEBRA_ROUTE_TABLE;
16101
16102 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16103 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16104
16105 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16106 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16107 metric);
16108 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16109 }
16110
16111 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16112 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16113 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16114 "Redistribute information from another routing protocol\n"
16115 "Open Shortest Path First (OSPFv2)\n"
16116 "Non-main Kernel Routing Table\n"
16117 "Instance ID/Table ID\n"
16118 "Metric for redistributed routes\n"
16119 "Default metric\n")
16120
16121 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16122 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16123 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16124 "Redistribute information from another routing protocol\n"
16125 "Open Shortest Path First (OSPFv2)\n"
16126 "Non-main Kernel Routing Table\n"
16127 "Instance ID/Table ID\n"
16128 "Route map reference\n"
16129 "Pointer to route-map entries\n"
16130 "Metric for redistributed routes\n"
16131 "Default metric\n")
16132 {
16133 VTY_DECLVAR_CONTEXT(bgp, bgp);
16134 int idx_ospf_table = 1;
16135 int idx_number = 2;
16136 int idx_word = 4;
16137 int idx_number_2 = 6;
16138 uint32_t metric;
16139 struct bgp_redist *red;
16140 unsigned short instance;
16141 int protocol;
16142 bool changed;
16143 struct route_map *route_map =
16144 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16145
16146 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16147 protocol = ZEBRA_ROUTE_OSPF;
16148 else
16149 protocol = ZEBRA_ROUTE_TABLE;
16150
16151 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16152 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16153
16154 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16155 changed =
16156 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16157 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16158 metric);
16159 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16160 }
16161
16162 ALIAS_HIDDEN(
16163 bgp_redistribute_ipv4_ospf_rmap_metric,
16164 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16165 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16166 "Redistribute information from another routing protocol\n"
16167 "Open Shortest Path First (OSPFv2)\n"
16168 "Non-main Kernel Routing Table\n"
16169 "Instance ID/Table ID\n"
16170 "Route map reference\n"
16171 "Pointer to route-map entries\n"
16172 "Metric for redistributed routes\n"
16173 "Default metric\n")
16174
16175 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16176 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16177 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16178 "Redistribute information from another routing protocol\n"
16179 "Open Shortest Path First (OSPFv2)\n"
16180 "Non-main Kernel Routing Table\n"
16181 "Instance ID/Table ID\n"
16182 "Metric for redistributed routes\n"
16183 "Default metric\n"
16184 "Route map reference\n"
16185 "Pointer to route-map entries\n")
16186 {
16187 VTY_DECLVAR_CONTEXT(bgp, bgp);
16188 int idx_ospf_table = 1;
16189 int idx_number = 2;
16190 int idx_number_2 = 4;
16191 int idx_word = 6;
16192 uint32_t metric;
16193 struct bgp_redist *red;
16194 unsigned short instance;
16195 int protocol;
16196 bool changed;
16197 struct route_map *route_map =
16198 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16199
16200 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16201 protocol = ZEBRA_ROUTE_OSPF;
16202 else
16203 protocol = ZEBRA_ROUTE_TABLE;
16204
16205 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16206 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16207
16208 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16209 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16210 metric);
16211 changed |=
16212 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16213 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16214 }
16215
16216 ALIAS_HIDDEN(
16217 bgp_redistribute_ipv4_ospf_metric_rmap,
16218 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16219 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16220 "Redistribute information from another routing protocol\n"
16221 "Open Shortest Path First (OSPFv2)\n"
16222 "Non-main Kernel Routing Table\n"
16223 "Instance ID/Table ID\n"
16224 "Metric for redistributed routes\n"
16225 "Default metric\n"
16226 "Route map reference\n"
16227 "Pointer to route-map entries\n")
16228
16229 DEFUN (no_bgp_redistribute_ipv4_ospf,
16230 no_bgp_redistribute_ipv4_ospf_cmd,
16231 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16232 NO_STR
16233 "Redistribute information from another routing protocol\n"
16234 "Open Shortest Path First (OSPFv2)\n"
16235 "Non-main Kernel Routing Table\n"
16236 "Instance ID/Table ID\n"
16237 "Metric for redistributed routes\n"
16238 "Default metric\n"
16239 "Route map reference\n"
16240 "Pointer to route-map entries\n")
16241 {
16242 VTY_DECLVAR_CONTEXT(bgp, bgp);
16243 int idx_ospf_table = 2;
16244 int idx_number = 3;
16245 unsigned short instance;
16246 int protocol;
16247
16248 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16249 protocol = ZEBRA_ROUTE_OSPF;
16250 else
16251 protocol = ZEBRA_ROUTE_TABLE;
16252
16253 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16254 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16255 }
16256
16257 ALIAS_HIDDEN(
16258 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16259 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16260 NO_STR
16261 "Redistribute information from another routing protocol\n"
16262 "Open Shortest Path First (OSPFv2)\n"
16263 "Non-main Kernel Routing Table\n"
16264 "Instance ID/Table ID\n"
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 (no_bgp_redistribute_ipv4,
16271 no_bgp_redistribute_ipv4_cmd,
16272 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16273 NO_STR
16274 "Redistribute information from another routing protocol\n"
16275 FRR_IP_REDIST_HELP_STR_BGPD
16276 "Metric for redistributed routes\n"
16277 "Default metric\n"
16278 "Route map reference\n"
16279 "Pointer to route-map entries\n")
16280 {
16281 VTY_DECLVAR_CONTEXT(bgp, bgp);
16282 int idx_protocol = 2;
16283 int type;
16284
16285 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16286 if (type < 0) {
16287 vty_out(vty, "%% Invalid route type\n");
16288 return CMD_WARNING_CONFIG_FAILED;
16289 }
16290 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16291 }
16292
16293 ALIAS_HIDDEN(
16294 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16295 "no redistribute " FRR_IP_REDIST_STR_BGPD
16296 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16297 NO_STR
16298 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16299 "Metric for redistributed routes\n"
16300 "Default metric\n"
16301 "Route map reference\n"
16302 "Pointer to route-map entries\n")
16303
16304 DEFUN (bgp_redistribute_ipv6,
16305 bgp_redistribute_ipv6_cmd,
16306 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16307 "Redistribute information from another routing protocol\n"
16308 FRR_IP6_REDIST_HELP_STR_BGPD)
16309 {
16310 VTY_DECLVAR_CONTEXT(bgp, bgp);
16311 int idx_protocol = 1;
16312 int type;
16313
16314 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16315 if (type < 0) {
16316 vty_out(vty, "%% Invalid route type\n");
16317 return CMD_WARNING_CONFIG_FAILED;
16318 }
16319
16320 bgp_redist_add(bgp, AFI_IP6, type, 0);
16321 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16322 }
16323
16324 DEFUN (bgp_redistribute_ipv6_rmap,
16325 bgp_redistribute_ipv6_rmap_cmd,
16326 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16327 "Redistribute information from another routing protocol\n"
16328 FRR_IP6_REDIST_HELP_STR_BGPD
16329 "Route map reference\n"
16330 "Pointer to route-map entries\n")
16331 {
16332 VTY_DECLVAR_CONTEXT(bgp, bgp);
16333 int idx_protocol = 1;
16334 int idx_word = 3;
16335 int type;
16336 struct bgp_redist *red;
16337 bool changed;
16338 struct route_map *route_map =
16339 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16340
16341 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16342 if (type < 0) {
16343 vty_out(vty, "%% Invalid route type\n");
16344 return CMD_WARNING_CONFIG_FAILED;
16345 }
16346
16347 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16348 changed =
16349 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16350 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16351 }
16352
16353 DEFUN (bgp_redistribute_ipv6_metric,
16354 bgp_redistribute_ipv6_metric_cmd,
16355 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16356 "Redistribute information from another routing protocol\n"
16357 FRR_IP6_REDIST_HELP_STR_BGPD
16358 "Metric for redistributed routes\n"
16359 "Default metric\n")
16360 {
16361 VTY_DECLVAR_CONTEXT(bgp, bgp);
16362 int idx_protocol = 1;
16363 int idx_number = 3;
16364 int type;
16365 uint32_t metric;
16366 struct bgp_redist *red;
16367 bool changed;
16368
16369 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16370 if (type < 0) {
16371 vty_out(vty, "%% Invalid route type\n");
16372 return CMD_WARNING_CONFIG_FAILED;
16373 }
16374 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16375
16376 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16377 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16378 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16379 }
16380
16381 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16382 bgp_redistribute_ipv6_rmap_metric_cmd,
16383 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16384 "Redistribute information from another routing protocol\n"
16385 FRR_IP6_REDIST_HELP_STR_BGPD
16386 "Route map reference\n"
16387 "Pointer to route-map entries\n"
16388 "Metric for redistributed routes\n"
16389 "Default metric\n")
16390 {
16391 VTY_DECLVAR_CONTEXT(bgp, bgp);
16392 int idx_protocol = 1;
16393 int idx_word = 3;
16394 int idx_number = 5;
16395 int type;
16396 uint32_t metric;
16397 struct bgp_redist *red;
16398 bool changed;
16399 struct route_map *route_map =
16400 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16401
16402 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16403 if (type < 0) {
16404 vty_out(vty, "%% Invalid route type\n");
16405 return CMD_WARNING_CONFIG_FAILED;
16406 }
16407 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16408
16409 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16410 changed =
16411 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16412 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16413 metric);
16414 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16415 }
16416
16417 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16418 bgp_redistribute_ipv6_metric_rmap_cmd,
16419 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16420 "Redistribute information from another routing protocol\n"
16421 FRR_IP6_REDIST_HELP_STR_BGPD
16422 "Metric for redistributed routes\n"
16423 "Default metric\n"
16424 "Route map reference\n"
16425 "Pointer to route-map entries\n")
16426 {
16427 VTY_DECLVAR_CONTEXT(bgp, bgp);
16428 int idx_protocol = 1;
16429 int idx_number = 3;
16430 int idx_word = 5;
16431 int type;
16432 uint32_t metric;
16433 struct bgp_redist *red;
16434 bool changed;
16435 struct route_map *route_map =
16436 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16437
16438 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16439 if (type < 0) {
16440 vty_out(vty, "%% Invalid route type\n");
16441 return CMD_WARNING_CONFIG_FAILED;
16442 }
16443 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16444
16445 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16446 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16447 metric);
16448 changed |=
16449 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16450 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16451 }
16452
16453 DEFUN (no_bgp_redistribute_ipv6,
16454 no_bgp_redistribute_ipv6_cmd,
16455 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16456 NO_STR
16457 "Redistribute information from another routing protocol\n"
16458 FRR_IP6_REDIST_HELP_STR_BGPD
16459 "Metric for redistributed routes\n"
16460 "Default metric\n"
16461 "Route map reference\n"
16462 "Pointer to route-map entries\n")
16463 {
16464 VTY_DECLVAR_CONTEXT(bgp, bgp);
16465 int idx_protocol = 2;
16466 int type;
16467
16468 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16469 if (type < 0) {
16470 vty_out(vty, "%% Invalid route type\n");
16471 return CMD_WARNING_CONFIG_FAILED;
16472 }
16473
16474 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16475 }
16476
16477 /* Neighbor update tcp-mss. */
16478 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16479 const char *tcp_mss_str)
16480 {
16481 struct peer *peer;
16482 uint32_t tcp_mss_val = 0;
16483
16484 peer = peer_and_group_lookup_vty(vty, peer_str);
16485 if (!peer)
16486 return CMD_WARNING_CONFIG_FAILED;
16487
16488 if (tcp_mss_str) {
16489 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16490 peer_tcp_mss_set(peer, tcp_mss_val);
16491 } else {
16492 peer_tcp_mss_unset(peer);
16493 }
16494
16495 return CMD_SUCCESS;
16496 }
16497
16498 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16499 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16500 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16501 "TCP max segment size\n"
16502 "TCP MSS value\n")
16503 {
16504 int peer_index = 1;
16505 int mss_index = 3;
16506
16507 vty_out(vty,
16508 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16509 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16510 argv[mss_index]->arg);
16511 }
16512
16513 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16514 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16515 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16516 "TCP max segment size\n"
16517 "TCP MSS value\n")
16518 {
16519 int peer_index = 2;
16520
16521 vty_out(vty,
16522 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16523 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16524 }
16525
16526 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16527 "[no$no] bgp retain route-target all",
16528 NO_STR BGP_STR
16529 "Retain BGP updates\n"
16530 "Retain BGP updates based on route-target values\n"
16531 "Retain all BGP updates\n")
16532 {
16533 bool check;
16534 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16535
16536 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16537 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16538 if (check != !no) {
16539 if (!no)
16540 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16541 [bgp_node_safi(vty)],
16542 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16543 else
16544 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16545 [bgp_node_safi(vty)],
16546 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16547 /* trigger a flush to re-sync with ADJ-RIB-in */
16548 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16549 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16550 }
16551 return CMD_SUCCESS;
16552 }
16553
16554 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16555 afi_t afi, safi_t safi)
16556 {
16557 int i;
16558
16559 /* Unicast redistribution only. */
16560 if (safi != SAFI_UNICAST)
16561 return;
16562
16563 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16564 /* Redistribute BGP does not make sense. */
16565 if (i != ZEBRA_ROUTE_BGP) {
16566 struct list *red_list;
16567 struct listnode *node;
16568 struct bgp_redist *red;
16569
16570 red_list = bgp->redist[afi][i];
16571 if (!red_list)
16572 continue;
16573
16574 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16575 /* "redistribute" configuration. */
16576 vty_out(vty, " redistribute %s",
16577 zebra_route_string(i));
16578 if (red->instance)
16579 vty_out(vty, " %d", red->instance);
16580 if (red->redist_metric_flag)
16581 vty_out(vty, " metric %u",
16582 red->redist_metric);
16583 if (red->rmap.name)
16584 vty_out(vty, " route-map %s",
16585 red->rmap.name);
16586 vty_out(vty, "\n");
16587 }
16588 }
16589 }
16590 }
16591
16592 /* peer-group helpers for config-write */
16593
16594 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16595 {
16596 if (!peer_group_active(peer)) {
16597 if (CHECK_FLAG(peer->flags_invert, flag))
16598 return !CHECK_FLAG(peer->flags, flag);
16599 else
16600 return !!CHECK_FLAG(peer->flags, flag);
16601 }
16602
16603 return !!CHECK_FLAG(peer->flags_override, flag);
16604 }
16605
16606 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16607 uint64_t flag)
16608 {
16609 if (!peer_group_active(peer)) {
16610 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16611 return !peer_af_flag_check(peer, afi, safi, flag);
16612 else
16613 return !!peer_af_flag_check(peer, afi, safi, flag);
16614 }
16615
16616 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16617 }
16618
16619 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16620 uint8_t type, int direct)
16621 {
16622 struct bgp_filter *filter;
16623
16624 if (peer_group_active(peer))
16625 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16626 type);
16627
16628 filter = &peer->filter[afi][safi];
16629 switch (type) {
16630 case PEER_FT_DISTRIBUTE_LIST:
16631 return !!(filter->dlist[direct].name);
16632 case PEER_FT_FILTER_LIST:
16633 return !!(filter->aslist[direct].name);
16634 case PEER_FT_PREFIX_LIST:
16635 return !!(filter->plist[direct].name);
16636 case PEER_FT_ROUTE_MAP:
16637 return !!(filter->map[direct].name);
16638 case PEER_FT_UNSUPPRESS_MAP:
16639 return !!(filter->usmap.name);
16640 case PEER_FT_ADVERTISE_MAP:
16641 return !!(filter->advmap.aname
16642 && ((filter->advmap.condition == direct)
16643 && filter->advmap.cname));
16644 default:
16645 return false;
16646 }
16647 }
16648
16649 /* Return true if the addpath type is set for peer and different from
16650 * peer-group.
16651 */
16652 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16653 safi_t safi)
16654 {
16655 enum bgp_addpath_strat type, g_type;
16656
16657 type = peer->addpath_type[afi][safi];
16658
16659 if (type != BGP_ADDPATH_NONE) {
16660 if (peer_group_active(peer)) {
16661 g_type = peer->group->conf->addpath_type[afi][safi];
16662
16663 if (type != g_type)
16664 return true;
16665 else
16666 return false;
16667 }
16668
16669 return true;
16670 }
16671
16672 return false;
16673 }
16674
16675 /* This is part of the address-family block (unicast only) */
16676 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16677 afi_t afi)
16678 {
16679 int indent = 2;
16680 uint32_t tovpn_sid_index = 0;
16681
16682 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16683 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16684 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16685 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16686 bgp->vpn_policy[afi]
16687 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16688 else
16689 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16690 bgp->vpn_policy[afi]
16691 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16692 }
16693 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16694 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16695 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16696 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16697 return;
16698
16699 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16700 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16701
16702 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16703
16704 } else {
16705 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16706 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16707 bgp->vpn_policy[afi].tovpn_label);
16708 }
16709 }
16710
16711 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16712 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16713 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16714 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16715 } else if (tovpn_sid_index != 0) {
16716 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16717 tovpn_sid_index);
16718 }
16719
16720 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16721 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16722 &bgp->vpn_policy[afi].tovpn_rd);
16723
16724 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16725 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16726
16727 char buf[PREFIX_STRLEN];
16728 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16729 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16730 sizeof(buf))) {
16731
16732 vty_out(vty, "%*snexthop vpn export %s\n",
16733 indent, "", buf);
16734 }
16735 }
16736 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16737 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16738 && ecommunity_cmp(
16739 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16740 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16741
16742 char *b = ecommunity_ecom2str(
16743 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16744 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16745 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16746 XFREE(MTYPE_ECOMMUNITY_STR, b);
16747 } else {
16748 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16749 char *b = ecommunity_ecom2str(
16750 bgp->vpn_policy[afi]
16751 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16752 ECOMMUNITY_FORMAT_ROUTE_MAP,
16753 ECOMMUNITY_ROUTE_TARGET);
16754 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16755 XFREE(MTYPE_ECOMMUNITY_STR, b);
16756 }
16757 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16758 char *b = ecommunity_ecom2str(
16759 bgp->vpn_policy[afi]
16760 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16761 ECOMMUNITY_FORMAT_ROUTE_MAP,
16762 ECOMMUNITY_ROUTE_TARGET);
16763 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16764 XFREE(MTYPE_ECOMMUNITY_STR, b);
16765 }
16766 }
16767
16768 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16769 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16770 bgp->vpn_policy[afi]
16771 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16772
16773 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16774 char *b = ecommunity_ecom2str(
16775 bgp->vpn_policy[afi]
16776 .import_redirect_rtlist,
16777 ECOMMUNITY_FORMAT_ROUTE_MAP,
16778 ECOMMUNITY_ROUTE_TARGET);
16779
16780 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16781 != ECOMMUNITY_SIZE)
16782 vty_out(vty, "%*srt6 redirect import %s\n",
16783 indent, "", b);
16784 else
16785 vty_out(vty, "%*srt redirect import %s\n",
16786 indent, "", b);
16787 XFREE(MTYPE_ECOMMUNITY_STR, b);
16788 }
16789 }
16790
16791 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16792 afi_t afi, safi_t safi)
16793 {
16794 struct bgp_filter *filter;
16795 char *addr;
16796
16797 addr = peer->host;
16798 filter = &peer->filter[afi][safi];
16799
16800 /* distribute-list. */
16801 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16802 FILTER_IN))
16803 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16804 filter->dlist[FILTER_IN].name);
16805
16806 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16807 FILTER_OUT))
16808 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16809 filter->dlist[FILTER_OUT].name);
16810
16811 /* prefix-list. */
16812 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16813 FILTER_IN))
16814 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16815 filter->plist[FILTER_IN].name);
16816
16817 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16818 FILTER_OUT))
16819 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16820 filter->plist[FILTER_OUT].name);
16821
16822 /* route-map. */
16823 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16824 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16825 filter->map[RMAP_IN].name);
16826
16827 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16828 RMAP_OUT))
16829 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16830 filter->map[RMAP_OUT].name);
16831
16832 /* unsuppress-map */
16833 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16834 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16835 filter->usmap.name);
16836
16837 /* advertise-map : always applied in OUT direction*/
16838 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16839 CONDITION_NON_EXIST))
16840 vty_out(vty,
16841 " neighbor %s advertise-map %s non-exist-map %s\n",
16842 addr, filter->advmap.aname, filter->advmap.cname);
16843
16844 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16845 CONDITION_EXIST))
16846 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16847 addr, filter->advmap.aname, filter->advmap.cname);
16848
16849 /* filter-list. */
16850 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16851 FILTER_IN))
16852 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16853 filter->aslist[FILTER_IN].name);
16854
16855 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16856 FILTER_OUT))
16857 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16858 filter->aslist[FILTER_OUT].name);
16859 }
16860
16861 /* BGP peer configuration display function. */
16862 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16863 struct peer *peer)
16864 {
16865 struct peer *g_peer = NULL;
16866 char *addr;
16867 int if_pg_printed = false;
16868 int if_ras_printed = false;
16869
16870 /* Skip dynamic neighbors. */
16871 if (peer_dynamic_neighbor(peer))
16872 return;
16873
16874 if (peer->conf_if)
16875 addr = peer->conf_if;
16876 else
16877 addr = peer->host;
16878
16879 /************************************
16880 ****** Global to the neighbor ******
16881 ************************************/
16882 if (peer->conf_if) {
16883 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16884 vty_out(vty, " neighbor %s interface v6only", addr);
16885 else
16886 vty_out(vty, " neighbor %s interface", addr);
16887
16888 if (peer_group_active(peer)) {
16889 vty_out(vty, " peer-group %s", peer->group->name);
16890 if_pg_printed = true;
16891 } else if (peer->as_type == AS_SPECIFIED) {
16892 vty_out(vty, " remote-as %u", peer->as);
16893 if_ras_printed = true;
16894 } else if (peer->as_type == AS_INTERNAL) {
16895 vty_out(vty, " remote-as internal");
16896 if_ras_printed = true;
16897 } else if (peer->as_type == AS_EXTERNAL) {
16898 vty_out(vty, " remote-as external");
16899 if_ras_printed = true;
16900 }
16901
16902 vty_out(vty, "\n");
16903 }
16904
16905 /* remote-as and peer-group */
16906 /* peer is a member of a peer-group */
16907 if (peer_group_active(peer)) {
16908 g_peer = peer->group->conf;
16909
16910 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16911 if (peer->as_type == AS_SPECIFIED) {
16912 vty_out(vty, " neighbor %s remote-as %u\n",
16913 addr, peer->as);
16914 } else if (peer->as_type == AS_INTERNAL) {
16915 vty_out(vty,
16916 " neighbor %s remote-as internal\n",
16917 addr);
16918 } else if (peer->as_type == AS_EXTERNAL) {
16919 vty_out(vty,
16920 " neighbor %s remote-as external\n",
16921 addr);
16922 }
16923 }
16924
16925 /* For swpX peers we displayed the peer-group
16926 * via 'neighbor swpX interface peer-group PGNAME' */
16927 if (!if_pg_printed)
16928 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16929 peer->group->name);
16930 }
16931
16932 /* peer is NOT a member of a peer-group */
16933 else {
16934 /* peer is a peer-group, declare the peer-group */
16935 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16936 vty_out(vty, " neighbor %s peer-group\n", addr);
16937 }
16938
16939 if (!if_ras_printed) {
16940 if (peer->as_type == AS_SPECIFIED) {
16941 vty_out(vty, " neighbor %s remote-as %u\n",
16942 addr, peer->as);
16943 } else if (peer->as_type == AS_INTERNAL) {
16944 vty_out(vty,
16945 " neighbor %s remote-as internal\n",
16946 addr);
16947 } else if (peer->as_type == AS_EXTERNAL) {
16948 vty_out(vty,
16949 " neighbor %s remote-as external\n",
16950 addr);
16951 }
16952 }
16953 }
16954
16955 /* local-as */
16956 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16957 vty_out(vty, " neighbor %s local-as %u", addr,
16958 peer->change_local_as);
16959 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16960 vty_out(vty, " no-prepend");
16961 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16962 vty_out(vty, " replace-as");
16963 vty_out(vty, "\n");
16964 }
16965
16966 /* description */
16967 if (peer->desc) {
16968 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16969 }
16970
16971 /* shutdown */
16972 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16973 if (peer->tx_shutdown_message)
16974 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16975 peer->tx_shutdown_message);
16976 else
16977 vty_out(vty, " neighbor %s shutdown\n", addr);
16978 }
16979
16980 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16981 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16982 peer->rtt_expected, peer->rtt_keepalive_conf);
16983
16984 /* bfd */
16985 if (peer->bfd_config)
16986 bgp_bfd_peer_config_write(vty, peer, addr);
16987
16988 /* password */
16989 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16990 vty_out(vty, " neighbor %s password %s\n", addr,
16991 peer->password);
16992
16993 /* neighbor solo */
16994 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16995 if (!peer_group_active(peer)) {
16996 vty_out(vty, " neighbor %s solo\n", addr);
16997 }
16998 }
16999
17000 /* BGP port */
17001 if (peer->port != BGP_PORT_DEFAULT) {
17002 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17003 }
17004
17005 /* Local interface name */
17006 if (peer->ifname) {
17007 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17008 }
17009
17010 /* TCP max segment size */
17011 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17012 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17013
17014 /* passive */
17015 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17016 vty_out(vty, " neighbor %s passive\n", addr);
17017
17018 /* ebgp-multihop */
17019 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17020 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17021 && peer->ttl == MAXTTL)) {
17022 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17023 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17024 peer->ttl);
17025 }
17026 }
17027
17028 /* role */
17029 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17030 peer->local_role != ROLE_UNDEFINED)
17031 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17032 bgp_get_name_by_role(peer->local_role),
17033 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17034 ? " strict-mode"
17035 : "");
17036
17037 /* ttl-security hops */
17038 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17039 if (!peer_group_active(peer)
17040 || g_peer->gtsm_hops != peer->gtsm_hops) {
17041 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17042 addr, peer->gtsm_hops);
17043 }
17044 }
17045
17046 /* disable-connected-check */
17047 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17048 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17049
17050 /* link-bw-encoding-ieee */
17051 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17052 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17053 addr);
17054
17055 /* extended-optional-parameters */
17056 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17057 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17058 addr);
17059
17060 /* enforce-first-as */
17061 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17062 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17063
17064 /* update-source */
17065 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17066 if (peer->update_source)
17067 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17068 peer->update_source);
17069 else if (peer->update_if)
17070 vty_out(vty, " neighbor %s update-source %s\n", addr,
17071 peer->update_if);
17072 }
17073
17074 /* advertisement-interval */
17075 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17076 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17077 peer->routeadv);
17078
17079 /* timers */
17080 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17081 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17082 peer->keepalive, peer->holdtime);
17083
17084 /* timers connect */
17085 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17086 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17087 peer->connect);
17088 /* need special-case handling for changed default values due to
17089 * config profile / version (because there is no "timers bgp connect"
17090 * command, we need to save this per-peer :/)
17091 */
17092 else if (!peer_group_active(peer) && !peer->connect &&
17093 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17094 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17095 peer->bgp->default_connect_retry);
17096
17097 /* timers delayopen */
17098 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17099 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17100 peer->delayopen);
17101 /* Save config even though flag is not set if default values have been
17102 * changed
17103 */
17104 else if (!peer_group_active(peer) && !peer->delayopen
17105 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17106 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17107 peer->bgp->default_delayopen);
17108
17109 /* capability dynamic */
17110 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17111 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17112
17113 /* capability extended-nexthop */
17114 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17115 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17116 !peer->conf_if)
17117 vty_out(vty,
17118 " no neighbor %s capability extended-nexthop\n",
17119 addr);
17120 else if (!peer->conf_if)
17121 vty_out(vty,
17122 " neighbor %s capability extended-nexthop\n",
17123 addr);
17124 }
17125
17126 /* dont-capability-negotiation */
17127 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17128 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17129
17130 /* override-capability */
17131 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17132 vty_out(vty, " neighbor %s override-capability\n", addr);
17133
17134 /* strict-capability-match */
17135 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17136 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17137
17138 /* Sender side AS path loop detection. */
17139 if (peer->as_path_loop_detection)
17140 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17141 addr);
17142
17143 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17144 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17145
17146 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17147 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17148 vty_out(vty,
17149 " neighbor %s graceful-restart-helper\n", addr);
17150 } else if (CHECK_FLAG(
17151 peer->peer_gr_new_status_flag,
17152 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17153 vty_out(vty,
17154 " neighbor %s graceful-restart\n", addr);
17155 } else if (
17156 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17157 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17158 && !(CHECK_FLAG(
17159 peer->peer_gr_new_status_flag,
17160 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17161 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17162 addr);
17163 }
17164 }
17165 }
17166
17167 /* BGP peer configuration display function. */
17168 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17169 struct peer *peer, afi_t afi, safi_t safi)
17170 {
17171 struct peer *g_peer = NULL;
17172 char *addr;
17173 bool flag_scomm, flag_secomm, flag_slcomm;
17174
17175 /* Skip dynamic neighbors. */
17176 if (peer_dynamic_neighbor(peer))
17177 return;
17178
17179 if (peer->conf_if)
17180 addr = peer->conf_if;
17181 else
17182 addr = peer->host;
17183
17184 /************************************
17185 ****** Per AF to the neighbor ******
17186 ************************************/
17187 if (peer_group_active(peer)) {
17188 g_peer = peer->group->conf;
17189
17190 /* If the peer-group is active but peer is not, print a 'no
17191 * activate' */
17192 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17193 vty_out(vty, " no neighbor %s activate\n", addr);
17194 }
17195
17196 /* If the peer-group is not active but peer is, print an
17197 'activate' */
17198 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17199 vty_out(vty, " neighbor %s activate\n", addr);
17200 }
17201 } else {
17202 if (peer->afc[afi][safi]) {
17203 if (safi == SAFI_ENCAP)
17204 vty_out(vty, " neighbor %s activate\n", addr);
17205 else if (!bgp->default_af[afi][safi])
17206 vty_out(vty, " neighbor %s activate\n", addr);
17207 } else {
17208 if (bgp->default_af[afi][safi])
17209 vty_out(vty, " no neighbor %s activate\n",
17210 addr);
17211 }
17212 }
17213
17214 /* addpath TX knobs */
17215 if (peergroup_af_addpath_check(peer, afi, safi)) {
17216 switch (peer->addpath_type[afi][safi]) {
17217 case BGP_ADDPATH_ALL:
17218 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17219 addr);
17220 break;
17221 case BGP_ADDPATH_BEST_PER_AS:
17222 vty_out(vty,
17223 " neighbor %s addpath-tx-bestpath-per-AS\n",
17224 addr);
17225 break;
17226 case BGP_ADDPATH_MAX:
17227 case BGP_ADDPATH_NONE:
17228 break;
17229 }
17230 }
17231
17232 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17233 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17234
17235 /* ORF capability. */
17236 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17237 || peergroup_af_flag_check(peer, afi, safi,
17238 PEER_FLAG_ORF_PREFIX_RM)) {
17239 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17240
17241 if (peergroup_af_flag_check(peer, afi, safi,
17242 PEER_FLAG_ORF_PREFIX_SM)
17243 && peergroup_af_flag_check(peer, afi, safi,
17244 PEER_FLAG_ORF_PREFIX_RM))
17245 vty_out(vty, " both");
17246 else if (peergroup_af_flag_check(peer, afi, safi,
17247 PEER_FLAG_ORF_PREFIX_SM))
17248 vty_out(vty, " send");
17249 else
17250 vty_out(vty, " receive");
17251 vty_out(vty, "\n");
17252 }
17253
17254 /* Route reflector client. */
17255 if (peergroup_af_flag_check(peer, afi, safi,
17256 PEER_FLAG_REFLECTOR_CLIENT)) {
17257 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17258 }
17259
17260 /* next-hop-self force */
17261 if (peergroup_af_flag_check(peer, afi, safi,
17262 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17263 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17264 }
17265
17266 /* next-hop-self */
17267 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17268 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17269 }
17270
17271 /* remove-private-AS */
17272 if (peergroup_af_flag_check(peer, afi, safi,
17273 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17274 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17275 addr);
17276 }
17277
17278 else if (peergroup_af_flag_check(peer, afi, safi,
17279 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17280 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17281 addr);
17282 }
17283
17284 else if (peergroup_af_flag_check(peer, afi, safi,
17285 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17286 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17287 }
17288
17289 else if (peergroup_af_flag_check(peer, afi, safi,
17290 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17291 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17292 }
17293
17294 /* as-override */
17295 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17296 vty_out(vty, " neighbor %s as-override\n", addr);
17297 }
17298
17299 /* send-community print. */
17300 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17301 PEER_FLAG_SEND_COMMUNITY);
17302 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17303 PEER_FLAG_SEND_EXT_COMMUNITY);
17304 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17305 PEER_FLAG_SEND_LARGE_COMMUNITY);
17306
17307 if (flag_scomm && flag_secomm && flag_slcomm) {
17308 vty_out(vty, " no neighbor %s send-community all\n", addr);
17309 } else {
17310 if (flag_scomm)
17311 vty_out(vty, " no neighbor %s send-community\n", addr);
17312 if (flag_secomm)
17313 vty_out(vty,
17314 " no neighbor %s send-community extended\n",
17315 addr);
17316
17317 if (flag_slcomm)
17318 vty_out(vty, " no neighbor %s send-community large\n",
17319 addr);
17320 }
17321
17322 /* Default information */
17323 if (peergroup_af_flag_check(peer, afi, safi,
17324 PEER_FLAG_DEFAULT_ORIGINATE)) {
17325 vty_out(vty, " neighbor %s default-originate", addr);
17326
17327 if (peer->default_rmap[afi][safi].name)
17328 vty_out(vty, " route-map %s",
17329 peer->default_rmap[afi][safi].name);
17330
17331 vty_out(vty, "\n");
17332 }
17333
17334 /* Soft reconfiguration inbound. */
17335 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17336 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17337 addr);
17338 }
17339
17340 /* maximum-prefix. */
17341 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17342 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17343 peer->pmax[afi][safi]);
17344
17345 if (peer->pmax_threshold[afi][safi]
17346 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17347 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17348 if (peer_af_flag_check(peer, afi, safi,
17349 PEER_FLAG_MAX_PREFIX_WARNING))
17350 vty_out(vty, " warning-only");
17351 if (peer->pmax_restart[afi][safi])
17352 vty_out(vty, " restart %u",
17353 peer->pmax_restart[afi][safi]);
17354 if (peer_af_flag_check(peer, afi, safi,
17355 PEER_FLAG_MAX_PREFIX_FORCE))
17356 vty_out(vty, " force");
17357
17358 vty_out(vty, "\n");
17359 }
17360
17361 /* maximum-prefix-out */
17362 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17363 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17364 addr, peer->pmax_out[afi][safi]);
17365
17366 /* Route server client. */
17367 if (peergroup_af_flag_check(peer, afi, safi,
17368 PEER_FLAG_RSERVER_CLIENT)) {
17369 vty_out(vty, " neighbor %s route-server-client\n", addr);
17370 }
17371
17372 /* Nexthop-local unchanged. */
17373 if (peergroup_af_flag_check(peer, afi, safi,
17374 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17375 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17376 }
17377
17378 /* allowas-in <1-10> */
17379 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17380 if (peer_af_flag_check(peer, afi, safi,
17381 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17382 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17383 } else if (peer->allowas_in[afi][safi] == 3) {
17384 vty_out(vty, " neighbor %s allowas-in\n", addr);
17385 } else {
17386 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17387 peer->allowas_in[afi][safi]);
17388 }
17389 }
17390
17391 /* accept-own */
17392 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17393 vty_out(vty, " neighbor %s accept-own\n", addr);
17394
17395 /* soo */
17396 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17397 char *soo_str = ecommunity_ecom2str(
17398 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17399
17400 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17401 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17402 }
17403
17404 /* weight */
17405 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17406 vty_out(vty, " neighbor %s weight %lu\n", addr,
17407 peer->weight[afi][safi]);
17408
17409 /* Filter. */
17410 bgp_config_write_filter(vty, peer, afi, safi);
17411
17412 /* atribute-unchanged. */
17413 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17414 || (safi != SAFI_EVPN
17415 && peer_af_flag_check(peer, afi, safi,
17416 PEER_FLAG_NEXTHOP_UNCHANGED))
17417 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17418
17419 if (!peer_group_active(peer)
17420 || peergroup_af_flag_check(peer, afi, safi,
17421 PEER_FLAG_AS_PATH_UNCHANGED)
17422 || peergroup_af_flag_check(peer, afi, safi,
17423 PEER_FLAG_NEXTHOP_UNCHANGED)
17424 || peergroup_af_flag_check(peer, afi, safi,
17425 PEER_FLAG_MED_UNCHANGED)) {
17426
17427 vty_out(vty,
17428 " neighbor %s attribute-unchanged%s%s%s\n",
17429 addr,
17430 peer_af_flag_check(peer, afi, safi,
17431 PEER_FLAG_AS_PATH_UNCHANGED)
17432 ? " as-path"
17433 : "",
17434 peer_af_flag_check(peer, afi, safi,
17435 PEER_FLAG_NEXTHOP_UNCHANGED)
17436 ? " next-hop"
17437 : "",
17438 peer_af_flag_check(peer, afi, safi,
17439 PEER_FLAG_MED_UNCHANGED)
17440 ? " med"
17441 : "");
17442 }
17443 }
17444
17445 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_ORR_GROUP))
17446 vty_out(vty, " neighbor %s optimal-route-reflection %s\n",
17447 addr, peer->orr_group_name[afi][safi]);
17448 }
17449
17450 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17451 safi_t safi)
17452 {
17453 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17454 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17455 vty_out(vty, " no bgp retain route-target all\n");
17456 }
17457
17458 /* Address family based peer configuration display. */
17459 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17460 safi_t safi)
17461 {
17462 struct peer *peer;
17463 struct peer_group *group;
17464 struct listnode *node, *nnode;
17465
17466
17467 vty_frame(vty, " !\n address-family ");
17468 if (afi == AFI_IP) {
17469 if (safi == SAFI_UNICAST)
17470 vty_frame(vty, "ipv4 unicast");
17471 else if (safi == SAFI_LABELED_UNICAST)
17472 vty_frame(vty, "ipv4 labeled-unicast");
17473 else if (safi == SAFI_MULTICAST)
17474 vty_frame(vty, "ipv4 multicast");
17475 else if (safi == SAFI_MPLS_VPN)
17476 vty_frame(vty, "ipv4 vpn");
17477 else if (safi == SAFI_ENCAP)
17478 vty_frame(vty, "ipv4 encap");
17479 else if (safi == SAFI_FLOWSPEC)
17480 vty_frame(vty, "ipv4 flowspec");
17481 } else if (afi == AFI_IP6) {
17482 if (safi == SAFI_UNICAST)
17483 vty_frame(vty, "ipv6 unicast");
17484 else if (safi == SAFI_LABELED_UNICAST)
17485 vty_frame(vty, "ipv6 labeled-unicast");
17486 else if (safi == SAFI_MULTICAST)
17487 vty_frame(vty, "ipv6 multicast");
17488 else if (safi == SAFI_MPLS_VPN)
17489 vty_frame(vty, "ipv6 vpn");
17490 else if (safi == SAFI_ENCAP)
17491 vty_frame(vty, "ipv6 encap");
17492 else if (safi == SAFI_FLOWSPEC)
17493 vty_frame(vty, "ipv6 flowspec");
17494 } else if (afi == AFI_L2VPN) {
17495 if (safi == SAFI_EVPN)
17496 vty_frame(vty, "l2vpn evpn");
17497 }
17498 vty_frame(vty, "\n");
17499
17500 bgp_config_write_distance(vty, bgp, afi, safi);
17501
17502 bgp_config_write_network(vty, bgp, afi, safi);
17503
17504 bgp_config_write_redistribute(vty, bgp, afi, safi);
17505
17506 /* BGP flag dampening. */
17507 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17508 bgp_config_write_damp(vty, afi, safi);
17509
17510 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17511 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17512
17513 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17514 /* Do not display doppelganger peers */
17515 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17516 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17517 }
17518
17519 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17520 bgp_config_write_table_map(vty, bgp, afi, safi);
17521
17522 if (safi == SAFI_EVPN)
17523 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17524
17525 if (safi == SAFI_FLOWSPEC)
17526 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17527
17528 if (safi == SAFI_MPLS_VPN)
17529 bgp_vpn_config_write(vty, bgp, afi, safi);
17530
17531 if (safi == SAFI_UNICAST) {
17532 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17533 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17534 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17535
17536 vty_out(vty, " export vpn\n");
17537 }
17538 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17539 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17540
17541 vty_out(vty, " import vpn\n");
17542 }
17543 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17544 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17545 char *name;
17546
17547 for (ALL_LIST_ELEMENTS_RO(
17548 bgp->vpn_policy[afi].import_vrf, node,
17549 name))
17550 vty_out(vty, " import vrf %s\n", name);
17551 }
17552 }
17553
17554 /* Optimal Route Reflection */
17555 bgp_config_write_orr(vty, bgp, afi, safi);
17556
17557 vty_endframe(vty, " exit-address-family\n");
17558 }
17559
17560 int bgp_config_write(struct vty *vty)
17561 {
17562 struct bgp *bgp;
17563 struct peer_group *group;
17564 struct peer *peer;
17565 struct listnode *node, *nnode;
17566 struct listnode *mnode, *mnnode;
17567 afi_t afi;
17568 safi_t safi;
17569
17570 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17571 vty_out(vty, "bgp route-map delay-timer %u\n",
17572 bm->rmap_update_timer);
17573
17574 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17575 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17576 if (bm->v_update_delay != bm->v_establish_wait)
17577 vty_out(vty, " %d", bm->v_establish_wait);
17578 vty_out(vty, "\n");
17579 }
17580
17581 if (bm->wait_for_fib)
17582 vty_out(vty, "bgp suppress-fib-pending\n");
17583
17584 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17585 vty_out(vty, "bgp graceful-shutdown\n");
17586
17587 /* No-RIB (Zebra) option flag configuration */
17588 if (bgp_option_check(BGP_OPT_NO_FIB))
17589 vty_out(vty, "bgp no-rib\n");
17590
17591 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17592 vty_out(vty, "bgp send-extra-data zebra\n");
17593
17594 /* BGP session DSCP value */
17595 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17596 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17597
17598 /* BGP configuration. */
17599 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17600
17601 /* skip all auto created vrf as they dont have user config */
17602 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17603 continue;
17604
17605 /* Router bgp ASN */
17606 vty_out(vty, "router bgp %u", bgp->as);
17607
17608 if (bgp->name)
17609 vty_out(vty, " %s %s",
17610 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17611 ? "view" : "vrf", bgp->name);
17612 vty_out(vty, "\n");
17613
17614 /* BGP fast-external-failover. */
17615 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17616 vty_out(vty, " no bgp fast-external-failover\n");
17617
17618 /* BGP router ID. */
17619 if (bgp->router_id_static.s_addr != INADDR_ANY)
17620 vty_out(vty, " bgp router-id %pI4\n",
17621 &bgp->router_id_static);
17622
17623 /* Suppress fib pending */
17624 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17625 vty_out(vty, " bgp suppress-fib-pending\n");
17626
17627 /* BGP log-neighbor-changes. */
17628 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17629 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17630 vty_out(vty, " %sbgp log-neighbor-changes\n",
17631 CHECK_FLAG(bgp->flags,
17632 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17633 ? ""
17634 : "no ");
17635
17636 /* BGP configuration. */
17637 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17638 vty_out(vty, " bgp always-compare-med\n");
17639
17640 /* RFC8212 default eBGP policy. */
17641 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17642 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17643 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17644 CHECK_FLAG(bgp->flags,
17645 BGP_FLAG_EBGP_REQUIRES_POLICY)
17646 ? ""
17647 : "no ");
17648
17649 /* draft-ietf-idr-deprecate-as-set-confed-set */
17650 if (bgp->reject_as_sets)
17651 vty_out(vty, " bgp reject-as-sets\n");
17652
17653 /* Suppress duplicate updates if the route actually not changed
17654 */
17655 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17656 != SAVE_BGP_SUPPRESS_DUPLICATES)
17657 vty_out(vty, " %sbgp suppress-duplicates\n",
17658 CHECK_FLAG(bgp->flags,
17659 BGP_FLAG_SUPPRESS_DUPLICATES)
17660 ? ""
17661 : "no ");
17662
17663 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17664 */
17665 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17666 SAVE_BGP_HARD_ADMIN_RESET)
17667 vty_out(vty, " %sbgp hard-administrative-reset\n",
17668 CHECK_FLAG(bgp->flags,
17669 BGP_FLAG_HARD_ADMIN_RESET)
17670 ? ""
17671 : "no ");
17672
17673 /* BGP default <afi>-<safi> */
17674 FOREACH_AFI_SAFI (afi, safi) {
17675 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17676 if (!bgp->default_af[afi][safi])
17677 vty_out(vty, " no bgp default %s\n",
17678 get_bgp_default_af_flag(afi,
17679 safi));
17680 } else if (bgp->default_af[afi][safi])
17681 vty_out(vty, " bgp default %s\n",
17682 get_bgp_default_af_flag(afi, safi));
17683 }
17684
17685 /* BGP default local-preference. */
17686 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17687 vty_out(vty, " bgp default local-preference %u\n",
17688 bgp->default_local_pref);
17689
17690 /* BGP default show-hostname */
17691 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17692 != SAVE_BGP_SHOW_HOSTNAME)
17693 vty_out(vty, " %sbgp default show-hostname\n",
17694 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17695 ? ""
17696 : "no ");
17697
17698 /* BGP default show-nexthop-hostname */
17699 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17700 != SAVE_BGP_SHOW_HOSTNAME)
17701 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17702 CHECK_FLAG(bgp->flags,
17703 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17704 ? ""
17705 : "no ");
17706
17707 /* BGP default subgroup-pkt-queue-max. */
17708 if (bgp->default_subgroup_pkt_queue_max
17709 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17710 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17711 bgp->default_subgroup_pkt_queue_max);
17712
17713 /* BGP client-to-client reflection. */
17714 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17715 vty_out(vty, " no bgp client-to-client reflection\n");
17716
17717 /* BGP cluster ID. */
17718 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17719 vty_out(vty, " bgp cluster-id %pI4\n",
17720 &bgp->cluster_id);
17721
17722 /* Disable ebgp connected nexthop check */
17723 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17724 vty_out(vty,
17725 " bgp disable-ebgp-connected-route-check\n");
17726
17727 /* Confederation identifier*/
17728 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17729 vty_out(vty, " bgp confederation identifier %u\n",
17730 bgp->confed_id);
17731
17732 /* Confederation peer */
17733 if (bgp->confed_peers_cnt > 0) {
17734 int i;
17735
17736 vty_out(vty, " bgp confederation peers");
17737
17738 for (i = 0; i < bgp->confed_peers_cnt; i++)
17739 vty_out(vty, " %u", bgp->confed_peers[i]);
17740
17741 vty_out(vty, "\n");
17742 }
17743
17744 /* BGP deterministic-med. */
17745 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17746 != SAVE_BGP_DETERMINISTIC_MED)
17747 vty_out(vty, " %sbgp deterministic-med\n",
17748 CHECK_FLAG(bgp->flags,
17749 BGP_FLAG_DETERMINISTIC_MED)
17750 ? ""
17751 : "no ");
17752
17753 /* BGP update-delay. */
17754 bgp_config_write_update_delay(vty, bgp);
17755
17756 if (bgp->v_maxmed_onstartup
17757 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17758 vty_out(vty, " bgp max-med on-startup %u",
17759 bgp->v_maxmed_onstartup);
17760 if (bgp->maxmed_onstartup_value
17761 != BGP_MAXMED_VALUE_DEFAULT)
17762 vty_out(vty, " %u",
17763 bgp->maxmed_onstartup_value);
17764 vty_out(vty, "\n");
17765 }
17766 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17767 vty_out(vty, " bgp max-med administrative");
17768 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17769 vty_out(vty, " %u", bgp->maxmed_admin_value);
17770 vty_out(vty, "\n");
17771 }
17772
17773 /* write quanta */
17774 bgp_config_write_wpkt_quanta(vty, bgp);
17775 /* read quanta */
17776 bgp_config_write_rpkt_quanta(vty, bgp);
17777
17778 /* coalesce time */
17779 bgp_config_write_coalesce_time(vty, bgp);
17780
17781 /* BGP per-instance graceful-shutdown */
17782 /* BGP-wide settings and per-instance settings are mutually
17783 * exclusive.
17784 */
17785 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17786 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17787 vty_out(vty, " bgp graceful-shutdown\n");
17788
17789 /* Long-lived Graceful Restart */
17790 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17791 vty_out(vty,
17792 " bgp long-lived-graceful-restart stale-time %u\n",
17793 bgp->llgr_stale_time);
17794
17795 /* BGP graceful-restart. */
17796 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17797 vty_out(vty,
17798 " bgp graceful-restart stalepath-time %u\n",
17799 bgp->stalepath_time);
17800
17801 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17802 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17803 bgp->restart_time);
17804
17805 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17806 SAVE_BGP_GRACEFUL_NOTIFICATION)
17807 vty_out(vty, " %sbgp graceful-restart notification\n",
17808 CHECK_FLAG(bgp->flags,
17809 BGP_FLAG_GRACEFUL_NOTIFICATION)
17810 ? ""
17811 : "no ");
17812
17813 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17814 vty_out(vty,
17815 " bgp graceful-restart select-defer-time %u\n",
17816 bgp->select_defer_time);
17817
17818 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17819 vty_out(vty, " bgp graceful-restart\n");
17820
17821 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17822 vty_out(vty, " bgp graceful-restart-disable\n");
17823
17824 /* BGP graceful-restart Preserve State F bit. */
17825 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17826 vty_out(vty,
17827 " bgp graceful-restart preserve-fw-state\n");
17828
17829 /* BGP TCP keepalive */
17830 bgp_config_tcp_keepalive(vty, bgp);
17831
17832 /* Stale timer for RIB */
17833 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17834 vty_out(vty,
17835 " bgp graceful-restart rib-stale-time %u\n",
17836 bgp->rib_stale_time);
17837
17838 /* BGP bestpath method. */
17839 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17840 vty_out(vty, " bgp bestpath as-path ignore\n");
17841 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17842 vty_out(vty, " bgp bestpath as-path confed\n");
17843
17844 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17845 if (CHECK_FLAG(bgp->flags,
17846 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17847 vty_out(vty,
17848 " bgp bestpath as-path multipath-relax as-set\n");
17849 } else {
17850 vty_out(vty,
17851 " bgp bestpath as-path multipath-relax\n");
17852 }
17853 }
17854
17855 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17856 vty_out(vty,
17857 " bgp route-reflector allow-outbound-policy\n");
17858 }
17859 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17860 vty_out(vty, " bgp bestpath compare-routerid\n");
17861 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17862 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17863 vty_out(vty, " bgp bestpath med");
17864 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17865 vty_out(vty, " confed");
17866 if (CHECK_FLAG(bgp->flags,
17867 BGP_FLAG_MED_MISSING_AS_WORST))
17868 vty_out(vty, " missing-as-worst");
17869 vty_out(vty, "\n");
17870 }
17871
17872 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17873 vty_out(vty,
17874 " bgp bestpath peer-type multipath-relax\n");
17875
17876 /* Link bandwidth handling. */
17877 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17878 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17879 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17880 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17881 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17882 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17883
17884 /* BGP network import check. */
17885 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17886 != SAVE_BGP_IMPORT_CHECK)
17887 vty_out(vty, " %sbgp network import-check\n",
17888 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17889 ? ""
17890 : "no ");
17891
17892 /* BGP timers configuration. */
17893 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17894 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17895 vty_out(vty, " timers bgp %u %u\n",
17896 bgp->default_keepalive, bgp->default_holdtime);
17897
17898 /* BGP minimum holdtime configuration. */
17899 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17900 && bgp->default_min_holdtime != 0)
17901 vty_out(vty, " bgp minimum-holdtime %u\n",
17902 bgp->default_min_holdtime);
17903
17904 /* Conditional advertisement timer configuration */
17905 if (bgp->condition_check_period
17906 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17907 vty_out(vty,
17908 " bgp conditional-advertisement timer %u\n",
17909 bgp->condition_check_period);
17910
17911 /* peer-group */
17912 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17913 bgp_config_write_peer_global(vty, bgp, group->conf);
17914 }
17915
17916 /* Normal neighbor configuration. */
17917 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17918 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17919 bgp_config_write_peer_global(vty, bgp, peer);
17920 }
17921
17922 /* listen range and limit for dynamic BGP neighbors */
17923 bgp_config_write_listen(vty, bgp);
17924
17925 /*
17926 * BGP default autoshutdown neighbors
17927 *
17928 * This must be placed after any peer and peer-group
17929 * configuration, to avoid setting all peers to shutdown after
17930 * a daemon restart, which is undesired behavior. (see #2286)
17931 */
17932 if (bgp->autoshutdown)
17933 vty_out(vty, " bgp default shutdown\n");
17934
17935 /* BGP instance administrative shutdown */
17936 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17937 vty_out(vty, " bgp shutdown\n");
17938
17939 if (bgp->allow_martian)
17940 vty_out(vty, " bgp allow-martian-nexthop\n");
17941
17942 if (bgp->fast_convergence)
17943 vty_out(vty, " bgp fast-convergence\n");
17944
17945 if (bgp->srv6_enabled) {
17946 vty_frame(vty, " !\n segment-routing srv6\n");
17947 if (strlen(bgp->srv6_locator_name))
17948 vty_out(vty, " locator %s\n",
17949 bgp->srv6_locator_name);
17950 vty_endframe(vty, " exit\n");
17951 }
17952
17953
17954 /* IPv4 unicast configuration. */
17955 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17956
17957 /* IPv4 multicast configuration. */
17958 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17959
17960 /* IPv4 labeled-unicast configuration. */
17961 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17962
17963 /* IPv4 VPN configuration. */
17964 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17965
17966 /* ENCAPv4 configuration. */
17967 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17968
17969 /* FLOWSPEC v4 configuration. */
17970 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17971
17972 /* IPv6 unicast configuration. */
17973 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17974
17975 /* IPv6 multicast configuration. */
17976 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17977
17978 /* IPv6 labeled-unicast configuration. */
17979 bgp_config_write_family(vty, bgp, AFI_IP6,
17980 SAFI_LABELED_UNICAST);
17981
17982 /* IPv6 VPN configuration. */
17983 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17984
17985 /* ENCAPv6 configuration. */
17986 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17987
17988 /* FLOWSPEC v6 configuration. */
17989 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17990
17991 /* EVPN configuration. */
17992 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17993
17994 hook_call(bgp_inst_config_write, bgp, vty);
17995
17996 #ifdef ENABLE_BGP_VNC
17997 bgp_rfapi_cfg_write(vty, bgp);
17998 #endif
17999
18000 vty_out(vty, "exit\n");
18001 vty_out(vty, "!\n");
18002 }
18003 return 0;
18004 }
18005
18006
18007 /* BGP node structure. */
18008 static struct cmd_node bgp_node = {
18009 .name = "bgp",
18010 .node = BGP_NODE,
18011 .parent_node = CONFIG_NODE,
18012 .prompt = "%s(config-router)# ",
18013 .config_write = bgp_config_write,
18014 };
18015
18016 static struct cmd_node bgp_ipv4_unicast_node = {
18017 .name = "bgp ipv4 unicast",
18018 .node = BGP_IPV4_NODE,
18019 .parent_node = BGP_NODE,
18020 .prompt = "%s(config-router-af)# ",
18021 .no_xpath = true,
18022 };
18023
18024 static struct cmd_node bgp_ipv4_multicast_node = {
18025 .name = "bgp ipv4 multicast",
18026 .node = BGP_IPV4M_NODE,
18027 .parent_node = BGP_NODE,
18028 .prompt = "%s(config-router-af)# ",
18029 .no_xpath = true,
18030 };
18031
18032 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18033 .name = "bgp ipv4 labeled unicast",
18034 .node = BGP_IPV4L_NODE,
18035 .parent_node = BGP_NODE,
18036 .prompt = "%s(config-router-af)# ",
18037 .no_xpath = true,
18038 };
18039
18040 static struct cmd_node bgp_ipv6_unicast_node = {
18041 .name = "bgp ipv6 unicast",
18042 .node = BGP_IPV6_NODE,
18043 .parent_node = BGP_NODE,
18044 .prompt = "%s(config-router-af)# ",
18045 .no_xpath = true,
18046 };
18047
18048 static struct cmd_node bgp_ipv6_multicast_node = {
18049 .name = "bgp ipv6 multicast",
18050 .node = BGP_IPV6M_NODE,
18051 .parent_node = BGP_NODE,
18052 .prompt = "%s(config-router-af)# ",
18053 .no_xpath = true,
18054 };
18055
18056 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18057 .name = "bgp ipv6 labeled unicast",
18058 .node = BGP_IPV6L_NODE,
18059 .parent_node = BGP_NODE,
18060 .prompt = "%s(config-router-af)# ",
18061 .no_xpath = true,
18062 };
18063
18064 static struct cmd_node bgp_vpnv4_node = {
18065 .name = "bgp vpnv4",
18066 .node = BGP_VPNV4_NODE,
18067 .parent_node = BGP_NODE,
18068 .prompt = "%s(config-router-af)# ",
18069 .no_xpath = true,
18070 };
18071
18072 static struct cmd_node bgp_vpnv6_node = {
18073 .name = "bgp vpnv6",
18074 .node = BGP_VPNV6_NODE,
18075 .parent_node = BGP_NODE,
18076 .prompt = "%s(config-router-af-vpnv6)# ",
18077 .no_xpath = true,
18078 };
18079
18080 static struct cmd_node bgp_evpn_node = {
18081 .name = "bgp evpn",
18082 .node = BGP_EVPN_NODE,
18083 .parent_node = BGP_NODE,
18084 .prompt = "%s(config-router-evpn)# ",
18085 .no_xpath = true,
18086 };
18087
18088 static struct cmd_node bgp_evpn_vni_node = {
18089 .name = "bgp evpn vni",
18090 .node = BGP_EVPN_VNI_NODE,
18091 .parent_node = BGP_EVPN_NODE,
18092 .prompt = "%s(config-router-af-vni)# ",
18093 };
18094
18095 static struct cmd_node bgp_flowspecv4_node = {
18096 .name = "bgp ipv4 flowspec",
18097 .node = BGP_FLOWSPECV4_NODE,
18098 .parent_node = BGP_NODE,
18099 .prompt = "%s(config-router-af)# ",
18100 .no_xpath = true,
18101 };
18102
18103 static struct cmd_node bgp_flowspecv6_node = {
18104 .name = "bgp ipv6 flowspec",
18105 .node = BGP_FLOWSPECV6_NODE,
18106 .parent_node = BGP_NODE,
18107 .prompt = "%s(config-router-af-vpnv6)# ",
18108 .no_xpath = true,
18109 };
18110
18111 static struct cmd_node bgp_srv6_node = {
18112 .name = "bgp srv6",
18113 .node = BGP_SRV6_NODE,
18114 .parent_node = BGP_NODE,
18115 .prompt = "%s(config-router-srv6)# ",
18116 };
18117
18118 static void community_list_vty(void);
18119
18120 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18121 {
18122 struct bgp *bgp;
18123 struct peer_group *group;
18124 struct listnode *lnbgp, *lnpeer;
18125
18126 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18127 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18128 vector_set(comps,
18129 XSTRDUP(MTYPE_COMPLETION, group->name));
18130 }
18131 }
18132
18133 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18134 {
18135 struct bgp *bgp;
18136 struct peer *peer;
18137 struct listnode *lnbgp, *lnpeer;
18138
18139 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18140 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18141 /* only provide suggestions on the appropriate input
18142 * token type,
18143 * they'll otherwise show up multiple times */
18144 enum cmd_token_type match_type;
18145 char *name = peer->host;
18146
18147 if (peer->conf_if) {
18148 match_type = VARIABLE_TKN;
18149 name = peer->conf_if;
18150 } else if (strchr(peer->host, ':'))
18151 match_type = IPV6_TKN;
18152 else
18153 match_type = IPV4_TKN;
18154
18155 if (token->type != match_type)
18156 continue;
18157
18158 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18159 }
18160 }
18161 }
18162
18163 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18164 {
18165 bgp_ac_peer(comps, token);
18166
18167 if (token->type == VARIABLE_TKN)
18168 bgp_ac_peergroup(comps, token);
18169 }
18170
18171 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18172 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18173 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18174 {.varname = "peer", .completions = bgp_ac_neighbor},
18175 {.completions = NULL}};
18176
18177 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18178 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18179 {.completions = NULL} };
18180
18181 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18182
18183 static struct thread *t_bgp_cfg;
18184
18185 bool bgp_config_inprocess(void)
18186 {
18187 return thread_is_scheduled(t_bgp_cfg);
18188 }
18189
18190 static void bgp_config_finish(struct thread *t)
18191 {
18192 struct listnode *node;
18193 struct bgp *bgp;
18194
18195 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18196 hook_call(bgp_config_end, bgp);
18197 }
18198
18199 static void bgp_config_start(void)
18200 {
18201 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18202 THREAD_OFF(t_bgp_cfg);
18203 thread_add_timer(bm->master, bgp_config_finish, NULL,
18204 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18205 }
18206
18207 /* When we receive a hook the configuration is read,
18208 * we start a timer to make sure we postpone sending
18209 * EoR before route-maps are processed.
18210 * This is especially valid if using `bgp route-map delay-timer`.
18211 */
18212 static void bgp_config_end(void)
18213 {
18214 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18215 uint32_t bgp_post_config_delay =
18216 thread_is_scheduled(bm->t_rmap_update)
18217 ? thread_timer_remain_second(bm->t_rmap_update)
18218 : BGP_POST_CONFIG_DELAY_SECONDS;
18219
18220 /* If BGP config processing thread isn't running, then
18221 * we can return and rely it's properly handled.
18222 */
18223 if (!bgp_config_inprocess())
18224 return;
18225
18226 THREAD_OFF(t_bgp_cfg);
18227
18228 /* Start a new timer to make sure we don't send EoR
18229 * before route-maps are processed.
18230 */
18231 thread_add_timer(bm->master, bgp_config_finish, NULL,
18232 bgp_post_config_delay, &t_bgp_cfg);
18233 }
18234
18235 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18236 {
18237 int write = 0;
18238 struct interface *ifp;
18239 struct bgp_interface *iifp;
18240
18241 FOR_ALL_INTERFACES (vrf, ifp) {
18242 iifp = ifp->info;
18243 if (!iifp)
18244 continue;
18245
18246 if_vty_config_start(vty, ifp);
18247
18248 if (CHECK_FLAG(iifp->flags,
18249 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18250 vty_out(vty, " mpls bgp forwarding\n");
18251 write++;
18252 }
18253
18254 if_vty_config_end(vty);
18255 }
18256
18257 return write;
18258 }
18259
18260 /* Configuration write function for bgpd. */
18261 static int config_write_interface(struct vty *vty)
18262 {
18263 int write = 0;
18264 struct vrf *vrf = NULL;
18265
18266 /* Display all VRF aware OSPF interface configuration */
18267 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18268 write += config_write_interface_one(vty, vrf);
18269 }
18270
18271 return write;
18272 }
18273
18274 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18275 "[no$no] mpls bgp forwarding",
18276 NO_STR MPLS_STR BGP_STR
18277 "Enable MPLS forwarding for eBGP directly connected peers\n")
18278 {
18279 bool check;
18280 struct bgp_interface *iifp;
18281
18282 VTY_DECLVAR_CONTEXT(interface, ifp);
18283 iifp = ifp->info;
18284 if (!iifp) {
18285 vty_out(vty, "Interface %s not available\n", ifp->name);
18286 return CMD_WARNING_CONFIG_FAILED;
18287 }
18288 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18289 if (check != !no) {
18290 if (no)
18291 UNSET_FLAG(iifp->flags,
18292 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18293 else
18294 SET_FLAG(iifp->flags,
18295 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18296 /* trigger a nht update on eBGP sessions */
18297 if (if_is_operative(ifp))
18298 bgp_nht_ifp_up(ifp);
18299 }
18300 return CMD_SUCCESS;
18301 }
18302
18303 /* Initialization of BGP interface. */
18304 static void bgp_vty_if_init(void)
18305 {
18306 /* Install interface node. */
18307 if_cmd_init(config_write_interface);
18308
18309 /* "mpls bgp forwarding" commands. */
18310 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18311 }
18312
18313 void bgp_vty_init(void)
18314 {
18315 cmd_variable_handler_register(bgp_var_neighbor);
18316 cmd_variable_handler_register(bgp_var_peergroup);
18317
18318 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18319
18320 /* Install bgp top node. */
18321 install_node(&bgp_node);
18322 install_node(&bgp_ipv4_unicast_node);
18323 install_node(&bgp_ipv4_multicast_node);
18324 install_node(&bgp_ipv4_labeled_unicast_node);
18325 install_node(&bgp_ipv6_unicast_node);
18326 install_node(&bgp_ipv6_multicast_node);
18327 install_node(&bgp_ipv6_labeled_unicast_node);
18328 install_node(&bgp_vpnv4_node);
18329 install_node(&bgp_vpnv6_node);
18330 install_node(&bgp_evpn_node);
18331 install_node(&bgp_evpn_vni_node);
18332 install_node(&bgp_flowspecv4_node);
18333 install_node(&bgp_flowspecv6_node);
18334 install_node(&bgp_srv6_node);
18335
18336 /* Install default VTY commands to new nodes. */
18337 install_default(BGP_NODE);
18338 install_default(BGP_IPV4_NODE);
18339 install_default(BGP_IPV4M_NODE);
18340 install_default(BGP_IPV4L_NODE);
18341 install_default(BGP_IPV6_NODE);
18342 install_default(BGP_IPV6M_NODE);
18343 install_default(BGP_IPV6L_NODE);
18344 install_default(BGP_VPNV4_NODE);
18345 install_default(BGP_VPNV6_NODE);
18346 install_default(BGP_FLOWSPECV4_NODE);
18347 install_default(BGP_FLOWSPECV6_NODE);
18348 install_default(BGP_EVPN_NODE);
18349 install_default(BGP_EVPN_VNI_NODE);
18350 install_default(BGP_SRV6_NODE);
18351
18352 /* "bgp local-mac" hidden commands. */
18353 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18354 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18355
18356 /* "bgp suppress-fib-pending" global */
18357 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18358
18359 /* bgp route-map delay-timer commands. */
18360 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18361 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18362
18363 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18364
18365 /* bgp fast-convergence command */
18366 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18367 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18368
18369 /* global bgp update-delay command */
18370 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18371 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18372
18373 /* global bgp graceful-shutdown command */
18374 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18375 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18376
18377 /* Dummy commands (Currently not supported) */
18378 install_element(BGP_NODE, &no_synchronization_cmd);
18379 install_element(BGP_NODE, &no_auto_summary_cmd);
18380
18381 /* "router bgp" commands. */
18382 install_element(CONFIG_NODE, &router_bgp_cmd);
18383
18384 /* "no router bgp" commands. */
18385 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18386
18387 /* "bgp session-dscp command */
18388 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18389 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18390
18391 /* "bgp router-id" commands. */
18392 install_element(BGP_NODE, &bgp_router_id_cmd);
18393 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18394
18395 /* "bgp suppress-fib-pending" command */
18396 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18397
18398 /* "bgp cluster-id" commands. */
18399 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18400 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18401
18402 /* "bgp no-rib" commands. */
18403 install_element(CONFIG_NODE, &bgp_norib_cmd);
18404 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18405
18406 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18407
18408 /* "bgp confederation" commands. */
18409 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18410 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18411
18412 /* "bgp confederation peers" commands. */
18413 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18414 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18415
18416 /* bgp max-med command */
18417 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18418 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18419 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18420 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18421 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18422
18423 /* "neighbor role" commands. */
18424 install_element(BGP_NODE, &neighbor_role_cmd);
18425 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18426 install_element(BGP_NODE, &no_neighbor_role_cmd);
18427
18428 /* bgp disable-ebgp-connected-nh-check */
18429 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18430 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18431
18432 /* bgp update-delay command */
18433 install_element(BGP_NODE, &bgp_update_delay_cmd);
18434 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18435
18436 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18437 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18438
18439 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18440 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18441
18442 /* "maximum-paths" commands. */
18443 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18444 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18445 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18446 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18447 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18448 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18449 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18450 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18451 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18452 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18453 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18454 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18455 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18456 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18457 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18458
18459 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18460 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18461 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18462 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18463 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18464 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18465 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18466 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18467 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18468 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18469
18470 /* "timers bgp" commands. */
18471 install_element(BGP_NODE, &bgp_timers_cmd);
18472 install_element(BGP_NODE, &no_bgp_timers_cmd);
18473
18474 /* "minimum-holdtime" commands. */
18475 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18476 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18477
18478 /* route-map delay-timer commands - per instance for backwards compat.
18479 */
18480 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18481 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18482
18483 /* "bgp client-to-client reflection" commands */
18484 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18485 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18486
18487 /* "bgp always-compare-med" commands */
18488 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18489 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18490
18491 /* bgp ebgp-requires-policy */
18492 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18493 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18494
18495 /* bgp suppress-duplicates */
18496 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18497 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18498
18499 /* bgp reject-as-sets */
18500 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18501 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18502
18503 /* "bgp deterministic-med" commands */
18504 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18505 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18506
18507 /* "bgp graceful-restart" command */
18508 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18509 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18510
18511 /* "bgp graceful-restart-disable" command */
18512 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18513 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18514
18515 /* "neighbor a:b:c:d graceful-restart" command */
18516 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18517 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18518
18519 /* "neighbor a:b:c:d graceful-restart-disable" command */
18520 install_element(BGP_NODE,
18521 &bgp_neighbor_graceful_restart_disable_set_cmd);
18522 install_element(BGP_NODE,
18523 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18524
18525 /* "neighbor a:b:c:d graceful-restart-helper" command */
18526 install_element(BGP_NODE,
18527 &bgp_neighbor_graceful_restart_helper_set_cmd);
18528 install_element(BGP_NODE,
18529 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18530
18531 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18532 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18533 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18534 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18535 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18536 install_element(BGP_NODE,
18537 &no_bgp_graceful_restart_select_defer_time_cmd);
18538 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18539 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18540 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18541
18542 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18543 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18544 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18545 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18546
18547 /* "bgp graceful-shutdown" commands */
18548 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18549 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18550
18551 /* "bgp hard-administrative-reset" commands */
18552 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18553
18554 /* "bgp long-lived-graceful-restart" commands */
18555 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18556 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18557
18558 /* "bgp fast-external-failover" commands */
18559 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18560 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18561
18562 /* "bgp bestpath compare-routerid" commands */
18563 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18564 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18565
18566 /* "bgp bestpath as-path ignore" commands */
18567 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18568 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18569
18570 /* "bgp bestpath as-path confed" commands */
18571 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18572 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18573
18574 /* "bgp bestpath as-path multipath-relax" commands */
18575 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18576 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18577
18578 /* "bgp bestpath peer-type multipath-relax" commands */
18579 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18580 install_element(BGP_NODE,
18581 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18582
18583 /* "bgp log-neighbor-changes" commands */
18584 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18585 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18586
18587 /* "bgp bestpath med" commands */
18588 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18589 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18590
18591 /* "bgp bestpath bandwidth" commands */
18592 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18593 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18594
18595 /* "no bgp default <afi>-<safi>" commands. */
18596 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18597
18598 /* "bgp network import-check" commands. */
18599 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18600 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18601 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18602
18603 /* "bgp default local-preference" commands. */
18604 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18605 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18606
18607 /* bgp default show-hostname */
18608 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18609 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18610
18611 /* bgp default show-nexthop-hostname */
18612 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18613 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18614
18615 /* "bgp default subgroup-pkt-queue-max" commands. */
18616 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18617 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18618
18619 /* bgp ibgp-allow-policy-mods command */
18620 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18621 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18622
18623 /* "bgp listen limit" commands. */
18624 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18625 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18626
18627 /* "bgp listen range" commands. */
18628 install_element(BGP_NODE, &bgp_listen_range_cmd);
18629 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18630
18631 /* "bgp default shutdown" command */
18632 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18633
18634 /* "bgp shutdown" commands */
18635 install_element(BGP_NODE, &bgp_shutdown_cmd);
18636 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18637 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18638 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18639
18640 /* "neighbor remote-as" commands. */
18641 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18642 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18643 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18644 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18645 install_element(BGP_NODE,
18646 &neighbor_interface_v6only_config_remote_as_cmd);
18647 install_element(BGP_NODE, &no_neighbor_cmd);
18648 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18649
18650 /* "neighbor peer-group" commands. */
18651 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18652 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18653 install_element(BGP_NODE,
18654 &no_neighbor_interface_peer_group_remote_as_cmd);
18655
18656 /* "neighbor local-as" commands. */
18657 install_element(BGP_NODE, &neighbor_local_as_cmd);
18658 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18659 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18660 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18661
18662 /* "neighbor solo" commands. */
18663 install_element(BGP_NODE, &neighbor_solo_cmd);
18664 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18665
18666 /* "neighbor password" commands. */
18667 install_element(BGP_NODE, &neighbor_password_cmd);
18668 install_element(BGP_NODE, &no_neighbor_password_cmd);
18669
18670 /* "neighbor activate" commands. */
18671 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18672 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18673 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18674 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18675 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18676 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18677 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18678 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18679 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18680 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18681 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18682 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18683
18684 /* "no neighbor activate" commands. */
18685 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18686 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18687 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18688 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18689 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18690 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18691 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18692 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18693 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18694 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18695 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18696 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18697
18698 /* "neighbor peer-group" set commands. */
18699 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18700 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18701 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18702 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18703 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18704 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18705 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18706 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18707 install_element(BGP_FLOWSPECV4_NODE,
18708 &neighbor_set_peer_group_hidden_cmd);
18709 install_element(BGP_FLOWSPECV6_NODE,
18710 &neighbor_set_peer_group_hidden_cmd);
18711
18712 /* "no neighbor peer-group unset" commands. */
18713 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18714 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18715 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18716 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18717 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18718 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18719 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18720 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18721 install_element(BGP_FLOWSPECV4_NODE,
18722 &no_neighbor_set_peer_group_hidden_cmd);
18723 install_element(BGP_FLOWSPECV6_NODE,
18724 &no_neighbor_set_peer_group_hidden_cmd);
18725
18726 /* "neighbor softreconfiguration inbound" commands.*/
18727 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18728 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18729 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18730 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18731 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18732 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18733 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18734 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18735 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18736 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18737 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18738 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18739 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18740 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18741 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18742 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18743 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18744 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18745 install_element(BGP_FLOWSPECV4_NODE,
18746 &neighbor_soft_reconfiguration_cmd);
18747 install_element(BGP_FLOWSPECV4_NODE,
18748 &no_neighbor_soft_reconfiguration_cmd);
18749 install_element(BGP_FLOWSPECV6_NODE,
18750 &neighbor_soft_reconfiguration_cmd);
18751 install_element(BGP_FLOWSPECV6_NODE,
18752 &no_neighbor_soft_reconfiguration_cmd);
18753 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18754 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18755
18756 /* "neighbor attribute-unchanged" commands. */
18757 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18758 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18759 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18760 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18761 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18762 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18763 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18764 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18765 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18766 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18767 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18768 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18769 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18770 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18771 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18772 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18773 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18774 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18775
18776 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18777 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18778
18779 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18780 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18781 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18782 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18783
18784 /* "nexthop-local unchanged" commands */
18785 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18786 install_element(BGP_IPV6_NODE,
18787 &no_neighbor_nexthop_local_unchanged_cmd);
18788
18789 /* "neighbor next-hop-self" commands. */
18790 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18791 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18792 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18793 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18794 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18795 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18796 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18797 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18798 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18799 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18800 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18801 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18802 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18803 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18804 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18805 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18806 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18807 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18808 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18809 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18810
18811 /* "neighbor next-hop-self force" commands. */
18812 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18813 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18814 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18815 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18816 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18817 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18818 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18819 install_element(BGP_IPV4_NODE,
18820 &no_neighbor_nexthop_self_all_hidden_cmd);
18821 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18822 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18823 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18824 install_element(BGP_IPV4M_NODE,
18825 &no_neighbor_nexthop_self_all_hidden_cmd);
18826 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18827 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18828 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18829 install_element(BGP_IPV4L_NODE,
18830 &no_neighbor_nexthop_self_all_hidden_cmd);
18831 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18832 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18833 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18834 install_element(BGP_IPV6_NODE,
18835 &no_neighbor_nexthop_self_all_hidden_cmd);
18836 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18837 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18838 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18839 install_element(BGP_IPV6M_NODE,
18840 &no_neighbor_nexthop_self_all_hidden_cmd);
18841 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18842 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18843 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18844 install_element(BGP_IPV6L_NODE,
18845 &no_neighbor_nexthop_self_all_hidden_cmd);
18846 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18847 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18848 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18849 install_element(BGP_VPNV4_NODE,
18850 &no_neighbor_nexthop_self_all_hidden_cmd);
18851 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18852 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18853 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18854 install_element(BGP_VPNV6_NODE,
18855 &no_neighbor_nexthop_self_all_hidden_cmd);
18856 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18857 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18858
18859 /* "neighbor as-override" commands. */
18860 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18861 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18862 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18863 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18864 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18865 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18866 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18867 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18868 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18869 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18870 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18871 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18872 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18873 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18874 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18875 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18876 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18877 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18878
18879 /* "neighbor remove-private-AS" commands. */
18880 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18881 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18882 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18883 install_element(BGP_NODE,
18884 &no_neighbor_remove_private_as_all_hidden_cmd);
18885 install_element(BGP_NODE,
18886 &neighbor_remove_private_as_replace_as_hidden_cmd);
18887 install_element(BGP_NODE,
18888 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18889 install_element(BGP_NODE,
18890 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18891 install_element(
18892 BGP_NODE,
18893 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18894 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18895 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18896 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18897 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18898 install_element(BGP_IPV4_NODE,
18899 &neighbor_remove_private_as_replace_as_cmd);
18900 install_element(BGP_IPV4_NODE,
18901 &no_neighbor_remove_private_as_replace_as_cmd);
18902 install_element(BGP_IPV4_NODE,
18903 &neighbor_remove_private_as_all_replace_as_cmd);
18904 install_element(BGP_IPV4_NODE,
18905 &no_neighbor_remove_private_as_all_replace_as_cmd);
18906 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18907 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18908 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18909 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18910 install_element(BGP_IPV4M_NODE,
18911 &neighbor_remove_private_as_replace_as_cmd);
18912 install_element(BGP_IPV4M_NODE,
18913 &no_neighbor_remove_private_as_replace_as_cmd);
18914 install_element(BGP_IPV4M_NODE,
18915 &neighbor_remove_private_as_all_replace_as_cmd);
18916 install_element(BGP_IPV4M_NODE,
18917 &no_neighbor_remove_private_as_all_replace_as_cmd);
18918 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18919 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18920 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18921 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18922 install_element(BGP_IPV4L_NODE,
18923 &neighbor_remove_private_as_replace_as_cmd);
18924 install_element(BGP_IPV4L_NODE,
18925 &no_neighbor_remove_private_as_replace_as_cmd);
18926 install_element(BGP_IPV4L_NODE,
18927 &neighbor_remove_private_as_all_replace_as_cmd);
18928 install_element(BGP_IPV4L_NODE,
18929 &no_neighbor_remove_private_as_all_replace_as_cmd);
18930 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18931 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18932 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18933 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18934 install_element(BGP_IPV6_NODE,
18935 &neighbor_remove_private_as_replace_as_cmd);
18936 install_element(BGP_IPV6_NODE,
18937 &no_neighbor_remove_private_as_replace_as_cmd);
18938 install_element(BGP_IPV6_NODE,
18939 &neighbor_remove_private_as_all_replace_as_cmd);
18940 install_element(BGP_IPV6_NODE,
18941 &no_neighbor_remove_private_as_all_replace_as_cmd);
18942 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18943 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18944 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18945 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18946 install_element(BGP_IPV6M_NODE,
18947 &neighbor_remove_private_as_replace_as_cmd);
18948 install_element(BGP_IPV6M_NODE,
18949 &no_neighbor_remove_private_as_replace_as_cmd);
18950 install_element(BGP_IPV6M_NODE,
18951 &neighbor_remove_private_as_all_replace_as_cmd);
18952 install_element(BGP_IPV6M_NODE,
18953 &no_neighbor_remove_private_as_all_replace_as_cmd);
18954 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18955 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18956 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18957 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18958 install_element(BGP_IPV6L_NODE,
18959 &neighbor_remove_private_as_replace_as_cmd);
18960 install_element(BGP_IPV6L_NODE,
18961 &no_neighbor_remove_private_as_replace_as_cmd);
18962 install_element(BGP_IPV6L_NODE,
18963 &neighbor_remove_private_as_all_replace_as_cmd);
18964 install_element(BGP_IPV6L_NODE,
18965 &no_neighbor_remove_private_as_all_replace_as_cmd);
18966 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18967 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18968 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18969 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18970 install_element(BGP_VPNV4_NODE,
18971 &neighbor_remove_private_as_replace_as_cmd);
18972 install_element(BGP_VPNV4_NODE,
18973 &no_neighbor_remove_private_as_replace_as_cmd);
18974 install_element(BGP_VPNV4_NODE,
18975 &neighbor_remove_private_as_all_replace_as_cmd);
18976 install_element(BGP_VPNV4_NODE,
18977 &no_neighbor_remove_private_as_all_replace_as_cmd);
18978 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18979 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18980 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18981 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18982 install_element(BGP_VPNV6_NODE,
18983 &neighbor_remove_private_as_replace_as_cmd);
18984 install_element(BGP_VPNV6_NODE,
18985 &no_neighbor_remove_private_as_replace_as_cmd);
18986 install_element(BGP_VPNV6_NODE,
18987 &neighbor_remove_private_as_all_replace_as_cmd);
18988 install_element(BGP_VPNV6_NODE,
18989 &no_neighbor_remove_private_as_all_replace_as_cmd);
18990
18991 /* "neighbor send-community" commands.*/
18992 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18993 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18994 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18995 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18996 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18997 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18998 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18999 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19000 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19001 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19002 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19003 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19004 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19005 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19006 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19007 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19008 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19009 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19010 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19011 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19012 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19013 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19014 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19015 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19016 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19017 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19018 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19019 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19020 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19021 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19022 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19023 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19024 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19025 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19026 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19027 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19028
19029 /* "neighbor route-reflector" commands.*/
19030 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19031 install_element(BGP_NODE,
19032 &no_neighbor_route_reflector_client_hidden_cmd);
19033 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19034 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19035 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19036 install_element(BGP_IPV4M_NODE,
19037 &no_neighbor_route_reflector_client_cmd);
19038 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19039 install_element(BGP_IPV4L_NODE,
19040 &no_neighbor_route_reflector_client_cmd);
19041 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19042 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19043 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19044 install_element(BGP_IPV6M_NODE,
19045 &no_neighbor_route_reflector_client_cmd);
19046 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19047 install_element(BGP_IPV6L_NODE,
19048 &no_neighbor_route_reflector_client_cmd);
19049 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19050 install_element(BGP_VPNV4_NODE,
19051 &no_neighbor_route_reflector_client_cmd);
19052 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19053 install_element(BGP_VPNV6_NODE,
19054 &no_neighbor_route_reflector_client_cmd);
19055 install_element(BGP_FLOWSPECV4_NODE,
19056 &neighbor_route_reflector_client_cmd);
19057 install_element(BGP_FLOWSPECV4_NODE,
19058 &no_neighbor_route_reflector_client_cmd);
19059 install_element(BGP_FLOWSPECV6_NODE,
19060 &neighbor_route_reflector_client_cmd);
19061 install_element(BGP_FLOWSPECV6_NODE,
19062 &no_neighbor_route_reflector_client_cmd);
19063 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19064 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19065
19066 /* "optimal-route-reflection" commands */
19067 install_element(BGP_IPV4_NODE, &optimal_route_reflection_cmd);
19068 install_element(BGP_IPV4M_NODE, &optimal_route_reflection_cmd);
19069 install_element(BGP_IPV4L_NODE, &optimal_route_reflection_cmd);
19070 install_element(BGP_IPV6_NODE, &optimal_route_reflection_cmd);
19071 install_element(BGP_IPV6M_NODE, &optimal_route_reflection_cmd);
19072 install_element(BGP_IPV6L_NODE, &optimal_route_reflection_cmd);
19073 install_element(BGP_VPNV4_NODE, &optimal_route_reflection_cmd);
19074 install_element(BGP_VPNV6_NODE, &optimal_route_reflection_cmd);
19075 install_element(BGP_FLOWSPECV4_NODE, &optimal_route_reflection_cmd);
19076 install_element(BGP_FLOWSPECV6_NODE, &optimal_route_reflection_cmd);
19077 install_element(BGP_EVPN_NODE, &optimal_route_reflection_cmd);
19078
19079 /* "neighbor optimal-route-reflection" commands */
19080 install_element(BGP_IPV4_NODE, &neighbor_optimal_route_reflection_cmd);
19081 install_element(BGP_IPV4M_NODE, &neighbor_optimal_route_reflection_cmd);
19082 install_element(BGP_IPV4L_NODE, &neighbor_optimal_route_reflection_cmd);
19083 install_element(BGP_IPV6_NODE, &neighbor_optimal_route_reflection_cmd);
19084 install_element(BGP_IPV6M_NODE, &neighbor_optimal_route_reflection_cmd);
19085 install_element(BGP_IPV6L_NODE, &neighbor_optimal_route_reflection_cmd);
19086 install_element(BGP_VPNV4_NODE, &neighbor_optimal_route_reflection_cmd);
19087 install_element(BGP_VPNV6_NODE, &neighbor_optimal_route_reflection_cmd);
19088 install_element(BGP_FLOWSPECV4_NODE,
19089 &neighbor_optimal_route_reflection_cmd);
19090 install_element(BGP_FLOWSPECV6_NODE,
19091 &neighbor_optimal_route_reflection_cmd);
19092 install_element(BGP_EVPN_NODE, &neighbor_optimal_route_reflection_cmd);
19093
19094 /* "neighbor route-server" commands.*/
19095 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19096 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19097 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19098 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19099 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19100 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19101 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19102 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19103 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19104 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19105 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19106 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19107 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19108 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19109 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19110 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19111 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19112 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19113 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19114 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19115 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19116 install_element(BGP_FLOWSPECV4_NODE,
19117 &no_neighbor_route_server_client_cmd);
19118 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19119 install_element(BGP_FLOWSPECV6_NODE,
19120 &no_neighbor_route_server_client_cmd);
19121
19122 /* "neighbor disable-addpath-rx" commands. */
19123 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19124 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19125 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19126 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19127 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19128 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19129 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19130 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19131 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19132 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19133 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19134 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19135 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19136 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19137 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19138 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19139
19140 /* "neighbor addpath-tx-all-paths" commands.*/
19141 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19142 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19143 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19144 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19145 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19146 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19147 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19148 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19149 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19150 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19151 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19152 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19153 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19154 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19155 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19156 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19157 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19158 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19159
19160 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19161 install_element(BGP_NODE,
19162 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19163 install_element(BGP_NODE,
19164 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19165 install_element(BGP_IPV4_NODE,
19166 &neighbor_addpath_tx_bestpath_per_as_cmd);
19167 install_element(BGP_IPV4_NODE,
19168 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19169 install_element(BGP_IPV4M_NODE,
19170 &neighbor_addpath_tx_bestpath_per_as_cmd);
19171 install_element(BGP_IPV4M_NODE,
19172 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19173 install_element(BGP_IPV4L_NODE,
19174 &neighbor_addpath_tx_bestpath_per_as_cmd);
19175 install_element(BGP_IPV4L_NODE,
19176 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19177 install_element(BGP_IPV6_NODE,
19178 &neighbor_addpath_tx_bestpath_per_as_cmd);
19179 install_element(BGP_IPV6_NODE,
19180 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19181 install_element(BGP_IPV6M_NODE,
19182 &neighbor_addpath_tx_bestpath_per_as_cmd);
19183 install_element(BGP_IPV6M_NODE,
19184 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19185 install_element(BGP_IPV6L_NODE,
19186 &neighbor_addpath_tx_bestpath_per_as_cmd);
19187 install_element(BGP_IPV6L_NODE,
19188 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19189 install_element(BGP_VPNV4_NODE,
19190 &neighbor_addpath_tx_bestpath_per_as_cmd);
19191 install_element(BGP_VPNV4_NODE,
19192 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19193 install_element(BGP_VPNV6_NODE,
19194 &neighbor_addpath_tx_bestpath_per_as_cmd);
19195 install_element(BGP_VPNV6_NODE,
19196 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19197
19198 /* "neighbor sender-as-path-loop-detection" commands. */
19199 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19200 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19201
19202 /* "neighbor passive" commands. */
19203 install_element(BGP_NODE, &neighbor_passive_cmd);
19204 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19205
19206
19207 /* "neighbor shutdown" commands. */
19208 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19209 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19210 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19211 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19212 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19213 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19214
19215 /* "neighbor capability extended-nexthop" commands.*/
19216 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19217 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19218
19219 /* "neighbor capability orf prefix-list" commands.*/
19220 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19221 install_element(BGP_NODE,
19222 &no_neighbor_capability_orf_prefix_hidden_cmd);
19223 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19224 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19225 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19226 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19227 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19228 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19229 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19230 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19231 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19232 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19233 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19234 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19235
19236 /* "neighbor capability dynamic" commands.*/
19237 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19238 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19239
19240 /* "neighbor dont-capability-negotiate" commands. */
19241 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19242 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19243
19244 /* "neighbor ebgp-multihop" commands. */
19245 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19246 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19247 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19248
19249 /* "neighbor disable-connected-check" commands. */
19250 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19251 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19252
19253 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19254 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19255 install_element(BGP_NODE,
19256 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19257
19258 /* "neighbor extended-optional-parameters" commands. */
19259 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19260 install_element(BGP_NODE,
19261 &no_neighbor_extended_optional_parameters_cmd);
19262
19263 /* "neighbor enforce-first-as" commands. */
19264 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19265 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19266
19267 /* "neighbor description" commands. */
19268 install_element(BGP_NODE, &neighbor_description_cmd);
19269 install_element(BGP_NODE, &no_neighbor_description_cmd);
19270 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19271
19272 /* "neighbor update-source" commands. "*/
19273 install_element(BGP_NODE, &neighbor_update_source_cmd);
19274 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19275
19276 /* "neighbor default-originate" commands. */
19277 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19278 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19279 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19280 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19281 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19282 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19283 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19284 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19285 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19286 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19287 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19288 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19289 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19290 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19291 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19292 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19293 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19294 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19295 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19296 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19297 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19298
19299 /* "neighbor port" commands. */
19300 install_element(BGP_NODE, &neighbor_port_cmd);
19301 install_element(BGP_NODE, &no_neighbor_port_cmd);
19302
19303 /* "neighbor weight" commands. */
19304 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19305 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19306
19307 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19308 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19309 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19310 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19311 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19312 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19313 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19314 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19315 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19316 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19317 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19318 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19319 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19320 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19321 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19322 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19323
19324 /* "neighbor override-capability" commands. */
19325 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19326 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19327
19328 /* "neighbor strict-capability-match" commands. */
19329 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19330 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19331
19332 /* "neighbor timers" commands. */
19333 install_element(BGP_NODE, &neighbor_timers_cmd);
19334 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19335
19336 /* "neighbor timers connect" commands. */
19337 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19338 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19339
19340 /* "neighbor timers delayopen" commands. */
19341 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19342 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19343
19344 /* "neighbor advertisement-interval" commands. */
19345 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19346 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19347
19348 /* "neighbor interface" commands. */
19349 install_element(BGP_NODE, &neighbor_interface_cmd);
19350 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19351
19352 /* "neighbor distribute" commands. */
19353 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19354 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19355 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19356 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19357 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19358 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19359 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19360 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19361 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19362 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19363 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19364 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19365 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19366 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19367 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19368 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19369 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19370 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19371
19372 /* "neighbor prefix-list" commands. */
19373 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19374 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19375 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19376 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19377 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19378 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19379 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19380 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19381 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19382 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19383 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19384 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19385 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19386 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19387 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19388 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19389 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19390 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19391 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19392 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19393 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19394 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19395
19396 /* "neighbor filter-list" commands. */
19397 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19398 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19399 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19400 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19401 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19402 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19403 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19404 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19405 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19406 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19407 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19408 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19409 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19410 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19411 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19412 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19413 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19414 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19415 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19416 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19417 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19418 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19419
19420 /* "neighbor route-map" commands. */
19421 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19422 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19423 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19424 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19425 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19426 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19427 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19428 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19429 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19430 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19431 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19432 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19433 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19434 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19435 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19436 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19437 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19438 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19439 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19440 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19441 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19442 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19443 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19444 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19445
19446 /* "neighbor unsuppress-map" commands. */
19447 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19448 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19449 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19450 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19451 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19452 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19453 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19454 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19455 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19456 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19457 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19458 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19459 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19460 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19461 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19462 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19463 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19464 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19465
19466 /* "neighbor advertise-map" commands. */
19467 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19468 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19469 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19470 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19471 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19472 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19473 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19474 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19475 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19476 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19477
19478 /* neighbor maximum-prefix-out commands. */
19479 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19480 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19481 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19482 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19483 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19484 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19485 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19486 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19487 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19488 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19489 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19490 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19491 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19492 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19493 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19494 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19495 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19496 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19497
19498 /* "neighbor maximum-prefix" commands. */
19499 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19500 install_element(BGP_NODE,
19501 &neighbor_maximum_prefix_threshold_hidden_cmd);
19502 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19503 install_element(BGP_NODE,
19504 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19505 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19506 install_element(BGP_NODE,
19507 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19508 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19509 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19510 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19511 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19512 install_element(BGP_IPV4_NODE,
19513 &neighbor_maximum_prefix_threshold_warning_cmd);
19514 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19515 install_element(BGP_IPV4_NODE,
19516 &neighbor_maximum_prefix_threshold_restart_cmd);
19517 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19518 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19519 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19520 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19521 install_element(BGP_IPV4M_NODE,
19522 &neighbor_maximum_prefix_threshold_warning_cmd);
19523 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19524 install_element(BGP_IPV4M_NODE,
19525 &neighbor_maximum_prefix_threshold_restart_cmd);
19526 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19527 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19528 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19529 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19530 install_element(BGP_IPV4L_NODE,
19531 &neighbor_maximum_prefix_threshold_warning_cmd);
19532 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19533 install_element(BGP_IPV4L_NODE,
19534 &neighbor_maximum_prefix_threshold_restart_cmd);
19535 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19536 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19537 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19538 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19539 install_element(BGP_IPV6_NODE,
19540 &neighbor_maximum_prefix_threshold_warning_cmd);
19541 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19542 install_element(BGP_IPV6_NODE,
19543 &neighbor_maximum_prefix_threshold_restart_cmd);
19544 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19545 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19546 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19547 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19548 install_element(BGP_IPV6M_NODE,
19549 &neighbor_maximum_prefix_threshold_warning_cmd);
19550 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19551 install_element(BGP_IPV6M_NODE,
19552 &neighbor_maximum_prefix_threshold_restart_cmd);
19553 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19554 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19555 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19556 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19557 install_element(BGP_IPV6L_NODE,
19558 &neighbor_maximum_prefix_threshold_warning_cmd);
19559 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19560 install_element(BGP_IPV6L_NODE,
19561 &neighbor_maximum_prefix_threshold_restart_cmd);
19562 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19563 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19564 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19565 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19566 install_element(BGP_VPNV4_NODE,
19567 &neighbor_maximum_prefix_threshold_warning_cmd);
19568 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19569 install_element(BGP_VPNV4_NODE,
19570 &neighbor_maximum_prefix_threshold_restart_cmd);
19571 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19572 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19573 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19574 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19575 install_element(BGP_VPNV6_NODE,
19576 &neighbor_maximum_prefix_threshold_warning_cmd);
19577 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19578 install_element(BGP_VPNV6_NODE,
19579 &neighbor_maximum_prefix_threshold_restart_cmd);
19580 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19581
19582 /* "neighbor allowas-in" */
19583 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19584 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19585 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19586 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19587 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19588 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19589 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19590 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19591 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19592 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19593 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19594 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19595 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19596 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19597 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19598 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19599 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19600 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19601 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19602 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19603
19604 /* neighbor accept-own */
19605 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19606 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19607
19608 /* "neighbor soo" */
19609 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19610 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19611 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19612 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19613 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19614 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19615 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19616 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19617 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19618 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19619 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19620 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19621 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19622 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19623 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19624 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19625 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19626 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19627
19628 /* address-family commands. */
19629 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19630 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19631 #ifdef KEEP_OLD_VPN_COMMANDS
19632 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19633 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19634 #endif /* KEEP_OLD_VPN_COMMANDS */
19635
19636 install_element(BGP_NODE, &address_family_evpn_cmd);
19637
19638 /* "exit-address-family" command. */
19639 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19640 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19641 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19642 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19643 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19644 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19645 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19646 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19647 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19648 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19649 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19650
19651 /* BGP retain all route-target */
19652 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19653 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19654
19655 /* "clear ip bgp commands" */
19656 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19657
19658 /* clear ip bgp prefix */
19659 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19660 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19661 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19662
19663 /* "show [ip] bgp summary" commands. */
19664 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19665 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19666 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19667 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19668 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19669 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19670 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19671
19672 /* "show [ip] bgp neighbors" commands. */
19673 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19674
19675 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19676
19677 /* "show [ip] bgp peer-group" commands. */
19678 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19679
19680 /* "show [ip] bgp paths" commands. */
19681 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19682
19683 /* "show [ip] bgp community" commands. */
19684 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19685
19686 /* "show ip bgp large-community" commands. */
19687 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19688 /* "show [ip] bgp attribute-info" commands. */
19689 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19690 /* "show [ip] bgp route-leak" command */
19691 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19692
19693 /* "redistribute" commands. */
19694 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19695 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19696 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19697 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19698 install_element(BGP_NODE,
19699 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19700 install_element(BGP_NODE,
19701 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19702 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19703 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19704 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19705 install_element(BGP_NODE,
19706 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19707 install_element(BGP_NODE,
19708 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19709 install_element(BGP_NODE,
19710 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19711 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19712 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19713 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19714 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19715 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19716 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19717 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19718 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19719 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19720 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19721 install_element(BGP_IPV4_NODE,
19722 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19723 install_element(BGP_IPV4_NODE,
19724 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19725 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19726 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19727 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19728 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19729 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19730 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19731
19732 /* import|export vpn [route-map RMAP_NAME] */
19733 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19734 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19735
19736 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19737 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19738
19739 /* ttl_security commands */
19740 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19741 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19742
19743 /* "bgp tcp-keepalive" commands */
19744 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
19745 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
19746
19747 /* "show [ip] bgp memory" commands. */
19748 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19749
19750 /* "show bgp martian next-hop" */
19751 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19752
19753 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19754
19755 /* "show [ip] bgp views" commands. */
19756 install_element(VIEW_NODE, &show_bgp_views_cmd);
19757
19758 /* "show [ip] bgp vrfs" commands. */
19759 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19760
19761 /* Community-list. */
19762 community_list_vty();
19763
19764 community_alias_vty();
19765
19766 /* vpn-policy commands */
19767 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19768 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19769 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19770 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19771 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19772 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19773 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19774 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19775 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19776 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19777 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19778 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19779
19780 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19781 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19782
19783 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19784 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19785 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19786 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19787 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19788 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19789 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19790 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19791 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19792 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19793
19794 /* tcp-mss command */
19795 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19796 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19797
19798 /* srv6 commands */
19799 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19800 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19801 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19802 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19803 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19804 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19805 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19806
19807 bgp_vty_if_init();
19808 }
19809
19810 #include "memory.h"
19811 #include "bgp_regex.h"
19812 #include "bgp_clist.h"
19813 #include "bgp_ecommunity.h"
19814
19815 /* VTY functions. */
19816
19817 /* Direction value to string conversion. */
19818 static const char *community_direct_str(int direct)
19819 {
19820 switch (direct) {
19821 case COMMUNITY_DENY:
19822 return "deny";
19823 case COMMUNITY_PERMIT:
19824 return "permit";
19825 default:
19826 return "unknown";
19827 }
19828 }
19829
19830 /* Display error string. */
19831 static void community_list_perror(struct vty *vty, int ret)
19832 {
19833 switch (ret) {
19834 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19835 vty_out(vty, "%% Can't find community-list\n");
19836 break;
19837 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19838 vty_out(vty, "%% Malformed community-list value\n");
19839 break;
19840 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19841 vty_out(vty,
19842 "%% Community name conflict, previously defined as standard community\n");
19843 break;
19844 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19845 vty_out(vty,
19846 "%% Community name conflict, previously defined as expanded community\n");
19847 break;
19848 }
19849 }
19850
19851 /* "community-list" keyword help string. */
19852 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19853
19854 /*community-list standard */
19855 DEFUN (community_list_standard,
19856 bgp_community_list_standard_cmd,
19857 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19858 BGP_STR
19859 COMMUNITY_LIST_STR
19860 "Community list number (standard)\n"
19861 "Add an standard community-list entry\n"
19862 "Community list name\n"
19863 "Sequence number of an entry\n"
19864 "Sequence number\n"
19865 "Specify community to reject\n"
19866 "Specify community to accept\n"
19867 COMMUNITY_VAL_STR)
19868 {
19869 char *cl_name_or_number = NULL;
19870 char *seq = NULL;
19871 int direct = 0;
19872 int style = COMMUNITY_LIST_STANDARD;
19873 int idx = 0;
19874
19875 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19876 seq = argv[idx]->arg;
19877
19878 idx = 0;
19879 argv_find(argv, argc, "(1-99)", &idx);
19880 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19881 cl_name_or_number = argv[idx]->arg;
19882 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19883 : COMMUNITY_DENY;
19884 argv_find(argv, argc, "AA:NN", &idx);
19885 char *str = argv_concat(argv, argc, idx);
19886
19887 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19888 direct, style);
19889
19890 XFREE(MTYPE_TMP, str);
19891
19892 if (ret < 0) {
19893 /* Display error string. */
19894 community_list_perror(vty, ret);
19895 return CMD_WARNING_CONFIG_FAILED;
19896 }
19897
19898 return CMD_SUCCESS;
19899 }
19900
19901 DEFUN (no_community_list_standard_all,
19902 no_bgp_community_list_standard_all_cmd,
19903 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19904 NO_STR
19905 BGP_STR
19906 COMMUNITY_LIST_STR
19907 "Community list number (standard)\n"
19908 "Add an standard community-list entry\n"
19909 "Community list name\n"
19910 "Sequence number of an entry\n"
19911 "Sequence number\n"
19912 "Specify community to reject\n"
19913 "Specify community to accept\n"
19914 COMMUNITY_VAL_STR)
19915 {
19916 char *cl_name_or_number = NULL;
19917 char *str = NULL;
19918 int direct = 0;
19919 int style = COMMUNITY_LIST_STANDARD;
19920 char *seq = NULL;
19921 int idx = 0;
19922
19923 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19924 seq = argv[idx]->arg;
19925
19926 idx = 0;
19927 argv_find(argv, argc, "permit", &idx);
19928 argv_find(argv, argc, "deny", &idx);
19929
19930 if (idx) {
19931 direct = argv_find(argv, argc, "permit", &idx)
19932 ? COMMUNITY_PERMIT
19933 : COMMUNITY_DENY;
19934
19935 idx = 0;
19936 argv_find(argv, argc, "AA:NN", &idx);
19937 str = argv_concat(argv, argc, idx);
19938 }
19939
19940 idx = 0;
19941 argv_find(argv, argc, "(1-99)", &idx);
19942 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19943 cl_name_or_number = argv[idx]->arg;
19944
19945 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19946 direct, style);
19947
19948 XFREE(MTYPE_TMP, str);
19949
19950 if (ret < 0) {
19951 community_list_perror(vty, ret);
19952 return CMD_WARNING_CONFIG_FAILED;
19953 }
19954
19955 return CMD_SUCCESS;
19956 }
19957
19958 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19959 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19960 NO_STR BGP_STR COMMUNITY_LIST_STR
19961 "Community list number (standard)\n"
19962 "Add an standard community-list entry\n"
19963 "Community list name\n")
19964
19965 /*community-list expanded */
19966 DEFUN (community_list_expanded_all,
19967 bgp_community_list_expanded_all_cmd,
19968 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19969 BGP_STR
19970 COMMUNITY_LIST_STR
19971 "Community list number (expanded)\n"
19972 "Add an expanded community-list entry\n"
19973 "Community list name\n"
19974 "Sequence number of an entry\n"
19975 "Sequence number\n"
19976 "Specify community to reject\n"
19977 "Specify community to accept\n"
19978 COMMUNITY_VAL_STR)
19979 {
19980 char *cl_name_or_number = NULL;
19981 char *seq = NULL;
19982 int direct = 0;
19983 int style = COMMUNITY_LIST_EXPANDED;
19984 int idx = 0;
19985
19986 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19987 seq = argv[idx]->arg;
19988
19989 idx = 0;
19990
19991 argv_find(argv, argc, "(100-500)", &idx);
19992 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19993 cl_name_or_number = argv[idx]->arg;
19994 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19995 : COMMUNITY_DENY;
19996 argv_find(argv, argc, "AA:NN", &idx);
19997 char *str = argv_concat(argv, argc, idx);
19998
19999 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20000 direct, style);
20001
20002 XFREE(MTYPE_TMP, str);
20003
20004 if (ret < 0) {
20005 /* Display error string. */
20006 community_list_perror(vty, ret);
20007 return CMD_WARNING_CONFIG_FAILED;
20008 }
20009
20010 return CMD_SUCCESS;
20011 }
20012
20013 DEFUN (no_community_list_expanded_all,
20014 no_bgp_community_list_expanded_all_cmd,
20015 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20016 NO_STR
20017 BGP_STR
20018 COMMUNITY_LIST_STR
20019 "Community list number (expanded)\n"
20020 "Add an expanded community-list entry\n"
20021 "Community list name\n"
20022 "Sequence number of an entry\n"
20023 "Sequence number\n"
20024 "Specify community to reject\n"
20025 "Specify community to accept\n"
20026 COMMUNITY_VAL_STR)
20027 {
20028 char *cl_name_or_number = NULL;
20029 char *seq = NULL;
20030 char *str = NULL;
20031 int direct = 0;
20032 int style = COMMUNITY_LIST_EXPANDED;
20033 int idx = 0;
20034
20035 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20036 seq = argv[idx]->arg;
20037
20038 idx = 0;
20039 argv_find(argv, argc, "permit", &idx);
20040 argv_find(argv, argc, "deny", &idx);
20041
20042 if (idx) {
20043 direct = argv_find(argv, argc, "permit", &idx)
20044 ? COMMUNITY_PERMIT
20045 : COMMUNITY_DENY;
20046
20047 idx = 0;
20048 argv_find(argv, argc, "AA:NN", &idx);
20049 str = argv_concat(argv, argc, idx);
20050 }
20051
20052 idx = 0;
20053 argv_find(argv, argc, "(100-500)", &idx);
20054 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20055 cl_name_or_number = argv[idx]->arg;
20056
20057 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20058 direct, style);
20059
20060 XFREE(MTYPE_TMP, str);
20061
20062 if (ret < 0) {
20063 community_list_perror(vty, ret);
20064 return CMD_WARNING_CONFIG_FAILED;
20065 }
20066
20067 return CMD_SUCCESS;
20068 }
20069
20070 ALIAS(no_community_list_expanded_all,
20071 no_bgp_community_list_expanded_all_list_cmd,
20072 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20073 NO_STR BGP_STR COMMUNITY_LIST_STR
20074 "Community list number (expanded)\n"
20075 "Add an expanded community-list entry\n"
20076 "Community list name\n")
20077
20078 /* Return configuration string of community-list entry. */
20079 static const char *community_list_config_str(struct community_entry *entry)
20080 {
20081 const char *str;
20082
20083 if (entry->any)
20084 str = "";
20085 else {
20086 if (entry->style == COMMUNITY_LIST_STANDARD)
20087 str = community_str(entry->u.com, false, false);
20088 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20089 str = lcommunity_str(entry->u.lcom, false, false);
20090 else
20091 str = entry->config;
20092 }
20093 return str;
20094 }
20095
20096 static void community_list_show(struct vty *vty, struct community_list *list)
20097 {
20098 struct community_entry *entry;
20099
20100 for (entry = list->head; entry; entry = entry->next) {
20101 if (entry == list->head) {
20102 if (all_digit(list->name))
20103 vty_out(vty, "Community %s list %s\n",
20104 entry->style == COMMUNITY_LIST_STANDARD
20105 ? "standard"
20106 : "(expanded) access",
20107 list->name);
20108 else
20109 vty_out(vty, "Named Community %s list %s\n",
20110 entry->style == COMMUNITY_LIST_STANDARD
20111 ? "standard"
20112 : "expanded",
20113 list->name);
20114 }
20115 if (entry->any)
20116 vty_out(vty, " %s\n",
20117 community_direct_str(entry->direct));
20118 else
20119 vty_out(vty, " %s %s\n",
20120 community_direct_str(entry->direct),
20121 community_list_config_str(entry));
20122 }
20123 }
20124
20125 DEFUN (show_community_list,
20126 show_bgp_community_list_cmd,
20127 "show bgp community-list",
20128 SHOW_STR
20129 BGP_STR
20130 "List community-list\n")
20131 {
20132 struct community_list *list;
20133 struct community_list_master *cm;
20134
20135 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20136 if (!cm)
20137 return CMD_SUCCESS;
20138
20139 for (list = cm->num.head; list; list = list->next)
20140 community_list_show(vty, list);
20141
20142 for (list = cm->str.head; list; list = list->next)
20143 community_list_show(vty, list);
20144
20145 return CMD_SUCCESS;
20146 }
20147
20148 DEFUN (show_community_list_arg,
20149 show_bgp_community_list_arg_cmd,
20150 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20151 SHOW_STR
20152 BGP_STR
20153 "List community-list\n"
20154 "Community-list number\n"
20155 "Community-list name\n"
20156 "Detailed information on community-list\n")
20157 {
20158 int idx_comm_list = 3;
20159 struct community_list *list;
20160
20161 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20162 COMMUNITY_LIST_MASTER);
20163 if (!list) {
20164 vty_out(vty, "%% Can't find community-list\n");
20165 return CMD_WARNING;
20166 }
20167
20168 community_list_show(vty, list);
20169
20170 return CMD_SUCCESS;
20171 }
20172
20173 /*
20174 * Large Community code.
20175 */
20176 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20177 struct cmd_token **argv, int style,
20178 int reject_all_digit_name)
20179 {
20180 int ret;
20181 int direct;
20182 char *str;
20183 int idx = 0;
20184 char *cl_name;
20185 char *seq = NULL;
20186
20187 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20188 seq = argv[idx]->arg;
20189
20190 idx = 0;
20191 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20192 : COMMUNITY_DENY;
20193
20194 /* All digit name check. */
20195 idx = 0;
20196 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20197 argv_find(argv, argc, "(1-99)", &idx);
20198 argv_find(argv, argc, "(100-500)", &idx);
20199 cl_name = argv[idx]->arg;
20200 if (reject_all_digit_name && all_digit(cl_name)) {
20201 vty_out(vty, "%% Community name cannot have all digits\n");
20202 return CMD_WARNING_CONFIG_FAILED;
20203 }
20204
20205 idx = 0;
20206 argv_find(argv, argc, "AA:BB:CC", &idx);
20207 argv_find(argv, argc, "LINE", &idx);
20208 /* Concat community string argument. */
20209 if (idx)
20210 str = argv_concat(argv, argc, idx);
20211 else
20212 str = NULL;
20213
20214 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20215
20216 /* Free temporary community list string allocated by
20217 argv_concat(). */
20218 XFREE(MTYPE_TMP, str);
20219
20220 if (ret < 0) {
20221 community_list_perror(vty, ret);
20222 return CMD_WARNING_CONFIG_FAILED;
20223 }
20224 return CMD_SUCCESS;
20225 }
20226
20227 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20228 struct cmd_token **argv, int style)
20229 {
20230 int ret;
20231 int direct = 0;
20232 char *str = NULL;
20233 int idx = 0;
20234 char *seq = NULL;
20235
20236 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20237 seq = argv[idx]->arg;
20238
20239 idx = 0;
20240 argv_find(argv, argc, "permit", &idx);
20241 argv_find(argv, argc, "deny", &idx);
20242
20243 if (idx) {
20244 /* Check the list direct. */
20245 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20246 direct = COMMUNITY_PERMIT;
20247 else
20248 direct = COMMUNITY_DENY;
20249
20250 idx = 0;
20251 argv_find(argv, argc, "LINE", &idx);
20252 argv_find(argv, argc, "AA:AA:NN", &idx);
20253 /* Concat community string argument. */
20254 str = argv_concat(argv, argc, idx);
20255 }
20256
20257 idx = 0;
20258 argv_find(argv, argc, "(1-99)", &idx);
20259 argv_find(argv, argc, "(100-500)", &idx);
20260 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20261
20262 /* Unset community list. */
20263 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20264 style);
20265
20266 /* Free temporary community list string allocated by
20267 argv_concat(). */
20268 XFREE(MTYPE_TMP, str);
20269
20270 if (ret < 0) {
20271 community_list_perror(vty, ret);
20272 return CMD_WARNING_CONFIG_FAILED;
20273 }
20274
20275 return CMD_SUCCESS;
20276 }
20277
20278 /* "large-community-list" keyword help string. */
20279 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20280 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20281
20282 DEFUN (lcommunity_list_standard,
20283 bgp_lcommunity_list_standard_cmd,
20284 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20285 BGP_STR
20286 LCOMMUNITY_LIST_STR
20287 "Large Community list number (standard)\n"
20288 "Sequence number of an entry\n"
20289 "Sequence number\n"
20290 "Specify large community to reject\n"
20291 "Specify large community to accept\n"
20292 LCOMMUNITY_VAL_STR)
20293 {
20294 return lcommunity_list_set_vty(vty, argc, argv,
20295 LARGE_COMMUNITY_LIST_STANDARD, 0);
20296 }
20297
20298 DEFUN (lcommunity_list_expanded,
20299 bgp_lcommunity_list_expanded_cmd,
20300 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20301 BGP_STR
20302 LCOMMUNITY_LIST_STR
20303 "Large Community list number (expanded)\n"
20304 "Sequence number of an entry\n"
20305 "Sequence number\n"
20306 "Specify large community to reject\n"
20307 "Specify large community to accept\n"
20308 "An ordered list as a regular-expression\n")
20309 {
20310 return lcommunity_list_set_vty(vty, argc, argv,
20311 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20312 }
20313
20314 DEFUN (lcommunity_list_name_standard,
20315 bgp_lcommunity_list_name_standard_cmd,
20316 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20317 BGP_STR
20318 LCOMMUNITY_LIST_STR
20319 "Specify standard large-community-list\n"
20320 "Large Community list name\n"
20321 "Sequence number of an entry\n"
20322 "Sequence number\n"
20323 "Specify large community to reject\n"
20324 "Specify large community to accept\n"
20325 LCOMMUNITY_VAL_STR)
20326 {
20327 return lcommunity_list_set_vty(vty, argc, argv,
20328 LARGE_COMMUNITY_LIST_STANDARD, 1);
20329 }
20330
20331 DEFUN (lcommunity_list_name_expanded,
20332 bgp_lcommunity_list_name_expanded_cmd,
20333 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20334 BGP_STR
20335 LCOMMUNITY_LIST_STR
20336 "Specify expanded large-community-list\n"
20337 "Large Community list name\n"
20338 "Sequence number of an entry\n"
20339 "Sequence number\n"
20340 "Specify large community to reject\n"
20341 "Specify large community to accept\n"
20342 "An ordered list as a regular-expression\n")
20343 {
20344 return lcommunity_list_set_vty(vty, argc, argv,
20345 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20346 }
20347
20348 DEFUN (no_lcommunity_list_all,
20349 no_bgp_lcommunity_list_all_cmd,
20350 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20351 NO_STR
20352 BGP_STR
20353 LCOMMUNITY_LIST_STR
20354 "Large Community list number (standard)\n"
20355 "Large Community list number (expanded)\n"
20356 "Large Community list name\n")
20357 {
20358 return lcommunity_list_unset_vty(vty, argc, argv,
20359 LARGE_COMMUNITY_LIST_STANDARD);
20360 }
20361
20362 DEFUN (no_lcommunity_list_name_standard_all,
20363 no_bgp_lcommunity_list_name_standard_all_cmd,
20364 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20365 NO_STR
20366 BGP_STR
20367 LCOMMUNITY_LIST_STR
20368 "Specify standard large-community-list\n"
20369 "Large Community list name\n")
20370 {
20371 return lcommunity_list_unset_vty(vty, argc, argv,
20372 LARGE_COMMUNITY_LIST_STANDARD);
20373 }
20374
20375 DEFUN (no_lcommunity_list_name_expanded_all,
20376 no_bgp_lcommunity_list_name_expanded_all_cmd,
20377 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20378 NO_STR
20379 BGP_STR
20380 LCOMMUNITY_LIST_STR
20381 "Specify expanded large-community-list\n"
20382 "Large Community list name\n")
20383 {
20384 return lcommunity_list_unset_vty(vty, argc, argv,
20385 LARGE_COMMUNITY_LIST_EXPANDED);
20386 }
20387
20388 DEFUN (no_lcommunity_list_standard,
20389 no_bgp_lcommunity_list_standard_cmd,
20390 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20391 NO_STR
20392 BGP_STR
20393 LCOMMUNITY_LIST_STR
20394 "Large Community list number (standard)\n"
20395 "Sequence number of an entry\n"
20396 "Sequence number\n"
20397 "Specify large community to reject\n"
20398 "Specify large community to accept\n"
20399 LCOMMUNITY_VAL_STR)
20400 {
20401 return lcommunity_list_unset_vty(vty, argc, argv,
20402 LARGE_COMMUNITY_LIST_STANDARD);
20403 }
20404
20405 DEFUN (no_lcommunity_list_expanded,
20406 no_bgp_lcommunity_list_expanded_cmd,
20407 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20408 NO_STR
20409 BGP_STR
20410 LCOMMUNITY_LIST_STR
20411 "Large Community list number (expanded)\n"
20412 "Sequence number of an entry\n"
20413 "Sequence number\n"
20414 "Specify large community to reject\n"
20415 "Specify large community to accept\n"
20416 "An ordered list as a regular-expression\n")
20417 {
20418 return lcommunity_list_unset_vty(vty, argc, argv,
20419 LARGE_COMMUNITY_LIST_EXPANDED);
20420 }
20421
20422 DEFUN (no_lcommunity_list_name_standard,
20423 no_bgp_lcommunity_list_name_standard_cmd,
20424 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20425 NO_STR
20426 BGP_STR
20427 LCOMMUNITY_LIST_STR
20428 "Specify standard large-community-list\n"
20429 "Large Community list name\n"
20430 "Sequence number of an entry\n"
20431 "Sequence number\n"
20432 "Specify large community to reject\n"
20433 "Specify large community to accept\n"
20434 LCOMMUNITY_VAL_STR)
20435 {
20436 return lcommunity_list_unset_vty(vty, argc, argv,
20437 LARGE_COMMUNITY_LIST_STANDARD);
20438 }
20439
20440 DEFUN (no_lcommunity_list_name_expanded,
20441 no_bgp_lcommunity_list_name_expanded_cmd,
20442 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20443 NO_STR
20444 BGP_STR
20445 LCOMMUNITY_LIST_STR
20446 "Specify expanded large-community-list\n"
20447 "Large community list name\n"
20448 "Sequence number of an entry\n"
20449 "Sequence number\n"
20450 "Specify large community to reject\n"
20451 "Specify large community to accept\n"
20452 "An ordered list as a regular-expression\n")
20453 {
20454 return lcommunity_list_unset_vty(vty, argc, argv,
20455 LARGE_COMMUNITY_LIST_EXPANDED);
20456 }
20457
20458 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20459 {
20460 struct community_entry *entry;
20461
20462 for (entry = list->head; entry; entry = entry->next) {
20463 if (entry == list->head) {
20464 if (all_digit(list->name))
20465 vty_out(vty, "Large community %s list %s\n",
20466 entry->style ==
20467 LARGE_COMMUNITY_LIST_STANDARD
20468 ? "standard"
20469 : "(expanded) access",
20470 list->name);
20471 else
20472 vty_out(vty,
20473 "Named large community %s list %s\n",
20474 entry->style ==
20475 LARGE_COMMUNITY_LIST_STANDARD
20476 ? "standard"
20477 : "expanded",
20478 list->name);
20479 }
20480 if (entry->any)
20481 vty_out(vty, " %s\n",
20482 community_direct_str(entry->direct));
20483 else
20484 vty_out(vty, " %s %s\n",
20485 community_direct_str(entry->direct),
20486 community_list_config_str(entry));
20487 }
20488 }
20489
20490 DEFUN (show_lcommunity_list,
20491 show_bgp_lcommunity_list_cmd,
20492 "show bgp large-community-list",
20493 SHOW_STR
20494 BGP_STR
20495 "List large-community list\n")
20496 {
20497 struct community_list *list;
20498 struct community_list_master *cm;
20499
20500 cm = community_list_master_lookup(bgp_clist,
20501 LARGE_COMMUNITY_LIST_MASTER);
20502 if (!cm)
20503 return CMD_SUCCESS;
20504
20505 for (list = cm->num.head; list; list = list->next)
20506 lcommunity_list_show(vty, list);
20507
20508 for (list = cm->str.head; list; list = list->next)
20509 lcommunity_list_show(vty, list);
20510
20511 return CMD_SUCCESS;
20512 }
20513
20514 DEFUN (show_lcommunity_list_arg,
20515 show_bgp_lcommunity_list_arg_cmd,
20516 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20517 SHOW_STR
20518 BGP_STR
20519 "List large-community list\n"
20520 "Large-community-list number\n"
20521 "Large-community-list name\n"
20522 "Detailed information on large-community-list\n")
20523 {
20524 struct community_list *list;
20525
20526 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20527 LARGE_COMMUNITY_LIST_MASTER);
20528 if (!list) {
20529 vty_out(vty, "%% Can't find large-community-list\n");
20530 return CMD_WARNING;
20531 }
20532
20533 lcommunity_list_show(vty, list);
20534
20535 return CMD_SUCCESS;
20536 }
20537
20538 /* "extcommunity-list" keyword help string. */
20539 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20540 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20541
20542 DEFUN (extcommunity_list_standard,
20543 bgp_extcommunity_list_standard_cmd,
20544 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20545 BGP_STR
20546 EXTCOMMUNITY_LIST_STR
20547 "Extended Community list number (standard)\n"
20548 "Specify standard extcommunity-list\n"
20549 "Community list name\n"
20550 "Sequence number of an entry\n"
20551 "Sequence number\n"
20552 "Specify community to reject\n"
20553 "Specify community to accept\n"
20554 EXTCOMMUNITY_VAL_STR)
20555 {
20556 int style = EXTCOMMUNITY_LIST_STANDARD;
20557 int direct = 0;
20558 char *cl_number_or_name = NULL;
20559 char *seq = NULL;
20560
20561 int idx = 0;
20562
20563 argv_find(argv, argc, "(1-99)", &idx);
20564 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20565 cl_number_or_name = argv[idx]->arg;
20566
20567 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20568 seq = argv[idx]->arg;
20569
20570 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20571 : COMMUNITY_DENY;
20572 argv_find(argv, argc, "AA:NN", &idx);
20573 char *str = argv_concat(argv, argc, idx);
20574
20575 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20576 direct, style);
20577
20578 XFREE(MTYPE_TMP, str);
20579
20580 if (ret < 0) {
20581 community_list_perror(vty, ret);
20582 return CMD_WARNING_CONFIG_FAILED;
20583 }
20584
20585 return CMD_SUCCESS;
20586 }
20587
20588 DEFUN (extcommunity_list_name_expanded,
20589 bgp_extcommunity_list_name_expanded_cmd,
20590 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20591 BGP_STR
20592 EXTCOMMUNITY_LIST_STR
20593 "Extended Community list number (expanded)\n"
20594 "Specify expanded extcommunity-list\n"
20595 "Extended Community list name\n"
20596 "Sequence number of an entry\n"
20597 "Sequence number\n"
20598 "Specify community to reject\n"
20599 "Specify community to accept\n"
20600 "An ordered list as a regular-expression\n")
20601 {
20602 int style = EXTCOMMUNITY_LIST_EXPANDED;
20603 int direct = 0;
20604 char *cl_number_or_name = NULL;
20605 char *seq = NULL;
20606 int idx = 0;
20607
20608 argv_find(argv, argc, "(100-500)", &idx);
20609 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20610 cl_number_or_name = argv[idx]->arg;
20611
20612 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20613 seq = argv[idx]->arg;
20614
20615 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20616 : COMMUNITY_DENY;
20617 argv_find(argv, argc, "LINE", &idx);
20618 char *str = argv_concat(argv, argc, idx);
20619
20620 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20621 direct, style);
20622
20623 XFREE(MTYPE_TMP, str);
20624
20625 if (ret < 0) {
20626 community_list_perror(vty, ret);
20627 return CMD_WARNING_CONFIG_FAILED;
20628 }
20629
20630 return CMD_SUCCESS;
20631 }
20632
20633 DEFUN (no_extcommunity_list_standard_all,
20634 no_bgp_extcommunity_list_standard_all_cmd,
20635 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20636 NO_STR
20637 BGP_STR
20638 EXTCOMMUNITY_LIST_STR
20639 "Extended Community list number (standard)\n"
20640 "Specify standard extcommunity-list\n"
20641 "Community list name\n"
20642 "Sequence number of an entry\n"
20643 "Sequence number\n"
20644 "Specify community to reject\n"
20645 "Specify community to accept\n"
20646 EXTCOMMUNITY_VAL_STR)
20647 {
20648 int style = EXTCOMMUNITY_LIST_STANDARD;
20649 int direct = 0;
20650 char *cl_number_or_name = NULL;
20651 char *str = NULL;
20652 char *seq = NULL;
20653 int idx = 0;
20654
20655 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20656 seq = argv[idx]->arg;
20657
20658 idx = 0;
20659 argv_find(argv, argc, "permit", &idx);
20660 argv_find(argv, argc, "deny", &idx);
20661 if (idx) {
20662 direct = argv_find(argv, argc, "permit", &idx)
20663 ? COMMUNITY_PERMIT
20664 : COMMUNITY_DENY;
20665
20666 idx = 0;
20667 argv_find(argv, argc, "AA:NN", &idx);
20668 str = argv_concat(argv, argc, idx);
20669 }
20670
20671 idx = 0;
20672 argv_find(argv, argc, "(1-99)", &idx);
20673 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20674 cl_number_or_name = argv[idx]->arg;
20675
20676 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20677 seq, direct, style);
20678
20679 XFREE(MTYPE_TMP, str);
20680
20681 if (ret < 0) {
20682 community_list_perror(vty, ret);
20683 return CMD_WARNING_CONFIG_FAILED;
20684 }
20685
20686 return CMD_SUCCESS;
20687 }
20688
20689 ALIAS(no_extcommunity_list_standard_all,
20690 no_bgp_extcommunity_list_standard_all_list_cmd,
20691 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20692 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20693 "Extended Community list number (standard)\n"
20694 "Specify standard extcommunity-list\n"
20695 "Community list name\n")
20696
20697 DEFUN (no_extcommunity_list_expanded_all,
20698 no_bgp_extcommunity_list_expanded_all_cmd,
20699 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20700 NO_STR
20701 BGP_STR
20702 EXTCOMMUNITY_LIST_STR
20703 "Extended Community list number (expanded)\n"
20704 "Specify expanded extcommunity-list\n"
20705 "Extended Community list name\n"
20706 "Sequence number of an entry\n"
20707 "Sequence number\n"
20708 "Specify community to reject\n"
20709 "Specify community to accept\n"
20710 "An ordered list as a regular-expression\n")
20711 {
20712 int style = EXTCOMMUNITY_LIST_EXPANDED;
20713 int direct = 0;
20714 char *cl_number_or_name = NULL;
20715 char *str = NULL;
20716 char *seq = NULL;
20717 int idx = 0;
20718
20719 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20720 seq = argv[idx]->arg;
20721
20722 idx = 0;
20723 argv_find(argv, argc, "permit", &idx);
20724 argv_find(argv, argc, "deny", &idx);
20725
20726 if (idx) {
20727 direct = argv_find(argv, argc, "permit", &idx)
20728 ? COMMUNITY_PERMIT
20729 : COMMUNITY_DENY;
20730
20731 idx = 0;
20732 argv_find(argv, argc, "LINE", &idx);
20733 str = argv_concat(argv, argc, idx);
20734 }
20735
20736 idx = 0;
20737 argv_find(argv, argc, "(100-500)", &idx);
20738 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20739 cl_number_or_name = argv[idx]->arg;
20740
20741 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20742 seq, direct, style);
20743
20744 XFREE(MTYPE_TMP, str);
20745
20746 if (ret < 0) {
20747 community_list_perror(vty, ret);
20748 return CMD_WARNING_CONFIG_FAILED;
20749 }
20750
20751 return CMD_SUCCESS;
20752 }
20753
20754 ALIAS(no_extcommunity_list_expanded_all,
20755 no_bgp_extcommunity_list_expanded_all_list_cmd,
20756 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20757 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20758 "Extended Community list number (expanded)\n"
20759 "Specify expanded extcommunity-list\n"
20760 "Extended Community list name\n")
20761
20762 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20763 {
20764 struct community_entry *entry;
20765
20766 for (entry = list->head; entry; entry = entry->next) {
20767 if (entry == list->head) {
20768 if (all_digit(list->name))
20769 vty_out(vty, "Extended community %s list %s\n",
20770 entry->style == EXTCOMMUNITY_LIST_STANDARD
20771 ? "standard"
20772 : "(expanded) access",
20773 list->name);
20774 else
20775 vty_out(vty,
20776 "Named extended community %s list %s\n",
20777 entry->style == EXTCOMMUNITY_LIST_STANDARD
20778 ? "standard"
20779 : "expanded",
20780 list->name);
20781 }
20782 if (entry->any)
20783 vty_out(vty, " %s\n",
20784 community_direct_str(entry->direct));
20785 else
20786 vty_out(vty, " %s %s\n",
20787 community_direct_str(entry->direct),
20788 community_list_config_str(entry));
20789 }
20790 }
20791
20792 DEFUN (show_extcommunity_list,
20793 show_bgp_extcommunity_list_cmd,
20794 "show bgp extcommunity-list",
20795 SHOW_STR
20796 BGP_STR
20797 "List extended-community list\n")
20798 {
20799 struct community_list *list;
20800 struct community_list_master *cm;
20801
20802 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20803 if (!cm)
20804 return CMD_SUCCESS;
20805
20806 for (list = cm->num.head; list; list = list->next)
20807 extcommunity_list_show(vty, list);
20808
20809 for (list = cm->str.head; list; list = list->next)
20810 extcommunity_list_show(vty, list);
20811
20812 return CMD_SUCCESS;
20813 }
20814
20815 DEFUN (show_extcommunity_list_arg,
20816 show_bgp_extcommunity_list_arg_cmd,
20817 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20818 SHOW_STR
20819 BGP_STR
20820 "List extended-community list\n"
20821 "Extcommunity-list number\n"
20822 "Extcommunity-list name\n"
20823 "Detailed information on extcommunity-list\n")
20824 {
20825 int idx_comm_list = 3;
20826 struct community_list *list;
20827
20828 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20829 EXTCOMMUNITY_LIST_MASTER);
20830 if (!list) {
20831 vty_out(vty, "%% Can't find extcommunity-list\n");
20832 return CMD_WARNING;
20833 }
20834
20835 extcommunity_list_show(vty, list);
20836
20837 return CMD_SUCCESS;
20838 }
20839
20840 /* Display community-list and extcommunity-list configuration. */
20841 static int community_list_config_write(struct vty *vty)
20842 {
20843 struct community_list *list;
20844 struct community_entry *entry;
20845 struct community_list_master *cm;
20846 int write = 0;
20847
20848 /* Community-list. */
20849 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20850
20851 for (list = cm->num.head; list; list = list->next)
20852 for (entry = list->head; entry; entry = entry->next) {
20853 vty_out(vty,
20854 "bgp community-list %s seq %" PRId64 " %s %s\n",
20855 list->name, entry->seq,
20856 community_direct_str(entry->direct),
20857 community_list_config_str(entry));
20858 write++;
20859 }
20860 for (list = cm->str.head; list; list = list->next)
20861 for (entry = list->head; entry; entry = entry->next) {
20862 vty_out(vty,
20863 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20864 entry->style == COMMUNITY_LIST_STANDARD
20865 ? "standard"
20866 : "expanded",
20867 list->name, entry->seq,
20868 community_direct_str(entry->direct),
20869 community_list_config_str(entry));
20870 write++;
20871 }
20872
20873 /* Extcommunity-list. */
20874 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20875
20876 for (list = cm->num.head; list; list = list->next)
20877 for (entry = list->head; entry; entry = entry->next) {
20878 vty_out(vty,
20879 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20880 list->name, entry->seq,
20881 community_direct_str(entry->direct),
20882 community_list_config_str(entry));
20883 write++;
20884 }
20885 for (list = cm->str.head; list; list = list->next)
20886 for (entry = list->head; entry; entry = entry->next) {
20887 vty_out(vty,
20888 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20889 entry->style == EXTCOMMUNITY_LIST_STANDARD
20890 ? "standard"
20891 : "expanded",
20892 list->name, entry->seq,
20893 community_direct_str(entry->direct),
20894 community_list_config_str(entry));
20895 write++;
20896 }
20897
20898
20899 /* lcommunity-list. */
20900 cm = community_list_master_lookup(bgp_clist,
20901 LARGE_COMMUNITY_LIST_MASTER);
20902
20903 for (list = cm->num.head; list; list = list->next)
20904 for (entry = list->head; entry; entry = entry->next) {
20905 vty_out(vty,
20906 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20907 list->name, entry->seq,
20908 community_direct_str(entry->direct),
20909 community_list_config_str(entry));
20910 write++;
20911 }
20912 for (list = cm->str.head; list; list = list->next)
20913 for (entry = list->head; entry; entry = entry->next) {
20914 vty_out(vty,
20915 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20916
20917 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20918 ? "standard"
20919 : "expanded",
20920 list->name, entry->seq, community_direct_str(entry->direct),
20921 community_list_config_str(entry));
20922 write++;
20923 }
20924
20925 return write;
20926 }
20927
20928 static int community_list_config_write(struct vty *vty);
20929 static struct cmd_node community_list_node = {
20930 .name = "community list",
20931 .node = COMMUNITY_LIST_NODE,
20932 .prompt = "",
20933 .config_write = community_list_config_write,
20934 };
20935
20936 static void community_list_vty(void)
20937 {
20938 install_node(&community_list_node);
20939
20940 /* Community-list. */
20941 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20942 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20943 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20944 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20945 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20946 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20947 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20948 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20949
20950 /* Extcommunity-list. */
20951 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20952 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20953 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20954 install_element(CONFIG_NODE,
20955 &no_bgp_extcommunity_list_standard_all_list_cmd);
20956 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20957 install_element(CONFIG_NODE,
20958 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20959 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20960 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20961
20962 /* Large Community List */
20963 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20964 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20965 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20966 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20967 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20968 install_element(CONFIG_NODE,
20969 &no_bgp_lcommunity_list_name_standard_all_cmd);
20970 install_element(CONFIG_NODE,
20971 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20972 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20973 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20974 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20975 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20976 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20977 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20978
20979 bgp_community_list_command_completion_setup();
20980 }
20981
20982 static struct cmd_node community_alias_node = {
20983 .name = "community alias",
20984 .node = COMMUNITY_ALIAS_NODE,
20985 .prompt = "",
20986 .config_write = bgp_community_alias_write,
20987 };
20988
20989 void community_alias_vty(void)
20990 {
20991 install_node(&community_alias_node);
20992
20993 /* Community-list. */
20994 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20995
20996 bgp_community_alias_command_completion_setup();
20997 }