]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Allow bgp to control the DSCP session TOS value
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_attr_evpn.h"
45 #include "bgpd/bgp_advertise.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_community_alias.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_debug.h"
54 #include "bgpd/bgp_errors.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_nexthop.h"
57 #include "bgpd/bgp_network.h"
58 #include "bgpd/bgp_open.h"
59 #include "bgpd/bgp_regex.h"
60 #include "bgpd/bgp_route.h"
61 #include "bgpd/bgp_mplsvpn.h"
62 #include "bgpd/bgp_zebra.h"
63 #include "bgpd/bgp_table.h"
64 #include "bgpd/bgp_vty.h"
65 #include "bgpd/bgp_mpath.h"
66 #include "bgpd/bgp_packet.h"
67 #include "bgpd/bgp_updgrp.h"
68 #include "bgpd/bgp_bfd.h"
69 #include "bgpd/bgp_io.h"
70 #include "bgpd/bgp_evpn.h"
71 #include "bgpd/bgp_evpn_vty.h"
72 #include "bgpd/bgp_evpn_mh.h"
73 #include "bgpd/bgp_addpath.h"
74 #include "bgpd/bgp_mac.h"
75 #include "bgpd/bgp_flowspec.h"
76 #include "bgpd/bgp_conditional_adv.h"
77 #ifdef ENABLE_BGP_VNC
78 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
79 #endif
80
81 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
88 );
89 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
92 );
93 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96 );
97 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
100 );
101 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
104 );
105 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108 );
109 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112 );
113 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116 );
117 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121 );
122 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
125 );
126 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
127 { .val_bool = false, .match_version = "< 8.3", },
128 { .val_bool = true },
129 );
130 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
131 { .val_bool = false, .match_version = "< 8.3", },
132 { .val_bool = true },
133 );
134
135 DEFINE_HOOK(bgp_inst_config_write,
136 (struct bgp *bgp, struct vty *vty),
137 (bgp, vty));
138 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
139 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
140
141 static struct peer_group *listen_range_exists(struct bgp *bgp,
142 struct prefix *range, int exact);
143
144 /* Show BGP peer's information. */
145 enum show_type {
146 show_all,
147 show_peer,
148 show_ipv4_all,
149 show_ipv6_all,
150 show_ipv4_peer,
151 show_ipv6_peer
152 };
153
154 static struct peer_group *listen_range_exists(struct bgp *bgp,
155 struct prefix *range, int exact);
156
157 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
158 struct bgp *bgp,
159 bool use_json,
160 json_object *json);
161
162 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
163 enum show_type type,
164 const char *ip_str,
165 afi_t afi, bool use_json);
166
167 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
168 {
169 switch (afi) {
170 case AFI_IP:
171 switch (safi) {
172 case SAFI_UNICAST:
173 return BGP_IPV4_NODE;
174 case SAFI_MULTICAST:
175 return BGP_IPV4M_NODE;
176 case SAFI_LABELED_UNICAST:
177 return BGP_IPV4L_NODE;
178 case SAFI_MPLS_VPN:
179 return BGP_VPNV4_NODE;
180 case SAFI_FLOWSPEC:
181 return BGP_FLOWSPECV4_NODE;
182 default:
183 /* not expected */
184 return BGP_IPV4_NODE;
185 }
186 case AFI_IP6:
187 switch (safi) {
188 case SAFI_UNICAST:
189 return BGP_IPV6_NODE;
190 case SAFI_MULTICAST:
191 return BGP_IPV6M_NODE;
192 case SAFI_LABELED_UNICAST:
193 return BGP_IPV6L_NODE;
194 case SAFI_MPLS_VPN:
195 return BGP_VPNV6_NODE;
196 case SAFI_FLOWSPEC:
197 return BGP_FLOWSPECV6_NODE;
198 default:
199 /* not expected */
200 return BGP_IPV4_NODE;
201 }
202 case AFI_L2VPN:
203 return BGP_EVPN_NODE;
204 case AFI_UNSPEC:
205 case AFI_MAX:
206 // We should never be here but to clarify the switch statement..
207 return BGP_IPV4_NODE;
208 }
209
210 // Impossible to happen
211 return BGP_IPV4_NODE;
212 }
213
214 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
215 {
216 if (afi == AFI_IP) {
217 if (safi == SAFI_UNICAST)
218 return "IPv4 Unicast";
219 if (safi == SAFI_MULTICAST)
220 return "IPv4 Multicast";
221 if (safi == SAFI_LABELED_UNICAST)
222 return "IPv4 Labeled Unicast";
223 if (safi == SAFI_MPLS_VPN)
224 return "IPv4 VPN";
225 if (safi == SAFI_ENCAP)
226 return "IPv4 Encap";
227 if (safi == SAFI_FLOWSPEC)
228 return "IPv4 Flowspec";
229 } else if (afi == AFI_IP6) {
230 if (safi == SAFI_UNICAST)
231 return "IPv6 Unicast";
232 if (safi == SAFI_MULTICAST)
233 return "IPv6 Multicast";
234 if (safi == SAFI_LABELED_UNICAST)
235 return "IPv6 Labeled Unicast";
236 if (safi == SAFI_MPLS_VPN)
237 return "IPv6 VPN";
238 if (safi == SAFI_ENCAP)
239 return "IPv6 Encap";
240 if (safi == SAFI_FLOWSPEC)
241 return "IPv6 Flowspec";
242 } else if (afi == AFI_L2VPN) {
243 if (safi == SAFI_EVPN)
244 return "L2VPN EVPN";
245 }
246
247 return "Unknown";
248 }
249
250 /*
251 * Please note that we have intentionally camelCased
252 * the return strings here. So if you want
253 * to use this function, please ensure you
254 * are doing this within json output
255 */
256 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
257 {
258 if (afi == AFI_IP) {
259 if (safi == SAFI_UNICAST)
260 return "ipv4Unicast";
261 if (safi == SAFI_MULTICAST)
262 return "ipv4Multicast";
263 if (safi == SAFI_LABELED_UNICAST)
264 return "ipv4LabeledUnicast";
265 if (safi == SAFI_MPLS_VPN)
266 return "ipv4Vpn";
267 if (safi == SAFI_ENCAP)
268 return "ipv4Encap";
269 if (safi == SAFI_FLOWSPEC)
270 return "ipv4Flowspec";
271 } else if (afi == AFI_IP6) {
272 if (safi == SAFI_UNICAST)
273 return "ipv6Unicast";
274 if (safi == SAFI_MULTICAST)
275 return "ipv6Multicast";
276 if (safi == SAFI_LABELED_UNICAST)
277 return "ipv6LabeledUnicast";
278 if (safi == SAFI_MPLS_VPN)
279 return "ipv6Vpn";
280 if (safi == SAFI_ENCAP)
281 return "ipv6Encap";
282 if (safi == SAFI_FLOWSPEC)
283 return "ipv6Flowspec";
284 } else if (afi == AFI_L2VPN) {
285 if (safi == SAFI_EVPN)
286 return "l2VpnEvpn";
287 }
288
289 return "Unknown";
290 }
291
292 /* unset srv6 locator */
293 static int bgp_srv6_locator_unset(struct bgp *bgp)
294 {
295 int ret;
296 struct listnode *node, *nnode;
297 struct srv6_locator_chunk *chunk;
298 struct bgp_srv6_function *func;
299 struct bgp *bgp_vrf;
300 struct in6_addr *tovpn_sid;
301
302 /* release chunk notification via ZAPI */
303 ret = bgp_zebra_srv6_manager_release_locator_chunk(
304 bgp->srv6_locator_name);
305 if (ret < 0)
306 return -1;
307
308 /* refresh chunks */
309 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
310 listnode_delete(bgp->srv6_locator_chunks, chunk);
311
312 /* refresh functions */
313 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func))
314 listnode_delete(bgp->srv6_functions, func);
315
316 /* refresh tovpn_sid */
317 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
318 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
319 continue;
320
321 /* refresh vpnv4 tovpn_sid */
322 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
323 if (tovpn_sid)
324 XFREE(MTYPE_BGP_SRV6_SID,
325 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
326
327 /* refresh vpnv6 tovpn_sid */
328 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
329 if (tovpn_sid)
330 XFREE(MTYPE_BGP_SRV6_SID,
331 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
332 }
333
334 /* update vpn bgp processes */
335 vpn_leak_postchange_all();
336
337 /* clear locator name */
338 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
339
340 return 0;
341 }
342
343 /* Utility function to get address family from current node. */
344 afi_t bgp_node_afi(struct vty *vty)
345 {
346 afi_t afi;
347 switch (vty->node) {
348 case BGP_IPV6_NODE:
349 case BGP_IPV6M_NODE:
350 case BGP_IPV6L_NODE:
351 case BGP_VPNV6_NODE:
352 case BGP_FLOWSPECV6_NODE:
353 afi = AFI_IP6;
354 break;
355 case BGP_EVPN_NODE:
356 afi = AFI_L2VPN;
357 break;
358 default:
359 afi = AFI_IP;
360 break;
361 }
362 return afi;
363 }
364
365 /* Utility function to get subsequent address family from current
366 node. */
367 safi_t bgp_node_safi(struct vty *vty)
368 {
369 safi_t safi;
370 switch (vty->node) {
371 case BGP_VPNV4_NODE:
372 case BGP_VPNV6_NODE:
373 safi = SAFI_MPLS_VPN;
374 break;
375 case BGP_IPV4M_NODE:
376 case BGP_IPV6M_NODE:
377 safi = SAFI_MULTICAST;
378 break;
379 case BGP_EVPN_NODE:
380 safi = SAFI_EVPN;
381 break;
382 case BGP_IPV4L_NODE:
383 case BGP_IPV6L_NODE:
384 safi = SAFI_LABELED_UNICAST;
385 break;
386 case BGP_FLOWSPECV4_NODE:
387 case BGP_FLOWSPECV6_NODE:
388 safi = SAFI_FLOWSPEC;
389 break;
390 default:
391 safi = SAFI_UNICAST;
392 break;
393 }
394 return safi;
395 }
396
397 /**
398 * Converts an AFI in string form to afi_t
399 *
400 * @param afi string, one of
401 * - "ipv4"
402 * - "ipv6"
403 * - "l2vpn"
404 * @return the corresponding afi_t
405 */
406 afi_t bgp_vty_afi_from_str(const char *afi_str)
407 {
408 afi_t afi = AFI_MAX; /* unknown */
409 if (strmatch(afi_str, "ipv4"))
410 afi = AFI_IP;
411 else if (strmatch(afi_str, "ipv6"))
412 afi = AFI_IP6;
413 else if (strmatch(afi_str, "l2vpn"))
414 afi = AFI_L2VPN;
415 return afi;
416 }
417
418 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
419 afi_t *afi)
420 {
421 int ret = 0;
422 if (argv_find(argv, argc, "ipv4", index)) {
423 ret = 1;
424 if (afi)
425 *afi = AFI_IP;
426 } else if (argv_find(argv, argc, "ipv6", index)) {
427 ret = 1;
428 if (afi)
429 *afi = AFI_IP6;
430 } else if (argv_find(argv, argc, "l2vpn", index)) {
431 ret = 1;
432 if (afi)
433 *afi = AFI_L2VPN;
434 }
435 return ret;
436 }
437
438 /* supports <unicast|multicast|vpn|labeled-unicast> */
439 safi_t bgp_vty_safi_from_str(const char *safi_str)
440 {
441 safi_t safi = SAFI_MAX; /* unknown */
442 if (strmatch(safi_str, "multicast"))
443 safi = SAFI_MULTICAST;
444 else if (strmatch(safi_str, "unicast"))
445 safi = SAFI_UNICAST;
446 else if (strmatch(safi_str, "vpn"))
447 safi = SAFI_MPLS_VPN;
448 else if (strmatch(safi_str, "evpn"))
449 safi = SAFI_EVPN;
450 else if (strmatch(safi_str, "labeled-unicast"))
451 safi = SAFI_LABELED_UNICAST;
452 else if (strmatch(safi_str, "flowspec"))
453 safi = SAFI_FLOWSPEC;
454 return safi;
455 }
456
457 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
458 safi_t *safi)
459 {
460 int ret = 0;
461 if (argv_find(argv, argc, "unicast", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_UNICAST;
465 } else if (argv_find(argv, argc, "multicast", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_MULTICAST;
469 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
470 ret = 1;
471 if (safi)
472 *safi = SAFI_LABELED_UNICAST;
473 } else if (argv_find(argv, argc, "vpn", index)) {
474 ret = 1;
475 if (safi)
476 *safi = SAFI_MPLS_VPN;
477 } else if (argv_find(argv, argc, "evpn", index)) {
478 ret = 1;
479 if (safi)
480 *safi = SAFI_EVPN;
481 } else if (argv_find(argv, argc, "flowspec", index)) {
482 ret = 1;
483 if (safi)
484 *safi = SAFI_FLOWSPEC;
485 }
486 return ret;
487 }
488
489 /*
490 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
491 *
492 * afi
493 * address-family identifier
494 *
495 * safi
496 * subsequent address-family identifier
497 *
498 * Returns:
499 * default_af string corresponding to the supplied afi/safi pair.
500 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
501 * return -1.
502 */
503 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
504 {
505 switch (afi) {
506 case AFI_IP:
507 switch (safi) {
508 case SAFI_UNICAST:
509 return "ipv4-unicast";
510 case SAFI_MULTICAST:
511 return "ipv4-multicast";
512 case SAFI_MPLS_VPN:
513 return "ipv4-vpn";
514 case SAFI_ENCAP:
515 return "ipv4-encap";
516 case SAFI_LABELED_UNICAST:
517 return "ipv4-labeled-unicast";
518 case SAFI_FLOWSPEC:
519 return "ipv4-flowspec";
520 default:
521 return "unknown-afi/safi";
522 }
523 break;
524 case AFI_IP6:
525 switch (safi) {
526 case SAFI_UNICAST:
527 return "ipv6-unicast";
528 case SAFI_MULTICAST:
529 return "ipv6-multicast";
530 case SAFI_MPLS_VPN:
531 return "ipv6-vpn";
532 case SAFI_ENCAP:
533 return "ipv6-encap";
534 case SAFI_LABELED_UNICAST:
535 return "ipv6-labeled-unicast";
536 case SAFI_FLOWSPEC:
537 return "ipv6-flowspec";
538 default:
539 return "unknown-afi/safi";
540 }
541 break;
542 case AFI_L2VPN:
543 switch (safi) {
544 case SAFI_EVPN:
545 return "l2vpn-evpn";
546 default:
547 return "unknown-afi/safi";
548 }
549 case AFI_UNSPEC:
550 case AFI_MAX:
551 return "unknown-afi/safi";
552 }
553 /* all AFIs are accounted for above, so this shouldn't happen */
554 return "unknown-afi/safi";
555 }
556
557 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
558 enum bgp_instance_type inst_type)
559 {
560 int ret = bgp_get(bgp, as, name, inst_type);
561
562 if (ret == BGP_CREATED) {
563 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
564 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
565
566 if (DFLT_BGP_IMPORT_CHECK)
567 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
568 if (DFLT_BGP_SHOW_HOSTNAME)
569 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
570 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
571 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
572 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
573 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
574 if (DFLT_BGP_DETERMINISTIC_MED)
575 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
576 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
577 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
578 if (DFLT_BGP_SUPPRESS_DUPLICATES)
579 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
580 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
581 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
582 if (DFLT_BGP_HARD_ADMIN_RESET)
583 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
584
585 ret = BGP_SUCCESS;
586 }
587 return ret;
588 }
589
590 /*
591 * bgp_vty_find_and_parse_afi_safi_bgp
592 *
593 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
594 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
595 * to appropriate values for the calling function. This is to allow the
596 * calling function to make decisions appropriate for the show command
597 * that is being parsed.
598 *
599 * The show commands are generally of the form:
600 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
601 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
602 *
603 * Since we use argv_find if the show command in particular doesn't have:
604 * [ip]
605 * [<view|vrf> VIEWVRFNAME]
606 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
607 * The command parsing should still be ok.
608 *
609 * vty -> The vty for the command so we can output some useful data in
610 * the event of a parse error in the vrf.
611 * argv -> The command tokens
612 * argc -> How many command tokens we have
613 * idx -> The current place in the command, generally should be 0 for this
614 * function
615 * afi -> The parsed afi if it was included in the show command, returned here
616 * safi -> The parsed safi if it was included in the show command, returned here
617 * bgp -> Pointer to the bgp data structure we need to fill in.
618 * use_json -> json is configured or not
619 *
620 * The function returns the correct location in the parse tree for the
621 * last token found.
622 *
623 * Returns 0 for failure to parse correctly, else the idx position of where
624 * it found the last token.
625 */
626 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
627 struct cmd_token **argv, int argc,
628 int *idx, afi_t *afi, safi_t *safi,
629 struct bgp **bgp, bool use_json)
630 {
631 char *vrf_name = NULL;
632
633 assert(afi);
634 assert(safi);
635 assert(bgp);
636
637 if (argv_find(argv, argc, "ip", idx))
638 *afi = AFI_IP;
639
640 if (argv_find(argv, argc, "view", idx))
641 vrf_name = argv[*idx + 1]->arg;
642 else if (argv_find(argv, argc, "vrf", idx)) {
643 vrf_name = argv[*idx + 1]->arg;
644 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
645 vrf_name = NULL;
646 }
647 if (vrf_name) {
648 if (strmatch(vrf_name, "all"))
649 *bgp = NULL;
650 else {
651 *bgp = bgp_lookup_by_name(vrf_name);
652 if (!*bgp) {
653 if (use_json) {
654 json_object *json = NULL;
655 json = json_object_new_object();
656 json_object_string_add(
657 json, "warning",
658 "View/Vrf is unknown");
659 vty_json(vty, json);
660 }
661 else
662 vty_out(vty, "View/Vrf %s is unknown\n",
663 vrf_name);
664 *idx = 0;
665 return 0;
666 }
667 }
668 } else {
669 *bgp = bgp_get_default();
670 if (!*bgp) {
671 if (use_json) {
672 json_object *json = NULL;
673 json = json_object_new_object();
674 json_object_string_add(
675 json, "warning",
676 "Default BGP instance not found");
677 vty_json(vty, json);
678 }
679 else
680 vty_out(vty,
681 "Default BGP instance not found\n");
682 *idx = 0;
683 return 0;
684 }
685 }
686
687 if (argv_find_and_parse_afi(argv, argc, idx, afi))
688 argv_find_and_parse_safi(argv, argc, idx, safi);
689
690 *idx += 1;
691 return *idx;
692 }
693
694 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
695 {
696 struct interface *ifp = NULL;
697 struct listnode *node;
698 struct bgp_listener *listener;
699 union sockunion all_su;
700
701 if (su->sa.sa_family == AF_INET) {
702 (void)str2sockunion("0.0.0.0", &all_su);
703 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
704 } else if (su->sa.sa_family == AF_INET6) {
705 (void)str2sockunion("::", &all_su);
706 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
707 su->sin6.sin6_scope_id,
708 bgp->vrf_id);
709 }
710
711 if (ifp) {
712 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
713 if (sockunion_family(su) !=
714 sockunion_family(&listener->su))
715 continue;
716
717 /* If 0.0.0.0/:: is a listener, then treat as self and
718 * reject.
719 */
720 if (!sockunion_cmp(&listener->su, su) ||
721 !sockunion_cmp(&listener->su, &all_su))
722 return true;
723 }
724 }
725
726 return false;
727 }
728
729 /* Utility function for looking up peer from VTY. */
730 /* This is used only for configuration, so disallow if attempted on
731 * a dynamic neighbor.
732 */
733 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
734 {
735 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
736 int ret;
737 union sockunion su;
738 struct peer *peer;
739
740 if (!bgp) {
741 return NULL;
742 }
743
744 ret = str2sockunion(ip_str, &su);
745 if (ret < 0) {
746 peer = peer_lookup_by_conf_if(bgp, ip_str);
747 if (!peer) {
748 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
749 == NULL) {
750 vty_out(vty,
751 "%% Malformed address or name: %s\n",
752 ip_str);
753 return NULL;
754 }
755 }
756 } else {
757 peer = peer_lookup(bgp, &su);
758 if (!peer) {
759 vty_out(vty,
760 "%% Specify remote-as or peer-group commands first\n");
761 return NULL;
762 }
763 if (peer_dynamic_neighbor(peer)) {
764 vty_out(vty,
765 "%% Operation not allowed on a dynamic neighbor\n");
766 return NULL;
767 }
768 }
769 return peer;
770 }
771
772 /* Utility function for looking up peer or peer group. */
773 /* This is used only for configuration, so disallow if attempted on
774 * a dynamic neighbor.
775 */
776 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
777 {
778 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
779 int ret;
780 union sockunion su;
781 struct peer *peer = NULL;
782 struct peer_group *group = NULL;
783
784 if (!bgp) {
785 return NULL;
786 }
787
788 ret = str2sockunion(peer_str, &su);
789 if (ret == 0) {
790 /* IP address, locate peer. */
791 peer = peer_lookup(bgp, &su);
792 } else {
793 /* Not IP, could match either peer configured on interface or a
794 * group. */
795 peer = peer_lookup_by_conf_if(bgp, peer_str);
796 if (!peer)
797 group = peer_group_lookup(bgp, peer_str);
798 }
799
800 if (peer) {
801 if (peer_dynamic_neighbor(peer)) {
802 vty_out(vty,
803 "%% Operation not allowed on a dynamic neighbor\n");
804 return NULL;
805 }
806
807 return peer;
808 }
809
810 if (group)
811 return group->conf;
812
813 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
814
815 return NULL;
816 }
817
818 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
819 {
820 const char *str = NULL;
821
822 switch (ret) {
823 case BGP_SUCCESS:
824 case BGP_CREATED:
825 case BGP_GR_NO_OPERATION:
826 break;
827 case BGP_ERR_INVALID_VALUE:
828 str = "Invalid value";
829 break;
830 case BGP_ERR_INVALID_FLAG:
831 str = "Invalid flag";
832 break;
833 case BGP_ERR_PEER_GROUP_SHUTDOWN:
834 str = "Peer-group has been shutdown. Activate the peer-group first";
835 break;
836 case BGP_ERR_PEER_FLAG_CONFLICT:
837 str = "Can't set override-capability and strict-capability-match at the same time";
838 break;
839 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
840 str = "Specify remote-as or peer-group remote AS first";
841 break;
842 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
843 str = "Cannot change the peer-group. Deconfigure first";
844 break;
845 case BGP_ERR_PEER_GROUP_MISMATCH:
846 str = "Peer is not a member of this peer-group";
847 break;
848 case BGP_ERR_PEER_FILTER_CONFLICT:
849 str = "Prefix/distribute list can not co-exist";
850 break;
851 case BGP_ERR_NOT_INTERNAL_PEER:
852 str = "Invalid command. Not an internal neighbor";
853 break;
854 case BGP_ERR_REMOVE_PRIVATE_AS:
855 str = "remove-private-AS cannot be configured for IBGP peers";
856 break;
857 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
858 str = "Local-AS allowed only for EBGP peers";
859 break;
860 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
861 str = "Cannot have local-as same as BGP AS number";
862 break;
863 case BGP_ERR_TCPSIG_FAILED:
864 str = "Error while applying TCP-Sig to session(s)";
865 break;
866 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
867 str = "ebgp-multihop and ttl-security cannot be configured together";
868 break;
869 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
870 str = "ttl-security only allowed for EBGP peers";
871 break;
872 case BGP_ERR_AS_OVERRIDE:
873 str = "as-override cannot be configured for IBGP peers";
874 break;
875 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
876 str = "Invalid limit for number of dynamic neighbors";
877 break;
878 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
879 str = "Dynamic neighbor listen range already exists";
880 break;
881 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
882 str = "Operation not allowed on a dynamic neighbor";
883 break;
884 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
885 str = "Operation not allowed on a directly connected neighbor";
886 break;
887 case BGP_ERR_PEER_SAFI_CONFLICT:
888 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
889 break;
890 case BGP_ERR_GR_INVALID_CMD:
891 str = "The Graceful Restart command used is not valid at this moment.";
892 break;
893 case BGP_ERR_GR_OPERATION_FAILED:
894 str = "The Graceful Restart Operation failed due to an err.";
895 break;
896 case BGP_ERR_PEER_GROUP_MEMBER:
897 str = "Peer-group member cannot override remote-as of peer-group.";
898 break;
899 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
900 str = "Peer-group members must be all internal or all external.";
901 break;
902 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
903 str = "Range specified cannot be deleted because it is not part of current config.";
904 break;
905 case BGP_ERR_INSTANCE_MISMATCH:
906 str = "Instance specified does not match the current instance.";
907 break;
908 case BGP_ERR_NO_INTERFACE_CONFIG:
909 str = "Interface specified is not being used for interface based peer.";
910 break;
911 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
912 str = "No configuration already specified for soft reconfiguration.";
913 break;
914 case BGP_ERR_AS_MISMATCH:
915 str = "BGP is already running.";
916 break;
917 case BGP_ERR_AF_UNCONFIGURED:
918 str = "AFI/SAFI specified is not currently configured.";
919 break;
920 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS:
921 str = "AS specified for local as is the same as the remote as and this is not allowed.";
922 break;
923 case BGP_ERR_INVALID_AS:
924 str = "Confederation AS specified is the same AS as our AS.";
925 break;
926 }
927 if (str) {
928 vty_out(vty, "%% %s\n", str);
929 return CMD_WARNING_CONFIG_FAILED;
930 }
931 return CMD_SUCCESS;
932 }
933
934 /* BGP clear sort. */
935 enum clear_sort {
936 clear_all,
937 clear_peer,
938 clear_group,
939 clear_external,
940 clear_as
941 };
942
943 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
944 safi_t safi, int error)
945 {
946 switch (error) {
947 case BGP_ERR_AF_UNCONFIGURED:
948 vty_out(vty,
949 "%% BGP: Enable %s address family for the neighbor %s\n",
950 get_afi_safi_str(afi, safi, false), peer->host);
951 break;
952 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
953 vty_out(vty,
954 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
955 peer->host);
956 break;
957 default:
958 break;
959 }
960 }
961
962 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
963 struct listnode **nnode, enum bgp_clear_type stype)
964 {
965 int ret = 0;
966 struct peer_af *paf;
967
968 /* if afi/.safi not specified, spin thru all of them */
969 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
970 afi_t tmp_afi;
971 safi_t tmp_safi;
972 enum bgp_af_index index;
973
974 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
975 paf = peer->peer_af_array[index];
976 if (!paf)
977 continue;
978
979 if (paf && paf->subgroup)
980 SET_FLAG(paf->subgroup->sflags,
981 SUBGRP_STATUS_FORCE_UPDATES);
982
983 tmp_afi = paf->afi;
984 tmp_safi = paf->safi;
985 if (!peer->afc[tmp_afi][tmp_safi])
986 continue;
987
988 if (stype == BGP_CLEAR_SOFT_NONE)
989 ret = peer_clear(peer, nnode);
990 else
991 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
992 stype);
993 }
994 /* if afi specified and safi not, spin thru safis on this afi */
995 } else if (safi == SAFI_UNSPEC) {
996 safi_t tmp_safi;
997
998 for (tmp_safi = SAFI_UNICAST;
999 tmp_safi < SAFI_MAX; tmp_safi++) {
1000 if (!peer->afc[afi][tmp_safi])
1001 continue;
1002
1003 paf = peer_af_find(peer, afi, tmp_safi);
1004 if (paf && paf->subgroup)
1005 SET_FLAG(paf->subgroup->sflags,
1006 SUBGRP_STATUS_FORCE_UPDATES);
1007
1008 if (stype == BGP_CLEAR_SOFT_NONE)
1009 ret = peer_clear(peer, nnode);
1010 else
1011 ret = peer_clear_soft(peer, afi,
1012 tmp_safi, stype);
1013 }
1014 /* both afi/safi specified, let the caller know if not defined */
1015 } else {
1016 if (!peer->afc[afi][safi])
1017 return 1;
1018
1019 paf = peer_af_find(peer, afi, safi);
1020 if (paf && paf->subgroup)
1021 SET_FLAG(paf->subgroup->sflags,
1022 SUBGRP_STATUS_FORCE_UPDATES);
1023
1024 if (stype == BGP_CLEAR_SOFT_NONE)
1025 ret = peer_clear(peer, nnode);
1026 else
1027 ret = peer_clear_soft(peer, afi, safi, stype);
1028 }
1029
1030 return ret;
1031 }
1032
1033 /* `clear ip bgp' functions. */
1034 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1035 enum clear_sort sort, enum bgp_clear_type stype,
1036 const char *arg)
1037 {
1038 int ret = 0;
1039 bool found = false;
1040 struct peer *peer;
1041
1042 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1043
1044 /* Clear all neighbors. */
1045 /*
1046 * Pass along pointer to next node to peer_clear() when walking all
1047 * nodes on the BGP instance as that may get freed if it is a
1048 * doppelganger
1049 */
1050 if (sort == clear_all) {
1051 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1052
1053 bgp_peer_gr_flags_update(peer);
1054
1055 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1056 gr_router_detected = true;
1057
1058 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1059 stype);
1060
1061 if (ret < 0)
1062 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1063 }
1064
1065 if (gr_router_detected
1066 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1067 bgp_zebra_send_capabilities(bgp, false);
1068 } else if (!gr_router_detected
1069 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1070 bgp_zebra_send_capabilities(bgp, true);
1071 }
1072
1073 /* This is to apply read-only mode on this clear. */
1074 if (stype == BGP_CLEAR_SOFT_NONE)
1075 bgp->update_delay_over = 0;
1076
1077 return CMD_SUCCESS;
1078 }
1079
1080 /* Clear specified neighbor. */
1081 if (sort == clear_peer) {
1082 union sockunion su;
1083
1084 /* Make sockunion for lookup. */
1085 ret = str2sockunion(arg, &su);
1086 if (ret < 0) {
1087 peer = peer_lookup_by_conf_if(bgp, arg);
1088 if (!peer) {
1089 peer = peer_lookup_by_hostname(bgp, arg);
1090 if (!peer) {
1091 vty_out(vty,
1092 "Malformed address or name: %s\n",
1093 arg);
1094 return CMD_WARNING;
1095 }
1096 }
1097 } else {
1098 peer = peer_lookup(bgp, &su);
1099 if (!peer) {
1100 vty_out(vty,
1101 "%% BGP: Unknown neighbor - \"%s\"\n",
1102 arg);
1103 return CMD_WARNING;
1104 }
1105 }
1106
1107 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1108 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1109
1110 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1111
1112 /* if afi/safi not defined for this peer, let caller know */
1113 if (ret == 1)
1114 ret = BGP_ERR_AF_UNCONFIGURED;
1115
1116 if (ret < 0)
1117 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1118
1119 return CMD_SUCCESS;
1120 }
1121
1122 /* Clear all neighbors belonging to a specific peer-group. */
1123 if (sort == clear_group) {
1124 struct peer_group *group;
1125
1126 group = peer_group_lookup(bgp, arg);
1127 if (!group) {
1128 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1129 return CMD_WARNING;
1130 }
1131
1132 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1133 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1134
1135 if (ret < 0)
1136 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1137 else
1138 found = true;
1139 }
1140
1141 if (!found)
1142 vty_out(vty,
1143 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1144 get_afi_safi_str(afi, safi, false), arg);
1145
1146 return CMD_SUCCESS;
1147 }
1148
1149 /* Clear all external (eBGP) neighbors. */
1150 if (sort == clear_external) {
1151 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1152 if (peer->sort == BGP_PEER_IBGP)
1153 continue;
1154
1155 bgp_peer_gr_flags_update(peer);
1156
1157 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1158 gr_router_detected = true;
1159
1160 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1161
1162 if (ret < 0)
1163 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1164 else
1165 found = true;
1166 }
1167
1168 if (gr_router_detected
1169 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1170 bgp_zebra_send_capabilities(bgp, false);
1171 } else if (!gr_router_detected
1172 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1173 bgp_zebra_send_capabilities(bgp, true);
1174 }
1175
1176 if (!found)
1177 vty_out(vty,
1178 "%% BGP: No external %s peer is configured\n",
1179 get_afi_safi_str(afi, safi, false));
1180
1181 return CMD_SUCCESS;
1182 }
1183
1184 /* Clear all neighbors belonging to a specific AS. */
1185 if (sort == clear_as) {
1186 as_t as = strtoul(arg, NULL, 10);
1187
1188 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1189 if (peer->as != as)
1190 continue;
1191
1192 bgp_peer_gr_flags_update(peer);
1193
1194 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1195 gr_router_detected = true;
1196
1197 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1198
1199 if (ret < 0)
1200 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1201 else
1202 found = true;
1203 }
1204
1205 if (gr_router_detected
1206 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1207 bgp_zebra_send_capabilities(bgp, false);
1208 } else if (!gr_router_detected
1209 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1210 bgp_zebra_send_capabilities(bgp, true);
1211 }
1212
1213 if (!found)
1214 vty_out(vty,
1215 "%% BGP: No %s peer is configured with AS %s\n",
1216 get_afi_safi_str(afi, safi, false), arg);
1217
1218 return CMD_SUCCESS;
1219 }
1220
1221 return CMD_SUCCESS;
1222 }
1223
1224 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1225 safi_t safi, enum clear_sort sort,
1226 enum bgp_clear_type stype, const char *arg)
1227 {
1228 struct bgp *bgp;
1229
1230 /* BGP structure lookup. */
1231 if (name) {
1232 bgp = bgp_lookup_by_name(name);
1233 if (bgp == NULL) {
1234 vty_out(vty, "Can't find BGP instance %s\n", name);
1235 return CMD_WARNING;
1236 }
1237 } else {
1238 bgp = bgp_get_default();
1239 if (bgp == NULL) {
1240 vty_out(vty, "No BGP process is configured\n");
1241 return CMD_WARNING;
1242 }
1243 }
1244
1245 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1246 }
1247
1248 /* clear soft inbound */
1249 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1250 {
1251 afi_t afi;
1252 safi_t safi;
1253
1254 FOREACH_AFI_SAFI (afi, safi)
1255 bgp_clear_vty(vty, name, afi, safi, clear_all,
1256 BGP_CLEAR_SOFT_IN, NULL);
1257 }
1258
1259 /* clear soft outbound */
1260 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1261 {
1262 afi_t afi;
1263 safi_t safi;
1264
1265 FOREACH_AFI_SAFI (afi, safi)
1266 bgp_clear_vty(vty, name, afi, safi, clear_all,
1267 BGP_CLEAR_SOFT_OUT, NULL);
1268 }
1269
1270
1271 #ifndef VTYSH_EXTRACT_PL
1272 #include "bgpd/bgp_vty_clippy.c"
1273 #endif
1274
1275 DEFUN_HIDDEN (bgp_local_mac,
1276 bgp_local_mac_cmd,
1277 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1278 BGP_STR
1279 "Local MAC config\n"
1280 "VxLAN Network Identifier\n"
1281 "VNI number\n"
1282 "local mac\n"
1283 "mac address\n"
1284 "mac-mobility sequence\n"
1285 "seq number\n")
1286 {
1287 int rv;
1288 vni_t vni;
1289 struct ethaddr mac;
1290 struct ipaddr ip;
1291 uint32_t seq;
1292 struct bgp *bgp;
1293
1294 vni = strtoul(argv[3]->arg, NULL, 10);
1295 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1296 vty_out(vty, "%% Malformed MAC address\n");
1297 return CMD_WARNING;
1298 }
1299 memset(&ip, 0, sizeof(ip));
1300 seq = strtoul(argv[7]->arg, NULL, 10);
1301
1302 bgp = bgp_get_default();
1303 if (!bgp) {
1304 vty_out(vty, "Default BGP instance is not there\n");
1305 return CMD_WARNING;
1306 }
1307
1308 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1309 zero_esi);
1310 if (rv < 0) {
1311 vty_out(vty, "Internal error\n");
1312 return CMD_WARNING;
1313 }
1314
1315 return CMD_SUCCESS;
1316 }
1317
1318 DEFUN_HIDDEN (no_bgp_local_mac,
1319 no_bgp_local_mac_cmd,
1320 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1321 NO_STR
1322 BGP_STR
1323 "Local MAC config\n"
1324 "VxLAN Network Identifier\n"
1325 "VNI number\n"
1326 "local mac\n"
1327 "mac address\n")
1328 {
1329 int rv;
1330 vni_t vni;
1331 struct ethaddr mac;
1332 struct ipaddr ip;
1333 struct bgp *bgp;
1334
1335 vni = strtoul(argv[4]->arg, NULL, 10);
1336 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1337 vty_out(vty, "%% Malformed MAC address\n");
1338 return CMD_WARNING;
1339 }
1340 memset(&ip, 0, sizeof(ip));
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_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1349 if (rv < 0) {
1350 vty_out(vty, "Internal error\n");
1351 return CMD_WARNING;
1352 }
1353
1354 return CMD_SUCCESS;
1355 }
1356
1357 DEFUN (no_synchronization,
1358 no_synchronization_cmd,
1359 "no synchronization",
1360 NO_STR
1361 "Perform IGP synchronization\n")
1362 {
1363 return CMD_SUCCESS;
1364 }
1365
1366 DEFUN (no_auto_summary,
1367 no_auto_summary_cmd,
1368 "no auto-summary",
1369 NO_STR
1370 "Enable automatic network number summarization\n")
1371 {
1372 return CMD_SUCCESS;
1373 }
1374
1375 /* "router bgp" commands. */
1376 DEFUN_NOSH (router_bgp,
1377 router_bgp_cmd,
1378 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1379 ROUTER_STR
1380 BGP_STR
1381 AS_STR
1382 BGP_INSTANCE_HELP_STR)
1383 {
1384 int idx_asn = 2;
1385 int idx_view_vrf = 3;
1386 int idx_vrf = 4;
1387 int is_new_bgp = 0;
1388 int ret;
1389 as_t as;
1390 struct bgp *bgp;
1391 const char *name = NULL;
1392 enum bgp_instance_type inst_type;
1393
1394 // "router bgp" without an ASN
1395 if (argc == 2) {
1396 // Pending: Make VRF option available for ASN less config
1397 bgp = bgp_get_default();
1398
1399 if (bgp == NULL) {
1400 vty_out(vty, "%% No BGP process is configured\n");
1401 return CMD_WARNING_CONFIG_FAILED;
1402 }
1403
1404 if (listcount(bm->bgp) > 1) {
1405 vty_out(vty, "%% Please specify ASN and VRF\n");
1406 return CMD_WARNING_CONFIG_FAILED;
1407 }
1408 }
1409
1410 // "router bgp X"
1411 else {
1412 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1413
1414 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1415 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1416 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1417
1418 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1419 if (argc > 3) {
1420 name = argv[idx_vrf]->arg;
1421
1422 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1423 if (strmatch(name, VRF_DEFAULT_NAME))
1424 name = NULL;
1425 else
1426 inst_type = BGP_INSTANCE_TYPE_VRF;
1427 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1428 inst_type = BGP_INSTANCE_TYPE_VIEW;
1429 }
1430
1431 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1432 is_new_bgp = (bgp_lookup(as, name) == NULL);
1433
1434 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1435 switch (ret) {
1436 case BGP_ERR_AS_MISMATCH:
1437 vty_out(vty, "BGP is already running; AS is %u\n", as);
1438 return CMD_WARNING_CONFIG_FAILED;
1439 case BGP_ERR_INSTANCE_MISMATCH:
1440 vty_out(vty,
1441 "BGP instance name and AS number mismatch\n");
1442 vty_out(vty,
1443 "BGP instance is already running; AS is %u\n",
1444 as);
1445 return CMD_WARNING_CONFIG_FAILED;
1446 }
1447
1448 /*
1449 * If we just instantiated the default instance, complete
1450 * any pending VRF-VPN leaking that was configured via
1451 * earlier "router bgp X vrf FOO" blocks.
1452 */
1453 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1454 vpn_leak_postchange_all();
1455
1456 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1457 bgp_vpn_leak_export(bgp);
1458 /* Pending: handle when user tries to change a view to vrf n vv.
1459 */
1460 }
1461
1462 /* unset the auto created flag as the user config is now present */
1463 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1464 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1465
1466 return CMD_SUCCESS;
1467 }
1468
1469 /* "no router bgp" commands. */
1470 DEFUN (no_router_bgp,
1471 no_router_bgp_cmd,
1472 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1473 NO_STR
1474 ROUTER_STR
1475 BGP_STR
1476 AS_STR
1477 BGP_INSTANCE_HELP_STR)
1478 {
1479 int idx_asn = 3;
1480 int idx_vrf = 5;
1481 as_t as;
1482 struct bgp *bgp;
1483 const char *name = NULL;
1484
1485 // "no router bgp" without an ASN
1486 if (argc == 3) {
1487 // Pending: Make VRF option available for ASN less config
1488 bgp = bgp_get_default();
1489
1490 if (bgp == NULL) {
1491 vty_out(vty, "%% No BGP process is configured\n");
1492 return CMD_WARNING_CONFIG_FAILED;
1493 }
1494
1495 if (listcount(bm->bgp) > 1) {
1496 vty_out(vty, "%% Please specify ASN and VRF\n");
1497 return CMD_WARNING_CONFIG_FAILED;
1498 }
1499
1500 if (bgp->l3vni) {
1501 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1502 bgp->l3vni);
1503 return CMD_WARNING_CONFIG_FAILED;
1504 }
1505 } else {
1506 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1507
1508 if (argc > 4) {
1509 name = argv[idx_vrf]->arg;
1510 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1511 && strmatch(name, VRF_DEFAULT_NAME))
1512 name = NULL;
1513 }
1514
1515 /* Lookup bgp structure. */
1516 bgp = bgp_lookup(as, name);
1517 if (!bgp) {
1518 vty_out(vty, "%% Can't find BGP instance\n");
1519 return CMD_WARNING_CONFIG_FAILED;
1520 }
1521
1522 if (bgp->l3vni) {
1523 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1524 bgp->l3vni);
1525 return CMD_WARNING_CONFIG_FAILED;
1526 }
1527
1528 /* Cannot delete default instance if vrf instances exist */
1529 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1530 struct listnode *node;
1531 struct bgp *tmp_bgp;
1532
1533 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1534 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1535 continue;
1536 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1537 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1538 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1539 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1540 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1541 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1542 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1543 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1544 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1545 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1546 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1547 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1548 (bgp == bgp_get_evpn() &&
1549 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1550 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1551 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1552 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1553 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1554 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1555 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1556 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1557 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1558 vty_out(vty,
1559 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1560 return CMD_WARNING_CONFIG_FAILED;
1561 }
1562 }
1563 }
1564 }
1565
1566 bgp_delete(bgp);
1567
1568 return CMD_SUCCESS;
1569 }
1570
1571 /* bgp session-dscp */
1572
1573 DEFPY (bgp_session_dscp,
1574 bgp_session_dscp_cmd,
1575 "bgp session-dscp (0-63)$dscp",
1576 BGP_STR
1577 "Override default (C6) bgp TCP session DSCP value\n"
1578 "Manually configured dscp parameter\n")
1579 {
1580 bm->tcp_dscp = dscp << 2;
1581
1582 return CMD_SUCCESS;
1583 }
1584
1585 DEFPY (no_bgp_session_dscp,
1586 no_bgp_session_dscp_cmd,
1587 "no bgp session-dscp [(0-63)]",
1588 NO_STR
1589 BGP_STR
1590 "Override default (C6) bgp TCP session DSCP value\n"
1591 "Manually configured dscp parameter\n")
1592 {
1593 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1594
1595 return CMD_SUCCESS;
1596 }
1597
1598 /* BGP router-id. */
1599
1600 DEFPY (bgp_router_id,
1601 bgp_router_id_cmd,
1602 "bgp router-id A.B.C.D",
1603 BGP_STR
1604 "Override configured router identifier\n"
1605 "Manually configured router identifier\n")
1606 {
1607 VTY_DECLVAR_CONTEXT(bgp, bgp);
1608 bgp_router_id_static_set(bgp, router_id);
1609 return CMD_SUCCESS;
1610 }
1611
1612 DEFPY (no_bgp_router_id,
1613 no_bgp_router_id_cmd,
1614 "no bgp router-id [A.B.C.D]",
1615 NO_STR
1616 BGP_STR
1617 "Override configured router identifier\n"
1618 "Manually configured router identifier\n")
1619 {
1620 VTY_DECLVAR_CONTEXT(bgp, bgp);
1621
1622 if (router_id_str) {
1623 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1624 vty_out(vty, "%% BGP router-id doesn't match\n");
1625 return CMD_WARNING_CONFIG_FAILED;
1626 }
1627 }
1628
1629 router_id.s_addr = 0;
1630 bgp_router_id_static_set(bgp, router_id);
1631
1632 return CMD_SUCCESS;
1633 }
1634
1635 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1636 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1637 NO_STR BGP_STR
1638 "Add community specific parameters\n"
1639 "Create an alias for a community\n"
1640 "Community (AA:BB or AA:BB:CC)\n"
1641 "Alias name\n")
1642 {
1643 struct community_alias ca1;
1644 struct community_alias ca2;
1645 struct community_alias *lookup_community;
1646 struct community_alias *lookup_alias;
1647
1648 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1649 vty_out(vty, "Invalid community format\n");
1650 return CMD_WARNING;
1651 }
1652
1653 memset(&ca1, 0, sizeof(ca1));
1654 memset(&ca2, 0, sizeof(ca2));
1655 strlcpy(ca1.community, community, sizeof(ca1.community));
1656 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
1657
1658 lookup_community = bgp_ca_community_lookup(&ca1);
1659 lookup_alias = bgp_ca_alias_lookup(&ca1);
1660
1661 if (no) {
1662 bgp_ca_alias_delete(&ca1);
1663 bgp_ca_community_delete(&ca1);
1664 } else {
1665 if (lookup_alias) {
1666 /* Lookup if community hash table has an item
1667 * with the same alias name.
1668 */
1669 strlcpy(ca2.community, lookup_alias->community,
1670 sizeof(ca2.community));
1671 if (bgp_ca_community_lookup(&ca2)) {
1672 vty_out(vty,
1673 "community (%s) already has this alias (%s)\n",
1674 lookup_alias->community,
1675 lookup_alias->alias);
1676 return CMD_WARNING;
1677 }
1678 bgp_ca_alias_delete(&ca1);
1679 }
1680
1681 if (lookup_community)
1682 bgp_ca_community_delete(&ca1);
1683
1684 bgp_ca_alias_insert(&ca1);
1685 bgp_ca_community_insert(&ca1);
1686 }
1687
1688 return CMD_SUCCESS;
1689 }
1690
1691 DEFPY (bgp_global_suppress_fib_pending,
1692 bgp_global_suppress_fib_pending_cmd,
1693 "[no] bgp suppress-fib-pending",
1694 NO_STR
1695 BGP_STR
1696 "Advertise only routes that are programmed in kernel to peers globally\n")
1697 {
1698 bm_wait_for_fib_set(!no);
1699
1700 return CMD_SUCCESS;
1701 }
1702
1703 DEFPY (bgp_suppress_fib_pending,
1704 bgp_suppress_fib_pending_cmd,
1705 "[no] bgp suppress-fib-pending",
1706 NO_STR
1707 BGP_STR
1708 "Advertise only routes that are programmed in kernel to peers\n")
1709 {
1710 VTY_DECLVAR_CONTEXT(bgp, bgp);
1711
1712 bgp_suppress_fib_pending_set(bgp, !no);
1713 return CMD_SUCCESS;
1714 }
1715
1716
1717 /* BGP Cluster ID. */
1718 DEFUN (bgp_cluster_id,
1719 bgp_cluster_id_cmd,
1720 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1721 BGP_STR
1722 "Configure Route-Reflector Cluster-id\n"
1723 "Route-Reflector Cluster-id in IP address format\n"
1724 "Route-Reflector Cluster-id as 32 bit quantity\n")
1725 {
1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 int idx_ipv4 = 2;
1728 int ret;
1729 struct in_addr cluster;
1730
1731 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1732 if (!ret) {
1733 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1734 return CMD_WARNING_CONFIG_FAILED;
1735 }
1736
1737 bgp_cluster_id_set(bgp, &cluster);
1738 bgp_clear_star_soft_out(vty, bgp->name);
1739
1740 return CMD_SUCCESS;
1741 }
1742
1743 DEFUN (no_bgp_cluster_id,
1744 no_bgp_cluster_id_cmd,
1745 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1746 NO_STR
1747 BGP_STR
1748 "Configure Route-Reflector Cluster-id\n"
1749 "Route-Reflector Cluster-id in IP address format\n"
1750 "Route-Reflector Cluster-id as 32 bit quantity\n")
1751 {
1752 VTY_DECLVAR_CONTEXT(bgp, bgp);
1753 bgp_cluster_id_unset(bgp);
1754 bgp_clear_star_soft_out(vty, bgp->name);
1755
1756 return CMD_SUCCESS;
1757 }
1758
1759 DEFPY (bgp_norib,
1760 bgp_norib_cmd,
1761 "bgp no-rib",
1762 BGP_STR
1763 "Disable BGP route installation to RIB (Zebra)\n")
1764 {
1765 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1766 vty_out(vty,
1767 "%% No-RIB option is already set, nothing to do here.\n");
1768 return CMD_SUCCESS;
1769 }
1770
1771 bgp_option_norib_set_runtime();
1772
1773 return CMD_SUCCESS;
1774 }
1775
1776 DEFPY (no_bgp_norib,
1777 no_bgp_norib_cmd,
1778 "no bgp no-rib",
1779 NO_STR
1780 BGP_STR
1781 "Disable BGP route installation to RIB (Zebra)\n")
1782 {
1783 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1784 vty_out(vty,
1785 "%% No-RIB option is not set, nothing to do here.\n");
1786 return CMD_SUCCESS;
1787 }
1788
1789 bgp_option_norib_unset_runtime();
1790
1791 return CMD_SUCCESS;
1792 }
1793
1794 DEFPY (no_bgp_send_extra_data,
1795 no_bgp_send_extra_data_cmd,
1796 "[no] bgp send-extra-data zebra",
1797 NO_STR
1798 BGP_STR
1799 "Extra data to Zebra for display/use\n"
1800 "To zebra\n")
1801 {
1802 if (no)
1803 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1804 else
1805 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1806
1807 return CMD_SUCCESS;
1808 }
1809
1810 DEFUN (bgp_confederation_identifier,
1811 bgp_confederation_identifier_cmd,
1812 "bgp confederation identifier (1-4294967295)",
1813 BGP_STR
1814 "AS confederation parameters\n"
1815 "AS number\n"
1816 "Set routing domain confederation AS\n")
1817 {
1818 VTY_DECLVAR_CONTEXT(bgp, bgp);
1819 int idx_number = 3;
1820 as_t as;
1821
1822 as = strtoul(argv[idx_number]->arg, NULL, 10);
1823
1824 bgp_confederation_id_set(bgp, as);
1825
1826 return CMD_SUCCESS;
1827 }
1828
1829 DEFUN (no_bgp_confederation_identifier,
1830 no_bgp_confederation_identifier_cmd,
1831 "no bgp confederation identifier [(1-4294967295)]",
1832 NO_STR
1833 BGP_STR
1834 "AS confederation parameters\n"
1835 "AS number\n"
1836 "Set routing domain confederation AS\n")
1837 {
1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 bgp_confederation_id_unset(bgp);
1840
1841 return CMD_SUCCESS;
1842 }
1843
1844 DEFUN (bgp_confederation_peers,
1845 bgp_confederation_peers_cmd,
1846 "bgp confederation peers (1-4294967295)...",
1847 BGP_STR
1848 "AS confederation parameters\n"
1849 "Peer ASs in BGP confederation\n"
1850 AS_STR)
1851 {
1852 VTY_DECLVAR_CONTEXT(bgp, bgp);
1853 int idx_asn = 3;
1854 as_t as;
1855 int i;
1856
1857 for (i = idx_asn; i < argc; i++) {
1858 as = strtoul(argv[i]->arg, NULL, 10);
1859
1860 if (bgp->as == as) {
1861 vty_out(vty,
1862 "%% Local member-AS not allowed in confed peer list\n");
1863 continue;
1864 }
1865
1866 bgp_confederation_peers_add(bgp, as);
1867 }
1868 return CMD_SUCCESS;
1869 }
1870
1871 DEFUN (no_bgp_confederation_peers,
1872 no_bgp_confederation_peers_cmd,
1873 "no bgp confederation peers (1-4294967295)...",
1874 NO_STR
1875 BGP_STR
1876 "AS confederation parameters\n"
1877 "Peer ASs in BGP confederation\n"
1878 AS_STR)
1879 {
1880 VTY_DECLVAR_CONTEXT(bgp, bgp);
1881 int idx_asn = 4;
1882 as_t as;
1883 int i;
1884
1885 for (i = idx_asn; i < argc; i++) {
1886 as = strtoul(argv[i]->arg, NULL, 10);
1887
1888 bgp_confederation_peers_remove(bgp, as);
1889 }
1890 return CMD_SUCCESS;
1891 }
1892
1893 /**
1894 * Central routine for maximum-paths configuration.
1895 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1896 * @set: 1 for setting values, 0 for removing the max-paths config.
1897 */
1898 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1899 const char *mpaths, uint16_t options,
1900 int set)
1901 {
1902 VTY_DECLVAR_CONTEXT(bgp, bgp);
1903 uint16_t maxpaths = 0;
1904 int ret;
1905 afi_t afi;
1906 safi_t safi;
1907
1908 afi = bgp_node_afi(vty);
1909 safi = bgp_node_safi(vty);
1910
1911 if (set) {
1912 maxpaths = strtol(mpaths, NULL, 10);
1913 if (maxpaths > multipath_num) {
1914 vty_out(vty,
1915 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1916 maxpaths, multipath_num);
1917 return CMD_WARNING_CONFIG_FAILED;
1918 }
1919 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1920 options);
1921 } else
1922 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1923
1924 if (ret < 0) {
1925 vty_out(vty,
1926 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1927 (set == 1) ? "" : "un",
1928 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1929 maxpaths, afi, safi);
1930 return CMD_WARNING_CONFIG_FAILED;
1931 }
1932
1933 bgp_recalculate_all_bestpaths(bgp);
1934
1935 return CMD_SUCCESS;
1936 }
1937
1938 DEFUN (bgp_maxmed_admin,
1939 bgp_maxmed_admin_cmd,
1940 "bgp max-med administrative ",
1941 BGP_STR
1942 "Advertise routes with max-med\n"
1943 "Administratively applied, for an indefinite period\n")
1944 {
1945 VTY_DECLVAR_CONTEXT(bgp, bgp);
1946
1947 bgp->v_maxmed_admin = 1;
1948 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1949
1950 bgp_maxmed_update(bgp);
1951
1952 return CMD_SUCCESS;
1953 }
1954
1955 DEFUN (bgp_maxmed_admin_medv,
1956 bgp_maxmed_admin_medv_cmd,
1957 "bgp max-med administrative (0-4294967295)",
1958 BGP_STR
1959 "Advertise routes with max-med\n"
1960 "Administratively applied, for an indefinite period\n"
1961 "Max MED value to be used\n")
1962 {
1963 VTY_DECLVAR_CONTEXT(bgp, bgp);
1964 int idx_number = 3;
1965
1966 bgp->v_maxmed_admin = 1;
1967 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1968
1969 bgp_maxmed_update(bgp);
1970
1971 return CMD_SUCCESS;
1972 }
1973
1974 DEFUN (no_bgp_maxmed_admin,
1975 no_bgp_maxmed_admin_cmd,
1976 "no bgp max-med administrative [(0-4294967295)]",
1977 NO_STR
1978 BGP_STR
1979 "Advertise routes with max-med\n"
1980 "Administratively applied, for an indefinite period\n"
1981 "Max MED value to be used\n")
1982 {
1983 VTY_DECLVAR_CONTEXT(bgp, bgp);
1984 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1985 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1986 bgp_maxmed_update(bgp);
1987
1988 return CMD_SUCCESS;
1989 }
1990
1991 DEFUN (bgp_maxmed_onstartup,
1992 bgp_maxmed_onstartup_cmd,
1993 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1994 BGP_STR
1995 "Advertise routes with max-med\n"
1996 "Effective on a startup\n"
1997 "Time (seconds) period for max-med\n"
1998 "Max MED value to be used\n")
1999 {
2000 VTY_DECLVAR_CONTEXT(bgp, bgp);
2001 int idx = 0;
2002
2003 if (argv_find(argv, argc, "(5-86400)", &idx))
2004 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2005 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2006 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2007 else
2008 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2009
2010 bgp_maxmed_update(bgp);
2011
2012 return CMD_SUCCESS;
2013 }
2014
2015 DEFUN (no_bgp_maxmed_onstartup,
2016 no_bgp_maxmed_onstartup_cmd,
2017 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2018 NO_STR
2019 BGP_STR
2020 "Advertise routes with max-med\n"
2021 "Effective on a startup\n"
2022 "Time (seconds) period for max-med\n"
2023 "Max MED value to be used\n")
2024 {
2025 VTY_DECLVAR_CONTEXT(bgp, bgp);
2026
2027 /* Cancel max-med onstartup if its on */
2028 if (bgp->t_maxmed_onstartup) {
2029 thread_cancel(&bgp->t_maxmed_onstartup);
2030 bgp->maxmed_onstartup_over = 1;
2031 }
2032
2033 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2034 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2035
2036 bgp_maxmed_update(bgp);
2037
2038 return CMD_SUCCESS;
2039 }
2040
2041 static int bgp_global_update_delay_config_vty(struct vty *vty,
2042 uint16_t update_delay,
2043 uint16_t establish_wait)
2044 {
2045 struct listnode *node, *nnode;
2046 struct bgp *bgp;
2047 bool vrf_cfg = false;
2048
2049 /*
2050 * See if update-delay is set per-vrf and warn user to delete it
2051 * Note that we only need to check this if this is the first time
2052 * setting the global config.
2053 */
2054 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2055 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2056 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2057 vty_out(vty,
2058 "%% update-delay configuration found in vrf %s\n",
2059 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2060 ? VRF_DEFAULT_NAME
2061 : bgp->name);
2062 vrf_cfg = true;
2063 }
2064 }
2065 }
2066
2067 if (vrf_cfg) {
2068 vty_out(vty,
2069 "%%Failed: global update-delay config not permitted\n");
2070 return CMD_WARNING;
2071 }
2072
2073 if (!establish_wait) { /* update-delay <delay> */
2074 bm->v_update_delay = update_delay;
2075 bm->v_establish_wait = bm->v_update_delay;
2076 } else {
2077 /* update-delay <delay> <establish-wait> */
2078 if (update_delay < establish_wait) {
2079 vty_out(vty,
2080 "%%Failed: update-delay less than the establish-wait!\n");
2081 return CMD_WARNING_CONFIG_FAILED;
2082 }
2083
2084 bm->v_update_delay = update_delay;
2085 bm->v_establish_wait = establish_wait;
2086 }
2087
2088 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2089 bgp->v_update_delay = bm->v_update_delay;
2090 bgp->v_establish_wait = bm->v_establish_wait;
2091 }
2092
2093 return CMD_SUCCESS;
2094 }
2095
2096 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2097 {
2098 struct listnode *node, *nnode;
2099 struct bgp *bgp;
2100
2101 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2102 bm->v_establish_wait = bm->v_update_delay;
2103
2104 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2105 bgp->v_update_delay = bm->v_update_delay;
2106 bgp->v_establish_wait = bm->v_establish_wait;
2107 }
2108
2109 return CMD_SUCCESS;
2110 }
2111
2112 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2113 uint16_t establish_wait)
2114 {
2115 VTY_DECLVAR_CONTEXT(bgp, bgp);
2116
2117 /* if configured globally, per-instance config is not allowed */
2118 if (bm->v_update_delay) {
2119 vty_out(vty,
2120 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2121 return CMD_WARNING_CONFIG_FAILED;
2122 }
2123
2124
2125 if (!establish_wait) /* update-delay <delay> */
2126 {
2127 bgp->v_update_delay = update_delay;
2128 bgp->v_establish_wait = bgp->v_update_delay;
2129 return CMD_SUCCESS;
2130 }
2131
2132 /* update-delay <delay> <establish-wait> */
2133 if (update_delay < establish_wait) {
2134 vty_out(vty,
2135 "%%Failed: update-delay less than the establish-wait!\n");
2136 return CMD_WARNING_CONFIG_FAILED;
2137 }
2138
2139 bgp->v_update_delay = update_delay;
2140 bgp->v_establish_wait = establish_wait;
2141
2142 return CMD_SUCCESS;
2143 }
2144
2145 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2146 {
2147 VTY_DECLVAR_CONTEXT(bgp, bgp);
2148
2149 /* If configured globally, cannot remove from one bgp instance */
2150 if (bm->v_update_delay) {
2151 vty_out(vty,
2152 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2153 return CMD_WARNING_CONFIG_FAILED;
2154 }
2155 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2156 bgp->v_establish_wait = bgp->v_update_delay;
2157
2158 return CMD_SUCCESS;
2159 }
2160
2161 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2162 {
2163 /* If configured globally, no need to display per-instance value */
2164 if (bgp->v_update_delay != bm->v_update_delay) {
2165 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2166 if (bgp->v_update_delay != bgp->v_establish_wait)
2167 vty_out(vty, " %d", bgp->v_establish_wait);
2168 vty_out(vty, "\n");
2169 }
2170 }
2171
2172 /* Global update-delay configuration */
2173 DEFPY (bgp_global_update_delay,
2174 bgp_global_update_delay_cmd,
2175 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2176 BGP_STR
2177 "Force initial delay for best-path and updates for all bgp instances\n"
2178 "Max delay in seconds\n"
2179 "Establish wait in seconds\n")
2180 {
2181 return bgp_global_update_delay_config_vty(vty, delay, wait);
2182 }
2183
2184 /* Global update-delay deconfiguration */
2185 DEFPY (no_bgp_global_update_delay,
2186 no_bgp_global_update_delay_cmd,
2187 "no bgp update-delay [(0-3600) [(1-3600)]]",
2188 NO_STR
2189 BGP_STR
2190 "Force initial delay for best-path and updates\n"
2191 "Max delay in seconds\n"
2192 "Establish wait in seconds\n")
2193 {
2194 return bgp_global_update_delay_deconfig_vty(vty);
2195 }
2196
2197 /* Update-delay configuration */
2198
2199 DEFPY (bgp_update_delay,
2200 bgp_update_delay_cmd,
2201 "update-delay (0-3600)$delay [(1-3600)$wait]",
2202 "Force initial delay for best-path and updates\n"
2203 "Max delay in seconds\n"
2204 "Establish wait in seconds\n")
2205 {
2206 return bgp_update_delay_config_vty(vty, delay, wait);
2207 }
2208
2209 /* Update-delay deconfiguration */
2210 DEFPY (no_bgp_update_delay,
2211 no_bgp_update_delay_cmd,
2212 "no update-delay [(0-3600) [(1-3600)]]",
2213 NO_STR
2214 "Force initial delay for best-path and updates\n"
2215 "Max delay in seconds\n"
2216 "Establish wait in seconds\n")
2217 {
2218 return bgp_update_delay_deconfig_vty(vty);
2219 }
2220
2221
2222 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2223 bool set)
2224 {
2225 VTY_DECLVAR_CONTEXT(bgp, bgp);
2226
2227 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2228 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2229
2230 return CMD_SUCCESS;
2231 }
2232
2233 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2234 bool set)
2235 {
2236 VTY_DECLVAR_CONTEXT(bgp, bgp);
2237
2238 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2239 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2240
2241 return CMD_SUCCESS;
2242 }
2243
2244 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2245 {
2246 uint32_t quanta =
2247 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2248 if (quanta != BGP_WRITE_PACKET_MAX)
2249 vty_out(vty, " write-quanta %d\n", quanta);
2250 }
2251
2252 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2253 {
2254 uint32_t quanta =
2255 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2256 if (quanta != BGP_READ_PACKET_MAX)
2257 vty_out(vty, " read-quanta %d\n", quanta);
2258 }
2259
2260 /* Packet quanta configuration
2261 *
2262 * XXX: The value set here controls the size of a stack buffer in the IO
2263 * thread. When changing these limits be careful to prevent stack overflow.
2264 *
2265 * Furthermore, the maximums used here should correspond to
2266 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2267 */
2268 DEFPY (bgp_wpkt_quanta,
2269 bgp_wpkt_quanta_cmd,
2270 "[no] write-quanta (1-64)$quanta",
2271 NO_STR
2272 "How many packets to write to peer socket per run\n"
2273 "Number of packets\n")
2274 {
2275 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2276 }
2277
2278 DEFPY (bgp_rpkt_quanta,
2279 bgp_rpkt_quanta_cmd,
2280 "[no] read-quanta (1-10)$quanta",
2281 NO_STR
2282 "How many packets to read from peer socket per I/O cycle\n"
2283 "Number of packets\n")
2284 {
2285 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2286 }
2287
2288 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2289 {
2290 if (!bgp->heuristic_coalesce)
2291 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2292 }
2293
2294
2295 DEFUN (bgp_coalesce_time,
2296 bgp_coalesce_time_cmd,
2297 "coalesce-time (0-4294967295)",
2298 "Subgroup coalesce timer\n"
2299 "Subgroup coalesce timer value (in ms)\n")
2300 {
2301 VTY_DECLVAR_CONTEXT(bgp, bgp);
2302
2303 int idx = 0;
2304
2305 bgp->heuristic_coalesce = false;
2306
2307 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2308 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2309
2310 return CMD_SUCCESS;
2311 }
2312
2313 DEFUN (no_bgp_coalesce_time,
2314 no_bgp_coalesce_time_cmd,
2315 "no coalesce-time (0-4294967295)",
2316 NO_STR
2317 "Subgroup coalesce timer\n"
2318 "Subgroup coalesce timer value (in ms)\n")
2319 {
2320 VTY_DECLVAR_CONTEXT(bgp, bgp);
2321
2322 bgp->heuristic_coalesce = true;
2323 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2324 return CMD_SUCCESS;
2325 }
2326
2327 /* Maximum-paths configuration */
2328 DEFUN (bgp_maxpaths,
2329 bgp_maxpaths_cmd,
2330 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2331 "Forward packets over multiple paths\n"
2332 "Number of paths\n")
2333 {
2334 int idx_number = 1;
2335 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2336 argv[idx_number]->arg, 0, 1);
2337 }
2338
2339 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2340 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2341 "Forward packets over multiple paths\n"
2342 "Number of paths\n")
2343
2344 DEFUN (bgp_maxpaths_ibgp,
2345 bgp_maxpaths_ibgp_cmd,
2346 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2347 "Forward packets over multiple paths\n"
2348 "iBGP-multipath\n"
2349 "Number of paths\n")
2350 {
2351 int idx_number = 2;
2352 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2353 argv[idx_number]->arg, 0, 1);
2354 }
2355
2356 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2357 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2358 "Forward packets over multiple paths\n"
2359 "iBGP-multipath\n"
2360 "Number of paths\n")
2361
2362 DEFUN (bgp_maxpaths_ibgp_cluster,
2363 bgp_maxpaths_ibgp_cluster_cmd,
2364 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2365 "Forward packets over multiple paths\n"
2366 "iBGP-multipath\n"
2367 "Number of paths\n"
2368 "Match the cluster length\n")
2369 {
2370 int idx_number = 2;
2371 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2372 argv[idx_number]->arg, true, 1);
2373 }
2374
2375 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2376 "maximum-paths ibgp " CMD_RANGE_STR(
2377 1, MULTIPATH_NUM) " equal-cluster-length",
2378 "Forward packets over multiple paths\n"
2379 "iBGP-multipath\n"
2380 "Number of paths\n"
2381 "Match the cluster length\n")
2382
2383 DEFUN (no_bgp_maxpaths,
2384 no_bgp_maxpaths_cmd,
2385 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2386 NO_STR
2387 "Forward packets over multiple paths\n"
2388 "Number of paths\n")
2389 {
2390 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2391 }
2392
2393 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2394 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2395 "Forward packets over multiple paths\n"
2396 "Number of paths\n")
2397
2398 DEFUN (no_bgp_maxpaths_ibgp,
2399 no_bgp_maxpaths_ibgp_cmd,
2400 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2401 NO_STR
2402 "Forward packets over multiple paths\n"
2403 "iBGP-multipath\n"
2404 "Number of paths\n"
2405 "Match the cluster length\n")
2406 {
2407 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2408 }
2409
2410 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2411 "no maximum-paths ibgp [" CMD_RANGE_STR(
2412 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2413 NO_STR
2414 "Forward packets over multiple paths\n"
2415 "iBGP-multipath\n"
2416 "Number of paths\n"
2417 "Match the cluster length\n")
2418
2419 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2420 afi_t afi, safi_t safi)
2421 {
2422 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2423 vty_out(vty, " maximum-paths %d\n",
2424 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2425 }
2426
2427 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2428 vty_out(vty, " maximum-paths ibgp %d",
2429 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2430 if (bgp->maxpaths[afi][safi].same_clusterlen)
2431 vty_out(vty, " equal-cluster-length");
2432 vty_out(vty, "\n");
2433 }
2434 }
2435
2436 /* BGP timers. */
2437
2438 DEFUN (bgp_timers,
2439 bgp_timers_cmd,
2440 "timers bgp (0-65535) (0-65535)",
2441 "Adjust routing timers\n"
2442 "BGP timers\n"
2443 "Keepalive interval\n"
2444 "Holdtime\n")
2445 {
2446 VTY_DECLVAR_CONTEXT(bgp, bgp);
2447 int idx_number = 2;
2448 int idx_number_2 = 3;
2449 unsigned long keepalive = 0;
2450 unsigned long holdtime = 0;
2451
2452 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2453 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2454
2455 /* Holdtime value check. */
2456 if (holdtime < 3 && holdtime != 0) {
2457 vty_out(vty,
2458 "%% hold time value must be either 0 or greater than 3\n");
2459 return CMD_WARNING_CONFIG_FAILED;
2460 }
2461
2462 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2463 BGP_DEFAULT_DELAYOPEN);
2464
2465 return CMD_SUCCESS;
2466 }
2467
2468 DEFUN (no_bgp_timers,
2469 no_bgp_timers_cmd,
2470 "no timers bgp [(0-65535) (0-65535)]",
2471 NO_STR
2472 "Adjust routing timers\n"
2473 "BGP timers\n"
2474 "Keepalive interval\n"
2475 "Holdtime\n")
2476 {
2477 VTY_DECLVAR_CONTEXT(bgp, bgp);
2478 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2479 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2480
2481 return CMD_SUCCESS;
2482 }
2483
2484 /* BGP minimum holdtime. */
2485
2486 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2487 "bgp minimum-holdtime (1-65535)",
2488 "BGP specific commands\n"
2489 "BGP minimum holdtime\n"
2490 "Seconds\n")
2491 {
2492 VTY_DECLVAR_CONTEXT(bgp, bgp);
2493 int idx_number = 2;
2494 unsigned long min_holdtime;
2495
2496 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2497
2498 bgp->default_min_holdtime = min_holdtime;
2499
2500 return CMD_SUCCESS;
2501 }
2502
2503 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2504 "no bgp minimum-holdtime [(1-65535)]",
2505 NO_STR
2506 "BGP specific commands\n"
2507 "BGP minimum holdtime\n"
2508 "Seconds\n")
2509 {
2510 VTY_DECLVAR_CONTEXT(bgp, bgp);
2511
2512 bgp->default_min_holdtime = 0;
2513
2514 return CMD_SUCCESS;
2515 }
2516
2517 DEFUN (bgp_client_to_client_reflection,
2518 bgp_client_to_client_reflection_cmd,
2519 "bgp client-to-client reflection",
2520 BGP_STR
2521 "Configure client to client route reflection\n"
2522 "reflection of routes allowed\n")
2523 {
2524 VTY_DECLVAR_CONTEXT(bgp, bgp);
2525 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2526 bgp_clear_star_soft_out(vty, bgp->name);
2527
2528 return CMD_SUCCESS;
2529 }
2530
2531 DEFUN (no_bgp_client_to_client_reflection,
2532 no_bgp_client_to_client_reflection_cmd,
2533 "no bgp client-to-client reflection",
2534 NO_STR
2535 BGP_STR
2536 "Configure client to client route reflection\n"
2537 "reflection of routes allowed\n")
2538 {
2539 VTY_DECLVAR_CONTEXT(bgp, bgp);
2540 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2541 bgp_clear_star_soft_out(vty, bgp->name);
2542
2543 return CMD_SUCCESS;
2544 }
2545
2546 /* "bgp always-compare-med" configuration. */
2547 DEFUN (bgp_always_compare_med,
2548 bgp_always_compare_med_cmd,
2549 "bgp always-compare-med",
2550 BGP_STR
2551 "Allow comparing MED from different neighbors\n")
2552 {
2553 VTY_DECLVAR_CONTEXT(bgp, bgp);
2554 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2555 bgp_recalculate_all_bestpaths(bgp);
2556
2557 return CMD_SUCCESS;
2558 }
2559
2560 DEFUN (no_bgp_always_compare_med,
2561 no_bgp_always_compare_med_cmd,
2562 "no bgp always-compare-med",
2563 NO_STR
2564 BGP_STR
2565 "Allow comparing MED from different neighbors\n")
2566 {
2567 VTY_DECLVAR_CONTEXT(bgp, bgp);
2568 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2569 bgp_recalculate_all_bestpaths(bgp);
2570
2571 return CMD_SUCCESS;
2572 }
2573
2574
2575 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2576 "bgp ebgp-requires-policy",
2577 BGP_STR
2578 "Require in and out policy for eBGP peers (RFC8212)\n")
2579 {
2580 VTY_DECLVAR_CONTEXT(bgp, bgp);
2581 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2582 return CMD_SUCCESS;
2583 }
2584
2585 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2586 "no bgp ebgp-requires-policy",
2587 NO_STR
2588 BGP_STR
2589 "Require in and out policy for eBGP peers (RFC8212)\n")
2590 {
2591 VTY_DECLVAR_CONTEXT(bgp, bgp);
2592 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2593 return CMD_SUCCESS;
2594 }
2595
2596 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2597 "bgp suppress-duplicates",
2598 BGP_STR
2599 "Suppress duplicate updates if the route actually not changed\n")
2600 {
2601 VTY_DECLVAR_CONTEXT(bgp, bgp);
2602 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2603 return CMD_SUCCESS;
2604 }
2605
2606 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2607 "no bgp suppress-duplicates",
2608 NO_STR
2609 BGP_STR
2610 "Suppress duplicate updates if the route actually not changed\n")
2611 {
2612 VTY_DECLVAR_CONTEXT(bgp, bgp);
2613 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2614 return CMD_SUCCESS;
2615 }
2616
2617 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2618 "bgp reject-as-sets",
2619 BGP_STR
2620 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2621 {
2622 VTY_DECLVAR_CONTEXT(bgp, bgp);
2623 struct listnode *node, *nnode;
2624 struct peer *peer;
2625
2626 bgp->reject_as_sets = true;
2627
2628 /* Reset existing BGP sessions to reject routes
2629 * with aspath containing AS_SET or AS_CONFED_SET.
2630 */
2631 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2632 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2633 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2634 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2635 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2636 }
2637 }
2638
2639 return CMD_SUCCESS;
2640 }
2641
2642 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2643 "no bgp reject-as-sets",
2644 NO_STR
2645 BGP_STR
2646 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2647 {
2648 VTY_DECLVAR_CONTEXT(bgp, bgp);
2649 struct listnode *node, *nnode;
2650 struct peer *peer;
2651
2652 bgp->reject_as_sets = false;
2653
2654 /* Reset existing BGP sessions to reject routes
2655 * with aspath containing AS_SET or AS_CONFED_SET.
2656 */
2657 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2658 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2659 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2660 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2661 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2662 }
2663 }
2664
2665 return CMD_SUCCESS;
2666 }
2667
2668 /* "bgp deterministic-med" configuration. */
2669 DEFUN (bgp_deterministic_med,
2670 bgp_deterministic_med_cmd,
2671 "bgp deterministic-med",
2672 BGP_STR
2673 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2674 {
2675 VTY_DECLVAR_CONTEXT(bgp, bgp);
2676
2677 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2678 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2679 bgp_recalculate_all_bestpaths(bgp);
2680 }
2681
2682 return CMD_SUCCESS;
2683 }
2684
2685 DEFUN (no_bgp_deterministic_med,
2686 no_bgp_deterministic_med_cmd,
2687 "no bgp deterministic-med",
2688 NO_STR
2689 BGP_STR
2690 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2691 {
2692 VTY_DECLVAR_CONTEXT(bgp, bgp);
2693 int bestpath_per_as_used;
2694 afi_t afi;
2695 safi_t safi;
2696 struct peer *peer;
2697 struct listnode *node, *nnode;
2698
2699 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2700 bestpath_per_as_used = 0;
2701
2702 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2703 FOREACH_AFI_SAFI (afi, safi)
2704 if (bgp_addpath_dmed_required(
2705 peer->addpath_type[afi][safi])) {
2706 bestpath_per_as_used = 1;
2707 break;
2708 }
2709
2710 if (bestpath_per_as_used)
2711 break;
2712 }
2713
2714 if (bestpath_per_as_used) {
2715 vty_out(vty,
2716 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2717 return CMD_WARNING_CONFIG_FAILED;
2718 } else {
2719 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2720 bgp_recalculate_all_bestpaths(bgp);
2721 }
2722 }
2723
2724 return CMD_SUCCESS;
2725 }
2726
2727 /* "bgp graceful-restart mode" configuration. */
2728 DEFUN (bgp_graceful_restart,
2729 bgp_graceful_restart_cmd,
2730 "bgp graceful-restart",
2731 BGP_STR
2732 GR_CMD
2733 )
2734 {
2735 int ret = BGP_GR_FAILURE;
2736
2737 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2738 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2739
2740 VTY_DECLVAR_CONTEXT(bgp, bgp);
2741
2742 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2743
2744 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2745 ret);
2746
2747 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2748 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2749 vty_out(vty,
2750 "Graceful restart configuration changed, reset all peers to take effect\n");
2751 return bgp_vty_return(vty, ret);
2752 }
2753
2754 DEFUN (no_bgp_graceful_restart,
2755 no_bgp_graceful_restart_cmd,
2756 "no bgp graceful-restart",
2757 NO_STR
2758 BGP_STR
2759 NO_GR_CMD
2760 )
2761 {
2762 VTY_DECLVAR_CONTEXT(bgp, bgp);
2763
2764 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2765 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2766
2767 int ret = BGP_GR_FAILURE;
2768
2769 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2770
2771 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2772 ret);
2773
2774 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2775 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2776 vty_out(vty,
2777 "Graceful restart configuration changed, reset all peers to take effect\n");
2778
2779 return bgp_vty_return(vty, ret);
2780 }
2781
2782 DEFUN (bgp_graceful_restart_stalepath_time,
2783 bgp_graceful_restart_stalepath_time_cmd,
2784 "bgp graceful-restart stalepath-time (1-4095)",
2785 BGP_STR
2786 "Graceful restart capability parameters\n"
2787 "Set the max time to hold onto restarting peer's stale paths\n"
2788 "Delay value (seconds)\n")
2789 {
2790 VTY_DECLVAR_CONTEXT(bgp, bgp);
2791 int idx_number = 3;
2792 uint32_t stalepath;
2793
2794 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2795 bgp->stalepath_time = stalepath;
2796 return CMD_SUCCESS;
2797 }
2798
2799 DEFUN (bgp_graceful_restart_restart_time,
2800 bgp_graceful_restart_restart_time_cmd,
2801 "bgp graceful-restart restart-time (0-4095)",
2802 BGP_STR
2803 "Graceful restart capability parameters\n"
2804 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2805 "Delay value (seconds)\n")
2806 {
2807 VTY_DECLVAR_CONTEXT(bgp, bgp);
2808 int idx_number = 3;
2809 uint32_t restart;
2810
2811 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2812 bgp->restart_time = restart;
2813 return CMD_SUCCESS;
2814 }
2815
2816 DEFUN (bgp_graceful_restart_select_defer_time,
2817 bgp_graceful_restart_select_defer_time_cmd,
2818 "bgp graceful-restart select-defer-time (0-3600)",
2819 BGP_STR
2820 "Graceful restart capability parameters\n"
2821 "Set the time to defer the BGP route selection after restart\n"
2822 "Delay value (seconds, 0 - disable)\n")
2823 {
2824 VTY_DECLVAR_CONTEXT(bgp, bgp);
2825 int idx_number = 3;
2826 uint32_t defer_time;
2827
2828 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2829 bgp->select_defer_time = defer_time;
2830 if (defer_time == 0)
2831 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2832 else
2833 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2834
2835 return CMD_SUCCESS;
2836 }
2837
2838 DEFUN (no_bgp_graceful_restart_stalepath_time,
2839 no_bgp_graceful_restart_stalepath_time_cmd,
2840 "no bgp graceful-restart stalepath-time [(1-4095)]",
2841 NO_STR
2842 BGP_STR
2843 "Graceful restart capability parameters\n"
2844 "Set the max time to hold onto restarting peer's stale paths\n"
2845 "Delay value (seconds)\n")
2846 {
2847 VTY_DECLVAR_CONTEXT(bgp, bgp);
2848
2849 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2850 return CMD_SUCCESS;
2851 }
2852
2853 DEFUN (no_bgp_graceful_restart_restart_time,
2854 no_bgp_graceful_restart_restart_time_cmd,
2855 "no bgp graceful-restart restart-time [(0-4095)]",
2856 NO_STR
2857 BGP_STR
2858 "Graceful restart capability parameters\n"
2859 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2860 "Delay value (seconds)\n")
2861 {
2862 VTY_DECLVAR_CONTEXT(bgp, bgp);
2863
2864 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2865 return CMD_SUCCESS;
2866 }
2867
2868 DEFUN (no_bgp_graceful_restart_select_defer_time,
2869 no_bgp_graceful_restart_select_defer_time_cmd,
2870 "no bgp graceful-restart select-defer-time [(0-3600)]",
2871 NO_STR
2872 BGP_STR
2873 "Graceful restart capability parameters\n"
2874 "Set the time to defer the BGP route selection after restart\n"
2875 "Delay value (seconds)\n")
2876 {
2877 VTY_DECLVAR_CONTEXT(bgp, bgp);
2878
2879 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2880 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2881
2882 return CMD_SUCCESS;
2883 }
2884
2885 DEFUN (bgp_graceful_restart_preserve_fw,
2886 bgp_graceful_restart_preserve_fw_cmd,
2887 "bgp graceful-restart preserve-fw-state",
2888 BGP_STR
2889 "Graceful restart capability parameters\n"
2890 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2891 {
2892 VTY_DECLVAR_CONTEXT(bgp, bgp);
2893 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2894 return CMD_SUCCESS;
2895 }
2896
2897 DEFUN (no_bgp_graceful_restart_preserve_fw,
2898 no_bgp_graceful_restart_preserve_fw_cmd,
2899 "no bgp graceful-restart preserve-fw-state",
2900 NO_STR
2901 BGP_STR
2902 "Graceful restart capability parameters\n"
2903 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2904 {
2905 VTY_DECLVAR_CONTEXT(bgp, bgp);
2906 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2907 return CMD_SUCCESS;
2908 }
2909
2910 DEFPY (bgp_graceful_restart_notification,
2911 bgp_graceful_restart_notification_cmd,
2912 "[no$no] bgp graceful-restart notification",
2913 NO_STR
2914 BGP_STR
2915 "Graceful restart capability parameters\n"
2916 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2917 {
2918 VTY_DECLVAR_CONTEXT(bgp, bgp);
2919
2920 if (no)
2921 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2922 else
2923 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2924
2925 return CMD_SUCCESS;
2926 }
2927
2928 DEFPY (bgp_administrative_reset,
2929 bgp_administrative_reset_cmd,
2930 "[no$no] bgp hard-administrative-reset",
2931 NO_STR
2932 BGP_STR
2933 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2934 {
2935 VTY_DECLVAR_CONTEXT(bgp, bgp);
2936
2937 if (no)
2938 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2939 else
2940 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2941
2942 return CMD_SUCCESS;
2943 }
2944
2945 DEFUN (bgp_graceful_restart_disable,
2946 bgp_graceful_restart_disable_cmd,
2947 "bgp graceful-restart-disable",
2948 BGP_STR
2949 GR_DISABLE)
2950 {
2951 int ret = BGP_GR_FAILURE;
2952
2953 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2954 zlog_debug(
2955 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2956
2957 VTY_DECLVAR_CONTEXT(bgp, bgp);
2958
2959 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2960
2961 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2962 bgp->peer, ret);
2963
2964 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2965 zlog_debug(
2966 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2967 vty_out(vty,
2968 "Graceful restart configuration changed, reset all peers to take effect\n");
2969
2970 return bgp_vty_return(vty, ret);
2971 }
2972
2973 DEFUN (no_bgp_graceful_restart_disable,
2974 no_bgp_graceful_restart_disable_cmd,
2975 "no bgp graceful-restart-disable",
2976 NO_STR
2977 BGP_STR
2978 NO_GR_DISABLE
2979 )
2980 {
2981 VTY_DECLVAR_CONTEXT(bgp, bgp);
2982
2983 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2984 zlog_debug(
2985 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2986
2987 int ret = BGP_GR_FAILURE;
2988
2989 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2990
2991 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2992 ret);
2993
2994 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2995 zlog_debug(
2996 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2997 vty_out(vty,
2998 "Graceful restart configuration changed, reset all peers to take effect\n");
2999
3000 return bgp_vty_return(vty, ret);
3001 }
3002
3003 DEFUN (bgp_neighbor_graceful_restart_set,
3004 bgp_neighbor_graceful_restart_set_cmd,
3005 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3006 NEIGHBOR_STR
3007 NEIGHBOR_ADDR_STR2
3008 GR_NEIGHBOR_CMD
3009 )
3010 {
3011 int idx_peer = 1;
3012 struct peer *peer;
3013 int ret = BGP_GR_FAILURE;
3014
3015 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3016
3017 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3018 zlog_debug(
3019 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3020
3021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3022 if (!peer)
3023 return CMD_WARNING_CONFIG_FAILED;
3024
3025 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3026
3027 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3028 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3029
3030 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3031 zlog_debug(
3032 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3033 vty_out(vty,
3034 "Graceful restart configuration changed, reset this peer to take effect\n");
3035
3036 return bgp_vty_return(vty, ret);
3037 }
3038
3039 DEFUN (no_bgp_neighbor_graceful_restart,
3040 no_bgp_neighbor_graceful_restart_set_cmd,
3041 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3042 NO_STR
3043 NEIGHBOR_STR
3044 NEIGHBOR_ADDR_STR2
3045 NO_GR_NEIGHBOR_CMD
3046 )
3047 {
3048 int idx_peer = 2;
3049 int ret = BGP_GR_FAILURE;
3050 struct peer *peer;
3051
3052 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3053
3054 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3055 if (!peer)
3056 return CMD_WARNING_CONFIG_FAILED;
3057
3058 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3059 zlog_debug(
3060 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3061
3062 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3063
3064 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3065 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3066
3067 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3068 zlog_debug(
3069 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3070 vty_out(vty,
3071 "Graceful restart configuration changed, reset this peer to take effect\n");
3072
3073 return bgp_vty_return(vty, ret);
3074 }
3075
3076 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3077 bgp_neighbor_graceful_restart_helper_set_cmd,
3078 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3079 NEIGHBOR_STR
3080 NEIGHBOR_ADDR_STR2
3081 GR_NEIGHBOR_HELPER_CMD
3082 )
3083 {
3084 int idx_peer = 1;
3085 struct peer *peer;
3086 int ret = BGP_GR_FAILURE;
3087
3088 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3089
3090 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3091 zlog_debug(
3092 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3093
3094 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3095
3096 if (!peer)
3097 return CMD_WARNING_CONFIG_FAILED;
3098
3099
3100 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3101
3102 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3103 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3104
3105 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3106 zlog_debug(
3107 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3108 vty_out(vty,
3109 "Graceful restart configuration changed, reset this peer to take effect\n");
3110
3111 return bgp_vty_return(vty, ret);
3112 }
3113
3114 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3115 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3116 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3117 NO_STR
3118 NEIGHBOR_STR
3119 NEIGHBOR_ADDR_STR2
3120 NO_GR_NEIGHBOR_HELPER_CMD
3121 )
3122 {
3123 int idx_peer = 2;
3124 int ret = BGP_GR_FAILURE;
3125 struct peer *peer;
3126
3127 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3128
3129 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3130 if (!peer)
3131 return CMD_WARNING_CONFIG_FAILED;
3132
3133 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3134 zlog_debug(
3135 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3136
3137 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3138
3139 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3140 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3141
3142 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3143 zlog_debug(
3144 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3145 vty_out(vty,
3146 "Graceful restart configuration changed, reset this peer to take effect\n");
3147
3148 return bgp_vty_return(vty, ret);
3149 }
3150
3151 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3152 bgp_neighbor_graceful_restart_disable_set_cmd,
3153 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3154 NEIGHBOR_STR
3155 NEIGHBOR_ADDR_STR2
3156 GR_NEIGHBOR_DISABLE_CMD
3157 )
3158 {
3159 int idx_peer = 1;
3160 struct peer *peer;
3161 int ret = BGP_GR_FAILURE;
3162
3163 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3164
3165 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3166 zlog_debug(
3167 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3168
3169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3170 if (!peer)
3171 return CMD_WARNING_CONFIG_FAILED;
3172
3173 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3174
3175 if (peer->bgp->t_startup)
3176 bgp_peer_gr_flags_update(peer);
3177
3178 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3179 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3180
3181 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3182 zlog_debug(
3183 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3184 vty_out(vty,
3185 "Graceful restart configuration changed, reset this peer to take effect\n");
3186
3187 return bgp_vty_return(vty, ret);
3188 }
3189
3190 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3191 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3192 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3193 NO_STR
3194 NEIGHBOR_STR
3195 NEIGHBOR_ADDR_STR2
3196 NO_GR_NEIGHBOR_DISABLE_CMD
3197 )
3198 {
3199 int idx_peer = 2;
3200 int ret = BGP_GR_FAILURE;
3201 struct peer *peer;
3202
3203 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3204
3205 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3206 if (!peer)
3207 return CMD_WARNING_CONFIG_FAILED;
3208
3209 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3210 zlog_debug(
3211 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3212
3213 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3214
3215 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3216 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3217
3218 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3219 zlog_debug(
3220 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3221 vty_out(vty,
3222 "Graceful restart configuration changed, reset this peer to take effect\n");
3223
3224 return bgp_vty_return(vty, ret);
3225 }
3226
3227 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3228 bgp_graceful_restart_disable_eor_cmd,
3229 "bgp graceful-restart disable-eor",
3230 BGP_STR
3231 "Graceful restart configuration parameters\n"
3232 "Disable EOR Check\n")
3233 {
3234 VTY_DECLVAR_CONTEXT(bgp, bgp);
3235 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3236
3237 return CMD_SUCCESS;
3238 }
3239
3240 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3241 no_bgp_graceful_restart_disable_eor_cmd,
3242 "no bgp graceful-restart disable-eor",
3243 NO_STR
3244 BGP_STR
3245 "Graceful restart configuration parameters\n"
3246 "Disable EOR Check\n")
3247 {
3248 VTY_DECLVAR_CONTEXT(bgp, bgp);
3249 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3250
3251 return CMD_SUCCESS;
3252 }
3253
3254 DEFUN (bgp_graceful_restart_rib_stale_time,
3255 bgp_graceful_restart_rib_stale_time_cmd,
3256 "bgp graceful-restart rib-stale-time (1-3600)",
3257 BGP_STR
3258 "Graceful restart configuration parameters\n"
3259 "Specify the stale route removal timer in rib\n"
3260 "Delay value (seconds)\n")
3261 {
3262 VTY_DECLVAR_CONTEXT(bgp, bgp);
3263 int idx_number = 3;
3264 uint32_t stale_time;
3265
3266 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3267 bgp->rib_stale_time = stale_time;
3268 /* Send the stale timer update message to RIB */
3269 if (bgp_zebra_stale_timer_update(bgp))
3270 return CMD_WARNING;
3271
3272 return CMD_SUCCESS;
3273 }
3274
3275 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3276 no_bgp_graceful_restart_rib_stale_time_cmd,
3277 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3278 NO_STR
3279 BGP_STR
3280 "Graceful restart configuration parameters\n"
3281 "Specify the stale route removal timer in rib\n"
3282 "Delay value (seconds)\n")
3283 {
3284 VTY_DECLVAR_CONTEXT(bgp, bgp);
3285
3286 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3287 /* Send the stale timer update message to RIB */
3288 if (bgp_zebra_stale_timer_update(bgp))
3289 return CMD_WARNING;
3290
3291 return CMD_SUCCESS;
3292 }
3293
3294 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3295 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3296 BGP_STR
3297 "Enable Long-lived Graceful Restart\n"
3298 "Specifies maximum time to wait before purging long-lived stale routes\n"
3299 "Stale time value (seconds)\n")
3300 {
3301 VTY_DECLVAR_CONTEXT(bgp, bgp);
3302
3303 uint32_t llgr_stale_time;
3304
3305 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3306 bgp->llgr_stale_time = llgr_stale_time;
3307
3308 return CMD_SUCCESS;
3309 }
3310
3311 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3312 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3313 NO_STR BGP_STR
3314 "Enable Long-lived Graceful Restart\n"
3315 "Specifies maximum time to wait before purging long-lived stale routes\n"
3316 "Stale time value (seconds)\n")
3317 {
3318 VTY_DECLVAR_CONTEXT(bgp, bgp);
3319
3320 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3321
3322 return CMD_SUCCESS;
3323 }
3324
3325 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3326 struct bgp *bgp)
3327 {
3328 bgp_static_redo_import_check(bgp);
3329 bgp_redistribute_redo(bgp);
3330 bgp_clear_star_soft_out(vty, bgp->name);
3331 bgp_clear_star_soft_in(vty, bgp->name);
3332 }
3333
3334 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3335 {
3336 struct listnode *node, *nnode;
3337 struct bgp *bgp;
3338 bool vrf_cfg = false;
3339
3340 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3341 return CMD_SUCCESS;
3342
3343 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3344 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3345 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3346 vty_out(vty,
3347 "%% graceful-shutdown configuration found in vrf %s\n",
3348 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3349 VRF_DEFAULT_NAME : bgp->name);
3350 vrf_cfg = true;
3351 }
3352 }
3353
3354 if (vrf_cfg) {
3355 vty_out(vty,
3356 "%%Failed: global graceful-shutdown not permitted\n");
3357 return CMD_WARNING;
3358 }
3359
3360 /* Set flag globally */
3361 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3362
3363 /* Initiate processing for all BGP instances. */
3364 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3365 bgp_initiate_graceful_shut_unshut(vty, bgp);
3366
3367 return CMD_SUCCESS;
3368 }
3369
3370 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3371 {
3372 struct listnode *node, *nnode;
3373 struct bgp *bgp;
3374
3375 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3376 return CMD_SUCCESS;
3377
3378 /* Unset flag globally */
3379 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3380
3381 /* Initiate processing for all BGP instances. */
3382 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3383 bgp_initiate_graceful_shut_unshut(vty, bgp);
3384
3385 return CMD_SUCCESS;
3386 }
3387
3388 /* "bgp graceful-shutdown" configuration */
3389 DEFUN (bgp_graceful_shutdown,
3390 bgp_graceful_shutdown_cmd,
3391 "bgp graceful-shutdown",
3392 BGP_STR
3393 "Graceful shutdown parameters\n")
3394 {
3395 if (vty->node == CONFIG_NODE)
3396 return bgp_global_graceful_shutdown_config_vty(vty);
3397
3398 VTY_DECLVAR_CONTEXT(bgp, bgp);
3399
3400 /* if configured globally, per-instance config is not allowed */
3401 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3402 vty_out(vty,
3403 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3404 return CMD_WARNING_CONFIG_FAILED;
3405 }
3406
3407 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3408 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3409 bgp_initiate_graceful_shut_unshut(vty, bgp);
3410 }
3411
3412 return CMD_SUCCESS;
3413 }
3414
3415 DEFUN (no_bgp_graceful_shutdown,
3416 no_bgp_graceful_shutdown_cmd,
3417 "no bgp graceful-shutdown",
3418 NO_STR
3419 BGP_STR
3420 "Graceful shutdown parameters\n")
3421 {
3422 if (vty->node == CONFIG_NODE)
3423 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3424
3425 VTY_DECLVAR_CONTEXT(bgp, bgp);
3426
3427 /* If configured globally, cannot remove from one bgp instance */
3428 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3429 vty_out(vty,
3430 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3431 return CMD_WARNING_CONFIG_FAILED;
3432 }
3433
3434 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3435 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3436 bgp_initiate_graceful_shut_unshut(vty, bgp);
3437 }
3438
3439 return CMD_SUCCESS;
3440 }
3441
3442 /* "bgp fast-external-failover" configuration. */
3443 DEFUN (bgp_fast_external_failover,
3444 bgp_fast_external_failover_cmd,
3445 "bgp fast-external-failover",
3446 BGP_STR
3447 "Immediately reset session if a link to a directly connected external peer goes down\n")
3448 {
3449 VTY_DECLVAR_CONTEXT(bgp, bgp);
3450 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3451 return CMD_SUCCESS;
3452 }
3453
3454 DEFUN (no_bgp_fast_external_failover,
3455 no_bgp_fast_external_failover_cmd,
3456 "no bgp fast-external-failover",
3457 NO_STR
3458 BGP_STR
3459 "Immediately reset session if a link to a directly connected external peer goes down\n")
3460 {
3461 VTY_DECLVAR_CONTEXT(bgp, bgp);
3462 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3463 return CMD_SUCCESS;
3464 }
3465
3466 /* "bgp bestpath compare-routerid" configuration. */
3467 DEFUN (bgp_bestpath_compare_router_id,
3468 bgp_bestpath_compare_router_id_cmd,
3469 "bgp bestpath compare-routerid",
3470 BGP_STR
3471 "Change the default bestpath selection\n"
3472 "Compare router-id for identical EBGP paths\n")
3473 {
3474 VTY_DECLVAR_CONTEXT(bgp, bgp);
3475 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3476 bgp_recalculate_all_bestpaths(bgp);
3477
3478 return CMD_SUCCESS;
3479 }
3480
3481 DEFUN (no_bgp_bestpath_compare_router_id,
3482 no_bgp_bestpath_compare_router_id_cmd,
3483 "no bgp bestpath compare-routerid",
3484 NO_STR
3485 BGP_STR
3486 "Change the default bestpath selection\n"
3487 "Compare router-id for identical EBGP paths\n")
3488 {
3489 VTY_DECLVAR_CONTEXT(bgp, bgp);
3490 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3491 bgp_recalculate_all_bestpaths(bgp);
3492
3493 return CMD_SUCCESS;
3494 }
3495
3496 /* "bgp bestpath as-path ignore" configuration. */
3497 DEFUN (bgp_bestpath_aspath_ignore,
3498 bgp_bestpath_aspath_ignore_cmd,
3499 "bgp bestpath as-path ignore",
3500 BGP_STR
3501 "Change the default bestpath selection\n"
3502 "AS-path attribute\n"
3503 "Ignore as-path length in selecting a route\n")
3504 {
3505 VTY_DECLVAR_CONTEXT(bgp, bgp);
3506 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3507 bgp_recalculate_all_bestpaths(bgp);
3508
3509 return CMD_SUCCESS;
3510 }
3511
3512 DEFUN (no_bgp_bestpath_aspath_ignore,
3513 no_bgp_bestpath_aspath_ignore_cmd,
3514 "no bgp bestpath as-path ignore",
3515 NO_STR
3516 BGP_STR
3517 "Change the default bestpath selection\n"
3518 "AS-path attribute\n"
3519 "Ignore as-path length in selecting a route\n")
3520 {
3521 VTY_DECLVAR_CONTEXT(bgp, bgp);
3522 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3523 bgp_recalculate_all_bestpaths(bgp);
3524
3525 return CMD_SUCCESS;
3526 }
3527
3528 /* "bgp bestpath as-path confed" configuration. */
3529 DEFUN (bgp_bestpath_aspath_confed,
3530 bgp_bestpath_aspath_confed_cmd,
3531 "bgp bestpath as-path confed",
3532 BGP_STR
3533 "Change the default bestpath selection\n"
3534 "AS-path attribute\n"
3535 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3536 {
3537 VTY_DECLVAR_CONTEXT(bgp, bgp);
3538 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3539 bgp_recalculate_all_bestpaths(bgp);
3540
3541 return CMD_SUCCESS;
3542 }
3543
3544 DEFUN (no_bgp_bestpath_aspath_confed,
3545 no_bgp_bestpath_aspath_confed_cmd,
3546 "no bgp bestpath as-path confed",
3547 NO_STR
3548 BGP_STR
3549 "Change the default bestpath selection\n"
3550 "AS-path attribute\n"
3551 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3552 {
3553 VTY_DECLVAR_CONTEXT(bgp, bgp);
3554 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3555 bgp_recalculate_all_bestpaths(bgp);
3556
3557 return CMD_SUCCESS;
3558 }
3559
3560 /* "bgp bestpath as-path multipath-relax" configuration. */
3561 DEFUN (bgp_bestpath_aspath_multipath_relax,
3562 bgp_bestpath_aspath_multipath_relax_cmd,
3563 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3564 BGP_STR
3565 "Change the default bestpath selection\n"
3566 "AS-path attribute\n"
3567 "Allow load sharing across routes that have different AS paths (but same length)\n"
3568 "Generate an AS_SET\n"
3569 "Do not generate an AS_SET\n")
3570 {
3571 VTY_DECLVAR_CONTEXT(bgp, bgp);
3572 int idx = 0;
3573 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3574
3575 /* no-as-set is now the default behavior so we can silently
3576 * ignore it */
3577 if (argv_find(argv, argc, "as-set", &idx))
3578 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3579 else
3580 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3581
3582 bgp_recalculate_all_bestpaths(bgp);
3583
3584 return CMD_SUCCESS;
3585 }
3586
3587 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3588 no_bgp_bestpath_aspath_multipath_relax_cmd,
3589 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3590 NO_STR
3591 BGP_STR
3592 "Change the default bestpath selection\n"
3593 "AS-path attribute\n"
3594 "Allow load sharing across routes that have different AS paths (but same length)\n"
3595 "Generate an AS_SET\n"
3596 "Do not generate an AS_SET\n")
3597 {
3598 VTY_DECLVAR_CONTEXT(bgp, bgp);
3599 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3600 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3601 bgp_recalculate_all_bestpaths(bgp);
3602
3603 return CMD_SUCCESS;
3604 }
3605
3606 /* "bgp bestpath peer-type multipath-relax" configuration. */
3607 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3608 bgp_bestpath_peer_type_multipath_relax_cmd,
3609 "bgp bestpath peer-type multipath-relax",
3610 BGP_STR
3611 "Change the default bestpath selection\n"
3612 "Peer type\n"
3613 "Allow load sharing across routes learned from different peer types\n")
3614 {
3615 VTY_DECLVAR_CONTEXT(bgp, bgp);
3616 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3617 bgp_recalculate_all_bestpaths(bgp);
3618
3619 return CMD_SUCCESS;
3620 }
3621
3622 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3623 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3624 "no bgp bestpath peer-type multipath-relax",
3625 NO_STR BGP_STR
3626 "Change the default bestpath selection\n"
3627 "Peer type\n"
3628 "Allow load sharing across routes learned from different peer types\n")
3629 {
3630 VTY_DECLVAR_CONTEXT(bgp, bgp);
3631 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3632 bgp_recalculate_all_bestpaths(bgp);
3633
3634 return CMD_SUCCESS;
3635 }
3636
3637 /* "bgp log-neighbor-changes" configuration. */
3638 DEFUN (bgp_log_neighbor_changes,
3639 bgp_log_neighbor_changes_cmd,
3640 "bgp log-neighbor-changes",
3641 BGP_STR
3642 "Log neighbor up/down and reset reason\n")
3643 {
3644 VTY_DECLVAR_CONTEXT(bgp, bgp);
3645 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3646 return CMD_SUCCESS;
3647 }
3648
3649 DEFUN (no_bgp_log_neighbor_changes,
3650 no_bgp_log_neighbor_changes_cmd,
3651 "no bgp log-neighbor-changes",
3652 NO_STR
3653 BGP_STR
3654 "Log neighbor up/down and reset reason\n")
3655 {
3656 VTY_DECLVAR_CONTEXT(bgp, bgp);
3657 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3658 return CMD_SUCCESS;
3659 }
3660
3661 /* "bgp bestpath med" configuration. */
3662 DEFUN (bgp_bestpath_med,
3663 bgp_bestpath_med_cmd,
3664 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3665 BGP_STR
3666 "Change the default bestpath selection\n"
3667 "MED attribute\n"
3668 "Compare MED among confederation paths\n"
3669 "Treat missing MED as the least preferred one\n"
3670 "Treat missing MED as the least preferred one\n"
3671 "Compare MED among confederation paths\n")
3672 {
3673 VTY_DECLVAR_CONTEXT(bgp, bgp);
3674
3675 int idx = 0;
3676 if (argv_find(argv, argc, "confed", &idx))
3677 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3678 idx = 0;
3679 if (argv_find(argv, argc, "missing-as-worst", &idx))
3680 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3681
3682 bgp_recalculate_all_bestpaths(bgp);
3683
3684 return CMD_SUCCESS;
3685 }
3686
3687 DEFUN (no_bgp_bestpath_med,
3688 no_bgp_bestpath_med_cmd,
3689 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3690 NO_STR
3691 BGP_STR
3692 "Change the default bestpath selection\n"
3693 "MED attribute\n"
3694 "Compare MED among confederation paths\n"
3695 "Treat missing MED as the least preferred one\n"
3696 "Treat missing MED as the least preferred one\n"
3697 "Compare MED among confederation paths\n")
3698 {
3699 VTY_DECLVAR_CONTEXT(bgp, bgp);
3700
3701 int idx = 0;
3702 if (argv_find(argv, argc, "confed", &idx))
3703 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3704 idx = 0;
3705 if (argv_find(argv, argc, "missing-as-worst", &idx))
3706 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3707
3708 bgp_recalculate_all_bestpaths(bgp);
3709
3710 return CMD_SUCCESS;
3711 }
3712
3713 /* "bgp bestpath bandwidth" configuration. */
3714 DEFPY (bgp_bestpath_bw,
3715 bgp_bestpath_bw_cmd,
3716 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3717 BGP_STR
3718 "Change the default bestpath selection\n"
3719 "Link Bandwidth attribute\n"
3720 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3721 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3722 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3723 {
3724 VTY_DECLVAR_CONTEXT(bgp, bgp);
3725 afi_t afi;
3726 safi_t safi;
3727
3728 if (!bw_cfg) {
3729 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3730 return CMD_ERR_INCOMPLETE;
3731 }
3732 if (!strcmp(bw_cfg, "ignore"))
3733 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3734 else if (!strcmp(bw_cfg, "skip-missing"))
3735 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3736 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3737 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3738 else
3739 return CMD_ERR_NO_MATCH;
3740
3741 /* This config is used in route install, so redo that. */
3742 FOREACH_AFI_SAFI (afi, safi) {
3743 if (!bgp_fibupd_safi(safi))
3744 continue;
3745 bgp_zebra_announce_table(bgp, afi, safi);
3746 }
3747
3748 return CMD_SUCCESS;
3749 }
3750
3751 DEFPY (no_bgp_bestpath_bw,
3752 no_bgp_bestpath_bw_cmd,
3753 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3754 NO_STR
3755 BGP_STR
3756 "Change the default bestpath selection\n"
3757 "Link Bandwidth attribute\n"
3758 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3759 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3760 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3761 {
3762 VTY_DECLVAR_CONTEXT(bgp, bgp);
3763 afi_t afi;
3764 safi_t safi;
3765
3766 bgp->lb_handling = BGP_LINK_BW_ECMP;
3767
3768 /* This config is used in route install, so redo that. */
3769 FOREACH_AFI_SAFI (afi, safi) {
3770 if (!bgp_fibupd_safi(safi))
3771 continue;
3772 bgp_zebra_announce_table(bgp, afi, safi);
3773 }
3774 return CMD_SUCCESS;
3775 }
3776
3777 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3778 "[no] bgp default <ipv4-unicast|"
3779 "ipv4-multicast|"
3780 "ipv4-vpn|"
3781 "ipv4-labeled-unicast|"
3782 "ipv4-flowspec|"
3783 "ipv6-unicast|"
3784 "ipv6-multicast|"
3785 "ipv6-vpn|"
3786 "ipv6-labeled-unicast|"
3787 "ipv6-flowspec|"
3788 "l2vpn-evpn>$afi_safi",
3789 NO_STR
3790 BGP_STR
3791 "Configure BGP defaults\n"
3792 "Activate ipv4-unicast for a peer by default\n"
3793 "Activate ipv4-multicast for a peer by default\n"
3794 "Activate ipv4-vpn for a peer by default\n"
3795 "Activate ipv4-labeled-unicast for a peer by default\n"
3796 "Activate ipv4-flowspec for a peer by default\n"
3797 "Activate ipv6-unicast for a peer by default\n"
3798 "Activate ipv6-multicast for a peer by default\n"
3799 "Activate ipv6-vpn for a peer by default\n"
3800 "Activate ipv6-labeled-unicast for a peer by default\n"
3801 "Activate ipv6-flowspec for a peer by default\n"
3802 "Activate l2vpn-evpn for a peer by default\n")
3803 {
3804 VTY_DECLVAR_CONTEXT(bgp, bgp);
3805 char afi_safi_str[strlen(afi_safi) + 1];
3806 char *afi_safi_str_tok;
3807
3808 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3809 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3810 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3811 afi_t afi = bgp_vty_afi_from_str(afi_str);
3812 safi_t safi;
3813
3814 if (strmatch(safi_str, "labeled"))
3815 safi = bgp_vty_safi_from_str("labeled-unicast");
3816 else
3817 safi = bgp_vty_safi_from_str(safi_str);
3818
3819 if (no)
3820 bgp->default_af[afi][safi] = false;
3821 else {
3822 if ((safi == SAFI_LABELED_UNICAST
3823 && bgp->default_af[afi][SAFI_UNICAST])
3824 || (safi == SAFI_UNICAST
3825 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3826 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3827 else
3828 bgp->default_af[afi][safi] = true;
3829 }
3830
3831 return CMD_SUCCESS;
3832 }
3833
3834 /* Display hostname in certain command outputs */
3835 DEFUN (bgp_default_show_hostname,
3836 bgp_default_show_hostname_cmd,
3837 "bgp default show-hostname",
3838 BGP_STR
3839 "Configure BGP defaults\n"
3840 "Show hostname in certain command outputs\n")
3841 {
3842 VTY_DECLVAR_CONTEXT(bgp, bgp);
3843 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3844 return CMD_SUCCESS;
3845 }
3846
3847 DEFUN (no_bgp_default_show_hostname,
3848 no_bgp_default_show_hostname_cmd,
3849 "no bgp default show-hostname",
3850 NO_STR
3851 BGP_STR
3852 "Configure BGP defaults\n"
3853 "Show hostname in certain command outputs\n")
3854 {
3855 VTY_DECLVAR_CONTEXT(bgp, bgp);
3856 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3857 return CMD_SUCCESS;
3858 }
3859
3860 /* Display hostname in certain command outputs */
3861 DEFUN (bgp_default_show_nexthop_hostname,
3862 bgp_default_show_nexthop_hostname_cmd,
3863 "bgp default show-nexthop-hostname",
3864 BGP_STR
3865 "Configure BGP defaults\n"
3866 "Show hostname for nexthop in certain command outputs\n")
3867 {
3868 VTY_DECLVAR_CONTEXT(bgp, bgp);
3869 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3870 return CMD_SUCCESS;
3871 }
3872
3873 DEFUN (no_bgp_default_show_nexthop_hostname,
3874 no_bgp_default_show_nexthop_hostname_cmd,
3875 "no bgp default show-nexthop-hostname",
3876 NO_STR
3877 BGP_STR
3878 "Configure BGP defaults\n"
3879 "Show hostname for nexthop in certain command outputs\n")
3880 {
3881 VTY_DECLVAR_CONTEXT(bgp, bgp);
3882 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3883 return CMD_SUCCESS;
3884 }
3885
3886 /* "bgp network import-check" configuration. */
3887 DEFUN (bgp_network_import_check,
3888 bgp_network_import_check_cmd,
3889 "bgp network import-check",
3890 BGP_STR
3891 "BGP network command\n"
3892 "Check BGP network route exists in IGP\n")
3893 {
3894 VTY_DECLVAR_CONTEXT(bgp, bgp);
3895 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3896 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3897 bgp_static_redo_import_check(bgp);
3898 }
3899
3900 return CMD_SUCCESS;
3901 }
3902
3903 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3904 "bgp network import-check exact",
3905 BGP_STR
3906 "BGP network command\n"
3907 "Check BGP network route exists in IGP\n"
3908 "Match route precisely\n")
3909
3910 DEFUN (no_bgp_network_import_check,
3911 no_bgp_network_import_check_cmd,
3912 "no bgp network import-check",
3913 NO_STR
3914 BGP_STR
3915 "BGP network command\n"
3916 "Check BGP network route exists in IGP\n")
3917 {
3918 VTY_DECLVAR_CONTEXT(bgp, bgp);
3919 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3920 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3921 bgp_static_redo_import_check(bgp);
3922 }
3923
3924 return CMD_SUCCESS;
3925 }
3926
3927 DEFUN (bgp_default_local_preference,
3928 bgp_default_local_preference_cmd,
3929 "bgp default local-preference (0-4294967295)",
3930 BGP_STR
3931 "Configure BGP defaults\n"
3932 "local preference (higher=more preferred)\n"
3933 "Configure default local preference value\n")
3934 {
3935 VTY_DECLVAR_CONTEXT(bgp, bgp);
3936 int idx_number = 3;
3937 uint32_t local_pref;
3938
3939 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3940
3941 bgp_default_local_preference_set(bgp, local_pref);
3942 bgp_clear_star_soft_in(vty, bgp->name);
3943
3944 return CMD_SUCCESS;
3945 }
3946
3947 DEFUN (no_bgp_default_local_preference,
3948 no_bgp_default_local_preference_cmd,
3949 "no bgp default local-preference [(0-4294967295)]",
3950 NO_STR
3951 BGP_STR
3952 "Configure BGP defaults\n"
3953 "local preference (higher=more preferred)\n"
3954 "Configure default local preference value\n")
3955 {
3956 VTY_DECLVAR_CONTEXT(bgp, bgp);
3957 bgp_default_local_preference_unset(bgp);
3958 bgp_clear_star_soft_in(vty, bgp->name);
3959
3960 return CMD_SUCCESS;
3961 }
3962
3963
3964 DEFUN (bgp_default_subgroup_pkt_queue_max,
3965 bgp_default_subgroup_pkt_queue_max_cmd,
3966 "bgp default subgroup-pkt-queue-max (20-100)",
3967 BGP_STR
3968 "Configure BGP defaults\n"
3969 "subgroup-pkt-queue-max\n"
3970 "Configure subgroup packet queue max\n")
3971 {
3972 VTY_DECLVAR_CONTEXT(bgp, bgp);
3973 int idx_number = 3;
3974 uint32_t max_size;
3975
3976 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3977
3978 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3979
3980 return CMD_SUCCESS;
3981 }
3982
3983 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3984 no_bgp_default_subgroup_pkt_queue_max_cmd,
3985 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3986 NO_STR
3987 BGP_STR
3988 "Configure BGP defaults\n"
3989 "subgroup-pkt-queue-max\n"
3990 "Configure subgroup packet queue max\n")
3991 {
3992 VTY_DECLVAR_CONTEXT(bgp, bgp);
3993 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3994 return CMD_SUCCESS;
3995 }
3996
3997
3998 DEFUN (bgp_rr_allow_outbound_policy,
3999 bgp_rr_allow_outbound_policy_cmd,
4000 "bgp route-reflector allow-outbound-policy",
4001 BGP_STR
4002 "Allow modifications made by out route-map\n"
4003 "on ibgp neighbors\n")
4004 {
4005 VTY_DECLVAR_CONTEXT(bgp, bgp);
4006
4007 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4008 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4009 update_group_announce_rrclients(bgp);
4010 bgp_clear_star_soft_out(vty, bgp->name);
4011 }
4012
4013 return CMD_SUCCESS;
4014 }
4015
4016 DEFUN (no_bgp_rr_allow_outbound_policy,
4017 no_bgp_rr_allow_outbound_policy_cmd,
4018 "no bgp route-reflector allow-outbound-policy",
4019 NO_STR
4020 BGP_STR
4021 "Allow modifications made by out route-map\n"
4022 "on ibgp neighbors\n")
4023 {
4024 VTY_DECLVAR_CONTEXT(bgp, bgp);
4025
4026 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4027 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4028 update_group_announce_rrclients(bgp);
4029 bgp_clear_star_soft_out(vty, bgp->name);
4030 }
4031
4032 return CMD_SUCCESS;
4033 }
4034
4035 DEFUN (bgp_listen_limit,
4036 bgp_listen_limit_cmd,
4037 "bgp listen limit (1-65535)",
4038 BGP_STR
4039 "BGP Dynamic Neighbors listen commands\n"
4040 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4041 "Configure Dynamic Neighbors listen limit value\n")
4042 {
4043 VTY_DECLVAR_CONTEXT(bgp, bgp);
4044 int idx_number = 3;
4045 int listen_limit;
4046
4047 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4048
4049 bgp_listen_limit_set(bgp, listen_limit);
4050
4051 return CMD_SUCCESS;
4052 }
4053
4054 DEFUN (no_bgp_listen_limit,
4055 no_bgp_listen_limit_cmd,
4056 "no bgp listen limit [(1-65535)]",
4057 NO_STR
4058 BGP_STR
4059 "BGP Dynamic Neighbors listen commands\n"
4060 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4061 "Configure Dynamic Neighbors listen limit value\n")
4062 {
4063 VTY_DECLVAR_CONTEXT(bgp, bgp);
4064 bgp_listen_limit_unset(bgp);
4065 return CMD_SUCCESS;
4066 }
4067
4068
4069 /*
4070 * Check if this listen range is already configured. Check for exact
4071 * match or overlap based on input.
4072 */
4073 static struct peer_group *listen_range_exists(struct bgp *bgp,
4074 struct prefix *range, int exact)
4075 {
4076 struct listnode *node, *nnode;
4077 struct listnode *node1, *nnode1;
4078 struct peer_group *group;
4079 struct prefix *lr;
4080 afi_t afi;
4081 int match;
4082
4083 afi = family2afi(range->family);
4084 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4085 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4086 lr)) {
4087 if (exact)
4088 match = prefix_same(range, lr);
4089 else
4090 match = (prefix_match(range, lr)
4091 || prefix_match(lr, range));
4092 if (match)
4093 return group;
4094 }
4095 }
4096
4097 return NULL;
4098 }
4099
4100 DEFUN (bgp_listen_range,
4101 bgp_listen_range_cmd,
4102 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4103 BGP_STR
4104 "Configure BGP dynamic neighbors listen range\n"
4105 "Configure BGP dynamic neighbors listen range\n"
4106 NEIGHBOR_ADDR_STR
4107 "Member of the peer-group\n"
4108 "Peer-group name\n")
4109 {
4110 VTY_DECLVAR_CONTEXT(bgp, bgp);
4111 struct prefix range;
4112 struct peer_group *group, *existing_group;
4113 afi_t afi;
4114 int ret;
4115 int idx = 0;
4116
4117 argv_find(argv, argc, "A.B.C.D/M", &idx);
4118 argv_find(argv, argc, "X:X::X:X/M", &idx);
4119 char *prefix = argv[idx]->arg;
4120 argv_find(argv, argc, "PGNAME", &idx);
4121 char *peergroup = argv[idx]->arg;
4122
4123 /* Convert IP prefix string to struct prefix. */
4124 ret = str2prefix(prefix, &range);
4125 if (!ret) {
4126 vty_out(vty, "%% Malformed listen range\n");
4127 return CMD_WARNING_CONFIG_FAILED;
4128 }
4129
4130 afi = family2afi(range.family);
4131
4132 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4133 vty_out(vty,
4134 "%% Malformed listen range (link-local address)\n");
4135 return CMD_WARNING_CONFIG_FAILED;
4136 }
4137
4138 apply_mask(&range);
4139
4140 /* Check if same listen range is already configured. */
4141 existing_group = listen_range_exists(bgp, &range, 1);
4142 if (existing_group) {
4143 if (strcmp(existing_group->name, peergroup) == 0)
4144 return CMD_SUCCESS;
4145 else {
4146 vty_out(vty,
4147 "%% Same listen range is attached to peer-group %s\n",
4148 existing_group->name);
4149 return CMD_WARNING_CONFIG_FAILED;
4150 }
4151 }
4152
4153 /* Check if an overlapping listen range exists. */
4154 if (listen_range_exists(bgp, &range, 0)) {
4155 vty_out(vty,
4156 "%% Listen range overlaps with existing listen range\n");
4157 return CMD_WARNING_CONFIG_FAILED;
4158 }
4159
4160 group = peer_group_lookup(bgp, peergroup);
4161 if (!group) {
4162 vty_out(vty, "%% Configure the peer-group first\n");
4163 return CMD_WARNING_CONFIG_FAILED;
4164 }
4165
4166 ret = peer_group_listen_range_add(group, &range);
4167 return bgp_vty_return(vty, ret);
4168 }
4169
4170 DEFUN (no_bgp_listen_range,
4171 no_bgp_listen_range_cmd,
4172 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4173 NO_STR
4174 BGP_STR
4175 "Unconfigure BGP dynamic neighbors listen range\n"
4176 "Unconfigure BGP dynamic neighbors listen range\n"
4177 NEIGHBOR_ADDR_STR
4178 "Member of the peer-group\n"
4179 "Peer-group name\n")
4180 {
4181 VTY_DECLVAR_CONTEXT(bgp, bgp);
4182 struct prefix range;
4183 struct peer_group *group;
4184 afi_t afi;
4185 int ret;
4186 int idx = 0;
4187
4188 argv_find(argv, argc, "A.B.C.D/M", &idx);
4189 argv_find(argv, argc, "X:X::X:X/M", &idx);
4190 char *prefix = argv[idx]->arg;
4191 argv_find(argv, argc, "PGNAME", &idx);
4192 char *peergroup = argv[idx]->arg;
4193
4194 /* Convert IP prefix string to struct prefix. */
4195 ret = str2prefix(prefix, &range);
4196 if (!ret) {
4197 vty_out(vty, "%% Malformed listen range\n");
4198 return CMD_WARNING_CONFIG_FAILED;
4199 }
4200
4201 afi = family2afi(range.family);
4202
4203 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4204 vty_out(vty,
4205 "%% Malformed listen range (link-local address)\n");
4206 return CMD_WARNING_CONFIG_FAILED;
4207 }
4208
4209 apply_mask(&range);
4210
4211 group = peer_group_lookup(bgp, peergroup);
4212 if (!group) {
4213 vty_out(vty, "%% Peer-group does not exist\n");
4214 return CMD_WARNING_CONFIG_FAILED;
4215 }
4216
4217 ret = peer_group_listen_range_del(group, &range);
4218 return bgp_vty_return(vty, ret);
4219 }
4220
4221 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4222 {
4223 struct peer_group *group;
4224 struct listnode *node, *nnode, *rnode, *nrnode;
4225 struct prefix *range;
4226 afi_t afi;
4227
4228 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4229 vty_out(vty, " bgp listen limit %d\n",
4230 bgp->dynamic_neighbors_limit);
4231
4232 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4233 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4234 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4235 nrnode, range)) {
4236 vty_out(vty,
4237 " bgp listen range %pFX peer-group %s\n",
4238 range, group->name);
4239 }
4240 }
4241 }
4242 }
4243
4244
4245 DEFUN (bgp_disable_connected_route_check,
4246 bgp_disable_connected_route_check_cmd,
4247 "bgp disable-ebgp-connected-route-check",
4248 BGP_STR
4249 "Disable checking if nexthop is connected on ebgp sessions\n")
4250 {
4251 VTY_DECLVAR_CONTEXT(bgp, bgp);
4252 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4253 bgp_clear_star_soft_in(vty, bgp->name);
4254
4255 return CMD_SUCCESS;
4256 }
4257
4258 DEFUN (no_bgp_disable_connected_route_check,
4259 no_bgp_disable_connected_route_check_cmd,
4260 "no bgp disable-ebgp-connected-route-check",
4261 NO_STR
4262 BGP_STR
4263 "Disable checking if nexthop is connected on ebgp sessions\n")
4264 {
4265 VTY_DECLVAR_CONTEXT(bgp, bgp);
4266 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4267 bgp_clear_star_soft_in(vty, bgp->name);
4268
4269 return CMD_SUCCESS;
4270 }
4271
4272
4273 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4274 const char *as_str)
4275 {
4276 VTY_DECLVAR_CONTEXT(bgp, bgp);
4277 int ret;
4278 as_t as;
4279 int as_type = AS_SPECIFIED;
4280 union sockunion su;
4281
4282 if (as_str[0] == 'i') {
4283 as = 0;
4284 as_type = AS_INTERNAL;
4285 } else if (as_str[0] == 'e') {
4286 as = 0;
4287 as_type = AS_EXTERNAL;
4288 } else {
4289 /* Get AS number. */
4290 as = strtoul(as_str, NULL, 10);
4291 }
4292
4293 /* If peer is peer group or interface peer, call proper function. */
4294 ret = str2sockunion(peer_str, &su);
4295 if (ret < 0) {
4296 struct peer *peer;
4297
4298 /* Check if existing interface peer */
4299 peer = peer_lookup_by_conf_if(bgp, peer_str);
4300
4301 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4302
4303 /* if not interface peer, check peer-group settings */
4304 if (ret < 0 && !peer) {
4305 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4306 if (ret < 0) {
4307 vty_out(vty,
4308 "%% Create the peer-group or interface first\n");
4309 return CMD_WARNING_CONFIG_FAILED;
4310 }
4311 return CMD_SUCCESS;
4312 }
4313 } else {
4314 if (peer_address_self_check(bgp, &su)) {
4315 vty_out(vty,
4316 "%% Can not configure the local system as neighbor\n");
4317 return CMD_WARNING_CONFIG_FAILED;
4318 }
4319 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4320 }
4321
4322 return bgp_vty_return(vty, ret);
4323 }
4324
4325 DEFUN (bgp_default_shutdown,
4326 bgp_default_shutdown_cmd,
4327 "[no] bgp default shutdown",
4328 NO_STR
4329 BGP_STR
4330 "Configure BGP defaults\n"
4331 "Apply administrative shutdown to newly configured peers\n")
4332 {
4333 VTY_DECLVAR_CONTEXT(bgp, bgp);
4334 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4335 return CMD_SUCCESS;
4336 }
4337
4338 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4339 BGP_STR
4340 "Administrative shutdown of the BGP instance\n"
4341 "Add a shutdown message (RFC 8203)\n"
4342 "Shutdown message\n")
4343 {
4344 char *msgstr = NULL;
4345
4346 VTY_DECLVAR_CONTEXT(bgp, bgp);
4347
4348 if (argc > 3)
4349 msgstr = argv_concat(argv, argc, 3);
4350
4351 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4352 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4353 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4354 return CMD_WARNING_CONFIG_FAILED;
4355 }
4356
4357 bgp_shutdown_enable(bgp, msgstr);
4358 XFREE(MTYPE_TMP, msgstr);
4359
4360 return CMD_SUCCESS;
4361 }
4362
4363 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4364 BGP_STR "Administrative shutdown of the BGP instance\n")
4365 {
4366 VTY_DECLVAR_CONTEXT(bgp, bgp);
4367
4368 bgp_shutdown_enable(bgp, NULL);
4369
4370 return CMD_SUCCESS;
4371 }
4372
4373 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4374 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4375 {
4376 VTY_DECLVAR_CONTEXT(bgp, bgp);
4377
4378 bgp_shutdown_disable(bgp);
4379
4380 return CMD_SUCCESS;
4381 }
4382
4383 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4384 "no bgp shutdown message MSG...", NO_STR BGP_STR
4385 "Administrative shutdown of the BGP instance\n"
4386 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4387
4388 DEFUN (neighbor_remote_as,
4389 neighbor_remote_as_cmd,
4390 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4391 NEIGHBOR_STR
4392 NEIGHBOR_ADDR_STR2
4393 "Specify a BGP neighbor\n"
4394 AS_STR
4395 "Internal BGP peer\n"
4396 "External BGP peer\n")
4397 {
4398 int idx_peer = 1;
4399 int idx_remote_as = 3;
4400 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4401 argv[idx_remote_as]->arg);
4402 }
4403 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4404 * sessions do not wait for hold timer expiry to bring down the sessions
4405 * when nexthop becomes unreachable
4406 */
4407 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4408 BGP_STR "Fast convergence for bgp sessions\n")
4409 {
4410 VTY_DECLVAR_CONTEXT(bgp, bgp);
4411 bgp->fast_convergence = true;
4412
4413 return CMD_SUCCESS;
4414 }
4415
4416 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4417 "no bgp fast-convergence",
4418 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4419 {
4420 VTY_DECLVAR_CONTEXT(bgp, bgp);
4421 bgp->fast_convergence = false;
4422
4423 return CMD_SUCCESS;
4424 }
4425
4426 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4427 int v6only,
4428 const char *peer_group_name,
4429 const char *as_str)
4430 {
4431 VTY_DECLVAR_CONTEXT(bgp, bgp);
4432 as_t as = 0;
4433 int as_type = AS_UNSPECIFIED;
4434 struct peer *peer;
4435 struct peer_group *group;
4436 int ret = 0;
4437
4438 group = peer_group_lookup(bgp, conf_if);
4439
4440 if (group) {
4441 vty_out(vty, "%% Name conflict with peer-group \n");
4442 return CMD_WARNING_CONFIG_FAILED;
4443 }
4444
4445 if (as_str) {
4446 if (as_str[0] == 'i') {
4447 as_type = AS_INTERNAL;
4448 } else if (as_str[0] == 'e') {
4449 as_type = AS_EXTERNAL;
4450 } else {
4451 /* Get AS number. */
4452 as = strtoul(as_str, NULL, 10);
4453 as_type = AS_SPECIFIED;
4454 }
4455 }
4456
4457 peer = peer_lookup_by_conf_if(bgp, conf_if);
4458 if (peer) {
4459 if (as_str)
4460 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4461 } else {
4462 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4463 NULL);
4464
4465 if (!peer) {
4466 vty_out(vty, "%% BGP failed to create peer\n");
4467 return CMD_WARNING_CONFIG_FAILED;
4468 }
4469
4470 if (v6only)
4471 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4472
4473 /* Request zebra to initiate IPv6 RAs on this interface. We do
4474 * this
4475 * any unnumbered peer in order to not worry about run-time
4476 * transitions
4477 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4478 * address
4479 * gets deleted later etc.)
4480 */
4481 if (peer->ifp)
4482 bgp_zebra_initiate_radv(bgp, peer);
4483 }
4484
4485 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4486 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4487 if (v6only)
4488 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4489 else
4490 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4491
4492 /* v6only flag changed. Reset bgp seesion */
4493 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4494 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4495 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4496 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4497 } else
4498 bgp_session_reset(peer);
4499 }
4500
4501 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4502 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4503 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4504 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4505 }
4506
4507 if (peer_group_name) {
4508 group = peer_group_lookup(bgp, peer_group_name);
4509 if (!group) {
4510 vty_out(vty, "%% Configure the peer-group first\n");
4511 return CMD_WARNING_CONFIG_FAILED;
4512 }
4513
4514 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4515 }
4516
4517 return bgp_vty_return(vty, ret);
4518 }
4519
4520 DEFUN (neighbor_interface_config,
4521 neighbor_interface_config_cmd,
4522 "neighbor WORD interface [peer-group PGNAME]",
4523 NEIGHBOR_STR
4524 "Interface name or neighbor tag\n"
4525 "Enable BGP on interface\n"
4526 "Member of the peer-group\n"
4527 "Peer-group name\n")
4528 {
4529 int idx_word = 1;
4530 int idx_peer_group_word = 4;
4531
4532 if (argc > idx_peer_group_word)
4533 return peer_conf_interface_get(
4534 vty, argv[idx_word]->arg, 0,
4535 argv[idx_peer_group_word]->arg, NULL);
4536 else
4537 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4538 NULL, NULL);
4539 }
4540
4541 DEFUN (neighbor_interface_config_v6only,
4542 neighbor_interface_config_v6only_cmd,
4543 "neighbor WORD interface v6only [peer-group PGNAME]",
4544 NEIGHBOR_STR
4545 "Interface name or neighbor tag\n"
4546 "Enable BGP on interface\n"
4547 "Enable BGP with v6 link-local only\n"
4548 "Member of the peer-group\n"
4549 "Peer-group name\n")
4550 {
4551 int idx_word = 1;
4552 int idx_peer_group_word = 5;
4553
4554 if (argc > idx_peer_group_word)
4555 return peer_conf_interface_get(
4556 vty, argv[idx_word]->arg, 1,
4557 argv[idx_peer_group_word]->arg, NULL);
4558
4559 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4560 }
4561
4562
4563 DEFUN (neighbor_interface_config_remote_as,
4564 neighbor_interface_config_remote_as_cmd,
4565 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4566 NEIGHBOR_STR
4567 "Interface name or neighbor tag\n"
4568 "Enable BGP on interface\n"
4569 "Specify a BGP neighbor\n"
4570 AS_STR
4571 "Internal BGP peer\n"
4572 "External BGP peer\n")
4573 {
4574 int idx_word = 1;
4575 int idx_remote_as = 4;
4576 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4577 argv[idx_remote_as]->arg);
4578 }
4579
4580 DEFUN (neighbor_interface_v6only_config_remote_as,
4581 neighbor_interface_v6only_config_remote_as_cmd,
4582 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4583 NEIGHBOR_STR
4584 "Interface name or neighbor tag\n"
4585 "Enable BGP with v6 link-local only\n"
4586 "Enable BGP on interface\n"
4587 "Specify a BGP neighbor\n"
4588 AS_STR
4589 "Internal BGP peer\n"
4590 "External BGP peer\n")
4591 {
4592 int idx_word = 1;
4593 int idx_remote_as = 5;
4594 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4595 argv[idx_remote_as]->arg);
4596 }
4597
4598 DEFUN (neighbor_peer_group,
4599 neighbor_peer_group_cmd,
4600 "neighbor WORD peer-group",
4601 NEIGHBOR_STR
4602 "Interface name or neighbor tag\n"
4603 "Configure peer-group\n")
4604 {
4605 VTY_DECLVAR_CONTEXT(bgp, bgp);
4606 int idx_word = 1;
4607 struct peer *peer;
4608 struct peer_group *group;
4609
4610 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4611 if (peer) {
4612 vty_out(vty, "%% Name conflict with interface: \n");
4613 return CMD_WARNING_CONFIG_FAILED;
4614 }
4615
4616 group = peer_group_get(bgp, argv[idx_word]->arg);
4617 if (!group) {
4618 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4619 return CMD_WARNING_CONFIG_FAILED;
4620 }
4621
4622 return CMD_SUCCESS;
4623 }
4624
4625 DEFUN (no_neighbor,
4626 no_neighbor_cmd,
4627 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4628 NO_STR
4629 NEIGHBOR_STR
4630 NEIGHBOR_ADDR_STR2
4631 "Specify a BGP neighbor\n"
4632 AS_STR
4633 "Internal BGP peer\n"
4634 "External BGP peer\n")
4635 {
4636 VTY_DECLVAR_CONTEXT(bgp, bgp);
4637 int idx_peer = 2;
4638 int ret;
4639 union sockunion su;
4640 struct peer_group *group;
4641 struct peer *peer;
4642 struct peer *other;
4643
4644 ret = str2sockunion(argv[idx_peer]->arg, &su);
4645 if (ret < 0) {
4646 /* look up for neighbor by interface name config. */
4647 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4648 if (peer) {
4649 /* Request zebra to terminate IPv6 RAs on this
4650 * interface. */
4651 if (peer->ifp)
4652 bgp_zebra_terminate_radv(peer->bgp, peer);
4653 peer_notify_unconfig(peer);
4654 peer_delete(peer);
4655 return CMD_SUCCESS;
4656 }
4657
4658 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4659 if (group) {
4660 peer_group_notify_unconfig(group);
4661 peer_group_delete(group);
4662 } else {
4663 vty_out(vty, "%% Create the peer-group first\n");
4664 return CMD_WARNING_CONFIG_FAILED;
4665 }
4666 } else {
4667 peer = peer_lookup(bgp, &su);
4668 if (peer) {
4669 if (peer_dynamic_neighbor(peer)) {
4670 vty_out(vty,
4671 "%% Operation not allowed on a dynamic neighbor\n");
4672 return CMD_WARNING_CONFIG_FAILED;
4673 }
4674
4675 other = peer->doppelganger;
4676
4677 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4678 bgp_zebra_terminate_radv(peer->bgp, peer);
4679
4680 peer_notify_unconfig(peer);
4681 peer_delete(peer);
4682 if (other && other->status != Deleted) {
4683 peer_notify_unconfig(other);
4684 peer_delete(other);
4685 }
4686 }
4687 }
4688
4689 return CMD_SUCCESS;
4690 }
4691
4692 DEFUN (no_neighbor_interface_config,
4693 no_neighbor_interface_config_cmd,
4694 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4695 NO_STR
4696 NEIGHBOR_STR
4697 "Interface name\n"
4698 "Configure BGP on interface\n"
4699 "Enable BGP with v6 link-local only\n"
4700 "Member of the peer-group\n"
4701 "Peer-group name\n"
4702 "Specify a BGP neighbor\n"
4703 AS_STR
4704 "Internal BGP peer\n"
4705 "External BGP peer\n")
4706 {
4707 VTY_DECLVAR_CONTEXT(bgp, bgp);
4708 int idx_word = 2;
4709 struct peer *peer;
4710
4711 /* look up for neighbor by interface name config. */
4712 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4713 if (peer) {
4714 /* Request zebra to terminate IPv6 RAs on this interface. */
4715 if (peer->ifp)
4716 bgp_zebra_terminate_radv(peer->bgp, peer);
4717 peer_notify_unconfig(peer);
4718 peer_delete(peer);
4719 } else {
4720 vty_out(vty, "%% Create the bgp interface first\n");
4721 return CMD_WARNING_CONFIG_FAILED;
4722 }
4723 return CMD_SUCCESS;
4724 }
4725
4726 DEFUN (no_neighbor_peer_group,
4727 no_neighbor_peer_group_cmd,
4728 "no neighbor WORD peer-group",
4729 NO_STR
4730 NEIGHBOR_STR
4731 "Neighbor tag\n"
4732 "Configure peer-group\n")
4733 {
4734 VTY_DECLVAR_CONTEXT(bgp, bgp);
4735 int idx_word = 2;
4736 struct peer_group *group;
4737
4738 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4739 if (group) {
4740 peer_group_notify_unconfig(group);
4741 peer_group_delete(group);
4742 } else {
4743 vty_out(vty, "%% Create the peer-group first\n");
4744 return CMD_WARNING_CONFIG_FAILED;
4745 }
4746 return CMD_SUCCESS;
4747 }
4748
4749 DEFUN (no_neighbor_interface_peer_group_remote_as,
4750 no_neighbor_interface_peer_group_remote_as_cmd,
4751 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4752 NO_STR
4753 NEIGHBOR_STR
4754 "Interface name or neighbor tag\n"
4755 "Specify a BGP neighbor\n"
4756 AS_STR
4757 "Internal BGP peer\n"
4758 "External BGP peer\n")
4759 {
4760 VTY_DECLVAR_CONTEXT(bgp, bgp);
4761 int idx_word = 2;
4762 struct peer_group *group;
4763 struct peer *peer;
4764
4765 /* look up for neighbor by interface name config. */
4766 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4767 if (peer) {
4768 peer_as_change(peer, 0, AS_UNSPECIFIED);
4769 return CMD_SUCCESS;
4770 }
4771
4772 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4773 if (group)
4774 peer_group_remote_as_delete(group);
4775 else {
4776 vty_out(vty, "%% Create the peer-group or interface first\n");
4777 return CMD_WARNING_CONFIG_FAILED;
4778 }
4779 return CMD_SUCCESS;
4780 }
4781
4782 DEFUN (neighbor_local_as,
4783 neighbor_local_as_cmd,
4784 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4785 NEIGHBOR_STR
4786 NEIGHBOR_ADDR_STR2
4787 "Specify a local-as number\n"
4788 "AS number used as local AS\n")
4789 {
4790 int idx_peer = 1;
4791 int idx_number = 3;
4792 struct peer *peer;
4793 int ret;
4794 as_t as;
4795
4796 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4797 if (!peer)
4798 return CMD_WARNING_CONFIG_FAILED;
4799
4800 as = strtoul(argv[idx_number]->arg, NULL, 10);
4801 ret = peer_local_as_set(peer, as, 0, 0);
4802 return bgp_vty_return(vty, ret);
4803 }
4804
4805 DEFUN (neighbor_local_as_no_prepend,
4806 neighbor_local_as_no_prepend_cmd,
4807 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4808 NEIGHBOR_STR
4809 NEIGHBOR_ADDR_STR2
4810 "Specify a local-as number\n"
4811 "AS number used as local AS\n"
4812 "Do not prepend local-as to updates from ebgp peers\n")
4813 {
4814 int idx_peer = 1;
4815 int idx_number = 3;
4816 struct peer *peer;
4817 int ret;
4818 as_t as;
4819
4820 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4821 if (!peer)
4822 return CMD_WARNING_CONFIG_FAILED;
4823
4824 as = strtoul(argv[idx_number]->arg, NULL, 10);
4825 ret = peer_local_as_set(peer, as, 1, 0);
4826 return bgp_vty_return(vty, ret);
4827 }
4828
4829 DEFUN (neighbor_local_as_no_prepend_replace_as,
4830 neighbor_local_as_no_prepend_replace_as_cmd,
4831 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Specify a local-as number\n"
4835 "AS number used as local AS\n"
4836 "Do not prepend local-as to updates from ebgp peers\n"
4837 "Do not prepend local-as to updates from ibgp peers\n")
4838 {
4839 int idx_peer = 1;
4840 int idx_number = 3;
4841 struct peer *peer;
4842 int ret;
4843 as_t as;
4844
4845 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4846 if (!peer)
4847 return CMD_WARNING_CONFIG_FAILED;
4848
4849 as = strtoul(argv[idx_number]->arg, NULL, 10);
4850 ret = peer_local_as_set(peer, as, 1, 1);
4851 return bgp_vty_return(vty, ret);
4852 }
4853
4854 DEFUN (no_neighbor_local_as,
4855 no_neighbor_local_as_cmd,
4856 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4857 NO_STR
4858 NEIGHBOR_STR
4859 NEIGHBOR_ADDR_STR2
4860 "Specify a local-as number\n"
4861 "AS number used as local AS\n"
4862 "Do not prepend local-as to updates from ebgp peers\n"
4863 "Do not prepend local-as to updates from ibgp peers\n")
4864 {
4865 int idx_peer = 2;
4866 struct peer *peer;
4867 int ret;
4868
4869 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4870 if (!peer)
4871 return CMD_WARNING_CONFIG_FAILED;
4872
4873 ret = peer_local_as_unset(peer);
4874 return bgp_vty_return(vty, ret);
4875 }
4876
4877
4878 DEFUN (neighbor_solo,
4879 neighbor_solo_cmd,
4880 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4881 NEIGHBOR_STR
4882 NEIGHBOR_ADDR_STR2
4883 "Solo peer - part of its own update group\n")
4884 {
4885 int idx_peer = 1;
4886 struct peer *peer;
4887 int ret;
4888
4889 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4890 if (!peer)
4891 return CMD_WARNING_CONFIG_FAILED;
4892
4893 ret = update_group_adjust_soloness(peer, 1);
4894 return bgp_vty_return(vty, ret);
4895 }
4896
4897 DEFUN (no_neighbor_solo,
4898 no_neighbor_solo_cmd,
4899 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4900 NO_STR
4901 NEIGHBOR_STR
4902 NEIGHBOR_ADDR_STR2
4903 "Solo peer - part of its own update group\n")
4904 {
4905 int idx_peer = 2;
4906 struct peer *peer;
4907 int ret;
4908
4909 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4910 if (!peer)
4911 return CMD_WARNING_CONFIG_FAILED;
4912
4913 ret = update_group_adjust_soloness(peer, 0);
4914 return bgp_vty_return(vty, ret);
4915 }
4916
4917 DEFUN (neighbor_password,
4918 neighbor_password_cmd,
4919 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Set a password\n"
4923 "The password\n")
4924 {
4925 int idx_peer = 1;
4926 int idx_line = 3;
4927 struct peer *peer;
4928 int ret;
4929
4930 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4931 if (!peer)
4932 return CMD_WARNING_CONFIG_FAILED;
4933
4934 ret = peer_password_set(peer, argv[idx_line]->arg);
4935 return bgp_vty_return(vty, ret);
4936 }
4937
4938 DEFUN (no_neighbor_password,
4939 no_neighbor_password_cmd,
4940 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4941 NO_STR
4942 NEIGHBOR_STR
4943 NEIGHBOR_ADDR_STR2
4944 "Set a password\n"
4945 "The password\n")
4946 {
4947 int idx_peer = 2;
4948 struct peer *peer;
4949 int ret;
4950
4951 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4952 if (!peer)
4953 return CMD_WARNING_CONFIG_FAILED;
4954
4955 ret = peer_password_unset(peer);
4956 return bgp_vty_return(vty, ret);
4957 }
4958
4959 DEFUN (neighbor_activate,
4960 neighbor_activate_cmd,
4961 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4962 NEIGHBOR_STR
4963 NEIGHBOR_ADDR_STR2
4964 "Enable the Address Family for this Neighbor\n")
4965 {
4966 int idx_peer = 1;
4967 int ret;
4968 struct peer *peer;
4969
4970 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4971 if (!peer)
4972 return CMD_WARNING_CONFIG_FAILED;
4973
4974 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4975 return bgp_vty_return(vty, ret);
4976 }
4977
4978 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4979 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4980 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4981 "Enable the Address Family for this Neighbor\n")
4982
4983 DEFUN (no_neighbor_activate,
4984 no_neighbor_activate_cmd,
4985 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4986 NO_STR
4987 NEIGHBOR_STR
4988 NEIGHBOR_ADDR_STR2
4989 "Enable the Address Family for this Neighbor\n")
4990 {
4991 int idx_peer = 2;
4992 int ret;
4993 struct peer *peer;
4994
4995 /* Lookup peer. */
4996 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4997 if (!peer)
4998 return CMD_WARNING_CONFIG_FAILED;
4999
5000 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5001 return bgp_vty_return(vty, ret);
5002 }
5003
5004 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5005 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5006 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5007 "Enable the Address Family for this Neighbor\n")
5008
5009 DEFUN (neighbor_set_peer_group,
5010 neighbor_set_peer_group_cmd,
5011 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5012 NEIGHBOR_STR
5013 NEIGHBOR_ADDR_STR2
5014 "Member of the peer-group\n"
5015 "Peer-group name\n")
5016 {
5017 VTY_DECLVAR_CONTEXT(bgp, bgp);
5018 int idx_peer = 1;
5019 int idx_word = 3;
5020 int ret;
5021 as_t as;
5022 union sockunion su;
5023 struct peer *peer;
5024 struct peer_group *group;
5025
5026 ret = str2sockunion(argv[idx_peer]->arg, &su);
5027 if (ret < 0) {
5028 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5029 if (!peer) {
5030 vty_out(vty, "%% Malformed address or name: %s\n",
5031 argv[idx_peer]->arg);
5032 return CMD_WARNING_CONFIG_FAILED;
5033 }
5034 } else {
5035 if (peer_address_self_check(bgp, &su)) {
5036 vty_out(vty,
5037 "%% Can not configure the local system as neighbor\n");
5038 return CMD_WARNING_CONFIG_FAILED;
5039 }
5040
5041 /* Disallow for dynamic neighbor. */
5042 peer = peer_lookup(bgp, &su);
5043 if (peer && peer_dynamic_neighbor(peer)) {
5044 vty_out(vty,
5045 "%% Operation not allowed on a dynamic neighbor\n");
5046 return CMD_WARNING_CONFIG_FAILED;
5047 }
5048 }
5049
5050 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5051 if (!group) {
5052 vty_out(vty, "%% Configure the peer-group first\n");
5053 return CMD_WARNING_CONFIG_FAILED;
5054 }
5055
5056 ret = peer_group_bind(bgp, &su, peer, group, &as);
5057
5058 return bgp_vty_return(vty, ret);
5059 }
5060
5061 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5062 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5063 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5064 "Member of the peer-group\n"
5065 "Peer-group name\n")
5066
5067 DEFUN (no_neighbor_set_peer_group,
5068 no_neighbor_set_peer_group_cmd,
5069 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5070 NO_STR
5071 NEIGHBOR_STR
5072 NEIGHBOR_ADDR_STR2
5073 "Member of the peer-group\n"
5074 "Peer-group name\n")
5075 {
5076 VTY_DECLVAR_CONTEXT(bgp, bgp);
5077 int idx_peer = 2;
5078 int idx_word = 4;
5079 int ret;
5080 struct peer *peer;
5081 struct peer_group *group;
5082
5083 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5084 if (!peer)
5085 return CMD_WARNING_CONFIG_FAILED;
5086
5087 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5088 if (!group) {
5089 vty_out(vty, "%% Configure the peer-group first\n");
5090 return CMD_WARNING_CONFIG_FAILED;
5091 }
5092
5093 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5094 bgp_zebra_terminate_radv(peer->bgp, peer);
5095
5096 peer_notify_unconfig(peer);
5097 ret = peer_delete(peer);
5098
5099 return bgp_vty_return(vty, ret);
5100 }
5101
5102 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5103 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5104 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5105 "Member of the peer-group\n"
5106 "Peer-group name\n")
5107
5108 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5109 uint32_t flag, int set)
5110 {
5111 int ret;
5112 struct peer *peer;
5113
5114 peer = peer_and_group_lookup_vty(vty, ip_str);
5115 if (!peer)
5116 return CMD_WARNING_CONFIG_FAILED;
5117
5118 /*
5119 * If 'neighbor <interface>', then this is for directly connected peers,
5120 * we should not accept disable-connected-check.
5121 */
5122 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5123 vty_out(vty,
5124 "%s is directly connected peer, cannot accept disable-connected-check\n",
5125 ip_str);
5126 return CMD_WARNING_CONFIG_FAILED;
5127 }
5128
5129 if (!set && flag == PEER_FLAG_SHUTDOWN)
5130 peer_tx_shutdown_message_unset(peer);
5131
5132 if (set)
5133 ret = peer_flag_set(peer, flag);
5134 else
5135 ret = peer_flag_unset(peer, flag);
5136
5137 return bgp_vty_return(vty, ret);
5138 }
5139
5140 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5141 {
5142 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5143 }
5144
5145 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5146 uint32_t flag)
5147 {
5148 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5149 }
5150
5151 /* neighbor passive. */
5152 DEFUN (neighbor_passive,
5153 neighbor_passive_cmd,
5154 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5155 NEIGHBOR_STR
5156 NEIGHBOR_ADDR_STR2
5157 "Don't send open messages to this neighbor\n")
5158 {
5159 int idx_peer = 1;
5160 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5161 }
5162
5163 DEFUN (no_neighbor_passive,
5164 no_neighbor_passive_cmd,
5165 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5166 NO_STR
5167 NEIGHBOR_STR
5168 NEIGHBOR_ADDR_STR2
5169 "Don't send open messages to this neighbor\n")
5170 {
5171 int idx_peer = 2;
5172 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5173 }
5174
5175 /* neighbor shutdown. */
5176 DEFUN (neighbor_shutdown_msg,
5177 neighbor_shutdown_msg_cmd,
5178 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5179 NEIGHBOR_STR
5180 NEIGHBOR_ADDR_STR2
5181 "Administratively shut down this neighbor\n"
5182 "Add a shutdown message (RFC 8203)\n"
5183 "Shutdown message\n")
5184 {
5185 int idx_peer = 1;
5186
5187 if (argc >= 5) {
5188 struct peer *peer =
5189 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5190 char *message;
5191
5192 if (!peer)
5193 return CMD_WARNING_CONFIG_FAILED;
5194 message = argv_concat(argv, argc, 4);
5195 peer_tx_shutdown_message_set(peer, message);
5196 XFREE(MTYPE_TMP, message);
5197 }
5198
5199 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5200 }
5201
5202 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5203 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5204 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5205 "Administratively shut down this neighbor\n")
5206
5207 DEFUN (no_neighbor_shutdown_msg,
5208 no_neighbor_shutdown_msg_cmd,
5209 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5210 NO_STR
5211 NEIGHBOR_STR
5212 NEIGHBOR_ADDR_STR2
5213 "Administratively shut down this neighbor\n"
5214 "Remove a shutdown message (RFC 8203)\n"
5215 "Shutdown message\n")
5216 {
5217 int idx_peer = 2;
5218
5219 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5220 PEER_FLAG_SHUTDOWN);
5221 }
5222
5223 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5224 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5225 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5226 "Administratively shut down this neighbor\n")
5227
5228 DEFUN(neighbor_shutdown_rtt,
5229 neighbor_shutdown_rtt_cmd,
5230 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5231 NEIGHBOR_STR
5232 NEIGHBOR_ADDR_STR2
5233 "Administratively shut down this neighbor\n"
5234 "Shutdown if round-trip-time is higher than expected\n"
5235 "Round-trip-time in milliseconds\n"
5236 "Specify the number of keepalives before shutdown\n"
5237 "The number of keepalives with higher RTT to shutdown\n")
5238 {
5239 int idx_peer = 1;
5240 int idx_rtt = 4;
5241 int idx_count = 0;
5242 struct peer *peer;
5243
5244 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5245
5246 if (!peer)
5247 return CMD_WARNING_CONFIG_FAILED;
5248
5249 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5250
5251 if (argv_find(argv, argc, "count", &idx_count))
5252 peer->rtt_keepalive_conf =
5253 strtol(argv[idx_count + 1]->arg, NULL, 10);
5254
5255 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5256 PEER_FLAG_RTT_SHUTDOWN);
5257 }
5258
5259 DEFUN(no_neighbor_shutdown_rtt,
5260 no_neighbor_shutdown_rtt_cmd,
5261 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5262 NO_STR
5263 NEIGHBOR_STR
5264 NEIGHBOR_ADDR_STR2
5265 "Administratively shut down this neighbor\n"
5266 "Shutdown if round-trip-time is higher than expected\n"
5267 "Round-trip-time in milliseconds\n"
5268 "Specify the number of keepalives before shutdown\n"
5269 "The number of keepalives with higher RTT to shutdown\n")
5270 {
5271 int idx_peer = 2;
5272 struct peer *peer;
5273
5274 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5275
5276 if (!peer)
5277 return CMD_WARNING_CONFIG_FAILED;
5278
5279 peer->rtt_expected = 0;
5280 peer->rtt_keepalive_conf = 1;
5281
5282 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5283 PEER_FLAG_RTT_SHUTDOWN);
5284 }
5285
5286 /* neighbor capability dynamic. */
5287 DEFUN (neighbor_capability_dynamic,
5288 neighbor_capability_dynamic_cmd,
5289 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5290 NEIGHBOR_STR
5291 NEIGHBOR_ADDR_STR2
5292 "Advertise capability to the peer\n"
5293 "Advertise dynamic capability to this neighbor\n")
5294 {
5295 int idx_peer = 1;
5296 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5297 PEER_FLAG_DYNAMIC_CAPABILITY);
5298 }
5299
5300 DEFUN (no_neighbor_capability_dynamic,
5301 no_neighbor_capability_dynamic_cmd,
5302 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5303 NO_STR
5304 NEIGHBOR_STR
5305 NEIGHBOR_ADDR_STR2
5306 "Advertise capability to the peer\n"
5307 "Advertise dynamic capability to this neighbor\n")
5308 {
5309 int idx_peer = 2;
5310 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5311 PEER_FLAG_DYNAMIC_CAPABILITY);
5312 }
5313
5314 /* neighbor dont-capability-negotiate */
5315 DEFUN (neighbor_dont_capability_negotiate,
5316 neighbor_dont_capability_negotiate_cmd,
5317 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5318 NEIGHBOR_STR
5319 NEIGHBOR_ADDR_STR2
5320 "Do not perform capability negotiation\n")
5321 {
5322 int idx_peer = 1;
5323 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5324 PEER_FLAG_DONT_CAPABILITY);
5325 }
5326
5327 DEFUN (no_neighbor_dont_capability_negotiate,
5328 no_neighbor_dont_capability_negotiate_cmd,
5329 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5330 NO_STR
5331 NEIGHBOR_STR
5332 NEIGHBOR_ADDR_STR2
5333 "Do not perform capability negotiation\n")
5334 {
5335 int idx_peer = 2;
5336 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5337 PEER_FLAG_DONT_CAPABILITY);
5338 }
5339
5340 /* neighbor capability extended next hop encoding */
5341 DEFUN (neighbor_capability_enhe,
5342 neighbor_capability_enhe_cmd,
5343 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5344 NEIGHBOR_STR
5345 NEIGHBOR_ADDR_STR2
5346 "Advertise capability to the peer\n"
5347 "Advertise extended next-hop capability to the peer\n")
5348 {
5349 int idx_peer = 1;
5350 struct peer *peer;
5351
5352 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5353 if (peer && peer->conf_if)
5354 return CMD_SUCCESS;
5355
5356 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5357 PEER_FLAG_CAPABILITY_ENHE);
5358 }
5359
5360 DEFUN (no_neighbor_capability_enhe,
5361 no_neighbor_capability_enhe_cmd,
5362 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5363 NO_STR
5364 NEIGHBOR_STR
5365 NEIGHBOR_ADDR_STR2
5366 "Advertise capability to the peer\n"
5367 "Advertise extended next-hop capability to the peer\n")
5368 {
5369 int idx_peer = 2;
5370 struct peer *peer;
5371
5372 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5373 if (peer && peer->conf_if) {
5374 vty_out(vty,
5375 "Peer %s cannot have capability extended-nexthop turned off\n",
5376 argv[idx_peer]->arg);
5377 return CMD_WARNING_CONFIG_FAILED;
5378 }
5379
5380 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5381 PEER_FLAG_CAPABILITY_ENHE);
5382 }
5383
5384 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5385 afi_t afi, safi_t safi, uint32_t flag,
5386 int set)
5387 {
5388 int ret;
5389 struct peer *peer;
5390
5391 peer = peer_and_group_lookup_vty(vty, peer_str);
5392 if (!peer)
5393 return CMD_WARNING_CONFIG_FAILED;
5394
5395 if (set)
5396 ret = peer_af_flag_set(peer, afi, safi, flag);
5397 else
5398 ret = peer_af_flag_unset(peer, afi, safi, flag);
5399
5400 return bgp_vty_return(vty, ret);
5401 }
5402
5403 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5404 afi_t afi, safi_t safi, uint32_t flag)
5405 {
5406 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5407 }
5408
5409 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5410 afi_t afi, safi_t safi, uint32_t flag)
5411 {
5412 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5413 }
5414
5415 /* neighbor capability orf prefix-list. */
5416 DEFUN (neighbor_capability_orf_prefix,
5417 neighbor_capability_orf_prefix_cmd,
5418 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5419 NEIGHBOR_STR
5420 NEIGHBOR_ADDR_STR2
5421 "Advertise capability to the peer\n"
5422 "Advertise ORF capability to the peer\n"
5423 "Advertise prefixlist ORF capability to this neighbor\n"
5424 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5425 "Capability to RECEIVE the ORF from this neighbor\n"
5426 "Capability to SEND the ORF to this neighbor\n")
5427 {
5428 int idx_send_recv = 5;
5429 char *peer_str = argv[1]->arg;
5430 struct peer *peer;
5431 afi_t afi = bgp_node_afi(vty);
5432 safi_t safi = bgp_node_safi(vty);
5433
5434 peer = peer_and_group_lookup_vty(vty, peer_str);
5435 if (!peer)
5436 return CMD_WARNING_CONFIG_FAILED;
5437
5438 if (strmatch(argv[idx_send_recv]->text, "send"))
5439 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5440 PEER_FLAG_ORF_PREFIX_SM);
5441
5442 if (strmatch(argv[idx_send_recv]->text, "receive"))
5443 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5444 PEER_FLAG_ORF_PREFIX_RM);
5445
5446 if (strmatch(argv[idx_send_recv]->text, "both"))
5447 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5448 PEER_FLAG_ORF_PREFIX_SM)
5449 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5450 PEER_FLAG_ORF_PREFIX_RM);
5451
5452 return CMD_WARNING_CONFIG_FAILED;
5453 }
5454
5455 ALIAS_HIDDEN(
5456 neighbor_capability_orf_prefix,
5457 neighbor_capability_orf_prefix_hidden_cmd,
5458 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5459 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5460 "Advertise capability to the peer\n"
5461 "Advertise ORF capability to the peer\n"
5462 "Advertise prefixlist ORF capability to this neighbor\n"
5463 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5464 "Capability to RECEIVE the ORF from this neighbor\n"
5465 "Capability to SEND the ORF to this neighbor\n")
5466
5467 DEFUN (no_neighbor_capability_orf_prefix,
5468 no_neighbor_capability_orf_prefix_cmd,
5469 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5470 NO_STR
5471 NEIGHBOR_STR
5472 NEIGHBOR_ADDR_STR2
5473 "Advertise capability to the peer\n"
5474 "Advertise ORF capability to the peer\n"
5475 "Advertise prefixlist ORF capability to this neighbor\n"
5476 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5477 "Capability to RECEIVE the ORF from this neighbor\n"
5478 "Capability to SEND the ORF to this neighbor\n")
5479 {
5480 int idx_send_recv = 6;
5481 char *peer_str = argv[2]->arg;
5482 struct peer *peer;
5483 afi_t afi = bgp_node_afi(vty);
5484 safi_t safi = bgp_node_safi(vty);
5485
5486 peer = peer_and_group_lookup_vty(vty, peer_str);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
5489
5490 if (strmatch(argv[idx_send_recv]->text, "send"))
5491 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5492 PEER_FLAG_ORF_PREFIX_SM);
5493
5494 if (strmatch(argv[idx_send_recv]->text, "receive"))
5495 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5496 PEER_FLAG_ORF_PREFIX_RM);
5497
5498 if (strmatch(argv[idx_send_recv]->text, "both"))
5499 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5500 PEER_FLAG_ORF_PREFIX_SM)
5501 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5502 PEER_FLAG_ORF_PREFIX_RM);
5503
5504 return CMD_WARNING_CONFIG_FAILED;
5505 }
5506
5507 ALIAS_HIDDEN(
5508 no_neighbor_capability_orf_prefix,
5509 no_neighbor_capability_orf_prefix_hidden_cmd,
5510 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5511 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5512 "Advertise capability to the peer\n"
5513 "Advertise ORF capability to the peer\n"
5514 "Advertise prefixlist ORF capability to this neighbor\n"
5515 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5516 "Capability to RECEIVE the ORF from this neighbor\n"
5517 "Capability to SEND the ORF to this neighbor\n")
5518
5519 /* neighbor next-hop-self. */
5520 DEFUN (neighbor_nexthop_self,
5521 neighbor_nexthop_self_cmd,
5522 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5523 NEIGHBOR_STR
5524 NEIGHBOR_ADDR_STR2
5525 "Disable the next hop calculation for this neighbor\n")
5526 {
5527 int idx_peer = 1;
5528 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5529 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5530 }
5531
5532 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5533 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5534 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5535 "Disable the next hop calculation for this neighbor\n")
5536
5537 /* neighbor next-hop-self. */
5538 DEFUN (neighbor_nexthop_self_force,
5539 neighbor_nexthop_self_force_cmd,
5540 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Disable the next hop calculation for this neighbor\n"
5544 "Set the next hop to self for reflected routes\n")
5545 {
5546 int idx_peer = 1;
5547 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5548 bgp_node_safi(vty),
5549 PEER_FLAG_FORCE_NEXTHOP_SELF);
5550 }
5551
5552 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5553 neighbor_nexthop_self_force_hidden_cmd,
5554 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5555 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5556 "Disable the next hop calculation for this neighbor\n"
5557 "Set the next hop to self for reflected routes\n")
5558
5559 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5560 neighbor_nexthop_self_all_hidden_cmd,
5561 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5562 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5563 "Disable the next hop calculation for this neighbor\n"
5564 "Set the next hop to self for reflected routes\n")
5565
5566 DEFUN (no_neighbor_nexthop_self,
5567 no_neighbor_nexthop_self_cmd,
5568 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5569 NO_STR
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR2
5572 "Disable the next hop calculation for this neighbor\n")
5573 {
5574 int idx_peer = 2;
5575 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5576 bgp_node_afi(vty), bgp_node_safi(vty),
5577 PEER_FLAG_NEXTHOP_SELF);
5578 }
5579
5580 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5581 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5582 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5583 "Disable the next hop calculation for this neighbor\n")
5584
5585 DEFUN (no_neighbor_nexthop_self_force,
5586 no_neighbor_nexthop_self_force_cmd,
5587 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5588 NO_STR
5589 NEIGHBOR_STR
5590 NEIGHBOR_ADDR_STR2
5591 "Disable the next hop calculation for this neighbor\n"
5592 "Set the next hop to self for reflected routes\n")
5593 {
5594 int idx_peer = 2;
5595 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5596 bgp_node_afi(vty), bgp_node_safi(vty),
5597 PEER_FLAG_FORCE_NEXTHOP_SELF);
5598 }
5599
5600 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5601 no_neighbor_nexthop_self_force_hidden_cmd,
5602 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5603 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5604 "Disable the next hop calculation for this neighbor\n"
5605 "Set the next hop to self for reflected routes\n")
5606
5607 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5608 no_neighbor_nexthop_self_all_hidden_cmd,
5609 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5610 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5611 "Disable the next hop calculation for this neighbor\n"
5612 "Set the next hop to self for reflected routes\n")
5613
5614 /* neighbor as-override */
5615 DEFUN (neighbor_as_override,
5616 neighbor_as_override_cmd,
5617 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5618 NEIGHBOR_STR
5619 NEIGHBOR_ADDR_STR2
5620 "Override ASNs in outbound updates if aspath equals remote-as\n")
5621 {
5622 int idx_peer = 1;
5623 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5624 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5625 }
5626
5627 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5628 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5629 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5630 "Override ASNs in outbound updates if aspath equals remote-as\n")
5631
5632 DEFUN (no_neighbor_as_override,
5633 no_neighbor_as_override_cmd,
5634 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5635 NO_STR
5636 NEIGHBOR_STR
5637 NEIGHBOR_ADDR_STR2
5638 "Override ASNs in outbound updates if aspath equals remote-as\n")
5639 {
5640 int idx_peer = 2;
5641 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5642 bgp_node_afi(vty), bgp_node_safi(vty),
5643 PEER_FLAG_AS_OVERRIDE);
5644 }
5645
5646 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5647 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5648 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5649 "Override ASNs in outbound updates if aspath equals remote-as\n")
5650
5651 /* neighbor remove-private-AS. */
5652 DEFUN (neighbor_remove_private_as,
5653 neighbor_remove_private_as_cmd,
5654 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5655 NEIGHBOR_STR
5656 NEIGHBOR_ADDR_STR2
5657 "Remove private ASNs in outbound updates\n")
5658 {
5659 int idx_peer = 1;
5660 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5661 bgp_node_safi(vty),
5662 PEER_FLAG_REMOVE_PRIVATE_AS);
5663 }
5664
5665 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5666 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5667 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5668 "Remove private ASNs in outbound updates\n")
5669
5670 DEFUN (neighbor_remove_private_as_all,
5671 neighbor_remove_private_as_all_cmd,
5672 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5673 NEIGHBOR_STR
5674 NEIGHBOR_ADDR_STR2
5675 "Remove private ASNs in outbound updates\n"
5676 "Apply to all AS numbers\n")
5677 {
5678 int idx_peer = 1;
5679 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5680 bgp_node_safi(vty),
5681 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5682 }
5683
5684 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5685 neighbor_remove_private_as_all_hidden_cmd,
5686 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5687 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5688 "Remove private ASNs in outbound updates\n"
5689 "Apply to all AS numbers")
5690
5691 DEFUN (neighbor_remove_private_as_replace_as,
5692 neighbor_remove_private_as_replace_as_cmd,
5693 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5694 NEIGHBOR_STR
5695 NEIGHBOR_ADDR_STR2
5696 "Remove private ASNs in outbound updates\n"
5697 "Replace private ASNs with our ASN in outbound updates\n")
5698 {
5699 int idx_peer = 1;
5700 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5701 bgp_node_safi(vty),
5702 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5703 }
5704
5705 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5706 neighbor_remove_private_as_replace_as_hidden_cmd,
5707 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5708 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5709 "Remove private ASNs in outbound updates\n"
5710 "Replace private ASNs with our ASN in outbound updates\n")
5711
5712 DEFUN (neighbor_remove_private_as_all_replace_as,
5713 neighbor_remove_private_as_all_replace_as_cmd,
5714 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5715 NEIGHBOR_STR
5716 NEIGHBOR_ADDR_STR2
5717 "Remove private ASNs in outbound updates\n"
5718 "Apply to all AS numbers\n"
5719 "Replace private ASNs with our ASN in outbound updates\n")
5720 {
5721 int idx_peer = 1;
5722 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5723 bgp_node_safi(vty),
5724 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5725 }
5726
5727 ALIAS_HIDDEN(
5728 neighbor_remove_private_as_all_replace_as,
5729 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5730 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5731 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5732 "Remove private ASNs in outbound updates\n"
5733 "Apply to all AS numbers\n"
5734 "Replace private ASNs with our ASN in outbound updates\n")
5735
5736 DEFUN (no_neighbor_remove_private_as,
5737 no_neighbor_remove_private_as_cmd,
5738 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5739 NO_STR
5740 NEIGHBOR_STR
5741 NEIGHBOR_ADDR_STR2
5742 "Remove private ASNs in outbound updates\n")
5743 {
5744 int idx_peer = 2;
5745 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5746 bgp_node_afi(vty), bgp_node_safi(vty),
5747 PEER_FLAG_REMOVE_PRIVATE_AS);
5748 }
5749
5750 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5751 no_neighbor_remove_private_as_hidden_cmd,
5752 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5753 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5754 "Remove private ASNs in outbound updates\n")
5755
5756 DEFUN (no_neighbor_remove_private_as_all,
5757 no_neighbor_remove_private_as_all_cmd,
5758 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5759 NO_STR
5760 NEIGHBOR_STR
5761 NEIGHBOR_ADDR_STR2
5762 "Remove private ASNs in outbound updates\n"
5763 "Apply to all AS numbers\n")
5764 {
5765 int idx_peer = 2;
5766 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5767 bgp_node_afi(vty), bgp_node_safi(vty),
5768 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5769 }
5770
5771 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5772 no_neighbor_remove_private_as_all_hidden_cmd,
5773 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5774 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5775 "Remove private ASNs in outbound updates\n"
5776 "Apply to all AS numbers\n")
5777
5778 DEFUN (no_neighbor_remove_private_as_replace_as,
5779 no_neighbor_remove_private_as_replace_as_cmd,
5780 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5781 NO_STR
5782 NEIGHBOR_STR
5783 NEIGHBOR_ADDR_STR2
5784 "Remove private ASNs in outbound updates\n"
5785 "Replace private ASNs with our ASN in outbound updates\n")
5786 {
5787 int idx_peer = 2;
5788 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5789 bgp_node_afi(vty), bgp_node_safi(vty),
5790 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5791 }
5792
5793 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5794 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5795 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5796 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5797 "Remove private ASNs in outbound updates\n"
5798 "Replace private ASNs with our ASN in outbound updates\n")
5799
5800 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5801 no_neighbor_remove_private_as_all_replace_as_cmd,
5802 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5803 NO_STR
5804 NEIGHBOR_STR
5805 NEIGHBOR_ADDR_STR2
5806 "Remove private ASNs in outbound updates\n"
5807 "Apply to all AS numbers\n"
5808 "Replace private ASNs with our ASN in outbound updates\n")
5809 {
5810 int idx_peer = 2;
5811 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5812 bgp_node_afi(vty), bgp_node_safi(vty),
5813 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5814 }
5815
5816 ALIAS_HIDDEN(
5817 no_neighbor_remove_private_as_all_replace_as,
5818 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5819 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5820 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5821 "Remove private ASNs in outbound updates\n"
5822 "Apply to all AS numbers\n"
5823 "Replace private ASNs with our ASN in outbound updates\n")
5824
5825
5826 /* neighbor send-community. */
5827 DEFUN (neighbor_send_community,
5828 neighbor_send_community_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5830 NEIGHBOR_STR
5831 NEIGHBOR_ADDR_STR2
5832 "Send Community attribute to this neighbor\n")
5833 {
5834 int idx_peer = 1;
5835
5836 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5837 bgp_node_safi(vty),
5838 PEER_FLAG_SEND_COMMUNITY);
5839 }
5840
5841 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5842 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5843 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5844 "Send Community attribute to this neighbor\n")
5845
5846 DEFUN (no_neighbor_send_community,
5847 no_neighbor_send_community_cmd,
5848 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5849 NO_STR
5850 NEIGHBOR_STR
5851 NEIGHBOR_ADDR_STR2
5852 "Send Community attribute to this neighbor\n")
5853 {
5854 int idx_peer = 2;
5855
5856 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5857 bgp_node_afi(vty), bgp_node_safi(vty),
5858 PEER_FLAG_SEND_COMMUNITY);
5859 }
5860
5861 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5862 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5863 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5864 "Send Community attribute to this neighbor\n")
5865
5866 /* neighbor send-community extended. */
5867 DEFUN (neighbor_send_community_type,
5868 neighbor_send_community_type_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Send Community attribute to this neighbor\n"
5873 "Send Standard and Extended Community attributes\n"
5874 "Send Standard, Large and Extended Community attributes\n"
5875 "Send Extended Community attributes\n"
5876 "Send Standard Community attributes\n"
5877 "Send Large Community attributes\n")
5878 {
5879 const char *type = argv[argc - 1]->text;
5880 char *peer_str = argv[1]->arg;
5881 struct peer *peer;
5882 afi_t afi = bgp_node_afi(vty);
5883 safi_t safi = bgp_node_safi(vty);
5884
5885 peer = peer_and_group_lookup_vty(vty, peer_str);
5886 if (!peer)
5887 return CMD_WARNING_CONFIG_FAILED;
5888
5889 if (strmatch(type, "standard"))
5890 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5891 PEER_FLAG_SEND_COMMUNITY);
5892
5893 if (strmatch(type, "extended"))
5894 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5895 PEER_FLAG_SEND_EXT_COMMUNITY);
5896
5897 if (strmatch(type, "large"))
5898 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5899 PEER_FLAG_SEND_LARGE_COMMUNITY);
5900
5901 if (strmatch(type, "both")) {
5902 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5903 PEER_FLAG_SEND_COMMUNITY)
5904 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5905 PEER_FLAG_SEND_EXT_COMMUNITY);
5906 }
5907 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5908 PEER_FLAG_SEND_COMMUNITY)
5909 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5910 PEER_FLAG_SEND_EXT_COMMUNITY)
5911 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5912 PEER_FLAG_SEND_LARGE_COMMUNITY);
5913 }
5914
5915 ALIAS_HIDDEN(
5916 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5917 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5918 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5919 "Send Community attribute to this neighbor\n"
5920 "Send Standard and Extended Community attributes\n"
5921 "Send Standard, Large and Extended Community attributes\n"
5922 "Send Extended Community attributes\n"
5923 "Send Standard Community attributes\n"
5924 "Send Large Community attributes\n")
5925
5926 DEFUN (no_neighbor_send_community_type,
5927 no_neighbor_send_community_type_cmd,
5928 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5929 NO_STR
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Send Community attribute to this neighbor\n"
5933 "Send Standard and Extended Community attributes\n"
5934 "Send Standard, Large and Extended Community attributes\n"
5935 "Send Extended Community attributes\n"
5936 "Send Standard Community attributes\n"
5937 "Send Large Community attributes\n")
5938 {
5939 const char *type = argv[argc - 1]->text;
5940 char *peer_str = argv[2]->arg;
5941 struct peer *peer;
5942 afi_t afi = bgp_node_afi(vty);
5943 safi_t safi = bgp_node_safi(vty);
5944
5945 peer = peer_and_group_lookup_vty(vty, peer_str);
5946 if (!peer)
5947 return CMD_WARNING_CONFIG_FAILED;
5948
5949 if (strmatch(type, "standard"))
5950 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5951 PEER_FLAG_SEND_COMMUNITY);
5952
5953 if (strmatch(type, "extended"))
5954 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5955 PEER_FLAG_SEND_EXT_COMMUNITY);
5956
5957 if (strmatch(type, "large"))
5958 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5959 PEER_FLAG_SEND_LARGE_COMMUNITY);
5960
5961 if (strmatch(type, "both")) {
5962
5963 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5964 PEER_FLAG_SEND_COMMUNITY)
5965 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5966 PEER_FLAG_SEND_EXT_COMMUNITY);
5967 }
5968
5969 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5970 PEER_FLAG_SEND_COMMUNITY)
5971 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5972 PEER_FLAG_SEND_EXT_COMMUNITY)
5973 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5974 PEER_FLAG_SEND_LARGE_COMMUNITY);
5975 }
5976
5977 ALIAS_HIDDEN(
5978 no_neighbor_send_community_type,
5979 no_neighbor_send_community_type_hidden_cmd,
5980 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5981 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5982 "Send Community attribute to this neighbor\n"
5983 "Send Standard and Extended Community attributes\n"
5984 "Send Standard, Large and Extended Community attributes\n"
5985 "Send Extended Community attributes\n"
5986 "Send Standard Community attributes\n"
5987 "Send Large Community attributes\n")
5988
5989 /* neighbor soft-reconfig. */
5990 DEFUN (neighbor_soft_reconfiguration,
5991 neighbor_soft_reconfiguration_cmd,
5992 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5993 NEIGHBOR_STR
5994 NEIGHBOR_ADDR_STR2
5995 "Per neighbor soft reconfiguration\n"
5996 "Allow inbound soft reconfiguration for this neighbor\n")
5997 {
5998 int idx_peer = 1;
5999 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6000 bgp_node_safi(vty),
6001 PEER_FLAG_SOFT_RECONFIG);
6002 }
6003
6004 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6005 neighbor_soft_reconfiguration_hidden_cmd,
6006 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6007 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6008 "Per neighbor soft reconfiguration\n"
6009 "Allow inbound soft reconfiguration for this neighbor\n")
6010
6011 DEFUN (no_neighbor_soft_reconfiguration,
6012 no_neighbor_soft_reconfiguration_cmd,
6013 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6014 NO_STR
6015 NEIGHBOR_STR
6016 NEIGHBOR_ADDR_STR2
6017 "Per neighbor soft reconfiguration\n"
6018 "Allow inbound soft reconfiguration for this neighbor\n")
6019 {
6020 int idx_peer = 2;
6021 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6022 bgp_node_afi(vty), bgp_node_safi(vty),
6023 PEER_FLAG_SOFT_RECONFIG);
6024 }
6025
6026 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6027 no_neighbor_soft_reconfiguration_hidden_cmd,
6028 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6029 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6030 "Per neighbor soft reconfiguration\n"
6031 "Allow inbound soft reconfiguration for this neighbor\n")
6032
6033 DEFUN (neighbor_route_reflector_client,
6034 neighbor_route_reflector_client_cmd,
6035 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6036 NEIGHBOR_STR
6037 NEIGHBOR_ADDR_STR2
6038 "Configure a neighbor as Route Reflector client\n")
6039 {
6040 int idx_peer = 1;
6041 struct peer *peer;
6042
6043
6044 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6045 if (!peer)
6046 return CMD_WARNING_CONFIG_FAILED;
6047
6048 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6049 bgp_node_safi(vty),
6050 PEER_FLAG_REFLECTOR_CLIENT);
6051 }
6052
6053 ALIAS_HIDDEN(neighbor_route_reflector_client,
6054 neighbor_route_reflector_client_hidden_cmd,
6055 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6056 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6057 "Configure a neighbor as Route Reflector client\n")
6058
6059 DEFUN (no_neighbor_route_reflector_client,
6060 no_neighbor_route_reflector_client_cmd,
6061 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6062 NO_STR
6063 NEIGHBOR_STR
6064 NEIGHBOR_ADDR_STR2
6065 "Configure a neighbor as Route Reflector client\n")
6066 {
6067 int idx_peer = 2;
6068 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6069 bgp_node_afi(vty), bgp_node_safi(vty),
6070 PEER_FLAG_REFLECTOR_CLIENT);
6071 }
6072
6073 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6074 no_neighbor_route_reflector_client_hidden_cmd,
6075 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6076 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6077 "Configure a neighbor as Route Reflector client\n")
6078
6079 /* neighbor route-server-client. */
6080 DEFUN (neighbor_route_server_client,
6081 neighbor_route_server_client_cmd,
6082 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6083 NEIGHBOR_STR
6084 NEIGHBOR_ADDR_STR2
6085 "Configure a neighbor as Route Server client\n")
6086 {
6087 int idx_peer = 1;
6088 struct peer *peer;
6089
6090 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6091 if (!peer)
6092 return CMD_WARNING_CONFIG_FAILED;
6093 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6094 bgp_node_safi(vty),
6095 PEER_FLAG_RSERVER_CLIENT);
6096 }
6097
6098 ALIAS_HIDDEN(neighbor_route_server_client,
6099 neighbor_route_server_client_hidden_cmd,
6100 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6101 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6102 "Configure a neighbor as Route Server client\n")
6103
6104 DEFUN (no_neighbor_route_server_client,
6105 no_neighbor_route_server_client_cmd,
6106 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6107 NO_STR
6108 NEIGHBOR_STR
6109 NEIGHBOR_ADDR_STR2
6110 "Configure a neighbor as Route Server client\n")
6111 {
6112 int idx_peer = 2;
6113 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6114 bgp_node_afi(vty), bgp_node_safi(vty),
6115 PEER_FLAG_RSERVER_CLIENT);
6116 }
6117
6118 ALIAS_HIDDEN(no_neighbor_route_server_client,
6119 no_neighbor_route_server_client_hidden_cmd,
6120 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6121 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6122 "Configure a neighbor as Route Server client\n")
6123
6124 DEFUN (neighbor_nexthop_local_unchanged,
6125 neighbor_nexthop_local_unchanged_cmd,
6126 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6127 NEIGHBOR_STR
6128 NEIGHBOR_ADDR_STR2
6129 "Configure treatment of outgoing link-local nexthop attribute\n"
6130 "Leave link-local nexthop unchanged for this peer\n")
6131 {
6132 int idx_peer = 1;
6133 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6134 bgp_node_safi(vty),
6135 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6136 }
6137
6138 DEFUN (no_neighbor_nexthop_local_unchanged,
6139 no_neighbor_nexthop_local_unchanged_cmd,
6140 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6141 NO_STR
6142 NEIGHBOR_STR
6143 NEIGHBOR_ADDR_STR2
6144 "Configure treatment of outgoing link-local-nexthop attribute\n"
6145 "Leave link-local nexthop unchanged for this peer\n")
6146 {
6147 int idx_peer = 2;
6148 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6149 bgp_node_afi(vty), bgp_node_safi(vty),
6150 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6151 }
6152
6153 DEFUN (neighbor_attr_unchanged,
6154 neighbor_attr_unchanged_cmd,
6155 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6156 NEIGHBOR_STR
6157 NEIGHBOR_ADDR_STR2
6158 "BGP attribute is propagated unchanged to this neighbor\n"
6159 "As-path attribute\n"
6160 "Nexthop attribute\n"
6161 "Med attribute\n")
6162 {
6163 int idx = 0;
6164 char *peer_str = argv[1]->arg;
6165 struct peer *peer;
6166 bool aspath = false;
6167 bool nexthop = false;
6168 bool med = false;
6169 afi_t afi = bgp_node_afi(vty);
6170 safi_t safi = bgp_node_safi(vty);
6171 int ret = 0;
6172
6173 peer = peer_and_group_lookup_vty(vty, peer_str);
6174 if (!peer)
6175 return CMD_WARNING_CONFIG_FAILED;
6176
6177 if (argv_find(argv, argc, "as-path", &idx))
6178 aspath = true;
6179
6180 idx = 0;
6181 if (argv_find(argv, argc, "next-hop", &idx))
6182 nexthop = true;
6183
6184 idx = 0;
6185 if (argv_find(argv, argc, "med", &idx))
6186 med = true;
6187
6188 /* no flags means all of them! */
6189 if (!aspath && !nexthop && !med) {
6190 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6191 PEER_FLAG_AS_PATH_UNCHANGED);
6192 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6193 PEER_FLAG_NEXTHOP_UNCHANGED);
6194 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6195 PEER_FLAG_MED_UNCHANGED);
6196 } else {
6197 if (!aspath) {
6198 if (peer_af_flag_check(peer, afi, safi,
6199 PEER_FLAG_AS_PATH_UNCHANGED)) {
6200 ret |= peer_af_flag_unset_vty(
6201 vty, peer_str, afi, safi,
6202 PEER_FLAG_AS_PATH_UNCHANGED);
6203 }
6204 } else
6205 ret |= peer_af_flag_set_vty(
6206 vty, peer_str, afi, safi,
6207 PEER_FLAG_AS_PATH_UNCHANGED);
6208
6209 if (!nexthop) {
6210 if (peer_af_flag_check(peer, afi, safi,
6211 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6212 ret |= peer_af_flag_unset_vty(
6213 vty, peer_str, afi, safi,
6214 PEER_FLAG_NEXTHOP_UNCHANGED);
6215 }
6216 } else
6217 ret |= peer_af_flag_set_vty(
6218 vty, peer_str, afi, safi,
6219 PEER_FLAG_NEXTHOP_UNCHANGED);
6220
6221 if (!med) {
6222 if (peer_af_flag_check(peer, afi, safi,
6223 PEER_FLAG_MED_UNCHANGED)) {
6224 ret |= peer_af_flag_unset_vty(
6225 vty, peer_str, afi, safi,
6226 PEER_FLAG_MED_UNCHANGED);
6227 }
6228 } else
6229 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6230 PEER_FLAG_MED_UNCHANGED);
6231 }
6232
6233 return ret;
6234 }
6235
6236 ALIAS_HIDDEN(
6237 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6238 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6239 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6240 "BGP attribute is propagated unchanged to this neighbor\n"
6241 "As-path attribute\n"
6242 "Nexthop attribute\n"
6243 "Med attribute\n")
6244
6245 DEFUN (no_neighbor_attr_unchanged,
6246 no_neighbor_attr_unchanged_cmd,
6247 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6248 NO_STR
6249 NEIGHBOR_STR
6250 NEIGHBOR_ADDR_STR2
6251 "BGP attribute is propagated unchanged to this neighbor\n"
6252 "As-path attribute\n"
6253 "Nexthop attribute\n"
6254 "Med attribute\n")
6255 {
6256 int idx = 0;
6257 char *peer_str = argv[2]->arg;
6258 struct peer *peer;
6259 bool aspath = false;
6260 bool nexthop = false;
6261 bool med = false;
6262 afi_t afi = bgp_node_afi(vty);
6263 safi_t safi = bgp_node_safi(vty);
6264 int ret = 0;
6265
6266 peer = peer_and_group_lookup_vty(vty, peer_str);
6267 if (!peer)
6268 return CMD_WARNING_CONFIG_FAILED;
6269
6270 if (argv_find(argv, argc, "as-path", &idx))
6271 aspath = true;
6272
6273 idx = 0;
6274 if (argv_find(argv, argc, "next-hop", &idx))
6275 nexthop = true;
6276
6277 idx = 0;
6278 if (argv_find(argv, argc, "med", &idx))
6279 med = true;
6280
6281 if (!aspath && !nexthop && !med) // no flags means all of them!
6282 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6283 PEER_FLAG_AS_PATH_UNCHANGED)
6284 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6285 PEER_FLAG_NEXTHOP_UNCHANGED)
6286 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6287 PEER_FLAG_MED_UNCHANGED);
6288
6289 if (aspath)
6290 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6291 PEER_FLAG_AS_PATH_UNCHANGED);
6292
6293 if (nexthop)
6294 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6295 PEER_FLAG_NEXTHOP_UNCHANGED);
6296
6297 if (med)
6298 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6299 PEER_FLAG_MED_UNCHANGED);
6300
6301 return ret;
6302 }
6303
6304 ALIAS_HIDDEN(
6305 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6306 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6308 "BGP attribute is propagated unchanged to this neighbor\n"
6309 "As-path attribute\n"
6310 "Nexthop attribute\n"
6311 "Med attribute\n")
6312
6313 /* EBGP multihop configuration. */
6314 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6315 const char *ttl_str)
6316 {
6317 struct peer *peer;
6318 unsigned int ttl;
6319
6320 peer = peer_and_group_lookup_vty(vty, ip_str);
6321 if (!peer)
6322 return CMD_WARNING_CONFIG_FAILED;
6323
6324 if (peer->conf_if)
6325 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6326
6327 if (!ttl_str)
6328 ttl = MAXTTL;
6329 else
6330 ttl = strtoul(ttl_str, NULL, 10);
6331
6332 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6333 }
6334
6335 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6336 {
6337 struct peer *peer;
6338
6339 peer = peer_and_group_lookup_vty(vty, ip_str);
6340 if (!peer)
6341 return CMD_WARNING_CONFIG_FAILED;
6342
6343 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6344 }
6345
6346 /* neighbor ebgp-multihop. */
6347 DEFUN (neighbor_ebgp_multihop,
6348 neighbor_ebgp_multihop_cmd,
6349 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6350 NEIGHBOR_STR
6351 NEIGHBOR_ADDR_STR2
6352 "Allow EBGP neighbors not on directly connected networks\n")
6353 {
6354 int idx_peer = 1;
6355 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6356 }
6357
6358 DEFUN (neighbor_ebgp_multihop_ttl,
6359 neighbor_ebgp_multihop_ttl_cmd,
6360 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6361 NEIGHBOR_STR
6362 NEIGHBOR_ADDR_STR2
6363 "Allow EBGP neighbors not on directly connected networks\n"
6364 "maximum hop count\n")
6365 {
6366 int idx_peer = 1;
6367 int idx_number = 3;
6368 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6369 argv[idx_number]->arg);
6370 }
6371
6372 DEFUN (no_neighbor_ebgp_multihop,
6373 no_neighbor_ebgp_multihop_cmd,
6374 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6375 NO_STR
6376 NEIGHBOR_STR
6377 NEIGHBOR_ADDR_STR2
6378 "Allow EBGP neighbors not on directly connected networks\n"
6379 "maximum hop count\n")
6380 {
6381 int idx_peer = 2;
6382 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6383 }
6384
6385
6386 /* disable-connected-check */
6387 DEFUN (neighbor_disable_connected_check,
6388 neighbor_disable_connected_check_cmd,
6389 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6390 NEIGHBOR_STR
6391 NEIGHBOR_ADDR_STR2
6392 "one-hop away EBGP peer using loopback address\n"
6393 "Enforce EBGP neighbors perform multihop\n")
6394 {
6395 int idx_peer = 1;
6396 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6397 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6398 }
6399
6400 DEFUN (no_neighbor_disable_connected_check,
6401 no_neighbor_disable_connected_check_cmd,
6402 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6403 NO_STR
6404 NEIGHBOR_STR
6405 NEIGHBOR_ADDR_STR2
6406 "one-hop away EBGP peer using loopback address\n"
6407 "Enforce EBGP neighbors perform multihop\n")
6408 {
6409 int idx_peer = 2;
6410 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6411 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6412 }
6413
6414 /* disable-link-bw-encoding-ieee */
6415 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6416 neighbor_disable_link_bw_encoding_ieee_cmd,
6417 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6418 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6419 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6420 {
6421 int idx_peer = 1;
6422
6423 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6424 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6425 }
6426
6427 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6428 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6429 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6430 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6431 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6432 {
6433 int idx_peer = 2;
6434
6435 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6436 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6437 }
6438
6439 /* extended-optional-parameters */
6440 DEFUN(neighbor_extended_optional_parameters,
6441 neighbor_extended_optional_parameters_cmd,
6442 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6443 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6444 "Force the extended optional parameters format for OPEN messages\n")
6445 {
6446 int idx_peer = 1;
6447
6448 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6449 PEER_FLAG_EXTENDED_OPT_PARAMS);
6450 }
6451
6452 DEFUN(no_neighbor_extended_optional_parameters,
6453 no_neighbor_extended_optional_parameters_cmd,
6454 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6455 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6456 "Force the extended optional parameters format for OPEN messages\n")
6457 {
6458 int idx_peer = 2;
6459
6460 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6461 PEER_FLAG_EXTENDED_OPT_PARAMS);
6462 }
6463
6464 /* enforce-first-as */
6465 DEFUN (neighbor_enforce_first_as,
6466 neighbor_enforce_first_as_cmd,
6467 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6468 NEIGHBOR_STR
6469 NEIGHBOR_ADDR_STR2
6470 "Enforce the first AS for EBGP routes\n")
6471 {
6472 int idx_peer = 1;
6473
6474 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6475 PEER_FLAG_ENFORCE_FIRST_AS);
6476 }
6477
6478 DEFUN (no_neighbor_enforce_first_as,
6479 no_neighbor_enforce_first_as_cmd,
6480 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6481 NO_STR
6482 NEIGHBOR_STR
6483 NEIGHBOR_ADDR_STR2
6484 "Enforce the first AS for EBGP routes\n")
6485 {
6486 int idx_peer = 2;
6487
6488 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6489 PEER_FLAG_ENFORCE_FIRST_AS);
6490 }
6491
6492
6493 DEFUN (neighbor_description,
6494 neighbor_description_cmd,
6495 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6496 NEIGHBOR_STR
6497 NEIGHBOR_ADDR_STR2
6498 "Neighbor specific description\n"
6499 "Up to 80 characters describing this neighbor\n")
6500 {
6501 int idx_peer = 1;
6502 int idx_line = 3;
6503 struct peer *peer;
6504 char *str;
6505
6506 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6507 if (!peer)
6508 return CMD_WARNING_CONFIG_FAILED;
6509
6510 str = argv_concat(argv, argc, idx_line);
6511
6512 peer_description_set(peer, str);
6513
6514 XFREE(MTYPE_TMP, str);
6515
6516 return CMD_SUCCESS;
6517 }
6518
6519 DEFUN (no_neighbor_description,
6520 no_neighbor_description_cmd,
6521 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6522 NO_STR
6523 NEIGHBOR_STR
6524 NEIGHBOR_ADDR_STR2
6525 "Neighbor specific description\n")
6526 {
6527 int idx_peer = 2;
6528 struct peer *peer;
6529
6530 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6531 if (!peer)
6532 return CMD_WARNING_CONFIG_FAILED;
6533
6534 peer_description_unset(peer);
6535
6536 return CMD_SUCCESS;
6537 }
6538
6539 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6540 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6541 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6542 "Neighbor specific description\n"
6543 "Up to 80 characters describing this neighbor\n")
6544
6545 /* Neighbor update-source. */
6546 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6547 const char *source_str)
6548 {
6549 struct peer *peer;
6550 struct prefix p;
6551 union sockunion su;
6552
6553 peer = peer_and_group_lookup_vty(vty, peer_str);
6554 if (!peer)
6555 return CMD_WARNING_CONFIG_FAILED;
6556
6557 if (peer->conf_if)
6558 return CMD_WARNING;
6559
6560 if (source_str) {
6561 if (str2sockunion(source_str, &su) == 0)
6562 peer_update_source_addr_set(peer, &su);
6563 else {
6564 if (str2prefix(source_str, &p)) {
6565 vty_out(vty,
6566 "%% Invalid update-source, remove prefix length \n");
6567 return CMD_WARNING_CONFIG_FAILED;
6568 } else
6569 peer_update_source_if_set(peer, source_str);
6570 }
6571 } else
6572 peer_update_source_unset(peer);
6573
6574 return CMD_SUCCESS;
6575 }
6576
6577 #define BGP_UPDATE_SOURCE_HELP_STR \
6578 "IPv4 address\n" \
6579 "IPv6 address\n" \
6580 "Interface name (requires zebra to be running)\n"
6581
6582 DEFUN (neighbor_update_source,
6583 neighbor_update_source_cmd,
6584 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6585 NEIGHBOR_STR
6586 NEIGHBOR_ADDR_STR2
6587 "Source of routing updates\n"
6588 BGP_UPDATE_SOURCE_HELP_STR)
6589 {
6590 int idx_peer = 1;
6591 int idx_peer_2 = 3;
6592 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6593 argv[idx_peer_2]->arg);
6594 }
6595
6596 DEFUN (no_neighbor_update_source,
6597 no_neighbor_update_source_cmd,
6598 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6599 NO_STR
6600 NEIGHBOR_STR
6601 NEIGHBOR_ADDR_STR2
6602 "Source of routing updates\n"
6603 BGP_UPDATE_SOURCE_HELP_STR)
6604 {
6605 int idx_peer = 2;
6606 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6607 }
6608
6609 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6610 afi_t afi, safi_t safi,
6611 const char *rmap, int set)
6612 {
6613 int ret;
6614 struct peer *peer;
6615 struct route_map *route_map = NULL;
6616
6617 peer = peer_and_group_lookup_vty(vty, peer_str);
6618 if (!peer)
6619 return CMD_WARNING_CONFIG_FAILED;
6620
6621 if (set) {
6622 if (rmap)
6623 route_map = route_map_lookup_warn_noexist(vty, rmap);
6624 ret = peer_default_originate_set(peer, afi, safi,
6625 rmap, route_map);
6626 } else
6627 ret = peer_default_originate_unset(peer, afi, safi);
6628
6629 return bgp_vty_return(vty, ret);
6630 }
6631
6632 /* neighbor default-originate. */
6633 DEFUN (neighbor_default_originate,
6634 neighbor_default_originate_cmd,
6635 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6636 NEIGHBOR_STR
6637 NEIGHBOR_ADDR_STR2
6638 "Originate default route to this neighbor\n")
6639 {
6640 int idx_peer = 1;
6641 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6642 bgp_node_afi(vty),
6643 bgp_node_safi(vty), NULL, 1);
6644 }
6645
6646 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6647 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6648 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6649 "Originate default route to this neighbor\n")
6650
6651 DEFUN (neighbor_default_originate_rmap,
6652 neighbor_default_originate_rmap_cmd,
6653 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6654 NEIGHBOR_STR
6655 NEIGHBOR_ADDR_STR2
6656 "Originate default route to this neighbor\n"
6657 "Route-map to specify criteria to originate default\n"
6658 "route-map name\n")
6659 {
6660 int idx_peer = 1;
6661 int idx_word = 4;
6662 return peer_default_originate_set_vty(
6663 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6664 argv[idx_word]->arg, 1);
6665 }
6666
6667 ALIAS_HIDDEN(
6668 neighbor_default_originate_rmap,
6669 neighbor_default_originate_rmap_hidden_cmd,
6670 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6671 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6672 "Originate default route to this neighbor\n"
6673 "Route-map to specify criteria to originate default\n"
6674 "route-map name\n")
6675
6676 DEFUN (no_neighbor_default_originate,
6677 no_neighbor_default_originate_cmd,
6678 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6679 NO_STR
6680 NEIGHBOR_STR
6681 NEIGHBOR_ADDR_STR2
6682 "Originate default route to this neighbor\n"
6683 "Route-map to specify criteria to originate default\n"
6684 "route-map name\n")
6685 {
6686 int idx_peer = 2;
6687 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6688 bgp_node_afi(vty),
6689 bgp_node_safi(vty), NULL, 0);
6690 }
6691
6692 ALIAS_HIDDEN(
6693 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6694 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6695 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6696 "Originate default route to this neighbor\n"
6697 "Route-map to specify criteria to originate default\n"
6698 "route-map name\n")
6699
6700
6701 /* Set neighbor's BGP port. */
6702 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6703 const char *port_str)
6704 {
6705 struct peer *peer;
6706 uint16_t port;
6707 struct servent *sp;
6708
6709 peer = peer_lookup_vty(vty, ip_str);
6710 if (!peer)
6711 return CMD_WARNING_CONFIG_FAILED;
6712
6713 if (!port_str) {
6714 sp = getservbyname("bgp", "tcp");
6715 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6716 } else {
6717 port = strtoul(port_str, NULL, 10);
6718 }
6719
6720 peer_port_set(peer, port);
6721
6722 return CMD_SUCCESS;
6723 }
6724
6725 /* Set specified peer's BGP port. */
6726 DEFUN (neighbor_port,
6727 neighbor_port_cmd,
6728 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6729 NEIGHBOR_STR
6730 NEIGHBOR_ADDR_STR
6731 "Neighbor's BGP port\n"
6732 "TCP port number\n")
6733 {
6734 int idx_ip = 1;
6735 int idx_number = 3;
6736 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6737 argv[idx_number]->arg);
6738 }
6739
6740 DEFUN (no_neighbor_port,
6741 no_neighbor_port_cmd,
6742 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6743 NO_STR
6744 NEIGHBOR_STR
6745 NEIGHBOR_ADDR_STR
6746 "Neighbor's BGP port\n"
6747 "TCP port number\n")
6748 {
6749 int idx_ip = 2;
6750 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6751 }
6752
6753
6754 /* neighbor weight. */
6755 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6756 safi_t safi, const char *weight_str)
6757 {
6758 int ret;
6759 struct peer *peer;
6760 unsigned long weight;
6761
6762 peer = peer_and_group_lookup_vty(vty, ip_str);
6763 if (!peer)
6764 return CMD_WARNING_CONFIG_FAILED;
6765
6766 weight = strtoul(weight_str, NULL, 10);
6767
6768 ret = peer_weight_set(peer, afi, safi, weight);
6769 return bgp_vty_return(vty, ret);
6770 }
6771
6772 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6773 safi_t safi)
6774 {
6775 int ret;
6776 struct peer *peer;
6777
6778 peer = peer_and_group_lookup_vty(vty, ip_str);
6779 if (!peer)
6780 return CMD_WARNING_CONFIG_FAILED;
6781
6782 ret = peer_weight_unset(peer, afi, safi);
6783 return bgp_vty_return(vty, ret);
6784 }
6785
6786 DEFUN (neighbor_weight,
6787 neighbor_weight_cmd,
6788 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6789 NEIGHBOR_STR
6790 NEIGHBOR_ADDR_STR2
6791 "Set default weight for routes from this neighbor\n"
6792 "default weight\n")
6793 {
6794 int idx_peer = 1;
6795 int idx_number = 3;
6796 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6797 bgp_node_safi(vty), argv[idx_number]->arg);
6798 }
6799
6800 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6801 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6803 "Set default weight for routes from this neighbor\n"
6804 "default weight\n")
6805
6806 DEFUN (no_neighbor_weight,
6807 no_neighbor_weight_cmd,
6808 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6809 NO_STR
6810 NEIGHBOR_STR
6811 NEIGHBOR_ADDR_STR2
6812 "Set default weight for routes from this neighbor\n"
6813 "default weight\n")
6814 {
6815 int idx_peer = 2;
6816 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6817 bgp_node_afi(vty), bgp_node_safi(vty));
6818 }
6819
6820 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6821 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6822 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6823 "Set default weight for routes from this neighbor\n"
6824 "default weight\n")
6825
6826
6827 /* Override capability negotiation. */
6828 DEFUN (neighbor_override_capability,
6829 neighbor_override_capability_cmd,
6830 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6831 NEIGHBOR_STR
6832 NEIGHBOR_ADDR_STR2
6833 "Override capability negotiation result\n")
6834 {
6835 int idx_peer = 1;
6836 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6837 PEER_FLAG_OVERRIDE_CAPABILITY);
6838 }
6839
6840 DEFUN (no_neighbor_override_capability,
6841 no_neighbor_override_capability_cmd,
6842 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6843 NO_STR
6844 NEIGHBOR_STR
6845 NEIGHBOR_ADDR_STR2
6846 "Override capability negotiation result\n")
6847 {
6848 int idx_peer = 2;
6849 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6850 PEER_FLAG_OVERRIDE_CAPABILITY);
6851 }
6852
6853 DEFUN (neighbor_strict_capability,
6854 neighbor_strict_capability_cmd,
6855 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6856 NEIGHBOR_STR
6857 NEIGHBOR_ADDR_STR2
6858 "Strict capability negotiation match\n")
6859 {
6860 int idx_peer = 1;
6861
6862 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6863 PEER_FLAG_STRICT_CAP_MATCH);
6864 }
6865
6866 DEFUN (no_neighbor_strict_capability,
6867 no_neighbor_strict_capability_cmd,
6868 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6869 NO_STR
6870 NEIGHBOR_STR
6871 NEIGHBOR_ADDR_STR2
6872 "Strict capability negotiation match\n")
6873 {
6874 int idx_peer = 2;
6875
6876 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6877 PEER_FLAG_STRICT_CAP_MATCH);
6878 }
6879
6880 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6881 const char *keep_str, const char *hold_str)
6882 {
6883 int ret;
6884 struct peer *peer;
6885 uint32_t keepalive;
6886 uint32_t holdtime;
6887
6888 peer = peer_and_group_lookup_vty(vty, ip_str);
6889 if (!peer)
6890 return CMD_WARNING_CONFIG_FAILED;
6891
6892 keepalive = strtoul(keep_str, NULL, 10);
6893 holdtime = strtoul(hold_str, NULL, 10);
6894
6895 ret = peer_timers_set(peer, keepalive, holdtime);
6896
6897 return bgp_vty_return(vty, ret);
6898 }
6899
6900 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
6901 {
6902 int ret;
6903 struct peer *peer;
6904
6905 peer = peer_and_group_lookup_vty(vty, ip_str);
6906 if (!peer)
6907 return CMD_WARNING_CONFIG_FAILED;
6908
6909 ret = peer_timers_unset(peer);
6910
6911 return bgp_vty_return(vty, ret);
6912 }
6913
6914 DEFUN (neighbor_timers,
6915 neighbor_timers_cmd,
6916 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6917 NEIGHBOR_STR
6918 NEIGHBOR_ADDR_STR2
6919 "BGP per neighbor timers\n"
6920 "Keepalive interval\n"
6921 "Holdtime\n")
6922 {
6923 int idx_peer = 1;
6924 int idx_number = 3;
6925 int idx_number_2 = 4;
6926 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6927 argv[idx_number]->arg,
6928 argv[idx_number_2]->arg);
6929 }
6930
6931 DEFUN (no_neighbor_timers,
6932 no_neighbor_timers_cmd,
6933 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6934 NO_STR
6935 NEIGHBOR_STR
6936 NEIGHBOR_ADDR_STR2
6937 "BGP per neighbor timers\n"
6938 "Keepalive interval\n"
6939 "Holdtime\n")
6940 {
6941 int idx_peer = 2;
6942 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6943 }
6944
6945
6946 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6947 const char *time_str)
6948 {
6949 int ret;
6950 struct peer *peer;
6951 uint32_t connect;
6952
6953 peer = peer_and_group_lookup_vty(vty, ip_str);
6954 if (!peer)
6955 return CMD_WARNING_CONFIG_FAILED;
6956
6957 connect = strtoul(time_str, NULL, 10);
6958
6959 ret = peer_timers_connect_set(peer, connect);
6960
6961 return bgp_vty_return(vty, ret);
6962 }
6963
6964 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
6965 {
6966 int ret;
6967 struct peer *peer;
6968
6969 peer = peer_and_group_lookup_vty(vty, ip_str);
6970 if (!peer)
6971 return CMD_WARNING_CONFIG_FAILED;
6972
6973 ret = peer_timers_connect_unset(peer);
6974
6975 return bgp_vty_return(vty, ret);
6976 }
6977
6978 DEFUN (neighbor_timers_connect,
6979 neighbor_timers_connect_cmd,
6980 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6981 NEIGHBOR_STR
6982 NEIGHBOR_ADDR_STR2
6983 "BGP per neighbor timers\n"
6984 "BGP connect timer\n"
6985 "Connect timer\n")
6986 {
6987 int idx_peer = 1;
6988 int idx_number = 4;
6989 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6990 argv[idx_number]->arg);
6991 }
6992
6993 DEFUN (no_neighbor_timers_connect,
6994 no_neighbor_timers_connect_cmd,
6995 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6996 NO_STR
6997 NEIGHBOR_STR
6998 NEIGHBOR_ADDR_STR2
6999 "BGP per neighbor timers\n"
7000 "BGP connect timer\n"
7001 "Connect timer\n")
7002 {
7003 int idx_peer = 2;
7004 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7005 }
7006
7007 DEFPY (neighbor_timers_delayopen,
7008 neighbor_timers_delayopen_cmd,
7009 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7010 NEIGHBOR_STR
7011 NEIGHBOR_ADDR_STR2
7012 "BGP per neighbor timers\n"
7013 "RFC 4271 DelayOpenTimer\n"
7014 "DelayOpenTime timer interval\n")
7015 {
7016 struct peer *peer;
7017
7018 peer = peer_and_group_lookup_vty(vty, neighbor);
7019 if (!peer)
7020 return CMD_WARNING_CONFIG_FAILED;
7021
7022 if (!interval) {
7023 if (peer_timers_delayopen_unset(peer))
7024 return CMD_WARNING_CONFIG_FAILED;
7025 } else {
7026 if (peer_timers_delayopen_set(peer, interval))
7027 return CMD_WARNING_CONFIG_FAILED;
7028 }
7029
7030 return CMD_SUCCESS;
7031 }
7032
7033 DEFPY (no_neighbor_timers_delayopen,
7034 no_neighbor_timers_delayopen_cmd,
7035 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7036 NO_STR
7037 NEIGHBOR_STR
7038 NEIGHBOR_ADDR_STR2
7039 "BGP per neighbor timers\n"
7040 "RFC 4271 DelayOpenTimer\n"
7041 "DelayOpenTime timer interval\n")
7042 {
7043 struct peer *peer;
7044
7045 peer = peer_and_group_lookup_vty(vty, neighbor);
7046 if (!peer)
7047 return CMD_WARNING_CONFIG_FAILED;
7048
7049 if (peer_timers_delayopen_unset(peer))
7050 return CMD_WARNING_CONFIG_FAILED;
7051
7052 return CMD_SUCCESS;
7053 }
7054
7055 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7056 const char *time_str, int set)
7057 {
7058 int ret;
7059 struct peer *peer;
7060 uint32_t routeadv = 0;
7061
7062 peer = peer_and_group_lookup_vty(vty, ip_str);
7063 if (!peer)
7064 return CMD_WARNING_CONFIG_FAILED;
7065
7066 if (time_str)
7067 routeadv = strtoul(time_str, NULL, 10);
7068
7069 if (set)
7070 ret = peer_advertise_interval_set(peer, routeadv);
7071 else
7072 ret = peer_advertise_interval_unset(peer);
7073
7074 return bgp_vty_return(vty, ret);
7075 }
7076
7077 DEFUN (neighbor_advertise_interval,
7078 neighbor_advertise_interval_cmd,
7079 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7080 NEIGHBOR_STR
7081 NEIGHBOR_ADDR_STR2
7082 "Minimum interval between sending BGP routing updates\n"
7083 "time in seconds\n")
7084 {
7085 int idx_peer = 1;
7086 int idx_number = 3;
7087 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7088 argv[idx_number]->arg, 1);
7089 }
7090
7091 DEFUN (no_neighbor_advertise_interval,
7092 no_neighbor_advertise_interval_cmd,
7093 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7094 NO_STR
7095 NEIGHBOR_STR
7096 NEIGHBOR_ADDR_STR2
7097 "Minimum interval between sending BGP routing updates\n"
7098 "time in seconds\n")
7099 {
7100 int idx_peer = 2;
7101 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7102 }
7103
7104
7105 /* Time to wait before processing route-map updates */
7106 DEFUN (bgp_set_route_map_delay_timer,
7107 bgp_set_route_map_delay_timer_cmd,
7108 "bgp route-map delay-timer (0-600)",
7109 SET_STR
7110 "BGP route-map delay timer\n"
7111 "Time in secs to wait before processing route-map changes\n"
7112 "0 disables the timer, no route updates happen when route-maps change\n")
7113 {
7114 int idx_number = 3;
7115 uint32_t rmap_delay_timer;
7116
7117 if (argv[idx_number]->arg) {
7118 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7119 bm->rmap_update_timer = rmap_delay_timer;
7120
7121 /* if the dynamic update handling is being disabled, and a timer
7122 * is
7123 * running, stop the timer and act as if the timer has already
7124 * fired.
7125 */
7126 if (!rmap_delay_timer && bm->t_rmap_update) {
7127 BGP_TIMER_OFF(bm->t_rmap_update);
7128 thread_execute(bm->master, bgp_route_map_update_timer,
7129 NULL, 0);
7130 }
7131 return CMD_SUCCESS;
7132 } else {
7133 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7134 return CMD_WARNING_CONFIG_FAILED;
7135 }
7136 }
7137
7138 DEFUN (no_bgp_set_route_map_delay_timer,
7139 no_bgp_set_route_map_delay_timer_cmd,
7140 "no bgp route-map delay-timer [(0-600)]",
7141 NO_STR
7142 BGP_STR
7143 "Default BGP route-map delay timer\n"
7144 "Reset to default time to wait for processing route-map changes\n"
7145 "0 disables the timer, no route updates happen when route-maps change\n")
7146 {
7147
7148 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7149
7150 return CMD_SUCCESS;
7151 }
7152
7153 /* neighbor interface */
7154 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7155 const char *str)
7156 {
7157 struct peer *peer;
7158
7159 peer = peer_lookup_vty(vty, ip_str);
7160 if (!peer || peer->conf_if) {
7161 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7162 return CMD_WARNING_CONFIG_FAILED;
7163 }
7164
7165 if (str)
7166 peer_interface_set(peer, str);
7167 else
7168 peer_interface_unset(peer);
7169
7170 return CMD_SUCCESS;
7171 }
7172
7173 DEFUN (neighbor_interface,
7174 neighbor_interface_cmd,
7175 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7176 NEIGHBOR_STR
7177 NEIGHBOR_ADDR_STR
7178 "Interface\n"
7179 "Interface name\n")
7180 {
7181 int idx_ip = 1;
7182 int idx_word = 3;
7183
7184 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7185 }
7186
7187 DEFUN (no_neighbor_interface,
7188 no_neighbor_interface_cmd,
7189 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7190 NO_STR
7191 NEIGHBOR_STR
7192 NEIGHBOR_ADDR_STR
7193 "Interface\n"
7194 "Interface name\n")
7195 {
7196 int idx_peer = 2;
7197
7198 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7199 }
7200
7201 DEFUN (neighbor_distribute_list,
7202 neighbor_distribute_list_cmd,
7203 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7204 NEIGHBOR_STR
7205 NEIGHBOR_ADDR_STR2
7206 "Filter updates to/from this neighbor\n"
7207 "IP Access-list name\n"
7208 "Filter incoming updates\n"
7209 "Filter outgoing updates\n")
7210 {
7211 int idx_peer = 1;
7212 int idx_acl = 3;
7213 int direct, ret;
7214 struct peer *peer;
7215
7216 const char *pstr = argv[idx_peer]->arg;
7217 const char *acl = argv[idx_acl]->arg;
7218 const char *inout = argv[argc - 1]->text;
7219
7220 peer = peer_and_group_lookup_vty(vty, pstr);
7221 if (!peer)
7222 return CMD_WARNING_CONFIG_FAILED;
7223
7224 /* Check filter direction. */
7225 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7226 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7227 direct, acl);
7228
7229 return bgp_vty_return(vty, ret);
7230 }
7231
7232 ALIAS_HIDDEN(
7233 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7234 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7235 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7236 "Filter updates to/from this neighbor\n"
7237 "IP Access-list name\n"
7238 "Filter incoming updates\n"
7239 "Filter outgoing updates\n")
7240
7241 DEFUN (no_neighbor_distribute_list,
7242 no_neighbor_distribute_list_cmd,
7243 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7244 NO_STR
7245 NEIGHBOR_STR
7246 NEIGHBOR_ADDR_STR2
7247 "Filter updates to/from this neighbor\n"
7248 "IP Access-list name\n"
7249 "Filter incoming updates\n"
7250 "Filter outgoing updates\n")
7251 {
7252 int idx_peer = 2;
7253 int direct, ret;
7254 struct peer *peer;
7255
7256 const char *pstr = argv[idx_peer]->arg;
7257 const char *inout = argv[argc - 1]->text;
7258
7259 peer = peer_and_group_lookup_vty(vty, pstr);
7260 if (!peer)
7261 return CMD_WARNING_CONFIG_FAILED;
7262
7263 /* Check filter direction. */
7264 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7265 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7266 direct);
7267
7268 return bgp_vty_return(vty, ret);
7269 }
7270
7271 ALIAS_HIDDEN(
7272 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7273 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7274 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7275 "Filter updates to/from this neighbor\n"
7276 "IP Access-list name\n"
7277 "Filter incoming updates\n"
7278 "Filter outgoing updates\n")
7279
7280 /* Set prefix list to the peer. */
7281 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7282 afi_t afi, safi_t safi,
7283 const char *name_str,
7284 const char *direct_str)
7285 {
7286 int ret;
7287 int direct = FILTER_IN;
7288 struct peer *peer;
7289
7290 peer = peer_and_group_lookup_vty(vty, ip_str);
7291 if (!peer)
7292 return CMD_WARNING_CONFIG_FAILED;
7293
7294 /* Check filter direction. */
7295 if (strncmp(direct_str, "i", 1) == 0)
7296 direct = FILTER_IN;
7297 else if (strncmp(direct_str, "o", 1) == 0)
7298 direct = FILTER_OUT;
7299
7300 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7301
7302 return bgp_vty_return(vty, ret);
7303 }
7304
7305 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7306 afi_t afi, safi_t safi,
7307 const char *direct_str)
7308 {
7309 int ret;
7310 struct peer *peer;
7311 int direct = FILTER_IN;
7312
7313 peer = peer_and_group_lookup_vty(vty, ip_str);
7314 if (!peer)
7315 return CMD_WARNING_CONFIG_FAILED;
7316
7317 /* Check filter direction. */
7318 if (strncmp(direct_str, "i", 1) == 0)
7319 direct = FILTER_IN;
7320 else if (strncmp(direct_str, "o", 1) == 0)
7321 direct = FILTER_OUT;
7322
7323 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7324
7325 return bgp_vty_return(vty, ret);
7326 }
7327
7328 DEFUN (neighbor_prefix_list,
7329 neighbor_prefix_list_cmd,
7330 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7331 NEIGHBOR_STR
7332 NEIGHBOR_ADDR_STR2
7333 "Filter updates to/from this neighbor\n"
7334 "Name of a prefix list\n"
7335 "Filter incoming updates\n"
7336 "Filter outgoing updates\n")
7337 {
7338 int idx_peer = 1;
7339 int idx_word = 3;
7340 int idx_in_out = 4;
7341 return peer_prefix_list_set_vty(
7342 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7343 argv[idx_word]->arg, argv[idx_in_out]->arg);
7344 }
7345
7346 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7347 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7348 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7349 "Filter updates to/from this neighbor\n"
7350 "Name of a prefix list\n"
7351 "Filter incoming updates\n"
7352 "Filter outgoing updates\n")
7353
7354 DEFUN (no_neighbor_prefix_list,
7355 no_neighbor_prefix_list_cmd,
7356 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7357 NO_STR
7358 NEIGHBOR_STR
7359 NEIGHBOR_ADDR_STR2
7360 "Filter updates to/from this neighbor\n"
7361 "Name of a prefix list\n"
7362 "Filter incoming updates\n"
7363 "Filter outgoing updates\n")
7364 {
7365 int idx_peer = 2;
7366 int idx_in_out = 5;
7367 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7368 bgp_node_afi(vty), bgp_node_safi(vty),
7369 argv[idx_in_out]->arg);
7370 }
7371
7372 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7373 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7374 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7375 "Filter updates to/from this neighbor\n"
7376 "Name of a prefix list\n"
7377 "Filter incoming updates\n"
7378 "Filter outgoing updates\n")
7379
7380 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7381 safi_t safi, const char *name_str,
7382 const char *direct_str)
7383 {
7384 int ret;
7385 struct peer *peer;
7386 int direct = FILTER_IN;
7387
7388 peer = peer_and_group_lookup_vty(vty, ip_str);
7389 if (!peer)
7390 return CMD_WARNING_CONFIG_FAILED;
7391
7392 /* Check filter direction. */
7393 if (strncmp(direct_str, "i", 1) == 0)
7394 direct = FILTER_IN;
7395 else if (strncmp(direct_str, "o", 1) == 0)
7396 direct = FILTER_OUT;
7397
7398 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7399
7400 return bgp_vty_return(vty, ret);
7401 }
7402
7403 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7404 safi_t safi, const char *direct_str)
7405 {
7406 int ret;
7407 struct peer *peer;
7408 int direct = FILTER_IN;
7409
7410 peer = peer_and_group_lookup_vty(vty, ip_str);
7411 if (!peer)
7412 return CMD_WARNING_CONFIG_FAILED;
7413
7414 /* Check filter direction. */
7415 if (strncmp(direct_str, "i", 1) == 0)
7416 direct = FILTER_IN;
7417 else if (strncmp(direct_str, "o", 1) == 0)
7418 direct = FILTER_OUT;
7419
7420 ret = peer_aslist_unset(peer, afi, safi, direct);
7421
7422 return bgp_vty_return(vty, ret);
7423 }
7424
7425 DEFUN (neighbor_filter_list,
7426 neighbor_filter_list_cmd,
7427 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7428 NEIGHBOR_STR
7429 NEIGHBOR_ADDR_STR2
7430 "Establish BGP filters\n"
7431 "AS path access-list name\n"
7432 "Filter incoming routes\n"
7433 "Filter outgoing routes\n")
7434 {
7435 int idx_peer = 1;
7436 int idx_word = 3;
7437 int idx_in_out = 4;
7438 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7439 bgp_node_safi(vty), argv[idx_word]->arg,
7440 argv[idx_in_out]->arg);
7441 }
7442
7443 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7444 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7445 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7446 "Establish BGP filters\n"
7447 "AS path access-list name\n"
7448 "Filter incoming routes\n"
7449 "Filter outgoing routes\n")
7450
7451 DEFUN (no_neighbor_filter_list,
7452 no_neighbor_filter_list_cmd,
7453 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7454 NO_STR
7455 NEIGHBOR_STR
7456 NEIGHBOR_ADDR_STR2
7457 "Establish BGP filters\n"
7458 "AS path access-list name\n"
7459 "Filter incoming routes\n"
7460 "Filter outgoing routes\n")
7461 {
7462 int idx_peer = 2;
7463 int idx_in_out = 5;
7464 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7465 bgp_node_afi(vty), bgp_node_safi(vty),
7466 argv[idx_in_out]->arg);
7467 }
7468
7469 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7470 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7471 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7472 "Establish BGP filters\n"
7473 "AS path access-list name\n"
7474 "Filter incoming routes\n"
7475 "Filter outgoing routes\n")
7476
7477 /* Set advertise-map to the peer. */
7478 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7479 afi_t afi, safi_t safi,
7480 const char *advertise_str,
7481 const char *condition_str, bool condition,
7482 bool set)
7483 {
7484 int ret = CMD_WARNING_CONFIG_FAILED;
7485 struct peer *peer;
7486 struct route_map *advertise_map;
7487 struct route_map *condition_map;
7488
7489 peer = peer_and_group_lookup_vty(vty, ip_str);
7490 if (!peer)
7491 return ret;
7492
7493 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7494 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7495
7496 if (set)
7497 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7498 advertise_map, condition_str,
7499 condition_map, condition);
7500 else
7501 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7502 advertise_map, condition_str,
7503 condition_map, condition);
7504
7505 return bgp_vty_return(vty, ret);
7506 }
7507
7508 DEFPY (bgp_condadv_period,
7509 bgp_condadv_period_cmd,
7510 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7511 NO_STR
7512 BGP_STR
7513 "Conditional advertisement settings\n"
7514 "Set period to rescan BGP table to check if condition is met\n"
7515 "Period between BGP table scans, in seconds; default 60\n")
7516 {
7517 VTY_DECLVAR_CONTEXT(bgp, bgp);
7518
7519 bgp->condition_check_period =
7520 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7521
7522 return CMD_SUCCESS;
7523 }
7524
7525 DEFPY (neighbor_advertise_map,
7526 neighbor_advertise_map_cmd,
7527 "[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",
7528 NO_STR
7529 NEIGHBOR_STR
7530 NEIGHBOR_ADDR_STR2
7531 "Route-map to conditionally advertise routes\n"
7532 "Name of advertise map\n"
7533 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7534 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7535 "Name of the exist or non exist map\n")
7536 {
7537 bool condition = CONDITION_EXIST;
7538
7539 if (!strcmp(exist, "non-exist-map"))
7540 condition = CONDITION_NON_EXIST;
7541
7542 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7543 bgp_node_safi(vty), advertise_str,
7544 condition_str, condition, !no);
7545 }
7546
7547 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7548 "[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",
7549 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7550 "Route-map to conditionally advertise routes\n"
7551 "Name of advertise map\n"
7552 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7553 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7554 "Name of the exist or non exist map\n")
7555
7556 /* Set route-map to the peer. */
7557 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7558 afi_t afi, safi_t safi, const char *name_str,
7559 const char *direct_str)
7560 {
7561 int ret;
7562 struct peer *peer;
7563 int direct = RMAP_IN;
7564 struct route_map *route_map;
7565
7566 peer = peer_and_group_lookup_vty(vty, ip_str);
7567 if (!peer)
7568 return CMD_WARNING_CONFIG_FAILED;
7569
7570 /* Check filter direction. */
7571 if (strncmp(direct_str, "in", 2) == 0)
7572 direct = RMAP_IN;
7573 else if (strncmp(direct_str, "o", 1) == 0)
7574 direct = RMAP_OUT;
7575
7576 route_map = route_map_lookup_warn_noexist(vty, name_str);
7577 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7578
7579 return bgp_vty_return(vty, ret);
7580 }
7581
7582 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7583 afi_t afi, safi_t safi,
7584 const char *direct_str)
7585 {
7586 int ret;
7587 struct peer *peer;
7588 int direct = RMAP_IN;
7589
7590 peer = peer_and_group_lookup_vty(vty, ip_str);
7591 if (!peer)
7592 return CMD_WARNING_CONFIG_FAILED;
7593
7594 /* Check filter direction. */
7595 if (strncmp(direct_str, "in", 2) == 0)
7596 direct = RMAP_IN;
7597 else if (strncmp(direct_str, "o", 1) == 0)
7598 direct = RMAP_OUT;
7599
7600 ret = peer_route_map_unset(peer, afi, safi, direct);
7601
7602 return bgp_vty_return(vty, ret);
7603 }
7604
7605 DEFUN (neighbor_route_map,
7606 neighbor_route_map_cmd,
7607 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7608 NEIGHBOR_STR
7609 NEIGHBOR_ADDR_STR2
7610 "Apply route map to neighbor\n"
7611 "Name of route map\n"
7612 "Apply map to incoming routes\n"
7613 "Apply map to outbound routes\n")
7614 {
7615 int idx_peer = 1;
7616 int idx_word = 3;
7617 int idx_in_out = 4;
7618 return peer_route_map_set_vty(
7619 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7620 argv[idx_word]->arg, argv[idx_in_out]->arg);
7621 }
7622
7623 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7624 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7625 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7626 "Apply route map to neighbor\n"
7627 "Name of route map\n"
7628 "Apply map to incoming routes\n"
7629 "Apply map to outbound routes\n")
7630
7631 DEFUN (no_neighbor_route_map,
7632 no_neighbor_route_map_cmd,
7633 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7634 NO_STR
7635 NEIGHBOR_STR
7636 NEIGHBOR_ADDR_STR2
7637 "Apply route map to neighbor\n"
7638 "Name of route map\n"
7639 "Apply map to incoming routes\n"
7640 "Apply map to outbound routes\n")
7641 {
7642 int idx_peer = 2;
7643 int idx_in_out = 5;
7644 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7645 bgp_node_afi(vty), bgp_node_safi(vty),
7646 argv[idx_in_out]->arg);
7647 }
7648
7649 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7650 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7651 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7652 "Apply route map to neighbor\n"
7653 "Name of route map\n"
7654 "Apply map to incoming routes\n"
7655 "Apply map to outbound routes\n")
7656
7657 /* Set unsuppress-map to the peer. */
7658 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7659 afi_t afi, safi_t safi,
7660 const char *name_str)
7661 {
7662 int ret;
7663 struct peer *peer;
7664 struct route_map *route_map;
7665
7666 peer = peer_and_group_lookup_vty(vty, ip_str);
7667 if (!peer)
7668 return CMD_WARNING_CONFIG_FAILED;
7669
7670 route_map = route_map_lookup_warn_noexist(vty, name_str);
7671 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7672
7673 return bgp_vty_return(vty, ret);
7674 }
7675
7676 /* Unset route-map from the peer. */
7677 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7678 afi_t afi, safi_t safi)
7679 {
7680 int ret;
7681 struct peer *peer;
7682
7683 peer = peer_and_group_lookup_vty(vty, ip_str);
7684 if (!peer)
7685 return CMD_WARNING_CONFIG_FAILED;
7686
7687 ret = peer_unsuppress_map_unset(peer, afi, safi);
7688
7689 return bgp_vty_return(vty, ret);
7690 }
7691
7692 DEFUN (neighbor_unsuppress_map,
7693 neighbor_unsuppress_map_cmd,
7694 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7695 NEIGHBOR_STR
7696 NEIGHBOR_ADDR_STR2
7697 "Route-map to selectively unsuppress suppressed routes\n"
7698 "Name of route map\n")
7699 {
7700 int idx_peer = 1;
7701 int idx_word = 3;
7702 return peer_unsuppress_map_set_vty(
7703 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7704 argv[idx_word]->arg);
7705 }
7706
7707 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7708 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7709 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7710 "Route-map to selectively unsuppress suppressed routes\n"
7711 "Name of route map\n")
7712
7713 DEFUN (no_neighbor_unsuppress_map,
7714 no_neighbor_unsuppress_map_cmd,
7715 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7716 NO_STR
7717 NEIGHBOR_STR
7718 NEIGHBOR_ADDR_STR2
7719 "Route-map to selectively unsuppress suppressed routes\n"
7720 "Name of route map\n")
7721 {
7722 int idx_peer = 2;
7723 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7724 bgp_node_afi(vty),
7725 bgp_node_safi(vty));
7726 }
7727
7728 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7729 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7730 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7731 "Route-map to selectively unsuppress suppressed routes\n"
7732 "Name of route map\n")
7733
7734 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7735 afi_t afi, safi_t safi,
7736 const char *num_str,
7737 const char *threshold_str, int warning,
7738 const char *restart_str,
7739 const char *force_str)
7740 {
7741 int ret;
7742 struct peer *peer;
7743 uint32_t max;
7744 uint8_t threshold;
7745 uint16_t restart;
7746
7747 peer = peer_and_group_lookup_vty(vty, ip_str);
7748 if (!peer)
7749 return CMD_WARNING_CONFIG_FAILED;
7750
7751 max = strtoul(num_str, NULL, 10);
7752 if (threshold_str)
7753 threshold = atoi(threshold_str);
7754 else
7755 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7756
7757 if (restart_str)
7758 restart = atoi(restart_str);
7759 else
7760 restart = 0;
7761
7762 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7763 restart, force_str ? true : false);
7764
7765 return bgp_vty_return(vty, ret);
7766 }
7767
7768 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7769 afi_t afi, safi_t safi)
7770 {
7771 int ret;
7772 struct peer *peer;
7773
7774 peer = peer_and_group_lookup_vty(vty, ip_str);
7775 if (!peer)
7776 return CMD_WARNING_CONFIG_FAILED;
7777
7778 ret = peer_maximum_prefix_unset(peer, afi, safi);
7779
7780 return bgp_vty_return(vty, ret);
7781 }
7782
7783 /* Maximum number of prefix to be sent to the neighbor. */
7784 DEFUN(neighbor_maximum_prefix_out,
7785 neighbor_maximum_prefix_out_cmd,
7786 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7787 NEIGHBOR_STR
7788 NEIGHBOR_ADDR_STR2
7789 "Maximum number of prefixes to be sent to this peer\n"
7790 "Maximum no. of prefix limit\n")
7791 {
7792 int ret;
7793 int idx_peer = 1;
7794 int idx_number = 3;
7795 struct peer *peer;
7796 uint32_t max;
7797 afi_t afi = bgp_node_afi(vty);
7798 safi_t safi = bgp_node_safi(vty);
7799
7800 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7801 if (!peer)
7802 return CMD_WARNING_CONFIG_FAILED;
7803
7804 max = strtoul(argv[idx_number]->arg, NULL, 10);
7805
7806 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
7807
7808 return bgp_vty_return(vty, ret);
7809 }
7810
7811 DEFUN(no_neighbor_maximum_prefix_out,
7812 no_neighbor_maximum_prefix_out_cmd,
7813 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
7814 NO_STR
7815 NEIGHBOR_STR
7816 NEIGHBOR_ADDR_STR2
7817 "Maximum number of prefixes to be sent to this peer\n"
7818 "Maximum no. of prefix limit\n")
7819 {
7820 int ret;
7821 int idx_peer = 2;
7822 struct peer *peer;
7823 afi_t afi = bgp_node_afi(vty);
7824 safi_t safi = bgp_node_safi(vty);
7825
7826 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7827 if (!peer)
7828 return CMD_WARNING_CONFIG_FAILED;
7829
7830 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
7831
7832 return bgp_vty_return(vty, ret);
7833 }
7834
7835 /* Maximum number of prefix configuration. Prefix count is different
7836 for each peer configuration. So this configuration can be set for
7837 each peer configuration. */
7838 DEFUN (neighbor_maximum_prefix,
7839 neighbor_maximum_prefix_cmd,
7840 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7841 NEIGHBOR_STR
7842 NEIGHBOR_ADDR_STR2
7843 "Maximum number of prefix accept from this peer\n"
7844 "maximum no. of prefix limit\n"
7845 "Force checking all received routes not only accepted\n")
7846 {
7847 int idx_peer = 1;
7848 int idx_number = 3;
7849 int idx_force = 0;
7850 char *force = NULL;
7851
7852 if (argv_find(argv, argc, "force", &idx_force))
7853 force = argv[idx_force]->arg;
7854
7855 return peer_maximum_prefix_set_vty(
7856 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7857 argv[idx_number]->arg, NULL, 0, NULL, force);
7858 }
7859
7860 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
7861 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7862 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7863 "Maximum number of prefix accept from this peer\n"
7864 "maximum no. of prefix limit\n"
7865 "Force checking all received routes not only accepted\n")
7866
7867 DEFUN (neighbor_maximum_prefix_threshold,
7868 neighbor_maximum_prefix_threshold_cmd,
7869 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7870 NEIGHBOR_STR
7871 NEIGHBOR_ADDR_STR2
7872 "Maximum number of prefix accept from this peer\n"
7873 "maximum no. of prefix limit\n"
7874 "Threshold value (%) at which to generate a warning msg\n"
7875 "Force checking all received routes not only accepted\n")
7876 {
7877 int idx_peer = 1;
7878 int idx_number = 3;
7879 int idx_number_2 = 4;
7880 int idx_force = 0;
7881 char *force = NULL;
7882
7883 if (argv_find(argv, argc, "force", &idx_force))
7884 force = argv[idx_force]->arg;
7885
7886 return peer_maximum_prefix_set_vty(
7887 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7888 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
7889 }
7890
7891 ALIAS_HIDDEN(
7892 neighbor_maximum_prefix_threshold,
7893 neighbor_maximum_prefix_threshold_hidden_cmd,
7894 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7895 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7896 "Maximum number of prefix accept from this peer\n"
7897 "maximum no. of prefix limit\n"
7898 "Threshold value (%) at which to generate a warning msg\n"
7899 "Force checking all received routes not only accepted\n")
7900
7901 DEFUN (neighbor_maximum_prefix_warning,
7902 neighbor_maximum_prefix_warning_cmd,
7903 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7904 NEIGHBOR_STR
7905 NEIGHBOR_ADDR_STR2
7906 "Maximum number of prefix accept from this peer\n"
7907 "maximum no. of prefix limit\n"
7908 "Only give warning message when limit is exceeded\n"
7909 "Force checking all received routes not only accepted\n")
7910 {
7911 int idx_peer = 1;
7912 int idx_number = 3;
7913 int idx_force = 0;
7914 char *force = NULL;
7915
7916 if (argv_find(argv, argc, "force", &idx_force))
7917 force = argv[idx_force]->arg;
7918
7919 return peer_maximum_prefix_set_vty(
7920 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7921 argv[idx_number]->arg, NULL, 1, NULL, force);
7922 }
7923
7924 ALIAS_HIDDEN(
7925 neighbor_maximum_prefix_warning,
7926 neighbor_maximum_prefix_warning_hidden_cmd,
7927 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7929 "Maximum number of prefix accept from this peer\n"
7930 "maximum no. of prefix limit\n"
7931 "Only give warning message when limit is exceeded\n"
7932 "Force checking all received routes not only accepted\n")
7933
7934 DEFUN (neighbor_maximum_prefix_threshold_warning,
7935 neighbor_maximum_prefix_threshold_warning_cmd,
7936 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7937 NEIGHBOR_STR
7938 NEIGHBOR_ADDR_STR2
7939 "Maximum number of prefix accept from this peer\n"
7940 "maximum no. of prefix limit\n"
7941 "Threshold value (%) at which to generate a warning msg\n"
7942 "Only give warning message when limit is exceeded\n"
7943 "Force checking all received routes not only accepted\n")
7944 {
7945 int idx_peer = 1;
7946 int idx_number = 3;
7947 int idx_number_2 = 4;
7948 int idx_force = 0;
7949 char *force = NULL;
7950
7951 if (argv_find(argv, argc, "force", &idx_force))
7952 force = argv[idx_force]->arg;
7953
7954 return peer_maximum_prefix_set_vty(
7955 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7956 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
7957 }
7958
7959 ALIAS_HIDDEN(
7960 neighbor_maximum_prefix_threshold_warning,
7961 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
7962 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7963 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7964 "Maximum number of prefix accept from this peer\n"
7965 "maximum no. of prefix limit\n"
7966 "Threshold value (%) at which to generate a warning msg\n"
7967 "Only give warning message when limit is exceeded\n"
7968 "Force checking all received routes not only accepted\n")
7969
7970 DEFUN (neighbor_maximum_prefix_restart,
7971 neighbor_maximum_prefix_restart_cmd,
7972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7973 NEIGHBOR_STR
7974 NEIGHBOR_ADDR_STR2
7975 "Maximum number of prefix accept from this peer\n"
7976 "maximum no. of prefix limit\n"
7977 "Restart bgp connection after limit is exceeded\n"
7978 "Restart interval in minutes\n"
7979 "Force checking all received routes not only accepted\n")
7980 {
7981 int idx_peer = 1;
7982 int idx_number = 3;
7983 int idx_number_2 = 5;
7984 int idx_force = 0;
7985 char *force = NULL;
7986
7987 if (argv_find(argv, argc, "force", &idx_force))
7988 force = argv[idx_force]->arg;
7989
7990 return peer_maximum_prefix_set_vty(
7991 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7992 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
7993 }
7994
7995 ALIAS_HIDDEN(
7996 neighbor_maximum_prefix_restart,
7997 neighbor_maximum_prefix_restart_hidden_cmd,
7998 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7999 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8000 "Maximum number of prefix accept from this peer\n"
8001 "maximum no. of prefix limit\n"
8002 "Restart bgp connection after limit is exceeded\n"
8003 "Restart interval in minutes\n"
8004 "Force checking all received routes not only accepted\n")
8005
8006 DEFUN (neighbor_maximum_prefix_threshold_restart,
8007 neighbor_maximum_prefix_threshold_restart_cmd,
8008 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8009 NEIGHBOR_STR
8010 NEIGHBOR_ADDR_STR2
8011 "Maximum number of prefixes to accept from this peer\n"
8012 "maximum no. of prefix limit\n"
8013 "Threshold value (%) at which to generate a warning msg\n"
8014 "Restart bgp connection after limit is exceeded\n"
8015 "Restart interval in minutes\n"
8016 "Force checking all received routes not only accepted\n")
8017 {
8018 int idx_peer = 1;
8019 int idx_number = 3;
8020 int idx_number_2 = 4;
8021 int idx_number_3 = 6;
8022 int idx_force = 0;
8023 char *force = NULL;
8024
8025 if (argv_find(argv, argc, "force", &idx_force))
8026 force = argv[idx_force]->arg;
8027
8028 return peer_maximum_prefix_set_vty(
8029 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8030 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8031 argv[idx_number_3]->arg, force);
8032 }
8033
8034 ALIAS_HIDDEN(
8035 neighbor_maximum_prefix_threshold_restart,
8036 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8037 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8038 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8039 "Maximum number of prefixes to accept from this peer\n"
8040 "maximum no. of prefix limit\n"
8041 "Threshold value (%) at which to generate a warning msg\n"
8042 "Restart bgp connection after limit is exceeded\n"
8043 "Restart interval in minutes\n"
8044 "Force checking all received routes not only accepted\n")
8045
8046 DEFUN (no_neighbor_maximum_prefix,
8047 no_neighbor_maximum_prefix_cmd,
8048 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8049 NO_STR
8050 NEIGHBOR_STR
8051 NEIGHBOR_ADDR_STR2
8052 "Maximum number of prefixes to accept from this peer\n"
8053 "maximum no. of prefix limit\n"
8054 "Threshold value (%) at which to generate a warning msg\n"
8055 "Restart bgp connection after limit is exceeded\n"
8056 "Restart interval in minutes\n"
8057 "Only give warning message when limit is exceeded\n"
8058 "Force checking all received routes not only accepted\n")
8059 {
8060 int idx_peer = 2;
8061 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8062 bgp_node_afi(vty),
8063 bgp_node_safi(vty));
8064 }
8065
8066 ALIAS_HIDDEN(
8067 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8068 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8069 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8070 "Maximum number of prefixes to accept from this peer\n"
8071 "maximum no. of prefix limit\n"
8072 "Threshold value (%) at which to generate a warning msg\n"
8073 "Restart bgp connection after limit is exceeded\n"
8074 "Restart interval in minutes\n"
8075 "Only give warning message when limit is exceeded\n"
8076 "Force checking all received routes not only accepted\n")
8077
8078
8079 /* "neighbor allowas-in" */
8080 DEFUN (neighbor_allowas_in,
8081 neighbor_allowas_in_cmd,
8082 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8083 NEIGHBOR_STR
8084 NEIGHBOR_ADDR_STR2
8085 "Accept as-path with my AS present in it\n"
8086 "Number of occurrences of AS number\n"
8087 "Only accept my AS in the as-path if the route was originated in my AS\n")
8088 {
8089 int idx_peer = 1;
8090 int idx_number_origin = 3;
8091 int ret;
8092 int origin = 0;
8093 struct peer *peer;
8094 int allow_num = 0;
8095
8096 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8097 if (!peer)
8098 return CMD_WARNING_CONFIG_FAILED;
8099
8100 if (argc <= idx_number_origin)
8101 allow_num = 3;
8102 else {
8103 if (argv[idx_number_origin]->type == WORD_TKN)
8104 origin = 1;
8105 else
8106 allow_num = atoi(argv[idx_number_origin]->arg);
8107 }
8108
8109 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8110 allow_num, origin);
8111
8112 return bgp_vty_return(vty, ret);
8113 }
8114
8115 ALIAS_HIDDEN(
8116 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8117 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8118 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8119 "Accept as-path with my AS present in it\n"
8120 "Number of occurrences of AS number\n"
8121 "Only accept my AS in the as-path if the route was originated in my AS\n")
8122
8123 DEFUN (no_neighbor_allowas_in,
8124 no_neighbor_allowas_in_cmd,
8125 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8126 NO_STR
8127 NEIGHBOR_STR
8128 NEIGHBOR_ADDR_STR2
8129 "allow local ASN appears in aspath attribute\n"
8130 "Number of occurrences of AS number\n"
8131 "Only accept my AS in the as-path if the route was originated in my AS\n")
8132 {
8133 int idx_peer = 2;
8134 int ret;
8135 struct peer *peer;
8136
8137 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8138 if (!peer)
8139 return CMD_WARNING_CONFIG_FAILED;
8140
8141 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8142 bgp_node_safi(vty));
8143
8144 return bgp_vty_return(vty, ret);
8145 }
8146
8147 ALIAS_HIDDEN(
8148 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8149 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8150 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8151 "allow local ASN appears in aspath attribute\n"
8152 "Number of occurrences of AS number\n"
8153 "Only accept my AS in the as-path if the route was originated in my AS\n")
8154
8155 DEFUN (neighbor_ttl_security,
8156 neighbor_ttl_security_cmd,
8157 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8158 NEIGHBOR_STR
8159 NEIGHBOR_ADDR_STR2
8160 "BGP ttl-security parameters\n"
8161 "Specify the maximum number of hops to the BGP peer\n"
8162 "Number of hops to BGP peer\n")
8163 {
8164 int idx_peer = 1;
8165 int idx_number = 4;
8166 struct peer *peer;
8167 int gtsm_hops;
8168
8169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8170 if (!peer)
8171 return CMD_WARNING_CONFIG_FAILED;
8172
8173 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8174
8175 /*
8176 * If 'neighbor swpX', then this is for directly connected peers,
8177 * we should not accept a ttl-security hops value greater than 1.
8178 */
8179 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8180 vty_out(vty,
8181 "%s is directly connected peer, hops cannot exceed 1\n",
8182 argv[idx_peer]->arg);
8183 return CMD_WARNING_CONFIG_FAILED;
8184 }
8185
8186 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8187 }
8188
8189 DEFUN (no_neighbor_ttl_security,
8190 no_neighbor_ttl_security_cmd,
8191 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8192 NO_STR
8193 NEIGHBOR_STR
8194 NEIGHBOR_ADDR_STR2
8195 "BGP ttl-security parameters\n"
8196 "Specify the maximum number of hops to the BGP peer\n"
8197 "Number of hops to BGP peer\n")
8198 {
8199 int idx_peer = 2;
8200 struct peer *peer;
8201
8202 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8203 if (!peer)
8204 return CMD_WARNING_CONFIG_FAILED;
8205
8206 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8207 }
8208
8209 /* disable-addpath-rx */
8210 DEFUN(neighbor_disable_addpath_rx,
8211 neighbor_disable_addpath_rx_cmd,
8212 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8213 NEIGHBOR_STR
8214 NEIGHBOR_ADDR_STR2
8215 "Do not accept additional paths\n")
8216 {
8217 char *peer_str = argv[1]->arg;
8218 struct peer *peer;
8219 afi_t afi = bgp_node_afi(vty);
8220 safi_t safi = bgp_node_safi(vty);
8221
8222 peer = peer_and_group_lookup_vty(vty, peer_str);
8223 if (!peer)
8224 return CMD_WARNING_CONFIG_FAILED;
8225
8226 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8227 PEER_FLAG_DISABLE_ADDPATH_RX);
8228 }
8229
8230 DEFUN(no_neighbor_disable_addpath_rx,
8231 no_neighbor_disable_addpath_rx_cmd,
8232 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8233 NO_STR
8234 NEIGHBOR_STR
8235 NEIGHBOR_ADDR_STR2
8236 "Do not accept additional paths\n")
8237 {
8238 char *peer_str = argv[2]->arg;
8239 struct peer *peer;
8240 afi_t afi = bgp_node_afi(vty);
8241 safi_t safi = bgp_node_safi(vty);
8242
8243 peer = peer_and_group_lookup_vty(vty, peer_str);
8244 if (!peer)
8245 return CMD_WARNING_CONFIG_FAILED;
8246
8247 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8248 PEER_FLAG_DISABLE_ADDPATH_RX);
8249 }
8250
8251 DEFUN (neighbor_addpath_tx_all_paths,
8252 neighbor_addpath_tx_all_paths_cmd,
8253 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8254 NEIGHBOR_STR
8255 NEIGHBOR_ADDR_STR2
8256 "Use addpath to advertise all paths to a neighbor\n")
8257 {
8258 int idx_peer = 1;
8259 struct peer *peer;
8260
8261 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8262 if (!peer)
8263 return CMD_WARNING_CONFIG_FAILED;
8264
8265 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8266 BGP_ADDPATH_ALL);
8267 return CMD_SUCCESS;
8268 }
8269
8270 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8271 neighbor_addpath_tx_all_paths_hidden_cmd,
8272 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8273 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8274 "Use addpath to advertise all paths to a neighbor\n")
8275
8276 DEFUN (no_neighbor_addpath_tx_all_paths,
8277 no_neighbor_addpath_tx_all_paths_cmd,
8278 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8279 NO_STR
8280 NEIGHBOR_STR
8281 NEIGHBOR_ADDR_STR2
8282 "Use addpath to advertise all paths to a neighbor\n")
8283 {
8284 int idx_peer = 2;
8285 struct peer *peer;
8286
8287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8288 if (!peer)
8289 return CMD_WARNING_CONFIG_FAILED;
8290
8291 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8292 != BGP_ADDPATH_ALL) {
8293 vty_out(vty,
8294 "%% Peer not currently configured to transmit all paths.");
8295 return CMD_WARNING_CONFIG_FAILED;
8296 }
8297
8298 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8299 BGP_ADDPATH_NONE);
8300
8301 return CMD_SUCCESS;
8302 }
8303
8304 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8305 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8306 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8308 "Use addpath to advertise all paths to a neighbor\n")
8309
8310 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8311 neighbor_addpath_tx_bestpath_per_as_cmd,
8312 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8313 NEIGHBOR_STR
8314 NEIGHBOR_ADDR_STR2
8315 "Use addpath to advertise the bestpath per each neighboring AS\n")
8316 {
8317 int idx_peer = 1;
8318 struct peer *peer;
8319
8320 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8321 if (!peer)
8322 return CMD_WARNING_CONFIG_FAILED;
8323
8324 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8325 BGP_ADDPATH_BEST_PER_AS);
8326
8327 return CMD_SUCCESS;
8328 }
8329
8330 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8331 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8332 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8334 "Use addpath to advertise the bestpath per each neighboring AS\n")
8335
8336 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8337 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8338 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8339 NO_STR
8340 NEIGHBOR_STR
8341 NEIGHBOR_ADDR_STR2
8342 "Use addpath to advertise the bestpath per each neighboring AS\n")
8343 {
8344 int idx_peer = 2;
8345 struct peer *peer;
8346
8347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8348 if (!peer)
8349 return CMD_WARNING_CONFIG_FAILED;
8350
8351 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8352 != BGP_ADDPATH_BEST_PER_AS) {
8353 vty_out(vty,
8354 "%% Peer not currently configured to transmit all best path per as.");
8355 return CMD_WARNING_CONFIG_FAILED;
8356 }
8357
8358 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8359 BGP_ADDPATH_NONE);
8360
8361 return CMD_SUCCESS;
8362 }
8363
8364 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8365 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8366 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8367 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8368 "Use addpath to advertise the bestpath per each neighboring AS\n")
8369
8370 DEFPY(
8371 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8372 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8373 NEIGHBOR_STR
8374 NEIGHBOR_ADDR_STR2
8375 "Detect AS loops before sending to neighbor\n")
8376 {
8377 struct peer *peer;
8378
8379 peer = peer_and_group_lookup_vty(vty, neighbor);
8380 if (!peer)
8381 return CMD_WARNING_CONFIG_FAILED;
8382
8383 peer->as_path_loop_detection = true;
8384
8385 return CMD_SUCCESS;
8386 }
8387
8388 DEFPY(
8389 no_neighbor_aspath_loop_detection,
8390 no_neighbor_aspath_loop_detection_cmd,
8391 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8392 NO_STR
8393 NEIGHBOR_STR
8394 NEIGHBOR_ADDR_STR2
8395 "Detect AS loops before sending to neighbor\n")
8396 {
8397 struct peer *peer;
8398
8399 peer = peer_and_group_lookup_vty(vty, neighbor);
8400 if (!peer)
8401 return CMD_WARNING_CONFIG_FAILED;
8402
8403 peer->as_path_loop_detection = false;
8404
8405 return CMD_SUCCESS;
8406 }
8407
8408 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8409 struct ecommunity **list, bool is_rt6)
8410 {
8411 struct ecommunity *ecom = NULL;
8412 struct ecommunity *ecomadd;
8413
8414 for (; argc; --argc, ++argv) {
8415 if (is_rt6)
8416 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8417 ECOMMUNITY_ROUTE_TARGET,
8418 0);
8419 else
8420 ecomadd = ecommunity_str2com(argv[0]->arg,
8421 ECOMMUNITY_ROUTE_TARGET,
8422 0);
8423 if (!ecomadd) {
8424 vty_out(vty, "Malformed community-list value\n");
8425 if (ecom)
8426 ecommunity_free(&ecom);
8427 return CMD_WARNING_CONFIG_FAILED;
8428 }
8429
8430 if (ecom) {
8431 ecommunity_merge(ecom, ecomadd);
8432 ecommunity_free(&ecomadd);
8433 } else {
8434 ecom = ecomadd;
8435 }
8436 }
8437
8438 if (*list) {
8439 ecommunity_free(&*list);
8440 }
8441 *list = ecom;
8442
8443 return CMD_SUCCESS;
8444 }
8445
8446 /*
8447 * v2vimport is true if we are handling a `import vrf ...` command
8448 */
8449 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8450 {
8451 afi_t afi;
8452
8453 switch (vty->node) {
8454 case BGP_IPV4_NODE:
8455 afi = AFI_IP;
8456 break;
8457 case BGP_IPV6_NODE:
8458 afi = AFI_IP6;
8459 break;
8460 default:
8461 vty_out(vty,
8462 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8463 return AFI_MAX;
8464 }
8465
8466 if (!v2vimport) {
8467 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8468 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8469 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8470 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8471 vty_out(vty,
8472 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8473 return AFI_MAX;
8474 }
8475 } else {
8476 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8477 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8478 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8479 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8480 vty_out(vty,
8481 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8482 return AFI_MAX;
8483 }
8484 }
8485 return afi;
8486 }
8487
8488 DEFPY (af_rd_vpn_export,
8489 af_rd_vpn_export_cmd,
8490 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8491 NO_STR
8492 "Specify route distinguisher\n"
8493 "Between current address-family and vpn\n"
8494 "For routes leaked from current address-family to vpn\n"
8495 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8496 {
8497 VTY_DECLVAR_CONTEXT(bgp, bgp);
8498 struct prefix_rd prd;
8499 int ret;
8500 afi_t afi;
8501 int idx = 0;
8502 bool yes = true;
8503
8504 if (argv_find(argv, argc, "no", &idx))
8505 yes = false;
8506
8507 if (yes) {
8508 ret = str2prefix_rd(rd_str, &prd);
8509 if (!ret) {
8510 vty_out(vty, "%% Malformed rd\n");
8511 return CMD_WARNING_CONFIG_FAILED;
8512 }
8513 }
8514
8515 afi = vpn_policy_getafi(vty, bgp, false);
8516 if (afi == AFI_MAX)
8517 return CMD_WARNING_CONFIG_FAILED;
8518
8519 /*
8520 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8521 */
8522 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8523 bgp_get_default(), bgp);
8524
8525 if (yes) {
8526 bgp->vpn_policy[afi].tovpn_rd = prd;
8527 SET_FLAG(bgp->vpn_policy[afi].flags,
8528 BGP_VPN_POLICY_TOVPN_RD_SET);
8529 } else {
8530 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8531 BGP_VPN_POLICY_TOVPN_RD_SET);
8532 }
8533
8534 /* post-change: re-export vpn routes */
8535 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8536 bgp_get_default(), bgp);
8537
8538 return CMD_SUCCESS;
8539 }
8540
8541 ALIAS (af_rd_vpn_export,
8542 af_no_rd_vpn_export_cmd,
8543 "no rd vpn export",
8544 NO_STR
8545 "Specify route distinguisher\n"
8546 "Between current address-family and vpn\n"
8547 "For routes leaked from current address-family to vpn\n")
8548
8549 DEFPY (af_label_vpn_export,
8550 af_label_vpn_export_cmd,
8551 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8552 NO_STR
8553 "label value for VRF\n"
8554 "Between current address-family and vpn\n"
8555 "For routes leaked from current address-family to vpn\n"
8556 "Label Value <0-1048575>\n"
8557 "Automatically assign a label\n")
8558 {
8559 VTY_DECLVAR_CONTEXT(bgp, bgp);
8560 mpls_label_t label = MPLS_LABEL_NONE;
8561 afi_t afi;
8562 int idx = 0;
8563 bool yes = true;
8564
8565 if (argv_find(argv, argc, "no", &idx))
8566 yes = false;
8567
8568 /* If "no ...", squash trailing parameter */
8569 if (!yes)
8570 label_auto = NULL;
8571
8572 if (yes) {
8573 if (!label_auto)
8574 label = label_val; /* parser should force unsigned */
8575 }
8576
8577 afi = vpn_policy_getafi(vty, bgp, false);
8578 if (afi == AFI_MAX)
8579 return CMD_WARNING_CONFIG_FAILED;
8580
8581
8582 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8583 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8584 /* no change */
8585 return CMD_SUCCESS;
8586
8587 /*
8588 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8589 */
8590 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8591 bgp_get_default(), bgp);
8592
8593 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8594 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8595
8596 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8597
8598 /*
8599 * label has previously been automatically
8600 * assigned by labelpool: release it
8601 *
8602 * NB if tovpn_label == MPLS_LABEL_NONE it
8603 * means the automatic assignment is in flight
8604 * and therefore the labelpool callback must
8605 * detect that the auto label is not needed.
8606 */
8607
8608 bgp_lp_release(LP_TYPE_VRF,
8609 &bgp->vpn_policy[afi],
8610 bgp->vpn_policy[afi].tovpn_label);
8611 }
8612 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8613 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8614 }
8615
8616 bgp->vpn_policy[afi].tovpn_label = label;
8617 if (label_auto) {
8618 SET_FLAG(bgp->vpn_policy[afi].flags,
8619 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8620 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8621 vpn_leak_label_callback);
8622 }
8623
8624 /* post-change: re-export vpn routes */
8625 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8626 bgp_get_default(), bgp);
8627
8628 hook_call(bgp_snmp_update_last_changed, bgp);
8629 return CMD_SUCCESS;
8630 }
8631
8632 DEFPY (af_sid_vpn_export,
8633 af_sid_vpn_export_cmd,
8634 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8635 NO_STR
8636 "sid value for VRF\n"
8637 "Between current address-family and vpn\n"
8638 "For routes leaked from current address-family to vpn\n"
8639 "Sid allocation index\n"
8640 "Automatically assign a label\n")
8641 {
8642 VTY_DECLVAR_CONTEXT(bgp, bgp);
8643 afi_t afi;
8644 int debug = 0;
8645 int idx = 0;
8646 bool yes = true;
8647
8648 if (argv_find(argv, argc, "no", &idx))
8649 yes = false;
8650 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8651 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8652
8653 afi = vpn_policy_getafi(vty, bgp, false);
8654 if (afi == AFI_MAX)
8655 return CMD_WARNING_CONFIG_FAILED;
8656
8657 if (!yes) {
8658 /* implement me */
8659 vty_out(vty, "It's not implemented\n");
8660 return CMD_WARNING_CONFIG_FAILED;
8661 }
8662
8663 /* skip when it's already configured */
8664 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8665 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8666 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8667 return CMD_SUCCESS;
8668
8669 /*
8670 * mode change between sid_idx and sid_auto isn't supported.
8671 * user must negate sid vpn export when they want to change the mode
8672 */
8673 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8674 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8675 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8676 vty_out(vty, "it's already configured as %s.\n",
8677 sid_auto ? "auto-mode" : "idx-mode");
8678 return CMD_WARNING_CONFIG_FAILED;
8679 }
8680
8681 /* pre-change */
8682 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8683 bgp_get_default(), bgp);
8684
8685 if (sid_auto) {
8686 /* SID allocation auto-mode */
8687 if (debug)
8688 zlog_debug("%s: auto sid alloc.", __func__);
8689 SET_FLAG(bgp->vpn_policy[afi].flags,
8690 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8691 } else {
8692 /* SID allocation index-mode */
8693 if (debug)
8694 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8695 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8696 }
8697
8698 /* post-change */
8699 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8700 bgp_get_default(), bgp);
8701 return CMD_SUCCESS;
8702 }
8703
8704 ALIAS (af_label_vpn_export,
8705 af_no_label_vpn_export_cmd,
8706 "no label vpn export",
8707 NO_STR
8708 "label value for VRF\n"
8709 "Between current address-family and vpn\n"
8710 "For routes leaked from current address-family to vpn\n")
8711
8712 DEFPY (af_nexthop_vpn_export,
8713 af_nexthop_vpn_export_cmd,
8714 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8715 NO_STR
8716 "Specify next hop to use for VRF advertised prefixes\n"
8717 "Between current address-family and vpn\n"
8718 "For routes leaked from current address-family to vpn\n"
8719 "IPv4 prefix\n"
8720 "IPv6 prefix\n")
8721 {
8722 VTY_DECLVAR_CONTEXT(bgp, bgp);
8723 afi_t afi;
8724 struct prefix p;
8725
8726 if (!no) {
8727 if (!nexthop_su) {
8728 vty_out(vty, "%% Nexthop required\n");
8729 return CMD_WARNING_CONFIG_FAILED;
8730 }
8731 if (!sockunion2hostprefix(nexthop_su, &p))
8732 return CMD_WARNING_CONFIG_FAILED;
8733 }
8734
8735 afi = vpn_policy_getafi(vty, bgp, false);
8736 if (afi == AFI_MAX)
8737 return CMD_WARNING_CONFIG_FAILED;
8738
8739 /*
8740 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8741 */
8742 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8743 bgp_get_default(), bgp);
8744
8745 if (!no) {
8746 bgp->vpn_policy[afi].tovpn_nexthop = p;
8747 SET_FLAG(bgp->vpn_policy[afi].flags,
8748 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8749 } else {
8750 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8751 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8752 }
8753
8754 /* post-change: re-export vpn routes */
8755 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8756 bgp_get_default(), bgp);
8757
8758 return CMD_SUCCESS;
8759 }
8760
8761 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8762 {
8763 if (!strcmp(dstr, "import")) {
8764 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8765 } else if (!strcmp(dstr, "export")) {
8766 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8767 } else if (!strcmp(dstr, "both")) {
8768 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8769 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8770 } else {
8771 vty_out(vty, "%% direction parse error\n");
8772 return CMD_WARNING_CONFIG_FAILED;
8773 }
8774 return CMD_SUCCESS;
8775 }
8776
8777 DEFPY (af_rt_vpn_imexport,
8778 af_rt_vpn_imexport_cmd,
8779 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8780 NO_STR
8781 "Specify route target list\n"
8782 "Specify route target list\n"
8783 "Between current address-family and vpn\n"
8784 "For routes leaked from vpn to current address-family: match any\n"
8785 "For routes leaked from current address-family to vpn: set\n"
8786 "both import: match any and export: set\n"
8787 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8788 {
8789 VTY_DECLVAR_CONTEXT(bgp, bgp);
8790 int ret;
8791 struct ecommunity *ecom = NULL;
8792 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8793 enum vpn_policy_direction dir;
8794 afi_t afi;
8795 int idx = 0;
8796 bool yes = true;
8797
8798 if (argv_find(argv, argc, "no", &idx))
8799 yes = false;
8800
8801 afi = vpn_policy_getafi(vty, bgp, false);
8802 if (afi == AFI_MAX)
8803 return CMD_WARNING_CONFIG_FAILED;
8804
8805 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8806 if (ret != CMD_SUCCESS)
8807 return ret;
8808
8809 if (yes) {
8810 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8811 vty_out(vty, "%% Missing RTLIST\n");
8812 return CMD_WARNING_CONFIG_FAILED;
8813 }
8814 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8815 if (ret != CMD_SUCCESS) {
8816 return ret;
8817 }
8818 }
8819
8820 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8821 if (!dodir[dir])
8822 continue;
8823
8824 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8825
8826 if (yes) {
8827 if (bgp->vpn_policy[afi].rtlist[dir])
8828 ecommunity_free(
8829 &bgp->vpn_policy[afi].rtlist[dir]);
8830 bgp->vpn_policy[afi].rtlist[dir] =
8831 ecommunity_dup(ecom);
8832 } else {
8833 if (bgp->vpn_policy[afi].rtlist[dir])
8834 ecommunity_free(
8835 &bgp->vpn_policy[afi].rtlist[dir]);
8836 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8837 }
8838
8839 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8840 }
8841
8842 if (ecom)
8843 ecommunity_free(&ecom);
8844
8845 return CMD_SUCCESS;
8846 }
8847
8848 ALIAS (af_rt_vpn_imexport,
8849 af_no_rt_vpn_imexport_cmd,
8850 "no <rt|route-target> vpn <import|export|both>$direction_str",
8851 NO_STR
8852 "Specify route target list\n"
8853 "Specify route target list\n"
8854 "Between current address-family and vpn\n"
8855 "For routes leaked from vpn to current address-family\n"
8856 "For routes leaked from current address-family to vpn\n"
8857 "both import and export\n")
8858
8859 DEFPY (af_route_map_vpn_imexport,
8860 af_route_map_vpn_imexport_cmd,
8861 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8862 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8863 NO_STR
8864 "Specify route map\n"
8865 "Between current address-family and vpn\n"
8866 "For routes leaked from vpn to current address-family\n"
8867 "For routes leaked from current address-family to vpn\n"
8868 "name of route-map\n")
8869 {
8870 VTY_DECLVAR_CONTEXT(bgp, bgp);
8871 int ret;
8872 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8873 enum vpn_policy_direction dir;
8874 afi_t afi;
8875 int idx = 0;
8876 bool yes = true;
8877
8878 if (argv_find(argv, argc, "no", &idx))
8879 yes = false;
8880
8881 afi = vpn_policy_getafi(vty, bgp, false);
8882 if (afi == AFI_MAX)
8883 return CMD_WARNING_CONFIG_FAILED;
8884
8885 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8886 if (ret != CMD_SUCCESS)
8887 return ret;
8888
8889 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8890 if (!dodir[dir])
8891 continue;
8892
8893 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8894
8895 if (yes) {
8896 if (bgp->vpn_policy[afi].rmap_name[dir])
8897 XFREE(MTYPE_ROUTE_MAP_NAME,
8898 bgp->vpn_policy[afi].rmap_name[dir]);
8899 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8900 MTYPE_ROUTE_MAP_NAME, rmap_str);
8901 bgp->vpn_policy[afi].rmap[dir] =
8902 route_map_lookup_warn_noexist(vty, rmap_str);
8903 if (!bgp->vpn_policy[afi].rmap[dir])
8904 return CMD_SUCCESS;
8905 } else {
8906 if (bgp->vpn_policy[afi].rmap_name[dir])
8907 XFREE(MTYPE_ROUTE_MAP_NAME,
8908 bgp->vpn_policy[afi].rmap_name[dir]);
8909 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8910 bgp->vpn_policy[afi].rmap[dir] = NULL;
8911 }
8912
8913 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8914 }
8915
8916 return CMD_SUCCESS;
8917 }
8918
8919 ALIAS (af_route_map_vpn_imexport,
8920 af_no_route_map_vpn_imexport_cmd,
8921 "no route-map vpn <import|export>$direction_str",
8922 NO_STR
8923 "Specify route map\n"
8924 "Between current address-family and vpn\n"
8925 "For routes leaked from vpn to current address-family\n"
8926 "For routes leaked from current address-family to vpn\n")
8927
8928 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
8929 "import vrf route-map RMAP$rmap_str",
8930 "Import routes from another VRF\n"
8931 "Vrf routes being filtered\n"
8932 "Specify route map\n"
8933 "name of route-map\n")
8934 {
8935 VTY_DECLVAR_CONTEXT(bgp, bgp);
8936 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
8937 afi_t afi;
8938 struct bgp *bgp_default;
8939
8940 afi = vpn_policy_getafi(vty, bgp, true);
8941 if (afi == AFI_MAX)
8942 return CMD_WARNING_CONFIG_FAILED;
8943
8944 bgp_default = bgp_get_default();
8945 if (!bgp_default) {
8946 int32_t ret;
8947 as_t as = bgp->as;
8948
8949 /* Auto-create assuming the same AS */
8950 ret = bgp_get_vty(&bgp_default, &as, NULL,
8951 BGP_INSTANCE_TYPE_DEFAULT);
8952
8953 if (ret) {
8954 vty_out(vty,
8955 "VRF default is not configured as a bgp instance\n");
8956 return CMD_WARNING;
8957 }
8958 }
8959
8960 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8961
8962 if (bgp->vpn_policy[afi].rmap_name[dir])
8963 XFREE(MTYPE_ROUTE_MAP_NAME,
8964 bgp->vpn_policy[afi].rmap_name[dir]);
8965 bgp->vpn_policy[afi].rmap_name[dir] =
8966 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8967 bgp->vpn_policy[afi].rmap[dir] =
8968 route_map_lookup_warn_noexist(vty, rmap_str);
8969 if (!bgp->vpn_policy[afi].rmap[dir])
8970 return CMD_SUCCESS;
8971
8972 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8973 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8974
8975 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8976
8977 return CMD_SUCCESS;
8978 }
8979
8980 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8981 "no import vrf route-map [RMAP$rmap_str]",
8982 NO_STR
8983 "Import routes from another VRF\n"
8984 "Vrf routes being filtered\n"
8985 "Specify route map\n"
8986 "name of route-map\n")
8987 {
8988 VTY_DECLVAR_CONTEXT(bgp, bgp);
8989 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
8990 afi_t afi;
8991
8992 afi = vpn_policy_getafi(vty, bgp, true);
8993 if (afi == AFI_MAX)
8994 return CMD_WARNING_CONFIG_FAILED;
8995
8996 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8997
8998 if (bgp->vpn_policy[afi].rmap_name[dir])
8999 XFREE(MTYPE_ROUTE_MAP_NAME,
9000 bgp->vpn_policy[afi].rmap_name[dir]);
9001 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9002 bgp->vpn_policy[afi].rmap[dir] = NULL;
9003
9004 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9005 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9006 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9007
9008 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9009
9010 return CMD_SUCCESS;
9011 }
9012
9013 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9014 "[no] import vrf VIEWVRFNAME$import_name",
9015 NO_STR
9016 "Import routes from another VRF\n"
9017 "VRF to import from\n"
9018 "The name of the VRF\n")
9019 {
9020 VTY_DECLVAR_CONTEXT(bgp, bgp);
9021 struct listnode *node;
9022 struct bgp *vrf_bgp, *bgp_default;
9023 int32_t ret = 0;
9024 as_t as = bgp->as;
9025 bool remove = false;
9026 int32_t idx = 0;
9027 char *vname;
9028 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9029 safi_t safi;
9030 afi_t afi;
9031
9032 if (import_name == NULL) {
9033 vty_out(vty, "%% Missing import name\n");
9034 return CMD_WARNING;
9035 }
9036
9037 if (strcmp(import_name, "route-map") == 0) {
9038 vty_out(vty, "%% Must include route-map name\n");
9039 return CMD_WARNING;
9040 }
9041
9042 if (argv_find(argv, argc, "no", &idx))
9043 remove = true;
9044
9045 afi = vpn_policy_getafi(vty, bgp, true);
9046 if (afi == AFI_MAX)
9047 return CMD_WARNING_CONFIG_FAILED;
9048
9049 safi = bgp_node_safi(vty);
9050
9051 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9052 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9053 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9054 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9055 remove ? "unimport" : "import", import_name);
9056 return CMD_WARNING;
9057 }
9058
9059 bgp_default = bgp_get_default();
9060 if (!bgp_default) {
9061 /* Auto-create assuming the same AS */
9062 ret = bgp_get_vty(&bgp_default, &as, NULL,
9063 BGP_INSTANCE_TYPE_DEFAULT);
9064
9065 if (ret) {
9066 vty_out(vty,
9067 "VRF default is not configured as a bgp instance\n");
9068 return CMD_WARNING;
9069 }
9070 }
9071
9072 vrf_bgp = bgp_lookup_by_name(import_name);
9073 if (!vrf_bgp) {
9074 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9075 vrf_bgp = bgp_default;
9076 else
9077 /* Auto-create assuming the same AS */
9078 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9079
9080 if (ret) {
9081 vty_out(vty,
9082 "VRF %s is not configured as a bgp instance\n",
9083 import_name);
9084 return CMD_WARNING;
9085 }
9086 }
9087
9088 if (remove) {
9089 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9090 } else {
9091 /* Already importing from "import_vrf"? */
9092 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9093 vname)) {
9094 if (strcmp(vname, import_name) == 0)
9095 return CMD_WARNING;
9096 }
9097
9098 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9099 }
9100
9101 return CMD_SUCCESS;
9102 }
9103
9104 /* This command is valid only in a bgp vrf instance or the default instance */
9105 DEFPY (bgp_imexport_vpn,
9106 bgp_imexport_vpn_cmd,
9107 "[no] <import|export>$direction_str vpn",
9108 NO_STR
9109 "Import routes to this address-family\n"
9110 "Export routes from this address-family\n"
9111 "to/from default instance VPN RIB\n")
9112 {
9113 VTY_DECLVAR_CONTEXT(bgp, bgp);
9114 int previous_state;
9115 afi_t afi;
9116 safi_t safi;
9117 int idx = 0;
9118 bool yes = true;
9119 int flag;
9120 enum vpn_policy_direction dir;
9121
9122 if (argv_find(argv, argc, "no", &idx))
9123 yes = false;
9124
9125 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9126 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9127
9128 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9129 return CMD_WARNING_CONFIG_FAILED;
9130 }
9131
9132 afi = bgp_node_afi(vty);
9133 safi = bgp_node_safi(vty);
9134 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9135 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9136 return CMD_WARNING_CONFIG_FAILED;
9137 }
9138
9139 if (!strcmp(direction_str, "import")) {
9140 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9141 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9142 } else if (!strcmp(direction_str, "export")) {
9143 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9144 dir = BGP_VPN_POLICY_DIR_TOVPN;
9145 } else {
9146 vty_out(vty, "%% unknown direction %s\n", direction_str);
9147 return CMD_WARNING_CONFIG_FAILED;
9148 }
9149
9150 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9151
9152 if (yes) {
9153 SET_FLAG(bgp->af_flags[afi][safi], flag);
9154 if (!previous_state) {
9155 /* trigger export current vrf */
9156 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9157 }
9158 } else {
9159 if (previous_state) {
9160 /* trigger un-export current vrf */
9161 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9162 }
9163 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9164 }
9165
9166 hook_call(bgp_snmp_init_stats, bgp);
9167
9168 return CMD_SUCCESS;
9169 }
9170
9171 DEFPY (af_routetarget_import,
9172 af_routetarget_import_cmd,
9173 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9174 NO_STR
9175 "Specify route target list\n"
9176 "Specify route target list\n"
9177 "Specify route target list\n"
9178 "Specify route target list\n"
9179 "Flow-spec redirect type route target\n"
9180 "Import routes to this address-family\n"
9181 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9182 {
9183 VTY_DECLVAR_CONTEXT(bgp, bgp);
9184 int ret;
9185 struct ecommunity *ecom = NULL;
9186 afi_t afi;
9187 int idx = 0, idx_unused = 0;
9188 bool yes = true;
9189 bool rt6 = false;
9190
9191 if (argv_find(argv, argc, "no", &idx))
9192 yes = false;
9193
9194 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9195 argv_find(argv, argc, "route-target6", &idx_unused))
9196 rt6 = true;
9197
9198 afi = vpn_policy_getafi(vty, bgp, false);
9199 if (afi == AFI_MAX)
9200 return CMD_WARNING_CONFIG_FAILED;
9201
9202 if (rt6 && afi != AFI_IP6)
9203 return CMD_WARNING_CONFIG_FAILED;
9204
9205 if (yes) {
9206 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9207 vty_out(vty, "%% Missing RTLIST\n");
9208 return CMD_WARNING_CONFIG_FAILED;
9209 }
9210 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9211 if (ret != CMD_SUCCESS)
9212 return ret;
9213 }
9214
9215 if (yes) {
9216 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9217 ecommunity_free(&bgp->vpn_policy[afi]
9218 .import_redirect_rtlist);
9219 bgp->vpn_policy[afi].import_redirect_rtlist =
9220 ecommunity_dup(ecom);
9221 } else {
9222 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9223 ecommunity_free(&bgp->vpn_policy[afi]
9224 .import_redirect_rtlist);
9225 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9226 }
9227
9228 if (ecom)
9229 ecommunity_free(&ecom);
9230
9231 return CMD_SUCCESS;
9232 }
9233
9234 DEFUN_NOSH (address_family_ipv4_safi,
9235 address_family_ipv4_safi_cmd,
9236 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9237 "Enter Address Family command mode\n"
9238 "Address Family\n"
9239 BGP_SAFI_WITH_LABEL_HELP_STR)
9240 {
9241
9242 if (argc == 3) {
9243 VTY_DECLVAR_CONTEXT(bgp, bgp);
9244 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9245 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9246 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9247 && safi != SAFI_EVPN) {
9248 vty_out(vty,
9249 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9250 return CMD_WARNING_CONFIG_FAILED;
9251 }
9252 vty->node = bgp_node_type(AFI_IP, safi);
9253 } else
9254 vty->node = BGP_IPV4_NODE;
9255
9256 return CMD_SUCCESS;
9257 }
9258
9259 DEFUN_NOSH (address_family_ipv6_safi,
9260 address_family_ipv6_safi_cmd,
9261 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9262 "Enter Address Family command mode\n"
9263 "Address Family\n"
9264 BGP_SAFI_WITH_LABEL_HELP_STR)
9265 {
9266 if (argc == 3) {
9267 VTY_DECLVAR_CONTEXT(bgp, bgp);
9268 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9269 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9270 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9271 && safi != SAFI_EVPN) {
9272 vty_out(vty,
9273 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9274 return CMD_WARNING_CONFIG_FAILED;
9275 }
9276 vty->node = bgp_node_type(AFI_IP6, safi);
9277 } else
9278 vty->node = BGP_IPV6_NODE;
9279
9280 return CMD_SUCCESS;
9281 }
9282
9283 #ifdef KEEP_OLD_VPN_COMMANDS
9284 DEFUN_NOSH (address_family_vpnv4,
9285 address_family_vpnv4_cmd,
9286 "address-family vpnv4 [unicast]",
9287 "Enter Address Family command mode\n"
9288 "Address Family\n"
9289 "Address Family modifier\n")
9290 {
9291 vty->node = BGP_VPNV4_NODE;
9292 return CMD_SUCCESS;
9293 }
9294
9295 DEFUN_NOSH (address_family_vpnv6,
9296 address_family_vpnv6_cmd,
9297 "address-family vpnv6 [unicast]",
9298 "Enter Address Family command mode\n"
9299 "Address Family\n"
9300 "Address Family modifier\n")
9301 {
9302 vty->node = BGP_VPNV6_NODE;
9303 return CMD_SUCCESS;
9304 }
9305 #endif /* KEEP_OLD_VPN_COMMANDS */
9306
9307 DEFUN_NOSH (address_family_evpn,
9308 address_family_evpn_cmd,
9309 "address-family l2vpn evpn",
9310 "Enter Address Family command mode\n"
9311 "Address Family\n"
9312 "Address Family modifier\n")
9313 {
9314 VTY_DECLVAR_CONTEXT(bgp, bgp);
9315 vty->node = BGP_EVPN_NODE;
9316 return CMD_SUCCESS;
9317 }
9318
9319 DEFUN_NOSH (bgp_segment_routing_srv6,
9320 bgp_segment_routing_srv6_cmd,
9321 "segment-routing srv6",
9322 "Segment-Routing configuration\n"
9323 "Segment-Routing SRv6 configuration\n")
9324 {
9325 VTY_DECLVAR_CONTEXT(bgp, bgp);
9326 bgp->srv6_enabled = true;
9327 vty->node = BGP_SRV6_NODE;
9328 return CMD_SUCCESS;
9329 }
9330
9331 DEFUN (no_bgp_segment_routing_srv6,
9332 no_bgp_segment_routing_srv6_cmd,
9333 "no segment-routing srv6",
9334 NO_STR
9335 "Segment-Routing configuration\n"
9336 "Segment-Routing SRv6 configuration\n")
9337 {
9338 VTY_DECLVAR_CONTEXT(bgp, bgp);
9339
9340 if (strlen(bgp->srv6_locator_name) > 0)
9341 if (bgp_srv6_locator_unset(bgp) < 0)
9342 return CMD_WARNING_CONFIG_FAILED;
9343
9344 bgp->srv6_enabled = false;
9345 return CMD_SUCCESS;
9346 }
9347
9348 DEFPY (bgp_srv6_locator,
9349 bgp_srv6_locator_cmd,
9350 "locator NAME$name",
9351 "Specify SRv6 locator\n"
9352 "Specify SRv6 locator\n")
9353 {
9354 VTY_DECLVAR_CONTEXT(bgp, bgp);
9355 int ret;
9356
9357 if (strlen(bgp->srv6_locator_name) > 0
9358 && strcmp(name, bgp->srv6_locator_name) != 0) {
9359 vty_out(vty, "srv6 locator is already configured\n");
9360 return CMD_WARNING_CONFIG_FAILED;
9361 }
9362
9363 snprintf(bgp->srv6_locator_name,
9364 sizeof(bgp->srv6_locator_name), "%s", name);
9365
9366 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9367 if (ret < 0)
9368 return CMD_WARNING_CONFIG_FAILED;
9369
9370 return CMD_SUCCESS;
9371 }
9372
9373 DEFPY (no_bgp_srv6_locator,
9374 no_bgp_srv6_locator_cmd,
9375 "no locator NAME$name",
9376 NO_STR
9377 "Specify SRv6 locator\n"
9378 "Specify SRv6 locator\n")
9379 {
9380 VTY_DECLVAR_CONTEXT(bgp, bgp);
9381
9382 /* when locator isn't configured, do nothing */
9383 if (strlen(bgp->srv6_locator_name) < 1)
9384 return CMD_SUCCESS;
9385
9386 /* name validation */
9387 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9388 vty_out(vty, "%% No srv6 locator is configured\n");
9389 return CMD_WARNING_CONFIG_FAILED;
9390 }
9391
9392 /* unset locator */
9393 if (bgp_srv6_locator_unset(bgp) < 0)
9394 return CMD_WARNING_CONFIG_FAILED;
9395
9396 return CMD_SUCCESS;
9397 }
9398
9399 DEFPY (show_bgp_srv6,
9400 show_bgp_srv6_cmd,
9401 "show bgp segment-routing srv6",
9402 SHOW_STR
9403 BGP_STR
9404 "BGP Segment Routing\n"
9405 "BGP Segment Routing SRv6\n")
9406 {
9407 struct bgp *bgp;
9408 struct listnode *node;
9409 struct srv6_locator_chunk *chunk;
9410 struct bgp_srv6_function *func;
9411 struct in6_addr *tovpn4_sid;
9412 struct in6_addr *tovpn6_sid;
9413 char buf[256];
9414 char buf_tovpn4_sid[256];
9415 char buf_tovpn6_sid[256];
9416
9417 bgp = bgp_get_default();
9418 if (!bgp)
9419 return CMD_SUCCESS;
9420
9421 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9422 vty_out(vty, "locator_chunks:\n");
9423 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9424 prefix2str(&chunk->prefix, buf, sizeof(buf));
9425 vty_out(vty, "- %s\n", buf);
9426 }
9427
9428 vty_out(vty, "functions:\n");
9429 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9430 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9431 vty_out(vty, "- sid: %s\n", buf);
9432 vty_out(vty, " locator: %s\n", func->locator_name);
9433 }
9434
9435 vty_out(vty, "bgps:\n");
9436 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9437 vty_out(vty, "- name: %s\n",
9438 bgp->name ? bgp->name : "default");
9439
9440 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9441 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9442 if (tovpn4_sid)
9443 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9444 sizeof(buf_tovpn4_sid));
9445 if (tovpn6_sid)
9446 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9447 sizeof(buf_tovpn6_sid));
9448
9449 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9450 tovpn4_sid ? buf_tovpn4_sid : "none");
9451 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9452 tovpn6_sid ? buf_tovpn6_sid : "none");
9453 }
9454
9455 return CMD_SUCCESS;
9456 }
9457
9458 DEFUN_NOSH (exit_address_family,
9459 exit_address_family_cmd,
9460 "exit-address-family",
9461 "Exit from Address Family configuration mode\n")
9462 {
9463 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9464 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9465 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9466 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9467 || vty->node == BGP_EVPN_NODE
9468 || vty->node == BGP_FLOWSPECV4_NODE
9469 || vty->node == BGP_FLOWSPECV6_NODE)
9470 vty->node = BGP_NODE;
9471 return CMD_SUCCESS;
9472 }
9473
9474 /* Recalculate bestpath and re-advertise a prefix */
9475 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9476 const char *ip_str, afi_t afi, safi_t safi,
9477 struct prefix_rd *prd)
9478 {
9479 int ret;
9480 struct prefix match;
9481 struct bgp_dest *dest;
9482 struct bgp_dest *rm;
9483 struct bgp *bgp;
9484 struct bgp_table *table;
9485 struct bgp_table *rib;
9486
9487 /* BGP structure lookup. */
9488 if (view_name) {
9489 bgp = bgp_lookup_by_name(view_name);
9490 if (bgp == NULL) {
9491 vty_out(vty, "%% Can't find BGP instance %s\n",
9492 view_name);
9493 return CMD_WARNING;
9494 }
9495 } else {
9496 bgp = bgp_get_default();
9497 if (bgp == NULL) {
9498 vty_out(vty, "%% No BGP process is configured\n");
9499 return CMD_WARNING;
9500 }
9501 }
9502
9503 /* Check IP address argument. */
9504 ret = str2prefix(ip_str, &match);
9505 if (!ret) {
9506 vty_out(vty, "%% address is malformed\n");
9507 return CMD_WARNING;
9508 }
9509
9510 match.family = afi2family(afi);
9511 rib = bgp->rib[afi][safi];
9512
9513 if (safi == SAFI_MPLS_VPN) {
9514 for (dest = bgp_table_top(rib); dest;
9515 dest = bgp_route_next(dest)) {
9516 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9517
9518 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9519 continue;
9520
9521 table = bgp_dest_get_bgp_table_info(dest);
9522 if (table == NULL)
9523 continue;
9524
9525 rm = bgp_node_match(table, &match);
9526 if (rm != NULL) {
9527 const struct prefix *rm_p =
9528 bgp_dest_get_prefix(rm);
9529
9530 if (rm_p->prefixlen == match.prefixlen) {
9531 SET_FLAG(rm->flags,
9532 BGP_NODE_USER_CLEAR);
9533 bgp_process(bgp, rm, afi, safi);
9534 }
9535 bgp_dest_unlock_node(rm);
9536 }
9537 }
9538 } else {
9539 dest = bgp_node_match(rib, &match);
9540 if (dest != NULL) {
9541 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9542
9543 if (dest_p->prefixlen == match.prefixlen) {
9544 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9545 bgp_process(bgp, dest, afi, safi);
9546 }
9547 bgp_dest_unlock_node(dest);
9548 }
9549 }
9550
9551 return CMD_SUCCESS;
9552 }
9553
9554 /* one clear bgp command to rule them all */
9555 DEFUN (clear_ip_bgp_all,
9556 clear_ip_bgp_all_cmd,
9557 "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>]",
9558 CLEAR_STR
9559 IP_STR
9560 BGP_STR
9561 BGP_INSTANCE_HELP_STR
9562 BGP_AFI_HELP_STR
9563 "Address Family\n"
9564 BGP_SAFI_WITH_LABEL_HELP_STR
9565 "Address Family modifier\n"
9566 "Clear all peers\n"
9567 "BGP IPv4 neighbor to clear\n"
9568 "BGP IPv6 neighbor to clear\n"
9569 "BGP neighbor on interface to clear\n"
9570 "Clear peers with the AS number\n"
9571 "Clear all external peers\n"
9572 "Clear all members of peer-group\n"
9573 "BGP peer-group name\n"
9574 BGP_SOFT_STR
9575 BGP_SOFT_IN_STR
9576 BGP_SOFT_OUT_STR
9577 BGP_SOFT_IN_STR
9578 "Push out prefix-list ORF and do inbound soft reconfig\n"
9579 BGP_SOFT_OUT_STR
9580 "Reset message statistics\n")
9581 {
9582 char *vrf = NULL;
9583
9584 afi_t afi = AFI_UNSPEC;
9585 safi_t safi = SAFI_UNSPEC;
9586 enum clear_sort clr_sort = clear_peer;
9587 enum bgp_clear_type clr_type;
9588 char *clr_arg = NULL;
9589
9590 int idx = 0;
9591
9592 /* clear [ip] bgp */
9593 if (argv_find(argv, argc, "ip", &idx))
9594 afi = AFI_IP;
9595
9596 /* [<vrf> VIEWVRFNAME] */
9597 if (argv_find(argv, argc, "vrf", &idx)) {
9598 vrf = argv[idx + 1]->arg;
9599 idx += 2;
9600 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9601 vrf = NULL;
9602 } else if (argv_find(argv, argc, "view", &idx)) {
9603 /* [<view> VIEWVRFNAME] */
9604 vrf = argv[idx + 1]->arg;
9605 idx += 2;
9606 }
9607 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9608 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9609 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9610
9611 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9612 if (argv_find(argv, argc, "*", &idx)) {
9613 clr_sort = clear_all;
9614 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9615 clr_sort = clear_peer;
9616 clr_arg = argv[idx]->arg;
9617 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9618 clr_sort = clear_peer;
9619 clr_arg = argv[idx]->arg;
9620 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9621 clr_sort = clear_group;
9622 idx++;
9623 clr_arg = argv[idx]->arg;
9624 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9625 clr_sort = clear_peer;
9626 clr_arg = argv[idx]->arg;
9627 } else if (argv_find(argv, argc, "WORD", &idx)) {
9628 clr_sort = clear_peer;
9629 clr_arg = argv[idx]->arg;
9630 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9631 clr_sort = clear_as;
9632 clr_arg = argv[idx]->arg;
9633 } else if (argv_find(argv, argc, "external", &idx)) {
9634 clr_sort = clear_external;
9635 }
9636
9637 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9638 if (argv_find(argv, argc, "soft", &idx)) {
9639 if (argv_find(argv, argc, "in", &idx)
9640 || argv_find(argv, argc, "out", &idx))
9641 clr_type = strmatch(argv[idx]->text, "in")
9642 ? BGP_CLEAR_SOFT_IN
9643 : BGP_CLEAR_SOFT_OUT;
9644 else
9645 clr_type = BGP_CLEAR_SOFT_BOTH;
9646 } else if (argv_find(argv, argc, "in", &idx)) {
9647 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9648 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9649 : BGP_CLEAR_SOFT_IN;
9650 } else if (argv_find(argv, argc, "out", &idx)) {
9651 clr_type = BGP_CLEAR_SOFT_OUT;
9652 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9653 clr_type = BGP_CLEAR_MESSAGE_STATS;
9654 } else
9655 clr_type = BGP_CLEAR_SOFT_NONE;
9656
9657 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9658 }
9659
9660 DEFUN (clear_ip_bgp_prefix,
9661 clear_ip_bgp_prefix_cmd,
9662 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9663 CLEAR_STR
9664 IP_STR
9665 BGP_STR
9666 BGP_INSTANCE_HELP_STR
9667 "Clear bestpath and re-advertise\n"
9668 "IPv4 prefix\n")
9669 {
9670 char *vrf = NULL;
9671 char *prefix = NULL;
9672
9673 int idx = 0;
9674
9675 /* [<view|vrf> VIEWVRFNAME] */
9676 if (argv_find(argv, argc, "vrf", &idx)) {
9677 vrf = argv[idx + 1]->arg;
9678 idx += 2;
9679 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9680 vrf = NULL;
9681 } else if (argv_find(argv, argc, "view", &idx)) {
9682 /* [<view> VIEWVRFNAME] */
9683 vrf = argv[idx + 1]->arg;
9684 idx += 2;
9685 }
9686
9687 prefix = argv[argc - 1]->arg;
9688
9689 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9690 }
9691
9692 DEFUN (clear_bgp_ipv6_safi_prefix,
9693 clear_bgp_ipv6_safi_prefix_cmd,
9694 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9695 CLEAR_STR
9696 IP_STR
9697 BGP_STR
9698 "Address Family\n"
9699 BGP_SAFI_HELP_STR
9700 "Clear bestpath and re-advertise\n"
9701 "IPv6 prefix\n")
9702 {
9703 int idx_safi = 0;
9704 int idx_ipv6_prefix = 0;
9705 safi_t safi = SAFI_UNICAST;
9706 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9707 argv[idx_ipv6_prefix]->arg : NULL;
9708
9709 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9710 return bgp_clear_prefix(
9711 vty, NULL, prefix, AFI_IP6,
9712 safi, NULL);
9713 }
9714
9715 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9716 clear_bgp_instance_ipv6_safi_prefix_cmd,
9717 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9718 CLEAR_STR
9719 IP_STR
9720 BGP_STR
9721 BGP_INSTANCE_HELP_STR
9722 "Address Family\n"
9723 BGP_SAFI_HELP_STR
9724 "Clear bestpath and re-advertise\n"
9725 "IPv6 prefix\n")
9726 {
9727 int idx_safi = 0;
9728 int idx_vrfview = 0;
9729 int idx_ipv6_prefix = 0;
9730 safi_t safi = SAFI_UNICAST;
9731 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9732 argv[idx_ipv6_prefix]->arg : NULL;
9733 char *vrfview = NULL;
9734
9735 /* [<view|vrf> VIEWVRFNAME] */
9736 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9737 vrfview = argv[idx_vrfview + 1]->arg;
9738 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9739 vrfview = NULL;
9740 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9741 /* [<view> VIEWVRFNAME] */
9742 vrfview = argv[idx_vrfview + 1]->arg;
9743 }
9744 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9745
9746 return bgp_clear_prefix(
9747 vty, vrfview, prefix,
9748 AFI_IP6, safi, NULL);
9749 }
9750
9751 DEFUN (show_bgp_views,
9752 show_bgp_views_cmd,
9753 "show [ip] bgp views",
9754 SHOW_STR
9755 IP_STR
9756 BGP_STR
9757 "Show the defined BGP views\n")
9758 {
9759 struct list *inst = bm->bgp;
9760 struct listnode *node;
9761 struct bgp *bgp;
9762
9763 vty_out(vty, "Defined BGP views:\n");
9764 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9765 /* Skip VRFs. */
9766 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9767 continue;
9768 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9769 bgp->as);
9770 }
9771
9772 return CMD_SUCCESS;
9773 }
9774
9775 DEFUN (show_bgp_vrfs,
9776 show_bgp_vrfs_cmd,
9777 "show [ip] bgp vrfs [json]",
9778 SHOW_STR
9779 IP_STR
9780 BGP_STR
9781 "Show BGP VRFs\n"
9782 JSON_STR)
9783 {
9784 char buf[ETHER_ADDR_STRLEN];
9785 struct list *inst = bm->bgp;
9786 struct listnode *node;
9787 struct bgp *bgp;
9788 bool uj = use_json(argc, argv);
9789 json_object *json = NULL;
9790 json_object *json_vrfs = NULL;
9791 int count = 0;
9792
9793 if (uj) {
9794 json = json_object_new_object();
9795 json_vrfs = json_object_new_object();
9796 }
9797
9798 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9799 const char *name, *type;
9800 struct peer *peer;
9801 struct listnode *node2, *nnode2;
9802 int peers_cfg, peers_estb;
9803 json_object *json_vrf = NULL;
9804
9805 /* Skip Views. */
9806 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9807 continue;
9808
9809 count++;
9810 if (!uj && count == 1) {
9811 vty_out(vty,
9812 "%4s %-5s %-16s %9s %10s %-37s\n",
9813 "Type", "Id", "routerId", "#PeersCfg",
9814 "#PeersEstb", "Name");
9815 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9816 "L3-VNI", "RouterMAC", "Interface");
9817 }
9818
9819 peers_cfg = peers_estb = 0;
9820 if (uj)
9821 json_vrf = json_object_new_object();
9822
9823
9824 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9825 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9826 continue;
9827 peers_cfg++;
9828 if (peer_established(peer))
9829 peers_estb++;
9830 }
9831
9832 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9833 name = VRF_DEFAULT_NAME;
9834 type = "DFLT";
9835 } else {
9836 name = bgp->name;
9837 type = "VRF";
9838 }
9839
9840
9841 if (uj) {
9842 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9843 ? -1
9844 : (int64_t)bgp->vrf_id;
9845 char buf[BUFSIZ] = {0};
9846
9847 json_object_string_add(json_vrf, "type", type);
9848 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9849 json_object_string_addf(json_vrf, "routerId", "%pI4",
9850 &bgp->router_id);
9851 json_object_int_add(json_vrf, "numConfiguredPeers",
9852 peers_cfg);
9853 json_object_int_add(json_vrf, "numEstablishedPeers",
9854 peers_estb);
9855
9856 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
9857 json_object_string_add(
9858 json_vrf, "rmac",
9859 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
9860 json_object_string_add(json_vrf, "interface",
9861 ifindex2ifname(bgp->l3vni_svi_ifindex,
9862 bgp->vrf_id));
9863 json_object_object_add(json_vrfs, name, json_vrf);
9864 } else {
9865 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
9866 type,
9867 bgp->vrf_id == VRF_UNKNOWN ? -1
9868 : (int)bgp->vrf_id,
9869 &bgp->router_id, peers_cfg, peers_estb, name);
9870 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9871 bgp->l3vni,
9872 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9873 ifindex2ifname(bgp->l3vni_svi_ifindex,
9874 bgp->vrf_id));
9875 }
9876 }
9877
9878 if (uj) {
9879 json_object_object_add(json, "vrfs", json_vrfs);
9880
9881 json_object_int_add(json, "totalVrfs", count);
9882
9883 vty_json(vty, json);
9884 } else {
9885 if (count)
9886 vty_out(vty,
9887 "\nTotal number of VRFs (including default): %d\n",
9888 count);
9889 }
9890
9891 return CMD_SUCCESS;
9892 }
9893
9894 DEFUN (show_bgp_mac_hash,
9895 show_bgp_mac_hash_cmd,
9896 "show bgp mac hash",
9897 SHOW_STR
9898 BGP_STR
9899 "Mac Address\n"
9900 "Mac Address database\n")
9901 {
9902 bgp_mac_dump_table(vty);
9903
9904 return CMD_SUCCESS;
9905 }
9906
9907 static void show_tip_entry(struct hash_bucket *bucket, void *args)
9908 {
9909 struct vty *vty = (struct vty *)args;
9910 struct tip_addr *tip = (struct tip_addr *)bucket->data;
9911
9912 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
9913 }
9914
9915 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9916 {
9917 vty_out(vty, "self nexthop database:\n");
9918 bgp_nexthop_show_address_hash(vty, bgp);
9919
9920 vty_out(vty, "Tunnel-ip database:\n");
9921 hash_iterate(bgp->tip_hash,
9922 (void (*)(struct hash_bucket *, void *))show_tip_entry,
9923 vty);
9924 }
9925
9926 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9927 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9928 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
9929 "martian next-hops\n"
9930 "martian next-hop database\n")
9931 {
9932 struct bgp *bgp = NULL;
9933 int idx = 0;
9934 char *name = NULL;
9935
9936 /* [<vrf> VIEWVRFNAME] */
9937 if (argv_find(argv, argc, "vrf", &idx)) {
9938 name = argv[idx + 1]->arg;
9939 if (name && strmatch(name, VRF_DEFAULT_NAME))
9940 name = NULL;
9941 } else if (argv_find(argv, argc, "view", &idx))
9942 /* [<view> VIEWVRFNAME] */
9943 name = argv[idx + 1]->arg;
9944 if (name)
9945 bgp = bgp_lookup_by_name(name);
9946 else
9947 bgp = bgp_get_default();
9948
9949 if (!bgp) {
9950 vty_out(vty, "%% No BGP process is configured\n");
9951 return CMD_WARNING;
9952 }
9953 bgp_show_martian_nexthops(vty, bgp);
9954
9955 return CMD_SUCCESS;
9956 }
9957
9958 DEFUN (show_bgp_memory,
9959 show_bgp_memory_cmd,
9960 "show [ip] bgp memory",
9961 SHOW_STR
9962 IP_STR
9963 BGP_STR
9964 "Global BGP memory statistics\n")
9965 {
9966 char memstrbuf[MTYPE_MEMSTR_LEN];
9967 unsigned long count;
9968
9969 /* RIB related usage stats */
9970 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9971 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9972 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9973 count * sizeof(struct bgp_dest)));
9974
9975 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9976 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9977 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9978 count * sizeof(struct bgp_path_info)));
9979 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9980 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9981 count,
9982 mtype_memstr(
9983 memstrbuf, sizeof(memstrbuf),
9984 count * sizeof(struct bgp_path_info_extra)));
9985
9986 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9987 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9988 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9989 count * sizeof(struct bgp_static)));
9990
9991 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9992 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9993 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9994 count * sizeof(struct bpacket)));
9995
9996 /* Adj-In/Out */
9997 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9998 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9999 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10000 count * sizeof(struct bgp_adj_in)));
10001 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10002 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10003 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10004 count * sizeof(struct bgp_adj_out)));
10005
10006 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10007 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10008 count,
10009 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10010 count * sizeof(struct bgp_nexthop_cache)));
10011
10012 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10013 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10014 count,
10015 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10016 count * sizeof(struct bgp_damp_info)));
10017
10018 /* Attributes */
10019 count = attr_count();
10020 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10021 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10022 count * sizeof(struct attr)));
10023
10024 if ((count = attr_unknown_count()))
10025 vty_out(vty, "%ld unknown attributes\n", count);
10026
10027 /* AS_PATH attributes */
10028 count = aspath_count();
10029 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10030 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10031 count * sizeof(struct aspath)));
10032
10033 count = mtype_stats_alloc(MTYPE_AS_SEG);
10034 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10035 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10036 count * sizeof(struct assegment)));
10037
10038 /* Other attributes */
10039 if ((count = community_count()))
10040 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10041 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10042 count * sizeof(struct community)));
10043 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10044 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10045 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10046 count * sizeof(struct ecommunity)));
10047 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10048 vty_out(vty,
10049 "%ld BGP large-community entries, using %s of memory\n",
10050 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10051 count * sizeof(struct lcommunity)));
10052
10053 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10054 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10055 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10056 count * sizeof(struct cluster_list)));
10057
10058 /* Peer related usage */
10059 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10060 vty_out(vty, "%ld peers, using %s of memory\n", count,
10061 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10062 count * sizeof(struct peer)));
10063
10064 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10065 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10066 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10067 count * sizeof(struct peer_group)));
10068
10069 /* Other */
10070 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10071 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10072 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10073 count * sizeof(regex_t)));
10074 return CMD_SUCCESS;
10075 }
10076
10077 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10078 {
10079 json_object *bestpath = json_object_new_object();
10080
10081 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10082 json_object_string_add(bestpath, "asPath", "ignore");
10083
10084 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10085 json_object_string_add(bestpath, "asPath", "confed");
10086
10087 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10088 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10089 json_object_string_add(bestpath, "multiPathRelax",
10090 "as-set");
10091 else
10092 json_object_string_add(bestpath, "multiPathRelax",
10093 "true");
10094 } else
10095 json_object_string_add(bestpath, "multiPathRelax", "false");
10096
10097 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10098 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10099
10100 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10101 json_object_string_add(bestpath, "compareRouterId", "true");
10102 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10103 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10104 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10105 json_object_string_add(bestpath, "med", "confed");
10106 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10107 json_object_string_add(bestpath, "med",
10108 "missing-as-worst");
10109 else
10110 json_object_string_add(bestpath, "med", "true");
10111 }
10112
10113 json_object_object_add(json, "bestPath", bestpath);
10114 }
10115
10116 /* Print the error code/subcode for why the peer is down */
10117 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10118 json_object *json_peer, bool use_json)
10119 {
10120 const char *code_str;
10121 const char *subcode_str;
10122
10123 if (use_json) {
10124 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10125 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10126 char errorcodesubcode_hexstr[5];
10127 char errorcodesubcode_str[256];
10128
10129 code_str = bgp_notify_code_str(peer->notify.code);
10130 subcode_str = bgp_notify_subcode_str(
10131 peer->notify.code,
10132 peer->notify.subcode);
10133
10134 snprintf(errorcodesubcode_hexstr,
10135 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10136 peer->notify.code, peer->notify.subcode);
10137 json_object_string_add(json_peer,
10138 "lastErrorCodeSubcode",
10139 errorcodesubcode_hexstr);
10140 snprintf(errorcodesubcode_str, 255, "%s%s",
10141 code_str, subcode_str);
10142 json_object_string_add(json_peer,
10143 "lastNotificationReason",
10144 errorcodesubcode_str);
10145 json_object_boolean_add(json_peer,
10146 "lastNotificationHardReset",
10147 peer->notify.hard_reset);
10148 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10149 && peer->notify.code == BGP_NOTIFY_CEASE
10150 && (peer->notify.subcode
10151 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10152 || peer->notify.subcode
10153 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10154 && peer->notify.length) {
10155 char msgbuf[1024];
10156 const char *msg_str;
10157
10158 msg_str = bgp_notify_admin_message(
10159 msgbuf, sizeof(msgbuf),
10160 (uint8_t *)peer->notify.data,
10161 peer->notify.length);
10162 if (msg_str)
10163 json_object_string_add(
10164 json_peer,
10165 "lastShutdownDescription",
10166 msg_str);
10167 }
10168
10169 }
10170 json_object_string_add(json_peer, "lastResetDueTo",
10171 peer_down_str[(int)peer->last_reset]);
10172 json_object_int_add(json_peer, "lastResetCode",
10173 peer->last_reset);
10174 } else {
10175 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10176 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10177 code_str = bgp_notify_code_str(peer->notify.code);
10178 subcode_str =
10179 bgp_notify_subcode_str(peer->notify.code,
10180 peer->notify.subcode);
10181 vty_out(vty, " Notification %s (%s%s%s)\n",
10182 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10183 ? "sent"
10184 : "received",
10185 code_str, subcode_str,
10186 peer->notify.hard_reset
10187 ? bgp_notify_subcode_str(
10188 BGP_NOTIFY_CEASE,
10189 BGP_NOTIFY_CEASE_HARD_RESET)
10190 : "");
10191 } else {
10192 vty_out(vty, " %s\n",
10193 peer_down_str[(int)peer->last_reset]);
10194 }
10195 }
10196 }
10197
10198 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10199 safi_t safi)
10200 {
10201 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10202 }
10203
10204 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10205 struct peer *peer, json_object *json_peer,
10206 int max_neighbor_width, bool use_json)
10207 {
10208 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10209 int len;
10210
10211 if (use_json) {
10212 if (peer_dynamic_neighbor(peer))
10213 json_object_boolean_true_add(json_peer,
10214 "dynamicPeer");
10215 if (peer->hostname)
10216 json_object_string_add(json_peer, "hostname",
10217 peer->hostname);
10218
10219 if (peer->domainname)
10220 json_object_string_add(json_peer, "domainname",
10221 peer->domainname);
10222 json_object_int_add(json_peer, "connectionsEstablished",
10223 peer->established);
10224 json_object_int_add(json_peer, "connectionsDropped",
10225 peer->dropped);
10226 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10227 use_json, json_peer);
10228 if (peer_established(peer))
10229 json_object_string_add(json_peer, "lastResetDueTo",
10230 "AFI/SAFI Not Negotiated");
10231 else
10232 bgp_show_peer_reset(NULL, peer, json_peer, true);
10233 } else {
10234 dn_flag[1] = '\0';
10235 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10236 if (peer->hostname
10237 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10238 len = vty_out(vty, "%s%s(%s)", dn_flag,
10239 peer->hostname, peer->host);
10240 else
10241 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10242
10243 /* pad the neighbor column with spaces */
10244 if (len < max_neighbor_width)
10245 vty_out(vty, "%*s", max_neighbor_width - len,
10246 " ");
10247 vty_out(vty, "%7d %7d %9s", peer->established,
10248 peer->dropped,
10249 peer_uptime(peer->uptime, timebuf,
10250 BGP_UPTIME_LEN, 0, NULL));
10251 if (peer_established(peer))
10252 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10253 else
10254 bgp_show_peer_reset(vty, peer, NULL,
10255 false);
10256 }
10257 }
10258
10259 /* Strip peer's description to the given size. */
10260 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10261 {
10262 static char stripped[BUFSIZ];
10263 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10264
10265 strlcpy(stripped, desc, len + 1);
10266
10267 return stripped;
10268 }
10269
10270 /* Determine whether var peer should be filtered out of the summary. */
10271 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10272 struct peer *fpeer, int as_type,
10273 as_t as)
10274 {
10275
10276 /* filter neighbor XXXX */
10277 if (fpeer && fpeer != peer)
10278 return true;
10279
10280 /* filter remote-as (internal|external) */
10281 if (as_type != AS_UNSPECIFIED) {
10282 if (peer->as_type == AS_SPECIFIED) {
10283 if (as_type == AS_INTERNAL) {
10284 if (peer->as != peer->local_as)
10285 return true;
10286 } else if (peer->as == peer->local_as)
10287 return true;
10288 } else if (as_type != peer->as_type)
10289 return true;
10290 } else if (as && as != peer->as) /* filter remote-as XXX */
10291 return true;
10292
10293 return false;
10294 }
10295
10296 /* Show BGP peer's summary information.
10297 *
10298 * Peer's description is stripped according to if `wide` option is given
10299 * or not.
10300 *
10301 * When adding new columns to `show bgp summary` output, please make
10302 * sure `Desc` is the lastest column to show because it can contain
10303 * whitespaces and the whole output will be tricky.
10304 */
10305 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10306 struct peer *fpeer, int as_type, as_t as,
10307 uint16_t show_flags)
10308 {
10309 struct peer *peer;
10310 struct listnode *node, *nnode;
10311 unsigned int count = 0, dn_count = 0;
10312 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10313 char neighbor_buf[VTY_BUFSIZ];
10314 int neighbor_col_default_width = 16;
10315 int len, failed_count = 0;
10316 unsigned int filtered_count = 0;
10317 int max_neighbor_width = 0;
10318 int pfx_rcd_safi;
10319 json_object *json = NULL;
10320 json_object *json_peer = NULL;
10321 json_object *json_peers = NULL;
10322 struct peer_af *paf;
10323 struct bgp_filter *filter;
10324 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10325 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10326 bool show_established =
10327 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10328 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10329 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10330
10331 /* labeled-unicast routes are installed in the unicast table so in order
10332 * to
10333 * display the correct PfxRcd value we must look at SAFI_UNICAST
10334 */
10335
10336 if (safi == SAFI_LABELED_UNICAST)
10337 pfx_rcd_safi = SAFI_UNICAST;
10338 else
10339 pfx_rcd_safi = safi;
10340
10341 if (use_json) {
10342 json = json_object_new_object();
10343 json_peers = json_object_new_object();
10344 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10345 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10346 as_type, as)) {
10347 filtered_count++;
10348 count++;
10349 continue;
10350 }
10351
10352 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10353 continue;
10354
10355 if (peer->afc[afi][safi]) {
10356 /* See if we have at least a single failed peer */
10357 if (bgp_has_peer_failed(peer, afi, safi))
10358 failed_count++;
10359 count++;
10360 }
10361 if (peer_dynamic_neighbor(peer))
10362 dn_count++;
10363 }
10364
10365 } else {
10366 /* Loop over all neighbors that will be displayed to determine
10367 * how many
10368 * characters are needed for the Neighbor column
10369 */
10370 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10371 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10372 as_type, as)) {
10373 filtered_count++;
10374 count++;
10375 continue;
10376 }
10377
10378 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10379 continue;
10380
10381 if (peer->afc[afi][safi]) {
10382 memset(dn_flag, '\0', sizeof(dn_flag));
10383 if (peer_dynamic_neighbor(peer))
10384 dn_flag[0] = '*';
10385
10386 if (peer->hostname
10387 && CHECK_FLAG(bgp->flags,
10388 BGP_FLAG_SHOW_HOSTNAME))
10389 snprintf(neighbor_buf,
10390 sizeof(neighbor_buf),
10391 "%s%s(%s) ", dn_flag,
10392 peer->hostname, peer->host);
10393 else
10394 snprintf(neighbor_buf,
10395 sizeof(neighbor_buf), "%s%s ",
10396 dn_flag, peer->host);
10397
10398 len = strlen(neighbor_buf);
10399
10400 if (len > max_neighbor_width)
10401 max_neighbor_width = len;
10402
10403 /* See if we have at least a single failed peer */
10404 if (bgp_has_peer_failed(peer, afi, safi))
10405 failed_count++;
10406 count++;
10407 }
10408 }
10409
10410 /* Originally we displayed the Neighbor column as 16
10411 * characters wide so make that the default
10412 */
10413 if (max_neighbor_width < neighbor_col_default_width)
10414 max_neighbor_width = neighbor_col_default_width;
10415 }
10416
10417 if (show_failed && !failed_count) {
10418 if (use_json) {
10419 json_object_int_add(json, "failedPeersCount", 0);
10420 json_object_int_add(json, "dynamicPeers", dn_count);
10421 json_object_int_add(json, "totalPeers", count);
10422
10423 vty_json(vty, json);
10424 } else {
10425 vty_out(vty, "%% No failed BGP neighbors found\n");
10426 }
10427 return CMD_SUCCESS;
10428 }
10429
10430 count = 0; /* Reset the value as its used again */
10431 filtered_count = 0;
10432 dn_count = 0;
10433 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10434 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10435 continue;
10436
10437 if (!peer->afc[afi][safi])
10438 continue;
10439
10440 if (!count) {
10441 unsigned long ents;
10442 char memstrbuf[MTYPE_MEMSTR_LEN];
10443 int64_t vrf_id_ui;
10444
10445 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10446 ? -1
10447 : (int64_t)bgp->vrf_id;
10448
10449 /* Usage summary and header */
10450 if (use_json) {
10451 json_object_string_addf(json, "routerId",
10452 "%pI4",
10453 &bgp->router_id);
10454 json_object_int_add(json, "as", bgp->as);
10455 json_object_int_add(json, "vrfId", vrf_id_ui);
10456 json_object_string_add(
10457 json, "vrfName",
10458 (bgp->inst_type
10459 == BGP_INSTANCE_TYPE_DEFAULT)
10460 ? VRF_DEFAULT_NAME
10461 : bgp->name);
10462 } else {
10463 vty_out(vty,
10464 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10465 &bgp->router_id, bgp->as,
10466 bgp->vrf_id == VRF_UNKNOWN
10467 ? -1
10468 : (int)bgp->vrf_id);
10469 vty_out(vty, "\n");
10470 }
10471
10472 if (bgp_update_delay_configured(bgp)) {
10473 if (use_json) {
10474 json_object_int_add(
10475 json, "updateDelayLimit",
10476 bgp->v_update_delay);
10477
10478 if (bgp->v_update_delay
10479 != bgp->v_establish_wait)
10480 json_object_int_add(
10481 json,
10482 "updateDelayEstablishWait",
10483 bgp->v_establish_wait);
10484
10485 if (bgp_update_delay_active(bgp)) {
10486 json_object_string_add(
10487 json,
10488 "updateDelayFirstNeighbor",
10489 bgp->update_delay_begin_time);
10490 json_object_boolean_true_add(
10491 json,
10492 "updateDelayInProgress");
10493 } else {
10494 if (bgp->update_delay_over) {
10495 json_object_string_add(
10496 json,
10497 "updateDelayFirstNeighbor",
10498 bgp->update_delay_begin_time);
10499 json_object_string_add(
10500 json,
10501 "updateDelayBestpathResumed",
10502 bgp->update_delay_end_time);
10503 json_object_string_add(
10504 json,
10505 "updateDelayZebraUpdateResume",
10506 bgp->update_delay_zebra_resume_time);
10507 json_object_string_add(
10508 json,
10509 "updateDelayPeerUpdateResume",
10510 bgp->update_delay_peers_resume_time);
10511 }
10512 }
10513 } else {
10514 vty_out(vty,
10515 "Read-only mode update-delay limit: %d seconds\n",
10516 bgp->v_update_delay);
10517 if (bgp->v_update_delay
10518 != bgp->v_establish_wait)
10519 vty_out(vty,
10520 " Establish wait: %d seconds\n",
10521 bgp->v_establish_wait);
10522
10523 if (bgp_update_delay_active(bgp)) {
10524 vty_out(vty,
10525 " First neighbor established: %s\n",
10526 bgp->update_delay_begin_time);
10527 vty_out(vty,
10528 " Delay in progress\n");
10529 } else {
10530 if (bgp->update_delay_over) {
10531 vty_out(vty,
10532 " First neighbor established: %s\n",
10533 bgp->update_delay_begin_time);
10534 vty_out(vty,
10535 " Best-paths resumed: %s\n",
10536 bgp->update_delay_end_time);
10537 vty_out(vty,
10538 " zebra update resumed: %s\n",
10539 bgp->update_delay_zebra_resume_time);
10540 vty_out(vty,
10541 " peers update resumed: %s\n",
10542 bgp->update_delay_peers_resume_time);
10543 }
10544 }
10545 }
10546 }
10547
10548 if (use_json) {
10549 if (bgp_maxmed_onstartup_configured(bgp)
10550 && bgp->maxmed_active)
10551 json_object_boolean_true_add(
10552 json, "maxMedOnStartup");
10553 if (bgp->v_maxmed_admin)
10554 json_object_boolean_true_add(
10555 json, "maxMedAdministrative");
10556
10557 json_object_int_add(
10558 json, "tableVersion",
10559 bgp_table_version(bgp->rib[afi][safi]));
10560
10561 ents = bgp_table_count(bgp->rib[afi][safi]);
10562 json_object_int_add(json, "ribCount", ents);
10563 json_object_int_add(
10564 json, "ribMemory",
10565 ents * sizeof(struct bgp_dest));
10566
10567 ents = bgp->af_peer_count[afi][safi];
10568 json_object_int_add(json, "peerCount", ents);
10569 json_object_int_add(json, "peerMemory",
10570 ents * sizeof(struct peer));
10571
10572 if ((ents = listcount(bgp->group))) {
10573 json_object_int_add(
10574 json, "peerGroupCount", ents);
10575 json_object_int_add(
10576 json, "peerGroupMemory",
10577 ents * sizeof(struct
10578 peer_group));
10579 }
10580
10581 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10582 BGP_CONFIG_DAMPENING))
10583 json_object_boolean_true_add(
10584 json, "dampeningEnabled");
10585 } else {
10586 if (!show_terse) {
10587 if (bgp_maxmed_onstartup_configured(bgp)
10588 && bgp->maxmed_active)
10589 vty_out(vty,
10590 "Max-med on-startup active\n");
10591 if (bgp->v_maxmed_admin)
10592 vty_out(vty,
10593 "Max-med administrative active\n");
10594
10595 vty_out(vty,
10596 "BGP table version %" PRIu64
10597 "\n",
10598 bgp_table_version(
10599 bgp->rib[afi][safi]));
10600
10601 ents = bgp_table_count(
10602 bgp->rib[afi][safi]);
10603 vty_out(vty,
10604 "RIB entries %ld, using %s of memory\n",
10605 ents,
10606 mtype_memstr(
10607 memstrbuf,
10608 sizeof(memstrbuf),
10609 ents
10610 * sizeof(
10611 struct
10612 bgp_dest)));
10613
10614 /* Peer related usage */
10615 ents = bgp->af_peer_count[afi][safi];
10616 vty_out(vty,
10617 "Peers %ld, using %s of memory\n",
10618 ents,
10619 mtype_memstr(
10620 memstrbuf,
10621 sizeof(memstrbuf),
10622 ents
10623 * sizeof(
10624 struct
10625 peer)));
10626
10627 if ((ents = listcount(bgp->group)))
10628 vty_out(vty,
10629 "Peer groups %ld, using %s of memory\n",
10630 ents,
10631 mtype_memstr(
10632 memstrbuf,
10633 sizeof(memstrbuf),
10634 ents
10635 * sizeof(
10636 struct
10637 peer_group)));
10638
10639 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10640 BGP_CONFIG_DAMPENING))
10641 vty_out(vty,
10642 "Dampening enabled.\n");
10643 }
10644 if (show_failed) {
10645 vty_out(vty, "\n");
10646
10647 /* Subtract 8 here because 'Neighbor' is
10648 * 8 characters */
10649 vty_out(vty, "Neighbor");
10650 vty_out(vty, "%*s",
10651 max_neighbor_width - 8, " ");
10652 vty_out(vty,
10653 BGP_SHOW_SUMMARY_HEADER_FAILED);
10654 }
10655 }
10656 }
10657
10658 paf = peer_af_find(peer, afi, safi);
10659 filter = &peer->filter[afi][safi];
10660
10661 count++;
10662 /* Works for both failed & successful cases */
10663 if (peer_dynamic_neighbor(peer))
10664 dn_count++;
10665
10666 if (use_json) {
10667 json_peer = NULL;
10668 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10669 as_type, as)) {
10670 filtered_count++;
10671 continue;
10672 }
10673 if (show_failed &&
10674 bgp_has_peer_failed(peer, afi, safi)) {
10675 json_peer = json_object_new_object();
10676 bgp_show_failed_summary(vty, bgp, peer,
10677 json_peer, 0, use_json);
10678 } else if (!show_failed) {
10679 if (show_established
10680 && bgp_has_peer_failed(peer, afi, safi)) {
10681 filtered_count++;
10682 continue;
10683 }
10684
10685 json_peer = json_object_new_object();
10686 if (peer_dynamic_neighbor(peer)) {
10687 json_object_boolean_true_add(json_peer,
10688 "dynamicPeer");
10689 }
10690
10691 if (peer->hostname)
10692 json_object_string_add(json_peer, "hostname",
10693 peer->hostname);
10694
10695 if (peer->domainname)
10696 json_object_string_add(json_peer, "domainname",
10697 peer->domainname);
10698
10699 json_object_int_add(json_peer, "remoteAs", peer->as);
10700 json_object_int_add(
10701 json_peer, "localAs",
10702 peer->change_local_as
10703 ? peer->change_local_as
10704 : peer->local_as);
10705 json_object_int_add(json_peer, "version", 4);
10706 json_object_int_add(json_peer, "msgRcvd",
10707 PEER_TOTAL_RX(peer));
10708 json_object_int_add(json_peer, "msgSent",
10709 PEER_TOTAL_TX(peer));
10710
10711 atomic_size_t outq_count, inq_count;
10712 outq_count = atomic_load_explicit(
10713 &peer->obuf->count,
10714 memory_order_relaxed);
10715 inq_count = atomic_load_explicit(
10716 &peer->ibuf->count,
10717 memory_order_relaxed);
10718
10719 json_object_int_add(json_peer, "tableVersion",
10720 peer->version[afi][safi]);
10721 json_object_int_add(json_peer, "outq",
10722 outq_count);
10723 json_object_int_add(json_peer, "inq",
10724 inq_count);
10725 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10726 use_json, json_peer);
10727
10728 json_object_int_add(json_peer, "pfxRcd",
10729 peer->pcount[afi][pfx_rcd_safi]);
10730
10731 if (paf && PAF_SUBGRP(paf))
10732 json_object_int_add(
10733 json_peer, "pfxSnt",
10734 (PAF_SUBGRP(paf))->scount);
10735 else
10736 json_object_int_add(json_peer, "pfxSnt",
10737 0);
10738
10739 /* BGP FSM state */
10740 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10741 || CHECK_FLAG(peer->bgp->flags,
10742 BGP_FLAG_SHUTDOWN))
10743 json_object_string_add(json_peer,
10744 "state",
10745 "Idle (Admin)");
10746 else if (peer->afc_recv[afi][safi])
10747 json_object_string_add(
10748 json_peer, "state",
10749 lookup_msg(bgp_status_msg,
10750 peer->status, NULL));
10751 else if (CHECK_FLAG(
10752 peer->sflags,
10753 PEER_STATUS_PREFIX_OVERFLOW))
10754 json_object_string_add(json_peer,
10755 "state",
10756 "Idle (PfxCt)");
10757 else
10758 json_object_string_add(
10759 json_peer, "state",
10760 lookup_msg(bgp_status_msg,
10761 peer->status, NULL));
10762
10763 /* BGP peer state */
10764 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10765 || CHECK_FLAG(peer->bgp->flags,
10766 BGP_FLAG_SHUTDOWN))
10767 json_object_string_add(json_peer,
10768 "peerState",
10769 "Admin");
10770 else if (CHECK_FLAG(
10771 peer->sflags,
10772 PEER_STATUS_PREFIX_OVERFLOW))
10773 json_object_string_add(json_peer,
10774 "peerState",
10775 "PfxCt");
10776 else if (CHECK_FLAG(peer->flags,
10777 PEER_FLAG_PASSIVE))
10778 json_object_string_add(json_peer,
10779 "peerState",
10780 "Passive");
10781 else if (CHECK_FLAG(peer->sflags,
10782 PEER_STATUS_NSF_WAIT))
10783 json_object_string_add(json_peer,
10784 "peerState",
10785 "NSF passive");
10786 else if (CHECK_FLAG(
10787 peer->bgp->flags,
10788 BGP_FLAG_EBGP_REQUIRES_POLICY)
10789 && (!bgp_inbound_policy_exists(peer,
10790 filter)
10791 || !bgp_outbound_policy_exists(
10792 peer, filter)))
10793 json_object_string_add(json_peer,
10794 "peerState",
10795 "Policy");
10796 else
10797 json_object_string_add(
10798 json_peer, "peerState", "OK");
10799
10800 json_object_int_add(json_peer, "connectionsEstablished",
10801 peer->established);
10802 json_object_int_add(json_peer, "connectionsDropped",
10803 peer->dropped);
10804 if (peer->desc)
10805 json_object_string_add(
10806 json_peer, "desc", peer->desc);
10807 }
10808 /* Avoid creating empty peer dicts in JSON */
10809 if (json_peer == NULL)
10810 continue;
10811
10812 if (peer->conf_if)
10813 json_object_string_add(json_peer, "idType",
10814 "interface");
10815 else if (peer->su.sa.sa_family == AF_INET)
10816 json_object_string_add(json_peer, "idType",
10817 "ipv4");
10818 else if (peer->su.sa.sa_family == AF_INET6)
10819 json_object_string_add(json_peer, "idType",
10820 "ipv6");
10821 json_object_object_add(json_peers, peer->host,
10822 json_peer);
10823 } else {
10824 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10825 as_type, as)) {
10826 filtered_count++;
10827 continue;
10828 }
10829 if (show_failed &&
10830 bgp_has_peer_failed(peer, afi, safi)) {
10831 bgp_show_failed_summary(vty, bgp, peer, NULL,
10832 max_neighbor_width,
10833 use_json);
10834 } else if (!show_failed) {
10835 if (show_established
10836 && bgp_has_peer_failed(peer, afi, safi)) {
10837 filtered_count++;
10838 continue;
10839 }
10840
10841 if ((count - filtered_count) == 1) {
10842 /* display headline before the first
10843 * neighbor line */
10844 vty_out(vty, "\n");
10845
10846 /* Subtract 8 here because 'Neighbor' is
10847 * 8 characters */
10848 vty_out(vty, "Neighbor");
10849 vty_out(vty, "%*s",
10850 max_neighbor_width - 8, " ");
10851 vty_out(vty,
10852 show_wide
10853 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10854 : BGP_SHOW_SUMMARY_HEADER_ALL);
10855 }
10856
10857 memset(dn_flag, '\0', sizeof(dn_flag));
10858 if (peer_dynamic_neighbor(peer)) {
10859 dn_flag[0] = '*';
10860 }
10861
10862 if (peer->hostname
10863 && CHECK_FLAG(bgp->flags,
10864 BGP_FLAG_SHOW_HOSTNAME))
10865 len = vty_out(vty, "%s%s(%s)", dn_flag,
10866 peer->hostname,
10867 peer->host);
10868 else
10869 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10870
10871 /* pad the neighbor column with spaces */
10872 if (len < max_neighbor_width)
10873 vty_out(vty, "%*s", max_neighbor_width - len,
10874 " ");
10875
10876 atomic_size_t outq_count, inq_count;
10877 outq_count = atomic_load_explicit(
10878 &peer->obuf->count,
10879 memory_order_relaxed);
10880 inq_count = atomic_load_explicit(
10881 &peer->ibuf->count,
10882 memory_order_relaxed);
10883
10884 if (show_wide)
10885 vty_out(vty,
10886 "4 %10u %10u %9u %9u %8" PRIu64
10887 " %4zu %4zu %8s",
10888 peer->as,
10889 peer->change_local_as
10890 ? peer->change_local_as
10891 : peer->local_as,
10892 PEER_TOTAL_RX(peer),
10893 PEER_TOTAL_TX(peer),
10894 peer->version[afi][safi],
10895 inq_count, outq_count,
10896 peer_uptime(peer->uptime,
10897 timebuf,
10898 BGP_UPTIME_LEN, 0,
10899 NULL));
10900 else
10901 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10902 " %4zu %4zu %8s",
10903 peer->as, PEER_TOTAL_RX(peer),
10904 PEER_TOTAL_TX(peer),
10905 peer->version[afi][safi],
10906 inq_count, outq_count,
10907 peer_uptime(peer->uptime,
10908 timebuf,
10909 BGP_UPTIME_LEN, 0,
10910 NULL));
10911
10912 if (peer_established(peer)) {
10913 if (peer->afc_recv[afi][safi]) {
10914 if (CHECK_FLAG(
10915 bgp->flags,
10916 BGP_FLAG_EBGP_REQUIRES_POLICY)
10917 && !bgp_inbound_policy_exists(
10918 peer, filter))
10919 vty_out(vty, " %12s",
10920 "(Policy)");
10921 else
10922 vty_out(vty,
10923 " %12u",
10924 peer->pcount
10925 [afi]
10926 [pfx_rcd_safi]);
10927 } else {
10928 vty_out(vty, " NoNeg");
10929 }
10930
10931 if (paf && PAF_SUBGRP(paf)) {
10932 if (CHECK_FLAG(
10933 bgp->flags,
10934 BGP_FLAG_EBGP_REQUIRES_POLICY)
10935 && !bgp_outbound_policy_exists(
10936 peer, filter))
10937 vty_out(vty, " %8s",
10938 "(Policy)");
10939 else
10940 vty_out(vty,
10941 " %8u",
10942 (PAF_SUBGRP(
10943 paf))
10944 ->scount);
10945 } else {
10946 vty_out(vty, " NoNeg");
10947 }
10948 } else {
10949 if (CHECK_FLAG(peer->flags,
10950 PEER_FLAG_SHUTDOWN)
10951 || CHECK_FLAG(peer->bgp->flags,
10952 BGP_FLAG_SHUTDOWN))
10953 vty_out(vty, " Idle (Admin)");
10954 else if (CHECK_FLAG(
10955 peer->sflags,
10956 PEER_STATUS_PREFIX_OVERFLOW))
10957 vty_out(vty, " Idle (PfxCt)");
10958 else
10959 vty_out(vty, " %12s",
10960 lookup_msg(bgp_status_msg,
10961 peer->status, NULL));
10962
10963 vty_out(vty, " %8u", 0);
10964 }
10965 /* Make sure `Desc` column is the lastest in
10966 * the output.
10967 */
10968 if (peer->desc)
10969 vty_out(vty, " %s",
10970 bgp_peer_description_stripped(
10971 peer->desc,
10972 show_wide ? 64 : 20));
10973 else
10974 vty_out(vty, " N/A");
10975 vty_out(vty, "\n");
10976 }
10977
10978 }
10979 }
10980
10981 if (use_json) {
10982 json_object_object_add(json, "peers", json_peers);
10983 json_object_int_add(json, "failedPeers", failed_count);
10984 json_object_int_add(json, "displayedPeers",
10985 count - filtered_count);
10986 json_object_int_add(json, "totalPeers", count);
10987 json_object_int_add(json, "dynamicPeers", dn_count);
10988
10989 if (!show_failed)
10990 bgp_show_bestpath_json(bgp, json);
10991
10992 vty_json(vty, json);
10993 } else {
10994 if (count) {
10995 if (filtered_count == count)
10996 vty_out(vty, "\n%% No matching neighbor\n");
10997 else {
10998 if (show_failed)
10999 vty_out(vty, "\nDisplayed neighbors %d",
11000 failed_count);
11001 else if (as_type != AS_UNSPECIFIED || as
11002 || fpeer || show_established)
11003 vty_out(vty, "\nDisplayed neighbors %d",
11004 count - filtered_count);
11005
11006 vty_out(vty, "\nTotal number of neighbors %d\n",
11007 count);
11008 }
11009 } else {
11010 vty_out(vty, "No %s neighbor is configured\n",
11011 get_afi_safi_str(afi, safi, false));
11012 }
11013
11014 if (dn_count) {
11015 vty_out(vty, "* - dynamic neighbor\n");
11016 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11017 dn_count, bgp->dynamic_neighbors_limit);
11018 }
11019 }
11020
11021 return CMD_SUCCESS;
11022 }
11023
11024 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11025 int safi, struct peer *fpeer, int as_type,
11026 as_t as, uint16_t show_flags)
11027 {
11028 int is_first = 1;
11029 int afi_wildcard = (afi == AFI_MAX);
11030 int safi_wildcard = (safi == SAFI_MAX);
11031 int is_wildcard = (afi_wildcard || safi_wildcard);
11032 bool nbr_output = false;
11033 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11034
11035 if (use_json && is_wildcard)
11036 vty_out(vty, "{\n");
11037 if (afi_wildcard)
11038 afi = 1; /* AFI_IP */
11039 while (afi < AFI_MAX) {
11040 if (safi_wildcard)
11041 safi = 1; /* SAFI_UNICAST */
11042 while (safi < SAFI_MAX) {
11043 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11044 nbr_output = true;
11045
11046 if (is_wildcard) {
11047 /*
11048 * So limit output to those afi/safi
11049 * pairs that
11050 * actualy have something interesting in
11051 * them
11052 */
11053 if (use_json) {
11054 if (!is_first)
11055 vty_out(vty, ",\n");
11056 else
11057 is_first = 0;
11058
11059 vty_out(vty, "\"%s\":",
11060 get_afi_safi_str(afi,
11061 safi,
11062 true));
11063 } else {
11064 vty_out(vty,
11065 "\n%s Summary (%s):\n",
11066 get_afi_safi_str(afi,
11067 safi,
11068 false),
11069 bgp->name_pretty);
11070 }
11071 }
11072 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11073 as_type, as, show_flags);
11074 }
11075 safi++;
11076 if (!safi_wildcard)
11077 safi = SAFI_MAX;
11078 }
11079 afi++;
11080 if (!afi_wildcard)
11081 afi = AFI_MAX;
11082 }
11083
11084 if (use_json && is_wildcard)
11085 vty_out(vty, "}\n");
11086 else if (!nbr_output) {
11087 if (use_json)
11088 vty_out(vty, "{}\n");
11089 else
11090 vty_out(vty, "%% No BGP neighbors found in %s\n",
11091 bgp->name_pretty);
11092 }
11093 }
11094
11095 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11096 safi_t safi,
11097 const char *neighbor,
11098 int as_type, as_t as,
11099 uint16_t show_flags)
11100 {
11101 struct listnode *node, *nnode;
11102 struct bgp *bgp;
11103 struct peer *fpeer = NULL;
11104 int is_first = 1;
11105 bool nbr_output = false;
11106 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11107
11108 if (use_json)
11109 vty_out(vty, "{\n");
11110
11111 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11112 nbr_output = true;
11113 if (use_json) {
11114 if (!is_first)
11115 vty_out(vty, ",\n");
11116 else
11117 is_first = 0;
11118
11119 vty_out(vty, "\"%s\":",
11120 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11121 ? VRF_DEFAULT_NAME
11122 : bgp->name);
11123 }
11124 if (neighbor) {
11125 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11126 use_json);
11127 if (!fpeer)
11128 continue;
11129 }
11130 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11131 as, show_flags);
11132 }
11133
11134 if (use_json)
11135 vty_out(vty, "}\n");
11136 else if (!nbr_output)
11137 vty_out(vty, "%% BGP instance not found\n");
11138 }
11139
11140 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11141 safi_t safi, const char *neighbor, int as_type,
11142 as_t as, uint16_t show_flags)
11143 {
11144 struct bgp *bgp;
11145 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11146 struct peer *fpeer = NULL;
11147
11148 if (name) {
11149 if (strmatch(name, "all")) {
11150 bgp_show_all_instances_summary_vty(vty, afi, safi,
11151 neighbor, as_type,
11152 as, show_flags);
11153 return CMD_SUCCESS;
11154 } else {
11155 bgp = bgp_lookup_by_name(name);
11156
11157 if (!bgp) {
11158 if (use_json)
11159 vty_out(vty, "{}\n");
11160 else
11161 vty_out(vty,
11162 "%% BGP instance not found\n");
11163 return CMD_WARNING;
11164 }
11165
11166 if (neighbor) {
11167 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11168 use_json);
11169 if (!fpeer)
11170 return CMD_WARNING;
11171 }
11172 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11173 as_type, as, show_flags);
11174 return CMD_SUCCESS;
11175 }
11176 }
11177
11178 bgp = bgp_get_default();
11179
11180 if (bgp) {
11181 if (neighbor) {
11182 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11183 use_json);
11184 if (!fpeer)
11185 return CMD_WARNING;
11186 }
11187 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11188 as, show_flags);
11189 } else {
11190 if (use_json)
11191 vty_out(vty, "{}\n");
11192 else
11193 vty_out(vty, "%% BGP instance not found\n");
11194 return CMD_WARNING;
11195 }
11196
11197 return CMD_SUCCESS;
11198 }
11199
11200 /* `show [ip] bgp summary' commands. */
11201 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11202 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11203 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11204 "]] [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]",
11205 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11206 BGP_SAFI_WITH_LABEL_HELP_STR
11207 "Display the entries for all address families\n"
11208 "Summary of BGP neighbor status\n"
11209 "Show only sessions in Established state\n"
11210 "Show only sessions not in Established state\n"
11211 "Show only the specified neighbor session\n"
11212 "Neighbor to display information about\n"
11213 "Neighbor to display information about\n"
11214 "Neighbor on BGP configured interface\n"
11215 "Show only the specified remote AS sessions\n"
11216 "AS number\n"
11217 "Internal (iBGP) AS sessions\n"
11218 "External (eBGP) AS sessions\n"
11219 "Shorten the information on BGP instances\n"
11220 "Increase table width for longer output\n" JSON_STR)
11221 {
11222 char *vrf = NULL;
11223 afi_t afi = AFI_MAX;
11224 safi_t safi = SAFI_MAX;
11225 as_t as = 0; /* 0 means AS filter not set */
11226 int as_type = AS_UNSPECIFIED;
11227 uint16_t show_flags = 0;
11228
11229 int idx = 0;
11230
11231 /* show [ip] bgp */
11232 if (!all && argv_find(argv, argc, "ip", &idx))
11233 afi = AFI_IP;
11234 /* [<vrf> VIEWVRFNAME] */
11235 if (argv_find(argv, argc, "vrf", &idx)) {
11236 vrf = argv[idx + 1]->arg;
11237 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11238 vrf = NULL;
11239 } else if (argv_find(argv, argc, "view", &idx))
11240 /* [<view> VIEWVRFNAME] */
11241 vrf = argv[idx + 1]->arg;
11242 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11243 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11244 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11245 }
11246
11247 if (argv_find(argv, argc, "failed", &idx))
11248 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11249
11250 if (argv_find(argv, argc, "established", &idx))
11251 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11252
11253 if (argv_find(argv, argc, "remote-as", &idx)) {
11254 if (argv[idx + 1]->arg[0] == 'i')
11255 as_type = AS_INTERNAL;
11256 else if (argv[idx + 1]->arg[0] == 'e')
11257 as_type = AS_EXTERNAL;
11258 else
11259 as = (as_t)atoi(argv[idx + 1]->arg);
11260 }
11261
11262 if (argv_find(argv, argc, "terse", &idx))
11263 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11264
11265 if (argv_find(argv, argc, "wide", &idx))
11266 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11267
11268 if (argv_find(argv, argc, "json", &idx))
11269 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11270
11271 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11272 show_flags);
11273 }
11274
11275 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11276 {
11277 if (for_json)
11278 return get_afi_safi_json_str(afi, safi);
11279 else
11280 return get_afi_safi_vty_str(afi, safi);
11281 }
11282
11283
11284 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11285 afi_t afi, safi_t safi,
11286 uint16_t adv_smcap, uint16_t adv_rmcap,
11287 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11288 bool use_json, json_object *json_pref)
11289 {
11290 /* Send-Mode */
11291 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11292 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11293 if (use_json) {
11294 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11295 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11296 json_object_string_add(json_pref, "sendMode",
11297 "advertisedAndReceived");
11298 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11299 json_object_string_add(json_pref, "sendMode",
11300 "advertised");
11301 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11302 json_object_string_add(json_pref, "sendMode",
11303 "received");
11304 } else {
11305 vty_out(vty, " Send-mode: ");
11306 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11307 vty_out(vty, "advertised");
11308 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11309 vty_out(vty, "%sreceived",
11310 CHECK_FLAG(p->af_cap[afi][safi],
11311 adv_smcap)
11312 ? ", "
11313 : "");
11314 vty_out(vty, "\n");
11315 }
11316 }
11317
11318 /* Receive-Mode */
11319 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11320 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11321 if (use_json) {
11322 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11323 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11324 json_object_string_add(json_pref, "recvMode",
11325 "advertisedAndReceived");
11326 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11327 json_object_string_add(json_pref, "recvMode",
11328 "advertised");
11329 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11330 json_object_string_add(json_pref, "recvMode",
11331 "received");
11332 } else {
11333 vty_out(vty, " Receive-mode: ");
11334 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11335 vty_out(vty, "advertised");
11336 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11337 vty_out(vty, "%sreceived",
11338 CHECK_FLAG(p->af_cap[afi][safi],
11339 adv_rmcap)
11340 ? ", "
11341 : "");
11342 vty_out(vty, "\n");
11343 }
11344 }
11345 }
11346
11347 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11348 struct peer *p,
11349 bool use_json,
11350 json_object *json)
11351 {
11352 bool rbit = false;
11353 bool nbit = false;
11354
11355 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11356 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11357 && (peer_established(p))) {
11358 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11359 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11360 }
11361
11362 if (use_json) {
11363 json_object_boolean_add(json, "rBit", rbit);
11364 json_object_boolean_add(json, "nBit", nbit);
11365 } else {
11366 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11367 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11368 }
11369 }
11370
11371 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11372 struct peer *peer,
11373 bool use_json,
11374 json_object *json)
11375 {
11376 const char *mode = "NotApplicable";
11377
11378 if (!use_json)
11379 vty_out(vty, "\n Remote GR Mode: ");
11380
11381 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11382 && (peer_established(peer))) {
11383
11384 if ((peer->nsf_af_count == 0)
11385 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11386
11387 mode = "Disable";
11388
11389 } else if (peer->nsf_af_count == 0
11390 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11391
11392 mode = "Helper";
11393
11394 } else if (peer->nsf_af_count != 0
11395 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11396
11397 mode = "Restart";
11398 }
11399 }
11400
11401 if (use_json) {
11402 json_object_string_add(json, "remoteGrMode", mode);
11403 } else
11404 vty_out(vty, mode, "\n");
11405 }
11406
11407 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11408 struct peer *p,
11409 bool use_json,
11410 json_object *json)
11411 {
11412 const char *mode = "Invalid";
11413
11414 if (!use_json)
11415 vty_out(vty, " Local GR Mode: ");
11416
11417 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11418 mode = "Helper";
11419 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11420 mode = "Restart";
11421 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11422 mode = "Disable";
11423 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11424 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11425 mode = "Helper*";
11426 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11427 mode = "Restart*";
11428 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11429 mode = "Disable*";
11430 else
11431 mode = "Invalid*";
11432 }
11433
11434 if (use_json) {
11435 json_object_string_add(json, "localGrMode", mode);
11436 } else {
11437 vty_out(vty, mode, "\n");
11438 }
11439 }
11440
11441 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11442 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11443 {
11444 afi_t afi;
11445 safi_t safi;
11446 json_object *json_afi_safi = NULL;
11447 json_object *json_timer = NULL;
11448 json_object *json_endofrib_status = NULL;
11449 bool eor_flag = false;
11450
11451 FOREACH_AFI_SAFI_NSF (afi, safi) {
11452 if (!peer->afc[afi][safi])
11453 continue;
11454
11455 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11456 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11457 continue;
11458
11459 if (use_json) {
11460 json_afi_safi = json_object_new_object();
11461 json_endofrib_status = json_object_new_object();
11462 json_timer = json_object_new_object();
11463 }
11464
11465 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11466 eor_flag = true;
11467 else
11468 eor_flag = false;
11469
11470 if (!use_json) {
11471 vty_out(vty, " %s:\n",
11472 get_afi_safi_str(afi, safi, false));
11473
11474 vty_out(vty, " F bit: ");
11475 }
11476
11477 if (peer->nsf[afi][safi] &&
11478 CHECK_FLAG(peer->af_cap[afi][safi],
11479 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11480
11481 if (use_json) {
11482 json_object_boolean_true_add(json_afi_safi,
11483 "fBit");
11484 } else
11485 vty_out(vty, "True\n");
11486 } else {
11487 if (use_json)
11488 json_object_boolean_false_add(json_afi_safi,
11489 "fBit");
11490 else
11491 vty_out(vty, "False\n");
11492 }
11493
11494 if (!use_json)
11495 vty_out(vty, " End-of-RIB sent: ");
11496
11497 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11498 PEER_STATUS_EOR_SEND)) {
11499 if (use_json) {
11500 json_object_boolean_true_add(
11501 json_endofrib_status, "endOfRibSend");
11502
11503 PRINT_EOR_JSON(eor_flag);
11504 } else {
11505 vty_out(vty, "Yes\n");
11506 vty_out(vty,
11507 " End-of-RIB sent after update: ");
11508
11509 PRINT_EOR(eor_flag);
11510 }
11511 } else {
11512 if (use_json) {
11513 json_object_boolean_false_add(
11514 json_endofrib_status, "endOfRibSend");
11515 json_object_boolean_false_add(
11516 json_endofrib_status,
11517 "endOfRibSentAfterUpdate");
11518 } else {
11519 vty_out(vty, "No\n");
11520 vty_out(vty,
11521 " End-of-RIB sent after update: ");
11522 vty_out(vty, "No\n");
11523 }
11524 }
11525
11526 if (!use_json)
11527 vty_out(vty, " End-of-RIB received: ");
11528
11529 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11530 PEER_STATUS_EOR_RECEIVED)) {
11531 if (use_json)
11532 json_object_boolean_true_add(
11533 json_endofrib_status, "endOfRibRecv");
11534 else
11535 vty_out(vty, "Yes\n");
11536 } else {
11537 if (use_json)
11538 json_object_boolean_false_add(
11539 json_endofrib_status, "endOfRibRecv");
11540 else
11541 vty_out(vty, "No\n");
11542 }
11543
11544 if (use_json) {
11545 json_object_int_add(json_timer, "stalePathTimer",
11546 peer->bgp->stalepath_time);
11547
11548 if (peer->t_gr_stale != NULL) {
11549 json_object_int_add(json_timer,
11550 "stalePathTimerRemaining",
11551 thread_timer_remain_second(
11552 peer->t_gr_stale));
11553 }
11554
11555 /* Display Configured Selection
11556 * Deferral only when when
11557 * Gr mode is enabled.
11558 */
11559 if (CHECK_FLAG(peer->flags,
11560 PEER_FLAG_GRACEFUL_RESTART)) {
11561 json_object_int_add(json_timer,
11562 "selectionDeferralTimer",
11563 peer->bgp->stalepath_time);
11564 }
11565
11566 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11567 NULL) {
11568
11569 json_object_int_add(
11570 json_timer,
11571 "selectionDeferralTimerRemaining",
11572 thread_timer_remain_second(
11573 peer->bgp->gr_info[afi][safi]
11574 .t_select_deferral));
11575 }
11576 } else {
11577 vty_out(vty, " Timers:\n");
11578 vty_out(vty,
11579 " Configured Stale Path Time(sec): %u\n",
11580 peer->bgp->stalepath_time);
11581
11582 if (peer->t_gr_stale != NULL)
11583 vty_out(vty,
11584 " Stale Path Remaining(sec): %ld\n",
11585 thread_timer_remain_second(
11586 peer->t_gr_stale));
11587 /* Display Configured Selection
11588 * Deferral only when when
11589 * Gr mode is enabled.
11590 */
11591 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11592 vty_out(vty,
11593 " Configured Selection Deferral Time(sec): %u\n",
11594 peer->bgp->select_defer_time);
11595
11596 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11597 NULL)
11598 vty_out(vty,
11599 " Selection Deferral Time Remaining(sec): %ld\n",
11600 thread_timer_remain_second(
11601 peer->bgp->gr_info[afi][safi]
11602 .t_select_deferral));
11603 }
11604 if (use_json) {
11605 json_object_object_add(json_afi_safi, "endOfRibStatus",
11606 json_endofrib_status);
11607 json_object_object_add(json_afi_safi, "timers",
11608 json_timer);
11609 json_object_object_add(
11610 json, get_afi_safi_str(afi, safi, true),
11611 json_afi_safi);
11612 }
11613 }
11614 }
11615
11616 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11617 struct peer *p,
11618 bool use_json,
11619 json_object *json)
11620 {
11621 if (use_json) {
11622 json_object *json_timer = NULL;
11623
11624 json_timer = json_object_new_object();
11625
11626 json_object_int_add(json_timer, "configuredRestartTimer",
11627 p->bgp->restart_time);
11628
11629 json_object_int_add(json_timer, "receivedRestartTimer",
11630 p->v_gr_restart);
11631
11632 if (p->t_gr_restart != NULL)
11633 json_object_int_add(
11634 json_timer, "restartTimerRemaining",
11635 thread_timer_remain_second(p->t_gr_restart));
11636
11637 json_object_object_add(json, "timers", json_timer);
11638 } else {
11639
11640 vty_out(vty, " Timers:\n");
11641 vty_out(vty, " Configured Restart Time(sec): %u\n",
11642 p->bgp->restart_time);
11643
11644 vty_out(vty, " Received Restart Time(sec): %u\n",
11645 p->v_gr_restart);
11646 if (p->t_gr_restart != NULL)
11647 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11648 thread_timer_remain_second(p->t_gr_restart));
11649 if (p->t_gr_restart != NULL) {
11650 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11651 thread_timer_remain_second(p->t_gr_restart));
11652 }
11653 }
11654 }
11655
11656 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11657 bool use_json, json_object *json)
11658 {
11659 char buf[SU_ADDRSTRLEN] = {0};
11660 char dn_flag[2] = {0};
11661 /* '*' + v6 address of neighbor */
11662 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11663
11664 if (!p->conf_if && peer_dynamic_neighbor(p))
11665 dn_flag[0] = '*';
11666
11667 if (p->conf_if) {
11668 if (use_json)
11669 json_object_string_add(
11670 json, "neighborAddr",
11671 BGP_PEER_SU_UNSPEC(p)
11672 ? "none"
11673 : sockunion2str(&p->su, buf,
11674 SU_ADDRSTRLEN));
11675 else
11676 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11677 BGP_PEER_SU_UNSPEC(p)
11678 ? "none"
11679 : sockunion2str(&p->su, buf,
11680 SU_ADDRSTRLEN));
11681 } else {
11682 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11683 p->host);
11684
11685 if (use_json)
11686 json_object_string_add(json, "neighborAddr",
11687 neighborAddr);
11688 else
11689 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11690 }
11691
11692 /* more gr info in new format */
11693 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11694 }
11695
11696 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11697 safi_t safi, bool use_json,
11698 json_object *json_neigh)
11699 {
11700 struct bgp_filter *filter;
11701 struct peer_af *paf;
11702 char orf_pfx_name[BUFSIZ];
11703 int orf_pfx_count;
11704 json_object *json_af = NULL;
11705 json_object *json_prefA = NULL;
11706 json_object *json_prefB = NULL;
11707 json_object *json_addr = NULL;
11708 json_object *json_advmap = NULL;
11709
11710 if (use_json) {
11711 json_addr = json_object_new_object();
11712 json_af = json_object_new_object();
11713 filter = &p->filter[afi][safi];
11714
11715 if (peer_group_active(p))
11716 json_object_string_add(json_addr, "peerGroupMember",
11717 p->group->name);
11718
11719 paf = peer_af_find(p, afi, safi);
11720 if (paf && PAF_SUBGRP(paf)) {
11721 json_object_int_add(json_addr, "updateGroupId",
11722 PAF_UPDGRP(paf)->id);
11723 json_object_int_add(json_addr, "subGroupId",
11724 PAF_SUBGRP(paf)->id);
11725 json_object_int_add(json_addr, "packetQueueLength",
11726 bpacket_queue_virtual_length(paf));
11727 }
11728
11729 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11730 || CHECK_FLAG(p->af_cap[afi][safi],
11731 PEER_CAP_ORF_PREFIX_SM_RCV)
11732 || CHECK_FLAG(p->af_cap[afi][safi],
11733 PEER_CAP_ORF_PREFIX_RM_ADV)
11734 || CHECK_FLAG(p->af_cap[afi][safi],
11735 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11736 json_object_int_add(json_af, "orfType",
11737 ORF_TYPE_PREFIX);
11738 json_prefA = json_object_new_object();
11739 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11740 PEER_CAP_ORF_PREFIX_SM_ADV,
11741 PEER_CAP_ORF_PREFIX_RM_ADV,
11742 PEER_CAP_ORF_PREFIX_SM_RCV,
11743 PEER_CAP_ORF_PREFIX_RM_RCV,
11744 use_json, json_prefA);
11745 json_object_object_add(json_af, "orfPrefixList",
11746 json_prefA);
11747 }
11748
11749 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11750 || CHECK_FLAG(p->af_cap[afi][safi],
11751 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11752 || CHECK_FLAG(p->af_cap[afi][safi],
11753 PEER_CAP_ORF_PREFIX_RM_ADV)
11754 || CHECK_FLAG(p->af_cap[afi][safi],
11755 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11756 json_object_int_add(json_af, "orfOldType",
11757 ORF_TYPE_PREFIX_OLD);
11758 json_prefB = json_object_new_object();
11759 bgp_show_peer_afi_orf_cap(
11760 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11761 PEER_CAP_ORF_PREFIX_RM_ADV,
11762 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11763 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11764 json_prefB);
11765 json_object_object_add(json_af, "orfOldPrefixList",
11766 json_prefB);
11767 }
11768
11769 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11770 || CHECK_FLAG(p->af_cap[afi][safi],
11771 PEER_CAP_ORF_PREFIX_SM_RCV)
11772 || CHECK_FLAG(p->af_cap[afi][safi],
11773 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11774 || CHECK_FLAG(p->af_cap[afi][safi],
11775 PEER_CAP_ORF_PREFIX_RM_ADV)
11776 || CHECK_FLAG(p->af_cap[afi][safi],
11777 PEER_CAP_ORF_PREFIX_RM_RCV)
11778 || CHECK_FLAG(p->af_cap[afi][safi],
11779 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11780 json_object_object_add(json_addr, "afDependentCap",
11781 json_af);
11782 else
11783 json_object_free(json_af);
11784
11785 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11786 p->host, afi, safi);
11787 orf_pfx_count = prefix_bgp_show_prefix_list(
11788 NULL, afi, orf_pfx_name, use_json);
11789
11790 if (CHECK_FLAG(p->af_sflags[afi][safi],
11791 PEER_STATUS_ORF_PREFIX_SEND)
11792 || orf_pfx_count) {
11793 if (CHECK_FLAG(p->af_sflags[afi][safi],
11794 PEER_STATUS_ORF_PREFIX_SEND))
11795 json_object_boolean_true_add(json_neigh,
11796 "orfSent");
11797 if (orf_pfx_count)
11798 json_object_int_add(json_addr, "orfRecvCounter",
11799 orf_pfx_count);
11800 }
11801 if (CHECK_FLAG(p->af_sflags[afi][safi],
11802 PEER_STATUS_ORF_WAIT_REFRESH))
11803 json_object_string_add(
11804 json_addr, "orfFirstUpdate",
11805 "deferredUntilORFOrRouteRefreshRecvd");
11806
11807 if (CHECK_FLAG(p->af_flags[afi][safi],
11808 PEER_FLAG_REFLECTOR_CLIENT))
11809 json_object_boolean_true_add(json_addr,
11810 "routeReflectorClient");
11811 if (CHECK_FLAG(p->af_flags[afi][safi],
11812 PEER_FLAG_RSERVER_CLIENT))
11813 json_object_boolean_true_add(json_addr,
11814 "routeServerClient");
11815 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11816 json_object_boolean_true_add(json_addr,
11817 "inboundSoftConfigPermit");
11818
11819 if (CHECK_FLAG(p->af_flags[afi][safi],
11820 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11821 json_object_boolean_true_add(
11822 json_addr,
11823 "privateAsNumsAllReplacedInUpdatesToNbr");
11824 else if (CHECK_FLAG(p->af_flags[afi][safi],
11825 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11826 json_object_boolean_true_add(
11827 json_addr,
11828 "privateAsNumsReplacedInUpdatesToNbr");
11829 else if (CHECK_FLAG(p->af_flags[afi][safi],
11830 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11831 json_object_boolean_true_add(
11832 json_addr,
11833 "privateAsNumsAllRemovedInUpdatesToNbr");
11834 else if (CHECK_FLAG(p->af_flags[afi][safi],
11835 PEER_FLAG_REMOVE_PRIVATE_AS))
11836 json_object_boolean_true_add(
11837 json_addr,
11838 "privateAsNumsRemovedInUpdatesToNbr");
11839
11840 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11841 json_object_boolean_true_add(
11842 json_addr,
11843 bgp_addpath_names(p->addpath_type[afi][safi])
11844 ->type_json_name);
11845
11846 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11847 json_object_string_add(json_addr,
11848 "overrideASNsInOutboundUpdates",
11849 "ifAspathEqualRemoteAs");
11850
11851 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11852 || CHECK_FLAG(p->af_flags[afi][safi],
11853 PEER_FLAG_FORCE_NEXTHOP_SELF))
11854 json_object_boolean_true_add(json_addr,
11855 "routerAlwaysNextHop");
11856 if (CHECK_FLAG(p->af_flags[afi][safi],
11857 PEER_FLAG_AS_PATH_UNCHANGED))
11858 json_object_boolean_true_add(
11859 json_addr, "unchangedAsPathPropogatedToNbr");
11860 if (CHECK_FLAG(p->af_flags[afi][safi],
11861 PEER_FLAG_NEXTHOP_UNCHANGED))
11862 json_object_boolean_true_add(
11863 json_addr, "unchangedNextHopPropogatedToNbr");
11864 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11865 json_object_boolean_true_add(
11866 json_addr, "unchangedMedPropogatedToNbr");
11867 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11868 || CHECK_FLAG(p->af_flags[afi][safi],
11869 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11870 if (CHECK_FLAG(p->af_flags[afi][safi],
11871 PEER_FLAG_SEND_COMMUNITY)
11872 && CHECK_FLAG(p->af_flags[afi][safi],
11873 PEER_FLAG_SEND_EXT_COMMUNITY))
11874 json_object_string_add(json_addr,
11875 "commAttriSentToNbr",
11876 "extendedAndStandard");
11877 else if (CHECK_FLAG(p->af_flags[afi][safi],
11878 PEER_FLAG_SEND_EXT_COMMUNITY))
11879 json_object_string_add(json_addr,
11880 "commAttriSentToNbr",
11881 "extended");
11882 else
11883 json_object_string_add(json_addr,
11884 "commAttriSentToNbr",
11885 "standard");
11886 }
11887 if (CHECK_FLAG(p->af_flags[afi][safi],
11888 PEER_FLAG_DEFAULT_ORIGINATE)) {
11889 if (p->default_rmap[afi][safi].name)
11890 json_object_string_add(
11891 json_addr, "defaultRouteMap",
11892 p->default_rmap[afi][safi].name);
11893
11894 if (paf && PAF_SUBGRP(paf)
11895 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11896 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11897 json_object_boolean_true_add(json_addr,
11898 "defaultSent");
11899 else
11900 json_object_boolean_true_add(json_addr,
11901 "defaultNotSent");
11902 }
11903
11904 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11905 if (is_evpn_enabled())
11906 json_object_boolean_true_add(
11907 json_addr, "advertiseAllVnis");
11908 }
11909
11910 if (filter->plist[FILTER_IN].name
11911 || filter->dlist[FILTER_IN].name
11912 || filter->aslist[FILTER_IN].name
11913 || filter->map[RMAP_IN].name)
11914 json_object_boolean_true_add(json_addr,
11915 "inboundPathPolicyConfig");
11916 if (filter->plist[FILTER_OUT].name
11917 || filter->dlist[FILTER_OUT].name
11918 || filter->aslist[FILTER_OUT].name
11919 || filter->map[RMAP_OUT].name || filter->usmap.name)
11920 json_object_boolean_true_add(
11921 json_addr, "outboundPathPolicyConfig");
11922
11923 /* prefix-list */
11924 if (filter->plist[FILTER_IN].name)
11925 json_object_string_add(json_addr,
11926 "incomingUpdatePrefixFilterList",
11927 filter->plist[FILTER_IN].name);
11928 if (filter->plist[FILTER_OUT].name)
11929 json_object_string_add(json_addr,
11930 "outgoingUpdatePrefixFilterList",
11931 filter->plist[FILTER_OUT].name);
11932
11933 /* distribute-list */
11934 if (filter->dlist[FILTER_IN].name)
11935 json_object_string_add(
11936 json_addr, "incomingUpdateNetworkFilterList",
11937 filter->dlist[FILTER_IN].name);
11938 if (filter->dlist[FILTER_OUT].name)
11939 json_object_string_add(
11940 json_addr, "outgoingUpdateNetworkFilterList",
11941 filter->dlist[FILTER_OUT].name);
11942
11943 /* filter-list. */
11944 if (filter->aslist[FILTER_IN].name)
11945 json_object_string_add(json_addr,
11946 "incomingUpdateAsPathFilterList",
11947 filter->aslist[FILTER_IN].name);
11948 if (filter->aslist[FILTER_OUT].name)
11949 json_object_string_add(json_addr,
11950 "outgoingUpdateAsPathFilterList",
11951 filter->aslist[FILTER_OUT].name);
11952
11953 /* route-map. */
11954 if (filter->map[RMAP_IN].name)
11955 json_object_string_add(
11956 json_addr, "routeMapForIncomingAdvertisements",
11957 filter->map[RMAP_IN].name);
11958 if (filter->map[RMAP_OUT].name)
11959 json_object_string_add(
11960 json_addr, "routeMapForOutgoingAdvertisements",
11961 filter->map[RMAP_OUT].name);
11962
11963 /* ebgp-requires-policy (inbound) */
11964 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11965 && !bgp_inbound_policy_exists(p, filter))
11966 json_object_string_add(
11967 json_addr, "inboundEbgpRequiresPolicy",
11968 "Inbound updates discarded due to missing policy");
11969
11970 /* ebgp-requires-policy (outbound) */
11971 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11972 && (!bgp_outbound_policy_exists(p, filter)))
11973 json_object_string_add(
11974 json_addr, "outboundEbgpRequiresPolicy",
11975 "Outbound updates discarded due to missing policy");
11976
11977 /* unsuppress-map */
11978 if (filter->usmap.name)
11979 json_object_string_add(json_addr,
11980 "selectiveUnsuppressRouteMap",
11981 filter->usmap.name);
11982
11983 /* advertise-map */
11984 if (filter->advmap.aname) {
11985 json_advmap = json_object_new_object();
11986 json_object_string_add(json_advmap, "condition",
11987 filter->advmap.condition
11988 ? "EXIST"
11989 : "NON_EXIST");
11990 json_object_string_add(json_advmap, "conditionMap",
11991 filter->advmap.cname);
11992 json_object_string_add(json_advmap, "advertiseMap",
11993 filter->advmap.aname);
11994 json_object_string_add(json_advmap, "advertiseStatus",
11995 filter->advmap.update_type
11996 == ADVERTISE
11997 ? "Advertise"
11998 : "Withdraw");
11999 json_object_object_add(json_addr, "advertiseMap",
12000 json_advmap);
12001 }
12002
12003 /* Receive prefix count */
12004 json_object_int_add(json_addr, "acceptedPrefixCounter",
12005 p->pcount[afi][safi]);
12006 if (paf && PAF_SUBGRP(paf))
12007 json_object_int_add(json_addr, "sentPrefixCounter",
12008 (PAF_SUBGRP(paf))->scount);
12009
12010 /* Maximum prefix */
12011 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12012 json_object_int_add(json_addr, "prefixOutAllowedMax",
12013 p->pmax_out[afi][safi]);
12014
12015 /* Maximum prefix */
12016 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12017 json_object_int_add(json_addr, "prefixAllowedMax",
12018 p->pmax[afi][safi]);
12019 if (CHECK_FLAG(p->af_flags[afi][safi],
12020 PEER_FLAG_MAX_PREFIX_WARNING))
12021 json_object_boolean_true_add(
12022 json_addr, "prefixAllowedMaxWarning");
12023 json_object_int_add(json_addr,
12024 "prefixAllowedWarningThresh",
12025 p->pmax_threshold[afi][safi]);
12026 if (p->pmax_restart[afi][safi])
12027 json_object_int_add(
12028 json_addr,
12029 "prefixAllowedRestartIntervalMsecs",
12030 p->pmax_restart[afi][safi] * 60000);
12031 }
12032 json_object_object_add(json_neigh,
12033 get_afi_safi_str(afi, safi, true),
12034 json_addr);
12035
12036 } else {
12037 filter = &p->filter[afi][safi];
12038
12039 vty_out(vty, " For address family: %s\n",
12040 get_afi_safi_str(afi, safi, false));
12041
12042 if (peer_group_active(p))
12043 vty_out(vty, " %s peer-group member\n",
12044 p->group->name);
12045
12046 paf = peer_af_find(p, afi, safi);
12047 if (paf && PAF_SUBGRP(paf)) {
12048 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12049 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12050 vty_out(vty, " Packet Queue length %d\n",
12051 bpacket_queue_virtual_length(paf));
12052 } else {
12053 vty_out(vty, " Not part of any update group\n");
12054 }
12055 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12056 || CHECK_FLAG(p->af_cap[afi][safi],
12057 PEER_CAP_ORF_PREFIX_SM_RCV)
12058 || CHECK_FLAG(p->af_cap[afi][safi],
12059 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12060 || CHECK_FLAG(p->af_cap[afi][safi],
12061 PEER_CAP_ORF_PREFIX_RM_ADV)
12062 || CHECK_FLAG(p->af_cap[afi][safi],
12063 PEER_CAP_ORF_PREFIX_RM_RCV)
12064 || CHECK_FLAG(p->af_cap[afi][safi],
12065 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12066 vty_out(vty, " AF-dependant capabilities:\n");
12067
12068 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12069 || CHECK_FLAG(p->af_cap[afi][safi],
12070 PEER_CAP_ORF_PREFIX_SM_RCV)
12071 || CHECK_FLAG(p->af_cap[afi][safi],
12072 PEER_CAP_ORF_PREFIX_RM_ADV)
12073 || CHECK_FLAG(p->af_cap[afi][safi],
12074 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12075 vty_out(vty,
12076 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12077 ORF_TYPE_PREFIX);
12078 bgp_show_peer_afi_orf_cap(
12079 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12080 PEER_CAP_ORF_PREFIX_RM_ADV,
12081 PEER_CAP_ORF_PREFIX_SM_RCV,
12082 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12083 }
12084 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12085 || CHECK_FLAG(p->af_cap[afi][safi],
12086 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12087 || CHECK_FLAG(p->af_cap[afi][safi],
12088 PEER_CAP_ORF_PREFIX_RM_ADV)
12089 || CHECK_FLAG(p->af_cap[afi][safi],
12090 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12091 vty_out(vty,
12092 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12093 ORF_TYPE_PREFIX_OLD);
12094 bgp_show_peer_afi_orf_cap(
12095 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12096 PEER_CAP_ORF_PREFIX_RM_ADV,
12097 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12098 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12099 }
12100
12101 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12102 p->host, afi, safi);
12103 orf_pfx_count = prefix_bgp_show_prefix_list(
12104 NULL, afi, orf_pfx_name, use_json);
12105
12106 if (CHECK_FLAG(p->af_sflags[afi][safi],
12107 PEER_STATUS_ORF_PREFIX_SEND)
12108 || orf_pfx_count) {
12109 vty_out(vty, " Outbound Route Filter (ORF):");
12110 if (CHECK_FLAG(p->af_sflags[afi][safi],
12111 PEER_STATUS_ORF_PREFIX_SEND))
12112 vty_out(vty, " sent;");
12113 if (orf_pfx_count)
12114 vty_out(vty, " received (%d entries)",
12115 orf_pfx_count);
12116 vty_out(vty, "\n");
12117 }
12118 if (CHECK_FLAG(p->af_sflags[afi][safi],
12119 PEER_STATUS_ORF_WAIT_REFRESH))
12120 vty_out(vty,
12121 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12122
12123 if (CHECK_FLAG(p->af_flags[afi][safi],
12124 PEER_FLAG_REFLECTOR_CLIENT))
12125 vty_out(vty, " Route-Reflector Client\n");
12126 if (CHECK_FLAG(p->af_flags[afi][safi],
12127 PEER_FLAG_RSERVER_CLIENT))
12128 vty_out(vty, " Route-Server Client\n");
12129 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12130 vty_out(vty,
12131 " Inbound soft reconfiguration allowed\n");
12132
12133 if (CHECK_FLAG(p->af_flags[afi][safi],
12134 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12135 vty_out(vty,
12136 " Private AS numbers (all) replaced in updates to this neighbor\n");
12137 else if (CHECK_FLAG(p->af_flags[afi][safi],
12138 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12139 vty_out(vty,
12140 " Private AS numbers replaced in updates to this neighbor\n");
12141 else if (CHECK_FLAG(p->af_flags[afi][safi],
12142 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12143 vty_out(vty,
12144 " Private AS numbers (all) removed in updates to this neighbor\n");
12145 else if (CHECK_FLAG(p->af_flags[afi][safi],
12146 PEER_FLAG_REMOVE_PRIVATE_AS))
12147 vty_out(vty,
12148 " Private AS numbers removed in updates to this neighbor\n");
12149
12150 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12151 vty_out(vty, " %s\n",
12152 bgp_addpath_names(p->addpath_type[afi][safi])
12153 ->human_description);
12154
12155 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12156 vty_out(vty,
12157 " Override ASNs in outbound updates if aspath equals remote-as\n");
12158
12159 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12160 || CHECK_FLAG(p->af_flags[afi][safi],
12161 PEER_FLAG_FORCE_NEXTHOP_SELF))
12162 vty_out(vty, " NEXT_HOP is always this router\n");
12163 if (CHECK_FLAG(p->af_flags[afi][safi],
12164 PEER_FLAG_AS_PATH_UNCHANGED))
12165 vty_out(vty,
12166 " AS_PATH is propagated unchanged to this neighbor\n");
12167 if (CHECK_FLAG(p->af_flags[afi][safi],
12168 PEER_FLAG_NEXTHOP_UNCHANGED))
12169 vty_out(vty,
12170 " NEXT_HOP is propagated unchanged to this neighbor\n");
12171 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12172 vty_out(vty,
12173 " MED is propagated unchanged to this neighbor\n");
12174 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12175 || CHECK_FLAG(p->af_flags[afi][safi],
12176 PEER_FLAG_SEND_EXT_COMMUNITY)
12177 || CHECK_FLAG(p->af_flags[afi][safi],
12178 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12179 vty_out(vty,
12180 " Community attribute sent to this neighbor");
12181 if (CHECK_FLAG(p->af_flags[afi][safi],
12182 PEER_FLAG_SEND_COMMUNITY)
12183 && CHECK_FLAG(p->af_flags[afi][safi],
12184 PEER_FLAG_SEND_EXT_COMMUNITY)
12185 && CHECK_FLAG(p->af_flags[afi][safi],
12186 PEER_FLAG_SEND_LARGE_COMMUNITY))
12187 vty_out(vty, "(all)\n");
12188 else if (CHECK_FLAG(p->af_flags[afi][safi],
12189 PEER_FLAG_SEND_LARGE_COMMUNITY))
12190 vty_out(vty, "(large)\n");
12191 else if (CHECK_FLAG(p->af_flags[afi][safi],
12192 PEER_FLAG_SEND_EXT_COMMUNITY))
12193 vty_out(vty, "(extended)\n");
12194 else
12195 vty_out(vty, "(standard)\n");
12196 }
12197 if (CHECK_FLAG(p->af_flags[afi][safi],
12198 PEER_FLAG_DEFAULT_ORIGINATE)) {
12199 vty_out(vty, " Default information originate,");
12200
12201 if (p->default_rmap[afi][safi].name)
12202 vty_out(vty, " default route-map %s%s,",
12203 p->default_rmap[afi][safi].map ? "*"
12204 : "",
12205 p->default_rmap[afi][safi].name);
12206 if (paf && PAF_SUBGRP(paf)
12207 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12208 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12209 vty_out(vty, " default sent\n");
12210 else
12211 vty_out(vty, " default not sent\n");
12212 }
12213
12214 /* advertise-vni-all */
12215 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12216 if (is_evpn_enabled())
12217 vty_out(vty, " advertise-all-vni\n");
12218 }
12219
12220 if (filter->plist[FILTER_IN].name
12221 || filter->dlist[FILTER_IN].name
12222 || filter->aslist[FILTER_IN].name
12223 || filter->map[RMAP_IN].name)
12224 vty_out(vty, " Inbound path policy configured\n");
12225 if (filter->plist[FILTER_OUT].name
12226 || filter->dlist[FILTER_OUT].name
12227 || filter->aslist[FILTER_OUT].name
12228 || filter->map[RMAP_OUT].name || filter->usmap.name)
12229 vty_out(vty, " Outbound path policy configured\n");
12230
12231 /* prefix-list */
12232 if (filter->plist[FILTER_IN].name)
12233 vty_out(vty,
12234 " Incoming update prefix filter list is %s%s\n",
12235 filter->plist[FILTER_IN].plist ? "*" : "",
12236 filter->plist[FILTER_IN].name);
12237 if (filter->plist[FILTER_OUT].name)
12238 vty_out(vty,
12239 " Outgoing update prefix filter list is %s%s\n",
12240 filter->plist[FILTER_OUT].plist ? "*" : "",
12241 filter->plist[FILTER_OUT].name);
12242
12243 /* distribute-list */
12244 if (filter->dlist[FILTER_IN].name)
12245 vty_out(vty,
12246 " Incoming update network filter list is %s%s\n",
12247 filter->dlist[FILTER_IN].alist ? "*" : "",
12248 filter->dlist[FILTER_IN].name);
12249 if (filter->dlist[FILTER_OUT].name)
12250 vty_out(vty,
12251 " Outgoing update network filter list is %s%s\n",
12252 filter->dlist[FILTER_OUT].alist ? "*" : "",
12253 filter->dlist[FILTER_OUT].name);
12254
12255 /* filter-list. */
12256 if (filter->aslist[FILTER_IN].name)
12257 vty_out(vty,
12258 " Incoming update AS path filter list is %s%s\n",
12259 filter->aslist[FILTER_IN].aslist ? "*" : "",
12260 filter->aslist[FILTER_IN].name);
12261 if (filter->aslist[FILTER_OUT].name)
12262 vty_out(vty,
12263 " Outgoing update AS path filter list is %s%s\n",
12264 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12265 filter->aslist[FILTER_OUT].name);
12266
12267 /* route-map. */
12268 if (filter->map[RMAP_IN].name)
12269 vty_out(vty,
12270 " Route map for incoming advertisements is %s%s\n",
12271 filter->map[RMAP_IN].map ? "*" : "",
12272 filter->map[RMAP_IN].name);
12273 if (filter->map[RMAP_OUT].name)
12274 vty_out(vty,
12275 " Route map for outgoing advertisements is %s%s\n",
12276 filter->map[RMAP_OUT].map ? "*" : "",
12277 filter->map[RMAP_OUT].name);
12278
12279 /* ebgp-requires-policy (inbound) */
12280 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12281 && !bgp_inbound_policy_exists(p, filter))
12282 vty_out(vty,
12283 " Inbound updates discarded due to missing policy\n");
12284
12285 /* ebgp-requires-policy (outbound) */
12286 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12287 && !bgp_outbound_policy_exists(p, filter))
12288 vty_out(vty,
12289 " Outbound updates discarded due to missing policy\n");
12290
12291 /* unsuppress-map */
12292 if (filter->usmap.name)
12293 vty_out(vty,
12294 " Route map for selective unsuppress is %s%s\n",
12295 filter->usmap.map ? "*" : "",
12296 filter->usmap.name);
12297
12298 /* advertise-map */
12299 if (filter->advmap.aname && filter->advmap.cname)
12300 vty_out(vty,
12301 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12302 filter->advmap.condition ? "EXIST"
12303 : "NON_EXIST",
12304 filter->advmap.cmap ? "*" : "",
12305 filter->advmap.cname,
12306 filter->advmap.amap ? "*" : "",
12307 filter->advmap.aname,
12308 filter->advmap.update_type == ADVERTISE
12309 ? "Advertise"
12310 : "Withdraw");
12311
12312 /* Receive prefix count */
12313 vty_out(vty, " %u accepted prefixes\n",
12314 p->pcount[afi][safi]);
12315
12316 /* maximum-prefix-out */
12317 if (CHECK_FLAG(p->af_flags[afi][safi],
12318 PEER_FLAG_MAX_PREFIX_OUT))
12319 vty_out(vty,
12320 " Maximum allowed prefixes sent %u\n",
12321 p->pmax_out[afi][safi]);
12322
12323 /* Maximum prefix */
12324 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12325 vty_out(vty,
12326 " Maximum prefixes allowed %u%s\n",
12327 p->pmax[afi][safi],
12328 CHECK_FLAG(p->af_flags[afi][safi],
12329 PEER_FLAG_MAX_PREFIX_WARNING)
12330 ? " (warning-only)"
12331 : "");
12332 vty_out(vty, " Threshold for warning message %d%%",
12333 p->pmax_threshold[afi][safi]);
12334 if (p->pmax_restart[afi][safi])
12335 vty_out(vty, ", restart interval %d min",
12336 p->pmax_restart[afi][safi]);
12337 vty_out(vty, "\n");
12338 }
12339
12340 vty_out(vty, "\n");
12341 }
12342 }
12343
12344 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12345 json_object *json)
12346 {
12347 struct bgp *bgp;
12348 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12349 char timebuf[BGP_UPTIME_LEN];
12350 char dn_flag[2];
12351 afi_t afi;
12352 safi_t safi;
12353 uint16_t i;
12354 uint8_t *msg;
12355 json_object *json_neigh = NULL;
12356 time_t epoch_tbuf;
12357 uint32_t sync_tcp_mss;
12358
12359 bgp = p->bgp;
12360
12361 if (use_json)
12362 json_neigh = json_object_new_object();
12363
12364 memset(dn_flag, '\0', sizeof(dn_flag));
12365 if (!p->conf_if && peer_dynamic_neighbor(p))
12366 dn_flag[0] = '*';
12367
12368 if (!use_json) {
12369 if (p->conf_if) /* Configured interface name. */
12370 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12371 BGP_PEER_SU_UNSPEC(p)
12372 ? "None"
12373 : sockunion2str(&p->su, buf,
12374 SU_ADDRSTRLEN));
12375 else /* Configured IP address. */
12376 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12377 p->host);
12378 }
12379
12380 if (use_json) {
12381 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12382 json_object_string_add(json_neigh, "bgpNeighborAddr",
12383 "none");
12384 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12385 json_object_string_add(
12386 json_neigh, "bgpNeighborAddr",
12387 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12388
12389 json_object_int_add(json_neigh, "remoteAs", p->as);
12390
12391 if (p->change_local_as)
12392 json_object_int_add(json_neigh, "localAs",
12393 p->change_local_as);
12394 else
12395 json_object_int_add(json_neigh, "localAs", p->local_as);
12396
12397 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12398 json_object_boolean_true_add(json_neigh,
12399 "localAsNoPrepend");
12400
12401 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12402 json_object_boolean_true_add(json_neigh,
12403 "localAsReplaceAs");
12404 } else {
12405 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12406 || (p->as_type == AS_INTERNAL))
12407 vty_out(vty, "remote AS %u, ", p->as);
12408 else
12409 vty_out(vty, "remote AS Unspecified, ");
12410 vty_out(vty, "local AS %u%s%s, ",
12411 p->change_local_as ? p->change_local_as : p->local_as,
12412 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12413 ? " no-prepend"
12414 : "",
12415 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12416 ? " replace-as"
12417 : "");
12418 }
12419 /* peer type internal or confed-internal */
12420 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12421 if (use_json) {
12422 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12423 json_object_boolean_true_add(
12424 json_neigh, "nbrConfedInternalLink");
12425 else
12426 json_object_boolean_true_add(json_neigh,
12427 "nbrInternalLink");
12428 } else {
12429 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12430 vty_out(vty, "confed-internal link\n");
12431 else
12432 vty_out(vty, "internal link\n");
12433 }
12434 /* peer type external or confed-external */
12435 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12436 if (use_json) {
12437 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12438 json_object_boolean_true_add(
12439 json_neigh, "nbrConfedExternalLink");
12440 else
12441 json_object_boolean_true_add(json_neigh,
12442 "nbrExternalLink");
12443 } else {
12444 if (bgp_confederation_peers_check(bgp, p->as))
12445 vty_out(vty, "confed-external link\n");
12446 else
12447 vty_out(vty, "external link\n");
12448 }
12449 } else {
12450 if (use_json)
12451 json_object_boolean_true_add(json_neigh,
12452 "nbrUnspecifiedLink");
12453 else
12454 vty_out(vty, "unspecified link\n");
12455 }
12456
12457 /* Description. */
12458 if (p->desc) {
12459 if (use_json)
12460 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12461 else
12462 vty_out(vty, " Description: %s\n", p->desc);
12463 }
12464
12465 if (p->hostname) {
12466 if (use_json) {
12467 if (p->hostname)
12468 json_object_string_add(json_neigh, "hostname",
12469 p->hostname);
12470
12471 if (p->domainname)
12472 json_object_string_add(json_neigh, "domainname",
12473 p->domainname);
12474 } else {
12475 if (p->domainname && (p->domainname[0] != '\0'))
12476 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12477 p->domainname);
12478 else
12479 vty_out(vty, "Hostname: %s\n", p->hostname);
12480 }
12481 }
12482
12483 /* Peer-group */
12484 if (p->group) {
12485 if (use_json) {
12486 json_object_string_add(json_neigh, "peerGroup",
12487 p->group->name);
12488
12489 if (dn_flag[0]) {
12490 struct prefix prefix, *range = NULL;
12491
12492 if (sockunion2hostprefix(&(p->su), &prefix))
12493 range = peer_group_lookup_dynamic_neighbor_range(
12494 p->group, &prefix);
12495
12496 if (range) {
12497 json_object_string_addf(
12498 json_neigh,
12499 "peerSubnetRangeGroup", "%pFX",
12500 range);
12501 }
12502 }
12503 } else {
12504 vty_out(vty,
12505 " Member of peer-group %s for session parameters\n",
12506 p->group->name);
12507
12508 if (dn_flag[0]) {
12509 struct prefix prefix, *range = NULL;
12510
12511 if (sockunion2hostprefix(&(p->su), &prefix))
12512 range = peer_group_lookup_dynamic_neighbor_range(
12513 p->group, &prefix);
12514
12515 if (range) {
12516 vty_out(vty,
12517 " Belongs to the subnet range group: %pFX\n",
12518 range);
12519 }
12520 }
12521 }
12522 }
12523
12524 if (use_json) {
12525 /* Administrative shutdown. */
12526 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12527 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12528 json_object_boolean_true_add(json_neigh,
12529 "adminShutDown");
12530
12531 /* BGP Version. */
12532 json_object_int_add(json_neigh, "bgpVersion", 4);
12533 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12534 &p->remote_id);
12535 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12536 &bgp->router_id);
12537
12538 /* Confederation */
12539 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12540 && bgp_confederation_peers_check(bgp, p->as))
12541 json_object_boolean_true_add(json_neigh,
12542 "nbrCommonAdmin");
12543
12544 /* Status. */
12545 json_object_string_add(
12546 json_neigh, "bgpState",
12547 lookup_msg(bgp_status_msg, p->status, NULL));
12548
12549 if (peer_established(p)) {
12550 time_t uptime;
12551
12552 uptime = bgp_clock();
12553 uptime -= p->uptime;
12554 epoch_tbuf = time(NULL) - uptime;
12555
12556 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12557 uptime * 1000);
12558 json_object_string_add(json_neigh, "bgpTimerUpString",
12559 peer_uptime(p->uptime, timebuf,
12560 BGP_UPTIME_LEN, 0,
12561 NULL));
12562 json_object_int_add(json_neigh,
12563 "bgpTimerUpEstablishedEpoch",
12564 epoch_tbuf);
12565 }
12566
12567 else if (p->status == Active) {
12568 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12569 json_object_string_add(json_neigh, "bgpStateIs",
12570 "passive");
12571 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12572 json_object_string_add(json_neigh, "bgpStateIs",
12573 "passiveNSF");
12574 }
12575
12576 /* read timer */
12577 time_t uptime;
12578 struct tm tm;
12579
12580 uptime = bgp_clock();
12581 uptime -= p->readtime;
12582 gmtime_r(&uptime, &tm);
12583
12584 json_object_int_add(json_neigh, "bgpTimerLastRead",
12585 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12586 + (tm.tm_hour * 3600000));
12587
12588 uptime = bgp_clock();
12589 uptime -= p->last_write;
12590 gmtime_r(&uptime, &tm);
12591
12592 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12593 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12594 + (tm.tm_hour * 3600000));
12595
12596 uptime = bgp_clock();
12597 uptime -= p->update_time;
12598 gmtime_r(&uptime, &tm);
12599
12600 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12601 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12602 + (tm.tm_hour * 3600000));
12603
12604 /* Configured timer values. */
12605 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12606 p->v_holdtime * 1000);
12607 json_object_int_add(json_neigh,
12608 "bgpTimerKeepAliveIntervalMsecs",
12609 p->v_keepalive * 1000);
12610 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12611 json_object_int_add(json_neigh,
12612 "bgpTimerDelayOpenTimeMsecs",
12613 p->v_delayopen * 1000);
12614 }
12615
12616 /* Configured and Synced tcp-mss value for peer */
12617 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12618 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12619 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12620 p->tcp_mss);
12621 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12622 sync_tcp_mss);
12623 }
12624
12625 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12626 json_object_int_add(json_neigh,
12627 "bgpTimerConfiguredHoldTimeMsecs",
12628 p->holdtime * 1000);
12629 json_object_int_add(
12630 json_neigh,
12631 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12632 p->keepalive * 1000);
12633 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12634 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12635 json_object_int_add(json_neigh,
12636 "bgpTimerConfiguredHoldTimeMsecs",
12637 bgp->default_holdtime);
12638 json_object_int_add(
12639 json_neigh,
12640 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12641 bgp->default_keepalive);
12642 }
12643
12644 /* Extended Optional Parameters Length for BGP OPEN Message */
12645 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12646 json_object_boolean_true_add(
12647 json_neigh, "extendedOptionalParametersLength");
12648 else
12649 json_object_boolean_false_add(
12650 json_neigh, "extendedOptionalParametersLength");
12651
12652 /* Conditional advertisements */
12653 json_object_int_add(
12654 json_neigh,
12655 "bgpTimerConfiguredConditionalAdvertisementsSec",
12656 bgp->condition_check_period);
12657 if (thread_is_scheduled(bgp->t_condition_check))
12658 json_object_int_add(
12659 json_neigh,
12660 "bgpTimerUntilConditionalAdvertisementsSec",
12661 thread_timer_remain_second(
12662 bgp->t_condition_check));
12663 } else {
12664 /* Administrative shutdown. */
12665 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12666 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12667 vty_out(vty, " Administratively shut down\n");
12668
12669 /* BGP Version. */
12670 vty_out(vty, " BGP version 4");
12671 vty_out(vty, ", remote router ID %s",
12672 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12673 vty_out(vty, ", local router ID %s\n",
12674 inet_ntop(AF_INET, &bgp->router_id, buf1,
12675 sizeof(buf1)));
12676
12677 /* Confederation */
12678 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12679 && bgp_confederation_peers_check(bgp, p->as))
12680 vty_out(vty,
12681 " Neighbor under common administration\n");
12682
12683 /* Status. */
12684 vty_out(vty, " BGP state = %s",
12685 lookup_msg(bgp_status_msg, p->status, NULL));
12686
12687 if (peer_established(p))
12688 vty_out(vty, ", up for %8s",
12689 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12690 0, NULL));
12691
12692 else if (p->status == Active) {
12693 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12694 vty_out(vty, " (passive)");
12695 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12696 vty_out(vty, " (NSF passive)");
12697 }
12698 vty_out(vty, "\n");
12699
12700 /* read timer */
12701 vty_out(vty, " Last read %s",
12702 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12703 NULL));
12704 vty_out(vty, ", Last write %s\n",
12705 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12706 NULL));
12707
12708 /* Configured timer values. */
12709 vty_out(vty,
12710 " Hold time is %d, keepalive interval is %d seconds\n",
12711 p->v_holdtime, p->v_keepalive);
12712 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12713 vty_out(vty, " Configured hold time is %d",
12714 p->holdtime);
12715 vty_out(vty, ", keepalive interval is %d seconds\n",
12716 p->keepalive);
12717 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12718 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12719 vty_out(vty, " Configured hold time is %d",
12720 bgp->default_holdtime);
12721 vty_out(vty, ", keepalive interval is %d seconds\n",
12722 bgp->default_keepalive);
12723 }
12724 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12725 vty_out(vty,
12726 " Configured DelayOpenTime is %d seconds\n",
12727 p->delayopen);
12728
12729 /* Configured and synced tcp-mss value for peer */
12730 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12731 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12732 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12733 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12734 }
12735
12736 /* Extended Optional Parameters Length for BGP OPEN Message */
12737 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12738 vty_out(vty,
12739 " Extended Optional Parameters Length is enabled\n");
12740
12741 /* Conditional advertisements */
12742 vty_out(vty,
12743 " Configured conditional advertisements interval is %d seconds\n",
12744 bgp->condition_check_period);
12745 if (thread_is_scheduled(bgp->t_condition_check))
12746 vty_out(vty,
12747 " Time until conditional advertisements begin is %lu seconds\n",
12748 thread_timer_remain_second(
12749 bgp->t_condition_check));
12750 }
12751 /* Capability. */
12752 if (peer_established(p) &&
12753 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12754 if (use_json) {
12755 json_object *json_cap = NULL;
12756
12757 json_cap = json_object_new_object();
12758
12759 /* AS4 */
12760 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12761 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12762 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12763 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12764 json_object_string_add(
12765 json_cap, "4byteAs",
12766 "advertisedAndReceived");
12767 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12768 json_object_string_add(json_cap,
12769 "4byteAs",
12770 "advertised");
12771 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12772 json_object_string_add(json_cap,
12773 "4byteAs",
12774 "received");
12775 }
12776
12777 /* Extended Message Support */
12778 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12779 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12780 json_object_string_add(json_cap,
12781 "extendedMessage",
12782 "advertisedAndReceived");
12783 else if (CHECK_FLAG(p->cap,
12784 PEER_CAP_EXTENDED_MESSAGE_ADV))
12785 json_object_string_add(json_cap,
12786 "extendedMessage",
12787 "advertised");
12788 else if (CHECK_FLAG(p->cap,
12789 PEER_CAP_EXTENDED_MESSAGE_RCV))
12790 json_object_string_add(json_cap,
12791 "extendedMessage",
12792 "received");
12793
12794 /* AddPath */
12795 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12796 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12797 json_object *json_add = NULL;
12798 const char *print_store;
12799
12800 json_add = json_object_new_object();
12801
12802 FOREACH_AFI_SAFI (afi, safi) {
12803 json_object *json_sub = NULL;
12804 json_sub = json_object_new_object();
12805 print_store = get_afi_safi_str(
12806 afi, safi, true);
12807
12808 if (CHECK_FLAG(
12809 p->af_cap[afi][safi],
12810 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12811 CHECK_FLAG(
12812 p->af_cap[afi][safi],
12813 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12814 if (CHECK_FLAG(
12815 p->af_cap[afi]
12816 [safi],
12817 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12818 CHECK_FLAG(
12819 p->af_cap[afi]
12820 [safi],
12821 PEER_CAP_ADDPATH_AF_TX_RCV))
12822 json_object_boolean_true_add(
12823 json_sub,
12824 "txAdvertisedAndReceived");
12825 else if (
12826 CHECK_FLAG(
12827 p->af_cap[afi]
12828 [safi],
12829 PEER_CAP_ADDPATH_AF_TX_ADV))
12830 json_object_boolean_true_add(
12831 json_sub,
12832 "txAdvertised");
12833 else if (
12834 CHECK_FLAG(
12835 p->af_cap[afi]
12836 [safi],
12837 PEER_CAP_ADDPATH_AF_TX_RCV))
12838 json_object_boolean_true_add(
12839 json_sub,
12840 "txReceived");
12841 }
12842
12843 if (CHECK_FLAG(
12844 p->af_cap[afi][safi],
12845 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12846 CHECK_FLAG(
12847 p->af_cap[afi][safi],
12848 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12849 if (CHECK_FLAG(
12850 p->af_cap[afi]
12851 [safi],
12852 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12853 CHECK_FLAG(
12854 p->af_cap[afi]
12855 [safi],
12856 PEER_CAP_ADDPATH_AF_RX_RCV))
12857 json_object_boolean_true_add(
12858 json_sub,
12859 "rxAdvertisedAndReceived");
12860 else if (
12861 CHECK_FLAG(
12862 p->af_cap[afi]
12863 [safi],
12864 PEER_CAP_ADDPATH_AF_RX_ADV))
12865 json_object_boolean_true_add(
12866 json_sub,
12867 "rxAdvertised");
12868 else if (
12869 CHECK_FLAG(
12870 p->af_cap[afi]
12871 [safi],
12872 PEER_CAP_ADDPATH_AF_RX_RCV))
12873 json_object_boolean_true_add(
12874 json_sub,
12875 "rxReceived");
12876 }
12877
12878 if (CHECK_FLAG(
12879 p->af_cap[afi][safi],
12880 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12881 CHECK_FLAG(
12882 p->af_cap[afi][safi],
12883 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12884 CHECK_FLAG(
12885 p->af_cap[afi][safi],
12886 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12887 CHECK_FLAG(
12888 p->af_cap[afi][safi],
12889 PEER_CAP_ADDPATH_AF_RX_RCV))
12890 json_object_object_add(
12891 json_add, print_store,
12892 json_sub);
12893 else
12894 json_object_free(json_sub);
12895 }
12896
12897 json_object_object_add(json_cap, "addPath",
12898 json_add);
12899 }
12900
12901 /* Dynamic */
12902 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12903 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12904 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12905 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12906 json_object_string_add(
12907 json_cap, "dynamic",
12908 "advertisedAndReceived");
12909 else if (CHECK_FLAG(p->cap,
12910 PEER_CAP_DYNAMIC_ADV))
12911 json_object_string_add(json_cap,
12912 "dynamic",
12913 "advertised");
12914 else if (CHECK_FLAG(p->cap,
12915 PEER_CAP_DYNAMIC_RCV))
12916 json_object_string_add(json_cap,
12917 "dynamic",
12918 "received");
12919 }
12920
12921 /* Extended nexthop */
12922 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12923 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12924 json_object *json_nxt = NULL;
12925 const char *print_store;
12926
12927
12928 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12929 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12930 json_object_string_add(
12931 json_cap, "extendedNexthop",
12932 "advertisedAndReceived");
12933 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12934 json_object_string_add(
12935 json_cap, "extendedNexthop",
12936 "advertised");
12937 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12938 json_object_string_add(
12939 json_cap, "extendedNexthop",
12940 "received");
12941
12942 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12943 json_nxt = json_object_new_object();
12944
12945 for (safi = SAFI_UNICAST;
12946 safi < SAFI_MAX; safi++) {
12947 if (CHECK_FLAG(
12948 p->af_cap[AFI_IP]
12949 [safi],
12950 PEER_CAP_ENHE_AF_RCV)) {
12951 print_store =
12952 get_afi_safi_str(
12953 AFI_IP,
12954 safi,
12955 true);
12956 json_object_string_add(
12957 json_nxt,
12958 print_store,
12959 "recieved"); /* misspelled for compatibility */
12960 }
12961 }
12962 json_object_object_add(
12963 json_cap,
12964 "extendedNexthopFamililesByPeer",
12965 json_nxt);
12966 }
12967 }
12968
12969 /* Long-lived Graceful Restart */
12970 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12971 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12972 json_object *json_llgr = NULL;
12973 const char *afi_safi_str;
12974
12975 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12976 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12977 json_object_string_add(
12978 json_cap,
12979 "longLivedGracefulRestart",
12980 "advertisedAndReceived");
12981 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12982 json_object_string_add(
12983 json_cap,
12984 "longLivedGracefulRestart",
12985 "advertised");
12986 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12987 json_object_string_add(
12988 json_cap,
12989 "longLivedGracefulRestart",
12990 "received");
12991
12992 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12993 json_llgr = json_object_new_object();
12994
12995 FOREACH_AFI_SAFI (afi, safi) {
12996 if (CHECK_FLAG(
12997 p->af_cap[afi]
12998 [safi],
12999 PEER_CAP_ENHE_AF_RCV)) {
13000 afi_safi_str =
13001 get_afi_safi_str(
13002 afi,
13003 safi,
13004 true);
13005 json_object_string_add(
13006 json_llgr,
13007 afi_safi_str,
13008 "received");
13009 }
13010 }
13011 json_object_object_add(
13012 json_cap,
13013 "longLivedGracefulRestartByPeer",
13014 json_llgr);
13015 }
13016 }
13017
13018 /* Route Refresh */
13019 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13020 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13021 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13022 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13023 (CHECK_FLAG(p->cap,
13024 PEER_CAP_REFRESH_NEW_RCV) ||
13025 CHECK_FLAG(p->cap,
13026 PEER_CAP_REFRESH_OLD_RCV))) {
13027 if (CHECK_FLAG(
13028 p->cap,
13029 PEER_CAP_REFRESH_OLD_RCV) &&
13030 CHECK_FLAG(
13031 p->cap,
13032 PEER_CAP_REFRESH_NEW_RCV))
13033 json_object_string_add(
13034 json_cap,
13035 "routeRefresh",
13036 "advertisedAndReceivedOldNew");
13037 else {
13038 if (CHECK_FLAG(
13039 p->cap,
13040 PEER_CAP_REFRESH_OLD_RCV))
13041 json_object_string_add(
13042 json_cap,
13043 "routeRefresh",
13044 "advertisedAndReceivedOld");
13045 else
13046 json_object_string_add(
13047 json_cap,
13048 "routeRefresh",
13049 "advertisedAndReceivedNew");
13050 }
13051 } else if (CHECK_FLAG(p->cap,
13052 PEER_CAP_REFRESH_ADV))
13053 json_object_string_add(json_cap,
13054 "routeRefresh",
13055 "advertised");
13056 else if (CHECK_FLAG(p->cap,
13057 PEER_CAP_REFRESH_NEW_RCV) ||
13058 CHECK_FLAG(p->cap,
13059 PEER_CAP_REFRESH_OLD_RCV))
13060 json_object_string_add(json_cap,
13061 "routeRefresh",
13062 "received");
13063 }
13064
13065 /* Enhanced Route Refresh */
13066 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13067 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13068 if (CHECK_FLAG(p->cap,
13069 PEER_CAP_ENHANCED_RR_ADV) &&
13070 CHECK_FLAG(p->cap,
13071 PEER_CAP_ENHANCED_RR_RCV))
13072 json_object_string_add(
13073 json_cap,
13074 "enhancedRouteRefresh",
13075 "advertisedAndReceived");
13076 else if (CHECK_FLAG(p->cap,
13077 PEER_CAP_ENHANCED_RR_ADV))
13078 json_object_string_add(
13079 json_cap,
13080 "enhancedRouteRefresh",
13081 "advertised");
13082 else if (CHECK_FLAG(p->cap,
13083 PEER_CAP_ENHANCED_RR_RCV))
13084 json_object_string_add(
13085 json_cap,
13086 "enhancedRouteRefresh",
13087 "received");
13088 }
13089
13090 /* Multiprotocol Extensions */
13091 json_object *json_multi = NULL;
13092
13093 json_multi = json_object_new_object();
13094
13095 FOREACH_AFI_SAFI (afi, safi) {
13096 if (p->afc_adv[afi][safi] ||
13097 p->afc_recv[afi][safi]) {
13098 json_object *json_exten = NULL;
13099 json_exten = json_object_new_object();
13100
13101 if (p->afc_adv[afi][safi] &&
13102 p->afc_recv[afi][safi])
13103 json_object_boolean_true_add(
13104 json_exten,
13105 "advertisedAndReceived");
13106 else if (p->afc_adv[afi][safi])
13107 json_object_boolean_true_add(
13108 json_exten,
13109 "advertised");
13110 else if (p->afc_recv[afi][safi])
13111 json_object_boolean_true_add(
13112 json_exten, "received");
13113
13114 json_object_object_add(
13115 json_multi,
13116 get_afi_safi_str(afi, safi,
13117 true),
13118 json_exten);
13119 }
13120 }
13121 json_object_object_add(json_cap,
13122 "multiprotocolExtensions",
13123 json_multi);
13124
13125 /* Hostname capabilities */
13126 json_object *json_hname = NULL;
13127
13128 json_hname = json_object_new_object();
13129
13130 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13131 json_object_string_add(
13132 json_hname, "advHostName",
13133 bgp->peer_self->hostname
13134 ? bgp->peer_self->hostname
13135 : "n/a");
13136 json_object_string_add(
13137 json_hname, "advDomainName",
13138 bgp->peer_self->domainname
13139 ? bgp->peer_self->domainname
13140 : "n/a");
13141 }
13142
13143
13144 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13145 json_object_string_add(
13146 json_hname, "rcvHostName",
13147 p->hostname ? p->hostname : "n/a");
13148 json_object_string_add(
13149 json_hname, "rcvDomainName",
13150 p->domainname ? p->domainname : "n/a");
13151 }
13152
13153 json_object_object_add(json_cap, "hostName",
13154 json_hname);
13155
13156 /* Graceful Restart */
13157 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13158 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13159 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13160 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13161 json_object_string_add(
13162 json_cap, "gracefulRestart",
13163 "advertisedAndReceived");
13164 else if (CHECK_FLAG(p->cap,
13165 PEER_CAP_RESTART_ADV))
13166 json_object_string_add(
13167 json_cap,
13168 "gracefulRestartCapability",
13169 "advertised");
13170 else if (CHECK_FLAG(p->cap,
13171 PEER_CAP_RESTART_RCV))
13172 json_object_string_add(
13173 json_cap,
13174 "gracefulRestartCapability",
13175 "received");
13176
13177 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13178 int restart_af_count = 0;
13179 json_object *json_restart = NULL;
13180 json_restart = json_object_new_object();
13181
13182 json_object_int_add(
13183 json_cap,
13184 "gracefulRestartRemoteTimerMsecs",
13185 p->v_gr_restart * 1000);
13186
13187 FOREACH_AFI_SAFI (afi, safi) {
13188 if (CHECK_FLAG(
13189 p->af_cap[afi]
13190 [safi],
13191 PEER_CAP_RESTART_AF_RCV)) {
13192 json_object *json_sub =
13193 NULL;
13194 json_sub =
13195 json_object_new_object();
13196
13197 if (CHECK_FLAG(
13198 p->af_cap
13199 [afi]
13200 [safi],
13201 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13202 json_object_boolean_true_add(
13203 json_sub,
13204 "preserved");
13205 restart_af_count++;
13206 json_object_object_add(
13207 json_restart,
13208 get_afi_safi_str(
13209 afi,
13210 safi,
13211 true),
13212 json_sub);
13213 }
13214 }
13215 if (!restart_af_count) {
13216 json_object_string_add(
13217 json_cap,
13218 "addressFamiliesByPeer",
13219 "none");
13220 json_object_free(json_restart);
13221 } else
13222 json_object_object_add(
13223 json_cap,
13224 "addressFamiliesByPeer",
13225 json_restart);
13226 }
13227 }
13228 json_object_object_add(
13229 json_neigh, "neighborCapabilities", json_cap);
13230 } else {
13231 vty_out(vty, " Neighbor capabilities:\n");
13232
13233 /* AS4 */
13234 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13235 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13236 vty_out(vty, " 4 Byte AS:");
13237 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13238 vty_out(vty, " advertised");
13239 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13240 vty_out(vty, " %sreceived",
13241 CHECK_FLAG(p->cap,
13242 PEER_CAP_AS4_ADV)
13243 ? "and "
13244 : "");
13245 vty_out(vty, "\n");
13246 }
13247
13248 /* Extended Message Support */
13249 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13250 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13251 vty_out(vty, " Extended Message:");
13252 if (CHECK_FLAG(p->cap,
13253 PEER_CAP_EXTENDED_MESSAGE_ADV))
13254 vty_out(vty, " advertised");
13255 if (CHECK_FLAG(p->cap,
13256 PEER_CAP_EXTENDED_MESSAGE_RCV))
13257 vty_out(vty, " %sreceived",
13258 CHECK_FLAG(
13259 p->cap,
13260 PEER_CAP_EXTENDED_MESSAGE_ADV)
13261 ? "and "
13262 : "");
13263 vty_out(vty, "\n");
13264 }
13265
13266 /* AddPath */
13267 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13268 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13269 vty_out(vty, " AddPath:\n");
13270
13271 FOREACH_AFI_SAFI (afi, safi) {
13272 if (CHECK_FLAG(
13273 p->af_cap[afi][safi],
13274 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13275 CHECK_FLAG(
13276 p->af_cap[afi][safi],
13277 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13278 vty_out(vty, " %s: TX ",
13279 get_afi_safi_str(
13280 afi, safi,
13281 false));
13282
13283 if (CHECK_FLAG(
13284 p->af_cap[afi]
13285 [safi],
13286 PEER_CAP_ADDPATH_AF_TX_ADV))
13287 vty_out(vty,
13288 "advertised");
13289
13290 if (CHECK_FLAG(
13291 p->af_cap[afi]
13292 [safi],
13293 PEER_CAP_ADDPATH_AF_TX_RCV))
13294 vty_out(vty,
13295 "%sreceived",
13296 CHECK_FLAG(
13297 p->af_cap
13298 [afi]
13299 [safi],
13300 PEER_CAP_ADDPATH_AF_TX_ADV)
13301 ? " and "
13302 : "");
13303
13304 vty_out(vty, "\n");
13305 }
13306
13307 if (CHECK_FLAG(
13308 p->af_cap[afi][safi],
13309 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13310 CHECK_FLAG(
13311 p->af_cap[afi][safi],
13312 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13313 vty_out(vty, " %s: RX ",
13314 get_afi_safi_str(
13315 afi, safi,
13316 false));
13317
13318 if (CHECK_FLAG(
13319 p->af_cap[afi]
13320 [safi],
13321 PEER_CAP_ADDPATH_AF_RX_ADV))
13322 vty_out(vty,
13323 "advertised");
13324
13325 if (CHECK_FLAG(
13326 p->af_cap[afi]
13327 [safi],
13328 PEER_CAP_ADDPATH_AF_RX_RCV))
13329 vty_out(vty,
13330 "%sreceived",
13331 CHECK_FLAG(
13332 p->af_cap
13333 [afi]
13334 [safi],
13335 PEER_CAP_ADDPATH_AF_RX_ADV)
13336 ? " and "
13337 : "");
13338
13339 vty_out(vty, "\n");
13340 }
13341 }
13342 }
13343
13344 /* Dynamic */
13345 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13346 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13347 vty_out(vty, " Dynamic:");
13348 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13349 vty_out(vty, " advertised");
13350 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13351 vty_out(vty, " %sreceived",
13352 CHECK_FLAG(p->cap,
13353 PEER_CAP_DYNAMIC_ADV)
13354 ? "and "
13355 : "");
13356 vty_out(vty, "\n");
13357 }
13358
13359 /* Extended nexthop */
13360 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13361 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13362 vty_out(vty, " Extended nexthop:");
13363 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13364 vty_out(vty, " advertised");
13365 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13366 vty_out(vty, " %sreceived",
13367 CHECK_FLAG(p->cap,
13368 PEER_CAP_ENHE_ADV)
13369 ? "and "
13370 : "");
13371 vty_out(vty, "\n");
13372
13373 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13374 vty_out(vty,
13375 " Address families by peer:\n ");
13376 for (safi = SAFI_UNICAST;
13377 safi < SAFI_MAX; safi++)
13378 if (CHECK_FLAG(
13379 p->af_cap[AFI_IP]
13380 [safi],
13381 PEER_CAP_ENHE_AF_RCV))
13382 vty_out(vty,
13383 " %s\n",
13384 get_afi_safi_str(
13385 AFI_IP,
13386 safi,
13387 false));
13388 }
13389 }
13390
13391 /* Long-lived Graceful Restart */
13392 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13393 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13394 vty_out(vty,
13395 " Long-lived Graceful Restart:");
13396 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13397 vty_out(vty, " advertised");
13398 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13399 vty_out(vty, " %sreceived",
13400 CHECK_FLAG(p->cap,
13401 PEER_CAP_LLGR_ADV)
13402 ? "and "
13403 : "");
13404 vty_out(vty, "\n");
13405
13406 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13407 vty_out(vty,
13408 " Address families by peer:\n");
13409 FOREACH_AFI_SAFI (afi, safi)
13410 if (CHECK_FLAG(
13411 p->af_cap[afi]
13412 [safi],
13413 PEER_CAP_LLGR_AF_RCV))
13414 vty_out(vty,
13415 " %s\n",
13416 get_afi_safi_str(
13417 afi,
13418 safi,
13419 false));
13420 }
13421 }
13422
13423 /* Route Refresh */
13424 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13425 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13426 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13427 vty_out(vty, " Route refresh:");
13428 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13429 vty_out(vty, " advertised");
13430 if (CHECK_FLAG(p->cap,
13431 PEER_CAP_REFRESH_NEW_RCV) ||
13432 CHECK_FLAG(p->cap,
13433 PEER_CAP_REFRESH_OLD_RCV))
13434 vty_out(vty, " %sreceived(%s)",
13435 CHECK_FLAG(p->cap,
13436 PEER_CAP_REFRESH_ADV)
13437 ? "and "
13438 : "",
13439 (CHECK_FLAG(
13440 p->cap,
13441 PEER_CAP_REFRESH_OLD_RCV) &&
13442 CHECK_FLAG(
13443 p->cap,
13444 PEER_CAP_REFRESH_NEW_RCV))
13445 ? "old & new"
13446 : CHECK_FLAG(
13447 p->cap,
13448 PEER_CAP_REFRESH_OLD_RCV)
13449 ? "old"
13450 : "new");
13451
13452 vty_out(vty, "\n");
13453 }
13454
13455 /* Enhanced Route Refresh */
13456 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13457 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13458 vty_out(vty, " Enhanced Route Refresh:");
13459 if (CHECK_FLAG(p->cap,
13460 PEER_CAP_ENHANCED_RR_ADV))
13461 vty_out(vty, " advertised");
13462 if (CHECK_FLAG(p->cap,
13463 PEER_CAP_ENHANCED_RR_RCV))
13464 vty_out(vty, " %sreceived",
13465 CHECK_FLAG(p->cap,
13466 PEER_CAP_REFRESH_ADV)
13467 ? "and "
13468 : "");
13469 vty_out(vty, "\n");
13470 }
13471
13472 /* Multiprotocol Extensions */
13473 FOREACH_AFI_SAFI (afi, safi)
13474 if (p->afc_adv[afi][safi] ||
13475 p->afc_recv[afi][safi]) {
13476 vty_out(vty, " Address Family %s:",
13477 get_afi_safi_str(afi, safi,
13478 false));
13479 if (p->afc_adv[afi][safi])
13480 vty_out(vty, " advertised");
13481 if (p->afc_recv[afi][safi])
13482 vty_out(vty, " %sreceived",
13483 p->afc_adv[afi][safi]
13484 ? "and "
13485 : "");
13486 vty_out(vty, "\n");
13487 }
13488
13489 /* Hostname capability */
13490 vty_out(vty, " Hostname Capability:");
13491
13492 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13493 vty_out(vty,
13494 " advertised (name: %s,domain name: %s)",
13495 bgp->peer_self->hostname
13496 ? bgp->peer_self->hostname
13497 : "n/a",
13498 bgp->peer_self->domainname
13499 ? bgp->peer_self->domainname
13500 : "n/a");
13501 } else {
13502 vty_out(vty, " not advertised");
13503 }
13504
13505 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13506 vty_out(vty,
13507 " received (name: %s,domain name: %s)",
13508 p->hostname ? p->hostname : "n/a",
13509 p->domainname ? p->domainname : "n/a");
13510 } else {
13511 vty_out(vty, " not received");
13512 }
13513
13514 vty_out(vty, "\n");
13515
13516 /* Graceful Restart */
13517 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13518 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13519 vty_out(vty,
13520 " Graceful Restart Capability:");
13521 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13522 vty_out(vty, " advertised");
13523 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13524 vty_out(vty, " %sreceived",
13525 CHECK_FLAG(p->cap,
13526 PEER_CAP_RESTART_ADV)
13527 ? "and "
13528 : "");
13529 vty_out(vty, "\n");
13530
13531 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13532 int restart_af_count = 0;
13533
13534 vty_out(vty,
13535 " Remote Restart timer is %d seconds\n",
13536 p->v_gr_restart);
13537 vty_out(vty,
13538 " Address families by peer:\n ");
13539
13540 FOREACH_AFI_SAFI (afi, safi)
13541 if (CHECK_FLAG(
13542 p->af_cap[afi]
13543 [safi],
13544 PEER_CAP_RESTART_AF_RCV)) {
13545 vty_out(vty, "%s%s(%s)",
13546 restart_af_count
13547 ? ", "
13548 : "",
13549 get_afi_safi_str(
13550 afi,
13551 safi,
13552 false),
13553 CHECK_FLAG(
13554 p->af_cap
13555 [afi]
13556 [safi],
13557 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13558 ? "preserved"
13559 : "not preserved");
13560 restart_af_count++;
13561 }
13562 if (!restart_af_count)
13563 vty_out(vty, "none");
13564 vty_out(vty, "\n");
13565 }
13566 } /* Graceful Restart */
13567 }
13568 }
13569
13570 /* graceful restart information */
13571 json_object *json_grace = NULL;
13572 json_object *json_grace_send = NULL;
13573 json_object *json_grace_recv = NULL;
13574 int eor_send_af_count = 0;
13575 int eor_receive_af_count = 0;
13576
13577 if (use_json) {
13578 json_grace = json_object_new_object();
13579 json_grace_send = json_object_new_object();
13580 json_grace_recv = json_object_new_object();
13581
13582 if ((peer_established(p)) &&
13583 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13584 FOREACH_AFI_SAFI (afi, safi) {
13585 if (CHECK_FLAG(p->af_sflags[afi][safi],
13586 PEER_STATUS_EOR_SEND)) {
13587 json_object_boolean_true_add(
13588 json_grace_send,
13589 get_afi_safi_str(afi, safi,
13590 true));
13591 eor_send_af_count++;
13592 }
13593 }
13594 FOREACH_AFI_SAFI (afi, safi) {
13595 if (CHECK_FLAG(p->af_sflags[afi][safi],
13596 PEER_STATUS_EOR_RECEIVED)) {
13597 json_object_boolean_true_add(
13598 json_grace_recv,
13599 get_afi_safi_str(afi, safi,
13600 true));
13601 eor_receive_af_count++;
13602 }
13603 }
13604 }
13605 json_object_object_add(json_grace, "endOfRibSend",
13606 json_grace_send);
13607 json_object_object_add(json_grace, "endOfRibRecv",
13608 json_grace_recv);
13609
13610
13611 if (p->t_gr_restart)
13612 json_object_int_add(
13613 json_grace, "gracefulRestartTimerMsecs",
13614 thread_timer_remain_second(p->t_gr_restart) *
13615 1000);
13616
13617 if (p->t_gr_stale)
13618 json_object_int_add(
13619 json_grace, "gracefulStalepathTimerMsecs",
13620 thread_timer_remain_second(p->t_gr_stale) *
13621 1000);
13622 /* more gr info in new format */
13623 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13624 json_object_object_add(json_neigh, "gracefulRestartInfo",
13625 json_grace);
13626 } else {
13627 vty_out(vty, " Graceful restart information:\n");
13628 if ((peer_established(p)) &&
13629 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13630
13631 vty_out(vty, " End-of-RIB send: ");
13632 FOREACH_AFI_SAFI (afi, safi) {
13633 if (CHECK_FLAG(p->af_sflags[afi][safi],
13634 PEER_STATUS_EOR_SEND)) {
13635 vty_out(vty, "%s%s",
13636 eor_send_af_count ? ", " : "",
13637 get_afi_safi_str(afi, safi,
13638 false));
13639 eor_send_af_count++;
13640 }
13641 }
13642 vty_out(vty, "\n");
13643 vty_out(vty, " End-of-RIB received: ");
13644 FOREACH_AFI_SAFI (afi, safi) {
13645 if (CHECK_FLAG(p->af_sflags[afi][safi],
13646 PEER_STATUS_EOR_RECEIVED)) {
13647 vty_out(vty, "%s%s",
13648 eor_receive_af_count ? ", "
13649 : "",
13650 get_afi_safi_str(afi, safi,
13651 false));
13652 eor_receive_af_count++;
13653 }
13654 }
13655 vty_out(vty, "\n");
13656 }
13657
13658 if (p->t_gr_restart)
13659 vty_out(vty,
13660 " The remaining time of restart timer is %ld\n",
13661 thread_timer_remain_second(p->t_gr_restart));
13662
13663 if (p->t_gr_stale)
13664 vty_out(vty,
13665 " The remaining time of stalepath timer is %ld\n",
13666 thread_timer_remain_second(p->t_gr_stale));
13667
13668 /* more gr info in new format */
13669 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13670 }
13671
13672 if (use_json) {
13673 json_object *json_stat = NULL;
13674 json_stat = json_object_new_object();
13675 /* Packet counts. */
13676
13677 atomic_size_t outq_count, inq_count;
13678 outq_count = atomic_load_explicit(&p->obuf->count,
13679 memory_order_relaxed);
13680 inq_count = atomic_load_explicit(&p->ibuf->count,
13681 memory_order_relaxed);
13682
13683 json_object_int_add(json_stat, "depthInq",
13684 (unsigned long)inq_count);
13685 json_object_int_add(json_stat, "depthOutq",
13686 (unsigned long)outq_count);
13687 json_object_int_add(json_stat, "opensSent",
13688 atomic_load_explicit(&p->open_out,
13689 memory_order_relaxed));
13690 json_object_int_add(json_stat, "opensRecv",
13691 atomic_load_explicit(&p->open_in,
13692 memory_order_relaxed));
13693 json_object_int_add(json_stat, "notificationsSent",
13694 atomic_load_explicit(&p->notify_out,
13695 memory_order_relaxed));
13696 json_object_int_add(json_stat, "notificationsRecv",
13697 atomic_load_explicit(&p->notify_in,
13698 memory_order_relaxed));
13699 json_object_int_add(json_stat, "updatesSent",
13700 atomic_load_explicit(&p->update_out,
13701 memory_order_relaxed));
13702 json_object_int_add(json_stat, "updatesRecv",
13703 atomic_load_explicit(&p->update_in,
13704 memory_order_relaxed));
13705 json_object_int_add(json_stat, "keepalivesSent",
13706 atomic_load_explicit(&p->keepalive_out,
13707 memory_order_relaxed));
13708 json_object_int_add(json_stat, "keepalivesRecv",
13709 atomic_load_explicit(&p->keepalive_in,
13710 memory_order_relaxed));
13711 json_object_int_add(json_stat, "routeRefreshSent",
13712 atomic_load_explicit(&p->refresh_out,
13713 memory_order_relaxed));
13714 json_object_int_add(json_stat, "routeRefreshRecv",
13715 atomic_load_explicit(&p->refresh_in,
13716 memory_order_relaxed));
13717 json_object_int_add(json_stat, "capabilitySent",
13718 atomic_load_explicit(&p->dynamic_cap_out,
13719 memory_order_relaxed));
13720 json_object_int_add(json_stat, "capabilityRecv",
13721 atomic_load_explicit(&p->dynamic_cap_in,
13722 memory_order_relaxed));
13723 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13724 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13725 json_object_object_add(json_neigh, "messageStats", json_stat);
13726 } else {
13727 atomic_size_t outq_count, inq_count, open_out, open_in,
13728 notify_out, notify_in, update_out, update_in,
13729 keepalive_out, keepalive_in, refresh_out, refresh_in,
13730 dynamic_cap_out, dynamic_cap_in;
13731 outq_count = atomic_load_explicit(&p->obuf->count,
13732 memory_order_relaxed);
13733 inq_count = atomic_load_explicit(&p->ibuf->count,
13734 memory_order_relaxed);
13735 open_out = atomic_load_explicit(&p->open_out,
13736 memory_order_relaxed);
13737 open_in =
13738 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13739 notify_out = atomic_load_explicit(&p->notify_out,
13740 memory_order_relaxed);
13741 notify_in = atomic_load_explicit(&p->notify_in,
13742 memory_order_relaxed);
13743 update_out = atomic_load_explicit(&p->update_out,
13744 memory_order_relaxed);
13745 update_in = atomic_load_explicit(&p->update_in,
13746 memory_order_relaxed);
13747 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13748 memory_order_relaxed);
13749 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13750 memory_order_relaxed);
13751 refresh_out = atomic_load_explicit(&p->refresh_out,
13752 memory_order_relaxed);
13753 refresh_in = atomic_load_explicit(&p->refresh_in,
13754 memory_order_relaxed);
13755 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13756 memory_order_relaxed);
13757 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13758 memory_order_relaxed);
13759
13760 /* Packet counts. */
13761 vty_out(vty, " Message statistics:\n");
13762 vty_out(vty, " Inq depth is %zu\n", inq_count);
13763 vty_out(vty, " Outq depth is %zu\n", outq_count);
13764 vty_out(vty, " Sent Rcvd\n");
13765 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13766 open_in);
13767 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13768 notify_in);
13769 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13770 update_in);
13771 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13772 keepalive_in);
13773 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13774 refresh_in);
13775 vty_out(vty, " Capability: %10zu %10zu\n",
13776 dynamic_cap_out, dynamic_cap_in);
13777 vty_out(vty, " Total: %10u %10u\n",
13778 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
13779 }
13780
13781 if (use_json) {
13782 /* advertisement-interval */
13783 json_object_int_add(json_neigh,
13784 "minBtwnAdvertisementRunsTimerMsecs",
13785 p->v_routeadv * 1000);
13786
13787 /* Update-source. */
13788 if (p->update_if || p->update_source) {
13789 if (p->update_if)
13790 json_object_string_add(json_neigh,
13791 "updateSource",
13792 p->update_if);
13793 else if (p->update_source)
13794 json_object_string_add(
13795 json_neigh, "updateSource",
13796 sockunion2str(p->update_source, buf1,
13797 SU_ADDRSTRLEN));
13798 }
13799 } else {
13800 /* advertisement-interval */
13801 vty_out(vty,
13802 " Minimum time between advertisement runs is %d seconds\n",
13803 p->v_routeadv);
13804
13805 /* Update-source. */
13806 if (p->update_if || p->update_source) {
13807 vty_out(vty, " Update source is ");
13808 if (p->update_if)
13809 vty_out(vty, "%s", p->update_if);
13810 else if (p->update_source)
13811 vty_out(vty, "%s",
13812 sockunion2str(p->update_source, buf1,
13813 SU_ADDRSTRLEN));
13814 vty_out(vty, "\n");
13815 }
13816
13817 vty_out(vty, "\n");
13818 }
13819
13820 /* Address Family Information */
13821 json_object *json_hold = NULL;
13822
13823 if (use_json)
13824 json_hold = json_object_new_object();
13825
13826 FOREACH_AFI_SAFI (afi, safi)
13827 if (p->afc[afi][safi])
13828 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13829 json_hold);
13830
13831 if (use_json) {
13832 json_object_object_add(json_neigh, "addressFamilyInfo",
13833 json_hold);
13834 json_object_int_add(json_neigh, "connectionsEstablished",
13835 p->established);
13836 json_object_int_add(json_neigh, "connectionsDropped",
13837 p->dropped);
13838 } else
13839 vty_out(vty, " Connections established %d; dropped %d\n",
13840 p->established, p->dropped);
13841
13842 if (!p->last_reset) {
13843 if (use_json)
13844 json_object_string_add(json_neigh, "lastReset",
13845 "never");
13846 else
13847 vty_out(vty, " Last reset never\n");
13848 } else {
13849 if (use_json) {
13850 time_t uptime;
13851 struct tm tm;
13852
13853 uptime = bgp_clock();
13854 uptime -= p->resettime;
13855 gmtime_r(&uptime, &tm);
13856
13857 json_object_int_add(json_neigh, "lastResetTimerMsecs",
13858 (tm.tm_sec * 1000)
13859 + (tm.tm_min * 60000)
13860 + (tm.tm_hour * 3600000));
13861 bgp_show_peer_reset(NULL, p, json_neigh, true);
13862 } else {
13863 vty_out(vty, " Last reset %s, ",
13864 peer_uptime(p->resettime, timebuf,
13865 BGP_UPTIME_LEN, 0, NULL));
13866
13867 bgp_show_peer_reset(vty, p, NULL, false);
13868 if (p->last_reset_cause_size) {
13869 msg = p->last_reset_cause;
13870 vty_out(vty,
13871 " Message received that caused BGP to send a NOTIFICATION:\n ");
13872 for (i = 1; i <= p->last_reset_cause_size;
13873 i++) {
13874 vty_out(vty, "%02X", *msg++);
13875
13876 if (i != p->last_reset_cause_size) {
13877 if (i % 16 == 0) {
13878 vty_out(vty, "\n ");
13879 } else if (i % 4 == 0) {
13880 vty_out(vty, " ");
13881 }
13882 }
13883 }
13884 vty_out(vty, "\n");
13885 }
13886 }
13887 }
13888
13889 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13890 if (use_json)
13891 json_object_boolean_true_add(json_neigh,
13892 "prefixesConfigExceedMax");
13893 else
13894 vty_out(vty,
13895 " Peer had exceeded the max. no. of prefixes configured.\n");
13896
13897 if (p->t_pmax_restart) {
13898 if (use_json) {
13899 json_object_boolean_true_add(
13900 json_neigh, "reducePrefixNumFrom");
13901 json_object_int_add(json_neigh,
13902 "restartInTimerMsec",
13903 thread_timer_remain_second(
13904 p->t_pmax_restart)
13905 * 1000);
13906 } else
13907 vty_out(vty,
13908 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
13909 p->host, thread_timer_remain_second(
13910 p->t_pmax_restart));
13911 } else {
13912 if (use_json)
13913 json_object_boolean_true_add(
13914 json_neigh,
13915 "reducePrefixNumAndClearIpBgp");
13916 else
13917 vty_out(vty,
13918 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13919 p->host);
13920 }
13921 }
13922
13923 /* EBGP Multihop and GTSM */
13924 if (p->sort != BGP_PEER_IBGP) {
13925 if (use_json) {
13926 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13927 json_object_int_add(json_neigh,
13928 "externalBgpNbrMaxHopsAway",
13929 p->gtsm_hops);
13930 else if (p->ttl > BGP_DEFAULT_TTL)
13931 json_object_int_add(json_neigh,
13932 "externalBgpNbrMaxHopsAway",
13933 p->ttl);
13934 } else {
13935 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13936 vty_out(vty,
13937 " External BGP neighbor may be up to %d hops away.\n",
13938 p->gtsm_hops);
13939 else if (p->ttl > BGP_DEFAULT_TTL)
13940 vty_out(vty,
13941 " External BGP neighbor may be up to %d hops away.\n",
13942 p->ttl);
13943 }
13944 } else {
13945 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
13946 if (use_json)
13947 json_object_int_add(json_neigh,
13948 "internalBgpNbrMaxHopsAway",
13949 p->gtsm_hops);
13950 else
13951 vty_out(vty,
13952 " Internal BGP neighbor may be up to %d hops away.\n",
13953 p->gtsm_hops);
13954 }
13955 }
13956
13957 /* Local address. */
13958 if (p->su_local) {
13959 if (use_json) {
13960 json_object_string_add(json_neigh, "hostLocal",
13961 sockunion2str(p->su_local, buf1,
13962 SU_ADDRSTRLEN));
13963 json_object_int_add(json_neigh, "portLocal",
13964 ntohs(p->su_local->sin.sin_port));
13965 } else
13966 vty_out(vty, "Local host: %s, Local port: %d\n",
13967 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13968 ntohs(p->su_local->sin.sin_port));
13969 }
13970
13971 /* Remote address. */
13972 if (p->su_remote) {
13973 if (use_json) {
13974 json_object_string_add(json_neigh, "hostForeign",
13975 sockunion2str(p->su_remote, buf1,
13976 SU_ADDRSTRLEN));
13977 json_object_int_add(json_neigh, "portForeign",
13978 ntohs(p->su_remote->sin.sin_port));
13979 } else
13980 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13981 sockunion2str(p->su_remote, buf1,
13982 SU_ADDRSTRLEN),
13983 ntohs(p->su_remote->sin.sin_port));
13984 }
13985
13986 /* Nexthop display. */
13987 if (p->su_local) {
13988 if (use_json) {
13989 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13990 &p->nexthop.v4);
13991 json_object_string_addf(json_neigh, "nexthopGlobal",
13992 "%pI6", &p->nexthop.v6_global);
13993 json_object_string_addf(json_neigh, "nexthopLocal",
13994 "%pI6", &p->nexthop.v6_local);
13995 if (p->shared_network)
13996 json_object_string_add(json_neigh,
13997 "bgpConnection",
13998 "sharedNetwork");
13999 else
14000 json_object_string_add(json_neigh,
14001 "bgpConnection",
14002 "nonSharedNetwork");
14003 } else {
14004 vty_out(vty, "Nexthop: %s\n",
14005 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14006 sizeof(buf1)));
14007 vty_out(vty, "Nexthop global: %s\n",
14008 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14009 sizeof(buf1)));
14010 vty_out(vty, "Nexthop local: %s\n",
14011 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14012 sizeof(buf1)));
14013 vty_out(vty, "BGP connection: %s\n",
14014 p->shared_network ? "shared network"
14015 : "non shared network");
14016 }
14017 }
14018
14019 /* Timer information. */
14020 if (use_json) {
14021 json_object_int_add(json_neigh, "connectRetryTimer",
14022 p->v_connect);
14023 if (peer_established(p) && p->rtt)
14024 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14025 p->rtt);
14026 if (p->t_start)
14027 json_object_int_add(
14028 json_neigh, "nextStartTimerDueInMsecs",
14029 thread_timer_remain_second(p->t_start) * 1000);
14030 if (p->t_connect)
14031 json_object_int_add(
14032 json_neigh, "nextConnectTimerDueInMsecs",
14033 thread_timer_remain_second(p->t_connect)
14034 * 1000);
14035 if (p->t_routeadv) {
14036 json_object_int_add(json_neigh, "mraiInterval",
14037 p->v_routeadv);
14038 json_object_int_add(
14039 json_neigh, "mraiTimerExpireInMsecs",
14040 thread_timer_remain_second(p->t_routeadv)
14041 * 1000);
14042 }
14043 if (p->password)
14044 json_object_int_add(json_neigh, "authenticationEnabled",
14045 1);
14046
14047 if (p->t_read)
14048 json_object_string_add(json_neigh, "readThread", "on");
14049 else
14050 json_object_string_add(json_neigh, "readThread", "off");
14051
14052 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14053 json_object_string_add(json_neigh, "writeThread", "on");
14054 else
14055 json_object_string_add(json_neigh, "writeThread",
14056 "off");
14057 } else {
14058 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14059 p->v_connect);
14060 if (peer_established(p) && p->rtt)
14061 vty_out(vty, "Estimated round trip time: %d ms\n",
14062 p->rtt);
14063 if (p->t_start)
14064 vty_out(vty, "Next start timer due in %ld seconds\n",
14065 thread_timer_remain_second(p->t_start));
14066 if (p->t_connect)
14067 vty_out(vty, "Next connect timer due in %ld seconds\n",
14068 thread_timer_remain_second(p->t_connect));
14069 if (p->t_routeadv)
14070 vty_out(vty,
14071 "MRAI (interval %u) timer expires in %ld seconds\n",
14072 p->v_routeadv,
14073 thread_timer_remain_second(p->t_routeadv));
14074 if (p->password)
14075 vty_out(vty, "Peer Authentication Enabled\n");
14076
14077 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14078 p->t_read ? "on" : "off",
14079 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14080 ? "on"
14081 : "off", p->fd);
14082 }
14083
14084 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14085 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14086 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14087
14088 if (!use_json)
14089 vty_out(vty, "\n");
14090
14091 /* BFD information. */
14092 if (p->bfd_config)
14093 bgp_bfd_show_info(vty, p, json_neigh);
14094
14095 if (use_json) {
14096 if (p->conf_if) /* Configured interface name. */
14097 json_object_object_add(json, p->conf_if, json_neigh);
14098 else /* Configured IP address. */
14099 json_object_object_add(json, p->host, json_neigh);
14100 }
14101 }
14102
14103 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14104 enum show_type type,
14105 union sockunion *su,
14106 const char *conf_if, afi_t afi,
14107 bool use_json)
14108 {
14109 struct listnode *node, *nnode;
14110 struct peer *peer;
14111 int find = 0;
14112 safi_t safi = SAFI_UNICAST;
14113 json_object *json = NULL;
14114 json_object *json_neighbor = NULL;
14115
14116 if (use_json) {
14117 json = json_object_new_object();
14118 json_neighbor = json_object_new_object();
14119 }
14120
14121 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14122
14123 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14124 continue;
14125
14126 if ((peer->afc[afi][safi]) == 0)
14127 continue;
14128
14129 if (type == show_all) {
14130 bgp_show_peer_gr_status(vty, peer, use_json,
14131 json_neighbor);
14132
14133 if (use_json) {
14134 json_object_object_add(json, peer->host,
14135 json_neighbor);
14136 json_neighbor = NULL;
14137 }
14138
14139 } else if (type == show_peer) {
14140 if (conf_if) {
14141 if ((peer->conf_if
14142 && !strcmp(peer->conf_if, conf_if))
14143 || (peer->hostname
14144 && !strcmp(peer->hostname, conf_if))) {
14145 find = 1;
14146 bgp_show_peer_gr_status(vty, peer,
14147 use_json,
14148 json_neighbor);
14149 }
14150 } else {
14151 if (sockunion_same(&peer->su, su)) {
14152 find = 1;
14153 bgp_show_peer_gr_status(vty, peer,
14154 use_json,
14155 json_neighbor);
14156 }
14157 }
14158 if (use_json && find)
14159 json_object_object_add(json, peer->host,
14160 json_neighbor);
14161 }
14162
14163 if (find) {
14164 json_neighbor = NULL;
14165 break;
14166 }
14167 }
14168
14169 if (type == show_peer && !find) {
14170 if (use_json)
14171 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14172 else
14173 vty_out(vty, "%% No such neighbor\n");
14174 }
14175 if (use_json) {
14176 if (json_neighbor)
14177 json_object_free(json_neighbor);
14178 vty_json(vty, json);
14179 } else {
14180 vty_out(vty, "\n");
14181 }
14182
14183 return CMD_SUCCESS;
14184 }
14185
14186 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14187 enum show_type type, union sockunion *su,
14188 const char *conf_if, bool use_json,
14189 json_object *json)
14190 {
14191 struct listnode *node, *nnode;
14192 struct peer *peer;
14193 int find = 0;
14194 bool nbr_output = false;
14195 afi_t afi = AFI_MAX;
14196 safi_t safi = SAFI_MAX;
14197
14198 if (type == show_ipv4_peer || type == show_ipv4_all) {
14199 afi = AFI_IP;
14200 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14201 afi = AFI_IP6;
14202 }
14203
14204 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14205 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14206 continue;
14207
14208 switch (type) {
14209 case show_all:
14210 bgp_show_peer(vty, peer, use_json, json);
14211 nbr_output = true;
14212 break;
14213 case show_peer:
14214 if (conf_if) {
14215 if ((peer->conf_if
14216 && !strcmp(peer->conf_if, conf_if))
14217 || (peer->hostname
14218 && !strcmp(peer->hostname, conf_if))) {
14219 find = 1;
14220 bgp_show_peer(vty, peer, use_json,
14221 json);
14222 }
14223 } else {
14224 if (sockunion_same(&peer->su, su)) {
14225 find = 1;
14226 bgp_show_peer(vty, peer, use_json,
14227 json);
14228 }
14229 }
14230 break;
14231 case show_ipv4_peer:
14232 case show_ipv6_peer:
14233 FOREACH_SAFI (safi) {
14234 if (peer->afc[afi][safi]) {
14235 if (conf_if) {
14236 if ((peer->conf_if
14237 && !strcmp(peer->conf_if, conf_if))
14238 || (peer->hostname
14239 && !strcmp(peer->hostname, conf_if))) {
14240 find = 1;
14241 bgp_show_peer(vty, peer, use_json,
14242 json);
14243 break;
14244 }
14245 } else {
14246 if (sockunion_same(&peer->su, su)) {
14247 find = 1;
14248 bgp_show_peer(vty, peer, use_json,
14249 json);
14250 break;
14251 }
14252 }
14253 }
14254 }
14255 break;
14256 case show_ipv4_all:
14257 case show_ipv6_all:
14258 FOREACH_SAFI (safi) {
14259 if (peer->afc[afi][safi]) {
14260 bgp_show_peer(vty, peer, use_json, json);
14261 nbr_output = true;
14262 break;
14263 }
14264 }
14265 break;
14266 }
14267 }
14268
14269 if ((type == show_peer || type == show_ipv4_peer ||
14270 type == show_ipv6_peer) && !find) {
14271 if (use_json)
14272 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14273 else
14274 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14275 }
14276
14277 if (type != show_peer && type != show_ipv4_peer &&
14278 type != show_ipv6_peer && !nbr_output && !use_json)
14279 vty_out(vty, "%% No BGP neighbors found\n");
14280
14281 if (use_json) {
14282 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14283 json, JSON_C_TO_STRING_PRETTY));
14284 } else {
14285 vty_out(vty, "\n");
14286 }
14287
14288 return CMD_SUCCESS;
14289 }
14290
14291 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14292 enum show_type type,
14293 const char *ip_str,
14294 afi_t afi, bool use_json)
14295 {
14296
14297 int ret;
14298 struct bgp *bgp;
14299 union sockunion su;
14300
14301 bgp = bgp_get_default();
14302
14303 if (!bgp)
14304 return;
14305
14306 if (!use_json)
14307 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14308 NULL);
14309
14310 if (ip_str) {
14311 ret = str2sockunion(ip_str, &su);
14312 if (ret < 0)
14313 bgp_show_neighbor_graceful_restart(
14314 vty, bgp, type, NULL, ip_str, afi, use_json);
14315 else
14316 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14317 NULL, afi, use_json);
14318 } else
14319 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14320 afi, use_json);
14321 }
14322
14323 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14324 enum show_type type,
14325 const char *ip_str,
14326 bool use_json)
14327 {
14328 struct listnode *node, *nnode;
14329 struct bgp *bgp;
14330 union sockunion su;
14331 json_object *json = NULL;
14332 int ret, is_first = 1;
14333 bool nbr_output = false;
14334
14335 if (use_json)
14336 vty_out(vty, "{\n");
14337
14338 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14339 nbr_output = true;
14340 if (use_json) {
14341 if (!(json = json_object_new_object())) {
14342 flog_err(
14343 EC_BGP_JSON_MEM_ERROR,
14344 "Unable to allocate memory for JSON object");
14345 vty_out(vty,
14346 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14347 return;
14348 }
14349
14350 json_object_int_add(json, "vrfId",
14351 (bgp->vrf_id == VRF_UNKNOWN)
14352 ? -1
14353 : (int64_t)bgp->vrf_id);
14354 json_object_string_add(
14355 json, "vrfName",
14356 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14357 ? VRF_DEFAULT_NAME
14358 : bgp->name);
14359
14360 if (!is_first)
14361 vty_out(vty, ",\n");
14362 else
14363 is_first = 0;
14364
14365 vty_out(vty, "\"%s\":",
14366 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14367 ? VRF_DEFAULT_NAME
14368 : bgp->name);
14369 } else {
14370 vty_out(vty, "\nInstance %s:\n",
14371 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14372 ? VRF_DEFAULT_NAME
14373 : bgp->name);
14374 }
14375
14376 if (type == show_peer || type == show_ipv4_peer ||
14377 type == show_ipv6_peer) {
14378 ret = str2sockunion(ip_str, &su);
14379 if (ret < 0)
14380 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14381 use_json, json);
14382 else
14383 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14384 use_json, json);
14385 } else {
14386 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14387 use_json, json);
14388 }
14389 json_object_free(json);
14390 json = NULL;
14391 }
14392
14393 if (use_json)
14394 vty_out(vty, "}\n");
14395 else if (!nbr_output)
14396 vty_out(vty, "%% BGP instance not found\n");
14397 }
14398
14399 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14400 enum show_type type, const char *ip_str,
14401 bool use_json)
14402 {
14403 int ret;
14404 struct bgp *bgp;
14405 union sockunion su;
14406 json_object *json = NULL;
14407
14408 if (name) {
14409 if (strmatch(name, "all")) {
14410 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14411 use_json);
14412 return CMD_SUCCESS;
14413 } else {
14414 bgp = bgp_lookup_by_name(name);
14415 if (!bgp) {
14416 if (use_json) {
14417 json = json_object_new_object();
14418 vty_json(vty, json);
14419 } else
14420 vty_out(vty,
14421 "%% BGP instance not found\n");
14422
14423 return CMD_WARNING;
14424 }
14425 }
14426 } else {
14427 bgp = bgp_get_default();
14428 }
14429
14430 if (bgp) {
14431 json = json_object_new_object();
14432 if (ip_str) {
14433 ret = str2sockunion(ip_str, &su);
14434 if (ret < 0)
14435 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14436 use_json, json);
14437 else
14438 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14439 use_json, json);
14440 } else {
14441 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14442 json);
14443 }
14444 json_object_free(json);
14445 } else {
14446 if (use_json)
14447 vty_out(vty, "{}\n");
14448 else
14449 vty_out(vty, "%% BGP instance not found\n");
14450 }
14451
14452 return CMD_SUCCESS;
14453 }
14454
14455
14456
14457 /* "show [ip] bgp neighbors graceful-restart" commands. */
14458 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14459 show_ip_bgp_neighbors_graceful_restart_cmd,
14460 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14461 SHOW_STR
14462 BGP_STR
14463 IP_STR
14464 IPV6_STR
14465 NEIGHBOR_STR
14466 "Neighbor to display information about\n"
14467 "Neighbor to display information about\n"
14468 "Neighbor on BGP configured interface\n"
14469 GR_SHOW
14470 JSON_STR)
14471 {
14472 char *sh_arg = NULL;
14473 enum show_type sh_type;
14474 int idx = 0;
14475 afi_t afi = AFI_MAX;
14476 bool uj = use_json(argc, argv);
14477
14478 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14479 afi = AFI_MAX;
14480
14481 idx++;
14482
14483 if (argv_find(argv, argc, "A.B.C.D", &idx)
14484 || argv_find(argv, argc, "X:X::X:X", &idx)
14485 || argv_find(argv, argc, "WORD", &idx)) {
14486 sh_type = show_peer;
14487 sh_arg = argv[idx]->arg;
14488 } else
14489 sh_type = show_all;
14490
14491 if (!argv_find(argv, argc, "graceful-restart", &idx))
14492 return CMD_SUCCESS;
14493
14494
14495 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14496 afi, uj);
14497 }
14498
14499 /* "show [ip] bgp neighbors" commands. */
14500 DEFUN (show_ip_bgp_neighbors,
14501 show_ip_bgp_neighbors_cmd,
14502 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14503 SHOW_STR
14504 IP_STR
14505 BGP_STR
14506 BGP_INSTANCE_HELP_STR
14507 "Address Family\n"
14508 "Address Family\n"
14509 "Detailed information on TCP and BGP neighbor connections\n"
14510 "Neighbor to display information about\n"
14511 "Neighbor to display information about\n"
14512 "Neighbor on BGP configured interface\n"
14513 JSON_STR)
14514 {
14515 char *vrf = NULL;
14516 char *sh_arg = NULL;
14517 enum show_type sh_type;
14518 afi_t afi = AFI_MAX;
14519
14520 bool uj = use_json(argc, argv);
14521
14522 int idx = 0;
14523
14524 /* [<vrf> VIEWVRFNAME] */
14525 if (argv_find(argv, argc, "vrf", &idx)) {
14526 vrf = argv[idx + 1]->arg;
14527 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14528 vrf = NULL;
14529 } else if (argv_find(argv, argc, "view", &idx))
14530 /* [<view> VIEWVRFNAME] */
14531 vrf = argv[idx + 1]->arg;
14532
14533 idx++;
14534
14535 if (argv_find(argv, argc, "ipv4", &idx)) {
14536 sh_type = show_ipv4_all;
14537 afi = AFI_IP;
14538 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14539 sh_type = show_ipv6_all;
14540 afi = AFI_IP6;
14541 } else {
14542 sh_type = show_all;
14543 }
14544
14545 if (argv_find(argv, argc, "A.B.C.D", &idx)
14546 || argv_find(argv, argc, "X:X::X:X", &idx)
14547 || argv_find(argv, argc, "WORD", &idx)) {
14548 sh_type = show_peer;
14549 sh_arg = argv[idx]->arg;
14550 }
14551
14552 if (sh_type == show_peer && afi == AFI_IP) {
14553 sh_type = show_ipv4_peer;
14554 } else if (sh_type == show_peer && afi == AFI_IP6) {
14555 sh_type = show_ipv6_peer;
14556 }
14557
14558 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14559 }
14560
14561 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14562 paths' and `show ip mbgp paths'. Those functions results are the
14563 same.*/
14564 DEFUN (show_ip_bgp_paths,
14565 show_ip_bgp_paths_cmd,
14566 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14567 SHOW_STR
14568 IP_STR
14569 BGP_STR
14570 BGP_SAFI_HELP_STR
14571 "Path information\n")
14572 {
14573 vty_out(vty, "Address Refcnt Path\n");
14574 aspath_print_all_vty(vty);
14575 return CMD_SUCCESS;
14576 }
14577
14578 #include "hash.h"
14579
14580 static void community_show_all_iterator(struct hash_bucket *bucket,
14581 struct vty *vty)
14582 {
14583 struct community *com;
14584
14585 com = (struct community *)bucket->data;
14586 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14587 community_str(com, false, false));
14588 }
14589
14590 /* Show BGP's community internal data. */
14591 DEFUN (show_ip_bgp_community_info,
14592 show_ip_bgp_community_info_cmd,
14593 "show [ip] bgp community-info",
14594 SHOW_STR
14595 IP_STR
14596 BGP_STR
14597 "List all bgp community information\n")
14598 {
14599 vty_out(vty, "Address Refcnt Community\n");
14600
14601 hash_iterate(community_hash(),
14602 (void (*)(struct hash_bucket *,
14603 void *))community_show_all_iterator,
14604 vty);
14605
14606 return CMD_SUCCESS;
14607 }
14608
14609 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14610 struct vty *vty)
14611 {
14612 struct lcommunity *lcom;
14613
14614 lcom = (struct lcommunity *)bucket->data;
14615 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14616 lcommunity_str(lcom, false, false));
14617 }
14618
14619 /* Show BGP's community internal data. */
14620 DEFUN (show_ip_bgp_lcommunity_info,
14621 show_ip_bgp_lcommunity_info_cmd,
14622 "show ip bgp large-community-info",
14623 SHOW_STR
14624 IP_STR
14625 BGP_STR
14626 "List all bgp large-community information\n")
14627 {
14628 vty_out(vty, "Address Refcnt Large-community\n");
14629
14630 hash_iterate(lcommunity_hash(),
14631 (void (*)(struct hash_bucket *,
14632 void *))lcommunity_show_all_iterator,
14633 vty);
14634
14635 return CMD_SUCCESS;
14636 }
14637 /* Graceful Restart */
14638
14639 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14640 struct bgp *bgp,
14641 bool use_json,
14642 json_object *json)
14643 {
14644
14645
14646 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14647
14648 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14649
14650 switch (bgp_global_gr_mode) {
14651
14652 case GLOBAL_HELPER:
14653 vty_out(vty, "Global BGP GR Mode : Helper\n");
14654 break;
14655
14656 case GLOBAL_GR:
14657 vty_out(vty, "Global BGP GR Mode : Restart\n");
14658 break;
14659
14660 case GLOBAL_DISABLE:
14661 vty_out(vty, "Global BGP GR Mode : Disable\n");
14662 break;
14663
14664 case GLOBAL_INVALID:
14665 vty_out(vty,
14666 "Global BGP GR Mode Invalid\n");
14667 break;
14668 }
14669 vty_out(vty, "\n");
14670 }
14671
14672 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14673 enum show_type type,
14674 const char *ip_str,
14675 afi_t afi, bool use_json)
14676 {
14677 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14678 afi = AFI_IP;
14679
14680 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14681
14682 bgp_show_neighbor_graceful_restart_vty(
14683 vty, type, ip_str, afi, use_json);
14684 afi++;
14685 }
14686 } else if (afi != AFI_MAX) {
14687 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14688 use_json);
14689 } else {
14690 return CMD_ERR_INCOMPLETE;
14691 }
14692
14693 return CMD_SUCCESS;
14694 }
14695 /* Graceful Restart */
14696
14697 DEFUN (show_ip_bgp_attr_info,
14698 show_ip_bgp_attr_info_cmd,
14699 "show [ip] bgp attribute-info",
14700 SHOW_STR
14701 IP_STR
14702 BGP_STR
14703 "List all bgp attribute information\n")
14704 {
14705 attr_show_all(vty);
14706 return CMD_SUCCESS;
14707 }
14708
14709 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14710 afi_t afi, safi_t safi,
14711 bool use_json, json_object *json)
14712 {
14713 struct bgp *bgp;
14714 struct listnode *node;
14715 char *vname;
14716 char buf1[INET6_ADDRSTRLEN];
14717 char *ecom_str;
14718 enum vpn_policy_direction dir;
14719
14720 if (json) {
14721 json_object *json_import_vrfs = NULL;
14722 json_object *json_export_vrfs = NULL;
14723
14724 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14725
14726 if (!bgp) {
14727 vty_json(vty, json);
14728
14729 return CMD_WARNING;
14730 }
14731
14732 /* Provide context for the block */
14733 json_object_string_add(json, "vrf", name ? name : "default");
14734 json_object_string_add(json, "afiSafi",
14735 get_afi_safi_str(afi, safi, true));
14736
14737 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14738 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14739 json_object_string_add(json, "importFromVrfs", "none");
14740 json_object_string_add(json, "importRts", "none");
14741 } else {
14742 json_import_vrfs = json_object_new_array();
14743
14744 for (ALL_LIST_ELEMENTS_RO(
14745 bgp->vpn_policy[afi].import_vrf,
14746 node, vname))
14747 json_object_array_add(json_import_vrfs,
14748 json_object_new_string(vname));
14749
14750 json_object_object_add(json, "importFromVrfs",
14751 json_import_vrfs);
14752 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14753 if (bgp->vpn_policy[afi].rtlist[dir]) {
14754 ecom_str = ecommunity_ecom2str(
14755 bgp->vpn_policy[afi].rtlist[dir],
14756 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14757 json_object_string_add(json, "importRts",
14758 ecom_str);
14759 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14760 } else
14761 json_object_string_add(json, "importRts",
14762 "none");
14763 }
14764
14765 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14766 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14767 json_object_string_add(json, "exportToVrfs", "none");
14768 json_object_string_add(json, "routeDistinguisher",
14769 "none");
14770 json_object_string_add(json, "exportRts", "none");
14771 } else {
14772 json_export_vrfs = json_object_new_array();
14773
14774 for (ALL_LIST_ELEMENTS_RO(
14775 bgp->vpn_policy[afi].export_vrf,
14776 node, vname))
14777 json_object_array_add(json_export_vrfs,
14778 json_object_new_string(vname));
14779 json_object_object_add(json, "exportToVrfs",
14780 json_export_vrfs);
14781 json_object_string_add(json, "routeDistinguisher",
14782 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14783 buf1, RD_ADDRSTRLEN));
14784
14785 dir = BGP_VPN_POLICY_DIR_TOVPN;
14786 if (bgp->vpn_policy[afi].rtlist[dir]) {
14787 ecom_str = ecommunity_ecom2str(
14788 bgp->vpn_policy[afi].rtlist[dir],
14789 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14790 json_object_string_add(json, "exportRts",
14791 ecom_str);
14792 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14793 } else
14794 json_object_string_add(json, "exportRts",
14795 "none");
14796 }
14797
14798 if (use_json) {
14799 vty_json(vty, json);
14800 }
14801 } else {
14802 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14803
14804 if (!bgp) {
14805 vty_out(vty, "%% No such BGP instance exist\n");
14806 return CMD_WARNING;
14807 }
14808
14809 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14810 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14811 vty_out(vty,
14812 "This VRF is not importing %s routes from any other VRF\n",
14813 get_afi_safi_str(afi, safi, false));
14814 else {
14815 vty_out(vty,
14816 "This VRF is importing %s routes from the following VRFs:\n",
14817 get_afi_safi_str(afi, safi, false));
14818
14819 for (ALL_LIST_ELEMENTS_RO(
14820 bgp->vpn_policy[afi].import_vrf,
14821 node, vname))
14822 vty_out(vty, " %s\n", vname);
14823
14824 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14825 ecom_str = NULL;
14826 if (bgp->vpn_policy[afi].rtlist[dir]) {
14827 ecom_str = ecommunity_ecom2str(
14828 bgp->vpn_policy[afi].rtlist[dir],
14829 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14830 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14831
14832 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14833 } else
14834 vty_out(vty, "Import RT(s):\n");
14835 }
14836
14837 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14838 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14839 vty_out(vty,
14840 "This VRF is not exporting %s routes to any other VRF\n",
14841 get_afi_safi_str(afi, safi, false));
14842 else {
14843 vty_out(vty,
14844 "This VRF is exporting %s routes to the following VRFs:\n",
14845 get_afi_safi_str(afi, safi, false));
14846
14847 for (ALL_LIST_ELEMENTS_RO(
14848 bgp->vpn_policy[afi].export_vrf,
14849 node, vname))
14850 vty_out(vty, " %s\n", vname);
14851
14852 vty_out(vty, "RD: %s\n",
14853 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14854 buf1, RD_ADDRSTRLEN));
14855
14856 dir = BGP_VPN_POLICY_DIR_TOVPN;
14857 if (bgp->vpn_policy[afi].rtlist[dir]) {
14858 ecom_str = ecommunity_ecom2str(
14859 bgp->vpn_policy[afi].rtlist[dir],
14860 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14861 vty_out(vty, "Export RT: %s\n", ecom_str);
14862 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14863 } else
14864 vty_out(vty, "Import RT(s):\n");
14865 }
14866 }
14867
14868 return CMD_SUCCESS;
14869 }
14870
14871 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14872 safi_t safi, bool use_json)
14873 {
14874 struct listnode *node, *nnode;
14875 struct bgp *bgp;
14876 char *vrf_name = NULL;
14877 json_object *json = NULL;
14878 json_object *json_vrf = NULL;
14879 json_object *json_vrfs = NULL;
14880
14881 if (use_json) {
14882 json = json_object_new_object();
14883 json_vrfs = json_object_new_object();
14884 }
14885
14886 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14887
14888 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14889 vrf_name = bgp->name;
14890
14891 if (use_json) {
14892 json_vrf = json_object_new_object();
14893 } else {
14894 vty_out(vty, "\nInstance %s:\n",
14895 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14896 ? VRF_DEFAULT_NAME : bgp->name);
14897 }
14898 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14899 if (use_json) {
14900 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14901 json_object_object_add(json_vrfs,
14902 VRF_DEFAULT_NAME, json_vrf);
14903 else
14904 json_object_object_add(json_vrfs, vrf_name,
14905 json_vrf);
14906 }
14907 }
14908
14909 if (use_json) {
14910 json_object_object_add(json, "vrfs", json_vrfs);
14911 vty_json(vty, json);
14912 }
14913
14914 return CMD_SUCCESS;
14915 }
14916
14917 /* "show [ip] bgp route-leak" command. */
14918 DEFUN (show_ip_bgp_route_leak,
14919 show_ip_bgp_route_leak_cmd,
14920 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
14921 SHOW_STR
14922 IP_STR
14923 BGP_STR
14924 BGP_INSTANCE_HELP_STR
14925 BGP_AFI_HELP_STR
14926 BGP_SAFI_HELP_STR
14927 "Route leaking information\n"
14928 JSON_STR)
14929 {
14930 char *vrf = NULL;
14931 afi_t afi = AFI_MAX;
14932 safi_t safi = SAFI_MAX;
14933
14934 bool uj = use_json(argc, argv);
14935 int idx = 0;
14936 json_object *json = NULL;
14937
14938 /* show [ip] bgp */
14939 if (argv_find(argv, argc, "ip", &idx)) {
14940 afi = AFI_IP;
14941 safi = SAFI_UNICAST;
14942 }
14943 /* [vrf VIEWVRFNAME] */
14944 if (argv_find(argv, argc, "view", &idx)) {
14945 vty_out(vty,
14946 "%% This command is not applicable to BGP views\n");
14947 return CMD_WARNING;
14948 }
14949
14950 if (argv_find(argv, argc, "vrf", &idx)) {
14951 vrf = argv[idx + 1]->arg;
14952 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14953 vrf = NULL;
14954 }
14955 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14956 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
14957 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14958
14959 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
14960 vty_out(vty,
14961 "%% This command is applicable only for unicast ipv4|ipv6\n");
14962 return CMD_WARNING;
14963 }
14964
14965 if (vrf && strmatch(vrf, "all"))
14966 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14967
14968 if (uj)
14969 json = json_object_new_object();
14970
14971 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
14972 }
14973
14974 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14975 safi_t safi)
14976 {
14977 struct listnode *node, *nnode;
14978 struct bgp *bgp;
14979
14980 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14981 vty_out(vty, "\nInstance %s:\n",
14982 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14983 ? VRF_DEFAULT_NAME
14984 : bgp->name);
14985 update_group_show(bgp, afi, safi, vty, 0);
14986 }
14987 }
14988
14989 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14990 int safi, uint64_t subgrp_id)
14991 {
14992 struct bgp *bgp;
14993
14994 if (name) {
14995 if (strmatch(name, "all")) {
14996 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14997 return CMD_SUCCESS;
14998 } else {
14999 bgp = bgp_lookup_by_name(name);
15000 }
15001 } else {
15002 bgp = bgp_get_default();
15003 }
15004
15005 if (bgp)
15006 update_group_show(bgp, afi, safi, vty, subgrp_id);
15007 return CMD_SUCCESS;
15008 }
15009
15010 DEFUN (show_ip_bgp_updgrps,
15011 show_ip_bgp_updgrps_cmd,
15012 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15013 SHOW_STR
15014 IP_STR
15015 BGP_STR
15016 BGP_INSTANCE_HELP_STR
15017 BGP_AFI_HELP_STR
15018 BGP_SAFI_WITH_LABEL_HELP_STR
15019 "Detailed info about dynamic update groups\n"
15020 "Specific subgroup to display detailed info for\n")
15021 {
15022 char *vrf = NULL;
15023 afi_t afi = AFI_IP6;
15024 safi_t safi = SAFI_UNICAST;
15025 uint64_t subgrp_id = 0;
15026
15027 int idx = 0;
15028
15029 /* show [ip] bgp */
15030 if (argv_find(argv, argc, "ip", &idx))
15031 afi = AFI_IP;
15032 /* [<vrf> VIEWVRFNAME] */
15033 if (argv_find(argv, argc, "vrf", &idx)) {
15034 vrf = argv[idx + 1]->arg;
15035 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15036 vrf = NULL;
15037 } else if (argv_find(argv, argc, "view", &idx))
15038 /* [<view> VIEWVRFNAME] */
15039 vrf = argv[idx + 1]->arg;
15040 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15041 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15042 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15043 }
15044
15045 /* get subgroup id, if provided */
15046 idx = argc - 1;
15047 if (argv[idx]->type == VARIABLE_TKN)
15048 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15049
15050 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15051 }
15052
15053 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15054 show_bgp_instance_all_ipv6_updgrps_cmd,
15055 "show [ip] bgp <view|vrf> all update-groups",
15056 SHOW_STR
15057 IP_STR
15058 BGP_STR
15059 BGP_INSTANCE_ALL_HELP_STR
15060 "Detailed info about dynamic update groups\n")
15061 {
15062 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15063 return CMD_SUCCESS;
15064 }
15065
15066 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15067 show_bgp_l2vpn_evpn_updgrps_cmd,
15068 "show [ip] bgp l2vpn evpn update-groups",
15069 SHOW_STR
15070 IP_STR
15071 BGP_STR
15072 "l2vpn address family\n"
15073 "evpn sub-address family\n"
15074 "Detailed info about dynamic update groups\n")
15075 {
15076 char *vrf = NULL;
15077 uint64_t subgrp_id = 0;
15078
15079 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15080 return CMD_SUCCESS;
15081 }
15082
15083 DEFUN (show_bgp_updgrps_stats,
15084 show_bgp_updgrps_stats_cmd,
15085 "show [ip] bgp update-groups statistics",
15086 SHOW_STR
15087 IP_STR
15088 BGP_STR
15089 "Detailed info about dynamic update groups\n"
15090 "Statistics\n")
15091 {
15092 struct bgp *bgp;
15093
15094 bgp = bgp_get_default();
15095 if (bgp)
15096 update_group_show_stats(bgp, vty);
15097
15098 return CMD_SUCCESS;
15099 }
15100
15101 DEFUN (show_bgp_instance_updgrps_stats,
15102 show_bgp_instance_updgrps_stats_cmd,
15103 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15104 SHOW_STR
15105 IP_STR
15106 BGP_STR
15107 BGP_INSTANCE_HELP_STR
15108 "Detailed info about dynamic update groups\n"
15109 "Statistics\n")
15110 {
15111 int idx_word = 3;
15112 struct bgp *bgp;
15113
15114 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15115 if (bgp)
15116 update_group_show_stats(bgp, vty);
15117
15118 return CMD_SUCCESS;
15119 }
15120
15121 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15122 afi_t afi, safi_t safi,
15123 const char *what, uint64_t subgrp_id)
15124 {
15125 struct bgp *bgp;
15126
15127 if (name)
15128 bgp = bgp_lookup_by_name(name);
15129 else
15130 bgp = bgp_get_default();
15131
15132 if (bgp) {
15133 if (!strcmp(what, "advertise-queue"))
15134 update_group_show_adj_queue(bgp, afi, safi, vty,
15135 subgrp_id);
15136 else if (!strcmp(what, "advertised-routes"))
15137 update_group_show_advertised(bgp, afi, safi, vty,
15138 subgrp_id);
15139 else if (!strcmp(what, "packet-queue"))
15140 update_group_show_packet_queue(bgp, afi, safi, vty,
15141 subgrp_id);
15142 }
15143 }
15144
15145 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15146 show_ip_bgp_instance_updgrps_adj_s_cmd,
15147 "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",
15148 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15149 BGP_SAFI_HELP_STR
15150 "Detailed info about dynamic update groups\n"
15151 "Specific subgroup to display info for\n"
15152 "Advertisement queue\n"
15153 "Announced routes\n"
15154 "Packet queue\n")
15155 {
15156 uint64_t subgrp_id = 0;
15157 afi_t afiz;
15158 safi_t safiz;
15159 if (sgid)
15160 subgrp_id = strtoull(sgid, NULL, 10);
15161
15162 if (!ip && !afi)
15163 afiz = AFI_IP6;
15164 if (!ip && afi)
15165 afiz = bgp_vty_afi_from_str(afi);
15166 if (ip && !afi)
15167 afiz = AFI_IP;
15168 if (ip && afi) {
15169 afiz = bgp_vty_afi_from_str(afi);
15170 if (afiz != AFI_IP)
15171 vty_out(vty,
15172 "%% Cannot specify both 'ip' and 'ipv6'\n");
15173 return CMD_WARNING;
15174 }
15175
15176 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15177
15178 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15179 return CMD_SUCCESS;
15180 }
15181
15182 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15183 json_object *json)
15184 {
15185 struct listnode *node, *nnode;
15186 struct prefix *range;
15187 struct peer *conf;
15188 struct peer *peer;
15189 afi_t afi;
15190 safi_t safi;
15191 const char *peer_status;
15192 int lr_count;
15193 int dynamic;
15194 bool af_cfgd;
15195 json_object *json_peer_group = NULL;
15196 json_object *json_peer_group_afc = NULL;
15197 json_object *json_peer_group_members = NULL;
15198 json_object *json_peer_group_dynamic = NULL;
15199 json_object *json_peer_group_dynamic_af = NULL;
15200 json_object *json_peer_group_ranges = NULL;
15201
15202 conf = group->conf;
15203
15204 if (json) {
15205 json_peer_group = json_object_new_object();
15206 json_peer_group_afc = json_object_new_array();
15207 }
15208
15209 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15210 if (json)
15211 json_object_int_add(json_peer_group, "remoteAs",
15212 conf->as);
15213 else
15214 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15215 group->name, conf->as);
15216 } else if (conf->as_type == AS_INTERNAL) {
15217 if (json)
15218 json_object_int_add(json_peer_group, "remoteAs",
15219 group->bgp->as);
15220 else
15221 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15222 group->name, group->bgp->as);
15223 } else {
15224 if (!json)
15225 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15226 }
15227
15228 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15229 if (json)
15230 json_object_string_add(json_peer_group, "type",
15231 "internal");
15232 else
15233 vty_out(vty, " Peer-group type is internal\n");
15234 } else {
15235 if (json)
15236 json_object_string_add(json_peer_group, "type",
15237 "external");
15238 else
15239 vty_out(vty, " Peer-group type is external\n");
15240 }
15241
15242 /* Display AFs configured. */
15243 if (!json)
15244 vty_out(vty, " Configured address-families:");
15245
15246 FOREACH_AFI_SAFI (afi, safi) {
15247 if (conf->afc[afi][safi]) {
15248 af_cfgd = true;
15249 if (json)
15250 json_object_array_add(
15251 json_peer_group_afc,
15252 json_object_new_string(get_afi_safi_str(
15253 afi, safi, false)));
15254 else
15255 vty_out(vty, " %s;",
15256 get_afi_safi_str(afi, safi, false));
15257 }
15258 }
15259
15260 if (json) {
15261 json_object_object_add(json_peer_group,
15262 "addressFamiliesConfigured",
15263 json_peer_group_afc);
15264 } else {
15265 if (!af_cfgd)
15266 vty_out(vty, " none\n");
15267 else
15268 vty_out(vty, "\n");
15269 }
15270
15271 /* Display listen ranges (for dynamic neighbors), if any */
15272 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15273 lr_count = listcount(group->listen_range[afi]);
15274 if (lr_count) {
15275 if (json) {
15276 if (!json_peer_group_dynamic)
15277 json_peer_group_dynamic =
15278 json_object_new_object();
15279
15280 json_peer_group_dynamic_af =
15281 json_object_new_object();
15282 json_peer_group_ranges =
15283 json_object_new_array();
15284 json_object_int_add(json_peer_group_dynamic_af,
15285 "count", lr_count);
15286 } else {
15287 vty_out(vty, " %d %s listen range(s)\n",
15288 lr_count, afi2str(afi));
15289 }
15290
15291 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15292 nnode, range)) {
15293 if (json) {
15294 char buf[BUFSIZ];
15295
15296 snprintfrr(buf, sizeof(buf), "%pFX",
15297 range);
15298
15299 json_object_array_add(
15300 json_peer_group_ranges,
15301 json_object_new_string(buf));
15302 } else {
15303 vty_out(vty, " %pFX\n", range);
15304 }
15305 }
15306
15307 if (json) {
15308 json_object_object_add(
15309 json_peer_group_dynamic_af, "ranges",
15310 json_peer_group_ranges);
15311
15312 json_object_object_add(
15313 json_peer_group_dynamic, afi2str(afi),
15314 json_peer_group_dynamic_af);
15315 }
15316 }
15317 }
15318
15319 if (json_peer_group_dynamic)
15320 json_object_object_add(json_peer_group, "dynamicRanges",
15321 json_peer_group_dynamic);
15322
15323 /* Display group members and their status */
15324 if (listcount(group->peer)) {
15325 if (json)
15326 json_peer_group_members = json_object_new_object();
15327 else
15328 vty_out(vty, " Peer-group members:\n");
15329 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15330 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15331 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15332 peer_status = "Idle (Admin)";
15333 else if (CHECK_FLAG(peer->sflags,
15334 PEER_STATUS_PREFIX_OVERFLOW))
15335 peer_status = "Idle (PfxCt)";
15336 else
15337 peer_status = lookup_msg(bgp_status_msg,
15338 peer->status, NULL);
15339
15340 dynamic = peer_dynamic_neighbor(peer);
15341
15342 if (json) {
15343 json_object *json_peer_group_member =
15344 json_object_new_object();
15345
15346 json_object_string_add(json_peer_group_member,
15347 "status", peer_status);
15348
15349 if (dynamic)
15350 json_object_boolean_true_add(
15351 json_peer_group_member,
15352 "dynamic");
15353
15354 json_object_object_add(json_peer_group_members,
15355 peer->host,
15356 json_peer_group_member);
15357 } else {
15358 vty_out(vty, " %s %s %s \n", peer->host,
15359 dynamic ? "(dynamic)" : "",
15360 peer_status);
15361 }
15362 }
15363 if (json)
15364 json_object_object_add(json_peer_group, "members",
15365 json_peer_group_members);
15366 }
15367
15368 if (json)
15369 json_object_object_add(json, group->name, json_peer_group);
15370
15371 return CMD_SUCCESS;
15372 }
15373
15374 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15375 const char *group_name, bool uj)
15376 {
15377 struct bgp *bgp;
15378 struct listnode *node, *nnode;
15379 struct peer_group *group;
15380 bool found = false;
15381 json_object *json = NULL;
15382
15383 if (uj)
15384 json = json_object_new_object();
15385
15386 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15387
15388 if (!bgp) {
15389 if (uj)
15390 vty_json(vty, json);
15391 else
15392 vty_out(vty, "%% BGP instance not found\n");
15393
15394 return CMD_WARNING;
15395 }
15396
15397 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15398 if (group_name) {
15399 if (strmatch(group->name, group_name)) {
15400 bgp_show_one_peer_group(vty, group, json);
15401 found = true;
15402 break;
15403 }
15404 } else {
15405 bgp_show_one_peer_group(vty, group, json);
15406 }
15407 }
15408
15409 if (group_name && !found && !uj)
15410 vty_out(vty, "%% No such peer-group\n");
15411
15412 if (uj)
15413 vty_json(vty, json);
15414
15415 return CMD_SUCCESS;
15416 }
15417
15418 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15419 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15420 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15421 "Detailed information on BGP peer groups\n"
15422 "Peer group name\n" JSON_STR)
15423 {
15424 char *vrf, *pg;
15425 int idx = 0;
15426 bool uj = use_json(argc, argv);
15427
15428 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15429 : NULL;
15430 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15431
15432 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15433 }
15434
15435
15436 /* Redistribute VTY commands. */
15437
15438 DEFUN (bgp_redistribute_ipv4,
15439 bgp_redistribute_ipv4_cmd,
15440 "redistribute " FRR_IP_REDIST_STR_BGPD,
15441 "Redistribute information from another routing protocol\n"
15442 FRR_IP_REDIST_HELP_STR_BGPD)
15443 {
15444 VTY_DECLVAR_CONTEXT(bgp, bgp);
15445 int idx_protocol = 1;
15446 int type;
15447
15448 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15449 if (type < 0) {
15450 vty_out(vty, "%% Invalid route type\n");
15451 return CMD_WARNING_CONFIG_FAILED;
15452 }
15453
15454 bgp_redist_add(bgp, AFI_IP, type, 0);
15455 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15456 }
15457
15458 ALIAS_HIDDEN(
15459 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15460 "redistribute " FRR_IP_REDIST_STR_BGPD,
15461 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15462
15463 DEFUN (bgp_redistribute_ipv4_rmap,
15464 bgp_redistribute_ipv4_rmap_cmd,
15465 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15466 "Redistribute information from another routing protocol\n"
15467 FRR_IP_REDIST_HELP_STR_BGPD
15468 "Route map reference\n"
15469 "Pointer to route-map entries\n")
15470 {
15471 VTY_DECLVAR_CONTEXT(bgp, bgp);
15472 int idx_protocol = 1;
15473 int idx_word = 3;
15474 int type;
15475 struct bgp_redist *red;
15476 bool changed;
15477 struct route_map *route_map = route_map_lookup_warn_noexist(
15478 vty, argv[idx_word]->arg);
15479
15480 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15481 if (type < 0) {
15482 vty_out(vty, "%% Invalid route type\n");
15483 return CMD_WARNING_CONFIG_FAILED;
15484 }
15485
15486 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15487 changed =
15488 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15489 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15490 }
15491
15492 ALIAS_HIDDEN(
15493 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15494 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15495 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15496 "Route map reference\n"
15497 "Pointer to route-map entries\n")
15498
15499 DEFUN (bgp_redistribute_ipv4_metric,
15500 bgp_redistribute_ipv4_metric_cmd,
15501 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15502 "Redistribute information from another routing protocol\n"
15503 FRR_IP_REDIST_HELP_STR_BGPD
15504 "Metric for redistributed routes\n"
15505 "Default metric\n")
15506 {
15507 VTY_DECLVAR_CONTEXT(bgp, bgp);
15508 int idx_protocol = 1;
15509 int idx_number = 3;
15510 int type;
15511 uint32_t metric;
15512 struct bgp_redist *red;
15513 bool changed;
15514
15515 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15516 if (type < 0) {
15517 vty_out(vty, "%% Invalid route type\n");
15518 return CMD_WARNING_CONFIG_FAILED;
15519 }
15520 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15521
15522 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15523 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15524 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15525 }
15526
15527 ALIAS_HIDDEN(
15528 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15529 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15530 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15531 "Metric for redistributed routes\n"
15532 "Default metric\n")
15533
15534 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15535 bgp_redistribute_ipv4_rmap_metric_cmd,
15536 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15537 "Redistribute information from another routing protocol\n"
15538 FRR_IP_REDIST_HELP_STR_BGPD
15539 "Route map reference\n"
15540 "Pointer to route-map entries\n"
15541 "Metric for redistributed routes\n"
15542 "Default metric\n")
15543 {
15544 VTY_DECLVAR_CONTEXT(bgp, bgp);
15545 int idx_protocol = 1;
15546 int idx_word = 3;
15547 int idx_number = 5;
15548 int type;
15549 uint32_t metric;
15550 struct bgp_redist *red;
15551 bool changed;
15552 struct route_map *route_map =
15553 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15554
15555 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15556 if (type < 0) {
15557 vty_out(vty, "%% Invalid route type\n");
15558 return CMD_WARNING_CONFIG_FAILED;
15559 }
15560 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15561
15562 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15563 changed =
15564 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15565 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15566 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15567 }
15568
15569 ALIAS_HIDDEN(
15570 bgp_redistribute_ipv4_rmap_metric,
15571 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15572 "redistribute " FRR_IP_REDIST_STR_BGPD
15573 " route-map WORD metric (0-4294967295)",
15574 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15575 "Route map reference\n"
15576 "Pointer to route-map entries\n"
15577 "Metric for redistributed routes\n"
15578 "Default metric\n")
15579
15580 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15581 bgp_redistribute_ipv4_metric_rmap_cmd,
15582 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15583 "Redistribute information from another routing protocol\n"
15584 FRR_IP_REDIST_HELP_STR_BGPD
15585 "Metric for redistributed routes\n"
15586 "Default metric\n"
15587 "Route map reference\n"
15588 "Pointer to route-map entries\n")
15589 {
15590 VTY_DECLVAR_CONTEXT(bgp, bgp);
15591 int idx_protocol = 1;
15592 int idx_number = 3;
15593 int idx_word = 5;
15594 int type;
15595 uint32_t metric;
15596 struct bgp_redist *red;
15597 bool changed;
15598 struct route_map *route_map =
15599 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15600
15601 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15602 if (type < 0) {
15603 vty_out(vty, "%% Invalid route type\n");
15604 return CMD_WARNING_CONFIG_FAILED;
15605 }
15606 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15607
15608 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15609 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15610 changed |=
15611 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15612 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15613 }
15614
15615 ALIAS_HIDDEN(
15616 bgp_redistribute_ipv4_metric_rmap,
15617 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15618 "redistribute " FRR_IP_REDIST_STR_BGPD
15619 " metric (0-4294967295) route-map WORD",
15620 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15621 "Metric for redistributed routes\n"
15622 "Default metric\n"
15623 "Route map reference\n"
15624 "Pointer to route-map entries\n")
15625
15626 DEFUN (bgp_redistribute_ipv4_ospf,
15627 bgp_redistribute_ipv4_ospf_cmd,
15628 "redistribute <ospf|table> (1-65535)",
15629 "Redistribute information from another routing protocol\n"
15630 "Open Shortest Path First (OSPFv2)\n"
15631 "Non-main Kernel Routing Table\n"
15632 "Instance ID/Table ID\n")
15633 {
15634 VTY_DECLVAR_CONTEXT(bgp, bgp);
15635 int idx_ospf_table = 1;
15636 int idx_number = 2;
15637 unsigned short instance;
15638 unsigned short protocol;
15639
15640 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15641
15642 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15643 protocol = ZEBRA_ROUTE_OSPF;
15644 else
15645 protocol = ZEBRA_ROUTE_TABLE;
15646
15647 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15648 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15649 }
15650
15651 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15652 "redistribute <ospf|table> (1-65535)",
15653 "Redistribute information from another routing protocol\n"
15654 "Open Shortest Path First (OSPFv2)\n"
15655 "Non-main Kernel Routing Table\n"
15656 "Instance ID/Table ID\n")
15657
15658 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15659 bgp_redistribute_ipv4_ospf_rmap_cmd,
15660 "redistribute <ospf|table> (1-65535) route-map WORD",
15661 "Redistribute information from another routing protocol\n"
15662 "Open Shortest Path First (OSPFv2)\n"
15663 "Non-main Kernel Routing Table\n"
15664 "Instance ID/Table ID\n"
15665 "Route map reference\n"
15666 "Pointer to route-map entries\n")
15667 {
15668 VTY_DECLVAR_CONTEXT(bgp, bgp);
15669 int idx_ospf_table = 1;
15670 int idx_number = 2;
15671 int idx_word = 4;
15672 struct bgp_redist *red;
15673 unsigned short instance;
15674 int protocol;
15675 bool changed;
15676 struct route_map *route_map =
15677 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15678
15679 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15680 protocol = ZEBRA_ROUTE_OSPF;
15681 else
15682 protocol = ZEBRA_ROUTE_TABLE;
15683
15684 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15685 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15686 changed =
15687 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15688 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15689 }
15690
15691 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15692 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15693 "redistribute <ospf|table> (1-65535) route-map WORD",
15694 "Redistribute information from another routing protocol\n"
15695 "Open Shortest Path First (OSPFv2)\n"
15696 "Non-main Kernel Routing Table\n"
15697 "Instance ID/Table ID\n"
15698 "Route map reference\n"
15699 "Pointer to route-map entries\n")
15700
15701 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15702 bgp_redistribute_ipv4_ospf_metric_cmd,
15703 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15704 "Redistribute information from another routing protocol\n"
15705 "Open Shortest Path First (OSPFv2)\n"
15706 "Non-main Kernel Routing Table\n"
15707 "Instance ID/Table ID\n"
15708 "Metric for redistributed routes\n"
15709 "Default metric\n")
15710 {
15711 VTY_DECLVAR_CONTEXT(bgp, bgp);
15712 int idx_ospf_table = 1;
15713 int idx_number = 2;
15714 int idx_number_2 = 4;
15715 uint32_t metric;
15716 struct bgp_redist *red;
15717 unsigned short instance;
15718 int protocol;
15719 bool changed;
15720
15721 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15722 protocol = ZEBRA_ROUTE_OSPF;
15723 else
15724 protocol = ZEBRA_ROUTE_TABLE;
15725
15726 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15727 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15728
15729 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15730 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15731 metric);
15732 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15733 }
15734
15735 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15736 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15737 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15738 "Redistribute information from another routing protocol\n"
15739 "Open Shortest Path First (OSPFv2)\n"
15740 "Non-main Kernel Routing Table\n"
15741 "Instance ID/Table ID\n"
15742 "Metric for redistributed routes\n"
15743 "Default metric\n")
15744
15745 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15746 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15747 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15748 "Redistribute information from another routing protocol\n"
15749 "Open Shortest Path First (OSPFv2)\n"
15750 "Non-main Kernel Routing Table\n"
15751 "Instance ID/Table ID\n"
15752 "Route map reference\n"
15753 "Pointer to route-map entries\n"
15754 "Metric for redistributed routes\n"
15755 "Default metric\n")
15756 {
15757 VTY_DECLVAR_CONTEXT(bgp, bgp);
15758 int idx_ospf_table = 1;
15759 int idx_number = 2;
15760 int idx_word = 4;
15761 int idx_number_2 = 6;
15762 uint32_t metric;
15763 struct bgp_redist *red;
15764 unsigned short instance;
15765 int protocol;
15766 bool changed;
15767 struct route_map *route_map =
15768 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15769
15770 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15771 protocol = ZEBRA_ROUTE_OSPF;
15772 else
15773 protocol = ZEBRA_ROUTE_TABLE;
15774
15775 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15776 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15777
15778 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15779 changed =
15780 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15781 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15782 metric);
15783 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15784 }
15785
15786 ALIAS_HIDDEN(
15787 bgp_redistribute_ipv4_ospf_rmap_metric,
15788 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15789 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15790 "Redistribute information from another routing protocol\n"
15791 "Open Shortest Path First (OSPFv2)\n"
15792 "Non-main Kernel Routing Table\n"
15793 "Instance ID/Table ID\n"
15794 "Route map reference\n"
15795 "Pointer to route-map entries\n"
15796 "Metric for redistributed routes\n"
15797 "Default metric\n")
15798
15799 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15800 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15801 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15802 "Redistribute information from another routing protocol\n"
15803 "Open Shortest Path First (OSPFv2)\n"
15804 "Non-main Kernel Routing Table\n"
15805 "Instance ID/Table ID\n"
15806 "Metric for redistributed routes\n"
15807 "Default metric\n"
15808 "Route map reference\n"
15809 "Pointer to route-map entries\n")
15810 {
15811 VTY_DECLVAR_CONTEXT(bgp, bgp);
15812 int idx_ospf_table = 1;
15813 int idx_number = 2;
15814 int idx_number_2 = 4;
15815 int idx_word = 6;
15816 uint32_t metric;
15817 struct bgp_redist *red;
15818 unsigned short instance;
15819 int protocol;
15820 bool changed;
15821 struct route_map *route_map =
15822 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15823
15824 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15825 protocol = ZEBRA_ROUTE_OSPF;
15826 else
15827 protocol = ZEBRA_ROUTE_TABLE;
15828
15829 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15830 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15831
15832 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15833 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15834 metric);
15835 changed |=
15836 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15837 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15838 }
15839
15840 ALIAS_HIDDEN(
15841 bgp_redistribute_ipv4_ospf_metric_rmap,
15842 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15843 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15844 "Redistribute information from another routing protocol\n"
15845 "Open Shortest Path First (OSPFv2)\n"
15846 "Non-main Kernel Routing Table\n"
15847 "Instance ID/Table ID\n"
15848 "Metric for redistributed routes\n"
15849 "Default metric\n"
15850 "Route map reference\n"
15851 "Pointer to route-map entries\n")
15852
15853 DEFUN (no_bgp_redistribute_ipv4_ospf,
15854 no_bgp_redistribute_ipv4_ospf_cmd,
15855 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15856 NO_STR
15857 "Redistribute information from another routing protocol\n"
15858 "Open Shortest Path First (OSPFv2)\n"
15859 "Non-main Kernel Routing Table\n"
15860 "Instance ID/Table ID\n"
15861 "Metric for redistributed routes\n"
15862 "Default metric\n"
15863 "Route map reference\n"
15864 "Pointer to route-map entries\n")
15865 {
15866 VTY_DECLVAR_CONTEXT(bgp, bgp);
15867 int idx_ospf_table = 2;
15868 int idx_number = 3;
15869 unsigned short instance;
15870 int protocol;
15871
15872 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15873 protocol = ZEBRA_ROUTE_OSPF;
15874 else
15875 protocol = ZEBRA_ROUTE_TABLE;
15876
15877 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15878 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
15879 }
15880
15881 ALIAS_HIDDEN(
15882 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15883 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15884 NO_STR
15885 "Redistribute information from another routing protocol\n"
15886 "Open Shortest Path First (OSPFv2)\n"
15887 "Non-main Kernel Routing Table\n"
15888 "Instance ID/Table ID\n"
15889 "Metric for redistributed routes\n"
15890 "Default metric\n"
15891 "Route map reference\n"
15892 "Pointer to route-map entries\n")
15893
15894 DEFUN (no_bgp_redistribute_ipv4,
15895 no_bgp_redistribute_ipv4_cmd,
15896 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15897 NO_STR
15898 "Redistribute information from another routing protocol\n"
15899 FRR_IP_REDIST_HELP_STR_BGPD
15900 "Metric for redistributed routes\n"
15901 "Default metric\n"
15902 "Route map reference\n"
15903 "Pointer to route-map entries\n")
15904 {
15905 VTY_DECLVAR_CONTEXT(bgp, bgp);
15906 int idx_protocol = 2;
15907 int type;
15908
15909 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15910 if (type < 0) {
15911 vty_out(vty, "%% Invalid route type\n");
15912 return CMD_WARNING_CONFIG_FAILED;
15913 }
15914 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
15915 }
15916
15917 ALIAS_HIDDEN(
15918 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15919 "no redistribute " FRR_IP_REDIST_STR_BGPD
15920 " [{metric (0-4294967295)|route-map WORD}]",
15921 NO_STR
15922 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15923 "Metric for redistributed routes\n"
15924 "Default metric\n"
15925 "Route map reference\n"
15926 "Pointer to route-map entries\n")
15927
15928 DEFUN (bgp_redistribute_ipv6,
15929 bgp_redistribute_ipv6_cmd,
15930 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15931 "Redistribute information from another routing protocol\n"
15932 FRR_IP6_REDIST_HELP_STR_BGPD)
15933 {
15934 VTY_DECLVAR_CONTEXT(bgp, bgp);
15935 int idx_protocol = 1;
15936 int type;
15937
15938 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15939 if (type < 0) {
15940 vty_out(vty, "%% Invalid route type\n");
15941 return CMD_WARNING_CONFIG_FAILED;
15942 }
15943
15944 bgp_redist_add(bgp, AFI_IP6, type, 0);
15945 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
15946 }
15947
15948 DEFUN (bgp_redistribute_ipv6_rmap,
15949 bgp_redistribute_ipv6_rmap_cmd,
15950 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15951 "Redistribute information from another routing protocol\n"
15952 FRR_IP6_REDIST_HELP_STR_BGPD
15953 "Route map reference\n"
15954 "Pointer to route-map entries\n")
15955 {
15956 VTY_DECLVAR_CONTEXT(bgp, bgp);
15957 int idx_protocol = 1;
15958 int idx_word = 3;
15959 int type;
15960 struct bgp_redist *red;
15961 bool changed;
15962 struct route_map *route_map =
15963 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15964
15965 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15966 if (type < 0) {
15967 vty_out(vty, "%% Invalid route type\n");
15968 return CMD_WARNING_CONFIG_FAILED;
15969 }
15970
15971 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15972 changed =
15973 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15974 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15975 }
15976
15977 DEFUN (bgp_redistribute_ipv6_metric,
15978 bgp_redistribute_ipv6_metric_cmd,
15979 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
15980 "Redistribute information from another routing protocol\n"
15981 FRR_IP6_REDIST_HELP_STR_BGPD
15982 "Metric for redistributed routes\n"
15983 "Default metric\n")
15984 {
15985 VTY_DECLVAR_CONTEXT(bgp, bgp);
15986 int idx_protocol = 1;
15987 int idx_number = 3;
15988 int type;
15989 uint32_t metric;
15990 struct bgp_redist *red;
15991 bool changed;
15992
15993 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15994 if (type < 0) {
15995 vty_out(vty, "%% Invalid route type\n");
15996 return CMD_WARNING_CONFIG_FAILED;
15997 }
15998 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15999
16000 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16001 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16002 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16003 }
16004
16005 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16006 bgp_redistribute_ipv6_rmap_metric_cmd,
16007 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
16008 "Redistribute information from another routing protocol\n"
16009 FRR_IP6_REDIST_HELP_STR_BGPD
16010 "Route map reference\n"
16011 "Pointer to route-map entries\n"
16012 "Metric for redistributed routes\n"
16013 "Default metric\n")
16014 {
16015 VTY_DECLVAR_CONTEXT(bgp, bgp);
16016 int idx_protocol = 1;
16017 int idx_word = 3;
16018 int idx_number = 5;
16019 int type;
16020 uint32_t metric;
16021 struct bgp_redist *red;
16022 bool changed;
16023 struct route_map *route_map =
16024 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16025
16026 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16027 if (type < 0) {
16028 vty_out(vty, "%% Invalid route type\n");
16029 return CMD_WARNING_CONFIG_FAILED;
16030 }
16031 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16032
16033 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16034 changed =
16035 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16036 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16037 metric);
16038 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16039 }
16040
16041 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16042 bgp_redistribute_ipv6_metric_rmap_cmd,
16043 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
16044 "Redistribute information from another routing protocol\n"
16045 FRR_IP6_REDIST_HELP_STR_BGPD
16046 "Metric for redistributed routes\n"
16047 "Default metric\n"
16048 "Route map reference\n"
16049 "Pointer to route-map entries\n")
16050 {
16051 VTY_DECLVAR_CONTEXT(bgp, bgp);
16052 int idx_protocol = 1;
16053 int idx_number = 3;
16054 int idx_word = 5;
16055 int type;
16056 uint32_t metric;
16057 struct bgp_redist *red;
16058 bool changed;
16059 struct route_map *route_map =
16060 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16061
16062 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16063 if (type < 0) {
16064 vty_out(vty, "%% Invalid route type\n");
16065 return CMD_WARNING_CONFIG_FAILED;
16066 }
16067 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16068
16069 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16070 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16071 metric);
16072 changed |=
16073 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16074 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16075 }
16076
16077 DEFUN (no_bgp_redistribute_ipv6,
16078 no_bgp_redistribute_ipv6_cmd,
16079 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16080 NO_STR
16081 "Redistribute information from another routing protocol\n"
16082 FRR_IP6_REDIST_HELP_STR_BGPD
16083 "Metric for redistributed routes\n"
16084 "Default metric\n"
16085 "Route map reference\n"
16086 "Pointer to route-map entries\n")
16087 {
16088 VTY_DECLVAR_CONTEXT(bgp, bgp);
16089 int idx_protocol = 2;
16090 int type;
16091
16092 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16093 if (type < 0) {
16094 vty_out(vty, "%% Invalid route type\n");
16095 return CMD_WARNING_CONFIG_FAILED;
16096 }
16097
16098 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16099 }
16100
16101 /* Neighbor update tcp-mss. */
16102 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16103 const char *tcp_mss_str)
16104 {
16105 struct peer *peer;
16106 uint32_t tcp_mss_val = 0;
16107
16108 peer = peer_and_group_lookup_vty(vty, peer_str);
16109 if (!peer)
16110 return CMD_WARNING_CONFIG_FAILED;
16111
16112 if (tcp_mss_str) {
16113 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16114 peer_tcp_mss_set(peer, tcp_mss_val);
16115 } else {
16116 peer_tcp_mss_unset(peer);
16117 }
16118
16119 return CMD_SUCCESS;
16120 }
16121
16122 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16123 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16124 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16125 "TCP max segment size\n"
16126 "TCP MSS value\n")
16127 {
16128 int peer_index = 1;
16129 int mss_index = 3;
16130
16131 vty_out(vty,
16132 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16133 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16134 argv[mss_index]->arg);
16135 }
16136
16137 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16138 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16139 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16140 "TCP max segment size\n"
16141 "TCP MSS value\n")
16142 {
16143 int peer_index = 2;
16144
16145 vty_out(vty,
16146 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16147 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16148 }
16149
16150 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16151 afi_t afi, safi_t safi)
16152 {
16153 int i;
16154
16155 /* Unicast redistribution only. */
16156 if (safi != SAFI_UNICAST)
16157 return;
16158
16159 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16160 /* Redistribute BGP does not make sense. */
16161 if (i != ZEBRA_ROUTE_BGP) {
16162 struct list *red_list;
16163 struct listnode *node;
16164 struct bgp_redist *red;
16165
16166 red_list = bgp->redist[afi][i];
16167 if (!red_list)
16168 continue;
16169
16170 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16171 /* "redistribute" configuration. */
16172 vty_out(vty, " redistribute %s",
16173 zebra_route_string(i));
16174 if (red->instance)
16175 vty_out(vty, " %d", red->instance);
16176 if (red->redist_metric_flag)
16177 vty_out(vty, " metric %u",
16178 red->redist_metric);
16179 if (red->rmap.name)
16180 vty_out(vty, " route-map %s",
16181 red->rmap.name);
16182 vty_out(vty, "\n");
16183 }
16184 }
16185 }
16186 }
16187
16188 /* peer-group helpers for config-write */
16189
16190 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16191 {
16192 if (!peer_group_active(peer)) {
16193 if (CHECK_FLAG(peer->flags_invert, flag))
16194 return !CHECK_FLAG(peer->flags, flag);
16195 else
16196 return !!CHECK_FLAG(peer->flags, flag);
16197 }
16198
16199 return !!CHECK_FLAG(peer->flags_override, flag);
16200 }
16201
16202 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16203 uint32_t flag)
16204 {
16205 if (!peer_group_active(peer)) {
16206 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16207 return !peer_af_flag_check(peer, afi, safi, flag);
16208 else
16209 return !!peer_af_flag_check(peer, afi, safi, flag);
16210 }
16211
16212 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16213 }
16214
16215 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16216 uint8_t type, int direct)
16217 {
16218 struct bgp_filter *filter;
16219
16220 if (peer_group_active(peer))
16221 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16222 type);
16223
16224 filter = &peer->filter[afi][safi];
16225 switch (type) {
16226 case PEER_FT_DISTRIBUTE_LIST:
16227 return !!(filter->dlist[direct].name);
16228 case PEER_FT_FILTER_LIST:
16229 return !!(filter->aslist[direct].name);
16230 case PEER_FT_PREFIX_LIST:
16231 return !!(filter->plist[direct].name);
16232 case PEER_FT_ROUTE_MAP:
16233 return !!(filter->map[direct].name);
16234 case PEER_FT_UNSUPPRESS_MAP:
16235 return !!(filter->usmap.name);
16236 case PEER_FT_ADVERTISE_MAP:
16237 return !!(filter->advmap.aname
16238 && ((filter->advmap.condition == direct)
16239 && filter->advmap.cname));
16240 default:
16241 return false;
16242 }
16243 }
16244
16245 /* Return true if the addpath type is set for peer and different from
16246 * peer-group.
16247 */
16248 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16249 safi_t safi)
16250 {
16251 enum bgp_addpath_strat type, g_type;
16252
16253 type = peer->addpath_type[afi][safi];
16254
16255 if (type != BGP_ADDPATH_NONE) {
16256 if (peer_group_active(peer)) {
16257 g_type = peer->group->conf->addpath_type[afi][safi];
16258
16259 if (type != g_type)
16260 return true;
16261 else
16262 return false;
16263 }
16264
16265 return true;
16266 }
16267
16268 return false;
16269 }
16270
16271 /* This is part of the address-family block (unicast only) */
16272 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16273 afi_t afi)
16274 {
16275 int indent = 2;
16276 uint32_t tovpn_sid_index = 0;
16277
16278 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16279 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16280 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16281 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16282 bgp->vpn_policy[afi]
16283 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16284 else
16285 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16286 bgp->vpn_policy[afi]
16287 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16288 }
16289 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16290 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16291 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16292 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16293 return;
16294
16295 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16296 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16297
16298 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16299
16300 } else {
16301 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16302 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16303 bgp->vpn_policy[afi].tovpn_label);
16304 }
16305 }
16306
16307 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16308 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16309 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16310 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16311 } else if (tovpn_sid_index != 0) {
16312 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16313 tovpn_sid_index);
16314 }
16315
16316 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16317 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16318 char buf[RD_ADDRSTRLEN];
16319 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16320 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16321 sizeof(buf)));
16322 }
16323 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16324 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16325
16326 char buf[PREFIX_STRLEN];
16327 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16328 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16329 sizeof(buf))) {
16330
16331 vty_out(vty, "%*snexthop vpn export %s\n",
16332 indent, "", buf);
16333 }
16334 }
16335 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16336 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16337 && ecommunity_cmp(
16338 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16339 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16340
16341 char *b = ecommunity_ecom2str(
16342 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16343 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16344 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16345 XFREE(MTYPE_ECOMMUNITY_STR, b);
16346 } else {
16347 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16348 char *b = ecommunity_ecom2str(
16349 bgp->vpn_policy[afi]
16350 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16351 ECOMMUNITY_FORMAT_ROUTE_MAP,
16352 ECOMMUNITY_ROUTE_TARGET);
16353 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16354 XFREE(MTYPE_ECOMMUNITY_STR, b);
16355 }
16356 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16357 char *b = ecommunity_ecom2str(
16358 bgp->vpn_policy[afi]
16359 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16360 ECOMMUNITY_FORMAT_ROUTE_MAP,
16361 ECOMMUNITY_ROUTE_TARGET);
16362 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16363 XFREE(MTYPE_ECOMMUNITY_STR, b);
16364 }
16365 }
16366
16367 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16368 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16369 bgp->vpn_policy[afi]
16370 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16371
16372 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16373 char *b = ecommunity_ecom2str(
16374 bgp->vpn_policy[afi]
16375 .import_redirect_rtlist,
16376 ECOMMUNITY_FORMAT_ROUTE_MAP,
16377 ECOMMUNITY_ROUTE_TARGET);
16378
16379 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16380 != ECOMMUNITY_SIZE)
16381 vty_out(vty, "%*srt6 redirect import %s\n",
16382 indent, "", b);
16383 else
16384 vty_out(vty, "%*srt redirect import %s\n",
16385 indent, "", b);
16386 XFREE(MTYPE_ECOMMUNITY_STR, b);
16387 }
16388 }
16389
16390 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16391 afi_t afi, safi_t safi)
16392 {
16393 struct bgp_filter *filter;
16394 char *addr;
16395
16396 addr = peer->host;
16397 filter = &peer->filter[afi][safi];
16398
16399 /* distribute-list. */
16400 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16401 FILTER_IN))
16402 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16403 filter->dlist[FILTER_IN].name);
16404
16405 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16406 FILTER_OUT))
16407 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16408 filter->dlist[FILTER_OUT].name);
16409
16410 /* prefix-list. */
16411 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16412 FILTER_IN))
16413 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16414 filter->plist[FILTER_IN].name);
16415
16416 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16417 FILTER_OUT))
16418 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16419 filter->plist[FILTER_OUT].name);
16420
16421 /* route-map. */
16422 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16423 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16424 filter->map[RMAP_IN].name);
16425
16426 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16427 RMAP_OUT))
16428 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16429 filter->map[RMAP_OUT].name);
16430
16431 /* unsuppress-map */
16432 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16433 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16434 filter->usmap.name);
16435
16436 /* advertise-map : always applied in OUT direction*/
16437 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16438 CONDITION_NON_EXIST))
16439 vty_out(vty,
16440 " neighbor %s advertise-map %s non-exist-map %s\n",
16441 addr, filter->advmap.aname, filter->advmap.cname);
16442
16443 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16444 CONDITION_EXIST))
16445 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16446 addr, filter->advmap.aname, filter->advmap.cname);
16447
16448 /* filter-list. */
16449 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16450 FILTER_IN))
16451 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16452 filter->aslist[FILTER_IN].name);
16453
16454 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16455 FILTER_OUT))
16456 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16457 filter->aslist[FILTER_OUT].name);
16458 }
16459
16460 /* BGP peer configuration display function. */
16461 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16462 struct peer *peer)
16463 {
16464 struct peer *g_peer = NULL;
16465 char buf[SU_ADDRSTRLEN];
16466 char *addr;
16467 int if_pg_printed = false;
16468 int if_ras_printed = false;
16469
16470 /* Skip dynamic neighbors. */
16471 if (peer_dynamic_neighbor(peer))
16472 return;
16473
16474 if (peer->conf_if)
16475 addr = peer->conf_if;
16476 else
16477 addr = peer->host;
16478
16479 /************************************
16480 ****** Global to the neighbor ******
16481 ************************************/
16482 if (peer->conf_if) {
16483 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16484 vty_out(vty, " neighbor %s interface v6only", addr);
16485 else
16486 vty_out(vty, " neighbor %s interface", addr);
16487
16488 if (peer_group_active(peer)) {
16489 vty_out(vty, " peer-group %s", peer->group->name);
16490 if_pg_printed = true;
16491 } else if (peer->as_type == AS_SPECIFIED) {
16492 vty_out(vty, " remote-as %u", peer->as);
16493 if_ras_printed = true;
16494 } else if (peer->as_type == AS_INTERNAL) {
16495 vty_out(vty, " remote-as internal");
16496 if_ras_printed = true;
16497 } else if (peer->as_type == AS_EXTERNAL) {
16498 vty_out(vty, " remote-as external");
16499 if_ras_printed = true;
16500 }
16501
16502 vty_out(vty, "\n");
16503 }
16504
16505 /* remote-as and peer-group */
16506 /* peer is a member of a peer-group */
16507 if (peer_group_active(peer)) {
16508 g_peer = peer->group->conf;
16509
16510 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16511 if (peer->as_type == AS_SPECIFIED) {
16512 vty_out(vty, " neighbor %s remote-as %u\n",
16513 addr, peer->as);
16514 } else if (peer->as_type == AS_INTERNAL) {
16515 vty_out(vty,
16516 " neighbor %s remote-as internal\n",
16517 addr);
16518 } else if (peer->as_type == AS_EXTERNAL) {
16519 vty_out(vty,
16520 " neighbor %s remote-as external\n",
16521 addr);
16522 }
16523 }
16524
16525 /* For swpX peers we displayed the peer-group
16526 * via 'neighbor swpX interface peer-group PGNAME' */
16527 if (!if_pg_printed)
16528 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16529 peer->group->name);
16530 }
16531
16532 /* peer is NOT a member of a peer-group */
16533 else {
16534 /* peer is a peer-group, declare the peer-group */
16535 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16536 vty_out(vty, " neighbor %s peer-group\n", addr);
16537 }
16538
16539 if (!if_ras_printed) {
16540 if (peer->as_type == AS_SPECIFIED) {
16541 vty_out(vty, " neighbor %s remote-as %u\n",
16542 addr, peer->as);
16543 } else if (peer->as_type == AS_INTERNAL) {
16544 vty_out(vty,
16545 " neighbor %s remote-as internal\n",
16546 addr);
16547 } else if (peer->as_type == AS_EXTERNAL) {
16548 vty_out(vty,
16549 " neighbor %s remote-as external\n",
16550 addr);
16551 }
16552 }
16553 }
16554
16555 /* local-as */
16556 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16557 vty_out(vty, " neighbor %s local-as %u", addr,
16558 peer->change_local_as);
16559 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16560 vty_out(vty, " no-prepend");
16561 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16562 vty_out(vty, " replace-as");
16563 vty_out(vty, "\n");
16564 }
16565
16566 /* description */
16567 if (peer->desc) {
16568 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16569 }
16570
16571 /* shutdown */
16572 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16573 if (peer->tx_shutdown_message)
16574 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16575 peer->tx_shutdown_message);
16576 else
16577 vty_out(vty, " neighbor %s shutdown\n", addr);
16578 }
16579
16580 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16581 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16582 peer->rtt_expected, peer->rtt_keepalive_conf);
16583
16584 /* bfd */
16585 if (peer->bfd_config)
16586 bgp_bfd_peer_config_write(vty, peer, addr);
16587
16588 /* password */
16589 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16590 vty_out(vty, " neighbor %s password %s\n", addr,
16591 peer->password);
16592
16593 /* neighbor solo */
16594 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16595 if (!peer_group_active(peer)) {
16596 vty_out(vty, " neighbor %s solo\n", addr);
16597 }
16598 }
16599
16600 /* BGP port */
16601 if (peer->port != BGP_PORT_DEFAULT) {
16602 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16603 }
16604
16605 /* Local interface name */
16606 if (peer->ifname) {
16607 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16608 }
16609
16610 /* TCP max segment size */
16611 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16612 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16613
16614 /* passive */
16615 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16616 vty_out(vty, " neighbor %s passive\n", addr);
16617
16618 /* ebgp-multihop */
16619 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16620 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16621 && peer->ttl == MAXTTL)) {
16622 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16623 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16624 peer->ttl);
16625 }
16626 }
16627
16628 /* ttl-security hops */
16629 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16630 if (!peer_group_active(peer)
16631 || g_peer->gtsm_hops != peer->gtsm_hops) {
16632 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16633 addr, peer->gtsm_hops);
16634 }
16635 }
16636
16637 /* disable-connected-check */
16638 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16639 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16640
16641 /* link-bw-encoding-ieee */
16642 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16643 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16644 addr);
16645
16646 /* extended-optional-parameters */
16647 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16648 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16649 addr);
16650
16651 /* enforce-first-as */
16652 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16653 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16654
16655 /* update-source */
16656 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16657 if (peer->update_source)
16658 vty_out(vty, " neighbor %s update-source %s\n", addr,
16659 sockunion2str(peer->update_source, buf,
16660 SU_ADDRSTRLEN));
16661 else if (peer->update_if)
16662 vty_out(vty, " neighbor %s update-source %s\n", addr,
16663 peer->update_if);
16664 }
16665
16666 /* advertisement-interval */
16667 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16668 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16669 peer->routeadv);
16670
16671 /* timers */
16672 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16673 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16674 peer->keepalive, peer->holdtime);
16675
16676 /* timers connect */
16677 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16678 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16679 peer->connect);
16680 /* need special-case handling for changed default values due to
16681 * config profile / version (because there is no "timers bgp connect"
16682 * command, we need to save this per-peer :/)
16683 */
16684 else if (!peer_group_active(peer) && !peer->connect &&
16685 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16686 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16687 peer->bgp->default_connect_retry);
16688
16689 /* timers delayopen */
16690 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16691 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16692 peer->delayopen);
16693 /* Save config even though flag is not set if default values have been
16694 * changed
16695 */
16696 else if (!peer_group_active(peer) && !peer->delayopen
16697 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16698 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16699 peer->bgp->default_delayopen);
16700
16701 /* capability dynamic */
16702 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16703 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16704
16705 /* capability extended-nexthop */
16706 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16707 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
16708 !peer->conf_if)
16709 vty_out(vty,
16710 " no neighbor %s capability extended-nexthop\n",
16711 addr);
16712 else if (!peer->conf_if)
16713 vty_out(vty,
16714 " neighbor %s capability extended-nexthop\n",
16715 addr);
16716 }
16717
16718 /* dont-capability-negotiation */
16719 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16720 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16721
16722 /* override-capability */
16723 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16724 vty_out(vty, " neighbor %s override-capability\n", addr);
16725
16726 /* strict-capability-match */
16727 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16728 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16729
16730 /* Sender side AS path loop detection. */
16731 if (peer->as_path_loop_detection)
16732 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16733 addr);
16734
16735 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16736 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16737
16738 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16739 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16740 vty_out(vty,
16741 " neighbor %s graceful-restart-helper\n", addr);
16742 } else if (CHECK_FLAG(
16743 peer->peer_gr_new_status_flag,
16744 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16745 vty_out(vty,
16746 " neighbor %s graceful-restart\n", addr);
16747 } else if (
16748 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16749 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16750 && !(CHECK_FLAG(
16751 peer->peer_gr_new_status_flag,
16752 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16753 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16754 addr);
16755 }
16756 }
16757 }
16758
16759 /* BGP peer configuration display function. */
16760 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16761 struct peer *peer, afi_t afi, safi_t safi)
16762 {
16763 struct peer *g_peer = NULL;
16764 char *addr;
16765 bool flag_scomm, flag_secomm, flag_slcomm;
16766
16767 /* Skip dynamic neighbors. */
16768 if (peer_dynamic_neighbor(peer))
16769 return;
16770
16771 if (peer->conf_if)
16772 addr = peer->conf_if;
16773 else
16774 addr = peer->host;
16775
16776 /************************************
16777 ****** Per AF to the neighbor ******
16778 ************************************/
16779 if (peer_group_active(peer)) {
16780 g_peer = peer->group->conf;
16781
16782 /* If the peer-group is active but peer is not, print a 'no
16783 * activate' */
16784 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16785 vty_out(vty, " no neighbor %s activate\n", addr);
16786 }
16787
16788 /* If the peer-group is not active but peer is, print an
16789 'activate' */
16790 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16791 vty_out(vty, " neighbor %s activate\n", addr);
16792 }
16793 } else {
16794 if (peer->afc[afi][safi]) {
16795 if (safi == SAFI_ENCAP)
16796 vty_out(vty, " neighbor %s activate\n", addr);
16797 else if (!bgp->default_af[afi][safi])
16798 vty_out(vty, " neighbor %s activate\n", addr);
16799 } else {
16800 if (bgp->default_af[afi][safi])
16801 vty_out(vty, " no neighbor %s activate\n",
16802 addr);
16803 }
16804 }
16805
16806 /* addpath TX knobs */
16807 if (peergroup_af_addpath_check(peer, afi, safi)) {
16808 switch (peer->addpath_type[afi][safi]) {
16809 case BGP_ADDPATH_ALL:
16810 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16811 addr);
16812 break;
16813 case BGP_ADDPATH_BEST_PER_AS:
16814 vty_out(vty,
16815 " neighbor %s addpath-tx-bestpath-per-AS\n",
16816 addr);
16817 break;
16818 case BGP_ADDPATH_MAX:
16819 case BGP_ADDPATH_NONE:
16820 break;
16821 }
16822 }
16823
16824 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16825 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16826
16827 /* ORF capability. */
16828 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16829 || peergroup_af_flag_check(peer, afi, safi,
16830 PEER_FLAG_ORF_PREFIX_RM)) {
16831 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16832
16833 if (peergroup_af_flag_check(peer, afi, safi,
16834 PEER_FLAG_ORF_PREFIX_SM)
16835 && peergroup_af_flag_check(peer, afi, safi,
16836 PEER_FLAG_ORF_PREFIX_RM))
16837 vty_out(vty, " both");
16838 else if (peergroup_af_flag_check(peer, afi, safi,
16839 PEER_FLAG_ORF_PREFIX_SM))
16840 vty_out(vty, " send");
16841 else
16842 vty_out(vty, " receive");
16843 vty_out(vty, "\n");
16844 }
16845
16846 /* Route reflector client. */
16847 if (peergroup_af_flag_check(peer, afi, safi,
16848 PEER_FLAG_REFLECTOR_CLIENT)) {
16849 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16850 }
16851
16852 /* next-hop-self force */
16853 if (peergroup_af_flag_check(peer, afi, safi,
16854 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16855 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16856 }
16857
16858 /* next-hop-self */
16859 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16860 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16861 }
16862
16863 /* remove-private-AS */
16864 if (peergroup_af_flag_check(peer, afi, safi,
16865 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16866 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16867 addr);
16868 }
16869
16870 else if (peergroup_af_flag_check(peer, afi, safi,
16871 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16872 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16873 addr);
16874 }
16875
16876 else if (peergroup_af_flag_check(peer, afi, safi,
16877 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16878 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16879 }
16880
16881 else if (peergroup_af_flag_check(peer, afi, safi,
16882 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16883 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16884 }
16885
16886 /* as-override */
16887 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16888 vty_out(vty, " neighbor %s as-override\n", addr);
16889 }
16890
16891 /* send-community print. */
16892 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16893 PEER_FLAG_SEND_COMMUNITY);
16894 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16895 PEER_FLAG_SEND_EXT_COMMUNITY);
16896 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16897 PEER_FLAG_SEND_LARGE_COMMUNITY);
16898
16899 if (flag_scomm && flag_secomm && flag_slcomm) {
16900 vty_out(vty, " no neighbor %s send-community all\n", addr);
16901 } else {
16902 if (flag_scomm)
16903 vty_out(vty, " no neighbor %s send-community\n", addr);
16904 if (flag_secomm)
16905 vty_out(vty,
16906 " no neighbor %s send-community extended\n",
16907 addr);
16908
16909 if (flag_slcomm)
16910 vty_out(vty, " no neighbor %s send-community large\n",
16911 addr);
16912 }
16913
16914 /* Default information */
16915 if (peergroup_af_flag_check(peer, afi, safi,
16916 PEER_FLAG_DEFAULT_ORIGINATE)) {
16917 vty_out(vty, " neighbor %s default-originate", addr);
16918
16919 if (peer->default_rmap[afi][safi].name)
16920 vty_out(vty, " route-map %s",
16921 peer->default_rmap[afi][safi].name);
16922
16923 vty_out(vty, "\n");
16924 }
16925
16926 /* Soft reconfiguration inbound. */
16927 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16928 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16929 addr);
16930 }
16931
16932 /* maximum-prefix. */
16933 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16934 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16935 peer->pmax[afi][safi]);
16936
16937 if (peer->pmax_threshold[afi][safi]
16938 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16939 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16940 if (peer_af_flag_check(peer, afi, safi,
16941 PEER_FLAG_MAX_PREFIX_WARNING))
16942 vty_out(vty, " warning-only");
16943 if (peer->pmax_restart[afi][safi])
16944 vty_out(vty, " restart %u",
16945 peer->pmax_restart[afi][safi]);
16946 if (peer_af_flag_check(peer, afi, safi,
16947 PEER_FLAG_MAX_PREFIX_FORCE))
16948 vty_out(vty, " force");
16949
16950 vty_out(vty, "\n");
16951 }
16952
16953 /* maximum-prefix-out */
16954 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16955 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16956 addr, peer->pmax_out[afi][safi]);
16957
16958 /* Route server client. */
16959 if (peergroup_af_flag_check(peer, afi, safi,
16960 PEER_FLAG_RSERVER_CLIENT)) {
16961 vty_out(vty, " neighbor %s route-server-client\n", addr);
16962 }
16963
16964 /* Nexthop-local unchanged. */
16965 if (peergroup_af_flag_check(peer, afi, safi,
16966 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16967 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16968 }
16969
16970 /* allowas-in <1-10> */
16971 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16972 if (peer_af_flag_check(peer, afi, safi,
16973 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16974 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16975 } else if (peer->allowas_in[afi][safi] == 3) {
16976 vty_out(vty, " neighbor %s allowas-in\n", addr);
16977 } else {
16978 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16979 peer->allowas_in[afi][safi]);
16980 }
16981 }
16982
16983 /* weight */
16984 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16985 vty_out(vty, " neighbor %s weight %lu\n", addr,
16986 peer->weight[afi][safi]);
16987
16988 /* Filter. */
16989 bgp_config_write_filter(vty, peer, afi, safi);
16990
16991 /* atribute-unchanged. */
16992 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16993 || (safi != SAFI_EVPN
16994 && peer_af_flag_check(peer, afi, safi,
16995 PEER_FLAG_NEXTHOP_UNCHANGED))
16996 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16997
16998 if (!peer_group_active(peer)
16999 || peergroup_af_flag_check(peer, afi, safi,
17000 PEER_FLAG_AS_PATH_UNCHANGED)
17001 || peergroup_af_flag_check(peer, afi, safi,
17002 PEER_FLAG_NEXTHOP_UNCHANGED)
17003 || peergroup_af_flag_check(peer, afi, safi,
17004 PEER_FLAG_MED_UNCHANGED)) {
17005
17006 vty_out(vty,
17007 " neighbor %s attribute-unchanged%s%s%s\n",
17008 addr,
17009 peer_af_flag_check(peer, afi, safi,
17010 PEER_FLAG_AS_PATH_UNCHANGED)
17011 ? " as-path"
17012 : "",
17013 peer_af_flag_check(peer, afi, safi,
17014 PEER_FLAG_NEXTHOP_UNCHANGED)
17015 ? " next-hop"
17016 : "",
17017 peer_af_flag_check(peer, afi, safi,
17018 PEER_FLAG_MED_UNCHANGED)
17019 ? " med"
17020 : "");
17021 }
17022 }
17023 }
17024
17025 /* Address family based peer configuration display. */
17026 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17027 safi_t safi)
17028 {
17029 struct peer *peer;
17030 struct peer_group *group;
17031 struct listnode *node, *nnode;
17032
17033
17034 vty_frame(vty, " !\n address-family ");
17035 if (afi == AFI_IP) {
17036 if (safi == SAFI_UNICAST)
17037 vty_frame(vty, "ipv4 unicast");
17038 else if (safi == SAFI_LABELED_UNICAST)
17039 vty_frame(vty, "ipv4 labeled-unicast");
17040 else if (safi == SAFI_MULTICAST)
17041 vty_frame(vty, "ipv4 multicast");
17042 else if (safi == SAFI_MPLS_VPN)
17043 vty_frame(vty, "ipv4 vpn");
17044 else if (safi == SAFI_ENCAP)
17045 vty_frame(vty, "ipv4 encap");
17046 else if (safi == SAFI_FLOWSPEC)
17047 vty_frame(vty, "ipv4 flowspec");
17048 } else if (afi == AFI_IP6) {
17049 if (safi == SAFI_UNICAST)
17050 vty_frame(vty, "ipv6 unicast");
17051 else if (safi == SAFI_LABELED_UNICAST)
17052 vty_frame(vty, "ipv6 labeled-unicast");
17053 else if (safi == SAFI_MULTICAST)
17054 vty_frame(vty, "ipv6 multicast");
17055 else if (safi == SAFI_MPLS_VPN)
17056 vty_frame(vty, "ipv6 vpn");
17057 else if (safi == SAFI_ENCAP)
17058 vty_frame(vty, "ipv6 encap");
17059 else if (safi == SAFI_FLOWSPEC)
17060 vty_frame(vty, "ipv6 flowspec");
17061 } else if (afi == AFI_L2VPN) {
17062 if (safi == SAFI_EVPN)
17063 vty_frame(vty, "l2vpn evpn");
17064 }
17065 vty_frame(vty, "\n");
17066
17067 bgp_config_write_distance(vty, bgp, afi, safi);
17068
17069 bgp_config_write_network(vty, bgp, afi, safi);
17070
17071 bgp_config_write_redistribute(vty, bgp, afi, safi);
17072
17073 /* BGP flag dampening. */
17074 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17075 bgp_config_write_damp(vty, afi, safi);
17076
17077 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17078 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17079
17080 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17081 /* Do not display doppelganger peers */
17082 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17083 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17084 }
17085
17086 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17087 bgp_config_write_table_map(vty, bgp, afi, safi);
17088
17089 if (safi == SAFI_EVPN)
17090 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17091
17092 if (safi == SAFI_FLOWSPEC)
17093 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17094
17095 if (safi == SAFI_UNICAST) {
17096 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17097 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17098 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17099
17100 vty_out(vty, " export vpn\n");
17101 }
17102 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17103 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17104
17105 vty_out(vty, " import vpn\n");
17106 }
17107 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17108 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17109 char *name;
17110
17111 for (ALL_LIST_ELEMENTS_RO(
17112 bgp->vpn_policy[afi].import_vrf, node,
17113 name))
17114 vty_out(vty, " import vrf %s\n", name);
17115 }
17116 }
17117
17118 vty_endframe(vty, " exit-address-family\n");
17119 }
17120
17121 int bgp_config_write(struct vty *vty)
17122 {
17123 struct bgp *bgp;
17124 struct peer_group *group;
17125 struct peer *peer;
17126 struct listnode *node, *nnode;
17127 struct listnode *mnode, *mnnode;
17128 afi_t afi;
17129 safi_t safi;
17130
17131 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17132 vty_out(vty, "bgp route-map delay-timer %u\n",
17133 bm->rmap_update_timer);
17134
17135 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17136 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17137 if (bm->v_update_delay != bm->v_establish_wait)
17138 vty_out(vty, " %d", bm->v_establish_wait);
17139 vty_out(vty, "\n");
17140 }
17141
17142 if (bm->wait_for_fib)
17143 vty_out(vty, "bgp suppress-fib-pending\n");
17144
17145 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17146 vty_out(vty, "bgp graceful-shutdown\n");
17147
17148 /* No-RIB (Zebra) option flag configuration */
17149 if (bgp_option_check(BGP_OPT_NO_FIB))
17150 vty_out(vty, "bgp no-rib\n");
17151
17152 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17153 vty_out(vty, "bgp send-extra-data zebra\n");
17154
17155 /* BGP session DSCP value */
17156 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17157 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17158
17159 /* BGP configuration. */
17160 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17161
17162 /* skip all auto created vrf as they dont have user config */
17163 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17164 continue;
17165
17166 /* Router bgp ASN */
17167 vty_out(vty, "router bgp %u", bgp->as);
17168
17169 if (bgp->name)
17170 vty_out(vty, " %s %s",
17171 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17172 ? "view" : "vrf", bgp->name);
17173 vty_out(vty, "\n");
17174
17175 /* BGP fast-external-failover. */
17176 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17177 vty_out(vty, " no bgp fast-external-failover\n");
17178
17179 /* BGP router ID. */
17180 if (bgp->router_id_static.s_addr != INADDR_ANY)
17181 vty_out(vty, " bgp router-id %pI4\n",
17182 &bgp->router_id_static);
17183
17184 /* Suppress fib pending */
17185 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17186 vty_out(vty, " bgp suppress-fib-pending\n");
17187
17188 /* BGP log-neighbor-changes. */
17189 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17190 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17191 vty_out(vty, " %sbgp log-neighbor-changes\n",
17192 CHECK_FLAG(bgp->flags,
17193 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17194 ? ""
17195 : "no ");
17196
17197 /* BGP configuration. */
17198 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17199 vty_out(vty, " bgp always-compare-med\n");
17200
17201 /* RFC8212 default eBGP policy. */
17202 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17203 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17204 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17205 CHECK_FLAG(bgp->flags,
17206 BGP_FLAG_EBGP_REQUIRES_POLICY)
17207 ? ""
17208 : "no ");
17209
17210 /* draft-ietf-idr-deprecate-as-set-confed-set */
17211 if (bgp->reject_as_sets)
17212 vty_out(vty, " bgp reject-as-sets\n");
17213
17214 /* Suppress duplicate updates if the route actually not changed
17215 */
17216 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17217 != SAVE_BGP_SUPPRESS_DUPLICATES)
17218 vty_out(vty, " %sbgp suppress-duplicates\n",
17219 CHECK_FLAG(bgp->flags,
17220 BGP_FLAG_SUPPRESS_DUPLICATES)
17221 ? ""
17222 : "no ");
17223
17224 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17225 */
17226 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17227 SAVE_BGP_HARD_ADMIN_RESET)
17228 vty_out(vty, " %sbgp hard-administrative-reset\n",
17229 CHECK_FLAG(bgp->flags,
17230 BGP_FLAG_HARD_ADMIN_RESET)
17231 ? ""
17232 : "no ");
17233
17234 /* BGP default <afi>-<safi> */
17235 FOREACH_AFI_SAFI (afi, safi) {
17236 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17237 if (!bgp->default_af[afi][safi])
17238 vty_out(vty, " no bgp default %s\n",
17239 get_bgp_default_af_flag(afi,
17240 safi));
17241 } else if (bgp->default_af[afi][safi])
17242 vty_out(vty, " bgp default %s\n",
17243 get_bgp_default_af_flag(afi, safi));
17244 }
17245
17246 /* BGP default local-preference. */
17247 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17248 vty_out(vty, " bgp default local-preference %u\n",
17249 bgp->default_local_pref);
17250
17251 /* BGP default show-hostname */
17252 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17253 != SAVE_BGP_SHOW_HOSTNAME)
17254 vty_out(vty, " %sbgp default show-hostname\n",
17255 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17256 ? ""
17257 : "no ");
17258
17259 /* BGP default show-nexthop-hostname */
17260 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17261 != SAVE_BGP_SHOW_HOSTNAME)
17262 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17263 CHECK_FLAG(bgp->flags,
17264 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17265 ? ""
17266 : "no ");
17267
17268 /* BGP default subgroup-pkt-queue-max. */
17269 if (bgp->default_subgroup_pkt_queue_max
17270 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17271 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17272 bgp->default_subgroup_pkt_queue_max);
17273
17274 /* BGP client-to-client reflection. */
17275 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17276 vty_out(vty, " no bgp client-to-client reflection\n");
17277
17278 /* BGP cluster ID. */
17279 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17280 vty_out(vty, " bgp cluster-id %pI4\n",
17281 &bgp->cluster_id);
17282
17283 /* Disable ebgp connected nexthop check */
17284 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17285 vty_out(vty,
17286 " bgp disable-ebgp-connected-route-check\n");
17287
17288 /* Confederation identifier*/
17289 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17290 vty_out(vty, " bgp confederation identifier %u\n",
17291 bgp->confed_id);
17292
17293 /* Confederation peer */
17294 if (bgp->confed_peers_cnt > 0) {
17295 int i;
17296
17297 vty_out(vty, " bgp confederation peers");
17298
17299 for (i = 0; i < bgp->confed_peers_cnt; i++)
17300 vty_out(vty, " %u", bgp->confed_peers[i]);
17301
17302 vty_out(vty, "\n");
17303 }
17304
17305 /* BGP deterministic-med. */
17306 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17307 != SAVE_BGP_DETERMINISTIC_MED)
17308 vty_out(vty, " %sbgp deterministic-med\n",
17309 CHECK_FLAG(bgp->flags,
17310 BGP_FLAG_DETERMINISTIC_MED)
17311 ? ""
17312 : "no ");
17313
17314 /* BGP update-delay. */
17315 bgp_config_write_update_delay(vty, bgp);
17316
17317 if (bgp->v_maxmed_onstartup
17318 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17319 vty_out(vty, " bgp max-med on-startup %u",
17320 bgp->v_maxmed_onstartup);
17321 if (bgp->maxmed_onstartup_value
17322 != BGP_MAXMED_VALUE_DEFAULT)
17323 vty_out(vty, " %u",
17324 bgp->maxmed_onstartup_value);
17325 vty_out(vty, "\n");
17326 }
17327 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17328 vty_out(vty, " bgp max-med administrative");
17329 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17330 vty_out(vty, " %u", bgp->maxmed_admin_value);
17331 vty_out(vty, "\n");
17332 }
17333
17334 /* write quanta */
17335 bgp_config_write_wpkt_quanta(vty, bgp);
17336 /* read quanta */
17337 bgp_config_write_rpkt_quanta(vty, bgp);
17338
17339 /* coalesce time */
17340 bgp_config_write_coalesce_time(vty, bgp);
17341
17342 /* BGP per-instance graceful-shutdown */
17343 /* BGP-wide settings and per-instance settings are mutually
17344 * exclusive.
17345 */
17346 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17347 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17348 vty_out(vty, " bgp graceful-shutdown\n");
17349
17350 /* Long-lived Graceful Restart */
17351 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17352 vty_out(vty,
17353 " bgp long-lived-graceful-restart stale-time %u\n",
17354 bgp->llgr_stale_time);
17355
17356 /* BGP graceful-restart. */
17357 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17358 vty_out(vty,
17359 " bgp graceful-restart stalepath-time %u\n",
17360 bgp->stalepath_time);
17361
17362 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17363 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17364 bgp->restart_time);
17365
17366 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17367 SAVE_BGP_GRACEFUL_NOTIFICATION)
17368 vty_out(vty, " %sbgp graceful-restart notification\n",
17369 CHECK_FLAG(bgp->flags,
17370 BGP_FLAG_GRACEFUL_NOTIFICATION)
17371 ? ""
17372 : "no ");
17373
17374 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17375 vty_out(vty,
17376 " bgp graceful-restart select-defer-time %u\n",
17377 bgp->select_defer_time);
17378
17379 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17380 vty_out(vty, " bgp graceful-restart\n");
17381
17382 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17383 vty_out(vty, " bgp graceful-restart-disable\n");
17384
17385 /* BGP graceful-restart Preserve State F bit. */
17386 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17387 vty_out(vty,
17388 " bgp graceful-restart preserve-fw-state\n");
17389
17390 /* Stale timer for RIB */
17391 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17392 vty_out(vty,
17393 " bgp graceful-restart rib-stale-time %u\n",
17394 bgp->rib_stale_time);
17395
17396 /* BGP bestpath method. */
17397 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17398 vty_out(vty, " bgp bestpath as-path ignore\n");
17399 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17400 vty_out(vty, " bgp bestpath as-path confed\n");
17401
17402 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17403 if (CHECK_FLAG(bgp->flags,
17404 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17405 vty_out(vty,
17406 " bgp bestpath as-path multipath-relax as-set\n");
17407 } else {
17408 vty_out(vty,
17409 " bgp bestpath as-path multipath-relax\n");
17410 }
17411 }
17412
17413 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17414 vty_out(vty,
17415 " bgp route-reflector allow-outbound-policy\n");
17416 }
17417 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17418 vty_out(vty, " bgp bestpath compare-routerid\n");
17419 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17420 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17421 vty_out(vty, " bgp bestpath med");
17422 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17423 vty_out(vty, " confed");
17424 if (CHECK_FLAG(bgp->flags,
17425 BGP_FLAG_MED_MISSING_AS_WORST))
17426 vty_out(vty, " missing-as-worst");
17427 vty_out(vty, "\n");
17428 }
17429
17430 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17431 vty_out(vty,
17432 " bgp bestpath peer-type multipath-relax\n");
17433
17434 /* Link bandwidth handling. */
17435 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17436 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17437 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17438 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17439 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17440 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17441
17442 /* BGP network import check. */
17443 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17444 != SAVE_BGP_IMPORT_CHECK)
17445 vty_out(vty, " %sbgp network import-check\n",
17446 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17447 ? ""
17448 : "no ");
17449
17450 /* BGP timers configuration. */
17451 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17452 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17453 vty_out(vty, " timers bgp %u %u\n",
17454 bgp->default_keepalive, bgp->default_holdtime);
17455
17456 /* BGP minimum holdtime configuration. */
17457 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17458 && bgp->default_min_holdtime != 0)
17459 vty_out(vty, " bgp minimum-holdtime %u\n",
17460 bgp->default_min_holdtime);
17461
17462 /* Conditional advertisement timer configuration */
17463 if (bgp->condition_check_period
17464 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17465 vty_out(vty,
17466 " bgp conditional-advertisement timer %u\n",
17467 bgp->condition_check_period);
17468
17469 /* peer-group */
17470 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17471 bgp_config_write_peer_global(vty, bgp, group->conf);
17472 }
17473
17474 /* Normal neighbor configuration. */
17475 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17476 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17477 bgp_config_write_peer_global(vty, bgp, peer);
17478 }
17479
17480 /* listen range and limit for dynamic BGP neighbors */
17481 bgp_config_write_listen(vty, bgp);
17482
17483 /*
17484 * BGP default autoshutdown neighbors
17485 *
17486 * This must be placed after any peer and peer-group
17487 * configuration, to avoid setting all peers to shutdown after
17488 * a daemon restart, which is undesired behavior. (see #2286)
17489 */
17490 if (bgp->autoshutdown)
17491 vty_out(vty, " bgp default shutdown\n");
17492
17493 /* BGP instance administrative shutdown */
17494 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17495 vty_out(vty, " bgp shutdown\n");
17496
17497 if (bgp->fast_convergence)
17498 vty_out(vty, " bgp fast-convergence\n");
17499
17500 if (bgp->srv6_enabled) {
17501 vty_frame(vty, " !\n segment-routing srv6\n");
17502 if (strlen(bgp->srv6_locator_name))
17503 vty_out(vty, " locator %s\n",
17504 bgp->srv6_locator_name);
17505 vty_endframe(vty, " exit\n");
17506 }
17507
17508
17509 /* IPv4 unicast configuration. */
17510 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17511
17512 /* IPv4 multicast configuration. */
17513 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17514
17515 /* IPv4 labeled-unicast configuration. */
17516 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17517
17518 /* IPv4 VPN configuration. */
17519 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17520
17521 /* ENCAPv4 configuration. */
17522 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17523
17524 /* FLOWSPEC v4 configuration. */
17525 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17526
17527 /* IPv6 unicast configuration. */
17528 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17529
17530 /* IPv6 multicast configuration. */
17531 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17532
17533 /* IPv6 labeled-unicast configuration. */
17534 bgp_config_write_family(vty, bgp, AFI_IP6,
17535 SAFI_LABELED_UNICAST);
17536
17537 /* IPv6 VPN configuration. */
17538 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17539
17540 /* ENCAPv6 configuration. */
17541 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17542
17543 /* FLOWSPEC v6 configuration. */
17544 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17545
17546 /* EVPN configuration. */
17547 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17548
17549 hook_call(bgp_inst_config_write, bgp, vty);
17550
17551 #ifdef ENABLE_BGP_VNC
17552 bgp_rfapi_cfg_write(vty, bgp);
17553 #endif
17554
17555 vty_out(vty, "exit\n");
17556 vty_out(vty, "!\n");
17557 }
17558 return 0;
17559 }
17560
17561
17562 /* BGP node structure. */
17563 static struct cmd_node bgp_node = {
17564 .name = "bgp",
17565 .node = BGP_NODE,
17566 .parent_node = CONFIG_NODE,
17567 .prompt = "%s(config-router)# ",
17568 .config_write = bgp_config_write,
17569 };
17570
17571 static struct cmd_node bgp_ipv4_unicast_node = {
17572 .name = "bgp ipv4 unicast",
17573 .node = BGP_IPV4_NODE,
17574 .parent_node = BGP_NODE,
17575 .prompt = "%s(config-router-af)# ",
17576 .no_xpath = true,
17577 };
17578
17579 static struct cmd_node bgp_ipv4_multicast_node = {
17580 .name = "bgp ipv4 multicast",
17581 .node = BGP_IPV4M_NODE,
17582 .parent_node = BGP_NODE,
17583 .prompt = "%s(config-router-af)# ",
17584 .no_xpath = true,
17585 };
17586
17587 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17588 .name = "bgp ipv4 labeled unicast",
17589 .node = BGP_IPV4L_NODE,
17590 .parent_node = BGP_NODE,
17591 .prompt = "%s(config-router-af)# ",
17592 .no_xpath = true,
17593 };
17594
17595 static struct cmd_node bgp_ipv6_unicast_node = {
17596 .name = "bgp ipv6 unicast",
17597 .node = BGP_IPV6_NODE,
17598 .parent_node = BGP_NODE,
17599 .prompt = "%s(config-router-af)# ",
17600 .no_xpath = true,
17601 };
17602
17603 static struct cmd_node bgp_ipv6_multicast_node = {
17604 .name = "bgp ipv6 multicast",
17605 .node = BGP_IPV6M_NODE,
17606 .parent_node = BGP_NODE,
17607 .prompt = "%s(config-router-af)# ",
17608 .no_xpath = true,
17609 };
17610
17611 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17612 .name = "bgp ipv6 labeled unicast",
17613 .node = BGP_IPV6L_NODE,
17614 .parent_node = BGP_NODE,
17615 .prompt = "%s(config-router-af)# ",
17616 .no_xpath = true,
17617 };
17618
17619 static struct cmd_node bgp_vpnv4_node = {
17620 .name = "bgp vpnv4",
17621 .node = BGP_VPNV4_NODE,
17622 .parent_node = BGP_NODE,
17623 .prompt = "%s(config-router-af)# ",
17624 .no_xpath = true,
17625 };
17626
17627 static struct cmd_node bgp_vpnv6_node = {
17628 .name = "bgp vpnv6",
17629 .node = BGP_VPNV6_NODE,
17630 .parent_node = BGP_NODE,
17631 .prompt = "%s(config-router-af-vpnv6)# ",
17632 .no_xpath = true,
17633 };
17634
17635 static struct cmd_node bgp_evpn_node = {
17636 .name = "bgp evpn",
17637 .node = BGP_EVPN_NODE,
17638 .parent_node = BGP_NODE,
17639 .prompt = "%s(config-router-evpn)# ",
17640 .no_xpath = true,
17641 };
17642
17643 static struct cmd_node bgp_evpn_vni_node = {
17644 .name = "bgp evpn vni",
17645 .node = BGP_EVPN_VNI_NODE,
17646 .parent_node = BGP_EVPN_NODE,
17647 .prompt = "%s(config-router-af-vni)# ",
17648 };
17649
17650 static struct cmd_node bgp_flowspecv4_node = {
17651 .name = "bgp ipv4 flowspec",
17652 .node = BGP_FLOWSPECV4_NODE,
17653 .parent_node = BGP_NODE,
17654 .prompt = "%s(config-router-af)# ",
17655 .no_xpath = true,
17656 };
17657
17658 static struct cmd_node bgp_flowspecv6_node = {
17659 .name = "bgp ipv6 flowspec",
17660 .node = BGP_FLOWSPECV6_NODE,
17661 .parent_node = BGP_NODE,
17662 .prompt = "%s(config-router-af-vpnv6)# ",
17663 .no_xpath = true,
17664 };
17665
17666 static struct cmd_node bgp_srv6_node = {
17667 .name = "bgp srv6",
17668 .node = BGP_SRV6_NODE,
17669 .parent_node = BGP_NODE,
17670 .prompt = "%s(config-router-srv6)# ",
17671 };
17672
17673 static void community_list_vty(void);
17674
17675 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17676 {
17677 struct bgp *bgp;
17678 struct peer_group *group;
17679 struct listnode *lnbgp, *lnpeer;
17680
17681 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17682 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17683 vector_set(comps,
17684 XSTRDUP(MTYPE_COMPLETION, group->name));
17685 }
17686 }
17687
17688 static void bgp_ac_peer(vector comps, struct cmd_token *token)
17689 {
17690 struct bgp *bgp;
17691 struct peer *peer;
17692 struct listnode *lnbgp, *lnpeer;
17693
17694 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17695 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17696 /* only provide suggestions on the appropriate input
17697 * token type,
17698 * they'll otherwise show up multiple times */
17699 enum cmd_token_type match_type;
17700 char *name = peer->host;
17701
17702 if (peer->conf_if) {
17703 match_type = VARIABLE_TKN;
17704 name = peer->conf_if;
17705 } else if (strchr(peer->host, ':'))
17706 match_type = IPV6_TKN;
17707 else
17708 match_type = IPV4_TKN;
17709
17710 if (token->type != match_type)
17711 continue;
17712
17713 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17714 }
17715 }
17716 }
17717
17718 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17719 {
17720 bgp_ac_peer(comps, token);
17721
17722 if (token->type == VARIABLE_TKN)
17723 bgp_ac_peergroup(comps, token);
17724 }
17725
17726 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17727 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17728 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17729 {.varname = "peer", .completions = bgp_ac_neighbor},
17730 {.completions = NULL}};
17731
17732 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17733 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17734 {.completions = NULL} };
17735
17736 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
17737
17738 static struct thread *t_bgp_cfg;
17739
17740 bool bgp_config_inprocess(void)
17741 {
17742 return thread_is_scheduled(t_bgp_cfg);
17743 }
17744
17745 static void bgp_config_finish(struct thread *t)
17746 {
17747 struct listnode *node;
17748 struct bgp *bgp;
17749
17750 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
17751 hook_call(bgp_config_end, bgp);
17752 }
17753
17754 static void bgp_config_start(void)
17755 {
17756 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
17757 THREAD_OFF(t_bgp_cfg);
17758 thread_add_timer(bm->master, bgp_config_finish, NULL,
17759 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
17760 }
17761
17762 /* When we receive a hook the configuration is read,
17763 * we start a timer to make sure we postpone sending
17764 * EoR before route-maps are processed.
17765 * This is especially valid if using `bgp route-map delay-timer`.
17766 */
17767 static void bgp_config_end(void)
17768 {
17769 #define BGP_POST_CONFIG_DELAY_SECONDS 1
17770 uint32_t bgp_post_config_delay =
17771 thread_is_scheduled(bm->t_rmap_update)
17772 ? thread_timer_remain_second(bm->t_rmap_update)
17773 : BGP_POST_CONFIG_DELAY_SECONDS;
17774
17775 /* If BGP config processing thread isn't running, then
17776 * we can return and rely it's properly handled.
17777 */
17778 if (!bgp_config_inprocess())
17779 return;
17780
17781 THREAD_OFF(t_bgp_cfg);
17782
17783 /* Start a new timer to make sure we don't send EoR
17784 * before route-maps are processed.
17785 */
17786 thread_add_timer(bm->master, bgp_config_finish, NULL,
17787 bgp_post_config_delay, &t_bgp_cfg);
17788 }
17789
17790 void bgp_vty_init(void)
17791 {
17792 cmd_variable_handler_register(bgp_var_neighbor);
17793 cmd_variable_handler_register(bgp_var_peergroup);
17794
17795 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
17796
17797 /* Install bgp top node. */
17798 install_node(&bgp_node);
17799 install_node(&bgp_ipv4_unicast_node);
17800 install_node(&bgp_ipv4_multicast_node);
17801 install_node(&bgp_ipv4_labeled_unicast_node);
17802 install_node(&bgp_ipv6_unicast_node);
17803 install_node(&bgp_ipv6_multicast_node);
17804 install_node(&bgp_ipv6_labeled_unicast_node);
17805 install_node(&bgp_vpnv4_node);
17806 install_node(&bgp_vpnv6_node);
17807 install_node(&bgp_evpn_node);
17808 install_node(&bgp_evpn_vni_node);
17809 install_node(&bgp_flowspecv4_node);
17810 install_node(&bgp_flowspecv6_node);
17811 install_node(&bgp_srv6_node);
17812
17813 /* Install default VTY commands to new nodes. */
17814 install_default(BGP_NODE);
17815 install_default(BGP_IPV4_NODE);
17816 install_default(BGP_IPV4M_NODE);
17817 install_default(BGP_IPV4L_NODE);
17818 install_default(BGP_IPV6_NODE);
17819 install_default(BGP_IPV6M_NODE);
17820 install_default(BGP_IPV6L_NODE);
17821 install_default(BGP_VPNV4_NODE);
17822 install_default(BGP_VPNV6_NODE);
17823 install_default(BGP_FLOWSPECV4_NODE);
17824 install_default(BGP_FLOWSPECV6_NODE);
17825 install_default(BGP_EVPN_NODE);
17826 install_default(BGP_EVPN_VNI_NODE);
17827 install_default(BGP_SRV6_NODE);
17828
17829 /* "bgp local-mac" hidden commands. */
17830 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17831 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17832
17833 /* "bgp suppress-fib-pending" global */
17834 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17835
17836 /* bgp route-map delay-timer commands. */
17837 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17838 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17839
17840 /* bgp fast-convergence command */
17841 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17842 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17843
17844 /* global bgp update-delay command */
17845 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17846 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17847
17848 /* global bgp graceful-shutdown command */
17849 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17850 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17851
17852 /* Dummy commands (Currently not supported) */
17853 install_element(BGP_NODE, &no_synchronization_cmd);
17854 install_element(BGP_NODE, &no_auto_summary_cmd);
17855
17856 /* "router bgp" commands. */
17857 install_element(CONFIG_NODE, &router_bgp_cmd);
17858
17859 /* "no router bgp" commands. */
17860 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17861
17862 /* "bgp session-dscp command */
17863 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
17864 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
17865
17866 /* "bgp router-id" commands. */
17867 install_element(BGP_NODE, &bgp_router_id_cmd);
17868 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17869
17870 /* "bgp suppress-fib-pending" command */
17871 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17872
17873 /* "bgp cluster-id" commands. */
17874 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17875 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17876
17877 /* "bgp no-rib" commands. */
17878 install_element(CONFIG_NODE, &bgp_norib_cmd);
17879 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17880
17881 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17882
17883 /* "bgp confederation" commands. */
17884 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17885 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17886
17887 /* "bgp confederation peers" commands. */
17888 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17889 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17890
17891 /* bgp max-med command */
17892 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17893 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17894 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17895 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17896 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17897
17898 /* bgp disable-ebgp-connected-nh-check */
17899 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17900 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17901
17902 /* bgp update-delay command */
17903 install_element(BGP_NODE, &bgp_update_delay_cmd);
17904 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17905
17906 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17907 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17908
17909 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17910 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17911
17912 /* "maximum-paths" commands. */
17913 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17914 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17915 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17916 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17917 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17918 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17919 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17920 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17921 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17922 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17923 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17924 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17925 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17926 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17927 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17928
17929 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17930 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17931 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17932 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17933 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17934 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17935 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17936 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17937 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17938 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17939
17940 /* "timers bgp" commands. */
17941 install_element(BGP_NODE, &bgp_timers_cmd);
17942 install_element(BGP_NODE, &no_bgp_timers_cmd);
17943
17944 /* "minimum-holdtime" commands. */
17945 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17946 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17947
17948 /* route-map delay-timer commands - per instance for backwards compat.
17949 */
17950 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17951 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17952
17953 /* "bgp client-to-client reflection" commands */
17954 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17955 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17956
17957 /* "bgp always-compare-med" commands */
17958 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17959 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17960
17961 /* bgp ebgp-requires-policy */
17962 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17963 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17964
17965 /* bgp suppress-duplicates */
17966 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17967 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17968
17969 /* bgp reject-as-sets */
17970 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17971 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17972
17973 /* "bgp deterministic-med" commands */
17974 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17975 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17976
17977 /* "bgp graceful-restart" command */
17978 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17979 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17980
17981 /* "bgp graceful-restart-disable" command */
17982 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17983 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17984
17985 /* "neighbor a:b:c:d graceful-restart" command */
17986 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17987 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17988
17989 /* "neighbor a:b:c:d graceful-restart-disable" command */
17990 install_element(BGP_NODE,
17991 &bgp_neighbor_graceful_restart_disable_set_cmd);
17992 install_element(BGP_NODE,
17993 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17994
17995 /* "neighbor a:b:c:d graceful-restart-helper" command */
17996 install_element(BGP_NODE,
17997 &bgp_neighbor_graceful_restart_helper_set_cmd);
17998 install_element(BGP_NODE,
17999 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18000
18001 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18002 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18003 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18004 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18005 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18006 install_element(BGP_NODE,
18007 &no_bgp_graceful_restart_select_defer_time_cmd);
18008 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18009 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18010 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18011
18012 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18013 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18014 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18015 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18016
18017 /* "bgp graceful-shutdown" commands */
18018 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18019 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18020
18021 /* "bgp hard-administrative-reset" commands */
18022 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18023
18024 /* "bgp long-lived-graceful-restart" commands */
18025 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18026 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18027
18028 /* "bgp fast-external-failover" commands */
18029 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18030 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18031
18032 /* "bgp bestpath compare-routerid" commands */
18033 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18034 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18035
18036 /* "bgp bestpath as-path ignore" commands */
18037 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18038 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18039
18040 /* "bgp bestpath as-path confed" commands */
18041 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18042 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18043
18044 /* "bgp bestpath as-path multipath-relax" commands */
18045 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18046 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18047
18048 /* "bgp bestpath peer-type multipath-relax" commands */
18049 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18050 install_element(BGP_NODE,
18051 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18052
18053 /* "bgp log-neighbor-changes" commands */
18054 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18055 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18056
18057 /* "bgp bestpath med" commands */
18058 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18059 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18060
18061 /* "bgp bestpath bandwidth" commands */
18062 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18063 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18064
18065 /* "no bgp default <afi>-<safi>" commands. */
18066 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18067
18068 /* "bgp network import-check" commands. */
18069 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18070 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18071 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18072
18073 /* "bgp default local-preference" commands. */
18074 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18075 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18076
18077 /* bgp default show-hostname */
18078 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18079 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18080
18081 /* bgp default show-nexthop-hostname */
18082 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18083 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18084
18085 /* "bgp default subgroup-pkt-queue-max" commands. */
18086 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18087 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18088
18089 /* bgp ibgp-allow-policy-mods command */
18090 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18091 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18092
18093 /* "bgp listen limit" commands. */
18094 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18095 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18096
18097 /* "bgp listen range" commands. */
18098 install_element(BGP_NODE, &bgp_listen_range_cmd);
18099 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18100
18101 /* "bgp default shutdown" command */
18102 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18103
18104 /* "bgp shutdown" commands */
18105 install_element(BGP_NODE, &bgp_shutdown_cmd);
18106 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18107 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18108 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18109
18110 /* "neighbor remote-as" commands. */
18111 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18112 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18113 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18114 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18115 install_element(BGP_NODE,
18116 &neighbor_interface_v6only_config_remote_as_cmd);
18117 install_element(BGP_NODE, &no_neighbor_cmd);
18118 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18119
18120 /* "neighbor peer-group" commands. */
18121 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18122 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18123 install_element(BGP_NODE,
18124 &no_neighbor_interface_peer_group_remote_as_cmd);
18125
18126 /* "neighbor local-as" commands. */
18127 install_element(BGP_NODE, &neighbor_local_as_cmd);
18128 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18129 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18130 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18131
18132 /* "neighbor solo" commands. */
18133 install_element(BGP_NODE, &neighbor_solo_cmd);
18134 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18135
18136 /* "neighbor password" commands. */
18137 install_element(BGP_NODE, &neighbor_password_cmd);
18138 install_element(BGP_NODE, &no_neighbor_password_cmd);
18139
18140 /* "neighbor activate" commands. */
18141 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18142 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18143 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18144 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18145 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18146 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18147 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18148 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18149 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18150 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18151 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18152 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18153
18154 /* "no neighbor activate" commands. */
18155 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18156 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18157 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18158 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18159 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18160 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18161 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18162 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18163 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18164 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18165 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18166 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18167
18168 /* "neighbor peer-group" set commands. */
18169 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18170 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18171 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18172 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18173 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18174 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18175 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18176 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18177 install_element(BGP_FLOWSPECV4_NODE,
18178 &neighbor_set_peer_group_hidden_cmd);
18179 install_element(BGP_FLOWSPECV6_NODE,
18180 &neighbor_set_peer_group_hidden_cmd);
18181
18182 /* "no neighbor peer-group unset" commands. */
18183 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18184 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18185 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18186 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18187 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18188 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18189 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18190 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18191 install_element(BGP_FLOWSPECV4_NODE,
18192 &no_neighbor_set_peer_group_hidden_cmd);
18193 install_element(BGP_FLOWSPECV6_NODE,
18194 &no_neighbor_set_peer_group_hidden_cmd);
18195
18196 /* "neighbor softreconfiguration inbound" commands.*/
18197 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18198 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18199 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18200 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18201 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18202 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18203 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18204 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18205 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18206 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18207 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18208 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18209 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18210 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18211 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18212 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18213 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18214 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18215 install_element(BGP_FLOWSPECV4_NODE,
18216 &neighbor_soft_reconfiguration_cmd);
18217 install_element(BGP_FLOWSPECV4_NODE,
18218 &no_neighbor_soft_reconfiguration_cmd);
18219 install_element(BGP_FLOWSPECV6_NODE,
18220 &neighbor_soft_reconfiguration_cmd);
18221 install_element(BGP_FLOWSPECV6_NODE,
18222 &no_neighbor_soft_reconfiguration_cmd);
18223 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18224 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18225
18226 /* "neighbor attribute-unchanged" commands. */
18227 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18228 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18229 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18230 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18231 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18232 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18233 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18234 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18235 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18236 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18237 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18238 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18239 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18240 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18241 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18242 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18243 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18244 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18245
18246 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18247 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18248
18249 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18250 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18251 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18252 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18253
18254 /* "nexthop-local unchanged" commands */
18255 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18256 install_element(BGP_IPV6_NODE,
18257 &no_neighbor_nexthop_local_unchanged_cmd);
18258
18259 /* "neighbor next-hop-self" commands. */
18260 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18261 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18262 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18263 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18264 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18265 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18266 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18267 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18268 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18269 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18270 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18271 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18272 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18273 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18274 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18275 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18276 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18277 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18278 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18279 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18280
18281 /* "neighbor next-hop-self force" commands. */
18282 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18283 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18284 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18285 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18286 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18287 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18288 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18289 install_element(BGP_IPV4_NODE,
18290 &no_neighbor_nexthop_self_all_hidden_cmd);
18291 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18292 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18293 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18294 install_element(BGP_IPV4M_NODE,
18295 &no_neighbor_nexthop_self_all_hidden_cmd);
18296 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18297 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18298 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18299 install_element(BGP_IPV4L_NODE,
18300 &no_neighbor_nexthop_self_all_hidden_cmd);
18301 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18302 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18303 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18304 install_element(BGP_IPV6_NODE,
18305 &no_neighbor_nexthop_self_all_hidden_cmd);
18306 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18307 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18308 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18309 install_element(BGP_IPV6M_NODE,
18310 &no_neighbor_nexthop_self_all_hidden_cmd);
18311 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18312 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18313 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18314 install_element(BGP_IPV6L_NODE,
18315 &no_neighbor_nexthop_self_all_hidden_cmd);
18316 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18317 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18318 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18319 install_element(BGP_VPNV4_NODE,
18320 &no_neighbor_nexthop_self_all_hidden_cmd);
18321 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18322 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18323 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18324 install_element(BGP_VPNV6_NODE,
18325 &no_neighbor_nexthop_self_all_hidden_cmd);
18326 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18327 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18328
18329 /* "neighbor as-override" commands. */
18330 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18331 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18332 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18333 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18334 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18335 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18336 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18337 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18338 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18339 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18340 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18341 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18342 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18343 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18344 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18345 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18346 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18347 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18348
18349 /* "neighbor remove-private-AS" commands. */
18350 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18351 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18352 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18353 install_element(BGP_NODE,
18354 &no_neighbor_remove_private_as_all_hidden_cmd);
18355 install_element(BGP_NODE,
18356 &neighbor_remove_private_as_replace_as_hidden_cmd);
18357 install_element(BGP_NODE,
18358 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18359 install_element(BGP_NODE,
18360 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18361 install_element(
18362 BGP_NODE,
18363 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18364 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18365 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18366 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18367 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18368 install_element(BGP_IPV4_NODE,
18369 &neighbor_remove_private_as_replace_as_cmd);
18370 install_element(BGP_IPV4_NODE,
18371 &no_neighbor_remove_private_as_replace_as_cmd);
18372 install_element(BGP_IPV4_NODE,
18373 &neighbor_remove_private_as_all_replace_as_cmd);
18374 install_element(BGP_IPV4_NODE,
18375 &no_neighbor_remove_private_as_all_replace_as_cmd);
18376 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18377 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18378 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18379 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18380 install_element(BGP_IPV4M_NODE,
18381 &neighbor_remove_private_as_replace_as_cmd);
18382 install_element(BGP_IPV4M_NODE,
18383 &no_neighbor_remove_private_as_replace_as_cmd);
18384 install_element(BGP_IPV4M_NODE,
18385 &neighbor_remove_private_as_all_replace_as_cmd);
18386 install_element(BGP_IPV4M_NODE,
18387 &no_neighbor_remove_private_as_all_replace_as_cmd);
18388 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18389 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18390 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18391 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18392 install_element(BGP_IPV4L_NODE,
18393 &neighbor_remove_private_as_replace_as_cmd);
18394 install_element(BGP_IPV4L_NODE,
18395 &no_neighbor_remove_private_as_replace_as_cmd);
18396 install_element(BGP_IPV4L_NODE,
18397 &neighbor_remove_private_as_all_replace_as_cmd);
18398 install_element(BGP_IPV4L_NODE,
18399 &no_neighbor_remove_private_as_all_replace_as_cmd);
18400 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18401 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18402 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18403 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18404 install_element(BGP_IPV6_NODE,
18405 &neighbor_remove_private_as_replace_as_cmd);
18406 install_element(BGP_IPV6_NODE,
18407 &no_neighbor_remove_private_as_replace_as_cmd);
18408 install_element(BGP_IPV6_NODE,
18409 &neighbor_remove_private_as_all_replace_as_cmd);
18410 install_element(BGP_IPV6_NODE,
18411 &no_neighbor_remove_private_as_all_replace_as_cmd);
18412 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18413 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18414 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18415 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18416 install_element(BGP_IPV6M_NODE,
18417 &neighbor_remove_private_as_replace_as_cmd);
18418 install_element(BGP_IPV6M_NODE,
18419 &no_neighbor_remove_private_as_replace_as_cmd);
18420 install_element(BGP_IPV6M_NODE,
18421 &neighbor_remove_private_as_all_replace_as_cmd);
18422 install_element(BGP_IPV6M_NODE,
18423 &no_neighbor_remove_private_as_all_replace_as_cmd);
18424 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18425 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18426 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18427 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18428 install_element(BGP_IPV6L_NODE,
18429 &neighbor_remove_private_as_replace_as_cmd);
18430 install_element(BGP_IPV6L_NODE,
18431 &no_neighbor_remove_private_as_replace_as_cmd);
18432 install_element(BGP_IPV6L_NODE,
18433 &neighbor_remove_private_as_all_replace_as_cmd);
18434 install_element(BGP_IPV6L_NODE,
18435 &no_neighbor_remove_private_as_all_replace_as_cmd);
18436 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18437 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18438 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18439 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18440 install_element(BGP_VPNV4_NODE,
18441 &neighbor_remove_private_as_replace_as_cmd);
18442 install_element(BGP_VPNV4_NODE,
18443 &no_neighbor_remove_private_as_replace_as_cmd);
18444 install_element(BGP_VPNV4_NODE,
18445 &neighbor_remove_private_as_all_replace_as_cmd);
18446 install_element(BGP_VPNV4_NODE,
18447 &no_neighbor_remove_private_as_all_replace_as_cmd);
18448 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18449 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18450 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18451 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18452 install_element(BGP_VPNV6_NODE,
18453 &neighbor_remove_private_as_replace_as_cmd);
18454 install_element(BGP_VPNV6_NODE,
18455 &no_neighbor_remove_private_as_replace_as_cmd);
18456 install_element(BGP_VPNV6_NODE,
18457 &neighbor_remove_private_as_all_replace_as_cmd);
18458 install_element(BGP_VPNV6_NODE,
18459 &no_neighbor_remove_private_as_all_replace_as_cmd);
18460
18461 /* "neighbor send-community" commands.*/
18462 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18463 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18464 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18465 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18466 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18467 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18468 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18469 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18470 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18471 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18472 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18473 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18474 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18475 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18476 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18477 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18478 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18479 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18480 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18481 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18482 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18483 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18484 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18485 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18486 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18487 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18488 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18489 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18490 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18491 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18492 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18493 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18494 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18495 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18496 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18497 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18498
18499 /* "neighbor route-reflector" commands.*/
18500 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18501 install_element(BGP_NODE,
18502 &no_neighbor_route_reflector_client_hidden_cmd);
18503 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18504 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18505 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18506 install_element(BGP_IPV4M_NODE,
18507 &no_neighbor_route_reflector_client_cmd);
18508 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18509 install_element(BGP_IPV4L_NODE,
18510 &no_neighbor_route_reflector_client_cmd);
18511 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18512 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18513 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18514 install_element(BGP_IPV6M_NODE,
18515 &no_neighbor_route_reflector_client_cmd);
18516 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18517 install_element(BGP_IPV6L_NODE,
18518 &no_neighbor_route_reflector_client_cmd);
18519 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18520 install_element(BGP_VPNV4_NODE,
18521 &no_neighbor_route_reflector_client_cmd);
18522 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18523 install_element(BGP_VPNV6_NODE,
18524 &no_neighbor_route_reflector_client_cmd);
18525 install_element(BGP_FLOWSPECV4_NODE,
18526 &neighbor_route_reflector_client_cmd);
18527 install_element(BGP_FLOWSPECV4_NODE,
18528 &no_neighbor_route_reflector_client_cmd);
18529 install_element(BGP_FLOWSPECV6_NODE,
18530 &neighbor_route_reflector_client_cmd);
18531 install_element(BGP_FLOWSPECV6_NODE,
18532 &no_neighbor_route_reflector_client_cmd);
18533 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18534 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18535
18536 /* "neighbor route-server" commands.*/
18537 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18538 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18539 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18540 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18541 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18542 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18543 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18544 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18545 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18546 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18547 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18548 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18549 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18550 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18551 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18552 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18553 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18554 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18555 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18556 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18557 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18558 install_element(BGP_FLOWSPECV4_NODE,
18559 &no_neighbor_route_server_client_cmd);
18560 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18561 install_element(BGP_FLOWSPECV6_NODE,
18562 &no_neighbor_route_server_client_cmd);
18563
18564 /* "neighbor disable-addpath-rx" commands. */
18565 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18566 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18567 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18568 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18569 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18570 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18571 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18572 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18573 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18574 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18575 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18576 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18577 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18578 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18579 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18580 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18581
18582 /* "neighbor addpath-tx-all-paths" commands.*/
18583 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18584 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18585 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18586 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18587 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18588 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18589 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18590 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18591 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18592 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18593 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18594 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18595 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18596 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18597 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18598 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18599 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18600 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18601
18602 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18603 install_element(BGP_NODE,
18604 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18605 install_element(BGP_NODE,
18606 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18607 install_element(BGP_IPV4_NODE,
18608 &neighbor_addpath_tx_bestpath_per_as_cmd);
18609 install_element(BGP_IPV4_NODE,
18610 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18611 install_element(BGP_IPV4M_NODE,
18612 &neighbor_addpath_tx_bestpath_per_as_cmd);
18613 install_element(BGP_IPV4M_NODE,
18614 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18615 install_element(BGP_IPV4L_NODE,
18616 &neighbor_addpath_tx_bestpath_per_as_cmd);
18617 install_element(BGP_IPV4L_NODE,
18618 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18619 install_element(BGP_IPV6_NODE,
18620 &neighbor_addpath_tx_bestpath_per_as_cmd);
18621 install_element(BGP_IPV6_NODE,
18622 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18623 install_element(BGP_IPV6M_NODE,
18624 &neighbor_addpath_tx_bestpath_per_as_cmd);
18625 install_element(BGP_IPV6M_NODE,
18626 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18627 install_element(BGP_IPV6L_NODE,
18628 &neighbor_addpath_tx_bestpath_per_as_cmd);
18629 install_element(BGP_IPV6L_NODE,
18630 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18631 install_element(BGP_VPNV4_NODE,
18632 &neighbor_addpath_tx_bestpath_per_as_cmd);
18633 install_element(BGP_VPNV4_NODE,
18634 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18635 install_element(BGP_VPNV6_NODE,
18636 &neighbor_addpath_tx_bestpath_per_as_cmd);
18637 install_element(BGP_VPNV6_NODE,
18638 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18639
18640 /* "neighbor sender-as-path-loop-detection" commands. */
18641 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18642 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18643
18644 /* "neighbor passive" commands. */
18645 install_element(BGP_NODE, &neighbor_passive_cmd);
18646 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18647
18648
18649 /* "neighbor shutdown" commands. */
18650 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18651 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18652 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18653 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18654 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18655 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18656
18657 /* "neighbor capability extended-nexthop" commands.*/
18658 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18659 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18660
18661 /* "neighbor capability orf prefix-list" commands.*/
18662 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18663 install_element(BGP_NODE,
18664 &no_neighbor_capability_orf_prefix_hidden_cmd);
18665 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18666 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18667 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18668 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18669 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18670 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18671 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18672 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18673 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18674 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18675 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18676 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18677
18678 /* "neighbor capability dynamic" commands.*/
18679 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18680 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18681
18682 /* "neighbor dont-capability-negotiate" commands. */
18683 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18684 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18685
18686 /* "neighbor ebgp-multihop" commands. */
18687 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18688 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18689 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18690
18691 /* "neighbor disable-connected-check" commands. */
18692 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18693 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18694
18695 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18696 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18697 install_element(BGP_NODE,
18698 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
18699
18700 /* "neighbor extended-optional-parameters" commands. */
18701 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18702 install_element(BGP_NODE,
18703 &no_neighbor_extended_optional_parameters_cmd);
18704
18705 /* "neighbor enforce-first-as" commands. */
18706 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18707 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18708
18709 /* "neighbor description" commands. */
18710 install_element(BGP_NODE, &neighbor_description_cmd);
18711 install_element(BGP_NODE, &no_neighbor_description_cmd);
18712 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18713
18714 /* "neighbor update-source" commands. "*/
18715 install_element(BGP_NODE, &neighbor_update_source_cmd);
18716 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18717
18718 /* "neighbor default-originate" commands. */
18719 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18720 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18721 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18722 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18723 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18724 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18725 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18726 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18727 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18728 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18729 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18730 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18731 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18732 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18733 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18734 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18735 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18736 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18737 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18738 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18739 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18740
18741 /* "neighbor port" commands. */
18742 install_element(BGP_NODE, &neighbor_port_cmd);
18743 install_element(BGP_NODE, &no_neighbor_port_cmd);
18744
18745 /* "neighbor weight" commands. */
18746 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18747 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18748
18749 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18750 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18751 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18752 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18753 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18754 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18755 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18756 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18757 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18758 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18759 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18760 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18761 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18762 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18763 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18764 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18765
18766 /* "neighbor override-capability" commands. */
18767 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18768 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18769
18770 /* "neighbor strict-capability-match" commands. */
18771 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18772 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18773
18774 /* "neighbor timers" commands. */
18775 install_element(BGP_NODE, &neighbor_timers_cmd);
18776 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18777
18778 /* "neighbor timers connect" commands. */
18779 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18780 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18781
18782 /* "neighbor timers delayopen" commands. */
18783 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18784 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18785
18786 /* "neighbor advertisement-interval" commands. */
18787 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18788 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18789
18790 /* "neighbor interface" commands. */
18791 install_element(BGP_NODE, &neighbor_interface_cmd);
18792 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18793
18794 /* "neighbor distribute" commands. */
18795 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18796 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18797 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18798 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18799 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18800 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18801 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18802 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18803 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18804 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18805 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18806 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18807 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18808 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18809 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18810 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18811 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18812 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18813
18814 /* "neighbor prefix-list" commands. */
18815 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18816 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18817 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18818 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18819 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18820 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18821 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18822 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18823 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18824 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18825 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18826 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18827 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18828 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18829 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18830 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18831 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18832 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18833 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18834 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18835 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18836 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18837
18838 /* "neighbor filter-list" commands. */
18839 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18840 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18841 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18842 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18843 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18844 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18845 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18846 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18847 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18848 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18849 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18850 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18851 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18852 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18853 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18854 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18855 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18856 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18857 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18858 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18859 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18860 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18861
18862 /* "neighbor route-map" commands. */
18863 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18864 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18865 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18866 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18867 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18868 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18869 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18870 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18871 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18872 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18873 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18874 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18875 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18876 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18877 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18878 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18879 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18880 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18881 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18882 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18883 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18884 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18885 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18886 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18887
18888 /* "neighbor unsuppress-map" commands. */
18889 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18890 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18891 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18892 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18893 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18894 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18895 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18896 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18897 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18898 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18899 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18900 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18901 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18902 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18903 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18904 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18905 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18906 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18907
18908 /* "neighbor advertise-map" commands. */
18909 install_element(BGP_NODE, &bgp_condadv_period_cmd);
18910 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18911 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18912 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18913 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18914 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18915 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18916 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18917 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18918 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18919
18920 /* neighbor maximum-prefix-out commands. */
18921 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18922 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18923 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18924 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18925 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18926 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18927 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18928 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18929 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18930 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18931 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18932 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18933 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18934 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18935 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18936 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18937 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18938 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18939
18940 /* "neighbor maximum-prefix" commands. */
18941 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18942 install_element(BGP_NODE,
18943 &neighbor_maximum_prefix_threshold_hidden_cmd);
18944 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18945 install_element(BGP_NODE,
18946 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18947 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18948 install_element(BGP_NODE,
18949 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18950 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18951 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18952 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18953 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18954 install_element(BGP_IPV4_NODE,
18955 &neighbor_maximum_prefix_threshold_warning_cmd);
18956 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18957 install_element(BGP_IPV4_NODE,
18958 &neighbor_maximum_prefix_threshold_restart_cmd);
18959 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18960 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18961 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18962 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18963 install_element(BGP_IPV4M_NODE,
18964 &neighbor_maximum_prefix_threshold_warning_cmd);
18965 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18966 install_element(BGP_IPV4M_NODE,
18967 &neighbor_maximum_prefix_threshold_restart_cmd);
18968 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18969 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18970 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18971 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18972 install_element(BGP_IPV4L_NODE,
18973 &neighbor_maximum_prefix_threshold_warning_cmd);
18974 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18975 install_element(BGP_IPV4L_NODE,
18976 &neighbor_maximum_prefix_threshold_restart_cmd);
18977 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18978 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18979 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18980 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18981 install_element(BGP_IPV6_NODE,
18982 &neighbor_maximum_prefix_threshold_warning_cmd);
18983 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18984 install_element(BGP_IPV6_NODE,
18985 &neighbor_maximum_prefix_threshold_restart_cmd);
18986 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18987 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18988 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18989 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18990 install_element(BGP_IPV6M_NODE,
18991 &neighbor_maximum_prefix_threshold_warning_cmd);
18992 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18993 install_element(BGP_IPV6M_NODE,
18994 &neighbor_maximum_prefix_threshold_restart_cmd);
18995 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18996 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18997 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18998 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18999 install_element(BGP_IPV6L_NODE,
19000 &neighbor_maximum_prefix_threshold_warning_cmd);
19001 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19002 install_element(BGP_IPV6L_NODE,
19003 &neighbor_maximum_prefix_threshold_restart_cmd);
19004 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19005 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19006 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19007 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19008 install_element(BGP_VPNV4_NODE,
19009 &neighbor_maximum_prefix_threshold_warning_cmd);
19010 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19011 install_element(BGP_VPNV4_NODE,
19012 &neighbor_maximum_prefix_threshold_restart_cmd);
19013 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19014 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19015 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19016 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19017 install_element(BGP_VPNV6_NODE,
19018 &neighbor_maximum_prefix_threshold_warning_cmd);
19019 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19020 install_element(BGP_VPNV6_NODE,
19021 &neighbor_maximum_prefix_threshold_restart_cmd);
19022 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19023
19024 /* "neighbor allowas-in" */
19025 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19026 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19027 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19028 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19029 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19030 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19031 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19032 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19033 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19034 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19035 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19036 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19037 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19038 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19039 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19040 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19041 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19042 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19043 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19044 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19045
19046 /* address-family commands. */
19047 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19048 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19049 #ifdef KEEP_OLD_VPN_COMMANDS
19050 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19051 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19052 #endif /* KEEP_OLD_VPN_COMMANDS */
19053
19054 install_element(BGP_NODE, &address_family_evpn_cmd);
19055
19056 /* "exit-address-family" command. */
19057 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19058 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19059 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19060 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19061 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19062 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19063 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19064 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19065 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19066 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19067 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19068
19069 /* "clear ip bgp commands" */
19070 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19071
19072 /* clear ip bgp prefix */
19073 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19074 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19075 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19076
19077 /* "show [ip] bgp summary" commands. */
19078 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19079 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19080 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19081 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19082 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19083 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19084 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19085
19086 /* "show [ip] bgp neighbors" commands. */
19087 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19088
19089 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19090
19091 /* "show [ip] bgp peer-group" commands. */
19092 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19093
19094 /* "show [ip] bgp paths" commands. */
19095 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19096
19097 /* "show [ip] bgp community" commands. */
19098 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19099
19100 /* "show ip bgp large-community" commands. */
19101 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19102 /* "show [ip] bgp attribute-info" commands. */
19103 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19104 /* "show [ip] bgp route-leak" command */
19105 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19106
19107 /* "redistribute" commands. */
19108 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19109 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19110 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19111 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19112 install_element(BGP_NODE,
19113 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19114 install_element(BGP_NODE,
19115 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19116 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19117 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19118 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19119 install_element(BGP_NODE,
19120 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19121 install_element(BGP_NODE,
19122 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19123 install_element(BGP_NODE,
19124 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19125 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19126 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19127 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19128 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19129 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19130 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19131 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19132 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19133 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19134 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19135 install_element(BGP_IPV4_NODE,
19136 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19137 install_element(BGP_IPV4_NODE,
19138 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19139 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19140 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19141 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19142 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19143 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19144 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19145
19146 /* import|export vpn [route-map WORD] */
19147 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19148 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19149
19150 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19151 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19152
19153 /* ttl_security commands */
19154 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19155 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19156
19157 /* "show [ip] bgp memory" commands. */
19158 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19159
19160 /* "show bgp martian next-hop" */
19161 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19162
19163 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19164
19165 /* "show [ip] bgp views" commands. */
19166 install_element(VIEW_NODE, &show_bgp_views_cmd);
19167
19168 /* "show [ip] bgp vrfs" commands. */
19169 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19170
19171 /* Community-list. */
19172 community_list_vty();
19173
19174 community_alias_vty();
19175
19176 /* vpn-policy commands */
19177 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19178 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19179 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19180 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19181 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19182 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19183 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19184 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19185 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19186 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19187 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19188 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19189
19190 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19191 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19192
19193 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19194 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19195 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19196 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19197 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19198 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19199 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19200 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19201 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19202 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19203
19204 /* tcp-mss command */
19205 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19206 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19207
19208 /* srv6 commands */
19209 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19210 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19211 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19212 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19213 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19214 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19215 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19216 }
19217
19218 #include "memory.h"
19219 #include "bgp_regex.h"
19220 #include "bgp_clist.h"
19221 #include "bgp_ecommunity.h"
19222
19223 /* VTY functions. */
19224
19225 /* Direction value to string conversion. */
19226 static const char *community_direct_str(int direct)
19227 {
19228 switch (direct) {
19229 case COMMUNITY_DENY:
19230 return "deny";
19231 case COMMUNITY_PERMIT:
19232 return "permit";
19233 default:
19234 return "unknown";
19235 }
19236 }
19237
19238 /* Display error string. */
19239 static void community_list_perror(struct vty *vty, int ret)
19240 {
19241 switch (ret) {
19242 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19243 vty_out(vty, "%% Can't find community-list\n");
19244 break;
19245 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19246 vty_out(vty, "%% Malformed community-list value\n");
19247 break;
19248 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19249 vty_out(vty,
19250 "%% Community name conflict, previously defined as standard community\n");
19251 break;
19252 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19253 vty_out(vty,
19254 "%% Community name conflict, previously defined as expanded community\n");
19255 break;
19256 }
19257 }
19258
19259 /* "community-list" keyword help string. */
19260 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19261
19262 /*community-list standard */
19263 DEFUN (community_list_standard,
19264 bgp_community_list_standard_cmd,
19265 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19266 BGP_STR
19267 COMMUNITY_LIST_STR
19268 "Community list number (standard)\n"
19269 "Add an standard community-list entry\n"
19270 "Community list name\n"
19271 "Sequence number of an entry\n"
19272 "Sequence number\n"
19273 "Specify community to reject\n"
19274 "Specify community to accept\n"
19275 COMMUNITY_VAL_STR)
19276 {
19277 char *cl_name_or_number = NULL;
19278 char *seq = NULL;
19279 int direct = 0;
19280 int style = COMMUNITY_LIST_STANDARD;
19281 int idx = 0;
19282
19283 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19284 seq = argv[idx]->arg;
19285
19286 idx = 0;
19287 argv_find(argv, argc, "(1-99)", &idx);
19288 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19289 cl_name_or_number = argv[idx]->arg;
19290 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19291 : COMMUNITY_DENY;
19292 argv_find(argv, argc, "AA:NN", &idx);
19293 char *str = argv_concat(argv, argc, idx);
19294
19295 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19296 direct, style);
19297
19298 XFREE(MTYPE_TMP, str);
19299
19300 if (ret < 0) {
19301 /* Display error string. */
19302 community_list_perror(vty, ret);
19303 return CMD_WARNING_CONFIG_FAILED;
19304 }
19305
19306 return CMD_SUCCESS;
19307 }
19308
19309 DEFUN (no_community_list_standard_all,
19310 no_bgp_community_list_standard_all_cmd,
19311 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19312 NO_STR
19313 BGP_STR
19314 COMMUNITY_LIST_STR
19315 "Community list number (standard)\n"
19316 "Add an standard community-list entry\n"
19317 "Community list name\n"
19318 "Sequence number of an entry\n"
19319 "Sequence number\n"
19320 "Specify community to reject\n"
19321 "Specify community to accept\n"
19322 COMMUNITY_VAL_STR)
19323 {
19324 char *cl_name_or_number = NULL;
19325 char *str = NULL;
19326 int direct = 0;
19327 int style = COMMUNITY_LIST_STANDARD;
19328 char *seq = NULL;
19329 int idx = 0;
19330
19331 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19332 seq = argv[idx]->arg;
19333
19334 idx = 0;
19335 argv_find(argv, argc, "permit", &idx);
19336 argv_find(argv, argc, "deny", &idx);
19337
19338 if (idx) {
19339 direct = argv_find(argv, argc, "permit", &idx)
19340 ? COMMUNITY_PERMIT
19341 : COMMUNITY_DENY;
19342
19343 idx = 0;
19344 argv_find(argv, argc, "AA:NN", &idx);
19345 str = argv_concat(argv, argc, idx);
19346 }
19347
19348 idx = 0;
19349 argv_find(argv, argc, "(1-99)", &idx);
19350 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19351 cl_name_or_number = argv[idx]->arg;
19352
19353 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19354 direct, style);
19355
19356 XFREE(MTYPE_TMP, str);
19357
19358 if (ret < 0) {
19359 community_list_perror(vty, ret);
19360 return CMD_WARNING_CONFIG_FAILED;
19361 }
19362
19363 return CMD_SUCCESS;
19364 }
19365
19366 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19367 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19368 NO_STR BGP_STR COMMUNITY_LIST_STR
19369 "Community list number (standard)\n"
19370 "Add an standard community-list entry\n"
19371 "Community list name\n")
19372
19373 /*community-list expanded */
19374 DEFUN (community_list_expanded_all,
19375 bgp_community_list_expanded_all_cmd,
19376 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19377 BGP_STR
19378 COMMUNITY_LIST_STR
19379 "Community list number (expanded)\n"
19380 "Add an expanded community-list entry\n"
19381 "Community list name\n"
19382 "Sequence number of an entry\n"
19383 "Sequence number\n"
19384 "Specify community to reject\n"
19385 "Specify community to accept\n"
19386 COMMUNITY_VAL_STR)
19387 {
19388 char *cl_name_or_number = NULL;
19389 char *seq = NULL;
19390 int direct = 0;
19391 int style = COMMUNITY_LIST_EXPANDED;
19392 int idx = 0;
19393
19394 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19395 seq = argv[idx]->arg;
19396
19397 idx = 0;
19398
19399 argv_find(argv, argc, "(100-500)", &idx);
19400 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19401 cl_name_or_number = argv[idx]->arg;
19402 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19403 : COMMUNITY_DENY;
19404 argv_find(argv, argc, "AA:NN", &idx);
19405 char *str = argv_concat(argv, argc, idx);
19406
19407 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19408 direct, style);
19409
19410 XFREE(MTYPE_TMP, str);
19411
19412 if (ret < 0) {
19413 /* Display error string. */
19414 community_list_perror(vty, ret);
19415 return CMD_WARNING_CONFIG_FAILED;
19416 }
19417
19418 return CMD_SUCCESS;
19419 }
19420
19421 DEFUN (no_community_list_expanded_all,
19422 no_bgp_community_list_expanded_all_cmd,
19423 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19424 NO_STR
19425 BGP_STR
19426 COMMUNITY_LIST_STR
19427 "Community list number (expanded)\n"
19428 "Add an expanded community-list entry\n"
19429 "Community list name\n"
19430 "Sequence number of an entry\n"
19431 "Sequence number\n"
19432 "Specify community to reject\n"
19433 "Specify community to accept\n"
19434 COMMUNITY_VAL_STR)
19435 {
19436 char *cl_name_or_number = NULL;
19437 char *seq = NULL;
19438 char *str = NULL;
19439 int direct = 0;
19440 int style = COMMUNITY_LIST_EXPANDED;
19441 int idx = 0;
19442
19443 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19444 seq = argv[idx]->arg;
19445
19446 idx = 0;
19447 argv_find(argv, argc, "permit", &idx);
19448 argv_find(argv, argc, "deny", &idx);
19449
19450 if (idx) {
19451 direct = argv_find(argv, argc, "permit", &idx)
19452 ? COMMUNITY_PERMIT
19453 : COMMUNITY_DENY;
19454
19455 idx = 0;
19456 argv_find(argv, argc, "AA:NN", &idx);
19457 str = argv_concat(argv, argc, idx);
19458 }
19459
19460 idx = 0;
19461 argv_find(argv, argc, "(100-500)", &idx);
19462 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19463 cl_name_or_number = argv[idx]->arg;
19464
19465 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19466 direct, style);
19467
19468 XFREE(MTYPE_TMP, str);
19469
19470 if (ret < 0) {
19471 community_list_perror(vty, ret);
19472 return CMD_WARNING_CONFIG_FAILED;
19473 }
19474
19475 return CMD_SUCCESS;
19476 }
19477
19478 ALIAS(no_community_list_expanded_all,
19479 no_bgp_community_list_expanded_all_list_cmd,
19480 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19481 NO_STR BGP_STR COMMUNITY_LIST_STR
19482 "Community list number (expanded)\n"
19483 "Add an expanded community-list entry\n"
19484 "Community list name\n")
19485
19486 /* Return configuration string of community-list entry. */
19487 static const char *community_list_config_str(struct community_entry *entry)
19488 {
19489 const char *str;
19490
19491 if (entry->any)
19492 str = "";
19493 else {
19494 if (entry->style == COMMUNITY_LIST_STANDARD)
19495 str = community_str(entry->u.com, false, false);
19496 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19497 str = lcommunity_str(entry->u.lcom, false, false);
19498 else
19499 str = entry->config;
19500 }
19501 return str;
19502 }
19503
19504 static void community_list_show(struct vty *vty, struct community_list *list)
19505 {
19506 struct community_entry *entry;
19507
19508 for (entry = list->head; entry; entry = entry->next) {
19509 if (entry == list->head) {
19510 if (all_digit(list->name))
19511 vty_out(vty, "Community %s list %s\n",
19512 entry->style == COMMUNITY_LIST_STANDARD
19513 ? "standard"
19514 : "(expanded) access",
19515 list->name);
19516 else
19517 vty_out(vty, "Named Community %s list %s\n",
19518 entry->style == COMMUNITY_LIST_STANDARD
19519 ? "standard"
19520 : "expanded",
19521 list->name);
19522 }
19523 if (entry->any)
19524 vty_out(vty, " %s\n",
19525 community_direct_str(entry->direct));
19526 else
19527 vty_out(vty, " %s %s\n",
19528 community_direct_str(entry->direct),
19529 community_list_config_str(entry));
19530 }
19531 }
19532
19533 DEFUN (show_community_list,
19534 show_bgp_community_list_cmd,
19535 "show bgp community-list",
19536 SHOW_STR
19537 BGP_STR
19538 "List community-list\n")
19539 {
19540 struct community_list *list;
19541 struct community_list_master *cm;
19542
19543 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19544 if (!cm)
19545 return CMD_SUCCESS;
19546
19547 for (list = cm->num.head; list; list = list->next)
19548 community_list_show(vty, list);
19549
19550 for (list = cm->str.head; list; list = list->next)
19551 community_list_show(vty, list);
19552
19553 return CMD_SUCCESS;
19554 }
19555
19556 DEFUN (show_community_list_arg,
19557 show_bgp_community_list_arg_cmd,
19558 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
19559 SHOW_STR
19560 BGP_STR
19561 "List community-list\n"
19562 "Community-list number\n"
19563 "Community-list name\n"
19564 "Detailed information on community-list\n")
19565 {
19566 int idx_comm_list = 3;
19567 struct community_list *list;
19568
19569 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19570 COMMUNITY_LIST_MASTER);
19571 if (!list) {
19572 vty_out(vty, "%% Can't find community-list\n");
19573 return CMD_WARNING;
19574 }
19575
19576 community_list_show(vty, list);
19577
19578 return CMD_SUCCESS;
19579 }
19580
19581 /*
19582 * Large Community code.
19583 */
19584 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19585 struct cmd_token **argv, int style,
19586 int reject_all_digit_name)
19587 {
19588 int ret;
19589 int direct;
19590 char *str;
19591 int idx = 0;
19592 char *cl_name;
19593 char *seq = NULL;
19594
19595 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19596 seq = argv[idx]->arg;
19597
19598 idx = 0;
19599 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19600 : COMMUNITY_DENY;
19601
19602 /* All digit name check. */
19603 idx = 0;
19604 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19605 argv_find(argv, argc, "(1-99)", &idx);
19606 argv_find(argv, argc, "(100-500)", &idx);
19607 cl_name = argv[idx]->arg;
19608 if (reject_all_digit_name && all_digit(cl_name)) {
19609 vty_out(vty, "%% Community name cannot have all digits\n");
19610 return CMD_WARNING_CONFIG_FAILED;
19611 }
19612
19613 idx = 0;
19614 argv_find(argv, argc, "AA:BB:CC", &idx);
19615 argv_find(argv, argc, "LINE", &idx);
19616 /* Concat community string argument. */
19617 if (idx)
19618 str = argv_concat(argv, argc, idx);
19619 else
19620 str = NULL;
19621
19622 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19623
19624 /* Free temporary community list string allocated by
19625 argv_concat(). */
19626 XFREE(MTYPE_TMP, str);
19627
19628 if (ret < 0) {
19629 community_list_perror(vty, ret);
19630 return CMD_WARNING_CONFIG_FAILED;
19631 }
19632 return CMD_SUCCESS;
19633 }
19634
19635 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19636 struct cmd_token **argv, int style)
19637 {
19638 int ret;
19639 int direct = 0;
19640 char *str = NULL;
19641 int idx = 0;
19642 char *seq = NULL;
19643
19644 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19645 seq = argv[idx]->arg;
19646
19647 idx = 0;
19648 argv_find(argv, argc, "permit", &idx);
19649 argv_find(argv, argc, "deny", &idx);
19650
19651 if (idx) {
19652 /* Check the list direct. */
19653 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19654 direct = COMMUNITY_PERMIT;
19655 else
19656 direct = COMMUNITY_DENY;
19657
19658 idx = 0;
19659 argv_find(argv, argc, "LINE", &idx);
19660 argv_find(argv, argc, "AA:AA:NN", &idx);
19661 /* Concat community string argument. */
19662 str = argv_concat(argv, argc, idx);
19663 }
19664
19665 idx = 0;
19666 argv_find(argv, argc, "(1-99)", &idx);
19667 argv_find(argv, argc, "(100-500)", &idx);
19668 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19669
19670 /* Unset community list. */
19671 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19672 style);
19673
19674 /* Free temporary community list string allocated by
19675 argv_concat(). */
19676 XFREE(MTYPE_TMP, str);
19677
19678 if (ret < 0) {
19679 community_list_perror(vty, ret);
19680 return CMD_WARNING_CONFIG_FAILED;
19681 }
19682
19683 return CMD_SUCCESS;
19684 }
19685
19686 /* "large-community-list" keyword help string. */
19687 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19688 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19689
19690 DEFUN (lcommunity_list_standard,
19691 bgp_lcommunity_list_standard_cmd,
19692 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19693 BGP_STR
19694 LCOMMUNITY_LIST_STR
19695 "Large Community list number (standard)\n"
19696 "Sequence number of an entry\n"
19697 "Sequence number\n"
19698 "Specify large community to reject\n"
19699 "Specify large community to accept\n"
19700 LCOMMUNITY_VAL_STR)
19701 {
19702 return lcommunity_list_set_vty(vty, argc, argv,
19703 LARGE_COMMUNITY_LIST_STANDARD, 0);
19704 }
19705
19706 DEFUN (lcommunity_list_expanded,
19707 bgp_lcommunity_list_expanded_cmd,
19708 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19709 BGP_STR
19710 LCOMMUNITY_LIST_STR
19711 "Large Community list number (expanded)\n"
19712 "Sequence number of an entry\n"
19713 "Sequence number\n"
19714 "Specify large community to reject\n"
19715 "Specify large community to accept\n"
19716 "An ordered list as a regular-expression\n")
19717 {
19718 return lcommunity_list_set_vty(vty, argc, argv,
19719 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19720 }
19721
19722 DEFUN (lcommunity_list_name_standard,
19723 bgp_lcommunity_list_name_standard_cmd,
19724 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19725 BGP_STR
19726 LCOMMUNITY_LIST_STR
19727 "Specify standard large-community-list\n"
19728 "Large Community list name\n"
19729 "Sequence number of an entry\n"
19730 "Sequence number\n"
19731 "Specify large community to reject\n"
19732 "Specify large community to accept\n"
19733 LCOMMUNITY_VAL_STR)
19734 {
19735 return lcommunity_list_set_vty(vty, argc, argv,
19736 LARGE_COMMUNITY_LIST_STANDARD, 1);
19737 }
19738
19739 DEFUN (lcommunity_list_name_expanded,
19740 bgp_lcommunity_list_name_expanded_cmd,
19741 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19742 BGP_STR
19743 LCOMMUNITY_LIST_STR
19744 "Specify expanded large-community-list\n"
19745 "Large Community list name\n"
19746 "Sequence number of an entry\n"
19747 "Sequence number\n"
19748 "Specify large community to reject\n"
19749 "Specify large community to accept\n"
19750 "An ordered list as a regular-expression\n")
19751 {
19752 return lcommunity_list_set_vty(vty, argc, argv,
19753 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19754 }
19755
19756 DEFUN (no_lcommunity_list_all,
19757 no_bgp_lcommunity_list_all_cmd,
19758 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
19759 NO_STR
19760 BGP_STR
19761 LCOMMUNITY_LIST_STR
19762 "Large Community list number (standard)\n"
19763 "Large Community list number (expanded)\n"
19764 "Large Community list name\n")
19765 {
19766 return lcommunity_list_unset_vty(vty, argc, argv,
19767 LARGE_COMMUNITY_LIST_STANDARD);
19768 }
19769
19770 DEFUN (no_lcommunity_list_name_standard_all,
19771 no_bgp_lcommunity_list_name_standard_all_cmd,
19772 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
19773 NO_STR
19774 BGP_STR
19775 LCOMMUNITY_LIST_STR
19776 "Specify standard large-community-list\n"
19777 "Large Community list name\n")
19778 {
19779 return lcommunity_list_unset_vty(vty, argc, argv,
19780 LARGE_COMMUNITY_LIST_STANDARD);
19781 }
19782
19783 DEFUN (no_lcommunity_list_name_expanded_all,
19784 no_bgp_lcommunity_list_name_expanded_all_cmd,
19785 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
19786 NO_STR
19787 BGP_STR
19788 LCOMMUNITY_LIST_STR
19789 "Specify expanded large-community-list\n"
19790 "Large Community list name\n")
19791 {
19792 return lcommunity_list_unset_vty(vty, argc, argv,
19793 LARGE_COMMUNITY_LIST_EXPANDED);
19794 }
19795
19796 DEFUN (no_lcommunity_list_standard,
19797 no_bgp_lcommunity_list_standard_cmd,
19798 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19799 NO_STR
19800 BGP_STR
19801 LCOMMUNITY_LIST_STR
19802 "Large Community list number (standard)\n"
19803 "Sequence number of an entry\n"
19804 "Sequence number\n"
19805 "Specify large community to reject\n"
19806 "Specify large community to accept\n"
19807 LCOMMUNITY_VAL_STR)
19808 {
19809 return lcommunity_list_unset_vty(vty, argc, argv,
19810 LARGE_COMMUNITY_LIST_STANDARD);
19811 }
19812
19813 DEFUN (no_lcommunity_list_expanded,
19814 no_bgp_lcommunity_list_expanded_cmd,
19815 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19816 NO_STR
19817 BGP_STR
19818 LCOMMUNITY_LIST_STR
19819 "Large Community list number (expanded)\n"
19820 "Sequence number of an entry\n"
19821 "Sequence number\n"
19822 "Specify large community to reject\n"
19823 "Specify large community to accept\n"
19824 "An ordered list as a regular-expression\n")
19825 {
19826 return lcommunity_list_unset_vty(vty, argc, argv,
19827 LARGE_COMMUNITY_LIST_EXPANDED);
19828 }
19829
19830 DEFUN (no_lcommunity_list_name_standard,
19831 no_bgp_lcommunity_list_name_standard_cmd,
19832 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19833 NO_STR
19834 BGP_STR
19835 LCOMMUNITY_LIST_STR
19836 "Specify standard large-community-list\n"
19837 "Large Community list name\n"
19838 "Sequence number of an entry\n"
19839 "Sequence number\n"
19840 "Specify large community to reject\n"
19841 "Specify large community to accept\n"
19842 LCOMMUNITY_VAL_STR)
19843 {
19844 return lcommunity_list_unset_vty(vty, argc, argv,
19845 LARGE_COMMUNITY_LIST_STANDARD);
19846 }
19847
19848 DEFUN (no_lcommunity_list_name_expanded,
19849 no_bgp_lcommunity_list_name_expanded_cmd,
19850 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19851 NO_STR
19852 BGP_STR
19853 LCOMMUNITY_LIST_STR
19854 "Specify expanded large-community-list\n"
19855 "Large community list name\n"
19856 "Sequence number of an entry\n"
19857 "Sequence number\n"
19858 "Specify large community to reject\n"
19859 "Specify large community to accept\n"
19860 "An ordered list as a regular-expression\n")
19861 {
19862 return lcommunity_list_unset_vty(vty, argc, argv,
19863 LARGE_COMMUNITY_LIST_EXPANDED);
19864 }
19865
19866 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19867 {
19868 struct community_entry *entry;
19869
19870 for (entry = list->head; entry; entry = entry->next) {
19871 if (entry == list->head) {
19872 if (all_digit(list->name))
19873 vty_out(vty, "Large community %s list %s\n",
19874 entry->style ==
19875 LARGE_COMMUNITY_LIST_STANDARD
19876 ? "standard"
19877 : "(expanded) access",
19878 list->name);
19879 else
19880 vty_out(vty,
19881 "Named large community %s list %s\n",
19882 entry->style ==
19883 LARGE_COMMUNITY_LIST_STANDARD
19884 ? "standard"
19885 : "expanded",
19886 list->name);
19887 }
19888 if (entry->any)
19889 vty_out(vty, " %s\n",
19890 community_direct_str(entry->direct));
19891 else
19892 vty_out(vty, " %s %s\n",
19893 community_direct_str(entry->direct),
19894 community_list_config_str(entry));
19895 }
19896 }
19897
19898 DEFUN (show_lcommunity_list,
19899 show_bgp_lcommunity_list_cmd,
19900 "show bgp large-community-list",
19901 SHOW_STR
19902 BGP_STR
19903 "List large-community list\n")
19904 {
19905 struct community_list *list;
19906 struct community_list_master *cm;
19907
19908 cm = community_list_master_lookup(bgp_clist,
19909 LARGE_COMMUNITY_LIST_MASTER);
19910 if (!cm)
19911 return CMD_SUCCESS;
19912
19913 for (list = cm->num.head; list; list = list->next)
19914 lcommunity_list_show(vty, list);
19915
19916 for (list = cm->str.head; list; list = list->next)
19917 lcommunity_list_show(vty, list);
19918
19919 return CMD_SUCCESS;
19920 }
19921
19922 DEFUN (show_lcommunity_list_arg,
19923 show_bgp_lcommunity_list_arg_cmd,
19924 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
19925 SHOW_STR
19926 BGP_STR
19927 "List large-community list\n"
19928 "Large-community-list number\n"
19929 "Large-community-list name\n"
19930 "Detailed information on large-community-list\n")
19931 {
19932 struct community_list *list;
19933
19934 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19935 LARGE_COMMUNITY_LIST_MASTER);
19936 if (!list) {
19937 vty_out(vty, "%% Can't find large-community-list\n");
19938 return CMD_WARNING;
19939 }
19940
19941 lcommunity_list_show(vty, list);
19942
19943 return CMD_SUCCESS;
19944 }
19945
19946 /* "extcommunity-list" keyword help string. */
19947 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19948 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19949
19950 DEFUN (extcommunity_list_standard,
19951 bgp_extcommunity_list_standard_cmd,
19952 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19953 BGP_STR
19954 EXTCOMMUNITY_LIST_STR
19955 "Extended Community list number (standard)\n"
19956 "Specify standard extcommunity-list\n"
19957 "Community list name\n"
19958 "Sequence number of an entry\n"
19959 "Sequence number\n"
19960 "Specify community to reject\n"
19961 "Specify community to accept\n"
19962 EXTCOMMUNITY_VAL_STR)
19963 {
19964 int style = EXTCOMMUNITY_LIST_STANDARD;
19965 int direct = 0;
19966 char *cl_number_or_name = NULL;
19967 char *seq = NULL;
19968
19969 int idx = 0;
19970
19971 argv_find(argv, argc, "(1-99)", &idx);
19972 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19973 cl_number_or_name = argv[idx]->arg;
19974
19975 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19976 seq = argv[idx]->arg;
19977
19978 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19979 : COMMUNITY_DENY;
19980 argv_find(argv, argc, "AA:NN", &idx);
19981 char *str = argv_concat(argv, argc, idx);
19982
19983 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19984 direct, style);
19985
19986 XFREE(MTYPE_TMP, str);
19987
19988 if (ret < 0) {
19989 community_list_perror(vty, ret);
19990 return CMD_WARNING_CONFIG_FAILED;
19991 }
19992
19993 return CMD_SUCCESS;
19994 }
19995
19996 DEFUN (extcommunity_list_name_expanded,
19997 bgp_extcommunity_list_name_expanded_cmd,
19998 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
19999 BGP_STR
20000 EXTCOMMUNITY_LIST_STR
20001 "Extended Community list number (expanded)\n"
20002 "Specify expanded extcommunity-list\n"
20003 "Extended Community list name\n"
20004 "Sequence number of an entry\n"
20005 "Sequence number\n"
20006 "Specify community to reject\n"
20007 "Specify community to accept\n"
20008 "An ordered list as a regular-expression\n")
20009 {
20010 int style = EXTCOMMUNITY_LIST_EXPANDED;
20011 int direct = 0;
20012 char *cl_number_or_name = NULL;
20013 char *seq = NULL;
20014 int idx = 0;
20015
20016 argv_find(argv, argc, "(100-500)", &idx);
20017 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20018 cl_number_or_name = argv[idx]->arg;
20019
20020 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20021 seq = argv[idx]->arg;
20022
20023 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20024 : COMMUNITY_DENY;
20025 argv_find(argv, argc, "LINE", &idx);
20026 char *str = argv_concat(argv, argc, idx);
20027
20028 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20029 direct, style);
20030
20031 XFREE(MTYPE_TMP, str);
20032
20033 if (ret < 0) {
20034 community_list_perror(vty, ret);
20035 return CMD_WARNING_CONFIG_FAILED;
20036 }
20037
20038 return CMD_SUCCESS;
20039 }
20040
20041 DEFUN (no_extcommunity_list_standard_all,
20042 no_bgp_extcommunity_list_standard_all_cmd,
20043 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20044 NO_STR
20045 BGP_STR
20046 EXTCOMMUNITY_LIST_STR
20047 "Extended Community list number (standard)\n"
20048 "Specify standard extcommunity-list\n"
20049 "Community list name\n"
20050 "Sequence number of an entry\n"
20051 "Sequence number\n"
20052 "Specify community to reject\n"
20053 "Specify community to accept\n"
20054 EXTCOMMUNITY_VAL_STR)
20055 {
20056 int style = EXTCOMMUNITY_LIST_STANDARD;
20057 int direct = 0;
20058 char *cl_number_or_name = NULL;
20059 char *str = NULL;
20060 char *seq = NULL;
20061 int idx = 0;
20062
20063 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20064 seq = argv[idx]->arg;
20065
20066 idx = 0;
20067 argv_find(argv, argc, "permit", &idx);
20068 argv_find(argv, argc, "deny", &idx);
20069 if (idx) {
20070 direct = argv_find(argv, argc, "permit", &idx)
20071 ? COMMUNITY_PERMIT
20072 : COMMUNITY_DENY;
20073
20074 idx = 0;
20075 argv_find(argv, argc, "AA:NN", &idx);
20076 str = argv_concat(argv, argc, idx);
20077 }
20078
20079 idx = 0;
20080 argv_find(argv, argc, "(1-99)", &idx);
20081 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20082 cl_number_or_name = argv[idx]->arg;
20083
20084 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20085 seq, direct, style);
20086
20087 XFREE(MTYPE_TMP, str);
20088
20089 if (ret < 0) {
20090 community_list_perror(vty, ret);
20091 return CMD_WARNING_CONFIG_FAILED;
20092 }
20093
20094 return CMD_SUCCESS;
20095 }
20096
20097 ALIAS(no_extcommunity_list_standard_all,
20098 no_bgp_extcommunity_list_standard_all_list_cmd,
20099 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20100 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20101 "Extended Community list number (standard)\n"
20102 "Specify standard extcommunity-list\n"
20103 "Community list name\n")
20104
20105 DEFUN (no_extcommunity_list_expanded_all,
20106 no_bgp_extcommunity_list_expanded_all_cmd,
20107 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20108 NO_STR
20109 BGP_STR
20110 EXTCOMMUNITY_LIST_STR
20111 "Extended Community list number (expanded)\n"
20112 "Specify expanded extcommunity-list\n"
20113 "Extended Community list name\n"
20114 "Sequence number of an entry\n"
20115 "Sequence number\n"
20116 "Specify community to reject\n"
20117 "Specify community to accept\n"
20118 "An ordered list as a regular-expression\n")
20119 {
20120 int style = EXTCOMMUNITY_LIST_EXPANDED;
20121 int direct = 0;
20122 char *cl_number_or_name = NULL;
20123 char *str = NULL;
20124 char *seq = NULL;
20125 int idx = 0;
20126
20127 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20128 seq = argv[idx]->arg;
20129
20130 idx = 0;
20131 argv_find(argv, argc, "permit", &idx);
20132 argv_find(argv, argc, "deny", &idx);
20133
20134 if (idx) {
20135 direct = argv_find(argv, argc, "permit", &idx)
20136 ? COMMUNITY_PERMIT
20137 : COMMUNITY_DENY;
20138
20139 idx = 0;
20140 argv_find(argv, argc, "LINE", &idx);
20141 str = argv_concat(argv, argc, idx);
20142 }
20143
20144 idx = 0;
20145 argv_find(argv, argc, "(100-500)", &idx);
20146 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20147 cl_number_or_name = argv[idx]->arg;
20148
20149 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20150 seq, direct, style);
20151
20152 XFREE(MTYPE_TMP, str);
20153
20154 if (ret < 0) {
20155 community_list_perror(vty, ret);
20156 return CMD_WARNING_CONFIG_FAILED;
20157 }
20158
20159 return CMD_SUCCESS;
20160 }
20161
20162 ALIAS(no_extcommunity_list_expanded_all,
20163 no_bgp_extcommunity_list_expanded_all_list_cmd,
20164 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20165 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20166 "Extended Community list number (expanded)\n"
20167 "Specify expanded extcommunity-list\n"
20168 "Extended Community list name\n")
20169
20170 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20171 {
20172 struct community_entry *entry;
20173
20174 for (entry = list->head; entry; entry = entry->next) {
20175 if (entry == list->head) {
20176 if (all_digit(list->name))
20177 vty_out(vty, "Extended community %s list %s\n",
20178 entry->style == EXTCOMMUNITY_LIST_STANDARD
20179 ? "standard"
20180 : "(expanded) access",
20181 list->name);
20182 else
20183 vty_out(vty,
20184 "Named extended community %s list %s\n",
20185 entry->style == EXTCOMMUNITY_LIST_STANDARD
20186 ? "standard"
20187 : "expanded",
20188 list->name);
20189 }
20190 if (entry->any)
20191 vty_out(vty, " %s\n",
20192 community_direct_str(entry->direct));
20193 else
20194 vty_out(vty, " %s %s\n",
20195 community_direct_str(entry->direct),
20196 community_list_config_str(entry));
20197 }
20198 }
20199
20200 DEFUN (show_extcommunity_list,
20201 show_bgp_extcommunity_list_cmd,
20202 "show bgp extcommunity-list",
20203 SHOW_STR
20204 BGP_STR
20205 "List extended-community list\n")
20206 {
20207 struct community_list *list;
20208 struct community_list_master *cm;
20209
20210 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20211 if (!cm)
20212 return CMD_SUCCESS;
20213
20214 for (list = cm->num.head; list; list = list->next)
20215 extcommunity_list_show(vty, list);
20216
20217 for (list = cm->str.head; list; list = list->next)
20218 extcommunity_list_show(vty, list);
20219
20220 return CMD_SUCCESS;
20221 }
20222
20223 DEFUN (show_extcommunity_list_arg,
20224 show_bgp_extcommunity_list_arg_cmd,
20225 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20226 SHOW_STR
20227 BGP_STR
20228 "List extended-community list\n"
20229 "Extcommunity-list number\n"
20230 "Extcommunity-list name\n"
20231 "Detailed information on extcommunity-list\n")
20232 {
20233 int idx_comm_list = 3;
20234 struct community_list *list;
20235
20236 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20237 EXTCOMMUNITY_LIST_MASTER);
20238 if (!list) {
20239 vty_out(vty, "%% Can't find extcommunity-list\n");
20240 return CMD_WARNING;
20241 }
20242
20243 extcommunity_list_show(vty, list);
20244
20245 return CMD_SUCCESS;
20246 }
20247
20248 /* Display community-list and extcommunity-list configuration. */
20249 static int community_list_config_write(struct vty *vty)
20250 {
20251 struct community_list *list;
20252 struct community_entry *entry;
20253 struct community_list_master *cm;
20254 int write = 0;
20255
20256 /* Community-list. */
20257 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20258
20259 for (list = cm->num.head; list; list = list->next)
20260 for (entry = list->head; entry; entry = entry->next) {
20261 vty_out(vty,
20262 "bgp community-list %s seq %" PRId64 " %s %s\n",
20263 list->name, entry->seq,
20264 community_direct_str(entry->direct),
20265 community_list_config_str(entry));
20266 write++;
20267 }
20268 for (list = cm->str.head; list; list = list->next)
20269 for (entry = list->head; entry; entry = entry->next) {
20270 vty_out(vty,
20271 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20272 entry->style == COMMUNITY_LIST_STANDARD
20273 ? "standard"
20274 : "expanded",
20275 list->name, entry->seq,
20276 community_direct_str(entry->direct),
20277 community_list_config_str(entry));
20278 write++;
20279 }
20280
20281 /* Extcommunity-list. */
20282 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20283
20284 for (list = cm->num.head; list; list = list->next)
20285 for (entry = list->head; entry; entry = entry->next) {
20286 vty_out(vty,
20287 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20288 list->name, entry->seq,
20289 community_direct_str(entry->direct),
20290 community_list_config_str(entry));
20291 write++;
20292 }
20293 for (list = cm->str.head; list; list = list->next)
20294 for (entry = list->head; entry; entry = entry->next) {
20295 vty_out(vty,
20296 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20297 entry->style == EXTCOMMUNITY_LIST_STANDARD
20298 ? "standard"
20299 : "expanded",
20300 list->name, entry->seq,
20301 community_direct_str(entry->direct),
20302 community_list_config_str(entry));
20303 write++;
20304 }
20305
20306
20307 /* lcommunity-list. */
20308 cm = community_list_master_lookup(bgp_clist,
20309 LARGE_COMMUNITY_LIST_MASTER);
20310
20311 for (list = cm->num.head; list; list = list->next)
20312 for (entry = list->head; entry; entry = entry->next) {
20313 vty_out(vty,
20314 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20315 list->name, entry->seq,
20316 community_direct_str(entry->direct),
20317 community_list_config_str(entry));
20318 write++;
20319 }
20320 for (list = cm->str.head; list; list = list->next)
20321 for (entry = list->head; entry; entry = entry->next) {
20322 vty_out(vty,
20323 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20324
20325 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20326 ? "standard"
20327 : "expanded",
20328 list->name, entry->seq, community_direct_str(entry->direct),
20329 community_list_config_str(entry));
20330 write++;
20331 }
20332
20333 return write;
20334 }
20335
20336 static int community_list_config_write(struct vty *vty);
20337 static struct cmd_node community_list_node = {
20338 .name = "community list",
20339 .node = COMMUNITY_LIST_NODE,
20340 .prompt = "",
20341 .config_write = community_list_config_write,
20342 };
20343
20344 static void community_list_vty(void)
20345 {
20346 install_node(&community_list_node);
20347
20348 /* Community-list. */
20349 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20350 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20351 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20352 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20353 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20354 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20355 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20356 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20357
20358 /* Extcommunity-list. */
20359 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20360 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20361 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20362 install_element(CONFIG_NODE,
20363 &no_bgp_extcommunity_list_standard_all_list_cmd);
20364 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20365 install_element(CONFIG_NODE,
20366 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20367 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20368 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20369
20370 /* Large Community List */
20371 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20372 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20373 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20374 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20375 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20376 install_element(CONFIG_NODE,
20377 &no_bgp_lcommunity_list_name_standard_all_cmd);
20378 install_element(CONFIG_NODE,
20379 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20380 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20381 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20382 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20383 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20384 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20385 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20386
20387 bgp_community_list_command_completion_setup();
20388 }
20389
20390 static struct cmd_node community_alias_node = {
20391 .name = "community alias",
20392 .node = COMMUNITY_ALIAS_NODE,
20393 .prompt = "",
20394 .config_write = bgp_community_alias_write,
20395 };
20396
20397 void community_alias_vty(void)
20398 {
20399 install_node(&community_alias_node);
20400
20401 /* Community-list. */
20402 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20403
20404 bgp_community_alias_command_completion_setup();
20405 }