]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12226 from spk-hebbar/zebra_fpm
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_attr_evpn.h"
45 #include "bgpd/bgp_advertise.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_community_alias.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_debug.h"
54 #include "bgpd/bgp_errors.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_nht.h"
57 #include "bgpd/bgp_nexthop.h"
58 #include "bgpd/bgp_network.h"
59 #include "bgpd/bgp_open.h"
60 #include "bgpd/bgp_regex.h"
61 #include "bgpd/bgp_route.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_zebra.h"
64 #include "bgpd/bgp_table.h"
65 #include "bgpd/bgp_vty.h"
66 #include "bgpd/bgp_mpath.h"
67 #include "bgpd/bgp_packet.h"
68 #include "bgpd/bgp_updgrp.h"
69 #include "bgpd/bgp_bfd.h"
70 #include "bgpd/bgp_io.h"
71 #include "bgpd/bgp_evpn.h"
72 #include "bgpd/bgp_evpn_vty.h"
73 #include "bgpd/bgp_evpn_mh.h"
74 #include "bgpd/bgp_addpath.h"
75 #include "bgpd/bgp_mac.h"
76 #include "bgpd/bgp_flowspec.h"
77 #include "bgpd/bgp_conditional_adv.h"
78 #ifdef ENABLE_BGP_VNC
79 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
80 #endif
81 #include "bgpd/bgp_orr.h"
82
83
84 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
85 {
86 .val_bool = false,
87 .match_profile = "traditional",
88 .match_version = "< 7.4",
89 },
90 { .val_bool = true },
91 );
92 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
95 );
96 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
99 );
100 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
103 );
104 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
105 { .val_bool = true, .match_profile = "datacenter", },
106 { .val_bool = false },
107 );
108 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
109 { .val_ulong = 10, .match_profile = "datacenter", },
110 { .val_ulong = 120 },
111 );
112 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
113 { .val_ulong = 9, .match_profile = "datacenter", },
114 { .val_ulong = 180 },
115 );
116 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
117 { .val_ulong = 3, .match_profile = "datacenter", },
118 { .val_ulong = 60 },
119 );
120 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
121 { .val_bool = false, .match_profile = "datacenter", },
122 { .val_bool = false, .match_version = "< 7.4", },
123 { .val_bool = true },
124 );
125 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
126 { .val_bool = false, .match_version = "< 7.6", },
127 { .val_bool = true },
128 );
129 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
130 { .val_bool = false, .match_version = "< 8.3", },
131 { .val_bool = true },
132 );
133 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
134 { .val_bool = false, .match_version = "< 8.3", },
135 { .val_bool = true },
136 );
137
138 DEFINE_HOOK(bgp_inst_config_write,
139 (struct bgp *bgp, struct vty *vty),
140 (bgp, vty));
141 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
142 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
143
144 static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
146
147 /* Show BGP peer's information. */
148 enum show_type {
149 show_all,
150 show_peer,
151 show_ipv4_all,
152 show_ipv6_all,
153 show_ipv4_peer,
154 show_ipv6_peer
155 };
156
157 static struct peer_group *listen_range_exists(struct bgp *bgp,
158 struct prefix *range, int exact);
159
160 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
161 struct bgp *bgp,
162 bool use_json,
163 json_object *json);
164
165 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
166 enum show_type type,
167 const char *ip_str,
168 afi_t afi, bool use_json);
169
170 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
171 {
172 switch (afi) {
173 case AFI_IP:
174 switch (safi) {
175 case SAFI_UNICAST:
176 return BGP_IPV4_NODE;
177 case SAFI_MULTICAST:
178 return BGP_IPV4M_NODE;
179 case SAFI_LABELED_UNICAST:
180 return BGP_IPV4L_NODE;
181 case SAFI_MPLS_VPN:
182 return BGP_VPNV4_NODE;
183 case SAFI_FLOWSPEC:
184 return BGP_FLOWSPECV4_NODE;
185 default:
186 /* not expected */
187 return BGP_IPV4_NODE;
188 }
189 case AFI_IP6:
190 switch (safi) {
191 case SAFI_UNICAST:
192 return BGP_IPV6_NODE;
193 case SAFI_MULTICAST:
194 return BGP_IPV6M_NODE;
195 case SAFI_LABELED_UNICAST:
196 return BGP_IPV6L_NODE;
197 case SAFI_MPLS_VPN:
198 return BGP_VPNV6_NODE;
199 case SAFI_FLOWSPEC:
200 return BGP_FLOWSPECV6_NODE;
201 default:
202 /* not expected */
203 return BGP_IPV4_NODE;
204 }
205 case AFI_L2VPN:
206 return BGP_EVPN_NODE;
207 case AFI_UNSPEC:
208 case AFI_MAX:
209 // We should never be here but to clarify the switch statement..
210 return BGP_IPV4_NODE;
211 }
212
213 // Impossible to happen
214 return BGP_IPV4_NODE;
215 }
216
217 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
218 {
219 if (afi == AFI_IP) {
220 if (safi == SAFI_UNICAST)
221 return "IPv4 Unicast";
222 if (safi == SAFI_MULTICAST)
223 return "IPv4 Multicast";
224 if (safi == SAFI_LABELED_UNICAST)
225 return "IPv4 Labeled Unicast";
226 if (safi == SAFI_MPLS_VPN)
227 return "IPv4 VPN";
228 if (safi == SAFI_ENCAP)
229 return "IPv4 Encap";
230 if (safi == SAFI_FLOWSPEC)
231 return "IPv4 Flowspec";
232 } else if (afi == AFI_IP6) {
233 if (safi == SAFI_UNICAST)
234 return "IPv6 Unicast";
235 if (safi == SAFI_MULTICAST)
236 return "IPv6 Multicast";
237 if (safi == SAFI_LABELED_UNICAST)
238 return "IPv6 Labeled Unicast";
239 if (safi == SAFI_MPLS_VPN)
240 return "IPv6 VPN";
241 if (safi == SAFI_ENCAP)
242 return "IPv6 Encap";
243 if (safi == SAFI_FLOWSPEC)
244 return "IPv6 Flowspec";
245 } else if (afi == AFI_L2VPN) {
246 if (safi == SAFI_EVPN)
247 return "L2VPN EVPN";
248 }
249
250 return "Unknown";
251 }
252
253 /*
254 * Please note that we have intentionally camelCased
255 * the return strings here. So if you want
256 * to use this function, please ensure you
257 * are doing this within json output
258 */
259 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
260 {
261 if (afi == AFI_IP) {
262 if (safi == SAFI_UNICAST)
263 return "ipv4Unicast";
264 if (safi == SAFI_MULTICAST)
265 return "ipv4Multicast";
266 if (safi == SAFI_LABELED_UNICAST)
267 return "ipv4LabeledUnicast";
268 if (safi == SAFI_MPLS_VPN)
269 return "ipv4Vpn";
270 if (safi == SAFI_ENCAP)
271 return "ipv4Encap";
272 if (safi == SAFI_FLOWSPEC)
273 return "ipv4Flowspec";
274 } else if (afi == AFI_IP6) {
275 if (safi == SAFI_UNICAST)
276 return "ipv6Unicast";
277 if (safi == SAFI_MULTICAST)
278 return "ipv6Multicast";
279 if (safi == SAFI_LABELED_UNICAST)
280 return "ipv6LabeledUnicast";
281 if (safi == SAFI_MPLS_VPN)
282 return "ipv6Vpn";
283 if (safi == SAFI_ENCAP)
284 return "ipv6Encap";
285 if (safi == SAFI_FLOWSPEC)
286 return "ipv6Flowspec";
287 } else if (afi == AFI_L2VPN) {
288 if (safi == SAFI_EVPN)
289 return "l2VpnEvpn";
290 }
291
292 return "Unknown";
293 }
294
295 /* unset srv6 locator */
296 static int bgp_srv6_locator_unset(struct bgp *bgp)
297 {
298 int ret;
299 struct listnode *node, *nnode;
300 struct srv6_locator_chunk *chunk;
301 struct bgp_srv6_function *func;
302 struct bgp *bgp_vrf;
303
304 /* release chunk notification via ZAPI */
305 ret = bgp_zebra_srv6_manager_release_locator_chunk(
306 bgp->srv6_locator_name);
307 if (ret < 0)
308 return -1;
309
310 /* refresh chunks */
311 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
312 listnode_delete(bgp->srv6_locator_chunks, chunk);
313 srv6_locator_chunk_free(&chunk);
314 }
315
316 /* refresh functions */
317 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
318 listnode_delete(bgp->srv6_functions, func);
319 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
320 }
321
322 /* refresh tovpn_sid */
323 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
324 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
325 continue;
326
327 /* refresh vpnv4 tovpn_sid */
328 XFREE(MTYPE_BGP_SRV6_SID,
329 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
330
331 /* refresh vpnv6 tovpn_sid */
332 XFREE(MTYPE_BGP_SRV6_SID,
333 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
334
335 /* refresh per-vrf tovpn_sid */
336 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
337 }
338
339 /* update vpn bgp processes */
340 vpn_leak_postchange_all();
341
342 /* refresh tovpn_sid_locator */
343 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
344 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
345 continue;
346
347 /* refresh vpnv4 tovpn_sid_locator */
348 srv6_locator_chunk_free(
349 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
350
351 /* refresh vpnv6 tovpn_sid_locator */
352 srv6_locator_chunk_free(
353 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
354
355 /* refresh per-vrf tovpn_sid_locator */
356 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
357 }
358
359 /* clear locator name */
360 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
361
362 return 0;
363 }
364
365 /* Utility function to get address family from current node. */
366 afi_t bgp_node_afi(struct vty *vty)
367 {
368 afi_t afi;
369 switch (vty->node) {
370 case BGP_IPV6_NODE:
371 case BGP_IPV6M_NODE:
372 case BGP_IPV6L_NODE:
373 case BGP_VPNV6_NODE:
374 case BGP_FLOWSPECV6_NODE:
375 afi = AFI_IP6;
376 break;
377 case BGP_EVPN_NODE:
378 afi = AFI_L2VPN;
379 break;
380 default:
381 afi = AFI_IP;
382 break;
383 }
384 return afi;
385 }
386
387 /* Utility function to get subsequent address family from current
388 node. */
389 safi_t bgp_node_safi(struct vty *vty)
390 {
391 safi_t safi;
392 switch (vty->node) {
393 case BGP_VPNV4_NODE:
394 case BGP_VPNV6_NODE:
395 safi = SAFI_MPLS_VPN;
396 break;
397 case BGP_IPV4M_NODE:
398 case BGP_IPV6M_NODE:
399 safi = SAFI_MULTICAST;
400 break;
401 case BGP_EVPN_NODE:
402 safi = SAFI_EVPN;
403 break;
404 case BGP_IPV4L_NODE:
405 case BGP_IPV6L_NODE:
406 safi = SAFI_LABELED_UNICAST;
407 break;
408 case BGP_FLOWSPECV4_NODE:
409 case BGP_FLOWSPECV6_NODE:
410 safi = SAFI_FLOWSPEC;
411 break;
412 default:
413 safi = SAFI_UNICAST;
414 break;
415 }
416 return safi;
417 }
418
419 /**
420 * Converts an AFI in string form to afi_t
421 *
422 * @param afi string, one of
423 * - "ipv4"
424 * - "ipv6"
425 * - "l2vpn"
426 * @return the corresponding afi_t
427 */
428 afi_t bgp_vty_afi_from_str(const char *afi_str)
429 {
430 afi_t afi = AFI_MAX; /* unknown */
431 if (strmatch(afi_str, "ipv4"))
432 afi = AFI_IP;
433 else if (strmatch(afi_str, "ipv6"))
434 afi = AFI_IP6;
435 else if (strmatch(afi_str, "l2vpn"))
436 afi = AFI_L2VPN;
437 return afi;
438 }
439
440 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
441 afi_t *afi)
442 {
443 int ret = 0;
444 if (argv_find(argv, argc, "ipv4", index)) {
445 ret = 1;
446 if (afi)
447 *afi = AFI_IP;
448 } else if (argv_find(argv, argc, "ipv6", index)) {
449 ret = 1;
450 if (afi)
451 *afi = AFI_IP6;
452 } else if (argv_find(argv, argc, "l2vpn", index)) {
453 ret = 1;
454 if (afi)
455 *afi = AFI_L2VPN;
456 }
457 return ret;
458 }
459
460 /* supports <unicast|multicast|vpn|labeled-unicast> */
461 safi_t bgp_vty_safi_from_str(const char *safi_str)
462 {
463 safi_t safi = SAFI_MAX; /* unknown */
464 if (strmatch(safi_str, "multicast"))
465 safi = SAFI_MULTICAST;
466 else if (strmatch(safi_str, "unicast"))
467 safi = SAFI_UNICAST;
468 else if (strmatch(safi_str, "vpn"))
469 safi = SAFI_MPLS_VPN;
470 else if (strmatch(safi_str, "evpn"))
471 safi = SAFI_EVPN;
472 else if (strmatch(safi_str, "labeled-unicast"))
473 safi = SAFI_LABELED_UNICAST;
474 else if (strmatch(safi_str, "flowspec"))
475 safi = SAFI_FLOWSPEC;
476 return safi;
477 }
478
479 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
480 safi_t *safi)
481 {
482 int ret = 0;
483 if (argv_find(argv, argc, "unicast", index)) {
484 ret = 1;
485 if (safi)
486 *safi = SAFI_UNICAST;
487 } else if (argv_find(argv, argc, "multicast", index)) {
488 ret = 1;
489 if (safi)
490 *safi = SAFI_MULTICAST;
491 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_LABELED_UNICAST;
495 } else if (argv_find(argv, argc, "vpn", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_MPLS_VPN;
499 } else if (argv_find(argv, argc, "evpn", index)) {
500 ret = 1;
501 if (safi)
502 *safi = SAFI_EVPN;
503 } else if (argv_find(argv, argc, "flowspec", index)) {
504 ret = 1;
505 if (safi)
506 *safi = SAFI_FLOWSPEC;
507 }
508 return ret;
509 }
510
511 /*
512 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
513 *
514 * afi
515 * address-family identifier
516 *
517 * safi
518 * subsequent address-family identifier
519 *
520 * Returns:
521 * default_af string corresponding to the supplied afi/safi pair.
522 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
523 * return -1.
524 */
525 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
526 {
527 switch (afi) {
528 case AFI_IP:
529 switch (safi) {
530 case SAFI_UNICAST:
531 return "ipv4-unicast";
532 case SAFI_MULTICAST:
533 return "ipv4-multicast";
534 case SAFI_MPLS_VPN:
535 return "ipv4-vpn";
536 case SAFI_ENCAP:
537 return "ipv4-encap";
538 case SAFI_LABELED_UNICAST:
539 return "ipv4-labeled-unicast";
540 case SAFI_FLOWSPEC:
541 return "ipv4-flowspec";
542 default:
543 return "unknown-afi/safi";
544 }
545 break;
546 case AFI_IP6:
547 switch (safi) {
548 case SAFI_UNICAST:
549 return "ipv6-unicast";
550 case SAFI_MULTICAST:
551 return "ipv6-multicast";
552 case SAFI_MPLS_VPN:
553 return "ipv6-vpn";
554 case SAFI_ENCAP:
555 return "ipv6-encap";
556 case SAFI_LABELED_UNICAST:
557 return "ipv6-labeled-unicast";
558 case SAFI_FLOWSPEC:
559 return "ipv6-flowspec";
560 default:
561 return "unknown-afi/safi";
562 }
563 break;
564 case AFI_L2VPN:
565 switch (safi) {
566 case SAFI_EVPN:
567 return "l2vpn-evpn";
568 default:
569 return "unknown-afi/safi";
570 }
571 case AFI_UNSPEC:
572 case AFI_MAX:
573 return "unknown-afi/safi";
574 }
575 /* all AFIs are accounted for above, so this shouldn't happen */
576 return "unknown-afi/safi";
577 }
578
579 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
580 enum bgp_instance_type inst_type)
581 {
582 int ret = bgp_get(bgp, as, name, inst_type);
583
584 if (ret == BGP_CREATED) {
585 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
586 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
587
588 if (DFLT_BGP_IMPORT_CHECK)
589 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
590 if (DFLT_BGP_SHOW_HOSTNAME)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
592 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
594 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
596 if (DFLT_BGP_DETERMINISTIC_MED)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
598 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
600 if (DFLT_BGP_SUPPRESS_DUPLICATES)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
602 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
604 if (DFLT_BGP_HARD_ADMIN_RESET)
605 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
606
607 ret = BGP_SUCCESS;
608 }
609 return ret;
610 }
611
612 /*
613 * bgp_vty_find_and_parse_afi_safi_bgp
614 *
615 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
616 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
617 * to appropriate values for the calling function. This is to allow the
618 * calling function to make decisions appropriate for the show command
619 * that is being parsed.
620 *
621 * The show commands are generally of the form:
622 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
623 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
624 *
625 * Since we use argv_find if the show command in particular doesn't have:
626 * [ip]
627 * [<view|vrf> VIEWVRFNAME]
628 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
629 * The command parsing should still be ok.
630 *
631 * vty -> The vty for the command so we can output some useful data in
632 * the event of a parse error in the vrf.
633 * argv -> The command tokens
634 * argc -> How many command tokens we have
635 * idx -> The current place in the command, generally should be 0 for this
636 * function
637 * afi -> The parsed afi if it was included in the show command, returned here
638 * safi -> The parsed safi if it was included in the show command, returned here
639 * bgp -> Pointer to the bgp data structure we need to fill in.
640 * use_json -> json is configured or not
641 *
642 * The function returns the correct location in the parse tree for the
643 * last token found.
644 *
645 * Returns 0 for failure to parse correctly, else the idx position of where
646 * it found the last token.
647 */
648 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
649 struct cmd_token **argv, int argc,
650 int *idx, afi_t *afi, safi_t *safi,
651 struct bgp **bgp, bool use_json)
652 {
653 char *vrf_name = NULL;
654
655 assert(afi);
656 assert(safi);
657 assert(bgp);
658
659 if (argv_find(argv, argc, "ip", idx))
660 *afi = AFI_IP;
661
662 if (argv_find(argv, argc, "view", idx))
663 vrf_name = argv[*idx + 1]->arg;
664 else if (argv_find(argv, argc, "vrf", idx)) {
665 vrf_name = argv[*idx + 1]->arg;
666 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
667 vrf_name = NULL;
668 }
669 if (vrf_name) {
670 if (strmatch(vrf_name, "all"))
671 *bgp = NULL;
672 else {
673 *bgp = bgp_lookup_by_name(vrf_name);
674 if (!*bgp) {
675 if (use_json) {
676 json_object *json = NULL;
677 json = json_object_new_object();
678 json_object_string_add(
679 json, "warning",
680 "View/Vrf is unknown");
681 vty_json(vty, json);
682 }
683 else
684 vty_out(vty, "View/Vrf %s is unknown\n",
685 vrf_name);
686 *idx = 0;
687 return 0;
688 }
689 }
690 } else {
691 *bgp = bgp_get_default();
692 if (!*bgp) {
693 if (use_json) {
694 json_object *json = NULL;
695 json = json_object_new_object();
696 json_object_string_add(
697 json, "warning",
698 "Default BGP instance not found");
699 vty_json(vty, json);
700 }
701 else
702 vty_out(vty,
703 "Default BGP instance not found\n");
704 *idx = 0;
705 return 0;
706 }
707 }
708
709 if (argv_find_and_parse_afi(argv, argc, idx, afi))
710 argv_find_and_parse_safi(argv, argc, idx, safi);
711
712 *idx += 1;
713 return *idx;
714 }
715
716 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
717 {
718 struct interface *ifp = NULL;
719 struct listnode *node;
720 struct bgp_listener *listener;
721 union sockunion all_su;
722
723 if (su->sa.sa_family == AF_INET) {
724 (void)str2sockunion("0.0.0.0", &all_su);
725 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
726 } else if (su->sa.sa_family == AF_INET6) {
727 (void)str2sockunion("::", &all_su);
728 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
729 su->sin6.sin6_scope_id,
730 bgp->vrf_id);
731 }
732
733 if (ifp) {
734 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
735 if (sockunion_family(su) !=
736 sockunion_family(&listener->su))
737 continue;
738
739 /* If 0.0.0.0/:: is a listener, then treat as self and
740 * reject.
741 */
742 if (!sockunion_cmp(&listener->su, su) ||
743 !sockunion_cmp(&listener->su, &all_su))
744 return true;
745 }
746 }
747
748 return false;
749 }
750
751 /* Utility function for looking up peer from VTY. */
752 /* This is used only for configuration, so disallow if attempted on
753 * a dynamic neighbor.
754 */
755 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
756 {
757 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
758 int ret;
759 union sockunion su;
760 struct peer *peer;
761
762 if (!bgp) {
763 return NULL;
764 }
765
766 ret = str2sockunion(ip_str, &su);
767 if (ret < 0) {
768 peer = peer_lookup_by_conf_if(bgp, ip_str);
769 if (!peer) {
770 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
771 == NULL) {
772 vty_out(vty,
773 "%% Malformed address or name: %s\n",
774 ip_str);
775 return NULL;
776 }
777 }
778 } else {
779 peer = peer_lookup(bgp, &su);
780 if (!peer) {
781 vty_out(vty,
782 "%% Specify remote-as or peer-group commands first\n");
783 return NULL;
784 }
785 if (peer_dynamic_neighbor(peer)) {
786 vty_out(vty,
787 "%% Operation not allowed on a dynamic neighbor\n");
788 return NULL;
789 }
790 }
791 return peer;
792 }
793
794 /* Utility function for looking up peer or peer group. */
795 /* This is used only for configuration, so disallow if attempted on
796 * a dynamic neighbor.
797 */
798 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
799 {
800 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
801 int ret;
802 union sockunion su;
803 struct peer *peer = NULL;
804 struct peer_group *group = NULL;
805
806 if (!bgp) {
807 return NULL;
808 }
809
810 ret = str2sockunion(peer_str, &su);
811 if (ret == 0) {
812 /* IP address, locate peer. */
813 peer = peer_lookup(bgp, &su);
814 } else {
815 /* Not IP, could match either peer configured on interface or a
816 * group. */
817 peer = peer_lookup_by_conf_if(bgp, peer_str);
818 if (!peer)
819 group = peer_group_lookup(bgp, peer_str);
820 }
821
822 if (peer) {
823 if (peer_dynamic_neighbor(peer)) {
824 vty_out(vty,
825 "%% Operation not allowed on a dynamic neighbor\n");
826 return NULL;
827 }
828
829 return peer;
830 }
831
832 if (group)
833 return group->conf;
834
835 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
836
837 return NULL;
838 }
839
840 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
841 {
842 const char *str = NULL;
843
844 switch (ret) {
845 case BGP_SUCCESS:
846 case BGP_CREATED:
847 case BGP_GR_NO_OPERATION:
848 break;
849 case BGP_ERR_INVALID_VALUE:
850 str = "Invalid value";
851 break;
852 case BGP_ERR_INVALID_FLAG:
853 str = "Invalid flag";
854 break;
855 case BGP_ERR_PEER_GROUP_SHUTDOWN:
856 str = "Peer-group has been shutdown. Activate the peer-group first";
857 break;
858 case BGP_ERR_PEER_FLAG_CONFLICT:
859 str = "Can't set override-capability and strict-capability-match at the same time";
860 break;
861 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
862 str = "Specify remote-as or peer-group remote AS first";
863 break;
864 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
865 str = "Cannot change the peer-group. Deconfigure first";
866 break;
867 case BGP_ERR_PEER_GROUP_MISMATCH:
868 str = "Peer is not a member of this peer-group";
869 break;
870 case BGP_ERR_PEER_FILTER_CONFLICT:
871 str = "Prefix/distribute list can not co-exist";
872 break;
873 case BGP_ERR_NOT_INTERNAL_PEER:
874 str = "Invalid command. Not an internal neighbor";
875 break;
876 case BGP_ERR_REMOVE_PRIVATE_AS:
877 str = "remove-private-AS cannot be configured for IBGP peers";
878 break;
879 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
880 str = "Cannot have local-as same as BGP AS number";
881 break;
882 case BGP_ERR_TCPSIG_FAILED:
883 str = "Error while applying TCP-Sig to session(s)";
884 break;
885 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
886 str = "ebgp-multihop and ttl-security cannot be configured together";
887 break;
888 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
889 str = "ttl-security only allowed for EBGP peers";
890 break;
891 case BGP_ERR_AS_OVERRIDE:
892 str = "as-override cannot be configured for IBGP peers";
893 break;
894 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
895 str = "Invalid limit for number of dynamic neighbors";
896 break;
897 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
898 str = "Dynamic neighbor listen range already exists";
899 break;
900 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
901 str = "Operation not allowed on a dynamic neighbor";
902 break;
903 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
904 str = "Operation not allowed on a directly connected neighbor";
905 break;
906 case BGP_ERR_PEER_SAFI_CONFLICT:
907 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
908 break;
909 case BGP_ERR_GR_INVALID_CMD:
910 str = "The Graceful Restart command used is not valid at this moment.";
911 break;
912 case BGP_ERR_GR_OPERATION_FAILED:
913 str = "The Graceful Restart Operation failed due to an err.";
914 break;
915 case BGP_ERR_PEER_GROUP_MEMBER:
916 str = "Peer-group member cannot override remote-as of peer-group.";
917 break;
918 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
919 str = "Peer-group members must be all internal or all external.";
920 break;
921 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
922 str = "Range specified cannot be deleted because it is not part of current config.";
923 break;
924 case BGP_ERR_INSTANCE_MISMATCH:
925 str = "Instance specified does not match the current instance.";
926 break;
927 case BGP_ERR_NO_INTERFACE_CONFIG:
928 str = "Interface specified is not being used for interface based peer.";
929 break;
930 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
931 str = "No configuration already specified for soft reconfiguration.";
932 break;
933 case BGP_ERR_AS_MISMATCH:
934 str = "BGP is already running.";
935 break;
936 case BGP_ERR_AF_UNCONFIGURED:
937 str = "AFI/SAFI specified is not currently configured.";
938 break;
939 case BGP_ERR_INVALID_AS:
940 str = "Confederation AS specified is the same AS as our AS.";
941 break;
942 case BGP_ERR_INVALID_ROLE_NAME:
943 str = "Invalid role name";
944 break;
945 case BGP_ERR_INVALID_INTERNAL_ROLE:
946 str = "External roles can be set only on eBGP session";
947 break;
948 case BGP_ERR_PEER_ORR_CONFIGURED:
949 str = "Deconfigure optimal-route-reflection on this peer first";
950 break;
951 }
952 if (str) {
953 vty_out(vty, "%% %s\n", str);
954 return CMD_WARNING_CONFIG_FAILED;
955 }
956 return CMD_SUCCESS;
957 }
958
959 /* BGP clear sort. */
960 enum clear_sort {
961 clear_all,
962 clear_peer,
963 clear_group,
964 clear_external,
965 clear_as
966 };
967
968 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
969 safi_t safi, int error)
970 {
971 switch (error) {
972 case BGP_ERR_AF_UNCONFIGURED:
973 if (vty)
974 vty_out(vty,
975 "%% BGP: Enable %s address family for the neighbor %s\n",
976 get_afi_safi_str(afi, safi, false), peer->host);
977 else
978 zlog_warn(
979 "%% BGP: Enable %s address family for the neighbor %s",
980 get_afi_safi_str(afi, safi, false), peer->host);
981 break;
982 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
983 if (vty)
984 vty_out(vty,
985 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
986 peer->host);
987 else
988 zlog_warn(
989 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
990 peer->host);
991 break;
992 default:
993 break;
994 }
995 }
996
997 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
998 struct listnode **nnode, enum bgp_clear_type stype)
999 {
1000 int ret = 0;
1001 struct peer_af *paf;
1002
1003 /* if afi/.safi not specified, spin thru all of them */
1004 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1005 afi_t tmp_afi;
1006 safi_t tmp_safi;
1007 enum bgp_af_index index;
1008
1009 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1010 paf = peer->peer_af_array[index];
1011 if (!paf)
1012 continue;
1013
1014 if (paf && paf->subgroup)
1015 SET_FLAG(paf->subgroup->sflags,
1016 SUBGRP_STATUS_FORCE_UPDATES);
1017
1018 tmp_afi = paf->afi;
1019 tmp_safi = paf->safi;
1020 if (!peer->afc[tmp_afi][tmp_safi])
1021 continue;
1022
1023 if (stype == BGP_CLEAR_SOFT_NONE)
1024 ret = peer_clear(peer, nnode);
1025 else
1026 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1027 stype);
1028 }
1029 /* if afi specified and safi not, spin thru safis on this afi */
1030 } else if (safi == SAFI_UNSPEC) {
1031 safi_t tmp_safi;
1032
1033 for (tmp_safi = SAFI_UNICAST;
1034 tmp_safi < SAFI_MAX; tmp_safi++) {
1035 if (!peer->afc[afi][tmp_safi])
1036 continue;
1037
1038 paf = peer_af_find(peer, afi, tmp_safi);
1039 if (paf && paf->subgroup)
1040 SET_FLAG(paf->subgroup->sflags,
1041 SUBGRP_STATUS_FORCE_UPDATES);
1042
1043 if (stype == BGP_CLEAR_SOFT_NONE)
1044 ret = peer_clear(peer, nnode);
1045 else
1046 ret = peer_clear_soft(peer, afi,
1047 tmp_safi, stype);
1048 }
1049 /* both afi/safi specified, let the caller know if not defined */
1050 } else {
1051 if (!peer->afc[afi][safi])
1052 return 1;
1053
1054 paf = peer_af_find(peer, afi, safi);
1055 if (paf && paf->subgroup)
1056 SET_FLAG(paf->subgroup->sflags,
1057 SUBGRP_STATUS_FORCE_UPDATES);
1058
1059 if (stype == BGP_CLEAR_SOFT_NONE)
1060 ret = peer_clear(peer, nnode);
1061 else
1062 ret = peer_clear_soft(peer, afi, safi, stype);
1063 }
1064
1065 return ret;
1066 }
1067
1068 /* `clear ip bgp' functions. */
1069 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1070 enum clear_sort sort, enum bgp_clear_type stype,
1071 const char *arg)
1072 {
1073 int ret = 0;
1074 bool found = false;
1075 struct peer *peer;
1076
1077 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1078
1079 /* Clear all neighbors. */
1080 /*
1081 * Pass along pointer to next node to peer_clear() when walking all
1082 * nodes on the BGP instance as that may get freed if it is a
1083 * doppelganger
1084 */
1085 if (sort == clear_all) {
1086 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1087
1088 bgp_peer_gr_flags_update(peer);
1089
1090 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1091 gr_router_detected = true;
1092
1093 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1094 stype);
1095
1096 if (ret < 0)
1097 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1098 }
1099
1100 if (gr_router_detected
1101 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1102 bgp_zebra_send_capabilities(bgp, false);
1103 } else if (!gr_router_detected
1104 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1105 bgp_zebra_send_capabilities(bgp, true);
1106 }
1107
1108 /* This is to apply read-only mode on this clear. */
1109 if (stype == BGP_CLEAR_SOFT_NONE)
1110 bgp->update_delay_over = 0;
1111
1112 return CMD_SUCCESS;
1113 }
1114
1115 /* Clear specified neighbor. */
1116 if (sort == clear_peer) {
1117 union sockunion su;
1118
1119 /* Make sockunion for lookup. */
1120 ret = str2sockunion(arg, &su);
1121 if (ret < 0) {
1122 peer = peer_lookup_by_conf_if(bgp, arg);
1123 if (!peer) {
1124 peer = peer_lookup_by_hostname(bgp, arg);
1125 if (!peer) {
1126 vty_out(vty,
1127 "Malformed address or name: %s\n",
1128 arg);
1129 return CMD_WARNING;
1130 }
1131 }
1132 } else {
1133 peer = peer_lookup(bgp, &su);
1134 if (!peer) {
1135 vty_out(vty,
1136 "%% BGP: Unknown neighbor - \"%s\"\n",
1137 arg);
1138 return CMD_WARNING;
1139 }
1140 }
1141
1142 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1143 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1144
1145 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1146
1147 /* if afi/safi not defined for this peer, let caller know */
1148 if (ret == 1)
1149 ret = BGP_ERR_AF_UNCONFIGURED;
1150
1151 if (ret < 0)
1152 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1153
1154 return CMD_SUCCESS;
1155 }
1156
1157 /* Clear all neighbors belonging to a specific peer-group. */
1158 if (sort == clear_group) {
1159 struct peer_group *group;
1160
1161 group = peer_group_lookup(bgp, arg);
1162 if (!group) {
1163 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1164 return CMD_WARNING;
1165 }
1166
1167 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1168 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1169
1170 if (ret < 0)
1171 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1172 else
1173 found = true;
1174 }
1175
1176 if (!found)
1177 vty_out(vty,
1178 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1179 get_afi_safi_str(afi, safi, false), arg);
1180
1181 return CMD_SUCCESS;
1182 }
1183
1184 /* Clear all external (eBGP) neighbors. */
1185 if (sort == clear_external) {
1186 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1187 if (peer->sort == BGP_PEER_IBGP)
1188 continue;
1189
1190 bgp_peer_gr_flags_update(peer);
1191
1192 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1193 gr_router_detected = true;
1194
1195 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1196
1197 if (ret < 0)
1198 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1199 else
1200 found = true;
1201 }
1202
1203 if (gr_router_detected
1204 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1205 bgp_zebra_send_capabilities(bgp, false);
1206 } else if (!gr_router_detected
1207 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1208 bgp_zebra_send_capabilities(bgp, true);
1209 }
1210
1211 if (!found)
1212 vty_out(vty,
1213 "%% BGP: No external %s peer is configured\n",
1214 get_afi_safi_str(afi, safi, false));
1215
1216 return CMD_SUCCESS;
1217 }
1218
1219 /* Clear all neighbors belonging to a specific AS. */
1220 if (sort == clear_as) {
1221 as_t as = strtoul(arg, NULL, 10);
1222
1223 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1224 if (peer->as != as)
1225 continue;
1226
1227 bgp_peer_gr_flags_update(peer);
1228
1229 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1230 gr_router_detected = true;
1231
1232 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1233
1234 if (ret < 0)
1235 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1236 else
1237 found = true;
1238 }
1239
1240 if (gr_router_detected
1241 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1242 bgp_zebra_send_capabilities(bgp, false);
1243 } else if (!gr_router_detected
1244 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1245 bgp_zebra_send_capabilities(bgp, true);
1246 }
1247
1248 if (!found)
1249 vty_out(vty,
1250 "%% BGP: No %s peer is configured with AS %s\n",
1251 get_afi_safi_str(afi, safi, false), arg);
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 return CMD_SUCCESS;
1257 }
1258
1259 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1260 safi_t safi, enum clear_sort sort,
1261 enum bgp_clear_type stype, const char *arg)
1262 {
1263 struct bgp *bgp;
1264
1265 /* BGP structure lookup. */
1266 if (name) {
1267 bgp = bgp_lookup_by_name(name);
1268 if (bgp == NULL) {
1269 vty_out(vty, "Can't find BGP instance %s\n", name);
1270 return CMD_WARNING;
1271 }
1272 } else {
1273 bgp = bgp_get_default();
1274 if (bgp == NULL) {
1275 vty_out(vty, "No BGP process is configured\n");
1276 return CMD_WARNING;
1277 }
1278 }
1279
1280 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1281 }
1282
1283 /* clear soft inbound */
1284 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1285 {
1286 afi_t afi;
1287 safi_t safi;
1288
1289 FOREACH_AFI_SAFI (afi, safi)
1290 bgp_clear_vty(vty, name, afi, safi, clear_all,
1291 BGP_CLEAR_SOFT_IN, NULL);
1292 }
1293
1294 /* clear soft outbound */
1295 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1296 {
1297 afi_t afi;
1298 safi_t safi;
1299
1300 FOREACH_AFI_SAFI (afi, safi)
1301 bgp_clear_vty(vty, name, afi, safi, clear_all,
1302 BGP_CLEAR_SOFT_OUT, NULL);
1303 }
1304
1305
1306 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1307 {
1308 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1309 }
1310
1311 #ifndef VTYSH_EXTRACT_PL
1312 #include "bgpd/bgp_vty_clippy.c"
1313 #endif
1314
1315 DEFUN_HIDDEN (bgp_local_mac,
1316 bgp_local_mac_cmd,
1317 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1318 BGP_STR
1319 "Local MAC config\n"
1320 "VxLAN Network Identifier\n"
1321 "VNI number\n"
1322 "local mac\n"
1323 "mac address\n"
1324 "mac-mobility sequence\n"
1325 "seq number\n")
1326 {
1327 int rv;
1328 vni_t vni;
1329 struct ethaddr mac;
1330 struct ipaddr ip;
1331 uint32_t seq;
1332 struct bgp *bgp;
1333
1334 vni = strtoul(argv[3]->arg, NULL, 10);
1335 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1336 vty_out(vty, "%% Malformed MAC address\n");
1337 return CMD_WARNING;
1338 }
1339 memset(&ip, 0, sizeof(ip));
1340 seq = strtoul(argv[7]->arg, NULL, 10);
1341
1342 bgp = bgp_get_default();
1343 if (!bgp) {
1344 vty_out(vty, "Default BGP instance is not there\n");
1345 return CMD_WARNING;
1346 }
1347
1348 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1349 zero_esi);
1350 if (rv < 0) {
1351 vty_out(vty, "Internal error\n");
1352 return CMD_WARNING;
1353 }
1354
1355 return CMD_SUCCESS;
1356 }
1357
1358 DEFUN_HIDDEN (no_bgp_local_mac,
1359 no_bgp_local_mac_cmd,
1360 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1361 NO_STR
1362 BGP_STR
1363 "Local MAC config\n"
1364 "VxLAN Network Identifier\n"
1365 "VNI number\n"
1366 "local mac\n"
1367 "mac address\n")
1368 {
1369 int rv;
1370 vni_t vni;
1371 struct ethaddr mac;
1372 struct ipaddr ip;
1373 struct bgp *bgp;
1374
1375 vni = strtoul(argv[4]->arg, NULL, 10);
1376 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1377 vty_out(vty, "%% Malformed MAC address\n");
1378 return CMD_WARNING;
1379 }
1380 memset(&ip, 0, sizeof(ip));
1381
1382 bgp = bgp_get_default();
1383 if (!bgp) {
1384 vty_out(vty, "Default BGP instance is not there\n");
1385 return CMD_WARNING;
1386 }
1387
1388 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1389 if (rv < 0) {
1390 vty_out(vty, "Internal error\n");
1391 return CMD_WARNING;
1392 }
1393
1394 return CMD_SUCCESS;
1395 }
1396
1397 DEFUN (no_synchronization,
1398 no_synchronization_cmd,
1399 "no synchronization",
1400 NO_STR
1401 "Perform IGP synchronization\n")
1402 {
1403 return CMD_SUCCESS;
1404 }
1405
1406 DEFUN (no_auto_summary,
1407 no_auto_summary_cmd,
1408 "no auto-summary",
1409 NO_STR
1410 "Enable automatic network number summarization\n")
1411 {
1412 return CMD_SUCCESS;
1413 }
1414
1415 /* "router bgp" commands. */
1416 DEFUN_NOSH (router_bgp,
1417 router_bgp_cmd,
1418 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1419 ROUTER_STR
1420 BGP_STR
1421 AS_STR
1422 BGP_INSTANCE_HELP_STR)
1423 {
1424 int idx_asn = 2;
1425 int idx_view_vrf = 3;
1426 int idx_vrf = 4;
1427 int is_new_bgp = 0;
1428 int ret;
1429 as_t as;
1430 struct bgp *bgp;
1431 const char *name = NULL;
1432 enum bgp_instance_type inst_type;
1433
1434 // "router bgp" without an ASN
1435 if (argc == 2) {
1436 // Pending: Make VRF option available for ASN less config
1437 bgp = bgp_get_default();
1438
1439 if (bgp == NULL) {
1440 vty_out(vty, "%% No BGP process is configured\n");
1441 return CMD_WARNING_CONFIG_FAILED;
1442 }
1443
1444 if (listcount(bm->bgp) > 1) {
1445 vty_out(vty, "%% Please specify ASN and VRF\n");
1446 return CMD_WARNING_CONFIG_FAILED;
1447 }
1448 }
1449
1450 // "router bgp X"
1451 else {
1452 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1453
1454 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1455 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1456 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1457
1458 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1459 if (argc > 3) {
1460 name = argv[idx_vrf]->arg;
1461
1462 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1463 if (strmatch(name, VRF_DEFAULT_NAME))
1464 name = NULL;
1465 else
1466 inst_type = BGP_INSTANCE_TYPE_VRF;
1467 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1468 inst_type = BGP_INSTANCE_TYPE_VIEW;
1469 }
1470
1471 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1472 is_new_bgp = (bgp_lookup(as, name) == NULL);
1473
1474 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1475 switch (ret) {
1476 case BGP_ERR_AS_MISMATCH:
1477 vty_out(vty, "BGP is already running; AS is %u\n", as);
1478 return CMD_WARNING_CONFIG_FAILED;
1479 case BGP_ERR_INSTANCE_MISMATCH:
1480 vty_out(vty,
1481 "BGP instance name and AS number mismatch\n");
1482 vty_out(vty,
1483 "BGP instance is already running; AS is %u\n",
1484 as);
1485 return CMD_WARNING_CONFIG_FAILED;
1486 }
1487
1488 /*
1489 * If we just instantiated the default instance, complete
1490 * any pending VRF-VPN leaking that was configured via
1491 * earlier "router bgp X vrf FOO" blocks.
1492 */
1493 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1494 vpn_leak_postchange_all();
1495
1496 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1497 bgp_vpn_leak_export(bgp);
1498 /* Pending: handle when user tries to change a view to vrf n vv.
1499 */
1500 }
1501
1502 /* unset the auto created flag as the user config is now present */
1503 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1504 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1505
1506 return CMD_SUCCESS;
1507 }
1508
1509 /* "no router bgp" commands. */
1510 DEFUN (no_router_bgp,
1511 no_router_bgp_cmd,
1512 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1513 NO_STR
1514 ROUTER_STR
1515 BGP_STR
1516 AS_STR
1517 BGP_INSTANCE_HELP_STR)
1518 {
1519 int idx_asn = 3;
1520 int idx_vrf = 5;
1521 as_t as;
1522 struct bgp *bgp;
1523 const char *name = NULL;
1524
1525 // "no router bgp" without an ASN
1526 if (argc == 3) {
1527 // Pending: Make VRF option available for ASN less config
1528 bgp = bgp_get_default();
1529
1530 if (bgp == NULL) {
1531 vty_out(vty, "%% No BGP process is configured\n");
1532 return CMD_WARNING_CONFIG_FAILED;
1533 }
1534
1535 if (listcount(bm->bgp) > 1) {
1536 vty_out(vty, "%% Please specify ASN and VRF\n");
1537 return CMD_WARNING_CONFIG_FAILED;
1538 }
1539
1540 if (bgp->l3vni) {
1541 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1542 bgp->l3vni);
1543 return CMD_WARNING_CONFIG_FAILED;
1544 }
1545 } else {
1546 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1547
1548 if (argc > 4) {
1549 name = argv[idx_vrf]->arg;
1550 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1551 && strmatch(name, VRF_DEFAULT_NAME))
1552 name = NULL;
1553 }
1554
1555 /* Lookup bgp structure. */
1556 bgp = bgp_lookup(as, name);
1557 if (!bgp) {
1558 vty_out(vty, "%% Can't find BGP instance\n");
1559 return CMD_WARNING_CONFIG_FAILED;
1560 }
1561
1562 if (bgp->l3vni) {
1563 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1564 bgp->l3vni);
1565 return CMD_WARNING_CONFIG_FAILED;
1566 }
1567
1568 /* Cannot delete default instance if vrf instances exist */
1569 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1570 struct listnode *node;
1571 struct bgp *tmp_bgp;
1572
1573 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1574 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1575 continue;
1576 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1577 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1578 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1579 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1580 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1581 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1582 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1583 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1584 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1585 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1586 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1587 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1588 (bgp == bgp_get_evpn() &&
1589 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1590 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1591 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1592 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1593 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1594 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1595 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1596 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1597 (hashcount(tmp_bgp->vnihash))) {
1598 vty_out(vty,
1599 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1600 return CMD_WARNING_CONFIG_FAILED;
1601 }
1602 }
1603 }
1604 }
1605
1606 bgp_delete(bgp);
1607
1608 return CMD_SUCCESS;
1609 }
1610
1611 /* bgp session-dscp */
1612
1613 DEFPY (bgp_session_dscp,
1614 bgp_session_dscp_cmd,
1615 "bgp session-dscp (0-63)$dscp",
1616 BGP_STR
1617 "Override default (C6) bgp TCP session DSCP value\n"
1618 "Manually configured dscp parameter\n")
1619 {
1620 bm->tcp_dscp = dscp << 2;
1621
1622 return CMD_SUCCESS;
1623 }
1624
1625 DEFPY (no_bgp_session_dscp,
1626 no_bgp_session_dscp_cmd,
1627 "no bgp session-dscp [(0-63)]",
1628 NO_STR
1629 BGP_STR
1630 "Override default (C6) bgp TCP session DSCP value\n"
1631 "Manually configured dscp parameter\n")
1632 {
1633 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1634
1635 return CMD_SUCCESS;
1636 }
1637
1638 /* BGP router-id. */
1639
1640 DEFPY (bgp_router_id,
1641 bgp_router_id_cmd,
1642 "bgp router-id A.B.C.D",
1643 BGP_STR
1644 "Override configured router identifier\n"
1645 "Manually configured router identifier\n")
1646 {
1647 VTY_DECLVAR_CONTEXT(bgp, bgp);
1648 bgp_router_id_static_set(bgp, router_id);
1649 return CMD_SUCCESS;
1650 }
1651
1652 DEFPY (no_bgp_router_id,
1653 no_bgp_router_id_cmd,
1654 "no bgp router-id [A.B.C.D]",
1655 NO_STR
1656 BGP_STR
1657 "Override configured router identifier\n"
1658 "Manually configured router identifier\n")
1659 {
1660 VTY_DECLVAR_CONTEXT(bgp, bgp);
1661
1662 if (router_id_str) {
1663 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1664 vty_out(vty, "%% BGP router-id doesn't match\n");
1665 return CMD_WARNING_CONFIG_FAILED;
1666 }
1667 }
1668
1669 router_id.s_addr = 0;
1670 bgp_router_id_static_set(bgp, router_id);
1671
1672 return CMD_SUCCESS;
1673 }
1674
1675 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1676 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1677 NO_STR BGP_STR
1678 "Add community specific parameters\n"
1679 "Create an alias for a community\n"
1680 "Community (AA:BB or AA:BB:CC)\n"
1681 "Alias name\n")
1682 {
1683 struct community_alias ca = {};
1684 struct community_alias *lookup_community;
1685 struct community_alias *lookup_alias;
1686 struct community *comm;
1687 struct lcommunity *lcomm;
1688 uint8_t invalid = 0;
1689
1690 comm = community_str2com(community);
1691 if (!comm)
1692 invalid++;
1693 community_free(&comm);
1694
1695 lcomm = lcommunity_str2com(community);
1696 if (!lcomm)
1697 invalid++;
1698 lcommunity_free(&lcomm);
1699
1700 if (invalid > 1) {
1701 vty_out(vty, "Invalid community format\n");
1702 return CMD_WARNING;
1703 }
1704
1705 strlcpy(ca.community, community, sizeof(ca.community));
1706 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1707
1708 lookup_community = bgp_ca_community_lookup(&ca);
1709 lookup_alias = bgp_ca_alias_lookup(&ca);
1710
1711 if (no) {
1712 bgp_ca_alias_delete(&ca);
1713 bgp_ca_community_delete(&ca);
1714 } else {
1715 if (lookup_alias) {
1716 /* Lookup if community hash table has an item
1717 * with the same alias name.
1718 */
1719 strlcpy(ca.community, lookup_alias->community,
1720 sizeof(ca.community));
1721 if (bgp_ca_community_lookup(&ca)) {
1722 vty_out(vty,
1723 "community (%s) already has this alias (%s)\n",
1724 lookup_alias->community,
1725 lookup_alias->alias);
1726 return CMD_WARNING;
1727 }
1728 bgp_ca_alias_delete(&ca);
1729 }
1730
1731 if (lookup_community) {
1732 /* Lookup if alias hash table has an item
1733 * with the same community.
1734 */
1735 strlcpy(ca.alias, lookup_community->alias,
1736 sizeof(ca.alias));
1737 if (bgp_ca_alias_lookup(&ca)) {
1738 vty_out(vty,
1739 "alias (%s) already has this community (%s)\n",
1740 lookup_community->alias,
1741 lookup_community->community);
1742 return CMD_WARNING;
1743 }
1744 bgp_ca_community_delete(&ca);
1745 }
1746
1747 bgp_ca_alias_insert(&ca);
1748 bgp_ca_community_insert(&ca);
1749 }
1750
1751 return CMD_SUCCESS;
1752 }
1753
1754 DEFPY (bgp_global_suppress_fib_pending,
1755 bgp_global_suppress_fib_pending_cmd,
1756 "[no] bgp suppress-fib-pending",
1757 NO_STR
1758 BGP_STR
1759 "Advertise only routes that are programmed in kernel to peers globally\n")
1760 {
1761 bm_wait_for_fib_set(!no);
1762
1763 return CMD_SUCCESS;
1764 }
1765
1766 DEFPY (bgp_suppress_fib_pending,
1767 bgp_suppress_fib_pending_cmd,
1768 "[no] bgp suppress-fib-pending",
1769 NO_STR
1770 BGP_STR
1771 "Advertise only routes that are programmed in kernel to peers\n")
1772 {
1773 VTY_DECLVAR_CONTEXT(bgp, bgp);
1774
1775 bgp_suppress_fib_pending_set(bgp, !no);
1776 return CMD_SUCCESS;
1777 }
1778
1779
1780 /* BGP Cluster ID. */
1781 DEFUN (bgp_cluster_id,
1782 bgp_cluster_id_cmd,
1783 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1784 BGP_STR
1785 "Configure Route-Reflector Cluster-id\n"
1786 "Route-Reflector Cluster-id in IP address format\n"
1787 "Route-Reflector Cluster-id as 32 bit quantity\n")
1788 {
1789 VTY_DECLVAR_CONTEXT(bgp, bgp);
1790 int idx_ipv4 = 2;
1791 int ret;
1792 struct in_addr cluster;
1793
1794 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1795 if (!ret) {
1796 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1797 return CMD_WARNING_CONFIG_FAILED;
1798 }
1799
1800 bgp_cluster_id_set(bgp, &cluster);
1801 bgp_clear_star_soft_out(vty, bgp->name);
1802
1803 return CMD_SUCCESS;
1804 }
1805
1806 DEFUN (no_bgp_cluster_id,
1807 no_bgp_cluster_id_cmd,
1808 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1809 NO_STR
1810 BGP_STR
1811 "Configure Route-Reflector Cluster-id\n"
1812 "Route-Reflector Cluster-id in IP address format\n"
1813 "Route-Reflector Cluster-id as 32 bit quantity\n")
1814 {
1815 VTY_DECLVAR_CONTEXT(bgp, bgp);
1816 bgp_cluster_id_unset(bgp);
1817 bgp_clear_star_soft_out(vty, bgp->name);
1818
1819 return CMD_SUCCESS;
1820 }
1821
1822 DEFPY (bgp_norib,
1823 bgp_norib_cmd,
1824 "bgp no-rib",
1825 BGP_STR
1826 "Disable BGP route installation to RIB (Zebra)\n")
1827 {
1828 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1829 vty_out(vty,
1830 "%% No-RIB option is already set, nothing to do here.\n");
1831 return CMD_SUCCESS;
1832 }
1833
1834 bgp_option_norib_set_runtime();
1835
1836 return CMD_SUCCESS;
1837 }
1838
1839 DEFPY (no_bgp_norib,
1840 no_bgp_norib_cmd,
1841 "no bgp no-rib",
1842 NO_STR
1843 BGP_STR
1844 "Disable BGP route installation to RIB (Zebra)\n")
1845 {
1846 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1847 vty_out(vty,
1848 "%% No-RIB option is not set, nothing to do here.\n");
1849 return CMD_SUCCESS;
1850 }
1851
1852 bgp_option_norib_unset_runtime();
1853
1854 return CMD_SUCCESS;
1855 }
1856
1857 DEFPY (no_bgp_send_extra_data,
1858 no_bgp_send_extra_data_cmd,
1859 "[no] bgp send-extra-data zebra",
1860 NO_STR
1861 BGP_STR
1862 "Extra data to Zebra for display/use\n"
1863 "To zebra\n")
1864 {
1865 if (no)
1866 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1867 else
1868 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1869
1870 return CMD_SUCCESS;
1871 }
1872
1873 DEFUN (bgp_confederation_identifier,
1874 bgp_confederation_identifier_cmd,
1875 "bgp confederation identifier (1-4294967295)",
1876 BGP_STR
1877 "AS confederation parameters\n"
1878 "AS number\n"
1879 "Set routing domain confederation AS\n")
1880 {
1881 VTY_DECLVAR_CONTEXT(bgp, bgp);
1882 int idx_number = 3;
1883 as_t as;
1884
1885 as = strtoul(argv[idx_number]->arg, NULL, 10);
1886
1887 bgp_confederation_id_set(bgp, as);
1888
1889 return CMD_SUCCESS;
1890 }
1891
1892 DEFUN (no_bgp_confederation_identifier,
1893 no_bgp_confederation_identifier_cmd,
1894 "no bgp confederation identifier [(1-4294967295)]",
1895 NO_STR
1896 BGP_STR
1897 "AS confederation parameters\n"
1898 "AS number\n"
1899 "Set routing domain confederation AS\n")
1900 {
1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902 bgp_confederation_id_unset(bgp);
1903
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (bgp_confederation_peers,
1908 bgp_confederation_peers_cmd,
1909 "bgp confederation peers (1-4294967295)...",
1910 BGP_STR
1911 "AS confederation parameters\n"
1912 "Peer ASs in BGP confederation\n"
1913 AS_STR)
1914 {
1915 VTY_DECLVAR_CONTEXT(bgp, bgp);
1916 int idx_asn = 3;
1917 as_t as;
1918 int i;
1919
1920 for (i = idx_asn; i < argc; i++) {
1921 as = strtoul(argv[i]->arg, NULL, 10);
1922
1923 if (bgp->as == as) {
1924 vty_out(vty,
1925 "%% Local member-AS not allowed in confed peer list\n");
1926 continue;
1927 }
1928
1929 bgp_confederation_peers_add(bgp, as);
1930 }
1931 return CMD_SUCCESS;
1932 }
1933
1934 DEFUN (no_bgp_confederation_peers,
1935 no_bgp_confederation_peers_cmd,
1936 "no bgp confederation peers (1-4294967295)...",
1937 NO_STR
1938 BGP_STR
1939 "AS confederation parameters\n"
1940 "Peer ASs in BGP confederation\n"
1941 AS_STR)
1942 {
1943 VTY_DECLVAR_CONTEXT(bgp, bgp);
1944 int idx_asn = 4;
1945 as_t as;
1946 int i;
1947
1948 for (i = idx_asn; i < argc; i++) {
1949 as = strtoul(argv[i]->arg, NULL, 10);
1950
1951 bgp_confederation_peers_remove(bgp, as);
1952 }
1953 return CMD_SUCCESS;
1954 }
1955
1956 /**
1957 * Central routine for maximum-paths configuration.
1958 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1959 * @set: 1 for setting values, 0 for removing the max-paths config.
1960 */
1961 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1962 const char *mpaths, uint16_t options,
1963 int set)
1964 {
1965 VTY_DECLVAR_CONTEXT(bgp, bgp);
1966 uint16_t maxpaths = 0;
1967 int ret;
1968 afi_t afi;
1969 safi_t safi;
1970
1971 afi = bgp_node_afi(vty);
1972 safi = bgp_node_safi(vty);
1973
1974 if (set) {
1975 maxpaths = strtol(mpaths, NULL, 10);
1976 if (maxpaths > multipath_num) {
1977 vty_out(vty,
1978 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1979 maxpaths, multipath_num);
1980 return CMD_WARNING_CONFIG_FAILED;
1981 }
1982 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1983 options);
1984 } else
1985 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1986
1987 if (ret < 0) {
1988 vty_out(vty,
1989 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1990 (set == 1) ? "" : "un",
1991 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1992 maxpaths, afi, safi);
1993 return CMD_WARNING_CONFIG_FAILED;
1994 }
1995
1996 bgp_recalculate_all_bestpaths(bgp);
1997
1998 return CMD_SUCCESS;
1999 }
2000
2001 DEFUN (bgp_maxmed_admin,
2002 bgp_maxmed_admin_cmd,
2003 "bgp max-med administrative ",
2004 BGP_STR
2005 "Advertise routes with max-med\n"
2006 "Administratively applied, for an indefinite period\n")
2007 {
2008 VTY_DECLVAR_CONTEXT(bgp, bgp);
2009
2010 bgp->v_maxmed_admin = 1;
2011 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2012
2013 bgp_maxmed_update(bgp);
2014
2015 return CMD_SUCCESS;
2016 }
2017
2018 DEFUN (bgp_maxmed_admin_medv,
2019 bgp_maxmed_admin_medv_cmd,
2020 "bgp max-med administrative (0-4294967295)",
2021 BGP_STR
2022 "Advertise routes with max-med\n"
2023 "Administratively applied, for an indefinite period\n"
2024 "Max MED value to be used\n")
2025 {
2026 VTY_DECLVAR_CONTEXT(bgp, bgp);
2027 int idx_number = 3;
2028
2029 bgp->v_maxmed_admin = 1;
2030 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2031
2032 bgp_maxmed_update(bgp);
2033
2034 return CMD_SUCCESS;
2035 }
2036
2037 DEFUN (no_bgp_maxmed_admin,
2038 no_bgp_maxmed_admin_cmd,
2039 "no bgp max-med administrative [(0-4294967295)]",
2040 NO_STR
2041 BGP_STR
2042 "Advertise routes with max-med\n"
2043 "Administratively applied, for an indefinite period\n"
2044 "Max MED value to be used\n")
2045 {
2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
2047 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2048 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2049 bgp_maxmed_update(bgp);
2050
2051 return CMD_SUCCESS;
2052 }
2053
2054 DEFUN (bgp_maxmed_onstartup,
2055 bgp_maxmed_onstartup_cmd,
2056 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2057 BGP_STR
2058 "Advertise routes with max-med\n"
2059 "Effective on a startup\n"
2060 "Time (seconds) period for max-med\n"
2061 "Max MED value to be used\n")
2062 {
2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
2064 int idx = 0;
2065
2066 if (argv_find(argv, argc, "(5-86400)", &idx))
2067 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2068 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2069 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2070 else
2071 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2072
2073 bgp_maxmed_update(bgp);
2074
2075 return CMD_SUCCESS;
2076 }
2077
2078 DEFUN (no_bgp_maxmed_onstartup,
2079 no_bgp_maxmed_onstartup_cmd,
2080 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2081 NO_STR
2082 BGP_STR
2083 "Advertise routes with max-med\n"
2084 "Effective on a startup\n"
2085 "Time (seconds) period for max-med\n"
2086 "Max MED value to be used\n")
2087 {
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
2090 /* Cancel max-med onstartup if its on */
2091 if (bgp->t_maxmed_onstartup) {
2092 THREAD_OFF(bgp->t_maxmed_onstartup);
2093 bgp->maxmed_onstartup_over = 1;
2094 }
2095
2096 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2097 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2098
2099 bgp_maxmed_update(bgp);
2100
2101 return CMD_SUCCESS;
2102 }
2103
2104 static int bgp_global_update_delay_config_vty(struct vty *vty,
2105 uint16_t update_delay,
2106 uint16_t establish_wait)
2107 {
2108 struct listnode *node, *nnode;
2109 struct bgp *bgp;
2110 bool vrf_cfg = false;
2111
2112 /*
2113 * See if update-delay is set per-vrf and warn user to delete it
2114 * Note that we only need to check this if this is the first time
2115 * setting the global config.
2116 */
2117 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2118 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2119 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2120 vty_out(vty,
2121 "%% update-delay configuration found in vrf %s\n",
2122 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2123 ? VRF_DEFAULT_NAME
2124 : bgp->name);
2125 vrf_cfg = true;
2126 }
2127 }
2128 }
2129
2130 if (vrf_cfg) {
2131 vty_out(vty,
2132 "%%Failed: global update-delay config not permitted\n");
2133 return CMD_WARNING;
2134 }
2135
2136 if (!establish_wait) { /* update-delay <delay> */
2137 bm->v_update_delay = update_delay;
2138 bm->v_establish_wait = bm->v_update_delay;
2139 } else {
2140 /* update-delay <delay> <establish-wait> */
2141 if (update_delay < establish_wait) {
2142 vty_out(vty,
2143 "%%Failed: update-delay less than the establish-wait!\n");
2144 return CMD_WARNING_CONFIG_FAILED;
2145 }
2146
2147 bm->v_update_delay = update_delay;
2148 bm->v_establish_wait = establish_wait;
2149 }
2150
2151 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2152 bgp->v_update_delay = bm->v_update_delay;
2153 bgp->v_establish_wait = bm->v_establish_wait;
2154 }
2155
2156 return CMD_SUCCESS;
2157 }
2158
2159 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2160 {
2161 struct listnode *node, *nnode;
2162 struct bgp *bgp;
2163
2164 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2165 bm->v_establish_wait = bm->v_update_delay;
2166
2167 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2168 bgp->v_update_delay = bm->v_update_delay;
2169 bgp->v_establish_wait = bm->v_establish_wait;
2170 }
2171
2172 return CMD_SUCCESS;
2173 }
2174
2175 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2176 uint16_t establish_wait)
2177 {
2178 VTY_DECLVAR_CONTEXT(bgp, bgp);
2179
2180 /* if configured globally, per-instance config is not allowed */
2181 if (bm->v_update_delay) {
2182 vty_out(vty,
2183 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2184 return CMD_WARNING_CONFIG_FAILED;
2185 }
2186
2187
2188 if (!establish_wait) /* update-delay <delay> */
2189 {
2190 bgp->v_update_delay = update_delay;
2191 bgp->v_establish_wait = bgp->v_update_delay;
2192 return CMD_SUCCESS;
2193 }
2194
2195 /* update-delay <delay> <establish-wait> */
2196 if (update_delay < establish_wait) {
2197 vty_out(vty,
2198 "%%Failed: update-delay less than the establish-wait!\n");
2199 return CMD_WARNING_CONFIG_FAILED;
2200 }
2201
2202 bgp->v_update_delay = update_delay;
2203 bgp->v_establish_wait = establish_wait;
2204
2205 return CMD_SUCCESS;
2206 }
2207
2208 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2209 {
2210 VTY_DECLVAR_CONTEXT(bgp, bgp);
2211
2212 /* If configured globally, cannot remove from one bgp instance */
2213 if (bm->v_update_delay) {
2214 vty_out(vty,
2215 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2216 return CMD_WARNING_CONFIG_FAILED;
2217 }
2218 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2219 bgp->v_establish_wait = bgp->v_update_delay;
2220
2221 return CMD_SUCCESS;
2222 }
2223
2224 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2225 {
2226 /* If configured globally, no need to display per-instance value */
2227 if (bgp->v_update_delay != bm->v_update_delay) {
2228 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2229 if (bgp->v_update_delay != bgp->v_establish_wait)
2230 vty_out(vty, " %d", bgp->v_establish_wait);
2231 vty_out(vty, "\n");
2232 }
2233 }
2234
2235 /* Global update-delay configuration */
2236 DEFPY (bgp_global_update_delay,
2237 bgp_global_update_delay_cmd,
2238 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2239 BGP_STR
2240 "Force initial delay for best-path and updates for all bgp instances\n"
2241 "Max delay in seconds\n"
2242 "Establish wait in seconds\n")
2243 {
2244 return bgp_global_update_delay_config_vty(vty, delay, wait);
2245 }
2246
2247 /* Global update-delay deconfiguration */
2248 DEFPY (no_bgp_global_update_delay,
2249 no_bgp_global_update_delay_cmd,
2250 "no bgp update-delay [(0-3600) [(1-3600)]]",
2251 NO_STR
2252 BGP_STR
2253 "Force initial delay for best-path and updates\n"
2254 "Max delay in seconds\n"
2255 "Establish wait in seconds\n")
2256 {
2257 return bgp_global_update_delay_deconfig_vty(vty);
2258 }
2259
2260 /* Update-delay configuration */
2261
2262 DEFPY (bgp_update_delay,
2263 bgp_update_delay_cmd,
2264 "update-delay (0-3600)$delay [(1-3600)$wait]",
2265 "Force initial delay for best-path and updates\n"
2266 "Max delay in seconds\n"
2267 "Establish wait in seconds\n")
2268 {
2269 return bgp_update_delay_config_vty(vty, delay, wait);
2270 }
2271
2272 /* Update-delay deconfiguration */
2273 DEFPY (no_bgp_update_delay,
2274 no_bgp_update_delay_cmd,
2275 "no update-delay [(0-3600) [(1-3600)]]",
2276 NO_STR
2277 "Force initial delay for best-path and updates\n"
2278 "Max delay in seconds\n"
2279 "Establish wait in seconds\n")
2280 {
2281 return bgp_update_delay_deconfig_vty(vty);
2282 }
2283
2284
2285 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2286 bool set)
2287 {
2288 VTY_DECLVAR_CONTEXT(bgp, bgp);
2289
2290 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2291 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2292
2293 return CMD_SUCCESS;
2294 }
2295
2296 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2297 bool set)
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300
2301 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2302 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2303
2304 return CMD_SUCCESS;
2305 }
2306
2307 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2308 {
2309 uint32_t quanta =
2310 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2311 if (quanta != BGP_WRITE_PACKET_MAX)
2312 vty_out(vty, " write-quanta %d\n", quanta);
2313 }
2314
2315 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2316 {
2317 uint32_t quanta =
2318 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2319 if (quanta != BGP_READ_PACKET_MAX)
2320 vty_out(vty, " read-quanta %d\n", quanta);
2321 }
2322
2323 /* Packet quanta configuration
2324 *
2325 * XXX: The value set here controls the size of a stack buffer in the IO
2326 * thread. When changing these limits be careful to prevent stack overflow.
2327 *
2328 * Furthermore, the maximums used here should correspond to
2329 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2330 */
2331 DEFPY (bgp_wpkt_quanta,
2332 bgp_wpkt_quanta_cmd,
2333 "[no] write-quanta (1-64)$quanta",
2334 NO_STR
2335 "How many packets to write to peer socket per run\n"
2336 "Number of packets\n")
2337 {
2338 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2339 }
2340
2341 DEFPY (bgp_rpkt_quanta,
2342 bgp_rpkt_quanta_cmd,
2343 "[no] read-quanta (1-10)$quanta",
2344 NO_STR
2345 "How many packets to read from peer socket per I/O cycle\n"
2346 "Number of packets\n")
2347 {
2348 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2349 }
2350
2351 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2352 {
2353 if (!bgp->heuristic_coalesce)
2354 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2355 }
2356
2357 /* BGP TCP keepalive */
2358 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2359 {
2360 if (bgp->tcp_keepalive_idle) {
2361 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2362 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2363 bgp->tcp_keepalive_probes);
2364 }
2365 }
2366
2367 DEFUN (bgp_coalesce_time,
2368 bgp_coalesce_time_cmd,
2369 "coalesce-time (0-4294967295)",
2370 "Subgroup coalesce timer\n"
2371 "Subgroup coalesce timer value (in ms)\n")
2372 {
2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
2374
2375 int idx = 0;
2376
2377 bgp->heuristic_coalesce = false;
2378
2379 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2380 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2381
2382 return CMD_SUCCESS;
2383 }
2384
2385 DEFUN (no_bgp_coalesce_time,
2386 no_bgp_coalesce_time_cmd,
2387 "no coalesce-time (0-4294967295)",
2388 NO_STR
2389 "Subgroup coalesce timer\n"
2390 "Subgroup coalesce timer value (in ms)\n")
2391 {
2392 VTY_DECLVAR_CONTEXT(bgp, bgp);
2393
2394 bgp->heuristic_coalesce = true;
2395 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2396 return CMD_SUCCESS;
2397 }
2398
2399 /* Maximum-paths configuration */
2400 DEFUN (bgp_maxpaths,
2401 bgp_maxpaths_cmd,
2402 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2403 "Forward packets over multiple paths\n"
2404 "Number of paths\n")
2405 {
2406 int idx_number = 1;
2407 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2408 argv[idx_number]->arg, 0, 1);
2409 }
2410
2411 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2412 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2413 "Forward packets over multiple paths\n"
2414 "Number of paths\n")
2415
2416 DEFUN (bgp_maxpaths_ibgp,
2417 bgp_maxpaths_ibgp_cmd,
2418 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2419 "Forward packets over multiple paths\n"
2420 "iBGP-multipath\n"
2421 "Number of paths\n")
2422 {
2423 int idx_number = 2;
2424 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2425 argv[idx_number]->arg, 0, 1);
2426 }
2427
2428 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2429 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2430 "Forward packets over multiple paths\n"
2431 "iBGP-multipath\n"
2432 "Number of paths\n")
2433
2434 DEFUN (bgp_maxpaths_ibgp_cluster,
2435 bgp_maxpaths_ibgp_cluster_cmd,
2436 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2437 "Forward packets over multiple paths\n"
2438 "iBGP-multipath\n"
2439 "Number of paths\n"
2440 "Match the cluster length\n")
2441 {
2442 int idx_number = 2;
2443 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2444 argv[idx_number]->arg, true, 1);
2445 }
2446
2447 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2448 "maximum-paths ibgp " CMD_RANGE_STR(
2449 1, MULTIPATH_NUM) " equal-cluster-length",
2450 "Forward packets over multiple paths\n"
2451 "iBGP-multipath\n"
2452 "Number of paths\n"
2453 "Match the cluster length\n")
2454
2455 DEFUN (no_bgp_maxpaths,
2456 no_bgp_maxpaths_cmd,
2457 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2458 NO_STR
2459 "Forward packets over multiple paths\n"
2460 "Number of paths\n")
2461 {
2462 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2463 }
2464
2465 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2466 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2467 "Forward packets over multiple paths\n"
2468 "Number of paths\n")
2469
2470 DEFUN (no_bgp_maxpaths_ibgp,
2471 no_bgp_maxpaths_ibgp_cmd,
2472 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2473 NO_STR
2474 "Forward packets over multiple paths\n"
2475 "iBGP-multipath\n"
2476 "Number of paths\n"
2477 "Match the cluster length\n")
2478 {
2479 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2480 }
2481
2482 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2483 "no maximum-paths ibgp [" CMD_RANGE_STR(
2484 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2485 NO_STR
2486 "Forward packets over multiple paths\n"
2487 "iBGP-multipath\n"
2488 "Number of paths\n"
2489 "Match the cluster length\n")
2490
2491 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2492 afi_t afi, safi_t safi)
2493 {
2494 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2495 vty_out(vty, " maximum-paths %d\n",
2496 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2497 }
2498
2499 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2500 vty_out(vty, " maximum-paths ibgp %d",
2501 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2502 if (bgp->maxpaths[afi][safi].same_clusterlen)
2503 vty_out(vty, " equal-cluster-length");
2504 vty_out(vty, "\n");
2505 }
2506 }
2507
2508 /* BGP timers. */
2509
2510 DEFUN (bgp_timers,
2511 bgp_timers_cmd,
2512 "timers bgp (0-65535) (0-65535)",
2513 "Adjust routing timers\n"
2514 "BGP timers\n"
2515 "Keepalive interval\n"
2516 "Holdtime\n")
2517 {
2518 VTY_DECLVAR_CONTEXT(bgp, bgp);
2519 int idx_number = 2;
2520 int idx_number_2 = 3;
2521 unsigned long keepalive = 0;
2522 unsigned long holdtime = 0;
2523
2524 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2525 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2526
2527 /* Holdtime value check. */
2528 if (holdtime < 3 && holdtime != 0) {
2529 vty_out(vty,
2530 "%% hold time value must be either 0 or greater than 3\n");
2531 return CMD_WARNING_CONFIG_FAILED;
2532 }
2533
2534 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2535 BGP_DEFAULT_DELAYOPEN);
2536
2537 return CMD_SUCCESS;
2538 }
2539
2540 DEFUN (no_bgp_timers,
2541 no_bgp_timers_cmd,
2542 "no timers bgp [(0-65535) (0-65535)]",
2543 NO_STR
2544 "Adjust routing timers\n"
2545 "BGP timers\n"
2546 "Keepalive interval\n"
2547 "Holdtime\n")
2548 {
2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
2550 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2551 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2552
2553 return CMD_SUCCESS;
2554 }
2555
2556 /* BGP minimum holdtime. */
2557
2558 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2559 "bgp minimum-holdtime (1-65535)",
2560 "BGP specific commands\n"
2561 "BGP minimum holdtime\n"
2562 "Seconds\n")
2563 {
2564 VTY_DECLVAR_CONTEXT(bgp, bgp);
2565 int idx_number = 2;
2566 unsigned long min_holdtime;
2567
2568 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2569
2570 bgp->default_min_holdtime = min_holdtime;
2571
2572 return CMD_SUCCESS;
2573 }
2574
2575 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2576 "no bgp minimum-holdtime [(1-65535)]",
2577 NO_STR
2578 "BGP specific commands\n"
2579 "BGP minimum holdtime\n"
2580 "Seconds\n")
2581 {
2582 VTY_DECLVAR_CONTEXT(bgp, bgp);
2583
2584 bgp->default_min_holdtime = 0;
2585
2586 return CMD_SUCCESS;
2587 }
2588
2589 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2590 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2591 BGP_STR
2592 "TCP keepalive parameters\n"
2593 "TCP keepalive idle time (seconds)\n"
2594 "TCP keepalive interval (seconds)\n"
2595 "TCP keepalive maximum probes\n")
2596 {
2597 VTY_DECLVAR_CONTEXT(bgp, bgp);
2598
2599 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2600 (uint16_t)probes);
2601
2602 return CMD_SUCCESS;
2603 }
2604
2605 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2606 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2607 NO_STR
2608 BGP_STR
2609 "TCP keepalive parameters\n"
2610 "TCP keepalive idle time (seconds)\n"
2611 "TCP keepalive interval (seconds)\n"
2612 "TCP keepalive maximum probes\n")
2613 {
2614 VTY_DECLVAR_CONTEXT(bgp, bgp);
2615
2616 bgp_tcp_keepalive_unset(bgp);
2617
2618 return CMD_SUCCESS;
2619 }
2620
2621 DEFUN (bgp_client_to_client_reflection,
2622 bgp_client_to_client_reflection_cmd,
2623 "bgp client-to-client reflection",
2624 BGP_STR
2625 "Configure client to client route reflection\n"
2626 "reflection of routes allowed\n")
2627 {
2628 VTY_DECLVAR_CONTEXT(bgp, bgp);
2629 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2630 bgp_clear_star_soft_out(vty, bgp->name);
2631
2632 return CMD_SUCCESS;
2633 }
2634
2635 DEFUN (no_bgp_client_to_client_reflection,
2636 no_bgp_client_to_client_reflection_cmd,
2637 "no bgp client-to-client reflection",
2638 NO_STR
2639 BGP_STR
2640 "Configure client to client route reflection\n"
2641 "reflection of routes allowed\n")
2642 {
2643 VTY_DECLVAR_CONTEXT(bgp, bgp);
2644 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2645 bgp_clear_star_soft_out(vty, bgp->name);
2646
2647 return CMD_SUCCESS;
2648 }
2649
2650 /* "bgp always-compare-med" configuration. */
2651 DEFUN (bgp_always_compare_med,
2652 bgp_always_compare_med_cmd,
2653 "bgp always-compare-med",
2654 BGP_STR
2655 "Allow comparing MED from different neighbors\n")
2656 {
2657 VTY_DECLVAR_CONTEXT(bgp, bgp);
2658 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2659 bgp_recalculate_all_bestpaths(bgp);
2660
2661 return CMD_SUCCESS;
2662 }
2663
2664 DEFUN (no_bgp_always_compare_med,
2665 no_bgp_always_compare_med_cmd,
2666 "no bgp always-compare-med",
2667 NO_STR
2668 BGP_STR
2669 "Allow comparing MED from different neighbors\n")
2670 {
2671 VTY_DECLVAR_CONTEXT(bgp, bgp);
2672 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2673 bgp_recalculate_all_bestpaths(bgp);
2674
2675 return CMD_SUCCESS;
2676 }
2677
2678
2679 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2680 "bgp ebgp-requires-policy",
2681 BGP_STR
2682 "Require in and out policy for eBGP peers (RFC8212)\n")
2683 {
2684 VTY_DECLVAR_CONTEXT(bgp, bgp);
2685 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2686 return CMD_SUCCESS;
2687 }
2688
2689 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2690 "no bgp ebgp-requires-policy",
2691 NO_STR
2692 BGP_STR
2693 "Require in and out policy for eBGP peers (RFC8212)\n")
2694 {
2695 VTY_DECLVAR_CONTEXT(bgp, bgp);
2696 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2697 return CMD_SUCCESS;
2698 }
2699
2700 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2701 "bgp suppress-duplicates",
2702 BGP_STR
2703 "Suppress duplicate updates if the route actually not changed\n")
2704 {
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2707 return CMD_SUCCESS;
2708 }
2709
2710 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2711 "no bgp suppress-duplicates",
2712 NO_STR
2713 BGP_STR
2714 "Suppress duplicate updates if the route actually not changed\n")
2715 {
2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
2717 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2718 return CMD_SUCCESS;
2719 }
2720
2721 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2722 "bgp reject-as-sets",
2723 BGP_STR
2724 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2725 {
2726 VTY_DECLVAR_CONTEXT(bgp, bgp);
2727 struct listnode *node, *nnode;
2728 struct peer *peer;
2729
2730 bgp->reject_as_sets = true;
2731
2732 /* Reset existing BGP sessions to reject routes
2733 * with aspath containing AS_SET or AS_CONFED_SET.
2734 */
2735 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2736 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2737 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2738 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2739 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2740 }
2741 }
2742
2743 return CMD_SUCCESS;
2744 }
2745
2746 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2747 "no bgp reject-as-sets",
2748 NO_STR
2749 BGP_STR
2750 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2751 {
2752 VTY_DECLVAR_CONTEXT(bgp, bgp);
2753 struct listnode *node, *nnode;
2754 struct peer *peer;
2755
2756 bgp->reject_as_sets = false;
2757
2758 /* Reset existing BGP sessions to reject routes
2759 * with aspath containing AS_SET or AS_CONFED_SET.
2760 */
2761 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2762 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2763 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2764 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2765 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2766 }
2767 }
2768
2769 return CMD_SUCCESS;
2770 }
2771
2772 /* "bgp deterministic-med" configuration. */
2773 DEFUN (bgp_deterministic_med,
2774 bgp_deterministic_med_cmd,
2775 "bgp deterministic-med",
2776 BGP_STR
2777 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2778 {
2779 VTY_DECLVAR_CONTEXT(bgp, bgp);
2780
2781 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2782 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2783 bgp_recalculate_all_bestpaths(bgp);
2784 }
2785
2786 return CMD_SUCCESS;
2787 }
2788
2789 DEFUN (no_bgp_deterministic_med,
2790 no_bgp_deterministic_med_cmd,
2791 "no bgp deterministic-med",
2792 NO_STR
2793 BGP_STR
2794 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2795 {
2796 VTY_DECLVAR_CONTEXT(bgp, bgp);
2797 int bestpath_per_as_used;
2798 afi_t afi;
2799 safi_t safi;
2800 struct peer *peer;
2801 struct listnode *node, *nnode;
2802
2803 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2804 bestpath_per_as_used = 0;
2805
2806 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2807 FOREACH_AFI_SAFI (afi, safi)
2808 if (bgp_addpath_dmed_required(
2809 peer->addpath_type[afi][safi])) {
2810 bestpath_per_as_used = 1;
2811 break;
2812 }
2813
2814 if (bestpath_per_as_used)
2815 break;
2816 }
2817
2818 if (bestpath_per_as_used) {
2819 vty_out(vty,
2820 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2821 return CMD_WARNING_CONFIG_FAILED;
2822 } else {
2823 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2824 bgp_recalculate_all_bestpaths(bgp);
2825 }
2826 }
2827
2828 return CMD_SUCCESS;
2829 }
2830
2831 /* "bgp graceful-restart mode" configuration. */
2832 DEFUN (bgp_graceful_restart,
2833 bgp_graceful_restart_cmd,
2834 "bgp graceful-restart",
2835 BGP_STR
2836 GR_CMD
2837 )
2838 {
2839 int ret = BGP_GR_FAILURE;
2840
2841 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2842 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2843
2844 VTY_DECLVAR_CONTEXT(bgp, bgp);
2845
2846 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2847
2848 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2849 ret);
2850
2851 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2852 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2853 vty_out(vty,
2854 "Graceful restart configuration changed, reset all peers to take effect\n");
2855 return bgp_vty_return(vty, ret);
2856 }
2857
2858 DEFUN (no_bgp_graceful_restart,
2859 no_bgp_graceful_restart_cmd,
2860 "no bgp graceful-restart",
2861 NO_STR
2862 BGP_STR
2863 NO_GR_CMD
2864 )
2865 {
2866 VTY_DECLVAR_CONTEXT(bgp, bgp);
2867
2868 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2869 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2870
2871 int ret = BGP_GR_FAILURE;
2872
2873 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2874
2875 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2876 ret);
2877
2878 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2879 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2880 vty_out(vty,
2881 "Graceful restart configuration changed, reset all peers to take effect\n");
2882
2883 return bgp_vty_return(vty, ret);
2884 }
2885
2886 DEFUN (bgp_graceful_restart_stalepath_time,
2887 bgp_graceful_restart_stalepath_time_cmd,
2888 "bgp graceful-restart stalepath-time (1-4095)",
2889 BGP_STR
2890 "Graceful restart capability parameters\n"
2891 "Set the max time to hold onto restarting peer's stale paths\n"
2892 "Delay value (seconds)\n")
2893 {
2894 VTY_DECLVAR_CONTEXT(bgp, bgp);
2895 int idx_number = 3;
2896 uint32_t stalepath;
2897
2898 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2899 bgp->stalepath_time = stalepath;
2900 return CMD_SUCCESS;
2901 }
2902
2903 DEFUN (bgp_graceful_restart_restart_time,
2904 bgp_graceful_restart_restart_time_cmd,
2905 "bgp graceful-restart restart-time (0-4095)",
2906 BGP_STR
2907 "Graceful restart capability parameters\n"
2908 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2909 "Delay value (seconds)\n")
2910 {
2911 VTY_DECLVAR_CONTEXT(bgp, bgp);
2912 int idx_number = 3;
2913 uint32_t restart;
2914
2915 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2916 bgp->restart_time = restart;
2917 return CMD_SUCCESS;
2918 }
2919
2920 DEFUN (bgp_graceful_restart_select_defer_time,
2921 bgp_graceful_restart_select_defer_time_cmd,
2922 "bgp graceful-restart select-defer-time (0-3600)",
2923 BGP_STR
2924 "Graceful restart capability parameters\n"
2925 "Set the time to defer the BGP route selection after restart\n"
2926 "Delay value (seconds, 0 - disable)\n")
2927 {
2928 VTY_DECLVAR_CONTEXT(bgp, bgp);
2929 int idx_number = 3;
2930 uint32_t defer_time;
2931
2932 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2933 bgp->select_defer_time = defer_time;
2934 if (defer_time == 0)
2935 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2936 else
2937 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2938
2939 return CMD_SUCCESS;
2940 }
2941
2942 DEFUN (no_bgp_graceful_restart_stalepath_time,
2943 no_bgp_graceful_restart_stalepath_time_cmd,
2944 "no bgp graceful-restart stalepath-time [(1-4095)]",
2945 NO_STR
2946 BGP_STR
2947 "Graceful restart capability parameters\n"
2948 "Set the max time to hold onto restarting peer's stale paths\n"
2949 "Delay value (seconds)\n")
2950 {
2951 VTY_DECLVAR_CONTEXT(bgp, bgp);
2952
2953 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2954 return CMD_SUCCESS;
2955 }
2956
2957 DEFUN (no_bgp_graceful_restart_restart_time,
2958 no_bgp_graceful_restart_restart_time_cmd,
2959 "no bgp graceful-restart restart-time [(0-4095)]",
2960 NO_STR
2961 BGP_STR
2962 "Graceful restart capability parameters\n"
2963 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2964 "Delay value (seconds)\n")
2965 {
2966 VTY_DECLVAR_CONTEXT(bgp, bgp);
2967
2968 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2969 return CMD_SUCCESS;
2970 }
2971
2972 DEFUN (no_bgp_graceful_restart_select_defer_time,
2973 no_bgp_graceful_restart_select_defer_time_cmd,
2974 "no bgp graceful-restart select-defer-time [(0-3600)]",
2975 NO_STR
2976 BGP_STR
2977 "Graceful restart capability parameters\n"
2978 "Set the time to defer the BGP route selection after restart\n"
2979 "Delay value (seconds)\n")
2980 {
2981 VTY_DECLVAR_CONTEXT(bgp, bgp);
2982
2983 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2984 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2985
2986 return CMD_SUCCESS;
2987 }
2988
2989 DEFUN (bgp_graceful_restart_preserve_fw,
2990 bgp_graceful_restart_preserve_fw_cmd,
2991 "bgp graceful-restart preserve-fw-state",
2992 BGP_STR
2993 "Graceful restart capability parameters\n"
2994 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2995 {
2996 VTY_DECLVAR_CONTEXT(bgp, bgp);
2997 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2998 return CMD_SUCCESS;
2999 }
3000
3001 DEFUN (no_bgp_graceful_restart_preserve_fw,
3002 no_bgp_graceful_restart_preserve_fw_cmd,
3003 "no bgp graceful-restart preserve-fw-state",
3004 NO_STR
3005 BGP_STR
3006 "Graceful restart capability parameters\n"
3007 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3008 {
3009 VTY_DECLVAR_CONTEXT(bgp, bgp);
3010 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3011 return CMD_SUCCESS;
3012 }
3013
3014 DEFPY (bgp_graceful_restart_notification,
3015 bgp_graceful_restart_notification_cmd,
3016 "[no$no] bgp graceful-restart notification",
3017 NO_STR
3018 BGP_STR
3019 "Graceful restart capability parameters\n"
3020 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3021 {
3022 VTY_DECLVAR_CONTEXT(bgp, bgp);
3023
3024 if (no)
3025 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3026 else
3027 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3028
3029 return CMD_SUCCESS;
3030 }
3031
3032 DEFPY (bgp_administrative_reset,
3033 bgp_administrative_reset_cmd,
3034 "[no$no] bgp hard-administrative-reset",
3035 NO_STR
3036 BGP_STR
3037 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3038 {
3039 VTY_DECLVAR_CONTEXT(bgp, bgp);
3040
3041 if (no)
3042 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3043 else
3044 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3045
3046 return CMD_SUCCESS;
3047 }
3048
3049 DEFUN (bgp_graceful_restart_disable,
3050 bgp_graceful_restart_disable_cmd,
3051 "bgp graceful-restart-disable",
3052 BGP_STR
3053 GR_DISABLE)
3054 {
3055 int ret = BGP_GR_FAILURE;
3056
3057 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3058 zlog_debug(
3059 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3060
3061 VTY_DECLVAR_CONTEXT(bgp, bgp);
3062
3063 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3064
3065 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3066 bgp->peer, ret);
3067
3068 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3069 zlog_debug(
3070 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3071 vty_out(vty,
3072 "Graceful restart configuration changed, reset all peers to take effect\n");
3073
3074 return bgp_vty_return(vty, ret);
3075 }
3076
3077 DEFUN (no_bgp_graceful_restart_disable,
3078 no_bgp_graceful_restart_disable_cmd,
3079 "no bgp graceful-restart-disable",
3080 NO_STR
3081 BGP_STR
3082 NO_GR_DISABLE
3083 )
3084 {
3085 VTY_DECLVAR_CONTEXT(bgp, bgp);
3086
3087 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3088 zlog_debug(
3089 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3090
3091 int ret = BGP_GR_FAILURE;
3092
3093 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3094
3095 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3096 ret);
3097
3098 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3099 zlog_debug(
3100 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3101 vty_out(vty,
3102 "Graceful restart configuration changed, reset all peers to take effect\n");
3103
3104 return bgp_vty_return(vty, ret);
3105 }
3106
3107 DEFUN (bgp_neighbor_graceful_restart_set,
3108 bgp_neighbor_graceful_restart_set_cmd,
3109 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3110 NEIGHBOR_STR
3111 NEIGHBOR_ADDR_STR2
3112 GR_NEIGHBOR_CMD
3113 )
3114 {
3115 int idx_peer = 1;
3116 struct peer *peer;
3117 int ret = BGP_GR_FAILURE;
3118
3119 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3120
3121 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3122 zlog_debug(
3123 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3124
3125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3126 if (!peer)
3127 return CMD_WARNING_CONFIG_FAILED;
3128
3129 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3130
3131 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3132 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3133
3134 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3135 zlog_debug(
3136 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3137 vty_out(vty,
3138 "Graceful restart configuration changed, reset this peer to take effect\n");
3139
3140 return bgp_vty_return(vty, ret);
3141 }
3142
3143 DEFUN (no_bgp_neighbor_graceful_restart,
3144 no_bgp_neighbor_graceful_restart_set_cmd,
3145 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3146 NO_STR
3147 NEIGHBOR_STR
3148 NEIGHBOR_ADDR_STR2
3149 NO_GR_NEIGHBOR_CMD
3150 )
3151 {
3152 int idx_peer = 2;
3153 int ret = BGP_GR_FAILURE;
3154 struct peer *peer;
3155
3156 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3157
3158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
3161
3162 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3163 zlog_debug(
3164 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3165
3166 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3167
3168 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3169 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3170
3171 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3172 zlog_debug(
3173 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3174 vty_out(vty,
3175 "Graceful restart configuration changed, reset this peer to take effect\n");
3176
3177 return bgp_vty_return(vty, ret);
3178 }
3179
3180 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3181 bgp_neighbor_graceful_restart_helper_set_cmd,
3182 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3183 NEIGHBOR_STR
3184 NEIGHBOR_ADDR_STR2
3185 GR_NEIGHBOR_HELPER_CMD
3186 )
3187 {
3188 int idx_peer = 1;
3189 struct peer *peer;
3190 int ret = BGP_GR_FAILURE;
3191
3192 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3193
3194 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3195 zlog_debug(
3196 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3197
3198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3199
3200 if (!peer)
3201 return CMD_WARNING_CONFIG_FAILED;
3202
3203
3204 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3205
3206 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3207 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3208
3209 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3210 zlog_debug(
3211 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3212 vty_out(vty,
3213 "Graceful restart configuration changed, reset this peer to take effect\n");
3214
3215 return bgp_vty_return(vty, ret);
3216 }
3217
3218 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3219 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3220 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3221 NO_STR
3222 NEIGHBOR_STR
3223 NEIGHBOR_ADDR_STR2
3224 NO_GR_NEIGHBOR_HELPER_CMD
3225 )
3226 {
3227 int idx_peer = 2;
3228 int ret = BGP_GR_FAILURE;
3229 struct peer *peer;
3230
3231 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3232
3233 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3234 if (!peer)
3235 return CMD_WARNING_CONFIG_FAILED;
3236
3237 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3238 zlog_debug(
3239 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3240
3241 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3242
3243 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3244 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3245
3246 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3247 zlog_debug(
3248 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3249 vty_out(vty,
3250 "Graceful restart configuration changed, reset this peer to take effect\n");
3251
3252 return bgp_vty_return(vty, ret);
3253 }
3254
3255 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3256 bgp_neighbor_graceful_restart_disable_set_cmd,
3257 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3258 NEIGHBOR_STR
3259 NEIGHBOR_ADDR_STR2
3260 GR_NEIGHBOR_DISABLE_CMD
3261 )
3262 {
3263 int idx_peer = 1;
3264 struct peer *peer;
3265 int ret = BGP_GR_FAILURE;
3266
3267 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3268
3269 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3270 zlog_debug(
3271 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3272
3273 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3274 if (!peer)
3275 return CMD_WARNING_CONFIG_FAILED;
3276
3277 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3278
3279 if (peer->bgp->t_startup)
3280 bgp_peer_gr_flags_update(peer);
3281
3282 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3283 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3284
3285 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3286 zlog_debug(
3287 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3288 vty_out(vty,
3289 "Graceful restart configuration changed, reset this peer to take effect\n");
3290
3291 return bgp_vty_return(vty, ret);
3292 }
3293
3294 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3295 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3296 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3297 NO_STR
3298 NEIGHBOR_STR
3299 NEIGHBOR_ADDR_STR2
3300 NO_GR_NEIGHBOR_DISABLE_CMD
3301 )
3302 {
3303 int idx_peer = 2;
3304 int ret = BGP_GR_FAILURE;
3305 struct peer *peer;
3306
3307 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3308
3309 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3310 if (!peer)
3311 return CMD_WARNING_CONFIG_FAILED;
3312
3313 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3314 zlog_debug(
3315 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3316
3317 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3318
3319 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3320 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3321
3322 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3323 zlog_debug(
3324 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3325 vty_out(vty,
3326 "Graceful restart configuration changed, reset this peer to take effect\n");
3327
3328 return bgp_vty_return(vty, ret);
3329 }
3330
3331 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3332 bgp_graceful_restart_disable_eor_cmd,
3333 "bgp graceful-restart disable-eor",
3334 BGP_STR
3335 "Graceful restart configuration parameters\n"
3336 "Disable EOR Check\n")
3337 {
3338 VTY_DECLVAR_CONTEXT(bgp, bgp);
3339 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3340
3341 return CMD_SUCCESS;
3342 }
3343
3344 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3345 no_bgp_graceful_restart_disable_eor_cmd,
3346 "no bgp graceful-restart disable-eor",
3347 NO_STR
3348 BGP_STR
3349 "Graceful restart configuration parameters\n"
3350 "Disable EOR Check\n")
3351 {
3352 VTY_DECLVAR_CONTEXT(bgp, bgp);
3353 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3354
3355 return CMD_SUCCESS;
3356 }
3357
3358 DEFUN (bgp_graceful_restart_rib_stale_time,
3359 bgp_graceful_restart_rib_stale_time_cmd,
3360 "bgp graceful-restart rib-stale-time (1-3600)",
3361 BGP_STR
3362 "Graceful restart configuration parameters\n"
3363 "Specify the stale route removal timer in rib\n"
3364 "Delay value (seconds)\n")
3365 {
3366 VTY_DECLVAR_CONTEXT(bgp, bgp);
3367 int idx_number = 3;
3368 uint32_t stale_time;
3369
3370 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3371 bgp->rib_stale_time = stale_time;
3372 /* Send the stale timer update message to RIB */
3373 if (bgp_zebra_stale_timer_update(bgp))
3374 return CMD_WARNING;
3375
3376 return CMD_SUCCESS;
3377 }
3378
3379 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3380 no_bgp_graceful_restart_rib_stale_time_cmd,
3381 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3382 NO_STR
3383 BGP_STR
3384 "Graceful restart configuration parameters\n"
3385 "Specify the stale route removal timer in rib\n"
3386 "Delay value (seconds)\n")
3387 {
3388 VTY_DECLVAR_CONTEXT(bgp, bgp);
3389
3390 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3391 /* Send the stale timer update message to RIB */
3392 if (bgp_zebra_stale_timer_update(bgp))
3393 return CMD_WARNING;
3394
3395 return CMD_SUCCESS;
3396 }
3397
3398 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3399 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3400 BGP_STR
3401 "Enable Long-lived Graceful Restart\n"
3402 "Specifies maximum time to wait before purging long-lived stale routes\n"
3403 "Stale time value (seconds)\n")
3404 {
3405 VTY_DECLVAR_CONTEXT(bgp, bgp);
3406
3407 uint32_t llgr_stale_time;
3408
3409 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3410 bgp->llgr_stale_time = llgr_stale_time;
3411
3412 return CMD_SUCCESS;
3413 }
3414
3415 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3416 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3417 NO_STR BGP_STR
3418 "Enable Long-lived Graceful Restart\n"
3419 "Specifies maximum time to wait before purging long-lived stale routes\n"
3420 "Stale time value (seconds)\n")
3421 {
3422 VTY_DECLVAR_CONTEXT(bgp, bgp);
3423
3424 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3425
3426 return CMD_SUCCESS;
3427 }
3428
3429 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3430 struct bgp *bgp)
3431 {
3432 bgp_static_redo_import_check(bgp);
3433 bgp_redistribute_redo(bgp);
3434 bgp_clear_star_soft_out(vty, bgp->name);
3435 bgp_clear_star_soft_in(vty, bgp->name);
3436 }
3437
3438 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3439 {
3440 struct listnode *node, *nnode;
3441 struct bgp *bgp;
3442 bool vrf_cfg = false;
3443
3444 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3445 return CMD_SUCCESS;
3446
3447 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3448 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3449 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3450 vty_out(vty,
3451 "%% graceful-shutdown configuration found in vrf %s\n",
3452 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3453 VRF_DEFAULT_NAME : bgp->name);
3454 vrf_cfg = true;
3455 }
3456 }
3457
3458 if (vrf_cfg) {
3459 vty_out(vty,
3460 "%%Failed: global graceful-shutdown not permitted\n");
3461 return CMD_WARNING;
3462 }
3463
3464 /* Set flag globally */
3465 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3466
3467 /* Initiate processing for all BGP instances. */
3468 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3469 bgp_initiate_graceful_shut_unshut(vty, bgp);
3470
3471 return CMD_SUCCESS;
3472 }
3473
3474 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3475 {
3476 struct listnode *node, *nnode;
3477 struct bgp *bgp;
3478
3479 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3480 return CMD_SUCCESS;
3481
3482 /* Unset flag globally */
3483 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3484
3485 /* Initiate processing for all BGP instances. */
3486 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3487 bgp_initiate_graceful_shut_unshut(vty, bgp);
3488
3489 return CMD_SUCCESS;
3490 }
3491
3492 /* "bgp graceful-shutdown" configuration */
3493 DEFUN (bgp_graceful_shutdown,
3494 bgp_graceful_shutdown_cmd,
3495 "bgp graceful-shutdown",
3496 BGP_STR
3497 "Graceful shutdown parameters\n")
3498 {
3499 if (vty->node == CONFIG_NODE)
3500 return bgp_global_graceful_shutdown_config_vty(vty);
3501
3502 VTY_DECLVAR_CONTEXT(bgp, bgp);
3503
3504 /* if configured globally, per-instance config is not allowed */
3505 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3506 vty_out(vty,
3507 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3508 return CMD_WARNING_CONFIG_FAILED;
3509 }
3510
3511 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3512 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3513 bgp_initiate_graceful_shut_unshut(vty, bgp);
3514 }
3515
3516 return CMD_SUCCESS;
3517 }
3518
3519 DEFUN (no_bgp_graceful_shutdown,
3520 no_bgp_graceful_shutdown_cmd,
3521 "no bgp graceful-shutdown",
3522 NO_STR
3523 BGP_STR
3524 "Graceful shutdown parameters\n")
3525 {
3526 if (vty->node == CONFIG_NODE)
3527 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3528
3529 VTY_DECLVAR_CONTEXT(bgp, bgp);
3530
3531 /* If configured globally, cannot remove from one bgp instance */
3532 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3533 vty_out(vty,
3534 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3535 return CMD_WARNING_CONFIG_FAILED;
3536 }
3537
3538 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3539 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3540 bgp_initiate_graceful_shut_unshut(vty, bgp);
3541 }
3542
3543 return CMD_SUCCESS;
3544 }
3545
3546 /* "bgp fast-external-failover" configuration. */
3547 DEFUN (bgp_fast_external_failover,
3548 bgp_fast_external_failover_cmd,
3549 "bgp fast-external-failover",
3550 BGP_STR
3551 "Immediately reset session if a link to a directly connected external peer goes down\n")
3552 {
3553 VTY_DECLVAR_CONTEXT(bgp, bgp);
3554 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3555 return CMD_SUCCESS;
3556 }
3557
3558 DEFUN (no_bgp_fast_external_failover,
3559 no_bgp_fast_external_failover_cmd,
3560 "no bgp fast-external-failover",
3561 NO_STR
3562 BGP_STR
3563 "Immediately reset session if a link to a directly connected external peer goes down\n")
3564 {
3565 VTY_DECLVAR_CONTEXT(bgp, bgp);
3566 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3567 return CMD_SUCCESS;
3568 }
3569
3570 /* "bgp bestpath compare-routerid" configuration. */
3571 DEFUN (bgp_bestpath_compare_router_id,
3572 bgp_bestpath_compare_router_id_cmd,
3573 "bgp bestpath compare-routerid",
3574 BGP_STR
3575 "Change the default bestpath selection\n"
3576 "Compare router-id for identical EBGP paths\n")
3577 {
3578 VTY_DECLVAR_CONTEXT(bgp, bgp);
3579 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3580 bgp_recalculate_all_bestpaths(bgp);
3581
3582 return CMD_SUCCESS;
3583 }
3584
3585 DEFUN (no_bgp_bestpath_compare_router_id,
3586 no_bgp_bestpath_compare_router_id_cmd,
3587 "no bgp bestpath compare-routerid",
3588 NO_STR
3589 BGP_STR
3590 "Change the default bestpath selection\n"
3591 "Compare router-id for identical EBGP paths\n")
3592 {
3593 VTY_DECLVAR_CONTEXT(bgp, bgp);
3594 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3595 bgp_recalculate_all_bestpaths(bgp);
3596
3597 return CMD_SUCCESS;
3598 }
3599
3600 /* "bgp bestpath as-path ignore" configuration. */
3601 DEFUN (bgp_bestpath_aspath_ignore,
3602 bgp_bestpath_aspath_ignore_cmd,
3603 "bgp bestpath as-path ignore",
3604 BGP_STR
3605 "Change the default bestpath selection\n"
3606 "AS-path attribute\n"
3607 "Ignore as-path length in selecting a route\n")
3608 {
3609 VTY_DECLVAR_CONTEXT(bgp, bgp);
3610 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3611 bgp_recalculate_all_bestpaths(bgp);
3612
3613 return CMD_SUCCESS;
3614 }
3615
3616 DEFUN (no_bgp_bestpath_aspath_ignore,
3617 no_bgp_bestpath_aspath_ignore_cmd,
3618 "no bgp bestpath as-path ignore",
3619 NO_STR
3620 BGP_STR
3621 "Change the default bestpath selection\n"
3622 "AS-path attribute\n"
3623 "Ignore as-path length in selecting a route\n")
3624 {
3625 VTY_DECLVAR_CONTEXT(bgp, bgp);
3626 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3627 bgp_recalculate_all_bestpaths(bgp);
3628
3629 return CMD_SUCCESS;
3630 }
3631
3632 /* "bgp bestpath as-path confed" configuration. */
3633 DEFUN (bgp_bestpath_aspath_confed,
3634 bgp_bestpath_aspath_confed_cmd,
3635 "bgp bestpath as-path confed",
3636 BGP_STR
3637 "Change the default bestpath selection\n"
3638 "AS-path attribute\n"
3639 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3640 {
3641 VTY_DECLVAR_CONTEXT(bgp, bgp);
3642 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3643 bgp_recalculate_all_bestpaths(bgp);
3644
3645 return CMD_SUCCESS;
3646 }
3647
3648 DEFUN (no_bgp_bestpath_aspath_confed,
3649 no_bgp_bestpath_aspath_confed_cmd,
3650 "no bgp bestpath as-path confed",
3651 NO_STR
3652 BGP_STR
3653 "Change the default bestpath selection\n"
3654 "AS-path attribute\n"
3655 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3656 {
3657 VTY_DECLVAR_CONTEXT(bgp, bgp);
3658 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3659 bgp_recalculate_all_bestpaths(bgp);
3660
3661 return CMD_SUCCESS;
3662 }
3663
3664 /* "bgp bestpath as-path multipath-relax" configuration. */
3665 DEFUN (bgp_bestpath_aspath_multipath_relax,
3666 bgp_bestpath_aspath_multipath_relax_cmd,
3667 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3668 BGP_STR
3669 "Change the default bestpath selection\n"
3670 "AS-path attribute\n"
3671 "Allow load sharing across routes that have different AS paths (but same length)\n"
3672 "Generate an AS_SET\n"
3673 "Do not generate an AS_SET\n")
3674 {
3675 VTY_DECLVAR_CONTEXT(bgp, bgp);
3676 int idx = 0;
3677 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3678
3679 /* no-as-set is now the default behavior so we can silently
3680 * ignore it */
3681 if (argv_find(argv, argc, "as-set", &idx))
3682 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3683 else
3684 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3685
3686 bgp_recalculate_all_bestpaths(bgp);
3687
3688 return CMD_SUCCESS;
3689 }
3690
3691 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3692 no_bgp_bestpath_aspath_multipath_relax_cmd,
3693 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3694 NO_STR
3695 BGP_STR
3696 "Change the default bestpath selection\n"
3697 "AS-path attribute\n"
3698 "Allow load sharing across routes that have different AS paths (but same length)\n"
3699 "Generate an AS_SET\n"
3700 "Do not generate an AS_SET\n")
3701 {
3702 VTY_DECLVAR_CONTEXT(bgp, bgp);
3703 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3704 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3705 bgp_recalculate_all_bestpaths(bgp);
3706
3707 return CMD_SUCCESS;
3708 }
3709
3710 /* "bgp bestpath peer-type multipath-relax" configuration. */
3711 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3712 bgp_bestpath_peer_type_multipath_relax_cmd,
3713 "bgp bestpath peer-type multipath-relax",
3714 BGP_STR
3715 "Change the default bestpath selection\n"
3716 "Peer type\n"
3717 "Allow load sharing across routes learned from different peer types\n")
3718 {
3719 VTY_DECLVAR_CONTEXT(bgp, bgp);
3720 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3721 bgp_recalculate_all_bestpaths(bgp);
3722
3723 return CMD_SUCCESS;
3724 }
3725
3726 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3727 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3728 "no bgp bestpath peer-type multipath-relax",
3729 NO_STR BGP_STR
3730 "Change the default bestpath selection\n"
3731 "Peer type\n"
3732 "Allow load sharing across routes learned from different peer types\n")
3733 {
3734 VTY_DECLVAR_CONTEXT(bgp, bgp);
3735 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3736 bgp_recalculate_all_bestpaths(bgp);
3737
3738 return CMD_SUCCESS;
3739 }
3740
3741 /* "bgp log-neighbor-changes" configuration. */
3742 DEFUN (bgp_log_neighbor_changes,
3743 bgp_log_neighbor_changes_cmd,
3744 "bgp log-neighbor-changes",
3745 BGP_STR
3746 "Log neighbor up/down and reset reason\n")
3747 {
3748 VTY_DECLVAR_CONTEXT(bgp, bgp);
3749 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3750 return CMD_SUCCESS;
3751 }
3752
3753 DEFUN (no_bgp_log_neighbor_changes,
3754 no_bgp_log_neighbor_changes_cmd,
3755 "no bgp log-neighbor-changes",
3756 NO_STR
3757 BGP_STR
3758 "Log neighbor up/down and reset reason\n")
3759 {
3760 VTY_DECLVAR_CONTEXT(bgp, bgp);
3761 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3762 return CMD_SUCCESS;
3763 }
3764
3765 /* "bgp bestpath med" configuration. */
3766 DEFUN (bgp_bestpath_med,
3767 bgp_bestpath_med_cmd,
3768 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3769 BGP_STR
3770 "Change the default bestpath selection\n"
3771 "MED attribute\n"
3772 "Compare MED among confederation paths\n"
3773 "Treat missing MED as the least preferred one\n"
3774 "Treat missing MED as the least preferred one\n"
3775 "Compare MED among confederation paths\n")
3776 {
3777 VTY_DECLVAR_CONTEXT(bgp, bgp);
3778
3779 int idx = 0;
3780 if (argv_find(argv, argc, "confed", &idx))
3781 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3782 idx = 0;
3783 if (argv_find(argv, argc, "missing-as-worst", &idx))
3784 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3785
3786 bgp_recalculate_all_bestpaths(bgp);
3787
3788 return CMD_SUCCESS;
3789 }
3790
3791 DEFUN (no_bgp_bestpath_med,
3792 no_bgp_bestpath_med_cmd,
3793 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3794 NO_STR
3795 BGP_STR
3796 "Change the default bestpath selection\n"
3797 "MED attribute\n"
3798 "Compare MED among confederation paths\n"
3799 "Treat missing MED as the least preferred one\n"
3800 "Treat missing MED as the least preferred one\n"
3801 "Compare MED among confederation paths\n")
3802 {
3803 VTY_DECLVAR_CONTEXT(bgp, bgp);
3804
3805 int idx = 0;
3806 if (argv_find(argv, argc, "confed", &idx))
3807 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3808 idx = 0;
3809 if (argv_find(argv, argc, "missing-as-worst", &idx))
3810 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3811
3812 bgp_recalculate_all_bestpaths(bgp);
3813
3814 return CMD_SUCCESS;
3815 }
3816
3817 /* "bgp bestpath bandwidth" configuration. */
3818 DEFPY (bgp_bestpath_bw,
3819 bgp_bestpath_bw_cmd,
3820 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3821 BGP_STR
3822 "Change the default bestpath selection\n"
3823 "Link Bandwidth attribute\n"
3824 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3825 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3826 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3827 {
3828 VTY_DECLVAR_CONTEXT(bgp, bgp);
3829 afi_t afi;
3830 safi_t safi;
3831
3832 if (!bw_cfg) {
3833 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3834 return CMD_ERR_INCOMPLETE;
3835 }
3836 if (!strcmp(bw_cfg, "ignore"))
3837 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3838 else if (!strcmp(bw_cfg, "skip-missing"))
3839 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3840 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3841 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3842 else
3843 return CMD_ERR_NO_MATCH;
3844
3845 /* This config is used in route install, so redo that. */
3846 FOREACH_AFI_SAFI (afi, safi) {
3847 if (!bgp_fibupd_safi(safi))
3848 continue;
3849 bgp_zebra_announce_table(bgp, afi, safi);
3850 }
3851
3852 return CMD_SUCCESS;
3853 }
3854
3855 DEFPY (no_bgp_bestpath_bw,
3856 no_bgp_bestpath_bw_cmd,
3857 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3858 NO_STR
3859 BGP_STR
3860 "Change the default bestpath selection\n"
3861 "Link Bandwidth attribute\n"
3862 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3863 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3864 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3865 {
3866 VTY_DECLVAR_CONTEXT(bgp, bgp);
3867 afi_t afi;
3868 safi_t safi;
3869
3870 bgp->lb_handling = BGP_LINK_BW_ECMP;
3871
3872 /* This config is used in route install, so redo that. */
3873 FOREACH_AFI_SAFI (afi, safi) {
3874 if (!bgp_fibupd_safi(safi))
3875 continue;
3876 bgp_zebra_announce_table(bgp, afi, safi);
3877 }
3878 return CMD_SUCCESS;
3879 }
3880
3881 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3882 "[no] bgp default <ipv4-unicast|"
3883 "ipv4-multicast|"
3884 "ipv4-vpn|"
3885 "ipv4-labeled-unicast|"
3886 "ipv4-flowspec|"
3887 "ipv6-unicast|"
3888 "ipv6-multicast|"
3889 "ipv6-vpn|"
3890 "ipv6-labeled-unicast|"
3891 "ipv6-flowspec|"
3892 "l2vpn-evpn>$afi_safi",
3893 NO_STR
3894 BGP_STR
3895 "Configure BGP defaults\n"
3896 "Activate ipv4-unicast for a peer by default\n"
3897 "Activate ipv4-multicast for a peer by default\n"
3898 "Activate ipv4-vpn for a peer by default\n"
3899 "Activate ipv4-labeled-unicast for a peer by default\n"
3900 "Activate ipv4-flowspec for a peer by default\n"
3901 "Activate ipv6-unicast for a peer by default\n"
3902 "Activate ipv6-multicast for a peer by default\n"
3903 "Activate ipv6-vpn for a peer by default\n"
3904 "Activate ipv6-labeled-unicast for a peer by default\n"
3905 "Activate ipv6-flowspec for a peer by default\n"
3906 "Activate l2vpn-evpn for a peer by default\n")
3907 {
3908 VTY_DECLVAR_CONTEXT(bgp, bgp);
3909 char afi_safi_str[strlen(afi_safi) + 1];
3910 char *afi_safi_str_tok;
3911
3912 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3913 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3914 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3915 afi_t afi = bgp_vty_afi_from_str(afi_str);
3916 safi_t safi;
3917
3918 /*
3919 * Impossible situation but making coverity happy
3920 */
3921 assert(afi != AFI_MAX);
3922
3923 if (strmatch(safi_str, "labeled"))
3924 safi = bgp_vty_safi_from_str("labeled-unicast");
3925 else
3926 safi = bgp_vty_safi_from_str(safi_str);
3927
3928 assert(safi != SAFI_MAX);
3929 if (no)
3930 bgp->default_af[afi][safi] = false;
3931 else {
3932 if ((safi == SAFI_LABELED_UNICAST
3933 && bgp->default_af[afi][SAFI_UNICAST])
3934 || (safi == SAFI_UNICAST
3935 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3936 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3937 else
3938 bgp->default_af[afi][safi] = true;
3939 }
3940
3941 return CMD_SUCCESS;
3942 }
3943
3944 /* Display hostname in certain command outputs */
3945 DEFUN (bgp_default_show_hostname,
3946 bgp_default_show_hostname_cmd,
3947 "bgp default show-hostname",
3948 BGP_STR
3949 "Configure BGP defaults\n"
3950 "Show hostname in certain command outputs\n")
3951 {
3952 VTY_DECLVAR_CONTEXT(bgp, bgp);
3953 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3954 return CMD_SUCCESS;
3955 }
3956
3957 DEFUN (no_bgp_default_show_hostname,
3958 no_bgp_default_show_hostname_cmd,
3959 "no bgp default show-hostname",
3960 NO_STR
3961 BGP_STR
3962 "Configure BGP defaults\n"
3963 "Show hostname in certain command outputs\n")
3964 {
3965 VTY_DECLVAR_CONTEXT(bgp, bgp);
3966 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3967 return CMD_SUCCESS;
3968 }
3969
3970 /* Display hostname in certain command outputs */
3971 DEFUN (bgp_default_show_nexthop_hostname,
3972 bgp_default_show_nexthop_hostname_cmd,
3973 "bgp default show-nexthop-hostname",
3974 BGP_STR
3975 "Configure BGP defaults\n"
3976 "Show hostname for nexthop in certain command outputs\n")
3977 {
3978 VTY_DECLVAR_CONTEXT(bgp, bgp);
3979 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3980 return CMD_SUCCESS;
3981 }
3982
3983 DEFUN (no_bgp_default_show_nexthop_hostname,
3984 no_bgp_default_show_nexthop_hostname_cmd,
3985 "no bgp default show-nexthop-hostname",
3986 NO_STR
3987 BGP_STR
3988 "Configure BGP defaults\n"
3989 "Show hostname for nexthop in certain command outputs\n")
3990 {
3991 VTY_DECLVAR_CONTEXT(bgp, bgp);
3992 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3993 return CMD_SUCCESS;
3994 }
3995
3996 /* "bgp network import-check" configuration. */
3997 DEFUN (bgp_network_import_check,
3998 bgp_network_import_check_cmd,
3999 "bgp network import-check",
4000 BGP_STR
4001 "BGP network command\n"
4002 "Check BGP network route exists in IGP\n")
4003 {
4004 VTY_DECLVAR_CONTEXT(bgp, bgp);
4005 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4006 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4007 bgp_static_redo_import_check(bgp);
4008 }
4009
4010 return CMD_SUCCESS;
4011 }
4012
4013 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4014 "bgp network import-check exact",
4015 BGP_STR
4016 "BGP network command\n"
4017 "Check BGP network route exists in IGP\n"
4018 "Match route precisely\n")
4019
4020 DEFUN (no_bgp_network_import_check,
4021 no_bgp_network_import_check_cmd,
4022 "no bgp network import-check",
4023 NO_STR
4024 BGP_STR
4025 "BGP network command\n"
4026 "Check BGP network route exists in IGP\n")
4027 {
4028 VTY_DECLVAR_CONTEXT(bgp, bgp);
4029 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4030 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4031 bgp_static_redo_import_check(bgp);
4032 }
4033
4034 return CMD_SUCCESS;
4035 }
4036
4037 DEFUN (bgp_default_local_preference,
4038 bgp_default_local_preference_cmd,
4039 "bgp default local-preference (0-4294967295)",
4040 BGP_STR
4041 "Configure BGP defaults\n"
4042 "local preference (higher=more preferred)\n"
4043 "Configure default local preference value\n")
4044 {
4045 VTY_DECLVAR_CONTEXT(bgp, bgp);
4046 int idx_number = 3;
4047 uint32_t local_pref;
4048
4049 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4050
4051 bgp_default_local_preference_set(bgp, local_pref);
4052 bgp_clear_star_soft_in(vty, bgp->name);
4053
4054 return CMD_SUCCESS;
4055 }
4056
4057 DEFUN (no_bgp_default_local_preference,
4058 no_bgp_default_local_preference_cmd,
4059 "no bgp default local-preference [(0-4294967295)]",
4060 NO_STR
4061 BGP_STR
4062 "Configure BGP defaults\n"
4063 "local preference (higher=more preferred)\n"
4064 "Configure default local preference value\n")
4065 {
4066 VTY_DECLVAR_CONTEXT(bgp, bgp);
4067 bgp_default_local_preference_unset(bgp);
4068 bgp_clear_star_soft_in(vty, bgp->name);
4069
4070 return CMD_SUCCESS;
4071 }
4072
4073
4074 DEFUN (bgp_default_subgroup_pkt_queue_max,
4075 bgp_default_subgroup_pkt_queue_max_cmd,
4076 "bgp default subgroup-pkt-queue-max (20-100)",
4077 BGP_STR
4078 "Configure BGP defaults\n"
4079 "subgroup-pkt-queue-max\n"
4080 "Configure subgroup packet queue max\n")
4081 {
4082 VTY_DECLVAR_CONTEXT(bgp, bgp);
4083 int idx_number = 3;
4084 uint32_t max_size;
4085
4086 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4087
4088 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4089
4090 return CMD_SUCCESS;
4091 }
4092
4093 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4094 no_bgp_default_subgroup_pkt_queue_max_cmd,
4095 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4096 NO_STR
4097 BGP_STR
4098 "Configure BGP defaults\n"
4099 "subgroup-pkt-queue-max\n"
4100 "Configure subgroup packet queue max\n")
4101 {
4102 VTY_DECLVAR_CONTEXT(bgp, bgp);
4103 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4104 return CMD_SUCCESS;
4105 }
4106
4107
4108 DEFUN (bgp_rr_allow_outbound_policy,
4109 bgp_rr_allow_outbound_policy_cmd,
4110 "bgp route-reflector allow-outbound-policy",
4111 BGP_STR
4112 "Allow modifications made by out route-map\n"
4113 "on ibgp neighbors\n")
4114 {
4115 VTY_DECLVAR_CONTEXT(bgp, bgp);
4116
4117 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4118 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4119 update_group_announce_rrclients(bgp);
4120 bgp_clear_star_soft_out(vty, bgp->name);
4121 }
4122
4123 return CMD_SUCCESS;
4124 }
4125
4126 DEFUN (no_bgp_rr_allow_outbound_policy,
4127 no_bgp_rr_allow_outbound_policy_cmd,
4128 "no bgp route-reflector allow-outbound-policy",
4129 NO_STR
4130 BGP_STR
4131 "Allow modifications made by out route-map\n"
4132 "on ibgp neighbors\n")
4133 {
4134 VTY_DECLVAR_CONTEXT(bgp, bgp);
4135
4136 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4137 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4138 update_group_announce_rrclients(bgp);
4139 bgp_clear_star_soft_out(vty, bgp->name);
4140 }
4141
4142 return CMD_SUCCESS;
4143 }
4144
4145 DEFUN (bgp_listen_limit,
4146 bgp_listen_limit_cmd,
4147 "bgp listen limit (1-65535)",
4148 BGP_STR
4149 "BGP Dynamic Neighbors listen commands\n"
4150 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4151 "Configure Dynamic Neighbors listen limit value\n")
4152 {
4153 VTY_DECLVAR_CONTEXT(bgp, bgp);
4154 int idx_number = 3;
4155 int listen_limit;
4156
4157 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4158
4159 bgp_listen_limit_set(bgp, listen_limit);
4160
4161 return CMD_SUCCESS;
4162 }
4163
4164 DEFUN (no_bgp_listen_limit,
4165 no_bgp_listen_limit_cmd,
4166 "no bgp listen limit [(1-65535)]",
4167 NO_STR
4168 BGP_STR
4169 "BGP Dynamic Neighbors listen commands\n"
4170 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4171 "Configure Dynamic Neighbors listen limit value\n")
4172 {
4173 VTY_DECLVAR_CONTEXT(bgp, bgp);
4174 bgp_listen_limit_unset(bgp);
4175 return CMD_SUCCESS;
4176 }
4177
4178
4179 /*
4180 * Check if this listen range is already configured. Check for exact
4181 * match or overlap based on input.
4182 */
4183 static struct peer_group *listen_range_exists(struct bgp *bgp,
4184 struct prefix *range, int exact)
4185 {
4186 struct listnode *node, *nnode;
4187 struct listnode *node1, *nnode1;
4188 struct peer_group *group;
4189 struct prefix *lr;
4190 afi_t afi;
4191 int match;
4192
4193 afi = family2afi(range->family);
4194 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4195 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4196 lr)) {
4197 if (exact)
4198 match = prefix_same(range, lr);
4199 else
4200 match = (prefix_match(range, lr)
4201 || prefix_match(lr, range));
4202 if (match)
4203 return group;
4204 }
4205 }
4206
4207 return NULL;
4208 }
4209
4210 DEFUN (bgp_listen_range,
4211 bgp_listen_range_cmd,
4212 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4213 BGP_STR
4214 "Configure BGP dynamic neighbors listen range\n"
4215 "Configure BGP dynamic neighbors listen range\n"
4216 NEIGHBOR_ADDR_STR
4217 "Member of the peer-group\n"
4218 "Peer-group name\n")
4219 {
4220 VTY_DECLVAR_CONTEXT(bgp, bgp);
4221 struct prefix range;
4222 struct peer_group *group, *existing_group;
4223 afi_t afi;
4224 int ret;
4225 int idx = 0;
4226
4227 argv_find(argv, argc, "A.B.C.D/M", &idx);
4228 argv_find(argv, argc, "X:X::X:X/M", &idx);
4229 char *prefix = argv[idx]->arg;
4230 argv_find(argv, argc, "PGNAME", &idx);
4231 char *peergroup = argv[idx]->arg;
4232
4233 /* Convert IP prefix string to struct prefix. */
4234 ret = str2prefix(prefix, &range);
4235 if (!ret) {
4236 vty_out(vty, "%% Malformed listen range\n");
4237 return CMD_WARNING_CONFIG_FAILED;
4238 }
4239
4240 afi = family2afi(range.family);
4241
4242 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4243 vty_out(vty,
4244 "%% Malformed listen range (link-local address)\n");
4245 return CMD_WARNING_CONFIG_FAILED;
4246 }
4247
4248 apply_mask(&range);
4249
4250 /* Check if same listen range is already configured. */
4251 existing_group = listen_range_exists(bgp, &range, 1);
4252 if (existing_group) {
4253 if (strcmp(existing_group->name, peergroup) == 0)
4254 return CMD_SUCCESS;
4255 else {
4256 vty_out(vty,
4257 "%% Same listen range is attached to peer-group %s\n",
4258 existing_group->name);
4259 return CMD_WARNING_CONFIG_FAILED;
4260 }
4261 }
4262
4263 /* Check if an overlapping listen range exists. */
4264 if (listen_range_exists(bgp, &range, 0)) {
4265 vty_out(vty,
4266 "%% Listen range overlaps with existing listen range\n");
4267 return CMD_WARNING_CONFIG_FAILED;
4268 }
4269
4270 group = peer_group_lookup(bgp, peergroup);
4271 if (!group) {
4272 vty_out(vty, "%% Configure the peer-group first\n");
4273 return CMD_WARNING_CONFIG_FAILED;
4274 }
4275
4276 ret = peer_group_listen_range_add(group, &range);
4277 return bgp_vty_return(vty, ret);
4278 }
4279
4280 DEFUN (no_bgp_listen_range,
4281 no_bgp_listen_range_cmd,
4282 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4283 NO_STR
4284 BGP_STR
4285 "Unconfigure BGP dynamic neighbors listen range\n"
4286 "Unconfigure BGP dynamic neighbors listen range\n"
4287 NEIGHBOR_ADDR_STR
4288 "Member of the peer-group\n"
4289 "Peer-group name\n")
4290 {
4291 VTY_DECLVAR_CONTEXT(bgp, bgp);
4292 struct prefix range;
4293 struct peer_group *group;
4294 afi_t afi;
4295 int ret;
4296 int idx = 0;
4297
4298 argv_find(argv, argc, "A.B.C.D/M", &idx);
4299 argv_find(argv, argc, "X:X::X:X/M", &idx);
4300 char *prefix = argv[idx]->arg;
4301 argv_find(argv, argc, "PGNAME", &idx);
4302 char *peergroup = argv[idx]->arg;
4303
4304 /* Convert IP prefix string to struct prefix. */
4305 ret = str2prefix(prefix, &range);
4306 if (!ret) {
4307 vty_out(vty, "%% Malformed listen range\n");
4308 return CMD_WARNING_CONFIG_FAILED;
4309 }
4310
4311 afi = family2afi(range.family);
4312
4313 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4314 vty_out(vty,
4315 "%% Malformed listen range (link-local address)\n");
4316 return CMD_WARNING_CONFIG_FAILED;
4317 }
4318
4319 apply_mask(&range);
4320
4321 group = peer_group_lookup(bgp, peergroup);
4322 if (!group) {
4323 vty_out(vty, "%% Peer-group does not exist\n");
4324 return CMD_WARNING_CONFIG_FAILED;
4325 }
4326
4327 ret = peer_group_listen_range_del(group, &range);
4328 return bgp_vty_return(vty, ret);
4329 }
4330
4331 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4332 {
4333 struct peer_group *group;
4334 struct listnode *node, *nnode, *rnode, *nrnode;
4335 struct prefix *range;
4336 afi_t afi;
4337
4338 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4339 vty_out(vty, " bgp listen limit %d\n",
4340 bgp->dynamic_neighbors_limit);
4341
4342 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4343 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4344 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4345 nrnode, range)) {
4346 vty_out(vty,
4347 " bgp listen range %pFX peer-group %s\n",
4348 range, group->name);
4349 }
4350 }
4351 }
4352 }
4353
4354
4355 DEFUN (bgp_disable_connected_route_check,
4356 bgp_disable_connected_route_check_cmd,
4357 "bgp disable-ebgp-connected-route-check",
4358 BGP_STR
4359 "Disable checking if nexthop is connected on ebgp sessions\n")
4360 {
4361 VTY_DECLVAR_CONTEXT(bgp, bgp);
4362 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4363 bgp_clear_star_soft_in(vty, bgp->name);
4364
4365 return CMD_SUCCESS;
4366 }
4367
4368 DEFUN (no_bgp_disable_connected_route_check,
4369 no_bgp_disable_connected_route_check_cmd,
4370 "no bgp disable-ebgp-connected-route-check",
4371 NO_STR
4372 BGP_STR
4373 "Disable checking if nexthop is connected on ebgp sessions\n")
4374 {
4375 VTY_DECLVAR_CONTEXT(bgp, bgp);
4376 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4377 bgp_clear_star_soft_in(vty, bgp->name);
4378
4379 return CMD_SUCCESS;
4380 }
4381
4382
4383 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4384 const char *as_str)
4385 {
4386 VTY_DECLVAR_CONTEXT(bgp, bgp);
4387 int ret;
4388 as_t as;
4389 int as_type = AS_SPECIFIED;
4390 union sockunion su;
4391
4392 if (as_str[0] == 'i') {
4393 as = 0;
4394 as_type = AS_INTERNAL;
4395 } else if (as_str[0] == 'e') {
4396 as = 0;
4397 as_type = AS_EXTERNAL;
4398 } else {
4399 /* Get AS number. */
4400 as = strtoul(as_str, NULL, 10);
4401 }
4402
4403 /* If peer is peer group or interface peer, call proper function. */
4404 ret = str2sockunion(peer_str, &su);
4405 if (ret < 0) {
4406 struct peer *peer;
4407
4408 /* Check if existing interface peer */
4409 peer = peer_lookup_by_conf_if(bgp, peer_str);
4410
4411 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4412
4413 /* if not interface peer, check peer-group settings */
4414 if (ret < 0 && !peer) {
4415 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4416 if (ret < 0) {
4417 vty_out(vty,
4418 "%% Create the peer-group or interface first\n");
4419 return CMD_WARNING_CONFIG_FAILED;
4420 }
4421 return CMD_SUCCESS;
4422 }
4423 } else {
4424 if (peer_address_self_check(bgp, &su)) {
4425 vty_out(vty,
4426 "%% Can not configure the local system as neighbor\n");
4427 return CMD_WARNING_CONFIG_FAILED;
4428 }
4429 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4430 }
4431
4432 return bgp_vty_return(vty, ret);
4433 }
4434
4435 DEFUN (bgp_default_shutdown,
4436 bgp_default_shutdown_cmd,
4437 "[no] bgp default shutdown",
4438 NO_STR
4439 BGP_STR
4440 "Configure BGP defaults\n"
4441 "Apply administrative shutdown to newly configured peers\n")
4442 {
4443 VTY_DECLVAR_CONTEXT(bgp, bgp);
4444 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4445 return CMD_SUCCESS;
4446 }
4447
4448 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4449 BGP_STR
4450 "Administrative shutdown of the BGP instance\n"
4451 "Add a shutdown message (RFC 8203)\n"
4452 "Shutdown message\n")
4453 {
4454 char *msgstr = NULL;
4455
4456 VTY_DECLVAR_CONTEXT(bgp, bgp);
4457
4458 if (argc > 3)
4459 msgstr = argv_concat(argv, argc, 3);
4460
4461 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4462 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4463 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4464 return CMD_WARNING_CONFIG_FAILED;
4465 }
4466
4467 bgp_shutdown_enable(bgp, msgstr);
4468 XFREE(MTYPE_TMP, msgstr);
4469
4470 return CMD_SUCCESS;
4471 }
4472
4473 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4474 BGP_STR "Administrative shutdown of the BGP instance\n")
4475 {
4476 VTY_DECLVAR_CONTEXT(bgp, bgp);
4477
4478 bgp_shutdown_enable(bgp, NULL);
4479
4480 return CMD_SUCCESS;
4481 }
4482
4483 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4484 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4485 {
4486 VTY_DECLVAR_CONTEXT(bgp, bgp);
4487
4488 bgp_shutdown_disable(bgp);
4489
4490 return CMD_SUCCESS;
4491 }
4492
4493 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4494 "no bgp shutdown message MSG...", NO_STR BGP_STR
4495 "Administrative shutdown of the BGP instance\n"
4496 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4497
4498 DEFUN (neighbor_remote_as,
4499 neighbor_remote_as_cmd,
4500 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4501 NEIGHBOR_STR
4502 NEIGHBOR_ADDR_STR2
4503 "Specify a BGP neighbor\n"
4504 AS_STR
4505 "Internal BGP peer\n"
4506 "External BGP peer\n")
4507 {
4508 int idx_peer = 1;
4509 int idx_remote_as = 3;
4510 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4511 argv[idx_remote_as]->arg);
4512 }
4513
4514 DEFPY (bgp_allow_martian,
4515 bgp_allow_martian_cmd,
4516 "[no]$no bgp allow-martian-nexthop",
4517 NO_STR
4518 BGP_STR
4519 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4520 {
4521 VTY_DECLVAR_CONTEXT(bgp, bgp);
4522
4523 if (no)
4524 bgp->allow_martian = false;
4525 else
4526 bgp->allow_martian = true;
4527
4528 return CMD_SUCCESS;
4529 }
4530
4531 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4532 * sessions do not wait for hold timer expiry to bring down the sessions
4533 * when nexthop becomes unreachable
4534 */
4535 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4536 BGP_STR "Fast convergence for bgp sessions\n")
4537 {
4538 VTY_DECLVAR_CONTEXT(bgp, bgp);
4539 bgp->fast_convergence = true;
4540
4541 return CMD_SUCCESS;
4542 }
4543
4544 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4545 "no bgp fast-convergence",
4546 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4547 {
4548 VTY_DECLVAR_CONTEXT(bgp, bgp);
4549 bgp->fast_convergence = false;
4550
4551 return CMD_SUCCESS;
4552 }
4553
4554 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4555 int v6only,
4556 const char *peer_group_name,
4557 const char *as_str)
4558 {
4559 VTY_DECLVAR_CONTEXT(bgp, bgp);
4560 as_t as = 0;
4561 int as_type = AS_UNSPECIFIED;
4562 struct peer *peer;
4563 struct peer_group *group;
4564 int ret = 0;
4565
4566 group = peer_group_lookup(bgp, conf_if);
4567
4568 if (group) {
4569 vty_out(vty, "%% Name conflict with peer-group \n");
4570 return CMD_WARNING_CONFIG_FAILED;
4571 }
4572
4573 if (as_str) {
4574 if (as_str[0] == 'i') {
4575 as_type = AS_INTERNAL;
4576 } else if (as_str[0] == 'e') {
4577 as_type = AS_EXTERNAL;
4578 } else {
4579 /* Get AS number. */
4580 as = strtoul(as_str, NULL, 10);
4581 as_type = AS_SPECIFIED;
4582 }
4583 }
4584
4585 peer = peer_lookup_by_conf_if(bgp, conf_if);
4586 if (peer) {
4587 if (as_str)
4588 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4589 } else {
4590 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4591 NULL);
4592
4593 if (!peer) {
4594 vty_out(vty, "%% BGP failed to create peer\n");
4595 return CMD_WARNING_CONFIG_FAILED;
4596 }
4597
4598 if (v6only)
4599 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4600
4601 /* Request zebra to initiate IPv6 RAs on this interface. We do
4602 * this
4603 * any unnumbered peer in order to not worry about run-time
4604 * transitions
4605 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4606 * address
4607 * gets deleted later etc.)
4608 */
4609 if (peer->ifp)
4610 bgp_zebra_initiate_radv(bgp, peer);
4611 }
4612
4613 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4614 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4615 if (v6only)
4616 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4617 else
4618 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4619
4620 /* v6only flag changed. Reset bgp seesion */
4621 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4622 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4623 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4624 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4625 } else
4626 bgp_session_reset(peer);
4627 }
4628
4629 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4630 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4631 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4632 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4633 }
4634
4635 if (peer_group_name) {
4636 group = peer_group_lookup(bgp, peer_group_name);
4637 if (!group) {
4638 vty_out(vty, "%% Configure the peer-group first\n");
4639 return CMD_WARNING_CONFIG_FAILED;
4640 }
4641
4642 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4643 }
4644
4645 return bgp_vty_return(vty, ret);
4646 }
4647
4648 DEFUN (neighbor_interface_config,
4649 neighbor_interface_config_cmd,
4650 "neighbor WORD interface [peer-group PGNAME]",
4651 NEIGHBOR_STR
4652 "Interface name or neighbor tag\n"
4653 "Enable BGP on interface\n"
4654 "Member of the peer-group\n"
4655 "Peer-group name\n")
4656 {
4657 int idx_word = 1;
4658 int idx_peer_group_word = 4;
4659
4660 if (argc > idx_peer_group_word)
4661 return peer_conf_interface_get(
4662 vty, argv[idx_word]->arg, 0,
4663 argv[idx_peer_group_word]->arg, NULL);
4664 else
4665 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4666 NULL, NULL);
4667 }
4668
4669 DEFUN (neighbor_interface_config_v6only,
4670 neighbor_interface_config_v6only_cmd,
4671 "neighbor WORD interface v6only [peer-group PGNAME]",
4672 NEIGHBOR_STR
4673 "Interface name or neighbor tag\n"
4674 "Enable BGP on interface\n"
4675 "Enable BGP with v6 link-local only\n"
4676 "Member of the peer-group\n"
4677 "Peer-group name\n")
4678 {
4679 int idx_word = 1;
4680 int idx_peer_group_word = 5;
4681
4682 if (argc > idx_peer_group_word)
4683 return peer_conf_interface_get(
4684 vty, argv[idx_word]->arg, 1,
4685 argv[idx_peer_group_word]->arg, NULL);
4686
4687 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4688 }
4689
4690
4691 DEFUN (neighbor_interface_config_remote_as,
4692 neighbor_interface_config_remote_as_cmd,
4693 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4694 NEIGHBOR_STR
4695 "Interface name or neighbor tag\n"
4696 "Enable BGP on interface\n"
4697 "Specify a BGP neighbor\n"
4698 AS_STR
4699 "Internal BGP peer\n"
4700 "External BGP peer\n")
4701 {
4702 int idx_word = 1;
4703 int idx_remote_as = 4;
4704 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4705 argv[idx_remote_as]->arg);
4706 }
4707
4708 DEFUN (neighbor_interface_v6only_config_remote_as,
4709 neighbor_interface_v6only_config_remote_as_cmd,
4710 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4711 NEIGHBOR_STR
4712 "Interface name or neighbor tag\n"
4713 "Enable BGP with v6 link-local only\n"
4714 "Enable BGP on interface\n"
4715 "Specify a BGP neighbor\n"
4716 AS_STR
4717 "Internal BGP peer\n"
4718 "External BGP peer\n")
4719 {
4720 int idx_word = 1;
4721 int idx_remote_as = 5;
4722 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4723 argv[idx_remote_as]->arg);
4724 }
4725
4726 DEFUN (neighbor_peer_group,
4727 neighbor_peer_group_cmd,
4728 "neighbor WORD peer-group",
4729 NEIGHBOR_STR
4730 "Interface name or neighbor tag\n"
4731 "Configure peer-group\n")
4732 {
4733 VTY_DECLVAR_CONTEXT(bgp, bgp);
4734 int idx_word = 1;
4735 struct peer *peer;
4736 struct peer_group *group;
4737
4738 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4739 if (peer) {
4740 vty_out(vty, "%% Name conflict with interface: \n");
4741 return CMD_WARNING_CONFIG_FAILED;
4742 }
4743
4744 group = peer_group_get(bgp, argv[idx_word]->arg);
4745 if (!group) {
4746 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4747 return CMD_WARNING_CONFIG_FAILED;
4748 }
4749
4750 return CMD_SUCCESS;
4751 }
4752
4753 DEFUN (no_neighbor,
4754 no_neighbor_cmd,
4755 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4756 NO_STR
4757 NEIGHBOR_STR
4758 NEIGHBOR_ADDR_STR2
4759 "Specify a BGP neighbor\n"
4760 AS_STR
4761 "Internal BGP peer\n"
4762 "External BGP peer\n")
4763 {
4764 VTY_DECLVAR_CONTEXT(bgp, bgp);
4765 int idx_peer = 2;
4766 int ret;
4767 union sockunion su;
4768 struct peer_group *group;
4769 struct peer *peer;
4770 struct peer *other;
4771
4772 ret = str2sockunion(argv[idx_peer]->arg, &su);
4773 if (ret < 0) {
4774 /* look up for neighbor by interface name config. */
4775 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4776 if (peer) {
4777 /* Request zebra to terminate IPv6 RAs on this
4778 * interface. */
4779 if (peer->ifp)
4780 bgp_zebra_terminate_radv(peer->bgp, peer);
4781 peer_notify_unconfig(peer);
4782 peer_delete(peer);
4783 return CMD_SUCCESS;
4784 }
4785
4786 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4787 if (group) {
4788 peer_group_notify_unconfig(group);
4789 peer_group_delete(group);
4790 } else {
4791 vty_out(vty, "%% Create the peer-group first\n");
4792 return CMD_WARNING_CONFIG_FAILED;
4793 }
4794 } else {
4795 peer = peer_lookup(bgp, &su);
4796 if (peer) {
4797 if (peer_dynamic_neighbor(peer)) {
4798 vty_out(vty,
4799 "%% Operation not allowed on a dynamic neighbor\n");
4800 return CMD_WARNING_CONFIG_FAILED;
4801 }
4802
4803 other = peer->doppelganger;
4804
4805 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4806 bgp_zebra_terminate_radv(peer->bgp, peer);
4807
4808 peer_notify_unconfig(peer);
4809 peer_delete(peer);
4810 if (other && other->status != Deleted) {
4811 peer_notify_unconfig(other);
4812 peer_delete(other);
4813 }
4814 }
4815 }
4816
4817 return CMD_SUCCESS;
4818 }
4819
4820 DEFUN (no_neighbor_interface_config,
4821 no_neighbor_interface_config_cmd,
4822 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4823 NO_STR
4824 NEIGHBOR_STR
4825 "Interface name\n"
4826 "Configure BGP on interface\n"
4827 "Enable BGP with v6 link-local only\n"
4828 "Member of the peer-group\n"
4829 "Peer-group name\n"
4830 "Specify a BGP neighbor\n"
4831 AS_STR
4832 "Internal BGP peer\n"
4833 "External BGP peer\n")
4834 {
4835 VTY_DECLVAR_CONTEXT(bgp, bgp);
4836 int idx_word = 2;
4837 struct peer *peer;
4838
4839 /* look up for neighbor by interface name config. */
4840 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4841 if (peer) {
4842 /* Request zebra to terminate IPv6 RAs on this interface. */
4843 if (peer->ifp)
4844 bgp_zebra_terminate_radv(peer->bgp, peer);
4845 peer_notify_unconfig(peer);
4846 peer_delete(peer);
4847 } else {
4848 vty_out(vty, "%% Create the bgp interface first\n");
4849 return CMD_WARNING_CONFIG_FAILED;
4850 }
4851 return CMD_SUCCESS;
4852 }
4853
4854 DEFUN (no_neighbor_peer_group,
4855 no_neighbor_peer_group_cmd,
4856 "no neighbor WORD peer-group",
4857 NO_STR
4858 NEIGHBOR_STR
4859 "Neighbor tag\n"
4860 "Configure peer-group\n")
4861 {
4862 VTY_DECLVAR_CONTEXT(bgp, bgp);
4863 int idx_word = 2;
4864 struct peer_group *group;
4865
4866 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4867 if (group) {
4868 peer_group_notify_unconfig(group);
4869 peer_group_delete(group);
4870 } else {
4871 vty_out(vty, "%% Create the peer-group first\n");
4872 return CMD_WARNING_CONFIG_FAILED;
4873 }
4874 return CMD_SUCCESS;
4875 }
4876
4877 DEFUN (no_neighbor_interface_peer_group_remote_as,
4878 no_neighbor_interface_peer_group_remote_as_cmd,
4879 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4880 NO_STR
4881 NEIGHBOR_STR
4882 "Interface name or neighbor tag\n"
4883 "Specify a BGP neighbor\n"
4884 AS_STR
4885 "Internal BGP peer\n"
4886 "External BGP peer\n")
4887 {
4888 VTY_DECLVAR_CONTEXT(bgp, bgp);
4889 int idx_word = 2;
4890 struct peer_group *group;
4891 struct peer *peer;
4892
4893 /* look up for neighbor by interface name config. */
4894 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4895 if (peer) {
4896 peer_as_change(peer, 0, AS_UNSPECIFIED);
4897 return CMD_SUCCESS;
4898 }
4899
4900 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4901 if (group)
4902 peer_group_remote_as_delete(group);
4903 else {
4904 vty_out(vty, "%% Create the peer-group or interface first\n");
4905 return CMD_WARNING_CONFIG_FAILED;
4906 }
4907 return CMD_SUCCESS;
4908 }
4909
4910 DEFUN (neighbor_local_as,
4911 neighbor_local_as_cmd,
4912 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4913 NEIGHBOR_STR
4914 NEIGHBOR_ADDR_STR2
4915 "Specify a local-as number\n"
4916 "AS number used as local AS\n")
4917 {
4918 int idx_peer = 1;
4919 int idx_number = 3;
4920 struct peer *peer;
4921 int ret;
4922 as_t as;
4923
4924 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4925 if (!peer)
4926 return CMD_WARNING_CONFIG_FAILED;
4927
4928 as = strtoul(argv[idx_number]->arg, NULL, 10);
4929 ret = peer_local_as_set(peer, as, 0, 0);
4930 return bgp_vty_return(vty, ret);
4931 }
4932
4933 DEFUN (neighbor_local_as_no_prepend,
4934 neighbor_local_as_no_prepend_cmd,
4935 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4936 NEIGHBOR_STR
4937 NEIGHBOR_ADDR_STR2
4938 "Specify a local-as number\n"
4939 "AS number used as local AS\n"
4940 "Do not prepend local-as to updates from ebgp peers\n")
4941 {
4942 int idx_peer = 1;
4943 int idx_number = 3;
4944 struct peer *peer;
4945 int ret;
4946 as_t as;
4947
4948 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4949 if (!peer)
4950 return CMD_WARNING_CONFIG_FAILED;
4951
4952 as = strtoul(argv[idx_number]->arg, NULL, 10);
4953 ret = peer_local_as_set(peer, as, 1, 0);
4954 return bgp_vty_return(vty, ret);
4955 }
4956
4957 DEFUN (neighbor_local_as_no_prepend_replace_as,
4958 neighbor_local_as_no_prepend_replace_as_cmd,
4959 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4960 NEIGHBOR_STR
4961 NEIGHBOR_ADDR_STR2
4962 "Specify a local-as number\n"
4963 "AS number used as local AS\n"
4964 "Do not prepend local-as to updates from ebgp peers\n"
4965 "Do not prepend local-as to updates from ibgp peers\n")
4966 {
4967 int idx_peer = 1;
4968 int idx_number = 3;
4969 struct peer *peer;
4970 int ret;
4971 as_t as;
4972
4973 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4974 if (!peer)
4975 return CMD_WARNING_CONFIG_FAILED;
4976
4977 as = strtoul(argv[idx_number]->arg, NULL, 10);
4978 ret = peer_local_as_set(peer, as, 1, 1);
4979 return bgp_vty_return(vty, ret);
4980 }
4981
4982 DEFUN (no_neighbor_local_as,
4983 no_neighbor_local_as_cmd,
4984 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4985 NO_STR
4986 NEIGHBOR_STR
4987 NEIGHBOR_ADDR_STR2
4988 "Specify a local-as number\n"
4989 "AS number used as local AS\n"
4990 "Do not prepend local-as to updates from ebgp peers\n"
4991 "Do not prepend local-as to updates from ibgp peers\n")
4992 {
4993 int idx_peer = 2;
4994 struct peer *peer;
4995 int ret;
4996
4997 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4998 if (!peer)
4999 return CMD_WARNING_CONFIG_FAILED;
5000
5001 ret = peer_local_as_unset(peer);
5002 return bgp_vty_return(vty, ret);
5003 }
5004
5005
5006 DEFUN (neighbor_solo,
5007 neighbor_solo_cmd,
5008 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5009 NEIGHBOR_STR
5010 NEIGHBOR_ADDR_STR2
5011 "Solo peer - part of its own update group\n")
5012 {
5013 int idx_peer = 1;
5014 struct peer *peer;
5015 int ret;
5016
5017 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5018 if (!peer)
5019 return CMD_WARNING_CONFIG_FAILED;
5020
5021 ret = update_group_adjust_soloness(peer, 1);
5022 return bgp_vty_return(vty, ret);
5023 }
5024
5025 DEFUN (no_neighbor_solo,
5026 no_neighbor_solo_cmd,
5027 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5028 NO_STR
5029 NEIGHBOR_STR
5030 NEIGHBOR_ADDR_STR2
5031 "Solo peer - part of its own update group\n")
5032 {
5033 int idx_peer = 2;
5034 struct peer *peer;
5035 int ret;
5036
5037 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5038 if (!peer)
5039 return CMD_WARNING_CONFIG_FAILED;
5040
5041 ret = update_group_adjust_soloness(peer, 0);
5042 return bgp_vty_return(vty, ret);
5043 }
5044
5045 DEFUN (neighbor_password,
5046 neighbor_password_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5048 NEIGHBOR_STR
5049 NEIGHBOR_ADDR_STR2
5050 "Set a password\n"
5051 "The password\n")
5052 {
5053 int idx_peer = 1;
5054 int idx_line = 3;
5055 struct peer *peer;
5056 int ret;
5057
5058 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5059 if (!peer)
5060 return CMD_WARNING_CONFIG_FAILED;
5061
5062 ret = peer_password_set(peer, argv[idx_line]->arg);
5063 return bgp_vty_return(vty, ret);
5064 }
5065
5066 DEFUN (no_neighbor_password,
5067 no_neighbor_password_cmd,
5068 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5069 NO_STR
5070 NEIGHBOR_STR
5071 NEIGHBOR_ADDR_STR2
5072 "Set a password\n"
5073 "The password\n")
5074 {
5075 int idx_peer = 2;
5076 struct peer *peer;
5077 int ret;
5078
5079 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5080 if (!peer)
5081 return CMD_WARNING_CONFIG_FAILED;
5082
5083 ret = peer_password_unset(peer);
5084 return bgp_vty_return(vty, ret);
5085 }
5086
5087 DEFUN (neighbor_activate,
5088 neighbor_activate_cmd,
5089 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5090 NEIGHBOR_STR
5091 NEIGHBOR_ADDR_STR2
5092 "Enable the Address Family for this Neighbor\n")
5093 {
5094 int idx_peer = 1;
5095 int ret;
5096 struct peer *peer;
5097
5098 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5099 if (!peer)
5100 return CMD_WARNING_CONFIG_FAILED;
5101
5102 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5103 return bgp_vty_return(vty, ret);
5104 }
5105
5106 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5107 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5108 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5109 "Enable the Address Family for this Neighbor\n")
5110
5111 DEFUN (no_neighbor_activate,
5112 no_neighbor_activate_cmd,
5113 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5114 NO_STR
5115 NEIGHBOR_STR
5116 NEIGHBOR_ADDR_STR2
5117 "Enable the Address Family for this Neighbor\n")
5118 {
5119 int idx_peer = 2;
5120 int ret;
5121 struct peer *peer;
5122
5123 /* Lookup peer. */
5124 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5125 if (!peer)
5126 return CMD_WARNING_CONFIG_FAILED;
5127
5128 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5129 return bgp_vty_return(vty, ret);
5130 }
5131
5132 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5133 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5134 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5135 "Enable the Address Family for this Neighbor\n")
5136
5137 DEFUN (neighbor_set_peer_group,
5138 neighbor_set_peer_group_cmd,
5139 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5140 NEIGHBOR_STR
5141 NEIGHBOR_ADDR_STR2
5142 "Member of the peer-group\n"
5143 "Peer-group name\n")
5144 {
5145 VTY_DECLVAR_CONTEXT(bgp, bgp);
5146 int idx_peer = 1;
5147 int idx_word = 3;
5148 int ret;
5149 as_t as;
5150 union sockunion su;
5151 struct peer *peer;
5152 struct peer_group *group;
5153
5154 ret = str2sockunion(argv[idx_peer]->arg, &su);
5155 if (ret < 0) {
5156 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5157 if (!peer) {
5158 vty_out(vty, "%% Malformed address or name: %s\n",
5159 argv[idx_peer]->arg);
5160 return CMD_WARNING_CONFIG_FAILED;
5161 }
5162 } else {
5163 if (peer_address_self_check(bgp, &su)) {
5164 vty_out(vty,
5165 "%% Can not configure the local system as neighbor\n");
5166 return CMD_WARNING_CONFIG_FAILED;
5167 }
5168
5169 /* Disallow for dynamic neighbor. */
5170 peer = peer_lookup(bgp, &su);
5171 if (peer && peer_dynamic_neighbor(peer)) {
5172 vty_out(vty,
5173 "%% Operation not allowed on a dynamic neighbor\n");
5174 return CMD_WARNING_CONFIG_FAILED;
5175 }
5176 }
5177
5178 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5179 if (!group) {
5180 vty_out(vty, "%% Configure the peer-group first\n");
5181 return CMD_WARNING_CONFIG_FAILED;
5182 }
5183
5184 ret = peer_group_bind(bgp, &su, peer, group, &as);
5185
5186 return bgp_vty_return(vty, ret);
5187 }
5188
5189 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5190 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5191 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5192 "Member of the peer-group\n"
5193 "Peer-group name\n")
5194
5195 DEFUN (no_neighbor_set_peer_group,
5196 no_neighbor_set_peer_group_cmd,
5197 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5198 NO_STR
5199 NEIGHBOR_STR
5200 NEIGHBOR_ADDR_STR2
5201 "Member of the peer-group\n"
5202 "Peer-group name\n")
5203 {
5204 VTY_DECLVAR_CONTEXT(bgp, bgp);
5205 int idx_peer = 2;
5206 int idx_word = 4;
5207 int ret;
5208 struct peer *peer;
5209 struct peer_group *group;
5210
5211 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5212 if (!peer)
5213 return CMD_WARNING_CONFIG_FAILED;
5214
5215 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5216 if (!group) {
5217 vty_out(vty, "%% Configure the peer-group first\n");
5218 return CMD_WARNING_CONFIG_FAILED;
5219 }
5220
5221 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5222 bgp_zebra_terminate_radv(peer->bgp, peer);
5223
5224 peer_notify_unconfig(peer);
5225 ret = peer_delete(peer);
5226
5227 return bgp_vty_return(vty, ret);
5228 }
5229
5230 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5231 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5232 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5233 "Member of the peer-group\n"
5234 "Peer-group name\n")
5235
5236 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5237 uint64_t flag, int set)
5238 {
5239 int ret;
5240 struct peer *peer;
5241
5242 peer = peer_and_group_lookup_vty(vty, ip_str);
5243 if (!peer)
5244 return CMD_WARNING_CONFIG_FAILED;
5245
5246 /*
5247 * If 'neighbor <interface>', then this is for directly connected peers,
5248 * we should not accept disable-connected-check.
5249 */
5250 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5251 vty_out(vty,
5252 "%s is directly connected peer, cannot accept disable-connected-check\n",
5253 ip_str);
5254 return CMD_WARNING_CONFIG_FAILED;
5255 }
5256
5257 if (!set && flag == PEER_FLAG_SHUTDOWN)
5258 peer_tx_shutdown_message_unset(peer);
5259
5260 if (set)
5261 ret = peer_flag_set(peer, flag);
5262 else
5263 ret = peer_flag_unset(peer, flag);
5264
5265 return bgp_vty_return(vty, ret);
5266 }
5267
5268 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5269 {
5270 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5271 }
5272
5273 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5274 uint64_t flag)
5275 {
5276 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5277 }
5278
5279 /* neighbor passive. */
5280 DEFUN (neighbor_passive,
5281 neighbor_passive_cmd,
5282 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5283 NEIGHBOR_STR
5284 NEIGHBOR_ADDR_STR2
5285 "Don't send open messages to this neighbor\n")
5286 {
5287 int idx_peer = 1;
5288 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5289 }
5290
5291 DEFUN (no_neighbor_passive,
5292 no_neighbor_passive_cmd,
5293 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5294 NO_STR
5295 NEIGHBOR_STR
5296 NEIGHBOR_ADDR_STR2
5297 "Don't send open messages to this neighbor\n")
5298 {
5299 int idx_peer = 2;
5300 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5301 }
5302
5303 /* neighbor shutdown. */
5304 DEFUN (neighbor_shutdown_msg,
5305 neighbor_shutdown_msg_cmd,
5306 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5307 NEIGHBOR_STR
5308 NEIGHBOR_ADDR_STR2
5309 "Administratively shut down this neighbor\n"
5310 "Add a shutdown message (RFC 8203)\n"
5311 "Shutdown message\n")
5312 {
5313 int idx_peer = 1;
5314
5315 if (argc >= 5) {
5316 struct peer *peer =
5317 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5318 char *message;
5319
5320 if (!peer)
5321 return CMD_WARNING_CONFIG_FAILED;
5322 message = argv_concat(argv, argc, 4);
5323 peer_tx_shutdown_message_set(peer, message);
5324 XFREE(MTYPE_TMP, message);
5325 }
5326
5327 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5328 }
5329
5330 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5331 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5332 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5333 "Administratively shut down this neighbor\n")
5334
5335 DEFUN (no_neighbor_shutdown_msg,
5336 no_neighbor_shutdown_msg_cmd,
5337 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5338 NO_STR
5339 NEIGHBOR_STR
5340 NEIGHBOR_ADDR_STR2
5341 "Administratively shut down this neighbor\n"
5342 "Remove a shutdown message (RFC 8203)\n"
5343 "Shutdown message\n")
5344 {
5345 int idx_peer = 2;
5346
5347 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5348 PEER_FLAG_SHUTDOWN);
5349 }
5350
5351 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5352 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5353 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5354 "Administratively shut down this neighbor\n")
5355
5356 DEFUN(neighbor_shutdown_rtt,
5357 neighbor_shutdown_rtt_cmd,
5358 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5359 NEIGHBOR_STR
5360 NEIGHBOR_ADDR_STR2
5361 "Administratively shut down this neighbor\n"
5362 "Shutdown if round-trip-time is higher than expected\n"
5363 "Round-trip-time in milliseconds\n"
5364 "Specify the number of keepalives before shutdown\n"
5365 "The number of keepalives with higher RTT to shutdown\n")
5366 {
5367 int idx_peer = 1;
5368 int idx_rtt = 4;
5369 int idx_count = 0;
5370 struct peer *peer;
5371
5372 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5373
5374 if (!peer)
5375 return CMD_WARNING_CONFIG_FAILED;
5376
5377 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5378
5379 if (argv_find(argv, argc, "count", &idx_count))
5380 peer->rtt_keepalive_conf =
5381 strtol(argv[idx_count + 1]->arg, NULL, 10);
5382
5383 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5384 PEER_FLAG_RTT_SHUTDOWN);
5385 }
5386
5387 DEFUN(no_neighbor_shutdown_rtt,
5388 no_neighbor_shutdown_rtt_cmd,
5389 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5390 NO_STR
5391 NEIGHBOR_STR
5392 NEIGHBOR_ADDR_STR2
5393 "Administratively shut down this neighbor\n"
5394 "Shutdown if round-trip-time is higher than expected\n"
5395 "Round-trip-time in milliseconds\n"
5396 "Specify the number of keepalives before shutdown\n"
5397 "The number of keepalives with higher RTT to shutdown\n")
5398 {
5399 int idx_peer = 2;
5400 struct peer *peer;
5401
5402 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5403
5404 if (!peer)
5405 return CMD_WARNING_CONFIG_FAILED;
5406
5407 peer->rtt_expected = 0;
5408 peer->rtt_keepalive_conf = 1;
5409
5410 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5411 PEER_FLAG_RTT_SHUTDOWN);
5412 }
5413
5414 /* neighbor capability dynamic. */
5415 DEFUN (neighbor_capability_dynamic,
5416 neighbor_capability_dynamic_cmd,
5417 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5418 NEIGHBOR_STR
5419 NEIGHBOR_ADDR_STR2
5420 "Advertise capability to the peer\n"
5421 "Advertise dynamic capability to this neighbor\n")
5422 {
5423 int idx_peer = 1;
5424 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5425 PEER_FLAG_DYNAMIC_CAPABILITY);
5426 }
5427
5428 DEFUN (no_neighbor_capability_dynamic,
5429 no_neighbor_capability_dynamic_cmd,
5430 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5431 NO_STR
5432 NEIGHBOR_STR
5433 NEIGHBOR_ADDR_STR2
5434 "Advertise capability to the peer\n"
5435 "Advertise dynamic capability to this neighbor\n")
5436 {
5437 int idx_peer = 2;
5438 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5439 PEER_FLAG_DYNAMIC_CAPABILITY);
5440 }
5441
5442 /* neighbor dont-capability-negotiate */
5443 DEFUN (neighbor_dont_capability_negotiate,
5444 neighbor_dont_capability_negotiate_cmd,
5445 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5446 NEIGHBOR_STR
5447 NEIGHBOR_ADDR_STR2
5448 "Do not perform capability negotiation\n")
5449 {
5450 int idx_peer = 1;
5451 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5452 PEER_FLAG_DONT_CAPABILITY);
5453 }
5454
5455 DEFUN (no_neighbor_dont_capability_negotiate,
5456 no_neighbor_dont_capability_negotiate_cmd,
5457 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5458 NO_STR
5459 NEIGHBOR_STR
5460 NEIGHBOR_ADDR_STR2
5461 "Do not perform capability negotiation\n")
5462 {
5463 int idx_peer = 2;
5464 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5465 PEER_FLAG_DONT_CAPABILITY);
5466 }
5467
5468 /* neighbor capability extended next hop encoding */
5469 DEFUN (neighbor_capability_enhe,
5470 neighbor_capability_enhe_cmd,
5471 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5472 NEIGHBOR_STR
5473 NEIGHBOR_ADDR_STR2
5474 "Advertise capability to the peer\n"
5475 "Advertise extended next-hop capability to the peer\n")
5476 {
5477 int idx_peer = 1;
5478 struct peer *peer;
5479
5480 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5481 if (peer && peer->conf_if)
5482 return CMD_SUCCESS;
5483
5484 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5485 PEER_FLAG_CAPABILITY_ENHE);
5486 }
5487
5488 DEFUN (no_neighbor_capability_enhe,
5489 no_neighbor_capability_enhe_cmd,
5490 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5491 NO_STR
5492 NEIGHBOR_STR
5493 NEIGHBOR_ADDR_STR2
5494 "Advertise capability to the peer\n"
5495 "Advertise extended next-hop capability to the peer\n")
5496 {
5497 int idx_peer = 2;
5498 struct peer *peer;
5499
5500 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5501 if (peer && peer->conf_if) {
5502 vty_out(vty,
5503 "Peer %s cannot have capability extended-nexthop turned off\n",
5504 argv[idx_peer]->arg);
5505 return CMD_WARNING_CONFIG_FAILED;
5506 }
5507
5508 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5509 PEER_FLAG_CAPABILITY_ENHE);
5510 }
5511
5512 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5513 afi_t afi, safi_t safi, uint32_t flag,
5514 int set)
5515 {
5516 int ret;
5517 struct peer *peer;
5518
5519 peer = peer_and_group_lookup_vty(vty, peer_str);
5520 if (!peer)
5521 return CMD_WARNING_CONFIG_FAILED;
5522
5523 if (set)
5524 ret = peer_af_flag_set(peer, afi, safi, flag);
5525 else
5526 ret = peer_af_flag_unset(peer, afi, safi, flag);
5527
5528 return bgp_vty_return(vty, ret);
5529 }
5530
5531 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5532 afi_t afi, safi_t safi, uint32_t flag)
5533 {
5534 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5535 }
5536
5537 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5538 afi_t afi, safi_t safi, uint32_t flag)
5539 {
5540 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5541 }
5542
5543 /* neighbor capability orf prefix-list. */
5544 DEFUN (neighbor_capability_orf_prefix,
5545 neighbor_capability_orf_prefix_cmd,
5546 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5547 NEIGHBOR_STR
5548 NEIGHBOR_ADDR_STR2
5549 "Advertise capability to the peer\n"
5550 "Advertise ORF capability to the peer\n"
5551 "Advertise prefixlist ORF capability to this neighbor\n"
5552 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5553 "Capability to RECEIVE the ORF from this neighbor\n"
5554 "Capability to SEND the ORF to this neighbor\n")
5555 {
5556 int idx_send_recv = 5;
5557 char *peer_str = argv[1]->arg;
5558 struct peer *peer;
5559 afi_t afi = bgp_node_afi(vty);
5560 safi_t safi = bgp_node_safi(vty);
5561
5562 peer = peer_and_group_lookup_vty(vty, peer_str);
5563 if (!peer)
5564 return CMD_WARNING_CONFIG_FAILED;
5565
5566 if (strmatch(argv[idx_send_recv]->text, "send"))
5567 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5568 PEER_FLAG_ORF_PREFIX_SM);
5569
5570 if (strmatch(argv[idx_send_recv]->text, "receive"))
5571 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5572 PEER_FLAG_ORF_PREFIX_RM);
5573
5574 if (strmatch(argv[idx_send_recv]->text, "both"))
5575 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5576 PEER_FLAG_ORF_PREFIX_SM)
5577 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5578 PEER_FLAG_ORF_PREFIX_RM);
5579
5580 return CMD_WARNING_CONFIG_FAILED;
5581 }
5582
5583 ALIAS_HIDDEN(
5584 neighbor_capability_orf_prefix,
5585 neighbor_capability_orf_prefix_hidden_cmd,
5586 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5587 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5588 "Advertise capability to the peer\n"
5589 "Advertise ORF capability to the peer\n"
5590 "Advertise prefixlist ORF capability to this neighbor\n"
5591 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5592 "Capability to RECEIVE the ORF from this neighbor\n"
5593 "Capability to SEND the ORF to this neighbor\n")
5594
5595 DEFUN (no_neighbor_capability_orf_prefix,
5596 no_neighbor_capability_orf_prefix_cmd,
5597 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5598 NO_STR
5599 NEIGHBOR_STR
5600 NEIGHBOR_ADDR_STR2
5601 "Advertise capability to the peer\n"
5602 "Advertise ORF capability to the peer\n"
5603 "Advertise prefixlist ORF capability to this neighbor\n"
5604 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5605 "Capability to RECEIVE the ORF from this neighbor\n"
5606 "Capability to SEND the ORF to this neighbor\n")
5607 {
5608 int idx_send_recv = 6;
5609 char *peer_str = argv[2]->arg;
5610 struct peer *peer;
5611 afi_t afi = bgp_node_afi(vty);
5612 safi_t safi = bgp_node_safi(vty);
5613
5614 peer = peer_and_group_lookup_vty(vty, peer_str);
5615 if (!peer)
5616 return CMD_WARNING_CONFIG_FAILED;
5617
5618 if (strmatch(argv[idx_send_recv]->text, "send"))
5619 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5620 PEER_FLAG_ORF_PREFIX_SM);
5621
5622 if (strmatch(argv[idx_send_recv]->text, "receive"))
5623 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5624 PEER_FLAG_ORF_PREFIX_RM);
5625
5626 if (strmatch(argv[idx_send_recv]->text, "both"))
5627 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5628 PEER_FLAG_ORF_PREFIX_SM)
5629 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5630 PEER_FLAG_ORF_PREFIX_RM);
5631
5632 return CMD_WARNING_CONFIG_FAILED;
5633 }
5634
5635 ALIAS_HIDDEN(
5636 no_neighbor_capability_orf_prefix,
5637 no_neighbor_capability_orf_prefix_hidden_cmd,
5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5639 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5640 "Advertise capability to the peer\n"
5641 "Advertise ORF capability to the peer\n"
5642 "Advertise prefixlist ORF capability to this neighbor\n"
5643 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5644 "Capability to RECEIVE the ORF from this neighbor\n"
5645 "Capability to SEND the ORF to this neighbor\n")
5646
5647 /* neighbor next-hop-self. */
5648 DEFUN (neighbor_nexthop_self,
5649 neighbor_nexthop_self_cmd,
5650 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5651 NEIGHBOR_STR
5652 NEIGHBOR_ADDR_STR2
5653 "Disable the next hop calculation for this neighbor\n")
5654 {
5655 int idx_peer = 1;
5656 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5657 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5658 }
5659
5660 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5661 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5662 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5663 "Disable the next hop calculation for this neighbor\n")
5664
5665 /* neighbor next-hop-self. */
5666 DEFUN (neighbor_nexthop_self_force,
5667 neighbor_nexthop_self_force_cmd,
5668 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5669 NEIGHBOR_STR
5670 NEIGHBOR_ADDR_STR2
5671 "Disable the next hop calculation for this neighbor\n"
5672 "Set the next hop to self for reflected routes\n")
5673 {
5674 int idx_peer = 1;
5675 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5676 bgp_node_safi(vty),
5677 PEER_FLAG_FORCE_NEXTHOP_SELF);
5678 }
5679
5680 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5681 neighbor_nexthop_self_force_hidden_cmd,
5682 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5683 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5684 "Disable the next hop calculation for this neighbor\n"
5685 "Set the next hop to self for reflected routes\n")
5686
5687 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5688 neighbor_nexthop_self_all_hidden_cmd,
5689 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5690 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Disable the next hop calculation for this neighbor\n"
5692 "Set the next hop to self for reflected routes\n")
5693
5694 DEFUN (no_neighbor_nexthop_self,
5695 no_neighbor_nexthop_self_cmd,
5696 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5697 NO_STR
5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Disable the next hop calculation for this neighbor\n")
5701 {
5702 int idx_peer = 2;
5703 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5704 bgp_node_afi(vty), bgp_node_safi(vty),
5705 PEER_FLAG_NEXTHOP_SELF);
5706 }
5707
5708 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5709 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5710 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5711 "Disable the next hop calculation for this neighbor\n")
5712
5713 DEFUN (no_neighbor_nexthop_self_force,
5714 no_neighbor_nexthop_self_force_cmd,
5715 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5716 NO_STR
5717 NEIGHBOR_STR
5718 NEIGHBOR_ADDR_STR2
5719 "Disable the next hop calculation for this neighbor\n"
5720 "Set the next hop to self for reflected routes\n")
5721 {
5722 int idx_peer = 2;
5723 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5724 bgp_node_afi(vty), bgp_node_safi(vty),
5725 PEER_FLAG_FORCE_NEXTHOP_SELF);
5726 }
5727
5728 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5729 no_neighbor_nexthop_self_force_hidden_cmd,
5730 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5731 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5732 "Disable the next hop calculation for this neighbor\n"
5733 "Set the next hop to self for reflected routes\n")
5734
5735 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5736 no_neighbor_nexthop_self_all_hidden_cmd,
5737 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5738 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5739 "Disable the next hop calculation for this neighbor\n"
5740 "Set the next hop to self for reflected routes\n")
5741
5742 /* neighbor as-override */
5743 DEFUN (neighbor_as_override,
5744 neighbor_as_override_cmd,
5745 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5746 NEIGHBOR_STR
5747 NEIGHBOR_ADDR_STR2
5748 "Override ASNs in outbound updates if aspath equals remote-as\n")
5749 {
5750 int idx_peer = 1;
5751 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5752 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5753 }
5754
5755 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5756 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5757 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5758 "Override ASNs in outbound updates if aspath equals remote-as\n")
5759
5760 DEFUN (no_neighbor_as_override,
5761 no_neighbor_as_override_cmd,
5762 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5763 NO_STR
5764 NEIGHBOR_STR
5765 NEIGHBOR_ADDR_STR2
5766 "Override ASNs in outbound updates if aspath equals remote-as\n")
5767 {
5768 int idx_peer = 2;
5769 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5770 bgp_node_afi(vty), bgp_node_safi(vty),
5771 PEER_FLAG_AS_OVERRIDE);
5772 }
5773
5774 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5775 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5776 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5777 "Override ASNs in outbound updates if aspath equals remote-as\n")
5778
5779 /* neighbor remove-private-AS. */
5780 DEFUN (neighbor_remove_private_as,
5781 neighbor_remove_private_as_cmd,
5782 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5783 NEIGHBOR_STR
5784 NEIGHBOR_ADDR_STR2
5785 "Remove private ASNs in outbound updates\n")
5786 {
5787 int idx_peer = 1;
5788 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5789 bgp_node_safi(vty),
5790 PEER_FLAG_REMOVE_PRIVATE_AS);
5791 }
5792
5793 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5794 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5795 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5796 "Remove private ASNs in outbound updates\n")
5797
5798 DEFUN (neighbor_remove_private_as_all,
5799 neighbor_remove_private_as_all_cmd,
5800 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5801 NEIGHBOR_STR
5802 NEIGHBOR_ADDR_STR2
5803 "Remove private ASNs in outbound updates\n"
5804 "Apply to all AS numbers\n")
5805 {
5806 int idx_peer = 1;
5807 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5808 bgp_node_safi(vty),
5809 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5810 }
5811
5812 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5813 neighbor_remove_private_as_all_hidden_cmd,
5814 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5815 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5816 "Remove private ASNs in outbound updates\n"
5817 "Apply to all AS numbers\n")
5818
5819 DEFUN (neighbor_remove_private_as_replace_as,
5820 neighbor_remove_private_as_replace_as_cmd,
5821 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5822 NEIGHBOR_STR
5823 NEIGHBOR_ADDR_STR2
5824 "Remove private ASNs in outbound updates\n"
5825 "Replace private ASNs with our ASN in outbound updates\n")
5826 {
5827 int idx_peer = 1;
5828 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5829 bgp_node_safi(vty),
5830 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5831 }
5832
5833 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5834 neighbor_remove_private_as_replace_as_hidden_cmd,
5835 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5836 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5837 "Remove private ASNs in outbound updates\n"
5838 "Replace private ASNs with our ASN in outbound updates\n")
5839
5840 DEFUN (neighbor_remove_private_as_all_replace_as,
5841 neighbor_remove_private_as_all_replace_as_cmd,
5842 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5843 NEIGHBOR_STR
5844 NEIGHBOR_ADDR_STR2
5845 "Remove private ASNs in outbound updates\n"
5846 "Apply to all AS numbers\n"
5847 "Replace private ASNs with our ASN in outbound updates\n")
5848 {
5849 int idx_peer = 1;
5850 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5851 bgp_node_safi(vty),
5852 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5853 }
5854
5855 ALIAS_HIDDEN(
5856 neighbor_remove_private_as_all_replace_as,
5857 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5858 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5859 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5860 "Remove private ASNs in outbound updates\n"
5861 "Apply to all AS numbers\n"
5862 "Replace private ASNs with our ASN in outbound updates\n")
5863
5864 DEFUN (no_neighbor_remove_private_as,
5865 no_neighbor_remove_private_as_cmd,
5866 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5867 NO_STR
5868 NEIGHBOR_STR
5869 NEIGHBOR_ADDR_STR2
5870 "Remove private ASNs in outbound updates\n")
5871 {
5872 int idx_peer = 2;
5873 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5874 bgp_node_afi(vty), bgp_node_safi(vty),
5875 PEER_FLAG_REMOVE_PRIVATE_AS);
5876 }
5877
5878 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5879 no_neighbor_remove_private_as_hidden_cmd,
5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5881 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5882 "Remove private ASNs in outbound updates\n")
5883
5884 DEFUN (no_neighbor_remove_private_as_all,
5885 no_neighbor_remove_private_as_all_cmd,
5886 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5887 NO_STR
5888 NEIGHBOR_STR
5889 NEIGHBOR_ADDR_STR2
5890 "Remove private ASNs in outbound updates\n"
5891 "Apply to all AS numbers\n")
5892 {
5893 int idx_peer = 2;
5894 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5895 bgp_node_afi(vty), bgp_node_safi(vty),
5896 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5897 }
5898
5899 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5900 no_neighbor_remove_private_as_all_hidden_cmd,
5901 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5902 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5903 "Remove private ASNs in outbound updates\n"
5904 "Apply to all AS numbers\n")
5905
5906 DEFUN (no_neighbor_remove_private_as_replace_as,
5907 no_neighbor_remove_private_as_replace_as_cmd,
5908 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5909 NO_STR
5910 NEIGHBOR_STR
5911 NEIGHBOR_ADDR_STR2
5912 "Remove private ASNs in outbound updates\n"
5913 "Replace private ASNs with our ASN in outbound updates\n")
5914 {
5915 int idx_peer = 2;
5916 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5917 bgp_node_afi(vty), bgp_node_safi(vty),
5918 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5919 }
5920
5921 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5922 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5923 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5924 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5925 "Remove private ASNs in outbound updates\n"
5926 "Replace private ASNs with our ASN in outbound updates\n")
5927
5928 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5929 no_neighbor_remove_private_as_all_replace_as_cmd,
5930 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5931 NO_STR
5932 NEIGHBOR_STR
5933 NEIGHBOR_ADDR_STR2
5934 "Remove private ASNs in outbound updates\n"
5935 "Apply to all AS numbers\n"
5936 "Replace private ASNs with our ASN in outbound updates\n")
5937 {
5938 int idx_peer = 2;
5939 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5940 bgp_node_afi(vty), bgp_node_safi(vty),
5941 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5942 }
5943
5944 ALIAS_HIDDEN(
5945 no_neighbor_remove_private_as_all_replace_as,
5946 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5947 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5949 "Remove private ASNs in outbound updates\n"
5950 "Apply to all AS numbers\n"
5951 "Replace private ASNs with our ASN in outbound updates\n")
5952
5953
5954 /* neighbor send-community. */
5955 DEFUN (neighbor_send_community,
5956 neighbor_send_community_cmd,
5957 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5958 NEIGHBOR_STR
5959 NEIGHBOR_ADDR_STR2
5960 "Send Community attribute to this neighbor\n")
5961 {
5962 int idx_peer = 1;
5963
5964 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5965 bgp_node_safi(vty),
5966 PEER_FLAG_SEND_COMMUNITY);
5967 }
5968
5969 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5970 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5971 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5972 "Send Community attribute to this neighbor\n")
5973
5974 DEFUN (no_neighbor_send_community,
5975 no_neighbor_send_community_cmd,
5976 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5977 NO_STR
5978 NEIGHBOR_STR
5979 NEIGHBOR_ADDR_STR2
5980 "Send Community attribute to this neighbor\n")
5981 {
5982 int idx_peer = 2;
5983
5984 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5985 bgp_node_afi(vty), bgp_node_safi(vty),
5986 PEER_FLAG_SEND_COMMUNITY);
5987 }
5988
5989 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5990 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5991 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5992 "Send Community attribute to this neighbor\n")
5993
5994 /* neighbor send-community extended. */
5995 DEFUN (neighbor_send_community_type,
5996 neighbor_send_community_type_cmd,
5997 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5998 NEIGHBOR_STR
5999 NEIGHBOR_ADDR_STR2
6000 "Send Community attribute to this neighbor\n"
6001 "Send Standard and Extended Community attributes\n"
6002 "Send Standard, Large and Extended Community attributes\n"
6003 "Send Extended Community attributes\n"
6004 "Send Standard Community attributes\n"
6005 "Send Large Community attributes\n")
6006 {
6007 const char *type = argv[argc - 1]->text;
6008 char *peer_str = argv[1]->arg;
6009 struct peer *peer;
6010 afi_t afi = bgp_node_afi(vty);
6011 safi_t safi = bgp_node_safi(vty);
6012
6013 peer = peer_and_group_lookup_vty(vty, peer_str);
6014 if (!peer)
6015 return CMD_WARNING_CONFIG_FAILED;
6016
6017 if (strmatch(type, "standard"))
6018 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6019 PEER_FLAG_SEND_COMMUNITY);
6020
6021 if (strmatch(type, "extended"))
6022 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6023 PEER_FLAG_SEND_EXT_COMMUNITY);
6024
6025 if (strmatch(type, "large"))
6026 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6027 PEER_FLAG_SEND_LARGE_COMMUNITY);
6028
6029 if (strmatch(type, "both")) {
6030 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6031 PEER_FLAG_SEND_COMMUNITY)
6032 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6033 PEER_FLAG_SEND_EXT_COMMUNITY);
6034 }
6035 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6036 PEER_FLAG_SEND_COMMUNITY)
6037 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6038 PEER_FLAG_SEND_EXT_COMMUNITY)
6039 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6040 PEER_FLAG_SEND_LARGE_COMMUNITY);
6041 }
6042
6043 ALIAS_HIDDEN(
6044 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6045 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6046 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6047 "Send Community attribute to this neighbor\n"
6048 "Send Standard and Extended Community attributes\n"
6049 "Send Standard, Large and Extended Community attributes\n"
6050 "Send Extended Community attributes\n"
6051 "Send Standard Community attributes\n"
6052 "Send Large Community attributes\n")
6053
6054 DEFUN (no_neighbor_send_community_type,
6055 no_neighbor_send_community_type_cmd,
6056 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6057 NO_STR
6058 NEIGHBOR_STR
6059 NEIGHBOR_ADDR_STR2
6060 "Send Community attribute to this neighbor\n"
6061 "Send Standard and Extended Community attributes\n"
6062 "Send Standard, Large and Extended Community attributes\n"
6063 "Send Extended Community attributes\n"
6064 "Send Standard Community attributes\n"
6065 "Send Large Community attributes\n")
6066 {
6067 const char *type = argv[argc - 1]->text;
6068 char *peer_str = argv[2]->arg;
6069 struct peer *peer;
6070 afi_t afi = bgp_node_afi(vty);
6071 safi_t safi = bgp_node_safi(vty);
6072
6073 peer = peer_and_group_lookup_vty(vty, peer_str);
6074 if (!peer)
6075 return CMD_WARNING_CONFIG_FAILED;
6076
6077 if (strmatch(type, "standard"))
6078 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6079 PEER_FLAG_SEND_COMMUNITY);
6080
6081 if (strmatch(type, "extended"))
6082 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6083 PEER_FLAG_SEND_EXT_COMMUNITY);
6084
6085 if (strmatch(type, "large"))
6086 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6087 PEER_FLAG_SEND_LARGE_COMMUNITY);
6088
6089 if (strmatch(type, "both")) {
6090
6091 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6092 PEER_FLAG_SEND_COMMUNITY)
6093 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6094 PEER_FLAG_SEND_EXT_COMMUNITY);
6095 }
6096
6097 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6098 PEER_FLAG_SEND_COMMUNITY)
6099 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6100 PEER_FLAG_SEND_EXT_COMMUNITY)
6101 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6102 PEER_FLAG_SEND_LARGE_COMMUNITY);
6103 }
6104
6105 ALIAS_HIDDEN(
6106 no_neighbor_send_community_type,
6107 no_neighbor_send_community_type_hidden_cmd,
6108 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6110 "Send Community attribute to this neighbor\n"
6111 "Send Standard and Extended Community attributes\n"
6112 "Send Standard, Large and Extended Community attributes\n"
6113 "Send Extended Community attributes\n"
6114 "Send Standard Community attributes\n"
6115 "Send Large Community attributes\n")
6116
6117 /* neighbor soft-reconfig. */
6118 DEFUN (neighbor_soft_reconfiguration,
6119 neighbor_soft_reconfiguration_cmd,
6120 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6121 NEIGHBOR_STR
6122 NEIGHBOR_ADDR_STR2
6123 "Per neighbor soft reconfiguration\n"
6124 "Allow inbound soft reconfiguration for this neighbor\n")
6125 {
6126 int idx_peer = 1;
6127 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6128 bgp_node_safi(vty),
6129 PEER_FLAG_SOFT_RECONFIG);
6130 }
6131
6132 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6133 neighbor_soft_reconfiguration_hidden_cmd,
6134 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6135 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6136 "Per neighbor soft reconfiguration\n"
6137 "Allow inbound soft reconfiguration for this neighbor\n")
6138
6139 DEFUN (no_neighbor_soft_reconfiguration,
6140 no_neighbor_soft_reconfiguration_cmd,
6141 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6142 NO_STR
6143 NEIGHBOR_STR
6144 NEIGHBOR_ADDR_STR2
6145 "Per neighbor soft reconfiguration\n"
6146 "Allow inbound soft reconfiguration for this neighbor\n")
6147 {
6148 int idx_peer = 2;
6149 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6150 bgp_node_afi(vty), bgp_node_safi(vty),
6151 PEER_FLAG_SOFT_RECONFIG);
6152 }
6153
6154 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6155 no_neighbor_soft_reconfiguration_hidden_cmd,
6156 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6157 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6158 "Per neighbor soft reconfiguration\n"
6159 "Allow inbound soft reconfiguration for this neighbor\n")
6160
6161 DEFUN (neighbor_route_reflector_client,
6162 neighbor_route_reflector_client_cmd,
6163 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6164 NEIGHBOR_STR
6165 NEIGHBOR_ADDR_STR2
6166 "Configure a neighbor as Route Reflector client\n")
6167 {
6168 int idx_peer = 1;
6169 struct peer *peer;
6170
6171
6172 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6173 if (!peer)
6174 return CMD_WARNING_CONFIG_FAILED;
6175
6176 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6177 bgp_node_safi(vty),
6178 PEER_FLAG_REFLECTOR_CLIENT);
6179 }
6180
6181 ALIAS_HIDDEN(neighbor_route_reflector_client,
6182 neighbor_route_reflector_client_hidden_cmd,
6183 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6184 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6185 "Configure a neighbor as Route Reflector client\n")
6186
6187 DEFUN (no_neighbor_route_reflector_client,
6188 no_neighbor_route_reflector_client_cmd,
6189 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6190 NO_STR
6191 NEIGHBOR_STR
6192 NEIGHBOR_ADDR_STR2
6193 "Configure a neighbor as Route Reflector client\n")
6194 {
6195 int idx_peer = 2;
6196 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6197 bgp_node_afi(vty), bgp_node_safi(vty),
6198 PEER_FLAG_REFLECTOR_CLIENT);
6199 }
6200
6201 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6202 no_neighbor_route_reflector_client_hidden_cmd,
6203 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6204 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6205 "Configure a neighbor as Route Reflector client\n")
6206
6207 /* optimal-route-reflection Root Routers configuration */
6208 DEFPY (optimal_route_reflection,
6209 optimal_route_reflection_cmd,
6210 "[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]]]",
6211 NO_STR
6212 "Create ORR group and assign root router(s)\n"
6213 "ORR Group name\n"
6214 "Primary Root address\n"
6215 "Primary Root IPv6 address\n"
6216 "Secondary Root address\n"
6217 "Secondary Root IPv6 address\n"
6218 "Tertiary Root address\n"
6219 "Tertiary Root IPv6 address\n")
6220 {
6221 if (!no && !primary) {
6222 vty_out(vty, "%% Specify Primary Root address\n");
6223 return CMD_WARNING_CONFIG_FAILED;
6224 }
6225 return bgp_afi_safi_orr_group_set_vty(
6226 vty, bgp_node_afi(vty), bgp_node_safi(vty), orr_group,
6227 primary_str, secondary_str, tertiary_str, !!no);
6228 }
6229
6230 /* neighbor optimal-route-reflection group*/
6231 DEFPY (neighbor_optimal_route_reflection,
6232 neighbor_optimal_route_reflection_cmd,
6233 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor optimal-route-reflection WORD$orr_group",
6234 NO_STR
6235 NEIGHBOR_STR
6236 NEIGHBOR_ADDR_STR2
6237 "Apply ORR group configuration to the neighbor\n"
6238 "ORR group name\n")
6239 {
6240 return peer_orr_group_set_vty(vty, neighbor, bgp_node_afi(vty),
6241 bgp_node_safi(vty), orr_group, !!no);
6242 }
6243
6244 /* neighbor route-server-client. */
6245 DEFUN (neighbor_route_server_client,
6246 neighbor_route_server_client_cmd,
6247 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6248 NEIGHBOR_STR
6249 NEIGHBOR_ADDR_STR2
6250 "Configure a neighbor as Route Server client\n")
6251 {
6252 int idx_peer = 1;
6253 struct peer *peer;
6254
6255 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6256 if (!peer)
6257 return CMD_WARNING_CONFIG_FAILED;
6258 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6259 bgp_node_safi(vty),
6260 PEER_FLAG_RSERVER_CLIENT);
6261 }
6262
6263 ALIAS_HIDDEN(neighbor_route_server_client,
6264 neighbor_route_server_client_hidden_cmd,
6265 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6266 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6267 "Configure a neighbor as Route Server client\n")
6268
6269 DEFUN (no_neighbor_route_server_client,
6270 no_neighbor_route_server_client_cmd,
6271 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6272 NO_STR
6273 NEIGHBOR_STR
6274 NEIGHBOR_ADDR_STR2
6275 "Configure a neighbor as Route Server client\n")
6276 {
6277 int idx_peer = 2;
6278 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6279 bgp_node_afi(vty), bgp_node_safi(vty),
6280 PEER_FLAG_RSERVER_CLIENT);
6281 }
6282
6283 ALIAS_HIDDEN(no_neighbor_route_server_client,
6284 no_neighbor_route_server_client_hidden_cmd,
6285 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6286 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6287 "Configure a neighbor as Route Server client\n")
6288
6289 DEFUN (neighbor_nexthop_local_unchanged,
6290 neighbor_nexthop_local_unchanged_cmd,
6291 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6292 NEIGHBOR_STR
6293 NEIGHBOR_ADDR_STR2
6294 "Configure treatment of outgoing link-local nexthop attribute\n"
6295 "Leave link-local nexthop unchanged for this peer\n")
6296 {
6297 int idx_peer = 1;
6298 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6299 bgp_node_safi(vty),
6300 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6301 }
6302
6303 DEFUN (no_neighbor_nexthop_local_unchanged,
6304 no_neighbor_nexthop_local_unchanged_cmd,
6305 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6306 NO_STR
6307 NEIGHBOR_STR
6308 NEIGHBOR_ADDR_STR2
6309 "Configure treatment of outgoing link-local-nexthop attribute\n"
6310 "Leave link-local nexthop unchanged for this peer\n")
6311 {
6312 int idx_peer = 2;
6313 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6314 bgp_node_afi(vty), bgp_node_safi(vty),
6315 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6316 }
6317
6318 DEFUN (neighbor_attr_unchanged,
6319 neighbor_attr_unchanged_cmd,
6320 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6321 NEIGHBOR_STR
6322 NEIGHBOR_ADDR_STR2
6323 "BGP attribute is propagated unchanged to this neighbor\n"
6324 "As-path attribute\n"
6325 "Nexthop attribute\n"
6326 "Med attribute\n")
6327 {
6328 int idx = 0;
6329 char *peer_str = argv[1]->arg;
6330 struct peer *peer;
6331 bool aspath = false;
6332 bool nexthop = false;
6333 bool med = false;
6334 afi_t afi = bgp_node_afi(vty);
6335 safi_t safi = bgp_node_safi(vty);
6336 int ret = 0;
6337
6338 peer = peer_and_group_lookup_vty(vty, peer_str);
6339 if (!peer)
6340 return CMD_WARNING_CONFIG_FAILED;
6341
6342 if (argv_find(argv, argc, "as-path", &idx))
6343 aspath = true;
6344
6345 idx = 0;
6346 if (argv_find(argv, argc, "next-hop", &idx))
6347 nexthop = true;
6348
6349 idx = 0;
6350 if (argv_find(argv, argc, "med", &idx))
6351 med = true;
6352
6353 /* no flags means all of them! */
6354 if (!aspath && !nexthop && !med) {
6355 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6356 PEER_FLAG_AS_PATH_UNCHANGED);
6357 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6358 PEER_FLAG_NEXTHOP_UNCHANGED);
6359 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6360 PEER_FLAG_MED_UNCHANGED);
6361 } else {
6362 if (!aspath) {
6363 if (peer_af_flag_check(peer, afi, safi,
6364 PEER_FLAG_AS_PATH_UNCHANGED)) {
6365 ret |= peer_af_flag_unset_vty(
6366 vty, peer_str, afi, safi,
6367 PEER_FLAG_AS_PATH_UNCHANGED);
6368 }
6369 } else
6370 ret |= peer_af_flag_set_vty(
6371 vty, peer_str, afi, safi,
6372 PEER_FLAG_AS_PATH_UNCHANGED);
6373
6374 if (!nexthop) {
6375 if (peer_af_flag_check(peer, afi, safi,
6376 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6377 ret |= peer_af_flag_unset_vty(
6378 vty, peer_str, afi, safi,
6379 PEER_FLAG_NEXTHOP_UNCHANGED);
6380 }
6381 } else
6382 ret |= peer_af_flag_set_vty(
6383 vty, peer_str, afi, safi,
6384 PEER_FLAG_NEXTHOP_UNCHANGED);
6385
6386 if (!med) {
6387 if (peer_af_flag_check(peer, afi, safi,
6388 PEER_FLAG_MED_UNCHANGED)) {
6389 ret |= peer_af_flag_unset_vty(
6390 vty, peer_str, afi, safi,
6391 PEER_FLAG_MED_UNCHANGED);
6392 }
6393 } else
6394 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6395 PEER_FLAG_MED_UNCHANGED);
6396 }
6397
6398 return ret;
6399 }
6400
6401 ALIAS_HIDDEN(
6402 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6403 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6404 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6405 "BGP attribute is propagated unchanged to this neighbor\n"
6406 "As-path attribute\n"
6407 "Nexthop attribute\n"
6408 "Med attribute\n")
6409
6410 DEFUN (no_neighbor_attr_unchanged,
6411 no_neighbor_attr_unchanged_cmd,
6412 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6413 NO_STR
6414 NEIGHBOR_STR
6415 NEIGHBOR_ADDR_STR2
6416 "BGP attribute is propagated unchanged to this neighbor\n"
6417 "As-path attribute\n"
6418 "Nexthop attribute\n"
6419 "Med attribute\n")
6420 {
6421 int idx = 0;
6422 char *peer_str = argv[2]->arg;
6423 struct peer *peer;
6424 bool aspath = false;
6425 bool nexthop = false;
6426 bool med = false;
6427 afi_t afi = bgp_node_afi(vty);
6428 safi_t safi = bgp_node_safi(vty);
6429 int ret = 0;
6430
6431 peer = peer_and_group_lookup_vty(vty, peer_str);
6432 if (!peer)
6433 return CMD_WARNING_CONFIG_FAILED;
6434
6435 if (argv_find(argv, argc, "as-path", &idx))
6436 aspath = true;
6437
6438 idx = 0;
6439 if (argv_find(argv, argc, "next-hop", &idx))
6440 nexthop = true;
6441
6442 idx = 0;
6443 if (argv_find(argv, argc, "med", &idx))
6444 med = true;
6445
6446 if (!aspath && !nexthop && !med) // no flags means all of them!
6447 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6448 PEER_FLAG_AS_PATH_UNCHANGED)
6449 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6450 PEER_FLAG_NEXTHOP_UNCHANGED)
6451 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6452 PEER_FLAG_MED_UNCHANGED);
6453
6454 if (aspath)
6455 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6456 PEER_FLAG_AS_PATH_UNCHANGED);
6457
6458 if (nexthop)
6459 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6460 PEER_FLAG_NEXTHOP_UNCHANGED);
6461
6462 if (med)
6463 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6464 PEER_FLAG_MED_UNCHANGED);
6465
6466 return ret;
6467 }
6468
6469 ALIAS_HIDDEN(
6470 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6471 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6472 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6473 "BGP attribute is propagated unchanged to this neighbor\n"
6474 "As-path attribute\n"
6475 "Nexthop attribute\n"
6476 "Med attribute\n")
6477
6478 /* EBGP multihop configuration. */
6479 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6480 const char *ttl_str)
6481 {
6482 struct peer *peer;
6483 unsigned int ttl;
6484
6485 peer = peer_and_group_lookup_vty(vty, ip_str);
6486 if (!peer)
6487 return CMD_WARNING_CONFIG_FAILED;
6488
6489 if (peer->conf_if)
6490 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6491
6492 if (!ttl_str)
6493 ttl = MAXTTL;
6494 else
6495 ttl = strtoul(ttl_str, NULL, 10);
6496
6497 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6498 }
6499
6500 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6501 {
6502 struct peer *peer;
6503
6504 peer = peer_and_group_lookup_vty(vty, ip_str);
6505 if (!peer)
6506 return CMD_WARNING_CONFIG_FAILED;
6507
6508 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6509 }
6510
6511 /* neighbor ebgp-multihop. */
6512 DEFUN (neighbor_ebgp_multihop,
6513 neighbor_ebgp_multihop_cmd,
6514 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6515 NEIGHBOR_STR
6516 NEIGHBOR_ADDR_STR2
6517 "Allow EBGP neighbors not on directly connected networks\n")
6518 {
6519 int idx_peer = 1;
6520 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6521 }
6522
6523 DEFUN (neighbor_ebgp_multihop_ttl,
6524 neighbor_ebgp_multihop_ttl_cmd,
6525 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6526 NEIGHBOR_STR
6527 NEIGHBOR_ADDR_STR2
6528 "Allow EBGP neighbors not on directly connected networks\n"
6529 "maximum hop count\n")
6530 {
6531 int idx_peer = 1;
6532 int idx_number = 3;
6533 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6534 argv[idx_number]->arg);
6535 }
6536
6537 DEFUN (no_neighbor_ebgp_multihop,
6538 no_neighbor_ebgp_multihop_cmd,
6539 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6540 NO_STR
6541 NEIGHBOR_STR
6542 NEIGHBOR_ADDR_STR2
6543 "Allow EBGP neighbors not on directly connected networks\n"
6544 "maximum hop count\n")
6545 {
6546 int idx_peer = 2;
6547 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6548 }
6549
6550 static uint8_t get_role_by_name(const char *role_str)
6551 {
6552 if (strncmp(role_str, "peer", 2) == 0)
6553 return ROLE_PEER;
6554 if (strncmp(role_str, "provider", 2) == 0)
6555 return ROLE_PROVIDER;
6556 if (strncmp(role_str, "customer", 2) == 0)
6557 return ROLE_CUSTOMER;
6558 if (strncmp(role_str, "rs-server", 4) == 0)
6559 return ROLE_RS_SERVER;
6560 if (strncmp(role_str, "rs-client", 4) == 0)
6561 return ROLE_RS_CLIENT;
6562 return ROLE_UNDEFINED;
6563 }
6564
6565 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6566 const char *role_str, bool strict_mode)
6567 {
6568 struct peer *peer;
6569
6570 peer = peer_and_group_lookup_vty(vty, ip_str);
6571 if (!peer)
6572 return CMD_WARNING_CONFIG_FAILED;
6573 uint8_t role = get_role_by_name(role_str);
6574
6575 if (role == ROLE_UNDEFINED)
6576 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6577 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6578 }
6579
6580 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6581 {
6582 struct peer *peer;
6583
6584 peer = peer_and_group_lookup_vty(vty, ip_str);
6585 if (!peer)
6586 return CMD_WARNING_CONFIG_FAILED;
6587 return bgp_vty_return(vty, peer_role_unset(peer));
6588 }
6589
6590 DEFPY(neighbor_role,
6591 neighbor_role_cmd,
6592 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6593 NEIGHBOR_STR
6594 NEIGHBOR_ADDR_STR2
6595 "Set session role\n"
6596 ROLE_STR)
6597 {
6598 int idx_peer = 1;
6599 int idx_role = 3;
6600
6601 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6602 false);
6603 }
6604
6605 DEFPY(neighbor_role_strict,
6606 neighbor_role_strict_cmd,
6607 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6608 NEIGHBOR_STR
6609 NEIGHBOR_ADDR_STR2
6610 "Set session role\n"
6611 ROLE_STR
6612 "Use additional restriction on peer\n")
6613 {
6614 int idx_peer = 1;
6615 int idx_role = 3;
6616
6617 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6618 true);
6619 }
6620
6621 DEFPY(no_neighbor_role,
6622 no_neighbor_role_cmd,
6623 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6624 NO_STR
6625 NEIGHBOR_STR
6626 NEIGHBOR_ADDR_STR2
6627 "Set session role\n"
6628 ROLE_STR
6629 "Use additional restriction on peer\n")
6630 {
6631 int idx_peer = 2;
6632
6633 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6634 }
6635
6636 /* disable-connected-check */
6637 DEFUN (neighbor_disable_connected_check,
6638 neighbor_disable_connected_check_cmd,
6639 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6640 NEIGHBOR_STR
6641 NEIGHBOR_ADDR_STR2
6642 "one-hop away EBGP peer using loopback address\n"
6643 "Enforce EBGP neighbors perform multihop\n")
6644 {
6645 int idx_peer = 1;
6646 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6647 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6648 }
6649
6650 DEFUN (no_neighbor_disable_connected_check,
6651 no_neighbor_disable_connected_check_cmd,
6652 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6653 NO_STR
6654 NEIGHBOR_STR
6655 NEIGHBOR_ADDR_STR2
6656 "one-hop away EBGP peer using loopback address\n"
6657 "Enforce EBGP neighbors perform multihop\n")
6658 {
6659 int idx_peer = 2;
6660 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6661 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6662 }
6663
6664 /* disable-link-bw-encoding-ieee */
6665 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6666 neighbor_disable_link_bw_encoding_ieee_cmd,
6667 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6668 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6669 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6670 {
6671 int idx_peer = 1;
6672
6673 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6674 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6675 }
6676
6677 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6678 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6679 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6680 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6681 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6682 {
6683 int idx_peer = 2;
6684
6685 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6686 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6687 }
6688
6689 /* extended-optional-parameters */
6690 DEFUN(neighbor_extended_optional_parameters,
6691 neighbor_extended_optional_parameters_cmd,
6692 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6693 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6694 "Force the extended optional parameters format for OPEN messages\n")
6695 {
6696 int idx_peer = 1;
6697
6698 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6699 PEER_FLAG_EXTENDED_OPT_PARAMS);
6700 }
6701
6702 DEFUN(no_neighbor_extended_optional_parameters,
6703 no_neighbor_extended_optional_parameters_cmd,
6704 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6705 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6706 "Force the extended optional parameters format for OPEN messages\n")
6707 {
6708 int idx_peer = 2;
6709
6710 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6711 PEER_FLAG_EXTENDED_OPT_PARAMS);
6712 }
6713
6714 /* enforce-first-as */
6715 DEFUN (neighbor_enforce_first_as,
6716 neighbor_enforce_first_as_cmd,
6717 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6718 NEIGHBOR_STR
6719 NEIGHBOR_ADDR_STR2
6720 "Enforce the first AS for EBGP routes\n")
6721 {
6722 int idx_peer = 1;
6723
6724 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6725 PEER_FLAG_ENFORCE_FIRST_AS);
6726 }
6727
6728 DEFUN (no_neighbor_enforce_first_as,
6729 no_neighbor_enforce_first_as_cmd,
6730 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6731 NO_STR
6732 NEIGHBOR_STR
6733 NEIGHBOR_ADDR_STR2
6734 "Enforce the first AS for EBGP routes\n")
6735 {
6736 int idx_peer = 2;
6737
6738 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6739 PEER_FLAG_ENFORCE_FIRST_AS);
6740 }
6741
6742
6743 DEFUN (neighbor_description,
6744 neighbor_description_cmd,
6745 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6746 NEIGHBOR_STR
6747 NEIGHBOR_ADDR_STR2
6748 "Neighbor specific description\n"
6749 "Up to 80 characters describing this neighbor\n")
6750 {
6751 int idx_peer = 1;
6752 int idx_line = 3;
6753 struct peer *peer;
6754 char *str;
6755
6756 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6757 if (!peer)
6758 return CMD_WARNING_CONFIG_FAILED;
6759
6760 str = argv_concat(argv, argc, idx_line);
6761
6762 peer_description_set(peer, str);
6763
6764 XFREE(MTYPE_TMP, str);
6765
6766 return CMD_SUCCESS;
6767 }
6768
6769 DEFUN (no_neighbor_description,
6770 no_neighbor_description_cmd,
6771 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6772 NO_STR
6773 NEIGHBOR_STR
6774 NEIGHBOR_ADDR_STR2
6775 "Neighbor specific description\n")
6776 {
6777 int idx_peer = 2;
6778 struct peer *peer;
6779
6780 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6781 if (!peer)
6782 return CMD_WARNING_CONFIG_FAILED;
6783
6784 peer_description_unset(peer);
6785
6786 return CMD_SUCCESS;
6787 }
6788
6789 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6790 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6791 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6792 "Neighbor specific description\n"
6793 "Up to 80 characters describing this neighbor\n")
6794
6795 /* Neighbor update-source. */
6796 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6797 const char *source_str)
6798 {
6799 struct peer *peer;
6800 struct prefix p;
6801 union sockunion su;
6802
6803 peer = peer_and_group_lookup_vty(vty, peer_str);
6804 if (!peer)
6805 return CMD_WARNING_CONFIG_FAILED;
6806
6807 if (peer->conf_if)
6808 return CMD_WARNING;
6809
6810 if (source_str) {
6811 if (str2sockunion(source_str, &su) == 0)
6812 peer_update_source_addr_set(peer, &su);
6813 else {
6814 if (str2prefix(source_str, &p)) {
6815 vty_out(vty,
6816 "%% Invalid update-source, remove prefix length \n");
6817 return CMD_WARNING_CONFIG_FAILED;
6818 } else
6819 peer_update_source_if_set(peer, source_str);
6820 }
6821 } else
6822 peer_update_source_unset(peer);
6823
6824 return CMD_SUCCESS;
6825 }
6826
6827 #define BGP_UPDATE_SOURCE_HELP_STR \
6828 "IPv4 address\n" \
6829 "IPv6 address\n" \
6830 "Interface name (requires zebra to be running)\n"
6831
6832 DEFUN (neighbor_update_source,
6833 neighbor_update_source_cmd,
6834 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6835 NEIGHBOR_STR
6836 NEIGHBOR_ADDR_STR2
6837 "Source of routing updates\n"
6838 BGP_UPDATE_SOURCE_HELP_STR)
6839 {
6840 int idx_peer = 1;
6841 int idx_peer_2 = 3;
6842 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6843 argv[idx_peer_2]->arg);
6844 }
6845
6846 DEFUN (no_neighbor_update_source,
6847 no_neighbor_update_source_cmd,
6848 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6849 NO_STR
6850 NEIGHBOR_STR
6851 NEIGHBOR_ADDR_STR2
6852 "Source of routing updates\n"
6853 BGP_UPDATE_SOURCE_HELP_STR)
6854 {
6855 int idx_peer = 2;
6856 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6857 }
6858
6859 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6860 afi_t afi, safi_t safi,
6861 const char *rmap, int set)
6862 {
6863 int ret;
6864 struct peer *peer;
6865 struct route_map *route_map = NULL;
6866
6867 peer = peer_and_group_lookup_vty(vty, peer_str);
6868 if (!peer)
6869 return CMD_WARNING_CONFIG_FAILED;
6870
6871 if (set) {
6872 if (rmap)
6873 route_map = route_map_lookup_warn_noexist(vty, rmap);
6874 ret = peer_default_originate_set(peer, afi, safi,
6875 rmap, route_map);
6876 } else
6877 ret = peer_default_originate_unset(peer, afi, safi);
6878
6879 return bgp_vty_return(vty, ret);
6880 }
6881
6882 /* neighbor default-originate. */
6883 DEFUN (neighbor_default_originate,
6884 neighbor_default_originate_cmd,
6885 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6886 NEIGHBOR_STR
6887 NEIGHBOR_ADDR_STR2
6888 "Originate default route to this neighbor\n")
6889 {
6890 int idx_peer = 1;
6891 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6892 bgp_node_afi(vty),
6893 bgp_node_safi(vty), NULL, 1);
6894 }
6895
6896 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6897 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6899 "Originate default route to this neighbor\n")
6900
6901 DEFUN (neighbor_default_originate_rmap,
6902 neighbor_default_originate_rmap_cmd,
6903 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6904 NEIGHBOR_STR
6905 NEIGHBOR_ADDR_STR2
6906 "Originate default route to this neighbor\n"
6907 "Route-map to specify criteria to originate default\n"
6908 "route-map name\n")
6909 {
6910 int idx_peer = 1;
6911 int idx_word = 4;
6912 return peer_default_originate_set_vty(
6913 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6914 argv[idx_word]->arg, 1);
6915 }
6916
6917 ALIAS_HIDDEN(
6918 neighbor_default_originate_rmap,
6919 neighbor_default_originate_rmap_hidden_cmd,
6920 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6921 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6922 "Originate default route to this neighbor\n"
6923 "Route-map to specify criteria to originate default\n"
6924 "route-map name\n")
6925
6926 DEFUN (no_neighbor_default_originate,
6927 no_neighbor_default_originate_cmd,
6928 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6929 NO_STR
6930 NEIGHBOR_STR
6931 NEIGHBOR_ADDR_STR2
6932 "Originate default route to this neighbor\n"
6933 "Route-map to specify criteria to originate default\n"
6934 "route-map name\n")
6935 {
6936 int idx_peer = 2;
6937 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6938 bgp_node_afi(vty),
6939 bgp_node_safi(vty), NULL, 0);
6940 }
6941
6942 ALIAS_HIDDEN(
6943 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6944 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6946 "Originate default route to this neighbor\n"
6947 "Route-map to specify criteria to originate default\n"
6948 "route-map name\n")
6949
6950
6951 /* Set neighbor's BGP port. */
6952 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6953 const char *port_str)
6954 {
6955 struct peer *peer;
6956 uint16_t port;
6957 struct servent *sp;
6958
6959 peer = peer_and_group_lookup_vty(vty, ip_str);
6960 if (!peer)
6961 return CMD_WARNING_CONFIG_FAILED;
6962
6963 if (!port_str) {
6964 sp = getservbyname("bgp", "tcp");
6965 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6966 } else {
6967 port = strtoul(port_str, NULL, 10);
6968 }
6969
6970 peer_port_set(peer, port);
6971
6972 return CMD_SUCCESS;
6973 }
6974
6975 /* Set specified peer's BGP port. */
6976 DEFUN (neighbor_port,
6977 neighbor_port_cmd,
6978 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6979 NEIGHBOR_STR
6980 NEIGHBOR_ADDR_STR2
6981 "Neighbor's BGP port\n"
6982 "TCP port number\n")
6983 {
6984 int idx_ip = 1;
6985 int idx_number = 3;
6986 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6987 argv[idx_number]->arg);
6988 }
6989
6990 DEFUN (no_neighbor_port,
6991 no_neighbor_port_cmd,
6992 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6993 NO_STR
6994 NEIGHBOR_STR
6995 NEIGHBOR_ADDR_STR2
6996 "Neighbor's BGP port\n"
6997 "TCP port number\n")
6998 {
6999 int idx_ip = 2;
7000 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7001 }
7002
7003
7004 /* neighbor weight. */
7005 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7006 safi_t safi, const char *weight_str)
7007 {
7008 int ret;
7009 struct peer *peer;
7010 unsigned long weight;
7011
7012 peer = peer_and_group_lookup_vty(vty, ip_str);
7013 if (!peer)
7014 return CMD_WARNING_CONFIG_FAILED;
7015
7016 weight = strtoul(weight_str, NULL, 10);
7017
7018 ret = peer_weight_set(peer, afi, safi, weight);
7019 return bgp_vty_return(vty, ret);
7020 }
7021
7022 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7023 safi_t safi)
7024 {
7025 int ret;
7026 struct peer *peer;
7027
7028 peer = peer_and_group_lookup_vty(vty, ip_str);
7029 if (!peer)
7030 return CMD_WARNING_CONFIG_FAILED;
7031
7032 ret = peer_weight_unset(peer, afi, safi);
7033 return bgp_vty_return(vty, ret);
7034 }
7035
7036 DEFUN (neighbor_weight,
7037 neighbor_weight_cmd,
7038 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7039 NEIGHBOR_STR
7040 NEIGHBOR_ADDR_STR2
7041 "Set default weight for routes from this neighbor\n"
7042 "default weight\n")
7043 {
7044 int idx_peer = 1;
7045 int idx_number = 3;
7046 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7047 bgp_node_safi(vty), argv[idx_number]->arg);
7048 }
7049
7050 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7051 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7052 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7053 "Set default weight for routes from this neighbor\n"
7054 "default weight\n")
7055
7056 DEFUN (no_neighbor_weight,
7057 no_neighbor_weight_cmd,
7058 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7059 NO_STR
7060 NEIGHBOR_STR
7061 NEIGHBOR_ADDR_STR2
7062 "Set default weight for routes from this neighbor\n"
7063 "default weight\n")
7064 {
7065 int idx_peer = 2;
7066 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7067 bgp_node_afi(vty), bgp_node_safi(vty));
7068 }
7069
7070 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7071 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7072 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7073 "Set default weight for routes from this neighbor\n"
7074 "default weight\n")
7075
7076
7077 /* Override capability negotiation. */
7078 DEFUN (neighbor_override_capability,
7079 neighbor_override_capability_cmd,
7080 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7081 NEIGHBOR_STR
7082 NEIGHBOR_ADDR_STR2
7083 "Override capability negotiation result\n")
7084 {
7085 int idx_peer = 1;
7086 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7087 PEER_FLAG_OVERRIDE_CAPABILITY);
7088 }
7089
7090 DEFUN (no_neighbor_override_capability,
7091 no_neighbor_override_capability_cmd,
7092 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7093 NO_STR
7094 NEIGHBOR_STR
7095 NEIGHBOR_ADDR_STR2
7096 "Override capability negotiation result\n")
7097 {
7098 int idx_peer = 2;
7099 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7100 PEER_FLAG_OVERRIDE_CAPABILITY);
7101 }
7102
7103 DEFUN (neighbor_strict_capability,
7104 neighbor_strict_capability_cmd,
7105 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7106 NEIGHBOR_STR
7107 NEIGHBOR_ADDR_STR2
7108 "Strict capability negotiation match\n")
7109 {
7110 int idx_peer = 1;
7111
7112 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7113 PEER_FLAG_STRICT_CAP_MATCH);
7114 }
7115
7116 DEFUN (no_neighbor_strict_capability,
7117 no_neighbor_strict_capability_cmd,
7118 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7119 NO_STR
7120 NEIGHBOR_STR
7121 NEIGHBOR_ADDR_STR2
7122 "Strict capability negotiation match\n")
7123 {
7124 int idx_peer = 2;
7125
7126 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7127 PEER_FLAG_STRICT_CAP_MATCH);
7128 }
7129
7130 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7131 const char *keep_str, const char *hold_str)
7132 {
7133 int ret;
7134 struct peer *peer;
7135 uint32_t keepalive;
7136 uint32_t holdtime;
7137
7138 peer = peer_and_group_lookup_vty(vty, ip_str);
7139 if (!peer)
7140 return CMD_WARNING_CONFIG_FAILED;
7141
7142 keepalive = strtoul(keep_str, NULL, 10);
7143 holdtime = strtoul(hold_str, NULL, 10);
7144
7145 ret = peer_timers_set(peer, keepalive, holdtime);
7146
7147 return bgp_vty_return(vty, ret);
7148 }
7149
7150 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7151 {
7152 int ret;
7153 struct peer *peer;
7154
7155 peer = peer_and_group_lookup_vty(vty, ip_str);
7156 if (!peer)
7157 return CMD_WARNING_CONFIG_FAILED;
7158
7159 ret = peer_timers_unset(peer);
7160
7161 return bgp_vty_return(vty, ret);
7162 }
7163
7164 DEFUN (neighbor_timers,
7165 neighbor_timers_cmd,
7166 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7167 NEIGHBOR_STR
7168 NEIGHBOR_ADDR_STR2
7169 "BGP per neighbor timers\n"
7170 "Keepalive interval\n"
7171 "Holdtime\n")
7172 {
7173 int idx_peer = 1;
7174 int idx_number = 3;
7175 int idx_number_2 = 4;
7176 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7177 argv[idx_number]->arg,
7178 argv[idx_number_2]->arg);
7179 }
7180
7181 DEFUN (no_neighbor_timers,
7182 no_neighbor_timers_cmd,
7183 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7184 NO_STR
7185 NEIGHBOR_STR
7186 NEIGHBOR_ADDR_STR2
7187 "BGP per neighbor timers\n"
7188 "Keepalive interval\n"
7189 "Holdtime\n")
7190 {
7191 int idx_peer = 2;
7192 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7193 }
7194
7195
7196 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7197 const char *time_str)
7198 {
7199 int ret;
7200 struct peer *peer;
7201 uint32_t connect;
7202
7203 peer = peer_and_group_lookup_vty(vty, ip_str);
7204 if (!peer)
7205 return CMD_WARNING_CONFIG_FAILED;
7206
7207 connect = strtoul(time_str, NULL, 10);
7208
7209 ret = peer_timers_connect_set(peer, connect);
7210
7211 return bgp_vty_return(vty, ret);
7212 }
7213
7214 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7215 {
7216 int ret;
7217 struct peer *peer;
7218
7219 peer = peer_and_group_lookup_vty(vty, ip_str);
7220 if (!peer)
7221 return CMD_WARNING_CONFIG_FAILED;
7222
7223 ret = peer_timers_connect_unset(peer);
7224
7225 return bgp_vty_return(vty, ret);
7226 }
7227
7228 DEFUN (neighbor_timers_connect,
7229 neighbor_timers_connect_cmd,
7230 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7231 NEIGHBOR_STR
7232 NEIGHBOR_ADDR_STR2
7233 "BGP per neighbor timers\n"
7234 "BGP connect timer\n"
7235 "Connect timer\n")
7236 {
7237 int idx_peer = 1;
7238 int idx_number = 4;
7239 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7240 argv[idx_number]->arg);
7241 }
7242
7243 DEFUN (no_neighbor_timers_connect,
7244 no_neighbor_timers_connect_cmd,
7245 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7246 NO_STR
7247 NEIGHBOR_STR
7248 NEIGHBOR_ADDR_STR2
7249 "BGP per neighbor timers\n"
7250 "BGP connect timer\n"
7251 "Connect timer\n")
7252 {
7253 int idx_peer = 2;
7254 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7255 }
7256
7257 DEFPY (neighbor_timers_delayopen,
7258 neighbor_timers_delayopen_cmd,
7259 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7260 NEIGHBOR_STR
7261 NEIGHBOR_ADDR_STR2
7262 "BGP per neighbor timers\n"
7263 "RFC 4271 DelayOpenTimer\n"
7264 "DelayOpenTime timer interval\n")
7265 {
7266 struct peer *peer;
7267
7268 peer = peer_and_group_lookup_vty(vty, neighbor);
7269 if (!peer)
7270 return CMD_WARNING_CONFIG_FAILED;
7271
7272 if (!interval) {
7273 if (peer_timers_delayopen_unset(peer))
7274 return CMD_WARNING_CONFIG_FAILED;
7275 } else {
7276 if (peer_timers_delayopen_set(peer, interval))
7277 return CMD_WARNING_CONFIG_FAILED;
7278 }
7279
7280 return CMD_SUCCESS;
7281 }
7282
7283 DEFPY (no_neighbor_timers_delayopen,
7284 no_neighbor_timers_delayopen_cmd,
7285 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7286 NO_STR
7287 NEIGHBOR_STR
7288 NEIGHBOR_ADDR_STR2
7289 "BGP per neighbor timers\n"
7290 "RFC 4271 DelayOpenTimer\n"
7291 "DelayOpenTime timer interval\n")
7292 {
7293 struct peer *peer;
7294
7295 peer = peer_and_group_lookup_vty(vty, neighbor);
7296 if (!peer)
7297 return CMD_WARNING_CONFIG_FAILED;
7298
7299 if (peer_timers_delayopen_unset(peer))
7300 return CMD_WARNING_CONFIG_FAILED;
7301
7302 return CMD_SUCCESS;
7303 }
7304
7305 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7306 const char *time_str, int set)
7307 {
7308 int ret;
7309 struct peer *peer;
7310 uint32_t routeadv = 0;
7311
7312 peer = peer_and_group_lookup_vty(vty, ip_str);
7313 if (!peer)
7314 return CMD_WARNING_CONFIG_FAILED;
7315
7316 if (time_str)
7317 routeadv = strtoul(time_str, NULL, 10);
7318
7319 if (set)
7320 ret = peer_advertise_interval_set(peer, routeadv);
7321 else
7322 ret = peer_advertise_interval_unset(peer);
7323
7324 return bgp_vty_return(vty, ret);
7325 }
7326
7327 DEFUN (neighbor_advertise_interval,
7328 neighbor_advertise_interval_cmd,
7329 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7330 NEIGHBOR_STR
7331 NEIGHBOR_ADDR_STR2
7332 "Minimum interval between sending BGP routing updates\n"
7333 "time in seconds\n")
7334 {
7335 int idx_peer = 1;
7336 int idx_number = 3;
7337 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7338 argv[idx_number]->arg, 1);
7339 }
7340
7341 DEFUN (no_neighbor_advertise_interval,
7342 no_neighbor_advertise_interval_cmd,
7343 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7344 NO_STR
7345 NEIGHBOR_STR
7346 NEIGHBOR_ADDR_STR2
7347 "Minimum interval between sending BGP routing updates\n"
7348 "time in seconds\n")
7349 {
7350 int idx_peer = 2;
7351 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7352 }
7353
7354
7355 /* Time to wait before processing route-map updates */
7356 DEFUN (bgp_set_route_map_delay_timer,
7357 bgp_set_route_map_delay_timer_cmd,
7358 "bgp route-map delay-timer (0-600)",
7359 SET_STR
7360 "BGP route-map delay timer\n"
7361 "Time in secs to wait before processing route-map changes\n"
7362 "0 disables the timer, no route updates happen when route-maps change\n")
7363 {
7364 int idx_number = 3;
7365 uint32_t rmap_delay_timer;
7366
7367 if (argv[idx_number]->arg) {
7368 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7369 bm->rmap_update_timer = rmap_delay_timer;
7370
7371 /* if the dynamic update handling is being disabled, and a timer
7372 * is
7373 * running, stop the timer and act as if the timer has already
7374 * fired.
7375 */
7376 if (!rmap_delay_timer && bm->t_rmap_update) {
7377 THREAD_OFF(bm->t_rmap_update);
7378 thread_execute(bm->master, bgp_route_map_update_timer,
7379 NULL, 0);
7380 }
7381 return CMD_SUCCESS;
7382 } else {
7383 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7384 return CMD_WARNING_CONFIG_FAILED;
7385 }
7386 }
7387
7388 DEFUN (no_bgp_set_route_map_delay_timer,
7389 no_bgp_set_route_map_delay_timer_cmd,
7390 "no bgp route-map delay-timer [(0-600)]",
7391 NO_STR
7392 BGP_STR
7393 "Default BGP route-map delay timer\n"
7394 "Reset to default time to wait for processing route-map changes\n"
7395 "0 disables the timer, no route updates happen when route-maps change\n")
7396 {
7397
7398 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7399
7400 return CMD_SUCCESS;
7401 }
7402
7403 /* neighbor interface */
7404 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7405 const char *str)
7406 {
7407 struct peer *peer;
7408
7409 peer = peer_lookup_vty(vty, ip_str);
7410 if (!peer || peer->conf_if) {
7411 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7412 return CMD_WARNING_CONFIG_FAILED;
7413 }
7414
7415 if (str)
7416 peer_interface_set(peer, str);
7417 else
7418 peer_interface_unset(peer);
7419
7420 return CMD_SUCCESS;
7421 }
7422
7423 DEFUN (neighbor_interface,
7424 neighbor_interface_cmd,
7425 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7426 NEIGHBOR_STR
7427 NEIGHBOR_ADDR_STR
7428 "Interface\n"
7429 "Interface name\n")
7430 {
7431 int idx_ip = 1;
7432 int idx_word = 3;
7433
7434 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7435 }
7436
7437 DEFUN (no_neighbor_interface,
7438 no_neighbor_interface_cmd,
7439 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7440 NO_STR
7441 NEIGHBOR_STR
7442 NEIGHBOR_ADDR_STR
7443 "Interface\n"
7444 "Interface name\n")
7445 {
7446 int idx_peer = 2;
7447
7448 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7449 }
7450
7451 DEFUN (neighbor_distribute_list,
7452 neighbor_distribute_list_cmd,
7453 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7454 NEIGHBOR_STR
7455 NEIGHBOR_ADDR_STR2
7456 "Filter updates to/from this neighbor\n"
7457 "IP Access-list name\n"
7458 "Filter incoming updates\n"
7459 "Filter outgoing updates\n")
7460 {
7461 int idx_peer = 1;
7462 int idx_acl = 3;
7463 int direct, ret;
7464 struct peer *peer;
7465
7466 const char *pstr = argv[idx_peer]->arg;
7467 const char *acl = argv[idx_acl]->arg;
7468 const char *inout = argv[argc - 1]->text;
7469
7470 peer = peer_and_group_lookup_vty(vty, pstr);
7471 if (!peer)
7472 return CMD_WARNING_CONFIG_FAILED;
7473
7474 /* Check filter direction. */
7475 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7476 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7477 direct, acl);
7478
7479 return bgp_vty_return(vty, ret);
7480 }
7481
7482 ALIAS_HIDDEN(
7483 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7484 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7485 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7486 "Filter updates to/from this neighbor\n"
7487 "IP Access-list name\n"
7488 "Filter incoming updates\n"
7489 "Filter outgoing updates\n")
7490
7491 DEFUN (no_neighbor_distribute_list,
7492 no_neighbor_distribute_list_cmd,
7493 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7494 NO_STR
7495 NEIGHBOR_STR
7496 NEIGHBOR_ADDR_STR2
7497 "Filter updates to/from this neighbor\n"
7498 "IP Access-list name\n"
7499 "Filter incoming updates\n"
7500 "Filter outgoing updates\n")
7501 {
7502 int idx_peer = 2;
7503 int direct, ret;
7504 struct peer *peer;
7505
7506 const char *pstr = argv[idx_peer]->arg;
7507 const char *inout = argv[argc - 1]->text;
7508
7509 peer = peer_and_group_lookup_vty(vty, pstr);
7510 if (!peer)
7511 return CMD_WARNING_CONFIG_FAILED;
7512
7513 /* Check filter direction. */
7514 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7515 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7516 direct);
7517
7518 return bgp_vty_return(vty, ret);
7519 }
7520
7521 ALIAS_HIDDEN(
7522 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7523 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7524 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7525 "Filter updates to/from this neighbor\n"
7526 "IP Access-list name\n"
7527 "Filter incoming updates\n"
7528 "Filter outgoing updates\n")
7529
7530 /* Set prefix list to the peer. */
7531 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7532 afi_t afi, safi_t safi,
7533 const char *name_str,
7534 const char *direct_str)
7535 {
7536 int ret;
7537 int direct = FILTER_IN;
7538 struct peer *peer;
7539
7540 peer = peer_and_group_lookup_vty(vty, ip_str);
7541 if (!peer)
7542 return CMD_WARNING_CONFIG_FAILED;
7543
7544 /* Check filter direction. */
7545 if (strncmp(direct_str, "i", 1) == 0)
7546 direct = FILTER_IN;
7547 else if (strncmp(direct_str, "o", 1) == 0)
7548 direct = FILTER_OUT;
7549
7550 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7551
7552 return bgp_vty_return(vty, ret);
7553 }
7554
7555 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7556 afi_t afi, safi_t safi,
7557 const char *direct_str)
7558 {
7559 int ret;
7560 struct peer *peer;
7561 int direct = FILTER_IN;
7562
7563 peer = peer_and_group_lookup_vty(vty, ip_str);
7564 if (!peer)
7565 return CMD_WARNING_CONFIG_FAILED;
7566
7567 /* Check filter direction. */
7568 if (strncmp(direct_str, "i", 1) == 0)
7569 direct = FILTER_IN;
7570 else if (strncmp(direct_str, "o", 1) == 0)
7571 direct = FILTER_OUT;
7572
7573 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7574
7575 return bgp_vty_return(vty, ret);
7576 }
7577
7578 DEFUN (neighbor_prefix_list,
7579 neighbor_prefix_list_cmd,
7580 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7581 NEIGHBOR_STR
7582 NEIGHBOR_ADDR_STR2
7583 "Filter updates to/from this neighbor\n"
7584 "Name of a prefix list\n"
7585 "Filter incoming updates\n"
7586 "Filter outgoing updates\n")
7587 {
7588 int idx_peer = 1;
7589 int idx_word = 3;
7590 int idx_in_out = 4;
7591 return peer_prefix_list_set_vty(
7592 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7593 argv[idx_word]->arg, argv[idx_in_out]->arg);
7594 }
7595
7596 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7597 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7598 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7599 "Filter updates to/from this neighbor\n"
7600 "Name of a prefix list\n"
7601 "Filter incoming updates\n"
7602 "Filter outgoing updates\n")
7603
7604 DEFUN (no_neighbor_prefix_list,
7605 no_neighbor_prefix_list_cmd,
7606 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7607 NO_STR
7608 NEIGHBOR_STR
7609 NEIGHBOR_ADDR_STR2
7610 "Filter updates to/from this neighbor\n"
7611 "Name of a prefix list\n"
7612 "Filter incoming updates\n"
7613 "Filter outgoing updates\n")
7614 {
7615 int idx_peer = 2;
7616 int idx_in_out = 5;
7617 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7618 bgp_node_afi(vty), bgp_node_safi(vty),
7619 argv[idx_in_out]->arg);
7620 }
7621
7622 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7623 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7624 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7625 "Filter updates to/from this neighbor\n"
7626 "Name of a prefix list\n"
7627 "Filter incoming updates\n"
7628 "Filter outgoing updates\n")
7629
7630 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7631 safi_t safi, const char *name_str,
7632 const char *direct_str)
7633 {
7634 int ret;
7635 struct peer *peer;
7636 int direct = FILTER_IN;
7637
7638 peer = peer_and_group_lookup_vty(vty, ip_str);
7639 if (!peer)
7640 return CMD_WARNING_CONFIG_FAILED;
7641
7642 /* Check filter direction. */
7643 if (strncmp(direct_str, "i", 1) == 0)
7644 direct = FILTER_IN;
7645 else if (strncmp(direct_str, "o", 1) == 0)
7646 direct = FILTER_OUT;
7647
7648 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7649
7650 return bgp_vty_return(vty, ret);
7651 }
7652
7653 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7654 safi_t safi, const char *direct_str)
7655 {
7656 int ret;
7657 struct peer *peer;
7658 int direct = FILTER_IN;
7659
7660 peer = peer_and_group_lookup_vty(vty, ip_str);
7661 if (!peer)
7662 return CMD_WARNING_CONFIG_FAILED;
7663
7664 /* Check filter direction. */
7665 if (strncmp(direct_str, "i", 1) == 0)
7666 direct = FILTER_IN;
7667 else if (strncmp(direct_str, "o", 1) == 0)
7668 direct = FILTER_OUT;
7669
7670 ret = peer_aslist_unset(peer, afi, safi, direct);
7671
7672 return bgp_vty_return(vty, ret);
7673 }
7674
7675 DEFUN (neighbor_filter_list,
7676 neighbor_filter_list_cmd,
7677 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7678 NEIGHBOR_STR
7679 NEIGHBOR_ADDR_STR2
7680 "Establish BGP filters\n"
7681 "AS path access-list name\n"
7682 "Filter incoming routes\n"
7683 "Filter outgoing routes\n")
7684 {
7685 int idx_peer = 1;
7686 int idx_word = 3;
7687 int idx_in_out = 4;
7688 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7689 bgp_node_safi(vty), argv[idx_word]->arg,
7690 argv[idx_in_out]->arg);
7691 }
7692
7693 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7694 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7695 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7696 "Establish BGP filters\n"
7697 "AS path access-list name\n"
7698 "Filter incoming routes\n"
7699 "Filter outgoing routes\n")
7700
7701 DEFUN (no_neighbor_filter_list,
7702 no_neighbor_filter_list_cmd,
7703 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7704 NO_STR
7705 NEIGHBOR_STR
7706 NEIGHBOR_ADDR_STR2
7707 "Establish BGP filters\n"
7708 "AS path access-list name\n"
7709 "Filter incoming routes\n"
7710 "Filter outgoing routes\n")
7711 {
7712 int idx_peer = 2;
7713 int idx_in_out = 5;
7714 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7715 bgp_node_afi(vty), bgp_node_safi(vty),
7716 argv[idx_in_out]->arg);
7717 }
7718
7719 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7720 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7721 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7722 "Establish BGP filters\n"
7723 "AS path access-list name\n"
7724 "Filter incoming routes\n"
7725 "Filter outgoing routes\n")
7726
7727 /* Set advertise-map to the peer. */
7728 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7729 afi_t afi, safi_t safi,
7730 const char *advertise_str,
7731 const char *condition_str, bool condition,
7732 bool set)
7733 {
7734 int ret = CMD_WARNING_CONFIG_FAILED;
7735 struct peer *peer;
7736 struct route_map *advertise_map;
7737 struct route_map *condition_map;
7738
7739 peer = peer_and_group_lookup_vty(vty, ip_str);
7740 if (!peer)
7741 return ret;
7742
7743 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7744 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7745
7746 if (set)
7747 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7748 advertise_map, condition_str,
7749 condition_map, condition);
7750 else
7751 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7752 advertise_map, condition_str,
7753 condition_map, condition);
7754
7755 return bgp_vty_return(vty, ret);
7756 }
7757
7758 DEFPY (bgp_condadv_period,
7759 bgp_condadv_period_cmd,
7760 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7761 NO_STR
7762 BGP_STR
7763 "Conditional advertisement settings\n"
7764 "Set period to rescan BGP table to check if condition is met\n"
7765 "Period between BGP table scans, in seconds; default 60\n")
7766 {
7767 VTY_DECLVAR_CONTEXT(bgp, bgp);
7768
7769 bgp->condition_check_period =
7770 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7771
7772 return CMD_SUCCESS;
7773 }
7774
7775 DEFPY (neighbor_advertise_map,
7776 neighbor_advertise_map_cmd,
7777 "[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",
7778 NO_STR
7779 NEIGHBOR_STR
7780 NEIGHBOR_ADDR_STR2
7781 "Route-map to conditionally advertise routes\n"
7782 "Name of advertise map\n"
7783 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7784 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7785 "Name of the exist or non exist map\n")
7786 {
7787 bool condition = CONDITION_EXIST;
7788
7789 if (!strcmp(exist, "non-exist-map"))
7790 condition = CONDITION_NON_EXIST;
7791
7792 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7793 bgp_node_safi(vty), advertise_str,
7794 condition_str, condition, !no);
7795 }
7796
7797 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7798 "[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",
7799 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7800 "Route-map to conditionally advertise routes\n"
7801 "Name of advertise map\n"
7802 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7803 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7804 "Name of the exist or non exist map\n")
7805
7806 /* Set route-map to the peer. */
7807 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7808 afi_t afi, safi_t safi, const char *name_str,
7809 const char *direct_str)
7810 {
7811 int ret;
7812 struct peer *peer;
7813 int direct = RMAP_IN;
7814 struct route_map *route_map;
7815
7816 peer = peer_and_group_lookup_vty(vty, ip_str);
7817 if (!peer)
7818 return CMD_WARNING_CONFIG_FAILED;
7819
7820 /* Check filter direction. */
7821 if (strncmp(direct_str, "in", 2) == 0)
7822 direct = RMAP_IN;
7823 else if (strncmp(direct_str, "o", 1) == 0)
7824 direct = RMAP_OUT;
7825
7826 route_map = route_map_lookup_warn_noexist(vty, name_str);
7827 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7828
7829 return bgp_vty_return(vty, ret);
7830 }
7831
7832 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7833 afi_t afi, safi_t safi,
7834 const char *direct_str)
7835 {
7836 int ret;
7837 struct peer *peer;
7838 int direct = RMAP_IN;
7839
7840 peer = peer_and_group_lookup_vty(vty, ip_str);
7841 if (!peer)
7842 return CMD_WARNING_CONFIG_FAILED;
7843
7844 /* Check filter direction. */
7845 if (strncmp(direct_str, "in", 2) == 0)
7846 direct = RMAP_IN;
7847 else if (strncmp(direct_str, "o", 1) == 0)
7848 direct = RMAP_OUT;
7849
7850 ret = peer_route_map_unset(peer, afi, safi, direct);
7851
7852 return bgp_vty_return(vty, ret);
7853 }
7854
7855 DEFUN (neighbor_route_map,
7856 neighbor_route_map_cmd,
7857 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7858 NEIGHBOR_STR
7859 NEIGHBOR_ADDR_STR2
7860 "Apply route map to neighbor\n"
7861 "Name of route map\n"
7862 "Apply map to incoming routes\n"
7863 "Apply map to outbound routes\n")
7864 {
7865 int idx_peer = 1;
7866 int idx_word = 3;
7867 int idx_in_out = 4;
7868 return peer_route_map_set_vty(
7869 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7870 argv[idx_word]->arg, argv[idx_in_out]->arg);
7871 }
7872
7873 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7874 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7876 "Apply route map to neighbor\n"
7877 "Name of route map\n"
7878 "Apply map to incoming routes\n"
7879 "Apply map to outbound routes\n")
7880
7881 DEFUN (no_neighbor_route_map,
7882 no_neighbor_route_map_cmd,
7883 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7884 NO_STR
7885 NEIGHBOR_STR
7886 NEIGHBOR_ADDR_STR2
7887 "Apply route map to neighbor\n"
7888 "Name of route map\n"
7889 "Apply map to incoming routes\n"
7890 "Apply map to outbound routes\n")
7891 {
7892 int idx_peer = 2;
7893 int idx_in_out = 5;
7894 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7895 bgp_node_afi(vty), bgp_node_safi(vty),
7896 argv[idx_in_out]->arg);
7897 }
7898
7899 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7900 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7901 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7902 "Apply route map to neighbor\n"
7903 "Name of route map\n"
7904 "Apply map to incoming routes\n"
7905 "Apply map to outbound routes\n")
7906
7907 /* Set unsuppress-map to the peer. */
7908 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7909 afi_t afi, safi_t safi,
7910 const char *name_str)
7911 {
7912 int ret;
7913 struct peer *peer;
7914 struct route_map *route_map;
7915
7916 peer = peer_and_group_lookup_vty(vty, ip_str);
7917 if (!peer)
7918 return CMD_WARNING_CONFIG_FAILED;
7919
7920 route_map = route_map_lookup_warn_noexist(vty, name_str);
7921 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7922
7923 return bgp_vty_return(vty, ret);
7924 }
7925
7926 /* Unset route-map from the peer. */
7927 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7928 afi_t afi, safi_t safi)
7929 {
7930 int ret;
7931 struct peer *peer;
7932
7933 peer = peer_and_group_lookup_vty(vty, ip_str);
7934 if (!peer)
7935 return CMD_WARNING_CONFIG_FAILED;
7936
7937 ret = peer_unsuppress_map_unset(peer, afi, safi);
7938
7939 return bgp_vty_return(vty, ret);
7940 }
7941
7942 DEFUN (neighbor_unsuppress_map,
7943 neighbor_unsuppress_map_cmd,
7944 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7945 NEIGHBOR_STR
7946 NEIGHBOR_ADDR_STR2
7947 "Route-map to selectively unsuppress suppressed routes\n"
7948 "Name of route map\n")
7949 {
7950 int idx_peer = 1;
7951 int idx_word = 3;
7952 return peer_unsuppress_map_set_vty(
7953 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7954 argv[idx_word]->arg);
7955 }
7956
7957 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7958 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7959 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7960 "Route-map to selectively unsuppress suppressed routes\n"
7961 "Name of route map\n")
7962
7963 DEFUN (no_neighbor_unsuppress_map,
7964 no_neighbor_unsuppress_map_cmd,
7965 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7966 NO_STR
7967 NEIGHBOR_STR
7968 NEIGHBOR_ADDR_STR2
7969 "Route-map to selectively unsuppress suppressed routes\n"
7970 "Name of route map\n")
7971 {
7972 int idx_peer = 2;
7973 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7974 bgp_node_afi(vty),
7975 bgp_node_safi(vty));
7976 }
7977
7978 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7979 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7980 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7981 "Route-map to selectively unsuppress suppressed routes\n"
7982 "Name of route map\n")
7983
7984 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7985 afi_t afi, safi_t safi,
7986 const char *num_str,
7987 const char *threshold_str, int warning,
7988 const char *restart_str,
7989 const char *force_str)
7990 {
7991 int ret;
7992 struct peer *peer;
7993 uint32_t max;
7994 uint8_t threshold;
7995 uint16_t restart;
7996
7997 peer = peer_and_group_lookup_vty(vty, ip_str);
7998 if (!peer)
7999 return CMD_WARNING_CONFIG_FAILED;
8000
8001 max = strtoul(num_str, NULL, 10);
8002 if (threshold_str)
8003 threshold = atoi(threshold_str);
8004 else
8005 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8006
8007 if (restart_str)
8008 restart = atoi(restart_str);
8009 else
8010 restart = 0;
8011
8012 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8013 restart, force_str ? true : false);
8014
8015 return bgp_vty_return(vty, ret);
8016 }
8017
8018 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8019 afi_t afi, safi_t safi)
8020 {
8021 int ret;
8022 struct peer *peer;
8023
8024 peer = peer_and_group_lookup_vty(vty, ip_str);
8025 if (!peer)
8026 return CMD_WARNING_CONFIG_FAILED;
8027
8028 ret = peer_maximum_prefix_unset(peer, afi, safi);
8029
8030 return bgp_vty_return(vty, ret);
8031 }
8032
8033 /* Maximum number of prefix to be sent to the neighbor. */
8034 DEFUN(neighbor_maximum_prefix_out,
8035 neighbor_maximum_prefix_out_cmd,
8036 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8037 NEIGHBOR_STR
8038 NEIGHBOR_ADDR_STR2
8039 "Maximum number of prefixes to be sent to this peer\n"
8040 "Maximum no. of prefix limit\n")
8041 {
8042 int ret;
8043 int idx_peer = 1;
8044 int idx_number = 3;
8045 struct peer *peer;
8046 uint32_t max;
8047 afi_t afi = bgp_node_afi(vty);
8048 safi_t safi = bgp_node_safi(vty);
8049
8050 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8051 if (!peer)
8052 return CMD_WARNING_CONFIG_FAILED;
8053
8054 max = strtoul(argv[idx_number]->arg, NULL, 10);
8055
8056 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8057
8058 return bgp_vty_return(vty, ret);
8059 }
8060
8061 DEFUN(no_neighbor_maximum_prefix_out,
8062 no_neighbor_maximum_prefix_out_cmd,
8063 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8064 NO_STR
8065 NEIGHBOR_STR
8066 NEIGHBOR_ADDR_STR2
8067 "Maximum number of prefixes to be sent to this peer\n"
8068 "Maximum no. of prefix limit\n")
8069 {
8070 int ret;
8071 int idx_peer = 2;
8072 struct peer *peer;
8073 afi_t afi = bgp_node_afi(vty);
8074 safi_t safi = bgp_node_safi(vty);
8075
8076 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8077 if (!peer)
8078 return CMD_WARNING_CONFIG_FAILED;
8079
8080 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8081
8082 return bgp_vty_return(vty, ret);
8083 }
8084
8085 /* Maximum number of prefix configuration. Prefix count is different
8086 for each peer configuration. So this configuration can be set for
8087 each peer configuration. */
8088 DEFUN (neighbor_maximum_prefix,
8089 neighbor_maximum_prefix_cmd,
8090 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8091 NEIGHBOR_STR
8092 NEIGHBOR_ADDR_STR2
8093 "Maximum number of prefix accept from this peer\n"
8094 "maximum no. of prefix limit\n"
8095 "Force checking all received routes not only accepted\n")
8096 {
8097 int idx_peer = 1;
8098 int idx_number = 3;
8099 int idx_force = 0;
8100 char *force = NULL;
8101
8102 if (argv_find(argv, argc, "force", &idx_force))
8103 force = argv[idx_force]->arg;
8104
8105 return peer_maximum_prefix_set_vty(
8106 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8107 argv[idx_number]->arg, NULL, 0, NULL, force);
8108 }
8109
8110 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8111 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8112 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8113 "Maximum number of prefix accept from this peer\n"
8114 "maximum no. of prefix limit\n"
8115 "Force checking all received routes not only accepted\n")
8116
8117 DEFUN (neighbor_maximum_prefix_threshold,
8118 neighbor_maximum_prefix_threshold_cmd,
8119 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8120 NEIGHBOR_STR
8121 NEIGHBOR_ADDR_STR2
8122 "Maximum number of prefix accept from this peer\n"
8123 "maximum no. of prefix limit\n"
8124 "Threshold value (%) at which to generate a warning msg\n"
8125 "Force checking all received routes not only accepted\n")
8126 {
8127 int idx_peer = 1;
8128 int idx_number = 3;
8129 int idx_number_2 = 4;
8130 int idx_force = 0;
8131 char *force = NULL;
8132
8133 if (argv_find(argv, argc, "force", &idx_force))
8134 force = argv[idx_force]->arg;
8135
8136 return peer_maximum_prefix_set_vty(
8137 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8138 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8139 }
8140
8141 ALIAS_HIDDEN(
8142 neighbor_maximum_prefix_threshold,
8143 neighbor_maximum_prefix_threshold_hidden_cmd,
8144 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8145 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8146 "Maximum number of prefix accept from this peer\n"
8147 "maximum no. of prefix limit\n"
8148 "Threshold value (%) at which to generate a warning msg\n"
8149 "Force checking all received routes not only accepted\n")
8150
8151 DEFUN (neighbor_maximum_prefix_warning,
8152 neighbor_maximum_prefix_warning_cmd,
8153 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8154 NEIGHBOR_STR
8155 NEIGHBOR_ADDR_STR2
8156 "Maximum number of prefix accept from this peer\n"
8157 "maximum no. of prefix limit\n"
8158 "Only give warning message when limit is exceeded\n"
8159 "Force checking all received routes not only accepted\n")
8160 {
8161 int idx_peer = 1;
8162 int idx_number = 3;
8163 int idx_force = 0;
8164 char *force = NULL;
8165
8166 if (argv_find(argv, argc, "force", &idx_force))
8167 force = argv[idx_force]->arg;
8168
8169 return peer_maximum_prefix_set_vty(
8170 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8171 argv[idx_number]->arg, NULL, 1, NULL, force);
8172 }
8173
8174 ALIAS_HIDDEN(
8175 neighbor_maximum_prefix_warning,
8176 neighbor_maximum_prefix_warning_hidden_cmd,
8177 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8178 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8179 "Maximum number of prefix accept from this peer\n"
8180 "maximum no. of prefix limit\n"
8181 "Only give warning message when limit is exceeded\n"
8182 "Force checking all received routes not only accepted\n")
8183
8184 DEFUN (neighbor_maximum_prefix_threshold_warning,
8185 neighbor_maximum_prefix_threshold_warning_cmd,
8186 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8187 NEIGHBOR_STR
8188 NEIGHBOR_ADDR_STR2
8189 "Maximum number of prefix accept from this peer\n"
8190 "maximum no. of prefix limit\n"
8191 "Threshold value (%) at which to generate a warning msg\n"
8192 "Only give warning message when limit is exceeded\n"
8193 "Force checking all received routes not only accepted\n")
8194 {
8195 int idx_peer = 1;
8196 int idx_number = 3;
8197 int idx_number_2 = 4;
8198 int idx_force = 0;
8199 char *force = NULL;
8200
8201 if (argv_find(argv, argc, "force", &idx_force))
8202 force = argv[idx_force]->arg;
8203
8204 return peer_maximum_prefix_set_vty(
8205 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8206 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8207 }
8208
8209 ALIAS_HIDDEN(
8210 neighbor_maximum_prefix_threshold_warning,
8211 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8212 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8213 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8214 "Maximum number of prefix accept from this peer\n"
8215 "maximum no. of prefix limit\n"
8216 "Threshold value (%) at which to generate a warning msg\n"
8217 "Only give warning message when limit is exceeded\n"
8218 "Force checking all received routes not only accepted\n")
8219
8220 DEFUN (neighbor_maximum_prefix_restart,
8221 neighbor_maximum_prefix_restart_cmd,
8222 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8223 NEIGHBOR_STR
8224 NEIGHBOR_ADDR_STR2
8225 "Maximum number of prefix accept from this peer\n"
8226 "maximum no. of prefix limit\n"
8227 "Restart bgp connection after limit is exceeded\n"
8228 "Restart interval in minutes\n"
8229 "Force checking all received routes not only accepted\n")
8230 {
8231 int idx_peer = 1;
8232 int idx_number = 3;
8233 int idx_number_2 = 5;
8234 int idx_force = 0;
8235 char *force = NULL;
8236
8237 if (argv_find(argv, argc, "force", &idx_force))
8238 force = argv[idx_force]->arg;
8239
8240 return peer_maximum_prefix_set_vty(
8241 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8242 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8243 }
8244
8245 ALIAS_HIDDEN(
8246 neighbor_maximum_prefix_restart,
8247 neighbor_maximum_prefix_restart_hidden_cmd,
8248 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8250 "Maximum number of prefix accept from this peer\n"
8251 "maximum no. of prefix limit\n"
8252 "Restart bgp connection after limit is exceeded\n"
8253 "Restart interval in minutes\n"
8254 "Force checking all received routes not only accepted\n")
8255
8256 DEFUN (neighbor_maximum_prefix_threshold_restart,
8257 neighbor_maximum_prefix_threshold_restart_cmd,
8258 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8259 NEIGHBOR_STR
8260 NEIGHBOR_ADDR_STR2
8261 "Maximum number of prefixes to accept from this peer\n"
8262 "maximum no. of prefix limit\n"
8263 "Threshold value (%) at which to generate a warning msg\n"
8264 "Restart bgp connection after limit is exceeded\n"
8265 "Restart interval in minutes\n"
8266 "Force checking all received routes not only accepted\n")
8267 {
8268 int idx_peer = 1;
8269 int idx_number = 3;
8270 int idx_number_2 = 4;
8271 int idx_number_3 = 6;
8272 int idx_force = 0;
8273 char *force = NULL;
8274
8275 if (argv_find(argv, argc, "force", &idx_force))
8276 force = argv[idx_force]->arg;
8277
8278 return peer_maximum_prefix_set_vty(
8279 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8280 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8281 argv[idx_number_3]->arg, force);
8282 }
8283
8284 ALIAS_HIDDEN(
8285 neighbor_maximum_prefix_threshold_restart,
8286 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8287 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8289 "Maximum number of prefixes to accept from this peer\n"
8290 "maximum no. of prefix limit\n"
8291 "Threshold value (%) at which to generate a warning msg\n"
8292 "Restart bgp connection after limit is exceeded\n"
8293 "Restart interval in minutes\n"
8294 "Force checking all received routes not only accepted\n")
8295
8296 DEFUN (no_neighbor_maximum_prefix,
8297 no_neighbor_maximum_prefix_cmd,
8298 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8299 NO_STR
8300 NEIGHBOR_STR
8301 NEIGHBOR_ADDR_STR2
8302 "Maximum number of prefixes to accept from this peer\n"
8303 "maximum no. of prefix limit\n"
8304 "Threshold value (%) at which to generate a warning msg\n"
8305 "Restart bgp connection after limit is exceeded\n"
8306 "Restart interval in minutes\n"
8307 "Only give warning message when limit is exceeded\n"
8308 "Force checking all received routes not only accepted\n")
8309 {
8310 int idx_peer = 2;
8311 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8312 bgp_node_afi(vty),
8313 bgp_node_safi(vty));
8314 }
8315
8316 ALIAS_HIDDEN(
8317 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8318 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8319 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8320 "Maximum number of prefixes to accept from this peer\n"
8321 "maximum no. of prefix limit\n"
8322 "Threshold value (%) at which to generate a warning msg\n"
8323 "Restart bgp connection after limit is exceeded\n"
8324 "Restart interval in minutes\n"
8325 "Only give warning message when limit is exceeded\n"
8326 "Force checking all received routes not only accepted\n")
8327
8328 /* "neighbor accept-own" */
8329 DEFPY (neighbor_accept_own,
8330 neighbor_accept_own_cmd,
8331 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8332 NO_STR
8333 NEIGHBOR_STR
8334 NEIGHBOR_ADDR_STR2
8335 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8336 {
8337 struct peer *peer;
8338 afi_t afi = bgp_node_afi(vty);
8339 safi_t safi = bgp_node_safi(vty);
8340 int ret;
8341
8342 peer = peer_and_group_lookup_vty(vty, neighbor);
8343 if (!peer)
8344 return CMD_WARNING_CONFIG_FAILED;
8345
8346 if (no)
8347 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8348 else
8349 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8350
8351 return bgp_vty_return(vty, ret);
8352 }
8353
8354 /* "neighbor soo" */
8355 DEFPY (neighbor_soo,
8356 neighbor_soo_cmd,
8357 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8358 NEIGHBOR_STR
8359 NEIGHBOR_ADDR_STR2
8360 "Set the Site-of-Origin (SoO) extended community\n"
8361 "VPN extended community\n")
8362 {
8363 struct peer *peer;
8364 afi_t afi = bgp_node_afi(vty);
8365 safi_t safi = bgp_node_safi(vty);
8366 struct ecommunity *ecomm_soo;
8367
8368 peer = peer_and_group_lookup_vty(vty, neighbor);
8369 if (!peer)
8370 return CMD_WARNING_CONFIG_FAILED;
8371
8372 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8373 if (!ecomm_soo) {
8374 vty_out(vty, "%% Malformed SoO extended community\n");
8375 return CMD_WARNING;
8376 }
8377 ecommunity_str(ecomm_soo);
8378
8379 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8380 ecommunity_free(&peer->soo[afi][safi]);
8381 peer->soo[afi][safi] = ecomm_soo;
8382 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8383 }
8384
8385 return bgp_vty_return(vty,
8386 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8387 }
8388
8389 DEFPY (no_neighbor_soo,
8390 no_neighbor_soo_cmd,
8391 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8392 NO_STR
8393 NEIGHBOR_STR
8394 NEIGHBOR_ADDR_STR2
8395 "Set the Site-of-Origin (SoO) extended community\n"
8396 "VPN extended community\n")
8397 {
8398 struct peer *peer;
8399 afi_t afi = bgp_node_afi(vty);
8400 safi_t safi = bgp_node_safi(vty);
8401
8402 peer = peer_and_group_lookup_vty(vty, neighbor);
8403 if (!peer)
8404 return CMD_WARNING_CONFIG_FAILED;
8405
8406 ecommunity_free(&peer->soo[afi][safi]);
8407
8408 return bgp_vty_return(
8409 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8410 }
8411
8412 /* "neighbor allowas-in" */
8413 DEFUN (neighbor_allowas_in,
8414 neighbor_allowas_in_cmd,
8415 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8416 NEIGHBOR_STR
8417 NEIGHBOR_ADDR_STR2
8418 "Accept as-path with my AS present in it\n"
8419 "Number of occurrences of AS number\n"
8420 "Only accept my AS in the as-path if the route was originated in my AS\n")
8421 {
8422 int idx_peer = 1;
8423 int idx_number_origin = 3;
8424 int ret;
8425 int origin = 0;
8426 struct peer *peer;
8427 int allow_num = 0;
8428
8429 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8430 if (!peer)
8431 return CMD_WARNING_CONFIG_FAILED;
8432
8433 if (argc <= idx_number_origin)
8434 allow_num = 3;
8435 else {
8436 if (argv[idx_number_origin]->type == WORD_TKN)
8437 origin = 1;
8438 else
8439 allow_num = atoi(argv[idx_number_origin]->arg);
8440 }
8441
8442 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8443 allow_num, origin);
8444
8445 return bgp_vty_return(vty, ret);
8446 }
8447
8448 ALIAS_HIDDEN(
8449 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8450 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8451 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8452 "Accept as-path with my AS present in it\n"
8453 "Number of occurrences of AS number\n"
8454 "Only accept my AS in the as-path if the route was originated in my AS\n")
8455
8456 DEFUN (no_neighbor_allowas_in,
8457 no_neighbor_allowas_in_cmd,
8458 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8459 NO_STR
8460 NEIGHBOR_STR
8461 NEIGHBOR_ADDR_STR2
8462 "allow local ASN appears in aspath attribute\n"
8463 "Number of occurrences of AS number\n"
8464 "Only accept my AS in the as-path if the route was originated in my AS\n")
8465 {
8466 int idx_peer = 2;
8467 int ret;
8468 struct peer *peer;
8469
8470 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8471 if (!peer)
8472 return CMD_WARNING_CONFIG_FAILED;
8473
8474 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8475 bgp_node_safi(vty));
8476
8477 return bgp_vty_return(vty, ret);
8478 }
8479
8480 ALIAS_HIDDEN(
8481 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8482 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8483 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8484 "allow local ASN appears in aspath attribute\n"
8485 "Number of occurrences of AS number\n"
8486 "Only accept my AS in the as-path if the route was originated in my AS\n")
8487
8488 DEFUN (neighbor_ttl_security,
8489 neighbor_ttl_security_cmd,
8490 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8491 NEIGHBOR_STR
8492 NEIGHBOR_ADDR_STR2
8493 "BGP ttl-security parameters\n"
8494 "Specify the maximum number of hops to the BGP peer\n"
8495 "Number of hops to BGP peer\n")
8496 {
8497 int idx_peer = 1;
8498 int idx_number = 4;
8499 struct peer *peer;
8500 int gtsm_hops;
8501
8502 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8503 if (!peer)
8504 return CMD_WARNING_CONFIG_FAILED;
8505
8506 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8507
8508 /*
8509 * If 'neighbor swpX', then this is for directly connected peers,
8510 * we should not accept a ttl-security hops value greater than 1.
8511 */
8512 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8513 vty_out(vty,
8514 "%s is directly connected peer, hops cannot exceed 1\n",
8515 argv[idx_peer]->arg);
8516 return CMD_WARNING_CONFIG_FAILED;
8517 }
8518
8519 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8520 }
8521
8522 DEFUN (no_neighbor_ttl_security,
8523 no_neighbor_ttl_security_cmd,
8524 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8525 NO_STR
8526 NEIGHBOR_STR
8527 NEIGHBOR_ADDR_STR2
8528 "BGP ttl-security parameters\n"
8529 "Specify the maximum number of hops to the BGP peer\n"
8530 "Number of hops to BGP peer\n")
8531 {
8532 int idx_peer = 2;
8533 struct peer *peer;
8534
8535 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8536 if (!peer)
8537 return CMD_WARNING_CONFIG_FAILED;
8538
8539 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8540 }
8541
8542 /* disable-addpath-rx */
8543 DEFUN(neighbor_disable_addpath_rx,
8544 neighbor_disable_addpath_rx_cmd,
8545 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8546 NEIGHBOR_STR
8547 NEIGHBOR_ADDR_STR2
8548 "Do not accept additional paths\n")
8549 {
8550 char *peer_str = argv[1]->arg;
8551 struct peer *peer;
8552 afi_t afi = bgp_node_afi(vty);
8553 safi_t safi = bgp_node_safi(vty);
8554
8555 peer = peer_and_group_lookup_vty(vty, peer_str);
8556 if (!peer)
8557 return CMD_WARNING_CONFIG_FAILED;
8558
8559 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8560 PEER_FLAG_DISABLE_ADDPATH_RX);
8561 }
8562
8563 DEFUN(no_neighbor_disable_addpath_rx,
8564 no_neighbor_disable_addpath_rx_cmd,
8565 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8566 NO_STR
8567 NEIGHBOR_STR
8568 NEIGHBOR_ADDR_STR2
8569 "Do not accept additional paths\n")
8570 {
8571 char *peer_str = argv[2]->arg;
8572 struct peer *peer;
8573 afi_t afi = bgp_node_afi(vty);
8574 safi_t safi = bgp_node_safi(vty);
8575
8576 peer = peer_and_group_lookup_vty(vty, peer_str);
8577 if (!peer)
8578 return CMD_WARNING_CONFIG_FAILED;
8579
8580 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8581 PEER_FLAG_DISABLE_ADDPATH_RX);
8582 }
8583
8584 DEFUN (neighbor_addpath_tx_all_paths,
8585 neighbor_addpath_tx_all_paths_cmd,
8586 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8587 NEIGHBOR_STR
8588 NEIGHBOR_ADDR_STR2
8589 "Use addpath to advertise all paths to a neighbor\n")
8590 {
8591 int idx_peer = 1;
8592 struct peer *peer;
8593
8594 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8595 if (!peer)
8596 return CMD_WARNING_CONFIG_FAILED;
8597
8598 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8599 BGP_ADDPATH_ALL);
8600 return CMD_SUCCESS;
8601 }
8602
8603 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8604 neighbor_addpath_tx_all_paths_hidden_cmd,
8605 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8606 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8607 "Use addpath to advertise all paths to a neighbor\n")
8608
8609 DEFUN (no_neighbor_addpath_tx_all_paths,
8610 no_neighbor_addpath_tx_all_paths_cmd,
8611 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8612 NO_STR
8613 NEIGHBOR_STR
8614 NEIGHBOR_ADDR_STR2
8615 "Use addpath to advertise all paths to a neighbor\n")
8616 {
8617 int idx_peer = 2;
8618 struct peer *peer;
8619
8620 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8621 if (!peer)
8622 return CMD_WARNING_CONFIG_FAILED;
8623
8624 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8625 != BGP_ADDPATH_ALL) {
8626 vty_out(vty,
8627 "%% Peer not currently configured to transmit all paths.");
8628 return CMD_WARNING_CONFIG_FAILED;
8629 }
8630
8631 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8632 BGP_ADDPATH_NONE);
8633
8634 return CMD_SUCCESS;
8635 }
8636
8637 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8638 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8639 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8640 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8641 "Use addpath to advertise all paths to a neighbor\n")
8642
8643 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8644 neighbor_addpath_tx_bestpath_per_as_cmd,
8645 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8646 NEIGHBOR_STR
8647 NEIGHBOR_ADDR_STR2
8648 "Use addpath to advertise the bestpath per each neighboring AS\n")
8649 {
8650 int idx_peer = 1;
8651 struct peer *peer;
8652
8653 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8654 if (!peer)
8655 return CMD_WARNING_CONFIG_FAILED;
8656
8657 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8658 BGP_ADDPATH_BEST_PER_AS);
8659
8660 return CMD_SUCCESS;
8661 }
8662
8663 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8664 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8665 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8666 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8667 "Use addpath to advertise the bestpath per each neighboring AS\n")
8668
8669 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8670 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8671 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8672 NO_STR
8673 NEIGHBOR_STR
8674 NEIGHBOR_ADDR_STR2
8675 "Use addpath to advertise the bestpath per each neighboring AS\n")
8676 {
8677 int idx_peer = 2;
8678 struct peer *peer;
8679
8680 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8681 if (!peer)
8682 return CMD_WARNING_CONFIG_FAILED;
8683
8684 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8685 != BGP_ADDPATH_BEST_PER_AS) {
8686 vty_out(vty,
8687 "%% Peer not currently configured to transmit all best path per as.");
8688 return CMD_WARNING_CONFIG_FAILED;
8689 }
8690
8691 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8692 BGP_ADDPATH_NONE);
8693
8694 return CMD_SUCCESS;
8695 }
8696
8697 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8698 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8699 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8700 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8701 "Use addpath to advertise the bestpath per each neighboring AS\n")
8702
8703 DEFPY(
8704 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8705 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8706 NEIGHBOR_STR
8707 NEIGHBOR_ADDR_STR2
8708 "Detect AS loops before sending to neighbor\n")
8709 {
8710 struct peer *peer;
8711
8712 peer = peer_and_group_lookup_vty(vty, neighbor);
8713 if (!peer)
8714 return CMD_WARNING_CONFIG_FAILED;
8715
8716 peer->as_path_loop_detection = true;
8717
8718 return CMD_SUCCESS;
8719 }
8720
8721 DEFPY(
8722 no_neighbor_aspath_loop_detection,
8723 no_neighbor_aspath_loop_detection_cmd,
8724 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8725 NO_STR
8726 NEIGHBOR_STR
8727 NEIGHBOR_ADDR_STR2
8728 "Detect AS loops before sending to neighbor\n")
8729 {
8730 struct peer *peer;
8731
8732 peer = peer_and_group_lookup_vty(vty, neighbor);
8733 if (!peer)
8734 return CMD_WARNING_CONFIG_FAILED;
8735
8736 peer->as_path_loop_detection = false;
8737
8738 return CMD_SUCCESS;
8739 }
8740
8741 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8742 struct ecommunity **list, bool is_rt6)
8743 {
8744 struct ecommunity *ecom = NULL;
8745 struct ecommunity *ecomadd;
8746
8747 for (; argc; --argc, ++argv) {
8748 if (is_rt6)
8749 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8750 ECOMMUNITY_ROUTE_TARGET,
8751 0);
8752 else
8753 ecomadd = ecommunity_str2com(argv[0]->arg,
8754 ECOMMUNITY_ROUTE_TARGET,
8755 0);
8756 if (!ecomadd) {
8757 vty_out(vty, "Malformed community-list value\n");
8758 if (ecom)
8759 ecommunity_free(&ecom);
8760 return CMD_WARNING_CONFIG_FAILED;
8761 }
8762
8763 if (ecom) {
8764 ecommunity_merge(ecom, ecomadd);
8765 ecommunity_free(&ecomadd);
8766 } else {
8767 ecom = ecomadd;
8768 }
8769 }
8770
8771 if (*list) {
8772 ecommunity_free(&*list);
8773 }
8774 *list = ecom;
8775
8776 return CMD_SUCCESS;
8777 }
8778
8779 /*
8780 * v2vimport is true if we are handling a `import vrf ...` command
8781 */
8782 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8783 {
8784 afi_t afi;
8785
8786 switch (vty->node) {
8787 case BGP_IPV4_NODE:
8788 afi = AFI_IP;
8789 break;
8790 case BGP_IPV6_NODE:
8791 afi = AFI_IP6;
8792 break;
8793 default:
8794 vty_out(vty,
8795 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8796 return AFI_MAX;
8797 }
8798
8799 if (!v2vimport) {
8800 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8801 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8802 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8803 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8804 vty_out(vty,
8805 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8806 return AFI_MAX;
8807 }
8808 } else {
8809 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8810 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8811 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8812 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8813 vty_out(vty,
8814 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8815 return AFI_MAX;
8816 }
8817 }
8818 return afi;
8819 }
8820
8821 DEFPY (af_rd_vpn_export,
8822 af_rd_vpn_export_cmd,
8823 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8824 NO_STR
8825 "Specify route distinguisher\n"
8826 "Between current address-family and vpn\n"
8827 "For routes leaked from current address-family to vpn\n"
8828 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8829 {
8830 VTY_DECLVAR_CONTEXT(bgp, bgp);
8831 struct prefix_rd prd;
8832 int ret;
8833 afi_t afi;
8834 int idx = 0;
8835 bool yes = true;
8836
8837 if (argv_find(argv, argc, "no", &idx))
8838 yes = false;
8839
8840 if (yes) {
8841 ret = str2prefix_rd(rd_str, &prd);
8842 if (!ret) {
8843 vty_out(vty, "%% Malformed rd\n");
8844 return CMD_WARNING_CONFIG_FAILED;
8845 }
8846 }
8847
8848 afi = vpn_policy_getafi(vty, bgp, false);
8849 if (afi == AFI_MAX)
8850 return CMD_WARNING_CONFIG_FAILED;
8851
8852 /*
8853 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8854 */
8855 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8856 bgp_get_default(), bgp);
8857
8858 if (yes) {
8859 bgp->vpn_policy[afi].tovpn_rd = prd;
8860 SET_FLAG(bgp->vpn_policy[afi].flags,
8861 BGP_VPN_POLICY_TOVPN_RD_SET);
8862 } else {
8863 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8864 BGP_VPN_POLICY_TOVPN_RD_SET);
8865 }
8866
8867 /* post-change: re-export vpn routes */
8868 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8869 bgp_get_default(), bgp);
8870
8871 return CMD_SUCCESS;
8872 }
8873
8874 ALIAS (af_rd_vpn_export,
8875 af_no_rd_vpn_export_cmd,
8876 "no rd vpn export",
8877 NO_STR
8878 "Specify route distinguisher\n"
8879 "Between current address-family and vpn\n"
8880 "For routes leaked from current address-family to vpn\n")
8881
8882 DEFPY (af_label_vpn_export,
8883 af_label_vpn_export_cmd,
8884 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8885 NO_STR
8886 "label value for VRF\n"
8887 "Between current address-family and vpn\n"
8888 "For routes leaked from current address-family to vpn\n"
8889 "Label Value <0-1048575>\n"
8890 "Automatically assign a label\n")
8891 {
8892 VTY_DECLVAR_CONTEXT(bgp, bgp);
8893 mpls_label_t label = MPLS_LABEL_NONE;
8894 afi_t afi;
8895 int idx = 0;
8896 bool yes = true;
8897
8898 if (argv_find(argv, argc, "no", &idx))
8899 yes = false;
8900
8901 /* If "no ...", squash trailing parameter */
8902 if (!yes)
8903 label_auto = NULL;
8904
8905 if (yes) {
8906 if (!label_auto)
8907 label = label_val; /* parser should force unsigned */
8908 }
8909
8910 afi = vpn_policy_getafi(vty, bgp, false);
8911 if (afi == AFI_MAX)
8912 return CMD_WARNING_CONFIG_FAILED;
8913
8914
8915 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8916 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8917 /* no change */
8918 return CMD_SUCCESS;
8919
8920 /*
8921 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8922 */
8923 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8924 bgp_get_default(), bgp);
8925
8926 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8927 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8928
8929 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8930
8931 /*
8932 * label has previously been automatically
8933 * assigned by labelpool: release it
8934 *
8935 * NB if tovpn_label == MPLS_LABEL_NONE it
8936 * means the automatic assignment is in flight
8937 * and therefore the labelpool callback must
8938 * detect that the auto label is not needed.
8939 */
8940
8941 bgp_lp_release(LP_TYPE_VRF,
8942 &bgp->vpn_policy[afi],
8943 bgp->vpn_policy[afi].tovpn_label);
8944 }
8945 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8946 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8947 }
8948
8949 bgp->vpn_policy[afi].tovpn_label = label;
8950 if (label_auto) {
8951 SET_FLAG(bgp->vpn_policy[afi].flags,
8952 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8953 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8954 vpn_leak_label_callback);
8955 }
8956
8957 /* post-change: re-export vpn routes */
8958 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8959 bgp_get_default(), bgp);
8960
8961 hook_call(bgp_snmp_update_last_changed, bgp);
8962 return CMD_SUCCESS;
8963 }
8964
8965 DEFPY (af_sid_vpn_export,
8966 af_sid_vpn_export_cmd,
8967 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
8968 NO_STR
8969 "sid value for VRF\n"
8970 "Between current address-family and vpn\n"
8971 "For routes leaked from current address-family to vpn\n"
8972 "Sid allocation index\n"
8973 "Automatically assign a label\n")
8974 {
8975 VTY_DECLVAR_CONTEXT(bgp, bgp);
8976 afi_t afi;
8977 int debug = 0;
8978 int idx = 0;
8979 bool yes = true;
8980
8981 if (argv_find(argv, argc, "no", &idx))
8982 yes = false;
8983 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8984 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8985
8986 afi = vpn_policy_getafi(vty, bgp, false);
8987 if (afi == AFI_MAX)
8988 return CMD_WARNING_CONFIG_FAILED;
8989
8990 if (!yes) {
8991 /* implement me */
8992 vty_out(vty, "It's not implemented\n");
8993 return CMD_WARNING_CONFIG_FAILED;
8994 }
8995
8996 if (bgp->tovpn_sid_index != 0 ||
8997 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
8998 vty_out(vty,
8999 "per-vrf sid and per-af sid are mutually exclusive\n"
9000 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9001 return CMD_WARNING_CONFIG_FAILED;
9002 }
9003
9004 /* skip when it's already configured */
9005 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9006 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9007 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9008 return CMD_SUCCESS;
9009
9010 /*
9011 * mode change between sid_idx and sid_auto isn't supported.
9012 * user must negate sid vpn export when they want to change the mode
9013 */
9014 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9015 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9016 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9017 vty_out(vty, "it's already configured as %s.\n",
9018 sid_auto ? "auto-mode" : "idx-mode");
9019 return CMD_WARNING_CONFIG_FAILED;
9020 }
9021
9022 /* pre-change */
9023 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9024 bgp_get_default(), bgp);
9025
9026 if (sid_auto) {
9027 /* SID allocation auto-mode */
9028 if (debug)
9029 zlog_debug("%s: auto sid alloc.", __func__);
9030 SET_FLAG(bgp->vpn_policy[afi].flags,
9031 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9032 } else {
9033 /* SID allocation index-mode */
9034 if (debug)
9035 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9036 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9037 }
9038
9039 /* post-change */
9040 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9041 bgp_get_default(), bgp);
9042 return CMD_SUCCESS;
9043 }
9044
9045 DEFPY (bgp_sid_vpn_export,
9046 bgp_sid_vpn_export_cmd,
9047 "[no] sid vpn per-vrf export <(1-255)$sid_idx|auto$sid_auto>",
9048 NO_STR
9049 "sid value for VRF\n"
9050 "Between current vrf and vpn\n"
9051 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9052 "For routes leaked from current vrf to vpn\n"
9053 "Sid allocation index\n"
9054 "Automatically assign a label\n")
9055 {
9056 VTY_DECLVAR_CONTEXT(bgp, bgp);
9057 int debug;
9058
9059 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9060 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9061
9062 if (no) {
9063 /* when per-VRF SID is not set, do nothing */
9064 if (bgp->tovpn_sid_index == 0 &&
9065 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9066 return CMD_SUCCESS;
9067
9068 sid_idx = 0;
9069 sid_auto = false;
9070 bgp->tovpn_sid_index = 0;
9071 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9072 }
9073
9074 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9075 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9076 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9077 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9078 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9079 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9080 vty_out(vty,
9081 "per-vrf sid and per-af sid are mutually exclusive\n"
9082 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9083 return CMD_WARNING_CONFIG_FAILED;
9084 }
9085
9086 /* skip when it's already configured */
9087 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9088 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9089 return CMD_SUCCESS;
9090
9091 /*
9092 * mode change between sid_idx and sid_auto isn't supported.
9093 * user must negate sid vpn export when they want to change the mode
9094 */
9095 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9096 (sid_idx != 0 &&
9097 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9098 vty_out(vty, "it's already configured as %s.\n",
9099 sid_auto ? "auto-mode" : "idx-mode");
9100 return CMD_WARNING_CONFIG_FAILED;
9101 }
9102
9103 /* pre-change */
9104 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9105 bgp);
9106 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9107 bgp);
9108
9109 if (sid_auto) {
9110 /* SID allocation auto-mode */
9111 if (debug)
9112 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9113 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9114 } else if (sid_idx != 0) {
9115 /* SID allocation index-mode */
9116 if (debug)
9117 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9118 sid_idx);
9119 bgp->tovpn_sid_index = sid_idx;
9120 }
9121
9122 /* post-change */
9123 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9124 bgp);
9125 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9126 bgp_get_default(), bgp);
9127
9128 return CMD_SUCCESS;
9129 }
9130
9131 ALIAS (af_label_vpn_export,
9132 af_no_label_vpn_export_cmd,
9133 "no label vpn export",
9134 NO_STR
9135 "label value for VRF\n"
9136 "Between current address-family and vpn\n"
9137 "For routes leaked from current address-family to vpn\n")
9138
9139 ALIAS (bgp_sid_vpn_export,
9140 no_bgp_sid_vpn_export_cmd,
9141 "no$no sid vpn per-vrf export",
9142 NO_STR
9143 "sid value for VRF\n"
9144 "Between current vrf and vpn\n"
9145 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9146 "For routes leaked from current vrf to vpn\n")
9147
9148 DEFPY (af_nexthop_vpn_export,
9149 af_nexthop_vpn_export_cmd,
9150 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9151 NO_STR
9152 "Specify next hop to use for VRF advertised prefixes\n"
9153 "Between current address-family and vpn\n"
9154 "For routes leaked from current address-family to vpn\n"
9155 "IPv4 prefix\n"
9156 "IPv6 prefix\n")
9157 {
9158 VTY_DECLVAR_CONTEXT(bgp, bgp);
9159 afi_t afi;
9160 struct prefix p;
9161
9162 if (!no) {
9163 if (!nexthop_su) {
9164 vty_out(vty, "%% Nexthop required\n");
9165 return CMD_WARNING_CONFIG_FAILED;
9166 }
9167 if (!sockunion2hostprefix(nexthop_su, &p))
9168 return CMD_WARNING_CONFIG_FAILED;
9169 }
9170
9171 afi = vpn_policy_getafi(vty, bgp, false);
9172 if (afi == AFI_MAX)
9173 return CMD_WARNING_CONFIG_FAILED;
9174
9175 /*
9176 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9177 */
9178 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9179 bgp_get_default(), bgp);
9180
9181 if (!no) {
9182 bgp->vpn_policy[afi].tovpn_nexthop = p;
9183 SET_FLAG(bgp->vpn_policy[afi].flags,
9184 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9185 } else {
9186 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9187 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9188 }
9189
9190 /* post-change: re-export vpn routes */
9191 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9192 bgp_get_default(), bgp);
9193
9194 return CMD_SUCCESS;
9195 }
9196
9197 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9198 {
9199 if (!strcmp(dstr, "import")) {
9200 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9201 } else if (!strcmp(dstr, "export")) {
9202 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9203 } else if (!strcmp(dstr, "both")) {
9204 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9205 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9206 } else {
9207 vty_out(vty, "%% direction parse error\n");
9208 return CMD_WARNING_CONFIG_FAILED;
9209 }
9210 return CMD_SUCCESS;
9211 }
9212
9213 DEFPY (af_rt_vpn_imexport,
9214 af_rt_vpn_imexport_cmd,
9215 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9216 NO_STR
9217 "Specify route target list\n"
9218 "Specify route target list\n"
9219 "Between current address-family and vpn\n"
9220 "For routes leaked from vpn to current address-family: match any\n"
9221 "For routes leaked from current address-family to vpn: set\n"
9222 "both import: match any and export: set\n"
9223 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9224 {
9225 VTY_DECLVAR_CONTEXT(bgp, bgp);
9226 int ret;
9227 struct ecommunity *ecom = NULL;
9228 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9229 enum vpn_policy_direction dir;
9230 afi_t afi;
9231 int idx = 0;
9232 bool yes = true;
9233
9234 if (argv_find(argv, argc, "no", &idx))
9235 yes = false;
9236
9237 afi = vpn_policy_getafi(vty, bgp, false);
9238 if (afi == AFI_MAX)
9239 return CMD_WARNING_CONFIG_FAILED;
9240
9241 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9242 if (ret != CMD_SUCCESS)
9243 return ret;
9244
9245 if (yes) {
9246 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9247 vty_out(vty, "%% Missing RTLIST\n");
9248 return CMD_WARNING_CONFIG_FAILED;
9249 }
9250 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9251 if (ret != CMD_SUCCESS) {
9252 return ret;
9253 }
9254 }
9255
9256 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9257 if (!dodir[dir])
9258 continue;
9259
9260 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9261
9262 if (yes) {
9263 if (bgp->vpn_policy[afi].rtlist[dir])
9264 ecommunity_free(
9265 &bgp->vpn_policy[afi].rtlist[dir]);
9266 bgp->vpn_policy[afi].rtlist[dir] =
9267 ecommunity_dup(ecom);
9268 } else {
9269 if (bgp->vpn_policy[afi].rtlist[dir])
9270 ecommunity_free(
9271 &bgp->vpn_policy[afi].rtlist[dir]);
9272 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9273 }
9274
9275 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9276 }
9277
9278 if (ecom)
9279 ecommunity_free(&ecom);
9280
9281 return CMD_SUCCESS;
9282 }
9283
9284 ALIAS (af_rt_vpn_imexport,
9285 af_no_rt_vpn_imexport_cmd,
9286 "no <rt|route-target> vpn <import|export|both>$direction_str",
9287 NO_STR
9288 "Specify route target list\n"
9289 "Specify route target list\n"
9290 "Between current address-family and vpn\n"
9291 "For routes leaked from vpn to current address-family\n"
9292 "For routes leaked from current address-family to vpn\n"
9293 "both import and export\n")
9294
9295 DEFPY (af_route_map_vpn_imexport,
9296 af_route_map_vpn_imexport_cmd,
9297 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9298 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9299 NO_STR
9300 "Specify route map\n"
9301 "Between current address-family and vpn\n"
9302 "For routes leaked from vpn to current address-family\n"
9303 "For routes leaked from current address-family to vpn\n"
9304 "name of route-map\n")
9305 {
9306 VTY_DECLVAR_CONTEXT(bgp, bgp);
9307 int ret;
9308 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9309 enum vpn_policy_direction dir;
9310 afi_t afi;
9311 int idx = 0;
9312 bool yes = true;
9313
9314 if (argv_find(argv, argc, "no", &idx))
9315 yes = false;
9316
9317 afi = vpn_policy_getafi(vty, bgp, false);
9318 if (afi == AFI_MAX)
9319 return CMD_WARNING_CONFIG_FAILED;
9320
9321 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9322 if (ret != CMD_SUCCESS)
9323 return ret;
9324
9325 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9326 if (!dodir[dir])
9327 continue;
9328
9329 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9330
9331 if (yes) {
9332 if (bgp->vpn_policy[afi].rmap_name[dir])
9333 XFREE(MTYPE_ROUTE_MAP_NAME,
9334 bgp->vpn_policy[afi].rmap_name[dir]);
9335 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9336 MTYPE_ROUTE_MAP_NAME, rmap_str);
9337 bgp->vpn_policy[afi].rmap[dir] =
9338 route_map_lookup_warn_noexist(vty, rmap_str);
9339 if (!bgp->vpn_policy[afi].rmap[dir])
9340 return CMD_SUCCESS;
9341 } else {
9342 if (bgp->vpn_policy[afi].rmap_name[dir])
9343 XFREE(MTYPE_ROUTE_MAP_NAME,
9344 bgp->vpn_policy[afi].rmap_name[dir]);
9345 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9346 bgp->vpn_policy[afi].rmap[dir] = NULL;
9347 }
9348
9349 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9350 }
9351
9352 return CMD_SUCCESS;
9353 }
9354
9355 ALIAS (af_route_map_vpn_imexport,
9356 af_no_route_map_vpn_imexport_cmd,
9357 "no route-map vpn <import|export>$direction_str",
9358 NO_STR
9359 "Specify route map\n"
9360 "Between current address-family and vpn\n"
9361 "For routes leaked from vpn to current address-family\n"
9362 "For routes leaked from current address-family to vpn\n")
9363
9364 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9365 "import vrf route-map RMAP$rmap_str",
9366 "Import routes from another VRF\n"
9367 "Vrf routes being filtered\n"
9368 "Specify route map\n"
9369 "name of route-map\n")
9370 {
9371 VTY_DECLVAR_CONTEXT(bgp, bgp);
9372 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9373 afi_t afi;
9374 struct bgp *bgp_default;
9375
9376 afi = vpn_policy_getafi(vty, bgp, true);
9377 if (afi == AFI_MAX)
9378 return CMD_WARNING_CONFIG_FAILED;
9379
9380 bgp_default = bgp_get_default();
9381 if (!bgp_default) {
9382 int32_t ret;
9383 as_t as = bgp->as;
9384
9385 /* Auto-create assuming the same AS */
9386 ret = bgp_get_vty(&bgp_default, &as, NULL,
9387 BGP_INSTANCE_TYPE_DEFAULT);
9388
9389 if (ret) {
9390 vty_out(vty,
9391 "VRF default is not configured as a bgp instance\n");
9392 return CMD_WARNING;
9393 }
9394 }
9395
9396 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9397
9398 if (bgp->vpn_policy[afi].rmap_name[dir])
9399 XFREE(MTYPE_ROUTE_MAP_NAME,
9400 bgp->vpn_policy[afi].rmap_name[dir]);
9401 bgp->vpn_policy[afi].rmap_name[dir] =
9402 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9403 bgp->vpn_policy[afi].rmap[dir] =
9404 route_map_lookup_warn_noexist(vty, rmap_str);
9405 if (!bgp->vpn_policy[afi].rmap[dir])
9406 return CMD_SUCCESS;
9407
9408 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9409 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9410
9411 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9412
9413 return CMD_SUCCESS;
9414 }
9415
9416 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9417 "no import vrf route-map [RMAP$rmap_str]",
9418 NO_STR
9419 "Import routes from another VRF\n"
9420 "Vrf routes being filtered\n"
9421 "Specify route map\n"
9422 "name of route-map\n")
9423 {
9424 VTY_DECLVAR_CONTEXT(bgp, bgp);
9425 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9426 afi_t afi;
9427
9428 afi = vpn_policy_getafi(vty, bgp, true);
9429 if (afi == AFI_MAX)
9430 return CMD_WARNING_CONFIG_FAILED;
9431
9432 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9433
9434 if (bgp->vpn_policy[afi].rmap_name[dir])
9435 XFREE(MTYPE_ROUTE_MAP_NAME,
9436 bgp->vpn_policy[afi].rmap_name[dir]);
9437 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9438 bgp->vpn_policy[afi].rmap[dir] = NULL;
9439
9440 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9441 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9442 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9443
9444 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9445
9446 return CMD_SUCCESS;
9447 }
9448
9449 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9450 "[no] import vrf VIEWVRFNAME$import_name",
9451 NO_STR
9452 "Import routes from another VRF\n"
9453 "VRF to import from\n"
9454 "The name of the VRF\n")
9455 {
9456 VTY_DECLVAR_CONTEXT(bgp, bgp);
9457 struct listnode *node;
9458 struct bgp *vrf_bgp, *bgp_default;
9459 int32_t ret = 0;
9460 as_t as = bgp->as;
9461 bool remove = false;
9462 int32_t idx = 0;
9463 char *vname;
9464 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9465 safi_t safi;
9466 afi_t afi;
9467
9468 if (import_name == NULL) {
9469 vty_out(vty, "%% Missing import name\n");
9470 return CMD_WARNING;
9471 }
9472
9473 if (strcmp(import_name, "route-map") == 0) {
9474 vty_out(vty, "%% Must include route-map name\n");
9475 return CMD_WARNING;
9476 }
9477
9478 if (argv_find(argv, argc, "no", &idx))
9479 remove = true;
9480
9481 afi = vpn_policy_getafi(vty, bgp, true);
9482 if (afi == AFI_MAX)
9483 return CMD_WARNING_CONFIG_FAILED;
9484
9485 safi = bgp_node_safi(vty);
9486
9487 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9488 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9489 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9490 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9491 remove ? "unimport" : "import", import_name);
9492 return CMD_WARNING;
9493 }
9494
9495 bgp_default = bgp_get_default();
9496 if (!bgp_default) {
9497 /* Auto-create assuming the same AS */
9498 ret = bgp_get_vty(&bgp_default, &as, NULL,
9499 BGP_INSTANCE_TYPE_DEFAULT);
9500
9501 if (ret) {
9502 vty_out(vty,
9503 "VRF default is not configured as a bgp instance\n");
9504 return CMD_WARNING;
9505 }
9506 }
9507
9508 vrf_bgp = bgp_lookup_by_name(import_name);
9509 if (!vrf_bgp) {
9510 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9511 vrf_bgp = bgp_default;
9512 else
9513 /* Auto-create assuming the same AS */
9514 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9515
9516 if (ret) {
9517 vty_out(vty,
9518 "VRF %s is not configured as a bgp instance\n",
9519 import_name);
9520 return CMD_WARNING;
9521 }
9522 }
9523
9524 if (remove) {
9525 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9526 } else {
9527 /* Already importing from "import_vrf"? */
9528 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9529 vname)) {
9530 if (strcmp(vname, import_name) == 0)
9531 return CMD_WARNING;
9532 }
9533
9534 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9535 }
9536
9537 return CMD_SUCCESS;
9538 }
9539
9540 /* This command is valid only in a bgp vrf instance or the default instance */
9541 DEFPY (bgp_imexport_vpn,
9542 bgp_imexport_vpn_cmd,
9543 "[no] <import|export>$direction_str vpn",
9544 NO_STR
9545 "Import routes to this address-family\n"
9546 "Export routes from this address-family\n"
9547 "to/from default instance VPN RIB\n")
9548 {
9549 VTY_DECLVAR_CONTEXT(bgp, bgp);
9550 int previous_state;
9551 afi_t afi;
9552 safi_t safi;
9553 int idx = 0;
9554 bool yes = true;
9555 int flag;
9556 enum vpn_policy_direction dir;
9557
9558 if (argv_find(argv, argc, "no", &idx))
9559 yes = false;
9560
9561 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9562 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9563
9564 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9565 return CMD_WARNING_CONFIG_FAILED;
9566 }
9567
9568 afi = bgp_node_afi(vty);
9569 safi = bgp_node_safi(vty);
9570 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9571 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9572 return CMD_WARNING_CONFIG_FAILED;
9573 }
9574
9575 if (!strcmp(direction_str, "import")) {
9576 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9577 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9578 } else if (!strcmp(direction_str, "export")) {
9579 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9580 dir = BGP_VPN_POLICY_DIR_TOVPN;
9581 } else {
9582 vty_out(vty, "%% unknown direction %s\n", direction_str);
9583 return CMD_WARNING_CONFIG_FAILED;
9584 }
9585
9586 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9587
9588 if (yes) {
9589 SET_FLAG(bgp->af_flags[afi][safi], flag);
9590 if (!previous_state) {
9591 /* trigger export current vrf */
9592 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9593 }
9594 } else {
9595 if (previous_state) {
9596 /* trigger un-export current vrf */
9597 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9598 }
9599 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9600 }
9601
9602 hook_call(bgp_snmp_init_stats, bgp);
9603
9604 return CMD_SUCCESS;
9605 }
9606
9607 DEFPY (af_routetarget_import,
9608 af_routetarget_import_cmd,
9609 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9610 NO_STR
9611 "Specify route target list\n"
9612 "Specify route target list\n"
9613 "Specify route target list\n"
9614 "Specify route target list\n"
9615 "Flow-spec redirect type route target\n"
9616 "Import routes to this address-family\n"
9617 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9618 {
9619 VTY_DECLVAR_CONTEXT(bgp, bgp);
9620 int ret;
9621 struct ecommunity *ecom = NULL;
9622 afi_t afi;
9623 int idx = 0, idx_unused = 0;
9624 bool yes = true;
9625 bool rt6 = false;
9626
9627 if (argv_find(argv, argc, "no", &idx))
9628 yes = false;
9629
9630 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9631 argv_find(argv, argc, "route-target6", &idx_unused))
9632 rt6 = true;
9633
9634 afi = vpn_policy_getafi(vty, bgp, false);
9635 if (afi == AFI_MAX)
9636 return CMD_WARNING_CONFIG_FAILED;
9637
9638 if (rt6 && afi != AFI_IP6)
9639 return CMD_WARNING_CONFIG_FAILED;
9640
9641 if (yes) {
9642 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9643 vty_out(vty, "%% Missing RTLIST\n");
9644 return CMD_WARNING_CONFIG_FAILED;
9645 }
9646 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9647 if (ret != CMD_SUCCESS)
9648 return ret;
9649 }
9650
9651 if (yes) {
9652 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9653 ecommunity_free(&bgp->vpn_policy[afi]
9654 .import_redirect_rtlist);
9655 bgp->vpn_policy[afi].import_redirect_rtlist =
9656 ecommunity_dup(ecom);
9657 } else {
9658 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9659 ecommunity_free(&bgp->vpn_policy[afi]
9660 .import_redirect_rtlist);
9661 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9662 }
9663
9664 if (ecom)
9665 ecommunity_free(&ecom);
9666
9667 return CMD_SUCCESS;
9668 }
9669
9670 DEFUN_NOSH (address_family_ipv4_safi,
9671 address_family_ipv4_safi_cmd,
9672 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9673 "Enter Address Family command mode\n"
9674 BGP_AF_STR
9675 BGP_SAFI_WITH_LABEL_HELP_STR)
9676 {
9677
9678 if (argc == 3) {
9679 VTY_DECLVAR_CONTEXT(bgp, bgp);
9680 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9681 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9682 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9683 && safi != SAFI_EVPN) {
9684 vty_out(vty,
9685 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9686 return CMD_WARNING_CONFIG_FAILED;
9687 }
9688 vty->node = bgp_node_type(AFI_IP, safi);
9689 } else
9690 vty->node = BGP_IPV4_NODE;
9691
9692 return CMD_SUCCESS;
9693 }
9694
9695 DEFUN_NOSH (address_family_ipv6_safi,
9696 address_family_ipv6_safi_cmd,
9697 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9698 "Enter Address Family command mode\n"
9699 BGP_AF_STR
9700 BGP_SAFI_WITH_LABEL_HELP_STR)
9701 {
9702 if (argc == 3) {
9703 VTY_DECLVAR_CONTEXT(bgp, bgp);
9704 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9705 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9706 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9707 && safi != SAFI_EVPN) {
9708 vty_out(vty,
9709 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9710 return CMD_WARNING_CONFIG_FAILED;
9711 }
9712 vty->node = bgp_node_type(AFI_IP6, safi);
9713 } else
9714 vty->node = BGP_IPV6_NODE;
9715
9716 return CMD_SUCCESS;
9717 }
9718
9719 #ifdef KEEP_OLD_VPN_COMMANDS
9720 DEFUN_NOSH (address_family_vpnv4,
9721 address_family_vpnv4_cmd,
9722 "address-family vpnv4 [unicast]",
9723 "Enter Address Family command mode\n"
9724 BGP_AF_STR
9725 BGP_AF_MODIFIER_STR)
9726 {
9727 vty->node = BGP_VPNV4_NODE;
9728 return CMD_SUCCESS;
9729 }
9730
9731 DEFUN_NOSH (address_family_vpnv6,
9732 address_family_vpnv6_cmd,
9733 "address-family vpnv6 [unicast]",
9734 "Enter Address Family command mode\n"
9735 BGP_AF_STR
9736 BGP_AF_MODIFIER_STR)
9737 {
9738 vty->node = BGP_VPNV6_NODE;
9739 return CMD_SUCCESS;
9740 }
9741 #endif /* KEEP_OLD_VPN_COMMANDS */
9742
9743 DEFUN_NOSH (address_family_evpn,
9744 address_family_evpn_cmd,
9745 "address-family l2vpn evpn",
9746 "Enter Address Family command mode\n"
9747 BGP_AF_STR
9748 BGP_AF_MODIFIER_STR)
9749 {
9750 VTY_DECLVAR_CONTEXT(bgp, bgp);
9751 vty->node = BGP_EVPN_NODE;
9752 return CMD_SUCCESS;
9753 }
9754
9755 DEFUN_NOSH (bgp_segment_routing_srv6,
9756 bgp_segment_routing_srv6_cmd,
9757 "segment-routing srv6",
9758 "Segment-Routing configuration\n"
9759 "Segment-Routing SRv6 configuration\n")
9760 {
9761 VTY_DECLVAR_CONTEXT(bgp, bgp);
9762 bgp->srv6_enabled = true;
9763 vty->node = BGP_SRV6_NODE;
9764 return CMD_SUCCESS;
9765 }
9766
9767 DEFUN (no_bgp_segment_routing_srv6,
9768 no_bgp_segment_routing_srv6_cmd,
9769 "no segment-routing srv6",
9770 NO_STR
9771 "Segment-Routing configuration\n"
9772 "Segment-Routing SRv6 configuration\n")
9773 {
9774 VTY_DECLVAR_CONTEXT(bgp, bgp);
9775
9776 if (strlen(bgp->srv6_locator_name) > 0)
9777 if (bgp_srv6_locator_unset(bgp) < 0)
9778 return CMD_WARNING_CONFIG_FAILED;
9779
9780 bgp->srv6_enabled = false;
9781 return CMD_SUCCESS;
9782 }
9783
9784 DEFPY (bgp_srv6_locator,
9785 bgp_srv6_locator_cmd,
9786 "locator NAME$name",
9787 "Specify SRv6 locator\n"
9788 "Specify SRv6 locator\n")
9789 {
9790 VTY_DECLVAR_CONTEXT(bgp, bgp);
9791 int ret;
9792
9793 if (strlen(bgp->srv6_locator_name) > 0
9794 && strcmp(name, bgp->srv6_locator_name) != 0) {
9795 vty_out(vty, "srv6 locator is already configured\n");
9796 return CMD_WARNING_CONFIG_FAILED;
9797 }
9798
9799 snprintf(bgp->srv6_locator_name,
9800 sizeof(bgp->srv6_locator_name), "%s", name);
9801
9802 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9803 if (ret < 0)
9804 return CMD_WARNING_CONFIG_FAILED;
9805
9806 return CMD_SUCCESS;
9807 }
9808
9809 DEFPY (no_bgp_srv6_locator,
9810 no_bgp_srv6_locator_cmd,
9811 "no locator NAME$name",
9812 NO_STR
9813 "Specify SRv6 locator\n"
9814 "Specify SRv6 locator\n")
9815 {
9816 VTY_DECLVAR_CONTEXT(bgp, bgp);
9817
9818 /* when locator isn't configured, do nothing */
9819 if (strlen(bgp->srv6_locator_name) < 1)
9820 return CMD_SUCCESS;
9821
9822 /* name validation */
9823 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9824 vty_out(vty, "%% No srv6 locator is configured\n");
9825 return CMD_WARNING_CONFIG_FAILED;
9826 }
9827
9828 /* unset locator */
9829 if (bgp_srv6_locator_unset(bgp) < 0)
9830 return CMD_WARNING_CONFIG_FAILED;
9831
9832 return CMD_SUCCESS;
9833 }
9834
9835 DEFPY (show_bgp_srv6,
9836 show_bgp_srv6_cmd,
9837 "show bgp segment-routing srv6",
9838 SHOW_STR
9839 BGP_STR
9840 "BGP Segment Routing\n"
9841 "BGP Segment Routing SRv6\n")
9842 {
9843 struct bgp *bgp;
9844 struct listnode *node;
9845 struct srv6_locator_chunk *chunk;
9846 struct bgp_srv6_function *func;
9847 char buf[256];
9848
9849 bgp = bgp_get_default();
9850 if (!bgp)
9851 return CMD_SUCCESS;
9852
9853 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9854 vty_out(vty, "locator_chunks:\n");
9855 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9856 vty_out(vty, "- %pFX\n", &chunk->prefix);
9857 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9858 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9859 vty_out(vty, " func-length: %d\n",
9860 chunk->function_bits_length);
9861 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9862 }
9863
9864 vty_out(vty, "functions:\n");
9865 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9866 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9867 vty_out(vty, "- sid: %s\n", buf);
9868 vty_out(vty, " locator: %s\n", func->locator_name);
9869 }
9870
9871 vty_out(vty, "bgps:\n");
9872 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9873 vty_out(vty, "- name: %s\n",
9874 bgp->name ? bgp->name : "default");
9875
9876 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9877 bgp->vpn_policy[AFI_IP].tovpn_sid);
9878 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9879 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9880 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
9881 }
9882
9883 return CMD_SUCCESS;
9884 }
9885
9886 DEFUN_NOSH (exit_address_family,
9887 exit_address_family_cmd,
9888 "exit-address-family",
9889 "Exit from Address Family configuration mode\n")
9890 {
9891 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9892 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9893 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9894 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9895 || vty->node == BGP_EVPN_NODE
9896 || vty->node == BGP_FLOWSPECV4_NODE
9897 || vty->node == BGP_FLOWSPECV6_NODE)
9898 vty->node = BGP_NODE;
9899 return CMD_SUCCESS;
9900 }
9901
9902 /* Recalculate bestpath and re-advertise a prefix */
9903 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9904 const char *ip_str, afi_t afi, safi_t safi,
9905 struct prefix_rd *prd)
9906 {
9907 int ret;
9908 struct prefix match;
9909 struct bgp_dest *dest;
9910 struct bgp_dest *rm;
9911 struct bgp *bgp;
9912 struct bgp_table *table;
9913 struct bgp_table *rib;
9914
9915 /* BGP structure lookup. */
9916 if (view_name) {
9917 bgp = bgp_lookup_by_name(view_name);
9918 if (bgp == NULL) {
9919 vty_out(vty, "%% Can't find BGP instance %s\n",
9920 view_name);
9921 return CMD_WARNING;
9922 }
9923 } else {
9924 bgp = bgp_get_default();
9925 if (bgp == NULL) {
9926 vty_out(vty, "%% No BGP process is configured\n");
9927 return CMD_WARNING;
9928 }
9929 }
9930
9931 /* Check IP address argument. */
9932 ret = str2prefix(ip_str, &match);
9933 if (!ret) {
9934 vty_out(vty, "%% address is malformed\n");
9935 return CMD_WARNING;
9936 }
9937
9938 match.family = afi2family(afi);
9939 rib = bgp->rib[afi][safi];
9940
9941 if (safi == SAFI_MPLS_VPN) {
9942 for (dest = bgp_table_top(rib); dest;
9943 dest = bgp_route_next(dest)) {
9944 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9945
9946 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9947 continue;
9948
9949 table = bgp_dest_get_bgp_table_info(dest);
9950 if (table == NULL)
9951 continue;
9952
9953 rm = bgp_node_match(table, &match);
9954 if (rm != NULL) {
9955 const struct prefix *rm_p =
9956 bgp_dest_get_prefix(rm);
9957
9958 if (rm_p->prefixlen == match.prefixlen) {
9959 SET_FLAG(rm->flags,
9960 BGP_NODE_USER_CLEAR);
9961 bgp_process(bgp, rm, afi, safi);
9962 }
9963 bgp_dest_unlock_node(rm);
9964 }
9965 }
9966 } else {
9967 dest = bgp_node_match(rib, &match);
9968 if (dest != NULL) {
9969 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9970
9971 if (dest_p->prefixlen == match.prefixlen) {
9972 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9973 bgp_process(bgp, dest, afi, safi);
9974 }
9975 bgp_dest_unlock_node(dest);
9976 }
9977 }
9978
9979 return CMD_SUCCESS;
9980 }
9981
9982 /* one clear bgp command to rule them all */
9983 DEFUN (clear_ip_bgp_all,
9984 clear_ip_bgp_all_cmd,
9985 "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>]",
9986 CLEAR_STR
9987 IP_STR
9988 BGP_STR
9989 BGP_INSTANCE_HELP_STR
9990 BGP_AFI_HELP_STR
9991 BGP_AF_STR
9992 BGP_SAFI_WITH_LABEL_HELP_STR
9993 BGP_AF_MODIFIER_STR
9994 "Clear all peers\n"
9995 "BGP IPv4 neighbor to clear\n"
9996 "BGP IPv6 neighbor to clear\n"
9997 "BGP neighbor on interface to clear\n"
9998 "Clear peers with the AS number\n"
9999 "Clear all external peers\n"
10000 "Clear all members of peer-group\n"
10001 "BGP peer-group name\n"
10002 BGP_SOFT_STR
10003 BGP_SOFT_IN_STR
10004 BGP_SOFT_OUT_STR
10005 BGP_SOFT_IN_STR
10006 "Push out prefix-list ORF and do inbound soft reconfig\n"
10007 BGP_SOFT_OUT_STR
10008 "Reset message statistics\n")
10009 {
10010 char *vrf = NULL;
10011
10012 afi_t afi = AFI_UNSPEC;
10013 safi_t safi = SAFI_UNSPEC;
10014 enum clear_sort clr_sort = clear_peer;
10015 enum bgp_clear_type clr_type;
10016 char *clr_arg = NULL;
10017
10018 int idx = 0;
10019
10020 /* clear [ip] bgp */
10021 if (argv_find(argv, argc, "ip", &idx))
10022 afi = AFI_IP;
10023
10024 /* [<vrf> VIEWVRFNAME] */
10025 if (argv_find(argv, argc, "vrf", &idx)) {
10026 vrf = argv[idx + 1]->arg;
10027 idx += 2;
10028 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10029 vrf = NULL;
10030 } else if (argv_find(argv, argc, "view", &idx)) {
10031 /* [<view> VIEWVRFNAME] */
10032 vrf = argv[idx + 1]->arg;
10033 idx += 2;
10034 }
10035 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10036 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10037 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10038
10039 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10040 if (argv_find(argv, argc, "*", &idx)) {
10041 clr_sort = clear_all;
10042 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10043 clr_sort = clear_peer;
10044 clr_arg = argv[idx]->arg;
10045 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10046 clr_sort = clear_peer;
10047 clr_arg = argv[idx]->arg;
10048 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10049 clr_sort = clear_group;
10050 idx++;
10051 clr_arg = argv[idx]->arg;
10052 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10053 clr_sort = clear_peer;
10054 clr_arg = argv[idx]->arg;
10055 } else if (argv_find(argv, argc, "WORD", &idx)) {
10056 clr_sort = clear_peer;
10057 clr_arg = argv[idx]->arg;
10058 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10059 clr_sort = clear_as;
10060 clr_arg = argv[idx]->arg;
10061 } else if (argv_find(argv, argc, "external", &idx)) {
10062 clr_sort = clear_external;
10063 }
10064
10065 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10066 if (argv_find(argv, argc, "soft", &idx)) {
10067 if (argv_find(argv, argc, "in", &idx)
10068 || argv_find(argv, argc, "out", &idx))
10069 clr_type = strmatch(argv[idx]->text, "in")
10070 ? BGP_CLEAR_SOFT_IN
10071 : BGP_CLEAR_SOFT_OUT;
10072 else
10073 clr_type = BGP_CLEAR_SOFT_BOTH;
10074 } else if (argv_find(argv, argc, "in", &idx)) {
10075 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10076 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10077 : BGP_CLEAR_SOFT_IN;
10078 } else if (argv_find(argv, argc, "out", &idx)) {
10079 clr_type = BGP_CLEAR_SOFT_OUT;
10080 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10081 clr_type = BGP_CLEAR_MESSAGE_STATS;
10082 } else
10083 clr_type = BGP_CLEAR_SOFT_NONE;
10084
10085 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10086 }
10087
10088 DEFUN (clear_ip_bgp_prefix,
10089 clear_ip_bgp_prefix_cmd,
10090 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10091 CLEAR_STR
10092 IP_STR
10093 BGP_STR
10094 BGP_INSTANCE_HELP_STR
10095 "Clear bestpath and re-advertise\n"
10096 "IPv4 prefix\n")
10097 {
10098 char *vrf = NULL;
10099 char *prefix = NULL;
10100
10101 int idx = 0;
10102
10103 /* [<view|vrf> VIEWVRFNAME] */
10104 if (argv_find(argv, argc, "vrf", &idx)) {
10105 vrf = argv[idx + 1]->arg;
10106 idx += 2;
10107 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10108 vrf = NULL;
10109 } else if (argv_find(argv, argc, "view", &idx)) {
10110 /* [<view> VIEWVRFNAME] */
10111 vrf = argv[idx + 1]->arg;
10112 idx += 2;
10113 }
10114
10115 prefix = argv[argc - 1]->arg;
10116
10117 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10118 }
10119
10120 DEFUN (clear_bgp_ipv6_safi_prefix,
10121 clear_bgp_ipv6_safi_prefix_cmd,
10122 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10123 CLEAR_STR
10124 IP_STR
10125 BGP_STR
10126 BGP_AF_STR
10127 BGP_SAFI_HELP_STR
10128 "Clear bestpath and re-advertise\n"
10129 "IPv6 prefix\n")
10130 {
10131 int idx_safi = 0;
10132 int idx_ipv6_prefix = 0;
10133 safi_t safi = SAFI_UNICAST;
10134 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10135 argv[idx_ipv6_prefix]->arg : NULL;
10136
10137 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10138 return bgp_clear_prefix(
10139 vty, NULL, prefix, AFI_IP6,
10140 safi, NULL);
10141 }
10142
10143 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10144 clear_bgp_instance_ipv6_safi_prefix_cmd,
10145 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10146 CLEAR_STR
10147 IP_STR
10148 BGP_STR
10149 BGP_INSTANCE_HELP_STR
10150 BGP_AF_STR
10151 BGP_SAFI_HELP_STR
10152 "Clear bestpath and re-advertise\n"
10153 "IPv6 prefix\n")
10154 {
10155 int idx_safi = 0;
10156 int idx_vrfview = 0;
10157 int idx_ipv6_prefix = 0;
10158 safi_t safi = SAFI_UNICAST;
10159 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10160 argv[idx_ipv6_prefix]->arg : NULL;
10161 char *vrfview = NULL;
10162
10163 /* [<view|vrf> VIEWVRFNAME] */
10164 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10165 vrfview = argv[idx_vrfview + 1]->arg;
10166 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10167 vrfview = NULL;
10168 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10169 /* [<view> VIEWVRFNAME] */
10170 vrfview = argv[idx_vrfview + 1]->arg;
10171 }
10172 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10173
10174 return bgp_clear_prefix(
10175 vty, vrfview, prefix,
10176 AFI_IP6, safi, NULL);
10177 }
10178
10179 DEFUN (show_bgp_views,
10180 show_bgp_views_cmd,
10181 "show [ip] bgp views",
10182 SHOW_STR
10183 IP_STR
10184 BGP_STR
10185 "Show the defined BGP views\n")
10186 {
10187 struct list *inst = bm->bgp;
10188 struct listnode *node;
10189 struct bgp *bgp;
10190
10191 vty_out(vty, "Defined BGP views:\n");
10192 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10193 /* Skip VRFs. */
10194 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10195 continue;
10196 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10197 bgp->as);
10198 }
10199
10200 return CMD_SUCCESS;
10201 }
10202
10203 DEFUN (show_bgp_vrfs,
10204 show_bgp_vrfs_cmd,
10205 "show [ip] bgp vrfs [json]",
10206 SHOW_STR
10207 IP_STR
10208 BGP_STR
10209 "Show BGP VRFs\n"
10210 JSON_STR)
10211 {
10212 char buf[ETHER_ADDR_STRLEN];
10213 struct list *inst = bm->bgp;
10214 struct listnode *node;
10215 struct bgp *bgp;
10216 bool uj = use_json(argc, argv);
10217 json_object *json = NULL;
10218 json_object *json_vrfs = NULL;
10219 int count = 0;
10220
10221 if (uj) {
10222 json = json_object_new_object();
10223 json_vrfs = json_object_new_object();
10224 }
10225
10226 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10227 const char *name, *type;
10228 struct peer *peer;
10229 struct listnode *node2, *nnode2;
10230 int peers_cfg, peers_estb;
10231 json_object *json_vrf = NULL;
10232
10233 /* Skip Views. */
10234 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10235 continue;
10236
10237 count++;
10238 if (!uj && count == 1) {
10239 vty_out(vty,
10240 "%4s %-5s %-16s %9s %10s %-37s\n",
10241 "Type", "Id", "routerId", "#PeersCfg",
10242 "#PeersEstb", "Name");
10243 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10244 "L3-VNI", "RouterMAC", "Interface");
10245 }
10246
10247 peers_cfg = peers_estb = 0;
10248 if (uj)
10249 json_vrf = json_object_new_object();
10250
10251
10252 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10253 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10254 continue;
10255 peers_cfg++;
10256 if (peer_established(peer))
10257 peers_estb++;
10258 }
10259
10260 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10261 name = VRF_DEFAULT_NAME;
10262 type = "DFLT";
10263 } else {
10264 name = bgp->name;
10265 type = "VRF";
10266 }
10267
10268
10269 if (uj) {
10270 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10271 ? -1
10272 : (int64_t)bgp->vrf_id;
10273 char buf[BUFSIZ] = {0};
10274
10275 json_object_string_add(json_vrf, "type", type);
10276 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10277 json_object_string_addf(json_vrf, "routerId", "%pI4",
10278 &bgp->router_id);
10279 json_object_int_add(json_vrf, "numConfiguredPeers",
10280 peers_cfg);
10281 json_object_int_add(json_vrf, "numEstablishedPeers",
10282 peers_estb);
10283
10284 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10285 json_object_string_add(
10286 json_vrf, "rmac",
10287 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10288 json_object_string_add(json_vrf, "interface",
10289 ifindex2ifname(bgp->l3vni_svi_ifindex,
10290 bgp->vrf_id));
10291 json_object_object_add(json_vrfs, name, json_vrf);
10292 } else {
10293 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10294 type,
10295 bgp->vrf_id == VRF_UNKNOWN ? -1
10296 : (int)bgp->vrf_id,
10297 &bgp->router_id, peers_cfg, peers_estb, name);
10298 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10299 bgp->l3vni,
10300 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10301 ifindex2ifname(bgp->l3vni_svi_ifindex,
10302 bgp->vrf_id));
10303 }
10304 }
10305
10306 if (uj) {
10307 json_object_object_add(json, "vrfs", json_vrfs);
10308
10309 json_object_int_add(json, "totalVrfs", count);
10310
10311 vty_json(vty, json);
10312 } else {
10313 if (count)
10314 vty_out(vty,
10315 "\nTotal number of VRFs (including default): %d\n",
10316 count);
10317 }
10318
10319 return CMD_SUCCESS;
10320 }
10321
10322 DEFUN (show_bgp_mac_hash,
10323 show_bgp_mac_hash_cmd,
10324 "show bgp mac hash",
10325 SHOW_STR
10326 BGP_STR
10327 "Mac Address\n"
10328 "Mac Address database\n")
10329 {
10330 bgp_mac_dump_table(vty);
10331
10332 return CMD_SUCCESS;
10333 }
10334
10335 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10336 {
10337 struct vty *vty = (struct vty *)args;
10338 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10339
10340 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10341 }
10342
10343 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10344 {
10345 vty_out(vty, "self nexthop database:\n");
10346 bgp_nexthop_show_address_hash(vty, bgp);
10347
10348 vty_out(vty, "Tunnel-ip database:\n");
10349 hash_iterate(bgp->tip_hash,
10350 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10351 vty);
10352 }
10353
10354 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10355 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10356 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10357 "martian next-hops\n"
10358 "martian next-hop database\n")
10359 {
10360 struct bgp *bgp = NULL;
10361 int idx = 0;
10362 char *name = NULL;
10363
10364 /* [<vrf> VIEWVRFNAME] */
10365 if (argv_find(argv, argc, "vrf", &idx)) {
10366 name = argv[idx + 1]->arg;
10367 if (name && strmatch(name, VRF_DEFAULT_NAME))
10368 name = NULL;
10369 } else if (argv_find(argv, argc, "view", &idx))
10370 /* [<view> VIEWVRFNAME] */
10371 name = argv[idx + 1]->arg;
10372 if (name)
10373 bgp = bgp_lookup_by_name(name);
10374 else
10375 bgp = bgp_get_default();
10376
10377 if (!bgp) {
10378 vty_out(vty, "%% No BGP process is configured\n");
10379 return CMD_WARNING;
10380 }
10381 bgp_show_martian_nexthops(vty, bgp);
10382
10383 return CMD_SUCCESS;
10384 }
10385
10386 DEFUN (show_bgp_memory,
10387 show_bgp_memory_cmd,
10388 "show [ip] bgp memory",
10389 SHOW_STR
10390 IP_STR
10391 BGP_STR
10392 "Global BGP memory statistics\n")
10393 {
10394 char memstrbuf[MTYPE_MEMSTR_LEN];
10395 unsigned long count;
10396
10397 /* RIB related usage stats */
10398 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10399 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10400 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10401 count * sizeof(struct bgp_dest)));
10402
10403 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10404 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10405 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10406 count * sizeof(struct bgp_path_info)));
10407 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10408 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10409 count,
10410 mtype_memstr(
10411 memstrbuf, sizeof(memstrbuf),
10412 count * sizeof(struct bgp_path_info_extra)));
10413
10414 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10415 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10416 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10417 count * sizeof(struct bgp_static)));
10418
10419 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10420 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10421 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10422 count * sizeof(struct bpacket)));
10423
10424 /* Adj-In/Out */
10425 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10426 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10427 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10428 count * sizeof(struct bgp_adj_in)));
10429 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10430 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10431 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10432 count * sizeof(struct bgp_adj_out)));
10433
10434 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10435 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10436 count,
10437 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10438 count * sizeof(struct bgp_nexthop_cache)));
10439
10440 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10441 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10442 count,
10443 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10444 count * sizeof(struct bgp_damp_info)));
10445
10446 /* Attributes */
10447 count = attr_count();
10448 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10449 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10450 count * sizeof(struct attr)));
10451
10452 if ((count = attr_unknown_count()))
10453 vty_out(vty, "%ld unknown attributes\n", count);
10454
10455 /* AS_PATH attributes */
10456 count = aspath_count();
10457 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10458 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10459 count * sizeof(struct aspath)));
10460
10461 count = mtype_stats_alloc(MTYPE_AS_SEG);
10462 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10463 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10464 count * sizeof(struct assegment)));
10465
10466 /* Other attributes */
10467 if ((count = community_count()))
10468 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10469 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10470 count * sizeof(struct community)));
10471 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10472 vty_out(vty,
10473 "%ld BGP ext-community entries, using %s of memory\n",
10474 count,
10475 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10476 count * sizeof(struct ecommunity)));
10477 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10478 vty_out(vty,
10479 "%ld BGP large-community entries, using %s of memory\n",
10480 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10481 count * sizeof(struct lcommunity)));
10482
10483 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10484 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10485 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10486 count * sizeof(struct cluster_list)));
10487
10488 /* Peer related usage */
10489 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10490 vty_out(vty, "%ld peers, using %s of memory\n", count,
10491 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10492 count * sizeof(struct peer)));
10493
10494 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10495 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10497 count * sizeof(struct peer_group)));
10498
10499 /* Other */
10500 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10501 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10502 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10503 count * sizeof(regex_t)));
10504 return CMD_SUCCESS;
10505 }
10506
10507 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10508 {
10509 json_object *bestpath = json_object_new_object();
10510
10511 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10512 json_object_string_add(bestpath, "asPath", "ignore");
10513
10514 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10515 json_object_string_add(bestpath, "asPath", "confed");
10516
10517 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10518 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10519 json_object_string_add(bestpath, "multiPathRelax",
10520 "as-set");
10521 else
10522 json_object_string_add(bestpath, "multiPathRelax",
10523 "true");
10524 } else
10525 json_object_string_add(bestpath, "multiPathRelax", "false");
10526
10527 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10528 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10529
10530 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10531 json_object_string_add(bestpath, "compareRouterId", "true");
10532 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10533 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10534 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10535 json_object_string_add(bestpath, "med", "confed");
10536 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10537 json_object_string_add(bestpath, "med",
10538 "missing-as-worst");
10539 else
10540 json_object_string_add(bestpath, "med", "true");
10541 }
10542
10543 json_object_object_add(json, "bestPath", bestpath);
10544 }
10545
10546 /* Print the error code/subcode for why the peer is down */
10547 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10548 json_object *json_peer, bool use_json)
10549 {
10550 const char *code_str;
10551 const char *subcode_str;
10552
10553 if (use_json) {
10554 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10555 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10556 char errorcodesubcode_hexstr[5];
10557 char errorcodesubcode_str[256];
10558
10559 code_str = bgp_notify_code_str(peer->notify.code);
10560 subcode_str = bgp_notify_subcode_str(
10561 peer->notify.code,
10562 peer->notify.subcode);
10563
10564 snprintf(errorcodesubcode_hexstr,
10565 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10566 peer->notify.code, peer->notify.subcode);
10567 json_object_string_add(json_peer,
10568 "lastErrorCodeSubcode",
10569 errorcodesubcode_hexstr);
10570 snprintf(errorcodesubcode_str, 255, "%s%s",
10571 code_str, subcode_str);
10572 json_object_string_add(json_peer,
10573 "lastNotificationReason",
10574 errorcodesubcode_str);
10575 json_object_boolean_add(json_peer,
10576 "lastNotificationHardReset",
10577 peer->notify.hard_reset);
10578 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10579 && peer->notify.code == BGP_NOTIFY_CEASE
10580 && (peer->notify.subcode
10581 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10582 || peer->notify.subcode
10583 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10584 && peer->notify.length) {
10585 char msgbuf[1024];
10586 const char *msg_str;
10587
10588 msg_str = bgp_notify_admin_message(
10589 msgbuf, sizeof(msgbuf),
10590 (uint8_t *)peer->notify.data,
10591 peer->notify.length);
10592 if (msg_str)
10593 json_object_string_add(
10594 json_peer,
10595 "lastShutdownDescription",
10596 msg_str);
10597 }
10598
10599 }
10600 json_object_string_add(json_peer, "lastResetDueTo",
10601 peer_down_str[(int)peer->last_reset]);
10602 json_object_int_add(json_peer, "lastResetCode",
10603 peer->last_reset);
10604 } else {
10605 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10606 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10607 code_str = bgp_notify_code_str(peer->notify.code);
10608 subcode_str =
10609 bgp_notify_subcode_str(peer->notify.code,
10610 peer->notify.subcode);
10611 vty_out(vty, " Notification %s (%s%s%s)\n",
10612 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10613 ? "sent"
10614 : "received",
10615 code_str, subcode_str,
10616 peer->notify.hard_reset
10617 ? bgp_notify_subcode_str(
10618 BGP_NOTIFY_CEASE,
10619 BGP_NOTIFY_CEASE_HARD_RESET)
10620 : "");
10621 } else {
10622 vty_out(vty, " %s\n",
10623 peer_down_str[(int)peer->last_reset]);
10624 }
10625 }
10626 }
10627
10628 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10629 safi_t safi)
10630 {
10631 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10632 }
10633
10634 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10635 struct peer *peer, json_object *json_peer,
10636 int max_neighbor_width, bool use_json)
10637 {
10638 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10639 int len;
10640
10641 if (use_json) {
10642 if (peer_dynamic_neighbor(peer))
10643 json_object_boolean_true_add(json_peer,
10644 "dynamicPeer");
10645 if (peer->hostname)
10646 json_object_string_add(json_peer, "hostname",
10647 peer->hostname);
10648
10649 if (peer->domainname)
10650 json_object_string_add(json_peer, "domainname",
10651 peer->domainname);
10652 json_object_int_add(json_peer, "connectionsEstablished",
10653 peer->established);
10654 json_object_int_add(json_peer, "connectionsDropped",
10655 peer->dropped);
10656 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10657 use_json, json_peer);
10658 if (peer_established(peer))
10659 json_object_string_add(json_peer, "lastResetDueTo",
10660 "AFI/SAFI Not Negotiated");
10661 else
10662 bgp_show_peer_reset(NULL, peer, json_peer, true);
10663 } else {
10664 dn_flag[1] = '\0';
10665 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10666 if (peer->hostname
10667 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10668 len = vty_out(vty, "%s%s(%s)", dn_flag,
10669 peer->hostname, peer->host);
10670 else
10671 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10672
10673 /* pad the neighbor column with spaces */
10674 if (len < max_neighbor_width)
10675 vty_out(vty, "%*s", max_neighbor_width - len,
10676 " ");
10677 vty_out(vty, "%7d %7d %9s", peer->established,
10678 peer->dropped,
10679 peer_uptime(peer->uptime, timebuf,
10680 BGP_UPTIME_LEN, 0, NULL));
10681 if (peer_established(peer))
10682 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10683 else
10684 bgp_show_peer_reset(vty, peer, NULL,
10685 false);
10686 }
10687 }
10688
10689 /* Strip peer's description to the given size. */
10690 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10691 {
10692 static char stripped[BUFSIZ];
10693 uint32_t i = 0;
10694 uint32_t last_space = 0;
10695
10696 while (i < size) {
10697 if (*(desc + i) == 0) {
10698 stripped[i] = '\0';
10699 return stripped;
10700 }
10701 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10702 last_space = i;
10703 stripped[i] = *(desc + i);
10704 i++;
10705 }
10706
10707 if (last_space > size)
10708 stripped[size + 1] = '\0';
10709 else
10710 stripped[last_space] = '\0';
10711
10712 return stripped;
10713 }
10714
10715 /* Determine whether var peer should be filtered out of the summary. */
10716 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10717 struct peer *fpeer, int as_type,
10718 as_t as)
10719 {
10720
10721 /* filter neighbor XXXX */
10722 if (fpeer && fpeer != peer)
10723 return true;
10724
10725 /* filter remote-as (internal|external) */
10726 if (as_type != AS_UNSPECIFIED) {
10727 if (peer->as_type == AS_SPECIFIED) {
10728 if (as_type == AS_INTERNAL) {
10729 if (peer->as != peer->local_as)
10730 return true;
10731 } else if (peer->as == peer->local_as)
10732 return true;
10733 } else if (as_type != peer->as_type)
10734 return true;
10735 } else if (as && as != peer->as) /* filter remote-as XXX */
10736 return true;
10737
10738 return false;
10739 }
10740
10741 /* Show BGP peer's summary information.
10742 *
10743 * Peer's description is stripped according to if `wide` option is given
10744 * or not.
10745 *
10746 * When adding new columns to `show bgp summary` output, please make
10747 * sure `Desc` is the lastest column to show because it can contain
10748 * whitespaces and the whole output will be tricky.
10749 */
10750 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10751 struct peer *fpeer, int as_type, as_t as,
10752 uint16_t show_flags)
10753 {
10754 struct peer *peer;
10755 struct listnode *node, *nnode;
10756 unsigned int count = 0, dn_count = 0;
10757 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10758 char neighbor_buf[VTY_BUFSIZ];
10759 int neighbor_col_default_width = 16;
10760 int len, failed_count = 0;
10761 unsigned int filtered_count = 0;
10762 int max_neighbor_width = 0;
10763 int pfx_rcd_safi;
10764 json_object *json = NULL;
10765 json_object *json_peer = NULL;
10766 json_object *json_peers = NULL;
10767 struct peer_af *paf;
10768 struct bgp_filter *filter;
10769 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10770 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10771 bool show_established =
10772 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10773 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10774 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10775
10776 /* labeled-unicast routes are installed in the unicast table so in order
10777 * to
10778 * display the correct PfxRcd value we must look at SAFI_UNICAST
10779 */
10780
10781 if (safi == SAFI_LABELED_UNICAST)
10782 pfx_rcd_safi = SAFI_UNICAST;
10783 else
10784 pfx_rcd_safi = safi;
10785
10786 if (use_json) {
10787 json = json_object_new_object();
10788 json_peers = json_object_new_object();
10789 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10790 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10791 as_type, as)) {
10792 filtered_count++;
10793 count++;
10794 continue;
10795 }
10796
10797 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10798 continue;
10799
10800 if (peer->afc[afi][safi]) {
10801 /* See if we have at least a single failed peer */
10802 if (bgp_has_peer_failed(peer, afi, safi))
10803 failed_count++;
10804 count++;
10805 }
10806 if (peer_dynamic_neighbor(peer))
10807 dn_count++;
10808 }
10809
10810 } else {
10811 /* Loop over all neighbors that will be displayed to determine
10812 * how many
10813 * characters are needed for the Neighbor column
10814 */
10815 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10816 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10817 as_type, as)) {
10818 filtered_count++;
10819 count++;
10820 continue;
10821 }
10822
10823 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10824 continue;
10825
10826 if (peer->afc[afi][safi]) {
10827 memset(dn_flag, '\0', sizeof(dn_flag));
10828 if (peer_dynamic_neighbor(peer))
10829 dn_flag[0] = '*';
10830
10831 if (peer->hostname
10832 && CHECK_FLAG(bgp->flags,
10833 BGP_FLAG_SHOW_HOSTNAME))
10834 snprintf(neighbor_buf,
10835 sizeof(neighbor_buf),
10836 "%s%s(%s) ", dn_flag,
10837 peer->hostname, peer->host);
10838 else
10839 snprintf(neighbor_buf,
10840 sizeof(neighbor_buf), "%s%s ",
10841 dn_flag, peer->host);
10842
10843 len = strlen(neighbor_buf);
10844
10845 if (len > max_neighbor_width)
10846 max_neighbor_width = len;
10847
10848 /* See if we have at least a single failed peer */
10849 if (bgp_has_peer_failed(peer, afi, safi))
10850 failed_count++;
10851 count++;
10852 }
10853 }
10854
10855 /* Originally we displayed the Neighbor column as 16
10856 * characters wide so make that the default
10857 */
10858 if (max_neighbor_width < neighbor_col_default_width)
10859 max_neighbor_width = neighbor_col_default_width;
10860 }
10861
10862 if (show_failed && !failed_count) {
10863 if (use_json) {
10864 json_object_int_add(json, "failedPeersCount", 0);
10865 json_object_int_add(json, "dynamicPeers", dn_count);
10866 json_object_int_add(json, "totalPeers", count);
10867
10868 vty_json(vty, json);
10869 } else {
10870 vty_out(vty, "%% No failed BGP neighbors found\n");
10871 }
10872 return CMD_SUCCESS;
10873 }
10874
10875 count = 0; /* Reset the value as its used again */
10876 filtered_count = 0;
10877 dn_count = 0;
10878 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10879 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10880 continue;
10881
10882 if (!peer->afc[afi][safi])
10883 continue;
10884
10885 if (!count) {
10886 unsigned long ents;
10887 char memstrbuf[MTYPE_MEMSTR_LEN];
10888 int64_t vrf_id_ui;
10889
10890 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10891 ? -1
10892 : (int64_t)bgp->vrf_id;
10893
10894 /* Usage summary and header */
10895 if (use_json) {
10896 json_object_string_addf(json, "routerId",
10897 "%pI4",
10898 &bgp->router_id);
10899 json_object_int_add(json, "as", bgp->as);
10900 json_object_int_add(json, "vrfId", vrf_id_ui);
10901 json_object_string_add(
10902 json, "vrfName",
10903 (bgp->inst_type
10904 == BGP_INSTANCE_TYPE_DEFAULT)
10905 ? VRF_DEFAULT_NAME
10906 : bgp->name);
10907 } else {
10908 vty_out(vty,
10909 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10910 &bgp->router_id, bgp->as,
10911 bgp->vrf_id == VRF_UNKNOWN
10912 ? -1
10913 : (int)bgp->vrf_id);
10914 vty_out(vty, "\n");
10915 }
10916
10917 if (bgp_update_delay_configured(bgp)) {
10918 if (use_json) {
10919 json_object_int_add(
10920 json, "updateDelayLimit",
10921 bgp->v_update_delay);
10922
10923 if (bgp->v_update_delay
10924 != bgp->v_establish_wait)
10925 json_object_int_add(
10926 json,
10927 "updateDelayEstablishWait",
10928 bgp->v_establish_wait);
10929
10930 if (bgp_update_delay_active(bgp)) {
10931 json_object_string_add(
10932 json,
10933 "updateDelayFirstNeighbor",
10934 bgp->update_delay_begin_time);
10935 json_object_boolean_true_add(
10936 json,
10937 "updateDelayInProgress");
10938 } else {
10939 if (bgp->update_delay_over) {
10940 json_object_string_add(
10941 json,
10942 "updateDelayFirstNeighbor",
10943 bgp->update_delay_begin_time);
10944 json_object_string_add(
10945 json,
10946 "updateDelayBestpathResumed",
10947 bgp->update_delay_end_time);
10948 json_object_string_add(
10949 json,
10950 "updateDelayZebraUpdateResume",
10951 bgp->update_delay_zebra_resume_time);
10952 json_object_string_add(
10953 json,
10954 "updateDelayPeerUpdateResume",
10955 bgp->update_delay_peers_resume_time);
10956 }
10957 }
10958 } else {
10959 vty_out(vty,
10960 "Read-only mode update-delay limit: %d seconds\n",
10961 bgp->v_update_delay);
10962 if (bgp->v_update_delay
10963 != bgp->v_establish_wait)
10964 vty_out(vty,
10965 " Establish wait: %d seconds\n",
10966 bgp->v_establish_wait);
10967
10968 if (bgp_update_delay_active(bgp)) {
10969 vty_out(vty,
10970 " First neighbor established: %s\n",
10971 bgp->update_delay_begin_time);
10972 vty_out(vty,
10973 " Delay in progress\n");
10974 } else {
10975 if (bgp->update_delay_over) {
10976 vty_out(vty,
10977 " First neighbor established: %s\n",
10978 bgp->update_delay_begin_time);
10979 vty_out(vty,
10980 " Best-paths resumed: %s\n",
10981 bgp->update_delay_end_time);
10982 vty_out(vty,
10983 " zebra update resumed: %s\n",
10984 bgp->update_delay_zebra_resume_time);
10985 vty_out(vty,
10986 " peers update resumed: %s\n",
10987 bgp->update_delay_peers_resume_time);
10988 }
10989 }
10990 }
10991 }
10992
10993 if (use_json) {
10994 if (bgp_maxmed_onstartup_configured(bgp)
10995 && bgp->maxmed_active)
10996 json_object_boolean_true_add(
10997 json, "maxMedOnStartup");
10998 if (bgp->v_maxmed_admin)
10999 json_object_boolean_true_add(
11000 json, "maxMedAdministrative");
11001
11002 json_object_int_add(
11003 json, "tableVersion",
11004 bgp_table_version(bgp->rib[afi][safi]));
11005
11006 ents = bgp_table_count(bgp->rib[afi][safi]);
11007 json_object_int_add(json, "ribCount", ents);
11008 json_object_int_add(
11009 json, "ribMemory",
11010 ents * sizeof(struct bgp_dest));
11011
11012 ents = bgp->af_peer_count[afi][safi];
11013 json_object_int_add(json, "peerCount", ents);
11014 json_object_int_add(json, "peerMemory",
11015 ents * sizeof(struct peer));
11016
11017 if ((ents = listcount(bgp->group))) {
11018 json_object_int_add(
11019 json, "peerGroupCount", ents);
11020 json_object_int_add(
11021 json, "peerGroupMemory",
11022 ents * sizeof(struct
11023 peer_group));
11024 }
11025
11026 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11027 BGP_CONFIG_DAMPENING))
11028 json_object_boolean_true_add(
11029 json, "dampeningEnabled");
11030 } else {
11031 if (!show_terse) {
11032 if (bgp_maxmed_onstartup_configured(bgp)
11033 && bgp->maxmed_active)
11034 vty_out(vty,
11035 "Max-med on-startup active\n");
11036 if (bgp->v_maxmed_admin)
11037 vty_out(vty,
11038 "Max-med administrative active\n");
11039
11040 vty_out(vty,
11041 "BGP table version %" PRIu64
11042 "\n",
11043 bgp_table_version(
11044 bgp->rib[afi][safi]));
11045
11046 ents = bgp_table_count(
11047 bgp->rib[afi][safi]);
11048 vty_out(vty,
11049 "RIB entries %ld, using %s of memory\n",
11050 ents,
11051 mtype_memstr(
11052 memstrbuf,
11053 sizeof(memstrbuf),
11054 ents
11055 * sizeof(
11056 struct
11057 bgp_dest)));
11058
11059 /* Peer related usage */
11060 ents = bgp->af_peer_count[afi][safi];
11061 vty_out(vty,
11062 "Peers %ld, using %s of memory\n",
11063 ents,
11064 mtype_memstr(
11065 memstrbuf,
11066 sizeof(memstrbuf),
11067 ents
11068 * sizeof(
11069 struct
11070 peer)));
11071
11072 if ((ents = listcount(bgp->group)))
11073 vty_out(vty,
11074 "Peer groups %ld, using %s of memory\n",
11075 ents,
11076 mtype_memstr(
11077 memstrbuf,
11078 sizeof(memstrbuf),
11079 ents
11080 * sizeof(
11081 struct
11082 peer_group)));
11083
11084 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11085 BGP_CONFIG_DAMPENING))
11086 vty_out(vty,
11087 "Dampening enabled.\n");
11088 }
11089 if (show_failed) {
11090 vty_out(vty, "\n");
11091
11092 /* Subtract 8 here because 'Neighbor' is
11093 * 8 characters */
11094 vty_out(vty, "Neighbor");
11095 vty_out(vty, "%*s",
11096 max_neighbor_width - 8, " ");
11097 vty_out(vty,
11098 BGP_SHOW_SUMMARY_HEADER_FAILED);
11099 }
11100 }
11101 }
11102
11103 paf = peer_af_find(peer, afi, safi);
11104 filter = &peer->filter[afi][safi];
11105
11106 count++;
11107 /* Works for both failed & successful cases */
11108 if (peer_dynamic_neighbor(peer))
11109 dn_count++;
11110
11111 if (use_json) {
11112 json_peer = NULL;
11113 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11114 as_type, as)) {
11115 filtered_count++;
11116 continue;
11117 }
11118 if (show_failed &&
11119 bgp_has_peer_failed(peer, afi, safi)) {
11120 json_peer = json_object_new_object();
11121 bgp_show_failed_summary(vty, bgp, peer,
11122 json_peer, 0, use_json);
11123 } else if (!show_failed) {
11124 if (show_established
11125 && bgp_has_peer_failed(peer, afi, safi)) {
11126 filtered_count++;
11127 continue;
11128 }
11129
11130 json_peer = json_object_new_object();
11131 if (peer_dynamic_neighbor(peer)) {
11132 json_object_boolean_true_add(json_peer,
11133 "dynamicPeer");
11134 }
11135
11136 if (peer->hostname)
11137 json_object_string_add(json_peer, "hostname",
11138 peer->hostname);
11139
11140 if (peer->domainname)
11141 json_object_string_add(json_peer, "domainname",
11142 peer->domainname);
11143
11144 json_object_int_add(json_peer, "remoteAs", peer->as);
11145 json_object_int_add(
11146 json_peer, "localAs",
11147 peer->change_local_as
11148 ? peer->change_local_as
11149 : peer->local_as);
11150 json_object_int_add(json_peer, "version", 4);
11151 json_object_int_add(json_peer, "msgRcvd",
11152 PEER_TOTAL_RX(peer));
11153 json_object_int_add(json_peer, "msgSent",
11154 PEER_TOTAL_TX(peer));
11155
11156 atomic_size_t outq_count, inq_count;
11157 outq_count = atomic_load_explicit(
11158 &peer->obuf->count,
11159 memory_order_relaxed);
11160 inq_count = atomic_load_explicit(
11161 &peer->ibuf->count,
11162 memory_order_relaxed);
11163
11164 json_object_int_add(json_peer, "tableVersion",
11165 peer->version[afi][safi]);
11166 json_object_int_add(json_peer, "outq",
11167 outq_count);
11168 json_object_int_add(json_peer, "inq",
11169 inq_count);
11170 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11171 use_json, json_peer);
11172
11173 json_object_int_add(json_peer, "pfxRcd",
11174 peer->pcount[afi][pfx_rcd_safi]);
11175
11176 if (paf && PAF_SUBGRP(paf))
11177 json_object_int_add(
11178 json_peer, "pfxSnt",
11179 (PAF_SUBGRP(paf))->scount);
11180 else
11181 json_object_int_add(json_peer, "pfxSnt",
11182 0);
11183
11184 /* BGP FSM state */
11185 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11186 || CHECK_FLAG(peer->bgp->flags,
11187 BGP_FLAG_SHUTDOWN))
11188 json_object_string_add(json_peer,
11189 "state",
11190 "Idle (Admin)");
11191 else if (peer->afc_recv[afi][safi])
11192 json_object_string_add(
11193 json_peer, "state",
11194 lookup_msg(bgp_status_msg,
11195 peer->status, NULL));
11196 else if (CHECK_FLAG(
11197 peer->sflags,
11198 PEER_STATUS_PREFIX_OVERFLOW))
11199 json_object_string_add(json_peer,
11200 "state",
11201 "Idle (PfxCt)");
11202 else
11203 json_object_string_add(
11204 json_peer, "state",
11205 lookup_msg(bgp_status_msg,
11206 peer->status, NULL));
11207
11208 /* BGP peer state */
11209 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11210 || CHECK_FLAG(peer->bgp->flags,
11211 BGP_FLAG_SHUTDOWN))
11212 json_object_string_add(json_peer,
11213 "peerState",
11214 "Admin");
11215 else if (CHECK_FLAG(
11216 peer->sflags,
11217 PEER_STATUS_PREFIX_OVERFLOW))
11218 json_object_string_add(json_peer,
11219 "peerState",
11220 "PfxCt");
11221 else if (CHECK_FLAG(peer->flags,
11222 PEER_FLAG_PASSIVE))
11223 json_object_string_add(json_peer,
11224 "peerState",
11225 "Passive");
11226 else if (CHECK_FLAG(peer->sflags,
11227 PEER_STATUS_NSF_WAIT))
11228 json_object_string_add(json_peer,
11229 "peerState",
11230 "NSF passive");
11231 else if (CHECK_FLAG(
11232 peer->bgp->flags,
11233 BGP_FLAG_EBGP_REQUIRES_POLICY)
11234 && (!bgp_inbound_policy_exists(peer,
11235 filter)
11236 || !bgp_outbound_policy_exists(
11237 peer, filter)))
11238 json_object_string_add(json_peer,
11239 "peerState",
11240 "Policy");
11241 else
11242 json_object_string_add(
11243 json_peer, "peerState", "OK");
11244
11245 json_object_int_add(json_peer, "connectionsEstablished",
11246 peer->established);
11247 json_object_int_add(json_peer, "connectionsDropped",
11248 peer->dropped);
11249 if (peer->desc)
11250 json_object_string_add(
11251 json_peer, "desc", peer->desc);
11252 }
11253 /* Avoid creating empty peer dicts in JSON */
11254 if (json_peer == NULL)
11255 continue;
11256
11257 if (peer->conf_if)
11258 json_object_string_add(json_peer, "idType",
11259 "interface");
11260 else if (peer->su.sa.sa_family == AF_INET)
11261 json_object_string_add(json_peer, "idType",
11262 "ipv4");
11263 else if (peer->su.sa.sa_family == AF_INET6)
11264 json_object_string_add(json_peer, "idType",
11265 "ipv6");
11266 json_object_object_add(json_peers, peer->host,
11267 json_peer);
11268 } else {
11269 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11270 as_type, as)) {
11271 filtered_count++;
11272 continue;
11273 }
11274 if (show_failed &&
11275 bgp_has_peer_failed(peer, afi, safi)) {
11276 bgp_show_failed_summary(vty, bgp, peer, NULL,
11277 max_neighbor_width,
11278 use_json);
11279 } else if (!show_failed) {
11280 if (show_established
11281 && bgp_has_peer_failed(peer, afi, safi)) {
11282 filtered_count++;
11283 continue;
11284 }
11285
11286 if ((count - filtered_count) == 1) {
11287 /* display headline before the first
11288 * neighbor line */
11289 vty_out(vty, "\n");
11290
11291 /* Subtract 8 here because 'Neighbor' is
11292 * 8 characters */
11293 vty_out(vty, "Neighbor");
11294 vty_out(vty, "%*s",
11295 max_neighbor_width - 8, " ");
11296 vty_out(vty,
11297 show_wide
11298 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11299 : BGP_SHOW_SUMMARY_HEADER_ALL);
11300 }
11301
11302 memset(dn_flag, '\0', sizeof(dn_flag));
11303 if (peer_dynamic_neighbor(peer)) {
11304 dn_flag[0] = '*';
11305 }
11306
11307 if (peer->hostname
11308 && CHECK_FLAG(bgp->flags,
11309 BGP_FLAG_SHOW_HOSTNAME))
11310 len = vty_out(vty, "%s%s(%s)", dn_flag,
11311 peer->hostname,
11312 peer->host);
11313 else
11314 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11315
11316 /* pad the neighbor column with spaces */
11317 if (len < max_neighbor_width)
11318 vty_out(vty, "%*s", max_neighbor_width - len,
11319 " ");
11320
11321 atomic_size_t outq_count, inq_count;
11322 outq_count = atomic_load_explicit(
11323 &peer->obuf->count,
11324 memory_order_relaxed);
11325 inq_count = atomic_load_explicit(
11326 &peer->ibuf->count,
11327 memory_order_relaxed);
11328
11329 if (show_wide)
11330 vty_out(vty,
11331 "4 %10u %10u %9u %9u %8" PRIu64
11332 " %4zu %4zu %8s",
11333 peer->as,
11334 peer->change_local_as
11335 ? peer->change_local_as
11336 : peer->local_as,
11337 PEER_TOTAL_RX(peer),
11338 PEER_TOTAL_TX(peer),
11339 peer->version[afi][safi],
11340 inq_count, outq_count,
11341 peer_uptime(peer->uptime,
11342 timebuf,
11343 BGP_UPTIME_LEN, 0,
11344 NULL));
11345 else
11346 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11347 " %4zu %4zu %8s",
11348 peer->as, PEER_TOTAL_RX(peer),
11349 PEER_TOTAL_TX(peer),
11350 peer->version[afi][safi],
11351 inq_count, outq_count,
11352 peer_uptime(peer->uptime,
11353 timebuf,
11354 BGP_UPTIME_LEN, 0,
11355 NULL));
11356
11357 if (peer_established(peer)) {
11358 if (peer->afc_recv[afi][safi]) {
11359 if (CHECK_FLAG(
11360 bgp->flags,
11361 BGP_FLAG_EBGP_REQUIRES_POLICY)
11362 && !bgp_inbound_policy_exists(
11363 peer, filter))
11364 vty_out(vty, " %12s",
11365 "(Policy)");
11366 else
11367 vty_out(vty,
11368 " %12u",
11369 peer->pcount
11370 [afi]
11371 [pfx_rcd_safi]);
11372 } else {
11373 vty_out(vty, " NoNeg");
11374 }
11375
11376 if (paf && PAF_SUBGRP(paf)) {
11377 if (CHECK_FLAG(
11378 bgp->flags,
11379 BGP_FLAG_EBGP_REQUIRES_POLICY)
11380 && !bgp_outbound_policy_exists(
11381 peer, filter))
11382 vty_out(vty, " %8s",
11383 "(Policy)");
11384 else
11385 vty_out(vty,
11386 " %8u",
11387 (PAF_SUBGRP(
11388 paf))
11389 ->scount);
11390 } else {
11391 vty_out(vty, " NoNeg");
11392 }
11393 } else {
11394 if (CHECK_FLAG(peer->flags,
11395 PEER_FLAG_SHUTDOWN)
11396 || CHECK_FLAG(peer->bgp->flags,
11397 BGP_FLAG_SHUTDOWN))
11398 vty_out(vty, " Idle (Admin)");
11399 else if (CHECK_FLAG(
11400 peer->sflags,
11401 PEER_STATUS_PREFIX_OVERFLOW))
11402 vty_out(vty, " Idle (PfxCt)");
11403 else
11404 vty_out(vty, " %12s",
11405 lookup_msg(bgp_status_msg,
11406 peer->status, NULL));
11407
11408 vty_out(vty, " %8u", 0);
11409 }
11410 /* Make sure `Desc` column is the lastest in
11411 * the output.
11412 */
11413 if (peer->desc)
11414 vty_out(vty, " %s",
11415 bgp_peer_description_stripped(
11416 peer->desc,
11417 show_wide ? 64 : 20));
11418 else
11419 vty_out(vty, " N/A");
11420 vty_out(vty, "\n");
11421 }
11422
11423 }
11424 }
11425
11426 if (use_json) {
11427 json_object_object_add(json, "peers", json_peers);
11428 json_object_int_add(json, "failedPeers", failed_count);
11429 json_object_int_add(json, "displayedPeers",
11430 count - filtered_count);
11431 json_object_int_add(json, "totalPeers", count);
11432 json_object_int_add(json, "dynamicPeers", dn_count);
11433
11434 if (!show_failed)
11435 bgp_show_bestpath_json(bgp, json);
11436
11437 vty_json(vty, json);
11438 } else {
11439 if (count) {
11440 if (filtered_count == count)
11441 vty_out(vty, "\n%% No matching neighbor\n");
11442 else {
11443 if (show_failed)
11444 vty_out(vty, "\nDisplayed neighbors %d",
11445 failed_count);
11446 else if (as_type != AS_UNSPECIFIED || as
11447 || fpeer || show_established)
11448 vty_out(vty, "\nDisplayed neighbors %d",
11449 count - filtered_count);
11450
11451 vty_out(vty, "\nTotal number of neighbors %d\n",
11452 count);
11453 }
11454 } else {
11455 vty_out(vty, "No %s neighbor is configured\n",
11456 get_afi_safi_str(afi, safi, false));
11457 }
11458
11459 if (dn_count) {
11460 vty_out(vty, "* - dynamic neighbor\n");
11461 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11462 dn_count, bgp->dynamic_neighbors_limit);
11463 }
11464 }
11465
11466 return CMD_SUCCESS;
11467 }
11468
11469 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11470 int safi, struct peer *fpeer, int as_type,
11471 as_t as, uint16_t show_flags)
11472 {
11473 int is_first = 1;
11474 int afi_wildcard = (afi == AFI_MAX);
11475 int safi_wildcard = (safi == SAFI_MAX);
11476 int is_wildcard = (afi_wildcard || safi_wildcard);
11477 bool nbr_output = false;
11478 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11479
11480 if (use_json && is_wildcard)
11481 vty_out(vty, "{\n");
11482 if (afi_wildcard)
11483 afi = 1; /* AFI_IP */
11484 while (afi < AFI_MAX) {
11485 if (safi_wildcard)
11486 safi = 1; /* SAFI_UNICAST */
11487 while (safi < SAFI_MAX) {
11488 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11489 nbr_output = true;
11490
11491 if (is_wildcard) {
11492 /*
11493 * So limit output to those afi/safi
11494 * pairs that
11495 * actualy have something interesting in
11496 * them
11497 */
11498 if (use_json) {
11499 if (!is_first)
11500 vty_out(vty, ",\n");
11501 else
11502 is_first = 0;
11503
11504 vty_out(vty, "\"%s\":",
11505 get_afi_safi_str(afi,
11506 safi,
11507 true));
11508 } else {
11509 vty_out(vty,
11510 "\n%s Summary (%s):\n",
11511 get_afi_safi_str(afi,
11512 safi,
11513 false),
11514 bgp->name_pretty);
11515 }
11516 }
11517 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11518 as_type, as, show_flags);
11519 }
11520 safi++;
11521 if (!safi_wildcard)
11522 safi = SAFI_MAX;
11523 }
11524 afi++;
11525 if (!afi_wildcard)
11526 afi = AFI_MAX;
11527 }
11528
11529 if (use_json && is_wildcard)
11530 vty_out(vty, "}\n");
11531 else if (!nbr_output) {
11532 if (use_json)
11533 vty_out(vty, "{}\n");
11534 else
11535 vty_out(vty, "%% No BGP neighbors found in %s\n",
11536 bgp->name_pretty);
11537 }
11538 }
11539
11540 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11541 safi_t safi,
11542 const char *neighbor,
11543 int as_type, as_t as,
11544 uint16_t show_flags)
11545 {
11546 struct listnode *node, *nnode;
11547 struct bgp *bgp;
11548 struct peer *fpeer = NULL;
11549 int is_first = 1;
11550 bool nbr_output = false;
11551 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11552
11553 if (use_json)
11554 vty_out(vty, "{\n");
11555
11556 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11557 nbr_output = true;
11558 if (use_json) {
11559 if (!is_first)
11560 vty_out(vty, ",\n");
11561 else
11562 is_first = 0;
11563
11564 vty_out(vty, "\"%s\":",
11565 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11566 ? VRF_DEFAULT_NAME
11567 : bgp->name);
11568 }
11569 if (neighbor) {
11570 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11571 use_json);
11572 if (!fpeer)
11573 continue;
11574 }
11575 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11576 as, show_flags);
11577 }
11578
11579 if (use_json)
11580 vty_out(vty, "}\n");
11581 else if (!nbr_output)
11582 vty_out(vty, "%% BGP instance not found\n");
11583 }
11584
11585 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11586 safi_t safi, const char *neighbor, int as_type,
11587 as_t as, uint16_t show_flags)
11588 {
11589 struct bgp *bgp;
11590 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11591 struct peer *fpeer = NULL;
11592
11593 if (name) {
11594 if (strmatch(name, "all")) {
11595 bgp_show_all_instances_summary_vty(vty, afi, safi,
11596 neighbor, as_type,
11597 as, show_flags);
11598 return CMD_SUCCESS;
11599 } else {
11600 bgp = bgp_lookup_by_name(name);
11601
11602 if (!bgp) {
11603 if (use_json)
11604 vty_out(vty, "{}\n");
11605 else
11606 vty_out(vty,
11607 "%% BGP instance not found\n");
11608 return CMD_WARNING;
11609 }
11610
11611 if (neighbor) {
11612 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11613 use_json);
11614 if (!fpeer)
11615 return CMD_WARNING;
11616 }
11617 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11618 as_type, as, show_flags);
11619 return CMD_SUCCESS;
11620 }
11621 }
11622
11623 bgp = bgp_get_default();
11624
11625 if (bgp) {
11626 if (neighbor) {
11627 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11628 use_json);
11629 if (!fpeer)
11630 return CMD_WARNING;
11631 }
11632 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11633 as, show_flags);
11634 } else {
11635 if (use_json)
11636 vty_out(vty, "{}\n");
11637 else
11638 vty_out(vty, "%% BGP instance not found\n");
11639 return CMD_WARNING;
11640 }
11641
11642 return CMD_SUCCESS;
11643 }
11644
11645 /* `show [ip] bgp summary' commands. */
11646 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11647 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11648 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11649 "]] [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]",
11650 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11651 BGP_SAFI_WITH_LABEL_HELP_STR
11652 "Display the entries for all address families\n"
11653 "Summary of BGP neighbor status\n"
11654 "Show only sessions in Established state\n"
11655 "Show only sessions not in Established state\n"
11656 "Show only the specified neighbor session\n"
11657 "Neighbor to display information about\n"
11658 "Neighbor to display information about\n"
11659 "Neighbor on BGP configured interface\n"
11660 "Show only the specified remote AS sessions\n"
11661 "AS number\n"
11662 "Internal (iBGP) AS sessions\n"
11663 "External (eBGP) AS sessions\n"
11664 "Shorten the information on BGP instances\n"
11665 "Increase table width for longer output\n" JSON_STR)
11666 {
11667 char *vrf = NULL;
11668 afi_t afi = AFI_MAX;
11669 safi_t safi = SAFI_MAX;
11670 as_t as = 0; /* 0 means AS filter not set */
11671 int as_type = AS_UNSPECIFIED;
11672 uint16_t show_flags = 0;
11673
11674 int idx = 0;
11675
11676 /* show [ip] bgp */
11677 if (!all && argv_find(argv, argc, "ip", &idx))
11678 afi = AFI_IP;
11679 /* [<vrf> VIEWVRFNAME] */
11680 if (argv_find(argv, argc, "vrf", &idx)) {
11681 vrf = argv[idx + 1]->arg;
11682 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11683 vrf = NULL;
11684 } else if (argv_find(argv, argc, "view", &idx))
11685 /* [<view> VIEWVRFNAME] */
11686 vrf = argv[idx + 1]->arg;
11687 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11688 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11689 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11690 }
11691
11692 if (argv_find(argv, argc, "failed", &idx))
11693 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11694
11695 if (argv_find(argv, argc, "established", &idx))
11696 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11697
11698 if (argv_find(argv, argc, "remote-as", &idx)) {
11699 if (argv[idx + 1]->arg[0] == 'i')
11700 as_type = AS_INTERNAL;
11701 else if (argv[idx + 1]->arg[0] == 'e')
11702 as_type = AS_EXTERNAL;
11703 else
11704 as = (as_t)atoi(argv[idx + 1]->arg);
11705 }
11706
11707 if (argv_find(argv, argc, "terse", &idx))
11708 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11709
11710 if (argv_find(argv, argc, "wide", &idx))
11711 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11712
11713 if (argv_find(argv, argc, "json", &idx))
11714 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11715
11716 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11717 show_flags);
11718 }
11719
11720 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11721 {
11722 if (for_json)
11723 return get_afi_safi_json_str(afi, safi);
11724 else
11725 return get_afi_safi_vty_str(afi, safi);
11726 }
11727
11728
11729 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11730 afi_t afi, safi_t safi,
11731 uint16_t adv_smcap, uint16_t adv_rmcap,
11732 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11733 bool use_json, json_object *json_pref)
11734 {
11735 /* Send-Mode */
11736 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11737 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11738 if (use_json) {
11739 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11740 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11741 json_object_string_add(json_pref, "sendMode",
11742 "advertisedAndReceived");
11743 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11744 json_object_string_add(json_pref, "sendMode",
11745 "advertised");
11746 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11747 json_object_string_add(json_pref, "sendMode",
11748 "received");
11749 } else {
11750 vty_out(vty, " Send-mode: ");
11751 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11752 vty_out(vty, "advertised");
11753 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11754 vty_out(vty, "%sreceived",
11755 CHECK_FLAG(p->af_cap[afi][safi],
11756 adv_smcap)
11757 ? ", "
11758 : "");
11759 vty_out(vty, "\n");
11760 }
11761 }
11762
11763 /* Receive-Mode */
11764 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11765 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11766 if (use_json) {
11767 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11768 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11769 json_object_string_add(json_pref, "recvMode",
11770 "advertisedAndReceived");
11771 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11772 json_object_string_add(json_pref, "recvMode",
11773 "advertised");
11774 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11775 json_object_string_add(json_pref, "recvMode",
11776 "received");
11777 } else {
11778 vty_out(vty, " Receive-mode: ");
11779 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11780 vty_out(vty, "advertised");
11781 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11782 vty_out(vty, "%sreceived",
11783 CHECK_FLAG(p->af_cap[afi][safi],
11784 adv_rmcap)
11785 ? ", "
11786 : "");
11787 vty_out(vty, "\n");
11788 }
11789 }
11790 }
11791
11792 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11793 struct peer *p,
11794 bool use_json,
11795 json_object *json)
11796 {
11797 bool rbit = false;
11798 bool nbit = false;
11799
11800 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11801 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11802 && (peer_established(p))) {
11803 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11804 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11805 }
11806
11807 if (use_json) {
11808 json_object_boolean_add(json, "rBit", rbit);
11809 json_object_boolean_add(json, "nBit", nbit);
11810 } else {
11811 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11812 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11813 }
11814 }
11815
11816 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11817 struct peer *peer,
11818 bool use_json,
11819 json_object *json)
11820 {
11821 const char *mode = "NotApplicable";
11822
11823 if (!use_json)
11824 vty_out(vty, "\n Remote GR Mode: ");
11825
11826 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11827 && (peer_established(peer))) {
11828
11829 if ((peer->nsf_af_count == 0)
11830 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11831
11832 mode = "Disable";
11833
11834 } else if (peer->nsf_af_count == 0
11835 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11836
11837 mode = "Helper";
11838
11839 } else if (peer->nsf_af_count != 0
11840 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11841
11842 mode = "Restart";
11843 }
11844 }
11845
11846 if (use_json) {
11847 json_object_string_add(json, "remoteGrMode", mode);
11848 } else
11849 vty_out(vty, mode, "\n");
11850 }
11851
11852 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11853 struct peer *p,
11854 bool use_json,
11855 json_object *json)
11856 {
11857 const char *mode = "Invalid";
11858
11859 if (!use_json)
11860 vty_out(vty, " Local GR Mode: ");
11861
11862 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11863 mode = "Helper";
11864 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11865 mode = "Restart";
11866 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11867 mode = "Disable";
11868 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11869 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11870 mode = "Helper*";
11871 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11872 mode = "Restart*";
11873 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11874 mode = "Disable*";
11875 else
11876 mode = "Invalid*";
11877 }
11878
11879 if (use_json) {
11880 json_object_string_add(json, "localGrMode", mode);
11881 } else {
11882 vty_out(vty, mode, "\n");
11883 }
11884 }
11885
11886 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11887 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11888 {
11889 afi_t afi;
11890 safi_t safi;
11891 json_object *json_afi_safi = NULL;
11892 json_object *json_timer = NULL;
11893 json_object *json_endofrib_status = NULL;
11894 bool eor_flag = false;
11895
11896 FOREACH_AFI_SAFI_NSF (afi, safi) {
11897 if (!peer->afc[afi][safi])
11898 continue;
11899
11900 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11901 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11902 continue;
11903
11904 if (use_json) {
11905 json_afi_safi = json_object_new_object();
11906 json_endofrib_status = json_object_new_object();
11907 json_timer = json_object_new_object();
11908 }
11909
11910 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11911 eor_flag = true;
11912 else
11913 eor_flag = false;
11914
11915 if (!use_json) {
11916 vty_out(vty, " %s:\n",
11917 get_afi_safi_str(afi, safi, false));
11918
11919 vty_out(vty, " F bit: ");
11920 }
11921
11922 if (peer->nsf[afi][safi] &&
11923 CHECK_FLAG(peer->af_cap[afi][safi],
11924 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11925
11926 if (use_json) {
11927 json_object_boolean_true_add(json_afi_safi,
11928 "fBit");
11929 } else
11930 vty_out(vty, "True\n");
11931 } else {
11932 if (use_json)
11933 json_object_boolean_false_add(json_afi_safi,
11934 "fBit");
11935 else
11936 vty_out(vty, "False\n");
11937 }
11938
11939 if (!use_json)
11940 vty_out(vty, " End-of-RIB sent: ");
11941
11942 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11943 PEER_STATUS_EOR_SEND)) {
11944 if (use_json) {
11945 json_object_boolean_true_add(
11946 json_endofrib_status, "endOfRibSend");
11947
11948 PRINT_EOR_JSON(eor_flag);
11949 } else {
11950 vty_out(vty, "Yes\n");
11951 vty_out(vty,
11952 " End-of-RIB sent after update: ");
11953
11954 PRINT_EOR(eor_flag);
11955 }
11956 } else {
11957 if (use_json) {
11958 json_object_boolean_false_add(
11959 json_endofrib_status, "endOfRibSend");
11960 json_object_boolean_false_add(
11961 json_endofrib_status,
11962 "endOfRibSentAfterUpdate");
11963 } else {
11964 vty_out(vty, "No\n");
11965 vty_out(vty,
11966 " End-of-RIB sent after update: ");
11967 vty_out(vty, "No\n");
11968 }
11969 }
11970
11971 if (!use_json)
11972 vty_out(vty, " End-of-RIB received: ");
11973
11974 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11975 PEER_STATUS_EOR_RECEIVED)) {
11976 if (use_json)
11977 json_object_boolean_true_add(
11978 json_endofrib_status, "endOfRibRecv");
11979 else
11980 vty_out(vty, "Yes\n");
11981 } else {
11982 if (use_json)
11983 json_object_boolean_false_add(
11984 json_endofrib_status, "endOfRibRecv");
11985 else
11986 vty_out(vty, "No\n");
11987 }
11988
11989 if (use_json) {
11990 json_object_int_add(json_timer, "stalePathTimer",
11991 peer->bgp->stalepath_time);
11992
11993 if (peer->t_gr_stale != NULL) {
11994 json_object_int_add(json_timer,
11995 "stalePathTimerRemaining",
11996 thread_timer_remain_second(
11997 peer->t_gr_stale));
11998 }
11999
12000 /* Display Configured Selection
12001 * Deferral only when when
12002 * Gr mode is enabled.
12003 */
12004 if (CHECK_FLAG(peer->flags,
12005 PEER_FLAG_GRACEFUL_RESTART)) {
12006 json_object_int_add(json_timer,
12007 "selectionDeferralTimer",
12008 peer->bgp->stalepath_time);
12009 }
12010
12011 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12012 NULL) {
12013
12014 json_object_int_add(
12015 json_timer,
12016 "selectionDeferralTimerRemaining",
12017 thread_timer_remain_second(
12018 peer->bgp->gr_info[afi][safi]
12019 .t_select_deferral));
12020 }
12021 } else {
12022 vty_out(vty, " Timers:\n");
12023 vty_out(vty,
12024 " Configured Stale Path Time(sec): %u\n",
12025 peer->bgp->stalepath_time);
12026
12027 if (peer->t_gr_stale != NULL)
12028 vty_out(vty,
12029 " Stale Path Remaining(sec): %ld\n",
12030 thread_timer_remain_second(
12031 peer->t_gr_stale));
12032 /* Display Configured Selection
12033 * Deferral only when when
12034 * Gr mode is enabled.
12035 */
12036 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12037 vty_out(vty,
12038 " Configured Selection Deferral Time(sec): %u\n",
12039 peer->bgp->select_defer_time);
12040
12041 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12042 NULL)
12043 vty_out(vty,
12044 " Selection Deferral Time Remaining(sec): %ld\n",
12045 thread_timer_remain_second(
12046 peer->bgp->gr_info[afi][safi]
12047 .t_select_deferral));
12048 }
12049 if (use_json) {
12050 json_object_object_add(json_afi_safi, "endOfRibStatus",
12051 json_endofrib_status);
12052 json_object_object_add(json_afi_safi, "timers",
12053 json_timer);
12054 json_object_object_add(
12055 json, get_afi_safi_str(afi, safi, true),
12056 json_afi_safi);
12057 }
12058 }
12059 }
12060
12061 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12062 struct peer *p,
12063 bool use_json,
12064 json_object *json)
12065 {
12066 if (use_json) {
12067 json_object *json_timer = NULL;
12068
12069 json_timer = json_object_new_object();
12070
12071 json_object_int_add(json_timer, "configuredRestartTimer",
12072 p->bgp->restart_time);
12073
12074 json_object_int_add(json_timer, "receivedRestartTimer",
12075 p->v_gr_restart);
12076
12077 if (p->t_gr_restart != NULL)
12078 json_object_int_add(
12079 json_timer, "restartTimerRemaining",
12080 thread_timer_remain_second(p->t_gr_restart));
12081
12082 json_object_object_add(json, "timers", json_timer);
12083 } else {
12084
12085 vty_out(vty, " Timers:\n");
12086 vty_out(vty, " Configured Restart Time(sec): %u\n",
12087 p->bgp->restart_time);
12088
12089 vty_out(vty, " Received Restart Time(sec): %u\n",
12090 p->v_gr_restart);
12091 if (p->t_gr_restart != NULL)
12092 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12093 thread_timer_remain_second(p->t_gr_restart));
12094 if (p->t_gr_restart != NULL) {
12095 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12096 thread_timer_remain_second(p->t_gr_restart));
12097 }
12098 }
12099 }
12100
12101 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12102 bool use_json, json_object *json)
12103 {
12104 char dn_flag[2] = {0};
12105 /* '*' + v6 address of neighbor */
12106 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12107
12108 if (!p->conf_if && peer_dynamic_neighbor(p))
12109 dn_flag[0] = '*';
12110
12111 if (p->conf_if) {
12112 if (use_json)
12113 json_object_string_addf(json, "neighborAddr", "%pSU",
12114 &p->su);
12115 else
12116 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12117 &p->su);
12118 } else {
12119 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12120 p->host);
12121
12122 if (use_json)
12123 json_object_string_add(json, "neighborAddr",
12124 neighborAddr);
12125 else
12126 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12127 }
12128
12129 /* more gr info in new format */
12130 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12131 }
12132
12133 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12134 safi_t safi, bool use_json,
12135 json_object *json_neigh)
12136 {
12137 struct bgp_filter *filter;
12138 struct peer_af *paf;
12139 char orf_pfx_name[BUFSIZ];
12140 int orf_pfx_count;
12141 json_object *json_af = NULL;
12142 json_object *json_prefA = NULL;
12143 json_object *json_prefB = NULL;
12144 json_object *json_addr = NULL;
12145 json_object *json_advmap = NULL;
12146
12147 if (use_json) {
12148 json_addr = json_object_new_object();
12149 json_af = json_object_new_object();
12150 filter = &p->filter[afi][safi];
12151
12152 if (peer_group_active(p))
12153 json_object_string_add(json_addr, "peerGroupMember",
12154 p->group->name);
12155
12156 paf = peer_af_find(p, afi, safi);
12157 if (paf && PAF_SUBGRP(paf)) {
12158 json_object_int_add(json_addr, "updateGroupId",
12159 PAF_UPDGRP(paf)->id);
12160 json_object_int_add(json_addr, "subGroupId",
12161 PAF_SUBGRP(paf)->id);
12162 json_object_int_add(json_addr, "packetQueueLength",
12163 bpacket_queue_virtual_length(paf));
12164 }
12165
12166 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12167 || CHECK_FLAG(p->af_cap[afi][safi],
12168 PEER_CAP_ORF_PREFIX_SM_RCV)
12169 || CHECK_FLAG(p->af_cap[afi][safi],
12170 PEER_CAP_ORF_PREFIX_RM_ADV)
12171 || CHECK_FLAG(p->af_cap[afi][safi],
12172 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12173 json_object_int_add(json_af, "orfType",
12174 ORF_TYPE_PREFIX);
12175 json_prefA = json_object_new_object();
12176 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12177 PEER_CAP_ORF_PREFIX_SM_ADV,
12178 PEER_CAP_ORF_PREFIX_RM_ADV,
12179 PEER_CAP_ORF_PREFIX_SM_RCV,
12180 PEER_CAP_ORF_PREFIX_RM_RCV,
12181 use_json, json_prefA);
12182 json_object_object_add(json_af, "orfPrefixList",
12183 json_prefA);
12184 }
12185
12186 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12187 || CHECK_FLAG(p->af_cap[afi][safi],
12188 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12189 || CHECK_FLAG(p->af_cap[afi][safi],
12190 PEER_CAP_ORF_PREFIX_RM_ADV)
12191 || CHECK_FLAG(p->af_cap[afi][safi],
12192 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12193 json_object_int_add(json_af, "orfOldType",
12194 ORF_TYPE_PREFIX_OLD);
12195 json_prefB = json_object_new_object();
12196 bgp_show_peer_afi_orf_cap(
12197 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12198 PEER_CAP_ORF_PREFIX_RM_ADV,
12199 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12200 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12201 json_prefB);
12202 json_object_object_add(json_af, "orfOldPrefixList",
12203 json_prefB);
12204 }
12205
12206 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12207 || CHECK_FLAG(p->af_cap[afi][safi],
12208 PEER_CAP_ORF_PREFIX_SM_RCV)
12209 || CHECK_FLAG(p->af_cap[afi][safi],
12210 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12211 || CHECK_FLAG(p->af_cap[afi][safi],
12212 PEER_CAP_ORF_PREFIX_RM_ADV)
12213 || CHECK_FLAG(p->af_cap[afi][safi],
12214 PEER_CAP_ORF_PREFIX_RM_RCV)
12215 || CHECK_FLAG(p->af_cap[afi][safi],
12216 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12217 json_object_object_add(json_addr, "afDependentCap",
12218 json_af);
12219 else
12220 json_object_free(json_af);
12221
12222 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12223 p->host, afi, safi);
12224 orf_pfx_count = prefix_bgp_show_prefix_list(
12225 NULL, afi, orf_pfx_name, use_json);
12226
12227 if (CHECK_FLAG(p->af_sflags[afi][safi],
12228 PEER_STATUS_ORF_PREFIX_SEND)
12229 || orf_pfx_count) {
12230 if (CHECK_FLAG(p->af_sflags[afi][safi],
12231 PEER_STATUS_ORF_PREFIX_SEND))
12232 json_object_boolean_true_add(json_neigh,
12233 "orfSent");
12234 if (orf_pfx_count)
12235 json_object_int_add(json_addr, "orfRecvCounter",
12236 orf_pfx_count);
12237 }
12238 if (CHECK_FLAG(p->af_sflags[afi][safi],
12239 PEER_STATUS_ORF_WAIT_REFRESH))
12240 json_object_string_add(
12241 json_addr, "orfFirstUpdate",
12242 "deferredUntilORFOrRouteRefreshRecvd");
12243
12244 if (CHECK_FLAG(p->af_flags[afi][safi],
12245 PEER_FLAG_REFLECTOR_CLIENT))
12246 json_object_boolean_true_add(json_addr,
12247 "routeReflectorClient");
12248 if (CHECK_FLAG(p->af_flags[afi][safi],
12249 PEER_FLAG_RSERVER_CLIENT))
12250 json_object_boolean_true_add(json_addr,
12251 "routeServerClient");
12252 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12253 json_object_boolean_true_add(json_addr,
12254 "inboundSoftConfigPermit");
12255
12256 if (CHECK_FLAG(p->af_flags[afi][safi],
12257 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12258 json_object_boolean_true_add(
12259 json_addr,
12260 "privateAsNumsAllReplacedInUpdatesToNbr");
12261 else if (CHECK_FLAG(p->af_flags[afi][safi],
12262 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12263 json_object_boolean_true_add(
12264 json_addr,
12265 "privateAsNumsReplacedInUpdatesToNbr");
12266 else if (CHECK_FLAG(p->af_flags[afi][safi],
12267 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12268 json_object_boolean_true_add(
12269 json_addr,
12270 "privateAsNumsAllRemovedInUpdatesToNbr");
12271 else if (CHECK_FLAG(p->af_flags[afi][safi],
12272 PEER_FLAG_REMOVE_PRIVATE_AS))
12273 json_object_boolean_true_add(
12274 json_addr,
12275 "privateAsNumsRemovedInUpdatesToNbr");
12276
12277 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12278 if (CHECK_FLAG(p->af_flags[afi][safi],
12279 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12280 json_object_boolean_true_add(json_addr,
12281 "allowAsInOrigin");
12282 else
12283 json_object_int_add(json_addr, "allowAsInCount",
12284 p->allowas_in[afi][safi]);
12285 }
12286
12287 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12288 json_object_boolean_true_add(
12289 json_addr,
12290 bgp_addpath_names(p->addpath_type[afi][safi])
12291 ->type_json_name);
12292
12293 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12294 json_object_string_add(json_addr,
12295 "overrideASNsInOutboundUpdates",
12296 "ifAspathEqualRemoteAs");
12297
12298 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12299 || CHECK_FLAG(p->af_flags[afi][safi],
12300 PEER_FLAG_FORCE_NEXTHOP_SELF))
12301 json_object_boolean_true_add(json_addr,
12302 "routerAlwaysNextHop");
12303 if (CHECK_FLAG(p->af_flags[afi][safi],
12304 PEER_FLAG_AS_PATH_UNCHANGED))
12305 json_object_boolean_true_add(
12306 json_addr, "unchangedAsPathPropogatedToNbr");
12307 if (CHECK_FLAG(p->af_flags[afi][safi],
12308 PEER_FLAG_NEXTHOP_UNCHANGED))
12309 json_object_boolean_true_add(
12310 json_addr, "unchangedNextHopPropogatedToNbr");
12311 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12312 json_object_boolean_true_add(
12313 json_addr, "unchangedMedPropogatedToNbr");
12314 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12315 || CHECK_FLAG(p->af_flags[afi][safi],
12316 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12317 if (CHECK_FLAG(p->af_flags[afi][safi],
12318 PEER_FLAG_SEND_COMMUNITY)
12319 && CHECK_FLAG(p->af_flags[afi][safi],
12320 PEER_FLAG_SEND_EXT_COMMUNITY))
12321 json_object_string_add(json_addr,
12322 "commAttriSentToNbr",
12323 "extendedAndStandard");
12324 else if (CHECK_FLAG(p->af_flags[afi][safi],
12325 PEER_FLAG_SEND_EXT_COMMUNITY))
12326 json_object_string_add(json_addr,
12327 "commAttriSentToNbr",
12328 "extended");
12329 else
12330 json_object_string_add(json_addr,
12331 "commAttriSentToNbr",
12332 "standard");
12333 }
12334 if (CHECK_FLAG(p->af_flags[afi][safi],
12335 PEER_FLAG_DEFAULT_ORIGINATE)) {
12336 if (p->default_rmap[afi][safi].name)
12337 json_object_string_add(
12338 json_addr, "defaultRouteMap",
12339 p->default_rmap[afi][safi].name);
12340
12341 if (paf && PAF_SUBGRP(paf)
12342 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12343 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12344 json_object_boolean_true_add(json_addr,
12345 "defaultSent");
12346 else
12347 json_object_boolean_true_add(json_addr,
12348 "defaultNotSent");
12349 }
12350
12351 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12352 if (is_evpn_enabled())
12353 json_object_boolean_true_add(
12354 json_addr, "advertiseAllVnis");
12355 }
12356
12357 if (filter->plist[FILTER_IN].name
12358 || filter->dlist[FILTER_IN].name
12359 || filter->aslist[FILTER_IN].name
12360 || filter->map[RMAP_IN].name)
12361 json_object_boolean_true_add(json_addr,
12362 "inboundPathPolicyConfig");
12363 if (filter->plist[FILTER_OUT].name
12364 || filter->dlist[FILTER_OUT].name
12365 || filter->aslist[FILTER_OUT].name
12366 || filter->map[RMAP_OUT].name || filter->usmap.name)
12367 json_object_boolean_true_add(
12368 json_addr, "outboundPathPolicyConfig");
12369
12370 /* prefix-list */
12371 if (filter->plist[FILTER_IN].name)
12372 json_object_string_add(json_addr,
12373 "incomingUpdatePrefixFilterList",
12374 filter->plist[FILTER_IN].name);
12375 if (filter->plist[FILTER_OUT].name)
12376 json_object_string_add(json_addr,
12377 "outgoingUpdatePrefixFilterList",
12378 filter->plist[FILTER_OUT].name);
12379
12380 /* distribute-list */
12381 if (filter->dlist[FILTER_IN].name)
12382 json_object_string_add(
12383 json_addr, "incomingUpdateNetworkFilterList",
12384 filter->dlist[FILTER_IN].name);
12385 if (filter->dlist[FILTER_OUT].name)
12386 json_object_string_add(
12387 json_addr, "outgoingUpdateNetworkFilterList",
12388 filter->dlist[FILTER_OUT].name);
12389
12390 /* filter-list. */
12391 if (filter->aslist[FILTER_IN].name)
12392 json_object_string_add(json_addr,
12393 "incomingUpdateAsPathFilterList",
12394 filter->aslist[FILTER_IN].name);
12395 if (filter->aslist[FILTER_OUT].name)
12396 json_object_string_add(json_addr,
12397 "outgoingUpdateAsPathFilterList",
12398 filter->aslist[FILTER_OUT].name);
12399
12400 /* route-map. */
12401 if (filter->map[RMAP_IN].name)
12402 json_object_string_add(
12403 json_addr, "routeMapForIncomingAdvertisements",
12404 filter->map[RMAP_IN].name);
12405 if (filter->map[RMAP_OUT].name)
12406 json_object_string_add(
12407 json_addr, "routeMapForOutgoingAdvertisements",
12408 filter->map[RMAP_OUT].name);
12409
12410 /* ebgp-requires-policy (inbound) */
12411 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12412 && !bgp_inbound_policy_exists(p, filter))
12413 json_object_string_add(
12414 json_addr, "inboundEbgpRequiresPolicy",
12415 "Inbound updates discarded due to missing policy");
12416
12417 /* ebgp-requires-policy (outbound) */
12418 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12419 && (!bgp_outbound_policy_exists(p, filter)))
12420 json_object_string_add(
12421 json_addr, "outboundEbgpRequiresPolicy",
12422 "Outbound updates discarded due to missing policy");
12423
12424 /* unsuppress-map */
12425 if (filter->usmap.name)
12426 json_object_string_add(json_addr,
12427 "selectiveUnsuppressRouteMap",
12428 filter->usmap.name);
12429
12430 /* advertise-map */
12431 if (filter->advmap.aname) {
12432 json_advmap = json_object_new_object();
12433 json_object_string_add(json_advmap, "condition",
12434 filter->advmap.condition
12435 ? "EXIST"
12436 : "NON_EXIST");
12437 json_object_string_add(json_advmap, "conditionMap",
12438 filter->advmap.cname);
12439 json_object_string_add(json_advmap, "advertiseMap",
12440 filter->advmap.aname);
12441 json_object_string_add(
12442 json_advmap, "advertiseStatus",
12443 filter->advmap.update_type ==
12444 UPDATE_TYPE_ADVERTISE
12445 ? "Advertise"
12446 : "Withdraw");
12447 json_object_object_add(json_addr, "advertiseMap",
12448 json_advmap);
12449 }
12450
12451 /* Receive prefix count */
12452 json_object_int_add(json_addr, "acceptedPrefixCounter",
12453 p->pcount[afi][safi]);
12454 if (paf && PAF_SUBGRP(paf))
12455 json_object_int_add(json_addr, "sentPrefixCounter",
12456 (PAF_SUBGRP(paf))->scount);
12457
12458 /* Maximum prefix */
12459 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12460 json_object_int_add(json_addr, "prefixOutAllowedMax",
12461 p->pmax_out[afi][safi]);
12462
12463 /* Maximum prefix */
12464 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12465 json_object_int_add(json_addr, "prefixAllowedMax",
12466 p->pmax[afi][safi]);
12467 if (CHECK_FLAG(p->af_flags[afi][safi],
12468 PEER_FLAG_MAX_PREFIX_WARNING))
12469 json_object_boolean_true_add(
12470 json_addr, "prefixAllowedMaxWarning");
12471 json_object_int_add(json_addr,
12472 "prefixAllowedWarningThresh",
12473 p->pmax_threshold[afi][safi]);
12474 if (p->pmax_restart[afi][safi])
12475 json_object_int_add(
12476 json_addr,
12477 "prefixAllowedRestartIntervalMsecs",
12478 p->pmax_restart[afi][safi] * 60000);
12479 }
12480 json_object_object_add(json_neigh,
12481 get_afi_safi_str(afi, safi, true),
12482 json_addr);
12483
12484 } else {
12485 filter = &p->filter[afi][safi];
12486
12487 vty_out(vty, " For address family: %s\n",
12488 get_afi_safi_str(afi, safi, false));
12489
12490 if (peer_group_active(p))
12491 vty_out(vty, " %s peer-group member\n",
12492 p->group->name);
12493
12494 paf = peer_af_find(p, afi, safi);
12495 if (paf && PAF_SUBGRP(paf)) {
12496 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12497 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12498 vty_out(vty, " Packet Queue length %d\n",
12499 bpacket_queue_virtual_length(paf));
12500 } else {
12501 vty_out(vty, " Not part of any update group\n");
12502 }
12503 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12504 || CHECK_FLAG(p->af_cap[afi][safi],
12505 PEER_CAP_ORF_PREFIX_SM_RCV)
12506 || CHECK_FLAG(p->af_cap[afi][safi],
12507 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12508 || CHECK_FLAG(p->af_cap[afi][safi],
12509 PEER_CAP_ORF_PREFIX_RM_ADV)
12510 || CHECK_FLAG(p->af_cap[afi][safi],
12511 PEER_CAP_ORF_PREFIX_RM_RCV)
12512 || CHECK_FLAG(p->af_cap[afi][safi],
12513 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12514 vty_out(vty, " AF-dependant capabilities:\n");
12515
12516 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12517 || CHECK_FLAG(p->af_cap[afi][safi],
12518 PEER_CAP_ORF_PREFIX_SM_RCV)
12519 || CHECK_FLAG(p->af_cap[afi][safi],
12520 PEER_CAP_ORF_PREFIX_RM_ADV)
12521 || CHECK_FLAG(p->af_cap[afi][safi],
12522 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12523 vty_out(vty,
12524 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12525 ORF_TYPE_PREFIX);
12526 bgp_show_peer_afi_orf_cap(
12527 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12528 PEER_CAP_ORF_PREFIX_RM_ADV,
12529 PEER_CAP_ORF_PREFIX_SM_RCV,
12530 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12531 }
12532 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12533 || CHECK_FLAG(p->af_cap[afi][safi],
12534 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12535 || CHECK_FLAG(p->af_cap[afi][safi],
12536 PEER_CAP_ORF_PREFIX_RM_ADV)
12537 || CHECK_FLAG(p->af_cap[afi][safi],
12538 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12539 vty_out(vty,
12540 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12541 ORF_TYPE_PREFIX_OLD);
12542 bgp_show_peer_afi_orf_cap(
12543 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12544 PEER_CAP_ORF_PREFIX_RM_ADV,
12545 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12546 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12547 }
12548
12549 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12550 p->host, afi, safi);
12551 orf_pfx_count = prefix_bgp_show_prefix_list(
12552 NULL, afi, orf_pfx_name, use_json);
12553
12554 if (CHECK_FLAG(p->af_sflags[afi][safi],
12555 PEER_STATUS_ORF_PREFIX_SEND)
12556 || orf_pfx_count) {
12557 vty_out(vty, " Outbound Route Filter (ORF):");
12558 if (CHECK_FLAG(p->af_sflags[afi][safi],
12559 PEER_STATUS_ORF_PREFIX_SEND))
12560 vty_out(vty, " sent;");
12561 if (orf_pfx_count)
12562 vty_out(vty, " received (%d entries)",
12563 orf_pfx_count);
12564 vty_out(vty, "\n");
12565 }
12566 if (CHECK_FLAG(p->af_sflags[afi][safi],
12567 PEER_STATUS_ORF_WAIT_REFRESH))
12568 vty_out(vty,
12569 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12570
12571 if (CHECK_FLAG(p->af_flags[afi][safi],
12572 PEER_FLAG_REFLECTOR_CLIENT))
12573 vty_out(vty, " Route-Reflector Client\n");
12574 if (CHECK_FLAG(p->af_flags[afi][safi],
12575 PEER_FLAG_RSERVER_CLIENT))
12576 vty_out(vty, " Route-Server Client\n");
12577
12578 if (peer_af_flag_check(p, afi, safi, PEER_FLAG_ORR_GROUP))
12579 vty_out(vty, " ORR group (configured) : %s\n",
12580 p->orr_group_name[afi][safi]);
12581
12582 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12583 vty_out(vty,
12584 " Inbound soft reconfiguration allowed\n");
12585
12586 if (CHECK_FLAG(p->af_flags[afi][safi],
12587 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12588 vty_out(vty,
12589 " Private AS numbers (all) replaced in updates to this neighbor\n");
12590 else if (CHECK_FLAG(p->af_flags[afi][safi],
12591 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12592 vty_out(vty,
12593 " Private AS numbers replaced in updates to this neighbor\n");
12594 else if (CHECK_FLAG(p->af_flags[afi][safi],
12595 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12596 vty_out(vty,
12597 " Private AS numbers (all) removed in updates to this neighbor\n");
12598 else if (CHECK_FLAG(p->af_flags[afi][safi],
12599 PEER_FLAG_REMOVE_PRIVATE_AS))
12600 vty_out(vty,
12601 " Private AS numbers removed in updates to this neighbor\n");
12602
12603 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12604 if (CHECK_FLAG(p->af_flags[afi][safi],
12605 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12606 vty_out(vty,
12607 " Local AS allowed as path origin\n");
12608 else
12609 vty_out(vty,
12610 " Local AS allowed in path, %d occurrences\n",
12611 p->allowas_in[afi][safi]);
12612 }
12613
12614 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12615 vty_out(vty, " %s\n",
12616 bgp_addpath_names(p->addpath_type[afi][safi])
12617 ->human_description);
12618
12619 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12620 vty_out(vty,
12621 " Override ASNs in outbound updates if aspath equals remote-as\n");
12622
12623 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12624 || CHECK_FLAG(p->af_flags[afi][safi],
12625 PEER_FLAG_FORCE_NEXTHOP_SELF))
12626 vty_out(vty, " NEXT_HOP is always this router\n");
12627 if (CHECK_FLAG(p->af_flags[afi][safi],
12628 PEER_FLAG_AS_PATH_UNCHANGED))
12629 vty_out(vty,
12630 " AS_PATH is propagated unchanged to this neighbor\n");
12631 if (CHECK_FLAG(p->af_flags[afi][safi],
12632 PEER_FLAG_NEXTHOP_UNCHANGED))
12633 vty_out(vty,
12634 " NEXT_HOP is propagated unchanged to this neighbor\n");
12635 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12636 vty_out(vty,
12637 " MED is propagated unchanged to this neighbor\n");
12638 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12639 || CHECK_FLAG(p->af_flags[afi][safi],
12640 PEER_FLAG_SEND_EXT_COMMUNITY)
12641 || CHECK_FLAG(p->af_flags[afi][safi],
12642 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12643 vty_out(vty,
12644 " Community attribute sent to this neighbor");
12645 if (CHECK_FLAG(p->af_flags[afi][safi],
12646 PEER_FLAG_SEND_COMMUNITY)
12647 && CHECK_FLAG(p->af_flags[afi][safi],
12648 PEER_FLAG_SEND_EXT_COMMUNITY)
12649 && CHECK_FLAG(p->af_flags[afi][safi],
12650 PEER_FLAG_SEND_LARGE_COMMUNITY))
12651 vty_out(vty, "(all)\n");
12652 else if (CHECK_FLAG(p->af_flags[afi][safi],
12653 PEER_FLAG_SEND_LARGE_COMMUNITY))
12654 vty_out(vty, "(large)\n");
12655 else if (CHECK_FLAG(p->af_flags[afi][safi],
12656 PEER_FLAG_SEND_EXT_COMMUNITY))
12657 vty_out(vty, "(extended)\n");
12658 else
12659 vty_out(vty, "(standard)\n");
12660 }
12661 if (CHECK_FLAG(p->af_flags[afi][safi],
12662 PEER_FLAG_DEFAULT_ORIGINATE)) {
12663 vty_out(vty, " Default information originate,");
12664
12665 if (p->default_rmap[afi][safi].name)
12666 vty_out(vty, " default route-map %s%s,",
12667 p->default_rmap[afi][safi].map ? "*"
12668 : "",
12669 p->default_rmap[afi][safi].name);
12670 if (paf && PAF_SUBGRP(paf)
12671 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12672 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12673 vty_out(vty, " default sent\n");
12674 else
12675 vty_out(vty, " default not sent\n");
12676 }
12677
12678 /* advertise-vni-all */
12679 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12680 if (is_evpn_enabled())
12681 vty_out(vty, " advertise-all-vni\n");
12682 }
12683
12684 if (filter->plist[FILTER_IN].name
12685 || filter->dlist[FILTER_IN].name
12686 || filter->aslist[FILTER_IN].name
12687 || filter->map[RMAP_IN].name)
12688 vty_out(vty, " Inbound path policy configured\n");
12689 if (filter->plist[FILTER_OUT].name
12690 || filter->dlist[FILTER_OUT].name
12691 || filter->aslist[FILTER_OUT].name
12692 || filter->map[RMAP_OUT].name || filter->usmap.name)
12693 vty_out(vty, " Outbound path policy configured\n");
12694
12695 /* prefix-list */
12696 if (filter->plist[FILTER_IN].name)
12697 vty_out(vty,
12698 " Incoming update prefix filter list is %s%s\n",
12699 filter->plist[FILTER_IN].plist ? "*" : "",
12700 filter->plist[FILTER_IN].name);
12701 if (filter->plist[FILTER_OUT].name)
12702 vty_out(vty,
12703 " Outgoing update prefix filter list is %s%s\n",
12704 filter->plist[FILTER_OUT].plist ? "*" : "",
12705 filter->plist[FILTER_OUT].name);
12706
12707 /* distribute-list */
12708 if (filter->dlist[FILTER_IN].name)
12709 vty_out(vty,
12710 " Incoming update network filter list is %s%s\n",
12711 filter->dlist[FILTER_IN].alist ? "*" : "",
12712 filter->dlist[FILTER_IN].name);
12713 if (filter->dlist[FILTER_OUT].name)
12714 vty_out(vty,
12715 " Outgoing update network filter list is %s%s\n",
12716 filter->dlist[FILTER_OUT].alist ? "*" : "",
12717 filter->dlist[FILTER_OUT].name);
12718
12719 /* filter-list. */
12720 if (filter->aslist[FILTER_IN].name)
12721 vty_out(vty,
12722 " Incoming update AS path filter list is %s%s\n",
12723 filter->aslist[FILTER_IN].aslist ? "*" : "",
12724 filter->aslist[FILTER_IN].name);
12725 if (filter->aslist[FILTER_OUT].name)
12726 vty_out(vty,
12727 " Outgoing update AS path filter list is %s%s\n",
12728 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12729 filter->aslist[FILTER_OUT].name);
12730
12731 /* route-map. */
12732 if (filter->map[RMAP_IN].name)
12733 vty_out(vty,
12734 " Route map for incoming advertisements is %s%s\n",
12735 filter->map[RMAP_IN].map ? "*" : "",
12736 filter->map[RMAP_IN].name);
12737 if (filter->map[RMAP_OUT].name)
12738 vty_out(vty,
12739 " Route map for outgoing advertisements is %s%s\n",
12740 filter->map[RMAP_OUT].map ? "*" : "",
12741 filter->map[RMAP_OUT].name);
12742
12743 /* ebgp-requires-policy (inbound) */
12744 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12745 && !bgp_inbound_policy_exists(p, filter))
12746 vty_out(vty,
12747 " Inbound updates discarded due to missing policy\n");
12748
12749 /* ebgp-requires-policy (outbound) */
12750 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12751 && !bgp_outbound_policy_exists(p, filter))
12752 vty_out(vty,
12753 " Outbound updates discarded due to missing policy\n");
12754
12755 /* unsuppress-map */
12756 if (filter->usmap.name)
12757 vty_out(vty,
12758 " Route map for selective unsuppress is %s%s\n",
12759 filter->usmap.map ? "*" : "",
12760 filter->usmap.name);
12761
12762 /* advertise-map */
12763 if (filter->advmap.aname && filter->advmap.cname)
12764 vty_out(vty,
12765 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12766 filter->advmap.condition ? "EXIST"
12767 : "NON_EXIST",
12768 filter->advmap.cmap ? "*" : "",
12769 filter->advmap.cname,
12770 filter->advmap.amap ? "*" : "",
12771 filter->advmap.aname,
12772 filter->advmap.update_type ==
12773 UPDATE_TYPE_ADVERTISE
12774 ? "Advertise"
12775 : "Withdraw");
12776
12777 /* Receive prefix count */
12778 vty_out(vty, " %u accepted prefixes\n",
12779 p->pcount[afi][safi]);
12780
12781 /* maximum-prefix-out */
12782 if (CHECK_FLAG(p->af_flags[afi][safi],
12783 PEER_FLAG_MAX_PREFIX_OUT))
12784 vty_out(vty,
12785 " Maximum allowed prefixes sent %u\n",
12786 p->pmax_out[afi][safi]);
12787
12788 /* Maximum prefix */
12789 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12790 vty_out(vty,
12791 " Maximum prefixes allowed %u%s\n",
12792 p->pmax[afi][safi],
12793 CHECK_FLAG(p->af_flags[afi][safi],
12794 PEER_FLAG_MAX_PREFIX_WARNING)
12795 ? " (warning-only)"
12796 : "");
12797 vty_out(vty, " Threshold for warning message %d%%",
12798 p->pmax_threshold[afi][safi]);
12799 if (p->pmax_restart[afi][safi])
12800 vty_out(vty, ", restart interval %d min",
12801 p->pmax_restart[afi][safi]);
12802 vty_out(vty, "\n");
12803 }
12804
12805 vty_out(vty, "\n");
12806 }
12807 }
12808
12809 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12810 json_object *json)
12811 {
12812 struct bgp *bgp;
12813 char buf1[PREFIX2STR_BUFFER];
12814 char timebuf[BGP_UPTIME_LEN];
12815 char dn_flag[2];
12816 afi_t afi;
12817 safi_t safi;
12818 uint16_t i;
12819 uint8_t *msg;
12820 json_object *json_neigh = NULL;
12821 time_t epoch_tbuf;
12822 uint32_t sync_tcp_mss;
12823
12824 bgp = p->bgp;
12825
12826 if (use_json)
12827 json_neigh = json_object_new_object();
12828
12829 memset(dn_flag, '\0', sizeof(dn_flag));
12830 if (!p->conf_if && peer_dynamic_neighbor(p))
12831 dn_flag[0] = '*';
12832
12833 if (!use_json) {
12834 if (p->conf_if) /* Configured interface name. */
12835 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12836 &p->su);
12837 else /* Configured IP address. */
12838 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12839 p->host);
12840 }
12841
12842 if (use_json) {
12843 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12844 json_object_string_add(json_neigh, "bgpNeighborAddr",
12845 "none");
12846 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12847 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12848 "%pSU", &p->su);
12849
12850 json_object_int_add(json_neigh, "remoteAs", p->as);
12851
12852 if (p->change_local_as)
12853 json_object_int_add(json_neigh, "localAs",
12854 p->change_local_as);
12855 else
12856 json_object_int_add(json_neigh, "localAs", p->local_as);
12857
12858 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12859 json_object_boolean_true_add(json_neigh,
12860 "localAsNoPrepend");
12861
12862 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12863 json_object_boolean_true_add(json_neigh,
12864 "localAsReplaceAs");
12865 } else {
12866 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12867 || (p->as_type == AS_INTERNAL))
12868 vty_out(vty, "remote AS %u, ", p->as);
12869 else
12870 vty_out(vty, "remote AS Unspecified, ");
12871 vty_out(vty, "local AS %u%s%s, ",
12872 p->change_local_as ? p->change_local_as : p->local_as,
12873 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12874 ? " no-prepend"
12875 : "",
12876 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12877 ? " replace-as"
12878 : "");
12879 }
12880 /* peer type internal or confed-internal */
12881 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12882 if (use_json) {
12883 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12884 json_object_boolean_true_add(
12885 json_neigh, "nbrConfedInternalLink");
12886 else
12887 json_object_boolean_true_add(json_neigh,
12888 "nbrInternalLink");
12889 } else {
12890 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12891 vty_out(vty, "confed-internal link\n");
12892 else
12893 vty_out(vty, "internal link\n");
12894 }
12895 /* peer type external or confed-external */
12896 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12897 if (use_json) {
12898 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12899 json_object_boolean_true_add(
12900 json_neigh, "nbrConfedExternalLink");
12901 else
12902 json_object_boolean_true_add(json_neigh,
12903 "nbrExternalLink");
12904 } else {
12905 if (bgp_confederation_peers_check(bgp, p->as))
12906 vty_out(vty, "confed-external link\n");
12907 else
12908 vty_out(vty, "external link\n");
12909 }
12910 } else {
12911 if (use_json)
12912 json_object_boolean_true_add(json_neigh,
12913 "nbrUnspecifiedLink");
12914 else
12915 vty_out(vty, "unspecified link\n");
12916 }
12917
12918 /* Roles */
12919 if (use_json) {
12920 json_object_string_add(json_neigh, "localRole",
12921 bgp_get_name_by_role(p->local_role));
12922 json_object_string_add(json_neigh, "remoteRole",
12923 bgp_get_name_by_role(p->remote_role));
12924 } else {
12925 vty_out(vty, " Local Role: %s\n",
12926 bgp_get_name_by_role(p->local_role));
12927 vty_out(vty, " Remote Role: %s\n",
12928 bgp_get_name_by_role(p->remote_role));
12929 }
12930
12931
12932 /* Description. */
12933 if (p->desc) {
12934 if (use_json)
12935 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12936 else
12937 vty_out(vty, " Description: %s\n", p->desc);
12938 }
12939
12940 if (p->hostname) {
12941 if (use_json) {
12942 if (p->hostname)
12943 json_object_string_add(json_neigh, "hostname",
12944 p->hostname);
12945
12946 if (p->domainname)
12947 json_object_string_add(json_neigh, "domainname",
12948 p->domainname);
12949 } else {
12950 if (p->domainname && (p->domainname[0] != '\0'))
12951 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12952 p->domainname);
12953 else
12954 vty_out(vty, "Hostname: %s\n", p->hostname);
12955 }
12956 }
12957
12958 /* Peer-group */
12959 if (p->group) {
12960 if (use_json) {
12961 json_object_string_add(json_neigh, "peerGroup",
12962 p->group->name);
12963
12964 if (dn_flag[0]) {
12965 struct prefix prefix, *range = NULL;
12966
12967 if (sockunion2hostprefix(&(p->su), &prefix))
12968 range = peer_group_lookup_dynamic_neighbor_range(
12969 p->group, &prefix);
12970
12971 if (range) {
12972 json_object_string_addf(
12973 json_neigh,
12974 "peerSubnetRangeGroup", "%pFX",
12975 range);
12976 }
12977 }
12978 } else {
12979 vty_out(vty,
12980 " Member of peer-group %s for session parameters\n",
12981 p->group->name);
12982
12983 if (dn_flag[0]) {
12984 struct prefix prefix, *range = NULL;
12985
12986 if (sockunion2hostprefix(&(p->su), &prefix))
12987 range = peer_group_lookup_dynamic_neighbor_range(
12988 p->group, &prefix);
12989
12990 if (range) {
12991 vty_out(vty,
12992 " Belongs to the subnet range group: %pFX\n",
12993 range);
12994 }
12995 }
12996 }
12997 }
12998
12999 if (use_json) {
13000 /* Administrative shutdown. */
13001 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13002 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13003 json_object_boolean_true_add(json_neigh,
13004 "adminShutDown");
13005
13006 /* BGP Version. */
13007 json_object_int_add(json_neigh, "bgpVersion", 4);
13008 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13009 &p->remote_id);
13010 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13011 &bgp->router_id);
13012
13013 /* Confederation */
13014 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13015 && bgp_confederation_peers_check(bgp, p->as))
13016 json_object_boolean_true_add(json_neigh,
13017 "nbrCommonAdmin");
13018
13019 /* Status. */
13020 json_object_string_add(
13021 json_neigh, "bgpState",
13022 lookup_msg(bgp_status_msg, p->status, NULL));
13023
13024 if (peer_established(p)) {
13025 time_t uptime;
13026
13027 uptime = monotime(NULL);
13028 uptime -= p->uptime;
13029 epoch_tbuf = time(NULL) - uptime;
13030
13031 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13032 uptime * 1000);
13033 json_object_string_add(json_neigh, "bgpTimerUpString",
13034 peer_uptime(p->uptime, timebuf,
13035 BGP_UPTIME_LEN, 0,
13036 NULL));
13037 json_object_int_add(json_neigh,
13038 "bgpTimerUpEstablishedEpoch",
13039 epoch_tbuf);
13040 }
13041
13042 else if (p->status == Active) {
13043 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13044 json_object_string_add(json_neigh, "bgpStateIs",
13045 "passive");
13046 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13047 json_object_string_add(json_neigh, "bgpStateIs",
13048 "passiveNSF");
13049 }
13050
13051 /* read timer */
13052 time_t uptime;
13053 struct tm tm;
13054
13055 uptime = monotime(NULL);
13056 uptime -= p->readtime;
13057 gmtime_r(&uptime, &tm);
13058
13059 json_object_int_add(json_neigh, "bgpTimerLastRead",
13060 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13061 + (tm.tm_hour * 3600000));
13062
13063 uptime = monotime(NULL);
13064 uptime -= p->last_write;
13065 gmtime_r(&uptime, &tm);
13066
13067 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13068 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13069 + (tm.tm_hour * 3600000));
13070
13071 uptime = monotime(NULL);
13072 uptime -= p->update_time;
13073 gmtime_r(&uptime, &tm);
13074
13075 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13076 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13077 + (tm.tm_hour * 3600000));
13078
13079 /* Configured timer values. */
13080 json_object_int_add(json_neigh,
13081 "bgpTimerConfiguredHoldTimeMsecs",
13082 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13083 ? p->holdtime * 1000
13084 : bgp->default_holdtime * 1000);
13085 json_object_int_add(json_neigh,
13086 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13087 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13088 ? p->keepalive * 1000
13089 : bgp->default_keepalive * 1000);
13090 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13091 p->v_holdtime * 1000);
13092 json_object_int_add(json_neigh,
13093 "bgpTimerKeepAliveIntervalMsecs",
13094 p->v_keepalive * 1000);
13095 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13096 json_object_int_add(json_neigh,
13097 "bgpTimerDelayOpenTimeMsecs",
13098 p->v_delayopen * 1000);
13099 }
13100
13101 /* Configured and Synced tcp-mss value for peer */
13102 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13103 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13104 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13105 p->tcp_mss);
13106 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13107 sync_tcp_mss);
13108 }
13109
13110 /* Extended Optional Parameters Length for BGP OPEN Message */
13111 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13112 json_object_boolean_true_add(
13113 json_neigh, "extendedOptionalParametersLength");
13114 else
13115 json_object_boolean_false_add(
13116 json_neigh, "extendedOptionalParametersLength");
13117
13118 /* Conditional advertisements */
13119 json_object_int_add(
13120 json_neigh,
13121 "bgpTimerConfiguredConditionalAdvertisementsSec",
13122 bgp->condition_check_period);
13123 if (thread_is_scheduled(bgp->t_condition_check))
13124 json_object_int_add(
13125 json_neigh,
13126 "bgpTimerUntilConditionalAdvertisementsSec",
13127 thread_timer_remain_second(
13128 bgp->t_condition_check));
13129 } else {
13130 /* Administrative shutdown. */
13131 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13132 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13133 vty_out(vty, " Administratively shut down\n");
13134
13135 /* BGP Version. */
13136 vty_out(vty, " BGP version 4");
13137 vty_out(vty, ", remote router ID %s",
13138 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
13139 vty_out(vty, ", local router ID %s\n",
13140 inet_ntop(AF_INET, &bgp->router_id, buf1,
13141 sizeof(buf1)));
13142
13143 /* Confederation */
13144 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13145 && bgp_confederation_peers_check(bgp, p->as))
13146 vty_out(vty,
13147 " Neighbor under common administration\n");
13148
13149 /* Status. */
13150 vty_out(vty, " BGP state = %s",
13151 lookup_msg(bgp_status_msg, p->status, NULL));
13152
13153 if (peer_established(p))
13154 vty_out(vty, ", up for %8s",
13155 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13156 0, NULL));
13157
13158 else if (p->status == Active) {
13159 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13160 vty_out(vty, " (passive)");
13161 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13162 vty_out(vty, " (NSF passive)");
13163 }
13164 vty_out(vty, "\n");
13165
13166 /* read timer */
13167 vty_out(vty, " Last read %s",
13168 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13169 NULL));
13170 vty_out(vty, ", Last write %s\n",
13171 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13172 NULL));
13173
13174 /* Configured timer values. */
13175 vty_out(vty,
13176 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13177 p->v_holdtime, p->v_keepalive);
13178 vty_out(vty, " Configured hold time is %d seconds",
13179 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13180 ? p->holdtime
13181 : bgp->default_holdtime);
13182 vty_out(vty, ", keepalive interval is %d seconds\n",
13183 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13184 ? p->keepalive
13185 : bgp->default_keepalive);
13186 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13187 vty_out(vty,
13188 " Configured DelayOpenTime is %d seconds\n",
13189 p->delayopen);
13190
13191 /* Configured and synced tcp-mss value for peer */
13192 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13193 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13194 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13195 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13196 }
13197
13198 /* Extended Optional Parameters Length for BGP OPEN Message */
13199 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13200 vty_out(vty,
13201 " Extended Optional Parameters Length is enabled\n");
13202
13203 /* Conditional advertisements */
13204 vty_out(vty,
13205 " Configured conditional advertisements interval is %d seconds\n",
13206 bgp->condition_check_period);
13207 if (thread_is_scheduled(bgp->t_condition_check))
13208 vty_out(vty,
13209 " Time until conditional advertisements begin is %lu seconds\n",
13210 thread_timer_remain_second(
13211 bgp->t_condition_check));
13212 }
13213 /* Capability. */
13214 if (peer_established(p) &&
13215 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13216 if (use_json) {
13217 json_object *json_cap = NULL;
13218
13219 json_cap = json_object_new_object();
13220
13221 /* AS4 */
13222 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13223 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13224 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13225 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13226 json_object_string_add(
13227 json_cap, "4byteAs",
13228 "advertisedAndReceived");
13229 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13230 json_object_string_add(json_cap,
13231 "4byteAs",
13232 "advertised");
13233 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13234 json_object_string_add(json_cap,
13235 "4byteAs",
13236 "received");
13237 }
13238
13239 /* Extended Message Support */
13240 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13241 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13242 json_object_string_add(json_cap,
13243 "extendedMessage",
13244 "advertisedAndReceived");
13245 else if (CHECK_FLAG(p->cap,
13246 PEER_CAP_EXTENDED_MESSAGE_ADV))
13247 json_object_string_add(json_cap,
13248 "extendedMessage",
13249 "advertised");
13250 else if (CHECK_FLAG(p->cap,
13251 PEER_CAP_EXTENDED_MESSAGE_RCV))
13252 json_object_string_add(json_cap,
13253 "extendedMessage",
13254 "received");
13255
13256 /* AddPath */
13257 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13258 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13259 json_object *json_add = NULL;
13260 const char *print_store;
13261
13262 json_add = json_object_new_object();
13263
13264 FOREACH_AFI_SAFI (afi, safi) {
13265 json_object *json_sub = NULL;
13266 json_sub = json_object_new_object();
13267 print_store = get_afi_safi_str(
13268 afi, safi, true);
13269
13270 if (CHECK_FLAG(
13271 p->af_cap[afi][safi],
13272 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13273 CHECK_FLAG(
13274 p->af_cap[afi][safi],
13275 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13276 if (CHECK_FLAG(
13277 p->af_cap[afi]
13278 [safi],
13279 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13280 CHECK_FLAG(
13281 p->af_cap[afi]
13282 [safi],
13283 PEER_CAP_ADDPATH_AF_TX_RCV))
13284 json_object_boolean_true_add(
13285 json_sub,
13286 "txAdvertisedAndReceived");
13287 else if (
13288 CHECK_FLAG(
13289 p->af_cap[afi]
13290 [safi],
13291 PEER_CAP_ADDPATH_AF_TX_ADV))
13292 json_object_boolean_true_add(
13293 json_sub,
13294 "txAdvertised");
13295 else if (
13296 CHECK_FLAG(
13297 p->af_cap[afi]
13298 [safi],
13299 PEER_CAP_ADDPATH_AF_TX_RCV))
13300 json_object_boolean_true_add(
13301 json_sub,
13302 "txReceived");
13303 }
13304
13305 if (CHECK_FLAG(
13306 p->af_cap[afi][safi],
13307 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13308 CHECK_FLAG(
13309 p->af_cap[afi][safi],
13310 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13311 if (CHECK_FLAG(
13312 p->af_cap[afi]
13313 [safi],
13314 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13315 CHECK_FLAG(
13316 p->af_cap[afi]
13317 [safi],
13318 PEER_CAP_ADDPATH_AF_RX_RCV))
13319 json_object_boolean_true_add(
13320 json_sub,
13321 "rxAdvertisedAndReceived");
13322 else if (
13323 CHECK_FLAG(
13324 p->af_cap[afi]
13325 [safi],
13326 PEER_CAP_ADDPATH_AF_RX_ADV))
13327 json_object_boolean_true_add(
13328 json_sub,
13329 "rxAdvertised");
13330 else if (
13331 CHECK_FLAG(
13332 p->af_cap[afi]
13333 [safi],
13334 PEER_CAP_ADDPATH_AF_RX_RCV))
13335 json_object_boolean_true_add(
13336 json_sub,
13337 "rxReceived");
13338 }
13339
13340 if (CHECK_FLAG(
13341 p->af_cap[afi][safi],
13342 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13343 CHECK_FLAG(
13344 p->af_cap[afi][safi],
13345 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13346 CHECK_FLAG(
13347 p->af_cap[afi][safi],
13348 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13349 CHECK_FLAG(
13350 p->af_cap[afi][safi],
13351 PEER_CAP_ADDPATH_AF_RX_RCV))
13352 json_object_object_add(
13353 json_add, print_store,
13354 json_sub);
13355 else
13356 json_object_free(json_sub);
13357 }
13358
13359 json_object_object_add(json_cap, "addPath",
13360 json_add);
13361 }
13362
13363 /* Dynamic */
13364 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13365 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13366 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13367 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13368 json_object_string_add(
13369 json_cap, "dynamic",
13370 "advertisedAndReceived");
13371 else if (CHECK_FLAG(p->cap,
13372 PEER_CAP_DYNAMIC_ADV))
13373 json_object_string_add(json_cap,
13374 "dynamic",
13375 "advertised");
13376 else if (CHECK_FLAG(p->cap,
13377 PEER_CAP_DYNAMIC_RCV))
13378 json_object_string_add(json_cap,
13379 "dynamic",
13380 "received");
13381 }
13382
13383 /* Role */
13384 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13385 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13386 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13387 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13388 json_object_string_add(
13389 json_cap, "role",
13390 "advertisedAndReceived");
13391 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13392 json_object_string_add(json_cap, "role",
13393 "advertised");
13394 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13395 json_object_string_add(json_cap, "role",
13396 "received");
13397 }
13398
13399 /* Extended nexthop */
13400 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13401 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13402 json_object *json_nxt = NULL;
13403 const char *print_store;
13404
13405
13406 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13407 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13408 json_object_string_add(
13409 json_cap, "extendedNexthop",
13410 "advertisedAndReceived");
13411 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13412 json_object_string_add(
13413 json_cap, "extendedNexthop",
13414 "advertised");
13415 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13416 json_object_string_add(
13417 json_cap, "extendedNexthop",
13418 "received");
13419
13420 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13421 json_nxt = json_object_new_object();
13422
13423 for (safi = SAFI_UNICAST;
13424 safi < SAFI_MAX; safi++) {
13425 if (CHECK_FLAG(
13426 p->af_cap[AFI_IP]
13427 [safi],
13428 PEER_CAP_ENHE_AF_RCV)) {
13429 print_store =
13430 get_afi_safi_str(
13431 AFI_IP,
13432 safi,
13433 true);
13434 json_object_string_add(
13435 json_nxt,
13436 print_store,
13437 "recieved"); /* misspelled for compatibility */
13438 }
13439 }
13440 json_object_object_add(
13441 json_cap,
13442 "extendedNexthopFamililesByPeer",
13443 json_nxt);
13444 }
13445 }
13446
13447 /* Long-lived Graceful Restart */
13448 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13449 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13450 json_object *json_llgr = NULL;
13451 const char *afi_safi_str;
13452
13453 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13454 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13455 json_object_string_add(
13456 json_cap,
13457 "longLivedGracefulRestart",
13458 "advertisedAndReceived");
13459 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13460 json_object_string_add(
13461 json_cap,
13462 "longLivedGracefulRestart",
13463 "advertised");
13464 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13465 json_object_string_add(
13466 json_cap,
13467 "longLivedGracefulRestart",
13468 "received");
13469
13470 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13471 json_llgr = json_object_new_object();
13472
13473 FOREACH_AFI_SAFI (afi, safi) {
13474 if (CHECK_FLAG(
13475 p->af_cap[afi]
13476 [safi],
13477 PEER_CAP_ENHE_AF_RCV)) {
13478 afi_safi_str =
13479 get_afi_safi_str(
13480 afi,
13481 safi,
13482 true);
13483 json_object_string_add(
13484 json_llgr,
13485 afi_safi_str,
13486 "received");
13487 }
13488 }
13489 json_object_object_add(
13490 json_cap,
13491 "longLivedGracefulRestartByPeer",
13492 json_llgr);
13493 }
13494 }
13495
13496 /* Route Refresh */
13497 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13498 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13499 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13500 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13501 (CHECK_FLAG(p->cap,
13502 PEER_CAP_REFRESH_NEW_RCV) ||
13503 CHECK_FLAG(p->cap,
13504 PEER_CAP_REFRESH_OLD_RCV))) {
13505 if (CHECK_FLAG(
13506 p->cap,
13507 PEER_CAP_REFRESH_OLD_RCV) &&
13508 CHECK_FLAG(
13509 p->cap,
13510 PEER_CAP_REFRESH_NEW_RCV))
13511 json_object_string_add(
13512 json_cap,
13513 "routeRefresh",
13514 "advertisedAndReceivedOldNew");
13515 else {
13516 if (CHECK_FLAG(
13517 p->cap,
13518 PEER_CAP_REFRESH_OLD_RCV))
13519 json_object_string_add(
13520 json_cap,
13521 "routeRefresh",
13522 "advertisedAndReceivedOld");
13523 else
13524 json_object_string_add(
13525 json_cap,
13526 "routeRefresh",
13527 "advertisedAndReceivedNew");
13528 }
13529 } else if (CHECK_FLAG(p->cap,
13530 PEER_CAP_REFRESH_ADV))
13531 json_object_string_add(json_cap,
13532 "routeRefresh",
13533 "advertised");
13534 else if (CHECK_FLAG(p->cap,
13535 PEER_CAP_REFRESH_NEW_RCV) ||
13536 CHECK_FLAG(p->cap,
13537 PEER_CAP_REFRESH_OLD_RCV))
13538 json_object_string_add(json_cap,
13539 "routeRefresh",
13540 "received");
13541 }
13542
13543 /* Enhanced Route Refresh */
13544 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13545 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13546 if (CHECK_FLAG(p->cap,
13547 PEER_CAP_ENHANCED_RR_ADV) &&
13548 CHECK_FLAG(p->cap,
13549 PEER_CAP_ENHANCED_RR_RCV))
13550 json_object_string_add(
13551 json_cap,
13552 "enhancedRouteRefresh",
13553 "advertisedAndReceived");
13554 else if (CHECK_FLAG(p->cap,
13555 PEER_CAP_ENHANCED_RR_ADV))
13556 json_object_string_add(
13557 json_cap,
13558 "enhancedRouteRefresh",
13559 "advertised");
13560 else if (CHECK_FLAG(p->cap,
13561 PEER_CAP_ENHANCED_RR_RCV))
13562 json_object_string_add(
13563 json_cap,
13564 "enhancedRouteRefresh",
13565 "received");
13566 }
13567
13568 /* Multiprotocol Extensions */
13569 json_object *json_multi = NULL;
13570
13571 json_multi = json_object_new_object();
13572
13573 FOREACH_AFI_SAFI (afi, safi) {
13574 if (p->afc_adv[afi][safi] ||
13575 p->afc_recv[afi][safi]) {
13576 json_object *json_exten = NULL;
13577 json_exten = json_object_new_object();
13578
13579 if (p->afc_adv[afi][safi] &&
13580 p->afc_recv[afi][safi])
13581 json_object_boolean_true_add(
13582 json_exten,
13583 "advertisedAndReceived");
13584 else if (p->afc_adv[afi][safi])
13585 json_object_boolean_true_add(
13586 json_exten,
13587 "advertised");
13588 else if (p->afc_recv[afi][safi])
13589 json_object_boolean_true_add(
13590 json_exten, "received");
13591
13592 json_object_object_add(
13593 json_multi,
13594 get_afi_safi_str(afi, safi,
13595 true),
13596 json_exten);
13597 }
13598 }
13599 json_object_object_add(json_cap,
13600 "multiprotocolExtensions",
13601 json_multi);
13602
13603 /* Hostname capabilities */
13604 json_object *json_hname = NULL;
13605
13606 json_hname = json_object_new_object();
13607
13608 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13609 json_object_string_add(
13610 json_hname, "advHostName",
13611 bgp->peer_self->hostname
13612 ? bgp->peer_self->hostname
13613 : "n/a");
13614 json_object_string_add(
13615 json_hname, "advDomainName",
13616 bgp->peer_self->domainname
13617 ? bgp->peer_self->domainname
13618 : "n/a");
13619 }
13620
13621
13622 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13623 json_object_string_add(
13624 json_hname, "rcvHostName",
13625 p->hostname ? p->hostname : "n/a");
13626 json_object_string_add(
13627 json_hname, "rcvDomainName",
13628 p->domainname ? p->domainname : "n/a");
13629 }
13630
13631 json_object_object_add(json_cap, "hostName",
13632 json_hname);
13633
13634 /* Graceful Restart */
13635 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13636 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13637 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13638 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13639 json_object_string_add(
13640 json_cap, "gracefulRestart",
13641 "advertisedAndReceived");
13642 else if (CHECK_FLAG(p->cap,
13643 PEER_CAP_RESTART_ADV))
13644 json_object_string_add(
13645 json_cap,
13646 "gracefulRestartCapability",
13647 "advertised");
13648 else if (CHECK_FLAG(p->cap,
13649 PEER_CAP_RESTART_RCV))
13650 json_object_string_add(
13651 json_cap,
13652 "gracefulRestartCapability",
13653 "received");
13654
13655 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13656 int restart_af_count = 0;
13657 json_object *json_restart = NULL;
13658 json_restart = json_object_new_object();
13659
13660 json_object_int_add(
13661 json_cap,
13662 "gracefulRestartRemoteTimerMsecs",
13663 p->v_gr_restart * 1000);
13664
13665 FOREACH_AFI_SAFI (afi, safi) {
13666 if (CHECK_FLAG(
13667 p->af_cap[afi]
13668 [safi],
13669 PEER_CAP_RESTART_AF_RCV)) {
13670 json_object *json_sub =
13671 NULL;
13672 json_sub =
13673 json_object_new_object();
13674
13675 if (CHECK_FLAG(
13676 p->af_cap
13677 [afi]
13678 [safi],
13679 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13680 json_object_boolean_true_add(
13681 json_sub,
13682 "preserved");
13683 restart_af_count++;
13684 json_object_object_add(
13685 json_restart,
13686 get_afi_safi_str(
13687 afi,
13688 safi,
13689 true),
13690 json_sub);
13691 }
13692 }
13693 if (!restart_af_count) {
13694 json_object_string_add(
13695 json_cap,
13696 "addressFamiliesByPeer",
13697 "none");
13698 json_object_free(json_restart);
13699 } else
13700 json_object_object_add(
13701 json_cap,
13702 "addressFamiliesByPeer",
13703 json_restart);
13704 }
13705 }
13706 json_object_object_add(
13707 json_neigh, "neighborCapabilities", json_cap);
13708 } else {
13709 vty_out(vty, " Neighbor capabilities:\n");
13710
13711 /* AS4 */
13712 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13713 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13714 vty_out(vty, " 4 Byte AS:");
13715 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13716 vty_out(vty, " advertised");
13717 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13718 vty_out(vty, " %sreceived",
13719 CHECK_FLAG(p->cap,
13720 PEER_CAP_AS4_ADV)
13721 ? "and "
13722 : "");
13723 vty_out(vty, "\n");
13724 }
13725
13726 /* Extended Message Support */
13727 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13728 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13729 vty_out(vty, " Extended Message:");
13730 if (CHECK_FLAG(p->cap,
13731 PEER_CAP_EXTENDED_MESSAGE_ADV))
13732 vty_out(vty, " advertised");
13733 if (CHECK_FLAG(p->cap,
13734 PEER_CAP_EXTENDED_MESSAGE_RCV))
13735 vty_out(vty, " %sreceived",
13736 CHECK_FLAG(
13737 p->cap,
13738 PEER_CAP_EXTENDED_MESSAGE_ADV)
13739 ? "and "
13740 : "");
13741 vty_out(vty, "\n");
13742 }
13743
13744 /* AddPath */
13745 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13746 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13747 vty_out(vty, " AddPath:\n");
13748
13749 FOREACH_AFI_SAFI (afi, safi) {
13750 if (CHECK_FLAG(
13751 p->af_cap[afi][safi],
13752 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13753 CHECK_FLAG(
13754 p->af_cap[afi][safi],
13755 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13756 vty_out(vty, " %s: TX ",
13757 get_afi_safi_str(
13758 afi, safi,
13759 false));
13760
13761 if (CHECK_FLAG(
13762 p->af_cap[afi]
13763 [safi],
13764 PEER_CAP_ADDPATH_AF_TX_ADV))
13765 vty_out(vty,
13766 "advertised");
13767
13768 if (CHECK_FLAG(
13769 p->af_cap[afi]
13770 [safi],
13771 PEER_CAP_ADDPATH_AF_TX_RCV))
13772 vty_out(vty,
13773 "%sreceived",
13774 CHECK_FLAG(
13775 p->af_cap
13776 [afi]
13777 [safi],
13778 PEER_CAP_ADDPATH_AF_TX_ADV)
13779 ? " and "
13780 : "");
13781
13782 vty_out(vty, "\n");
13783 }
13784
13785 if (CHECK_FLAG(
13786 p->af_cap[afi][safi],
13787 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13788 CHECK_FLAG(
13789 p->af_cap[afi][safi],
13790 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13791 vty_out(vty, " %s: RX ",
13792 get_afi_safi_str(
13793 afi, safi,
13794 false));
13795
13796 if (CHECK_FLAG(
13797 p->af_cap[afi]
13798 [safi],
13799 PEER_CAP_ADDPATH_AF_RX_ADV))
13800 vty_out(vty,
13801 "advertised");
13802
13803 if (CHECK_FLAG(
13804 p->af_cap[afi]
13805 [safi],
13806 PEER_CAP_ADDPATH_AF_RX_RCV))
13807 vty_out(vty,
13808 "%sreceived",
13809 CHECK_FLAG(
13810 p->af_cap
13811 [afi]
13812 [safi],
13813 PEER_CAP_ADDPATH_AF_RX_ADV)
13814 ? " and "
13815 : "");
13816
13817 vty_out(vty, "\n");
13818 }
13819 }
13820 }
13821
13822 /* Dynamic */
13823 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13824 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13825 vty_out(vty, " Dynamic:");
13826 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13827 vty_out(vty, " advertised");
13828 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13829 vty_out(vty, " %sreceived",
13830 CHECK_FLAG(p->cap,
13831 PEER_CAP_DYNAMIC_ADV)
13832 ? "and "
13833 : "");
13834 vty_out(vty, "\n");
13835 }
13836
13837 /* Role */
13838 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13839 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13840 vty_out(vty, " Role:");
13841 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13842 vty_out(vty, " advertised");
13843 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13844 vty_out(vty, " %sreceived",
13845 CHECK_FLAG(p->cap,
13846 PEER_CAP_ROLE_ADV)
13847 ? "and "
13848 : "");
13849 vty_out(vty, "\n");
13850 }
13851
13852 /* Extended nexthop */
13853 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13854 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13855 vty_out(vty, " Extended nexthop:");
13856 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13857 vty_out(vty, " advertised");
13858 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13859 vty_out(vty, " %sreceived",
13860 CHECK_FLAG(p->cap,
13861 PEER_CAP_ENHE_ADV)
13862 ? "and "
13863 : "");
13864 vty_out(vty, "\n");
13865
13866 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13867 vty_out(vty,
13868 " Address families by peer:\n ");
13869 for (safi = SAFI_UNICAST;
13870 safi < SAFI_MAX; safi++)
13871 if (CHECK_FLAG(
13872 p->af_cap[AFI_IP]
13873 [safi],
13874 PEER_CAP_ENHE_AF_RCV))
13875 vty_out(vty,
13876 " %s\n",
13877 get_afi_safi_str(
13878 AFI_IP,
13879 safi,
13880 false));
13881 }
13882 }
13883
13884 /* Long-lived Graceful Restart */
13885 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13886 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13887 vty_out(vty,
13888 " Long-lived Graceful Restart:");
13889 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13890 vty_out(vty, " advertised");
13891 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13892 vty_out(vty, " %sreceived",
13893 CHECK_FLAG(p->cap,
13894 PEER_CAP_LLGR_ADV)
13895 ? "and "
13896 : "");
13897 vty_out(vty, "\n");
13898
13899 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13900 vty_out(vty,
13901 " Address families by peer:\n");
13902 FOREACH_AFI_SAFI (afi, safi)
13903 if (CHECK_FLAG(
13904 p->af_cap[afi]
13905 [safi],
13906 PEER_CAP_LLGR_AF_RCV))
13907 vty_out(vty,
13908 " %s\n",
13909 get_afi_safi_str(
13910 afi,
13911 safi,
13912 false));
13913 }
13914 }
13915
13916 /* Route Refresh */
13917 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13918 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13919 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13920 vty_out(vty, " Route refresh:");
13921 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13922 vty_out(vty, " advertised");
13923 if (CHECK_FLAG(p->cap,
13924 PEER_CAP_REFRESH_NEW_RCV) ||
13925 CHECK_FLAG(p->cap,
13926 PEER_CAP_REFRESH_OLD_RCV))
13927 vty_out(vty, " %sreceived(%s)",
13928 CHECK_FLAG(p->cap,
13929 PEER_CAP_REFRESH_ADV)
13930 ? "and "
13931 : "",
13932 (CHECK_FLAG(
13933 p->cap,
13934 PEER_CAP_REFRESH_OLD_RCV) &&
13935 CHECK_FLAG(
13936 p->cap,
13937 PEER_CAP_REFRESH_NEW_RCV))
13938 ? "old & new"
13939 : CHECK_FLAG(
13940 p->cap,
13941 PEER_CAP_REFRESH_OLD_RCV)
13942 ? "old"
13943 : "new");
13944
13945 vty_out(vty, "\n");
13946 }
13947
13948 /* Enhanced Route Refresh */
13949 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13950 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13951 vty_out(vty, " Enhanced Route Refresh:");
13952 if (CHECK_FLAG(p->cap,
13953 PEER_CAP_ENHANCED_RR_ADV))
13954 vty_out(vty, " advertised");
13955 if (CHECK_FLAG(p->cap,
13956 PEER_CAP_ENHANCED_RR_RCV))
13957 vty_out(vty, " %sreceived",
13958 CHECK_FLAG(p->cap,
13959 PEER_CAP_REFRESH_ADV)
13960 ? "and "
13961 : "");
13962 vty_out(vty, "\n");
13963 }
13964
13965 /* Multiprotocol Extensions */
13966 FOREACH_AFI_SAFI (afi, safi)
13967 if (p->afc_adv[afi][safi] ||
13968 p->afc_recv[afi][safi]) {
13969 vty_out(vty, " Address Family %s:",
13970 get_afi_safi_str(afi, safi,
13971 false));
13972 if (p->afc_adv[afi][safi])
13973 vty_out(vty, " advertised");
13974 if (p->afc_recv[afi][safi])
13975 vty_out(vty, " %sreceived",
13976 p->afc_adv[afi][safi]
13977 ? "and "
13978 : "");
13979 vty_out(vty, "\n");
13980 }
13981
13982 /* Hostname capability */
13983 vty_out(vty, " Hostname Capability:");
13984
13985 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13986 vty_out(vty,
13987 " advertised (name: %s,domain name: %s)",
13988 bgp->peer_self->hostname
13989 ? bgp->peer_self->hostname
13990 : "n/a",
13991 bgp->peer_self->domainname
13992 ? bgp->peer_self->domainname
13993 : "n/a");
13994 } else {
13995 vty_out(vty, " not advertised");
13996 }
13997
13998 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13999 vty_out(vty,
14000 " received (name: %s,domain name: %s)",
14001 p->hostname ? p->hostname : "n/a",
14002 p->domainname ? p->domainname : "n/a");
14003 } else {
14004 vty_out(vty, " not received");
14005 }
14006
14007 vty_out(vty, "\n");
14008
14009 /* Graceful Restart */
14010 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14011 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14012 vty_out(vty,
14013 " Graceful Restart Capability:");
14014 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14015 vty_out(vty, " advertised");
14016 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14017 vty_out(vty, " %sreceived",
14018 CHECK_FLAG(p->cap,
14019 PEER_CAP_RESTART_ADV)
14020 ? "and "
14021 : "");
14022 vty_out(vty, "\n");
14023
14024 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14025 int restart_af_count = 0;
14026
14027 vty_out(vty,
14028 " Remote Restart timer is %d seconds\n",
14029 p->v_gr_restart);
14030 vty_out(vty,
14031 " Address families by peer:\n ");
14032
14033 FOREACH_AFI_SAFI (afi, safi)
14034 if (CHECK_FLAG(
14035 p->af_cap[afi]
14036 [safi],
14037 PEER_CAP_RESTART_AF_RCV)) {
14038 vty_out(vty, "%s%s(%s)",
14039 restart_af_count
14040 ? ", "
14041 : "",
14042 get_afi_safi_str(
14043 afi,
14044 safi,
14045 false),
14046 CHECK_FLAG(
14047 p->af_cap
14048 [afi]
14049 [safi],
14050 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14051 ? "preserved"
14052 : "not preserved");
14053 restart_af_count++;
14054 }
14055 if (!restart_af_count)
14056 vty_out(vty, "none");
14057 vty_out(vty, "\n");
14058 }
14059 } /* Graceful Restart */
14060 }
14061 }
14062
14063 /* graceful restart information */
14064 json_object *json_grace = NULL;
14065 json_object *json_grace_send = NULL;
14066 json_object *json_grace_recv = NULL;
14067 int eor_send_af_count = 0;
14068 int eor_receive_af_count = 0;
14069
14070 if (use_json) {
14071 json_grace = json_object_new_object();
14072 json_grace_send = json_object_new_object();
14073 json_grace_recv = json_object_new_object();
14074
14075 if ((peer_established(p)) &&
14076 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14077 FOREACH_AFI_SAFI (afi, safi) {
14078 if (CHECK_FLAG(p->af_sflags[afi][safi],
14079 PEER_STATUS_EOR_SEND)) {
14080 json_object_boolean_true_add(
14081 json_grace_send,
14082 get_afi_safi_str(afi, safi,
14083 true));
14084 eor_send_af_count++;
14085 }
14086 }
14087 FOREACH_AFI_SAFI (afi, safi) {
14088 if (CHECK_FLAG(p->af_sflags[afi][safi],
14089 PEER_STATUS_EOR_RECEIVED)) {
14090 json_object_boolean_true_add(
14091 json_grace_recv,
14092 get_afi_safi_str(afi, safi,
14093 true));
14094 eor_receive_af_count++;
14095 }
14096 }
14097 }
14098 json_object_object_add(json_grace, "endOfRibSend",
14099 json_grace_send);
14100 json_object_object_add(json_grace, "endOfRibRecv",
14101 json_grace_recv);
14102
14103
14104 if (p->t_gr_restart)
14105 json_object_int_add(
14106 json_grace, "gracefulRestartTimerMsecs",
14107 thread_timer_remain_second(p->t_gr_restart) *
14108 1000);
14109
14110 if (p->t_gr_stale)
14111 json_object_int_add(
14112 json_grace, "gracefulStalepathTimerMsecs",
14113 thread_timer_remain_second(p->t_gr_stale) *
14114 1000);
14115 /* more gr info in new format */
14116 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
14117 json_object_object_add(json_neigh, "gracefulRestartInfo",
14118 json_grace);
14119 } else {
14120 vty_out(vty, " Graceful restart information:\n");
14121 if ((peer_established(p)) &&
14122 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14123
14124 vty_out(vty, " End-of-RIB send: ");
14125 FOREACH_AFI_SAFI (afi, safi) {
14126 if (CHECK_FLAG(p->af_sflags[afi][safi],
14127 PEER_STATUS_EOR_SEND)) {
14128 vty_out(vty, "%s%s",
14129 eor_send_af_count ? ", " : "",
14130 get_afi_safi_str(afi, safi,
14131 false));
14132 eor_send_af_count++;
14133 }
14134 }
14135 vty_out(vty, "\n");
14136 vty_out(vty, " End-of-RIB received: ");
14137 FOREACH_AFI_SAFI (afi, safi) {
14138 if (CHECK_FLAG(p->af_sflags[afi][safi],
14139 PEER_STATUS_EOR_RECEIVED)) {
14140 vty_out(vty, "%s%s",
14141 eor_receive_af_count ? ", "
14142 : "",
14143 get_afi_safi_str(afi, safi,
14144 false));
14145 eor_receive_af_count++;
14146 }
14147 }
14148 vty_out(vty, "\n");
14149 }
14150
14151 if (p->t_gr_restart)
14152 vty_out(vty,
14153 " The remaining time of restart timer is %ld\n",
14154 thread_timer_remain_second(p->t_gr_restart));
14155
14156 if (p->t_gr_stale)
14157 vty_out(vty,
14158 " The remaining time of stalepath timer is %ld\n",
14159 thread_timer_remain_second(p->t_gr_stale));
14160
14161 /* more gr info in new format */
14162 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
14163 }
14164
14165 if (use_json) {
14166 json_object *json_stat = NULL;
14167 json_stat = json_object_new_object();
14168 /* Packet counts. */
14169
14170 atomic_size_t outq_count, inq_count;
14171 outq_count = atomic_load_explicit(&p->obuf->count,
14172 memory_order_relaxed);
14173 inq_count = atomic_load_explicit(&p->ibuf->count,
14174 memory_order_relaxed);
14175
14176 json_object_int_add(json_stat, "depthInq",
14177 (unsigned long)inq_count);
14178 json_object_int_add(json_stat, "depthOutq",
14179 (unsigned long)outq_count);
14180 json_object_int_add(json_stat, "opensSent",
14181 atomic_load_explicit(&p->open_out,
14182 memory_order_relaxed));
14183 json_object_int_add(json_stat, "opensRecv",
14184 atomic_load_explicit(&p->open_in,
14185 memory_order_relaxed));
14186 json_object_int_add(json_stat, "notificationsSent",
14187 atomic_load_explicit(&p->notify_out,
14188 memory_order_relaxed));
14189 json_object_int_add(json_stat, "notificationsRecv",
14190 atomic_load_explicit(&p->notify_in,
14191 memory_order_relaxed));
14192 json_object_int_add(json_stat, "updatesSent",
14193 atomic_load_explicit(&p->update_out,
14194 memory_order_relaxed));
14195 json_object_int_add(json_stat, "updatesRecv",
14196 atomic_load_explicit(&p->update_in,
14197 memory_order_relaxed));
14198 json_object_int_add(json_stat, "keepalivesSent",
14199 atomic_load_explicit(&p->keepalive_out,
14200 memory_order_relaxed));
14201 json_object_int_add(json_stat, "keepalivesRecv",
14202 atomic_load_explicit(&p->keepalive_in,
14203 memory_order_relaxed));
14204 json_object_int_add(json_stat, "routeRefreshSent",
14205 atomic_load_explicit(&p->refresh_out,
14206 memory_order_relaxed));
14207 json_object_int_add(json_stat, "routeRefreshRecv",
14208 atomic_load_explicit(&p->refresh_in,
14209 memory_order_relaxed));
14210 json_object_int_add(json_stat, "capabilitySent",
14211 atomic_load_explicit(&p->dynamic_cap_out,
14212 memory_order_relaxed));
14213 json_object_int_add(json_stat, "capabilityRecv",
14214 atomic_load_explicit(&p->dynamic_cap_in,
14215 memory_order_relaxed));
14216 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14217 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14218 json_object_object_add(json_neigh, "messageStats", json_stat);
14219 } else {
14220 atomic_size_t outq_count, inq_count, open_out, open_in,
14221 notify_out, notify_in, update_out, update_in,
14222 keepalive_out, keepalive_in, refresh_out, refresh_in,
14223 dynamic_cap_out, dynamic_cap_in;
14224 outq_count = atomic_load_explicit(&p->obuf->count,
14225 memory_order_relaxed);
14226 inq_count = atomic_load_explicit(&p->ibuf->count,
14227 memory_order_relaxed);
14228 open_out = atomic_load_explicit(&p->open_out,
14229 memory_order_relaxed);
14230 open_in =
14231 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14232 notify_out = atomic_load_explicit(&p->notify_out,
14233 memory_order_relaxed);
14234 notify_in = atomic_load_explicit(&p->notify_in,
14235 memory_order_relaxed);
14236 update_out = atomic_load_explicit(&p->update_out,
14237 memory_order_relaxed);
14238 update_in = atomic_load_explicit(&p->update_in,
14239 memory_order_relaxed);
14240 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14241 memory_order_relaxed);
14242 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14243 memory_order_relaxed);
14244 refresh_out = atomic_load_explicit(&p->refresh_out,
14245 memory_order_relaxed);
14246 refresh_in = atomic_load_explicit(&p->refresh_in,
14247 memory_order_relaxed);
14248 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14249 memory_order_relaxed);
14250 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14251 memory_order_relaxed);
14252
14253 /* Packet counts. */
14254 vty_out(vty, " Message statistics:\n");
14255 vty_out(vty, " Inq depth is %zu\n", inq_count);
14256 vty_out(vty, " Outq depth is %zu\n", outq_count);
14257 vty_out(vty, " Sent Rcvd\n");
14258 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14259 open_in);
14260 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14261 notify_in);
14262 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14263 update_in);
14264 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14265 keepalive_in);
14266 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14267 refresh_in);
14268 vty_out(vty, " Capability: %10zu %10zu\n",
14269 dynamic_cap_out, dynamic_cap_in);
14270 vty_out(vty, " Total: %10u %10u\n",
14271 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14272 }
14273
14274 if (use_json) {
14275 /* advertisement-interval */
14276 json_object_int_add(json_neigh,
14277 "minBtwnAdvertisementRunsTimerMsecs",
14278 p->v_routeadv * 1000);
14279
14280 /* Update-source. */
14281 if (p->update_if || p->update_source) {
14282 if (p->update_if)
14283 json_object_string_add(json_neigh,
14284 "updateSource",
14285 p->update_if);
14286 else if (p->update_source)
14287 json_object_string_addf(json_neigh,
14288 "updateSource", "%pSU",
14289 p->update_source);
14290 }
14291 } else {
14292 /* advertisement-interval */
14293 vty_out(vty,
14294 " Minimum time between advertisement runs is %d seconds\n",
14295 p->v_routeadv);
14296
14297 /* Update-source. */
14298 if (p->update_if || p->update_source) {
14299 vty_out(vty, " Update source is ");
14300 if (p->update_if)
14301 vty_out(vty, "%s", p->update_if);
14302 else if (p->update_source)
14303 vty_out(vty, "%pSU", p->update_source);
14304 vty_out(vty, "\n");
14305 }
14306
14307 vty_out(vty, "\n");
14308 }
14309
14310 /* Address Family Information */
14311 json_object *json_hold = NULL;
14312
14313 if (use_json)
14314 json_hold = json_object_new_object();
14315
14316 FOREACH_AFI_SAFI (afi, safi)
14317 if (p->afc[afi][safi])
14318 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14319 json_hold);
14320
14321 if (use_json) {
14322 json_object_object_add(json_neigh, "addressFamilyInfo",
14323 json_hold);
14324 json_object_int_add(json_neigh, "connectionsEstablished",
14325 p->established);
14326 json_object_int_add(json_neigh, "connectionsDropped",
14327 p->dropped);
14328 } else
14329 vty_out(vty, " Connections established %d; dropped %d\n",
14330 p->established, p->dropped);
14331
14332 if (!p->last_reset) {
14333 if (use_json)
14334 json_object_string_add(json_neigh, "lastReset",
14335 "never");
14336 else
14337 vty_out(vty, " Last reset never\n");
14338 } else {
14339 if (use_json) {
14340 time_t uptime;
14341 struct tm tm;
14342
14343 uptime = monotime(NULL);
14344 uptime -= p->resettime;
14345 gmtime_r(&uptime, &tm);
14346
14347 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14348 (tm.tm_sec * 1000)
14349 + (tm.tm_min * 60000)
14350 + (tm.tm_hour * 3600000));
14351 bgp_show_peer_reset(NULL, p, json_neigh, true);
14352 } else {
14353 vty_out(vty, " Last reset %s, ",
14354 peer_uptime(p->resettime, timebuf,
14355 BGP_UPTIME_LEN, 0, NULL));
14356
14357 bgp_show_peer_reset(vty, p, NULL, false);
14358 if (p->last_reset_cause_size) {
14359 msg = p->last_reset_cause;
14360 vty_out(vty,
14361 " Message received that caused BGP to send a NOTIFICATION:\n ");
14362 for (i = 1; i <= p->last_reset_cause_size;
14363 i++) {
14364 vty_out(vty, "%02X", *msg++);
14365
14366 if (i != p->last_reset_cause_size) {
14367 if (i % 16 == 0) {
14368 vty_out(vty, "\n ");
14369 } else if (i % 4 == 0) {
14370 vty_out(vty, " ");
14371 }
14372 }
14373 }
14374 vty_out(vty, "\n");
14375 }
14376 }
14377 }
14378
14379 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14380 if (use_json)
14381 json_object_boolean_true_add(json_neigh,
14382 "prefixesConfigExceedMax");
14383 else
14384 vty_out(vty,
14385 " Peer had exceeded the max. no. of prefixes configured.\n");
14386
14387 if (p->t_pmax_restart) {
14388 if (use_json) {
14389 json_object_boolean_true_add(
14390 json_neigh, "reducePrefixNumFrom");
14391 json_object_int_add(json_neigh,
14392 "restartInTimerMsec",
14393 thread_timer_remain_second(
14394 p->t_pmax_restart)
14395 * 1000);
14396 } else
14397 vty_out(vty,
14398 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14399 p->host, thread_timer_remain_second(
14400 p->t_pmax_restart));
14401 } else {
14402 if (use_json)
14403 json_object_boolean_true_add(
14404 json_neigh,
14405 "reducePrefixNumAndClearIpBgp");
14406 else
14407 vty_out(vty,
14408 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14409 p->host);
14410 }
14411 }
14412
14413 /* EBGP Multihop and GTSM */
14414 if (p->sort != BGP_PEER_IBGP) {
14415 if (use_json) {
14416 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14417 json_object_int_add(json_neigh,
14418 "externalBgpNbrMaxHopsAway",
14419 p->gtsm_hops);
14420 else
14421 json_object_int_add(json_neigh,
14422 "externalBgpNbrMaxHopsAway",
14423 p->ttl);
14424 } else {
14425 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14426 vty_out(vty,
14427 " External BGP neighbor may be up to %d hops away.\n",
14428 p->gtsm_hops);
14429 else
14430 vty_out(vty,
14431 " External BGP neighbor may be up to %d hops away.\n",
14432 p->ttl);
14433 }
14434 } else {
14435 if (use_json) {
14436 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14437 json_object_int_add(json_neigh,
14438 "internalBgpNbrMaxHopsAway",
14439 p->gtsm_hops);
14440 else
14441 json_object_int_add(json_neigh,
14442 "internalBgpNbrMaxHopsAway",
14443 p->ttl);
14444 } else {
14445 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14446 vty_out(vty,
14447 " Internal BGP neighbor may be up to %d hops away.\n",
14448 p->gtsm_hops);
14449 else
14450 vty_out(vty,
14451 " Internal BGP neighbor may be up to %d hops away.\n",
14452 p->ttl);
14453 }
14454 }
14455
14456 /* Local address. */
14457 if (p->su_local) {
14458 if (use_json) {
14459 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14460 p->su_local);
14461 json_object_int_add(json_neigh, "portLocal",
14462 ntohs(p->su_local->sin.sin_port));
14463 } else
14464 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14465 p->su_local, ntohs(p->su_local->sin.sin_port));
14466 } else {
14467 if (use_json) {
14468 json_object_string_add(json_neigh, "hostLocal",
14469 "Unknown");
14470 json_object_int_add(json_neigh, "portLocal", -1);
14471 }
14472 }
14473
14474 /* Remote address. */
14475 if (p->su_remote) {
14476 if (use_json) {
14477 json_object_string_addf(json_neigh, "hostForeign",
14478 "%pSU", p->su_remote);
14479 json_object_int_add(json_neigh, "portForeign",
14480 ntohs(p->su_remote->sin.sin_port));
14481 } else
14482 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14483 p->su_remote,
14484 ntohs(p->su_remote->sin.sin_port));
14485 } else {
14486 if (use_json) {
14487 json_object_string_add(json_neigh, "hostForeign",
14488 "Unknown");
14489 json_object_int_add(json_neigh, "portForeign", -1);
14490 }
14491 }
14492
14493 /* Nexthop display. */
14494 if (p->su_local) {
14495 if (use_json) {
14496 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14497 &p->nexthop.v4);
14498 json_object_string_addf(json_neigh, "nexthopGlobal",
14499 "%pI6", &p->nexthop.v6_global);
14500 json_object_string_addf(json_neigh, "nexthopLocal",
14501 "%pI6", &p->nexthop.v6_local);
14502 if (p->shared_network)
14503 json_object_string_add(json_neigh,
14504 "bgpConnection",
14505 "sharedNetwork");
14506 else
14507 json_object_string_add(json_neigh,
14508 "bgpConnection",
14509 "nonSharedNetwork");
14510 } else {
14511 vty_out(vty, "Nexthop: %s\n",
14512 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14513 sizeof(buf1)));
14514 vty_out(vty, "Nexthop global: %s\n",
14515 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14516 sizeof(buf1)));
14517 vty_out(vty, "Nexthop local: %s\n",
14518 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14519 sizeof(buf1)));
14520 vty_out(vty, "BGP connection: %s\n",
14521 p->shared_network ? "shared network"
14522 : "non shared network");
14523 }
14524 }
14525
14526 /* Timer information. */
14527 if (use_json) {
14528 json_object_int_add(json_neigh, "connectRetryTimer",
14529 p->v_connect);
14530 if (peer_established(p) && p->rtt)
14531 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14532 p->rtt);
14533 if (p->t_start)
14534 json_object_int_add(
14535 json_neigh, "nextStartTimerDueInMsecs",
14536 thread_timer_remain_second(p->t_start) * 1000);
14537 if (p->t_connect)
14538 json_object_int_add(
14539 json_neigh, "nextConnectTimerDueInMsecs",
14540 thread_timer_remain_second(p->t_connect)
14541 * 1000);
14542 if (p->t_routeadv) {
14543 json_object_int_add(json_neigh, "mraiInterval",
14544 p->v_routeadv);
14545 json_object_int_add(
14546 json_neigh, "mraiTimerExpireInMsecs",
14547 thread_timer_remain_second(p->t_routeadv)
14548 * 1000);
14549 }
14550 if (p->password)
14551 json_object_int_add(json_neigh, "authenticationEnabled",
14552 1);
14553
14554 if (p->t_read)
14555 json_object_string_add(json_neigh, "readThread", "on");
14556 else
14557 json_object_string_add(json_neigh, "readThread", "off");
14558
14559 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14560 json_object_string_add(json_neigh, "writeThread", "on");
14561 else
14562 json_object_string_add(json_neigh, "writeThread",
14563 "off");
14564 } else {
14565 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14566 p->v_connect);
14567 if (peer_established(p) && p->rtt)
14568 vty_out(vty, "Estimated round trip time: %d ms\n",
14569 p->rtt);
14570 if (p->t_start)
14571 vty_out(vty, "Next start timer due in %ld seconds\n",
14572 thread_timer_remain_second(p->t_start));
14573 if (p->t_connect)
14574 vty_out(vty, "Next connect timer due in %ld seconds\n",
14575 thread_timer_remain_second(p->t_connect));
14576 if (p->t_routeadv)
14577 vty_out(vty,
14578 "MRAI (interval %u) timer expires in %ld seconds\n",
14579 p->v_routeadv,
14580 thread_timer_remain_second(p->t_routeadv));
14581 if (p->password)
14582 vty_out(vty, "Peer Authentication Enabled\n");
14583
14584 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14585 p->t_read ? "on" : "off",
14586 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14587 ? "on"
14588 : "off", p->fd);
14589 }
14590
14591 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14592 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14593 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14594
14595 if (!use_json)
14596 vty_out(vty, "\n");
14597
14598 /* BFD information. */
14599 if (p->bfd_config)
14600 bgp_bfd_show_info(vty, p, json_neigh);
14601
14602 if (use_json) {
14603 if (p->conf_if) /* Configured interface name. */
14604 json_object_object_add(json, p->conf_if, json_neigh);
14605 else /* Configured IP address. */
14606 json_object_object_add(json, p->host, json_neigh);
14607 }
14608 }
14609
14610 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14611 enum show_type type,
14612 union sockunion *su,
14613 const char *conf_if, afi_t afi,
14614 bool use_json)
14615 {
14616 struct listnode *node, *nnode;
14617 struct peer *peer;
14618 int find = 0;
14619 safi_t safi = SAFI_UNICAST;
14620 json_object *json = NULL;
14621 json_object *json_neighbor = NULL;
14622
14623 if (use_json) {
14624 json = json_object_new_object();
14625 json_neighbor = json_object_new_object();
14626 }
14627
14628 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14629
14630 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14631 continue;
14632
14633 if ((peer->afc[afi][safi]) == 0)
14634 continue;
14635
14636 if (type == show_all) {
14637 bgp_show_peer_gr_status(vty, peer, use_json,
14638 json_neighbor);
14639
14640 if (use_json) {
14641 json_object_object_add(json, peer->host,
14642 json_neighbor);
14643 json_neighbor = NULL;
14644 }
14645
14646 } else if (type == show_peer) {
14647 if (conf_if) {
14648 if ((peer->conf_if
14649 && !strcmp(peer->conf_if, conf_if))
14650 || (peer->hostname
14651 && !strcmp(peer->hostname, conf_if))) {
14652 find = 1;
14653 bgp_show_peer_gr_status(vty, peer,
14654 use_json,
14655 json_neighbor);
14656 }
14657 } else {
14658 if (sockunion_same(&peer->su, su)) {
14659 find = 1;
14660 bgp_show_peer_gr_status(vty, peer,
14661 use_json,
14662 json_neighbor);
14663 }
14664 }
14665 if (use_json && find)
14666 json_object_object_add(json, peer->host,
14667 json_neighbor);
14668 }
14669
14670 if (find) {
14671 json_neighbor = NULL;
14672 break;
14673 }
14674 }
14675
14676 if (type == show_peer && !find) {
14677 if (use_json)
14678 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14679 else
14680 vty_out(vty, "%% No such neighbor\n");
14681 }
14682 if (use_json) {
14683 if (json_neighbor)
14684 json_object_free(json_neighbor);
14685 vty_json(vty, json);
14686 } else {
14687 vty_out(vty, "\n");
14688 }
14689
14690 return CMD_SUCCESS;
14691 }
14692
14693 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14694 enum show_type type, union sockunion *su,
14695 const char *conf_if, bool use_json,
14696 json_object *json)
14697 {
14698 struct listnode *node, *nnode;
14699 struct peer *peer;
14700 int find = 0;
14701 bool nbr_output = false;
14702 afi_t afi = AFI_MAX;
14703 safi_t safi = SAFI_MAX;
14704
14705 if (type == show_ipv4_peer || type == show_ipv4_all) {
14706 afi = AFI_IP;
14707 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14708 afi = AFI_IP6;
14709 }
14710
14711 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14712 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14713 continue;
14714
14715 switch (type) {
14716 case show_all:
14717 bgp_show_peer(vty, peer, use_json, json);
14718 nbr_output = true;
14719 break;
14720 case show_peer:
14721 if (conf_if) {
14722 if ((peer->conf_if
14723 && !strcmp(peer->conf_if, conf_if))
14724 || (peer->hostname
14725 && !strcmp(peer->hostname, conf_if))) {
14726 find = 1;
14727 bgp_show_peer(vty, peer, use_json,
14728 json);
14729 }
14730 } else {
14731 if (sockunion_same(&peer->su, su)) {
14732 find = 1;
14733 bgp_show_peer(vty, peer, use_json,
14734 json);
14735 }
14736 }
14737 break;
14738 case show_ipv4_peer:
14739 case show_ipv6_peer:
14740 FOREACH_SAFI (safi) {
14741 if (peer->afc[afi][safi]) {
14742 if (conf_if) {
14743 if ((peer->conf_if
14744 && !strcmp(peer->conf_if, conf_if))
14745 || (peer->hostname
14746 && !strcmp(peer->hostname, conf_if))) {
14747 find = 1;
14748 bgp_show_peer(vty, peer, use_json,
14749 json);
14750 break;
14751 }
14752 } else {
14753 if (sockunion_same(&peer->su, su)) {
14754 find = 1;
14755 bgp_show_peer(vty, peer, use_json,
14756 json);
14757 break;
14758 }
14759 }
14760 }
14761 }
14762 break;
14763 case show_ipv4_all:
14764 case show_ipv6_all:
14765 FOREACH_SAFI (safi) {
14766 if (peer->afc[afi][safi]) {
14767 bgp_show_peer(vty, peer, use_json, json);
14768 nbr_output = true;
14769 break;
14770 }
14771 }
14772 break;
14773 }
14774 }
14775
14776 if ((type == show_peer || type == show_ipv4_peer ||
14777 type == show_ipv6_peer) && !find) {
14778 if (use_json)
14779 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14780 else
14781 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14782 }
14783
14784 if (type != show_peer && type != show_ipv4_peer &&
14785 type != show_ipv6_peer && !nbr_output && !use_json)
14786 vty_out(vty, "%% No BGP neighbors found\n");
14787
14788 if (use_json) {
14789 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14790 json, JSON_C_TO_STRING_PRETTY));
14791 } else {
14792 vty_out(vty, "\n");
14793 }
14794
14795 return CMD_SUCCESS;
14796 }
14797
14798 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14799 enum show_type type,
14800 const char *ip_str,
14801 afi_t afi, bool use_json)
14802 {
14803
14804 int ret;
14805 struct bgp *bgp;
14806 union sockunion su;
14807
14808 bgp = bgp_get_default();
14809
14810 if (!bgp)
14811 return;
14812
14813 if (!use_json)
14814 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14815 NULL);
14816
14817 if (ip_str) {
14818 ret = str2sockunion(ip_str, &su);
14819 if (ret < 0)
14820 bgp_show_neighbor_graceful_restart(
14821 vty, bgp, type, NULL, ip_str, afi, use_json);
14822 else
14823 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14824 NULL, afi, use_json);
14825 } else
14826 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14827 afi, use_json);
14828 }
14829
14830 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14831 enum show_type type,
14832 const char *ip_str,
14833 bool use_json)
14834 {
14835 struct listnode *node, *nnode;
14836 struct bgp *bgp;
14837 union sockunion su;
14838 json_object *json = NULL;
14839 int ret, is_first = 1;
14840 bool nbr_output = false;
14841
14842 if (use_json)
14843 vty_out(vty, "{\n");
14844
14845 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14846 nbr_output = true;
14847 if (use_json) {
14848 if (!(json = json_object_new_object())) {
14849 flog_err(
14850 EC_BGP_JSON_MEM_ERROR,
14851 "Unable to allocate memory for JSON object");
14852 vty_out(vty,
14853 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14854 return;
14855 }
14856
14857 json_object_int_add(json, "vrfId",
14858 (bgp->vrf_id == VRF_UNKNOWN)
14859 ? -1
14860 : (int64_t)bgp->vrf_id);
14861 json_object_string_add(
14862 json, "vrfName",
14863 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14864 ? VRF_DEFAULT_NAME
14865 : bgp->name);
14866
14867 if (!is_first)
14868 vty_out(vty, ",\n");
14869 else
14870 is_first = 0;
14871
14872 vty_out(vty, "\"%s\":",
14873 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14874 ? VRF_DEFAULT_NAME
14875 : bgp->name);
14876 } else {
14877 vty_out(vty, "\nInstance %s:\n",
14878 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14879 ? VRF_DEFAULT_NAME
14880 : bgp->name);
14881 }
14882
14883 if (type == show_peer || type == show_ipv4_peer ||
14884 type == show_ipv6_peer) {
14885 ret = str2sockunion(ip_str, &su);
14886 if (ret < 0)
14887 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14888 use_json, json);
14889 else
14890 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14891 use_json, json);
14892 } else {
14893 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14894 use_json, json);
14895 }
14896 json_object_free(json);
14897 json = NULL;
14898 }
14899
14900 if (use_json)
14901 vty_out(vty, "}\n");
14902 else if (!nbr_output)
14903 vty_out(vty, "%% BGP instance not found\n");
14904 }
14905
14906 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14907 enum show_type type, const char *ip_str,
14908 bool use_json)
14909 {
14910 int ret;
14911 struct bgp *bgp;
14912 union sockunion su;
14913 json_object *json = NULL;
14914
14915 if (name) {
14916 if (strmatch(name, "all")) {
14917 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14918 use_json);
14919 return CMD_SUCCESS;
14920 } else {
14921 bgp = bgp_lookup_by_name(name);
14922 if (!bgp) {
14923 if (use_json) {
14924 json = json_object_new_object();
14925 vty_json(vty, json);
14926 } else
14927 vty_out(vty,
14928 "%% BGP instance not found\n");
14929
14930 return CMD_WARNING;
14931 }
14932 }
14933 } else {
14934 bgp = bgp_get_default();
14935 }
14936
14937 if (bgp) {
14938 json = json_object_new_object();
14939 if (ip_str) {
14940 ret = str2sockunion(ip_str, &su);
14941 if (ret < 0)
14942 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14943 use_json, json);
14944 else
14945 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14946 use_json, json);
14947 } else {
14948 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14949 json);
14950 }
14951 json_object_free(json);
14952 } else {
14953 if (use_json)
14954 vty_out(vty, "{}\n");
14955 else
14956 vty_out(vty, "%% BGP instance not found\n");
14957 }
14958
14959 return CMD_SUCCESS;
14960 }
14961
14962
14963
14964 /* "show [ip] bgp neighbors graceful-restart" commands. */
14965 DEFUN (show_ip_bgp_neighbors_graceful_restart,
14966 show_ip_bgp_neighbors_graceful_restart_cmd,
14967 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14968 SHOW_STR
14969 BGP_STR
14970 IP_STR
14971 IPV6_STR
14972 NEIGHBOR_STR
14973 "Neighbor to display information about\n"
14974 "Neighbor to display information about\n"
14975 "Neighbor on BGP configured interface\n"
14976 GR_SHOW
14977 JSON_STR)
14978 {
14979 char *sh_arg = NULL;
14980 enum show_type sh_type;
14981 int idx = 0;
14982 afi_t afi = AFI_MAX;
14983 bool uj = use_json(argc, argv);
14984
14985 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14986 afi = AFI_MAX;
14987
14988 idx++;
14989
14990 if (argv_find(argv, argc, "A.B.C.D", &idx)
14991 || argv_find(argv, argc, "X:X::X:X", &idx)
14992 || argv_find(argv, argc, "WORD", &idx)) {
14993 sh_type = show_peer;
14994 sh_arg = argv[idx]->arg;
14995 } else
14996 sh_type = show_all;
14997
14998 if (!argv_find(argv, argc, "graceful-restart", &idx))
14999 return CMD_SUCCESS;
15000
15001
15002 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15003 afi, uj);
15004 }
15005
15006 /* "show [ip] bgp neighbors" commands. */
15007 DEFUN (show_ip_bgp_neighbors,
15008 show_ip_bgp_neighbors_cmd,
15009 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15010 SHOW_STR
15011 IP_STR
15012 BGP_STR
15013 BGP_INSTANCE_HELP_STR
15014 BGP_AF_STR
15015 BGP_AF_STR
15016 "Detailed information on TCP and BGP neighbor connections\n"
15017 "Neighbor to display information about\n"
15018 "Neighbor to display information about\n"
15019 "Neighbor on BGP configured interface\n"
15020 JSON_STR)
15021 {
15022 char *vrf = NULL;
15023 char *sh_arg = NULL;
15024 enum show_type sh_type;
15025 afi_t afi = AFI_MAX;
15026
15027 bool uj = use_json(argc, argv);
15028
15029 int idx = 0;
15030
15031 /* [<vrf> VIEWVRFNAME] */
15032 if (argv_find(argv, argc, "vrf", &idx)) {
15033 vrf = argv[idx + 1]->arg;
15034 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15035 vrf = NULL;
15036 } else if (argv_find(argv, argc, "view", &idx))
15037 /* [<view> VIEWVRFNAME] */
15038 vrf = argv[idx + 1]->arg;
15039
15040 idx++;
15041
15042 if (argv_find(argv, argc, "ipv4", &idx)) {
15043 sh_type = show_ipv4_all;
15044 afi = AFI_IP;
15045 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15046 sh_type = show_ipv6_all;
15047 afi = AFI_IP6;
15048 } else {
15049 sh_type = show_all;
15050 }
15051
15052 if (argv_find(argv, argc, "A.B.C.D", &idx)
15053 || argv_find(argv, argc, "X:X::X:X", &idx)
15054 || argv_find(argv, argc, "WORD", &idx)) {
15055 sh_type = show_peer;
15056 sh_arg = argv[idx]->arg;
15057 }
15058
15059 if (sh_type == show_peer && afi == AFI_IP) {
15060 sh_type = show_ipv4_peer;
15061 } else if (sh_type == show_peer && afi == AFI_IP6) {
15062 sh_type = show_ipv6_peer;
15063 }
15064
15065 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15066 }
15067
15068 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15069 paths' and `show ip mbgp paths'. Those functions results are the
15070 same.*/
15071 DEFUN (show_ip_bgp_paths,
15072 show_ip_bgp_paths_cmd,
15073 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15074 SHOW_STR
15075 IP_STR
15076 BGP_STR
15077 BGP_SAFI_HELP_STR
15078 "Path information\n")
15079 {
15080 vty_out(vty, "Address Refcnt Path\n");
15081 aspath_print_all_vty(vty);
15082 return CMD_SUCCESS;
15083 }
15084
15085 #include "hash.h"
15086
15087 static void community_show_all_iterator(struct hash_bucket *bucket,
15088 struct vty *vty)
15089 {
15090 struct community *com;
15091
15092 com = (struct community *)bucket->data;
15093 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15094 community_str(com, false, false));
15095 }
15096
15097 /* Show BGP's community internal data. */
15098 DEFUN (show_ip_bgp_community_info,
15099 show_ip_bgp_community_info_cmd,
15100 "show [ip] bgp community-info",
15101 SHOW_STR
15102 IP_STR
15103 BGP_STR
15104 "List all bgp community information\n")
15105 {
15106 vty_out(vty, "Address Refcnt Community\n");
15107
15108 hash_iterate(community_hash(),
15109 (void (*)(struct hash_bucket *,
15110 void *))community_show_all_iterator,
15111 vty);
15112
15113 return CMD_SUCCESS;
15114 }
15115
15116 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15117 struct vty *vty)
15118 {
15119 struct lcommunity *lcom;
15120
15121 lcom = (struct lcommunity *)bucket->data;
15122 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15123 lcommunity_str(lcom, false, false));
15124 }
15125
15126 /* Show BGP's community internal data. */
15127 DEFUN (show_ip_bgp_lcommunity_info,
15128 show_ip_bgp_lcommunity_info_cmd,
15129 "show ip bgp large-community-info",
15130 SHOW_STR
15131 IP_STR
15132 BGP_STR
15133 "List all bgp large-community information\n")
15134 {
15135 vty_out(vty, "Address Refcnt Large-community\n");
15136
15137 hash_iterate(lcommunity_hash(),
15138 (void (*)(struct hash_bucket *,
15139 void *))lcommunity_show_all_iterator,
15140 vty);
15141
15142 return CMD_SUCCESS;
15143 }
15144 /* Graceful Restart */
15145
15146 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15147 struct bgp *bgp,
15148 bool use_json,
15149 json_object *json)
15150 {
15151
15152
15153 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15154
15155 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15156
15157 switch (bgp_global_gr_mode) {
15158
15159 case GLOBAL_HELPER:
15160 vty_out(vty, "Global BGP GR Mode : Helper\n");
15161 break;
15162
15163 case GLOBAL_GR:
15164 vty_out(vty, "Global BGP GR Mode : Restart\n");
15165 break;
15166
15167 case GLOBAL_DISABLE:
15168 vty_out(vty, "Global BGP GR Mode : Disable\n");
15169 break;
15170
15171 case GLOBAL_INVALID:
15172 vty_out(vty,
15173 "Global BGP GR Mode Invalid\n");
15174 break;
15175 }
15176 vty_out(vty, "\n");
15177 }
15178
15179 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15180 enum show_type type,
15181 const char *ip_str,
15182 afi_t afi, bool use_json)
15183 {
15184 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15185 afi = AFI_IP;
15186
15187 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15188
15189 bgp_show_neighbor_graceful_restart_vty(
15190 vty, type, ip_str, afi, use_json);
15191 afi++;
15192 }
15193 } else if (afi != AFI_MAX) {
15194 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15195 use_json);
15196 } else {
15197 return CMD_ERR_INCOMPLETE;
15198 }
15199
15200 return CMD_SUCCESS;
15201 }
15202 /* Graceful Restart */
15203
15204 DEFUN (show_ip_bgp_attr_info,
15205 show_ip_bgp_attr_info_cmd,
15206 "show [ip] bgp attribute-info",
15207 SHOW_STR
15208 IP_STR
15209 BGP_STR
15210 "List all bgp attribute information\n")
15211 {
15212 attr_show_all(vty);
15213 return CMD_SUCCESS;
15214 }
15215
15216 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15217 afi_t afi, safi_t safi,
15218 bool use_json, json_object *json)
15219 {
15220 struct bgp *bgp;
15221 struct listnode *node;
15222 char *vname;
15223 char *ecom_str;
15224 enum vpn_policy_direction dir;
15225
15226 if (json) {
15227 json_object *json_import_vrfs = NULL;
15228 json_object *json_export_vrfs = NULL;
15229
15230 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15231
15232 if (!bgp) {
15233 vty_json(vty, json);
15234
15235 return CMD_WARNING;
15236 }
15237
15238 /* Provide context for the block */
15239 json_object_string_add(json, "vrf", name ? name : "default");
15240 json_object_string_add(json, "afiSafi",
15241 get_afi_safi_str(afi, safi, true));
15242
15243 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15244 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15245 json_object_string_add(json, "importFromVrfs", "none");
15246 json_object_string_add(json, "importRts", "none");
15247 } else {
15248 json_import_vrfs = json_object_new_array();
15249
15250 for (ALL_LIST_ELEMENTS_RO(
15251 bgp->vpn_policy[afi].import_vrf,
15252 node, vname))
15253 json_object_array_add(json_import_vrfs,
15254 json_object_new_string(vname));
15255
15256 json_object_object_add(json, "importFromVrfs",
15257 json_import_vrfs);
15258 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15259 if (bgp->vpn_policy[afi].rtlist[dir]) {
15260 ecom_str = ecommunity_ecom2str(
15261 bgp->vpn_policy[afi].rtlist[dir],
15262 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15263 json_object_string_add(json, "importRts",
15264 ecom_str);
15265 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15266 } else
15267 json_object_string_add(json, "importRts",
15268 "none");
15269 }
15270
15271 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15272 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15273 json_object_string_add(json, "exportToVrfs", "none");
15274 json_object_string_add(json, "routeDistinguisher",
15275 "none");
15276 json_object_string_add(json, "exportRts", "none");
15277 } else {
15278 json_export_vrfs = json_object_new_array();
15279
15280 for (ALL_LIST_ELEMENTS_RO(
15281 bgp->vpn_policy[afi].export_vrf,
15282 node, vname))
15283 json_object_array_add(json_export_vrfs,
15284 json_object_new_string(vname));
15285 json_object_object_add(json, "exportToVrfs",
15286 json_export_vrfs);
15287 json_object_string_addf(json, "routeDistinguisher",
15288 "%pRD",
15289 &bgp->vpn_policy[afi].tovpn_rd);
15290
15291 dir = BGP_VPN_POLICY_DIR_TOVPN;
15292 if (bgp->vpn_policy[afi].rtlist[dir]) {
15293 ecom_str = ecommunity_ecom2str(
15294 bgp->vpn_policy[afi].rtlist[dir],
15295 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15296 json_object_string_add(json, "exportRts",
15297 ecom_str);
15298 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15299 } else
15300 json_object_string_add(json, "exportRts",
15301 "none");
15302 }
15303
15304 if (use_json) {
15305 vty_json(vty, json);
15306 }
15307 } else {
15308 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15309
15310 if (!bgp) {
15311 vty_out(vty, "%% No such BGP instance exist\n");
15312 return CMD_WARNING;
15313 }
15314
15315 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15316 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15317 vty_out(vty,
15318 "This VRF is not importing %s routes from any other VRF\n",
15319 get_afi_safi_str(afi, safi, false));
15320 else {
15321 vty_out(vty,
15322 "This VRF is importing %s routes from the following VRFs:\n",
15323 get_afi_safi_str(afi, safi, false));
15324
15325 for (ALL_LIST_ELEMENTS_RO(
15326 bgp->vpn_policy[afi].import_vrf,
15327 node, vname))
15328 vty_out(vty, " %s\n", vname);
15329
15330 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15331 ecom_str = NULL;
15332 if (bgp->vpn_policy[afi].rtlist[dir]) {
15333 ecom_str = ecommunity_ecom2str(
15334 bgp->vpn_policy[afi].rtlist[dir],
15335 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15336 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15337
15338 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15339 } else
15340 vty_out(vty, "Import RT(s):\n");
15341 }
15342
15343 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15344 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15345 vty_out(vty,
15346 "This VRF is not exporting %s routes to any other VRF\n",
15347 get_afi_safi_str(afi, safi, false));
15348 else {
15349 vty_out(vty,
15350 "This VRF is exporting %s routes to the following VRFs:\n",
15351 get_afi_safi_str(afi, safi, false));
15352
15353 for (ALL_LIST_ELEMENTS_RO(
15354 bgp->vpn_policy[afi].export_vrf,
15355 node, vname))
15356 vty_out(vty, " %s\n", vname);
15357
15358 vty_out(vty, "RD: %pRD\n",
15359 &bgp->vpn_policy[afi].tovpn_rd);
15360
15361 dir = BGP_VPN_POLICY_DIR_TOVPN;
15362 if (bgp->vpn_policy[afi].rtlist[dir]) {
15363 ecom_str = ecommunity_ecom2str(
15364 bgp->vpn_policy[afi].rtlist[dir],
15365 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15366 vty_out(vty, "Export RT: %s\n", ecom_str);
15367 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15368 } else
15369 vty_out(vty, "Import RT(s):\n");
15370 }
15371 }
15372
15373 return CMD_SUCCESS;
15374 }
15375
15376 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15377 safi_t safi, bool use_json)
15378 {
15379 struct listnode *node, *nnode;
15380 struct bgp *bgp;
15381 char *vrf_name = NULL;
15382 json_object *json = NULL;
15383 json_object *json_vrf = NULL;
15384 json_object *json_vrfs = NULL;
15385
15386 if (use_json) {
15387 json = json_object_new_object();
15388 json_vrfs = json_object_new_object();
15389 }
15390
15391 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15392
15393 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15394 vrf_name = bgp->name;
15395
15396 if (use_json) {
15397 json_vrf = json_object_new_object();
15398 } else {
15399 vty_out(vty, "\nInstance %s:\n",
15400 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15401 ? VRF_DEFAULT_NAME : bgp->name);
15402 }
15403 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15404 if (use_json) {
15405 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15406 json_object_object_add(json_vrfs,
15407 VRF_DEFAULT_NAME, json_vrf);
15408 else
15409 json_object_object_add(json_vrfs, vrf_name,
15410 json_vrf);
15411 }
15412 }
15413
15414 if (use_json) {
15415 json_object_object_add(json, "vrfs", json_vrfs);
15416 vty_json(vty, json);
15417 }
15418
15419 return CMD_SUCCESS;
15420 }
15421
15422 /* "show [ip] bgp route-leak" command. */
15423 DEFUN (show_ip_bgp_route_leak,
15424 show_ip_bgp_route_leak_cmd,
15425 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15426 SHOW_STR
15427 IP_STR
15428 BGP_STR
15429 BGP_INSTANCE_HELP_STR
15430 BGP_AFI_HELP_STR
15431 BGP_SAFI_HELP_STR
15432 "Route leaking information\n"
15433 JSON_STR)
15434 {
15435 char *vrf = NULL;
15436 afi_t afi = AFI_MAX;
15437 safi_t safi = SAFI_MAX;
15438
15439 bool uj = use_json(argc, argv);
15440 int idx = 0;
15441 json_object *json = NULL;
15442
15443 /* show [ip] bgp */
15444 if (argv_find(argv, argc, "ip", &idx)) {
15445 afi = AFI_IP;
15446 safi = SAFI_UNICAST;
15447 }
15448 /* [vrf VIEWVRFNAME] */
15449 if (argv_find(argv, argc, "view", &idx)) {
15450 vty_out(vty,
15451 "%% This command is not applicable to BGP views\n");
15452 return CMD_WARNING;
15453 }
15454
15455 if (argv_find(argv, argc, "vrf", &idx)) {
15456 vrf = argv[idx + 1]->arg;
15457 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15458 vrf = NULL;
15459 }
15460 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15461 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15462 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15463
15464 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15465 vty_out(vty,
15466 "%% This command is applicable only for unicast ipv4|ipv6\n");
15467 return CMD_WARNING;
15468 }
15469
15470 if (vrf && strmatch(vrf, "all"))
15471 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15472
15473 if (uj)
15474 json = json_object_new_object();
15475
15476 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15477 }
15478
15479 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15480 safi_t safi)
15481 {
15482 struct listnode *node, *nnode;
15483 struct bgp *bgp;
15484
15485 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15486 vty_out(vty, "\nInstance %s:\n",
15487 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15488 ? VRF_DEFAULT_NAME
15489 : bgp->name);
15490 update_group_show(bgp, afi, safi, vty, 0);
15491 }
15492 }
15493
15494 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15495 int safi, uint64_t subgrp_id)
15496 {
15497 struct bgp *bgp;
15498
15499 if (name) {
15500 if (strmatch(name, "all")) {
15501 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15502 return CMD_SUCCESS;
15503 } else {
15504 bgp = bgp_lookup_by_name(name);
15505 }
15506 } else {
15507 bgp = bgp_get_default();
15508 }
15509
15510 if (bgp)
15511 update_group_show(bgp, afi, safi, vty, subgrp_id);
15512 return CMD_SUCCESS;
15513 }
15514
15515 DEFUN (show_ip_bgp_updgrps,
15516 show_ip_bgp_updgrps_cmd,
15517 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15518 SHOW_STR
15519 IP_STR
15520 BGP_STR
15521 BGP_INSTANCE_HELP_STR
15522 BGP_AFI_HELP_STR
15523 BGP_SAFI_WITH_LABEL_HELP_STR
15524 "Detailed info about dynamic update groups\n"
15525 "Specific subgroup to display detailed info for\n")
15526 {
15527 char *vrf = NULL;
15528 afi_t afi = AFI_IP6;
15529 safi_t safi = SAFI_UNICAST;
15530 uint64_t subgrp_id = 0;
15531
15532 int idx = 0;
15533
15534 /* show [ip] bgp */
15535 if (argv_find(argv, argc, "ip", &idx))
15536 afi = AFI_IP;
15537 /* [<vrf> VIEWVRFNAME] */
15538 if (argv_find(argv, argc, "vrf", &idx)) {
15539 vrf = argv[idx + 1]->arg;
15540 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15541 vrf = NULL;
15542 } else if (argv_find(argv, argc, "view", &idx))
15543 /* [<view> VIEWVRFNAME] */
15544 vrf = argv[idx + 1]->arg;
15545 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15546 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15547 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15548 }
15549
15550 /* get subgroup id, if provided */
15551 idx = argc - 1;
15552 if (argv[idx]->type == VARIABLE_TKN)
15553 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15554
15555 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15556 }
15557
15558 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15559 show_bgp_instance_all_ipv6_updgrps_cmd,
15560 "show [ip] bgp <view|vrf> all update-groups",
15561 SHOW_STR
15562 IP_STR
15563 BGP_STR
15564 BGP_INSTANCE_ALL_HELP_STR
15565 "Detailed info about dynamic update groups\n")
15566 {
15567 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15568 return CMD_SUCCESS;
15569 }
15570
15571 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15572 show_bgp_l2vpn_evpn_updgrps_cmd,
15573 "show [ip] bgp l2vpn evpn update-groups",
15574 SHOW_STR
15575 IP_STR
15576 BGP_STR
15577 "l2vpn address family\n"
15578 "evpn sub-address family\n"
15579 "Detailed info about dynamic update groups\n")
15580 {
15581 char *vrf = NULL;
15582 uint64_t subgrp_id = 0;
15583
15584 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15585 return CMD_SUCCESS;
15586 }
15587
15588 DEFUN (show_bgp_updgrps_stats,
15589 show_bgp_updgrps_stats_cmd,
15590 "show [ip] bgp update-groups statistics",
15591 SHOW_STR
15592 IP_STR
15593 BGP_STR
15594 "Detailed info about dynamic update groups\n"
15595 "Statistics\n")
15596 {
15597 struct bgp *bgp;
15598
15599 bgp = bgp_get_default();
15600 if (bgp)
15601 update_group_show_stats(bgp, vty);
15602
15603 return CMD_SUCCESS;
15604 }
15605
15606 DEFUN (show_bgp_instance_updgrps_stats,
15607 show_bgp_instance_updgrps_stats_cmd,
15608 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15609 SHOW_STR
15610 IP_STR
15611 BGP_STR
15612 BGP_INSTANCE_HELP_STR
15613 "Detailed info about dynamic update groups\n"
15614 "Statistics\n")
15615 {
15616 int idx_word = 3;
15617 struct bgp *bgp;
15618
15619 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15620 if (bgp)
15621 update_group_show_stats(bgp, vty);
15622
15623 return CMD_SUCCESS;
15624 }
15625
15626 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15627 afi_t afi, safi_t safi,
15628 const char *what, uint64_t subgrp_id)
15629 {
15630 struct bgp *bgp;
15631
15632 if (name)
15633 bgp = bgp_lookup_by_name(name);
15634 else
15635 bgp = bgp_get_default();
15636
15637 if (bgp) {
15638 if (!strcmp(what, "advertise-queue"))
15639 update_group_show_adj_queue(bgp, afi, safi, vty,
15640 subgrp_id);
15641 else if (!strcmp(what, "advertised-routes"))
15642 update_group_show_advertised(bgp, afi, safi, vty,
15643 subgrp_id);
15644 else if (!strcmp(what, "packet-queue"))
15645 update_group_show_packet_queue(bgp, afi, safi, vty,
15646 subgrp_id);
15647 }
15648 }
15649
15650 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15651 show_ip_bgp_instance_updgrps_adj_s_cmd,
15652 "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",
15653 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15654 BGP_SAFI_HELP_STR
15655 "Detailed info about dynamic update groups\n"
15656 "Specific subgroup to display info for\n"
15657 "Advertisement queue\n"
15658 "Announced routes\n"
15659 "Packet queue\n")
15660 {
15661 uint64_t subgrp_id = 0;
15662 afi_t afiz;
15663 safi_t safiz;
15664 if (sgid)
15665 subgrp_id = strtoull(sgid, NULL, 10);
15666
15667 if (!ip && !afi)
15668 afiz = AFI_IP6;
15669 if (!ip && afi)
15670 afiz = bgp_vty_afi_from_str(afi);
15671 if (ip && !afi)
15672 afiz = AFI_IP;
15673 if (ip && afi) {
15674 afiz = bgp_vty_afi_from_str(afi);
15675 if (afiz != AFI_IP)
15676 vty_out(vty,
15677 "%% Cannot specify both 'ip' and 'ipv6'\n");
15678 return CMD_WARNING;
15679 }
15680
15681 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15682
15683 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15684 return CMD_SUCCESS;
15685 }
15686
15687 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15688 json_object *json)
15689 {
15690 struct listnode *node, *nnode;
15691 struct prefix *range;
15692 struct peer *conf;
15693 struct peer *peer;
15694 afi_t afi;
15695 safi_t safi;
15696 const char *peer_status;
15697 int lr_count;
15698 int dynamic;
15699 bool af_cfgd;
15700 json_object *json_peer_group = NULL;
15701 json_object *json_peer_group_afc = NULL;
15702 json_object *json_peer_group_members = NULL;
15703 json_object *json_peer_group_dynamic = NULL;
15704 json_object *json_peer_group_dynamic_af = NULL;
15705 json_object *json_peer_group_ranges = NULL;
15706
15707 conf = group->conf;
15708
15709 if (json) {
15710 json_peer_group = json_object_new_object();
15711 json_peer_group_afc = json_object_new_array();
15712 }
15713
15714 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15715 if (json)
15716 json_object_int_add(json_peer_group, "remoteAs",
15717 conf->as);
15718 else
15719 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15720 group->name, conf->as);
15721 } else if (conf->as_type == AS_INTERNAL) {
15722 if (json)
15723 json_object_int_add(json_peer_group, "remoteAs",
15724 group->bgp->as);
15725 else
15726 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15727 group->name, group->bgp->as);
15728 } else {
15729 if (!json)
15730 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15731 }
15732
15733 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15734 if (json)
15735 json_object_string_add(json_peer_group, "type",
15736 "internal");
15737 else
15738 vty_out(vty, " Peer-group type is internal\n");
15739 } else {
15740 if (json)
15741 json_object_string_add(json_peer_group, "type",
15742 "external");
15743 else
15744 vty_out(vty, " Peer-group type is external\n");
15745 }
15746
15747 /* Display AFs configured. */
15748 if (!json)
15749 vty_out(vty, " Configured address-families:");
15750
15751 FOREACH_AFI_SAFI (afi, safi) {
15752 if (conf->afc[afi][safi]) {
15753 af_cfgd = true;
15754 if (json)
15755 json_object_array_add(
15756 json_peer_group_afc,
15757 json_object_new_string(get_afi_safi_str(
15758 afi, safi, false)));
15759 else
15760 vty_out(vty, " %s;",
15761 get_afi_safi_str(afi, safi, false));
15762 }
15763 }
15764
15765 if (json) {
15766 json_object_object_add(json_peer_group,
15767 "addressFamiliesConfigured",
15768 json_peer_group_afc);
15769 } else {
15770 if (!af_cfgd)
15771 vty_out(vty, " none\n");
15772 else
15773 vty_out(vty, "\n");
15774 }
15775
15776 /* Display listen ranges (for dynamic neighbors), if any */
15777 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15778 lr_count = listcount(group->listen_range[afi]);
15779 if (lr_count) {
15780 if (json) {
15781 if (!json_peer_group_dynamic)
15782 json_peer_group_dynamic =
15783 json_object_new_object();
15784
15785 json_peer_group_dynamic_af =
15786 json_object_new_object();
15787 json_peer_group_ranges =
15788 json_object_new_array();
15789 json_object_int_add(json_peer_group_dynamic_af,
15790 "count", lr_count);
15791 } else {
15792 vty_out(vty, " %d %s listen range(s)\n",
15793 lr_count, afi2str(afi));
15794 }
15795
15796 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15797 nnode, range)) {
15798 if (json) {
15799 char buf[BUFSIZ];
15800
15801 snprintfrr(buf, sizeof(buf), "%pFX",
15802 range);
15803
15804 json_object_array_add(
15805 json_peer_group_ranges,
15806 json_object_new_string(buf));
15807 } else {
15808 vty_out(vty, " %pFX\n", range);
15809 }
15810 }
15811
15812 if (json) {
15813 json_object_object_add(
15814 json_peer_group_dynamic_af, "ranges",
15815 json_peer_group_ranges);
15816
15817 json_object_object_add(
15818 json_peer_group_dynamic, afi2str(afi),
15819 json_peer_group_dynamic_af);
15820 }
15821 }
15822 }
15823
15824 if (json_peer_group_dynamic)
15825 json_object_object_add(json_peer_group, "dynamicRanges",
15826 json_peer_group_dynamic);
15827
15828 /* Display group members and their status */
15829 if (listcount(group->peer)) {
15830 if (json)
15831 json_peer_group_members = json_object_new_object();
15832 else
15833 vty_out(vty, " Peer-group members:\n");
15834 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15835 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15836 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15837 peer_status = "Idle (Admin)";
15838 else if (CHECK_FLAG(peer->sflags,
15839 PEER_STATUS_PREFIX_OVERFLOW))
15840 peer_status = "Idle (PfxCt)";
15841 else
15842 peer_status = lookup_msg(bgp_status_msg,
15843 peer->status, NULL);
15844
15845 dynamic = peer_dynamic_neighbor(peer);
15846
15847 if (json) {
15848 json_object *json_peer_group_member =
15849 json_object_new_object();
15850
15851 json_object_string_add(json_peer_group_member,
15852 "status", peer_status);
15853
15854 if (dynamic)
15855 json_object_boolean_true_add(
15856 json_peer_group_member,
15857 "dynamic");
15858
15859 json_object_object_add(json_peer_group_members,
15860 peer->host,
15861 json_peer_group_member);
15862 } else {
15863 vty_out(vty, " %s %s %s \n", peer->host,
15864 dynamic ? "(dynamic)" : "",
15865 peer_status);
15866 }
15867 }
15868 if (json)
15869 json_object_object_add(json_peer_group, "members",
15870 json_peer_group_members);
15871 }
15872
15873 if (json)
15874 json_object_object_add(json, group->name, json_peer_group);
15875
15876 return CMD_SUCCESS;
15877 }
15878
15879 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15880 const char *group_name, bool uj)
15881 {
15882 struct bgp *bgp;
15883 struct listnode *node, *nnode;
15884 struct peer_group *group;
15885 bool found = false;
15886 json_object *json = NULL;
15887
15888 if (uj)
15889 json = json_object_new_object();
15890
15891 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15892
15893 if (!bgp) {
15894 if (uj)
15895 vty_json(vty, json);
15896 else
15897 vty_out(vty, "%% BGP instance not found\n");
15898
15899 return CMD_WARNING;
15900 }
15901
15902 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15903 if (group_name) {
15904 if (strmatch(group->name, group_name)) {
15905 bgp_show_one_peer_group(vty, group, json);
15906 found = true;
15907 break;
15908 }
15909 } else {
15910 bgp_show_one_peer_group(vty, group, json);
15911 }
15912 }
15913
15914 if (group_name && !found && !uj)
15915 vty_out(vty, "%% No such peer-group\n");
15916
15917 if (uj)
15918 vty_json(vty, json);
15919
15920 return CMD_SUCCESS;
15921 }
15922
15923 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15924 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15925 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15926 "Detailed information on BGP peer groups\n"
15927 "Peer group name\n" JSON_STR)
15928 {
15929 char *vrf, *pg;
15930 int idx = 0;
15931 bool uj = use_json(argc, argv);
15932
15933 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15934 : NULL;
15935 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15936
15937 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15938 }
15939
15940
15941 /* Redistribute VTY commands. */
15942
15943 DEFUN (bgp_redistribute_ipv4,
15944 bgp_redistribute_ipv4_cmd,
15945 "redistribute " FRR_IP_REDIST_STR_BGPD,
15946 "Redistribute information from another routing protocol\n"
15947 FRR_IP_REDIST_HELP_STR_BGPD)
15948 {
15949 VTY_DECLVAR_CONTEXT(bgp, bgp);
15950 int idx_protocol = 1;
15951 int type;
15952
15953 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15954 if (type < 0) {
15955 vty_out(vty, "%% Invalid route type\n");
15956 return CMD_WARNING_CONFIG_FAILED;
15957 }
15958
15959 bgp_redist_add(bgp, AFI_IP, type, 0);
15960 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15961 }
15962
15963 ALIAS_HIDDEN(
15964 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15965 "redistribute " FRR_IP_REDIST_STR_BGPD,
15966 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15967
15968 DEFUN (bgp_redistribute_ipv4_rmap,
15969 bgp_redistribute_ipv4_rmap_cmd,
15970 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15971 "Redistribute information from another routing protocol\n"
15972 FRR_IP_REDIST_HELP_STR_BGPD
15973 "Route map reference\n"
15974 "Pointer to route-map entries\n")
15975 {
15976 VTY_DECLVAR_CONTEXT(bgp, bgp);
15977 int idx_protocol = 1;
15978 int idx_word = 3;
15979 int type;
15980 struct bgp_redist *red;
15981 bool changed;
15982 struct route_map *route_map = route_map_lookup_warn_noexist(
15983 vty, argv[idx_word]->arg);
15984
15985 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15986 if (type < 0) {
15987 vty_out(vty, "%% Invalid route type\n");
15988 return CMD_WARNING_CONFIG_FAILED;
15989 }
15990
15991 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15992 changed =
15993 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15994 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15995 }
15996
15997 ALIAS_HIDDEN(
15998 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15999 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16000 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16001 "Route map reference\n"
16002 "Pointer to route-map entries\n")
16003
16004 DEFUN (bgp_redistribute_ipv4_metric,
16005 bgp_redistribute_ipv4_metric_cmd,
16006 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16007 "Redistribute information from another routing protocol\n"
16008 FRR_IP_REDIST_HELP_STR_BGPD
16009 "Metric for redistributed routes\n"
16010 "Default metric\n")
16011 {
16012 VTY_DECLVAR_CONTEXT(bgp, bgp);
16013 int idx_protocol = 1;
16014 int idx_number = 3;
16015 int type;
16016 uint32_t metric;
16017 struct bgp_redist *red;
16018 bool changed;
16019
16020 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16021 if (type < 0) {
16022 vty_out(vty, "%% Invalid route type\n");
16023 return CMD_WARNING_CONFIG_FAILED;
16024 }
16025 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16026
16027 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16028 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16029 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16030 }
16031
16032 ALIAS_HIDDEN(
16033 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16034 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16035 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16036 "Metric for redistributed routes\n"
16037 "Default metric\n")
16038
16039 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16040 bgp_redistribute_ipv4_rmap_metric_cmd,
16041 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16042 "Redistribute information from another routing protocol\n"
16043 FRR_IP_REDIST_HELP_STR_BGPD
16044 "Route map reference\n"
16045 "Pointer to route-map entries\n"
16046 "Metric for redistributed routes\n"
16047 "Default metric\n")
16048 {
16049 VTY_DECLVAR_CONTEXT(bgp, bgp);
16050 int idx_protocol = 1;
16051 int idx_word = 3;
16052 int idx_number = 5;
16053 int type;
16054 uint32_t metric;
16055 struct bgp_redist *red;
16056 bool changed;
16057 struct route_map *route_map =
16058 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16059
16060 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16061 if (type < 0) {
16062 vty_out(vty, "%% Invalid route type\n");
16063 return CMD_WARNING_CONFIG_FAILED;
16064 }
16065 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16066
16067 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16068 changed =
16069 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16070 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16071 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16072 }
16073
16074 ALIAS_HIDDEN(
16075 bgp_redistribute_ipv4_rmap_metric,
16076 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16077 "redistribute " FRR_IP_REDIST_STR_BGPD
16078 " route-map RMAP_NAME metric (0-4294967295)",
16079 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16080 "Route map reference\n"
16081 "Pointer to route-map entries\n"
16082 "Metric for redistributed routes\n"
16083 "Default metric\n")
16084
16085 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16086 bgp_redistribute_ipv4_metric_rmap_cmd,
16087 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16088 "Redistribute information from another routing protocol\n"
16089 FRR_IP_REDIST_HELP_STR_BGPD
16090 "Metric for redistributed routes\n"
16091 "Default metric\n"
16092 "Route map reference\n"
16093 "Pointer to route-map entries\n")
16094 {
16095 VTY_DECLVAR_CONTEXT(bgp, bgp);
16096 int idx_protocol = 1;
16097 int idx_number = 3;
16098 int idx_word = 5;
16099 int type;
16100 uint32_t metric;
16101 struct bgp_redist *red;
16102 bool changed;
16103 struct route_map *route_map =
16104 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16105
16106 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16107 if (type < 0) {
16108 vty_out(vty, "%% Invalid route type\n");
16109 return CMD_WARNING_CONFIG_FAILED;
16110 }
16111 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16112
16113 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16114 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16115 changed |=
16116 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16117 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16118 }
16119
16120 ALIAS_HIDDEN(
16121 bgp_redistribute_ipv4_metric_rmap,
16122 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16123 "redistribute " FRR_IP_REDIST_STR_BGPD
16124 " metric (0-4294967295) route-map RMAP_NAME",
16125 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16126 "Metric for redistributed routes\n"
16127 "Default metric\n"
16128 "Route map reference\n"
16129 "Pointer to route-map entries\n")
16130
16131 DEFUN (bgp_redistribute_ipv4_ospf,
16132 bgp_redistribute_ipv4_ospf_cmd,
16133 "redistribute <ospf|table> (1-65535)",
16134 "Redistribute information from another routing protocol\n"
16135 "Open Shortest Path First (OSPFv2)\n"
16136 "Non-main Kernel Routing Table\n"
16137 "Instance ID/Table ID\n")
16138 {
16139 VTY_DECLVAR_CONTEXT(bgp, bgp);
16140 int idx_ospf_table = 1;
16141 int idx_number = 2;
16142 unsigned short instance;
16143 unsigned short protocol;
16144
16145 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16146
16147 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16148 protocol = ZEBRA_ROUTE_OSPF;
16149 else
16150 protocol = ZEBRA_ROUTE_TABLE;
16151
16152 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16153 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16154 }
16155
16156 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16157 "redistribute <ospf|table> (1-65535)",
16158 "Redistribute information from another routing protocol\n"
16159 "Open Shortest Path First (OSPFv2)\n"
16160 "Non-main Kernel Routing Table\n"
16161 "Instance ID/Table ID\n")
16162
16163 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16164 bgp_redistribute_ipv4_ospf_rmap_cmd,
16165 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
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 {
16173 VTY_DECLVAR_CONTEXT(bgp, bgp);
16174 int idx_ospf_table = 1;
16175 int idx_number = 2;
16176 int idx_word = 4;
16177 struct bgp_redist *red;
16178 unsigned short instance;
16179 int protocol;
16180 bool changed;
16181 struct route_map *route_map =
16182 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16183
16184 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16185 protocol = ZEBRA_ROUTE_OSPF;
16186 else
16187 protocol = ZEBRA_ROUTE_TABLE;
16188
16189 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16190 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16191 changed =
16192 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16193 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16194 }
16195
16196 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16197 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16198 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16199 "Redistribute information from another routing protocol\n"
16200 "Open Shortest Path First (OSPFv2)\n"
16201 "Non-main Kernel Routing Table\n"
16202 "Instance ID/Table ID\n"
16203 "Route map reference\n"
16204 "Pointer to route-map entries\n")
16205
16206 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16207 bgp_redistribute_ipv4_ospf_metric_cmd,
16208 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16209 "Redistribute information from another routing protocol\n"
16210 "Open Shortest Path First (OSPFv2)\n"
16211 "Non-main Kernel Routing Table\n"
16212 "Instance ID/Table ID\n"
16213 "Metric for redistributed routes\n"
16214 "Default metric\n")
16215 {
16216 VTY_DECLVAR_CONTEXT(bgp, bgp);
16217 int idx_ospf_table = 1;
16218 int idx_number = 2;
16219 int idx_number_2 = 4;
16220 uint32_t metric;
16221 struct bgp_redist *red;
16222 unsigned short instance;
16223 int protocol;
16224 bool changed;
16225
16226 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16227 protocol = ZEBRA_ROUTE_OSPF;
16228 else
16229 protocol = ZEBRA_ROUTE_TABLE;
16230
16231 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16232 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16233
16234 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16235 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16236 metric);
16237 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16238 }
16239
16240 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16241 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16242 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16243 "Redistribute information from another routing protocol\n"
16244 "Open Shortest Path First (OSPFv2)\n"
16245 "Non-main Kernel Routing Table\n"
16246 "Instance ID/Table ID\n"
16247 "Metric for redistributed routes\n"
16248 "Default metric\n")
16249
16250 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16251 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16252 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16253 "Redistribute information from another routing protocol\n"
16254 "Open Shortest Path First (OSPFv2)\n"
16255 "Non-main Kernel Routing Table\n"
16256 "Instance ID/Table ID\n"
16257 "Route map reference\n"
16258 "Pointer to route-map entries\n"
16259 "Metric for redistributed routes\n"
16260 "Default metric\n")
16261 {
16262 VTY_DECLVAR_CONTEXT(bgp, bgp);
16263 int idx_ospf_table = 1;
16264 int idx_number = 2;
16265 int idx_word = 4;
16266 int idx_number_2 = 6;
16267 uint32_t metric;
16268 struct bgp_redist *red;
16269 unsigned short instance;
16270 int protocol;
16271 bool changed;
16272 struct route_map *route_map =
16273 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16274
16275 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16276 protocol = ZEBRA_ROUTE_OSPF;
16277 else
16278 protocol = ZEBRA_ROUTE_TABLE;
16279
16280 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16281 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16282
16283 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16284 changed =
16285 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16286 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16287 metric);
16288 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16289 }
16290
16291 ALIAS_HIDDEN(
16292 bgp_redistribute_ipv4_ospf_rmap_metric,
16293 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16294 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16295 "Redistribute information from another routing protocol\n"
16296 "Open Shortest Path First (OSPFv2)\n"
16297 "Non-main Kernel Routing Table\n"
16298 "Instance ID/Table ID\n"
16299 "Route map reference\n"
16300 "Pointer to route-map entries\n"
16301 "Metric for redistributed routes\n"
16302 "Default metric\n")
16303
16304 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16305 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16306 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16307 "Redistribute information from another routing protocol\n"
16308 "Open Shortest Path First (OSPFv2)\n"
16309 "Non-main Kernel Routing Table\n"
16310 "Instance ID/Table ID\n"
16311 "Metric for redistributed routes\n"
16312 "Default metric\n"
16313 "Route map reference\n"
16314 "Pointer to route-map entries\n")
16315 {
16316 VTY_DECLVAR_CONTEXT(bgp, bgp);
16317 int idx_ospf_table = 1;
16318 int idx_number = 2;
16319 int idx_number_2 = 4;
16320 int idx_word = 6;
16321 uint32_t metric;
16322 struct bgp_redist *red;
16323 unsigned short instance;
16324 int protocol;
16325 bool changed;
16326 struct route_map *route_map =
16327 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16328
16329 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16330 protocol = ZEBRA_ROUTE_OSPF;
16331 else
16332 protocol = ZEBRA_ROUTE_TABLE;
16333
16334 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16335 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16336
16337 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16338 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16339 metric);
16340 changed |=
16341 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16342 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16343 }
16344
16345 ALIAS_HIDDEN(
16346 bgp_redistribute_ipv4_ospf_metric_rmap,
16347 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16348 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16349 "Redistribute information from another routing protocol\n"
16350 "Open Shortest Path First (OSPFv2)\n"
16351 "Non-main Kernel Routing Table\n"
16352 "Instance ID/Table ID\n"
16353 "Metric for redistributed routes\n"
16354 "Default metric\n"
16355 "Route map reference\n"
16356 "Pointer to route-map entries\n")
16357
16358 DEFUN (no_bgp_redistribute_ipv4_ospf,
16359 no_bgp_redistribute_ipv4_ospf_cmd,
16360 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16361 NO_STR
16362 "Redistribute information from another routing protocol\n"
16363 "Open Shortest Path First (OSPFv2)\n"
16364 "Non-main Kernel Routing Table\n"
16365 "Instance ID/Table ID\n"
16366 "Metric for redistributed routes\n"
16367 "Default metric\n"
16368 "Route map reference\n"
16369 "Pointer to route-map entries\n")
16370 {
16371 VTY_DECLVAR_CONTEXT(bgp, bgp);
16372 int idx_ospf_table = 2;
16373 int idx_number = 3;
16374 unsigned short instance;
16375 int protocol;
16376
16377 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16378 protocol = ZEBRA_ROUTE_OSPF;
16379 else
16380 protocol = ZEBRA_ROUTE_TABLE;
16381
16382 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16383 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16384 }
16385
16386 ALIAS_HIDDEN(
16387 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16388 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16389 NO_STR
16390 "Redistribute information from another routing protocol\n"
16391 "Open Shortest Path First (OSPFv2)\n"
16392 "Non-main Kernel Routing Table\n"
16393 "Instance ID/Table ID\n"
16394 "Metric for redistributed routes\n"
16395 "Default metric\n"
16396 "Route map reference\n"
16397 "Pointer to route-map entries\n")
16398
16399 DEFUN (no_bgp_redistribute_ipv4,
16400 no_bgp_redistribute_ipv4_cmd,
16401 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16402 NO_STR
16403 "Redistribute information from another routing protocol\n"
16404 FRR_IP_REDIST_HELP_STR_BGPD
16405 "Metric for redistributed routes\n"
16406 "Default metric\n"
16407 "Route map reference\n"
16408 "Pointer to route-map entries\n")
16409 {
16410 VTY_DECLVAR_CONTEXT(bgp, bgp);
16411 int idx_protocol = 2;
16412 int type;
16413
16414 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16415 if (type < 0) {
16416 vty_out(vty, "%% Invalid route type\n");
16417 return CMD_WARNING_CONFIG_FAILED;
16418 }
16419 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16420 }
16421
16422 ALIAS_HIDDEN(
16423 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16424 "no redistribute " FRR_IP_REDIST_STR_BGPD
16425 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16426 NO_STR
16427 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16428 "Metric for redistributed routes\n"
16429 "Default metric\n"
16430 "Route map reference\n"
16431 "Pointer to route-map entries\n")
16432
16433 DEFUN (bgp_redistribute_ipv6,
16434 bgp_redistribute_ipv6_cmd,
16435 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16436 "Redistribute information from another routing protocol\n"
16437 FRR_IP6_REDIST_HELP_STR_BGPD)
16438 {
16439 VTY_DECLVAR_CONTEXT(bgp, bgp);
16440 int idx_protocol = 1;
16441 int type;
16442
16443 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16444 if (type < 0) {
16445 vty_out(vty, "%% Invalid route type\n");
16446 return CMD_WARNING_CONFIG_FAILED;
16447 }
16448
16449 bgp_redist_add(bgp, AFI_IP6, type, 0);
16450 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16451 }
16452
16453 DEFUN (bgp_redistribute_ipv6_rmap,
16454 bgp_redistribute_ipv6_rmap_cmd,
16455 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16456 "Redistribute information from another routing protocol\n"
16457 FRR_IP6_REDIST_HELP_STR_BGPD
16458 "Route map reference\n"
16459 "Pointer to route-map entries\n")
16460 {
16461 VTY_DECLVAR_CONTEXT(bgp, bgp);
16462 int idx_protocol = 1;
16463 int idx_word = 3;
16464 int type;
16465 struct bgp_redist *red;
16466 bool changed;
16467 struct route_map *route_map =
16468 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16469
16470 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16471 if (type < 0) {
16472 vty_out(vty, "%% Invalid route type\n");
16473 return CMD_WARNING_CONFIG_FAILED;
16474 }
16475
16476 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16477 changed =
16478 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16479 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16480 }
16481
16482 DEFUN (bgp_redistribute_ipv6_metric,
16483 bgp_redistribute_ipv6_metric_cmd,
16484 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16485 "Redistribute information from another routing protocol\n"
16486 FRR_IP6_REDIST_HELP_STR_BGPD
16487 "Metric for redistributed routes\n"
16488 "Default metric\n")
16489 {
16490 VTY_DECLVAR_CONTEXT(bgp, bgp);
16491 int idx_protocol = 1;
16492 int idx_number = 3;
16493 int type;
16494 uint32_t metric;
16495 struct bgp_redist *red;
16496 bool changed;
16497
16498 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16499 if (type < 0) {
16500 vty_out(vty, "%% Invalid route type\n");
16501 return CMD_WARNING_CONFIG_FAILED;
16502 }
16503 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16504
16505 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16506 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16507 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16508 }
16509
16510 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16511 bgp_redistribute_ipv6_rmap_metric_cmd,
16512 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16513 "Redistribute information from another routing protocol\n"
16514 FRR_IP6_REDIST_HELP_STR_BGPD
16515 "Route map reference\n"
16516 "Pointer to route-map entries\n"
16517 "Metric for redistributed routes\n"
16518 "Default metric\n")
16519 {
16520 VTY_DECLVAR_CONTEXT(bgp, bgp);
16521 int idx_protocol = 1;
16522 int idx_word = 3;
16523 int idx_number = 5;
16524 int type;
16525 uint32_t metric;
16526 struct bgp_redist *red;
16527 bool changed;
16528 struct route_map *route_map =
16529 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16530
16531 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16532 if (type < 0) {
16533 vty_out(vty, "%% Invalid route type\n");
16534 return CMD_WARNING_CONFIG_FAILED;
16535 }
16536 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16537
16538 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16539 changed =
16540 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16541 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16542 metric);
16543 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16544 }
16545
16546 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16547 bgp_redistribute_ipv6_metric_rmap_cmd,
16548 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16549 "Redistribute information from another routing protocol\n"
16550 FRR_IP6_REDIST_HELP_STR_BGPD
16551 "Metric for redistributed routes\n"
16552 "Default metric\n"
16553 "Route map reference\n"
16554 "Pointer to route-map entries\n")
16555 {
16556 VTY_DECLVAR_CONTEXT(bgp, bgp);
16557 int idx_protocol = 1;
16558 int idx_number = 3;
16559 int idx_word = 5;
16560 int type;
16561 uint32_t metric;
16562 struct bgp_redist *red;
16563 bool changed;
16564 struct route_map *route_map =
16565 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16566
16567 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16568 if (type < 0) {
16569 vty_out(vty, "%% Invalid route type\n");
16570 return CMD_WARNING_CONFIG_FAILED;
16571 }
16572 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16573
16574 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16575 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16576 metric);
16577 changed |=
16578 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16579 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16580 }
16581
16582 DEFUN (no_bgp_redistribute_ipv6,
16583 no_bgp_redistribute_ipv6_cmd,
16584 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16585 NO_STR
16586 "Redistribute information from another routing protocol\n"
16587 FRR_IP6_REDIST_HELP_STR_BGPD
16588 "Metric for redistributed routes\n"
16589 "Default metric\n"
16590 "Route map reference\n"
16591 "Pointer to route-map entries\n")
16592 {
16593 VTY_DECLVAR_CONTEXT(bgp, bgp);
16594 int idx_protocol = 2;
16595 int type;
16596
16597 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16598 if (type < 0) {
16599 vty_out(vty, "%% Invalid route type\n");
16600 return CMD_WARNING_CONFIG_FAILED;
16601 }
16602
16603 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16604 }
16605
16606 /* Neighbor update tcp-mss. */
16607 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16608 const char *tcp_mss_str)
16609 {
16610 struct peer *peer;
16611 uint32_t tcp_mss_val = 0;
16612
16613 peer = peer_and_group_lookup_vty(vty, peer_str);
16614 if (!peer)
16615 return CMD_WARNING_CONFIG_FAILED;
16616
16617 if (tcp_mss_str) {
16618 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16619 peer_tcp_mss_set(peer, tcp_mss_val);
16620 } else {
16621 peer_tcp_mss_unset(peer);
16622 }
16623
16624 return CMD_SUCCESS;
16625 }
16626
16627 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16628 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16629 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16630 "TCP max segment size\n"
16631 "TCP MSS value\n")
16632 {
16633 int peer_index = 1;
16634 int mss_index = 3;
16635
16636 vty_out(vty,
16637 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16638 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16639 argv[mss_index]->arg);
16640 }
16641
16642 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16643 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16644 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16645 "TCP max segment size\n"
16646 "TCP MSS value\n")
16647 {
16648 int peer_index = 2;
16649
16650 vty_out(vty,
16651 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16652 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16653 }
16654
16655 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16656 "[no$no] bgp retain route-target all",
16657 NO_STR BGP_STR
16658 "Retain BGP updates\n"
16659 "Retain BGP updates based on route-target values\n"
16660 "Retain all BGP updates\n")
16661 {
16662 bool check;
16663 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16664
16665 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16666 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16667 if (check != !no) {
16668 if (!no)
16669 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16670 [bgp_node_safi(vty)],
16671 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16672 else
16673 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16674 [bgp_node_safi(vty)],
16675 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16676 /* trigger a flush to re-sync with ADJ-RIB-in */
16677 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16678 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16679 }
16680 return CMD_SUCCESS;
16681 }
16682
16683 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16684 afi_t afi, safi_t safi)
16685 {
16686 int i;
16687
16688 /* Unicast redistribution only. */
16689 if (safi != SAFI_UNICAST)
16690 return;
16691
16692 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16693 /* Redistribute BGP does not make sense. */
16694 if (i != ZEBRA_ROUTE_BGP) {
16695 struct list *red_list;
16696 struct listnode *node;
16697 struct bgp_redist *red;
16698
16699 red_list = bgp->redist[afi][i];
16700 if (!red_list)
16701 continue;
16702
16703 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16704 /* "redistribute" configuration. */
16705 vty_out(vty, " redistribute %s",
16706 zebra_route_string(i));
16707 if (red->instance)
16708 vty_out(vty, " %d", red->instance);
16709 if (red->redist_metric_flag)
16710 vty_out(vty, " metric %u",
16711 red->redist_metric);
16712 if (red->rmap.name)
16713 vty_out(vty, " route-map %s",
16714 red->rmap.name);
16715 vty_out(vty, "\n");
16716 }
16717 }
16718 }
16719 }
16720
16721 /* peer-group helpers for config-write */
16722
16723 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16724 {
16725 if (!peer_group_active(peer)) {
16726 if (CHECK_FLAG(peer->flags_invert, flag))
16727 return !CHECK_FLAG(peer->flags, flag);
16728 else
16729 return !!CHECK_FLAG(peer->flags, flag);
16730 }
16731
16732 return !!CHECK_FLAG(peer->flags_override, flag);
16733 }
16734
16735 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16736 uint64_t flag)
16737 {
16738 if (!peer_group_active(peer)) {
16739 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16740 return !peer_af_flag_check(peer, afi, safi, flag);
16741 else
16742 return !!peer_af_flag_check(peer, afi, safi, flag);
16743 }
16744
16745 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16746 }
16747
16748 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16749 uint8_t type, int direct)
16750 {
16751 struct bgp_filter *filter;
16752
16753 if (peer_group_active(peer))
16754 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16755 type);
16756
16757 filter = &peer->filter[afi][safi];
16758 switch (type) {
16759 case PEER_FT_DISTRIBUTE_LIST:
16760 return !!(filter->dlist[direct].name);
16761 case PEER_FT_FILTER_LIST:
16762 return !!(filter->aslist[direct].name);
16763 case PEER_FT_PREFIX_LIST:
16764 return !!(filter->plist[direct].name);
16765 case PEER_FT_ROUTE_MAP:
16766 return !!(filter->map[direct].name);
16767 case PEER_FT_UNSUPPRESS_MAP:
16768 return !!(filter->usmap.name);
16769 case PEER_FT_ADVERTISE_MAP:
16770 return !!(filter->advmap.aname
16771 && ((filter->advmap.condition == direct)
16772 && filter->advmap.cname));
16773 default:
16774 return false;
16775 }
16776 }
16777
16778 /* Return true if the addpath type is set for peer and different from
16779 * peer-group.
16780 */
16781 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16782 safi_t safi)
16783 {
16784 enum bgp_addpath_strat type, g_type;
16785
16786 type = peer->addpath_type[afi][safi];
16787
16788 if (type != BGP_ADDPATH_NONE) {
16789 if (peer_group_active(peer)) {
16790 g_type = peer->group->conf->addpath_type[afi][safi];
16791
16792 if (type != g_type)
16793 return true;
16794 else
16795 return false;
16796 }
16797
16798 return true;
16799 }
16800
16801 return false;
16802 }
16803
16804 /* This is part of the address-family block (unicast only) */
16805 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16806 afi_t afi)
16807 {
16808 int indent = 2;
16809 uint32_t tovpn_sid_index = 0;
16810
16811 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16812 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16813 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16814 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16815 bgp->vpn_policy[afi]
16816 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16817 else
16818 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16819 bgp->vpn_policy[afi]
16820 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16821 }
16822 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16823 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16824 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16825 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16826 return;
16827
16828 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16829 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16830
16831 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16832
16833 } else {
16834 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16835 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16836 bgp->vpn_policy[afi].tovpn_label);
16837 }
16838 }
16839
16840 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16841 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16842 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16843 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16844 } else if (tovpn_sid_index != 0) {
16845 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16846 tovpn_sid_index);
16847 }
16848
16849 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16850 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16851 &bgp->vpn_policy[afi].tovpn_rd);
16852
16853 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16854 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16855
16856 char buf[PREFIX_STRLEN];
16857 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16858 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16859 sizeof(buf))) {
16860
16861 vty_out(vty, "%*snexthop vpn export %s\n",
16862 indent, "", buf);
16863 }
16864 }
16865 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16866 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16867 && ecommunity_cmp(
16868 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16869 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16870
16871 char *b = ecommunity_ecom2str(
16872 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16873 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16874 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16875 XFREE(MTYPE_ECOMMUNITY_STR, b);
16876 } else {
16877 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16878 char *b = ecommunity_ecom2str(
16879 bgp->vpn_policy[afi]
16880 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16881 ECOMMUNITY_FORMAT_ROUTE_MAP,
16882 ECOMMUNITY_ROUTE_TARGET);
16883 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16884 XFREE(MTYPE_ECOMMUNITY_STR, b);
16885 }
16886 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16887 char *b = ecommunity_ecom2str(
16888 bgp->vpn_policy[afi]
16889 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16890 ECOMMUNITY_FORMAT_ROUTE_MAP,
16891 ECOMMUNITY_ROUTE_TARGET);
16892 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16893 XFREE(MTYPE_ECOMMUNITY_STR, b);
16894 }
16895 }
16896
16897 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16898 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16899 bgp->vpn_policy[afi]
16900 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16901
16902 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16903 char *b = ecommunity_ecom2str(
16904 bgp->vpn_policy[afi]
16905 .import_redirect_rtlist,
16906 ECOMMUNITY_FORMAT_ROUTE_MAP,
16907 ECOMMUNITY_ROUTE_TARGET);
16908
16909 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16910 != ECOMMUNITY_SIZE)
16911 vty_out(vty, "%*srt6 redirect import %s\n",
16912 indent, "", b);
16913 else
16914 vty_out(vty, "%*srt redirect import %s\n",
16915 indent, "", b);
16916 XFREE(MTYPE_ECOMMUNITY_STR, b);
16917 }
16918 }
16919
16920 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16921 afi_t afi, safi_t safi)
16922 {
16923 struct bgp_filter *filter;
16924 char *addr;
16925
16926 addr = peer->host;
16927 filter = &peer->filter[afi][safi];
16928
16929 /* distribute-list. */
16930 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16931 FILTER_IN))
16932 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16933 filter->dlist[FILTER_IN].name);
16934
16935 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16936 FILTER_OUT))
16937 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16938 filter->dlist[FILTER_OUT].name);
16939
16940 /* prefix-list. */
16941 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16942 FILTER_IN))
16943 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16944 filter->plist[FILTER_IN].name);
16945
16946 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16947 FILTER_OUT))
16948 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16949 filter->plist[FILTER_OUT].name);
16950
16951 /* route-map. */
16952 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16953 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16954 filter->map[RMAP_IN].name);
16955
16956 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16957 RMAP_OUT))
16958 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16959 filter->map[RMAP_OUT].name);
16960
16961 /* unsuppress-map */
16962 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16963 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16964 filter->usmap.name);
16965
16966 /* advertise-map : always applied in OUT direction*/
16967 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16968 CONDITION_NON_EXIST))
16969 vty_out(vty,
16970 " neighbor %s advertise-map %s non-exist-map %s\n",
16971 addr, filter->advmap.aname, filter->advmap.cname);
16972
16973 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16974 CONDITION_EXIST))
16975 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16976 addr, filter->advmap.aname, filter->advmap.cname);
16977
16978 /* filter-list. */
16979 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16980 FILTER_IN))
16981 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16982 filter->aslist[FILTER_IN].name);
16983
16984 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16985 FILTER_OUT))
16986 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16987 filter->aslist[FILTER_OUT].name);
16988 }
16989
16990 /* BGP peer configuration display function. */
16991 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16992 struct peer *peer)
16993 {
16994 struct peer *g_peer = NULL;
16995 char *addr;
16996 int if_pg_printed = false;
16997 int if_ras_printed = false;
16998
16999 /* Skip dynamic neighbors. */
17000 if (peer_dynamic_neighbor(peer))
17001 return;
17002
17003 if (peer->conf_if)
17004 addr = peer->conf_if;
17005 else
17006 addr = peer->host;
17007
17008 /************************************
17009 ****** Global to the neighbor ******
17010 ************************************/
17011 if (peer->conf_if) {
17012 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17013 vty_out(vty, " neighbor %s interface v6only", addr);
17014 else
17015 vty_out(vty, " neighbor %s interface", addr);
17016
17017 if (peer_group_active(peer)) {
17018 vty_out(vty, " peer-group %s", peer->group->name);
17019 if_pg_printed = true;
17020 } else if (peer->as_type == AS_SPECIFIED) {
17021 vty_out(vty, " remote-as %u", peer->as);
17022 if_ras_printed = true;
17023 } else if (peer->as_type == AS_INTERNAL) {
17024 vty_out(vty, " remote-as internal");
17025 if_ras_printed = true;
17026 } else if (peer->as_type == AS_EXTERNAL) {
17027 vty_out(vty, " remote-as external");
17028 if_ras_printed = true;
17029 }
17030
17031 vty_out(vty, "\n");
17032 }
17033
17034 /* remote-as and peer-group */
17035 /* peer is a member of a peer-group */
17036 if (peer_group_active(peer)) {
17037 g_peer = peer->group->conf;
17038
17039 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17040 if (peer->as_type == AS_SPECIFIED) {
17041 vty_out(vty, " neighbor %s remote-as %u\n",
17042 addr, peer->as);
17043 } else if (peer->as_type == AS_INTERNAL) {
17044 vty_out(vty,
17045 " neighbor %s remote-as internal\n",
17046 addr);
17047 } else if (peer->as_type == AS_EXTERNAL) {
17048 vty_out(vty,
17049 " neighbor %s remote-as external\n",
17050 addr);
17051 }
17052 }
17053
17054 /* For swpX peers we displayed the peer-group
17055 * via 'neighbor swpX interface peer-group PGNAME' */
17056 if (!if_pg_printed)
17057 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17058 peer->group->name);
17059 }
17060
17061 /* peer is NOT a member of a peer-group */
17062 else {
17063 /* peer is a peer-group, declare the peer-group */
17064 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17065 vty_out(vty, " neighbor %s peer-group\n", addr);
17066 }
17067
17068 if (!if_ras_printed) {
17069 if (peer->as_type == AS_SPECIFIED) {
17070 vty_out(vty, " neighbor %s remote-as %u\n",
17071 addr, peer->as);
17072 } else if (peer->as_type == AS_INTERNAL) {
17073 vty_out(vty,
17074 " neighbor %s remote-as internal\n",
17075 addr);
17076 } else if (peer->as_type == AS_EXTERNAL) {
17077 vty_out(vty,
17078 " neighbor %s remote-as external\n",
17079 addr);
17080 }
17081 }
17082 }
17083
17084 /* local-as */
17085 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17086 vty_out(vty, " neighbor %s local-as %u", addr,
17087 peer->change_local_as);
17088 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17089 vty_out(vty, " no-prepend");
17090 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17091 vty_out(vty, " replace-as");
17092 vty_out(vty, "\n");
17093 }
17094
17095 /* description */
17096 if (peer->desc) {
17097 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17098 }
17099
17100 /* shutdown */
17101 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17102 if (peer->tx_shutdown_message)
17103 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17104 peer->tx_shutdown_message);
17105 else
17106 vty_out(vty, " neighbor %s shutdown\n", addr);
17107 }
17108
17109 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17110 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17111 peer->rtt_expected, peer->rtt_keepalive_conf);
17112
17113 /* bfd */
17114 if (peer->bfd_config)
17115 bgp_bfd_peer_config_write(vty, peer, addr);
17116
17117 /* password */
17118 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17119 vty_out(vty, " neighbor %s password %s\n", addr,
17120 peer->password);
17121
17122 /* neighbor solo */
17123 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17124 if (!peer_group_active(peer)) {
17125 vty_out(vty, " neighbor %s solo\n", addr);
17126 }
17127 }
17128
17129 /* BGP port */
17130 if (peer->port != BGP_PORT_DEFAULT) {
17131 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17132 }
17133
17134 /* Local interface name */
17135 if (peer->ifname) {
17136 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17137 }
17138
17139 /* TCP max segment size */
17140 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17141 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17142
17143 /* passive */
17144 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17145 vty_out(vty, " neighbor %s passive\n", addr);
17146
17147 /* ebgp-multihop */
17148 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17149 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17150 && peer->ttl == MAXTTL)) {
17151 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17152 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17153 peer->ttl);
17154 }
17155 }
17156
17157 /* role */
17158 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17159 peer->local_role != ROLE_UNDEFINED)
17160 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17161 bgp_get_name_by_role(peer->local_role),
17162 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17163 ? " strict-mode"
17164 : "");
17165
17166 /* ttl-security hops */
17167 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17168 if (!peer_group_active(peer)
17169 || g_peer->gtsm_hops != peer->gtsm_hops) {
17170 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17171 addr, peer->gtsm_hops);
17172 }
17173 }
17174
17175 /* disable-connected-check */
17176 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17177 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17178
17179 /* link-bw-encoding-ieee */
17180 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17181 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17182 addr);
17183
17184 /* extended-optional-parameters */
17185 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17186 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17187 addr);
17188
17189 /* enforce-first-as */
17190 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17191 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17192
17193 /* update-source */
17194 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17195 if (peer->update_source)
17196 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17197 peer->update_source);
17198 else if (peer->update_if)
17199 vty_out(vty, " neighbor %s update-source %s\n", addr,
17200 peer->update_if);
17201 }
17202
17203 /* advertisement-interval */
17204 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17205 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17206 peer->routeadv);
17207
17208 /* timers */
17209 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17210 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17211 peer->keepalive, peer->holdtime);
17212
17213 /* timers connect */
17214 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17215 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17216 peer->connect);
17217 /* need special-case handling for changed default values due to
17218 * config profile / version (because there is no "timers bgp connect"
17219 * command, we need to save this per-peer :/)
17220 */
17221 else if (!peer_group_active(peer) && !peer->connect &&
17222 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17223 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17224 peer->bgp->default_connect_retry);
17225
17226 /* timers delayopen */
17227 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17228 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17229 peer->delayopen);
17230 /* Save config even though flag is not set if default values have been
17231 * changed
17232 */
17233 else if (!peer_group_active(peer) && !peer->delayopen
17234 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17235 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17236 peer->bgp->default_delayopen);
17237
17238 /* capability dynamic */
17239 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17240 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17241
17242 /* capability extended-nexthop */
17243 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17244 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17245 !peer->conf_if)
17246 vty_out(vty,
17247 " no neighbor %s capability extended-nexthop\n",
17248 addr);
17249 else if (!peer->conf_if)
17250 vty_out(vty,
17251 " neighbor %s capability extended-nexthop\n",
17252 addr);
17253 }
17254
17255 /* dont-capability-negotiation */
17256 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17257 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17258
17259 /* override-capability */
17260 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17261 vty_out(vty, " neighbor %s override-capability\n", addr);
17262
17263 /* strict-capability-match */
17264 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17265 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17266
17267 /* Sender side AS path loop detection. */
17268 if (peer->as_path_loop_detection)
17269 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17270 addr);
17271
17272 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17273 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17274
17275 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17276 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17277 vty_out(vty,
17278 " neighbor %s graceful-restart-helper\n", addr);
17279 } else if (CHECK_FLAG(
17280 peer->peer_gr_new_status_flag,
17281 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17282 vty_out(vty,
17283 " neighbor %s graceful-restart\n", addr);
17284 } else if (
17285 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17286 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17287 && !(CHECK_FLAG(
17288 peer->peer_gr_new_status_flag,
17289 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17290 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17291 addr);
17292 }
17293 }
17294 }
17295
17296 /* BGP peer configuration display function. */
17297 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17298 struct peer *peer, afi_t afi, safi_t safi)
17299 {
17300 struct peer *g_peer = NULL;
17301 char *addr;
17302 bool flag_scomm, flag_secomm, flag_slcomm;
17303
17304 /* Skip dynamic neighbors. */
17305 if (peer_dynamic_neighbor(peer))
17306 return;
17307
17308 if (peer->conf_if)
17309 addr = peer->conf_if;
17310 else
17311 addr = peer->host;
17312
17313 /************************************
17314 ****** Per AF to the neighbor ******
17315 ************************************/
17316 if (peer_group_active(peer)) {
17317 g_peer = peer->group->conf;
17318
17319 /* If the peer-group is active but peer is not, print a 'no
17320 * activate' */
17321 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17322 vty_out(vty, " no neighbor %s activate\n", addr);
17323 }
17324
17325 /* If the peer-group is not active but peer is, print an
17326 'activate' */
17327 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17328 vty_out(vty, " neighbor %s activate\n", addr);
17329 }
17330 } else {
17331 if (peer->afc[afi][safi]) {
17332 if (safi == SAFI_ENCAP)
17333 vty_out(vty, " neighbor %s activate\n", addr);
17334 else if (!bgp->default_af[afi][safi])
17335 vty_out(vty, " neighbor %s activate\n", addr);
17336 } else {
17337 if (bgp->default_af[afi][safi])
17338 vty_out(vty, " no neighbor %s activate\n",
17339 addr);
17340 }
17341 }
17342
17343 /* addpath TX knobs */
17344 if (peergroup_af_addpath_check(peer, afi, safi)) {
17345 switch (peer->addpath_type[afi][safi]) {
17346 case BGP_ADDPATH_ALL:
17347 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17348 addr);
17349 break;
17350 case BGP_ADDPATH_BEST_PER_AS:
17351 vty_out(vty,
17352 " neighbor %s addpath-tx-bestpath-per-AS\n",
17353 addr);
17354 break;
17355 case BGP_ADDPATH_MAX:
17356 case BGP_ADDPATH_NONE:
17357 break;
17358 }
17359 }
17360
17361 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17362 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17363
17364 /* ORF capability. */
17365 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17366 || peergroup_af_flag_check(peer, afi, safi,
17367 PEER_FLAG_ORF_PREFIX_RM)) {
17368 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17369
17370 if (peergroup_af_flag_check(peer, afi, safi,
17371 PEER_FLAG_ORF_PREFIX_SM)
17372 && peergroup_af_flag_check(peer, afi, safi,
17373 PEER_FLAG_ORF_PREFIX_RM))
17374 vty_out(vty, " both");
17375 else if (peergroup_af_flag_check(peer, afi, safi,
17376 PEER_FLAG_ORF_PREFIX_SM))
17377 vty_out(vty, " send");
17378 else
17379 vty_out(vty, " receive");
17380 vty_out(vty, "\n");
17381 }
17382
17383 /* Route reflector client. */
17384 if (peergroup_af_flag_check(peer, afi, safi,
17385 PEER_FLAG_REFLECTOR_CLIENT)) {
17386 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17387 }
17388
17389 /* next-hop-self force */
17390 if (peergroup_af_flag_check(peer, afi, safi,
17391 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17392 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17393 }
17394
17395 /* next-hop-self */
17396 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17397 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17398 }
17399
17400 /* remove-private-AS */
17401 if (peergroup_af_flag_check(peer, afi, safi,
17402 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17403 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17404 addr);
17405 }
17406
17407 else if (peergroup_af_flag_check(peer, afi, safi,
17408 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17409 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17410 addr);
17411 }
17412
17413 else if (peergroup_af_flag_check(peer, afi, safi,
17414 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17415 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17416 }
17417
17418 else if (peergroup_af_flag_check(peer, afi, safi,
17419 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17420 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17421 }
17422
17423 /* as-override */
17424 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17425 vty_out(vty, " neighbor %s as-override\n", addr);
17426 }
17427
17428 /* send-community print. */
17429 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17430 PEER_FLAG_SEND_COMMUNITY);
17431 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17432 PEER_FLAG_SEND_EXT_COMMUNITY);
17433 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17434 PEER_FLAG_SEND_LARGE_COMMUNITY);
17435
17436 if (flag_scomm && flag_secomm && flag_slcomm) {
17437 vty_out(vty, " no neighbor %s send-community all\n", addr);
17438 } else {
17439 if (flag_scomm)
17440 vty_out(vty, " no neighbor %s send-community\n", addr);
17441 if (flag_secomm)
17442 vty_out(vty,
17443 " no neighbor %s send-community extended\n",
17444 addr);
17445
17446 if (flag_slcomm)
17447 vty_out(vty, " no neighbor %s send-community large\n",
17448 addr);
17449 }
17450
17451 /* Default information */
17452 if (peergroup_af_flag_check(peer, afi, safi,
17453 PEER_FLAG_DEFAULT_ORIGINATE)) {
17454 vty_out(vty, " neighbor %s default-originate", addr);
17455
17456 if (peer->default_rmap[afi][safi].name)
17457 vty_out(vty, " route-map %s",
17458 peer->default_rmap[afi][safi].name);
17459
17460 vty_out(vty, "\n");
17461 }
17462
17463 /* Soft reconfiguration inbound. */
17464 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17465 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17466 addr);
17467 }
17468
17469 /* maximum-prefix. */
17470 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17471 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17472 peer->pmax[afi][safi]);
17473
17474 if (peer->pmax_threshold[afi][safi]
17475 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17476 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17477 if (peer_af_flag_check(peer, afi, safi,
17478 PEER_FLAG_MAX_PREFIX_WARNING))
17479 vty_out(vty, " warning-only");
17480 if (peer->pmax_restart[afi][safi])
17481 vty_out(vty, " restart %u",
17482 peer->pmax_restart[afi][safi]);
17483 if (peer_af_flag_check(peer, afi, safi,
17484 PEER_FLAG_MAX_PREFIX_FORCE))
17485 vty_out(vty, " force");
17486
17487 vty_out(vty, "\n");
17488 }
17489
17490 /* maximum-prefix-out */
17491 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17492 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17493 addr, peer->pmax_out[afi][safi]);
17494
17495 /* Route server client. */
17496 if (peergroup_af_flag_check(peer, afi, safi,
17497 PEER_FLAG_RSERVER_CLIENT)) {
17498 vty_out(vty, " neighbor %s route-server-client\n", addr);
17499 }
17500
17501 /* Nexthop-local unchanged. */
17502 if (peergroup_af_flag_check(peer, afi, safi,
17503 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17504 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17505 }
17506
17507 /* allowas-in <1-10> */
17508 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17509 if (peer_af_flag_check(peer, afi, safi,
17510 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17511 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17512 } else if (peer->allowas_in[afi][safi] == 3) {
17513 vty_out(vty, " neighbor %s allowas-in\n", addr);
17514 } else {
17515 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17516 peer->allowas_in[afi][safi]);
17517 }
17518 }
17519
17520 /* accept-own */
17521 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17522 vty_out(vty, " neighbor %s accept-own\n", addr);
17523
17524 /* soo */
17525 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17526 char *soo_str = ecommunity_ecom2str(
17527 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17528
17529 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17530 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17531 }
17532
17533 /* weight */
17534 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17535 vty_out(vty, " neighbor %s weight %lu\n", addr,
17536 peer->weight[afi][safi]);
17537
17538 /* Filter. */
17539 bgp_config_write_filter(vty, peer, afi, safi);
17540
17541 /* atribute-unchanged. */
17542 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17543 || (safi != SAFI_EVPN
17544 && peer_af_flag_check(peer, afi, safi,
17545 PEER_FLAG_NEXTHOP_UNCHANGED))
17546 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17547
17548 if (!peer_group_active(peer)
17549 || peergroup_af_flag_check(peer, afi, safi,
17550 PEER_FLAG_AS_PATH_UNCHANGED)
17551 || peergroup_af_flag_check(peer, afi, safi,
17552 PEER_FLAG_NEXTHOP_UNCHANGED)
17553 || peergroup_af_flag_check(peer, afi, safi,
17554 PEER_FLAG_MED_UNCHANGED)) {
17555
17556 vty_out(vty,
17557 " neighbor %s attribute-unchanged%s%s%s\n",
17558 addr,
17559 peer_af_flag_check(peer, afi, safi,
17560 PEER_FLAG_AS_PATH_UNCHANGED)
17561 ? " as-path"
17562 : "",
17563 peer_af_flag_check(peer, afi, safi,
17564 PEER_FLAG_NEXTHOP_UNCHANGED)
17565 ? " next-hop"
17566 : "",
17567 peer_af_flag_check(peer, afi, safi,
17568 PEER_FLAG_MED_UNCHANGED)
17569 ? " med"
17570 : "");
17571 }
17572 }
17573
17574 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_ORR_GROUP))
17575 vty_out(vty, " neighbor %s optimal-route-reflection %s\n",
17576 addr, peer->orr_group_name[afi][safi]);
17577 }
17578
17579 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17580 safi_t safi)
17581 {
17582 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17583 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17584 vty_out(vty, " no bgp retain route-target all\n");
17585 }
17586
17587 /* Address family based peer configuration display. */
17588 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17589 safi_t safi)
17590 {
17591 struct peer *peer;
17592 struct peer_group *group;
17593 struct listnode *node, *nnode;
17594
17595
17596 vty_frame(vty, " !\n address-family ");
17597 if (afi == AFI_IP) {
17598 if (safi == SAFI_UNICAST)
17599 vty_frame(vty, "ipv4 unicast");
17600 else if (safi == SAFI_LABELED_UNICAST)
17601 vty_frame(vty, "ipv4 labeled-unicast");
17602 else if (safi == SAFI_MULTICAST)
17603 vty_frame(vty, "ipv4 multicast");
17604 else if (safi == SAFI_MPLS_VPN)
17605 vty_frame(vty, "ipv4 vpn");
17606 else if (safi == SAFI_ENCAP)
17607 vty_frame(vty, "ipv4 encap");
17608 else if (safi == SAFI_FLOWSPEC)
17609 vty_frame(vty, "ipv4 flowspec");
17610 } else if (afi == AFI_IP6) {
17611 if (safi == SAFI_UNICAST)
17612 vty_frame(vty, "ipv6 unicast");
17613 else if (safi == SAFI_LABELED_UNICAST)
17614 vty_frame(vty, "ipv6 labeled-unicast");
17615 else if (safi == SAFI_MULTICAST)
17616 vty_frame(vty, "ipv6 multicast");
17617 else if (safi == SAFI_MPLS_VPN)
17618 vty_frame(vty, "ipv6 vpn");
17619 else if (safi == SAFI_ENCAP)
17620 vty_frame(vty, "ipv6 encap");
17621 else if (safi == SAFI_FLOWSPEC)
17622 vty_frame(vty, "ipv6 flowspec");
17623 } else if (afi == AFI_L2VPN) {
17624 if (safi == SAFI_EVPN)
17625 vty_frame(vty, "l2vpn evpn");
17626 }
17627 vty_frame(vty, "\n");
17628
17629 bgp_config_write_distance(vty, bgp, afi, safi);
17630
17631 bgp_config_write_network(vty, bgp, afi, safi);
17632
17633 bgp_config_write_redistribute(vty, bgp, afi, safi);
17634
17635 /* BGP flag dampening. */
17636 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17637 bgp_config_write_damp(vty, afi, safi);
17638
17639 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17640 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17641
17642 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17643 /* Do not display doppelganger peers */
17644 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17645 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17646 }
17647
17648 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17649 bgp_config_write_table_map(vty, bgp, afi, safi);
17650
17651 if (safi == SAFI_EVPN)
17652 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17653
17654 if (safi == SAFI_FLOWSPEC)
17655 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17656
17657 if (safi == SAFI_MPLS_VPN)
17658 bgp_vpn_config_write(vty, bgp, afi, safi);
17659
17660 if (safi == SAFI_UNICAST) {
17661 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17662 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17663 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17664
17665 vty_out(vty, " export vpn\n");
17666 }
17667 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17668 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17669
17670 vty_out(vty, " import vpn\n");
17671 }
17672 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17673 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17674 char *name;
17675
17676 for (ALL_LIST_ELEMENTS_RO(
17677 bgp->vpn_policy[afi].import_vrf, node,
17678 name))
17679 vty_out(vty, " import vrf %s\n", name);
17680 }
17681 }
17682
17683 /* Optimal Route Reflection */
17684 bgp_config_write_orr(vty, bgp, afi, safi);
17685
17686 vty_endframe(vty, " exit-address-family\n");
17687 }
17688
17689 int bgp_config_write(struct vty *vty)
17690 {
17691 struct bgp *bgp;
17692 struct peer_group *group;
17693 struct peer *peer;
17694 struct listnode *node, *nnode;
17695 struct listnode *mnode, *mnnode;
17696 afi_t afi;
17697 safi_t safi;
17698 uint32_t tovpn_sid_index = 0;
17699
17700 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17701 vty_out(vty, "bgp route-map delay-timer %u\n",
17702 bm->rmap_update_timer);
17703
17704 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17705 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17706 if (bm->v_update_delay != bm->v_establish_wait)
17707 vty_out(vty, " %d", bm->v_establish_wait);
17708 vty_out(vty, "\n");
17709 }
17710
17711 if (bm->wait_for_fib)
17712 vty_out(vty, "bgp suppress-fib-pending\n");
17713
17714 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17715 vty_out(vty, "bgp graceful-shutdown\n");
17716
17717 /* No-RIB (Zebra) option flag configuration */
17718 if (bgp_option_check(BGP_OPT_NO_FIB))
17719 vty_out(vty, "bgp no-rib\n");
17720
17721 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17722 vty_out(vty, "bgp send-extra-data zebra\n");
17723
17724 /* BGP session DSCP value */
17725 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17726 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17727
17728 /* BGP InQ limit */
17729 if (bm->inq_limit != BM_DEFAULT_INQ_LIMIT)
17730 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17731
17732 /* BGP configuration. */
17733 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17734
17735 /* skip all auto created vrf as they dont have user config */
17736 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17737 continue;
17738
17739 /* Router bgp ASN */
17740 vty_out(vty, "router bgp %u", bgp->as);
17741
17742 if (bgp->name)
17743 vty_out(vty, " %s %s",
17744 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17745 ? "view" : "vrf", bgp->name);
17746 vty_out(vty, "\n");
17747
17748 /* BGP fast-external-failover. */
17749 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17750 vty_out(vty, " no bgp fast-external-failover\n");
17751
17752 /* BGP router ID. */
17753 if (bgp->router_id_static.s_addr != INADDR_ANY)
17754 vty_out(vty, " bgp router-id %pI4\n",
17755 &bgp->router_id_static);
17756
17757 /* Suppress fib pending */
17758 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17759 vty_out(vty, " bgp suppress-fib-pending\n");
17760
17761 /* BGP log-neighbor-changes. */
17762 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17763 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17764 vty_out(vty, " %sbgp log-neighbor-changes\n",
17765 CHECK_FLAG(bgp->flags,
17766 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17767 ? ""
17768 : "no ");
17769
17770 /* BGP configuration. */
17771 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17772 vty_out(vty, " bgp always-compare-med\n");
17773
17774 /* RFC8212 default eBGP policy. */
17775 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17776 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17777 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17778 CHECK_FLAG(bgp->flags,
17779 BGP_FLAG_EBGP_REQUIRES_POLICY)
17780 ? ""
17781 : "no ");
17782
17783 /* draft-ietf-idr-deprecate-as-set-confed-set */
17784 if (bgp->reject_as_sets)
17785 vty_out(vty, " bgp reject-as-sets\n");
17786
17787 /* Suppress duplicate updates if the route actually not changed
17788 */
17789 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17790 != SAVE_BGP_SUPPRESS_DUPLICATES)
17791 vty_out(vty, " %sbgp suppress-duplicates\n",
17792 CHECK_FLAG(bgp->flags,
17793 BGP_FLAG_SUPPRESS_DUPLICATES)
17794 ? ""
17795 : "no ");
17796
17797 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17798 */
17799 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17800 SAVE_BGP_HARD_ADMIN_RESET)
17801 vty_out(vty, " %sbgp hard-administrative-reset\n",
17802 CHECK_FLAG(bgp->flags,
17803 BGP_FLAG_HARD_ADMIN_RESET)
17804 ? ""
17805 : "no ");
17806
17807 /* BGP default <afi>-<safi> */
17808 FOREACH_AFI_SAFI (afi, safi) {
17809 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17810 if (!bgp->default_af[afi][safi])
17811 vty_out(vty, " no bgp default %s\n",
17812 get_bgp_default_af_flag(afi,
17813 safi));
17814 } else if (bgp->default_af[afi][safi])
17815 vty_out(vty, " bgp default %s\n",
17816 get_bgp_default_af_flag(afi, safi));
17817 }
17818
17819 /* BGP default local-preference. */
17820 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17821 vty_out(vty, " bgp default local-preference %u\n",
17822 bgp->default_local_pref);
17823
17824 /* BGP default show-hostname */
17825 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17826 != SAVE_BGP_SHOW_HOSTNAME)
17827 vty_out(vty, " %sbgp default show-hostname\n",
17828 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17829 ? ""
17830 : "no ");
17831
17832 /* BGP default show-nexthop-hostname */
17833 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17834 != SAVE_BGP_SHOW_HOSTNAME)
17835 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17836 CHECK_FLAG(bgp->flags,
17837 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17838 ? ""
17839 : "no ");
17840
17841 /* BGP default subgroup-pkt-queue-max. */
17842 if (bgp->default_subgroup_pkt_queue_max
17843 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17844 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17845 bgp->default_subgroup_pkt_queue_max);
17846
17847 /* BGP client-to-client reflection. */
17848 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17849 vty_out(vty, " no bgp client-to-client reflection\n");
17850
17851 /* BGP cluster ID. */
17852 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17853 vty_out(vty, " bgp cluster-id %pI4\n",
17854 &bgp->cluster_id);
17855
17856 /* Disable ebgp connected nexthop check */
17857 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17858 vty_out(vty,
17859 " bgp disable-ebgp-connected-route-check\n");
17860
17861 /* Confederation identifier*/
17862 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17863 vty_out(vty, " bgp confederation identifier %u\n",
17864 bgp->confed_id);
17865
17866 /* Confederation peer */
17867 if (bgp->confed_peers_cnt > 0) {
17868 int i;
17869
17870 vty_out(vty, " bgp confederation peers");
17871
17872 for (i = 0; i < bgp->confed_peers_cnt; i++)
17873 vty_out(vty, " %u", bgp->confed_peers[i]);
17874
17875 vty_out(vty, "\n");
17876 }
17877
17878 /* BGP deterministic-med. */
17879 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17880 != SAVE_BGP_DETERMINISTIC_MED)
17881 vty_out(vty, " %sbgp deterministic-med\n",
17882 CHECK_FLAG(bgp->flags,
17883 BGP_FLAG_DETERMINISTIC_MED)
17884 ? ""
17885 : "no ");
17886
17887 /* BGP update-delay. */
17888 bgp_config_write_update_delay(vty, bgp);
17889
17890 if (bgp->v_maxmed_onstartup
17891 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17892 vty_out(vty, " bgp max-med on-startup %u",
17893 bgp->v_maxmed_onstartup);
17894 if (bgp->maxmed_onstartup_value
17895 != BGP_MAXMED_VALUE_DEFAULT)
17896 vty_out(vty, " %u",
17897 bgp->maxmed_onstartup_value);
17898 vty_out(vty, "\n");
17899 }
17900 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17901 vty_out(vty, " bgp max-med administrative");
17902 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17903 vty_out(vty, " %u", bgp->maxmed_admin_value);
17904 vty_out(vty, "\n");
17905 }
17906
17907 /* write quanta */
17908 bgp_config_write_wpkt_quanta(vty, bgp);
17909 /* read quanta */
17910 bgp_config_write_rpkt_quanta(vty, bgp);
17911
17912 /* coalesce time */
17913 bgp_config_write_coalesce_time(vty, bgp);
17914
17915 /* BGP per-instance graceful-shutdown */
17916 /* BGP-wide settings and per-instance settings are mutually
17917 * exclusive.
17918 */
17919 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17920 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17921 vty_out(vty, " bgp graceful-shutdown\n");
17922
17923 /* Long-lived Graceful Restart */
17924 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17925 vty_out(vty,
17926 " bgp long-lived-graceful-restart stale-time %u\n",
17927 bgp->llgr_stale_time);
17928
17929 /* BGP graceful-restart. */
17930 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17931 vty_out(vty,
17932 " bgp graceful-restart stalepath-time %u\n",
17933 bgp->stalepath_time);
17934
17935 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17936 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17937 bgp->restart_time);
17938
17939 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17940 SAVE_BGP_GRACEFUL_NOTIFICATION)
17941 vty_out(vty, " %sbgp graceful-restart notification\n",
17942 CHECK_FLAG(bgp->flags,
17943 BGP_FLAG_GRACEFUL_NOTIFICATION)
17944 ? ""
17945 : "no ");
17946
17947 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17948 vty_out(vty,
17949 " bgp graceful-restart select-defer-time %u\n",
17950 bgp->select_defer_time);
17951
17952 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17953 vty_out(vty, " bgp graceful-restart\n");
17954
17955 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17956 vty_out(vty, " bgp graceful-restart-disable\n");
17957
17958 /* BGP graceful-restart Preserve State F bit. */
17959 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17960 vty_out(vty,
17961 " bgp graceful-restart preserve-fw-state\n");
17962
17963 /* BGP TCP keepalive */
17964 bgp_config_tcp_keepalive(vty, bgp);
17965
17966 /* Stale timer for RIB */
17967 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17968 vty_out(vty,
17969 " bgp graceful-restart rib-stale-time %u\n",
17970 bgp->rib_stale_time);
17971
17972 /* BGP bestpath method. */
17973 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17974 vty_out(vty, " bgp bestpath as-path ignore\n");
17975 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17976 vty_out(vty, " bgp bestpath as-path confed\n");
17977
17978 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17979 if (CHECK_FLAG(bgp->flags,
17980 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17981 vty_out(vty,
17982 " bgp bestpath as-path multipath-relax as-set\n");
17983 } else {
17984 vty_out(vty,
17985 " bgp bestpath as-path multipath-relax\n");
17986 }
17987 }
17988
17989 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17990 vty_out(vty,
17991 " bgp route-reflector allow-outbound-policy\n");
17992 }
17993 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17994 vty_out(vty, " bgp bestpath compare-routerid\n");
17995 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17996 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17997 vty_out(vty, " bgp bestpath med");
17998 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17999 vty_out(vty, " confed");
18000 if (CHECK_FLAG(bgp->flags,
18001 BGP_FLAG_MED_MISSING_AS_WORST))
18002 vty_out(vty, " missing-as-worst");
18003 vty_out(vty, "\n");
18004 }
18005
18006 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18007 vty_out(vty,
18008 " bgp bestpath peer-type multipath-relax\n");
18009
18010 /* Link bandwidth handling. */
18011 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18012 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18013 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18014 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18015 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18016 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18017
18018 /* BGP network import check. */
18019 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18020 != SAVE_BGP_IMPORT_CHECK)
18021 vty_out(vty, " %sbgp network import-check\n",
18022 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18023 ? ""
18024 : "no ");
18025
18026 /* BGP timers configuration. */
18027 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18028 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18029 vty_out(vty, " timers bgp %u %u\n",
18030 bgp->default_keepalive, bgp->default_holdtime);
18031
18032 /* BGP minimum holdtime configuration. */
18033 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18034 && bgp->default_min_holdtime != 0)
18035 vty_out(vty, " bgp minimum-holdtime %u\n",
18036 bgp->default_min_holdtime);
18037
18038 /* Conditional advertisement timer configuration */
18039 if (bgp->condition_check_period
18040 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18041 vty_out(vty,
18042 " bgp conditional-advertisement timer %u\n",
18043 bgp->condition_check_period);
18044
18045 /* peer-group */
18046 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18047 bgp_config_write_peer_global(vty, bgp, group->conf);
18048 }
18049
18050 /* Normal neighbor configuration. */
18051 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18052 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18053 bgp_config_write_peer_global(vty, bgp, peer);
18054 }
18055
18056 /* listen range and limit for dynamic BGP neighbors */
18057 bgp_config_write_listen(vty, bgp);
18058
18059 /*
18060 * BGP default autoshutdown neighbors
18061 *
18062 * This must be placed after any peer and peer-group
18063 * configuration, to avoid setting all peers to shutdown after
18064 * a daemon restart, which is undesired behavior. (see #2286)
18065 */
18066 if (bgp->autoshutdown)
18067 vty_out(vty, " bgp default shutdown\n");
18068
18069 /* BGP instance administrative shutdown */
18070 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18071 vty_out(vty, " bgp shutdown\n");
18072
18073 if (bgp->allow_martian)
18074 vty_out(vty, " bgp allow-martian-nexthop\n");
18075
18076 if (bgp->fast_convergence)
18077 vty_out(vty, " bgp fast-convergence\n");
18078
18079 if (bgp->srv6_enabled) {
18080 vty_frame(vty, " !\n segment-routing srv6\n");
18081 if (strlen(bgp->srv6_locator_name))
18082 vty_out(vty, " locator %s\n",
18083 bgp->srv6_locator_name);
18084 vty_endframe(vty, " exit\n");
18085 }
18086
18087 tovpn_sid_index = bgp->tovpn_sid_index;
18088 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18089 vty_out(vty, " sid vpn per-vrf export auto\n");
18090 } else if (tovpn_sid_index != 0) {
18091 vty_out(vty, " sid vpn per-vrf export %d\n",
18092 tovpn_sid_index);
18093 }
18094
18095 /* IPv4 unicast configuration. */
18096 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18097
18098 /* IPv4 multicast configuration. */
18099 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18100
18101 /* IPv4 labeled-unicast configuration. */
18102 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18103
18104 /* IPv4 VPN configuration. */
18105 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18106
18107 /* ENCAPv4 configuration. */
18108 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18109
18110 /* FLOWSPEC v4 configuration. */
18111 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18112
18113 /* IPv6 unicast configuration. */
18114 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18115
18116 /* IPv6 multicast configuration. */
18117 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18118
18119 /* IPv6 labeled-unicast configuration. */
18120 bgp_config_write_family(vty, bgp, AFI_IP6,
18121 SAFI_LABELED_UNICAST);
18122
18123 /* IPv6 VPN configuration. */
18124 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18125
18126 /* ENCAPv6 configuration. */
18127 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18128
18129 /* FLOWSPEC v6 configuration. */
18130 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18131
18132 /* EVPN configuration. */
18133 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18134
18135 hook_call(bgp_inst_config_write, bgp, vty);
18136
18137 #ifdef ENABLE_BGP_VNC
18138 bgp_rfapi_cfg_write(vty, bgp);
18139 #endif
18140
18141 vty_out(vty, "exit\n");
18142 vty_out(vty, "!\n");
18143 }
18144 return 0;
18145 }
18146
18147
18148 /* BGP node structure. */
18149 static struct cmd_node bgp_node = {
18150 .name = "bgp",
18151 .node = BGP_NODE,
18152 .parent_node = CONFIG_NODE,
18153 .prompt = "%s(config-router)# ",
18154 .config_write = bgp_config_write,
18155 };
18156
18157 static struct cmd_node bgp_ipv4_unicast_node = {
18158 .name = "bgp ipv4 unicast",
18159 .node = BGP_IPV4_NODE,
18160 .parent_node = BGP_NODE,
18161 .prompt = "%s(config-router-af)# ",
18162 .no_xpath = true,
18163 };
18164
18165 static struct cmd_node bgp_ipv4_multicast_node = {
18166 .name = "bgp ipv4 multicast",
18167 .node = BGP_IPV4M_NODE,
18168 .parent_node = BGP_NODE,
18169 .prompt = "%s(config-router-af)# ",
18170 .no_xpath = true,
18171 };
18172
18173 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18174 .name = "bgp ipv4 labeled unicast",
18175 .node = BGP_IPV4L_NODE,
18176 .parent_node = BGP_NODE,
18177 .prompt = "%s(config-router-af)# ",
18178 .no_xpath = true,
18179 };
18180
18181 static struct cmd_node bgp_ipv6_unicast_node = {
18182 .name = "bgp ipv6 unicast",
18183 .node = BGP_IPV6_NODE,
18184 .parent_node = BGP_NODE,
18185 .prompt = "%s(config-router-af)# ",
18186 .no_xpath = true,
18187 };
18188
18189 static struct cmd_node bgp_ipv6_multicast_node = {
18190 .name = "bgp ipv6 multicast",
18191 .node = BGP_IPV6M_NODE,
18192 .parent_node = BGP_NODE,
18193 .prompt = "%s(config-router-af)# ",
18194 .no_xpath = true,
18195 };
18196
18197 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18198 .name = "bgp ipv6 labeled unicast",
18199 .node = BGP_IPV6L_NODE,
18200 .parent_node = BGP_NODE,
18201 .prompt = "%s(config-router-af)# ",
18202 .no_xpath = true,
18203 };
18204
18205 static struct cmd_node bgp_vpnv4_node = {
18206 .name = "bgp vpnv4",
18207 .node = BGP_VPNV4_NODE,
18208 .parent_node = BGP_NODE,
18209 .prompt = "%s(config-router-af)# ",
18210 .no_xpath = true,
18211 };
18212
18213 static struct cmd_node bgp_vpnv6_node = {
18214 .name = "bgp vpnv6",
18215 .node = BGP_VPNV6_NODE,
18216 .parent_node = BGP_NODE,
18217 .prompt = "%s(config-router-af-vpnv6)# ",
18218 .no_xpath = true,
18219 };
18220
18221 static struct cmd_node bgp_evpn_node = {
18222 .name = "bgp evpn",
18223 .node = BGP_EVPN_NODE,
18224 .parent_node = BGP_NODE,
18225 .prompt = "%s(config-router-evpn)# ",
18226 .no_xpath = true,
18227 };
18228
18229 static struct cmd_node bgp_evpn_vni_node = {
18230 .name = "bgp evpn vni",
18231 .node = BGP_EVPN_VNI_NODE,
18232 .parent_node = BGP_EVPN_NODE,
18233 .prompt = "%s(config-router-af-vni)# ",
18234 };
18235
18236 static struct cmd_node bgp_flowspecv4_node = {
18237 .name = "bgp ipv4 flowspec",
18238 .node = BGP_FLOWSPECV4_NODE,
18239 .parent_node = BGP_NODE,
18240 .prompt = "%s(config-router-af)# ",
18241 .no_xpath = true,
18242 };
18243
18244 static struct cmd_node bgp_flowspecv6_node = {
18245 .name = "bgp ipv6 flowspec",
18246 .node = BGP_FLOWSPECV6_NODE,
18247 .parent_node = BGP_NODE,
18248 .prompt = "%s(config-router-af-vpnv6)# ",
18249 .no_xpath = true,
18250 };
18251
18252 static struct cmd_node bgp_srv6_node = {
18253 .name = "bgp srv6",
18254 .node = BGP_SRV6_NODE,
18255 .parent_node = BGP_NODE,
18256 .prompt = "%s(config-router-srv6)# ",
18257 };
18258
18259 static void community_list_vty(void);
18260
18261 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18262 {
18263 struct bgp *bgp;
18264 struct peer_group *group;
18265 struct listnode *lnbgp, *lnpeer;
18266
18267 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18268 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18269 vector_set(comps,
18270 XSTRDUP(MTYPE_COMPLETION, group->name));
18271 }
18272 }
18273
18274 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18275 {
18276 struct bgp *bgp;
18277 struct peer *peer;
18278 struct listnode *lnbgp, *lnpeer;
18279
18280 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18281 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18282 /* only provide suggestions on the appropriate input
18283 * token type,
18284 * they'll otherwise show up multiple times */
18285 enum cmd_token_type match_type;
18286 char *name = peer->host;
18287
18288 if (peer->conf_if) {
18289 match_type = VARIABLE_TKN;
18290 name = peer->conf_if;
18291 } else if (strchr(peer->host, ':'))
18292 match_type = IPV6_TKN;
18293 else
18294 match_type = IPV4_TKN;
18295
18296 if (token->type != match_type)
18297 continue;
18298
18299 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18300 }
18301 }
18302 }
18303
18304 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18305 {
18306 bgp_ac_peer(comps, token);
18307
18308 if (token->type == VARIABLE_TKN)
18309 bgp_ac_peergroup(comps, token);
18310 }
18311
18312 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18313 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18314 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18315 {.varname = "peer", .completions = bgp_ac_neighbor},
18316 {.completions = NULL}};
18317
18318 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18319 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18320 {.completions = NULL} };
18321
18322 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18323
18324 static struct thread *t_bgp_cfg;
18325
18326 bool bgp_config_inprocess(void)
18327 {
18328 return thread_is_scheduled(t_bgp_cfg);
18329 }
18330
18331 static void bgp_config_finish(struct thread *t)
18332 {
18333 struct listnode *node;
18334 struct bgp *bgp;
18335
18336 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18337 hook_call(bgp_config_end, bgp);
18338 }
18339
18340 static void bgp_config_start(void)
18341 {
18342 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18343 THREAD_OFF(t_bgp_cfg);
18344 thread_add_timer(bm->master, bgp_config_finish, NULL,
18345 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18346 }
18347
18348 /* When we receive a hook the configuration is read,
18349 * we start a timer to make sure we postpone sending
18350 * EoR before route-maps are processed.
18351 * This is especially valid if using `bgp route-map delay-timer`.
18352 */
18353 static void bgp_config_end(void)
18354 {
18355 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18356 uint32_t bgp_post_config_delay =
18357 thread_is_scheduled(bm->t_rmap_update)
18358 ? thread_timer_remain_second(bm->t_rmap_update)
18359 : BGP_POST_CONFIG_DELAY_SECONDS;
18360
18361 /* If BGP config processing thread isn't running, then
18362 * we can return and rely it's properly handled.
18363 */
18364 if (!bgp_config_inprocess())
18365 return;
18366
18367 THREAD_OFF(t_bgp_cfg);
18368
18369 /* Start a new timer to make sure we don't send EoR
18370 * before route-maps are processed.
18371 */
18372 thread_add_timer(bm->master, bgp_config_finish, NULL,
18373 bgp_post_config_delay, &t_bgp_cfg);
18374 }
18375
18376 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18377 {
18378 int write = 0;
18379 struct interface *ifp;
18380 struct bgp_interface *iifp;
18381
18382 FOR_ALL_INTERFACES (vrf, ifp) {
18383 iifp = ifp->info;
18384 if (!iifp)
18385 continue;
18386
18387 if_vty_config_start(vty, ifp);
18388
18389 if (CHECK_FLAG(iifp->flags,
18390 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18391 vty_out(vty, " mpls bgp forwarding\n");
18392 write++;
18393 }
18394
18395 if_vty_config_end(vty);
18396 }
18397
18398 return write;
18399 }
18400
18401 /* Configuration write function for bgpd. */
18402 static int config_write_interface(struct vty *vty)
18403 {
18404 int write = 0;
18405 struct vrf *vrf = NULL;
18406
18407 /* Display all VRF aware OSPF interface configuration */
18408 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18409 write += config_write_interface_one(vty, vrf);
18410 }
18411
18412 return write;
18413 }
18414
18415 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18416 "[no$no] mpls bgp forwarding",
18417 NO_STR MPLS_STR BGP_STR
18418 "Enable MPLS forwarding for eBGP directly connected peers\n")
18419 {
18420 bool check;
18421 struct bgp_interface *iifp;
18422
18423 VTY_DECLVAR_CONTEXT(interface, ifp);
18424 iifp = ifp->info;
18425 if (!iifp) {
18426 vty_out(vty, "Interface %s not available\n", ifp->name);
18427 return CMD_WARNING_CONFIG_FAILED;
18428 }
18429 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18430 if (check != !no) {
18431 if (no)
18432 UNSET_FLAG(iifp->flags,
18433 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18434 else
18435 SET_FLAG(iifp->flags,
18436 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18437 /* trigger a nht update on eBGP sessions */
18438 if (if_is_operative(ifp))
18439 bgp_nht_ifp_up(ifp);
18440 }
18441 return CMD_SUCCESS;
18442 }
18443
18444 DEFPY (bgp_inq_limit,
18445 bgp_inq_limit_cmd,
18446 "bgp input-queue-limit (1-4294967295)$limit",
18447 BGP_STR
18448 "Set the BGP Input Queue limit for all peers when message parsing\n"
18449 "Input-Queue limit\n")
18450 {
18451 bm->inq_limit = limit;
18452
18453 return CMD_SUCCESS;
18454 }
18455
18456 DEFPY (no_bgp_inq_limit,
18457 no_bgp_inq_limit_cmd,
18458 "no bgp input-queue-limit [(1-4294967295)$limit]",
18459 NO_STR
18460 BGP_STR
18461 "Set the BGP Input Queue limit for all peers when message parsing\n"
18462 "Input-Queue limit\n")
18463 {
18464 bm->inq_limit = BM_DEFAULT_INQ_LIMIT;
18465
18466 return CMD_SUCCESS;
18467 }
18468
18469 /* Initialization of BGP interface. */
18470 static void bgp_vty_if_init(void)
18471 {
18472 /* Install interface node. */
18473 if_cmd_init(config_write_interface);
18474
18475 /* "mpls bgp forwarding" commands. */
18476 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18477 }
18478
18479 void bgp_vty_init(void)
18480 {
18481 cmd_variable_handler_register(bgp_var_neighbor);
18482 cmd_variable_handler_register(bgp_var_peergroup);
18483
18484 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18485
18486 /* Install bgp top node. */
18487 install_node(&bgp_node);
18488 install_node(&bgp_ipv4_unicast_node);
18489 install_node(&bgp_ipv4_multicast_node);
18490 install_node(&bgp_ipv4_labeled_unicast_node);
18491 install_node(&bgp_ipv6_unicast_node);
18492 install_node(&bgp_ipv6_multicast_node);
18493 install_node(&bgp_ipv6_labeled_unicast_node);
18494 install_node(&bgp_vpnv4_node);
18495 install_node(&bgp_vpnv6_node);
18496 install_node(&bgp_evpn_node);
18497 install_node(&bgp_evpn_vni_node);
18498 install_node(&bgp_flowspecv4_node);
18499 install_node(&bgp_flowspecv6_node);
18500 install_node(&bgp_srv6_node);
18501
18502 /* Install default VTY commands to new nodes. */
18503 install_default(BGP_NODE);
18504 install_default(BGP_IPV4_NODE);
18505 install_default(BGP_IPV4M_NODE);
18506 install_default(BGP_IPV4L_NODE);
18507 install_default(BGP_IPV6_NODE);
18508 install_default(BGP_IPV6M_NODE);
18509 install_default(BGP_IPV6L_NODE);
18510 install_default(BGP_VPNV4_NODE);
18511 install_default(BGP_VPNV6_NODE);
18512 install_default(BGP_FLOWSPECV4_NODE);
18513 install_default(BGP_FLOWSPECV6_NODE);
18514 install_default(BGP_EVPN_NODE);
18515 install_default(BGP_EVPN_VNI_NODE);
18516 install_default(BGP_SRV6_NODE);
18517
18518 /* "global bgp inq-limit command */
18519 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18520 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18521
18522 /* "bgp local-mac" hidden commands. */
18523 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18524 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18525
18526 /* "bgp suppress-fib-pending" global */
18527 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18528
18529 /* bgp route-map delay-timer commands. */
18530 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18531 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18532
18533 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18534
18535 /* bgp fast-convergence command */
18536 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18537 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18538
18539 /* global bgp update-delay command */
18540 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18541 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18542
18543 /* global bgp graceful-shutdown command */
18544 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18545 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18546
18547 /* Dummy commands (Currently not supported) */
18548 install_element(BGP_NODE, &no_synchronization_cmd);
18549 install_element(BGP_NODE, &no_auto_summary_cmd);
18550
18551 /* "router bgp" commands. */
18552 install_element(CONFIG_NODE, &router_bgp_cmd);
18553
18554 /* "no router bgp" commands. */
18555 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18556
18557 /* "bgp session-dscp command */
18558 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18559 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18560
18561 /* "bgp router-id" commands. */
18562 install_element(BGP_NODE, &bgp_router_id_cmd);
18563 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18564
18565 /* "bgp suppress-fib-pending" command */
18566 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18567
18568 /* "bgp cluster-id" commands. */
18569 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18570 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18571
18572 /* "bgp no-rib" commands. */
18573 install_element(CONFIG_NODE, &bgp_norib_cmd);
18574 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18575
18576 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18577
18578 /* "bgp confederation" commands. */
18579 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18580 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18581
18582 /* "bgp confederation peers" commands. */
18583 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18584 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18585
18586 /* bgp max-med command */
18587 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18588 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18589 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18590 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18591 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18592
18593 /* "neighbor role" commands. */
18594 install_element(BGP_NODE, &neighbor_role_cmd);
18595 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18596 install_element(BGP_NODE, &no_neighbor_role_cmd);
18597
18598 /* bgp disable-ebgp-connected-nh-check */
18599 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18600 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18601
18602 /* bgp update-delay command */
18603 install_element(BGP_NODE, &bgp_update_delay_cmd);
18604 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18605
18606 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18607 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18608
18609 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18610 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18611
18612 /* "maximum-paths" commands. */
18613 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18614 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18615 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18616 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18617 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18618 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18619 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18620 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18621 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18622 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18623 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18624 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18625 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18626 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18627 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18628
18629 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18630 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18631 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18632 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18633 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18634 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18635 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18636 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18637 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18638 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18639
18640 /* "timers bgp" commands. */
18641 install_element(BGP_NODE, &bgp_timers_cmd);
18642 install_element(BGP_NODE, &no_bgp_timers_cmd);
18643
18644 /* "minimum-holdtime" commands. */
18645 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18646 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18647
18648 /* route-map delay-timer commands - per instance for backwards compat.
18649 */
18650 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18651 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18652
18653 /* "bgp client-to-client reflection" commands */
18654 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18655 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18656
18657 /* "bgp always-compare-med" commands */
18658 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18659 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18660
18661 /* bgp ebgp-requires-policy */
18662 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18663 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18664
18665 /* bgp suppress-duplicates */
18666 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18667 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18668
18669 /* bgp reject-as-sets */
18670 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18671 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18672
18673 /* "bgp deterministic-med" commands */
18674 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18675 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18676
18677 /* "bgp graceful-restart" command */
18678 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18679 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18680
18681 /* "bgp graceful-restart-disable" command */
18682 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18683 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18684
18685 /* "neighbor a:b:c:d graceful-restart" command */
18686 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18687 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18688
18689 /* "neighbor a:b:c:d graceful-restart-disable" command */
18690 install_element(BGP_NODE,
18691 &bgp_neighbor_graceful_restart_disable_set_cmd);
18692 install_element(BGP_NODE,
18693 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18694
18695 /* "neighbor a:b:c:d graceful-restart-helper" command */
18696 install_element(BGP_NODE,
18697 &bgp_neighbor_graceful_restart_helper_set_cmd);
18698 install_element(BGP_NODE,
18699 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18700
18701 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18702 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18703 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18704 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18705 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18706 install_element(BGP_NODE,
18707 &no_bgp_graceful_restart_select_defer_time_cmd);
18708 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18709 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18710 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18711
18712 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18713 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18714 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18715 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18716
18717 /* "bgp inq-limit command */
18718 install_element(BGP_NODE, &bgp_inq_limit_cmd);
18719 install_element(BGP_NODE, &no_bgp_inq_limit_cmd);
18720
18721 /* "bgp graceful-shutdown" commands */
18722 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18723 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18724
18725 /* "bgp hard-administrative-reset" commands */
18726 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18727
18728 /* "bgp long-lived-graceful-restart" commands */
18729 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18730 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18731
18732 /* "bgp fast-external-failover" commands */
18733 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18734 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18735
18736 /* "bgp bestpath compare-routerid" commands */
18737 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18738 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18739
18740 /* "bgp bestpath as-path ignore" commands */
18741 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18742 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18743
18744 /* "bgp bestpath as-path confed" commands */
18745 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18746 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18747
18748 /* "bgp bestpath as-path multipath-relax" commands */
18749 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18750 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18751
18752 /* "bgp bestpath peer-type multipath-relax" commands */
18753 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18754 install_element(BGP_NODE,
18755 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18756
18757 /* "bgp log-neighbor-changes" commands */
18758 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18759 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18760
18761 /* "bgp bestpath med" commands */
18762 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18763 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18764
18765 /* "bgp bestpath bandwidth" commands */
18766 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18767 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18768
18769 /* "no bgp default <afi>-<safi>" commands. */
18770 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18771
18772 /* "bgp network import-check" commands. */
18773 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18774 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18775 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18776
18777 /* "bgp default local-preference" commands. */
18778 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18779 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18780
18781 /* bgp default show-hostname */
18782 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18783 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18784
18785 /* bgp default show-nexthop-hostname */
18786 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18787 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18788
18789 /* "bgp default subgroup-pkt-queue-max" commands. */
18790 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18791 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18792
18793 /* bgp ibgp-allow-policy-mods command */
18794 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18795 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18796
18797 /* "bgp listen limit" commands. */
18798 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18799 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18800
18801 /* "bgp listen range" commands. */
18802 install_element(BGP_NODE, &bgp_listen_range_cmd);
18803 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18804
18805 /* "bgp default shutdown" command */
18806 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18807
18808 /* "bgp shutdown" commands */
18809 install_element(BGP_NODE, &bgp_shutdown_cmd);
18810 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18811 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18812 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18813
18814 /* "neighbor remote-as" commands. */
18815 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18816 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18817 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18818 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18819 install_element(BGP_NODE,
18820 &neighbor_interface_v6only_config_remote_as_cmd);
18821 install_element(BGP_NODE, &no_neighbor_cmd);
18822 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18823
18824 /* "neighbor peer-group" commands. */
18825 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18826 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18827 install_element(BGP_NODE,
18828 &no_neighbor_interface_peer_group_remote_as_cmd);
18829
18830 /* "neighbor local-as" commands. */
18831 install_element(BGP_NODE, &neighbor_local_as_cmd);
18832 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18833 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18834 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18835
18836 /* "neighbor solo" commands. */
18837 install_element(BGP_NODE, &neighbor_solo_cmd);
18838 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18839
18840 /* "neighbor password" commands. */
18841 install_element(BGP_NODE, &neighbor_password_cmd);
18842 install_element(BGP_NODE, &no_neighbor_password_cmd);
18843
18844 /* "neighbor activate" commands. */
18845 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18846 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18847 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18848 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18849 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18850 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18851 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18852 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18853 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18854 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18855 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18856 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18857
18858 /* "no neighbor activate" commands. */
18859 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18860 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18861 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18862 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18863 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18864 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18865 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18866 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18867 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18868 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18869 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18870 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18871
18872 /* "neighbor peer-group" set commands. */
18873 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18874 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18875 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18876 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18877 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18878 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18879 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18880 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18881 install_element(BGP_FLOWSPECV4_NODE,
18882 &neighbor_set_peer_group_hidden_cmd);
18883 install_element(BGP_FLOWSPECV6_NODE,
18884 &neighbor_set_peer_group_hidden_cmd);
18885
18886 /* "no neighbor peer-group unset" commands. */
18887 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18888 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18889 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18890 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18891 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18892 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18893 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18894 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18895 install_element(BGP_FLOWSPECV4_NODE,
18896 &no_neighbor_set_peer_group_hidden_cmd);
18897 install_element(BGP_FLOWSPECV6_NODE,
18898 &no_neighbor_set_peer_group_hidden_cmd);
18899
18900 /* "neighbor softreconfiguration inbound" commands.*/
18901 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18902 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18903 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18904 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18905 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18906 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18907 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18908 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18909 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18910 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18911 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18912 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18913 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18914 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18915 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18916 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18917 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18918 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18919 install_element(BGP_FLOWSPECV4_NODE,
18920 &neighbor_soft_reconfiguration_cmd);
18921 install_element(BGP_FLOWSPECV4_NODE,
18922 &no_neighbor_soft_reconfiguration_cmd);
18923 install_element(BGP_FLOWSPECV6_NODE,
18924 &neighbor_soft_reconfiguration_cmd);
18925 install_element(BGP_FLOWSPECV6_NODE,
18926 &no_neighbor_soft_reconfiguration_cmd);
18927 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18928 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18929
18930 /* "neighbor attribute-unchanged" commands. */
18931 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18932 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18933 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18934 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18935 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18936 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18937 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18938 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18939 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18940 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18941 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18942 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18943 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18944 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18945 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18946 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18947 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18948 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18949
18950 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18951 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18952
18953 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18954 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18955 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18956 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18957
18958 /* "nexthop-local unchanged" commands */
18959 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18960 install_element(BGP_IPV6_NODE,
18961 &no_neighbor_nexthop_local_unchanged_cmd);
18962
18963 /* "neighbor next-hop-self" commands. */
18964 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18965 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18966 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18967 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18968 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18969 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18970 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18971 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18972 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18973 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18974 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18975 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18976 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18977 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18978 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18979 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18980 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18981 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18982 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18983 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18984
18985 /* "neighbor next-hop-self force" commands. */
18986 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18987 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18988 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18989 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18990 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18991 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18992 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18993 install_element(BGP_IPV4_NODE,
18994 &no_neighbor_nexthop_self_all_hidden_cmd);
18995 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18996 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18997 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18998 install_element(BGP_IPV4M_NODE,
18999 &no_neighbor_nexthop_self_all_hidden_cmd);
19000 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19001 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19002 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19003 install_element(BGP_IPV4L_NODE,
19004 &no_neighbor_nexthop_self_all_hidden_cmd);
19005 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19006 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19007 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19008 install_element(BGP_IPV6_NODE,
19009 &no_neighbor_nexthop_self_all_hidden_cmd);
19010 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19011 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19012 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19013 install_element(BGP_IPV6M_NODE,
19014 &no_neighbor_nexthop_self_all_hidden_cmd);
19015 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19016 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19017 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19018 install_element(BGP_IPV6L_NODE,
19019 &no_neighbor_nexthop_self_all_hidden_cmd);
19020 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19021 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19022 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19023 install_element(BGP_VPNV4_NODE,
19024 &no_neighbor_nexthop_self_all_hidden_cmd);
19025 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19026 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19027 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19028 install_element(BGP_VPNV6_NODE,
19029 &no_neighbor_nexthop_self_all_hidden_cmd);
19030 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19031 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19032
19033 /* "neighbor as-override" commands. */
19034 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19035 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19036 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19037 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19038 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19039 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19040 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19041 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19042 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19043 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19044 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19045 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19046 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19047 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19048 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19049 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19050 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19051 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19052
19053 /* "neighbor remove-private-AS" commands. */
19054 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19055 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19056 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19057 install_element(BGP_NODE,
19058 &no_neighbor_remove_private_as_all_hidden_cmd);
19059 install_element(BGP_NODE,
19060 &neighbor_remove_private_as_replace_as_hidden_cmd);
19061 install_element(BGP_NODE,
19062 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19063 install_element(BGP_NODE,
19064 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19065 install_element(
19066 BGP_NODE,
19067 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19068 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19069 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19070 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19071 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19072 install_element(BGP_IPV4_NODE,
19073 &neighbor_remove_private_as_replace_as_cmd);
19074 install_element(BGP_IPV4_NODE,
19075 &no_neighbor_remove_private_as_replace_as_cmd);
19076 install_element(BGP_IPV4_NODE,
19077 &neighbor_remove_private_as_all_replace_as_cmd);
19078 install_element(BGP_IPV4_NODE,
19079 &no_neighbor_remove_private_as_all_replace_as_cmd);
19080 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19081 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19082 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19083 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19084 install_element(BGP_IPV4M_NODE,
19085 &neighbor_remove_private_as_replace_as_cmd);
19086 install_element(BGP_IPV4M_NODE,
19087 &no_neighbor_remove_private_as_replace_as_cmd);
19088 install_element(BGP_IPV4M_NODE,
19089 &neighbor_remove_private_as_all_replace_as_cmd);
19090 install_element(BGP_IPV4M_NODE,
19091 &no_neighbor_remove_private_as_all_replace_as_cmd);
19092 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19093 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19094 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19095 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19096 install_element(BGP_IPV4L_NODE,
19097 &neighbor_remove_private_as_replace_as_cmd);
19098 install_element(BGP_IPV4L_NODE,
19099 &no_neighbor_remove_private_as_replace_as_cmd);
19100 install_element(BGP_IPV4L_NODE,
19101 &neighbor_remove_private_as_all_replace_as_cmd);
19102 install_element(BGP_IPV4L_NODE,
19103 &no_neighbor_remove_private_as_all_replace_as_cmd);
19104 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19105 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19106 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19107 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19108 install_element(BGP_IPV6_NODE,
19109 &neighbor_remove_private_as_replace_as_cmd);
19110 install_element(BGP_IPV6_NODE,
19111 &no_neighbor_remove_private_as_replace_as_cmd);
19112 install_element(BGP_IPV6_NODE,
19113 &neighbor_remove_private_as_all_replace_as_cmd);
19114 install_element(BGP_IPV6_NODE,
19115 &no_neighbor_remove_private_as_all_replace_as_cmd);
19116 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19117 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19118 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19119 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19120 install_element(BGP_IPV6M_NODE,
19121 &neighbor_remove_private_as_replace_as_cmd);
19122 install_element(BGP_IPV6M_NODE,
19123 &no_neighbor_remove_private_as_replace_as_cmd);
19124 install_element(BGP_IPV6M_NODE,
19125 &neighbor_remove_private_as_all_replace_as_cmd);
19126 install_element(BGP_IPV6M_NODE,
19127 &no_neighbor_remove_private_as_all_replace_as_cmd);
19128 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19129 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19130 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19131 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19132 install_element(BGP_IPV6L_NODE,
19133 &neighbor_remove_private_as_replace_as_cmd);
19134 install_element(BGP_IPV6L_NODE,
19135 &no_neighbor_remove_private_as_replace_as_cmd);
19136 install_element(BGP_IPV6L_NODE,
19137 &neighbor_remove_private_as_all_replace_as_cmd);
19138 install_element(BGP_IPV6L_NODE,
19139 &no_neighbor_remove_private_as_all_replace_as_cmd);
19140 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19141 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19142 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19143 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19144 install_element(BGP_VPNV4_NODE,
19145 &neighbor_remove_private_as_replace_as_cmd);
19146 install_element(BGP_VPNV4_NODE,
19147 &no_neighbor_remove_private_as_replace_as_cmd);
19148 install_element(BGP_VPNV4_NODE,
19149 &neighbor_remove_private_as_all_replace_as_cmd);
19150 install_element(BGP_VPNV4_NODE,
19151 &no_neighbor_remove_private_as_all_replace_as_cmd);
19152 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19153 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19154 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19155 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19156 install_element(BGP_VPNV6_NODE,
19157 &neighbor_remove_private_as_replace_as_cmd);
19158 install_element(BGP_VPNV6_NODE,
19159 &no_neighbor_remove_private_as_replace_as_cmd);
19160 install_element(BGP_VPNV6_NODE,
19161 &neighbor_remove_private_as_all_replace_as_cmd);
19162 install_element(BGP_VPNV6_NODE,
19163 &no_neighbor_remove_private_as_all_replace_as_cmd);
19164
19165 /* "neighbor send-community" commands.*/
19166 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19167 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19168 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19169 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19170 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19171 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19172 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19173 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19174 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19175 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19176 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19177 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19178 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19179 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19180 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19181 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19182 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19183 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19184 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19185 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19186 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19187 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19188 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19189 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19190 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19191 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19192 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19193 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19194 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19195 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19196 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19197 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19198 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19199 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19200 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19201 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19202
19203 /* "neighbor route-reflector" commands.*/
19204 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19205 install_element(BGP_NODE,
19206 &no_neighbor_route_reflector_client_hidden_cmd);
19207 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19208 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19209 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19210 install_element(BGP_IPV4M_NODE,
19211 &no_neighbor_route_reflector_client_cmd);
19212 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19213 install_element(BGP_IPV4L_NODE,
19214 &no_neighbor_route_reflector_client_cmd);
19215 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19216 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19217 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19218 install_element(BGP_IPV6M_NODE,
19219 &no_neighbor_route_reflector_client_cmd);
19220 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19221 install_element(BGP_IPV6L_NODE,
19222 &no_neighbor_route_reflector_client_cmd);
19223 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19224 install_element(BGP_VPNV4_NODE,
19225 &no_neighbor_route_reflector_client_cmd);
19226 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19227 install_element(BGP_VPNV6_NODE,
19228 &no_neighbor_route_reflector_client_cmd);
19229 install_element(BGP_FLOWSPECV4_NODE,
19230 &neighbor_route_reflector_client_cmd);
19231 install_element(BGP_FLOWSPECV4_NODE,
19232 &no_neighbor_route_reflector_client_cmd);
19233 install_element(BGP_FLOWSPECV6_NODE,
19234 &neighbor_route_reflector_client_cmd);
19235 install_element(BGP_FLOWSPECV6_NODE,
19236 &no_neighbor_route_reflector_client_cmd);
19237 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19238 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19239
19240 /* "optimal-route-reflection" commands */
19241 install_element(BGP_IPV4_NODE, &optimal_route_reflection_cmd);
19242 install_element(BGP_IPV4M_NODE, &optimal_route_reflection_cmd);
19243 install_element(BGP_IPV4L_NODE, &optimal_route_reflection_cmd);
19244 install_element(BGP_IPV6_NODE, &optimal_route_reflection_cmd);
19245 install_element(BGP_IPV6M_NODE, &optimal_route_reflection_cmd);
19246 install_element(BGP_IPV6L_NODE, &optimal_route_reflection_cmd);
19247 install_element(BGP_VPNV4_NODE, &optimal_route_reflection_cmd);
19248 install_element(BGP_VPNV6_NODE, &optimal_route_reflection_cmd);
19249 install_element(BGP_FLOWSPECV4_NODE, &optimal_route_reflection_cmd);
19250 install_element(BGP_FLOWSPECV6_NODE, &optimal_route_reflection_cmd);
19251 install_element(BGP_EVPN_NODE, &optimal_route_reflection_cmd);
19252
19253 /* "neighbor optimal-route-reflection" commands */
19254 install_element(BGP_IPV4_NODE, &neighbor_optimal_route_reflection_cmd);
19255 install_element(BGP_IPV4M_NODE, &neighbor_optimal_route_reflection_cmd);
19256 install_element(BGP_IPV4L_NODE, &neighbor_optimal_route_reflection_cmd);
19257 install_element(BGP_IPV6_NODE, &neighbor_optimal_route_reflection_cmd);
19258 install_element(BGP_IPV6M_NODE, &neighbor_optimal_route_reflection_cmd);
19259 install_element(BGP_IPV6L_NODE, &neighbor_optimal_route_reflection_cmd);
19260 install_element(BGP_VPNV4_NODE, &neighbor_optimal_route_reflection_cmd);
19261 install_element(BGP_VPNV6_NODE, &neighbor_optimal_route_reflection_cmd);
19262 install_element(BGP_FLOWSPECV4_NODE,
19263 &neighbor_optimal_route_reflection_cmd);
19264 install_element(BGP_FLOWSPECV6_NODE,
19265 &neighbor_optimal_route_reflection_cmd);
19266 install_element(BGP_EVPN_NODE, &neighbor_optimal_route_reflection_cmd);
19267
19268 /* "neighbor route-server" commands.*/
19269 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19270 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19271 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19272 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19273 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19274 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19275 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19276 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19277 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19278 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19279 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19280 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19281 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19282 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19283 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19284 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19285 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19286 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19287 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19288 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19289 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19290 install_element(BGP_FLOWSPECV4_NODE,
19291 &no_neighbor_route_server_client_cmd);
19292 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19293 install_element(BGP_FLOWSPECV6_NODE,
19294 &no_neighbor_route_server_client_cmd);
19295
19296 /* "neighbor disable-addpath-rx" commands. */
19297 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19298 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19299 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19300 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19301 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19302 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19303 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19304 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19305 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19306 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19307 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19308 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19309 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19310 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19311 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19312 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19313
19314 /* "neighbor addpath-tx-all-paths" commands.*/
19315 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19316 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19317 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19318 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19319 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19320 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19321 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19322 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19323 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19324 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19325 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19326 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19327 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19328 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19329 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19330 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19331 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19332 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19333
19334 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19335 install_element(BGP_NODE,
19336 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19337 install_element(BGP_NODE,
19338 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19339 install_element(BGP_IPV4_NODE,
19340 &neighbor_addpath_tx_bestpath_per_as_cmd);
19341 install_element(BGP_IPV4_NODE,
19342 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19343 install_element(BGP_IPV4M_NODE,
19344 &neighbor_addpath_tx_bestpath_per_as_cmd);
19345 install_element(BGP_IPV4M_NODE,
19346 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19347 install_element(BGP_IPV4L_NODE,
19348 &neighbor_addpath_tx_bestpath_per_as_cmd);
19349 install_element(BGP_IPV4L_NODE,
19350 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19351 install_element(BGP_IPV6_NODE,
19352 &neighbor_addpath_tx_bestpath_per_as_cmd);
19353 install_element(BGP_IPV6_NODE,
19354 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19355 install_element(BGP_IPV6M_NODE,
19356 &neighbor_addpath_tx_bestpath_per_as_cmd);
19357 install_element(BGP_IPV6M_NODE,
19358 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19359 install_element(BGP_IPV6L_NODE,
19360 &neighbor_addpath_tx_bestpath_per_as_cmd);
19361 install_element(BGP_IPV6L_NODE,
19362 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19363 install_element(BGP_VPNV4_NODE,
19364 &neighbor_addpath_tx_bestpath_per_as_cmd);
19365 install_element(BGP_VPNV4_NODE,
19366 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19367 install_element(BGP_VPNV6_NODE,
19368 &neighbor_addpath_tx_bestpath_per_as_cmd);
19369 install_element(BGP_VPNV6_NODE,
19370 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19371
19372 /* "neighbor sender-as-path-loop-detection" commands. */
19373 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19374 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19375
19376 /* "neighbor passive" commands. */
19377 install_element(BGP_NODE, &neighbor_passive_cmd);
19378 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19379
19380
19381 /* "neighbor shutdown" commands. */
19382 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19383 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19384 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19385 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19386 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19387 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19388
19389 /* "neighbor capability extended-nexthop" commands.*/
19390 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19391 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19392
19393 /* "neighbor capability orf prefix-list" commands.*/
19394 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19395 install_element(BGP_NODE,
19396 &no_neighbor_capability_orf_prefix_hidden_cmd);
19397 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19398 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19399 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19400 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19401 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19402 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19403 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19404 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19405 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19406 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19407 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19408 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19409
19410 /* "neighbor capability dynamic" commands.*/
19411 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19412 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19413
19414 /* "neighbor dont-capability-negotiate" commands. */
19415 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19416 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19417
19418 /* "neighbor ebgp-multihop" commands. */
19419 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19420 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19421 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19422
19423 /* "neighbor disable-connected-check" commands. */
19424 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19425 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19426
19427 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19428 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19429 install_element(BGP_NODE,
19430 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19431
19432 /* "neighbor extended-optional-parameters" commands. */
19433 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19434 install_element(BGP_NODE,
19435 &no_neighbor_extended_optional_parameters_cmd);
19436
19437 /* "neighbor enforce-first-as" commands. */
19438 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19439 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19440
19441 /* "neighbor description" commands. */
19442 install_element(BGP_NODE, &neighbor_description_cmd);
19443 install_element(BGP_NODE, &no_neighbor_description_cmd);
19444 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19445
19446 /* "neighbor update-source" commands. "*/
19447 install_element(BGP_NODE, &neighbor_update_source_cmd);
19448 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19449
19450 /* "neighbor default-originate" commands. */
19451 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19452 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19453 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19454 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19455 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19456 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19457 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19458 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19459 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19460 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19461 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19462 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19463 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19464 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19465 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19466 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19467 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19468 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19469 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19470 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19471 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19472
19473 /* "neighbor port" commands. */
19474 install_element(BGP_NODE, &neighbor_port_cmd);
19475 install_element(BGP_NODE, &no_neighbor_port_cmd);
19476
19477 /* "neighbor weight" commands. */
19478 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19479 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19480
19481 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19482 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19483 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19484 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19485 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19486 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19487 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19488 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19489 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19490 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19491 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19492 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19493 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19494 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19495 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19496 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19497
19498 /* "neighbor override-capability" commands. */
19499 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19500 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19501
19502 /* "neighbor strict-capability-match" commands. */
19503 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19504 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19505
19506 /* "neighbor timers" commands. */
19507 install_element(BGP_NODE, &neighbor_timers_cmd);
19508 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19509
19510 /* "neighbor timers connect" commands. */
19511 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19512 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19513
19514 /* "neighbor timers delayopen" commands. */
19515 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19516 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19517
19518 /* "neighbor advertisement-interval" commands. */
19519 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19520 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19521
19522 /* "neighbor interface" commands. */
19523 install_element(BGP_NODE, &neighbor_interface_cmd);
19524 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19525
19526 /* "neighbor distribute" commands. */
19527 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19528 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19529 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19530 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19531 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19532 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19533 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19534 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19535 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19536 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19537 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19538 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19539 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19540 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19541 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19542 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19543 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19544 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19545
19546 /* "neighbor prefix-list" commands. */
19547 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19548 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19549 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19550 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19551 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19552 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19553 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19554 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19555 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19556 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19557 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19558 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19559 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19560 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19561 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19562 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19563 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19564 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19565 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19566 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19567 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19568 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19569
19570 /* "neighbor filter-list" commands. */
19571 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19572 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19573 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19574 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19575 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19576 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19577 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19578 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19579 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19580 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19581 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19582 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19583 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19584 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19585 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19586 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19587 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19588 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19589 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19590 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19591 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19592 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19593
19594 /* "neighbor route-map" commands. */
19595 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19596 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19597 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19598 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19599 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19600 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19601 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19602 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19603 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19604 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19605 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19606 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19607 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19608 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19609 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19610 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19611 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19612 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19613 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19614 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19615 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19616 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19617 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19618 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19619
19620 /* "neighbor unsuppress-map" commands. */
19621 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19622 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19623 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19624 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19625 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19626 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19627 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19628 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19629 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19630 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19631 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19632 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19633 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19634 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19635 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19636 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19637 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19638 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19639
19640 /* "neighbor advertise-map" commands. */
19641 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19642 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19643 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19644 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19645 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19646 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19647 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19648 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19649 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19650 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19651
19652 /* neighbor maximum-prefix-out commands. */
19653 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19654 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19655 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19656 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19657 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19658 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19659 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19660 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19661 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19662 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19663 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19664 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19665 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19666 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19667 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19668 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19669 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19670 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19671
19672 /* "neighbor maximum-prefix" commands. */
19673 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19674 install_element(BGP_NODE,
19675 &neighbor_maximum_prefix_threshold_hidden_cmd);
19676 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19677 install_element(BGP_NODE,
19678 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19679 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19680 install_element(BGP_NODE,
19681 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19682 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19683 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19684 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19685 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19686 install_element(BGP_IPV4_NODE,
19687 &neighbor_maximum_prefix_threshold_warning_cmd);
19688 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19689 install_element(BGP_IPV4_NODE,
19690 &neighbor_maximum_prefix_threshold_restart_cmd);
19691 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19692 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19693 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19694 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19695 install_element(BGP_IPV4M_NODE,
19696 &neighbor_maximum_prefix_threshold_warning_cmd);
19697 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19698 install_element(BGP_IPV4M_NODE,
19699 &neighbor_maximum_prefix_threshold_restart_cmd);
19700 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19701 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19702 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19703 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19704 install_element(BGP_IPV4L_NODE,
19705 &neighbor_maximum_prefix_threshold_warning_cmd);
19706 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19707 install_element(BGP_IPV4L_NODE,
19708 &neighbor_maximum_prefix_threshold_restart_cmd);
19709 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19710 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19711 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19712 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19713 install_element(BGP_IPV6_NODE,
19714 &neighbor_maximum_prefix_threshold_warning_cmd);
19715 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19716 install_element(BGP_IPV6_NODE,
19717 &neighbor_maximum_prefix_threshold_restart_cmd);
19718 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19719 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19720 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19721 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19722 install_element(BGP_IPV6M_NODE,
19723 &neighbor_maximum_prefix_threshold_warning_cmd);
19724 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19725 install_element(BGP_IPV6M_NODE,
19726 &neighbor_maximum_prefix_threshold_restart_cmd);
19727 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19728 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19729 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19730 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19731 install_element(BGP_IPV6L_NODE,
19732 &neighbor_maximum_prefix_threshold_warning_cmd);
19733 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19734 install_element(BGP_IPV6L_NODE,
19735 &neighbor_maximum_prefix_threshold_restart_cmd);
19736 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19737 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19738 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19739 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19740 install_element(BGP_VPNV4_NODE,
19741 &neighbor_maximum_prefix_threshold_warning_cmd);
19742 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19743 install_element(BGP_VPNV4_NODE,
19744 &neighbor_maximum_prefix_threshold_restart_cmd);
19745 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19746 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19747 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19748 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19749 install_element(BGP_VPNV6_NODE,
19750 &neighbor_maximum_prefix_threshold_warning_cmd);
19751 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19752 install_element(BGP_VPNV6_NODE,
19753 &neighbor_maximum_prefix_threshold_restart_cmd);
19754 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19755
19756 /* "neighbor allowas-in" */
19757 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19758 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19759 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19760 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19761 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19762 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19763 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19764 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19765 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19766 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19767 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19768 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19769 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19770 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19771 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19772 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19773 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19774 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19775 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19776 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19777
19778 /* neighbor accept-own */
19779 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19780 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19781
19782 /* "neighbor soo" */
19783 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19784 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19785 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19786 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19787 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19788 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19789 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19790 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19791 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19792 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19793 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19794 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19795 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19796 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19797 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19798 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19799 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19800 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19801
19802 /* address-family commands. */
19803 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19804 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19805 #ifdef KEEP_OLD_VPN_COMMANDS
19806 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19807 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19808 #endif /* KEEP_OLD_VPN_COMMANDS */
19809
19810 install_element(BGP_NODE, &address_family_evpn_cmd);
19811
19812 /* "exit-address-family" command. */
19813 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19814 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19815 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19816 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19817 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19818 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19819 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19820 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19821 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19822 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19823 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19824
19825 /* BGP retain all route-target */
19826 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19827 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19828
19829 /* "clear ip bgp commands" */
19830 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19831
19832 /* clear ip bgp prefix */
19833 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19834 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19835 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19836
19837 /* "show [ip] bgp summary" commands. */
19838 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19839 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19840 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19841 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19842 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19843 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19844 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19845
19846 /* "show [ip] bgp neighbors" commands. */
19847 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19848
19849 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19850
19851 /* "show [ip] bgp peer-group" commands. */
19852 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19853
19854 /* "show [ip] bgp paths" commands. */
19855 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19856
19857 /* "show [ip] bgp community" commands. */
19858 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19859
19860 /* "show ip bgp large-community" commands. */
19861 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19862 /* "show [ip] bgp attribute-info" commands. */
19863 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19864 /* "show [ip] bgp route-leak" command */
19865 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19866
19867 /* "redistribute" commands. */
19868 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19869 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19870 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19871 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19872 install_element(BGP_NODE,
19873 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19874 install_element(BGP_NODE,
19875 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19876 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19877 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19878 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19879 install_element(BGP_NODE,
19880 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19881 install_element(BGP_NODE,
19882 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19883 install_element(BGP_NODE,
19884 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19885 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19886 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19887 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19888 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19889 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19890 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19891 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19892 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19893 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19894 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19895 install_element(BGP_IPV4_NODE,
19896 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19897 install_element(BGP_IPV4_NODE,
19898 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19899 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19900 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19901 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19902 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19903 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19904 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19905
19906 /* import|export vpn [route-map RMAP_NAME] */
19907 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19908 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19909
19910 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19911 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19912
19913 /* ttl_security commands */
19914 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19915 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19916
19917 /* "bgp tcp-keepalive" commands */
19918 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
19919 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
19920
19921 /* "show [ip] bgp memory" commands. */
19922 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19923
19924 /* "show bgp martian next-hop" */
19925 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19926
19927 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19928
19929 /* "show [ip] bgp views" commands. */
19930 install_element(VIEW_NODE, &show_bgp_views_cmd);
19931
19932 /* "show [ip] bgp vrfs" commands. */
19933 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19934
19935 /* Community-list. */
19936 community_list_vty();
19937
19938 community_alias_vty();
19939
19940 /* vpn-policy commands */
19941 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19942 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19943 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19944 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19945 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19946 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19947 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19948 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19949 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19950 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19951 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19952 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19953
19954 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19955 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19956
19957 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19958 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19959 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19960 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19961 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19962 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19963 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19964 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19965 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19966 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19967
19968 /* tcp-mss command */
19969 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19970 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19971
19972 /* srv6 commands */
19973 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19974 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19975 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19976 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19977 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19978 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19979 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19980 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
19981 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
19982
19983 bgp_vty_if_init();
19984 }
19985
19986 #include "memory.h"
19987 #include "bgp_regex.h"
19988 #include "bgp_clist.h"
19989 #include "bgp_ecommunity.h"
19990
19991 /* VTY functions. */
19992
19993 /* Direction value to string conversion. */
19994 static const char *community_direct_str(int direct)
19995 {
19996 switch (direct) {
19997 case COMMUNITY_DENY:
19998 return "deny";
19999 case COMMUNITY_PERMIT:
20000 return "permit";
20001 default:
20002 return "unknown";
20003 }
20004 }
20005
20006 /* Display error string. */
20007 static void community_list_perror(struct vty *vty, int ret)
20008 {
20009 switch (ret) {
20010 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20011 vty_out(vty, "%% Can't find community-list\n");
20012 break;
20013 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20014 vty_out(vty, "%% Malformed community-list value\n");
20015 break;
20016 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20017 vty_out(vty,
20018 "%% Community name conflict, previously defined as standard community\n");
20019 break;
20020 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20021 vty_out(vty,
20022 "%% Community name conflict, previously defined as expanded community\n");
20023 break;
20024 }
20025 }
20026
20027 /* "community-list" keyword help string. */
20028 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20029
20030 /*community-list standard */
20031 DEFUN (community_list_standard,
20032 bgp_community_list_standard_cmd,
20033 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20034 BGP_STR
20035 COMMUNITY_LIST_STR
20036 "Community list number (standard)\n"
20037 "Add an standard community-list entry\n"
20038 "Community list name\n"
20039 "Sequence number of an entry\n"
20040 "Sequence number\n"
20041 "Specify community to reject\n"
20042 "Specify community to accept\n"
20043 COMMUNITY_VAL_STR)
20044 {
20045 char *cl_name_or_number = NULL;
20046 char *seq = NULL;
20047 int direct = 0;
20048 int style = COMMUNITY_LIST_STANDARD;
20049 int idx = 0;
20050
20051 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20052 seq = argv[idx]->arg;
20053
20054 idx = 0;
20055 argv_find(argv, argc, "(1-99)", &idx);
20056 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20057 cl_name_or_number = argv[idx]->arg;
20058 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20059 : COMMUNITY_DENY;
20060 argv_find(argv, argc, "AA:NN", &idx);
20061 char *str = argv_concat(argv, argc, idx);
20062
20063 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20064 direct, style);
20065
20066 XFREE(MTYPE_TMP, str);
20067
20068 if (ret < 0) {
20069 /* Display error string. */
20070 community_list_perror(vty, ret);
20071 return CMD_WARNING_CONFIG_FAILED;
20072 }
20073
20074 return CMD_SUCCESS;
20075 }
20076
20077 DEFUN (no_community_list_standard_all,
20078 no_bgp_community_list_standard_all_cmd,
20079 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20080 NO_STR
20081 BGP_STR
20082 COMMUNITY_LIST_STR
20083 "Community list number (standard)\n"
20084 "Add an standard community-list entry\n"
20085 "Community list name\n"
20086 "Sequence number of an entry\n"
20087 "Sequence number\n"
20088 "Specify community to reject\n"
20089 "Specify community to accept\n"
20090 COMMUNITY_VAL_STR)
20091 {
20092 char *cl_name_or_number = NULL;
20093 char *str = NULL;
20094 int direct = 0;
20095 int style = COMMUNITY_LIST_STANDARD;
20096 char *seq = NULL;
20097 int idx = 0;
20098
20099 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20100 seq = argv[idx]->arg;
20101
20102 idx = 0;
20103 argv_find(argv, argc, "permit", &idx);
20104 argv_find(argv, argc, "deny", &idx);
20105
20106 if (idx) {
20107 direct = argv_find(argv, argc, "permit", &idx)
20108 ? COMMUNITY_PERMIT
20109 : COMMUNITY_DENY;
20110
20111 idx = 0;
20112 argv_find(argv, argc, "AA:NN", &idx);
20113 str = argv_concat(argv, argc, idx);
20114 }
20115
20116 idx = 0;
20117 argv_find(argv, argc, "(1-99)", &idx);
20118 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20119 cl_name_or_number = argv[idx]->arg;
20120
20121 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20122 direct, style);
20123
20124 XFREE(MTYPE_TMP, str);
20125
20126 if (ret < 0) {
20127 community_list_perror(vty, ret);
20128 return CMD_WARNING_CONFIG_FAILED;
20129 }
20130
20131 return CMD_SUCCESS;
20132 }
20133
20134 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20135 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20136 NO_STR BGP_STR COMMUNITY_LIST_STR
20137 "Community list number (standard)\n"
20138 "Add an standard community-list entry\n"
20139 "Community list name\n")
20140
20141 /*community-list expanded */
20142 DEFUN (community_list_expanded_all,
20143 bgp_community_list_expanded_all_cmd,
20144 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20145 BGP_STR
20146 COMMUNITY_LIST_STR
20147 "Community list number (expanded)\n"
20148 "Add an expanded community-list entry\n"
20149 "Community list name\n"
20150 "Sequence number of an entry\n"
20151 "Sequence number\n"
20152 "Specify community to reject\n"
20153 "Specify community to accept\n"
20154 COMMUNITY_VAL_STR)
20155 {
20156 char *cl_name_or_number = NULL;
20157 char *seq = NULL;
20158 int direct = 0;
20159 int style = COMMUNITY_LIST_EXPANDED;
20160 int idx = 0;
20161
20162 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20163 seq = argv[idx]->arg;
20164
20165 idx = 0;
20166
20167 argv_find(argv, argc, "(100-500)", &idx);
20168 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20169 cl_name_or_number = argv[idx]->arg;
20170 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20171 : COMMUNITY_DENY;
20172 argv_find(argv, argc, "AA:NN", &idx);
20173 char *str = argv_concat(argv, argc, idx);
20174
20175 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20176 direct, style);
20177
20178 XFREE(MTYPE_TMP, str);
20179
20180 if (ret < 0) {
20181 /* Display error string. */
20182 community_list_perror(vty, ret);
20183 return CMD_WARNING_CONFIG_FAILED;
20184 }
20185
20186 return CMD_SUCCESS;
20187 }
20188
20189 DEFUN (no_community_list_expanded_all,
20190 no_bgp_community_list_expanded_all_cmd,
20191 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20192 NO_STR
20193 BGP_STR
20194 COMMUNITY_LIST_STR
20195 "Community list number (expanded)\n"
20196 "Add an expanded community-list entry\n"
20197 "Community list name\n"
20198 "Sequence number of an entry\n"
20199 "Sequence number\n"
20200 "Specify community to reject\n"
20201 "Specify community to accept\n"
20202 COMMUNITY_VAL_STR)
20203 {
20204 char *cl_name_or_number = NULL;
20205 char *seq = NULL;
20206 char *str = NULL;
20207 int direct = 0;
20208 int style = COMMUNITY_LIST_EXPANDED;
20209 int idx = 0;
20210
20211 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20212 seq = argv[idx]->arg;
20213
20214 idx = 0;
20215 argv_find(argv, argc, "permit", &idx);
20216 argv_find(argv, argc, "deny", &idx);
20217
20218 if (idx) {
20219 direct = argv_find(argv, argc, "permit", &idx)
20220 ? COMMUNITY_PERMIT
20221 : COMMUNITY_DENY;
20222
20223 idx = 0;
20224 argv_find(argv, argc, "AA:NN", &idx);
20225 str = argv_concat(argv, argc, idx);
20226 }
20227
20228 idx = 0;
20229 argv_find(argv, argc, "(100-500)", &idx);
20230 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20231 cl_name_or_number = argv[idx]->arg;
20232
20233 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20234 direct, style);
20235
20236 XFREE(MTYPE_TMP, str);
20237
20238 if (ret < 0) {
20239 community_list_perror(vty, ret);
20240 return CMD_WARNING_CONFIG_FAILED;
20241 }
20242
20243 return CMD_SUCCESS;
20244 }
20245
20246 ALIAS(no_community_list_expanded_all,
20247 no_bgp_community_list_expanded_all_list_cmd,
20248 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20249 NO_STR BGP_STR COMMUNITY_LIST_STR
20250 "Community list number (expanded)\n"
20251 "Add an expanded community-list entry\n"
20252 "Community list name\n")
20253
20254 /* Return configuration string of community-list entry. */
20255 static const char *community_list_config_str(struct community_entry *entry)
20256 {
20257 const char *str;
20258
20259 if (entry->any)
20260 str = "";
20261 else {
20262 if (entry->style == COMMUNITY_LIST_STANDARD)
20263 str = community_str(entry->u.com, false, false);
20264 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20265 str = lcommunity_str(entry->u.lcom, false, false);
20266 else
20267 str = entry->config;
20268 }
20269 return str;
20270 }
20271
20272 static void community_list_show(struct vty *vty, struct community_list *list)
20273 {
20274 struct community_entry *entry;
20275
20276 for (entry = list->head; entry; entry = entry->next) {
20277 if (entry == list->head) {
20278 if (all_digit(list->name))
20279 vty_out(vty, "Community %s list %s\n",
20280 entry->style == COMMUNITY_LIST_STANDARD
20281 ? "standard"
20282 : "(expanded) access",
20283 list->name);
20284 else
20285 vty_out(vty, "Named Community %s list %s\n",
20286 entry->style == COMMUNITY_LIST_STANDARD
20287 ? "standard"
20288 : "expanded",
20289 list->name);
20290 }
20291 if (entry->any)
20292 vty_out(vty, " %s\n",
20293 community_direct_str(entry->direct));
20294 else
20295 vty_out(vty, " %s %s\n",
20296 community_direct_str(entry->direct),
20297 community_list_config_str(entry));
20298 }
20299 }
20300
20301 DEFUN (show_community_list,
20302 show_bgp_community_list_cmd,
20303 "show bgp community-list",
20304 SHOW_STR
20305 BGP_STR
20306 "List community-list\n")
20307 {
20308 struct community_list *list;
20309 struct community_list_master *cm;
20310
20311 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20312 if (!cm)
20313 return CMD_SUCCESS;
20314
20315 for (list = cm->num.head; list; list = list->next)
20316 community_list_show(vty, list);
20317
20318 for (list = cm->str.head; list; list = list->next)
20319 community_list_show(vty, list);
20320
20321 return CMD_SUCCESS;
20322 }
20323
20324 DEFUN (show_community_list_arg,
20325 show_bgp_community_list_arg_cmd,
20326 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20327 SHOW_STR
20328 BGP_STR
20329 "List community-list\n"
20330 "Community-list number\n"
20331 "Community-list name\n"
20332 "Detailed information on community-list\n")
20333 {
20334 int idx_comm_list = 3;
20335 struct community_list *list;
20336
20337 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20338 COMMUNITY_LIST_MASTER);
20339 if (!list) {
20340 vty_out(vty, "%% Can't find community-list\n");
20341 return CMD_WARNING;
20342 }
20343
20344 community_list_show(vty, list);
20345
20346 return CMD_SUCCESS;
20347 }
20348
20349 /*
20350 * Large Community code.
20351 */
20352 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20353 struct cmd_token **argv, int style,
20354 int reject_all_digit_name)
20355 {
20356 int ret;
20357 int direct;
20358 char *str;
20359 int idx = 0;
20360 char *cl_name;
20361 char *seq = NULL;
20362
20363 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20364 seq = argv[idx]->arg;
20365
20366 idx = 0;
20367 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20368 : COMMUNITY_DENY;
20369
20370 /* All digit name check. */
20371 idx = 0;
20372 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20373 argv_find(argv, argc, "(1-99)", &idx);
20374 argv_find(argv, argc, "(100-500)", &idx);
20375 cl_name = argv[idx]->arg;
20376 if (reject_all_digit_name && all_digit(cl_name)) {
20377 vty_out(vty, "%% Community name cannot have all digits\n");
20378 return CMD_WARNING_CONFIG_FAILED;
20379 }
20380
20381 idx = 0;
20382 argv_find(argv, argc, "AA:BB:CC", &idx);
20383 argv_find(argv, argc, "LINE", &idx);
20384 /* Concat community string argument. */
20385 if (idx)
20386 str = argv_concat(argv, argc, idx);
20387 else
20388 str = NULL;
20389
20390 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20391
20392 /* Free temporary community list string allocated by
20393 argv_concat(). */
20394 XFREE(MTYPE_TMP, str);
20395
20396 if (ret < 0) {
20397 community_list_perror(vty, ret);
20398 return CMD_WARNING_CONFIG_FAILED;
20399 }
20400 return CMD_SUCCESS;
20401 }
20402
20403 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20404 struct cmd_token **argv, int style)
20405 {
20406 int ret;
20407 int direct = 0;
20408 char *str = NULL;
20409 int idx = 0;
20410 char *seq = NULL;
20411
20412 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20413 seq = argv[idx]->arg;
20414
20415 idx = 0;
20416 argv_find(argv, argc, "permit", &idx);
20417 argv_find(argv, argc, "deny", &idx);
20418
20419 if (idx) {
20420 /* Check the list direct. */
20421 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20422 direct = COMMUNITY_PERMIT;
20423 else
20424 direct = COMMUNITY_DENY;
20425
20426 idx = 0;
20427 argv_find(argv, argc, "LINE", &idx);
20428 argv_find(argv, argc, "AA:AA:NN", &idx);
20429 /* Concat community string argument. */
20430 str = argv_concat(argv, argc, idx);
20431 }
20432
20433 idx = 0;
20434 argv_find(argv, argc, "(1-99)", &idx);
20435 argv_find(argv, argc, "(100-500)", &idx);
20436 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20437
20438 /* Unset community list. */
20439 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20440 style);
20441
20442 /* Free temporary community list string allocated by
20443 argv_concat(). */
20444 XFREE(MTYPE_TMP, str);
20445
20446 if (ret < 0) {
20447 community_list_perror(vty, ret);
20448 return CMD_WARNING_CONFIG_FAILED;
20449 }
20450
20451 return CMD_SUCCESS;
20452 }
20453
20454 /* "large-community-list" keyword help string. */
20455 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20456 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20457
20458 DEFUN (lcommunity_list_standard,
20459 bgp_lcommunity_list_standard_cmd,
20460 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20461 BGP_STR
20462 LCOMMUNITY_LIST_STR
20463 "Large Community list number (standard)\n"
20464 "Sequence number of an entry\n"
20465 "Sequence number\n"
20466 "Specify large community to reject\n"
20467 "Specify large community to accept\n"
20468 LCOMMUNITY_VAL_STR)
20469 {
20470 return lcommunity_list_set_vty(vty, argc, argv,
20471 LARGE_COMMUNITY_LIST_STANDARD, 0);
20472 }
20473
20474 DEFUN (lcommunity_list_expanded,
20475 bgp_lcommunity_list_expanded_cmd,
20476 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20477 BGP_STR
20478 LCOMMUNITY_LIST_STR
20479 "Large Community list number (expanded)\n"
20480 "Sequence number of an entry\n"
20481 "Sequence number\n"
20482 "Specify large community to reject\n"
20483 "Specify large community to accept\n"
20484 "An ordered list as a regular-expression\n")
20485 {
20486 return lcommunity_list_set_vty(vty, argc, argv,
20487 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20488 }
20489
20490 DEFUN (lcommunity_list_name_standard,
20491 bgp_lcommunity_list_name_standard_cmd,
20492 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20493 BGP_STR
20494 LCOMMUNITY_LIST_STR
20495 "Specify standard large-community-list\n"
20496 "Large Community list name\n"
20497 "Sequence number of an entry\n"
20498 "Sequence number\n"
20499 "Specify large community to reject\n"
20500 "Specify large community to accept\n"
20501 LCOMMUNITY_VAL_STR)
20502 {
20503 return lcommunity_list_set_vty(vty, argc, argv,
20504 LARGE_COMMUNITY_LIST_STANDARD, 1);
20505 }
20506
20507 DEFUN (lcommunity_list_name_expanded,
20508 bgp_lcommunity_list_name_expanded_cmd,
20509 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20510 BGP_STR
20511 LCOMMUNITY_LIST_STR
20512 "Specify expanded large-community-list\n"
20513 "Large Community list name\n"
20514 "Sequence number of an entry\n"
20515 "Sequence number\n"
20516 "Specify large community to reject\n"
20517 "Specify large community to accept\n"
20518 "An ordered list as a regular-expression\n")
20519 {
20520 return lcommunity_list_set_vty(vty, argc, argv,
20521 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20522 }
20523
20524 DEFUN (no_lcommunity_list_all,
20525 no_bgp_lcommunity_list_all_cmd,
20526 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20527 NO_STR
20528 BGP_STR
20529 LCOMMUNITY_LIST_STR
20530 "Large Community list number (standard)\n"
20531 "Large Community list number (expanded)\n"
20532 "Large Community list name\n")
20533 {
20534 return lcommunity_list_unset_vty(vty, argc, argv,
20535 LARGE_COMMUNITY_LIST_STANDARD);
20536 }
20537
20538 DEFUN (no_lcommunity_list_name_standard_all,
20539 no_bgp_lcommunity_list_name_standard_all_cmd,
20540 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20541 NO_STR
20542 BGP_STR
20543 LCOMMUNITY_LIST_STR
20544 "Specify standard large-community-list\n"
20545 "Large Community list name\n")
20546 {
20547 return lcommunity_list_unset_vty(vty, argc, argv,
20548 LARGE_COMMUNITY_LIST_STANDARD);
20549 }
20550
20551 DEFUN (no_lcommunity_list_name_expanded_all,
20552 no_bgp_lcommunity_list_name_expanded_all_cmd,
20553 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20554 NO_STR
20555 BGP_STR
20556 LCOMMUNITY_LIST_STR
20557 "Specify expanded large-community-list\n"
20558 "Large Community list name\n")
20559 {
20560 return lcommunity_list_unset_vty(vty, argc, argv,
20561 LARGE_COMMUNITY_LIST_EXPANDED);
20562 }
20563
20564 DEFUN (no_lcommunity_list_standard,
20565 no_bgp_lcommunity_list_standard_cmd,
20566 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20567 NO_STR
20568 BGP_STR
20569 LCOMMUNITY_LIST_STR
20570 "Large Community list number (standard)\n"
20571 "Sequence number of an entry\n"
20572 "Sequence number\n"
20573 "Specify large community to reject\n"
20574 "Specify large community to accept\n"
20575 LCOMMUNITY_VAL_STR)
20576 {
20577 return lcommunity_list_unset_vty(vty, argc, argv,
20578 LARGE_COMMUNITY_LIST_STANDARD);
20579 }
20580
20581 DEFUN (no_lcommunity_list_expanded,
20582 no_bgp_lcommunity_list_expanded_cmd,
20583 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20584 NO_STR
20585 BGP_STR
20586 LCOMMUNITY_LIST_STR
20587 "Large Community list number (expanded)\n"
20588 "Sequence number of an entry\n"
20589 "Sequence number\n"
20590 "Specify large community to reject\n"
20591 "Specify large community to accept\n"
20592 "An ordered list as a regular-expression\n")
20593 {
20594 return lcommunity_list_unset_vty(vty, argc, argv,
20595 LARGE_COMMUNITY_LIST_EXPANDED);
20596 }
20597
20598 DEFUN (no_lcommunity_list_name_standard,
20599 no_bgp_lcommunity_list_name_standard_cmd,
20600 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20601 NO_STR
20602 BGP_STR
20603 LCOMMUNITY_LIST_STR
20604 "Specify standard large-community-list\n"
20605 "Large Community list name\n"
20606 "Sequence number of an entry\n"
20607 "Sequence number\n"
20608 "Specify large community to reject\n"
20609 "Specify large community to accept\n"
20610 LCOMMUNITY_VAL_STR)
20611 {
20612 return lcommunity_list_unset_vty(vty, argc, argv,
20613 LARGE_COMMUNITY_LIST_STANDARD);
20614 }
20615
20616 DEFUN (no_lcommunity_list_name_expanded,
20617 no_bgp_lcommunity_list_name_expanded_cmd,
20618 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20619 NO_STR
20620 BGP_STR
20621 LCOMMUNITY_LIST_STR
20622 "Specify expanded large-community-list\n"
20623 "Large community list name\n"
20624 "Sequence number of an entry\n"
20625 "Sequence number\n"
20626 "Specify large community to reject\n"
20627 "Specify large community to accept\n"
20628 "An ordered list as a regular-expression\n")
20629 {
20630 return lcommunity_list_unset_vty(vty, argc, argv,
20631 LARGE_COMMUNITY_LIST_EXPANDED);
20632 }
20633
20634 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20635 {
20636 struct community_entry *entry;
20637
20638 for (entry = list->head; entry; entry = entry->next) {
20639 if (entry == list->head) {
20640 if (all_digit(list->name))
20641 vty_out(vty, "Large community %s list %s\n",
20642 entry->style ==
20643 LARGE_COMMUNITY_LIST_STANDARD
20644 ? "standard"
20645 : "(expanded) access",
20646 list->name);
20647 else
20648 vty_out(vty,
20649 "Named large community %s list %s\n",
20650 entry->style ==
20651 LARGE_COMMUNITY_LIST_STANDARD
20652 ? "standard"
20653 : "expanded",
20654 list->name);
20655 }
20656 if (entry->any)
20657 vty_out(vty, " %s\n",
20658 community_direct_str(entry->direct));
20659 else
20660 vty_out(vty, " %s %s\n",
20661 community_direct_str(entry->direct),
20662 community_list_config_str(entry));
20663 }
20664 }
20665
20666 DEFUN (show_lcommunity_list,
20667 show_bgp_lcommunity_list_cmd,
20668 "show bgp large-community-list",
20669 SHOW_STR
20670 BGP_STR
20671 "List large-community list\n")
20672 {
20673 struct community_list *list;
20674 struct community_list_master *cm;
20675
20676 cm = community_list_master_lookup(bgp_clist,
20677 LARGE_COMMUNITY_LIST_MASTER);
20678 if (!cm)
20679 return CMD_SUCCESS;
20680
20681 for (list = cm->num.head; list; list = list->next)
20682 lcommunity_list_show(vty, list);
20683
20684 for (list = cm->str.head; list; list = list->next)
20685 lcommunity_list_show(vty, list);
20686
20687 return CMD_SUCCESS;
20688 }
20689
20690 DEFUN (show_lcommunity_list_arg,
20691 show_bgp_lcommunity_list_arg_cmd,
20692 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20693 SHOW_STR
20694 BGP_STR
20695 "List large-community list\n"
20696 "Large-community-list number\n"
20697 "Large-community-list name\n"
20698 "Detailed information on large-community-list\n")
20699 {
20700 struct community_list *list;
20701
20702 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20703 LARGE_COMMUNITY_LIST_MASTER);
20704 if (!list) {
20705 vty_out(vty, "%% Can't find large-community-list\n");
20706 return CMD_WARNING;
20707 }
20708
20709 lcommunity_list_show(vty, list);
20710
20711 return CMD_SUCCESS;
20712 }
20713
20714 /* "extcommunity-list" keyword help string. */
20715 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20716 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20717
20718 DEFUN (extcommunity_list_standard,
20719 bgp_extcommunity_list_standard_cmd,
20720 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20721 BGP_STR
20722 EXTCOMMUNITY_LIST_STR
20723 "Extended Community list number (standard)\n"
20724 "Specify standard extcommunity-list\n"
20725 "Community list name\n"
20726 "Sequence number of an entry\n"
20727 "Sequence number\n"
20728 "Specify community to reject\n"
20729 "Specify community to accept\n"
20730 EXTCOMMUNITY_VAL_STR)
20731 {
20732 int style = EXTCOMMUNITY_LIST_STANDARD;
20733 int direct = 0;
20734 char *cl_number_or_name = NULL;
20735 char *seq = NULL;
20736
20737 int idx = 0;
20738
20739 argv_find(argv, argc, "(1-99)", &idx);
20740 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20741 cl_number_or_name = argv[idx]->arg;
20742
20743 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20744 seq = argv[idx]->arg;
20745
20746 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20747 : COMMUNITY_DENY;
20748 argv_find(argv, argc, "AA:NN", &idx);
20749 char *str = argv_concat(argv, argc, idx);
20750
20751 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20752 direct, style);
20753
20754 XFREE(MTYPE_TMP, str);
20755
20756 if (ret < 0) {
20757 community_list_perror(vty, ret);
20758 return CMD_WARNING_CONFIG_FAILED;
20759 }
20760
20761 return CMD_SUCCESS;
20762 }
20763
20764 DEFUN (extcommunity_list_name_expanded,
20765 bgp_extcommunity_list_name_expanded_cmd,
20766 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20767 BGP_STR
20768 EXTCOMMUNITY_LIST_STR
20769 "Extended Community list number (expanded)\n"
20770 "Specify expanded extcommunity-list\n"
20771 "Extended Community list name\n"
20772 "Sequence number of an entry\n"
20773 "Sequence number\n"
20774 "Specify community to reject\n"
20775 "Specify community to accept\n"
20776 "An ordered list as a regular-expression\n")
20777 {
20778 int style = EXTCOMMUNITY_LIST_EXPANDED;
20779 int direct = 0;
20780 char *cl_number_or_name = NULL;
20781 char *seq = NULL;
20782 int idx = 0;
20783
20784 argv_find(argv, argc, "(100-500)", &idx);
20785 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20786 cl_number_or_name = argv[idx]->arg;
20787
20788 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20789 seq = argv[idx]->arg;
20790
20791 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20792 : COMMUNITY_DENY;
20793 argv_find(argv, argc, "LINE", &idx);
20794 char *str = argv_concat(argv, argc, idx);
20795
20796 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20797 direct, style);
20798
20799 XFREE(MTYPE_TMP, str);
20800
20801 if (ret < 0) {
20802 community_list_perror(vty, ret);
20803 return CMD_WARNING_CONFIG_FAILED;
20804 }
20805
20806 return CMD_SUCCESS;
20807 }
20808
20809 DEFUN (no_extcommunity_list_standard_all,
20810 no_bgp_extcommunity_list_standard_all_cmd,
20811 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20812 NO_STR
20813 BGP_STR
20814 EXTCOMMUNITY_LIST_STR
20815 "Extended Community list number (standard)\n"
20816 "Specify standard extcommunity-list\n"
20817 "Community list name\n"
20818 "Sequence number of an entry\n"
20819 "Sequence number\n"
20820 "Specify community to reject\n"
20821 "Specify community to accept\n"
20822 EXTCOMMUNITY_VAL_STR)
20823 {
20824 int style = EXTCOMMUNITY_LIST_STANDARD;
20825 int direct = 0;
20826 char *cl_number_or_name = NULL;
20827 char *str = NULL;
20828 char *seq = NULL;
20829 int idx = 0;
20830
20831 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20832 seq = argv[idx]->arg;
20833
20834 idx = 0;
20835 argv_find(argv, argc, "permit", &idx);
20836 argv_find(argv, argc, "deny", &idx);
20837 if (idx) {
20838 direct = argv_find(argv, argc, "permit", &idx)
20839 ? COMMUNITY_PERMIT
20840 : COMMUNITY_DENY;
20841
20842 idx = 0;
20843 argv_find(argv, argc, "AA:NN", &idx);
20844 str = argv_concat(argv, argc, idx);
20845 }
20846
20847 idx = 0;
20848 argv_find(argv, argc, "(1-99)", &idx);
20849 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20850 cl_number_or_name = argv[idx]->arg;
20851
20852 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20853 seq, direct, style);
20854
20855 XFREE(MTYPE_TMP, str);
20856
20857 if (ret < 0) {
20858 community_list_perror(vty, ret);
20859 return CMD_WARNING_CONFIG_FAILED;
20860 }
20861
20862 return CMD_SUCCESS;
20863 }
20864
20865 ALIAS(no_extcommunity_list_standard_all,
20866 no_bgp_extcommunity_list_standard_all_list_cmd,
20867 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20868 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20869 "Extended Community list number (standard)\n"
20870 "Specify standard extcommunity-list\n"
20871 "Community list name\n")
20872
20873 DEFUN (no_extcommunity_list_expanded_all,
20874 no_bgp_extcommunity_list_expanded_all_cmd,
20875 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20876 NO_STR
20877 BGP_STR
20878 EXTCOMMUNITY_LIST_STR
20879 "Extended Community list number (expanded)\n"
20880 "Specify expanded extcommunity-list\n"
20881 "Extended Community list name\n"
20882 "Sequence number of an entry\n"
20883 "Sequence number\n"
20884 "Specify community to reject\n"
20885 "Specify community to accept\n"
20886 "An ordered list as a regular-expression\n")
20887 {
20888 int style = EXTCOMMUNITY_LIST_EXPANDED;
20889 int direct = 0;
20890 char *cl_number_or_name = NULL;
20891 char *str = NULL;
20892 char *seq = NULL;
20893 int idx = 0;
20894
20895 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20896 seq = argv[idx]->arg;
20897
20898 idx = 0;
20899 argv_find(argv, argc, "permit", &idx);
20900 argv_find(argv, argc, "deny", &idx);
20901
20902 if (idx) {
20903 direct = argv_find(argv, argc, "permit", &idx)
20904 ? COMMUNITY_PERMIT
20905 : COMMUNITY_DENY;
20906
20907 idx = 0;
20908 argv_find(argv, argc, "LINE", &idx);
20909 str = argv_concat(argv, argc, idx);
20910 }
20911
20912 idx = 0;
20913 argv_find(argv, argc, "(100-500)", &idx);
20914 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20915 cl_number_or_name = argv[idx]->arg;
20916
20917 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20918 seq, direct, style);
20919
20920 XFREE(MTYPE_TMP, str);
20921
20922 if (ret < 0) {
20923 community_list_perror(vty, ret);
20924 return CMD_WARNING_CONFIG_FAILED;
20925 }
20926
20927 return CMD_SUCCESS;
20928 }
20929
20930 ALIAS(no_extcommunity_list_expanded_all,
20931 no_bgp_extcommunity_list_expanded_all_list_cmd,
20932 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20933 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20934 "Extended Community list number (expanded)\n"
20935 "Specify expanded extcommunity-list\n"
20936 "Extended Community list name\n")
20937
20938 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20939 {
20940 struct community_entry *entry;
20941
20942 for (entry = list->head; entry; entry = entry->next) {
20943 if (entry == list->head) {
20944 if (all_digit(list->name))
20945 vty_out(vty, "Extended community %s list %s\n",
20946 entry->style == EXTCOMMUNITY_LIST_STANDARD
20947 ? "standard"
20948 : "(expanded) access",
20949 list->name);
20950 else
20951 vty_out(vty,
20952 "Named extended community %s list %s\n",
20953 entry->style == EXTCOMMUNITY_LIST_STANDARD
20954 ? "standard"
20955 : "expanded",
20956 list->name);
20957 }
20958 if (entry->any)
20959 vty_out(vty, " %s\n",
20960 community_direct_str(entry->direct));
20961 else
20962 vty_out(vty, " %s %s\n",
20963 community_direct_str(entry->direct),
20964 community_list_config_str(entry));
20965 }
20966 }
20967
20968 DEFUN (show_extcommunity_list,
20969 show_bgp_extcommunity_list_cmd,
20970 "show bgp extcommunity-list",
20971 SHOW_STR
20972 BGP_STR
20973 "List extended-community list\n")
20974 {
20975 struct community_list *list;
20976 struct community_list_master *cm;
20977
20978 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20979 if (!cm)
20980 return CMD_SUCCESS;
20981
20982 for (list = cm->num.head; list; list = list->next)
20983 extcommunity_list_show(vty, list);
20984
20985 for (list = cm->str.head; list; list = list->next)
20986 extcommunity_list_show(vty, list);
20987
20988 return CMD_SUCCESS;
20989 }
20990
20991 DEFUN (show_extcommunity_list_arg,
20992 show_bgp_extcommunity_list_arg_cmd,
20993 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20994 SHOW_STR
20995 BGP_STR
20996 "List extended-community list\n"
20997 "Extcommunity-list number\n"
20998 "Extcommunity-list name\n"
20999 "Detailed information on extcommunity-list\n")
21000 {
21001 int idx_comm_list = 3;
21002 struct community_list *list;
21003
21004 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21005 EXTCOMMUNITY_LIST_MASTER);
21006 if (!list) {
21007 vty_out(vty, "%% Can't find extcommunity-list\n");
21008 return CMD_WARNING;
21009 }
21010
21011 extcommunity_list_show(vty, list);
21012
21013 return CMD_SUCCESS;
21014 }
21015
21016 /* Display community-list and extcommunity-list configuration. */
21017 static int community_list_config_write(struct vty *vty)
21018 {
21019 struct community_list *list;
21020 struct community_entry *entry;
21021 struct community_list_master *cm;
21022 int write = 0;
21023
21024 /* Community-list. */
21025 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21026
21027 for (list = cm->num.head; list; list = list->next)
21028 for (entry = list->head; entry; entry = entry->next) {
21029 vty_out(vty,
21030 "bgp community-list %s seq %" PRId64 " %s %s\n",
21031 list->name, entry->seq,
21032 community_direct_str(entry->direct),
21033 community_list_config_str(entry));
21034 write++;
21035 }
21036 for (list = cm->str.head; list; list = list->next)
21037 for (entry = list->head; entry; entry = entry->next) {
21038 vty_out(vty,
21039 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21040 entry->style == COMMUNITY_LIST_STANDARD
21041 ? "standard"
21042 : "expanded",
21043 list->name, entry->seq,
21044 community_direct_str(entry->direct),
21045 community_list_config_str(entry));
21046 write++;
21047 }
21048
21049 /* Extcommunity-list. */
21050 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21051
21052 for (list = cm->num.head; list; list = list->next)
21053 for (entry = list->head; entry; entry = entry->next) {
21054 vty_out(vty,
21055 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21056 list->name, entry->seq,
21057 community_direct_str(entry->direct),
21058 community_list_config_str(entry));
21059 write++;
21060 }
21061 for (list = cm->str.head; list; list = list->next)
21062 for (entry = list->head; entry; entry = entry->next) {
21063 vty_out(vty,
21064 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21065 entry->style == EXTCOMMUNITY_LIST_STANDARD
21066 ? "standard"
21067 : "expanded",
21068 list->name, entry->seq,
21069 community_direct_str(entry->direct),
21070 community_list_config_str(entry));
21071 write++;
21072 }
21073
21074
21075 /* lcommunity-list. */
21076 cm = community_list_master_lookup(bgp_clist,
21077 LARGE_COMMUNITY_LIST_MASTER);
21078
21079 for (list = cm->num.head; list; list = list->next)
21080 for (entry = list->head; entry; entry = entry->next) {
21081 vty_out(vty,
21082 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21083 list->name, entry->seq,
21084 community_direct_str(entry->direct),
21085 community_list_config_str(entry));
21086 write++;
21087 }
21088 for (list = cm->str.head; list; list = list->next)
21089 for (entry = list->head; entry; entry = entry->next) {
21090 vty_out(vty,
21091 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21092
21093 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21094 ? "standard"
21095 : "expanded",
21096 list->name, entry->seq, community_direct_str(entry->direct),
21097 community_list_config_str(entry));
21098 write++;
21099 }
21100
21101 return write;
21102 }
21103
21104 static int community_list_config_write(struct vty *vty);
21105 static struct cmd_node community_list_node = {
21106 .name = "community list",
21107 .node = COMMUNITY_LIST_NODE,
21108 .prompt = "",
21109 .config_write = community_list_config_write,
21110 };
21111
21112 static void community_list_vty(void)
21113 {
21114 install_node(&community_list_node);
21115
21116 /* Community-list. */
21117 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21118 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21119 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21120 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21121 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21122 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21123 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21124 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21125
21126 /* Extcommunity-list. */
21127 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21128 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21129 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21130 install_element(CONFIG_NODE,
21131 &no_bgp_extcommunity_list_standard_all_list_cmd);
21132 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21133 install_element(CONFIG_NODE,
21134 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21135 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21136 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21137
21138 /* Large Community List */
21139 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21140 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21141 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21142 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21143 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21144 install_element(CONFIG_NODE,
21145 &no_bgp_lcommunity_list_name_standard_all_cmd);
21146 install_element(CONFIG_NODE,
21147 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21148 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21149 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21150 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21151 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21152 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21153 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21154
21155 bgp_community_list_command_completion_setup();
21156 }
21157
21158 static struct cmd_node community_alias_node = {
21159 .name = "community alias",
21160 .node = COMMUNITY_ALIAS_NODE,
21161 .prompt = "",
21162 .config_write = bgp_community_alias_write,
21163 };
21164
21165 void community_alias_vty(void)
21166 {
21167 install_node(&community_alias_node);
21168
21169 /* Community-list. */
21170 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21171
21172 bgp_community_alias_command_completion_setup();
21173 }