]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #11842 from opensourcerouting/fix/topotests_platform_check
[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 case BGP_ERR_INVALID_ROLE_NAME:
927 str = "Invalid role name";
928 break;
929 case BGP_ERR_INVALID_INTERNAL_ROLE:
930 str = "External roles can be set only on eBGP session";
931 break;
932 }
933 if (str) {
934 vty_out(vty, "%% %s\n", str);
935 return CMD_WARNING_CONFIG_FAILED;
936 }
937 return CMD_SUCCESS;
938 }
939
940 /* BGP clear sort. */
941 enum clear_sort {
942 clear_all,
943 clear_peer,
944 clear_group,
945 clear_external,
946 clear_as
947 };
948
949 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
950 safi_t safi, int error)
951 {
952 switch (error) {
953 case BGP_ERR_AF_UNCONFIGURED:
954 if (vty)
955 vty_out(vty,
956 "%% BGP: Enable %s address family for the neighbor %s\n",
957 get_afi_safi_str(afi, safi, false), peer->host);
958 else
959 zlog_warn(
960 "%% BGP: Enable %s address family for the neighbor %s",
961 get_afi_safi_str(afi, safi, false), peer->host);
962 break;
963 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
964 if (vty)
965 vty_out(vty,
966 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
967 peer->host);
968 else
969 zlog_warn(
970 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
971 peer->host);
972 break;
973 default:
974 break;
975 }
976 }
977
978 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
979 struct listnode **nnode, enum bgp_clear_type stype)
980 {
981 int ret = 0;
982 struct peer_af *paf;
983
984 /* if afi/.safi not specified, spin thru all of them */
985 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
986 afi_t tmp_afi;
987 safi_t tmp_safi;
988 enum bgp_af_index index;
989
990 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
991 paf = peer->peer_af_array[index];
992 if (!paf)
993 continue;
994
995 if (paf && paf->subgroup)
996 SET_FLAG(paf->subgroup->sflags,
997 SUBGRP_STATUS_FORCE_UPDATES);
998
999 tmp_afi = paf->afi;
1000 tmp_safi = paf->safi;
1001 if (!peer->afc[tmp_afi][tmp_safi])
1002 continue;
1003
1004 if (stype == BGP_CLEAR_SOFT_NONE)
1005 ret = peer_clear(peer, nnode);
1006 else
1007 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1008 stype);
1009 }
1010 /* if afi specified and safi not, spin thru safis on this afi */
1011 } else if (safi == SAFI_UNSPEC) {
1012 safi_t tmp_safi;
1013
1014 for (tmp_safi = SAFI_UNICAST;
1015 tmp_safi < SAFI_MAX; tmp_safi++) {
1016 if (!peer->afc[afi][tmp_safi])
1017 continue;
1018
1019 paf = peer_af_find(peer, afi, tmp_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,
1028 tmp_safi, stype);
1029 }
1030 /* both afi/safi specified, let the caller know if not defined */
1031 } else {
1032 if (!peer->afc[afi][safi])
1033 return 1;
1034
1035 paf = peer_af_find(peer, afi, safi);
1036 if (paf && paf->subgroup)
1037 SET_FLAG(paf->subgroup->sflags,
1038 SUBGRP_STATUS_FORCE_UPDATES);
1039
1040 if (stype == BGP_CLEAR_SOFT_NONE)
1041 ret = peer_clear(peer, nnode);
1042 else
1043 ret = peer_clear_soft(peer, afi, safi, stype);
1044 }
1045
1046 return ret;
1047 }
1048
1049 /* `clear ip bgp' functions. */
1050 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1051 enum clear_sort sort, enum bgp_clear_type stype,
1052 const char *arg)
1053 {
1054 int ret = 0;
1055 bool found = false;
1056 struct peer *peer;
1057
1058 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1059
1060 /* Clear all neighbors. */
1061 /*
1062 * Pass along pointer to next node to peer_clear() when walking all
1063 * nodes on the BGP instance as that may get freed if it is a
1064 * doppelganger
1065 */
1066 if (sort == clear_all) {
1067 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1068
1069 bgp_peer_gr_flags_update(peer);
1070
1071 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1072 gr_router_detected = true;
1073
1074 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1075 stype);
1076
1077 if (ret < 0)
1078 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1079 }
1080
1081 if (gr_router_detected
1082 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1083 bgp_zebra_send_capabilities(bgp, false);
1084 } else if (!gr_router_detected
1085 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1086 bgp_zebra_send_capabilities(bgp, true);
1087 }
1088
1089 /* This is to apply read-only mode on this clear. */
1090 if (stype == BGP_CLEAR_SOFT_NONE)
1091 bgp->update_delay_over = 0;
1092
1093 return CMD_SUCCESS;
1094 }
1095
1096 /* Clear specified neighbor. */
1097 if (sort == clear_peer) {
1098 union sockunion su;
1099
1100 /* Make sockunion for lookup. */
1101 ret = str2sockunion(arg, &su);
1102 if (ret < 0) {
1103 peer = peer_lookup_by_conf_if(bgp, arg);
1104 if (!peer) {
1105 peer = peer_lookup_by_hostname(bgp, arg);
1106 if (!peer) {
1107 vty_out(vty,
1108 "Malformed address or name: %s\n",
1109 arg);
1110 return CMD_WARNING;
1111 }
1112 }
1113 } else {
1114 peer = peer_lookup(bgp, &su);
1115 if (!peer) {
1116 vty_out(vty,
1117 "%% BGP: Unknown neighbor - \"%s\"\n",
1118 arg);
1119 return CMD_WARNING;
1120 }
1121 }
1122
1123 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1124 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1125
1126 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1127
1128 /* if afi/safi not defined for this peer, let caller know */
1129 if (ret == 1)
1130 ret = BGP_ERR_AF_UNCONFIGURED;
1131
1132 if (ret < 0)
1133 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1134
1135 return CMD_SUCCESS;
1136 }
1137
1138 /* Clear all neighbors belonging to a specific peer-group. */
1139 if (sort == clear_group) {
1140 struct peer_group *group;
1141
1142 group = peer_group_lookup(bgp, arg);
1143 if (!group) {
1144 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1145 return CMD_WARNING;
1146 }
1147
1148 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1149 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1150
1151 if (ret < 0)
1152 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1153 else
1154 found = true;
1155 }
1156
1157 if (!found)
1158 vty_out(vty,
1159 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1160 get_afi_safi_str(afi, safi, false), arg);
1161
1162 return CMD_SUCCESS;
1163 }
1164
1165 /* Clear all external (eBGP) neighbors. */
1166 if (sort == clear_external) {
1167 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1168 if (peer->sort == BGP_PEER_IBGP)
1169 continue;
1170
1171 bgp_peer_gr_flags_update(peer);
1172
1173 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1174 gr_router_detected = true;
1175
1176 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1177
1178 if (ret < 0)
1179 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1180 else
1181 found = true;
1182 }
1183
1184 if (gr_router_detected
1185 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1186 bgp_zebra_send_capabilities(bgp, false);
1187 } else if (!gr_router_detected
1188 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1189 bgp_zebra_send_capabilities(bgp, true);
1190 }
1191
1192 if (!found)
1193 vty_out(vty,
1194 "%% BGP: No external %s peer is configured\n",
1195 get_afi_safi_str(afi, safi, false));
1196
1197 return CMD_SUCCESS;
1198 }
1199
1200 /* Clear all neighbors belonging to a specific AS. */
1201 if (sort == clear_as) {
1202 as_t as = strtoul(arg, NULL, 10);
1203
1204 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1205 if (peer->as != as)
1206 continue;
1207
1208 bgp_peer_gr_flags_update(peer);
1209
1210 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1211 gr_router_detected = true;
1212
1213 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1214
1215 if (ret < 0)
1216 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1217 else
1218 found = true;
1219 }
1220
1221 if (gr_router_detected
1222 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1223 bgp_zebra_send_capabilities(bgp, false);
1224 } else if (!gr_router_detected
1225 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1226 bgp_zebra_send_capabilities(bgp, true);
1227 }
1228
1229 if (!found)
1230 vty_out(vty,
1231 "%% BGP: No %s peer is configured with AS %s\n",
1232 get_afi_safi_str(afi, safi, false), arg);
1233
1234 return CMD_SUCCESS;
1235 }
1236
1237 return CMD_SUCCESS;
1238 }
1239
1240 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1241 safi_t safi, enum clear_sort sort,
1242 enum bgp_clear_type stype, const char *arg)
1243 {
1244 struct bgp *bgp;
1245
1246 /* BGP structure lookup. */
1247 if (name) {
1248 bgp = bgp_lookup_by_name(name);
1249 if (bgp == NULL) {
1250 vty_out(vty, "Can't find BGP instance %s\n", name);
1251 return CMD_WARNING;
1252 }
1253 } else {
1254 bgp = bgp_get_default();
1255 if (bgp == NULL) {
1256 vty_out(vty, "No BGP process is configured\n");
1257 return CMD_WARNING;
1258 }
1259 }
1260
1261 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1262 }
1263
1264 /* clear soft inbound */
1265 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1266 {
1267 afi_t afi;
1268 safi_t safi;
1269
1270 FOREACH_AFI_SAFI (afi, safi)
1271 bgp_clear_vty(vty, name, afi, safi, clear_all,
1272 BGP_CLEAR_SOFT_IN, NULL);
1273 }
1274
1275 /* clear soft outbound */
1276 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1277 {
1278 afi_t afi;
1279 safi_t safi;
1280
1281 FOREACH_AFI_SAFI (afi, safi)
1282 bgp_clear_vty(vty, name, afi, safi, clear_all,
1283 BGP_CLEAR_SOFT_OUT, NULL);
1284 }
1285
1286
1287 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1288 {
1289 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1290 }
1291
1292 #ifndef VTYSH_EXTRACT_PL
1293 #include "bgpd/bgp_vty_clippy.c"
1294 #endif
1295
1296 DEFUN_HIDDEN (bgp_local_mac,
1297 bgp_local_mac_cmd,
1298 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1299 BGP_STR
1300 "Local MAC config\n"
1301 "VxLAN Network Identifier\n"
1302 "VNI number\n"
1303 "local mac\n"
1304 "mac address\n"
1305 "mac-mobility sequence\n"
1306 "seq number\n")
1307 {
1308 int rv;
1309 vni_t vni;
1310 struct ethaddr mac;
1311 struct ipaddr ip;
1312 uint32_t seq;
1313 struct bgp *bgp;
1314
1315 vni = strtoul(argv[3]->arg, NULL, 10);
1316 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1317 vty_out(vty, "%% Malformed MAC address\n");
1318 return CMD_WARNING;
1319 }
1320 memset(&ip, 0, sizeof(ip));
1321 seq = strtoul(argv[7]->arg, NULL, 10);
1322
1323 bgp = bgp_get_default();
1324 if (!bgp) {
1325 vty_out(vty, "Default BGP instance is not there\n");
1326 return CMD_WARNING;
1327 }
1328
1329 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1330 zero_esi);
1331 if (rv < 0) {
1332 vty_out(vty, "Internal error\n");
1333 return CMD_WARNING;
1334 }
1335
1336 return CMD_SUCCESS;
1337 }
1338
1339 DEFUN_HIDDEN (no_bgp_local_mac,
1340 no_bgp_local_mac_cmd,
1341 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1342 NO_STR
1343 BGP_STR
1344 "Local MAC config\n"
1345 "VxLAN Network Identifier\n"
1346 "VNI number\n"
1347 "local mac\n"
1348 "mac address\n")
1349 {
1350 int rv;
1351 vni_t vni;
1352 struct ethaddr mac;
1353 struct ipaddr ip;
1354 struct bgp *bgp;
1355
1356 vni = strtoul(argv[4]->arg, NULL, 10);
1357 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1358 vty_out(vty, "%% Malformed MAC address\n");
1359 return CMD_WARNING;
1360 }
1361 memset(&ip, 0, sizeof(ip));
1362
1363 bgp = bgp_get_default();
1364 if (!bgp) {
1365 vty_out(vty, "Default BGP instance is not there\n");
1366 return CMD_WARNING;
1367 }
1368
1369 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1370 if (rv < 0) {
1371 vty_out(vty, "Internal error\n");
1372 return CMD_WARNING;
1373 }
1374
1375 return CMD_SUCCESS;
1376 }
1377
1378 DEFUN (no_synchronization,
1379 no_synchronization_cmd,
1380 "no synchronization",
1381 NO_STR
1382 "Perform IGP synchronization\n")
1383 {
1384 return CMD_SUCCESS;
1385 }
1386
1387 DEFUN (no_auto_summary,
1388 no_auto_summary_cmd,
1389 "no auto-summary",
1390 NO_STR
1391 "Enable automatic network number summarization\n")
1392 {
1393 return CMD_SUCCESS;
1394 }
1395
1396 /* "router bgp" commands. */
1397 DEFUN_NOSH (router_bgp,
1398 router_bgp_cmd,
1399 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1400 ROUTER_STR
1401 BGP_STR
1402 AS_STR
1403 BGP_INSTANCE_HELP_STR)
1404 {
1405 int idx_asn = 2;
1406 int idx_view_vrf = 3;
1407 int idx_vrf = 4;
1408 int is_new_bgp = 0;
1409 int ret;
1410 as_t as;
1411 struct bgp *bgp;
1412 const char *name = NULL;
1413 enum bgp_instance_type inst_type;
1414
1415 // "router bgp" without an ASN
1416 if (argc == 2) {
1417 // Pending: Make VRF option available for ASN less config
1418 bgp = bgp_get_default();
1419
1420 if (bgp == NULL) {
1421 vty_out(vty, "%% No BGP process is configured\n");
1422 return CMD_WARNING_CONFIG_FAILED;
1423 }
1424
1425 if (listcount(bm->bgp) > 1) {
1426 vty_out(vty, "%% Please specify ASN and VRF\n");
1427 return CMD_WARNING_CONFIG_FAILED;
1428 }
1429 }
1430
1431 // "router bgp X"
1432 else {
1433 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1434
1435 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1436 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1437 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1438
1439 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1440 if (argc > 3) {
1441 name = argv[idx_vrf]->arg;
1442
1443 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1444 if (strmatch(name, VRF_DEFAULT_NAME))
1445 name = NULL;
1446 else
1447 inst_type = BGP_INSTANCE_TYPE_VRF;
1448 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1449 inst_type = BGP_INSTANCE_TYPE_VIEW;
1450 }
1451
1452 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1453 is_new_bgp = (bgp_lookup(as, name) == NULL);
1454
1455 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1456 switch (ret) {
1457 case BGP_ERR_AS_MISMATCH:
1458 vty_out(vty, "BGP is already running; AS is %u\n", as);
1459 return CMD_WARNING_CONFIG_FAILED;
1460 case BGP_ERR_INSTANCE_MISMATCH:
1461 vty_out(vty,
1462 "BGP instance name and AS number mismatch\n");
1463 vty_out(vty,
1464 "BGP instance is already running; AS is %u\n",
1465 as);
1466 return CMD_WARNING_CONFIG_FAILED;
1467 }
1468
1469 /*
1470 * If we just instantiated the default instance, complete
1471 * any pending VRF-VPN leaking that was configured via
1472 * earlier "router bgp X vrf FOO" blocks.
1473 */
1474 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1475 vpn_leak_postchange_all();
1476
1477 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1478 bgp_vpn_leak_export(bgp);
1479 /* Pending: handle when user tries to change a view to vrf n vv.
1480 */
1481 }
1482
1483 /* unset the auto created flag as the user config is now present */
1484 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1485 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1486
1487 return CMD_SUCCESS;
1488 }
1489
1490 /* "no router bgp" commands. */
1491 DEFUN (no_router_bgp,
1492 no_router_bgp_cmd,
1493 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1494 NO_STR
1495 ROUTER_STR
1496 BGP_STR
1497 AS_STR
1498 BGP_INSTANCE_HELP_STR)
1499 {
1500 int idx_asn = 3;
1501 int idx_vrf = 5;
1502 as_t as;
1503 struct bgp *bgp;
1504 const char *name = NULL;
1505
1506 // "no router bgp" without an ASN
1507 if (argc == 3) {
1508 // Pending: Make VRF option available for ASN less config
1509 bgp = bgp_get_default();
1510
1511 if (bgp == NULL) {
1512 vty_out(vty, "%% No BGP process is configured\n");
1513 return CMD_WARNING_CONFIG_FAILED;
1514 }
1515
1516 if (listcount(bm->bgp) > 1) {
1517 vty_out(vty, "%% Please specify ASN and VRF\n");
1518 return CMD_WARNING_CONFIG_FAILED;
1519 }
1520
1521 if (bgp->l3vni) {
1522 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1523 bgp->l3vni);
1524 return CMD_WARNING_CONFIG_FAILED;
1525 }
1526 } else {
1527 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1528
1529 if (argc > 4) {
1530 name = argv[idx_vrf]->arg;
1531 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1532 && strmatch(name, VRF_DEFAULT_NAME))
1533 name = NULL;
1534 }
1535
1536 /* Lookup bgp structure. */
1537 bgp = bgp_lookup(as, name);
1538 if (!bgp) {
1539 vty_out(vty, "%% Can't find BGP instance\n");
1540 return CMD_WARNING_CONFIG_FAILED;
1541 }
1542
1543 if (bgp->l3vni) {
1544 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1545 bgp->l3vni);
1546 return CMD_WARNING_CONFIG_FAILED;
1547 }
1548
1549 /* Cannot delete default instance if vrf instances exist */
1550 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1551 struct listnode *node;
1552 struct bgp *tmp_bgp;
1553
1554 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1555 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1556 continue;
1557 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1558 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1559 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1560 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1561 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1562 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1563 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1564 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1565 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1566 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1567 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1568 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1569 (bgp == bgp_get_evpn() &&
1570 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1571 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1572 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1573 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1574 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1575 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1576 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1577 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1578 (hashcount(tmp_bgp->vnihash))) {
1579 vty_out(vty,
1580 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1581 return CMD_WARNING_CONFIG_FAILED;
1582 }
1583 }
1584 }
1585 }
1586
1587 bgp_delete(bgp);
1588
1589 return CMD_SUCCESS;
1590 }
1591
1592 /* bgp session-dscp */
1593
1594 DEFPY (bgp_session_dscp,
1595 bgp_session_dscp_cmd,
1596 "bgp session-dscp (0-63)$dscp",
1597 BGP_STR
1598 "Override default (C6) bgp TCP session DSCP value\n"
1599 "Manually configured dscp parameter\n")
1600 {
1601 bm->tcp_dscp = dscp << 2;
1602
1603 return CMD_SUCCESS;
1604 }
1605
1606 DEFPY (no_bgp_session_dscp,
1607 no_bgp_session_dscp_cmd,
1608 "no bgp session-dscp [(0-63)]",
1609 NO_STR
1610 BGP_STR
1611 "Override default (C6) bgp TCP session DSCP value\n"
1612 "Manually configured dscp parameter\n")
1613 {
1614 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1615
1616 return CMD_SUCCESS;
1617 }
1618
1619 /* BGP router-id. */
1620
1621 DEFPY (bgp_router_id,
1622 bgp_router_id_cmd,
1623 "bgp router-id A.B.C.D",
1624 BGP_STR
1625 "Override configured router identifier\n"
1626 "Manually configured router identifier\n")
1627 {
1628 VTY_DECLVAR_CONTEXT(bgp, bgp);
1629 bgp_router_id_static_set(bgp, router_id);
1630 return CMD_SUCCESS;
1631 }
1632
1633 DEFPY (no_bgp_router_id,
1634 no_bgp_router_id_cmd,
1635 "no bgp router-id [A.B.C.D]",
1636 NO_STR
1637 BGP_STR
1638 "Override configured router identifier\n"
1639 "Manually configured router identifier\n")
1640 {
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642
1643 if (router_id_str) {
1644 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1645 vty_out(vty, "%% BGP router-id doesn't match\n");
1646 return CMD_WARNING_CONFIG_FAILED;
1647 }
1648 }
1649
1650 router_id.s_addr = 0;
1651 bgp_router_id_static_set(bgp, router_id);
1652
1653 return CMD_SUCCESS;
1654 }
1655
1656 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1657 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1658 NO_STR BGP_STR
1659 "Add community specific parameters\n"
1660 "Create an alias for a community\n"
1661 "Community (AA:BB or AA:BB:CC)\n"
1662 "Alias name\n")
1663 {
1664 struct community_alias ca = {};
1665 struct community_alias *lookup_community;
1666 struct community_alias *lookup_alias;
1667 struct community *comm;
1668 struct lcommunity *lcomm;
1669 uint8_t invalid = 0;
1670
1671 comm = community_str2com(community);
1672 if (!comm)
1673 invalid++;
1674 community_free(&comm);
1675
1676 lcomm = lcommunity_str2com(community);
1677 if (!lcomm)
1678 invalid++;
1679 lcommunity_free(&lcomm);
1680
1681 if (invalid > 1) {
1682 vty_out(vty, "Invalid community format\n");
1683 return CMD_WARNING;
1684 }
1685
1686 strlcpy(ca.community, community, sizeof(ca.community));
1687 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1688
1689 lookup_community = bgp_ca_community_lookup(&ca);
1690 lookup_alias = bgp_ca_alias_lookup(&ca);
1691
1692 if (no) {
1693 bgp_ca_alias_delete(&ca);
1694 bgp_ca_community_delete(&ca);
1695 } else {
1696 if (lookup_alias) {
1697 /* Lookup if community hash table has an item
1698 * with the same alias name.
1699 */
1700 strlcpy(ca.community, lookup_alias->community,
1701 sizeof(ca.community));
1702 if (bgp_ca_community_lookup(&ca)) {
1703 vty_out(vty,
1704 "community (%s) already has this alias (%s)\n",
1705 lookup_alias->community,
1706 lookup_alias->alias);
1707 return CMD_WARNING;
1708 }
1709 bgp_ca_alias_delete(&ca);
1710 }
1711
1712 if (lookup_community) {
1713 /* Lookup if alias hash table has an item
1714 * with the same community.
1715 */
1716 strlcpy(ca.alias, lookup_community->alias,
1717 sizeof(ca.alias));
1718 if (bgp_ca_alias_lookup(&ca)) {
1719 vty_out(vty,
1720 "alias (%s) already has this community (%s)\n",
1721 lookup_community->alias,
1722 lookup_community->community);
1723 return CMD_WARNING;
1724 }
1725 bgp_ca_community_delete(&ca);
1726 }
1727
1728 bgp_ca_alias_insert(&ca);
1729 bgp_ca_community_insert(&ca);
1730 }
1731
1732 return CMD_SUCCESS;
1733 }
1734
1735 DEFPY (bgp_global_suppress_fib_pending,
1736 bgp_global_suppress_fib_pending_cmd,
1737 "[no] bgp suppress-fib-pending",
1738 NO_STR
1739 BGP_STR
1740 "Advertise only routes that are programmed in kernel to peers globally\n")
1741 {
1742 bm_wait_for_fib_set(!no);
1743
1744 return CMD_SUCCESS;
1745 }
1746
1747 DEFPY (bgp_suppress_fib_pending,
1748 bgp_suppress_fib_pending_cmd,
1749 "[no] bgp suppress-fib-pending",
1750 NO_STR
1751 BGP_STR
1752 "Advertise only routes that are programmed in kernel to peers\n")
1753 {
1754 VTY_DECLVAR_CONTEXT(bgp, bgp);
1755
1756 bgp_suppress_fib_pending_set(bgp, !no);
1757 return CMD_SUCCESS;
1758 }
1759
1760
1761 /* BGP Cluster ID. */
1762 DEFUN (bgp_cluster_id,
1763 bgp_cluster_id_cmd,
1764 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1765 BGP_STR
1766 "Configure Route-Reflector Cluster-id\n"
1767 "Route-Reflector Cluster-id in IP address format\n"
1768 "Route-Reflector Cluster-id as 32 bit quantity\n")
1769 {
1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1771 int idx_ipv4 = 2;
1772 int ret;
1773 struct in_addr cluster;
1774
1775 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1776 if (!ret) {
1777 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1778 return CMD_WARNING_CONFIG_FAILED;
1779 }
1780
1781 bgp_cluster_id_set(bgp, &cluster);
1782 bgp_clear_star_soft_out(vty, bgp->name);
1783
1784 return CMD_SUCCESS;
1785 }
1786
1787 DEFUN (no_bgp_cluster_id,
1788 no_bgp_cluster_id_cmd,
1789 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1790 NO_STR
1791 BGP_STR
1792 "Configure Route-Reflector Cluster-id\n"
1793 "Route-Reflector Cluster-id in IP address format\n"
1794 "Route-Reflector Cluster-id as 32 bit quantity\n")
1795 {
1796 VTY_DECLVAR_CONTEXT(bgp, bgp);
1797 bgp_cluster_id_unset(bgp);
1798 bgp_clear_star_soft_out(vty, bgp->name);
1799
1800 return CMD_SUCCESS;
1801 }
1802
1803 DEFPY (bgp_norib,
1804 bgp_norib_cmd,
1805 "bgp no-rib",
1806 BGP_STR
1807 "Disable BGP route installation to RIB (Zebra)\n")
1808 {
1809 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1810 vty_out(vty,
1811 "%% No-RIB option is already set, nothing to do here.\n");
1812 return CMD_SUCCESS;
1813 }
1814
1815 bgp_option_norib_set_runtime();
1816
1817 return CMD_SUCCESS;
1818 }
1819
1820 DEFPY (no_bgp_norib,
1821 no_bgp_norib_cmd,
1822 "no bgp no-rib",
1823 NO_STR
1824 BGP_STR
1825 "Disable BGP route installation to RIB (Zebra)\n")
1826 {
1827 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1828 vty_out(vty,
1829 "%% No-RIB option is not set, nothing to do here.\n");
1830 return CMD_SUCCESS;
1831 }
1832
1833 bgp_option_norib_unset_runtime();
1834
1835 return CMD_SUCCESS;
1836 }
1837
1838 DEFPY (no_bgp_send_extra_data,
1839 no_bgp_send_extra_data_cmd,
1840 "[no] bgp send-extra-data zebra",
1841 NO_STR
1842 BGP_STR
1843 "Extra data to Zebra for display/use\n"
1844 "To zebra\n")
1845 {
1846 if (no)
1847 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1848 else
1849 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1850
1851 return CMD_SUCCESS;
1852 }
1853
1854 DEFUN (bgp_confederation_identifier,
1855 bgp_confederation_identifier_cmd,
1856 "bgp confederation identifier (1-4294967295)",
1857 BGP_STR
1858 "AS confederation parameters\n"
1859 "AS number\n"
1860 "Set routing domain confederation AS\n")
1861 {
1862 VTY_DECLVAR_CONTEXT(bgp, bgp);
1863 int idx_number = 3;
1864 as_t as;
1865
1866 as = strtoul(argv[idx_number]->arg, NULL, 10);
1867
1868 bgp_confederation_id_set(bgp, as);
1869
1870 return CMD_SUCCESS;
1871 }
1872
1873 DEFUN (no_bgp_confederation_identifier,
1874 no_bgp_confederation_identifier_cmd,
1875 "no bgp confederation identifier [(1-4294967295)]",
1876 NO_STR
1877 BGP_STR
1878 "AS confederation parameters\n"
1879 "AS number\n"
1880 "Set routing domain confederation AS\n")
1881 {
1882 VTY_DECLVAR_CONTEXT(bgp, bgp);
1883 bgp_confederation_id_unset(bgp);
1884
1885 return CMD_SUCCESS;
1886 }
1887
1888 DEFUN (bgp_confederation_peers,
1889 bgp_confederation_peers_cmd,
1890 "bgp confederation peers (1-4294967295)...",
1891 BGP_STR
1892 "AS confederation parameters\n"
1893 "Peer ASs in BGP confederation\n"
1894 AS_STR)
1895 {
1896 VTY_DECLVAR_CONTEXT(bgp, bgp);
1897 int idx_asn = 3;
1898 as_t as;
1899 int i;
1900
1901 for (i = idx_asn; i < argc; i++) {
1902 as = strtoul(argv[i]->arg, NULL, 10);
1903
1904 if (bgp->as == as) {
1905 vty_out(vty,
1906 "%% Local member-AS not allowed in confed peer list\n");
1907 continue;
1908 }
1909
1910 bgp_confederation_peers_add(bgp, as);
1911 }
1912 return CMD_SUCCESS;
1913 }
1914
1915 DEFUN (no_bgp_confederation_peers,
1916 no_bgp_confederation_peers_cmd,
1917 "no bgp confederation peers (1-4294967295)...",
1918 NO_STR
1919 BGP_STR
1920 "AS confederation parameters\n"
1921 "Peer ASs in BGP confederation\n"
1922 AS_STR)
1923 {
1924 VTY_DECLVAR_CONTEXT(bgp, bgp);
1925 int idx_asn = 4;
1926 as_t as;
1927 int i;
1928
1929 for (i = idx_asn; i < argc; i++) {
1930 as = strtoul(argv[i]->arg, NULL, 10);
1931
1932 bgp_confederation_peers_remove(bgp, as);
1933 }
1934 return CMD_SUCCESS;
1935 }
1936
1937 /**
1938 * Central routine for maximum-paths configuration.
1939 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1940 * @set: 1 for setting values, 0 for removing the max-paths config.
1941 */
1942 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1943 const char *mpaths, uint16_t options,
1944 int set)
1945 {
1946 VTY_DECLVAR_CONTEXT(bgp, bgp);
1947 uint16_t maxpaths = 0;
1948 int ret;
1949 afi_t afi;
1950 safi_t safi;
1951
1952 afi = bgp_node_afi(vty);
1953 safi = bgp_node_safi(vty);
1954
1955 if (set) {
1956 maxpaths = strtol(mpaths, NULL, 10);
1957 if (maxpaths > multipath_num) {
1958 vty_out(vty,
1959 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1960 maxpaths, multipath_num);
1961 return CMD_WARNING_CONFIG_FAILED;
1962 }
1963 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1964 options);
1965 } else
1966 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1967
1968 if (ret < 0) {
1969 vty_out(vty,
1970 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1971 (set == 1) ? "" : "un",
1972 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1973 maxpaths, afi, safi);
1974 return CMD_WARNING_CONFIG_FAILED;
1975 }
1976
1977 bgp_recalculate_all_bestpaths(bgp);
1978
1979 return CMD_SUCCESS;
1980 }
1981
1982 DEFUN (bgp_maxmed_admin,
1983 bgp_maxmed_admin_cmd,
1984 "bgp max-med administrative ",
1985 BGP_STR
1986 "Advertise routes with max-med\n"
1987 "Administratively applied, for an indefinite period\n")
1988 {
1989 VTY_DECLVAR_CONTEXT(bgp, bgp);
1990
1991 bgp->v_maxmed_admin = 1;
1992 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1993
1994 bgp_maxmed_update(bgp);
1995
1996 return CMD_SUCCESS;
1997 }
1998
1999 DEFUN (bgp_maxmed_admin_medv,
2000 bgp_maxmed_admin_medv_cmd,
2001 "bgp max-med administrative (0-4294967295)",
2002 BGP_STR
2003 "Advertise routes with max-med\n"
2004 "Administratively applied, for an indefinite period\n"
2005 "Max MED value to be used\n")
2006 {
2007 VTY_DECLVAR_CONTEXT(bgp, bgp);
2008 int idx_number = 3;
2009
2010 bgp->v_maxmed_admin = 1;
2011 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2012
2013 bgp_maxmed_update(bgp);
2014
2015 return CMD_SUCCESS;
2016 }
2017
2018 DEFUN (no_bgp_maxmed_admin,
2019 no_bgp_maxmed_admin_cmd,
2020 "no bgp max-med administrative [(0-4294967295)]",
2021 NO_STR
2022 BGP_STR
2023 "Advertise routes with max-med\n"
2024 "Administratively applied, for an indefinite period\n"
2025 "Max MED value to be used\n")
2026 {
2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
2028 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2029 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2030 bgp_maxmed_update(bgp);
2031
2032 return CMD_SUCCESS;
2033 }
2034
2035 DEFUN (bgp_maxmed_onstartup,
2036 bgp_maxmed_onstartup_cmd,
2037 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2038 BGP_STR
2039 "Advertise routes with max-med\n"
2040 "Effective on a startup\n"
2041 "Time (seconds) period for max-med\n"
2042 "Max MED value to be used\n")
2043 {
2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 int idx = 0;
2046
2047 if (argv_find(argv, argc, "(5-86400)", &idx))
2048 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2049 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2050 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2051 else
2052 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2053
2054 bgp_maxmed_update(bgp);
2055
2056 return CMD_SUCCESS;
2057 }
2058
2059 DEFUN (no_bgp_maxmed_onstartup,
2060 no_bgp_maxmed_onstartup_cmd,
2061 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2062 NO_STR
2063 BGP_STR
2064 "Advertise routes with max-med\n"
2065 "Effective on a startup\n"
2066 "Time (seconds) period for max-med\n"
2067 "Max MED value to be used\n")
2068 {
2069 VTY_DECLVAR_CONTEXT(bgp, bgp);
2070
2071 /* Cancel max-med onstartup if its on */
2072 if (bgp->t_maxmed_onstartup) {
2073 THREAD_OFF(bgp->t_maxmed_onstartup);
2074 bgp->maxmed_onstartup_over = 1;
2075 }
2076
2077 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2078 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2079
2080 bgp_maxmed_update(bgp);
2081
2082 return CMD_SUCCESS;
2083 }
2084
2085 static int bgp_global_update_delay_config_vty(struct vty *vty,
2086 uint16_t update_delay,
2087 uint16_t establish_wait)
2088 {
2089 struct listnode *node, *nnode;
2090 struct bgp *bgp;
2091 bool vrf_cfg = false;
2092
2093 /*
2094 * See if update-delay is set per-vrf and warn user to delete it
2095 * Note that we only need to check this if this is the first time
2096 * setting the global config.
2097 */
2098 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2099 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2100 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2101 vty_out(vty,
2102 "%% update-delay configuration found in vrf %s\n",
2103 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2104 ? VRF_DEFAULT_NAME
2105 : bgp->name);
2106 vrf_cfg = true;
2107 }
2108 }
2109 }
2110
2111 if (vrf_cfg) {
2112 vty_out(vty,
2113 "%%Failed: global update-delay config not permitted\n");
2114 return CMD_WARNING;
2115 }
2116
2117 if (!establish_wait) { /* update-delay <delay> */
2118 bm->v_update_delay = update_delay;
2119 bm->v_establish_wait = bm->v_update_delay;
2120 } else {
2121 /* update-delay <delay> <establish-wait> */
2122 if (update_delay < establish_wait) {
2123 vty_out(vty,
2124 "%%Failed: update-delay less than the establish-wait!\n");
2125 return CMD_WARNING_CONFIG_FAILED;
2126 }
2127
2128 bm->v_update_delay = update_delay;
2129 bm->v_establish_wait = establish_wait;
2130 }
2131
2132 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2133 bgp->v_update_delay = bm->v_update_delay;
2134 bgp->v_establish_wait = bm->v_establish_wait;
2135 }
2136
2137 return CMD_SUCCESS;
2138 }
2139
2140 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2141 {
2142 struct listnode *node, *nnode;
2143 struct bgp *bgp;
2144
2145 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2146 bm->v_establish_wait = bm->v_update_delay;
2147
2148 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2149 bgp->v_update_delay = bm->v_update_delay;
2150 bgp->v_establish_wait = bm->v_establish_wait;
2151 }
2152
2153 return CMD_SUCCESS;
2154 }
2155
2156 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2157 uint16_t establish_wait)
2158 {
2159 VTY_DECLVAR_CONTEXT(bgp, bgp);
2160
2161 /* if configured globally, per-instance config is not allowed */
2162 if (bm->v_update_delay) {
2163 vty_out(vty,
2164 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2165 return CMD_WARNING_CONFIG_FAILED;
2166 }
2167
2168
2169 if (!establish_wait) /* update-delay <delay> */
2170 {
2171 bgp->v_update_delay = update_delay;
2172 bgp->v_establish_wait = bgp->v_update_delay;
2173 return CMD_SUCCESS;
2174 }
2175
2176 /* update-delay <delay> <establish-wait> */
2177 if (update_delay < establish_wait) {
2178 vty_out(vty,
2179 "%%Failed: update-delay less than the establish-wait!\n");
2180 return CMD_WARNING_CONFIG_FAILED;
2181 }
2182
2183 bgp->v_update_delay = update_delay;
2184 bgp->v_establish_wait = establish_wait;
2185
2186 return CMD_SUCCESS;
2187 }
2188
2189 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2190 {
2191 VTY_DECLVAR_CONTEXT(bgp, bgp);
2192
2193 /* If configured globally, cannot remove from one bgp instance */
2194 if (bm->v_update_delay) {
2195 vty_out(vty,
2196 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2197 return CMD_WARNING_CONFIG_FAILED;
2198 }
2199 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2200 bgp->v_establish_wait = bgp->v_update_delay;
2201
2202 return CMD_SUCCESS;
2203 }
2204
2205 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2206 {
2207 /* If configured globally, no need to display per-instance value */
2208 if (bgp->v_update_delay != bm->v_update_delay) {
2209 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2210 if (bgp->v_update_delay != bgp->v_establish_wait)
2211 vty_out(vty, " %d", bgp->v_establish_wait);
2212 vty_out(vty, "\n");
2213 }
2214 }
2215
2216 /* Global update-delay configuration */
2217 DEFPY (bgp_global_update_delay,
2218 bgp_global_update_delay_cmd,
2219 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2220 BGP_STR
2221 "Force initial delay for best-path and updates for all bgp instances\n"
2222 "Max delay in seconds\n"
2223 "Establish wait in seconds\n")
2224 {
2225 return bgp_global_update_delay_config_vty(vty, delay, wait);
2226 }
2227
2228 /* Global update-delay deconfiguration */
2229 DEFPY (no_bgp_global_update_delay,
2230 no_bgp_global_update_delay_cmd,
2231 "no bgp update-delay [(0-3600) [(1-3600)]]",
2232 NO_STR
2233 BGP_STR
2234 "Force initial delay for best-path and updates\n"
2235 "Max delay in seconds\n"
2236 "Establish wait in seconds\n")
2237 {
2238 return bgp_global_update_delay_deconfig_vty(vty);
2239 }
2240
2241 /* Update-delay configuration */
2242
2243 DEFPY (bgp_update_delay,
2244 bgp_update_delay_cmd,
2245 "update-delay (0-3600)$delay [(1-3600)$wait]",
2246 "Force initial delay for best-path and updates\n"
2247 "Max delay in seconds\n"
2248 "Establish wait in seconds\n")
2249 {
2250 return bgp_update_delay_config_vty(vty, delay, wait);
2251 }
2252
2253 /* Update-delay deconfiguration */
2254 DEFPY (no_bgp_update_delay,
2255 no_bgp_update_delay_cmd,
2256 "no update-delay [(0-3600) [(1-3600)]]",
2257 NO_STR
2258 "Force initial delay for best-path and updates\n"
2259 "Max delay in seconds\n"
2260 "Establish wait in seconds\n")
2261 {
2262 return bgp_update_delay_deconfig_vty(vty);
2263 }
2264
2265
2266 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2267 bool set)
2268 {
2269 VTY_DECLVAR_CONTEXT(bgp, bgp);
2270
2271 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2272 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2273
2274 return CMD_SUCCESS;
2275 }
2276
2277 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2278 bool set)
2279 {
2280 VTY_DECLVAR_CONTEXT(bgp, bgp);
2281
2282 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2283 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2284
2285 return CMD_SUCCESS;
2286 }
2287
2288 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2289 {
2290 uint32_t quanta =
2291 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2292 if (quanta != BGP_WRITE_PACKET_MAX)
2293 vty_out(vty, " write-quanta %d\n", quanta);
2294 }
2295
2296 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2297 {
2298 uint32_t quanta =
2299 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2300 if (quanta != BGP_READ_PACKET_MAX)
2301 vty_out(vty, " read-quanta %d\n", quanta);
2302 }
2303
2304 /* Packet quanta configuration
2305 *
2306 * XXX: The value set here controls the size of a stack buffer in the IO
2307 * thread. When changing these limits be careful to prevent stack overflow.
2308 *
2309 * Furthermore, the maximums used here should correspond to
2310 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2311 */
2312 DEFPY (bgp_wpkt_quanta,
2313 bgp_wpkt_quanta_cmd,
2314 "[no] write-quanta (1-64)$quanta",
2315 NO_STR
2316 "How many packets to write to peer socket per run\n"
2317 "Number of packets\n")
2318 {
2319 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2320 }
2321
2322 DEFPY (bgp_rpkt_quanta,
2323 bgp_rpkt_quanta_cmd,
2324 "[no] read-quanta (1-10)$quanta",
2325 NO_STR
2326 "How many packets to read from peer socket per I/O cycle\n"
2327 "Number of packets\n")
2328 {
2329 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2330 }
2331
2332 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2333 {
2334 if (!bgp->heuristic_coalesce)
2335 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2336 }
2337
2338
2339 DEFUN (bgp_coalesce_time,
2340 bgp_coalesce_time_cmd,
2341 "coalesce-time (0-4294967295)",
2342 "Subgroup coalesce timer\n"
2343 "Subgroup coalesce timer value (in ms)\n")
2344 {
2345 VTY_DECLVAR_CONTEXT(bgp, bgp);
2346
2347 int idx = 0;
2348
2349 bgp->heuristic_coalesce = false;
2350
2351 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2352 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2353
2354 return CMD_SUCCESS;
2355 }
2356
2357 DEFUN (no_bgp_coalesce_time,
2358 no_bgp_coalesce_time_cmd,
2359 "no coalesce-time (0-4294967295)",
2360 NO_STR
2361 "Subgroup coalesce timer\n"
2362 "Subgroup coalesce timer value (in ms)\n")
2363 {
2364 VTY_DECLVAR_CONTEXT(bgp, bgp);
2365
2366 bgp->heuristic_coalesce = true;
2367 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2368 return CMD_SUCCESS;
2369 }
2370
2371 /* Maximum-paths configuration */
2372 DEFUN (bgp_maxpaths,
2373 bgp_maxpaths_cmd,
2374 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2375 "Forward packets over multiple paths\n"
2376 "Number of paths\n")
2377 {
2378 int idx_number = 1;
2379 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2380 argv[idx_number]->arg, 0, 1);
2381 }
2382
2383 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2384 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2385 "Forward packets over multiple paths\n"
2386 "Number of paths\n")
2387
2388 DEFUN (bgp_maxpaths_ibgp,
2389 bgp_maxpaths_ibgp_cmd,
2390 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2391 "Forward packets over multiple paths\n"
2392 "iBGP-multipath\n"
2393 "Number of paths\n")
2394 {
2395 int idx_number = 2;
2396 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2397 argv[idx_number]->arg, 0, 1);
2398 }
2399
2400 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2401 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2402 "Forward packets over multiple paths\n"
2403 "iBGP-multipath\n"
2404 "Number of paths\n")
2405
2406 DEFUN (bgp_maxpaths_ibgp_cluster,
2407 bgp_maxpaths_ibgp_cluster_cmd,
2408 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2409 "Forward packets over multiple paths\n"
2410 "iBGP-multipath\n"
2411 "Number of paths\n"
2412 "Match the cluster length\n")
2413 {
2414 int idx_number = 2;
2415 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2416 argv[idx_number]->arg, true, 1);
2417 }
2418
2419 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2420 "maximum-paths ibgp " CMD_RANGE_STR(
2421 1, MULTIPATH_NUM) " equal-cluster-length",
2422 "Forward packets over multiple paths\n"
2423 "iBGP-multipath\n"
2424 "Number of paths\n"
2425 "Match the cluster length\n")
2426
2427 DEFUN (no_bgp_maxpaths,
2428 no_bgp_maxpaths_cmd,
2429 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2430 NO_STR
2431 "Forward packets over multiple paths\n"
2432 "Number of paths\n")
2433 {
2434 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2435 }
2436
2437 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2438 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2439 "Forward packets over multiple paths\n"
2440 "Number of paths\n")
2441
2442 DEFUN (no_bgp_maxpaths_ibgp,
2443 no_bgp_maxpaths_ibgp_cmd,
2444 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2445 NO_STR
2446 "Forward packets over multiple paths\n"
2447 "iBGP-multipath\n"
2448 "Number of paths\n"
2449 "Match the cluster length\n")
2450 {
2451 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2452 }
2453
2454 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2455 "no maximum-paths ibgp [" CMD_RANGE_STR(
2456 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2457 NO_STR
2458 "Forward packets over multiple paths\n"
2459 "iBGP-multipath\n"
2460 "Number of paths\n"
2461 "Match the cluster length\n")
2462
2463 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2464 afi_t afi, safi_t safi)
2465 {
2466 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2467 vty_out(vty, " maximum-paths %d\n",
2468 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2469 }
2470
2471 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2472 vty_out(vty, " maximum-paths ibgp %d",
2473 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2474 if (bgp->maxpaths[afi][safi].same_clusterlen)
2475 vty_out(vty, " equal-cluster-length");
2476 vty_out(vty, "\n");
2477 }
2478 }
2479
2480 /* BGP timers. */
2481
2482 DEFUN (bgp_timers,
2483 bgp_timers_cmd,
2484 "timers bgp (0-65535) (0-65535)",
2485 "Adjust routing timers\n"
2486 "BGP timers\n"
2487 "Keepalive interval\n"
2488 "Holdtime\n")
2489 {
2490 VTY_DECLVAR_CONTEXT(bgp, bgp);
2491 int idx_number = 2;
2492 int idx_number_2 = 3;
2493 unsigned long keepalive = 0;
2494 unsigned long holdtime = 0;
2495
2496 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2497 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2498
2499 /* Holdtime value check. */
2500 if (holdtime < 3 && holdtime != 0) {
2501 vty_out(vty,
2502 "%% hold time value must be either 0 or greater than 3\n");
2503 return CMD_WARNING_CONFIG_FAILED;
2504 }
2505
2506 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2507 BGP_DEFAULT_DELAYOPEN);
2508
2509 return CMD_SUCCESS;
2510 }
2511
2512 DEFUN (no_bgp_timers,
2513 no_bgp_timers_cmd,
2514 "no timers bgp [(0-65535) (0-65535)]",
2515 NO_STR
2516 "Adjust routing timers\n"
2517 "BGP timers\n"
2518 "Keepalive interval\n"
2519 "Holdtime\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2523 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2524
2525 return CMD_SUCCESS;
2526 }
2527
2528 /* BGP minimum holdtime. */
2529
2530 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2531 "bgp minimum-holdtime (1-65535)",
2532 "BGP specific commands\n"
2533 "BGP minimum holdtime\n"
2534 "Seconds\n")
2535 {
2536 VTY_DECLVAR_CONTEXT(bgp, bgp);
2537 int idx_number = 2;
2538 unsigned long min_holdtime;
2539
2540 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2541
2542 bgp->default_min_holdtime = min_holdtime;
2543
2544 return CMD_SUCCESS;
2545 }
2546
2547 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2548 "no bgp minimum-holdtime [(1-65535)]",
2549 NO_STR
2550 "BGP specific commands\n"
2551 "BGP minimum holdtime\n"
2552 "Seconds\n")
2553 {
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555
2556 bgp->default_min_holdtime = 0;
2557
2558 return CMD_SUCCESS;
2559 }
2560
2561 DEFUN (bgp_client_to_client_reflection,
2562 bgp_client_to_client_reflection_cmd,
2563 "bgp client-to-client reflection",
2564 BGP_STR
2565 "Configure client to client route reflection\n"
2566 "reflection of routes allowed\n")
2567 {
2568 VTY_DECLVAR_CONTEXT(bgp, bgp);
2569 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2570 bgp_clear_star_soft_out(vty, bgp->name);
2571
2572 return CMD_SUCCESS;
2573 }
2574
2575 DEFUN (no_bgp_client_to_client_reflection,
2576 no_bgp_client_to_client_reflection_cmd,
2577 "no bgp client-to-client reflection",
2578 NO_STR
2579 BGP_STR
2580 "Configure client to client route reflection\n"
2581 "reflection of routes allowed\n")
2582 {
2583 VTY_DECLVAR_CONTEXT(bgp, bgp);
2584 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2585 bgp_clear_star_soft_out(vty, bgp->name);
2586
2587 return CMD_SUCCESS;
2588 }
2589
2590 /* "bgp always-compare-med" configuration. */
2591 DEFUN (bgp_always_compare_med,
2592 bgp_always_compare_med_cmd,
2593 "bgp always-compare-med",
2594 BGP_STR
2595 "Allow comparing MED from different neighbors\n")
2596 {
2597 VTY_DECLVAR_CONTEXT(bgp, bgp);
2598 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2599 bgp_recalculate_all_bestpaths(bgp);
2600
2601 return CMD_SUCCESS;
2602 }
2603
2604 DEFUN (no_bgp_always_compare_med,
2605 no_bgp_always_compare_med_cmd,
2606 "no bgp always-compare-med",
2607 NO_STR
2608 BGP_STR
2609 "Allow comparing MED from different neighbors\n")
2610 {
2611 VTY_DECLVAR_CONTEXT(bgp, bgp);
2612 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2613 bgp_recalculate_all_bestpaths(bgp);
2614
2615 return CMD_SUCCESS;
2616 }
2617
2618
2619 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2620 "bgp ebgp-requires-policy",
2621 BGP_STR
2622 "Require in and out policy for eBGP peers (RFC8212)\n")
2623 {
2624 VTY_DECLVAR_CONTEXT(bgp, bgp);
2625 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2626 return CMD_SUCCESS;
2627 }
2628
2629 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2630 "no bgp ebgp-requires-policy",
2631 NO_STR
2632 BGP_STR
2633 "Require in and out policy for eBGP peers (RFC8212)\n")
2634 {
2635 VTY_DECLVAR_CONTEXT(bgp, bgp);
2636 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2637 return CMD_SUCCESS;
2638 }
2639
2640 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2641 "bgp suppress-duplicates",
2642 BGP_STR
2643 "Suppress duplicate updates if the route actually not changed\n")
2644 {
2645 VTY_DECLVAR_CONTEXT(bgp, bgp);
2646 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2647 return CMD_SUCCESS;
2648 }
2649
2650 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2651 "no bgp suppress-duplicates",
2652 NO_STR
2653 BGP_STR
2654 "Suppress duplicate updates if the route actually not changed\n")
2655 {
2656 VTY_DECLVAR_CONTEXT(bgp, bgp);
2657 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2658 return CMD_SUCCESS;
2659 }
2660
2661 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2662 "bgp reject-as-sets",
2663 BGP_STR
2664 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2665 {
2666 VTY_DECLVAR_CONTEXT(bgp, bgp);
2667 struct listnode *node, *nnode;
2668 struct peer *peer;
2669
2670 bgp->reject_as_sets = true;
2671
2672 /* Reset existing BGP sessions to reject routes
2673 * with aspath containing AS_SET or AS_CONFED_SET.
2674 */
2675 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2676 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2677 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2678 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2679 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2680 }
2681 }
2682
2683 return CMD_SUCCESS;
2684 }
2685
2686 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2687 "no bgp reject-as-sets",
2688 NO_STR
2689 BGP_STR
2690 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2691 {
2692 VTY_DECLVAR_CONTEXT(bgp, bgp);
2693 struct listnode *node, *nnode;
2694 struct peer *peer;
2695
2696 bgp->reject_as_sets = false;
2697
2698 /* Reset existing BGP sessions to reject routes
2699 * with aspath containing AS_SET or AS_CONFED_SET.
2700 */
2701 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2702 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2703 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2704 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2705 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2706 }
2707 }
2708
2709 return CMD_SUCCESS;
2710 }
2711
2712 /* "bgp deterministic-med" configuration. */
2713 DEFUN (bgp_deterministic_med,
2714 bgp_deterministic_med_cmd,
2715 "bgp deterministic-med",
2716 BGP_STR
2717 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2718 {
2719 VTY_DECLVAR_CONTEXT(bgp, bgp);
2720
2721 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2722 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2723 bgp_recalculate_all_bestpaths(bgp);
2724 }
2725
2726 return CMD_SUCCESS;
2727 }
2728
2729 DEFUN (no_bgp_deterministic_med,
2730 no_bgp_deterministic_med_cmd,
2731 "no bgp deterministic-med",
2732 NO_STR
2733 BGP_STR
2734 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2735 {
2736 VTY_DECLVAR_CONTEXT(bgp, bgp);
2737 int bestpath_per_as_used;
2738 afi_t afi;
2739 safi_t safi;
2740 struct peer *peer;
2741 struct listnode *node, *nnode;
2742
2743 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2744 bestpath_per_as_used = 0;
2745
2746 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2747 FOREACH_AFI_SAFI (afi, safi)
2748 if (bgp_addpath_dmed_required(
2749 peer->addpath_type[afi][safi])) {
2750 bestpath_per_as_used = 1;
2751 break;
2752 }
2753
2754 if (bestpath_per_as_used)
2755 break;
2756 }
2757
2758 if (bestpath_per_as_used) {
2759 vty_out(vty,
2760 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2761 return CMD_WARNING_CONFIG_FAILED;
2762 } else {
2763 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2764 bgp_recalculate_all_bestpaths(bgp);
2765 }
2766 }
2767
2768 return CMD_SUCCESS;
2769 }
2770
2771 /* "bgp graceful-restart mode" configuration. */
2772 DEFUN (bgp_graceful_restart,
2773 bgp_graceful_restart_cmd,
2774 "bgp graceful-restart",
2775 BGP_STR
2776 GR_CMD
2777 )
2778 {
2779 int ret = BGP_GR_FAILURE;
2780
2781 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2782 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2783
2784 VTY_DECLVAR_CONTEXT(bgp, bgp);
2785
2786 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2787
2788 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2789 ret);
2790
2791 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2792 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2793 vty_out(vty,
2794 "Graceful restart configuration changed, reset all peers to take effect\n");
2795 return bgp_vty_return(vty, ret);
2796 }
2797
2798 DEFUN (no_bgp_graceful_restart,
2799 no_bgp_graceful_restart_cmd,
2800 "no bgp graceful-restart",
2801 NO_STR
2802 BGP_STR
2803 NO_GR_CMD
2804 )
2805 {
2806 VTY_DECLVAR_CONTEXT(bgp, bgp);
2807
2808 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2809 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2810
2811 int ret = BGP_GR_FAILURE;
2812
2813 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2814
2815 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2816 ret);
2817
2818 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2819 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2820 vty_out(vty,
2821 "Graceful restart configuration changed, reset all peers to take effect\n");
2822
2823 return bgp_vty_return(vty, ret);
2824 }
2825
2826 DEFUN (bgp_graceful_restart_stalepath_time,
2827 bgp_graceful_restart_stalepath_time_cmd,
2828 "bgp graceful-restart stalepath-time (1-4095)",
2829 BGP_STR
2830 "Graceful restart capability parameters\n"
2831 "Set the max time to hold onto restarting peer's stale paths\n"
2832 "Delay value (seconds)\n")
2833 {
2834 VTY_DECLVAR_CONTEXT(bgp, bgp);
2835 int idx_number = 3;
2836 uint32_t stalepath;
2837
2838 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2839 bgp->stalepath_time = stalepath;
2840 return CMD_SUCCESS;
2841 }
2842
2843 DEFUN (bgp_graceful_restart_restart_time,
2844 bgp_graceful_restart_restart_time_cmd,
2845 "bgp graceful-restart restart-time (0-4095)",
2846 BGP_STR
2847 "Graceful restart capability parameters\n"
2848 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2849 "Delay value (seconds)\n")
2850 {
2851 VTY_DECLVAR_CONTEXT(bgp, bgp);
2852 int idx_number = 3;
2853 uint32_t restart;
2854
2855 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2856 bgp->restart_time = restart;
2857 return CMD_SUCCESS;
2858 }
2859
2860 DEFUN (bgp_graceful_restart_select_defer_time,
2861 bgp_graceful_restart_select_defer_time_cmd,
2862 "bgp graceful-restart select-defer-time (0-3600)",
2863 BGP_STR
2864 "Graceful restart capability parameters\n"
2865 "Set the time to defer the BGP route selection after restart\n"
2866 "Delay value (seconds, 0 - disable)\n")
2867 {
2868 VTY_DECLVAR_CONTEXT(bgp, bgp);
2869 int idx_number = 3;
2870 uint32_t defer_time;
2871
2872 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2873 bgp->select_defer_time = defer_time;
2874 if (defer_time == 0)
2875 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2876 else
2877 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2878
2879 return CMD_SUCCESS;
2880 }
2881
2882 DEFUN (no_bgp_graceful_restart_stalepath_time,
2883 no_bgp_graceful_restart_stalepath_time_cmd,
2884 "no bgp graceful-restart stalepath-time [(1-4095)]",
2885 NO_STR
2886 BGP_STR
2887 "Graceful restart capability parameters\n"
2888 "Set the max time to hold onto restarting peer's stale paths\n"
2889 "Delay value (seconds)\n")
2890 {
2891 VTY_DECLVAR_CONTEXT(bgp, bgp);
2892
2893 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2894 return CMD_SUCCESS;
2895 }
2896
2897 DEFUN (no_bgp_graceful_restart_restart_time,
2898 no_bgp_graceful_restart_restart_time_cmd,
2899 "no bgp graceful-restart restart-time [(0-4095)]",
2900 NO_STR
2901 BGP_STR
2902 "Graceful restart capability parameters\n"
2903 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2904 "Delay value (seconds)\n")
2905 {
2906 VTY_DECLVAR_CONTEXT(bgp, bgp);
2907
2908 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2909 return CMD_SUCCESS;
2910 }
2911
2912 DEFUN (no_bgp_graceful_restart_select_defer_time,
2913 no_bgp_graceful_restart_select_defer_time_cmd,
2914 "no bgp graceful-restart select-defer-time [(0-3600)]",
2915 NO_STR
2916 BGP_STR
2917 "Graceful restart capability parameters\n"
2918 "Set the time to defer the BGP route selection after restart\n"
2919 "Delay value (seconds)\n")
2920 {
2921 VTY_DECLVAR_CONTEXT(bgp, bgp);
2922
2923 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2924 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2925
2926 return CMD_SUCCESS;
2927 }
2928
2929 DEFUN (bgp_graceful_restart_preserve_fw,
2930 bgp_graceful_restart_preserve_fw_cmd,
2931 "bgp graceful-restart preserve-fw-state",
2932 BGP_STR
2933 "Graceful restart capability parameters\n"
2934 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2935 {
2936 VTY_DECLVAR_CONTEXT(bgp, bgp);
2937 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2938 return CMD_SUCCESS;
2939 }
2940
2941 DEFUN (no_bgp_graceful_restart_preserve_fw,
2942 no_bgp_graceful_restart_preserve_fw_cmd,
2943 "no bgp graceful-restart preserve-fw-state",
2944 NO_STR
2945 BGP_STR
2946 "Graceful restart capability parameters\n"
2947 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2948 {
2949 VTY_DECLVAR_CONTEXT(bgp, bgp);
2950 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2951 return CMD_SUCCESS;
2952 }
2953
2954 DEFPY (bgp_graceful_restart_notification,
2955 bgp_graceful_restart_notification_cmd,
2956 "[no$no] bgp graceful-restart notification",
2957 NO_STR
2958 BGP_STR
2959 "Graceful restart capability parameters\n"
2960 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2961 {
2962 VTY_DECLVAR_CONTEXT(bgp, bgp);
2963
2964 if (no)
2965 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2966 else
2967 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2968
2969 return CMD_SUCCESS;
2970 }
2971
2972 DEFPY (bgp_administrative_reset,
2973 bgp_administrative_reset_cmd,
2974 "[no$no] bgp hard-administrative-reset",
2975 NO_STR
2976 BGP_STR
2977 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2978 {
2979 VTY_DECLVAR_CONTEXT(bgp, bgp);
2980
2981 if (no)
2982 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2983 else
2984 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2985
2986 return CMD_SUCCESS;
2987 }
2988
2989 DEFUN (bgp_graceful_restart_disable,
2990 bgp_graceful_restart_disable_cmd,
2991 "bgp graceful-restart-disable",
2992 BGP_STR
2993 GR_DISABLE)
2994 {
2995 int ret = BGP_GR_FAILURE;
2996
2997 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2998 zlog_debug(
2999 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3000
3001 VTY_DECLVAR_CONTEXT(bgp, bgp);
3002
3003 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3004
3005 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3006 bgp->peer, ret);
3007
3008 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3009 zlog_debug(
3010 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3011 vty_out(vty,
3012 "Graceful restart configuration changed, reset all peers to take effect\n");
3013
3014 return bgp_vty_return(vty, ret);
3015 }
3016
3017 DEFUN (no_bgp_graceful_restart_disable,
3018 no_bgp_graceful_restart_disable_cmd,
3019 "no bgp graceful-restart-disable",
3020 NO_STR
3021 BGP_STR
3022 NO_GR_DISABLE
3023 )
3024 {
3025 VTY_DECLVAR_CONTEXT(bgp, bgp);
3026
3027 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3028 zlog_debug(
3029 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3030
3031 int ret = BGP_GR_FAILURE;
3032
3033 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3034
3035 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3036 ret);
3037
3038 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3039 zlog_debug(
3040 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3041 vty_out(vty,
3042 "Graceful restart configuration changed, reset all peers to take effect\n");
3043
3044 return bgp_vty_return(vty, ret);
3045 }
3046
3047 DEFUN (bgp_neighbor_graceful_restart_set,
3048 bgp_neighbor_graceful_restart_set_cmd,
3049 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3050 NEIGHBOR_STR
3051 NEIGHBOR_ADDR_STR2
3052 GR_NEIGHBOR_CMD
3053 )
3054 {
3055 int idx_peer = 1;
3056 struct peer *peer;
3057 int ret = BGP_GR_FAILURE;
3058
3059 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3060
3061 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3062 zlog_debug(
3063 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3064
3065 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3066 if (!peer)
3067 return CMD_WARNING_CONFIG_FAILED;
3068
3069 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3070
3071 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3072 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3073
3074 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3075 zlog_debug(
3076 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3077 vty_out(vty,
3078 "Graceful restart configuration changed, reset this peer to take effect\n");
3079
3080 return bgp_vty_return(vty, ret);
3081 }
3082
3083 DEFUN (no_bgp_neighbor_graceful_restart,
3084 no_bgp_neighbor_graceful_restart_set_cmd,
3085 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3086 NO_STR
3087 NEIGHBOR_STR
3088 NEIGHBOR_ADDR_STR2
3089 NO_GR_NEIGHBOR_CMD
3090 )
3091 {
3092 int idx_peer = 2;
3093 int ret = BGP_GR_FAILURE;
3094 struct peer *peer;
3095
3096 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3097
3098 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3099 if (!peer)
3100 return CMD_WARNING_CONFIG_FAILED;
3101
3102 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3103 zlog_debug(
3104 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3105
3106 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3107
3108 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3109 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3110
3111 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3112 zlog_debug(
3113 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3114 vty_out(vty,
3115 "Graceful restart configuration changed, reset this peer to take effect\n");
3116
3117 return bgp_vty_return(vty, ret);
3118 }
3119
3120 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3121 bgp_neighbor_graceful_restart_helper_set_cmd,
3122 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3123 NEIGHBOR_STR
3124 NEIGHBOR_ADDR_STR2
3125 GR_NEIGHBOR_HELPER_CMD
3126 )
3127 {
3128 int idx_peer = 1;
3129 struct peer *peer;
3130 int ret = BGP_GR_FAILURE;
3131
3132 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3133
3134 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3135 zlog_debug(
3136 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3137
3138 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3139
3140 if (!peer)
3141 return CMD_WARNING_CONFIG_FAILED;
3142
3143
3144 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3145
3146 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3147 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3148
3149 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3150 zlog_debug(
3151 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3152 vty_out(vty,
3153 "Graceful restart configuration changed, reset this peer to take effect\n");
3154
3155 return bgp_vty_return(vty, ret);
3156 }
3157
3158 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3159 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3160 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3161 NO_STR
3162 NEIGHBOR_STR
3163 NEIGHBOR_ADDR_STR2
3164 NO_GR_NEIGHBOR_HELPER_CMD
3165 )
3166 {
3167 int idx_peer = 2;
3168 int ret = BGP_GR_FAILURE;
3169 struct peer *peer;
3170
3171 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3172
3173 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3174 if (!peer)
3175 return CMD_WARNING_CONFIG_FAILED;
3176
3177 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3178 zlog_debug(
3179 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3180
3181 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3182
3183 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3184 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3185
3186 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3187 zlog_debug(
3188 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3189 vty_out(vty,
3190 "Graceful restart configuration changed, reset this peer to take effect\n");
3191
3192 return bgp_vty_return(vty, ret);
3193 }
3194
3195 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3196 bgp_neighbor_graceful_restart_disable_set_cmd,
3197 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3198 NEIGHBOR_STR
3199 NEIGHBOR_ADDR_STR2
3200 GR_NEIGHBOR_DISABLE_CMD
3201 )
3202 {
3203 int idx_peer = 1;
3204 struct peer *peer;
3205 int ret = BGP_GR_FAILURE;
3206
3207 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3208
3209 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3210 zlog_debug(
3211 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3212
3213 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3214 if (!peer)
3215 return CMD_WARNING_CONFIG_FAILED;
3216
3217 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3218
3219 if (peer->bgp->t_startup)
3220 bgp_peer_gr_flags_update(peer);
3221
3222 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3223 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3224
3225 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3226 zlog_debug(
3227 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3228 vty_out(vty,
3229 "Graceful restart configuration changed, reset this peer to take effect\n");
3230
3231 return bgp_vty_return(vty, ret);
3232 }
3233
3234 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3235 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3236 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3237 NO_STR
3238 NEIGHBOR_STR
3239 NEIGHBOR_ADDR_STR2
3240 NO_GR_NEIGHBOR_DISABLE_CMD
3241 )
3242 {
3243 int idx_peer = 2;
3244 int ret = BGP_GR_FAILURE;
3245 struct peer *peer;
3246
3247 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3248
3249 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3250 if (!peer)
3251 return CMD_WARNING_CONFIG_FAILED;
3252
3253 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3254 zlog_debug(
3255 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3256
3257 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3258
3259 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3260 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3261
3262 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3263 zlog_debug(
3264 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3265 vty_out(vty,
3266 "Graceful restart configuration changed, reset this peer to take effect\n");
3267
3268 return bgp_vty_return(vty, ret);
3269 }
3270
3271 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3272 bgp_graceful_restart_disable_eor_cmd,
3273 "bgp graceful-restart disable-eor",
3274 BGP_STR
3275 "Graceful restart configuration parameters\n"
3276 "Disable EOR Check\n")
3277 {
3278 VTY_DECLVAR_CONTEXT(bgp, bgp);
3279 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3280
3281 return CMD_SUCCESS;
3282 }
3283
3284 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3285 no_bgp_graceful_restart_disable_eor_cmd,
3286 "no bgp graceful-restart disable-eor",
3287 NO_STR
3288 BGP_STR
3289 "Graceful restart configuration parameters\n"
3290 "Disable EOR Check\n")
3291 {
3292 VTY_DECLVAR_CONTEXT(bgp, bgp);
3293 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3294
3295 return CMD_SUCCESS;
3296 }
3297
3298 DEFUN (bgp_graceful_restart_rib_stale_time,
3299 bgp_graceful_restart_rib_stale_time_cmd,
3300 "bgp graceful-restart rib-stale-time (1-3600)",
3301 BGP_STR
3302 "Graceful restart configuration parameters\n"
3303 "Specify the stale route removal timer in rib\n"
3304 "Delay value (seconds)\n")
3305 {
3306 VTY_DECLVAR_CONTEXT(bgp, bgp);
3307 int idx_number = 3;
3308 uint32_t stale_time;
3309
3310 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3311 bgp->rib_stale_time = stale_time;
3312 /* Send the stale timer update message to RIB */
3313 if (bgp_zebra_stale_timer_update(bgp))
3314 return CMD_WARNING;
3315
3316 return CMD_SUCCESS;
3317 }
3318
3319 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3320 no_bgp_graceful_restart_rib_stale_time_cmd,
3321 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3322 NO_STR
3323 BGP_STR
3324 "Graceful restart configuration parameters\n"
3325 "Specify the stale route removal timer in rib\n"
3326 "Delay value (seconds)\n")
3327 {
3328 VTY_DECLVAR_CONTEXT(bgp, bgp);
3329
3330 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3331 /* Send the stale timer update message to RIB */
3332 if (bgp_zebra_stale_timer_update(bgp))
3333 return CMD_WARNING;
3334
3335 return CMD_SUCCESS;
3336 }
3337
3338 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3339 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3340 BGP_STR
3341 "Enable Long-lived Graceful Restart\n"
3342 "Specifies maximum time to wait before purging long-lived stale routes\n"
3343 "Stale time value (seconds)\n")
3344 {
3345 VTY_DECLVAR_CONTEXT(bgp, bgp);
3346
3347 uint32_t llgr_stale_time;
3348
3349 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3350 bgp->llgr_stale_time = llgr_stale_time;
3351
3352 return CMD_SUCCESS;
3353 }
3354
3355 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3356 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3357 NO_STR BGP_STR
3358 "Enable Long-lived Graceful Restart\n"
3359 "Specifies maximum time to wait before purging long-lived stale routes\n"
3360 "Stale time value (seconds)\n")
3361 {
3362 VTY_DECLVAR_CONTEXT(bgp, bgp);
3363
3364 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3365
3366 return CMD_SUCCESS;
3367 }
3368
3369 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3370 struct bgp *bgp)
3371 {
3372 bgp_static_redo_import_check(bgp);
3373 bgp_redistribute_redo(bgp);
3374 bgp_clear_star_soft_out(vty, bgp->name);
3375 bgp_clear_star_soft_in(vty, bgp->name);
3376 }
3377
3378 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3379 {
3380 struct listnode *node, *nnode;
3381 struct bgp *bgp;
3382 bool vrf_cfg = false;
3383
3384 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3385 return CMD_SUCCESS;
3386
3387 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3388 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3389 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3390 vty_out(vty,
3391 "%% graceful-shutdown configuration found in vrf %s\n",
3392 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3393 VRF_DEFAULT_NAME : bgp->name);
3394 vrf_cfg = true;
3395 }
3396 }
3397
3398 if (vrf_cfg) {
3399 vty_out(vty,
3400 "%%Failed: global graceful-shutdown not permitted\n");
3401 return CMD_WARNING;
3402 }
3403
3404 /* Set flag globally */
3405 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3406
3407 /* Initiate processing for all BGP instances. */
3408 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3409 bgp_initiate_graceful_shut_unshut(vty, bgp);
3410
3411 return CMD_SUCCESS;
3412 }
3413
3414 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3415 {
3416 struct listnode *node, *nnode;
3417 struct bgp *bgp;
3418
3419 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3420 return CMD_SUCCESS;
3421
3422 /* Unset flag globally */
3423 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3424
3425 /* Initiate processing for all BGP instances. */
3426 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3427 bgp_initiate_graceful_shut_unshut(vty, bgp);
3428
3429 return CMD_SUCCESS;
3430 }
3431
3432 /* "bgp graceful-shutdown" configuration */
3433 DEFUN (bgp_graceful_shutdown,
3434 bgp_graceful_shutdown_cmd,
3435 "bgp graceful-shutdown",
3436 BGP_STR
3437 "Graceful shutdown parameters\n")
3438 {
3439 if (vty->node == CONFIG_NODE)
3440 return bgp_global_graceful_shutdown_config_vty(vty);
3441
3442 VTY_DECLVAR_CONTEXT(bgp, bgp);
3443
3444 /* if configured globally, per-instance config is not allowed */
3445 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3446 vty_out(vty,
3447 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3448 return CMD_WARNING_CONFIG_FAILED;
3449 }
3450
3451 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3452 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3453 bgp_initiate_graceful_shut_unshut(vty, bgp);
3454 }
3455
3456 return CMD_SUCCESS;
3457 }
3458
3459 DEFUN (no_bgp_graceful_shutdown,
3460 no_bgp_graceful_shutdown_cmd,
3461 "no bgp graceful-shutdown",
3462 NO_STR
3463 BGP_STR
3464 "Graceful shutdown parameters\n")
3465 {
3466 if (vty->node == CONFIG_NODE)
3467 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3468
3469 VTY_DECLVAR_CONTEXT(bgp, bgp);
3470
3471 /* If configured globally, cannot remove from one bgp instance */
3472 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3473 vty_out(vty,
3474 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3475 return CMD_WARNING_CONFIG_FAILED;
3476 }
3477
3478 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3479 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3480 bgp_initiate_graceful_shut_unshut(vty, bgp);
3481 }
3482
3483 return CMD_SUCCESS;
3484 }
3485
3486 /* "bgp fast-external-failover" configuration. */
3487 DEFUN (bgp_fast_external_failover,
3488 bgp_fast_external_failover_cmd,
3489 "bgp fast-external-failover",
3490 BGP_STR
3491 "Immediately reset session if a link to a directly connected external peer goes down\n")
3492 {
3493 VTY_DECLVAR_CONTEXT(bgp, bgp);
3494 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3495 return CMD_SUCCESS;
3496 }
3497
3498 DEFUN (no_bgp_fast_external_failover,
3499 no_bgp_fast_external_failover_cmd,
3500 "no bgp fast-external-failover",
3501 NO_STR
3502 BGP_STR
3503 "Immediately reset session if a link to a directly connected external peer goes down\n")
3504 {
3505 VTY_DECLVAR_CONTEXT(bgp, bgp);
3506 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3507 return CMD_SUCCESS;
3508 }
3509
3510 /* "bgp bestpath compare-routerid" configuration. */
3511 DEFUN (bgp_bestpath_compare_router_id,
3512 bgp_bestpath_compare_router_id_cmd,
3513 "bgp bestpath compare-routerid",
3514 BGP_STR
3515 "Change the default bestpath selection\n"
3516 "Compare router-id for identical EBGP paths\n")
3517 {
3518 VTY_DECLVAR_CONTEXT(bgp, bgp);
3519 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3520 bgp_recalculate_all_bestpaths(bgp);
3521
3522 return CMD_SUCCESS;
3523 }
3524
3525 DEFUN (no_bgp_bestpath_compare_router_id,
3526 no_bgp_bestpath_compare_router_id_cmd,
3527 "no bgp bestpath compare-routerid",
3528 NO_STR
3529 BGP_STR
3530 "Change the default bestpath selection\n"
3531 "Compare router-id for identical EBGP paths\n")
3532 {
3533 VTY_DECLVAR_CONTEXT(bgp, bgp);
3534 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3535 bgp_recalculate_all_bestpaths(bgp);
3536
3537 return CMD_SUCCESS;
3538 }
3539
3540 /* "bgp bestpath as-path ignore" configuration. */
3541 DEFUN (bgp_bestpath_aspath_ignore,
3542 bgp_bestpath_aspath_ignore_cmd,
3543 "bgp bestpath as-path ignore",
3544 BGP_STR
3545 "Change the default bestpath selection\n"
3546 "AS-path attribute\n"
3547 "Ignore as-path length in selecting a route\n")
3548 {
3549 VTY_DECLVAR_CONTEXT(bgp, bgp);
3550 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3551 bgp_recalculate_all_bestpaths(bgp);
3552
3553 return CMD_SUCCESS;
3554 }
3555
3556 DEFUN (no_bgp_bestpath_aspath_ignore,
3557 no_bgp_bestpath_aspath_ignore_cmd,
3558 "no bgp bestpath as-path ignore",
3559 NO_STR
3560 BGP_STR
3561 "Change the default bestpath selection\n"
3562 "AS-path attribute\n"
3563 "Ignore as-path length in selecting a route\n")
3564 {
3565 VTY_DECLVAR_CONTEXT(bgp, bgp);
3566 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3567 bgp_recalculate_all_bestpaths(bgp);
3568
3569 return CMD_SUCCESS;
3570 }
3571
3572 /* "bgp bestpath as-path confed" configuration. */
3573 DEFUN (bgp_bestpath_aspath_confed,
3574 bgp_bestpath_aspath_confed_cmd,
3575 "bgp bestpath as-path confed",
3576 BGP_STR
3577 "Change the default bestpath selection\n"
3578 "AS-path attribute\n"
3579 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3580 {
3581 VTY_DECLVAR_CONTEXT(bgp, bgp);
3582 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3583 bgp_recalculate_all_bestpaths(bgp);
3584
3585 return CMD_SUCCESS;
3586 }
3587
3588 DEFUN (no_bgp_bestpath_aspath_confed,
3589 no_bgp_bestpath_aspath_confed_cmd,
3590 "no bgp bestpath as-path confed",
3591 NO_STR
3592 BGP_STR
3593 "Change the default bestpath selection\n"
3594 "AS-path attribute\n"
3595 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3596 {
3597 VTY_DECLVAR_CONTEXT(bgp, bgp);
3598 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3599 bgp_recalculate_all_bestpaths(bgp);
3600
3601 return CMD_SUCCESS;
3602 }
3603
3604 /* "bgp bestpath as-path multipath-relax" configuration. */
3605 DEFUN (bgp_bestpath_aspath_multipath_relax,
3606 bgp_bestpath_aspath_multipath_relax_cmd,
3607 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3608 BGP_STR
3609 "Change the default bestpath selection\n"
3610 "AS-path attribute\n"
3611 "Allow load sharing across routes that have different AS paths (but same length)\n"
3612 "Generate an AS_SET\n"
3613 "Do not generate an AS_SET\n")
3614 {
3615 VTY_DECLVAR_CONTEXT(bgp, bgp);
3616 int idx = 0;
3617 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3618
3619 /* no-as-set is now the default behavior so we can silently
3620 * ignore it */
3621 if (argv_find(argv, argc, "as-set", &idx))
3622 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3623 else
3624 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3625
3626 bgp_recalculate_all_bestpaths(bgp);
3627
3628 return CMD_SUCCESS;
3629 }
3630
3631 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3632 no_bgp_bestpath_aspath_multipath_relax_cmd,
3633 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3634 NO_STR
3635 BGP_STR
3636 "Change the default bestpath selection\n"
3637 "AS-path attribute\n"
3638 "Allow load sharing across routes that have different AS paths (but same length)\n"
3639 "Generate an AS_SET\n"
3640 "Do not generate an AS_SET\n")
3641 {
3642 VTY_DECLVAR_CONTEXT(bgp, bgp);
3643 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3644 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3645 bgp_recalculate_all_bestpaths(bgp);
3646
3647 return CMD_SUCCESS;
3648 }
3649
3650 /* "bgp bestpath peer-type multipath-relax" configuration. */
3651 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3652 bgp_bestpath_peer_type_multipath_relax_cmd,
3653 "bgp bestpath peer-type multipath-relax",
3654 BGP_STR
3655 "Change the default bestpath selection\n"
3656 "Peer type\n"
3657 "Allow load sharing across routes learned from different peer types\n")
3658 {
3659 VTY_DECLVAR_CONTEXT(bgp, bgp);
3660 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3661 bgp_recalculate_all_bestpaths(bgp);
3662
3663 return CMD_SUCCESS;
3664 }
3665
3666 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3667 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3668 "no bgp bestpath peer-type multipath-relax",
3669 NO_STR BGP_STR
3670 "Change the default bestpath selection\n"
3671 "Peer type\n"
3672 "Allow load sharing across routes learned from different peer types\n")
3673 {
3674 VTY_DECLVAR_CONTEXT(bgp, bgp);
3675 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3676 bgp_recalculate_all_bestpaths(bgp);
3677
3678 return CMD_SUCCESS;
3679 }
3680
3681 /* "bgp log-neighbor-changes" configuration. */
3682 DEFUN (bgp_log_neighbor_changes,
3683 bgp_log_neighbor_changes_cmd,
3684 "bgp log-neighbor-changes",
3685 BGP_STR
3686 "Log neighbor up/down and reset reason\n")
3687 {
3688 VTY_DECLVAR_CONTEXT(bgp, bgp);
3689 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3690 return CMD_SUCCESS;
3691 }
3692
3693 DEFUN (no_bgp_log_neighbor_changes,
3694 no_bgp_log_neighbor_changes_cmd,
3695 "no bgp log-neighbor-changes",
3696 NO_STR
3697 BGP_STR
3698 "Log neighbor up/down and reset reason\n")
3699 {
3700 VTY_DECLVAR_CONTEXT(bgp, bgp);
3701 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3702 return CMD_SUCCESS;
3703 }
3704
3705 /* "bgp bestpath med" configuration. */
3706 DEFUN (bgp_bestpath_med,
3707 bgp_bestpath_med_cmd,
3708 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3709 BGP_STR
3710 "Change the default bestpath selection\n"
3711 "MED attribute\n"
3712 "Compare MED among confederation paths\n"
3713 "Treat missing MED as the least preferred one\n"
3714 "Treat missing MED as the least preferred one\n"
3715 "Compare MED among confederation paths\n")
3716 {
3717 VTY_DECLVAR_CONTEXT(bgp, bgp);
3718
3719 int idx = 0;
3720 if (argv_find(argv, argc, "confed", &idx))
3721 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3722 idx = 0;
3723 if (argv_find(argv, argc, "missing-as-worst", &idx))
3724 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3725
3726 bgp_recalculate_all_bestpaths(bgp);
3727
3728 return CMD_SUCCESS;
3729 }
3730
3731 DEFUN (no_bgp_bestpath_med,
3732 no_bgp_bestpath_med_cmd,
3733 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3734 NO_STR
3735 BGP_STR
3736 "Change the default bestpath selection\n"
3737 "MED attribute\n"
3738 "Compare MED among confederation paths\n"
3739 "Treat missing MED as the least preferred one\n"
3740 "Treat missing MED as the least preferred one\n"
3741 "Compare MED among confederation paths\n")
3742 {
3743 VTY_DECLVAR_CONTEXT(bgp, bgp);
3744
3745 int idx = 0;
3746 if (argv_find(argv, argc, "confed", &idx))
3747 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3748 idx = 0;
3749 if (argv_find(argv, argc, "missing-as-worst", &idx))
3750 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3751
3752 bgp_recalculate_all_bestpaths(bgp);
3753
3754 return CMD_SUCCESS;
3755 }
3756
3757 /* "bgp bestpath bandwidth" configuration. */
3758 DEFPY (bgp_bestpath_bw,
3759 bgp_bestpath_bw_cmd,
3760 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3761 BGP_STR
3762 "Change the default bestpath selection\n"
3763 "Link Bandwidth attribute\n"
3764 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3765 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3766 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3767 {
3768 VTY_DECLVAR_CONTEXT(bgp, bgp);
3769 afi_t afi;
3770 safi_t safi;
3771
3772 if (!bw_cfg) {
3773 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3774 return CMD_ERR_INCOMPLETE;
3775 }
3776 if (!strcmp(bw_cfg, "ignore"))
3777 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3778 else if (!strcmp(bw_cfg, "skip-missing"))
3779 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3780 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3781 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3782 else
3783 return CMD_ERR_NO_MATCH;
3784
3785 /* This config is used in route install, so redo that. */
3786 FOREACH_AFI_SAFI (afi, safi) {
3787 if (!bgp_fibupd_safi(safi))
3788 continue;
3789 bgp_zebra_announce_table(bgp, afi, safi);
3790 }
3791
3792 return CMD_SUCCESS;
3793 }
3794
3795 DEFPY (no_bgp_bestpath_bw,
3796 no_bgp_bestpath_bw_cmd,
3797 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3798 NO_STR
3799 BGP_STR
3800 "Change the default bestpath selection\n"
3801 "Link Bandwidth attribute\n"
3802 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3803 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3804 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3805 {
3806 VTY_DECLVAR_CONTEXT(bgp, bgp);
3807 afi_t afi;
3808 safi_t safi;
3809
3810 bgp->lb_handling = BGP_LINK_BW_ECMP;
3811
3812 /* This config is used in route install, so redo that. */
3813 FOREACH_AFI_SAFI (afi, safi) {
3814 if (!bgp_fibupd_safi(safi))
3815 continue;
3816 bgp_zebra_announce_table(bgp, afi, safi);
3817 }
3818 return CMD_SUCCESS;
3819 }
3820
3821 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3822 "[no] bgp default <ipv4-unicast|"
3823 "ipv4-multicast|"
3824 "ipv4-vpn|"
3825 "ipv4-labeled-unicast|"
3826 "ipv4-flowspec|"
3827 "ipv6-unicast|"
3828 "ipv6-multicast|"
3829 "ipv6-vpn|"
3830 "ipv6-labeled-unicast|"
3831 "ipv6-flowspec|"
3832 "l2vpn-evpn>$afi_safi",
3833 NO_STR
3834 BGP_STR
3835 "Configure BGP defaults\n"
3836 "Activate ipv4-unicast for a peer by default\n"
3837 "Activate ipv4-multicast for a peer by default\n"
3838 "Activate ipv4-vpn for a peer by default\n"
3839 "Activate ipv4-labeled-unicast for a peer by default\n"
3840 "Activate ipv4-flowspec for a peer by default\n"
3841 "Activate ipv6-unicast for a peer by default\n"
3842 "Activate ipv6-multicast for a peer by default\n"
3843 "Activate ipv6-vpn for a peer by default\n"
3844 "Activate ipv6-labeled-unicast for a peer by default\n"
3845 "Activate ipv6-flowspec for a peer by default\n"
3846 "Activate l2vpn-evpn for a peer by default\n")
3847 {
3848 VTY_DECLVAR_CONTEXT(bgp, bgp);
3849 char afi_safi_str[strlen(afi_safi) + 1];
3850 char *afi_safi_str_tok;
3851
3852 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3853 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3854 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3855 afi_t afi = bgp_vty_afi_from_str(afi_str);
3856 safi_t safi;
3857
3858 /*
3859 * Impossible situation but making coverity happy
3860 */
3861 assert(afi != AFI_MAX);
3862
3863 if (strmatch(safi_str, "labeled"))
3864 safi = bgp_vty_safi_from_str("labeled-unicast");
3865 else
3866 safi = bgp_vty_safi_from_str(safi_str);
3867
3868 assert(safi != SAFI_MAX);
3869 if (no)
3870 bgp->default_af[afi][safi] = false;
3871 else {
3872 if ((safi == SAFI_LABELED_UNICAST
3873 && bgp->default_af[afi][SAFI_UNICAST])
3874 || (safi == SAFI_UNICAST
3875 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3876 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3877 else
3878 bgp->default_af[afi][safi] = true;
3879 }
3880
3881 return CMD_SUCCESS;
3882 }
3883
3884 /* Display hostname in certain command outputs */
3885 DEFUN (bgp_default_show_hostname,
3886 bgp_default_show_hostname_cmd,
3887 "bgp default show-hostname",
3888 BGP_STR
3889 "Configure BGP defaults\n"
3890 "Show hostname in certain command outputs\n")
3891 {
3892 VTY_DECLVAR_CONTEXT(bgp, bgp);
3893 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3894 return CMD_SUCCESS;
3895 }
3896
3897 DEFUN (no_bgp_default_show_hostname,
3898 no_bgp_default_show_hostname_cmd,
3899 "no bgp default show-hostname",
3900 NO_STR
3901 BGP_STR
3902 "Configure BGP defaults\n"
3903 "Show hostname in certain command outputs\n")
3904 {
3905 VTY_DECLVAR_CONTEXT(bgp, bgp);
3906 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3907 return CMD_SUCCESS;
3908 }
3909
3910 /* Display hostname in certain command outputs */
3911 DEFUN (bgp_default_show_nexthop_hostname,
3912 bgp_default_show_nexthop_hostname_cmd,
3913 "bgp default show-nexthop-hostname",
3914 BGP_STR
3915 "Configure BGP defaults\n"
3916 "Show hostname for nexthop in certain command outputs\n")
3917 {
3918 VTY_DECLVAR_CONTEXT(bgp, bgp);
3919 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3920 return CMD_SUCCESS;
3921 }
3922
3923 DEFUN (no_bgp_default_show_nexthop_hostname,
3924 no_bgp_default_show_nexthop_hostname_cmd,
3925 "no bgp default show-nexthop-hostname",
3926 NO_STR
3927 BGP_STR
3928 "Configure BGP defaults\n"
3929 "Show hostname for nexthop in certain command outputs\n")
3930 {
3931 VTY_DECLVAR_CONTEXT(bgp, bgp);
3932 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3933 return CMD_SUCCESS;
3934 }
3935
3936 /* "bgp network import-check" configuration. */
3937 DEFUN (bgp_network_import_check,
3938 bgp_network_import_check_cmd,
3939 "bgp network import-check",
3940 BGP_STR
3941 "BGP network command\n"
3942 "Check BGP network route exists in IGP\n")
3943 {
3944 VTY_DECLVAR_CONTEXT(bgp, bgp);
3945 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3946 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3947 bgp_static_redo_import_check(bgp);
3948 }
3949
3950 return CMD_SUCCESS;
3951 }
3952
3953 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3954 "bgp network import-check exact",
3955 BGP_STR
3956 "BGP network command\n"
3957 "Check BGP network route exists in IGP\n"
3958 "Match route precisely\n")
3959
3960 DEFUN (no_bgp_network_import_check,
3961 no_bgp_network_import_check_cmd,
3962 "no bgp network import-check",
3963 NO_STR
3964 BGP_STR
3965 "BGP network command\n"
3966 "Check BGP network route exists in IGP\n")
3967 {
3968 VTY_DECLVAR_CONTEXT(bgp, bgp);
3969 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3970 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3971 bgp_static_redo_import_check(bgp);
3972 }
3973
3974 return CMD_SUCCESS;
3975 }
3976
3977 DEFUN (bgp_default_local_preference,
3978 bgp_default_local_preference_cmd,
3979 "bgp default local-preference (0-4294967295)",
3980 BGP_STR
3981 "Configure BGP defaults\n"
3982 "local preference (higher=more preferred)\n"
3983 "Configure default local preference value\n")
3984 {
3985 VTY_DECLVAR_CONTEXT(bgp, bgp);
3986 int idx_number = 3;
3987 uint32_t local_pref;
3988
3989 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3990
3991 bgp_default_local_preference_set(bgp, local_pref);
3992 bgp_clear_star_soft_in(vty, bgp->name);
3993
3994 return CMD_SUCCESS;
3995 }
3996
3997 DEFUN (no_bgp_default_local_preference,
3998 no_bgp_default_local_preference_cmd,
3999 "no bgp default local-preference [(0-4294967295)]",
4000 NO_STR
4001 BGP_STR
4002 "Configure BGP defaults\n"
4003 "local preference (higher=more preferred)\n"
4004 "Configure default local preference value\n")
4005 {
4006 VTY_DECLVAR_CONTEXT(bgp, bgp);
4007 bgp_default_local_preference_unset(bgp);
4008 bgp_clear_star_soft_in(vty, bgp->name);
4009
4010 return CMD_SUCCESS;
4011 }
4012
4013
4014 DEFUN (bgp_default_subgroup_pkt_queue_max,
4015 bgp_default_subgroup_pkt_queue_max_cmd,
4016 "bgp default subgroup-pkt-queue-max (20-100)",
4017 BGP_STR
4018 "Configure BGP defaults\n"
4019 "subgroup-pkt-queue-max\n"
4020 "Configure subgroup packet queue max\n")
4021 {
4022 VTY_DECLVAR_CONTEXT(bgp, bgp);
4023 int idx_number = 3;
4024 uint32_t max_size;
4025
4026 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4027
4028 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4029
4030 return CMD_SUCCESS;
4031 }
4032
4033 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4034 no_bgp_default_subgroup_pkt_queue_max_cmd,
4035 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4036 NO_STR
4037 BGP_STR
4038 "Configure BGP defaults\n"
4039 "subgroup-pkt-queue-max\n"
4040 "Configure subgroup packet queue max\n")
4041 {
4042 VTY_DECLVAR_CONTEXT(bgp, bgp);
4043 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4044 return CMD_SUCCESS;
4045 }
4046
4047
4048 DEFUN (bgp_rr_allow_outbound_policy,
4049 bgp_rr_allow_outbound_policy_cmd,
4050 "bgp route-reflector allow-outbound-policy",
4051 BGP_STR
4052 "Allow modifications made by out route-map\n"
4053 "on ibgp neighbors\n")
4054 {
4055 VTY_DECLVAR_CONTEXT(bgp, bgp);
4056
4057 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4058 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4059 update_group_announce_rrclients(bgp);
4060 bgp_clear_star_soft_out(vty, bgp->name);
4061 }
4062
4063 return CMD_SUCCESS;
4064 }
4065
4066 DEFUN (no_bgp_rr_allow_outbound_policy,
4067 no_bgp_rr_allow_outbound_policy_cmd,
4068 "no bgp route-reflector allow-outbound-policy",
4069 NO_STR
4070 BGP_STR
4071 "Allow modifications made by out route-map\n"
4072 "on ibgp neighbors\n")
4073 {
4074 VTY_DECLVAR_CONTEXT(bgp, bgp);
4075
4076 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4077 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4078 update_group_announce_rrclients(bgp);
4079 bgp_clear_star_soft_out(vty, bgp->name);
4080 }
4081
4082 return CMD_SUCCESS;
4083 }
4084
4085 DEFUN (bgp_listen_limit,
4086 bgp_listen_limit_cmd,
4087 "bgp listen limit (1-65535)",
4088 BGP_STR
4089 "BGP Dynamic Neighbors listen commands\n"
4090 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4091 "Configure Dynamic Neighbors listen limit value\n")
4092 {
4093 VTY_DECLVAR_CONTEXT(bgp, bgp);
4094 int idx_number = 3;
4095 int listen_limit;
4096
4097 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4098
4099 bgp_listen_limit_set(bgp, listen_limit);
4100
4101 return CMD_SUCCESS;
4102 }
4103
4104 DEFUN (no_bgp_listen_limit,
4105 no_bgp_listen_limit_cmd,
4106 "no bgp listen limit [(1-65535)]",
4107 NO_STR
4108 BGP_STR
4109 "BGP Dynamic Neighbors listen commands\n"
4110 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4111 "Configure Dynamic Neighbors listen limit value\n")
4112 {
4113 VTY_DECLVAR_CONTEXT(bgp, bgp);
4114 bgp_listen_limit_unset(bgp);
4115 return CMD_SUCCESS;
4116 }
4117
4118
4119 /*
4120 * Check if this listen range is already configured. Check for exact
4121 * match or overlap based on input.
4122 */
4123 static struct peer_group *listen_range_exists(struct bgp *bgp,
4124 struct prefix *range, int exact)
4125 {
4126 struct listnode *node, *nnode;
4127 struct listnode *node1, *nnode1;
4128 struct peer_group *group;
4129 struct prefix *lr;
4130 afi_t afi;
4131 int match;
4132
4133 afi = family2afi(range->family);
4134 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4135 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4136 lr)) {
4137 if (exact)
4138 match = prefix_same(range, lr);
4139 else
4140 match = (prefix_match(range, lr)
4141 || prefix_match(lr, range));
4142 if (match)
4143 return group;
4144 }
4145 }
4146
4147 return NULL;
4148 }
4149
4150 DEFUN (bgp_listen_range,
4151 bgp_listen_range_cmd,
4152 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4153 BGP_STR
4154 "Configure BGP dynamic neighbors listen range\n"
4155 "Configure BGP dynamic neighbors listen range\n"
4156 NEIGHBOR_ADDR_STR
4157 "Member of the peer-group\n"
4158 "Peer-group name\n")
4159 {
4160 VTY_DECLVAR_CONTEXT(bgp, bgp);
4161 struct prefix range;
4162 struct peer_group *group, *existing_group;
4163 afi_t afi;
4164 int ret;
4165 int idx = 0;
4166
4167 argv_find(argv, argc, "A.B.C.D/M", &idx);
4168 argv_find(argv, argc, "X:X::X:X/M", &idx);
4169 char *prefix = argv[idx]->arg;
4170 argv_find(argv, argc, "PGNAME", &idx);
4171 char *peergroup = argv[idx]->arg;
4172
4173 /* Convert IP prefix string to struct prefix. */
4174 ret = str2prefix(prefix, &range);
4175 if (!ret) {
4176 vty_out(vty, "%% Malformed listen range\n");
4177 return CMD_WARNING_CONFIG_FAILED;
4178 }
4179
4180 afi = family2afi(range.family);
4181
4182 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4183 vty_out(vty,
4184 "%% Malformed listen range (link-local address)\n");
4185 return CMD_WARNING_CONFIG_FAILED;
4186 }
4187
4188 apply_mask(&range);
4189
4190 /* Check if same listen range is already configured. */
4191 existing_group = listen_range_exists(bgp, &range, 1);
4192 if (existing_group) {
4193 if (strcmp(existing_group->name, peergroup) == 0)
4194 return CMD_SUCCESS;
4195 else {
4196 vty_out(vty,
4197 "%% Same listen range is attached to peer-group %s\n",
4198 existing_group->name);
4199 return CMD_WARNING_CONFIG_FAILED;
4200 }
4201 }
4202
4203 /* Check if an overlapping listen range exists. */
4204 if (listen_range_exists(bgp, &range, 0)) {
4205 vty_out(vty,
4206 "%% Listen range overlaps with existing listen range\n");
4207 return CMD_WARNING_CONFIG_FAILED;
4208 }
4209
4210 group = peer_group_lookup(bgp, peergroup);
4211 if (!group) {
4212 vty_out(vty, "%% Configure the peer-group first\n");
4213 return CMD_WARNING_CONFIG_FAILED;
4214 }
4215
4216 ret = peer_group_listen_range_add(group, &range);
4217 return bgp_vty_return(vty, ret);
4218 }
4219
4220 DEFUN (no_bgp_listen_range,
4221 no_bgp_listen_range_cmd,
4222 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4223 NO_STR
4224 BGP_STR
4225 "Unconfigure BGP dynamic neighbors listen range\n"
4226 "Unconfigure BGP dynamic neighbors listen range\n"
4227 NEIGHBOR_ADDR_STR
4228 "Member of the peer-group\n"
4229 "Peer-group name\n")
4230 {
4231 VTY_DECLVAR_CONTEXT(bgp, bgp);
4232 struct prefix range;
4233 struct peer_group *group;
4234 afi_t afi;
4235 int ret;
4236 int idx = 0;
4237
4238 argv_find(argv, argc, "A.B.C.D/M", &idx);
4239 argv_find(argv, argc, "X:X::X:X/M", &idx);
4240 char *prefix = argv[idx]->arg;
4241 argv_find(argv, argc, "PGNAME", &idx);
4242 char *peergroup = argv[idx]->arg;
4243
4244 /* Convert IP prefix string to struct prefix. */
4245 ret = str2prefix(prefix, &range);
4246 if (!ret) {
4247 vty_out(vty, "%% Malformed listen range\n");
4248 return CMD_WARNING_CONFIG_FAILED;
4249 }
4250
4251 afi = family2afi(range.family);
4252
4253 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4254 vty_out(vty,
4255 "%% Malformed listen range (link-local address)\n");
4256 return CMD_WARNING_CONFIG_FAILED;
4257 }
4258
4259 apply_mask(&range);
4260
4261 group = peer_group_lookup(bgp, peergroup);
4262 if (!group) {
4263 vty_out(vty, "%% Peer-group does not exist\n");
4264 return CMD_WARNING_CONFIG_FAILED;
4265 }
4266
4267 ret = peer_group_listen_range_del(group, &range);
4268 return bgp_vty_return(vty, ret);
4269 }
4270
4271 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4272 {
4273 struct peer_group *group;
4274 struct listnode *node, *nnode, *rnode, *nrnode;
4275 struct prefix *range;
4276 afi_t afi;
4277
4278 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4279 vty_out(vty, " bgp listen limit %d\n",
4280 bgp->dynamic_neighbors_limit);
4281
4282 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4283 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4284 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4285 nrnode, range)) {
4286 vty_out(vty,
4287 " bgp listen range %pFX peer-group %s\n",
4288 range, group->name);
4289 }
4290 }
4291 }
4292 }
4293
4294
4295 DEFUN (bgp_disable_connected_route_check,
4296 bgp_disable_connected_route_check_cmd,
4297 "bgp disable-ebgp-connected-route-check",
4298 BGP_STR
4299 "Disable checking if nexthop is connected on ebgp sessions\n")
4300 {
4301 VTY_DECLVAR_CONTEXT(bgp, bgp);
4302 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4303 bgp_clear_star_soft_in(vty, bgp->name);
4304
4305 return CMD_SUCCESS;
4306 }
4307
4308 DEFUN (no_bgp_disable_connected_route_check,
4309 no_bgp_disable_connected_route_check_cmd,
4310 "no bgp disable-ebgp-connected-route-check",
4311 NO_STR
4312 BGP_STR
4313 "Disable checking if nexthop is connected on ebgp sessions\n")
4314 {
4315 VTY_DECLVAR_CONTEXT(bgp, bgp);
4316 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4317 bgp_clear_star_soft_in(vty, bgp->name);
4318
4319 return CMD_SUCCESS;
4320 }
4321
4322
4323 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4324 const char *as_str)
4325 {
4326 VTY_DECLVAR_CONTEXT(bgp, bgp);
4327 int ret;
4328 as_t as;
4329 int as_type = AS_SPECIFIED;
4330 union sockunion su;
4331
4332 if (as_str[0] == 'i') {
4333 as = 0;
4334 as_type = AS_INTERNAL;
4335 } else if (as_str[0] == 'e') {
4336 as = 0;
4337 as_type = AS_EXTERNAL;
4338 } else {
4339 /* Get AS number. */
4340 as = strtoul(as_str, NULL, 10);
4341 }
4342
4343 /* If peer is peer group or interface peer, call proper function. */
4344 ret = str2sockunion(peer_str, &su);
4345 if (ret < 0) {
4346 struct peer *peer;
4347
4348 /* Check if existing interface peer */
4349 peer = peer_lookup_by_conf_if(bgp, peer_str);
4350
4351 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4352
4353 /* if not interface peer, check peer-group settings */
4354 if (ret < 0 && !peer) {
4355 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4356 if (ret < 0) {
4357 vty_out(vty,
4358 "%% Create the peer-group or interface first\n");
4359 return CMD_WARNING_CONFIG_FAILED;
4360 }
4361 return CMD_SUCCESS;
4362 }
4363 } else {
4364 if (peer_address_self_check(bgp, &su)) {
4365 vty_out(vty,
4366 "%% Can not configure the local system as neighbor\n");
4367 return CMD_WARNING_CONFIG_FAILED;
4368 }
4369 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4370 }
4371
4372 return bgp_vty_return(vty, ret);
4373 }
4374
4375 DEFUN (bgp_default_shutdown,
4376 bgp_default_shutdown_cmd,
4377 "[no] bgp default shutdown",
4378 NO_STR
4379 BGP_STR
4380 "Configure BGP defaults\n"
4381 "Apply administrative shutdown to newly configured peers\n")
4382 {
4383 VTY_DECLVAR_CONTEXT(bgp, bgp);
4384 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4385 return CMD_SUCCESS;
4386 }
4387
4388 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4389 BGP_STR
4390 "Administrative shutdown of the BGP instance\n"
4391 "Add a shutdown message (RFC 8203)\n"
4392 "Shutdown message\n")
4393 {
4394 char *msgstr = NULL;
4395
4396 VTY_DECLVAR_CONTEXT(bgp, bgp);
4397
4398 if (argc > 3)
4399 msgstr = argv_concat(argv, argc, 3);
4400
4401 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4402 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4403 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4404 return CMD_WARNING_CONFIG_FAILED;
4405 }
4406
4407 bgp_shutdown_enable(bgp, msgstr);
4408 XFREE(MTYPE_TMP, msgstr);
4409
4410 return CMD_SUCCESS;
4411 }
4412
4413 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4414 BGP_STR "Administrative shutdown of the BGP instance\n")
4415 {
4416 VTY_DECLVAR_CONTEXT(bgp, bgp);
4417
4418 bgp_shutdown_enable(bgp, NULL);
4419
4420 return CMD_SUCCESS;
4421 }
4422
4423 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4424 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4425 {
4426 VTY_DECLVAR_CONTEXT(bgp, bgp);
4427
4428 bgp_shutdown_disable(bgp);
4429
4430 return CMD_SUCCESS;
4431 }
4432
4433 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4434 "no bgp shutdown message MSG...", NO_STR BGP_STR
4435 "Administrative shutdown of the BGP instance\n"
4436 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4437
4438 DEFUN (neighbor_remote_as,
4439 neighbor_remote_as_cmd,
4440 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4441 NEIGHBOR_STR
4442 NEIGHBOR_ADDR_STR2
4443 "Specify a BGP neighbor\n"
4444 AS_STR
4445 "Internal BGP peer\n"
4446 "External BGP peer\n")
4447 {
4448 int idx_peer = 1;
4449 int idx_remote_as = 3;
4450 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4451 argv[idx_remote_as]->arg);
4452 }
4453
4454 DEFPY (bgp_allow_martian,
4455 bgp_allow_martian_cmd,
4456 "[no]$no bgp allow-martian-nexthop",
4457 NO_STR
4458 BGP_STR
4459 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4460 {
4461 VTY_DECLVAR_CONTEXT(bgp, bgp);
4462
4463 if (no)
4464 bgp->allow_martian = false;
4465 else
4466 bgp->allow_martian = true;
4467
4468 return CMD_SUCCESS;
4469 }
4470
4471 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4472 * sessions do not wait for hold timer expiry to bring down the sessions
4473 * when nexthop becomes unreachable
4474 */
4475 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4476 BGP_STR "Fast convergence for bgp sessions\n")
4477 {
4478 VTY_DECLVAR_CONTEXT(bgp, bgp);
4479 bgp->fast_convergence = true;
4480
4481 return CMD_SUCCESS;
4482 }
4483
4484 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4485 "no bgp fast-convergence",
4486 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4487 {
4488 VTY_DECLVAR_CONTEXT(bgp, bgp);
4489 bgp->fast_convergence = false;
4490
4491 return CMD_SUCCESS;
4492 }
4493
4494 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4495 int v6only,
4496 const char *peer_group_name,
4497 const char *as_str)
4498 {
4499 VTY_DECLVAR_CONTEXT(bgp, bgp);
4500 as_t as = 0;
4501 int as_type = AS_UNSPECIFIED;
4502 struct peer *peer;
4503 struct peer_group *group;
4504 int ret = 0;
4505
4506 group = peer_group_lookup(bgp, conf_if);
4507
4508 if (group) {
4509 vty_out(vty, "%% Name conflict with peer-group \n");
4510 return CMD_WARNING_CONFIG_FAILED;
4511 }
4512
4513 if (as_str) {
4514 if (as_str[0] == 'i') {
4515 as_type = AS_INTERNAL;
4516 } else if (as_str[0] == 'e') {
4517 as_type = AS_EXTERNAL;
4518 } else {
4519 /* Get AS number. */
4520 as = strtoul(as_str, NULL, 10);
4521 as_type = AS_SPECIFIED;
4522 }
4523 }
4524
4525 peer = peer_lookup_by_conf_if(bgp, conf_if);
4526 if (peer) {
4527 if (as_str)
4528 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4529 } else {
4530 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4531 NULL);
4532
4533 if (!peer) {
4534 vty_out(vty, "%% BGP failed to create peer\n");
4535 return CMD_WARNING_CONFIG_FAILED;
4536 }
4537
4538 if (v6only)
4539 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4540
4541 /* Request zebra to initiate IPv6 RAs on this interface. We do
4542 * this
4543 * any unnumbered peer in order to not worry about run-time
4544 * transitions
4545 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4546 * address
4547 * gets deleted later etc.)
4548 */
4549 if (peer->ifp)
4550 bgp_zebra_initiate_radv(bgp, peer);
4551 }
4552
4553 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4554 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4555 if (v6only)
4556 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4557 else
4558 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4559
4560 /* v6only flag changed. Reset bgp seesion */
4561 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4562 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4563 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4564 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4565 } else
4566 bgp_session_reset(peer);
4567 }
4568
4569 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4570 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4571 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4572 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4573 }
4574
4575 if (peer_group_name) {
4576 group = peer_group_lookup(bgp, peer_group_name);
4577 if (!group) {
4578 vty_out(vty, "%% Configure the peer-group first\n");
4579 return CMD_WARNING_CONFIG_FAILED;
4580 }
4581
4582 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4583 }
4584
4585 return bgp_vty_return(vty, ret);
4586 }
4587
4588 DEFUN (neighbor_interface_config,
4589 neighbor_interface_config_cmd,
4590 "neighbor WORD interface [peer-group PGNAME]",
4591 NEIGHBOR_STR
4592 "Interface name or neighbor tag\n"
4593 "Enable BGP on interface\n"
4594 "Member of the peer-group\n"
4595 "Peer-group name\n")
4596 {
4597 int idx_word = 1;
4598 int idx_peer_group_word = 4;
4599
4600 if (argc > idx_peer_group_word)
4601 return peer_conf_interface_get(
4602 vty, argv[idx_word]->arg, 0,
4603 argv[idx_peer_group_word]->arg, NULL);
4604 else
4605 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4606 NULL, NULL);
4607 }
4608
4609 DEFUN (neighbor_interface_config_v6only,
4610 neighbor_interface_config_v6only_cmd,
4611 "neighbor WORD interface v6only [peer-group PGNAME]",
4612 NEIGHBOR_STR
4613 "Interface name or neighbor tag\n"
4614 "Enable BGP on interface\n"
4615 "Enable BGP with v6 link-local only\n"
4616 "Member of the peer-group\n"
4617 "Peer-group name\n")
4618 {
4619 int idx_word = 1;
4620 int idx_peer_group_word = 5;
4621
4622 if (argc > idx_peer_group_word)
4623 return peer_conf_interface_get(
4624 vty, argv[idx_word]->arg, 1,
4625 argv[idx_peer_group_word]->arg, NULL);
4626
4627 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4628 }
4629
4630
4631 DEFUN (neighbor_interface_config_remote_as,
4632 neighbor_interface_config_remote_as_cmd,
4633 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4634 NEIGHBOR_STR
4635 "Interface name or neighbor tag\n"
4636 "Enable BGP on interface\n"
4637 "Specify a BGP neighbor\n"
4638 AS_STR
4639 "Internal BGP peer\n"
4640 "External BGP peer\n")
4641 {
4642 int idx_word = 1;
4643 int idx_remote_as = 4;
4644 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4645 argv[idx_remote_as]->arg);
4646 }
4647
4648 DEFUN (neighbor_interface_v6only_config_remote_as,
4649 neighbor_interface_v6only_config_remote_as_cmd,
4650 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4651 NEIGHBOR_STR
4652 "Interface name or neighbor tag\n"
4653 "Enable BGP with v6 link-local only\n"
4654 "Enable BGP on interface\n"
4655 "Specify a BGP neighbor\n"
4656 AS_STR
4657 "Internal BGP peer\n"
4658 "External BGP peer\n")
4659 {
4660 int idx_word = 1;
4661 int idx_remote_as = 5;
4662 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4663 argv[idx_remote_as]->arg);
4664 }
4665
4666 DEFUN (neighbor_peer_group,
4667 neighbor_peer_group_cmd,
4668 "neighbor WORD peer-group",
4669 NEIGHBOR_STR
4670 "Interface name or neighbor tag\n"
4671 "Configure peer-group\n")
4672 {
4673 VTY_DECLVAR_CONTEXT(bgp, bgp);
4674 int idx_word = 1;
4675 struct peer *peer;
4676 struct peer_group *group;
4677
4678 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4679 if (peer) {
4680 vty_out(vty, "%% Name conflict with interface: \n");
4681 return CMD_WARNING_CONFIG_FAILED;
4682 }
4683
4684 group = peer_group_get(bgp, argv[idx_word]->arg);
4685 if (!group) {
4686 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4687 return CMD_WARNING_CONFIG_FAILED;
4688 }
4689
4690 return CMD_SUCCESS;
4691 }
4692
4693 DEFUN (no_neighbor,
4694 no_neighbor_cmd,
4695 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4696 NO_STR
4697 NEIGHBOR_STR
4698 NEIGHBOR_ADDR_STR2
4699 "Specify a BGP neighbor\n"
4700 AS_STR
4701 "Internal BGP peer\n"
4702 "External BGP peer\n")
4703 {
4704 VTY_DECLVAR_CONTEXT(bgp, bgp);
4705 int idx_peer = 2;
4706 int ret;
4707 union sockunion su;
4708 struct peer_group *group;
4709 struct peer *peer;
4710 struct peer *other;
4711
4712 ret = str2sockunion(argv[idx_peer]->arg, &su);
4713 if (ret < 0) {
4714 /* look up for neighbor by interface name config. */
4715 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4716 if (peer) {
4717 /* Request zebra to terminate IPv6 RAs on this
4718 * interface. */
4719 if (peer->ifp)
4720 bgp_zebra_terminate_radv(peer->bgp, peer);
4721 peer_notify_unconfig(peer);
4722 peer_delete(peer);
4723 return CMD_SUCCESS;
4724 }
4725
4726 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4727 if (group) {
4728 peer_group_notify_unconfig(group);
4729 peer_group_delete(group);
4730 } else {
4731 vty_out(vty, "%% Create the peer-group first\n");
4732 return CMD_WARNING_CONFIG_FAILED;
4733 }
4734 } else {
4735 peer = peer_lookup(bgp, &su);
4736 if (peer) {
4737 if (peer_dynamic_neighbor(peer)) {
4738 vty_out(vty,
4739 "%% Operation not allowed on a dynamic neighbor\n");
4740 return CMD_WARNING_CONFIG_FAILED;
4741 }
4742
4743 other = peer->doppelganger;
4744
4745 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4746 bgp_zebra_terminate_radv(peer->bgp, peer);
4747
4748 peer_notify_unconfig(peer);
4749 peer_delete(peer);
4750 if (other && other->status != Deleted) {
4751 peer_notify_unconfig(other);
4752 peer_delete(other);
4753 }
4754 }
4755 }
4756
4757 return CMD_SUCCESS;
4758 }
4759
4760 DEFUN (no_neighbor_interface_config,
4761 no_neighbor_interface_config_cmd,
4762 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4763 NO_STR
4764 NEIGHBOR_STR
4765 "Interface name\n"
4766 "Configure BGP on interface\n"
4767 "Enable BGP with v6 link-local only\n"
4768 "Member of the peer-group\n"
4769 "Peer-group name\n"
4770 "Specify a BGP neighbor\n"
4771 AS_STR
4772 "Internal BGP peer\n"
4773 "External BGP peer\n")
4774 {
4775 VTY_DECLVAR_CONTEXT(bgp, bgp);
4776 int idx_word = 2;
4777 struct peer *peer;
4778
4779 /* look up for neighbor by interface name config. */
4780 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4781 if (peer) {
4782 /* Request zebra to terminate IPv6 RAs on this interface. */
4783 if (peer->ifp)
4784 bgp_zebra_terminate_radv(peer->bgp, peer);
4785 peer_notify_unconfig(peer);
4786 peer_delete(peer);
4787 } else {
4788 vty_out(vty, "%% Create the bgp interface first\n");
4789 return CMD_WARNING_CONFIG_FAILED;
4790 }
4791 return CMD_SUCCESS;
4792 }
4793
4794 DEFUN (no_neighbor_peer_group,
4795 no_neighbor_peer_group_cmd,
4796 "no neighbor WORD peer-group",
4797 NO_STR
4798 NEIGHBOR_STR
4799 "Neighbor tag\n"
4800 "Configure peer-group\n")
4801 {
4802 VTY_DECLVAR_CONTEXT(bgp, bgp);
4803 int idx_word = 2;
4804 struct peer_group *group;
4805
4806 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4807 if (group) {
4808 peer_group_notify_unconfig(group);
4809 peer_group_delete(group);
4810 } else {
4811 vty_out(vty, "%% Create the peer-group first\n");
4812 return CMD_WARNING_CONFIG_FAILED;
4813 }
4814 return CMD_SUCCESS;
4815 }
4816
4817 DEFUN (no_neighbor_interface_peer_group_remote_as,
4818 no_neighbor_interface_peer_group_remote_as_cmd,
4819 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4820 NO_STR
4821 NEIGHBOR_STR
4822 "Interface name or neighbor tag\n"
4823 "Specify a BGP neighbor\n"
4824 AS_STR
4825 "Internal BGP peer\n"
4826 "External BGP peer\n")
4827 {
4828 VTY_DECLVAR_CONTEXT(bgp, bgp);
4829 int idx_word = 2;
4830 struct peer_group *group;
4831 struct peer *peer;
4832
4833 /* look up for neighbor by interface name config. */
4834 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4835 if (peer) {
4836 peer_as_change(peer, 0, AS_UNSPECIFIED);
4837 return CMD_SUCCESS;
4838 }
4839
4840 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4841 if (group)
4842 peer_group_remote_as_delete(group);
4843 else {
4844 vty_out(vty, "%% Create the peer-group or interface first\n");
4845 return CMD_WARNING_CONFIG_FAILED;
4846 }
4847 return CMD_SUCCESS;
4848 }
4849
4850 DEFUN (neighbor_local_as,
4851 neighbor_local_as_cmd,
4852 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4853 NEIGHBOR_STR
4854 NEIGHBOR_ADDR_STR2
4855 "Specify a local-as number\n"
4856 "AS number used as local AS\n")
4857 {
4858 int idx_peer = 1;
4859 int idx_number = 3;
4860 struct peer *peer;
4861 int ret;
4862 as_t as;
4863
4864 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4865 if (!peer)
4866 return CMD_WARNING_CONFIG_FAILED;
4867
4868 as = strtoul(argv[idx_number]->arg, NULL, 10);
4869 ret = peer_local_as_set(peer, as, 0, 0);
4870 return bgp_vty_return(vty, ret);
4871 }
4872
4873 DEFUN (neighbor_local_as_no_prepend,
4874 neighbor_local_as_no_prepend_cmd,
4875 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4876 NEIGHBOR_STR
4877 NEIGHBOR_ADDR_STR2
4878 "Specify a local-as number\n"
4879 "AS number used as local AS\n"
4880 "Do not prepend local-as to updates from ebgp peers\n")
4881 {
4882 int idx_peer = 1;
4883 int idx_number = 3;
4884 struct peer *peer;
4885 int ret;
4886 as_t as;
4887
4888 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4889 if (!peer)
4890 return CMD_WARNING_CONFIG_FAILED;
4891
4892 as = strtoul(argv[idx_number]->arg, NULL, 10);
4893 ret = peer_local_as_set(peer, as, 1, 0);
4894 return bgp_vty_return(vty, ret);
4895 }
4896
4897 DEFUN (neighbor_local_as_no_prepend_replace_as,
4898 neighbor_local_as_no_prepend_replace_as_cmd,
4899 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4900 NEIGHBOR_STR
4901 NEIGHBOR_ADDR_STR2
4902 "Specify a local-as number\n"
4903 "AS number used as local AS\n"
4904 "Do not prepend local-as to updates from ebgp peers\n"
4905 "Do not prepend local-as to updates from ibgp peers\n")
4906 {
4907 int idx_peer = 1;
4908 int idx_number = 3;
4909 struct peer *peer;
4910 int ret;
4911 as_t as;
4912
4913 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4914 if (!peer)
4915 return CMD_WARNING_CONFIG_FAILED;
4916
4917 as = strtoul(argv[idx_number]->arg, NULL, 10);
4918 ret = peer_local_as_set(peer, as, 1, 1);
4919 return bgp_vty_return(vty, ret);
4920 }
4921
4922 DEFUN (no_neighbor_local_as,
4923 no_neighbor_local_as_cmd,
4924 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4925 NO_STR
4926 NEIGHBOR_STR
4927 NEIGHBOR_ADDR_STR2
4928 "Specify a local-as number\n"
4929 "AS number used as local AS\n"
4930 "Do not prepend local-as to updates from ebgp peers\n"
4931 "Do not prepend local-as to updates from ibgp peers\n")
4932 {
4933 int idx_peer = 2;
4934 struct peer *peer;
4935 int ret;
4936
4937 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4938 if (!peer)
4939 return CMD_WARNING_CONFIG_FAILED;
4940
4941 ret = peer_local_as_unset(peer);
4942 return bgp_vty_return(vty, ret);
4943 }
4944
4945
4946 DEFUN (neighbor_solo,
4947 neighbor_solo_cmd,
4948 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4949 NEIGHBOR_STR
4950 NEIGHBOR_ADDR_STR2
4951 "Solo peer - part of its own update group\n")
4952 {
4953 int idx_peer = 1;
4954 struct peer *peer;
4955 int ret;
4956
4957 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4958 if (!peer)
4959 return CMD_WARNING_CONFIG_FAILED;
4960
4961 ret = update_group_adjust_soloness(peer, 1);
4962 return bgp_vty_return(vty, ret);
4963 }
4964
4965 DEFUN (no_neighbor_solo,
4966 no_neighbor_solo_cmd,
4967 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4968 NO_STR
4969 NEIGHBOR_STR
4970 NEIGHBOR_ADDR_STR2
4971 "Solo peer - part of its own update group\n")
4972 {
4973 int idx_peer = 2;
4974 struct peer *peer;
4975 int ret;
4976
4977 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4978 if (!peer)
4979 return CMD_WARNING_CONFIG_FAILED;
4980
4981 ret = update_group_adjust_soloness(peer, 0);
4982 return bgp_vty_return(vty, ret);
4983 }
4984
4985 DEFUN (neighbor_password,
4986 neighbor_password_cmd,
4987 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4988 NEIGHBOR_STR
4989 NEIGHBOR_ADDR_STR2
4990 "Set a password\n"
4991 "The password\n")
4992 {
4993 int idx_peer = 1;
4994 int idx_line = 3;
4995 struct peer *peer;
4996 int ret;
4997
4998 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4999 if (!peer)
5000 return CMD_WARNING_CONFIG_FAILED;
5001
5002 ret = peer_password_set(peer, argv[idx_line]->arg);
5003 return bgp_vty_return(vty, ret);
5004 }
5005
5006 DEFUN (no_neighbor_password,
5007 no_neighbor_password_cmd,
5008 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5009 NO_STR
5010 NEIGHBOR_STR
5011 NEIGHBOR_ADDR_STR2
5012 "Set a password\n"
5013 "The password\n")
5014 {
5015 int idx_peer = 2;
5016 struct peer *peer;
5017 int ret;
5018
5019 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5020 if (!peer)
5021 return CMD_WARNING_CONFIG_FAILED;
5022
5023 ret = peer_password_unset(peer);
5024 return bgp_vty_return(vty, ret);
5025 }
5026
5027 DEFUN (neighbor_activate,
5028 neighbor_activate_cmd,
5029 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5030 NEIGHBOR_STR
5031 NEIGHBOR_ADDR_STR2
5032 "Enable the Address Family for this Neighbor\n")
5033 {
5034 int idx_peer = 1;
5035 int ret;
5036 struct peer *peer;
5037
5038 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5039 if (!peer)
5040 return CMD_WARNING_CONFIG_FAILED;
5041
5042 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5043 return bgp_vty_return(vty, ret);
5044 }
5045
5046 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5048 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5049 "Enable the Address Family for this Neighbor\n")
5050
5051 DEFUN (no_neighbor_activate,
5052 no_neighbor_activate_cmd,
5053 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5054 NO_STR
5055 NEIGHBOR_STR
5056 NEIGHBOR_ADDR_STR2
5057 "Enable the Address Family for this Neighbor\n")
5058 {
5059 int idx_peer = 2;
5060 int ret;
5061 struct peer *peer;
5062
5063 /* Lookup peer. */
5064 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5065 if (!peer)
5066 return CMD_WARNING_CONFIG_FAILED;
5067
5068 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5069 return bgp_vty_return(vty, ret);
5070 }
5071
5072 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5073 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5074 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5075 "Enable the Address Family for this Neighbor\n")
5076
5077 DEFUN (neighbor_set_peer_group,
5078 neighbor_set_peer_group_cmd,
5079 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5080 NEIGHBOR_STR
5081 NEIGHBOR_ADDR_STR2
5082 "Member of the peer-group\n"
5083 "Peer-group name\n")
5084 {
5085 VTY_DECLVAR_CONTEXT(bgp, bgp);
5086 int idx_peer = 1;
5087 int idx_word = 3;
5088 int ret;
5089 as_t as;
5090 union sockunion su;
5091 struct peer *peer;
5092 struct peer_group *group;
5093
5094 ret = str2sockunion(argv[idx_peer]->arg, &su);
5095 if (ret < 0) {
5096 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5097 if (!peer) {
5098 vty_out(vty, "%% Malformed address or name: %s\n",
5099 argv[idx_peer]->arg);
5100 return CMD_WARNING_CONFIG_FAILED;
5101 }
5102 } else {
5103 if (peer_address_self_check(bgp, &su)) {
5104 vty_out(vty,
5105 "%% Can not configure the local system as neighbor\n");
5106 return CMD_WARNING_CONFIG_FAILED;
5107 }
5108
5109 /* Disallow for dynamic neighbor. */
5110 peer = peer_lookup(bgp, &su);
5111 if (peer && peer_dynamic_neighbor(peer)) {
5112 vty_out(vty,
5113 "%% Operation not allowed on a dynamic neighbor\n");
5114 return CMD_WARNING_CONFIG_FAILED;
5115 }
5116 }
5117
5118 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5119 if (!group) {
5120 vty_out(vty, "%% Configure the peer-group first\n");
5121 return CMD_WARNING_CONFIG_FAILED;
5122 }
5123
5124 ret = peer_group_bind(bgp, &su, peer, group, &as);
5125
5126 return bgp_vty_return(vty, ret);
5127 }
5128
5129 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5130 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5132 "Member of the peer-group\n"
5133 "Peer-group name\n")
5134
5135 DEFUN (no_neighbor_set_peer_group,
5136 no_neighbor_set_peer_group_cmd,
5137 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5138 NO_STR
5139 NEIGHBOR_STR
5140 NEIGHBOR_ADDR_STR2
5141 "Member of the peer-group\n"
5142 "Peer-group name\n")
5143 {
5144 VTY_DECLVAR_CONTEXT(bgp, bgp);
5145 int idx_peer = 2;
5146 int idx_word = 4;
5147 int ret;
5148 struct peer *peer;
5149 struct peer_group *group;
5150
5151 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5152 if (!peer)
5153 return CMD_WARNING_CONFIG_FAILED;
5154
5155 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5156 if (!group) {
5157 vty_out(vty, "%% Configure the peer-group first\n");
5158 return CMD_WARNING_CONFIG_FAILED;
5159 }
5160
5161 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5162 bgp_zebra_terminate_radv(peer->bgp, peer);
5163
5164 peer_notify_unconfig(peer);
5165 ret = peer_delete(peer);
5166
5167 return bgp_vty_return(vty, ret);
5168 }
5169
5170 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5171 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5172 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5173 "Member of the peer-group\n"
5174 "Peer-group name\n")
5175
5176 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5177 uint64_t flag, int set)
5178 {
5179 int ret;
5180 struct peer *peer;
5181
5182 peer = peer_and_group_lookup_vty(vty, ip_str);
5183 if (!peer)
5184 return CMD_WARNING_CONFIG_FAILED;
5185
5186 /*
5187 * If 'neighbor <interface>', then this is for directly connected peers,
5188 * we should not accept disable-connected-check.
5189 */
5190 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5191 vty_out(vty,
5192 "%s is directly connected peer, cannot accept disable-connected-check\n",
5193 ip_str);
5194 return CMD_WARNING_CONFIG_FAILED;
5195 }
5196
5197 if (!set && flag == PEER_FLAG_SHUTDOWN)
5198 peer_tx_shutdown_message_unset(peer);
5199
5200 if (set)
5201 ret = peer_flag_set(peer, flag);
5202 else
5203 ret = peer_flag_unset(peer, flag);
5204
5205 return bgp_vty_return(vty, ret);
5206 }
5207
5208 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5209 {
5210 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5211 }
5212
5213 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5214 uint64_t flag)
5215 {
5216 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5217 }
5218
5219 /* neighbor passive. */
5220 DEFUN (neighbor_passive,
5221 neighbor_passive_cmd,
5222 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5223 NEIGHBOR_STR
5224 NEIGHBOR_ADDR_STR2
5225 "Don't send open messages to this neighbor\n")
5226 {
5227 int idx_peer = 1;
5228 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5229 }
5230
5231 DEFUN (no_neighbor_passive,
5232 no_neighbor_passive_cmd,
5233 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5234 NO_STR
5235 NEIGHBOR_STR
5236 NEIGHBOR_ADDR_STR2
5237 "Don't send open messages to this neighbor\n")
5238 {
5239 int idx_peer = 2;
5240 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5241 }
5242
5243 /* neighbor shutdown. */
5244 DEFUN (neighbor_shutdown_msg,
5245 neighbor_shutdown_msg_cmd,
5246 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5247 NEIGHBOR_STR
5248 NEIGHBOR_ADDR_STR2
5249 "Administratively shut down this neighbor\n"
5250 "Add a shutdown message (RFC 8203)\n"
5251 "Shutdown message\n")
5252 {
5253 int idx_peer = 1;
5254
5255 if (argc >= 5) {
5256 struct peer *peer =
5257 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5258 char *message;
5259
5260 if (!peer)
5261 return CMD_WARNING_CONFIG_FAILED;
5262 message = argv_concat(argv, argc, 4);
5263 peer_tx_shutdown_message_set(peer, message);
5264 XFREE(MTYPE_TMP, message);
5265 }
5266
5267 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5268 }
5269
5270 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5271 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5272 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5273 "Administratively shut down this neighbor\n")
5274
5275 DEFUN (no_neighbor_shutdown_msg,
5276 no_neighbor_shutdown_msg_cmd,
5277 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5278 NO_STR
5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Administratively shut down this neighbor\n"
5282 "Remove a shutdown message (RFC 8203)\n"
5283 "Shutdown message\n")
5284 {
5285 int idx_peer = 2;
5286
5287 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5288 PEER_FLAG_SHUTDOWN);
5289 }
5290
5291 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5292 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5293 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5294 "Administratively shut down this neighbor\n")
5295
5296 DEFUN(neighbor_shutdown_rtt,
5297 neighbor_shutdown_rtt_cmd,
5298 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5299 NEIGHBOR_STR
5300 NEIGHBOR_ADDR_STR2
5301 "Administratively shut down this neighbor\n"
5302 "Shutdown if round-trip-time is higher than expected\n"
5303 "Round-trip-time in milliseconds\n"
5304 "Specify the number of keepalives before shutdown\n"
5305 "The number of keepalives with higher RTT to shutdown\n")
5306 {
5307 int idx_peer = 1;
5308 int idx_rtt = 4;
5309 int idx_count = 0;
5310 struct peer *peer;
5311
5312 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5313
5314 if (!peer)
5315 return CMD_WARNING_CONFIG_FAILED;
5316
5317 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5318
5319 if (argv_find(argv, argc, "count", &idx_count))
5320 peer->rtt_keepalive_conf =
5321 strtol(argv[idx_count + 1]->arg, NULL, 10);
5322
5323 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5324 PEER_FLAG_RTT_SHUTDOWN);
5325 }
5326
5327 DEFUN(no_neighbor_shutdown_rtt,
5328 no_neighbor_shutdown_rtt_cmd,
5329 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5330 NO_STR
5331 NEIGHBOR_STR
5332 NEIGHBOR_ADDR_STR2
5333 "Administratively shut down this neighbor\n"
5334 "Shutdown if round-trip-time is higher than expected\n"
5335 "Round-trip-time in milliseconds\n"
5336 "Specify the number of keepalives before shutdown\n"
5337 "The number of keepalives with higher RTT to shutdown\n")
5338 {
5339 int idx_peer = 2;
5340 struct peer *peer;
5341
5342 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5343
5344 if (!peer)
5345 return CMD_WARNING_CONFIG_FAILED;
5346
5347 peer->rtt_expected = 0;
5348 peer->rtt_keepalive_conf = 1;
5349
5350 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5351 PEER_FLAG_RTT_SHUTDOWN);
5352 }
5353
5354 /* neighbor capability dynamic. */
5355 DEFUN (neighbor_capability_dynamic,
5356 neighbor_capability_dynamic_cmd,
5357 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5358 NEIGHBOR_STR
5359 NEIGHBOR_ADDR_STR2
5360 "Advertise capability to the peer\n"
5361 "Advertise dynamic capability to this neighbor\n")
5362 {
5363 int idx_peer = 1;
5364 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5365 PEER_FLAG_DYNAMIC_CAPABILITY);
5366 }
5367
5368 DEFUN (no_neighbor_capability_dynamic,
5369 no_neighbor_capability_dynamic_cmd,
5370 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5371 NO_STR
5372 NEIGHBOR_STR
5373 NEIGHBOR_ADDR_STR2
5374 "Advertise capability to the peer\n"
5375 "Advertise dynamic capability to this neighbor\n")
5376 {
5377 int idx_peer = 2;
5378 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5379 PEER_FLAG_DYNAMIC_CAPABILITY);
5380 }
5381
5382 /* neighbor dont-capability-negotiate */
5383 DEFUN (neighbor_dont_capability_negotiate,
5384 neighbor_dont_capability_negotiate_cmd,
5385 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5386 NEIGHBOR_STR
5387 NEIGHBOR_ADDR_STR2
5388 "Do not perform capability negotiation\n")
5389 {
5390 int idx_peer = 1;
5391 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5392 PEER_FLAG_DONT_CAPABILITY);
5393 }
5394
5395 DEFUN (no_neighbor_dont_capability_negotiate,
5396 no_neighbor_dont_capability_negotiate_cmd,
5397 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5398 NO_STR
5399 NEIGHBOR_STR
5400 NEIGHBOR_ADDR_STR2
5401 "Do not perform capability negotiation\n")
5402 {
5403 int idx_peer = 2;
5404 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5405 PEER_FLAG_DONT_CAPABILITY);
5406 }
5407
5408 /* neighbor capability extended next hop encoding */
5409 DEFUN (neighbor_capability_enhe,
5410 neighbor_capability_enhe_cmd,
5411 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5412 NEIGHBOR_STR
5413 NEIGHBOR_ADDR_STR2
5414 "Advertise capability to the peer\n"
5415 "Advertise extended next-hop capability to the peer\n")
5416 {
5417 int idx_peer = 1;
5418 struct peer *peer;
5419
5420 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5421 if (peer && peer->conf_if)
5422 return CMD_SUCCESS;
5423
5424 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5425 PEER_FLAG_CAPABILITY_ENHE);
5426 }
5427
5428 DEFUN (no_neighbor_capability_enhe,
5429 no_neighbor_capability_enhe_cmd,
5430 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5431 NO_STR
5432 NEIGHBOR_STR
5433 NEIGHBOR_ADDR_STR2
5434 "Advertise capability to the peer\n"
5435 "Advertise extended next-hop capability to the peer\n")
5436 {
5437 int idx_peer = 2;
5438 struct peer *peer;
5439
5440 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5441 if (peer && peer->conf_if) {
5442 vty_out(vty,
5443 "Peer %s cannot have capability extended-nexthop turned off\n",
5444 argv[idx_peer]->arg);
5445 return CMD_WARNING_CONFIG_FAILED;
5446 }
5447
5448 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5449 PEER_FLAG_CAPABILITY_ENHE);
5450 }
5451
5452 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5453 afi_t afi, safi_t safi, uint32_t flag,
5454 int set)
5455 {
5456 int ret;
5457 struct peer *peer;
5458
5459 peer = peer_and_group_lookup_vty(vty, peer_str);
5460 if (!peer)
5461 return CMD_WARNING_CONFIG_FAILED;
5462
5463 if (set)
5464 ret = peer_af_flag_set(peer, afi, safi, flag);
5465 else
5466 ret = peer_af_flag_unset(peer, afi, safi, flag);
5467
5468 return bgp_vty_return(vty, ret);
5469 }
5470
5471 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5472 afi_t afi, safi_t safi, uint32_t flag)
5473 {
5474 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5475 }
5476
5477 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5478 afi_t afi, safi_t safi, uint32_t flag)
5479 {
5480 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5481 }
5482
5483 /* neighbor capability orf prefix-list. */
5484 DEFUN (neighbor_capability_orf_prefix,
5485 neighbor_capability_orf_prefix_cmd,
5486 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5487 NEIGHBOR_STR
5488 NEIGHBOR_ADDR_STR2
5489 "Advertise capability to the peer\n"
5490 "Advertise ORF capability to the peer\n"
5491 "Advertise prefixlist ORF capability to this neighbor\n"
5492 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5493 "Capability to RECEIVE the ORF from this neighbor\n"
5494 "Capability to SEND the ORF to this neighbor\n")
5495 {
5496 int idx_send_recv = 5;
5497 char *peer_str = argv[1]->arg;
5498 struct peer *peer;
5499 afi_t afi = bgp_node_afi(vty);
5500 safi_t safi = bgp_node_safi(vty);
5501
5502 peer = peer_and_group_lookup_vty(vty, peer_str);
5503 if (!peer)
5504 return CMD_WARNING_CONFIG_FAILED;
5505
5506 if (strmatch(argv[idx_send_recv]->text, "send"))
5507 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5508 PEER_FLAG_ORF_PREFIX_SM);
5509
5510 if (strmatch(argv[idx_send_recv]->text, "receive"))
5511 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5512 PEER_FLAG_ORF_PREFIX_RM);
5513
5514 if (strmatch(argv[idx_send_recv]->text, "both"))
5515 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5516 PEER_FLAG_ORF_PREFIX_SM)
5517 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5518 PEER_FLAG_ORF_PREFIX_RM);
5519
5520 return CMD_WARNING_CONFIG_FAILED;
5521 }
5522
5523 ALIAS_HIDDEN(
5524 neighbor_capability_orf_prefix,
5525 neighbor_capability_orf_prefix_hidden_cmd,
5526 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5527 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5528 "Advertise capability to the peer\n"
5529 "Advertise ORF capability to the peer\n"
5530 "Advertise prefixlist ORF capability to this neighbor\n"
5531 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5532 "Capability to RECEIVE the ORF from this neighbor\n"
5533 "Capability to SEND the ORF to this neighbor\n")
5534
5535 DEFUN (no_neighbor_capability_orf_prefix,
5536 no_neighbor_capability_orf_prefix_cmd,
5537 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5538 NO_STR
5539 NEIGHBOR_STR
5540 NEIGHBOR_ADDR_STR2
5541 "Advertise capability to the peer\n"
5542 "Advertise ORF capability to the peer\n"
5543 "Advertise prefixlist ORF capability to this neighbor\n"
5544 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5545 "Capability to RECEIVE the ORF from this neighbor\n"
5546 "Capability to SEND the ORF to this neighbor\n")
5547 {
5548 int idx_send_recv = 6;
5549 char *peer_str = argv[2]->arg;
5550 struct peer *peer;
5551 afi_t afi = bgp_node_afi(vty);
5552 safi_t safi = bgp_node_safi(vty);
5553
5554 peer = peer_and_group_lookup_vty(vty, peer_str);
5555 if (!peer)
5556 return CMD_WARNING_CONFIG_FAILED;
5557
5558 if (strmatch(argv[idx_send_recv]->text, "send"))
5559 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5560 PEER_FLAG_ORF_PREFIX_SM);
5561
5562 if (strmatch(argv[idx_send_recv]->text, "receive"))
5563 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5564 PEER_FLAG_ORF_PREFIX_RM);
5565
5566 if (strmatch(argv[idx_send_recv]->text, "both"))
5567 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5568 PEER_FLAG_ORF_PREFIX_SM)
5569 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5570 PEER_FLAG_ORF_PREFIX_RM);
5571
5572 return CMD_WARNING_CONFIG_FAILED;
5573 }
5574
5575 ALIAS_HIDDEN(
5576 no_neighbor_capability_orf_prefix,
5577 no_neighbor_capability_orf_prefix_hidden_cmd,
5578 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5579 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5580 "Advertise capability to the peer\n"
5581 "Advertise ORF capability to the peer\n"
5582 "Advertise prefixlist ORF capability to this neighbor\n"
5583 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5584 "Capability to RECEIVE the ORF from this neighbor\n"
5585 "Capability to SEND the ORF to this neighbor\n")
5586
5587 /* neighbor next-hop-self. */
5588 DEFUN (neighbor_nexthop_self,
5589 neighbor_nexthop_self_cmd,
5590 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5591 NEIGHBOR_STR
5592 NEIGHBOR_ADDR_STR2
5593 "Disable the next hop calculation for this neighbor\n")
5594 {
5595 int idx_peer = 1;
5596 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5597 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5598 }
5599
5600 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5601 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5602 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5603 "Disable the next hop calculation for this neighbor\n")
5604
5605 /* neighbor next-hop-self. */
5606 DEFUN (neighbor_nexthop_self_force,
5607 neighbor_nexthop_self_force_cmd,
5608 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5609 NEIGHBOR_STR
5610 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 int idx_peer = 1;
5615 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5616 bgp_node_safi(vty),
5617 PEER_FLAG_FORCE_NEXTHOP_SELF);
5618 }
5619
5620 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5621 neighbor_nexthop_self_force_hidden_cmd,
5622 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5623 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5624 "Disable the next hop calculation for this neighbor\n"
5625 "Set the next hop to self for reflected routes\n")
5626
5627 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5628 neighbor_nexthop_self_all_hidden_cmd,
5629 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Disable the next hop calculation for this neighbor\n"
5632 "Set the next hop to self for reflected routes\n")
5633
5634 DEFUN (no_neighbor_nexthop_self,
5635 no_neighbor_nexthop_self_cmd,
5636 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5637 NO_STR
5638 NEIGHBOR_STR
5639 NEIGHBOR_ADDR_STR2
5640 "Disable the next hop calculation for this neighbor\n")
5641 {
5642 int idx_peer = 2;
5643 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5644 bgp_node_afi(vty), bgp_node_safi(vty),
5645 PEER_FLAG_NEXTHOP_SELF);
5646 }
5647
5648 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5649 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5650 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5651 "Disable the next hop calculation for this neighbor\n")
5652
5653 DEFUN (no_neighbor_nexthop_self_force,
5654 no_neighbor_nexthop_self_force_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5656 NO_STR
5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Disable the next hop calculation for this neighbor\n"
5660 "Set the next hop to self for reflected routes\n")
5661 {
5662 int idx_peer = 2;
5663 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5664 bgp_node_afi(vty), bgp_node_safi(vty),
5665 PEER_FLAG_FORCE_NEXTHOP_SELF);
5666 }
5667
5668 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5669 no_neighbor_nexthop_self_force_hidden_cmd,
5670 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5672 "Disable the next hop calculation for this neighbor\n"
5673 "Set the next hop to self for reflected routes\n")
5674
5675 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5676 no_neighbor_nexthop_self_all_hidden_cmd,
5677 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5678 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5679 "Disable the next hop calculation for this neighbor\n"
5680 "Set the next hop to self for reflected routes\n")
5681
5682 /* neighbor as-override */
5683 DEFUN (neighbor_as_override,
5684 neighbor_as_override_cmd,
5685 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5686 NEIGHBOR_STR
5687 NEIGHBOR_ADDR_STR2
5688 "Override ASNs in outbound updates if aspath equals remote-as\n")
5689 {
5690 int idx_peer = 1;
5691 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5692 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5693 }
5694
5695 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5696 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5697 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5698 "Override ASNs in outbound updates if aspath equals remote-as\n")
5699
5700 DEFUN (no_neighbor_as_override,
5701 no_neighbor_as_override_cmd,
5702 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5703 NO_STR
5704 NEIGHBOR_STR
5705 NEIGHBOR_ADDR_STR2
5706 "Override ASNs in outbound updates if aspath equals remote-as\n")
5707 {
5708 int idx_peer = 2;
5709 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5710 bgp_node_afi(vty), bgp_node_safi(vty),
5711 PEER_FLAG_AS_OVERRIDE);
5712 }
5713
5714 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5715 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5716 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5717 "Override ASNs in outbound updates if aspath equals remote-as\n")
5718
5719 /* neighbor remove-private-AS. */
5720 DEFUN (neighbor_remove_private_as,
5721 neighbor_remove_private_as_cmd,
5722 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5723 NEIGHBOR_STR
5724 NEIGHBOR_ADDR_STR2
5725 "Remove private ASNs in outbound updates\n")
5726 {
5727 int idx_peer = 1;
5728 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5729 bgp_node_safi(vty),
5730 PEER_FLAG_REMOVE_PRIVATE_AS);
5731 }
5732
5733 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5734 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Remove private ASNs in outbound updates\n")
5737
5738 DEFUN (neighbor_remove_private_as_all,
5739 neighbor_remove_private_as_all_cmd,
5740 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5741 NEIGHBOR_STR
5742 NEIGHBOR_ADDR_STR2
5743 "Remove private ASNs in outbound updates\n"
5744 "Apply to all AS numbers\n")
5745 {
5746 int idx_peer = 1;
5747 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5748 bgp_node_safi(vty),
5749 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5750 }
5751
5752 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5753 neighbor_remove_private_as_all_hidden_cmd,
5754 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5755 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5756 "Remove private ASNs in outbound updates\n"
5757 "Apply to all AS numbers")
5758
5759 DEFUN (neighbor_remove_private_as_replace_as,
5760 neighbor_remove_private_as_replace_as_cmd,
5761 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5762 NEIGHBOR_STR
5763 NEIGHBOR_ADDR_STR2
5764 "Remove private ASNs in outbound updates\n"
5765 "Replace private ASNs with our ASN in outbound updates\n")
5766 {
5767 int idx_peer = 1;
5768 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5769 bgp_node_safi(vty),
5770 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5771 }
5772
5773 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5774 neighbor_remove_private_as_replace_as_hidden_cmd,
5775 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5776 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5777 "Remove private ASNs in outbound updates\n"
5778 "Replace private ASNs with our ASN in outbound updates\n")
5779
5780 DEFUN (neighbor_remove_private_as_all_replace_as,
5781 neighbor_remove_private_as_all_replace_as_cmd,
5782 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5783 NEIGHBOR_STR
5784 NEIGHBOR_ADDR_STR2
5785 "Remove private ASNs in outbound updates\n"
5786 "Apply to all AS numbers\n"
5787 "Replace private ASNs with our ASN in outbound updates\n")
5788 {
5789 int idx_peer = 1;
5790 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5791 bgp_node_safi(vty),
5792 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5793 }
5794
5795 ALIAS_HIDDEN(
5796 neighbor_remove_private_as_all_replace_as,
5797 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5798 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5800 "Remove private ASNs in outbound updates\n"
5801 "Apply to all AS numbers\n"
5802 "Replace private ASNs with our ASN in outbound updates\n")
5803
5804 DEFUN (no_neighbor_remove_private_as,
5805 no_neighbor_remove_private_as_cmd,
5806 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5807 NO_STR
5808 NEIGHBOR_STR
5809 NEIGHBOR_ADDR_STR2
5810 "Remove private ASNs in outbound updates\n")
5811 {
5812 int idx_peer = 2;
5813 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5814 bgp_node_afi(vty), bgp_node_safi(vty),
5815 PEER_FLAG_REMOVE_PRIVATE_AS);
5816 }
5817
5818 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5819 no_neighbor_remove_private_as_hidden_cmd,
5820 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5822 "Remove private ASNs in outbound updates\n")
5823
5824 DEFUN (no_neighbor_remove_private_as_all,
5825 no_neighbor_remove_private_as_all_cmd,
5826 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5827 NO_STR
5828 NEIGHBOR_STR
5829 NEIGHBOR_ADDR_STR2
5830 "Remove private ASNs in outbound updates\n"
5831 "Apply to all AS numbers\n")
5832 {
5833 int idx_peer = 2;
5834 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5835 bgp_node_afi(vty), bgp_node_safi(vty),
5836 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5837 }
5838
5839 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5840 no_neighbor_remove_private_as_all_hidden_cmd,
5841 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5842 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Remove private ASNs in outbound updates\n"
5844 "Apply to all AS numbers\n")
5845
5846 DEFUN (no_neighbor_remove_private_as_replace_as,
5847 no_neighbor_remove_private_as_replace_as_cmd,
5848 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5849 NO_STR
5850 NEIGHBOR_STR
5851 NEIGHBOR_ADDR_STR2
5852 "Remove private ASNs in outbound updates\n"
5853 "Replace private ASNs with our ASN in outbound updates\n")
5854 {
5855 int idx_peer = 2;
5856 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5857 bgp_node_afi(vty), bgp_node_safi(vty),
5858 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5859 }
5860
5861 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5862 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5863 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5864 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5865 "Remove private ASNs in outbound updates\n"
5866 "Replace private ASNs with our ASN in outbound updates\n")
5867
5868 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5869 no_neighbor_remove_private_as_all_replace_as_cmd,
5870 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5871 NO_STR
5872 NEIGHBOR_STR
5873 NEIGHBOR_ADDR_STR2
5874 "Remove private ASNs in outbound updates\n"
5875 "Apply to all AS numbers\n"
5876 "Replace private ASNs with our ASN in outbound updates\n")
5877 {
5878 int idx_peer = 2;
5879 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5880 bgp_node_afi(vty), bgp_node_safi(vty),
5881 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5882 }
5883
5884 ALIAS_HIDDEN(
5885 no_neighbor_remove_private_as_all_replace_as,
5886 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5887 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5888 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5889 "Remove private ASNs in outbound updates\n"
5890 "Apply to all AS numbers\n"
5891 "Replace private ASNs with our ASN in outbound updates\n")
5892
5893
5894 /* neighbor send-community. */
5895 DEFUN (neighbor_send_community,
5896 neighbor_send_community_cmd,
5897 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5898 NEIGHBOR_STR
5899 NEIGHBOR_ADDR_STR2
5900 "Send Community attribute to this neighbor\n")
5901 {
5902 int idx_peer = 1;
5903
5904 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5905 bgp_node_safi(vty),
5906 PEER_FLAG_SEND_COMMUNITY);
5907 }
5908
5909 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5910 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5912 "Send Community attribute to this neighbor\n")
5913
5914 DEFUN (no_neighbor_send_community,
5915 no_neighbor_send_community_cmd,
5916 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5917 NO_STR
5918 NEIGHBOR_STR
5919 NEIGHBOR_ADDR_STR2
5920 "Send Community attribute to this neighbor\n")
5921 {
5922 int idx_peer = 2;
5923
5924 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5925 bgp_node_afi(vty), bgp_node_safi(vty),
5926 PEER_FLAG_SEND_COMMUNITY);
5927 }
5928
5929 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5930 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5931 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5932 "Send Community attribute to this neighbor\n")
5933
5934 /* neighbor send-community extended. */
5935 DEFUN (neighbor_send_community_type,
5936 neighbor_send_community_type_cmd,
5937 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5938 NEIGHBOR_STR
5939 NEIGHBOR_ADDR_STR2
5940 "Send Community attribute to this neighbor\n"
5941 "Send Standard and Extended Community attributes\n"
5942 "Send Standard, Large and Extended Community attributes\n"
5943 "Send Extended Community attributes\n"
5944 "Send Standard Community attributes\n"
5945 "Send Large Community attributes\n")
5946 {
5947 const char *type = argv[argc - 1]->text;
5948 char *peer_str = argv[1]->arg;
5949 struct peer *peer;
5950 afi_t afi = bgp_node_afi(vty);
5951 safi_t safi = bgp_node_safi(vty);
5952
5953 peer = peer_and_group_lookup_vty(vty, peer_str);
5954 if (!peer)
5955 return CMD_WARNING_CONFIG_FAILED;
5956
5957 if (strmatch(type, "standard"))
5958 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5959 PEER_FLAG_SEND_COMMUNITY);
5960
5961 if (strmatch(type, "extended"))
5962 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5963 PEER_FLAG_SEND_EXT_COMMUNITY);
5964
5965 if (strmatch(type, "large"))
5966 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5967 PEER_FLAG_SEND_LARGE_COMMUNITY);
5968
5969 if (strmatch(type, "both")) {
5970 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5971 PEER_FLAG_SEND_COMMUNITY)
5972 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5973 PEER_FLAG_SEND_EXT_COMMUNITY);
5974 }
5975 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5976 PEER_FLAG_SEND_COMMUNITY)
5977 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5978 PEER_FLAG_SEND_EXT_COMMUNITY)
5979 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5980 PEER_FLAG_SEND_LARGE_COMMUNITY);
5981 }
5982
5983 ALIAS_HIDDEN(
5984 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5985 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5986 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5987 "Send Community attribute to this neighbor\n"
5988 "Send Standard and Extended Community attributes\n"
5989 "Send Standard, Large and Extended Community attributes\n"
5990 "Send Extended Community attributes\n"
5991 "Send Standard Community attributes\n"
5992 "Send Large Community attributes\n")
5993
5994 DEFUN (no_neighbor_send_community_type,
5995 no_neighbor_send_community_type_cmd,
5996 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5997 NO_STR
5998 NEIGHBOR_STR
5999 NEIGHBOR_ADDR_STR2
6000 "Send Community attribute to this neighbor\n"
6001 "Send Standard and Extended Community attributes\n"
6002 "Send Standard, Large and Extended Community attributes\n"
6003 "Send Extended Community attributes\n"
6004 "Send Standard Community attributes\n"
6005 "Send Large Community attributes\n")
6006 {
6007 const char *type = argv[argc - 1]->text;
6008 char *peer_str = argv[2]->arg;
6009 struct peer *peer;
6010 afi_t afi = bgp_node_afi(vty);
6011 safi_t safi = bgp_node_safi(vty);
6012
6013 peer = peer_and_group_lookup_vty(vty, peer_str);
6014 if (!peer)
6015 return CMD_WARNING_CONFIG_FAILED;
6016
6017 if (strmatch(type, "standard"))
6018 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6019 PEER_FLAG_SEND_COMMUNITY);
6020
6021 if (strmatch(type, "extended"))
6022 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6023 PEER_FLAG_SEND_EXT_COMMUNITY);
6024
6025 if (strmatch(type, "large"))
6026 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6027 PEER_FLAG_SEND_LARGE_COMMUNITY);
6028
6029 if (strmatch(type, "both")) {
6030
6031 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6032 PEER_FLAG_SEND_COMMUNITY)
6033 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6034 PEER_FLAG_SEND_EXT_COMMUNITY);
6035 }
6036
6037 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6038 PEER_FLAG_SEND_COMMUNITY)
6039 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6040 PEER_FLAG_SEND_EXT_COMMUNITY)
6041 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6042 PEER_FLAG_SEND_LARGE_COMMUNITY);
6043 }
6044
6045 ALIAS_HIDDEN(
6046 no_neighbor_send_community_type,
6047 no_neighbor_send_community_type_hidden_cmd,
6048 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6049 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6050 "Send Community attribute to this neighbor\n"
6051 "Send Standard and Extended Community attributes\n"
6052 "Send Standard, Large and Extended Community attributes\n"
6053 "Send Extended Community attributes\n"
6054 "Send Standard Community attributes\n"
6055 "Send Large Community attributes\n")
6056
6057 /* neighbor soft-reconfig. */
6058 DEFUN (neighbor_soft_reconfiguration,
6059 neighbor_soft_reconfiguration_cmd,
6060 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6061 NEIGHBOR_STR
6062 NEIGHBOR_ADDR_STR2
6063 "Per neighbor soft reconfiguration\n"
6064 "Allow inbound soft reconfiguration for this neighbor\n")
6065 {
6066 int idx_peer = 1;
6067 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6068 bgp_node_safi(vty),
6069 PEER_FLAG_SOFT_RECONFIG);
6070 }
6071
6072 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6073 neighbor_soft_reconfiguration_hidden_cmd,
6074 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6075 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6076 "Per neighbor soft reconfiguration\n"
6077 "Allow inbound soft reconfiguration for this neighbor\n")
6078
6079 DEFUN (no_neighbor_soft_reconfiguration,
6080 no_neighbor_soft_reconfiguration_cmd,
6081 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6082 NO_STR
6083 NEIGHBOR_STR
6084 NEIGHBOR_ADDR_STR2
6085 "Per neighbor soft reconfiguration\n"
6086 "Allow inbound soft reconfiguration for this neighbor\n")
6087 {
6088 int idx_peer = 2;
6089 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6090 bgp_node_afi(vty), bgp_node_safi(vty),
6091 PEER_FLAG_SOFT_RECONFIG);
6092 }
6093
6094 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6095 no_neighbor_soft_reconfiguration_hidden_cmd,
6096 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6097 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6098 "Per neighbor soft reconfiguration\n"
6099 "Allow inbound soft reconfiguration for this neighbor\n")
6100
6101 DEFUN (neighbor_route_reflector_client,
6102 neighbor_route_reflector_client_cmd,
6103 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6104 NEIGHBOR_STR
6105 NEIGHBOR_ADDR_STR2
6106 "Configure a neighbor as Route Reflector client\n")
6107 {
6108 int idx_peer = 1;
6109 struct peer *peer;
6110
6111
6112 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6113 if (!peer)
6114 return CMD_WARNING_CONFIG_FAILED;
6115
6116 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6117 bgp_node_safi(vty),
6118 PEER_FLAG_REFLECTOR_CLIENT);
6119 }
6120
6121 ALIAS_HIDDEN(neighbor_route_reflector_client,
6122 neighbor_route_reflector_client_hidden_cmd,
6123 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6124 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6125 "Configure a neighbor as Route Reflector client\n")
6126
6127 DEFUN (no_neighbor_route_reflector_client,
6128 no_neighbor_route_reflector_client_cmd,
6129 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6130 NO_STR
6131 NEIGHBOR_STR
6132 NEIGHBOR_ADDR_STR2
6133 "Configure a neighbor as Route Reflector client\n")
6134 {
6135 int idx_peer = 2;
6136 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6137 bgp_node_afi(vty), bgp_node_safi(vty),
6138 PEER_FLAG_REFLECTOR_CLIENT);
6139 }
6140
6141 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6142 no_neighbor_route_reflector_client_hidden_cmd,
6143 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6144 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6145 "Configure a neighbor as Route Reflector client\n")
6146
6147 /* neighbor route-server-client. */
6148 DEFUN (neighbor_route_server_client,
6149 neighbor_route_server_client_cmd,
6150 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6151 NEIGHBOR_STR
6152 NEIGHBOR_ADDR_STR2
6153 "Configure a neighbor as Route Server client\n")
6154 {
6155 int idx_peer = 1;
6156 struct peer *peer;
6157
6158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6159 if (!peer)
6160 return CMD_WARNING_CONFIG_FAILED;
6161 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6162 bgp_node_safi(vty),
6163 PEER_FLAG_RSERVER_CLIENT);
6164 }
6165
6166 ALIAS_HIDDEN(neighbor_route_server_client,
6167 neighbor_route_server_client_hidden_cmd,
6168 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6169 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6170 "Configure a neighbor as Route Server client\n")
6171
6172 DEFUN (no_neighbor_route_server_client,
6173 no_neighbor_route_server_client_cmd,
6174 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6175 NO_STR
6176 NEIGHBOR_STR
6177 NEIGHBOR_ADDR_STR2
6178 "Configure a neighbor as Route Server client\n")
6179 {
6180 int idx_peer = 2;
6181 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6182 bgp_node_afi(vty), bgp_node_safi(vty),
6183 PEER_FLAG_RSERVER_CLIENT);
6184 }
6185
6186 ALIAS_HIDDEN(no_neighbor_route_server_client,
6187 no_neighbor_route_server_client_hidden_cmd,
6188 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6189 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6190 "Configure a neighbor as Route Server client\n")
6191
6192 DEFUN (neighbor_nexthop_local_unchanged,
6193 neighbor_nexthop_local_unchanged_cmd,
6194 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6195 NEIGHBOR_STR
6196 NEIGHBOR_ADDR_STR2
6197 "Configure treatment of outgoing link-local nexthop attribute\n"
6198 "Leave link-local nexthop unchanged for this peer\n")
6199 {
6200 int idx_peer = 1;
6201 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6202 bgp_node_safi(vty),
6203 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6204 }
6205
6206 DEFUN (no_neighbor_nexthop_local_unchanged,
6207 no_neighbor_nexthop_local_unchanged_cmd,
6208 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6209 NO_STR
6210 NEIGHBOR_STR
6211 NEIGHBOR_ADDR_STR2
6212 "Configure treatment of outgoing link-local-nexthop attribute\n"
6213 "Leave link-local nexthop unchanged for this peer\n")
6214 {
6215 int idx_peer = 2;
6216 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6217 bgp_node_afi(vty), bgp_node_safi(vty),
6218 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6219 }
6220
6221 DEFUN (neighbor_attr_unchanged,
6222 neighbor_attr_unchanged_cmd,
6223 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6224 NEIGHBOR_STR
6225 NEIGHBOR_ADDR_STR2
6226 "BGP attribute is propagated unchanged to this neighbor\n"
6227 "As-path attribute\n"
6228 "Nexthop attribute\n"
6229 "Med attribute\n")
6230 {
6231 int idx = 0;
6232 char *peer_str = argv[1]->arg;
6233 struct peer *peer;
6234 bool aspath = false;
6235 bool nexthop = false;
6236 bool med = false;
6237 afi_t afi = bgp_node_afi(vty);
6238 safi_t safi = bgp_node_safi(vty);
6239 int ret = 0;
6240
6241 peer = peer_and_group_lookup_vty(vty, peer_str);
6242 if (!peer)
6243 return CMD_WARNING_CONFIG_FAILED;
6244
6245 if (argv_find(argv, argc, "as-path", &idx))
6246 aspath = true;
6247
6248 idx = 0;
6249 if (argv_find(argv, argc, "next-hop", &idx))
6250 nexthop = true;
6251
6252 idx = 0;
6253 if (argv_find(argv, argc, "med", &idx))
6254 med = true;
6255
6256 /* no flags means all of them! */
6257 if (!aspath && !nexthop && !med) {
6258 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6259 PEER_FLAG_AS_PATH_UNCHANGED);
6260 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6261 PEER_FLAG_NEXTHOP_UNCHANGED);
6262 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6263 PEER_FLAG_MED_UNCHANGED);
6264 } else {
6265 if (!aspath) {
6266 if (peer_af_flag_check(peer, afi, safi,
6267 PEER_FLAG_AS_PATH_UNCHANGED)) {
6268 ret |= peer_af_flag_unset_vty(
6269 vty, peer_str, afi, safi,
6270 PEER_FLAG_AS_PATH_UNCHANGED);
6271 }
6272 } else
6273 ret |= peer_af_flag_set_vty(
6274 vty, peer_str, afi, safi,
6275 PEER_FLAG_AS_PATH_UNCHANGED);
6276
6277 if (!nexthop) {
6278 if (peer_af_flag_check(peer, afi, safi,
6279 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6280 ret |= peer_af_flag_unset_vty(
6281 vty, peer_str, afi, safi,
6282 PEER_FLAG_NEXTHOP_UNCHANGED);
6283 }
6284 } else
6285 ret |= peer_af_flag_set_vty(
6286 vty, peer_str, afi, safi,
6287 PEER_FLAG_NEXTHOP_UNCHANGED);
6288
6289 if (!med) {
6290 if (peer_af_flag_check(peer, afi, safi,
6291 PEER_FLAG_MED_UNCHANGED)) {
6292 ret |= peer_af_flag_unset_vty(
6293 vty, peer_str, afi, safi,
6294 PEER_FLAG_MED_UNCHANGED);
6295 }
6296 } else
6297 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6298 PEER_FLAG_MED_UNCHANGED);
6299 }
6300
6301 return ret;
6302 }
6303
6304 ALIAS_HIDDEN(
6305 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6306 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6307 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 DEFUN (no_neighbor_attr_unchanged,
6314 no_neighbor_attr_unchanged_cmd,
6315 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6316 NO_STR
6317 NEIGHBOR_STR
6318 NEIGHBOR_ADDR_STR2
6319 "BGP attribute is propagated unchanged to this neighbor\n"
6320 "As-path attribute\n"
6321 "Nexthop attribute\n"
6322 "Med attribute\n")
6323 {
6324 int idx = 0;
6325 char *peer_str = argv[2]->arg;
6326 struct peer *peer;
6327 bool aspath = false;
6328 bool nexthop = false;
6329 bool med = false;
6330 afi_t afi = bgp_node_afi(vty);
6331 safi_t safi = bgp_node_safi(vty);
6332 int ret = 0;
6333
6334 peer = peer_and_group_lookup_vty(vty, peer_str);
6335 if (!peer)
6336 return CMD_WARNING_CONFIG_FAILED;
6337
6338 if (argv_find(argv, argc, "as-path", &idx))
6339 aspath = true;
6340
6341 idx = 0;
6342 if (argv_find(argv, argc, "next-hop", &idx))
6343 nexthop = true;
6344
6345 idx = 0;
6346 if (argv_find(argv, argc, "med", &idx))
6347 med = true;
6348
6349 if (!aspath && !nexthop && !med) // no flags means all of them!
6350 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6351 PEER_FLAG_AS_PATH_UNCHANGED)
6352 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6353 PEER_FLAG_NEXTHOP_UNCHANGED)
6354 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6355 PEER_FLAG_MED_UNCHANGED);
6356
6357 if (aspath)
6358 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6359 PEER_FLAG_AS_PATH_UNCHANGED);
6360
6361 if (nexthop)
6362 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6363 PEER_FLAG_NEXTHOP_UNCHANGED);
6364
6365 if (med)
6366 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6367 PEER_FLAG_MED_UNCHANGED);
6368
6369 return ret;
6370 }
6371
6372 ALIAS_HIDDEN(
6373 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6374 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6375 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6376 "BGP attribute is propagated unchanged to this neighbor\n"
6377 "As-path attribute\n"
6378 "Nexthop attribute\n"
6379 "Med attribute\n")
6380
6381 /* EBGP multihop configuration. */
6382 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6383 const char *ttl_str)
6384 {
6385 struct peer *peer;
6386 unsigned int ttl;
6387
6388 peer = peer_and_group_lookup_vty(vty, ip_str);
6389 if (!peer)
6390 return CMD_WARNING_CONFIG_FAILED;
6391
6392 if (peer->conf_if)
6393 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6394
6395 if (!ttl_str)
6396 ttl = MAXTTL;
6397 else
6398 ttl = strtoul(ttl_str, NULL, 10);
6399
6400 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6401 }
6402
6403 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6404 {
6405 struct peer *peer;
6406
6407 peer = peer_and_group_lookup_vty(vty, ip_str);
6408 if (!peer)
6409 return CMD_WARNING_CONFIG_FAILED;
6410
6411 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6412 }
6413
6414 /* neighbor ebgp-multihop. */
6415 DEFUN (neighbor_ebgp_multihop,
6416 neighbor_ebgp_multihop_cmd,
6417 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6418 NEIGHBOR_STR
6419 NEIGHBOR_ADDR_STR2
6420 "Allow EBGP neighbors not on directly connected networks\n")
6421 {
6422 int idx_peer = 1;
6423 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6424 }
6425
6426 DEFUN (neighbor_ebgp_multihop_ttl,
6427 neighbor_ebgp_multihop_ttl_cmd,
6428 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6429 NEIGHBOR_STR
6430 NEIGHBOR_ADDR_STR2
6431 "Allow EBGP neighbors not on directly connected networks\n"
6432 "maximum hop count\n")
6433 {
6434 int idx_peer = 1;
6435 int idx_number = 3;
6436 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6437 argv[idx_number]->arg);
6438 }
6439
6440 DEFUN (no_neighbor_ebgp_multihop,
6441 no_neighbor_ebgp_multihop_cmd,
6442 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6443 NO_STR
6444 NEIGHBOR_STR
6445 NEIGHBOR_ADDR_STR2
6446 "Allow EBGP neighbors not on directly connected networks\n"
6447 "maximum hop count\n")
6448 {
6449 int idx_peer = 2;
6450 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6451 }
6452
6453 static uint8_t get_role_by_name(const char *role_str)
6454 {
6455 if (strncmp(role_str, "peer", 2) == 0)
6456 return ROLE_PEER;
6457 if (strncmp(role_str, "provider", 2) == 0)
6458 return ROLE_PROVIDER;
6459 if (strncmp(role_str, "customer", 2) == 0)
6460 return ROLE_CUSTOMER;
6461 if (strncmp(role_str, "rs-server", 4) == 0)
6462 return ROLE_RS_SERVER;
6463 if (strncmp(role_str, "rs-client", 4) == 0)
6464 return ROLE_RS_CLIENT;
6465 return ROLE_UNDEFINED;
6466 }
6467
6468 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6469 const char *role_str, bool strict_mode)
6470 {
6471 struct peer *peer;
6472
6473 peer = peer_and_group_lookup_vty(vty, ip_str);
6474 if (!peer)
6475 return CMD_WARNING_CONFIG_FAILED;
6476 uint8_t role = get_role_by_name(role_str);
6477
6478 if (role == ROLE_UNDEFINED)
6479 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6480 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6481 }
6482
6483 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6484 {
6485 struct peer *peer;
6486
6487 peer = peer_and_group_lookup_vty(vty, ip_str);
6488 if (!peer)
6489 return CMD_WARNING_CONFIG_FAILED;
6490 return bgp_vty_return(vty, peer_role_unset(peer));
6491 }
6492
6493 DEFPY(neighbor_role,
6494 neighbor_role_cmd,
6495 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6496 NEIGHBOR_STR
6497 NEIGHBOR_ADDR_STR2
6498 "Set session role\n"
6499 ROLE_STR)
6500 {
6501 int idx_peer = 1;
6502 int idx_role = 3;
6503
6504 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6505 false);
6506 }
6507
6508 DEFPY(neighbor_role_strict,
6509 neighbor_role_strict_cmd,
6510 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6511 NEIGHBOR_STR
6512 NEIGHBOR_ADDR_STR2
6513 "Set session role\n"
6514 ROLE_STR
6515 "Use additional restriction on peer\n")
6516 {
6517 int idx_peer = 1;
6518 int idx_role = 3;
6519
6520 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6521 true);
6522 }
6523
6524 DEFPY(no_neighbor_role,
6525 no_neighbor_role_cmd,
6526 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6527 NO_STR
6528 NEIGHBOR_STR
6529 NEIGHBOR_ADDR_STR2
6530 "Set session role\n"
6531 ROLE_STR
6532 "Use additional restriction on peer\n")
6533 {
6534 int idx_peer = 2;
6535
6536 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6537 }
6538
6539 /* disable-connected-check */
6540 DEFUN (neighbor_disable_connected_check,
6541 neighbor_disable_connected_check_cmd,
6542 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6543 NEIGHBOR_STR
6544 NEIGHBOR_ADDR_STR2
6545 "one-hop away EBGP peer using loopback address\n"
6546 "Enforce EBGP neighbors perform multihop\n")
6547 {
6548 int idx_peer = 1;
6549 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6550 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6551 }
6552
6553 DEFUN (no_neighbor_disable_connected_check,
6554 no_neighbor_disable_connected_check_cmd,
6555 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6556 NO_STR
6557 NEIGHBOR_STR
6558 NEIGHBOR_ADDR_STR2
6559 "one-hop away EBGP peer using loopback address\n"
6560 "Enforce EBGP neighbors perform multihop\n")
6561 {
6562 int idx_peer = 2;
6563 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6564 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6565 }
6566
6567 /* disable-link-bw-encoding-ieee */
6568 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6569 neighbor_disable_link_bw_encoding_ieee_cmd,
6570 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6571 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6572 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6573 {
6574 int idx_peer = 1;
6575
6576 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6577 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6578 }
6579
6580 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6581 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6582 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6583 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6584 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6585 {
6586 int idx_peer = 2;
6587
6588 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6589 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6590 }
6591
6592 /* extended-optional-parameters */
6593 DEFUN(neighbor_extended_optional_parameters,
6594 neighbor_extended_optional_parameters_cmd,
6595 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6596 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6597 "Force the extended optional parameters format for OPEN messages\n")
6598 {
6599 int idx_peer = 1;
6600
6601 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6602 PEER_FLAG_EXTENDED_OPT_PARAMS);
6603 }
6604
6605 DEFUN(no_neighbor_extended_optional_parameters,
6606 no_neighbor_extended_optional_parameters_cmd,
6607 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6608 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6609 "Force the extended optional parameters format for OPEN messages\n")
6610 {
6611 int idx_peer = 2;
6612
6613 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6614 PEER_FLAG_EXTENDED_OPT_PARAMS);
6615 }
6616
6617 /* enforce-first-as */
6618 DEFUN (neighbor_enforce_first_as,
6619 neighbor_enforce_first_as_cmd,
6620 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6621 NEIGHBOR_STR
6622 NEIGHBOR_ADDR_STR2
6623 "Enforce the first AS for EBGP routes\n")
6624 {
6625 int idx_peer = 1;
6626
6627 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6628 PEER_FLAG_ENFORCE_FIRST_AS);
6629 }
6630
6631 DEFUN (no_neighbor_enforce_first_as,
6632 no_neighbor_enforce_first_as_cmd,
6633 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6634 NO_STR
6635 NEIGHBOR_STR
6636 NEIGHBOR_ADDR_STR2
6637 "Enforce the first AS for EBGP routes\n")
6638 {
6639 int idx_peer = 2;
6640
6641 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6642 PEER_FLAG_ENFORCE_FIRST_AS);
6643 }
6644
6645
6646 DEFUN (neighbor_description,
6647 neighbor_description_cmd,
6648 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6649 NEIGHBOR_STR
6650 NEIGHBOR_ADDR_STR2
6651 "Neighbor specific description\n"
6652 "Up to 80 characters describing this neighbor\n")
6653 {
6654 int idx_peer = 1;
6655 int idx_line = 3;
6656 struct peer *peer;
6657 char *str;
6658
6659 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6660 if (!peer)
6661 return CMD_WARNING_CONFIG_FAILED;
6662
6663 str = argv_concat(argv, argc, idx_line);
6664
6665 peer_description_set(peer, str);
6666
6667 XFREE(MTYPE_TMP, str);
6668
6669 return CMD_SUCCESS;
6670 }
6671
6672 DEFUN (no_neighbor_description,
6673 no_neighbor_description_cmd,
6674 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6675 NO_STR
6676 NEIGHBOR_STR
6677 NEIGHBOR_ADDR_STR2
6678 "Neighbor specific description\n")
6679 {
6680 int idx_peer = 2;
6681 struct peer *peer;
6682
6683 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6684 if (!peer)
6685 return CMD_WARNING_CONFIG_FAILED;
6686
6687 peer_description_unset(peer);
6688
6689 return CMD_SUCCESS;
6690 }
6691
6692 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6693 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6694 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6695 "Neighbor specific description\n"
6696 "Up to 80 characters describing this neighbor\n")
6697
6698 /* Neighbor update-source. */
6699 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6700 const char *source_str)
6701 {
6702 struct peer *peer;
6703 struct prefix p;
6704 union sockunion su;
6705
6706 peer = peer_and_group_lookup_vty(vty, peer_str);
6707 if (!peer)
6708 return CMD_WARNING_CONFIG_FAILED;
6709
6710 if (peer->conf_if)
6711 return CMD_WARNING;
6712
6713 if (source_str) {
6714 if (str2sockunion(source_str, &su) == 0)
6715 peer_update_source_addr_set(peer, &su);
6716 else {
6717 if (str2prefix(source_str, &p)) {
6718 vty_out(vty,
6719 "%% Invalid update-source, remove prefix length \n");
6720 return CMD_WARNING_CONFIG_FAILED;
6721 } else
6722 peer_update_source_if_set(peer, source_str);
6723 }
6724 } else
6725 peer_update_source_unset(peer);
6726
6727 return CMD_SUCCESS;
6728 }
6729
6730 #define BGP_UPDATE_SOURCE_HELP_STR \
6731 "IPv4 address\n" \
6732 "IPv6 address\n" \
6733 "Interface name (requires zebra to be running)\n"
6734
6735 DEFUN (neighbor_update_source,
6736 neighbor_update_source_cmd,
6737 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6738 NEIGHBOR_STR
6739 NEIGHBOR_ADDR_STR2
6740 "Source of routing updates\n"
6741 BGP_UPDATE_SOURCE_HELP_STR)
6742 {
6743 int idx_peer = 1;
6744 int idx_peer_2 = 3;
6745 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6746 argv[idx_peer_2]->arg);
6747 }
6748
6749 DEFUN (no_neighbor_update_source,
6750 no_neighbor_update_source_cmd,
6751 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6752 NO_STR
6753 NEIGHBOR_STR
6754 NEIGHBOR_ADDR_STR2
6755 "Source of routing updates\n"
6756 BGP_UPDATE_SOURCE_HELP_STR)
6757 {
6758 int idx_peer = 2;
6759 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6760 }
6761
6762 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6763 afi_t afi, safi_t safi,
6764 const char *rmap, int set)
6765 {
6766 int ret;
6767 struct peer *peer;
6768 struct route_map *route_map = NULL;
6769
6770 peer = peer_and_group_lookup_vty(vty, peer_str);
6771 if (!peer)
6772 return CMD_WARNING_CONFIG_FAILED;
6773
6774 if (set) {
6775 if (rmap)
6776 route_map = route_map_lookup_warn_noexist(vty, rmap);
6777 ret = peer_default_originate_set(peer, afi, safi,
6778 rmap, route_map);
6779 } else
6780 ret = peer_default_originate_unset(peer, afi, safi);
6781
6782 return bgp_vty_return(vty, ret);
6783 }
6784
6785 /* neighbor default-originate. */
6786 DEFUN (neighbor_default_originate,
6787 neighbor_default_originate_cmd,
6788 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6789 NEIGHBOR_STR
6790 NEIGHBOR_ADDR_STR2
6791 "Originate default route to this neighbor\n")
6792 {
6793 int idx_peer = 1;
6794 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6795 bgp_node_afi(vty),
6796 bgp_node_safi(vty), NULL, 1);
6797 }
6798
6799 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6800 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6801 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6802 "Originate default route to this neighbor\n")
6803
6804 DEFUN (neighbor_default_originate_rmap,
6805 neighbor_default_originate_rmap_cmd,
6806 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6807 NEIGHBOR_STR
6808 NEIGHBOR_ADDR_STR2
6809 "Originate default route to this neighbor\n"
6810 "Route-map to specify criteria to originate default\n"
6811 "route-map name\n")
6812 {
6813 int idx_peer = 1;
6814 int idx_word = 4;
6815 return peer_default_originate_set_vty(
6816 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6817 argv[idx_word]->arg, 1);
6818 }
6819
6820 ALIAS_HIDDEN(
6821 neighbor_default_originate_rmap,
6822 neighbor_default_originate_rmap_hidden_cmd,
6823 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6824 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6825 "Originate default route to this neighbor\n"
6826 "Route-map to specify criteria to originate default\n"
6827 "route-map name\n")
6828
6829 DEFUN (no_neighbor_default_originate,
6830 no_neighbor_default_originate_cmd,
6831 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6832 NO_STR
6833 NEIGHBOR_STR
6834 NEIGHBOR_ADDR_STR2
6835 "Originate default route to this neighbor\n"
6836 "Route-map to specify criteria to originate default\n"
6837 "route-map name\n")
6838 {
6839 int idx_peer = 2;
6840 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6841 bgp_node_afi(vty),
6842 bgp_node_safi(vty), NULL, 0);
6843 }
6844
6845 ALIAS_HIDDEN(
6846 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6847 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6849 "Originate default route to this neighbor\n"
6850 "Route-map to specify criteria to originate default\n"
6851 "route-map name\n")
6852
6853
6854 /* Set neighbor's BGP port. */
6855 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6856 const char *port_str)
6857 {
6858 struct peer *peer;
6859 uint16_t port;
6860 struct servent *sp;
6861
6862 peer = peer_and_group_lookup_vty(vty, ip_str);
6863 if (!peer)
6864 return CMD_WARNING_CONFIG_FAILED;
6865
6866 if (!port_str) {
6867 sp = getservbyname("bgp", "tcp");
6868 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6869 } else {
6870 port = strtoul(port_str, NULL, 10);
6871 }
6872
6873 peer_port_set(peer, port);
6874
6875 return CMD_SUCCESS;
6876 }
6877
6878 /* Set specified peer's BGP port. */
6879 DEFUN (neighbor_port,
6880 neighbor_port_cmd,
6881 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6882 NEIGHBOR_STR
6883 NEIGHBOR_ADDR_STR2
6884 "Neighbor's BGP port\n"
6885 "TCP port number\n")
6886 {
6887 int idx_ip = 1;
6888 int idx_number = 3;
6889 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6890 argv[idx_number]->arg);
6891 }
6892
6893 DEFUN (no_neighbor_port,
6894 no_neighbor_port_cmd,
6895 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6896 NO_STR
6897 NEIGHBOR_STR
6898 NEIGHBOR_ADDR_STR2
6899 "Neighbor's BGP port\n"
6900 "TCP port number\n")
6901 {
6902 int idx_ip = 2;
6903 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6904 }
6905
6906
6907 /* neighbor weight. */
6908 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6909 safi_t safi, const char *weight_str)
6910 {
6911 int ret;
6912 struct peer *peer;
6913 unsigned long weight;
6914
6915 peer = peer_and_group_lookup_vty(vty, ip_str);
6916 if (!peer)
6917 return CMD_WARNING_CONFIG_FAILED;
6918
6919 weight = strtoul(weight_str, NULL, 10);
6920
6921 ret = peer_weight_set(peer, afi, safi, weight);
6922 return bgp_vty_return(vty, ret);
6923 }
6924
6925 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6926 safi_t safi)
6927 {
6928 int ret;
6929 struct peer *peer;
6930
6931 peer = peer_and_group_lookup_vty(vty, ip_str);
6932 if (!peer)
6933 return CMD_WARNING_CONFIG_FAILED;
6934
6935 ret = peer_weight_unset(peer, afi, safi);
6936 return bgp_vty_return(vty, ret);
6937 }
6938
6939 DEFUN (neighbor_weight,
6940 neighbor_weight_cmd,
6941 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6942 NEIGHBOR_STR
6943 NEIGHBOR_ADDR_STR2
6944 "Set default weight for routes from this neighbor\n"
6945 "default weight\n")
6946 {
6947 int idx_peer = 1;
6948 int idx_number = 3;
6949 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6950 bgp_node_safi(vty), argv[idx_number]->arg);
6951 }
6952
6953 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6954 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6955 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6956 "Set default weight for routes from this neighbor\n"
6957 "default weight\n")
6958
6959 DEFUN (no_neighbor_weight,
6960 no_neighbor_weight_cmd,
6961 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6962 NO_STR
6963 NEIGHBOR_STR
6964 NEIGHBOR_ADDR_STR2
6965 "Set default weight for routes from this neighbor\n"
6966 "default weight\n")
6967 {
6968 int idx_peer = 2;
6969 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6970 bgp_node_afi(vty), bgp_node_safi(vty));
6971 }
6972
6973 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6974 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6975 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6976 "Set default weight for routes from this neighbor\n"
6977 "default weight\n")
6978
6979
6980 /* Override capability negotiation. */
6981 DEFUN (neighbor_override_capability,
6982 neighbor_override_capability_cmd,
6983 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6984 NEIGHBOR_STR
6985 NEIGHBOR_ADDR_STR2
6986 "Override capability negotiation result\n")
6987 {
6988 int idx_peer = 1;
6989 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6990 PEER_FLAG_OVERRIDE_CAPABILITY);
6991 }
6992
6993 DEFUN (no_neighbor_override_capability,
6994 no_neighbor_override_capability_cmd,
6995 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6996 NO_STR
6997 NEIGHBOR_STR
6998 NEIGHBOR_ADDR_STR2
6999 "Override capability negotiation result\n")
7000 {
7001 int idx_peer = 2;
7002 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7003 PEER_FLAG_OVERRIDE_CAPABILITY);
7004 }
7005
7006 DEFUN (neighbor_strict_capability,
7007 neighbor_strict_capability_cmd,
7008 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7009 NEIGHBOR_STR
7010 NEIGHBOR_ADDR_STR2
7011 "Strict capability negotiation match\n")
7012 {
7013 int idx_peer = 1;
7014
7015 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7016 PEER_FLAG_STRICT_CAP_MATCH);
7017 }
7018
7019 DEFUN (no_neighbor_strict_capability,
7020 no_neighbor_strict_capability_cmd,
7021 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7022 NO_STR
7023 NEIGHBOR_STR
7024 NEIGHBOR_ADDR_STR2
7025 "Strict capability negotiation match\n")
7026 {
7027 int idx_peer = 2;
7028
7029 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7030 PEER_FLAG_STRICT_CAP_MATCH);
7031 }
7032
7033 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7034 const char *keep_str, const char *hold_str)
7035 {
7036 int ret;
7037 struct peer *peer;
7038 uint32_t keepalive;
7039 uint32_t holdtime;
7040
7041 peer = peer_and_group_lookup_vty(vty, ip_str);
7042 if (!peer)
7043 return CMD_WARNING_CONFIG_FAILED;
7044
7045 keepalive = strtoul(keep_str, NULL, 10);
7046 holdtime = strtoul(hold_str, NULL, 10);
7047
7048 ret = peer_timers_set(peer, keepalive, holdtime);
7049
7050 return bgp_vty_return(vty, ret);
7051 }
7052
7053 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7054 {
7055 int ret;
7056 struct peer *peer;
7057
7058 peer = peer_and_group_lookup_vty(vty, ip_str);
7059 if (!peer)
7060 return CMD_WARNING_CONFIG_FAILED;
7061
7062 ret = peer_timers_unset(peer);
7063
7064 return bgp_vty_return(vty, ret);
7065 }
7066
7067 DEFUN (neighbor_timers,
7068 neighbor_timers_cmd,
7069 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7070 NEIGHBOR_STR
7071 NEIGHBOR_ADDR_STR2
7072 "BGP per neighbor timers\n"
7073 "Keepalive interval\n"
7074 "Holdtime\n")
7075 {
7076 int idx_peer = 1;
7077 int idx_number = 3;
7078 int idx_number_2 = 4;
7079 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7080 argv[idx_number]->arg,
7081 argv[idx_number_2]->arg);
7082 }
7083
7084 DEFUN (no_neighbor_timers,
7085 no_neighbor_timers_cmd,
7086 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7087 NO_STR
7088 NEIGHBOR_STR
7089 NEIGHBOR_ADDR_STR2
7090 "BGP per neighbor timers\n"
7091 "Keepalive interval\n"
7092 "Holdtime\n")
7093 {
7094 int idx_peer = 2;
7095 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7096 }
7097
7098
7099 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7100 const char *time_str)
7101 {
7102 int ret;
7103 struct peer *peer;
7104 uint32_t connect;
7105
7106 peer = peer_and_group_lookup_vty(vty, ip_str);
7107 if (!peer)
7108 return CMD_WARNING_CONFIG_FAILED;
7109
7110 connect = strtoul(time_str, NULL, 10);
7111
7112 ret = peer_timers_connect_set(peer, connect);
7113
7114 return bgp_vty_return(vty, ret);
7115 }
7116
7117 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7118 {
7119 int ret;
7120 struct peer *peer;
7121
7122 peer = peer_and_group_lookup_vty(vty, ip_str);
7123 if (!peer)
7124 return CMD_WARNING_CONFIG_FAILED;
7125
7126 ret = peer_timers_connect_unset(peer);
7127
7128 return bgp_vty_return(vty, ret);
7129 }
7130
7131 DEFUN (neighbor_timers_connect,
7132 neighbor_timers_connect_cmd,
7133 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7134 NEIGHBOR_STR
7135 NEIGHBOR_ADDR_STR2
7136 "BGP per neighbor timers\n"
7137 "BGP connect timer\n"
7138 "Connect timer\n")
7139 {
7140 int idx_peer = 1;
7141 int idx_number = 4;
7142 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7143 argv[idx_number]->arg);
7144 }
7145
7146 DEFUN (no_neighbor_timers_connect,
7147 no_neighbor_timers_connect_cmd,
7148 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7149 NO_STR
7150 NEIGHBOR_STR
7151 NEIGHBOR_ADDR_STR2
7152 "BGP per neighbor timers\n"
7153 "BGP connect timer\n"
7154 "Connect timer\n")
7155 {
7156 int idx_peer = 2;
7157 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7158 }
7159
7160 DEFPY (neighbor_timers_delayopen,
7161 neighbor_timers_delayopen_cmd,
7162 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7163 NEIGHBOR_STR
7164 NEIGHBOR_ADDR_STR2
7165 "BGP per neighbor timers\n"
7166 "RFC 4271 DelayOpenTimer\n"
7167 "DelayOpenTime timer interval\n")
7168 {
7169 struct peer *peer;
7170
7171 peer = peer_and_group_lookup_vty(vty, neighbor);
7172 if (!peer)
7173 return CMD_WARNING_CONFIG_FAILED;
7174
7175 if (!interval) {
7176 if (peer_timers_delayopen_unset(peer))
7177 return CMD_WARNING_CONFIG_FAILED;
7178 } else {
7179 if (peer_timers_delayopen_set(peer, interval))
7180 return CMD_WARNING_CONFIG_FAILED;
7181 }
7182
7183 return CMD_SUCCESS;
7184 }
7185
7186 DEFPY (no_neighbor_timers_delayopen,
7187 no_neighbor_timers_delayopen_cmd,
7188 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7189 NO_STR
7190 NEIGHBOR_STR
7191 NEIGHBOR_ADDR_STR2
7192 "BGP per neighbor timers\n"
7193 "RFC 4271 DelayOpenTimer\n"
7194 "DelayOpenTime timer interval\n")
7195 {
7196 struct peer *peer;
7197
7198 peer = peer_and_group_lookup_vty(vty, neighbor);
7199 if (!peer)
7200 return CMD_WARNING_CONFIG_FAILED;
7201
7202 if (peer_timers_delayopen_unset(peer))
7203 return CMD_WARNING_CONFIG_FAILED;
7204
7205 return CMD_SUCCESS;
7206 }
7207
7208 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7209 const char *time_str, int set)
7210 {
7211 int ret;
7212 struct peer *peer;
7213 uint32_t routeadv = 0;
7214
7215 peer = peer_and_group_lookup_vty(vty, ip_str);
7216 if (!peer)
7217 return CMD_WARNING_CONFIG_FAILED;
7218
7219 if (time_str)
7220 routeadv = strtoul(time_str, NULL, 10);
7221
7222 if (set)
7223 ret = peer_advertise_interval_set(peer, routeadv);
7224 else
7225 ret = peer_advertise_interval_unset(peer);
7226
7227 return bgp_vty_return(vty, ret);
7228 }
7229
7230 DEFUN (neighbor_advertise_interval,
7231 neighbor_advertise_interval_cmd,
7232 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7233 NEIGHBOR_STR
7234 NEIGHBOR_ADDR_STR2
7235 "Minimum interval between sending BGP routing updates\n"
7236 "time in seconds\n")
7237 {
7238 int idx_peer = 1;
7239 int idx_number = 3;
7240 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7241 argv[idx_number]->arg, 1);
7242 }
7243
7244 DEFUN (no_neighbor_advertise_interval,
7245 no_neighbor_advertise_interval_cmd,
7246 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7247 NO_STR
7248 NEIGHBOR_STR
7249 NEIGHBOR_ADDR_STR2
7250 "Minimum interval between sending BGP routing updates\n"
7251 "time in seconds\n")
7252 {
7253 int idx_peer = 2;
7254 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7255 }
7256
7257
7258 /* Time to wait before processing route-map updates */
7259 DEFUN (bgp_set_route_map_delay_timer,
7260 bgp_set_route_map_delay_timer_cmd,
7261 "bgp route-map delay-timer (0-600)",
7262 SET_STR
7263 "BGP route-map delay timer\n"
7264 "Time in secs to wait before processing route-map changes\n"
7265 "0 disables the timer, no route updates happen when route-maps change\n")
7266 {
7267 int idx_number = 3;
7268 uint32_t rmap_delay_timer;
7269
7270 if (argv[idx_number]->arg) {
7271 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7272 bm->rmap_update_timer = rmap_delay_timer;
7273
7274 /* if the dynamic update handling is being disabled, and a timer
7275 * is
7276 * running, stop the timer and act as if the timer has already
7277 * fired.
7278 */
7279 if (!rmap_delay_timer && bm->t_rmap_update) {
7280 THREAD_OFF(bm->t_rmap_update);
7281 thread_execute(bm->master, bgp_route_map_update_timer,
7282 NULL, 0);
7283 }
7284 return CMD_SUCCESS;
7285 } else {
7286 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7287 return CMD_WARNING_CONFIG_FAILED;
7288 }
7289 }
7290
7291 DEFUN (no_bgp_set_route_map_delay_timer,
7292 no_bgp_set_route_map_delay_timer_cmd,
7293 "no bgp route-map delay-timer [(0-600)]",
7294 NO_STR
7295 BGP_STR
7296 "Default BGP route-map delay timer\n"
7297 "Reset to default time to wait for processing route-map changes\n"
7298 "0 disables the timer, no route updates happen when route-maps change\n")
7299 {
7300
7301 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7302
7303 return CMD_SUCCESS;
7304 }
7305
7306 /* neighbor interface */
7307 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7308 const char *str)
7309 {
7310 struct peer *peer;
7311
7312 peer = peer_lookup_vty(vty, ip_str);
7313 if (!peer || peer->conf_if) {
7314 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7315 return CMD_WARNING_CONFIG_FAILED;
7316 }
7317
7318 if (str)
7319 peer_interface_set(peer, str);
7320 else
7321 peer_interface_unset(peer);
7322
7323 return CMD_SUCCESS;
7324 }
7325
7326 DEFUN (neighbor_interface,
7327 neighbor_interface_cmd,
7328 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7329 NEIGHBOR_STR
7330 NEIGHBOR_ADDR_STR
7331 "Interface\n"
7332 "Interface name\n")
7333 {
7334 int idx_ip = 1;
7335 int idx_word = 3;
7336
7337 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7338 }
7339
7340 DEFUN (no_neighbor_interface,
7341 no_neighbor_interface_cmd,
7342 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7343 NO_STR
7344 NEIGHBOR_STR
7345 NEIGHBOR_ADDR_STR
7346 "Interface\n"
7347 "Interface name\n")
7348 {
7349 int idx_peer = 2;
7350
7351 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7352 }
7353
7354 DEFUN (neighbor_distribute_list,
7355 neighbor_distribute_list_cmd,
7356 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7357 NEIGHBOR_STR
7358 NEIGHBOR_ADDR_STR2
7359 "Filter updates to/from this neighbor\n"
7360 "IP Access-list name\n"
7361 "Filter incoming updates\n"
7362 "Filter outgoing updates\n")
7363 {
7364 int idx_peer = 1;
7365 int idx_acl = 3;
7366 int direct, ret;
7367 struct peer *peer;
7368
7369 const char *pstr = argv[idx_peer]->arg;
7370 const char *acl = argv[idx_acl]->arg;
7371 const char *inout = argv[argc - 1]->text;
7372
7373 peer = peer_and_group_lookup_vty(vty, pstr);
7374 if (!peer)
7375 return CMD_WARNING_CONFIG_FAILED;
7376
7377 /* Check filter direction. */
7378 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7379 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7380 direct, acl);
7381
7382 return bgp_vty_return(vty, ret);
7383 }
7384
7385 ALIAS_HIDDEN(
7386 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7387 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7388 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7389 "Filter updates to/from this neighbor\n"
7390 "IP Access-list name\n"
7391 "Filter incoming updates\n"
7392 "Filter outgoing updates\n")
7393
7394 DEFUN (no_neighbor_distribute_list,
7395 no_neighbor_distribute_list_cmd,
7396 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7397 NO_STR
7398 NEIGHBOR_STR
7399 NEIGHBOR_ADDR_STR2
7400 "Filter updates to/from this neighbor\n"
7401 "IP Access-list name\n"
7402 "Filter incoming updates\n"
7403 "Filter outgoing updates\n")
7404 {
7405 int idx_peer = 2;
7406 int direct, ret;
7407 struct peer *peer;
7408
7409 const char *pstr = argv[idx_peer]->arg;
7410 const char *inout = argv[argc - 1]->text;
7411
7412 peer = peer_and_group_lookup_vty(vty, pstr);
7413 if (!peer)
7414 return CMD_WARNING_CONFIG_FAILED;
7415
7416 /* Check filter direction. */
7417 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7418 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7419 direct);
7420
7421 return bgp_vty_return(vty, ret);
7422 }
7423
7424 ALIAS_HIDDEN(
7425 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7426 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7427 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7428 "Filter updates to/from this neighbor\n"
7429 "IP Access-list name\n"
7430 "Filter incoming updates\n"
7431 "Filter outgoing updates\n")
7432
7433 /* Set prefix list to the peer. */
7434 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7435 afi_t afi, safi_t safi,
7436 const char *name_str,
7437 const char *direct_str)
7438 {
7439 int ret;
7440 int direct = FILTER_IN;
7441 struct peer *peer;
7442
7443 peer = peer_and_group_lookup_vty(vty, ip_str);
7444 if (!peer)
7445 return CMD_WARNING_CONFIG_FAILED;
7446
7447 /* Check filter direction. */
7448 if (strncmp(direct_str, "i", 1) == 0)
7449 direct = FILTER_IN;
7450 else if (strncmp(direct_str, "o", 1) == 0)
7451 direct = FILTER_OUT;
7452
7453 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7454
7455 return bgp_vty_return(vty, ret);
7456 }
7457
7458 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7459 afi_t afi, safi_t safi,
7460 const char *direct_str)
7461 {
7462 int ret;
7463 struct peer *peer;
7464 int direct = FILTER_IN;
7465
7466 peer = peer_and_group_lookup_vty(vty, ip_str);
7467 if (!peer)
7468 return CMD_WARNING_CONFIG_FAILED;
7469
7470 /* Check filter direction. */
7471 if (strncmp(direct_str, "i", 1) == 0)
7472 direct = FILTER_IN;
7473 else if (strncmp(direct_str, "o", 1) == 0)
7474 direct = FILTER_OUT;
7475
7476 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7477
7478 return bgp_vty_return(vty, ret);
7479 }
7480
7481 DEFUN (neighbor_prefix_list,
7482 neighbor_prefix_list_cmd,
7483 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7484 NEIGHBOR_STR
7485 NEIGHBOR_ADDR_STR2
7486 "Filter updates to/from this neighbor\n"
7487 "Name of a prefix list\n"
7488 "Filter incoming updates\n"
7489 "Filter outgoing updates\n")
7490 {
7491 int idx_peer = 1;
7492 int idx_word = 3;
7493 int idx_in_out = 4;
7494 return peer_prefix_list_set_vty(
7495 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7496 argv[idx_word]->arg, argv[idx_in_out]->arg);
7497 }
7498
7499 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7500 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7501 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7502 "Filter updates to/from this neighbor\n"
7503 "Name of a prefix list\n"
7504 "Filter incoming updates\n"
7505 "Filter outgoing updates\n")
7506
7507 DEFUN (no_neighbor_prefix_list,
7508 no_neighbor_prefix_list_cmd,
7509 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7510 NO_STR
7511 NEIGHBOR_STR
7512 NEIGHBOR_ADDR_STR2
7513 "Filter updates to/from this neighbor\n"
7514 "Name of a prefix list\n"
7515 "Filter incoming updates\n"
7516 "Filter outgoing updates\n")
7517 {
7518 int idx_peer = 2;
7519 int idx_in_out = 5;
7520 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7521 bgp_node_afi(vty), bgp_node_safi(vty),
7522 argv[idx_in_out]->arg);
7523 }
7524
7525 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7526 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7527 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7528 "Filter updates to/from this neighbor\n"
7529 "Name of a prefix list\n"
7530 "Filter incoming updates\n"
7531 "Filter outgoing updates\n")
7532
7533 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7534 safi_t safi, const char *name_str,
7535 const char *direct_str)
7536 {
7537 int ret;
7538 struct peer *peer;
7539 int direct = FILTER_IN;
7540
7541 peer = peer_and_group_lookup_vty(vty, ip_str);
7542 if (!peer)
7543 return CMD_WARNING_CONFIG_FAILED;
7544
7545 /* Check filter direction. */
7546 if (strncmp(direct_str, "i", 1) == 0)
7547 direct = FILTER_IN;
7548 else if (strncmp(direct_str, "o", 1) == 0)
7549 direct = FILTER_OUT;
7550
7551 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7552
7553 return bgp_vty_return(vty, ret);
7554 }
7555
7556 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7557 safi_t safi, const char *direct_str)
7558 {
7559 int ret;
7560 struct peer *peer;
7561 int direct = FILTER_IN;
7562
7563 peer = peer_and_group_lookup_vty(vty, ip_str);
7564 if (!peer)
7565 return CMD_WARNING_CONFIG_FAILED;
7566
7567 /* Check filter direction. */
7568 if (strncmp(direct_str, "i", 1) == 0)
7569 direct = FILTER_IN;
7570 else if (strncmp(direct_str, "o", 1) == 0)
7571 direct = FILTER_OUT;
7572
7573 ret = peer_aslist_unset(peer, afi, safi, direct);
7574
7575 return bgp_vty_return(vty, ret);
7576 }
7577
7578 DEFUN (neighbor_filter_list,
7579 neighbor_filter_list_cmd,
7580 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7581 NEIGHBOR_STR
7582 NEIGHBOR_ADDR_STR2
7583 "Establish BGP filters\n"
7584 "AS path access-list name\n"
7585 "Filter incoming routes\n"
7586 "Filter outgoing routes\n")
7587 {
7588 int idx_peer = 1;
7589 int idx_word = 3;
7590 int idx_in_out = 4;
7591 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7592 bgp_node_safi(vty), argv[idx_word]->arg,
7593 argv[idx_in_out]->arg);
7594 }
7595
7596 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7597 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7598 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7599 "Establish BGP filters\n"
7600 "AS path access-list name\n"
7601 "Filter incoming routes\n"
7602 "Filter outgoing routes\n")
7603
7604 DEFUN (no_neighbor_filter_list,
7605 no_neighbor_filter_list_cmd,
7606 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7607 NO_STR
7608 NEIGHBOR_STR
7609 NEIGHBOR_ADDR_STR2
7610 "Establish BGP filters\n"
7611 "AS path access-list name\n"
7612 "Filter incoming routes\n"
7613 "Filter outgoing routes\n")
7614 {
7615 int idx_peer = 2;
7616 int idx_in_out = 5;
7617 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7618 bgp_node_afi(vty), bgp_node_safi(vty),
7619 argv[idx_in_out]->arg);
7620 }
7621
7622 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7623 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7624 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7625 "Establish BGP filters\n"
7626 "AS path access-list name\n"
7627 "Filter incoming routes\n"
7628 "Filter outgoing routes\n")
7629
7630 /* Set advertise-map to the peer. */
7631 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7632 afi_t afi, safi_t safi,
7633 const char *advertise_str,
7634 const char *condition_str, bool condition,
7635 bool set)
7636 {
7637 int ret = CMD_WARNING_CONFIG_FAILED;
7638 struct peer *peer;
7639 struct route_map *advertise_map;
7640 struct route_map *condition_map;
7641
7642 peer = peer_and_group_lookup_vty(vty, ip_str);
7643 if (!peer)
7644 return ret;
7645
7646 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7647 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7648
7649 if (set)
7650 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7651 advertise_map, condition_str,
7652 condition_map, condition);
7653 else
7654 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7655 advertise_map, condition_str,
7656 condition_map, condition);
7657
7658 return bgp_vty_return(vty, ret);
7659 }
7660
7661 DEFPY (bgp_condadv_period,
7662 bgp_condadv_period_cmd,
7663 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7664 NO_STR
7665 BGP_STR
7666 "Conditional advertisement settings\n"
7667 "Set period to rescan BGP table to check if condition is met\n"
7668 "Period between BGP table scans, in seconds; default 60\n")
7669 {
7670 VTY_DECLVAR_CONTEXT(bgp, bgp);
7671
7672 bgp->condition_check_period =
7673 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7674
7675 return CMD_SUCCESS;
7676 }
7677
7678 DEFPY (neighbor_advertise_map,
7679 neighbor_advertise_map_cmd,
7680 "[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",
7681 NO_STR
7682 NEIGHBOR_STR
7683 NEIGHBOR_ADDR_STR2
7684 "Route-map to conditionally advertise routes\n"
7685 "Name of advertise map\n"
7686 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7687 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7688 "Name of the exist or non exist map\n")
7689 {
7690 bool condition = CONDITION_EXIST;
7691
7692 if (!strcmp(exist, "non-exist-map"))
7693 condition = CONDITION_NON_EXIST;
7694
7695 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7696 bgp_node_safi(vty), advertise_str,
7697 condition_str, condition, !no);
7698 }
7699
7700 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7701 "[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",
7702 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7703 "Route-map to conditionally advertise routes\n"
7704 "Name of advertise map\n"
7705 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7706 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7707 "Name of the exist or non exist map\n")
7708
7709 /* Set route-map to the peer. */
7710 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7711 afi_t afi, safi_t safi, const char *name_str,
7712 const char *direct_str)
7713 {
7714 int ret;
7715 struct peer *peer;
7716 int direct = RMAP_IN;
7717 struct route_map *route_map;
7718
7719 peer = peer_and_group_lookup_vty(vty, ip_str);
7720 if (!peer)
7721 return CMD_WARNING_CONFIG_FAILED;
7722
7723 /* Check filter direction. */
7724 if (strncmp(direct_str, "in", 2) == 0)
7725 direct = RMAP_IN;
7726 else if (strncmp(direct_str, "o", 1) == 0)
7727 direct = RMAP_OUT;
7728
7729 route_map = route_map_lookup_warn_noexist(vty, name_str);
7730 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7731
7732 return bgp_vty_return(vty, ret);
7733 }
7734
7735 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7736 afi_t afi, safi_t safi,
7737 const char *direct_str)
7738 {
7739 int ret;
7740 struct peer *peer;
7741 int direct = RMAP_IN;
7742
7743 peer = peer_and_group_lookup_vty(vty, ip_str);
7744 if (!peer)
7745 return CMD_WARNING_CONFIG_FAILED;
7746
7747 /* Check filter direction. */
7748 if (strncmp(direct_str, "in", 2) == 0)
7749 direct = RMAP_IN;
7750 else if (strncmp(direct_str, "o", 1) == 0)
7751 direct = RMAP_OUT;
7752
7753 ret = peer_route_map_unset(peer, afi, safi, direct);
7754
7755 return bgp_vty_return(vty, ret);
7756 }
7757
7758 DEFUN (neighbor_route_map,
7759 neighbor_route_map_cmd,
7760 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7761 NEIGHBOR_STR
7762 NEIGHBOR_ADDR_STR2
7763 "Apply route map to neighbor\n"
7764 "Name of route map\n"
7765 "Apply map to incoming routes\n"
7766 "Apply map to outbound routes\n")
7767 {
7768 int idx_peer = 1;
7769 int idx_word = 3;
7770 int idx_in_out = 4;
7771 return peer_route_map_set_vty(
7772 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7773 argv[idx_word]->arg, argv[idx_in_out]->arg);
7774 }
7775
7776 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7777 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7778 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7779 "Apply route map to neighbor\n"
7780 "Name of route map\n"
7781 "Apply map to incoming routes\n"
7782 "Apply map to outbound routes\n")
7783
7784 DEFUN (no_neighbor_route_map,
7785 no_neighbor_route_map_cmd,
7786 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7787 NO_STR
7788 NEIGHBOR_STR
7789 NEIGHBOR_ADDR_STR2
7790 "Apply route map to neighbor\n"
7791 "Name of route map\n"
7792 "Apply map to incoming routes\n"
7793 "Apply map to outbound routes\n")
7794 {
7795 int idx_peer = 2;
7796 int idx_in_out = 5;
7797 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7798 bgp_node_afi(vty), bgp_node_safi(vty),
7799 argv[idx_in_out]->arg);
7800 }
7801
7802 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7803 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7804 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7805 "Apply route map to neighbor\n"
7806 "Name of route map\n"
7807 "Apply map to incoming routes\n"
7808 "Apply map to outbound routes\n")
7809
7810 /* Set unsuppress-map to the peer. */
7811 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7812 afi_t afi, safi_t safi,
7813 const char *name_str)
7814 {
7815 int ret;
7816 struct peer *peer;
7817 struct route_map *route_map;
7818
7819 peer = peer_and_group_lookup_vty(vty, ip_str);
7820 if (!peer)
7821 return CMD_WARNING_CONFIG_FAILED;
7822
7823 route_map = route_map_lookup_warn_noexist(vty, name_str);
7824 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7825
7826 return bgp_vty_return(vty, ret);
7827 }
7828
7829 /* Unset route-map from the peer. */
7830 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7831 afi_t afi, safi_t safi)
7832 {
7833 int ret;
7834 struct peer *peer;
7835
7836 peer = peer_and_group_lookup_vty(vty, ip_str);
7837 if (!peer)
7838 return CMD_WARNING_CONFIG_FAILED;
7839
7840 ret = peer_unsuppress_map_unset(peer, afi, safi);
7841
7842 return bgp_vty_return(vty, ret);
7843 }
7844
7845 DEFUN (neighbor_unsuppress_map,
7846 neighbor_unsuppress_map_cmd,
7847 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7848 NEIGHBOR_STR
7849 NEIGHBOR_ADDR_STR2
7850 "Route-map to selectively unsuppress suppressed routes\n"
7851 "Name of route map\n")
7852 {
7853 int idx_peer = 1;
7854 int idx_word = 3;
7855 return peer_unsuppress_map_set_vty(
7856 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7857 argv[idx_word]->arg);
7858 }
7859
7860 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7861 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7862 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7863 "Route-map to selectively unsuppress suppressed routes\n"
7864 "Name of route map\n")
7865
7866 DEFUN (no_neighbor_unsuppress_map,
7867 no_neighbor_unsuppress_map_cmd,
7868 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7869 NO_STR
7870 NEIGHBOR_STR
7871 NEIGHBOR_ADDR_STR2
7872 "Route-map to selectively unsuppress suppressed routes\n"
7873 "Name of route map\n")
7874 {
7875 int idx_peer = 2;
7876 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7877 bgp_node_afi(vty),
7878 bgp_node_safi(vty));
7879 }
7880
7881 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7882 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7883 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7884 "Route-map to selectively unsuppress suppressed routes\n"
7885 "Name of route map\n")
7886
7887 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7888 afi_t afi, safi_t safi,
7889 const char *num_str,
7890 const char *threshold_str, int warning,
7891 const char *restart_str,
7892 const char *force_str)
7893 {
7894 int ret;
7895 struct peer *peer;
7896 uint32_t max;
7897 uint8_t threshold;
7898 uint16_t restart;
7899
7900 peer = peer_and_group_lookup_vty(vty, ip_str);
7901 if (!peer)
7902 return CMD_WARNING_CONFIG_FAILED;
7903
7904 max = strtoul(num_str, NULL, 10);
7905 if (threshold_str)
7906 threshold = atoi(threshold_str);
7907 else
7908 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7909
7910 if (restart_str)
7911 restart = atoi(restart_str);
7912 else
7913 restart = 0;
7914
7915 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7916 restart, force_str ? true : false);
7917
7918 return bgp_vty_return(vty, ret);
7919 }
7920
7921 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7922 afi_t afi, safi_t safi)
7923 {
7924 int ret;
7925 struct peer *peer;
7926
7927 peer = peer_and_group_lookup_vty(vty, ip_str);
7928 if (!peer)
7929 return CMD_WARNING_CONFIG_FAILED;
7930
7931 ret = peer_maximum_prefix_unset(peer, afi, safi);
7932
7933 return bgp_vty_return(vty, ret);
7934 }
7935
7936 /* Maximum number of prefix to be sent to the neighbor. */
7937 DEFUN(neighbor_maximum_prefix_out,
7938 neighbor_maximum_prefix_out_cmd,
7939 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7940 NEIGHBOR_STR
7941 NEIGHBOR_ADDR_STR2
7942 "Maximum number of prefixes to be sent to this peer\n"
7943 "Maximum no. of prefix limit\n")
7944 {
7945 int ret;
7946 int idx_peer = 1;
7947 int idx_number = 3;
7948 struct peer *peer;
7949 uint32_t max;
7950 afi_t afi = bgp_node_afi(vty);
7951 safi_t safi = bgp_node_safi(vty);
7952
7953 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7954 if (!peer)
7955 return CMD_WARNING_CONFIG_FAILED;
7956
7957 max = strtoul(argv[idx_number]->arg, NULL, 10);
7958
7959 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
7960
7961 return bgp_vty_return(vty, ret);
7962 }
7963
7964 DEFUN(no_neighbor_maximum_prefix_out,
7965 no_neighbor_maximum_prefix_out_cmd,
7966 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
7967 NO_STR
7968 NEIGHBOR_STR
7969 NEIGHBOR_ADDR_STR2
7970 "Maximum number of prefixes to be sent to this peer\n"
7971 "Maximum no. of prefix limit\n")
7972 {
7973 int ret;
7974 int idx_peer = 2;
7975 struct peer *peer;
7976 afi_t afi = bgp_node_afi(vty);
7977 safi_t safi = bgp_node_safi(vty);
7978
7979 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7980 if (!peer)
7981 return CMD_WARNING_CONFIG_FAILED;
7982
7983 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
7984
7985 return bgp_vty_return(vty, ret);
7986 }
7987
7988 /* Maximum number of prefix configuration. Prefix count is different
7989 for each peer configuration. So this configuration can be set for
7990 each peer configuration. */
7991 DEFUN (neighbor_maximum_prefix,
7992 neighbor_maximum_prefix_cmd,
7993 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7994 NEIGHBOR_STR
7995 NEIGHBOR_ADDR_STR2
7996 "Maximum number of prefix accept from this peer\n"
7997 "maximum no. of prefix limit\n"
7998 "Force checking all received routes not only accepted\n")
7999 {
8000 int idx_peer = 1;
8001 int idx_number = 3;
8002 int idx_force = 0;
8003 char *force = NULL;
8004
8005 if (argv_find(argv, argc, "force", &idx_force))
8006 force = argv[idx_force]->arg;
8007
8008 return peer_maximum_prefix_set_vty(
8009 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8010 argv[idx_number]->arg, NULL, 0, NULL, force);
8011 }
8012
8013 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8014 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8015 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8016 "Maximum number of prefix accept from this peer\n"
8017 "maximum no. of prefix limit\n"
8018 "Force checking all received routes not only accepted\n")
8019
8020 DEFUN (neighbor_maximum_prefix_threshold,
8021 neighbor_maximum_prefix_threshold_cmd,
8022 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8023 NEIGHBOR_STR
8024 NEIGHBOR_ADDR_STR2
8025 "Maximum number of prefix accept from this peer\n"
8026 "maximum no. of prefix limit\n"
8027 "Threshold value (%) at which to generate a warning msg\n"
8028 "Force checking all received routes not only accepted\n")
8029 {
8030 int idx_peer = 1;
8031 int idx_number = 3;
8032 int idx_number_2 = 4;
8033 int idx_force = 0;
8034 char *force = NULL;
8035
8036 if (argv_find(argv, argc, "force", &idx_force))
8037 force = argv[idx_force]->arg;
8038
8039 return peer_maximum_prefix_set_vty(
8040 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8041 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8042 }
8043
8044 ALIAS_HIDDEN(
8045 neighbor_maximum_prefix_threshold,
8046 neighbor_maximum_prefix_threshold_hidden_cmd,
8047 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8048 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8049 "Maximum number of prefix accept from this peer\n"
8050 "maximum no. of prefix limit\n"
8051 "Threshold value (%) at which to generate a warning msg\n"
8052 "Force checking all received routes not only accepted\n")
8053
8054 DEFUN (neighbor_maximum_prefix_warning,
8055 neighbor_maximum_prefix_warning_cmd,
8056 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8057 NEIGHBOR_STR
8058 NEIGHBOR_ADDR_STR2
8059 "Maximum number of prefix accept from this peer\n"
8060 "maximum no. of prefix limit\n"
8061 "Only give warning message when limit is exceeded\n"
8062 "Force checking all received routes not only accepted\n")
8063 {
8064 int idx_peer = 1;
8065 int idx_number = 3;
8066 int idx_force = 0;
8067 char *force = NULL;
8068
8069 if (argv_find(argv, argc, "force", &idx_force))
8070 force = argv[idx_force]->arg;
8071
8072 return peer_maximum_prefix_set_vty(
8073 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8074 argv[idx_number]->arg, NULL, 1, NULL, force);
8075 }
8076
8077 ALIAS_HIDDEN(
8078 neighbor_maximum_prefix_warning,
8079 neighbor_maximum_prefix_warning_hidden_cmd,
8080 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8081 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8082 "Maximum number of prefix accept from this peer\n"
8083 "maximum no. of prefix limit\n"
8084 "Only give warning message when limit is exceeded\n"
8085 "Force checking all received routes not only accepted\n")
8086
8087 DEFUN (neighbor_maximum_prefix_threshold_warning,
8088 neighbor_maximum_prefix_threshold_warning_cmd,
8089 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8090 NEIGHBOR_STR
8091 NEIGHBOR_ADDR_STR2
8092 "Maximum number of prefix accept from this peer\n"
8093 "maximum no. of prefix limit\n"
8094 "Threshold value (%) at which to generate a warning msg\n"
8095 "Only give warning message when limit is exceeded\n"
8096 "Force checking all received routes not only accepted\n")
8097 {
8098 int idx_peer = 1;
8099 int idx_number = 3;
8100 int idx_number_2 = 4;
8101 int idx_force = 0;
8102 char *force = NULL;
8103
8104 if (argv_find(argv, argc, "force", &idx_force))
8105 force = argv[idx_force]->arg;
8106
8107 return peer_maximum_prefix_set_vty(
8108 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8109 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8110 }
8111
8112 ALIAS_HIDDEN(
8113 neighbor_maximum_prefix_threshold_warning,
8114 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8115 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8116 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8117 "Maximum number of prefix accept from this peer\n"
8118 "maximum no. of prefix limit\n"
8119 "Threshold value (%) at which to generate a warning msg\n"
8120 "Only give warning message when limit is exceeded\n"
8121 "Force checking all received routes not only accepted\n")
8122
8123 DEFUN (neighbor_maximum_prefix_restart,
8124 neighbor_maximum_prefix_restart_cmd,
8125 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8126 NEIGHBOR_STR
8127 NEIGHBOR_ADDR_STR2
8128 "Maximum number of prefix accept from this peer\n"
8129 "maximum no. of prefix limit\n"
8130 "Restart bgp connection after limit is exceeded\n"
8131 "Restart interval in minutes\n"
8132 "Force checking all received routes not only accepted\n")
8133 {
8134 int idx_peer = 1;
8135 int idx_number = 3;
8136 int idx_number_2 = 5;
8137 int idx_force = 0;
8138 char *force = NULL;
8139
8140 if (argv_find(argv, argc, "force", &idx_force))
8141 force = argv[idx_force]->arg;
8142
8143 return peer_maximum_prefix_set_vty(
8144 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8145 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8146 }
8147
8148 ALIAS_HIDDEN(
8149 neighbor_maximum_prefix_restart,
8150 neighbor_maximum_prefix_restart_hidden_cmd,
8151 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8152 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8153 "Maximum number of prefix accept from this peer\n"
8154 "maximum no. of prefix limit\n"
8155 "Restart bgp connection after limit is exceeded\n"
8156 "Restart interval in minutes\n"
8157 "Force checking all received routes not only accepted\n")
8158
8159 DEFUN (neighbor_maximum_prefix_threshold_restart,
8160 neighbor_maximum_prefix_threshold_restart_cmd,
8161 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8162 NEIGHBOR_STR
8163 NEIGHBOR_ADDR_STR2
8164 "Maximum number of prefixes to accept from this peer\n"
8165 "maximum no. of prefix limit\n"
8166 "Threshold value (%) at which to generate a warning msg\n"
8167 "Restart bgp connection after limit is exceeded\n"
8168 "Restart interval in minutes\n"
8169 "Force checking all received routes not only accepted\n")
8170 {
8171 int idx_peer = 1;
8172 int idx_number = 3;
8173 int idx_number_2 = 4;
8174 int idx_number_3 = 6;
8175 int idx_force = 0;
8176 char *force = NULL;
8177
8178 if (argv_find(argv, argc, "force", &idx_force))
8179 force = argv[idx_force]->arg;
8180
8181 return peer_maximum_prefix_set_vty(
8182 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8183 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8184 argv[idx_number_3]->arg, force);
8185 }
8186
8187 ALIAS_HIDDEN(
8188 neighbor_maximum_prefix_threshold_restart,
8189 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8190 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8191 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8192 "Maximum number of prefixes to accept from this peer\n"
8193 "maximum no. of prefix limit\n"
8194 "Threshold value (%) at which to generate a warning msg\n"
8195 "Restart bgp connection after limit is exceeded\n"
8196 "Restart interval in minutes\n"
8197 "Force checking all received routes not only accepted\n")
8198
8199 DEFUN (no_neighbor_maximum_prefix,
8200 no_neighbor_maximum_prefix_cmd,
8201 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8202 NO_STR
8203 NEIGHBOR_STR
8204 NEIGHBOR_ADDR_STR2
8205 "Maximum number of prefixes to accept from this peer\n"
8206 "maximum no. of prefix limit\n"
8207 "Threshold value (%) at which to generate a warning msg\n"
8208 "Restart bgp connection after limit is exceeded\n"
8209 "Restart interval in minutes\n"
8210 "Only give warning message when limit is exceeded\n"
8211 "Force checking all received routes not only accepted\n")
8212 {
8213 int idx_peer = 2;
8214 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8215 bgp_node_afi(vty),
8216 bgp_node_safi(vty));
8217 }
8218
8219 ALIAS_HIDDEN(
8220 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8221 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8223 "Maximum number of prefixes to accept from this peer\n"
8224 "maximum no. of prefix limit\n"
8225 "Threshold value (%) at which to generate a warning msg\n"
8226 "Restart bgp connection after limit is exceeded\n"
8227 "Restart interval in minutes\n"
8228 "Only give warning message when limit is exceeded\n"
8229 "Force checking all received routes not only accepted\n")
8230
8231
8232 /* "neighbor allowas-in" */
8233 DEFUN (neighbor_allowas_in,
8234 neighbor_allowas_in_cmd,
8235 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8236 NEIGHBOR_STR
8237 NEIGHBOR_ADDR_STR2
8238 "Accept as-path with my AS present in it\n"
8239 "Number of occurrences of AS number\n"
8240 "Only accept my AS in the as-path if the route was originated in my AS\n")
8241 {
8242 int idx_peer = 1;
8243 int idx_number_origin = 3;
8244 int ret;
8245 int origin = 0;
8246 struct peer *peer;
8247 int allow_num = 0;
8248
8249 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8250 if (!peer)
8251 return CMD_WARNING_CONFIG_FAILED;
8252
8253 if (argc <= idx_number_origin)
8254 allow_num = 3;
8255 else {
8256 if (argv[idx_number_origin]->type == WORD_TKN)
8257 origin = 1;
8258 else
8259 allow_num = atoi(argv[idx_number_origin]->arg);
8260 }
8261
8262 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8263 allow_num, origin);
8264
8265 return bgp_vty_return(vty, ret);
8266 }
8267
8268 ALIAS_HIDDEN(
8269 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8270 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8271 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8272 "Accept as-path with my AS present in it\n"
8273 "Number of occurrences of AS number\n"
8274 "Only accept my AS in the as-path if the route was originated in my AS\n")
8275
8276 DEFUN (no_neighbor_allowas_in,
8277 no_neighbor_allowas_in_cmd,
8278 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8279 NO_STR
8280 NEIGHBOR_STR
8281 NEIGHBOR_ADDR_STR2
8282 "allow local ASN appears in aspath attribute\n"
8283 "Number of occurrences of AS number\n"
8284 "Only accept my AS in the as-path if the route was originated in my AS\n")
8285 {
8286 int idx_peer = 2;
8287 int ret;
8288 struct peer *peer;
8289
8290 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8291 if (!peer)
8292 return CMD_WARNING_CONFIG_FAILED;
8293
8294 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8295 bgp_node_safi(vty));
8296
8297 return bgp_vty_return(vty, ret);
8298 }
8299
8300 ALIAS_HIDDEN(
8301 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8302 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8303 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8304 "allow local ASN appears in aspath attribute\n"
8305 "Number of occurrences of AS number\n"
8306 "Only accept my AS in the as-path if the route was originated in my AS\n")
8307
8308 DEFUN (neighbor_ttl_security,
8309 neighbor_ttl_security_cmd,
8310 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8311 NEIGHBOR_STR
8312 NEIGHBOR_ADDR_STR2
8313 "BGP ttl-security parameters\n"
8314 "Specify the maximum number of hops to the BGP peer\n"
8315 "Number of hops to BGP peer\n")
8316 {
8317 int idx_peer = 1;
8318 int idx_number = 4;
8319 struct peer *peer;
8320 int gtsm_hops;
8321
8322 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8323 if (!peer)
8324 return CMD_WARNING_CONFIG_FAILED;
8325
8326 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8327
8328 /*
8329 * If 'neighbor swpX', then this is for directly connected peers,
8330 * we should not accept a ttl-security hops value greater than 1.
8331 */
8332 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8333 vty_out(vty,
8334 "%s is directly connected peer, hops cannot exceed 1\n",
8335 argv[idx_peer]->arg);
8336 return CMD_WARNING_CONFIG_FAILED;
8337 }
8338
8339 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8340 }
8341
8342 DEFUN (no_neighbor_ttl_security,
8343 no_neighbor_ttl_security_cmd,
8344 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8345 NO_STR
8346 NEIGHBOR_STR
8347 NEIGHBOR_ADDR_STR2
8348 "BGP ttl-security parameters\n"
8349 "Specify the maximum number of hops to the BGP peer\n"
8350 "Number of hops to BGP peer\n")
8351 {
8352 int idx_peer = 2;
8353 struct peer *peer;
8354
8355 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8356 if (!peer)
8357 return CMD_WARNING_CONFIG_FAILED;
8358
8359 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8360 }
8361
8362 /* disable-addpath-rx */
8363 DEFUN(neighbor_disable_addpath_rx,
8364 neighbor_disable_addpath_rx_cmd,
8365 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8366 NEIGHBOR_STR
8367 NEIGHBOR_ADDR_STR2
8368 "Do not accept additional paths\n")
8369 {
8370 char *peer_str = argv[1]->arg;
8371 struct peer *peer;
8372 afi_t afi = bgp_node_afi(vty);
8373 safi_t safi = bgp_node_safi(vty);
8374
8375 peer = peer_and_group_lookup_vty(vty, peer_str);
8376 if (!peer)
8377 return CMD_WARNING_CONFIG_FAILED;
8378
8379 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8380 PEER_FLAG_DISABLE_ADDPATH_RX);
8381 }
8382
8383 DEFUN(no_neighbor_disable_addpath_rx,
8384 no_neighbor_disable_addpath_rx_cmd,
8385 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8386 NO_STR
8387 NEIGHBOR_STR
8388 NEIGHBOR_ADDR_STR2
8389 "Do not accept additional paths\n")
8390 {
8391 char *peer_str = argv[2]->arg;
8392 struct peer *peer;
8393 afi_t afi = bgp_node_afi(vty);
8394 safi_t safi = bgp_node_safi(vty);
8395
8396 peer = peer_and_group_lookup_vty(vty, peer_str);
8397 if (!peer)
8398 return CMD_WARNING_CONFIG_FAILED;
8399
8400 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8401 PEER_FLAG_DISABLE_ADDPATH_RX);
8402 }
8403
8404 DEFUN (neighbor_addpath_tx_all_paths,
8405 neighbor_addpath_tx_all_paths_cmd,
8406 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8407 NEIGHBOR_STR
8408 NEIGHBOR_ADDR_STR2
8409 "Use addpath to advertise all paths to a neighbor\n")
8410 {
8411 int idx_peer = 1;
8412 struct peer *peer;
8413
8414 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8415 if (!peer)
8416 return CMD_WARNING_CONFIG_FAILED;
8417
8418 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8419 BGP_ADDPATH_ALL);
8420 return CMD_SUCCESS;
8421 }
8422
8423 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8424 neighbor_addpath_tx_all_paths_hidden_cmd,
8425 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8426 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8427 "Use addpath to advertise all paths to a neighbor\n")
8428
8429 DEFUN (no_neighbor_addpath_tx_all_paths,
8430 no_neighbor_addpath_tx_all_paths_cmd,
8431 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8432 NO_STR
8433 NEIGHBOR_STR
8434 NEIGHBOR_ADDR_STR2
8435 "Use addpath to advertise all paths to a neighbor\n")
8436 {
8437 int idx_peer = 2;
8438 struct peer *peer;
8439
8440 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8441 if (!peer)
8442 return CMD_WARNING_CONFIG_FAILED;
8443
8444 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8445 != BGP_ADDPATH_ALL) {
8446 vty_out(vty,
8447 "%% Peer not currently configured to transmit all paths.");
8448 return CMD_WARNING_CONFIG_FAILED;
8449 }
8450
8451 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8452 BGP_ADDPATH_NONE);
8453
8454 return CMD_SUCCESS;
8455 }
8456
8457 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8458 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8459 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8460 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8461 "Use addpath to advertise all paths to a neighbor\n")
8462
8463 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8464 neighbor_addpath_tx_bestpath_per_as_cmd,
8465 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8466 NEIGHBOR_STR
8467 NEIGHBOR_ADDR_STR2
8468 "Use addpath to advertise the bestpath per each neighboring AS\n")
8469 {
8470 int idx_peer = 1;
8471 struct peer *peer;
8472
8473 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8474 if (!peer)
8475 return CMD_WARNING_CONFIG_FAILED;
8476
8477 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8478 BGP_ADDPATH_BEST_PER_AS);
8479
8480 return CMD_SUCCESS;
8481 }
8482
8483 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8484 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8485 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8486 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8487 "Use addpath to advertise the bestpath per each neighboring AS\n")
8488
8489 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8490 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8491 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8492 NO_STR
8493 NEIGHBOR_STR
8494 NEIGHBOR_ADDR_STR2
8495 "Use addpath to advertise the bestpath per each neighboring AS\n")
8496 {
8497 int idx_peer = 2;
8498 struct peer *peer;
8499
8500 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8501 if (!peer)
8502 return CMD_WARNING_CONFIG_FAILED;
8503
8504 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8505 != BGP_ADDPATH_BEST_PER_AS) {
8506 vty_out(vty,
8507 "%% Peer not currently configured to transmit all best path per as.");
8508 return CMD_WARNING_CONFIG_FAILED;
8509 }
8510
8511 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8512 BGP_ADDPATH_NONE);
8513
8514 return CMD_SUCCESS;
8515 }
8516
8517 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8518 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8519 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8520 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8521 "Use addpath to advertise the bestpath per each neighboring AS\n")
8522
8523 DEFPY(
8524 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8525 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8526 NEIGHBOR_STR
8527 NEIGHBOR_ADDR_STR2
8528 "Detect AS loops before sending to neighbor\n")
8529 {
8530 struct peer *peer;
8531
8532 peer = peer_and_group_lookup_vty(vty, neighbor);
8533 if (!peer)
8534 return CMD_WARNING_CONFIG_FAILED;
8535
8536 peer->as_path_loop_detection = true;
8537
8538 return CMD_SUCCESS;
8539 }
8540
8541 DEFPY(
8542 no_neighbor_aspath_loop_detection,
8543 no_neighbor_aspath_loop_detection_cmd,
8544 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8545 NO_STR
8546 NEIGHBOR_STR
8547 NEIGHBOR_ADDR_STR2
8548 "Detect AS loops before sending to neighbor\n")
8549 {
8550 struct peer *peer;
8551
8552 peer = peer_and_group_lookup_vty(vty, neighbor);
8553 if (!peer)
8554 return CMD_WARNING_CONFIG_FAILED;
8555
8556 peer->as_path_loop_detection = false;
8557
8558 return CMD_SUCCESS;
8559 }
8560
8561 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8562 struct ecommunity **list, bool is_rt6)
8563 {
8564 struct ecommunity *ecom = NULL;
8565 struct ecommunity *ecomadd;
8566
8567 for (; argc; --argc, ++argv) {
8568 if (is_rt6)
8569 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8570 ECOMMUNITY_ROUTE_TARGET,
8571 0);
8572 else
8573 ecomadd = ecommunity_str2com(argv[0]->arg,
8574 ECOMMUNITY_ROUTE_TARGET,
8575 0);
8576 if (!ecomadd) {
8577 vty_out(vty, "Malformed community-list value\n");
8578 if (ecom)
8579 ecommunity_free(&ecom);
8580 return CMD_WARNING_CONFIG_FAILED;
8581 }
8582
8583 if (ecom) {
8584 ecommunity_merge(ecom, ecomadd);
8585 ecommunity_free(&ecomadd);
8586 } else {
8587 ecom = ecomadd;
8588 }
8589 }
8590
8591 if (*list) {
8592 ecommunity_free(&*list);
8593 }
8594 *list = ecom;
8595
8596 return CMD_SUCCESS;
8597 }
8598
8599 /*
8600 * v2vimport is true if we are handling a `import vrf ...` command
8601 */
8602 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8603 {
8604 afi_t afi;
8605
8606 switch (vty->node) {
8607 case BGP_IPV4_NODE:
8608 afi = AFI_IP;
8609 break;
8610 case BGP_IPV6_NODE:
8611 afi = AFI_IP6;
8612 break;
8613 default:
8614 vty_out(vty,
8615 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8616 return AFI_MAX;
8617 }
8618
8619 if (!v2vimport) {
8620 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8621 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8622 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8623 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8624 vty_out(vty,
8625 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8626 return AFI_MAX;
8627 }
8628 } else {
8629 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8630 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8631 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8632 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8633 vty_out(vty,
8634 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8635 return AFI_MAX;
8636 }
8637 }
8638 return afi;
8639 }
8640
8641 DEFPY (af_rd_vpn_export,
8642 af_rd_vpn_export_cmd,
8643 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8644 NO_STR
8645 "Specify route distinguisher\n"
8646 "Between current address-family and vpn\n"
8647 "For routes leaked from current address-family to vpn\n"
8648 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8649 {
8650 VTY_DECLVAR_CONTEXT(bgp, bgp);
8651 struct prefix_rd prd;
8652 int ret;
8653 afi_t afi;
8654 int idx = 0;
8655 bool yes = true;
8656
8657 if (argv_find(argv, argc, "no", &idx))
8658 yes = false;
8659
8660 if (yes) {
8661 ret = str2prefix_rd(rd_str, &prd);
8662 if (!ret) {
8663 vty_out(vty, "%% Malformed rd\n");
8664 return CMD_WARNING_CONFIG_FAILED;
8665 }
8666 }
8667
8668 afi = vpn_policy_getafi(vty, bgp, false);
8669 if (afi == AFI_MAX)
8670 return CMD_WARNING_CONFIG_FAILED;
8671
8672 /*
8673 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8674 */
8675 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8676 bgp_get_default(), bgp);
8677
8678 if (yes) {
8679 bgp->vpn_policy[afi].tovpn_rd = prd;
8680 SET_FLAG(bgp->vpn_policy[afi].flags,
8681 BGP_VPN_POLICY_TOVPN_RD_SET);
8682 } else {
8683 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8684 BGP_VPN_POLICY_TOVPN_RD_SET);
8685 }
8686
8687 /* post-change: re-export vpn routes */
8688 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8689 bgp_get_default(), bgp);
8690
8691 return CMD_SUCCESS;
8692 }
8693
8694 ALIAS (af_rd_vpn_export,
8695 af_no_rd_vpn_export_cmd,
8696 "no rd vpn export",
8697 NO_STR
8698 "Specify route distinguisher\n"
8699 "Between current address-family and vpn\n"
8700 "For routes leaked from current address-family to vpn\n")
8701
8702 DEFPY (af_label_vpn_export,
8703 af_label_vpn_export_cmd,
8704 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8705 NO_STR
8706 "label value for VRF\n"
8707 "Between current address-family and vpn\n"
8708 "For routes leaked from current address-family to vpn\n"
8709 "Label Value <0-1048575>\n"
8710 "Automatically assign a label\n")
8711 {
8712 VTY_DECLVAR_CONTEXT(bgp, bgp);
8713 mpls_label_t label = MPLS_LABEL_NONE;
8714 afi_t afi;
8715 int idx = 0;
8716 bool yes = true;
8717
8718 if (argv_find(argv, argc, "no", &idx))
8719 yes = false;
8720
8721 /* If "no ...", squash trailing parameter */
8722 if (!yes)
8723 label_auto = NULL;
8724
8725 if (yes) {
8726 if (!label_auto)
8727 label = label_val; /* parser should force unsigned */
8728 }
8729
8730 afi = vpn_policy_getafi(vty, bgp, false);
8731 if (afi == AFI_MAX)
8732 return CMD_WARNING_CONFIG_FAILED;
8733
8734
8735 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8736 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8737 /* no change */
8738 return CMD_SUCCESS;
8739
8740 /*
8741 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8742 */
8743 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8744 bgp_get_default(), bgp);
8745
8746 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8747 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8748
8749 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8750
8751 /*
8752 * label has previously been automatically
8753 * assigned by labelpool: release it
8754 *
8755 * NB if tovpn_label == MPLS_LABEL_NONE it
8756 * means the automatic assignment is in flight
8757 * and therefore the labelpool callback must
8758 * detect that the auto label is not needed.
8759 */
8760
8761 bgp_lp_release(LP_TYPE_VRF,
8762 &bgp->vpn_policy[afi],
8763 bgp->vpn_policy[afi].tovpn_label);
8764 }
8765 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8766 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8767 }
8768
8769 bgp->vpn_policy[afi].tovpn_label = label;
8770 if (label_auto) {
8771 SET_FLAG(bgp->vpn_policy[afi].flags,
8772 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8773 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8774 vpn_leak_label_callback);
8775 }
8776
8777 /* post-change: re-export vpn routes */
8778 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8779 bgp_get_default(), bgp);
8780
8781 hook_call(bgp_snmp_update_last_changed, bgp);
8782 return CMD_SUCCESS;
8783 }
8784
8785 DEFPY (af_sid_vpn_export,
8786 af_sid_vpn_export_cmd,
8787 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8788 NO_STR
8789 "sid value for VRF\n"
8790 "Between current address-family and vpn\n"
8791 "For routes leaked from current address-family to vpn\n"
8792 "Sid allocation index\n"
8793 "Automatically assign a label\n")
8794 {
8795 VTY_DECLVAR_CONTEXT(bgp, bgp);
8796 afi_t afi;
8797 int debug = 0;
8798 int idx = 0;
8799 bool yes = true;
8800
8801 if (argv_find(argv, argc, "no", &idx))
8802 yes = false;
8803 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8804 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8805
8806 afi = vpn_policy_getafi(vty, bgp, false);
8807 if (afi == AFI_MAX)
8808 return CMD_WARNING_CONFIG_FAILED;
8809
8810 if (!yes) {
8811 /* implement me */
8812 vty_out(vty, "It's not implemented\n");
8813 return CMD_WARNING_CONFIG_FAILED;
8814 }
8815
8816 /* skip when it's already configured */
8817 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8818 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8819 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8820 return CMD_SUCCESS;
8821
8822 /*
8823 * mode change between sid_idx and sid_auto isn't supported.
8824 * user must negate sid vpn export when they want to change the mode
8825 */
8826 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8827 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8828 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8829 vty_out(vty, "it's already configured as %s.\n",
8830 sid_auto ? "auto-mode" : "idx-mode");
8831 return CMD_WARNING_CONFIG_FAILED;
8832 }
8833
8834 /* pre-change */
8835 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8836 bgp_get_default(), bgp);
8837
8838 if (sid_auto) {
8839 /* SID allocation auto-mode */
8840 if (debug)
8841 zlog_debug("%s: auto sid alloc.", __func__);
8842 SET_FLAG(bgp->vpn_policy[afi].flags,
8843 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8844 } else {
8845 /* SID allocation index-mode */
8846 if (debug)
8847 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8848 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8849 }
8850
8851 /* post-change */
8852 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8853 bgp_get_default(), bgp);
8854 return CMD_SUCCESS;
8855 }
8856
8857 ALIAS (af_label_vpn_export,
8858 af_no_label_vpn_export_cmd,
8859 "no label vpn export",
8860 NO_STR
8861 "label value for VRF\n"
8862 "Between current address-family and vpn\n"
8863 "For routes leaked from current address-family to vpn\n")
8864
8865 DEFPY (af_nexthop_vpn_export,
8866 af_nexthop_vpn_export_cmd,
8867 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8868 NO_STR
8869 "Specify next hop to use for VRF advertised prefixes\n"
8870 "Between current address-family and vpn\n"
8871 "For routes leaked from current address-family to vpn\n"
8872 "IPv4 prefix\n"
8873 "IPv6 prefix\n")
8874 {
8875 VTY_DECLVAR_CONTEXT(bgp, bgp);
8876 afi_t afi;
8877 struct prefix p;
8878
8879 if (!no) {
8880 if (!nexthop_su) {
8881 vty_out(vty, "%% Nexthop required\n");
8882 return CMD_WARNING_CONFIG_FAILED;
8883 }
8884 if (!sockunion2hostprefix(nexthop_su, &p))
8885 return CMD_WARNING_CONFIG_FAILED;
8886 }
8887
8888 afi = vpn_policy_getafi(vty, bgp, false);
8889 if (afi == AFI_MAX)
8890 return CMD_WARNING_CONFIG_FAILED;
8891
8892 /*
8893 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8894 */
8895 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8896 bgp_get_default(), bgp);
8897
8898 if (!no) {
8899 bgp->vpn_policy[afi].tovpn_nexthop = p;
8900 SET_FLAG(bgp->vpn_policy[afi].flags,
8901 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8902 } else {
8903 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8904 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8905 }
8906
8907 /* post-change: re-export vpn routes */
8908 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8909 bgp_get_default(), bgp);
8910
8911 return CMD_SUCCESS;
8912 }
8913
8914 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8915 {
8916 if (!strcmp(dstr, "import")) {
8917 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8918 } else if (!strcmp(dstr, "export")) {
8919 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8920 } else if (!strcmp(dstr, "both")) {
8921 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8922 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8923 } else {
8924 vty_out(vty, "%% direction parse error\n");
8925 return CMD_WARNING_CONFIG_FAILED;
8926 }
8927 return CMD_SUCCESS;
8928 }
8929
8930 DEFPY (af_rt_vpn_imexport,
8931 af_rt_vpn_imexport_cmd,
8932 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8933 NO_STR
8934 "Specify route target list\n"
8935 "Specify route target list\n"
8936 "Between current address-family and vpn\n"
8937 "For routes leaked from vpn to current address-family: match any\n"
8938 "For routes leaked from current address-family to vpn: set\n"
8939 "both import: match any and export: set\n"
8940 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8941 {
8942 VTY_DECLVAR_CONTEXT(bgp, bgp);
8943 int ret;
8944 struct ecommunity *ecom = NULL;
8945 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8946 enum vpn_policy_direction dir;
8947 afi_t afi;
8948 int idx = 0;
8949 bool yes = true;
8950
8951 if (argv_find(argv, argc, "no", &idx))
8952 yes = false;
8953
8954 afi = vpn_policy_getafi(vty, bgp, false);
8955 if (afi == AFI_MAX)
8956 return CMD_WARNING_CONFIG_FAILED;
8957
8958 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8959 if (ret != CMD_SUCCESS)
8960 return ret;
8961
8962 if (yes) {
8963 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8964 vty_out(vty, "%% Missing RTLIST\n");
8965 return CMD_WARNING_CONFIG_FAILED;
8966 }
8967 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8968 if (ret != CMD_SUCCESS) {
8969 return ret;
8970 }
8971 }
8972
8973 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8974 if (!dodir[dir])
8975 continue;
8976
8977 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8978
8979 if (yes) {
8980 if (bgp->vpn_policy[afi].rtlist[dir])
8981 ecommunity_free(
8982 &bgp->vpn_policy[afi].rtlist[dir]);
8983 bgp->vpn_policy[afi].rtlist[dir] =
8984 ecommunity_dup(ecom);
8985 } else {
8986 if (bgp->vpn_policy[afi].rtlist[dir])
8987 ecommunity_free(
8988 &bgp->vpn_policy[afi].rtlist[dir]);
8989 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8990 }
8991
8992 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8993 }
8994
8995 if (ecom)
8996 ecommunity_free(&ecom);
8997
8998 return CMD_SUCCESS;
8999 }
9000
9001 ALIAS (af_rt_vpn_imexport,
9002 af_no_rt_vpn_imexport_cmd,
9003 "no <rt|route-target> vpn <import|export|both>$direction_str",
9004 NO_STR
9005 "Specify route target list\n"
9006 "Specify route target list\n"
9007 "Between current address-family and vpn\n"
9008 "For routes leaked from vpn to current address-family\n"
9009 "For routes leaked from current address-family to vpn\n"
9010 "both import and export\n")
9011
9012 DEFPY (af_route_map_vpn_imexport,
9013 af_route_map_vpn_imexport_cmd,
9014 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9015 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9016 NO_STR
9017 "Specify route map\n"
9018 "Between current address-family and vpn\n"
9019 "For routes leaked from vpn to current address-family\n"
9020 "For routes leaked from current address-family to vpn\n"
9021 "name of route-map\n")
9022 {
9023 VTY_DECLVAR_CONTEXT(bgp, bgp);
9024 int ret;
9025 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9026 enum vpn_policy_direction dir;
9027 afi_t afi;
9028 int idx = 0;
9029 bool yes = true;
9030
9031 if (argv_find(argv, argc, "no", &idx))
9032 yes = false;
9033
9034 afi = vpn_policy_getafi(vty, bgp, false);
9035 if (afi == AFI_MAX)
9036 return CMD_WARNING_CONFIG_FAILED;
9037
9038 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9039 if (ret != CMD_SUCCESS)
9040 return ret;
9041
9042 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9043 if (!dodir[dir])
9044 continue;
9045
9046 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9047
9048 if (yes) {
9049 if (bgp->vpn_policy[afi].rmap_name[dir])
9050 XFREE(MTYPE_ROUTE_MAP_NAME,
9051 bgp->vpn_policy[afi].rmap_name[dir]);
9052 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9053 MTYPE_ROUTE_MAP_NAME, rmap_str);
9054 bgp->vpn_policy[afi].rmap[dir] =
9055 route_map_lookup_warn_noexist(vty, rmap_str);
9056 if (!bgp->vpn_policy[afi].rmap[dir])
9057 return CMD_SUCCESS;
9058 } else {
9059 if (bgp->vpn_policy[afi].rmap_name[dir])
9060 XFREE(MTYPE_ROUTE_MAP_NAME,
9061 bgp->vpn_policy[afi].rmap_name[dir]);
9062 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9063 bgp->vpn_policy[afi].rmap[dir] = NULL;
9064 }
9065
9066 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9067 }
9068
9069 return CMD_SUCCESS;
9070 }
9071
9072 ALIAS (af_route_map_vpn_imexport,
9073 af_no_route_map_vpn_imexport_cmd,
9074 "no route-map vpn <import|export>$direction_str",
9075 NO_STR
9076 "Specify route map\n"
9077 "Between current address-family and vpn\n"
9078 "For routes leaked from vpn to current address-family\n"
9079 "For routes leaked from current address-family to vpn\n")
9080
9081 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9082 "import vrf route-map RMAP$rmap_str",
9083 "Import routes from another VRF\n"
9084 "Vrf routes being filtered\n"
9085 "Specify route map\n"
9086 "name of route-map\n")
9087 {
9088 VTY_DECLVAR_CONTEXT(bgp, bgp);
9089 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9090 afi_t afi;
9091 struct bgp *bgp_default;
9092
9093 afi = vpn_policy_getafi(vty, bgp, true);
9094 if (afi == AFI_MAX)
9095 return CMD_WARNING_CONFIG_FAILED;
9096
9097 bgp_default = bgp_get_default();
9098 if (!bgp_default) {
9099 int32_t ret;
9100 as_t as = bgp->as;
9101
9102 /* Auto-create assuming the same AS */
9103 ret = bgp_get_vty(&bgp_default, &as, NULL,
9104 BGP_INSTANCE_TYPE_DEFAULT);
9105
9106 if (ret) {
9107 vty_out(vty,
9108 "VRF default is not configured as a bgp instance\n");
9109 return CMD_WARNING;
9110 }
9111 }
9112
9113 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9114
9115 if (bgp->vpn_policy[afi].rmap_name[dir])
9116 XFREE(MTYPE_ROUTE_MAP_NAME,
9117 bgp->vpn_policy[afi].rmap_name[dir]);
9118 bgp->vpn_policy[afi].rmap_name[dir] =
9119 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9120 bgp->vpn_policy[afi].rmap[dir] =
9121 route_map_lookup_warn_noexist(vty, rmap_str);
9122 if (!bgp->vpn_policy[afi].rmap[dir])
9123 return CMD_SUCCESS;
9124
9125 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9126 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9127
9128 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9129
9130 return CMD_SUCCESS;
9131 }
9132
9133 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9134 "no import vrf route-map [RMAP$rmap_str]",
9135 NO_STR
9136 "Import routes from another VRF\n"
9137 "Vrf routes being filtered\n"
9138 "Specify route map\n"
9139 "name of route-map\n")
9140 {
9141 VTY_DECLVAR_CONTEXT(bgp, bgp);
9142 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9143 afi_t afi;
9144
9145 afi = vpn_policy_getafi(vty, bgp, true);
9146 if (afi == AFI_MAX)
9147 return CMD_WARNING_CONFIG_FAILED;
9148
9149 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9150
9151 if (bgp->vpn_policy[afi].rmap_name[dir])
9152 XFREE(MTYPE_ROUTE_MAP_NAME,
9153 bgp->vpn_policy[afi].rmap_name[dir]);
9154 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9155 bgp->vpn_policy[afi].rmap[dir] = NULL;
9156
9157 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9158 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9159 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9160
9161 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9162
9163 return CMD_SUCCESS;
9164 }
9165
9166 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9167 "[no] import vrf VIEWVRFNAME$import_name",
9168 NO_STR
9169 "Import routes from another VRF\n"
9170 "VRF to import from\n"
9171 "The name of the VRF\n")
9172 {
9173 VTY_DECLVAR_CONTEXT(bgp, bgp);
9174 struct listnode *node;
9175 struct bgp *vrf_bgp, *bgp_default;
9176 int32_t ret = 0;
9177 as_t as = bgp->as;
9178 bool remove = false;
9179 int32_t idx = 0;
9180 char *vname;
9181 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9182 safi_t safi;
9183 afi_t afi;
9184
9185 if (import_name == NULL) {
9186 vty_out(vty, "%% Missing import name\n");
9187 return CMD_WARNING;
9188 }
9189
9190 if (strcmp(import_name, "route-map") == 0) {
9191 vty_out(vty, "%% Must include route-map name\n");
9192 return CMD_WARNING;
9193 }
9194
9195 if (argv_find(argv, argc, "no", &idx))
9196 remove = true;
9197
9198 afi = vpn_policy_getafi(vty, bgp, true);
9199 if (afi == AFI_MAX)
9200 return CMD_WARNING_CONFIG_FAILED;
9201
9202 safi = bgp_node_safi(vty);
9203
9204 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9205 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9206 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9207 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9208 remove ? "unimport" : "import", import_name);
9209 return CMD_WARNING;
9210 }
9211
9212 bgp_default = bgp_get_default();
9213 if (!bgp_default) {
9214 /* Auto-create assuming the same AS */
9215 ret = bgp_get_vty(&bgp_default, &as, NULL,
9216 BGP_INSTANCE_TYPE_DEFAULT);
9217
9218 if (ret) {
9219 vty_out(vty,
9220 "VRF default is not configured as a bgp instance\n");
9221 return CMD_WARNING;
9222 }
9223 }
9224
9225 vrf_bgp = bgp_lookup_by_name(import_name);
9226 if (!vrf_bgp) {
9227 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9228 vrf_bgp = bgp_default;
9229 else
9230 /* Auto-create assuming the same AS */
9231 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9232
9233 if (ret) {
9234 vty_out(vty,
9235 "VRF %s is not configured as a bgp instance\n",
9236 import_name);
9237 return CMD_WARNING;
9238 }
9239 }
9240
9241 if (remove) {
9242 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9243 } else {
9244 /* Already importing from "import_vrf"? */
9245 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9246 vname)) {
9247 if (strcmp(vname, import_name) == 0)
9248 return CMD_WARNING;
9249 }
9250
9251 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9252 }
9253
9254 return CMD_SUCCESS;
9255 }
9256
9257 /* This command is valid only in a bgp vrf instance or the default instance */
9258 DEFPY (bgp_imexport_vpn,
9259 bgp_imexport_vpn_cmd,
9260 "[no] <import|export>$direction_str vpn",
9261 NO_STR
9262 "Import routes to this address-family\n"
9263 "Export routes from this address-family\n"
9264 "to/from default instance VPN RIB\n")
9265 {
9266 VTY_DECLVAR_CONTEXT(bgp, bgp);
9267 int previous_state;
9268 afi_t afi;
9269 safi_t safi;
9270 int idx = 0;
9271 bool yes = true;
9272 int flag;
9273 enum vpn_policy_direction dir;
9274
9275 if (argv_find(argv, argc, "no", &idx))
9276 yes = false;
9277
9278 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9279 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9280
9281 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9282 return CMD_WARNING_CONFIG_FAILED;
9283 }
9284
9285 afi = bgp_node_afi(vty);
9286 safi = bgp_node_safi(vty);
9287 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9288 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9289 return CMD_WARNING_CONFIG_FAILED;
9290 }
9291
9292 if (!strcmp(direction_str, "import")) {
9293 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9294 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9295 } else if (!strcmp(direction_str, "export")) {
9296 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9297 dir = BGP_VPN_POLICY_DIR_TOVPN;
9298 } else {
9299 vty_out(vty, "%% unknown direction %s\n", direction_str);
9300 return CMD_WARNING_CONFIG_FAILED;
9301 }
9302
9303 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9304
9305 if (yes) {
9306 SET_FLAG(bgp->af_flags[afi][safi], flag);
9307 if (!previous_state) {
9308 /* trigger export current vrf */
9309 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9310 }
9311 } else {
9312 if (previous_state) {
9313 /* trigger un-export current vrf */
9314 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9315 }
9316 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9317 }
9318
9319 hook_call(bgp_snmp_init_stats, bgp);
9320
9321 return CMD_SUCCESS;
9322 }
9323
9324 DEFPY (af_routetarget_import,
9325 af_routetarget_import_cmd,
9326 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9327 NO_STR
9328 "Specify route target list\n"
9329 "Specify route target list\n"
9330 "Specify route target list\n"
9331 "Specify route target list\n"
9332 "Flow-spec redirect type route target\n"
9333 "Import routes to this address-family\n"
9334 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9335 {
9336 VTY_DECLVAR_CONTEXT(bgp, bgp);
9337 int ret;
9338 struct ecommunity *ecom = NULL;
9339 afi_t afi;
9340 int idx = 0, idx_unused = 0;
9341 bool yes = true;
9342 bool rt6 = false;
9343
9344 if (argv_find(argv, argc, "no", &idx))
9345 yes = false;
9346
9347 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9348 argv_find(argv, argc, "route-target6", &idx_unused))
9349 rt6 = true;
9350
9351 afi = vpn_policy_getafi(vty, bgp, false);
9352 if (afi == AFI_MAX)
9353 return CMD_WARNING_CONFIG_FAILED;
9354
9355 if (rt6 && afi != AFI_IP6)
9356 return CMD_WARNING_CONFIG_FAILED;
9357
9358 if (yes) {
9359 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9360 vty_out(vty, "%% Missing RTLIST\n");
9361 return CMD_WARNING_CONFIG_FAILED;
9362 }
9363 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9364 if (ret != CMD_SUCCESS)
9365 return ret;
9366 }
9367
9368 if (yes) {
9369 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9370 ecommunity_free(&bgp->vpn_policy[afi]
9371 .import_redirect_rtlist);
9372 bgp->vpn_policy[afi].import_redirect_rtlist =
9373 ecommunity_dup(ecom);
9374 } else {
9375 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9376 ecommunity_free(&bgp->vpn_policy[afi]
9377 .import_redirect_rtlist);
9378 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9379 }
9380
9381 if (ecom)
9382 ecommunity_free(&ecom);
9383
9384 return CMD_SUCCESS;
9385 }
9386
9387 DEFUN_NOSH (address_family_ipv4_safi,
9388 address_family_ipv4_safi_cmd,
9389 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9390 "Enter Address Family command mode\n"
9391 BGP_AF_STR
9392 BGP_SAFI_WITH_LABEL_HELP_STR)
9393 {
9394
9395 if (argc == 3) {
9396 VTY_DECLVAR_CONTEXT(bgp, bgp);
9397 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9398 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9399 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9400 && safi != SAFI_EVPN) {
9401 vty_out(vty,
9402 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9403 return CMD_WARNING_CONFIG_FAILED;
9404 }
9405 vty->node = bgp_node_type(AFI_IP, safi);
9406 } else
9407 vty->node = BGP_IPV4_NODE;
9408
9409 return CMD_SUCCESS;
9410 }
9411
9412 DEFUN_NOSH (address_family_ipv6_safi,
9413 address_family_ipv6_safi_cmd,
9414 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9415 "Enter Address Family command mode\n"
9416 BGP_AF_STR
9417 BGP_SAFI_WITH_LABEL_HELP_STR)
9418 {
9419 if (argc == 3) {
9420 VTY_DECLVAR_CONTEXT(bgp, bgp);
9421 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9422 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9423 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9424 && safi != SAFI_EVPN) {
9425 vty_out(vty,
9426 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9427 return CMD_WARNING_CONFIG_FAILED;
9428 }
9429 vty->node = bgp_node_type(AFI_IP6, safi);
9430 } else
9431 vty->node = BGP_IPV6_NODE;
9432
9433 return CMD_SUCCESS;
9434 }
9435
9436 #ifdef KEEP_OLD_VPN_COMMANDS
9437 DEFUN_NOSH (address_family_vpnv4,
9438 address_family_vpnv4_cmd,
9439 "address-family vpnv4 [unicast]",
9440 "Enter Address Family command mode\n"
9441 BGP_AF_STR
9442 BGP_AF_MODIFIER_STR)
9443 {
9444 vty->node = BGP_VPNV4_NODE;
9445 return CMD_SUCCESS;
9446 }
9447
9448 DEFUN_NOSH (address_family_vpnv6,
9449 address_family_vpnv6_cmd,
9450 "address-family vpnv6 [unicast]",
9451 "Enter Address Family command mode\n"
9452 BGP_AF_STR
9453 BGP_AF_MODIFIER_STR)
9454 {
9455 vty->node = BGP_VPNV6_NODE;
9456 return CMD_SUCCESS;
9457 }
9458 #endif /* KEEP_OLD_VPN_COMMANDS */
9459
9460 DEFUN_NOSH (address_family_evpn,
9461 address_family_evpn_cmd,
9462 "address-family l2vpn evpn",
9463 "Enter Address Family command mode\n"
9464 BGP_AF_STR
9465 BGP_AF_MODIFIER_STR)
9466 {
9467 VTY_DECLVAR_CONTEXT(bgp, bgp);
9468 vty->node = BGP_EVPN_NODE;
9469 return CMD_SUCCESS;
9470 }
9471
9472 DEFUN_NOSH (bgp_segment_routing_srv6,
9473 bgp_segment_routing_srv6_cmd,
9474 "segment-routing srv6",
9475 "Segment-Routing configuration\n"
9476 "Segment-Routing SRv6 configuration\n")
9477 {
9478 VTY_DECLVAR_CONTEXT(bgp, bgp);
9479 bgp->srv6_enabled = true;
9480 vty->node = BGP_SRV6_NODE;
9481 return CMD_SUCCESS;
9482 }
9483
9484 DEFUN (no_bgp_segment_routing_srv6,
9485 no_bgp_segment_routing_srv6_cmd,
9486 "no segment-routing srv6",
9487 NO_STR
9488 "Segment-Routing configuration\n"
9489 "Segment-Routing SRv6 configuration\n")
9490 {
9491 VTY_DECLVAR_CONTEXT(bgp, bgp);
9492
9493 if (strlen(bgp->srv6_locator_name) > 0)
9494 if (bgp_srv6_locator_unset(bgp) < 0)
9495 return CMD_WARNING_CONFIG_FAILED;
9496
9497 bgp->srv6_enabled = false;
9498 return CMD_SUCCESS;
9499 }
9500
9501 DEFPY (bgp_srv6_locator,
9502 bgp_srv6_locator_cmd,
9503 "locator NAME$name",
9504 "Specify SRv6 locator\n"
9505 "Specify SRv6 locator\n")
9506 {
9507 VTY_DECLVAR_CONTEXT(bgp, bgp);
9508 int ret;
9509
9510 if (strlen(bgp->srv6_locator_name) > 0
9511 && strcmp(name, bgp->srv6_locator_name) != 0) {
9512 vty_out(vty, "srv6 locator is already configured\n");
9513 return CMD_WARNING_CONFIG_FAILED;
9514 }
9515
9516 snprintf(bgp->srv6_locator_name,
9517 sizeof(bgp->srv6_locator_name), "%s", name);
9518
9519 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9520 if (ret < 0)
9521 return CMD_WARNING_CONFIG_FAILED;
9522
9523 return CMD_SUCCESS;
9524 }
9525
9526 DEFPY (no_bgp_srv6_locator,
9527 no_bgp_srv6_locator_cmd,
9528 "no locator NAME$name",
9529 NO_STR
9530 "Specify SRv6 locator\n"
9531 "Specify SRv6 locator\n")
9532 {
9533 VTY_DECLVAR_CONTEXT(bgp, bgp);
9534
9535 /* when locator isn't configured, do nothing */
9536 if (strlen(bgp->srv6_locator_name) < 1)
9537 return CMD_SUCCESS;
9538
9539 /* name validation */
9540 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9541 vty_out(vty, "%% No srv6 locator is configured\n");
9542 return CMD_WARNING_CONFIG_FAILED;
9543 }
9544
9545 /* unset locator */
9546 if (bgp_srv6_locator_unset(bgp) < 0)
9547 return CMD_WARNING_CONFIG_FAILED;
9548
9549 return CMD_SUCCESS;
9550 }
9551
9552 DEFPY (show_bgp_srv6,
9553 show_bgp_srv6_cmd,
9554 "show bgp segment-routing srv6",
9555 SHOW_STR
9556 BGP_STR
9557 "BGP Segment Routing\n"
9558 "BGP Segment Routing SRv6\n")
9559 {
9560 struct bgp *bgp;
9561 struct listnode *node;
9562 struct srv6_locator_chunk *chunk;
9563 struct bgp_srv6_function *func;
9564 struct in6_addr *tovpn4_sid;
9565 struct in6_addr *tovpn6_sid;
9566 char buf[256];
9567 char buf_tovpn4_sid[256];
9568 char buf_tovpn6_sid[256];
9569
9570 bgp = bgp_get_default();
9571 if (!bgp)
9572 return CMD_SUCCESS;
9573
9574 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9575 vty_out(vty, "locator_chunks:\n");
9576 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9577 prefix2str(&chunk->prefix, buf, sizeof(buf));
9578 vty_out(vty, "- %s\n", buf);
9579 }
9580
9581 vty_out(vty, "functions:\n");
9582 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9583 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9584 vty_out(vty, "- sid: %s\n", buf);
9585 vty_out(vty, " locator: %s\n", func->locator_name);
9586 }
9587
9588 vty_out(vty, "bgps:\n");
9589 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9590 vty_out(vty, "- name: %s\n",
9591 bgp->name ? bgp->name : "default");
9592
9593 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9594 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9595 if (tovpn4_sid)
9596 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9597 sizeof(buf_tovpn4_sid));
9598 if (tovpn6_sid)
9599 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9600 sizeof(buf_tovpn6_sid));
9601
9602 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9603 tovpn4_sid ? buf_tovpn4_sid : "none");
9604 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9605 tovpn6_sid ? buf_tovpn6_sid : "none");
9606 }
9607
9608 return CMD_SUCCESS;
9609 }
9610
9611 DEFUN_NOSH (exit_address_family,
9612 exit_address_family_cmd,
9613 "exit-address-family",
9614 "Exit from Address Family configuration mode\n")
9615 {
9616 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9617 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9618 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9619 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9620 || vty->node == BGP_EVPN_NODE
9621 || vty->node == BGP_FLOWSPECV4_NODE
9622 || vty->node == BGP_FLOWSPECV6_NODE)
9623 vty->node = BGP_NODE;
9624 return CMD_SUCCESS;
9625 }
9626
9627 /* Recalculate bestpath and re-advertise a prefix */
9628 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9629 const char *ip_str, afi_t afi, safi_t safi,
9630 struct prefix_rd *prd)
9631 {
9632 int ret;
9633 struct prefix match;
9634 struct bgp_dest *dest;
9635 struct bgp_dest *rm;
9636 struct bgp *bgp;
9637 struct bgp_table *table;
9638 struct bgp_table *rib;
9639
9640 /* BGP structure lookup. */
9641 if (view_name) {
9642 bgp = bgp_lookup_by_name(view_name);
9643 if (bgp == NULL) {
9644 vty_out(vty, "%% Can't find BGP instance %s\n",
9645 view_name);
9646 return CMD_WARNING;
9647 }
9648 } else {
9649 bgp = bgp_get_default();
9650 if (bgp == NULL) {
9651 vty_out(vty, "%% No BGP process is configured\n");
9652 return CMD_WARNING;
9653 }
9654 }
9655
9656 /* Check IP address argument. */
9657 ret = str2prefix(ip_str, &match);
9658 if (!ret) {
9659 vty_out(vty, "%% address is malformed\n");
9660 return CMD_WARNING;
9661 }
9662
9663 match.family = afi2family(afi);
9664 rib = bgp->rib[afi][safi];
9665
9666 if (safi == SAFI_MPLS_VPN) {
9667 for (dest = bgp_table_top(rib); dest;
9668 dest = bgp_route_next(dest)) {
9669 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9670
9671 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9672 continue;
9673
9674 table = bgp_dest_get_bgp_table_info(dest);
9675 if (table == NULL)
9676 continue;
9677
9678 rm = bgp_node_match(table, &match);
9679 if (rm != NULL) {
9680 const struct prefix *rm_p =
9681 bgp_dest_get_prefix(rm);
9682
9683 if (rm_p->prefixlen == match.prefixlen) {
9684 SET_FLAG(rm->flags,
9685 BGP_NODE_USER_CLEAR);
9686 bgp_process(bgp, rm, afi, safi);
9687 }
9688 bgp_dest_unlock_node(rm);
9689 }
9690 }
9691 } else {
9692 dest = bgp_node_match(rib, &match);
9693 if (dest != NULL) {
9694 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9695
9696 if (dest_p->prefixlen == match.prefixlen) {
9697 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9698 bgp_process(bgp, dest, afi, safi);
9699 }
9700 bgp_dest_unlock_node(dest);
9701 }
9702 }
9703
9704 return CMD_SUCCESS;
9705 }
9706
9707 /* one clear bgp command to rule them all */
9708 DEFUN (clear_ip_bgp_all,
9709 clear_ip_bgp_all_cmd,
9710 "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>]",
9711 CLEAR_STR
9712 IP_STR
9713 BGP_STR
9714 BGP_INSTANCE_HELP_STR
9715 BGP_AFI_HELP_STR
9716 BGP_AF_STR
9717 BGP_SAFI_WITH_LABEL_HELP_STR
9718 BGP_AF_MODIFIER_STR
9719 "Clear all peers\n"
9720 "BGP IPv4 neighbor to clear\n"
9721 "BGP IPv6 neighbor to clear\n"
9722 "BGP neighbor on interface to clear\n"
9723 "Clear peers with the AS number\n"
9724 "Clear all external peers\n"
9725 "Clear all members of peer-group\n"
9726 "BGP peer-group name\n"
9727 BGP_SOFT_STR
9728 BGP_SOFT_IN_STR
9729 BGP_SOFT_OUT_STR
9730 BGP_SOFT_IN_STR
9731 "Push out prefix-list ORF and do inbound soft reconfig\n"
9732 BGP_SOFT_OUT_STR
9733 "Reset message statistics\n")
9734 {
9735 char *vrf = NULL;
9736
9737 afi_t afi = AFI_UNSPEC;
9738 safi_t safi = SAFI_UNSPEC;
9739 enum clear_sort clr_sort = clear_peer;
9740 enum bgp_clear_type clr_type;
9741 char *clr_arg = NULL;
9742
9743 int idx = 0;
9744
9745 /* clear [ip] bgp */
9746 if (argv_find(argv, argc, "ip", &idx))
9747 afi = AFI_IP;
9748
9749 /* [<vrf> VIEWVRFNAME] */
9750 if (argv_find(argv, argc, "vrf", &idx)) {
9751 vrf = argv[idx + 1]->arg;
9752 idx += 2;
9753 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9754 vrf = NULL;
9755 } else if (argv_find(argv, argc, "view", &idx)) {
9756 /* [<view> VIEWVRFNAME] */
9757 vrf = argv[idx + 1]->arg;
9758 idx += 2;
9759 }
9760 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9761 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9762 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9763
9764 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9765 if (argv_find(argv, argc, "*", &idx)) {
9766 clr_sort = clear_all;
9767 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9768 clr_sort = clear_peer;
9769 clr_arg = argv[idx]->arg;
9770 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9771 clr_sort = clear_peer;
9772 clr_arg = argv[idx]->arg;
9773 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9774 clr_sort = clear_group;
9775 idx++;
9776 clr_arg = argv[idx]->arg;
9777 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9778 clr_sort = clear_peer;
9779 clr_arg = argv[idx]->arg;
9780 } else if (argv_find(argv, argc, "WORD", &idx)) {
9781 clr_sort = clear_peer;
9782 clr_arg = argv[idx]->arg;
9783 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9784 clr_sort = clear_as;
9785 clr_arg = argv[idx]->arg;
9786 } else if (argv_find(argv, argc, "external", &idx)) {
9787 clr_sort = clear_external;
9788 }
9789
9790 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9791 if (argv_find(argv, argc, "soft", &idx)) {
9792 if (argv_find(argv, argc, "in", &idx)
9793 || argv_find(argv, argc, "out", &idx))
9794 clr_type = strmatch(argv[idx]->text, "in")
9795 ? BGP_CLEAR_SOFT_IN
9796 : BGP_CLEAR_SOFT_OUT;
9797 else
9798 clr_type = BGP_CLEAR_SOFT_BOTH;
9799 } else if (argv_find(argv, argc, "in", &idx)) {
9800 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9801 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9802 : BGP_CLEAR_SOFT_IN;
9803 } else if (argv_find(argv, argc, "out", &idx)) {
9804 clr_type = BGP_CLEAR_SOFT_OUT;
9805 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9806 clr_type = BGP_CLEAR_MESSAGE_STATS;
9807 } else
9808 clr_type = BGP_CLEAR_SOFT_NONE;
9809
9810 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9811 }
9812
9813 DEFUN (clear_ip_bgp_prefix,
9814 clear_ip_bgp_prefix_cmd,
9815 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9816 CLEAR_STR
9817 IP_STR
9818 BGP_STR
9819 BGP_INSTANCE_HELP_STR
9820 "Clear bestpath and re-advertise\n"
9821 "IPv4 prefix\n")
9822 {
9823 char *vrf = NULL;
9824 char *prefix = NULL;
9825
9826 int idx = 0;
9827
9828 /* [<view|vrf> VIEWVRFNAME] */
9829 if (argv_find(argv, argc, "vrf", &idx)) {
9830 vrf = argv[idx + 1]->arg;
9831 idx += 2;
9832 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9833 vrf = NULL;
9834 } else if (argv_find(argv, argc, "view", &idx)) {
9835 /* [<view> VIEWVRFNAME] */
9836 vrf = argv[idx + 1]->arg;
9837 idx += 2;
9838 }
9839
9840 prefix = argv[argc - 1]->arg;
9841
9842 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9843 }
9844
9845 DEFUN (clear_bgp_ipv6_safi_prefix,
9846 clear_bgp_ipv6_safi_prefix_cmd,
9847 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9848 CLEAR_STR
9849 IP_STR
9850 BGP_STR
9851 BGP_AF_STR
9852 BGP_SAFI_HELP_STR
9853 "Clear bestpath and re-advertise\n"
9854 "IPv6 prefix\n")
9855 {
9856 int idx_safi = 0;
9857 int idx_ipv6_prefix = 0;
9858 safi_t safi = SAFI_UNICAST;
9859 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9860 argv[idx_ipv6_prefix]->arg : NULL;
9861
9862 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9863 return bgp_clear_prefix(
9864 vty, NULL, prefix, AFI_IP6,
9865 safi, NULL);
9866 }
9867
9868 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9869 clear_bgp_instance_ipv6_safi_prefix_cmd,
9870 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9871 CLEAR_STR
9872 IP_STR
9873 BGP_STR
9874 BGP_INSTANCE_HELP_STR
9875 BGP_AF_STR
9876 BGP_SAFI_HELP_STR
9877 "Clear bestpath and re-advertise\n"
9878 "IPv6 prefix\n")
9879 {
9880 int idx_safi = 0;
9881 int idx_vrfview = 0;
9882 int idx_ipv6_prefix = 0;
9883 safi_t safi = SAFI_UNICAST;
9884 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9885 argv[idx_ipv6_prefix]->arg : NULL;
9886 char *vrfview = NULL;
9887
9888 /* [<view|vrf> VIEWVRFNAME] */
9889 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9890 vrfview = argv[idx_vrfview + 1]->arg;
9891 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9892 vrfview = NULL;
9893 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9894 /* [<view> VIEWVRFNAME] */
9895 vrfview = argv[idx_vrfview + 1]->arg;
9896 }
9897 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9898
9899 return bgp_clear_prefix(
9900 vty, vrfview, prefix,
9901 AFI_IP6, safi, NULL);
9902 }
9903
9904 DEFUN (show_bgp_views,
9905 show_bgp_views_cmd,
9906 "show [ip] bgp views",
9907 SHOW_STR
9908 IP_STR
9909 BGP_STR
9910 "Show the defined BGP views\n")
9911 {
9912 struct list *inst = bm->bgp;
9913 struct listnode *node;
9914 struct bgp *bgp;
9915
9916 vty_out(vty, "Defined BGP views:\n");
9917 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9918 /* Skip VRFs. */
9919 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9920 continue;
9921 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9922 bgp->as);
9923 }
9924
9925 return CMD_SUCCESS;
9926 }
9927
9928 DEFUN (show_bgp_vrfs,
9929 show_bgp_vrfs_cmd,
9930 "show [ip] bgp vrfs [json]",
9931 SHOW_STR
9932 IP_STR
9933 BGP_STR
9934 "Show BGP VRFs\n"
9935 JSON_STR)
9936 {
9937 char buf[ETHER_ADDR_STRLEN];
9938 struct list *inst = bm->bgp;
9939 struct listnode *node;
9940 struct bgp *bgp;
9941 bool uj = use_json(argc, argv);
9942 json_object *json = NULL;
9943 json_object *json_vrfs = NULL;
9944 int count = 0;
9945
9946 if (uj) {
9947 json = json_object_new_object();
9948 json_vrfs = json_object_new_object();
9949 }
9950
9951 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9952 const char *name, *type;
9953 struct peer *peer;
9954 struct listnode *node2, *nnode2;
9955 int peers_cfg, peers_estb;
9956 json_object *json_vrf = NULL;
9957
9958 /* Skip Views. */
9959 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9960 continue;
9961
9962 count++;
9963 if (!uj && count == 1) {
9964 vty_out(vty,
9965 "%4s %-5s %-16s %9s %10s %-37s\n",
9966 "Type", "Id", "routerId", "#PeersCfg",
9967 "#PeersEstb", "Name");
9968 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9969 "L3-VNI", "RouterMAC", "Interface");
9970 }
9971
9972 peers_cfg = peers_estb = 0;
9973 if (uj)
9974 json_vrf = json_object_new_object();
9975
9976
9977 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9978 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9979 continue;
9980 peers_cfg++;
9981 if (peer_established(peer))
9982 peers_estb++;
9983 }
9984
9985 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9986 name = VRF_DEFAULT_NAME;
9987 type = "DFLT";
9988 } else {
9989 name = bgp->name;
9990 type = "VRF";
9991 }
9992
9993
9994 if (uj) {
9995 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9996 ? -1
9997 : (int64_t)bgp->vrf_id;
9998 char buf[BUFSIZ] = {0};
9999
10000 json_object_string_add(json_vrf, "type", type);
10001 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10002 json_object_string_addf(json_vrf, "routerId", "%pI4",
10003 &bgp->router_id);
10004 json_object_int_add(json_vrf, "numConfiguredPeers",
10005 peers_cfg);
10006 json_object_int_add(json_vrf, "numEstablishedPeers",
10007 peers_estb);
10008
10009 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10010 json_object_string_add(
10011 json_vrf, "rmac",
10012 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10013 json_object_string_add(json_vrf, "interface",
10014 ifindex2ifname(bgp->l3vni_svi_ifindex,
10015 bgp->vrf_id));
10016 json_object_object_add(json_vrfs, name, json_vrf);
10017 } else {
10018 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10019 type,
10020 bgp->vrf_id == VRF_UNKNOWN ? -1
10021 : (int)bgp->vrf_id,
10022 &bgp->router_id, peers_cfg, peers_estb, name);
10023 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10024 bgp->l3vni,
10025 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10026 ifindex2ifname(bgp->l3vni_svi_ifindex,
10027 bgp->vrf_id));
10028 }
10029 }
10030
10031 if (uj) {
10032 json_object_object_add(json, "vrfs", json_vrfs);
10033
10034 json_object_int_add(json, "totalVrfs", count);
10035
10036 vty_json(vty, json);
10037 } else {
10038 if (count)
10039 vty_out(vty,
10040 "\nTotal number of VRFs (including default): %d\n",
10041 count);
10042 }
10043
10044 return CMD_SUCCESS;
10045 }
10046
10047 DEFUN (show_bgp_mac_hash,
10048 show_bgp_mac_hash_cmd,
10049 "show bgp mac hash",
10050 SHOW_STR
10051 BGP_STR
10052 "Mac Address\n"
10053 "Mac Address database\n")
10054 {
10055 bgp_mac_dump_table(vty);
10056
10057 return CMD_SUCCESS;
10058 }
10059
10060 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10061 {
10062 struct vty *vty = (struct vty *)args;
10063 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10064
10065 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10066 }
10067
10068 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10069 {
10070 vty_out(vty, "self nexthop database:\n");
10071 bgp_nexthop_show_address_hash(vty, bgp);
10072
10073 vty_out(vty, "Tunnel-ip database:\n");
10074 hash_iterate(bgp->tip_hash,
10075 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10076 vty);
10077 }
10078
10079 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10080 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10081 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10082 "martian next-hops\n"
10083 "martian next-hop database\n")
10084 {
10085 struct bgp *bgp = NULL;
10086 int idx = 0;
10087 char *name = NULL;
10088
10089 /* [<vrf> VIEWVRFNAME] */
10090 if (argv_find(argv, argc, "vrf", &idx)) {
10091 name = argv[idx + 1]->arg;
10092 if (name && strmatch(name, VRF_DEFAULT_NAME))
10093 name = NULL;
10094 } else if (argv_find(argv, argc, "view", &idx))
10095 /* [<view> VIEWVRFNAME] */
10096 name = argv[idx + 1]->arg;
10097 if (name)
10098 bgp = bgp_lookup_by_name(name);
10099 else
10100 bgp = bgp_get_default();
10101
10102 if (!bgp) {
10103 vty_out(vty, "%% No BGP process is configured\n");
10104 return CMD_WARNING;
10105 }
10106 bgp_show_martian_nexthops(vty, bgp);
10107
10108 return CMD_SUCCESS;
10109 }
10110
10111 DEFUN (show_bgp_memory,
10112 show_bgp_memory_cmd,
10113 "show [ip] bgp memory",
10114 SHOW_STR
10115 IP_STR
10116 BGP_STR
10117 "Global BGP memory statistics\n")
10118 {
10119 char memstrbuf[MTYPE_MEMSTR_LEN];
10120 unsigned long count;
10121
10122 /* RIB related usage stats */
10123 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10124 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10125 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10126 count * sizeof(struct bgp_dest)));
10127
10128 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10129 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10130 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10131 count * sizeof(struct bgp_path_info)));
10132 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10133 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10134 count,
10135 mtype_memstr(
10136 memstrbuf, sizeof(memstrbuf),
10137 count * sizeof(struct bgp_path_info_extra)));
10138
10139 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10140 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10141 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10142 count * sizeof(struct bgp_static)));
10143
10144 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10145 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10146 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10147 count * sizeof(struct bpacket)));
10148
10149 /* Adj-In/Out */
10150 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10151 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10152 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10153 count * sizeof(struct bgp_adj_in)));
10154 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10155 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10156 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10157 count * sizeof(struct bgp_adj_out)));
10158
10159 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10160 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10161 count,
10162 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10163 count * sizeof(struct bgp_nexthop_cache)));
10164
10165 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10166 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10167 count,
10168 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10169 count * sizeof(struct bgp_damp_info)));
10170
10171 /* Attributes */
10172 count = attr_count();
10173 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10174 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10175 count * sizeof(struct attr)));
10176
10177 if ((count = attr_unknown_count()))
10178 vty_out(vty, "%ld unknown attributes\n", count);
10179
10180 /* AS_PATH attributes */
10181 count = aspath_count();
10182 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10183 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10184 count * sizeof(struct aspath)));
10185
10186 count = mtype_stats_alloc(MTYPE_AS_SEG);
10187 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10188 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10189 count * sizeof(struct assegment)));
10190
10191 /* Other attributes */
10192 if ((count = community_count()))
10193 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10194 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10195 count * sizeof(struct community)));
10196 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10197 vty_out(vty,
10198 "%ld BGP ext-community entries, using %s of memory\n",
10199 count,
10200 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10201 count * sizeof(struct ecommunity)));
10202 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10203 vty_out(vty,
10204 "%ld BGP large-community entries, using %s of memory\n",
10205 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10206 count * sizeof(struct lcommunity)));
10207
10208 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10209 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10210 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10211 count * sizeof(struct cluster_list)));
10212
10213 /* Peer related usage */
10214 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10215 vty_out(vty, "%ld peers, using %s of memory\n", count,
10216 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10217 count * sizeof(struct peer)));
10218
10219 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10220 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10221 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10222 count * sizeof(struct peer_group)));
10223
10224 /* Other */
10225 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10226 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10227 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10228 count * sizeof(regex_t)));
10229 return CMD_SUCCESS;
10230 }
10231
10232 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10233 {
10234 json_object *bestpath = json_object_new_object();
10235
10236 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10237 json_object_string_add(bestpath, "asPath", "ignore");
10238
10239 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10240 json_object_string_add(bestpath, "asPath", "confed");
10241
10242 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10243 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10244 json_object_string_add(bestpath, "multiPathRelax",
10245 "as-set");
10246 else
10247 json_object_string_add(bestpath, "multiPathRelax",
10248 "true");
10249 } else
10250 json_object_string_add(bestpath, "multiPathRelax", "false");
10251
10252 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10253 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10254
10255 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10256 json_object_string_add(bestpath, "compareRouterId", "true");
10257 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10258 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10259 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10260 json_object_string_add(bestpath, "med", "confed");
10261 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10262 json_object_string_add(bestpath, "med",
10263 "missing-as-worst");
10264 else
10265 json_object_string_add(bestpath, "med", "true");
10266 }
10267
10268 json_object_object_add(json, "bestPath", bestpath);
10269 }
10270
10271 /* Print the error code/subcode for why the peer is down */
10272 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10273 json_object *json_peer, bool use_json)
10274 {
10275 const char *code_str;
10276 const char *subcode_str;
10277
10278 if (use_json) {
10279 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10280 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10281 char errorcodesubcode_hexstr[5];
10282 char errorcodesubcode_str[256];
10283
10284 code_str = bgp_notify_code_str(peer->notify.code);
10285 subcode_str = bgp_notify_subcode_str(
10286 peer->notify.code,
10287 peer->notify.subcode);
10288
10289 snprintf(errorcodesubcode_hexstr,
10290 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10291 peer->notify.code, peer->notify.subcode);
10292 json_object_string_add(json_peer,
10293 "lastErrorCodeSubcode",
10294 errorcodesubcode_hexstr);
10295 snprintf(errorcodesubcode_str, 255, "%s%s",
10296 code_str, subcode_str);
10297 json_object_string_add(json_peer,
10298 "lastNotificationReason",
10299 errorcodesubcode_str);
10300 json_object_boolean_add(json_peer,
10301 "lastNotificationHardReset",
10302 peer->notify.hard_reset);
10303 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10304 && peer->notify.code == BGP_NOTIFY_CEASE
10305 && (peer->notify.subcode
10306 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10307 || peer->notify.subcode
10308 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10309 && peer->notify.length) {
10310 char msgbuf[1024];
10311 const char *msg_str;
10312
10313 msg_str = bgp_notify_admin_message(
10314 msgbuf, sizeof(msgbuf),
10315 (uint8_t *)peer->notify.data,
10316 peer->notify.length);
10317 if (msg_str)
10318 json_object_string_add(
10319 json_peer,
10320 "lastShutdownDescription",
10321 msg_str);
10322 }
10323
10324 }
10325 json_object_string_add(json_peer, "lastResetDueTo",
10326 peer_down_str[(int)peer->last_reset]);
10327 json_object_int_add(json_peer, "lastResetCode",
10328 peer->last_reset);
10329 } else {
10330 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10331 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10332 code_str = bgp_notify_code_str(peer->notify.code);
10333 subcode_str =
10334 bgp_notify_subcode_str(peer->notify.code,
10335 peer->notify.subcode);
10336 vty_out(vty, " Notification %s (%s%s%s)\n",
10337 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10338 ? "sent"
10339 : "received",
10340 code_str, subcode_str,
10341 peer->notify.hard_reset
10342 ? bgp_notify_subcode_str(
10343 BGP_NOTIFY_CEASE,
10344 BGP_NOTIFY_CEASE_HARD_RESET)
10345 : "");
10346 } else {
10347 vty_out(vty, " %s\n",
10348 peer_down_str[(int)peer->last_reset]);
10349 }
10350 }
10351 }
10352
10353 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10354 safi_t safi)
10355 {
10356 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10357 }
10358
10359 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10360 struct peer *peer, json_object *json_peer,
10361 int max_neighbor_width, bool use_json)
10362 {
10363 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10364 int len;
10365
10366 if (use_json) {
10367 if (peer_dynamic_neighbor(peer))
10368 json_object_boolean_true_add(json_peer,
10369 "dynamicPeer");
10370 if (peer->hostname)
10371 json_object_string_add(json_peer, "hostname",
10372 peer->hostname);
10373
10374 if (peer->domainname)
10375 json_object_string_add(json_peer, "domainname",
10376 peer->domainname);
10377 json_object_int_add(json_peer, "connectionsEstablished",
10378 peer->established);
10379 json_object_int_add(json_peer, "connectionsDropped",
10380 peer->dropped);
10381 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10382 use_json, json_peer);
10383 if (peer_established(peer))
10384 json_object_string_add(json_peer, "lastResetDueTo",
10385 "AFI/SAFI Not Negotiated");
10386 else
10387 bgp_show_peer_reset(NULL, peer, json_peer, true);
10388 } else {
10389 dn_flag[1] = '\0';
10390 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10391 if (peer->hostname
10392 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10393 len = vty_out(vty, "%s%s(%s)", dn_flag,
10394 peer->hostname, peer->host);
10395 else
10396 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10397
10398 /* pad the neighbor column with spaces */
10399 if (len < max_neighbor_width)
10400 vty_out(vty, "%*s", max_neighbor_width - len,
10401 " ");
10402 vty_out(vty, "%7d %7d %9s", peer->established,
10403 peer->dropped,
10404 peer_uptime(peer->uptime, timebuf,
10405 BGP_UPTIME_LEN, 0, NULL));
10406 if (peer_established(peer))
10407 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10408 else
10409 bgp_show_peer_reset(vty, peer, NULL,
10410 false);
10411 }
10412 }
10413
10414 /* Strip peer's description to the given size. */
10415 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10416 {
10417 static char stripped[BUFSIZ];
10418 uint32_t i = 0;
10419 uint32_t last_space = 0;
10420
10421 while (i < size) {
10422 if (*(desc + i) == 0) {
10423 stripped[i] = '\0';
10424 return stripped;
10425 }
10426 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10427 last_space = i;
10428 stripped[i] = *(desc + i);
10429 i++;
10430 }
10431
10432 if (last_space > size)
10433 stripped[size + 1] = '\0';
10434 else
10435 stripped[last_space] = '\0';
10436
10437 return stripped;
10438 }
10439
10440 /* Determine whether var peer should be filtered out of the summary. */
10441 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10442 struct peer *fpeer, int as_type,
10443 as_t as)
10444 {
10445
10446 /* filter neighbor XXXX */
10447 if (fpeer && fpeer != peer)
10448 return true;
10449
10450 /* filter remote-as (internal|external) */
10451 if (as_type != AS_UNSPECIFIED) {
10452 if (peer->as_type == AS_SPECIFIED) {
10453 if (as_type == AS_INTERNAL) {
10454 if (peer->as != peer->local_as)
10455 return true;
10456 } else if (peer->as == peer->local_as)
10457 return true;
10458 } else if (as_type != peer->as_type)
10459 return true;
10460 } else if (as && as != peer->as) /* filter remote-as XXX */
10461 return true;
10462
10463 return false;
10464 }
10465
10466 /* Show BGP peer's summary information.
10467 *
10468 * Peer's description is stripped according to if `wide` option is given
10469 * or not.
10470 *
10471 * When adding new columns to `show bgp summary` output, please make
10472 * sure `Desc` is the lastest column to show because it can contain
10473 * whitespaces and the whole output will be tricky.
10474 */
10475 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10476 struct peer *fpeer, int as_type, as_t as,
10477 uint16_t show_flags)
10478 {
10479 struct peer *peer;
10480 struct listnode *node, *nnode;
10481 unsigned int count = 0, dn_count = 0;
10482 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10483 char neighbor_buf[VTY_BUFSIZ];
10484 int neighbor_col_default_width = 16;
10485 int len, failed_count = 0;
10486 unsigned int filtered_count = 0;
10487 int max_neighbor_width = 0;
10488 int pfx_rcd_safi;
10489 json_object *json = NULL;
10490 json_object *json_peer = NULL;
10491 json_object *json_peers = NULL;
10492 struct peer_af *paf;
10493 struct bgp_filter *filter;
10494 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10495 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10496 bool show_established =
10497 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10498 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10499 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10500
10501 /* labeled-unicast routes are installed in the unicast table so in order
10502 * to
10503 * display the correct PfxRcd value we must look at SAFI_UNICAST
10504 */
10505
10506 if (safi == SAFI_LABELED_UNICAST)
10507 pfx_rcd_safi = SAFI_UNICAST;
10508 else
10509 pfx_rcd_safi = safi;
10510
10511 if (use_json) {
10512 json = json_object_new_object();
10513 json_peers = json_object_new_object();
10514 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10515 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10516 as_type, as)) {
10517 filtered_count++;
10518 count++;
10519 continue;
10520 }
10521
10522 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10523 continue;
10524
10525 if (peer->afc[afi][safi]) {
10526 /* See if we have at least a single failed peer */
10527 if (bgp_has_peer_failed(peer, afi, safi))
10528 failed_count++;
10529 count++;
10530 }
10531 if (peer_dynamic_neighbor(peer))
10532 dn_count++;
10533 }
10534
10535 } else {
10536 /* Loop over all neighbors that will be displayed to determine
10537 * how many
10538 * characters are needed for the Neighbor column
10539 */
10540 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10541 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10542 as_type, as)) {
10543 filtered_count++;
10544 count++;
10545 continue;
10546 }
10547
10548 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10549 continue;
10550
10551 if (peer->afc[afi][safi]) {
10552 memset(dn_flag, '\0', sizeof(dn_flag));
10553 if (peer_dynamic_neighbor(peer))
10554 dn_flag[0] = '*';
10555
10556 if (peer->hostname
10557 && CHECK_FLAG(bgp->flags,
10558 BGP_FLAG_SHOW_HOSTNAME))
10559 snprintf(neighbor_buf,
10560 sizeof(neighbor_buf),
10561 "%s%s(%s) ", dn_flag,
10562 peer->hostname, peer->host);
10563 else
10564 snprintf(neighbor_buf,
10565 sizeof(neighbor_buf), "%s%s ",
10566 dn_flag, peer->host);
10567
10568 len = strlen(neighbor_buf);
10569
10570 if (len > max_neighbor_width)
10571 max_neighbor_width = len;
10572
10573 /* See if we have at least a single failed peer */
10574 if (bgp_has_peer_failed(peer, afi, safi))
10575 failed_count++;
10576 count++;
10577 }
10578 }
10579
10580 /* Originally we displayed the Neighbor column as 16
10581 * characters wide so make that the default
10582 */
10583 if (max_neighbor_width < neighbor_col_default_width)
10584 max_neighbor_width = neighbor_col_default_width;
10585 }
10586
10587 if (show_failed && !failed_count) {
10588 if (use_json) {
10589 json_object_int_add(json, "failedPeersCount", 0);
10590 json_object_int_add(json, "dynamicPeers", dn_count);
10591 json_object_int_add(json, "totalPeers", count);
10592
10593 vty_json(vty, json);
10594 } else {
10595 vty_out(vty, "%% No failed BGP neighbors found\n");
10596 }
10597 return CMD_SUCCESS;
10598 }
10599
10600 count = 0; /* Reset the value as its used again */
10601 filtered_count = 0;
10602 dn_count = 0;
10603 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10604 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10605 continue;
10606
10607 if (!peer->afc[afi][safi])
10608 continue;
10609
10610 if (!count) {
10611 unsigned long ents;
10612 char memstrbuf[MTYPE_MEMSTR_LEN];
10613 int64_t vrf_id_ui;
10614
10615 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10616 ? -1
10617 : (int64_t)bgp->vrf_id;
10618
10619 /* Usage summary and header */
10620 if (use_json) {
10621 json_object_string_addf(json, "routerId",
10622 "%pI4",
10623 &bgp->router_id);
10624 json_object_int_add(json, "as", bgp->as);
10625 json_object_int_add(json, "vrfId", vrf_id_ui);
10626 json_object_string_add(
10627 json, "vrfName",
10628 (bgp->inst_type
10629 == BGP_INSTANCE_TYPE_DEFAULT)
10630 ? VRF_DEFAULT_NAME
10631 : bgp->name);
10632 } else {
10633 vty_out(vty,
10634 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10635 &bgp->router_id, bgp->as,
10636 bgp->vrf_id == VRF_UNKNOWN
10637 ? -1
10638 : (int)bgp->vrf_id);
10639 vty_out(vty, "\n");
10640 }
10641
10642 if (bgp_update_delay_configured(bgp)) {
10643 if (use_json) {
10644 json_object_int_add(
10645 json, "updateDelayLimit",
10646 bgp->v_update_delay);
10647
10648 if (bgp->v_update_delay
10649 != bgp->v_establish_wait)
10650 json_object_int_add(
10651 json,
10652 "updateDelayEstablishWait",
10653 bgp->v_establish_wait);
10654
10655 if (bgp_update_delay_active(bgp)) {
10656 json_object_string_add(
10657 json,
10658 "updateDelayFirstNeighbor",
10659 bgp->update_delay_begin_time);
10660 json_object_boolean_true_add(
10661 json,
10662 "updateDelayInProgress");
10663 } else {
10664 if (bgp->update_delay_over) {
10665 json_object_string_add(
10666 json,
10667 "updateDelayFirstNeighbor",
10668 bgp->update_delay_begin_time);
10669 json_object_string_add(
10670 json,
10671 "updateDelayBestpathResumed",
10672 bgp->update_delay_end_time);
10673 json_object_string_add(
10674 json,
10675 "updateDelayZebraUpdateResume",
10676 bgp->update_delay_zebra_resume_time);
10677 json_object_string_add(
10678 json,
10679 "updateDelayPeerUpdateResume",
10680 bgp->update_delay_peers_resume_time);
10681 }
10682 }
10683 } else {
10684 vty_out(vty,
10685 "Read-only mode update-delay limit: %d seconds\n",
10686 bgp->v_update_delay);
10687 if (bgp->v_update_delay
10688 != bgp->v_establish_wait)
10689 vty_out(vty,
10690 " Establish wait: %d seconds\n",
10691 bgp->v_establish_wait);
10692
10693 if (bgp_update_delay_active(bgp)) {
10694 vty_out(vty,
10695 " First neighbor established: %s\n",
10696 bgp->update_delay_begin_time);
10697 vty_out(vty,
10698 " Delay in progress\n");
10699 } else {
10700 if (bgp->update_delay_over) {
10701 vty_out(vty,
10702 " First neighbor established: %s\n",
10703 bgp->update_delay_begin_time);
10704 vty_out(vty,
10705 " Best-paths resumed: %s\n",
10706 bgp->update_delay_end_time);
10707 vty_out(vty,
10708 " zebra update resumed: %s\n",
10709 bgp->update_delay_zebra_resume_time);
10710 vty_out(vty,
10711 " peers update resumed: %s\n",
10712 bgp->update_delay_peers_resume_time);
10713 }
10714 }
10715 }
10716 }
10717
10718 if (use_json) {
10719 if (bgp_maxmed_onstartup_configured(bgp)
10720 && bgp->maxmed_active)
10721 json_object_boolean_true_add(
10722 json, "maxMedOnStartup");
10723 if (bgp->v_maxmed_admin)
10724 json_object_boolean_true_add(
10725 json, "maxMedAdministrative");
10726
10727 json_object_int_add(
10728 json, "tableVersion",
10729 bgp_table_version(bgp->rib[afi][safi]));
10730
10731 ents = bgp_table_count(bgp->rib[afi][safi]);
10732 json_object_int_add(json, "ribCount", ents);
10733 json_object_int_add(
10734 json, "ribMemory",
10735 ents * sizeof(struct bgp_dest));
10736
10737 ents = bgp->af_peer_count[afi][safi];
10738 json_object_int_add(json, "peerCount", ents);
10739 json_object_int_add(json, "peerMemory",
10740 ents * sizeof(struct peer));
10741
10742 if ((ents = listcount(bgp->group))) {
10743 json_object_int_add(
10744 json, "peerGroupCount", ents);
10745 json_object_int_add(
10746 json, "peerGroupMemory",
10747 ents * sizeof(struct
10748 peer_group));
10749 }
10750
10751 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10752 BGP_CONFIG_DAMPENING))
10753 json_object_boolean_true_add(
10754 json, "dampeningEnabled");
10755 } else {
10756 if (!show_terse) {
10757 if (bgp_maxmed_onstartup_configured(bgp)
10758 && bgp->maxmed_active)
10759 vty_out(vty,
10760 "Max-med on-startup active\n");
10761 if (bgp->v_maxmed_admin)
10762 vty_out(vty,
10763 "Max-med administrative active\n");
10764
10765 vty_out(vty,
10766 "BGP table version %" PRIu64
10767 "\n",
10768 bgp_table_version(
10769 bgp->rib[afi][safi]));
10770
10771 ents = bgp_table_count(
10772 bgp->rib[afi][safi]);
10773 vty_out(vty,
10774 "RIB entries %ld, using %s of memory\n",
10775 ents,
10776 mtype_memstr(
10777 memstrbuf,
10778 sizeof(memstrbuf),
10779 ents
10780 * sizeof(
10781 struct
10782 bgp_dest)));
10783
10784 /* Peer related usage */
10785 ents = bgp->af_peer_count[afi][safi];
10786 vty_out(vty,
10787 "Peers %ld, using %s of memory\n",
10788 ents,
10789 mtype_memstr(
10790 memstrbuf,
10791 sizeof(memstrbuf),
10792 ents
10793 * sizeof(
10794 struct
10795 peer)));
10796
10797 if ((ents = listcount(bgp->group)))
10798 vty_out(vty,
10799 "Peer groups %ld, using %s of memory\n",
10800 ents,
10801 mtype_memstr(
10802 memstrbuf,
10803 sizeof(memstrbuf),
10804 ents
10805 * sizeof(
10806 struct
10807 peer_group)));
10808
10809 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10810 BGP_CONFIG_DAMPENING))
10811 vty_out(vty,
10812 "Dampening enabled.\n");
10813 }
10814 if (show_failed) {
10815 vty_out(vty, "\n");
10816
10817 /* Subtract 8 here because 'Neighbor' is
10818 * 8 characters */
10819 vty_out(vty, "Neighbor");
10820 vty_out(vty, "%*s",
10821 max_neighbor_width - 8, " ");
10822 vty_out(vty,
10823 BGP_SHOW_SUMMARY_HEADER_FAILED);
10824 }
10825 }
10826 }
10827
10828 paf = peer_af_find(peer, afi, safi);
10829 filter = &peer->filter[afi][safi];
10830
10831 count++;
10832 /* Works for both failed & successful cases */
10833 if (peer_dynamic_neighbor(peer))
10834 dn_count++;
10835
10836 if (use_json) {
10837 json_peer = NULL;
10838 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10839 as_type, as)) {
10840 filtered_count++;
10841 continue;
10842 }
10843 if (show_failed &&
10844 bgp_has_peer_failed(peer, afi, safi)) {
10845 json_peer = json_object_new_object();
10846 bgp_show_failed_summary(vty, bgp, peer,
10847 json_peer, 0, use_json);
10848 } else if (!show_failed) {
10849 if (show_established
10850 && bgp_has_peer_failed(peer, afi, safi)) {
10851 filtered_count++;
10852 continue;
10853 }
10854
10855 json_peer = json_object_new_object();
10856 if (peer_dynamic_neighbor(peer)) {
10857 json_object_boolean_true_add(json_peer,
10858 "dynamicPeer");
10859 }
10860
10861 if (peer->hostname)
10862 json_object_string_add(json_peer, "hostname",
10863 peer->hostname);
10864
10865 if (peer->domainname)
10866 json_object_string_add(json_peer, "domainname",
10867 peer->domainname);
10868
10869 json_object_int_add(json_peer, "remoteAs", peer->as);
10870 json_object_int_add(
10871 json_peer, "localAs",
10872 peer->change_local_as
10873 ? peer->change_local_as
10874 : peer->local_as);
10875 json_object_int_add(json_peer, "version", 4);
10876 json_object_int_add(json_peer, "msgRcvd",
10877 PEER_TOTAL_RX(peer));
10878 json_object_int_add(json_peer, "msgSent",
10879 PEER_TOTAL_TX(peer));
10880
10881 atomic_size_t outq_count, inq_count;
10882 outq_count = atomic_load_explicit(
10883 &peer->obuf->count,
10884 memory_order_relaxed);
10885 inq_count = atomic_load_explicit(
10886 &peer->ibuf->count,
10887 memory_order_relaxed);
10888
10889 json_object_int_add(json_peer, "tableVersion",
10890 peer->version[afi][safi]);
10891 json_object_int_add(json_peer, "outq",
10892 outq_count);
10893 json_object_int_add(json_peer, "inq",
10894 inq_count);
10895 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10896 use_json, json_peer);
10897
10898 json_object_int_add(json_peer, "pfxRcd",
10899 peer->pcount[afi][pfx_rcd_safi]);
10900
10901 if (paf && PAF_SUBGRP(paf))
10902 json_object_int_add(
10903 json_peer, "pfxSnt",
10904 (PAF_SUBGRP(paf))->scount);
10905 else
10906 json_object_int_add(json_peer, "pfxSnt",
10907 0);
10908
10909 /* BGP FSM state */
10910 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10911 || CHECK_FLAG(peer->bgp->flags,
10912 BGP_FLAG_SHUTDOWN))
10913 json_object_string_add(json_peer,
10914 "state",
10915 "Idle (Admin)");
10916 else if (peer->afc_recv[afi][safi])
10917 json_object_string_add(
10918 json_peer, "state",
10919 lookup_msg(bgp_status_msg,
10920 peer->status, NULL));
10921 else if (CHECK_FLAG(
10922 peer->sflags,
10923 PEER_STATUS_PREFIX_OVERFLOW))
10924 json_object_string_add(json_peer,
10925 "state",
10926 "Idle (PfxCt)");
10927 else
10928 json_object_string_add(
10929 json_peer, "state",
10930 lookup_msg(bgp_status_msg,
10931 peer->status, NULL));
10932
10933 /* BGP peer state */
10934 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10935 || CHECK_FLAG(peer->bgp->flags,
10936 BGP_FLAG_SHUTDOWN))
10937 json_object_string_add(json_peer,
10938 "peerState",
10939 "Admin");
10940 else if (CHECK_FLAG(
10941 peer->sflags,
10942 PEER_STATUS_PREFIX_OVERFLOW))
10943 json_object_string_add(json_peer,
10944 "peerState",
10945 "PfxCt");
10946 else if (CHECK_FLAG(peer->flags,
10947 PEER_FLAG_PASSIVE))
10948 json_object_string_add(json_peer,
10949 "peerState",
10950 "Passive");
10951 else if (CHECK_FLAG(peer->sflags,
10952 PEER_STATUS_NSF_WAIT))
10953 json_object_string_add(json_peer,
10954 "peerState",
10955 "NSF passive");
10956 else if (CHECK_FLAG(
10957 peer->bgp->flags,
10958 BGP_FLAG_EBGP_REQUIRES_POLICY)
10959 && (!bgp_inbound_policy_exists(peer,
10960 filter)
10961 || !bgp_outbound_policy_exists(
10962 peer, filter)))
10963 json_object_string_add(json_peer,
10964 "peerState",
10965 "Policy");
10966 else
10967 json_object_string_add(
10968 json_peer, "peerState", "OK");
10969
10970 json_object_int_add(json_peer, "connectionsEstablished",
10971 peer->established);
10972 json_object_int_add(json_peer, "connectionsDropped",
10973 peer->dropped);
10974 if (peer->desc)
10975 json_object_string_add(
10976 json_peer, "desc", peer->desc);
10977 }
10978 /* Avoid creating empty peer dicts in JSON */
10979 if (json_peer == NULL)
10980 continue;
10981
10982 if (peer->conf_if)
10983 json_object_string_add(json_peer, "idType",
10984 "interface");
10985 else if (peer->su.sa.sa_family == AF_INET)
10986 json_object_string_add(json_peer, "idType",
10987 "ipv4");
10988 else if (peer->su.sa.sa_family == AF_INET6)
10989 json_object_string_add(json_peer, "idType",
10990 "ipv6");
10991 json_object_object_add(json_peers, peer->host,
10992 json_peer);
10993 } else {
10994 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10995 as_type, as)) {
10996 filtered_count++;
10997 continue;
10998 }
10999 if (show_failed &&
11000 bgp_has_peer_failed(peer, afi, safi)) {
11001 bgp_show_failed_summary(vty, bgp, peer, NULL,
11002 max_neighbor_width,
11003 use_json);
11004 } else if (!show_failed) {
11005 if (show_established
11006 && bgp_has_peer_failed(peer, afi, safi)) {
11007 filtered_count++;
11008 continue;
11009 }
11010
11011 if ((count - filtered_count) == 1) {
11012 /* display headline before the first
11013 * neighbor line */
11014 vty_out(vty, "\n");
11015
11016 /* Subtract 8 here because 'Neighbor' is
11017 * 8 characters */
11018 vty_out(vty, "Neighbor");
11019 vty_out(vty, "%*s",
11020 max_neighbor_width - 8, " ");
11021 vty_out(vty,
11022 show_wide
11023 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11024 : BGP_SHOW_SUMMARY_HEADER_ALL);
11025 }
11026
11027 memset(dn_flag, '\0', sizeof(dn_flag));
11028 if (peer_dynamic_neighbor(peer)) {
11029 dn_flag[0] = '*';
11030 }
11031
11032 if (peer->hostname
11033 && CHECK_FLAG(bgp->flags,
11034 BGP_FLAG_SHOW_HOSTNAME))
11035 len = vty_out(vty, "%s%s(%s)", dn_flag,
11036 peer->hostname,
11037 peer->host);
11038 else
11039 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11040
11041 /* pad the neighbor column with spaces */
11042 if (len < max_neighbor_width)
11043 vty_out(vty, "%*s", max_neighbor_width - len,
11044 " ");
11045
11046 atomic_size_t outq_count, inq_count;
11047 outq_count = atomic_load_explicit(
11048 &peer->obuf->count,
11049 memory_order_relaxed);
11050 inq_count = atomic_load_explicit(
11051 &peer->ibuf->count,
11052 memory_order_relaxed);
11053
11054 if (show_wide)
11055 vty_out(vty,
11056 "4 %10u %10u %9u %9u %8" PRIu64
11057 " %4zu %4zu %8s",
11058 peer->as,
11059 peer->change_local_as
11060 ? peer->change_local_as
11061 : peer->local_as,
11062 PEER_TOTAL_RX(peer),
11063 PEER_TOTAL_TX(peer),
11064 peer->version[afi][safi],
11065 inq_count, outq_count,
11066 peer_uptime(peer->uptime,
11067 timebuf,
11068 BGP_UPTIME_LEN, 0,
11069 NULL));
11070 else
11071 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11072 " %4zu %4zu %8s",
11073 peer->as, PEER_TOTAL_RX(peer),
11074 PEER_TOTAL_TX(peer),
11075 peer->version[afi][safi],
11076 inq_count, outq_count,
11077 peer_uptime(peer->uptime,
11078 timebuf,
11079 BGP_UPTIME_LEN, 0,
11080 NULL));
11081
11082 if (peer_established(peer)) {
11083 if (peer->afc_recv[afi][safi]) {
11084 if (CHECK_FLAG(
11085 bgp->flags,
11086 BGP_FLAG_EBGP_REQUIRES_POLICY)
11087 && !bgp_inbound_policy_exists(
11088 peer, filter))
11089 vty_out(vty, " %12s",
11090 "(Policy)");
11091 else
11092 vty_out(vty,
11093 " %12u",
11094 peer->pcount
11095 [afi]
11096 [pfx_rcd_safi]);
11097 } else {
11098 vty_out(vty, " NoNeg");
11099 }
11100
11101 if (paf && PAF_SUBGRP(paf)) {
11102 if (CHECK_FLAG(
11103 bgp->flags,
11104 BGP_FLAG_EBGP_REQUIRES_POLICY)
11105 && !bgp_outbound_policy_exists(
11106 peer, filter))
11107 vty_out(vty, " %8s",
11108 "(Policy)");
11109 else
11110 vty_out(vty,
11111 " %8u",
11112 (PAF_SUBGRP(
11113 paf))
11114 ->scount);
11115 } else {
11116 vty_out(vty, " NoNeg");
11117 }
11118 } else {
11119 if (CHECK_FLAG(peer->flags,
11120 PEER_FLAG_SHUTDOWN)
11121 || CHECK_FLAG(peer->bgp->flags,
11122 BGP_FLAG_SHUTDOWN))
11123 vty_out(vty, " Idle (Admin)");
11124 else if (CHECK_FLAG(
11125 peer->sflags,
11126 PEER_STATUS_PREFIX_OVERFLOW))
11127 vty_out(vty, " Idle (PfxCt)");
11128 else
11129 vty_out(vty, " %12s",
11130 lookup_msg(bgp_status_msg,
11131 peer->status, NULL));
11132
11133 vty_out(vty, " %8u", 0);
11134 }
11135 /* Make sure `Desc` column is the lastest in
11136 * the output.
11137 */
11138 if (peer->desc)
11139 vty_out(vty, " %s",
11140 bgp_peer_description_stripped(
11141 peer->desc,
11142 show_wide ? 64 : 20));
11143 else
11144 vty_out(vty, " N/A");
11145 vty_out(vty, "\n");
11146 }
11147
11148 }
11149 }
11150
11151 if (use_json) {
11152 json_object_object_add(json, "peers", json_peers);
11153 json_object_int_add(json, "failedPeers", failed_count);
11154 json_object_int_add(json, "displayedPeers",
11155 count - filtered_count);
11156 json_object_int_add(json, "totalPeers", count);
11157 json_object_int_add(json, "dynamicPeers", dn_count);
11158
11159 if (!show_failed)
11160 bgp_show_bestpath_json(bgp, json);
11161
11162 vty_json(vty, json);
11163 } else {
11164 if (count) {
11165 if (filtered_count == count)
11166 vty_out(vty, "\n%% No matching neighbor\n");
11167 else {
11168 if (show_failed)
11169 vty_out(vty, "\nDisplayed neighbors %d",
11170 failed_count);
11171 else if (as_type != AS_UNSPECIFIED || as
11172 || fpeer || show_established)
11173 vty_out(vty, "\nDisplayed neighbors %d",
11174 count - filtered_count);
11175
11176 vty_out(vty, "\nTotal number of neighbors %d\n",
11177 count);
11178 }
11179 } else {
11180 vty_out(vty, "No %s neighbor is configured\n",
11181 get_afi_safi_str(afi, safi, false));
11182 }
11183
11184 if (dn_count) {
11185 vty_out(vty, "* - dynamic neighbor\n");
11186 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11187 dn_count, bgp->dynamic_neighbors_limit);
11188 }
11189 }
11190
11191 return CMD_SUCCESS;
11192 }
11193
11194 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11195 int safi, struct peer *fpeer, int as_type,
11196 as_t as, uint16_t show_flags)
11197 {
11198 int is_first = 1;
11199 int afi_wildcard = (afi == AFI_MAX);
11200 int safi_wildcard = (safi == SAFI_MAX);
11201 int is_wildcard = (afi_wildcard || safi_wildcard);
11202 bool nbr_output = false;
11203 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11204
11205 if (use_json && is_wildcard)
11206 vty_out(vty, "{\n");
11207 if (afi_wildcard)
11208 afi = 1; /* AFI_IP */
11209 while (afi < AFI_MAX) {
11210 if (safi_wildcard)
11211 safi = 1; /* SAFI_UNICAST */
11212 while (safi < SAFI_MAX) {
11213 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11214 nbr_output = true;
11215
11216 if (is_wildcard) {
11217 /*
11218 * So limit output to those afi/safi
11219 * pairs that
11220 * actualy have something interesting in
11221 * them
11222 */
11223 if (use_json) {
11224 if (!is_first)
11225 vty_out(vty, ",\n");
11226 else
11227 is_first = 0;
11228
11229 vty_out(vty, "\"%s\":",
11230 get_afi_safi_str(afi,
11231 safi,
11232 true));
11233 } else {
11234 vty_out(vty,
11235 "\n%s Summary (%s):\n",
11236 get_afi_safi_str(afi,
11237 safi,
11238 false),
11239 bgp->name_pretty);
11240 }
11241 }
11242 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11243 as_type, as, show_flags);
11244 }
11245 safi++;
11246 if (!safi_wildcard)
11247 safi = SAFI_MAX;
11248 }
11249 afi++;
11250 if (!afi_wildcard)
11251 afi = AFI_MAX;
11252 }
11253
11254 if (use_json && is_wildcard)
11255 vty_out(vty, "}\n");
11256 else if (!nbr_output) {
11257 if (use_json)
11258 vty_out(vty, "{}\n");
11259 else
11260 vty_out(vty, "%% No BGP neighbors found in %s\n",
11261 bgp->name_pretty);
11262 }
11263 }
11264
11265 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11266 safi_t safi,
11267 const char *neighbor,
11268 int as_type, as_t as,
11269 uint16_t show_flags)
11270 {
11271 struct listnode *node, *nnode;
11272 struct bgp *bgp;
11273 struct peer *fpeer = NULL;
11274 int is_first = 1;
11275 bool nbr_output = false;
11276 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11277
11278 if (use_json)
11279 vty_out(vty, "{\n");
11280
11281 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11282 nbr_output = true;
11283 if (use_json) {
11284 if (!is_first)
11285 vty_out(vty, ",\n");
11286 else
11287 is_first = 0;
11288
11289 vty_out(vty, "\"%s\":",
11290 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11291 ? VRF_DEFAULT_NAME
11292 : bgp->name);
11293 }
11294 if (neighbor) {
11295 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11296 use_json);
11297 if (!fpeer)
11298 continue;
11299 }
11300 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11301 as, show_flags);
11302 }
11303
11304 if (use_json)
11305 vty_out(vty, "}\n");
11306 else if (!nbr_output)
11307 vty_out(vty, "%% BGP instance not found\n");
11308 }
11309
11310 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11311 safi_t safi, const char *neighbor, int as_type,
11312 as_t as, uint16_t show_flags)
11313 {
11314 struct bgp *bgp;
11315 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11316 struct peer *fpeer = NULL;
11317
11318 if (name) {
11319 if (strmatch(name, "all")) {
11320 bgp_show_all_instances_summary_vty(vty, afi, safi,
11321 neighbor, as_type,
11322 as, show_flags);
11323 return CMD_SUCCESS;
11324 } else {
11325 bgp = bgp_lookup_by_name(name);
11326
11327 if (!bgp) {
11328 if (use_json)
11329 vty_out(vty, "{}\n");
11330 else
11331 vty_out(vty,
11332 "%% BGP instance not found\n");
11333 return CMD_WARNING;
11334 }
11335
11336 if (neighbor) {
11337 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11338 use_json);
11339 if (!fpeer)
11340 return CMD_WARNING;
11341 }
11342 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11343 as_type, as, show_flags);
11344 return CMD_SUCCESS;
11345 }
11346 }
11347
11348 bgp = bgp_get_default();
11349
11350 if (bgp) {
11351 if (neighbor) {
11352 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11353 use_json);
11354 if (!fpeer)
11355 return CMD_WARNING;
11356 }
11357 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11358 as, show_flags);
11359 } else {
11360 if (use_json)
11361 vty_out(vty, "{}\n");
11362 else
11363 vty_out(vty, "%% BGP instance not found\n");
11364 return CMD_WARNING;
11365 }
11366
11367 return CMD_SUCCESS;
11368 }
11369
11370 /* `show [ip] bgp summary' commands. */
11371 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11372 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11373 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11374 "]] [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]",
11375 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11376 BGP_SAFI_WITH_LABEL_HELP_STR
11377 "Display the entries for all address families\n"
11378 "Summary of BGP neighbor status\n"
11379 "Show only sessions in Established state\n"
11380 "Show only sessions not in Established state\n"
11381 "Show only the specified neighbor session\n"
11382 "Neighbor to display information about\n"
11383 "Neighbor to display information about\n"
11384 "Neighbor on BGP configured interface\n"
11385 "Show only the specified remote AS sessions\n"
11386 "AS number\n"
11387 "Internal (iBGP) AS sessions\n"
11388 "External (eBGP) AS sessions\n"
11389 "Shorten the information on BGP instances\n"
11390 "Increase table width for longer output\n" JSON_STR)
11391 {
11392 char *vrf = NULL;
11393 afi_t afi = AFI_MAX;
11394 safi_t safi = SAFI_MAX;
11395 as_t as = 0; /* 0 means AS filter not set */
11396 int as_type = AS_UNSPECIFIED;
11397 uint16_t show_flags = 0;
11398
11399 int idx = 0;
11400
11401 /* show [ip] bgp */
11402 if (!all && argv_find(argv, argc, "ip", &idx))
11403 afi = AFI_IP;
11404 /* [<vrf> VIEWVRFNAME] */
11405 if (argv_find(argv, argc, "vrf", &idx)) {
11406 vrf = argv[idx + 1]->arg;
11407 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11408 vrf = NULL;
11409 } else if (argv_find(argv, argc, "view", &idx))
11410 /* [<view> VIEWVRFNAME] */
11411 vrf = argv[idx + 1]->arg;
11412 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11413 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11414 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11415 }
11416
11417 if (argv_find(argv, argc, "failed", &idx))
11418 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11419
11420 if (argv_find(argv, argc, "established", &idx))
11421 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11422
11423 if (argv_find(argv, argc, "remote-as", &idx)) {
11424 if (argv[idx + 1]->arg[0] == 'i')
11425 as_type = AS_INTERNAL;
11426 else if (argv[idx + 1]->arg[0] == 'e')
11427 as_type = AS_EXTERNAL;
11428 else
11429 as = (as_t)atoi(argv[idx + 1]->arg);
11430 }
11431
11432 if (argv_find(argv, argc, "terse", &idx))
11433 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11434
11435 if (argv_find(argv, argc, "wide", &idx))
11436 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11437
11438 if (argv_find(argv, argc, "json", &idx))
11439 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11440
11441 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11442 show_flags);
11443 }
11444
11445 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11446 {
11447 if (for_json)
11448 return get_afi_safi_json_str(afi, safi);
11449 else
11450 return get_afi_safi_vty_str(afi, safi);
11451 }
11452
11453
11454 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11455 afi_t afi, safi_t safi,
11456 uint16_t adv_smcap, uint16_t adv_rmcap,
11457 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11458 bool use_json, json_object *json_pref)
11459 {
11460 /* Send-Mode */
11461 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11462 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11463 if (use_json) {
11464 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11465 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11466 json_object_string_add(json_pref, "sendMode",
11467 "advertisedAndReceived");
11468 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11469 json_object_string_add(json_pref, "sendMode",
11470 "advertised");
11471 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11472 json_object_string_add(json_pref, "sendMode",
11473 "received");
11474 } else {
11475 vty_out(vty, " Send-mode: ");
11476 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11477 vty_out(vty, "advertised");
11478 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11479 vty_out(vty, "%sreceived",
11480 CHECK_FLAG(p->af_cap[afi][safi],
11481 adv_smcap)
11482 ? ", "
11483 : "");
11484 vty_out(vty, "\n");
11485 }
11486 }
11487
11488 /* Receive-Mode */
11489 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11490 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11491 if (use_json) {
11492 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11493 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11494 json_object_string_add(json_pref, "recvMode",
11495 "advertisedAndReceived");
11496 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11497 json_object_string_add(json_pref, "recvMode",
11498 "advertised");
11499 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11500 json_object_string_add(json_pref, "recvMode",
11501 "received");
11502 } else {
11503 vty_out(vty, " Receive-mode: ");
11504 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11505 vty_out(vty, "advertised");
11506 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11507 vty_out(vty, "%sreceived",
11508 CHECK_FLAG(p->af_cap[afi][safi],
11509 adv_rmcap)
11510 ? ", "
11511 : "");
11512 vty_out(vty, "\n");
11513 }
11514 }
11515 }
11516
11517 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11518 struct peer *p,
11519 bool use_json,
11520 json_object *json)
11521 {
11522 bool rbit = false;
11523 bool nbit = false;
11524
11525 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11526 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11527 && (peer_established(p))) {
11528 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11529 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11530 }
11531
11532 if (use_json) {
11533 json_object_boolean_add(json, "rBit", rbit);
11534 json_object_boolean_add(json, "nBit", nbit);
11535 } else {
11536 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11537 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11538 }
11539 }
11540
11541 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11542 struct peer *peer,
11543 bool use_json,
11544 json_object *json)
11545 {
11546 const char *mode = "NotApplicable";
11547
11548 if (!use_json)
11549 vty_out(vty, "\n Remote GR Mode: ");
11550
11551 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11552 && (peer_established(peer))) {
11553
11554 if ((peer->nsf_af_count == 0)
11555 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11556
11557 mode = "Disable";
11558
11559 } else if (peer->nsf_af_count == 0
11560 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11561
11562 mode = "Helper";
11563
11564 } else if (peer->nsf_af_count != 0
11565 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11566
11567 mode = "Restart";
11568 }
11569 }
11570
11571 if (use_json) {
11572 json_object_string_add(json, "remoteGrMode", mode);
11573 } else
11574 vty_out(vty, mode, "\n");
11575 }
11576
11577 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11578 struct peer *p,
11579 bool use_json,
11580 json_object *json)
11581 {
11582 const char *mode = "Invalid";
11583
11584 if (!use_json)
11585 vty_out(vty, " Local GR Mode: ");
11586
11587 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11588 mode = "Helper";
11589 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11590 mode = "Restart";
11591 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11592 mode = "Disable";
11593 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11594 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11595 mode = "Helper*";
11596 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11597 mode = "Restart*";
11598 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11599 mode = "Disable*";
11600 else
11601 mode = "Invalid*";
11602 }
11603
11604 if (use_json) {
11605 json_object_string_add(json, "localGrMode", mode);
11606 } else {
11607 vty_out(vty, mode, "\n");
11608 }
11609 }
11610
11611 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11612 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11613 {
11614 afi_t afi;
11615 safi_t safi;
11616 json_object *json_afi_safi = NULL;
11617 json_object *json_timer = NULL;
11618 json_object *json_endofrib_status = NULL;
11619 bool eor_flag = false;
11620
11621 FOREACH_AFI_SAFI_NSF (afi, safi) {
11622 if (!peer->afc[afi][safi])
11623 continue;
11624
11625 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11626 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11627 continue;
11628
11629 if (use_json) {
11630 json_afi_safi = json_object_new_object();
11631 json_endofrib_status = json_object_new_object();
11632 json_timer = json_object_new_object();
11633 }
11634
11635 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11636 eor_flag = true;
11637 else
11638 eor_flag = false;
11639
11640 if (!use_json) {
11641 vty_out(vty, " %s:\n",
11642 get_afi_safi_str(afi, safi, false));
11643
11644 vty_out(vty, " F bit: ");
11645 }
11646
11647 if (peer->nsf[afi][safi] &&
11648 CHECK_FLAG(peer->af_cap[afi][safi],
11649 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11650
11651 if (use_json) {
11652 json_object_boolean_true_add(json_afi_safi,
11653 "fBit");
11654 } else
11655 vty_out(vty, "True\n");
11656 } else {
11657 if (use_json)
11658 json_object_boolean_false_add(json_afi_safi,
11659 "fBit");
11660 else
11661 vty_out(vty, "False\n");
11662 }
11663
11664 if (!use_json)
11665 vty_out(vty, " End-of-RIB sent: ");
11666
11667 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11668 PEER_STATUS_EOR_SEND)) {
11669 if (use_json) {
11670 json_object_boolean_true_add(
11671 json_endofrib_status, "endOfRibSend");
11672
11673 PRINT_EOR_JSON(eor_flag);
11674 } else {
11675 vty_out(vty, "Yes\n");
11676 vty_out(vty,
11677 " End-of-RIB sent after update: ");
11678
11679 PRINT_EOR(eor_flag);
11680 }
11681 } else {
11682 if (use_json) {
11683 json_object_boolean_false_add(
11684 json_endofrib_status, "endOfRibSend");
11685 json_object_boolean_false_add(
11686 json_endofrib_status,
11687 "endOfRibSentAfterUpdate");
11688 } else {
11689 vty_out(vty, "No\n");
11690 vty_out(vty,
11691 " End-of-RIB sent after update: ");
11692 vty_out(vty, "No\n");
11693 }
11694 }
11695
11696 if (!use_json)
11697 vty_out(vty, " End-of-RIB received: ");
11698
11699 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11700 PEER_STATUS_EOR_RECEIVED)) {
11701 if (use_json)
11702 json_object_boolean_true_add(
11703 json_endofrib_status, "endOfRibRecv");
11704 else
11705 vty_out(vty, "Yes\n");
11706 } else {
11707 if (use_json)
11708 json_object_boolean_false_add(
11709 json_endofrib_status, "endOfRibRecv");
11710 else
11711 vty_out(vty, "No\n");
11712 }
11713
11714 if (use_json) {
11715 json_object_int_add(json_timer, "stalePathTimer",
11716 peer->bgp->stalepath_time);
11717
11718 if (peer->t_gr_stale != NULL) {
11719 json_object_int_add(json_timer,
11720 "stalePathTimerRemaining",
11721 thread_timer_remain_second(
11722 peer->t_gr_stale));
11723 }
11724
11725 /* Display Configured Selection
11726 * Deferral only when when
11727 * Gr mode is enabled.
11728 */
11729 if (CHECK_FLAG(peer->flags,
11730 PEER_FLAG_GRACEFUL_RESTART)) {
11731 json_object_int_add(json_timer,
11732 "selectionDeferralTimer",
11733 peer->bgp->stalepath_time);
11734 }
11735
11736 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11737 NULL) {
11738
11739 json_object_int_add(
11740 json_timer,
11741 "selectionDeferralTimerRemaining",
11742 thread_timer_remain_second(
11743 peer->bgp->gr_info[afi][safi]
11744 .t_select_deferral));
11745 }
11746 } else {
11747 vty_out(vty, " Timers:\n");
11748 vty_out(vty,
11749 " Configured Stale Path Time(sec): %u\n",
11750 peer->bgp->stalepath_time);
11751
11752 if (peer->t_gr_stale != NULL)
11753 vty_out(vty,
11754 " Stale Path Remaining(sec): %ld\n",
11755 thread_timer_remain_second(
11756 peer->t_gr_stale));
11757 /* Display Configured Selection
11758 * Deferral only when when
11759 * Gr mode is enabled.
11760 */
11761 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11762 vty_out(vty,
11763 " Configured Selection Deferral Time(sec): %u\n",
11764 peer->bgp->select_defer_time);
11765
11766 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11767 NULL)
11768 vty_out(vty,
11769 " Selection Deferral Time Remaining(sec): %ld\n",
11770 thread_timer_remain_second(
11771 peer->bgp->gr_info[afi][safi]
11772 .t_select_deferral));
11773 }
11774 if (use_json) {
11775 json_object_object_add(json_afi_safi, "endOfRibStatus",
11776 json_endofrib_status);
11777 json_object_object_add(json_afi_safi, "timers",
11778 json_timer);
11779 json_object_object_add(
11780 json, get_afi_safi_str(afi, safi, true),
11781 json_afi_safi);
11782 }
11783 }
11784 }
11785
11786 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11787 struct peer *p,
11788 bool use_json,
11789 json_object *json)
11790 {
11791 if (use_json) {
11792 json_object *json_timer = NULL;
11793
11794 json_timer = json_object_new_object();
11795
11796 json_object_int_add(json_timer, "configuredRestartTimer",
11797 p->bgp->restart_time);
11798
11799 json_object_int_add(json_timer, "receivedRestartTimer",
11800 p->v_gr_restart);
11801
11802 if (p->t_gr_restart != NULL)
11803 json_object_int_add(
11804 json_timer, "restartTimerRemaining",
11805 thread_timer_remain_second(p->t_gr_restart));
11806
11807 json_object_object_add(json, "timers", json_timer);
11808 } else {
11809
11810 vty_out(vty, " Timers:\n");
11811 vty_out(vty, " Configured Restart Time(sec): %u\n",
11812 p->bgp->restart_time);
11813
11814 vty_out(vty, " Received Restart Time(sec): %u\n",
11815 p->v_gr_restart);
11816 if (p->t_gr_restart != NULL)
11817 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11818 thread_timer_remain_second(p->t_gr_restart));
11819 if (p->t_gr_restart != NULL) {
11820 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11821 thread_timer_remain_second(p->t_gr_restart));
11822 }
11823 }
11824 }
11825
11826 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11827 bool use_json, json_object *json)
11828 {
11829 char dn_flag[2] = {0};
11830 /* '*' + v6 address of neighbor */
11831 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11832
11833 if (!p->conf_if && peer_dynamic_neighbor(p))
11834 dn_flag[0] = '*';
11835
11836 if (p->conf_if) {
11837 if (use_json)
11838 json_object_string_addf(json, "neighborAddr", "%pSU",
11839 &p->su);
11840 else
11841 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11842 &p->su);
11843 } else {
11844 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11845 p->host);
11846
11847 if (use_json)
11848 json_object_string_add(json, "neighborAddr",
11849 neighborAddr);
11850 else
11851 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11852 }
11853
11854 /* more gr info in new format */
11855 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11856 }
11857
11858 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11859 safi_t safi, bool use_json,
11860 json_object *json_neigh)
11861 {
11862 struct bgp_filter *filter;
11863 struct peer_af *paf;
11864 char orf_pfx_name[BUFSIZ];
11865 int orf_pfx_count;
11866 json_object *json_af = NULL;
11867 json_object *json_prefA = NULL;
11868 json_object *json_prefB = NULL;
11869 json_object *json_addr = NULL;
11870 json_object *json_advmap = NULL;
11871
11872 if (use_json) {
11873 json_addr = json_object_new_object();
11874 json_af = json_object_new_object();
11875 filter = &p->filter[afi][safi];
11876
11877 if (peer_group_active(p))
11878 json_object_string_add(json_addr, "peerGroupMember",
11879 p->group->name);
11880
11881 paf = peer_af_find(p, afi, safi);
11882 if (paf && PAF_SUBGRP(paf)) {
11883 json_object_int_add(json_addr, "updateGroupId",
11884 PAF_UPDGRP(paf)->id);
11885 json_object_int_add(json_addr, "subGroupId",
11886 PAF_SUBGRP(paf)->id);
11887 json_object_int_add(json_addr, "packetQueueLength",
11888 bpacket_queue_virtual_length(paf));
11889 }
11890
11891 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11892 || CHECK_FLAG(p->af_cap[afi][safi],
11893 PEER_CAP_ORF_PREFIX_SM_RCV)
11894 || CHECK_FLAG(p->af_cap[afi][safi],
11895 PEER_CAP_ORF_PREFIX_RM_ADV)
11896 || CHECK_FLAG(p->af_cap[afi][safi],
11897 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11898 json_object_int_add(json_af, "orfType",
11899 ORF_TYPE_PREFIX);
11900 json_prefA = json_object_new_object();
11901 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11902 PEER_CAP_ORF_PREFIX_SM_ADV,
11903 PEER_CAP_ORF_PREFIX_RM_ADV,
11904 PEER_CAP_ORF_PREFIX_SM_RCV,
11905 PEER_CAP_ORF_PREFIX_RM_RCV,
11906 use_json, json_prefA);
11907 json_object_object_add(json_af, "orfPrefixList",
11908 json_prefA);
11909 }
11910
11911 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11912 || CHECK_FLAG(p->af_cap[afi][safi],
11913 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11914 || CHECK_FLAG(p->af_cap[afi][safi],
11915 PEER_CAP_ORF_PREFIX_RM_ADV)
11916 || CHECK_FLAG(p->af_cap[afi][safi],
11917 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11918 json_object_int_add(json_af, "orfOldType",
11919 ORF_TYPE_PREFIX_OLD);
11920 json_prefB = json_object_new_object();
11921 bgp_show_peer_afi_orf_cap(
11922 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11923 PEER_CAP_ORF_PREFIX_RM_ADV,
11924 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11925 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11926 json_prefB);
11927 json_object_object_add(json_af, "orfOldPrefixList",
11928 json_prefB);
11929 }
11930
11931 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11932 || CHECK_FLAG(p->af_cap[afi][safi],
11933 PEER_CAP_ORF_PREFIX_SM_RCV)
11934 || CHECK_FLAG(p->af_cap[afi][safi],
11935 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11936 || CHECK_FLAG(p->af_cap[afi][safi],
11937 PEER_CAP_ORF_PREFIX_RM_ADV)
11938 || CHECK_FLAG(p->af_cap[afi][safi],
11939 PEER_CAP_ORF_PREFIX_RM_RCV)
11940 || CHECK_FLAG(p->af_cap[afi][safi],
11941 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11942 json_object_object_add(json_addr, "afDependentCap",
11943 json_af);
11944 else
11945 json_object_free(json_af);
11946
11947 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11948 p->host, afi, safi);
11949 orf_pfx_count = prefix_bgp_show_prefix_list(
11950 NULL, afi, orf_pfx_name, use_json);
11951
11952 if (CHECK_FLAG(p->af_sflags[afi][safi],
11953 PEER_STATUS_ORF_PREFIX_SEND)
11954 || orf_pfx_count) {
11955 if (CHECK_FLAG(p->af_sflags[afi][safi],
11956 PEER_STATUS_ORF_PREFIX_SEND))
11957 json_object_boolean_true_add(json_neigh,
11958 "orfSent");
11959 if (orf_pfx_count)
11960 json_object_int_add(json_addr, "orfRecvCounter",
11961 orf_pfx_count);
11962 }
11963 if (CHECK_FLAG(p->af_sflags[afi][safi],
11964 PEER_STATUS_ORF_WAIT_REFRESH))
11965 json_object_string_add(
11966 json_addr, "orfFirstUpdate",
11967 "deferredUntilORFOrRouteRefreshRecvd");
11968
11969 if (CHECK_FLAG(p->af_flags[afi][safi],
11970 PEER_FLAG_REFLECTOR_CLIENT))
11971 json_object_boolean_true_add(json_addr,
11972 "routeReflectorClient");
11973 if (CHECK_FLAG(p->af_flags[afi][safi],
11974 PEER_FLAG_RSERVER_CLIENT))
11975 json_object_boolean_true_add(json_addr,
11976 "routeServerClient");
11977 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11978 json_object_boolean_true_add(json_addr,
11979 "inboundSoftConfigPermit");
11980
11981 if (CHECK_FLAG(p->af_flags[afi][safi],
11982 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11983 json_object_boolean_true_add(
11984 json_addr,
11985 "privateAsNumsAllReplacedInUpdatesToNbr");
11986 else if (CHECK_FLAG(p->af_flags[afi][safi],
11987 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11988 json_object_boolean_true_add(
11989 json_addr,
11990 "privateAsNumsReplacedInUpdatesToNbr");
11991 else if (CHECK_FLAG(p->af_flags[afi][safi],
11992 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11993 json_object_boolean_true_add(
11994 json_addr,
11995 "privateAsNumsAllRemovedInUpdatesToNbr");
11996 else if (CHECK_FLAG(p->af_flags[afi][safi],
11997 PEER_FLAG_REMOVE_PRIVATE_AS))
11998 json_object_boolean_true_add(
11999 json_addr,
12000 "privateAsNumsRemovedInUpdatesToNbr");
12001
12002 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12003 json_object_boolean_true_add(
12004 json_addr,
12005 bgp_addpath_names(p->addpath_type[afi][safi])
12006 ->type_json_name);
12007
12008 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12009 json_object_string_add(json_addr,
12010 "overrideASNsInOutboundUpdates",
12011 "ifAspathEqualRemoteAs");
12012
12013 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12014 || CHECK_FLAG(p->af_flags[afi][safi],
12015 PEER_FLAG_FORCE_NEXTHOP_SELF))
12016 json_object_boolean_true_add(json_addr,
12017 "routerAlwaysNextHop");
12018 if (CHECK_FLAG(p->af_flags[afi][safi],
12019 PEER_FLAG_AS_PATH_UNCHANGED))
12020 json_object_boolean_true_add(
12021 json_addr, "unchangedAsPathPropogatedToNbr");
12022 if (CHECK_FLAG(p->af_flags[afi][safi],
12023 PEER_FLAG_NEXTHOP_UNCHANGED))
12024 json_object_boolean_true_add(
12025 json_addr, "unchangedNextHopPropogatedToNbr");
12026 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12027 json_object_boolean_true_add(
12028 json_addr, "unchangedMedPropogatedToNbr");
12029 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12030 || CHECK_FLAG(p->af_flags[afi][safi],
12031 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12032 if (CHECK_FLAG(p->af_flags[afi][safi],
12033 PEER_FLAG_SEND_COMMUNITY)
12034 && CHECK_FLAG(p->af_flags[afi][safi],
12035 PEER_FLAG_SEND_EXT_COMMUNITY))
12036 json_object_string_add(json_addr,
12037 "commAttriSentToNbr",
12038 "extendedAndStandard");
12039 else if (CHECK_FLAG(p->af_flags[afi][safi],
12040 PEER_FLAG_SEND_EXT_COMMUNITY))
12041 json_object_string_add(json_addr,
12042 "commAttriSentToNbr",
12043 "extended");
12044 else
12045 json_object_string_add(json_addr,
12046 "commAttriSentToNbr",
12047 "standard");
12048 }
12049 if (CHECK_FLAG(p->af_flags[afi][safi],
12050 PEER_FLAG_DEFAULT_ORIGINATE)) {
12051 if (p->default_rmap[afi][safi].name)
12052 json_object_string_add(
12053 json_addr, "defaultRouteMap",
12054 p->default_rmap[afi][safi].name);
12055
12056 if (paf && PAF_SUBGRP(paf)
12057 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12058 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12059 json_object_boolean_true_add(json_addr,
12060 "defaultSent");
12061 else
12062 json_object_boolean_true_add(json_addr,
12063 "defaultNotSent");
12064 }
12065
12066 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12067 if (is_evpn_enabled())
12068 json_object_boolean_true_add(
12069 json_addr, "advertiseAllVnis");
12070 }
12071
12072 if (filter->plist[FILTER_IN].name
12073 || filter->dlist[FILTER_IN].name
12074 || filter->aslist[FILTER_IN].name
12075 || filter->map[RMAP_IN].name)
12076 json_object_boolean_true_add(json_addr,
12077 "inboundPathPolicyConfig");
12078 if (filter->plist[FILTER_OUT].name
12079 || filter->dlist[FILTER_OUT].name
12080 || filter->aslist[FILTER_OUT].name
12081 || filter->map[RMAP_OUT].name || filter->usmap.name)
12082 json_object_boolean_true_add(
12083 json_addr, "outboundPathPolicyConfig");
12084
12085 /* prefix-list */
12086 if (filter->plist[FILTER_IN].name)
12087 json_object_string_add(json_addr,
12088 "incomingUpdatePrefixFilterList",
12089 filter->plist[FILTER_IN].name);
12090 if (filter->plist[FILTER_OUT].name)
12091 json_object_string_add(json_addr,
12092 "outgoingUpdatePrefixFilterList",
12093 filter->plist[FILTER_OUT].name);
12094
12095 /* distribute-list */
12096 if (filter->dlist[FILTER_IN].name)
12097 json_object_string_add(
12098 json_addr, "incomingUpdateNetworkFilterList",
12099 filter->dlist[FILTER_IN].name);
12100 if (filter->dlist[FILTER_OUT].name)
12101 json_object_string_add(
12102 json_addr, "outgoingUpdateNetworkFilterList",
12103 filter->dlist[FILTER_OUT].name);
12104
12105 /* filter-list. */
12106 if (filter->aslist[FILTER_IN].name)
12107 json_object_string_add(json_addr,
12108 "incomingUpdateAsPathFilterList",
12109 filter->aslist[FILTER_IN].name);
12110 if (filter->aslist[FILTER_OUT].name)
12111 json_object_string_add(json_addr,
12112 "outgoingUpdateAsPathFilterList",
12113 filter->aslist[FILTER_OUT].name);
12114
12115 /* route-map. */
12116 if (filter->map[RMAP_IN].name)
12117 json_object_string_add(
12118 json_addr, "routeMapForIncomingAdvertisements",
12119 filter->map[RMAP_IN].name);
12120 if (filter->map[RMAP_OUT].name)
12121 json_object_string_add(
12122 json_addr, "routeMapForOutgoingAdvertisements",
12123 filter->map[RMAP_OUT].name);
12124
12125 /* ebgp-requires-policy (inbound) */
12126 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12127 && !bgp_inbound_policy_exists(p, filter))
12128 json_object_string_add(
12129 json_addr, "inboundEbgpRequiresPolicy",
12130 "Inbound updates discarded due to missing policy");
12131
12132 /* ebgp-requires-policy (outbound) */
12133 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12134 && (!bgp_outbound_policy_exists(p, filter)))
12135 json_object_string_add(
12136 json_addr, "outboundEbgpRequiresPolicy",
12137 "Outbound updates discarded due to missing policy");
12138
12139 /* unsuppress-map */
12140 if (filter->usmap.name)
12141 json_object_string_add(json_addr,
12142 "selectiveUnsuppressRouteMap",
12143 filter->usmap.name);
12144
12145 /* advertise-map */
12146 if (filter->advmap.aname) {
12147 json_advmap = json_object_new_object();
12148 json_object_string_add(json_advmap, "condition",
12149 filter->advmap.condition
12150 ? "EXIST"
12151 : "NON_EXIST");
12152 json_object_string_add(json_advmap, "conditionMap",
12153 filter->advmap.cname);
12154 json_object_string_add(json_advmap, "advertiseMap",
12155 filter->advmap.aname);
12156 json_object_string_add(
12157 json_advmap, "advertiseStatus",
12158 filter->advmap.update_type ==
12159 UPDATE_TYPE_ADVERTISE
12160 ? "Advertise"
12161 : "Withdraw");
12162 json_object_object_add(json_addr, "advertiseMap",
12163 json_advmap);
12164 }
12165
12166 /* Receive prefix count */
12167 json_object_int_add(json_addr, "acceptedPrefixCounter",
12168 p->pcount[afi][safi]);
12169 if (paf && PAF_SUBGRP(paf))
12170 json_object_int_add(json_addr, "sentPrefixCounter",
12171 (PAF_SUBGRP(paf))->scount);
12172
12173 /* Maximum prefix */
12174 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12175 json_object_int_add(json_addr, "prefixOutAllowedMax",
12176 p->pmax_out[afi][safi]);
12177
12178 /* Maximum prefix */
12179 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12180 json_object_int_add(json_addr, "prefixAllowedMax",
12181 p->pmax[afi][safi]);
12182 if (CHECK_FLAG(p->af_flags[afi][safi],
12183 PEER_FLAG_MAX_PREFIX_WARNING))
12184 json_object_boolean_true_add(
12185 json_addr, "prefixAllowedMaxWarning");
12186 json_object_int_add(json_addr,
12187 "prefixAllowedWarningThresh",
12188 p->pmax_threshold[afi][safi]);
12189 if (p->pmax_restart[afi][safi])
12190 json_object_int_add(
12191 json_addr,
12192 "prefixAllowedRestartIntervalMsecs",
12193 p->pmax_restart[afi][safi] * 60000);
12194 }
12195 json_object_object_add(json_neigh,
12196 get_afi_safi_str(afi, safi, true),
12197 json_addr);
12198
12199 } else {
12200 filter = &p->filter[afi][safi];
12201
12202 vty_out(vty, " For address family: %s\n",
12203 get_afi_safi_str(afi, safi, false));
12204
12205 if (peer_group_active(p))
12206 vty_out(vty, " %s peer-group member\n",
12207 p->group->name);
12208
12209 paf = peer_af_find(p, afi, safi);
12210 if (paf && PAF_SUBGRP(paf)) {
12211 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12212 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12213 vty_out(vty, " Packet Queue length %d\n",
12214 bpacket_queue_virtual_length(paf));
12215 } else {
12216 vty_out(vty, " Not part of any update group\n");
12217 }
12218 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12219 || CHECK_FLAG(p->af_cap[afi][safi],
12220 PEER_CAP_ORF_PREFIX_SM_RCV)
12221 || CHECK_FLAG(p->af_cap[afi][safi],
12222 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12223 || CHECK_FLAG(p->af_cap[afi][safi],
12224 PEER_CAP_ORF_PREFIX_RM_ADV)
12225 || CHECK_FLAG(p->af_cap[afi][safi],
12226 PEER_CAP_ORF_PREFIX_RM_RCV)
12227 || CHECK_FLAG(p->af_cap[afi][safi],
12228 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12229 vty_out(vty, " AF-dependant capabilities:\n");
12230
12231 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12232 || CHECK_FLAG(p->af_cap[afi][safi],
12233 PEER_CAP_ORF_PREFIX_SM_RCV)
12234 || CHECK_FLAG(p->af_cap[afi][safi],
12235 PEER_CAP_ORF_PREFIX_RM_ADV)
12236 || CHECK_FLAG(p->af_cap[afi][safi],
12237 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12238 vty_out(vty,
12239 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12240 ORF_TYPE_PREFIX);
12241 bgp_show_peer_afi_orf_cap(
12242 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12243 PEER_CAP_ORF_PREFIX_RM_ADV,
12244 PEER_CAP_ORF_PREFIX_SM_RCV,
12245 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12246 }
12247 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12248 || CHECK_FLAG(p->af_cap[afi][safi],
12249 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12250 || CHECK_FLAG(p->af_cap[afi][safi],
12251 PEER_CAP_ORF_PREFIX_RM_ADV)
12252 || CHECK_FLAG(p->af_cap[afi][safi],
12253 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12254 vty_out(vty,
12255 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12256 ORF_TYPE_PREFIX_OLD);
12257 bgp_show_peer_afi_orf_cap(
12258 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12259 PEER_CAP_ORF_PREFIX_RM_ADV,
12260 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12261 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12262 }
12263
12264 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12265 p->host, afi, safi);
12266 orf_pfx_count = prefix_bgp_show_prefix_list(
12267 NULL, afi, orf_pfx_name, use_json);
12268
12269 if (CHECK_FLAG(p->af_sflags[afi][safi],
12270 PEER_STATUS_ORF_PREFIX_SEND)
12271 || orf_pfx_count) {
12272 vty_out(vty, " Outbound Route Filter (ORF):");
12273 if (CHECK_FLAG(p->af_sflags[afi][safi],
12274 PEER_STATUS_ORF_PREFIX_SEND))
12275 vty_out(vty, " sent;");
12276 if (orf_pfx_count)
12277 vty_out(vty, " received (%d entries)",
12278 orf_pfx_count);
12279 vty_out(vty, "\n");
12280 }
12281 if (CHECK_FLAG(p->af_sflags[afi][safi],
12282 PEER_STATUS_ORF_WAIT_REFRESH))
12283 vty_out(vty,
12284 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12285
12286 if (CHECK_FLAG(p->af_flags[afi][safi],
12287 PEER_FLAG_REFLECTOR_CLIENT))
12288 vty_out(vty, " Route-Reflector Client\n");
12289 if (CHECK_FLAG(p->af_flags[afi][safi],
12290 PEER_FLAG_RSERVER_CLIENT))
12291 vty_out(vty, " Route-Server Client\n");
12292 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12293 vty_out(vty,
12294 " Inbound soft reconfiguration allowed\n");
12295
12296 if (CHECK_FLAG(p->af_flags[afi][safi],
12297 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12298 vty_out(vty,
12299 " Private AS numbers (all) replaced in updates to this neighbor\n");
12300 else if (CHECK_FLAG(p->af_flags[afi][safi],
12301 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12302 vty_out(vty,
12303 " Private AS numbers replaced in updates to this neighbor\n");
12304 else if (CHECK_FLAG(p->af_flags[afi][safi],
12305 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12306 vty_out(vty,
12307 " Private AS numbers (all) removed in updates to this neighbor\n");
12308 else if (CHECK_FLAG(p->af_flags[afi][safi],
12309 PEER_FLAG_REMOVE_PRIVATE_AS))
12310 vty_out(vty,
12311 " Private AS numbers removed in updates to this neighbor\n");
12312
12313 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12314 vty_out(vty, " %s\n",
12315 bgp_addpath_names(p->addpath_type[afi][safi])
12316 ->human_description);
12317
12318 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12319 vty_out(vty,
12320 " Override ASNs in outbound updates if aspath equals remote-as\n");
12321
12322 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12323 || CHECK_FLAG(p->af_flags[afi][safi],
12324 PEER_FLAG_FORCE_NEXTHOP_SELF))
12325 vty_out(vty, " NEXT_HOP is always this router\n");
12326 if (CHECK_FLAG(p->af_flags[afi][safi],
12327 PEER_FLAG_AS_PATH_UNCHANGED))
12328 vty_out(vty,
12329 " AS_PATH is propagated unchanged to this neighbor\n");
12330 if (CHECK_FLAG(p->af_flags[afi][safi],
12331 PEER_FLAG_NEXTHOP_UNCHANGED))
12332 vty_out(vty,
12333 " NEXT_HOP is propagated unchanged to this neighbor\n");
12334 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12335 vty_out(vty,
12336 " MED is propagated unchanged to this neighbor\n");
12337 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12338 || CHECK_FLAG(p->af_flags[afi][safi],
12339 PEER_FLAG_SEND_EXT_COMMUNITY)
12340 || CHECK_FLAG(p->af_flags[afi][safi],
12341 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12342 vty_out(vty,
12343 " Community attribute sent to this neighbor");
12344 if (CHECK_FLAG(p->af_flags[afi][safi],
12345 PEER_FLAG_SEND_COMMUNITY)
12346 && CHECK_FLAG(p->af_flags[afi][safi],
12347 PEER_FLAG_SEND_EXT_COMMUNITY)
12348 && CHECK_FLAG(p->af_flags[afi][safi],
12349 PEER_FLAG_SEND_LARGE_COMMUNITY))
12350 vty_out(vty, "(all)\n");
12351 else if (CHECK_FLAG(p->af_flags[afi][safi],
12352 PEER_FLAG_SEND_LARGE_COMMUNITY))
12353 vty_out(vty, "(large)\n");
12354 else if (CHECK_FLAG(p->af_flags[afi][safi],
12355 PEER_FLAG_SEND_EXT_COMMUNITY))
12356 vty_out(vty, "(extended)\n");
12357 else
12358 vty_out(vty, "(standard)\n");
12359 }
12360 if (CHECK_FLAG(p->af_flags[afi][safi],
12361 PEER_FLAG_DEFAULT_ORIGINATE)) {
12362 vty_out(vty, " Default information originate,");
12363
12364 if (p->default_rmap[afi][safi].name)
12365 vty_out(vty, " default route-map %s%s,",
12366 p->default_rmap[afi][safi].map ? "*"
12367 : "",
12368 p->default_rmap[afi][safi].name);
12369 if (paf && PAF_SUBGRP(paf)
12370 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12371 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12372 vty_out(vty, " default sent\n");
12373 else
12374 vty_out(vty, " default not sent\n");
12375 }
12376
12377 /* advertise-vni-all */
12378 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12379 if (is_evpn_enabled())
12380 vty_out(vty, " advertise-all-vni\n");
12381 }
12382
12383 if (filter->plist[FILTER_IN].name
12384 || filter->dlist[FILTER_IN].name
12385 || filter->aslist[FILTER_IN].name
12386 || filter->map[RMAP_IN].name)
12387 vty_out(vty, " Inbound path policy configured\n");
12388 if (filter->plist[FILTER_OUT].name
12389 || filter->dlist[FILTER_OUT].name
12390 || filter->aslist[FILTER_OUT].name
12391 || filter->map[RMAP_OUT].name || filter->usmap.name)
12392 vty_out(vty, " Outbound path policy configured\n");
12393
12394 /* prefix-list */
12395 if (filter->plist[FILTER_IN].name)
12396 vty_out(vty,
12397 " Incoming update prefix filter list is %s%s\n",
12398 filter->plist[FILTER_IN].plist ? "*" : "",
12399 filter->plist[FILTER_IN].name);
12400 if (filter->plist[FILTER_OUT].name)
12401 vty_out(vty,
12402 " Outgoing update prefix filter list is %s%s\n",
12403 filter->plist[FILTER_OUT].plist ? "*" : "",
12404 filter->plist[FILTER_OUT].name);
12405
12406 /* distribute-list */
12407 if (filter->dlist[FILTER_IN].name)
12408 vty_out(vty,
12409 " Incoming update network filter list is %s%s\n",
12410 filter->dlist[FILTER_IN].alist ? "*" : "",
12411 filter->dlist[FILTER_IN].name);
12412 if (filter->dlist[FILTER_OUT].name)
12413 vty_out(vty,
12414 " Outgoing update network filter list is %s%s\n",
12415 filter->dlist[FILTER_OUT].alist ? "*" : "",
12416 filter->dlist[FILTER_OUT].name);
12417
12418 /* filter-list. */
12419 if (filter->aslist[FILTER_IN].name)
12420 vty_out(vty,
12421 " Incoming update AS path filter list is %s%s\n",
12422 filter->aslist[FILTER_IN].aslist ? "*" : "",
12423 filter->aslist[FILTER_IN].name);
12424 if (filter->aslist[FILTER_OUT].name)
12425 vty_out(vty,
12426 " Outgoing update AS path filter list is %s%s\n",
12427 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12428 filter->aslist[FILTER_OUT].name);
12429
12430 /* route-map. */
12431 if (filter->map[RMAP_IN].name)
12432 vty_out(vty,
12433 " Route map for incoming advertisements is %s%s\n",
12434 filter->map[RMAP_IN].map ? "*" : "",
12435 filter->map[RMAP_IN].name);
12436 if (filter->map[RMAP_OUT].name)
12437 vty_out(vty,
12438 " Route map for outgoing advertisements is %s%s\n",
12439 filter->map[RMAP_OUT].map ? "*" : "",
12440 filter->map[RMAP_OUT].name);
12441
12442 /* ebgp-requires-policy (inbound) */
12443 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12444 && !bgp_inbound_policy_exists(p, filter))
12445 vty_out(vty,
12446 " Inbound updates discarded due to missing policy\n");
12447
12448 /* ebgp-requires-policy (outbound) */
12449 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12450 && !bgp_outbound_policy_exists(p, filter))
12451 vty_out(vty,
12452 " Outbound updates discarded due to missing policy\n");
12453
12454 /* unsuppress-map */
12455 if (filter->usmap.name)
12456 vty_out(vty,
12457 " Route map for selective unsuppress is %s%s\n",
12458 filter->usmap.map ? "*" : "",
12459 filter->usmap.name);
12460
12461 /* advertise-map */
12462 if (filter->advmap.aname && filter->advmap.cname)
12463 vty_out(vty,
12464 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12465 filter->advmap.condition ? "EXIST"
12466 : "NON_EXIST",
12467 filter->advmap.cmap ? "*" : "",
12468 filter->advmap.cname,
12469 filter->advmap.amap ? "*" : "",
12470 filter->advmap.aname,
12471 filter->advmap.update_type ==
12472 UPDATE_TYPE_ADVERTISE
12473 ? "Advertise"
12474 : "Withdraw");
12475
12476 /* Receive prefix count */
12477 vty_out(vty, " %u accepted prefixes\n",
12478 p->pcount[afi][safi]);
12479
12480 /* maximum-prefix-out */
12481 if (CHECK_FLAG(p->af_flags[afi][safi],
12482 PEER_FLAG_MAX_PREFIX_OUT))
12483 vty_out(vty,
12484 " Maximum allowed prefixes sent %u\n",
12485 p->pmax_out[afi][safi]);
12486
12487 /* Maximum prefix */
12488 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12489 vty_out(vty,
12490 " Maximum prefixes allowed %u%s\n",
12491 p->pmax[afi][safi],
12492 CHECK_FLAG(p->af_flags[afi][safi],
12493 PEER_FLAG_MAX_PREFIX_WARNING)
12494 ? " (warning-only)"
12495 : "");
12496 vty_out(vty, " Threshold for warning message %d%%",
12497 p->pmax_threshold[afi][safi]);
12498 if (p->pmax_restart[afi][safi])
12499 vty_out(vty, ", restart interval %d min",
12500 p->pmax_restart[afi][safi]);
12501 vty_out(vty, "\n");
12502 }
12503
12504 vty_out(vty, "\n");
12505 }
12506 }
12507
12508 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12509 json_object *json)
12510 {
12511 struct bgp *bgp;
12512 char buf1[PREFIX2STR_BUFFER];
12513 char timebuf[BGP_UPTIME_LEN];
12514 char dn_flag[2];
12515 afi_t afi;
12516 safi_t safi;
12517 uint16_t i;
12518 uint8_t *msg;
12519 json_object *json_neigh = NULL;
12520 time_t epoch_tbuf;
12521 uint32_t sync_tcp_mss;
12522
12523 bgp = p->bgp;
12524
12525 if (use_json)
12526 json_neigh = json_object_new_object();
12527
12528 memset(dn_flag, '\0', sizeof(dn_flag));
12529 if (!p->conf_if && peer_dynamic_neighbor(p))
12530 dn_flag[0] = '*';
12531
12532 if (!use_json) {
12533 if (p->conf_if) /* Configured interface name. */
12534 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12535 &p->su);
12536 else /* Configured IP address. */
12537 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12538 p->host);
12539 }
12540
12541 if (use_json) {
12542 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12543 json_object_string_add(json_neigh, "bgpNeighborAddr",
12544 "none");
12545 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12546 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12547 "%pSU", &p->su);
12548
12549 json_object_int_add(json_neigh, "remoteAs", p->as);
12550
12551 if (p->change_local_as)
12552 json_object_int_add(json_neigh, "localAs",
12553 p->change_local_as);
12554 else
12555 json_object_int_add(json_neigh, "localAs", p->local_as);
12556
12557 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12558 json_object_boolean_true_add(json_neigh,
12559 "localAsNoPrepend");
12560
12561 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12562 json_object_boolean_true_add(json_neigh,
12563 "localAsReplaceAs");
12564 } else {
12565 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12566 || (p->as_type == AS_INTERNAL))
12567 vty_out(vty, "remote AS %u, ", p->as);
12568 else
12569 vty_out(vty, "remote AS Unspecified, ");
12570 vty_out(vty, "local AS %u%s%s, ",
12571 p->change_local_as ? p->change_local_as : p->local_as,
12572 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12573 ? " no-prepend"
12574 : "",
12575 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12576 ? " replace-as"
12577 : "");
12578 }
12579 /* peer type internal or confed-internal */
12580 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12581 if (use_json) {
12582 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12583 json_object_boolean_true_add(
12584 json_neigh, "nbrConfedInternalLink");
12585 else
12586 json_object_boolean_true_add(json_neigh,
12587 "nbrInternalLink");
12588 } else {
12589 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12590 vty_out(vty, "confed-internal link\n");
12591 else
12592 vty_out(vty, "internal link\n");
12593 }
12594 /* peer type external or confed-external */
12595 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12596 if (use_json) {
12597 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12598 json_object_boolean_true_add(
12599 json_neigh, "nbrConfedExternalLink");
12600 else
12601 json_object_boolean_true_add(json_neigh,
12602 "nbrExternalLink");
12603 } else {
12604 if (bgp_confederation_peers_check(bgp, p->as))
12605 vty_out(vty, "confed-external link\n");
12606 else
12607 vty_out(vty, "external link\n");
12608 }
12609 } else {
12610 if (use_json)
12611 json_object_boolean_true_add(json_neigh,
12612 "nbrUnspecifiedLink");
12613 else
12614 vty_out(vty, "unspecified link\n");
12615 }
12616
12617 /* Roles */
12618 if (use_json) {
12619 json_object_string_add(json_neigh, "localRole",
12620 bgp_get_name_by_role(p->local_role));
12621 json_object_string_add(json_neigh, "remoteRole",
12622 bgp_get_name_by_role(p->remote_role));
12623 } else {
12624 vty_out(vty, " Local Role: %s\n",
12625 bgp_get_name_by_role(p->local_role));
12626 vty_out(vty, " Remote Role: %s\n",
12627 bgp_get_name_by_role(p->remote_role));
12628 }
12629
12630
12631 /* Description. */
12632 if (p->desc) {
12633 if (use_json)
12634 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12635 else
12636 vty_out(vty, " Description: %s\n", p->desc);
12637 }
12638
12639 if (p->hostname) {
12640 if (use_json) {
12641 if (p->hostname)
12642 json_object_string_add(json_neigh, "hostname",
12643 p->hostname);
12644
12645 if (p->domainname)
12646 json_object_string_add(json_neigh, "domainname",
12647 p->domainname);
12648 } else {
12649 if (p->domainname && (p->domainname[0] != '\0'))
12650 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12651 p->domainname);
12652 else
12653 vty_out(vty, "Hostname: %s\n", p->hostname);
12654 }
12655 }
12656
12657 /* Peer-group */
12658 if (p->group) {
12659 if (use_json) {
12660 json_object_string_add(json_neigh, "peerGroup",
12661 p->group->name);
12662
12663 if (dn_flag[0]) {
12664 struct prefix prefix, *range = NULL;
12665
12666 if (sockunion2hostprefix(&(p->su), &prefix))
12667 range = peer_group_lookup_dynamic_neighbor_range(
12668 p->group, &prefix);
12669
12670 if (range) {
12671 json_object_string_addf(
12672 json_neigh,
12673 "peerSubnetRangeGroup", "%pFX",
12674 range);
12675 }
12676 }
12677 } else {
12678 vty_out(vty,
12679 " Member of peer-group %s for session parameters\n",
12680 p->group->name);
12681
12682 if (dn_flag[0]) {
12683 struct prefix prefix, *range = NULL;
12684
12685 if (sockunion2hostprefix(&(p->su), &prefix))
12686 range = peer_group_lookup_dynamic_neighbor_range(
12687 p->group, &prefix);
12688
12689 if (range) {
12690 vty_out(vty,
12691 " Belongs to the subnet range group: %pFX\n",
12692 range);
12693 }
12694 }
12695 }
12696 }
12697
12698 if (use_json) {
12699 /* Administrative shutdown. */
12700 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12701 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12702 json_object_boolean_true_add(json_neigh,
12703 "adminShutDown");
12704
12705 /* BGP Version. */
12706 json_object_int_add(json_neigh, "bgpVersion", 4);
12707 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12708 &p->remote_id);
12709 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12710 &bgp->router_id);
12711
12712 /* Confederation */
12713 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12714 && bgp_confederation_peers_check(bgp, p->as))
12715 json_object_boolean_true_add(json_neigh,
12716 "nbrCommonAdmin");
12717
12718 /* Status. */
12719 json_object_string_add(
12720 json_neigh, "bgpState",
12721 lookup_msg(bgp_status_msg, p->status, NULL));
12722
12723 if (peer_established(p)) {
12724 time_t uptime;
12725
12726 uptime = bgp_clock();
12727 uptime -= p->uptime;
12728 epoch_tbuf = time(NULL) - uptime;
12729
12730 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12731 uptime * 1000);
12732 json_object_string_add(json_neigh, "bgpTimerUpString",
12733 peer_uptime(p->uptime, timebuf,
12734 BGP_UPTIME_LEN, 0,
12735 NULL));
12736 json_object_int_add(json_neigh,
12737 "bgpTimerUpEstablishedEpoch",
12738 epoch_tbuf);
12739 }
12740
12741 else if (p->status == Active) {
12742 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12743 json_object_string_add(json_neigh, "bgpStateIs",
12744 "passive");
12745 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12746 json_object_string_add(json_neigh, "bgpStateIs",
12747 "passiveNSF");
12748 }
12749
12750 /* read timer */
12751 time_t uptime;
12752 struct tm tm;
12753
12754 uptime = bgp_clock();
12755 uptime -= p->readtime;
12756 gmtime_r(&uptime, &tm);
12757
12758 json_object_int_add(json_neigh, "bgpTimerLastRead",
12759 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12760 + (tm.tm_hour * 3600000));
12761
12762 uptime = bgp_clock();
12763 uptime -= p->last_write;
12764 gmtime_r(&uptime, &tm);
12765
12766 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12767 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12768 + (tm.tm_hour * 3600000));
12769
12770 uptime = bgp_clock();
12771 uptime -= p->update_time;
12772 gmtime_r(&uptime, &tm);
12773
12774 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12775 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12776 + (tm.tm_hour * 3600000));
12777
12778 /* Configured timer values. */
12779 json_object_int_add(json_neigh,
12780 "bgpTimerConfiguredHoldTimeMsecs",
12781 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12782 ? p->holdtime * 1000
12783 : bgp->default_holdtime * 1000);
12784 json_object_int_add(json_neigh,
12785 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12786 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12787 ? p->keepalive * 1000
12788 : bgp->default_keepalive * 1000);
12789 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12790 p->v_holdtime * 1000);
12791 json_object_int_add(json_neigh,
12792 "bgpTimerKeepAliveIntervalMsecs",
12793 p->v_keepalive * 1000);
12794 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12795 json_object_int_add(json_neigh,
12796 "bgpTimerDelayOpenTimeMsecs",
12797 p->v_delayopen * 1000);
12798 }
12799
12800 /* Configured and Synced tcp-mss value for peer */
12801 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12802 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12803 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12804 p->tcp_mss);
12805 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12806 sync_tcp_mss);
12807 }
12808
12809 /* Extended Optional Parameters Length for BGP OPEN Message */
12810 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12811 json_object_boolean_true_add(
12812 json_neigh, "extendedOptionalParametersLength");
12813 else
12814 json_object_boolean_false_add(
12815 json_neigh, "extendedOptionalParametersLength");
12816
12817 /* Conditional advertisements */
12818 json_object_int_add(
12819 json_neigh,
12820 "bgpTimerConfiguredConditionalAdvertisementsSec",
12821 bgp->condition_check_period);
12822 if (thread_is_scheduled(bgp->t_condition_check))
12823 json_object_int_add(
12824 json_neigh,
12825 "bgpTimerUntilConditionalAdvertisementsSec",
12826 thread_timer_remain_second(
12827 bgp->t_condition_check));
12828 } else {
12829 /* Administrative shutdown. */
12830 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12831 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12832 vty_out(vty, " Administratively shut down\n");
12833
12834 /* BGP Version. */
12835 vty_out(vty, " BGP version 4");
12836 vty_out(vty, ", remote router ID %s",
12837 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12838 vty_out(vty, ", local router ID %s\n",
12839 inet_ntop(AF_INET, &bgp->router_id, buf1,
12840 sizeof(buf1)));
12841
12842 /* Confederation */
12843 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12844 && bgp_confederation_peers_check(bgp, p->as))
12845 vty_out(vty,
12846 " Neighbor under common administration\n");
12847
12848 /* Status. */
12849 vty_out(vty, " BGP state = %s",
12850 lookup_msg(bgp_status_msg, p->status, NULL));
12851
12852 if (peer_established(p))
12853 vty_out(vty, ", up for %8s",
12854 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12855 0, NULL));
12856
12857 else if (p->status == Active) {
12858 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12859 vty_out(vty, " (passive)");
12860 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12861 vty_out(vty, " (NSF passive)");
12862 }
12863 vty_out(vty, "\n");
12864
12865 /* read timer */
12866 vty_out(vty, " Last read %s",
12867 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12868 NULL));
12869 vty_out(vty, ", Last write %s\n",
12870 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12871 NULL));
12872
12873 /* Configured timer values. */
12874 vty_out(vty,
12875 " Hold time is %d seconds, keepalive interval is %d seconds\n",
12876 p->v_holdtime, p->v_keepalive);
12877 vty_out(vty, " Configured hold time is %d seconds",
12878 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12879 ? p->holdtime
12880 : bgp->default_holdtime);
12881 vty_out(vty, ", keepalive interval is %d seconds\n",
12882 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12883 ? p->keepalive
12884 : bgp->default_keepalive);
12885 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12886 vty_out(vty,
12887 " Configured DelayOpenTime is %d seconds\n",
12888 p->delayopen);
12889
12890 /* Configured and synced tcp-mss value for peer */
12891 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12892 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12893 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12894 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12895 }
12896
12897 /* Extended Optional Parameters Length for BGP OPEN Message */
12898 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12899 vty_out(vty,
12900 " Extended Optional Parameters Length is enabled\n");
12901
12902 /* Conditional advertisements */
12903 vty_out(vty,
12904 " Configured conditional advertisements interval is %d seconds\n",
12905 bgp->condition_check_period);
12906 if (thread_is_scheduled(bgp->t_condition_check))
12907 vty_out(vty,
12908 " Time until conditional advertisements begin is %lu seconds\n",
12909 thread_timer_remain_second(
12910 bgp->t_condition_check));
12911 }
12912 /* Capability. */
12913 if (peer_established(p) &&
12914 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12915 if (use_json) {
12916 json_object *json_cap = NULL;
12917
12918 json_cap = json_object_new_object();
12919
12920 /* AS4 */
12921 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12922 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12923 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12924 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12925 json_object_string_add(
12926 json_cap, "4byteAs",
12927 "advertisedAndReceived");
12928 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12929 json_object_string_add(json_cap,
12930 "4byteAs",
12931 "advertised");
12932 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12933 json_object_string_add(json_cap,
12934 "4byteAs",
12935 "received");
12936 }
12937
12938 /* Extended Message Support */
12939 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12940 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12941 json_object_string_add(json_cap,
12942 "extendedMessage",
12943 "advertisedAndReceived");
12944 else if (CHECK_FLAG(p->cap,
12945 PEER_CAP_EXTENDED_MESSAGE_ADV))
12946 json_object_string_add(json_cap,
12947 "extendedMessage",
12948 "advertised");
12949 else if (CHECK_FLAG(p->cap,
12950 PEER_CAP_EXTENDED_MESSAGE_RCV))
12951 json_object_string_add(json_cap,
12952 "extendedMessage",
12953 "received");
12954
12955 /* AddPath */
12956 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12957 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12958 json_object *json_add = NULL;
12959 const char *print_store;
12960
12961 json_add = json_object_new_object();
12962
12963 FOREACH_AFI_SAFI (afi, safi) {
12964 json_object *json_sub = NULL;
12965 json_sub = json_object_new_object();
12966 print_store = get_afi_safi_str(
12967 afi, safi, true);
12968
12969 if (CHECK_FLAG(
12970 p->af_cap[afi][safi],
12971 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12972 CHECK_FLAG(
12973 p->af_cap[afi][safi],
12974 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12975 if (CHECK_FLAG(
12976 p->af_cap[afi]
12977 [safi],
12978 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12979 CHECK_FLAG(
12980 p->af_cap[afi]
12981 [safi],
12982 PEER_CAP_ADDPATH_AF_TX_RCV))
12983 json_object_boolean_true_add(
12984 json_sub,
12985 "txAdvertisedAndReceived");
12986 else if (
12987 CHECK_FLAG(
12988 p->af_cap[afi]
12989 [safi],
12990 PEER_CAP_ADDPATH_AF_TX_ADV))
12991 json_object_boolean_true_add(
12992 json_sub,
12993 "txAdvertised");
12994 else if (
12995 CHECK_FLAG(
12996 p->af_cap[afi]
12997 [safi],
12998 PEER_CAP_ADDPATH_AF_TX_RCV))
12999 json_object_boolean_true_add(
13000 json_sub,
13001 "txReceived");
13002 }
13003
13004 if (CHECK_FLAG(
13005 p->af_cap[afi][safi],
13006 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13007 CHECK_FLAG(
13008 p->af_cap[afi][safi],
13009 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13010 if (CHECK_FLAG(
13011 p->af_cap[afi]
13012 [safi],
13013 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13014 CHECK_FLAG(
13015 p->af_cap[afi]
13016 [safi],
13017 PEER_CAP_ADDPATH_AF_RX_RCV))
13018 json_object_boolean_true_add(
13019 json_sub,
13020 "rxAdvertisedAndReceived");
13021 else if (
13022 CHECK_FLAG(
13023 p->af_cap[afi]
13024 [safi],
13025 PEER_CAP_ADDPATH_AF_RX_ADV))
13026 json_object_boolean_true_add(
13027 json_sub,
13028 "rxAdvertised");
13029 else if (
13030 CHECK_FLAG(
13031 p->af_cap[afi]
13032 [safi],
13033 PEER_CAP_ADDPATH_AF_RX_RCV))
13034 json_object_boolean_true_add(
13035 json_sub,
13036 "rxReceived");
13037 }
13038
13039 if (CHECK_FLAG(
13040 p->af_cap[afi][safi],
13041 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13042 CHECK_FLAG(
13043 p->af_cap[afi][safi],
13044 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13045 CHECK_FLAG(
13046 p->af_cap[afi][safi],
13047 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13048 CHECK_FLAG(
13049 p->af_cap[afi][safi],
13050 PEER_CAP_ADDPATH_AF_RX_RCV))
13051 json_object_object_add(
13052 json_add, print_store,
13053 json_sub);
13054 else
13055 json_object_free(json_sub);
13056 }
13057
13058 json_object_object_add(json_cap, "addPath",
13059 json_add);
13060 }
13061
13062 /* Dynamic */
13063 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13064 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13065 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13066 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13067 json_object_string_add(
13068 json_cap, "dynamic",
13069 "advertisedAndReceived");
13070 else if (CHECK_FLAG(p->cap,
13071 PEER_CAP_DYNAMIC_ADV))
13072 json_object_string_add(json_cap,
13073 "dynamic",
13074 "advertised");
13075 else if (CHECK_FLAG(p->cap,
13076 PEER_CAP_DYNAMIC_RCV))
13077 json_object_string_add(json_cap,
13078 "dynamic",
13079 "received");
13080 }
13081
13082 /* Role */
13083 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13084 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13085 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13086 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13087 json_object_string_add(
13088 json_cap, "role",
13089 "advertisedAndReceived");
13090 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13091 json_object_string_add(json_cap, "role",
13092 "advertised");
13093 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13094 json_object_string_add(json_cap, "role",
13095 "received");
13096 }
13097
13098 /* Extended nexthop */
13099 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13100 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13101 json_object *json_nxt = NULL;
13102 const char *print_store;
13103
13104
13105 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13106 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13107 json_object_string_add(
13108 json_cap, "extendedNexthop",
13109 "advertisedAndReceived");
13110 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13111 json_object_string_add(
13112 json_cap, "extendedNexthop",
13113 "advertised");
13114 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13115 json_object_string_add(
13116 json_cap, "extendedNexthop",
13117 "received");
13118
13119 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13120 json_nxt = json_object_new_object();
13121
13122 for (safi = SAFI_UNICAST;
13123 safi < SAFI_MAX; safi++) {
13124 if (CHECK_FLAG(
13125 p->af_cap[AFI_IP]
13126 [safi],
13127 PEER_CAP_ENHE_AF_RCV)) {
13128 print_store =
13129 get_afi_safi_str(
13130 AFI_IP,
13131 safi,
13132 true);
13133 json_object_string_add(
13134 json_nxt,
13135 print_store,
13136 "recieved"); /* misspelled for compatibility */
13137 }
13138 }
13139 json_object_object_add(
13140 json_cap,
13141 "extendedNexthopFamililesByPeer",
13142 json_nxt);
13143 }
13144 }
13145
13146 /* Long-lived Graceful Restart */
13147 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13148 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13149 json_object *json_llgr = NULL;
13150 const char *afi_safi_str;
13151
13152 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13153 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13154 json_object_string_add(
13155 json_cap,
13156 "longLivedGracefulRestart",
13157 "advertisedAndReceived");
13158 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13159 json_object_string_add(
13160 json_cap,
13161 "longLivedGracefulRestart",
13162 "advertised");
13163 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13164 json_object_string_add(
13165 json_cap,
13166 "longLivedGracefulRestart",
13167 "received");
13168
13169 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13170 json_llgr = json_object_new_object();
13171
13172 FOREACH_AFI_SAFI (afi, safi) {
13173 if (CHECK_FLAG(
13174 p->af_cap[afi]
13175 [safi],
13176 PEER_CAP_ENHE_AF_RCV)) {
13177 afi_safi_str =
13178 get_afi_safi_str(
13179 afi,
13180 safi,
13181 true);
13182 json_object_string_add(
13183 json_llgr,
13184 afi_safi_str,
13185 "received");
13186 }
13187 }
13188 json_object_object_add(
13189 json_cap,
13190 "longLivedGracefulRestartByPeer",
13191 json_llgr);
13192 }
13193 }
13194
13195 /* Route Refresh */
13196 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13197 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13198 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13199 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13200 (CHECK_FLAG(p->cap,
13201 PEER_CAP_REFRESH_NEW_RCV) ||
13202 CHECK_FLAG(p->cap,
13203 PEER_CAP_REFRESH_OLD_RCV))) {
13204 if (CHECK_FLAG(
13205 p->cap,
13206 PEER_CAP_REFRESH_OLD_RCV) &&
13207 CHECK_FLAG(
13208 p->cap,
13209 PEER_CAP_REFRESH_NEW_RCV))
13210 json_object_string_add(
13211 json_cap,
13212 "routeRefresh",
13213 "advertisedAndReceivedOldNew");
13214 else {
13215 if (CHECK_FLAG(
13216 p->cap,
13217 PEER_CAP_REFRESH_OLD_RCV))
13218 json_object_string_add(
13219 json_cap,
13220 "routeRefresh",
13221 "advertisedAndReceivedOld");
13222 else
13223 json_object_string_add(
13224 json_cap,
13225 "routeRefresh",
13226 "advertisedAndReceivedNew");
13227 }
13228 } else if (CHECK_FLAG(p->cap,
13229 PEER_CAP_REFRESH_ADV))
13230 json_object_string_add(json_cap,
13231 "routeRefresh",
13232 "advertised");
13233 else if (CHECK_FLAG(p->cap,
13234 PEER_CAP_REFRESH_NEW_RCV) ||
13235 CHECK_FLAG(p->cap,
13236 PEER_CAP_REFRESH_OLD_RCV))
13237 json_object_string_add(json_cap,
13238 "routeRefresh",
13239 "received");
13240 }
13241
13242 /* Enhanced Route Refresh */
13243 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13244 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13245 if (CHECK_FLAG(p->cap,
13246 PEER_CAP_ENHANCED_RR_ADV) &&
13247 CHECK_FLAG(p->cap,
13248 PEER_CAP_ENHANCED_RR_RCV))
13249 json_object_string_add(
13250 json_cap,
13251 "enhancedRouteRefresh",
13252 "advertisedAndReceived");
13253 else if (CHECK_FLAG(p->cap,
13254 PEER_CAP_ENHANCED_RR_ADV))
13255 json_object_string_add(
13256 json_cap,
13257 "enhancedRouteRefresh",
13258 "advertised");
13259 else if (CHECK_FLAG(p->cap,
13260 PEER_CAP_ENHANCED_RR_RCV))
13261 json_object_string_add(
13262 json_cap,
13263 "enhancedRouteRefresh",
13264 "received");
13265 }
13266
13267 /* Multiprotocol Extensions */
13268 json_object *json_multi = NULL;
13269
13270 json_multi = json_object_new_object();
13271
13272 FOREACH_AFI_SAFI (afi, safi) {
13273 if (p->afc_adv[afi][safi] ||
13274 p->afc_recv[afi][safi]) {
13275 json_object *json_exten = NULL;
13276 json_exten = json_object_new_object();
13277
13278 if (p->afc_adv[afi][safi] &&
13279 p->afc_recv[afi][safi])
13280 json_object_boolean_true_add(
13281 json_exten,
13282 "advertisedAndReceived");
13283 else if (p->afc_adv[afi][safi])
13284 json_object_boolean_true_add(
13285 json_exten,
13286 "advertised");
13287 else if (p->afc_recv[afi][safi])
13288 json_object_boolean_true_add(
13289 json_exten, "received");
13290
13291 json_object_object_add(
13292 json_multi,
13293 get_afi_safi_str(afi, safi,
13294 true),
13295 json_exten);
13296 }
13297 }
13298 json_object_object_add(json_cap,
13299 "multiprotocolExtensions",
13300 json_multi);
13301
13302 /* Hostname capabilities */
13303 json_object *json_hname = NULL;
13304
13305 json_hname = json_object_new_object();
13306
13307 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13308 json_object_string_add(
13309 json_hname, "advHostName",
13310 bgp->peer_self->hostname
13311 ? bgp->peer_self->hostname
13312 : "n/a");
13313 json_object_string_add(
13314 json_hname, "advDomainName",
13315 bgp->peer_self->domainname
13316 ? bgp->peer_self->domainname
13317 : "n/a");
13318 }
13319
13320
13321 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13322 json_object_string_add(
13323 json_hname, "rcvHostName",
13324 p->hostname ? p->hostname : "n/a");
13325 json_object_string_add(
13326 json_hname, "rcvDomainName",
13327 p->domainname ? p->domainname : "n/a");
13328 }
13329
13330 json_object_object_add(json_cap, "hostName",
13331 json_hname);
13332
13333 /* Graceful Restart */
13334 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13335 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13336 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13337 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13338 json_object_string_add(
13339 json_cap, "gracefulRestart",
13340 "advertisedAndReceived");
13341 else if (CHECK_FLAG(p->cap,
13342 PEER_CAP_RESTART_ADV))
13343 json_object_string_add(
13344 json_cap,
13345 "gracefulRestartCapability",
13346 "advertised");
13347 else if (CHECK_FLAG(p->cap,
13348 PEER_CAP_RESTART_RCV))
13349 json_object_string_add(
13350 json_cap,
13351 "gracefulRestartCapability",
13352 "received");
13353
13354 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13355 int restart_af_count = 0;
13356 json_object *json_restart = NULL;
13357 json_restart = json_object_new_object();
13358
13359 json_object_int_add(
13360 json_cap,
13361 "gracefulRestartRemoteTimerMsecs",
13362 p->v_gr_restart * 1000);
13363
13364 FOREACH_AFI_SAFI (afi, safi) {
13365 if (CHECK_FLAG(
13366 p->af_cap[afi]
13367 [safi],
13368 PEER_CAP_RESTART_AF_RCV)) {
13369 json_object *json_sub =
13370 NULL;
13371 json_sub =
13372 json_object_new_object();
13373
13374 if (CHECK_FLAG(
13375 p->af_cap
13376 [afi]
13377 [safi],
13378 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13379 json_object_boolean_true_add(
13380 json_sub,
13381 "preserved");
13382 restart_af_count++;
13383 json_object_object_add(
13384 json_restart,
13385 get_afi_safi_str(
13386 afi,
13387 safi,
13388 true),
13389 json_sub);
13390 }
13391 }
13392 if (!restart_af_count) {
13393 json_object_string_add(
13394 json_cap,
13395 "addressFamiliesByPeer",
13396 "none");
13397 json_object_free(json_restart);
13398 } else
13399 json_object_object_add(
13400 json_cap,
13401 "addressFamiliesByPeer",
13402 json_restart);
13403 }
13404 }
13405 json_object_object_add(
13406 json_neigh, "neighborCapabilities", json_cap);
13407 } else {
13408 vty_out(vty, " Neighbor capabilities:\n");
13409
13410 /* AS4 */
13411 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13412 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13413 vty_out(vty, " 4 Byte AS:");
13414 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13415 vty_out(vty, " advertised");
13416 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13417 vty_out(vty, " %sreceived",
13418 CHECK_FLAG(p->cap,
13419 PEER_CAP_AS4_ADV)
13420 ? "and "
13421 : "");
13422 vty_out(vty, "\n");
13423 }
13424
13425 /* Extended Message Support */
13426 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13427 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13428 vty_out(vty, " Extended Message:");
13429 if (CHECK_FLAG(p->cap,
13430 PEER_CAP_EXTENDED_MESSAGE_ADV))
13431 vty_out(vty, " advertised");
13432 if (CHECK_FLAG(p->cap,
13433 PEER_CAP_EXTENDED_MESSAGE_RCV))
13434 vty_out(vty, " %sreceived",
13435 CHECK_FLAG(
13436 p->cap,
13437 PEER_CAP_EXTENDED_MESSAGE_ADV)
13438 ? "and "
13439 : "");
13440 vty_out(vty, "\n");
13441 }
13442
13443 /* AddPath */
13444 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13445 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13446 vty_out(vty, " AddPath:\n");
13447
13448 FOREACH_AFI_SAFI (afi, safi) {
13449 if (CHECK_FLAG(
13450 p->af_cap[afi][safi],
13451 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13452 CHECK_FLAG(
13453 p->af_cap[afi][safi],
13454 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13455 vty_out(vty, " %s: TX ",
13456 get_afi_safi_str(
13457 afi, safi,
13458 false));
13459
13460 if (CHECK_FLAG(
13461 p->af_cap[afi]
13462 [safi],
13463 PEER_CAP_ADDPATH_AF_TX_ADV))
13464 vty_out(vty,
13465 "advertised");
13466
13467 if (CHECK_FLAG(
13468 p->af_cap[afi]
13469 [safi],
13470 PEER_CAP_ADDPATH_AF_TX_RCV))
13471 vty_out(vty,
13472 "%sreceived",
13473 CHECK_FLAG(
13474 p->af_cap
13475 [afi]
13476 [safi],
13477 PEER_CAP_ADDPATH_AF_TX_ADV)
13478 ? " and "
13479 : "");
13480
13481 vty_out(vty, "\n");
13482 }
13483
13484 if (CHECK_FLAG(
13485 p->af_cap[afi][safi],
13486 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13487 CHECK_FLAG(
13488 p->af_cap[afi][safi],
13489 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13490 vty_out(vty, " %s: RX ",
13491 get_afi_safi_str(
13492 afi, safi,
13493 false));
13494
13495 if (CHECK_FLAG(
13496 p->af_cap[afi]
13497 [safi],
13498 PEER_CAP_ADDPATH_AF_RX_ADV))
13499 vty_out(vty,
13500 "advertised");
13501
13502 if (CHECK_FLAG(
13503 p->af_cap[afi]
13504 [safi],
13505 PEER_CAP_ADDPATH_AF_RX_RCV))
13506 vty_out(vty,
13507 "%sreceived",
13508 CHECK_FLAG(
13509 p->af_cap
13510 [afi]
13511 [safi],
13512 PEER_CAP_ADDPATH_AF_RX_ADV)
13513 ? " and "
13514 : "");
13515
13516 vty_out(vty, "\n");
13517 }
13518 }
13519 }
13520
13521 /* Dynamic */
13522 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13523 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13524 vty_out(vty, " Dynamic:");
13525 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13526 vty_out(vty, " advertised");
13527 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13528 vty_out(vty, " %sreceived",
13529 CHECK_FLAG(p->cap,
13530 PEER_CAP_DYNAMIC_ADV)
13531 ? "and "
13532 : "");
13533 vty_out(vty, "\n");
13534 }
13535
13536 /* Role */
13537 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13538 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13539 vty_out(vty, " Role:");
13540 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13541 vty_out(vty, " advertised");
13542 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13543 vty_out(vty, " %sreceived",
13544 CHECK_FLAG(p->cap,
13545 PEER_CAP_ROLE_ADV)
13546 ? "and "
13547 : "");
13548 vty_out(vty, "\n");
13549 }
13550
13551 /* Extended nexthop */
13552 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13553 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13554 vty_out(vty, " Extended nexthop:");
13555 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13556 vty_out(vty, " advertised");
13557 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13558 vty_out(vty, " %sreceived",
13559 CHECK_FLAG(p->cap,
13560 PEER_CAP_ENHE_ADV)
13561 ? "and "
13562 : "");
13563 vty_out(vty, "\n");
13564
13565 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13566 vty_out(vty,
13567 " Address families by peer:\n ");
13568 for (safi = SAFI_UNICAST;
13569 safi < SAFI_MAX; safi++)
13570 if (CHECK_FLAG(
13571 p->af_cap[AFI_IP]
13572 [safi],
13573 PEER_CAP_ENHE_AF_RCV))
13574 vty_out(vty,
13575 " %s\n",
13576 get_afi_safi_str(
13577 AFI_IP,
13578 safi,
13579 false));
13580 }
13581 }
13582
13583 /* Long-lived Graceful Restart */
13584 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13585 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13586 vty_out(vty,
13587 " Long-lived Graceful Restart:");
13588 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13589 vty_out(vty, " advertised");
13590 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13591 vty_out(vty, " %sreceived",
13592 CHECK_FLAG(p->cap,
13593 PEER_CAP_LLGR_ADV)
13594 ? "and "
13595 : "");
13596 vty_out(vty, "\n");
13597
13598 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13599 vty_out(vty,
13600 " Address families by peer:\n");
13601 FOREACH_AFI_SAFI (afi, safi)
13602 if (CHECK_FLAG(
13603 p->af_cap[afi]
13604 [safi],
13605 PEER_CAP_LLGR_AF_RCV))
13606 vty_out(vty,
13607 " %s\n",
13608 get_afi_safi_str(
13609 afi,
13610 safi,
13611 false));
13612 }
13613 }
13614
13615 /* Route Refresh */
13616 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13617 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13618 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13619 vty_out(vty, " Route refresh:");
13620 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13621 vty_out(vty, " advertised");
13622 if (CHECK_FLAG(p->cap,
13623 PEER_CAP_REFRESH_NEW_RCV) ||
13624 CHECK_FLAG(p->cap,
13625 PEER_CAP_REFRESH_OLD_RCV))
13626 vty_out(vty, " %sreceived(%s)",
13627 CHECK_FLAG(p->cap,
13628 PEER_CAP_REFRESH_ADV)
13629 ? "and "
13630 : "",
13631 (CHECK_FLAG(
13632 p->cap,
13633 PEER_CAP_REFRESH_OLD_RCV) &&
13634 CHECK_FLAG(
13635 p->cap,
13636 PEER_CAP_REFRESH_NEW_RCV))
13637 ? "old & new"
13638 : CHECK_FLAG(
13639 p->cap,
13640 PEER_CAP_REFRESH_OLD_RCV)
13641 ? "old"
13642 : "new");
13643
13644 vty_out(vty, "\n");
13645 }
13646
13647 /* Enhanced Route Refresh */
13648 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13649 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13650 vty_out(vty, " Enhanced Route Refresh:");
13651 if (CHECK_FLAG(p->cap,
13652 PEER_CAP_ENHANCED_RR_ADV))
13653 vty_out(vty, " advertised");
13654 if (CHECK_FLAG(p->cap,
13655 PEER_CAP_ENHANCED_RR_RCV))
13656 vty_out(vty, " %sreceived",
13657 CHECK_FLAG(p->cap,
13658 PEER_CAP_REFRESH_ADV)
13659 ? "and "
13660 : "");
13661 vty_out(vty, "\n");
13662 }
13663
13664 /* Multiprotocol Extensions */
13665 FOREACH_AFI_SAFI (afi, safi)
13666 if (p->afc_adv[afi][safi] ||
13667 p->afc_recv[afi][safi]) {
13668 vty_out(vty, " Address Family %s:",
13669 get_afi_safi_str(afi, safi,
13670 false));
13671 if (p->afc_adv[afi][safi])
13672 vty_out(vty, " advertised");
13673 if (p->afc_recv[afi][safi])
13674 vty_out(vty, " %sreceived",
13675 p->afc_adv[afi][safi]
13676 ? "and "
13677 : "");
13678 vty_out(vty, "\n");
13679 }
13680
13681 /* Hostname capability */
13682 vty_out(vty, " Hostname Capability:");
13683
13684 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13685 vty_out(vty,
13686 " advertised (name: %s,domain name: %s)",
13687 bgp->peer_self->hostname
13688 ? bgp->peer_self->hostname
13689 : "n/a",
13690 bgp->peer_self->domainname
13691 ? bgp->peer_self->domainname
13692 : "n/a");
13693 } else {
13694 vty_out(vty, " not advertised");
13695 }
13696
13697 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13698 vty_out(vty,
13699 " received (name: %s,domain name: %s)",
13700 p->hostname ? p->hostname : "n/a",
13701 p->domainname ? p->domainname : "n/a");
13702 } else {
13703 vty_out(vty, " not received");
13704 }
13705
13706 vty_out(vty, "\n");
13707
13708 /* Graceful Restart */
13709 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13710 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13711 vty_out(vty,
13712 " Graceful Restart Capability:");
13713 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13714 vty_out(vty, " advertised");
13715 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13716 vty_out(vty, " %sreceived",
13717 CHECK_FLAG(p->cap,
13718 PEER_CAP_RESTART_ADV)
13719 ? "and "
13720 : "");
13721 vty_out(vty, "\n");
13722
13723 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13724 int restart_af_count = 0;
13725
13726 vty_out(vty,
13727 " Remote Restart timer is %d seconds\n",
13728 p->v_gr_restart);
13729 vty_out(vty,
13730 " Address families by peer:\n ");
13731
13732 FOREACH_AFI_SAFI (afi, safi)
13733 if (CHECK_FLAG(
13734 p->af_cap[afi]
13735 [safi],
13736 PEER_CAP_RESTART_AF_RCV)) {
13737 vty_out(vty, "%s%s(%s)",
13738 restart_af_count
13739 ? ", "
13740 : "",
13741 get_afi_safi_str(
13742 afi,
13743 safi,
13744 false),
13745 CHECK_FLAG(
13746 p->af_cap
13747 [afi]
13748 [safi],
13749 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13750 ? "preserved"
13751 : "not preserved");
13752 restart_af_count++;
13753 }
13754 if (!restart_af_count)
13755 vty_out(vty, "none");
13756 vty_out(vty, "\n");
13757 }
13758 } /* Graceful Restart */
13759 }
13760 }
13761
13762 /* graceful restart information */
13763 json_object *json_grace = NULL;
13764 json_object *json_grace_send = NULL;
13765 json_object *json_grace_recv = NULL;
13766 int eor_send_af_count = 0;
13767 int eor_receive_af_count = 0;
13768
13769 if (use_json) {
13770 json_grace = json_object_new_object();
13771 json_grace_send = json_object_new_object();
13772 json_grace_recv = json_object_new_object();
13773
13774 if ((peer_established(p)) &&
13775 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13776 FOREACH_AFI_SAFI (afi, safi) {
13777 if (CHECK_FLAG(p->af_sflags[afi][safi],
13778 PEER_STATUS_EOR_SEND)) {
13779 json_object_boolean_true_add(
13780 json_grace_send,
13781 get_afi_safi_str(afi, safi,
13782 true));
13783 eor_send_af_count++;
13784 }
13785 }
13786 FOREACH_AFI_SAFI (afi, safi) {
13787 if (CHECK_FLAG(p->af_sflags[afi][safi],
13788 PEER_STATUS_EOR_RECEIVED)) {
13789 json_object_boolean_true_add(
13790 json_grace_recv,
13791 get_afi_safi_str(afi, safi,
13792 true));
13793 eor_receive_af_count++;
13794 }
13795 }
13796 }
13797 json_object_object_add(json_grace, "endOfRibSend",
13798 json_grace_send);
13799 json_object_object_add(json_grace, "endOfRibRecv",
13800 json_grace_recv);
13801
13802
13803 if (p->t_gr_restart)
13804 json_object_int_add(
13805 json_grace, "gracefulRestartTimerMsecs",
13806 thread_timer_remain_second(p->t_gr_restart) *
13807 1000);
13808
13809 if (p->t_gr_stale)
13810 json_object_int_add(
13811 json_grace, "gracefulStalepathTimerMsecs",
13812 thread_timer_remain_second(p->t_gr_stale) *
13813 1000);
13814 /* more gr info in new format */
13815 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13816 json_object_object_add(json_neigh, "gracefulRestartInfo",
13817 json_grace);
13818 } else {
13819 vty_out(vty, " Graceful restart information:\n");
13820 if ((peer_established(p)) &&
13821 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13822
13823 vty_out(vty, " End-of-RIB send: ");
13824 FOREACH_AFI_SAFI (afi, safi) {
13825 if (CHECK_FLAG(p->af_sflags[afi][safi],
13826 PEER_STATUS_EOR_SEND)) {
13827 vty_out(vty, "%s%s",
13828 eor_send_af_count ? ", " : "",
13829 get_afi_safi_str(afi, safi,
13830 false));
13831 eor_send_af_count++;
13832 }
13833 }
13834 vty_out(vty, "\n");
13835 vty_out(vty, " End-of-RIB received: ");
13836 FOREACH_AFI_SAFI (afi, safi) {
13837 if (CHECK_FLAG(p->af_sflags[afi][safi],
13838 PEER_STATUS_EOR_RECEIVED)) {
13839 vty_out(vty, "%s%s",
13840 eor_receive_af_count ? ", "
13841 : "",
13842 get_afi_safi_str(afi, safi,
13843 false));
13844 eor_receive_af_count++;
13845 }
13846 }
13847 vty_out(vty, "\n");
13848 }
13849
13850 if (p->t_gr_restart)
13851 vty_out(vty,
13852 " The remaining time of restart timer is %ld\n",
13853 thread_timer_remain_second(p->t_gr_restart));
13854
13855 if (p->t_gr_stale)
13856 vty_out(vty,
13857 " The remaining time of stalepath timer is %ld\n",
13858 thread_timer_remain_second(p->t_gr_stale));
13859
13860 /* more gr info in new format */
13861 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13862 }
13863
13864 if (use_json) {
13865 json_object *json_stat = NULL;
13866 json_stat = json_object_new_object();
13867 /* Packet counts. */
13868
13869 atomic_size_t outq_count, inq_count;
13870 outq_count = atomic_load_explicit(&p->obuf->count,
13871 memory_order_relaxed);
13872 inq_count = atomic_load_explicit(&p->ibuf->count,
13873 memory_order_relaxed);
13874
13875 json_object_int_add(json_stat, "depthInq",
13876 (unsigned long)inq_count);
13877 json_object_int_add(json_stat, "depthOutq",
13878 (unsigned long)outq_count);
13879 json_object_int_add(json_stat, "opensSent",
13880 atomic_load_explicit(&p->open_out,
13881 memory_order_relaxed));
13882 json_object_int_add(json_stat, "opensRecv",
13883 atomic_load_explicit(&p->open_in,
13884 memory_order_relaxed));
13885 json_object_int_add(json_stat, "notificationsSent",
13886 atomic_load_explicit(&p->notify_out,
13887 memory_order_relaxed));
13888 json_object_int_add(json_stat, "notificationsRecv",
13889 atomic_load_explicit(&p->notify_in,
13890 memory_order_relaxed));
13891 json_object_int_add(json_stat, "updatesSent",
13892 atomic_load_explicit(&p->update_out,
13893 memory_order_relaxed));
13894 json_object_int_add(json_stat, "updatesRecv",
13895 atomic_load_explicit(&p->update_in,
13896 memory_order_relaxed));
13897 json_object_int_add(json_stat, "keepalivesSent",
13898 atomic_load_explicit(&p->keepalive_out,
13899 memory_order_relaxed));
13900 json_object_int_add(json_stat, "keepalivesRecv",
13901 atomic_load_explicit(&p->keepalive_in,
13902 memory_order_relaxed));
13903 json_object_int_add(json_stat, "routeRefreshSent",
13904 atomic_load_explicit(&p->refresh_out,
13905 memory_order_relaxed));
13906 json_object_int_add(json_stat, "routeRefreshRecv",
13907 atomic_load_explicit(&p->refresh_in,
13908 memory_order_relaxed));
13909 json_object_int_add(json_stat, "capabilitySent",
13910 atomic_load_explicit(&p->dynamic_cap_out,
13911 memory_order_relaxed));
13912 json_object_int_add(json_stat, "capabilityRecv",
13913 atomic_load_explicit(&p->dynamic_cap_in,
13914 memory_order_relaxed));
13915 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13916 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13917 json_object_object_add(json_neigh, "messageStats", json_stat);
13918 } else {
13919 atomic_size_t outq_count, inq_count, open_out, open_in,
13920 notify_out, notify_in, update_out, update_in,
13921 keepalive_out, keepalive_in, refresh_out, refresh_in,
13922 dynamic_cap_out, dynamic_cap_in;
13923 outq_count = atomic_load_explicit(&p->obuf->count,
13924 memory_order_relaxed);
13925 inq_count = atomic_load_explicit(&p->ibuf->count,
13926 memory_order_relaxed);
13927 open_out = atomic_load_explicit(&p->open_out,
13928 memory_order_relaxed);
13929 open_in =
13930 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13931 notify_out = atomic_load_explicit(&p->notify_out,
13932 memory_order_relaxed);
13933 notify_in = atomic_load_explicit(&p->notify_in,
13934 memory_order_relaxed);
13935 update_out = atomic_load_explicit(&p->update_out,
13936 memory_order_relaxed);
13937 update_in = atomic_load_explicit(&p->update_in,
13938 memory_order_relaxed);
13939 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13940 memory_order_relaxed);
13941 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13942 memory_order_relaxed);
13943 refresh_out = atomic_load_explicit(&p->refresh_out,
13944 memory_order_relaxed);
13945 refresh_in = atomic_load_explicit(&p->refresh_in,
13946 memory_order_relaxed);
13947 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13948 memory_order_relaxed);
13949 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13950 memory_order_relaxed);
13951
13952 /* Packet counts. */
13953 vty_out(vty, " Message statistics:\n");
13954 vty_out(vty, " Inq depth is %zu\n", inq_count);
13955 vty_out(vty, " Outq depth is %zu\n", outq_count);
13956 vty_out(vty, " Sent Rcvd\n");
13957 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13958 open_in);
13959 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13960 notify_in);
13961 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13962 update_in);
13963 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13964 keepalive_in);
13965 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13966 refresh_in);
13967 vty_out(vty, " Capability: %10zu %10zu\n",
13968 dynamic_cap_out, dynamic_cap_in);
13969 vty_out(vty, " Total: %10u %10u\n",
13970 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
13971 }
13972
13973 if (use_json) {
13974 /* advertisement-interval */
13975 json_object_int_add(json_neigh,
13976 "minBtwnAdvertisementRunsTimerMsecs",
13977 p->v_routeadv * 1000);
13978
13979 /* Update-source. */
13980 if (p->update_if || p->update_source) {
13981 if (p->update_if)
13982 json_object_string_add(json_neigh,
13983 "updateSource",
13984 p->update_if);
13985 else if (p->update_source)
13986 json_object_string_addf(json_neigh,
13987 "updateSource", "%pSU",
13988 p->update_source);
13989 }
13990 } else {
13991 /* advertisement-interval */
13992 vty_out(vty,
13993 " Minimum time between advertisement runs is %d seconds\n",
13994 p->v_routeadv);
13995
13996 /* Update-source. */
13997 if (p->update_if || p->update_source) {
13998 vty_out(vty, " Update source is ");
13999 if (p->update_if)
14000 vty_out(vty, "%s", p->update_if);
14001 else if (p->update_source)
14002 vty_out(vty, "%pSU", p->update_source);
14003 vty_out(vty, "\n");
14004 }
14005
14006 vty_out(vty, "\n");
14007 }
14008
14009 /* Address Family Information */
14010 json_object *json_hold = NULL;
14011
14012 if (use_json)
14013 json_hold = json_object_new_object();
14014
14015 FOREACH_AFI_SAFI (afi, safi)
14016 if (p->afc[afi][safi])
14017 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14018 json_hold);
14019
14020 if (use_json) {
14021 json_object_object_add(json_neigh, "addressFamilyInfo",
14022 json_hold);
14023 json_object_int_add(json_neigh, "connectionsEstablished",
14024 p->established);
14025 json_object_int_add(json_neigh, "connectionsDropped",
14026 p->dropped);
14027 } else
14028 vty_out(vty, " Connections established %d; dropped %d\n",
14029 p->established, p->dropped);
14030
14031 if (!p->last_reset) {
14032 if (use_json)
14033 json_object_string_add(json_neigh, "lastReset",
14034 "never");
14035 else
14036 vty_out(vty, " Last reset never\n");
14037 } else {
14038 if (use_json) {
14039 time_t uptime;
14040 struct tm tm;
14041
14042 uptime = bgp_clock();
14043 uptime -= p->resettime;
14044 gmtime_r(&uptime, &tm);
14045
14046 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14047 (tm.tm_sec * 1000)
14048 + (tm.tm_min * 60000)
14049 + (tm.tm_hour * 3600000));
14050 bgp_show_peer_reset(NULL, p, json_neigh, true);
14051 } else {
14052 vty_out(vty, " Last reset %s, ",
14053 peer_uptime(p->resettime, timebuf,
14054 BGP_UPTIME_LEN, 0, NULL));
14055
14056 bgp_show_peer_reset(vty, p, NULL, false);
14057 if (p->last_reset_cause_size) {
14058 msg = p->last_reset_cause;
14059 vty_out(vty,
14060 " Message received that caused BGP to send a NOTIFICATION:\n ");
14061 for (i = 1; i <= p->last_reset_cause_size;
14062 i++) {
14063 vty_out(vty, "%02X", *msg++);
14064
14065 if (i != p->last_reset_cause_size) {
14066 if (i % 16 == 0) {
14067 vty_out(vty, "\n ");
14068 } else if (i % 4 == 0) {
14069 vty_out(vty, " ");
14070 }
14071 }
14072 }
14073 vty_out(vty, "\n");
14074 }
14075 }
14076 }
14077
14078 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14079 if (use_json)
14080 json_object_boolean_true_add(json_neigh,
14081 "prefixesConfigExceedMax");
14082 else
14083 vty_out(vty,
14084 " Peer had exceeded the max. no. of prefixes configured.\n");
14085
14086 if (p->t_pmax_restart) {
14087 if (use_json) {
14088 json_object_boolean_true_add(
14089 json_neigh, "reducePrefixNumFrom");
14090 json_object_int_add(json_neigh,
14091 "restartInTimerMsec",
14092 thread_timer_remain_second(
14093 p->t_pmax_restart)
14094 * 1000);
14095 } else
14096 vty_out(vty,
14097 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14098 p->host, thread_timer_remain_second(
14099 p->t_pmax_restart));
14100 } else {
14101 if (use_json)
14102 json_object_boolean_true_add(
14103 json_neigh,
14104 "reducePrefixNumAndClearIpBgp");
14105 else
14106 vty_out(vty,
14107 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14108 p->host);
14109 }
14110 }
14111
14112 /* EBGP Multihop and GTSM */
14113 if (p->sort != BGP_PEER_IBGP) {
14114 if (use_json) {
14115 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14116 json_object_int_add(json_neigh,
14117 "externalBgpNbrMaxHopsAway",
14118 p->gtsm_hops);
14119 else
14120 json_object_int_add(json_neigh,
14121 "externalBgpNbrMaxHopsAway",
14122 p->ttl);
14123 } else {
14124 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14125 vty_out(vty,
14126 " External BGP neighbor may be up to %d hops away.\n",
14127 p->gtsm_hops);
14128 else
14129 vty_out(vty,
14130 " External BGP neighbor may be up to %d hops away.\n",
14131 p->ttl);
14132 }
14133 } else {
14134 if (use_json) {
14135 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14136 json_object_int_add(json_neigh,
14137 "internalBgpNbrMaxHopsAway",
14138 p->gtsm_hops);
14139 else
14140 json_object_int_add(json_neigh,
14141 "internalBgpNbrMaxHopsAway",
14142 p->ttl);
14143 } else {
14144 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14145 vty_out(vty,
14146 " Internal BGP neighbor may be up to %d hops away.\n",
14147 p->gtsm_hops);
14148 else
14149 vty_out(vty,
14150 " Internal BGP neighbor may be up to %d hops away.\n",
14151 p->ttl);
14152 }
14153 }
14154
14155 /* Local address. */
14156 if (p->su_local) {
14157 if (use_json) {
14158 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14159 p->su_local);
14160 json_object_int_add(json_neigh, "portLocal",
14161 ntohs(p->su_local->sin.sin_port));
14162 } else
14163 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14164 p->su_local, ntohs(p->su_local->sin.sin_port));
14165 } else {
14166 if (use_json) {
14167 json_object_string_add(json_neigh, "hostLocal",
14168 "Unknown");
14169 json_object_int_add(json_neigh, "portLocal", -1);
14170 }
14171 }
14172
14173 /* Remote address. */
14174 if (p->su_remote) {
14175 if (use_json) {
14176 json_object_string_addf(json_neigh, "hostForeign",
14177 "%pSU", p->su_remote);
14178 json_object_int_add(json_neigh, "portForeign",
14179 ntohs(p->su_remote->sin.sin_port));
14180 } else
14181 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14182 p->su_remote,
14183 ntohs(p->su_remote->sin.sin_port));
14184 } else {
14185 if (use_json) {
14186 json_object_string_add(json_neigh, "hostForeign",
14187 "Unknown");
14188 json_object_int_add(json_neigh, "portForeign", -1);
14189 }
14190 }
14191
14192 /* Nexthop display. */
14193 if (p->su_local) {
14194 if (use_json) {
14195 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14196 &p->nexthop.v4);
14197 json_object_string_addf(json_neigh, "nexthopGlobal",
14198 "%pI6", &p->nexthop.v6_global);
14199 json_object_string_addf(json_neigh, "nexthopLocal",
14200 "%pI6", &p->nexthop.v6_local);
14201 if (p->shared_network)
14202 json_object_string_add(json_neigh,
14203 "bgpConnection",
14204 "sharedNetwork");
14205 else
14206 json_object_string_add(json_neigh,
14207 "bgpConnection",
14208 "nonSharedNetwork");
14209 } else {
14210 vty_out(vty, "Nexthop: %s\n",
14211 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14212 sizeof(buf1)));
14213 vty_out(vty, "Nexthop global: %s\n",
14214 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14215 sizeof(buf1)));
14216 vty_out(vty, "Nexthop local: %s\n",
14217 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14218 sizeof(buf1)));
14219 vty_out(vty, "BGP connection: %s\n",
14220 p->shared_network ? "shared network"
14221 : "non shared network");
14222 }
14223 }
14224
14225 /* Timer information. */
14226 if (use_json) {
14227 json_object_int_add(json_neigh, "connectRetryTimer",
14228 p->v_connect);
14229 if (peer_established(p) && p->rtt)
14230 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14231 p->rtt);
14232 if (p->t_start)
14233 json_object_int_add(
14234 json_neigh, "nextStartTimerDueInMsecs",
14235 thread_timer_remain_second(p->t_start) * 1000);
14236 if (p->t_connect)
14237 json_object_int_add(
14238 json_neigh, "nextConnectTimerDueInMsecs",
14239 thread_timer_remain_second(p->t_connect)
14240 * 1000);
14241 if (p->t_routeadv) {
14242 json_object_int_add(json_neigh, "mraiInterval",
14243 p->v_routeadv);
14244 json_object_int_add(
14245 json_neigh, "mraiTimerExpireInMsecs",
14246 thread_timer_remain_second(p->t_routeadv)
14247 * 1000);
14248 }
14249 if (p->password)
14250 json_object_int_add(json_neigh, "authenticationEnabled",
14251 1);
14252
14253 if (p->t_read)
14254 json_object_string_add(json_neigh, "readThread", "on");
14255 else
14256 json_object_string_add(json_neigh, "readThread", "off");
14257
14258 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14259 json_object_string_add(json_neigh, "writeThread", "on");
14260 else
14261 json_object_string_add(json_neigh, "writeThread",
14262 "off");
14263 } else {
14264 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14265 p->v_connect);
14266 if (peer_established(p) && p->rtt)
14267 vty_out(vty, "Estimated round trip time: %d ms\n",
14268 p->rtt);
14269 if (p->t_start)
14270 vty_out(vty, "Next start timer due in %ld seconds\n",
14271 thread_timer_remain_second(p->t_start));
14272 if (p->t_connect)
14273 vty_out(vty, "Next connect timer due in %ld seconds\n",
14274 thread_timer_remain_second(p->t_connect));
14275 if (p->t_routeadv)
14276 vty_out(vty,
14277 "MRAI (interval %u) timer expires in %ld seconds\n",
14278 p->v_routeadv,
14279 thread_timer_remain_second(p->t_routeadv));
14280 if (p->password)
14281 vty_out(vty, "Peer Authentication Enabled\n");
14282
14283 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14284 p->t_read ? "on" : "off",
14285 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14286 ? "on"
14287 : "off", p->fd);
14288 }
14289
14290 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14291 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14292 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14293
14294 if (!use_json)
14295 vty_out(vty, "\n");
14296
14297 /* BFD information. */
14298 if (p->bfd_config)
14299 bgp_bfd_show_info(vty, p, json_neigh);
14300
14301 if (use_json) {
14302 if (p->conf_if) /* Configured interface name. */
14303 json_object_object_add(json, p->conf_if, json_neigh);
14304 else /* Configured IP address. */
14305 json_object_object_add(json, p->host, json_neigh);
14306 }
14307 }
14308
14309 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14310 enum show_type type,
14311 union sockunion *su,
14312 const char *conf_if, afi_t afi,
14313 bool use_json)
14314 {
14315 struct listnode *node, *nnode;
14316 struct peer *peer;
14317 int find = 0;
14318 safi_t safi = SAFI_UNICAST;
14319 json_object *json = NULL;
14320 json_object *json_neighbor = NULL;
14321
14322 if (use_json) {
14323 json = json_object_new_object();
14324 json_neighbor = json_object_new_object();
14325 }
14326
14327 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14328
14329 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14330 continue;
14331
14332 if ((peer->afc[afi][safi]) == 0)
14333 continue;
14334
14335 if (type == show_all) {
14336 bgp_show_peer_gr_status(vty, peer, use_json,
14337 json_neighbor);
14338
14339 if (use_json) {
14340 json_object_object_add(json, peer->host,
14341 json_neighbor);
14342 json_neighbor = NULL;
14343 }
14344
14345 } else if (type == show_peer) {
14346 if (conf_if) {
14347 if ((peer->conf_if
14348 && !strcmp(peer->conf_if, conf_if))
14349 || (peer->hostname
14350 && !strcmp(peer->hostname, conf_if))) {
14351 find = 1;
14352 bgp_show_peer_gr_status(vty, peer,
14353 use_json,
14354 json_neighbor);
14355 }
14356 } else {
14357 if (sockunion_same(&peer->su, su)) {
14358 find = 1;
14359 bgp_show_peer_gr_status(vty, peer,
14360 use_json,
14361 json_neighbor);
14362 }
14363 }
14364 if (use_json && find)
14365 json_object_object_add(json, peer->host,
14366 json_neighbor);
14367 }
14368
14369 if (find) {
14370 json_neighbor = NULL;
14371 break;
14372 }
14373 }
14374
14375 if (type == show_peer && !find) {
14376 if (use_json)
14377 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14378 else
14379 vty_out(vty, "%% No such neighbor\n");
14380 }
14381 if (use_json) {
14382 if (json_neighbor)
14383 json_object_free(json_neighbor);
14384 vty_json(vty, json);
14385 } else {
14386 vty_out(vty, "\n");
14387 }
14388
14389 return CMD_SUCCESS;
14390 }
14391
14392 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14393 enum show_type type, union sockunion *su,
14394 const char *conf_if, bool use_json,
14395 json_object *json)
14396 {
14397 struct listnode *node, *nnode;
14398 struct peer *peer;
14399 int find = 0;
14400 bool nbr_output = false;
14401 afi_t afi = AFI_MAX;
14402 safi_t safi = SAFI_MAX;
14403
14404 if (type == show_ipv4_peer || type == show_ipv4_all) {
14405 afi = AFI_IP;
14406 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14407 afi = AFI_IP6;
14408 }
14409
14410 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14411 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14412 continue;
14413
14414 switch (type) {
14415 case show_all:
14416 bgp_show_peer(vty, peer, use_json, json);
14417 nbr_output = true;
14418 break;
14419 case show_peer:
14420 if (conf_if) {
14421 if ((peer->conf_if
14422 && !strcmp(peer->conf_if, conf_if))
14423 || (peer->hostname
14424 && !strcmp(peer->hostname, conf_if))) {
14425 find = 1;
14426 bgp_show_peer(vty, peer, use_json,
14427 json);
14428 }
14429 } else {
14430 if (sockunion_same(&peer->su, su)) {
14431 find = 1;
14432 bgp_show_peer(vty, peer, use_json,
14433 json);
14434 }
14435 }
14436 break;
14437 case show_ipv4_peer:
14438 case show_ipv6_peer:
14439 FOREACH_SAFI (safi) {
14440 if (peer->afc[afi][safi]) {
14441 if (conf_if) {
14442 if ((peer->conf_if
14443 && !strcmp(peer->conf_if, conf_if))
14444 || (peer->hostname
14445 && !strcmp(peer->hostname, conf_if))) {
14446 find = 1;
14447 bgp_show_peer(vty, peer, use_json,
14448 json);
14449 break;
14450 }
14451 } else {
14452 if (sockunion_same(&peer->su, su)) {
14453 find = 1;
14454 bgp_show_peer(vty, peer, use_json,
14455 json);
14456 break;
14457 }
14458 }
14459 }
14460 }
14461 break;
14462 case show_ipv4_all:
14463 case show_ipv6_all:
14464 FOREACH_SAFI (safi) {
14465 if (peer->afc[afi][safi]) {
14466 bgp_show_peer(vty, peer, use_json, json);
14467 nbr_output = true;
14468 break;
14469 }
14470 }
14471 break;
14472 }
14473 }
14474
14475 if ((type == show_peer || type == show_ipv4_peer ||
14476 type == show_ipv6_peer) && !find) {
14477 if (use_json)
14478 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14479 else
14480 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14481 }
14482
14483 if (type != show_peer && type != show_ipv4_peer &&
14484 type != show_ipv6_peer && !nbr_output && !use_json)
14485 vty_out(vty, "%% No BGP neighbors found\n");
14486
14487 if (use_json) {
14488 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14489 json, JSON_C_TO_STRING_PRETTY));
14490 } else {
14491 vty_out(vty, "\n");
14492 }
14493
14494 return CMD_SUCCESS;
14495 }
14496
14497 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14498 enum show_type type,
14499 const char *ip_str,
14500 afi_t afi, bool use_json)
14501 {
14502
14503 int ret;
14504 struct bgp *bgp;
14505 union sockunion su;
14506
14507 bgp = bgp_get_default();
14508
14509 if (!bgp)
14510 return;
14511
14512 if (!use_json)
14513 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14514 NULL);
14515
14516 if (ip_str) {
14517 ret = str2sockunion(ip_str, &su);
14518 if (ret < 0)
14519 bgp_show_neighbor_graceful_restart(
14520 vty, bgp, type, NULL, ip_str, afi, use_json);
14521 else
14522 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14523 NULL, afi, use_json);
14524 } else
14525 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14526 afi, use_json);
14527 }
14528
14529 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14530 enum show_type type,
14531 const char *ip_str,
14532 bool use_json)
14533 {
14534 struct listnode *node, *nnode;
14535 struct bgp *bgp;
14536 union sockunion su;
14537 json_object *json = NULL;
14538 int ret, is_first = 1;
14539 bool nbr_output = false;
14540
14541 if (use_json)
14542 vty_out(vty, "{\n");
14543
14544 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14545 nbr_output = true;
14546 if (use_json) {
14547 if (!(json = json_object_new_object())) {
14548 flog_err(
14549 EC_BGP_JSON_MEM_ERROR,
14550 "Unable to allocate memory for JSON object");
14551 vty_out(vty,
14552 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14553 return;
14554 }
14555
14556 json_object_int_add(json, "vrfId",
14557 (bgp->vrf_id == VRF_UNKNOWN)
14558 ? -1
14559 : (int64_t)bgp->vrf_id);
14560 json_object_string_add(
14561 json, "vrfName",
14562 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14563 ? VRF_DEFAULT_NAME
14564 : bgp->name);
14565
14566 if (!is_first)
14567 vty_out(vty, ",\n");
14568 else
14569 is_first = 0;
14570
14571 vty_out(vty, "\"%s\":",
14572 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14573 ? VRF_DEFAULT_NAME
14574 : bgp->name);
14575 } else {
14576 vty_out(vty, "\nInstance %s:\n",
14577 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14578 ? VRF_DEFAULT_NAME
14579 : bgp->name);
14580 }
14581
14582 if (type == show_peer || type == show_ipv4_peer ||
14583 type == show_ipv6_peer) {
14584 ret = str2sockunion(ip_str, &su);
14585 if (ret < 0)
14586 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14587 use_json, json);
14588 else
14589 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14590 use_json, json);
14591 } else {
14592 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14593 use_json, json);
14594 }
14595 json_object_free(json);
14596 json = NULL;
14597 }
14598
14599 if (use_json)
14600 vty_out(vty, "}\n");
14601 else if (!nbr_output)
14602 vty_out(vty, "%% BGP instance not found\n");
14603 }
14604
14605 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14606 enum show_type type, const char *ip_str,
14607 bool use_json)
14608 {
14609 int ret;
14610 struct bgp *bgp;
14611 union sockunion su;
14612 json_object *json = NULL;
14613
14614 if (name) {
14615 if (strmatch(name, "all")) {
14616 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14617 use_json);
14618 return CMD_SUCCESS;
14619 } else {
14620 bgp = bgp_lookup_by_name(name);
14621 if (!bgp) {
14622 if (use_json) {
14623 json = json_object_new_object();
14624 vty_json(vty, json);
14625 } else
14626 vty_out(vty,
14627 "%% BGP instance not found\n");
14628
14629 return CMD_WARNING;
14630 }
14631 }
14632 } else {
14633 bgp = bgp_get_default();
14634 }
14635
14636 if (bgp) {
14637 json = json_object_new_object();
14638 if (ip_str) {
14639 ret = str2sockunion(ip_str, &su);
14640 if (ret < 0)
14641 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14642 use_json, json);
14643 else
14644 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14645 use_json, json);
14646 } else {
14647 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14648 json);
14649 }
14650 json_object_free(json);
14651 } else {
14652 if (use_json)
14653 vty_out(vty, "{}\n");
14654 else
14655 vty_out(vty, "%% BGP instance not found\n");
14656 }
14657
14658 return CMD_SUCCESS;
14659 }
14660
14661
14662
14663 /* "show [ip] bgp neighbors graceful-restart" commands. */
14664 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14665 show_ip_bgp_neighbors_graceful_restart_cmd,
14666 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14667 SHOW_STR
14668 BGP_STR
14669 IP_STR
14670 IPV6_STR
14671 NEIGHBOR_STR
14672 "Neighbor to display information about\n"
14673 "Neighbor to display information about\n"
14674 "Neighbor on BGP configured interface\n"
14675 GR_SHOW
14676 JSON_STR)
14677 {
14678 char *sh_arg = NULL;
14679 enum show_type sh_type;
14680 int idx = 0;
14681 afi_t afi = AFI_MAX;
14682 bool uj = use_json(argc, argv);
14683
14684 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14685 afi = AFI_MAX;
14686
14687 idx++;
14688
14689 if (argv_find(argv, argc, "A.B.C.D", &idx)
14690 || argv_find(argv, argc, "X:X::X:X", &idx)
14691 || argv_find(argv, argc, "WORD", &idx)) {
14692 sh_type = show_peer;
14693 sh_arg = argv[idx]->arg;
14694 } else
14695 sh_type = show_all;
14696
14697 if (!argv_find(argv, argc, "graceful-restart", &idx))
14698 return CMD_SUCCESS;
14699
14700
14701 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14702 afi, uj);
14703 }
14704
14705 /* "show [ip] bgp neighbors" commands. */
14706 DEFUN (show_ip_bgp_neighbors,
14707 show_ip_bgp_neighbors_cmd,
14708 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14709 SHOW_STR
14710 IP_STR
14711 BGP_STR
14712 BGP_INSTANCE_HELP_STR
14713 BGP_AF_STR
14714 BGP_AF_STR
14715 "Detailed information on TCP and BGP neighbor connections\n"
14716 "Neighbor to display information about\n"
14717 "Neighbor to display information about\n"
14718 "Neighbor on BGP configured interface\n"
14719 JSON_STR)
14720 {
14721 char *vrf = NULL;
14722 char *sh_arg = NULL;
14723 enum show_type sh_type;
14724 afi_t afi = AFI_MAX;
14725
14726 bool uj = use_json(argc, argv);
14727
14728 int idx = 0;
14729
14730 /* [<vrf> VIEWVRFNAME] */
14731 if (argv_find(argv, argc, "vrf", &idx)) {
14732 vrf = argv[idx + 1]->arg;
14733 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14734 vrf = NULL;
14735 } else if (argv_find(argv, argc, "view", &idx))
14736 /* [<view> VIEWVRFNAME] */
14737 vrf = argv[idx + 1]->arg;
14738
14739 idx++;
14740
14741 if (argv_find(argv, argc, "ipv4", &idx)) {
14742 sh_type = show_ipv4_all;
14743 afi = AFI_IP;
14744 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14745 sh_type = show_ipv6_all;
14746 afi = AFI_IP6;
14747 } else {
14748 sh_type = show_all;
14749 }
14750
14751 if (argv_find(argv, argc, "A.B.C.D", &idx)
14752 || argv_find(argv, argc, "X:X::X:X", &idx)
14753 || argv_find(argv, argc, "WORD", &idx)) {
14754 sh_type = show_peer;
14755 sh_arg = argv[idx]->arg;
14756 }
14757
14758 if (sh_type == show_peer && afi == AFI_IP) {
14759 sh_type = show_ipv4_peer;
14760 } else if (sh_type == show_peer && afi == AFI_IP6) {
14761 sh_type = show_ipv6_peer;
14762 }
14763
14764 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14765 }
14766
14767 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14768 paths' and `show ip mbgp paths'. Those functions results are the
14769 same.*/
14770 DEFUN (show_ip_bgp_paths,
14771 show_ip_bgp_paths_cmd,
14772 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14773 SHOW_STR
14774 IP_STR
14775 BGP_STR
14776 BGP_SAFI_HELP_STR
14777 "Path information\n")
14778 {
14779 vty_out(vty, "Address Refcnt Path\n");
14780 aspath_print_all_vty(vty);
14781 return CMD_SUCCESS;
14782 }
14783
14784 #include "hash.h"
14785
14786 static void community_show_all_iterator(struct hash_bucket *bucket,
14787 struct vty *vty)
14788 {
14789 struct community *com;
14790
14791 com = (struct community *)bucket->data;
14792 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14793 community_str(com, false, false));
14794 }
14795
14796 /* Show BGP's community internal data. */
14797 DEFUN (show_ip_bgp_community_info,
14798 show_ip_bgp_community_info_cmd,
14799 "show [ip] bgp community-info",
14800 SHOW_STR
14801 IP_STR
14802 BGP_STR
14803 "List all bgp community information\n")
14804 {
14805 vty_out(vty, "Address Refcnt Community\n");
14806
14807 hash_iterate(community_hash(),
14808 (void (*)(struct hash_bucket *,
14809 void *))community_show_all_iterator,
14810 vty);
14811
14812 return CMD_SUCCESS;
14813 }
14814
14815 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14816 struct vty *vty)
14817 {
14818 struct lcommunity *lcom;
14819
14820 lcom = (struct lcommunity *)bucket->data;
14821 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14822 lcommunity_str(lcom, false, false));
14823 }
14824
14825 /* Show BGP's community internal data. */
14826 DEFUN (show_ip_bgp_lcommunity_info,
14827 show_ip_bgp_lcommunity_info_cmd,
14828 "show ip bgp large-community-info",
14829 SHOW_STR
14830 IP_STR
14831 BGP_STR
14832 "List all bgp large-community information\n")
14833 {
14834 vty_out(vty, "Address Refcnt Large-community\n");
14835
14836 hash_iterate(lcommunity_hash(),
14837 (void (*)(struct hash_bucket *,
14838 void *))lcommunity_show_all_iterator,
14839 vty);
14840
14841 return CMD_SUCCESS;
14842 }
14843 /* Graceful Restart */
14844
14845 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14846 struct bgp *bgp,
14847 bool use_json,
14848 json_object *json)
14849 {
14850
14851
14852 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14853
14854 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14855
14856 switch (bgp_global_gr_mode) {
14857
14858 case GLOBAL_HELPER:
14859 vty_out(vty, "Global BGP GR Mode : Helper\n");
14860 break;
14861
14862 case GLOBAL_GR:
14863 vty_out(vty, "Global BGP GR Mode : Restart\n");
14864 break;
14865
14866 case GLOBAL_DISABLE:
14867 vty_out(vty, "Global BGP GR Mode : Disable\n");
14868 break;
14869
14870 case GLOBAL_INVALID:
14871 vty_out(vty,
14872 "Global BGP GR Mode Invalid\n");
14873 break;
14874 }
14875 vty_out(vty, "\n");
14876 }
14877
14878 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14879 enum show_type type,
14880 const char *ip_str,
14881 afi_t afi, bool use_json)
14882 {
14883 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14884 afi = AFI_IP;
14885
14886 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14887
14888 bgp_show_neighbor_graceful_restart_vty(
14889 vty, type, ip_str, afi, use_json);
14890 afi++;
14891 }
14892 } else if (afi != AFI_MAX) {
14893 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14894 use_json);
14895 } else {
14896 return CMD_ERR_INCOMPLETE;
14897 }
14898
14899 return CMD_SUCCESS;
14900 }
14901 /* Graceful Restart */
14902
14903 DEFUN (show_ip_bgp_attr_info,
14904 show_ip_bgp_attr_info_cmd,
14905 "show [ip] bgp attribute-info",
14906 SHOW_STR
14907 IP_STR
14908 BGP_STR
14909 "List all bgp attribute information\n")
14910 {
14911 attr_show_all(vty);
14912 return CMD_SUCCESS;
14913 }
14914
14915 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14916 afi_t afi, safi_t safi,
14917 bool use_json, json_object *json)
14918 {
14919 struct bgp *bgp;
14920 struct listnode *node;
14921 char *vname;
14922 char buf1[INET6_ADDRSTRLEN];
14923 char *ecom_str;
14924 enum vpn_policy_direction dir;
14925
14926 if (json) {
14927 json_object *json_import_vrfs = NULL;
14928 json_object *json_export_vrfs = NULL;
14929
14930 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14931
14932 if (!bgp) {
14933 vty_json(vty, json);
14934
14935 return CMD_WARNING;
14936 }
14937
14938 /* Provide context for the block */
14939 json_object_string_add(json, "vrf", name ? name : "default");
14940 json_object_string_add(json, "afiSafi",
14941 get_afi_safi_str(afi, safi, true));
14942
14943 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14944 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14945 json_object_string_add(json, "importFromVrfs", "none");
14946 json_object_string_add(json, "importRts", "none");
14947 } else {
14948 json_import_vrfs = json_object_new_array();
14949
14950 for (ALL_LIST_ELEMENTS_RO(
14951 bgp->vpn_policy[afi].import_vrf,
14952 node, vname))
14953 json_object_array_add(json_import_vrfs,
14954 json_object_new_string(vname));
14955
14956 json_object_object_add(json, "importFromVrfs",
14957 json_import_vrfs);
14958 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14959 if (bgp->vpn_policy[afi].rtlist[dir]) {
14960 ecom_str = ecommunity_ecom2str(
14961 bgp->vpn_policy[afi].rtlist[dir],
14962 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14963 json_object_string_add(json, "importRts",
14964 ecom_str);
14965 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14966 } else
14967 json_object_string_add(json, "importRts",
14968 "none");
14969 }
14970
14971 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14972 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14973 json_object_string_add(json, "exportToVrfs", "none");
14974 json_object_string_add(json, "routeDistinguisher",
14975 "none");
14976 json_object_string_add(json, "exportRts", "none");
14977 } else {
14978 json_export_vrfs = json_object_new_array();
14979
14980 for (ALL_LIST_ELEMENTS_RO(
14981 bgp->vpn_policy[afi].export_vrf,
14982 node, vname))
14983 json_object_array_add(json_export_vrfs,
14984 json_object_new_string(vname));
14985 json_object_object_add(json, "exportToVrfs",
14986 json_export_vrfs);
14987 json_object_string_add(json, "routeDistinguisher",
14988 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14989 buf1, RD_ADDRSTRLEN));
14990
14991 dir = BGP_VPN_POLICY_DIR_TOVPN;
14992 if (bgp->vpn_policy[afi].rtlist[dir]) {
14993 ecom_str = ecommunity_ecom2str(
14994 bgp->vpn_policy[afi].rtlist[dir],
14995 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14996 json_object_string_add(json, "exportRts",
14997 ecom_str);
14998 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14999 } else
15000 json_object_string_add(json, "exportRts",
15001 "none");
15002 }
15003
15004 if (use_json) {
15005 vty_json(vty, json);
15006 }
15007 } else {
15008 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15009
15010 if (!bgp) {
15011 vty_out(vty, "%% No such BGP instance exist\n");
15012 return CMD_WARNING;
15013 }
15014
15015 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15016 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15017 vty_out(vty,
15018 "This VRF is not importing %s routes from any other VRF\n",
15019 get_afi_safi_str(afi, safi, false));
15020 else {
15021 vty_out(vty,
15022 "This VRF is importing %s routes from the following VRFs:\n",
15023 get_afi_safi_str(afi, safi, false));
15024
15025 for (ALL_LIST_ELEMENTS_RO(
15026 bgp->vpn_policy[afi].import_vrf,
15027 node, vname))
15028 vty_out(vty, " %s\n", vname);
15029
15030 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15031 ecom_str = NULL;
15032 if (bgp->vpn_policy[afi].rtlist[dir]) {
15033 ecom_str = ecommunity_ecom2str(
15034 bgp->vpn_policy[afi].rtlist[dir],
15035 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15036 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15037
15038 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15039 } else
15040 vty_out(vty, "Import RT(s):\n");
15041 }
15042
15043 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15044 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15045 vty_out(vty,
15046 "This VRF is not exporting %s routes to any other VRF\n",
15047 get_afi_safi_str(afi, safi, false));
15048 else {
15049 vty_out(vty,
15050 "This VRF is exporting %s routes to the following VRFs:\n",
15051 get_afi_safi_str(afi, safi, false));
15052
15053 for (ALL_LIST_ELEMENTS_RO(
15054 bgp->vpn_policy[afi].export_vrf,
15055 node, vname))
15056 vty_out(vty, " %s\n", vname);
15057
15058 vty_out(vty, "RD: %s\n",
15059 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15060 buf1, RD_ADDRSTRLEN));
15061
15062 dir = BGP_VPN_POLICY_DIR_TOVPN;
15063 if (bgp->vpn_policy[afi].rtlist[dir]) {
15064 ecom_str = ecommunity_ecom2str(
15065 bgp->vpn_policy[afi].rtlist[dir],
15066 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15067 vty_out(vty, "Export RT: %s\n", ecom_str);
15068 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15069 } else
15070 vty_out(vty, "Import RT(s):\n");
15071 }
15072 }
15073
15074 return CMD_SUCCESS;
15075 }
15076
15077 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15078 safi_t safi, bool use_json)
15079 {
15080 struct listnode *node, *nnode;
15081 struct bgp *bgp;
15082 char *vrf_name = NULL;
15083 json_object *json = NULL;
15084 json_object *json_vrf = NULL;
15085 json_object *json_vrfs = NULL;
15086
15087 if (use_json) {
15088 json = json_object_new_object();
15089 json_vrfs = json_object_new_object();
15090 }
15091
15092 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15093
15094 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15095 vrf_name = bgp->name;
15096
15097 if (use_json) {
15098 json_vrf = json_object_new_object();
15099 } else {
15100 vty_out(vty, "\nInstance %s:\n",
15101 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15102 ? VRF_DEFAULT_NAME : bgp->name);
15103 }
15104 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15105 if (use_json) {
15106 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15107 json_object_object_add(json_vrfs,
15108 VRF_DEFAULT_NAME, json_vrf);
15109 else
15110 json_object_object_add(json_vrfs, vrf_name,
15111 json_vrf);
15112 }
15113 }
15114
15115 if (use_json) {
15116 json_object_object_add(json, "vrfs", json_vrfs);
15117 vty_json(vty, json);
15118 }
15119
15120 return CMD_SUCCESS;
15121 }
15122
15123 /* "show [ip] bgp route-leak" command. */
15124 DEFUN (show_ip_bgp_route_leak,
15125 show_ip_bgp_route_leak_cmd,
15126 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15127 SHOW_STR
15128 IP_STR
15129 BGP_STR
15130 BGP_INSTANCE_HELP_STR
15131 BGP_AFI_HELP_STR
15132 BGP_SAFI_HELP_STR
15133 "Route leaking information\n"
15134 JSON_STR)
15135 {
15136 char *vrf = NULL;
15137 afi_t afi = AFI_MAX;
15138 safi_t safi = SAFI_MAX;
15139
15140 bool uj = use_json(argc, argv);
15141 int idx = 0;
15142 json_object *json = NULL;
15143
15144 /* show [ip] bgp */
15145 if (argv_find(argv, argc, "ip", &idx)) {
15146 afi = AFI_IP;
15147 safi = SAFI_UNICAST;
15148 }
15149 /* [vrf VIEWVRFNAME] */
15150 if (argv_find(argv, argc, "view", &idx)) {
15151 vty_out(vty,
15152 "%% This command is not applicable to BGP views\n");
15153 return CMD_WARNING;
15154 }
15155
15156 if (argv_find(argv, argc, "vrf", &idx)) {
15157 vrf = argv[idx + 1]->arg;
15158 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15159 vrf = NULL;
15160 }
15161 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15162 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15163 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15164
15165 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15166 vty_out(vty,
15167 "%% This command is applicable only for unicast ipv4|ipv6\n");
15168 return CMD_WARNING;
15169 }
15170
15171 if (vrf && strmatch(vrf, "all"))
15172 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15173
15174 if (uj)
15175 json = json_object_new_object();
15176
15177 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15178 }
15179
15180 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15181 safi_t safi)
15182 {
15183 struct listnode *node, *nnode;
15184 struct bgp *bgp;
15185
15186 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15187 vty_out(vty, "\nInstance %s:\n",
15188 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15189 ? VRF_DEFAULT_NAME
15190 : bgp->name);
15191 update_group_show(bgp, afi, safi, vty, 0);
15192 }
15193 }
15194
15195 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15196 int safi, uint64_t subgrp_id)
15197 {
15198 struct bgp *bgp;
15199
15200 if (name) {
15201 if (strmatch(name, "all")) {
15202 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15203 return CMD_SUCCESS;
15204 } else {
15205 bgp = bgp_lookup_by_name(name);
15206 }
15207 } else {
15208 bgp = bgp_get_default();
15209 }
15210
15211 if (bgp)
15212 update_group_show(bgp, afi, safi, vty, subgrp_id);
15213 return CMD_SUCCESS;
15214 }
15215
15216 DEFUN (show_ip_bgp_updgrps,
15217 show_ip_bgp_updgrps_cmd,
15218 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15219 SHOW_STR
15220 IP_STR
15221 BGP_STR
15222 BGP_INSTANCE_HELP_STR
15223 BGP_AFI_HELP_STR
15224 BGP_SAFI_WITH_LABEL_HELP_STR
15225 "Detailed info about dynamic update groups\n"
15226 "Specific subgroup to display detailed info for\n")
15227 {
15228 char *vrf = NULL;
15229 afi_t afi = AFI_IP6;
15230 safi_t safi = SAFI_UNICAST;
15231 uint64_t subgrp_id = 0;
15232
15233 int idx = 0;
15234
15235 /* show [ip] bgp */
15236 if (argv_find(argv, argc, "ip", &idx))
15237 afi = AFI_IP;
15238 /* [<vrf> VIEWVRFNAME] */
15239 if (argv_find(argv, argc, "vrf", &idx)) {
15240 vrf = argv[idx + 1]->arg;
15241 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15242 vrf = NULL;
15243 } else if (argv_find(argv, argc, "view", &idx))
15244 /* [<view> VIEWVRFNAME] */
15245 vrf = argv[idx + 1]->arg;
15246 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15247 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15248 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15249 }
15250
15251 /* get subgroup id, if provided */
15252 idx = argc - 1;
15253 if (argv[idx]->type == VARIABLE_TKN)
15254 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15255
15256 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15257 }
15258
15259 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15260 show_bgp_instance_all_ipv6_updgrps_cmd,
15261 "show [ip] bgp <view|vrf> all update-groups",
15262 SHOW_STR
15263 IP_STR
15264 BGP_STR
15265 BGP_INSTANCE_ALL_HELP_STR
15266 "Detailed info about dynamic update groups\n")
15267 {
15268 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15269 return CMD_SUCCESS;
15270 }
15271
15272 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15273 show_bgp_l2vpn_evpn_updgrps_cmd,
15274 "show [ip] bgp l2vpn evpn update-groups",
15275 SHOW_STR
15276 IP_STR
15277 BGP_STR
15278 "l2vpn address family\n"
15279 "evpn sub-address family\n"
15280 "Detailed info about dynamic update groups\n")
15281 {
15282 char *vrf = NULL;
15283 uint64_t subgrp_id = 0;
15284
15285 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15286 return CMD_SUCCESS;
15287 }
15288
15289 DEFUN (show_bgp_updgrps_stats,
15290 show_bgp_updgrps_stats_cmd,
15291 "show [ip] bgp update-groups statistics",
15292 SHOW_STR
15293 IP_STR
15294 BGP_STR
15295 "Detailed info about dynamic update groups\n"
15296 "Statistics\n")
15297 {
15298 struct bgp *bgp;
15299
15300 bgp = bgp_get_default();
15301 if (bgp)
15302 update_group_show_stats(bgp, vty);
15303
15304 return CMD_SUCCESS;
15305 }
15306
15307 DEFUN (show_bgp_instance_updgrps_stats,
15308 show_bgp_instance_updgrps_stats_cmd,
15309 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15310 SHOW_STR
15311 IP_STR
15312 BGP_STR
15313 BGP_INSTANCE_HELP_STR
15314 "Detailed info about dynamic update groups\n"
15315 "Statistics\n")
15316 {
15317 int idx_word = 3;
15318 struct bgp *bgp;
15319
15320 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15321 if (bgp)
15322 update_group_show_stats(bgp, vty);
15323
15324 return CMD_SUCCESS;
15325 }
15326
15327 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15328 afi_t afi, safi_t safi,
15329 const char *what, uint64_t subgrp_id)
15330 {
15331 struct bgp *bgp;
15332
15333 if (name)
15334 bgp = bgp_lookup_by_name(name);
15335 else
15336 bgp = bgp_get_default();
15337
15338 if (bgp) {
15339 if (!strcmp(what, "advertise-queue"))
15340 update_group_show_adj_queue(bgp, afi, safi, vty,
15341 subgrp_id);
15342 else if (!strcmp(what, "advertised-routes"))
15343 update_group_show_advertised(bgp, afi, safi, vty,
15344 subgrp_id);
15345 else if (!strcmp(what, "packet-queue"))
15346 update_group_show_packet_queue(bgp, afi, safi, vty,
15347 subgrp_id);
15348 }
15349 }
15350
15351 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15352 show_ip_bgp_instance_updgrps_adj_s_cmd,
15353 "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",
15354 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15355 BGP_SAFI_HELP_STR
15356 "Detailed info about dynamic update groups\n"
15357 "Specific subgroup to display info for\n"
15358 "Advertisement queue\n"
15359 "Announced routes\n"
15360 "Packet queue\n")
15361 {
15362 uint64_t subgrp_id = 0;
15363 afi_t afiz;
15364 safi_t safiz;
15365 if (sgid)
15366 subgrp_id = strtoull(sgid, NULL, 10);
15367
15368 if (!ip && !afi)
15369 afiz = AFI_IP6;
15370 if (!ip && afi)
15371 afiz = bgp_vty_afi_from_str(afi);
15372 if (ip && !afi)
15373 afiz = AFI_IP;
15374 if (ip && afi) {
15375 afiz = bgp_vty_afi_from_str(afi);
15376 if (afiz != AFI_IP)
15377 vty_out(vty,
15378 "%% Cannot specify both 'ip' and 'ipv6'\n");
15379 return CMD_WARNING;
15380 }
15381
15382 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15383
15384 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15385 return CMD_SUCCESS;
15386 }
15387
15388 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15389 json_object *json)
15390 {
15391 struct listnode *node, *nnode;
15392 struct prefix *range;
15393 struct peer *conf;
15394 struct peer *peer;
15395 afi_t afi;
15396 safi_t safi;
15397 const char *peer_status;
15398 int lr_count;
15399 int dynamic;
15400 bool af_cfgd;
15401 json_object *json_peer_group = NULL;
15402 json_object *json_peer_group_afc = NULL;
15403 json_object *json_peer_group_members = NULL;
15404 json_object *json_peer_group_dynamic = NULL;
15405 json_object *json_peer_group_dynamic_af = NULL;
15406 json_object *json_peer_group_ranges = NULL;
15407
15408 conf = group->conf;
15409
15410 if (json) {
15411 json_peer_group = json_object_new_object();
15412 json_peer_group_afc = json_object_new_array();
15413 }
15414
15415 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15416 if (json)
15417 json_object_int_add(json_peer_group, "remoteAs",
15418 conf->as);
15419 else
15420 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15421 group->name, conf->as);
15422 } else if (conf->as_type == AS_INTERNAL) {
15423 if (json)
15424 json_object_int_add(json_peer_group, "remoteAs",
15425 group->bgp->as);
15426 else
15427 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15428 group->name, group->bgp->as);
15429 } else {
15430 if (!json)
15431 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15432 }
15433
15434 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15435 if (json)
15436 json_object_string_add(json_peer_group, "type",
15437 "internal");
15438 else
15439 vty_out(vty, " Peer-group type is internal\n");
15440 } else {
15441 if (json)
15442 json_object_string_add(json_peer_group, "type",
15443 "external");
15444 else
15445 vty_out(vty, " Peer-group type is external\n");
15446 }
15447
15448 /* Display AFs configured. */
15449 if (!json)
15450 vty_out(vty, " Configured address-families:");
15451
15452 FOREACH_AFI_SAFI (afi, safi) {
15453 if (conf->afc[afi][safi]) {
15454 af_cfgd = true;
15455 if (json)
15456 json_object_array_add(
15457 json_peer_group_afc,
15458 json_object_new_string(get_afi_safi_str(
15459 afi, safi, false)));
15460 else
15461 vty_out(vty, " %s;",
15462 get_afi_safi_str(afi, safi, false));
15463 }
15464 }
15465
15466 if (json) {
15467 json_object_object_add(json_peer_group,
15468 "addressFamiliesConfigured",
15469 json_peer_group_afc);
15470 } else {
15471 if (!af_cfgd)
15472 vty_out(vty, " none\n");
15473 else
15474 vty_out(vty, "\n");
15475 }
15476
15477 /* Display listen ranges (for dynamic neighbors), if any */
15478 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15479 lr_count = listcount(group->listen_range[afi]);
15480 if (lr_count) {
15481 if (json) {
15482 if (!json_peer_group_dynamic)
15483 json_peer_group_dynamic =
15484 json_object_new_object();
15485
15486 json_peer_group_dynamic_af =
15487 json_object_new_object();
15488 json_peer_group_ranges =
15489 json_object_new_array();
15490 json_object_int_add(json_peer_group_dynamic_af,
15491 "count", lr_count);
15492 } else {
15493 vty_out(vty, " %d %s listen range(s)\n",
15494 lr_count, afi2str(afi));
15495 }
15496
15497 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15498 nnode, range)) {
15499 if (json) {
15500 char buf[BUFSIZ];
15501
15502 snprintfrr(buf, sizeof(buf), "%pFX",
15503 range);
15504
15505 json_object_array_add(
15506 json_peer_group_ranges,
15507 json_object_new_string(buf));
15508 } else {
15509 vty_out(vty, " %pFX\n", range);
15510 }
15511 }
15512
15513 if (json) {
15514 json_object_object_add(
15515 json_peer_group_dynamic_af, "ranges",
15516 json_peer_group_ranges);
15517
15518 json_object_object_add(
15519 json_peer_group_dynamic, afi2str(afi),
15520 json_peer_group_dynamic_af);
15521 }
15522 }
15523 }
15524
15525 if (json_peer_group_dynamic)
15526 json_object_object_add(json_peer_group, "dynamicRanges",
15527 json_peer_group_dynamic);
15528
15529 /* Display group members and their status */
15530 if (listcount(group->peer)) {
15531 if (json)
15532 json_peer_group_members = json_object_new_object();
15533 else
15534 vty_out(vty, " Peer-group members:\n");
15535 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15536 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15537 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15538 peer_status = "Idle (Admin)";
15539 else if (CHECK_FLAG(peer->sflags,
15540 PEER_STATUS_PREFIX_OVERFLOW))
15541 peer_status = "Idle (PfxCt)";
15542 else
15543 peer_status = lookup_msg(bgp_status_msg,
15544 peer->status, NULL);
15545
15546 dynamic = peer_dynamic_neighbor(peer);
15547
15548 if (json) {
15549 json_object *json_peer_group_member =
15550 json_object_new_object();
15551
15552 json_object_string_add(json_peer_group_member,
15553 "status", peer_status);
15554
15555 if (dynamic)
15556 json_object_boolean_true_add(
15557 json_peer_group_member,
15558 "dynamic");
15559
15560 json_object_object_add(json_peer_group_members,
15561 peer->host,
15562 json_peer_group_member);
15563 } else {
15564 vty_out(vty, " %s %s %s \n", peer->host,
15565 dynamic ? "(dynamic)" : "",
15566 peer_status);
15567 }
15568 }
15569 if (json)
15570 json_object_object_add(json_peer_group, "members",
15571 json_peer_group_members);
15572 }
15573
15574 if (json)
15575 json_object_object_add(json, group->name, json_peer_group);
15576
15577 return CMD_SUCCESS;
15578 }
15579
15580 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15581 const char *group_name, bool uj)
15582 {
15583 struct bgp *bgp;
15584 struct listnode *node, *nnode;
15585 struct peer_group *group;
15586 bool found = false;
15587 json_object *json = NULL;
15588
15589 if (uj)
15590 json = json_object_new_object();
15591
15592 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15593
15594 if (!bgp) {
15595 if (uj)
15596 vty_json(vty, json);
15597 else
15598 vty_out(vty, "%% BGP instance not found\n");
15599
15600 return CMD_WARNING;
15601 }
15602
15603 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15604 if (group_name) {
15605 if (strmatch(group->name, group_name)) {
15606 bgp_show_one_peer_group(vty, group, json);
15607 found = true;
15608 break;
15609 }
15610 } else {
15611 bgp_show_one_peer_group(vty, group, json);
15612 }
15613 }
15614
15615 if (group_name && !found && !uj)
15616 vty_out(vty, "%% No such peer-group\n");
15617
15618 if (uj)
15619 vty_json(vty, json);
15620
15621 return CMD_SUCCESS;
15622 }
15623
15624 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15625 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15626 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15627 "Detailed information on BGP peer groups\n"
15628 "Peer group name\n" JSON_STR)
15629 {
15630 char *vrf, *pg;
15631 int idx = 0;
15632 bool uj = use_json(argc, argv);
15633
15634 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15635 : NULL;
15636 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15637
15638 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15639 }
15640
15641
15642 /* Redistribute VTY commands. */
15643
15644 DEFUN (bgp_redistribute_ipv4,
15645 bgp_redistribute_ipv4_cmd,
15646 "redistribute " FRR_IP_REDIST_STR_BGPD,
15647 "Redistribute information from another routing protocol\n"
15648 FRR_IP_REDIST_HELP_STR_BGPD)
15649 {
15650 VTY_DECLVAR_CONTEXT(bgp, bgp);
15651 int idx_protocol = 1;
15652 int type;
15653
15654 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15655 if (type < 0) {
15656 vty_out(vty, "%% Invalid route type\n");
15657 return CMD_WARNING_CONFIG_FAILED;
15658 }
15659
15660 bgp_redist_add(bgp, AFI_IP, type, 0);
15661 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15662 }
15663
15664 ALIAS_HIDDEN(
15665 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15666 "redistribute " FRR_IP_REDIST_STR_BGPD,
15667 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15668
15669 DEFUN (bgp_redistribute_ipv4_rmap,
15670 bgp_redistribute_ipv4_rmap_cmd,
15671 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15672 "Redistribute information from another routing protocol\n"
15673 FRR_IP_REDIST_HELP_STR_BGPD
15674 "Route map reference\n"
15675 "Pointer to route-map entries\n")
15676 {
15677 VTY_DECLVAR_CONTEXT(bgp, bgp);
15678 int idx_protocol = 1;
15679 int idx_word = 3;
15680 int type;
15681 struct bgp_redist *red;
15682 bool changed;
15683 struct route_map *route_map = route_map_lookup_warn_noexist(
15684 vty, argv[idx_word]->arg);
15685
15686 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15687 if (type < 0) {
15688 vty_out(vty, "%% Invalid route type\n");
15689 return CMD_WARNING_CONFIG_FAILED;
15690 }
15691
15692 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15693 changed =
15694 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15695 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15696 }
15697
15698 ALIAS_HIDDEN(
15699 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15700 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15701 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15702 "Route map reference\n"
15703 "Pointer to route-map entries\n")
15704
15705 DEFUN (bgp_redistribute_ipv4_metric,
15706 bgp_redistribute_ipv4_metric_cmd,
15707 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15708 "Redistribute information from another routing protocol\n"
15709 FRR_IP_REDIST_HELP_STR_BGPD
15710 "Metric for redistributed routes\n"
15711 "Default metric\n")
15712 {
15713 VTY_DECLVAR_CONTEXT(bgp, bgp);
15714 int idx_protocol = 1;
15715 int idx_number = 3;
15716 int type;
15717 uint32_t metric;
15718 struct bgp_redist *red;
15719 bool changed;
15720
15721 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15722 if (type < 0) {
15723 vty_out(vty, "%% Invalid route type\n");
15724 return CMD_WARNING_CONFIG_FAILED;
15725 }
15726 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15727
15728 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15729 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15730 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15731 }
15732
15733 ALIAS_HIDDEN(
15734 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15735 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15736 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15737 "Metric for redistributed routes\n"
15738 "Default metric\n")
15739
15740 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15741 bgp_redistribute_ipv4_rmap_metric_cmd,
15742 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15743 "Redistribute information from another routing protocol\n"
15744 FRR_IP_REDIST_HELP_STR_BGPD
15745 "Route map reference\n"
15746 "Pointer to route-map entries\n"
15747 "Metric for redistributed routes\n"
15748 "Default metric\n")
15749 {
15750 VTY_DECLVAR_CONTEXT(bgp, bgp);
15751 int idx_protocol = 1;
15752 int idx_word = 3;
15753 int idx_number = 5;
15754 int type;
15755 uint32_t metric;
15756 struct bgp_redist *red;
15757 bool changed;
15758 struct route_map *route_map =
15759 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15760
15761 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15762 if (type < 0) {
15763 vty_out(vty, "%% Invalid route type\n");
15764 return CMD_WARNING_CONFIG_FAILED;
15765 }
15766 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15767
15768 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15769 changed =
15770 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15771 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15772 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15773 }
15774
15775 ALIAS_HIDDEN(
15776 bgp_redistribute_ipv4_rmap_metric,
15777 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15778 "redistribute " FRR_IP_REDIST_STR_BGPD
15779 " route-map RMAP_NAME metric (0-4294967295)",
15780 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15781 "Route map reference\n"
15782 "Pointer to route-map entries\n"
15783 "Metric for redistributed routes\n"
15784 "Default metric\n")
15785
15786 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15787 bgp_redistribute_ipv4_metric_rmap_cmd,
15788 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15789 "Redistribute information from another routing protocol\n"
15790 FRR_IP_REDIST_HELP_STR_BGPD
15791 "Metric for redistributed routes\n"
15792 "Default metric\n"
15793 "Route map reference\n"
15794 "Pointer to route-map entries\n")
15795 {
15796 VTY_DECLVAR_CONTEXT(bgp, bgp);
15797 int idx_protocol = 1;
15798 int idx_number = 3;
15799 int idx_word = 5;
15800 int type;
15801 uint32_t metric;
15802 struct bgp_redist *red;
15803 bool changed;
15804 struct route_map *route_map =
15805 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15806
15807 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15808 if (type < 0) {
15809 vty_out(vty, "%% Invalid route type\n");
15810 return CMD_WARNING_CONFIG_FAILED;
15811 }
15812 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15813
15814 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15815 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15816 changed |=
15817 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15818 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15819 }
15820
15821 ALIAS_HIDDEN(
15822 bgp_redistribute_ipv4_metric_rmap,
15823 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15824 "redistribute " FRR_IP_REDIST_STR_BGPD
15825 " metric (0-4294967295) route-map RMAP_NAME",
15826 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15827 "Metric for redistributed routes\n"
15828 "Default metric\n"
15829 "Route map reference\n"
15830 "Pointer to route-map entries\n")
15831
15832 DEFUN (bgp_redistribute_ipv4_ospf,
15833 bgp_redistribute_ipv4_ospf_cmd,
15834 "redistribute <ospf|table> (1-65535)",
15835 "Redistribute information from another routing protocol\n"
15836 "Open Shortest Path First (OSPFv2)\n"
15837 "Non-main Kernel Routing Table\n"
15838 "Instance ID/Table ID\n")
15839 {
15840 VTY_DECLVAR_CONTEXT(bgp, bgp);
15841 int idx_ospf_table = 1;
15842 int idx_number = 2;
15843 unsigned short instance;
15844 unsigned short protocol;
15845
15846 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15847
15848 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15849 protocol = ZEBRA_ROUTE_OSPF;
15850 else
15851 protocol = ZEBRA_ROUTE_TABLE;
15852
15853 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15854 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15855 }
15856
15857 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15858 "redistribute <ospf|table> (1-65535)",
15859 "Redistribute information from another routing protocol\n"
15860 "Open Shortest Path First (OSPFv2)\n"
15861 "Non-main Kernel Routing Table\n"
15862 "Instance ID/Table ID\n")
15863
15864 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15865 bgp_redistribute_ipv4_ospf_rmap_cmd,
15866 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15867 "Redistribute information from another routing protocol\n"
15868 "Open Shortest Path First (OSPFv2)\n"
15869 "Non-main Kernel Routing Table\n"
15870 "Instance ID/Table ID\n"
15871 "Route map reference\n"
15872 "Pointer to route-map entries\n")
15873 {
15874 VTY_DECLVAR_CONTEXT(bgp, bgp);
15875 int idx_ospf_table = 1;
15876 int idx_number = 2;
15877 int idx_word = 4;
15878 struct bgp_redist *red;
15879 unsigned short instance;
15880 int protocol;
15881 bool changed;
15882 struct route_map *route_map =
15883 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15884
15885 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15886 protocol = ZEBRA_ROUTE_OSPF;
15887 else
15888 protocol = ZEBRA_ROUTE_TABLE;
15889
15890 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15891 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15892 changed =
15893 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15894 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15895 }
15896
15897 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15898 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15899 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15900 "Redistribute information from another routing protocol\n"
15901 "Open Shortest Path First (OSPFv2)\n"
15902 "Non-main Kernel Routing Table\n"
15903 "Instance ID/Table ID\n"
15904 "Route map reference\n"
15905 "Pointer to route-map entries\n")
15906
15907 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15908 bgp_redistribute_ipv4_ospf_metric_cmd,
15909 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15910 "Redistribute information from another routing protocol\n"
15911 "Open Shortest Path First (OSPFv2)\n"
15912 "Non-main Kernel Routing Table\n"
15913 "Instance ID/Table ID\n"
15914 "Metric for redistributed routes\n"
15915 "Default metric\n")
15916 {
15917 VTY_DECLVAR_CONTEXT(bgp, bgp);
15918 int idx_ospf_table = 1;
15919 int idx_number = 2;
15920 int idx_number_2 = 4;
15921 uint32_t metric;
15922 struct bgp_redist *red;
15923 unsigned short instance;
15924 int protocol;
15925 bool changed;
15926
15927 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15928 protocol = ZEBRA_ROUTE_OSPF;
15929 else
15930 protocol = ZEBRA_ROUTE_TABLE;
15931
15932 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15933 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15934
15935 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15936 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15937 metric);
15938 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15939 }
15940
15941 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15942 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15943 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15944 "Redistribute information from another routing protocol\n"
15945 "Open Shortest Path First (OSPFv2)\n"
15946 "Non-main Kernel Routing Table\n"
15947 "Instance ID/Table ID\n"
15948 "Metric for redistributed routes\n"
15949 "Default metric\n")
15950
15951 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15952 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15953 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
15954 "Redistribute information from another routing protocol\n"
15955 "Open Shortest Path First (OSPFv2)\n"
15956 "Non-main Kernel Routing Table\n"
15957 "Instance ID/Table ID\n"
15958 "Route map reference\n"
15959 "Pointer to route-map entries\n"
15960 "Metric for redistributed routes\n"
15961 "Default metric\n")
15962 {
15963 VTY_DECLVAR_CONTEXT(bgp, bgp);
15964 int idx_ospf_table = 1;
15965 int idx_number = 2;
15966 int idx_word = 4;
15967 int idx_number_2 = 6;
15968 uint32_t metric;
15969 struct bgp_redist *red;
15970 unsigned short instance;
15971 int protocol;
15972 bool changed;
15973 struct route_map *route_map =
15974 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15975
15976 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15977 protocol = ZEBRA_ROUTE_OSPF;
15978 else
15979 protocol = ZEBRA_ROUTE_TABLE;
15980
15981 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15982 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15983
15984 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15985 changed =
15986 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15987 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15988 metric);
15989 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15990 }
15991
15992 ALIAS_HIDDEN(
15993 bgp_redistribute_ipv4_ospf_rmap_metric,
15994 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15995 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
15996 "Redistribute information from another routing protocol\n"
15997 "Open Shortest Path First (OSPFv2)\n"
15998 "Non-main Kernel Routing Table\n"
15999 "Instance ID/Table ID\n"
16000 "Route map reference\n"
16001 "Pointer to route-map entries\n"
16002 "Metric for redistributed routes\n"
16003 "Default metric\n")
16004
16005 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16006 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16007 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16008 "Redistribute information from another routing protocol\n"
16009 "Open Shortest Path First (OSPFv2)\n"
16010 "Non-main Kernel Routing Table\n"
16011 "Instance ID/Table ID\n"
16012 "Metric for redistributed routes\n"
16013 "Default metric\n"
16014 "Route map reference\n"
16015 "Pointer to route-map entries\n")
16016 {
16017 VTY_DECLVAR_CONTEXT(bgp, bgp);
16018 int idx_ospf_table = 1;
16019 int idx_number = 2;
16020 int idx_number_2 = 4;
16021 int idx_word = 6;
16022 uint32_t metric;
16023 struct bgp_redist *red;
16024 unsigned short instance;
16025 int protocol;
16026 bool changed;
16027 struct route_map *route_map =
16028 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16029
16030 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16031 protocol = ZEBRA_ROUTE_OSPF;
16032 else
16033 protocol = ZEBRA_ROUTE_TABLE;
16034
16035 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16036 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16037
16038 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16039 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16040 metric);
16041 changed |=
16042 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16043 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16044 }
16045
16046 ALIAS_HIDDEN(
16047 bgp_redistribute_ipv4_ospf_metric_rmap,
16048 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16049 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16050 "Redistribute information from another routing protocol\n"
16051 "Open Shortest Path First (OSPFv2)\n"
16052 "Non-main Kernel Routing Table\n"
16053 "Instance ID/Table ID\n"
16054 "Metric for redistributed routes\n"
16055 "Default metric\n"
16056 "Route map reference\n"
16057 "Pointer to route-map entries\n")
16058
16059 DEFUN (no_bgp_redistribute_ipv4_ospf,
16060 no_bgp_redistribute_ipv4_ospf_cmd,
16061 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16062 NO_STR
16063 "Redistribute information from another routing protocol\n"
16064 "Open Shortest Path First (OSPFv2)\n"
16065 "Non-main Kernel Routing Table\n"
16066 "Instance ID/Table ID\n"
16067 "Metric for redistributed routes\n"
16068 "Default metric\n"
16069 "Route map reference\n"
16070 "Pointer to route-map entries\n")
16071 {
16072 VTY_DECLVAR_CONTEXT(bgp, bgp);
16073 int idx_ospf_table = 2;
16074 int idx_number = 3;
16075 unsigned short instance;
16076 int protocol;
16077
16078 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16079 protocol = ZEBRA_ROUTE_OSPF;
16080 else
16081 protocol = ZEBRA_ROUTE_TABLE;
16082
16083 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16084 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16085 }
16086
16087 ALIAS_HIDDEN(
16088 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16089 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16090 NO_STR
16091 "Redistribute information from another routing protocol\n"
16092 "Open Shortest Path First (OSPFv2)\n"
16093 "Non-main Kernel Routing Table\n"
16094 "Instance ID/Table ID\n"
16095 "Metric for redistributed routes\n"
16096 "Default metric\n"
16097 "Route map reference\n"
16098 "Pointer to route-map entries\n")
16099
16100 DEFUN (no_bgp_redistribute_ipv4,
16101 no_bgp_redistribute_ipv4_cmd,
16102 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16103 NO_STR
16104 "Redistribute information from another routing protocol\n"
16105 FRR_IP_REDIST_HELP_STR_BGPD
16106 "Metric for redistributed routes\n"
16107 "Default metric\n"
16108 "Route map reference\n"
16109 "Pointer to route-map entries\n")
16110 {
16111 VTY_DECLVAR_CONTEXT(bgp, bgp);
16112 int idx_protocol = 2;
16113 int type;
16114
16115 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16116 if (type < 0) {
16117 vty_out(vty, "%% Invalid route type\n");
16118 return CMD_WARNING_CONFIG_FAILED;
16119 }
16120 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16121 }
16122
16123 ALIAS_HIDDEN(
16124 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16125 "no redistribute " FRR_IP_REDIST_STR_BGPD
16126 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16127 NO_STR
16128 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16129 "Metric for redistributed routes\n"
16130 "Default metric\n"
16131 "Route map reference\n"
16132 "Pointer to route-map entries\n")
16133
16134 DEFUN (bgp_redistribute_ipv6,
16135 bgp_redistribute_ipv6_cmd,
16136 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16137 "Redistribute information from another routing protocol\n"
16138 FRR_IP6_REDIST_HELP_STR_BGPD)
16139 {
16140 VTY_DECLVAR_CONTEXT(bgp, bgp);
16141 int idx_protocol = 1;
16142 int type;
16143
16144 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16145 if (type < 0) {
16146 vty_out(vty, "%% Invalid route type\n");
16147 return CMD_WARNING_CONFIG_FAILED;
16148 }
16149
16150 bgp_redist_add(bgp, AFI_IP6, type, 0);
16151 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16152 }
16153
16154 DEFUN (bgp_redistribute_ipv6_rmap,
16155 bgp_redistribute_ipv6_rmap_cmd,
16156 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16157 "Redistribute information from another routing protocol\n"
16158 FRR_IP6_REDIST_HELP_STR_BGPD
16159 "Route map reference\n"
16160 "Pointer to route-map entries\n")
16161 {
16162 VTY_DECLVAR_CONTEXT(bgp, bgp);
16163 int idx_protocol = 1;
16164 int idx_word = 3;
16165 int type;
16166 struct bgp_redist *red;
16167 bool changed;
16168 struct route_map *route_map =
16169 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16170
16171 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16172 if (type < 0) {
16173 vty_out(vty, "%% Invalid route type\n");
16174 return CMD_WARNING_CONFIG_FAILED;
16175 }
16176
16177 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16178 changed =
16179 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16180 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16181 }
16182
16183 DEFUN (bgp_redistribute_ipv6_metric,
16184 bgp_redistribute_ipv6_metric_cmd,
16185 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16186 "Redistribute information from another routing protocol\n"
16187 FRR_IP6_REDIST_HELP_STR_BGPD
16188 "Metric for redistributed routes\n"
16189 "Default metric\n")
16190 {
16191 VTY_DECLVAR_CONTEXT(bgp, bgp);
16192 int idx_protocol = 1;
16193 int idx_number = 3;
16194 int type;
16195 uint32_t metric;
16196 struct bgp_redist *red;
16197 bool changed;
16198
16199 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16200 if (type < 0) {
16201 vty_out(vty, "%% Invalid route type\n");
16202 return CMD_WARNING_CONFIG_FAILED;
16203 }
16204 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16205
16206 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16207 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16208 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16209 }
16210
16211 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16212 bgp_redistribute_ipv6_rmap_metric_cmd,
16213 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16214 "Redistribute information from another routing protocol\n"
16215 FRR_IP6_REDIST_HELP_STR_BGPD
16216 "Route map reference\n"
16217 "Pointer to route-map entries\n"
16218 "Metric for redistributed routes\n"
16219 "Default metric\n")
16220 {
16221 VTY_DECLVAR_CONTEXT(bgp, bgp);
16222 int idx_protocol = 1;
16223 int idx_word = 3;
16224 int idx_number = 5;
16225 int type;
16226 uint32_t metric;
16227 struct bgp_redist *red;
16228 bool changed;
16229 struct route_map *route_map =
16230 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16231
16232 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16233 if (type < 0) {
16234 vty_out(vty, "%% Invalid route type\n");
16235 return CMD_WARNING_CONFIG_FAILED;
16236 }
16237 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16238
16239 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16240 changed =
16241 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16242 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16243 metric);
16244 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16245 }
16246
16247 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16248 bgp_redistribute_ipv6_metric_rmap_cmd,
16249 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16250 "Redistribute information from another routing protocol\n"
16251 FRR_IP6_REDIST_HELP_STR_BGPD
16252 "Metric for redistributed routes\n"
16253 "Default metric\n"
16254 "Route map reference\n"
16255 "Pointer to route-map entries\n")
16256 {
16257 VTY_DECLVAR_CONTEXT(bgp, bgp);
16258 int idx_protocol = 1;
16259 int idx_number = 3;
16260 int idx_word = 5;
16261 int type;
16262 uint32_t metric;
16263 struct bgp_redist *red;
16264 bool changed;
16265 struct route_map *route_map =
16266 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16267
16268 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16269 if (type < 0) {
16270 vty_out(vty, "%% Invalid route type\n");
16271 return CMD_WARNING_CONFIG_FAILED;
16272 }
16273 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16274
16275 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16276 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16277 metric);
16278 changed |=
16279 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16280 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16281 }
16282
16283 DEFUN (no_bgp_redistribute_ipv6,
16284 no_bgp_redistribute_ipv6_cmd,
16285 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16286 NO_STR
16287 "Redistribute information from another routing protocol\n"
16288 FRR_IP6_REDIST_HELP_STR_BGPD
16289 "Metric for redistributed routes\n"
16290 "Default metric\n"
16291 "Route map reference\n"
16292 "Pointer to route-map entries\n")
16293 {
16294 VTY_DECLVAR_CONTEXT(bgp, bgp);
16295 int idx_protocol = 2;
16296 int type;
16297
16298 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16299 if (type < 0) {
16300 vty_out(vty, "%% Invalid route type\n");
16301 return CMD_WARNING_CONFIG_FAILED;
16302 }
16303
16304 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16305 }
16306
16307 /* Neighbor update tcp-mss. */
16308 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16309 const char *tcp_mss_str)
16310 {
16311 struct peer *peer;
16312 uint32_t tcp_mss_val = 0;
16313
16314 peer = peer_and_group_lookup_vty(vty, peer_str);
16315 if (!peer)
16316 return CMD_WARNING_CONFIG_FAILED;
16317
16318 if (tcp_mss_str) {
16319 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16320 peer_tcp_mss_set(peer, tcp_mss_val);
16321 } else {
16322 peer_tcp_mss_unset(peer);
16323 }
16324
16325 return CMD_SUCCESS;
16326 }
16327
16328 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16329 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16330 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16331 "TCP max segment size\n"
16332 "TCP MSS value\n")
16333 {
16334 int peer_index = 1;
16335 int mss_index = 3;
16336
16337 vty_out(vty,
16338 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16339 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16340 argv[mss_index]->arg);
16341 }
16342
16343 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16344 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16345 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16346 "TCP max segment size\n"
16347 "TCP MSS value\n")
16348 {
16349 int peer_index = 2;
16350
16351 vty_out(vty,
16352 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16353 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16354 }
16355
16356 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16357 "[no$no] bgp retain route-target all",
16358 NO_STR BGP_STR
16359 "Retain BGP updates\n"
16360 "Retain BGP updates based on route-target values\n"
16361 "Retain all BGP updates\n")
16362 {
16363 bool check;
16364 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16365
16366 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16367 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16368 if (check != !no) {
16369 if (!no)
16370 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16371 [bgp_node_safi(vty)],
16372 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16373 else
16374 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16375 [bgp_node_safi(vty)],
16376 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16377 /* trigger a flush to re-sync with ADJ-RIB-in */
16378 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16379 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16380 }
16381 return CMD_SUCCESS;
16382 }
16383
16384 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16385 afi_t afi, safi_t safi)
16386 {
16387 int i;
16388
16389 /* Unicast redistribution only. */
16390 if (safi != SAFI_UNICAST)
16391 return;
16392
16393 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16394 /* Redistribute BGP does not make sense. */
16395 if (i != ZEBRA_ROUTE_BGP) {
16396 struct list *red_list;
16397 struct listnode *node;
16398 struct bgp_redist *red;
16399
16400 red_list = bgp->redist[afi][i];
16401 if (!red_list)
16402 continue;
16403
16404 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16405 /* "redistribute" configuration. */
16406 vty_out(vty, " redistribute %s",
16407 zebra_route_string(i));
16408 if (red->instance)
16409 vty_out(vty, " %d", red->instance);
16410 if (red->redist_metric_flag)
16411 vty_out(vty, " metric %u",
16412 red->redist_metric);
16413 if (red->rmap.name)
16414 vty_out(vty, " route-map %s",
16415 red->rmap.name);
16416 vty_out(vty, "\n");
16417 }
16418 }
16419 }
16420 }
16421
16422 /* peer-group helpers for config-write */
16423
16424 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16425 {
16426 if (!peer_group_active(peer)) {
16427 if (CHECK_FLAG(peer->flags_invert, flag))
16428 return !CHECK_FLAG(peer->flags, flag);
16429 else
16430 return !!CHECK_FLAG(peer->flags, flag);
16431 }
16432
16433 return !!CHECK_FLAG(peer->flags_override, flag);
16434 }
16435
16436 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16437 uint32_t flag)
16438 {
16439 if (!peer_group_active(peer)) {
16440 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16441 return !peer_af_flag_check(peer, afi, safi, flag);
16442 else
16443 return !!peer_af_flag_check(peer, afi, safi, flag);
16444 }
16445
16446 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16447 }
16448
16449 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16450 uint8_t type, int direct)
16451 {
16452 struct bgp_filter *filter;
16453
16454 if (peer_group_active(peer))
16455 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16456 type);
16457
16458 filter = &peer->filter[afi][safi];
16459 switch (type) {
16460 case PEER_FT_DISTRIBUTE_LIST:
16461 return !!(filter->dlist[direct].name);
16462 case PEER_FT_FILTER_LIST:
16463 return !!(filter->aslist[direct].name);
16464 case PEER_FT_PREFIX_LIST:
16465 return !!(filter->plist[direct].name);
16466 case PEER_FT_ROUTE_MAP:
16467 return !!(filter->map[direct].name);
16468 case PEER_FT_UNSUPPRESS_MAP:
16469 return !!(filter->usmap.name);
16470 case PEER_FT_ADVERTISE_MAP:
16471 return !!(filter->advmap.aname
16472 && ((filter->advmap.condition == direct)
16473 && filter->advmap.cname));
16474 default:
16475 return false;
16476 }
16477 }
16478
16479 /* Return true if the addpath type is set for peer and different from
16480 * peer-group.
16481 */
16482 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16483 safi_t safi)
16484 {
16485 enum bgp_addpath_strat type, g_type;
16486
16487 type = peer->addpath_type[afi][safi];
16488
16489 if (type != BGP_ADDPATH_NONE) {
16490 if (peer_group_active(peer)) {
16491 g_type = peer->group->conf->addpath_type[afi][safi];
16492
16493 if (type != g_type)
16494 return true;
16495 else
16496 return false;
16497 }
16498
16499 return true;
16500 }
16501
16502 return false;
16503 }
16504
16505 /* This is part of the address-family block (unicast only) */
16506 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16507 afi_t afi)
16508 {
16509 int indent = 2;
16510 uint32_t tovpn_sid_index = 0;
16511
16512 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16513 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16514 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16515 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16516 bgp->vpn_policy[afi]
16517 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16518 else
16519 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16520 bgp->vpn_policy[afi]
16521 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16522 }
16523 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16524 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16525 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16526 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16527 return;
16528
16529 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16530 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16531
16532 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16533
16534 } else {
16535 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16536 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16537 bgp->vpn_policy[afi].tovpn_label);
16538 }
16539 }
16540
16541 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16542 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16543 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16544 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16545 } else if (tovpn_sid_index != 0) {
16546 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16547 tovpn_sid_index);
16548 }
16549
16550 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16551 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16552 char buf[RD_ADDRSTRLEN];
16553 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16554 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16555 sizeof(buf)));
16556 }
16557 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16558 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16559
16560 char buf[PREFIX_STRLEN];
16561 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16562 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16563 sizeof(buf))) {
16564
16565 vty_out(vty, "%*snexthop vpn export %s\n",
16566 indent, "", buf);
16567 }
16568 }
16569 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16570 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16571 && ecommunity_cmp(
16572 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16573 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16574
16575 char *b = ecommunity_ecom2str(
16576 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16577 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16578 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16579 XFREE(MTYPE_ECOMMUNITY_STR, b);
16580 } else {
16581 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16582 char *b = ecommunity_ecom2str(
16583 bgp->vpn_policy[afi]
16584 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16585 ECOMMUNITY_FORMAT_ROUTE_MAP,
16586 ECOMMUNITY_ROUTE_TARGET);
16587 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16588 XFREE(MTYPE_ECOMMUNITY_STR, b);
16589 }
16590 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16591 char *b = ecommunity_ecom2str(
16592 bgp->vpn_policy[afi]
16593 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16594 ECOMMUNITY_FORMAT_ROUTE_MAP,
16595 ECOMMUNITY_ROUTE_TARGET);
16596 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16597 XFREE(MTYPE_ECOMMUNITY_STR, b);
16598 }
16599 }
16600
16601 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16602 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16603 bgp->vpn_policy[afi]
16604 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16605
16606 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16607 char *b = ecommunity_ecom2str(
16608 bgp->vpn_policy[afi]
16609 .import_redirect_rtlist,
16610 ECOMMUNITY_FORMAT_ROUTE_MAP,
16611 ECOMMUNITY_ROUTE_TARGET);
16612
16613 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16614 != ECOMMUNITY_SIZE)
16615 vty_out(vty, "%*srt6 redirect import %s\n",
16616 indent, "", b);
16617 else
16618 vty_out(vty, "%*srt redirect import %s\n",
16619 indent, "", b);
16620 XFREE(MTYPE_ECOMMUNITY_STR, b);
16621 }
16622 }
16623
16624 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16625 afi_t afi, safi_t safi)
16626 {
16627 struct bgp_filter *filter;
16628 char *addr;
16629
16630 addr = peer->host;
16631 filter = &peer->filter[afi][safi];
16632
16633 /* distribute-list. */
16634 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16635 FILTER_IN))
16636 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16637 filter->dlist[FILTER_IN].name);
16638
16639 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16640 FILTER_OUT))
16641 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16642 filter->dlist[FILTER_OUT].name);
16643
16644 /* prefix-list. */
16645 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16646 FILTER_IN))
16647 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16648 filter->plist[FILTER_IN].name);
16649
16650 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16651 FILTER_OUT))
16652 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16653 filter->plist[FILTER_OUT].name);
16654
16655 /* route-map. */
16656 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16657 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16658 filter->map[RMAP_IN].name);
16659
16660 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16661 RMAP_OUT))
16662 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16663 filter->map[RMAP_OUT].name);
16664
16665 /* unsuppress-map */
16666 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16667 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16668 filter->usmap.name);
16669
16670 /* advertise-map : always applied in OUT direction*/
16671 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16672 CONDITION_NON_EXIST))
16673 vty_out(vty,
16674 " neighbor %s advertise-map %s non-exist-map %s\n",
16675 addr, filter->advmap.aname, filter->advmap.cname);
16676
16677 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16678 CONDITION_EXIST))
16679 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16680 addr, filter->advmap.aname, filter->advmap.cname);
16681
16682 /* filter-list. */
16683 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16684 FILTER_IN))
16685 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16686 filter->aslist[FILTER_IN].name);
16687
16688 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16689 FILTER_OUT))
16690 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16691 filter->aslist[FILTER_OUT].name);
16692 }
16693
16694 /* BGP peer configuration display function. */
16695 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16696 struct peer *peer)
16697 {
16698 struct peer *g_peer = NULL;
16699 char *addr;
16700 int if_pg_printed = false;
16701 int if_ras_printed = false;
16702
16703 /* Skip dynamic neighbors. */
16704 if (peer_dynamic_neighbor(peer))
16705 return;
16706
16707 if (peer->conf_if)
16708 addr = peer->conf_if;
16709 else
16710 addr = peer->host;
16711
16712 /************************************
16713 ****** Global to the neighbor ******
16714 ************************************/
16715 if (peer->conf_if) {
16716 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16717 vty_out(vty, " neighbor %s interface v6only", addr);
16718 else
16719 vty_out(vty, " neighbor %s interface", addr);
16720
16721 if (peer_group_active(peer)) {
16722 vty_out(vty, " peer-group %s", peer->group->name);
16723 if_pg_printed = true;
16724 } else if (peer->as_type == AS_SPECIFIED) {
16725 vty_out(vty, " remote-as %u", peer->as);
16726 if_ras_printed = true;
16727 } else if (peer->as_type == AS_INTERNAL) {
16728 vty_out(vty, " remote-as internal");
16729 if_ras_printed = true;
16730 } else if (peer->as_type == AS_EXTERNAL) {
16731 vty_out(vty, " remote-as external");
16732 if_ras_printed = true;
16733 }
16734
16735 vty_out(vty, "\n");
16736 }
16737
16738 /* remote-as and peer-group */
16739 /* peer is a member of a peer-group */
16740 if (peer_group_active(peer)) {
16741 g_peer = peer->group->conf;
16742
16743 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16744 if (peer->as_type == AS_SPECIFIED) {
16745 vty_out(vty, " neighbor %s remote-as %u\n",
16746 addr, peer->as);
16747 } else if (peer->as_type == AS_INTERNAL) {
16748 vty_out(vty,
16749 " neighbor %s remote-as internal\n",
16750 addr);
16751 } else if (peer->as_type == AS_EXTERNAL) {
16752 vty_out(vty,
16753 " neighbor %s remote-as external\n",
16754 addr);
16755 }
16756 }
16757
16758 /* For swpX peers we displayed the peer-group
16759 * via 'neighbor swpX interface peer-group PGNAME' */
16760 if (!if_pg_printed)
16761 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16762 peer->group->name);
16763 }
16764
16765 /* peer is NOT a member of a peer-group */
16766 else {
16767 /* peer is a peer-group, declare the peer-group */
16768 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16769 vty_out(vty, " neighbor %s peer-group\n", addr);
16770 }
16771
16772 if (!if_ras_printed) {
16773 if (peer->as_type == AS_SPECIFIED) {
16774 vty_out(vty, " neighbor %s remote-as %u\n",
16775 addr, peer->as);
16776 } else if (peer->as_type == AS_INTERNAL) {
16777 vty_out(vty,
16778 " neighbor %s remote-as internal\n",
16779 addr);
16780 } else if (peer->as_type == AS_EXTERNAL) {
16781 vty_out(vty,
16782 " neighbor %s remote-as external\n",
16783 addr);
16784 }
16785 }
16786 }
16787
16788 /* local-as */
16789 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16790 vty_out(vty, " neighbor %s local-as %u", addr,
16791 peer->change_local_as);
16792 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16793 vty_out(vty, " no-prepend");
16794 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16795 vty_out(vty, " replace-as");
16796 vty_out(vty, "\n");
16797 }
16798
16799 /* description */
16800 if (peer->desc) {
16801 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16802 }
16803
16804 /* shutdown */
16805 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16806 if (peer->tx_shutdown_message)
16807 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16808 peer->tx_shutdown_message);
16809 else
16810 vty_out(vty, " neighbor %s shutdown\n", addr);
16811 }
16812
16813 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16814 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16815 peer->rtt_expected, peer->rtt_keepalive_conf);
16816
16817 /* bfd */
16818 if (peer->bfd_config)
16819 bgp_bfd_peer_config_write(vty, peer, addr);
16820
16821 /* password */
16822 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16823 vty_out(vty, " neighbor %s password %s\n", addr,
16824 peer->password);
16825
16826 /* neighbor solo */
16827 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16828 if (!peer_group_active(peer)) {
16829 vty_out(vty, " neighbor %s solo\n", addr);
16830 }
16831 }
16832
16833 /* BGP port */
16834 if (peer->port != BGP_PORT_DEFAULT) {
16835 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16836 }
16837
16838 /* Local interface name */
16839 if (peer->ifname) {
16840 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16841 }
16842
16843 /* TCP max segment size */
16844 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16845 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16846
16847 /* passive */
16848 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16849 vty_out(vty, " neighbor %s passive\n", addr);
16850
16851 /* ebgp-multihop */
16852 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16853 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16854 && peer->ttl == MAXTTL)) {
16855 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16856 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16857 peer->ttl);
16858 }
16859 }
16860
16861 /* role */
16862 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16863 peer->local_role != ROLE_UNDEFINED)
16864 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16865 bgp_get_name_by_role(peer->local_role),
16866 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
16867 ? " strict-mode"
16868 : "");
16869
16870 /* ttl-security hops */
16871 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16872 if (!peer_group_active(peer)
16873 || g_peer->gtsm_hops != peer->gtsm_hops) {
16874 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16875 addr, peer->gtsm_hops);
16876 }
16877 }
16878
16879 /* disable-connected-check */
16880 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16881 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16882
16883 /* link-bw-encoding-ieee */
16884 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16885 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16886 addr);
16887
16888 /* extended-optional-parameters */
16889 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16890 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16891 addr);
16892
16893 /* enforce-first-as */
16894 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16895 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16896
16897 /* update-source */
16898 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16899 if (peer->update_source)
16900 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16901 peer->update_source);
16902 else if (peer->update_if)
16903 vty_out(vty, " neighbor %s update-source %s\n", addr,
16904 peer->update_if);
16905 }
16906
16907 /* advertisement-interval */
16908 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16909 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16910 peer->routeadv);
16911
16912 /* timers */
16913 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16914 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16915 peer->keepalive, peer->holdtime);
16916
16917 /* timers connect */
16918 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16919 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16920 peer->connect);
16921 /* need special-case handling for changed default values due to
16922 * config profile / version (because there is no "timers bgp connect"
16923 * command, we need to save this per-peer :/)
16924 */
16925 else if (!peer_group_active(peer) && !peer->connect &&
16926 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16927 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16928 peer->bgp->default_connect_retry);
16929
16930 /* timers delayopen */
16931 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16932 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16933 peer->delayopen);
16934 /* Save config even though flag is not set if default values have been
16935 * changed
16936 */
16937 else if (!peer_group_active(peer) && !peer->delayopen
16938 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16939 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16940 peer->bgp->default_delayopen);
16941
16942 /* capability dynamic */
16943 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16944 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16945
16946 /* capability extended-nexthop */
16947 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16948 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
16949 !peer->conf_if)
16950 vty_out(vty,
16951 " no neighbor %s capability extended-nexthop\n",
16952 addr);
16953 else if (!peer->conf_if)
16954 vty_out(vty,
16955 " neighbor %s capability extended-nexthop\n",
16956 addr);
16957 }
16958
16959 /* dont-capability-negotiation */
16960 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16961 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16962
16963 /* override-capability */
16964 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16965 vty_out(vty, " neighbor %s override-capability\n", addr);
16966
16967 /* strict-capability-match */
16968 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16969 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16970
16971 /* Sender side AS path loop detection. */
16972 if (peer->as_path_loop_detection)
16973 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16974 addr);
16975
16976 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16977 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16978
16979 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16980 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16981 vty_out(vty,
16982 " neighbor %s graceful-restart-helper\n", addr);
16983 } else if (CHECK_FLAG(
16984 peer->peer_gr_new_status_flag,
16985 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16986 vty_out(vty,
16987 " neighbor %s graceful-restart\n", addr);
16988 } else if (
16989 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16990 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16991 && !(CHECK_FLAG(
16992 peer->peer_gr_new_status_flag,
16993 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16994 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16995 addr);
16996 }
16997 }
16998 }
16999
17000 /* BGP peer configuration display function. */
17001 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17002 struct peer *peer, afi_t afi, safi_t safi)
17003 {
17004 struct peer *g_peer = NULL;
17005 char *addr;
17006 bool flag_scomm, flag_secomm, flag_slcomm;
17007
17008 /* Skip dynamic neighbors. */
17009 if (peer_dynamic_neighbor(peer))
17010 return;
17011
17012 if (peer->conf_if)
17013 addr = peer->conf_if;
17014 else
17015 addr = peer->host;
17016
17017 /************************************
17018 ****** Per AF to the neighbor ******
17019 ************************************/
17020 if (peer_group_active(peer)) {
17021 g_peer = peer->group->conf;
17022
17023 /* If the peer-group is active but peer is not, print a 'no
17024 * activate' */
17025 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17026 vty_out(vty, " no neighbor %s activate\n", addr);
17027 }
17028
17029 /* If the peer-group is not active but peer is, print an
17030 'activate' */
17031 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17032 vty_out(vty, " neighbor %s activate\n", addr);
17033 }
17034 } else {
17035 if (peer->afc[afi][safi]) {
17036 if (safi == SAFI_ENCAP)
17037 vty_out(vty, " neighbor %s activate\n", addr);
17038 else if (!bgp->default_af[afi][safi])
17039 vty_out(vty, " neighbor %s activate\n", addr);
17040 } else {
17041 if (bgp->default_af[afi][safi])
17042 vty_out(vty, " no neighbor %s activate\n",
17043 addr);
17044 }
17045 }
17046
17047 /* addpath TX knobs */
17048 if (peergroup_af_addpath_check(peer, afi, safi)) {
17049 switch (peer->addpath_type[afi][safi]) {
17050 case BGP_ADDPATH_ALL:
17051 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17052 addr);
17053 break;
17054 case BGP_ADDPATH_BEST_PER_AS:
17055 vty_out(vty,
17056 " neighbor %s addpath-tx-bestpath-per-AS\n",
17057 addr);
17058 break;
17059 case BGP_ADDPATH_MAX:
17060 case BGP_ADDPATH_NONE:
17061 break;
17062 }
17063 }
17064
17065 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17066 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17067
17068 /* ORF capability. */
17069 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17070 || peergroup_af_flag_check(peer, afi, safi,
17071 PEER_FLAG_ORF_PREFIX_RM)) {
17072 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17073
17074 if (peergroup_af_flag_check(peer, afi, safi,
17075 PEER_FLAG_ORF_PREFIX_SM)
17076 && peergroup_af_flag_check(peer, afi, safi,
17077 PEER_FLAG_ORF_PREFIX_RM))
17078 vty_out(vty, " both");
17079 else if (peergroup_af_flag_check(peer, afi, safi,
17080 PEER_FLAG_ORF_PREFIX_SM))
17081 vty_out(vty, " send");
17082 else
17083 vty_out(vty, " receive");
17084 vty_out(vty, "\n");
17085 }
17086
17087 /* Route reflector client. */
17088 if (peergroup_af_flag_check(peer, afi, safi,
17089 PEER_FLAG_REFLECTOR_CLIENT)) {
17090 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17091 }
17092
17093 /* next-hop-self force */
17094 if (peergroup_af_flag_check(peer, afi, safi,
17095 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17096 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17097 }
17098
17099 /* next-hop-self */
17100 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17101 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17102 }
17103
17104 /* remove-private-AS */
17105 if (peergroup_af_flag_check(peer, afi, safi,
17106 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17107 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17108 addr);
17109 }
17110
17111 else if (peergroup_af_flag_check(peer, afi, safi,
17112 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17113 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17114 addr);
17115 }
17116
17117 else if (peergroup_af_flag_check(peer, afi, safi,
17118 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17119 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17120 }
17121
17122 else if (peergroup_af_flag_check(peer, afi, safi,
17123 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17124 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17125 }
17126
17127 /* as-override */
17128 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17129 vty_out(vty, " neighbor %s as-override\n", addr);
17130 }
17131
17132 /* send-community print. */
17133 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17134 PEER_FLAG_SEND_COMMUNITY);
17135 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17136 PEER_FLAG_SEND_EXT_COMMUNITY);
17137 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17138 PEER_FLAG_SEND_LARGE_COMMUNITY);
17139
17140 if (flag_scomm && flag_secomm && flag_slcomm) {
17141 vty_out(vty, " no neighbor %s send-community all\n", addr);
17142 } else {
17143 if (flag_scomm)
17144 vty_out(vty, " no neighbor %s send-community\n", addr);
17145 if (flag_secomm)
17146 vty_out(vty,
17147 " no neighbor %s send-community extended\n",
17148 addr);
17149
17150 if (flag_slcomm)
17151 vty_out(vty, " no neighbor %s send-community large\n",
17152 addr);
17153 }
17154
17155 /* Default information */
17156 if (peergroup_af_flag_check(peer, afi, safi,
17157 PEER_FLAG_DEFAULT_ORIGINATE)) {
17158 vty_out(vty, " neighbor %s default-originate", addr);
17159
17160 if (peer->default_rmap[afi][safi].name)
17161 vty_out(vty, " route-map %s",
17162 peer->default_rmap[afi][safi].name);
17163
17164 vty_out(vty, "\n");
17165 }
17166
17167 /* Soft reconfiguration inbound. */
17168 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17169 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17170 addr);
17171 }
17172
17173 /* maximum-prefix. */
17174 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17175 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17176 peer->pmax[afi][safi]);
17177
17178 if (peer->pmax_threshold[afi][safi]
17179 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17180 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17181 if (peer_af_flag_check(peer, afi, safi,
17182 PEER_FLAG_MAX_PREFIX_WARNING))
17183 vty_out(vty, " warning-only");
17184 if (peer->pmax_restart[afi][safi])
17185 vty_out(vty, " restart %u",
17186 peer->pmax_restart[afi][safi]);
17187 if (peer_af_flag_check(peer, afi, safi,
17188 PEER_FLAG_MAX_PREFIX_FORCE))
17189 vty_out(vty, " force");
17190
17191 vty_out(vty, "\n");
17192 }
17193
17194 /* maximum-prefix-out */
17195 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17196 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17197 addr, peer->pmax_out[afi][safi]);
17198
17199 /* Route server client. */
17200 if (peergroup_af_flag_check(peer, afi, safi,
17201 PEER_FLAG_RSERVER_CLIENT)) {
17202 vty_out(vty, " neighbor %s route-server-client\n", addr);
17203 }
17204
17205 /* Nexthop-local unchanged. */
17206 if (peergroup_af_flag_check(peer, afi, safi,
17207 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17208 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17209 }
17210
17211 /* allowas-in <1-10> */
17212 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17213 if (peer_af_flag_check(peer, afi, safi,
17214 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17215 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17216 } else if (peer->allowas_in[afi][safi] == 3) {
17217 vty_out(vty, " neighbor %s allowas-in\n", addr);
17218 } else {
17219 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17220 peer->allowas_in[afi][safi]);
17221 }
17222 }
17223
17224 /* weight */
17225 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17226 vty_out(vty, " neighbor %s weight %lu\n", addr,
17227 peer->weight[afi][safi]);
17228
17229 /* Filter. */
17230 bgp_config_write_filter(vty, peer, afi, safi);
17231
17232 /* atribute-unchanged. */
17233 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17234 || (safi != SAFI_EVPN
17235 && peer_af_flag_check(peer, afi, safi,
17236 PEER_FLAG_NEXTHOP_UNCHANGED))
17237 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17238
17239 if (!peer_group_active(peer)
17240 || peergroup_af_flag_check(peer, afi, safi,
17241 PEER_FLAG_AS_PATH_UNCHANGED)
17242 || peergroup_af_flag_check(peer, afi, safi,
17243 PEER_FLAG_NEXTHOP_UNCHANGED)
17244 || peergroup_af_flag_check(peer, afi, safi,
17245 PEER_FLAG_MED_UNCHANGED)) {
17246
17247 vty_out(vty,
17248 " neighbor %s attribute-unchanged%s%s%s\n",
17249 addr,
17250 peer_af_flag_check(peer, afi, safi,
17251 PEER_FLAG_AS_PATH_UNCHANGED)
17252 ? " as-path"
17253 : "",
17254 peer_af_flag_check(peer, afi, safi,
17255 PEER_FLAG_NEXTHOP_UNCHANGED)
17256 ? " next-hop"
17257 : "",
17258 peer_af_flag_check(peer, afi, safi,
17259 PEER_FLAG_MED_UNCHANGED)
17260 ? " med"
17261 : "");
17262 }
17263 }
17264 }
17265
17266 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17267 safi_t safi)
17268 {
17269 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17270 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17271 vty_out(vty, " no bgp retain route-target all\n");
17272 }
17273
17274 /* Address family based peer configuration display. */
17275 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17276 safi_t safi)
17277 {
17278 struct peer *peer;
17279 struct peer_group *group;
17280 struct listnode *node, *nnode;
17281
17282
17283 vty_frame(vty, " !\n address-family ");
17284 if (afi == AFI_IP) {
17285 if (safi == SAFI_UNICAST)
17286 vty_frame(vty, "ipv4 unicast");
17287 else if (safi == SAFI_LABELED_UNICAST)
17288 vty_frame(vty, "ipv4 labeled-unicast");
17289 else if (safi == SAFI_MULTICAST)
17290 vty_frame(vty, "ipv4 multicast");
17291 else if (safi == SAFI_MPLS_VPN)
17292 vty_frame(vty, "ipv4 vpn");
17293 else if (safi == SAFI_ENCAP)
17294 vty_frame(vty, "ipv4 encap");
17295 else if (safi == SAFI_FLOWSPEC)
17296 vty_frame(vty, "ipv4 flowspec");
17297 } else if (afi == AFI_IP6) {
17298 if (safi == SAFI_UNICAST)
17299 vty_frame(vty, "ipv6 unicast");
17300 else if (safi == SAFI_LABELED_UNICAST)
17301 vty_frame(vty, "ipv6 labeled-unicast");
17302 else if (safi == SAFI_MULTICAST)
17303 vty_frame(vty, "ipv6 multicast");
17304 else if (safi == SAFI_MPLS_VPN)
17305 vty_frame(vty, "ipv6 vpn");
17306 else if (safi == SAFI_ENCAP)
17307 vty_frame(vty, "ipv6 encap");
17308 else if (safi == SAFI_FLOWSPEC)
17309 vty_frame(vty, "ipv6 flowspec");
17310 } else if (afi == AFI_L2VPN) {
17311 if (safi == SAFI_EVPN)
17312 vty_frame(vty, "l2vpn evpn");
17313 }
17314 vty_frame(vty, "\n");
17315
17316 bgp_config_write_distance(vty, bgp, afi, safi);
17317
17318 bgp_config_write_network(vty, bgp, afi, safi);
17319
17320 bgp_config_write_redistribute(vty, bgp, afi, safi);
17321
17322 /* BGP flag dampening. */
17323 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17324 bgp_config_write_damp(vty, afi, safi);
17325
17326 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17327 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17328
17329 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17330 /* Do not display doppelganger peers */
17331 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17332 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17333 }
17334
17335 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17336 bgp_config_write_table_map(vty, bgp, afi, safi);
17337
17338 if (safi == SAFI_EVPN)
17339 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17340
17341 if (safi == SAFI_FLOWSPEC)
17342 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17343
17344 if (safi == SAFI_MPLS_VPN)
17345 bgp_vpn_config_write(vty, bgp, afi, safi);
17346
17347 if (safi == SAFI_UNICAST) {
17348 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17349 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17350 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17351
17352 vty_out(vty, " export vpn\n");
17353 }
17354 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17355 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17356
17357 vty_out(vty, " import vpn\n");
17358 }
17359 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17360 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17361 char *name;
17362
17363 for (ALL_LIST_ELEMENTS_RO(
17364 bgp->vpn_policy[afi].import_vrf, node,
17365 name))
17366 vty_out(vty, " import vrf %s\n", name);
17367 }
17368 }
17369
17370 vty_endframe(vty, " exit-address-family\n");
17371 }
17372
17373 int bgp_config_write(struct vty *vty)
17374 {
17375 struct bgp *bgp;
17376 struct peer_group *group;
17377 struct peer *peer;
17378 struct listnode *node, *nnode;
17379 struct listnode *mnode, *mnnode;
17380 afi_t afi;
17381 safi_t safi;
17382
17383 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17384 vty_out(vty, "bgp route-map delay-timer %u\n",
17385 bm->rmap_update_timer);
17386
17387 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17388 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17389 if (bm->v_update_delay != bm->v_establish_wait)
17390 vty_out(vty, " %d", bm->v_establish_wait);
17391 vty_out(vty, "\n");
17392 }
17393
17394 if (bm->wait_for_fib)
17395 vty_out(vty, "bgp suppress-fib-pending\n");
17396
17397 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17398 vty_out(vty, "bgp graceful-shutdown\n");
17399
17400 /* No-RIB (Zebra) option flag configuration */
17401 if (bgp_option_check(BGP_OPT_NO_FIB))
17402 vty_out(vty, "bgp no-rib\n");
17403
17404 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17405 vty_out(vty, "bgp send-extra-data zebra\n");
17406
17407 /* BGP session DSCP value */
17408 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17409 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17410
17411 /* BGP configuration. */
17412 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17413
17414 /* skip all auto created vrf as they dont have user config */
17415 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17416 continue;
17417
17418 /* Router bgp ASN */
17419 vty_out(vty, "router bgp %u", bgp->as);
17420
17421 if (bgp->name)
17422 vty_out(vty, " %s %s",
17423 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17424 ? "view" : "vrf", bgp->name);
17425 vty_out(vty, "\n");
17426
17427 /* BGP fast-external-failover. */
17428 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17429 vty_out(vty, " no bgp fast-external-failover\n");
17430
17431 /* BGP router ID. */
17432 if (bgp->router_id_static.s_addr != INADDR_ANY)
17433 vty_out(vty, " bgp router-id %pI4\n",
17434 &bgp->router_id_static);
17435
17436 /* Suppress fib pending */
17437 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17438 vty_out(vty, " bgp suppress-fib-pending\n");
17439
17440 /* BGP log-neighbor-changes. */
17441 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17442 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17443 vty_out(vty, " %sbgp log-neighbor-changes\n",
17444 CHECK_FLAG(bgp->flags,
17445 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17446 ? ""
17447 : "no ");
17448
17449 /* BGP configuration. */
17450 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17451 vty_out(vty, " bgp always-compare-med\n");
17452
17453 /* RFC8212 default eBGP policy. */
17454 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17455 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17456 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17457 CHECK_FLAG(bgp->flags,
17458 BGP_FLAG_EBGP_REQUIRES_POLICY)
17459 ? ""
17460 : "no ");
17461
17462 /* draft-ietf-idr-deprecate-as-set-confed-set */
17463 if (bgp->reject_as_sets)
17464 vty_out(vty, " bgp reject-as-sets\n");
17465
17466 /* Suppress duplicate updates if the route actually not changed
17467 */
17468 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17469 != SAVE_BGP_SUPPRESS_DUPLICATES)
17470 vty_out(vty, " %sbgp suppress-duplicates\n",
17471 CHECK_FLAG(bgp->flags,
17472 BGP_FLAG_SUPPRESS_DUPLICATES)
17473 ? ""
17474 : "no ");
17475
17476 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17477 */
17478 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17479 SAVE_BGP_HARD_ADMIN_RESET)
17480 vty_out(vty, " %sbgp hard-administrative-reset\n",
17481 CHECK_FLAG(bgp->flags,
17482 BGP_FLAG_HARD_ADMIN_RESET)
17483 ? ""
17484 : "no ");
17485
17486 /* BGP default <afi>-<safi> */
17487 FOREACH_AFI_SAFI (afi, safi) {
17488 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17489 if (!bgp->default_af[afi][safi])
17490 vty_out(vty, " no bgp default %s\n",
17491 get_bgp_default_af_flag(afi,
17492 safi));
17493 } else if (bgp->default_af[afi][safi])
17494 vty_out(vty, " bgp default %s\n",
17495 get_bgp_default_af_flag(afi, safi));
17496 }
17497
17498 /* BGP default local-preference. */
17499 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17500 vty_out(vty, " bgp default local-preference %u\n",
17501 bgp->default_local_pref);
17502
17503 /* BGP default show-hostname */
17504 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17505 != SAVE_BGP_SHOW_HOSTNAME)
17506 vty_out(vty, " %sbgp default show-hostname\n",
17507 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17508 ? ""
17509 : "no ");
17510
17511 /* BGP default show-nexthop-hostname */
17512 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17513 != SAVE_BGP_SHOW_HOSTNAME)
17514 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17515 CHECK_FLAG(bgp->flags,
17516 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17517 ? ""
17518 : "no ");
17519
17520 /* BGP default subgroup-pkt-queue-max. */
17521 if (bgp->default_subgroup_pkt_queue_max
17522 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17523 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17524 bgp->default_subgroup_pkt_queue_max);
17525
17526 /* BGP client-to-client reflection. */
17527 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17528 vty_out(vty, " no bgp client-to-client reflection\n");
17529
17530 /* BGP cluster ID. */
17531 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17532 vty_out(vty, " bgp cluster-id %pI4\n",
17533 &bgp->cluster_id);
17534
17535 /* Disable ebgp connected nexthop check */
17536 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17537 vty_out(vty,
17538 " bgp disable-ebgp-connected-route-check\n");
17539
17540 /* Confederation identifier*/
17541 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17542 vty_out(vty, " bgp confederation identifier %u\n",
17543 bgp->confed_id);
17544
17545 /* Confederation peer */
17546 if (bgp->confed_peers_cnt > 0) {
17547 int i;
17548
17549 vty_out(vty, " bgp confederation peers");
17550
17551 for (i = 0; i < bgp->confed_peers_cnt; i++)
17552 vty_out(vty, " %u", bgp->confed_peers[i]);
17553
17554 vty_out(vty, "\n");
17555 }
17556
17557 /* BGP deterministic-med. */
17558 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17559 != SAVE_BGP_DETERMINISTIC_MED)
17560 vty_out(vty, " %sbgp deterministic-med\n",
17561 CHECK_FLAG(bgp->flags,
17562 BGP_FLAG_DETERMINISTIC_MED)
17563 ? ""
17564 : "no ");
17565
17566 /* BGP update-delay. */
17567 bgp_config_write_update_delay(vty, bgp);
17568
17569 if (bgp->v_maxmed_onstartup
17570 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17571 vty_out(vty, " bgp max-med on-startup %u",
17572 bgp->v_maxmed_onstartup);
17573 if (bgp->maxmed_onstartup_value
17574 != BGP_MAXMED_VALUE_DEFAULT)
17575 vty_out(vty, " %u",
17576 bgp->maxmed_onstartup_value);
17577 vty_out(vty, "\n");
17578 }
17579 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17580 vty_out(vty, " bgp max-med administrative");
17581 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17582 vty_out(vty, " %u", bgp->maxmed_admin_value);
17583 vty_out(vty, "\n");
17584 }
17585
17586 /* write quanta */
17587 bgp_config_write_wpkt_quanta(vty, bgp);
17588 /* read quanta */
17589 bgp_config_write_rpkt_quanta(vty, bgp);
17590
17591 /* coalesce time */
17592 bgp_config_write_coalesce_time(vty, bgp);
17593
17594 /* BGP per-instance graceful-shutdown */
17595 /* BGP-wide settings and per-instance settings are mutually
17596 * exclusive.
17597 */
17598 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17599 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17600 vty_out(vty, " bgp graceful-shutdown\n");
17601
17602 /* Long-lived Graceful Restart */
17603 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17604 vty_out(vty,
17605 " bgp long-lived-graceful-restart stale-time %u\n",
17606 bgp->llgr_stale_time);
17607
17608 /* BGP graceful-restart. */
17609 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17610 vty_out(vty,
17611 " bgp graceful-restart stalepath-time %u\n",
17612 bgp->stalepath_time);
17613
17614 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17615 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17616 bgp->restart_time);
17617
17618 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17619 SAVE_BGP_GRACEFUL_NOTIFICATION)
17620 vty_out(vty, " %sbgp graceful-restart notification\n",
17621 CHECK_FLAG(bgp->flags,
17622 BGP_FLAG_GRACEFUL_NOTIFICATION)
17623 ? ""
17624 : "no ");
17625
17626 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17627 vty_out(vty,
17628 " bgp graceful-restart select-defer-time %u\n",
17629 bgp->select_defer_time);
17630
17631 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17632 vty_out(vty, " bgp graceful-restart\n");
17633
17634 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17635 vty_out(vty, " bgp graceful-restart-disable\n");
17636
17637 /* BGP graceful-restart Preserve State F bit. */
17638 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17639 vty_out(vty,
17640 " bgp graceful-restart preserve-fw-state\n");
17641
17642 /* Stale timer for RIB */
17643 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17644 vty_out(vty,
17645 " bgp graceful-restart rib-stale-time %u\n",
17646 bgp->rib_stale_time);
17647
17648 /* BGP bestpath method. */
17649 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17650 vty_out(vty, " bgp bestpath as-path ignore\n");
17651 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17652 vty_out(vty, " bgp bestpath as-path confed\n");
17653
17654 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17655 if (CHECK_FLAG(bgp->flags,
17656 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17657 vty_out(vty,
17658 " bgp bestpath as-path multipath-relax as-set\n");
17659 } else {
17660 vty_out(vty,
17661 " bgp bestpath as-path multipath-relax\n");
17662 }
17663 }
17664
17665 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17666 vty_out(vty,
17667 " bgp route-reflector allow-outbound-policy\n");
17668 }
17669 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17670 vty_out(vty, " bgp bestpath compare-routerid\n");
17671 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17672 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17673 vty_out(vty, " bgp bestpath med");
17674 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17675 vty_out(vty, " confed");
17676 if (CHECK_FLAG(bgp->flags,
17677 BGP_FLAG_MED_MISSING_AS_WORST))
17678 vty_out(vty, " missing-as-worst");
17679 vty_out(vty, "\n");
17680 }
17681
17682 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17683 vty_out(vty,
17684 " bgp bestpath peer-type multipath-relax\n");
17685
17686 /* Link bandwidth handling. */
17687 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17688 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17689 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17690 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17691 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17692 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17693
17694 /* BGP network import check. */
17695 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17696 != SAVE_BGP_IMPORT_CHECK)
17697 vty_out(vty, " %sbgp network import-check\n",
17698 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17699 ? ""
17700 : "no ");
17701
17702 /* BGP timers configuration. */
17703 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17704 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17705 vty_out(vty, " timers bgp %u %u\n",
17706 bgp->default_keepalive, bgp->default_holdtime);
17707
17708 /* BGP minimum holdtime configuration. */
17709 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17710 && bgp->default_min_holdtime != 0)
17711 vty_out(vty, " bgp minimum-holdtime %u\n",
17712 bgp->default_min_holdtime);
17713
17714 /* Conditional advertisement timer configuration */
17715 if (bgp->condition_check_period
17716 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17717 vty_out(vty,
17718 " bgp conditional-advertisement timer %u\n",
17719 bgp->condition_check_period);
17720
17721 /* peer-group */
17722 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17723 bgp_config_write_peer_global(vty, bgp, group->conf);
17724 }
17725
17726 /* Normal neighbor configuration. */
17727 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17728 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17729 bgp_config_write_peer_global(vty, bgp, peer);
17730 }
17731
17732 /* listen range and limit for dynamic BGP neighbors */
17733 bgp_config_write_listen(vty, bgp);
17734
17735 /*
17736 * BGP default autoshutdown neighbors
17737 *
17738 * This must be placed after any peer and peer-group
17739 * configuration, to avoid setting all peers to shutdown after
17740 * a daemon restart, which is undesired behavior. (see #2286)
17741 */
17742 if (bgp->autoshutdown)
17743 vty_out(vty, " bgp default shutdown\n");
17744
17745 /* BGP instance administrative shutdown */
17746 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17747 vty_out(vty, " bgp shutdown\n");
17748
17749 if (bgp->allow_martian)
17750 vty_out(vty, " bgp allow-martian-nexthop\n");
17751
17752 if (bgp->fast_convergence)
17753 vty_out(vty, " bgp fast-convergence\n");
17754
17755 if (bgp->srv6_enabled) {
17756 vty_frame(vty, " !\n segment-routing srv6\n");
17757 if (strlen(bgp->srv6_locator_name))
17758 vty_out(vty, " locator %s\n",
17759 bgp->srv6_locator_name);
17760 vty_endframe(vty, " exit\n");
17761 }
17762
17763
17764 /* IPv4 unicast configuration. */
17765 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17766
17767 /* IPv4 multicast configuration. */
17768 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17769
17770 /* IPv4 labeled-unicast configuration. */
17771 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17772
17773 /* IPv4 VPN configuration. */
17774 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17775
17776 /* ENCAPv4 configuration. */
17777 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17778
17779 /* FLOWSPEC v4 configuration. */
17780 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17781
17782 /* IPv6 unicast configuration. */
17783 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17784
17785 /* IPv6 multicast configuration. */
17786 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17787
17788 /* IPv6 labeled-unicast configuration. */
17789 bgp_config_write_family(vty, bgp, AFI_IP6,
17790 SAFI_LABELED_UNICAST);
17791
17792 /* IPv6 VPN configuration. */
17793 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17794
17795 /* ENCAPv6 configuration. */
17796 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17797
17798 /* FLOWSPEC v6 configuration. */
17799 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17800
17801 /* EVPN configuration. */
17802 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17803
17804 hook_call(bgp_inst_config_write, bgp, vty);
17805
17806 #ifdef ENABLE_BGP_VNC
17807 bgp_rfapi_cfg_write(vty, bgp);
17808 #endif
17809
17810 vty_out(vty, "exit\n");
17811 vty_out(vty, "!\n");
17812 }
17813 return 0;
17814 }
17815
17816
17817 /* BGP node structure. */
17818 static struct cmd_node bgp_node = {
17819 .name = "bgp",
17820 .node = BGP_NODE,
17821 .parent_node = CONFIG_NODE,
17822 .prompt = "%s(config-router)# ",
17823 .config_write = bgp_config_write,
17824 };
17825
17826 static struct cmd_node bgp_ipv4_unicast_node = {
17827 .name = "bgp ipv4 unicast",
17828 .node = BGP_IPV4_NODE,
17829 .parent_node = BGP_NODE,
17830 .prompt = "%s(config-router-af)# ",
17831 .no_xpath = true,
17832 };
17833
17834 static struct cmd_node bgp_ipv4_multicast_node = {
17835 .name = "bgp ipv4 multicast",
17836 .node = BGP_IPV4M_NODE,
17837 .parent_node = BGP_NODE,
17838 .prompt = "%s(config-router-af)# ",
17839 .no_xpath = true,
17840 };
17841
17842 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17843 .name = "bgp ipv4 labeled unicast",
17844 .node = BGP_IPV4L_NODE,
17845 .parent_node = BGP_NODE,
17846 .prompt = "%s(config-router-af)# ",
17847 .no_xpath = true,
17848 };
17849
17850 static struct cmd_node bgp_ipv6_unicast_node = {
17851 .name = "bgp ipv6 unicast",
17852 .node = BGP_IPV6_NODE,
17853 .parent_node = BGP_NODE,
17854 .prompt = "%s(config-router-af)# ",
17855 .no_xpath = true,
17856 };
17857
17858 static struct cmd_node bgp_ipv6_multicast_node = {
17859 .name = "bgp ipv6 multicast",
17860 .node = BGP_IPV6M_NODE,
17861 .parent_node = BGP_NODE,
17862 .prompt = "%s(config-router-af)# ",
17863 .no_xpath = true,
17864 };
17865
17866 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17867 .name = "bgp ipv6 labeled unicast",
17868 .node = BGP_IPV6L_NODE,
17869 .parent_node = BGP_NODE,
17870 .prompt = "%s(config-router-af)# ",
17871 .no_xpath = true,
17872 };
17873
17874 static struct cmd_node bgp_vpnv4_node = {
17875 .name = "bgp vpnv4",
17876 .node = BGP_VPNV4_NODE,
17877 .parent_node = BGP_NODE,
17878 .prompt = "%s(config-router-af)# ",
17879 .no_xpath = true,
17880 };
17881
17882 static struct cmd_node bgp_vpnv6_node = {
17883 .name = "bgp vpnv6",
17884 .node = BGP_VPNV6_NODE,
17885 .parent_node = BGP_NODE,
17886 .prompt = "%s(config-router-af-vpnv6)# ",
17887 .no_xpath = true,
17888 };
17889
17890 static struct cmd_node bgp_evpn_node = {
17891 .name = "bgp evpn",
17892 .node = BGP_EVPN_NODE,
17893 .parent_node = BGP_NODE,
17894 .prompt = "%s(config-router-evpn)# ",
17895 .no_xpath = true,
17896 };
17897
17898 static struct cmd_node bgp_evpn_vni_node = {
17899 .name = "bgp evpn vni",
17900 .node = BGP_EVPN_VNI_NODE,
17901 .parent_node = BGP_EVPN_NODE,
17902 .prompt = "%s(config-router-af-vni)# ",
17903 };
17904
17905 static struct cmd_node bgp_flowspecv4_node = {
17906 .name = "bgp ipv4 flowspec",
17907 .node = BGP_FLOWSPECV4_NODE,
17908 .parent_node = BGP_NODE,
17909 .prompt = "%s(config-router-af)# ",
17910 .no_xpath = true,
17911 };
17912
17913 static struct cmd_node bgp_flowspecv6_node = {
17914 .name = "bgp ipv6 flowspec",
17915 .node = BGP_FLOWSPECV6_NODE,
17916 .parent_node = BGP_NODE,
17917 .prompt = "%s(config-router-af-vpnv6)# ",
17918 .no_xpath = true,
17919 };
17920
17921 static struct cmd_node bgp_srv6_node = {
17922 .name = "bgp srv6",
17923 .node = BGP_SRV6_NODE,
17924 .parent_node = BGP_NODE,
17925 .prompt = "%s(config-router-srv6)# ",
17926 };
17927
17928 static void community_list_vty(void);
17929
17930 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17931 {
17932 struct bgp *bgp;
17933 struct peer_group *group;
17934 struct listnode *lnbgp, *lnpeer;
17935
17936 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17937 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17938 vector_set(comps,
17939 XSTRDUP(MTYPE_COMPLETION, group->name));
17940 }
17941 }
17942
17943 static void bgp_ac_peer(vector comps, struct cmd_token *token)
17944 {
17945 struct bgp *bgp;
17946 struct peer *peer;
17947 struct listnode *lnbgp, *lnpeer;
17948
17949 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17950 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17951 /* only provide suggestions on the appropriate input
17952 * token type,
17953 * they'll otherwise show up multiple times */
17954 enum cmd_token_type match_type;
17955 char *name = peer->host;
17956
17957 if (peer->conf_if) {
17958 match_type = VARIABLE_TKN;
17959 name = peer->conf_if;
17960 } else if (strchr(peer->host, ':'))
17961 match_type = IPV6_TKN;
17962 else
17963 match_type = IPV4_TKN;
17964
17965 if (token->type != match_type)
17966 continue;
17967
17968 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17969 }
17970 }
17971 }
17972
17973 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17974 {
17975 bgp_ac_peer(comps, token);
17976
17977 if (token->type == VARIABLE_TKN)
17978 bgp_ac_peergroup(comps, token);
17979 }
17980
17981 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17982 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17983 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17984 {.varname = "peer", .completions = bgp_ac_neighbor},
17985 {.completions = NULL}};
17986
17987 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17988 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17989 {.completions = NULL} };
17990
17991 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
17992
17993 static struct thread *t_bgp_cfg;
17994
17995 bool bgp_config_inprocess(void)
17996 {
17997 return thread_is_scheduled(t_bgp_cfg);
17998 }
17999
18000 static void bgp_config_finish(struct thread *t)
18001 {
18002 struct listnode *node;
18003 struct bgp *bgp;
18004
18005 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18006 hook_call(bgp_config_end, bgp);
18007 }
18008
18009 static void bgp_config_start(void)
18010 {
18011 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18012 THREAD_OFF(t_bgp_cfg);
18013 thread_add_timer(bm->master, bgp_config_finish, NULL,
18014 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18015 }
18016
18017 /* When we receive a hook the configuration is read,
18018 * we start a timer to make sure we postpone sending
18019 * EoR before route-maps are processed.
18020 * This is especially valid if using `bgp route-map delay-timer`.
18021 */
18022 static void bgp_config_end(void)
18023 {
18024 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18025 uint32_t bgp_post_config_delay =
18026 thread_is_scheduled(bm->t_rmap_update)
18027 ? thread_timer_remain_second(bm->t_rmap_update)
18028 : BGP_POST_CONFIG_DELAY_SECONDS;
18029
18030 /* If BGP config processing thread isn't running, then
18031 * we can return and rely it's properly handled.
18032 */
18033 if (!bgp_config_inprocess())
18034 return;
18035
18036 THREAD_OFF(t_bgp_cfg);
18037
18038 /* Start a new timer to make sure we don't send EoR
18039 * before route-maps are processed.
18040 */
18041 thread_add_timer(bm->master, bgp_config_finish, NULL,
18042 bgp_post_config_delay, &t_bgp_cfg);
18043 }
18044
18045 void bgp_vty_init(void)
18046 {
18047 cmd_variable_handler_register(bgp_var_neighbor);
18048 cmd_variable_handler_register(bgp_var_peergroup);
18049
18050 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18051
18052 /* Install bgp top node. */
18053 install_node(&bgp_node);
18054 install_node(&bgp_ipv4_unicast_node);
18055 install_node(&bgp_ipv4_multicast_node);
18056 install_node(&bgp_ipv4_labeled_unicast_node);
18057 install_node(&bgp_ipv6_unicast_node);
18058 install_node(&bgp_ipv6_multicast_node);
18059 install_node(&bgp_ipv6_labeled_unicast_node);
18060 install_node(&bgp_vpnv4_node);
18061 install_node(&bgp_vpnv6_node);
18062 install_node(&bgp_evpn_node);
18063 install_node(&bgp_evpn_vni_node);
18064 install_node(&bgp_flowspecv4_node);
18065 install_node(&bgp_flowspecv6_node);
18066 install_node(&bgp_srv6_node);
18067
18068 /* Install default VTY commands to new nodes. */
18069 install_default(BGP_NODE);
18070 install_default(BGP_IPV4_NODE);
18071 install_default(BGP_IPV4M_NODE);
18072 install_default(BGP_IPV4L_NODE);
18073 install_default(BGP_IPV6_NODE);
18074 install_default(BGP_IPV6M_NODE);
18075 install_default(BGP_IPV6L_NODE);
18076 install_default(BGP_VPNV4_NODE);
18077 install_default(BGP_VPNV6_NODE);
18078 install_default(BGP_FLOWSPECV4_NODE);
18079 install_default(BGP_FLOWSPECV6_NODE);
18080 install_default(BGP_EVPN_NODE);
18081 install_default(BGP_EVPN_VNI_NODE);
18082 install_default(BGP_SRV6_NODE);
18083
18084 /* "bgp local-mac" hidden commands. */
18085 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18086 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18087
18088 /* "bgp suppress-fib-pending" global */
18089 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18090
18091 /* bgp route-map delay-timer commands. */
18092 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18093 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18094
18095 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18096
18097 /* bgp fast-convergence command */
18098 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18099 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18100
18101 /* global bgp update-delay command */
18102 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18103 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18104
18105 /* global bgp graceful-shutdown command */
18106 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18107 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18108
18109 /* Dummy commands (Currently not supported) */
18110 install_element(BGP_NODE, &no_synchronization_cmd);
18111 install_element(BGP_NODE, &no_auto_summary_cmd);
18112
18113 /* "router bgp" commands. */
18114 install_element(CONFIG_NODE, &router_bgp_cmd);
18115
18116 /* "no router bgp" commands. */
18117 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18118
18119 /* "bgp session-dscp command */
18120 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18121 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18122
18123 /* "bgp router-id" commands. */
18124 install_element(BGP_NODE, &bgp_router_id_cmd);
18125 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18126
18127 /* "bgp suppress-fib-pending" command */
18128 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18129
18130 /* "bgp cluster-id" commands. */
18131 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18132 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18133
18134 /* "bgp no-rib" commands. */
18135 install_element(CONFIG_NODE, &bgp_norib_cmd);
18136 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18137
18138 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18139
18140 /* "bgp confederation" commands. */
18141 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18142 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18143
18144 /* "bgp confederation peers" commands. */
18145 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18146 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18147
18148 /* bgp max-med command */
18149 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18150 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18151 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18152 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18153 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18154
18155 /* "neighbor role" commands. */
18156 install_element(BGP_NODE, &neighbor_role_cmd);
18157 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18158 install_element(BGP_NODE, &no_neighbor_role_cmd);
18159
18160 /* bgp disable-ebgp-connected-nh-check */
18161 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18162 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18163
18164 /* bgp update-delay command */
18165 install_element(BGP_NODE, &bgp_update_delay_cmd);
18166 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18167
18168 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18169 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18170
18171 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18172 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18173
18174 /* "maximum-paths" commands. */
18175 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18176 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18177 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18178 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18179 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18180 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18181 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18182 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18183 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18184 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18185 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18186 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18187 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18188 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18189 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18190
18191 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18192 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18193 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18194 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18195 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18196 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18197 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18198 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18199 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18200 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18201
18202 /* "timers bgp" commands. */
18203 install_element(BGP_NODE, &bgp_timers_cmd);
18204 install_element(BGP_NODE, &no_bgp_timers_cmd);
18205
18206 /* "minimum-holdtime" commands. */
18207 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18208 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18209
18210 /* route-map delay-timer commands - per instance for backwards compat.
18211 */
18212 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18213 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18214
18215 /* "bgp client-to-client reflection" commands */
18216 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18217 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18218
18219 /* "bgp always-compare-med" commands */
18220 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18221 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18222
18223 /* bgp ebgp-requires-policy */
18224 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18225 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18226
18227 /* bgp suppress-duplicates */
18228 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18229 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18230
18231 /* bgp reject-as-sets */
18232 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18233 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18234
18235 /* "bgp deterministic-med" commands */
18236 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18237 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18238
18239 /* "bgp graceful-restart" command */
18240 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18241 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18242
18243 /* "bgp graceful-restart-disable" command */
18244 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18245 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18246
18247 /* "neighbor a:b:c:d graceful-restart" command */
18248 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18249 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18250
18251 /* "neighbor a:b:c:d graceful-restart-disable" command */
18252 install_element(BGP_NODE,
18253 &bgp_neighbor_graceful_restart_disable_set_cmd);
18254 install_element(BGP_NODE,
18255 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18256
18257 /* "neighbor a:b:c:d graceful-restart-helper" command */
18258 install_element(BGP_NODE,
18259 &bgp_neighbor_graceful_restart_helper_set_cmd);
18260 install_element(BGP_NODE,
18261 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18262
18263 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18264 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18265 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18266 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18267 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18268 install_element(BGP_NODE,
18269 &no_bgp_graceful_restart_select_defer_time_cmd);
18270 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18271 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18272 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18273
18274 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18275 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18276 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18277 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18278
18279 /* "bgp graceful-shutdown" commands */
18280 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18281 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18282
18283 /* "bgp hard-administrative-reset" commands */
18284 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18285
18286 /* "bgp long-lived-graceful-restart" commands */
18287 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18288 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18289
18290 /* "bgp fast-external-failover" commands */
18291 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18292 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18293
18294 /* "bgp bestpath compare-routerid" commands */
18295 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18296 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18297
18298 /* "bgp bestpath as-path ignore" commands */
18299 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18300 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18301
18302 /* "bgp bestpath as-path confed" commands */
18303 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18304 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18305
18306 /* "bgp bestpath as-path multipath-relax" commands */
18307 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18308 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18309
18310 /* "bgp bestpath peer-type multipath-relax" commands */
18311 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18312 install_element(BGP_NODE,
18313 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18314
18315 /* "bgp log-neighbor-changes" commands */
18316 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18317 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18318
18319 /* "bgp bestpath med" commands */
18320 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18321 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18322
18323 /* "bgp bestpath bandwidth" commands */
18324 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18325 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18326
18327 /* "no bgp default <afi>-<safi>" commands. */
18328 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18329
18330 /* "bgp network import-check" commands. */
18331 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18332 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18333 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18334
18335 /* "bgp default local-preference" commands. */
18336 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18337 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18338
18339 /* bgp default show-hostname */
18340 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18341 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18342
18343 /* bgp default show-nexthop-hostname */
18344 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18345 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18346
18347 /* "bgp default subgroup-pkt-queue-max" commands. */
18348 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18349 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18350
18351 /* bgp ibgp-allow-policy-mods command */
18352 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18353 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18354
18355 /* "bgp listen limit" commands. */
18356 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18357 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18358
18359 /* "bgp listen range" commands. */
18360 install_element(BGP_NODE, &bgp_listen_range_cmd);
18361 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18362
18363 /* "bgp default shutdown" command */
18364 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18365
18366 /* "bgp shutdown" commands */
18367 install_element(BGP_NODE, &bgp_shutdown_cmd);
18368 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18369 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18370 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18371
18372 /* "neighbor remote-as" commands. */
18373 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18374 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18375 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18376 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18377 install_element(BGP_NODE,
18378 &neighbor_interface_v6only_config_remote_as_cmd);
18379 install_element(BGP_NODE, &no_neighbor_cmd);
18380 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18381
18382 /* "neighbor peer-group" commands. */
18383 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18384 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18385 install_element(BGP_NODE,
18386 &no_neighbor_interface_peer_group_remote_as_cmd);
18387
18388 /* "neighbor local-as" commands. */
18389 install_element(BGP_NODE, &neighbor_local_as_cmd);
18390 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18391 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18392 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18393
18394 /* "neighbor solo" commands. */
18395 install_element(BGP_NODE, &neighbor_solo_cmd);
18396 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18397
18398 /* "neighbor password" commands. */
18399 install_element(BGP_NODE, &neighbor_password_cmd);
18400 install_element(BGP_NODE, &no_neighbor_password_cmd);
18401
18402 /* "neighbor activate" commands. */
18403 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18404 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18405 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18406 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18407 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18408 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18409 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18410 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18411 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18412 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18413 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18414 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18415
18416 /* "no neighbor activate" commands. */
18417 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18418 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18419 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18420 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18421 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18422 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18423 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18424 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18425 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18426 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18427 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18428 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18429
18430 /* "neighbor peer-group" set commands. */
18431 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18432 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18433 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18434 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18435 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18436 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18437 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18438 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18439 install_element(BGP_FLOWSPECV4_NODE,
18440 &neighbor_set_peer_group_hidden_cmd);
18441 install_element(BGP_FLOWSPECV6_NODE,
18442 &neighbor_set_peer_group_hidden_cmd);
18443
18444 /* "no neighbor peer-group unset" commands. */
18445 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18446 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18447 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18448 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18449 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18450 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18451 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18452 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18453 install_element(BGP_FLOWSPECV4_NODE,
18454 &no_neighbor_set_peer_group_hidden_cmd);
18455 install_element(BGP_FLOWSPECV6_NODE,
18456 &no_neighbor_set_peer_group_hidden_cmd);
18457
18458 /* "neighbor softreconfiguration inbound" commands.*/
18459 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18460 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18461 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18462 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18463 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18464 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18465 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18466 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18467 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18468 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18469 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18470 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18471 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18472 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18473 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18474 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18475 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18476 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18477 install_element(BGP_FLOWSPECV4_NODE,
18478 &neighbor_soft_reconfiguration_cmd);
18479 install_element(BGP_FLOWSPECV4_NODE,
18480 &no_neighbor_soft_reconfiguration_cmd);
18481 install_element(BGP_FLOWSPECV6_NODE,
18482 &neighbor_soft_reconfiguration_cmd);
18483 install_element(BGP_FLOWSPECV6_NODE,
18484 &no_neighbor_soft_reconfiguration_cmd);
18485 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18486 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18487
18488 /* "neighbor attribute-unchanged" commands. */
18489 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18490 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18491 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18492 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18493 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18494 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18495 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18496 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18497 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18498 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18499 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18500 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18501 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18502 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18503 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18504 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18505 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18506 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18507
18508 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18509 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18510
18511 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18512 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18513 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18514 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18515
18516 /* "nexthop-local unchanged" commands */
18517 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18518 install_element(BGP_IPV6_NODE,
18519 &no_neighbor_nexthop_local_unchanged_cmd);
18520
18521 /* "neighbor next-hop-self" commands. */
18522 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18523 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18524 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18525 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18526 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18527 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18528 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18529 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18530 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18531 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18532 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18533 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18534 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18535 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18536 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18537 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18538 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18539 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18540 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18541 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18542
18543 /* "neighbor next-hop-self force" commands. */
18544 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18545 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18546 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18547 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18548 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18549 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18550 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18551 install_element(BGP_IPV4_NODE,
18552 &no_neighbor_nexthop_self_all_hidden_cmd);
18553 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18554 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18555 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18556 install_element(BGP_IPV4M_NODE,
18557 &no_neighbor_nexthop_self_all_hidden_cmd);
18558 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18559 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18560 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18561 install_element(BGP_IPV4L_NODE,
18562 &no_neighbor_nexthop_self_all_hidden_cmd);
18563 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18564 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18565 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18566 install_element(BGP_IPV6_NODE,
18567 &no_neighbor_nexthop_self_all_hidden_cmd);
18568 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18569 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18570 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18571 install_element(BGP_IPV6M_NODE,
18572 &no_neighbor_nexthop_self_all_hidden_cmd);
18573 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18574 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18575 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18576 install_element(BGP_IPV6L_NODE,
18577 &no_neighbor_nexthop_self_all_hidden_cmd);
18578 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18579 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18580 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18581 install_element(BGP_VPNV4_NODE,
18582 &no_neighbor_nexthop_self_all_hidden_cmd);
18583 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18584 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18585 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18586 install_element(BGP_VPNV6_NODE,
18587 &no_neighbor_nexthop_self_all_hidden_cmd);
18588 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18589 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18590
18591 /* "neighbor as-override" commands. */
18592 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18593 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18594 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18595 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18596 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18597 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18598 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18599 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18600 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18601 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18602 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18603 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18604 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18605 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18606 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18607 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18608 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18609 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18610
18611 /* "neighbor remove-private-AS" commands. */
18612 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18613 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18614 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18615 install_element(BGP_NODE,
18616 &no_neighbor_remove_private_as_all_hidden_cmd);
18617 install_element(BGP_NODE,
18618 &neighbor_remove_private_as_replace_as_hidden_cmd);
18619 install_element(BGP_NODE,
18620 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18621 install_element(BGP_NODE,
18622 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18623 install_element(
18624 BGP_NODE,
18625 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18626 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18627 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18628 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18629 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18630 install_element(BGP_IPV4_NODE,
18631 &neighbor_remove_private_as_replace_as_cmd);
18632 install_element(BGP_IPV4_NODE,
18633 &no_neighbor_remove_private_as_replace_as_cmd);
18634 install_element(BGP_IPV4_NODE,
18635 &neighbor_remove_private_as_all_replace_as_cmd);
18636 install_element(BGP_IPV4_NODE,
18637 &no_neighbor_remove_private_as_all_replace_as_cmd);
18638 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18639 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18640 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18641 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18642 install_element(BGP_IPV4M_NODE,
18643 &neighbor_remove_private_as_replace_as_cmd);
18644 install_element(BGP_IPV4M_NODE,
18645 &no_neighbor_remove_private_as_replace_as_cmd);
18646 install_element(BGP_IPV4M_NODE,
18647 &neighbor_remove_private_as_all_replace_as_cmd);
18648 install_element(BGP_IPV4M_NODE,
18649 &no_neighbor_remove_private_as_all_replace_as_cmd);
18650 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18651 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18652 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18653 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18654 install_element(BGP_IPV4L_NODE,
18655 &neighbor_remove_private_as_replace_as_cmd);
18656 install_element(BGP_IPV4L_NODE,
18657 &no_neighbor_remove_private_as_replace_as_cmd);
18658 install_element(BGP_IPV4L_NODE,
18659 &neighbor_remove_private_as_all_replace_as_cmd);
18660 install_element(BGP_IPV4L_NODE,
18661 &no_neighbor_remove_private_as_all_replace_as_cmd);
18662 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18663 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18664 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18665 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18666 install_element(BGP_IPV6_NODE,
18667 &neighbor_remove_private_as_replace_as_cmd);
18668 install_element(BGP_IPV6_NODE,
18669 &no_neighbor_remove_private_as_replace_as_cmd);
18670 install_element(BGP_IPV6_NODE,
18671 &neighbor_remove_private_as_all_replace_as_cmd);
18672 install_element(BGP_IPV6_NODE,
18673 &no_neighbor_remove_private_as_all_replace_as_cmd);
18674 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18675 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18676 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18677 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18678 install_element(BGP_IPV6M_NODE,
18679 &neighbor_remove_private_as_replace_as_cmd);
18680 install_element(BGP_IPV6M_NODE,
18681 &no_neighbor_remove_private_as_replace_as_cmd);
18682 install_element(BGP_IPV6M_NODE,
18683 &neighbor_remove_private_as_all_replace_as_cmd);
18684 install_element(BGP_IPV6M_NODE,
18685 &no_neighbor_remove_private_as_all_replace_as_cmd);
18686 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18687 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18688 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18689 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18690 install_element(BGP_IPV6L_NODE,
18691 &neighbor_remove_private_as_replace_as_cmd);
18692 install_element(BGP_IPV6L_NODE,
18693 &no_neighbor_remove_private_as_replace_as_cmd);
18694 install_element(BGP_IPV6L_NODE,
18695 &neighbor_remove_private_as_all_replace_as_cmd);
18696 install_element(BGP_IPV6L_NODE,
18697 &no_neighbor_remove_private_as_all_replace_as_cmd);
18698 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18699 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18700 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18701 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18702 install_element(BGP_VPNV4_NODE,
18703 &neighbor_remove_private_as_replace_as_cmd);
18704 install_element(BGP_VPNV4_NODE,
18705 &no_neighbor_remove_private_as_replace_as_cmd);
18706 install_element(BGP_VPNV4_NODE,
18707 &neighbor_remove_private_as_all_replace_as_cmd);
18708 install_element(BGP_VPNV4_NODE,
18709 &no_neighbor_remove_private_as_all_replace_as_cmd);
18710 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18711 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18712 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18713 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18714 install_element(BGP_VPNV6_NODE,
18715 &neighbor_remove_private_as_replace_as_cmd);
18716 install_element(BGP_VPNV6_NODE,
18717 &no_neighbor_remove_private_as_replace_as_cmd);
18718 install_element(BGP_VPNV6_NODE,
18719 &neighbor_remove_private_as_all_replace_as_cmd);
18720 install_element(BGP_VPNV6_NODE,
18721 &no_neighbor_remove_private_as_all_replace_as_cmd);
18722
18723 /* "neighbor send-community" commands.*/
18724 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18725 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18726 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18727 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18728 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18729 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18730 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18731 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18732 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18733 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18734 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18735 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18736 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18737 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18738 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18739 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18740 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18741 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18742 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18743 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18744 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18745 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18746 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18747 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18748 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18749 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18750 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18751 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18752 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18753 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18754 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18755 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18756 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18757 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18758 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18759 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18760
18761 /* "neighbor route-reflector" commands.*/
18762 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18763 install_element(BGP_NODE,
18764 &no_neighbor_route_reflector_client_hidden_cmd);
18765 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18766 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18767 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18768 install_element(BGP_IPV4M_NODE,
18769 &no_neighbor_route_reflector_client_cmd);
18770 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18771 install_element(BGP_IPV4L_NODE,
18772 &no_neighbor_route_reflector_client_cmd);
18773 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18774 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18775 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18776 install_element(BGP_IPV6M_NODE,
18777 &no_neighbor_route_reflector_client_cmd);
18778 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18779 install_element(BGP_IPV6L_NODE,
18780 &no_neighbor_route_reflector_client_cmd);
18781 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18782 install_element(BGP_VPNV4_NODE,
18783 &no_neighbor_route_reflector_client_cmd);
18784 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18785 install_element(BGP_VPNV6_NODE,
18786 &no_neighbor_route_reflector_client_cmd);
18787 install_element(BGP_FLOWSPECV4_NODE,
18788 &neighbor_route_reflector_client_cmd);
18789 install_element(BGP_FLOWSPECV4_NODE,
18790 &no_neighbor_route_reflector_client_cmd);
18791 install_element(BGP_FLOWSPECV6_NODE,
18792 &neighbor_route_reflector_client_cmd);
18793 install_element(BGP_FLOWSPECV6_NODE,
18794 &no_neighbor_route_reflector_client_cmd);
18795 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18796 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18797
18798 /* "neighbor route-server" commands.*/
18799 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18800 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18801 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18802 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18803 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18804 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18805 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18806 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18807 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18808 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18809 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18810 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18811 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18812 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18813 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18814 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18815 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18816 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18817 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18818 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18819 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18820 install_element(BGP_FLOWSPECV4_NODE,
18821 &no_neighbor_route_server_client_cmd);
18822 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18823 install_element(BGP_FLOWSPECV6_NODE,
18824 &no_neighbor_route_server_client_cmd);
18825
18826 /* "neighbor disable-addpath-rx" commands. */
18827 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18828 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18829 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18830 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18831 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18832 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18833 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18834 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18835 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18836 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18837 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18838 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18839 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18840 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18841 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18842 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18843
18844 /* "neighbor addpath-tx-all-paths" commands.*/
18845 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18846 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18847 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18848 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18849 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18850 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18851 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18852 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18853 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18854 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18855 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18856 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18857 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18858 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18859 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18860 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18861 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18862 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18863
18864 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18865 install_element(BGP_NODE,
18866 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18867 install_element(BGP_NODE,
18868 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18869 install_element(BGP_IPV4_NODE,
18870 &neighbor_addpath_tx_bestpath_per_as_cmd);
18871 install_element(BGP_IPV4_NODE,
18872 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18873 install_element(BGP_IPV4M_NODE,
18874 &neighbor_addpath_tx_bestpath_per_as_cmd);
18875 install_element(BGP_IPV4M_NODE,
18876 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18877 install_element(BGP_IPV4L_NODE,
18878 &neighbor_addpath_tx_bestpath_per_as_cmd);
18879 install_element(BGP_IPV4L_NODE,
18880 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18881 install_element(BGP_IPV6_NODE,
18882 &neighbor_addpath_tx_bestpath_per_as_cmd);
18883 install_element(BGP_IPV6_NODE,
18884 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18885 install_element(BGP_IPV6M_NODE,
18886 &neighbor_addpath_tx_bestpath_per_as_cmd);
18887 install_element(BGP_IPV6M_NODE,
18888 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18889 install_element(BGP_IPV6L_NODE,
18890 &neighbor_addpath_tx_bestpath_per_as_cmd);
18891 install_element(BGP_IPV6L_NODE,
18892 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18893 install_element(BGP_VPNV4_NODE,
18894 &neighbor_addpath_tx_bestpath_per_as_cmd);
18895 install_element(BGP_VPNV4_NODE,
18896 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18897 install_element(BGP_VPNV6_NODE,
18898 &neighbor_addpath_tx_bestpath_per_as_cmd);
18899 install_element(BGP_VPNV6_NODE,
18900 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18901
18902 /* "neighbor sender-as-path-loop-detection" commands. */
18903 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18904 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18905
18906 /* "neighbor passive" commands. */
18907 install_element(BGP_NODE, &neighbor_passive_cmd);
18908 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18909
18910
18911 /* "neighbor shutdown" commands. */
18912 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18913 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18914 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18915 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18916 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18917 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18918
18919 /* "neighbor capability extended-nexthop" commands.*/
18920 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18921 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18922
18923 /* "neighbor capability orf prefix-list" commands.*/
18924 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18925 install_element(BGP_NODE,
18926 &no_neighbor_capability_orf_prefix_hidden_cmd);
18927 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18928 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18929 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18930 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18931 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18932 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18933 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18934 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18935 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18936 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18937 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18938 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18939
18940 /* "neighbor capability dynamic" commands.*/
18941 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18942 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18943
18944 /* "neighbor dont-capability-negotiate" commands. */
18945 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18946 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18947
18948 /* "neighbor ebgp-multihop" commands. */
18949 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18950 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18951 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18952
18953 /* "neighbor disable-connected-check" commands. */
18954 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18955 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18956
18957 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18958 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18959 install_element(BGP_NODE,
18960 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
18961
18962 /* "neighbor extended-optional-parameters" commands. */
18963 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18964 install_element(BGP_NODE,
18965 &no_neighbor_extended_optional_parameters_cmd);
18966
18967 /* "neighbor enforce-first-as" commands. */
18968 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18969 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18970
18971 /* "neighbor description" commands. */
18972 install_element(BGP_NODE, &neighbor_description_cmd);
18973 install_element(BGP_NODE, &no_neighbor_description_cmd);
18974 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18975
18976 /* "neighbor update-source" commands. "*/
18977 install_element(BGP_NODE, &neighbor_update_source_cmd);
18978 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18979
18980 /* "neighbor default-originate" commands. */
18981 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18982 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18983 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18984 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18985 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18986 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18987 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18988 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18989 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18990 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18991 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18992 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18993 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18994 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18995 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18996 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18997 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18998 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18999 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19000 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19001 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19002
19003 /* "neighbor port" commands. */
19004 install_element(BGP_NODE, &neighbor_port_cmd);
19005 install_element(BGP_NODE, &no_neighbor_port_cmd);
19006
19007 /* "neighbor weight" commands. */
19008 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19009 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19010
19011 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19012 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19013 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19014 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19015 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19016 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19017 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19018 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19019 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19020 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19021 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19022 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19023 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19024 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19025 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19026 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19027
19028 /* "neighbor override-capability" commands. */
19029 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19030 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19031
19032 /* "neighbor strict-capability-match" commands. */
19033 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19034 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19035
19036 /* "neighbor timers" commands. */
19037 install_element(BGP_NODE, &neighbor_timers_cmd);
19038 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19039
19040 /* "neighbor timers connect" commands. */
19041 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19042 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19043
19044 /* "neighbor timers delayopen" commands. */
19045 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19046 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19047
19048 /* "neighbor advertisement-interval" commands. */
19049 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19050 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19051
19052 /* "neighbor interface" commands. */
19053 install_element(BGP_NODE, &neighbor_interface_cmd);
19054 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19055
19056 /* "neighbor distribute" commands. */
19057 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19058 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19059 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19060 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19061 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19062 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19063 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19064 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19065 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19066 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19067 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19068 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19069 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19070 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19071 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19072 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19073 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19074 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19075
19076 /* "neighbor prefix-list" commands. */
19077 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19078 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19079 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19080 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19081 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19082 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19083 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19084 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19085 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19086 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19087 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19088 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19089 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19090 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19091 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19092 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19093 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19094 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19095 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19096 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19097 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19098 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19099
19100 /* "neighbor filter-list" commands. */
19101 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19102 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19103 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19104 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19105 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19106 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19107 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19108 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19109 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19110 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19111 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19112 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19113 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19114 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19115 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19116 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19117 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19118 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19119 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19120 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19121 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19122 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19123
19124 /* "neighbor route-map" commands. */
19125 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19126 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19127 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19128 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19129 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19130 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19131 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19132 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19133 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19134 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19135 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19136 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19137 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19138 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19139 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19140 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19141 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19142 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19143 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19144 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19145 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19146 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19147 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19148 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19149
19150 /* "neighbor unsuppress-map" commands. */
19151 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19152 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19153 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19154 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19155 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19156 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19157 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19158 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19159 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19160 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19161 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19162 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19163 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19164 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19165 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19166 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19167 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19168 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19169
19170 /* "neighbor advertise-map" commands. */
19171 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19172 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19173 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19174 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19175 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19176 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19177 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19178 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19179 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19180 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19181
19182 /* neighbor maximum-prefix-out commands. */
19183 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19184 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19185 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19186 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19187 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19188 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19189 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19190 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19191 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19192 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19193 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19194 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19195 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19196 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19197 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19198 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19199 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19200 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19201
19202 /* "neighbor maximum-prefix" commands. */
19203 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19204 install_element(BGP_NODE,
19205 &neighbor_maximum_prefix_threshold_hidden_cmd);
19206 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19207 install_element(BGP_NODE,
19208 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19209 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19210 install_element(BGP_NODE,
19211 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19212 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19213 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19214 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19215 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19216 install_element(BGP_IPV4_NODE,
19217 &neighbor_maximum_prefix_threshold_warning_cmd);
19218 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19219 install_element(BGP_IPV4_NODE,
19220 &neighbor_maximum_prefix_threshold_restart_cmd);
19221 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19222 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19223 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19224 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19225 install_element(BGP_IPV4M_NODE,
19226 &neighbor_maximum_prefix_threshold_warning_cmd);
19227 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19228 install_element(BGP_IPV4M_NODE,
19229 &neighbor_maximum_prefix_threshold_restart_cmd);
19230 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19231 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19232 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19233 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19234 install_element(BGP_IPV4L_NODE,
19235 &neighbor_maximum_prefix_threshold_warning_cmd);
19236 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19237 install_element(BGP_IPV4L_NODE,
19238 &neighbor_maximum_prefix_threshold_restart_cmd);
19239 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19240 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19241 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19242 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19243 install_element(BGP_IPV6_NODE,
19244 &neighbor_maximum_prefix_threshold_warning_cmd);
19245 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19246 install_element(BGP_IPV6_NODE,
19247 &neighbor_maximum_prefix_threshold_restart_cmd);
19248 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19249 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19250 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19251 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19252 install_element(BGP_IPV6M_NODE,
19253 &neighbor_maximum_prefix_threshold_warning_cmd);
19254 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19255 install_element(BGP_IPV6M_NODE,
19256 &neighbor_maximum_prefix_threshold_restart_cmd);
19257 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19258 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19259 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19260 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19261 install_element(BGP_IPV6L_NODE,
19262 &neighbor_maximum_prefix_threshold_warning_cmd);
19263 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19264 install_element(BGP_IPV6L_NODE,
19265 &neighbor_maximum_prefix_threshold_restart_cmd);
19266 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19267 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19268 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19269 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19270 install_element(BGP_VPNV4_NODE,
19271 &neighbor_maximum_prefix_threshold_warning_cmd);
19272 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19273 install_element(BGP_VPNV4_NODE,
19274 &neighbor_maximum_prefix_threshold_restart_cmd);
19275 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19276 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19277 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19278 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19279 install_element(BGP_VPNV6_NODE,
19280 &neighbor_maximum_prefix_threshold_warning_cmd);
19281 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19282 install_element(BGP_VPNV6_NODE,
19283 &neighbor_maximum_prefix_threshold_restart_cmd);
19284 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19285
19286 /* "neighbor allowas-in" */
19287 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19288 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19289 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19290 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19291 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19292 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19293 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19294 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19295 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19296 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19297 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19298 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19299 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19300 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19301 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19302 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19303 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19304 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19305 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19306 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19307
19308 /* address-family commands. */
19309 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19310 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19311 #ifdef KEEP_OLD_VPN_COMMANDS
19312 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19313 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19314 #endif /* KEEP_OLD_VPN_COMMANDS */
19315
19316 install_element(BGP_NODE, &address_family_evpn_cmd);
19317
19318 /* "exit-address-family" command. */
19319 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19320 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19321 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19322 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19323 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19324 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19325 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19326 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19327 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19328 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19329 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19330
19331 /* BGP retain all route-target */
19332 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19333 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19334
19335 /* "clear ip bgp commands" */
19336 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19337
19338 /* clear ip bgp prefix */
19339 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19340 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19341 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19342
19343 /* "show [ip] bgp summary" commands. */
19344 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19345 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19346 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19347 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19348 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19349 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19350 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19351
19352 /* "show [ip] bgp neighbors" commands. */
19353 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19354
19355 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19356
19357 /* "show [ip] bgp peer-group" commands. */
19358 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19359
19360 /* "show [ip] bgp paths" commands. */
19361 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19362
19363 /* "show [ip] bgp community" commands. */
19364 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19365
19366 /* "show ip bgp large-community" commands. */
19367 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19368 /* "show [ip] bgp attribute-info" commands. */
19369 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19370 /* "show [ip] bgp route-leak" command */
19371 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19372
19373 /* "redistribute" commands. */
19374 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19375 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19376 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19377 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19378 install_element(BGP_NODE,
19379 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19380 install_element(BGP_NODE,
19381 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19382 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19383 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19384 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19385 install_element(BGP_NODE,
19386 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19387 install_element(BGP_NODE,
19388 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19389 install_element(BGP_NODE,
19390 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19391 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19392 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19393 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19394 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19395 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19396 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19397 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19398 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19399 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19400 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19401 install_element(BGP_IPV4_NODE,
19402 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19403 install_element(BGP_IPV4_NODE,
19404 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19405 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19406 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19407 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19408 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19409 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19410 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19411
19412 /* import|export vpn [route-map RMAP_NAME] */
19413 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19414 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19415
19416 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19417 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19418
19419 /* ttl_security commands */
19420 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19421 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19422
19423 /* "show [ip] bgp memory" commands. */
19424 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19425
19426 /* "show bgp martian next-hop" */
19427 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19428
19429 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19430
19431 /* "show [ip] bgp views" commands. */
19432 install_element(VIEW_NODE, &show_bgp_views_cmd);
19433
19434 /* "show [ip] bgp vrfs" commands. */
19435 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19436
19437 /* Community-list. */
19438 community_list_vty();
19439
19440 community_alias_vty();
19441
19442 /* vpn-policy commands */
19443 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19444 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19445 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19446 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19447 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19448 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19449 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19450 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19451 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19452 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19453 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19454 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19455
19456 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19457 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19458
19459 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19460 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19461 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19462 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19463 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19464 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19465 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19466 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19467 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19468 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19469
19470 /* tcp-mss command */
19471 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19472 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19473
19474 /* srv6 commands */
19475 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19476 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19477 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19478 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19479 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19480 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19481 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19482 }
19483
19484 #include "memory.h"
19485 #include "bgp_regex.h"
19486 #include "bgp_clist.h"
19487 #include "bgp_ecommunity.h"
19488
19489 /* VTY functions. */
19490
19491 /* Direction value to string conversion. */
19492 static const char *community_direct_str(int direct)
19493 {
19494 switch (direct) {
19495 case COMMUNITY_DENY:
19496 return "deny";
19497 case COMMUNITY_PERMIT:
19498 return "permit";
19499 default:
19500 return "unknown";
19501 }
19502 }
19503
19504 /* Display error string. */
19505 static void community_list_perror(struct vty *vty, int ret)
19506 {
19507 switch (ret) {
19508 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19509 vty_out(vty, "%% Can't find community-list\n");
19510 break;
19511 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19512 vty_out(vty, "%% Malformed community-list value\n");
19513 break;
19514 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19515 vty_out(vty,
19516 "%% Community name conflict, previously defined as standard community\n");
19517 break;
19518 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19519 vty_out(vty,
19520 "%% Community name conflict, previously defined as expanded community\n");
19521 break;
19522 }
19523 }
19524
19525 /* "community-list" keyword help string. */
19526 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19527
19528 /*community-list standard */
19529 DEFUN (community_list_standard,
19530 bgp_community_list_standard_cmd,
19531 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19532 BGP_STR
19533 COMMUNITY_LIST_STR
19534 "Community list number (standard)\n"
19535 "Add an standard community-list entry\n"
19536 "Community list name\n"
19537 "Sequence number of an entry\n"
19538 "Sequence number\n"
19539 "Specify community to reject\n"
19540 "Specify community to accept\n"
19541 COMMUNITY_VAL_STR)
19542 {
19543 char *cl_name_or_number = NULL;
19544 char *seq = NULL;
19545 int direct = 0;
19546 int style = COMMUNITY_LIST_STANDARD;
19547 int idx = 0;
19548
19549 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19550 seq = argv[idx]->arg;
19551
19552 idx = 0;
19553 argv_find(argv, argc, "(1-99)", &idx);
19554 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19555 cl_name_or_number = argv[idx]->arg;
19556 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19557 : COMMUNITY_DENY;
19558 argv_find(argv, argc, "AA:NN", &idx);
19559 char *str = argv_concat(argv, argc, idx);
19560
19561 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19562 direct, style);
19563
19564 XFREE(MTYPE_TMP, str);
19565
19566 if (ret < 0) {
19567 /* Display error string. */
19568 community_list_perror(vty, ret);
19569 return CMD_WARNING_CONFIG_FAILED;
19570 }
19571
19572 return CMD_SUCCESS;
19573 }
19574
19575 DEFUN (no_community_list_standard_all,
19576 no_bgp_community_list_standard_all_cmd,
19577 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19578 NO_STR
19579 BGP_STR
19580 COMMUNITY_LIST_STR
19581 "Community list number (standard)\n"
19582 "Add an standard community-list entry\n"
19583 "Community list name\n"
19584 "Sequence number of an entry\n"
19585 "Sequence number\n"
19586 "Specify community to reject\n"
19587 "Specify community to accept\n"
19588 COMMUNITY_VAL_STR)
19589 {
19590 char *cl_name_or_number = NULL;
19591 char *str = NULL;
19592 int direct = 0;
19593 int style = COMMUNITY_LIST_STANDARD;
19594 char *seq = NULL;
19595 int idx = 0;
19596
19597 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19598 seq = argv[idx]->arg;
19599
19600 idx = 0;
19601 argv_find(argv, argc, "permit", &idx);
19602 argv_find(argv, argc, "deny", &idx);
19603
19604 if (idx) {
19605 direct = argv_find(argv, argc, "permit", &idx)
19606 ? COMMUNITY_PERMIT
19607 : COMMUNITY_DENY;
19608
19609 idx = 0;
19610 argv_find(argv, argc, "AA:NN", &idx);
19611 str = argv_concat(argv, argc, idx);
19612 }
19613
19614 idx = 0;
19615 argv_find(argv, argc, "(1-99)", &idx);
19616 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19617 cl_name_or_number = argv[idx]->arg;
19618
19619 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19620 direct, style);
19621
19622 XFREE(MTYPE_TMP, str);
19623
19624 if (ret < 0) {
19625 community_list_perror(vty, ret);
19626 return CMD_WARNING_CONFIG_FAILED;
19627 }
19628
19629 return CMD_SUCCESS;
19630 }
19631
19632 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19633 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19634 NO_STR BGP_STR COMMUNITY_LIST_STR
19635 "Community list number (standard)\n"
19636 "Add an standard community-list entry\n"
19637 "Community list name\n")
19638
19639 /*community-list expanded */
19640 DEFUN (community_list_expanded_all,
19641 bgp_community_list_expanded_all_cmd,
19642 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19643 BGP_STR
19644 COMMUNITY_LIST_STR
19645 "Community list number (expanded)\n"
19646 "Add an expanded community-list entry\n"
19647 "Community list name\n"
19648 "Sequence number of an entry\n"
19649 "Sequence number\n"
19650 "Specify community to reject\n"
19651 "Specify community to accept\n"
19652 COMMUNITY_VAL_STR)
19653 {
19654 char *cl_name_or_number = NULL;
19655 char *seq = NULL;
19656 int direct = 0;
19657 int style = COMMUNITY_LIST_EXPANDED;
19658 int idx = 0;
19659
19660 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19661 seq = argv[idx]->arg;
19662
19663 idx = 0;
19664
19665 argv_find(argv, argc, "(100-500)", &idx);
19666 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19667 cl_name_or_number = argv[idx]->arg;
19668 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19669 : COMMUNITY_DENY;
19670 argv_find(argv, argc, "AA:NN", &idx);
19671 char *str = argv_concat(argv, argc, idx);
19672
19673 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19674 direct, style);
19675
19676 XFREE(MTYPE_TMP, str);
19677
19678 if (ret < 0) {
19679 /* Display error string. */
19680 community_list_perror(vty, ret);
19681 return CMD_WARNING_CONFIG_FAILED;
19682 }
19683
19684 return CMD_SUCCESS;
19685 }
19686
19687 DEFUN (no_community_list_expanded_all,
19688 no_bgp_community_list_expanded_all_cmd,
19689 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19690 NO_STR
19691 BGP_STR
19692 COMMUNITY_LIST_STR
19693 "Community list number (expanded)\n"
19694 "Add an expanded community-list entry\n"
19695 "Community list name\n"
19696 "Sequence number of an entry\n"
19697 "Sequence number\n"
19698 "Specify community to reject\n"
19699 "Specify community to accept\n"
19700 COMMUNITY_VAL_STR)
19701 {
19702 char *cl_name_or_number = NULL;
19703 char *seq = NULL;
19704 char *str = NULL;
19705 int direct = 0;
19706 int style = COMMUNITY_LIST_EXPANDED;
19707 int idx = 0;
19708
19709 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19710 seq = argv[idx]->arg;
19711
19712 idx = 0;
19713 argv_find(argv, argc, "permit", &idx);
19714 argv_find(argv, argc, "deny", &idx);
19715
19716 if (idx) {
19717 direct = argv_find(argv, argc, "permit", &idx)
19718 ? COMMUNITY_PERMIT
19719 : COMMUNITY_DENY;
19720
19721 idx = 0;
19722 argv_find(argv, argc, "AA:NN", &idx);
19723 str = argv_concat(argv, argc, idx);
19724 }
19725
19726 idx = 0;
19727 argv_find(argv, argc, "(100-500)", &idx);
19728 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19729 cl_name_or_number = argv[idx]->arg;
19730
19731 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19732 direct, style);
19733
19734 XFREE(MTYPE_TMP, str);
19735
19736 if (ret < 0) {
19737 community_list_perror(vty, ret);
19738 return CMD_WARNING_CONFIG_FAILED;
19739 }
19740
19741 return CMD_SUCCESS;
19742 }
19743
19744 ALIAS(no_community_list_expanded_all,
19745 no_bgp_community_list_expanded_all_list_cmd,
19746 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19747 NO_STR BGP_STR COMMUNITY_LIST_STR
19748 "Community list number (expanded)\n"
19749 "Add an expanded community-list entry\n"
19750 "Community list name\n")
19751
19752 /* Return configuration string of community-list entry. */
19753 static const char *community_list_config_str(struct community_entry *entry)
19754 {
19755 const char *str;
19756
19757 if (entry->any)
19758 str = "";
19759 else {
19760 if (entry->style == COMMUNITY_LIST_STANDARD)
19761 str = community_str(entry->u.com, false, false);
19762 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19763 str = lcommunity_str(entry->u.lcom, false, false);
19764 else
19765 str = entry->config;
19766 }
19767 return str;
19768 }
19769
19770 static void community_list_show(struct vty *vty, struct community_list *list)
19771 {
19772 struct community_entry *entry;
19773
19774 for (entry = list->head; entry; entry = entry->next) {
19775 if (entry == list->head) {
19776 if (all_digit(list->name))
19777 vty_out(vty, "Community %s list %s\n",
19778 entry->style == COMMUNITY_LIST_STANDARD
19779 ? "standard"
19780 : "(expanded) access",
19781 list->name);
19782 else
19783 vty_out(vty, "Named Community %s list %s\n",
19784 entry->style == COMMUNITY_LIST_STANDARD
19785 ? "standard"
19786 : "expanded",
19787 list->name);
19788 }
19789 if (entry->any)
19790 vty_out(vty, " %s\n",
19791 community_direct_str(entry->direct));
19792 else
19793 vty_out(vty, " %s %s\n",
19794 community_direct_str(entry->direct),
19795 community_list_config_str(entry));
19796 }
19797 }
19798
19799 DEFUN (show_community_list,
19800 show_bgp_community_list_cmd,
19801 "show bgp community-list",
19802 SHOW_STR
19803 BGP_STR
19804 "List community-list\n")
19805 {
19806 struct community_list *list;
19807 struct community_list_master *cm;
19808
19809 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19810 if (!cm)
19811 return CMD_SUCCESS;
19812
19813 for (list = cm->num.head; list; list = list->next)
19814 community_list_show(vty, list);
19815
19816 for (list = cm->str.head; list; list = list->next)
19817 community_list_show(vty, list);
19818
19819 return CMD_SUCCESS;
19820 }
19821
19822 DEFUN (show_community_list_arg,
19823 show_bgp_community_list_arg_cmd,
19824 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
19825 SHOW_STR
19826 BGP_STR
19827 "List community-list\n"
19828 "Community-list number\n"
19829 "Community-list name\n"
19830 "Detailed information on community-list\n")
19831 {
19832 int idx_comm_list = 3;
19833 struct community_list *list;
19834
19835 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19836 COMMUNITY_LIST_MASTER);
19837 if (!list) {
19838 vty_out(vty, "%% Can't find community-list\n");
19839 return CMD_WARNING;
19840 }
19841
19842 community_list_show(vty, list);
19843
19844 return CMD_SUCCESS;
19845 }
19846
19847 /*
19848 * Large Community code.
19849 */
19850 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19851 struct cmd_token **argv, int style,
19852 int reject_all_digit_name)
19853 {
19854 int ret;
19855 int direct;
19856 char *str;
19857 int idx = 0;
19858 char *cl_name;
19859 char *seq = NULL;
19860
19861 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19862 seq = argv[idx]->arg;
19863
19864 idx = 0;
19865 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19866 : COMMUNITY_DENY;
19867
19868 /* All digit name check. */
19869 idx = 0;
19870 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19871 argv_find(argv, argc, "(1-99)", &idx);
19872 argv_find(argv, argc, "(100-500)", &idx);
19873 cl_name = argv[idx]->arg;
19874 if (reject_all_digit_name && all_digit(cl_name)) {
19875 vty_out(vty, "%% Community name cannot have all digits\n");
19876 return CMD_WARNING_CONFIG_FAILED;
19877 }
19878
19879 idx = 0;
19880 argv_find(argv, argc, "AA:BB:CC", &idx);
19881 argv_find(argv, argc, "LINE", &idx);
19882 /* Concat community string argument. */
19883 if (idx)
19884 str = argv_concat(argv, argc, idx);
19885 else
19886 str = NULL;
19887
19888 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19889
19890 /* Free temporary community list string allocated by
19891 argv_concat(). */
19892 XFREE(MTYPE_TMP, str);
19893
19894 if (ret < 0) {
19895 community_list_perror(vty, ret);
19896 return CMD_WARNING_CONFIG_FAILED;
19897 }
19898 return CMD_SUCCESS;
19899 }
19900
19901 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19902 struct cmd_token **argv, int style)
19903 {
19904 int ret;
19905 int direct = 0;
19906 char *str = NULL;
19907 int idx = 0;
19908 char *seq = NULL;
19909
19910 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19911 seq = argv[idx]->arg;
19912
19913 idx = 0;
19914 argv_find(argv, argc, "permit", &idx);
19915 argv_find(argv, argc, "deny", &idx);
19916
19917 if (idx) {
19918 /* Check the list direct. */
19919 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19920 direct = COMMUNITY_PERMIT;
19921 else
19922 direct = COMMUNITY_DENY;
19923
19924 idx = 0;
19925 argv_find(argv, argc, "LINE", &idx);
19926 argv_find(argv, argc, "AA:AA:NN", &idx);
19927 /* Concat community string argument. */
19928 str = argv_concat(argv, argc, idx);
19929 }
19930
19931 idx = 0;
19932 argv_find(argv, argc, "(1-99)", &idx);
19933 argv_find(argv, argc, "(100-500)", &idx);
19934 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19935
19936 /* Unset community list. */
19937 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19938 style);
19939
19940 /* Free temporary community list string allocated by
19941 argv_concat(). */
19942 XFREE(MTYPE_TMP, str);
19943
19944 if (ret < 0) {
19945 community_list_perror(vty, ret);
19946 return CMD_WARNING_CONFIG_FAILED;
19947 }
19948
19949 return CMD_SUCCESS;
19950 }
19951
19952 /* "large-community-list" keyword help string. */
19953 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19954 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19955
19956 DEFUN (lcommunity_list_standard,
19957 bgp_lcommunity_list_standard_cmd,
19958 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19959 BGP_STR
19960 LCOMMUNITY_LIST_STR
19961 "Large Community list number (standard)\n"
19962 "Sequence number of an entry\n"
19963 "Sequence number\n"
19964 "Specify large community to reject\n"
19965 "Specify large community to accept\n"
19966 LCOMMUNITY_VAL_STR)
19967 {
19968 return lcommunity_list_set_vty(vty, argc, argv,
19969 LARGE_COMMUNITY_LIST_STANDARD, 0);
19970 }
19971
19972 DEFUN (lcommunity_list_expanded,
19973 bgp_lcommunity_list_expanded_cmd,
19974 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19975 BGP_STR
19976 LCOMMUNITY_LIST_STR
19977 "Large Community list number (expanded)\n"
19978 "Sequence number of an entry\n"
19979 "Sequence number\n"
19980 "Specify large community to reject\n"
19981 "Specify large community to accept\n"
19982 "An ordered list as a regular-expression\n")
19983 {
19984 return lcommunity_list_set_vty(vty, argc, argv,
19985 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19986 }
19987
19988 DEFUN (lcommunity_list_name_standard,
19989 bgp_lcommunity_list_name_standard_cmd,
19990 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19991 BGP_STR
19992 LCOMMUNITY_LIST_STR
19993 "Specify standard large-community-list\n"
19994 "Large Community list name\n"
19995 "Sequence number of an entry\n"
19996 "Sequence number\n"
19997 "Specify large community to reject\n"
19998 "Specify large community to accept\n"
19999 LCOMMUNITY_VAL_STR)
20000 {
20001 return lcommunity_list_set_vty(vty, argc, argv,
20002 LARGE_COMMUNITY_LIST_STANDARD, 1);
20003 }
20004
20005 DEFUN (lcommunity_list_name_expanded,
20006 bgp_lcommunity_list_name_expanded_cmd,
20007 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20008 BGP_STR
20009 LCOMMUNITY_LIST_STR
20010 "Specify expanded large-community-list\n"
20011 "Large Community list name\n"
20012 "Sequence number of an entry\n"
20013 "Sequence number\n"
20014 "Specify large community to reject\n"
20015 "Specify large community to accept\n"
20016 "An ordered list as a regular-expression\n")
20017 {
20018 return lcommunity_list_set_vty(vty, argc, argv,
20019 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20020 }
20021
20022 DEFUN (no_lcommunity_list_all,
20023 no_bgp_lcommunity_list_all_cmd,
20024 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20025 NO_STR
20026 BGP_STR
20027 LCOMMUNITY_LIST_STR
20028 "Large Community list number (standard)\n"
20029 "Large Community list number (expanded)\n"
20030 "Large Community list name\n")
20031 {
20032 return lcommunity_list_unset_vty(vty, argc, argv,
20033 LARGE_COMMUNITY_LIST_STANDARD);
20034 }
20035
20036 DEFUN (no_lcommunity_list_name_standard_all,
20037 no_bgp_lcommunity_list_name_standard_all_cmd,
20038 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20039 NO_STR
20040 BGP_STR
20041 LCOMMUNITY_LIST_STR
20042 "Specify standard large-community-list\n"
20043 "Large Community list name\n")
20044 {
20045 return lcommunity_list_unset_vty(vty, argc, argv,
20046 LARGE_COMMUNITY_LIST_STANDARD);
20047 }
20048
20049 DEFUN (no_lcommunity_list_name_expanded_all,
20050 no_bgp_lcommunity_list_name_expanded_all_cmd,
20051 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20052 NO_STR
20053 BGP_STR
20054 LCOMMUNITY_LIST_STR
20055 "Specify expanded large-community-list\n"
20056 "Large Community list name\n")
20057 {
20058 return lcommunity_list_unset_vty(vty, argc, argv,
20059 LARGE_COMMUNITY_LIST_EXPANDED);
20060 }
20061
20062 DEFUN (no_lcommunity_list_standard,
20063 no_bgp_lcommunity_list_standard_cmd,
20064 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20065 NO_STR
20066 BGP_STR
20067 LCOMMUNITY_LIST_STR
20068 "Large Community list number (standard)\n"
20069 "Sequence number of an entry\n"
20070 "Sequence number\n"
20071 "Specify large community to reject\n"
20072 "Specify large community to accept\n"
20073 LCOMMUNITY_VAL_STR)
20074 {
20075 return lcommunity_list_unset_vty(vty, argc, argv,
20076 LARGE_COMMUNITY_LIST_STANDARD);
20077 }
20078
20079 DEFUN (no_lcommunity_list_expanded,
20080 no_bgp_lcommunity_list_expanded_cmd,
20081 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20082 NO_STR
20083 BGP_STR
20084 LCOMMUNITY_LIST_STR
20085 "Large Community list number (expanded)\n"
20086 "Sequence number of an entry\n"
20087 "Sequence number\n"
20088 "Specify large community to reject\n"
20089 "Specify large community to accept\n"
20090 "An ordered list as a regular-expression\n")
20091 {
20092 return lcommunity_list_unset_vty(vty, argc, argv,
20093 LARGE_COMMUNITY_LIST_EXPANDED);
20094 }
20095
20096 DEFUN (no_lcommunity_list_name_standard,
20097 no_bgp_lcommunity_list_name_standard_cmd,
20098 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20099 NO_STR
20100 BGP_STR
20101 LCOMMUNITY_LIST_STR
20102 "Specify standard large-community-list\n"
20103 "Large Community list name\n"
20104 "Sequence number of an entry\n"
20105 "Sequence number\n"
20106 "Specify large community to reject\n"
20107 "Specify large community to accept\n"
20108 LCOMMUNITY_VAL_STR)
20109 {
20110 return lcommunity_list_unset_vty(vty, argc, argv,
20111 LARGE_COMMUNITY_LIST_STANDARD);
20112 }
20113
20114 DEFUN (no_lcommunity_list_name_expanded,
20115 no_bgp_lcommunity_list_name_expanded_cmd,
20116 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20117 NO_STR
20118 BGP_STR
20119 LCOMMUNITY_LIST_STR
20120 "Specify expanded large-community-list\n"
20121 "Large community list name\n"
20122 "Sequence number of an entry\n"
20123 "Sequence number\n"
20124 "Specify large community to reject\n"
20125 "Specify large community to accept\n"
20126 "An ordered list as a regular-expression\n")
20127 {
20128 return lcommunity_list_unset_vty(vty, argc, argv,
20129 LARGE_COMMUNITY_LIST_EXPANDED);
20130 }
20131
20132 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20133 {
20134 struct community_entry *entry;
20135
20136 for (entry = list->head; entry; entry = entry->next) {
20137 if (entry == list->head) {
20138 if (all_digit(list->name))
20139 vty_out(vty, "Large community %s list %s\n",
20140 entry->style ==
20141 LARGE_COMMUNITY_LIST_STANDARD
20142 ? "standard"
20143 : "(expanded) access",
20144 list->name);
20145 else
20146 vty_out(vty,
20147 "Named large community %s list %s\n",
20148 entry->style ==
20149 LARGE_COMMUNITY_LIST_STANDARD
20150 ? "standard"
20151 : "expanded",
20152 list->name);
20153 }
20154 if (entry->any)
20155 vty_out(vty, " %s\n",
20156 community_direct_str(entry->direct));
20157 else
20158 vty_out(vty, " %s %s\n",
20159 community_direct_str(entry->direct),
20160 community_list_config_str(entry));
20161 }
20162 }
20163
20164 DEFUN (show_lcommunity_list,
20165 show_bgp_lcommunity_list_cmd,
20166 "show bgp large-community-list",
20167 SHOW_STR
20168 BGP_STR
20169 "List large-community list\n")
20170 {
20171 struct community_list *list;
20172 struct community_list_master *cm;
20173
20174 cm = community_list_master_lookup(bgp_clist,
20175 LARGE_COMMUNITY_LIST_MASTER);
20176 if (!cm)
20177 return CMD_SUCCESS;
20178
20179 for (list = cm->num.head; list; list = list->next)
20180 lcommunity_list_show(vty, list);
20181
20182 for (list = cm->str.head; list; list = list->next)
20183 lcommunity_list_show(vty, list);
20184
20185 return CMD_SUCCESS;
20186 }
20187
20188 DEFUN (show_lcommunity_list_arg,
20189 show_bgp_lcommunity_list_arg_cmd,
20190 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20191 SHOW_STR
20192 BGP_STR
20193 "List large-community list\n"
20194 "Large-community-list number\n"
20195 "Large-community-list name\n"
20196 "Detailed information on large-community-list\n")
20197 {
20198 struct community_list *list;
20199
20200 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20201 LARGE_COMMUNITY_LIST_MASTER);
20202 if (!list) {
20203 vty_out(vty, "%% Can't find large-community-list\n");
20204 return CMD_WARNING;
20205 }
20206
20207 lcommunity_list_show(vty, list);
20208
20209 return CMD_SUCCESS;
20210 }
20211
20212 /* "extcommunity-list" keyword help string. */
20213 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20214 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20215
20216 DEFUN (extcommunity_list_standard,
20217 bgp_extcommunity_list_standard_cmd,
20218 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20219 BGP_STR
20220 EXTCOMMUNITY_LIST_STR
20221 "Extended Community list number (standard)\n"
20222 "Specify standard extcommunity-list\n"
20223 "Community list name\n"
20224 "Sequence number of an entry\n"
20225 "Sequence number\n"
20226 "Specify community to reject\n"
20227 "Specify community to accept\n"
20228 EXTCOMMUNITY_VAL_STR)
20229 {
20230 int style = EXTCOMMUNITY_LIST_STANDARD;
20231 int direct = 0;
20232 char *cl_number_or_name = NULL;
20233 char *seq = NULL;
20234
20235 int idx = 0;
20236
20237 argv_find(argv, argc, "(1-99)", &idx);
20238 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20239 cl_number_or_name = argv[idx]->arg;
20240
20241 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20242 seq = argv[idx]->arg;
20243
20244 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20245 : COMMUNITY_DENY;
20246 argv_find(argv, argc, "AA:NN", &idx);
20247 char *str = argv_concat(argv, argc, idx);
20248
20249 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20250 direct, style);
20251
20252 XFREE(MTYPE_TMP, str);
20253
20254 if (ret < 0) {
20255 community_list_perror(vty, ret);
20256 return CMD_WARNING_CONFIG_FAILED;
20257 }
20258
20259 return CMD_SUCCESS;
20260 }
20261
20262 DEFUN (extcommunity_list_name_expanded,
20263 bgp_extcommunity_list_name_expanded_cmd,
20264 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20265 BGP_STR
20266 EXTCOMMUNITY_LIST_STR
20267 "Extended Community list number (expanded)\n"
20268 "Specify expanded extcommunity-list\n"
20269 "Extended Community list name\n"
20270 "Sequence number of an entry\n"
20271 "Sequence number\n"
20272 "Specify community to reject\n"
20273 "Specify community to accept\n"
20274 "An ordered list as a regular-expression\n")
20275 {
20276 int style = EXTCOMMUNITY_LIST_EXPANDED;
20277 int direct = 0;
20278 char *cl_number_or_name = NULL;
20279 char *seq = NULL;
20280 int idx = 0;
20281
20282 argv_find(argv, argc, "(100-500)", &idx);
20283 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20284 cl_number_or_name = argv[idx]->arg;
20285
20286 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20287 seq = argv[idx]->arg;
20288
20289 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20290 : COMMUNITY_DENY;
20291 argv_find(argv, argc, "LINE", &idx);
20292 char *str = argv_concat(argv, argc, idx);
20293
20294 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20295 direct, style);
20296
20297 XFREE(MTYPE_TMP, str);
20298
20299 if (ret < 0) {
20300 community_list_perror(vty, ret);
20301 return CMD_WARNING_CONFIG_FAILED;
20302 }
20303
20304 return CMD_SUCCESS;
20305 }
20306
20307 DEFUN (no_extcommunity_list_standard_all,
20308 no_bgp_extcommunity_list_standard_all_cmd,
20309 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20310 NO_STR
20311 BGP_STR
20312 EXTCOMMUNITY_LIST_STR
20313 "Extended Community list number (standard)\n"
20314 "Specify standard extcommunity-list\n"
20315 "Community list name\n"
20316 "Sequence number of an entry\n"
20317 "Sequence number\n"
20318 "Specify community to reject\n"
20319 "Specify community to accept\n"
20320 EXTCOMMUNITY_VAL_STR)
20321 {
20322 int style = EXTCOMMUNITY_LIST_STANDARD;
20323 int direct = 0;
20324 char *cl_number_or_name = NULL;
20325 char *str = NULL;
20326 char *seq = NULL;
20327 int idx = 0;
20328
20329 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20330 seq = argv[idx]->arg;
20331
20332 idx = 0;
20333 argv_find(argv, argc, "permit", &idx);
20334 argv_find(argv, argc, "deny", &idx);
20335 if (idx) {
20336 direct = argv_find(argv, argc, "permit", &idx)
20337 ? COMMUNITY_PERMIT
20338 : COMMUNITY_DENY;
20339
20340 idx = 0;
20341 argv_find(argv, argc, "AA:NN", &idx);
20342 str = argv_concat(argv, argc, idx);
20343 }
20344
20345 idx = 0;
20346 argv_find(argv, argc, "(1-99)", &idx);
20347 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20348 cl_number_or_name = argv[idx]->arg;
20349
20350 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20351 seq, direct, style);
20352
20353 XFREE(MTYPE_TMP, str);
20354
20355 if (ret < 0) {
20356 community_list_perror(vty, ret);
20357 return CMD_WARNING_CONFIG_FAILED;
20358 }
20359
20360 return CMD_SUCCESS;
20361 }
20362
20363 ALIAS(no_extcommunity_list_standard_all,
20364 no_bgp_extcommunity_list_standard_all_list_cmd,
20365 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20366 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20367 "Extended Community list number (standard)\n"
20368 "Specify standard extcommunity-list\n"
20369 "Community list name\n")
20370
20371 DEFUN (no_extcommunity_list_expanded_all,
20372 no_bgp_extcommunity_list_expanded_all_cmd,
20373 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20374 NO_STR
20375 BGP_STR
20376 EXTCOMMUNITY_LIST_STR
20377 "Extended Community list number (expanded)\n"
20378 "Specify expanded extcommunity-list\n"
20379 "Extended Community list name\n"
20380 "Sequence number of an entry\n"
20381 "Sequence number\n"
20382 "Specify community to reject\n"
20383 "Specify community to accept\n"
20384 "An ordered list as a regular-expression\n")
20385 {
20386 int style = EXTCOMMUNITY_LIST_EXPANDED;
20387 int direct = 0;
20388 char *cl_number_or_name = NULL;
20389 char *str = NULL;
20390 char *seq = NULL;
20391 int idx = 0;
20392
20393 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20394 seq = argv[idx]->arg;
20395
20396 idx = 0;
20397 argv_find(argv, argc, "permit", &idx);
20398 argv_find(argv, argc, "deny", &idx);
20399
20400 if (idx) {
20401 direct = argv_find(argv, argc, "permit", &idx)
20402 ? COMMUNITY_PERMIT
20403 : COMMUNITY_DENY;
20404
20405 idx = 0;
20406 argv_find(argv, argc, "LINE", &idx);
20407 str = argv_concat(argv, argc, idx);
20408 }
20409
20410 idx = 0;
20411 argv_find(argv, argc, "(100-500)", &idx);
20412 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20413 cl_number_or_name = argv[idx]->arg;
20414
20415 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20416 seq, direct, style);
20417
20418 XFREE(MTYPE_TMP, str);
20419
20420 if (ret < 0) {
20421 community_list_perror(vty, ret);
20422 return CMD_WARNING_CONFIG_FAILED;
20423 }
20424
20425 return CMD_SUCCESS;
20426 }
20427
20428 ALIAS(no_extcommunity_list_expanded_all,
20429 no_bgp_extcommunity_list_expanded_all_list_cmd,
20430 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20431 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20432 "Extended Community list number (expanded)\n"
20433 "Specify expanded extcommunity-list\n"
20434 "Extended Community list name\n")
20435
20436 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20437 {
20438 struct community_entry *entry;
20439
20440 for (entry = list->head; entry; entry = entry->next) {
20441 if (entry == list->head) {
20442 if (all_digit(list->name))
20443 vty_out(vty, "Extended community %s list %s\n",
20444 entry->style == EXTCOMMUNITY_LIST_STANDARD
20445 ? "standard"
20446 : "(expanded) access",
20447 list->name);
20448 else
20449 vty_out(vty,
20450 "Named extended community %s list %s\n",
20451 entry->style == EXTCOMMUNITY_LIST_STANDARD
20452 ? "standard"
20453 : "expanded",
20454 list->name);
20455 }
20456 if (entry->any)
20457 vty_out(vty, " %s\n",
20458 community_direct_str(entry->direct));
20459 else
20460 vty_out(vty, " %s %s\n",
20461 community_direct_str(entry->direct),
20462 community_list_config_str(entry));
20463 }
20464 }
20465
20466 DEFUN (show_extcommunity_list,
20467 show_bgp_extcommunity_list_cmd,
20468 "show bgp extcommunity-list",
20469 SHOW_STR
20470 BGP_STR
20471 "List extended-community list\n")
20472 {
20473 struct community_list *list;
20474 struct community_list_master *cm;
20475
20476 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20477 if (!cm)
20478 return CMD_SUCCESS;
20479
20480 for (list = cm->num.head; list; list = list->next)
20481 extcommunity_list_show(vty, list);
20482
20483 for (list = cm->str.head; list; list = list->next)
20484 extcommunity_list_show(vty, list);
20485
20486 return CMD_SUCCESS;
20487 }
20488
20489 DEFUN (show_extcommunity_list_arg,
20490 show_bgp_extcommunity_list_arg_cmd,
20491 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20492 SHOW_STR
20493 BGP_STR
20494 "List extended-community list\n"
20495 "Extcommunity-list number\n"
20496 "Extcommunity-list name\n"
20497 "Detailed information on extcommunity-list\n")
20498 {
20499 int idx_comm_list = 3;
20500 struct community_list *list;
20501
20502 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20503 EXTCOMMUNITY_LIST_MASTER);
20504 if (!list) {
20505 vty_out(vty, "%% Can't find extcommunity-list\n");
20506 return CMD_WARNING;
20507 }
20508
20509 extcommunity_list_show(vty, list);
20510
20511 return CMD_SUCCESS;
20512 }
20513
20514 /* Display community-list and extcommunity-list configuration. */
20515 static int community_list_config_write(struct vty *vty)
20516 {
20517 struct community_list *list;
20518 struct community_entry *entry;
20519 struct community_list_master *cm;
20520 int write = 0;
20521
20522 /* Community-list. */
20523 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20524
20525 for (list = cm->num.head; list; list = list->next)
20526 for (entry = list->head; entry; entry = entry->next) {
20527 vty_out(vty,
20528 "bgp community-list %s seq %" PRId64 " %s %s\n",
20529 list->name, entry->seq,
20530 community_direct_str(entry->direct),
20531 community_list_config_str(entry));
20532 write++;
20533 }
20534 for (list = cm->str.head; list; list = list->next)
20535 for (entry = list->head; entry; entry = entry->next) {
20536 vty_out(vty,
20537 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20538 entry->style == COMMUNITY_LIST_STANDARD
20539 ? "standard"
20540 : "expanded",
20541 list->name, entry->seq,
20542 community_direct_str(entry->direct),
20543 community_list_config_str(entry));
20544 write++;
20545 }
20546
20547 /* Extcommunity-list. */
20548 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20549
20550 for (list = cm->num.head; list; list = list->next)
20551 for (entry = list->head; entry; entry = entry->next) {
20552 vty_out(vty,
20553 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20554 list->name, entry->seq,
20555 community_direct_str(entry->direct),
20556 community_list_config_str(entry));
20557 write++;
20558 }
20559 for (list = cm->str.head; list; list = list->next)
20560 for (entry = list->head; entry; entry = entry->next) {
20561 vty_out(vty,
20562 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20563 entry->style == EXTCOMMUNITY_LIST_STANDARD
20564 ? "standard"
20565 : "expanded",
20566 list->name, entry->seq,
20567 community_direct_str(entry->direct),
20568 community_list_config_str(entry));
20569 write++;
20570 }
20571
20572
20573 /* lcommunity-list. */
20574 cm = community_list_master_lookup(bgp_clist,
20575 LARGE_COMMUNITY_LIST_MASTER);
20576
20577 for (list = cm->num.head; list; list = list->next)
20578 for (entry = list->head; entry; entry = entry->next) {
20579 vty_out(vty,
20580 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20581 list->name, entry->seq,
20582 community_direct_str(entry->direct),
20583 community_list_config_str(entry));
20584 write++;
20585 }
20586 for (list = cm->str.head; list; list = list->next)
20587 for (entry = list->head; entry; entry = entry->next) {
20588 vty_out(vty,
20589 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20590
20591 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20592 ? "standard"
20593 : "expanded",
20594 list->name, entry->seq, community_direct_str(entry->direct),
20595 community_list_config_str(entry));
20596 write++;
20597 }
20598
20599 return write;
20600 }
20601
20602 static int community_list_config_write(struct vty *vty);
20603 static struct cmd_node community_list_node = {
20604 .name = "community list",
20605 .node = COMMUNITY_LIST_NODE,
20606 .prompt = "",
20607 .config_write = community_list_config_write,
20608 };
20609
20610 static void community_list_vty(void)
20611 {
20612 install_node(&community_list_node);
20613
20614 /* Community-list. */
20615 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20616 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20617 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20618 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20619 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20620 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20621 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20622 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20623
20624 /* Extcommunity-list. */
20625 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20626 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20627 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20628 install_element(CONFIG_NODE,
20629 &no_bgp_extcommunity_list_standard_all_list_cmd);
20630 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20631 install_element(CONFIG_NODE,
20632 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20633 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20634 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20635
20636 /* Large Community List */
20637 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20638 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20639 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20640 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20641 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20642 install_element(CONFIG_NODE,
20643 &no_bgp_lcommunity_list_name_standard_all_cmd);
20644 install_element(CONFIG_NODE,
20645 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20646 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20647 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20648 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20649 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20650 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20651 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20652
20653 bgp_community_list_command_completion_setup();
20654 }
20655
20656 static struct cmd_node community_alias_node = {
20657 .name = "community alias",
20658 .node = COMMUNITY_ALIAS_NODE,
20659 .prompt = "",
20660 .config_write = bgp_community_alias_write,
20661 };
20662
20663 void community_alias_vty(void)
20664 {
20665 install_node(&community_alias_node);
20666
20667 /* Community-list. */
20668 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20669
20670 bgp_community_alias_command_completion_setup();
20671 }