]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #11611 from fdumontet6WIND/FMJA/desc_mess
[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 vty_out(vty,
955 "%% BGP: Enable %s address family for the neighbor %s\n",
956 get_afi_safi_str(afi, safi, false), peer->host);
957 break;
958 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
959 vty_out(vty,
960 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
961 peer->host);
962 break;
963 default:
964 break;
965 }
966 }
967
968 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
969 struct listnode **nnode, enum bgp_clear_type stype)
970 {
971 int ret = 0;
972 struct peer_af *paf;
973
974 /* if afi/.safi not specified, spin thru all of them */
975 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
976 afi_t tmp_afi;
977 safi_t tmp_safi;
978 enum bgp_af_index index;
979
980 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
981 paf = peer->peer_af_array[index];
982 if (!paf)
983 continue;
984
985 if (paf && paf->subgroup)
986 SET_FLAG(paf->subgroup->sflags,
987 SUBGRP_STATUS_FORCE_UPDATES);
988
989 tmp_afi = paf->afi;
990 tmp_safi = paf->safi;
991 if (!peer->afc[tmp_afi][tmp_safi])
992 continue;
993
994 if (stype == BGP_CLEAR_SOFT_NONE)
995 ret = peer_clear(peer, nnode);
996 else
997 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
998 stype);
999 }
1000 /* if afi specified and safi not, spin thru safis on this afi */
1001 } else if (safi == SAFI_UNSPEC) {
1002 safi_t tmp_safi;
1003
1004 for (tmp_safi = SAFI_UNICAST;
1005 tmp_safi < SAFI_MAX; tmp_safi++) {
1006 if (!peer->afc[afi][tmp_safi])
1007 continue;
1008
1009 paf = peer_af_find(peer, afi, tmp_safi);
1010 if (paf && paf->subgroup)
1011 SET_FLAG(paf->subgroup->sflags,
1012 SUBGRP_STATUS_FORCE_UPDATES);
1013
1014 if (stype == BGP_CLEAR_SOFT_NONE)
1015 ret = peer_clear(peer, nnode);
1016 else
1017 ret = peer_clear_soft(peer, afi,
1018 tmp_safi, stype);
1019 }
1020 /* both afi/safi specified, let the caller know if not defined */
1021 } else {
1022 if (!peer->afc[afi][safi])
1023 return 1;
1024
1025 paf = peer_af_find(peer, afi, safi);
1026 if (paf && paf->subgroup)
1027 SET_FLAG(paf->subgroup->sflags,
1028 SUBGRP_STATUS_FORCE_UPDATES);
1029
1030 if (stype == BGP_CLEAR_SOFT_NONE)
1031 ret = peer_clear(peer, nnode);
1032 else
1033 ret = peer_clear_soft(peer, afi, safi, stype);
1034 }
1035
1036 return ret;
1037 }
1038
1039 /* `clear ip bgp' functions. */
1040 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1041 enum clear_sort sort, enum bgp_clear_type stype,
1042 const char *arg)
1043 {
1044 int ret = 0;
1045 bool found = false;
1046 struct peer *peer;
1047
1048 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1049
1050 /* Clear all neighbors. */
1051 /*
1052 * Pass along pointer to next node to peer_clear() when walking all
1053 * nodes on the BGP instance as that may get freed if it is a
1054 * doppelganger
1055 */
1056 if (sort == clear_all) {
1057 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1058
1059 bgp_peer_gr_flags_update(peer);
1060
1061 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1062 gr_router_detected = true;
1063
1064 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1065 stype);
1066
1067 if (ret < 0)
1068 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1069 }
1070
1071 if (gr_router_detected
1072 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1073 bgp_zebra_send_capabilities(bgp, false);
1074 } else if (!gr_router_detected
1075 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1076 bgp_zebra_send_capabilities(bgp, true);
1077 }
1078
1079 /* This is to apply read-only mode on this clear. */
1080 if (stype == BGP_CLEAR_SOFT_NONE)
1081 bgp->update_delay_over = 0;
1082
1083 return CMD_SUCCESS;
1084 }
1085
1086 /* Clear specified neighbor. */
1087 if (sort == clear_peer) {
1088 union sockunion su;
1089
1090 /* Make sockunion for lookup. */
1091 ret = str2sockunion(arg, &su);
1092 if (ret < 0) {
1093 peer = peer_lookup_by_conf_if(bgp, arg);
1094 if (!peer) {
1095 peer = peer_lookup_by_hostname(bgp, arg);
1096 if (!peer) {
1097 vty_out(vty,
1098 "Malformed address or name: %s\n",
1099 arg);
1100 return CMD_WARNING;
1101 }
1102 }
1103 } else {
1104 peer = peer_lookup(bgp, &su);
1105 if (!peer) {
1106 vty_out(vty,
1107 "%% BGP: Unknown neighbor - \"%s\"\n",
1108 arg);
1109 return CMD_WARNING;
1110 }
1111 }
1112
1113 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1114 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1115
1116 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1117
1118 /* if afi/safi not defined for this peer, let caller know */
1119 if (ret == 1)
1120 ret = BGP_ERR_AF_UNCONFIGURED;
1121
1122 if (ret < 0)
1123 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1124
1125 return CMD_SUCCESS;
1126 }
1127
1128 /* Clear all neighbors belonging to a specific peer-group. */
1129 if (sort == clear_group) {
1130 struct peer_group *group;
1131
1132 group = peer_group_lookup(bgp, arg);
1133 if (!group) {
1134 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1135 return CMD_WARNING;
1136 }
1137
1138 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1139 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1140
1141 if (ret < 0)
1142 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1143 else
1144 found = true;
1145 }
1146
1147 if (!found)
1148 vty_out(vty,
1149 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1150 get_afi_safi_str(afi, safi, false), arg);
1151
1152 return CMD_SUCCESS;
1153 }
1154
1155 /* Clear all external (eBGP) neighbors. */
1156 if (sort == clear_external) {
1157 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1158 if (peer->sort == BGP_PEER_IBGP)
1159 continue;
1160
1161 bgp_peer_gr_flags_update(peer);
1162
1163 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1164 gr_router_detected = true;
1165
1166 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1167
1168 if (ret < 0)
1169 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1170 else
1171 found = true;
1172 }
1173
1174 if (gr_router_detected
1175 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1176 bgp_zebra_send_capabilities(bgp, false);
1177 } else if (!gr_router_detected
1178 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1179 bgp_zebra_send_capabilities(bgp, true);
1180 }
1181
1182 if (!found)
1183 vty_out(vty,
1184 "%% BGP: No external %s peer is configured\n",
1185 get_afi_safi_str(afi, safi, false));
1186
1187 return CMD_SUCCESS;
1188 }
1189
1190 /* Clear all neighbors belonging to a specific AS. */
1191 if (sort == clear_as) {
1192 as_t as = strtoul(arg, NULL, 10);
1193
1194 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1195 if (peer->as != as)
1196 continue;
1197
1198 bgp_peer_gr_flags_update(peer);
1199
1200 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1201 gr_router_detected = true;
1202
1203 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1204
1205 if (ret < 0)
1206 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1207 else
1208 found = true;
1209 }
1210
1211 if (gr_router_detected
1212 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1213 bgp_zebra_send_capabilities(bgp, false);
1214 } else if (!gr_router_detected
1215 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1216 bgp_zebra_send_capabilities(bgp, true);
1217 }
1218
1219 if (!found)
1220 vty_out(vty,
1221 "%% BGP: No %s peer is configured with AS %s\n",
1222 get_afi_safi_str(afi, safi, false), arg);
1223
1224 return CMD_SUCCESS;
1225 }
1226
1227 return CMD_SUCCESS;
1228 }
1229
1230 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1231 safi_t safi, enum clear_sort sort,
1232 enum bgp_clear_type stype, const char *arg)
1233 {
1234 struct bgp *bgp;
1235
1236 /* BGP structure lookup. */
1237 if (name) {
1238 bgp = bgp_lookup_by_name(name);
1239 if (bgp == NULL) {
1240 vty_out(vty, "Can't find BGP instance %s\n", name);
1241 return CMD_WARNING;
1242 }
1243 } else {
1244 bgp = bgp_get_default();
1245 if (bgp == NULL) {
1246 vty_out(vty, "No BGP process is configured\n");
1247 return CMD_WARNING;
1248 }
1249 }
1250
1251 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1252 }
1253
1254 /* clear soft inbound */
1255 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1256 {
1257 afi_t afi;
1258 safi_t safi;
1259
1260 FOREACH_AFI_SAFI (afi, safi)
1261 bgp_clear_vty(vty, name, afi, safi, clear_all,
1262 BGP_CLEAR_SOFT_IN, NULL);
1263 }
1264
1265 /* clear soft outbound */
1266 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1267 {
1268 afi_t afi;
1269 safi_t safi;
1270
1271 FOREACH_AFI_SAFI (afi, safi)
1272 bgp_clear_vty(vty, name, afi, safi, clear_all,
1273 BGP_CLEAR_SOFT_OUT, NULL);
1274 }
1275
1276
1277 #ifndef VTYSH_EXTRACT_PL
1278 #include "bgpd/bgp_vty_clippy.c"
1279 #endif
1280
1281 DEFUN_HIDDEN (bgp_local_mac,
1282 bgp_local_mac_cmd,
1283 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1284 BGP_STR
1285 "Local MAC config\n"
1286 "VxLAN Network Identifier\n"
1287 "VNI number\n"
1288 "local mac\n"
1289 "mac address\n"
1290 "mac-mobility sequence\n"
1291 "seq number\n")
1292 {
1293 int rv;
1294 vni_t vni;
1295 struct ethaddr mac;
1296 struct ipaddr ip;
1297 uint32_t seq;
1298 struct bgp *bgp;
1299
1300 vni = strtoul(argv[3]->arg, NULL, 10);
1301 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1302 vty_out(vty, "%% Malformed MAC address\n");
1303 return CMD_WARNING;
1304 }
1305 memset(&ip, 0, sizeof(ip));
1306 seq = strtoul(argv[7]->arg, NULL, 10);
1307
1308 bgp = bgp_get_default();
1309 if (!bgp) {
1310 vty_out(vty, "Default BGP instance is not there\n");
1311 return CMD_WARNING;
1312 }
1313
1314 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1315 zero_esi);
1316 if (rv < 0) {
1317 vty_out(vty, "Internal error\n");
1318 return CMD_WARNING;
1319 }
1320
1321 return CMD_SUCCESS;
1322 }
1323
1324 DEFUN_HIDDEN (no_bgp_local_mac,
1325 no_bgp_local_mac_cmd,
1326 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1327 NO_STR
1328 BGP_STR
1329 "Local MAC config\n"
1330 "VxLAN Network Identifier\n"
1331 "VNI number\n"
1332 "local mac\n"
1333 "mac address\n")
1334 {
1335 int rv;
1336 vni_t vni;
1337 struct ethaddr mac;
1338 struct ipaddr ip;
1339 struct bgp *bgp;
1340
1341 vni = strtoul(argv[4]->arg, NULL, 10);
1342 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1343 vty_out(vty, "%% Malformed MAC address\n");
1344 return CMD_WARNING;
1345 }
1346 memset(&ip, 0, sizeof(ip));
1347
1348 bgp = bgp_get_default();
1349 if (!bgp) {
1350 vty_out(vty, "Default BGP instance is not there\n");
1351 return CMD_WARNING;
1352 }
1353
1354 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1355 if (rv < 0) {
1356 vty_out(vty, "Internal error\n");
1357 return CMD_WARNING;
1358 }
1359
1360 return CMD_SUCCESS;
1361 }
1362
1363 DEFUN (no_synchronization,
1364 no_synchronization_cmd,
1365 "no synchronization",
1366 NO_STR
1367 "Perform IGP synchronization\n")
1368 {
1369 return CMD_SUCCESS;
1370 }
1371
1372 DEFUN (no_auto_summary,
1373 no_auto_summary_cmd,
1374 "no auto-summary",
1375 NO_STR
1376 "Enable automatic network number summarization\n")
1377 {
1378 return CMD_SUCCESS;
1379 }
1380
1381 /* "router bgp" commands. */
1382 DEFUN_NOSH (router_bgp,
1383 router_bgp_cmd,
1384 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1385 ROUTER_STR
1386 BGP_STR
1387 AS_STR
1388 BGP_INSTANCE_HELP_STR)
1389 {
1390 int idx_asn = 2;
1391 int idx_view_vrf = 3;
1392 int idx_vrf = 4;
1393 int is_new_bgp = 0;
1394 int ret;
1395 as_t as;
1396 struct bgp *bgp;
1397 const char *name = NULL;
1398 enum bgp_instance_type inst_type;
1399
1400 // "router bgp" without an ASN
1401 if (argc == 2) {
1402 // Pending: Make VRF option available for ASN less config
1403 bgp = bgp_get_default();
1404
1405 if (bgp == NULL) {
1406 vty_out(vty, "%% No BGP process is configured\n");
1407 return CMD_WARNING_CONFIG_FAILED;
1408 }
1409
1410 if (listcount(bm->bgp) > 1) {
1411 vty_out(vty, "%% Please specify ASN and VRF\n");
1412 return CMD_WARNING_CONFIG_FAILED;
1413 }
1414 }
1415
1416 // "router bgp X"
1417 else {
1418 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1419
1420 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1421 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1422 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1423
1424 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1425 if (argc > 3) {
1426 name = argv[idx_vrf]->arg;
1427
1428 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1429 if (strmatch(name, VRF_DEFAULT_NAME))
1430 name = NULL;
1431 else
1432 inst_type = BGP_INSTANCE_TYPE_VRF;
1433 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1434 inst_type = BGP_INSTANCE_TYPE_VIEW;
1435 }
1436
1437 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1438 is_new_bgp = (bgp_lookup(as, name) == NULL);
1439
1440 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1441 switch (ret) {
1442 case BGP_ERR_AS_MISMATCH:
1443 vty_out(vty, "BGP is already running; AS is %u\n", as);
1444 return CMD_WARNING_CONFIG_FAILED;
1445 case BGP_ERR_INSTANCE_MISMATCH:
1446 vty_out(vty,
1447 "BGP instance name and AS number mismatch\n");
1448 vty_out(vty,
1449 "BGP instance is already running; AS is %u\n",
1450 as);
1451 return CMD_WARNING_CONFIG_FAILED;
1452 }
1453
1454 /*
1455 * If we just instantiated the default instance, complete
1456 * any pending VRF-VPN leaking that was configured via
1457 * earlier "router bgp X vrf FOO" blocks.
1458 */
1459 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1460 vpn_leak_postchange_all();
1461
1462 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1463 bgp_vpn_leak_export(bgp);
1464 /* Pending: handle when user tries to change a view to vrf n vv.
1465 */
1466 }
1467
1468 /* unset the auto created flag as the user config is now present */
1469 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1470 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1471
1472 return CMD_SUCCESS;
1473 }
1474
1475 /* "no router bgp" commands. */
1476 DEFUN (no_router_bgp,
1477 no_router_bgp_cmd,
1478 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1479 NO_STR
1480 ROUTER_STR
1481 BGP_STR
1482 AS_STR
1483 BGP_INSTANCE_HELP_STR)
1484 {
1485 int idx_asn = 3;
1486 int idx_vrf = 5;
1487 as_t as;
1488 struct bgp *bgp;
1489 const char *name = NULL;
1490
1491 // "no router bgp" without an ASN
1492 if (argc == 3) {
1493 // Pending: Make VRF option available for ASN less config
1494 bgp = bgp_get_default();
1495
1496 if (bgp == NULL) {
1497 vty_out(vty, "%% No BGP process is configured\n");
1498 return CMD_WARNING_CONFIG_FAILED;
1499 }
1500
1501 if (listcount(bm->bgp) > 1) {
1502 vty_out(vty, "%% Please specify ASN and VRF\n");
1503 return CMD_WARNING_CONFIG_FAILED;
1504 }
1505
1506 if (bgp->l3vni) {
1507 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1508 bgp->l3vni);
1509 return CMD_WARNING_CONFIG_FAILED;
1510 }
1511 } else {
1512 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1513
1514 if (argc > 4) {
1515 name = argv[idx_vrf]->arg;
1516 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1517 && strmatch(name, VRF_DEFAULT_NAME))
1518 name = NULL;
1519 }
1520
1521 /* Lookup bgp structure. */
1522 bgp = bgp_lookup(as, name);
1523 if (!bgp) {
1524 vty_out(vty, "%% Can't find BGP instance\n");
1525 return CMD_WARNING_CONFIG_FAILED;
1526 }
1527
1528 if (bgp->l3vni) {
1529 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1530 bgp->l3vni);
1531 return CMD_WARNING_CONFIG_FAILED;
1532 }
1533
1534 /* Cannot delete default instance if vrf instances exist */
1535 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1536 struct listnode *node;
1537 struct bgp *tmp_bgp;
1538
1539 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1540 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1541 continue;
1542 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1543 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1544 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1545 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1546 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1547 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1548 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1549 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1550 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1551 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1552 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1553 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1554 (bgp == bgp_get_evpn() &&
1555 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1556 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1557 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1558 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1559 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1560 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1561 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1562 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1563 (hashcount(tmp_bgp->vnihash))) {
1564 vty_out(vty,
1565 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1566 return CMD_WARNING_CONFIG_FAILED;
1567 }
1568 }
1569 }
1570 }
1571
1572 bgp_delete(bgp);
1573
1574 return CMD_SUCCESS;
1575 }
1576
1577 /* bgp session-dscp */
1578
1579 DEFPY (bgp_session_dscp,
1580 bgp_session_dscp_cmd,
1581 "bgp session-dscp (0-63)$dscp",
1582 BGP_STR
1583 "Override default (C6) bgp TCP session DSCP value\n"
1584 "Manually configured dscp parameter\n")
1585 {
1586 bm->tcp_dscp = dscp << 2;
1587
1588 return CMD_SUCCESS;
1589 }
1590
1591 DEFPY (no_bgp_session_dscp,
1592 no_bgp_session_dscp_cmd,
1593 "no bgp session-dscp [(0-63)]",
1594 NO_STR
1595 BGP_STR
1596 "Override default (C6) bgp TCP session DSCP value\n"
1597 "Manually configured dscp parameter\n")
1598 {
1599 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1600
1601 return CMD_SUCCESS;
1602 }
1603
1604 /* BGP router-id. */
1605
1606 DEFPY (bgp_router_id,
1607 bgp_router_id_cmd,
1608 "bgp router-id A.B.C.D",
1609 BGP_STR
1610 "Override configured router identifier\n"
1611 "Manually configured router identifier\n")
1612 {
1613 VTY_DECLVAR_CONTEXT(bgp, bgp);
1614 bgp_router_id_static_set(bgp, router_id);
1615 return CMD_SUCCESS;
1616 }
1617
1618 DEFPY (no_bgp_router_id,
1619 no_bgp_router_id_cmd,
1620 "no bgp router-id [A.B.C.D]",
1621 NO_STR
1622 BGP_STR
1623 "Override configured router identifier\n"
1624 "Manually configured router identifier\n")
1625 {
1626 VTY_DECLVAR_CONTEXT(bgp, bgp);
1627
1628 if (router_id_str) {
1629 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1630 vty_out(vty, "%% BGP router-id doesn't match\n");
1631 return CMD_WARNING_CONFIG_FAILED;
1632 }
1633 }
1634
1635 router_id.s_addr = 0;
1636 bgp_router_id_static_set(bgp, router_id);
1637
1638 return CMD_SUCCESS;
1639 }
1640
1641 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1642 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1643 NO_STR BGP_STR
1644 "Add community specific parameters\n"
1645 "Create an alias for a community\n"
1646 "Community (AA:BB or AA:BB:CC)\n"
1647 "Alias name\n")
1648 {
1649 struct community_alias ca = {};
1650 struct community_alias *lookup_community;
1651 struct community_alias *lookup_alias;
1652 struct community *comm;
1653 struct lcommunity *lcomm;
1654 uint8_t invalid = 0;
1655
1656 comm = community_str2com(community);
1657 if (!comm)
1658 invalid++;
1659 community_free(&comm);
1660
1661 lcomm = lcommunity_str2com(community);
1662 if (!lcomm)
1663 invalid++;
1664 lcommunity_free(&lcomm);
1665
1666 if (invalid > 1) {
1667 vty_out(vty, "Invalid community format\n");
1668 return CMD_WARNING;
1669 }
1670
1671 strlcpy(ca.community, community, sizeof(ca.community));
1672 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1673
1674 lookup_community = bgp_ca_community_lookup(&ca);
1675 lookup_alias = bgp_ca_alias_lookup(&ca);
1676
1677 if (no) {
1678 bgp_ca_alias_delete(&ca);
1679 bgp_ca_community_delete(&ca);
1680 } else {
1681 if (lookup_alias) {
1682 /* Lookup if community hash table has an item
1683 * with the same alias name.
1684 */
1685 strlcpy(ca.community, lookup_alias->community,
1686 sizeof(ca.community));
1687 if (bgp_ca_community_lookup(&ca)) {
1688 vty_out(vty,
1689 "community (%s) already has this alias (%s)\n",
1690 lookup_alias->community,
1691 lookup_alias->alias);
1692 return CMD_WARNING;
1693 }
1694 bgp_ca_alias_delete(&ca);
1695 }
1696
1697 if (lookup_community) {
1698 /* Lookup if alias hash table has an item
1699 * with the same community.
1700 */
1701 strlcpy(ca.alias, lookup_community->alias,
1702 sizeof(ca.alias));
1703 if (bgp_ca_alias_lookup(&ca)) {
1704 vty_out(vty,
1705 "alias (%s) already has this community (%s)\n",
1706 lookup_community->alias,
1707 lookup_community->community);
1708 return CMD_WARNING;
1709 }
1710 bgp_ca_community_delete(&ca);
1711 }
1712
1713 bgp_ca_alias_insert(&ca);
1714 bgp_ca_community_insert(&ca);
1715 }
1716
1717 return CMD_SUCCESS;
1718 }
1719
1720 DEFPY (bgp_global_suppress_fib_pending,
1721 bgp_global_suppress_fib_pending_cmd,
1722 "[no] bgp suppress-fib-pending",
1723 NO_STR
1724 BGP_STR
1725 "Advertise only routes that are programmed in kernel to peers globally\n")
1726 {
1727 bm_wait_for_fib_set(!no);
1728
1729 return CMD_SUCCESS;
1730 }
1731
1732 DEFPY (bgp_suppress_fib_pending,
1733 bgp_suppress_fib_pending_cmd,
1734 "[no] bgp suppress-fib-pending",
1735 NO_STR
1736 BGP_STR
1737 "Advertise only routes that are programmed in kernel to peers\n")
1738 {
1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740
1741 bgp_suppress_fib_pending_set(bgp, !no);
1742 return CMD_SUCCESS;
1743 }
1744
1745
1746 /* BGP Cluster ID. */
1747 DEFUN (bgp_cluster_id,
1748 bgp_cluster_id_cmd,
1749 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1750 BGP_STR
1751 "Configure Route-Reflector Cluster-id\n"
1752 "Route-Reflector Cluster-id in IP address format\n"
1753 "Route-Reflector Cluster-id as 32 bit quantity\n")
1754 {
1755 VTY_DECLVAR_CONTEXT(bgp, bgp);
1756 int idx_ipv4 = 2;
1757 int ret;
1758 struct in_addr cluster;
1759
1760 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1761 if (!ret) {
1762 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1763 return CMD_WARNING_CONFIG_FAILED;
1764 }
1765
1766 bgp_cluster_id_set(bgp, &cluster);
1767 bgp_clear_star_soft_out(vty, bgp->name);
1768
1769 return CMD_SUCCESS;
1770 }
1771
1772 DEFUN (no_bgp_cluster_id,
1773 no_bgp_cluster_id_cmd,
1774 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1775 NO_STR
1776 BGP_STR
1777 "Configure Route-Reflector Cluster-id\n"
1778 "Route-Reflector Cluster-id in IP address format\n"
1779 "Route-Reflector Cluster-id as 32 bit quantity\n")
1780 {
1781 VTY_DECLVAR_CONTEXT(bgp, bgp);
1782 bgp_cluster_id_unset(bgp);
1783 bgp_clear_star_soft_out(vty, bgp->name);
1784
1785 return CMD_SUCCESS;
1786 }
1787
1788 DEFPY (bgp_norib,
1789 bgp_norib_cmd,
1790 "bgp no-rib",
1791 BGP_STR
1792 "Disable BGP route installation to RIB (Zebra)\n")
1793 {
1794 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1795 vty_out(vty,
1796 "%% No-RIB option is already set, nothing to do here.\n");
1797 return CMD_SUCCESS;
1798 }
1799
1800 bgp_option_norib_set_runtime();
1801
1802 return CMD_SUCCESS;
1803 }
1804
1805 DEFPY (no_bgp_norib,
1806 no_bgp_norib_cmd,
1807 "no bgp no-rib",
1808 NO_STR
1809 BGP_STR
1810 "Disable BGP route installation to RIB (Zebra)\n")
1811 {
1812 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1813 vty_out(vty,
1814 "%% No-RIB option is not set, nothing to do here.\n");
1815 return CMD_SUCCESS;
1816 }
1817
1818 bgp_option_norib_unset_runtime();
1819
1820 return CMD_SUCCESS;
1821 }
1822
1823 DEFPY (no_bgp_send_extra_data,
1824 no_bgp_send_extra_data_cmd,
1825 "[no] bgp send-extra-data zebra",
1826 NO_STR
1827 BGP_STR
1828 "Extra data to Zebra for display/use\n"
1829 "To zebra\n")
1830 {
1831 if (no)
1832 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1833 else
1834 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1835
1836 return CMD_SUCCESS;
1837 }
1838
1839 DEFUN (bgp_confederation_identifier,
1840 bgp_confederation_identifier_cmd,
1841 "bgp confederation identifier (1-4294967295)",
1842 BGP_STR
1843 "AS confederation parameters\n"
1844 "AS number\n"
1845 "Set routing domain confederation AS\n")
1846 {
1847 VTY_DECLVAR_CONTEXT(bgp, bgp);
1848 int idx_number = 3;
1849 as_t as;
1850
1851 as = strtoul(argv[idx_number]->arg, NULL, 10);
1852
1853 bgp_confederation_id_set(bgp, as);
1854
1855 return CMD_SUCCESS;
1856 }
1857
1858 DEFUN (no_bgp_confederation_identifier,
1859 no_bgp_confederation_identifier_cmd,
1860 "no bgp confederation identifier [(1-4294967295)]",
1861 NO_STR
1862 BGP_STR
1863 "AS confederation parameters\n"
1864 "AS number\n"
1865 "Set routing domain confederation AS\n")
1866 {
1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868 bgp_confederation_id_unset(bgp);
1869
1870 return CMD_SUCCESS;
1871 }
1872
1873 DEFUN (bgp_confederation_peers,
1874 bgp_confederation_peers_cmd,
1875 "bgp confederation peers (1-4294967295)...",
1876 BGP_STR
1877 "AS confederation parameters\n"
1878 "Peer ASs in BGP confederation\n"
1879 AS_STR)
1880 {
1881 VTY_DECLVAR_CONTEXT(bgp, bgp);
1882 int idx_asn = 3;
1883 as_t as;
1884 int i;
1885
1886 for (i = idx_asn; i < argc; i++) {
1887 as = strtoul(argv[i]->arg, NULL, 10);
1888
1889 if (bgp->as == as) {
1890 vty_out(vty,
1891 "%% Local member-AS not allowed in confed peer list\n");
1892 continue;
1893 }
1894
1895 bgp_confederation_peers_add(bgp, as);
1896 }
1897 return CMD_SUCCESS;
1898 }
1899
1900 DEFUN (no_bgp_confederation_peers,
1901 no_bgp_confederation_peers_cmd,
1902 "no bgp confederation peers (1-4294967295)...",
1903 NO_STR
1904 BGP_STR
1905 "AS confederation parameters\n"
1906 "Peer ASs in BGP confederation\n"
1907 AS_STR)
1908 {
1909 VTY_DECLVAR_CONTEXT(bgp, bgp);
1910 int idx_asn = 4;
1911 as_t as;
1912 int i;
1913
1914 for (i = idx_asn; i < argc; i++) {
1915 as = strtoul(argv[i]->arg, NULL, 10);
1916
1917 bgp_confederation_peers_remove(bgp, as);
1918 }
1919 return CMD_SUCCESS;
1920 }
1921
1922 /**
1923 * Central routine for maximum-paths configuration.
1924 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1925 * @set: 1 for setting values, 0 for removing the max-paths config.
1926 */
1927 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1928 const char *mpaths, uint16_t options,
1929 int set)
1930 {
1931 VTY_DECLVAR_CONTEXT(bgp, bgp);
1932 uint16_t maxpaths = 0;
1933 int ret;
1934 afi_t afi;
1935 safi_t safi;
1936
1937 afi = bgp_node_afi(vty);
1938 safi = bgp_node_safi(vty);
1939
1940 if (set) {
1941 maxpaths = strtol(mpaths, NULL, 10);
1942 if (maxpaths > multipath_num) {
1943 vty_out(vty,
1944 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1945 maxpaths, multipath_num);
1946 return CMD_WARNING_CONFIG_FAILED;
1947 }
1948 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1949 options);
1950 } else
1951 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1952
1953 if (ret < 0) {
1954 vty_out(vty,
1955 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1956 (set == 1) ? "" : "un",
1957 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1958 maxpaths, afi, safi);
1959 return CMD_WARNING_CONFIG_FAILED;
1960 }
1961
1962 bgp_recalculate_all_bestpaths(bgp);
1963
1964 return CMD_SUCCESS;
1965 }
1966
1967 DEFUN (bgp_maxmed_admin,
1968 bgp_maxmed_admin_cmd,
1969 "bgp max-med administrative ",
1970 BGP_STR
1971 "Advertise routes with max-med\n"
1972 "Administratively applied, for an indefinite period\n")
1973 {
1974 VTY_DECLVAR_CONTEXT(bgp, bgp);
1975
1976 bgp->v_maxmed_admin = 1;
1977 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1978
1979 bgp_maxmed_update(bgp);
1980
1981 return CMD_SUCCESS;
1982 }
1983
1984 DEFUN (bgp_maxmed_admin_medv,
1985 bgp_maxmed_admin_medv_cmd,
1986 "bgp max-med administrative (0-4294967295)",
1987 BGP_STR
1988 "Advertise routes with max-med\n"
1989 "Administratively applied, for an indefinite period\n"
1990 "Max MED value to be used\n")
1991 {
1992 VTY_DECLVAR_CONTEXT(bgp, bgp);
1993 int idx_number = 3;
1994
1995 bgp->v_maxmed_admin = 1;
1996 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1997
1998 bgp_maxmed_update(bgp);
1999
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (no_bgp_maxmed_admin,
2004 no_bgp_maxmed_admin_cmd,
2005 "no bgp max-med administrative [(0-4294967295)]",
2006 NO_STR
2007 BGP_STR
2008 "Advertise routes with max-med\n"
2009 "Administratively applied, for an indefinite period\n"
2010 "Max MED value to be used\n")
2011 {
2012 VTY_DECLVAR_CONTEXT(bgp, bgp);
2013 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2014 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2015 bgp_maxmed_update(bgp);
2016
2017 return CMD_SUCCESS;
2018 }
2019
2020 DEFUN (bgp_maxmed_onstartup,
2021 bgp_maxmed_onstartup_cmd,
2022 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2023 BGP_STR
2024 "Advertise routes with max-med\n"
2025 "Effective on a startup\n"
2026 "Time (seconds) period for max-med\n"
2027 "Max MED value to be used\n")
2028 {
2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 int idx = 0;
2031
2032 if (argv_find(argv, argc, "(5-86400)", &idx))
2033 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2034 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2035 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2036 else
2037 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2038
2039 bgp_maxmed_update(bgp);
2040
2041 return CMD_SUCCESS;
2042 }
2043
2044 DEFUN (no_bgp_maxmed_onstartup,
2045 no_bgp_maxmed_onstartup_cmd,
2046 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2047 NO_STR
2048 BGP_STR
2049 "Advertise routes with max-med\n"
2050 "Effective on a startup\n"
2051 "Time (seconds) period for max-med\n"
2052 "Max MED value to be used\n")
2053 {
2054 VTY_DECLVAR_CONTEXT(bgp, bgp);
2055
2056 /* Cancel max-med onstartup if its on */
2057 if (bgp->t_maxmed_onstartup) {
2058 thread_cancel(&bgp->t_maxmed_onstartup);
2059 bgp->maxmed_onstartup_over = 1;
2060 }
2061
2062 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2063 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2064
2065 bgp_maxmed_update(bgp);
2066
2067 return CMD_SUCCESS;
2068 }
2069
2070 static int bgp_global_update_delay_config_vty(struct vty *vty,
2071 uint16_t update_delay,
2072 uint16_t establish_wait)
2073 {
2074 struct listnode *node, *nnode;
2075 struct bgp *bgp;
2076 bool vrf_cfg = false;
2077
2078 /*
2079 * See if update-delay is set per-vrf and warn user to delete it
2080 * Note that we only need to check this if this is the first time
2081 * setting the global config.
2082 */
2083 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2084 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2085 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2086 vty_out(vty,
2087 "%% update-delay configuration found in vrf %s\n",
2088 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2089 ? VRF_DEFAULT_NAME
2090 : bgp->name);
2091 vrf_cfg = true;
2092 }
2093 }
2094 }
2095
2096 if (vrf_cfg) {
2097 vty_out(vty,
2098 "%%Failed: global update-delay config not permitted\n");
2099 return CMD_WARNING;
2100 }
2101
2102 if (!establish_wait) { /* update-delay <delay> */
2103 bm->v_update_delay = update_delay;
2104 bm->v_establish_wait = bm->v_update_delay;
2105 } else {
2106 /* update-delay <delay> <establish-wait> */
2107 if (update_delay < establish_wait) {
2108 vty_out(vty,
2109 "%%Failed: update-delay less than the establish-wait!\n");
2110 return CMD_WARNING_CONFIG_FAILED;
2111 }
2112
2113 bm->v_update_delay = update_delay;
2114 bm->v_establish_wait = establish_wait;
2115 }
2116
2117 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2118 bgp->v_update_delay = bm->v_update_delay;
2119 bgp->v_establish_wait = bm->v_establish_wait;
2120 }
2121
2122 return CMD_SUCCESS;
2123 }
2124
2125 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2126 {
2127 struct listnode *node, *nnode;
2128 struct bgp *bgp;
2129
2130 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2131 bm->v_establish_wait = bm->v_update_delay;
2132
2133 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2134 bgp->v_update_delay = bm->v_update_delay;
2135 bgp->v_establish_wait = bm->v_establish_wait;
2136 }
2137
2138 return CMD_SUCCESS;
2139 }
2140
2141 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2142 uint16_t establish_wait)
2143 {
2144 VTY_DECLVAR_CONTEXT(bgp, bgp);
2145
2146 /* if configured globally, per-instance config is not allowed */
2147 if (bm->v_update_delay) {
2148 vty_out(vty,
2149 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2150 return CMD_WARNING_CONFIG_FAILED;
2151 }
2152
2153
2154 if (!establish_wait) /* update-delay <delay> */
2155 {
2156 bgp->v_update_delay = update_delay;
2157 bgp->v_establish_wait = bgp->v_update_delay;
2158 return CMD_SUCCESS;
2159 }
2160
2161 /* update-delay <delay> <establish-wait> */
2162 if (update_delay < establish_wait) {
2163 vty_out(vty,
2164 "%%Failed: update-delay less than the establish-wait!\n");
2165 return CMD_WARNING_CONFIG_FAILED;
2166 }
2167
2168 bgp->v_update_delay = update_delay;
2169 bgp->v_establish_wait = establish_wait;
2170
2171 return CMD_SUCCESS;
2172 }
2173
2174 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2175 {
2176 VTY_DECLVAR_CONTEXT(bgp, bgp);
2177
2178 /* If configured globally, cannot remove from one bgp instance */
2179 if (bm->v_update_delay) {
2180 vty_out(vty,
2181 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2182 return CMD_WARNING_CONFIG_FAILED;
2183 }
2184 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2185 bgp->v_establish_wait = bgp->v_update_delay;
2186
2187 return CMD_SUCCESS;
2188 }
2189
2190 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2191 {
2192 /* If configured globally, no need to display per-instance value */
2193 if (bgp->v_update_delay != bm->v_update_delay) {
2194 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2195 if (bgp->v_update_delay != bgp->v_establish_wait)
2196 vty_out(vty, " %d", bgp->v_establish_wait);
2197 vty_out(vty, "\n");
2198 }
2199 }
2200
2201 /* Global update-delay configuration */
2202 DEFPY (bgp_global_update_delay,
2203 bgp_global_update_delay_cmd,
2204 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2205 BGP_STR
2206 "Force initial delay for best-path and updates for all bgp instances\n"
2207 "Max delay in seconds\n"
2208 "Establish wait in seconds\n")
2209 {
2210 return bgp_global_update_delay_config_vty(vty, delay, wait);
2211 }
2212
2213 /* Global update-delay deconfiguration */
2214 DEFPY (no_bgp_global_update_delay,
2215 no_bgp_global_update_delay_cmd,
2216 "no bgp update-delay [(0-3600) [(1-3600)]]",
2217 NO_STR
2218 BGP_STR
2219 "Force initial delay for best-path and updates\n"
2220 "Max delay in seconds\n"
2221 "Establish wait in seconds\n")
2222 {
2223 return bgp_global_update_delay_deconfig_vty(vty);
2224 }
2225
2226 /* Update-delay configuration */
2227
2228 DEFPY (bgp_update_delay,
2229 bgp_update_delay_cmd,
2230 "update-delay (0-3600)$delay [(1-3600)$wait]",
2231 "Force initial delay for best-path and updates\n"
2232 "Max delay in seconds\n"
2233 "Establish wait in seconds\n")
2234 {
2235 return bgp_update_delay_config_vty(vty, delay, wait);
2236 }
2237
2238 /* Update-delay deconfiguration */
2239 DEFPY (no_bgp_update_delay,
2240 no_bgp_update_delay_cmd,
2241 "no update-delay [(0-3600) [(1-3600)]]",
2242 NO_STR
2243 "Force initial delay for best-path and updates\n"
2244 "Max delay in seconds\n"
2245 "Establish wait in seconds\n")
2246 {
2247 return bgp_update_delay_deconfig_vty(vty);
2248 }
2249
2250
2251 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2252 bool set)
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255
2256 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2257 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2258
2259 return CMD_SUCCESS;
2260 }
2261
2262 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2263 bool set)
2264 {
2265 VTY_DECLVAR_CONTEXT(bgp, bgp);
2266
2267 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2268 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2269
2270 return CMD_SUCCESS;
2271 }
2272
2273 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2274 {
2275 uint32_t quanta =
2276 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2277 if (quanta != BGP_WRITE_PACKET_MAX)
2278 vty_out(vty, " write-quanta %d\n", quanta);
2279 }
2280
2281 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2282 {
2283 uint32_t quanta =
2284 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2285 if (quanta != BGP_READ_PACKET_MAX)
2286 vty_out(vty, " read-quanta %d\n", quanta);
2287 }
2288
2289 /* Packet quanta configuration
2290 *
2291 * XXX: The value set here controls the size of a stack buffer in the IO
2292 * thread. When changing these limits be careful to prevent stack overflow.
2293 *
2294 * Furthermore, the maximums used here should correspond to
2295 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2296 */
2297 DEFPY (bgp_wpkt_quanta,
2298 bgp_wpkt_quanta_cmd,
2299 "[no] write-quanta (1-64)$quanta",
2300 NO_STR
2301 "How many packets to write to peer socket per run\n"
2302 "Number of packets\n")
2303 {
2304 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2305 }
2306
2307 DEFPY (bgp_rpkt_quanta,
2308 bgp_rpkt_quanta_cmd,
2309 "[no] read-quanta (1-10)$quanta",
2310 NO_STR
2311 "How many packets to read from peer socket per I/O cycle\n"
2312 "Number of packets\n")
2313 {
2314 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2315 }
2316
2317 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2318 {
2319 if (!bgp->heuristic_coalesce)
2320 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2321 }
2322
2323
2324 DEFUN (bgp_coalesce_time,
2325 bgp_coalesce_time_cmd,
2326 "coalesce-time (0-4294967295)",
2327 "Subgroup coalesce timer\n"
2328 "Subgroup coalesce timer value (in ms)\n")
2329 {
2330 VTY_DECLVAR_CONTEXT(bgp, bgp);
2331
2332 int idx = 0;
2333
2334 bgp->heuristic_coalesce = false;
2335
2336 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2337 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2338
2339 return CMD_SUCCESS;
2340 }
2341
2342 DEFUN (no_bgp_coalesce_time,
2343 no_bgp_coalesce_time_cmd,
2344 "no coalesce-time (0-4294967295)",
2345 NO_STR
2346 "Subgroup coalesce timer\n"
2347 "Subgroup coalesce timer value (in ms)\n")
2348 {
2349 VTY_DECLVAR_CONTEXT(bgp, bgp);
2350
2351 bgp->heuristic_coalesce = true;
2352 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2353 return CMD_SUCCESS;
2354 }
2355
2356 /* Maximum-paths configuration */
2357 DEFUN (bgp_maxpaths,
2358 bgp_maxpaths_cmd,
2359 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2360 "Forward packets over multiple paths\n"
2361 "Number of paths\n")
2362 {
2363 int idx_number = 1;
2364 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2365 argv[idx_number]->arg, 0, 1);
2366 }
2367
2368 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2369 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2370 "Forward packets over multiple paths\n"
2371 "Number of paths\n")
2372
2373 DEFUN (bgp_maxpaths_ibgp,
2374 bgp_maxpaths_ibgp_cmd,
2375 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2376 "Forward packets over multiple paths\n"
2377 "iBGP-multipath\n"
2378 "Number of paths\n")
2379 {
2380 int idx_number = 2;
2381 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2382 argv[idx_number]->arg, 0, 1);
2383 }
2384
2385 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2386 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2387 "Forward packets over multiple paths\n"
2388 "iBGP-multipath\n"
2389 "Number of paths\n")
2390
2391 DEFUN (bgp_maxpaths_ibgp_cluster,
2392 bgp_maxpaths_ibgp_cluster_cmd,
2393 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2394 "Forward packets over multiple paths\n"
2395 "iBGP-multipath\n"
2396 "Number of paths\n"
2397 "Match the cluster length\n")
2398 {
2399 int idx_number = 2;
2400 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2401 argv[idx_number]->arg, true, 1);
2402 }
2403
2404 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2405 "maximum-paths ibgp " CMD_RANGE_STR(
2406 1, MULTIPATH_NUM) " equal-cluster-length",
2407 "Forward packets over multiple paths\n"
2408 "iBGP-multipath\n"
2409 "Number of paths\n"
2410 "Match the cluster length\n")
2411
2412 DEFUN (no_bgp_maxpaths,
2413 no_bgp_maxpaths_cmd,
2414 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2415 NO_STR
2416 "Forward packets over multiple paths\n"
2417 "Number of paths\n")
2418 {
2419 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2420 }
2421
2422 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2423 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2424 "Forward packets over multiple paths\n"
2425 "Number of paths\n")
2426
2427 DEFUN (no_bgp_maxpaths_ibgp,
2428 no_bgp_maxpaths_ibgp_cmd,
2429 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2430 NO_STR
2431 "Forward packets over multiple paths\n"
2432 "iBGP-multipath\n"
2433 "Number of paths\n"
2434 "Match the cluster length\n")
2435 {
2436 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2437 }
2438
2439 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2440 "no maximum-paths ibgp [" CMD_RANGE_STR(
2441 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2442 NO_STR
2443 "Forward packets over multiple paths\n"
2444 "iBGP-multipath\n"
2445 "Number of paths\n"
2446 "Match the cluster length\n")
2447
2448 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2449 afi_t afi, safi_t safi)
2450 {
2451 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2452 vty_out(vty, " maximum-paths %d\n",
2453 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2454 }
2455
2456 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2457 vty_out(vty, " maximum-paths ibgp %d",
2458 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2459 if (bgp->maxpaths[afi][safi].same_clusterlen)
2460 vty_out(vty, " equal-cluster-length");
2461 vty_out(vty, "\n");
2462 }
2463 }
2464
2465 /* BGP timers. */
2466
2467 DEFUN (bgp_timers,
2468 bgp_timers_cmd,
2469 "timers bgp (0-65535) (0-65535)",
2470 "Adjust routing timers\n"
2471 "BGP timers\n"
2472 "Keepalive interval\n"
2473 "Holdtime\n")
2474 {
2475 VTY_DECLVAR_CONTEXT(bgp, bgp);
2476 int idx_number = 2;
2477 int idx_number_2 = 3;
2478 unsigned long keepalive = 0;
2479 unsigned long holdtime = 0;
2480
2481 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2482 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2483
2484 /* Holdtime value check. */
2485 if (holdtime < 3 && holdtime != 0) {
2486 vty_out(vty,
2487 "%% hold time value must be either 0 or greater than 3\n");
2488 return CMD_WARNING_CONFIG_FAILED;
2489 }
2490
2491 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2492 BGP_DEFAULT_DELAYOPEN);
2493
2494 return CMD_SUCCESS;
2495 }
2496
2497 DEFUN (no_bgp_timers,
2498 no_bgp_timers_cmd,
2499 "no timers bgp [(0-65535) (0-65535)]",
2500 NO_STR
2501 "Adjust routing timers\n"
2502 "BGP timers\n"
2503 "Keepalive interval\n"
2504 "Holdtime\n")
2505 {
2506 VTY_DECLVAR_CONTEXT(bgp, bgp);
2507 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2508 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2509
2510 return CMD_SUCCESS;
2511 }
2512
2513 /* BGP minimum holdtime. */
2514
2515 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2516 "bgp minimum-holdtime (1-65535)",
2517 "BGP specific commands\n"
2518 "BGP minimum holdtime\n"
2519 "Seconds\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int idx_number = 2;
2523 unsigned long min_holdtime;
2524
2525 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2526
2527 bgp->default_min_holdtime = min_holdtime;
2528
2529 return CMD_SUCCESS;
2530 }
2531
2532 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2533 "no bgp minimum-holdtime [(1-65535)]",
2534 NO_STR
2535 "BGP specific commands\n"
2536 "BGP minimum holdtime\n"
2537 "Seconds\n")
2538 {
2539 VTY_DECLVAR_CONTEXT(bgp, bgp);
2540
2541 bgp->default_min_holdtime = 0;
2542
2543 return CMD_SUCCESS;
2544 }
2545
2546 DEFUN (bgp_client_to_client_reflection,
2547 bgp_client_to_client_reflection_cmd,
2548 "bgp client-to-client reflection",
2549 BGP_STR
2550 "Configure client to client route reflection\n"
2551 "reflection of routes allowed\n")
2552 {
2553 VTY_DECLVAR_CONTEXT(bgp, bgp);
2554 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2555 bgp_clear_star_soft_out(vty, bgp->name);
2556
2557 return CMD_SUCCESS;
2558 }
2559
2560 DEFUN (no_bgp_client_to_client_reflection,
2561 no_bgp_client_to_client_reflection_cmd,
2562 "no bgp client-to-client reflection",
2563 NO_STR
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 SET_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 /* "bgp always-compare-med" configuration. */
2576 DEFUN (bgp_always_compare_med,
2577 bgp_always_compare_med_cmd,
2578 "bgp always-compare-med",
2579 BGP_STR
2580 "Allow comparing MED from different neighbors\n")
2581 {
2582 VTY_DECLVAR_CONTEXT(bgp, bgp);
2583 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2584 bgp_recalculate_all_bestpaths(bgp);
2585
2586 return CMD_SUCCESS;
2587 }
2588
2589 DEFUN (no_bgp_always_compare_med,
2590 no_bgp_always_compare_med_cmd,
2591 "no bgp always-compare-med",
2592 NO_STR
2593 BGP_STR
2594 "Allow comparing MED from different neighbors\n")
2595 {
2596 VTY_DECLVAR_CONTEXT(bgp, bgp);
2597 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2598 bgp_recalculate_all_bestpaths(bgp);
2599
2600 return CMD_SUCCESS;
2601 }
2602
2603
2604 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2605 "bgp ebgp-requires-policy",
2606 BGP_STR
2607 "Require in and out policy for eBGP peers (RFC8212)\n")
2608 {
2609 VTY_DECLVAR_CONTEXT(bgp, bgp);
2610 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2611 return CMD_SUCCESS;
2612 }
2613
2614 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2615 "no bgp ebgp-requires-policy",
2616 NO_STR
2617 BGP_STR
2618 "Require in and out policy for eBGP peers (RFC8212)\n")
2619 {
2620 VTY_DECLVAR_CONTEXT(bgp, bgp);
2621 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2622 return CMD_SUCCESS;
2623 }
2624
2625 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2626 "bgp suppress-duplicates",
2627 BGP_STR
2628 "Suppress duplicate updates if the route actually not changed\n")
2629 {
2630 VTY_DECLVAR_CONTEXT(bgp, bgp);
2631 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2632 return CMD_SUCCESS;
2633 }
2634
2635 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2636 "no bgp suppress-duplicates",
2637 NO_STR
2638 BGP_STR
2639 "Suppress duplicate updates if the route actually not changed\n")
2640 {
2641 VTY_DECLVAR_CONTEXT(bgp, bgp);
2642 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2643 return CMD_SUCCESS;
2644 }
2645
2646 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2647 "bgp reject-as-sets",
2648 BGP_STR
2649 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2650 {
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652 struct listnode *node, *nnode;
2653 struct peer *peer;
2654
2655 bgp->reject_as_sets = true;
2656
2657 /* Reset existing BGP sessions to reject routes
2658 * with aspath containing AS_SET or AS_CONFED_SET.
2659 */
2660 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2661 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2662 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2663 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2664 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2665 }
2666 }
2667
2668 return CMD_SUCCESS;
2669 }
2670
2671 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2672 "no bgp reject-as-sets",
2673 NO_STR
2674 BGP_STR
2675 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2676 {
2677 VTY_DECLVAR_CONTEXT(bgp, bgp);
2678 struct listnode *node, *nnode;
2679 struct peer *peer;
2680
2681 bgp->reject_as_sets = false;
2682
2683 /* Reset existing BGP sessions to reject routes
2684 * with aspath containing AS_SET or AS_CONFED_SET.
2685 */
2686 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2687 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2688 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2689 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2690 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2691 }
2692 }
2693
2694 return CMD_SUCCESS;
2695 }
2696
2697 /* "bgp deterministic-med" configuration. */
2698 DEFUN (bgp_deterministic_med,
2699 bgp_deterministic_med_cmd,
2700 "bgp deterministic-med",
2701 BGP_STR
2702 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2703 {
2704 VTY_DECLVAR_CONTEXT(bgp, bgp);
2705
2706 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2707 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2708 bgp_recalculate_all_bestpaths(bgp);
2709 }
2710
2711 return CMD_SUCCESS;
2712 }
2713
2714 DEFUN (no_bgp_deterministic_med,
2715 no_bgp_deterministic_med_cmd,
2716 "no bgp deterministic-med",
2717 NO_STR
2718 BGP_STR
2719 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2720 {
2721 VTY_DECLVAR_CONTEXT(bgp, bgp);
2722 int bestpath_per_as_used;
2723 afi_t afi;
2724 safi_t safi;
2725 struct peer *peer;
2726 struct listnode *node, *nnode;
2727
2728 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2729 bestpath_per_as_used = 0;
2730
2731 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2732 FOREACH_AFI_SAFI (afi, safi)
2733 if (bgp_addpath_dmed_required(
2734 peer->addpath_type[afi][safi])) {
2735 bestpath_per_as_used = 1;
2736 break;
2737 }
2738
2739 if (bestpath_per_as_used)
2740 break;
2741 }
2742
2743 if (bestpath_per_as_used) {
2744 vty_out(vty,
2745 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2746 return CMD_WARNING_CONFIG_FAILED;
2747 } else {
2748 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2749 bgp_recalculate_all_bestpaths(bgp);
2750 }
2751 }
2752
2753 return CMD_SUCCESS;
2754 }
2755
2756 /* "bgp graceful-restart mode" configuration. */
2757 DEFUN (bgp_graceful_restart,
2758 bgp_graceful_restart_cmd,
2759 "bgp graceful-restart",
2760 BGP_STR
2761 GR_CMD
2762 )
2763 {
2764 int ret = BGP_GR_FAILURE;
2765
2766 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2767 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2768
2769 VTY_DECLVAR_CONTEXT(bgp, bgp);
2770
2771 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2772
2773 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2774 ret);
2775
2776 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2777 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2778 vty_out(vty,
2779 "Graceful restart configuration changed, reset all peers to take effect\n");
2780 return bgp_vty_return(vty, ret);
2781 }
2782
2783 DEFUN (no_bgp_graceful_restart,
2784 no_bgp_graceful_restart_cmd,
2785 "no bgp graceful-restart",
2786 NO_STR
2787 BGP_STR
2788 NO_GR_CMD
2789 )
2790 {
2791 VTY_DECLVAR_CONTEXT(bgp, bgp);
2792
2793 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2794 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2795
2796 int ret = BGP_GR_FAILURE;
2797
2798 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2799
2800 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2801 ret);
2802
2803 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2804 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2805 vty_out(vty,
2806 "Graceful restart configuration changed, reset all peers to take effect\n");
2807
2808 return bgp_vty_return(vty, ret);
2809 }
2810
2811 DEFUN (bgp_graceful_restart_stalepath_time,
2812 bgp_graceful_restart_stalepath_time_cmd,
2813 "bgp graceful-restart stalepath-time (1-4095)",
2814 BGP_STR
2815 "Graceful restart capability parameters\n"
2816 "Set the max time to hold onto restarting peer's stale paths\n"
2817 "Delay value (seconds)\n")
2818 {
2819 VTY_DECLVAR_CONTEXT(bgp, bgp);
2820 int idx_number = 3;
2821 uint32_t stalepath;
2822
2823 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2824 bgp->stalepath_time = stalepath;
2825 return CMD_SUCCESS;
2826 }
2827
2828 DEFUN (bgp_graceful_restart_restart_time,
2829 bgp_graceful_restart_restart_time_cmd,
2830 "bgp graceful-restart restart-time (0-4095)",
2831 BGP_STR
2832 "Graceful restart capability parameters\n"
2833 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2834 "Delay value (seconds)\n")
2835 {
2836 VTY_DECLVAR_CONTEXT(bgp, bgp);
2837 int idx_number = 3;
2838 uint32_t restart;
2839
2840 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2841 bgp->restart_time = restart;
2842 return CMD_SUCCESS;
2843 }
2844
2845 DEFUN (bgp_graceful_restart_select_defer_time,
2846 bgp_graceful_restart_select_defer_time_cmd,
2847 "bgp graceful-restart select-defer-time (0-3600)",
2848 BGP_STR
2849 "Graceful restart capability parameters\n"
2850 "Set the time to defer the BGP route selection after restart\n"
2851 "Delay value (seconds, 0 - disable)\n")
2852 {
2853 VTY_DECLVAR_CONTEXT(bgp, bgp);
2854 int idx_number = 3;
2855 uint32_t defer_time;
2856
2857 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2858 bgp->select_defer_time = defer_time;
2859 if (defer_time == 0)
2860 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2861 else
2862 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2863
2864 return CMD_SUCCESS;
2865 }
2866
2867 DEFUN (no_bgp_graceful_restart_stalepath_time,
2868 no_bgp_graceful_restart_stalepath_time_cmd,
2869 "no bgp graceful-restart stalepath-time [(1-4095)]",
2870 NO_STR
2871 BGP_STR
2872 "Graceful restart capability parameters\n"
2873 "Set the max time to hold onto restarting peer's stale paths\n"
2874 "Delay value (seconds)\n")
2875 {
2876 VTY_DECLVAR_CONTEXT(bgp, bgp);
2877
2878 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2879 return CMD_SUCCESS;
2880 }
2881
2882 DEFUN (no_bgp_graceful_restart_restart_time,
2883 no_bgp_graceful_restart_restart_time_cmd,
2884 "no bgp graceful-restart restart-time [(0-4095)]",
2885 NO_STR
2886 BGP_STR
2887 "Graceful restart capability parameters\n"
2888 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2889 "Delay value (seconds)\n")
2890 {
2891 VTY_DECLVAR_CONTEXT(bgp, bgp);
2892
2893 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2894 return CMD_SUCCESS;
2895 }
2896
2897 DEFUN (no_bgp_graceful_restart_select_defer_time,
2898 no_bgp_graceful_restart_select_defer_time_cmd,
2899 "no bgp graceful-restart select-defer-time [(0-3600)]",
2900 NO_STR
2901 BGP_STR
2902 "Graceful restart capability parameters\n"
2903 "Set the time to defer the BGP route selection after restart\n"
2904 "Delay value (seconds)\n")
2905 {
2906 VTY_DECLVAR_CONTEXT(bgp, bgp);
2907
2908 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2909 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2910
2911 return CMD_SUCCESS;
2912 }
2913
2914 DEFUN (bgp_graceful_restart_preserve_fw,
2915 bgp_graceful_restart_preserve_fw_cmd,
2916 "bgp graceful-restart preserve-fw-state",
2917 BGP_STR
2918 "Graceful restart capability parameters\n"
2919 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2920 {
2921 VTY_DECLVAR_CONTEXT(bgp, bgp);
2922 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2923 return CMD_SUCCESS;
2924 }
2925
2926 DEFUN (no_bgp_graceful_restart_preserve_fw,
2927 no_bgp_graceful_restart_preserve_fw_cmd,
2928 "no bgp graceful-restart preserve-fw-state",
2929 NO_STR
2930 BGP_STR
2931 "Graceful restart capability parameters\n"
2932 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2933 {
2934 VTY_DECLVAR_CONTEXT(bgp, bgp);
2935 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2936 return CMD_SUCCESS;
2937 }
2938
2939 DEFPY (bgp_graceful_restart_notification,
2940 bgp_graceful_restart_notification_cmd,
2941 "[no$no] bgp graceful-restart notification",
2942 NO_STR
2943 BGP_STR
2944 "Graceful restart capability parameters\n"
2945 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2946 {
2947 VTY_DECLVAR_CONTEXT(bgp, bgp);
2948
2949 if (no)
2950 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2951 else
2952 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2953
2954 return CMD_SUCCESS;
2955 }
2956
2957 DEFPY (bgp_administrative_reset,
2958 bgp_administrative_reset_cmd,
2959 "[no$no] bgp hard-administrative-reset",
2960 NO_STR
2961 BGP_STR
2962 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2963 {
2964 VTY_DECLVAR_CONTEXT(bgp, bgp);
2965
2966 if (no)
2967 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2968 else
2969 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2970
2971 return CMD_SUCCESS;
2972 }
2973
2974 DEFUN (bgp_graceful_restart_disable,
2975 bgp_graceful_restart_disable_cmd,
2976 "bgp graceful-restart-disable",
2977 BGP_STR
2978 GR_DISABLE)
2979 {
2980 int ret = BGP_GR_FAILURE;
2981
2982 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2983 zlog_debug(
2984 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2985
2986 VTY_DECLVAR_CONTEXT(bgp, bgp);
2987
2988 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2989
2990 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2991 bgp->peer, ret);
2992
2993 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2994 zlog_debug(
2995 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2996 vty_out(vty,
2997 "Graceful restart configuration changed, reset all peers to take effect\n");
2998
2999 return bgp_vty_return(vty, ret);
3000 }
3001
3002 DEFUN (no_bgp_graceful_restart_disable,
3003 no_bgp_graceful_restart_disable_cmd,
3004 "no bgp graceful-restart-disable",
3005 NO_STR
3006 BGP_STR
3007 NO_GR_DISABLE
3008 )
3009 {
3010 VTY_DECLVAR_CONTEXT(bgp, bgp);
3011
3012 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3013 zlog_debug(
3014 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3015
3016 int ret = BGP_GR_FAILURE;
3017
3018 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3019
3020 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3021 ret);
3022
3023 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3024 zlog_debug(
3025 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3026 vty_out(vty,
3027 "Graceful restart configuration changed, reset all peers to take effect\n");
3028
3029 return bgp_vty_return(vty, ret);
3030 }
3031
3032 DEFUN (bgp_neighbor_graceful_restart_set,
3033 bgp_neighbor_graceful_restart_set_cmd,
3034 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3035 NEIGHBOR_STR
3036 NEIGHBOR_ADDR_STR2
3037 GR_NEIGHBOR_CMD
3038 )
3039 {
3040 int idx_peer = 1;
3041 struct peer *peer;
3042 int ret = BGP_GR_FAILURE;
3043
3044 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3045
3046 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3047 zlog_debug(
3048 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3049
3050 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3051 if (!peer)
3052 return CMD_WARNING_CONFIG_FAILED;
3053
3054 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3055
3056 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3057 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3058
3059 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3060 zlog_debug(
3061 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3062 vty_out(vty,
3063 "Graceful restart configuration changed, reset this peer to take effect\n");
3064
3065 return bgp_vty_return(vty, ret);
3066 }
3067
3068 DEFUN (no_bgp_neighbor_graceful_restart,
3069 no_bgp_neighbor_graceful_restart_set_cmd,
3070 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3071 NO_STR
3072 NEIGHBOR_STR
3073 NEIGHBOR_ADDR_STR2
3074 NO_GR_NEIGHBOR_CMD
3075 )
3076 {
3077 int idx_peer = 2;
3078 int ret = BGP_GR_FAILURE;
3079 struct peer *peer;
3080
3081 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3082
3083 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3084 if (!peer)
3085 return CMD_WARNING_CONFIG_FAILED;
3086
3087 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3088 zlog_debug(
3089 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3090
3091 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3092
3093 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3094 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3095
3096 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3097 zlog_debug(
3098 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3099 vty_out(vty,
3100 "Graceful restart configuration changed, reset this peer to take effect\n");
3101
3102 return bgp_vty_return(vty, ret);
3103 }
3104
3105 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3106 bgp_neighbor_graceful_restart_helper_set_cmd,
3107 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3108 NEIGHBOR_STR
3109 NEIGHBOR_ADDR_STR2
3110 GR_NEIGHBOR_HELPER_CMD
3111 )
3112 {
3113 int idx_peer = 1;
3114 struct peer *peer;
3115 int ret = BGP_GR_FAILURE;
3116
3117 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3118
3119 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3120 zlog_debug(
3121 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3122
3123 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3124
3125 if (!peer)
3126 return CMD_WARNING_CONFIG_FAILED;
3127
3128
3129 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3130
3131 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3132 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3133
3134 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3135 zlog_debug(
3136 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3137 vty_out(vty,
3138 "Graceful restart configuration changed, reset this peer to take effect\n");
3139
3140 return bgp_vty_return(vty, ret);
3141 }
3142
3143 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3144 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3145 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3146 NO_STR
3147 NEIGHBOR_STR
3148 NEIGHBOR_ADDR_STR2
3149 NO_GR_NEIGHBOR_HELPER_CMD
3150 )
3151 {
3152 int idx_peer = 2;
3153 int ret = BGP_GR_FAILURE;
3154 struct peer *peer;
3155
3156 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3157
3158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
3161
3162 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3163 zlog_debug(
3164 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3165
3166 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3167
3168 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3169 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3170
3171 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3172 zlog_debug(
3173 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3174 vty_out(vty,
3175 "Graceful restart configuration changed, reset this peer to take effect\n");
3176
3177 return bgp_vty_return(vty, ret);
3178 }
3179
3180 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3181 bgp_neighbor_graceful_restart_disable_set_cmd,
3182 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3183 NEIGHBOR_STR
3184 NEIGHBOR_ADDR_STR2
3185 GR_NEIGHBOR_DISABLE_CMD
3186 )
3187 {
3188 int idx_peer = 1;
3189 struct peer *peer;
3190 int ret = BGP_GR_FAILURE;
3191
3192 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3193
3194 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3195 zlog_debug(
3196 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3197
3198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3199 if (!peer)
3200 return CMD_WARNING_CONFIG_FAILED;
3201
3202 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3203
3204 if (peer->bgp->t_startup)
3205 bgp_peer_gr_flags_update(peer);
3206
3207 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3208 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3209
3210 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3211 zlog_debug(
3212 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3213 vty_out(vty,
3214 "Graceful restart configuration changed, reset this peer to take effect\n");
3215
3216 return bgp_vty_return(vty, ret);
3217 }
3218
3219 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3220 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3221 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3222 NO_STR
3223 NEIGHBOR_STR
3224 NEIGHBOR_ADDR_STR2
3225 NO_GR_NEIGHBOR_DISABLE_CMD
3226 )
3227 {
3228 int idx_peer = 2;
3229 int ret = BGP_GR_FAILURE;
3230 struct peer *peer;
3231
3232 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3233
3234 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3235 if (!peer)
3236 return CMD_WARNING_CONFIG_FAILED;
3237
3238 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3239 zlog_debug(
3240 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3241
3242 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3243
3244 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3245 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3246
3247 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3248 zlog_debug(
3249 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3250 vty_out(vty,
3251 "Graceful restart configuration changed, reset this peer to take effect\n");
3252
3253 return bgp_vty_return(vty, ret);
3254 }
3255
3256 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3257 bgp_graceful_restart_disable_eor_cmd,
3258 "bgp graceful-restart disable-eor",
3259 BGP_STR
3260 "Graceful restart configuration parameters\n"
3261 "Disable EOR Check\n")
3262 {
3263 VTY_DECLVAR_CONTEXT(bgp, bgp);
3264 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3265
3266 return CMD_SUCCESS;
3267 }
3268
3269 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3270 no_bgp_graceful_restart_disable_eor_cmd,
3271 "no bgp graceful-restart disable-eor",
3272 NO_STR
3273 BGP_STR
3274 "Graceful restart configuration parameters\n"
3275 "Disable EOR Check\n")
3276 {
3277 VTY_DECLVAR_CONTEXT(bgp, bgp);
3278 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3279
3280 return CMD_SUCCESS;
3281 }
3282
3283 DEFUN (bgp_graceful_restart_rib_stale_time,
3284 bgp_graceful_restart_rib_stale_time_cmd,
3285 "bgp graceful-restart rib-stale-time (1-3600)",
3286 BGP_STR
3287 "Graceful restart configuration parameters\n"
3288 "Specify the stale route removal timer in rib\n"
3289 "Delay value (seconds)\n")
3290 {
3291 VTY_DECLVAR_CONTEXT(bgp, bgp);
3292 int idx_number = 3;
3293 uint32_t stale_time;
3294
3295 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3296 bgp->rib_stale_time = stale_time;
3297 /* Send the stale timer update message to RIB */
3298 if (bgp_zebra_stale_timer_update(bgp))
3299 return CMD_WARNING;
3300
3301 return CMD_SUCCESS;
3302 }
3303
3304 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3305 no_bgp_graceful_restart_rib_stale_time_cmd,
3306 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3307 NO_STR
3308 BGP_STR
3309 "Graceful restart configuration parameters\n"
3310 "Specify the stale route removal timer in rib\n"
3311 "Delay value (seconds)\n")
3312 {
3313 VTY_DECLVAR_CONTEXT(bgp, bgp);
3314
3315 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3316 /* Send the stale timer update message to RIB */
3317 if (bgp_zebra_stale_timer_update(bgp))
3318 return CMD_WARNING;
3319
3320 return CMD_SUCCESS;
3321 }
3322
3323 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3324 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3325 BGP_STR
3326 "Enable Long-lived Graceful Restart\n"
3327 "Specifies maximum time to wait before purging long-lived stale routes\n"
3328 "Stale time value (seconds)\n")
3329 {
3330 VTY_DECLVAR_CONTEXT(bgp, bgp);
3331
3332 uint32_t llgr_stale_time;
3333
3334 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3335 bgp->llgr_stale_time = llgr_stale_time;
3336
3337 return CMD_SUCCESS;
3338 }
3339
3340 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3341 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3342 NO_STR BGP_STR
3343 "Enable Long-lived Graceful Restart\n"
3344 "Specifies maximum time to wait before purging long-lived stale routes\n"
3345 "Stale time value (seconds)\n")
3346 {
3347 VTY_DECLVAR_CONTEXT(bgp, bgp);
3348
3349 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3350
3351 return CMD_SUCCESS;
3352 }
3353
3354 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3355 struct bgp *bgp)
3356 {
3357 bgp_static_redo_import_check(bgp);
3358 bgp_redistribute_redo(bgp);
3359 bgp_clear_star_soft_out(vty, bgp->name);
3360 bgp_clear_star_soft_in(vty, bgp->name);
3361 }
3362
3363 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3364 {
3365 struct listnode *node, *nnode;
3366 struct bgp *bgp;
3367 bool vrf_cfg = false;
3368
3369 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3370 return CMD_SUCCESS;
3371
3372 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3373 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3374 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3375 vty_out(vty,
3376 "%% graceful-shutdown configuration found in vrf %s\n",
3377 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3378 VRF_DEFAULT_NAME : bgp->name);
3379 vrf_cfg = true;
3380 }
3381 }
3382
3383 if (vrf_cfg) {
3384 vty_out(vty,
3385 "%%Failed: global graceful-shutdown not permitted\n");
3386 return CMD_WARNING;
3387 }
3388
3389 /* Set flag globally */
3390 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3391
3392 /* Initiate processing for all BGP instances. */
3393 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3394 bgp_initiate_graceful_shut_unshut(vty, bgp);
3395
3396 return CMD_SUCCESS;
3397 }
3398
3399 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3400 {
3401 struct listnode *node, *nnode;
3402 struct bgp *bgp;
3403
3404 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3405 return CMD_SUCCESS;
3406
3407 /* Unset flag globally */
3408 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3409
3410 /* Initiate processing for all BGP instances. */
3411 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3412 bgp_initiate_graceful_shut_unshut(vty, bgp);
3413
3414 return CMD_SUCCESS;
3415 }
3416
3417 /* "bgp graceful-shutdown" configuration */
3418 DEFUN (bgp_graceful_shutdown,
3419 bgp_graceful_shutdown_cmd,
3420 "bgp graceful-shutdown",
3421 BGP_STR
3422 "Graceful shutdown parameters\n")
3423 {
3424 if (vty->node == CONFIG_NODE)
3425 return bgp_global_graceful_shutdown_config_vty(vty);
3426
3427 VTY_DECLVAR_CONTEXT(bgp, bgp);
3428
3429 /* if configured globally, per-instance config is not allowed */
3430 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3431 vty_out(vty,
3432 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3433 return CMD_WARNING_CONFIG_FAILED;
3434 }
3435
3436 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3437 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3438 bgp_initiate_graceful_shut_unshut(vty, bgp);
3439 }
3440
3441 return CMD_SUCCESS;
3442 }
3443
3444 DEFUN (no_bgp_graceful_shutdown,
3445 no_bgp_graceful_shutdown_cmd,
3446 "no bgp graceful-shutdown",
3447 NO_STR
3448 BGP_STR
3449 "Graceful shutdown parameters\n")
3450 {
3451 if (vty->node == CONFIG_NODE)
3452 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3453
3454 VTY_DECLVAR_CONTEXT(bgp, bgp);
3455
3456 /* If configured globally, cannot remove from one bgp instance */
3457 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3458 vty_out(vty,
3459 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3460 return CMD_WARNING_CONFIG_FAILED;
3461 }
3462
3463 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3464 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3465 bgp_initiate_graceful_shut_unshut(vty, bgp);
3466 }
3467
3468 return CMD_SUCCESS;
3469 }
3470
3471 /* "bgp fast-external-failover" configuration. */
3472 DEFUN (bgp_fast_external_failover,
3473 bgp_fast_external_failover_cmd,
3474 "bgp fast-external-failover",
3475 BGP_STR
3476 "Immediately reset session if a link to a directly connected external peer goes down\n")
3477 {
3478 VTY_DECLVAR_CONTEXT(bgp, bgp);
3479 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3480 return CMD_SUCCESS;
3481 }
3482
3483 DEFUN (no_bgp_fast_external_failover,
3484 no_bgp_fast_external_failover_cmd,
3485 "no bgp fast-external-failover",
3486 NO_STR
3487 BGP_STR
3488 "Immediately reset session if a link to a directly connected external peer goes down\n")
3489 {
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3492 return CMD_SUCCESS;
3493 }
3494
3495 /* "bgp bestpath compare-routerid" configuration. */
3496 DEFUN (bgp_bestpath_compare_router_id,
3497 bgp_bestpath_compare_router_id_cmd,
3498 "bgp bestpath compare-routerid",
3499 BGP_STR
3500 "Change the default bestpath selection\n"
3501 "Compare router-id for identical EBGP paths\n")
3502 {
3503 VTY_DECLVAR_CONTEXT(bgp, bgp);
3504 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3505 bgp_recalculate_all_bestpaths(bgp);
3506
3507 return CMD_SUCCESS;
3508 }
3509
3510 DEFUN (no_bgp_bestpath_compare_router_id,
3511 no_bgp_bestpath_compare_router_id_cmd,
3512 "no bgp bestpath compare-routerid",
3513 NO_STR
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 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3520 bgp_recalculate_all_bestpaths(bgp);
3521
3522 return CMD_SUCCESS;
3523 }
3524
3525 /* "bgp bestpath as-path ignore" configuration. */
3526 DEFUN (bgp_bestpath_aspath_ignore,
3527 bgp_bestpath_aspath_ignore_cmd,
3528 "bgp bestpath as-path ignore",
3529 BGP_STR
3530 "Change the default bestpath selection\n"
3531 "AS-path attribute\n"
3532 "Ignore as-path length in selecting a route\n")
3533 {
3534 VTY_DECLVAR_CONTEXT(bgp, bgp);
3535 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3536 bgp_recalculate_all_bestpaths(bgp);
3537
3538 return CMD_SUCCESS;
3539 }
3540
3541 DEFUN (no_bgp_bestpath_aspath_ignore,
3542 no_bgp_bestpath_aspath_ignore_cmd,
3543 "no bgp bestpath as-path ignore",
3544 NO_STR
3545 BGP_STR
3546 "Change the default bestpath selection\n"
3547 "AS-path attribute\n"
3548 "Ignore as-path length in selecting a route\n")
3549 {
3550 VTY_DECLVAR_CONTEXT(bgp, bgp);
3551 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3552 bgp_recalculate_all_bestpaths(bgp);
3553
3554 return CMD_SUCCESS;
3555 }
3556
3557 /* "bgp bestpath as-path confed" configuration. */
3558 DEFUN (bgp_bestpath_aspath_confed,
3559 bgp_bestpath_aspath_confed_cmd,
3560 "bgp bestpath as-path confed",
3561 BGP_STR
3562 "Change the default bestpath selection\n"
3563 "AS-path attribute\n"
3564 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3565 {
3566 VTY_DECLVAR_CONTEXT(bgp, bgp);
3567 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3568 bgp_recalculate_all_bestpaths(bgp);
3569
3570 return CMD_SUCCESS;
3571 }
3572
3573 DEFUN (no_bgp_bestpath_aspath_confed,
3574 no_bgp_bestpath_aspath_confed_cmd,
3575 "no bgp bestpath as-path confed",
3576 NO_STR
3577 BGP_STR
3578 "Change the default bestpath selection\n"
3579 "AS-path attribute\n"
3580 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3581 {
3582 VTY_DECLVAR_CONTEXT(bgp, bgp);
3583 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3584 bgp_recalculate_all_bestpaths(bgp);
3585
3586 return CMD_SUCCESS;
3587 }
3588
3589 /* "bgp bestpath as-path multipath-relax" configuration. */
3590 DEFUN (bgp_bestpath_aspath_multipath_relax,
3591 bgp_bestpath_aspath_multipath_relax_cmd,
3592 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3593 BGP_STR
3594 "Change the default bestpath selection\n"
3595 "AS-path attribute\n"
3596 "Allow load sharing across routes that have different AS paths (but same length)\n"
3597 "Generate an AS_SET\n"
3598 "Do not generate an AS_SET\n")
3599 {
3600 VTY_DECLVAR_CONTEXT(bgp, bgp);
3601 int idx = 0;
3602 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3603
3604 /* no-as-set is now the default behavior so we can silently
3605 * ignore it */
3606 if (argv_find(argv, argc, "as-set", &idx))
3607 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3608 else
3609 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3610
3611 bgp_recalculate_all_bestpaths(bgp);
3612
3613 return CMD_SUCCESS;
3614 }
3615
3616 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3617 no_bgp_bestpath_aspath_multipath_relax_cmd,
3618 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3619 NO_STR
3620 BGP_STR
3621 "Change the default bestpath selection\n"
3622 "AS-path attribute\n"
3623 "Allow load sharing across routes that have different AS paths (but same length)\n"
3624 "Generate an AS_SET\n"
3625 "Do not generate an AS_SET\n")
3626 {
3627 VTY_DECLVAR_CONTEXT(bgp, bgp);
3628 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3629 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3630 bgp_recalculate_all_bestpaths(bgp);
3631
3632 return CMD_SUCCESS;
3633 }
3634
3635 /* "bgp bestpath peer-type multipath-relax" configuration. */
3636 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3637 bgp_bestpath_peer_type_multipath_relax_cmd,
3638 "bgp bestpath peer-type multipath-relax",
3639 BGP_STR
3640 "Change the default bestpath selection\n"
3641 "Peer type\n"
3642 "Allow load sharing across routes learned from different peer types\n")
3643 {
3644 VTY_DECLVAR_CONTEXT(bgp, bgp);
3645 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3646 bgp_recalculate_all_bestpaths(bgp);
3647
3648 return CMD_SUCCESS;
3649 }
3650
3651 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3652 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3653 "no bgp bestpath peer-type multipath-relax",
3654 NO_STR 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 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3661 bgp_recalculate_all_bestpaths(bgp);
3662
3663 return CMD_SUCCESS;
3664 }
3665
3666 /* "bgp log-neighbor-changes" configuration. */
3667 DEFUN (bgp_log_neighbor_changes,
3668 bgp_log_neighbor_changes_cmd,
3669 "bgp log-neighbor-changes",
3670 BGP_STR
3671 "Log neighbor up/down and reset reason\n")
3672 {
3673 VTY_DECLVAR_CONTEXT(bgp, bgp);
3674 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3675 return CMD_SUCCESS;
3676 }
3677
3678 DEFUN (no_bgp_log_neighbor_changes,
3679 no_bgp_log_neighbor_changes_cmd,
3680 "no bgp log-neighbor-changes",
3681 NO_STR
3682 BGP_STR
3683 "Log neighbor up/down and reset reason\n")
3684 {
3685 VTY_DECLVAR_CONTEXT(bgp, bgp);
3686 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3687 return CMD_SUCCESS;
3688 }
3689
3690 /* "bgp bestpath med" configuration. */
3691 DEFUN (bgp_bestpath_med,
3692 bgp_bestpath_med_cmd,
3693 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3694 BGP_STR
3695 "Change the default bestpath selection\n"
3696 "MED attribute\n"
3697 "Compare MED among confederation paths\n"
3698 "Treat missing MED as the least preferred one\n"
3699 "Treat missing MED as the least preferred one\n"
3700 "Compare MED among confederation paths\n")
3701 {
3702 VTY_DECLVAR_CONTEXT(bgp, bgp);
3703
3704 int idx = 0;
3705 if (argv_find(argv, argc, "confed", &idx))
3706 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3707 idx = 0;
3708 if (argv_find(argv, argc, "missing-as-worst", &idx))
3709 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3710
3711 bgp_recalculate_all_bestpaths(bgp);
3712
3713 return CMD_SUCCESS;
3714 }
3715
3716 DEFUN (no_bgp_bestpath_med,
3717 no_bgp_bestpath_med_cmd,
3718 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3719 NO_STR
3720 BGP_STR
3721 "Change the default bestpath selection\n"
3722 "MED attribute\n"
3723 "Compare MED among confederation paths\n"
3724 "Treat missing MED as the least preferred one\n"
3725 "Treat missing MED as the least preferred one\n"
3726 "Compare MED among confederation paths\n")
3727 {
3728 VTY_DECLVAR_CONTEXT(bgp, bgp);
3729
3730 int idx = 0;
3731 if (argv_find(argv, argc, "confed", &idx))
3732 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3733 idx = 0;
3734 if (argv_find(argv, argc, "missing-as-worst", &idx))
3735 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3736
3737 bgp_recalculate_all_bestpaths(bgp);
3738
3739 return CMD_SUCCESS;
3740 }
3741
3742 /* "bgp bestpath bandwidth" configuration. */
3743 DEFPY (bgp_bestpath_bw,
3744 bgp_bestpath_bw_cmd,
3745 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3746 BGP_STR
3747 "Change the default bestpath selection\n"
3748 "Link Bandwidth attribute\n"
3749 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3750 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3751 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3752 {
3753 VTY_DECLVAR_CONTEXT(bgp, bgp);
3754 afi_t afi;
3755 safi_t safi;
3756
3757 if (!bw_cfg) {
3758 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3759 return CMD_ERR_INCOMPLETE;
3760 }
3761 if (!strcmp(bw_cfg, "ignore"))
3762 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3763 else if (!strcmp(bw_cfg, "skip-missing"))
3764 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3765 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3766 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3767 else
3768 return CMD_ERR_NO_MATCH;
3769
3770 /* This config is used in route install, so redo that. */
3771 FOREACH_AFI_SAFI (afi, safi) {
3772 if (!bgp_fibupd_safi(safi))
3773 continue;
3774 bgp_zebra_announce_table(bgp, afi, safi);
3775 }
3776
3777 return CMD_SUCCESS;
3778 }
3779
3780 DEFPY (no_bgp_bestpath_bw,
3781 no_bgp_bestpath_bw_cmd,
3782 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3783 NO_STR
3784 BGP_STR
3785 "Change the default bestpath selection\n"
3786 "Link Bandwidth attribute\n"
3787 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3788 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3789 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3790 {
3791 VTY_DECLVAR_CONTEXT(bgp, bgp);
3792 afi_t afi;
3793 safi_t safi;
3794
3795 bgp->lb_handling = BGP_LINK_BW_ECMP;
3796
3797 /* This config is used in route install, so redo that. */
3798 FOREACH_AFI_SAFI (afi, safi) {
3799 if (!bgp_fibupd_safi(safi))
3800 continue;
3801 bgp_zebra_announce_table(bgp, afi, safi);
3802 }
3803 return CMD_SUCCESS;
3804 }
3805
3806 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3807 "[no] bgp default <ipv4-unicast|"
3808 "ipv4-multicast|"
3809 "ipv4-vpn|"
3810 "ipv4-labeled-unicast|"
3811 "ipv4-flowspec|"
3812 "ipv6-unicast|"
3813 "ipv6-multicast|"
3814 "ipv6-vpn|"
3815 "ipv6-labeled-unicast|"
3816 "ipv6-flowspec|"
3817 "l2vpn-evpn>$afi_safi",
3818 NO_STR
3819 BGP_STR
3820 "Configure BGP defaults\n"
3821 "Activate ipv4-unicast for a peer by default\n"
3822 "Activate ipv4-multicast for a peer by default\n"
3823 "Activate ipv4-vpn for a peer by default\n"
3824 "Activate ipv4-labeled-unicast for a peer by default\n"
3825 "Activate ipv4-flowspec for a peer by default\n"
3826 "Activate ipv6-unicast for a peer by default\n"
3827 "Activate ipv6-multicast for a peer by default\n"
3828 "Activate ipv6-vpn for a peer by default\n"
3829 "Activate ipv6-labeled-unicast for a peer by default\n"
3830 "Activate ipv6-flowspec for a peer by default\n"
3831 "Activate l2vpn-evpn for a peer by default\n")
3832 {
3833 VTY_DECLVAR_CONTEXT(bgp, bgp);
3834 char afi_safi_str[strlen(afi_safi) + 1];
3835 char *afi_safi_str_tok;
3836
3837 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3838 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3839 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3840 afi_t afi = bgp_vty_afi_from_str(afi_str);
3841 safi_t safi;
3842
3843 if (strmatch(safi_str, "labeled"))
3844 safi = bgp_vty_safi_from_str("labeled-unicast");
3845 else
3846 safi = bgp_vty_safi_from_str(safi_str);
3847
3848 if (no)
3849 bgp->default_af[afi][safi] = false;
3850 else {
3851 if ((safi == SAFI_LABELED_UNICAST
3852 && bgp->default_af[afi][SAFI_UNICAST])
3853 || (safi == SAFI_UNICAST
3854 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3855 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3856 else
3857 bgp->default_af[afi][safi] = true;
3858 }
3859
3860 return CMD_SUCCESS;
3861 }
3862
3863 /* Display hostname in certain command outputs */
3864 DEFUN (bgp_default_show_hostname,
3865 bgp_default_show_hostname_cmd,
3866 "bgp default show-hostname",
3867 BGP_STR
3868 "Configure BGP defaults\n"
3869 "Show hostname in certain command outputs\n")
3870 {
3871 VTY_DECLVAR_CONTEXT(bgp, bgp);
3872 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3873 return CMD_SUCCESS;
3874 }
3875
3876 DEFUN (no_bgp_default_show_hostname,
3877 no_bgp_default_show_hostname_cmd,
3878 "no bgp default show-hostname",
3879 NO_STR
3880 BGP_STR
3881 "Configure BGP defaults\n"
3882 "Show hostname in certain command outputs\n")
3883 {
3884 VTY_DECLVAR_CONTEXT(bgp, bgp);
3885 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3886 return CMD_SUCCESS;
3887 }
3888
3889 /* Display hostname in certain command outputs */
3890 DEFUN (bgp_default_show_nexthop_hostname,
3891 bgp_default_show_nexthop_hostname_cmd,
3892 "bgp default show-nexthop-hostname",
3893 BGP_STR
3894 "Configure BGP defaults\n"
3895 "Show hostname for nexthop in certain command outputs\n")
3896 {
3897 VTY_DECLVAR_CONTEXT(bgp, bgp);
3898 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3899 return CMD_SUCCESS;
3900 }
3901
3902 DEFUN (no_bgp_default_show_nexthop_hostname,
3903 no_bgp_default_show_nexthop_hostname_cmd,
3904 "no bgp default show-nexthop-hostname",
3905 NO_STR
3906 BGP_STR
3907 "Configure BGP defaults\n"
3908 "Show hostname for nexthop in certain command outputs\n")
3909 {
3910 VTY_DECLVAR_CONTEXT(bgp, bgp);
3911 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3912 return CMD_SUCCESS;
3913 }
3914
3915 /* "bgp network import-check" configuration. */
3916 DEFUN (bgp_network_import_check,
3917 bgp_network_import_check_cmd,
3918 "bgp network import-check",
3919 BGP_STR
3920 "BGP network command\n"
3921 "Check BGP network route exists in IGP\n")
3922 {
3923 VTY_DECLVAR_CONTEXT(bgp, bgp);
3924 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3925 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3926 bgp_static_redo_import_check(bgp);
3927 }
3928
3929 return CMD_SUCCESS;
3930 }
3931
3932 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3933 "bgp network import-check exact",
3934 BGP_STR
3935 "BGP network command\n"
3936 "Check BGP network route exists in IGP\n"
3937 "Match route precisely\n")
3938
3939 DEFUN (no_bgp_network_import_check,
3940 no_bgp_network_import_check_cmd,
3941 "no bgp network import-check",
3942 NO_STR
3943 BGP_STR
3944 "BGP network command\n"
3945 "Check BGP network route exists in IGP\n")
3946 {
3947 VTY_DECLVAR_CONTEXT(bgp, bgp);
3948 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3949 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3950 bgp_static_redo_import_check(bgp);
3951 }
3952
3953 return CMD_SUCCESS;
3954 }
3955
3956 DEFUN (bgp_default_local_preference,
3957 bgp_default_local_preference_cmd,
3958 "bgp default local-preference (0-4294967295)",
3959 BGP_STR
3960 "Configure BGP defaults\n"
3961 "local preference (higher=more preferred)\n"
3962 "Configure default local preference value\n")
3963 {
3964 VTY_DECLVAR_CONTEXT(bgp, bgp);
3965 int idx_number = 3;
3966 uint32_t local_pref;
3967
3968 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3969
3970 bgp_default_local_preference_set(bgp, local_pref);
3971 bgp_clear_star_soft_in(vty, bgp->name);
3972
3973 return CMD_SUCCESS;
3974 }
3975
3976 DEFUN (no_bgp_default_local_preference,
3977 no_bgp_default_local_preference_cmd,
3978 "no bgp default local-preference [(0-4294967295)]",
3979 NO_STR
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 bgp_default_local_preference_unset(bgp);
3987 bgp_clear_star_soft_in(vty, bgp->name);
3988
3989 return CMD_SUCCESS;
3990 }
3991
3992
3993 DEFUN (bgp_default_subgroup_pkt_queue_max,
3994 bgp_default_subgroup_pkt_queue_max_cmd,
3995 "bgp default subgroup-pkt-queue-max (20-100)",
3996 BGP_STR
3997 "Configure BGP defaults\n"
3998 "subgroup-pkt-queue-max\n"
3999 "Configure subgroup packet queue max\n")
4000 {
4001 VTY_DECLVAR_CONTEXT(bgp, bgp);
4002 int idx_number = 3;
4003 uint32_t max_size;
4004
4005 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4006
4007 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4008
4009 return CMD_SUCCESS;
4010 }
4011
4012 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4013 no_bgp_default_subgroup_pkt_queue_max_cmd,
4014 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4015 NO_STR
4016 BGP_STR
4017 "Configure BGP defaults\n"
4018 "subgroup-pkt-queue-max\n"
4019 "Configure subgroup packet queue max\n")
4020 {
4021 VTY_DECLVAR_CONTEXT(bgp, bgp);
4022 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4023 return CMD_SUCCESS;
4024 }
4025
4026
4027 DEFUN (bgp_rr_allow_outbound_policy,
4028 bgp_rr_allow_outbound_policy_cmd,
4029 "bgp route-reflector allow-outbound-policy",
4030 BGP_STR
4031 "Allow modifications made by out route-map\n"
4032 "on ibgp neighbors\n")
4033 {
4034 VTY_DECLVAR_CONTEXT(bgp, bgp);
4035
4036 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4037 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4038 update_group_announce_rrclients(bgp);
4039 bgp_clear_star_soft_out(vty, bgp->name);
4040 }
4041
4042 return CMD_SUCCESS;
4043 }
4044
4045 DEFUN (no_bgp_rr_allow_outbound_policy,
4046 no_bgp_rr_allow_outbound_policy_cmd,
4047 "no bgp route-reflector allow-outbound-policy",
4048 NO_STR
4049 BGP_STR
4050 "Allow modifications made by out route-map\n"
4051 "on ibgp neighbors\n")
4052 {
4053 VTY_DECLVAR_CONTEXT(bgp, bgp);
4054
4055 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4056 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4057 update_group_announce_rrclients(bgp);
4058 bgp_clear_star_soft_out(vty, bgp->name);
4059 }
4060
4061 return CMD_SUCCESS;
4062 }
4063
4064 DEFUN (bgp_listen_limit,
4065 bgp_listen_limit_cmd,
4066 "bgp listen limit (1-65535)",
4067 BGP_STR
4068 "BGP Dynamic Neighbors listen commands\n"
4069 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4070 "Configure Dynamic Neighbors listen limit value\n")
4071 {
4072 VTY_DECLVAR_CONTEXT(bgp, bgp);
4073 int idx_number = 3;
4074 int listen_limit;
4075
4076 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4077
4078 bgp_listen_limit_set(bgp, listen_limit);
4079
4080 return CMD_SUCCESS;
4081 }
4082
4083 DEFUN (no_bgp_listen_limit,
4084 no_bgp_listen_limit_cmd,
4085 "no bgp listen limit [(1-65535)]",
4086 NO_STR
4087 BGP_STR
4088 "BGP Dynamic Neighbors listen commands\n"
4089 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4090 "Configure Dynamic Neighbors listen limit value\n")
4091 {
4092 VTY_DECLVAR_CONTEXT(bgp, bgp);
4093 bgp_listen_limit_unset(bgp);
4094 return CMD_SUCCESS;
4095 }
4096
4097
4098 /*
4099 * Check if this listen range is already configured. Check for exact
4100 * match or overlap based on input.
4101 */
4102 static struct peer_group *listen_range_exists(struct bgp *bgp,
4103 struct prefix *range, int exact)
4104 {
4105 struct listnode *node, *nnode;
4106 struct listnode *node1, *nnode1;
4107 struct peer_group *group;
4108 struct prefix *lr;
4109 afi_t afi;
4110 int match;
4111
4112 afi = family2afi(range->family);
4113 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4114 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4115 lr)) {
4116 if (exact)
4117 match = prefix_same(range, lr);
4118 else
4119 match = (prefix_match(range, lr)
4120 || prefix_match(lr, range));
4121 if (match)
4122 return group;
4123 }
4124 }
4125
4126 return NULL;
4127 }
4128
4129 DEFUN (bgp_listen_range,
4130 bgp_listen_range_cmd,
4131 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4132 BGP_STR
4133 "Configure BGP dynamic neighbors listen range\n"
4134 "Configure BGP dynamic neighbors listen range\n"
4135 NEIGHBOR_ADDR_STR
4136 "Member of the peer-group\n"
4137 "Peer-group name\n")
4138 {
4139 VTY_DECLVAR_CONTEXT(bgp, bgp);
4140 struct prefix range;
4141 struct peer_group *group, *existing_group;
4142 afi_t afi;
4143 int ret;
4144 int idx = 0;
4145
4146 argv_find(argv, argc, "A.B.C.D/M", &idx);
4147 argv_find(argv, argc, "X:X::X:X/M", &idx);
4148 char *prefix = argv[idx]->arg;
4149 argv_find(argv, argc, "PGNAME", &idx);
4150 char *peergroup = argv[idx]->arg;
4151
4152 /* Convert IP prefix string to struct prefix. */
4153 ret = str2prefix(prefix, &range);
4154 if (!ret) {
4155 vty_out(vty, "%% Malformed listen range\n");
4156 return CMD_WARNING_CONFIG_FAILED;
4157 }
4158
4159 afi = family2afi(range.family);
4160
4161 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4162 vty_out(vty,
4163 "%% Malformed listen range (link-local address)\n");
4164 return CMD_WARNING_CONFIG_FAILED;
4165 }
4166
4167 apply_mask(&range);
4168
4169 /* Check if same listen range is already configured. */
4170 existing_group = listen_range_exists(bgp, &range, 1);
4171 if (existing_group) {
4172 if (strcmp(existing_group->name, peergroup) == 0)
4173 return CMD_SUCCESS;
4174 else {
4175 vty_out(vty,
4176 "%% Same listen range is attached to peer-group %s\n",
4177 existing_group->name);
4178 return CMD_WARNING_CONFIG_FAILED;
4179 }
4180 }
4181
4182 /* Check if an overlapping listen range exists. */
4183 if (listen_range_exists(bgp, &range, 0)) {
4184 vty_out(vty,
4185 "%% Listen range overlaps with existing listen range\n");
4186 return CMD_WARNING_CONFIG_FAILED;
4187 }
4188
4189 group = peer_group_lookup(bgp, peergroup);
4190 if (!group) {
4191 vty_out(vty, "%% Configure the peer-group first\n");
4192 return CMD_WARNING_CONFIG_FAILED;
4193 }
4194
4195 ret = peer_group_listen_range_add(group, &range);
4196 return bgp_vty_return(vty, ret);
4197 }
4198
4199 DEFUN (no_bgp_listen_range,
4200 no_bgp_listen_range_cmd,
4201 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4202 NO_STR
4203 BGP_STR
4204 "Unconfigure BGP dynamic neighbors listen range\n"
4205 "Unconfigure BGP dynamic neighbors listen range\n"
4206 NEIGHBOR_ADDR_STR
4207 "Member of the peer-group\n"
4208 "Peer-group name\n")
4209 {
4210 VTY_DECLVAR_CONTEXT(bgp, bgp);
4211 struct prefix range;
4212 struct peer_group *group;
4213 afi_t afi;
4214 int ret;
4215 int idx = 0;
4216
4217 argv_find(argv, argc, "A.B.C.D/M", &idx);
4218 argv_find(argv, argc, "X:X::X:X/M", &idx);
4219 char *prefix = argv[idx]->arg;
4220 argv_find(argv, argc, "PGNAME", &idx);
4221 char *peergroup = argv[idx]->arg;
4222
4223 /* Convert IP prefix string to struct prefix. */
4224 ret = str2prefix(prefix, &range);
4225 if (!ret) {
4226 vty_out(vty, "%% Malformed listen range\n");
4227 return CMD_WARNING_CONFIG_FAILED;
4228 }
4229
4230 afi = family2afi(range.family);
4231
4232 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4233 vty_out(vty,
4234 "%% Malformed listen range (link-local address)\n");
4235 return CMD_WARNING_CONFIG_FAILED;
4236 }
4237
4238 apply_mask(&range);
4239
4240 group = peer_group_lookup(bgp, peergroup);
4241 if (!group) {
4242 vty_out(vty, "%% Peer-group does not exist\n");
4243 return CMD_WARNING_CONFIG_FAILED;
4244 }
4245
4246 ret = peer_group_listen_range_del(group, &range);
4247 return bgp_vty_return(vty, ret);
4248 }
4249
4250 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4251 {
4252 struct peer_group *group;
4253 struct listnode *node, *nnode, *rnode, *nrnode;
4254 struct prefix *range;
4255 afi_t afi;
4256
4257 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4258 vty_out(vty, " bgp listen limit %d\n",
4259 bgp->dynamic_neighbors_limit);
4260
4261 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4262 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4263 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4264 nrnode, range)) {
4265 vty_out(vty,
4266 " bgp listen range %pFX peer-group %s\n",
4267 range, group->name);
4268 }
4269 }
4270 }
4271 }
4272
4273
4274 DEFUN (bgp_disable_connected_route_check,
4275 bgp_disable_connected_route_check_cmd,
4276 "bgp disable-ebgp-connected-route-check",
4277 BGP_STR
4278 "Disable checking if nexthop is connected on ebgp sessions\n")
4279 {
4280 VTY_DECLVAR_CONTEXT(bgp, bgp);
4281 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4282 bgp_clear_star_soft_in(vty, bgp->name);
4283
4284 return CMD_SUCCESS;
4285 }
4286
4287 DEFUN (no_bgp_disable_connected_route_check,
4288 no_bgp_disable_connected_route_check_cmd,
4289 "no bgp disable-ebgp-connected-route-check",
4290 NO_STR
4291 BGP_STR
4292 "Disable checking if nexthop is connected on ebgp sessions\n")
4293 {
4294 VTY_DECLVAR_CONTEXT(bgp, bgp);
4295 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4296 bgp_clear_star_soft_in(vty, bgp->name);
4297
4298 return CMD_SUCCESS;
4299 }
4300
4301
4302 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4303 const char *as_str)
4304 {
4305 VTY_DECLVAR_CONTEXT(bgp, bgp);
4306 int ret;
4307 as_t as;
4308 int as_type = AS_SPECIFIED;
4309 union sockunion su;
4310
4311 if (as_str[0] == 'i') {
4312 as = 0;
4313 as_type = AS_INTERNAL;
4314 } else if (as_str[0] == 'e') {
4315 as = 0;
4316 as_type = AS_EXTERNAL;
4317 } else {
4318 /* Get AS number. */
4319 as = strtoul(as_str, NULL, 10);
4320 }
4321
4322 /* If peer is peer group or interface peer, call proper function. */
4323 ret = str2sockunion(peer_str, &su);
4324 if (ret < 0) {
4325 struct peer *peer;
4326
4327 /* Check if existing interface peer */
4328 peer = peer_lookup_by_conf_if(bgp, peer_str);
4329
4330 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4331
4332 /* if not interface peer, check peer-group settings */
4333 if (ret < 0 && !peer) {
4334 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4335 if (ret < 0) {
4336 vty_out(vty,
4337 "%% Create the peer-group or interface first\n");
4338 return CMD_WARNING_CONFIG_FAILED;
4339 }
4340 return CMD_SUCCESS;
4341 }
4342 } else {
4343 if (peer_address_self_check(bgp, &su)) {
4344 vty_out(vty,
4345 "%% Can not configure the local system as neighbor\n");
4346 return CMD_WARNING_CONFIG_FAILED;
4347 }
4348 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4349 }
4350
4351 return bgp_vty_return(vty, ret);
4352 }
4353
4354 DEFUN (bgp_default_shutdown,
4355 bgp_default_shutdown_cmd,
4356 "[no] bgp default shutdown",
4357 NO_STR
4358 BGP_STR
4359 "Configure BGP defaults\n"
4360 "Apply administrative shutdown to newly configured peers\n")
4361 {
4362 VTY_DECLVAR_CONTEXT(bgp, bgp);
4363 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4364 return CMD_SUCCESS;
4365 }
4366
4367 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4368 BGP_STR
4369 "Administrative shutdown of the BGP instance\n"
4370 "Add a shutdown message (RFC 8203)\n"
4371 "Shutdown message\n")
4372 {
4373 char *msgstr = NULL;
4374
4375 VTY_DECLVAR_CONTEXT(bgp, bgp);
4376
4377 if (argc > 3)
4378 msgstr = argv_concat(argv, argc, 3);
4379
4380 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4381 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4382 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4383 return CMD_WARNING_CONFIG_FAILED;
4384 }
4385
4386 bgp_shutdown_enable(bgp, msgstr);
4387 XFREE(MTYPE_TMP, msgstr);
4388
4389 return CMD_SUCCESS;
4390 }
4391
4392 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4393 BGP_STR "Administrative shutdown of the BGP instance\n")
4394 {
4395 VTY_DECLVAR_CONTEXT(bgp, bgp);
4396
4397 bgp_shutdown_enable(bgp, NULL);
4398
4399 return CMD_SUCCESS;
4400 }
4401
4402 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4403 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4404 {
4405 VTY_DECLVAR_CONTEXT(bgp, bgp);
4406
4407 bgp_shutdown_disable(bgp);
4408
4409 return CMD_SUCCESS;
4410 }
4411
4412 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4413 "no bgp shutdown message MSG...", NO_STR BGP_STR
4414 "Administrative shutdown of the BGP instance\n"
4415 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4416
4417 DEFUN (neighbor_remote_as,
4418 neighbor_remote_as_cmd,
4419 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4420 NEIGHBOR_STR
4421 NEIGHBOR_ADDR_STR2
4422 "Specify a BGP neighbor\n"
4423 AS_STR
4424 "Internal BGP peer\n"
4425 "External BGP peer\n")
4426 {
4427 int idx_peer = 1;
4428 int idx_remote_as = 3;
4429 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4430 argv[idx_remote_as]->arg);
4431 }
4432
4433 DEFPY (bgp_allow_martian,
4434 bgp_allow_martian_cmd,
4435 "[no]$no bgp allow-martian-nexthop",
4436 NO_STR
4437 BGP_STR
4438 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4439 {
4440 VTY_DECLVAR_CONTEXT(bgp, bgp);
4441
4442 if (no)
4443 bgp->allow_martian = false;
4444 else
4445 bgp->allow_martian = true;
4446
4447 return CMD_SUCCESS;
4448 }
4449
4450 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4451 * sessions do not wait for hold timer expiry to bring down the sessions
4452 * when nexthop becomes unreachable
4453 */
4454 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4455 BGP_STR "Fast convergence for bgp sessions\n")
4456 {
4457 VTY_DECLVAR_CONTEXT(bgp, bgp);
4458 bgp->fast_convergence = true;
4459
4460 return CMD_SUCCESS;
4461 }
4462
4463 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4464 "no bgp fast-convergence",
4465 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4466 {
4467 VTY_DECLVAR_CONTEXT(bgp, bgp);
4468 bgp->fast_convergence = false;
4469
4470 return CMD_SUCCESS;
4471 }
4472
4473 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4474 int v6only,
4475 const char *peer_group_name,
4476 const char *as_str)
4477 {
4478 VTY_DECLVAR_CONTEXT(bgp, bgp);
4479 as_t as = 0;
4480 int as_type = AS_UNSPECIFIED;
4481 struct peer *peer;
4482 struct peer_group *group;
4483 int ret = 0;
4484
4485 group = peer_group_lookup(bgp, conf_if);
4486
4487 if (group) {
4488 vty_out(vty, "%% Name conflict with peer-group \n");
4489 return CMD_WARNING_CONFIG_FAILED;
4490 }
4491
4492 if (as_str) {
4493 if (as_str[0] == 'i') {
4494 as_type = AS_INTERNAL;
4495 } else if (as_str[0] == 'e') {
4496 as_type = AS_EXTERNAL;
4497 } else {
4498 /* Get AS number. */
4499 as = strtoul(as_str, NULL, 10);
4500 as_type = AS_SPECIFIED;
4501 }
4502 }
4503
4504 peer = peer_lookup_by_conf_if(bgp, conf_if);
4505 if (peer) {
4506 if (as_str)
4507 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4508 } else {
4509 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4510 NULL);
4511
4512 if (!peer) {
4513 vty_out(vty, "%% BGP failed to create peer\n");
4514 return CMD_WARNING_CONFIG_FAILED;
4515 }
4516
4517 if (v6only)
4518 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4519
4520 /* Request zebra to initiate IPv6 RAs on this interface. We do
4521 * this
4522 * any unnumbered peer in order to not worry about run-time
4523 * transitions
4524 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4525 * address
4526 * gets deleted later etc.)
4527 */
4528 if (peer->ifp)
4529 bgp_zebra_initiate_radv(bgp, peer);
4530 }
4531
4532 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4533 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4534 if (v6only)
4535 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4536 else
4537 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4538
4539 /* v6only flag changed. Reset bgp seesion */
4540 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4541 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4542 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4543 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4544 } else
4545 bgp_session_reset(peer);
4546 }
4547
4548 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4549 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4550 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4551 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4552 }
4553
4554 if (peer_group_name) {
4555 group = peer_group_lookup(bgp, peer_group_name);
4556 if (!group) {
4557 vty_out(vty, "%% Configure the peer-group first\n");
4558 return CMD_WARNING_CONFIG_FAILED;
4559 }
4560
4561 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4562 }
4563
4564 return bgp_vty_return(vty, ret);
4565 }
4566
4567 DEFUN (neighbor_interface_config,
4568 neighbor_interface_config_cmd,
4569 "neighbor WORD interface [peer-group PGNAME]",
4570 NEIGHBOR_STR
4571 "Interface name or neighbor tag\n"
4572 "Enable BGP on interface\n"
4573 "Member of the peer-group\n"
4574 "Peer-group name\n")
4575 {
4576 int idx_word = 1;
4577 int idx_peer_group_word = 4;
4578
4579 if (argc > idx_peer_group_word)
4580 return peer_conf_interface_get(
4581 vty, argv[idx_word]->arg, 0,
4582 argv[idx_peer_group_word]->arg, NULL);
4583 else
4584 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4585 NULL, NULL);
4586 }
4587
4588 DEFUN (neighbor_interface_config_v6only,
4589 neighbor_interface_config_v6only_cmd,
4590 "neighbor WORD interface v6only [peer-group PGNAME]",
4591 NEIGHBOR_STR
4592 "Interface name or neighbor tag\n"
4593 "Enable BGP on interface\n"
4594 "Enable BGP with v6 link-local only\n"
4595 "Member of the peer-group\n"
4596 "Peer-group name\n")
4597 {
4598 int idx_word = 1;
4599 int idx_peer_group_word = 5;
4600
4601 if (argc > idx_peer_group_word)
4602 return peer_conf_interface_get(
4603 vty, argv[idx_word]->arg, 1,
4604 argv[idx_peer_group_word]->arg, NULL);
4605
4606 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4607 }
4608
4609
4610 DEFUN (neighbor_interface_config_remote_as,
4611 neighbor_interface_config_remote_as_cmd,
4612 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4613 NEIGHBOR_STR
4614 "Interface name or neighbor tag\n"
4615 "Enable BGP on interface\n"
4616 "Specify a BGP neighbor\n"
4617 AS_STR
4618 "Internal BGP peer\n"
4619 "External BGP peer\n")
4620 {
4621 int idx_word = 1;
4622 int idx_remote_as = 4;
4623 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4624 argv[idx_remote_as]->arg);
4625 }
4626
4627 DEFUN (neighbor_interface_v6only_config_remote_as,
4628 neighbor_interface_v6only_config_remote_as_cmd,
4629 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4630 NEIGHBOR_STR
4631 "Interface name or neighbor tag\n"
4632 "Enable BGP with v6 link-local only\n"
4633 "Enable BGP on interface\n"
4634 "Specify a BGP neighbor\n"
4635 AS_STR
4636 "Internal BGP peer\n"
4637 "External BGP peer\n")
4638 {
4639 int idx_word = 1;
4640 int idx_remote_as = 5;
4641 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4642 argv[idx_remote_as]->arg);
4643 }
4644
4645 DEFUN (neighbor_peer_group,
4646 neighbor_peer_group_cmd,
4647 "neighbor WORD peer-group",
4648 NEIGHBOR_STR
4649 "Interface name or neighbor tag\n"
4650 "Configure peer-group\n")
4651 {
4652 VTY_DECLVAR_CONTEXT(bgp, bgp);
4653 int idx_word = 1;
4654 struct peer *peer;
4655 struct peer_group *group;
4656
4657 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4658 if (peer) {
4659 vty_out(vty, "%% Name conflict with interface: \n");
4660 return CMD_WARNING_CONFIG_FAILED;
4661 }
4662
4663 group = peer_group_get(bgp, argv[idx_word]->arg);
4664 if (!group) {
4665 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4666 return CMD_WARNING_CONFIG_FAILED;
4667 }
4668
4669 return CMD_SUCCESS;
4670 }
4671
4672 DEFUN (no_neighbor,
4673 no_neighbor_cmd,
4674 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4675 NO_STR
4676 NEIGHBOR_STR
4677 NEIGHBOR_ADDR_STR2
4678 "Specify a BGP neighbor\n"
4679 AS_STR
4680 "Internal BGP peer\n"
4681 "External BGP peer\n")
4682 {
4683 VTY_DECLVAR_CONTEXT(bgp, bgp);
4684 int idx_peer = 2;
4685 int ret;
4686 union sockunion su;
4687 struct peer_group *group;
4688 struct peer *peer;
4689 struct peer *other;
4690
4691 ret = str2sockunion(argv[idx_peer]->arg, &su);
4692 if (ret < 0) {
4693 /* look up for neighbor by interface name config. */
4694 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4695 if (peer) {
4696 /* Request zebra to terminate IPv6 RAs on this
4697 * interface. */
4698 if (peer->ifp)
4699 bgp_zebra_terminate_radv(peer->bgp, peer);
4700 peer_notify_unconfig(peer);
4701 peer_delete(peer);
4702 return CMD_SUCCESS;
4703 }
4704
4705 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4706 if (group) {
4707 peer_group_notify_unconfig(group);
4708 peer_group_delete(group);
4709 } else {
4710 vty_out(vty, "%% Create the peer-group first\n");
4711 return CMD_WARNING_CONFIG_FAILED;
4712 }
4713 } else {
4714 peer = peer_lookup(bgp, &su);
4715 if (peer) {
4716 if (peer_dynamic_neighbor(peer)) {
4717 vty_out(vty,
4718 "%% Operation not allowed on a dynamic neighbor\n");
4719 return CMD_WARNING_CONFIG_FAILED;
4720 }
4721
4722 other = peer->doppelganger;
4723
4724 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4725 bgp_zebra_terminate_radv(peer->bgp, peer);
4726
4727 peer_notify_unconfig(peer);
4728 peer_delete(peer);
4729 if (other && other->status != Deleted) {
4730 peer_notify_unconfig(other);
4731 peer_delete(other);
4732 }
4733 }
4734 }
4735
4736 return CMD_SUCCESS;
4737 }
4738
4739 DEFUN (no_neighbor_interface_config,
4740 no_neighbor_interface_config_cmd,
4741 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4742 NO_STR
4743 NEIGHBOR_STR
4744 "Interface name\n"
4745 "Configure BGP on interface\n"
4746 "Enable BGP with v6 link-local only\n"
4747 "Member of the peer-group\n"
4748 "Peer-group name\n"
4749 "Specify a BGP neighbor\n"
4750 AS_STR
4751 "Internal BGP peer\n"
4752 "External BGP peer\n")
4753 {
4754 VTY_DECLVAR_CONTEXT(bgp, bgp);
4755 int idx_word = 2;
4756 struct peer *peer;
4757
4758 /* look up for neighbor by interface name config. */
4759 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4760 if (peer) {
4761 /* Request zebra to terminate IPv6 RAs on this interface. */
4762 if (peer->ifp)
4763 bgp_zebra_terminate_radv(peer->bgp, peer);
4764 peer_notify_unconfig(peer);
4765 peer_delete(peer);
4766 } else {
4767 vty_out(vty, "%% Create the bgp interface first\n");
4768 return CMD_WARNING_CONFIG_FAILED;
4769 }
4770 return CMD_SUCCESS;
4771 }
4772
4773 DEFUN (no_neighbor_peer_group,
4774 no_neighbor_peer_group_cmd,
4775 "no neighbor WORD peer-group",
4776 NO_STR
4777 NEIGHBOR_STR
4778 "Neighbor tag\n"
4779 "Configure peer-group\n")
4780 {
4781 VTY_DECLVAR_CONTEXT(bgp, bgp);
4782 int idx_word = 2;
4783 struct peer_group *group;
4784
4785 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4786 if (group) {
4787 peer_group_notify_unconfig(group);
4788 peer_group_delete(group);
4789 } else {
4790 vty_out(vty, "%% Create the peer-group first\n");
4791 return CMD_WARNING_CONFIG_FAILED;
4792 }
4793 return CMD_SUCCESS;
4794 }
4795
4796 DEFUN (no_neighbor_interface_peer_group_remote_as,
4797 no_neighbor_interface_peer_group_remote_as_cmd,
4798 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4799 NO_STR
4800 NEIGHBOR_STR
4801 "Interface name or neighbor tag\n"
4802 "Specify a BGP neighbor\n"
4803 AS_STR
4804 "Internal BGP peer\n"
4805 "External BGP peer\n")
4806 {
4807 VTY_DECLVAR_CONTEXT(bgp, bgp);
4808 int idx_word = 2;
4809 struct peer_group *group;
4810 struct peer *peer;
4811
4812 /* look up for neighbor by interface name config. */
4813 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4814 if (peer) {
4815 peer_as_change(peer, 0, AS_UNSPECIFIED);
4816 return CMD_SUCCESS;
4817 }
4818
4819 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4820 if (group)
4821 peer_group_remote_as_delete(group);
4822 else {
4823 vty_out(vty, "%% Create the peer-group or interface first\n");
4824 return CMD_WARNING_CONFIG_FAILED;
4825 }
4826 return CMD_SUCCESS;
4827 }
4828
4829 DEFUN (neighbor_local_as,
4830 neighbor_local_as_cmd,
4831 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Specify a local-as number\n"
4835 "AS number used as local AS\n")
4836 {
4837 int idx_peer = 1;
4838 int idx_number = 3;
4839 struct peer *peer;
4840 int ret;
4841 as_t as;
4842
4843 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4844 if (!peer)
4845 return CMD_WARNING_CONFIG_FAILED;
4846
4847 as = strtoul(argv[idx_number]->arg, NULL, 10);
4848 ret = peer_local_as_set(peer, as, 0, 0);
4849 return bgp_vty_return(vty, ret);
4850 }
4851
4852 DEFUN (neighbor_local_as_no_prepend,
4853 neighbor_local_as_no_prepend_cmd,
4854 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4855 NEIGHBOR_STR
4856 NEIGHBOR_ADDR_STR2
4857 "Specify a local-as number\n"
4858 "AS number used as local AS\n"
4859 "Do not prepend local-as to updates from ebgp peers\n")
4860 {
4861 int idx_peer = 1;
4862 int idx_number = 3;
4863 struct peer *peer;
4864 int ret;
4865 as_t as;
4866
4867 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4868 if (!peer)
4869 return CMD_WARNING_CONFIG_FAILED;
4870
4871 as = strtoul(argv[idx_number]->arg, NULL, 10);
4872 ret = peer_local_as_set(peer, as, 1, 0);
4873 return bgp_vty_return(vty, ret);
4874 }
4875
4876 DEFUN (neighbor_local_as_no_prepend_replace_as,
4877 neighbor_local_as_no_prepend_replace_as_cmd,
4878 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4879 NEIGHBOR_STR
4880 NEIGHBOR_ADDR_STR2
4881 "Specify a local-as number\n"
4882 "AS number used as local AS\n"
4883 "Do not prepend local-as to updates from ebgp peers\n"
4884 "Do not prepend local-as to updates from ibgp peers\n")
4885 {
4886 int idx_peer = 1;
4887 int idx_number = 3;
4888 struct peer *peer;
4889 int ret;
4890 as_t as;
4891
4892 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4893 if (!peer)
4894 return CMD_WARNING_CONFIG_FAILED;
4895
4896 as = strtoul(argv[idx_number]->arg, NULL, 10);
4897 ret = peer_local_as_set(peer, as, 1, 1);
4898 return bgp_vty_return(vty, ret);
4899 }
4900
4901 DEFUN (no_neighbor_local_as,
4902 no_neighbor_local_as_cmd,
4903 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4904 NO_STR
4905 NEIGHBOR_STR
4906 NEIGHBOR_ADDR_STR2
4907 "Specify a local-as number\n"
4908 "AS number used as local AS\n"
4909 "Do not prepend local-as to updates from ebgp peers\n"
4910 "Do not prepend local-as to updates from ibgp peers\n")
4911 {
4912 int idx_peer = 2;
4913 struct peer *peer;
4914 int ret;
4915
4916 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4917 if (!peer)
4918 return CMD_WARNING_CONFIG_FAILED;
4919
4920 ret = peer_local_as_unset(peer);
4921 return bgp_vty_return(vty, ret);
4922 }
4923
4924
4925 DEFUN (neighbor_solo,
4926 neighbor_solo_cmd,
4927 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4928 NEIGHBOR_STR
4929 NEIGHBOR_ADDR_STR2
4930 "Solo peer - part of its own update group\n")
4931 {
4932 int idx_peer = 1;
4933 struct peer *peer;
4934 int ret;
4935
4936 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4937 if (!peer)
4938 return CMD_WARNING_CONFIG_FAILED;
4939
4940 ret = update_group_adjust_soloness(peer, 1);
4941 return bgp_vty_return(vty, ret);
4942 }
4943
4944 DEFUN (no_neighbor_solo,
4945 no_neighbor_solo_cmd,
4946 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4947 NO_STR
4948 NEIGHBOR_STR
4949 NEIGHBOR_ADDR_STR2
4950 "Solo peer - part of its own update group\n")
4951 {
4952 int idx_peer = 2;
4953 struct peer *peer;
4954 int ret;
4955
4956 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4957 if (!peer)
4958 return CMD_WARNING_CONFIG_FAILED;
4959
4960 ret = update_group_adjust_soloness(peer, 0);
4961 return bgp_vty_return(vty, ret);
4962 }
4963
4964 DEFUN (neighbor_password,
4965 neighbor_password_cmd,
4966 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4967 NEIGHBOR_STR
4968 NEIGHBOR_ADDR_STR2
4969 "Set a password\n"
4970 "The password\n")
4971 {
4972 int idx_peer = 1;
4973 int idx_line = 3;
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 = peer_password_set(peer, argv[idx_line]->arg);
4982 return bgp_vty_return(vty, ret);
4983 }
4984
4985 DEFUN (no_neighbor_password,
4986 no_neighbor_password_cmd,
4987 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4988 NO_STR
4989 NEIGHBOR_STR
4990 NEIGHBOR_ADDR_STR2
4991 "Set a password\n"
4992 "The password\n")
4993 {
4994 int idx_peer = 2;
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_unset(peer);
5003 return bgp_vty_return(vty, ret);
5004 }
5005
5006 DEFUN (neighbor_activate,
5007 neighbor_activate_cmd,
5008 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5009 NEIGHBOR_STR
5010 NEIGHBOR_ADDR_STR2
5011 "Enable the Address Family for this Neighbor\n")
5012 {
5013 int idx_peer = 1;
5014 int ret;
5015 struct peer *peer;
5016
5017 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5018 if (!peer)
5019 return CMD_WARNING_CONFIG_FAILED;
5020
5021 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5022 return bgp_vty_return(vty, ret);
5023 }
5024
5025 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5026 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5027 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5028 "Enable the Address Family for this Neighbor\n")
5029
5030 DEFUN (no_neighbor_activate,
5031 no_neighbor_activate_cmd,
5032 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5033 NO_STR
5034 NEIGHBOR_STR
5035 NEIGHBOR_ADDR_STR2
5036 "Enable the Address Family for this Neighbor\n")
5037 {
5038 int idx_peer = 2;
5039 int ret;
5040 struct peer *peer;
5041
5042 /* Lookup peer. */
5043 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5044 if (!peer)
5045 return CMD_WARNING_CONFIG_FAILED;
5046
5047 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5048 return bgp_vty_return(vty, ret);
5049 }
5050
5051 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5052 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5053 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5054 "Enable the Address Family for this Neighbor\n")
5055
5056 DEFUN (neighbor_set_peer_group,
5057 neighbor_set_peer_group_cmd,
5058 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5059 NEIGHBOR_STR
5060 NEIGHBOR_ADDR_STR2
5061 "Member of the peer-group\n"
5062 "Peer-group name\n")
5063 {
5064 VTY_DECLVAR_CONTEXT(bgp, bgp);
5065 int idx_peer = 1;
5066 int idx_word = 3;
5067 int ret;
5068 as_t as;
5069 union sockunion su;
5070 struct peer *peer;
5071 struct peer_group *group;
5072
5073 ret = str2sockunion(argv[idx_peer]->arg, &su);
5074 if (ret < 0) {
5075 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5076 if (!peer) {
5077 vty_out(vty, "%% Malformed address or name: %s\n",
5078 argv[idx_peer]->arg);
5079 return CMD_WARNING_CONFIG_FAILED;
5080 }
5081 } else {
5082 if (peer_address_self_check(bgp, &su)) {
5083 vty_out(vty,
5084 "%% Can not configure the local system as neighbor\n");
5085 return CMD_WARNING_CONFIG_FAILED;
5086 }
5087
5088 /* Disallow for dynamic neighbor. */
5089 peer = peer_lookup(bgp, &su);
5090 if (peer && peer_dynamic_neighbor(peer)) {
5091 vty_out(vty,
5092 "%% Operation not allowed on a dynamic neighbor\n");
5093 return CMD_WARNING_CONFIG_FAILED;
5094 }
5095 }
5096
5097 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5098 if (!group) {
5099 vty_out(vty, "%% Configure the peer-group first\n");
5100 return CMD_WARNING_CONFIG_FAILED;
5101 }
5102
5103 ret = peer_group_bind(bgp, &su, peer, group, &as);
5104
5105 return bgp_vty_return(vty, ret);
5106 }
5107
5108 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5109 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5110 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5111 "Member of the peer-group\n"
5112 "Peer-group name\n")
5113
5114 DEFUN (no_neighbor_set_peer_group,
5115 no_neighbor_set_peer_group_cmd,
5116 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5117 NO_STR
5118 NEIGHBOR_STR
5119 NEIGHBOR_ADDR_STR2
5120 "Member of the peer-group\n"
5121 "Peer-group name\n")
5122 {
5123 VTY_DECLVAR_CONTEXT(bgp, bgp);
5124 int idx_peer = 2;
5125 int idx_word = 4;
5126 int ret;
5127 struct peer *peer;
5128 struct peer_group *group;
5129
5130 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5131 if (!peer)
5132 return CMD_WARNING_CONFIG_FAILED;
5133
5134 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5135 if (!group) {
5136 vty_out(vty, "%% Configure the peer-group first\n");
5137 return CMD_WARNING_CONFIG_FAILED;
5138 }
5139
5140 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5141 bgp_zebra_terminate_radv(peer->bgp, peer);
5142
5143 peer_notify_unconfig(peer);
5144 ret = peer_delete(peer);
5145
5146 return bgp_vty_return(vty, ret);
5147 }
5148
5149 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5150 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5152 "Member of the peer-group\n"
5153 "Peer-group name\n")
5154
5155 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5156 uint64_t flag, int set)
5157 {
5158 int ret;
5159 struct peer *peer;
5160
5161 peer = peer_and_group_lookup_vty(vty, ip_str);
5162 if (!peer)
5163 return CMD_WARNING_CONFIG_FAILED;
5164
5165 /*
5166 * If 'neighbor <interface>', then this is for directly connected peers,
5167 * we should not accept disable-connected-check.
5168 */
5169 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5170 vty_out(vty,
5171 "%s is directly connected peer, cannot accept disable-connected-check\n",
5172 ip_str);
5173 return CMD_WARNING_CONFIG_FAILED;
5174 }
5175
5176 if (!set && flag == PEER_FLAG_SHUTDOWN)
5177 peer_tx_shutdown_message_unset(peer);
5178
5179 if (set)
5180 ret = peer_flag_set(peer, flag);
5181 else
5182 ret = peer_flag_unset(peer, flag);
5183
5184 return bgp_vty_return(vty, ret);
5185 }
5186
5187 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5188 {
5189 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5190 }
5191
5192 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5193 uint64_t flag)
5194 {
5195 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5196 }
5197
5198 /* neighbor passive. */
5199 DEFUN (neighbor_passive,
5200 neighbor_passive_cmd,
5201 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5202 NEIGHBOR_STR
5203 NEIGHBOR_ADDR_STR2
5204 "Don't send open messages to this neighbor\n")
5205 {
5206 int idx_peer = 1;
5207 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5208 }
5209
5210 DEFUN (no_neighbor_passive,
5211 no_neighbor_passive_cmd,
5212 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5213 NO_STR
5214 NEIGHBOR_STR
5215 NEIGHBOR_ADDR_STR2
5216 "Don't send open messages to this neighbor\n")
5217 {
5218 int idx_peer = 2;
5219 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5220 }
5221
5222 /* neighbor shutdown. */
5223 DEFUN (neighbor_shutdown_msg,
5224 neighbor_shutdown_msg_cmd,
5225 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5226 NEIGHBOR_STR
5227 NEIGHBOR_ADDR_STR2
5228 "Administratively shut down this neighbor\n"
5229 "Add a shutdown message (RFC 8203)\n"
5230 "Shutdown message\n")
5231 {
5232 int idx_peer = 1;
5233
5234 if (argc >= 5) {
5235 struct peer *peer =
5236 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5237 char *message;
5238
5239 if (!peer)
5240 return CMD_WARNING_CONFIG_FAILED;
5241 message = argv_concat(argv, argc, 4);
5242 peer_tx_shutdown_message_set(peer, message);
5243 XFREE(MTYPE_TMP, message);
5244 }
5245
5246 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5247 }
5248
5249 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5250 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5252 "Administratively shut down this neighbor\n")
5253
5254 DEFUN (no_neighbor_shutdown_msg,
5255 no_neighbor_shutdown_msg_cmd,
5256 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5257 NO_STR
5258 NEIGHBOR_STR
5259 NEIGHBOR_ADDR_STR2
5260 "Administratively shut down this neighbor\n"
5261 "Remove a shutdown message (RFC 8203)\n"
5262 "Shutdown message\n")
5263 {
5264 int idx_peer = 2;
5265
5266 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5267 PEER_FLAG_SHUTDOWN);
5268 }
5269
5270 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5271 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5272 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5273 "Administratively shut down this neighbor\n")
5274
5275 DEFUN(neighbor_shutdown_rtt,
5276 neighbor_shutdown_rtt_cmd,
5277 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5278 NEIGHBOR_STR
5279 NEIGHBOR_ADDR_STR2
5280 "Administratively shut down this neighbor\n"
5281 "Shutdown if round-trip-time is higher than expected\n"
5282 "Round-trip-time in milliseconds\n"
5283 "Specify the number of keepalives before shutdown\n"
5284 "The number of keepalives with higher RTT to shutdown\n")
5285 {
5286 int idx_peer = 1;
5287 int idx_rtt = 4;
5288 int idx_count = 0;
5289 struct peer *peer;
5290
5291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5292
5293 if (!peer)
5294 return CMD_WARNING_CONFIG_FAILED;
5295
5296 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5297
5298 if (argv_find(argv, argc, "count", &idx_count))
5299 peer->rtt_keepalive_conf =
5300 strtol(argv[idx_count + 1]->arg, NULL, 10);
5301
5302 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5303 PEER_FLAG_RTT_SHUTDOWN);
5304 }
5305
5306 DEFUN(no_neighbor_shutdown_rtt,
5307 no_neighbor_shutdown_rtt_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5309 NO_STR
5310 NEIGHBOR_STR
5311 NEIGHBOR_ADDR_STR2
5312 "Administratively shut down this neighbor\n"
5313 "Shutdown if round-trip-time is higher than expected\n"
5314 "Round-trip-time in milliseconds\n"
5315 "Specify the number of keepalives before shutdown\n"
5316 "The number of keepalives with higher RTT to shutdown\n")
5317 {
5318 int idx_peer = 2;
5319 struct peer *peer;
5320
5321 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5322
5323 if (!peer)
5324 return CMD_WARNING_CONFIG_FAILED;
5325
5326 peer->rtt_expected = 0;
5327 peer->rtt_keepalive_conf = 1;
5328
5329 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5330 PEER_FLAG_RTT_SHUTDOWN);
5331 }
5332
5333 /* neighbor capability dynamic. */
5334 DEFUN (neighbor_capability_dynamic,
5335 neighbor_capability_dynamic_cmd,
5336 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5337 NEIGHBOR_STR
5338 NEIGHBOR_ADDR_STR2
5339 "Advertise capability to the peer\n"
5340 "Advertise dynamic capability to this neighbor\n")
5341 {
5342 int idx_peer = 1;
5343 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5344 PEER_FLAG_DYNAMIC_CAPABILITY);
5345 }
5346
5347 DEFUN (no_neighbor_capability_dynamic,
5348 no_neighbor_capability_dynamic_cmd,
5349 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5350 NO_STR
5351 NEIGHBOR_STR
5352 NEIGHBOR_ADDR_STR2
5353 "Advertise capability to the peer\n"
5354 "Advertise dynamic capability to this neighbor\n")
5355 {
5356 int idx_peer = 2;
5357 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5358 PEER_FLAG_DYNAMIC_CAPABILITY);
5359 }
5360
5361 /* neighbor dont-capability-negotiate */
5362 DEFUN (neighbor_dont_capability_negotiate,
5363 neighbor_dont_capability_negotiate_cmd,
5364 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5365 NEIGHBOR_STR
5366 NEIGHBOR_ADDR_STR2
5367 "Do not perform capability negotiation\n")
5368 {
5369 int idx_peer = 1;
5370 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5371 PEER_FLAG_DONT_CAPABILITY);
5372 }
5373
5374 DEFUN (no_neighbor_dont_capability_negotiate,
5375 no_neighbor_dont_capability_negotiate_cmd,
5376 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5377 NO_STR
5378 NEIGHBOR_STR
5379 NEIGHBOR_ADDR_STR2
5380 "Do not perform capability negotiation\n")
5381 {
5382 int idx_peer = 2;
5383 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5384 PEER_FLAG_DONT_CAPABILITY);
5385 }
5386
5387 /* neighbor capability extended next hop encoding */
5388 DEFUN (neighbor_capability_enhe,
5389 neighbor_capability_enhe_cmd,
5390 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5391 NEIGHBOR_STR
5392 NEIGHBOR_ADDR_STR2
5393 "Advertise capability to the peer\n"
5394 "Advertise extended next-hop capability to the peer\n")
5395 {
5396 int idx_peer = 1;
5397 struct peer *peer;
5398
5399 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5400 if (peer && peer->conf_if)
5401 return CMD_SUCCESS;
5402
5403 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5404 PEER_FLAG_CAPABILITY_ENHE);
5405 }
5406
5407 DEFUN (no_neighbor_capability_enhe,
5408 no_neighbor_capability_enhe_cmd,
5409 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5410 NO_STR
5411 NEIGHBOR_STR
5412 NEIGHBOR_ADDR_STR2
5413 "Advertise capability to the peer\n"
5414 "Advertise extended next-hop capability to the peer\n")
5415 {
5416 int idx_peer = 2;
5417 struct peer *peer;
5418
5419 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5420 if (peer && peer->conf_if) {
5421 vty_out(vty,
5422 "Peer %s cannot have capability extended-nexthop turned off\n",
5423 argv[idx_peer]->arg);
5424 return CMD_WARNING_CONFIG_FAILED;
5425 }
5426
5427 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5428 PEER_FLAG_CAPABILITY_ENHE);
5429 }
5430
5431 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5432 afi_t afi, safi_t safi, uint32_t flag,
5433 int set)
5434 {
5435 int ret;
5436 struct peer *peer;
5437
5438 peer = peer_and_group_lookup_vty(vty, peer_str);
5439 if (!peer)
5440 return CMD_WARNING_CONFIG_FAILED;
5441
5442 if (set)
5443 ret = peer_af_flag_set(peer, afi, safi, flag);
5444 else
5445 ret = peer_af_flag_unset(peer, afi, safi, flag);
5446
5447 return bgp_vty_return(vty, ret);
5448 }
5449
5450 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5451 afi_t afi, safi_t safi, uint32_t flag)
5452 {
5453 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5454 }
5455
5456 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5457 afi_t afi, safi_t safi, uint32_t flag)
5458 {
5459 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5460 }
5461
5462 /* neighbor capability orf prefix-list. */
5463 DEFUN (neighbor_capability_orf_prefix,
5464 neighbor_capability_orf_prefix_cmd,
5465 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5466 NEIGHBOR_STR
5467 NEIGHBOR_ADDR_STR2
5468 "Advertise capability to the peer\n"
5469 "Advertise ORF capability to the peer\n"
5470 "Advertise prefixlist ORF capability to this neighbor\n"
5471 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5472 "Capability to RECEIVE the ORF from this neighbor\n"
5473 "Capability to SEND the ORF to this neighbor\n")
5474 {
5475 int idx_send_recv = 5;
5476 char *peer_str = argv[1]->arg;
5477 struct peer *peer;
5478 afi_t afi = bgp_node_afi(vty);
5479 safi_t safi = bgp_node_safi(vty);
5480
5481 peer = peer_and_group_lookup_vty(vty, peer_str);
5482 if (!peer)
5483 return CMD_WARNING_CONFIG_FAILED;
5484
5485 if (strmatch(argv[idx_send_recv]->text, "send"))
5486 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5487 PEER_FLAG_ORF_PREFIX_SM);
5488
5489 if (strmatch(argv[idx_send_recv]->text, "receive"))
5490 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5491 PEER_FLAG_ORF_PREFIX_RM);
5492
5493 if (strmatch(argv[idx_send_recv]->text, "both"))
5494 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5495 PEER_FLAG_ORF_PREFIX_SM)
5496 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5497 PEER_FLAG_ORF_PREFIX_RM);
5498
5499 return CMD_WARNING_CONFIG_FAILED;
5500 }
5501
5502 ALIAS_HIDDEN(
5503 neighbor_capability_orf_prefix,
5504 neighbor_capability_orf_prefix_hidden_cmd,
5505 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5507 "Advertise capability to the peer\n"
5508 "Advertise ORF capability to the peer\n"
5509 "Advertise prefixlist ORF capability to this neighbor\n"
5510 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5511 "Capability to RECEIVE the ORF from this neighbor\n"
5512 "Capability to SEND the ORF to this neighbor\n")
5513
5514 DEFUN (no_neighbor_capability_orf_prefix,
5515 no_neighbor_capability_orf_prefix_cmd,
5516 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5517 NO_STR
5518 NEIGHBOR_STR
5519 NEIGHBOR_ADDR_STR2
5520 "Advertise capability to the peer\n"
5521 "Advertise ORF capability to the peer\n"
5522 "Advertise prefixlist ORF capability to this neighbor\n"
5523 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5524 "Capability to RECEIVE the ORF from this neighbor\n"
5525 "Capability to SEND the ORF to this neighbor\n")
5526 {
5527 int idx_send_recv = 6;
5528 char *peer_str = argv[2]->arg;
5529 struct peer *peer;
5530 afi_t afi = bgp_node_afi(vty);
5531 safi_t safi = bgp_node_safi(vty);
5532
5533 peer = peer_and_group_lookup_vty(vty, peer_str);
5534 if (!peer)
5535 return CMD_WARNING_CONFIG_FAILED;
5536
5537 if (strmatch(argv[idx_send_recv]->text, "send"))
5538 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5539 PEER_FLAG_ORF_PREFIX_SM);
5540
5541 if (strmatch(argv[idx_send_recv]->text, "receive"))
5542 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5543 PEER_FLAG_ORF_PREFIX_RM);
5544
5545 if (strmatch(argv[idx_send_recv]->text, "both"))
5546 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5547 PEER_FLAG_ORF_PREFIX_SM)
5548 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5549 PEER_FLAG_ORF_PREFIX_RM);
5550
5551 return CMD_WARNING_CONFIG_FAILED;
5552 }
5553
5554 ALIAS_HIDDEN(
5555 no_neighbor_capability_orf_prefix,
5556 no_neighbor_capability_orf_prefix_hidden_cmd,
5557 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5558 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5559 "Advertise capability to the peer\n"
5560 "Advertise ORF capability to the peer\n"
5561 "Advertise prefixlist ORF capability to this neighbor\n"
5562 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5563 "Capability to RECEIVE the ORF from this neighbor\n"
5564 "Capability to SEND the ORF to this neighbor\n")
5565
5566 /* neighbor next-hop-self. */
5567 DEFUN (neighbor_nexthop_self,
5568 neighbor_nexthop_self_cmd,
5569 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR2
5572 "Disable the next hop calculation for this neighbor\n")
5573 {
5574 int idx_peer = 1;
5575 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5576 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5577 }
5578
5579 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5580 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5582 "Disable the next hop calculation for this neighbor\n")
5583
5584 /* neighbor next-hop-self. */
5585 DEFUN (neighbor_nexthop_self_force,
5586 neighbor_nexthop_self_force_cmd,
5587 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5588 NEIGHBOR_STR
5589 NEIGHBOR_ADDR_STR2
5590 "Disable the next hop calculation for this neighbor\n"
5591 "Set the next hop to self for reflected routes\n")
5592 {
5593 int idx_peer = 1;
5594 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5595 bgp_node_safi(vty),
5596 PEER_FLAG_FORCE_NEXTHOP_SELF);
5597 }
5598
5599 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5600 neighbor_nexthop_self_force_hidden_cmd,
5601 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5602 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5603 "Disable the next hop calculation for this neighbor\n"
5604 "Set the next hop to self for reflected routes\n")
5605
5606 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5607 neighbor_nexthop_self_all_hidden_cmd,
5608 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5610 "Disable the next hop calculation for this neighbor\n"
5611 "Set the next hop to self for reflected routes\n")
5612
5613 DEFUN (no_neighbor_nexthop_self,
5614 no_neighbor_nexthop_self_cmd,
5615 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5616 NO_STR
5617 NEIGHBOR_STR
5618 NEIGHBOR_ADDR_STR2
5619 "Disable the next hop calculation for this neighbor\n")
5620 {
5621 int idx_peer = 2;
5622 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5623 bgp_node_afi(vty), bgp_node_safi(vty),
5624 PEER_FLAG_NEXTHOP_SELF);
5625 }
5626
5627 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5628 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5629 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5630 "Disable the next hop calculation for this neighbor\n")
5631
5632 DEFUN (no_neighbor_nexthop_self_force,
5633 no_neighbor_nexthop_self_force_cmd,
5634 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5635 NO_STR
5636 NEIGHBOR_STR
5637 NEIGHBOR_ADDR_STR2
5638 "Disable the next hop calculation for this neighbor\n"
5639 "Set the next hop to self for reflected routes\n")
5640 {
5641 int idx_peer = 2;
5642 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5643 bgp_node_afi(vty), bgp_node_safi(vty),
5644 PEER_FLAG_FORCE_NEXTHOP_SELF);
5645 }
5646
5647 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5648 no_neighbor_nexthop_self_force_hidden_cmd,
5649 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5650 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5651 "Disable the next hop calculation for this neighbor\n"
5652 "Set the next hop to self for reflected routes\n")
5653
5654 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5655 no_neighbor_nexthop_self_all_hidden_cmd,
5656 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5657 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5658 "Disable the next hop calculation for this neighbor\n"
5659 "Set the next hop to self for reflected routes\n")
5660
5661 /* neighbor as-override */
5662 DEFUN (neighbor_as_override,
5663 neighbor_as_override_cmd,
5664 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5665 NEIGHBOR_STR
5666 NEIGHBOR_ADDR_STR2
5667 "Override ASNs in outbound updates if aspath equals remote-as\n")
5668 {
5669 int idx_peer = 1;
5670 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5671 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5672 }
5673
5674 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5675 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5676 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5677 "Override ASNs in outbound updates if aspath equals remote-as\n")
5678
5679 DEFUN (no_neighbor_as_override,
5680 no_neighbor_as_override_cmd,
5681 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5682 NO_STR
5683 NEIGHBOR_STR
5684 NEIGHBOR_ADDR_STR2
5685 "Override ASNs in outbound updates if aspath equals remote-as\n")
5686 {
5687 int idx_peer = 2;
5688 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5689 bgp_node_afi(vty), bgp_node_safi(vty),
5690 PEER_FLAG_AS_OVERRIDE);
5691 }
5692
5693 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5694 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5695 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5696 "Override ASNs in outbound updates if aspath equals remote-as\n")
5697
5698 /* neighbor remove-private-AS. */
5699 DEFUN (neighbor_remove_private_as,
5700 neighbor_remove_private_as_cmd,
5701 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5702 NEIGHBOR_STR
5703 NEIGHBOR_ADDR_STR2
5704 "Remove private ASNs in outbound updates\n")
5705 {
5706 int idx_peer = 1;
5707 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5708 bgp_node_safi(vty),
5709 PEER_FLAG_REMOVE_PRIVATE_AS);
5710 }
5711
5712 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Remove private ASNs in outbound updates\n")
5716
5717 DEFUN (neighbor_remove_private_as_all,
5718 neighbor_remove_private_as_all_cmd,
5719 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Remove private ASNs in outbound updates\n"
5723 "Apply to all AS numbers\n")
5724 {
5725 int idx_peer = 1;
5726 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5727 bgp_node_safi(vty),
5728 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5729 }
5730
5731 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5732 neighbor_remove_private_as_all_hidden_cmd,
5733 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5734 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5735 "Remove private ASNs in outbound updates\n"
5736 "Apply to all AS numbers")
5737
5738 DEFUN (neighbor_remove_private_as_replace_as,
5739 neighbor_remove_private_as_replace_as_cmd,
5740 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5741 NEIGHBOR_STR
5742 NEIGHBOR_ADDR_STR2
5743 "Remove private ASNs in outbound updates\n"
5744 "Replace private ASNs with our ASN in outbound updates\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_REPLACE);
5750 }
5751
5752 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5753 neighbor_remove_private_as_replace_as_hidden_cmd,
5754 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5755 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5756 "Remove private ASNs in outbound updates\n"
5757 "Replace private ASNs with our ASN in outbound updates\n")
5758
5759 DEFUN (neighbor_remove_private_as_all_replace_as,
5760 neighbor_remove_private_as_all_replace_as_cmd,
5761 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5762 NEIGHBOR_STR
5763 NEIGHBOR_ADDR_STR2
5764 "Remove private ASNs in outbound updates\n"
5765 "Apply to all AS numbers\n"
5766 "Replace private ASNs with our ASN in outbound updates\n")
5767 {
5768 int idx_peer = 1;
5769 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5770 bgp_node_safi(vty),
5771 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5772 }
5773
5774 ALIAS_HIDDEN(
5775 neighbor_remove_private_as_all_replace_as,
5776 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5777 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5778 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5779 "Remove private ASNs in outbound updates\n"
5780 "Apply to all AS numbers\n"
5781 "Replace private ASNs with our ASN in outbound updates\n")
5782
5783 DEFUN (no_neighbor_remove_private_as,
5784 no_neighbor_remove_private_as_cmd,
5785 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5786 NO_STR
5787 NEIGHBOR_STR
5788 NEIGHBOR_ADDR_STR2
5789 "Remove private ASNs in outbound updates\n")
5790 {
5791 int idx_peer = 2;
5792 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5793 bgp_node_afi(vty), bgp_node_safi(vty),
5794 PEER_FLAG_REMOVE_PRIVATE_AS);
5795 }
5796
5797 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5798 no_neighbor_remove_private_as_hidden_cmd,
5799 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5800 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5801 "Remove private ASNs in outbound updates\n")
5802
5803 DEFUN (no_neighbor_remove_private_as_all,
5804 no_neighbor_remove_private_as_all_cmd,
5805 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5806 NO_STR
5807 NEIGHBOR_STR
5808 NEIGHBOR_ADDR_STR2
5809 "Remove private ASNs in outbound updates\n"
5810 "Apply to all AS numbers\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_ALL);
5816 }
5817
5818 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5819 no_neighbor_remove_private_as_all_hidden_cmd,
5820 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5822 "Remove private ASNs in outbound updates\n"
5823 "Apply to all AS numbers\n")
5824
5825 DEFUN (no_neighbor_remove_private_as_replace_as,
5826 no_neighbor_remove_private_as_replace_as_cmd,
5827 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5828 NO_STR
5829 NEIGHBOR_STR
5830 NEIGHBOR_ADDR_STR2
5831 "Remove private ASNs in outbound updates\n"
5832 "Replace private ASNs with our ASN in outbound updates\n")
5833 {
5834 int idx_peer = 2;
5835 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5836 bgp_node_afi(vty), bgp_node_safi(vty),
5837 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5838 }
5839
5840 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5841 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5842 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5843 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5844 "Remove private ASNs in outbound updates\n"
5845 "Replace private ASNs with our ASN in outbound updates\n")
5846
5847 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5848 no_neighbor_remove_private_as_all_replace_as_cmd,
5849 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5850 NO_STR
5851 NEIGHBOR_STR
5852 NEIGHBOR_ADDR_STR2
5853 "Remove private ASNs in outbound updates\n"
5854 "Apply to all AS numbers\n"
5855 "Replace private ASNs with our ASN in outbound updates\n")
5856 {
5857 int idx_peer = 2;
5858 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5859 bgp_node_afi(vty), bgp_node_safi(vty),
5860 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5861 }
5862
5863 ALIAS_HIDDEN(
5864 no_neighbor_remove_private_as_all_replace_as,
5865 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5866 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5867 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5868 "Remove private ASNs in outbound updates\n"
5869 "Apply to all AS numbers\n"
5870 "Replace private ASNs with our ASN in outbound updates\n")
5871
5872
5873 /* neighbor send-community. */
5874 DEFUN (neighbor_send_community,
5875 neighbor_send_community_cmd,
5876 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5877 NEIGHBOR_STR
5878 NEIGHBOR_ADDR_STR2
5879 "Send Community attribute to this neighbor\n")
5880 {
5881 int idx_peer = 1;
5882
5883 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5884 bgp_node_safi(vty),
5885 PEER_FLAG_SEND_COMMUNITY);
5886 }
5887
5888 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5889 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5891 "Send Community attribute to this neighbor\n")
5892
5893 DEFUN (no_neighbor_send_community,
5894 no_neighbor_send_community_cmd,
5895 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5896 NO_STR
5897 NEIGHBOR_STR
5898 NEIGHBOR_ADDR_STR2
5899 "Send Community attribute to this neighbor\n")
5900 {
5901 int idx_peer = 2;
5902
5903 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5904 bgp_node_afi(vty), bgp_node_safi(vty),
5905 PEER_FLAG_SEND_COMMUNITY);
5906 }
5907
5908 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5909 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5910 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Send Community attribute to this neighbor\n")
5912
5913 /* neighbor send-community extended. */
5914 DEFUN (neighbor_send_community_type,
5915 neighbor_send_community_type_cmd,
5916 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5917 NEIGHBOR_STR
5918 NEIGHBOR_ADDR_STR2
5919 "Send Community attribute to this neighbor\n"
5920 "Send Standard and Extended Community attributes\n"
5921 "Send Standard, Large and Extended Community attributes\n"
5922 "Send Extended Community attributes\n"
5923 "Send Standard Community attributes\n"
5924 "Send Large Community attributes\n")
5925 {
5926 const char *type = argv[argc - 1]->text;
5927 char *peer_str = argv[1]->arg;
5928 struct peer *peer;
5929 afi_t afi = bgp_node_afi(vty);
5930 safi_t safi = bgp_node_safi(vty);
5931
5932 peer = peer_and_group_lookup_vty(vty, peer_str);
5933 if (!peer)
5934 return CMD_WARNING_CONFIG_FAILED;
5935
5936 if (strmatch(type, "standard"))
5937 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5938 PEER_FLAG_SEND_COMMUNITY);
5939
5940 if (strmatch(type, "extended"))
5941 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5942 PEER_FLAG_SEND_EXT_COMMUNITY);
5943
5944 if (strmatch(type, "large"))
5945 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5946 PEER_FLAG_SEND_LARGE_COMMUNITY);
5947
5948 if (strmatch(type, "both")) {
5949 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5950 PEER_FLAG_SEND_COMMUNITY)
5951 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5952 PEER_FLAG_SEND_EXT_COMMUNITY);
5953 }
5954 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5955 PEER_FLAG_SEND_COMMUNITY)
5956 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5957 PEER_FLAG_SEND_EXT_COMMUNITY)
5958 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5959 PEER_FLAG_SEND_LARGE_COMMUNITY);
5960 }
5961
5962 ALIAS_HIDDEN(
5963 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5964 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5966 "Send Community attribute to this neighbor\n"
5967 "Send Standard and Extended Community attributes\n"
5968 "Send Standard, Large and Extended Community attributes\n"
5969 "Send Extended Community attributes\n"
5970 "Send Standard Community attributes\n"
5971 "Send Large Community attributes\n")
5972
5973 DEFUN (no_neighbor_send_community_type,
5974 no_neighbor_send_community_type_cmd,
5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5976 NO_STR
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Send Community attribute to this neighbor\n"
5980 "Send Standard and Extended Community attributes\n"
5981 "Send Standard, Large and Extended Community attributes\n"
5982 "Send Extended Community attributes\n"
5983 "Send Standard Community attributes\n"
5984 "Send Large Community attributes\n")
5985 {
5986 const char *type = argv[argc - 1]->text;
5987 char *peer_str = argv[2]->arg;
5988 struct peer *peer;
5989 afi_t afi = bgp_node_afi(vty);
5990 safi_t safi = bgp_node_safi(vty);
5991
5992 peer = peer_and_group_lookup_vty(vty, peer_str);
5993 if (!peer)
5994 return CMD_WARNING_CONFIG_FAILED;
5995
5996 if (strmatch(type, "standard"))
5997 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5998 PEER_FLAG_SEND_COMMUNITY);
5999
6000 if (strmatch(type, "extended"))
6001 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6002 PEER_FLAG_SEND_EXT_COMMUNITY);
6003
6004 if (strmatch(type, "large"))
6005 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6006 PEER_FLAG_SEND_LARGE_COMMUNITY);
6007
6008 if (strmatch(type, "both")) {
6009
6010 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6011 PEER_FLAG_SEND_COMMUNITY)
6012 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6013 PEER_FLAG_SEND_EXT_COMMUNITY);
6014 }
6015
6016 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6017 PEER_FLAG_SEND_COMMUNITY)
6018 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6019 PEER_FLAG_SEND_EXT_COMMUNITY)
6020 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6021 PEER_FLAG_SEND_LARGE_COMMUNITY);
6022 }
6023
6024 ALIAS_HIDDEN(
6025 no_neighbor_send_community_type,
6026 no_neighbor_send_community_type_hidden_cmd,
6027 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6028 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6029 "Send Community attribute to this neighbor\n"
6030 "Send Standard and Extended Community attributes\n"
6031 "Send Standard, Large and Extended Community attributes\n"
6032 "Send Extended Community attributes\n"
6033 "Send Standard Community attributes\n"
6034 "Send Large Community attributes\n")
6035
6036 /* neighbor soft-reconfig. */
6037 DEFUN (neighbor_soft_reconfiguration,
6038 neighbor_soft_reconfiguration_cmd,
6039 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6040 NEIGHBOR_STR
6041 NEIGHBOR_ADDR_STR2
6042 "Per neighbor soft reconfiguration\n"
6043 "Allow inbound soft reconfiguration for this neighbor\n")
6044 {
6045 int idx_peer = 1;
6046 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6047 bgp_node_safi(vty),
6048 PEER_FLAG_SOFT_RECONFIG);
6049 }
6050
6051 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6052 neighbor_soft_reconfiguration_hidden_cmd,
6053 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6054 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6055 "Per neighbor soft reconfiguration\n"
6056 "Allow inbound soft reconfiguration for this neighbor\n")
6057
6058 DEFUN (no_neighbor_soft_reconfiguration,
6059 no_neighbor_soft_reconfiguration_cmd,
6060 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6061 NO_STR
6062 NEIGHBOR_STR
6063 NEIGHBOR_ADDR_STR2
6064 "Per neighbor soft reconfiguration\n"
6065 "Allow inbound soft reconfiguration for this neighbor\n")
6066 {
6067 int idx_peer = 2;
6068 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6069 bgp_node_afi(vty), bgp_node_safi(vty),
6070 PEER_FLAG_SOFT_RECONFIG);
6071 }
6072
6073 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6074 no_neighbor_soft_reconfiguration_hidden_cmd,
6075 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6076 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6077 "Per neighbor soft reconfiguration\n"
6078 "Allow inbound soft reconfiguration for this neighbor\n")
6079
6080 DEFUN (neighbor_route_reflector_client,
6081 neighbor_route_reflector_client_cmd,
6082 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6083 NEIGHBOR_STR
6084 NEIGHBOR_ADDR_STR2
6085 "Configure a neighbor as Route Reflector client\n")
6086 {
6087 int idx_peer = 1;
6088 struct peer *peer;
6089
6090
6091 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6092 if (!peer)
6093 return CMD_WARNING_CONFIG_FAILED;
6094
6095 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6096 bgp_node_safi(vty),
6097 PEER_FLAG_REFLECTOR_CLIENT);
6098 }
6099
6100 ALIAS_HIDDEN(neighbor_route_reflector_client,
6101 neighbor_route_reflector_client_hidden_cmd,
6102 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6104 "Configure a neighbor as Route Reflector client\n")
6105
6106 DEFUN (no_neighbor_route_reflector_client,
6107 no_neighbor_route_reflector_client_cmd,
6108 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6109 NO_STR
6110 NEIGHBOR_STR
6111 NEIGHBOR_ADDR_STR2
6112 "Configure a neighbor as Route Reflector client\n")
6113 {
6114 int idx_peer = 2;
6115 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6116 bgp_node_afi(vty), bgp_node_safi(vty),
6117 PEER_FLAG_REFLECTOR_CLIENT);
6118 }
6119
6120 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6121 no_neighbor_route_reflector_client_hidden_cmd,
6122 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6123 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6124 "Configure a neighbor as Route Reflector client\n")
6125
6126 /* neighbor route-server-client. */
6127 DEFUN (neighbor_route_server_client,
6128 neighbor_route_server_client_cmd,
6129 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
6132 "Configure a neighbor as Route Server client\n")
6133 {
6134 int idx_peer = 1;
6135 struct peer *peer;
6136
6137 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6138 if (!peer)
6139 return CMD_WARNING_CONFIG_FAILED;
6140 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6141 bgp_node_safi(vty),
6142 PEER_FLAG_RSERVER_CLIENT);
6143 }
6144
6145 ALIAS_HIDDEN(neighbor_route_server_client,
6146 neighbor_route_server_client_hidden_cmd,
6147 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6148 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6149 "Configure a neighbor as Route Server client\n")
6150
6151 DEFUN (no_neighbor_route_server_client,
6152 no_neighbor_route_server_client_cmd,
6153 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6154 NO_STR
6155 NEIGHBOR_STR
6156 NEIGHBOR_ADDR_STR2
6157 "Configure a neighbor as Route Server client\n")
6158 {
6159 int idx_peer = 2;
6160 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6161 bgp_node_afi(vty), bgp_node_safi(vty),
6162 PEER_FLAG_RSERVER_CLIENT);
6163 }
6164
6165 ALIAS_HIDDEN(no_neighbor_route_server_client,
6166 no_neighbor_route_server_client_hidden_cmd,
6167 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6168 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6169 "Configure a neighbor as Route Server client\n")
6170
6171 DEFUN (neighbor_nexthop_local_unchanged,
6172 neighbor_nexthop_local_unchanged_cmd,
6173 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6174 NEIGHBOR_STR
6175 NEIGHBOR_ADDR_STR2
6176 "Configure treatment of outgoing link-local nexthop attribute\n"
6177 "Leave link-local nexthop unchanged for this peer\n")
6178 {
6179 int idx_peer = 1;
6180 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6181 bgp_node_safi(vty),
6182 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6183 }
6184
6185 DEFUN (no_neighbor_nexthop_local_unchanged,
6186 no_neighbor_nexthop_local_unchanged_cmd,
6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6188 NO_STR
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "Configure treatment of outgoing link-local-nexthop attribute\n"
6192 "Leave link-local nexthop unchanged for this peer\n")
6193 {
6194 int idx_peer = 2;
6195 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6196 bgp_node_afi(vty), bgp_node_safi(vty),
6197 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6198 }
6199
6200 DEFUN (neighbor_attr_unchanged,
6201 neighbor_attr_unchanged_cmd,
6202 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6203 NEIGHBOR_STR
6204 NEIGHBOR_ADDR_STR2
6205 "BGP attribute is propagated unchanged to this neighbor\n"
6206 "As-path attribute\n"
6207 "Nexthop attribute\n"
6208 "Med attribute\n")
6209 {
6210 int idx = 0;
6211 char *peer_str = argv[1]->arg;
6212 struct peer *peer;
6213 bool aspath = false;
6214 bool nexthop = false;
6215 bool med = false;
6216 afi_t afi = bgp_node_afi(vty);
6217 safi_t safi = bgp_node_safi(vty);
6218 int ret = 0;
6219
6220 peer = peer_and_group_lookup_vty(vty, peer_str);
6221 if (!peer)
6222 return CMD_WARNING_CONFIG_FAILED;
6223
6224 if (argv_find(argv, argc, "as-path", &idx))
6225 aspath = true;
6226
6227 idx = 0;
6228 if (argv_find(argv, argc, "next-hop", &idx))
6229 nexthop = true;
6230
6231 idx = 0;
6232 if (argv_find(argv, argc, "med", &idx))
6233 med = true;
6234
6235 /* no flags means all of them! */
6236 if (!aspath && !nexthop && !med) {
6237 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6238 PEER_FLAG_AS_PATH_UNCHANGED);
6239 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6240 PEER_FLAG_NEXTHOP_UNCHANGED);
6241 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6242 PEER_FLAG_MED_UNCHANGED);
6243 } else {
6244 if (!aspath) {
6245 if (peer_af_flag_check(peer, afi, safi,
6246 PEER_FLAG_AS_PATH_UNCHANGED)) {
6247 ret |= peer_af_flag_unset_vty(
6248 vty, peer_str, afi, safi,
6249 PEER_FLAG_AS_PATH_UNCHANGED);
6250 }
6251 } else
6252 ret |= peer_af_flag_set_vty(
6253 vty, peer_str, afi, safi,
6254 PEER_FLAG_AS_PATH_UNCHANGED);
6255
6256 if (!nexthop) {
6257 if (peer_af_flag_check(peer, afi, safi,
6258 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6259 ret |= peer_af_flag_unset_vty(
6260 vty, peer_str, afi, safi,
6261 PEER_FLAG_NEXTHOP_UNCHANGED);
6262 }
6263 } else
6264 ret |= peer_af_flag_set_vty(
6265 vty, peer_str, afi, safi,
6266 PEER_FLAG_NEXTHOP_UNCHANGED);
6267
6268 if (!med) {
6269 if (peer_af_flag_check(peer, afi, safi,
6270 PEER_FLAG_MED_UNCHANGED)) {
6271 ret |= peer_af_flag_unset_vty(
6272 vty, peer_str, afi, safi,
6273 PEER_FLAG_MED_UNCHANGED);
6274 }
6275 } else
6276 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6277 PEER_FLAG_MED_UNCHANGED);
6278 }
6279
6280 return ret;
6281 }
6282
6283 ALIAS_HIDDEN(
6284 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6285 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6286 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6287 "BGP attribute is propagated unchanged to this neighbor\n"
6288 "As-path attribute\n"
6289 "Nexthop attribute\n"
6290 "Med attribute\n")
6291
6292 DEFUN (no_neighbor_attr_unchanged,
6293 no_neighbor_attr_unchanged_cmd,
6294 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6295 NO_STR
6296 NEIGHBOR_STR
6297 NEIGHBOR_ADDR_STR2
6298 "BGP attribute is propagated unchanged to this neighbor\n"
6299 "As-path attribute\n"
6300 "Nexthop attribute\n"
6301 "Med attribute\n")
6302 {
6303 int idx = 0;
6304 char *peer_str = argv[2]->arg;
6305 struct peer *peer;
6306 bool aspath = false;
6307 bool nexthop = false;
6308 bool med = false;
6309 afi_t afi = bgp_node_afi(vty);
6310 safi_t safi = bgp_node_safi(vty);
6311 int ret = 0;
6312
6313 peer = peer_and_group_lookup_vty(vty, peer_str);
6314 if (!peer)
6315 return CMD_WARNING_CONFIG_FAILED;
6316
6317 if (argv_find(argv, argc, "as-path", &idx))
6318 aspath = true;
6319
6320 idx = 0;
6321 if (argv_find(argv, argc, "next-hop", &idx))
6322 nexthop = true;
6323
6324 idx = 0;
6325 if (argv_find(argv, argc, "med", &idx))
6326 med = true;
6327
6328 if (!aspath && !nexthop && !med) // no flags means all of them!
6329 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6330 PEER_FLAG_AS_PATH_UNCHANGED)
6331 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6332 PEER_FLAG_NEXTHOP_UNCHANGED)
6333 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6334 PEER_FLAG_MED_UNCHANGED);
6335
6336 if (aspath)
6337 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6338 PEER_FLAG_AS_PATH_UNCHANGED);
6339
6340 if (nexthop)
6341 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6342 PEER_FLAG_NEXTHOP_UNCHANGED);
6343
6344 if (med)
6345 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6346 PEER_FLAG_MED_UNCHANGED);
6347
6348 return ret;
6349 }
6350
6351 ALIAS_HIDDEN(
6352 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6353 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6354 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6355 "BGP attribute is propagated unchanged to this neighbor\n"
6356 "As-path attribute\n"
6357 "Nexthop attribute\n"
6358 "Med attribute\n")
6359
6360 /* EBGP multihop configuration. */
6361 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6362 const char *ttl_str)
6363 {
6364 struct peer *peer;
6365 unsigned int ttl;
6366
6367 peer = peer_and_group_lookup_vty(vty, ip_str);
6368 if (!peer)
6369 return CMD_WARNING_CONFIG_FAILED;
6370
6371 if (peer->conf_if)
6372 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6373
6374 if (!ttl_str)
6375 ttl = MAXTTL;
6376 else
6377 ttl = strtoul(ttl_str, NULL, 10);
6378
6379 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6380 }
6381
6382 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6383 {
6384 struct peer *peer;
6385
6386 peer = peer_and_group_lookup_vty(vty, ip_str);
6387 if (!peer)
6388 return CMD_WARNING_CONFIG_FAILED;
6389
6390 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6391 }
6392
6393 /* neighbor ebgp-multihop. */
6394 DEFUN (neighbor_ebgp_multihop,
6395 neighbor_ebgp_multihop_cmd,
6396 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6397 NEIGHBOR_STR
6398 NEIGHBOR_ADDR_STR2
6399 "Allow EBGP neighbors not on directly connected networks\n")
6400 {
6401 int idx_peer = 1;
6402 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6403 }
6404
6405 DEFUN (neighbor_ebgp_multihop_ttl,
6406 neighbor_ebgp_multihop_ttl_cmd,
6407 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6408 NEIGHBOR_STR
6409 NEIGHBOR_ADDR_STR2
6410 "Allow EBGP neighbors not on directly connected networks\n"
6411 "maximum hop count\n")
6412 {
6413 int idx_peer = 1;
6414 int idx_number = 3;
6415 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6416 argv[idx_number]->arg);
6417 }
6418
6419 DEFUN (no_neighbor_ebgp_multihop,
6420 no_neighbor_ebgp_multihop_cmd,
6421 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6422 NO_STR
6423 NEIGHBOR_STR
6424 NEIGHBOR_ADDR_STR2
6425 "Allow EBGP neighbors not on directly connected networks\n"
6426 "maximum hop count\n")
6427 {
6428 int idx_peer = 2;
6429 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6430 }
6431
6432 static uint8_t get_role_by_name(const char *role_str)
6433 {
6434 if (strncmp(role_str, "peer", 2) == 0)
6435 return ROLE_PEER;
6436 if (strncmp(role_str, "provider", 2) == 0)
6437 return ROLE_PROVIDER;
6438 if (strncmp(role_str, "customer", 2) == 0)
6439 return ROLE_CUSTOMER;
6440 if (strncmp(role_str, "rs-server", 4) == 0)
6441 return ROLE_RS_SERVER;
6442 if (strncmp(role_str, "rs-client", 4) == 0)
6443 return ROLE_RS_CLIENT;
6444 return ROLE_UNDEFINED;
6445 }
6446
6447 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6448 const char *role_str, bool strict_mode)
6449 {
6450 struct peer *peer;
6451
6452 peer = peer_and_group_lookup_vty(vty, ip_str);
6453 if (!peer)
6454 return CMD_WARNING_CONFIG_FAILED;
6455 uint8_t role = get_role_by_name(role_str);
6456
6457 if (role == ROLE_UNDEFINED)
6458 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6459 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6460 }
6461
6462 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6463 {
6464 struct peer *peer;
6465
6466 peer = peer_and_group_lookup_vty(vty, ip_str);
6467 if (!peer)
6468 return CMD_WARNING_CONFIG_FAILED;
6469 return bgp_vty_return(vty, peer_role_unset(peer));
6470 }
6471
6472 DEFPY(neighbor_role,
6473 neighbor_role_cmd,
6474 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6475 NEIGHBOR_STR
6476 NEIGHBOR_ADDR_STR2
6477 "Set session role\n"
6478 ROLE_STR)
6479 {
6480 int idx_peer = 1;
6481 int idx_role = 3;
6482
6483 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6484 false);
6485 }
6486
6487 DEFPY(neighbor_role_strict,
6488 neighbor_role_strict_cmd,
6489 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6490 NEIGHBOR_STR
6491 NEIGHBOR_ADDR_STR2
6492 "Set session role\n"
6493 ROLE_STR
6494 "Use additional restriction on peer\n")
6495 {
6496 int idx_peer = 1;
6497 int idx_role = 3;
6498
6499 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6500 true);
6501 }
6502
6503 DEFPY(no_neighbor_role,
6504 no_neighbor_role_cmd,
6505 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6506 NO_STR
6507 NEIGHBOR_STR
6508 NEIGHBOR_ADDR_STR2
6509 "Set session role\n"
6510 ROLE_STR
6511 "Use additional restriction on peer\n")
6512 {
6513 int idx_peer = 2;
6514
6515 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6516 }
6517
6518 /* disable-connected-check */
6519 DEFUN (neighbor_disable_connected_check,
6520 neighbor_disable_connected_check_cmd,
6521 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6522 NEIGHBOR_STR
6523 NEIGHBOR_ADDR_STR2
6524 "one-hop away EBGP peer using loopback address\n"
6525 "Enforce EBGP neighbors perform multihop\n")
6526 {
6527 int idx_peer = 1;
6528 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6529 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6530 }
6531
6532 DEFUN (no_neighbor_disable_connected_check,
6533 no_neighbor_disable_connected_check_cmd,
6534 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6535 NO_STR
6536 NEIGHBOR_STR
6537 NEIGHBOR_ADDR_STR2
6538 "one-hop away EBGP peer using loopback address\n"
6539 "Enforce EBGP neighbors perform multihop\n")
6540 {
6541 int idx_peer = 2;
6542 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6543 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6544 }
6545
6546 /* disable-link-bw-encoding-ieee */
6547 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6548 neighbor_disable_link_bw_encoding_ieee_cmd,
6549 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6550 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6551 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6552 {
6553 int idx_peer = 1;
6554
6555 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6556 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6557 }
6558
6559 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6560 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6561 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6562 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6563 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6564 {
6565 int idx_peer = 2;
6566
6567 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6568 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6569 }
6570
6571 /* extended-optional-parameters */
6572 DEFUN(neighbor_extended_optional_parameters,
6573 neighbor_extended_optional_parameters_cmd,
6574 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6575 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6576 "Force the extended optional parameters format for OPEN messages\n")
6577 {
6578 int idx_peer = 1;
6579
6580 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6581 PEER_FLAG_EXTENDED_OPT_PARAMS);
6582 }
6583
6584 DEFUN(no_neighbor_extended_optional_parameters,
6585 no_neighbor_extended_optional_parameters_cmd,
6586 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6587 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6588 "Force the extended optional parameters format for OPEN messages\n")
6589 {
6590 int idx_peer = 2;
6591
6592 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6593 PEER_FLAG_EXTENDED_OPT_PARAMS);
6594 }
6595
6596 /* enforce-first-as */
6597 DEFUN (neighbor_enforce_first_as,
6598 neighbor_enforce_first_as_cmd,
6599 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6600 NEIGHBOR_STR
6601 NEIGHBOR_ADDR_STR2
6602 "Enforce the first AS for EBGP routes\n")
6603 {
6604 int idx_peer = 1;
6605
6606 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6607 PEER_FLAG_ENFORCE_FIRST_AS);
6608 }
6609
6610 DEFUN (no_neighbor_enforce_first_as,
6611 no_neighbor_enforce_first_as_cmd,
6612 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6613 NO_STR
6614 NEIGHBOR_STR
6615 NEIGHBOR_ADDR_STR2
6616 "Enforce the first AS for EBGP routes\n")
6617 {
6618 int idx_peer = 2;
6619
6620 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6621 PEER_FLAG_ENFORCE_FIRST_AS);
6622 }
6623
6624
6625 DEFUN (neighbor_description,
6626 neighbor_description_cmd,
6627 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6628 NEIGHBOR_STR
6629 NEIGHBOR_ADDR_STR2
6630 "Neighbor specific description\n"
6631 "Up to 80 characters describing this neighbor\n")
6632 {
6633 int idx_peer = 1;
6634 int idx_line = 3;
6635 struct peer *peer;
6636 char *str;
6637
6638 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6639 if (!peer)
6640 return CMD_WARNING_CONFIG_FAILED;
6641
6642 str = argv_concat(argv, argc, idx_line);
6643
6644 peer_description_set(peer, str);
6645
6646 XFREE(MTYPE_TMP, str);
6647
6648 return CMD_SUCCESS;
6649 }
6650
6651 DEFUN (no_neighbor_description,
6652 no_neighbor_description_cmd,
6653 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6654 NO_STR
6655 NEIGHBOR_STR
6656 NEIGHBOR_ADDR_STR2
6657 "Neighbor specific description\n")
6658 {
6659 int idx_peer = 2;
6660 struct peer *peer;
6661
6662 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6663 if (!peer)
6664 return CMD_WARNING_CONFIG_FAILED;
6665
6666 peer_description_unset(peer);
6667
6668 return CMD_SUCCESS;
6669 }
6670
6671 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6672 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6674 "Neighbor specific description\n"
6675 "Up to 80 characters describing this neighbor\n")
6676
6677 /* Neighbor update-source. */
6678 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6679 const char *source_str)
6680 {
6681 struct peer *peer;
6682 struct prefix p;
6683 union sockunion su;
6684
6685 peer = peer_and_group_lookup_vty(vty, peer_str);
6686 if (!peer)
6687 return CMD_WARNING_CONFIG_FAILED;
6688
6689 if (peer->conf_if)
6690 return CMD_WARNING;
6691
6692 if (source_str) {
6693 if (str2sockunion(source_str, &su) == 0)
6694 peer_update_source_addr_set(peer, &su);
6695 else {
6696 if (str2prefix(source_str, &p)) {
6697 vty_out(vty,
6698 "%% Invalid update-source, remove prefix length \n");
6699 return CMD_WARNING_CONFIG_FAILED;
6700 } else
6701 peer_update_source_if_set(peer, source_str);
6702 }
6703 } else
6704 peer_update_source_unset(peer);
6705
6706 return CMD_SUCCESS;
6707 }
6708
6709 #define BGP_UPDATE_SOURCE_HELP_STR \
6710 "IPv4 address\n" \
6711 "IPv6 address\n" \
6712 "Interface name (requires zebra to be running)\n"
6713
6714 DEFUN (neighbor_update_source,
6715 neighbor_update_source_cmd,
6716 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6717 NEIGHBOR_STR
6718 NEIGHBOR_ADDR_STR2
6719 "Source of routing updates\n"
6720 BGP_UPDATE_SOURCE_HELP_STR)
6721 {
6722 int idx_peer = 1;
6723 int idx_peer_2 = 3;
6724 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6725 argv[idx_peer_2]->arg);
6726 }
6727
6728 DEFUN (no_neighbor_update_source,
6729 no_neighbor_update_source_cmd,
6730 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6731 NO_STR
6732 NEIGHBOR_STR
6733 NEIGHBOR_ADDR_STR2
6734 "Source of routing updates\n"
6735 BGP_UPDATE_SOURCE_HELP_STR)
6736 {
6737 int idx_peer = 2;
6738 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6739 }
6740
6741 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6742 afi_t afi, safi_t safi,
6743 const char *rmap, int set)
6744 {
6745 int ret;
6746 struct peer *peer;
6747 struct route_map *route_map = NULL;
6748
6749 peer = peer_and_group_lookup_vty(vty, peer_str);
6750 if (!peer)
6751 return CMD_WARNING_CONFIG_FAILED;
6752
6753 if (set) {
6754 if (rmap)
6755 route_map = route_map_lookup_warn_noexist(vty, rmap);
6756 ret = peer_default_originate_set(peer, afi, safi,
6757 rmap, route_map);
6758 } else
6759 ret = peer_default_originate_unset(peer, afi, safi);
6760
6761 return bgp_vty_return(vty, ret);
6762 }
6763
6764 /* neighbor default-originate. */
6765 DEFUN (neighbor_default_originate,
6766 neighbor_default_originate_cmd,
6767 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6768 NEIGHBOR_STR
6769 NEIGHBOR_ADDR_STR2
6770 "Originate default route to this neighbor\n")
6771 {
6772 int idx_peer = 1;
6773 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6774 bgp_node_afi(vty),
6775 bgp_node_safi(vty), NULL, 1);
6776 }
6777
6778 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6779 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6780 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6781 "Originate default route to this neighbor\n")
6782
6783 DEFUN (neighbor_default_originate_rmap,
6784 neighbor_default_originate_rmap_cmd,
6785 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6786 NEIGHBOR_STR
6787 NEIGHBOR_ADDR_STR2
6788 "Originate default route to this neighbor\n"
6789 "Route-map to specify criteria to originate default\n"
6790 "route-map name\n")
6791 {
6792 int idx_peer = 1;
6793 int idx_word = 4;
6794 return peer_default_originate_set_vty(
6795 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6796 argv[idx_word]->arg, 1);
6797 }
6798
6799 ALIAS_HIDDEN(
6800 neighbor_default_originate_rmap,
6801 neighbor_default_originate_rmap_hidden_cmd,
6802 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6804 "Originate default route to this neighbor\n"
6805 "Route-map to specify criteria to originate default\n"
6806 "route-map name\n")
6807
6808 DEFUN (no_neighbor_default_originate,
6809 no_neighbor_default_originate_cmd,
6810 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6811 NO_STR
6812 NEIGHBOR_STR
6813 NEIGHBOR_ADDR_STR2
6814 "Originate default route to this neighbor\n"
6815 "Route-map to specify criteria to originate default\n"
6816 "route-map name\n")
6817 {
6818 int idx_peer = 2;
6819 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6820 bgp_node_afi(vty),
6821 bgp_node_safi(vty), NULL, 0);
6822 }
6823
6824 ALIAS_HIDDEN(
6825 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6826 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6828 "Originate default route to this neighbor\n"
6829 "Route-map to specify criteria to originate default\n"
6830 "route-map name\n")
6831
6832
6833 /* Set neighbor's BGP port. */
6834 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6835 const char *port_str)
6836 {
6837 struct peer *peer;
6838 uint16_t port;
6839 struct servent *sp;
6840
6841 peer = peer_lookup_vty(vty, ip_str);
6842 if (!peer)
6843 return CMD_WARNING_CONFIG_FAILED;
6844
6845 if (!port_str) {
6846 sp = getservbyname("bgp", "tcp");
6847 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6848 } else {
6849 port = strtoul(port_str, NULL, 10);
6850 }
6851
6852 peer_port_set(peer, port);
6853
6854 return CMD_SUCCESS;
6855 }
6856
6857 /* Set specified peer's BGP port. */
6858 DEFUN (neighbor_port,
6859 neighbor_port_cmd,
6860 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6861 NEIGHBOR_STR
6862 NEIGHBOR_ADDR_STR
6863 "Neighbor's BGP port\n"
6864 "TCP port number\n")
6865 {
6866 int idx_ip = 1;
6867 int idx_number = 3;
6868 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6869 argv[idx_number]->arg);
6870 }
6871
6872 DEFUN (no_neighbor_port,
6873 no_neighbor_port_cmd,
6874 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6875 NO_STR
6876 NEIGHBOR_STR
6877 NEIGHBOR_ADDR_STR
6878 "Neighbor's BGP port\n"
6879 "TCP port number\n")
6880 {
6881 int idx_ip = 2;
6882 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6883 }
6884
6885
6886 /* neighbor weight. */
6887 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6888 safi_t safi, const char *weight_str)
6889 {
6890 int ret;
6891 struct peer *peer;
6892 unsigned long weight;
6893
6894 peer = peer_and_group_lookup_vty(vty, ip_str);
6895 if (!peer)
6896 return CMD_WARNING_CONFIG_FAILED;
6897
6898 weight = strtoul(weight_str, NULL, 10);
6899
6900 ret = peer_weight_set(peer, afi, safi, weight);
6901 return bgp_vty_return(vty, ret);
6902 }
6903
6904 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6905 safi_t safi)
6906 {
6907 int ret;
6908 struct peer *peer;
6909
6910 peer = peer_and_group_lookup_vty(vty, ip_str);
6911 if (!peer)
6912 return CMD_WARNING_CONFIG_FAILED;
6913
6914 ret = peer_weight_unset(peer, afi, safi);
6915 return bgp_vty_return(vty, ret);
6916 }
6917
6918 DEFUN (neighbor_weight,
6919 neighbor_weight_cmd,
6920 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6921 NEIGHBOR_STR
6922 NEIGHBOR_ADDR_STR2
6923 "Set default weight for routes from this neighbor\n"
6924 "default weight\n")
6925 {
6926 int idx_peer = 1;
6927 int idx_number = 3;
6928 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6929 bgp_node_safi(vty), argv[idx_number]->arg);
6930 }
6931
6932 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6933 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6935 "Set default weight for routes from this neighbor\n"
6936 "default weight\n")
6937
6938 DEFUN (no_neighbor_weight,
6939 no_neighbor_weight_cmd,
6940 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6941 NO_STR
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 = 2;
6948 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6949 bgp_node_afi(vty), bgp_node_safi(vty));
6950 }
6951
6952 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6953 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6954 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6955 "Set default weight for routes from this neighbor\n"
6956 "default weight\n")
6957
6958
6959 /* Override capability negotiation. */
6960 DEFUN (neighbor_override_capability,
6961 neighbor_override_capability_cmd,
6962 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6963 NEIGHBOR_STR
6964 NEIGHBOR_ADDR_STR2
6965 "Override capability negotiation result\n")
6966 {
6967 int idx_peer = 1;
6968 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6969 PEER_FLAG_OVERRIDE_CAPABILITY);
6970 }
6971
6972 DEFUN (no_neighbor_override_capability,
6973 no_neighbor_override_capability_cmd,
6974 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6975 NO_STR
6976 NEIGHBOR_STR
6977 NEIGHBOR_ADDR_STR2
6978 "Override capability negotiation result\n")
6979 {
6980 int idx_peer = 2;
6981 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6982 PEER_FLAG_OVERRIDE_CAPABILITY);
6983 }
6984
6985 DEFUN (neighbor_strict_capability,
6986 neighbor_strict_capability_cmd,
6987 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6988 NEIGHBOR_STR
6989 NEIGHBOR_ADDR_STR2
6990 "Strict capability negotiation match\n")
6991 {
6992 int idx_peer = 1;
6993
6994 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6995 PEER_FLAG_STRICT_CAP_MATCH);
6996 }
6997
6998 DEFUN (no_neighbor_strict_capability,
6999 no_neighbor_strict_capability_cmd,
7000 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7001 NO_STR
7002 NEIGHBOR_STR
7003 NEIGHBOR_ADDR_STR2
7004 "Strict capability negotiation match\n")
7005 {
7006 int idx_peer = 2;
7007
7008 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7009 PEER_FLAG_STRICT_CAP_MATCH);
7010 }
7011
7012 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7013 const char *keep_str, const char *hold_str)
7014 {
7015 int ret;
7016 struct peer *peer;
7017 uint32_t keepalive;
7018 uint32_t holdtime;
7019
7020 peer = peer_and_group_lookup_vty(vty, ip_str);
7021 if (!peer)
7022 return CMD_WARNING_CONFIG_FAILED;
7023
7024 keepalive = strtoul(keep_str, NULL, 10);
7025 holdtime = strtoul(hold_str, NULL, 10);
7026
7027 ret = peer_timers_set(peer, keepalive, holdtime);
7028
7029 return bgp_vty_return(vty, ret);
7030 }
7031
7032 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7033 {
7034 int ret;
7035 struct peer *peer;
7036
7037 peer = peer_and_group_lookup_vty(vty, ip_str);
7038 if (!peer)
7039 return CMD_WARNING_CONFIG_FAILED;
7040
7041 ret = peer_timers_unset(peer);
7042
7043 return bgp_vty_return(vty, ret);
7044 }
7045
7046 DEFUN (neighbor_timers,
7047 neighbor_timers_cmd,
7048 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7049 NEIGHBOR_STR
7050 NEIGHBOR_ADDR_STR2
7051 "BGP per neighbor timers\n"
7052 "Keepalive interval\n"
7053 "Holdtime\n")
7054 {
7055 int idx_peer = 1;
7056 int idx_number = 3;
7057 int idx_number_2 = 4;
7058 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7059 argv[idx_number]->arg,
7060 argv[idx_number_2]->arg);
7061 }
7062
7063 DEFUN (no_neighbor_timers,
7064 no_neighbor_timers_cmd,
7065 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7066 NO_STR
7067 NEIGHBOR_STR
7068 NEIGHBOR_ADDR_STR2
7069 "BGP per neighbor timers\n"
7070 "Keepalive interval\n"
7071 "Holdtime\n")
7072 {
7073 int idx_peer = 2;
7074 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7075 }
7076
7077
7078 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7079 const char *time_str)
7080 {
7081 int ret;
7082 struct peer *peer;
7083 uint32_t connect;
7084
7085 peer = peer_and_group_lookup_vty(vty, ip_str);
7086 if (!peer)
7087 return CMD_WARNING_CONFIG_FAILED;
7088
7089 connect = strtoul(time_str, NULL, 10);
7090
7091 ret = peer_timers_connect_set(peer, connect);
7092
7093 return bgp_vty_return(vty, ret);
7094 }
7095
7096 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7097 {
7098 int ret;
7099 struct peer *peer;
7100
7101 peer = peer_and_group_lookup_vty(vty, ip_str);
7102 if (!peer)
7103 return CMD_WARNING_CONFIG_FAILED;
7104
7105 ret = peer_timers_connect_unset(peer);
7106
7107 return bgp_vty_return(vty, ret);
7108 }
7109
7110 DEFUN (neighbor_timers_connect,
7111 neighbor_timers_connect_cmd,
7112 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7113 NEIGHBOR_STR
7114 NEIGHBOR_ADDR_STR2
7115 "BGP per neighbor timers\n"
7116 "BGP connect timer\n"
7117 "Connect timer\n")
7118 {
7119 int idx_peer = 1;
7120 int idx_number = 4;
7121 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7122 argv[idx_number]->arg);
7123 }
7124
7125 DEFUN (no_neighbor_timers_connect,
7126 no_neighbor_timers_connect_cmd,
7127 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7128 NO_STR
7129 NEIGHBOR_STR
7130 NEIGHBOR_ADDR_STR2
7131 "BGP per neighbor timers\n"
7132 "BGP connect timer\n"
7133 "Connect timer\n")
7134 {
7135 int idx_peer = 2;
7136 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7137 }
7138
7139 DEFPY (neighbor_timers_delayopen,
7140 neighbor_timers_delayopen_cmd,
7141 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7142 NEIGHBOR_STR
7143 NEIGHBOR_ADDR_STR2
7144 "BGP per neighbor timers\n"
7145 "RFC 4271 DelayOpenTimer\n"
7146 "DelayOpenTime timer interval\n")
7147 {
7148 struct peer *peer;
7149
7150 peer = peer_and_group_lookup_vty(vty, neighbor);
7151 if (!peer)
7152 return CMD_WARNING_CONFIG_FAILED;
7153
7154 if (!interval) {
7155 if (peer_timers_delayopen_unset(peer))
7156 return CMD_WARNING_CONFIG_FAILED;
7157 } else {
7158 if (peer_timers_delayopen_set(peer, interval))
7159 return CMD_WARNING_CONFIG_FAILED;
7160 }
7161
7162 return CMD_SUCCESS;
7163 }
7164
7165 DEFPY (no_neighbor_timers_delayopen,
7166 no_neighbor_timers_delayopen_cmd,
7167 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7168 NO_STR
7169 NEIGHBOR_STR
7170 NEIGHBOR_ADDR_STR2
7171 "BGP per neighbor timers\n"
7172 "RFC 4271 DelayOpenTimer\n"
7173 "DelayOpenTime timer interval\n")
7174 {
7175 struct peer *peer;
7176
7177 peer = peer_and_group_lookup_vty(vty, neighbor);
7178 if (!peer)
7179 return CMD_WARNING_CONFIG_FAILED;
7180
7181 if (peer_timers_delayopen_unset(peer))
7182 return CMD_WARNING_CONFIG_FAILED;
7183
7184 return CMD_SUCCESS;
7185 }
7186
7187 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7188 const char *time_str, int set)
7189 {
7190 int ret;
7191 struct peer *peer;
7192 uint32_t routeadv = 0;
7193
7194 peer = peer_and_group_lookup_vty(vty, ip_str);
7195 if (!peer)
7196 return CMD_WARNING_CONFIG_FAILED;
7197
7198 if (time_str)
7199 routeadv = strtoul(time_str, NULL, 10);
7200
7201 if (set)
7202 ret = peer_advertise_interval_set(peer, routeadv);
7203 else
7204 ret = peer_advertise_interval_unset(peer);
7205
7206 return bgp_vty_return(vty, ret);
7207 }
7208
7209 DEFUN (neighbor_advertise_interval,
7210 neighbor_advertise_interval_cmd,
7211 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7212 NEIGHBOR_STR
7213 NEIGHBOR_ADDR_STR2
7214 "Minimum interval between sending BGP routing updates\n"
7215 "time in seconds\n")
7216 {
7217 int idx_peer = 1;
7218 int idx_number = 3;
7219 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7220 argv[idx_number]->arg, 1);
7221 }
7222
7223 DEFUN (no_neighbor_advertise_interval,
7224 no_neighbor_advertise_interval_cmd,
7225 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7226 NO_STR
7227 NEIGHBOR_STR
7228 NEIGHBOR_ADDR_STR2
7229 "Minimum interval between sending BGP routing updates\n"
7230 "time in seconds\n")
7231 {
7232 int idx_peer = 2;
7233 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7234 }
7235
7236
7237 /* Time to wait before processing route-map updates */
7238 DEFUN (bgp_set_route_map_delay_timer,
7239 bgp_set_route_map_delay_timer_cmd,
7240 "bgp route-map delay-timer (0-600)",
7241 SET_STR
7242 "BGP route-map delay timer\n"
7243 "Time in secs to wait before processing route-map changes\n"
7244 "0 disables the timer, no route updates happen when route-maps change\n")
7245 {
7246 int idx_number = 3;
7247 uint32_t rmap_delay_timer;
7248
7249 if (argv[idx_number]->arg) {
7250 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7251 bm->rmap_update_timer = rmap_delay_timer;
7252
7253 /* if the dynamic update handling is being disabled, and a timer
7254 * is
7255 * running, stop the timer and act as if the timer has already
7256 * fired.
7257 */
7258 if (!rmap_delay_timer && bm->t_rmap_update) {
7259 BGP_TIMER_OFF(bm->t_rmap_update);
7260 thread_execute(bm->master, bgp_route_map_update_timer,
7261 NULL, 0);
7262 }
7263 return CMD_SUCCESS;
7264 } else {
7265 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7266 return CMD_WARNING_CONFIG_FAILED;
7267 }
7268 }
7269
7270 DEFUN (no_bgp_set_route_map_delay_timer,
7271 no_bgp_set_route_map_delay_timer_cmd,
7272 "no bgp route-map delay-timer [(0-600)]",
7273 NO_STR
7274 BGP_STR
7275 "Default BGP route-map delay timer\n"
7276 "Reset to default time to wait for processing route-map changes\n"
7277 "0 disables the timer, no route updates happen when route-maps change\n")
7278 {
7279
7280 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7281
7282 return CMD_SUCCESS;
7283 }
7284
7285 /* neighbor interface */
7286 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7287 const char *str)
7288 {
7289 struct peer *peer;
7290
7291 peer = peer_lookup_vty(vty, ip_str);
7292 if (!peer || peer->conf_if) {
7293 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7294 return CMD_WARNING_CONFIG_FAILED;
7295 }
7296
7297 if (str)
7298 peer_interface_set(peer, str);
7299 else
7300 peer_interface_unset(peer);
7301
7302 return CMD_SUCCESS;
7303 }
7304
7305 DEFUN (neighbor_interface,
7306 neighbor_interface_cmd,
7307 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7308 NEIGHBOR_STR
7309 NEIGHBOR_ADDR_STR
7310 "Interface\n"
7311 "Interface name\n")
7312 {
7313 int idx_ip = 1;
7314 int idx_word = 3;
7315
7316 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7317 }
7318
7319 DEFUN (no_neighbor_interface,
7320 no_neighbor_interface_cmd,
7321 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7322 NO_STR
7323 NEIGHBOR_STR
7324 NEIGHBOR_ADDR_STR
7325 "Interface\n"
7326 "Interface name\n")
7327 {
7328 int idx_peer = 2;
7329
7330 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7331 }
7332
7333 DEFUN (neighbor_distribute_list,
7334 neighbor_distribute_list_cmd,
7335 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7336 NEIGHBOR_STR
7337 NEIGHBOR_ADDR_STR2
7338 "Filter updates to/from this neighbor\n"
7339 "IP Access-list name\n"
7340 "Filter incoming updates\n"
7341 "Filter outgoing updates\n")
7342 {
7343 int idx_peer = 1;
7344 int idx_acl = 3;
7345 int direct, ret;
7346 struct peer *peer;
7347
7348 const char *pstr = argv[idx_peer]->arg;
7349 const char *acl = argv[idx_acl]->arg;
7350 const char *inout = argv[argc - 1]->text;
7351
7352 peer = peer_and_group_lookup_vty(vty, pstr);
7353 if (!peer)
7354 return CMD_WARNING_CONFIG_FAILED;
7355
7356 /* Check filter direction. */
7357 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7358 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7359 direct, acl);
7360
7361 return bgp_vty_return(vty, ret);
7362 }
7363
7364 ALIAS_HIDDEN(
7365 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7366 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7367 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7368 "Filter updates to/from this neighbor\n"
7369 "IP Access-list name\n"
7370 "Filter incoming updates\n"
7371 "Filter outgoing updates\n")
7372
7373 DEFUN (no_neighbor_distribute_list,
7374 no_neighbor_distribute_list_cmd,
7375 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7376 NO_STR
7377 NEIGHBOR_STR
7378 NEIGHBOR_ADDR_STR2
7379 "Filter updates to/from this neighbor\n"
7380 "IP Access-list name\n"
7381 "Filter incoming updates\n"
7382 "Filter outgoing updates\n")
7383 {
7384 int idx_peer = 2;
7385 int direct, ret;
7386 struct peer *peer;
7387
7388 const char *pstr = argv[idx_peer]->arg;
7389 const char *inout = argv[argc - 1]->text;
7390
7391 peer = peer_and_group_lookup_vty(vty, pstr);
7392 if (!peer)
7393 return CMD_WARNING_CONFIG_FAILED;
7394
7395 /* Check filter direction. */
7396 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7397 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7398 direct);
7399
7400 return bgp_vty_return(vty, ret);
7401 }
7402
7403 ALIAS_HIDDEN(
7404 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7405 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7406 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7407 "Filter updates to/from this neighbor\n"
7408 "IP Access-list name\n"
7409 "Filter incoming updates\n"
7410 "Filter outgoing updates\n")
7411
7412 /* Set prefix list to the peer. */
7413 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7414 afi_t afi, safi_t safi,
7415 const char *name_str,
7416 const char *direct_str)
7417 {
7418 int ret;
7419 int direct = FILTER_IN;
7420 struct peer *peer;
7421
7422 peer = peer_and_group_lookup_vty(vty, ip_str);
7423 if (!peer)
7424 return CMD_WARNING_CONFIG_FAILED;
7425
7426 /* Check filter direction. */
7427 if (strncmp(direct_str, "i", 1) == 0)
7428 direct = FILTER_IN;
7429 else if (strncmp(direct_str, "o", 1) == 0)
7430 direct = FILTER_OUT;
7431
7432 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7433
7434 return bgp_vty_return(vty, ret);
7435 }
7436
7437 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7438 afi_t afi, safi_t safi,
7439 const char *direct_str)
7440 {
7441 int ret;
7442 struct peer *peer;
7443 int direct = FILTER_IN;
7444
7445 peer = peer_and_group_lookup_vty(vty, ip_str);
7446 if (!peer)
7447 return CMD_WARNING_CONFIG_FAILED;
7448
7449 /* Check filter direction. */
7450 if (strncmp(direct_str, "i", 1) == 0)
7451 direct = FILTER_IN;
7452 else if (strncmp(direct_str, "o", 1) == 0)
7453 direct = FILTER_OUT;
7454
7455 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7456
7457 return bgp_vty_return(vty, ret);
7458 }
7459
7460 DEFUN (neighbor_prefix_list,
7461 neighbor_prefix_list_cmd,
7462 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7463 NEIGHBOR_STR
7464 NEIGHBOR_ADDR_STR2
7465 "Filter updates to/from this neighbor\n"
7466 "Name of a prefix list\n"
7467 "Filter incoming updates\n"
7468 "Filter outgoing updates\n")
7469 {
7470 int idx_peer = 1;
7471 int idx_word = 3;
7472 int idx_in_out = 4;
7473 return peer_prefix_list_set_vty(
7474 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7475 argv[idx_word]->arg, argv[idx_in_out]->arg);
7476 }
7477
7478 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7479 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7480 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7481 "Filter updates to/from this neighbor\n"
7482 "Name of a prefix list\n"
7483 "Filter incoming updates\n"
7484 "Filter outgoing updates\n")
7485
7486 DEFUN (no_neighbor_prefix_list,
7487 no_neighbor_prefix_list_cmd,
7488 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7489 NO_STR
7490 NEIGHBOR_STR
7491 NEIGHBOR_ADDR_STR2
7492 "Filter updates to/from this neighbor\n"
7493 "Name of a prefix list\n"
7494 "Filter incoming updates\n"
7495 "Filter outgoing updates\n")
7496 {
7497 int idx_peer = 2;
7498 int idx_in_out = 5;
7499 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7500 bgp_node_afi(vty), bgp_node_safi(vty),
7501 argv[idx_in_out]->arg);
7502 }
7503
7504 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7505 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7506 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7507 "Filter updates to/from this neighbor\n"
7508 "Name of a prefix list\n"
7509 "Filter incoming updates\n"
7510 "Filter outgoing updates\n")
7511
7512 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7513 safi_t safi, const char *name_str,
7514 const char *direct_str)
7515 {
7516 int ret;
7517 struct peer *peer;
7518 int direct = FILTER_IN;
7519
7520 peer = peer_and_group_lookup_vty(vty, ip_str);
7521 if (!peer)
7522 return CMD_WARNING_CONFIG_FAILED;
7523
7524 /* Check filter direction. */
7525 if (strncmp(direct_str, "i", 1) == 0)
7526 direct = FILTER_IN;
7527 else if (strncmp(direct_str, "o", 1) == 0)
7528 direct = FILTER_OUT;
7529
7530 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7531
7532 return bgp_vty_return(vty, ret);
7533 }
7534
7535 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7536 safi_t safi, const char *direct_str)
7537 {
7538 int ret;
7539 struct peer *peer;
7540 int direct = FILTER_IN;
7541
7542 peer = peer_and_group_lookup_vty(vty, ip_str);
7543 if (!peer)
7544 return CMD_WARNING_CONFIG_FAILED;
7545
7546 /* Check filter direction. */
7547 if (strncmp(direct_str, "i", 1) == 0)
7548 direct = FILTER_IN;
7549 else if (strncmp(direct_str, "o", 1) == 0)
7550 direct = FILTER_OUT;
7551
7552 ret = peer_aslist_unset(peer, afi, safi, direct);
7553
7554 return bgp_vty_return(vty, ret);
7555 }
7556
7557 DEFUN (neighbor_filter_list,
7558 neighbor_filter_list_cmd,
7559 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7560 NEIGHBOR_STR
7561 NEIGHBOR_ADDR_STR2
7562 "Establish BGP filters\n"
7563 "AS path access-list name\n"
7564 "Filter incoming routes\n"
7565 "Filter outgoing routes\n")
7566 {
7567 int idx_peer = 1;
7568 int idx_word = 3;
7569 int idx_in_out = 4;
7570 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7571 bgp_node_safi(vty), argv[idx_word]->arg,
7572 argv[idx_in_out]->arg);
7573 }
7574
7575 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7576 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7578 "Establish BGP filters\n"
7579 "AS path access-list name\n"
7580 "Filter incoming routes\n"
7581 "Filter outgoing routes\n")
7582
7583 DEFUN (no_neighbor_filter_list,
7584 no_neighbor_filter_list_cmd,
7585 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7586 NO_STR
7587 NEIGHBOR_STR
7588 NEIGHBOR_ADDR_STR2
7589 "Establish BGP filters\n"
7590 "AS path access-list name\n"
7591 "Filter incoming routes\n"
7592 "Filter outgoing routes\n")
7593 {
7594 int idx_peer = 2;
7595 int idx_in_out = 5;
7596 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7597 bgp_node_afi(vty), bgp_node_safi(vty),
7598 argv[idx_in_out]->arg);
7599 }
7600
7601 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7602 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7603 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7604 "Establish BGP filters\n"
7605 "AS path access-list name\n"
7606 "Filter incoming routes\n"
7607 "Filter outgoing routes\n")
7608
7609 /* Set advertise-map to the peer. */
7610 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7611 afi_t afi, safi_t safi,
7612 const char *advertise_str,
7613 const char *condition_str, bool condition,
7614 bool set)
7615 {
7616 int ret = CMD_WARNING_CONFIG_FAILED;
7617 struct peer *peer;
7618 struct route_map *advertise_map;
7619 struct route_map *condition_map;
7620
7621 peer = peer_and_group_lookup_vty(vty, ip_str);
7622 if (!peer)
7623 return ret;
7624
7625 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7626 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7627
7628 if (set)
7629 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7630 advertise_map, condition_str,
7631 condition_map, condition);
7632 else
7633 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7634 advertise_map, condition_str,
7635 condition_map, condition);
7636
7637 return bgp_vty_return(vty, ret);
7638 }
7639
7640 DEFPY (bgp_condadv_period,
7641 bgp_condadv_period_cmd,
7642 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7643 NO_STR
7644 BGP_STR
7645 "Conditional advertisement settings\n"
7646 "Set period to rescan BGP table to check if condition is met\n"
7647 "Period between BGP table scans, in seconds; default 60\n")
7648 {
7649 VTY_DECLVAR_CONTEXT(bgp, bgp);
7650
7651 bgp->condition_check_period =
7652 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7653
7654 return CMD_SUCCESS;
7655 }
7656
7657 DEFPY (neighbor_advertise_map,
7658 neighbor_advertise_map_cmd,
7659 "[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",
7660 NO_STR
7661 NEIGHBOR_STR
7662 NEIGHBOR_ADDR_STR2
7663 "Route-map to conditionally advertise routes\n"
7664 "Name of advertise map\n"
7665 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7666 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7667 "Name of the exist or non exist map\n")
7668 {
7669 bool condition = CONDITION_EXIST;
7670
7671 if (!strcmp(exist, "non-exist-map"))
7672 condition = CONDITION_NON_EXIST;
7673
7674 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7675 bgp_node_safi(vty), advertise_str,
7676 condition_str, condition, !no);
7677 }
7678
7679 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_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 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7682 "Route-map to conditionally advertise routes\n"
7683 "Name of advertise map\n"
7684 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7685 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7686 "Name of the exist or non exist map\n")
7687
7688 /* Set route-map to the peer. */
7689 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7690 afi_t afi, safi_t safi, const char *name_str,
7691 const char *direct_str)
7692 {
7693 int ret;
7694 struct peer *peer;
7695 int direct = RMAP_IN;
7696 struct route_map *route_map;
7697
7698 peer = peer_and_group_lookup_vty(vty, ip_str);
7699 if (!peer)
7700 return CMD_WARNING_CONFIG_FAILED;
7701
7702 /* Check filter direction. */
7703 if (strncmp(direct_str, "in", 2) == 0)
7704 direct = RMAP_IN;
7705 else if (strncmp(direct_str, "o", 1) == 0)
7706 direct = RMAP_OUT;
7707
7708 route_map = route_map_lookup_warn_noexist(vty, name_str);
7709 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7710
7711 return bgp_vty_return(vty, ret);
7712 }
7713
7714 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7715 afi_t afi, safi_t safi,
7716 const char *direct_str)
7717 {
7718 int ret;
7719 struct peer *peer;
7720 int direct = RMAP_IN;
7721
7722 peer = peer_and_group_lookup_vty(vty, ip_str);
7723 if (!peer)
7724 return CMD_WARNING_CONFIG_FAILED;
7725
7726 /* Check filter direction. */
7727 if (strncmp(direct_str, "in", 2) == 0)
7728 direct = RMAP_IN;
7729 else if (strncmp(direct_str, "o", 1) == 0)
7730 direct = RMAP_OUT;
7731
7732 ret = peer_route_map_unset(peer, afi, safi, direct);
7733
7734 return bgp_vty_return(vty, ret);
7735 }
7736
7737 DEFUN (neighbor_route_map,
7738 neighbor_route_map_cmd,
7739 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7740 NEIGHBOR_STR
7741 NEIGHBOR_ADDR_STR2
7742 "Apply route map to neighbor\n"
7743 "Name of route map\n"
7744 "Apply map to incoming routes\n"
7745 "Apply map to outbound routes\n")
7746 {
7747 int idx_peer = 1;
7748 int idx_word = 3;
7749 int idx_in_out = 4;
7750 return peer_route_map_set_vty(
7751 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7752 argv[idx_word]->arg, argv[idx_in_out]->arg);
7753 }
7754
7755 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7756 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7757 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7758 "Apply route map to neighbor\n"
7759 "Name of route map\n"
7760 "Apply map to incoming routes\n"
7761 "Apply map to outbound routes\n")
7762
7763 DEFUN (no_neighbor_route_map,
7764 no_neighbor_route_map_cmd,
7765 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7766 NO_STR
7767 NEIGHBOR_STR
7768 NEIGHBOR_ADDR_STR2
7769 "Apply route map to neighbor\n"
7770 "Name of route map\n"
7771 "Apply map to incoming routes\n"
7772 "Apply map to outbound routes\n")
7773 {
7774 int idx_peer = 2;
7775 int idx_in_out = 5;
7776 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7777 bgp_node_afi(vty), bgp_node_safi(vty),
7778 argv[idx_in_out]->arg);
7779 }
7780
7781 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7782 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7784 "Apply route map to neighbor\n"
7785 "Name of route map\n"
7786 "Apply map to incoming routes\n"
7787 "Apply map to outbound routes\n")
7788
7789 /* Set unsuppress-map to the peer. */
7790 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7791 afi_t afi, safi_t safi,
7792 const char *name_str)
7793 {
7794 int ret;
7795 struct peer *peer;
7796 struct route_map *route_map;
7797
7798 peer = peer_and_group_lookup_vty(vty, ip_str);
7799 if (!peer)
7800 return CMD_WARNING_CONFIG_FAILED;
7801
7802 route_map = route_map_lookup_warn_noexist(vty, name_str);
7803 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7804
7805 return bgp_vty_return(vty, ret);
7806 }
7807
7808 /* Unset route-map from the peer. */
7809 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7810 afi_t afi, safi_t safi)
7811 {
7812 int ret;
7813 struct peer *peer;
7814
7815 peer = peer_and_group_lookup_vty(vty, ip_str);
7816 if (!peer)
7817 return CMD_WARNING_CONFIG_FAILED;
7818
7819 ret = peer_unsuppress_map_unset(peer, afi, safi);
7820
7821 return bgp_vty_return(vty, ret);
7822 }
7823
7824 DEFUN (neighbor_unsuppress_map,
7825 neighbor_unsuppress_map_cmd,
7826 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7827 NEIGHBOR_STR
7828 NEIGHBOR_ADDR_STR2
7829 "Route-map to selectively unsuppress suppressed routes\n"
7830 "Name of route map\n")
7831 {
7832 int idx_peer = 1;
7833 int idx_word = 3;
7834 return peer_unsuppress_map_set_vty(
7835 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7836 argv[idx_word]->arg);
7837 }
7838
7839 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7840 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7841 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7842 "Route-map to selectively unsuppress suppressed routes\n"
7843 "Name of route map\n")
7844
7845 DEFUN (no_neighbor_unsuppress_map,
7846 no_neighbor_unsuppress_map_cmd,
7847 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7848 NO_STR
7849 NEIGHBOR_STR
7850 NEIGHBOR_ADDR_STR2
7851 "Route-map to selectively unsuppress suppressed routes\n"
7852 "Name of route map\n")
7853 {
7854 int idx_peer = 2;
7855 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7856 bgp_node_afi(vty),
7857 bgp_node_safi(vty));
7858 }
7859
7860 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7861 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7862 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7863 "Route-map to selectively unsuppress suppressed routes\n"
7864 "Name of route map\n")
7865
7866 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7867 afi_t afi, safi_t safi,
7868 const char *num_str,
7869 const char *threshold_str, int warning,
7870 const char *restart_str,
7871 const char *force_str)
7872 {
7873 int ret;
7874 struct peer *peer;
7875 uint32_t max;
7876 uint8_t threshold;
7877 uint16_t restart;
7878
7879 peer = peer_and_group_lookup_vty(vty, ip_str);
7880 if (!peer)
7881 return CMD_WARNING_CONFIG_FAILED;
7882
7883 max = strtoul(num_str, NULL, 10);
7884 if (threshold_str)
7885 threshold = atoi(threshold_str);
7886 else
7887 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7888
7889 if (restart_str)
7890 restart = atoi(restart_str);
7891 else
7892 restart = 0;
7893
7894 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7895 restart, force_str ? true : false);
7896
7897 return bgp_vty_return(vty, ret);
7898 }
7899
7900 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7901 afi_t afi, safi_t safi)
7902 {
7903 int ret;
7904 struct peer *peer;
7905
7906 peer = peer_and_group_lookup_vty(vty, ip_str);
7907 if (!peer)
7908 return CMD_WARNING_CONFIG_FAILED;
7909
7910 ret = peer_maximum_prefix_unset(peer, afi, safi);
7911
7912 return bgp_vty_return(vty, ret);
7913 }
7914
7915 /* Maximum number of prefix to be sent to the neighbor. */
7916 DEFUN(neighbor_maximum_prefix_out,
7917 neighbor_maximum_prefix_out_cmd,
7918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7919 NEIGHBOR_STR
7920 NEIGHBOR_ADDR_STR2
7921 "Maximum number of prefixes to be sent to this peer\n"
7922 "Maximum no. of prefix limit\n")
7923 {
7924 int ret;
7925 int idx_peer = 1;
7926 int idx_number = 3;
7927 struct peer *peer;
7928 uint32_t max;
7929 afi_t afi = bgp_node_afi(vty);
7930 safi_t safi = bgp_node_safi(vty);
7931
7932 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7933 if (!peer)
7934 return CMD_WARNING_CONFIG_FAILED;
7935
7936 max = strtoul(argv[idx_number]->arg, NULL, 10);
7937
7938 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
7939
7940 return bgp_vty_return(vty, ret);
7941 }
7942
7943 DEFUN(no_neighbor_maximum_prefix_out,
7944 no_neighbor_maximum_prefix_out_cmd,
7945 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
7946 NO_STR
7947 NEIGHBOR_STR
7948 NEIGHBOR_ADDR_STR2
7949 "Maximum number of prefixes to be sent to this peer\n"
7950 "Maximum no. of prefix limit\n")
7951 {
7952 int ret;
7953 int idx_peer = 2;
7954 struct peer *peer;
7955 afi_t afi = bgp_node_afi(vty);
7956 safi_t safi = bgp_node_safi(vty);
7957
7958 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7959 if (!peer)
7960 return CMD_WARNING_CONFIG_FAILED;
7961
7962 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
7963
7964 return bgp_vty_return(vty, ret);
7965 }
7966
7967 /* Maximum number of prefix configuration. Prefix count is different
7968 for each peer configuration. So this configuration can be set for
7969 each peer configuration. */
7970 DEFUN (neighbor_maximum_prefix,
7971 neighbor_maximum_prefix_cmd,
7972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7973 NEIGHBOR_STR
7974 NEIGHBOR_ADDR_STR2
7975 "Maximum number of prefix accept from this peer\n"
7976 "maximum no. of prefix limit\n"
7977 "Force checking all received routes not only accepted\n")
7978 {
7979 int idx_peer = 1;
7980 int idx_number = 3;
7981 int idx_force = 0;
7982 char *force = NULL;
7983
7984 if (argv_find(argv, argc, "force", &idx_force))
7985 force = argv[idx_force]->arg;
7986
7987 return peer_maximum_prefix_set_vty(
7988 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7989 argv[idx_number]->arg, NULL, 0, NULL, force);
7990 }
7991
7992 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
7993 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7995 "Maximum number of prefix accept from this peer\n"
7996 "maximum no. of prefix limit\n"
7997 "Force checking all received routes not only accepted\n")
7998
7999 DEFUN (neighbor_maximum_prefix_threshold,
8000 neighbor_maximum_prefix_threshold_cmd,
8001 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8002 NEIGHBOR_STR
8003 NEIGHBOR_ADDR_STR2
8004 "Maximum number of prefix accept from this peer\n"
8005 "maximum no. of prefix limit\n"
8006 "Threshold value (%) at which to generate a warning msg\n"
8007 "Force checking all received routes not only accepted\n")
8008 {
8009 int idx_peer = 1;
8010 int idx_number = 3;
8011 int idx_number_2 = 4;
8012 int idx_force = 0;
8013 char *force = NULL;
8014
8015 if (argv_find(argv, argc, "force", &idx_force))
8016 force = argv[idx_force]->arg;
8017
8018 return peer_maximum_prefix_set_vty(
8019 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8020 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8021 }
8022
8023 ALIAS_HIDDEN(
8024 neighbor_maximum_prefix_threshold,
8025 neighbor_maximum_prefix_threshold_hidden_cmd,
8026 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8027 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8028 "Maximum number of prefix accept from this peer\n"
8029 "maximum no. of prefix limit\n"
8030 "Threshold value (%) at which to generate a warning msg\n"
8031 "Force checking all received routes not only accepted\n")
8032
8033 DEFUN (neighbor_maximum_prefix_warning,
8034 neighbor_maximum_prefix_warning_cmd,
8035 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8036 NEIGHBOR_STR
8037 NEIGHBOR_ADDR_STR2
8038 "Maximum number of prefix accept from this peer\n"
8039 "maximum no. of prefix limit\n"
8040 "Only give warning message when limit is exceeded\n"
8041 "Force checking all received routes not only accepted\n")
8042 {
8043 int idx_peer = 1;
8044 int idx_number = 3;
8045 int idx_force = 0;
8046 char *force = NULL;
8047
8048 if (argv_find(argv, argc, "force", &idx_force))
8049 force = argv[idx_force]->arg;
8050
8051 return peer_maximum_prefix_set_vty(
8052 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8053 argv[idx_number]->arg, NULL, 1, NULL, force);
8054 }
8055
8056 ALIAS_HIDDEN(
8057 neighbor_maximum_prefix_warning,
8058 neighbor_maximum_prefix_warning_hidden_cmd,
8059 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8060 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8061 "Maximum number of prefix accept from this peer\n"
8062 "maximum no. of prefix limit\n"
8063 "Only give warning message when limit is exceeded\n"
8064 "Force checking all received routes not only accepted\n")
8065
8066 DEFUN (neighbor_maximum_prefix_threshold_warning,
8067 neighbor_maximum_prefix_threshold_warning_cmd,
8068 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8069 NEIGHBOR_STR
8070 NEIGHBOR_ADDR_STR2
8071 "Maximum number of prefix accept from this peer\n"
8072 "maximum no. of prefix limit\n"
8073 "Threshold value (%) at which to generate a warning msg\n"
8074 "Only give warning message when limit is exceeded\n"
8075 "Force checking all received routes not only accepted\n")
8076 {
8077 int idx_peer = 1;
8078 int idx_number = 3;
8079 int idx_number_2 = 4;
8080 int idx_force = 0;
8081 char *force = NULL;
8082
8083 if (argv_find(argv, argc, "force", &idx_force))
8084 force = argv[idx_force]->arg;
8085
8086 return peer_maximum_prefix_set_vty(
8087 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8088 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8089 }
8090
8091 ALIAS_HIDDEN(
8092 neighbor_maximum_prefix_threshold_warning,
8093 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8094 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8096 "Maximum number of prefix accept from this peer\n"
8097 "maximum no. of prefix limit\n"
8098 "Threshold value (%) at which to generate a warning msg\n"
8099 "Only give warning message when limit is exceeded\n"
8100 "Force checking all received routes not only accepted\n")
8101
8102 DEFUN (neighbor_maximum_prefix_restart,
8103 neighbor_maximum_prefix_restart_cmd,
8104 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8105 NEIGHBOR_STR
8106 NEIGHBOR_ADDR_STR2
8107 "Maximum number of prefix accept from this peer\n"
8108 "maximum no. of prefix limit\n"
8109 "Restart bgp connection after limit is exceeded\n"
8110 "Restart interval in minutes\n"
8111 "Force checking all received routes not only accepted\n")
8112 {
8113 int idx_peer = 1;
8114 int idx_number = 3;
8115 int idx_number_2 = 5;
8116 int idx_force = 0;
8117 char *force = NULL;
8118
8119 if (argv_find(argv, argc, "force", &idx_force))
8120 force = argv[idx_force]->arg;
8121
8122 return peer_maximum_prefix_set_vty(
8123 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8124 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8125 }
8126
8127 ALIAS_HIDDEN(
8128 neighbor_maximum_prefix_restart,
8129 neighbor_maximum_prefix_restart_hidden_cmd,
8130 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8132 "Maximum number of prefix accept from this peer\n"
8133 "maximum no. of prefix limit\n"
8134 "Restart bgp connection after limit is exceeded\n"
8135 "Restart interval in minutes\n"
8136 "Force checking all received routes not only accepted\n")
8137
8138 DEFUN (neighbor_maximum_prefix_threshold_restart,
8139 neighbor_maximum_prefix_threshold_restart_cmd,
8140 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8141 NEIGHBOR_STR
8142 NEIGHBOR_ADDR_STR2
8143 "Maximum number of prefixes to accept from this peer\n"
8144 "maximum no. of prefix limit\n"
8145 "Threshold value (%) at which to generate a warning msg\n"
8146 "Restart bgp connection after limit is exceeded\n"
8147 "Restart interval in minutes\n"
8148 "Force checking all received routes not only accepted\n")
8149 {
8150 int idx_peer = 1;
8151 int idx_number = 3;
8152 int idx_number_2 = 4;
8153 int idx_number_3 = 6;
8154 int idx_force = 0;
8155 char *force = NULL;
8156
8157 if (argv_find(argv, argc, "force", &idx_force))
8158 force = argv[idx_force]->arg;
8159
8160 return peer_maximum_prefix_set_vty(
8161 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8162 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8163 argv[idx_number_3]->arg, force);
8164 }
8165
8166 ALIAS_HIDDEN(
8167 neighbor_maximum_prefix_threshold_restart,
8168 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8169 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8170 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8171 "Maximum number of prefixes to accept from this peer\n"
8172 "maximum no. of prefix limit\n"
8173 "Threshold value (%) at which to generate a warning msg\n"
8174 "Restart bgp connection after limit is exceeded\n"
8175 "Restart interval in minutes\n"
8176 "Force checking all received routes not only accepted\n")
8177
8178 DEFUN (no_neighbor_maximum_prefix,
8179 no_neighbor_maximum_prefix_cmd,
8180 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8181 NO_STR
8182 NEIGHBOR_STR
8183 NEIGHBOR_ADDR_STR2
8184 "Maximum number of prefixes to accept from this peer\n"
8185 "maximum no. of prefix limit\n"
8186 "Threshold value (%) at which to generate a warning msg\n"
8187 "Restart bgp connection after limit is exceeded\n"
8188 "Restart interval in minutes\n"
8189 "Only give warning message when limit is exceeded\n"
8190 "Force checking all received routes not only accepted\n")
8191 {
8192 int idx_peer = 2;
8193 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8194 bgp_node_afi(vty),
8195 bgp_node_safi(vty));
8196 }
8197
8198 ALIAS_HIDDEN(
8199 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8200 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8201 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8202 "Maximum number of prefixes to accept from this peer\n"
8203 "maximum no. of prefix limit\n"
8204 "Threshold value (%) at which to generate a warning msg\n"
8205 "Restart bgp connection after limit is exceeded\n"
8206 "Restart interval in minutes\n"
8207 "Only give warning message when limit is exceeded\n"
8208 "Force checking all received routes not only accepted\n")
8209
8210
8211 /* "neighbor allowas-in" */
8212 DEFUN (neighbor_allowas_in,
8213 neighbor_allowas_in_cmd,
8214 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8215 NEIGHBOR_STR
8216 NEIGHBOR_ADDR_STR2
8217 "Accept as-path with my AS present in it\n"
8218 "Number of occurrences of AS number\n"
8219 "Only accept my AS in the as-path if the route was originated in my AS\n")
8220 {
8221 int idx_peer = 1;
8222 int idx_number_origin = 3;
8223 int ret;
8224 int origin = 0;
8225 struct peer *peer;
8226 int allow_num = 0;
8227
8228 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8229 if (!peer)
8230 return CMD_WARNING_CONFIG_FAILED;
8231
8232 if (argc <= idx_number_origin)
8233 allow_num = 3;
8234 else {
8235 if (argv[idx_number_origin]->type == WORD_TKN)
8236 origin = 1;
8237 else
8238 allow_num = atoi(argv[idx_number_origin]->arg);
8239 }
8240
8241 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8242 allow_num, origin);
8243
8244 return bgp_vty_return(vty, ret);
8245 }
8246
8247 ALIAS_HIDDEN(
8248 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8249 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8250 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8251 "Accept as-path with my AS present in it\n"
8252 "Number of occurrences of AS number\n"
8253 "Only accept my AS in the as-path if the route was originated in my AS\n")
8254
8255 DEFUN (no_neighbor_allowas_in,
8256 no_neighbor_allowas_in_cmd,
8257 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8258 NO_STR
8259 NEIGHBOR_STR
8260 NEIGHBOR_ADDR_STR2
8261 "allow local ASN appears in aspath attribute\n"
8262 "Number of occurrences of AS number\n"
8263 "Only accept my AS in the as-path if the route was originated in my AS\n")
8264 {
8265 int idx_peer = 2;
8266 int ret;
8267 struct peer *peer;
8268
8269 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8270 if (!peer)
8271 return CMD_WARNING_CONFIG_FAILED;
8272
8273 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8274 bgp_node_safi(vty));
8275
8276 return bgp_vty_return(vty, ret);
8277 }
8278
8279 ALIAS_HIDDEN(
8280 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8281 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8282 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8283 "allow local ASN appears in aspath attribute\n"
8284 "Number of occurrences of AS number\n"
8285 "Only accept my AS in the as-path if the route was originated in my AS\n")
8286
8287 DEFUN (neighbor_ttl_security,
8288 neighbor_ttl_security_cmd,
8289 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8290 NEIGHBOR_STR
8291 NEIGHBOR_ADDR_STR2
8292 "BGP ttl-security parameters\n"
8293 "Specify the maximum number of hops to the BGP peer\n"
8294 "Number of hops to BGP peer\n")
8295 {
8296 int idx_peer = 1;
8297 int idx_number = 4;
8298 struct peer *peer;
8299 int gtsm_hops;
8300
8301 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8302 if (!peer)
8303 return CMD_WARNING_CONFIG_FAILED;
8304
8305 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8306
8307 /*
8308 * If 'neighbor swpX', then this is for directly connected peers,
8309 * we should not accept a ttl-security hops value greater than 1.
8310 */
8311 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8312 vty_out(vty,
8313 "%s is directly connected peer, hops cannot exceed 1\n",
8314 argv[idx_peer]->arg);
8315 return CMD_WARNING_CONFIG_FAILED;
8316 }
8317
8318 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8319 }
8320
8321 DEFUN (no_neighbor_ttl_security,
8322 no_neighbor_ttl_security_cmd,
8323 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8324 NO_STR
8325 NEIGHBOR_STR
8326 NEIGHBOR_ADDR_STR2
8327 "BGP ttl-security parameters\n"
8328 "Specify the maximum number of hops to the BGP peer\n"
8329 "Number of hops to BGP peer\n")
8330 {
8331 int idx_peer = 2;
8332 struct peer *peer;
8333
8334 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8335 if (!peer)
8336 return CMD_WARNING_CONFIG_FAILED;
8337
8338 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8339 }
8340
8341 /* disable-addpath-rx */
8342 DEFUN(neighbor_disable_addpath_rx,
8343 neighbor_disable_addpath_rx_cmd,
8344 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8345 NEIGHBOR_STR
8346 NEIGHBOR_ADDR_STR2
8347 "Do not accept additional paths\n")
8348 {
8349 char *peer_str = argv[1]->arg;
8350 struct peer *peer;
8351 afi_t afi = bgp_node_afi(vty);
8352 safi_t safi = bgp_node_safi(vty);
8353
8354 peer = peer_and_group_lookup_vty(vty, peer_str);
8355 if (!peer)
8356 return CMD_WARNING_CONFIG_FAILED;
8357
8358 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8359 PEER_FLAG_DISABLE_ADDPATH_RX);
8360 }
8361
8362 DEFUN(no_neighbor_disable_addpath_rx,
8363 no_neighbor_disable_addpath_rx_cmd,
8364 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8365 NO_STR
8366 NEIGHBOR_STR
8367 NEIGHBOR_ADDR_STR2
8368 "Do not accept additional paths\n")
8369 {
8370 char *peer_str = argv[2]->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_unset_vty(vty, peer_str, afi, safi,
8380 PEER_FLAG_DISABLE_ADDPATH_RX);
8381 }
8382
8383 DEFUN (neighbor_addpath_tx_all_paths,
8384 neighbor_addpath_tx_all_paths_cmd,
8385 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8386 NEIGHBOR_STR
8387 NEIGHBOR_ADDR_STR2
8388 "Use addpath to advertise all paths to a neighbor\n")
8389 {
8390 int idx_peer = 1;
8391 struct peer *peer;
8392
8393 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8394 if (!peer)
8395 return CMD_WARNING_CONFIG_FAILED;
8396
8397 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8398 BGP_ADDPATH_ALL);
8399 return CMD_SUCCESS;
8400 }
8401
8402 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8403 neighbor_addpath_tx_all_paths_hidden_cmd,
8404 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8405 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8406 "Use addpath to advertise all paths to a neighbor\n")
8407
8408 DEFUN (no_neighbor_addpath_tx_all_paths,
8409 no_neighbor_addpath_tx_all_paths_cmd,
8410 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8411 NO_STR
8412 NEIGHBOR_STR
8413 NEIGHBOR_ADDR_STR2
8414 "Use addpath to advertise all paths to a neighbor\n")
8415 {
8416 int idx_peer = 2;
8417 struct peer *peer;
8418
8419 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8420 if (!peer)
8421 return CMD_WARNING_CONFIG_FAILED;
8422
8423 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8424 != BGP_ADDPATH_ALL) {
8425 vty_out(vty,
8426 "%% Peer not currently configured to transmit all paths.");
8427 return CMD_WARNING_CONFIG_FAILED;
8428 }
8429
8430 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8431 BGP_ADDPATH_NONE);
8432
8433 return CMD_SUCCESS;
8434 }
8435
8436 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8437 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8438 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8439 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8440 "Use addpath to advertise all paths to a neighbor\n")
8441
8442 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8443 neighbor_addpath_tx_bestpath_per_as_cmd,
8444 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8445 NEIGHBOR_STR
8446 NEIGHBOR_ADDR_STR2
8447 "Use addpath to advertise the bestpath per each neighboring AS\n")
8448 {
8449 int idx_peer = 1;
8450 struct peer *peer;
8451
8452 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8453 if (!peer)
8454 return CMD_WARNING_CONFIG_FAILED;
8455
8456 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8457 BGP_ADDPATH_BEST_PER_AS);
8458
8459 return CMD_SUCCESS;
8460 }
8461
8462 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8463 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8464 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8465 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8466 "Use addpath to advertise the bestpath per each neighboring AS\n")
8467
8468 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8469 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8470 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8471 NO_STR
8472 NEIGHBOR_STR
8473 NEIGHBOR_ADDR_STR2
8474 "Use addpath to advertise the bestpath per each neighboring AS\n")
8475 {
8476 int idx_peer = 2;
8477 struct peer *peer;
8478
8479 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8480 if (!peer)
8481 return CMD_WARNING_CONFIG_FAILED;
8482
8483 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8484 != BGP_ADDPATH_BEST_PER_AS) {
8485 vty_out(vty,
8486 "%% Peer not currently configured to transmit all best path per as.");
8487 return CMD_WARNING_CONFIG_FAILED;
8488 }
8489
8490 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8491 BGP_ADDPATH_NONE);
8492
8493 return CMD_SUCCESS;
8494 }
8495
8496 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8497 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8498 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8499 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8500 "Use addpath to advertise the bestpath per each neighboring AS\n")
8501
8502 DEFPY(
8503 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8504 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8505 NEIGHBOR_STR
8506 NEIGHBOR_ADDR_STR2
8507 "Detect AS loops before sending to neighbor\n")
8508 {
8509 struct peer *peer;
8510
8511 peer = peer_and_group_lookup_vty(vty, neighbor);
8512 if (!peer)
8513 return CMD_WARNING_CONFIG_FAILED;
8514
8515 peer->as_path_loop_detection = true;
8516
8517 return CMD_SUCCESS;
8518 }
8519
8520 DEFPY(
8521 no_neighbor_aspath_loop_detection,
8522 no_neighbor_aspath_loop_detection_cmd,
8523 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8524 NO_STR
8525 NEIGHBOR_STR
8526 NEIGHBOR_ADDR_STR2
8527 "Detect AS loops before sending to neighbor\n")
8528 {
8529 struct peer *peer;
8530
8531 peer = peer_and_group_lookup_vty(vty, neighbor);
8532 if (!peer)
8533 return CMD_WARNING_CONFIG_FAILED;
8534
8535 peer->as_path_loop_detection = false;
8536
8537 return CMD_SUCCESS;
8538 }
8539
8540 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8541 struct ecommunity **list, bool is_rt6)
8542 {
8543 struct ecommunity *ecom = NULL;
8544 struct ecommunity *ecomadd;
8545
8546 for (; argc; --argc, ++argv) {
8547 if (is_rt6)
8548 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8549 ECOMMUNITY_ROUTE_TARGET,
8550 0);
8551 else
8552 ecomadd = ecommunity_str2com(argv[0]->arg,
8553 ECOMMUNITY_ROUTE_TARGET,
8554 0);
8555 if (!ecomadd) {
8556 vty_out(vty, "Malformed community-list value\n");
8557 if (ecom)
8558 ecommunity_free(&ecom);
8559 return CMD_WARNING_CONFIG_FAILED;
8560 }
8561
8562 if (ecom) {
8563 ecommunity_merge(ecom, ecomadd);
8564 ecommunity_free(&ecomadd);
8565 } else {
8566 ecom = ecomadd;
8567 }
8568 }
8569
8570 if (*list) {
8571 ecommunity_free(&*list);
8572 }
8573 *list = ecom;
8574
8575 return CMD_SUCCESS;
8576 }
8577
8578 /*
8579 * v2vimport is true if we are handling a `import vrf ...` command
8580 */
8581 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8582 {
8583 afi_t afi;
8584
8585 switch (vty->node) {
8586 case BGP_IPV4_NODE:
8587 afi = AFI_IP;
8588 break;
8589 case BGP_IPV6_NODE:
8590 afi = AFI_IP6;
8591 break;
8592 default:
8593 vty_out(vty,
8594 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8595 return AFI_MAX;
8596 }
8597
8598 if (!v2vimport) {
8599 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8600 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8601 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8602 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8603 vty_out(vty,
8604 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8605 return AFI_MAX;
8606 }
8607 } else {
8608 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8609 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8610 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8611 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8612 vty_out(vty,
8613 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8614 return AFI_MAX;
8615 }
8616 }
8617 return afi;
8618 }
8619
8620 DEFPY (af_rd_vpn_export,
8621 af_rd_vpn_export_cmd,
8622 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8623 NO_STR
8624 "Specify route distinguisher\n"
8625 "Between current address-family and vpn\n"
8626 "For routes leaked from current address-family to vpn\n"
8627 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8628 {
8629 VTY_DECLVAR_CONTEXT(bgp, bgp);
8630 struct prefix_rd prd;
8631 int ret;
8632 afi_t afi;
8633 int idx = 0;
8634 bool yes = true;
8635
8636 if (argv_find(argv, argc, "no", &idx))
8637 yes = false;
8638
8639 if (yes) {
8640 ret = str2prefix_rd(rd_str, &prd);
8641 if (!ret) {
8642 vty_out(vty, "%% Malformed rd\n");
8643 return CMD_WARNING_CONFIG_FAILED;
8644 }
8645 }
8646
8647 afi = vpn_policy_getafi(vty, bgp, false);
8648 if (afi == AFI_MAX)
8649 return CMD_WARNING_CONFIG_FAILED;
8650
8651 /*
8652 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8653 */
8654 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8655 bgp_get_default(), bgp);
8656
8657 if (yes) {
8658 bgp->vpn_policy[afi].tovpn_rd = prd;
8659 SET_FLAG(bgp->vpn_policy[afi].flags,
8660 BGP_VPN_POLICY_TOVPN_RD_SET);
8661 } else {
8662 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8663 BGP_VPN_POLICY_TOVPN_RD_SET);
8664 }
8665
8666 /* post-change: re-export vpn routes */
8667 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8668 bgp_get_default(), bgp);
8669
8670 return CMD_SUCCESS;
8671 }
8672
8673 ALIAS (af_rd_vpn_export,
8674 af_no_rd_vpn_export_cmd,
8675 "no rd vpn export",
8676 NO_STR
8677 "Specify route distinguisher\n"
8678 "Between current address-family and vpn\n"
8679 "For routes leaked from current address-family to vpn\n")
8680
8681 DEFPY (af_label_vpn_export,
8682 af_label_vpn_export_cmd,
8683 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8684 NO_STR
8685 "label value for VRF\n"
8686 "Between current address-family and vpn\n"
8687 "For routes leaked from current address-family to vpn\n"
8688 "Label Value <0-1048575>\n"
8689 "Automatically assign a label\n")
8690 {
8691 VTY_DECLVAR_CONTEXT(bgp, bgp);
8692 mpls_label_t label = MPLS_LABEL_NONE;
8693 afi_t afi;
8694 int idx = 0;
8695 bool yes = true;
8696
8697 if (argv_find(argv, argc, "no", &idx))
8698 yes = false;
8699
8700 /* If "no ...", squash trailing parameter */
8701 if (!yes)
8702 label_auto = NULL;
8703
8704 if (yes) {
8705 if (!label_auto)
8706 label = label_val; /* parser should force unsigned */
8707 }
8708
8709 afi = vpn_policy_getafi(vty, bgp, false);
8710 if (afi == AFI_MAX)
8711 return CMD_WARNING_CONFIG_FAILED;
8712
8713
8714 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8715 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8716 /* no change */
8717 return CMD_SUCCESS;
8718
8719 /*
8720 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8721 */
8722 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8723 bgp_get_default(), bgp);
8724
8725 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8726 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8727
8728 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8729
8730 /*
8731 * label has previously been automatically
8732 * assigned by labelpool: release it
8733 *
8734 * NB if tovpn_label == MPLS_LABEL_NONE it
8735 * means the automatic assignment is in flight
8736 * and therefore the labelpool callback must
8737 * detect that the auto label is not needed.
8738 */
8739
8740 bgp_lp_release(LP_TYPE_VRF,
8741 &bgp->vpn_policy[afi],
8742 bgp->vpn_policy[afi].tovpn_label);
8743 }
8744 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8745 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8746 }
8747
8748 bgp->vpn_policy[afi].tovpn_label = label;
8749 if (label_auto) {
8750 SET_FLAG(bgp->vpn_policy[afi].flags,
8751 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8752 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8753 vpn_leak_label_callback);
8754 }
8755
8756 /* post-change: re-export vpn routes */
8757 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8758 bgp_get_default(), bgp);
8759
8760 hook_call(bgp_snmp_update_last_changed, bgp);
8761 return CMD_SUCCESS;
8762 }
8763
8764 DEFPY (af_sid_vpn_export,
8765 af_sid_vpn_export_cmd,
8766 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8767 NO_STR
8768 "sid value for VRF\n"
8769 "Between current address-family and vpn\n"
8770 "For routes leaked from current address-family to vpn\n"
8771 "Sid allocation index\n"
8772 "Automatically assign a label\n")
8773 {
8774 VTY_DECLVAR_CONTEXT(bgp, bgp);
8775 afi_t afi;
8776 int debug = 0;
8777 int idx = 0;
8778 bool yes = true;
8779
8780 if (argv_find(argv, argc, "no", &idx))
8781 yes = false;
8782 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8783 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8784
8785 afi = vpn_policy_getafi(vty, bgp, false);
8786 if (afi == AFI_MAX)
8787 return CMD_WARNING_CONFIG_FAILED;
8788
8789 if (!yes) {
8790 /* implement me */
8791 vty_out(vty, "It's not implemented\n");
8792 return CMD_WARNING_CONFIG_FAILED;
8793 }
8794
8795 /* skip when it's already configured */
8796 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8797 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8798 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8799 return CMD_SUCCESS;
8800
8801 /*
8802 * mode change between sid_idx and sid_auto isn't supported.
8803 * user must negate sid vpn export when they want to change the mode
8804 */
8805 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8806 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8807 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8808 vty_out(vty, "it's already configured as %s.\n",
8809 sid_auto ? "auto-mode" : "idx-mode");
8810 return CMD_WARNING_CONFIG_FAILED;
8811 }
8812
8813 /* pre-change */
8814 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8815 bgp_get_default(), bgp);
8816
8817 if (sid_auto) {
8818 /* SID allocation auto-mode */
8819 if (debug)
8820 zlog_debug("%s: auto sid alloc.", __func__);
8821 SET_FLAG(bgp->vpn_policy[afi].flags,
8822 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8823 } else {
8824 /* SID allocation index-mode */
8825 if (debug)
8826 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8827 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8828 }
8829
8830 /* post-change */
8831 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8832 bgp_get_default(), bgp);
8833 return CMD_SUCCESS;
8834 }
8835
8836 ALIAS (af_label_vpn_export,
8837 af_no_label_vpn_export_cmd,
8838 "no label vpn export",
8839 NO_STR
8840 "label value for VRF\n"
8841 "Between current address-family and vpn\n"
8842 "For routes leaked from current address-family to vpn\n")
8843
8844 DEFPY (af_nexthop_vpn_export,
8845 af_nexthop_vpn_export_cmd,
8846 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8847 NO_STR
8848 "Specify next hop to use for VRF advertised prefixes\n"
8849 "Between current address-family and vpn\n"
8850 "For routes leaked from current address-family to vpn\n"
8851 "IPv4 prefix\n"
8852 "IPv6 prefix\n")
8853 {
8854 VTY_DECLVAR_CONTEXT(bgp, bgp);
8855 afi_t afi;
8856 struct prefix p;
8857
8858 if (!no) {
8859 if (!nexthop_su) {
8860 vty_out(vty, "%% Nexthop required\n");
8861 return CMD_WARNING_CONFIG_FAILED;
8862 }
8863 if (!sockunion2hostprefix(nexthop_su, &p))
8864 return CMD_WARNING_CONFIG_FAILED;
8865 }
8866
8867 afi = vpn_policy_getafi(vty, bgp, false);
8868 if (afi == AFI_MAX)
8869 return CMD_WARNING_CONFIG_FAILED;
8870
8871 /*
8872 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8873 */
8874 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8875 bgp_get_default(), bgp);
8876
8877 if (!no) {
8878 bgp->vpn_policy[afi].tovpn_nexthop = p;
8879 SET_FLAG(bgp->vpn_policy[afi].flags,
8880 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8881 } else {
8882 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8883 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8884 }
8885
8886 /* post-change: re-export vpn routes */
8887 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8888 bgp_get_default(), bgp);
8889
8890 return CMD_SUCCESS;
8891 }
8892
8893 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8894 {
8895 if (!strcmp(dstr, "import")) {
8896 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8897 } else if (!strcmp(dstr, "export")) {
8898 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8899 } else if (!strcmp(dstr, "both")) {
8900 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8901 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8902 } else {
8903 vty_out(vty, "%% direction parse error\n");
8904 return CMD_WARNING_CONFIG_FAILED;
8905 }
8906 return CMD_SUCCESS;
8907 }
8908
8909 DEFPY (af_rt_vpn_imexport,
8910 af_rt_vpn_imexport_cmd,
8911 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8912 NO_STR
8913 "Specify route target list\n"
8914 "Specify route target list\n"
8915 "Between current address-family and vpn\n"
8916 "For routes leaked from vpn to current address-family: match any\n"
8917 "For routes leaked from current address-family to vpn: set\n"
8918 "both import: match any and export: set\n"
8919 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8920 {
8921 VTY_DECLVAR_CONTEXT(bgp, bgp);
8922 int ret;
8923 struct ecommunity *ecom = NULL;
8924 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8925 enum vpn_policy_direction dir;
8926 afi_t afi;
8927 int idx = 0;
8928 bool yes = true;
8929
8930 if (argv_find(argv, argc, "no", &idx))
8931 yes = false;
8932
8933 afi = vpn_policy_getafi(vty, bgp, false);
8934 if (afi == AFI_MAX)
8935 return CMD_WARNING_CONFIG_FAILED;
8936
8937 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8938 if (ret != CMD_SUCCESS)
8939 return ret;
8940
8941 if (yes) {
8942 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8943 vty_out(vty, "%% Missing RTLIST\n");
8944 return CMD_WARNING_CONFIG_FAILED;
8945 }
8946 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8947 if (ret != CMD_SUCCESS) {
8948 return ret;
8949 }
8950 }
8951
8952 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8953 if (!dodir[dir])
8954 continue;
8955
8956 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8957
8958 if (yes) {
8959 if (bgp->vpn_policy[afi].rtlist[dir])
8960 ecommunity_free(
8961 &bgp->vpn_policy[afi].rtlist[dir]);
8962 bgp->vpn_policy[afi].rtlist[dir] =
8963 ecommunity_dup(ecom);
8964 } else {
8965 if (bgp->vpn_policy[afi].rtlist[dir])
8966 ecommunity_free(
8967 &bgp->vpn_policy[afi].rtlist[dir]);
8968 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8969 }
8970
8971 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8972 }
8973
8974 if (ecom)
8975 ecommunity_free(&ecom);
8976
8977 return CMD_SUCCESS;
8978 }
8979
8980 ALIAS (af_rt_vpn_imexport,
8981 af_no_rt_vpn_imexport_cmd,
8982 "no <rt|route-target> vpn <import|export|both>$direction_str",
8983 NO_STR
8984 "Specify route target list\n"
8985 "Specify route target list\n"
8986 "Between current address-family and vpn\n"
8987 "For routes leaked from vpn to current address-family\n"
8988 "For routes leaked from current address-family to vpn\n"
8989 "both import and export\n")
8990
8991 DEFPY (af_route_map_vpn_imexport,
8992 af_route_map_vpn_imexport_cmd,
8993 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8994 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8995 NO_STR
8996 "Specify route map\n"
8997 "Between current address-family and vpn\n"
8998 "For routes leaked from vpn to current address-family\n"
8999 "For routes leaked from current address-family to vpn\n"
9000 "name of route-map\n")
9001 {
9002 VTY_DECLVAR_CONTEXT(bgp, bgp);
9003 int ret;
9004 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9005 enum vpn_policy_direction dir;
9006 afi_t afi;
9007 int idx = 0;
9008 bool yes = true;
9009
9010 if (argv_find(argv, argc, "no", &idx))
9011 yes = false;
9012
9013 afi = vpn_policy_getafi(vty, bgp, false);
9014 if (afi == AFI_MAX)
9015 return CMD_WARNING_CONFIG_FAILED;
9016
9017 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9018 if (ret != CMD_SUCCESS)
9019 return ret;
9020
9021 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9022 if (!dodir[dir])
9023 continue;
9024
9025 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9026
9027 if (yes) {
9028 if (bgp->vpn_policy[afi].rmap_name[dir])
9029 XFREE(MTYPE_ROUTE_MAP_NAME,
9030 bgp->vpn_policy[afi].rmap_name[dir]);
9031 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9032 MTYPE_ROUTE_MAP_NAME, rmap_str);
9033 bgp->vpn_policy[afi].rmap[dir] =
9034 route_map_lookup_warn_noexist(vty, rmap_str);
9035 if (!bgp->vpn_policy[afi].rmap[dir])
9036 return CMD_SUCCESS;
9037 } else {
9038 if (bgp->vpn_policy[afi].rmap_name[dir])
9039 XFREE(MTYPE_ROUTE_MAP_NAME,
9040 bgp->vpn_policy[afi].rmap_name[dir]);
9041 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9042 bgp->vpn_policy[afi].rmap[dir] = NULL;
9043 }
9044
9045 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9046 }
9047
9048 return CMD_SUCCESS;
9049 }
9050
9051 ALIAS (af_route_map_vpn_imexport,
9052 af_no_route_map_vpn_imexport_cmd,
9053 "no route-map vpn <import|export>$direction_str",
9054 NO_STR
9055 "Specify route map\n"
9056 "Between current address-family and vpn\n"
9057 "For routes leaked from vpn to current address-family\n"
9058 "For routes leaked from current address-family to vpn\n")
9059
9060 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9061 "import vrf route-map RMAP$rmap_str",
9062 "Import routes from another VRF\n"
9063 "Vrf routes being filtered\n"
9064 "Specify route map\n"
9065 "name of route-map\n")
9066 {
9067 VTY_DECLVAR_CONTEXT(bgp, bgp);
9068 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9069 afi_t afi;
9070 struct bgp *bgp_default;
9071
9072 afi = vpn_policy_getafi(vty, bgp, true);
9073 if (afi == AFI_MAX)
9074 return CMD_WARNING_CONFIG_FAILED;
9075
9076 bgp_default = bgp_get_default();
9077 if (!bgp_default) {
9078 int32_t ret;
9079 as_t as = bgp->as;
9080
9081 /* Auto-create assuming the same AS */
9082 ret = bgp_get_vty(&bgp_default, &as, NULL,
9083 BGP_INSTANCE_TYPE_DEFAULT);
9084
9085 if (ret) {
9086 vty_out(vty,
9087 "VRF default is not configured as a bgp instance\n");
9088 return CMD_WARNING;
9089 }
9090 }
9091
9092 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9093
9094 if (bgp->vpn_policy[afi].rmap_name[dir])
9095 XFREE(MTYPE_ROUTE_MAP_NAME,
9096 bgp->vpn_policy[afi].rmap_name[dir]);
9097 bgp->vpn_policy[afi].rmap_name[dir] =
9098 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9099 bgp->vpn_policy[afi].rmap[dir] =
9100 route_map_lookup_warn_noexist(vty, rmap_str);
9101 if (!bgp->vpn_policy[afi].rmap[dir])
9102 return CMD_SUCCESS;
9103
9104 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9105 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9106
9107 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9108
9109 return CMD_SUCCESS;
9110 }
9111
9112 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9113 "no import vrf route-map [RMAP$rmap_str]",
9114 NO_STR
9115 "Import routes from another VRF\n"
9116 "Vrf routes being filtered\n"
9117 "Specify route map\n"
9118 "name of route-map\n")
9119 {
9120 VTY_DECLVAR_CONTEXT(bgp, bgp);
9121 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9122 afi_t afi;
9123
9124 afi = vpn_policy_getafi(vty, bgp, true);
9125 if (afi == AFI_MAX)
9126 return CMD_WARNING_CONFIG_FAILED;
9127
9128 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9129
9130 if (bgp->vpn_policy[afi].rmap_name[dir])
9131 XFREE(MTYPE_ROUTE_MAP_NAME,
9132 bgp->vpn_policy[afi].rmap_name[dir]);
9133 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9134 bgp->vpn_policy[afi].rmap[dir] = NULL;
9135
9136 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9137 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9138 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9139
9140 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9141
9142 return CMD_SUCCESS;
9143 }
9144
9145 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9146 "[no] import vrf VIEWVRFNAME$import_name",
9147 NO_STR
9148 "Import routes from another VRF\n"
9149 "VRF to import from\n"
9150 "The name of the VRF\n")
9151 {
9152 VTY_DECLVAR_CONTEXT(bgp, bgp);
9153 struct listnode *node;
9154 struct bgp *vrf_bgp, *bgp_default;
9155 int32_t ret = 0;
9156 as_t as = bgp->as;
9157 bool remove = false;
9158 int32_t idx = 0;
9159 char *vname;
9160 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9161 safi_t safi;
9162 afi_t afi;
9163
9164 if (import_name == NULL) {
9165 vty_out(vty, "%% Missing import name\n");
9166 return CMD_WARNING;
9167 }
9168
9169 if (strcmp(import_name, "route-map") == 0) {
9170 vty_out(vty, "%% Must include route-map name\n");
9171 return CMD_WARNING;
9172 }
9173
9174 if (argv_find(argv, argc, "no", &idx))
9175 remove = true;
9176
9177 afi = vpn_policy_getafi(vty, bgp, true);
9178 if (afi == AFI_MAX)
9179 return CMD_WARNING_CONFIG_FAILED;
9180
9181 safi = bgp_node_safi(vty);
9182
9183 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9184 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9185 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9186 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9187 remove ? "unimport" : "import", import_name);
9188 return CMD_WARNING;
9189 }
9190
9191 bgp_default = bgp_get_default();
9192 if (!bgp_default) {
9193 /* Auto-create assuming the same AS */
9194 ret = bgp_get_vty(&bgp_default, &as, NULL,
9195 BGP_INSTANCE_TYPE_DEFAULT);
9196
9197 if (ret) {
9198 vty_out(vty,
9199 "VRF default is not configured as a bgp instance\n");
9200 return CMD_WARNING;
9201 }
9202 }
9203
9204 vrf_bgp = bgp_lookup_by_name(import_name);
9205 if (!vrf_bgp) {
9206 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9207 vrf_bgp = bgp_default;
9208 else
9209 /* Auto-create assuming the same AS */
9210 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9211
9212 if (ret) {
9213 vty_out(vty,
9214 "VRF %s is not configured as a bgp instance\n",
9215 import_name);
9216 return CMD_WARNING;
9217 }
9218 }
9219
9220 if (remove) {
9221 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9222 } else {
9223 /* Already importing from "import_vrf"? */
9224 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9225 vname)) {
9226 if (strcmp(vname, import_name) == 0)
9227 return CMD_WARNING;
9228 }
9229
9230 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9231 }
9232
9233 return CMD_SUCCESS;
9234 }
9235
9236 /* This command is valid only in a bgp vrf instance or the default instance */
9237 DEFPY (bgp_imexport_vpn,
9238 bgp_imexport_vpn_cmd,
9239 "[no] <import|export>$direction_str vpn",
9240 NO_STR
9241 "Import routes to this address-family\n"
9242 "Export routes from this address-family\n"
9243 "to/from default instance VPN RIB\n")
9244 {
9245 VTY_DECLVAR_CONTEXT(bgp, bgp);
9246 int previous_state;
9247 afi_t afi;
9248 safi_t safi;
9249 int idx = 0;
9250 bool yes = true;
9251 int flag;
9252 enum vpn_policy_direction dir;
9253
9254 if (argv_find(argv, argc, "no", &idx))
9255 yes = false;
9256
9257 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9258 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9259
9260 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9261 return CMD_WARNING_CONFIG_FAILED;
9262 }
9263
9264 afi = bgp_node_afi(vty);
9265 safi = bgp_node_safi(vty);
9266 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9267 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9268 return CMD_WARNING_CONFIG_FAILED;
9269 }
9270
9271 if (!strcmp(direction_str, "import")) {
9272 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9273 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9274 } else if (!strcmp(direction_str, "export")) {
9275 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9276 dir = BGP_VPN_POLICY_DIR_TOVPN;
9277 } else {
9278 vty_out(vty, "%% unknown direction %s\n", direction_str);
9279 return CMD_WARNING_CONFIG_FAILED;
9280 }
9281
9282 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9283
9284 if (yes) {
9285 SET_FLAG(bgp->af_flags[afi][safi], flag);
9286 if (!previous_state) {
9287 /* trigger export current vrf */
9288 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9289 }
9290 } else {
9291 if (previous_state) {
9292 /* trigger un-export current vrf */
9293 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9294 }
9295 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9296 }
9297
9298 hook_call(bgp_snmp_init_stats, bgp);
9299
9300 return CMD_SUCCESS;
9301 }
9302
9303 DEFPY (af_routetarget_import,
9304 af_routetarget_import_cmd,
9305 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9306 NO_STR
9307 "Specify route target list\n"
9308 "Specify route target list\n"
9309 "Specify route target list\n"
9310 "Specify route target list\n"
9311 "Flow-spec redirect type route target\n"
9312 "Import routes to this address-family\n"
9313 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9314 {
9315 VTY_DECLVAR_CONTEXT(bgp, bgp);
9316 int ret;
9317 struct ecommunity *ecom = NULL;
9318 afi_t afi;
9319 int idx = 0, idx_unused = 0;
9320 bool yes = true;
9321 bool rt6 = false;
9322
9323 if (argv_find(argv, argc, "no", &idx))
9324 yes = false;
9325
9326 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9327 argv_find(argv, argc, "route-target6", &idx_unused))
9328 rt6 = true;
9329
9330 afi = vpn_policy_getafi(vty, bgp, false);
9331 if (afi == AFI_MAX)
9332 return CMD_WARNING_CONFIG_FAILED;
9333
9334 if (rt6 && afi != AFI_IP6)
9335 return CMD_WARNING_CONFIG_FAILED;
9336
9337 if (yes) {
9338 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9339 vty_out(vty, "%% Missing RTLIST\n");
9340 return CMD_WARNING_CONFIG_FAILED;
9341 }
9342 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9343 if (ret != CMD_SUCCESS)
9344 return ret;
9345 }
9346
9347 if (yes) {
9348 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9349 ecommunity_free(&bgp->vpn_policy[afi]
9350 .import_redirect_rtlist);
9351 bgp->vpn_policy[afi].import_redirect_rtlist =
9352 ecommunity_dup(ecom);
9353 } else {
9354 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9355 ecommunity_free(&bgp->vpn_policy[afi]
9356 .import_redirect_rtlist);
9357 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9358 }
9359
9360 if (ecom)
9361 ecommunity_free(&ecom);
9362
9363 return CMD_SUCCESS;
9364 }
9365
9366 DEFUN_NOSH (address_family_ipv4_safi,
9367 address_family_ipv4_safi_cmd,
9368 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9369 "Enter Address Family command mode\n"
9370 BGP_AF_STR
9371 BGP_SAFI_WITH_LABEL_HELP_STR)
9372 {
9373
9374 if (argc == 3) {
9375 VTY_DECLVAR_CONTEXT(bgp, bgp);
9376 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9377 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9378 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9379 && safi != SAFI_EVPN) {
9380 vty_out(vty,
9381 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9382 return CMD_WARNING_CONFIG_FAILED;
9383 }
9384 vty->node = bgp_node_type(AFI_IP, safi);
9385 } else
9386 vty->node = BGP_IPV4_NODE;
9387
9388 return CMD_SUCCESS;
9389 }
9390
9391 DEFUN_NOSH (address_family_ipv6_safi,
9392 address_family_ipv6_safi_cmd,
9393 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9394 "Enter Address Family command mode\n"
9395 BGP_AF_STR
9396 BGP_SAFI_WITH_LABEL_HELP_STR)
9397 {
9398 if (argc == 3) {
9399 VTY_DECLVAR_CONTEXT(bgp, bgp);
9400 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9401 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9402 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9403 && safi != SAFI_EVPN) {
9404 vty_out(vty,
9405 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9406 return CMD_WARNING_CONFIG_FAILED;
9407 }
9408 vty->node = bgp_node_type(AFI_IP6, safi);
9409 } else
9410 vty->node = BGP_IPV6_NODE;
9411
9412 return CMD_SUCCESS;
9413 }
9414
9415 #ifdef KEEP_OLD_VPN_COMMANDS
9416 DEFUN_NOSH (address_family_vpnv4,
9417 address_family_vpnv4_cmd,
9418 "address-family vpnv4 [unicast]",
9419 "Enter Address Family command mode\n"
9420 BGP_AF_STR
9421 BGP_AF_MODIFIER_STR)
9422 {
9423 vty->node = BGP_VPNV4_NODE;
9424 return CMD_SUCCESS;
9425 }
9426
9427 DEFUN_NOSH (address_family_vpnv6,
9428 address_family_vpnv6_cmd,
9429 "address-family vpnv6 [unicast]",
9430 "Enter Address Family command mode\n"
9431 BGP_AF_STR
9432 BGP_AF_MODIFIER_STR)
9433 {
9434 vty->node = BGP_VPNV6_NODE;
9435 return CMD_SUCCESS;
9436 }
9437 #endif /* KEEP_OLD_VPN_COMMANDS */
9438
9439 DEFUN_NOSH (address_family_evpn,
9440 address_family_evpn_cmd,
9441 "address-family l2vpn evpn",
9442 "Enter Address Family command mode\n"
9443 BGP_AF_STR
9444 BGP_AF_MODIFIER_STR)
9445 {
9446 VTY_DECLVAR_CONTEXT(bgp, bgp);
9447 vty->node = BGP_EVPN_NODE;
9448 return CMD_SUCCESS;
9449 }
9450
9451 DEFUN_NOSH (bgp_segment_routing_srv6,
9452 bgp_segment_routing_srv6_cmd,
9453 "segment-routing srv6",
9454 "Segment-Routing configuration\n"
9455 "Segment-Routing SRv6 configuration\n")
9456 {
9457 VTY_DECLVAR_CONTEXT(bgp, bgp);
9458 bgp->srv6_enabled = true;
9459 vty->node = BGP_SRV6_NODE;
9460 return CMD_SUCCESS;
9461 }
9462
9463 DEFUN (no_bgp_segment_routing_srv6,
9464 no_bgp_segment_routing_srv6_cmd,
9465 "no segment-routing srv6",
9466 NO_STR
9467 "Segment-Routing configuration\n"
9468 "Segment-Routing SRv6 configuration\n")
9469 {
9470 VTY_DECLVAR_CONTEXT(bgp, bgp);
9471
9472 if (strlen(bgp->srv6_locator_name) > 0)
9473 if (bgp_srv6_locator_unset(bgp) < 0)
9474 return CMD_WARNING_CONFIG_FAILED;
9475
9476 bgp->srv6_enabled = false;
9477 return CMD_SUCCESS;
9478 }
9479
9480 DEFPY (bgp_srv6_locator,
9481 bgp_srv6_locator_cmd,
9482 "locator NAME$name",
9483 "Specify SRv6 locator\n"
9484 "Specify SRv6 locator\n")
9485 {
9486 VTY_DECLVAR_CONTEXT(bgp, bgp);
9487 int ret;
9488
9489 if (strlen(bgp->srv6_locator_name) > 0
9490 && strcmp(name, bgp->srv6_locator_name) != 0) {
9491 vty_out(vty, "srv6 locator is already configured\n");
9492 return CMD_WARNING_CONFIG_FAILED;
9493 }
9494
9495 snprintf(bgp->srv6_locator_name,
9496 sizeof(bgp->srv6_locator_name), "%s", name);
9497
9498 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9499 if (ret < 0)
9500 return CMD_WARNING_CONFIG_FAILED;
9501
9502 return CMD_SUCCESS;
9503 }
9504
9505 DEFPY (no_bgp_srv6_locator,
9506 no_bgp_srv6_locator_cmd,
9507 "no locator NAME$name",
9508 NO_STR
9509 "Specify SRv6 locator\n"
9510 "Specify SRv6 locator\n")
9511 {
9512 VTY_DECLVAR_CONTEXT(bgp, bgp);
9513
9514 /* when locator isn't configured, do nothing */
9515 if (strlen(bgp->srv6_locator_name) < 1)
9516 return CMD_SUCCESS;
9517
9518 /* name validation */
9519 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9520 vty_out(vty, "%% No srv6 locator is configured\n");
9521 return CMD_WARNING_CONFIG_FAILED;
9522 }
9523
9524 /* unset locator */
9525 if (bgp_srv6_locator_unset(bgp) < 0)
9526 return CMD_WARNING_CONFIG_FAILED;
9527
9528 return CMD_SUCCESS;
9529 }
9530
9531 DEFPY (show_bgp_srv6,
9532 show_bgp_srv6_cmd,
9533 "show bgp segment-routing srv6",
9534 SHOW_STR
9535 BGP_STR
9536 "BGP Segment Routing\n"
9537 "BGP Segment Routing SRv6\n")
9538 {
9539 struct bgp *bgp;
9540 struct listnode *node;
9541 struct srv6_locator_chunk *chunk;
9542 struct bgp_srv6_function *func;
9543 struct in6_addr *tovpn4_sid;
9544 struct in6_addr *tovpn6_sid;
9545 char buf[256];
9546 char buf_tovpn4_sid[256];
9547 char buf_tovpn6_sid[256];
9548
9549 bgp = bgp_get_default();
9550 if (!bgp)
9551 return CMD_SUCCESS;
9552
9553 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9554 vty_out(vty, "locator_chunks:\n");
9555 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9556 prefix2str(&chunk->prefix, buf, sizeof(buf));
9557 vty_out(vty, "- %s\n", buf);
9558 }
9559
9560 vty_out(vty, "functions:\n");
9561 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9562 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9563 vty_out(vty, "- sid: %s\n", buf);
9564 vty_out(vty, " locator: %s\n", func->locator_name);
9565 }
9566
9567 vty_out(vty, "bgps:\n");
9568 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9569 vty_out(vty, "- name: %s\n",
9570 bgp->name ? bgp->name : "default");
9571
9572 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9573 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9574 if (tovpn4_sid)
9575 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9576 sizeof(buf_tovpn4_sid));
9577 if (tovpn6_sid)
9578 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9579 sizeof(buf_tovpn6_sid));
9580
9581 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9582 tovpn4_sid ? buf_tovpn4_sid : "none");
9583 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9584 tovpn6_sid ? buf_tovpn6_sid : "none");
9585 }
9586
9587 return CMD_SUCCESS;
9588 }
9589
9590 DEFUN_NOSH (exit_address_family,
9591 exit_address_family_cmd,
9592 "exit-address-family",
9593 "Exit from Address Family configuration mode\n")
9594 {
9595 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9596 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9597 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9598 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9599 || vty->node == BGP_EVPN_NODE
9600 || vty->node == BGP_FLOWSPECV4_NODE
9601 || vty->node == BGP_FLOWSPECV6_NODE)
9602 vty->node = BGP_NODE;
9603 return CMD_SUCCESS;
9604 }
9605
9606 /* Recalculate bestpath and re-advertise a prefix */
9607 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9608 const char *ip_str, afi_t afi, safi_t safi,
9609 struct prefix_rd *prd)
9610 {
9611 int ret;
9612 struct prefix match;
9613 struct bgp_dest *dest;
9614 struct bgp_dest *rm;
9615 struct bgp *bgp;
9616 struct bgp_table *table;
9617 struct bgp_table *rib;
9618
9619 /* BGP structure lookup. */
9620 if (view_name) {
9621 bgp = bgp_lookup_by_name(view_name);
9622 if (bgp == NULL) {
9623 vty_out(vty, "%% Can't find BGP instance %s\n",
9624 view_name);
9625 return CMD_WARNING;
9626 }
9627 } else {
9628 bgp = bgp_get_default();
9629 if (bgp == NULL) {
9630 vty_out(vty, "%% No BGP process is configured\n");
9631 return CMD_WARNING;
9632 }
9633 }
9634
9635 /* Check IP address argument. */
9636 ret = str2prefix(ip_str, &match);
9637 if (!ret) {
9638 vty_out(vty, "%% address is malformed\n");
9639 return CMD_WARNING;
9640 }
9641
9642 match.family = afi2family(afi);
9643 rib = bgp->rib[afi][safi];
9644
9645 if (safi == SAFI_MPLS_VPN) {
9646 for (dest = bgp_table_top(rib); dest;
9647 dest = bgp_route_next(dest)) {
9648 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9649
9650 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9651 continue;
9652
9653 table = bgp_dest_get_bgp_table_info(dest);
9654 if (table == NULL)
9655 continue;
9656
9657 rm = bgp_node_match(table, &match);
9658 if (rm != NULL) {
9659 const struct prefix *rm_p =
9660 bgp_dest_get_prefix(rm);
9661
9662 if (rm_p->prefixlen == match.prefixlen) {
9663 SET_FLAG(rm->flags,
9664 BGP_NODE_USER_CLEAR);
9665 bgp_process(bgp, rm, afi, safi);
9666 }
9667 bgp_dest_unlock_node(rm);
9668 }
9669 }
9670 } else {
9671 dest = bgp_node_match(rib, &match);
9672 if (dest != NULL) {
9673 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9674
9675 if (dest_p->prefixlen == match.prefixlen) {
9676 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9677 bgp_process(bgp, dest, afi, safi);
9678 }
9679 bgp_dest_unlock_node(dest);
9680 }
9681 }
9682
9683 return CMD_SUCCESS;
9684 }
9685
9686 /* one clear bgp command to rule them all */
9687 DEFUN (clear_ip_bgp_all,
9688 clear_ip_bgp_all_cmd,
9689 "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>]",
9690 CLEAR_STR
9691 IP_STR
9692 BGP_STR
9693 BGP_INSTANCE_HELP_STR
9694 BGP_AFI_HELP_STR
9695 BGP_AF_STR
9696 BGP_SAFI_WITH_LABEL_HELP_STR
9697 BGP_AF_MODIFIER_STR
9698 "Clear all peers\n"
9699 "BGP IPv4 neighbor to clear\n"
9700 "BGP IPv6 neighbor to clear\n"
9701 "BGP neighbor on interface to clear\n"
9702 "Clear peers with the AS number\n"
9703 "Clear all external peers\n"
9704 "Clear all members of peer-group\n"
9705 "BGP peer-group name\n"
9706 BGP_SOFT_STR
9707 BGP_SOFT_IN_STR
9708 BGP_SOFT_OUT_STR
9709 BGP_SOFT_IN_STR
9710 "Push out prefix-list ORF and do inbound soft reconfig\n"
9711 BGP_SOFT_OUT_STR
9712 "Reset message statistics\n")
9713 {
9714 char *vrf = NULL;
9715
9716 afi_t afi = AFI_UNSPEC;
9717 safi_t safi = SAFI_UNSPEC;
9718 enum clear_sort clr_sort = clear_peer;
9719 enum bgp_clear_type clr_type;
9720 char *clr_arg = NULL;
9721
9722 int idx = 0;
9723
9724 /* clear [ip] bgp */
9725 if (argv_find(argv, argc, "ip", &idx))
9726 afi = AFI_IP;
9727
9728 /* [<vrf> VIEWVRFNAME] */
9729 if (argv_find(argv, argc, "vrf", &idx)) {
9730 vrf = argv[idx + 1]->arg;
9731 idx += 2;
9732 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9733 vrf = NULL;
9734 } else if (argv_find(argv, argc, "view", &idx)) {
9735 /* [<view> VIEWVRFNAME] */
9736 vrf = argv[idx + 1]->arg;
9737 idx += 2;
9738 }
9739 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9740 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9741 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9742
9743 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9744 if (argv_find(argv, argc, "*", &idx)) {
9745 clr_sort = clear_all;
9746 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9747 clr_sort = clear_peer;
9748 clr_arg = argv[idx]->arg;
9749 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9750 clr_sort = clear_peer;
9751 clr_arg = argv[idx]->arg;
9752 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9753 clr_sort = clear_group;
9754 idx++;
9755 clr_arg = argv[idx]->arg;
9756 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9757 clr_sort = clear_peer;
9758 clr_arg = argv[idx]->arg;
9759 } else if (argv_find(argv, argc, "WORD", &idx)) {
9760 clr_sort = clear_peer;
9761 clr_arg = argv[idx]->arg;
9762 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9763 clr_sort = clear_as;
9764 clr_arg = argv[idx]->arg;
9765 } else if (argv_find(argv, argc, "external", &idx)) {
9766 clr_sort = clear_external;
9767 }
9768
9769 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9770 if (argv_find(argv, argc, "soft", &idx)) {
9771 if (argv_find(argv, argc, "in", &idx)
9772 || argv_find(argv, argc, "out", &idx))
9773 clr_type = strmatch(argv[idx]->text, "in")
9774 ? BGP_CLEAR_SOFT_IN
9775 : BGP_CLEAR_SOFT_OUT;
9776 else
9777 clr_type = BGP_CLEAR_SOFT_BOTH;
9778 } else if (argv_find(argv, argc, "in", &idx)) {
9779 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9780 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9781 : BGP_CLEAR_SOFT_IN;
9782 } else if (argv_find(argv, argc, "out", &idx)) {
9783 clr_type = BGP_CLEAR_SOFT_OUT;
9784 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9785 clr_type = BGP_CLEAR_MESSAGE_STATS;
9786 } else
9787 clr_type = BGP_CLEAR_SOFT_NONE;
9788
9789 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9790 }
9791
9792 DEFUN (clear_ip_bgp_prefix,
9793 clear_ip_bgp_prefix_cmd,
9794 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9795 CLEAR_STR
9796 IP_STR
9797 BGP_STR
9798 BGP_INSTANCE_HELP_STR
9799 "Clear bestpath and re-advertise\n"
9800 "IPv4 prefix\n")
9801 {
9802 char *vrf = NULL;
9803 char *prefix = NULL;
9804
9805 int idx = 0;
9806
9807 /* [<view|vrf> VIEWVRFNAME] */
9808 if (argv_find(argv, argc, "vrf", &idx)) {
9809 vrf = argv[idx + 1]->arg;
9810 idx += 2;
9811 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9812 vrf = NULL;
9813 } else if (argv_find(argv, argc, "view", &idx)) {
9814 /* [<view> VIEWVRFNAME] */
9815 vrf = argv[idx + 1]->arg;
9816 idx += 2;
9817 }
9818
9819 prefix = argv[argc - 1]->arg;
9820
9821 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9822 }
9823
9824 DEFUN (clear_bgp_ipv6_safi_prefix,
9825 clear_bgp_ipv6_safi_prefix_cmd,
9826 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9827 CLEAR_STR
9828 IP_STR
9829 BGP_STR
9830 BGP_AF_STR
9831 BGP_SAFI_HELP_STR
9832 "Clear bestpath and re-advertise\n"
9833 "IPv6 prefix\n")
9834 {
9835 int idx_safi = 0;
9836 int idx_ipv6_prefix = 0;
9837 safi_t safi = SAFI_UNICAST;
9838 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9839 argv[idx_ipv6_prefix]->arg : NULL;
9840
9841 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9842 return bgp_clear_prefix(
9843 vty, NULL, prefix, AFI_IP6,
9844 safi, NULL);
9845 }
9846
9847 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9848 clear_bgp_instance_ipv6_safi_prefix_cmd,
9849 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9850 CLEAR_STR
9851 IP_STR
9852 BGP_STR
9853 BGP_INSTANCE_HELP_STR
9854 BGP_AF_STR
9855 BGP_SAFI_HELP_STR
9856 "Clear bestpath and re-advertise\n"
9857 "IPv6 prefix\n")
9858 {
9859 int idx_safi = 0;
9860 int idx_vrfview = 0;
9861 int idx_ipv6_prefix = 0;
9862 safi_t safi = SAFI_UNICAST;
9863 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9864 argv[idx_ipv6_prefix]->arg : NULL;
9865 char *vrfview = NULL;
9866
9867 /* [<view|vrf> VIEWVRFNAME] */
9868 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9869 vrfview = argv[idx_vrfview + 1]->arg;
9870 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9871 vrfview = NULL;
9872 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9873 /* [<view> VIEWVRFNAME] */
9874 vrfview = argv[idx_vrfview + 1]->arg;
9875 }
9876 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9877
9878 return bgp_clear_prefix(
9879 vty, vrfview, prefix,
9880 AFI_IP6, safi, NULL);
9881 }
9882
9883 DEFUN (show_bgp_views,
9884 show_bgp_views_cmd,
9885 "show [ip] bgp views",
9886 SHOW_STR
9887 IP_STR
9888 BGP_STR
9889 "Show the defined BGP views\n")
9890 {
9891 struct list *inst = bm->bgp;
9892 struct listnode *node;
9893 struct bgp *bgp;
9894
9895 vty_out(vty, "Defined BGP views:\n");
9896 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9897 /* Skip VRFs. */
9898 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9899 continue;
9900 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9901 bgp->as);
9902 }
9903
9904 return CMD_SUCCESS;
9905 }
9906
9907 DEFUN (show_bgp_vrfs,
9908 show_bgp_vrfs_cmd,
9909 "show [ip] bgp vrfs [json]",
9910 SHOW_STR
9911 IP_STR
9912 BGP_STR
9913 "Show BGP VRFs\n"
9914 JSON_STR)
9915 {
9916 char buf[ETHER_ADDR_STRLEN];
9917 struct list *inst = bm->bgp;
9918 struct listnode *node;
9919 struct bgp *bgp;
9920 bool uj = use_json(argc, argv);
9921 json_object *json = NULL;
9922 json_object *json_vrfs = NULL;
9923 int count = 0;
9924
9925 if (uj) {
9926 json = json_object_new_object();
9927 json_vrfs = json_object_new_object();
9928 }
9929
9930 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9931 const char *name, *type;
9932 struct peer *peer;
9933 struct listnode *node2, *nnode2;
9934 int peers_cfg, peers_estb;
9935 json_object *json_vrf = NULL;
9936
9937 /* Skip Views. */
9938 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9939 continue;
9940
9941 count++;
9942 if (!uj && count == 1) {
9943 vty_out(vty,
9944 "%4s %-5s %-16s %9s %10s %-37s\n",
9945 "Type", "Id", "routerId", "#PeersCfg",
9946 "#PeersEstb", "Name");
9947 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9948 "L3-VNI", "RouterMAC", "Interface");
9949 }
9950
9951 peers_cfg = peers_estb = 0;
9952 if (uj)
9953 json_vrf = json_object_new_object();
9954
9955
9956 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9957 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9958 continue;
9959 peers_cfg++;
9960 if (peer_established(peer))
9961 peers_estb++;
9962 }
9963
9964 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9965 name = VRF_DEFAULT_NAME;
9966 type = "DFLT";
9967 } else {
9968 name = bgp->name;
9969 type = "VRF";
9970 }
9971
9972
9973 if (uj) {
9974 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9975 ? -1
9976 : (int64_t)bgp->vrf_id;
9977 char buf[BUFSIZ] = {0};
9978
9979 json_object_string_add(json_vrf, "type", type);
9980 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9981 json_object_string_addf(json_vrf, "routerId", "%pI4",
9982 &bgp->router_id);
9983 json_object_int_add(json_vrf, "numConfiguredPeers",
9984 peers_cfg);
9985 json_object_int_add(json_vrf, "numEstablishedPeers",
9986 peers_estb);
9987
9988 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
9989 json_object_string_add(
9990 json_vrf, "rmac",
9991 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
9992 json_object_string_add(json_vrf, "interface",
9993 ifindex2ifname(bgp->l3vni_svi_ifindex,
9994 bgp->vrf_id));
9995 json_object_object_add(json_vrfs, name, json_vrf);
9996 } else {
9997 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
9998 type,
9999 bgp->vrf_id == VRF_UNKNOWN ? -1
10000 : (int)bgp->vrf_id,
10001 &bgp->router_id, peers_cfg, peers_estb, name);
10002 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10003 bgp->l3vni,
10004 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10005 ifindex2ifname(bgp->l3vni_svi_ifindex,
10006 bgp->vrf_id));
10007 }
10008 }
10009
10010 if (uj) {
10011 json_object_object_add(json, "vrfs", json_vrfs);
10012
10013 json_object_int_add(json, "totalVrfs", count);
10014
10015 vty_json(vty, json);
10016 } else {
10017 if (count)
10018 vty_out(vty,
10019 "\nTotal number of VRFs (including default): %d\n",
10020 count);
10021 }
10022
10023 return CMD_SUCCESS;
10024 }
10025
10026 DEFUN (show_bgp_mac_hash,
10027 show_bgp_mac_hash_cmd,
10028 "show bgp mac hash",
10029 SHOW_STR
10030 BGP_STR
10031 "Mac Address\n"
10032 "Mac Address database\n")
10033 {
10034 bgp_mac_dump_table(vty);
10035
10036 return CMD_SUCCESS;
10037 }
10038
10039 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10040 {
10041 struct vty *vty = (struct vty *)args;
10042 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10043
10044 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10045 }
10046
10047 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10048 {
10049 vty_out(vty, "self nexthop database:\n");
10050 bgp_nexthop_show_address_hash(vty, bgp);
10051
10052 vty_out(vty, "Tunnel-ip database:\n");
10053 hash_iterate(bgp->tip_hash,
10054 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10055 vty);
10056 }
10057
10058 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10059 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10060 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10061 "martian next-hops\n"
10062 "martian next-hop database\n")
10063 {
10064 struct bgp *bgp = NULL;
10065 int idx = 0;
10066 char *name = NULL;
10067
10068 /* [<vrf> VIEWVRFNAME] */
10069 if (argv_find(argv, argc, "vrf", &idx)) {
10070 name = argv[idx + 1]->arg;
10071 if (name && strmatch(name, VRF_DEFAULT_NAME))
10072 name = NULL;
10073 } else if (argv_find(argv, argc, "view", &idx))
10074 /* [<view> VIEWVRFNAME] */
10075 name = argv[idx + 1]->arg;
10076 if (name)
10077 bgp = bgp_lookup_by_name(name);
10078 else
10079 bgp = bgp_get_default();
10080
10081 if (!bgp) {
10082 vty_out(vty, "%% No BGP process is configured\n");
10083 return CMD_WARNING;
10084 }
10085 bgp_show_martian_nexthops(vty, bgp);
10086
10087 return CMD_SUCCESS;
10088 }
10089
10090 DEFUN (show_bgp_memory,
10091 show_bgp_memory_cmd,
10092 "show [ip] bgp memory",
10093 SHOW_STR
10094 IP_STR
10095 BGP_STR
10096 "Global BGP memory statistics\n")
10097 {
10098 char memstrbuf[MTYPE_MEMSTR_LEN];
10099 unsigned long count;
10100
10101 /* RIB related usage stats */
10102 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10103 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10104 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10105 count * sizeof(struct bgp_dest)));
10106
10107 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10108 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10109 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10110 count * sizeof(struct bgp_path_info)));
10111 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10112 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10113 count,
10114 mtype_memstr(
10115 memstrbuf, sizeof(memstrbuf),
10116 count * sizeof(struct bgp_path_info_extra)));
10117
10118 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10119 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10120 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10121 count * sizeof(struct bgp_static)));
10122
10123 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10124 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10125 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10126 count * sizeof(struct bpacket)));
10127
10128 /* Adj-In/Out */
10129 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10130 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10131 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10132 count * sizeof(struct bgp_adj_in)));
10133 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10134 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10135 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10136 count * sizeof(struct bgp_adj_out)));
10137
10138 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10139 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10140 count,
10141 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10142 count * sizeof(struct bgp_nexthop_cache)));
10143
10144 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10145 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10146 count,
10147 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10148 count * sizeof(struct bgp_damp_info)));
10149
10150 /* Attributes */
10151 count = attr_count();
10152 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10153 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10154 count * sizeof(struct attr)));
10155
10156 if ((count = attr_unknown_count()))
10157 vty_out(vty, "%ld unknown attributes\n", count);
10158
10159 /* AS_PATH attributes */
10160 count = aspath_count();
10161 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10162 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10163 count * sizeof(struct aspath)));
10164
10165 count = mtype_stats_alloc(MTYPE_AS_SEG);
10166 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10167 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10168 count * sizeof(struct assegment)));
10169
10170 /* Other attributes */
10171 if ((count = community_count()))
10172 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10173 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10174 count * sizeof(struct community)));
10175 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10176 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10177 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10178 count * sizeof(struct ecommunity)));
10179 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10180 vty_out(vty,
10181 "%ld BGP large-community entries, using %s of memory\n",
10182 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10183 count * sizeof(struct lcommunity)));
10184
10185 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10186 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10187 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10188 count * sizeof(struct cluster_list)));
10189
10190 /* Peer related usage */
10191 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10192 vty_out(vty, "%ld peers, using %s of memory\n", count,
10193 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10194 count * sizeof(struct peer)));
10195
10196 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10197 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10198 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10199 count * sizeof(struct peer_group)));
10200
10201 /* Other */
10202 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10203 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10204 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10205 count * sizeof(regex_t)));
10206 return CMD_SUCCESS;
10207 }
10208
10209 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10210 {
10211 json_object *bestpath = json_object_new_object();
10212
10213 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10214 json_object_string_add(bestpath, "asPath", "ignore");
10215
10216 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10217 json_object_string_add(bestpath, "asPath", "confed");
10218
10219 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10220 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10221 json_object_string_add(bestpath, "multiPathRelax",
10222 "as-set");
10223 else
10224 json_object_string_add(bestpath, "multiPathRelax",
10225 "true");
10226 } else
10227 json_object_string_add(bestpath, "multiPathRelax", "false");
10228
10229 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10230 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10231
10232 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10233 json_object_string_add(bestpath, "compareRouterId", "true");
10234 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10235 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10236 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10237 json_object_string_add(bestpath, "med", "confed");
10238 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10239 json_object_string_add(bestpath, "med",
10240 "missing-as-worst");
10241 else
10242 json_object_string_add(bestpath, "med", "true");
10243 }
10244
10245 json_object_object_add(json, "bestPath", bestpath);
10246 }
10247
10248 /* Print the error code/subcode for why the peer is down */
10249 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10250 json_object *json_peer, bool use_json)
10251 {
10252 const char *code_str;
10253 const char *subcode_str;
10254
10255 if (use_json) {
10256 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10257 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10258 char errorcodesubcode_hexstr[5];
10259 char errorcodesubcode_str[256];
10260
10261 code_str = bgp_notify_code_str(peer->notify.code);
10262 subcode_str = bgp_notify_subcode_str(
10263 peer->notify.code,
10264 peer->notify.subcode);
10265
10266 snprintf(errorcodesubcode_hexstr,
10267 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10268 peer->notify.code, peer->notify.subcode);
10269 json_object_string_add(json_peer,
10270 "lastErrorCodeSubcode",
10271 errorcodesubcode_hexstr);
10272 snprintf(errorcodesubcode_str, 255, "%s%s",
10273 code_str, subcode_str);
10274 json_object_string_add(json_peer,
10275 "lastNotificationReason",
10276 errorcodesubcode_str);
10277 json_object_boolean_add(json_peer,
10278 "lastNotificationHardReset",
10279 peer->notify.hard_reset);
10280 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10281 && peer->notify.code == BGP_NOTIFY_CEASE
10282 && (peer->notify.subcode
10283 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10284 || peer->notify.subcode
10285 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10286 && peer->notify.length) {
10287 char msgbuf[1024];
10288 const char *msg_str;
10289
10290 msg_str = bgp_notify_admin_message(
10291 msgbuf, sizeof(msgbuf),
10292 (uint8_t *)peer->notify.data,
10293 peer->notify.length);
10294 if (msg_str)
10295 json_object_string_add(
10296 json_peer,
10297 "lastShutdownDescription",
10298 msg_str);
10299 }
10300
10301 }
10302 json_object_string_add(json_peer, "lastResetDueTo",
10303 peer_down_str[(int)peer->last_reset]);
10304 json_object_int_add(json_peer, "lastResetCode",
10305 peer->last_reset);
10306 } else {
10307 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10308 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10309 code_str = bgp_notify_code_str(peer->notify.code);
10310 subcode_str =
10311 bgp_notify_subcode_str(peer->notify.code,
10312 peer->notify.subcode);
10313 vty_out(vty, " Notification %s (%s%s%s)\n",
10314 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10315 ? "sent"
10316 : "received",
10317 code_str, subcode_str,
10318 peer->notify.hard_reset
10319 ? bgp_notify_subcode_str(
10320 BGP_NOTIFY_CEASE,
10321 BGP_NOTIFY_CEASE_HARD_RESET)
10322 : "");
10323 } else {
10324 vty_out(vty, " %s\n",
10325 peer_down_str[(int)peer->last_reset]);
10326 }
10327 }
10328 }
10329
10330 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10331 safi_t safi)
10332 {
10333 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10334 }
10335
10336 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10337 struct peer *peer, json_object *json_peer,
10338 int max_neighbor_width, bool use_json)
10339 {
10340 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10341 int len;
10342
10343 if (use_json) {
10344 if (peer_dynamic_neighbor(peer))
10345 json_object_boolean_true_add(json_peer,
10346 "dynamicPeer");
10347 if (peer->hostname)
10348 json_object_string_add(json_peer, "hostname",
10349 peer->hostname);
10350
10351 if (peer->domainname)
10352 json_object_string_add(json_peer, "domainname",
10353 peer->domainname);
10354 json_object_int_add(json_peer, "connectionsEstablished",
10355 peer->established);
10356 json_object_int_add(json_peer, "connectionsDropped",
10357 peer->dropped);
10358 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10359 use_json, json_peer);
10360 if (peer_established(peer))
10361 json_object_string_add(json_peer, "lastResetDueTo",
10362 "AFI/SAFI Not Negotiated");
10363 else
10364 bgp_show_peer_reset(NULL, peer, json_peer, true);
10365 } else {
10366 dn_flag[1] = '\0';
10367 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10368 if (peer->hostname
10369 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10370 len = vty_out(vty, "%s%s(%s)", dn_flag,
10371 peer->hostname, peer->host);
10372 else
10373 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10374
10375 /* pad the neighbor column with spaces */
10376 if (len < max_neighbor_width)
10377 vty_out(vty, "%*s", max_neighbor_width - len,
10378 " ");
10379 vty_out(vty, "%7d %7d %9s", peer->established,
10380 peer->dropped,
10381 peer_uptime(peer->uptime, timebuf,
10382 BGP_UPTIME_LEN, 0, NULL));
10383 if (peer_established(peer))
10384 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10385 else
10386 bgp_show_peer_reset(vty, peer, NULL,
10387 false);
10388 }
10389 }
10390
10391 /* Strip peer's description to the given size. */
10392 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10393 {
10394 static char stripped[BUFSIZ];
10395 uint32_t i = 0;
10396 uint32_t last_space = 0;
10397
10398 while (i < size) {
10399 if (*(desc + i) == 0) {
10400 stripped[i] = '\0';
10401 return stripped;
10402 }
10403 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10404 last_space = i;
10405 stripped[i] = *(desc + i);
10406 i++;
10407 }
10408
10409 if (last_space > size)
10410 stripped[size + 1] = '\0';
10411 else
10412 stripped[last_space] = '\0';
10413
10414 return stripped;
10415 }
10416
10417 /* Determine whether var peer should be filtered out of the summary. */
10418 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10419 struct peer *fpeer, int as_type,
10420 as_t as)
10421 {
10422
10423 /* filter neighbor XXXX */
10424 if (fpeer && fpeer != peer)
10425 return true;
10426
10427 /* filter remote-as (internal|external) */
10428 if (as_type != AS_UNSPECIFIED) {
10429 if (peer->as_type == AS_SPECIFIED) {
10430 if (as_type == AS_INTERNAL) {
10431 if (peer->as != peer->local_as)
10432 return true;
10433 } else if (peer->as == peer->local_as)
10434 return true;
10435 } else if (as_type != peer->as_type)
10436 return true;
10437 } else if (as && as != peer->as) /* filter remote-as XXX */
10438 return true;
10439
10440 return false;
10441 }
10442
10443 /* Show BGP peer's summary information.
10444 *
10445 * Peer's description is stripped according to if `wide` option is given
10446 * or not.
10447 *
10448 * When adding new columns to `show bgp summary` output, please make
10449 * sure `Desc` is the lastest column to show because it can contain
10450 * whitespaces and the whole output will be tricky.
10451 */
10452 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10453 struct peer *fpeer, int as_type, as_t as,
10454 uint16_t show_flags)
10455 {
10456 struct peer *peer;
10457 struct listnode *node, *nnode;
10458 unsigned int count = 0, dn_count = 0;
10459 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10460 char neighbor_buf[VTY_BUFSIZ];
10461 int neighbor_col_default_width = 16;
10462 int len, failed_count = 0;
10463 unsigned int filtered_count = 0;
10464 int max_neighbor_width = 0;
10465 int pfx_rcd_safi;
10466 json_object *json = NULL;
10467 json_object *json_peer = NULL;
10468 json_object *json_peers = NULL;
10469 struct peer_af *paf;
10470 struct bgp_filter *filter;
10471 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10472 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10473 bool show_established =
10474 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10475 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10476 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10477
10478 /* labeled-unicast routes are installed in the unicast table so in order
10479 * to
10480 * display the correct PfxRcd value we must look at SAFI_UNICAST
10481 */
10482
10483 if (safi == SAFI_LABELED_UNICAST)
10484 pfx_rcd_safi = SAFI_UNICAST;
10485 else
10486 pfx_rcd_safi = safi;
10487
10488 if (use_json) {
10489 json = json_object_new_object();
10490 json_peers = json_object_new_object();
10491 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10492 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10493 as_type, as)) {
10494 filtered_count++;
10495 count++;
10496 continue;
10497 }
10498
10499 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10500 continue;
10501
10502 if (peer->afc[afi][safi]) {
10503 /* See if we have at least a single failed peer */
10504 if (bgp_has_peer_failed(peer, afi, safi))
10505 failed_count++;
10506 count++;
10507 }
10508 if (peer_dynamic_neighbor(peer))
10509 dn_count++;
10510 }
10511
10512 } else {
10513 /* Loop over all neighbors that will be displayed to determine
10514 * how many
10515 * characters are needed for the Neighbor column
10516 */
10517 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10518 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10519 as_type, as)) {
10520 filtered_count++;
10521 count++;
10522 continue;
10523 }
10524
10525 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10526 continue;
10527
10528 if (peer->afc[afi][safi]) {
10529 memset(dn_flag, '\0', sizeof(dn_flag));
10530 if (peer_dynamic_neighbor(peer))
10531 dn_flag[0] = '*';
10532
10533 if (peer->hostname
10534 && CHECK_FLAG(bgp->flags,
10535 BGP_FLAG_SHOW_HOSTNAME))
10536 snprintf(neighbor_buf,
10537 sizeof(neighbor_buf),
10538 "%s%s(%s) ", dn_flag,
10539 peer->hostname, peer->host);
10540 else
10541 snprintf(neighbor_buf,
10542 sizeof(neighbor_buf), "%s%s ",
10543 dn_flag, peer->host);
10544
10545 len = strlen(neighbor_buf);
10546
10547 if (len > max_neighbor_width)
10548 max_neighbor_width = len;
10549
10550 /* See if we have at least a single failed peer */
10551 if (bgp_has_peer_failed(peer, afi, safi))
10552 failed_count++;
10553 count++;
10554 }
10555 }
10556
10557 /* Originally we displayed the Neighbor column as 16
10558 * characters wide so make that the default
10559 */
10560 if (max_neighbor_width < neighbor_col_default_width)
10561 max_neighbor_width = neighbor_col_default_width;
10562 }
10563
10564 if (show_failed && !failed_count) {
10565 if (use_json) {
10566 json_object_int_add(json, "failedPeersCount", 0);
10567 json_object_int_add(json, "dynamicPeers", dn_count);
10568 json_object_int_add(json, "totalPeers", count);
10569
10570 vty_json(vty, json);
10571 } else {
10572 vty_out(vty, "%% No failed BGP neighbors found\n");
10573 }
10574 return CMD_SUCCESS;
10575 }
10576
10577 count = 0; /* Reset the value as its used again */
10578 filtered_count = 0;
10579 dn_count = 0;
10580 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10581 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10582 continue;
10583
10584 if (!peer->afc[afi][safi])
10585 continue;
10586
10587 if (!count) {
10588 unsigned long ents;
10589 char memstrbuf[MTYPE_MEMSTR_LEN];
10590 int64_t vrf_id_ui;
10591
10592 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10593 ? -1
10594 : (int64_t)bgp->vrf_id;
10595
10596 /* Usage summary and header */
10597 if (use_json) {
10598 json_object_string_addf(json, "routerId",
10599 "%pI4",
10600 &bgp->router_id);
10601 json_object_int_add(json, "as", bgp->as);
10602 json_object_int_add(json, "vrfId", vrf_id_ui);
10603 json_object_string_add(
10604 json, "vrfName",
10605 (bgp->inst_type
10606 == BGP_INSTANCE_TYPE_DEFAULT)
10607 ? VRF_DEFAULT_NAME
10608 : bgp->name);
10609 } else {
10610 vty_out(vty,
10611 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10612 &bgp->router_id, bgp->as,
10613 bgp->vrf_id == VRF_UNKNOWN
10614 ? -1
10615 : (int)bgp->vrf_id);
10616 vty_out(vty, "\n");
10617 }
10618
10619 if (bgp_update_delay_configured(bgp)) {
10620 if (use_json) {
10621 json_object_int_add(
10622 json, "updateDelayLimit",
10623 bgp->v_update_delay);
10624
10625 if (bgp->v_update_delay
10626 != bgp->v_establish_wait)
10627 json_object_int_add(
10628 json,
10629 "updateDelayEstablishWait",
10630 bgp->v_establish_wait);
10631
10632 if (bgp_update_delay_active(bgp)) {
10633 json_object_string_add(
10634 json,
10635 "updateDelayFirstNeighbor",
10636 bgp->update_delay_begin_time);
10637 json_object_boolean_true_add(
10638 json,
10639 "updateDelayInProgress");
10640 } else {
10641 if (bgp->update_delay_over) {
10642 json_object_string_add(
10643 json,
10644 "updateDelayFirstNeighbor",
10645 bgp->update_delay_begin_time);
10646 json_object_string_add(
10647 json,
10648 "updateDelayBestpathResumed",
10649 bgp->update_delay_end_time);
10650 json_object_string_add(
10651 json,
10652 "updateDelayZebraUpdateResume",
10653 bgp->update_delay_zebra_resume_time);
10654 json_object_string_add(
10655 json,
10656 "updateDelayPeerUpdateResume",
10657 bgp->update_delay_peers_resume_time);
10658 }
10659 }
10660 } else {
10661 vty_out(vty,
10662 "Read-only mode update-delay limit: %d seconds\n",
10663 bgp->v_update_delay);
10664 if (bgp->v_update_delay
10665 != bgp->v_establish_wait)
10666 vty_out(vty,
10667 " Establish wait: %d seconds\n",
10668 bgp->v_establish_wait);
10669
10670 if (bgp_update_delay_active(bgp)) {
10671 vty_out(vty,
10672 " First neighbor established: %s\n",
10673 bgp->update_delay_begin_time);
10674 vty_out(vty,
10675 " Delay in progress\n");
10676 } else {
10677 if (bgp->update_delay_over) {
10678 vty_out(vty,
10679 " First neighbor established: %s\n",
10680 bgp->update_delay_begin_time);
10681 vty_out(vty,
10682 " Best-paths resumed: %s\n",
10683 bgp->update_delay_end_time);
10684 vty_out(vty,
10685 " zebra update resumed: %s\n",
10686 bgp->update_delay_zebra_resume_time);
10687 vty_out(vty,
10688 " peers update resumed: %s\n",
10689 bgp->update_delay_peers_resume_time);
10690 }
10691 }
10692 }
10693 }
10694
10695 if (use_json) {
10696 if (bgp_maxmed_onstartup_configured(bgp)
10697 && bgp->maxmed_active)
10698 json_object_boolean_true_add(
10699 json, "maxMedOnStartup");
10700 if (bgp->v_maxmed_admin)
10701 json_object_boolean_true_add(
10702 json, "maxMedAdministrative");
10703
10704 json_object_int_add(
10705 json, "tableVersion",
10706 bgp_table_version(bgp->rib[afi][safi]));
10707
10708 ents = bgp_table_count(bgp->rib[afi][safi]);
10709 json_object_int_add(json, "ribCount", ents);
10710 json_object_int_add(
10711 json, "ribMemory",
10712 ents * sizeof(struct bgp_dest));
10713
10714 ents = bgp->af_peer_count[afi][safi];
10715 json_object_int_add(json, "peerCount", ents);
10716 json_object_int_add(json, "peerMemory",
10717 ents * sizeof(struct peer));
10718
10719 if ((ents = listcount(bgp->group))) {
10720 json_object_int_add(
10721 json, "peerGroupCount", ents);
10722 json_object_int_add(
10723 json, "peerGroupMemory",
10724 ents * sizeof(struct
10725 peer_group));
10726 }
10727
10728 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10729 BGP_CONFIG_DAMPENING))
10730 json_object_boolean_true_add(
10731 json, "dampeningEnabled");
10732 } else {
10733 if (!show_terse) {
10734 if (bgp_maxmed_onstartup_configured(bgp)
10735 && bgp->maxmed_active)
10736 vty_out(vty,
10737 "Max-med on-startup active\n");
10738 if (bgp->v_maxmed_admin)
10739 vty_out(vty,
10740 "Max-med administrative active\n");
10741
10742 vty_out(vty,
10743 "BGP table version %" PRIu64
10744 "\n",
10745 bgp_table_version(
10746 bgp->rib[afi][safi]));
10747
10748 ents = bgp_table_count(
10749 bgp->rib[afi][safi]);
10750 vty_out(vty,
10751 "RIB entries %ld, using %s of memory\n",
10752 ents,
10753 mtype_memstr(
10754 memstrbuf,
10755 sizeof(memstrbuf),
10756 ents
10757 * sizeof(
10758 struct
10759 bgp_dest)));
10760
10761 /* Peer related usage */
10762 ents = bgp->af_peer_count[afi][safi];
10763 vty_out(vty,
10764 "Peers %ld, using %s of memory\n",
10765 ents,
10766 mtype_memstr(
10767 memstrbuf,
10768 sizeof(memstrbuf),
10769 ents
10770 * sizeof(
10771 struct
10772 peer)));
10773
10774 if ((ents = listcount(bgp->group)))
10775 vty_out(vty,
10776 "Peer groups %ld, using %s of memory\n",
10777 ents,
10778 mtype_memstr(
10779 memstrbuf,
10780 sizeof(memstrbuf),
10781 ents
10782 * sizeof(
10783 struct
10784 peer_group)));
10785
10786 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10787 BGP_CONFIG_DAMPENING))
10788 vty_out(vty,
10789 "Dampening enabled.\n");
10790 }
10791 if (show_failed) {
10792 vty_out(vty, "\n");
10793
10794 /* Subtract 8 here because 'Neighbor' is
10795 * 8 characters */
10796 vty_out(vty, "Neighbor");
10797 vty_out(vty, "%*s",
10798 max_neighbor_width - 8, " ");
10799 vty_out(vty,
10800 BGP_SHOW_SUMMARY_HEADER_FAILED);
10801 }
10802 }
10803 }
10804
10805 paf = peer_af_find(peer, afi, safi);
10806 filter = &peer->filter[afi][safi];
10807
10808 count++;
10809 /* Works for both failed & successful cases */
10810 if (peer_dynamic_neighbor(peer))
10811 dn_count++;
10812
10813 if (use_json) {
10814 json_peer = NULL;
10815 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10816 as_type, as)) {
10817 filtered_count++;
10818 continue;
10819 }
10820 if (show_failed &&
10821 bgp_has_peer_failed(peer, afi, safi)) {
10822 json_peer = json_object_new_object();
10823 bgp_show_failed_summary(vty, bgp, peer,
10824 json_peer, 0, use_json);
10825 } else if (!show_failed) {
10826 if (show_established
10827 && bgp_has_peer_failed(peer, afi, safi)) {
10828 filtered_count++;
10829 continue;
10830 }
10831
10832 json_peer = json_object_new_object();
10833 if (peer_dynamic_neighbor(peer)) {
10834 json_object_boolean_true_add(json_peer,
10835 "dynamicPeer");
10836 }
10837
10838 if (peer->hostname)
10839 json_object_string_add(json_peer, "hostname",
10840 peer->hostname);
10841
10842 if (peer->domainname)
10843 json_object_string_add(json_peer, "domainname",
10844 peer->domainname);
10845
10846 json_object_int_add(json_peer, "remoteAs", peer->as);
10847 json_object_int_add(
10848 json_peer, "localAs",
10849 peer->change_local_as
10850 ? peer->change_local_as
10851 : peer->local_as);
10852 json_object_int_add(json_peer, "version", 4);
10853 json_object_int_add(json_peer, "msgRcvd",
10854 PEER_TOTAL_RX(peer));
10855 json_object_int_add(json_peer, "msgSent",
10856 PEER_TOTAL_TX(peer));
10857
10858 atomic_size_t outq_count, inq_count;
10859 outq_count = atomic_load_explicit(
10860 &peer->obuf->count,
10861 memory_order_relaxed);
10862 inq_count = atomic_load_explicit(
10863 &peer->ibuf->count,
10864 memory_order_relaxed);
10865
10866 json_object_int_add(json_peer, "tableVersion",
10867 peer->version[afi][safi]);
10868 json_object_int_add(json_peer, "outq",
10869 outq_count);
10870 json_object_int_add(json_peer, "inq",
10871 inq_count);
10872 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10873 use_json, json_peer);
10874
10875 json_object_int_add(json_peer, "pfxRcd",
10876 peer->pcount[afi][pfx_rcd_safi]);
10877
10878 if (paf && PAF_SUBGRP(paf))
10879 json_object_int_add(
10880 json_peer, "pfxSnt",
10881 (PAF_SUBGRP(paf))->scount);
10882 else
10883 json_object_int_add(json_peer, "pfxSnt",
10884 0);
10885
10886 /* BGP FSM state */
10887 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10888 || CHECK_FLAG(peer->bgp->flags,
10889 BGP_FLAG_SHUTDOWN))
10890 json_object_string_add(json_peer,
10891 "state",
10892 "Idle (Admin)");
10893 else if (peer->afc_recv[afi][safi])
10894 json_object_string_add(
10895 json_peer, "state",
10896 lookup_msg(bgp_status_msg,
10897 peer->status, NULL));
10898 else if (CHECK_FLAG(
10899 peer->sflags,
10900 PEER_STATUS_PREFIX_OVERFLOW))
10901 json_object_string_add(json_peer,
10902 "state",
10903 "Idle (PfxCt)");
10904 else
10905 json_object_string_add(
10906 json_peer, "state",
10907 lookup_msg(bgp_status_msg,
10908 peer->status, NULL));
10909
10910 /* BGP peer state */
10911 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10912 || CHECK_FLAG(peer->bgp->flags,
10913 BGP_FLAG_SHUTDOWN))
10914 json_object_string_add(json_peer,
10915 "peerState",
10916 "Admin");
10917 else if (CHECK_FLAG(
10918 peer->sflags,
10919 PEER_STATUS_PREFIX_OVERFLOW))
10920 json_object_string_add(json_peer,
10921 "peerState",
10922 "PfxCt");
10923 else if (CHECK_FLAG(peer->flags,
10924 PEER_FLAG_PASSIVE))
10925 json_object_string_add(json_peer,
10926 "peerState",
10927 "Passive");
10928 else if (CHECK_FLAG(peer->sflags,
10929 PEER_STATUS_NSF_WAIT))
10930 json_object_string_add(json_peer,
10931 "peerState",
10932 "NSF passive");
10933 else if (CHECK_FLAG(
10934 peer->bgp->flags,
10935 BGP_FLAG_EBGP_REQUIRES_POLICY)
10936 && (!bgp_inbound_policy_exists(peer,
10937 filter)
10938 || !bgp_outbound_policy_exists(
10939 peer, filter)))
10940 json_object_string_add(json_peer,
10941 "peerState",
10942 "Policy");
10943 else
10944 json_object_string_add(
10945 json_peer, "peerState", "OK");
10946
10947 json_object_int_add(json_peer, "connectionsEstablished",
10948 peer->established);
10949 json_object_int_add(json_peer, "connectionsDropped",
10950 peer->dropped);
10951 if (peer->desc)
10952 json_object_string_add(
10953 json_peer, "desc", peer->desc);
10954 }
10955 /* Avoid creating empty peer dicts in JSON */
10956 if (json_peer == NULL)
10957 continue;
10958
10959 if (peer->conf_if)
10960 json_object_string_add(json_peer, "idType",
10961 "interface");
10962 else if (peer->su.sa.sa_family == AF_INET)
10963 json_object_string_add(json_peer, "idType",
10964 "ipv4");
10965 else if (peer->su.sa.sa_family == AF_INET6)
10966 json_object_string_add(json_peer, "idType",
10967 "ipv6");
10968 json_object_object_add(json_peers, peer->host,
10969 json_peer);
10970 } else {
10971 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10972 as_type, as)) {
10973 filtered_count++;
10974 continue;
10975 }
10976 if (show_failed &&
10977 bgp_has_peer_failed(peer, afi, safi)) {
10978 bgp_show_failed_summary(vty, bgp, peer, NULL,
10979 max_neighbor_width,
10980 use_json);
10981 } else if (!show_failed) {
10982 if (show_established
10983 && bgp_has_peer_failed(peer, afi, safi)) {
10984 filtered_count++;
10985 continue;
10986 }
10987
10988 if ((count - filtered_count) == 1) {
10989 /* display headline before the first
10990 * neighbor line */
10991 vty_out(vty, "\n");
10992
10993 /* Subtract 8 here because 'Neighbor' is
10994 * 8 characters */
10995 vty_out(vty, "Neighbor");
10996 vty_out(vty, "%*s",
10997 max_neighbor_width - 8, " ");
10998 vty_out(vty,
10999 show_wide
11000 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11001 : BGP_SHOW_SUMMARY_HEADER_ALL);
11002 }
11003
11004 memset(dn_flag, '\0', sizeof(dn_flag));
11005 if (peer_dynamic_neighbor(peer)) {
11006 dn_flag[0] = '*';
11007 }
11008
11009 if (peer->hostname
11010 && CHECK_FLAG(bgp->flags,
11011 BGP_FLAG_SHOW_HOSTNAME))
11012 len = vty_out(vty, "%s%s(%s)", dn_flag,
11013 peer->hostname,
11014 peer->host);
11015 else
11016 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11017
11018 /* pad the neighbor column with spaces */
11019 if (len < max_neighbor_width)
11020 vty_out(vty, "%*s", max_neighbor_width - len,
11021 " ");
11022
11023 atomic_size_t outq_count, inq_count;
11024 outq_count = atomic_load_explicit(
11025 &peer->obuf->count,
11026 memory_order_relaxed);
11027 inq_count = atomic_load_explicit(
11028 &peer->ibuf->count,
11029 memory_order_relaxed);
11030
11031 if (show_wide)
11032 vty_out(vty,
11033 "4 %10u %10u %9u %9u %8" PRIu64
11034 " %4zu %4zu %8s",
11035 peer->as,
11036 peer->change_local_as
11037 ? peer->change_local_as
11038 : peer->local_as,
11039 PEER_TOTAL_RX(peer),
11040 PEER_TOTAL_TX(peer),
11041 peer->version[afi][safi],
11042 inq_count, outq_count,
11043 peer_uptime(peer->uptime,
11044 timebuf,
11045 BGP_UPTIME_LEN, 0,
11046 NULL));
11047 else
11048 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11049 " %4zu %4zu %8s",
11050 peer->as, PEER_TOTAL_RX(peer),
11051 PEER_TOTAL_TX(peer),
11052 peer->version[afi][safi],
11053 inq_count, outq_count,
11054 peer_uptime(peer->uptime,
11055 timebuf,
11056 BGP_UPTIME_LEN, 0,
11057 NULL));
11058
11059 if (peer_established(peer)) {
11060 if (peer->afc_recv[afi][safi]) {
11061 if (CHECK_FLAG(
11062 bgp->flags,
11063 BGP_FLAG_EBGP_REQUIRES_POLICY)
11064 && !bgp_inbound_policy_exists(
11065 peer, filter))
11066 vty_out(vty, " %12s",
11067 "(Policy)");
11068 else
11069 vty_out(vty,
11070 " %12u",
11071 peer->pcount
11072 [afi]
11073 [pfx_rcd_safi]);
11074 } else {
11075 vty_out(vty, " NoNeg");
11076 }
11077
11078 if (paf && PAF_SUBGRP(paf)) {
11079 if (CHECK_FLAG(
11080 bgp->flags,
11081 BGP_FLAG_EBGP_REQUIRES_POLICY)
11082 && !bgp_outbound_policy_exists(
11083 peer, filter))
11084 vty_out(vty, " %8s",
11085 "(Policy)");
11086 else
11087 vty_out(vty,
11088 " %8u",
11089 (PAF_SUBGRP(
11090 paf))
11091 ->scount);
11092 } else {
11093 vty_out(vty, " NoNeg");
11094 }
11095 } else {
11096 if (CHECK_FLAG(peer->flags,
11097 PEER_FLAG_SHUTDOWN)
11098 || CHECK_FLAG(peer->bgp->flags,
11099 BGP_FLAG_SHUTDOWN))
11100 vty_out(vty, " Idle (Admin)");
11101 else if (CHECK_FLAG(
11102 peer->sflags,
11103 PEER_STATUS_PREFIX_OVERFLOW))
11104 vty_out(vty, " Idle (PfxCt)");
11105 else
11106 vty_out(vty, " %12s",
11107 lookup_msg(bgp_status_msg,
11108 peer->status, NULL));
11109
11110 vty_out(vty, " %8u", 0);
11111 }
11112 /* Make sure `Desc` column is the lastest in
11113 * the output.
11114 */
11115 if (peer->desc)
11116 vty_out(vty, " %s",
11117 bgp_peer_description_stripped(
11118 peer->desc,
11119 show_wide ? 64 : 20));
11120 else
11121 vty_out(vty, " N/A");
11122 vty_out(vty, "\n");
11123 }
11124
11125 }
11126 }
11127
11128 if (use_json) {
11129 json_object_object_add(json, "peers", json_peers);
11130 json_object_int_add(json, "failedPeers", failed_count);
11131 json_object_int_add(json, "displayedPeers",
11132 count - filtered_count);
11133 json_object_int_add(json, "totalPeers", count);
11134 json_object_int_add(json, "dynamicPeers", dn_count);
11135
11136 if (!show_failed)
11137 bgp_show_bestpath_json(bgp, json);
11138
11139 vty_json(vty, json);
11140 } else {
11141 if (count) {
11142 if (filtered_count == count)
11143 vty_out(vty, "\n%% No matching neighbor\n");
11144 else {
11145 if (show_failed)
11146 vty_out(vty, "\nDisplayed neighbors %d",
11147 failed_count);
11148 else if (as_type != AS_UNSPECIFIED || as
11149 || fpeer || show_established)
11150 vty_out(vty, "\nDisplayed neighbors %d",
11151 count - filtered_count);
11152
11153 vty_out(vty, "\nTotal number of neighbors %d\n",
11154 count);
11155 }
11156 } else {
11157 vty_out(vty, "No %s neighbor is configured\n",
11158 get_afi_safi_str(afi, safi, false));
11159 }
11160
11161 if (dn_count) {
11162 vty_out(vty, "* - dynamic neighbor\n");
11163 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11164 dn_count, bgp->dynamic_neighbors_limit);
11165 }
11166 }
11167
11168 return CMD_SUCCESS;
11169 }
11170
11171 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11172 int safi, struct peer *fpeer, int as_type,
11173 as_t as, uint16_t show_flags)
11174 {
11175 int is_first = 1;
11176 int afi_wildcard = (afi == AFI_MAX);
11177 int safi_wildcard = (safi == SAFI_MAX);
11178 int is_wildcard = (afi_wildcard || safi_wildcard);
11179 bool nbr_output = false;
11180 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11181
11182 if (use_json && is_wildcard)
11183 vty_out(vty, "{\n");
11184 if (afi_wildcard)
11185 afi = 1; /* AFI_IP */
11186 while (afi < AFI_MAX) {
11187 if (safi_wildcard)
11188 safi = 1; /* SAFI_UNICAST */
11189 while (safi < SAFI_MAX) {
11190 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11191 nbr_output = true;
11192
11193 if (is_wildcard) {
11194 /*
11195 * So limit output to those afi/safi
11196 * pairs that
11197 * actualy have something interesting in
11198 * them
11199 */
11200 if (use_json) {
11201 if (!is_first)
11202 vty_out(vty, ",\n");
11203 else
11204 is_first = 0;
11205
11206 vty_out(vty, "\"%s\":",
11207 get_afi_safi_str(afi,
11208 safi,
11209 true));
11210 } else {
11211 vty_out(vty,
11212 "\n%s Summary (%s):\n",
11213 get_afi_safi_str(afi,
11214 safi,
11215 false),
11216 bgp->name_pretty);
11217 }
11218 }
11219 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11220 as_type, as, show_flags);
11221 }
11222 safi++;
11223 if (!safi_wildcard)
11224 safi = SAFI_MAX;
11225 }
11226 afi++;
11227 if (!afi_wildcard)
11228 afi = AFI_MAX;
11229 }
11230
11231 if (use_json && is_wildcard)
11232 vty_out(vty, "}\n");
11233 else if (!nbr_output) {
11234 if (use_json)
11235 vty_out(vty, "{}\n");
11236 else
11237 vty_out(vty, "%% No BGP neighbors found in %s\n",
11238 bgp->name_pretty);
11239 }
11240 }
11241
11242 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11243 safi_t safi,
11244 const char *neighbor,
11245 int as_type, as_t as,
11246 uint16_t show_flags)
11247 {
11248 struct listnode *node, *nnode;
11249 struct bgp *bgp;
11250 struct peer *fpeer = NULL;
11251 int is_first = 1;
11252 bool nbr_output = false;
11253 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11254
11255 if (use_json)
11256 vty_out(vty, "{\n");
11257
11258 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11259 nbr_output = true;
11260 if (use_json) {
11261 if (!is_first)
11262 vty_out(vty, ",\n");
11263 else
11264 is_first = 0;
11265
11266 vty_out(vty, "\"%s\":",
11267 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11268 ? VRF_DEFAULT_NAME
11269 : bgp->name);
11270 }
11271 if (neighbor) {
11272 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11273 use_json);
11274 if (!fpeer)
11275 continue;
11276 }
11277 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11278 as, show_flags);
11279 }
11280
11281 if (use_json)
11282 vty_out(vty, "}\n");
11283 else if (!nbr_output)
11284 vty_out(vty, "%% BGP instance not found\n");
11285 }
11286
11287 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11288 safi_t safi, const char *neighbor, int as_type,
11289 as_t as, uint16_t show_flags)
11290 {
11291 struct bgp *bgp;
11292 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11293 struct peer *fpeer = NULL;
11294
11295 if (name) {
11296 if (strmatch(name, "all")) {
11297 bgp_show_all_instances_summary_vty(vty, afi, safi,
11298 neighbor, as_type,
11299 as, show_flags);
11300 return CMD_SUCCESS;
11301 } else {
11302 bgp = bgp_lookup_by_name(name);
11303
11304 if (!bgp) {
11305 if (use_json)
11306 vty_out(vty, "{}\n");
11307 else
11308 vty_out(vty,
11309 "%% BGP instance not found\n");
11310 return CMD_WARNING;
11311 }
11312
11313 if (neighbor) {
11314 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11315 use_json);
11316 if (!fpeer)
11317 return CMD_WARNING;
11318 }
11319 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11320 as_type, as, show_flags);
11321 return CMD_SUCCESS;
11322 }
11323 }
11324
11325 bgp = bgp_get_default();
11326
11327 if (bgp) {
11328 if (neighbor) {
11329 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11330 use_json);
11331 if (!fpeer)
11332 return CMD_WARNING;
11333 }
11334 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11335 as, show_flags);
11336 } else {
11337 if (use_json)
11338 vty_out(vty, "{}\n");
11339 else
11340 vty_out(vty, "%% BGP instance not found\n");
11341 return CMD_WARNING;
11342 }
11343
11344 return CMD_SUCCESS;
11345 }
11346
11347 /* `show [ip] bgp summary' commands. */
11348 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11349 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11350 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11351 "]] [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]",
11352 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11353 BGP_SAFI_WITH_LABEL_HELP_STR
11354 "Display the entries for all address families\n"
11355 "Summary of BGP neighbor status\n"
11356 "Show only sessions in Established state\n"
11357 "Show only sessions not in Established state\n"
11358 "Show only the specified neighbor session\n"
11359 "Neighbor to display information about\n"
11360 "Neighbor to display information about\n"
11361 "Neighbor on BGP configured interface\n"
11362 "Show only the specified remote AS sessions\n"
11363 "AS number\n"
11364 "Internal (iBGP) AS sessions\n"
11365 "External (eBGP) AS sessions\n"
11366 "Shorten the information on BGP instances\n"
11367 "Increase table width for longer output\n" JSON_STR)
11368 {
11369 char *vrf = NULL;
11370 afi_t afi = AFI_MAX;
11371 safi_t safi = SAFI_MAX;
11372 as_t as = 0; /* 0 means AS filter not set */
11373 int as_type = AS_UNSPECIFIED;
11374 uint16_t show_flags = 0;
11375
11376 int idx = 0;
11377
11378 /* show [ip] bgp */
11379 if (!all && argv_find(argv, argc, "ip", &idx))
11380 afi = AFI_IP;
11381 /* [<vrf> VIEWVRFNAME] */
11382 if (argv_find(argv, argc, "vrf", &idx)) {
11383 vrf = argv[idx + 1]->arg;
11384 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11385 vrf = NULL;
11386 } else if (argv_find(argv, argc, "view", &idx))
11387 /* [<view> VIEWVRFNAME] */
11388 vrf = argv[idx + 1]->arg;
11389 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11390 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11391 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11392 }
11393
11394 if (argv_find(argv, argc, "failed", &idx))
11395 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11396
11397 if (argv_find(argv, argc, "established", &idx))
11398 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11399
11400 if (argv_find(argv, argc, "remote-as", &idx)) {
11401 if (argv[idx + 1]->arg[0] == 'i')
11402 as_type = AS_INTERNAL;
11403 else if (argv[idx + 1]->arg[0] == 'e')
11404 as_type = AS_EXTERNAL;
11405 else
11406 as = (as_t)atoi(argv[idx + 1]->arg);
11407 }
11408
11409 if (argv_find(argv, argc, "terse", &idx))
11410 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11411
11412 if (argv_find(argv, argc, "wide", &idx))
11413 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11414
11415 if (argv_find(argv, argc, "json", &idx))
11416 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11417
11418 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11419 show_flags);
11420 }
11421
11422 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11423 {
11424 if (for_json)
11425 return get_afi_safi_json_str(afi, safi);
11426 else
11427 return get_afi_safi_vty_str(afi, safi);
11428 }
11429
11430
11431 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11432 afi_t afi, safi_t safi,
11433 uint16_t adv_smcap, uint16_t adv_rmcap,
11434 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11435 bool use_json, json_object *json_pref)
11436 {
11437 /* Send-Mode */
11438 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11439 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11440 if (use_json) {
11441 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11442 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11443 json_object_string_add(json_pref, "sendMode",
11444 "advertisedAndReceived");
11445 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11446 json_object_string_add(json_pref, "sendMode",
11447 "advertised");
11448 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11449 json_object_string_add(json_pref, "sendMode",
11450 "received");
11451 } else {
11452 vty_out(vty, " Send-mode: ");
11453 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11454 vty_out(vty, "advertised");
11455 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11456 vty_out(vty, "%sreceived",
11457 CHECK_FLAG(p->af_cap[afi][safi],
11458 adv_smcap)
11459 ? ", "
11460 : "");
11461 vty_out(vty, "\n");
11462 }
11463 }
11464
11465 /* Receive-Mode */
11466 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11467 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11468 if (use_json) {
11469 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11470 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11471 json_object_string_add(json_pref, "recvMode",
11472 "advertisedAndReceived");
11473 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11474 json_object_string_add(json_pref, "recvMode",
11475 "advertised");
11476 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11477 json_object_string_add(json_pref, "recvMode",
11478 "received");
11479 } else {
11480 vty_out(vty, " Receive-mode: ");
11481 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11482 vty_out(vty, "advertised");
11483 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11484 vty_out(vty, "%sreceived",
11485 CHECK_FLAG(p->af_cap[afi][safi],
11486 adv_rmcap)
11487 ? ", "
11488 : "");
11489 vty_out(vty, "\n");
11490 }
11491 }
11492 }
11493
11494 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11495 struct peer *p,
11496 bool use_json,
11497 json_object *json)
11498 {
11499 bool rbit = false;
11500 bool nbit = false;
11501
11502 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11503 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11504 && (peer_established(p))) {
11505 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11506 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11507 }
11508
11509 if (use_json) {
11510 json_object_boolean_add(json, "rBit", rbit);
11511 json_object_boolean_add(json, "nBit", nbit);
11512 } else {
11513 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11514 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11515 }
11516 }
11517
11518 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11519 struct peer *peer,
11520 bool use_json,
11521 json_object *json)
11522 {
11523 const char *mode = "NotApplicable";
11524
11525 if (!use_json)
11526 vty_out(vty, "\n Remote GR Mode: ");
11527
11528 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11529 && (peer_established(peer))) {
11530
11531 if ((peer->nsf_af_count == 0)
11532 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11533
11534 mode = "Disable";
11535
11536 } else if (peer->nsf_af_count == 0
11537 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11538
11539 mode = "Helper";
11540
11541 } else if (peer->nsf_af_count != 0
11542 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11543
11544 mode = "Restart";
11545 }
11546 }
11547
11548 if (use_json) {
11549 json_object_string_add(json, "remoteGrMode", mode);
11550 } else
11551 vty_out(vty, mode, "\n");
11552 }
11553
11554 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11555 struct peer *p,
11556 bool use_json,
11557 json_object *json)
11558 {
11559 const char *mode = "Invalid";
11560
11561 if (!use_json)
11562 vty_out(vty, " Local GR Mode: ");
11563
11564 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11565 mode = "Helper";
11566 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11567 mode = "Restart";
11568 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11569 mode = "Disable";
11570 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11571 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11572 mode = "Helper*";
11573 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11574 mode = "Restart*";
11575 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11576 mode = "Disable*";
11577 else
11578 mode = "Invalid*";
11579 }
11580
11581 if (use_json) {
11582 json_object_string_add(json, "localGrMode", mode);
11583 } else {
11584 vty_out(vty, mode, "\n");
11585 }
11586 }
11587
11588 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11589 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11590 {
11591 afi_t afi;
11592 safi_t safi;
11593 json_object *json_afi_safi = NULL;
11594 json_object *json_timer = NULL;
11595 json_object *json_endofrib_status = NULL;
11596 bool eor_flag = false;
11597
11598 FOREACH_AFI_SAFI_NSF (afi, safi) {
11599 if (!peer->afc[afi][safi])
11600 continue;
11601
11602 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11603 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11604 continue;
11605
11606 if (use_json) {
11607 json_afi_safi = json_object_new_object();
11608 json_endofrib_status = json_object_new_object();
11609 json_timer = json_object_new_object();
11610 }
11611
11612 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11613 eor_flag = true;
11614 else
11615 eor_flag = false;
11616
11617 if (!use_json) {
11618 vty_out(vty, " %s:\n",
11619 get_afi_safi_str(afi, safi, false));
11620
11621 vty_out(vty, " F bit: ");
11622 }
11623
11624 if (peer->nsf[afi][safi] &&
11625 CHECK_FLAG(peer->af_cap[afi][safi],
11626 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11627
11628 if (use_json) {
11629 json_object_boolean_true_add(json_afi_safi,
11630 "fBit");
11631 } else
11632 vty_out(vty, "True\n");
11633 } else {
11634 if (use_json)
11635 json_object_boolean_false_add(json_afi_safi,
11636 "fBit");
11637 else
11638 vty_out(vty, "False\n");
11639 }
11640
11641 if (!use_json)
11642 vty_out(vty, " End-of-RIB sent: ");
11643
11644 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11645 PEER_STATUS_EOR_SEND)) {
11646 if (use_json) {
11647 json_object_boolean_true_add(
11648 json_endofrib_status, "endOfRibSend");
11649
11650 PRINT_EOR_JSON(eor_flag);
11651 } else {
11652 vty_out(vty, "Yes\n");
11653 vty_out(vty,
11654 " End-of-RIB sent after update: ");
11655
11656 PRINT_EOR(eor_flag);
11657 }
11658 } else {
11659 if (use_json) {
11660 json_object_boolean_false_add(
11661 json_endofrib_status, "endOfRibSend");
11662 json_object_boolean_false_add(
11663 json_endofrib_status,
11664 "endOfRibSentAfterUpdate");
11665 } else {
11666 vty_out(vty, "No\n");
11667 vty_out(vty,
11668 " End-of-RIB sent after update: ");
11669 vty_out(vty, "No\n");
11670 }
11671 }
11672
11673 if (!use_json)
11674 vty_out(vty, " End-of-RIB received: ");
11675
11676 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11677 PEER_STATUS_EOR_RECEIVED)) {
11678 if (use_json)
11679 json_object_boolean_true_add(
11680 json_endofrib_status, "endOfRibRecv");
11681 else
11682 vty_out(vty, "Yes\n");
11683 } else {
11684 if (use_json)
11685 json_object_boolean_false_add(
11686 json_endofrib_status, "endOfRibRecv");
11687 else
11688 vty_out(vty, "No\n");
11689 }
11690
11691 if (use_json) {
11692 json_object_int_add(json_timer, "stalePathTimer",
11693 peer->bgp->stalepath_time);
11694
11695 if (peer->t_gr_stale != NULL) {
11696 json_object_int_add(json_timer,
11697 "stalePathTimerRemaining",
11698 thread_timer_remain_second(
11699 peer->t_gr_stale));
11700 }
11701
11702 /* Display Configured Selection
11703 * Deferral only when when
11704 * Gr mode is enabled.
11705 */
11706 if (CHECK_FLAG(peer->flags,
11707 PEER_FLAG_GRACEFUL_RESTART)) {
11708 json_object_int_add(json_timer,
11709 "selectionDeferralTimer",
11710 peer->bgp->stalepath_time);
11711 }
11712
11713 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11714 NULL) {
11715
11716 json_object_int_add(
11717 json_timer,
11718 "selectionDeferralTimerRemaining",
11719 thread_timer_remain_second(
11720 peer->bgp->gr_info[afi][safi]
11721 .t_select_deferral));
11722 }
11723 } else {
11724 vty_out(vty, " Timers:\n");
11725 vty_out(vty,
11726 " Configured Stale Path Time(sec): %u\n",
11727 peer->bgp->stalepath_time);
11728
11729 if (peer->t_gr_stale != NULL)
11730 vty_out(vty,
11731 " Stale Path Remaining(sec): %ld\n",
11732 thread_timer_remain_second(
11733 peer->t_gr_stale));
11734 /* Display Configured Selection
11735 * Deferral only when when
11736 * Gr mode is enabled.
11737 */
11738 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11739 vty_out(vty,
11740 " Configured Selection Deferral Time(sec): %u\n",
11741 peer->bgp->select_defer_time);
11742
11743 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11744 NULL)
11745 vty_out(vty,
11746 " Selection Deferral Time Remaining(sec): %ld\n",
11747 thread_timer_remain_second(
11748 peer->bgp->gr_info[afi][safi]
11749 .t_select_deferral));
11750 }
11751 if (use_json) {
11752 json_object_object_add(json_afi_safi, "endOfRibStatus",
11753 json_endofrib_status);
11754 json_object_object_add(json_afi_safi, "timers",
11755 json_timer);
11756 json_object_object_add(
11757 json, get_afi_safi_str(afi, safi, true),
11758 json_afi_safi);
11759 }
11760 }
11761 }
11762
11763 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11764 struct peer *p,
11765 bool use_json,
11766 json_object *json)
11767 {
11768 if (use_json) {
11769 json_object *json_timer = NULL;
11770
11771 json_timer = json_object_new_object();
11772
11773 json_object_int_add(json_timer, "configuredRestartTimer",
11774 p->bgp->restart_time);
11775
11776 json_object_int_add(json_timer, "receivedRestartTimer",
11777 p->v_gr_restart);
11778
11779 if (p->t_gr_restart != NULL)
11780 json_object_int_add(
11781 json_timer, "restartTimerRemaining",
11782 thread_timer_remain_second(p->t_gr_restart));
11783
11784 json_object_object_add(json, "timers", json_timer);
11785 } else {
11786
11787 vty_out(vty, " Timers:\n");
11788 vty_out(vty, " Configured Restart Time(sec): %u\n",
11789 p->bgp->restart_time);
11790
11791 vty_out(vty, " Received Restart Time(sec): %u\n",
11792 p->v_gr_restart);
11793 if (p->t_gr_restart != NULL)
11794 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11795 thread_timer_remain_second(p->t_gr_restart));
11796 if (p->t_gr_restart != NULL) {
11797 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11798 thread_timer_remain_second(p->t_gr_restart));
11799 }
11800 }
11801 }
11802
11803 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11804 bool use_json, json_object *json)
11805 {
11806 char dn_flag[2] = {0};
11807 /* '*' + v6 address of neighbor */
11808 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11809
11810 if (!p->conf_if && peer_dynamic_neighbor(p))
11811 dn_flag[0] = '*';
11812
11813 if (p->conf_if) {
11814 if (use_json)
11815 json_object_string_addf(json, "neighborAddr", "%pSU",
11816 &p->su);
11817 else
11818 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11819 &p->su);
11820 } else {
11821 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11822 p->host);
11823
11824 if (use_json)
11825 json_object_string_add(json, "neighborAddr",
11826 neighborAddr);
11827 else
11828 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11829 }
11830
11831 /* more gr info in new format */
11832 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11833 }
11834
11835 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11836 safi_t safi, bool use_json,
11837 json_object *json_neigh)
11838 {
11839 struct bgp_filter *filter;
11840 struct peer_af *paf;
11841 char orf_pfx_name[BUFSIZ];
11842 int orf_pfx_count;
11843 json_object *json_af = NULL;
11844 json_object *json_prefA = NULL;
11845 json_object *json_prefB = NULL;
11846 json_object *json_addr = NULL;
11847 json_object *json_advmap = NULL;
11848
11849 if (use_json) {
11850 json_addr = json_object_new_object();
11851 json_af = json_object_new_object();
11852 filter = &p->filter[afi][safi];
11853
11854 if (peer_group_active(p))
11855 json_object_string_add(json_addr, "peerGroupMember",
11856 p->group->name);
11857
11858 paf = peer_af_find(p, afi, safi);
11859 if (paf && PAF_SUBGRP(paf)) {
11860 json_object_int_add(json_addr, "updateGroupId",
11861 PAF_UPDGRP(paf)->id);
11862 json_object_int_add(json_addr, "subGroupId",
11863 PAF_SUBGRP(paf)->id);
11864 json_object_int_add(json_addr, "packetQueueLength",
11865 bpacket_queue_virtual_length(paf));
11866 }
11867
11868 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11869 || CHECK_FLAG(p->af_cap[afi][safi],
11870 PEER_CAP_ORF_PREFIX_SM_RCV)
11871 || CHECK_FLAG(p->af_cap[afi][safi],
11872 PEER_CAP_ORF_PREFIX_RM_ADV)
11873 || CHECK_FLAG(p->af_cap[afi][safi],
11874 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11875 json_object_int_add(json_af, "orfType",
11876 ORF_TYPE_PREFIX);
11877 json_prefA = json_object_new_object();
11878 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11879 PEER_CAP_ORF_PREFIX_SM_ADV,
11880 PEER_CAP_ORF_PREFIX_RM_ADV,
11881 PEER_CAP_ORF_PREFIX_SM_RCV,
11882 PEER_CAP_ORF_PREFIX_RM_RCV,
11883 use_json, json_prefA);
11884 json_object_object_add(json_af, "orfPrefixList",
11885 json_prefA);
11886 }
11887
11888 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11889 || CHECK_FLAG(p->af_cap[afi][safi],
11890 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11891 || CHECK_FLAG(p->af_cap[afi][safi],
11892 PEER_CAP_ORF_PREFIX_RM_ADV)
11893 || CHECK_FLAG(p->af_cap[afi][safi],
11894 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11895 json_object_int_add(json_af, "orfOldType",
11896 ORF_TYPE_PREFIX_OLD);
11897 json_prefB = json_object_new_object();
11898 bgp_show_peer_afi_orf_cap(
11899 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11900 PEER_CAP_ORF_PREFIX_RM_ADV,
11901 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11902 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11903 json_prefB);
11904 json_object_object_add(json_af, "orfOldPrefixList",
11905 json_prefB);
11906 }
11907
11908 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11909 || CHECK_FLAG(p->af_cap[afi][safi],
11910 PEER_CAP_ORF_PREFIX_SM_RCV)
11911 || CHECK_FLAG(p->af_cap[afi][safi],
11912 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11913 || CHECK_FLAG(p->af_cap[afi][safi],
11914 PEER_CAP_ORF_PREFIX_RM_ADV)
11915 || CHECK_FLAG(p->af_cap[afi][safi],
11916 PEER_CAP_ORF_PREFIX_RM_RCV)
11917 || CHECK_FLAG(p->af_cap[afi][safi],
11918 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11919 json_object_object_add(json_addr, "afDependentCap",
11920 json_af);
11921 else
11922 json_object_free(json_af);
11923
11924 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11925 p->host, afi, safi);
11926 orf_pfx_count = prefix_bgp_show_prefix_list(
11927 NULL, afi, orf_pfx_name, use_json);
11928
11929 if (CHECK_FLAG(p->af_sflags[afi][safi],
11930 PEER_STATUS_ORF_PREFIX_SEND)
11931 || orf_pfx_count) {
11932 if (CHECK_FLAG(p->af_sflags[afi][safi],
11933 PEER_STATUS_ORF_PREFIX_SEND))
11934 json_object_boolean_true_add(json_neigh,
11935 "orfSent");
11936 if (orf_pfx_count)
11937 json_object_int_add(json_addr, "orfRecvCounter",
11938 orf_pfx_count);
11939 }
11940 if (CHECK_FLAG(p->af_sflags[afi][safi],
11941 PEER_STATUS_ORF_WAIT_REFRESH))
11942 json_object_string_add(
11943 json_addr, "orfFirstUpdate",
11944 "deferredUntilORFOrRouteRefreshRecvd");
11945
11946 if (CHECK_FLAG(p->af_flags[afi][safi],
11947 PEER_FLAG_REFLECTOR_CLIENT))
11948 json_object_boolean_true_add(json_addr,
11949 "routeReflectorClient");
11950 if (CHECK_FLAG(p->af_flags[afi][safi],
11951 PEER_FLAG_RSERVER_CLIENT))
11952 json_object_boolean_true_add(json_addr,
11953 "routeServerClient");
11954 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11955 json_object_boolean_true_add(json_addr,
11956 "inboundSoftConfigPermit");
11957
11958 if (CHECK_FLAG(p->af_flags[afi][safi],
11959 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11960 json_object_boolean_true_add(
11961 json_addr,
11962 "privateAsNumsAllReplacedInUpdatesToNbr");
11963 else if (CHECK_FLAG(p->af_flags[afi][safi],
11964 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11965 json_object_boolean_true_add(
11966 json_addr,
11967 "privateAsNumsReplacedInUpdatesToNbr");
11968 else if (CHECK_FLAG(p->af_flags[afi][safi],
11969 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11970 json_object_boolean_true_add(
11971 json_addr,
11972 "privateAsNumsAllRemovedInUpdatesToNbr");
11973 else if (CHECK_FLAG(p->af_flags[afi][safi],
11974 PEER_FLAG_REMOVE_PRIVATE_AS))
11975 json_object_boolean_true_add(
11976 json_addr,
11977 "privateAsNumsRemovedInUpdatesToNbr");
11978
11979 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11980 json_object_boolean_true_add(
11981 json_addr,
11982 bgp_addpath_names(p->addpath_type[afi][safi])
11983 ->type_json_name);
11984
11985 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11986 json_object_string_add(json_addr,
11987 "overrideASNsInOutboundUpdates",
11988 "ifAspathEqualRemoteAs");
11989
11990 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11991 || CHECK_FLAG(p->af_flags[afi][safi],
11992 PEER_FLAG_FORCE_NEXTHOP_SELF))
11993 json_object_boolean_true_add(json_addr,
11994 "routerAlwaysNextHop");
11995 if (CHECK_FLAG(p->af_flags[afi][safi],
11996 PEER_FLAG_AS_PATH_UNCHANGED))
11997 json_object_boolean_true_add(
11998 json_addr, "unchangedAsPathPropogatedToNbr");
11999 if (CHECK_FLAG(p->af_flags[afi][safi],
12000 PEER_FLAG_NEXTHOP_UNCHANGED))
12001 json_object_boolean_true_add(
12002 json_addr, "unchangedNextHopPropogatedToNbr");
12003 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12004 json_object_boolean_true_add(
12005 json_addr, "unchangedMedPropogatedToNbr");
12006 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12007 || CHECK_FLAG(p->af_flags[afi][safi],
12008 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12009 if (CHECK_FLAG(p->af_flags[afi][safi],
12010 PEER_FLAG_SEND_COMMUNITY)
12011 && CHECK_FLAG(p->af_flags[afi][safi],
12012 PEER_FLAG_SEND_EXT_COMMUNITY))
12013 json_object_string_add(json_addr,
12014 "commAttriSentToNbr",
12015 "extendedAndStandard");
12016 else if (CHECK_FLAG(p->af_flags[afi][safi],
12017 PEER_FLAG_SEND_EXT_COMMUNITY))
12018 json_object_string_add(json_addr,
12019 "commAttriSentToNbr",
12020 "extended");
12021 else
12022 json_object_string_add(json_addr,
12023 "commAttriSentToNbr",
12024 "standard");
12025 }
12026 if (CHECK_FLAG(p->af_flags[afi][safi],
12027 PEER_FLAG_DEFAULT_ORIGINATE)) {
12028 if (p->default_rmap[afi][safi].name)
12029 json_object_string_add(
12030 json_addr, "defaultRouteMap",
12031 p->default_rmap[afi][safi].name);
12032
12033 if (paf && PAF_SUBGRP(paf)
12034 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12035 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12036 json_object_boolean_true_add(json_addr,
12037 "defaultSent");
12038 else
12039 json_object_boolean_true_add(json_addr,
12040 "defaultNotSent");
12041 }
12042
12043 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12044 if (is_evpn_enabled())
12045 json_object_boolean_true_add(
12046 json_addr, "advertiseAllVnis");
12047 }
12048
12049 if (filter->plist[FILTER_IN].name
12050 || filter->dlist[FILTER_IN].name
12051 || filter->aslist[FILTER_IN].name
12052 || filter->map[RMAP_IN].name)
12053 json_object_boolean_true_add(json_addr,
12054 "inboundPathPolicyConfig");
12055 if (filter->plist[FILTER_OUT].name
12056 || filter->dlist[FILTER_OUT].name
12057 || filter->aslist[FILTER_OUT].name
12058 || filter->map[RMAP_OUT].name || filter->usmap.name)
12059 json_object_boolean_true_add(
12060 json_addr, "outboundPathPolicyConfig");
12061
12062 /* prefix-list */
12063 if (filter->plist[FILTER_IN].name)
12064 json_object_string_add(json_addr,
12065 "incomingUpdatePrefixFilterList",
12066 filter->plist[FILTER_IN].name);
12067 if (filter->plist[FILTER_OUT].name)
12068 json_object_string_add(json_addr,
12069 "outgoingUpdatePrefixFilterList",
12070 filter->plist[FILTER_OUT].name);
12071
12072 /* distribute-list */
12073 if (filter->dlist[FILTER_IN].name)
12074 json_object_string_add(
12075 json_addr, "incomingUpdateNetworkFilterList",
12076 filter->dlist[FILTER_IN].name);
12077 if (filter->dlist[FILTER_OUT].name)
12078 json_object_string_add(
12079 json_addr, "outgoingUpdateNetworkFilterList",
12080 filter->dlist[FILTER_OUT].name);
12081
12082 /* filter-list. */
12083 if (filter->aslist[FILTER_IN].name)
12084 json_object_string_add(json_addr,
12085 "incomingUpdateAsPathFilterList",
12086 filter->aslist[FILTER_IN].name);
12087 if (filter->aslist[FILTER_OUT].name)
12088 json_object_string_add(json_addr,
12089 "outgoingUpdateAsPathFilterList",
12090 filter->aslist[FILTER_OUT].name);
12091
12092 /* route-map. */
12093 if (filter->map[RMAP_IN].name)
12094 json_object_string_add(
12095 json_addr, "routeMapForIncomingAdvertisements",
12096 filter->map[RMAP_IN].name);
12097 if (filter->map[RMAP_OUT].name)
12098 json_object_string_add(
12099 json_addr, "routeMapForOutgoingAdvertisements",
12100 filter->map[RMAP_OUT].name);
12101
12102 /* ebgp-requires-policy (inbound) */
12103 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12104 && !bgp_inbound_policy_exists(p, filter))
12105 json_object_string_add(
12106 json_addr, "inboundEbgpRequiresPolicy",
12107 "Inbound updates discarded due to missing policy");
12108
12109 /* ebgp-requires-policy (outbound) */
12110 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12111 && (!bgp_outbound_policy_exists(p, filter)))
12112 json_object_string_add(
12113 json_addr, "outboundEbgpRequiresPolicy",
12114 "Outbound updates discarded due to missing policy");
12115
12116 /* unsuppress-map */
12117 if (filter->usmap.name)
12118 json_object_string_add(json_addr,
12119 "selectiveUnsuppressRouteMap",
12120 filter->usmap.name);
12121
12122 /* advertise-map */
12123 if (filter->advmap.aname) {
12124 json_advmap = json_object_new_object();
12125 json_object_string_add(json_advmap, "condition",
12126 filter->advmap.condition
12127 ? "EXIST"
12128 : "NON_EXIST");
12129 json_object_string_add(json_advmap, "conditionMap",
12130 filter->advmap.cname);
12131 json_object_string_add(json_advmap, "advertiseMap",
12132 filter->advmap.aname);
12133 json_object_string_add(
12134 json_advmap, "advertiseStatus",
12135 filter->advmap.update_type ==
12136 UPDATE_TYPE_ADVERTISE
12137 ? "Advertise"
12138 : "Withdraw");
12139 json_object_object_add(json_addr, "advertiseMap",
12140 json_advmap);
12141 }
12142
12143 /* Receive prefix count */
12144 json_object_int_add(json_addr, "acceptedPrefixCounter",
12145 p->pcount[afi][safi]);
12146 if (paf && PAF_SUBGRP(paf))
12147 json_object_int_add(json_addr, "sentPrefixCounter",
12148 (PAF_SUBGRP(paf))->scount);
12149
12150 /* Maximum prefix */
12151 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12152 json_object_int_add(json_addr, "prefixOutAllowedMax",
12153 p->pmax_out[afi][safi]);
12154
12155 /* Maximum prefix */
12156 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12157 json_object_int_add(json_addr, "prefixAllowedMax",
12158 p->pmax[afi][safi]);
12159 if (CHECK_FLAG(p->af_flags[afi][safi],
12160 PEER_FLAG_MAX_PREFIX_WARNING))
12161 json_object_boolean_true_add(
12162 json_addr, "prefixAllowedMaxWarning");
12163 json_object_int_add(json_addr,
12164 "prefixAllowedWarningThresh",
12165 p->pmax_threshold[afi][safi]);
12166 if (p->pmax_restart[afi][safi])
12167 json_object_int_add(
12168 json_addr,
12169 "prefixAllowedRestartIntervalMsecs",
12170 p->pmax_restart[afi][safi] * 60000);
12171 }
12172 json_object_object_add(json_neigh,
12173 get_afi_safi_str(afi, safi, true),
12174 json_addr);
12175
12176 } else {
12177 filter = &p->filter[afi][safi];
12178
12179 vty_out(vty, " For address family: %s\n",
12180 get_afi_safi_str(afi, safi, false));
12181
12182 if (peer_group_active(p))
12183 vty_out(vty, " %s peer-group member\n",
12184 p->group->name);
12185
12186 paf = peer_af_find(p, afi, safi);
12187 if (paf && PAF_SUBGRP(paf)) {
12188 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12189 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12190 vty_out(vty, " Packet Queue length %d\n",
12191 bpacket_queue_virtual_length(paf));
12192 } else {
12193 vty_out(vty, " Not part of any update group\n");
12194 }
12195 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12196 || CHECK_FLAG(p->af_cap[afi][safi],
12197 PEER_CAP_ORF_PREFIX_SM_RCV)
12198 || CHECK_FLAG(p->af_cap[afi][safi],
12199 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12200 || CHECK_FLAG(p->af_cap[afi][safi],
12201 PEER_CAP_ORF_PREFIX_RM_ADV)
12202 || CHECK_FLAG(p->af_cap[afi][safi],
12203 PEER_CAP_ORF_PREFIX_RM_RCV)
12204 || CHECK_FLAG(p->af_cap[afi][safi],
12205 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12206 vty_out(vty, " AF-dependant capabilities:\n");
12207
12208 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12209 || CHECK_FLAG(p->af_cap[afi][safi],
12210 PEER_CAP_ORF_PREFIX_SM_RCV)
12211 || CHECK_FLAG(p->af_cap[afi][safi],
12212 PEER_CAP_ORF_PREFIX_RM_ADV)
12213 || CHECK_FLAG(p->af_cap[afi][safi],
12214 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12215 vty_out(vty,
12216 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12217 ORF_TYPE_PREFIX);
12218 bgp_show_peer_afi_orf_cap(
12219 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12220 PEER_CAP_ORF_PREFIX_RM_ADV,
12221 PEER_CAP_ORF_PREFIX_SM_RCV,
12222 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12223 }
12224 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12225 || CHECK_FLAG(p->af_cap[afi][safi],
12226 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12227 || CHECK_FLAG(p->af_cap[afi][safi],
12228 PEER_CAP_ORF_PREFIX_RM_ADV)
12229 || CHECK_FLAG(p->af_cap[afi][safi],
12230 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12231 vty_out(vty,
12232 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12233 ORF_TYPE_PREFIX_OLD);
12234 bgp_show_peer_afi_orf_cap(
12235 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12236 PEER_CAP_ORF_PREFIX_RM_ADV,
12237 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12238 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12239 }
12240
12241 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12242 p->host, afi, safi);
12243 orf_pfx_count = prefix_bgp_show_prefix_list(
12244 NULL, afi, orf_pfx_name, use_json);
12245
12246 if (CHECK_FLAG(p->af_sflags[afi][safi],
12247 PEER_STATUS_ORF_PREFIX_SEND)
12248 || orf_pfx_count) {
12249 vty_out(vty, " Outbound Route Filter (ORF):");
12250 if (CHECK_FLAG(p->af_sflags[afi][safi],
12251 PEER_STATUS_ORF_PREFIX_SEND))
12252 vty_out(vty, " sent;");
12253 if (orf_pfx_count)
12254 vty_out(vty, " received (%d entries)",
12255 orf_pfx_count);
12256 vty_out(vty, "\n");
12257 }
12258 if (CHECK_FLAG(p->af_sflags[afi][safi],
12259 PEER_STATUS_ORF_WAIT_REFRESH))
12260 vty_out(vty,
12261 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12262
12263 if (CHECK_FLAG(p->af_flags[afi][safi],
12264 PEER_FLAG_REFLECTOR_CLIENT))
12265 vty_out(vty, " Route-Reflector Client\n");
12266 if (CHECK_FLAG(p->af_flags[afi][safi],
12267 PEER_FLAG_RSERVER_CLIENT))
12268 vty_out(vty, " Route-Server Client\n");
12269 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12270 vty_out(vty,
12271 " Inbound soft reconfiguration allowed\n");
12272
12273 if (CHECK_FLAG(p->af_flags[afi][safi],
12274 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12275 vty_out(vty,
12276 " Private AS numbers (all) replaced in updates to this neighbor\n");
12277 else if (CHECK_FLAG(p->af_flags[afi][safi],
12278 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12279 vty_out(vty,
12280 " Private AS numbers replaced in updates to this neighbor\n");
12281 else if (CHECK_FLAG(p->af_flags[afi][safi],
12282 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12283 vty_out(vty,
12284 " Private AS numbers (all) removed in updates to this neighbor\n");
12285 else if (CHECK_FLAG(p->af_flags[afi][safi],
12286 PEER_FLAG_REMOVE_PRIVATE_AS))
12287 vty_out(vty,
12288 " Private AS numbers removed in updates to this neighbor\n");
12289
12290 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12291 vty_out(vty, " %s\n",
12292 bgp_addpath_names(p->addpath_type[afi][safi])
12293 ->human_description);
12294
12295 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12296 vty_out(vty,
12297 " Override ASNs in outbound updates if aspath equals remote-as\n");
12298
12299 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12300 || CHECK_FLAG(p->af_flags[afi][safi],
12301 PEER_FLAG_FORCE_NEXTHOP_SELF))
12302 vty_out(vty, " NEXT_HOP is always this router\n");
12303 if (CHECK_FLAG(p->af_flags[afi][safi],
12304 PEER_FLAG_AS_PATH_UNCHANGED))
12305 vty_out(vty,
12306 " AS_PATH is propagated unchanged to this neighbor\n");
12307 if (CHECK_FLAG(p->af_flags[afi][safi],
12308 PEER_FLAG_NEXTHOP_UNCHANGED))
12309 vty_out(vty,
12310 " NEXT_HOP is propagated unchanged to this neighbor\n");
12311 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12312 vty_out(vty,
12313 " MED is propagated unchanged to this neighbor\n");
12314 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12315 || CHECK_FLAG(p->af_flags[afi][safi],
12316 PEER_FLAG_SEND_EXT_COMMUNITY)
12317 || CHECK_FLAG(p->af_flags[afi][safi],
12318 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12319 vty_out(vty,
12320 " Community attribute sent to this neighbor");
12321 if (CHECK_FLAG(p->af_flags[afi][safi],
12322 PEER_FLAG_SEND_COMMUNITY)
12323 && CHECK_FLAG(p->af_flags[afi][safi],
12324 PEER_FLAG_SEND_EXT_COMMUNITY)
12325 && CHECK_FLAG(p->af_flags[afi][safi],
12326 PEER_FLAG_SEND_LARGE_COMMUNITY))
12327 vty_out(vty, "(all)\n");
12328 else if (CHECK_FLAG(p->af_flags[afi][safi],
12329 PEER_FLAG_SEND_LARGE_COMMUNITY))
12330 vty_out(vty, "(large)\n");
12331 else if (CHECK_FLAG(p->af_flags[afi][safi],
12332 PEER_FLAG_SEND_EXT_COMMUNITY))
12333 vty_out(vty, "(extended)\n");
12334 else
12335 vty_out(vty, "(standard)\n");
12336 }
12337 if (CHECK_FLAG(p->af_flags[afi][safi],
12338 PEER_FLAG_DEFAULT_ORIGINATE)) {
12339 vty_out(vty, " Default information originate,");
12340
12341 if (p->default_rmap[afi][safi].name)
12342 vty_out(vty, " default route-map %s%s,",
12343 p->default_rmap[afi][safi].map ? "*"
12344 : "",
12345 p->default_rmap[afi][safi].name);
12346 if (paf && PAF_SUBGRP(paf)
12347 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12348 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12349 vty_out(vty, " default sent\n");
12350 else
12351 vty_out(vty, " default not sent\n");
12352 }
12353
12354 /* advertise-vni-all */
12355 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12356 if (is_evpn_enabled())
12357 vty_out(vty, " advertise-all-vni\n");
12358 }
12359
12360 if (filter->plist[FILTER_IN].name
12361 || filter->dlist[FILTER_IN].name
12362 || filter->aslist[FILTER_IN].name
12363 || filter->map[RMAP_IN].name)
12364 vty_out(vty, " Inbound path policy configured\n");
12365 if (filter->plist[FILTER_OUT].name
12366 || filter->dlist[FILTER_OUT].name
12367 || filter->aslist[FILTER_OUT].name
12368 || filter->map[RMAP_OUT].name || filter->usmap.name)
12369 vty_out(vty, " Outbound path policy configured\n");
12370
12371 /* prefix-list */
12372 if (filter->plist[FILTER_IN].name)
12373 vty_out(vty,
12374 " Incoming update prefix filter list is %s%s\n",
12375 filter->plist[FILTER_IN].plist ? "*" : "",
12376 filter->plist[FILTER_IN].name);
12377 if (filter->plist[FILTER_OUT].name)
12378 vty_out(vty,
12379 " Outgoing update prefix filter list is %s%s\n",
12380 filter->plist[FILTER_OUT].plist ? "*" : "",
12381 filter->plist[FILTER_OUT].name);
12382
12383 /* distribute-list */
12384 if (filter->dlist[FILTER_IN].name)
12385 vty_out(vty,
12386 " Incoming update network filter list is %s%s\n",
12387 filter->dlist[FILTER_IN].alist ? "*" : "",
12388 filter->dlist[FILTER_IN].name);
12389 if (filter->dlist[FILTER_OUT].name)
12390 vty_out(vty,
12391 " Outgoing update network filter list is %s%s\n",
12392 filter->dlist[FILTER_OUT].alist ? "*" : "",
12393 filter->dlist[FILTER_OUT].name);
12394
12395 /* filter-list. */
12396 if (filter->aslist[FILTER_IN].name)
12397 vty_out(vty,
12398 " Incoming update AS path filter list is %s%s\n",
12399 filter->aslist[FILTER_IN].aslist ? "*" : "",
12400 filter->aslist[FILTER_IN].name);
12401 if (filter->aslist[FILTER_OUT].name)
12402 vty_out(vty,
12403 " Outgoing update AS path filter list is %s%s\n",
12404 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12405 filter->aslist[FILTER_OUT].name);
12406
12407 /* route-map. */
12408 if (filter->map[RMAP_IN].name)
12409 vty_out(vty,
12410 " Route map for incoming advertisements is %s%s\n",
12411 filter->map[RMAP_IN].map ? "*" : "",
12412 filter->map[RMAP_IN].name);
12413 if (filter->map[RMAP_OUT].name)
12414 vty_out(vty,
12415 " Route map for outgoing advertisements is %s%s\n",
12416 filter->map[RMAP_OUT].map ? "*" : "",
12417 filter->map[RMAP_OUT].name);
12418
12419 /* ebgp-requires-policy (inbound) */
12420 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12421 && !bgp_inbound_policy_exists(p, filter))
12422 vty_out(vty,
12423 " Inbound updates discarded due to missing policy\n");
12424
12425 /* ebgp-requires-policy (outbound) */
12426 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12427 && !bgp_outbound_policy_exists(p, filter))
12428 vty_out(vty,
12429 " Outbound updates discarded due to missing policy\n");
12430
12431 /* unsuppress-map */
12432 if (filter->usmap.name)
12433 vty_out(vty,
12434 " Route map for selective unsuppress is %s%s\n",
12435 filter->usmap.map ? "*" : "",
12436 filter->usmap.name);
12437
12438 /* advertise-map */
12439 if (filter->advmap.aname && filter->advmap.cname)
12440 vty_out(vty,
12441 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12442 filter->advmap.condition ? "EXIST"
12443 : "NON_EXIST",
12444 filter->advmap.cmap ? "*" : "",
12445 filter->advmap.cname,
12446 filter->advmap.amap ? "*" : "",
12447 filter->advmap.aname,
12448 filter->advmap.update_type ==
12449 UPDATE_TYPE_ADVERTISE
12450 ? "Advertise"
12451 : "Withdraw");
12452
12453 /* Receive prefix count */
12454 vty_out(vty, " %u accepted prefixes\n",
12455 p->pcount[afi][safi]);
12456
12457 /* maximum-prefix-out */
12458 if (CHECK_FLAG(p->af_flags[afi][safi],
12459 PEER_FLAG_MAX_PREFIX_OUT))
12460 vty_out(vty,
12461 " Maximum allowed prefixes sent %u\n",
12462 p->pmax_out[afi][safi]);
12463
12464 /* Maximum prefix */
12465 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12466 vty_out(vty,
12467 " Maximum prefixes allowed %u%s\n",
12468 p->pmax[afi][safi],
12469 CHECK_FLAG(p->af_flags[afi][safi],
12470 PEER_FLAG_MAX_PREFIX_WARNING)
12471 ? " (warning-only)"
12472 : "");
12473 vty_out(vty, " Threshold for warning message %d%%",
12474 p->pmax_threshold[afi][safi]);
12475 if (p->pmax_restart[afi][safi])
12476 vty_out(vty, ", restart interval %d min",
12477 p->pmax_restart[afi][safi]);
12478 vty_out(vty, "\n");
12479 }
12480
12481 vty_out(vty, "\n");
12482 }
12483 }
12484
12485 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12486 json_object *json)
12487 {
12488 struct bgp *bgp;
12489 char buf1[PREFIX2STR_BUFFER];
12490 char timebuf[BGP_UPTIME_LEN];
12491 char dn_flag[2];
12492 afi_t afi;
12493 safi_t safi;
12494 uint16_t i;
12495 uint8_t *msg;
12496 json_object *json_neigh = NULL;
12497 time_t epoch_tbuf;
12498 uint32_t sync_tcp_mss;
12499
12500 bgp = p->bgp;
12501
12502 if (use_json)
12503 json_neigh = json_object_new_object();
12504
12505 memset(dn_flag, '\0', sizeof(dn_flag));
12506 if (!p->conf_if && peer_dynamic_neighbor(p))
12507 dn_flag[0] = '*';
12508
12509 if (!use_json) {
12510 if (p->conf_if) /* Configured interface name. */
12511 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12512 &p->su);
12513 else /* Configured IP address. */
12514 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12515 p->host);
12516 }
12517
12518 if (use_json) {
12519 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12520 json_object_string_add(json_neigh, "bgpNeighborAddr",
12521 "none");
12522 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12523 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12524 "%pSU", &p->su);
12525
12526 json_object_int_add(json_neigh, "remoteAs", p->as);
12527
12528 if (p->change_local_as)
12529 json_object_int_add(json_neigh, "localAs",
12530 p->change_local_as);
12531 else
12532 json_object_int_add(json_neigh, "localAs", p->local_as);
12533
12534 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12535 json_object_boolean_true_add(json_neigh,
12536 "localAsNoPrepend");
12537
12538 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12539 json_object_boolean_true_add(json_neigh,
12540 "localAsReplaceAs");
12541 } else {
12542 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12543 || (p->as_type == AS_INTERNAL))
12544 vty_out(vty, "remote AS %u, ", p->as);
12545 else
12546 vty_out(vty, "remote AS Unspecified, ");
12547 vty_out(vty, "local AS %u%s%s, ",
12548 p->change_local_as ? p->change_local_as : p->local_as,
12549 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12550 ? " no-prepend"
12551 : "",
12552 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12553 ? " replace-as"
12554 : "");
12555 }
12556 /* peer type internal or confed-internal */
12557 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12558 if (use_json) {
12559 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12560 json_object_boolean_true_add(
12561 json_neigh, "nbrConfedInternalLink");
12562 else
12563 json_object_boolean_true_add(json_neigh,
12564 "nbrInternalLink");
12565 } else {
12566 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12567 vty_out(vty, "confed-internal link\n");
12568 else
12569 vty_out(vty, "internal link\n");
12570 }
12571 /* peer type external or confed-external */
12572 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12573 if (use_json) {
12574 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12575 json_object_boolean_true_add(
12576 json_neigh, "nbrConfedExternalLink");
12577 else
12578 json_object_boolean_true_add(json_neigh,
12579 "nbrExternalLink");
12580 } else {
12581 if (bgp_confederation_peers_check(bgp, p->as))
12582 vty_out(vty, "confed-external link\n");
12583 else
12584 vty_out(vty, "external link\n");
12585 }
12586 } else {
12587 if (use_json)
12588 json_object_boolean_true_add(json_neigh,
12589 "nbrUnspecifiedLink");
12590 else
12591 vty_out(vty, "unspecified link\n");
12592 }
12593
12594 /* Roles */
12595 if (use_json) {
12596 json_object_string_add(json_neigh, "localRole",
12597 bgp_get_name_by_role(p->local_role));
12598 json_object_string_add(json_neigh, "remoteRole",
12599 bgp_get_name_by_role(p->remote_role));
12600 } else {
12601 vty_out(vty, " Local Role: %s\n",
12602 bgp_get_name_by_role(p->local_role));
12603 vty_out(vty, " Remote Role: %s\n",
12604 bgp_get_name_by_role(p->remote_role));
12605 }
12606
12607
12608 /* Description. */
12609 if (p->desc) {
12610 if (use_json)
12611 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12612 else
12613 vty_out(vty, " Description: %s\n", p->desc);
12614 }
12615
12616 if (p->hostname) {
12617 if (use_json) {
12618 if (p->hostname)
12619 json_object_string_add(json_neigh, "hostname",
12620 p->hostname);
12621
12622 if (p->domainname)
12623 json_object_string_add(json_neigh, "domainname",
12624 p->domainname);
12625 } else {
12626 if (p->domainname && (p->domainname[0] != '\0'))
12627 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12628 p->domainname);
12629 else
12630 vty_out(vty, "Hostname: %s\n", p->hostname);
12631 }
12632 }
12633
12634 /* Peer-group */
12635 if (p->group) {
12636 if (use_json) {
12637 json_object_string_add(json_neigh, "peerGroup",
12638 p->group->name);
12639
12640 if (dn_flag[0]) {
12641 struct prefix prefix, *range = NULL;
12642
12643 if (sockunion2hostprefix(&(p->su), &prefix))
12644 range = peer_group_lookup_dynamic_neighbor_range(
12645 p->group, &prefix);
12646
12647 if (range) {
12648 json_object_string_addf(
12649 json_neigh,
12650 "peerSubnetRangeGroup", "%pFX",
12651 range);
12652 }
12653 }
12654 } else {
12655 vty_out(vty,
12656 " Member of peer-group %s for session parameters\n",
12657 p->group->name);
12658
12659 if (dn_flag[0]) {
12660 struct prefix prefix, *range = NULL;
12661
12662 if (sockunion2hostprefix(&(p->su), &prefix))
12663 range = peer_group_lookup_dynamic_neighbor_range(
12664 p->group, &prefix);
12665
12666 if (range) {
12667 vty_out(vty,
12668 " Belongs to the subnet range group: %pFX\n",
12669 range);
12670 }
12671 }
12672 }
12673 }
12674
12675 if (use_json) {
12676 /* Administrative shutdown. */
12677 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12678 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12679 json_object_boolean_true_add(json_neigh,
12680 "adminShutDown");
12681
12682 /* BGP Version. */
12683 json_object_int_add(json_neigh, "bgpVersion", 4);
12684 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12685 &p->remote_id);
12686 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12687 &bgp->router_id);
12688
12689 /* Confederation */
12690 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12691 && bgp_confederation_peers_check(bgp, p->as))
12692 json_object_boolean_true_add(json_neigh,
12693 "nbrCommonAdmin");
12694
12695 /* Status. */
12696 json_object_string_add(
12697 json_neigh, "bgpState",
12698 lookup_msg(bgp_status_msg, p->status, NULL));
12699
12700 if (peer_established(p)) {
12701 time_t uptime;
12702
12703 uptime = bgp_clock();
12704 uptime -= p->uptime;
12705 epoch_tbuf = time(NULL) - uptime;
12706
12707 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12708 uptime * 1000);
12709 json_object_string_add(json_neigh, "bgpTimerUpString",
12710 peer_uptime(p->uptime, timebuf,
12711 BGP_UPTIME_LEN, 0,
12712 NULL));
12713 json_object_int_add(json_neigh,
12714 "bgpTimerUpEstablishedEpoch",
12715 epoch_tbuf);
12716 }
12717
12718 else if (p->status == Active) {
12719 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12720 json_object_string_add(json_neigh, "bgpStateIs",
12721 "passive");
12722 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12723 json_object_string_add(json_neigh, "bgpStateIs",
12724 "passiveNSF");
12725 }
12726
12727 /* read timer */
12728 time_t uptime;
12729 struct tm tm;
12730
12731 uptime = bgp_clock();
12732 uptime -= p->readtime;
12733 gmtime_r(&uptime, &tm);
12734
12735 json_object_int_add(json_neigh, "bgpTimerLastRead",
12736 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12737 + (tm.tm_hour * 3600000));
12738
12739 uptime = bgp_clock();
12740 uptime -= p->last_write;
12741 gmtime_r(&uptime, &tm);
12742
12743 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12744 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12745 + (tm.tm_hour * 3600000));
12746
12747 uptime = bgp_clock();
12748 uptime -= p->update_time;
12749 gmtime_r(&uptime, &tm);
12750
12751 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12752 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12753 + (tm.tm_hour * 3600000));
12754
12755 /* Configured timer values. */
12756 json_object_int_add(json_neigh,
12757 "bgpTimerConfiguredHoldTimeMsecs",
12758 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12759 ? p->holdtime * 1000
12760 : bgp->default_holdtime * 1000);
12761 json_object_int_add(json_neigh,
12762 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12763 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12764 ? p->keepalive * 1000
12765 : bgp->default_keepalive * 1000);
12766 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12767 p->v_holdtime * 1000);
12768 json_object_int_add(json_neigh,
12769 "bgpTimerKeepAliveIntervalMsecs",
12770 p->v_keepalive * 1000);
12771 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12772 json_object_int_add(json_neigh,
12773 "bgpTimerDelayOpenTimeMsecs",
12774 p->v_delayopen * 1000);
12775 }
12776
12777 /* Configured and Synced tcp-mss value for peer */
12778 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12779 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12780 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12781 p->tcp_mss);
12782 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12783 sync_tcp_mss);
12784 }
12785
12786 /* Extended Optional Parameters Length for BGP OPEN Message */
12787 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12788 json_object_boolean_true_add(
12789 json_neigh, "extendedOptionalParametersLength");
12790 else
12791 json_object_boolean_false_add(
12792 json_neigh, "extendedOptionalParametersLength");
12793
12794 /* Conditional advertisements */
12795 json_object_int_add(
12796 json_neigh,
12797 "bgpTimerConfiguredConditionalAdvertisementsSec",
12798 bgp->condition_check_period);
12799 if (thread_is_scheduled(bgp->t_condition_check))
12800 json_object_int_add(
12801 json_neigh,
12802 "bgpTimerUntilConditionalAdvertisementsSec",
12803 thread_timer_remain_second(
12804 bgp->t_condition_check));
12805 } else {
12806 /* Administrative shutdown. */
12807 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12808 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12809 vty_out(vty, " Administratively shut down\n");
12810
12811 /* BGP Version. */
12812 vty_out(vty, " BGP version 4");
12813 vty_out(vty, ", remote router ID %s",
12814 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12815 vty_out(vty, ", local router ID %s\n",
12816 inet_ntop(AF_INET, &bgp->router_id, buf1,
12817 sizeof(buf1)));
12818
12819 /* Confederation */
12820 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12821 && bgp_confederation_peers_check(bgp, p->as))
12822 vty_out(vty,
12823 " Neighbor under common administration\n");
12824
12825 /* Status. */
12826 vty_out(vty, " BGP state = %s",
12827 lookup_msg(bgp_status_msg, p->status, NULL));
12828
12829 if (peer_established(p))
12830 vty_out(vty, ", up for %8s",
12831 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12832 0, NULL));
12833
12834 else if (p->status == Active) {
12835 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12836 vty_out(vty, " (passive)");
12837 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12838 vty_out(vty, " (NSF passive)");
12839 }
12840 vty_out(vty, "\n");
12841
12842 /* read timer */
12843 vty_out(vty, " Last read %s",
12844 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12845 NULL));
12846 vty_out(vty, ", Last write %s\n",
12847 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12848 NULL));
12849
12850 /* Configured timer values. */
12851 vty_out(vty,
12852 " Hold time is %d seconds, keepalive interval is %d seconds\n",
12853 p->v_holdtime, p->v_keepalive);
12854 vty_out(vty, " Configured hold time is %d seconds",
12855 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12856 ? p->holdtime
12857 : bgp->default_holdtime);
12858 vty_out(vty, ", keepalive interval is %d seconds\n",
12859 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12860 ? p->keepalive
12861 : bgp->default_keepalive);
12862 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12863 vty_out(vty,
12864 " Configured DelayOpenTime is %d seconds\n",
12865 p->delayopen);
12866
12867 /* Configured and synced tcp-mss value for peer */
12868 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12869 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12870 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12871 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12872 }
12873
12874 /* Extended Optional Parameters Length for BGP OPEN Message */
12875 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12876 vty_out(vty,
12877 " Extended Optional Parameters Length is enabled\n");
12878
12879 /* Conditional advertisements */
12880 vty_out(vty,
12881 " Configured conditional advertisements interval is %d seconds\n",
12882 bgp->condition_check_period);
12883 if (thread_is_scheduled(bgp->t_condition_check))
12884 vty_out(vty,
12885 " Time until conditional advertisements begin is %lu seconds\n",
12886 thread_timer_remain_second(
12887 bgp->t_condition_check));
12888 }
12889 /* Capability. */
12890 if (peer_established(p) &&
12891 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12892 if (use_json) {
12893 json_object *json_cap = NULL;
12894
12895 json_cap = json_object_new_object();
12896
12897 /* AS4 */
12898 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12899 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12900 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12901 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12902 json_object_string_add(
12903 json_cap, "4byteAs",
12904 "advertisedAndReceived");
12905 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12906 json_object_string_add(json_cap,
12907 "4byteAs",
12908 "advertised");
12909 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12910 json_object_string_add(json_cap,
12911 "4byteAs",
12912 "received");
12913 }
12914
12915 /* Extended Message Support */
12916 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12917 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12918 json_object_string_add(json_cap,
12919 "extendedMessage",
12920 "advertisedAndReceived");
12921 else if (CHECK_FLAG(p->cap,
12922 PEER_CAP_EXTENDED_MESSAGE_ADV))
12923 json_object_string_add(json_cap,
12924 "extendedMessage",
12925 "advertised");
12926 else if (CHECK_FLAG(p->cap,
12927 PEER_CAP_EXTENDED_MESSAGE_RCV))
12928 json_object_string_add(json_cap,
12929 "extendedMessage",
12930 "received");
12931
12932 /* AddPath */
12933 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12934 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12935 json_object *json_add = NULL;
12936 const char *print_store;
12937
12938 json_add = json_object_new_object();
12939
12940 FOREACH_AFI_SAFI (afi, safi) {
12941 json_object *json_sub = NULL;
12942 json_sub = json_object_new_object();
12943 print_store = get_afi_safi_str(
12944 afi, safi, true);
12945
12946 if (CHECK_FLAG(
12947 p->af_cap[afi][safi],
12948 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12949 CHECK_FLAG(
12950 p->af_cap[afi][safi],
12951 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12952 if (CHECK_FLAG(
12953 p->af_cap[afi]
12954 [safi],
12955 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12956 CHECK_FLAG(
12957 p->af_cap[afi]
12958 [safi],
12959 PEER_CAP_ADDPATH_AF_TX_RCV))
12960 json_object_boolean_true_add(
12961 json_sub,
12962 "txAdvertisedAndReceived");
12963 else if (
12964 CHECK_FLAG(
12965 p->af_cap[afi]
12966 [safi],
12967 PEER_CAP_ADDPATH_AF_TX_ADV))
12968 json_object_boolean_true_add(
12969 json_sub,
12970 "txAdvertised");
12971 else if (
12972 CHECK_FLAG(
12973 p->af_cap[afi]
12974 [safi],
12975 PEER_CAP_ADDPATH_AF_TX_RCV))
12976 json_object_boolean_true_add(
12977 json_sub,
12978 "txReceived");
12979 }
12980
12981 if (CHECK_FLAG(
12982 p->af_cap[afi][safi],
12983 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12984 CHECK_FLAG(
12985 p->af_cap[afi][safi],
12986 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12987 if (CHECK_FLAG(
12988 p->af_cap[afi]
12989 [safi],
12990 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12991 CHECK_FLAG(
12992 p->af_cap[afi]
12993 [safi],
12994 PEER_CAP_ADDPATH_AF_RX_RCV))
12995 json_object_boolean_true_add(
12996 json_sub,
12997 "rxAdvertisedAndReceived");
12998 else if (
12999 CHECK_FLAG(
13000 p->af_cap[afi]
13001 [safi],
13002 PEER_CAP_ADDPATH_AF_RX_ADV))
13003 json_object_boolean_true_add(
13004 json_sub,
13005 "rxAdvertised");
13006 else if (
13007 CHECK_FLAG(
13008 p->af_cap[afi]
13009 [safi],
13010 PEER_CAP_ADDPATH_AF_RX_RCV))
13011 json_object_boolean_true_add(
13012 json_sub,
13013 "rxReceived");
13014 }
13015
13016 if (CHECK_FLAG(
13017 p->af_cap[afi][safi],
13018 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13019 CHECK_FLAG(
13020 p->af_cap[afi][safi],
13021 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13022 CHECK_FLAG(
13023 p->af_cap[afi][safi],
13024 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13025 CHECK_FLAG(
13026 p->af_cap[afi][safi],
13027 PEER_CAP_ADDPATH_AF_RX_RCV))
13028 json_object_object_add(
13029 json_add, print_store,
13030 json_sub);
13031 else
13032 json_object_free(json_sub);
13033 }
13034
13035 json_object_object_add(json_cap, "addPath",
13036 json_add);
13037 }
13038
13039 /* Dynamic */
13040 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13041 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13042 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13043 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13044 json_object_string_add(
13045 json_cap, "dynamic",
13046 "advertisedAndReceived");
13047 else if (CHECK_FLAG(p->cap,
13048 PEER_CAP_DYNAMIC_ADV))
13049 json_object_string_add(json_cap,
13050 "dynamic",
13051 "advertised");
13052 else if (CHECK_FLAG(p->cap,
13053 PEER_CAP_DYNAMIC_RCV))
13054 json_object_string_add(json_cap,
13055 "dynamic",
13056 "received");
13057 }
13058
13059 /* Role */
13060 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13061 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13062 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13063 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13064 json_object_string_add(
13065 json_cap, "role",
13066 "advertisedAndReceived");
13067 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13068 json_object_string_add(json_cap, "role",
13069 "advertised");
13070 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13071 json_object_string_add(json_cap, "role",
13072 "received");
13073 }
13074
13075 /* Extended nexthop */
13076 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13077 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13078 json_object *json_nxt = NULL;
13079 const char *print_store;
13080
13081
13082 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13083 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13084 json_object_string_add(
13085 json_cap, "extendedNexthop",
13086 "advertisedAndReceived");
13087 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13088 json_object_string_add(
13089 json_cap, "extendedNexthop",
13090 "advertised");
13091 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13092 json_object_string_add(
13093 json_cap, "extendedNexthop",
13094 "received");
13095
13096 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13097 json_nxt = json_object_new_object();
13098
13099 for (safi = SAFI_UNICAST;
13100 safi < SAFI_MAX; safi++) {
13101 if (CHECK_FLAG(
13102 p->af_cap[AFI_IP]
13103 [safi],
13104 PEER_CAP_ENHE_AF_RCV)) {
13105 print_store =
13106 get_afi_safi_str(
13107 AFI_IP,
13108 safi,
13109 true);
13110 json_object_string_add(
13111 json_nxt,
13112 print_store,
13113 "recieved"); /* misspelled for compatibility */
13114 }
13115 }
13116 json_object_object_add(
13117 json_cap,
13118 "extendedNexthopFamililesByPeer",
13119 json_nxt);
13120 }
13121 }
13122
13123 /* Long-lived Graceful Restart */
13124 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13125 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13126 json_object *json_llgr = NULL;
13127 const char *afi_safi_str;
13128
13129 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13130 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13131 json_object_string_add(
13132 json_cap,
13133 "longLivedGracefulRestart",
13134 "advertisedAndReceived");
13135 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13136 json_object_string_add(
13137 json_cap,
13138 "longLivedGracefulRestart",
13139 "advertised");
13140 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13141 json_object_string_add(
13142 json_cap,
13143 "longLivedGracefulRestart",
13144 "received");
13145
13146 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13147 json_llgr = json_object_new_object();
13148
13149 FOREACH_AFI_SAFI (afi, safi) {
13150 if (CHECK_FLAG(
13151 p->af_cap[afi]
13152 [safi],
13153 PEER_CAP_ENHE_AF_RCV)) {
13154 afi_safi_str =
13155 get_afi_safi_str(
13156 afi,
13157 safi,
13158 true);
13159 json_object_string_add(
13160 json_llgr,
13161 afi_safi_str,
13162 "received");
13163 }
13164 }
13165 json_object_object_add(
13166 json_cap,
13167 "longLivedGracefulRestartByPeer",
13168 json_llgr);
13169 }
13170 }
13171
13172 /* Route Refresh */
13173 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13174 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13175 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13176 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13177 (CHECK_FLAG(p->cap,
13178 PEER_CAP_REFRESH_NEW_RCV) ||
13179 CHECK_FLAG(p->cap,
13180 PEER_CAP_REFRESH_OLD_RCV))) {
13181 if (CHECK_FLAG(
13182 p->cap,
13183 PEER_CAP_REFRESH_OLD_RCV) &&
13184 CHECK_FLAG(
13185 p->cap,
13186 PEER_CAP_REFRESH_NEW_RCV))
13187 json_object_string_add(
13188 json_cap,
13189 "routeRefresh",
13190 "advertisedAndReceivedOldNew");
13191 else {
13192 if (CHECK_FLAG(
13193 p->cap,
13194 PEER_CAP_REFRESH_OLD_RCV))
13195 json_object_string_add(
13196 json_cap,
13197 "routeRefresh",
13198 "advertisedAndReceivedOld");
13199 else
13200 json_object_string_add(
13201 json_cap,
13202 "routeRefresh",
13203 "advertisedAndReceivedNew");
13204 }
13205 } else if (CHECK_FLAG(p->cap,
13206 PEER_CAP_REFRESH_ADV))
13207 json_object_string_add(json_cap,
13208 "routeRefresh",
13209 "advertised");
13210 else if (CHECK_FLAG(p->cap,
13211 PEER_CAP_REFRESH_NEW_RCV) ||
13212 CHECK_FLAG(p->cap,
13213 PEER_CAP_REFRESH_OLD_RCV))
13214 json_object_string_add(json_cap,
13215 "routeRefresh",
13216 "received");
13217 }
13218
13219 /* Enhanced Route Refresh */
13220 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13221 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13222 if (CHECK_FLAG(p->cap,
13223 PEER_CAP_ENHANCED_RR_ADV) &&
13224 CHECK_FLAG(p->cap,
13225 PEER_CAP_ENHANCED_RR_RCV))
13226 json_object_string_add(
13227 json_cap,
13228 "enhancedRouteRefresh",
13229 "advertisedAndReceived");
13230 else if (CHECK_FLAG(p->cap,
13231 PEER_CAP_ENHANCED_RR_ADV))
13232 json_object_string_add(
13233 json_cap,
13234 "enhancedRouteRefresh",
13235 "advertised");
13236 else if (CHECK_FLAG(p->cap,
13237 PEER_CAP_ENHANCED_RR_RCV))
13238 json_object_string_add(
13239 json_cap,
13240 "enhancedRouteRefresh",
13241 "received");
13242 }
13243
13244 /* Multiprotocol Extensions */
13245 json_object *json_multi = NULL;
13246
13247 json_multi = json_object_new_object();
13248
13249 FOREACH_AFI_SAFI (afi, safi) {
13250 if (p->afc_adv[afi][safi] ||
13251 p->afc_recv[afi][safi]) {
13252 json_object *json_exten = NULL;
13253 json_exten = json_object_new_object();
13254
13255 if (p->afc_adv[afi][safi] &&
13256 p->afc_recv[afi][safi])
13257 json_object_boolean_true_add(
13258 json_exten,
13259 "advertisedAndReceived");
13260 else if (p->afc_adv[afi][safi])
13261 json_object_boolean_true_add(
13262 json_exten,
13263 "advertised");
13264 else if (p->afc_recv[afi][safi])
13265 json_object_boolean_true_add(
13266 json_exten, "received");
13267
13268 json_object_object_add(
13269 json_multi,
13270 get_afi_safi_str(afi, safi,
13271 true),
13272 json_exten);
13273 }
13274 }
13275 json_object_object_add(json_cap,
13276 "multiprotocolExtensions",
13277 json_multi);
13278
13279 /* Hostname capabilities */
13280 json_object *json_hname = NULL;
13281
13282 json_hname = json_object_new_object();
13283
13284 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13285 json_object_string_add(
13286 json_hname, "advHostName",
13287 bgp->peer_self->hostname
13288 ? bgp->peer_self->hostname
13289 : "n/a");
13290 json_object_string_add(
13291 json_hname, "advDomainName",
13292 bgp->peer_self->domainname
13293 ? bgp->peer_self->domainname
13294 : "n/a");
13295 }
13296
13297
13298 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13299 json_object_string_add(
13300 json_hname, "rcvHostName",
13301 p->hostname ? p->hostname : "n/a");
13302 json_object_string_add(
13303 json_hname, "rcvDomainName",
13304 p->domainname ? p->domainname : "n/a");
13305 }
13306
13307 json_object_object_add(json_cap, "hostName",
13308 json_hname);
13309
13310 /* Graceful Restart */
13311 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13312 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13313 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13314 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13315 json_object_string_add(
13316 json_cap, "gracefulRestart",
13317 "advertisedAndReceived");
13318 else if (CHECK_FLAG(p->cap,
13319 PEER_CAP_RESTART_ADV))
13320 json_object_string_add(
13321 json_cap,
13322 "gracefulRestartCapability",
13323 "advertised");
13324 else if (CHECK_FLAG(p->cap,
13325 PEER_CAP_RESTART_RCV))
13326 json_object_string_add(
13327 json_cap,
13328 "gracefulRestartCapability",
13329 "received");
13330
13331 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13332 int restart_af_count = 0;
13333 json_object *json_restart = NULL;
13334 json_restart = json_object_new_object();
13335
13336 json_object_int_add(
13337 json_cap,
13338 "gracefulRestartRemoteTimerMsecs",
13339 p->v_gr_restart * 1000);
13340
13341 FOREACH_AFI_SAFI (afi, safi) {
13342 if (CHECK_FLAG(
13343 p->af_cap[afi]
13344 [safi],
13345 PEER_CAP_RESTART_AF_RCV)) {
13346 json_object *json_sub =
13347 NULL;
13348 json_sub =
13349 json_object_new_object();
13350
13351 if (CHECK_FLAG(
13352 p->af_cap
13353 [afi]
13354 [safi],
13355 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13356 json_object_boolean_true_add(
13357 json_sub,
13358 "preserved");
13359 restart_af_count++;
13360 json_object_object_add(
13361 json_restart,
13362 get_afi_safi_str(
13363 afi,
13364 safi,
13365 true),
13366 json_sub);
13367 }
13368 }
13369 if (!restart_af_count) {
13370 json_object_string_add(
13371 json_cap,
13372 "addressFamiliesByPeer",
13373 "none");
13374 json_object_free(json_restart);
13375 } else
13376 json_object_object_add(
13377 json_cap,
13378 "addressFamiliesByPeer",
13379 json_restart);
13380 }
13381 }
13382 json_object_object_add(
13383 json_neigh, "neighborCapabilities", json_cap);
13384 } else {
13385 vty_out(vty, " Neighbor capabilities:\n");
13386
13387 /* AS4 */
13388 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13389 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13390 vty_out(vty, " 4 Byte AS:");
13391 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13392 vty_out(vty, " advertised");
13393 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13394 vty_out(vty, " %sreceived",
13395 CHECK_FLAG(p->cap,
13396 PEER_CAP_AS4_ADV)
13397 ? "and "
13398 : "");
13399 vty_out(vty, "\n");
13400 }
13401
13402 /* Extended Message Support */
13403 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13404 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13405 vty_out(vty, " Extended Message:");
13406 if (CHECK_FLAG(p->cap,
13407 PEER_CAP_EXTENDED_MESSAGE_ADV))
13408 vty_out(vty, " advertised");
13409 if (CHECK_FLAG(p->cap,
13410 PEER_CAP_EXTENDED_MESSAGE_RCV))
13411 vty_out(vty, " %sreceived",
13412 CHECK_FLAG(
13413 p->cap,
13414 PEER_CAP_EXTENDED_MESSAGE_ADV)
13415 ? "and "
13416 : "");
13417 vty_out(vty, "\n");
13418 }
13419
13420 /* AddPath */
13421 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13422 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13423 vty_out(vty, " AddPath:\n");
13424
13425 FOREACH_AFI_SAFI (afi, safi) {
13426 if (CHECK_FLAG(
13427 p->af_cap[afi][safi],
13428 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13429 CHECK_FLAG(
13430 p->af_cap[afi][safi],
13431 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13432 vty_out(vty, " %s: TX ",
13433 get_afi_safi_str(
13434 afi, safi,
13435 false));
13436
13437 if (CHECK_FLAG(
13438 p->af_cap[afi]
13439 [safi],
13440 PEER_CAP_ADDPATH_AF_TX_ADV))
13441 vty_out(vty,
13442 "advertised");
13443
13444 if (CHECK_FLAG(
13445 p->af_cap[afi]
13446 [safi],
13447 PEER_CAP_ADDPATH_AF_TX_RCV))
13448 vty_out(vty,
13449 "%sreceived",
13450 CHECK_FLAG(
13451 p->af_cap
13452 [afi]
13453 [safi],
13454 PEER_CAP_ADDPATH_AF_TX_ADV)
13455 ? " and "
13456 : "");
13457
13458 vty_out(vty, "\n");
13459 }
13460
13461 if (CHECK_FLAG(
13462 p->af_cap[afi][safi],
13463 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13464 CHECK_FLAG(
13465 p->af_cap[afi][safi],
13466 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13467 vty_out(vty, " %s: RX ",
13468 get_afi_safi_str(
13469 afi, safi,
13470 false));
13471
13472 if (CHECK_FLAG(
13473 p->af_cap[afi]
13474 [safi],
13475 PEER_CAP_ADDPATH_AF_RX_ADV))
13476 vty_out(vty,
13477 "advertised");
13478
13479 if (CHECK_FLAG(
13480 p->af_cap[afi]
13481 [safi],
13482 PEER_CAP_ADDPATH_AF_RX_RCV))
13483 vty_out(vty,
13484 "%sreceived",
13485 CHECK_FLAG(
13486 p->af_cap
13487 [afi]
13488 [safi],
13489 PEER_CAP_ADDPATH_AF_RX_ADV)
13490 ? " and "
13491 : "");
13492
13493 vty_out(vty, "\n");
13494 }
13495 }
13496 }
13497
13498 /* Dynamic */
13499 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13500 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13501 vty_out(vty, " Dynamic:");
13502 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13503 vty_out(vty, " advertised");
13504 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13505 vty_out(vty, " %sreceived",
13506 CHECK_FLAG(p->cap,
13507 PEER_CAP_DYNAMIC_ADV)
13508 ? "and "
13509 : "");
13510 vty_out(vty, "\n");
13511 }
13512
13513 /* Role */
13514 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13515 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13516 vty_out(vty, " Role:");
13517 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13518 vty_out(vty, " advertised");
13519 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13520 vty_out(vty, " %sreceived",
13521 CHECK_FLAG(p->cap,
13522 PEER_CAP_ROLE_ADV)
13523 ? "and "
13524 : "");
13525 vty_out(vty, "\n");
13526 }
13527
13528 /* Extended nexthop */
13529 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13530 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13531 vty_out(vty, " Extended nexthop:");
13532 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13533 vty_out(vty, " advertised");
13534 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13535 vty_out(vty, " %sreceived",
13536 CHECK_FLAG(p->cap,
13537 PEER_CAP_ENHE_ADV)
13538 ? "and "
13539 : "");
13540 vty_out(vty, "\n");
13541
13542 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13543 vty_out(vty,
13544 " Address families by peer:\n ");
13545 for (safi = SAFI_UNICAST;
13546 safi < SAFI_MAX; safi++)
13547 if (CHECK_FLAG(
13548 p->af_cap[AFI_IP]
13549 [safi],
13550 PEER_CAP_ENHE_AF_RCV))
13551 vty_out(vty,
13552 " %s\n",
13553 get_afi_safi_str(
13554 AFI_IP,
13555 safi,
13556 false));
13557 }
13558 }
13559
13560 /* Long-lived Graceful Restart */
13561 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13562 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13563 vty_out(vty,
13564 " Long-lived Graceful Restart:");
13565 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13566 vty_out(vty, " advertised");
13567 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13568 vty_out(vty, " %sreceived",
13569 CHECK_FLAG(p->cap,
13570 PEER_CAP_LLGR_ADV)
13571 ? "and "
13572 : "");
13573 vty_out(vty, "\n");
13574
13575 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13576 vty_out(vty,
13577 " Address families by peer:\n");
13578 FOREACH_AFI_SAFI (afi, safi)
13579 if (CHECK_FLAG(
13580 p->af_cap[afi]
13581 [safi],
13582 PEER_CAP_LLGR_AF_RCV))
13583 vty_out(vty,
13584 " %s\n",
13585 get_afi_safi_str(
13586 afi,
13587 safi,
13588 false));
13589 }
13590 }
13591
13592 /* Route Refresh */
13593 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13594 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13595 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13596 vty_out(vty, " Route refresh:");
13597 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13598 vty_out(vty, " advertised");
13599 if (CHECK_FLAG(p->cap,
13600 PEER_CAP_REFRESH_NEW_RCV) ||
13601 CHECK_FLAG(p->cap,
13602 PEER_CAP_REFRESH_OLD_RCV))
13603 vty_out(vty, " %sreceived(%s)",
13604 CHECK_FLAG(p->cap,
13605 PEER_CAP_REFRESH_ADV)
13606 ? "and "
13607 : "",
13608 (CHECK_FLAG(
13609 p->cap,
13610 PEER_CAP_REFRESH_OLD_RCV) &&
13611 CHECK_FLAG(
13612 p->cap,
13613 PEER_CAP_REFRESH_NEW_RCV))
13614 ? "old & new"
13615 : CHECK_FLAG(
13616 p->cap,
13617 PEER_CAP_REFRESH_OLD_RCV)
13618 ? "old"
13619 : "new");
13620
13621 vty_out(vty, "\n");
13622 }
13623
13624 /* Enhanced Route Refresh */
13625 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13626 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13627 vty_out(vty, " Enhanced Route Refresh:");
13628 if (CHECK_FLAG(p->cap,
13629 PEER_CAP_ENHANCED_RR_ADV))
13630 vty_out(vty, " advertised");
13631 if (CHECK_FLAG(p->cap,
13632 PEER_CAP_ENHANCED_RR_RCV))
13633 vty_out(vty, " %sreceived",
13634 CHECK_FLAG(p->cap,
13635 PEER_CAP_REFRESH_ADV)
13636 ? "and "
13637 : "");
13638 vty_out(vty, "\n");
13639 }
13640
13641 /* Multiprotocol Extensions */
13642 FOREACH_AFI_SAFI (afi, safi)
13643 if (p->afc_adv[afi][safi] ||
13644 p->afc_recv[afi][safi]) {
13645 vty_out(vty, " Address Family %s:",
13646 get_afi_safi_str(afi, safi,
13647 false));
13648 if (p->afc_adv[afi][safi])
13649 vty_out(vty, " advertised");
13650 if (p->afc_recv[afi][safi])
13651 vty_out(vty, " %sreceived",
13652 p->afc_adv[afi][safi]
13653 ? "and "
13654 : "");
13655 vty_out(vty, "\n");
13656 }
13657
13658 /* Hostname capability */
13659 vty_out(vty, " Hostname Capability:");
13660
13661 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13662 vty_out(vty,
13663 " advertised (name: %s,domain name: %s)",
13664 bgp->peer_self->hostname
13665 ? bgp->peer_self->hostname
13666 : "n/a",
13667 bgp->peer_self->domainname
13668 ? bgp->peer_self->domainname
13669 : "n/a");
13670 } else {
13671 vty_out(vty, " not advertised");
13672 }
13673
13674 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13675 vty_out(vty,
13676 " received (name: %s,domain name: %s)",
13677 p->hostname ? p->hostname : "n/a",
13678 p->domainname ? p->domainname : "n/a");
13679 } else {
13680 vty_out(vty, " not received");
13681 }
13682
13683 vty_out(vty, "\n");
13684
13685 /* Graceful Restart */
13686 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13687 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13688 vty_out(vty,
13689 " Graceful Restart Capability:");
13690 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13691 vty_out(vty, " advertised");
13692 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13693 vty_out(vty, " %sreceived",
13694 CHECK_FLAG(p->cap,
13695 PEER_CAP_RESTART_ADV)
13696 ? "and "
13697 : "");
13698 vty_out(vty, "\n");
13699
13700 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13701 int restart_af_count = 0;
13702
13703 vty_out(vty,
13704 " Remote Restart timer is %d seconds\n",
13705 p->v_gr_restart);
13706 vty_out(vty,
13707 " Address families by peer:\n ");
13708
13709 FOREACH_AFI_SAFI (afi, safi)
13710 if (CHECK_FLAG(
13711 p->af_cap[afi]
13712 [safi],
13713 PEER_CAP_RESTART_AF_RCV)) {
13714 vty_out(vty, "%s%s(%s)",
13715 restart_af_count
13716 ? ", "
13717 : "",
13718 get_afi_safi_str(
13719 afi,
13720 safi,
13721 false),
13722 CHECK_FLAG(
13723 p->af_cap
13724 [afi]
13725 [safi],
13726 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13727 ? "preserved"
13728 : "not preserved");
13729 restart_af_count++;
13730 }
13731 if (!restart_af_count)
13732 vty_out(vty, "none");
13733 vty_out(vty, "\n");
13734 }
13735 } /* Graceful Restart */
13736 }
13737 }
13738
13739 /* graceful restart information */
13740 json_object *json_grace = NULL;
13741 json_object *json_grace_send = NULL;
13742 json_object *json_grace_recv = NULL;
13743 int eor_send_af_count = 0;
13744 int eor_receive_af_count = 0;
13745
13746 if (use_json) {
13747 json_grace = json_object_new_object();
13748 json_grace_send = json_object_new_object();
13749 json_grace_recv = json_object_new_object();
13750
13751 if ((peer_established(p)) &&
13752 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13753 FOREACH_AFI_SAFI (afi, safi) {
13754 if (CHECK_FLAG(p->af_sflags[afi][safi],
13755 PEER_STATUS_EOR_SEND)) {
13756 json_object_boolean_true_add(
13757 json_grace_send,
13758 get_afi_safi_str(afi, safi,
13759 true));
13760 eor_send_af_count++;
13761 }
13762 }
13763 FOREACH_AFI_SAFI (afi, safi) {
13764 if (CHECK_FLAG(p->af_sflags[afi][safi],
13765 PEER_STATUS_EOR_RECEIVED)) {
13766 json_object_boolean_true_add(
13767 json_grace_recv,
13768 get_afi_safi_str(afi, safi,
13769 true));
13770 eor_receive_af_count++;
13771 }
13772 }
13773 }
13774 json_object_object_add(json_grace, "endOfRibSend",
13775 json_grace_send);
13776 json_object_object_add(json_grace, "endOfRibRecv",
13777 json_grace_recv);
13778
13779
13780 if (p->t_gr_restart)
13781 json_object_int_add(
13782 json_grace, "gracefulRestartTimerMsecs",
13783 thread_timer_remain_second(p->t_gr_restart) *
13784 1000);
13785
13786 if (p->t_gr_stale)
13787 json_object_int_add(
13788 json_grace, "gracefulStalepathTimerMsecs",
13789 thread_timer_remain_second(p->t_gr_stale) *
13790 1000);
13791 /* more gr info in new format */
13792 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13793 json_object_object_add(json_neigh, "gracefulRestartInfo",
13794 json_grace);
13795 } else {
13796 vty_out(vty, " Graceful restart information:\n");
13797 if ((peer_established(p)) &&
13798 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13799
13800 vty_out(vty, " End-of-RIB send: ");
13801 FOREACH_AFI_SAFI (afi, safi) {
13802 if (CHECK_FLAG(p->af_sflags[afi][safi],
13803 PEER_STATUS_EOR_SEND)) {
13804 vty_out(vty, "%s%s",
13805 eor_send_af_count ? ", " : "",
13806 get_afi_safi_str(afi, safi,
13807 false));
13808 eor_send_af_count++;
13809 }
13810 }
13811 vty_out(vty, "\n");
13812 vty_out(vty, " End-of-RIB received: ");
13813 FOREACH_AFI_SAFI (afi, safi) {
13814 if (CHECK_FLAG(p->af_sflags[afi][safi],
13815 PEER_STATUS_EOR_RECEIVED)) {
13816 vty_out(vty, "%s%s",
13817 eor_receive_af_count ? ", "
13818 : "",
13819 get_afi_safi_str(afi, safi,
13820 false));
13821 eor_receive_af_count++;
13822 }
13823 }
13824 vty_out(vty, "\n");
13825 }
13826
13827 if (p->t_gr_restart)
13828 vty_out(vty,
13829 " The remaining time of restart timer is %ld\n",
13830 thread_timer_remain_second(p->t_gr_restart));
13831
13832 if (p->t_gr_stale)
13833 vty_out(vty,
13834 " The remaining time of stalepath timer is %ld\n",
13835 thread_timer_remain_second(p->t_gr_stale));
13836
13837 /* more gr info in new format */
13838 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13839 }
13840
13841 if (use_json) {
13842 json_object *json_stat = NULL;
13843 json_stat = json_object_new_object();
13844 /* Packet counts. */
13845
13846 atomic_size_t outq_count, inq_count;
13847 outq_count = atomic_load_explicit(&p->obuf->count,
13848 memory_order_relaxed);
13849 inq_count = atomic_load_explicit(&p->ibuf->count,
13850 memory_order_relaxed);
13851
13852 json_object_int_add(json_stat, "depthInq",
13853 (unsigned long)inq_count);
13854 json_object_int_add(json_stat, "depthOutq",
13855 (unsigned long)outq_count);
13856 json_object_int_add(json_stat, "opensSent",
13857 atomic_load_explicit(&p->open_out,
13858 memory_order_relaxed));
13859 json_object_int_add(json_stat, "opensRecv",
13860 atomic_load_explicit(&p->open_in,
13861 memory_order_relaxed));
13862 json_object_int_add(json_stat, "notificationsSent",
13863 atomic_load_explicit(&p->notify_out,
13864 memory_order_relaxed));
13865 json_object_int_add(json_stat, "notificationsRecv",
13866 atomic_load_explicit(&p->notify_in,
13867 memory_order_relaxed));
13868 json_object_int_add(json_stat, "updatesSent",
13869 atomic_load_explicit(&p->update_out,
13870 memory_order_relaxed));
13871 json_object_int_add(json_stat, "updatesRecv",
13872 atomic_load_explicit(&p->update_in,
13873 memory_order_relaxed));
13874 json_object_int_add(json_stat, "keepalivesSent",
13875 atomic_load_explicit(&p->keepalive_out,
13876 memory_order_relaxed));
13877 json_object_int_add(json_stat, "keepalivesRecv",
13878 atomic_load_explicit(&p->keepalive_in,
13879 memory_order_relaxed));
13880 json_object_int_add(json_stat, "routeRefreshSent",
13881 atomic_load_explicit(&p->refresh_out,
13882 memory_order_relaxed));
13883 json_object_int_add(json_stat, "routeRefreshRecv",
13884 atomic_load_explicit(&p->refresh_in,
13885 memory_order_relaxed));
13886 json_object_int_add(json_stat, "capabilitySent",
13887 atomic_load_explicit(&p->dynamic_cap_out,
13888 memory_order_relaxed));
13889 json_object_int_add(json_stat, "capabilityRecv",
13890 atomic_load_explicit(&p->dynamic_cap_in,
13891 memory_order_relaxed));
13892 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13893 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13894 json_object_object_add(json_neigh, "messageStats", json_stat);
13895 } else {
13896 atomic_size_t outq_count, inq_count, open_out, open_in,
13897 notify_out, notify_in, update_out, update_in,
13898 keepalive_out, keepalive_in, refresh_out, refresh_in,
13899 dynamic_cap_out, dynamic_cap_in;
13900 outq_count = atomic_load_explicit(&p->obuf->count,
13901 memory_order_relaxed);
13902 inq_count = atomic_load_explicit(&p->ibuf->count,
13903 memory_order_relaxed);
13904 open_out = atomic_load_explicit(&p->open_out,
13905 memory_order_relaxed);
13906 open_in =
13907 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13908 notify_out = atomic_load_explicit(&p->notify_out,
13909 memory_order_relaxed);
13910 notify_in = atomic_load_explicit(&p->notify_in,
13911 memory_order_relaxed);
13912 update_out = atomic_load_explicit(&p->update_out,
13913 memory_order_relaxed);
13914 update_in = atomic_load_explicit(&p->update_in,
13915 memory_order_relaxed);
13916 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13917 memory_order_relaxed);
13918 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13919 memory_order_relaxed);
13920 refresh_out = atomic_load_explicit(&p->refresh_out,
13921 memory_order_relaxed);
13922 refresh_in = atomic_load_explicit(&p->refresh_in,
13923 memory_order_relaxed);
13924 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13925 memory_order_relaxed);
13926 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13927 memory_order_relaxed);
13928
13929 /* Packet counts. */
13930 vty_out(vty, " Message statistics:\n");
13931 vty_out(vty, " Inq depth is %zu\n", inq_count);
13932 vty_out(vty, " Outq depth is %zu\n", outq_count);
13933 vty_out(vty, " Sent Rcvd\n");
13934 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13935 open_in);
13936 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13937 notify_in);
13938 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13939 update_in);
13940 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13941 keepalive_in);
13942 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13943 refresh_in);
13944 vty_out(vty, " Capability: %10zu %10zu\n",
13945 dynamic_cap_out, dynamic_cap_in);
13946 vty_out(vty, " Total: %10u %10u\n",
13947 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
13948 }
13949
13950 if (use_json) {
13951 /* advertisement-interval */
13952 json_object_int_add(json_neigh,
13953 "minBtwnAdvertisementRunsTimerMsecs",
13954 p->v_routeadv * 1000);
13955
13956 /* Update-source. */
13957 if (p->update_if || p->update_source) {
13958 if (p->update_if)
13959 json_object_string_add(json_neigh,
13960 "updateSource",
13961 p->update_if);
13962 else if (p->update_source)
13963 json_object_string_addf(json_neigh,
13964 "updateSource", "%pSU",
13965 p->update_source);
13966 }
13967 } else {
13968 /* advertisement-interval */
13969 vty_out(vty,
13970 " Minimum time between advertisement runs is %d seconds\n",
13971 p->v_routeadv);
13972
13973 /* Update-source. */
13974 if (p->update_if || p->update_source) {
13975 vty_out(vty, " Update source is ");
13976 if (p->update_if)
13977 vty_out(vty, "%s", p->update_if);
13978 else if (p->update_source)
13979 vty_out(vty, "%pSU", p->update_source);
13980 vty_out(vty, "\n");
13981 }
13982
13983 vty_out(vty, "\n");
13984 }
13985
13986 /* Address Family Information */
13987 json_object *json_hold = NULL;
13988
13989 if (use_json)
13990 json_hold = json_object_new_object();
13991
13992 FOREACH_AFI_SAFI (afi, safi)
13993 if (p->afc[afi][safi])
13994 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13995 json_hold);
13996
13997 if (use_json) {
13998 json_object_object_add(json_neigh, "addressFamilyInfo",
13999 json_hold);
14000 json_object_int_add(json_neigh, "connectionsEstablished",
14001 p->established);
14002 json_object_int_add(json_neigh, "connectionsDropped",
14003 p->dropped);
14004 } else
14005 vty_out(vty, " Connections established %d; dropped %d\n",
14006 p->established, p->dropped);
14007
14008 if (!p->last_reset) {
14009 if (use_json)
14010 json_object_string_add(json_neigh, "lastReset",
14011 "never");
14012 else
14013 vty_out(vty, " Last reset never\n");
14014 } else {
14015 if (use_json) {
14016 time_t uptime;
14017 struct tm tm;
14018
14019 uptime = bgp_clock();
14020 uptime -= p->resettime;
14021 gmtime_r(&uptime, &tm);
14022
14023 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14024 (tm.tm_sec * 1000)
14025 + (tm.tm_min * 60000)
14026 + (tm.tm_hour * 3600000));
14027 bgp_show_peer_reset(NULL, p, json_neigh, true);
14028 } else {
14029 vty_out(vty, " Last reset %s, ",
14030 peer_uptime(p->resettime, timebuf,
14031 BGP_UPTIME_LEN, 0, NULL));
14032
14033 bgp_show_peer_reset(vty, p, NULL, false);
14034 if (p->last_reset_cause_size) {
14035 msg = p->last_reset_cause;
14036 vty_out(vty,
14037 " Message received that caused BGP to send a NOTIFICATION:\n ");
14038 for (i = 1; i <= p->last_reset_cause_size;
14039 i++) {
14040 vty_out(vty, "%02X", *msg++);
14041
14042 if (i != p->last_reset_cause_size) {
14043 if (i % 16 == 0) {
14044 vty_out(vty, "\n ");
14045 } else if (i % 4 == 0) {
14046 vty_out(vty, " ");
14047 }
14048 }
14049 }
14050 vty_out(vty, "\n");
14051 }
14052 }
14053 }
14054
14055 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14056 if (use_json)
14057 json_object_boolean_true_add(json_neigh,
14058 "prefixesConfigExceedMax");
14059 else
14060 vty_out(vty,
14061 " Peer had exceeded the max. no. of prefixes configured.\n");
14062
14063 if (p->t_pmax_restart) {
14064 if (use_json) {
14065 json_object_boolean_true_add(
14066 json_neigh, "reducePrefixNumFrom");
14067 json_object_int_add(json_neigh,
14068 "restartInTimerMsec",
14069 thread_timer_remain_second(
14070 p->t_pmax_restart)
14071 * 1000);
14072 } else
14073 vty_out(vty,
14074 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14075 p->host, thread_timer_remain_second(
14076 p->t_pmax_restart));
14077 } else {
14078 if (use_json)
14079 json_object_boolean_true_add(
14080 json_neigh,
14081 "reducePrefixNumAndClearIpBgp");
14082 else
14083 vty_out(vty,
14084 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14085 p->host);
14086 }
14087 }
14088
14089 /* EBGP Multihop and GTSM */
14090 if (p->sort != BGP_PEER_IBGP) {
14091 if (use_json) {
14092 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14093 json_object_int_add(json_neigh,
14094 "externalBgpNbrMaxHopsAway",
14095 p->gtsm_hops);
14096 else
14097 json_object_int_add(json_neigh,
14098 "externalBgpNbrMaxHopsAway",
14099 p->ttl);
14100 } else {
14101 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14102 vty_out(vty,
14103 " External BGP neighbor may be up to %d hops away.\n",
14104 p->gtsm_hops);
14105 else
14106 vty_out(vty,
14107 " External BGP neighbor may be up to %d hops away.\n",
14108 p->ttl);
14109 }
14110 } else {
14111 if (use_json) {
14112 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14113 json_object_int_add(json_neigh,
14114 "internalBgpNbrMaxHopsAway",
14115 p->gtsm_hops);
14116 else
14117 json_object_int_add(json_neigh,
14118 "internalBgpNbrMaxHopsAway",
14119 p->ttl);
14120 } else {
14121 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14122 vty_out(vty,
14123 " Internal BGP neighbor may be up to %d hops away.\n",
14124 p->gtsm_hops);
14125 else
14126 vty_out(vty,
14127 " Internal BGP neighbor may be up to %d hops away.\n",
14128 p->ttl);
14129 }
14130 }
14131
14132 /* Local address. */
14133 if (p->su_local) {
14134 if (use_json) {
14135 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14136 p->su_local);
14137 json_object_int_add(json_neigh, "portLocal",
14138 ntohs(p->su_local->sin.sin_port));
14139 } else
14140 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14141 p->su_local, ntohs(p->su_local->sin.sin_port));
14142 } else {
14143 if (use_json) {
14144 json_object_string_add(json_neigh, "hostLocal",
14145 "Unknown");
14146 json_object_int_add(json_neigh, "portLocal", -1);
14147 }
14148 }
14149
14150 /* Remote address. */
14151 if (p->su_remote) {
14152 if (use_json) {
14153 json_object_string_addf(json_neigh, "hostForeign",
14154 "%pSU", p->su_remote);
14155 json_object_int_add(json_neigh, "portForeign",
14156 ntohs(p->su_remote->sin.sin_port));
14157 } else
14158 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14159 p->su_remote,
14160 ntohs(p->su_remote->sin.sin_port));
14161 } else {
14162 if (use_json) {
14163 json_object_string_add(json_neigh, "hostForeign",
14164 "Unknown");
14165 json_object_int_add(json_neigh, "portForeign", -1);
14166 }
14167 }
14168
14169 /* Nexthop display. */
14170 if (p->su_local) {
14171 if (use_json) {
14172 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14173 &p->nexthop.v4);
14174 json_object_string_addf(json_neigh, "nexthopGlobal",
14175 "%pI6", &p->nexthop.v6_global);
14176 json_object_string_addf(json_neigh, "nexthopLocal",
14177 "%pI6", &p->nexthop.v6_local);
14178 if (p->shared_network)
14179 json_object_string_add(json_neigh,
14180 "bgpConnection",
14181 "sharedNetwork");
14182 else
14183 json_object_string_add(json_neigh,
14184 "bgpConnection",
14185 "nonSharedNetwork");
14186 } else {
14187 vty_out(vty, "Nexthop: %s\n",
14188 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14189 sizeof(buf1)));
14190 vty_out(vty, "Nexthop global: %s\n",
14191 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14192 sizeof(buf1)));
14193 vty_out(vty, "Nexthop local: %s\n",
14194 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14195 sizeof(buf1)));
14196 vty_out(vty, "BGP connection: %s\n",
14197 p->shared_network ? "shared network"
14198 : "non shared network");
14199 }
14200 }
14201
14202 /* Timer information. */
14203 if (use_json) {
14204 json_object_int_add(json_neigh, "connectRetryTimer",
14205 p->v_connect);
14206 if (peer_established(p) && p->rtt)
14207 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14208 p->rtt);
14209 if (p->t_start)
14210 json_object_int_add(
14211 json_neigh, "nextStartTimerDueInMsecs",
14212 thread_timer_remain_second(p->t_start) * 1000);
14213 if (p->t_connect)
14214 json_object_int_add(
14215 json_neigh, "nextConnectTimerDueInMsecs",
14216 thread_timer_remain_second(p->t_connect)
14217 * 1000);
14218 if (p->t_routeadv) {
14219 json_object_int_add(json_neigh, "mraiInterval",
14220 p->v_routeadv);
14221 json_object_int_add(
14222 json_neigh, "mraiTimerExpireInMsecs",
14223 thread_timer_remain_second(p->t_routeadv)
14224 * 1000);
14225 }
14226 if (p->password)
14227 json_object_int_add(json_neigh, "authenticationEnabled",
14228 1);
14229
14230 if (p->t_read)
14231 json_object_string_add(json_neigh, "readThread", "on");
14232 else
14233 json_object_string_add(json_neigh, "readThread", "off");
14234
14235 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14236 json_object_string_add(json_neigh, "writeThread", "on");
14237 else
14238 json_object_string_add(json_neigh, "writeThread",
14239 "off");
14240 } else {
14241 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14242 p->v_connect);
14243 if (peer_established(p) && p->rtt)
14244 vty_out(vty, "Estimated round trip time: %d ms\n",
14245 p->rtt);
14246 if (p->t_start)
14247 vty_out(vty, "Next start timer due in %ld seconds\n",
14248 thread_timer_remain_second(p->t_start));
14249 if (p->t_connect)
14250 vty_out(vty, "Next connect timer due in %ld seconds\n",
14251 thread_timer_remain_second(p->t_connect));
14252 if (p->t_routeadv)
14253 vty_out(vty,
14254 "MRAI (interval %u) timer expires in %ld seconds\n",
14255 p->v_routeadv,
14256 thread_timer_remain_second(p->t_routeadv));
14257 if (p->password)
14258 vty_out(vty, "Peer Authentication Enabled\n");
14259
14260 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14261 p->t_read ? "on" : "off",
14262 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14263 ? "on"
14264 : "off", p->fd);
14265 }
14266
14267 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14268 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14269 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14270
14271 if (!use_json)
14272 vty_out(vty, "\n");
14273
14274 /* BFD information. */
14275 if (p->bfd_config)
14276 bgp_bfd_show_info(vty, p, json_neigh);
14277
14278 if (use_json) {
14279 if (p->conf_if) /* Configured interface name. */
14280 json_object_object_add(json, p->conf_if, json_neigh);
14281 else /* Configured IP address. */
14282 json_object_object_add(json, p->host, json_neigh);
14283 }
14284 }
14285
14286 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14287 enum show_type type,
14288 union sockunion *su,
14289 const char *conf_if, afi_t afi,
14290 bool use_json)
14291 {
14292 struct listnode *node, *nnode;
14293 struct peer *peer;
14294 int find = 0;
14295 safi_t safi = SAFI_UNICAST;
14296 json_object *json = NULL;
14297 json_object *json_neighbor = NULL;
14298
14299 if (use_json) {
14300 json = json_object_new_object();
14301 json_neighbor = json_object_new_object();
14302 }
14303
14304 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14305
14306 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14307 continue;
14308
14309 if ((peer->afc[afi][safi]) == 0)
14310 continue;
14311
14312 if (type == show_all) {
14313 bgp_show_peer_gr_status(vty, peer, use_json,
14314 json_neighbor);
14315
14316 if (use_json) {
14317 json_object_object_add(json, peer->host,
14318 json_neighbor);
14319 json_neighbor = NULL;
14320 }
14321
14322 } else if (type == show_peer) {
14323 if (conf_if) {
14324 if ((peer->conf_if
14325 && !strcmp(peer->conf_if, conf_if))
14326 || (peer->hostname
14327 && !strcmp(peer->hostname, conf_if))) {
14328 find = 1;
14329 bgp_show_peer_gr_status(vty, peer,
14330 use_json,
14331 json_neighbor);
14332 }
14333 } else {
14334 if (sockunion_same(&peer->su, su)) {
14335 find = 1;
14336 bgp_show_peer_gr_status(vty, peer,
14337 use_json,
14338 json_neighbor);
14339 }
14340 }
14341 if (use_json && find)
14342 json_object_object_add(json, peer->host,
14343 json_neighbor);
14344 }
14345
14346 if (find) {
14347 json_neighbor = NULL;
14348 break;
14349 }
14350 }
14351
14352 if (type == show_peer && !find) {
14353 if (use_json)
14354 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14355 else
14356 vty_out(vty, "%% No such neighbor\n");
14357 }
14358 if (use_json) {
14359 if (json_neighbor)
14360 json_object_free(json_neighbor);
14361 vty_json(vty, json);
14362 } else {
14363 vty_out(vty, "\n");
14364 }
14365
14366 return CMD_SUCCESS;
14367 }
14368
14369 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14370 enum show_type type, union sockunion *su,
14371 const char *conf_if, bool use_json,
14372 json_object *json)
14373 {
14374 struct listnode *node, *nnode;
14375 struct peer *peer;
14376 int find = 0;
14377 bool nbr_output = false;
14378 afi_t afi = AFI_MAX;
14379 safi_t safi = SAFI_MAX;
14380
14381 if (type == show_ipv4_peer || type == show_ipv4_all) {
14382 afi = AFI_IP;
14383 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14384 afi = AFI_IP6;
14385 }
14386
14387 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14388 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14389 continue;
14390
14391 switch (type) {
14392 case show_all:
14393 bgp_show_peer(vty, peer, use_json, json);
14394 nbr_output = true;
14395 break;
14396 case show_peer:
14397 if (conf_if) {
14398 if ((peer->conf_if
14399 && !strcmp(peer->conf_if, conf_if))
14400 || (peer->hostname
14401 && !strcmp(peer->hostname, conf_if))) {
14402 find = 1;
14403 bgp_show_peer(vty, peer, use_json,
14404 json);
14405 }
14406 } else {
14407 if (sockunion_same(&peer->su, su)) {
14408 find = 1;
14409 bgp_show_peer(vty, peer, use_json,
14410 json);
14411 }
14412 }
14413 break;
14414 case show_ipv4_peer:
14415 case show_ipv6_peer:
14416 FOREACH_SAFI (safi) {
14417 if (peer->afc[afi][safi]) {
14418 if (conf_if) {
14419 if ((peer->conf_if
14420 && !strcmp(peer->conf_if, conf_if))
14421 || (peer->hostname
14422 && !strcmp(peer->hostname, conf_if))) {
14423 find = 1;
14424 bgp_show_peer(vty, peer, use_json,
14425 json);
14426 break;
14427 }
14428 } else {
14429 if (sockunion_same(&peer->su, su)) {
14430 find = 1;
14431 bgp_show_peer(vty, peer, use_json,
14432 json);
14433 break;
14434 }
14435 }
14436 }
14437 }
14438 break;
14439 case show_ipv4_all:
14440 case show_ipv6_all:
14441 FOREACH_SAFI (safi) {
14442 if (peer->afc[afi][safi]) {
14443 bgp_show_peer(vty, peer, use_json, json);
14444 nbr_output = true;
14445 break;
14446 }
14447 }
14448 break;
14449 }
14450 }
14451
14452 if ((type == show_peer || type == show_ipv4_peer ||
14453 type == show_ipv6_peer) && !find) {
14454 if (use_json)
14455 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14456 else
14457 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14458 }
14459
14460 if (type != show_peer && type != show_ipv4_peer &&
14461 type != show_ipv6_peer && !nbr_output && !use_json)
14462 vty_out(vty, "%% No BGP neighbors found\n");
14463
14464 if (use_json) {
14465 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14466 json, JSON_C_TO_STRING_PRETTY));
14467 } else {
14468 vty_out(vty, "\n");
14469 }
14470
14471 return CMD_SUCCESS;
14472 }
14473
14474 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14475 enum show_type type,
14476 const char *ip_str,
14477 afi_t afi, bool use_json)
14478 {
14479
14480 int ret;
14481 struct bgp *bgp;
14482 union sockunion su;
14483
14484 bgp = bgp_get_default();
14485
14486 if (!bgp)
14487 return;
14488
14489 if (!use_json)
14490 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14491 NULL);
14492
14493 if (ip_str) {
14494 ret = str2sockunion(ip_str, &su);
14495 if (ret < 0)
14496 bgp_show_neighbor_graceful_restart(
14497 vty, bgp, type, NULL, ip_str, afi, use_json);
14498 else
14499 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14500 NULL, afi, use_json);
14501 } else
14502 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14503 afi, use_json);
14504 }
14505
14506 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14507 enum show_type type,
14508 const char *ip_str,
14509 bool use_json)
14510 {
14511 struct listnode *node, *nnode;
14512 struct bgp *bgp;
14513 union sockunion su;
14514 json_object *json = NULL;
14515 int ret, is_first = 1;
14516 bool nbr_output = false;
14517
14518 if (use_json)
14519 vty_out(vty, "{\n");
14520
14521 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14522 nbr_output = true;
14523 if (use_json) {
14524 if (!(json = json_object_new_object())) {
14525 flog_err(
14526 EC_BGP_JSON_MEM_ERROR,
14527 "Unable to allocate memory for JSON object");
14528 vty_out(vty,
14529 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14530 return;
14531 }
14532
14533 json_object_int_add(json, "vrfId",
14534 (bgp->vrf_id == VRF_UNKNOWN)
14535 ? -1
14536 : (int64_t)bgp->vrf_id);
14537 json_object_string_add(
14538 json, "vrfName",
14539 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14540 ? VRF_DEFAULT_NAME
14541 : bgp->name);
14542
14543 if (!is_first)
14544 vty_out(vty, ",\n");
14545 else
14546 is_first = 0;
14547
14548 vty_out(vty, "\"%s\":",
14549 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14550 ? VRF_DEFAULT_NAME
14551 : bgp->name);
14552 } else {
14553 vty_out(vty, "\nInstance %s:\n",
14554 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14555 ? VRF_DEFAULT_NAME
14556 : bgp->name);
14557 }
14558
14559 if (type == show_peer || type == show_ipv4_peer ||
14560 type == show_ipv6_peer) {
14561 ret = str2sockunion(ip_str, &su);
14562 if (ret < 0)
14563 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14564 use_json, json);
14565 else
14566 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14567 use_json, json);
14568 } else {
14569 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14570 use_json, json);
14571 }
14572 json_object_free(json);
14573 json = NULL;
14574 }
14575
14576 if (use_json)
14577 vty_out(vty, "}\n");
14578 else if (!nbr_output)
14579 vty_out(vty, "%% BGP instance not found\n");
14580 }
14581
14582 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14583 enum show_type type, const char *ip_str,
14584 bool use_json)
14585 {
14586 int ret;
14587 struct bgp *bgp;
14588 union sockunion su;
14589 json_object *json = NULL;
14590
14591 if (name) {
14592 if (strmatch(name, "all")) {
14593 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14594 use_json);
14595 return CMD_SUCCESS;
14596 } else {
14597 bgp = bgp_lookup_by_name(name);
14598 if (!bgp) {
14599 if (use_json) {
14600 json = json_object_new_object();
14601 vty_json(vty, json);
14602 } else
14603 vty_out(vty,
14604 "%% BGP instance not found\n");
14605
14606 return CMD_WARNING;
14607 }
14608 }
14609 } else {
14610 bgp = bgp_get_default();
14611 }
14612
14613 if (bgp) {
14614 json = json_object_new_object();
14615 if (ip_str) {
14616 ret = str2sockunion(ip_str, &su);
14617 if (ret < 0)
14618 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14619 use_json, json);
14620 else
14621 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14622 use_json, json);
14623 } else {
14624 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14625 json);
14626 }
14627 json_object_free(json);
14628 } else {
14629 if (use_json)
14630 vty_out(vty, "{}\n");
14631 else
14632 vty_out(vty, "%% BGP instance not found\n");
14633 }
14634
14635 return CMD_SUCCESS;
14636 }
14637
14638
14639
14640 /* "show [ip] bgp neighbors graceful-restart" commands. */
14641 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14642 show_ip_bgp_neighbors_graceful_restart_cmd,
14643 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14644 SHOW_STR
14645 BGP_STR
14646 IP_STR
14647 IPV6_STR
14648 NEIGHBOR_STR
14649 "Neighbor to display information about\n"
14650 "Neighbor to display information about\n"
14651 "Neighbor on BGP configured interface\n"
14652 GR_SHOW
14653 JSON_STR)
14654 {
14655 char *sh_arg = NULL;
14656 enum show_type sh_type;
14657 int idx = 0;
14658 afi_t afi = AFI_MAX;
14659 bool uj = use_json(argc, argv);
14660
14661 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14662 afi = AFI_MAX;
14663
14664 idx++;
14665
14666 if (argv_find(argv, argc, "A.B.C.D", &idx)
14667 || argv_find(argv, argc, "X:X::X:X", &idx)
14668 || argv_find(argv, argc, "WORD", &idx)) {
14669 sh_type = show_peer;
14670 sh_arg = argv[idx]->arg;
14671 } else
14672 sh_type = show_all;
14673
14674 if (!argv_find(argv, argc, "graceful-restart", &idx))
14675 return CMD_SUCCESS;
14676
14677
14678 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14679 afi, uj);
14680 }
14681
14682 /* "show [ip] bgp neighbors" commands. */
14683 DEFUN (show_ip_bgp_neighbors,
14684 show_ip_bgp_neighbors_cmd,
14685 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14686 SHOW_STR
14687 IP_STR
14688 BGP_STR
14689 BGP_INSTANCE_HELP_STR
14690 BGP_AF_STR
14691 BGP_AF_STR
14692 "Detailed information on TCP and BGP neighbor connections\n"
14693 "Neighbor to display information about\n"
14694 "Neighbor to display information about\n"
14695 "Neighbor on BGP configured interface\n"
14696 JSON_STR)
14697 {
14698 char *vrf = NULL;
14699 char *sh_arg = NULL;
14700 enum show_type sh_type;
14701 afi_t afi = AFI_MAX;
14702
14703 bool uj = use_json(argc, argv);
14704
14705 int idx = 0;
14706
14707 /* [<vrf> VIEWVRFNAME] */
14708 if (argv_find(argv, argc, "vrf", &idx)) {
14709 vrf = argv[idx + 1]->arg;
14710 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14711 vrf = NULL;
14712 } else if (argv_find(argv, argc, "view", &idx))
14713 /* [<view> VIEWVRFNAME] */
14714 vrf = argv[idx + 1]->arg;
14715
14716 idx++;
14717
14718 if (argv_find(argv, argc, "ipv4", &idx)) {
14719 sh_type = show_ipv4_all;
14720 afi = AFI_IP;
14721 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14722 sh_type = show_ipv6_all;
14723 afi = AFI_IP6;
14724 } else {
14725 sh_type = show_all;
14726 }
14727
14728 if (argv_find(argv, argc, "A.B.C.D", &idx)
14729 || argv_find(argv, argc, "X:X::X:X", &idx)
14730 || argv_find(argv, argc, "WORD", &idx)) {
14731 sh_type = show_peer;
14732 sh_arg = argv[idx]->arg;
14733 }
14734
14735 if (sh_type == show_peer && afi == AFI_IP) {
14736 sh_type = show_ipv4_peer;
14737 } else if (sh_type == show_peer && afi == AFI_IP6) {
14738 sh_type = show_ipv6_peer;
14739 }
14740
14741 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14742 }
14743
14744 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14745 paths' and `show ip mbgp paths'. Those functions results are the
14746 same.*/
14747 DEFUN (show_ip_bgp_paths,
14748 show_ip_bgp_paths_cmd,
14749 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14750 SHOW_STR
14751 IP_STR
14752 BGP_STR
14753 BGP_SAFI_HELP_STR
14754 "Path information\n")
14755 {
14756 vty_out(vty, "Address Refcnt Path\n");
14757 aspath_print_all_vty(vty);
14758 return CMD_SUCCESS;
14759 }
14760
14761 #include "hash.h"
14762
14763 static void community_show_all_iterator(struct hash_bucket *bucket,
14764 struct vty *vty)
14765 {
14766 struct community *com;
14767
14768 com = (struct community *)bucket->data;
14769 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14770 community_str(com, false, false));
14771 }
14772
14773 /* Show BGP's community internal data. */
14774 DEFUN (show_ip_bgp_community_info,
14775 show_ip_bgp_community_info_cmd,
14776 "show [ip] bgp community-info",
14777 SHOW_STR
14778 IP_STR
14779 BGP_STR
14780 "List all bgp community information\n")
14781 {
14782 vty_out(vty, "Address Refcnt Community\n");
14783
14784 hash_iterate(community_hash(),
14785 (void (*)(struct hash_bucket *,
14786 void *))community_show_all_iterator,
14787 vty);
14788
14789 return CMD_SUCCESS;
14790 }
14791
14792 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14793 struct vty *vty)
14794 {
14795 struct lcommunity *lcom;
14796
14797 lcom = (struct lcommunity *)bucket->data;
14798 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14799 lcommunity_str(lcom, false, false));
14800 }
14801
14802 /* Show BGP's community internal data. */
14803 DEFUN (show_ip_bgp_lcommunity_info,
14804 show_ip_bgp_lcommunity_info_cmd,
14805 "show ip bgp large-community-info",
14806 SHOW_STR
14807 IP_STR
14808 BGP_STR
14809 "List all bgp large-community information\n")
14810 {
14811 vty_out(vty, "Address Refcnt Large-community\n");
14812
14813 hash_iterate(lcommunity_hash(),
14814 (void (*)(struct hash_bucket *,
14815 void *))lcommunity_show_all_iterator,
14816 vty);
14817
14818 return CMD_SUCCESS;
14819 }
14820 /* Graceful Restart */
14821
14822 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14823 struct bgp *bgp,
14824 bool use_json,
14825 json_object *json)
14826 {
14827
14828
14829 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14830
14831 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14832
14833 switch (bgp_global_gr_mode) {
14834
14835 case GLOBAL_HELPER:
14836 vty_out(vty, "Global BGP GR Mode : Helper\n");
14837 break;
14838
14839 case GLOBAL_GR:
14840 vty_out(vty, "Global BGP GR Mode : Restart\n");
14841 break;
14842
14843 case GLOBAL_DISABLE:
14844 vty_out(vty, "Global BGP GR Mode : Disable\n");
14845 break;
14846
14847 case GLOBAL_INVALID:
14848 vty_out(vty,
14849 "Global BGP GR Mode Invalid\n");
14850 break;
14851 }
14852 vty_out(vty, "\n");
14853 }
14854
14855 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14856 enum show_type type,
14857 const char *ip_str,
14858 afi_t afi, bool use_json)
14859 {
14860 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14861 afi = AFI_IP;
14862
14863 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14864
14865 bgp_show_neighbor_graceful_restart_vty(
14866 vty, type, ip_str, afi, use_json);
14867 afi++;
14868 }
14869 } else if (afi != AFI_MAX) {
14870 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14871 use_json);
14872 } else {
14873 return CMD_ERR_INCOMPLETE;
14874 }
14875
14876 return CMD_SUCCESS;
14877 }
14878 /* Graceful Restart */
14879
14880 DEFUN (show_ip_bgp_attr_info,
14881 show_ip_bgp_attr_info_cmd,
14882 "show [ip] bgp attribute-info",
14883 SHOW_STR
14884 IP_STR
14885 BGP_STR
14886 "List all bgp attribute information\n")
14887 {
14888 attr_show_all(vty);
14889 return CMD_SUCCESS;
14890 }
14891
14892 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14893 afi_t afi, safi_t safi,
14894 bool use_json, json_object *json)
14895 {
14896 struct bgp *bgp;
14897 struct listnode *node;
14898 char *vname;
14899 char buf1[INET6_ADDRSTRLEN];
14900 char *ecom_str;
14901 enum vpn_policy_direction dir;
14902
14903 if (json) {
14904 json_object *json_import_vrfs = NULL;
14905 json_object *json_export_vrfs = NULL;
14906
14907 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14908
14909 if (!bgp) {
14910 vty_json(vty, json);
14911
14912 return CMD_WARNING;
14913 }
14914
14915 /* Provide context for the block */
14916 json_object_string_add(json, "vrf", name ? name : "default");
14917 json_object_string_add(json, "afiSafi",
14918 get_afi_safi_str(afi, safi, true));
14919
14920 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14921 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14922 json_object_string_add(json, "importFromVrfs", "none");
14923 json_object_string_add(json, "importRts", "none");
14924 } else {
14925 json_import_vrfs = json_object_new_array();
14926
14927 for (ALL_LIST_ELEMENTS_RO(
14928 bgp->vpn_policy[afi].import_vrf,
14929 node, vname))
14930 json_object_array_add(json_import_vrfs,
14931 json_object_new_string(vname));
14932
14933 json_object_object_add(json, "importFromVrfs",
14934 json_import_vrfs);
14935 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14936 if (bgp->vpn_policy[afi].rtlist[dir]) {
14937 ecom_str = ecommunity_ecom2str(
14938 bgp->vpn_policy[afi].rtlist[dir],
14939 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14940 json_object_string_add(json, "importRts",
14941 ecom_str);
14942 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14943 } else
14944 json_object_string_add(json, "importRts",
14945 "none");
14946 }
14947
14948 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14949 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14950 json_object_string_add(json, "exportToVrfs", "none");
14951 json_object_string_add(json, "routeDistinguisher",
14952 "none");
14953 json_object_string_add(json, "exportRts", "none");
14954 } else {
14955 json_export_vrfs = json_object_new_array();
14956
14957 for (ALL_LIST_ELEMENTS_RO(
14958 bgp->vpn_policy[afi].export_vrf,
14959 node, vname))
14960 json_object_array_add(json_export_vrfs,
14961 json_object_new_string(vname));
14962 json_object_object_add(json, "exportToVrfs",
14963 json_export_vrfs);
14964 json_object_string_add(json, "routeDistinguisher",
14965 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14966 buf1, RD_ADDRSTRLEN));
14967
14968 dir = BGP_VPN_POLICY_DIR_TOVPN;
14969 if (bgp->vpn_policy[afi].rtlist[dir]) {
14970 ecom_str = ecommunity_ecom2str(
14971 bgp->vpn_policy[afi].rtlist[dir],
14972 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14973 json_object_string_add(json, "exportRts",
14974 ecom_str);
14975 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14976 } else
14977 json_object_string_add(json, "exportRts",
14978 "none");
14979 }
14980
14981 if (use_json) {
14982 vty_json(vty, json);
14983 }
14984 } else {
14985 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14986
14987 if (!bgp) {
14988 vty_out(vty, "%% No such BGP instance exist\n");
14989 return CMD_WARNING;
14990 }
14991
14992 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14993 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14994 vty_out(vty,
14995 "This VRF is not importing %s routes from any other VRF\n",
14996 get_afi_safi_str(afi, safi, false));
14997 else {
14998 vty_out(vty,
14999 "This VRF is importing %s routes from the following VRFs:\n",
15000 get_afi_safi_str(afi, safi, false));
15001
15002 for (ALL_LIST_ELEMENTS_RO(
15003 bgp->vpn_policy[afi].import_vrf,
15004 node, vname))
15005 vty_out(vty, " %s\n", vname);
15006
15007 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15008 ecom_str = NULL;
15009 if (bgp->vpn_policy[afi].rtlist[dir]) {
15010 ecom_str = ecommunity_ecom2str(
15011 bgp->vpn_policy[afi].rtlist[dir],
15012 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15013 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15014
15015 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15016 } else
15017 vty_out(vty, "Import RT(s):\n");
15018 }
15019
15020 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15021 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15022 vty_out(vty,
15023 "This VRF is not exporting %s routes to any other VRF\n",
15024 get_afi_safi_str(afi, safi, false));
15025 else {
15026 vty_out(vty,
15027 "This VRF is exporting %s routes to the following VRFs:\n",
15028 get_afi_safi_str(afi, safi, false));
15029
15030 for (ALL_LIST_ELEMENTS_RO(
15031 bgp->vpn_policy[afi].export_vrf,
15032 node, vname))
15033 vty_out(vty, " %s\n", vname);
15034
15035 vty_out(vty, "RD: %s\n",
15036 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15037 buf1, RD_ADDRSTRLEN));
15038
15039 dir = BGP_VPN_POLICY_DIR_TOVPN;
15040 if (bgp->vpn_policy[afi].rtlist[dir]) {
15041 ecom_str = ecommunity_ecom2str(
15042 bgp->vpn_policy[afi].rtlist[dir],
15043 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15044 vty_out(vty, "Export RT: %s\n", ecom_str);
15045 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15046 } else
15047 vty_out(vty, "Import RT(s):\n");
15048 }
15049 }
15050
15051 return CMD_SUCCESS;
15052 }
15053
15054 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15055 safi_t safi, bool use_json)
15056 {
15057 struct listnode *node, *nnode;
15058 struct bgp *bgp;
15059 char *vrf_name = NULL;
15060 json_object *json = NULL;
15061 json_object *json_vrf = NULL;
15062 json_object *json_vrfs = NULL;
15063
15064 if (use_json) {
15065 json = json_object_new_object();
15066 json_vrfs = json_object_new_object();
15067 }
15068
15069 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15070
15071 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15072 vrf_name = bgp->name;
15073
15074 if (use_json) {
15075 json_vrf = json_object_new_object();
15076 } else {
15077 vty_out(vty, "\nInstance %s:\n",
15078 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15079 ? VRF_DEFAULT_NAME : bgp->name);
15080 }
15081 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15082 if (use_json) {
15083 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15084 json_object_object_add(json_vrfs,
15085 VRF_DEFAULT_NAME, json_vrf);
15086 else
15087 json_object_object_add(json_vrfs, vrf_name,
15088 json_vrf);
15089 }
15090 }
15091
15092 if (use_json) {
15093 json_object_object_add(json, "vrfs", json_vrfs);
15094 vty_json(vty, json);
15095 }
15096
15097 return CMD_SUCCESS;
15098 }
15099
15100 /* "show [ip] bgp route-leak" command. */
15101 DEFUN (show_ip_bgp_route_leak,
15102 show_ip_bgp_route_leak_cmd,
15103 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15104 SHOW_STR
15105 IP_STR
15106 BGP_STR
15107 BGP_INSTANCE_HELP_STR
15108 BGP_AFI_HELP_STR
15109 BGP_SAFI_HELP_STR
15110 "Route leaking information\n"
15111 JSON_STR)
15112 {
15113 char *vrf = NULL;
15114 afi_t afi = AFI_MAX;
15115 safi_t safi = SAFI_MAX;
15116
15117 bool uj = use_json(argc, argv);
15118 int idx = 0;
15119 json_object *json = NULL;
15120
15121 /* show [ip] bgp */
15122 if (argv_find(argv, argc, "ip", &idx)) {
15123 afi = AFI_IP;
15124 safi = SAFI_UNICAST;
15125 }
15126 /* [vrf VIEWVRFNAME] */
15127 if (argv_find(argv, argc, "view", &idx)) {
15128 vty_out(vty,
15129 "%% This command is not applicable to BGP views\n");
15130 return CMD_WARNING;
15131 }
15132
15133 if (argv_find(argv, argc, "vrf", &idx)) {
15134 vrf = argv[idx + 1]->arg;
15135 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15136 vrf = NULL;
15137 }
15138 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15139 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15140 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15141
15142 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15143 vty_out(vty,
15144 "%% This command is applicable only for unicast ipv4|ipv6\n");
15145 return CMD_WARNING;
15146 }
15147
15148 if (vrf && strmatch(vrf, "all"))
15149 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15150
15151 if (uj)
15152 json = json_object_new_object();
15153
15154 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15155 }
15156
15157 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15158 safi_t safi)
15159 {
15160 struct listnode *node, *nnode;
15161 struct bgp *bgp;
15162
15163 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15164 vty_out(vty, "\nInstance %s:\n",
15165 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15166 ? VRF_DEFAULT_NAME
15167 : bgp->name);
15168 update_group_show(bgp, afi, safi, vty, 0);
15169 }
15170 }
15171
15172 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15173 int safi, uint64_t subgrp_id)
15174 {
15175 struct bgp *bgp;
15176
15177 if (name) {
15178 if (strmatch(name, "all")) {
15179 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15180 return CMD_SUCCESS;
15181 } else {
15182 bgp = bgp_lookup_by_name(name);
15183 }
15184 } else {
15185 bgp = bgp_get_default();
15186 }
15187
15188 if (bgp)
15189 update_group_show(bgp, afi, safi, vty, subgrp_id);
15190 return CMD_SUCCESS;
15191 }
15192
15193 DEFUN (show_ip_bgp_updgrps,
15194 show_ip_bgp_updgrps_cmd,
15195 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15196 SHOW_STR
15197 IP_STR
15198 BGP_STR
15199 BGP_INSTANCE_HELP_STR
15200 BGP_AFI_HELP_STR
15201 BGP_SAFI_WITH_LABEL_HELP_STR
15202 "Detailed info about dynamic update groups\n"
15203 "Specific subgroup to display detailed info for\n")
15204 {
15205 char *vrf = NULL;
15206 afi_t afi = AFI_IP6;
15207 safi_t safi = SAFI_UNICAST;
15208 uint64_t subgrp_id = 0;
15209
15210 int idx = 0;
15211
15212 /* show [ip] bgp */
15213 if (argv_find(argv, argc, "ip", &idx))
15214 afi = AFI_IP;
15215 /* [<vrf> VIEWVRFNAME] */
15216 if (argv_find(argv, argc, "vrf", &idx)) {
15217 vrf = argv[idx + 1]->arg;
15218 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15219 vrf = NULL;
15220 } else if (argv_find(argv, argc, "view", &idx))
15221 /* [<view> VIEWVRFNAME] */
15222 vrf = argv[idx + 1]->arg;
15223 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15224 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15225 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15226 }
15227
15228 /* get subgroup id, if provided */
15229 idx = argc - 1;
15230 if (argv[idx]->type == VARIABLE_TKN)
15231 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15232
15233 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15234 }
15235
15236 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15237 show_bgp_instance_all_ipv6_updgrps_cmd,
15238 "show [ip] bgp <view|vrf> all update-groups",
15239 SHOW_STR
15240 IP_STR
15241 BGP_STR
15242 BGP_INSTANCE_ALL_HELP_STR
15243 "Detailed info about dynamic update groups\n")
15244 {
15245 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15246 return CMD_SUCCESS;
15247 }
15248
15249 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15250 show_bgp_l2vpn_evpn_updgrps_cmd,
15251 "show [ip] bgp l2vpn evpn update-groups",
15252 SHOW_STR
15253 IP_STR
15254 BGP_STR
15255 "l2vpn address family\n"
15256 "evpn sub-address family\n"
15257 "Detailed info about dynamic update groups\n")
15258 {
15259 char *vrf = NULL;
15260 uint64_t subgrp_id = 0;
15261
15262 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15263 return CMD_SUCCESS;
15264 }
15265
15266 DEFUN (show_bgp_updgrps_stats,
15267 show_bgp_updgrps_stats_cmd,
15268 "show [ip] bgp update-groups statistics",
15269 SHOW_STR
15270 IP_STR
15271 BGP_STR
15272 "Detailed info about dynamic update groups\n"
15273 "Statistics\n")
15274 {
15275 struct bgp *bgp;
15276
15277 bgp = bgp_get_default();
15278 if (bgp)
15279 update_group_show_stats(bgp, vty);
15280
15281 return CMD_SUCCESS;
15282 }
15283
15284 DEFUN (show_bgp_instance_updgrps_stats,
15285 show_bgp_instance_updgrps_stats_cmd,
15286 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15287 SHOW_STR
15288 IP_STR
15289 BGP_STR
15290 BGP_INSTANCE_HELP_STR
15291 "Detailed info about dynamic update groups\n"
15292 "Statistics\n")
15293 {
15294 int idx_word = 3;
15295 struct bgp *bgp;
15296
15297 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15298 if (bgp)
15299 update_group_show_stats(bgp, vty);
15300
15301 return CMD_SUCCESS;
15302 }
15303
15304 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15305 afi_t afi, safi_t safi,
15306 const char *what, uint64_t subgrp_id)
15307 {
15308 struct bgp *bgp;
15309
15310 if (name)
15311 bgp = bgp_lookup_by_name(name);
15312 else
15313 bgp = bgp_get_default();
15314
15315 if (bgp) {
15316 if (!strcmp(what, "advertise-queue"))
15317 update_group_show_adj_queue(bgp, afi, safi, vty,
15318 subgrp_id);
15319 else if (!strcmp(what, "advertised-routes"))
15320 update_group_show_advertised(bgp, afi, safi, vty,
15321 subgrp_id);
15322 else if (!strcmp(what, "packet-queue"))
15323 update_group_show_packet_queue(bgp, afi, safi, vty,
15324 subgrp_id);
15325 }
15326 }
15327
15328 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15329 show_ip_bgp_instance_updgrps_adj_s_cmd,
15330 "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",
15331 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15332 BGP_SAFI_HELP_STR
15333 "Detailed info about dynamic update groups\n"
15334 "Specific subgroup to display info for\n"
15335 "Advertisement queue\n"
15336 "Announced routes\n"
15337 "Packet queue\n")
15338 {
15339 uint64_t subgrp_id = 0;
15340 afi_t afiz;
15341 safi_t safiz;
15342 if (sgid)
15343 subgrp_id = strtoull(sgid, NULL, 10);
15344
15345 if (!ip && !afi)
15346 afiz = AFI_IP6;
15347 if (!ip && afi)
15348 afiz = bgp_vty_afi_from_str(afi);
15349 if (ip && !afi)
15350 afiz = AFI_IP;
15351 if (ip && afi) {
15352 afiz = bgp_vty_afi_from_str(afi);
15353 if (afiz != AFI_IP)
15354 vty_out(vty,
15355 "%% Cannot specify both 'ip' and 'ipv6'\n");
15356 return CMD_WARNING;
15357 }
15358
15359 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15360
15361 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15362 return CMD_SUCCESS;
15363 }
15364
15365 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15366 json_object *json)
15367 {
15368 struct listnode *node, *nnode;
15369 struct prefix *range;
15370 struct peer *conf;
15371 struct peer *peer;
15372 afi_t afi;
15373 safi_t safi;
15374 const char *peer_status;
15375 int lr_count;
15376 int dynamic;
15377 bool af_cfgd;
15378 json_object *json_peer_group = NULL;
15379 json_object *json_peer_group_afc = NULL;
15380 json_object *json_peer_group_members = NULL;
15381 json_object *json_peer_group_dynamic = NULL;
15382 json_object *json_peer_group_dynamic_af = NULL;
15383 json_object *json_peer_group_ranges = NULL;
15384
15385 conf = group->conf;
15386
15387 if (json) {
15388 json_peer_group = json_object_new_object();
15389 json_peer_group_afc = json_object_new_array();
15390 }
15391
15392 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15393 if (json)
15394 json_object_int_add(json_peer_group, "remoteAs",
15395 conf->as);
15396 else
15397 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15398 group->name, conf->as);
15399 } else if (conf->as_type == AS_INTERNAL) {
15400 if (json)
15401 json_object_int_add(json_peer_group, "remoteAs",
15402 group->bgp->as);
15403 else
15404 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15405 group->name, group->bgp->as);
15406 } else {
15407 if (!json)
15408 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15409 }
15410
15411 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15412 if (json)
15413 json_object_string_add(json_peer_group, "type",
15414 "internal");
15415 else
15416 vty_out(vty, " Peer-group type is internal\n");
15417 } else {
15418 if (json)
15419 json_object_string_add(json_peer_group, "type",
15420 "external");
15421 else
15422 vty_out(vty, " Peer-group type is external\n");
15423 }
15424
15425 /* Display AFs configured. */
15426 if (!json)
15427 vty_out(vty, " Configured address-families:");
15428
15429 FOREACH_AFI_SAFI (afi, safi) {
15430 if (conf->afc[afi][safi]) {
15431 af_cfgd = true;
15432 if (json)
15433 json_object_array_add(
15434 json_peer_group_afc,
15435 json_object_new_string(get_afi_safi_str(
15436 afi, safi, false)));
15437 else
15438 vty_out(vty, " %s;",
15439 get_afi_safi_str(afi, safi, false));
15440 }
15441 }
15442
15443 if (json) {
15444 json_object_object_add(json_peer_group,
15445 "addressFamiliesConfigured",
15446 json_peer_group_afc);
15447 } else {
15448 if (!af_cfgd)
15449 vty_out(vty, " none\n");
15450 else
15451 vty_out(vty, "\n");
15452 }
15453
15454 /* Display listen ranges (for dynamic neighbors), if any */
15455 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15456 lr_count = listcount(group->listen_range[afi]);
15457 if (lr_count) {
15458 if (json) {
15459 if (!json_peer_group_dynamic)
15460 json_peer_group_dynamic =
15461 json_object_new_object();
15462
15463 json_peer_group_dynamic_af =
15464 json_object_new_object();
15465 json_peer_group_ranges =
15466 json_object_new_array();
15467 json_object_int_add(json_peer_group_dynamic_af,
15468 "count", lr_count);
15469 } else {
15470 vty_out(vty, " %d %s listen range(s)\n",
15471 lr_count, afi2str(afi));
15472 }
15473
15474 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15475 nnode, range)) {
15476 if (json) {
15477 char buf[BUFSIZ];
15478
15479 snprintfrr(buf, sizeof(buf), "%pFX",
15480 range);
15481
15482 json_object_array_add(
15483 json_peer_group_ranges,
15484 json_object_new_string(buf));
15485 } else {
15486 vty_out(vty, " %pFX\n", range);
15487 }
15488 }
15489
15490 if (json) {
15491 json_object_object_add(
15492 json_peer_group_dynamic_af, "ranges",
15493 json_peer_group_ranges);
15494
15495 json_object_object_add(
15496 json_peer_group_dynamic, afi2str(afi),
15497 json_peer_group_dynamic_af);
15498 }
15499 }
15500 }
15501
15502 if (json_peer_group_dynamic)
15503 json_object_object_add(json_peer_group, "dynamicRanges",
15504 json_peer_group_dynamic);
15505
15506 /* Display group members and their status */
15507 if (listcount(group->peer)) {
15508 if (json)
15509 json_peer_group_members = json_object_new_object();
15510 else
15511 vty_out(vty, " Peer-group members:\n");
15512 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15513 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15514 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15515 peer_status = "Idle (Admin)";
15516 else if (CHECK_FLAG(peer->sflags,
15517 PEER_STATUS_PREFIX_OVERFLOW))
15518 peer_status = "Idle (PfxCt)";
15519 else
15520 peer_status = lookup_msg(bgp_status_msg,
15521 peer->status, NULL);
15522
15523 dynamic = peer_dynamic_neighbor(peer);
15524
15525 if (json) {
15526 json_object *json_peer_group_member =
15527 json_object_new_object();
15528
15529 json_object_string_add(json_peer_group_member,
15530 "status", peer_status);
15531
15532 if (dynamic)
15533 json_object_boolean_true_add(
15534 json_peer_group_member,
15535 "dynamic");
15536
15537 json_object_object_add(json_peer_group_members,
15538 peer->host,
15539 json_peer_group_member);
15540 } else {
15541 vty_out(vty, " %s %s %s \n", peer->host,
15542 dynamic ? "(dynamic)" : "",
15543 peer_status);
15544 }
15545 }
15546 if (json)
15547 json_object_object_add(json_peer_group, "members",
15548 json_peer_group_members);
15549 }
15550
15551 if (json)
15552 json_object_object_add(json, group->name, json_peer_group);
15553
15554 return CMD_SUCCESS;
15555 }
15556
15557 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15558 const char *group_name, bool uj)
15559 {
15560 struct bgp *bgp;
15561 struct listnode *node, *nnode;
15562 struct peer_group *group;
15563 bool found = false;
15564 json_object *json = NULL;
15565
15566 if (uj)
15567 json = json_object_new_object();
15568
15569 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15570
15571 if (!bgp) {
15572 if (uj)
15573 vty_json(vty, json);
15574 else
15575 vty_out(vty, "%% BGP instance not found\n");
15576
15577 return CMD_WARNING;
15578 }
15579
15580 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15581 if (group_name) {
15582 if (strmatch(group->name, group_name)) {
15583 bgp_show_one_peer_group(vty, group, json);
15584 found = true;
15585 break;
15586 }
15587 } else {
15588 bgp_show_one_peer_group(vty, group, json);
15589 }
15590 }
15591
15592 if (group_name && !found && !uj)
15593 vty_out(vty, "%% No such peer-group\n");
15594
15595 if (uj)
15596 vty_json(vty, json);
15597
15598 return CMD_SUCCESS;
15599 }
15600
15601 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15602 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15603 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15604 "Detailed information on BGP peer groups\n"
15605 "Peer group name\n" JSON_STR)
15606 {
15607 char *vrf, *pg;
15608 int idx = 0;
15609 bool uj = use_json(argc, argv);
15610
15611 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15612 : NULL;
15613 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15614
15615 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15616 }
15617
15618
15619 /* Redistribute VTY commands. */
15620
15621 DEFUN (bgp_redistribute_ipv4,
15622 bgp_redistribute_ipv4_cmd,
15623 "redistribute " FRR_IP_REDIST_STR_BGPD,
15624 "Redistribute information from another routing protocol\n"
15625 FRR_IP_REDIST_HELP_STR_BGPD)
15626 {
15627 VTY_DECLVAR_CONTEXT(bgp, bgp);
15628 int idx_protocol = 1;
15629 int type;
15630
15631 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15632 if (type < 0) {
15633 vty_out(vty, "%% Invalid route type\n");
15634 return CMD_WARNING_CONFIG_FAILED;
15635 }
15636
15637 bgp_redist_add(bgp, AFI_IP, type, 0);
15638 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15639 }
15640
15641 ALIAS_HIDDEN(
15642 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15643 "redistribute " FRR_IP_REDIST_STR_BGPD,
15644 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15645
15646 DEFUN (bgp_redistribute_ipv4_rmap,
15647 bgp_redistribute_ipv4_rmap_cmd,
15648 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15649 "Redistribute information from another routing protocol\n"
15650 FRR_IP_REDIST_HELP_STR_BGPD
15651 "Route map reference\n"
15652 "Pointer to route-map entries\n")
15653 {
15654 VTY_DECLVAR_CONTEXT(bgp, bgp);
15655 int idx_protocol = 1;
15656 int idx_word = 3;
15657 int type;
15658 struct bgp_redist *red;
15659 bool changed;
15660 struct route_map *route_map = route_map_lookup_warn_noexist(
15661 vty, argv[idx_word]->arg);
15662
15663 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15664 if (type < 0) {
15665 vty_out(vty, "%% Invalid route type\n");
15666 return CMD_WARNING_CONFIG_FAILED;
15667 }
15668
15669 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15670 changed =
15671 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15672 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15673 }
15674
15675 ALIAS_HIDDEN(
15676 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15677 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15678 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15679 "Route map reference\n"
15680 "Pointer to route-map entries\n")
15681
15682 DEFUN (bgp_redistribute_ipv4_metric,
15683 bgp_redistribute_ipv4_metric_cmd,
15684 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15685 "Redistribute information from another routing protocol\n"
15686 FRR_IP_REDIST_HELP_STR_BGPD
15687 "Metric for redistributed routes\n"
15688 "Default metric\n")
15689 {
15690 VTY_DECLVAR_CONTEXT(bgp, bgp);
15691 int idx_protocol = 1;
15692 int idx_number = 3;
15693 int type;
15694 uint32_t metric;
15695 struct bgp_redist *red;
15696 bool changed;
15697
15698 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15699 if (type < 0) {
15700 vty_out(vty, "%% Invalid route type\n");
15701 return CMD_WARNING_CONFIG_FAILED;
15702 }
15703 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15704
15705 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15706 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15707 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15708 }
15709
15710 ALIAS_HIDDEN(
15711 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15712 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15713 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15714 "Metric for redistributed routes\n"
15715 "Default metric\n")
15716
15717 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15718 bgp_redistribute_ipv4_rmap_metric_cmd,
15719 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15720 "Redistribute information from another routing protocol\n"
15721 FRR_IP_REDIST_HELP_STR_BGPD
15722 "Route map reference\n"
15723 "Pointer to route-map entries\n"
15724 "Metric for redistributed routes\n"
15725 "Default metric\n")
15726 {
15727 VTY_DECLVAR_CONTEXT(bgp, bgp);
15728 int idx_protocol = 1;
15729 int idx_word = 3;
15730 int idx_number = 5;
15731 int type;
15732 uint32_t metric;
15733 struct bgp_redist *red;
15734 bool changed;
15735 struct route_map *route_map =
15736 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15737
15738 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15739 if (type < 0) {
15740 vty_out(vty, "%% Invalid route type\n");
15741 return CMD_WARNING_CONFIG_FAILED;
15742 }
15743 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15744
15745 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15746 changed =
15747 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15748 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15749 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15750 }
15751
15752 ALIAS_HIDDEN(
15753 bgp_redistribute_ipv4_rmap_metric,
15754 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15755 "redistribute " FRR_IP_REDIST_STR_BGPD
15756 " route-map RMAP_NAME metric (0-4294967295)",
15757 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15758 "Route map reference\n"
15759 "Pointer to route-map entries\n"
15760 "Metric for redistributed routes\n"
15761 "Default metric\n")
15762
15763 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15764 bgp_redistribute_ipv4_metric_rmap_cmd,
15765 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15766 "Redistribute information from another routing protocol\n"
15767 FRR_IP_REDIST_HELP_STR_BGPD
15768 "Metric for redistributed routes\n"
15769 "Default metric\n"
15770 "Route map reference\n"
15771 "Pointer to route-map entries\n")
15772 {
15773 VTY_DECLVAR_CONTEXT(bgp, bgp);
15774 int idx_protocol = 1;
15775 int idx_number = 3;
15776 int idx_word = 5;
15777 int type;
15778 uint32_t metric;
15779 struct bgp_redist *red;
15780 bool changed;
15781 struct route_map *route_map =
15782 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15783
15784 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15785 if (type < 0) {
15786 vty_out(vty, "%% Invalid route type\n");
15787 return CMD_WARNING_CONFIG_FAILED;
15788 }
15789 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15790
15791 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15792 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15793 changed |=
15794 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15795 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15796 }
15797
15798 ALIAS_HIDDEN(
15799 bgp_redistribute_ipv4_metric_rmap,
15800 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15801 "redistribute " FRR_IP_REDIST_STR_BGPD
15802 " metric (0-4294967295) route-map RMAP_NAME",
15803 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15804 "Metric for redistributed routes\n"
15805 "Default metric\n"
15806 "Route map reference\n"
15807 "Pointer to route-map entries\n")
15808
15809 DEFUN (bgp_redistribute_ipv4_ospf,
15810 bgp_redistribute_ipv4_ospf_cmd,
15811 "redistribute <ospf|table> (1-65535)",
15812 "Redistribute information from another routing protocol\n"
15813 "Open Shortest Path First (OSPFv2)\n"
15814 "Non-main Kernel Routing Table\n"
15815 "Instance ID/Table ID\n")
15816 {
15817 VTY_DECLVAR_CONTEXT(bgp, bgp);
15818 int idx_ospf_table = 1;
15819 int idx_number = 2;
15820 unsigned short instance;
15821 unsigned short protocol;
15822
15823 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15824
15825 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15826 protocol = ZEBRA_ROUTE_OSPF;
15827 else
15828 protocol = ZEBRA_ROUTE_TABLE;
15829
15830 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15831 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15832 }
15833
15834 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15835 "redistribute <ospf|table> (1-65535)",
15836 "Redistribute information from another routing protocol\n"
15837 "Open Shortest Path First (OSPFv2)\n"
15838 "Non-main Kernel Routing Table\n"
15839 "Instance ID/Table ID\n")
15840
15841 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15842 bgp_redistribute_ipv4_ospf_rmap_cmd,
15843 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15844 "Redistribute information from another routing protocol\n"
15845 "Open Shortest Path First (OSPFv2)\n"
15846 "Non-main Kernel Routing Table\n"
15847 "Instance ID/Table ID\n"
15848 "Route map reference\n"
15849 "Pointer to route-map entries\n")
15850 {
15851 VTY_DECLVAR_CONTEXT(bgp, bgp);
15852 int idx_ospf_table = 1;
15853 int idx_number = 2;
15854 int idx_word = 4;
15855 struct bgp_redist *red;
15856 unsigned short instance;
15857 int protocol;
15858 bool changed;
15859 struct route_map *route_map =
15860 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15861
15862 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15863 protocol = ZEBRA_ROUTE_OSPF;
15864 else
15865 protocol = ZEBRA_ROUTE_TABLE;
15866
15867 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15868 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15869 changed =
15870 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15871 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15872 }
15873
15874 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15875 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15876 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15877 "Redistribute information from another routing protocol\n"
15878 "Open Shortest Path First (OSPFv2)\n"
15879 "Non-main Kernel Routing Table\n"
15880 "Instance ID/Table ID\n"
15881 "Route map reference\n"
15882 "Pointer to route-map entries\n")
15883
15884 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15885 bgp_redistribute_ipv4_ospf_metric_cmd,
15886 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15887 "Redistribute information from another routing protocol\n"
15888 "Open Shortest Path First (OSPFv2)\n"
15889 "Non-main Kernel Routing Table\n"
15890 "Instance ID/Table ID\n"
15891 "Metric for redistributed routes\n"
15892 "Default metric\n")
15893 {
15894 VTY_DECLVAR_CONTEXT(bgp, bgp);
15895 int idx_ospf_table = 1;
15896 int idx_number = 2;
15897 int idx_number_2 = 4;
15898 uint32_t metric;
15899 struct bgp_redist *red;
15900 unsigned short instance;
15901 int protocol;
15902 bool changed;
15903
15904 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15905 protocol = ZEBRA_ROUTE_OSPF;
15906 else
15907 protocol = ZEBRA_ROUTE_TABLE;
15908
15909 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15910 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15911
15912 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15913 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15914 metric);
15915 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15916 }
15917
15918 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15919 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15920 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15921 "Redistribute information from another routing protocol\n"
15922 "Open Shortest Path First (OSPFv2)\n"
15923 "Non-main Kernel Routing Table\n"
15924 "Instance ID/Table ID\n"
15925 "Metric for redistributed routes\n"
15926 "Default metric\n")
15927
15928 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15929 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15930 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
15931 "Redistribute information from another routing protocol\n"
15932 "Open Shortest Path First (OSPFv2)\n"
15933 "Non-main Kernel Routing Table\n"
15934 "Instance ID/Table ID\n"
15935 "Route map reference\n"
15936 "Pointer to route-map entries\n"
15937 "Metric for redistributed routes\n"
15938 "Default metric\n")
15939 {
15940 VTY_DECLVAR_CONTEXT(bgp, bgp);
15941 int idx_ospf_table = 1;
15942 int idx_number = 2;
15943 int idx_word = 4;
15944 int idx_number_2 = 6;
15945 uint32_t metric;
15946 struct bgp_redist *red;
15947 unsigned short instance;
15948 int protocol;
15949 bool changed;
15950 struct route_map *route_map =
15951 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15952
15953 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15954 protocol = ZEBRA_ROUTE_OSPF;
15955 else
15956 protocol = ZEBRA_ROUTE_TABLE;
15957
15958 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15959 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15960
15961 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15962 changed =
15963 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15964 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15965 metric);
15966 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15967 }
15968
15969 ALIAS_HIDDEN(
15970 bgp_redistribute_ipv4_ospf_rmap_metric,
15971 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15972 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
15973 "Redistribute information from another routing protocol\n"
15974 "Open Shortest Path First (OSPFv2)\n"
15975 "Non-main Kernel Routing Table\n"
15976 "Instance ID/Table ID\n"
15977 "Route map reference\n"
15978 "Pointer to route-map entries\n"
15979 "Metric for redistributed routes\n"
15980 "Default metric\n")
15981
15982 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15983 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15984 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
15985 "Redistribute information from another routing protocol\n"
15986 "Open Shortest Path First (OSPFv2)\n"
15987 "Non-main Kernel Routing Table\n"
15988 "Instance ID/Table ID\n"
15989 "Metric for redistributed routes\n"
15990 "Default metric\n"
15991 "Route map reference\n"
15992 "Pointer to route-map entries\n")
15993 {
15994 VTY_DECLVAR_CONTEXT(bgp, bgp);
15995 int idx_ospf_table = 1;
15996 int idx_number = 2;
15997 int idx_number_2 = 4;
15998 int idx_word = 6;
15999 uint32_t metric;
16000 struct bgp_redist *red;
16001 unsigned short instance;
16002 int protocol;
16003 bool changed;
16004 struct route_map *route_map =
16005 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16006
16007 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16008 protocol = ZEBRA_ROUTE_OSPF;
16009 else
16010 protocol = ZEBRA_ROUTE_TABLE;
16011
16012 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16013 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16014
16015 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16016 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16017 metric);
16018 changed |=
16019 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16020 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16021 }
16022
16023 ALIAS_HIDDEN(
16024 bgp_redistribute_ipv4_ospf_metric_rmap,
16025 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16026 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16027 "Redistribute information from another routing protocol\n"
16028 "Open Shortest Path First (OSPFv2)\n"
16029 "Non-main Kernel Routing Table\n"
16030 "Instance ID/Table ID\n"
16031 "Metric for redistributed routes\n"
16032 "Default metric\n"
16033 "Route map reference\n"
16034 "Pointer to route-map entries\n")
16035
16036 DEFUN (no_bgp_redistribute_ipv4_ospf,
16037 no_bgp_redistribute_ipv4_ospf_cmd,
16038 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16039 NO_STR
16040 "Redistribute information from another routing protocol\n"
16041 "Open Shortest Path First (OSPFv2)\n"
16042 "Non-main Kernel Routing Table\n"
16043 "Instance ID/Table ID\n"
16044 "Metric for redistributed routes\n"
16045 "Default metric\n"
16046 "Route map reference\n"
16047 "Pointer to route-map entries\n")
16048 {
16049 VTY_DECLVAR_CONTEXT(bgp, bgp);
16050 int idx_ospf_table = 2;
16051 int idx_number = 3;
16052 unsigned short instance;
16053 int protocol;
16054
16055 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16056 protocol = ZEBRA_ROUTE_OSPF;
16057 else
16058 protocol = ZEBRA_ROUTE_TABLE;
16059
16060 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16061 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16062 }
16063
16064 ALIAS_HIDDEN(
16065 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16066 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16067 NO_STR
16068 "Redistribute information from another routing protocol\n"
16069 "Open Shortest Path First (OSPFv2)\n"
16070 "Non-main Kernel Routing Table\n"
16071 "Instance ID/Table ID\n"
16072 "Metric for redistributed routes\n"
16073 "Default metric\n"
16074 "Route map reference\n"
16075 "Pointer to route-map entries\n")
16076
16077 DEFUN (no_bgp_redistribute_ipv4,
16078 no_bgp_redistribute_ipv4_cmd,
16079 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16080 NO_STR
16081 "Redistribute information from another routing protocol\n"
16082 FRR_IP_REDIST_HELP_STR_BGPD
16083 "Metric for redistributed routes\n"
16084 "Default metric\n"
16085 "Route map reference\n"
16086 "Pointer to route-map entries\n")
16087 {
16088 VTY_DECLVAR_CONTEXT(bgp, bgp);
16089 int idx_protocol = 2;
16090 int type;
16091
16092 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16093 if (type < 0) {
16094 vty_out(vty, "%% Invalid route type\n");
16095 return CMD_WARNING_CONFIG_FAILED;
16096 }
16097 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16098 }
16099
16100 ALIAS_HIDDEN(
16101 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16102 "no redistribute " FRR_IP_REDIST_STR_BGPD
16103 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16104 NO_STR
16105 "Redistribute information from another routing protocol\n" 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 DEFUN (bgp_redistribute_ipv6,
16112 bgp_redistribute_ipv6_cmd,
16113 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16114 "Redistribute information from another routing protocol\n"
16115 FRR_IP6_REDIST_HELP_STR_BGPD)
16116 {
16117 VTY_DECLVAR_CONTEXT(bgp, bgp);
16118 int idx_protocol = 1;
16119 int type;
16120
16121 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16122 if (type < 0) {
16123 vty_out(vty, "%% Invalid route type\n");
16124 return CMD_WARNING_CONFIG_FAILED;
16125 }
16126
16127 bgp_redist_add(bgp, AFI_IP6, type, 0);
16128 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16129 }
16130
16131 DEFUN (bgp_redistribute_ipv6_rmap,
16132 bgp_redistribute_ipv6_rmap_cmd,
16133 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16134 "Redistribute information from another routing protocol\n"
16135 FRR_IP6_REDIST_HELP_STR_BGPD
16136 "Route map reference\n"
16137 "Pointer to route-map entries\n")
16138 {
16139 VTY_DECLVAR_CONTEXT(bgp, bgp);
16140 int idx_protocol = 1;
16141 int idx_word = 3;
16142 int type;
16143 struct bgp_redist *red;
16144 bool changed;
16145 struct route_map *route_map =
16146 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16147
16148 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16149 if (type < 0) {
16150 vty_out(vty, "%% Invalid route type\n");
16151 return CMD_WARNING_CONFIG_FAILED;
16152 }
16153
16154 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16155 changed =
16156 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16157 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16158 }
16159
16160 DEFUN (bgp_redistribute_ipv6_metric,
16161 bgp_redistribute_ipv6_metric_cmd,
16162 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16163 "Redistribute information from another routing protocol\n"
16164 FRR_IP6_REDIST_HELP_STR_BGPD
16165 "Metric for redistributed routes\n"
16166 "Default metric\n")
16167 {
16168 VTY_DECLVAR_CONTEXT(bgp, bgp);
16169 int idx_protocol = 1;
16170 int idx_number = 3;
16171 int type;
16172 uint32_t metric;
16173 struct bgp_redist *red;
16174 bool changed;
16175
16176 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16177 if (type < 0) {
16178 vty_out(vty, "%% Invalid route type\n");
16179 return CMD_WARNING_CONFIG_FAILED;
16180 }
16181 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16182
16183 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16184 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16185 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16186 }
16187
16188 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16189 bgp_redistribute_ipv6_rmap_metric_cmd,
16190 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16191 "Redistribute information from another routing protocol\n"
16192 FRR_IP6_REDIST_HELP_STR_BGPD
16193 "Route map reference\n"
16194 "Pointer to route-map entries\n"
16195 "Metric for redistributed routes\n"
16196 "Default metric\n")
16197 {
16198 VTY_DECLVAR_CONTEXT(bgp, bgp);
16199 int idx_protocol = 1;
16200 int idx_word = 3;
16201 int idx_number = 5;
16202 int type;
16203 uint32_t metric;
16204 struct bgp_redist *red;
16205 bool changed;
16206 struct route_map *route_map =
16207 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16208
16209 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16210 if (type < 0) {
16211 vty_out(vty, "%% Invalid route type\n");
16212 return CMD_WARNING_CONFIG_FAILED;
16213 }
16214 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16215
16216 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16217 changed =
16218 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16219 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16220 metric);
16221 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16222 }
16223
16224 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16225 bgp_redistribute_ipv6_metric_rmap_cmd,
16226 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16227 "Redistribute information from another routing protocol\n"
16228 FRR_IP6_REDIST_HELP_STR_BGPD
16229 "Metric for redistributed routes\n"
16230 "Default metric\n"
16231 "Route map reference\n"
16232 "Pointer to route-map entries\n")
16233 {
16234 VTY_DECLVAR_CONTEXT(bgp, bgp);
16235 int idx_protocol = 1;
16236 int idx_number = 3;
16237 int idx_word = 5;
16238 int type;
16239 uint32_t metric;
16240 struct bgp_redist *red;
16241 bool changed;
16242 struct route_map *route_map =
16243 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16244
16245 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16246 if (type < 0) {
16247 vty_out(vty, "%% Invalid route type\n");
16248 return CMD_WARNING_CONFIG_FAILED;
16249 }
16250 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16251
16252 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16253 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16254 metric);
16255 changed |=
16256 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16257 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16258 }
16259
16260 DEFUN (no_bgp_redistribute_ipv6,
16261 no_bgp_redistribute_ipv6_cmd,
16262 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16263 NO_STR
16264 "Redistribute information from another routing protocol\n"
16265 FRR_IP6_REDIST_HELP_STR_BGPD
16266 "Metric for redistributed routes\n"
16267 "Default metric\n"
16268 "Route map reference\n"
16269 "Pointer to route-map entries\n")
16270 {
16271 VTY_DECLVAR_CONTEXT(bgp, bgp);
16272 int idx_protocol = 2;
16273 int type;
16274
16275 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16276 if (type < 0) {
16277 vty_out(vty, "%% Invalid route type\n");
16278 return CMD_WARNING_CONFIG_FAILED;
16279 }
16280
16281 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16282 }
16283
16284 /* Neighbor update tcp-mss. */
16285 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16286 const char *tcp_mss_str)
16287 {
16288 struct peer *peer;
16289 uint32_t tcp_mss_val = 0;
16290
16291 peer = peer_and_group_lookup_vty(vty, peer_str);
16292 if (!peer)
16293 return CMD_WARNING_CONFIG_FAILED;
16294
16295 if (tcp_mss_str) {
16296 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16297 peer_tcp_mss_set(peer, tcp_mss_val);
16298 } else {
16299 peer_tcp_mss_unset(peer);
16300 }
16301
16302 return CMD_SUCCESS;
16303 }
16304
16305 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16306 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16307 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16308 "TCP max segment size\n"
16309 "TCP MSS value\n")
16310 {
16311 int peer_index = 1;
16312 int mss_index = 3;
16313
16314 vty_out(vty,
16315 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16316 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16317 argv[mss_index]->arg);
16318 }
16319
16320 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16321 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16322 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16323 "TCP max segment size\n"
16324 "TCP MSS value\n")
16325 {
16326 int peer_index = 2;
16327
16328 vty_out(vty,
16329 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16330 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16331 }
16332
16333 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16334 afi_t afi, safi_t safi)
16335 {
16336 int i;
16337
16338 /* Unicast redistribution only. */
16339 if (safi != SAFI_UNICAST)
16340 return;
16341
16342 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16343 /* Redistribute BGP does not make sense. */
16344 if (i != ZEBRA_ROUTE_BGP) {
16345 struct list *red_list;
16346 struct listnode *node;
16347 struct bgp_redist *red;
16348
16349 red_list = bgp->redist[afi][i];
16350 if (!red_list)
16351 continue;
16352
16353 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16354 /* "redistribute" configuration. */
16355 vty_out(vty, " redistribute %s",
16356 zebra_route_string(i));
16357 if (red->instance)
16358 vty_out(vty, " %d", red->instance);
16359 if (red->redist_metric_flag)
16360 vty_out(vty, " metric %u",
16361 red->redist_metric);
16362 if (red->rmap.name)
16363 vty_out(vty, " route-map %s",
16364 red->rmap.name);
16365 vty_out(vty, "\n");
16366 }
16367 }
16368 }
16369 }
16370
16371 /* peer-group helpers for config-write */
16372
16373 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16374 {
16375 if (!peer_group_active(peer)) {
16376 if (CHECK_FLAG(peer->flags_invert, flag))
16377 return !CHECK_FLAG(peer->flags, flag);
16378 else
16379 return !!CHECK_FLAG(peer->flags, flag);
16380 }
16381
16382 return !!CHECK_FLAG(peer->flags_override, flag);
16383 }
16384
16385 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16386 uint32_t flag)
16387 {
16388 if (!peer_group_active(peer)) {
16389 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16390 return !peer_af_flag_check(peer, afi, safi, flag);
16391 else
16392 return !!peer_af_flag_check(peer, afi, safi, flag);
16393 }
16394
16395 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16396 }
16397
16398 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16399 uint8_t type, int direct)
16400 {
16401 struct bgp_filter *filter;
16402
16403 if (peer_group_active(peer))
16404 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16405 type);
16406
16407 filter = &peer->filter[afi][safi];
16408 switch (type) {
16409 case PEER_FT_DISTRIBUTE_LIST:
16410 return !!(filter->dlist[direct].name);
16411 case PEER_FT_FILTER_LIST:
16412 return !!(filter->aslist[direct].name);
16413 case PEER_FT_PREFIX_LIST:
16414 return !!(filter->plist[direct].name);
16415 case PEER_FT_ROUTE_MAP:
16416 return !!(filter->map[direct].name);
16417 case PEER_FT_UNSUPPRESS_MAP:
16418 return !!(filter->usmap.name);
16419 case PEER_FT_ADVERTISE_MAP:
16420 return !!(filter->advmap.aname
16421 && ((filter->advmap.condition == direct)
16422 && filter->advmap.cname));
16423 default:
16424 return false;
16425 }
16426 }
16427
16428 /* Return true if the addpath type is set for peer and different from
16429 * peer-group.
16430 */
16431 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16432 safi_t safi)
16433 {
16434 enum bgp_addpath_strat type, g_type;
16435
16436 type = peer->addpath_type[afi][safi];
16437
16438 if (type != BGP_ADDPATH_NONE) {
16439 if (peer_group_active(peer)) {
16440 g_type = peer->group->conf->addpath_type[afi][safi];
16441
16442 if (type != g_type)
16443 return true;
16444 else
16445 return false;
16446 }
16447
16448 return true;
16449 }
16450
16451 return false;
16452 }
16453
16454 /* This is part of the address-family block (unicast only) */
16455 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16456 afi_t afi)
16457 {
16458 int indent = 2;
16459 uint32_t tovpn_sid_index = 0;
16460
16461 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16462 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16463 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16464 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16465 bgp->vpn_policy[afi]
16466 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16467 else
16468 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16469 bgp->vpn_policy[afi]
16470 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16471 }
16472 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16473 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16474 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16475 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16476 return;
16477
16478 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16479 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16480
16481 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16482
16483 } else {
16484 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16485 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16486 bgp->vpn_policy[afi].tovpn_label);
16487 }
16488 }
16489
16490 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16491 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16492 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16493 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16494 } else if (tovpn_sid_index != 0) {
16495 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16496 tovpn_sid_index);
16497 }
16498
16499 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16500 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16501 char buf[RD_ADDRSTRLEN];
16502 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16503 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16504 sizeof(buf)));
16505 }
16506 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16507 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16508
16509 char buf[PREFIX_STRLEN];
16510 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16511 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16512 sizeof(buf))) {
16513
16514 vty_out(vty, "%*snexthop vpn export %s\n",
16515 indent, "", buf);
16516 }
16517 }
16518 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16519 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16520 && ecommunity_cmp(
16521 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16522 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16523
16524 char *b = ecommunity_ecom2str(
16525 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16526 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16527 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16528 XFREE(MTYPE_ECOMMUNITY_STR, b);
16529 } else {
16530 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16531 char *b = ecommunity_ecom2str(
16532 bgp->vpn_policy[afi]
16533 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16534 ECOMMUNITY_FORMAT_ROUTE_MAP,
16535 ECOMMUNITY_ROUTE_TARGET);
16536 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16537 XFREE(MTYPE_ECOMMUNITY_STR, b);
16538 }
16539 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16540 char *b = ecommunity_ecom2str(
16541 bgp->vpn_policy[afi]
16542 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16543 ECOMMUNITY_FORMAT_ROUTE_MAP,
16544 ECOMMUNITY_ROUTE_TARGET);
16545 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16546 XFREE(MTYPE_ECOMMUNITY_STR, b);
16547 }
16548 }
16549
16550 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16551 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16552 bgp->vpn_policy[afi]
16553 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16554
16555 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16556 char *b = ecommunity_ecom2str(
16557 bgp->vpn_policy[afi]
16558 .import_redirect_rtlist,
16559 ECOMMUNITY_FORMAT_ROUTE_MAP,
16560 ECOMMUNITY_ROUTE_TARGET);
16561
16562 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16563 != ECOMMUNITY_SIZE)
16564 vty_out(vty, "%*srt6 redirect import %s\n",
16565 indent, "", b);
16566 else
16567 vty_out(vty, "%*srt redirect import %s\n",
16568 indent, "", b);
16569 XFREE(MTYPE_ECOMMUNITY_STR, b);
16570 }
16571 }
16572
16573 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16574 afi_t afi, safi_t safi)
16575 {
16576 struct bgp_filter *filter;
16577 char *addr;
16578
16579 addr = peer->host;
16580 filter = &peer->filter[afi][safi];
16581
16582 /* distribute-list. */
16583 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16584 FILTER_IN))
16585 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16586 filter->dlist[FILTER_IN].name);
16587
16588 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16589 FILTER_OUT))
16590 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16591 filter->dlist[FILTER_OUT].name);
16592
16593 /* prefix-list. */
16594 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16595 FILTER_IN))
16596 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16597 filter->plist[FILTER_IN].name);
16598
16599 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16600 FILTER_OUT))
16601 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16602 filter->plist[FILTER_OUT].name);
16603
16604 /* route-map. */
16605 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16606 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16607 filter->map[RMAP_IN].name);
16608
16609 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16610 RMAP_OUT))
16611 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16612 filter->map[RMAP_OUT].name);
16613
16614 /* unsuppress-map */
16615 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16616 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16617 filter->usmap.name);
16618
16619 /* advertise-map : always applied in OUT direction*/
16620 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16621 CONDITION_NON_EXIST))
16622 vty_out(vty,
16623 " neighbor %s advertise-map %s non-exist-map %s\n",
16624 addr, filter->advmap.aname, filter->advmap.cname);
16625
16626 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16627 CONDITION_EXIST))
16628 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16629 addr, filter->advmap.aname, filter->advmap.cname);
16630
16631 /* filter-list. */
16632 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16633 FILTER_IN))
16634 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16635 filter->aslist[FILTER_IN].name);
16636
16637 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16638 FILTER_OUT))
16639 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16640 filter->aslist[FILTER_OUT].name);
16641 }
16642
16643 /* BGP peer configuration display function. */
16644 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16645 struct peer *peer)
16646 {
16647 struct peer *g_peer = NULL;
16648 char *addr;
16649 int if_pg_printed = false;
16650 int if_ras_printed = false;
16651
16652 /* Skip dynamic neighbors. */
16653 if (peer_dynamic_neighbor(peer))
16654 return;
16655
16656 if (peer->conf_if)
16657 addr = peer->conf_if;
16658 else
16659 addr = peer->host;
16660
16661 /************************************
16662 ****** Global to the neighbor ******
16663 ************************************/
16664 if (peer->conf_if) {
16665 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16666 vty_out(vty, " neighbor %s interface v6only", addr);
16667 else
16668 vty_out(vty, " neighbor %s interface", addr);
16669
16670 if (peer_group_active(peer)) {
16671 vty_out(vty, " peer-group %s", peer->group->name);
16672 if_pg_printed = true;
16673 } else if (peer->as_type == AS_SPECIFIED) {
16674 vty_out(vty, " remote-as %u", peer->as);
16675 if_ras_printed = true;
16676 } else if (peer->as_type == AS_INTERNAL) {
16677 vty_out(vty, " remote-as internal");
16678 if_ras_printed = true;
16679 } else if (peer->as_type == AS_EXTERNAL) {
16680 vty_out(vty, " remote-as external");
16681 if_ras_printed = true;
16682 }
16683
16684 vty_out(vty, "\n");
16685 }
16686
16687 /* remote-as and peer-group */
16688 /* peer is a member of a peer-group */
16689 if (peer_group_active(peer)) {
16690 g_peer = peer->group->conf;
16691
16692 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16693 if (peer->as_type == AS_SPECIFIED) {
16694 vty_out(vty, " neighbor %s remote-as %u\n",
16695 addr, peer->as);
16696 } else if (peer->as_type == AS_INTERNAL) {
16697 vty_out(vty,
16698 " neighbor %s remote-as internal\n",
16699 addr);
16700 } else if (peer->as_type == AS_EXTERNAL) {
16701 vty_out(vty,
16702 " neighbor %s remote-as external\n",
16703 addr);
16704 }
16705 }
16706
16707 /* For swpX peers we displayed the peer-group
16708 * via 'neighbor swpX interface peer-group PGNAME' */
16709 if (!if_pg_printed)
16710 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16711 peer->group->name);
16712 }
16713
16714 /* peer is NOT a member of a peer-group */
16715 else {
16716 /* peer is a peer-group, declare the peer-group */
16717 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16718 vty_out(vty, " neighbor %s peer-group\n", addr);
16719 }
16720
16721 if (!if_ras_printed) {
16722 if (peer->as_type == AS_SPECIFIED) {
16723 vty_out(vty, " neighbor %s remote-as %u\n",
16724 addr, peer->as);
16725 } else if (peer->as_type == AS_INTERNAL) {
16726 vty_out(vty,
16727 " neighbor %s remote-as internal\n",
16728 addr);
16729 } else if (peer->as_type == AS_EXTERNAL) {
16730 vty_out(vty,
16731 " neighbor %s remote-as external\n",
16732 addr);
16733 }
16734 }
16735 }
16736
16737 /* local-as */
16738 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16739 vty_out(vty, " neighbor %s local-as %u", addr,
16740 peer->change_local_as);
16741 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16742 vty_out(vty, " no-prepend");
16743 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16744 vty_out(vty, " replace-as");
16745 vty_out(vty, "\n");
16746 }
16747
16748 /* description */
16749 if (peer->desc) {
16750 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16751 }
16752
16753 /* shutdown */
16754 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16755 if (peer->tx_shutdown_message)
16756 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16757 peer->tx_shutdown_message);
16758 else
16759 vty_out(vty, " neighbor %s shutdown\n", addr);
16760 }
16761
16762 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16763 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16764 peer->rtt_expected, peer->rtt_keepalive_conf);
16765
16766 /* bfd */
16767 if (peer->bfd_config)
16768 bgp_bfd_peer_config_write(vty, peer, addr);
16769
16770 /* password */
16771 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16772 vty_out(vty, " neighbor %s password %s\n", addr,
16773 peer->password);
16774
16775 /* neighbor solo */
16776 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16777 if (!peer_group_active(peer)) {
16778 vty_out(vty, " neighbor %s solo\n", addr);
16779 }
16780 }
16781
16782 /* BGP port */
16783 if (peer->port != BGP_PORT_DEFAULT) {
16784 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16785 }
16786
16787 /* Local interface name */
16788 if (peer->ifname) {
16789 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16790 }
16791
16792 /* TCP max segment size */
16793 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16794 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16795
16796 /* passive */
16797 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16798 vty_out(vty, " neighbor %s passive\n", addr);
16799
16800 /* ebgp-multihop */
16801 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16802 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16803 && peer->ttl == MAXTTL)) {
16804 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16805 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16806 peer->ttl);
16807 }
16808 }
16809
16810 /* role */
16811 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16812 peer->local_role != ROLE_UNDEFINED)
16813 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16814 bgp_get_name_by_role(peer->local_role),
16815 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
16816 ? " strict-mode"
16817 : "");
16818
16819 /* ttl-security hops */
16820 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16821 if (!peer_group_active(peer)
16822 || g_peer->gtsm_hops != peer->gtsm_hops) {
16823 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16824 addr, peer->gtsm_hops);
16825 }
16826 }
16827
16828 /* disable-connected-check */
16829 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16830 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16831
16832 /* link-bw-encoding-ieee */
16833 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16834 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16835 addr);
16836
16837 /* extended-optional-parameters */
16838 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16839 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16840 addr);
16841
16842 /* enforce-first-as */
16843 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16844 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16845
16846 /* update-source */
16847 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16848 if (peer->update_source)
16849 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16850 peer->update_source);
16851 else if (peer->update_if)
16852 vty_out(vty, " neighbor %s update-source %s\n", addr,
16853 peer->update_if);
16854 }
16855
16856 /* advertisement-interval */
16857 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16858 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16859 peer->routeadv);
16860
16861 /* timers */
16862 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16863 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16864 peer->keepalive, peer->holdtime);
16865
16866 /* timers connect */
16867 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16868 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16869 peer->connect);
16870 /* need special-case handling for changed default values due to
16871 * config profile / version (because there is no "timers bgp connect"
16872 * command, we need to save this per-peer :/)
16873 */
16874 else if (!peer_group_active(peer) && !peer->connect &&
16875 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16876 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16877 peer->bgp->default_connect_retry);
16878
16879 /* timers delayopen */
16880 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16881 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16882 peer->delayopen);
16883 /* Save config even though flag is not set if default values have been
16884 * changed
16885 */
16886 else if (!peer_group_active(peer) && !peer->delayopen
16887 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16888 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16889 peer->bgp->default_delayopen);
16890
16891 /* capability dynamic */
16892 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16893 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16894
16895 /* capability extended-nexthop */
16896 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16897 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
16898 !peer->conf_if)
16899 vty_out(vty,
16900 " no neighbor %s capability extended-nexthop\n",
16901 addr);
16902 else if (!peer->conf_if)
16903 vty_out(vty,
16904 " neighbor %s capability extended-nexthop\n",
16905 addr);
16906 }
16907
16908 /* dont-capability-negotiation */
16909 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16910 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16911
16912 /* override-capability */
16913 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16914 vty_out(vty, " neighbor %s override-capability\n", addr);
16915
16916 /* strict-capability-match */
16917 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16918 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16919
16920 /* Sender side AS path loop detection. */
16921 if (peer->as_path_loop_detection)
16922 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16923 addr);
16924
16925 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16926 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16927
16928 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16929 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16930 vty_out(vty,
16931 " neighbor %s graceful-restart-helper\n", addr);
16932 } else if (CHECK_FLAG(
16933 peer->peer_gr_new_status_flag,
16934 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16935 vty_out(vty,
16936 " neighbor %s graceful-restart\n", addr);
16937 } else if (
16938 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16939 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16940 && !(CHECK_FLAG(
16941 peer->peer_gr_new_status_flag,
16942 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16943 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16944 addr);
16945 }
16946 }
16947 }
16948
16949 /* BGP peer configuration display function. */
16950 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16951 struct peer *peer, afi_t afi, safi_t safi)
16952 {
16953 struct peer *g_peer = NULL;
16954 char *addr;
16955 bool flag_scomm, flag_secomm, flag_slcomm;
16956
16957 /* Skip dynamic neighbors. */
16958 if (peer_dynamic_neighbor(peer))
16959 return;
16960
16961 if (peer->conf_if)
16962 addr = peer->conf_if;
16963 else
16964 addr = peer->host;
16965
16966 /************************************
16967 ****** Per AF to the neighbor ******
16968 ************************************/
16969 if (peer_group_active(peer)) {
16970 g_peer = peer->group->conf;
16971
16972 /* If the peer-group is active but peer is not, print a 'no
16973 * activate' */
16974 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16975 vty_out(vty, " no neighbor %s activate\n", addr);
16976 }
16977
16978 /* If the peer-group is not active but peer is, print an
16979 'activate' */
16980 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16981 vty_out(vty, " neighbor %s activate\n", addr);
16982 }
16983 } else {
16984 if (peer->afc[afi][safi]) {
16985 if (safi == SAFI_ENCAP)
16986 vty_out(vty, " neighbor %s activate\n", addr);
16987 else if (!bgp->default_af[afi][safi])
16988 vty_out(vty, " neighbor %s activate\n", addr);
16989 } else {
16990 if (bgp->default_af[afi][safi])
16991 vty_out(vty, " no neighbor %s activate\n",
16992 addr);
16993 }
16994 }
16995
16996 /* addpath TX knobs */
16997 if (peergroup_af_addpath_check(peer, afi, safi)) {
16998 switch (peer->addpath_type[afi][safi]) {
16999 case BGP_ADDPATH_ALL:
17000 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17001 addr);
17002 break;
17003 case BGP_ADDPATH_BEST_PER_AS:
17004 vty_out(vty,
17005 " neighbor %s addpath-tx-bestpath-per-AS\n",
17006 addr);
17007 break;
17008 case BGP_ADDPATH_MAX:
17009 case BGP_ADDPATH_NONE:
17010 break;
17011 }
17012 }
17013
17014 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17015 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17016
17017 /* ORF capability. */
17018 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17019 || peergroup_af_flag_check(peer, afi, safi,
17020 PEER_FLAG_ORF_PREFIX_RM)) {
17021 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17022
17023 if (peergroup_af_flag_check(peer, afi, safi,
17024 PEER_FLAG_ORF_PREFIX_SM)
17025 && peergroup_af_flag_check(peer, afi, safi,
17026 PEER_FLAG_ORF_PREFIX_RM))
17027 vty_out(vty, " both");
17028 else if (peergroup_af_flag_check(peer, afi, safi,
17029 PEER_FLAG_ORF_PREFIX_SM))
17030 vty_out(vty, " send");
17031 else
17032 vty_out(vty, " receive");
17033 vty_out(vty, "\n");
17034 }
17035
17036 /* Route reflector client. */
17037 if (peergroup_af_flag_check(peer, afi, safi,
17038 PEER_FLAG_REFLECTOR_CLIENT)) {
17039 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17040 }
17041
17042 /* next-hop-self force */
17043 if (peergroup_af_flag_check(peer, afi, safi,
17044 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17045 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17046 }
17047
17048 /* next-hop-self */
17049 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17050 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17051 }
17052
17053 /* remove-private-AS */
17054 if (peergroup_af_flag_check(peer, afi, safi,
17055 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17056 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17057 addr);
17058 }
17059
17060 else if (peergroup_af_flag_check(peer, afi, safi,
17061 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17062 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17063 addr);
17064 }
17065
17066 else if (peergroup_af_flag_check(peer, afi, safi,
17067 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17068 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17069 }
17070
17071 else if (peergroup_af_flag_check(peer, afi, safi,
17072 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17073 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17074 }
17075
17076 /* as-override */
17077 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17078 vty_out(vty, " neighbor %s as-override\n", addr);
17079 }
17080
17081 /* send-community print. */
17082 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17083 PEER_FLAG_SEND_COMMUNITY);
17084 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17085 PEER_FLAG_SEND_EXT_COMMUNITY);
17086 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17087 PEER_FLAG_SEND_LARGE_COMMUNITY);
17088
17089 if (flag_scomm && flag_secomm && flag_slcomm) {
17090 vty_out(vty, " no neighbor %s send-community all\n", addr);
17091 } else {
17092 if (flag_scomm)
17093 vty_out(vty, " no neighbor %s send-community\n", addr);
17094 if (flag_secomm)
17095 vty_out(vty,
17096 " no neighbor %s send-community extended\n",
17097 addr);
17098
17099 if (flag_slcomm)
17100 vty_out(vty, " no neighbor %s send-community large\n",
17101 addr);
17102 }
17103
17104 /* Default information */
17105 if (peergroup_af_flag_check(peer, afi, safi,
17106 PEER_FLAG_DEFAULT_ORIGINATE)) {
17107 vty_out(vty, " neighbor %s default-originate", addr);
17108
17109 if (peer->default_rmap[afi][safi].name)
17110 vty_out(vty, " route-map %s",
17111 peer->default_rmap[afi][safi].name);
17112
17113 vty_out(vty, "\n");
17114 }
17115
17116 /* Soft reconfiguration inbound. */
17117 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17118 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17119 addr);
17120 }
17121
17122 /* maximum-prefix. */
17123 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17124 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17125 peer->pmax[afi][safi]);
17126
17127 if (peer->pmax_threshold[afi][safi]
17128 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17129 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17130 if (peer_af_flag_check(peer, afi, safi,
17131 PEER_FLAG_MAX_PREFIX_WARNING))
17132 vty_out(vty, " warning-only");
17133 if (peer->pmax_restart[afi][safi])
17134 vty_out(vty, " restart %u",
17135 peer->pmax_restart[afi][safi]);
17136 if (peer_af_flag_check(peer, afi, safi,
17137 PEER_FLAG_MAX_PREFIX_FORCE))
17138 vty_out(vty, " force");
17139
17140 vty_out(vty, "\n");
17141 }
17142
17143 /* maximum-prefix-out */
17144 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17145 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17146 addr, peer->pmax_out[afi][safi]);
17147
17148 /* Route server client. */
17149 if (peergroup_af_flag_check(peer, afi, safi,
17150 PEER_FLAG_RSERVER_CLIENT)) {
17151 vty_out(vty, " neighbor %s route-server-client\n", addr);
17152 }
17153
17154 /* Nexthop-local unchanged. */
17155 if (peergroup_af_flag_check(peer, afi, safi,
17156 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17157 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17158 }
17159
17160 /* allowas-in <1-10> */
17161 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17162 if (peer_af_flag_check(peer, afi, safi,
17163 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17164 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17165 } else if (peer->allowas_in[afi][safi] == 3) {
17166 vty_out(vty, " neighbor %s allowas-in\n", addr);
17167 } else {
17168 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17169 peer->allowas_in[afi][safi]);
17170 }
17171 }
17172
17173 /* weight */
17174 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17175 vty_out(vty, " neighbor %s weight %lu\n", addr,
17176 peer->weight[afi][safi]);
17177
17178 /* Filter. */
17179 bgp_config_write_filter(vty, peer, afi, safi);
17180
17181 /* atribute-unchanged. */
17182 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17183 || (safi != SAFI_EVPN
17184 && peer_af_flag_check(peer, afi, safi,
17185 PEER_FLAG_NEXTHOP_UNCHANGED))
17186 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17187
17188 if (!peer_group_active(peer)
17189 || peergroup_af_flag_check(peer, afi, safi,
17190 PEER_FLAG_AS_PATH_UNCHANGED)
17191 || peergroup_af_flag_check(peer, afi, safi,
17192 PEER_FLAG_NEXTHOP_UNCHANGED)
17193 || peergroup_af_flag_check(peer, afi, safi,
17194 PEER_FLAG_MED_UNCHANGED)) {
17195
17196 vty_out(vty,
17197 " neighbor %s attribute-unchanged%s%s%s\n",
17198 addr,
17199 peer_af_flag_check(peer, afi, safi,
17200 PEER_FLAG_AS_PATH_UNCHANGED)
17201 ? " as-path"
17202 : "",
17203 peer_af_flag_check(peer, afi, safi,
17204 PEER_FLAG_NEXTHOP_UNCHANGED)
17205 ? " next-hop"
17206 : "",
17207 peer_af_flag_check(peer, afi, safi,
17208 PEER_FLAG_MED_UNCHANGED)
17209 ? " med"
17210 : "");
17211 }
17212 }
17213 }
17214
17215 /* Address family based peer configuration display. */
17216 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17217 safi_t safi)
17218 {
17219 struct peer *peer;
17220 struct peer_group *group;
17221 struct listnode *node, *nnode;
17222
17223
17224 vty_frame(vty, " !\n address-family ");
17225 if (afi == AFI_IP) {
17226 if (safi == SAFI_UNICAST)
17227 vty_frame(vty, "ipv4 unicast");
17228 else if (safi == SAFI_LABELED_UNICAST)
17229 vty_frame(vty, "ipv4 labeled-unicast");
17230 else if (safi == SAFI_MULTICAST)
17231 vty_frame(vty, "ipv4 multicast");
17232 else if (safi == SAFI_MPLS_VPN)
17233 vty_frame(vty, "ipv4 vpn");
17234 else if (safi == SAFI_ENCAP)
17235 vty_frame(vty, "ipv4 encap");
17236 else if (safi == SAFI_FLOWSPEC)
17237 vty_frame(vty, "ipv4 flowspec");
17238 } else if (afi == AFI_IP6) {
17239 if (safi == SAFI_UNICAST)
17240 vty_frame(vty, "ipv6 unicast");
17241 else if (safi == SAFI_LABELED_UNICAST)
17242 vty_frame(vty, "ipv6 labeled-unicast");
17243 else if (safi == SAFI_MULTICAST)
17244 vty_frame(vty, "ipv6 multicast");
17245 else if (safi == SAFI_MPLS_VPN)
17246 vty_frame(vty, "ipv6 vpn");
17247 else if (safi == SAFI_ENCAP)
17248 vty_frame(vty, "ipv6 encap");
17249 else if (safi == SAFI_FLOWSPEC)
17250 vty_frame(vty, "ipv6 flowspec");
17251 } else if (afi == AFI_L2VPN) {
17252 if (safi == SAFI_EVPN)
17253 vty_frame(vty, "l2vpn evpn");
17254 }
17255 vty_frame(vty, "\n");
17256
17257 bgp_config_write_distance(vty, bgp, afi, safi);
17258
17259 bgp_config_write_network(vty, bgp, afi, safi);
17260
17261 bgp_config_write_redistribute(vty, bgp, afi, safi);
17262
17263 /* BGP flag dampening. */
17264 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17265 bgp_config_write_damp(vty, afi, safi);
17266
17267 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17268 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17269
17270 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17271 /* Do not display doppelganger peers */
17272 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17273 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17274 }
17275
17276 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17277 bgp_config_write_table_map(vty, bgp, afi, safi);
17278
17279 if (safi == SAFI_EVPN)
17280 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17281
17282 if (safi == SAFI_FLOWSPEC)
17283 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17284
17285 if (safi == SAFI_UNICAST) {
17286 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17287 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17288 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17289
17290 vty_out(vty, " export vpn\n");
17291 }
17292 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17293 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17294
17295 vty_out(vty, " import vpn\n");
17296 }
17297 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17298 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17299 char *name;
17300
17301 for (ALL_LIST_ELEMENTS_RO(
17302 bgp->vpn_policy[afi].import_vrf, node,
17303 name))
17304 vty_out(vty, " import vrf %s\n", name);
17305 }
17306 }
17307
17308 vty_endframe(vty, " exit-address-family\n");
17309 }
17310
17311 int bgp_config_write(struct vty *vty)
17312 {
17313 struct bgp *bgp;
17314 struct peer_group *group;
17315 struct peer *peer;
17316 struct listnode *node, *nnode;
17317 struct listnode *mnode, *mnnode;
17318 afi_t afi;
17319 safi_t safi;
17320
17321 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17322 vty_out(vty, "bgp route-map delay-timer %u\n",
17323 bm->rmap_update_timer);
17324
17325 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17326 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17327 if (bm->v_update_delay != bm->v_establish_wait)
17328 vty_out(vty, " %d", bm->v_establish_wait);
17329 vty_out(vty, "\n");
17330 }
17331
17332 if (bm->wait_for_fib)
17333 vty_out(vty, "bgp suppress-fib-pending\n");
17334
17335 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17336 vty_out(vty, "bgp graceful-shutdown\n");
17337
17338 /* No-RIB (Zebra) option flag configuration */
17339 if (bgp_option_check(BGP_OPT_NO_FIB))
17340 vty_out(vty, "bgp no-rib\n");
17341
17342 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17343 vty_out(vty, "bgp send-extra-data zebra\n");
17344
17345 /* BGP session DSCP value */
17346 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17347 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17348
17349 /* BGP configuration. */
17350 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17351
17352 /* skip all auto created vrf as they dont have user config */
17353 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17354 continue;
17355
17356 /* Router bgp ASN */
17357 vty_out(vty, "router bgp %u", bgp->as);
17358
17359 if (bgp->name)
17360 vty_out(vty, " %s %s",
17361 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17362 ? "view" : "vrf", bgp->name);
17363 vty_out(vty, "\n");
17364
17365 /* BGP fast-external-failover. */
17366 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17367 vty_out(vty, " no bgp fast-external-failover\n");
17368
17369 /* BGP router ID. */
17370 if (bgp->router_id_static.s_addr != INADDR_ANY)
17371 vty_out(vty, " bgp router-id %pI4\n",
17372 &bgp->router_id_static);
17373
17374 /* Suppress fib pending */
17375 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17376 vty_out(vty, " bgp suppress-fib-pending\n");
17377
17378 /* BGP log-neighbor-changes. */
17379 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17380 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17381 vty_out(vty, " %sbgp log-neighbor-changes\n",
17382 CHECK_FLAG(bgp->flags,
17383 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17384 ? ""
17385 : "no ");
17386
17387 /* BGP configuration. */
17388 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17389 vty_out(vty, " bgp always-compare-med\n");
17390
17391 /* RFC8212 default eBGP policy. */
17392 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17393 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17394 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17395 CHECK_FLAG(bgp->flags,
17396 BGP_FLAG_EBGP_REQUIRES_POLICY)
17397 ? ""
17398 : "no ");
17399
17400 /* draft-ietf-idr-deprecate-as-set-confed-set */
17401 if (bgp->reject_as_sets)
17402 vty_out(vty, " bgp reject-as-sets\n");
17403
17404 /* Suppress duplicate updates if the route actually not changed
17405 */
17406 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17407 != SAVE_BGP_SUPPRESS_DUPLICATES)
17408 vty_out(vty, " %sbgp suppress-duplicates\n",
17409 CHECK_FLAG(bgp->flags,
17410 BGP_FLAG_SUPPRESS_DUPLICATES)
17411 ? ""
17412 : "no ");
17413
17414 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17415 */
17416 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17417 SAVE_BGP_HARD_ADMIN_RESET)
17418 vty_out(vty, " %sbgp hard-administrative-reset\n",
17419 CHECK_FLAG(bgp->flags,
17420 BGP_FLAG_HARD_ADMIN_RESET)
17421 ? ""
17422 : "no ");
17423
17424 /* BGP default <afi>-<safi> */
17425 FOREACH_AFI_SAFI (afi, safi) {
17426 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17427 if (!bgp->default_af[afi][safi])
17428 vty_out(vty, " no bgp default %s\n",
17429 get_bgp_default_af_flag(afi,
17430 safi));
17431 } else if (bgp->default_af[afi][safi])
17432 vty_out(vty, " bgp default %s\n",
17433 get_bgp_default_af_flag(afi, safi));
17434 }
17435
17436 /* BGP default local-preference. */
17437 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17438 vty_out(vty, " bgp default local-preference %u\n",
17439 bgp->default_local_pref);
17440
17441 /* BGP default show-hostname */
17442 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17443 != SAVE_BGP_SHOW_HOSTNAME)
17444 vty_out(vty, " %sbgp default show-hostname\n",
17445 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17446 ? ""
17447 : "no ");
17448
17449 /* BGP default show-nexthop-hostname */
17450 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17451 != SAVE_BGP_SHOW_HOSTNAME)
17452 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17453 CHECK_FLAG(bgp->flags,
17454 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17455 ? ""
17456 : "no ");
17457
17458 /* BGP default subgroup-pkt-queue-max. */
17459 if (bgp->default_subgroup_pkt_queue_max
17460 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17461 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17462 bgp->default_subgroup_pkt_queue_max);
17463
17464 /* BGP client-to-client reflection. */
17465 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17466 vty_out(vty, " no bgp client-to-client reflection\n");
17467
17468 /* BGP cluster ID. */
17469 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17470 vty_out(vty, " bgp cluster-id %pI4\n",
17471 &bgp->cluster_id);
17472
17473 /* Disable ebgp connected nexthop check */
17474 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17475 vty_out(vty,
17476 " bgp disable-ebgp-connected-route-check\n");
17477
17478 /* Confederation identifier*/
17479 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17480 vty_out(vty, " bgp confederation identifier %u\n",
17481 bgp->confed_id);
17482
17483 /* Confederation peer */
17484 if (bgp->confed_peers_cnt > 0) {
17485 int i;
17486
17487 vty_out(vty, " bgp confederation peers");
17488
17489 for (i = 0; i < bgp->confed_peers_cnt; i++)
17490 vty_out(vty, " %u", bgp->confed_peers[i]);
17491
17492 vty_out(vty, "\n");
17493 }
17494
17495 /* BGP deterministic-med. */
17496 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17497 != SAVE_BGP_DETERMINISTIC_MED)
17498 vty_out(vty, " %sbgp deterministic-med\n",
17499 CHECK_FLAG(bgp->flags,
17500 BGP_FLAG_DETERMINISTIC_MED)
17501 ? ""
17502 : "no ");
17503
17504 /* BGP update-delay. */
17505 bgp_config_write_update_delay(vty, bgp);
17506
17507 if (bgp->v_maxmed_onstartup
17508 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17509 vty_out(vty, " bgp max-med on-startup %u",
17510 bgp->v_maxmed_onstartup);
17511 if (bgp->maxmed_onstartup_value
17512 != BGP_MAXMED_VALUE_DEFAULT)
17513 vty_out(vty, " %u",
17514 bgp->maxmed_onstartup_value);
17515 vty_out(vty, "\n");
17516 }
17517 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17518 vty_out(vty, " bgp max-med administrative");
17519 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17520 vty_out(vty, " %u", bgp->maxmed_admin_value);
17521 vty_out(vty, "\n");
17522 }
17523
17524 /* write quanta */
17525 bgp_config_write_wpkt_quanta(vty, bgp);
17526 /* read quanta */
17527 bgp_config_write_rpkt_quanta(vty, bgp);
17528
17529 /* coalesce time */
17530 bgp_config_write_coalesce_time(vty, bgp);
17531
17532 /* BGP per-instance graceful-shutdown */
17533 /* BGP-wide settings and per-instance settings are mutually
17534 * exclusive.
17535 */
17536 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17537 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17538 vty_out(vty, " bgp graceful-shutdown\n");
17539
17540 /* Long-lived Graceful Restart */
17541 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17542 vty_out(vty,
17543 " bgp long-lived-graceful-restart stale-time %u\n",
17544 bgp->llgr_stale_time);
17545
17546 /* BGP graceful-restart. */
17547 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17548 vty_out(vty,
17549 " bgp graceful-restart stalepath-time %u\n",
17550 bgp->stalepath_time);
17551
17552 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17553 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17554 bgp->restart_time);
17555
17556 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17557 SAVE_BGP_GRACEFUL_NOTIFICATION)
17558 vty_out(vty, " %sbgp graceful-restart notification\n",
17559 CHECK_FLAG(bgp->flags,
17560 BGP_FLAG_GRACEFUL_NOTIFICATION)
17561 ? ""
17562 : "no ");
17563
17564 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17565 vty_out(vty,
17566 " bgp graceful-restart select-defer-time %u\n",
17567 bgp->select_defer_time);
17568
17569 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17570 vty_out(vty, " bgp graceful-restart\n");
17571
17572 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17573 vty_out(vty, " bgp graceful-restart-disable\n");
17574
17575 /* BGP graceful-restart Preserve State F bit. */
17576 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17577 vty_out(vty,
17578 " bgp graceful-restart preserve-fw-state\n");
17579
17580 /* Stale timer for RIB */
17581 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17582 vty_out(vty,
17583 " bgp graceful-restart rib-stale-time %u\n",
17584 bgp->rib_stale_time);
17585
17586 /* BGP bestpath method. */
17587 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17588 vty_out(vty, " bgp bestpath as-path ignore\n");
17589 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17590 vty_out(vty, " bgp bestpath as-path confed\n");
17591
17592 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17593 if (CHECK_FLAG(bgp->flags,
17594 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17595 vty_out(vty,
17596 " bgp bestpath as-path multipath-relax as-set\n");
17597 } else {
17598 vty_out(vty,
17599 " bgp bestpath as-path multipath-relax\n");
17600 }
17601 }
17602
17603 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17604 vty_out(vty,
17605 " bgp route-reflector allow-outbound-policy\n");
17606 }
17607 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17608 vty_out(vty, " bgp bestpath compare-routerid\n");
17609 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17610 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17611 vty_out(vty, " bgp bestpath med");
17612 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17613 vty_out(vty, " confed");
17614 if (CHECK_FLAG(bgp->flags,
17615 BGP_FLAG_MED_MISSING_AS_WORST))
17616 vty_out(vty, " missing-as-worst");
17617 vty_out(vty, "\n");
17618 }
17619
17620 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17621 vty_out(vty,
17622 " bgp bestpath peer-type multipath-relax\n");
17623
17624 /* Link bandwidth handling. */
17625 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17626 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17627 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17628 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17629 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17630 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17631
17632 /* BGP network import check. */
17633 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17634 != SAVE_BGP_IMPORT_CHECK)
17635 vty_out(vty, " %sbgp network import-check\n",
17636 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17637 ? ""
17638 : "no ");
17639
17640 /* BGP timers configuration. */
17641 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17642 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17643 vty_out(vty, " timers bgp %u %u\n",
17644 bgp->default_keepalive, bgp->default_holdtime);
17645
17646 /* BGP minimum holdtime configuration. */
17647 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17648 && bgp->default_min_holdtime != 0)
17649 vty_out(vty, " bgp minimum-holdtime %u\n",
17650 bgp->default_min_holdtime);
17651
17652 /* Conditional advertisement timer configuration */
17653 if (bgp->condition_check_period
17654 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17655 vty_out(vty,
17656 " bgp conditional-advertisement timer %u\n",
17657 bgp->condition_check_period);
17658
17659 /* peer-group */
17660 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17661 bgp_config_write_peer_global(vty, bgp, group->conf);
17662 }
17663
17664 /* Normal neighbor configuration. */
17665 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17666 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17667 bgp_config_write_peer_global(vty, bgp, peer);
17668 }
17669
17670 /* listen range and limit for dynamic BGP neighbors */
17671 bgp_config_write_listen(vty, bgp);
17672
17673 /*
17674 * BGP default autoshutdown neighbors
17675 *
17676 * This must be placed after any peer and peer-group
17677 * configuration, to avoid setting all peers to shutdown after
17678 * a daemon restart, which is undesired behavior. (see #2286)
17679 */
17680 if (bgp->autoshutdown)
17681 vty_out(vty, " bgp default shutdown\n");
17682
17683 /* BGP instance administrative shutdown */
17684 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17685 vty_out(vty, " bgp shutdown\n");
17686
17687 if (bgp->allow_martian)
17688 vty_out(vty, " bgp allow-martian-nexthop\n");
17689
17690 if (bgp->fast_convergence)
17691 vty_out(vty, " bgp fast-convergence\n");
17692
17693 if (bgp->srv6_enabled) {
17694 vty_frame(vty, " !\n segment-routing srv6\n");
17695 if (strlen(bgp->srv6_locator_name))
17696 vty_out(vty, " locator %s\n",
17697 bgp->srv6_locator_name);
17698 vty_endframe(vty, " exit\n");
17699 }
17700
17701
17702 /* IPv4 unicast configuration. */
17703 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17704
17705 /* IPv4 multicast configuration. */
17706 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17707
17708 /* IPv4 labeled-unicast configuration. */
17709 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17710
17711 /* IPv4 VPN configuration. */
17712 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17713
17714 /* ENCAPv4 configuration. */
17715 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17716
17717 /* FLOWSPEC v4 configuration. */
17718 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17719
17720 /* IPv6 unicast configuration. */
17721 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17722
17723 /* IPv6 multicast configuration. */
17724 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17725
17726 /* IPv6 labeled-unicast configuration. */
17727 bgp_config_write_family(vty, bgp, AFI_IP6,
17728 SAFI_LABELED_UNICAST);
17729
17730 /* IPv6 VPN configuration. */
17731 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17732
17733 /* ENCAPv6 configuration. */
17734 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17735
17736 /* FLOWSPEC v6 configuration. */
17737 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17738
17739 /* EVPN configuration. */
17740 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17741
17742 hook_call(bgp_inst_config_write, bgp, vty);
17743
17744 #ifdef ENABLE_BGP_VNC
17745 bgp_rfapi_cfg_write(vty, bgp);
17746 #endif
17747
17748 vty_out(vty, "exit\n");
17749 vty_out(vty, "!\n");
17750 }
17751 return 0;
17752 }
17753
17754
17755 /* BGP node structure. */
17756 static struct cmd_node bgp_node = {
17757 .name = "bgp",
17758 .node = BGP_NODE,
17759 .parent_node = CONFIG_NODE,
17760 .prompt = "%s(config-router)# ",
17761 .config_write = bgp_config_write,
17762 };
17763
17764 static struct cmd_node bgp_ipv4_unicast_node = {
17765 .name = "bgp ipv4 unicast",
17766 .node = BGP_IPV4_NODE,
17767 .parent_node = BGP_NODE,
17768 .prompt = "%s(config-router-af)# ",
17769 .no_xpath = true,
17770 };
17771
17772 static struct cmd_node bgp_ipv4_multicast_node = {
17773 .name = "bgp ipv4 multicast",
17774 .node = BGP_IPV4M_NODE,
17775 .parent_node = BGP_NODE,
17776 .prompt = "%s(config-router-af)# ",
17777 .no_xpath = true,
17778 };
17779
17780 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17781 .name = "bgp ipv4 labeled unicast",
17782 .node = BGP_IPV4L_NODE,
17783 .parent_node = BGP_NODE,
17784 .prompt = "%s(config-router-af)# ",
17785 .no_xpath = true,
17786 };
17787
17788 static struct cmd_node bgp_ipv6_unicast_node = {
17789 .name = "bgp ipv6 unicast",
17790 .node = BGP_IPV6_NODE,
17791 .parent_node = BGP_NODE,
17792 .prompt = "%s(config-router-af)# ",
17793 .no_xpath = true,
17794 };
17795
17796 static struct cmd_node bgp_ipv6_multicast_node = {
17797 .name = "bgp ipv6 multicast",
17798 .node = BGP_IPV6M_NODE,
17799 .parent_node = BGP_NODE,
17800 .prompt = "%s(config-router-af)# ",
17801 .no_xpath = true,
17802 };
17803
17804 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17805 .name = "bgp ipv6 labeled unicast",
17806 .node = BGP_IPV6L_NODE,
17807 .parent_node = BGP_NODE,
17808 .prompt = "%s(config-router-af)# ",
17809 .no_xpath = true,
17810 };
17811
17812 static struct cmd_node bgp_vpnv4_node = {
17813 .name = "bgp vpnv4",
17814 .node = BGP_VPNV4_NODE,
17815 .parent_node = BGP_NODE,
17816 .prompt = "%s(config-router-af)# ",
17817 .no_xpath = true,
17818 };
17819
17820 static struct cmd_node bgp_vpnv6_node = {
17821 .name = "bgp vpnv6",
17822 .node = BGP_VPNV6_NODE,
17823 .parent_node = BGP_NODE,
17824 .prompt = "%s(config-router-af-vpnv6)# ",
17825 .no_xpath = true,
17826 };
17827
17828 static struct cmd_node bgp_evpn_node = {
17829 .name = "bgp evpn",
17830 .node = BGP_EVPN_NODE,
17831 .parent_node = BGP_NODE,
17832 .prompt = "%s(config-router-evpn)# ",
17833 .no_xpath = true,
17834 };
17835
17836 static struct cmd_node bgp_evpn_vni_node = {
17837 .name = "bgp evpn vni",
17838 .node = BGP_EVPN_VNI_NODE,
17839 .parent_node = BGP_EVPN_NODE,
17840 .prompt = "%s(config-router-af-vni)# ",
17841 };
17842
17843 static struct cmd_node bgp_flowspecv4_node = {
17844 .name = "bgp ipv4 flowspec",
17845 .node = BGP_FLOWSPECV4_NODE,
17846 .parent_node = BGP_NODE,
17847 .prompt = "%s(config-router-af)# ",
17848 .no_xpath = true,
17849 };
17850
17851 static struct cmd_node bgp_flowspecv6_node = {
17852 .name = "bgp ipv6 flowspec",
17853 .node = BGP_FLOWSPECV6_NODE,
17854 .parent_node = BGP_NODE,
17855 .prompt = "%s(config-router-af-vpnv6)# ",
17856 .no_xpath = true,
17857 };
17858
17859 static struct cmd_node bgp_srv6_node = {
17860 .name = "bgp srv6",
17861 .node = BGP_SRV6_NODE,
17862 .parent_node = BGP_NODE,
17863 .prompt = "%s(config-router-srv6)# ",
17864 };
17865
17866 static void community_list_vty(void);
17867
17868 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17869 {
17870 struct bgp *bgp;
17871 struct peer_group *group;
17872 struct listnode *lnbgp, *lnpeer;
17873
17874 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17875 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17876 vector_set(comps,
17877 XSTRDUP(MTYPE_COMPLETION, group->name));
17878 }
17879 }
17880
17881 static void bgp_ac_peer(vector comps, struct cmd_token *token)
17882 {
17883 struct bgp *bgp;
17884 struct peer *peer;
17885 struct listnode *lnbgp, *lnpeer;
17886
17887 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17888 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17889 /* only provide suggestions on the appropriate input
17890 * token type,
17891 * they'll otherwise show up multiple times */
17892 enum cmd_token_type match_type;
17893 char *name = peer->host;
17894
17895 if (peer->conf_if) {
17896 match_type = VARIABLE_TKN;
17897 name = peer->conf_if;
17898 } else if (strchr(peer->host, ':'))
17899 match_type = IPV6_TKN;
17900 else
17901 match_type = IPV4_TKN;
17902
17903 if (token->type != match_type)
17904 continue;
17905
17906 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17907 }
17908 }
17909 }
17910
17911 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17912 {
17913 bgp_ac_peer(comps, token);
17914
17915 if (token->type == VARIABLE_TKN)
17916 bgp_ac_peergroup(comps, token);
17917 }
17918
17919 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17920 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17921 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17922 {.varname = "peer", .completions = bgp_ac_neighbor},
17923 {.completions = NULL}};
17924
17925 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17926 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17927 {.completions = NULL} };
17928
17929 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
17930
17931 static struct thread *t_bgp_cfg;
17932
17933 bool bgp_config_inprocess(void)
17934 {
17935 return thread_is_scheduled(t_bgp_cfg);
17936 }
17937
17938 static void bgp_config_finish(struct thread *t)
17939 {
17940 struct listnode *node;
17941 struct bgp *bgp;
17942
17943 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
17944 hook_call(bgp_config_end, bgp);
17945 }
17946
17947 static void bgp_config_start(void)
17948 {
17949 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
17950 THREAD_OFF(t_bgp_cfg);
17951 thread_add_timer(bm->master, bgp_config_finish, NULL,
17952 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
17953 }
17954
17955 /* When we receive a hook the configuration is read,
17956 * we start a timer to make sure we postpone sending
17957 * EoR before route-maps are processed.
17958 * This is especially valid if using `bgp route-map delay-timer`.
17959 */
17960 static void bgp_config_end(void)
17961 {
17962 #define BGP_POST_CONFIG_DELAY_SECONDS 1
17963 uint32_t bgp_post_config_delay =
17964 thread_is_scheduled(bm->t_rmap_update)
17965 ? thread_timer_remain_second(bm->t_rmap_update)
17966 : BGP_POST_CONFIG_DELAY_SECONDS;
17967
17968 /* If BGP config processing thread isn't running, then
17969 * we can return and rely it's properly handled.
17970 */
17971 if (!bgp_config_inprocess())
17972 return;
17973
17974 THREAD_OFF(t_bgp_cfg);
17975
17976 /* Start a new timer to make sure we don't send EoR
17977 * before route-maps are processed.
17978 */
17979 thread_add_timer(bm->master, bgp_config_finish, NULL,
17980 bgp_post_config_delay, &t_bgp_cfg);
17981 }
17982
17983 void bgp_vty_init(void)
17984 {
17985 cmd_variable_handler_register(bgp_var_neighbor);
17986 cmd_variable_handler_register(bgp_var_peergroup);
17987
17988 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
17989
17990 /* Install bgp top node. */
17991 install_node(&bgp_node);
17992 install_node(&bgp_ipv4_unicast_node);
17993 install_node(&bgp_ipv4_multicast_node);
17994 install_node(&bgp_ipv4_labeled_unicast_node);
17995 install_node(&bgp_ipv6_unicast_node);
17996 install_node(&bgp_ipv6_multicast_node);
17997 install_node(&bgp_ipv6_labeled_unicast_node);
17998 install_node(&bgp_vpnv4_node);
17999 install_node(&bgp_vpnv6_node);
18000 install_node(&bgp_evpn_node);
18001 install_node(&bgp_evpn_vni_node);
18002 install_node(&bgp_flowspecv4_node);
18003 install_node(&bgp_flowspecv6_node);
18004 install_node(&bgp_srv6_node);
18005
18006 /* Install default VTY commands to new nodes. */
18007 install_default(BGP_NODE);
18008 install_default(BGP_IPV4_NODE);
18009 install_default(BGP_IPV4M_NODE);
18010 install_default(BGP_IPV4L_NODE);
18011 install_default(BGP_IPV6_NODE);
18012 install_default(BGP_IPV6M_NODE);
18013 install_default(BGP_IPV6L_NODE);
18014 install_default(BGP_VPNV4_NODE);
18015 install_default(BGP_VPNV6_NODE);
18016 install_default(BGP_FLOWSPECV4_NODE);
18017 install_default(BGP_FLOWSPECV6_NODE);
18018 install_default(BGP_EVPN_NODE);
18019 install_default(BGP_EVPN_VNI_NODE);
18020 install_default(BGP_SRV6_NODE);
18021
18022 /* "bgp local-mac" hidden commands. */
18023 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18024 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18025
18026 /* "bgp suppress-fib-pending" global */
18027 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18028
18029 /* bgp route-map delay-timer commands. */
18030 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18031 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18032
18033 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18034
18035 /* bgp fast-convergence command */
18036 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18037 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18038
18039 /* global bgp update-delay command */
18040 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18041 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18042
18043 /* global bgp graceful-shutdown command */
18044 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18045 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18046
18047 /* Dummy commands (Currently not supported) */
18048 install_element(BGP_NODE, &no_synchronization_cmd);
18049 install_element(BGP_NODE, &no_auto_summary_cmd);
18050
18051 /* "router bgp" commands. */
18052 install_element(CONFIG_NODE, &router_bgp_cmd);
18053
18054 /* "no router bgp" commands. */
18055 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18056
18057 /* "bgp session-dscp command */
18058 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18059 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18060
18061 /* "bgp router-id" commands. */
18062 install_element(BGP_NODE, &bgp_router_id_cmd);
18063 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18064
18065 /* "bgp suppress-fib-pending" command */
18066 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18067
18068 /* "bgp cluster-id" commands. */
18069 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18070 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18071
18072 /* "bgp no-rib" commands. */
18073 install_element(CONFIG_NODE, &bgp_norib_cmd);
18074 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18075
18076 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18077
18078 /* "bgp confederation" commands. */
18079 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18080 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18081
18082 /* "bgp confederation peers" commands. */
18083 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18084 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18085
18086 /* bgp max-med command */
18087 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18088 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18089 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18090 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18091 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18092
18093 /* "neighbor role" commands. */
18094 install_element(BGP_NODE, &neighbor_role_cmd);
18095 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18096 install_element(BGP_NODE, &no_neighbor_role_cmd);
18097
18098 /* bgp disable-ebgp-connected-nh-check */
18099 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18100 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18101
18102 /* bgp update-delay command */
18103 install_element(BGP_NODE, &bgp_update_delay_cmd);
18104 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18105
18106 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18107 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18108
18109 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18110 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18111
18112 /* "maximum-paths" commands. */
18113 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18114 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18115 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18116 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18117 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18118 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18119 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18120 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18121 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18122 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18123 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18124 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18125 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18126 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18127 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18128
18129 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18130 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18131 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18132 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18133 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18134 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18135 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18136 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18137 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18138 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18139
18140 /* "timers bgp" commands. */
18141 install_element(BGP_NODE, &bgp_timers_cmd);
18142 install_element(BGP_NODE, &no_bgp_timers_cmd);
18143
18144 /* "minimum-holdtime" commands. */
18145 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18146 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18147
18148 /* route-map delay-timer commands - per instance for backwards compat.
18149 */
18150 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18151 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18152
18153 /* "bgp client-to-client reflection" commands */
18154 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18155 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18156
18157 /* "bgp always-compare-med" commands */
18158 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18159 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18160
18161 /* bgp ebgp-requires-policy */
18162 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18163 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18164
18165 /* bgp suppress-duplicates */
18166 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18167 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18168
18169 /* bgp reject-as-sets */
18170 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18171 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18172
18173 /* "bgp deterministic-med" commands */
18174 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18175 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18176
18177 /* "bgp graceful-restart" command */
18178 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18179 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18180
18181 /* "bgp graceful-restart-disable" command */
18182 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18183 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18184
18185 /* "neighbor a:b:c:d graceful-restart" command */
18186 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18187 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18188
18189 /* "neighbor a:b:c:d graceful-restart-disable" command */
18190 install_element(BGP_NODE,
18191 &bgp_neighbor_graceful_restart_disable_set_cmd);
18192 install_element(BGP_NODE,
18193 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18194
18195 /* "neighbor a:b:c:d graceful-restart-helper" command */
18196 install_element(BGP_NODE,
18197 &bgp_neighbor_graceful_restart_helper_set_cmd);
18198 install_element(BGP_NODE,
18199 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18200
18201 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18202 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18203 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18204 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18205 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18206 install_element(BGP_NODE,
18207 &no_bgp_graceful_restart_select_defer_time_cmd);
18208 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18209 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18210 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18211
18212 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18213 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18214 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18215 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18216
18217 /* "bgp graceful-shutdown" commands */
18218 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18219 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18220
18221 /* "bgp hard-administrative-reset" commands */
18222 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18223
18224 /* "bgp long-lived-graceful-restart" commands */
18225 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18226 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18227
18228 /* "bgp fast-external-failover" commands */
18229 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18230 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18231
18232 /* "bgp bestpath compare-routerid" commands */
18233 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18234 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18235
18236 /* "bgp bestpath as-path ignore" commands */
18237 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18238 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18239
18240 /* "bgp bestpath as-path confed" commands */
18241 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18242 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18243
18244 /* "bgp bestpath as-path multipath-relax" commands */
18245 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18246 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18247
18248 /* "bgp bestpath peer-type multipath-relax" commands */
18249 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18250 install_element(BGP_NODE,
18251 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18252
18253 /* "bgp log-neighbor-changes" commands */
18254 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18255 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18256
18257 /* "bgp bestpath med" commands */
18258 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18259 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18260
18261 /* "bgp bestpath bandwidth" commands */
18262 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18263 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18264
18265 /* "no bgp default <afi>-<safi>" commands. */
18266 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18267
18268 /* "bgp network import-check" commands. */
18269 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18270 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18271 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18272
18273 /* "bgp default local-preference" commands. */
18274 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18275 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18276
18277 /* bgp default show-hostname */
18278 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18279 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18280
18281 /* bgp default show-nexthop-hostname */
18282 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18283 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18284
18285 /* "bgp default subgroup-pkt-queue-max" commands. */
18286 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18287 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18288
18289 /* bgp ibgp-allow-policy-mods command */
18290 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18291 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18292
18293 /* "bgp listen limit" commands. */
18294 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18295 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18296
18297 /* "bgp listen range" commands. */
18298 install_element(BGP_NODE, &bgp_listen_range_cmd);
18299 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18300
18301 /* "bgp default shutdown" command */
18302 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18303
18304 /* "bgp shutdown" commands */
18305 install_element(BGP_NODE, &bgp_shutdown_cmd);
18306 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18307 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18308 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18309
18310 /* "neighbor remote-as" commands. */
18311 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18312 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18313 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18314 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18315 install_element(BGP_NODE,
18316 &neighbor_interface_v6only_config_remote_as_cmd);
18317 install_element(BGP_NODE, &no_neighbor_cmd);
18318 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18319
18320 /* "neighbor peer-group" commands. */
18321 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18322 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18323 install_element(BGP_NODE,
18324 &no_neighbor_interface_peer_group_remote_as_cmd);
18325
18326 /* "neighbor local-as" commands. */
18327 install_element(BGP_NODE, &neighbor_local_as_cmd);
18328 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18329 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18330 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18331
18332 /* "neighbor solo" commands. */
18333 install_element(BGP_NODE, &neighbor_solo_cmd);
18334 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18335
18336 /* "neighbor password" commands. */
18337 install_element(BGP_NODE, &neighbor_password_cmd);
18338 install_element(BGP_NODE, &no_neighbor_password_cmd);
18339
18340 /* "neighbor activate" commands. */
18341 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18342 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18343 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18344 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18345 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18346 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18347 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18348 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18349 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18350 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18351 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18352 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18353
18354 /* "no neighbor activate" commands. */
18355 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18356 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18357 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18358 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18359 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18360 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18361 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18362 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18363 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18364 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18365 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18366 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18367
18368 /* "neighbor peer-group" set commands. */
18369 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18370 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18371 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18372 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18373 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18374 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18375 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18376 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18377 install_element(BGP_FLOWSPECV4_NODE,
18378 &neighbor_set_peer_group_hidden_cmd);
18379 install_element(BGP_FLOWSPECV6_NODE,
18380 &neighbor_set_peer_group_hidden_cmd);
18381
18382 /* "no neighbor peer-group unset" commands. */
18383 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18384 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18385 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18386 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18387 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18388 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18389 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18390 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18391 install_element(BGP_FLOWSPECV4_NODE,
18392 &no_neighbor_set_peer_group_hidden_cmd);
18393 install_element(BGP_FLOWSPECV6_NODE,
18394 &no_neighbor_set_peer_group_hidden_cmd);
18395
18396 /* "neighbor softreconfiguration inbound" commands.*/
18397 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18398 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18399 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18400 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18401 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18402 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18403 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18404 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18405 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18406 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18407 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18408 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18409 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18410 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18411 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18412 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18413 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18414 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18415 install_element(BGP_FLOWSPECV4_NODE,
18416 &neighbor_soft_reconfiguration_cmd);
18417 install_element(BGP_FLOWSPECV4_NODE,
18418 &no_neighbor_soft_reconfiguration_cmd);
18419 install_element(BGP_FLOWSPECV6_NODE,
18420 &neighbor_soft_reconfiguration_cmd);
18421 install_element(BGP_FLOWSPECV6_NODE,
18422 &no_neighbor_soft_reconfiguration_cmd);
18423 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18424 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18425
18426 /* "neighbor attribute-unchanged" commands. */
18427 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18428 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18429 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18430 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18431 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18432 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18433 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18434 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18435 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18436 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18437 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18438 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18439 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18440 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18441 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18442 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18443 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18444 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18445
18446 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18447 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18448
18449 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18450 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18451 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18452 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18453
18454 /* "nexthop-local unchanged" commands */
18455 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18456 install_element(BGP_IPV6_NODE,
18457 &no_neighbor_nexthop_local_unchanged_cmd);
18458
18459 /* "neighbor next-hop-self" commands. */
18460 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18461 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18462 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18463 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18464 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18465 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18466 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18467 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18468 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18469 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18470 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18471 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18472 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18473 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18474 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18475 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18476 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18477 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18478 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18479 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18480
18481 /* "neighbor next-hop-self force" commands. */
18482 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18483 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18484 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18485 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18486 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18487 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18488 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18489 install_element(BGP_IPV4_NODE,
18490 &no_neighbor_nexthop_self_all_hidden_cmd);
18491 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18492 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18493 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18494 install_element(BGP_IPV4M_NODE,
18495 &no_neighbor_nexthop_self_all_hidden_cmd);
18496 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18497 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18498 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18499 install_element(BGP_IPV4L_NODE,
18500 &no_neighbor_nexthop_self_all_hidden_cmd);
18501 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18502 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18503 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18504 install_element(BGP_IPV6_NODE,
18505 &no_neighbor_nexthop_self_all_hidden_cmd);
18506 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18507 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18508 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18509 install_element(BGP_IPV6M_NODE,
18510 &no_neighbor_nexthop_self_all_hidden_cmd);
18511 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18512 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18513 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18514 install_element(BGP_IPV6L_NODE,
18515 &no_neighbor_nexthop_self_all_hidden_cmd);
18516 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18517 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18518 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18519 install_element(BGP_VPNV4_NODE,
18520 &no_neighbor_nexthop_self_all_hidden_cmd);
18521 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18522 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18523 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18524 install_element(BGP_VPNV6_NODE,
18525 &no_neighbor_nexthop_self_all_hidden_cmd);
18526 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18527 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18528
18529 /* "neighbor as-override" commands. */
18530 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18531 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18532 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18533 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18534 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18535 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18536 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18537 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18538 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18539 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18540 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18541 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18542 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18543 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18544 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18545 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18546 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18547 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18548
18549 /* "neighbor remove-private-AS" commands. */
18550 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18551 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18552 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18553 install_element(BGP_NODE,
18554 &no_neighbor_remove_private_as_all_hidden_cmd);
18555 install_element(BGP_NODE,
18556 &neighbor_remove_private_as_replace_as_hidden_cmd);
18557 install_element(BGP_NODE,
18558 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18559 install_element(BGP_NODE,
18560 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18561 install_element(
18562 BGP_NODE,
18563 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18564 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18565 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18566 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18567 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18568 install_element(BGP_IPV4_NODE,
18569 &neighbor_remove_private_as_replace_as_cmd);
18570 install_element(BGP_IPV4_NODE,
18571 &no_neighbor_remove_private_as_replace_as_cmd);
18572 install_element(BGP_IPV4_NODE,
18573 &neighbor_remove_private_as_all_replace_as_cmd);
18574 install_element(BGP_IPV4_NODE,
18575 &no_neighbor_remove_private_as_all_replace_as_cmd);
18576 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18577 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18578 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18579 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18580 install_element(BGP_IPV4M_NODE,
18581 &neighbor_remove_private_as_replace_as_cmd);
18582 install_element(BGP_IPV4M_NODE,
18583 &no_neighbor_remove_private_as_replace_as_cmd);
18584 install_element(BGP_IPV4M_NODE,
18585 &neighbor_remove_private_as_all_replace_as_cmd);
18586 install_element(BGP_IPV4M_NODE,
18587 &no_neighbor_remove_private_as_all_replace_as_cmd);
18588 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18589 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18590 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18591 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18592 install_element(BGP_IPV4L_NODE,
18593 &neighbor_remove_private_as_replace_as_cmd);
18594 install_element(BGP_IPV4L_NODE,
18595 &no_neighbor_remove_private_as_replace_as_cmd);
18596 install_element(BGP_IPV4L_NODE,
18597 &neighbor_remove_private_as_all_replace_as_cmd);
18598 install_element(BGP_IPV4L_NODE,
18599 &no_neighbor_remove_private_as_all_replace_as_cmd);
18600 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18601 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18602 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18603 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18604 install_element(BGP_IPV6_NODE,
18605 &neighbor_remove_private_as_replace_as_cmd);
18606 install_element(BGP_IPV6_NODE,
18607 &no_neighbor_remove_private_as_replace_as_cmd);
18608 install_element(BGP_IPV6_NODE,
18609 &neighbor_remove_private_as_all_replace_as_cmd);
18610 install_element(BGP_IPV6_NODE,
18611 &no_neighbor_remove_private_as_all_replace_as_cmd);
18612 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18613 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18614 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18615 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18616 install_element(BGP_IPV6M_NODE,
18617 &neighbor_remove_private_as_replace_as_cmd);
18618 install_element(BGP_IPV6M_NODE,
18619 &no_neighbor_remove_private_as_replace_as_cmd);
18620 install_element(BGP_IPV6M_NODE,
18621 &neighbor_remove_private_as_all_replace_as_cmd);
18622 install_element(BGP_IPV6M_NODE,
18623 &no_neighbor_remove_private_as_all_replace_as_cmd);
18624 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18625 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18626 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18627 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18628 install_element(BGP_IPV6L_NODE,
18629 &neighbor_remove_private_as_replace_as_cmd);
18630 install_element(BGP_IPV6L_NODE,
18631 &no_neighbor_remove_private_as_replace_as_cmd);
18632 install_element(BGP_IPV6L_NODE,
18633 &neighbor_remove_private_as_all_replace_as_cmd);
18634 install_element(BGP_IPV6L_NODE,
18635 &no_neighbor_remove_private_as_all_replace_as_cmd);
18636 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18637 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18638 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18639 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18640 install_element(BGP_VPNV4_NODE,
18641 &neighbor_remove_private_as_replace_as_cmd);
18642 install_element(BGP_VPNV4_NODE,
18643 &no_neighbor_remove_private_as_replace_as_cmd);
18644 install_element(BGP_VPNV4_NODE,
18645 &neighbor_remove_private_as_all_replace_as_cmd);
18646 install_element(BGP_VPNV4_NODE,
18647 &no_neighbor_remove_private_as_all_replace_as_cmd);
18648 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18649 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18650 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18651 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18652 install_element(BGP_VPNV6_NODE,
18653 &neighbor_remove_private_as_replace_as_cmd);
18654 install_element(BGP_VPNV6_NODE,
18655 &no_neighbor_remove_private_as_replace_as_cmd);
18656 install_element(BGP_VPNV6_NODE,
18657 &neighbor_remove_private_as_all_replace_as_cmd);
18658 install_element(BGP_VPNV6_NODE,
18659 &no_neighbor_remove_private_as_all_replace_as_cmd);
18660
18661 /* "neighbor send-community" commands.*/
18662 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18663 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18664 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18665 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18666 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18667 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18668 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18669 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18670 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18671 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18672 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18673 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18674 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18675 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18676 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18677 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18678 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18679 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18680 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18681 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18682 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18683 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18684 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18685 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18686 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18687 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18688 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18689 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18690 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18691 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18692 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18693 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18694 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18695 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18696 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18697 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18698
18699 /* "neighbor route-reflector" commands.*/
18700 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18701 install_element(BGP_NODE,
18702 &no_neighbor_route_reflector_client_hidden_cmd);
18703 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18704 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18705 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18706 install_element(BGP_IPV4M_NODE,
18707 &no_neighbor_route_reflector_client_cmd);
18708 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18709 install_element(BGP_IPV4L_NODE,
18710 &no_neighbor_route_reflector_client_cmd);
18711 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18712 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18713 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18714 install_element(BGP_IPV6M_NODE,
18715 &no_neighbor_route_reflector_client_cmd);
18716 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18717 install_element(BGP_IPV6L_NODE,
18718 &no_neighbor_route_reflector_client_cmd);
18719 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18720 install_element(BGP_VPNV4_NODE,
18721 &no_neighbor_route_reflector_client_cmd);
18722 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18723 install_element(BGP_VPNV6_NODE,
18724 &no_neighbor_route_reflector_client_cmd);
18725 install_element(BGP_FLOWSPECV4_NODE,
18726 &neighbor_route_reflector_client_cmd);
18727 install_element(BGP_FLOWSPECV4_NODE,
18728 &no_neighbor_route_reflector_client_cmd);
18729 install_element(BGP_FLOWSPECV6_NODE,
18730 &neighbor_route_reflector_client_cmd);
18731 install_element(BGP_FLOWSPECV6_NODE,
18732 &no_neighbor_route_reflector_client_cmd);
18733 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18734 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18735
18736 /* "neighbor route-server" commands.*/
18737 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18738 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18739 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18740 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18741 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18742 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18743 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18744 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18745 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18746 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18747 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18748 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18749 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18750 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18751 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18752 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18753 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18754 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18755 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18756 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18757 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18758 install_element(BGP_FLOWSPECV4_NODE,
18759 &no_neighbor_route_server_client_cmd);
18760 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18761 install_element(BGP_FLOWSPECV6_NODE,
18762 &no_neighbor_route_server_client_cmd);
18763
18764 /* "neighbor disable-addpath-rx" commands. */
18765 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18766 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18767 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18768 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18769 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18770 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18771 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18772 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18773 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18774 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18775 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18776 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18777 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18778 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18779 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18780 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18781
18782 /* "neighbor addpath-tx-all-paths" commands.*/
18783 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18784 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18785 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18786 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18787 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18788 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18789 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18790 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18791 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18792 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18793 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18794 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18795 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18796 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18797 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18798 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18799 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18800 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18801
18802 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18803 install_element(BGP_NODE,
18804 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18805 install_element(BGP_NODE,
18806 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18807 install_element(BGP_IPV4_NODE,
18808 &neighbor_addpath_tx_bestpath_per_as_cmd);
18809 install_element(BGP_IPV4_NODE,
18810 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18811 install_element(BGP_IPV4M_NODE,
18812 &neighbor_addpath_tx_bestpath_per_as_cmd);
18813 install_element(BGP_IPV4M_NODE,
18814 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18815 install_element(BGP_IPV4L_NODE,
18816 &neighbor_addpath_tx_bestpath_per_as_cmd);
18817 install_element(BGP_IPV4L_NODE,
18818 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18819 install_element(BGP_IPV6_NODE,
18820 &neighbor_addpath_tx_bestpath_per_as_cmd);
18821 install_element(BGP_IPV6_NODE,
18822 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18823 install_element(BGP_IPV6M_NODE,
18824 &neighbor_addpath_tx_bestpath_per_as_cmd);
18825 install_element(BGP_IPV6M_NODE,
18826 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18827 install_element(BGP_IPV6L_NODE,
18828 &neighbor_addpath_tx_bestpath_per_as_cmd);
18829 install_element(BGP_IPV6L_NODE,
18830 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18831 install_element(BGP_VPNV4_NODE,
18832 &neighbor_addpath_tx_bestpath_per_as_cmd);
18833 install_element(BGP_VPNV4_NODE,
18834 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18835 install_element(BGP_VPNV6_NODE,
18836 &neighbor_addpath_tx_bestpath_per_as_cmd);
18837 install_element(BGP_VPNV6_NODE,
18838 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18839
18840 /* "neighbor sender-as-path-loop-detection" commands. */
18841 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18842 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18843
18844 /* "neighbor passive" commands. */
18845 install_element(BGP_NODE, &neighbor_passive_cmd);
18846 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18847
18848
18849 /* "neighbor shutdown" commands. */
18850 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18851 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18852 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18853 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18854 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18855 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18856
18857 /* "neighbor capability extended-nexthop" commands.*/
18858 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18859 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18860
18861 /* "neighbor capability orf prefix-list" commands.*/
18862 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18863 install_element(BGP_NODE,
18864 &no_neighbor_capability_orf_prefix_hidden_cmd);
18865 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18866 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18867 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18868 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18869 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18870 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18871 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18872 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18873 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18874 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18875 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18876 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18877
18878 /* "neighbor capability dynamic" commands.*/
18879 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18880 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18881
18882 /* "neighbor dont-capability-negotiate" commands. */
18883 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18884 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18885
18886 /* "neighbor ebgp-multihop" commands. */
18887 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18888 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18889 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18890
18891 /* "neighbor disable-connected-check" commands. */
18892 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18893 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18894
18895 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18896 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18897 install_element(BGP_NODE,
18898 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
18899
18900 /* "neighbor extended-optional-parameters" commands. */
18901 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18902 install_element(BGP_NODE,
18903 &no_neighbor_extended_optional_parameters_cmd);
18904
18905 /* "neighbor enforce-first-as" commands. */
18906 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18907 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18908
18909 /* "neighbor description" commands. */
18910 install_element(BGP_NODE, &neighbor_description_cmd);
18911 install_element(BGP_NODE, &no_neighbor_description_cmd);
18912 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18913
18914 /* "neighbor update-source" commands. "*/
18915 install_element(BGP_NODE, &neighbor_update_source_cmd);
18916 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18917
18918 /* "neighbor default-originate" commands. */
18919 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18920 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18921 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18922 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18923 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18924 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18925 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18926 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18927 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18928 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18929 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18930 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18931 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18932 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18933 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18934 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18935 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18936 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18937 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18938 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18939 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18940
18941 /* "neighbor port" commands. */
18942 install_element(BGP_NODE, &neighbor_port_cmd);
18943 install_element(BGP_NODE, &no_neighbor_port_cmd);
18944
18945 /* "neighbor weight" commands. */
18946 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18947 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18948
18949 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18950 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18951 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18952 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18953 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18954 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18955 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18956 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18957 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18958 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18959 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18960 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18961 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18962 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18963 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18964 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18965
18966 /* "neighbor override-capability" commands. */
18967 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18968 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18969
18970 /* "neighbor strict-capability-match" commands. */
18971 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18972 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18973
18974 /* "neighbor timers" commands. */
18975 install_element(BGP_NODE, &neighbor_timers_cmd);
18976 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18977
18978 /* "neighbor timers connect" commands. */
18979 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18980 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18981
18982 /* "neighbor timers delayopen" commands. */
18983 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18984 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18985
18986 /* "neighbor advertisement-interval" commands. */
18987 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18988 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18989
18990 /* "neighbor interface" commands. */
18991 install_element(BGP_NODE, &neighbor_interface_cmd);
18992 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18993
18994 /* "neighbor distribute" commands. */
18995 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18996 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18997 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18998 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18999 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19000 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19001 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19002 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19003 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19004 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19005 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19006 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19007 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19008 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19009 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19010 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19011 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19012 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19013
19014 /* "neighbor prefix-list" commands. */
19015 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19016 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19017 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19018 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19019 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19020 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19021 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19022 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19023 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19024 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19025 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19026 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19027 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19028 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19029 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19030 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19031 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19032 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19033 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19034 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19035 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19036 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19037
19038 /* "neighbor filter-list" commands. */
19039 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19040 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19041 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19042 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19043 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19044 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19045 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19046 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19047 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19048 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19049 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19050 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19051 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19052 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19053 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19054 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19055 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19056 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19057 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19058 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19059 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19060 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19061
19062 /* "neighbor route-map" commands. */
19063 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19064 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19065 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19066 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19067 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19068 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19069 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19070 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19071 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19072 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19073 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19074 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19075 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19076 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19077 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19078 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19079 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19080 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19081 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19082 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19083 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19084 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19085 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19086 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19087
19088 /* "neighbor unsuppress-map" commands. */
19089 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19090 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19091 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19092 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19093 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19094 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19095 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19096 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19097 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19098 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19099 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19100 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19101 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19102 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19103 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19104 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19105 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19106 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19107
19108 /* "neighbor advertise-map" commands. */
19109 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19110 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19111 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19112 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19113 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19114 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19115 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19116 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19117 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19118 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19119
19120 /* neighbor maximum-prefix-out commands. */
19121 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19122 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19123 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19124 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19125 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19126 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19127 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19128 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19129 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19130 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19131 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19132 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19133 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19134 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19135 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19136 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19137 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19138 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19139
19140 /* "neighbor maximum-prefix" commands. */
19141 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19142 install_element(BGP_NODE,
19143 &neighbor_maximum_prefix_threshold_hidden_cmd);
19144 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19145 install_element(BGP_NODE,
19146 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19147 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19148 install_element(BGP_NODE,
19149 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19150 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19151 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19152 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19153 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19154 install_element(BGP_IPV4_NODE,
19155 &neighbor_maximum_prefix_threshold_warning_cmd);
19156 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19157 install_element(BGP_IPV4_NODE,
19158 &neighbor_maximum_prefix_threshold_restart_cmd);
19159 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19160 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19161 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19162 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19163 install_element(BGP_IPV4M_NODE,
19164 &neighbor_maximum_prefix_threshold_warning_cmd);
19165 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19166 install_element(BGP_IPV4M_NODE,
19167 &neighbor_maximum_prefix_threshold_restart_cmd);
19168 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19169 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19170 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19171 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19172 install_element(BGP_IPV4L_NODE,
19173 &neighbor_maximum_prefix_threshold_warning_cmd);
19174 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19175 install_element(BGP_IPV4L_NODE,
19176 &neighbor_maximum_prefix_threshold_restart_cmd);
19177 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19178 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19179 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19180 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19181 install_element(BGP_IPV6_NODE,
19182 &neighbor_maximum_prefix_threshold_warning_cmd);
19183 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19184 install_element(BGP_IPV6_NODE,
19185 &neighbor_maximum_prefix_threshold_restart_cmd);
19186 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19187 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19188 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19189 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19190 install_element(BGP_IPV6M_NODE,
19191 &neighbor_maximum_prefix_threshold_warning_cmd);
19192 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19193 install_element(BGP_IPV6M_NODE,
19194 &neighbor_maximum_prefix_threshold_restart_cmd);
19195 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19196 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19197 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19198 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19199 install_element(BGP_IPV6L_NODE,
19200 &neighbor_maximum_prefix_threshold_warning_cmd);
19201 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19202 install_element(BGP_IPV6L_NODE,
19203 &neighbor_maximum_prefix_threshold_restart_cmd);
19204 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19205 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19206 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19207 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19208 install_element(BGP_VPNV4_NODE,
19209 &neighbor_maximum_prefix_threshold_warning_cmd);
19210 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19211 install_element(BGP_VPNV4_NODE,
19212 &neighbor_maximum_prefix_threshold_restart_cmd);
19213 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19214 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19215 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19216 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19217 install_element(BGP_VPNV6_NODE,
19218 &neighbor_maximum_prefix_threshold_warning_cmd);
19219 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19220 install_element(BGP_VPNV6_NODE,
19221 &neighbor_maximum_prefix_threshold_restart_cmd);
19222 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19223
19224 /* "neighbor allowas-in" */
19225 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19226 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19227 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19228 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19229 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19230 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19231 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19232 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19233 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19234 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19235 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19236 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19237 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19238 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19239 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19240 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19241 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19242 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19243 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19244 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19245
19246 /* address-family commands. */
19247 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19248 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19249 #ifdef KEEP_OLD_VPN_COMMANDS
19250 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19251 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19252 #endif /* KEEP_OLD_VPN_COMMANDS */
19253
19254 install_element(BGP_NODE, &address_family_evpn_cmd);
19255
19256 /* "exit-address-family" command. */
19257 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19258 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19259 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19260 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19261 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19262 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19263 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19264 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19265 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19266 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19267 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19268
19269 /* "clear ip bgp commands" */
19270 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19271
19272 /* clear ip bgp prefix */
19273 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19274 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19275 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19276
19277 /* "show [ip] bgp summary" commands. */
19278 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19279 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19280 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19281 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19282 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19283 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19284 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19285
19286 /* "show [ip] bgp neighbors" commands. */
19287 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19288
19289 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19290
19291 /* "show [ip] bgp peer-group" commands. */
19292 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19293
19294 /* "show [ip] bgp paths" commands. */
19295 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19296
19297 /* "show [ip] bgp community" commands. */
19298 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19299
19300 /* "show ip bgp large-community" commands. */
19301 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19302 /* "show [ip] bgp attribute-info" commands. */
19303 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19304 /* "show [ip] bgp route-leak" command */
19305 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19306
19307 /* "redistribute" commands. */
19308 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19309 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19310 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19311 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19312 install_element(BGP_NODE,
19313 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19314 install_element(BGP_NODE,
19315 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19316 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19317 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19318 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19319 install_element(BGP_NODE,
19320 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19321 install_element(BGP_NODE,
19322 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19323 install_element(BGP_NODE,
19324 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19325 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19326 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19327 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19328 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19329 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19330 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19331 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19332 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19333 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19334 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19335 install_element(BGP_IPV4_NODE,
19336 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19337 install_element(BGP_IPV4_NODE,
19338 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19339 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19340 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19341 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19342 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19343 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19344 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19345
19346 /* import|export vpn [route-map RMAP_NAME] */
19347 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19348 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19349
19350 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19351 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19352
19353 /* ttl_security commands */
19354 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19355 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19356
19357 /* "show [ip] bgp memory" commands. */
19358 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19359
19360 /* "show bgp martian next-hop" */
19361 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19362
19363 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19364
19365 /* "show [ip] bgp views" commands. */
19366 install_element(VIEW_NODE, &show_bgp_views_cmd);
19367
19368 /* "show [ip] bgp vrfs" commands. */
19369 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19370
19371 /* Community-list. */
19372 community_list_vty();
19373
19374 community_alias_vty();
19375
19376 /* vpn-policy commands */
19377 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19378 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19379 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19380 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19381 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19382 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19383 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19384 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19385 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19386 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19387 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19388 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19389
19390 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19391 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19392
19393 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19394 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19395 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19396 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19397 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19398 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19399 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19400 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19401 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19402 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19403
19404 /* tcp-mss command */
19405 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19406 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19407
19408 /* srv6 commands */
19409 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19410 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19411 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19412 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19413 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19414 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19415 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19416 }
19417
19418 #include "memory.h"
19419 #include "bgp_regex.h"
19420 #include "bgp_clist.h"
19421 #include "bgp_ecommunity.h"
19422
19423 /* VTY functions. */
19424
19425 /* Direction value to string conversion. */
19426 static const char *community_direct_str(int direct)
19427 {
19428 switch (direct) {
19429 case COMMUNITY_DENY:
19430 return "deny";
19431 case COMMUNITY_PERMIT:
19432 return "permit";
19433 default:
19434 return "unknown";
19435 }
19436 }
19437
19438 /* Display error string. */
19439 static void community_list_perror(struct vty *vty, int ret)
19440 {
19441 switch (ret) {
19442 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19443 vty_out(vty, "%% Can't find community-list\n");
19444 break;
19445 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19446 vty_out(vty, "%% Malformed community-list value\n");
19447 break;
19448 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19449 vty_out(vty,
19450 "%% Community name conflict, previously defined as standard community\n");
19451 break;
19452 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19453 vty_out(vty,
19454 "%% Community name conflict, previously defined as expanded community\n");
19455 break;
19456 }
19457 }
19458
19459 /* "community-list" keyword help string. */
19460 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19461
19462 /*community-list standard */
19463 DEFUN (community_list_standard,
19464 bgp_community_list_standard_cmd,
19465 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19466 BGP_STR
19467 COMMUNITY_LIST_STR
19468 "Community list number (standard)\n"
19469 "Add an standard community-list entry\n"
19470 "Community list name\n"
19471 "Sequence number of an entry\n"
19472 "Sequence number\n"
19473 "Specify community to reject\n"
19474 "Specify community to accept\n"
19475 COMMUNITY_VAL_STR)
19476 {
19477 char *cl_name_or_number = NULL;
19478 char *seq = NULL;
19479 int direct = 0;
19480 int style = COMMUNITY_LIST_STANDARD;
19481 int idx = 0;
19482
19483 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19484 seq = argv[idx]->arg;
19485
19486 idx = 0;
19487 argv_find(argv, argc, "(1-99)", &idx);
19488 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19489 cl_name_or_number = argv[idx]->arg;
19490 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19491 : COMMUNITY_DENY;
19492 argv_find(argv, argc, "AA:NN", &idx);
19493 char *str = argv_concat(argv, argc, idx);
19494
19495 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19496 direct, style);
19497
19498 XFREE(MTYPE_TMP, str);
19499
19500 if (ret < 0) {
19501 /* Display error string. */
19502 community_list_perror(vty, ret);
19503 return CMD_WARNING_CONFIG_FAILED;
19504 }
19505
19506 return CMD_SUCCESS;
19507 }
19508
19509 DEFUN (no_community_list_standard_all,
19510 no_bgp_community_list_standard_all_cmd,
19511 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19512 NO_STR
19513 BGP_STR
19514 COMMUNITY_LIST_STR
19515 "Community list number (standard)\n"
19516 "Add an standard community-list entry\n"
19517 "Community list name\n"
19518 "Sequence number of an entry\n"
19519 "Sequence number\n"
19520 "Specify community to reject\n"
19521 "Specify community to accept\n"
19522 COMMUNITY_VAL_STR)
19523 {
19524 char *cl_name_or_number = NULL;
19525 char *str = NULL;
19526 int direct = 0;
19527 int style = COMMUNITY_LIST_STANDARD;
19528 char *seq = NULL;
19529 int idx = 0;
19530
19531 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19532 seq = argv[idx]->arg;
19533
19534 idx = 0;
19535 argv_find(argv, argc, "permit", &idx);
19536 argv_find(argv, argc, "deny", &idx);
19537
19538 if (idx) {
19539 direct = argv_find(argv, argc, "permit", &idx)
19540 ? COMMUNITY_PERMIT
19541 : COMMUNITY_DENY;
19542
19543 idx = 0;
19544 argv_find(argv, argc, "AA:NN", &idx);
19545 str = argv_concat(argv, argc, idx);
19546 }
19547
19548 idx = 0;
19549 argv_find(argv, argc, "(1-99)", &idx);
19550 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19551 cl_name_or_number = argv[idx]->arg;
19552
19553 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19554 direct, style);
19555
19556 XFREE(MTYPE_TMP, str);
19557
19558 if (ret < 0) {
19559 community_list_perror(vty, ret);
19560 return CMD_WARNING_CONFIG_FAILED;
19561 }
19562
19563 return CMD_SUCCESS;
19564 }
19565
19566 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19567 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19568 NO_STR BGP_STR COMMUNITY_LIST_STR
19569 "Community list number (standard)\n"
19570 "Add an standard community-list entry\n"
19571 "Community list name\n")
19572
19573 /*community-list expanded */
19574 DEFUN (community_list_expanded_all,
19575 bgp_community_list_expanded_all_cmd,
19576 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19577 BGP_STR
19578 COMMUNITY_LIST_STR
19579 "Community list number (expanded)\n"
19580 "Add an expanded community-list entry\n"
19581 "Community list name\n"
19582 "Sequence number of an entry\n"
19583 "Sequence number\n"
19584 "Specify community to reject\n"
19585 "Specify community to accept\n"
19586 COMMUNITY_VAL_STR)
19587 {
19588 char *cl_name_or_number = NULL;
19589 char *seq = NULL;
19590 int direct = 0;
19591 int style = COMMUNITY_LIST_EXPANDED;
19592 int idx = 0;
19593
19594 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19595 seq = argv[idx]->arg;
19596
19597 idx = 0;
19598
19599 argv_find(argv, argc, "(100-500)", &idx);
19600 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19601 cl_name_or_number = argv[idx]->arg;
19602 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19603 : COMMUNITY_DENY;
19604 argv_find(argv, argc, "AA:NN", &idx);
19605 char *str = argv_concat(argv, argc, idx);
19606
19607 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19608 direct, style);
19609
19610 XFREE(MTYPE_TMP, str);
19611
19612 if (ret < 0) {
19613 /* Display error string. */
19614 community_list_perror(vty, ret);
19615 return CMD_WARNING_CONFIG_FAILED;
19616 }
19617
19618 return CMD_SUCCESS;
19619 }
19620
19621 DEFUN (no_community_list_expanded_all,
19622 no_bgp_community_list_expanded_all_cmd,
19623 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19624 NO_STR
19625 BGP_STR
19626 COMMUNITY_LIST_STR
19627 "Community list number (expanded)\n"
19628 "Add an expanded community-list entry\n"
19629 "Community list name\n"
19630 "Sequence number of an entry\n"
19631 "Sequence number\n"
19632 "Specify community to reject\n"
19633 "Specify community to accept\n"
19634 COMMUNITY_VAL_STR)
19635 {
19636 char *cl_name_or_number = NULL;
19637 char *seq = NULL;
19638 char *str = NULL;
19639 int direct = 0;
19640 int style = COMMUNITY_LIST_EXPANDED;
19641 int idx = 0;
19642
19643 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19644 seq = argv[idx]->arg;
19645
19646 idx = 0;
19647 argv_find(argv, argc, "permit", &idx);
19648 argv_find(argv, argc, "deny", &idx);
19649
19650 if (idx) {
19651 direct = argv_find(argv, argc, "permit", &idx)
19652 ? COMMUNITY_PERMIT
19653 : COMMUNITY_DENY;
19654
19655 idx = 0;
19656 argv_find(argv, argc, "AA:NN", &idx);
19657 str = argv_concat(argv, argc, idx);
19658 }
19659
19660 idx = 0;
19661 argv_find(argv, argc, "(100-500)", &idx);
19662 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19663 cl_name_or_number = argv[idx]->arg;
19664
19665 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19666 direct, style);
19667
19668 XFREE(MTYPE_TMP, str);
19669
19670 if (ret < 0) {
19671 community_list_perror(vty, ret);
19672 return CMD_WARNING_CONFIG_FAILED;
19673 }
19674
19675 return CMD_SUCCESS;
19676 }
19677
19678 ALIAS(no_community_list_expanded_all,
19679 no_bgp_community_list_expanded_all_list_cmd,
19680 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19681 NO_STR BGP_STR COMMUNITY_LIST_STR
19682 "Community list number (expanded)\n"
19683 "Add an expanded community-list entry\n"
19684 "Community list name\n")
19685
19686 /* Return configuration string of community-list entry. */
19687 static const char *community_list_config_str(struct community_entry *entry)
19688 {
19689 const char *str;
19690
19691 if (entry->any)
19692 str = "";
19693 else {
19694 if (entry->style == COMMUNITY_LIST_STANDARD)
19695 str = community_str(entry->u.com, false, false);
19696 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19697 str = lcommunity_str(entry->u.lcom, false, false);
19698 else
19699 str = entry->config;
19700 }
19701 return str;
19702 }
19703
19704 static void community_list_show(struct vty *vty, struct community_list *list)
19705 {
19706 struct community_entry *entry;
19707
19708 for (entry = list->head; entry; entry = entry->next) {
19709 if (entry == list->head) {
19710 if (all_digit(list->name))
19711 vty_out(vty, "Community %s list %s\n",
19712 entry->style == COMMUNITY_LIST_STANDARD
19713 ? "standard"
19714 : "(expanded) access",
19715 list->name);
19716 else
19717 vty_out(vty, "Named Community %s list %s\n",
19718 entry->style == COMMUNITY_LIST_STANDARD
19719 ? "standard"
19720 : "expanded",
19721 list->name);
19722 }
19723 if (entry->any)
19724 vty_out(vty, " %s\n",
19725 community_direct_str(entry->direct));
19726 else
19727 vty_out(vty, " %s %s\n",
19728 community_direct_str(entry->direct),
19729 community_list_config_str(entry));
19730 }
19731 }
19732
19733 DEFUN (show_community_list,
19734 show_bgp_community_list_cmd,
19735 "show bgp community-list",
19736 SHOW_STR
19737 BGP_STR
19738 "List community-list\n")
19739 {
19740 struct community_list *list;
19741 struct community_list_master *cm;
19742
19743 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19744 if (!cm)
19745 return CMD_SUCCESS;
19746
19747 for (list = cm->num.head; list; list = list->next)
19748 community_list_show(vty, list);
19749
19750 for (list = cm->str.head; list; list = list->next)
19751 community_list_show(vty, list);
19752
19753 return CMD_SUCCESS;
19754 }
19755
19756 DEFUN (show_community_list_arg,
19757 show_bgp_community_list_arg_cmd,
19758 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
19759 SHOW_STR
19760 BGP_STR
19761 "List community-list\n"
19762 "Community-list number\n"
19763 "Community-list name\n"
19764 "Detailed information on community-list\n")
19765 {
19766 int idx_comm_list = 3;
19767 struct community_list *list;
19768
19769 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19770 COMMUNITY_LIST_MASTER);
19771 if (!list) {
19772 vty_out(vty, "%% Can't find community-list\n");
19773 return CMD_WARNING;
19774 }
19775
19776 community_list_show(vty, list);
19777
19778 return CMD_SUCCESS;
19779 }
19780
19781 /*
19782 * Large Community code.
19783 */
19784 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19785 struct cmd_token **argv, int style,
19786 int reject_all_digit_name)
19787 {
19788 int ret;
19789 int direct;
19790 char *str;
19791 int idx = 0;
19792 char *cl_name;
19793 char *seq = NULL;
19794
19795 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19796 seq = argv[idx]->arg;
19797
19798 idx = 0;
19799 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19800 : COMMUNITY_DENY;
19801
19802 /* All digit name check. */
19803 idx = 0;
19804 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19805 argv_find(argv, argc, "(1-99)", &idx);
19806 argv_find(argv, argc, "(100-500)", &idx);
19807 cl_name = argv[idx]->arg;
19808 if (reject_all_digit_name && all_digit(cl_name)) {
19809 vty_out(vty, "%% Community name cannot have all digits\n");
19810 return CMD_WARNING_CONFIG_FAILED;
19811 }
19812
19813 idx = 0;
19814 argv_find(argv, argc, "AA:BB:CC", &idx);
19815 argv_find(argv, argc, "LINE", &idx);
19816 /* Concat community string argument. */
19817 if (idx)
19818 str = argv_concat(argv, argc, idx);
19819 else
19820 str = NULL;
19821
19822 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19823
19824 /* Free temporary community list string allocated by
19825 argv_concat(). */
19826 XFREE(MTYPE_TMP, str);
19827
19828 if (ret < 0) {
19829 community_list_perror(vty, ret);
19830 return CMD_WARNING_CONFIG_FAILED;
19831 }
19832 return CMD_SUCCESS;
19833 }
19834
19835 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19836 struct cmd_token **argv, int style)
19837 {
19838 int ret;
19839 int direct = 0;
19840 char *str = NULL;
19841 int idx = 0;
19842 char *seq = NULL;
19843
19844 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19845 seq = argv[idx]->arg;
19846
19847 idx = 0;
19848 argv_find(argv, argc, "permit", &idx);
19849 argv_find(argv, argc, "deny", &idx);
19850
19851 if (idx) {
19852 /* Check the list direct. */
19853 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19854 direct = COMMUNITY_PERMIT;
19855 else
19856 direct = COMMUNITY_DENY;
19857
19858 idx = 0;
19859 argv_find(argv, argc, "LINE", &idx);
19860 argv_find(argv, argc, "AA:AA:NN", &idx);
19861 /* Concat community string argument. */
19862 str = argv_concat(argv, argc, idx);
19863 }
19864
19865 idx = 0;
19866 argv_find(argv, argc, "(1-99)", &idx);
19867 argv_find(argv, argc, "(100-500)", &idx);
19868 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19869
19870 /* Unset community list. */
19871 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19872 style);
19873
19874 /* Free temporary community list string allocated by
19875 argv_concat(). */
19876 XFREE(MTYPE_TMP, str);
19877
19878 if (ret < 0) {
19879 community_list_perror(vty, ret);
19880 return CMD_WARNING_CONFIG_FAILED;
19881 }
19882
19883 return CMD_SUCCESS;
19884 }
19885
19886 /* "large-community-list" keyword help string. */
19887 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19888 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19889
19890 DEFUN (lcommunity_list_standard,
19891 bgp_lcommunity_list_standard_cmd,
19892 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19893 BGP_STR
19894 LCOMMUNITY_LIST_STR
19895 "Large Community list number (standard)\n"
19896 "Sequence number of an entry\n"
19897 "Sequence number\n"
19898 "Specify large community to reject\n"
19899 "Specify large community to accept\n"
19900 LCOMMUNITY_VAL_STR)
19901 {
19902 return lcommunity_list_set_vty(vty, argc, argv,
19903 LARGE_COMMUNITY_LIST_STANDARD, 0);
19904 }
19905
19906 DEFUN (lcommunity_list_expanded,
19907 bgp_lcommunity_list_expanded_cmd,
19908 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19909 BGP_STR
19910 LCOMMUNITY_LIST_STR
19911 "Large Community list number (expanded)\n"
19912 "Sequence number of an entry\n"
19913 "Sequence number\n"
19914 "Specify large community to reject\n"
19915 "Specify large community to accept\n"
19916 "An ordered list as a regular-expression\n")
19917 {
19918 return lcommunity_list_set_vty(vty, argc, argv,
19919 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19920 }
19921
19922 DEFUN (lcommunity_list_name_standard,
19923 bgp_lcommunity_list_name_standard_cmd,
19924 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19925 BGP_STR
19926 LCOMMUNITY_LIST_STR
19927 "Specify standard large-community-list\n"
19928 "Large Community list name\n"
19929 "Sequence number of an entry\n"
19930 "Sequence number\n"
19931 "Specify large community to reject\n"
19932 "Specify large community to accept\n"
19933 LCOMMUNITY_VAL_STR)
19934 {
19935 return lcommunity_list_set_vty(vty, argc, argv,
19936 LARGE_COMMUNITY_LIST_STANDARD, 1);
19937 }
19938
19939 DEFUN (lcommunity_list_name_expanded,
19940 bgp_lcommunity_list_name_expanded_cmd,
19941 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19942 BGP_STR
19943 LCOMMUNITY_LIST_STR
19944 "Specify expanded large-community-list\n"
19945 "Large Community list name\n"
19946 "Sequence number of an entry\n"
19947 "Sequence number\n"
19948 "Specify large community to reject\n"
19949 "Specify large community to accept\n"
19950 "An ordered list as a regular-expression\n")
19951 {
19952 return lcommunity_list_set_vty(vty, argc, argv,
19953 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19954 }
19955
19956 DEFUN (no_lcommunity_list_all,
19957 no_bgp_lcommunity_list_all_cmd,
19958 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
19959 NO_STR
19960 BGP_STR
19961 LCOMMUNITY_LIST_STR
19962 "Large Community list number (standard)\n"
19963 "Large Community list number (expanded)\n"
19964 "Large Community list name\n")
19965 {
19966 return lcommunity_list_unset_vty(vty, argc, argv,
19967 LARGE_COMMUNITY_LIST_STANDARD);
19968 }
19969
19970 DEFUN (no_lcommunity_list_name_standard_all,
19971 no_bgp_lcommunity_list_name_standard_all_cmd,
19972 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
19973 NO_STR
19974 BGP_STR
19975 LCOMMUNITY_LIST_STR
19976 "Specify standard large-community-list\n"
19977 "Large Community list name\n")
19978 {
19979 return lcommunity_list_unset_vty(vty, argc, argv,
19980 LARGE_COMMUNITY_LIST_STANDARD);
19981 }
19982
19983 DEFUN (no_lcommunity_list_name_expanded_all,
19984 no_bgp_lcommunity_list_name_expanded_all_cmd,
19985 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
19986 NO_STR
19987 BGP_STR
19988 LCOMMUNITY_LIST_STR
19989 "Specify expanded large-community-list\n"
19990 "Large Community list name\n")
19991 {
19992 return lcommunity_list_unset_vty(vty, argc, argv,
19993 LARGE_COMMUNITY_LIST_EXPANDED);
19994 }
19995
19996 DEFUN (no_lcommunity_list_standard,
19997 no_bgp_lcommunity_list_standard_cmd,
19998 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19999 NO_STR
20000 BGP_STR
20001 LCOMMUNITY_LIST_STR
20002 "Large Community list number (standard)\n"
20003 "Sequence number of an entry\n"
20004 "Sequence number\n"
20005 "Specify large community to reject\n"
20006 "Specify large community to accept\n"
20007 LCOMMUNITY_VAL_STR)
20008 {
20009 return lcommunity_list_unset_vty(vty, argc, argv,
20010 LARGE_COMMUNITY_LIST_STANDARD);
20011 }
20012
20013 DEFUN (no_lcommunity_list_expanded,
20014 no_bgp_lcommunity_list_expanded_cmd,
20015 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20016 NO_STR
20017 BGP_STR
20018 LCOMMUNITY_LIST_STR
20019 "Large Community list number (expanded)\n"
20020 "Sequence number of an entry\n"
20021 "Sequence number\n"
20022 "Specify large community to reject\n"
20023 "Specify large community to accept\n"
20024 "An ordered list as a regular-expression\n")
20025 {
20026 return lcommunity_list_unset_vty(vty, argc, argv,
20027 LARGE_COMMUNITY_LIST_EXPANDED);
20028 }
20029
20030 DEFUN (no_lcommunity_list_name_standard,
20031 no_bgp_lcommunity_list_name_standard_cmd,
20032 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20033 NO_STR
20034 BGP_STR
20035 LCOMMUNITY_LIST_STR
20036 "Specify standard large-community-list\n"
20037 "Large Community list name\n"
20038 "Sequence number of an entry\n"
20039 "Sequence number\n"
20040 "Specify large community to reject\n"
20041 "Specify large community to accept\n"
20042 LCOMMUNITY_VAL_STR)
20043 {
20044 return lcommunity_list_unset_vty(vty, argc, argv,
20045 LARGE_COMMUNITY_LIST_STANDARD);
20046 }
20047
20048 DEFUN (no_lcommunity_list_name_expanded,
20049 no_bgp_lcommunity_list_name_expanded_cmd,
20050 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20051 NO_STR
20052 BGP_STR
20053 LCOMMUNITY_LIST_STR
20054 "Specify expanded large-community-list\n"
20055 "Large community list name\n"
20056 "Sequence number of an entry\n"
20057 "Sequence number\n"
20058 "Specify large community to reject\n"
20059 "Specify large community to accept\n"
20060 "An ordered list as a regular-expression\n")
20061 {
20062 return lcommunity_list_unset_vty(vty, argc, argv,
20063 LARGE_COMMUNITY_LIST_EXPANDED);
20064 }
20065
20066 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20067 {
20068 struct community_entry *entry;
20069
20070 for (entry = list->head; entry; entry = entry->next) {
20071 if (entry == list->head) {
20072 if (all_digit(list->name))
20073 vty_out(vty, "Large community %s list %s\n",
20074 entry->style ==
20075 LARGE_COMMUNITY_LIST_STANDARD
20076 ? "standard"
20077 : "(expanded) access",
20078 list->name);
20079 else
20080 vty_out(vty,
20081 "Named large community %s list %s\n",
20082 entry->style ==
20083 LARGE_COMMUNITY_LIST_STANDARD
20084 ? "standard"
20085 : "expanded",
20086 list->name);
20087 }
20088 if (entry->any)
20089 vty_out(vty, " %s\n",
20090 community_direct_str(entry->direct));
20091 else
20092 vty_out(vty, " %s %s\n",
20093 community_direct_str(entry->direct),
20094 community_list_config_str(entry));
20095 }
20096 }
20097
20098 DEFUN (show_lcommunity_list,
20099 show_bgp_lcommunity_list_cmd,
20100 "show bgp large-community-list",
20101 SHOW_STR
20102 BGP_STR
20103 "List large-community list\n")
20104 {
20105 struct community_list *list;
20106 struct community_list_master *cm;
20107
20108 cm = community_list_master_lookup(bgp_clist,
20109 LARGE_COMMUNITY_LIST_MASTER);
20110 if (!cm)
20111 return CMD_SUCCESS;
20112
20113 for (list = cm->num.head; list; list = list->next)
20114 lcommunity_list_show(vty, list);
20115
20116 for (list = cm->str.head; list; list = list->next)
20117 lcommunity_list_show(vty, list);
20118
20119 return CMD_SUCCESS;
20120 }
20121
20122 DEFUN (show_lcommunity_list_arg,
20123 show_bgp_lcommunity_list_arg_cmd,
20124 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20125 SHOW_STR
20126 BGP_STR
20127 "List large-community list\n"
20128 "Large-community-list number\n"
20129 "Large-community-list name\n"
20130 "Detailed information on large-community-list\n")
20131 {
20132 struct community_list *list;
20133
20134 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20135 LARGE_COMMUNITY_LIST_MASTER);
20136 if (!list) {
20137 vty_out(vty, "%% Can't find large-community-list\n");
20138 return CMD_WARNING;
20139 }
20140
20141 lcommunity_list_show(vty, list);
20142
20143 return CMD_SUCCESS;
20144 }
20145
20146 /* "extcommunity-list" keyword help string. */
20147 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20148 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20149
20150 DEFUN (extcommunity_list_standard,
20151 bgp_extcommunity_list_standard_cmd,
20152 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20153 BGP_STR
20154 EXTCOMMUNITY_LIST_STR
20155 "Extended Community list number (standard)\n"
20156 "Specify standard extcommunity-list\n"
20157 "Community list name\n"
20158 "Sequence number of an entry\n"
20159 "Sequence number\n"
20160 "Specify community to reject\n"
20161 "Specify community to accept\n"
20162 EXTCOMMUNITY_VAL_STR)
20163 {
20164 int style = EXTCOMMUNITY_LIST_STANDARD;
20165 int direct = 0;
20166 char *cl_number_or_name = NULL;
20167 char *seq = NULL;
20168
20169 int idx = 0;
20170
20171 argv_find(argv, argc, "(1-99)", &idx);
20172 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20173 cl_number_or_name = argv[idx]->arg;
20174
20175 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20176 seq = argv[idx]->arg;
20177
20178 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20179 : COMMUNITY_DENY;
20180 argv_find(argv, argc, "AA:NN", &idx);
20181 char *str = argv_concat(argv, argc, idx);
20182
20183 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20184 direct, style);
20185
20186 XFREE(MTYPE_TMP, str);
20187
20188 if (ret < 0) {
20189 community_list_perror(vty, ret);
20190 return CMD_WARNING_CONFIG_FAILED;
20191 }
20192
20193 return CMD_SUCCESS;
20194 }
20195
20196 DEFUN (extcommunity_list_name_expanded,
20197 bgp_extcommunity_list_name_expanded_cmd,
20198 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20199 BGP_STR
20200 EXTCOMMUNITY_LIST_STR
20201 "Extended Community list number (expanded)\n"
20202 "Specify expanded extcommunity-list\n"
20203 "Extended Community list name\n"
20204 "Sequence number of an entry\n"
20205 "Sequence number\n"
20206 "Specify community to reject\n"
20207 "Specify community to accept\n"
20208 "An ordered list as a regular-expression\n")
20209 {
20210 int style = EXTCOMMUNITY_LIST_EXPANDED;
20211 int direct = 0;
20212 char *cl_number_or_name = NULL;
20213 char *seq = NULL;
20214 int idx = 0;
20215
20216 argv_find(argv, argc, "(100-500)", &idx);
20217 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20218 cl_number_or_name = argv[idx]->arg;
20219
20220 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20221 seq = argv[idx]->arg;
20222
20223 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20224 : COMMUNITY_DENY;
20225 argv_find(argv, argc, "LINE", &idx);
20226 char *str = argv_concat(argv, argc, idx);
20227
20228 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20229 direct, style);
20230
20231 XFREE(MTYPE_TMP, str);
20232
20233 if (ret < 0) {
20234 community_list_perror(vty, ret);
20235 return CMD_WARNING_CONFIG_FAILED;
20236 }
20237
20238 return CMD_SUCCESS;
20239 }
20240
20241 DEFUN (no_extcommunity_list_standard_all,
20242 no_bgp_extcommunity_list_standard_all_cmd,
20243 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20244 NO_STR
20245 BGP_STR
20246 EXTCOMMUNITY_LIST_STR
20247 "Extended Community list number (standard)\n"
20248 "Specify standard extcommunity-list\n"
20249 "Community list name\n"
20250 "Sequence number of an entry\n"
20251 "Sequence number\n"
20252 "Specify community to reject\n"
20253 "Specify community to accept\n"
20254 EXTCOMMUNITY_VAL_STR)
20255 {
20256 int style = EXTCOMMUNITY_LIST_STANDARD;
20257 int direct = 0;
20258 char *cl_number_or_name = NULL;
20259 char *str = NULL;
20260 char *seq = NULL;
20261 int idx = 0;
20262
20263 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20264 seq = argv[idx]->arg;
20265
20266 idx = 0;
20267 argv_find(argv, argc, "permit", &idx);
20268 argv_find(argv, argc, "deny", &idx);
20269 if (idx) {
20270 direct = argv_find(argv, argc, "permit", &idx)
20271 ? COMMUNITY_PERMIT
20272 : COMMUNITY_DENY;
20273
20274 idx = 0;
20275 argv_find(argv, argc, "AA:NN", &idx);
20276 str = argv_concat(argv, argc, idx);
20277 }
20278
20279 idx = 0;
20280 argv_find(argv, argc, "(1-99)", &idx);
20281 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20282 cl_number_or_name = argv[idx]->arg;
20283
20284 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20285 seq, direct, style);
20286
20287 XFREE(MTYPE_TMP, str);
20288
20289 if (ret < 0) {
20290 community_list_perror(vty, ret);
20291 return CMD_WARNING_CONFIG_FAILED;
20292 }
20293
20294 return CMD_SUCCESS;
20295 }
20296
20297 ALIAS(no_extcommunity_list_standard_all,
20298 no_bgp_extcommunity_list_standard_all_list_cmd,
20299 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20300 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20301 "Extended Community list number (standard)\n"
20302 "Specify standard extcommunity-list\n"
20303 "Community list name\n")
20304
20305 DEFUN (no_extcommunity_list_expanded_all,
20306 no_bgp_extcommunity_list_expanded_all_cmd,
20307 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20308 NO_STR
20309 BGP_STR
20310 EXTCOMMUNITY_LIST_STR
20311 "Extended Community list number (expanded)\n"
20312 "Specify expanded extcommunity-list\n"
20313 "Extended Community list name\n"
20314 "Sequence number of an entry\n"
20315 "Sequence number\n"
20316 "Specify community to reject\n"
20317 "Specify community to accept\n"
20318 "An ordered list as a regular-expression\n")
20319 {
20320 int style = EXTCOMMUNITY_LIST_EXPANDED;
20321 int direct = 0;
20322 char *cl_number_or_name = NULL;
20323 char *str = NULL;
20324 char *seq = NULL;
20325 int idx = 0;
20326
20327 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20328 seq = argv[idx]->arg;
20329
20330 idx = 0;
20331 argv_find(argv, argc, "permit", &idx);
20332 argv_find(argv, argc, "deny", &idx);
20333
20334 if (idx) {
20335 direct = argv_find(argv, argc, "permit", &idx)
20336 ? COMMUNITY_PERMIT
20337 : COMMUNITY_DENY;
20338
20339 idx = 0;
20340 argv_find(argv, argc, "LINE", &idx);
20341 str = argv_concat(argv, argc, idx);
20342 }
20343
20344 idx = 0;
20345 argv_find(argv, argc, "(100-500)", &idx);
20346 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20347 cl_number_or_name = argv[idx]->arg;
20348
20349 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20350 seq, direct, style);
20351
20352 XFREE(MTYPE_TMP, str);
20353
20354 if (ret < 0) {
20355 community_list_perror(vty, ret);
20356 return CMD_WARNING_CONFIG_FAILED;
20357 }
20358
20359 return CMD_SUCCESS;
20360 }
20361
20362 ALIAS(no_extcommunity_list_expanded_all,
20363 no_bgp_extcommunity_list_expanded_all_list_cmd,
20364 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20365 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20366 "Extended Community list number (expanded)\n"
20367 "Specify expanded extcommunity-list\n"
20368 "Extended Community list name\n")
20369
20370 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20371 {
20372 struct community_entry *entry;
20373
20374 for (entry = list->head; entry; entry = entry->next) {
20375 if (entry == list->head) {
20376 if (all_digit(list->name))
20377 vty_out(vty, "Extended community %s list %s\n",
20378 entry->style == EXTCOMMUNITY_LIST_STANDARD
20379 ? "standard"
20380 : "(expanded) access",
20381 list->name);
20382 else
20383 vty_out(vty,
20384 "Named extended community %s list %s\n",
20385 entry->style == EXTCOMMUNITY_LIST_STANDARD
20386 ? "standard"
20387 : "expanded",
20388 list->name);
20389 }
20390 if (entry->any)
20391 vty_out(vty, " %s\n",
20392 community_direct_str(entry->direct));
20393 else
20394 vty_out(vty, " %s %s\n",
20395 community_direct_str(entry->direct),
20396 community_list_config_str(entry));
20397 }
20398 }
20399
20400 DEFUN (show_extcommunity_list,
20401 show_bgp_extcommunity_list_cmd,
20402 "show bgp extcommunity-list",
20403 SHOW_STR
20404 BGP_STR
20405 "List extended-community list\n")
20406 {
20407 struct community_list *list;
20408 struct community_list_master *cm;
20409
20410 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20411 if (!cm)
20412 return CMD_SUCCESS;
20413
20414 for (list = cm->num.head; list; list = list->next)
20415 extcommunity_list_show(vty, list);
20416
20417 for (list = cm->str.head; list; list = list->next)
20418 extcommunity_list_show(vty, list);
20419
20420 return CMD_SUCCESS;
20421 }
20422
20423 DEFUN (show_extcommunity_list_arg,
20424 show_bgp_extcommunity_list_arg_cmd,
20425 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20426 SHOW_STR
20427 BGP_STR
20428 "List extended-community list\n"
20429 "Extcommunity-list number\n"
20430 "Extcommunity-list name\n"
20431 "Detailed information on extcommunity-list\n")
20432 {
20433 int idx_comm_list = 3;
20434 struct community_list *list;
20435
20436 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20437 EXTCOMMUNITY_LIST_MASTER);
20438 if (!list) {
20439 vty_out(vty, "%% Can't find extcommunity-list\n");
20440 return CMD_WARNING;
20441 }
20442
20443 extcommunity_list_show(vty, list);
20444
20445 return CMD_SUCCESS;
20446 }
20447
20448 /* Display community-list and extcommunity-list configuration. */
20449 static int community_list_config_write(struct vty *vty)
20450 {
20451 struct community_list *list;
20452 struct community_entry *entry;
20453 struct community_list_master *cm;
20454 int write = 0;
20455
20456 /* Community-list. */
20457 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20458
20459 for (list = cm->num.head; list; list = list->next)
20460 for (entry = list->head; entry; entry = entry->next) {
20461 vty_out(vty,
20462 "bgp community-list %s seq %" PRId64 " %s %s\n",
20463 list->name, entry->seq,
20464 community_direct_str(entry->direct),
20465 community_list_config_str(entry));
20466 write++;
20467 }
20468 for (list = cm->str.head; list; list = list->next)
20469 for (entry = list->head; entry; entry = entry->next) {
20470 vty_out(vty,
20471 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20472 entry->style == COMMUNITY_LIST_STANDARD
20473 ? "standard"
20474 : "expanded",
20475 list->name, entry->seq,
20476 community_direct_str(entry->direct),
20477 community_list_config_str(entry));
20478 write++;
20479 }
20480
20481 /* Extcommunity-list. */
20482 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20483
20484 for (list = cm->num.head; list; list = list->next)
20485 for (entry = list->head; entry; entry = entry->next) {
20486 vty_out(vty,
20487 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20488 list->name, entry->seq,
20489 community_direct_str(entry->direct),
20490 community_list_config_str(entry));
20491 write++;
20492 }
20493 for (list = cm->str.head; list; list = list->next)
20494 for (entry = list->head; entry; entry = entry->next) {
20495 vty_out(vty,
20496 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20497 entry->style == EXTCOMMUNITY_LIST_STANDARD
20498 ? "standard"
20499 : "expanded",
20500 list->name, entry->seq,
20501 community_direct_str(entry->direct),
20502 community_list_config_str(entry));
20503 write++;
20504 }
20505
20506
20507 /* lcommunity-list. */
20508 cm = community_list_master_lookup(bgp_clist,
20509 LARGE_COMMUNITY_LIST_MASTER);
20510
20511 for (list = cm->num.head; list; list = list->next)
20512 for (entry = list->head; entry; entry = entry->next) {
20513 vty_out(vty,
20514 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20515 list->name, entry->seq,
20516 community_direct_str(entry->direct),
20517 community_list_config_str(entry));
20518 write++;
20519 }
20520 for (list = cm->str.head; list; list = list->next)
20521 for (entry = list->head; entry; entry = entry->next) {
20522 vty_out(vty,
20523 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20524
20525 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20526 ? "standard"
20527 : "expanded",
20528 list->name, entry->seq, community_direct_str(entry->direct),
20529 community_list_config_str(entry));
20530 write++;
20531 }
20532
20533 return write;
20534 }
20535
20536 static int community_list_config_write(struct vty *vty);
20537 static struct cmd_node community_list_node = {
20538 .name = "community list",
20539 .node = COMMUNITY_LIST_NODE,
20540 .prompt = "",
20541 .config_write = community_list_config_write,
20542 };
20543
20544 static void community_list_vty(void)
20545 {
20546 install_node(&community_list_node);
20547
20548 /* Community-list. */
20549 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20550 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20551 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20552 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20553 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20554 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20555 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20556 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20557
20558 /* Extcommunity-list. */
20559 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20560 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20561 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20562 install_element(CONFIG_NODE,
20563 &no_bgp_extcommunity_list_standard_all_list_cmd);
20564 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20565 install_element(CONFIG_NODE,
20566 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20567 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20568 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20569
20570 /* Large Community List */
20571 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20572 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20573 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20574 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20575 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20576 install_element(CONFIG_NODE,
20577 &no_bgp_lcommunity_list_name_standard_all_cmd);
20578 install_element(CONFIG_NODE,
20579 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20580 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20581 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20582 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20583 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20584 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20585 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20586
20587 bgp_community_list_command_completion_setup();
20588 }
20589
20590 static struct cmd_node community_alias_node = {
20591 .name = "community alias",
20592 .node = COMMUNITY_ALIAS_NODE,
20593 .prompt = "",
20594 .config_write = bgp_community_alias_write,
20595 };
20596
20597 void community_alias_vty(void)
20598 {
20599 install_node(&community_alias_node);
20600
20601 /* Community-list. */
20602 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20603
20604 bgp_community_alias_command_completion_setup();
20605 }