]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Allow using remote-as the same as local-as
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_attr_evpn.h"
45 #include "bgpd/bgp_advertise.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_community_alias.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_debug.h"
54 #include "bgpd/bgp_errors.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_nht.h"
57 #include "bgpd/bgp_nexthop.h"
58 #include "bgpd/bgp_network.h"
59 #include "bgpd/bgp_open.h"
60 #include "bgpd/bgp_regex.h"
61 #include "bgpd/bgp_route.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_zebra.h"
64 #include "bgpd/bgp_table.h"
65 #include "bgpd/bgp_vty.h"
66 #include "bgpd/bgp_mpath.h"
67 #include "bgpd/bgp_packet.h"
68 #include "bgpd/bgp_updgrp.h"
69 #include "bgpd/bgp_bfd.h"
70 #include "bgpd/bgp_io.h"
71 #include "bgpd/bgp_evpn.h"
72 #include "bgpd/bgp_evpn_vty.h"
73 #include "bgpd/bgp_evpn_mh.h"
74 #include "bgpd/bgp_addpath.h"
75 #include "bgpd/bgp_mac.h"
76 #include "bgpd/bgp_flowspec.h"
77 #include "bgpd/bgp_conditional_adv.h"
78 #ifdef ENABLE_BGP_VNC
79 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
80 #endif
81
82 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
83 {
84 .val_bool = false,
85 .match_profile = "traditional",
86 .match_version = "< 7.4",
87 },
88 { .val_bool = true },
89 );
90 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
91 { .val_bool = true, .match_profile = "datacenter", },
92 { .val_bool = false },
93 );
94 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
95 { .val_bool = true, .match_profile = "datacenter", },
96 { .val_bool = false },
97 );
98 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
99 { .val_bool = true, .match_profile = "datacenter", },
100 { .val_bool = false },
101 );
102 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
103 { .val_bool = true, .match_profile = "datacenter", },
104 { .val_bool = false },
105 );
106 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
107 { .val_ulong = 10, .match_profile = "datacenter", },
108 { .val_ulong = 120 },
109 );
110 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
111 { .val_ulong = 9, .match_profile = "datacenter", },
112 { .val_ulong = 180 },
113 );
114 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
115 { .val_ulong = 3, .match_profile = "datacenter", },
116 { .val_ulong = 60 },
117 );
118 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
119 { .val_bool = false, .match_profile = "datacenter", },
120 { .val_bool = false, .match_version = "< 7.4", },
121 { .val_bool = true },
122 );
123 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
124 { .val_bool = false, .match_version = "< 7.6", },
125 { .val_bool = true },
126 );
127 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
128 { .val_bool = false, .match_version = "< 8.3", },
129 { .val_bool = true },
130 );
131 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
132 { .val_bool = false, .match_version = "< 8.3", },
133 { .val_bool = true },
134 );
135
136 DEFINE_HOOK(bgp_inst_config_write,
137 (struct bgp *bgp, struct vty *vty),
138 (bgp, vty));
139 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
140 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
141
142 static struct peer_group *listen_range_exists(struct bgp *bgp,
143 struct prefix *range, int exact);
144
145 /* Show BGP peer's information. */
146 enum show_type {
147 show_all,
148 show_peer,
149 show_ipv4_all,
150 show_ipv6_all,
151 show_ipv4_peer,
152 show_ipv6_peer
153 };
154
155 static struct peer_group *listen_range_exists(struct bgp *bgp,
156 struct prefix *range, int exact);
157
158 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
159 struct bgp *bgp,
160 bool use_json,
161 json_object *json);
162
163 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
164 enum show_type type,
165 const char *ip_str,
166 afi_t afi, bool use_json);
167
168 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
169 {
170 switch (afi) {
171 case AFI_IP:
172 switch (safi) {
173 case SAFI_UNICAST:
174 return BGP_IPV4_NODE;
175 case SAFI_MULTICAST:
176 return BGP_IPV4M_NODE;
177 case SAFI_LABELED_UNICAST:
178 return BGP_IPV4L_NODE;
179 case SAFI_MPLS_VPN:
180 return BGP_VPNV4_NODE;
181 case SAFI_FLOWSPEC:
182 return BGP_FLOWSPECV4_NODE;
183 default:
184 /* not expected */
185 return BGP_IPV4_NODE;
186 }
187 case AFI_IP6:
188 switch (safi) {
189 case SAFI_UNICAST:
190 return BGP_IPV6_NODE;
191 case SAFI_MULTICAST:
192 return BGP_IPV6M_NODE;
193 case SAFI_LABELED_UNICAST:
194 return BGP_IPV6L_NODE;
195 case SAFI_MPLS_VPN:
196 return BGP_VPNV6_NODE;
197 case SAFI_FLOWSPEC:
198 return BGP_FLOWSPECV6_NODE;
199 default:
200 /* not expected */
201 return BGP_IPV4_NODE;
202 }
203 case AFI_L2VPN:
204 return BGP_EVPN_NODE;
205 case AFI_UNSPEC:
206 case AFI_MAX:
207 // We should never be here but to clarify the switch statement..
208 return BGP_IPV4_NODE;
209 }
210
211 // Impossible to happen
212 return BGP_IPV4_NODE;
213 }
214
215 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
216 {
217 if (afi == AFI_IP) {
218 if (safi == SAFI_UNICAST)
219 return "IPv4 Unicast";
220 if (safi == SAFI_MULTICAST)
221 return "IPv4 Multicast";
222 if (safi == SAFI_LABELED_UNICAST)
223 return "IPv4 Labeled Unicast";
224 if (safi == SAFI_MPLS_VPN)
225 return "IPv4 VPN";
226 if (safi == SAFI_ENCAP)
227 return "IPv4 Encap";
228 if (safi == SAFI_FLOWSPEC)
229 return "IPv4 Flowspec";
230 } else if (afi == AFI_IP6) {
231 if (safi == SAFI_UNICAST)
232 return "IPv6 Unicast";
233 if (safi == SAFI_MULTICAST)
234 return "IPv6 Multicast";
235 if (safi == SAFI_LABELED_UNICAST)
236 return "IPv6 Labeled Unicast";
237 if (safi == SAFI_MPLS_VPN)
238 return "IPv6 VPN";
239 if (safi == SAFI_ENCAP)
240 return "IPv6 Encap";
241 if (safi == SAFI_FLOWSPEC)
242 return "IPv6 Flowspec";
243 } else if (afi == AFI_L2VPN) {
244 if (safi == SAFI_EVPN)
245 return "L2VPN EVPN";
246 }
247
248 return "Unknown";
249 }
250
251 /*
252 * Please note that we have intentionally camelCased
253 * the return strings here. So if you want
254 * to use this function, please ensure you
255 * are doing this within json output
256 */
257 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
258 {
259 if (afi == AFI_IP) {
260 if (safi == SAFI_UNICAST)
261 return "ipv4Unicast";
262 if (safi == SAFI_MULTICAST)
263 return "ipv4Multicast";
264 if (safi == SAFI_LABELED_UNICAST)
265 return "ipv4LabeledUnicast";
266 if (safi == SAFI_MPLS_VPN)
267 return "ipv4Vpn";
268 if (safi == SAFI_ENCAP)
269 return "ipv4Encap";
270 if (safi == SAFI_FLOWSPEC)
271 return "ipv4Flowspec";
272 } else if (afi == AFI_IP6) {
273 if (safi == SAFI_UNICAST)
274 return "ipv6Unicast";
275 if (safi == SAFI_MULTICAST)
276 return "ipv6Multicast";
277 if (safi == SAFI_LABELED_UNICAST)
278 return "ipv6LabeledUnicast";
279 if (safi == SAFI_MPLS_VPN)
280 return "ipv6Vpn";
281 if (safi == SAFI_ENCAP)
282 return "ipv6Encap";
283 if (safi == SAFI_FLOWSPEC)
284 return "ipv6Flowspec";
285 } else if (afi == AFI_L2VPN) {
286 if (safi == SAFI_EVPN)
287 return "l2VpnEvpn";
288 }
289
290 return "Unknown";
291 }
292
293 /* unset srv6 locator */
294 static int bgp_srv6_locator_unset(struct bgp *bgp)
295 {
296 int ret;
297 struct listnode *node, *nnode;
298 struct srv6_locator_chunk *chunk;
299 struct bgp_srv6_function *func;
300 struct bgp *bgp_vrf;
301 struct in6_addr *tovpn_sid;
302
303 /* release chunk notification via ZAPI */
304 ret = bgp_zebra_srv6_manager_release_locator_chunk(
305 bgp->srv6_locator_name);
306 if (ret < 0)
307 return -1;
308
309 /* refresh chunks */
310 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
311 listnode_delete(bgp->srv6_locator_chunks, chunk);
312 srv6_locator_chunk_free(chunk);
313 }
314
315 /* refresh functions */
316 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
317 listnode_delete(bgp->srv6_functions, func);
318 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
319 }
320
321 /* refresh tovpn_sid */
322 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
323 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
324 continue;
325
326 /* refresh vpnv4 tovpn_sid */
327 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
328 if (tovpn_sid)
329 XFREE(MTYPE_BGP_SRV6_SID,
330 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
331
332 /* refresh vpnv6 tovpn_sid */
333 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
334 if (tovpn_sid)
335 XFREE(MTYPE_BGP_SRV6_SID,
336 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
337 }
338
339 /* update vpn bgp processes */
340 vpn_leak_postchange_all();
341
342 /* refresh tovpn_sid_locator */
343 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
344 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
345 continue;
346
347 /* refresh vpnv4 tovpn_sid_locator */
348 XFREE(MTYPE_BGP_SRV6_SID,
349 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
350
351 /* refresh vpnv6 tovpn_sid_locator */
352 XFREE(MTYPE_BGP_SRV6_SID,
353 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
354 }
355
356 /* clear locator name */
357 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
358
359 return 0;
360 }
361
362 /* Utility function to get address family from current node. */
363 afi_t bgp_node_afi(struct vty *vty)
364 {
365 afi_t afi;
366 switch (vty->node) {
367 case BGP_IPV6_NODE:
368 case BGP_IPV6M_NODE:
369 case BGP_IPV6L_NODE:
370 case BGP_VPNV6_NODE:
371 case BGP_FLOWSPECV6_NODE:
372 afi = AFI_IP6;
373 break;
374 case BGP_EVPN_NODE:
375 afi = AFI_L2VPN;
376 break;
377 default:
378 afi = AFI_IP;
379 break;
380 }
381 return afi;
382 }
383
384 /* Utility function to get subsequent address family from current
385 node. */
386 safi_t bgp_node_safi(struct vty *vty)
387 {
388 safi_t safi;
389 switch (vty->node) {
390 case BGP_VPNV4_NODE:
391 case BGP_VPNV6_NODE:
392 safi = SAFI_MPLS_VPN;
393 break;
394 case BGP_IPV4M_NODE:
395 case BGP_IPV6M_NODE:
396 safi = SAFI_MULTICAST;
397 break;
398 case BGP_EVPN_NODE:
399 safi = SAFI_EVPN;
400 break;
401 case BGP_IPV4L_NODE:
402 case BGP_IPV6L_NODE:
403 safi = SAFI_LABELED_UNICAST;
404 break;
405 case BGP_FLOWSPECV4_NODE:
406 case BGP_FLOWSPECV6_NODE:
407 safi = SAFI_FLOWSPEC;
408 break;
409 default:
410 safi = SAFI_UNICAST;
411 break;
412 }
413 return safi;
414 }
415
416 /**
417 * Converts an AFI in string form to afi_t
418 *
419 * @param afi string, one of
420 * - "ipv4"
421 * - "ipv6"
422 * - "l2vpn"
423 * @return the corresponding afi_t
424 */
425 afi_t bgp_vty_afi_from_str(const char *afi_str)
426 {
427 afi_t afi = AFI_MAX; /* unknown */
428 if (strmatch(afi_str, "ipv4"))
429 afi = AFI_IP;
430 else if (strmatch(afi_str, "ipv6"))
431 afi = AFI_IP6;
432 else if (strmatch(afi_str, "l2vpn"))
433 afi = AFI_L2VPN;
434 return afi;
435 }
436
437 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
438 afi_t *afi)
439 {
440 int ret = 0;
441 if (argv_find(argv, argc, "ipv4", index)) {
442 ret = 1;
443 if (afi)
444 *afi = AFI_IP;
445 } else if (argv_find(argv, argc, "ipv6", index)) {
446 ret = 1;
447 if (afi)
448 *afi = AFI_IP6;
449 } else if (argv_find(argv, argc, "l2vpn", index)) {
450 ret = 1;
451 if (afi)
452 *afi = AFI_L2VPN;
453 }
454 return ret;
455 }
456
457 /* supports <unicast|multicast|vpn|labeled-unicast> */
458 safi_t bgp_vty_safi_from_str(const char *safi_str)
459 {
460 safi_t safi = SAFI_MAX; /* unknown */
461 if (strmatch(safi_str, "multicast"))
462 safi = SAFI_MULTICAST;
463 else if (strmatch(safi_str, "unicast"))
464 safi = SAFI_UNICAST;
465 else if (strmatch(safi_str, "vpn"))
466 safi = SAFI_MPLS_VPN;
467 else if (strmatch(safi_str, "evpn"))
468 safi = SAFI_EVPN;
469 else if (strmatch(safi_str, "labeled-unicast"))
470 safi = SAFI_LABELED_UNICAST;
471 else if (strmatch(safi_str, "flowspec"))
472 safi = SAFI_FLOWSPEC;
473 return safi;
474 }
475
476 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
477 safi_t *safi)
478 {
479 int ret = 0;
480 if (argv_find(argv, argc, "unicast", index)) {
481 ret = 1;
482 if (safi)
483 *safi = SAFI_UNICAST;
484 } else if (argv_find(argv, argc, "multicast", index)) {
485 ret = 1;
486 if (safi)
487 *safi = SAFI_MULTICAST;
488 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
489 ret = 1;
490 if (safi)
491 *safi = SAFI_LABELED_UNICAST;
492 } else if (argv_find(argv, argc, "vpn", index)) {
493 ret = 1;
494 if (safi)
495 *safi = SAFI_MPLS_VPN;
496 } else if (argv_find(argv, argc, "evpn", index)) {
497 ret = 1;
498 if (safi)
499 *safi = SAFI_EVPN;
500 } else if (argv_find(argv, argc, "flowspec", index)) {
501 ret = 1;
502 if (safi)
503 *safi = SAFI_FLOWSPEC;
504 }
505 return ret;
506 }
507
508 /*
509 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
510 *
511 * afi
512 * address-family identifier
513 *
514 * safi
515 * subsequent address-family identifier
516 *
517 * Returns:
518 * default_af string corresponding to the supplied afi/safi pair.
519 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
520 * return -1.
521 */
522 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
523 {
524 switch (afi) {
525 case AFI_IP:
526 switch (safi) {
527 case SAFI_UNICAST:
528 return "ipv4-unicast";
529 case SAFI_MULTICAST:
530 return "ipv4-multicast";
531 case SAFI_MPLS_VPN:
532 return "ipv4-vpn";
533 case SAFI_ENCAP:
534 return "ipv4-encap";
535 case SAFI_LABELED_UNICAST:
536 return "ipv4-labeled-unicast";
537 case SAFI_FLOWSPEC:
538 return "ipv4-flowspec";
539 default:
540 return "unknown-afi/safi";
541 }
542 break;
543 case AFI_IP6:
544 switch (safi) {
545 case SAFI_UNICAST:
546 return "ipv6-unicast";
547 case SAFI_MULTICAST:
548 return "ipv6-multicast";
549 case SAFI_MPLS_VPN:
550 return "ipv6-vpn";
551 case SAFI_ENCAP:
552 return "ipv6-encap";
553 case SAFI_LABELED_UNICAST:
554 return "ipv6-labeled-unicast";
555 case SAFI_FLOWSPEC:
556 return "ipv6-flowspec";
557 default:
558 return "unknown-afi/safi";
559 }
560 break;
561 case AFI_L2VPN:
562 switch (safi) {
563 case SAFI_EVPN:
564 return "l2vpn-evpn";
565 default:
566 return "unknown-afi/safi";
567 }
568 case AFI_UNSPEC:
569 case AFI_MAX:
570 return "unknown-afi/safi";
571 }
572 /* all AFIs are accounted for above, so this shouldn't happen */
573 return "unknown-afi/safi";
574 }
575
576 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
577 enum bgp_instance_type inst_type)
578 {
579 int ret = bgp_get(bgp, as, name, inst_type);
580
581 if (ret == BGP_CREATED) {
582 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
583 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
584
585 if (DFLT_BGP_IMPORT_CHECK)
586 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
587 if (DFLT_BGP_SHOW_HOSTNAME)
588 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
589 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
590 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
591 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
592 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
593 if (DFLT_BGP_DETERMINISTIC_MED)
594 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
595 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
596 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
597 if (DFLT_BGP_SUPPRESS_DUPLICATES)
598 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
599 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
600 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
601 if (DFLT_BGP_HARD_ADMIN_RESET)
602 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
603
604 ret = BGP_SUCCESS;
605 }
606 return ret;
607 }
608
609 /*
610 * bgp_vty_find_and_parse_afi_safi_bgp
611 *
612 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
613 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
614 * to appropriate values for the calling function. This is to allow the
615 * calling function to make decisions appropriate for the show command
616 * that is being parsed.
617 *
618 * The show commands are generally of the form:
619 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
620 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
621 *
622 * Since we use argv_find if the show command in particular doesn't have:
623 * [ip]
624 * [<view|vrf> VIEWVRFNAME]
625 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
626 * The command parsing should still be ok.
627 *
628 * vty -> The vty for the command so we can output some useful data in
629 * the event of a parse error in the vrf.
630 * argv -> The command tokens
631 * argc -> How many command tokens we have
632 * idx -> The current place in the command, generally should be 0 for this
633 * function
634 * afi -> The parsed afi if it was included in the show command, returned here
635 * safi -> The parsed safi if it was included in the show command, returned here
636 * bgp -> Pointer to the bgp data structure we need to fill in.
637 * use_json -> json is configured or not
638 *
639 * The function returns the correct location in the parse tree for the
640 * last token found.
641 *
642 * Returns 0 for failure to parse correctly, else the idx position of where
643 * it found the last token.
644 */
645 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
646 struct cmd_token **argv, int argc,
647 int *idx, afi_t *afi, safi_t *safi,
648 struct bgp **bgp, bool use_json)
649 {
650 char *vrf_name = NULL;
651
652 assert(afi);
653 assert(safi);
654 assert(bgp);
655
656 if (argv_find(argv, argc, "ip", idx))
657 *afi = AFI_IP;
658
659 if (argv_find(argv, argc, "view", idx))
660 vrf_name = argv[*idx + 1]->arg;
661 else if (argv_find(argv, argc, "vrf", idx)) {
662 vrf_name = argv[*idx + 1]->arg;
663 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
664 vrf_name = NULL;
665 }
666 if (vrf_name) {
667 if (strmatch(vrf_name, "all"))
668 *bgp = NULL;
669 else {
670 *bgp = bgp_lookup_by_name(vrf_name);
671 if (!*bgp) {
672 if (use_json) {
673 json_object *json = NULL;
674 json = json_object_new_object();
675 json_object_string_add(
676 json, "warning",
677 "View/Vrf is unknown");
678 vty_json(vty, json);
679 }
680 else
681 vty_out(vty, "View/Vrf %s is unknown\n",
682 vrf_name);
683 *idx = 0;
684 return 0;
685 }
686 }
687 } else {
688 *bgp = bgp_get_default();
689 if (!*bgp) {
690 if (use_json) {
691 json_object *json = NULL;
692 json = json_object_new_object();
693 json_object_string_add(
694 json, "warning",
695 "Default BGP instance not found");
696 vty_json(vty, json);
697 }
698 else
699 vty_out(vty,
700 "Default BGP instance not found\n");
701 *idx = 0;
702 return 0;
703 }
704 }
705
706 if (argv_find_and_parse_afi(argv, argc, idx, afi))
707 argv_find_and_parse_safi(argv, argc, idx, safi);
708
709 *idx += 1;
710 return *idx;
711 }
712
713 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
714 {
715 struct interface *ifp = NULL;
716 struct listnode *node;
717 struct bgp_listener *listener;
718 union sockunion all_su;
719
720 if (su->sa.sa_family == AF_INET) {
721 (void)str2sockunion("0.0.0.0", &all_su);
722 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
723 } else if (su->sa.sa_family == AF_INET6) {
724 (void)str2sockunion("::", &all_su);
725 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
726 su->sin6.sin6_scope_id,
727 bgp->vrf_id);
728 }
729
730 if (ifp) {
731 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
732 if (sockunion_family(su) !=
733 sockunion_family(&listener->su))
734 continue;
735
736 /* If 0.0.0.0/:: is a listener, then treat as self and
737 * reject.
738 */
739 if (!sockunion_cmp(&listener->su, su) ||
740 !sockunion_cmp(&listener->su, &all_su))
741 return true;
742 }
743 }
744
745 return false;
746 }
747
748 /* Utility function for looking up peer from VTY. */
749 /* This is used only for configuration, so disallow if attempted on
750 * a dynamic neighbor.
751 */
752 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
753 {
754 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
755 int ret;
756 union sockunion su;
757 struct peer *peer;
758
759 if (!bgp) {
760 return NULL;
761 }
762
763 ret = str2sockunion(ip_str, &su);
764 if (ret < 0) {
765 peer = peer_lookup_by_conf_if(bgp, ip_str);
766 if (!peer) {
767 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
768 == NULL) {
769 vty_out(vty,
770 "%% Malformed address or name: %s\n",
771 ip_str);
772 return NULL;
773 }
774 }
775 } else {
776 peer = peer_lookup(bgp, &su);
777 if (!peer) {
778 vty_out(vty,
779 "%% Specify remote-as or peer-group commands first\n");
780 return NULL;
781 }
782 if (peer_dynamic_neighbor(peer)) {
783 vty_out(vty,
784 "%% Operation not allowed on a dynamic neighbor\n");
785 return NULL;
786 }
787 }
788 return peer;
789 }
790
791 /* Utility function for looking up peer or peer group. */
792 /* This is used only for configuration, so disallow if attempted on
793 * a dynamic neighbor.
794 */
795 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
796 {
797 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
798 int ret;
799 union sockunion su;
800 struct peer *peer = NULL;
801 struct peer_group *group = NULL;
802
803 if (!bgp) {
804 return NULL;
805 }
806
807 ret = str2sockunion(peer_str, &su);
808 if (ret == 0) {
809 /* IP address, locate peer. */
810 peer = peer_lookup(bgp, &su);
811 } else {
812 /* Not IP, could match either peer configured on interface or a
813 * group. */
814 peer = peer_lookup_by_conf_if(bgp, peer_str);
815 if (!peer)
816 group = peer_group_lookup(bgp, peer_str);
817 }
818
819 if (peer) {
820 if (peer_dynamic_neighbor(peer)) {
821 vty_out(vty,
822 "%% Operation not allowed on a dynamic neighbor\n");
823 return NULL;
824 }
825
826 return peer;
827 }
828
829 if (group)
830 return group->conf;
831
832 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
833
834 return NULL;
835 }
836
837 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
838 {
839 const char *str = NULL;
840
841 switch (ret) {
842 case BGP_SUCCESS:
843 case BGP_CREATED:
844 case BGP_GR_NO_OPERATION:
845 break;
846 case BGP_ERR_INVALID_VALUE:
847 str = "Invalid value";
848 break;
849 case BGP_ERR_INVALID_FLAG:
850 str = "Invalid flag";
851 break;
852 case BGP_ERR_PEER_GROUP_SHUTDOWN:
853 str = "Peer-group has been shutdown. Activate the peer-group first";
854 break;
855 case BGP_ERR_PEER_FLAG_CONFLICT:
856 str = "Can't set override-capability and strict-capability-match at the same time";
857 break;
858 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
859 str = "Specify remote-as or peer-group remote AS first";
860 break;
861 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
862 str = "Cannot change the peer-group. Deconfigure first";
863 break;
864 case BGP_ERR_PEER_GROUP_MISMATCH:
865 str = "Peer is not a member of this peer-group";
866 break;
867 case BGP_ERR_PEER_FILTER_CONFLICT:
868 str = "Prefix/distribute list can not co-exist";
869 break;
870 case BGP_ERR_NOT_INTERNAL_PEER:
871 str = "Invalid command. Not an internal neighbor";
872 break;
873 case BGP_ERR_REMOVE_PRIVATE_AS:
874 str = "remove-private-AS cannot be configured for IBGP peers";
875 break;
876 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
877 str = "Cannot have local-as same as BGP AS number";
878 break;
879 case BGP_ERR_TCPSIG_FAILED:
880 str = "Error while applying TCP-Sig to session(s)";
881 break;
882 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
883 str = "ebgp-multihop and ttl-security cannot be configured together";
884 break;
885 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
886 str = "ttl-security only allowed for EBGP peers";
887 break;
888 case BGP_ERR_AS_OVERRIDE:
889 str = "as-override cannot be configured for IBGP peers";
890 break;
891 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
892 str = "Invalid limit for number of dynamic neighbors";
893 break;
894 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
895 str = "Dynamic neighbor listen range already exists";
896 break;
897 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
898 str = "Operation not allowed on a dynamic neighbor";
899 break;
900 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
901 str = "Operation not allowed on a directly connected neighbor";
902 break;
903 case BGP_ERR_PEER_SAFI_CONFLICT:
904 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
905 break;
906 case BGP_ERR_GR_INVALID_CMD:
907 str = "The Graceful Restart command used is not valid at this moment.";
908 break;
909 case BGP_ERR_GR_OPERATION_FAILED:
910 str = "The Graceful Restart Operation failed due to an err.";
911 break;
912 case BGP_ERR_PEER_GROUP_MEMBER:
913 str = "Peer-group member cannot override remote-as of peer-group.";
914 break;
915 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
916 str = "Peer-group members must be all internal or all external.";
917 break;
918 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
919 str = "Range specified cannot be deleted because it is not part of current config.";
920 break;
921 case BGP_ERR_INSTANCE_MISMATCH:
922 str = "Instance specified does not match the current instance.";
923 break;
924 case BGP_ERR_NO_INTERFACE_CONFIG:
925 str = "Interface specified is not being used for interface based peer.";
926 break;
927 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
928 str = "No configuration already specified for soft reconfiguration.";
929 break;
930 case BGP_ERR_AS_MISMATCH:
931 str = "BGP is already running.";
932 break;
933 case BGP_ERR_AF_UNCONFIGURED:
934 str = "AFI/SAFI specified is not currently configured.";
935 break;
936 case BGP_ERR_INVALID_AS:
937 str = "Confederation AS specified is the same AS as our AS.";
938 break;
939 case BGP_ERR_INVALID_ROLE_NAME:
940 str = "Invalid role name";
941 break;
942 case BGP_ERR_INVALID_INTERNAL_ROLE:
943 str = "External roles can be set only on eBGP session";
944 break;
945 }
946 if (str) {
947 vty_out(vty, "%% %s\n", str);
948 return CMD_WARNING_CONFIG_FAILED;
949 }
950 return CMD_SUCCESS;
951 }
952
953 /* BGP clear sort. */
954 enum clear_sort {
955 clear_all,
956 clear_peer,
957 clear_group,
958 clear_external,
959 clear_as
960 };
961
962 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
963 safi_t safi, int error)
964 {
965 switch (error) {
966 case BGP_ERR_AF_UNCONFIGURED:
967 if (vty)
968 vty_out(vty,
969 "%% BGP: Enable %s address family for the neighbor %s\n",
970 get_afi_safi_str(afi, safi, false), peer->host);
971 else
972 zlog_warn(
973 "%% BGP: Enable %s address family for the neighbor %s",
974 get_afi_safi_str(afi, safi, false), peer->host);
975 break;
976 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
977 if (vty)
978 vty_out(vty,
979 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
980 peer->host);
981 else
982 zlog_warn(
983 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
984 peer->host);
985 break;
986 default:
987 break;
988 }
989 }
990
991 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
992 struct listnode **nnode, enum bgp_clear_type stype)
993 {
994 int ret = 0;
995 struct peer_af *paf;
996
997 /* if afi/.safi not specified, spin thru all of them */
998 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
999 afi_t tmp_afi;
1000 safi_t tmp_safi;
1001 enum bgp_af_index index;
1002
1003 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1004 paf = peer->peer_af_array[index];
1005 if (!paf)
1006 continue;
1007
1008 if (paf && paf->subgroup)
1009 SET_FLAG(paf->subgroup->sflags,
1010 SUBGRP_STATUS_FORCE_UPDATES);
1011
1012 tmp_afi = paf->afi;
1013 tmp_safi = paf->safi;
1014 if (!peer->afc[tmp_afi][tmp_safi])
1015 continue;
1016
1017 if (stype == BGP_CLEAR_SOFT_NONE)
1018 ret = peer_clear(peer, nnode);
1019 else
1020 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1021 stype);
1022 }
1023 /* if afi specified and safi not, spin thru safis on this afi */
1024 } else if (safi == SAFI_UNSPEC) {
1025 safi_t tmp_safi;
1026
1027 for (tmp_safi = SAFI_UNICAST;
1028 tmp_safi < SAFI_MAX; tmp_safi++) {
1029 if (!peer->afc[afi][tmp_safi])
1030 continue;
1031
1032 paf = peer_af_find(peer, afi, tmp_safi);
1033 if (paf && paf->subgroup)
1034 SET_FLAG(paf->subgroup->sflags,
1035 SUBGRP_STATUS_FORCE_UPDATES);
1036
1037 if (stype == BGP_CLEAR_SOFT_NONE)
1038 ret = peer_clear(peer, nnode);
1039 else
1040 ret = peer_clear_soft(peer, afi,
1041 tmp_safi, stype);
1042 }
1043 /* both afi/safi specified, let the caller know if not defined */
1044 } else {
1045 if (!peer->afc[afi][safi])
1046 return 1;
1047
1048 paf = peer_af_find(peer, afi, safi);
1049 if (paf && paf->subgroup)
1050 SET_FLAG(paf->subgroup->sflags,
1051 SUBGRP_STATUS_FORCE_UPDATES);
1052
1053 if (stype == BGP_CLEAR_SOFT_NONE)
1054 ret = peer_clear(peer, nnode);
1055 else
1056 ret = peer_clear_soft(peer, afi, safi, stype);
1057 }
1058
1059 return ret;
1060 }
1061
1062 /* `clear ip bgp' functions. */
1063 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1064 enum clear_sort sort, enum bgp_clear_type stype,
1065 const char *arg)
1066 {
1067 int ret = 0;
1068 bool found = false;
1069 struct peer *peer;
1070
1071 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1072
1073 /* Clear all neighbors. */
1074 /*
1075 * Pass along pointer to next node to peer_clear() when walking all
1076 * nodes on the BGP instance as that may get freed if it is a
1077 * doppelganger
1078 */
1079 if (sort == clear_all) {
1080 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1081
1082 bgp_peer_gr_flags_update(peer);
1083
1084 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1085 gr_router_detected = true;
1086
1087 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1088 stype);
1089
1090 if (ret < 0)
1091 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1092 }
1093
1094 if (gr_router_detected
1095 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1096 bgp_zebra_send_capabilities(bgp, false);
1097 } else if (!gr_router_detected
1098 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1099 bgp_zebra_send_capabilities(bgp, true);
1100 }
1101
1102 /* This is to apply read-only mode on this clear. */
1103 if (stype == BGP_CLEAR_SOFT_NONE)
1104 bgp->update_delay_over = 0;
1105
1106 return CMD_SUCCESS;
1107 }
1108
1109 /* Clear specified neighbor. */
1110 if (sort == clear_peer) {
1111 union sockunion su;
1112
1113 /* Make sockunion for lookup. */
1114 ret = str2sockunion(arg, &su);
1115 if (ret < 0) {
1116 peer = peer_lookup_by_conf_if(bgp, arg);
1117 if (!peer) {
1118 peer = peer_lookup_by_hostname(bgp, arg);
1119 if (!peer) {
1120 vty_out(vty,
1121 "Malformed address or name: %s\n",
1122 arg);
1123 return CMD_WARNING;
1124 }
1125 }
1126 } else {
1127 peer = peer_lookup(bgp, &su);
1128 if (!peer) {
1129 vty_out(vty,
1130 "%% BGP: Unknown neighbor - \"%s\"\n",
1131 arg);
1132 return CMD_WARNING;
1133 }
1134 }
1135
1136 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1137 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1138
1139 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1140
1141 /* if afi/safi not defined for this peer, let caller know */
1142 if (ret == 1)
1143 ret = BGP_ERR_AF_UNCONFIGURED;
1144
1145 if (ret < 0)
1146 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1147
1148 return CMD_SUCCESS;
1149 }
1150
1151 /* Clear all neighbors belonging to a specific peer-group. */
1152 if (sort == clear_group) {
1153 struct peer_group *group;
1154
1155 group = peer_group_lookup(bgp, arg);
1156 if (!group) {
1157 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1158 return CMD_WARNING;
1159 }
1160
1161 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1162 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1163
1164 if (ret < 0)
1165 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1166 else
1167 found = true;
1168 }
1169
1170 if (!found)
1171 vty_out(vty,
1172 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1173 get_afi_safi_str(afi, safi, false), arg);
1174
1175 return CMD_SUCCESS;
1176 }
1177
1178 /* Clear all external (eBGP) neighbors. */
1179 if (sort == clear_external) {
1180 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1181 if (peer->sort == BGP_PEER_IBGP)
1182 continue;
1183
1184 bgp_peer_gr_flags_update(peer);
1185
1186 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1187 gr_router_detected = true;
1188
1189 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1190
1191 if (ret < 0)
1192 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1193 else
1194 found = true;
1195 }
1196
1197 if (gr_router_detected
1198 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1199 bgp_zebra_send_capabilities(bgp, false);
1200 } else if (!gr_router_detected
1201 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1202 bgp_zebra_send_capabilities(bgp, true);
1203 }
1204
1205 if (!found)
1206 vty_out(vty,
1207 "%% BGP: No external %s peer is configured\n",
1208 get_afi_safi_str(afi, safi, false));
1209
1210 return CMD_SUCCESS;
1211 }
1212
1213 /* Clear all neighbors belonging to a specific AS. */
1214 if (sort == clear_as) {
1215 as_t as = strtoul(arg, NULL, 10);
1216
1217 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1218 if (peer->as != as)
1219 continue;
1220
1221 bgp_peer_gr_flags_update(peer);
1222
1223 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1224 gr_router_detected = true;
1225
1226 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1227
1228 if (ret < 0)
1229 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1230 else
1231 found = true;
1232 }
1233
1234 if (gr_router_detected
1235 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1236 bgp_zebra_send_capabilities(bgp, false);
1237 } else if (!gr_router_detected
1238 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1239 bgp_zebra_send_capabilities(bgp, true);
1240 }
1241
1242 if (!found)
1243 vty_out(vty,
1244 "%% BGP: No %s peer is configured with AS %s\n",
1245 get_afi_safi_str(afi, safi, false), arg);
1246
1247 return CMD_SUCCESS;
1248 }
1249
1250 return CMD_SUCCESS;
1251 }
1252
1253 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1254 safi_t safi, enum clear_sort sort,
1255 enum bgp_clear_type stype, const char *arg)
1256 {
1257 struct bgp *bgp;
1258
1259 /* BGP structure lookup. */
1260 if (name) {
1261 bgp = bgp_lookup_by_name(name);
1262 if (bgp == NULL) {
1263 vty_out(vty, "Can't find BGP instance %s\n", name);
1264 return CMD_WARNING;
1265 }
1266 } else {
1267 bgp = bgp_get_default();
1268 if (bgp == NULL) {
1269 vty_out(vty, "No BGP process is configured\n");
1270 return CMD_WARNING;
1271 }
1272 }
1273
1274 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1275 }
1276
1277 /* clear soft inbound */
1278 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1279 {
1280 afi_t afi;
1281 safi_t safi;
1282
1283 FOREACH_AFI_SAFI (afi, safi)
1284 bgp_clear_vty(vty, name, afi, safi, clear_all,
1285 BGP_CLEAR_SOFT_IN, NULL);
1286 }
1287
1288 /* clear soft outbound */
1289 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1290 {
1291 afi_t afi;
1292 safi_t safi;
1293
1294 FOREACH_AFI_SAFI (afi, safi)
1295 bgp_clear_vty(vty, name, afi, safi, clear_all,
1296 BGP_CLEAR_SOFT_OUT, NULL);
1297 }
1298
1299
1300 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1301 {
1302 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1303 }
1304
1305 #ifndef VTYSH_EXTRACT_PL
1306 #include "bgpd/bgp_vty_clippy.c"
1307 #endif
1308
1309 DEFUN_HIDDEN (bgp_local_mac,
1310 bgp_local_mac_cmd,
1311 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1312 BGP_STR
1313 "Local MAC config\n"
1314 "VxLAN Network Identifier\n"
1315 "VNI number\n"
1316 "local mac\n"
1317 "mac address\n"
1318 "mac-mobility sequence\n"
1319 "seq number\n")
1320 {
1321 int rv;
1322 vni_t vni;
1323 struct ethaddr mac;
1324 struct ipaddr ip;
1325 uint32_t seq;
1326 struct bgp *bgp;
1327
1328 vni = strtoul(argv[3]->arg, NULL, 10);
1329 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1330 vty_out(vty, "%% Malformed MAC address\n");
1331 return CMD_WARNING;
1332 }
1333 memset(&ip, 0, sizeof(ip));
1334 seq = strtoul(argv[7]->arg, NULL, 10);
1335
1336 bgp = bgp_get_default();
1337 if (!bgp) {
1338 vty_out(vty, "Default BGP instance is not there\n");
1339 return CMD_WARNING;
1340 }
1341
1342 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1343 zero_esi);
1344 if (rv < 0) {
1345 vty_out(vty, "Internal error\n");
1346 return CMD_WARNING;
1347 }
1348
1349 return CMD_SUCCESS;
1350 }
1351
1352 DEFUN_HIDDEN (no_bgp_local_mac,
1353 no_bgp_local_mac_cmd,
1354 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1355 NO_STR
1356 BGP_STR
1357 "Local MAC config\n"
1358 "VxLAN Network Identifier\n"
1359 "VNI number\n"
1360 "local mac\n"
1361 "mac address\n")
1362 {
1363 int rv;
1364 vni_t vni;
1365 struct ethaddr mac;
1366 struct ipaddr ip;
1367 struct bgp *bgp;
1368
1369 vni = strtoul(argv[4]->arg, NULL, 10);
1370 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1371 vty_out(vty, "%% Malformed MAC address\n");
1372 return CMD_WARNING;
1373 }
1374 memset(&ip, 0, sizeof(ip));
1375
1376 bgp = bgp_get_default();
1377 if (!bgp) {
1378 vty_out(vty, "Default BGP instance is not there\n");
1379 return CMD_WARNING;
1380 }
1381
1382 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1383 if (rv < 0) {
1384 vty_out(vty, "Internal error\n");
1385 return CMD_WARNING;
1386 }
1387
1388 return CMD_SUCCESS;
1389 }
1390
1391 DEFUN (no_synchronization,
1392 no_synchronization_cmd,
1393 "no synchronization",
1394 NO_STR
1395 "Perform IGP synchronization\n")
1396 {
1397 return CMD_SUCCESS;
1398 }
1399
1400 DEFUN (no_auto_summary,
1401 no_auto_summary_cmd,
1402 "no auto-summary",
1403 NO_STR
1404 "Enable automatic network number summarization\n")
1405 {
1406 return CMD_SUCCESS;
1407 }
1408
1409 /* "router bgp" commands. */
1410 DEFUN_NOSH (router_bgp,
1411 router_bgp_cmd,
1412 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1413 ROUTER_STR
1414 BGP_STR
1415 AS_STR
1416 BGP_INSTANCE_HELP_STR)
1417 {
1418 int idx_asn = 2;
1419 int idx_view_vrf = 3;
1420 int idx_vrf = 4;
1421 int is_new_bgp = 0;
1422 int ret;
1423 as_t as;
1424 struct bgp *bgp;
1425 const char *name = NULL;
1426 enum bgp_instance_type inst_type;
1427
1428 // "router bgp" without an ASN
1429 if (argc == 2) {
1430 // Pending: Make VRF option available for ASN less config
1431 bgp = bgp_get_default();
1432
1433 if (bgp == NULL) {
1434 vty_out(vty, "%% No BGP process is configured\n");
1435 return CMD_WARNING_CONFIG_FAILED;
1436 }
1437
1438 if (listcount(bm->bgp) > 1) {
1439 vty_out(vty, "%% Please specify ASN and VRF\n");
1440 return CMD_WARNING_CONFIG_FAILED;
1441 }
1442 }
1443
1444 // "router bgp X"
1445 else {
1446 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1447
1448 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1449 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1450 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1451
1452 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1453 if (argc > 3) {
1454 name = argv[idx_vrf]->arg;
1455
1456 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1457 if (strmatch(name, VRF_DEFAULT_NAME))
1458 name = NULL;
1459 else
1460 inst_type = BGP_INSTANCE_TYPE_VRF;
1461 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1462 inst_type = BGP_INSTANCE_TYPE_VIEW;
1463 }
1464
1465 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1466 is_new_bgp = (bgp_lookup(as, name) == NULL);
1467
1468 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1469 switch (ret) {
1470 case BGP_ERR_AS_MISMATCH:
1471 vty_out(vty, "BGP is already running; AS is %u\n", as);
1472 return CMD_WARNING_CONFIG_FAILED;
1473 case BGP_ERR_INSTANCE_MISMATCH:
1474 vty_out(vty,
1475 "BGP instance name and AS number mismatch\n");
1476 vty_out(vty,
1477 "BGP instance is already running; AS is %u\n",
1478 as);
1479 return CMD_WARNING_CONFIG_FAILED;
1480 }
1481
1482 /*
1483 * If we just instantiated the default instance, complete
1484 * any pending VRF-VPN leaking that was configured via
1485 * earlier "router bgp X vrf FOO" blocks.
1486 */
1487 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1488 vpn_leak_postchange_all();
1489
1490 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1491 bgp_vpn_leak_export(bgp);
1492 /* Pending: handle when user tries to change a view to vrf n vv.
1493 */
1494 }
1495
1496 /* unset the auto created flag as the user config is now present */
1497 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1498 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1499
1500 return CMD_SUCCESS;
1501 }
1502
1503 /* "no router bgp" commands. */
1504 DEFUN (no_router_bgp,
1505 no_router_bgp_cmd,
1506 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1507 NO_STR
1508 ROUTER_STR
1509 BGP_STR
1510 AS_STR
1511 BGP_INSTANCE_HELP_STR)
1512 {
1513 int idx_asn = 3;
1514 int idx_vrf = 5;
1515 as_t as;
1516 struct bgp *bgp;
1517 const char *name = NULL;
1518
1519 // "no router bgp" without an ASN
1520 if (argc == 3) {
1521 // Pending: Make VRF option available for ASN less config
1522 bgp = bgp_get_default();
1523
1524 if (bgp == NULL) {
1525 vty_out(vty, "%% No BGP process is configured\n");
1526 return CMD_WARNING_CONFIG_FAILED;
1527 }
1528
1529 if (listcount(bm->bgp) > 1) {
1530 vty_out(vty, "%% Please specify ASN and VRF\n");
1531 return CMD_WARNING_CONFIG_FAILED;
1532 }
1533
1534 if (bgp->l3vni) {
1535 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1536 bgp->l3vni);
1537 return CMD_WARNING_CONFIG_FAILED;
1538 }
1539 } else {
1540 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1541
1542 if (argc > 4) {
1543 name = argv[idx_vrf]->arg;
1544 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1545 && strmatch(name, VRF_DEFAULT_NAME))
1546 name = NULL;
1547 }
1548
1549 /* Lookup bgp structure. */
1550 bgp = bgp_lookup(as, name);
1551 if (!bgp) {
1552 vty_out(vty, "%% Can't find BGP instance\n");
1553 return CMD_WARNING_CONFIG_FAILED;
1554 }
1555
1556 if (bgp->l3vni) {
1557 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1558 bgp->l3vni);
1559 return CMD_WARNING_CONFIG_FAILED;
1560 }
1561
1562 /* Cannot delete default instance if vrf instances exist */
1563 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1564 struct listnode *node;
1565 struct bgp *tmp_bgp;
1566
1567 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1568 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1569 continue;
1570 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1571 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1572 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1573 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1574 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1575 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1576 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1577 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1578 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1579 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1580 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1581 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1582 (bgp == bgp_get_evpn() &&
1583 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1584 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1585 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1586 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1587 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1588 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1589 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1590 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1591 (hashcount(tmp_bgp->vnihash))) {
1592 vty_out(vty,
1593 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1594 return CMD_WARNING_CONFIG_FAILED;
1595 }
1596 }
1597 }
1598 }
1599
1600 bgp_delete(bgp);
1601
1602 return CMD_SUCCESS;
1603 }
1604
1605 /* bgp session-dscp */
1606
1607 DEFPY (bgp_session_dscp,
1608 bgp_session_dscp_cmd,
1609 "bgp session-dscp (0-63)$dscp",
1610 BGP_STR
1611 "Override default (C6) bgp TCP session DSCP value\n"
1612 "Manually configured dscp parameter\n")
1613 {
1614 bm->tcp_dscp = dscp << 2;
1615
1616 return CMD_SUCCESS;
1617 }
1618
1619 DEFPY (no_bgp_session_dscp,
1620 no_bgp_session_dscp_cmd,
1621 "no bgp session-dscp [(0-63)]",
1622 NO_STR
1623 BGP_STR
1624 "Override default (C6) bgp TCP session DSCP value\n"
1625 "Manually configured dscp parameter\n")
1626 {
1627 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1628
1629 return CMD_SUCCESS;
1630 }
1631
1632 /* BGP router-id. */
1633
1634 DEFPY (bgp_router_id,
1635 bgp_router_id_cmd,
1636 "bgp router-id A.B.C.D",
1637 BGP_STR
1638 "Override configured router identifier\n"
1639 "Manually configured router identifier\n")
1640 {
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642 bgp_router_id_static_set(bgp, router_id);
1643 return CMD_SUCCESS;
1644 }
1645
1646 DEFPY (no_bgp_router_id,
1647 no_bgp_router_id_cmd,
1648 "no bgp router-id [A.B.C.D]",
1649 NO_STR
1650 BGP_STR
1651 "Override configured router identifier\n"
1652 "Manually configured router identifier\n")
1653 {
1654 VTY_DECLVAR_CONTEXT(bgp, bgp);
1655
1656 if (router_id_str) {
1657 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1658 vty_out(vty, "%% BGP router-id doesn't match\n");
1659 return CMD_WARNING_CONFIG_FAILED;
1660 }
1661 }
1662
1663 router_id.s_addr = 0;
1664 bgp_router_id_static_set(bgp, router_id);
1665
1666 return CMD_SUCCESS;
1667 }
1668
1669 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1670 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1671 NO_STR BGP_STR
1672 "Add community specific parameters\n"
1673 "Create an alias for a community\n"
1674 "Community (AA:BB or AA:BB:CC)\n"
1675 "Alias name\n")
1676 {
1677 struct community_alias ca = {};
1678 struct community_alias *lookup_community;
1679 struct community_alias *lookup_alias;
1680 struct community *comm;
1681 struct lcommunity *lcomm;
1682 uint8_t invalid = 0;
1683
1684 comm = community_str2com(community);
1685 if (!comm)
1686 invalid++;
1687 community_free(&comm);
1688
1689 lcomm = lcommunity_str2com(community);
1690 if (!lcomm)
1691 invalid++;
1692 lcommunity_free(&lcomm);
1693
1694 if (invalid > 1) {
1695 vty_out(vty, "Invalid community format\n");
1696 return CMD_WARNING;
1697 }
1698
1699 strlcpy(ca.community, community, sizeof(ca.community));
1700 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1701
1702 lookup_community = bgp_ca_community_lookup(&ca);
1703 lookup_alias = bgp_ca_alias_lookup(&ca);
1704
1705 if (no) {
1706 bgp_ca_alias_delete(&ca);
1707 bgp_ca_community_delete(&ca);
1708 } else {
1709 if (lookup_alias) {
1710 /* Lookup if community hash table has an item
1711 * with the same alias name.
1712 */
1713 strlcpy(ca.community, lookup_alias->community,
1714 sizeof(ca.community));
1715 if (bgp_ca_community_lookup(&ca)) {
1716 vty_out(vty,
1717 "community (%s) already has this alias (%s)\n",
1718 lookup_alias->community,
1719 lookup_alias->alias);
1720 return CMD_WARNING;
1721 }
1722 bgp_ca_alias_delete(&ca);
1723 }
1724
1725 if (lookup_community) {
1726 /* Lookup if alias hash table has an item
1727 * with the same community.
1728 */
1729 strlcpy(ca.alias, lookup_community->alias,
1730 sizeof(ca.alias));
1731 if (bgp_ca_alias_lookup(&ca)) {
1732 vty_out(vty,
1733 "alias (%s) already has this community (%s)\n",
1734 lookup_community->alias,
1735 lookup_community->community);
1736 return CMD_WARNING;
1737 }
1738 bgp_ca_community_delete(&ca);
1739 }
1740
1741 bgp_ca_alias_insert(&ca);
1742 bgp_ca_community_insert(&ca);
1743 }
1744
1745 return CMD_SUCCESS;
1746 }
1747
1748 DEFPY (bgp_global_suppress_fib_pending,
1749 bgp_global_suppress_fib_pending_cmd,
1750 "[no] bgp suppress-fib-pending",
1751 NO_STR
1752 BGP_STR
1753 "Advertise only routes that are programmed in kernel to peers globally\n")
1754 {
1755 bm_wait_for_fib_set(!no);
1756
1757 return CMD_SUCCESS;
1758 }
1759
1760 DEFPY (bgp_suppress_fib_pending,
1761 bgp_suppress_fib_pending_cmd,
1762 "[no] bgp suppress-fib-pending",
1763 NO_STR
1764 BGP_STR
1765 "Advertise only routes that are programmed in kernel to peers\n")
1766 {
1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768
1769 bgp_suppress_fib_pending_set(bgp, !no);
1770 return CMD_SUCCESS;
1771 }
1772
1773
1774 /* BGP Cluster ID. */
1775 DEFUN (bgp_cluster_id,
1776 bgp_cluster_id_cmd,
1777 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1778 BGP_STR
1779 "Configure Route-Reflector Cluster-id\n"
1780 "Route-Reflector Cluster-id in IP address format\n"
1781 "Route-Reflector Cluster-id as 32 bit quantity\n")
1782 {
1783 VTY_DECLVAR_CONTEXT(bgp, bgp);
1784 int idx_ipv4 = 2;
1785 int ret;
1786 struct in_addr cluster;
1787
1788 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1789 if (!ret) {
1790 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1791 return CMD_WARNING_CONFIG_FAILED;
1792 }
1793
1794 bgp_cluster_id_set(bgp, &cluster);
1795 bgp_clear_star_soft_out(vty, bgp->name);
1796
1797 return CMD_SUCCESS;
1798 }
1799
1800 DEFUN (no_bgp_cluster_id,
1801 no_bgp_cluster_id_cmd,
1802 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1803 NO_STR
1804 BGP_STR
1805 "Configure Route-Reflector Cluster-id\n"
1806 "Route-Reflector Cluster-id in IP address format\n"
1807 "Route-Reflector Cluster-id as 32 bit quantity\n")
1808 {
1809 VTY_DECLVAR_CONTEXT(bgp, bgp);
1810 bgp_cluster_id_unset(bgp);
1811 bgp_clear_star_soft_out(vty, bgp->name);
1812
1813 return CMD_SUCCESS;
1814 }
1815
1816 DEFPY (bgp_norib,
1817 bgp_norib_cmd,
1818 "bgp no-rib",
1819 BGP_STR
1820 "Disable BGP route installation to RIB (Zebra)\n")
1821 {
1822 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1823 vty_out(vty,
1824 "%% No-RIB option is already set, nothing to do here.\n");
1825 return CMD_SUCCESS;
1826 }
1827
1828 bgp_option_norib_set_runtime();
1829
1830 return CMD_SUCCESS;
1831 }
1832
1833 DEFPY (no_bgp_norib,
1834 no_bgp_norib_cmd,
1835 "no bgp no-rib",
1836 NO_STR
1837 BGP_STR
1838 "Disable BGP route installation to RIB (Zebra)\n")
1839 {
1840 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1841 vty_out(vty,
1842 "%% No-RIB option is not set, nothing to do here.\n");
1843 return CMD_SUCCESS;
1844 }
1845
1846 bgp_option_norib_unset_runtime();
1847
1848 return CMD_SUCCESS;
1849 }
1850
1851 DEFPY (no_bgp_send_extra_data,
1852 no_bgp_send_extra_data_cmd,
1853 "[no] bgp send-extra-data zebra",
1854 NO_STR
1855 BGP_STR
1856 "Extra data to Zebra for display/use\n"
1857 "To zebra\n")
1858 {
1859 if (no)
1860 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1861 else
1862 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1863
1864 return CMD_SUCCESS;
1865 }
1866
1867 DEFUN (bgp_confederation_identifier,
1868 bgp_confederation_identifier_cmd,
1869 "bgp confederation identifier (1-4294967295)",
1870 BGP_STR
1871 "AS confederation parameters\n"
1872 "AS number\n"
1873 "Set routing domain confederation AS\n")
1874 {
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876 int idx_number = 3;
1877 as_t as;
1878
1879 as = strtoul(argv[idx_number]->arg, NULL, 10);
1880
1881 bgp_confederation_id_set(bgp, as);
1882
1883 return CMD_SUCCESS;
1884 }
1885
1886 DEFUN (no_bgp_confederation_identifier,
1887 no_bgp_confederation_identifier_cmd,
1888 "no bgp confederation identifier [(1-4294967295)]",
1889 NO_STR
1890 BGP_STR
1891 "AS confederation parameters\n"
1892 "AS number\n"
1893 "Set routing domain confederation AS\n")
1894 {
1895 VTY_DECLVAR_CONTEXT(bgp, bgp);
1896 bgp_confederation_id_unset(bgp);
1897
1898 return CMD_SUCCESS;
1899 }
1900
1901 DEFUN (bgp_confederation_peers,
1902 bgp_confederation_peers_cmd,
1903 "bgp confederation peers (1-4294967295)...",
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 = 3;
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 if (bgp->as == as) {
1918 vty_out(vty,
1919 "%% Local member-AS not allowed in confed peer list\n");
1920 continue;
1921 }
1922
1923 bgp_confederation_peers_add(bgp, as);
1924 }
1925 return CMD_SUCCESS;
1926 }
1927
1928 DEFUN (no_bgp_confederation_peers,
1929 no_bgp_confederation_peers_cmd,
1930 "no bgp confederation peers (1-4294967295)...",
1931 NO_STR
1932 BGP_STR
1933 "AS confederation parameters\n"
1934 "Peer ASs in BGP confederation\n"
1935 AS_STR)
1936 {
1937 VTY_DECLVAR_CONTEXT(bgp, bgp);
1938 int idx_asn = 4;
1939 as_t as;
1940 int i;
1941
1942 for (i = idx_asn; i < argc; i++) {
1943 as = strtoul(argv[i]->arg, NULL, 10);
1944
1945 bgp_confederation_peers_remove(bgp, as);
1946 }
1947 return CMD_SUCCESS;
1948 }
1949
1950 /**
1951 * Central routine for maximum-paths configuration.
1952 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1953 * @set: 1 for setting values, 0 for removing the max-paths config.
1954 */
1955 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1956 const char *mpaths, uint16_t options,
1957 int set)
1958 {
1959 VTY_DECLVAR_CONTEXT(bgp, bgp);
1960 uint16_t maxpaths = 0;
1961 int ret;
1962 afi_t afi;
1963 safi_t safi;
1964
1965 afi = bgp_node_afi(vty);
1966 safi = bgp_node_safi(vty);
1967
1968 if (set) {
1969 maxpaths = strtol(mpaths, NULL, 10);
1970 if (maxpaths > multipath_num) {
1971 vty_out(vty,
1972 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1973 maxpaths, multipath_num);
1974 return CMD_WARNING_CONFIG_FAILED;
1975 }
1976 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1977 options);
1978 } else
1979 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1980
1981 if (ret < 0) {
1982 vty_out(vty,
1983 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1984 (set == 1) ? "" : "un",
1985 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1986 maxpaths, afi, safi);
1987 return CMD_WARNING_CONFIG_FAILED;
1988 }
1989
1990 bgp_recalculate_all_bestpaths(bgp);
1991
1992 return CMD_SUCCESS;
1993 }
1994
1995 DEFUN (bgp_maxmed_admin,
1996 bgp_maxmed_admin_cmd,
1997 "bgp max-med administrative ",
1998 BGP_STR
1999 "Advertise routes with max-med\n"
2000 "Administratively applied, for an indefinite period\n")
2001 {
2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003
2004 bgp->v_maxmed_admin = 1;
2005 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2006
2007 bgp_maxmed_update(bgp);
2008
2009 return CMD_SUCCESS;
2010 }
2011
2012 DEFUN (bgp_maxmed_admin_medv,
2013 bgp_maxmed_admin_medv_cmd,
2014 "bgp max-med administrative (0-4294967295)",
2015 BGP_STR
2016 "Advertise routes with max-med\n"
2017 "Administratively applied, for an indefinite period\n"
2018 "Max MED value to be used\n")
2019 {
2020 VTY_DECLVAR_CONTEXT(bgp, bgp);
2021 int idx_number = 3;
2022
2023 bgp->v_maxmed_admin = 1;
2024 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2025
2026 bgp_maxmed_update(bgp);
2027
2028 return CMD_SUCCESS;
2029 }
2030
2031 DEFUN (no_bgp_maxmed_admin,
2032 no_bgp_maxmed_admin_cmd,
2033 "no bgp max-med administrative [(0-4294967295)]",
2034 NO_STR
2035 BGP_STR
2036 "Advertise routes with max-med\n"
2037 "Administratively applied, for an indefinite period\n"
2038 "Max MED value to be used\n")
2039 {
2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2042 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2043 bgp_maxmed_update(bgp);
2044
2045 return CMD_SUCCESS;
2046 }
2047
2048 DEFUN (bgp_maxmed_onstartup,
2049 bgp_maxmed_onstartup_cmd,
2050 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2051 BGP_STR
2052 "Advertise routes with max-med\n"
2053 "Effective on a startup\n"
2054 "Time (seconds) period for max-med\n"
2055 "Max MED value to be used\n")
2056 {
2057 VTY_DECLVAR_CONTEXT(bgp, bgp);
2058 int idx = 0;
2059
2060 if (argv_find(argv, argc, "(5-86400)", &idx))
2061 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2062 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2063 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2064 else
2065 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2066
2067 bgp_maxmed_update(bgp);
2068
2069 return CMD_SUCCESS;
2070 }
2071
2072 DEFUN (no_bgp_maxmed_onstartup,
2073 no_bgp_maxmed_onstartup_cmd,
2074 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2075 NO_STR
2076 BGP_STR
2077 "Advertise routes with max-med\n"
2078 "Effective on a startup\n"
2079 "Time (seconds) period for max-med\n"
2080 "Max MED value to be used\n")
2081 {
2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083
2084 /* Cancel max-med onstartup if its on */
2085 if (bgp->t_maxmed_onstartup) {
2086 THREAD_OFF(bgp->t_maxmed_onstartup);
2087 bgp->maxmed_onstartup_over = 1;
2088 }
2089
2090 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2091 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2092
2093 bgp_maxmed_update(bgp);
2094
2095 return CMD_SUCCESS;
2096 }
2097
2098 static int bgp_global_update_delay_config_vty(struct vty *vty,
2099 uint16_t update_delay,
2100 uint16_t establish_wait)
2101 {
2102 struct listnode *node, *nnode;
2103 struct bgp *bgp;
2104 bool vrf_cfg = false;
2105
2106 /*
2107 * See if update-delay is set per-vrf and warn user to delete it
2108 * Note that we only need to check this if this is the first time
2109 * setting the global config.
2110 */
2111 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2112 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2113 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2114 vty_out(vty,
2115 "%% update-delay configuration found in vrf %s\n",
2116 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2117 ? VRF_DEFAULT_NAME
2118 : bgp->name);
2119 vrf_cfg = true;
2120 }
2121 }
2122 }
2123
2124 if (vrf_cfg) {
2125 vty_out(vty,
2126 "%%Failed: global update-delay config not permitted\n");
2127 return CMD_WARNING;
2128 }
2129
2130 if (!establish_wait) { /* update-delay <delay> */
2131 bm->v_update_delay = update_delay;
2132 bm->v_establish_wait = bm->v_update_delay;
2133 } else {
2134 /* update-delay <delay> <establish-wait> */
2135 if (update_delay < establish_wait) {
2136 vty_out(vty,
2137 "%%Failed: update-delay less than the establish-wait!\n");
2138 return CMD_WARNING_CONFIG_FAILED;
2139 }
2140
2141 bm->v_update_delay = update_delay;
2142 bm->v_establish_wait = establish_wait;
2143 }
2144
2145 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2146 bgp->v_update_delay = bm->v_update_delay;
2147 bgp->v_establish_wait = bm->v_establish_wait;
2148 }
2149
2150 return CMD_SUCCESS;
2151 }
2152
2153 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2154 {
2155 struct listnode *node, *nnode;
2156 struct bgp *bgp;
2157
2158 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2159 bm->v_establish_wait = bm->v_update_delay;
2160
2161 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2162 bgp->v_update_delay = bm->v_update_delay;
2163 bgp->v_establish_wait = bm->v_establish_wait;
2164 }
2165
2166 return CMD_SUCCESS;
2167 }
2168
2169 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2170 uint16_t establish_wait)
2171 {
2172 VTY_DECLVAR_CONTEXT(bgp, bgp);
2173
2174 /* if configured globally, per-instance config is not allowed */
2175 if (bm->v_update_delay) {
2176 vty_out(vty,
2177 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2178 return CMD_WARNING_CONFIG_FAILED;
2179 }
2180
2181
2182 if (!establish_wait) /* update-delay <delay> */
2183 {
2184 bgp->v_update_delay = update_delay;
2185 bgp->v_establish_wait = bgp->v_update_delay;
2186 return CMD_SUCCESS;
2187 }
2188
2189 /* update-delay <delay> <establish-wait> */
2190 if (update_delay < establish_wait) {
2191 vty_out(vty,
2192 "%%Failed: update-delay less than the establish-wait!\n");
2193 return CMD_WARNING_CONFIG_FAILED;
2194 }
2195
2196 bgp->v_update_delay = update_delay;
2197 bgp->v_establish_wait = establish_wait;
2198
2199 return CMD_SUCCESS;
2200 }
2201
2202 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2203 {
2204 VTY_DECLVAR_CONTEXT(bgp, bgp);
2205
2206 /* If configured globally, cannot remove from one bgp instance */
2207 if (bm->v_update_delay) {
2208 vty_out(vty,
2209 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2210 return CMD_WARNING_CONFIG_FAILED;
2211 }
2212 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2213 bgp->v_establish_wait = bgp->v_update_delay;
2214
2215 return CMD_SUCCESS;
2216 }
2217
2218 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2219 {
2220 /* If configured globally, no need to display per-instance value */
2221 if (bgp->v_update_delay != bm->v_update_delay) {
2222 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2223 if (bgp->v_update_delay != bgp->v_establish_wait)
2224 vty_out(vty, " %d", bgp->v_establish_wait);
2225 vty_out(vty, "\n");
2226 }
2227 }
2228
2229 /* Global update-delay configuration */
2230 DEFPY (bgp_global_update_delay,
2231 bgp_global_update_delay_cmd,
2232 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2233 BGP_STR
2234 "Force initial delay for best-path and updates for all bgp instances\n"
2235 "Max delay in seconds\n"
2236 "Establish wait in seconds\n")
2237 {
2238 return bgp_global_update_delay_config_vty(vty, delay, wait);
2239 }
2240
2241 /* Global update-delay deconfiguration */
2242 DEFPY (no_bgp_global_update_delay,
2243 no_bgp_global_update_delay_cmd,
2244 "no bgp update-delay [(0-3600) [(1-3600)]]",
2245 NO_STR
2246 BGP_STR
2247 "Force initial delay for best-path and updates\n"
2248 "Max delay in seconds\n"
2249 "Establish wait in seconds\n")
2250 {
2251 return bgp_global_update_delay_deconfig_vty(vty);
2252 }
2253
2254 /* Update-delay configuration */
2255
2256 DEFPY (bgp_update_delay,
2257 bgp_update_delay_cmd,
2258 "update-delay (0-3600)$delay [(1-3600)$wait]",
2259 "Force initial delay for best-path and updates\n"
2260 "Max delay in seconds\n"
2261 "Establish wait in seconds\n")
2262 {
2263 return bgp_update_delay_config_vty(vty, delay, wait);
2264 }
2265
2266 /* Update-delay deconfiguration */
2267 DEFPY (no_bgp_update_delay,
2268 no_bgp_update_delay_cmd,
2269 "no update-delay [(0-3600) [(1-3600)]]",
2270 NO_STR
2271 "Force initial delay for best-path and updates\n"
2272 "Max delay in seconds\n"
2273 "Establish wait in seconds\n")
2274 {
2275 return bgp_update_delay_deconfig_vty(vty);
2276 }
2277
2278
2279 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2280 bool set)
2281 {
2282 VTY_DECLVAR_CONTEXT(bgp, bgp);
2283
2284 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2285 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2286
2287 return CMD_SUCCESS;
2288 }
2289
2290 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2291 bool set)
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294
2295 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2296 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2297
2298 return CMD_SUCCESS;
2299 }
2300
2301 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2302 {
2303 uint32_t quanta =
2304 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2305 if (quanta != BGP_WRITE_PACKET_MAX)
2306 vty_out(vty, " write-quanta %d\n", quanta);
2307 }
2308
2309 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2310 {
2311 uint32_t quanta =
2312 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2313 if (quanta != BGP_READ_PACKET_MAX)
2314 vty_out(vty, " read-quanta %d\n", quanta);
2315 }
2316
2317 /* Packet quanta configuration
2318 *
2319 * XXX: The value set here controls the size of a stack buffer in the IO
2320 * thread. When changing these limits be careful to prevent stack overflow.
2321 *
2322 * Furthermore, the maximums used here should correspond to
2323 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2324 */
2325 DEFPY (bgp_wpkt_quanta,
2326 bgp_wpkt_quanta_cmd,
2327 "[no] write-quanta (1-64)$quanta",
2328 NO_STR
2329 "How many packets to write to peer socket per run\n"
2330 "Number of packets\n")
2331 {
2332 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2333 }
2334
2335 DEFPY (bgp_rpkt_quanta,
2336 bgp_rpkt_quanta_cmd,
2337 "[no] read-quanta (1-10)$quanta",
2338 NO_STR
2339 "How many packets to read from peer socket per I/O cycle\n"
2340 "Number of packets\n")
2341 {
2342 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2343 }
2344
2345 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2346 {
2347 if (!bgp->heuristic_coalesce)
2348 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2349 }
2350
2351
2352 DEFUN (bgp_coalesce_time,
2353 bgp_coalesce_time_cmd,
2354 "coalesce-time (0-4294967295)",
2355 "Subgroup coalesce timer\n"
2356 "Subgroup coalesce timer value (in ms)\n")
2357 {
2358 VTY_DECLVAR_CONTEXT(bgp, bgp);
2359
2360 int idx = 0;
2361
2362 bgp->heuristic_coalesce = false;
2363
2364 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2365 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2366
2367 return CMD_SUCCESS;
2368 }
2369
2370 DEFUN (no_bgp_coalesce_time,
2371 no_bgp_coalesce_time_cmd,
2372 "no coalesce-time (0-4294967295)",
2373 NO_STR
2374 "Subgroup coalesce timer\n"
2375 "Subgroup coalesce timer value (in ms)\n")
2376 {
2377 VTY_DECLVAR_CONTEXT(bgp, bgp);
2378
2379 bgp->heuristic_coalesce = true;
2380 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2381 return CMD_SUCCESS;
2382 }
2383
2384 /* Maximum-paths configuration */
2385 DEFUN (bgp_maxpaths,
2386 bgp_maxpaths_cmd,
2387 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2388 "Forward packets over multiple paths\n"
2389 "Number of paths\n")
2390 {
2391 int idx_number = 1;
2392 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2393 argv[idx_number]->arg, 0, 1);
2394 }
2395
2396 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2397 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2398 "Forward packets over multiple paths\n"
2399 "Number of paths\n")
2400
2401 DEFUN (bgp_maxpaths_ibgp,
2402 bgp_maxpaths_ibgp_cmd,
2403 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2404 "Forward packets over multiple paths\n"
2405 "iBGP-multipath\n"
2406 "Number of paths\n")
2407 {
2408 int idx_number = 2;
2409 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2410 argv[idx_number]->arg, 0, 1);
2411 }
2412
2413 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2414 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2415 "Forward packets over multiple paths\n"
2416 "iBGP-multipath\n"
2417 "Number of paths\n")
2418
2419 DEFUN (bgp_maxpaths_ibgp_cluster,
2420 bgp_maxpaths_ibgp_cluster_cmd,
2421 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2422 "Forward packets over multiple paths\n"
2423 "iBGP-multipath\n"
2424 "Number of paths\n"
2425 "Match the cluster length\n")
2426 {
2427 int idx_number = 2;
2428 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2429 argv[idx_number]->arg, true, 1);
2430 }
2431
2432 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2433 "maximum-paths ibgp " CMD_RANGE_STR(
2434 1, MULTIPATH_NUM) " equal-cluster-length",
2435 "Forward packets over multiple paths\n"
2436 "iBGP-multipath\n"
2437 "Number of paths\n"
2438 "Match the cluster length\n")
2439
2440 DEFUN (no_bgp_maxpaths,
2441 no_bgp_maxpaths_cmd,
2442 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2443 NO_STR
2444 "Forward packets over multiple paths\n"
2445 "Number of paths\n")
2446 {
2447 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2448 }
2449
2450 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2451 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2452 "Forward packets over multiple paths\n"
2453 "Number of paths\n")
2454
2455 DEFUN (no_bgp_maxpaths_ibgp,
2456 no_bgp_maxpaths_ibgp_cmd,
2457 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2458 NO_STR
2459 "Forward packets over multiple paths\n"
2460 "iBGP-multipath\n"
2461 "Number of paths\n"
2462 "Match the cluster length\n")
2463 {
2464 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2465 }
2466
2467 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2468 "no maximum-paths ibgp [" CMD_RANGE_STR(
2469 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2470 NO_STR
2471 "Forward packets over multiple paths\n"
2472 "iBGP-multipath\n"
2473 "Number of paths\n"
2474 "Match the cluster length\n")
2475
2476 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2477 afi_t afi, safi_t safi)
2478 {
2479 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2480 vty_out(vty, " maximum-paths %d\n",
2481 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2482 }
2483
2484 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2485 vty_out(vty, " maximum-paths ibgp %d",
2486 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2487 if (bgp->maxpaths[afi][safi].same_clusterlen)
2488 vty_out(vty, " equal-cluster-length");
2489 vty_out(vty, "\n");
2490 }
2491 }
2492
2493 /* BGP timers. */
2494
2495 DEFUN (bgp_timers,
2496 bgp_timers_cmd,
2497 "timers bgp (0-65535) (0-65535)",
2498 "Adjust routing timers\n"
2499 "BGP timers\n"
2500 "Keepalive interval\n"
2501 "Holdtime\n")
2502 {
2503 VTY_DECLVAR_CONTEXT(bgp, bgp);
2504 int idx_number = 2;
2505 int idx_number_2 = 3;
2506 unsigned long keepalive = 0;
2507 unsigned long holdtime = 0;
2508
2509 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2510 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2511
2512 /* Holdtime value check. */
2513 if (holdtime < 3 && holdtime != 0) {
2514 vty_out(vty,
2515 "%% hold time value must be either 0 or greater than 3\n");
2516 return CMD_WARNING_CONFIG_FAILED;
2517 }
2518
2519 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2520 BGP_DEFAULT_DELAYOPEN);
2521
2522 return CMD_SUCCESS;
2523 }
2524
2525 DEFUN (no_bgp_timers,
2526 no_bgp_timers_cmd,
2527 "no timers bgp [(0-65535) (0-65535)]",
2528 NO_STR
2529 "Adjust routing timers\n"
2530 "BGP timers\n"
2531 "Keepalive interval\n"
2532 "Holdtime\n")
2533 {
2534 VTY_DECLVAR_CONTEXT(bgp, bgp);
2535 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2536 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2537
2538 return CMD_SUCCESS;
2539 }
2540
2541 /* BGP minimum holdtime. */
2542
2543 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2544 "bgp minimum-holdtime (1-65535)",
2545 "BGP specific commands\n"
2546 "BGP minimum holdtime\n"
2547 "Seconds\n")
2548 {
2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
2550 int idx_number = 2;
2551 unsigned long min_holdtime;
2552
2553 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2554
2555 bgp->default_min_holdtime = min_holdtime;
2556
2557 return CMD_SUCCESS;
2558 }
2559
2560 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2561 "no bgp minimum-holdtime [(1-65535)]",
2562 NO_STR
2563 "BGP specific commands\n"
2564 "BGP minimum holdtime\n"
2565 "Seconds\n")
2566 {
2567 VTY_DECLVAR_CONTEXT(bgp, bgp);
2568
2569 bgp->default_min_holdtime = 0;
2570
2571 return CMD_SUCCESS;
2572 }
2573
2574 DEFUN (bgp_client_to_client_reflection,
2575 bgp_client_to_client_reflection_cmd,
2576 "bgp client-to-client reflection",
2577 BGP_STR
2578 "Configure client to client route reflection\n"
2579 "reflection of routes allowed\n")
2580 {
2581 VTY_DECLVAR_CONTEXT(bgp, bgp);
2582 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2583 bgp_clear_star_soft_out(vty, bgp->name);
2584
2585 return CMD_SUCCESS;
2586 }
2587
2588 DEFUN (no_bgp_client_to_client_reflection,
2589 no_bgp_client_to_client_reflection_cmd,
2590 "no bgp client-to-client reflection",
2591 NO_STR
2592 BGP_STR
2593 "Configure client to client route reflection\n"
2594 "reflection of routes allowed\n")
2595 {
2596 VTY_DECLVAR_CONTEXT(bgp, bgp);
2597 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2598 bgp_clear_star_soft_out(vty, bgp->name);
2599
2600 return CMD_SUCCESS;
2601 }
2602
2603 /* "bgp always-compare-med" configuration. */
2604 DEFUN (bgp_always_compare_med,
2605 bgp_always_compare_med_cmd,
2606 "bgp always-compare-med",
2607 BGP_STR
2608 "Allow comparing MED from different neighbors\n")
2609 {
2610 VTY_DECLVAR_CONTEXT(bgp, bgp);
2611 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2612 bgp_recalculate_all_bestpaths(bgp);
2613
2614 return CMD_SUCCESS;
2615 }
2616
2617 DEFUN (no_bgp_always_compare_med,
2618 no_bgp_always_compare_med_cmd,
2619 "no bgp always-compare-med",
2620 NO_STR
2621 BGP_STR
2622 "Allow comparing MED from different neighbors\n")
2623 {
2624 VTY_DECLVAR_CONTEXT(bgp, bgp);
2625 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2626 bgp_recalculate_all_bestpaths(bgp);
2627
2628 return CMD_SUCCESS;
2629 }
2630
2631
2632 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2633 "bgp ebgp-requires-policy",
2634 BGP_STR
2635 "Require in and out policy for eBGP peers (RFC8212)\n")
2636 {
2637 VTY_DECLVAR_CONTEXT(bgp, bgp);
2638 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2639 return CMD_SUCCESS;
2640 }
2641
2642 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2643 "no bgp ebgp-requires-policy",
2644 NO_STR
2645 BGP_STR
2646 "Require in and out policy for eBGP peers (RFC8212)\n")
2647 {
2648 VTY_DECLVAR_CONTEXT(bgp, bgp);
2649 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2650 return CMD_SUCCESS;
2651 }
2652
2653 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2654 "bgp suppress-duplicates",
2655 BGP_STR
2656 "Suppress duplicate updates if the route actually not changed\n")
2657 {
2658 VTY_DECLVAR_CONTEXT(bgp, bgp);
2659 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2660 return CMD_SUCCESS;
2661 }
2662
2663 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2664 "no bgp suppress-duplicates",
2665 NO_STR
2666 BGP_STR
2667 "Suppress duplicate updates if the route actually not changed\n")
2668 {
2669 VTY_DECLVAR_CONTEXT(bgp, bgp);
2670 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2671 return CMD_SUCCESS;
2672 }
2673
2674 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2675 "bgp reject-as-sets",
2676 BGP_STR
2677 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2678 {
2679 VTY_DECLVAR_CONTEXT(bgp, bgp);
2680 struct listnode *node, *nnode;
2681 struct peer *peer;
2682
2683 bgp->reject_as_sets = true;
2684
2685 /* Reset existing BGP sessions to reject routes
2686 * with aspath containing AS_SET or AS_CONFED_SET.
2687 */
2688 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2689 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2690 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2691 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2692 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2693 }
2694 }
2695
2696 return CMD_SUCCESS;
2697 }
2698
2699 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2700 "no bgp reject-as-sets",
2701 NO_STR
2702 BGP_STR
2703 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2704 {
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706 struct listnode *node, *nnode;
2707 struct peer *peer;
2708
2709 bgp->reject_as_sets = false;
2710
2711 /* Reset existing BGP sessions to reject routes
2712 * with aspath containing AS_SET or AS_CONFED_SET.
2713 */
2714 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2715 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2716 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2717 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2718 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2719 }
2720 }
2721
2722 return CMD_SUCCESS;
2723 }
2724
2725 /* "bgp deterministic-med" configuration. */
2726 DEFUN (bgp_deterministic_med,
2727 bgp_deterministic_med_cmd,
2728 "bgp deterministic-med",
2729 BGP_STR
2730 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2731 {
2732 VTY_DECLVAR_CONTEXT(bgp, bgp);
2733
2734 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2735 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2736 bgp_recalculate_all_bestpaths(bgp);
2737 }
2738
2739 return CMD_SUCCESS;
2740 }
2741
2742 DEFUN (no_bgp_deterministic_med,
2743 no_bgp_deterministic_med_cmd,
2744 "no bgp deterministic-med",
2745 NO_STR
2746 BGP_STR
2747 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2748 {
2749 VTY_DECLVAR_CONTEXT(bgp, bgp);
2750 int bestpath_per_as_used;
2751 afi_t afi;
2752 safi_t safi;
2753 struct peer *peer;
2754 struct listnode *node, *nnode;
2755
2756 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2757 bestpath_per_as_used = 0;
2758
2759 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2760 FOREACH_AFI_SAFI (afi, safi)
2761 if (bgp_addpath_dmed_required(
2762 peer->addpath_type[afi][safi])) {
2763 bestpath_per_as_used = 1;
2764 break;
2765 }
2766
2767 if (bestpath_per_as_used)
2768 break;
2769 }
2770
2771 if (bestpath_per_as_used) {
2772 vty_out(vty,
2773 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2774 return CMD_WARNING_CONFIG_FAILED;
2775 } else {
2776 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2777 bgp_recalculate_all_bestpaths(bgp);
2778 }
2779 }
2780
2781 return CMD_SUCCESS;
2782 }
2783
2784 /* "bgp graceful-restart mode" configuration. */
2785 DEFUN (bgp_graceful_restart,
2786 bgp_graceful_restart_cmd,
2787 "bgp graceful-restart",
2788 BGP_STR
2789 GR_CMD
2790 )
2791 {
2792 int ret = BGP_GR_FAILURE;
2793
2794 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2795 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2796
2797 VTY_DECLVAR_CONTEXT(bgp, bgp);
2798
2799 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2800
2801 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2802 ret);
2803
2804 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2805 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2806 vty_out(vty,
2807 "Graceful restart configuration changed, reset all peers to take effect\n");
2808 return bgp_vty_return(vty, ret);
2809 }
2810
2811 DEFUN (no_bgp_graceful_restart,
2812 no_bgp_graceful_restart_cmd,
2813 "no bgp graceful-restart",
2814 NO_STR
2815 BGP_STR
2816 NO_GR_CMD
2817 )
2818 {
2819 VTY_DECLVAR_CONTEXT(bgp, bgp);
2820
2821 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2822 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2823
2824 int ret = BGP_GR_FAILURE;
2825
2826 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2827
2828 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2829 ret);
2830
2831 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2832 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2833 vty_out(vty,
2834 "Graceful restart configuration changed, reset all peers to take effect\n");
2835
2836 return bgp_vty_return(vty, ret);
2837 }
2838
2839 DEFUN (bgp_graceful_restart_stalepath_time,
2840 bgp_graceful_restart_stalepath_time_cmd,
2841 "bgp graceful-restart stalepath-time (1-4095)",
2842 BGP_STR
2843 "Graceful restart capability parameters\n"
2844 "Set the max time to hold onto restarting peer's stale paths\n"
2845 "Delay value (seconds)\n")
2846 {
2847 VTY_DECLVAR_CONTEXT(bgp, bgp);
2848 int idx_number = 3;
2849 uint32_t stalepath;
2850
2851 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2852 bgp->stalepath_time = stalepath;
2853 return CMD_SUCCESS;
2854 }
2855
2856 DEFUN (bgp_graceful_restart_restart_time,
2857 bgp_graceful_restart_restart_time_cmd,
2858 "bgp graceful-restart restart-time (0-4095)",
2859 BGP_STR
2860 "Graceful restart capability parameters\n"
2861 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2862 "Delay value (seconds)\n")
2863 {
2864 VTY_DECLVAR_CONTEXT(bgp, bgp);
2865 int idx_number = 3;
2866 uint32_t restart;
2867
2868 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2869 bgp->restart_time = restart;
2870 return CMD_SUCCESS;
2871 }
2872
2873 DEFUN (bgp_graceful_restart_select_defer_time,
2874 bgp_graceful_restart_select_defer_time_cmd,
2875 "bgp graceful-restart select-defer-time (0-3600)",
2876 BGP_STR
2877 "Graceful restart capability parameters\n"
2878 "Set the time to defer the BGP route selection after restart\n"
2879 "Delay value (seconds, 0 - disable)\n")
2880 {
2881 VTY_DECLVAR_CONTEXT(bgp, bgp);
2882 int idx_number = 3;
2883 uint32_t defer_time;
2884
2885 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2886 bgp->select_defer_time = defer_time;
2887 if (defer_time == 0)
2888 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2889 else
2890 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2891
2892 return CMD_SUCCESS;
2893 }
2894
2895 DEFUN (no_bgp_graceful_restart_stalepath_time,
2896 no_bgp_graceful_restart_stalepath_time_cmd,
2897 "no bgp graceful-restart stalepath-time [(1-4095)]",
2898 NO_STR
2899 BGP_STR
2900 "Graceful restart capability parameters\n"
2901 "Set the max time to hold onto restarting peer's stale paths\n"
2902 "Delay value (seconds)\n")
2903 {
2904 VTY_DECLVAR_CONTEXT(bgp, bgp);
2905
2906 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2907 return CMD_SUCCESS;
2908 }
2909
2910 DEFUN (no_bgp_graceful_restart_restart_time,
2911 no_bgp_graceful_restart_restart_time_cmd,
2912 "no bgp graceful-restart restart-time [(0-4095)]",
2913 NO_STR
2914 BGP_STR
2915 "Graceful restart capability parameters\n"
2916 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2917 "Delay value (seconds)\n")
2918 {
2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
2920
2921 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2922 return CMD_SUCCESS;
2923 }
2924
2925 DEFUN (no_bgp_graceful_restart_select_defer_time,
2926 no_bgp_graceful_restart_select_defer_time_cmd,
2927 "no bgp graceful-restart select-defer-time [(0-3600)]",
2928 NO_STR
2929 BGP_STR
2930 "Graceful restart capability parameters\n"
2931 "Set the time to defer the BGP route selection after restart\n"
2932 "Delay value (seconds)\n")
2933 {
2934 VTY_DECLVAR_CONTEXT(bgp, bgp);
2935
2936 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2937 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2938
2939 return CMD_SUCCESS;
2940 }
2941
2942 DEFUN (bgp_graceful_restart_preserve_fw,
2943 bgp_graceful_restart_preserve_fw_cmd,
2944 "bgp graceful-restart preserve-fw-state",
2945 BGP_STR
2946 "Graceful restart capability parameters\n"
2947 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2948 {
2949 VTY_DECLVAR_CONTEXT(bgp, bgp);
2950 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2951 return CMD_SUCCESS;
2952 }
2953
2954 DEFUN (no_bgp_graceful_restart_preserve_fw,
2955 no_bgp_graceful_restart_preserve_fw_cmd,
2956 "no bgp graceful-restart preserve-fw-state",
2957 NO_STR
2958 BGP_STR
2959 "Graceful restart capability parameters\n"
2960 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2961 {
2962 VTY_DECLVAR_CONTEXT(bgp, bgp);
2963 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2964 return CMD_SUCCESS;
2965 }
2966
2967 DEFPY (bgp_graceful_restart_notification,
2968 bgp_graceful_restart_notification_cmd,
2969 "[no$no] bgp graceful-restart notification",
2970 NO_STR
2971 BGP_STR
2972 "Graceful restart capability parameters\n"
2973 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2974 {
2975 VTY_DECLVAR_CONTEXT(bgp, bgp);
2976
2977 if (no)
2978 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2979 else
2980 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2981
2982 return CMD_SUCCESS;
2983 }
2984
2985 DEFPY (bgp_administrative_reset,
2986 bgp_administrative_reset_cmd,
2987 "[no$no] bgp hard-administrative-reset",
2988 NO_STR
2989 BGP_STR
2990 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2991 {
2992 VTY_DECLVAR_CONTEXT(bgp, bgp);
2993
2994 if (no)
2995 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2996 else
2997 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2998
2999 return CMD_SUCCESS;
3000 }
3001
3002 DEFUN (bgp_graceful_restart_disable,
3003 bgp_graceful_restart_disable_cmd,
3004 "bgp graceful-restart-disable",
3005 BGP_STR
3006 GR_DISABLE)
3007 {
3008 int ret = BGP_GR_FAILURE;
3009
3010 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3011 zlog_debug(
3012 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3013
3014 VTY_DECLVAR_CONTEXT(bgp, bgp);
3015
3016 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3017
3018 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3019 bgp->peer, ret);
3020
3021 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3022 zlog_debug(
3023 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3024 vty_out(vty,
3025 "Graceful restart configuration changed, reset all peers to take effect\n");
3026
3027 return bgp_vty_return(vty, ret);
3028 }
3029
3030 DEFUN (no_bgp_graceful_restart_disable,
3031 no_bgp_graceful_restart_disable_cmd,
3032 "no bgp graceful-restart-disable",
3033 NO_STR
3034 BGP_STR
3035 NO_GR_DISABLE
3036 )
3037 {
3038 VTY_DECLVAR_CONTEXT(bgp, bgp);
3039
3040 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3041 zlog_debug(
3042 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3043
3044 int ret = BGP_GR_FAILURE;
3045
3046 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3047
3048 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3049 ret);
3050
3051 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3052 zlog_debug(
3053 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3054 vty_out(vty,
3055 "Graceful restart configuration changed, reset all peers to take effect\n");
3056
3057 return bgp_vty_return(vty, ret);
3058 }
3059
3060 DEFUN (bgp_neighbor_graceful_restart_set,
3061 bgp_neighbor_graceful_restart_set_cmd,
3062 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3063 NEIGHBOR_STR
3064 NEIGHBOR_ADDR_STR2
3065 GR_NEIGHBOR_CMD
3066 )
3067 {
3068 int idx_peer = 1;
3069 struct peer *peer;
3070 int ret = BGP_GR_FAILURE;
3071
3072 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3073
3074 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3075 zlog_debug(
3076 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3077
3078 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3079 if (!peer)
3080 return CMD_WARNING_CONFIG_FAILED;
3081
3082 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3083
3084 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3085 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3086
3087 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3088 zlog_debug(
3089 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3090 vty_out(vty,
3091 "Graceful restart configuration changed, reset this peer to take effect\n");
3092
3093 return bgp_vty_return(vty, ret);
3094 }
3095
3096 DEFUN (no_bgp_neighbor_graceful_restart,
3097 no_bgp_neighbor_graceful_restart_set_cmd,
3098 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3099 NO_STR
3100 NEIGHBOR_STR
3101 NEIGHBOR_ADDR_STR2
3102 NO_GR_NEIGHBOR_CMD
3103 )
3104 {
3105 int idx_peer = 2;
3106 int ret = BGP_GR_FAILURE;
3107 struct peer *peer;
3108
3109 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3110
3111 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3112 if (!peer)
3113 return CMD_WARNING_CONFIG_FAILED;
3114
3115 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3116 zlog_debug(
3117 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3118
3119 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3120
3121 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3122 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3123
3124 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3125 zlog_debug(
3126 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3127 vty_out(vty,
3128 "Graceful restart configuration changed, reset this peer to take effect\n");
3129
3130 return bgp_vty_return(vty, ret);
3131 }
3132
3133 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3134 bgp_neighbor_graceful_restart_helper_set_cmd,
3135 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3136 NEIGHBOR_STR
3137 NEIGHBOR_ADDR_STR2
3138 GR_NEIGHBOR_HELPER_CMD
3139 )
3140 {
3141 int idx_peer = 1;
3142 struct peer *peer;
3143 int ret = BGP_GR_FAILURE;
3144
3145 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3146
3147 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3148 zlog_debug(
3149 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3150
3151 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3152
3153 if (!peer)
3154 return CMD_WARNING_CONFIG_FAILED;
3155
3156
3157 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3158
3159 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3160 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3161
3162 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3163 zlog_debug(
3164 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3165 vty_out(vty,
3166 "Graceful restart configuration changed, reset this peer to take effect\n");
3167
3168 return bgp_vty_return(vty, ret);
3169 }
3170
3171 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3172 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3173 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3174 NO_STR
3175 NEIGHBOR_STR
3176 NEIGHBOR_ADDR_STR2
3177 NO_GR_NEIGHBOR_HELPER_CMD
3178 )
3179 {
3180 int idx_peer = 2;
3181 int ret = BGP_GR_FAILURE;
3182 struct peer *peer;
3183
3184 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3185
3186 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3187 if (!peer)
3188 return CMD_WARNING_CONFIG_FAILED;
3189
3190 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3191 zlog_debug(
3192 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3193
3194 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3195
3196 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3197 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3198
3199 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3200 zlog_debug(
3201 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3202 vty_out(vty,
3203 "Graceful restart configuration changed, reset this peer to take effect\n");
3204
3205 return bgp_vty_return(vty, ret);
3206 }
3207
3208 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3209 bgp_neighbor_graceful_restart_disable_set_cmd,
3210 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3211 NEIGHBOR_STR
3212 NEIGHBOR_ADDR_STR2
3213 GR_NEIGHBOR_DISABLE_CMD
3214 )
3215 {
3216 int idx_peer = 1;
3217 struct peer *peer;
3218 int ret = BGP_GR_FAILURE;
3219
3220 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3221
3222 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3223 zlog_debug(
3224 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3225
3226 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3227 if (!peer)
3228 return CMD_WARNING_CONFIG_FAILED;
3229
3230 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3231
3232 if (peer->bgp->t_startup)
3233 bgp_peer_gr_flags_update(peer);
3234
3235 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3236 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3237
3238 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3239 zlog_debug(
3240 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3241 vty_out(vty,
3242 "Graceful restart configuration changed, reset this peer to take effect\n");
3243
3244 return bgp_vty_return(vty, ret);
3245 }
3246
3247 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3248 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3249 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3250 NO_STR
3251 NEIGHBOR_STR
3252 NEIGHBOR_ADDR_STR2
3253 NO_GR_NEIGHBOR_DISABLE_CMD
3254 )
3255 {
3256 int idx_peer = 2;
3257 int ret = BGP_GR_FAILURE;
3258 struct peer *peer;
3259
3260 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3261
3262 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3263 if (!peer)
3264 return CMD_WARNING_CONFIG_FAILED;
3265
3266 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3267 zlog_debug(
3268 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3269
3270 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3271
3272 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3273 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3274
3275 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3276 zlog_debug(
3277 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3278 vty_out(vty,
3279 "Graceful restart configuration changed, reset this peer to take effect\n");
3280
3281 return bgp_vty_return(vty, ret);
3282 }
3283
3284 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3285 bgp_graceful_restart_disable_eor_cmd,
3286 "bgp graceful-restart disable-eor",
3287 BGP_STR
3288 "Graceful restart configuration parameters\n"
3289 "Disable EOR Check\n")
3290 {
3291 VTY_DECLVAR_CONTEXT(bgp, bgp);
3292 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3293
3294 return CMD_SUCCESS;
3295 }
3296
3297 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3298 no_bgp_graceful_restart_disable_eor_cmd,
3299 "no bgp graceful-restart disable-eor",
3300 NO_STR
3301 BGP_STR
3302 "Graceful restart configuration parameters\n"
3303 "Disable EOR Check\n")
3304 {
3305 VTY_DECLVAR_CONTEXT(bgp, bgp);
3306 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3307
3308 return CMD_SUCCESS;
3309 }
3310
3311 DEFUN (bgp_graceful_restart_rib_stale_time,
3312 bgp_graceful_restart_rib_stale_time_cmd,
3313 "bgp graceful-restart rib-stale-time (1-3600)",
3314 BGP_STR
3315 "Graceful restart configuration parameters\n"
3316 "Specify the stale route removal timer in rib\n"
3317 "Delay value (seconds)\n")
3318 {
3319 VTY_DECLVAR_CONTEXT(bgp, bgp);
3320 int idx_number = 3;
3321 uint32_t stale_time;
3322
3323 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3324 bgp->rib_stale_time = stale_time;
3325 /* Send the stale timer update message to RIB */
3326 if (bgp_zebra_stale_timer_update(bgp))
3327 return CMD_WARNING;
3328
3329 return CMD_SUCCESS;
3330 }
3331
3332 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3333 no_bgp_graceful_restart_rib_stale_time_cmd,
3334 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3335 NO_STR
3336 BGP_STR
3337 "Graceful restart configuration parameters\n"
3338 "Specify the stale route removal timer in rib\n"
3339 "Delay value (seconds)\n")
3340 {
3341 VTY_DECLVAR_CONTEXT(bgp, bgp);
3342
3343 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3344 /* Send the stale timer update message to RIB */
3345 if (bgp_zebra_stale_timer_update(bgp))
3346 return CMD_WARNING;
3347
3348 return CMD_SUCCESS;
3349 }
3350
3351 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3352 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3353 BGP_STR
3354 "Enable Long-lived Graceful Restart\n"
3355 "Specifies maximum time to wait before purging long-lived stale routes\n"
3356 "Stale time value (seconds)\n")
3357 {
3358 VTY_DECLVAR_CONTEXT(bgp, bgp);
3359
3360 uint32_t llgr_stale_time;
3361
3362 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3363 bgp->llgr_stale_time = llgr_stale_time;
3364
3365 return CMD_SUCCESS;
3366 }
3367
3368 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3369 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3370 NO_STR BGP_STR
3371 "Enable Long-lived Graceful Restart\n"
3372 "Specifies maximum time to wait before purging long-lived stale routes\n"
3373 "Stale time value (seconds)\n")
3374 {
3375 VTY_DECLVAR_CONTEXT(bgp, bgp);
3376
3377 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3378
3379 return CMD_SUCCESS;
3380 }
3381
3382 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3383 struct bgp *bgp)
3384 {
3385 bgp_static_redo_import_check(bgp);
3386 bgp_redistribute_redo(bgp);
3387 bgp_clear_star_soft_out(vty, bgp->name);
3388 bgp_clear_star_soft_in(vty, bgp->name);
3389 }
3390
3391 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3392 {
3393 struct listnode *node, *nnode;
3394 struct bgp *bgp;
3395 bool vrf_cfg = false;
3396
3397 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3398 return CMD_SUCCESS;
3399
3400 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3401 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3402 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3403 vty_out(vty,
3404 "%% graceful-shutdown configuration found in vrf %s\n",
3405 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3406 VRF_DEFAULT_NAME : bgp->name);
3407 vrf_cfg = true;
3408 }
3409 }
3410
3411 if (vrf_cfg) {
3412 vty_out(vty,
3413 "%%Failed: global graceful-shutdown not permitted\n");
3414 return CMD_WARNING;
3415 }
3416
3417 /* Set flag globally */
3418 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3419
3420 /* Initiate processing for all BGP instances. */
3421 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3422 bgp_initiate_graceful_shut_unshut(vty, bgp);
3423
3424 return CMD_SUCCESS;
3425 }
3426
3427 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3428 {
3429 struct listnode *node, *nnode;
3430 struct bgp *bgp;
3431
3432 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3433 return CMD_SUCCESS;
3434
3435 /* Unset flag globally */
3436 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3437
3438 /* Initiate processing for all BGP instances. */
3439 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3440 bgp_initiate_graceful_shut_unshut(vty, bgp);
3441
3442 return CMD_SUCCESS;
3443 }
3444
3445 /* "bgp graceful-shutdown" configuration */
3446 DEFUN (bgp_graceful_shutdown,
3447 bgp_graceful_shutdown_cmd,
3448 "bgp graceful-shutdown",
3449 BGP_STR
3450 "Graceful shutdown parameters\n")
3451 {
3452 if (vty->node == CONFIG_NODE)
3453 return bgp_global_graceful_shutdown_config_vty(vty);
3454
3455 VTY_DECLVAR_CONTEXT(bgp, bgp);
3456
3457 /* if configured globally, per-instance config is not allowed */
3458 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3459 vty_out(vty,
3460 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3461 return CMD_WARNING_CONFIG_FAILED;
3462 }
3463
3464 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3465 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3466 bgp_initiate_graceful_shut_unshut(vty, bgp);
3467 }
3468
3469 return CMD_SUCCESS;
3470 }
3471
3472 DEFUN (no_bgp_graceful_shutdown,
3473 no_bgp_graceful_shutdown_cmd,
3474 "no bgp graceful-shutdown",
3475 NO_STR
3476 BGP_STR
3477 "Graceful shutdown parameters\n")
3478 {
3479 if (vty->node == CONFIG_NODE)
3480 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3481
3482 VTY_DECLVAR_CONTEXT(bgp, bgp);
3483
3484 /* If configured globally, cannot remove from one bgp instance */
3485 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3486 vty_out(vty,
3487 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3488 return CMD_WARNING_CONFIG_FAILED;
3489 }
3490
3491 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3492 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3493 bgp_initiate_graceful_shut_unshut(vty, bgp);
3494 }
3495
3496 return CMD_SUCCESS;
3497 }
3498
3499 /* "bgp fast-external-failover" configuration. */
3500 DEFUN (bgp_fast_external_failover,
3501 bgp_fast_external_failover_cmd,
3502 "bgp fast-external-failover",
3503 BGP_STR
3504 "Immediately reset session if a link to a directly connected external peer goes down\n")
3505 {
3506 VTY_DECLVAR_CONTEXT(bgp, bgp);
3507 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3508 return CMD_SUCCESS;
3509 }
3510
3511 DEFUN (no_bgp_fast_external_failover,
3512 no_bgp_fast_external_failover_cmd,
3513 "no bgp fast-external-failover",
3514 NO_STR
3515 BGP_STR
3516 "Immediately reset session if a link to a directly connected external peer goes down\n")
3517 {
3518 VTY_DECLVAR_CONTEXT(bgp, bgp);
3519 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3520 return CMD_SUCCESS;
3521 }
3522
3523 /* "bgp bestpath compare-routerid" configuration. */
3524 DEFUN (bgp_bestpath_compare_router_id,
3525 bgp_bestpath_compare_router_id_cmd,
3526 "bgp bestpath compare-routerid",
3527 BGP_STR
3528 "Change the default bestpath selection\n"
3529 "Compare router-id for identical EBGP paths\n")
3530 {
3531 VTY_DECLVAR_CONTEXT(bgp, bgp);
3532 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3533 bgp_recalculate_all_bestpaths(bgp);
3534
3535 return CMD_SUCCESS;
3536 }
3537
3538 DEFUN (no_bgp_bestpath_compare_router_id,
3539 no_bgp_bestpath_compare_router_id_cmd,
3540 "no bgp bestpath compare-routerid",
3541 NO_STR
3542 BGP_STR
3543 "Change the default bestpath selection\n"
3544 "Compare router-id for identical EBGP paths\n")
3545 {
3546 VTY_DECLVAR_CONTEXT(bgp, bgp);
3547 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3548 bgp_recalculate_all_bestpaths(bgp);
3549
3550 return CMD_SUCCESS;
3551 }
3552
3553 /* "bgp bestpath as-path ignore" configuration. */
3554 DEFUN (bgp_bestpath_aspath_ignore,
3555 bgp_bestpath_aspath_ignore_cmd,
3556 "bgp bestpath as-path ignore",
3557 BGP_STR
3558 "Change the default bestpath selection\n"
3559 "AS-path attribute\n"
3560 "Ignore as-path length in selecting a route\n")
3561 {
3562 VTY_DECLVAR_CONTEXT(bgp, bgp);
3563 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3564 bgp_recalculate_all_bestpaths(bgp);
3565
3566 return CMD_SUCCESS;
3567 }
3568
3569 DEFUN (no_bgp_bestpath_aspath_ignore,
3570 no_bgp_bestpath_aspath_ignore_cmd,
3571 "no bgp bestpath as-path ignore",
3572 NO_STR
3573 BGP_STR
3574 "Change the default bestpath selection\n"
3575 "AS-path attribute\n"
3576 "Ignore as-path length in selecting a route\n")
3577 {
3578 VTY_DECLVAR_CONTEXT(bgp, bgp);
3579 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3580 bgp_recalculate_all_bestpaths(bgp);
3581
3582 return CMD_SUCCESS;
3583 }
3584
3585 /* "bgp bestpath as-path confed" configuration. */
3586 DEFUN (bgp_bestpath_aspath_confed,
3587 bgp_bestpath_aspath_confed_cmd,
3588 "bgp bestpath as-path confed",
3589 BGP_STR
3590 "Change the default bestpath selection\n"
3591 "AS-path attribute\n"
3592 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3593 {
3594 VTY_DECLVAR_CONTEXT(bgp, bgp);
3595 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3596 bgp_recalculate_all_bestpaths(bgp);
3597
3598 return CMD_SUCCESS;
3599 }
3600
3601 DEFUN (no_bgp_bestpath_aspath_confed,
3602 no_bgp_bestpath_aspath_confed_cmd,
3603 "no bgp bestpath as-path confed",
3604 NO_STR
3605 BGP_STR
3606 "Change the default bestpath selection\n"
3607 "AS-path attribute\n"
3608 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3609 {
3610 VTY_DECLVAR_CONTEXT(bgp, bgp);
3611 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3612 bgp_recalculate_all_bestpaths(bgp);
3613
3614 return CMD_SUCCESS;
3615 }
3616
3617 /* "bgp bestpath as-path multipath-relax" configuration. */
3618 DEFUN (bgp_bestpath_aspath_multipath_relax,
3619 bgp_bestpath_aspath_multipath_relax_cmd,
3620 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3621 BGP_STR
3622 "Change the default bestpath selection\n"
3623 "AS-path attribute\n"
3624 "Allow load sharing across routes that have different AS paths (but same length)\n"
3625 "Generate an AS_SET\n"
3626 "Do not generate an AS_SET\n")
3627 {
3628 VTY_DECLVAR_CONTEXT(bgp, bgp);
3629 int idx = 0;
3630 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3631
3632 /* no-as-set is now the default behavior so we can silently
3633 * ignore it */
3634 if (argv_find(argv, argc, "as-set", &idx))
3635 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3636 else
3637 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3638
3639 bgp_recalculate_all_bestpaths(bgp);
3640
3641 return CMD_SUCCESS;
3642 }
3643
3644 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3645 no_bgp_bestpath_aspath_multipath_relax_cmd,
3646 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3647 NO_STR
3648 BGP_STR
3649 "Change the default bestpath selection\n"
3650 "AS-path attribute\n"
3651 "Allow load sharing across routes that have different AS paths (but same length)\n"
3652 "Generate an AS_SET\n"
3653 "Do not generate an AS_SET\n")
3654 {
3655 VTY_DECLVAR_CONTEXT(bgp, bgp);
3656 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3657 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3658 bgp_recalculate_all_bestpaths(bgp);
3659
3660 return CMD_SUCCESS;
3661 }
3662
3663 /* "bgp bestpath peer-type multipath-relax" configuration. */
3664 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3665 bgp_bestpath_peer_type_multipath_relax_cmd,
3666 "bgp bestpath peer-type multipath-relax",
3667 BGP_STR
3668 "Change the default bestpath selection\n"
3669 "Peer type\n"
3670 "Allow load sharing across routes learned from different peer types\n")
3671 {
3672 VTY_DECLVAR_CONTEXT(bgp, bgp);
3673 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3674 bgp_recalculate_all_bestpaths(bgp);
3675
3676 return CMD_SUCCESS;
3677 }
3678
3679 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3680 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3681 "no bgp bestpath peer-type multipath-relax",
3682 NO_STR BGP_STR
3683 "Change the default bestpath selection\n"
3684 "Peer type\n"
3685 "Allow load sharing across routes learned from different peer types\n")
3686 {
3687 VTY_DECLVAR_CONTEXT(bgp, bgp);
3688 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3689 bgp_recalculate_all_bestpaths(bgp);
3690
3691 return CMD_SUCCESS;
3692 }
3693
3694 /* "bgp log-neighbor-changes" configuration. */
3695 DEFUN (bgp_log_neighbor_changes,
3696 bgp_log_neighbor_changes_cmd,
3697 "bgp log-neighbor-changes",
3698 BGP_STR
3699 "Log neighbor up/down and reset reason\n")
3700 {
3701 VTY_DECLVAR_CONTEXT(bgp, bgp);
3702 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3703 return CMD_SUCCESS;
3704 }
3705
3706 DEFUN (no_bgp_log_neighbor_changes,
3707 no_bgp_log_neighbor_changes_cmd,
3708 "no bgp log-neighbor-changes",
3709 NO_STR
3710 BGP_STR
3711 "Log neighbor up/down and reset reason\n")
3712 {
3713 VTY_DECLVAR_CONTEXT(bgp, bgp);
3714 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3715 return CMD_SUCCESS;
3716 }
3717
3718 /* "bgp bestpath med" configuration. */
3719 DEFUN (bgp_bestpath_med,
3720 bgp_bestpath_med_cmd,
3721 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3722 BGP_STR
3723 "Change the default bestpath selection\n"
3724 "MED attribute\n"
3725 "Compare MED among confederation paths\n"
3726 "Treat missing MED as the least preferred one\n"
3727 "Treat missing MED as the least preferred one\n"
3728 "Compare MED among confederation paths\n")
3729 {
3730 VTY_DECLVAR_CONTEXT(bgp, bgp);
3731
3732 int idx = 0;
3733 if (argv_find(argv, argc, "confed", &idx))
3734 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3735 idx = 0;
3736 if (argv_find(argv, argc, "missing-as-worst", &idx))
3737 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3738
3739 bgp_recalculate_all_bestpaths(bgp);
3740
3741 return CMD_SUCCESS;
3742 }
3743
3744 DEFUN (no_bgp_bestpath_med,
3745 no_bgp_bestpath_med_cmd,
3746 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3747 NO_STR
3748 BGP_STR
3749 "Change the default bestpath selection\n"
3750 "MED attribute\n"
3751 "Compare MED among confederation paths\n"
3752 "Treat missing MED as the least preferred one\n"
3753 "Treat missing MED as the least preferred one\n"
3754 "Compare MED among confederation paths\n")
3755 {
3756 VTY_DECLVAR_CONTEXT(bgp, bgp);
3757
3758 int idx = 0;
3759 if (argv_find(argv, argc, "confed", &idx))
3760 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3761 idx = 0;
3762 if (argv_find(argv, argc, "missing-as-worst", &idx))
3763 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3764
3765 bgp_recalculate_all_bestpaths(bgp);
3766
3767 return CMD_SUCCESS;
3768 }
3769
3770 /* "bgp bestpath bandwidth" configuration. */
3771 DEFPY (bgp_bestpath_bw,
3772 bgp_bestpath_bw_cmd,
3773 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3774 BGP_STR
3775 "Change the default bestpath selection\n"
3776 "Link Bandwidth attribute\n"
3777 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3778 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3779 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3780 {
3781 VTY_DECLVAR_CONTEXT(bgp, bgp);
3782 afi_t afi;
3783 safi_t safi;
3784
3785 if (!bw_cfg) {
3786 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3787 return CMD_ERR_INCOMPLETE;
3788 }
3789 if (!strcmp(bw_cfg, "ignore"))
3790 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3791 else if (!strcmp(bw_cfg, "skip-missing"))
3792 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3793 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3794 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3795 else
3796 return CMD_ERR_NO_MATCH;
3797
3798 /* This config is used in route install, so redo that. */
3799 FOREACH_AFI_SAFI (afi, safi) {
3800 if (!bgp_fibupd_safi(safi))
3801 continue;
3802 bgp_zebra_announce_table(bgp, afi, safi);
3803 }
3804
3805 return CMD_SUCCESS;
3806 }
3807
3808 DEFPY (no_bgp_bestpath_bw,
3809 no_bgp_bestpath_bw_cmd,
3810 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3811 NO_STR
3812 BGP_STR
3813 "Change the default bestpath selection\n"
3814 "Link Bandwidth attribute\n"
3815 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3816 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3817 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3818 {
3819 VTY_DECLVAR_CONTEXT(bgp, bgp);
3820 afi_t afi;
3821 safi_t safi;
3822
3823 bgp->lb_handling = BGP_LINK_BW_ECMP;
3824
3825 /* This config is used in route install, so redo that. */
3826 FOREACH_AFI_SAFI (afi, safi) {
3827 if (!bgp_fibupd_safi(safi))
3828 continue;
3829 bgp_zebra_announce_table(bgp, afi, safi);
3830 }
3831 return CMD_SUCCESS;
3832 }
3833
3834 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3835 "[no] bgp default <ipv4-unicast|"
3836 "ipv4-multicast|"
3837 "ipv4-vpn|"
3838 "ipv4-labeled-unicast|"
3839 "ipv4-flowspec|"
3840 "ipv6-unicast|"
3841 "ipv6-multicast|"
3842 "ipv6-vpn|"
3843 "ipv6-labeled-unicast|"
3844 "ipv6-flowspec|"
3845 "l2vpn-evpn>$afi_safi",
3846 NO_STR
3847 BGP_STR
3848 "Configure BGP defaults\n"
3849 "Activate ipv4-unicast for a peer by default\n"
3850 "Activate ipv4-multicast for a peer by default\n"
3851 "Activate ipv4-vpn for a peer by default\n"
3852 "Activate ipv4-labeled-unicast for a peer by default\n"
3853 "Activate ipv4-flowspec for a peer by default\n"
3854 "Activate ipv6-unicast for a peer by default\n"
3855 "Activate ipv6-multicast for a peer by default\n"
3856 "Activate ipv6-vpn for a peer by default\n"
3857 "Activate ipv6-labeled-unicast for a peer by default\n"
3858 "Activate ipv6-flowspec for a peer by default\n"
3859 "Activate l2vpn-evpn for a peer by default\n")
3860 {
3861 VTY_DECLVAR_CONTEXT(bgp, bgp);
3862 char afi_safi_str[strlen(afi_safi) + 1];
3863 char *afi_safi_str_tok;
3864
3865 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3866 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3867 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3868 afi_t afi = bgp_vty_afi_from_str(afi_str);
3869 safi_t safi;
3870
3871 /*
3872 * Impossible situation but making coverity happy
3873 */
3874 assert(afi != AFI_MAX);
3875
3876 if (strmatch(safi_str, "labeled"))
3877 safi = bgp_vty_safi_from_str("labeled-unicast");
3878 else
3879 safi = bgp_vty_safi_from_str(safi_str);
3880
3881 assert(safi != SAFI_MAX);
3882 if (no)
3883 bgp->default_af[afi][safi] = false;
3884 else {
3885 if ((safi == SAFI_LABELED_UNICAST
3886 && bgp->default_af[afi][SAFI_UNICAST])
3887 || (safi == SAFI_UNICAST
3888 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3889 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3890 else
3891 bgp->default_af[afi][safi] = true;
3892 }
3893
3894 return CMD_SUCCESS;
3895 }
3896
3897 /* Display hostname in certain command outputs */
3898 DEFUN (bgp_default_show_hostname,
3899 bgp_default_show_hostname_cmd,
3900 "bgp default show-hostname",
3901 BGP_STR
3902 "Configure BGP defaults\n"
3903 "Show hostname in certain command outputs\n")
3904 {
3905 VTY_DECLVAR_CONTEXT(bgp, bgp);
3906 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3907 return CMD_SUCCESS;
3908 }
3909
3910 DEFUN (no_bgp_default_show_hostname,
3911 no_bgp_default_show_hostname_cmd,
3912 "no bgp default show-hostname",
3913 NO_STR
3914 BGP_STR
3915 "Configure BGP defaults\n"
3916 "Show hostname in certain command outputs\n")
3917 {
3918 VTY_DECLVAR_CONTEXT(bgp, bgp);
3919 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3920 return CMD_SUCCESS;
3921 }
3922
3923 /* Display hostname in certain command outputs */
3924 DEFUN (bgp_default_show_nexthop_hostname,
3925 bgp_default_show_nexthop_hostname_cmd,
3926 "bgp default show-nexthop-hostname",
3927 BGP_STR
3928 "Configure BGP defaults\n"
3929 "Show hostname for nexthop in certain command outputs\n")
3930 {
3931 VTY_DECLVAR_CONTEXT(bgp, bgp);
3932 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3933 return CMD_SUCCESS;
3934 }
3935
3936 DEFUN (no_bgp_default_show_nexthop_hostname,
3937 no_bgp_default_show_nexthop_hostname_cmd,
3938 "no bgp default show-nexthop-hostname",
3939 NO_STR
3940 BGP_STR
3941 "Configure BGP defaults\n"
3942 "Show hostname for nexthop in certain command outputs\n")
3943 {
3944 VTY_DECLVAR_CONTEXT(bgp, bgp);
3945 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3946 return CMD_SUCCESS;
3947 }
3948
3949 /* "bgp network import-check" configuration. */
3950 DEFUN (bgp_network_import_check,
3951 bgp_network_import_check_cmd,
3952 "bgp network import-check",
3953 BGP_STR
3954 "BGP network command\n"
3955 "Check BGP network route exists in IGP\n")
3956 {
3957 VTY_DECLVAR_CONTEXT(bgp, bgp);
3958 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3959 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3960 bgp_static_redo_import_check(bgp);
3961 }
3962
3963 return CMD_SUCCESS;
3964 }
3965
3966 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3967 "bgp network import-check exact",
3968 BGP_STR
3969 "BGP network command\n"
3970 "Check BGP network route exists in IGP\n"
3971 "Match route precisely\n")
3972
3973 DEFUN (no_bgp_network_import_check,
3974 no_bgp_network_import_check_cmd,
3975 "no bgp network import-check",
3976 NO_STR
3977 BGP_STR
3978 "BGP network command\n"
3979 "Check BGP network route exists in IGP\n")
3980 {
3981 VTY_DECLVAR_CONTEXT(bgp, bgp);
3982 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3983 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3984 bgp_static_redo_import_check(bgp);
3985 }
3986
3987 return CMD_SUCCESS;
3988 }
3989
3990 DEFUN (bgp_default_local_preference,
3991 bgp_default_local_preference_cmd,
3992 "bgp default local-preference (0-4294967295)",
3993 BGP_STR
3994 "Configure BGP defaults\n"
3995 "local preference (higher=more preferred)\n"
3996 "Configure default local preference value\n")
3997 {
3998 VTY_DECLVAR_CONTEXT(bgp, bgp);
3999 int idx_number = 3;
4000 uint32_t local_pref;
4001
4002 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4003
4004 bgp_default_local_preference_set(bgp, local_pref);
4005 bgp_clear_star_soft_in(vty, bgp->name);
4006
4007 return CMD_SUCCESS;
4008 }
4009
4010 DEFUN (no_bgp_default_local_preference,
4011 no_bgp_default_local_preference_cmd,
4012 "no bgp default local-preference [(0-4294967295)]",
4013 NO_STR
4014 BGP_STR
4015 "Configure BGP defaults\n"
4016 "local preference (higher=more preferred)\n"
4017 "Configure default local preference value\n")
4018 {
4019 VTY_DECLVAR_CONTEXT(bgp, bgp);
4020 bgp_default_local_preference_unset(bgp);
4021 bgp_clear_star_soft_in(vty, bgp->name);
4022
4023 return CMD_SUCCESS;
4024 }
4025
4026
4027 DEFUN (bgp_default_subgroup_pkt_queue_max,
4028 bgp_default_subgroup_pkt_queue_max_cmd,
4029 "bgp default subgroup-pkt-queue-max (20-100)",
4030 BGP_STR
4031 "Configure BGP defaults\n"
4032 "subgroup-pkt-queue-max\n"
4033 "Configure subgroup packet queue max\n")
4034 {
4035 VTY_DECLVAR_CONTEXT(bgp, bgp);
4036 int idx_number = 3;
4037 uint32_t max_size;
4038
4039 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4040
4041 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4042
4043 return CMD_SUCCESS;
4044 }
4045
4046 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4047 no_bgp_default_subgroup_pkt_queue_max_cmd,
4048 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4049 NO_STR
4050 BGP_STR
4051 "Configure BGP defaults\n"
4052 "subgroup-pkt-queue-max\n"
4053 "Configure subgroup packet queue max\n")
4054 {
4055 VTY_DECLVAR_CONTEXT(bgp, bgp);
4056 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4057 return CMD_SUCCESS;
4058 }
4059
4060
4061 DEFUN (bgp_rr_allow_outbound_policy,
4062 bgp_rr_allow_outbound_policy_cmd,
4063 "bgp route-reflector allow-outbound-policy",
4064 BGP_STR
4065 "Allow modifications made by out route-map\n"
4066 "on ibgp neighbors\n")
4067 {
4068 VTY_DECLVAR_CONTEXT(bgp, bgp);
4069
4070 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4071 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4072 update_group_announce_rrclients(bgp);
4073 bgp_clear_star_soft_out(vty, bgp->name);
4074 }
4075
4076 return CMD_SUCCESS;
4077 }
4078
4079 DEFUN (no_bgp_rr_allow_outbound_policy,
4080 no_bgp_rr_allow_outbound_policy_cmd,
4081 "no bgp route-reflector allow-outbound-policy",
4082 NO_STR
4083 BGP_STR
4084 "Allow modifications made by out route-map\n"
4085 "on ibgp neighbors\n")
4086 {
4087 VTY_DECLVAR_CONTEXT(bgp, bgp);
4088
4089 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4090 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4091 update_group_announce_rrclients(bgp);
4092 bgp_clear_star_soft_out(vty, bgp->name);
4093 }
4094
4095 return CMD_SUCCESS;
4096 }
4097
4098 DEFUN (bgp_listen_limit,
4099 bgp_listen_limit_cmd,
4100 "bgp listen limit (1-65535)",
4101 BGP_STR
4102 "BGP Dynamic Neighbors listen commands\n"
4103 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4104 "Configure Dynamic Neighbors listen limit value\n")
4105 {
4106 VTY_DECLVAR_CONTEXT(bgp, bgp);
4107 int idx_number = 3;
4108 int listen_limit;
4109
4110 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4111
4112 bgp_listen_limit_set(bgp, listen_limit);
4113
4114 return CMD_SUCCESS;
4115 }
4116
4117 DEFUN (no_bgp_listen_limit,
4118 no_bgp_listen_limit_cmd,
4119 "no bgp listen limit [(1-65535)]",
4120 NO_STR
4121 BGP_STR
4122 "BGP Dynamic Neighbors listen commands\n"
4123 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4124 "Configure Dynamic Neighbors listen limit value\n")
4125 {
4126 VTY_DECLVAR_CONTEXT(bgp, bgp);
4127 bgp_listen_limit_unset(bgp);
4128 return CMD_SUCCESS;
4129 }
4130
4131
4132 /*
4133 * Check if this listen range is already configured. Check for exact
4134 * match or overlap based on input.
4135 */
4136 static struct peer_group *listen_range_exists(struct bgp *bgp,
4137 struct prefix *range, int exact)
4138 {
4139 struct listnode *node, *nnode;
4140 struct listnode *node1, *nnode1;
4141 struct peer_group *group;
4142 struct prefix *lr;
4143 afi_t afi;
4144 int match;
4145
4146 afi = family2afi(range->family);
4147 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4148 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4149 lr)) {
4150 if (exact)
4151 match = prefix_same(range, lr);
4152 else
4153 match = (prefix_match(range, lr)
4154 || prefix_match(lr, range));
4155 if (match)
4156 return group;
4157 }
4158 }
4159
4160 return NULL;
4161 }
4162
4163 DEFUN (bgp_listen_range,
4164 bgp_listen_range_cmd,
4165 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4166 BGP_STR
4167 "Configure BGP dynamic neighbors listen range\n"
4168 "Configure BGP dynamic neighbors listen range\n"
4169 NEIGHBOR_ADDR_STR
4170 "Member of the peer-group\n"
4171 "Peer-group name\n")
4172 {
4173 VTY_DECLVAR_CONTEXT(bgp, bgp);
4174 struct prefix range;
4175 struct peer_group *group, *existing_group;
4176 afi_t afi;
4177 int ret;
4178 int idx = 0;
4179
4180 argv_find(argv, argc, "A.B.C.D/M", &idx);
4181 argv_find(argv, argc, "X:X::X:X/M", &idx);
4182 char *prefix = argv[idx]->arg;
4183 argv_find(argv, argc, "PGNAME", &idx);
4184 char *peergroup = argv[idx]->arg;
4185
4186 /* Convert IP prefix string to struct prefix. */
4187 ret = str2prefix(prefix, &range);
4188 if (!ret) {
4189 vty_out(vty, "%% Malformed listen range\n");
4190 return CMD_WARNING_CONFIG_FAILED;
4191 }
4192
4193 afi = family2afi(range.family);
4194
4195 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4196 vty_out(vty,
4197 "%% Malformed listen range (link-local address)\n");
4198 return CMD_WARNING_CONFIG_FAILED;
4199 }
4200
4201 apply_mask(&range);
4202
4203 /* Check if same listen range is already configured. */
4204 existing_group = listen_range_exists(bgp, &range, 1);
4205 if (existing_group) {
4206 if (strcmp(existing_group->name, peergroup) == 0)
4207 return CMD_SUCCESS;
4208 else {
4209 vty_out(vty,
4210 "%% Same listen range is attached to peer-group %s\n",
4211 existing_group->name);
4212 return CMD_WARNING_CONFIG_FAILED;
4213 }
4214 }
4215
4216 /* Check if an overlapping listen range exists. */
4217 if (listen_range_exists(bgp, &range, 0)) {
4218 vty_out(vty,
4219 "%% Listen range overlaps with existing listen range\n");
4220 return CMD_WARNING_CONFIG_FAILED;
4221 }
4222
4223 group = peer_group_lookup(bgp, peergroup);
4224 if (!group) {
4225 vty_out(vty, "%% Configure the peer-group first\n");
4226 return CMD_WARNING_CONFIG_FAILED;
4227 }
4228
4229 ret = peer_group_listen_range_add(group, &range);
4230 return bgp_vty_return(vty, ret);
4231 }
4232
4233 DEFUN (no_bgp_listen_range,
4234 no_bgp_listen_range_cmd,
4235 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4236 NO_STR
4237 BGP_STR
4238 "Unconfigure BGP dynamic neighbors listen range\n"
4239 "Unconfigure BGP dynamic neighbors listen range\n"
4240 NEIGHBOR_ADDR_STR
4241 "Member of the peer-group\n"
4242 "Peer-group name\n")
4243 {
4244 VTY_DECLVAR_CONTEXT(bgp, bgp);
4245 struct prefix range;
4246 struct peer_group *group;
4247 afi_t afi;
4248 int ret;
4249 int idx = 0;
4250
4251 argv_find(argv, argc, "A.B.C.D/M", &idx);
4252 argv_find(argv, argc, "X:X::X:X/M", &idx);
4253 char *prefix = argv[idx]->arg;
4254 argv_find(argv, argc, "PGNAME", &idx);
4255 char *peergroup = argv[idx]->arg;
4256
4257 /* Convert IP prefix string to struct prefix. */
4258 ret = str2prefix(prefix, &range);
4259 if (!ret) {
4260 vty_out(vty, "%% Malformed listen range\n");
4261 return CMD_WARNING_CONFIG_FAILED;
4262 }
4263
4264 afi = family2afi(range.family);
4265
4266 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4267 vty_out(vty,
4268 "%% Malformed listen range (link-local address)\n");
4269 return CMD_WARNING_CONFIG_FAILED;
4270 }
4271
4272 apply_mask(&range);
4273
4274 group = peer_group_lookup(bgp, peergroup);
4275 if (!group) {
4276 vty_out(vty, "%% Peer-group does not exist\n");
4277 return CMD_WARNING_CONFIG_FAILED;
4278 }
4279
4280 ret = peer_group_listen_range_del(group, &range);
4281 return bgp_vty_return(vty, ret);
4282 }
4283
4284 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4285 {
4286 struct peer_group *group;
4287 struct listnode *node, *nnode, *rnode, *nrnode;
4288 struct prefix *range;
4289 afi_t afi;
4290
4291 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4292 vty_out(vty, " bgp listen limit %d\n",
4293 bgp->dynamic_neighbors_limit);
4294
4295 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4296 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4297 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4298 nrnode, range)) {
4299 vty_out(vty,
4300 " bgp listen range %pFX peer-group %s\n",
4301 range, group->name);
4302 }
4303 }
4304 }
4305 }
4306
4307
4308 DEFUN (bgp_disable_connected_route_check,
4309 bgp_disable_connected_route_check_cmd,
4310 "bgp disable-ebgp-connected-route-check",
4311 BGP_STR
4312 "Disable checking if nexthop is connected on ebgp sessions\n")
4313 {
4314 VTY_DECLVAR_CONTEXT(bgp, bgp);
4315 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4316 bgp_clear_star_soft_in(vty, bgp->name);
4317
4318 return CMD_SUCCESS;
4319 }
4320
4321 DEFUN (no_bgp_disable_connected_route_check,
4322 no_bgp_disable_connected_route_check_cmd,
4323 "no bgp disable-ebgp-connected-route-check",
4324 NO_STR
4325 BGP_STR
4326 "Disable checking if nexthop is connected on ebgp sessions\n")
4327 {
4328 VTY_DECLVAR_CONTEXT(bgp, bgp);
4329 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4330 bgp_clear_star_soft_in(vty, bgp->name);
4331
4332 return CMD_SUCCESS;
4333 }
4334
4335
4336 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4337 const char *as_str)
4338 {
4339 VTY_DECLVAR_CONTEXT(bgp, bgp);
4340 int ret;
4341 as_t as;
4342 int as_type = AS_SPECIFIED;
4343 union sockunion su;
4344
4345 if (as_str[0] == 'i') {
4346 as = 0;
4347 as_type = AS_INTERNAL;
4348 } else if (as_str[0] == 'e') {
4349 as = 0;
4350 as_type = AS_EXTERNAL;
4351 } else {
4352 /* Get AS number. */
4353 as = strtoul(as_str, NULL, 10);
4354 }
4355
4356 /* If peer is peer group or interface peer, call proper function. */
4357 ret = str2sockunion(peer_str, &su);
4358 if (ret < 0) {
4359 struct peer *peer;
4360
4361 /* Check if existing interface peer */
4362 peer = peer_lookup_by_conf_if(bgp, peer_str);
4363
4364 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4365
4366 /* if not interface peer, check peer-group settings */
4367 if (ret < 0 && !peer) {
4368 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4369 if (ret < 0) {
4370 vty_out(vty,
4371 "%% Create the peer-group or interface first\n");
4372 return CMD_WARNING_CONFIG_FAILED;
4373 }
4374 return CMD_SUCCESS;
4375 }
4376 } else {
4377 if (peer_address_self_check(bgp, &su)) {
4378 vty_out(vty,
4379 "%% Can not configure the local system as neighbor\n");
4380 return CMD_WARNING_CONFIG_FAILED;
4381 }
4382 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4383 }
4384
4385 return bgp_vty_return(vty, ret);
4386 }
4387
4388 DEFUN (bgp_default_shutdown,
4389 bgp_default_shutdown_cmd,
4390 "[no] bgp default shutdown",
4391 NO_STR
4392 BGP_STR
4393 "Configure BGP defaults\n"
4394 "Apply administrative shutdown to newly configured peers\n")
4395 {
4396 VTY_DECLVAR_CONTEXT(bgp, bgp);
4397 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4398 return CMD_SUCCESS;
4399 }
4400
4401 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4402 BGP_STR
4403 "Administrative shutdown of the BGP instance\n"
4404 "Add a shutdown message (RFC 8203)\n"
4405 "Shutdown message\n")
4406 {
4407 char *msgstr = NULL;
4408
4409 VTY_DECLVAR_CONTEXT(bgp, bgp);
4410
4411 if (argc > 3)
4412 msgstr = argv_concat(argv, argc, 3);
4413
4414 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4415 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4416 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4417 return CMD_WARNING_CONFIG_FAILED;
4418 }
4419
4420 bgp_shutdown_enable(bgp, msgstr);
4421 XFREE(MTYPE_TMP, msgstr);
4422
4423 return CMD_SUCCESS;
4424 }
4425
4426 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4427 BGP_STR "Administrative shutdown of the BGP instance\n")
4428 {
4429 VTY_DECLVAR_CONTEXT(bgp, bgp);
4430
4431 bgp_shutdown_enable(bgp, NULL);
4432
4433 return CMD_SUCCESS;
4434 }
4435
4436 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4437 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4438 {
4439 VTY_DECLVAR_CONTEXT(bgp, bgp);
4440
4441 bgp_shutdown_disable(bgp);
4442
4443 return CMD_SUCCESS;
4444 }
4445
4446 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4447 "no bgp shutdown message MSG...", NO_STR BGP_STR
4448 "Administrative shutdown of the BGP instance\n"
4449 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4450
4451 DEFUN (neighbor_remote_as,
4452 neighbor_remote_as_cmd,
4453 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4454 NEIGHBOR_STR
4455 NEIGHBOR_ADDR_STR2
4456 "Specify a BGP neighbor\n"
4457 AS_STR
4458 "Internal BGP peer\n"
4459 "External BGP peer\n")
4460 {
4461 int idx_peer = 1;
4462 int idx_remote_as = 3;
4463 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4464 argv[idx_remote_as]->arg);
4465 }
4466
4467 DEFPY (bgp_allow_martian,
4468 bgp_allow_martian_cmd,
4469 "[no]$no bgp allow-martian-nexthop",
4470 NO_STR
4471 BGP_STR
4472 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4473 {
4474 VTY_DECLVAR_CONTEXT(bgp, bgp);
4475
4476 if (no)
4477 bgp->allow_martian = false;
4478 else
4479 bgp->allow_martian = true;
4480
4481 return CMD_SUCCESS;
4482 }
4483
4484 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4485 * sessions do not wait for hold timer expiry to bring down the sessions
4486 * when nexthop becomes unreachable
4487 */
4488 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4489 BGP_STR "Fast convergence for bgp sessions\n")
4490 {
4491 VTY_DECLVAR_CONTEXT(bgp, bgp);
4492 bgp->fast_convergence = true;
4493
4494 return CMD_SUCCESS;
4495 }
4496
4497 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4498 "no bgp fast-convergence",
4499 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4500 {
4501 VTY_DECLVAR_CONTEXT(bgp, bgp);
4502 bgp->fast_convergence = false;
4503
4504 return CMD_SUCCESS;
4505 }
4506
4507 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4508 int v6only,
4509 const char *peer_group_name,
4510 const char *as_str)
4511 {
4512 VTY_DECLVAR_CONTEXT(bgp, bgp);
4513 as_t as = 0;
4514 int as_type = AS_UNSPECIFIED;
4515 struct peer *peer;
4516 struct peer_group *group;
4517 int ret = 0;
4518
4519 group = peer_group_lookup(bgp, conf_if);
4520
4521 if (group) {
4522 vty_out(vty, "%% Name conflict with peer-group \n");
4523 return CMD_WARNING_CONFIG_FAILED;
4524 }
4525
4526 if (as_str) {
4527 if (as_str[0] == 'i') {
4528 as_type = AS_INTERNAL;
4529 } else if (as_str[0] == 'e') {
4530 as_type = AS_EXTERNAL;
4531 } else {
4532 /* Get AS number. */
4533 as = strtoul(as_str, NULL, 10);
4534 as_type = AS_SPECIFIED;
4535 }
4536 }
4537
4538 peer = peer_lookup_by_conf_if(bgp, conf_if);
4539 if (peer) {
4540 if (as_str)
4541 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4542 } else {
4543 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4544 NULL);
4545
4546 if (!peer) {
4547 vty_out(vty, "%% BGP failed to create peer\n");
4548 return CMD_WARNING_CONFIG_FAILED;
4549 }
4550
4551 if (v6only)
4552 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4553
4554 /* Request zebra to initiate IPv6 RAs on this interface. We do
4555 * this
4556 * any unnumbered peer in order to not worry about run-time
4557 * transitions
4558 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4559 * address
4560 * gets deleted later etc.)
4561 */
4562 if (peer->ifp)
4563 bgp_zebra_initiate_radv(bgp, peer);
4564 }
4565
4566 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4567 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4568 if (v6only)
4569 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4570 else
4571 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4572
4573 /* v6only flag changed. Reset bgp seesion */
4574 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4575 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4576 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4577 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4578 } else
4579 bgp_session_reset(peer);
4580 }
4581
4582 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4583 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4584 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4585 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4586 }
4587
4588 if (peer_group_name) {
4589 group = peer_group_lookup(bgp, peer_group_name);
4590 if (!group) {
4591 vty_out(vty, "%% Configure the peer-group first\n");
4592 return CMD_WARNING_CONFIG_FAILED;
4593 }
4594
4595 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4596 }
4597
4598 return bgp_vty_return(vty, ret);
4599 }
4600
4601 DEFUN (neighbor_interface_config,
4602 neighbor_interface_config_cmd,
4603 "neighbor WORD interface [peer-group PGNAME]",
4604 NEIGHBOR_STR
4605 "Interface name or neighbor tag\n"
4606 "Enable BGP on interface\n"
4607 "Member of the peer-group\n"
4608 "Peer-group name\n")
4609 {
4610 int idx_word = 1;
4611 int idx_peer_group_word = 4;
4612
4613 if (argc > idx_peer_group_word)
4614 return peer_conf_interface_get(
4615 vty, argv[idx_word]->arg, 0,
4616 argv[idx_peer_group_word]->arg, NULL);
4617 else
4618 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4619 NULL, NULL);
4620 }
4621
4622 DEFUN (neighbor_interface_config_v6only,
4623 neighbor_interface_config_v6only_cmd,
4624 "neighbor WORD interface v6only [peer-group PGNAME]",
4625 NEIGHBOR_STR
4626 "Interface name or neighbor tag\n"
4627 "Enable BGP on interface\n"
4628 "Enable BGP with v6 link-local only\n"
4629 "Member of the peer-group\n"
4630 "Peer-group name\n")
4631 {
4632 int idx_word = 1;
4633 int idx_peer_group_word = 5;
4634
4635 if (argc > idx_peer_group_word)
4636 return peer_conf_interface_get(
4637 vty, argv[idx_word]->arg, 1,
4638 argv[idx_peer_group_word]->arg, NULL);
4639
4640 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4641 }
4642
4643
4644 DEFUN (neighbor_interface_config_remote_as,
4645 neighbor_interface_config_remote_as_cmd,
4646 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4647 NEIGHBOR_STR
4648 "Interface name or neighbor tag\n"
4649 "Enable BGP on interface\n"
4650 "Specify a BGP neighbor\n"
4651 AS_STR
4652 "Internal BGP peer\n"
4653 "External BGP peer\n")
4654 {
4655 int idx_word = 1;
4656 int idx_remote_as = 4;
4657 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4658 argv[idx_remote_as]->arg);
4659 }
4660
4661 DEFUN (neighbor_interface_v6only_config_remote_as,
4662 neighbor_interface_v6only_config_remote_as_cmd,
4663 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4664 NEIGHBOR_STR
4665 "Interface name or neighbor tag\n"
4666 "Enable BGP with v6 link-local only\n"
4667 "Enable BGP on interface\n"
4668 "Specify a BGP neighbor\n"
4669 AS_STR
4670 "Internal BGP peer\n"
4671 "External BGP peer\n")
4672 {
4673 int idx_word = 1;
4674 int idx_remote_as = 5;
4675 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4676 argv[idx_remote_as]->arg);
4677 }
4678
4679 DEFUN (neighbor_peer_group,
4680 neighbor_peer_group_cmd,
4681 "neighbor WORD peer-group",
4682 NEIGHBOR_STR
4683 "Interface name or neighbor tag\n"
4684 "Configure peer-group\n")
4685 {
4686 VTY_DECLVAR_CONTEXT(bgp, bgp);
4687 int idx_word = 1;
4688 struct peer *peer;
4689 struct peer_group *group;
4690
4691 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4692 if (peer) {
4693 vty_out(vty, "%% Name conflict with interface: \n");
4694 return CMD_WARNING_CONFIG_FAILED;
4695 }
4696
4697 group = peer_group_get(bgp, argv[idx_word]->arg);
4698 if (!group) {
4699 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4700 return CMD_WARNING_CONFIG_FAILED;
4701 }
4702
4703 return CMD_SUCCESS;
4704 }
4705
4706 DEFUN (no_neighbor,
4707 no_neighbor_cmd,
4708 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4709 NO_STR
4710 NEIGHBOR_STR
4711 NEIGHBOR_ADDR_STR2
4712 "Specify a BGP neighbor\n"
4713 AS_STR
4714 "Internal BGP peer\n"
4715 "External BGP peer\n")
4716 {
4717 VTY_DECLVAR_CONTEXT(bgp, bgp);
4718 int idx_peer = 2;
4719 int ret;
4720 union sockunion su;
4721 struct peer_group *group;
4722 struct peer *peer;
4723 struct peer *other;
4724
4725 ret = str2sockunion(argv[idx_peer]->arg, &su);
4726 if (ret < 0) {
4727 /* look up for neighbor by interface name config. */
4728 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4729 if (peer) {
4730 /* Request zebra to terminate IPv6 RAs on this
4731 * interface. */
4732 if (peer->ifp)
4733 bgp_zebra_terminate_radv(peer->bgp, peer);
4734 peer_notify_unconfig(peer);
4735 peer_delete(peer);
4736 return CMD_SUCCESS;
4737 }
4738
4739 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4740 if (group) {
4741 peer_group_notify_unconfig(group);
4742 peer_group_delete(group);
4743 } else {
4744 vty_out(vty, "%% Create the peer-group first\n");
4745 return CMD_WARNING_CONFIG_FAILED;
4746 }
4747 } else {
4748 peer = peer_lookup(bgp, &su);
4749 if (peer) {
4750 if (peer_dynamic_neighbor(peer)) {
4751 vty_out(vty,
4752 "%% Operation not allowed on a dynamic neighbor\n");
4753 return CMD_WARNING_CONFIG_FAILED;
4754 }
4755
4756 other = peer->doppelganger;
4757
4758 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4759 bgp_zebra_terminate_radv(peer->bgp, peer);
4760
4761 peer_notify_unconfig(peer);
4762 peer_delete(peer);
4763 if (other && other->status != Deleted) {
4764 peer_notify_unconfig(other);
4765 peer_delete(other);
4766 }
4767 }
4768 }
4769
4770 return CMD_SUCCESS;
4771 }
4772
4773 DEFUN (no_neighbor_interface_config,
4774 no_neighbor_interface_config_cmd,
4775 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4776 NO_STR
4777 NEIGHBOR_STR
4778 "Interface name\n"
4779 "Configure BGP on interface\n"
4780 "Enable BGP with v6 link-local only\n"
4781 "Member of the peer-group\n"
4782 "Peer-group name\n"
4783 "Specify a BGP neighbor\n"
4784 AS_STR
4785 "Internal BGP peer\n"
4786 "External BGP peer\n")
4787 {
4788 VTY_DECLVAR_CONTEXT(bgp, bgp);
4789 int idx_word = 2;
4790 struct peer *peer;
4791
4792 /* look up for neighbor by interface name config. */
4793 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4794 if (peer) {
4795 /* Request zebra to terminate IPv6 RAs on this interface. */
4796 if (peer->ifp)
4797 bgp_zebra_terminate_radv(peer->bgp, peer);
4798 peer_notify_unconfig(peer);
4799 peer_delete(peer);
4800 } else {
4801 vty_out(vty, "%% Create the bgp interface first\n");
4802 return CMD_WARNING_CONFIG_FAILED;
4803 }
4804 return CMD_SUCCESS;
4805 }
4806
4807 DEFUN (no_neighbor_peer_group,
4808 no_neighbor_peer_group_cmd,
4809 "no neighbor WORD peer-group",
4810 NO_STR
4811 NEIGHBOR_STR
4812 "Neighbor tag\n"
4813 "Configure peer-group\n")
4814 {
4815 VTY_DECLVAR_CONTEXT(bgp, bgp);
4816 int idx_word = 2;
4817 struct peer_group *group;
4818
4819 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4820 if (group) {
4821 peer_group_notify_unconfig(group);
4822 peer_group_delete(group);
4823 } else {
4824 vty_out(vty, "%% Create the peer-group first\n");
4825 return CMD_WARNING_CONFIG_FAILED;
4826 }
4827 return CMD_SUCCESS;
4828 }
4829
4830 DEFUN (no_neighbor_interface_peer_group_remote_as,
4831 no_neighbor_interface_peer_group_remote_as_cmd,
4832 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4833 NO_STR
4834 NEIGHBOR_STR
4835 "Interface name or neighbor tag\n"
4836 "Specify a BGP neighbor\n"
4837 AS_STR
4838 "Internal BGP peer\n"
4839 "External BGP peer\n")
4840 {
4841 VTY_DECLVAR_CONTEXT(bgp, bgp);
4842 int idx_word = 2;
4843 struct peer_group *group;
4844 struct peer *peer;
4845
4846 /* look up for neighbor by interface name config. */
4847 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4848 if (peer) {
4849 peer_as_change(peer, 0, AS_UNSPECIFIED);
4850 return CMD_SUCCESS;
4851 }
4852
4853 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4854 if (group)
4855 peer_group_remote_as_delete(group);
4856 else {
4857 vty_out(vty, "%% Create the peer-group or interface first\n");
4858 return CMD_WARNING_CONFIG_FAILED;
4859 }
4860 return CMD_SUCCESS;
4861 }
4862
4863 DEFUN (neighbor_local_as,
4864 neighbor_local_as_cmd,
4865 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4866 NEIGHBOR_STR
4867 NEIGHBOR_ADDR_STR2
4868 "Specify a local-as number\n"
4869 "AS number used as local AS\n")
4870 {
4871 int idx_peer = 1;
4872 int idx_number = 3;
4873 struct peer *peer;
4874 int ret;
4875 as_t as;
4876
4877 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4878 if (!peer)
4879 return CMD_WARNING_CONFIG_FAILED;
4880
4881 as = strtoul(argv[idx_number]->arg, NULL, 10);
4882 ret = peer_local_as_set(peer, as, 0, 0);
4883 return bgp_vty_return(vty, ret);
4884 }
4885
4886 DEFUN (neighbor_local_as_no_prepend,
4887 neighbor_local_as_no_prepend_cmd,
4888 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4889 NEIGHBOR_STR
4890 NEIGHBOR_ADDR_STR2
4891 "Specify a local-as number\n"
4892 "AS number used as local AS\n"
4893 "Do not prepend local-as to updates from ebgp peers\n")
4894 {
4895 int idx_peer = 1;
4896 int idx_number = 3;
4897 struct peer *peer;
4898 int ret;
4899 as_t as;
4900
4901 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4902 if (!peer)
4903 return CMD_WARNING_CONFIG_FAILED;
4904
4905 as = strtoul(argv[idx_number]->arg, NULL, 10);
4906 ret = peer_local_as_set(peer, as, 1, 0);
4907 return bgp_vty_return(vty, ret);
4908 }
4909
4910 DEFUN (neighbor_local_as_no_prepend_replace_as,
4911 neighbor_local_as_no_prepend_replace_as_cmd,
4912 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4913 NEIGHBOR_STR
4914 NEIGHBOR_ADDR_STR2
4915 "Specify a local-as number\n"
4916 "AS number used as local AS\n"
4917 "Do not prepend local-as to updates from ebgp peers\n"
4918 "Do not prepend local-as to updates from ibgp peers\n")
4919 {
4920 int idx_peer = 1;
4921 int idx_number = 3;
4922 struct peer *peer;
4923 int ret;
4924 as_t as;
4925
4926 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4927 if (!peer)
4928 return CMD_WARNING_CONFIG_FAILED;
4929
4930 as = strtoul(argv[idx_number]->arg, NULL, 10);
4931 ret = peer_local_as_set(peer, as, 1, 1);
4932 return bgp_vty_return(vty, ret);
4933 }
4934
4935 DEFUN (no_neighbor_local_as,
4936 no_neighbor_local_as_cmd,
4937 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4938 NO_STR
4939 NEIGHBOR_STR
4940 NEIGHBOR_ADDR_STR2
4941 "Specify a local-as number\n"
4942 "AS number used as local AS\n"
4943 "Do not prepend local-as to updates from ebgp peers\n"
4944 "Do not prepend local-as to updates from ibgp peers\n")
4945 {
4946 int idx_peer = 2;
4947 struct peer *peer;
4948 int ret;
4949
4950 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4951 if (!peer)
4952 return CMD_WARNING_CONFIG_FAILED;
4953
4954 ret = peer_local_as_unset(peer);
4955 return bgp_vty_return(vty, ret);
4956 }
4957
4958
4959 DEFUN (neighbor_solo,
4960 neighbor_solo_cmd,
4961 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4962 NEIGHBOR_STR
4963 NEIGHBOR_ADDR_STR2
4964 "Solo peer - part of its own update group\n")
4965 {
4966 int idx_peer = 1;
4967 struct peer *peer;
4968 int ret;
4969
4970 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4971 if (!peer)
4972 return CMD_WARNING_CONFIG_FAILED;
4973
4974 ret = update_group_adjust_soloness(peer, 1);
4975 return bgp_vty_return(vty, ret);
4976 }
4977
4978 DEFUN (no_neighbor_solo,
4979 no_neighbor_solo_cmd,
4980 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4981 NO_STR
4982 NEIGHBOR_STR
4983 NEIGHBOR_ADDR_STR2
4984 "Solo peer - part of its own update group\n")
4985 {
4986 int idx_peer = 2;
4987 struct peer *peer;
4988 int ret;
4989
4990 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4991 if (!peer)
4992 return CMD_WARNING_CONFIG_FAILED;
4993
4994 ret = update_group_adjust_soloness(peer, 0);
4995 return bgp_vty_return(vty, ret);
4996 }
4997
4998 DEFUN (neighbor_password,
4999 neighbor_password_cmd,
5000 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5001 NEIGHBOR_STR
5002 NEIGHBOR_ADDR_STR2
5003 "Set a password\n"
5004 "The password\n")
5005 {
5006 int idx_peer = 1;
5007 int idx_line = 3;
5008 struct peer *peer;
5009 int ret;
5010
5011 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5012 if (!peer)
5013 return CMD_WARNING_CONFIG_FAILED;
5014
5015 ret = peer_password_set(peer, argv[idx_line]->arg);
5016 return bgp_vty_return(vty, ret);
5017 }
5018
5019 DEFUN (no_neighbor_password,
5020 no_neighbor_password_cmd,
5021 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5022 NO_STR
5023 NEIGHBOR_STR
5024 NEIGHBOR_ADDR_STR2
5025 "Set a password\n"
5026 "The password\n")
5027 {
5028 int idx_peer = 2;
5029 struct peer *peer;
5030 int ret;
5031
5032 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5033 if (!peer)
5034 return CMD_WARNING_CONFIG_FAILED;
5035
5036 ret = peer_password_unset(peer);
5037 return bgp_vty_return(vty, ret);
5038 }
5039
5040 DEFUN (neighbor_activate,
5041 neighbor_activate_cmd,
5042 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "Enable the Address Family for this Neighbor\n")
5046 {
5047 int idx_peer = 1;
5048 int ret;
5049 struct peer *peer;
5050
5051 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5052 if (!peer)
5053 return CMD_WARNING_CONFIG_FAILED;
5054
5055 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5056 return bgp_vty_return(vty, ret);
5057 }
5058
5059 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5060 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5062 "Enable the Address Family for this Neighbor\n")
5063
5064 DEFUN (no_neighbor_activate,
5065 no_neighbor_activate_cmd,
5066 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5067 NO_STR
5068 NEIGHBOR_STR
5069 NEIGHBOR_ADDR_STR2
5070 "Enable the Address Family for this Neighbor\n")
5071 {
5072 int idx_peer = 2;
5073 int ret;
5074 struct peer *peer;
5075
5076 /* Lookup peer. */
5077 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5078 if (!peer)
5079 return CMD_WARNING_CONFIG_FAILED;
5080
5081 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5082 return bgp_vty_return(vty, ret);
5083 }
5084
5085 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5086 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5087 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5088 "Enable the Address Family for this Neighbor\n")
5089
5090 DEFUN (neighbor_set_peer_group,
5091 neighbor_set_peer_group_cmd,
5092 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5093 NEIGHBOR_STR
5094 NEIGHBOR_ADDR_STR2
5095 "Member of the peer-group\n"
5096 "Peer-group name\n")
5097 {
5098 VTY_DECLVAR_CONTEXT(bgp, bgp);
5099 int idx_peer = 1;
5100 int idx_word = 3;
5101 int ret;
5102 as_t as;
5103 union sockunion su;
5104 struct peer *peer;
5105 struct peer_group *group;
5106
5107 ret = str2sockunion(argv[idx_peer]->arg, &su);
5108 if (ret < 0) {
5109 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5110 if (!peer) {
5111 vty_out(vty, "%% Malformed address or name: %s\n",
5112 argv[idx_peer]->arg);
5113 return CMD_WARNING_CONFIG_FAILED;
5114 }
5115 } else {
5116 if (peer_address_self_check(bgp, &su)) {
5117 vty_out(vty,
5118 "%% Can not configure the local system as neighbor\n");
5119 return CMD_WARNING_CONFIG_FAILED;
5120 }
5121
5122 /* Disallow for dynamic neighbor. */
5123 peer = peer_lookup(bgp, &su);
5124 if (peer && peer_dynamic_neighbor(peer)) {
5125 vty_out(vty,
5126 "%% Operation not allowed on a dynamic neighbor\n");
5127 return CMD_WARNING_CONFIG_FAILED;
5128 }
5129 }
5130
5131 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5132 if (!group) {
5133 vty_out(vty, "%% Configure the peer-group first\n");
5134 return CMD_WARNING_CONFIG_FAILED;
5135 }
5136
5137 ret = peer_group_bind(bgp, &su, peer, group, &as);
5138
5139 return bgp_vty_return(vty, ret);
5140 }
5141
5142 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5143 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5144 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5145 "Member of the peer-group\n"
5146 "Peer-group name\n")
5147
5148 DEFUN (no_neighbor_set_peer_group,
5149 no_neighbor_set_peer_group_cmd,
5150 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5151 NO_STR
5152 NEIGHBOR_STR
5153 NEIGHBOR_ADDR_STR2
5154 "Member of the peer-group\n"
5155 "Peer-group name\n")
5156 {
5157 VTY_DECLVAR_CONTEXT(bgp, bgp);
5158 int idx_peer = 2;
5159 int idx_word = 4;
5160 int ret;
5161 struct peer *peer;
5162 struct peer_group *group;
5163
5164 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5165 if (!peer)
5166 return CMD_WARNING_CONFIG_FAILED;
5167
5168 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5169 if (!group) {
5170 vty_out(vty, "%% Configure the peer-group first\n");
5171 return CMD_WARNING_CONFIG_FAILED;
5172 }
5173
5174 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5175 bgp_zebra_terminate_radv(peer->bgp, peer);
5176
5177 peer_notify_unconfig(peer);
5178 ret = peer_delete(peer);
5179
5180 return bgp_vty_return(vty, ret);
5181 }
5182
5183 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5184 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5185 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5186 "Member of the peer-group\n"
5187 "Peer-group name\n")
5188
5189 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5190 uint64_t flag, int set)
5191 {
5192 int ret;
5193 struct peer *peer;
5194
5195 peer = peer_and_group_lookup_vty(vty, ip_str);
5196 if (!peer)
5197 return CMD_WARNING_CONFIG_FAILED;
5198
5199 /*
5200 * If 'neighbor <interface>', then this is for directly connected peers,
5201 * we should not accept disable-connected-check.
5202 */
5203 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5204 vty_out(vty,
5205 "%s is directly connected peer, cannot accept disable-connected-check\n",
5206 ip_str);
5207 return CMD_WARNING_CONFIG_FAILED;
5208 }
5209
5210 if (!set && flag == PEER_FLAG_SHUTDOWN)
5211 peer_tx_shutdown_message_unset(peer);
5212
5213 if (set)
5214 ret = peer_flag_set(peer, flag);
5215 else
5216 ret = peer_flag_unset(peer, flag);
5217
5218 return bgp_vty_return(vty, ret);
5219 }
5220
5221 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5222 {
5223 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5224 }
5225
5226 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5227 uint64_t flag)
5228 {
5229 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5230 }
5231
5232 /* neighbor passive. */
5233 DEFUN (neighbor_passive,
5234 neighbor_passive_cmd,
5235 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5236 NEIGHBOR_STR
5237 NEIGHBOR_ADDR_STR2
5238 "Don't send open messages to this neighbor\n")
5239 {
5240 int idx_peer = 1;
5241 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5242 }
5243
5244 DEFUN (no_neighbor_passive,
5245 no_neighbor_passive_cmd,
5246 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5247 NO_STR
5248 NEIGHBOR_STR
5249 NEIGHBOR_ADDR_STR2
5250 "Don't send open messages to this neighbor\n")
5251 {
5252 int idx_peer = 2;
5253 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5254 }
5255
5256 /* neighbor shutdown. */
5257 DEFUN (neighbor_shutdown_msg,
5258 neighbor_shutdown_msg_cmd,
5259 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5260 NEIGHBOR_STR
5261 NEIGHBOR_ADDR_STR2
5262 "Administratively shut down this neighbor\n"
5263 "Add a shutdown message (RFC 8203)\n"
5264 "Shutdown message\n")
5265 {
5266 int idx_peer = 1;
5267
5268 if (argc >= 5) {
5269 struct peer *peer =
5270 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5271 char *message;
5272
5273 if (!peer)
5274 return CMD_WARNING_CONFIG_FAILED;
5275 message = argv_concat(argv, argc, 4);
5276 peer_tx_shutdown_message_set(peer, message);
5277 XFREE(MTYPE_TMP, message);
5278 }
5279
5280 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5281 }
5282
5283 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5284 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5285 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5286 "Administratively shut down this neighbor\n")
5287
5288 DEFUN (no_neighbor_shutdown_msg,
5289 no_neighbor_shutdown_msg_cmd,
5290 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5291 NO_STR
5292 NEIGHBOR_STR
5293 NEIGHBOR_ADDR_STR2
5294 "Administratively shut down this neighbor\n"
5295 "Remove a shutdown message (RFC 8203)\n"
5296 "Shutdown message\n")
5297 {
5298 int idx_peer = 2;
5299
5300 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5301 PEER_FLAG_SHUTDOWN);
5302 }
5303
5304 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5305 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5306 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5307 "Administratively shut down this neighbor\n")
5308
5309 DEFUN(neighbor_shutdown_rtt,
5310 neighbor_shutdown_rtt_cmd,
5311 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5312 NEIGHBOR_STR
5313 NEIGHBOR_ADDR_STR2
5314 "Administratively shut down this neighbor\n"
5315 "Shutdown if round-trip-time is higher than expected\n"
5316 "Round-trip-time in milliseconds\n"
5317 "Specify the number of keepalives before shutdown\n"
5318 "The number of keepalives with higher RTT to shutdown\n")
5319 {
5320 int idx_peer = 1;
5321 int idx_rtt = 4;
5322 int idx_count = 0;
5323 struct peer *peer;
5324
5325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5326
5327 if (!peer)
5328 return CMD_WARNING_CONFIG_FAILED;
5329
5330 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5331
5332 if (argv_find(argv, argc, "count", &idx_count))
5333 peer->rtt_keepalive_conf =
5334 strtol(argv[idx_count + 1]->arg, NULL, 10);
5335
5336 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5337 PEER_FLAG_RTT_SHUTDOWN);
5338 }
5339
5340 DEFUN(no_neighbor_shutdown_rtt,
5341 no_neighbor_shutdown_rtt_cmd,
5342 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5343 NO_STR
5344 NEIGHBOR_STR
5345 NEIGHBOR_ADDR_STR2
5346 "Administratively shut down this neighbor\n"
5347 "Shutdown if round-trip-time is higher than expected\n"
5348 "Round-trip-time in milliseconds\n"
5349 "Specify the number of keepalives before shutdown\n"
5350 "The number of keepalives with higher RTT to shutdown\n")
5351 {
5352 int idx_peer = 2;
5353 struct peer *peer;
5354
5355 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5356
5357 if (!peer)
5358 return CMD_WARNING_CONFIG_FAILED;
5359
5360 peer->rtt_expected = 0;
5361 peer->rtt_keepalive_conf = 1;
5362
5363 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5364 PEER_FLAG_RTT_SHUTDOWN);
5365 }
5366
5367 /* neighbor capability dynamic. */
5368 DEFUN (neighbor_capability_dynamic,
5369 neighbor_capability_dynamic_cmd,
5370 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5371 NEIGHBOR_STR
5372 NEIGHBOR_ADDR_STR2
5373 "Advertise capability to the peer\n"
5374 "Advertise dynamic capability to this neighbor\n")
5375 {
5376 int idx_peer = 1;
5377 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5378 PEER_FLAG_DYNAMIC_CAPABILITY);
5379 }
5380
5381 DEFUN (no_neighbor_capability_dynamic,
5382 no_neighbor_capability_dynamic_cmd,
5383 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5384 NO_STR
5385 NEIGHBOR_STR
5386 NEIGHBOR_ADDR_STR2
5387 "Advertise capability to the peer\n"
5388 "Advertise dynamic capability to this neighbor\n")
5389 {
5390 int idx_peer = 2;
5391 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5392 PEER_FLAG_DYNAMIC_CAPABILITY);
5393 }
5394
5395 /* neighbor dont-capability-negotiate */
5396 DEFUN (neighbor_dont_capability_negotiate,
5397 neighbor_dont_capability_negotiate_cmd,
5398 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5399 NEIGHBOR_STR
5400 NEIGHBOR_ADDR_STR2
5401 "Do not perform capability negotiation\n")
5402 {
5403 int idx_peer = 1;
5404 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5405 PEER_FLAG_DONT_CAPABILITY);
5406 }
5407
5408 DEFUN (no_neighbor_dont_capability_negotiate,
5409 no_neighbor_dont_capability_negotiate_cmd,
5410 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5411 NO_STR
5412 NEIGHBOR_STR
5413 NEIGHBOR_ADDR_STR2
5414 "Do not perform capability negotiation\n")
5415 {
5416 int idx_peer = 2;
5417 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5418 PEER_FLAG_DONT_CAPABILITY);
5419 }
5420
5421 /* neighbor capability extended next hop encoding */
5422 DEFUN (neighbor_capability_enhe,
5423 neighbor_capability_enhe_cmd,
5424 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5425 NEIGHBOR_STR
5426 NEIGHBOR_ADDR_STR2
5427 "Advertise capability to the peer\n"
5428 "Advertise extended next-hop capability to the peer\n")
5429 {
5430 int idx_peer = 1;
5431 struct peer *peer;
5432
5433 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5434 if (peer && peer->conf_if)
5435 return CMD_SUCCESS;
5436
5437 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5438 PEER_FLAG_CAPABILITY_ENHE);
5439 }
5440
5441 DEFUN (no_neighbor_capability_enhe,
5442 no_neighbor_capability_enhe_cmd,
5443 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5444 NO_STR
5445 NEIGHBOR_STR
5446 NEIGHBOR_ADDR_STR2
5447 "Advertise capability to the peer\n"
5448 "Advertise extended next-hop capability to the peer\n")
5449 {
5450 int idx_peer = 2;
5451 struct peer *peer;
5452
5453 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5454 if (peer && peer->conf_if) {
5455 vty_out(vty,
5456 "Peer %s cannot have capability extended-nexthop turned off\n",
5457 argv[idx_peer]->arg);
5458 return CMD_WARNING_CONFIG_FAILED;
5459 }
5460
5461 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5462 PEER_FLAG_CAPABILITY_ENHE);
5463 }
5464
5465 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5466 afi_t afi, safi_t safi, uint32_t flag,
5467 int set)
5468 {
5469 int ret;
5470 struct peer *peer;
5471
5472 peer = peer_and_group_lookup_vty(vty, peer_str);
5473 if (!peer)
5474 return CMD_WARNING_CONFIG_FAILED;
5475
5476 if (set)
5477 ret = peer_af_flag_set(peer, afi, safi, flag);
5478 else
5479 ret = peer_af_flag_unset(peer, afi, safi, flag);
5480
5481 return bgp_vty_return(vty, ret);
5482 }
5483
5484 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5485 afi_t afi, safi_t safi, uint32_t flag)
5486 {
5487 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5488 }
5489
5490 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5491 afi_t afi, safi_t safi, uint32_t flag)
5492 {
5493 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5494 }
5495
5496 /* neighbor capability orf prefix-list. */
5497 DEFUN (neighbor_capability_orf_prefix,
5498 neighbor_capability_orf_prefix_cmd,
5499 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5500 NEIGHBOR_STR
5501 NEIGHBOR_ADDR_STR2
5502 "Advertise capability to the peer\n"
5503 "Advertise ORF capability to the peer\n"
5504 "Advertise prefixlist ORF capability to this neighbor\n"
5505 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5506 "Capability to RECEIVE the ORF from this neighbor\n"
5507 "Capability to SEND the ORF to this neighbor\n")
5508 {
5509 int idx_send_recv = 5;
5510 char *peer_str = argv[1]->arg;
5511 struct peer *peer;
5512 afi_t afi = bgp_node_afi(vty);
5513 safi_t safi = bgp_node_safi(vty);
5514
5515 peer = peer_and_group_lookup_vty(vty, peer_str);
5516 if (!peer)
5517 return CMD_WARNING_CONFIG_FAILED;
5518
5519 if (strmatch(argv[idx_send_recv]->text, "send"))
5520 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5521 PEER_FLAG_ORF_PREFIX_SM);
5522
5523 if (strmatch(argv[idx_send_recv]->text, "receive"))
5524 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5525 PEER_FLAG_ORF_PREFIX_RM);
5526
5527 if (strmatch(argv[idx_send_recv]->text, "both"))
5528 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5529 PEER_FLAG_ORF_PREFIX_SM)
5530 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5531 PEER_FLAG_ORF_PREFIX_RM);
5532
5533 return CMD_WARNING_CONFIG_FAILED;
5534 }
5535
5536 ALIAS_HIDDEN(
5537 neighbor_capability_orf_prefix,
5538 neighbor_capability_orf_prefix_hidden_cmd,
5539 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5540 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5541 "Advertise capability to the peer\n"
5542 "Advertise ORF capability to the peer\n"
5543 "Advertise prefixlist ORF capability to this neighbor\n"
5544 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5545 "Capability to RECEIVE the ORF from this neighbor\n"
5546 "Capability to SEND the ORF to this neighbor\n")
5547
5548 DEFUN (no_neighbor_capability_orf_prefix,
5549 no_neighbor_capability_orf_prefix_cmd,
5550 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5551 NO_STR
5552 NEIGHBOR_STR
5553 NEIGHBOR_ADDR_STR2
5554 "Advertise capability to the peer\n"
5555 "Advertise ORF capability to the peer\n"
5556 "Advertise prefixlist ORF capability to this neighbor\n"
5557 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5558 "Capability to RECEIVE the ORF from this neighbor\n"
5559 "Capability to SEND the ORF to this neighbor\n")
5560 {
5561 int idx_send_recv = 6;
5562 char *peer_str = argv[2]->arg;
5563 struct peer *peer;
5564 afi_t afi = bgp_node_afi(vty);
5565 safi_t safi = bgp_node_safi(vty);
5566
5567 peer = peer_and_group_lookup_vty(vty, peer_str);
5568 if (!peer)
5569 return CMD_WARNING_CONFIG_FAILED;
5570
5571 if (strmatch(argv[idx_send_recv]->text, "send"))
5572 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5573 PEER_FLAG_ORF_PREFIX_SM);
5574
5575 if (strmatch(argv[idx_send_recv]->text, "receive"))
5576 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5577 PEER_FLAG_ORF_PREFIX_RM);
5578
5579 if (strmatch(argv[idx_send_recv]->text, "both"))
5580 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5581 PEER_FLAG_ORF_PREFIX_SM)
5582 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5583 PEER_FLAG_ORF_PREFIX_RM);
5584
5585 return CMD_WARNING_CONFIG_FAILED;
5586 }
5587
5588 ALIAS_HIDDEN(
5589 no_neighbor_capability_orf_prefix,
5590 no_neighbor_capability_orf_prefix_hidden_cmd,
5591 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5592 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5593 "Advertise capability to the peer\n"
5594 "Advertise ORF capability to the peer\n"
5595 "Advertise prefixlist ORF capability to this neighbor\n"
5596 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5597 "Capability to RECEIVE the ORF from this neighbor\n"
5598 "Capability to SEND the ORF to this neighbor\n")
5599
5600 /* neighbor next-hop-self. */
5601 DEFUN (neighbor_nexthop_self,
5602 neighbor_nexthop_self_cmd,
5603 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5604 NEIGHBOR_STR
5605 NEIGHBOR_ADDR_STR2
5606 "Disable the next hop calculation for this neighbor\n")
5607 {
5608 int idx_peer = 1;
5609 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5610 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5611 }
5612
5613 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5614 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5615 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5616 "Disable the next hop calculation for this neighbor\n")
5617
5618 /* neighbor next-hop-self. */
5619 DEFUN (neighbor_nexthop_self_force,
5620 neighbor_nexthop_self_force_cmd,
5621 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5622 NEIGHBOR_STR
5623 NEIGHBOR_ADDR_STR2
5624 "Disable the next hop calculation for this neighbor\n"
5625 "Set the next hop to self for reflected routes\n")
5626 {
5627 int idx_peer = 1;
5628 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5629 bgp_node_safi(vty),
5630 PEER_FLAG_FORCE_NEXTHOP_SELF);
5631 }
5632
5633 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5634 neighbor_nexthop_self_force_hidden_cmd,
5635 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5636 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5637 "Disable the next hop calculation for this neighbor\n"
5638 "Set the next hop to self for reflected routes\n")
5639
5640 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5641 neighbor_nexthop_self_all_hidden_cmd,
5642 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5643 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5644 "Disable the next hop calculation for this neighbor\n"
5645 "Set the next hop to self for reflected routes\n")
5646
5647 DEFUN (no_neighbor_nexthop_self,
5648 no_neighbor_nexthop_self_cmd,
5649 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5650 NO_STR
5651 NEIGHBOR_STR
5652 NEIGHBOR_ADDR_STR2
5653 "Disable the next hop calculation for this neighbor\n")
5654 {
5655 int idx_peer = 2;
5656 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5657 bgp_node_afi(vty), bgp_node_safi(vty),
5658 PEER_FLAG_NEXTHOP_SELF);
5659 }
5660
5661 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5662 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5663 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5664 "Disable the next hop calculation for this neighbor\n")
5665
5666 DEFUN (no_neighbor_nexthop_self_force,
5667 no_neighbor_nexthop_self_force_cmd,
5668 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5669 NO_STR
5670 NEIGHBOR_STR
5671 NEIGHBOR_ADDR_STR2
5672 "Disable the next hop calculation for this neighbor\n"
5673 "Set the next hop to self for reflected routes\n")
5674 {
5675 int idx_peer = 2;
5676 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5677 bgp_node_afi(vty), bgp_node_safi(vty),
5678 PEER_FLAG_FORCE_NEXTHOP_SELF);
5679 }
5680
5681 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5682 no_neighbor_nexthop_self_force_hidden_cmd,
5683 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5684 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5685 "Disable the next hop calculation for this neighbor\n"
5686 "Set the next hop to self for reflected routes\n")
5687
5688 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5689 no_neighbor_nexthop_self_all_hidden_cmd,
5690 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5691 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5692 "Disable the next hop calculation for this neighbor\n"
5693 "Set the next hop to self for reflected routes\n")
5694
5695 /* neighbor as-override */
5696 DEFUN (neighbor_as_override,
5697 neighbor_as_override_cmd,
5698 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5699 NEIGHBOR_STR
5700 NEIGHBOR_ADDR_STR2
5701 "Override ASNs in outbound updates if aspath equals remote-as\n")
5702 {
5703 int idx_peer = 1;
5704 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5705 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5706 }
5707
5708 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5709 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5710 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5711 "Override ASNs in outbound updates if aspath equals remote-as\n")
5712
5713 DEFUN (no_neighbor_as_override,
5714 no_neighbor_as_override_cmd,
5715 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5716 NO_STR
5717 NEIGHBOR_STR
5718 NEIGHBOR_ADDR_STR2
5719 "Override ASNs in outbound updates if aspath equals remote-as\n")
5720 {
5721 int idx_peer = 2;
5722 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5723 bgp_node_afi(vty), bgp_node_safi(vty),
5724 PEER_FLAG_AS_OVERRIDE);
5725 }
5726
5727 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5728 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5729 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5730 "Override ASNs in outbound updates if aspath equals remote-as\n")
5731
5732 /* neighbor remove-private-AS. */
5733 DEFUN (neighbor_remove_private_as,
5734 neighbor_remove_private_as_cmd,
5735 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5736 NEIGHBOR_STR
5737 NEIGHBOR_ADDR_STR2
5738 "Remove private ASNs in outbound updates\n")
5739 {
5740 int idx_peer = 1;
5741 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5742 bgp_node_safi(vty),
5743 PEER_FLAG_REMOVE_PRIVATE_AS);
5744 }
5745
5746 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5747 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5748 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5749 "Remove private ASNs in outbound updates\n")
5750
5751 DEFUN (neighbor_remove_private_as_all,
5752 neighbor_remove_private_as_all_cmd,
5753 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5754 NEIGHBOR_STR
5755 NEIGHBOR_ADDR_STR2
5756 "Remove private ASNs in outbound updates\n"
5757 "Apply to all AS numbers\n")
5758 {
5759 int idx_peer = 1;
5760 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5761 bgp_node_safi(vty),
5762 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5763 }
5764
5765 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5766 neighbor_remove_private_as_all_hidden_cmd,
5767 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5768 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5769 "Remove private ASNs in outbound updates\n"
5770 "Apply to all AS numbers")
5771
5772 DEFUN (neighbor_remove_private_as_replace_as,
5773 neighbor_remove_private_as_replace_as_cmd,
5774 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5775 NEIGHBOR_STR
5776 NEIGHBOR_ADDR_STR2
5777 "Remove private ASNs in outbound updates\n"
5778 "Replace private ASNs with our ASN in outbound updates\n")
5779 {
5780 int idx_peer = 1;
5781 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5782 bgp_node_safi(vty),
5783 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5784 }
5785
5786 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5787 neighbor_remove_private_as_replace_as_hidden_cmd,
5788 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5789 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5790 "Remove private ASNs in outbound updates\n"
5791 "Replace private ASNs with our ASN in outbound updates\n")
5792
5793 DEFUN (neighbor_remove_private_as_all_replace_as,
5794 neighbor_remove_private_as_all_replace_as_cmd,
5795 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5796 NEIGHBOR_STR
5797 NEIGHBOR_ADDR_STR2
5798 "Remove private ASNs in outbound updates\n"
5799 "Apply to all AS numbers\n"
5800 "Replace private ASNs with our ASN in outbound updates\n")
5801 {
5802 int idx_peer = 1;
5803 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5804 bgp_node_safi(vty),
5805 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5806 }
5807
5808 ALIAS_HIDDEN(
5809 neighbor_remove_private_as_all_replace_as,
5810 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5813 "Remove private ASNs in outbound updates\n"
5814 "Apply to all AS numbers\n"
5815 "Replace private ASNs with our ASN in outbound updates\n")
5816
5817 DEFUN (no_neighbor_remove_private_as,
5818 no_neighbor_remove_private_as_cmd,
5819 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5820 NO_STR
5821 NEIGHBOR_STR
5822 NEIGHBOR_ADDR_STR2
5823 "Remove private ASNs in outbound updates\n")
5824 {
5825 int idx_peer = 2;
5826 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5827 bgp_node_afi(vty), bgp_node_safi(vty),
5828 PEER_FLAG_REMOVE_PRIVATE_AS);
5829 }
5830
5831 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5832 no_neighbor_remove_private_as_hidden_cmd,
5833 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5834 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5835 "Remove private ASNs in outbound updates\n")
5836
5837 DEFUN (no_neighbor_remove_private_as_all,
5838 no_neighbor_remove_private_as_all_cmd,
5839 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5840 NO_STR
5841 NEIGHBOR_STR
5842 NEIGHBOR_ADDR_STR2
5843 "Remove private ASNs in outbound updates\n"
5844 "Apply to all AS numbers\n")
5845 {
5846 int idx_peer = 2;
5847 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5848 bgp_node_afi(vty), bgp_node_safi(vty),
5849 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5850 }
5851
5852 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5853 no_neighbor_remove_private_as_all_hidden_cmd,
5854 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5855 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Remove private ASNs in outbound updates\n"
5857 "Apply to all AS numbers\n")
5858
5859 DEFUN (no_neighbor_remove_private_as_replace_as,
5860 no_neighbor_remove_private_as_replace_as_cmd,
5861 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5862 NO_STR
5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
5865 "Remove private ASNs in outbound updates\n"
5866 "Replace private ASNs with our ASN in outbound updates\n")
5867 {
5868 int idx_peer = 2;
5869 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5870 bgp_node_afi(vty), bgp_node_safi(vty),
5871 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5872 }
5873
5874 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5875 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5876 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5877 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5878 "Remove private ASNs in outbound updates\n"
5879 "Replace private ASNs with our ASN in outbound updates\n")
5880
5881 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5882 no_neighbor_remove_private_as_all_replace_as_cmd,
5883 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5884 NO_STR
5885 NEIGHBOR_STR
5886 NEIGHBOR_ADDR_STR2
5887 "Remove private ASNs in outbound updates\n"
5888 "Apply to all AS numbers\n"
5889 "Replace private ASNs with our ASN in outbound updates\n")
5890 {
5891 int idx_peer = 2;
5892 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5893 bgp_node_afi(vty), bgp_node_safi(vty),
5894 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5895 }
5896
5897 ALIAS_HIDDEN(
5898 no_neighbor_remove_private_as_all_replace_as,
5899 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5900 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5901 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5902 "Remove private ASNs in outbound updates\n"
5903 "Apply to all AS numbers\n"
5904 "Replace private ASNs with our ASN in outbound updates\n")
5905
5906
5907 /* neighbor send-community. */
5908 DEFUN (neighbor_send_community,
5909 neighbor_send_community_cmd,
5910 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5911 NEIGHBOR_STR
5912 NEIGHBOR_ADDR_STR2
5913 "Send Community attribute to this neighbor\n")
5914 {
5915 int idx_peer = 1;
5916
5917 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5918 bgp_node_safi(vty),
5919 PEER_FLAG_SEND_COMMUNITY);
5920 }
5921
5922 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5925 "Send Community attribute to this neighbor\n")
5926
5927 DEFUN (no_neighbor_send_community,
5928 no_neighbor_send_community_cmd,
5929 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5930 NO_STR
5931 NEIGHBOR_STR
5932 NEIGHBOR_ADDR_STR2
5933 "Send Community attribute to this neighbor\n")
5934 {
5935 int idx_peer = 2;
5936
5937 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5938 bgp_node_afi(vty), bgp_node_safi(vty),
5939 PEER_FLAG_SEND_COMMUNITY);
5940 }
5941
5942 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5943 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5944 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5945 "Send Community attribute to this neighbor\n")
5946
5947 /* neighbor send-community extended. */
5948 DEFUN (neighbor_send_community_type,
5949 neighbor_send_community_type_cmd,
5950 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5951 NEIGHBOR_STR
5952 NEIGHBOR_ADDR_STR2
5953 "Send Community attribute to this neighbor\n"
5954 "Send Standard and Extended Community attributes\n"
5955 "Send Standard, Large and Extended Community attributes\n"
5956 "Send Extended Community attributes\n"
5957 "Send Standard Community attributes\n"
5958 "Send Large Community attributes\n")
5959 {
5960 const char *type = argv[argc - 1]->text;
5961 char *peer_str = argv[1]->arg;
5962 struct peer *peer;
5963 afi_t afi = bgp_node_afi(vty);
5964 safi_t safi = bgp_node_safi(vty);
5965
5966 peer = peer_and_group_lookup_vty(vty, peer_str);
5967 if (!peer)
5968 return CMD_WARNING_CONFIG_FAILED;
5969
5970 if (strmatch(type, "standard"))
5971 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5972 PEER_FLAG_SEND_COMMUNITY);
5973
5974 if (strmatch(type, "extended"))
5975 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5976 PEER_FLAG_SEND_EXT_COMMUNITY);
5977
5978 if (strmatch(type, "large"))
5979 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5980 PEER_FLAG_SEND_LARGE_COMMUNITY);
5981
5982 if (strmatch(type, "both")) {
5983 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5984 PEER_FLAG_SEND_COMMUNITY)
5985 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5986 PEER_FLAG_SEND_EXT_COMMUNITY);
5987 }
5988 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5989 PEER_FLAG_SEND_COMMUNITY)
5990 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5991 PEER_FLAG_SEND_EXT_COMMUNITY)
5992 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5993 PEER_FLAG_SEND_LARGE_COMMUNITY);
5994 }
5995
5996 ALIAS_HIDDEN(
5997 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5998 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5999 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6000 "Send Community attribute to this neighbor\n"
6001 "Send Standard and Extended Community attributes\n"
6002 "Send Standard, Large and Extended Community attributes\n"
6003 "Send Extended Community attributes\n"
6004 "Send Standard Community attributes\n"
6005 "Send Large Community attributes\n")
6006
6007 DEFUN (no_neighbor_send_community_type,
6008 no_neighbor_send_community_type_cmd,
6009 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6010 NO_STR
6011 NEIGHBOR_STR
6012 NEIGHBOR_ADDR_STR2
6013 "Send Community attribute to this neighbor\n"
6014 "Send Standard and Extended Community attributes\n"
6015 "Send Standard, Large and Extended Community attributes\n"
6016 "Send Extended Community attributes\n"
6017 "Send Standard Community attributes\n"
6018 "Send Large Community attributes\n")
6019 {
6020 const char *type = argv[argc - 1]->text;
6021 char *peer_str = argv[2]->arg;
6022 struct peer *peer;
6023 afi_t afi = bgp_node_afi(vty);
6024 safi_t safi = bgp_node_safi(vty);
6025
6026 peer = peer_and_group_lookup_vty(vty, peer_str);
6027 if (!peer)
6028 return CMD_WARNING_CONFIG_FAILED;
6029
6030 if (strmatch(type, "standard"))
6031 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6032 PEER_FLAG_SEND_COMMUNITY);
6033
6034 if (strmatch(type, "extended"))
6035 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6036 PEER_FLAG_SEND_EXT_COMMUNITY);
6037
6038 if (strmatch(type, "large"))
6039 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6040 PEER_FLAG_SEND_LARGE_COMMUNITY);
6041
6042 if (strmatch(type, "both")) {
6043
6044 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6045 PEER_FLAG_SEND_COMMUNITY)
6046 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6047 PEER_FLAG_SEND_EXT_COMMUNITY);
6048 }
6049
6050 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6051 PEER_FLAG_SEND_COMMUNITY)
6052 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6053 PEER_FLAG_SEND_EXT_COMMUNITY)
6054 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6055 PEER_FLAG_SEND_LARGE_COMMUNITY);
6056 }
6057
6058 ALIAS_HIDDEN(
6059 no_neighbor_send_community_type,
6060 no_neighbor_send_community_type_hidden_cmd,
6061 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6063 "Send Community attribute to this neighbor\n"
6064 "Send Standard and Extended Community attributes\n"
6065 "Send Standard, Large and Extended Community attributes\n"
6066 "Send Extended Community attributes\n"
6067 "Send Standard Community attributes\n"
6068 "Send Large Community attributes\n")
6069
6070 /* neighbor soft-reconfig. */
6071 DEFUN (neighbor_soft_reconfiguration,
6072 neighbor_soft_reconfiguration_cmd,
6073 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6074 NEIGHBOR_STR
6075 NEIGHBOR_ADDR_STR2
6076 "Per neighbor soft reconfiguration\n"
6077 "Allow inbound soft reconfiguration for this neighbor\n")
6078 {
6079 int idx_peer = 1;
6080 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6081 bgp_node_safi(vty),
6082 PEER_FLAG_SOFT_RECONFIG);
6083 }
6084
6085 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6086 neighbor_soft_reconfiguration_hidden_cmd,
6087 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6089 "Per neighbor soft reconfiguration\n"
6090 "Allow inbound soft reconfiguration for this neighbor\n")
6091
6092 DEFUN (no_neighbor_soft_reconfiguration,
6093 no_neighbor_soft_reconfiguration_cmd,
6094 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6095 NO_STR
6096 NEIGHBOR_STR
6097 NEIGHBOR_ADDR_STR2
6098 "Per neighbor soft reconfiguration\n"
6099 "Allow inbound soft reconfiguration for this neighbor\n")
6100 {
6101 int idx_peer = 2;
6102 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6103 bgp_node_afi(vty), bgp_node_safi(vty),
6104 PEER_FLAG_SOFT_RECONFIG);
6105 }
6106
6107 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6108 no_neighbor_soft_reconfiguration_hidden_cmd,
6109 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6110 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6111 "Per neighbor soft reconfiguration\n"
6112 "Allow inbound soft reconfiguration for this neighbor\n")
6113
6114 DEFUN (neighbor_route_reflector_client,
6115 neighbor_route_reflector_client_cmd,
6116 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "Configure a neighbor as Route Reflector client\n")
6120 {
6121 int idx_peer = 1;
6122 struct peer *peer;
6123
6124
6125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6126 if (!peer)
6127 return CMD_WARNING_CONFIG_FAILED;
6128
6129 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6130 bgp_node_safi(vty),
6131 PEER_FLAG_REFLECTOR_CLIENT);
6132 }
6133
6134 ALIAS_HIDDEN(neighbor_route_reflector_client,
6135 neighbor_route_reflector_client_hidden_cmd,
6136 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6138 "Configure a neighbor as Route Reflector client\n")
6139
6140 DEFUN (no_neighbor_route_reflector_client,
6141 no_neighbor_route_reflector_client_cmd,
6142 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6143 NO_STR
6144 NEIGHBOR_STR
6145 NEIGHBOR_ADDR_STR2
6146 "Configure a neighbor as Route Reflector client\n")
6147 {
6148 int idx_peer = 2;
6149 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6150 bgp_node_afi(vty), bgp_node_safi(vty),
6151 PEER_FLAG_REFLECTOR_CLIENT);
6152 }
6153
6154 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6155 no_neighbor_route_reflector_client_hidden_cmd,
6156 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6157 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6158 "Configure a neighbor as Route Reflector client\n")
6159
6160 /* neighbor route-server-client. */
6161 DEFUN (neighbor_route_server_client,
6162 neighbor_route_server_client_cmd,
6163 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6164 NEIGHBOR_STR
6165 NEIGHBOR_ADDR_STR2
6166 "Configure a neighbor as Route Server client\n")
6167 {
6168 int idx_peer = 1;
6169 struct peer *peer;
6170
6171 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6172 if (!peer)
6173 return CMD_WARNING_CONFIG_FAILED;
6174 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6175 bgp_node_safi(vty),
6176 PEER_FLAG_RSERVER_CLIENT);
6177 }
6178
6179 ALIAS_HIDDEN(neighbor_route_server_client,
6180 neighbor_route_server_client_hidden_cmd,
6181 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6183 "Configure a neighbor as Route Server client\n")
6184
6185 DEFUN (no_neighbor_route_server_client,
6186 no_neighbor_route_server_client_cmd,
6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6188 NO_STR
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "Configure a neighbor as Route Server client\n")
6192 {
6193 int idx_peer = 2;
6194 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6195 bgp_node_afi(vty), bgp_node_safi(vty),
6196 PEER_FLAG_RSERVER_CLIENT);
6197 }
6198
6199 ALIAS_HIDDEN(no_neighbor_route_server_client,
6200 no_neighbor_route_server_client_hidden_cmd,
6201 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6203 "Configure a neighbor as Route Server client\n")
6204
6205 DEFUN (neighbor_nexthop_local_unchanged,
6206 neighbor_nexthop_local_unchanged_cmd,
6207 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6208 NEIGHBOR_STR
6209 NEIGHBOR_ADDR_STR2
6210 "Configure treatment of outgoing link-local nexthop attribute\n"
6211 "Leave link-local nexthop unchanged for this peer\n")
6212 {
6213 int idx_peer = 1;
6214 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6215 bgp_node_safi(vty),
6216 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6217 }
6218
6219 DEFUN (no_neighbor_nexthop_local_unchanged,
6220 no_neighbor_nexthop_local_unchanged_cmd,
6221 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6222 NO_STR
6223 NEIGHBOR_STR
6224 NEIGHBOR_ADDR_STR2
6225 "Configure treatment of outgoing link-local-nexthop attribute\n"
6226 "Leave link-local nexthop unchanged for this peer\n")
6227 {
6228 int idx_peer = 2;
6229 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6230 bgp_node_afi(vty), bgp_node_safi(vty),
6231 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6232 }
6233
6234 DEFUN (neighbor_attr_unchanged,
6235 neighbor_attr_unchanged_cmd,
6236 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6237 NEIGHBOR_STR
6238 NEIGHBOR_ADDR_STR2
6239 "BGP attribute is propagated unchanged to this neighbor\n"
6240 "As-path attribute\n"
6241 "Nexthop attribute\n"
6242 "Med attribute\n")
6243 {
6244 int idx = 0;
6245 char *peer_str = argv[1]->arg;
6246 struct peer *peer;
6247 bool aspath = false;
6248 bool nexthop = false;
6249 bool med = false;
6250 afi_t afi = bgp_node_afi(vty);
6251 safi_t safi = bgp_node_safi(vty);
6252 int ret = 0;
6253
6254 peer = peer_and_group_lookup_vty(vty, peer_str);
6255 if (!peer)
6256 return CMD_WARNING_CONFIG_FAILED;
6257
6258 if (argv_find(argv, argc, "as-path", &idx))
6259 aspath = true;
6260
6261 idx = 0;
6262 if (argv_find(argv, argc, "next-hop", &idx))
6263 nexthop = true;
6264
6265 idx = 0;
6266 if (argv_find(argv, argc, "med", &idx))
6267 med = true;
6268
6269 /* no flags means all of them! */
6270 if (!aspath && !nexthop && !med) {
6271 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6272 PEER_FLAG_AS_PATH_UNCHANGED);
6273 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6274 PEER_FLAG_NEXTHOP_UNCHANGED);
6275 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6276 PEER_FLAG_MED_UNCHANGED);
6277 } else {
6278 if (!aspath) {
6279 if (peer_af_flag_check(peer, afi, safi,
6280 PEER_FLAG_AS_PATH_UNCHANGED)) {
6281 ret |= peer_af_flag_unset_vty(
6282 vty, peer_str, afi, safi,
6283 PEER_FLAG_AS_PATH_UNCHANGED);
6284 }
6285 } else
6286 ret |= peer_af_flag_set_vty(
6287 vty, peer_str, afi, safi,
6288 PEER_FLAG_AS_PATH_UNCHANGED);
6289
6290 if (!nexthop) {
6291 if (peer_af_flag_check(peer, afi, safi,
6292 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6293 ret |= peer_af_flag_unset_vty(
6294 vty, peer_str, afi, safi,
6295 PEER_FLAG_NEXTHOP_UNCHANGED);
6296 }
6297 } else
6298 ret |= peer_af_flag_set_vty(
6299 vty, peer_str, afi, safi,
6300 PEER_FLAG_NEXTHOP_UNCHANGED);
6301
6302 if (!med) {
6303 if (peer_af_flag_check(peer, afi, safi,
6304 PEER_FLAG_MED_UNCHANGED)) {
6305 ret |= peer_af_flag_unset_vty(
6306 vty, peer_str, afi, safi,
6307 PEER_FLAG_MED_UNCHANGED);
6308 }
6309 } else
6310 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6311 PEER_FLAG_MED_UNCHANGED);
6312 }
6313
6314 return ret;
6315 }
6316
6317 ALIAS_HIDDEN(
6318 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6319 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6321 "BGP attribute is propagated unchanged to this neighbor\n"
6322 "As-path attribute\n"
6323 "Nexthop attribute\n"
6324 "Med attribute\n")
6325
6326 DEFUN (no_neighbor_attr_unchanged,
6327 no_neighbor_attr_unchanged_cmd,
6328 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6329 NO_STR
6330 NEIGHBOR_STR
6331 NEIGHBOR_ADDR_STR2
6332 "BGP attribute is propagated unchanged to this neighbor\n"
6333 "As-path attribute\n"
6334 "Nexthop attribute\n"
6335 "Med attribute\n")
6336 {
6337 int idx = 0;
6338 char *peer_str = argv[2]->arg;
6339 struct peer *peer;
6340 bool aspath = false;
6341 bool nexthop = false;
6342 bool med = false;
6343 afi_t afi = bgp_node_afi(vty);
6344 safi_t safi = bgp_node_safi(vty);
6345 int ret = 0;
6346
6347 peer = peer_and_group_lookup_vty(vty, peer_str);
6348 if (!peer)
6349 return CMD_WARNING_CONFIG_FAILED;
6350
6351 if (argv_find(argv, argc, "as-path", &idx))
6352 aspath = true;
6353
6354 idx = 0;
6355 if (argv_find(argv, argc, "next-hop", &idx))
6356 nexthop = true;
6357
6358 idx = 0;
6359 if (argv_find(argv, argc, "med", &idx))
6360 med = true;
6361
6362 if (!aspath && !nexthop && !med) // no flags means all of them!
6363 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6364 PEER_FLAG_AS_PATH_UNCHANGED)
6365 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6366 PEER_FLAG_NEXTHOP_UNCHANGED)
6367 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6368 PEER_FLAG_MED_UNCHANGED);
6369
6370 if (aspath)
6371 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6372 PEER_FLAG_AS_PATH_UNCHANGED);
6373
6374 if (nexthop)
6375 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6376 PEER_FLAG_NEXTHOP_UNCHANGED);
6377
6378 if (med)
6379 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6380 PEER_FLAG_MED_UNCHANGED);
6381
6382 return ret;
6383 }
6384
6385 ALIAS_HIDDEN(
6386 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6387 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6388 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6389 "BGP attribute is propagated unchanged to this neighbor\n"
6390 "As-path attribute\n"
6391 "Nexthop attribute\n"
6392 "Med attribute\n")
6393
6394 /* EBGP multihop configuration. */
6395 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6396 const char *ttl_str)
6397 {
6398 struct peer *peer;
6399 unsigned int ttl;
6400
6401 peer = peer_and_group_lookup_vty(vty, ip_str);
6402 if (!peer)
6403 return CMD_WARNING_CONFIG_FAILED;
6404
6405 if (peer->conf_if)
6406 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6407
6408 if (!ttl_str)
6409 ttl = MAXTTL;
6410 else
6411 ttl = strtoul(ttl_str, NULL, 10);
6412
6413 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6414 }
6415
6416 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6417 {
6418 struct peer *peer;
6419
6420 peer = peer_and_group_lookup_vty(vty, ip_str);
6421 if (!peer)
6422 return CMD_WARNING_CONFIG_FAILED;
6423
6424 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6425 }
6426
6427 /* neighbor ebgp-multihop. */
6428 DEFUN (neighbor_ebgp_multihop,
6429 neighbor_ebgp_multihop_cmd,
6430 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6431 NEIGHBOR_STR
6432 NEIGHBOR_ADDR_STR2
6433 "Allow EBGP neighbors not on directly connected networks\n")
6434 {
6435 int idx_peer = 1;
6436 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6437 }
6438
6439 DEFUN (neighbor_ebgp_multihop_ttl,
6440 neighbor_ebgp_multihop_ttl_cmd,
6441 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6442 NEIGHBOR_STR
6443 NEIGHBOR_ADDR_STR2
6444 "Allow EBGP neighbors not on directly connected networks\n"
6445 "maximum hop count\n")
6446 {
6447 int idx_peer = 1;
6448 int idx_number = 3;
6449 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6450 argv[idx_number]->arg);
6451 }
6452
6453 DEFUN (no_neighbor_ebgp_multihop,
6454 no_neighbor_ebgp_multihop_cmd,
6455 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6456 NO_STR
6457 NEIGHBOR_STR
6458 NEIGHBOR_ADDR_STR2
6459 "Allow EBGP neighbors not on directly connected networks\n"
6460 "maximum hop count\n")
6461 {
6462 int idx_peer = 2;
6463 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6464 }
6465
6466 static uint8_t get_role_by_name(const char *role_str)
6467 {
6468 if (strncmp(role_str, "peer", 2) == 0)
6469 return ROLE_PEER;
6470 if (strncmp(role_str, "provider", 2) == 0)
6471 return ROLE_PROVIDER;
6472 if (strncmp(role_str, "customer", 2) == 0)
6473 return ROLE_CUSTOMER;
6474 if (strncmp(role_str, "rs-server", 4) == 0)
6475 return ROLE_RS_SERVER;
6476 if (strncmp(role_str, "rs-client", 4) == 0)
6477 return ROLE_RS_CLIENT;
6478 return ROLE_UNDEFINED;
6479 }
6480
6481 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6482 const char *role_str, bool strict_mode)
6483 {
6484 struct peer *peer;
6485
6486 peer = peer_and_group_lookup_vty(vty, ip_str);
6487 if (!peer)
6488 return CMD_WARNING_CONFIG_FAILED;
6489 uint8_t role = get_role_by_name(role_str);
6490
6491 if (role == ROLE_UNDEFINED)
6492 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6493 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6494 }
6495
6496 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6497 {
6498 struct peer *peer;
6499
6500 peer = peer_and_group_lookup_vty(vty, ip_str);
6501 if (!peer)
6502 return CMD_WARNING_CONFIG_FAILED;
6503 return bgp_vty_return(vty, peer_role_unset(peer));
6504 }
6505
6506 DEFPY(neighbor_role,
6507 neighbor_role_cmd,
6508 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6509 NEIGHBOR_STR
6510 NEIGHBOR_ADDR_STR2
6511 "Set session role\n"
6512 ROLE_STR)
6513 {
6514 int idx_peer = 1;
6515 int idx_role = 3;
6516
6517 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6518 false);
6519 }
6520
6521 DEFPY(neighbor_role_strict,
6522 neighbor_role_strict_cmd,
6523 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6524 NEIGHBOR_STR
6525 NEIGHBOR_ADDR_STR2
6526 "Set session role\n"
6527 ROLE_STR
6528 "Use additional restriction on peer\n")
6529 {
6530 int idx_peer = 1;
6531 int idx_role = 3;
6532
6533 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6534 true);
6535 }
6536
6537 DEFPY(no_neighbor_role,
6538 no_neighbor_role_cmd,
6539 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6540 NO_STR
6541 NEIGHBOR_STR
6542 NEIGHBOR_ADDR_STR2
6543 "Set session role\n"
6544 ROLE_STR
6545 "Use additional restriction on peer\n")
6546 {
6547 int idx_peer = 2;
6548
6549 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6550 }
6551
6552 /* disable-connected-check */
6553 DEFUN (neighbor_disable_connected_check,
6554 neighbor_disable_connected_check_cmd,
6555 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6556 NEIGHBOR_STR
6557 NEIGHBOR_ADDR_STR2
6558 "one-hop away EBGP peer using loopback address\n"
6559 "Enforce EBGP neighbors perform multihop\n")
6560 {
6561 int idx_peer = 1;
6562 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6563 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6564 }
6565
6566 DEFUN (no_neighbor_disable_connected_check,
6567 no_neighbor_disable_connected_check_cmd,
6568 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6569 NO_STR
6570 NEIGHBOR_STR
6571 NEIGHBOR_ADDR_STR2
6572 "one-hop away EBGP peer using loopback address\n"
6573 "Enforce EBGP neighbors perform multihop\n")
6574 {
6575 int idx_peer = 2;
6576 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6577 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6578 }
6579
6580 /* disable-link-bw-encoding-ieee */
6581 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6582 neighbor_disable_link_bw_encoding_ieee_cmd,
6583 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6584 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6585 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6586 {
6587 int idx_peer = 1;
6588
6589 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6590 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6591 }
6592
6593 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6594 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6595 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6596 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6597 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6598 {
6599 int idx_peer = 2;
6600
6601 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6602 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6603 }
6604
6605 /* extended-optional-parameters */
6606 DEFUN(neighbor_extended_optional_parameters,
6607 neighbor_extended_optional_parameters_cmd,
6608 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6610 "Force the extended optional parameters format for OPEN messages\n")
6611 {
6612 int idx_peer = 1;
6613
6614 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6615 PEER_FLAG_EXTENDED_OPT_PARAMS);
6616 }
6617
6618 DEFUN(no_neighbor_extended_optional_parameters,
6619 no_neighbor_extended_optional_parameters_cmd,
6620 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6621 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6622 "Force the extended optional parameters format for OPEN messages\n")
6623 {
6624 int idx_peer = 2;
6625
6626 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6627 PEER_FLAG_EXTENDED_OPT_PARAMS);
6628 }
6629
6630 /* enforce-first-as */
6631 DEFUN (neighbor_enforce_first_as,
6632 neighbor_enforce_first_as_cmd,
6633 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6634 NEIGHBOR_STR
6635 NEIGHBOR_ADDR_STR2
6636 "Enforce the first AS for EBGP routes\n")
6637 {
6638 int idx_peer = 1;
6639
6640 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6641 PEER_FLAG_ENFORCE_FIRST_AS);
6642 }
6643
6644 DEFUN (no_neighbor_enforce_first_as,
6645 no_neighbor_enforce_first_as_cmd,
6646 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6647 NO_STR
6648 NEIGHBOR_STR
6649 NEIGHBOR_ADDR_STR2
6650 "Enforce the first AS for EBGP routes\n")
6651 {
6652 int idx_peer = 2;
6653
6654 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6655 PEER_FLAG_ENFORCE_FIRST_AS);
6656 }
6657
6658
6659 DEFUN (neighbor_description,
6660 neighbor_description_cmd,
6661 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6662 NEIGHBOR_STR
6663 NEIGHBOR_ADDR_STR2
6664 "Neighbor specific description\n"
6665 "Up to 80 characters describing this neighbor\n")
6666 {
6667 int idx_peer = 1;
6668 int idx_line = 3;
6669 struct peer *peer;
6670 char *str;
6671
6672 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6673 if (!peer)
6674 return CMD_WARNING_CONFIG_FAILED;
6675
6676 str = argv_concat(argv, argc, idx_line);
6677
6678 peer_description_set(peer, str);
6679
6680 XFREE(MTYPE_TMP, str);
6681
6682 return CMD_SUCCESS;
6683 }
6684
6685 DEFUN (no_neighbor_description,
6686 no_neighbor_description_cmd,
6687 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6688 NO_STR
6689 NEIGHBOR_STR
6690 NEIGHBOR_ADDR_STR2
6691 "Neighbor specific description\n")
6692 {
6693 int idx_peer = 2;
6694 struct peer *peer;
6695
6696 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6697 if (!peer)
6698 return CMD_WARNING_CONFIG_FAILED;
6699
6700 peer_description_unset(peer);
6701
6702 return CMD_SUCCESS;
6703 }
6704
6705 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6706 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6707 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6708 "Neighbor specific description\n"
6709 "Up to 80 characters describing this neighbor\n")
6710
6711 /* Neighbor update-source. */
6712 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6713 const char *source_str)
6714 {
6715 struct peer *peer;
6716 struct prefix p;
6717 union sockunion su;
6718
6719 peer = peer_and_group_lookup_vty(vty, peer_str);
6720 if (!peer)
6721 return CMD_WARNING_CONFIG_FAILED;
6722
6723 if (peer->conf_if)
6724 return CMD_WARNING;
6725
6726 if (source_str) {
6727 if (str2sockunion(source_str, &su) == 0)
6728 peer_update_source_addr_set(peer, &su);
6729 else {
6730 if (str2prefix(source_str, &p)) {
6731 vty_out(vty,
6732 "%% Invalid update-source, remove prefix length \n");
6733 return CMD_WARNING_CONFIG_FAILED;
6734 } else
6735 peer_update_source_if_set(peer, source_str);
6736 }
6737 } else
6738 peer_update_source_unset(peer);
6739
6740 return CMD_SUCCESS;
6741 }
6742
6743 #define BGP_UPDATE_SOURCE_HELP_STR \
6744 "IPv4 address\n" \
6745 "IPv6 address\n" \
6746 "Interface name (requires zebra to be running)\n"
6747
6748 DEFUN (neighbor_update_source,
6749 neighbor_update_source_cmd,
6750 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6751 NEIGHBOR_STR
6752 NEIGHBOR_ADDR_STR2
6753 "Source of routing updates\n"
6754 BGP_UPDATE_SOURCE_HELP_STR)
6755 {
6756 int idx_peer = 1;
6757 int idx_peer_2 = 3;
6758 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6759 argv[idx_peer_2]->arg);
6760 }
6761
6762 DEFUN (no_neighbor_update_source,
6763 no_neighbor_update_source_cmd,
6764 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6765 NO_STR
6766 NEIGHBOR_STR
6767 NEIGHBOR_ADDR_STR2
6768 "Source of routing updates\n"
6769 BGP_UPDATE_SOURCE_HELP_STR)
6770 {
6771 int idx_peer = 2;
6772 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6773 }
6774
6775 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6776 afi_t afi, safi_t safi,
6777 const char *rmap, int set)
6778 {
6779 int ret;
6780 struct peer *peer;
6781 struct route_map *route_map = NULL;
6782
6783 peer = peer_and_group_lookup_vty(vty, peer_str);
6784 if (!peer)
6785 return CMD_WARNING_CONFIG_FAILED;
6786
6787 if (set) {
6788 if (rmap)
6789 route_map = route_map_lookup_warn_noexist(vty, rmap);
6790 ret = peer_default_originate_set(peer, afi, safi,
6791 rmap, route_map);
6792 } else
6793 ret = peer_default_originate_unset(peer, afi, safi);
6794
6795 return bgp_vty_return(vty, ret);
6796 }
6797
6798 /* neighbor default-originate. */
6799 DEFUN (neighbor_default_originate,
6800 neighbor_default_originate_cmd,
6801 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6802 NEIGHBOR_STR
6803 NEIGHBOR_ADDR_STR2
6804 "Originate default route to this neighbor\n")
6805 {
6806 int idx_peer = 1;
6807 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6808 bgp_node_afi(vty),
6809 bgp_node_safi(vty), NULL, 1);
6810 }
6811
6812 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6813 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6814 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6815 "Originate default route to this neighbor\n")
6816
6817 DEFUN (neighbor_default_originate_rmap,
6818 neighbor_default_originate_rmap_cmd,
6819 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6820 NEIGHBOR_STR
6821 NEIGHBOR_ADDR_STR2
6822 "Originate default route to this neighbor\n"
6823 "Route-map to specify criteria to originate default\n"
6824 "route-map name\n")
6825 {
6826 int idx_peer = 1;
6827 int idx_word = 4;
6828 return peer_default_originate_set_vty(
6829 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6830 argv[idx_word]->arg, 1);
6831 }
6832
6833 ALIAS_HIDDEN(
6834 neighbor_default_originate_rmap,
6835 neighbor_default_originate_rmap_hidden_cmd,
6836 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6837 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6838 "Originate default route to this neighbor\n"
6839 "Route-map to specify criteria to originate default\n"
6840 "route-map name\n")
6841
6842 DEFUN (no_neighbor_default_originate,
6843 no_neighbor_default_originate_cmd,
6844 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6845 NO_STR
6846 NEIGHBOR_STR
6847 NEIGHBOR_ADDR_STR2
6848 "Originate default route to this neighbor\n"
6849 "Route-map to specify criteria to originate default\n"
6850 "route-map name\n")
6851 {
6852 int idx_peer = 2;
6853 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6854 bgp_node_afi(vty),
6855 bgp_node_safi(vty), NULL, 0);
6856 }
6857
6858 ALIAS_HIDDEN(
6859 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6860 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6861 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6862 "Originate default route to this neighbor\n"
6863 "Route-map to specify criteria to originate default\n"
6864 "route-map name\n")
6865
6866
6867 /* Set neighbor's BGP port. */
6868 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6869 const char *port_str)
6870 {
6871 struct peer *peer;
6872 uint16_t port;
6873 struct servent *sp;
6874
6875 peer = peer_and_group_lookup_vty(vty, ip_str);
6876 if (!peer)
6877 return CMD_WARNING_CONFIG_FAILED;
6878
6879 if (!port_str) {
6880 sp = getservbyname("bgp", "tcp");
6881 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6882 } else {
6883 port = strtoul(port_str, NULL, 10);
6884 }
6885
6886 peer_port_set(peer, port);
6887
6888 return CMD_SUCCESS;
6889 }
6890
6891 /* Set specified peer's BGP port. */
6892 DEFUN (neighbor_port,
6893 neighbor_port_cmd,
6894 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6895 NEIGHBOR_STR
6896 NEIGHBOR_ADDR_STR2
6897 "Neighbor's BGP port\n"
6898 "TCP port number\n")
6899 {
6900 int idx_ip = 1;
6901 int idx_number = 3;
6902 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6903 argv[idx_number]->arg);
6904 }
6905
6906 DEFUN (no_neighbor_port,
6907 no_neighbor_port_cmd,
6908 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6909 NO_STR
6910 NEIGHBOR_STR
6911 NEIGHBOR_ADDR_STR2
6912 "Neighbor's BGP port\n"
6913 "TCP port number\n")
6914 {
6915 int idx_ip = 2;
6916 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6917 }
6918
6919
6920 /* neighbor weight. */
6921 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6922 safi_t safi, const char *weight_str)
6923 {
6924 int ret;
6925 struct peer *peer;
6926 unsigned long weight;
6927
6928 peer = peer_and_group_lookup_vty(vty, ip_str);
6929 if (!peer)
6930 return CMD_WARNING_CONFIG_FAILED;
6931
6932 weight = strtoul(weight_str, NULL, 10);
6933
6934 ret = peer_weight_set(peer, afi, safi, weight);
6935 return bgp_vty_return(vty, ret);
6936 }
6937
6938 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6939 safi_t safi)
6940 {
6941 int ret;
6942 struct peer *peer;
6943
6944 peer = peer_and_group_lookup_vty(vty, ip_str);
6945 if (!peer)
6946 return CMD_WARNING_CONFIG_FAILED;
6947
6948 ret = peer_weight_unset(peer, afi, safi);
6949 return bgp_vty_return(vty, ret);
6950 }
6951
6952 DEFUN (neighbor_weight,
6953 neighbor_weight_cmd,
6954 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6955 NEIGHBOR_STR
6956 NEIGHBOR_ADDR_STR2
6957 "Set default weight for routes from this neighbor\n"
6958 "default weight\n")
6959 {
6960 int idx_peer = 1;
6961 int idx_number = 3;
6962 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6963 bgp_node_safi(vty), argv[idx_number]->arg);
6964 }
6965
6966 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6967 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6969 "Set default weight for routes from this neighbor\n"
6970 "default weight\n")
6971
6972 DEFUN (no_neighbor_weight,
6973 no_neighbor_weight_cmd,
6974 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6975 NO_STR
6976 NEIGHBOR_STR
6977 NEIGHBOR_ADDR_STR2
6978 "Set default weight for routes from this neighbor\n"
6979 "default weight\n")
6980 {
6981 int idx_peer = 2;
6982 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6983 bgp_node_afi(vty), bgp_node_safi(vty));
6984 }
6985
6986 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6987 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6988 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6989 "Set default weight for routes from this neighbor\n"
6990 "default weight\n")
6991
6992
6993 /* Override capability negotiation. */
6994 DEFUN (neighbor_override_capability,
6995 neighbor_override_capability_cmd,
6996 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6997 NEIGHBOR_STR
6998 NEIGHBOR_ADDR_STR2
6999 "Override capability negotiation result\n")
7000 {
7001 int idx_peer = 1;
7002 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7003 PEER_FLAG_OVERRIDE_CAPABILITY);
7004 }
7005
7006 DEFUN (no_neighbor_override_capability,
7007 no_neighbor_override_capability_cmd,
7008 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7009 NO_STR
7010 NEIGHBOR_STR
7011 NEIGHBOR_ADDR_STR2
7012 "Override capability negotiation result\n")
7013 {
7014 int idx_peer = 2;
7015 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7016 PEER_FLAG_OVERRIDE_CAPABILITY);
7017 }
7018
7019 DEFUN (neighbor_strict_capability,
7020 neighbor_strict_capability_cmd,
7021 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7022 NEIGHBOR_STR
7023 NEIGHBOR_ADDR_STR2
7024 "Strict capability negotiation match\n")
7025 {
7026 int idx_peer = 1;
7027
7028 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7029 PEER_FLAG_STRICT_CAP_MATCH);
7030 }
7031
7032 DEFUN (no_neighbor_strict_capability,
7033 no_neighbor_strict_capability_cmd,
7034 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7035 NO_STR
7036 NEIGHBOR_STR
7037 NEIGHBOR_ADDR_STR2
7038 "Strict capability negotiation match\n")
7039 {
7040 int idx_peer = 2;
7041
7042 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7043 PEER_FLAG_STRICT_CAP_MATCH);
7044 }
7045
7046 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7047 const char *keep_str, const char *hold_str)
7048 {
7049 int ret;
7050 struct peer *peer;
7051 uint32_t keepalive;
7052 uint32_t holdtime;
7053
7054 peer = peer_and_group_lookup_vty(vty, ip_str);
7055 if (!peer)
7056 return CMD_WARNING_CONFIG_FAILED;
7057
7058 keepalive = strtoul(keep_str, NULL, 10);
7059 holdtime = strtoul(hold_str, NULL, 10);
7060
7061 ret = peer_timers_set(peer, keepalive, holdtime);
7062
7063 return bgp_vty_return(vty, ret);
7064 }
7065
7066 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7067 {
7068 int ret;
7069 struct peer *peer;
7070
7071 peer = peer_and_group_lookup_vty(vty, ip_str);
7072 if (!peer)
7073 return CMD_WARNING_CONFIG_FAILED;
7074
7075 ret = peer_timers_unset(peer);
7076
7077 return bgp_vty_return(vty, ret);
7078 }
7079
7080 DEFUN (neighbor_timers,
7081 neighbor_timers_cmd,
7082 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7083 NEIGHBOR_STR
7084 NEIGHBOR_ADDR_STR2
7085 "BGP per neighbor timers\n"
7086 "Keepalive interval\n"
7087 "Holdtime\n")
7088 {
7089 int idx_peer = 1;
7090 int idx_number = 3;
7091 int idx_number_2 = 4;
7092 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7093 argv[idx_number]->arg,
7094 argv[idx_number_2]->arg);
7095 }
7096
7097 DEFUN (no_neighbor_timers,
7098 no_neighbor_timers_cmd,
7099 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7100 NO_STR
7101 NEIGHBOR_STR
7102 NEIGHBOR_ADDR_STR2
7103 "BGP per neighbor timers\n"
7104 "Keepalive interval\n"
7105 "Holdtime\n")
7106 {
7107 int idx_peer = 2;
7108 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7109 }
7110
7111
7112 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7113 const char *time_str)
7114 {
7115 int ret;
7116 struct peer *peer;
7117 uint32_t connect;
7118
7119 peer = peer_and_group_lookup_vty(vty, ip_str);
7120 if (!peer)
7121 return CMD_WARNING_CONFIG_FAILED;
7122
7123 connect = strtoul(time_str, NULL, 10);
7124
7125 ret = peer_timers_connect_set(peer, connect);
7126
7127 return bgp_vty_return(vty, ret);
7128 }
7129
7130 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7131 {
7132 int ret;
7133 struct peer *peer;
7134
7135 peer = peer_and_group_lookup_vty(vty, ip_str);
7136 if (!peer)
7137 return CMD_WARNING_CONFIG_FAILED;
7138
7139 ret = peer_timers_connect_unset(peer);
7140
7141 return bgp_vty_return(vty, ret);
7142 }
7143
7144 DEFUN (neighbor_timers_connect,
7145 neighbor_timers_connect_cmd,
7146 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7147 NEIGHBOR_STR
7148 NEIGHBOR_ADDR_STR2
7149 "BGP per neighbor timers\n"
7150 "BGP connect timer\n"
7151 "Connect timer\n")
7152 {
7153 int idx_peer = 1;
7154 int idx_number = 4;
7155 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7156 argv[idx_number]->arg);
7157 }
7158
7159 DEFUN (no_neighbor_timers_connect,
7160 no_neighbor_timers_connect_cmd,
7161 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7162 NO_STR
7163 NEIGHBOR_STR
7164 NEIGHBOR_ADDR_STR2
7165 "BGP per neighbor timers\n"
7166 "BGP connect timer\n"
7167 "Connect timer\n")
7168 {
7169 int idx_peer = 2;
7170 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7171 }
7172
7173 DEFPY (neighbor_timers_delayopen,
7174 neighbor_timers_delayopen_cmd,
7175 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7176 NEIGHBOR_STR
7177 NEIGHBOR_ADDR_STR2
7178 "BGP per neighbor timers\n"
7179 "RFC 4271 DelayOpenTimer\n"
7180 "DelayOpenTime timer interval\n")
7181 {
7182 struct peer *peer;
7183
7184 peer = peer_and_group_lookup_vty(vty, neighbor);
7185 if (!peer)
7186 return CMD_WARNING_CONFIG_FAILED;
7187
7188 if (!interval) {
7189 if (peer_timers_delayopen_unset(peer))
7190 return CMD_WARNING_CONFIG_FAILED;
7191 } else {
7192 if (peer_timers_delayopen_set(peer, interval))
7193 return CMD_WARNING_CONFIG_FAILED;
7194 }
7195
7196 return CMD_SUCCESS;
7197 }
7198
7199 DEFPY (no_neighbor_timers_delayopen,
7200 no_neighbor_timers_delayopen_cmd,
7201 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7202 NO_STR
7203 NEIGHBOR_STR
7204 NEIGHBOR_ADDR_STR2
7205 "BGP per neighbor timers\n"
7206 "RFC 4271 DelayOpenTimer\n"
7207 "DelayOpenTime timer interval\n")
7208 {
7209 struct peer *peer;
7210
7211 peer = peer_and_group_lookup_vty(vty, neighbor);
7212 if (!peer)
7213 return CMD_WARNING_CONFIG_FAILED;
7214
7215 if (peer_timers_delayopen_unset(peer))
7216 return CMD_WARNING_CONFIG_FAILED;
7217
7218 return CMD_SUCCESS;
7219 }
7220
7221 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7222 const char *time_str, int set)
7223 {
7224 int ret;
7225 struct peer *peer;
7226 uint32_t routeadv = 0;
7227
7228 peer = peer_and_group_lookup_vty(vty, ip_str);
7229 if (!peer)
7230 return CMD_WARNING_CONFIG_FAILED;
7231
7232 if (time_str)
7233 routeadv = strtoul(time_str, NULL, 10);
7234
7235 if (set)
7236 ret = peer_advertise_interval_set(peer, routeadv);
7237 else
7238 ret = peer_advertise_interval_unset(peer);
7239
7240 return bgp_vty_return(vty, ret);
7241 }
7242
7243 DEFUN (neighbor_advertise_interval,
7244 neighbor_advertise_interval_cmd,
7245 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7246 NEIGHBOR_STR
7247 NEIGHBOR_ADDR_STR2
7248 "Minimum interval between sending BGP routing updates\n"
7249 "time in seconds\n")
7250 {
7251 int idx_peer = 1;
7252 int idx_number = 3;
7253 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7254 argv[idx_number]->arg, 1);
7255 }
7256
7257 DEFUN (no_neighbor_advertise_interval,
7258 no_neighbor_advertise_interval_cmd,
7259 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7260 NO_STR
7261 NEIGHBOR_STR
7262 NEIGHBOR_ADDR_STR2
7263 "Minimum interval between sending BGP routing updates\n"
7264 "time in seconds\n")
7265 {
7266 int idx_peer = 2;
7267 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7268 }
7269
7270
7271 /* Time to wait before processing route-map updates */
7272 DEFUN (bgp_set_route_map_delay_timer,
7273 bgp_set_route_map_delay_timer_cmd,
7274 "bgp route-map delay-timer (0-600)",
7275 SET_STR
7276 "BGP route-map delay timer\n"
7277 "Time in secs to wait before processing route-map changes\n"
7278 "0 disables the timer, no route updates happen when route-maps change\n")
7279 {
7280 int idx_number = 3;
7281 uint32_t rmap_delay_timer;
7282
7283 if (argv[idx_number]->arg) {
7284 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7285 bm->rmap_update_timer = rmap_delay_timer;
7286
7287 /* if the dynamic update handling is being disabled, and a timer
7288 * is
7289 * running, stop the timer and act as if the timer has already
7290 * fired.
7291 */
7292 if (!rmap_delay_timer && bm->t_rmap_update) {
7293 THREAD_OFF(bm->t_rmap_update);
7294 thread_execute(bm->master, bgp_route_map_update_timer,
7295 NULL, 0);
7296 }
7297 return CMD_SUCCESS;
7298 } else {
7299 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7300 return CMD_WARNING_CONFIG_FAILED;
7301 }
7302 }
7303
7304 DEFUN (no_bgp_set_route_map_delay_timer,
7305 no_bgp_set_route_map_delay_timer_cmd,
7306 "no bgp route-map delay-timer [(0-600)]",
7307 NO_STR
7308 BGP_STR
7309 "Default BGP route-map delay timer\n"
7310 "Reset to default time to wait for processing route-map changes\n"
7311 "0 disables the timer, no route updates happen when route-maps change\n")
7312 {
7313
7314 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7315
7316 return CMD_SUCCESS;
7317 }
7318
7319 /* neighbor interface */
7320 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7321 const char *str)
7322 {
7323 struct peer *peer;
7324
7325 peer = peer_lookup_vty(vty, ip_str);
7326 if (!peer || peer->conf_if) {
7327 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7328 return CMD_WARNING_CONFIG_FAILED;
7329 }
7330
7331 if (str)
7332 peer_interface_set(peer, str);
7333 else
7334 peer_interface_unset(peer);
7335
7336 return CMD_SUCCESS;
7337 }
7338
7339 DEFUN (neighbor_interface,
7340 neighbor_interface_cmd,
7341 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7342 NEIGHBOR_STR
7343 NEIGHBOR_ADDR_STR
7344 "Interface\n"
7345 "Interface name\n")
7346 {
7347 int idx_ip = 1;
7348 int idx_word = 3;
7349
7350 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7351 }
7352
7353 DEFUN (no_neighbor_interface,
7354 no_neighbor_interface_cmd,
7355 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7356 NO_STR
7357 NEIGHBOR_STR
7358 NEIGHBOR_ADDR_STR
7359 "Interface\n"
7360 "Interface name\n")
7361 {
7362 int idx_peer = 2;
7363
7364 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7365 }
7366
7367 DEFUN (neighbor_distribute_list,
7368 neighbor_distribute_list_cmd,
7369 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7370 NEIGHBOR_STR
7371 NEIGHBOR_ADDR_STR2
7372 "Filter updates to/from this neighbor\n"
7373 "IP Access-list name\n"
7374 "Filter incoming updates\n"
7375 "Filter outgoing updates\n")
7376 {
7377 int idx_peer = 1;
7378 int idx_acl = 3;
7379 int direct, ret;
7380 struct peer *peer;
7381
7382 const char *pstr = argv[idx_peer]->arg;
7383 const char *acl = argv[idx_acl]->arg;
7384 const char *inout = argv[argc - 1]->text;
7385
7386 peer = peer_and_group_lookup_vty(vty, pstr);
7387 if (!peer)
7388 return CMD_WARNING_CONFIG_FAILED;
7389
7390 /* Check filter direction. */
7391 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7392 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7393 direct, acl);
7394
7395 return bgp_vty_return(vty, ret);
7396 }
7397
7398 ALIAS_HIDDEN(
7399 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7400 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7401 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7402 "Filter updates to/from this neighbor\n"
7403 "IP Access-list name\n"
7404 "Filter incoming updates\n"
7405 "Filter outgoing updates\n")
7406
7407 DEFUN (no_neighbor_distribute_list,
7408 no_neighbor_distribute_list_cmd,
7409 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7410 NO_STR
7411 NEIGHBOR_STR
7412 NEIGHBOR_ADDR_STR2
7413 "Filter updates to/from this neighbor\n"
7414 "IP Access-list name\n"
7415 "Filter incoming updates\n"
7416 "Filter outgoing updates\n")
7417 {
7418 int idx_peer = 2;
7419 int direct, ret;
7420 struct peer *peer;
7421
7422 const char *pstr = argv[idx_peer]->arg;
7423 const char *inout = argv[argc - 1]->text;
7424
7425 peer = peer_and_group_lookup_vty(vty, pstr);
7426 if (!peer)
7427 return CMD_WARNING_CONFIG_FAILED;
7428
7429 /* Check filter direction. */
7430 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7431 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7432 direct);
7433
7434 return bgp_vty_return(vty, ret);
7435 }
7436
7437 ALIAS_HIDDEN(
7438 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7439 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7440 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7441 "Filter updates to/from this neighbor\n"
7442 "IP Access-list name\n"
7443 "Filter incoming updates\n"
7444 "Filter outgoing updates\n")
7445
7446 /* Set prefix list to the peer. */
7447 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7448 afi_t afi, safi_t safi,
7449 const char *name_str,
7450 const char *direct_str)
7451 {
7452 int ret;
7453 int direct = FILTER_IN;
7454 struct peer *peer;
7455
7456 peer = peer_and_group_lookup_vty(vty, ip_str);
7457 if (!peer)
7458 return CMD_WARNING_CONFIG_FAILED;
7459
7460 /* Check filter direction. */
7461 if (strncmp(direct_str, "i", 1) == 0)
7462 direct = FILTER_IN;
7463 else if (strncmp(direct_str, "o", 1) == 0)
7464 direct = FILTER_OUT;
7465
7466 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7467
7468 return bgp_vty_return(vty, ret);
7469 }
7470
7471 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7472 afi_t afi, safi_t safi,
7473 const char *direct_str)
7474 {
7475 int ret;
7476 struct peer *peer;
7477 int direct = FILTER_IN;
7478
7479 peer = peer_and_group_lookup_vty(vty, ip_str);
7480 if (!peer)
7481 return CMD_WARNING_CONFIG_FAILED;
7482
7483 /* Check filter direction. */
7484 if (strncmp(direct_str, "i", 1) == 0)
7485 direct = FILTER_IN;
7486 else if (strncmp(direct_str, "o", 1) == 0)
7487 direct = FILTER_OUT;
7488
7489 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7490
7491 return bgp_vty_return(vty, ret);
7492 }
7493
7494 DEFUN (neighbor_prefix_list,
7495 neighbor_prefix_list_cmd,
7496 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7497 NEIGHBOR_STR
7498 NEIGHBOR_ADDR_STR2
7499 "Filter updates to/from this neighbor\n"
7500 "Name of a prefix list\n"
7501 "Filter incoming updates\n"
7502 "Filter outgoing updates\n")
7503 {
7504 int idx_peer = 1;
7505 int idx_word = 3;
7506 int idx_in_out = 4;
7507 return peer_prefix_list_set_vty(
7508 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7509 argv[idx_word]->arg, argv[idx_in_out]->arg);
7510 }
7511
7512 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7513 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7514 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7515 "Filter updates to/from this neighbor\n"
7516 "Name of a prefix list\n"
7517 "Filter incoming updates\n"
7518 "Filter outgoing updates\n")
7519
7520 DEFUN (no_neighbor_prefix_list,
7521 no_neighbor_prefix_list_cmd,
7522 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7523 NO_STR
7524 NEIGHBOR_STR
7525 NEIGHBOR_ADDR_STR2
7526 "Filter updates to/from this neighbor\n"
7527 "Name of a prefix list\n"
7528 "Filter incoming updates\n"
7529 "Filter outgoing updates\n")
7530 {
7531 int idx_peer = 2;
7532 int idx_in_out = 5;
7533 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7534 bgp_node_afi(vty), bgp_node_safi(vty),
7535 argv[idx_in_out]->arg);
7536 }
7537
7538 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7539 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7540 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7541 "Filter updates to/from this neighbor\n"
7542 "Name of a prefix list\n"
7543 "Filter incoming updates\n"
7544 "Filter outgoing updates\n")
7545
7546 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7547 safi_t safi, const char *name_str,
7548 const char *direct_str)
7549 {
7550 int ret;
7551 struct peer *peer;
7552 int direct = FILTER_IN;
7553
7554 peer = peer_and_group_lookup_vty(vty, ip_str);
7555 if (!peer)
7556 return CMD_WARNING_CONFIG_FAILED;
7557
7558 /* Check filter direction. */
7559 if (strncmp(direct_str, "i", 1) == 0)
7560 direct = FILTER_IN;
7561 else if (strncmp(direct_str, "o", 1) == 0)
7562 direct = FILTER_OUT;
7563
7564 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7565
7566 return bgp_vty_return(vty, ret);
7567 }
7568
7569 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7570 safi_t safi, const char *direct_str)
7571 {
7572 int ret;
7573 struct peer *peer;
7574 int direct = FILTER_IN;
7575
7576 peer = peer_and_group_lookup_vty(vty, ip_str);
7577 if (!peer)
7578 return CMD_WARNING_CONFIG_FAILED;
7579
7580 /* Check filter direction. */
7581 if (strncmp(direct_str, "i", 1) == 0)
7582 direct = FILTER_IN;
7583 else if (strncmp(direct_str, "o", 1) == 0)
7584 direct = FILTER_OUT;
7585
7586 ret = peer_aslist_unset(peer, afi, safi, direct);
7587
7588 return bgp_vty_return(vty, ret);
7589 }
7590
7591 DEFUN (neighbor_filter_list,
7592 neighbor_filter_list_cmd,
7593 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7594 NEIGHBOR_STR
7595 NEIGHBOR_ADDR_STR2
7596 "Establish BGP filters\n"
7597 "AS path access-list name\n"
7598 "Filter incoming routes\n"
7599 "Filter outgoing routes\n")
7600 {
7601 int idx_peer = 1;
7602 int idx_word = 3;
7603 int idx_in_out = 4;
7604 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7605 bgp_node_safi(vty), argv[idx_word]->arg,
7606 argv[idx_in_out]->arg);
7607 }
7608
7609 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7610 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7611 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7612 "Establish BGP filters\n"
7613 "AS path access-list name\n"
7614 "Filter incoming routes\n"
7615 "Filter outgoing routes\n")
7616
7617 DEFUN (no_neighbor_filter_list,
7618 no_neighbor_filter_list_cmd,
7619 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7620 NO_STR
7621 NEIGHBOR_STR
7622 NEIGHBOR_ADDR_STR2
7623 "Establish BGP filters\n"
7624 "AS path access-list name\n"
7625 "Filter incoming routes\n"
7626 "Filter outgoing routes\n")
7627 {
7628 int idx_peer = 2;
7629 int idx_in_out = 5;
7630 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7631 bgp_node_afi(vty), bgp_node_safi(vty),
7632 argv[idx_in_out]->arg);
7633 }
7634
7635 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7636 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7637 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7638 "Establish BGP filters\n"
7639 "AS path access-list name\n"
7640 "Filter incoming routes\n"
7641 "Filter outgoing routes\n")
7642
7643 /* Set advertise-map to the peer. */
7644 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7645 afi_t afi, safi_t safi,
7646 const char *advertise_str,
7647 const char *condition_str, bool condition,
7648 bool set)
7649 {
7650 int ret = CMD_WARNING_CONFIG_FAILED;
7651 struct peer *peer;
7652 struct route_map *advertise_map;
7653 struct route_map *condition_map;
7654
7655 peer = peer_and_group_lookup_vty(vty, ip_str);
7656 if (!peer)
7657 return ret;
7658
7659 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7660 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7661
7662 if (set)
7663 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7664 advertise_map, condition_str,
7665 condition_map, condition);
7666 else
7667 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7668 advertise_map, condition_str,
7669 condition_map, condition);
7670
7671 return bgp_vty_return(vty, ret);
7672 }
7673
7674 DEFPY (bgp_condadv_period,
7675 bgp_condadv_period_cmd,
7676 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7677 NO_STR
7678 BGP_STR
7679 "Conditional advertisement settings\n"
7680 "Set period to rescan BGP table to check if condition is met\n"
7681 "Period between BGP table scans, in seconds; default 60\n")
7682 {
7683 VTY_DECLVAR_CONTEXT(bgp, bgp);
7684
7685 bgp->condition_check_period =
7686 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7687
7688 return CMD_SUCCESS;
7689 }
7690
7691 DEFPY (neighbor_advertise_map,
7692 neighbor_advertise_map_cmd,
7693 "[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",
7694 NO_STR
7695 NEIGHBOR_STR
7696 NEIGHBOR_ADDR_STR2
7697 "Route-map to conditionally advertise routes\n"
7698 "Name of advertise map\n"
7699 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7700 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7701 "Name of the exist or non exist map\n")
7702 {
7703 bool condition = CONDITION_EXIST;
7704
7705 if (!strcmp(exist, "non-exist-map"))
7706 condition = CONDITION_NON_EXIST;
7707
7708 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7709 bgp_node_safi(vty), advertise_str,
7710 condition_str, condition, !no);
7711 }
7712
7713 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7714 "[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",
7715 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7716 "Route-map to conditionally advertise routes\n"
7717 "Name of advertise map\n"
7718 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7719 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7720 "Name of the exist or non exist map\n")
7721
7722 /* Set route-map to the peer. */
7723 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7724 afi_t afi, safi_t safi, const char *name_str,
7725 const char *direct_str)
7726 {
7727 int ret;
7728 struct peer *peer;
7729 int direct = RMAP_IN;
7730 struct route_map *route_map;
7731
7732 peer = peer_and_group_lookup_vty(vty, ip_str);
7733 if (!peer)
7734 return CMD_WARNING_CONFIG_FAILED;
7735
7736 /* Check filter direction. */
7737 if (strncmp(direct_str, "in", 2) == 0)
7738 direct = RMAP_IN;
7739 else if (strncmp(direct_str, "o", 1) == 0)
7740 direct = RMAP_OUT;
7741
7742 route_map = route_map_lookup_warn_noexist(vty, name_str);
7743 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7744
7745 return bgp_vty_return(vty, ret);
7746 }
7747
7748 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7749 afi_t afi, safi_t safi,
7750 const char *direct_str)
7751 {
7752 int ret;
7753 struct peer *peer;
7754 int direct = RMAP_IN;
7755
7756 peer = peer_and_group_lookup_vty(vty, ip_str);
7757 if (!peer)
7758 return CMD_WARNING_CONFIG_FAILED;
7759
7760 /* Check filter direction. */
7761 if (strncmp(direct_str, "in", 2) == 0)
7762 direct = RMAP_IN;
7763 else if (strncmp(direct_str, "o", 1) == 0)
7764 direct = RMAP_OUT;
7765
7766 ret = peer_route_map_unset(peer, afi, safi, direct);
7767
7768 return bgp_vty_return(vty, ret);
7769 }
7770
7771 DEFUN (neighbor_route_map,
7772 neighbor_route_map_cmd,
7773 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7774 NEIGHBOR_STR
7775 NEIGHBOR_ADDR_STR2
7776 "Apply route map to neighbor\n"
7777 "Name of route map\n"
7778 "Apply map to incoming routes\n"
7779 "Apply map to outbound routes\n")
7780 {
7781 int idx_peer = 1;
7782 int idx_word = 3;
7783 int idx_in_out = 4;
7784 return peer_route_map_set_vty(
7785 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7786 argv[idx_word]->arg, argv[idx_in_out]->arg);
7787 }
7788
7789 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7790 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7791 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7792 "Apply route map to neighbor\n"
7793 "Name of route map\n"
7794 "Apply map to incoming routes\n"
7795 "Apply map to outbound routes\n")
7796
7797 DEFUN (no_neighbor_route_map,
7798 no_neighbor_route_map_cmd,
7799 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7800 NO_STR
7801 NEIGHBOR_STR
7802 NEIGHBOR_ADDR_STR2
7803 "Apply route map to neighbor\n"
7804 "Name of route map\n"
7805 "Apply map to incoming routes\n"
7806 "Apply map to outbound routes\n")
7807 {
7808 int idx_peer = 2;
7809 int idx_in_out = 5;
7810 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7811 bgp_node_afi(vty), bgp_node_safi(vty),
7812 argv[idx_in_out]->arg);
7813 }
7814
7815 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7816 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7817 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7818 "Apply route map to neighbor\n"
7819 "Name of route map\n"
7820 "Apply map to incoming routes\n"
7821 "Apply map to outbound routes\n")
7822
7823 /* Set unsuppress-map to the peer. */
7824 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7825 afi_t afi, safi_t safi,
7826 const char *name_str)
7827 {
7828 int ret;
7829 struct peer *peer;
7830 struct route_map *route_map;
7831
7832 peer = peer_and_group_lookup_vty(vty, ip_str);
7833 if (!peer)
7834 return CMD_WARNING_CONFIG_FAILED;
7835
7836 route_map = route_map_lookup_warn_noexist(vty, name_str);
7837 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7838
7839 return bgp_vty_return(vty, ret);
7840 }
7841
7842 /* Unset route-map from the peer. */
7843 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7844 afi_t afi, safi_t safi)
7845 {
7846 int ret;
7847 struct peer *peer;
7848
7849 peer = peer_and_group_lookup_vty(vty, ip_str);
7850 if (!peer)
7851 return CMD_WARNING_CONFIG_FAILED;
7852
7853 ret = peer_unsuppress_map_unset(peer, afi, safi);
7854
7855 return bgp_vty_return(vty, ret);
7856 }
7857
7858 DEFUN (neighbor_unsuppress_map,
7859 neighbor_unsuppress_map_cmd,
7860 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7861 NEIGHBOR_STR
7862 NEIGHBOR_ADDR_STR2
7863 "Route-map to selectively unsuppress suppressed routes\n"
7864 "Name of route map\n")
7865 {
7866 int idx_peer = 1;
7867 int idx_word = 3;
7868 return peer_unsuppress_map_set_vty(
7869 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7870 argv[idx_word]->arg);
7871 }
7872
7873 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7874 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7876 "Route-map to selectively unsuppress suppressed routes\n"
7877 "Name of route map\n")
7878
7879 DEFUN (no_neighbor_unsuppress_map,
7880 no_neighbor_unsuppress_map_cmd,
7881 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7882 NO_STR
7883 NEIGHBOR_STR
7884 NEIGHBOR_ADDR_STR2
7885 "Route-map to selectively unsuppress suppressed routes\n"
7886 "Name of route map\n")
7887 {
7888 int idx_peer = 2;
7889 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7890 bgp_node_afi(vty),
7891 bgp_node_safi(vty));
7892 }
7893
7894 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7895 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7896 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7897 "Route-map to selectively unsuppress suppressed routes\n"
7898 "Name of route map\n")
7899
7900 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7901 afi_t afi, safi_t safi,
7902 const char *num_str,
7903 const char *threshold_str, int warning,
7904 const char *restart_str,
7905 const char *force_str)
7906 {
7907 int ret;
7908 struct peer *peer;
7909 uint32_t max;
7910 uint8_t threshold;
7911 uint16_t restart;
7912
7913 peer = peer_and_group_lookup_vty(vty, ip_str);
7914 if (!peer)
7915 return CMD_WARNING_CONFIG_FAILED;
7916
7917 max = strtoul(num_str, NULL, 10);
7918 if (threshold_str)
7919 threshold = atoi(threshold_str);
7920 else
7921 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7922
7923 if (restart_str)
7924 restart = atoi(restart_str);
7925 else
7926 restart = 0;
7927
7928 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7929 restart, force_str ? true : false);
7930
7931 return bgp_vty_return(vty, ret);
7932 }
7933
7934 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7935 afi_t afi, safi_t safi)
7936 {
7937 int ret;
7938 struct peer *peer;
7939
7940 peer = peer_and_group_lookup_vty(vty, ip_str);
7941 if (!peer)
7942 return CMD_WARNING_CONFIG_FAILED;
7943
7944 ret = peer_maximum_prefix_unset(peer, afi, safi);
7945
7946 return bgp_vty_return(vty, ret);
7947 }
7948
7949 /* Maximum number of prefix to be sent to the neighbor. */
7950 DEFUN(neighbor_maximum_prefix_out,
7951 neighbor_maximum_prefix_out_cmd,
7952 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7953 NEIGHBOR_STR
7954 NEIGHBOR_ADDR_STR2
7955 "Maximum number of prefixes to be sent to this peer\n"
7956 "Maximum no. of prefix limit\n")
7957 {
7958 int ret;
7959 int idx_peer = 1;
7960 int idx_number = 3;
7961 struct peer *peer;
7962 uint32_t max;
7963 afi_t afi = bgp_node_afi(vty);
7964 safi_t safi = bgp_node_safi(vty);
7965
7966 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7967 if (!peer)
7968 return CMD_WARNING_CONFIG_FAILED;
7969
7970 max = strtoul(argv[idx_number]->arg, NULL, 10);
7971
7972 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
7973
7974 return bgp_vty_return(vty, ret);
7975 }
7976
7977 DEFUN(no_neighbor_maximum_prefix_out,
7978 no_neighbor_maximum_prefix_out_cmd,
7979 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
7980 NO_STR
7981 NEIGHBOR_STR
7982 NEIGHBOR_ADDR_STR2
7983 "Maximum number of prefixes to be sent to this peer\n"
7984 "Maximum no. of prefix limit\n")
7985 {
7986 int ret;
7987 int idx_peer = 2;
7988 struct peer *peer;
7989 afi_t afi = bgp_node_afi(vty);
7990 safi_t safi = bgp_node_safi(vty);
7991
7992 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7993 if (!peer)
7994 return CMD_WARNING_CONFIG_FAILED;
7995
7996 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
7997
7998 return bgp_vty_return(vty, ret);
7999 }
8000
8001 /* Maximum number of prefix configuration. Prefix count is different
8002 for each peer configuration. So this configuration can be set for
8003 each peer configuration. */
8004 DEFUN (neighbor_maximum_prefix,
8005 neighbor_maximum_prefix_cmd,
8006 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8007 NEIGHBOR_STR
8008 NEIGHBOR_ADDR_STR2
8009 "Maximum number of prefix accept from this peer\n"
8010 "maximum no. of prefix limit\n"
8011 "Force checking all received routes not only accepted\n")
8012 {
8013 int idx_peer = 1;
8014 int idx_number = 3;
8015 int idx_force = 0;
8016 char *force = NULL;
8017
8018 if (argv_find(argv, argc, "force", &idx_force))
8019 force = argv[idx_force]->arg;
8020
8021 return peer_maximum_prefix_set_vty(
8022 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8023 argv[idx_number]->arg, NULL, 0, NULL, force);
8024 }
8025
8026 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8027 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8028 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8029 "Maximum number of prefix accept from this peer\n"
8030 "maximum no. of prefix limit\n"
8031 "Force checking all received routes not only accepted\n")
8032
8033 DEFUN (neighbor_maximum_prefix_threshold,
8034 neighbor_maximum_prefix_threshold_cmd,
8035 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [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 "Threshold value (%) at which to generate a warning msg\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_number_2 = 4;
8046 int idx_force = 0;
8047 char *force = NULL;
8048
8049 if (argv_find(argv, argc, "force", &idx_force))
8050 force = argv[idx_force]->arg;
8051
8052 return peer_maximum_prefix_set_vty(
8053 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8054 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8055 }
8056
8057 ALIAS_HIDDEN(
8058 neighbor_maximum_prefix_threshold,
8059 neighbor_maximum_prefix_threshold_hidden_cmd,
8060 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8062 "Maximum number of prefix accept from this peer\n"
8063 "maximum no. of prefix limit\n"
8064 "Threshold value (%) at which to generate a warning msg\n"
8065 "Force checking all received routes not only accepted\n")
8066
8067 DEFUN (neighbor_maximum_prefix_warning,
8068 neighbor_maximum_prefix_warning_cmd,
8069 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8070 NEIGHBOR_STR
8071 NEIGHBOR_ADDR_STR2
8072 "Maximum number of prefix accept from this peer\n"
8073 "maximum no. of prefix limit\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_force = 0;
8080 char *force = NULL;
8081
8082 if (argv_find(argv, argc, "force", &idx_force))
8083 force = argv[idx_force]->arg;
8084
8085 return peer_maximum_prefix_set_vty(
8086 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8087 argv[idx_number]->arg, NULL, 1, NULL, force);
8088 }
8089
8090 ALIAS_HIDDEN(
8091 neighbor_maximum_prefix_warning,
8092 neighbor_maximum_prefix_warning_hidden_cmd,
8093 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8094 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8095 "Maximum number of prefix accept from this peer\n"
8096 "maximum no. of prefix limit\n"
8097 "Only give warning message when limit is exceeded\n"
8098 "Force checking all received routes not only accepted\n")
8099
8100 DEFUN (neighbor_maximum_prefix_threshold_warning,
8101 neighbor_maximum_prefix_threshold_warning_cmd,
8102 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8103 NEIGHBOR_STR
8104 NEIGHBOR_ADDR_STR2
8105 "Maximum number of prefix accept from this peer\n"
8106 "maximum no. of prefix limit\n"
8107 "Threshold value (%) at which to generate a warning msg\n"
8108 "Only give warning message when limit is exceeded\n"
8109 "Force checking all received routes not only accepted\n")
8110 {
8111 int idx_peer = 1;
8112 int idx_number = 3;
8113 int idx_number_2 = 4;
8114 int idx_force = 0;
8115 char *force = NULL;
8116
8117 if (argv_find(argv, argc, "force", &idx_force))
8118 force = argv[idx_force]->arg;
8119
8120 return peer_maximum_prefix_set_vty(
8121 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8122 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8123 }
8124
8125 ALIAS_HIDDEN(
8126 neighbor_maximum_prefix_threshold_warning,
8127 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8128 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8130 "Maximum number of prefix accept from this peer\n"
8131 "maximum no. of prefix limit\n"
8132 "Threshold value (%) at which to generate a warning msg\n"
8133 "Only give warning message when limit is exceeded\n"
8134 "Force checking all received routes not only accepted\n")
8135
8136 DEFUN (neighbor_maximum_prefix_restart,
8137 neighbor_maximum_prefix_restart_cmd,
8138 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8139 NEIGHBOR_STR
8140 NEIGHBOR_ADDR_STR2
8141 "Maximum number of prefix accept from this peer\n"
8142 "maximum no. of prefix limit\n"
8143 "Restart bgp connection after limit is exceeded\n"
8144 "Restart interval in minutes\n"
8145 "Force checking all received routes not only accepted\n")
8146 {
8147 int idx_peer = 1;
8148 int idx_number = 3;
8149 int idx_number_2 = 5;
8150 int idx_force = 0;
8151 char *force = NULL;
8152
8153 if (argv_find(argv, argc, "force", &idx_force))
8154 force = argv[idx_force]->arg;
8155
8156 return peer_maximum_prefix_set_vty(
8157 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8158 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8159 }
8160
8161 ALIAS_HIDDEN(
8162 neighbor_maximum_prefix_restart,
8163 neighbor_maximum_prefix_restart_hidden_cmd,
8164 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8166 "Maximum number of prefix accept from this peer\n"
8167 "maximum no. of prefix limit\n"
8168 "Restart bgp connection after limit is exceeded\n"
8169 "Restart interval in minutes\n"
8170 "Force checking all received routes not only accepted\n")
8171
8172 DEFUN (neighbor_maximum_prefix_threshold_restart,
8173 neighbor_maximum_prefix_threshold_restart_cmd,
8174 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8175 NEIGHBOR_STR
8176 NEIGHBOR_ADDR_STR2
8177 "Maximum number of prefixes to accept from this peer\n"
8178 "maximum no. of prefix limit\n"
8179 "Threshold value (%) at which to generate a warning msg\n"
8180 "Restart bgp connection after limit is exceeded\n"
8181 "Restart interval in minutes\n"
8182 "Force checking all received routes not only accepted\n")
8183 {
8184 int idx_peer = 1;
8185 int idx_number = 3;
8186 int idx_number_2 = 4;
8187 int idx_number_3 = 6;
8188 int idx_force = 0;
8189 char *force = NULL;
8190
8191 if (argv_find(argv, argc, "force", &idx_force))
8192 force = argv[idx_force]->arg;
8193
8194 return peer_maximum_prefix_set_vty(
8195 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8196 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8197 argv[idx_number_3]->arg, force);
8198 }
8199
8200 ALIAS_HIDDEN(
8201 neighbor_maximum_prefix_threshold_restart,
8202 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8203 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8204 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8205 "Maximum number of prefixes to accept from this peer\n"
8206 "maximum no. of prefix limit\n"
8207 "Threshold value (%) at which to generate a warning msg\n"
8208 "Restart bgp connection after limit is exceeded\n"
8209 "Restart interval in minutes\n"
8210 "Force checking all received routes not only accepted\n")
8211
8212 DEFUN (no_neighbor_maximum_prefix,
8213 no_neighbor_maximum_prefix_cmd,
8214 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8215 NO_STR
8216 NEIGHBOR_STR
8217 NEIGHBOR_ADDR_STR2
8218 "Maximum number of prefixes to accept from this peer\n"
8219 "maximum no. of prefix limit\n"
8220 "Threshold value (%) at which to generate a warning msg\n"
8221 "Restart bgp connection after limit is exceeded\n"
8222 "Restart interval in minutes\n"
8223 "Only give warning message when limit is exceeded\n"
8224 "Force checking all received routes not only accepted\n")
8225 {
8226 int idx_peer = 2;
8227 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8228 bgp_node_afi(vty),
8229 bgp_node_safi(vty));
8230 }
8231
8232 ALIAS_HIDDEN(
8233 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8234 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8235 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8236 "Maximum number of prefixes to accept from this peer\n"
8237 "maximum no. of prefix limit\n"
8238 "Threshold value (%) at which to generate a warning msg\n"
8239 "Restart bgp connection after limit is exceeded\n"
8240 "Restart interval in minutes\n"
8241 "Only give warning message when limit is exceeded\n"
8242 "Force checking all received routes not only accepted\n")
8243
8244 /* "neighbor soo" */
8245 DEFPY (neighbor_soo,
8246 neighbor_soo_cmd,
8247 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8248 NEIGHBOR_STR
8249 NEIGHBOR_ADDR_STR2
8250 "Set the Site-of-Origin (SoO) extended community\n"
8251 "VPN extended community\n")
8252 {
8253 struct peer *peer;
8254 afi_t afi = bgp_node_afi(vty);
8255 safi_t safi = bgp_node_safi(vty);
8256 struct ecommunity *ecomm_soo;
8257
8258 peer = peer_and_group_lookup_vty(vty, neighbor);
8259 if (!peer)
8260 return CMD_WARNING_CONFIG_FAILED;
8261
8262 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8263 if (!ecomm_soo) {
8264 vty_out(vty, "%% Malformed SoO extended community\n");
8265 return CMD_WARNING;
8266 }
8267 ecommunity_str(ecomm_soo);
8268
8269 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8270 ecommunity_free(&peer->soo[afi][safi]);
8271 peer->soo[afi][safi] = ecomm_soo;
8272 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8273 }
8274
8275 return bgp_vty_return(vty,
8276 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8277 }
8278
8279 DEFPY (no_neighbor_soo,
8280 no_neighbor_soo_cmd,
8281 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8282 NO_STR
8283 NEIGHBOR_STR
8284 NEIGHBOR_ADDR_STR2
8285 "Set the Site-of-Origin (SoO) extended community\n"
8286 "VPN extended community\n")
8287 {
8288 struct peer *peer;
8289 afi_t afi = bgp_node_afi(vty);
8290 safi_t safi = bgp_node_safi(vty);
8291
8292 peer = peer_and_group_lookup_vty(vty, neighbor);
8293 if (!peer)
8294 return CMD_WARNING_CONFIG_FAILED;
8295
8296 ecommunity_free(&peer->soo[afi][safi]);
8297
8298 return bgp_vty_return(
8299 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8300 }
8301
8302 /* "neighbor allowas-in" */
8303 DEFUN (neighbor_allowas_in,
8304 neighbor_allowas_in_cmd,
8305 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8306 NEIGHBOR_STR
8307 NEIGHBOR_ADDR_STR2
8308 "Accept as-path with my AS present in it\n"
8309 "Number of occurrences of AS number\n"
8310 "Only accept my AS in the as-path if the route was originated in my AS\n")
8311 {
8312 int idx_peer = 1;
8313 int idx_number_origin = 3;
8314 int ret;
8315 int origin = 0;
8316 struct peer *peer;
8317 int allow_num = 0;
8318
8319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8320 if (!peer)
8321 return CMD_WARNING_CONFIG_FAILED;
8322
8323 if (argc <= idx_number_origin)
8324 allow_num = 3;
8325 else {
8326 if (argv[idx_number_origin]->type == WORD_TKN)
8327 origin = 1;
8328 else
8329 allow_num = atoi(argv[idx_number_origin]->arg);
8330 }
8331
8332 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8333 allow_num, origin);
8334
8335 return bgp_vty_return(vty, ret);
8336 }
8337
8338 ALIAS_HIDDEN(
8339 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8340 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8341 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8342 "Accept as-path with my AS present in it\n"
8343 "Number of occurrences of AS number\n"
8344 "Only accept my AS in the as-path if the route was originated in my AS\n")
8345
8346 DEFUN (no_neighbor_allowas_in,
8347 no_neighbor_allowas_in_cmd,
8348 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8349 NO_STR
8350 NEIGHBOR_STR
8351 NEIGHBOR_ADDR_STR2
8352 "allow local ASN appears in aspath attribute\n"
8353 "Number of occurrences of AS number\n"
8354 "Only accept my AS in the as-path if the route was originated in my AS\n")
8355 {
8356 int idx_peer = 2;
8357 int ret;
8358 struct peer *peer;
8359
8360 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8361 if (!peer)
8362 return CMD_WARNING_CONFIG_FAILED;
8363
8364 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8365 bgp_node_safi(vty));
8366
8367 return bgp_vty_return(vty, ret);
8368 }
8369
8370 ALIAS_HIDDEN(
8371 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8372 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8373 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8374 "allow local ASN appears in aspath attribute\n"
8375 "Number of occurrences of AS number\n"
8376 "Only accept my AS in the as-path if the route was originated in my AS\n")
8377
8378 DEFUN (neighbor_ttl_security,
8379 neighbor_ttl_security_cmd,
8380 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8381 NEIGHBOR_STR
8382 NEIGHBOR_ADDR_STR2
8383 "BGP ttl-security parameters\n"
8384 "Specify the maximum number of hops to the BGP peer\n"
8385 "Number of hops to BGP peer\n")
8386 {
8387 int idx_peer = 1;
8388 int idx_number = 4;
8389 struct peer *peer;
8390 int gtsm_hops;
8391
8392 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8393 if (!peer)
8394 return CMD_WARNING_CONFIG_FAILED;
8395
8396 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8397
8398 /*
8399 * If 'neighbor swpX', then this is for directly connected peers,
8400 * we should not accept a ttl-security hops value greater than 1.
8401 */
8402 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8403 vty_out(vty,
8404 "%s is directly connected peer, hops cannot exceed 1\n",
8405 argv[idx_peer]->arg);
8406 return CMD_WARNING_CONFIG_FAILED;
8407 }
8408
8409 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8410 }
8411
8412 DEFUN (no_neighbor_ttl_security,
8413 no_neighbor_ttl_security_cmd,
8414 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8415 NO_STR
8416 NEIGHBOR_STR
8417 NEIGHBOR_ADDR_STR2
8418 "BGP ttl-security parameters\n"
8419 "Specify the maximum number of hops to the BGP peer\n"
8420 "Number of hops to BGP peer\n")
8421 {
8422 int idx_peer = 2;
8423 struct peer *peer;
8424
8425 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8426 if (!peer)
8427 return CMD_WARNING_CONFIG_FAILED;
8428
8429 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8430 }
8431
8432 /* disable-addpath-rx */
8433 DEFUN(neighbor_disable_addpath_rx,
8434 neighbor_disable_addpath_rx_cmd,
8435 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8436 NEIGHBOR_STR
8437 NEIGHBOR_ADDR_STR2
8438 "Do not accept additional paths\n")
8439 {
8440 char *peer_str = argv[1]->arg;
8441 struct peer *peer;
8442 afi_t afi = bgp_node_afi(vty);
8443 safi_t safi = bgp_node_safi(vty);
8444
8445 peer = peer_and_group_lookup_vty(vty, peer_str);
8446 if (!peer)
8447 return CMD_WARNING_CONFIG_FAILED;
8448
8449 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8450 PEER_FLAG_DISABLE_ADDPATH_RX);
8451 }
8452
8453 DEFUN(no_neighbor_disable_addpath_rx,
8454 no_neighbor_disable_addpath_rx_cmd,
8455 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8456 NO_STR
8457 NEIGHBOR_STR
8458 NEIGHBOR_ADDR_STR2
8459 "Do not accept additional paths\n")
8460 {
8461 char *peer_str = argv[2]->arg;
8462 struct peer *peer;
8463 afi_t afi = bgp_node_afi(vty);
8464 safi_t safi = bgp_node_safi(vty);
8465
8466 peer = peer_and_group_lookup_vty(vty, peer_str);
8467 if (!peer)
8468 return CMD_WARNING_CONFIG_FAILED;
8469
8470 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8471 PEER_FLAG_DISABLE_ADDPATH_RX);
8472 }
8473
8474 DEFUN (neighbor_addpath_tx_all_paths,
8475 neighbor_addpath_tx_all_paths_cmd,
8476 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8477 NEIGHBOR_STR
8478 NEIGHBOR_ADDR_STR2
8479 "Use addpath to advertise all paths to a neighbor\n")
8480 {
8481 int idx_peer = 1;
8482 struct peer *peer;
8483
8484 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8485 if (!peer)
8486 return CMD_WARNING_CONFIG_FAILED;
8487
8488 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8489 BGP_ADDPATH_ALL);
8490 return CMD_SUCCESS;
8491 }
8492
8493 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8494 neighbor_addpath_tx_all_paths_hidden_cmd,
8495 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8496 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8497 "Use addpath to advertise all paths to a neighbor\n")
8498
8499 DEFUN (no_neighbor_addpath_tx_all_paths,
8500 no_neighbor_addpath_tx_all_paths_cmd,
8501 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8502 NO_STR
8503 NEIGHBOR_STR
8504 NEIGHBOR_ADDR_STR2
8505 "Use addpath to advertise all paths to a neighbor\n")
8506 {
8507 int idx_peer = 2;
8508 struct peer *peer;
8509
8510 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8511 if (!peer)
8512 return CMD_WARNING_CONFIG_FAILED;
8513
8514 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8515 != BGP_ADDPATH_ALL) {
8516 vty_out(vty,
8517 "%% Peer not currently configured to transmit all paths.");
8518 return CMD_WARNING_CONFIG_FAILED;
8519 }
8520
8521 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8522 BGP_ADDPATH_NONE);
8523
8524 return CMD_SUCCESS;
8525 }
8526
8527 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8528 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8529 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8530 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8531 "Use addpath to advertise all paths to a neighbor\n")
8532
8533 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8534 neighbor_addpath_tx_bestpath_per_as_cmd,
8535 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8536 NEIGHBOR_STR
8537 NEIGHBOR_ADDR_STR2
8538 "Use addpath to advertise the bestpath per each neighboring AS\n")
8539 {
8540 int idx_peer = 1;
8541 struct peer *peer;
8542
8543 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8544 if (!peer)
8545 return CMD_WARNING_CONFIG_FAILED;
8546
8547 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8548 BGP_ADDPATH_BEST_PER_AS);
8549
8550 return CMD_SUCCESS;
8551 }
8552
8553 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8554 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8555 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8556 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8557 "Use addpath to advertise the bestpath per each neighboring AS\n")
8558
8559 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8560 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8561 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8562 NO_STR
8563 NEIGHBOR_STR
8564 NEIGHBOR_ADDR_STR2
8565 "Use addpath to advertise the bestpath per each neighboring AS\n")
8566 {
8567 int idx_peer = 2;
8568 struct peer *peer;
8569
8570 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8571 if (!peer)
8572 return CMD_WARNING_CONFIG_FAILED;
8573
8574 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8575 != BGP_ADDPATH_BEST_PER_AS) {
8576 vty_out(vty,
8577 "%% Peer not currently configured to transmit all best path per as.");
8578 return CMD_WARNING_CONFIG_FAILED;
8579 }
8580
8581 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8582 BGP_ADDPATH_NONE);
8583
8584 return CMD_SUCCESS;
8585 }
8586
8587 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8588 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8589 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8590 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8591 "Use addpath to advertise the bestpath per each neighboring AS\n")
8592
8593 DEFPY(
8594 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8595 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8596 NEIGHBOR_STR
8597 NEIGHBOR_ADDR_STR2
8598 "Detect AS loops before sending to neighbor\n")
8599 {
8600 struct peer *peer;
8601
8602 peer = peer_and_group_lookup_vty(vty, neighbor);
8603 if (!peer)
8604 return CMD_WARNING_CONFIG_FAILED;
8605
8606 peer->as_path_loop_detection = true;
8607
8608 return CMD_SUCCESS;
8609 }
8610
8611 DEFPY(
8612 no_neighbor_aspath_loop_detection,
8613 no_neighbor_aspath_loop_detection_cmd,
8614 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8615 NO_STR
8616 NEIGHBOR_STR
8617 NEIGHBOR_ADDR_STR2
8618 "Detect AS loops before sending to neighbor\n")
8619 {
8620 struct peer *peer;
8621
8622 peer = peer_and_group_lookup_vty(vty, neighbor);
8623 if (!peer)
8624 return CMD_WARNING_CONFIG_FAILED;
8625
8626 peer->as_path_loop_detection = false;
8627
8628 return CMD_SUCCESS;
8629 }
8630
8631 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8632 struct ecommunity **list, bool is_rt6)
8633 {
8634 struct ecommunity *ecom = NULL;
8635 struct ecommunity *ecomadd;
8636
8637 for (; argc; --argc, ++argv) {
8638 if (is_rt6)
8639 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8640 ECOMMUNITY_ROUTE_TARGET,
8641 0);
8642 else
8643 ecomadd = ecommunity_str2com(argv[0]->arg,
8644 ECOMMUNITY_ROUTE_TARGET,
8645 0);
8646 if (!ecomadd) {
8647 vty_out(vty, "Malformed community-list value\n");
8648 if (ecom)
8649 ecommunity_free(&ecom);
8650 return CMD_WARNING_CONFIG_FAILED;
8651 }
8652
8653 if (ecom) {
8654 ecommunity_merge(ecom, ecomadd);
8655 ecommunity_free(&ecomadd);
8656 } else {
8657 ecom = ecomadd;
8658 }
8659 }
8660
8661 if (*list) {
8662 ecommunity_free(&*list);
8663 }
8664 *list = ecom;
8665
8666 return CMD_SUCCESS;
8667 }
8668
8669 /*
8670 * v2vimport is true if we are handling a `import vrf ...` command
8671 */
8672 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8673 {
8674 afi_t afi;
8675
8676 switch (vty->node) {
8677 case BGP_IPV4_NODE:
8678 afi = AFI_IP;
8679 break;
8680 case BGP_IPV6_NODE:
8681 afi = AFI_IP6;
8682 break;
8683 default:
8684 vty_out(vty,
8685 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8686 return AFI_MAX;
8687 }
8688
8689 if (!v2vimport) {
8690 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8691 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8692 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8693 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8694 vty_out(vty,
8695 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8696 return AFI_MAX;
8697 }
8698 } else {
8699 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8700 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8701 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8702 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8703 vty_out(vty,
8704 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8705 return AFI_MAX;
8706 }
8707 }
8708 return afi;
8709 }
8710
8711 DEFPY (af_rd_vpn_export,
8712 af_rd_vpn_export_cmd,
8713 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8714 NO_STR
8715 "Specify route distinguisher\n"
8716 "Between current address-family and vpn\n"
8717 "For routes leaked from current address-family to vpn\n"
8718 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8719 {
8720 VTY_DECLVAR_CONTEXT(bgp, bgp);
8721 struct prefix_rd prd;
8722 int ret;
8723 afi_t afi;
8724 int idx = 0;
8725 bool yes = true;
8726
8727 if (argv_find(argv, argc, "no", &idx))
8728 yes = false;
8729
8730 if (yes) {
8731 ret = str2prefix_rd(rd_str, &prd);
8732 if (!ret) {
8733 vty_out(vty, "%% Malformed rd\n");
8734 return CMD_WARNING_CONFIG_FAILED;
8735 }
8736 }
8737
8738 afi = vpn_policy_getafi(vty, bgp, false);
8739 if (afi == AFI_MAX)
8740 return CMD_WARNING_CONFIG_FAILED;
8741
8742 /*
8743 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8744 */
8745 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8746 bgp_get_default(), bgp);
8747
8748 if (yes) {
8749 bgp->vpn_policy[afi].tovpn_rd = prd;
8750 SET_FLAG(bgp->vpn_policy[afi].flags,
8751 BGP_VPN_POLICY_TOVPN_RD_SET);
8752 } else {
8753 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8754 BGP_VPN_POLICY_TOVPN_RD_SET);
8755 }
8756
8757 /* post-change: re-export vpn routes */
8758 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8759 bgp_get_default(), bgp);
8760
8761 return CMD_SUCCESS;
8762 }
8763
8764 ALIAS (af_rd_vpn_export,
8765 af_no_rd_vpn_export_cmd,
8766 "no rd vpn export",
8767 NO_STR
8768 "Specify route distinguisher\n"
8769 "Between current address-family and vpn\n"
8770 "For routes leaked from current address-family to vpn\n")
8771
8772 DEFPY (af_label_vpn_export,
8773 af_label_vpn_export_cmd,
8774 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8775 NO_STR
8776 "label value for VRF\n"
8777 "Between current address-family and vpn\n"
8778 "For routes leaked from current address-family to vpn\n"
8779 "Label Value <0-1048575>\n"
8780 "Automatically assign a label\n")
8781 {
8782 VTY_DECLVAR_CONTEXT(bgp, bgp);
8783 mpls_label_t label = MPLS_LABEL_NONE;
8784 afi_t afi;
8785 int idx = 0;
8786 bool yes = true;
8787
8788 if (argv_find(argv, argc, "no", &idx))
8789 yes = false;
8790
8791 /* If "no ...", squash trailing parameter */
8792 if (!yes)
8793 label_auto = NULL;
8794
8795 if (yes) {
8796 if (!label_auto)
8797 label = label_val; /* parser should force unsigned */
8798 }
8799
8800 afi = vpn_policy_getafi(vty, bgp, false);
8801 if (afi == AFI_MAX)
8802 return CMD_WARNING_CONFIG_FAILED;
8803
8804
8805 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8806 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8807 /* no change */
8808 return CMD_SUCCESS;
8809
8810 /*
8811 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8812 */
8813 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8814 bgp_get_default(), bgp);
8815
8816 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8817 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8818
8819 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8820
8821 /*
8822 * label has previously been automatically
8823 * assigned by labelpool: release it
8824 *
8825 * NB if tovpn_label == MPLS_LABEL_NONE it
8826 * means the automatic assignment is in flight
8827 * and therefore the labelpool callback must
8828 * detect that the auto label is not needed.
8829 */
8830
8831 bgp_lp_release(LP_TYPE_VRF,
8832 &bgp->vpn_policy[afi],
8833 bgp->vpn_policy[afi].tovpn_label);
8834 }
8835 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8836 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8837 }
8838
8839 bgp->vpn_policy[afi].tovpn_label = label;
8840 if (label_auto) {
8841 SET_FLAG(bgp->vpn_policy[afi].flags,
8842 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8843 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8844 vpn_leak_label_callback);
8845 }
8846
8847 /* post-change: re-export vpn routes */
8848 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8849 bgp_get_default(), bgp);
8850
8851 hook_call(bgp_snmp_update_last_changed, bgp);
8852 return CMD_SUCCESS;
8853 }
8854
8855 DEFPY (af_sid_vpn_export,
8856 af_sid_vpn_export_cmd,
8857 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8858 NO_STR
8859 "sid value for VRF\n"
8860 "Between current address-family and vpn\n"
8861 "For routes leaked from current address-family to vpn\n"
8862 "Sid allocation index\n"
8863 "Automatically assign a label\n")
8864 {
8865 VTY_DECLVAR_CONTEXT(bgp, bgp);
8866 afi_t afi;
8867 int debug = 0;
8868 int idx = 0;
8869 bool yes = true;
8870
8871 if (argv_find(argv, argc, "no", &idx))
8872 yes = false;
8873 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8874 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8875
8876 afi = vpn_policy_getafi(vty, bgp, false);
8877 if (afi == AFI_MAX)
8878 return CMD_WARNING_CONFIG_FAILED;
8879
8880 if (!yes) {
8881 /* implement me */
8882 vty_out(vty, "It's not implemented\n");
8883 return CMD_WARNING_CONFIG_FAILED;
8884 }
8885
8886 /* skip when it's already configured */
8887 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8888 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8889 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8890 return CMD_SUCCESS;
8891
8892 /*
8893 * mode change between sid_idx and sid_auto isn't supported.
8894 * user must negate sid vpn export when they want to change the mode
8895 */
8896 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8897 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8898 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8899 vty_out(vty, "it's already configured as %s.\n",
8900 sid_auto ? "auto-mode" : "idx-mode");
8901 return CMD_WARNING_CONFIG_FAILED;
8902 }
8903
8904 /* pre-change */
8905 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8906 bgp_get_default(), bgp);
8907
8908 if (sid_auto) {
8909 /* SID allocation auto-mode */
8910 if (debug)
8911 zlog_debug("%s: auto sid alloc.", __func__);
8912 SET_FLAG(bgp->vpn_policy[afi].flags,
8913 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8914 } else {
8915 /* SID allocation index-mode */
8916 if (debug)
8917 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8918 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8919 }
8920
8921 /* post-change */
8922 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8923 bgp_get_default(), bgp);
8924 return CMD_SUCCESS;
8925 }
8926
8927 ALIAS (af_label_vpn_export,
8928 af_no_label_vpn_export_cmd,
8929 "no label vpn export",
8930 NO_STR
8931 "label value for VRF\n"
8932 "Between current address-family and vpn\n"
8933 "For routes leaked from current address-family to vpn\n")
8934
8935 DEFPY (af_nexthop_vpn_export,
8936 af_nexthop_vpn_export_cmd,
8937 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8938 NO_STR
8939 "Specify next hop to use for VRF advertised prefixes\n"
8940 "Between current address-family and vpn\n"
8941 "For routes leaked from current address-family to vpn\n"
8942 "IPv4 prefix\n"
8943 "IPv6 prefix\n")
8944 {
8945 VTY_DECLVAR_CONTEXT(bgp, bgp);
8946 afi_t afi;
8947 struct prefix p;
8948
8949 if (!no) {
8950 if (!nexthop_su) {
8951 vty_out(vty, "%% Nexthop required\n");
8952 return CMD_WARNING_CONFIG_FAILED;
8953 }
8954 if (!sockunion2hostprefix(nexthop_su, &p))
8955 return CMD_WARNING_CONFIG_FAILED;
8956 }
8957
8958 afi = vpn_policy_getafi(vty, bgp, false);
8959 if (afi == AFI_MAX)
8960 return CMD_WARNING_CONFIG_FAILED;
8961
8962 /*
8963 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8964 */
8965 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8966 bgp_get_default(), bgp);
8967
8968 if (!no) {
8969 bgp->vpn_policy[afi].tovpn_nexthop = p;
8970 SET_FLAG(bgp->vpn_policy[afi].flags,
8971 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8972 } else {
8973 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8974 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8975 }
8976
8977 /* post-change: re-export vpn routes */
8978 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8979 bgp_get_default(), bgp);
8980
8981 return CMD_SUCCESS;
8982 }
8983
8984 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8985 {
8986 if (!strcmp(dstr, "import")) {
8987 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8988 } else if (!strcmp(dstr, "export")) {
8989 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8990 } else if (!strcmp(dstr, "both")) {
8991 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8992 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8993 } else {
8994 vty_out(vty, "%% direction parse error\n");
8995 return CMD_WARNING_CONFIG_FAILED;
8996 }
8997 return CMD_SUCCESS;
8998 }
8999
9000 DEFPY (af_rt_vpn_imexport,
9001 af_rt_vpn_imexport_cmd,
9002 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9003 NO_STR
9004 "Specify route target list\n"
9005 "Specify route target list\n"
9006 "Between current address-family and vpn\n"
9007 "For routes leaked from vpn to current address-family: match any\n"
9008 "For routes leaked from current address-family to vpn: set\n"
9009 "both import: match any and export: set\n"
9010 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9011 {
9012 VTY_DECLVAR_CONTEXT(bgp, bgp);
9013 int ret;
9014 struct ecommunity *ecom = NULL;
9015 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9016 enum vpn_policy_direction dir;
9017 afi_t afi;
9018 int idx = 0;
9019 bool yes = true;
9020
9021 if (argv_find(argv, argc, "no", &idx))
9022 yes = false;
9023
9024 afi = vpn_policy_getafi(vty, bgp, false);
9025 if (afi == AFI_MAX)
9026 return CMD_WARNING_CONFIG_FAILED;
9027
9028 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9029 if (ret != CMD_SUCCESS)
9030 return ret;
9031
9032 if (yes) {
9033 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9034 vty_out(vty, "%% Missing RTLIST\n");
9035 return CMD_WARNING_CONFIG_FAILED;
9036 }
9037 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9038 if (ret != CMD_SUCCESS) {
9039 return ret;
9040 }
9041 }
9042
9043 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9044 if (!dodir[dir])
9045 continue;
9046
9047 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9048
9049 if (yes) {
9050 if (bgp->vpn_policy[afi].rtlist[dir])
9051 ecommunity_free(
9052 &bgp->vpn_policy[afi].rtlist[dir]);
9053 bgp->vpn_policy[afi].rtlist[dir] =
9054 ecommunity_dup(ecom);
9055 } else {
9056 if (bgp->vpn_policy[afi].rtlist[dir])
9057 ecommunity_free(
9058 &bgp->vpn_policy[afi].rtlist[dir]);
9059 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9060 }
9061
9062 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9063 }
9064
9065 if (ecom)
9066 ecommunity_free(&ecom);
9067
9068 return CMD_SUCCESS;
9069 }
9070
9071 ALIAS (af_rt_vpn_imexport,
9072 af_no_rt_vpn_imexport_cmd,
9073 "no <rt|route-target> vpn <import|export|both>$direction_str",
9074 NO_STR
9075 "Specify route target list\n"
9076 "Specify route target list\n"
9077 "Between current address-family and vpn\n"
9078 "For routes leaked from vpn to current address-family\n"
9079 "For routes leaked from current address-family to vpn\n"
9080 "both import and export\n")
9081
9082 DEFPY (af_route_map_vpn_imexport,
9083 af_route_map_vpn_imexport_cmd,
9084 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9085 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9086 NO_STR
9087 "Specify route map\n"
9088 "Between current address-family and vpn\n"
9089 "For routes leaked from vpn to current address-family\n"
9090 "For routes leaked from current address-family to vpn\n"
9091 "name of route-map\n")
9092 {
9093 VTY_DECLVAR_CONTEXT(bgp, bgp);
9094 int ret;
9095 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9096 enum vpn_policy_direction dir;
9097 afi_t afi;
9098 int idx = 0;
9099 bool yes = true;
9100
9101 if (argv_find(argv, argc, "no", &idx))
9102 yes = false;
9103
9104 afi = vpn_policy_getafi(vty, bgp, false);
9105 if (afi == AFI_MAX)
9106 return CMD_WARNING_CONFIG_FAILED;
9107
9108 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9109 if (ret != CMD_SUCCESS)
9110 return ret;
9111
9112 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9113 if (!dodir[dir])
9114 continue;
9115
9116 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9117
9118 if (yes) {
9119 if (bgp->vpn_policy[afi].rmap_name[dir])
9120 XFREE(MTYPE_ROUTE_MAP_NAME,
9121 bgp->vpn_policy[afi].rmap_name[dir]);
9122 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9123 MTYPE_ROUTE_MAP_NAME, rmap_str);
9124 bgp->vpn_policy[afi].rmap[dir] =
9125 route_map_lookup_warn_noexist(vty, rmap_str);
9126 if (!bgp->vpn_policy[afi].rmap[dir])
9127 return CMD_SUCCESS;
9128 } else {
9129 if (bgp->vpn_policy[afi].rmap_name[dir])
9130 XFREE(MTYPE_ROUTE_MAP_NAME,
9131 bgp->vpn_policy[afi].rmap_name[dir]);
9132 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9133 bgp->vpn_policy[afi].rmap[dir] = NULL;
9134 }
9135
9136 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9137 }
9138
9139 return CMD_SUCCESS;
9140 }
9141
9142 ALIAS (af_route_map_vpn_imexport,
9143 af_no_route_map_vpn_imexport_cmd,
9144 "no route-map vpn <import|export>$direction_str",
9145 NO_STR
9146 "Specify route map\n"
9147 "Between current address-family and vpn\n"
9148 "For routes leaked from vpn to current address-family\n"
9149 "For routes leaked from current address-family to vpn\n")
9150
9151 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9152 "import vrf route-map RMAP$rmap_str",
9153 "Import routes from another VRF\n"
9154 "Vrf routes being filtered\n"
9155 "Specify route map\n"
9156 "name of route-map\n")
9157 {
9158 VTY_DECLVAR_CONTEXT(bgp, bgp);
9159 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9160 afi_t afi;
9161 struct bgp *bgp_default;
9162
9163 afi = vpn_policy_getafi(vty, bgp, true);
9164 if (afi == AFI_MAX)
9165 return CMD_WARNING_CONFIG_FAILED;
9166
9167 bgp_default = bgp_get_default();
9168 if (!bgp_default) {
9169 int32_t ret;
9170 as_t as = bgp->as;
9171
9172 /* Auto-create assuming the same AS */
9173 ret = bgp_get_vty(&bgp_default, &as, NULL,
9174 BGP_INSTANCE_TYPE_DEFAULT);
9175
9176 if (ret) {
9177 vty_out(vty,
9178 "VRF default is not configured as a bgp instance\n");
9179 return CMD_WARNING;
9180 }
9181 }
9182
9183 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9184
9185 if (bgp->vpn_policy[afi].rmap_name[dir])
9186 XFREE(MTYPE_ROUTE_MAP_NAME,
9187 bgp->vpn_policy[afi].rmap_name[dir]);
9188 bgp->vpn_policy[afi].rmap_name[dir] =
9189 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9190 bgp->vpn_policy[afi].rmap[dir] =
9191 route_map_lookup_warn_noexist(vty, rmap_str);
9192 if (!bgp->vpn_policy[afi].rmap[dir])
9193 return CMD_SUCCESS;
9194
9195 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9196 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9197
9198 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9199
9200 return CMD_SUCCESS;
9201 }
9202
9203 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9204 "no import vrf route-map [RMAP$rmap_str]",
9205 NO_STR
9206 "Import routes from another VRF\n"
9207 "Vrf routes being filtered\n"
9208 "Specify route map\n"
9209 "name of route-map\n")
9210 {
9211 VTY_DECLVAR_CONTEXT(bgp, bgp);
9212 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9213 afi_t afi;
9214
9215 afi = vpn_policy_getafi(vty, bgp, true);
9216 if (afi == AFI_MAX)
9217 return CMD_WARNING_CONFIG_FAILED;
9218
9219 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9220
9221 if (bgp->vpn_policy[afi].rmap_name[dir])
9222 XFREE(MTYPE_ROUTE_MAP_NAME,
9223 bgp->vpn_policy[afi].rmap_name[dir]);
9224 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9225 bgp->vpn_policy[afi].rmap[dir] = NULL;
9226
9227 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9228 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9229 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9230
9231 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9232
9233 return CMD_SUCCESS;
9234 }
9235
9236 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9237 "[no] import vrf VIEWVRFNAME$import_name",
9238 NO_STR
9239 "Import routes from another VRF\n"
9240 "VRF to import from\n"
9241 "The name of the VRF\n")
9242 {
9243 VTY_DECLVAR_CONTEXT(bgp, bgp);
9244 struct listnode *node;
9245 struct bgp *vrf_bgp, *bgp_default;
9246 int32_t ret = 0;
9247 as_t as = bgp->as;
9248 bool remove = false;
9249 int32_t idx = 0;
9250 char *vname;
9251 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9252 safi_t safi;
9253 afi_t afi;
9254
9255 if (import_name == NULL) {
9256 vty_out(vty, "%% Missing import name\n");
9257 return CMD_WARNING;
9258 }
9259
9260 if (strcmp(import_name, "route-map") == 0) {
9261 vty_out(vty, "%% Must include route-map name\n");
9262 return CMD_WARNING;
9263 }
9264
9265 if (argv_find(argv, argc, "no", &idx))
9266 remove = true;
9267
9268 afi = vpn_policy_getafi(vty, bgp, true);
9269 if (afi == AFI_MAX)
9270 return CMD_WARNING_CONFIG_FAILED;
9271
9272 safi = bgp_node_safi(vty);
9273
9274 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9275 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9276 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9277 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9278 remove ? "unimport" : "import", import_name);
9279 return CMD_WARNING;
9280 }
9281
9282 bgp_default = bgp_get_default();
9283 if (!bgp_default) {
9284 /* Auto-create assuming the same AS */
9285 ret = bgp_get_vty(&bgp_default, &as, NULL,
9286 BGP_INSTANCE_TYPE_DEFAULT);
9287
9288 if (ret) {
9289 vty_out(vty,
9290 "VRF default is not configured as a bgp instance\n");
9291 return CMD_WARNING;
9292 }
9293 }
9294
9295 vrf_bgp = bgp_lookup_by_name(import_name);
9296 if (!vrf_bgp) {
9297 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9298 vrf_bgp = bgp_default;
9299 else
9300 /* Auto-create assuming the same AS */
9301 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9302
9303 if (ret) {
9304 vty_out(vty,
9305 "VRF %s is not configured as a bgp instance\n",
9306 import_name);
9307 return CMD_WARNING;
9308 }
9309 }
9310
9311 if (remove) {
9312 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9313 } else {
9314 /* Already importing from "import_vrf"? */
9315 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9316 vname)) {
9317 if (strcmp(vname, import_name) == 0)
9318 return CMD_WARNING;
9319 }
9320
9321 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9322 }
9323
9324 return CMD_SUCCESS;
9325 }
9326
9327 /* This command is valid only in a bgp vrf instance or the default instance */
9328 DEFPY (bgp_imexport_vpn,
9329 bgp_imexport_vpn_cmd,
9330 "[no] <import|export>$direction_str vpn",
9331 NO_STR
9332 "Import routes to this address-family\n"
9333 "Export routes from this address-family\n"
9334 "to/from default instance VPN RIB\n")
9335 {
9336 VTY_DECLVAR_CONTEXT(bgp, bgp);
9337 int previous_state;
9338 afi_t afi;
9339 safi_t safi;
9340 int idx = 0;
9341 bool yes = true;
9342 int flag;
9343 enum vpn_policy_direction dir;
9344
9345 if (argv_find(argv, argc, "no", &idx))
9346 yes = false;
9347
9348 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9349 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9350
9351 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9352 return CMD_WARNING_CONFIG_FAILED;
9353 }
9354
9355 afi = bgp_node_afi(vty);
9356 safi = bgp_node_safi(vty);
9357 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9358 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9359 return CMD_WARNING_CONFIG_FAILED;
9360 }
9361
9362 if (!strcmp(direction_str, "import")) {
9363 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9364 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9365 } else if (!strcmp(direction_str, "export")) {
9366 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9367 dir = BGP_VPN_POLICY_DIR_TOVPN;
9368 } else {
9369 vty_out(vty, "%% unknown direction %s\n", direction_str);
9370 return CMD_WARNING_CONFIG_FAILED;
9371 }
9372
9373 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9374
9375 if (yes) {
9376 SET_FLAG(bgp->af_flags[afi][safi], flag);
9377 if (!previous_state) {
9378 /* trigger export current vrf */
9379 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9380 }
9381 } else {
9382 if (previous_state) {
9383 /* trigger un-export current vrf */
9384 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9385 }
9386 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9387 }
9388
9389 hook_call(bgp_snmp_init_stats, bgp);
9390
9391 return CMD_SUCCESS;
9392 }
9393
9394 DEFPY (af_routetarget_import,
9395 af_routetarget_import_cmd,
9396 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9397 NO_STR
9398 "Specify route target list\n"
9399 "Specify route target list\n"
9400 "Specify route target list\n"
9401 "Specify route target list\n"
9402 "Flow-spec redirect type route target\n"
9403 "Import routes to this address-family\n"
9404 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9405 {
9406 VTY_DECLVAR_CONTEXT(bgp, bgp);
9407 int ret;
9408 struct ecommunity *ecom = NULL;
9409 afi_t afi;
9410 int idx = 0, idx_unused = 0;
9411 bool yes = true;
9412 bool rt6 = false;
9413
9414 if (argv_find(argv, argc, "no", &idx))
9415 yes = false;
9416
9417 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9418 argv_find(argv, argc, "route-target6", &idx_unused))
9419 rt6 = true;
9420
9421 afi = vpn_policy_getafi(vty, bgp, false);
9422 if (afi == AFI_MAX)
9423 return CMD_WARNING_CONFIG_FAILED;
9424
9425 if (rt6 && afi != AFI_IP6)
9426 return CMD_WARNING_CONFIG_FAILED;
9427
9428 if (yes) {
9429 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9430 vty_out(vty, "%% Missing RTLIST\n");
9431 return CMD_WARNING_CONFIG_FAILED;
9432 }
9433 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9434 if (ret != CMD_SUCCESS)
9435 return ret;
9436 }
9437
9438 if (yes) {
9439 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9440 ecommunity_free(&bgp->vpn_policy[afi]
9441 .import_redirect_rtlist);
9442 bgp->vpn_policy[afi].import_redirect_rtlist =
9443 ecommunity_dup(ecom);
9444 } else {
9445 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9446 ecommunity_free(&bgp->vpn_policy[afi]
9447 .import_redirect_rtlist);
9448 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9449 }
9450
9451 if (ecom)
9452 ecommunity_free(&ecom);
9453
9454 return CMD_SUCCESS;
9455 }
9456
9457 DEFUN_NOSH (address_family_ipv4_safi,
9458 address_family_ipv4_safi_cmd,
9459 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9460 "Enter Address Family command mode\n"
9461 BGP_AF_STR
9462 BGP_SAFI_WITH_LABEL_HELP_STR)
9463 {
9464
9465 if (argc == 3) {
9466 VTY_DECLVAR_CONTEXT(bgp, bgp);
9467 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9468 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9469 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9470 && safi != SAFI_EVPN) {
9471 vty_out(vty,
9472 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9473 return CMD_WARNING_CONFIG_FAILED;
9474 }
9475 vty->node = bgp_node_type(AFI_IP, safi);
9476 } else
9477 vty->node = BGP_IPV4_NODE;
9478
9479 return CMD_SUCCESS;
9480 }
9481
9482 DEFUN_NOSH (address_family_ipv6_safi,
9483 address_family_ipv6_safi_cmd,
9484 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9485 "Enter Address Family command mode\n"
9486 BGP_AF_STR
9487 BGP_SAFI_WITH_LABEL_HELP_STR)
9488 {
9489 if (argc == 3) {
9490 VTY_DECLVAR_CONTEXT(bgp, bgp);
9491 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9492 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9493 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9494 && safi != SAFI_EVPN) {
9495 vty_out(vty,
9496 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9497 return CMD_WARNING_CONFIG_FAILED;
9498 }
9499 vty->node = bgp_node_type(AFI_IP6, safi);
9500 } else
9501 vty->node = BGP_IPV6_NODE;
9502
9503 return CMD_SUCCESS;
9504 }
9505
9506 #ifdef KEEP_OLD_VPN_COMMANDS
9507 DEFUN_NOSH (address_family_vpnv4,
9508 address_family_vpnv4_cmd,
9509 "address-family vpnv4 [unicast]",
9510 "Enter Address Family command mode\n"
9511 BGP_AF_STR
9512 BGP_AF_MODIFIER_STR)
9513 {
9514 vty->node = BGP_VPNV4_NODE;
9515 return CMD_SUCCESS;
9516 }
9517
9518 DEFUN_NOSH (address_family_vpnv6,
9519 address_family_vpnv6_cmd,
9520 "address-family vpnv6 [unicast]",
9521 "Enter Address Family command mode\n"
9522 BGP_AF_STR
9523 BGP_AF_MODIFIER_STR)
9524 {
9525 vty->node = BGP_VPNV6_NODE;
9526 return CMD_SUCCESS;
9527 }
9528 #endif /* KEEP_OLD_VPN_COMMANDS */
9529
9530 DEFUN_NOSH (address_family_evpn,
9531 address_family_evpn_cmd,
9532 "address-family l2vpn evpn",
9533 "Enter Address Family command mode\n"
9534 BGP_AF_STR
9535 BGP_AF_MODIFIER_STR)
9536 {
9537 VTY_DECLVAR_CONTEXT(bgp, bgp);
9538 vty->node = BGP_EVPN_NODE;
9539 return CMD_SUCCESS;
9540 }
9541
9542 DEFUN_NOSH (bgp_segment_routing_srv6,
9543 bgp_segment_routing_srv6_cmd,
9544 "segment-routing srv6",
9545 "Segment-Routing configuration\n"
9546 "Segment-Routing SRv6 configuration\n")
9547 {
9548 VTY_DECLVAR_CONTEXT(bgp, bgp);
9549 bgp->srv6_enabled = true;
9550 vty->node = BGP_SRV6_NODE;
9551 return CMD_SUCCESS;
9552 }
9553
9554 DEFUN (no_bgp_segment_routing_srv6,
9555 no_bgp_segment_routing_srv6_cmd,
9556 "no segment-routing srv6",
9557 NO_STR
9558 "Segment-Routing configuration\n"
9559 "Segment-Routing SRv6 configuration\n")
9560 {
9561 VTY_DECLVAR_CONTEXT(bgp, bgp);
9562
9563 if (strlen(bgp->srv6_locator_name) > 0)
9564 if (bgp_srv6_locator_unset(bgp) < 0)
9565 return CMD_WARNING_CONFIG_FAILED;
9566
9567 bgp->srv6_enabled = false;
9568 return CMD_SUCCESS;
9569 }
9570
9571 DEFPY (bgp_srv6_locator,
9572 bgp_srv6_locator_cmd,
9573 "locator NAME$name",
9574 "Specify SRv6 locator\n"
9575 "Specify SRv6 locator\n")
9576 {
9577 VTY_DECLVAR_CONTEXT(bgp, bgp);
9578 int ret;
9579
9580 if (strlen(bgp->srv6_locator_name) > 0
9581 && strcmp(name, bgp->srv6_locator_name) != 0) {
9582 vty_out(vty, "srv6 locator is already configured\n");
9583 return CMD_WARNING_CONFIG_FAILED;
9584 }
9585
9586 snprintf(bgp->srv6_locator_name,
9587 sizeof(bgp->srv6_locator_name), "%s", name);
9588
9589 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9590 if (ret < 0)
9591 return CMD_WARNING_CONFIG_FAILED;
9592
9593 return CMD_SUCCESS;
9594 }
9595
9596 DEFPY (no_bgp_srv6_locator,
9597 no_bgp_srv6_locator_cmd,
9598 "no locator NAME$name",
9599 NO_STR
9600 "Specify SRv6 locator\n"
9601 "Specify SRv6 locator\n")
9602 {
9603 VTY_DECLVAR_CONTEXT(bgp, bgp);
9604
9605 /* when locator isn't configured, do nothing */
9606 if (strlen(bgp->srv6_locator_name) < 1)
9607 return CMD_SUCCESS;
9608
9609 /* name validation */
9610 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9611 vty_out(vty, "%% No srv6 locator is configured\n");
9612 return CMD_WARNING_CONFIG_FAILED;
9613 }
9614
9615 /* unset locator */
9616 if (bgp_srv6_locator_unset(bgp) < 0)
9617 return CMD_WARNING_CONFIG_FAILED;
9618
9619 return CMD_SUCCESS;
9620 }
9621
9622 DEFPY (show_bgp_srv6,
9623 show_bgp_srv6_cmd,
9624 "show bgp segment-routing srv6",
9625 SHOW_STR
9626 BGP_STR
9627 "BGP Segment Routing\n"
9628 "BGP Segment Routing SRv6\n")
9629 {
9630 struct bgp *bgp;
9631 struct listnode *node;
9632 struct srv6_locator_chunk *chunk;
9633 struct bgp_srv6_function *func;
9634 struct in6_addr *tovpn4_sid;
9635 struct in6_addr *tovpn6_sid;
9636 char buf[256];
9637 char buf_tovpn4_sid[256];
9638 char buf_tovpn6_sid[256];
9639
9640 bgp = bgp_get_default();
9641 if (!bgp)
9642 return CMD_SUCCESS;
9643
9644 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9645 vty_out(vty, "locator_chunks:\n");
9646 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk))
9647 vty_out(vty, "- %pFX\n", &chunk->prefix);
9648
9649 vty_out(vty, "functions:\n");
9650 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9651 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9652 vty_out(vty, "- sid: %s\n", buf);
9653 vty_out(vty, " locator: %s\n", func->locator_name);
9654 }
9655
9656 vty_out(vty, "bgps:\n");
9657 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9658 vty_out(vty, "- name: %s\n",
9659 bgp->name ? bgp->name : "default");
9660
9661 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9662 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9663 if (tovpn4_sid)
9664 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9665 sizeof(buf_tovpn4_sid));
9666 if (tovpn6_sid)
9667 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9668 sizeof(buf_tovpn6_sid));
9669
9670 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9671 tovpn4_sid ? buf_tovpn4_sid : "none");
9672 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9673 tovpn6_sid ? buf_tovpn6_sid : "none");
9674 }
9675
9676 return CMD_SUCCESS;
9677 }
9678
9679 DEFUN_NOSH (exit_address_family,
9680 exit_address_family_cmd,
9681 "exit-address-family",
9682 "Exit from Address Family configuration mode\n")
9683 {
9684 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9685 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9686 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9687 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9688 || vty->node == BGP_EVPN_NODE
9689 || vty->node == BGP_FLOWSPECV4_NODE
9690 || vty->node == BGP_FLOWSPECV6_NODE)
9691 vty->node = BGP_NODE;
9692 return CMD_SUCCESS;
9693 }
9694
9695 /* Recalculate bestpath and re-advertise a prefix */
9696 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9697 const char *ip_str, afi_t afi, safi_t safi,
9698 struct prefix_rd *prd)
9699 {
9700 int ret;
9701 struct prefix match;
9702 struct bgp_dest *dest;
9703 struct bgp_dest *rm;
9704 struct bgp *bgp;
9705 struct bgp_table *table;
9706 struct bgp_table *rib;
9707
9708 /* BGP structure lookup. */
9709 if (view_name) {
9710 bgp = bgp_lookup_by_name(view_name);
9711 if (bgp == NULL) {
9712 vty_out(vty, "%% Can't find BGP instance %s\n",
9713 view_name);
9714 return CMD_WARNING;
9715 }
9716 } else {
9717 bgp = bgp_get_default();
9718 if (bgp == NULL) {
9719 vty_out(vty, "%% No BGP process is configured\n");
9720 return CMD_WARNING;
9721 }
9722 }
9723
9724 /* Check IP address argument. */
9725 ret = str2prefix(ip_str, &match);
9726 if (!ret) {
9727 vty_out(vty, "%% address is malformed\n");
9728 return CMD_WARNING;
9729 }
9730
9731 match.family = afi2family(afi);
9732 rib = bgp->rib[afi][safi];
9733
9734 if (safi == SAFI_MPLS_VPN) {
9735 for (dest = bgp_table_top(rib); dest;
9736 dest = bgp_route_next(dest)) {
9737 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9738
9739 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9740 continue;
9741
9742 table = bgp_dest_get_bgp_table_info(dest);
9743 if (table == NULL)
9744 continue;
9745
9746 rm = bgp_node_match(table, &match);
9747 if (rm != NULL) {
9748 const struct prefix *rm_p =
9749 bgp_dest_get_prefix(rm);
9750
9751 if (rm_p->prefixlen == match.prefixlen) {
9752 SET_FLAG(rm->flags,
9753 BGP_NODE_USER_CLEAR);
9754 bgp_process(bgp, rm, afi, safi);
9755 }
9756 bgp_dest_unlock_node(rm);
9757 }
9758 }
9759 } else {
9760 dest = bgp_node_match(rib, &match);
9761 if (dest != NULL) {
9762 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9763
9764 if (dest_p->prefixlen == match.prefixlen) {
9765 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9766 bgp_process(bgp, dest, afi, safi);
9767 }
9768 bgp_dest_unlock_node(dest);
9769 }
9770 }
9771
9772 return CMD_SUCCESS;
9773 }
9774
9775 /* one clear bgp command to rule them all */
9776 DEFUN (clear_ip_bgp_all,
9777 clear_ip_bgp_all_cmd,
9778 "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>]",
9779 CLEAR_STR
9780 IP_STR
9781 BGP_STR
9782 BGP_INSTANCE_HELP_STR
9783 BGP_AFI_HELP_STR
9784 BGP_AF_STR
9785 BGP_SAFI_WITH_LABEL_HELP_STR
9786 BGP_AF_MODIFIER_STR
9787 "Clear all peers\n"
9788 "BGP IPv4 neighbor to clear\n"
9789 "BGP IPv6 neighbor to clear\n"
9790 "BGP neighbor on interface to clear\n"
9791 "Clear peers with the AS number\n"
9792 "Clear all external peers\n"
9793 "Clear all members of peer-group\n"
9794 "BGP peer-group name\n"
9795 BGP_SOFT_STR
9796 BGP_SOFT_IN_STR
9797 BGP_SOFT_OUT_STR
9798 BGP_SOFT_IN_STR
9799 "Push out prefix-list ORF and do inbound soft reconfig\n"
9800 BGP_SOFT_OUT_STR
9801 "Reset message statistics\n")
9802 {
9803 char *vrf = NULL;
9804
9805 afi_t afi = AFI_UNSPEC;
9806 safi_t safi = SAFI_UNSPEC;
9807 enum clear_sort clr_sort = clear_peer;
9808 enum bgp_clear_type clr_type;
9809 char *clr_arg = NULL;
9810
9811 int idx = 0;
9812
9813 /* clear [ip] bgp */
9814 if (argv_find(argv, argc, "ip", &idx))
9815 afi = AFI_IP;
9816
9817 /* [<vrf> VIEWVRFNAME] */
9818 if (argv_find(argv, argc, "vrf", &idx)) {
9819 vrf = argv[idx + 1]->arg;
9820 idx += 2;
9821 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9822 vrf = NULL;
9823 } else if (argv_find(argv, argc, "view", &idx)) {
9824 /* [<view> VIEWVRFNAME] */
9825 vrf = argv[idx + 1]->arg;
9826 idx += 2;
9827 }
9828 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9829 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9830 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9831
9832 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9833 if (argv_find(argv, argc, "*", &idx)) {
9834 clr_sort = clear_all;
9835 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9836 clr_sort = clear_peer;
9837 clr_arg = argv[idx]->arg;
9838 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9839 clr_sort = clear_peer;
9840 clr_arg = argv[idx]->arg;
9841 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9842 clr_sort = clear_group;
9843 idx++;
9844 clr_arg = argv[idx]->arg;
9845 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9846 clr_sort = clear_peer;
9847 clr_arg = argv[idx]->arg;
9848 } else if (argv_find(argv, argc, "WORD", &idx)) {
9849 clr_sort = clear_peer;
9850 clr_arg = argv[idx]->arg;
9851 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9852 clr_sort = clear_as;
9853 clr_arg = argv[idx]->arg;
9854 } else if (argv_find(argv, argc, "external", &idx)) {
9855 clr_sort = clear_external;
9856 }
9857
9858 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9859 if (argv_find(argv, argc, "soft", &idx)) {
9860 if (argv_find(argv, argc, "in", &idx)
9861 || argv_find(argv, argc, "out", &idx))
9862 clr_type = strmatch(argv[idx]->text, "in")
9863 ? BGP_CLEAR_SOFT_IN
9864 : BGP_CLEAR_SOFT_OUT;
9865 else
9866 clr_type = BGP_CLEAR_SOFT_BOTH;
9867 } else if (argv_find(argv, argc, "in", &idx)) {
9868 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9869 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9870 : BGP_CLEAR_SOFT_IN;
9871 } else if (argv_find(argv, argc, "out", &idx)) {
9872 clr_type = BGP_CLEAR_SOFT_OUT;
9873 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9874 clr_type = BGP_CLEAR_MESSAGE_STATS;
9875 } else
9876 clr_type = BGP_CLEAR_SOFT_NONE;
9877
9878 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9879 }
9880
9881 DEFUN (clear_ip_bgp_prefix,
9882 clear_ip_bgp_prefix_cmd,
9883 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9884 CLEAR_STR
9885 IP_STR
9886 BGP_STR
9887 BGP_INSTANCE_HELP_STR
9888 "Clear bestpath and re-advertise\n"
9889 "IPv4 prefix\n")
9890 {
9891 char *vrf = NULL;
9892 char *prefix = NULL;
9893
9894 int idx = 0;
9895
9896 /* [<view|vrf> VIEWVRFNAME] */
9897 if (argv_find(argv, argc, "vrf", &idx)) {
9898 vrf = argv[idx + 1]->arg;
9899 idx += 2;
9900 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9901 vrf = NULL;
9902 } else if (argv_find(argv, argc, "view", &idx)) {
9903 /* [<view> VIEWVRFNAME] */
9904 vrf = argv[idx + 1]->arg;
9905 idx += 2;
9906 }
9907
9908 prefix = argv[argc - 1]->arg;
9909
9910 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9911 }
9912
9913 DEFUN (clear_bgp_ipv6_safi_prefix,
9914 clear_bgp_ipv6_safi_prefix_cmd,
9915 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9916 CLEAR_STR
9917 IP_STR
9918 BGP_STR
9919 BGP_AF_STR
9920 BGP_SAFI_HELP_STR
9921 "Clear bestpath and re-advertise\n"
9922 "IPv6 prefix\n")
9923 {
9924 int idx_safi = 0;
9925 int idx_ipv6_prefix = 0;
9926 safi_t safi = SAFI_UNICAST;
9927 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9928 argv[idx_ipv6_prefix]->arg : NULL;
9929
9930 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9931 return bgp_clear_prefix(
9932 vty, NULL, prefix, AFI_IP6,
9933 safi, NULL);
9934 }
9935
9936 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9937 clear_bgp_instance_ipv6_safi_prefix_cmd,
9938 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9939 CLEAR_STR
9940 IP_STR
9941 BGP_STR
9942 BGP_INSTANCE_HELP_STR
9943 BGP_AF_STR
9944 BGP_SAFI_HELP_STR
9945 "Clear bestpath and re-advertise\n"
9946 "IPv6 prefix\n")
9947 {
9948 int idx_safi = 0;
9949 int idx_vrfview = 0;
9950 int idx_ipv6_prefix = 0;
9951 safi_t safi = SAFI_UNICAST;
9952 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9953 argv[idx_ipv6_prefix]->arg : NULL;
9954 char *vrfview = NULL;
9955
9956 /* [<view|vrf> VIEWVRFNAME] */
9957 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9958 vrfview = argv[idx_vrfview + 1]->arg;
9959 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9960 vrfview = NULL;
9961 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9962 /* [<view> VIEWVRFNAME] */
9963 vrfview = argv[idx_vrfview + 1]->arg;
9964 }
9965 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9966
9967 return bgp_clear_prefix(
9968 vty, vrfview, prefix,
9969 AFI_IP6, safi, NULL);
9970 }
9971
9972 DEFUN (show_bgp_views,
9973 show_bgp_views_cmd,
9974 "show [ip] bgp views",
9975 SHOW_STR
9976 IP_STR
9977 BGP_STR
9978 "Show the defined BGP views\n")
9979 {
9980 struct list *inst = bm->bgp;
9981 struct listnode *node;
9982 struct bgp *bgp;
9983
9984 vty_out(vty, "Defined BGP views:\n");
9985 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9986 /* Skip VRFs. */
9987 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9988 continue;
9989 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9990 bgp->as);
9991 }
9992
9993 return CMD_SUCCESS;
9994 }
9995
9996 DEFUN (show_bgp_vrfs,
9997 show_bgp_vrfs_cmd,
9998 "show [ip] bgp vrfs [json]",
9999 SHOW_STR
10000 IP_STR
10001 BGP_STR
10002 "Show BGP VRFs\n"
10003 JSON_STR)
10004 {
10005 char buf[ETHER_ADDR_STRLEN];
10006 struct list *inst = bm->bgp;
10007 struct listnode *node;
10008 struct bgp *bgp;
10009 bool uj = use_json(argc, argv);
10010 json_object *json = NULL;
10011 json_object *json_vrfs = NULL;
10012 int count = 0;
10013
10014 if (uj) {
10015 json = json_object_new_object();
10016 json_vrfs = json_object_new_object();
10017 }
10018
10019 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10020 const char *name, *type;
10021 struct peer *peer;
10022 struct listnode *node2, *nnode2;
10023 int peers_cfg, peers_estb;
10024 json_object *json_vrf = NULL;
10025
10026 /* Skip Views. */
10027 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10028 continue;
10029
10030 count++;
10031 if (!uj && count == 1) {
10032 vty_out(vty,
10033 "%4s %-5s %-16s %9s %10s %-37s\n",
10034 "Type", "Id", "routerId", "#PeersCfg",
10035 "#PeersEstb", "Name");
10036 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10037 "L3-VNI", "RouterMAC", "Interface");
10038 }
10039
10040 peers_cfg = peers_estb = 0;
10041 if (uj)
10042 json_vrf = json_object_new_object();
10043
10044
10045 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10046 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10047 continue;
10048 peers_cfg++;
10049 if (peer_established(peer))
10050 peers_estb++;
10051 }
10052
10053 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10054 name = VRF_DEFAULT_NAME;
10055 type = "DFLT";
10056 } else {
10057 name = bgp->name;
10058 type = "VRF";
10059 }
10060
10061
10062 if (uj) {
10063 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10064 ? -1
10065 : (int64_t)bgp->vrf_id;
10066 char buf[BUFSIZ] = {0};
10067
10068 json_object_string_add(json_vrf, "type", type);
10069 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10070 json_object_string_addf(json_vrf, "routerId", "%pI4",
10071 &bgp->router_id);
10072 json_object_int_add(json_vrf, "numConfiguredPeers",
10073 peers_cfg);
10074 json_object_int_add(json_vrf, "numEstablishedPeers",
10075 peers_estb);
10076
10077 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10078 json_object_string_add(
10079 json_vrf, "rmac",
10080 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10081 json_object_string_add(json_vrf, "interface",
10082 ifindex2ifname(bgp->l3vni_svi_ifindex,
10083 bgp->vrf_id));
10084 json_object_object_add(json_vrfs, name, json_vrf);
10085 } else {
10086 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10087 type,
10088 bgp->vrf_id == VRF_UNKNOWN ? -1
10089 : (int)bgp->vrf_id,
10090 &bgp->router_id, peers_cfg, peers_estb, name);
10091 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10092 bgp->l3vni,
10093 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10094 ifindex2ifname(bgp->l3vni_svi_ifindex,
10095 bgp->vrf_id));
10096 }
10097 }
10098
10099 if (uj) {
10100 json_object_object_add(json, "vrfs", json_vrfs);
10101
10102 json_object_int_add(json, "totalVrfs", count);
10103
10104 vty_json(vty, json);
10105 } else {
10106 if (count)
10107 vty_out(vty,
10108 "\nTotal number of VRFs (including default): %d\n",
10109 count);
10110 }
10111
10112 return CMD_SUCCESS;
10113 }
10114
10115 DEFUN (show_bgp_mac_hash,
10116 show_bgp_mac_hash_cmd,
10117 "show bgp mac hash",
10118 SHOW_STR
10119 BGP_STR
10120 "Mac Address\n"
10121 "Mac Address database\n")
10122 {
10123 bgp_mac_dump_table(vty);
10124
10125 return CMD_SUCCESS;
10126 }
10127
10128 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10129 {
10130 struct vty *vty = (struct vty *)args;
10131 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10132
10133 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10134 }
10135
10136 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10137 {
10138 vty_out(vty, "self nexthop database:\n");
10139 bgp_nexthop_show_address_hash(vty, bgp);
10140
10141 vty_out(vty, "Tunnel-ip database:\n");
10142 hash_iterate(bgp->tip_hash,
10143 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10144 vty);
10145 }
10146
10147 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10148 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10149 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10150 "martian next-hops\n"
10151 "martian next-hop database\n")
10152 {
10153 struct bgp *bgp = NULL;
10154 int idx = 0;
10155 char *name = NULL;
10156
10157 /* [<vrf> VIEWVRFNAME] */
10158 if (argv_find(argv, argc, "vrf", &idx)) {
10159 name = argv[idx + 1]->arg;
10160 if (name && strmatch(name, VRF_DEFAULT_NAME))
10161 name = NULL;
10162 } else if (argv_find(argv, argc, "view", &idx))
10163 /* [<view> VIEWVRFNAME] */
10164 name = argv[idx + 1]->arg;
10165 if (name)
10166 bgp = bgp_lookup_by_name(name);
10167 else
10168 bgp = bgp_get_default();
10169
10170 if (!bgp) {
10171 vty_out(vty, "%% No BGP process is configured\n");
10172 return CMD_WARNING;
10173 }
10174 bgp_show_martian_nexthops(vty, bgp);
10175
10176 return CMD_SUCCESS;
10177 }
10178
10179 DEFUN (show_bgp_memory,
10180 show_bgp_memory_cmd,
10181 "show [ip] bgp memory",
10182 SHOW_STR
10183 IP_STR
10184 BGP_STR
10185 "Global BGP memory statistics\n")
10186 {
10187 char memstrbuf[MTYPE_MEMSTR_LEN];
10188 unsigned long count;
10189
10190 /* RIB related usage stats */
10191 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10192 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10193 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10194 count * sizeof(struct bgp_dest)));
10195
10196 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10197 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10198 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10199 count * sizeof(struct bgp_path_info)));
10200 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10201 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10202 count,
10203 mtype_memstr(
10204 memstrbuf, sizeof(memstrbuf),
10205 count * sizeof(struct bgp_path_info_extra)));
10206
10207 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10208 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10209 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10210 count * sizeof(struct bgp_static)));
10211
10212 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10213 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10214 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10215 count * sizeof(struct bpacket)));
10216
10217 /* Adj-In/Out */
10218 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10219 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10220 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10221 count * sizeof(struct bgp_adj_in)));
10222 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10223 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10224 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10225 count * sizeof(struct bgp_adj_out)));
10226
10227 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10228 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10229 count,
10230 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10231 count * sizeof(struct bgp_nexthop_cache)));
10232
10233 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10234 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10235 count,
10236 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10237 count * sizeof(struct bgp_damp_info)));
10238
10239 /* Attributes */
10240 count = attr_count();
10241 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10242 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10243 count * sizeof(struct attr)));
10244
10245 if ((count = attr_unknown_count()))
10246 vty_out(vty, "%ld unknown attributes\n", count);
10247
10248 /* AS_PATH attributes */
10249 count = aspath_count();
10250 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10251 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10252 count * sizeof(struct aspath)));
10253
10254 count = mtype_stats_alloc(MTYPE_AS_SEG);
10255 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10256 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10257 count * sizeof(struct assegment)));
10258
10259 /* Other attributes */
10260 if ((count = community_count()))
10261 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10262 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10263 count * sizeof(struct community)));
10264 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10265 vty_out(vty,
10266 "%ld BGP ext-community entries, using %s of memory\n",
10267 count,
10268 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10269 count * sizeof(struct ecommunity)));
10270 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10271 vty_out(vty,
10272 "%ld BGP large-community entries, using %s of memory\n",
10273 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10274 count * sizeof(struct lcommunity)));
10275
10276 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10277 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10278 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10279 count * sizeof(struct cluster_list)));
10280
10281 /* Peer related usage */
10282 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10283 vty_out(vty, "%ld peers, using %s of memory\n", count,
10284 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10285 count * sizeof(struct peer)));
10286
10287 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10288 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10289 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10290 count * sizeof(struct peer_group)));
10291
10292 /* Other */
10293 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10294 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10295 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10296 count * sizeof(regex_t)));
10297 return CMD_SUCCESS;
10298 }
10299
10300 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10301 {
10302 json_object *bestpath = json_object_new_object();
10303
10304 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10305 json_object_string_add(bestpath, "asPath", "ignore");
10306
10307 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10308 json_object_string_add(bestpath, "asPath", "confed");
10309
10310 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10311 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10312 json_object_string_add(bestpath, "multiPathRelax",
10313 "as-set");
10314 else
10315 json_object_string_add(bestpath, "multiPathRelax",
10316 "true");
10317 } else
10318 json_object_string_add(bestpath, "multiPathRelax", "false");
10319
10320 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10321 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10322
10323 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10324 json_object_string_add(bestpath, "compareRouterId", "true");
10325 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10326 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10327 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10328 json_object_string_add(bestpath, "med", "confed");
10329 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10330 json_object_string_add(bestpath, "med",
10331 "missing-as-worst");
10332 else
10333 json_object_string_add(bestpath, "med", "true");
10334 }
10335
10336 json_object_object_add(json, "bestPath", bestpath);
10337 }
10338
10339 /* Print the error code/subcode for why the peer is down */
10340 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10341 json_object *json_peer, bool use_json)
10342 {
10343 const char *code_str;
10344 const char *subcode_str;
10345
10346 if (use_json) {
10347 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10348 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10349 char errorcodesubcode_hexstr[5];
10350 char errorcodesubcode_str[256];
10351
10352 code_str = bgp_notify_code_str(peer->notify.code);
10353 subcode_str = bgp_notify_subcode_str(
10354 peer->notify.code,
10355 peer->notify.subcode);
10356
10357 snprintf(errorcodesubcode_hexstr,
10358 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10359 peer->notify.code, peer->notify.subcode);
10360 json_object_string_add(json_peer,
10361 "lastErrorCodeSubcode",
10362 errorcodesubcode_hexstr);
10363 snprintf(errorcodesubcode_str, 255, "%s%s",
10364 code_str, subcode_str);
10365 json_object_string_add(json_peer,
10366 "lastNotificationReason",
10367 errorcodesubcode_str);
10368 json_object_boolean_add(json_peer,
10369 "lastNotificationHardReset",
10370 peer->notify.hard_reset);
10371 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10372 && peer->notify.code == BGP_NOTIFY_CEASE
10373 && (peer->notify.subcode
10374 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10375 || peer->notify.subcode
10376 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10377 && peer->notify.length) {
10378 char msgbuf[1024];
10379 const char *msg_str;
10380
10381 msg_str = bgp_notify_admin_message(
10382 msgbuf, sizeof(msgbuf),
10383 (uint8_t *)peer->notify.data,
10384 peer->notify.length);
10385 if (msg_str)
10386 json_object_string_add(
10387 json_peer,
10388 "lastShutdownDescription",
10389 msg_str);
10390 }
10391
10392 }
10393 json_object_string_add(json_peer, "lastResetDueTo",
10394 peer_down_str[(int)peer->last_reset]);
10395 json_object_int_add(json_peer, "lastResetCode",
10396 peer->last_reset);
10397 } else {
10398 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10399 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10400 code_str = bgp_notify_code_str(peer->notify.code);
10401 subcode_str =
10402 bgp_notify_subcode_str(peer->notify.code,
10403 peer->notify.subcode);
10404 vty_out(vty, " Notification %s (%s%s%s)\n",
10405 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10406 ? "sent"
10407 : "received",
10408 code_str, subcode_str,
10409 peer->notify.hard_reset
10410 ? bgp_notify_subcode_str(
10411 BGP_NOTIFY_CEASE,
10412 BGP_NOTIFY_CEASE_HARD_RESET)
10413 : "");
10414 } else {
10415 vty_out(vty, " %s\n",
10416 peer_down_str[(int)peer->last_reset]);
10417 }
10418 }
10419 }
10420
10421 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10422 safi_t safi)
10423 {
10424 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10425 }
10426
10427 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10428 struct peer *peer, json_object *json_peer,
10429 int max_neighbor_width, bool use_json)
10430 {
10431 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10432 int len;
10433
10434 if (use_json) {
10435 if (peer_dynamic_neighbor(peer))
10436 json_object_boolean_true_add(json_peer,
10437 "dynamicPeer");
10438 if (peer->hostname)
10439 json_object_string_add(json_peer, "hostname",
10440 peer->hostname);
10441
10442 if (peer->domainname)
10443 json_object_string_add(json_peer, "domainname",
10444 peer->domainname);
10445 json_object_int_add(json_peer, "connectionsEstablished",
10446 peer->established);
10447 json_object_int_add(json_peer, "connectionsDropped",
10448 peer->dropped);
10449 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10450 use_json, json_peer);
10451 if (peer_established(peer))
10452 json_object_string_add(json_peer, "lastResetDueTo",
10453 "AFI/SAFI Not Negotiated");
10454 else
10455 bgp_show_peer_reset(NULL, peer, json_peer, true);
10456 } else {
10457 dn_flag[1] = '\0';
10458 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10459 if (peer->hostname
10460 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10461 len = vty_out(vty, "%s%s(%s)", dn_flag,
10462 peer->hostname, peer->host);
10463 else
10464 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10465
10466 /* pad the neighbor column with spaces */
10467 if (len < max_neighbor_width)
10468 vty_out(vty, "%*s", max_neighbor_width - len,
10469 " ");
10470 vty_out(vty, "%7d %7d %9s", peer->established,
10471 peer->dropped,
10472 peer_uptime(peer->uptime, timebuf,
10473 BGP_UPTIME_LEN, 0, NULL));
10474 if (peer_established(peer))
10475 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10476 else
10477 bgp_show_peer_reset(vty, peer, NULL,
10478 false);
10479 }
10480 }
10481
10482 /* Strip peer's description to the given size. */
10483 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10484 {
10485 static char stripped[BUFSIZ];
10486 uint32_t i = 0;
10487 uint32_t last_space = 0;
10488
10489 while (i < size) {
10490 if (*(desc + i) == 0) {
10491 stripped[i] = '\0';
10492 return stripped;
10493 }
10494 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10495 last_space = i;
10496 stripped[i] = *(desc + i);
10497 i++;
10498 }
10499
10500 if (last_space > size)
10501 stripped[size + 1] = '\0';
10502 else
10503 stripped[last_space] = '\0';
10504
10505 return stripped;
10506 }
10507
10508 /* Determine whether var peer should be filtered out of the summary. */
10509 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10510 struct peer *fpeer, int as_type,
10511 as_t as)
10512 {
10513
10514 /* filter neighbor XXXX */
10515 if (fpeer && fpeer != peer)
10516 return true;
10517
10518 /* filter remote-as (internal|external) */
10519 if (as_type != AS_UNSPECIFIED) {
10520 if (peer->as_type == AS_SPECIFIED) {
10521 if (as_type == AS_INTERNAL) {
10522 if (peer->as != peer->local_as)
10523 return true;
10524 } else if (peer->as == peer->local_as)
10525 return true;
10526 } else if (as_type != peer->as_type)
10527 return true;
10528 } else if (as && as != peer->as) /* filter remote-as XXX */
10529 return true;
10530
10531 return false;
10532 }
10533
10534 /* Show BGP peer's summary information.
10535 *
10536 * Peer's description is stripped according to if `wide` option is given
10537 * or not.
10538 *
10539 * When adding new columns to `show bgp summary` output, please make
10540 * sure `Desc` is the lastest column to show because it can contain
10541 * whitespaces and the whole output will be tricky.
10542 */
10543 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10544 struct peer *fpeer, int as_type, as_t as,
10545 uint16_t show_flags)
10546 {
10547 struct peer *peer;
10548 struct listnode *node, *nnode;
10549 unsigned int count = 0, dn_count = 0;
10550 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10551 char neighbor_buf[VTY_BUFSIZ];
10552 int neighbor_col_default_width = 16;
10553 int len, failed_count = 0;
10554 unsigned int filtered_count = 0;
10555 int max_neighbor_width = 0;
10556 int pfx_rcd_safi;
10557 json_object *json = NULL;
10558 json_object *json_peer = NULL;
10559 json_object *json_peers = NULL;
10560 struct peer_af *paf;
10561 struct bgp_filter *filter;
10562 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10563 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10564 bool show_established =
10565 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10566 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10567 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10568
10569 /* labeled-unicast routes are installed in the unicast table so in order
10570 * to
10571 * display the correct PfxRcd value we must look at SAFI_UNICAST
10572 */
10573
10574 if (safi == SAFI_LABELED_UNICAST)
10575 pfx_rcd_safi = SAFI_UNICAST;
10576 else
10577 pfx_rcd_safi = safi;
10578
10579 if (use_json) {
10580 json = json_object_new_object();
10581 json_peers = json_object_new_object();
10582 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10583 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10584 as_type, as)) {
10585 filtered_count++;
10586 count++;
10587 continue;
10588 }
10589
10590 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10591 continue;
10592
10593 if (peer->afc[afi][safi]) {
10594 /* See if we have at least a single failed peer */
10595 if (bgp_has_peer_failed(peer, afi, safi))
10596 failed_count++;
10597 count++;
10598 }
10599 if (peer_dynamic_neighbor(peer))
10600 dn_count++;
10601 }
10602
10603 } else {
10604 /* Loop over all neighbors that will be displayed to determine
10605 * how many
10606 * characters are needed for the Neighbor column
10607 */
10608 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10609 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10610 as_type, as)) {
10611 filtered_count++;
10612 count++;
10613 continue;
10614 }
10615
10616 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10617 continue;
10618
10619 if (peer->afc[afi][safi]) {
10620 memset(dn_flag, '\0', sizeof(dn_flag));
10621 if (peer_dynamic_neighbor(peer))
10622 dn_flag[0] = '*';
10623
10624 if (peer->hostname
10625 && CHECK_FLAG(bgp->flags,
10626 BGP_FLAG_SHOW_HOSTNAME))
10627 snprintf(neighbor_buf,
10628 sizeof(neighbor_buf),
10629 "%s%s(%s) ", dn_flag,
10630 peer->hostname, peer->host);
10631 else
10632 snprintf(neighbor_buf,
10633 sizeof(neighbor_buf), "%s%s ",
10634 dn_flag, peer->host);
10635
10636 len = strlen(neighbor_buf);
10637
10638 if (len > max_neighbor_width)
10639 max_neighbor_width = len;
10640
10641 /* See if we have at least a single failed peer */
10642 if (bgp_has_peer_failed(peer, afi, safi))
10643 failed_count++;
10644 count++;
10645 }
10646 }
10647
10648 /* Originally we displayed the Neighbor column as 16
10649 * characters wide so make that the default
10650 */
10651 if (max_neighbor_width < neighbor_col_default_width)
10652 max_neighbor_width = neighbor_col_default_width;
10653 }
10654
10655 if (show_failed && !failed_count) {
10656 if (use_json) {
10657 json_object_int_add(json, "failedPeersCount", 0);
10658 json_object_int_add(json, "dynamicPeers", dn_count);
10659 json_object_int_add(json, "totalPeers", count);
10660
10661 vty_json(vty, json);
10662 } else {
10663 vty_out(vty, "%% No failed BGP neighbors found\n");
10664 }
10665 return CMD_SUCCESS;
10666 }
10667
10668 count = 0; /* Reset the value as its used again */
10669 filtered_count = 0;
10670 dn_count = 0;
10671 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10672 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10673 continue;
10674
10675 if (!peer->afc[afi][safi])
10676 continue;
10677
10678 if (!count) {
10679 unsigned long ents;
10680 char memstrbuf[MTYPE_MEMSTR_LEN];
10681 int64_t vrf_id_ui;
10682
10683 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10684 ? -1
10685 : (int64_t)bgp->vrf_id;
10686
10687 /* Usage summary and header */
10688 if (use_json) {
10689 json_object_string_addf(json, "routerId",
10690 "%pI4",
10691 &bgp->router_id);
10692 json_object_int_add(json, "as", bgp->as);
10693 json_object_int_add(json, "vrfId", vrf_id_ui);
10694 json_object_string_add(
10695 json, "vrfName",
10696 (bgp->inst_type
10697 == BGP_INSTANCE_TYPE_DEFAULT)
10698 ? VRF_DEFAULT_NAME
10699 : bgp->name);
10700 } else {
10701 vty_out(vty,
10702 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10703 &bgp->router_id, bgp->as,
10704 bgp->vrf_id == VRF_UNKNOWN
10705 ? -1
10706 : (int)bgp->vrf_id);
10707 vty_out(vty, "\n");
10708 }
10709
10710 if (bgp_update_delay_configured(bgp)) {
10711 if (use_json) {
10712 json_object_int_add(
10713 json, "updateDelayLimit",
10714 bgp->v_update_delay);
10715
10716 if (bgp->v_update_delay
10717 != bgp->v_establish_wait)
10718 json_object_int_add(
10719 json,
10720 "updateDelayEstablishWait",
10721 bgp->v_establish_wait);
10722
10723 if (bgp_update_delay_active(bgp)) {
10724 json_object_string_add(
10725 json,
10726 "updateDelayFirstNeighbor",
10727 bgp->update_delay_begin_time);
10728 json_object_boolean_true_add(
10729 json,
10730 "updateDelayInProgress");
10731 } else {
10732 if (bgp->update_delay_over) {
10733 json_object_string_add(
10734 json,
10735 "updateDelayFirstNeighbor",
10736 bgp->update_delay_begin_time);
10737 json_object_string_add(
10738 json,
10739 "updateDelayBestpathResumed",
10740 bgp->update_delay_end_time);
10741 json_object_string_add(
10742 json,
10743 "updateDelayZebraUpdateResume",
10744 bgp->update_delay_zebra_resume_time);
10745 json_object_string_add(
10746 json,
10747 "updateDelayPeerUpdateResume",
10748 bgp->update_delay_peers_resume_time);
10749 }
10750 }
10751 } else {
10752 vty_out(vty,
10753 "Read-only mode update-delay limit: %d seconds\n",
10754 bgp->v_update_delay);
10755 if (bgp->v_update_delay
10756 != bgp->v_establish_wait)
10757 vty_out(vty,
10758 " Establish wait: %d seconds\n",
10759 bgp->v_establish_wait);
10760
10761 if (bgp_update_delay_active(bgp)) {
10762 vty_out(vty,
10763 " First neighbor established: %s\n",
10764 bgp->update_delay_begin_time);
10765 vty_out(vty,
10766 " Delay in progress\n");
10767 } else {
10768 if (bgp->update_delay_over) {
10769 vty_out(vty,
10770 " First neighbor established: %s\n",
10771 bgp->update_delay_begin_time);
10772 vty_out(vty,
10773 " Best-paths resumed: %s\n",
10774 bgp->update_delay_end_time);
10775 vty_out(vty,
10776 " zebra update resumed: %s\n",
10777 bgp->update_delay_zebra_resume_time);
10778 vty_out(vty,
10779 " peers update resumed: %s\n",
10780 bgp->update_delay_peers_resume_time);
10781 }
10782 }
10783 }
10784 }
10785
10786 if (use_json) {
10787 if (bgp_maxmed_onstartup_configured(bgp)
10788 && bgp->maxmed_active)
10789 json_object_boolean_true_add(
10790 json, "maxMedOnStartup");
10791 if (bgp->v_maxmed_admin)
10792 json_object_boolean_true_add(
10793 json, "maxMedAdministrative");
10794
10795 json_object_int_add(
10796 json, "tableVersion",
10797 bgp_table_version(bgp->rib[afi][safi]));
10798
10799 ents = bgp_table_count(bgp->rib[afi][safi]);
10800 json_object_int_add(json, "ribCount", ents);
10801 json_object_int_add(
10802 json, "ribMemory",
10803 ents * sizeof(struct bgp_dest));
10804
10805 ents = bgp->af_peer_count[afi][safi];
10806 json_object_int_add(json, "peerCount", ents);
10807 json_object_int_add(json, "peerMemory",
10808 ents * sizeof(struct peer));
10809
10810 if ((ents = listcount(bgp->group))) {
10811 json_object_int_add(
10812 json, "peerGroupCount", ents);
10813 json_object_int_add(
10814 json, "peerGroupMemory",
10815 ents * sizeof(struct
10816 peer_group));
10817 }
10818
10819 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10820 BGP_CONFIG_DAMPENING))
10821 json_object_boolean_true_add(
10822 json, "dampeningEnabled");
10823 } else {
10824 if (!show_terse) {
10825 if (bgp_maxmed_onstartup_configured(bgp)
10826 && bgp->maxmed_active)
10827 vty_out(vty,
10828 "Max-med on-startup active\n");
10829 if (bgp->v_maxmed_admin)
10830 vty_out(vty,
10831 "Max-med administrative active\n");
10832
10833 vty_out(vty,
10834 "BGP table version %" PRIu64
10835 "\n",
10836 bgp_table_version(
10837 bgp->rib[afi][safi]));
10838
10839 ents = bgp_table_count(
10840 bgp->rib[afi][safi]);
10841 vty_out(vty,
10842 "RIB entries %ld, using %s of memory\n",
10843 ents,
10844 mtype_memstr(
10845 memstrbuf,
10846 sizeof(memstrbuf),
10847 ents
10848 * sizeof(
10849 struct
10850 bgp_dest)));
10851
10852 /* Peer related usage */
10853 ents = bgp->af_peer_count[afi][safi];
10854 vty_out(vty,
10855 "Peers %ld, using %s of memory\n",
10856 ents,
10857 mtype_memstr(
10858 memstrbuf,
10859 sizeof(memstrbuf),
10860 ents
10861 * sizeof(
10862 struct
10863 peer)));
10864
10865 if ((ents = listcount(bgp->group)))
10866 vty_out(vty,
10867 "Peer groups %ld, using %s of memory\n",
10868 ents,
10869 mtype_memstr(
10870 memstrbuf,
10871 sizeof(memstrbuf),
10872 ents
10873 * sizeof(
10874 struct
10875 peer_group)));
10876
10877 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10878 BGP_CONFIG_DAMPENING))
10879 vty_out(vty,
10880 "Dampening enabled.\n");
10881 }
10882 if (show_failed) {
10883 vty_out(vty, "\n");
10884
10885 /* Subtract 8 here because 'Neighbor' is
10886 * 8 characters */
10887 vty_out(vty, "Neighbor");
10888 vty_out(vty, "%*s",
10889 max_neighbor_width - 8, " ");
10890 vty_out(vty,
10891 BGP_SHOW_SUMMARY_HEADER_FAILED);
10892 }
10893 }
10894 }
10895
10896 paf = peer_af_find(peer, afi, safi);
10897 filter = &peer->filter[afi][safi];
10898
10899 count++;
10900 /* Works for both failed & successful cases */
10901 if (peer_dynamic_neighbor(peer))
10902 dn_count++;
10903
10904 if (use_json) {
10905 json_peer = NULL;
10906 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10907 as_type, as)) {
10908 filtered_count++;
10909 continue;
10910 }
10911 if (show_failed &&
10912 bgp_has_peer_failed(peer, afi, safi)) {
10913 json_peer = json_object_new_object();
10914 bgp_show_failed_summary(vty, bgp, peer,
10915 json_peer, 0, use_json);
10916 } else if (!show_failed) {
10917 if (show_established
10918 && bgp_has_peer_failed(peer, afi, safi)) {
10919 filtered_count++;
10920 continue;
10921 }
10922
10923 json_peer = json_object_new_object();
10924 if (peer_dynamic_neighbor(peer)) {
10925 json_object_boolean_true_add(json_peer,
10926 "dynamicPeer");
10927 }
10928
10929 if (peer->hostname)
10930 json_object_string_add(json_peer, "hostname",
10931 peer->hostname);
10932
10933 if (peer->domainname)
10934 json_object_string_add(json_peer, "domainname",
10935 peer->domainname);
10936
10937 json_object_int_add(json_peer, "remoteAs", peer->as);
10938 json_object_int_add(
10939 json_peer, "localAs",
10940 peer->change_local_as
10941 ? peer->change_local_as
10942 : peer->local_as);
10943 json_object_int_add(json_peer, "version", 4);
10944 json_object_int_add(json_peer, "msgRcvd",
10945 PEER_TOTAL_RX(peer));
10946 json_object_int_add(json_peer, "msgSent",
10947 PEER_TOTAL_TX(peer));
10948
10949 atomic_size_t outq_count, inq_count;
10950 outq_count = atomic_load_explicit(
10951 &peer->obuf->count,
10952 memory_order_relaxed);
10953 inq_count = atomic_load_explicit(
10954 &peer->ibuf->count,
10955 memory_order_relaxed);
10956
10957 json_object_int_add(json_peer, "tableVersion",
10958 peer->version[afi][safi]);
10959 json_object_int_add(json_peer, "outq",
10960 outq_count);
10961 json_object_int_add(json_peer, "inq",
10962 inq_count);
10963 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10964 use_json, json_peer);
10965
10966 json_object_int_add(json_peer, "pfxRcd",
10967 peer->pcount[afi][pfx_rcd_safi]);
10968
10969 if (paf && PAF_SUBGRP(paf))
10970 json_object_int_add(
10971 json_peer, "pfxSnt",
10972 (PAF_SUBGRP(paf))->scount);
10973 else
10974 json_object_int_add(json_peer, "pfxSnt",
10975 0);
10976
10977 /* BGP FSM state */
10978 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10979 || CHECK_FLAG(peer->bgp->flags,
10980 BGP_FLAG_SHUTDOWN))
10981 json_object_string_add(json_peer,
10982 "state",
10983 "Idle (Admin)");
10984 else if (peer->afc_recv[afi][safi])
10985 json_object_string_add(
10986 json_peer, "state",
10987 lookup_msg(bgp_status_msg,
10988 peer->status, NULL));
10989 else if (CHECK_FLAG(
10990 peer->sflags,
10991 PEER_STATUS_PREFIX_OVERFLOW))
10992 json_object_string_add(json_peer,
10993 "state",
10994 "Idle (PfxCt)");
10995 else
10996 json_object_string_add(
10997 json_peer, "state",
10998 lookup_msg(bgp_status_msg,
10999 peer->status, NULL));
11000
11001 /* BGP peer state */
11002 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11003 || CHECK_FLAG(peer->bgp->flags,
11004 BGP_FLAG_SHUTDOWN))
11005 json_object_string_add(json_peer,
11006 "peerState",
11007 "Admin");
11008 else if (CHECK_FLAG(
11009 peer->sflags,
11010 PEER_STATUS_PREFIX_OVERFLOW))
11011 json_object_string_add(json_peer,
11012 "peerState",
11013 "PfxCt");
11014 else if (CHECK_FLAG(peer->flags,
11015 PEER_FLAG_PASSIVE))
11016 json_object_string_add(json_peer,
11017 "peerState",
11018 "Passive");
11019 else if (CHECK_FLAG(peer->sflags,
11020 PEER_STATUS_NSF_WAIT))
11021 json_object_string_add(json_peer,
11022 "peerState",
11023 "NSF passive");
11024 else if (CHECK_FLAG(
11025 peer->bgp->flags,
11026 BGP_FLAG_EBGP_REQUIRES_POLICY)
11027 && (!bgp_inbound_policy_exists(peer,
11028 filter)
11029 || !bgp_outbound_policy_exists(
11030 peer, filter)))
11031 json_object_string_add(json_peer,
11032 "peerState",
11033 "Policy");
11034 else
11035 json_object_string_add(
11036 json_peer, "peerState", "OK");
11037
11038 json_object_int_add(json_peer, "connectionsEstablished",
11039 peer->established);
11040 json_object_int_add(json_peer, "connectionsDropped",
11041 peer->dropped);
11042 if (peer->desc)
11043 json_object_string_add(
11044 json_peer, "desc", peer->desc);
11045 }
11046 /* Avoid creating empty peer dicts in JSON */
11047 if (json_peer == NULL)
11048 continue;
11049
11050 if (peer->conf_if)
11051 json_object_string_add(json_peer, "idType",
11052 "interface");
11053 else if (peer->su.sa.sa_family == AF_INET)
11054 json_object_string_add(json_peer, "idType",
11055 "ipv4");
11056 else if (peer->su.sa.sa_family == AF_INET6)
11057 json_object_string_add(json_peer, "idType",
11058 "ipv6");
11059 json_object_object_add(json_peers, peer->host,
11060 json_peer);
11061 } else {
11062 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11063 as_type, as)) {
11064 filtered_count++;
11065 continue;
11066 }
11067 if (show_failed &&
11068 bgp_has_peer_failed(peer, afi, safi)) {
11069 bgp_show_failed_summary(vty, bgp, peer, NULL,
11070 max_neighbor_width,
11071 use_json);
11072 } else if (!show_failed) {
11073 if (show_established
11074 && bgp_has_peer_failed(peer, afi, safi)) {
11075 filtered_count++;
11076 continue;
11077 }
11078
11079 if ((count - filtered_count) == 1) {
11080 /* display headline before the first
11081 * neighbor line */
11082 vty_out(vty, "\n");
11083
11084 /* Subtract 8 here because 'Neighbor' is
11085 * 8 characters */
11086 vty_out(vty, "Neighbor");
11087 vty_out(vty, "%*s",
11088 max_neighbor_width - 8, " ");
11089 vty_out(vty,
11090 show_wide
11091 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11092 : BGP_SHOW_SUMMARY_HEADER_ALL);
11093 }
11094
11095 memset(dn_flag, '\0', sizeof(dn_flag));
11096 if (peer_dynamic_neighbor(peer)) {
11097 dn_flag[0] = '*';
11098 }
11099
11100 if (peer->hostname
11101 && CHECK_FLAG(bgp->flags,
11102 BGP_FLAG_SHOW_HOSTNAME))
11103 len = vty_out(vty, "%s%s(%s)", dn_flag,
11104 peer->hostname,
11105 peer->host);
11106 else
11107 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11108
11109 /* pad the neighbor column with spaces */
11110 if (len < max_neighbor_width)
11111 vty_out(vty, "%*s", max_neighbor_width - len,
11112 " ");
11113
11114 atomic_size_t outq_count, inq_count;
11115 outq_count = atomic_load_explicit(
11116 &peer->obuf->count,
11117 memory_order_relaxed);
11118 inq_count = atomic_load_explicit(
11119 &peer->ibuf->count,
11120 memory_order_relaxed);
11121
11122 if (show_wide)
11123 vty_out(vty,
11124 "4 %10u %10u %9u %9u %8" PRIu64
11125 " %4zu %4zu %8s",
11126 peer->as,
11127 peer->change_local_as
11128 ? peer->change_local_as
11129 : peer->local_as,
11130 PEER_TOTAL_RX(peer),
11131 PEER_TOTAL_TX(peer),
11132 peer->version[afi][safi],
11133 inq_count, outq_count,
11134 peer_uptime(peer->uptime,
11135 timebuf,
11136 BGP_UPTIME_LEN, 0,
11137 NULL));
11138 else
11139 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11140 " %4zu %4zu %8s",
11141 peer->as, PEER_TOTAL_RX(peer),
11142 PEER_TOTAL_TX(peer),
11143 peer->version[afi][safi],
11144 inq_count, outq_count,
11145 peer_uptime(peer->uptime,
11146 timebuf,
11147 BGP_UPTIME_LEN, 0,
11148 NULL));
11149
11150 if (peer_established(peer)) {
11151 if (peer->afc_recv[afi][safi]) {
11152 if (CHECK_FLAG(
11153 bgp->flags,
11154 BGP_FLAG_EBGP_REQUIRES_POLICY)
11155 && !bgp_inbound_policy_exists(
11156 peer, filter))
11157 vty_out(vty, " %12s",
11158 "(Policy)");
11159 else
11160 vty_out(vty,
11161 " %12u",
11162 peer->pcount
11163 [afi]
11164 [pfx_rcd_safi]);
11165 } else {
11166 vty_out(vty, " NoNeg");
11167 }
11168
11169 if (paf && PAF_SUBGRP(paf)) {
11170 if (CHECK_FLAG(
11171 bgp->flags,
11172 BGP_FLAG_EBGP_REQUIRES_POLICY)
11173 && !bgp_outbound_policy_exists(
11174 peer, filter))
11175 vty_out(vty, " %8s",
11176 "(Policy)");
11177 else
11178 vty_out(vty,
11179 " %8u",
11180 (PAF_SUBGRP(
11181 paf))
11182 ->scount);
11183 } else {
11184 vty_out(vty, " NoNeg");
11185 }
11186 } else {
11187 if (CHECK_FLAG(peer->flags,
11188 PEER_FLAG_SHUTDOWN)
11189 || CHECK_FLAG(peer->bgp->flags,
11190 BGP_FLAG_SHUTDOWN))
11191 vty_out(vty, " Idle (Admin)");
11192 else if (CHECK_FLAG(
11193 peer->sflags,
11194 PEER_STATUS_PREFIX_OVERFLOW))
11195 vty_out(vty, " Idle (PfxCt)");
11196 else
11197 vty_out(vty, " %12s",
11198 lookup_msg(bgp_status_msg,
11199 peer->status, NULL));
11200
11201 vty_out(vty, " %8u", 0);
11202 }
11203 /* Make sure `Desc` column is the lastest in
11204 * the output.
11205 */
11206 if (peer->desc)
11207 vty_out(vty, " %s",
11208 bgp_peer_description_stripped(
11209 peer->desc,
11210 show_wide ? 64 : 20));
11211 else
11212 vty_out(vty, " N/A");
11213 vty_out(vty, "\n");
11214 }
11215
11216 }
11217 }
11218
11219 if (use_json) {
11220 json_object_object_add(json, "peers", json_peers);
11221 json_object_int_add(json, "failedPeers", failed_count);
11222 json_object_int_add(json, "displayedPeers",
11223 count - filtered_count);
11224 json_object_int_add(json, "totalPeers", count);
11225 json_object_int_add(json, "dynamicPeers", dn_count);
11226
11227 if (!show_failed)
11228 bgp_show_bestpath_json(bgp, json);
11229
11230 vty_json(vty, json);
11231 } else {
11232 if (count) {
11233 if (filtered_count == count)
11234 vty_out(vty, "\n%% No matching neighbor\n");
11235 else {
11236 if (show_failed)
11237 vty_out(vty, "\nDisplayed neighbors %d",
11238 failed_count);
11239 else if (as_type != AS_UNSPECIFIED || as
11240 || fpeer || show_established)
11241 vty_out(vty, "\nDisplayed neighbors %d",
11242 count - filtered_count);
11243
11244 vty_out(vty, "\nTotal number of neighbors %d\n",
11245 count);
11246 }
11247 } else {
11248 vty_out(vty, "No %s neighbor is configured\n",
11249 get_afi_safi_str(afi, safi, false));
11250 }
11251
11252 if (dn_count) {
11253 vty_out(vty, "* - dynamic neighbor\n");
11254 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11255 dn_count, bgp->dynamic_neighbors_limit);
11256 }
11257 }
11258
11259 return CMD_SUCCESS;
11260 }
11261
11262 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11263 int safi, struct peer *fpeer, int as_type,
11264 as_t as, uint16_t show_flags)
11265 {
11266 int is_first = 1;
11267 int afi_wildcard = (afi == AFI_MAX);
11268 int safi_wildcard = (safi == SAFI_MAX);
11269 int is_wildcard = (afi_wildcard || safi_wildcard);
11270 bool nbr_output = false;
11271 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11272
11273 if (use_json && is_wildcard)
11274 vty_out(vty, "{\n");
11275 if (afi_wildcard)
11276 afi = 1; /* AFI_IP */
11277 while (afi < AFI_MAX) {
11278 if (safi_wildcard)
11279 safi = 1; /* SAFI_UNICAST */
11280 while (safi < SAFI_MAX) {
11281 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11282 nbr_output = true;
11283
11284 if (is_wildcard) {
11285 /*
11286 * So limit output to those afi/safi
11287 * pairs that
11288 * actualy have something interesting in
11289 * them
11290 */
11291 if (use_json) {
11292 if (!is_first)
11293 vty_out(vty, ",\n");
11294 else
11295 is_first = 0;
11296
11297 vty_out(vty, "\"%s\":",
11298 get_afi_safi_str(afi,
11299 safi,
11300 true));
11301 } else {
11302 vty_out(vty,
11303 "\n%s Summary (%s):\n",
11304 get_afi_safi_str(afi,
11305 safi,
11306 false),
11307 bgp->name_pretty);
11308 }
11309 }
11310 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11311 as_type, as, show_flags);
11312 }
11313 safi++;
11314 if (!safi_wildcard)
11315 safi = SAFI_MAX;
11316 }
11317 afi++;
11318 if (!afi_wildcard)
11319 afi = AFI_MAX;
11320 }
11321
11322 if (use_json && is_wildcard)
11323 vty_out(vty, "}\n");
11324 else if (!nbr_output) {
11325 if (use_json)
11326 vty_out(vty, "{}\n");
11327 else
11328 vty_out(vty, "%% No BGP neighbors found in %s\n",
11329 bgp->name_pretty);
11330 }
11331 }
11332
11333 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11334 safi_t safi,
11335 const char *neighbor,
11336 int as_type, as_t as,
11337 uint16_t show_flags)
11338 {
11339 struct listnode *node, *nnode;
11340 struct bgp *bgp;
11341 struct peer *fpeer = NULL;
11342 int is_first = 1;
11343 bool nbr_output = false;
11344 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11345
11346 if (use_json)
11347 vty_out(vty, "{\n");
11348
11349 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11350 nbr_output = true;
11351 if (use_json) {
11352 if (!is_first)
11353 vty_out(vty, ",\n");
11354 else
11355 is_first = 0;
11356
11357 vty_out(vty, "\"%s\":",
11358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11359 ? VRF_DEFAULT_NAME
11360 : bgp->name);
11361 }
11362 if (neighbor) {
11363 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11364 use_json);
11365 if (!fpeer)
11366 continue;
11367 }
11368 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11369 as, show_flags);
11370 }
11371
11372 if (use_json)
11373 vty_out(vty, "}\n");
11374 else if (!nbr_output)
11375 vty_out(vty, "%% BGP instance not found\n");
11376 }
11377
11378 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11379 safi_t safi, const char *neighbor, int as_type,
11380 as_t as, uint16_t show_flags)
11381 {
11382 struct bgp *bgp;
11383 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11384 struct peer *fpeer = NULL;
11385
11386 if (name) {
11387 if (strmatch(name, "all")) {
11388 bgp_show_all_instances_summary_vty(vty, afi, safi,
11389 neighbor, as_type,
11390 as, show_flags);
11391 return CMD_SUCCESS;
11392 } else {
11393 bgp = bgp_lookup_by_name(name);
11394
11395 if (!bgp) {
11396 if (use_json)
11397 vty_out(vty, "{}\n");
11398 else
11399 vty_out(vty,
11400 "%% BGP instance not found\n");
11401 return CMD_WARNING;
11402 }
11403
11404 if (neighbor) {
11405 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11406 use_json);
11407 if (!fpeer)
11408 return CMD_WARNING;
11409 }
11410 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11411 as_type, as, show_flags);
11412 return CMD_SUCCESS;
11413 }
11414 }
11415
11416 bgp = bgp_get_default();
11417
11418 if (bgp) {
11419 if (neighbor) {
11420 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11421 use_json);
11422 if (!fpeer)
11423 return CMD_WARNING;
11424 }
11425 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11426 as, show_flags);
11427 } else {
11428 if (use_json)
11429 vty_out(vty, "{}\n");
11430 else
11431 vty_out(vty, "%% BGP instance not found\n");
11432 return CMD_WARNING;
11433 }
11434
11435 return CMD_SUCCESS;
11436 }
11437
11438 /* `show [ip] bgp summary' commands. */
11439 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11440 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11441 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11442 "]] [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]",
11443 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11444 BGP_SAFI_WITH_LABEL_HELP_STR
11445 "Display the entries for all address families\n"
11446 "Summary of BGP neighbor status\n"
11447 "Show only sessions in Established state\n"
11448 "Show only sessions not in Established state\n"
11449 "Show only the specified neighbor session\n"
11450 "Neighbor to display information about\n"
11451 "Neighbor to display information about\n"
11452 "Neighbor on BGP configured interface\n"
11453 "Show only the specified remote AS sessions\n"
11454 "AS number\n"
11455 "Internal (iBGP) AS sessions\n"
11456 "External (eBGP) AS sessions\n"
11457 "Shorten the information on BGP instances\n"
11458 "Increase table width for longer output\n" JSON_STR)
11459 {
11460 char *vrf = NULL;
11461 afi_t afi = AFI_MAX;
11462 safi_t safi = SAFI_MAX;
11463 as_t as = 0; /* 0 means AS filter not set */
11464 int as_type = AS_UNSPECIFIED;
11465 uint16_t show_flags = 0;
11466
11467 int idx = 0;
11468
11469 /* show [ip] bgp */
11470 if (!all && argv_find(argv, argc, "ip", &idx))
11471 afi = AFI_IP;
11472 /* [<vrf> VIEWVRFNAME] */
11473 if (argv_find(argv, argc, "vrf", &idx)) {
11474 vrf = argv[idx + 1]->arg;
11475 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11476 vrf = NULL;
11477 } else if (argv_find(argv, argc, "view", &idx))
11478 /* [<view> VIEWVRFNAME] */
11479 vrf = argv[idx + 1]->arg;
11480 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11481 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11482 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11483 }
11484
11485 if (argv_find(argv, argc, "failed", &idx))
11486 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11487
11488 if (argv_find(argv, argc, "established", &idx))
11489 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11490
11491 if (argv_find(argv, argc, "remote-as", &idx)) {
11492 if (argv[idx + 1]->arg[0] == 'i')
11493 as_type = AS_INTERNAL;
11494 else if (argv[idx + 1]->arg[0] == 'e')
11495 as_type = AS_EXTERNAL;
11496 else
11497 as = (as_t)atoi(argv[idx + 1]->arg);
11498 }
11499
11500 if (argv_find(argv, argc, "terse", &idx))
11501 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11502
11503 if (argv_find(argv, argc, "wide", &idx))
11504 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11505
11506 if (argv_find(argv, argc, "json", &idx))
11507 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11508
11509 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11510 show_flags);
11511 }
11512
11513 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11514 {
11515 if (for_json)
11516 return get_afi_safi_json_str(afi, safi);
11517 else
11518 return get_afi_safi_vty_str(afi, safi);
11519 }
11520
11521
11522 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11523 afi_t afi, safi_t safi,
11524 uint16_t adv_smcap, uint16_t adv_rmcap,
11525 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11526 bool use_json, json_object *json_pref)
11527 {
11528 /* Send-Mode */
11529 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11530 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11531 if (use_json) {
11532 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11533 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11534 json_object_string_add(json_pref, "sendMode",
11535 "advertisedAndReceived");
11536 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11537 json_object_string_add(json_pref, "sendMode",
11538 "advertised");
11539 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11540 json_object_string_add(json_pref, "sendMode",
11541 "received");
11542 } else {
11543 vty_out(vty, " Send-mode: ");
11544 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11545 vty_out(vty, "advertised");
11546 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11547 vty_out(vty, "%sreceived",
11548 CHECK_FLAG(p->af_cap[afi][safi],
11549 adv_smcap)
11550 ? ", "
11551 : "");
11552 vty_out(vty, "\n");
11553 }
11554 }
11555
11556 /* Receive-Mode */
11557 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11558 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11559 if (use_json) {
11560 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11561 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11562 json_object_string_add(json_pref, "recvMode",
11563 "advertisedAndReceived");
11564 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11565 json_object_string_add(json_pref, "recvMode",
11566 "advertised");
11567 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11568 json_object_string_add(json_pref, "recvMode",
11569 "received");
11570 } else {
11571 vty_out(vty, " Receive-mode: ");
11572 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11573 vty_out(vty, "advertised");
11574 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11575 vty_out(vty, "%sreceived",
11576 CHECK_FLAG(p->af_cap[afi][safi],
11577 adv_rmcap)
11578 ? ", "
11579 : "");
11580 vty_out(vty, "\n");
11581 }
11582 }
11583 }
11584
11585 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11586 struct peer *p,
11587 bool use_json,
11588 json_object *json)
11589 {
11590 bool rbit = false;
11591 bool nbit = false;
11592
11593 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11594 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11595 && (peer_established(p))) {
11596 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11597 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11598 }
11599
11600 if (use_json) {
11601 json_object_boolean_add(json, "rBit", rbit);
11602 json_object_boolean_add(json, "nBit", nbit);
11603 } else {
11604 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11605 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11606 }
11607 }
11608
11609 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11610 struct peer *peer,
11611 bool use_json,
11612 json_object *json)
11613 {
11614 const char *mode = "NotApplicable";
11615
11616 if (!use_json)
11617 vty_out(vty, "\n Remote GR Mode: ");
11618
11619 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11620 && (peer_established(peer))) {
11621
11622 if ((peer->nsf_af_count == 0)
11623 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11624
11625 mode = "Disable";
11626
11627 } else if (peer->nsf_af_count == 0
11628 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11629
11630 mode = "Helper";
11631
11632 } else if (peer->nsf_af_count != 0
11633 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11634
11635 mode = "Restart";
11636 }
11637 }
11638
11639 if (use_json) {
11640 json_object_string_add(json, "remoteGrMode", mode);
11641 } else
11642 vty_out(vty, mode, "\n");
11643 }
11644
11645 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11646 struct peer *p,
11647 bool use_json,
11648 json_object *json)
11649 {
11650 const char *mode = "Invalid";
11651
11652 if (!use_json)
11653 vty_out(vty, " Local GR Mode: ");
11654
11655 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11656 mode = "Helper";
11657 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11658 mode = "Restart";
11659 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11660 mode = "Disable";
11661 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11662 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11663 mode = "Helper*";
11664 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11665 mode = "Restart*";
11666 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11667 mode = "Disable*";
11668 else
11669 mode = "Invalid*";
11670 }
11671
11672 if (use_json) {
11673 json_object_string_add(json, "localGrMode", mode);
11674 } else {
11675 vty_out(vty, mode, "\n");
11676 }
11677 }
11678
11679 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11680 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11681 {
11682 afi_t afi;
11683 safi_t safi;
11684 json_object *json_afi_safi = NULL;
11685 json_object *json_timer = NULL;
11686 json_object *json_endofrib_status = NULL;
11687 bool eor_flag = false;
11688
11689 FOREACH_AFI_SAFI_NSF (afi, safi) {
11690 if (!peer->afc[afi][safi])
11691 continue;
11692
11693 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11694 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11695 continue;
11696
11697 if (use_json) {
11698 json_afi_safi = json_object_new_object();
11699 json_endofrib_status = json_object_new_object();
11700 json_timer = json_object_new_object();
11701 }
11702
11703 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11704 eor_flag = true;
11705 else
11706 eor_flag = false;
11707
11708 if (!use_json) {
11709 vty_out(vty, " %s:\n",
11710 get_afi_safi_str(afi, safi, false));
11711
11712 vty_out(vty, " F bit: ");
11713 }
11714
11715 if (peer->nsf[afi][safi] &&
11716 CHECK_FLAG(peer->af_cap[afi][safi],
11717 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11718
11719 if (use_json) {
11720 json_object_boolean_true_add(json_afi_safi,
11721 "fBit");
11722 } else
11723 vty_out(vty, "True\n");
11724 } else {
11725 if (use_json)
11726 json_object_boolean_false_add(json_afi_safi,
11727 "fBit");
11728 else
11729 vty_out(vty, "False\n");
11730 }
11731
11732 if (!use_json)
11733 vty_out(vty, " End-of-RIB sent: ");
11734
11735 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11736 PEER_STATUS_EOR_SEND)) {
11737 if (use_json) {
11738 json_object_boolean_true_add(
11739 json_endofrib_status, "endOfRibSend");
11740
11741 PRINT_EOR_JSON(eor_flag);
11742 } else {
11743 vty_out(vty, "Yes\n");
11744 vty_out(vty,
11745 " End-of-RIB sent after update: ");
11746
11747 PRINT_EOR(eor_flag);
11748 }
11749 } else {
11750 if (use_json) {
11751 json_object_boolean_false_add(
11752 json_endofrib_status, "endOfRibSend");
11753 json_object_boolean_false_add(
11754 json_endofrib_status,
11755 "endOfRibSentAfterUpdate");
11756 } else {
11757 vty_out(vty, "No\n");
11758 vty_out(vty,
11759 " End-of-RIB sent after update: ");
11760 vty_out(vty, "No\n");
11761 }
11762 }
11763
11764 if (!use_json)
11765 vty_out(vty, " End-of-RIB received: ");
11766
11767 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11768 PEER_STATUS_EOR_RECEIVED)) {
11769 if (use_json)
11770 json_object_boolean_true_add(
11771 json_endofrib_status, "endOfRibRecv");
11772 else
11773 vty_out(vty, "Yes\n");
11774 } else {
11775 if (use_json)
11776 json_object_boolean_false_add(
11777 json_endofrib_status, "endOfRibRecv");
11778 else
11779 vty_out(vty, "No\n");
11780 }
11781
11782 if (use_json) {
11783 json_object_int_add(json_timer, "stalePathTimer",
11784 peer->bgp->stalepath_time);
11785
11786 if (peer->t_gr_stale != NULL) {
11787 json_object_int_add(json_timer,
11788 "stalePathTimerRemaining",
11789 thread_timer_remain_second(
11790 peer->t_gr_stale));
11791 }
11792
11793 /* Display Configured Selection
11794 * Deferral only when when
11795 * Gr mode is enabled.
11796 */
11797 if (CHECK_FLAG(peer->flags,
11798 PEER_FLAG_GRACEFUL_RESTART)) {
11799 json_object_int_add(json_timer,
11800 "selectionDeferralTimer",
11801 peer->bgp->stalepath_time);
11802 }
11803
11804 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11805 NULL) {
11806
11807 json_object_int_add(
11808 json_timer,
11809 "selectionDeferralTimerRemaining",
11810 thread_timer_remain_second(
11811 peer->bgp->gr_info[afi][safi]
11812 .t_select_deferral));
11813 }
11814 } else {
11815 vty_out(vty, " Timers:\n");
11816 vty_out(vty,
11817 " Configured Stale Path Time(sec): %u\n",
11818 peer->bgp->stalepath_time);
11819
11820 if (peer->t_gr_stale != NULL)
11821 vty_out(vty,
11822 " Stale Path Remaining(sec): %ld\n",
11823 thread_timer_remain_second(
11824 peer->t_gr_stale));
11825 /* Display Configured Selection
11826 * Deferral only when when
11827 * Gr mode is enabled.
11828 */
11829 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11830 vty_out(vty,
11831 " Configured Selection Deferral Time(sec): %u\n",
11832 peer->bgp->select_defer_time);
11833
11834 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11835 NULL)
11836 vty_out(vty,
11837 " Selection Deferral Time Remaining(sec): %ld\n",
11838 thread_timer_remain_second(
11839 peer->bgp->gr_info[afi][safi]
11840 .t_select_deferral));
11841 }
11842 if (use_json) {
11843 json_object_object_add(json_afi_safi, "endOfRibStatus",
11844 json_endofrib_status);
11845 json_object_object_add(json_afi_safi, "timers",
11846 json_timer);
11847 json_object_object_add(
11848 json, get_afi_safi_str(afi, safi, true),
11849 json_afi_safi);
11850 }
11851 }
11852 }
11853
11854 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11855 struct peer *p,
11856 bool use_json,
11857 json_object *json)
11858 {
11859 if (use_json) {
11860 json_object *json_timer = NULL;
11861
11862 json_timer = json_object_new_object();
11863
11864 json_object_int_add(json_timer, "configuredRestartTimer",
11865 p->bgp->restart_time);
11866
11867 json_object_int_add(json_timer, "receivedRestartTimer",
11868 p->v_gr_restart);
11869
11870 if (p->t_gr_restart != NULL)
11871 json_object_int_add(
11872 json_timer, "restartTimerRemaining",
11873 thread_timer_remain_second(p->t_gr_restart));
11874
11875 json_object_object_add(json, "timers", json_timer);
11876 } else {
11877
11878 vty_out(vty, " Timers:\n");
11879 vty_out(vty, " Configured Restart Time(sec): %u\n",
11880 p->bgp->restart_time);
11881
11882 vty_out(vty, " Received Restart Time(sec): %u\n",
11883 p->v_gr_restart);
11884 if (p->t_gr_restart != NULL)
11885 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11886 thread_timer_remain_second(p->t_gr_restart));
11887 if (p->t_gr_restart != NULL) {
11888 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11889 thread_timer_remain_second(p->t_gr_restart));
11890 }
11891 }
11892 }
11893
11894 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11895 bool use_json, json_object *json)
11896 {
11897 char dn_flag[2] = {0};
11898 /* '*' + v6 address of neighbor */
11899 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11900
11901 if (!p->conf_if && peer_dynamic_neighbor(p))
11902 dn_flag[0] = '*';
11903
11904 if (p->conf_if) {
11905 if (use_json)
11906 json_object_string_addf(json, "neighborAddr", "%pSU",
11907 &p->su);
11908 else
11909 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11910 &p->su);
11911 } else {
11912 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11913 p->host);
11914
11915 if (use_json)
11916 json_object_string_add(json, "neighborAddr",
11917 neighborAddr);
11918 else
11919 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11920 }
11921
11922 /* more gr info in new format */
11923 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11924 }
11925
11926 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11927 safi_t safi, bool use_json,
11928 json_object *json_neigh)
11929 {
11930 struct bgp_filter *filter;
11931 struct peer_af *paf;
11932 char orf_pfx_name[BUFSIZ];
11933 int orf_pfx_count;
11934 json_object *json_af = NULL;
11935 json_object *json_prefA = NULL;
11936 json_object *json_prefB = NULL;
11937 json_object *json_addr = NULL;
11938 json_object *json_advmap = NULL;
11939
11940 if (use_json) {
11941 json_addr = json_object_new_object();
11942 json_af = json_object_new_object();
11943 filter = &p->filter[afi][safi];
11944
11945 if (peer_group_active(p))
11946 json_object_string_add(json_addr, "peerGroupMember",
11947 p->group->name);
11948
11949 paf = peer_af_find(p, afi, safi);
11950 if (paf && PAF_SUBGRP(paf)) {
11951 json_object_int_add(json_addr, "updateGroupId",
11952 PAF_UPDGRP(paf)->id);
11953 json_object_int_add(json_addr, "subGroupId",
11954 PAF_SUBGRP(paf)->id);
11955 json_object_int_add(json_addr, "packetQueueLength",
11956 bpacket_queue_virtual_length(paf));
11957 }
11958
11959 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11960 || CHECK_FLAG(p->af_cap[afi][safi],
11961 PEER_CAP_ORF_PREFIX_SM_RCV)
11962 || CHECK_FLAG(p->af_cap[afi][safi],
11963 PEER_CAP_ORF_PREFIX_RM_ADV)
11964 || CHECK_FLAG(p->af_cap[afi][safi],
11965 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11966 json_object_int_add(json_af, "orfType",
11967 ORF_TYPE_PREFIX);
11968 json_prefA = json_object_new_object();
11969 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11970 PEER_CAP_ORF_PREFIX_SM_ADV,
11971 PEER_CAP_ORF_PREFIX_RM_ADV,
11972 PEER_CAP_ORF_PREFIX_SM_RCV,
11973 PEER_CAP_ORF_PREFIX_RM_RCV,
11974 use_json, json_prefA);
11975 json_object_object_add(json_af, "orfPrefixList",
11976 json_prefA);
11977 }
11978
11979 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11980 || CHECK_FLAG(p->af_cap[afi][safi],
11981 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11982 || CHECK_FLAG(p->af_cap[afi][safi],
11983 PEER_CAP_ORF_PREFIX_RM_ADV)
11984 || CHECK_FLAG(p->af_cap[afi][safi],
11985 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11986 json_object_int_add(json_af, "orfOldType",
11987 ORF_TYPE_PREFIX_OLD);
11988 json_prefB = json_object_new_object();
11989 bgp_show_peer_afi_orf_cap(
11990 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11991 PEER_CAP_ORF_PREFIX_RM_ADV,
11992 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11993 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11994 json_prefB);
11995 json_object_object_add(json_af, "orfOldPrefixList",
11996 json_prefB);
11997 }
11998
11999 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12000 || CHECK_FLAG(p->af_cap[afi][safi],
12001 PEER_CAP_ORF_PREFIX_SM_RCV)
12002 || CHECK_FLAG(p->af_cap[afi][safi],
12003 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12004 || CHECK_FLAG(p->af_cap[afi][safi],
12005 PEER_CAP_ORF_PREFIX_RM_ADV)
12006 || CHECK_FLAG(p->af_cap[afi][safi],
12007 PEER_CAP_ORF_PREFIX_RM_RCV)
12008 || CHECK_FLAG(p->af_cap[afi][safi],
12009 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12010 json_object_object_add(json_addr, "afDependentCap",
12011 json_af);
12012 else
12013 json_object_free(json_af);
12014
12015 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12016 p->host, afi, safi);
12017 orf_pfx_count = prefix_bgp_show_prefix_list(
12018 NULL, afi, orf_pfx_name, use_json);
12019
12020 if (CHECK_FLAG(p->af_sflags[afi][safi],
12021 PEER_STATUS_ORF_PREFIX_SEND)
12022 || orf_pfx_count) {
12023 if (CHECK_FLAG(p->af_sflags[afi][safi],
12024 PEER_STATUS_ORF_PREFIX_SEND))
12025 json_object_boolean_true_add(json_neigh,
12026 "orfSent");
12027 if (orf_pfx_count)
12028 json_object_int_add(json_addr, "orfRecvCounter",
12029 orf_pfx_count);
12030 }
12031 if (CHECK_FLAG(p->af_sflags[afi][safi],
12032 PEER_STATUS_ORF_WAIT_REFRESH))
12033 json_object_string_add(
12034 json_addr, "orfFirstUpdate",
12035 "deferredUntilORFOrRouteRefreshRecvd");
12036
12037 if (CHECK_FLAG(p->af_flags[afi][safi],
12038 PEER_FLAG_REFLECTOR_CLIENT))
12039 json_object_boolean_true_add(json_addr,
12040 "routeReflectorClient");
12041 if (CHECK_FLAG(p->af_flags[afi][safi],
12042 PEER_FLAG_RSERVER_CLIENT))
12043 json_object_boolean_true_add(json_addr,
12044 "routeServerClient");
12045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12046 json_object_boolean_true_add(json_addr,
12047 "inboundSoftConfigPermit");
12048
12049 if (CHECK_FLAG(p->af_flags[afi][safi],
12050 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12051 json_object_boolean_true_add(
12052 json_addr,
12053 "privateAsNumsAllReplacedInUpdatesToNbr");
12054 else if (CHECK_FLAG(p->af_flags[afi][safi],
12055 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12056 json_object_boolean_true_add(
12057 json_addr,
12058 "privateAsNumsReplacedInUpdatesToNbr");
12059 else if (CHECK_FLAG(p->af_flags[afi][safi],
12060 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12061 json_object_boolean_true_add(
12062 json_addr,
12063 "privateAsNumsAllRemovedInUpdatesToNbr");
12064 else if (CHECK_FLAG(p->af_flags[afi][safi],
12065 PEER_FLAG_REMOVE_PRIVATE_AS))
12066 json_object_boolean_true_add(
12067 json_addr,
12068 "privateAsNumsRemovedInUpdatesToNbr");
12069
12070 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12071 json_object_boolean_true_add(
12072 json_addr,
12073 bgp_addpath_names(p->addpath_type[afi][safi])
12074 ->type_json_name);
12075
12076 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12077 json_object_string_add(json_addr,
12078 "overrideASNsInOutboundUpdates",
12079 "ifAspathEqualRemoteAs");
12080
12081 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12082 || CHECK_FLAG(p->af_flags[afi][safi],
12083 PEER_FLAG_FORCE_NEXTHOP_SELF))
12084 json_object_boolean_true_add(json_addr,
12085 "routerAlwaysNextHop");
12086 if (CHECK_FLAG(p->af_flags[afi][safi],
12087 PEER_FLAG_AS_PATH_UNCHANGED))
12088 json_object_boolean_true_add(
12089 json_addr, "unchangedAsPathPropogatedToNbr");
12090 if (CHECK_FLAG(p->af_flags[afi][safi],
12091 PEER_FLAG_NEXTHOP_UNCHANGED))
12092 json_object_boolean_true_add(
12093 json_addr, "unchangedNextHopPropogatedToNbr");
12094 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12095 json_object_boolean_true_add(
12096 json_addr, "unchangedMedPropogatedToNbr");
12097 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12098 || CHECK_FLAG(p->af_flags[afi][safi],
12099 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12100 if (CHECK_FLAG(p->af_flags[afi][safi],
12101 PEER_FLAG_SEND_COMMUNITY)
12102 && CHECK_FLAG(p->af_flags[afi][safi],
12103 PEER_FLAG_SEND_EXT_COMMUNITY))
12104 json_object_string_add(json_addr,
12105 "commAttriSentToNbr",
12106 "extendedAndStandard");
12107 else if (CHECK_FLAG(p->af_flags[afi][safi],
12108 PEER_FLAG_SEND_EXT_COMMUNITY))
12109 json_object_string_add(json_addr,
12110 "commAttriSentToNbr",
12111 "extended");
12112 else
12113 json_object_string_add(json_addr,
12114 "commAttriSentToNbr",
12115 "standard");
12116 }
12117 if (CHECK_FLAG(p->af_flags[afi][safi],
12118 PEER_FLAG_DEFAULT_ORIGINATE)) {
12119 if (p->default_rmap[afi][safi].name)
12120 json_object_string_add(
12121 json_addr, "defaultRouteMap",
12122 p->default_rmap[afi][safi].name);
12123
12124 if (paf && PAF_SUBGRP(paf)
12125 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12126 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12127 json_object_boolean_true_add(json_addr,
12128 "defaultSent");
12129 else
12130 json_object_boolean_true_add(json_addr,
12131 "defaultNotSent");
12132 }
12133
12134 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12135 if (is_evpn_enabled())
12136 json_object_boolean_true_add(
12137 json_addr, "advertiseAllVnis");
12138 }
12139
12140 if (filter->plist[FILTER_IN].name
12141 || filter->dlist[FILTER_IN].name
12142 || filter->aslist[FILTER_IN].name
12143 || filter->map[RMAP_IN].name)
12144 json_object_boolean_true_add(json_addr,
12145 "inboundPathPolicyConfig");
12146 if (filter->plist[FILTER_OUT].name
12147 || filter->dlist[FILTER_OUT].name
12148 || filter->aslist[FILTER_OUT].name
12149 || filter->map[RMAP_OUT].name || filter->usmap.name)
12150 json_object_boolean_true_add(
12151 json_addr, "outboundPathPolicyConfig");
12152
12153 /* prefix-list */
12154 if (filter->plist[FILTER_IN].name)
12155 json_object_string_add(json_addr,
12156 "incomingUpdatePrefixFilterList",
12157 filter->plist[FILTER_IN].name);
12158 if (filter->plist[FILTER_OUT].name)
12159 json_object_string_add(json_addr,
12160 "outgoingUpdatePrefixFilterList",
12161 filter->plist[FILTER_OUT].name);
12162
12163 /* distribute-list */
12164 if (filter->dlist[FILTER_IN].name)
12165 json_object_string_add(
12166 json_addr, "incomingUpdateNetworkFilterList",
12167 filter->dlist[FILTER_IN].name);
12168 if (filter->dlist[FILTER_OUT].name)
12169 json_object_string_add(
12170 json_addr, "outgoingUpdateNetworkFilterList",
12171 filter->dlist[FILTER_OUT].name);
12172
12173 /* filter-list. */
12174 if (filter->aslist[FILTER_IN].name)
12175 json_object_string_add(json_addr,
12176 "incomingUpdateAsPathFilterList",
12177 filter->aslist[FILTER_IN].name);
12178 if (filter->aslist[FILTER_OUT].name)
12179 json_object_string_add(json_addr,
12180 "outgoingUpdateAsPathFilterList",
12181 filter->aslist[FILTER_OUT].name);
12182
12183 /* route-map. */
12184 if (filter->map[RMAP_IN].name)
12185 json_object_string_add(
12186 json_addr, "routeMapForIncomingAdvertisements",
12187 filter->map[RMAP_IN].name);
12188 if (filter->map[RMAP_OUT].name)
12189 json_object_string_add(
12190 json_addr, "routeMapForOutgoingAdvertisements",
12191 filter->map[RMAP_OUT].name);
12192
12193 /* ebgp-requires-policy (inbound) */
12194 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12195 && !bgp_inbound_policy_exists(p, filter))
12196 json_object_string_add(
12197 json_addr, "inboundEbgpRequiresPolicy",
12198 "Inbound updates discarded due to missing policy");
12199
12200 /* ebgp-requires-policy (outbound) */
12201 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12202 && (!bgp_outbound_policy_exists(p, filter)))
12203 json_object_string_add(
12204 json_addr, "outboundEbgpRequiresPolicy",
12205 "Outbound updates discarded due to missing policy");
12206
12207 /* unsuppress-map */
12208 if (filter->usmap.name)
12209 json_object_string_add(json_addr,
12210 "selectiveUnsuppressRouteMap",
12211 filter->usmap.name);
12212
12213 /* advertise-map */
12214 if (filter->advmap.aname) {
12215 json_advmap = json_object_new_object();
12216 json_object_string_add(json_advmap, "condition",
12217 filter->advmap.condition
12218 ? "EXIST"
12219 : "NON_EXIST");
12220 json_object_string_add(json_advmap, "conditionMap",
12221 filter->advmap.cname);
12222 json_object_string_add(json_advmap, "advertiseMap",
12223 filter->advmap.aname);
12224 json_object_string_add(
12225 json_advmap, "advertiseStatus",
12226 filter->advmap.update_type ==
12227 UPDATE_TYPE_ADVERTISE
12228 ? "Advertise"
12229 : "Withdraw");
12230 json_object_object_add(json_addr, "advertiseMap",
12231 json_advmap);
12232 }
12233
12234 /* Receive prefix count */
12235 json_object_int_add(json_addr, "acceptedPrefixCounter",
12236 p->pcount[afi][safi]);
12237 if (paf && PAF_SUBGRP(paf))
12238 json_object_int_add(json_addr, "sentPrefixCounter",
12239 (PAF_SUBGRP(paf))->scount);
12240
12241 /* Maximum prefix */
12242 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12243 json_object_int_add(json_addr, "prefixOutAllowedMax",
12244 p->pmax_out[afi][safi]);
12245
12246 /* Maximum prefix */
12247 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12248 json_object_int_add(json_addr, "prefixAllowedMax",
12249 p->pmax[afi][safi]);
12250 if (CHECK_FLAG(p->af_flags[afi][safi],
12251 PEER_FLAG_MAX_PREFIX_WARNING))
12252 json_object_boolean_true_add(
12253 json_addr, "prefixAllowedMaxWarning");
12254 json_object_int_add(json_addr,
12255 "prefixAllowedWarningThresh",
12256 p->pmax_threshold[afi][safi]);
12257 if (p->pmax_restart[afi][safi])
12258 json_object_int_add(
12259 json_addr,
12260 "prefixAllowedRestartIntervalMsecs",
12261 p->pmax_restart[afi][safi] * 60000);
12262 }
12263 json_object_object_add(json_neigh,
12264 get_afi_safi_str(afi, safi, true),
12265 json_addr);
12266
12267 } else {
12268 filter = &p->filter[afi][safi];
12269
12270 vty_out(vty, " For address family: %s\n",
12271 get_afi_safi_str(afi, safi, false));
12272
12273 if (peer_group_active(p))
12274 vty_out(vty, " %s peer-group member\n",
12275 p->group->name);
12276
12277 paf = peer_af_find(p, afi, safi);
12278 if (paf && PAF_SUBGRP(paf)) {
12279 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12280 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12281 vty_out(vty, " Packet Queue length %d\n",
12282 bpacket_queue_virtual_length(paf));
12283 } else {
12284 vty_out(vty, " Not part of any update group\n");
12285 }
12286 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12287 || CHECK_FLAG(p->af_cap[afi][safi],
12288 PEER_CAP_ORF_PREFIX_SM_RCV)
12289 || CHECK_FLAG(p->af_cap[afi][safi],
12290 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12291 || CHECK_FLAG(p->af_cap[afi][safi],
12292 PEER_CAP_ORF_PREFIX_RM_ADV)
12293 || CHECK_FLAG(p->af_cap[afi][safi],
12294 PEER_CAP_ORF_PREFIX_RM_RCV)
12295 || CHECK_FLAG(p->af_cap[afi][safi],
12296 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12297 vty_out(vty, " AF-dependant capabilities:\n");
12298
12299 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12300 || CHECK_FLAG(p->af_cap[afi][safi],
12301 PEER_CAP_ORF_PREFIX_SM_RCV)
12302 || CHECK_FLAG(p->af_cap[afi][safi],
12303 PEER_CAP_ORF_PREFIX_RM_ADV)
12304 || CHECK_FLAG(p->af_cap[afi][safi],
12305 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12306 vty_out(vty,
12307 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12308 ORF_TYPE_PREFIX);
12309 bgp_show_peer_afi_orf_cap(
12310 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12311 PEER_CAP_ORF_PREFIX_RM_ADV,
12312 PEER_CAP_ORF_PREFIX_SM_RCV,
12313 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12314 }
12315 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12316 || CHECK_FLAG(p->af_cap[afi][safi],
12317 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12318 || CHECK_FLAG(p->af_cap[afi][safi],
12319 PEER_CAP_ORF_PREFIX_RM_ADV)
12320 || CHECK_FLAG(p->af_cap[afi][safi],
12321 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12322 vty_out(vty,
12323 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12324 ORF_TYPE_PREFIX_OLD);
12325 bgp_show_peer_afi_orf_cap(
12326 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12327 PEER_CAP_ORF_PREFIX_RM_ADV,
12328 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12329 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12330 }
12331
12332 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12333 p->host, afi, safi);
12334 orf_pfx_count = prefix_bgp_show_prefix_list(
12335 NULL, afi, orf_pfx_name, use_json);
12336
12337 if (CHECK_FLAG(p->af_sflags[afi][safi],
12338 PEER_STATUS_ORF_PREFIX_SEND)
12339 || orf_pfx_count) {
12340 vty_out(vty, " Outbound Route Filter (ORF):");
12341 if (CHECK_FLAG(p->af_sflags[afi][safi],
12342 PEER_STATUS_ORF_PREFIX_SEND))
12343 vty_out(vty, " sent;");
12344 if (orf_pfx_count)
12345 vty_out(vty, " received (%d entries)",
12346 orf_pfx_count);
12347 vty_out(vty, "\n");
12348 }
12349 if (CHECK_FLAG(p->af_sflags[afi][safi],
12350 PEER_STATUS_ORF_WAIT_REFRESH))
12351 vty_out(vty,
12352 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12353
12354 if (CHECK_FLAG(p->af_flags[afi][safi],
12355 PEER_FLAG_REFLECTOR_CLIENT))
12356 vty_out(vty, " Route-Reflector Client\n");
12357 if (CHECK_FLAG(p->af_flags[afi][safi],
12358 PEER_FLAG_RSERVER_CLIENT))
12359 vty_out(vty, " Route-Server Client\n");
12360 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12361 vty_out(vty,
12362 " Inbound soft reconfiguration allowed\n");
12363
12364 if (CHECK_FLAG(p->af_flags[afi][safi],
12365 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12366 vty_out(vty,
12367 " Private AS numbers (all) replaced in updates to this neighbor\n");
12368 else if (CHECK_FLAG(p->af_flags[afi][safi],
12369 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12370 vty_out(vty,
12371 " Private AS numbers replaced in updates to this neighbor\n");
12372 else if (CHECK_FLAG(p->af_flags[afi][safi],
12373 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12374 vty_out(vty,
12375 " Private AS numbers (all) removed in updates to this neighbor\n");
12376 else if (CHECK_FLAG(p->af_flags[afi][safi],
12377 PEER_FLAG_REMOVE_PRIVATE_AS))
12378 vty_out(vty,
12379 " Private AS numbers removed in updates to this neighbor\n");
12380
12381 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12382 vty_out(vty, " %s\n",
12383 bgp_addpath_names(p->addpath_type[afi][safi])
12384 ->human_description);
12385
12386 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12387 vty_out(vty,
12388 " Override ASNs in outbound updates if aspath equals remote-as\n");
12389
12390 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12391 || CHECK_FLAG(p->af_flags[afi][safi],
12392 PEER_FLAG_FORCE_NEXTHOP_SELF))
12393 vty_out(vty, " NEXT_HOP is always this router\n");
12394 if (CHECK_FLAG(p->af_flags[afi][safi],
12395 PEER_FLAG_AS_PATH_UNCHANGED))
12396 vty_out(vty,
12397 " AS_PATH is propagated unchanged to this neighbor\n");
12398 if (CHECK_FLAG(p->af_flags[afi][safi],
12399 PEER_FLAG_NEXTHOP_UNCHANGED))
12400 vty_out(vty,
12401 " NEXT_HOP is propagated unchanged to this neighbor\n");
12402 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12403 vty_out(vty,
12404 " MED is propagated unchanged to this neighbor\n");
12405 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12406 || CHECK_FLAG(p->af_flags[afi][safi],
12407 PEER_FLAG_SEND_EXT_COMMUNITY)
12408 || CHECK_FLAG(p->af_flags[afi][safi],
12409 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12410 vty_out(vty,
12411 " Community attribute sent to this neighbor");
12412 if (CHECK_FLAG(p->af_flags[afi][safi],
12413 PEER_FLAG_SEND_COMMUNITY)
12414 && CHECK_FLAG(p->af_flags[afi][safi],
12415 PEER_FLAG_SEND_EXT_COMMUNITY)
12416 && CHECK_FLAG(p->af_flags[afi][safi],
12417 PEER_FLAG_SEND_LARGE_COMMUNITY))
12418 vty_out(vty, "(all)\n");
12419 else if (CHECK_FLAG(p->af_flags[afi][safi],
12420 PEER_FLAG_SEND_LARGE_COMMUNITY))
12421 vty_out(vty, "(large)\n");
12422 else if (CHECK_FLAG(p->af_flags[afi][safi],
12423 PEER_FLAG_SEND_EXT_COMMUNITY))
12424 vty_out(vty, "(extended)\n");
12425 else
12426 vty_out(vty, "(standard)\n");
12427 }
12428 if (CHECK_FLAG(p->af_flags[afi][safi],
12429 PEER_FLAG_DEFAULT_ORIGINATE)) {
12430 vty_out(vty, " Default information originate,");
12431
12432 if (p->default_rmap[afi][safi].name)
12433 vty_out(vty, " default route-map %s%s,",
12434 p->default_rmap[afi][safi].map ? "*"
12435 : "",
12436 p->default_rmap[afi][safi].name);
12437 if (paf && PAF_SUBGRP(paf)
12438 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12439 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12440 vty_out(vty, " default sent\n");
12441 else
12442 vty_out(vty, " default not sent\n");
12443 }
12444
12445 /* advertise-vni-all */
12446 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12447 if (is_evpn_enabled())
12448 vty_out(vty, " advertise-all-vni\n");
12449 }
12450
12451 if (filter->plist[FILTER_IN].name
12452 || filter->dlist[FILTER_IN].name
12453 || filter->aslist[FILTER_IN].name
12454 || filter->map[RMAP_IN].name)
12455 vty_out(vty, " Inbound path policy configured\n");
12456 if (filter->plist[FILTER_OUT].name
12457 || filter->dlist[FILTER_OUT].name
12458 || filter->aslist[FILTER_OUT].name
12459 || filter->map[RMAP_OUT].name || filter->usmap.name)
12460 vty_out(vty, " Outbound path policy configured\n");
12461
12462 /* prefix-list */
12463 if (filter->plist[FILTER_IN].name)
12464 vty_out(vty,
12465 " Incoming update prefix filter list is %s%s\n",
12466 filter->plist[FILTER_IN].plist ? "*" : "",
12467 filter->plist[FILTER_IN].name);
12468 if (filter->plist[FILTER_OUT].name)
12469 vty_out(vty,
12470 " Outgoing update prefix filter list is %s%s\n",
12471 filter->plist[FILTER_OUT].plist ? "*" : "",
12472 filter->plist[FILTER_OUT].name);
12473
12474 /* distribute-list */
12475 if (filter->dlist[FILTER_IN].name)
12476 vty_out(vty,
12477 " Incoming update network filter list is %s%s\n",
12478 filter->dlist[FILTER_IN].alist ? "*" : "",
12479 filter->dlist[FILTER_IN].name);
12480 if (filter->dlist[FILTER_OUT].name)
12481 vty_out(vty,
12482 " Outgoing update network filter list is %s%s\n",
12483 filter->dlist[FILTER_OUT].alist ? "*" : "",
12484 filter->dlist[FILTER_OUT].name);
12485
12486 /* filter-list. */
12487 if (filter->aslist[FILTER_IN].name)
12488 vty_out(vty,
12489 " Incoming update AS path filter list is %s%s\n",
12490 filter->aslist[FILTER_IN].aslist ? "*" : "",
12491 filter->aslist[FILTER_IN].name);
12492 if (filter->aslist[FILTER_OUT].name)
12493 vty_out(vty,
12494 " Outgoing update AS path filter list is %s%s\n",
12495 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12496 filter->aslist[FILTER_OUT].name);
12497
12498 /* route-map. */
12499 if (filter->map[RMAP_IN].name)
12500 vty_out(vty,
12501 " Route map for incoming advertisements is %s%s\n",
12502 filter->map[RMAP_IN].map ? "*" : "",
12503 filter->map[RMAP_IN].name);
12504 if (filter->map[RMAP_OUT].name)
12505 vty_out(vty,
12506 " Route map for outgoing advertisements is %s%s\n",
12507 filter->map[RMAP_OUT].map ? "*" : "",
12508 filter->map[RMAP_OUT].name);
12509
12510 /* ebgp-requires-policy (inbound) */
12511 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12512 && !bgp_inbound_policy_exists(p, filter))
12513 vty_out(vty,
12514 " Inbound updates discarded due to missing policy\n");
12515
12516 /* ebgp-requires-policy (outbound) */
12517 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12518 && !bgp_outbound_policy_exists(p, filter))
12519 vty_out(vty,
12520 " Outbound updates discarded due to missing policy\n");
12521
12522 /* unsuppress-map */
12523 if (filter->usmap.name)
12524 vty_out(vty,
12525 " Route map for selective unsuppress is %s%s\n",
12526 filter->usmap.map ? "*" : "",
12527 filter->usmap.name);
12528
12529 /* advertise-map */
12530 if (filter->advmap.aname && filter->advmap.cname)
12531 vty_out(vty,
12532 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12533 filter->advmap.condition ? "EXIST"
12534 : "NON_EXIST",
12535 filter->advmap.cmap ? "*" : "",
12536 filter->advmap.cname,
12537 filter->advmap.amap ? "*" : "",
12538 filter->advmap.aname,
12539 filter->advmap.update_type ==
12540 UPDATE_TYPE_ADVERTISE
12541 ? "Advertise"
12542 : "Withdraw");
12543
12544 /* Receive prefix count */
12545 vty_out(vty, " %u accepted prefixes\n",
12546 p->pcount[afi][safi]);
12547
12548 /* maximum-prefix-out */
12549 if (CHECK_FLAG(p->af_flags[afi][safi],
12550 PEER_FLAG_MAX_PREFIX_OUT))
12551 vty_out(vty,
12552 " Maximum allowed prefixes sent %u\n",
12553 p->pmax_out[afi][safi]);
12554
12555 /* Maximum prefix */
12556 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12557 vty_out(vty,
12558 " Maximum prefixes allowed %u%s\n",
12559 p->pmax[afi][safi],
12560 CHECK_FLAG(p->af_flags[afi][safi],
12561 PEER_FLAG_MAX_PREFIX_WARNING)
12562 ? " (warning-only)"
12563 : "");
12564 vty_out(vty, " Threshold for warning message %d%%",
12565 p->pmax_threshold[afi][safi]);
12566 if (p->pmax_restart[afi][safi])
12567 vty_out(vty, ", restart interval %d min",
12568 p->pmax_restart[afi][safi]);
12569 vty_out(vty, "\n");
12570 }
12571
12572 vty_out(vty, "\n");
12573 }
12574 }
12575
12576 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12577 json_object *json)
12578 {
12579 struct bgp *bgp;
12580 char buf1[PREFIX2STR_BUFFER];
12581 char timebuf[BGP_UPTIME_LEN];
12582 char dn_flag[2];
12583 afi_t afi;
12584 safi_t safi;
12585 uint16_t i;
12586 uint8_t *msg;
12587 json_object *json_neigh = NULL;
12588 time_t epoch_tbuf;
12589 uint32_t sync_tcp_mss;
12590
12591 bgp = p->bgp;
12592
12593 if (use_json)
12594 json_neigh = json_object_new_object();
12595
12596 memset(dn_flag, '\0', sizeof(dn_flag));
12597 if (!p->conf_if && peer_dynamic_neighbor(p))
12598 dn_flag[0] = '*';
12599
12600 if (!use_json) {
12601 if (p->conf_if) /* Configured interface name. */
12602 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12603 &p->su);
12604 else /* Configured IP address. */
12605 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12606 p->host);
12607 }
12608
12609 if (use_json) {
12610 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12611 json_object_string_add(json_neigh, "bgpNeighborAddr",
12612 "none");
12613 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12614 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12615 "%pSU", &p->su);
12616
12617 json_object_int_add(json_neigh, "remoteAs", p->as);
12618
12619 if (p->change_local_as)
12620 json_object_int_add(json_neigh, "localAs",
12621 p->change_local_as);
12622 else
12623 json_object_int_add(json_neigh, "localAs", p->local_as);
12624
12625 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12626 json_object_boolean_true_add(json_neigh,
12627 "localAsNoPrepend");
12628
12629 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12630 json_object_boolean_true_add(json_neigh,
12631 "localAsReplaceAs");
12632 } else {
12633 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12634 || (p->as_type == AS_INTERNAL))
12635 vty_out(vty, "remote AS %u, ", p->as);
12636 else
12637 vty_out(vty, "remote AS Unspecified, ");
12638 vty_out(vty, "local AS %u%s%s, ",
12639 p->change_local_as ? p->change_local_as : p->local_as,
12640 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12641 ? " no-prepend"
12642 : "",
12643 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12644 ? " replace-as"
12645 : "");
12646 }
12647 /* peer type internal or confed-internal */
12648 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12649 if (use_json) {
12650 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12651 json_object_boolean_true_add(
12652 json_neigh, "nbrConfedInternalLink");
12653 else
12654 json_object_boolean_true_add(json_neigh,
12655 "nbrInternalLink");
12656 } else {
12657 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12658 vty_out(vty, "confed-internal link\n");
12659 else
12660 vty_out(vty, "internal link\n");
12661 }
12662 /* peer type external or confed-external */
12663 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12664 if (use_json) {
12665 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12666 json_object_boolean_true_add(
12667 json_neigh, "nbrConfedExternalLink");
12668 else
12669 json_object_boolean_true_add(json_neigh,
12670 "nbrExternalLink");
12671 } else {
12672 if (bgp_confederation_peers_check(bgp, p->as))
12673 vty_out(vty, "confed-external link\n");
12674 else
12675 vty_out(vty, "external link\n");
12676 }
12677 } else {
12678 if (use_json)
12679 json_object_boolean_true_add(json_neigh,
12680 "nbrUnspecifiedLink");
12681 else
12682 vty_out(vty, "unspecified link\n");
12683 }
12684
12685 /* Roles */
12686 if (use_json) {
12687 json_object_string_add(json_neigh, "localRole",
12688 bgp_get_name_by_role(p->local_role));
12689 json_object_string_add(json_neigh, "remoteRole",
12690 bgp_get_name_by_role(p->remote_role));
12691 } else {
12692 vty_out(vty, " Local Role: %s\n",
12693 bgp_get_name_by_role(p->local_role));
12694 vty_out(vty, " Remote Role: %s\n",
12695 bgp_get_name_by_role(p->remote_role));
12696 }
12697
12698
12699 /* Description. */
12700 if (p->desc) {
12701 if (use_json)
12702 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12703 else
12704 vty_out(vty, " Description: %s\n", p->desc);
12705 }
12706
12707 if (p->hostname) {
12708 if (use_json) {
12709 if (p->hostname)
12710 json_object_string_add(json_neigh, "hostname",
12711 p->hostname);
12712
12713 if (p->domainname)
12714 json_object_string_add(json_neigh, "domainname",
12715 p->domainname);
12716 } else {
12717 if (p->domainname && (p->domainname[0] != '\0'))
12718 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12719 p->domainname);
12720 else
12721 vty_out(vty, "Hostname: %s\n", p->hostname);
12722 }
12723 }
12724
12725 /* Peer-group */
12726 if (p->group) {
12727 if (use_json) {
12728 json_object_string_add(json_neigh, "peerGroup",
12729 p->group->name);
12730
12731 if (dn_flag[0]) {
12732 struct prefix prefix, *range = NULL;
12733
12734 if (sockunion2hostprefix(&(p->su), &prefix))
12735 range = peer_group_lookup_dynamic_neighbor_range(
12736 p->group, &prefix);
12737
12738 if (range) {
12739 json_object_string_addf(
12740 json_neigh,
12741 "peerSubnetRangeGroup", "%pFX",
12742 range);
12743 }
12744 }
12745 } else {
12746 vty_out(vty,
12747 " Member of peer-group %s for session parameters\n",
12748 p->group->name);
12749
12750 if (dn_flag[0]) {
12751 struct prefix prefix, *range = NULL;
12752
12753 if (sockunion2hostprefix(&(p->su), &prefix))
12754 range = peer_group_lookup_dynamic_neighbor_range(
12755 p->group, &prefix);
12756
12757 if (range) {
12758 vty_out(vty,
12759 " Belongs to the subnet range group: %pFX\n",
12760 range);
12761 }
12762 }
12763 }
12764 }
12765
12766 if (use_json) {
12767 /* Administrative shutdown. */
12768 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12769 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12770 json_object_boolean_true_add(json_neigh,
12771 "adminShutDown");
12772
12773 /* BGP Version. */
12774 json_object_int_add(json_neigh, "bgpVersion", 4);
12775 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12776 &p->remote_id);
12777 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12778 &bgp->router_id);
12779
12780 /* Confederation */
12781 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12782 && bgp_confederation_peers_check(bgp, p->as))
12783 json_object_boolean_true_add(json_neigh,
12784 "nbrCommonAdmin");
12785
12786 /* Status. */
12787 json_object_string_add(
12788 json_neigh, "bgpState",
12789 lookup_msg(bgp_status_msg, p->status, NULL));
12790
12791 if (peer_established(p)) {
12792 time_t uptime;
12793
12794 uptime = monotime(NULL);
12795 uptime -= p->uptime;
12796 epoch_tbuf = time(NULL) - uptime;
12797
12798 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12799 uptime * 1000);
12800 json_object_string_add(json_neigh, "bgpTimerUpString",
12801 peer_uptime(p->uptime, timebuf,
12802 BGP_UPTIME_LEN, 0,
12803 NULL));
12804 json_object_int_add(json_neigh,
12805 "bgpTimerUpEstablishedEpoch",
12806 epoch_tbuf);
12807 }
12808
12809 else if (p->status == Active) {
12810 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12811 json_object_string_add(json_neigh, "bgpStateIs",
12812 "passive");
12813 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12814 json_object_string_add(json_neigh, "bgpStateIs",
12815 "passiveNSF");
12816 }
12817
12818 /* read timer */
12819 time_t uptime;
12820 struct tm tm;
12821
12822 uptime = monotime(NULL);
12823 uptime -= p->readtime;
12824 gmtime_r(&uptime, &tm);
12825
12826 json_object_int_add(json_neigh, "bgpTimerLastRead",
12827 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12828 + (tm.tm_hour * 3600000));
12829
12830 uptime = monotime(NULL);
12831 uptime -= p->last_write;
12832 gmtime_r(&uptime, &tm);
12833
12834 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12835 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12836 + (tm.tm_hour * 3600000));
12837
12838 uptime = monotime(NULL);
12839 uptime -= p->update_time;
12840 gmtime_r(&uptime, &tm);
12841
12842 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12843 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12844 + (tm.tm_hour * 3600000));
12845
12846 /* Configured timer values. */
12847 json_object_int_add(json_neigh,
12848 "bgpTimerConfiguredHoldTimeMsecs",
12849 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12850 ? p->holdtime * 1000
12851 : bgp->default_holdtime * 1000);
12852 json_object_int_add(json_neigh,
12853 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12854 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12855 ? p->keepalive * 1000
12856 : bgp->default_keepalive * 1000);
12857 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12858 p->v_holdtime * 1000);
12859 json_object_int_add(json_neigh,
12860 "bgpTimerKeepAliveIntervalMsecs",
12861 p->v_keepalive * 1000);
12862 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12863 json_object_int_add(json_neigh,
12864 "bgpTimerDelayOpenTimeMsecs",
12865 p->v_delayopen * 1000);
12866 }
12867
12868 /* Configured and Synced tcp-mss value for peer */
12869 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12870 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12871 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12872 p->tcp_mss);
12873 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12874 sync_tcp_mss);
12875 }
12876
12877 /* Extended Optional Parameters Length for BGP OPEN Message */
12878 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12879 json_object_boolean_true_add(
12880 json_neigh, "extendedOptionalParametersLength");
12881 else
12882 json_object_boolean_false_add(
12883 json_neigh, "extendedOptionalParametersLength");
12884
12885 /* Conditional advertisements */
12886 json_object_int_add(
12887 json_neigh,
12888 "bgpTimerConfiguredConditionalAdvertisementsSec",
12889 bgp->condition_check_period);
12890 if (thread_is_scheduled(bgp->t_condition_check))
12891 json_object_int_add(
12892 json_neigh,
12893 "bgpTimerUntilConditionalAdvertisementsSec",
12894 thread_timer_remain_second(
12895 bgp->t_condition_check));
12896 } else {
12897 /* Administrative shutdown. */
12898 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12899 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12900 vty_out(vty, " Administratively shut down\n");
12901
12902 /* BGP Version. */
12903 vty_out(vty, " BGP version 4");
12904 vty_out(vty, ", remote router ID %s",
12905 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12906 vty_out(vty, ", local router ID %s\n",
12907 inet_ntop(AF_INET, &bgp->router_id, buf1,
12908 sizeof(buf1)));
12909
12910 /* Confederation */
12911 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12912 && bgp_confederation_peers_check(bgp, p->as))
12913 vty_out(vty,
12914 " Neighbor under common administration\n");
12915
12916 /* Status. */
12917 vty_out(vty, " BGP state = %s",
12918 lookup_msg(bgp_status_msg, p->status, NULL));
12919
12920 if (peer_established(p))
12921 vty_out(vty, ", up for %8s",
12922 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12923 0, NULL));
12924
12925 else if (p->status == Active) {
12926 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12927 vty_out(vty, " (passive)");
12928 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12929 vty_out(vty, " (NSF passive)");
12930 }
12931 vty_out(vty, "\n");
12932
12933 /* read timer */
12934 vty_out(vty, " Last read %s",
12935 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12936 NULL));
12937 vty_out(vty, ", Last write %s\n",
12938 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12939 NULL));
12940
12941 /* Configured timer values. */
12942 vty_out(vty,
12943 " Hold time is %d seconds, keepalive interval is %d seconds\n",
12944 p->v_holdtime, p->v_keepalive);
12945 vty_out(vty, " Configured hold time is %d seconds",
12946 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12947 ? p->holdtime
12948 : bgp->default_holdtime);
12949 vty_out(vty, ", keepalive interval is %d seconds\n",
12950 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12951 ? p->keepalive
12952 : bgp->default_keepalive);
12953 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12954 vty_out(vty,
12955 " Configured DelayOpenTime is %d seconds\n",
12956 p->delayopen);
12957
12958 /* Configured and synced tcp-mss value for peer */
12959 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12960 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12961 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12962 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12963 }
12964
12965 /* Extended Optional Parameters Length for BGP OPEN Message */
12966 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12967 vty_out(vty,
12968 " Extended Optional Parameters Length is enabled\n");
12969
12970 /* Conditional advertisements */
12971 vty_out(vty,
12972 " Configured conditional advertisements interval is %d seconds\n",
12973 bgp->condition_check_period);
12974 if (thread_is_scheduled(bgp->t_condition_check))
12975 vty_out(vty,
12976 " Time until conditional advertisements begin is %lu seconds\n",
12977 thread_timer_remain_second(
12978 bgp->t_condition_check));
12979 }
12980 /* Capability. */
12981 if (peer_established(p) &&
12982 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12983 if (use_json) {
12984 json_object *json_cap = NULL;
12985
12986 json_cap = json_object_new_object();
12987
12988 /* AS4 */
12989 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12990 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12991 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12992 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12993 json_object_string_add(
12994 json_cap, "4byteAs",
12995 "advertisedAndReceived");
12996 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12997 json_object_string_add(json_cap,
12998 "4byteAs",
12999 "advertised");
13000 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13001 json_object_string_add(json_cap,
13002 "4byteAs",
13003 "received");
13004 }
13005
13006 /* Extended Message Support */
13007 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13008 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13009 json_object_string_add(json_cap,
13010 "extendedMessage",
13011 "advertisedAndReceived");
13012 else if (CHECK_FLAG(p->cap,
13013 PEER_CAP_EXTENDED_MESSAGE_ADV))
13014 json_object_string_add(json_cap,
13015 "extendedMessage",
13016 "advertised");
13017 else if (CHECK_FLAG(p->cap,
13018 PEER_CAP_EXTENDED_MESSAGE_RCV))
13019 json_object_string_add(json_cap,
13020 "extendedMessage",
13021 "received");
13022
13023 /* AddPath */
13024 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13025 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13026 json_object *json_add = NULL;
13027 const char *print_store;
13028
13029 json_add = json_object_new_object();
13030
13031 FOREACH_AFI_SAFI (afi, safi) {
13032 json_object *json_sub = NULL;
13033 json_sub = json_object_new_object();
13034 print_store = get_afi_safi_str(
13035 afi, safi, true);
13036
13037 if (CHECK_FLAG(
13038 p->af_cap[afi][safi],
13039 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13040 CHECK_FLAG(
13041 p->af_cap[afi][safi],
13042 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13043 if (CHECK_FLAG(
13044 p->af_cap[afi]
13045 [safi],
13046 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13047 CHECK_FLAG(
13048 p->af_cap[afi]
13049 [safi],
13050 PEER_CAP_ADDPATH_AF_TX_RCV))
13051 json_object_boolean_true_add(
13052 json_sub,
13053 "txAdvertisedAndReceived");
13054 else if (
13055 CHECK_FLAG(
13056 p->af_cap[afi]
13057 [safi],
13058 PEER_CAP_ADDPATH_AF_TX_ADV))
13059 json_object_boolean_true_add(
13060 json_sub,
13061 "txAdvertised");
13062 else if (
13063 CHECK_FLAG(
13064 p->af_cap[afi]
13065 [safi],
13066 PEER_CAP_ADDPATH_AF_TX_RCV))
13067 json_object_boolean_true_add(
13068 json_sub,
13069 "txReceived");
13070 }
13071
13072 if (CHECK_FLAG(
13073 p->af_cap[afi][safi],
13074 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13075 CHECK_FLAG(
13076 p->af_cap[afi][safi],
13077 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13078 if (CHECK_FLAG(
13079 p->af_cap[afi]
13080 [safi],
13081 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13082 CHECK_FLAG(
13083 p->af_cap[afi]
13084 [safi],
13085 PEER_CAP_ADDPATH_AF_RX_RCV))
13086 json_object_boolean_true_add(
13087 json_sub,
13088 "rxAdvertisedAndReceived");
13089 else if (
13090 CHECK_FLAG(
13091 p->af_cap[afi]
13092 [safi],
13093 PEER_CAP_ADDPATH_AF_RX_ADV))
13094 json_object_boolean_true_add(
13095 json_sub,
13096 "rxAdvertised");
13097 else if (
13098 CHECK_FLAG(
13099 p->af_cap[afi]
13100 [safi],
13101 PEER_CAP_ADDPATH_AF_RX_RCV))
13102 json_object_boolean_true_add(
13103 json_sub,
13104 "rxReceived");
13105 }
13106
13107 if (CHECK_FLAG(
13108 p->af_cap[afi][safi],
13109 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13110 CHECK_FLAG(
13111 p->af_cap[afi][safi],
13112 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13113 CHECK_FLAG(
13114 p->af_cap[afi][safi],
13115 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13116 CHECK_FLAG(
13117 p->af_cap[afi][safi],
13118 PEER_CAP_ADDPATH_AF_RX_RCV))
13119 json_object_object_add(
13120 json_add, print_store,
13121 json_sub);
13122 else
13123 json_object_free(json_sub);
13124 }
13125
13126 json_object_object_add(json_cap, "addPath",
13127 json_add);
13128 }
13129
13130 /* Dynamic */
13131 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13132 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13133 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13134 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13135 json_object_string_add(
13136 json_cap, "dynamic",
13137 "advertisedAndReceived");
13138 else if (CHECK_FLAG(p->cap,
13139 PEER_CAP_DYNAMIC_ADV))
13140 json_object_string_add(json_cap,
13141 "dynamic",
13142 "advertised");
13143 else if (CHECK_FLAG(p->cap,
13144 PEER_CAP_DYNAMIC_RCV))
13145 json_object_string_add(json_cap,
13146 "dynamic",
13147 "received");
13148 }
13149
13150 /* Role */
13151 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13152 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13153 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13154 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13155 json_object_string_add(
13156 json_cap, "role",
13157 "advertisedAndReceived");
13158 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13159 json_object_string_add(json_cap, "role",
13160 "advertised");
13161 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13162 json_object_string_add(json_cap, "role",
13163 "received");
13164 }
13165
13166 /* Extended nexthop */
13167 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13168 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13169 json_object *json_nxt = NULL;
13170 const char *print_store;
13171
13172
13173 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13174 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13175 json_object_string_add(
13176 json_cap, "extendedNexthop",
13177 "advertisedAndReceived");
13178 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13179 json_object_string_add(
13180 json_cap, "extendedNexthop",
13181 "advertised");
13182 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13183 json_object_string_add(
13184 json_cap, "extendedNexthop",
13185 "received");
13186
13187 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13188 json_nxt = json_object_new_object();
13189
13190 for (safi = SAFI_UNICAST;
13191 safi < SAFI_MAX; safi++) {
13192 if (CHECK_FLAG(
13193 p->af_cap[AFI_IP]
13194 [safi],
13195 PEER_CAP_ENHE_AF_RCV)) {
13196 print_store =
13197 get_afi_safi_str(
13198 AFI_IP,
13199 safi,
13200 true);
13201 json_object_string_add(
13202 json_nxt,
13203 print_store,
13204 "recieved"); /* misspelled for compatibility */
13205 }
13206 }
13207 json_object_object_add(
13208 json_cap,
13209 "extendedNexthopFamililesByPeer",
13210 json_nxt);
13211 }
13212 }
13213
13214 /* Long-lived Graceful Restart */
13215 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13216 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13217 json_object *json_llgr = NULL;
13218 const char *afi_safi_str;
13219
13220 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13221 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13222 json_object_string_add(
13223 json_cap,
13224 "longLivedGracefulRestart",
13225 "advertisedAndReceived");
13226 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13227 json_object_string_add(
13228 json_cap,
13229 "longLivedGracefulRestart",
13230 "advertised");
13231 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13232 json_object_string_add(
13233 json_cap,
13234 "longLivedGracefulRestart",
13235 "received");
13236
13237 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13238 json_llgr = json_object_new_object();
13239
13240 FOREACH_AFI_SAFI (afi, safi) {
13241 if (CHECK_FLAG(
13242 p->af_cap[afi]
13243 [safi],
13244 PEER_CAP_ENHE_AF_RCV)) {
13245 afi_safi_str =
13246 get_afi_safi_str(
13247 afi,
13248 safi,
13249 true);
13250 json_object_string_add(
13251 json_llgr,
13252 afi_safi_str,
13253 "received");
13254 }
13255 }
13256 json_object_object_add(
13257 json_cap,
13258 "longLivedGracefulRestartByPeer",
13259 json_llgr);
13260 }
13261 }
13262
13263 /* Route Refresh */
13264 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13265 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13266 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13267 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13268 (CHECK_FLAG(p->cap,
13269 PEER_CAP_REFRESH_NEW_RCV) ||
13270 CHECK_FLAG(p->cap,
13271 PEER_CAP_REFRESH_OLD_RCV))) {
13272 if (CHECK_FLAG(
13273 p->cap,
13274 PEER_CAP_REFRESH_OLD_RCV) &&
13275 CHECK_FLAG(
13276 p->cap,
13277 PEER_CAP_REFRESH_NEW_RCV))
13278 json_object_string_add(
13279 json_cap,
13280 "routeRefresh",
13281 "advertisedAndReceivedOldNew");
13282 else {
13283 if (CHECK_FLAG(
13284 p->cap,
13285 PEER_CAP_REFRESH_OLD_RCV))
13286 json_object_string_add(
13287 json_cap,
13288 "routeRefresh",
13289 "advertisedAndReceivedOld");
13290 else
13291 json_object_string_add(
13292 json_cap,
13293 "routeRefresh",
13294 "advertisedAndReceivedNew");
13295 }
13296 } else if (CHECK_FLAG(p->cap,
13297 PEER_CAP_REFRESH_ADV))
13298 json_object_string_add(json_cap,
13299 "routeRefresh",
13300 "advertised");
13301 else if (CHECK_FLAG(p->cap,
13302 PEER_CAP_REFRESH_NEW_RCV) ||
13303 CHECK_FLAG(p->cap,
13304 PEER_CAP_REFRESH_OLD_RCV))
13305 json_object_string_add(json_cap,
13306 "routeRefresh",
13307 "received");
13308 }
13309
13310 /* Enhanced Route Refresh */
13311 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13312 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13313 if (CHECK_FLAG(p->cap,
13314 PEER_CAP_ENHANCED_RR_ADV) &&
13315 CHECK_FLAG(p->cap,
13316 PEER_CAP_ENHANCED_RR_RCV))
13317 json_object_string_add(
13318 json_cap,
13319 "enhancedRouteRefresh",
13320 "advertisedAndReceived");
13321 else if (CHECK_FLAG(p->cap,
13322 PEER_CAP_ENHANCED_RR_ADV))
13323 json_object_string_add(
13324 json_cap,
13325 "enhancedRouteRefresh",
13326 "advertised");
13327 else if (CHECK_FLAG(p->cap,
13328 PEER_CAP_ENHANCED_RR_RCV))
13329 json_object_string_add(
13330 json_cap,
13331 "enhancedRouteRefresh",
13332 "received");
13333 }
13334
13335 /* Multiprotocol Extensions */
13336 json_object *json_multi = NULL;
13337
13338 json_multi = json_object_new_object();
13339
13340 FOREACH_AFI_SAFI (afi, safi) {
13341 if (p->afc_adv[afi][safi] ||
13342 p->afc_recv[afi][safi]) {
13343 json_object *json_exten = NULL;
13344 json_exten = json_object_new_object();
13345
13346 if (p->afc_adv[afi][safi] &&
13347 p->afc_recv[afi][safi])
13348 json_object_boolean_true_add(
13349 json_exten,
13350 "advertisedAndReceived");
13351 else if (p->afc_adv[afi][safi])
13352 json_object_boolean_true_add(
13353 json_exten,
13354 "advertised");
13355 else if (p->afc_recv[afi][safi])
13356 json_object_boolean_true_add(
13357 json_exten, "received");
13358
13359 json_object_object_add(
13360 json_multi,
13361 get_afi_safi_str(afi, safi,
13362 true),
13363 json_exten);
13364 }
13365 }
13366 json_object_object_add(json_cap,
13367 "multiprotocolExtensions",
13368 json_multi);
13369
13370 /* Hostname capabilities */
13371 json_object *json_hname = NULL;
13372
13373 json_hname = json_object_new_object();
13374
13375 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13376 json_object_string_add(
13377 json_hname, "advHostName",
13378 bgp->peer_self->hostname
13379 ? bgp->peer_self->hostname
13380 : "n/a");
13381 json_object_string_add(
13382 json_hname, "advDomainName",
13383 bgp->peer_self->domainname
13384 ? bgp->peer_self->domainname
13385 : "n/a");
13386 }
13387
13388
13389 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13390 json_object_string_add(
13391 json_hname, "rcvHostName",
13392 p->hostname ? p->hostname : "n/a");
13393 json_object_string_add(
13394 json_hname, "rcvDomainName",
13395 p->domainname ? p->domainname : "n/a");
13396 }
13397
13398 json_object_object_add(json_cap, "hostName",
13399 json_hname);
13400
13401 /* Graceful Restart */
13402 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13403 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13404 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13405 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13406 json_object_string_add(
13407 json_cap, "gracefulRestart",
13408 "advertisedAndReceived");
13409 else if (CHECK_FLAG(p->cap,
13410 PEER_CAP_RESTART_ADV))
13411 json_object_string_add(
13412 json_cap,
13413 "gracefulRestartCapability",
13414 "advertised");
13415 else if (CHECK_FLAG(p->cap,
13416 PEER_CAP_RESTART_RCV))
13417 json_object_string_add(
13418 json_cap,
13419 "gracefulRestartCapability",
13420 "received");
13421
13422 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13423 int restart_af_count = 0;
13424 json_object *json_restart = NULL;
13425 json_restart = json_object_new_object();
13426
13427 json_object_int_add(
13428 json_cap,
13429 "gracefulRestartRemoteTimerMsecs",
13430 p->v_gr_restart * 1000);
13431
13432 FOREACH_AFI_SAFI (afi, safi) {
13433 if (CHECK_FLAG(
13434 p->af_cap[afi]
13435 [safi],
13436 PEER_CAP_RESTART_AF_RCV)) {
13437 json_object *json_sub =
13438 NULL;
13439 json_sub =
13440 json_object_new_object();
13441
13442 if (CHECK_FLAG(
13443 p->af_cap
13444 [afi]
13445 [safi],
13446 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13447 json_object_boolean_true_add(
13448 json_sub,
13449 "preserved");
13450 restart_af_count++;
13451 json_object_object_add(
13452 json_restart,
13453 get_afi_safi_str(
13454 afi,
13455 safi,
13456 true),
13457 json_sub);
13458 }
13459 }
13460 if (!restart_af_count) {
13461 json_object_string_add(
13462 json_cap,
13463 "addressFamiliesByPeer",
13464 "none");
13465 json_object_free(json_restart);
13466 } else
13467 json_object_object_add(
13468 json_cap,
13469 "addressFamiliesByPeer",
13470 json_restart);
13471 }
13472 }
13473 json_object_object_add(
13474 json_neigh, "neighborCapabilities", json_cap);
13475 } else {
13476 vty_out(vty, " Neighbor capabilities:\n");
13477
13478 /* AS4 */
13479 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13480 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13481 vty_out(vty, " 4 Byte AS:");
13482 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13483 vty_out(vty, " advertised");
13484 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13485 vty_out(vty, " %sreceived",
13486 CHECK_FLAG(p->cap,
13487 PEER_CAP_AS4_ADV)
13488 ? "and "
13489 : "");
13490 vty_out(vty, "\n");
13491 }
13492
13493 /* Extended Message Support */
13494 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13495 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13496 vty_out(vty, " Extended Message:");
13497 if (CHECK_FLAG(p->cap,
13498 PEER_CAP_EXTENDED_MESSAGE_ADV))
13499 vty_out(vty, " advertised");
13500 if (CHECK_FLAG(p->cap,
13501 PEER_CAP_EXTENDED_MESSAGE_RCV))
13502 vty_out(vty, " %sreceived",
13503 CHECK_FLAG(
13504 p->cap,
13505 PEER_CAP_EXTENDED_MESSAGE_ADV)
13506 ? "and "
13507 : "");
13508 vty_out(vty, "\n");
13509 }
13510
13511 /* AddPath */
13512 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13513 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13514 vty_out(vty, " AddPath:\n");
13515
13516 FOREACH_AFI_SAFI (afi, safi) {
13517 if (CHECK_FLAG(
13518 p->af_cap[afi][safi],
13519 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13520 CHECK_FLAG(
13521 p->af_cap[afi][safi],
13522 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13523 vty_out(vty, " %s: TX ",
13524 get_afi_safi_str(
13525 afi, safi,
13526 false));
13527
13528 if (CHECK_FLAG(
13529 p->af_cap[afi]
13530 [safi],
13531 PEER_CAP_ADDPATH_AF_TX_ADV))
13532 vty_out(vty,
13533 "advertised");
13534
13535 if (CHECK_FLAG(
13536 p->af_cap[afi]
13537 [safi],
13538 PEER_CAP_ADDPATH_AF_TX_RCV))
13539 vty_out(vty,
13540 "%sreceived",
13541 CHECK_FLAG(
13542 p->af_cap
13543 [afi]
13544 [safi],
13545 PEER_CAP_ADDPATH_AF_TX_ADV)
13546 ? " and "
13547 : "");
13548
13549 vty_out(vty, "\n");
13550 }
13551
13552 if (CHECK_FLAG(
13553 p->af_cap[afi][safi],
13554 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13555 CHECK_FLAG(
13556 p->af_cap[afi][safi],
13557 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13558 vty_out(vty, " %s: RX ",
13559 get_afi_safi_str(
13560 afi, safi,
13561 false));
13562
13563 if (CHECK_FLAG(
13564 p->af_cap[afi]
13565 [safi],
13566 PEER_CAP_ADDPATH_AF_RX_ADV))
13567 vty_out(vty,
13568 "advertised");
13569
13570 if (CHECK_FLAG(
13571 p->af_cap[afi]
13572 [safi],
13573 PEER_CAP_ADDPATH_AF_RX_RCV))
13574 vty_out(vty,
13575 "%sreceived",
13576 CHECK_FLAG(
13577 p->af_cap
13578 [afi]
13579 [safi],
13580 PEER_CAP_ADDPATH_AF_RX_ADV)
13581 ? " and "
13582 : "");
13583
13584 vty_out(vty, "\n");
13585 }
13586 }
13587 }
13588
13589 /* Dynamic */
13590 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13591 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13592 vty_out(vty, " Dynamic:");
13593 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13594 vty_out(vty, " advertised");
13595 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13596 vty_out(vty, " %sreceived",
13597 CHECK_FLAG(p->cap,
13598 PEER_CAP_DYNAMIC_ADV)
13599 ? "and "
13600 : "");
13601 vty_out(vty, "\n");
13602 }
13603
13604 /* Role */
13605 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13606 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13607 vty_out(vty, " Role:");
13608 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13609 vty_out(vty, " advertised");
13610 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13611 vty_out(vty, " %sreceived",
13612 CHECK_FLAG(p->cap,
13613 PEER_CAP_ROLE_ADV)
13614 ? "and "
13615 : "");
13616 vty_out(vty, "\n");
13617 }
13618
13619 /* Extended nexthop */
13620 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13621 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13622 vty_out(vty, " Extended nexthop:");
13623 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13624 vty_out(vty, " advertised");
13625 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13626 vty_out(vty, " %sreceived",
13627 CHECK_FLAG(p->cap,
13628 PEER_CAP_ENHE_ADV)
13629 ? "and "
13630 : "");
13631 vty_out(vty, "\n");
13632
13633 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13634 vty_out(vty,
13635 " Address families by peer:\n ");
13636 for (safi = SAFI_UNICAST;
13637 safi < SAFI_MAX; safi++)
13638 if (CHECK_FLAG(
13639 p->af_cap[AFI_IP]
13640 [safi],
13641 PEER_CAP_ENHE_AF_RCV))
13642 vty_out(vty,
13643 " %s\n",
13644 get_afi_safi_str(
13645 AFI_IP,
13646 safi,
13647 false));
13648 }
13649 }
13650
13651 /* Long-lived Graceful Restart */
13652 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13653 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13654 vty_out(vty,
13655 " Long-lived Graceful Restart:");
13656 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13657 vty_out(vty, " advertised");
13658 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13659 vty_out(vty, " %sreceived",
13660 CHECK_FLAG(p->cap,
13661 PEER_CAP_LLGR_ADV)
13662 ? "and "
13663 : "");
13664 vty_out(vty, "\n");
13665
13666 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13667 vty_out(vty,
13668 " Address families by peer:\n");
13669 FOREACH_AFI_SAFI (afi, safi)
13670 if (CHECK_FLAG(
13671 p->af_cap[afi]
13672 [safi],
13673 PEER_CAP_LLGR_AF_RCV))
13674 vty_out(vty,
13675 " %s\n",
13676 get_afi_safi_str(
13677 afi,
13678 safi,
13679 false));
13680 }
13681 }
13682
13683 /* Route Refresh */
13684 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13685 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13686 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13687 vty_out(vty, " Route refresh:");
13688 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13689 vty_out(vty, " advertised");
13690 if (CHECK_FLAG(p->cap,
13691 PEER_CAP_REFRESH_NEW_RCV) ||
13692 CHECK_FLAG(p->cap,
13693 PEER_CAP_REFRESH_OLD_RCV))
13694 vty_out(vty, " %sreceived(%s)",
13695 CHECK_FLAG(p->cap,
13696 PEER_CAP_REFRESH_ADV)
13697 ? "and "
13698 : "",
13699 (CHECK_FLAG(
13700 p->cap,
13701 PEER_CAP_REFRESH_OLD_RCV) &&
13702 CHECK_FLAG(
13703 p->cap,
13704 PEER_CAP_REFRESH_NEW_RCV))
13705 ? "old & new"
13706 : CHECK_FLAG(
13707 p->cap,
13708 PEER_CAP_REFRESH_OLD_RCV)
13709 ? "old"
13710 : "new");
13711
13712 vty_out(vty, "\n");
13713 }
13714
13715 /* Enhanced Route Refresh */
13716 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13717 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13718 vty_out(vty, " Enhanced Route Refresh:");
13719 if (CHECK_FLAG(p->cap,
13720 PEER_CAP_ENHANCED_RR_ADV))
13721 vty_out(vty, " advertised");
13722 if (CHECK_FLAG(p->cap,
13723 PEER_CAP_ENHANCED_RR_RCV))
13724 vty_out(vty, " %sreceived",
13725 CHECK_FLAG(p->cap,
13726 PEER_CAP_REFRESH_ADV)
13727 ? "and "
13728 : "");
13729 vty_out(vty, "\n");
13730 }
13731
13732 /* Multiprotocol Extensions */
13733 FOREACH_AFI_SAFI (afi, safi)
13734 if (p->afc_adv[afi][safi] ||
13735 p->afc_recv[afi][safi]) {
13736 vty_out(vty, " Address Family %s:",
13737 get_afi_safi_str(afi, safi,
13738 false));
13739 if (p->afc_adv[afi][safi])
13740 vty_out(vty, " advertised");
13741 if (p->afc_recv[afi][safi])
13742 vty_out(vty, " %sreceived",
13743 p->afc_adv[afi][safi]
13744 ? "and "
13745 : "");
13746 vty_out(vty, "\n");
13747 }
13748
13749 /* Hostname capability */
13750 vty_out(vty, " Hostname Capability:");
13751
13752 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13753 vty_out(vty,
13754 " advertised (name: %s,domain name: %s)",
13755 bgp->peer_self->hostname
13756 ? bgp->peer_self->hostname
13757 : "n/a",
13758 bgp->peer_self->domainname
13759 ? bgp->peer_self->domainname
13760 : "n/a");
13761 } else {
13762 vty_out(vty, " not advertised");
13763 }
13764
13765 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13766 vty_out(vty,
13767 " received (name: %s,domain name: %s)",
13768 p->hostname ? p->hostname : "n/a",
13769 p->domainname ? p->domainname : "n/a");
13770 } else {
13771 vty_out(vty, " not received");
13772 }
13773
13774 vty_out(vty, "\n");
13775
13776 /* Graceful Restart */
13777 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13778 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13779 vty_out(vty,
13780 " Graceful Restart Capability:");
13781 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13782 vty_out(vty, " advertised");
13783 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13784 vty_out(vty, " %sreceived",
13785 CHECK_FLAG(p->cap,
13786 PEER_CAP_RESTART_ADV)
13787 ? "and "
13788 : "");
13789 vty_out(vty, "\n");
13790
13791 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13792 int restart_af_count = 0;
13793
13794 vty_out(vty,
13795 " Remote Restart timer is %d seconds\n",
13796 p->v_gr_restart);
13797 vty_out(vty,
13798 " Address families by peer:\n ");
13799
13800 FOREACH_AFI_SAFI (afi, safi)
13801 if (CHECK_FLAG(
13802 p->af_cap[afi]
13803 [safi],
13804 PEER_CAP_RESTART_AF_RCV)) {
13805 vty_out(vty, "%s%s(%s)",
13806 restart_af_count
13807 ? ", "
13808 : "",
13809 get_afi_safi_str(
13810 afi,
13811 safi,
13812 false),
13813 CHECK_FLAG(
13814 p->af_cap
13815 [afi]
13816 [safi],
13817 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13818 ? "preserved"
13819 : "not preserved");
13820 restart_af_count++;
13821 }
13822 if (!restart_af_count)
13823 vty_out(vty, "none");
13824 vty_out(vty, "\n");
13825 }
13826 } /* Graceful Restart */
13827 }
13828 }
13829
13830 /* graceful restart information */
13831 json_object *json_grace = NULL;
13832 json_object *json_grace_send = NULL;
13833 json_object *json_grace_recv = NULL;
13834 int eor_send_af_count = 0;
13835 int eor_receive_af_count = 0;
13836
13837 if (use_json) {
13838 json_grace = json_object_new_object();
13839 json_grace_send = json_object_new_object();
13840 json_grace_recv = json_object_new_object();
13841
13842 if ((peer_established(p)) &&
13843 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13844 FOREACH_AFI_SAFI (afi, safi) {
13845 if (CHECK_FLAG(p->af_sflags[afi][safi],
13846 PEER_STATUS_EOR_SEND)) {
13847 json_object_boolean_true_add(
13848 json_grace_send,
13849 get_afi_safi_str(afi, safi,
13850 true));
13851 eor_send_af_count++;
13852 }
13853 }
13854 FOREACH_AFI_SAFI (afi, safi) {
13855 if (CHECK_FLAG(p->af_sflags[afi][safi],
13856 PEER_STATUS_EOR_RECEIVED)) {
13857 json_object_boolean_true_add(
13858 json_grace_recv,
13859 get_afi_safi_str(afi, safi,
13860 true));
13861 eor_receive_af_count++;
13862 }
13863 }
13864 }
13865 json_object_object_add(json_grace, "endOfRibSend",
13866 json_grace_send);
13867 json_object_object_add(json_grace, "endOfRibRecv",
13868 json_grace_recv);
13869
13870
13871 if (p->t_gr_restart)
13872 json_object_int_add(
13873 json_grace, "gracefulRestartTimerMsecs",
13874 thread_timer_remain_second(p->t_gr_restart) *
13875 1000);
13876
13877 if (p->t_gr_stale)
13878 json_object_int_add(
13879 json_grace, "gracefulStalepathTimerMsecs",
13880 thread_timer_remain_second(p->t_gr_stale) *
13881 1000);
13882 /* more gr info in new format */
13883 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13884 json_object_object_add(json_neigh, "gracefulRestartInfo",
13885 json_grace);
13886 } else {
13887 vty_out(vty, " Graceful restart information:\n");
13888 if ((peer_established(p)) &&
13889 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13890
13891 vty_out(vty, " End-of-RIB send: ");
13892 FOREACH_AFI_SAFI (afi, safi) {
13893 if (CHECK_FLAG(p->af_sflags[afi][safi],
13894 PEER_STATUS_EOR_SEND)) {
13895 vty_out(vty, "%s%s",
13896 eor_send_af_count ? ", " : "",
13897 get_afi_safi_str(afi, safi,
13898 false));
13899 eor_send_af_count++;
13900 }
13901 }
13902 vty_out(vty, "\n");
13903 vty_out(vty, " End-of-RIB received: ");
13904 FOREACH_AFI_SAFI (afi, safi) {
13905 if (CHECK_FLAG(p->af_sflags[afi][safi],
13906 PEER_STATUS_EOR_RECEIVED)) {
13907 vty_out(vty, "%s%s",
13908 eor_receive_af_count ? ", "
13909 : "",
13910 get_afi_safi_str(afi, safi,
13911 false));
13912 eor_receive_af_count++;
13913 }
13914 }
13915 vty_out(vty, "\n");
13916 }
13917
13918 if (p->t_gr_restart)
13919 vty_out(vty,
13920 " The remaining time of restart timer is %ld\n",
13921 thread_timer_remain_second(p->t_gr_restart));
13922
13923 if (p->t_gr_stale)
13924 vty_out(vty,
13925 " The remaining time of stalepath timer is %ld\n",
13926 thread_timer_remain_second(p->t_gr_stale));
13927
13928 /* more gr info in new format */
13929 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13930 }
13931
13932 if (use_json) {
13933 json_object *json_stat = NULL;
13934 json_stat = json_object_new_object();
13935 /* Packet counts. */
13936
13937 atomic_size_t outq_count, inq_count;
13938 outq_count = atomic_load_explicit(&p->obuf->count,
13939 memory_order_relaxed);
13940 inq_count = atomic_load_explicit(&p->ibuf->count,
13941 memory_order_relaxed);
13942
13943 json_object_int_add(json_stat, "depthInq",
13944 (unsigned long)inq_count);
13945 json_object_int_add(json_stat, "depthOutq",
13946 (unsigned long)outq_count);
13947 json_object_int_add(json_stat, "opensSent",
13948 atomic_load_explicit(&p->open_out,
13949 memory_order_relaxed));
13950 json_object_int_add(json_stat, "opensRecv",
13951 atomic_load_explicit(&p->open_in,
13952 memory_order_relaxed));
13953 json_object_int_add(json_stat, "notificationsSent",
13954 atomic_load_explicit(&p->notify_out,
13955 memory_order_relaxed));
13956 json_object_int_add(json_stat, "notificationsRecv",
13957 atomic_load_explicit(&p->notify_in,
13958 memory_order_relaxed));
13959 json_object_int_add(json_stat, "updatesSent",
13960 atomic_load_explicit(&p->update_out,
13961 memory_order_relaxed));
13962 json_object_int_add(json_stat, "updatesRecv",
13963 atomic_load_explicit(&p->update_in,
13964 memory_order_relaxed));
13965 json_object_int_add(json_stat, "keepalivesSent",
13966 atomic_load_explicit(&p->keepalive_out,
13967 memory_order_relaxed));
13968 json_object_int_add(json_stat, "keepalivesRecv",
13969 atomic_load_explicit(&p->keepalive_in,
13970 memory_order_relaxed));
13971 json_object_int_add(json_stat, "routeRefreshSent",
13972 atomic_load_explicit(&p->refresh_out,
13973 memory_order_relaxed));
13974 json_object_int_add(json_stat, "routeRefreshRecv",
13975 atomic_load_explicit(&p->refresh_in,
13976 memory_order_relaxed));
13977 json_object_int_add(json_stat, "capabilitySent",
13978 atomic_load_explicit(&p->dynamic_cap_out,
13979 memory_order_relaxed));
13980 json_object_int_add(json_stat, "capabilityRecv",
13981 atomic_load_explicit(&p->dynamic_cap_in,
13982 memory_order_relaxed));
13983 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13984 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13985 json_object_object_add(json_neigh, "messageStats", json_stat);
13986 } else {
13987 atomic_size_t outq_count, inq_count, open_out, open_in,
13988 notify_out, notify_in, update_out, update_in,
13989 keepalive_out, keepalive_in, refresh_out, refresh_in,
13990 dynamic_cap_out, dynamic_cap_in;
13991 outq_count = atomic_load_explicit(&p->obuf->count,
13992 memory_order_relaxed);
13993 inq_count = atomic_load_explicit(&p->ibuf->count,
13994 memory_order_relaxed);
13995 open_out = atomic_load_explicit(&p->open_out,
13996 memory_order_relaxed);
13997 open_in =
13998 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13999 notify_out = atomic_load_explicit(&p->notify_out,
14000 memory_order_relaxed);
14001 notify_in = atomic_load_explicit(&p->notify_in,
14002 memory_order_relaxed);
14003 update_out = atomic_load_explicit(&p->update_out,
14004 memory_order_relaxed);
14005 update_in = atomic_load_explicit(&p->update_in,
14006 memory_order_relaxed);
14007 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14008 memory_order_relaxed);
14009 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14010 memory_order_relaxed);
14011 refresh_out = atomic_load_explicit(&p->refresh_out,
14012 memory_order_relaxed);
14013 refresh_in = atomic_load_explicit(&p->refresh_in,
14014 memory_order_relaxed);
14015 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14016 memory_order_relaxed);
14017 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14018 memory_order_relaxed);
14019
14020 /* Packet counts. */
14021 vty_out(vty, " Message statistics:\n");
14022 vty_out(vty, " Inq depth is %zu\n", inq_count);
14023 vty_out(vty, " Outq depth is %zu\n", outq_count);
14024 vty_out(vty, " Sent Rcvd\n");
14025 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14026 open_in);
14027 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14028 notify_in);
14029 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14030 update_in);
14031 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14032 keepalive_in);
14033 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14034 refresh_in);
14035 vty_out(vty, " Capability: %10zu %10zu\n",
14036 dynamic_cap_out, dynamic_cap_in);
14037 vty_out(vty, " Total: %10u %10u\n",
14038 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14039 }
14040
14041 if (use_json) {
14042 /* advertisement-interval */
14043 json_object_int_add(json_neigh,
14044 "minBtwnAdvertisementRunsTimerMsecs",
14045 p->v_routeadv * 1000);
14046
14047 /* Update-source. */
14048 if (p->update_if || p->update_source) {
14049 if (p->update_if)
14050 json_object_string_add(json_neigh,
14051 "updateSource",
14052 p->update_if);
14053 else if (p->update_source)
14054 json_object_string_addf(json_neigh,
14055 "updateSource", "%pSU",
14056 p->update_source);
14057 }
14058 } else {
14059 /* advertisement-interval */
14060 vty_out(vty,
14061 " Minimum time between advertisement runs is %d seconds\n",
14062 p->v_routeadv);
14063
14064 /* Update-source. */
14065 if (p->update_if || p->update_source) {
14066 vty_out(vty, " Update source is ");
14067 if (p->update_if)
14068 vty_out(vty, "%s", p->update_if);
14069 else if (p->update_source)
14070 vty_out(vty, "%pSU", p->update_source);
14071 vty_out(vty, "\n");
14072 }
14073
14074 vty_out(vty, "\n");
14075 }
14076
14077 /* Address Family Information */
14078 json_object *json_hold = NULL;
14079
14080 if (use_json)
14081 json_hold = json_object_new_object();
14082
14083 FOREACH_AFI_SAFI (afi, safi)
14084 if (p->afc[afi][safi])
14085 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14086 json_hold);
14087
14088 if (use_json) {
14089 json_object_object_add(json_neigh, "addressFamilyInfo",
14090 json_hold);
14091 json_object_int_add(json_neigh, "connectionsEstablished",
14092 p->established);
14093 json_object_int_add(json_neigh, "connectionsDropped",
14094 p->dropped);
14095 } else
14096 vty_out(vty, " Connections established %d; dropped %d\n",
14097 p->established, p->dropped);
14098
14099 if (!p->last_reset) {
14100 if (use_json)
14101 json_object_string_add(json_neigh, "lastReset",
14102 "never");
14103 else
14104 vty_out(vty, " Last reset never\n");
14105 } else {
14106 if (use_json) {
14107 time_t uptime;
14108 struct tm tm;
14109
14110 uptime = monotime(NULL);
14111 uptime -= p->resettime;
14112 gmtime_r(&uptime, &tm);
14113
14114 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14115 (tm.tm_sec * 1000)
14116 + (tm.tm_min * 60000)
14117 + (tm.tm_hour * 3600000));
14118 bgp_show_peer_reset(NULL, p, json_neigh, true);
14119 } else {
14120 vty_out(vty, " Last reset %s, ",
14121 peer_uptime(p->resettime, timebuf,
14122 BGP_UPTIME_LEN, 0, NULL));
14123
14124 bgp_show_peer_reset(vty, p, NULL, false);
14125 if (p->last_reset_cause_size) {
14126 msg = p->last_reset_cause;
14127 vty_out(vty,
14128 " Message received that caused BGP to send a NOTIFICATION:\n ");
14129 for (i = 1; i <= p->last_reset_cause_size;
14130 i++) {
14131 vty_out(vty, "%02X", *msg++);
14132
14133 if (i != p->last_reset_cause_size) {
14134 if (i % 16 == 0) {
14135 vty_out(vty, "\n ");
14136 } else if (i % 4 == 0) {
14137 vty_out(vty, " ");
14138 }
14139 }
14140 }
14141 vty_out(vty, "\n");
14142 }
14143 }
14144 }
14145
14146 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14147 if (use_json)
14148 json_object_boolean_true_add(json_neigh,
14149 "prefixesConfigExceedMax");
14150 else
14151 vty_out(vty,
14152 " Peer had exceeded the max. no. of prefixes configured.\n");
14153
14154 if (p->t_pmax_restart) {
14155 if (use_json) {
14156 json_object_boolean_true_add(
14157 json_neigh, "reducePrefixNumFrom");
14158 json_object_int_add(json_neigh,
14159 "restartInTimerMsec",
14160 thread_timer_remain_second(
14161 p->t_pmax_restart)
14162 * 1000);
14163 } else
14164 vty_out(vty,
14165 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14166 p->host, thread_timer_remain_second(
14167 p->t_pmax_restart));
14168 } else {
14169 if (use_json)
14170 json_object_boolean_true_add(
14171 json_neigh,
14172 "reducePrefixNumAndClearIpBgp");
14173 else
14174 vty_out(vty,
14175 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14176 p->host);
14177 }
14178 }
14179
14180 /* EBGP Multihop and GTSM */
14181 if (p->sort != BGP_PEER_IBGP) {
14182 if (use_json) {
14183 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14184 json_object_int_add(json_neigh,
14185 "externalBgpNbrMaxHopsAway",
14186 p->gtsm_hops);
14187 else
14188 json_object_int_add(json_neigh,
14189 "externalBgpNbrMaxHopsAway",
14190 p->ttl);
14191 } else {
14192 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14193 vty_out(vty,
14194 " External BGP neighbor may be up to %d hops away.\n",
14195 p->gtsm_hops);
14196 else
14197 vty_out(vty,
14198 " External BGP neighbor may be up to %d hops away.\n",
14199 p->ttl);
14200 }
14201 } else {
14202 if (use_json) {
14203 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14204 json_object_int_add(json_neigh,
14205 "internalBgpNbrMaxHopsAway",
14206 p->gtsm_hops);
14207 else
14208 json_object_int_add(json_neigh,
14209 "internalBgpNbrMaxHopsAway",
14210 p->ttl);
14211 } else {
14212 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14213 vty_out(vty,
14214 " Internal BGP neighbor may be up to %d hops away.\n",
14215 p->gtsm_hops);
14216 else
14217 vty_out(vty,
14218 " Internal BGP neighbor may be up to %d hops away.\n",
14219 p->ttl);
14220 }
14221 }
14222
14223 /* Local address. */
14224 if (p->su_local) {
14225 if (use_json) {
14226 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14227 p->su_local);
14228 json_object_int_add(json_neigh, "portLocal",
14229 ntohs(p->su_local->sin.sin_port));
14230 } else
14231 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14232 p->su_local, ntohs(p->su_local->sin.sin_port));
14233 } else {
14234 if (use_json) {
14235 json_object_string_add(json_neigh, "hostLocal",
14236 "Unknown");
14237 json_object_int_add(json_neigh, "portLocal", -1);
14238 }
14239 }
14240
14241 /* Remote address. */
14242 if (p->su_remote) {
14243 if (use_json) {
14244 json_object_string_addf(json_neigh, "hostForeign",
14245 "%pSU", p->su_remote);
14246 json_object_int_add(json_neigh, "portForeign",
14247 ntohs(p->su_remote->sin.sin_port));
14248 } else
14249 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14250 p->su_remote,
14251 ntohs(p->su_remote->sin.sin_port));
14252 } else {
14253 if (use_json) {
14254 json_object_string_add(json_neigh, "hostForeign",
14255 "Unknown");
14256 json_object_int_add(json_neigh, "portForeign", -1);
14257 }
14258 }
14259
14260 /* Nexthop display. */
14261 if (p->su_local) {
14262 if (use_json) {
14263 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14264 &p->nexthop.v4);
14265 json_object_string_addf(json_neigh, "nexthopGlobal",
14266 "%pI6", &p->nexthop.v6_global);
14267 json_object_string_addf(json_neigh, "nexthopLocal",
14268 "%pI6", &p->nexthop.v6_local);
14269 if (p->shared_network)
14270 json_object_string_add(json_neigh,
14271 "bgpConnection",
14272 "sharedNetwork");
14273 else
14274 json_object_string_add(json_neigh,
14275 "bgpConnection",
14276 "nonSharedNetwork");
14277 } else {
14278 vty_out(vty, "Nexthop: %s\n",
14279 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14280 sizeof(buf1)));
14281 vty_out(vty, "Nexthop global: %s\n",
14282 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14283 sizeof(buf1)));
14284 vty_out(vty, "Nexthop local: %s\n",
14285 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14286 sizeof(buf1)));
14287 vty_out(vty, "BGP connection: %s\n",
14288 p->shared_network ? "shared network"
14289 : "non shared network");
14290 }
14291 }
14292
14293 /* Timer information. */
14294 if (use_json) {
14295 json_object_int_add(json_neigh, "connectRetryTimer",
14296 p->v_connect);
14297 if (peer_established(p) && p->rtt)
14298 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14299 p->rtt);
14300 if (p->t_start)
14301 json_object_int_add(
14302 json_neigh, "nextStartTimerDueInMsecs",
14303 thread_timer_remain_second(p->t_start) * 1000);
14304 if (p->t_connect)
14305 json_object_int_add(
14306 json_neigh, "nextConnectTimerDueInMsecs",
14307 thread_timer_remain_second(p->t_connect)
14308 * 1000);
14309 if (p->t_routeadv) {
14310 json_object_int_add(json_neigh, "mraiInterval",
14311 p->v_routeadv);
14312 json_object_int_add(
14313 json_neigh, "mraiTimerExpireInMsecs",
14314 thread_timer_remain_second(p->t_routeadv)
14315 * 1000);
14316 }
14317 if (p->password)
14318 json_object_int_add(json_neigh, "authenticationEnabled",
14319 1);
14320
14321 if (p->t_read)
14322 json_object_string_add(json_neigh, "readThread", "on");
14323 else
14324 json_object_string_add(json_neigh, "readThread", "off");
14325
14326 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14327 json_object_string_add(json_neigh, "writeThread", "on");
14328 else
14329 json_object_string_add(json_neigh, "writeThread",
14330 "off");
14331 } else {
14332 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14333 p->v_connect);
14334 if (peer_established(p) && p->rtt)
14335 vty_out(vty, "Estimated round trip time: %d ms\n",
14336 p->rtt);
14337 if (p->t_start)
14338 vty_out(vty, "Next start timer due in %ld seconds\n",
14339 thread_timer_remain_second(p->t_start));
14340 if (p->t_connect)
14341 vty_out(vty, "Next connect timer due in %ld seconds\n",
14342 thread_timer_remain_second(p->t_connect));
14343 if (p->t_routeadv)
14344 vty_out(vty,
14345 "MRAI (interval %u) timer expires in %ld seconds\n",
14346 p->v_routeadv,
14347 thread_timer_remain_second(p->t_routeadv));
14348 if (p->password)
14349 vty_out(vty, "Peer Authentication Enabled\n");
14350
14351 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14352 p->t_read ? "on" : "off",
14353 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14354 ? "on"
14355 : "off", p->fd);
14356 }
14357
14358 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14359 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14360 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14361
14362 if (!use_json)
14363 vty_out(vty, "\n");
14364
14365 /* BFD information. */
14366 if (p->bfd_config)
14367 bgp_bfd_show_info(vty, p, json_neigh);
14368
14369 if (use_json) {
14370 if (p->conf_if) /* Configured interface name. */
14371 json_object_object_add(json, p->conf_if, json_neigh);
14372 else /* Configured IP address. */
14373 json_object_object_add(json, p->host, json_neigh);
14374 }
14375 }
14376
14377 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14378 enum show_type type,
14379 union sockunion *su,
14380 const char *conf_if, afi_t afi,
14381 bool use_json)
14382 {
14383 struct listnode *node, *nnode;
14384 struct peer *peer;
14385 int find = 0;
14386 safi_t safi = SAFI_UNICAST;
14387 json_object *json = NULL;
14388 json_object *json_neighbor = NULL;
14389
14390 if (use_json) {
14391 json = json_object_new_object();
14392 json_neighbor = json_object_new_object();
14393 }
14394
14395 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14396
14397 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14398 continue;
14399
14400 if ((peer->afc[afi][safi]) == 0)
14401 continue;
14402
14403 if (type == show_all) {
14404 bgp_show_peer_gr_status(vty, peer, use_json,
14405 json_neighbor);
14406
14407 if (use_json) {
14408 json_object_object_add(json, peer->host,
14409 json_neighbor);
14410 json_neighbor = NULL;
14411 }
14412
14413 } else if (type == show_peer) {
14414 if (conf_if) {
14415 if ((peer->conf_if
14416 && !strcmp(peer->conf_if, conf_if))
14417 || (peer->hostname
14418 && !strcmp(peer->hostname, conf_if))) {
14419 find = 1;
14420 bgp_show_peer_gr_status(vty, peer,
14421 use_json,
14422 json_neighbor);
14423 }
14424 } else {
14425 if (sockunion_same(&peer->su, su)) {
14426 find = 1;
14427 bgp_show_peer_gr_status(vty, peer,
14428 use_json,
14429 json_neighbor);
14430 }
14431 }
14432 if (use_json && find)
14433 json_object_object_add(json, peer->host,
14434 json_neighbor);
14435 }
14436
14437 if (find) {
14438 json_neighbor = NULL;
14439 break;
14440 }
14441 }
14442
14443 if (type == show_peer && !find) {
14444 if (use_json)
14445 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14446 else
14447 vty_out(vty, "%% No such neighbor\n");
14448 }
14449 if (use_json) {
14450 if (json_neighbor)
14451 json_object_free(json_neighbor);
14452 vty_json(vty, json);
14453 } else {
14454 vty_out(vty, "\n");
14455 }
14456
14457 return CMD_SUCCESS;
14458 }
14459
14460 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14461 enum show_type type, union sockunion *su,
14462 const char *conf_if, bool use_json,
14463 json_object *json)
14464 {
14465 struct listnode *node, *nnode;
14466 struct peer *peer;
14467 int find = 0;
14468 bool nbr_output = false;
14469 afi_t afi = AFI_MAX;
14470 safi_t safi = SAFI_MAX;
14471
14472 if (type == show_ipv4_peer || type == show_ipv4_all) {
14473 afi = AFI_IP;
14474 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14475 afi = AFI_IP6;
14476 }
14477
14478 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14479 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14480 continue;
14481
14482 switch (type) {
14483 case show_all:
14484 bgp_show_peer(vty, peer, use_json, json);
14485 nbr_output = true;
14486 break;
14487 case show_peer:
14488 if (conf_if) {
14489 if ((peer->conf_if
14490 && !strcmp(peer->conf_if, conf_if))
14491 || (peer->hostname
14492 && !strcmp(peer->hostname, conf_if))) {
14493 find = 1;
14494 bgp_show_peer(vty, peer, use_json,
14495 json);
14496 }
14497 } else {
14498 if (sockunion_same(&peer->su, su)) {
14499 find = 1;
14500 bgp_show_peer(vty, peer, use_json,
14501 json);
14502 }
14503 }
14504 break;
14505 case show_ipv4_peer:
14506 case show_ipv6_peer:
14507 FOREACH_SAFI (safi) {
14508 if (peer->afc[afi][safi]) {
14509 if (conf_if) {
14510 if ((peer->conf_if
14511 && !strcmp(peer->conf_if, conf_if))
14512 || (peer->hostname
14513 && !strcmp(peer->hostname, conf_if))) {
14514 find = 1;
14515 bgp_show_peer(vty, peer, use_json,
14516 json);
14517 break;
14518 }
14519 } else {
14520 if (sockunion_same(&peer->su, su)) {
14521 find = 1;
14522 bgp_show_peer(vty, peer, use_json,
14523 json);
14524 break;
14525 }
14526 }
14527 }
14528 }
14529 break;
14530 case show_ipv4_all:
14531 case show_ipv6_all:
14532 FOREACH_SAFI (safi) {
14533 if (peer->afc[afi][safi]) {
14534 bgp_show_peer(vty, peer, use_json, json);
14535 nbr_output = true;
14536 break;
14537 }
14538 }
14539 break;
14540 }
14541 }
14542
14543 if ((type == show_peer || type == show_ipv4_peer ||
14544 type == show_ipv6_peer) && !find) {
14545 if (use_json)
14546 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14547 else
14548 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14549 }
14550
14551 if (type != show_peer && type != show_ipv4_peer &&
14552 type != show_ipv6_peer && !nbr_output && !use_json)
14553 vty_out(vty, "%% No BGP neighbors found\n");
14554
14555 if (use_json) {
14556 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14557 json, JSON_C_TO_STRING_PRETTY));
14558 } else {
14559 vty_out(vty, "\n");
14560 }
14561
14562 return CMD_SUCCESS;
14563 }
14564
14565 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14566 enum show_type type,
14567 const char *ip_str,
14568 afi_t afi, bool use_json)
14569 {
14570
14571 int ret;
14572 struct bgp *bgp;
14573 union sockunion su;
14574
14575 bgp = bgp_get_default();
14576
14577 if (!bgp)
14578 return;
14579
14580 if (!use_json)
14581 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14582 NULL);
14583
14584 if (ip_str) {
14585 ret = str2sockunion(ip_str, &su);
14586 if (ret < 0)
14587 bgp_show_neighbor_graceful_restart(
14588 vty, bgp, type, NULL, ip_str, afi, use_json);
14589 else
14590 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14591 NULL, afi, use_json);
14592 } else
14593 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14594 afi, use_json);
14595 }
14596
14597 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14598 enum show_type type,
14599 const char *ip_str,
14600 bool use_json)
14601 {
14602 struct listnode *node, *nnode;
14603 struct bgp *bgp;
14604 union sockunion su;
14605 json_object *json = NULL;
14606 int ret, is_first = 1;
14607 bool nbr_output = false;
14608
14609 if (use_json)
14610 vty_out(vty, "{\n");
14611
14612 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14613 nbr_output = true;
14614 if (use_json) {
14615 if (!(json = json_object_new_object())) {
14616 flog_err(
14617 EC_BGP_JSON_MEM_ERROR,
14618 "Unable to allocate memory for JSON object");
14619 vty_out(vty,
14620 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14621 return;
14622 }
14623
14624 json_object_int_add(json, "vrfId",
14625 (bgp->vrf_id == VRF_UNKNOWN)
14626 ? -1
14627 : (int64_t)bgp->vrf_id);
14628 json_object_string_add(
14629 json, "vrfName",
14630 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14631 ? VRF_DEFAULT_NAME
14632 : bgp->name);
14633
14634 if (!is_first)
14635 vty_out(vty, ",\n");
14636 else
14637 is_first = 0;
14638
14639 vty_out(vty, "\"%s\":",
14640 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14641 ? VRF_DEFAULT_NAME
14642 : bgp->name);
14643 } else {
14644 vty_out(vty, "\nInstance %s:\n",
14645 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14646 ? VRF_DEFAULT_NAME
14647 : bgp->name);
14648 }
14649
14650 if (type == show_peer || type == show_ipv4_peer ||
14651 type == show_ipv6_peer) {
14652 ret = str2sockunion(ip_str, &su);
14653 if (ret < 0)
14654 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14655 use_json, json);
14656 else
14657 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14658 use_json, json);
14659 } else {
14660 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14661 use_json, json);
14662 }
14663 json_object_free(json);
14664 json = NULL;
14665 }
14666
14667 if (use_json)
14668 vty_out(vty, "}\n");
14669 else if (!nbr_output)
14670 vty_out(vty, "%% BGP instance not found\n");
14671 }
14672
14673 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14674 enum show_type type, const char *ip_str,
14675 bool use_json)
14676 {
14677 int ret;
14678 struct bgp *bgp;
14679 union sockunion su;
14680 json_object *json = NULL;
14681
14682 if (name) {
14683 if (strmatch(name, "all")) {
14684 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14685 use_json);
14686 return CMD_SUCCESS;
14687 } else {
14688 bgp = bgp_lookup_by_name(name);
14689 if (!bgp) {
14690 if (use_json) {
14691 json = json_object_new_object();
14692 vty_json(vty, json);
14693 } else
14694 vty_out(vty,
14695 "%% BGP instance not found\n");
14696
14697 return CMD_WARNING;
14698 }
14699 }
14700 } else {
14701 bgp = bgp_get_default();
14702 }
14703
14704 if (bgp) {
14705 json = json_object_new_object();
14706 if (ip_str) {
14707 ret = str2sockunion(ip_str, &su);
14708 if (ret < 0)
14709 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14710 use_json, json);
14711 else
14712 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14713 use_json, json);
14714 } else {
14715 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14716 json);
14717 }
14718 json_object_free(json);
14719 } else {
14720 if (use_json)
14721 vty_out(vty, "{}\n");
14722 else
14723 vty_out(vty, "%% BGP instance not found\n");
14724 }
14725
14726 return CMD_SUCCESS;
14727 }
14728
14729
14730
14731 /* "show [ip] bgp neighbors graceful-restart" commands. */
14732 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14733 show_ip_bgp_neighbors_graceful_restart_cmd,
14734 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14735 SHOW_STR
14736 BGP_STR
14737 IP_STR
14738 IPV6_STR
14739 NEIGHBOR_STR
14740 "Neighbor to display information about\n"
14741 "Neighbor to display information about\n"
14742 "Neighbor on BGP configured interface\n"
14743 GR_SHOW
14744 JSON_STR)
14745 {
14746 char *sh_arg = NULL;
14747 enum show_type sh_type;
14748 int idx = 0;
14749 afi_t afi = AFI_MAX;
14750 bool uj = use_json(argc, argv);
14751
14752 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14753 afi = AFI_MAX;
14754
14755 idx++;
14756
14757 if (argv_find(argv, argc, "A.B.C.D", &idx)
14758 || argv_find(argv, argc, "X:X::X:X", &idx)
14759 || argv_find(argv, argc, "WORD", &idx)) {
14760 sh_type = show_peer;
14761 sh_arg = argv[idx]->arg;
14762 } else
14763 sh_type = show_all;
14764
14765 if (!argv_find(argv, argc, "graceful-restart", &idx))
14766 return CMD_SUCCESS;
14767
14768
14769 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14770 afi, uj);
14771 }
14772
14773 /* "show [ip] bgp neighbors" commands. */
14774 DEFUN (show_ip_bgp_neighbors,
14775 show_ip_bgp_neighbors_cmd,
14776 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14777 SHOW_STR
14778 IP_STR
14779 BGP_STR
14780 BGP_INSTANCE_HELP_STR
14781 BGP_AF_STR
14782 BGP_AF_STR
14783 "Detailed information on TCP and BGP neighbor connections\n"
14784 "Neighbor to display information about\n"
14785 "Neighbor to display information about\n"
14786 "Neighbor on BGP configured interface\n"
14787 JSON_STR)
14788 {
14789 char *vrf = NULL;
14790 char *sh_arg = NULL;
14791 enum show_type sh_type;
14792 afi_t afi = AFI_MAX;
14793
14794 bool uj = use_json(argc, argv);
14795
14796 int idx = 0;
14797
14798 /* [<vrf> VIEWVRFNAME] */
14799 if (argv_find(argv, argc, "vrf", &idx)) {
14800 vrf = argv[idx + 1]->arg;
14801 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14802 vrf = NULL;
14803 } else if (argv_find(argv, argc, "view", &idx))
14804 /* [<view> VIEWVRFNAME] */
14805 vrf = argv[idx + 1]->arg;
14806
14807 idx++;
14808
14809 if (argv_find(argv, argc, "ipv4", &idx)) {
14810 sh_type = show_ipv4_all;
14811 afi = AFI_IP;
14812 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14813 sh_type = show_ipv6_all;
14814 afi = AFI_IP6;
14815 } else {
14816 sh_type = show_all;
14817 }
14818
14819 if (argv_find(argv, argc, "A.B.C.D", &idx)
14820 || argv_find(argv, argc, "X:X::X:X", &idx)
14821 || argv_find(argv, argc, "WORD", &idx)) {
14822 sh_type = show_peer;
14823 sh_arg = argv[idx]->arg;
14824 }
14825
14826 if (sh_type == show_peer && afi == AFI_IP) {
14827 sh_type = show_ipv4_peer;
14828 } else if (sh_type == show_peer && afi == AFI_IP6) {
14829 sh_type = show_ipv6_peer;
14830 }
14831
14832 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14833 }
14834
14835 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14836 paths' and `show ip mbgp paths'. Those functions results are the
14837 same.*/
14838 DEFUN (show_ip_bgp_paths,
14839 show_ip_bgp_paths_cmd,
14840 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14841 SHOW_STR
14842 IP_STR
14843 BGP_STR
14844 BGP_SAFI_HELP_STR
14845 "Path information\n")
14846 {
14847 vty_out(vty, "Address Refcnt Path\n");
14848 aspath_print_all_vty(vty);
14849 return CMD_SUCCESS;
14850 }
14851
14852 #include "hash.h"
14853
14854 static void community_show_all_iterator(struct hash_bucket *bucket,
14855 struct vty *vty)
14856 {
14857 struct community *com;
14858
14859 com = (struct community *)bucket->data;
14860 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14861 community_str(com, false, false));
14862 }
14863
14864 /* Show BGP's community internal data. */
14865 DEFUN (show_ip_bgp_community_info,
14866 show_ip_bgp_community_info_cmd,
14867 "show [ip] bgp community-info",
14868 SHOW_STR
14869 IP_STR
14870 BGP_STR
14871 "List all bgp community information\n")
14872 {
14873 vty_out(vty, "Address Refcnt Community\n");
14874
14875 hash_iterate(community_hash(),
14876 (void (*)(struct hash_bucket *,
14877 void *))community_show_all_iterator,
14878 vty);
14879
14880 return CMD_SUCCESS;
14881 }
14882
14883 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14884 struct vty *vty)
14885 {
14886 struct lcommunity *lcom;
14887
14888 lcom = (struct lcommunity *)bucket->data;
14889 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14890 lcommunity_str(lcom, false, false));
14891 }
14892
14893 /* Show BGP's community internal data. */
14894 DEFUN (show_ip_bgp_lcommunity_info,
14895 show_ip_bgp_lcommunity_info_cmd,
14896 "show ip bgp large-community-info",
14897 SHOW_STR
14898 IP_STR
14899 BGP_STR
14900 "List all bgp large-community information\n")
14901 {
14902 vty_out(vty, "Address Refcnt Large-community\n");
14903
14904 hash_iterate(lcommunity_hash(),
14905 (void (*)(struct hash_bucket *,
14906 void *))lcommunity_show_all_iterator,
14907 vty);
14908
14909 return CMD_SUCCESS;
14910 }
14911 /* Graceful Restart */
14912
14913 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14914 struct bgp *bgp,
14915 bool use_json,
14916 json_object *json)
14917 {
14918
14919
14920 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14921
14922 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14923
14924 switch (bgp_global_gr_mode) {
14925
14926 case GLOBAL_HELPER:
14927 vty_out(vty, "Global BGP GR Mode : Helper\n");
14928 break;
14929
14930 case GLOBAL_GR:
14931 vty_out(vty, "Global BGP GR Mode : Restart\n");
14932 break;
14933
14934 case GLOBAL_DISABLE:
14935 vty_out(vty, "Global BGP GR Mode : Disable\n");
14936 break;
14937
14938 case GLOBAL_INVALID:
14939 vty_out(vty,
14940 "Global BGP GR Mode Invalid\n");
14941 break;
14942 }
14943 vty_out(vty, "\n");
14944 }
14945
14946 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14947 enum show_type type,
14948 const char *ip_str,
14949 afi_t afi, bool use_json)
14950 {
14951 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14952 afi = AFI_IP;
14953
14954 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14955
14956 bgp_show_neighbor_graceful_restart_vty(
14957 vty, type, ip_str, afi, use_json);
14958 afi++;
14959 }
14960 } else if (afi != AFI_MAX) {
14961 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14962 use_json);
14963 } else {
14964 return CMD_ERR_INCOMPLETE;
14965 }
14966
14967 return CMD_SUCCESS;
14968 }
14969 /* Graceful Restart */
14970
14971 DEFUN (show_ip_bgp_attr_info,
14972 show_ip_bgp_attr_info_cmd,
14973 "show [ip] bgp attribute-info",
14974 SHOW_STR
14975 IP_STR
14976 BGP_STR
14977 "List all bgp attribute information\n")
14978 {
14979 attr_show_all(vty);
14980 return CMD_SUCCESS;
14981 }
14982
14983 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14984 afi_t afi, safi_t safi,
14985 bool use_json, json_object *json)
14986 {
14987 struct bgp *bgp;
14988 struct listnode *node;
14989 char *vname;
14990 char *ecom_str;
14991 enum vpn_policy_direction dir;
14992
14993 if (json) {
14994 json_object *json_import_vrfs = NULL;
14995 json_object *json_export_vrfs = NULL;
14996
14997 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14998
14999 if (!bgp) {
15000 vty_json(vty, json);
15001
15002 return CMD_WARNING;
15003 }
15004
15005 /* Provide context for the block */
15006 json_object_string_add(json, "vrf", name ? name : "default");
15007 json_object_string_add(json, "afiSafi",
15008 get_afi_safi_str(afi, safi, true));
15009
15010 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15011 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15012 json_object_string_add(json, "importFromVrfs", "none");
15013 json_object_string_add(json, "importRts", "none");
15014 } else {
15015 json_import_vrfs = json_object_new_array();
15016
15017 for (ALL_LIST_ELEMENTS_RO(
15018 bgp->vpn_policy[afi].import_vrf,
15019 node, vname))
15020 json_object_array_add(json_import_vrfs,
15021 json_object_new_string(vname));
15022
15023 json_object_object_add(json, "importFromVrfs",
15024 json_import_vrfs);
15025 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15026 if (bgp->vpn_policy[afi].rtlist[dir]) {
15027 ecom_str = ecommunity_ecom2str(
15028 bgp->vpn_policy[afi].rtlist[dir],
15029 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15030 json_object_string_add(json, "importRts",
15031 ecom_str);
15032 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15033 } else
15034 json_object_string_add(json, "importRts",
15035 "none");
15036 }
15037
15038 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15039 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15040 json_object_string_add(json, "exportToVrfs", "none");
15041 json_object_string_add(json, "routeDistinguisher",
15042 "none");
15043 json_object_string_add(json, "exportRts", "none");
15044 } else {
15045 json_export_vrfs = json_object_new_array();
15046
15047 for (ALL_LIST_ELEMENTS_RO(
15048 bgp->vpn_policy[afi].export_vrf,
15049 node, vname))
15050 json_object_array_add(json_export_vrfs,
15051 json_object_new_string(vname));
15052 json_object_object_add(json, "exportToVrfs",
15053 json_export_vrfs);
15054 json_object_string_addf(json, "routeDistinguisher",
15055 "%pRD",
15056 &bgp->vpn_policy[afi].tovpn_rd);
15057
15058 dir = BGP_VPN_POLICY_DIR_TOVPN;
15059 if (bgp->vpn_policy[afi].rtlist[dir]) {
15060 ecom_str = ecommunity_ecom2str(
15061 bgp->vpn_policy[afi].rtlist[dir],
15062 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15063 json_object_string_add(json, "exportRts",
15064 ecom_str);
15065 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15066 } else
15067 json_object_string_add(json, "exportRts",
15068 "none");
15069 }
15070
15071 if (use_json) {
15072 vty_json(vty, json);
15073 }
15074 } else {
15075 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15076
15077 if (!bgp) {
15078 vty_out(vty, "%% No such BGP instance exist\n");
15079 return CMD_WARNING;
15080 }
15081
15082 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15083 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15084 vty_out(vty,
15085 "This VRF is not importing %s routes from any other VRF\n",
15086 get_afi_safi_str(afi, safi, false));
15087 else {
15088 vty_out(vty,
15089 "This VRF is importing %s routes from the following VRFs:\n",
15090 get_afi_safi_str(afi, safi, false));
15091
15092 for (ALL_LIST_ELEMENTS_RO(
15093 bgp->vpn_policy[afi].import_vrf,
15094 node, vname))
15095 vty_out(vty, " %s\n", vname);
15096
15097 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15098 ecom_str = NULL;
15099 if (bgp->vpn_policy[afi].rtlist[dir]) {
15100 ecom_str = ecommunity_ecom2str(
15101 bgp->vpn_policy[afi].rtlist[dir],
15102 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15103 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15104
15105 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15106 } else
15107 vty_out(vty, "Import RT(s):\n");
15108 }
15109
15110 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15111 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15112 vty_out(vty,
15113 "This VRF is not exporting %s routes to any other VRF\n",
15114 get_afi_safi_str(afi, safi, false));
15115 else {
15116 vty_out(vty,
15117 "This VRF is exporting %s routes to the following VRFs:\n",
15118 get_afi_safi_str(afi, safi, false));
15119
15120 for (ALL_LIST_ELEMENTS_RO(
15121 bgp->vpn_policy[afi].export_vrf,
15122 node, vname))
15123 vty_out(vty, " %s\n", vname);
15124
15125 vty_out(vty, "RD: %pRD\n",
15126 &bgp->vpn_policy[afi].tovpn_rd);
15127
15128 dir = BGP_VPN_POLICY_DIR_TOVPN;
15129 if (bgp->vpn_policy[afi].rtlist[dir]) {
15130 ecom_str = ecommunity_ecom2str(
15131 bgp->vpn_policy[afi].rtlist[dir],
15132 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15133 vty_out(vty, "Export RT: %s\n", ecom_str);
15134 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15135 } else
15136 vty_out(vty, "Import RT(s):\n");
15137 }
15138 }
15139
15140 return CMD_SUCCESS;
15141 }
15142
15143 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15144 safi_t safi, bool use_json)
15145 {
15146 struct listnode *node, *nnode;
15147 struct bgp *bgp;
15148 char *vrf_name = NULL;
15149 json_object *json = NULL;
15150 json_object *json_vrf = NULL;
15151 json_object *json_vrfs = NULL;
15152
15153 if (use_json) {
15154 json = json_object_new_object();
15155 json_vrfs = json_object_new_object();
15156 }
15157
15158 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15159
15160 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15161 vrf_name = bgp->name;
15162
15163 if (use_json) {
15164 json_vrf = json_object_new_object();
15165 } else {
15166 vty_out(vty, "\nInstance %s:\n",
15167 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15168 ? VRF_DEFAULT_NAME : bgp->name);
15169 }
15170 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15171 if (use_json) {
15172 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15173 json_object_object_add(json_vrfs,
15174 VRF_DEFAULT_NAME, json_vrf);
15175 else
15176 json_object_object_add(json_vrfs, vrf_name,
15177 json_vrf);
15178 }
15179 }
15180
15181 if (use_json) {
15182 json_object_object_add(json, "vrfs", json_vrfs);
15183 vty_json(vty, json);
15184 }
15185
15186 return CMD_SUCCESS;
15187 }
15188
15189 /* "show [ip] bgp route-leak" command. */
15190 DEFUN (show_ip_bgp_route_leak,
15191 show_ip_bgp_route_leak_cmd,
15192 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15193 SHOW_STR
15194 IP_STR
15195 BGP_STR
15196 BGP_INSTANCE_HELP_STR
15197 BGP_AFI_HELP_STR
15198 BGP_SAFI_HELP_STR
15199 "Route leaking information\n"
15200 JSON_STR)
15201 {
15202 char *vrf = NULL;
15203 afi_t afi = AFI_MAX;
15204 safi_t safi = SAFI_MAX;
15205
15206 bool uj = use_json(argc, argv);
15207 int idx = 0;
15208 json_object *json = NULL;
15209
15210 /* show [ip] bgp */
15211 if (argv_find(argv, argc, "ip", &idx)) {
15212 afi = AFI_IP;
15213 safi = SAFI_UNICAST;
15214 }
15215 /* [vrf VIEWVRFNAME] */
15216 if (argv_find(argv, argc, "view", &idx)) {
15217 vty_out(vty,
15218 "%% This command is not applicable to BGP views\n");
15219 return CMD_WARNING;
15220 }
15221
15222 if (argv_find(argv, argc, "vrf", &idx)) {
15223 vrf = argv[idx + 1]->arg;
15224 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15225 vrf = NULL;
15226 }
15227 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15228 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15229 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15230
15231 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15232 vty_out(vty,
15233 "%% This command is applicable only for unicast ipv4|ipv6\n");
15234 return CMD_WARNING;
15235 }
15236
15237 if (vrf && strmatch(vrf, "all"))
15238 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15239
15240 if (uj)
15241 json = json_object_new_object();
15242
15243 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15244 }
15245
15246 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15247 safi_t safi)
15248 {
15249 struct listnode *node, *nnode;
15250 struct bgp *bgp;
15251
15252 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15253 vty_out(vty, "\nInstance %s:\n",
15254 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15255 ? VRF_DEFAULT_NAME
15256 : bgp->name);
15257 update_group_show(bgp, afi, safi, vty, 0);
15258 }
15259 }
15260
15261 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15262 int safi, uint64_t subgrp_id)
15263 {
15264 struct bgp *bgp;
15265
15266 if (name) {
15267 if (strmatch(name, "all")) {
15268 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15269 return CMD_SUCCESS;
15270 } else {
15271 bgp = bgp_lookup_by_name(name);
15272 }
15273 } else {
15274 bgp = bgp_get_default();
15275 }
15276
15277 if (bgp)
15278 update_group_show(bgp, afi, safi, vty, subgrp_id);
15279 return CMD_SUCCESS;
15280 }
15281
15282 DEFUN (show_ip_bgp_updgrps,
15283 show_ip_bgp_updgrps_cmd,
15284 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15285 SHOW_STR
15286 IP_STR
15287 BGP_STR
15288 BGP_INSTANCE_HELP_STR
15289 BGP_AFI_HELP_STR
15290 BGP_SAFI_WITH_LABEL_HELP_STR
15291 "Detailed info about dynamic update groups\n"
15292 "Specific subgroup to display detailed info for\n")
15293 {
15294 char *vrf = NULL;
15295 afi_t afi = AFI_IP6;
15296 safi_t safi = SAFI_UNICAST;
15297 uint64_t subgrp_id = 0;
15298
15299 int idx = 0;
15300
15301 /* show [ip] bgp */
15302 if (argv_find(argv, argc, "ip", &idx))
15303 afi = AFI_IP;
15304 /* [<vrf> VIEWVRFNAME] */
15305 if (argv_find(argv, argc, "vrf", &idx)) {
15306 vrf = argv[idx + 1]->arg;
15307 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15308 vrf = NULL;
15309 } else if (argv_find(argv, argc, "view", &idx))
15310 /* [<view> VIEWVRFNAME] */
15311 vrf = argv[idx + 1]->arg;
15312 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15313 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15314 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15315 }
15316
15317 /* get subgroup id, if provided */
15318 idx = argc - 1;
15319 if (argv[idx]->type == VARIABLE_TKN)
15320 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15321
15322 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15323 }
15324
15325 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15326 show_bgp_instance_all_ipv6_updgrps_cmd,
15327 "show [ip] bgp <view|vrf> all update-groups",
15328 SHOW_STR
15329 IP_STR
15330 BGP_STR
15331 BGP_INSTANCE_ALL_HELP_STR
15332 "Detailed info about dynamic update groups\n")
15333 {
15334 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15335 return CMD_SUCCESS;
15336 }
15337
15338 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15339 show_bgp_l2vpn_evpn_updgrps_cmd,
15340 "show [ip] bgp l2vpn evpn update-groups",
15341 SHOW_STR
15342 IP_STR
15343 BGP_STR
15344 "l2vpn address family\n"
15345 "evpn sub-address family\n"
15346 "Detailed info about dynamic update groups\n")
15347 {
15348 char *vrf = NULL;
15349 uint64_t subgrp_id = 0;
15350
15351 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15352 return CMD_SUCCESS;
15353 }
15354
15355 DEFUN (show_bgp_updgrps_stats,
15356 show_bgp_updgrps_stats_cmd,
15357 "show [ip] bgp update-groups statistics",
15358 SHOW_STR
15359 IP_STR
15360 BGP_STR
15361 "Detailed info about dynamic update groups\n"
15362 "Statistics\n")
15363 {
15364 struct bgp *bgp;
15365
15366 bgp = bgp_get_default();
15367 if (bgp)
15368 update_group_show_stats(bgp, vty);
15369
15370 return CMD_SUCCESS;
15371 }
15372
15373 DEFUN (show_bgp_instance_updgrps_stats,
15374 show_bgp_instance_updgrps_stats_cmd,
15375 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15376 SHOW_STR
15377 IP_STR
15378 BGP_STR
15379 BGP_INSTANCE_HELP_STR
15380 "Detailed info about dynamic update groups\n"
15381 "Statistics\n")
15382 {
15383 int idx_word = 3;
15384 struct bgp *bgp;
15385
15386 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15387 if (bgp)
15388 update_group_show_stats(bgp, vty);
15389
15390 return CMD_SUCCESS;
15391 }
15392
15393 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15394 afi_t afi, safi_t safi,
15395 const char *what, uint64_t subgrp_id)
15396 {
15397 struct bgp *bgp;
15398
15399 if (name)
15400 bgp = bgp_lookup_by_name(name);
15401 else
15402 bgp = bgp_get_default();
15403
15404 if (bgp) {
15405 if (!strcmp(what, "advertise-queue"))
15406 update_group_show_adj_queue(bgp, afi, safi, vty,
15407 subgrp_id);
15408 else if (!strcmp(what, "advertised-routes"))
15409 update_group_show_advertised(bgp, afi, safi, vty,
15410 subgrp_id);
15411 else if (!strcmp(what, "packet-queue"))
15412 update_group_show_packet_queue(bgp, afi, safi, vty,
15413 subgrp_id);
15414 }
15415 }
15416
15417 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15418 show_ip_bgp_instance_updgrps_adj_s_cmd,
15419 "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",
15420 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15421 BGP_SAFI_HELP_STR
15422 "Detailed info about dynamic update groups\n"
15423 "Specific subgroup to display info for\n"
15424 "Advertisement queue\n"
15425 "Announced routes\n"
15426 "Packet queue\n")
15427 {
15428 uint64_t subgrp_id = 0;
15429 afi_t afiz;
15430 safi_t safiz;
15431 if (sgid)
15432 subgrp_id = strtoull(sgid, NULL, 10);
15433
15434 if (!ip && !afi)
15435 afiz = AFI_IP6;
15436 if (!ip && afi)
15437 afiz = bgp_vty_afi_from_str(afi);
15438 if (ip && !afi)
15439 afiz = AFI_IP;
15440 if (ip && afi) {
15441 afiz = bgp_vty_afi_from_str(afi);
15442 if (afiz != AFI_IP)
15443 vty_out(vty,
15444 "%% Cannot specify both 'ip' and 'ipv6'\n");
15445 return CMD_WARNING;
15446 }
15447
15448 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15449
15450 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15451 return CMD_SUCCESS;
15452 }
15453
15454 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15455 json_object *json)
15456 {
15457 struct listnode *node, *nnode;
15458 struct prefix *range;
15459 struct peer *conf;
15460 struct peer *peer;
15461 afi_t afi;
15462 safi_t safi;
15463 const char *peer_status;
15464 int lr_count;
15465 int dynamic;
15466 bool af_cfgd;
15467 json_object *json_peer_group = NULL;
15468 json_object *json_peer_group_afc = NULL;
15469 json_object *json_peer_group_members = NULL;
15470 json_object *json_peer_group_dynamic = NULL;
15471 json_object *json_peer_group_dynamic_af = NULL;
15472 json_object *json_peer_group_ranges = NULL;
15473
15474 conf = group->conf;
15475
15476 if (json) {
15477 json_peer_group = json_object_new_object();
15478 json_peer_group_afc = json_object_new_array();
15479 }
15480
15481 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15482 if (json)
15483 json_object_int_add(json_peer_group, "remoteAs",
15484 conf->as);
15485 else
15486 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15487 group->name, conf->as);
15488 } else if (conf->as_type == AS_INTERNAL) {
15489 if (json)
15490 json_object_int_add(json_peer_group, "remoteAs",
15491 group->bgp->as);
15492 else
15493 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15494 group->name, group->bgp->as);
15495 } else {
15496 if (!json)
15497 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15498 }
15499
15500 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15501 if (json)
15502 json_object_string_add(json_peer_group, "type",
15503 "internal");
15504 else
15505 vty_out(vty, " Peer-group type is internal\n");
15506 } else {
15507 if (json)
15508 json_object_string_add(json_peer_group, "type",
15509 "external");
15510 else
15511 vty_out(vty, " Peer-group type is external\n");
15512 }
15513
15514 /* Display AFs configured. */
15515 if (!json)
15516 vty_out(vty, " Configured address-families:");
15517
15518 FOREACH_AFI_SAFI (afi, safi) {
15519 if (conf->afc[afi][safi]) {
15520 af_cfgd = true;
15521 if (json)
15522 json_object_array_add(
15523 json_peer_group_afc,
15524 json_object_new_string(get_afi_safi_str(
15525 afi, safi, false)));
15526 else
15527 vty_out(vty, " %s;",
15528 get_afi_safi_str(afi, safi, false));
15529 }
15530 }
15531
15532 if (json) {
15533 json_object_object_add(json_peer_group,
15534 "addressFamiliesConfigured",
15535 json_peer_group_afc);
15536 } else {
15537 if (!af_cfgd)
15538 vty_out(vty, " none\n");
15539 else
15540 vty_out(vty, "\n");
15541 }
15542
15543 /* Display listen ranges (for dynamic neighbors), if any */
15544 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15545 lr_count = listcount(group->listen_range[afi]);
15546 if (lr_count) {
15547 if (json) {
15548 if (!json_peer_group_dynamic)
15549 json_peer_group_dynamic =
15550 json_object_new_object();
15551
15552 json_peer_group_dynamic_af =
15553 json_object_new_object();
15554 json_peer_group_ranges =
15555 json_object_new_array();
15556 json_object_int_add(json_peer_group_dynamic_af,
15557 "count", lr_count);
15558 } else {
15559 vty_out(vty, " %d %s listen range(s)\n",
15560 lr_count, afi2str(afi));
15561 }
15562
15563 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15564 nnode, range)) {
15565 if (json) {
15566 char buf[BUFSIZ];
15567
15568 snprintfrr(buf, sizeof(buf), "%pFX",
15569 range);
15570
15571 json_object_array_add(
15572 json_peer_group_ranges,
15573 json_object_new_string(buf));
15574 } else {
15575 vty_out(vty, " %pFX\n", range);
15576 }
15577 }
15578
15579 if (json) {
15580 json_object_object_add(
15581 json_peer_group_dynamic_af, "ranges",
15582 json_peer_group_ranges);
15583
15584 json_object_object_add(
15585 json_peer_group_dynamic, afi2str(afi),
15586 json_peer_group_dynamic_af);
15587 }
15588 }
15589 }
15590
15591 if (json_peer_group_dynamic)
15592 json_object_object_add(json_peer_group, "dynamicRanges",
15593 json_peer_group_dynamic);
15594
15595 /* Display group members and their status */
15596 if (listcount(group->peer)) {
15597 if (json)
15598 json_peer_group_members = json_object_new_object();
15599 else
15600 vty_out(vty, " Peer-group members:\n");
15601 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15602 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15603 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15604 peer_status = "Idle (Admin)";
15605 else if (CHECK_FLAG(peer->sflags,
15606 PEER_STATUS_PREFIX_OVERFLOW))
15607 peer_status = "Idle (PfxCt)";
15608 else
15609 peer_status = lookup_msg(bgp_status_msg,
15610 peer->status, NULL);
15611
15612 dynamic = peer_dynamic_neighbor(peer);
15613
15614 if (json) {
15615 json_object *json_peer_group_member =
15616 json_object_new_object();
15617
15618 json_object_string_add(json_peer_group_member,
15619 "status", peer_status);
15620
15621 if (dynamic)
15622 json_object_boolean_true_add(
15623 json_peer_group_member,
15624 "dynamic");
15625
15626 json_object_object_add(json_peer_group_members,
15627 peer->host,
15628 json_peer_group_member);
15629 } else {
15630 vty_out(vty, " %s %s %s \n", peer->host,
15631 dynamic ? "(dynamic)" : "",
15632 peer_status);
15633 }
15634 }
15635 if (json)
15636 json_object_object_add(json_peer_group, "members",
15637 json_peer_group_members);
15638 }
15639
15640 if (json)
15641 json_object_object_add(json, group->name, json_peer_group);
15642
15643 return CMD_SUCCESS;
15644 }
15645
15646 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15647 const char *group_name, bool uj)
15648 {
15649 struct bgp *bgp;
15650 struct listnode *node, *nnode;
15651 struct peer_group *group;
15652 bool found = false;
15653 json_object *json = NULL;
15654
15655 if (uj)
15656 json = json_object_new_object();
15657
15658 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15659
15660 if (!bgp) {
15661 if (uj)
15662 vty_json(vty, json);
15663 else
15664 vty_out(vty, "%% BGP instance not found\n");
15665
15666 return CMD_WARNING;
15667 }
15668
15669 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15670 if (group_name) {
15671 if (strmatch(group->name, group_name)) {
15672 bgp_show_one_peer_group(vty, group, json);
15673 found = true;
15674 break;
15675 }
15676 } else {
15677 bgp_show_one_peer_group(vty, group, json);
15678 }
15679 }
15680
15681 if (group_name && !found && !uj)
15682 vty_out(vty, "%% No such peer-group\n");
15683
15684 if (uj)
15685 vty_json(vty, json);
15686
15687 return CMD_SUCCESS;
15688 }
15689
15690 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15691 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15692 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15693 "Detailed information on BGP peer groups\n"
15694 "Peer group name\n" JSON_STR)
15695 {
15696 char *vrf, *pg;
15697 int idx = 0;
15698 bool uj = use_json(argc, argv);
15699
15700 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15701 : NULL;
15702 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15703
15704 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15705 }
15706
15707
15708 /* Redistribute VTY commands. */
15709
15710 DEFUN (bgp_redistribute_ipv4,
15711 bgp_redistribute_ipv4_cmd,
15712 "redistribute " FRR_IP_REDIST_STR_BGPD,
15713 "Redistribute information from another routing protocol\n"
15714 FRR_IP_REDIST_HELP_STR_BGPD)
15715 {
15716 VTY_DECLVAR_CONTEXT(bgp, bgp);
15717 int idx_protocol = 1;
15718 int type;
15719
15720 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15721 if (type < 0) {
15722 vty_out(vty, "%% Invalid route type\n");
15723 return CMD_WARNING_CONFIG_FAILED;
15724 }
15725
15726 bgp_redist_add(bgp, AFI_IP, type, 0);
15727 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15728 }
15729
15730 ALIAS_HIDDEN(
15731 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15732 "redistribute " FRR_IP_REDIST_STR_BGPD,
15733 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15734
15735 DEFUN (bgp_redistribute_ipv4_rmap,
15736 bgp_redistribute_ipv4_rmap_cmd,
15737 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15738 "Redistribute information from another routing protocol\n"
15739 FRR_IP_REDIST_HELP_STR_BGPD
15740 "Route map reference\n"
15741 "Pointer to route-map entries\n")
15742 {
15743 VTY_DECLVAR_CONTEXT(bgp, bgp);
15744 int idx_protocol = 1;
15745 int idx_word = 3;
15746 int type;
15747 struct bgp_redist *red;
15748 bool changed;
15749 struct route_map *route_map = route_map_lookup_warn_noexist(
15750 vty, argv[idx_word]->arg);
15751
15752 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15753 if (type < 0) {
15754 vty_out(vty, "%% Invalid route type\n");
15755 return CMD_WARNING_CONFIG_FAILED;
15756 }
15757
15758 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15759 changed =
15760 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15761 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15762 }
15763
15764 ALIAS_HIDDEN(
15765 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15766 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15767 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15768 "Route map reference\n"
15769 "Pointer to route-map entries\n")
15770
15771 DEFUN (bgp_redistribute_ipv4_metric,
15772 bgp_redistribute_ipv4_metric_cmd,
15773 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15774 "Redistribute information from another routing protocol\n"
15775 FRR_IP_REDIST_HELP_STR_BGPD
15776 "Metric for redistributed routes\n"
15777 "Default metric\n")
15778 {
15779 VTY_DECLVAR_CONTEXT(bgp, bgp);
15780 int idx_protocol = 1;
15781 int idx_number = 3;
15782 int type;
15783 uint32_t metric;
15784 struct bgp_redist *red;
15785 bool changed;
15786
15787 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15788 if (type < 0) {
15789 vty_out(vty, "%% Invalid route type\n");
15790 return CMD_WARNING_CONFIG_FAILED;
15791 }
15792 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15793
15794 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15795 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15796 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15797 }
15798
15799 ALIAS_HIDDEN(
15800 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15801 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15802 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15803 "Metric for redistributed routes\n"
15804 "Default metric\n")
15805
15806 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15807 bgp_redistribute_ipv4_rmap_metric_cmd,
15808 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15809 "Redistribute information from another routing protocol\n"
15810 FRR_IP_REDIST_HELP_STR_BGPD
15811 "Route map reference\n"
15812 "Pointer to route-map entries\n"
15813 "Metric for redistributed routes\n"
15814 "Default metric\n")
15815 {
15816 VTY_DECLVAR_CONTEXT(bgp, bgp);
15817 int idx_protocol = 1;
15818 int idx_word = 3;
15819 int idx_number = 5;
15820 int type;
15821 uint32_t metric;
15822 struct bgp_redist *red;
15823 bool changed;
15824 struct route_map *route_map =
15825 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15826
15827 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15828 if (type < 0) {
15829 vty_out(vty, "%% Invalid route type\n");
15830 return CMD_WARNING_CONFIG_FAILED;
15831 }
15832 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15833
15834 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15835 changed =
15836 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15837 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15838 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15839 }
15840
15841 ALIAS_HIDDEN(
15842 bgp_redistribute_ipv4_rmap_metric,
15843 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15844 "redistribute " FRR_IP_REDIST_STR_BGPD
15845 " route-map RMAP_NAME metric (0-4294967295)",
15846 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15847 "Route map reference\n"
15848 "Pointer to route-map entries\n"
15849 "Metric for redistributed routes\n"
15850 "Default metric\n")
15851
15852 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15853 bgp_redistribute_ipv4_metric_rmap_cmd,
15854 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15855 "Redistribute information from another routing protocol\n"
15856 FRR_IP_REDIST_HELP_STR_BGPD
15857 "Metric for redistributed routes\n"
15858 "Default metric\n"
15859 "Route map reference\n"
15860 "Pointer to route-map entries\n")
15861 {
15862 VTY_DECLVAR_CONTEXT(bgp, bgp);
15863 int idx_protocol = 1;
15864 int idx_number = 3;
15865 int idx_word = 5;
15866 int type;
15867 uint32_t metric;
15868 struct bgp_redist *red;
15869 bool changed;
15870 struct route_map *route_map =
15871 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15872
15873 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15874 if (type < 0) {
15875 vty_out(vty, "%% Invalid route type\n");
15876 return CMD_WARNING_CONFIG_FAILED;
15877 }
15878 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15879
15880 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15881 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15882 changed |=
15883 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15884 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15885 }
15886
15887 ALIAS_HIDDEN(
15888 bgp_redistribute_ipv4_metric_rmap,
15889 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15890 "redistribute " FRR_IP_REDIST_STR_BGPD
15891 " metric (0-4294967295) route-map RMAP_NAME",
15892 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15893 "Metric for redistributed routes\n"
15894 "Default metric\n"
15895 "Route map reference\n"
15896 "Pointer to route-map entries\n")
15897
15898 DEFUN (bgp_redistribute_ipv4_ospf,
15899 bgp_redistribute_ipv4_ospf_cmd,
15900 "redistribute <ospf|table> (1-65535)",
15901 "Redistribute information from another routing protocol\n"
15902 "Open Shortest Path First (OSPFv2)\n"
15903 "Non-main Kernel Routing Table\n"
15904 "Instance ID/Table ID\n")
15905 {
15906 VTY_DECLVAR_CONTEXT(bgp, bgp);
15907 int idx_ospf_table = 1;
15908 int idx_number = 2;
15909 unsigned short instance;
15910 unsigned short protocol;
15911
15912 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15913
15914 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15915 protocol = ZEBRA_ROUTE_OSPF;
15916 else
15917 protocol = ZEBRA_ROUTE_TABLE;
15918
15919 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15920 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15921 }
15922
15923 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15924 "redistribute <ospf|table> (1-65535)",
15925 "Redistribute information from another routing protocol\n"
15926 "Open Shortest Path First (OSPFv2)\n"
15927 "Non-main Kernel Routing Table\n"
15928 "Instance ID/Table ID\n")
15929
15930 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15931 bgp_redistribute_ipv4_ospf_rmap_cmd,
15932 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15933 "Redistribute information from another routing protocol\n"
15934 "Open Shortest Path First (OSPFv2)\n"
15935 "Non-main Kernel Routing Table\n"
15936 "Instance ID/Table ID\n"
15937 "Route map reference\n"
15938 "Pointer to route-map entries\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 struct bgp_redist *red;
15945 unsigned short instance;
15946 int protocol;
15947 bool changed;
15948 struct route_map *route_map =
15949 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15950
15951 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15952 protocol = ZEBRA_ROUTE_OSPF;
15953 else
15954 protocol = ZEBRA_ROUTE_TABLE;
15955
15956 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15957 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15958 changed =
15959 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15960 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15961 }
15962
15963 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15964 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15965 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15966 "Redistribute information from another routing protocol\n"
15967 "Open Shortest Path First (OSPFv2)\n"
15968 "Non-main Kernel Routing Table\n"
15969 "Instance ID/Table ID\n"
15970 "Route map reference\n"
15971 "Pointer to route-map entries\n")
15972
15973 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15974 bgp_redistribute_ipv4_ospf_metric_cmd,
15975 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15976 "Redistribute information from another routing protocol\n"
15977 "Open Shortest Path First (OSPFv2)\n"
15978 "Non-main Kernel Routing Table\n"
15979 "Instance ID/Table ID\n"
15980 "Metric for redistributed routes\n"
15981 "Default metric\n")
15982 {
15983 VTY_DECLVAR_CONTEXT(bgp, bgp);
15984 int idx_ospf_table = 1;
15985 int idx_number = 2;
15986 int idx_number_2 = 4;
15987 uint32_t metric;
15988 struct bgp_redist *red;
15989 unsigned short instance;
15990 int protocol;
15991 bool changed;
15992
15993 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15994 protocol = ZEBRA_ROUTE_OSPF;
15995 else
15996 protocol = ZEBRA_ROUTE_TABLE;
15997
15998 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15999 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16000
16001 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16002 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16003 metric);
16004 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16005 }
16006
16007 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16008 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16009 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16010 "Redistribute information from another routing protocol\n"
16011 "Open Shortest Path First (OSPFv2)\n"
16012 "Non-main Kernel Routing Table\n"
16013 "Instance ID/Table ID\n"
16014 "Metric for redistributed routes\n"
16015 "Default metric\n")
16016
16017 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16018 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16019 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16020 "Redistribute information from another routing protocol\n"
16021 "Open Shortest Path First (OSPFv2)\n"
16022 "Non-main Kernel Routing Table\n"
16023 "Instance ID/Table ID\n"
16024 "Route map reference\n"
16025 "Pointer to route-map entries\n"
16026 "Metric for redistributed routes\n"
16027 "Default metric\n")
16028 {
16029 VTY_DECLVAR_CONTEXT(bgp, bgp);
16030 int idx_ospf_table = 1;
16031 int idx_number = 2;
16032 int idx_word = 4;
16033 int idx_number_2 = 6;
16034 uint32_t metric;
16035 struct bgp_redist *red;
16036 unsigned short instance;
16037 int protocol;
16038 bool changed;
16039 struct route_map *route_map =
16040 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16041
16042 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16043 protocol = ZEBRA_ROUTE_OSPF;
16044 else
16045 protocol = ZEBRA_ROUTE_TABLE;
16046
16047 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16048 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16049
16050 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16051 changed =
16052 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16053 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16054 metric);
16055 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16056 }
16057
16058 ALIAS_HIDDEN(
16059 bgp_redistribute_ipv4_ospf_rmap_metric,
16060 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16061 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16062 "Redistribute information from another routing protocol\n"
16063 "Open Shortest Path First (OSPFv2)\n"
16064 "Non-main Kernel Routing Table\n"
16065 "Instance ID/Table ID\n"
16066 "Route map reference\n"
16067 "Pointer to route-map entries\n"
16068 "Metric for redistributed routes\n"
16069 "Default metric\n")
16070
16071 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16072 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16073 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16074 "Redistribute information from another routing protocol\n"
16075 "Open Shortest Path First (OSPFv2)\n"
16076 "Non-main Kernel Routing Table\n"
16077 "Instance ID/Table ID\n"
16078 "Metric for redistributed routes\n"
16079 "Default metric\n"
16080 "Route map reference\n"
16081 "Pointer to route-map entries\n")
16082 {
16083 VTY_DECLVAR_CONTEXT(bgp, bgp);
16084 int idx_ospf_table = 1;
16085 int idx_number = 2;
16086 int idx_number_2 = 4;
16087 int idx_word = 6;
16088 uint32_t metric;
16089 struct bgp_redist *red;
16090 unsigned short instance;
16091 int protocol;
16092 bool changed;
16093 struct route_map *route_map =
16094 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16095
16096 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16097 protocol = ZEBRA_ROUTE_OSPF;
16098 else
16099 protocol = ZEBRA_ROUTE_TABLE;
16100
16101 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16102 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16103
16104 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16105 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16106 metric);
16107 changed |=
16108 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16109 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16110 }
16111
16112 ALIAS_HIDDEN(
16113 bgp_redistribute_ipv4_ospf_metric_rmap,
16114 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16115 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16116 "Redistribute information from another routing protocol\n"
16117 "Open Shortest Path First (OSPFv2)\n"
16118 "Non-main Kernel Routing Table\n"
16119 "Instance ID/Table ID\n"
16120 "Metric for redistributed routes\n"
16121 "Default metric\n"
16122 "Route map reference\n"
16123 "Pointer to route-map entries\n")
16124
16125 DEFUN (no_bgp_redistribute_ipv4_ospf,
16126 no_bgp_redistribute_ipv4_ospf_cmd,
16127 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16128 NO_STR
16129 "Redistribute information from another routing protocol\n"
16130 "Open Shortest Path First (OSPFv2)\n"
16131 "Non-main Kernel Routing Table\n"
16132 "Instance ID/Table ID\n"
16133 "Metric for redistributed routes\n"
16134 "Default metric\n"
16135 "Route map reference\n"
16136 "Pointer to route-map entries\n")
16137 {
16138 VTY_DECLVAR_CONTEXT(bgp, bgp);
16139 int idx_ospf_table = 2;
16140 int idx_number = 3;
16141 unsigned short instance;
16142 int protocol;
16143
16144 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16145 protocol = ZEBRA_ROUTE_OSPF;
16146 else
16147 protocol = ZEBRA_ROUTE_TABLE;
16148
16149 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16150 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16151 }
16152
16153 ALIAS_HIDDEN(
16154 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16155 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16156 NO_STR
16157 "Redistribute information from another routing protocol\n"
16158 "Open Shortest Path First (OSPFv2)\n"
16159 "Non-main Kernel Routing Table\n"
16160 "Instance ID/Table ID\n"
16161 "Metric for redistributed routes\n"
16162 "Default metric\n"
16163 "Route map reference\n"
16164 "Pointer to route-map entries\n")
16165
16166 DEFUN (no_bgp_redistribute_ipv4,
16167 no_bgp_redistribute_ipv4_cmd,
16168 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16169 NO_STR
16170 "Redistribute information from another routing protocol\n"
16171 FRR_IP_REDIST_HELP_STR_BGPD
16172 "Metric for redistributed routes\n"
16173 "Default metric\n"
16174 "Route map reference\n"
16175 "Pointer to route-map entries\n")
16176 {
16177 VTY_DECLVAR_CONTEXT(bgp, bgp);
16178 int idx_protocol = 2;
16179 int type;
16180
16181 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16182 if (type < 0) {
16183 vty_out(vty, "%% Invalid route type\n");
16184 return CMD_WARNING_CONFIG_FAILED;
16185 }
16186 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16187 }
16188
16189 ALIAS_HIDDEN(
16190 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16191 "no redistribute " FRR_IP_REDIST_STR_BGPD
16192 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16193 NO_STR
16194 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16195 "Metric for redistributed routes\n"
16196 "Default metric\n"
16197 "Route map reference\n"
16198 "Pointer to route-map entries\n")
16199
16200 DEFUN (bgp_redistribute_ipv6,
16201 bgp_redistribute_ipv6_cmd,
16202 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16203 "Redistribute information from another routing protocol\n"
16204 FRR_IP6_REDIST_HELP_STR_BGPD)
16205 {
16206 VTY_DECLVAR_CONTEXT(bgp, bgp);
16207 int idx_protocol = 1;
16208 int type;
16209
16210 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16211 if (type < 0) {
16212 vty_out(vty, "%% Invalid route type\n");
16213 return CMD_WARNING_CONFIG_FAILED;
16214 }
16215
16216 bgp_redist_add(bgp, AFI_IP6, type, 0);
16217 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16218 }
16219
16220 DEFUN (bgp_redistribute_ipv6_rmap,
16221 bgp_redistribute_ipv6_rmap_cmd,
16222 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16223 "Redistribute information from another routing protocol\n"
16224 FRR_IP6_REDIST_HELP_STR_BGPD
16225 "Route map reference\n"
16226 "Pointer to route-map entries\n")
16227 {
16228 VTY_DECLVAR_CONTEXT(bgp, bgp);
16229 int idx_protocol = 1;
16230 int idx_word = 3;
16231 int type;
16232 struct bgp_redist *red;
16233 bool changed;
16234 struct route_map *route_map =
16235 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16236
16237 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16238 if (type < 0) {
16239 vty_out(vty, "%% Invalid route type\n");
16240 return CMD_WARNING_CONFIG_FAILED;
16241 }
16242
16243 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16244 changed =
16245 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16246 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16247 }
16248
16249 DEFUN (bgp_redistribute_ipv6_metric,
16250 bgp_redistribute_ipv6_metric_cmd,
16251 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16252 "Redistribute information from another routing protocol\n"
16253 FRR_IP6_REDIST_HELP_STR_BGPD
16254 "Metric for redistributed routes\n"
16255 "Default metric\n")
16256 {
16257 VTY_DECLVAR_CONTEXT(bgp, bgp);
16258 int idx_protocol = 1;
16259 int idx_number = 3;
16260 int type;
16261 uint32_t metric;
16262 struct bgp_redist *red;
16263 bool changed;
16264
16265 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16266 if (type < 0) {
16267 vty_out(vty, "%% Invalid route type\n");
16268 return CMD_WARNING_CONFIG_FAILED;
16269 }
16270 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16271
16272 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16273 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16274 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16275 }
16276
16277 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16278 bgp_redistribute_ipv6_rmap_metric_cmd,
16279 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16280 "Redistribute information from another routing protocol\n"
16281 FRR_IP6_REDIST_HELP_STR_BGPD
16282 "Route map reference\n"
16283 "Pointer to route-map entries\n"
16284 "Metric for redistributed routes\n"
16285 "Default metric\n")
16286 {
16287 VTY_DECLVAR_CONTEXT(bgp, bgp);
16288 int idx_protocol = 1;
16289 int idx_word = 3;
16290 int idx_number = 5;
16291 int type;
16292 uint32_t metric;
16293 struct bgp_redist *red;
16294 bool changed;
16295 struct route_map *route_map =
16296 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16297
16298 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16299 if (type < 0) {
16300 vty_out(vty, "%% Invalid route type\n");
16301 return CMD_WARNING_CONFIG_FAILED;
16302 }
16303 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16304
16305 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16306 changed =
16307 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16308 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16309 metric);
16310 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16311 }
16312
16313 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16314 bgp_redistribute_ipv6_metric_rmap_cmd,
16315 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16316 "Redistribute information from another routing protocol\n"
16317 FRR_IP6_REDIST_HELP_STR_BGPD
16318 "Metric for redistributed routes\n"
16319 "Default metric\n"
16320 "Route map reference\n"
16321 "Pointer to route-map entries\n")
16322 {
16323 VTY_DECLVAR_CONTEXT(bgp, bgp);
16324 int idx_protocol = 1;
16325 int idx_number = 3;
16326 int idx_word = 5;
16327 int type;
16328 uint32_t metric;
16329 struct bgp_redist *red;
16330 bool changed;
16331 struct route_map *route_map =
16332 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16333
16334 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16335 if (type < 0) {
16336 vty_out(vty, "%% Invalid route type\n");
16337 return CMD_WARNING_CONFIG_FAILED;
16338 }
16339 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16340
16341 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16342 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16343 metric);
16344 changed |=
16345 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16346 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16347 }
16348
16349 DEFUN (no_bgp_redistribute_ipv6,
16350 no_bgp_redistribute_ipv6_cmd,
16351 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16352 NO_STR
16353 "Redistribute information from another routing protocol\n"
16354 FRR_IP6_REDIST_HELP_STR_BGPD
16355 "Metric for redistributed routes\n"
16356 "Default metric\n"
16357 "Route map reference\n"
16358 "Pointer to route-map entries\n")
16359 {
16360 VTY_DECLVAR_CONTEXT(bgp, bgp);
16361 int idx_protocol = 2;
16362 int type;
16363
16364 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16365 if (type < 0) {
16366 vty_out(vty, "%% Invalid route type\n");
16367 return CMD_WARNING_CONFIG_FAILED;
16368 }
16369
16370 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16371 }
16372
16373 /* Neighbor update tcp-mss. */
16374 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16375 const char *tcp_mss_str)
16376 {
16377 struct peer *peer;
16378 uint32_t tcp_mss_val = 0;
16379
16380 peer = peer_and_group_lookup_vty(vty, peer_str);
16381 if (!peer)
16382 return CMD_WARNING_CONFIG_FAILED;
16383
16384 if (tcp_mss_str) {
16385 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16386 peer_tcp_mss_set(peer, tcp_mss_val);
16387 } else {
16388 peer_tcp_mss_unset(peer);
16389 }
16390
16391 return CMD_SUCCESS;
16392 }
16393
16394 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16395 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16396 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16397 "TCP max segment size\n"
16398 "TCP MSS value\n")
16399 {
16400 int peer_index = 1;
16401 int mss_index = 3;
16402
16403 vty_out(vty,
16404 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16405 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16406 argv[mss_index]->arg);
16407 }
16408
16409 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16410 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16411 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16412 "TCP max segment size\n"
16413 "TCP MSS value\n")
16414 {
16415 int peer_index = 2;
16416
16417 vty_out(vty,
16418 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16419 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16420 }
16421
16422 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16423 "[no$no] bgp retain route-target all",
16424 NO_STR BGP_STR
16425 "Retain BGP updates\n"
16426 "Retain BGP updates based on route-target values\n"
16427 "Retain all BGP updates\n")
16428 {
16429 bool check;
16430 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16431
16432 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16433 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16434 if (check != !no) {
16435 if (!no)
16436 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16437 [bgp_node_safi(vty)],
16438 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16439 else
16440 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16441 [bgp_node_safi(vty)],
16442 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16443 /* trigger a flush to re-sync with ADJ-RIB-in */
16444 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16445 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16446 }
16447 return CMD_SUCCESS;
16448 }
16449
16450 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16451 afi_t afi, safi_t safi)
16452 {
16453 int i;
16454
16455 /* Unicast redistribution only. */
16456 if (safi != SAFI_UNICAST)
16457 return;
16458
16459 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16460 /* Redistribute BGP does not make sense. */
16461 if (i != ZEBRA_ROUTE_BGP) {
16462 struct list *red_list;
16463 struct listnode *node;
16464 struct bgp_redist *red;
16465
16466 red_list = bgp->redist[afi][i];
16467 if (!red_list)
16468 continue;
16469
16470 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16471 /* "redistribute" configuration. */
16472 vty_out(vty, " redistribute %s",
16473 zebra_route_string(i));
16474 if (red->instance)
16475 vty_out(vty, " %d", red->instance);
16476 if (red->redist_metric_flag)
16477 vty_out(vty, " metric %u",
16478 red->redist_metric);
16479 if (red->rmap.name)
16480 vty_out(vty, " route-map %s",
16481 red->rmap.name);
16482 vty_out(vty, "\n");
16483 }
16484 }
16485 }
16486 }
16487
16488 /* peer-group helpers for config-write */
16489
16490 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16491 {
16492 if (!peer_group_active(peer)) {
16493 if (CHECK_FLAG(peer->flags_invert, flag))
16494 return !CHECK_FLAG(peer->flags, flag);
16495 else
16496 return !!CHECK_FLAG(peer->flags, flag);
16497 }
16498
16499 return !!CHECK_FLAG(peer->flags_override, flag);
16500 }
16501
16502 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16503 uint64_t flag)
16504 {
16505 if (!peer_group_active(peer)) {
16506 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16507 return !peer_af_flag_check(peer, afi, safi, flag);
16508 else
16509 return !!peer_af_flag_check(peer, afi, safi, flag);
16510 }
16511
16512 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16513 }
16514
16515 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16516 uint8_t type, int direct)
16517 {
16518 struct bgp_filter *filter;
16519
16520 if (peer_group_active(peer))
16521 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16522 type);
16523
16524 filter = &peer->filter[afi][safi];
16525 switch (type) {
16526 case PEER_FT_DISTRIBUTE_LIST:
16527 return !!(filter->dlist[direct].name);
16528 case PEER_FT_FILTER_LIST:
16529 return !!(filter->aslist[direct].name);
16530 case PEER_FT_PREFIX_LIST:
16531 return !!(filter->plist[direct].name);
16532 case PEER_FT_ROUTE_MAP:
16533 return !!(filter->map[direct].name);
16534 case PEER_FT_UNSUPPRESS_MAP:
16535 return !!(filter->usmap.name);
16536 case PEER_FT_ADVERTISE_MAP:
16537 return !!(filter->advmap.aname
16538 && ((filter->advmap.condition == direct)
16539 && filter->advmap.cname));
16540 default:
16541 return false;
16542 }
16543 }
16544
16545 /* Return true if the addpath type is set for peer and different from
16546 * peer-group.
16547 */
16548 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16549 safi_t safi)
16550 {
16551 enum bgp_addpath_strat type, g_type;
16552
16553 type = peer->addpath_type[afi][safi];
16554
16555 if (type != BGP_ADDPATH_NONE) {
16556 if (peer_group_active(peer)) {
16557 g_type = peer->group->conf->addpath_type[afi][safi];
16558
16559 if (type != g_type)
16560 return true;
16561 else
16562 return false;
16563 }
16564
16565 return true;
16566 }
16567
16568 return false;
16569 }
16570
16571 /* This is part of the address-family block (unicast only) */
16572 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16573 afi_t afi)
16574 {
16575 int indent = 2;
16576 uint32_t tovpn_sid_index = 0;
16577
16578 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16579 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16580 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16581 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16582 bgp->vpn_policy[afi]
16583 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16584 else
16585 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16586 bgp->vpn_policy[afi]
16587 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16588 }
16589 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16590 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16591 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16592 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16593 return;
16594
16595 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16596 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16597
16598 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16599
16600 } else {
16601 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16602 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16603 bgp->vpn_policy[afi].tovpn_label);
16604 }
16605 }
16606
16607 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16608 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16609 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16610 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16611 } else if (tovpn_sid_index != 0) {
16612 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16613 tovpn_sid_index);
16614 }
16615
16616 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16617 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16618 &bgp->vpn_policy[afi].tovpn_rd);
16619
16620 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16621 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16622
16623 char buf[PREFIX_STRLEN];
16624 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16625 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16626 sizeof(buf))) {
16627
16628 vty_out(vty, "%*snexthop vpn export %s\n",
16629 indent, "", buf);
16630 }
16631 }
16632 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16633 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16634 && ecommunity_cmp(
16635 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16636 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16637
16638 char *b = ecommunity_ecom2str(
16639 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16640 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16641 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16642 XFREE(MTYPE_ECOMMUNITY_STR, b);
16643 } else {
16644 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16645 char *b = ecommunity_ecom2str(
16646 bgp->vpn_policy[afi]
16647 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16648 ECOMMUNITY_FORMAT_ROUTE_MAP,
16649 ECOMMUNITY_ROUTE_TARGET);
16650 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16651 XFREE(MTYPE_ECOMMUNITY_STR, b);
16652 }
16653 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16654 char *b = ecommunity_ecom2str(
16655 bgp->vpn_policy[afi]
16656 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16657 ECOMMUNITY_FORMAT_ROUTE_MAP,
16658 ECOMMUNITY_ROUTE_TARGET);
16659 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16660 XFREE(MTYPE_ECOMMUNITY_STR, b);
16661 }
16662 }
16663
16664 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16665 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16666 bgp->vpn_policy[afi]
16667 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16668
16669 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16670 char *b = ecommunity_ecom2str(
16671 bgp->vpn_policy[afi]
16672 .import_redirect_rtlist,
16673 ECOMMUNITY_FORMAT_ROUTE_MAP,
16674 ECOMMUNITY_ROUTE_TARGET);
16675
16676 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16677 != ECOMMUNITY_SIZE)
16678 vty_out(vty, "%*srt6 redirect import %s\n",
16679 indent, "", b);
16680 else
16681 vty_out(vty, "%*srt redirect import %s\n",
16682 indent, "", b);
16683 XFREE(MTYPE_ECOMMUNITY_STR, b);
16684 }
16685 }
16686
16687 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16688 afi_t afi, safi_t safi)
16689 {
16690 struct bgp_filter *filter;
16691 char *addr;
16692
16693 addr = peer->host;
16694 filter = &peer->filter[afi][safi];
16695
16696 /* distribute-list. */
16697 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16698 FILTER_IN))
16699 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16700 filter->dlist[FILTER_IN].name);
16701
16702 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16703 FILTER_OUT))
16704 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16705 filter->dlist[FILTER_OUT].name);
16706
16707 /* prefix-list. */
16708 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16709 FILTER_IN))
16710 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16711 filter->plist[FILTER_IN].name);
16712
16713 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16714 FILTER_OUT))
16715 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16716 filter->plist[FILTER_OUT].name);
16717
16718 /* route-map. */
16719 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16720 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16721 filter->map[RMAP_IN].name);
16722
16723 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16724 RMAP_OUT))
16725 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16726 filter->map[RMAP_OUT].name);
16727
16728 /* unsuppress-map */
16729 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16730 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16731 filter->usmap.name);
16732
16733 /* advertise-map : always applied in OUT direction*/
16734 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16735 CONDITION_NON_EXIST))
16736 vty_out(vty,
16737 " neighbor %s advertise-map %s non-exist-map %s\n",
16738 addr, filter->advmap.aname, filter->advmap.cname);
16739
16740 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16741 CONDITION_EXIST))
16742 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16743 addr, filter->advmap.aname, filter->advmap.cname);
16744
16745 /* filter-list. */
16746 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16747 FILTER_IN))
16748 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16749 filter->aslist[FILTER_IN].name);
16750
16751 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16752 FILTER_OUT))
16753 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16754 filter->aslist[FILTER_OUT].name);
16755 }
16756
16757 /* BGP peer configuration display function. */
16758 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16759 struct peer *peer)
16760 {
16761 struct peer *g_peer = NULL;
16762 char *addr;
16763 int if_pg_printed = false;
16764 int if_ras_printed = false;
16765
16766 /* Skip dynamic neighbors. */
16767 if (peer_dynamic_neighbor(peer))
16768 return;
16769
16770 if (peer->conf_if)
16771 addr = peer->conf_if;
16772 else
16773 addr = peer->host;
16774
16775 /************************************
16776 ****** Global to the neighbor ******
16777 ************************************/
16778 if (peer->conf_if) {
16779 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16780 vty_out(vty, " neighbor %s interface v6only", addr);
16781 else
16782 vty_out(vty, " neighbor %s interface", addr);
16783
16784 if (peer_group_active(peer)) {
16785 vty_out(vty, " peer-group %s", peer->group->name);
16786 if_pg_printed = true;
16787 } else if (peer->as_type == AS_SPECIFIED) {
16788 vty_out(vty, " remote-as %u", peer->as);
16789 if_ras_printed = true;
16790 } else if (peer->as_type == AS_INTERNAL) {
16791 vty_out(vty, " remote-as internal");
16792 if_ras_printed = true;
16793 } else if (peer->as_type == AS_EXTERNAL) {
16794 vty_out(vty, " remote-as external");
16795 if_ras_printed = true;
16796 }
16797
16798 vty_out(vty, "\n");
16799 }
16800
16801 /* remote-as and peer-group */
16802 /* peer is a member of a peer-group */
16803 if (peer_group_active(peer)) {
16804 g_peer = peer->group->conf;
16805
16806 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16807 if (peer->as_type == AS_SPECIFIED) {
16808 vty_out(vty, " neighbor %s remote-as %u\n",
16809 addr, peer->as);
16810 } else if (peer->as_type == AS_INTERNAL) {
16811 vty_out(vty,
16812 " neighbor %s remote-as internal\n",
16813 addr);
16814 } else if (peer->as_type == AS_EXTERNAL) {
16815 vty_out(vty,
16816 " neighbor %s remote-as external\n",
16817 addr);
16818 }
16819 }
16820
16821 /* For swpX peers we displayed the peer-group
16822 * via 'neighbor swpX interface peer-group PGNAME' */
16823 if (!if_pg_printed)
16824 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16825 peer->group->name);
16826 }
16827
16828 /* peer is NOT a member of a peer-group */
16829 else {
16830 /* peer is a peer-group, declare the peer-group */
16831 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16832 vty_out(vty, " neighbor %s peer-group\n", addr);
16833 }
16834
16835 if (!if_ras_printed) {
16836 if (peer->as_type == AS_SPECIFIED) {
16837 vty_out(vty, " neighbor %s remote-as %u\n",
16838 addr, peer->as);
16839 } else if (peer->as_type == AS_INTERNAL) {
16840 vty_out(vty,
16841 " neighbor %s remote-as internal\n",
16842 addr);
16843 } else if (peer->as_type == AS_EXTERNAL) {
16844 vty_out(vty,
16845 " neighbor %s remote-as external\n",
16846 addr);
16847 }
16848 }
16849 }
16850
16851 /* local-as */
16852 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16853 vty_out(vty, " neighbor %s local-as %u", addr,
16854 peer->change_local_as);
16855 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16856 vty_out(vty, " no-prepend");
16857 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16858 vty_out(vty, " replace-as");
16859 vty_out(vty, "\n");
16860 }
16861
16862 /* description */
16863 if (peer->desc) {
16864 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16865 }
16866
16867 /* shutdown */
16868 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16869 if (peer->tx_shutdown_message)
16870 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16871 peer->tx_shutdown_message);
16872 else
16873 vty_out(vty, " neighbor %s shutdown\n", addr);
16874 }
16875
16876 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16877 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16878 peer->rtt_expected, peer->rtt_keepalive_conf);
16879
16880 /* bfd */
16881 if (peer->bfd_config)
16882 bgp_bfd_peer_config_write(vty, peer, addr);
16883
16884 /* password */
16885 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16886 vty_out(vty, " neighbor %s password %s\n", addr,
16887 peer->password);
16888
16889 /* neighbor solo */
16890 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16891 if (!peer_group_active(peer)) {
16892 vty_out(vty, " neighbor %s solo\n", addr);
16893 }
16894 }
16895
16896 /* BGP port */
16897 if (peer->port != BGP_PORT_DEFAULT) {
16898 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16899 }
16900
16901 /* Local interface name */
16902 if (peer->ifname) {
16903 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16904 }
16905
16906 /* TCP max segment size */
16907 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16908 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16909
16910 /* passive */
16911 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16912 vty_out(vty, " neighbor %s passive\n", addr);
16913
16914 /* ebgp-multihop */
16915 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16916 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16917 && peer->ttl == MAXTTL)) {
16918 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16919 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16920 peer->ttl);
16921 }
16922 }
16923
16924 /* role */
16925 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16926 peer->local_role != ROLE_UNDEFINED)
16927 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16928 bgp_get_name_by_role(peer->local_role),
16929 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
16930 ? " strict-mode"
16931 : "");
16932
16933 /* ttl-security hops */
16934 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16935 if (!peer_group_active(peer)
16936 || g_peer->gtsm_hops != peer->gtsm_hops) {
16937 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16938 addr, peer->gtsm_hops);
16939 }
16940 }
16941
16942 /* disable-connected-check */
16943 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16944 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16945
16946 /* link-bw-encoding-ieee */
16947 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16948 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16949 addr);
16950
16951 /* extended-optional-parameters */
16952 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16953 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16954 addr);
16955
16956 /* enforce-first-as */
16957 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16958 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16959
16960 /* update-source */
16961 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16962 if (peer->update_source)
16963 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16964 peer->update_source);
16965 else if (peer->update_if)
16966 vty_out(vty, " neighbor %s update-source %s\n", addr,
16967 peer->update_if);
16968 }
16969
16970 /* advertisement-interval */
16971 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16972 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16973 peer->routeadv);
16974
16975 /* timers */
16976 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16977 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16978 peer->keepalive, peer->holdtime);
16979
16980 /* timers connect */
16981 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16982 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16983 peer->connect);
16984 /* need special-case handling for changed default values due to
16985 * config profile / version (because there is no "timers bgp connect"
16986 * command, we need to save this per-peer :/)
16987 */
16988 else if (!peer_group_active(peer) && !peer->connect &&
16989 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16990 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16991 peer->bgp->default_connect_retry);
16992
16993 /* timers delayopen */
16994 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16995 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16996 peer->delayopen);
16997 /* Save config even though flag is not set if default values have been
16998 * changed
16999 */
17000 else if (!peer_group_active(peer) && !peer->delayopen
17001 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17002 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17003 peer->bgp->default_delayopen);
17004
17005 /* capability dynamic */
17006 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17007 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17008
17009 /* capability extended-nexthop */
17010 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17011 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17012 !peer->conf_if)
17013 vty_out(vty,
17014 " no neighbor %s capability extended-nexthop\n",
17015 addr);
17016 else if (!peer->conf_if)
17017 vty_out(vty,
17018 " neighbor %s capability extended-nexthop\n",
17019 addr);
17020 }
17021
17022 /* dont-capability-negotiation */
17023 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17024 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17025
17026 /* override-capability */
17027 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17028 vty_out(vty, " neighbor %s override-capability\n", addr);
17029
17030 /* strict-capability-match */
17031 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17032 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17033
17034 /* Sender side AS path loop detection. */
17035 if (peer->as_path_loop_detection)
17036 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17037 addr);
17038
17039 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17040 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17041
17042 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17043 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17044 vty_out(vty,
17045 " neighbor %s graceful-restart-helper\n", addr);
17046 } else if (CHECK_FLAG(
17047 peer->peer_gr_new_status_flag,
17048 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17049 vty_out(vty,
17050 " neighbor %s graceful-restart\n", addr);
17051 } else if (
17052 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17053 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17054 && !(CHECK_FLAG(
17055 peer->peer_gr_new_status_flag,
17056 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17057 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17058 addr);
17059 }
17060 }
17061 }
17062
17063 /* BGP peer configuration display function. */
17064 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17065 struct peer *peer, afi_t afi, safi_t safi)
17066 {
17067 struct peer *g_peer = NULL;
17068 char *addr;
17069 bool flag_scomm, flag_secomm, flag_slcomm;
17070
17071 /* Skip dynamic neighbors. */
17072 if (peer_dynamic_neighbor(peer))
17073 return;
17074
17075 if (peer->conf_if)
17076 addr = peer->conf_if;
17077 else
17078 addr = peer->host;
17079
17080 /************************************
17081 ****** Per AF to the neighbor ******
17082 ************************************/
17083 if (peer_group_active(peer)) {
17084 g_peer = peer->group->conf;
17085
17086 /* If the peer-group is active but peer is not, print a 'no
17087 * activate' */
17088 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17089 vty_out(vty, " no neighbor %s activate\n", addr);
17090 }
17091
17092 /* If the peer-group is not active but peer is, print an
17093 'activate' */
17094 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17095 vty_out(vty, " neighbor %s activate\n", addr);
17096 }
17097 } else {
17098 if (peer->afc[afi][safi]) {
17099 if (safi == SAFI_ENCAP)
17100 vty_out(vty, " neighbor %s activate\n", addr);
17101 else if (!bgp->default_af[afi][safi])
17102 vty_out(vty, " neighbor %s activate\n", addr);
17103 } else {
17104 if (bgp->default_af[afi][safi])
17105 vty_out(vty, " no neighbor %s activate\n",
17106 addr);
17107 }
17108 }
17109
17110 /* addpath TX knobs */
17111 if (peergroup_af_addpath_check(peer, afi, safi)) {
17112 switch (peer->addpath_type[afi][safi]) {
17113 case BGP_ADDPATH_ALL:
17114 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17115 addr);
17116 break;
17117 case BGP_ADDPATH_BEST_PER_AS:
17118 vty_out(vty,
17119 " neighbor %s addpath-tx-bestpath-per-AS\n",
17120 addr);
17121 break;
17122 case BGP_ADDPATH_MAX:
17123 case BGP_ADDPATH_NONE:
17124 break;
17125 }
17126 }
17127
17128 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17129 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17130
17131 /* ORF capability. */
17132 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17133 || peergroup_af_flag_check(peer, afi, safi,
17134 PEER_FLAG_ORF_PREFIX_RM)) {
17135 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17136
17137 if (peergroup_af_flag_check(peer, afi, safi,
17138 PEER_FLAG_ORF_PREFIX_SM)
17139 && peergroup_af_flag_check(peer, afi, safi,
17140 PEER_FLAG_ORF_PREFIX_RM))
17141 vty_out(vty, " both");
17142 else if (peergroup_af_flag_check(peer, afi, safi,
17143 PEER_FLAG_ORF_PREFIX_SM))
17144 vty_out(vty, " send");
17145 else
17146 vty_out(vty, " receive");
17147 vty_out(vty, "\n");
17148 }
17149
17150 /* Route reflector client. */
17151 if (peergroup_af_flag_check(peer, afi, safi,
17152 PEER_FLAG_REFLECTOR_CLIENT)) {
17153 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17154 }
17155
17156 /* next-hop-self force */
17157 if (peergroup_af_flag_check(peer, afi, safi,
17158 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17159 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17160 }
17161
17162 /* next-hop-self */
17163 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17164 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17165 }
17166
17167 /* remove-private-AS */
17168 if (peergroup_af_flag_check(peer, afi, safi,
17169 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17170 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17171 addr);
17172 }
17173
17174 else if (peergroup_af_flag_check(peer, afi, safi,
17175 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17176 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17177 addr);
17178 }
17179
17180 else if (peergroup_af_flag_check(peer, afi, safi,
17181 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17182 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17183 }
17184
17185 else if (peergroup_af_flag_check(peer, afi, safi,
17186 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17187 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17188 }
17189
17190 /* as-override */
17191 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17192 vty_out(vty, " neighbor %s as-override\n", addr);
17193 }
17194
17195 /* send-community print. */
17196 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17197 PEER_FLAG_SEND_COMMUNITY);
17198 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17199 PEER_FLAG_SEND_EXT_COMMUNITY);
17200 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17201 PEER_FLAG_SEND_LARGE_COMMUNITY);
17202
17203 if (flag_scomm && flag_secomm && flag_slcomm) {
17204 vty_out(vty, " no neighbor %s send-community all\n", addr);
17205 } else {
17206 if (flag_scomm)
17207 vty_out(vty, " no neighbor %s send-community\n", addr);
17208 if (flag_secomm)
17209 vty_out(vty,
17210 " no neighbor %s send-community extended\n",
17211 addr);
17212
17213 if (flag_slcomm)
17214 vty_out(vty, " no neighbor %s send-community large\n",
17215 addr);
17216 }
17217
17218 /* Default information */
17219 if (peergroup_af_flag_check(peer, afi, safi,
17220 PEER_FLAG_DEFAULT_ORIGINATE)) {
17221 vty_out(vty, " neighbor %s default-originate", addr);
17222
17223 if (peer->default_rmap[afi][safi].name)
17224 vty_out(vty, " route-map %s",
17225 peer->default_rmap[afi][safi].name);
17226
17227 vty_out(vty, "\n");
17228 }
17229
17230 /* Soft reconfiguration inbound. */
17231 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17232 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17233 addr);
17234 }
17235
17236 /* maximum-prefix. */
17237 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17238 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17239 peer->pmax[afi][safi]);
17240
17241 if (peer->pmax_threshold[afi][safi]
17242 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17243 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17244 if (peer_af_flag_check(peer, afi, safi,
17245 PEER_FLAG_MAX_PREFIX_WARNING))
17246 vty_out(vty, " warning-only");
17247 if (peer->pmax_restart[afi][safi])
17248 vty_out(vty, " restart %u",
17249 peer->pmax_restart[afi][safi]);
17250 if (peer_af_flag_check(peer, afi, safi,
17251 PEER_FLAG_MAX_PREFIX_FORCE))
17252 vty_out(vty, " force");
17253
17254 vty_out(vty, "\n");
17255 }
17256
17257 /* maximum-prefix-out */
17258 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17259 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17260 addr, peer->pmax_out[afi][safi]);
17261
17262 /* Route server client. */
17263 if (peergroup_af_flag_check(peer, afi, safi,
17264 PEER_FLAG_RSERVER_CLIENT)) {
17265 vty_out(vty, " neighbor %s route-server-client\n", addr);
17266 }
17267
17268 /* Nexthop-local unchanged. */
17269 if (peergroup_af_flag_check(peer, afi, safi,
17270 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17271 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17272 }
17273
17274 /* allowas-in <1-10> */
17275 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17276 if (peer_af_flag_check(peer, afi, safi,
17277 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17278 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17279 } else if (peer->allowas_in[afi][safi] == 3) {
17280 vty_out(vty, " neighbor %s allowas-in\n", addr);
17281 } else {
17282 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17283 peer->allowas_in[afi][safi]);
17284 }
17285 }
17286
17287 /* soo */
17288 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17289 char *soo_str = ecommunity_ecom2str(
17290 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17291
17292 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17293 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17294 }
17295
17296 /* weight */
17297 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17298 vty_out(vty, " neighbor %s weight %lu\n", addr,
17299 peer->weight[afi][safi]);
17300
17301 /* Filter. */
17302 bgp_config_write_filter(vty, peer, afi, safi);
17303
17304 /* atribute-unchanged. */
17305 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17306 || (safi != SAFI_EVPN
17307 && peer_af_flag_check(peer, afi, safi,
17308 PEER_FLAG_NEXTHOP_UNCHANGED))
17309 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17310
17311 if (!peer_group_active(peer)
17312 || peergroup_af_flag_check(peer, afi, safi,
17313 PEER_FLAG_AS_PATH_UNCHANGED)
17314 || peergroup_af_flag_check(peer, afi, safi,
17315 PEER_FLAG_NEXTHOP_UNCHANGED)
17316 || peergroup_af_flag_check(peer, afi, safi,
17317 PEER_FLAG_MED_UNCHANGED)) {
17318
17319 vty_out(vty,
17320 " neighbor %s attribute-unchanged%s%s%s\n",
17321 addr,
17322 peer_af_flag_check(peer, afi, safi,
17323 PEER_FLAG_AS_PATH_UNCHANGED)
17324 ? " as-path"
17325 : "",
17326 peer_af_flag_check(peer, afi, safi,
17327 PEER_FLAG_NEXTHOP_UNCHANGED)
17328 ? " next-hop"
17329 : "",
17330 peer_af_flag_check(peer, afi, safi,
17331 PEER_FLAG_MED_UNCHANGED)
17332 ? " med"
17333 : "");
17334 }
17335 }
17336 }
17337
17338 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17339 safi_t safi)
17340 {
17341 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17342 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17343 vty_out(vty, " no bgp retain route-target all\n");
17344 }
17345
17346 /* Address family based peer configuration display. */
17347 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17348 safi_t safi)
17349 {
17350 struct peer *peer;
17351 struct peer_group *group;
17352 struct listnode *node, *nnode;
17353
17354
17355 vty_frame(vty, " !\n address-family ");
17356 if (afi == AFI_IP) {
17357 if (safi == SAFI_UNICAST)
17358 vty_frame(vty, "ipv4 unicast");
17359 else if (safi == SAFI_LABELED_UNICAST)
17360 vty_frame(vty, "ipv4 labeled-unicast");
17361 else if (safi == SAFI_MULTICAST)
17362 vty_frame(vty, "ipv4 multicast");
17363 else if (safi == SAFI_MPLS_VPN)
17364 vty_frame(vty, "ipv4 vpn");
17365 else if (safi == SAFI_ENCAP)
17366 vty_frame(vty, "ipv4 encap");
17367 else if (safi == SAFI_FLOWSPEC)
17368 vty_frame(vty, "ipv4 flowspec");
17369 } else if (afi == AFI_IP6) {
17370 if (safi == SAFI_UNICAST)
17371 vty_frame(vty, "ipv6 unicast");
17372 else if (safi == SAFI_LABELED_UNICAST)
17373 vty_frame(vty, "ipv6 labeled-unicast");
17374 else if (safi == SAFI_MULTICAST)
17375 vty_frame(vty, "ipv6 multicast");
17376 else if (safi == SAFI_MPLS_VPN)
17377 vty_frame(vty, "ipv6 vpn");
17378 else if (safi == SAFI_ENCAP)
17379 vty_frame(vty, "ipv6 encap");
17380 else if (safi == SAFI_FLOWSPEC)
17381 vty_frame(vty, "ipv6 flowspec");
17382 } else if (afi == AFI_L2VPN) {
17383 if (safi == SAFI_EVPN)
17384 vty_frame(vty, "l2vpn evpn");
17385 }
17386 vty_frame(vty, "\n");
17387
17388 bgp_config_write_distance(vty, bgp, afi, safi);
17389
17390 bgp_config_write_network(vty, bgp, afi, safi);
17391
17392 bgp_config_write_redistribute(vty, bgp, afi, safi);
17393
17394 /* BGP flag dampening. */
17395 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17396 bgp_config_write_damp(vty, afi, safi);
17397
17398 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17399 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17400
17401 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17402 /* Do not display doppelganger peers */
17403 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17404 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17405 }
17406
17407 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17408 bgp_config_write_table_map(vty, bgp, afi, safi);
17409
17410 if (safi == SAFI_EVPN)
17411 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17412
17413 if (safi == SAFI_FLOWSPEC)
17414 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17415
17416 if (safi == SAFI_MPLS_VPN)
17417 bgp_vpn_config_write(vty, bgp, afi, safi);
17418
17419 if (safi == SAFI_UNICAST) {
17420 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17421 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17422 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17423
17424 vty_out(vty, " export vpn\n");
17425 }
17426 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17427 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17428
17429 vty_out(vty, " import vpn\n");
17430 }
17431 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17432 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17433 char *name;
17434
17435 for (ALL_LIST_ELEMENTS_RO(
17436 bgp->vpn_policy[afi].import_vrf, node,
17437 name))
17438 vty_out(vty, " import vrf %s\n", name);
17439 }
17440 }
17441
17442 vty_endframe(vty, " exit-address-family\n");
17443 }
17444
17445 int bgp_config_write(struct vty *vty)
17446 {
17447 struct bgp *bgp;
17448 struct peer_group *group;
17449 struct peer *peer;
17450 struct listnode *node, *nnode;
17451 struct listnode *mnode, *mnnode;
17452 afi_t afi;
17453 safi_t safi;
17454
17455 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17456 vty_out(vty, "bgp route-map delay-timer %u\n",
17457 bm->rmap_update_timer);
17458
17459 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17460 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17461 if (bm->v_update_delay != bm->v_establish_wait)
17462 vty_out(vty, " %d", bm->v_establish_wait);
17463 vty_out(vty, "\n");
17464 }
17465
17466 if (bm->wait_for_fib)
17467 vty_out(vty, "bgp suppress-fib-pending\n");
17468
17469 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17470 vty_out(vty, "bgp graceful-shutdown\n");
17471
17472 /* No-RIB (Zebra) option flag configuration */
17473 if (bgp_option_check(BGP_OPT_NO_FIB))
17474 vty_out(vty, "bgp no-rib\n");
17475
17476 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17477 vty_out(vty, "bgp send-extra-data zebra\n");
17478
17479 /* BGP session DSCP value */
17480 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17481 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17482
17483 /* BGP configuration. */
17484 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17485
17486 /* skip all auto created vrf as they dont have user config */
17487 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17488 continue;
17489
17490 /* Router bgp ASN */
17491 vty_out(vty, "router bgp %u", bgp->as);
17492
17493 if (bgp->name)
17494 vty_out(vty, " %s %s",
17495 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17496 ? "view" : "vrf", bgp->name);
17497 vty_out(vty, "\n");
17498
17499 /* BGP fast-external-failover. */
17500 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17501 vty_out(vty, " no bgp fast-external-failover\n");
17502
17503 /* BGP router ID. */
17504 if (bgp->router_id_static.s_addr != INADDR_ANY)
17505 vty_out(vty, " bgp router-id %pI4\n",
17506 &bgp->router_id_static);
17507
17508 /* Suppress fib pending */
17509 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17510 vty_out(vty, " bgp suppress-fib-pending\n");
17511
17512 /* BGP log-neighbor-changes. */
17513 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17514 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17515 vty_out(vty, " %sbgp log-neighbor-changes\n",
17516 CHECK_FLAG(bgp->flags,
17517 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17518 ? ""
17519 : "no ");
17520
17521 /* BGP configuration. */
17522 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17523 vty_out(vty, " bgp always-compare-med\n");
17524
17525 /* RFC8212 default eBGP policy. */
17526 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17527 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17528 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17529 CHECK_FLAG(bgp->flags,
17530 BGP_FLAG_EBGP_REQUIRES_POLICY)
17531 ? ""
17532 : "no ");
17533
17534 /* draft-ietf-idr-deprecate-as-set-confed-set */
17535 if (bgp->reject_as_sets)
17536 vty_out(vty, " bgp reject-as-sets\n");
17537
17538 /* Suppress duplicate updates if the route actually not changed
17539 */
17540 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17541 != SAVE_BGP_SUPPRESS_DUPLICATES)
17542 vty_out(vty, " %sbgp suppress-duplicates\n",
17543 CHECK_FLAG(bgp->flags,
17544 BGP_FLAG_SUPPRESS_DUPLICATES)
17545 ? ""
17546 : "no ");
17547
17548 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17549 */
17550 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17551 SAVE_BGP_HARD_ADMIN_RESET)
17552 vty_out(vty, " %sbgp hard-administrative-reset\n",
17553 CHECK_FLAG(bgp->flags,
17554 BGP_FLAG_HARD_ADMIN_RESET)
17555 ? ""
17556 : "no ");
17557
17558 /* BGP default <afi>-<safi> */
17559 FOREACH_AFI_SAFI (afi, safi) {
17560 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17561 if (!bgp->default_af[afi][safi])
17562 vty_out(vty, " no bgp default %s\n",
17563 get_bgp_default_af_flag(afi,
17564 safi));
17565 } else if (bgp->default_af[afi][safi])
17566 vty_out(vty, " bgp default %s\n",
17567 get_bgp_default_af_flag(afi, safi));
17568 }
17569
17570 /* BGP default local-preference. */
17571 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17572 vty_out(vty, " bgp default local-preference %u\n",
17573 bgp->default_local_pref);
17574
17575 /* BGP default show-hostname */
17576 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17577 != SAVE_BGP_SHOW_HOSTNAME)
17578 vty_out(vty, " %sbgp default show-hostname\n",
17579 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17580 ? ""
17581 : "no ");
17582
17583 /* BGP default show-nexthop-hostname */
17584 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17585 != SAVE_BGP_SHOW_HOSTNAME)
17586 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17587 CHECK_FLAG(bgp->flags,
17588 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17589 ? ""
17590 : "no ");
17591
17592 /* BGP default subgroup-pkt-queue-max. */
17593 if (bgp->default_subgroup_pkt_queue_max
17594 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17595 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17596 bgp->default_subgroup_pkt_queue_max);
17597
17598 /* BGP client-to-client reflection. */
17599 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17600 vty_out(vty, " no bgp client-to-client reflection\n");
17601
17602 /* BGP cluster ID. */
17603 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17604 vty_out(vty, " bgp cluster-id %pI4\n",
17605 &bgp->cluster_id);
17606
17607 /* Disable ebgp connected nexthop check */
17608 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17609 vty_out(vty,
17610 " bgp disable-ebgp-connected-route-check\n");
17611
17612 /* Confederation identifier*/
17613 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17614 vty_out(vty, " bgp confederation identifier %u\n",
17615 bgp->confed_id);
17616
17617 /* Confederation peer */
17618 if (bgp->confed_peers_cnt > 0) {
17619 int i;
17620
17621 vty_out(vty, " bgp confederation peers");
17622
17623 for (i = 0; i < bgp->confed_peers_cnt; i++)
17624 vty_out(vty, " %u", bgp->confed_peers[i]);
17625
17626 vty_out(vty, "\n");
17627 }
17628
17629 /* BGP deterministic-med. */
17630 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17631 != SAVE_BGP_DETERMINISTIC_MED)
17632 vty_out(vty, " %sbgp deterministic-med\n",
17633 CHECK_FLAG(bgp->flags,
17634 BGP_FLAG_DETERMINISTIC_MED)
17635 ? ""
17636 : "no ");
17637
17638 /* BGP update-delay. */
17639 bgp_config_write_update_delay(vty, bgp);
17640
17641 if (bgp->v_maxmed_onstartup
17642 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17643 vty_out(vty, " bgp max-med on-startup %u",
17644 bgp->v_maxmed_onstartup);
17645 if (bgp->maxmed_onstartup_value
17646 != BGP_MAXMED_VALUE_DEFAULT)
17647 vty_out(vty, " %u",
17648 bgp->maxmed_onstartup_value);
17649 vty_out(vty, "\n");
17650 }
17651 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17652 vty_out(vty, " bgp max-med administrative");
17653 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17654 vty_out(vty, " %u", bgp->maxmed_admin_value);
17655 vty_out(vty, "\n");
17656 }
17657
17658 /* write quanta */
17659 bgp_config_write_wpkt_quanta(vty, bgp);
17660 /* read quanta */
17661 bgp_config_write_rpkt_quanta(vty, bgp);
17662
17663 /* coalesce time */
17664 bgp_config_write_coalesce_time(vty, bgp);
17665
17666 /* BGP per-instance graceful-shutdown */
17667 /* BGP-wide settings and per-instance settings are mutually
17668 * exclusive.
17669 */
17670 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17671 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17672 vty_out(vty, " bgp graceful-shutdown\n");
17673
17674 /* Long-lived Graceful Restart */
17675 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17676 vty_out(vty,
17677 " bgp long-lived-graceful-restart stale-time %u\n",
17678 bgp->llgr_stale_time);
17679
17680 /* BGP graceful-restart. */
17681 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17682 vty_out(vty,
17683 " bgp graceful-restart stalepath-time %u\n",
17684 bgp->stalepath_time);
17685
17686 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17687 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17688 bgp->restart_time);
17689
17690 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17691 SAVE_BGP_GRACEFUL_NOTIFICATION)
17692 vty_out(vty, " %sbgp graceful-restart notification\n",
17693 CHECK_FLAG(bgp->flags,
17694 BGP_FLAG_GRACEFUL_NOTIFICATION)
17695 ? ""
17696 : "no ");
17697
17698 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17699 vty_out(vty,
17700 " bgp graceful-restart select-defer-time %u\n",
17701 bgp->select_defer_time);
17702
17703 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17704 vty_out(vty, " bgp graceful-restart\n");
17705
17706 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17707 vty_out(vty, " bgp graceful-restart-disable\n");
17708
17709 /* BGP graceful-restart Preserve State F bit. */
17710 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17711 vty_out(vty,
17712 " bgp graceful-restart preserve-fw-state\n");
17713
17714 /* Stale timer for RIB */
17715 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17716 vty_out(vty,
17717 " bgp graceful-restart rib-stale-time %u\n",
17718 bgp->rib_stale_time);
17719
17720 /* BGP bestpath method. */
17721 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17722 vty_out(vty, " bgp bestpath as-path ignore\n");
17723 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17724 vty_out(vty, " bgp bestpath as-path confed\n");
17725
17726 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17727 if (CHECK_FLAG(bgp->flags,
17728 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17729 vty_out(vty,
17730 " bgp bestpath as-path multipath-relax as-set\n");
17731 } else {
17732 vty_out(vty,
17733 " bgp bestpath as-path multipath-relax\n");
17734 }
17735 }
17736
17737 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17738 vty_out(vty,
17739 " bgp route-reflector allow-outbound-policy\n");
17740 }
17741 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17742 vty_out(vty, " bgp bestpath compare-routerid\n");
17743 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17744 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17745 vty_out(vty, " bgp bestpath med");
17746 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17747 vty_out(vty, " confed");
17748 if (CHECK_FLAG(bgp->flags,
17749 BGP_FLAG_MED_MISSING_AS_WORST))
17750 vty_out(vty, " missing-as-worst");
17751 vty_out(vty, "\n");
17752 }
17753
17754 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17755 vty_out(vty,
17756 " bgp bestpath peer-type multipath-relax\n");
17757
17758 /* Link bandwidth handling. */
17759 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17760 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17761 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17762 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17763 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17764 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17765
17766 /* BGP network import check. */
17767 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17768 != SAVE_BGP_IMPORT_CHECK)
17769 vty_out(vty, " %sbgp network import-check\n",
17770 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17771 ? ""
17772 : "no ");
17773
17774 /* BGP timers configuration. */
17775 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17776 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17777 vty_out(vty, " timers bgp %u %u\n",
17778 bgp->default_keepalive, bgp->default_holdtime);
17779
17780 /* BGP minimum holdtime configuration. */
17781 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17782 && bgp->default_min_holdtime != 0)
17783 vty_out(vty, " bgp minimum-holdtime %u\n",
17784 bgp->default_min_holdtime);
17785
17786 /* Conditional advertisement timer configuration */
17787 if (bgp->condition_check_period
17788 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17789 vty_out(vty,
17790 " bgp conditional-advertisement timer %u\n",
17791 bgp->condition_check_period);
17792
17793 /* peer-group */
17794 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17795 bgp_config_write_peer_global(vty, bgp, group->conf);
17796 }
17797
17798 /* Normal neighbor configuration. */
17799 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17800 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17801 bgp_config_write_peer_global(vty, bgp, peer);
17802 }
17803
17804 /* listen range and limit for dynamic BGP neighbors */
17805 bgp_config_write_listen(vty, bgp);
17806
17807 /*
17808 * BGP default autoshutdown neighbors
17809 *
17810 * This must be placed after any peer and peer-group
17811 * configuration, to avoid setting all peers to shutdown after
17812 * a daemon restart, which is undesired behavior. (see #2286)
17813 */
17814 if (bgp->autoshutdown)
17815 vty_out(vty, " bgp default shutdown\n");
17816
17817 /* BGP instance administrative shutdown */
17818 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17819 vty_out(vty, " bgp shutdown\n");
17820
17821 if (bgp->allow_martian)
17822 vty_out(vty, " bgp allow-martian-nexthop\n");
17823
17824 if (bgp->fast_convergence)
17825 vty_out(vty, " bgp fast-convergence\n");
17826
17827 if (bgp->srv6_enabled) {
17828 vty_frame(vty, " !\n segment-routing srv6\n");
17829 if (strlen(bgp->srv6_locator_name))
17830 vty_out(vty, " locator %s\n",
17831 bgp->srv6_locator_name);
17832 vty_endframe(vty, " exit\n");
17833 }
17834
17835
17836 /* IPv4 unicast configuration. */
17837 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17838
17839 /* IPv4 multicast configuration. */
17840 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17841
17842 /* IPv4 labeled-unicast configuration. */
17843 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17844
17845 /* IPv4 VPN configuration. */
17846 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17847
17848 /* ENCAPv4 configuration. */
17849 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17850
17851 /* FLOWSPEC v4 configuration. */
17852 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17853
17854 /* IPv6 unicast configuration. */
17855 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17856
17857 /* IPv6 multicast configuration. */
17858 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17859
17860 /* IPv6 labeled-unicast configuration. */
17861 bgp_config_write_family(vty, bgp, AFI_IP6,
17862 SAFI_LABELED_UNICAST);
17863
17864 /* IPv6 VPN configuration. */
17865 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17866
17867 /* ENCAPv6 configuration. */
17868 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17869
17870 /* FLOWSPEC v6 configuration. */
17871 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17872
17873 /* EVPN configuration. */
17874 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17875
17876 hook_call(bgp_inst_config_write, bgp, vty);
17877
17878 #ifdef ENABLE_BGP_VNC
17879 bgp_rfapi_cfg_write(vty, bgp);
17880 #endif
17881
17882 vty_out(vty, "exit\n");
17883 vty_out(vty, "!\n");
17884 }
17885 return 0;
17886 }
17887
17888
17889 /* BGP node structure. */
17890 static struct cmd_node bgp_node = {
17891 .name = "bgp",
17892 .node = BGP_NODE,
17893 .parent_node = CONFIG_NODE,
17894 .prompt = "%s(config-router)# ",
17895 .config_write = bgp_config_write,
17896 };
17897
17898 static struct cmd_node bgp_ipv4_unicast_node = {
17899 .name = "bgp ipv4 unicast",
17900 .node = BGP_IPV4_NODE,
17901 .parent_node = BGP_NODE,
17902 .prompt = "%s(config-router-af)# ",
17903 .no_xpath = true,
17904 };
17905
17906 static struct cmd_node bgp_ipv4_multicast_node = {
17907 .name = "bgp ipv4 multicast",
17908 .node = BGP_IPV4M_NODE,
17909 .parent_node = BGP_NODE,
17910 .prompt = "%s(config-router-af)# ",
17911 .no_xpath = true,
17912 };
17913
17914 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17915 .name = "bgp ipv4 labeled unicast",
17916 .node = BGP_IPV4L_NODE,
17917 .parent_node = BGP_NODE,
17918 .prompt = "%s(config-router-af)# ",
17919 .no_xpath = true,
17920 };
17921
17922 static struct cmd_node bgp_ipv6_unicast_node = {
17923 .name = "bgp ipv6 unicast",
17924 .node = BGP_IPV6_NODE,
17925 .parent_node = BGP_NODE,
17926 .prompt = "%s(config-router-af)# ",
17927 .no_xpath = true,
17928 };
17929
17930 static struct cmd_node bgp_ipv6_multicast_node = {
17931 .name = "bgp ipv6 multicast",
17932 .node = BGP_IPV6M_NODE,
17933 .parent_node = BGP_NODE,
17934 .prompt = "%s(config-router-af)# ",
17935 .no_xpath = true,
17936 };
17937
17938 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17939 .name = "bgp ipv6 labeled unicast",
17940 .node = BGP_IPV6L_NODE,
17941 .parent_node = BGP_NODE,
17942 .prompt = "%s(config-router-af)# ",
17943 .no_xpath = true,
17944 };
17945
17946 static struct cmd_node bgp_vpnv4_node = {
17947 .name = "bgp vpnv4",
17948 .node = BGP_VPNV4_NODE,
17949 .parent_node = BGP_NODE,
17950 .prompt = "%s(config-router-af)# ",
17951 .no_xpath = true,
17952 };
17953
17954 static struct cmd_node bgp_vpnv6_node = {
17955 .name = "bgp vpnv6",
17956 .node = BGP_VPNV6_NODE,
17957 .parent_node = BGP_NODE,
17958 .prompt = "%s(config-router-af-vpnv6)# ",
17959 .no_xpath = true,
17960 };
17961
17962 static struct cmd_node bgp_evpn_node = {
17963 .name = "bgp evpn",
17964 .node = BGP_EVPN_NODE,
17965 .parent_node = BGP_NODE,
17966 .prompt = "%s(config-router-evpn)# ",
17967 .no_xpath = true,
17968 };
17969
17970 static struct cmd_node bgp_evpn_vni_node = {
17971 .name = "bgp evpn vni",
17972 .node = BGP_EVPN_VNI_NODE,
17973 .parent_node = BGP_EVPN_NODE,
17974 .prompt = "%s(config-router-af-vni)# ",
17975 };
17976
17977 static struct cmd_node bgp_flowspecv4_node = {
17978 .name = "bgp ipv4 flowspec",
17979 .node = BGP_FLOWSPECV4_NODE,
17980 .parent_node = BGP_NODE,
17981 .prompt = "%s(config-router-af)# ",
17982 .no_xpath = true,
17983 };
17984
17985 static struct cmd_node bgp_flowspecv6_node = {
17986 .name = "bgp ipv6 flowspec",
17987 .node = BGP_FLOWSPECV6_NODE,
17988 .parent_node = BGP_NODE,
17989 .prompt = "%s(config-router-af-vpnv6)# ",
17990 .no_xpath = true,
17991 };
17992
17993 static struct cmd_node bgp_srv6_node = {
17994 .name = "bgp srv6",
17995 .node = BGP_SRV6_NODE,
17996 .parent_node = BGP_NODE,
17997 .prompt = "%s(config-router-srv6)# ",
17998 };
17999
18000 static void community_list_vty(void);
18001
18002 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18003 {
18004 struct bgp *bgp;
18005 struct peer_group *group;
18006 struct listnode *lnbgp, *lnpeer;
18007
18008 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18009 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18010 vector_set(comps,
18011 XSTRDUP(MTYPE_COMPLETION, group->name));
18012 }
18013 }
18014
18015 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18016 {
18017 struct bgp *bgp;
18018 struct peer *peer;
18019 struct listnode *lnbgp, *lnpeer;
18020
18021 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18022 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18023 /* only provide suggestions on the appropriate input
18024 * token type,
18025 * they'll otherwise show up multiple times */
18026 enum cmd_token_type match_type;
18027 char *name = peer->host;
18028
18029 if (peer->conf_if) {
18030 match_type = VARIABLE_TKN;
18031 name = peer->conf_if;
18032 } else if (strchr(peer->host, ':'))
18033 match_type = IPV6_TKN;
18034 else
18035 match_type = IPV4_TKN;
18036
18037 if (token->type != match_type)
18038 continue;
18039
18040 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18041 }
18042 }
18043 }
18044
18045 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18046 {
18047 bgp_ac_peer(comps, token);
18048
18049 if (token->type == VARIABLE_TKN)
18050 bgp_ac_peergroup(comps, token);
18051 }
18052
18053 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18054 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18055 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18056 {.varname = "peer", .completions = bgp_ac_neighbor},
18057 {.completions = NULL}};
18058
18059 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18060 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18061 {.completions = NULL} };
18062
18063 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18064
18065 static struct thread *t_bgp_cfg;
18066
18067 bool bgp_config_inprocess(void)
18068 {
18069 return thread_is_scheduled(t_bgp_cfg);
18070 }
18071
18072 static void bgp_config_finish(struct thread *t)
18073 {
18074 struct listnode *node;
18075 struct bgp *bgp;
18076
18077 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18078 hook_call(bgp_config_end, bgp);
18079 }
18080
18081 static void bgp_config_start(void)
18082 {
18083 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18084 THREAD_OFF(t_bgp_cfg);
18085 thread_add_timer(bm->master, bgp_config_finish, NULL,
18086 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18087 }
18088
18089 /* When we receive a hook the configuration is read,
18090 * we start a timer to make sure we postpone sending
18091 * EoR before route-maps are processed.
18092 * This is especially valid if using `bgp route-map delay-timer`.
18093 */
18094 static void bgp_config_end(void)
18095 {
18096 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18097 uint32_t bgp_post_config_delay =
18098 thread_is_scheduled(bm->t_rmap_update)
18099 ? thread_timer_remain_second(bm->t_rmap_update)
18100 : BGP_POST_CONFIG_DELAY_SECONDS;
18101
18102 /* If BGP config processing thread isn't running, then
18103 * we can return and rely it's properly handled.
18104 */
18105 if (!bgp_config_inprocess())
18106 return;
18107
18108 THREAD_OFF(t_bgp_cfg);
18109
18110 /* Start a new timer to make sure we don't send EoR
18111 * before route-maps are processed.
18112 */
18113 thread_add_timer(bm->master, bgp_config_finish, NULL,
18114 bgp_post_config_delay, &t_bgp_cfg);
18115 }
18116
18117 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18118 {
18119 int write = 0;
18120 struct interface *ifp;
18121 struct bgp_interface *iifp;
18122
18123 FOR_ALL_INTERFACES (vrf, ifp) {
18124 iifp = ifp->info;
18125 if (!iifp)
18126 continue;
18127
18128 if_vty_config_start(vty, ifp);
18129
18130 if (CHECK_FLAG(iifp->flags,
18131 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18132 vty_out(vty, " mpls bgp forwarding\n");
18133 write++;
18134 }
18135
18136 if_vty_config_end(vty);
18137 }
18138
18139 return write;
18140 }
18141
18142 /* Configuration write function for bgpd. */
18143 static int config_write_interface(struct vty *vty)
18144 {
18145 int write = 0;
18146 struct vrf *vrf = NULL;
18147
18148 /* Display all VRF aware OSPF interface configuration */
18149 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18150 write += config_write_interface_one(vty, vrf);
18151 }
18152
18153 return write;
18154 }
18155
18156 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18157 "[no$no] mpls bgp forwarding",
18158 NO_STR MPLS_STR BGP_STR
18159 "Enable MPLS forwarding for eBGP directly connected peers\n")
18160 {
18161 bool check;
18162 struct bgp_interface *iifp;
18163
18164 VTY_DECLVAR_CONTEXT(interface, ifp);
18165 iifp = ifp->info;
18166 if (!iifp) {
18167 vty_out(vty, "Interface %s not available\n", ifp->name);
18168 return CMD_WARNING_CONFIG_FAILED;
18169 }
18170 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18171 if (check != !no) {
18172 if (no)
18173 UNSET_FLAG(iifp->flags,
18174 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18175 else
18176 SET_FLAG(iifp->flags,
18177 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18178 /* trigger a nht update on eBGP sessions */
18179 if (if_is_operative(ifp))
18180 bgp_nht_ifp_up(ifp);
18181 }
18182 return CMD_SUCCESS;
18183 }
18184
18185 /* Initialization of BGP interface. */
18186 static void bgp_vty_if_init(void)
18187 {
18188 /* Install interface node. */
18189 if_cmd_init(config_write_interface);
18190
18191 /* "mpls bgp forwarding" commands. */
18192 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18193 }
18194
18195 void bgp_vty_init(void)
18196 {
18197 cmd_variable_handler_register(bgp_var_neighbor);
18198 cmd_variable_handler_register(bgp_var_peergroup);
18199
18200 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18201
18202 /* Install bgp top node. */
18203 install_node(&bgp_node);
18204 install_node(&bgp_ipv4_unicast_node);
18205 install_node(&bgp_ipv4_multicast_node);
18206 install_node(&bgp_ipv4_labeled_unicast_node);
18207 install_node(&bgp_ipv6_unicast_node);
18208 install_node(&bgp_ipv6_multicast_node);
18209 install_node(&bgp_ipv6_labeled_unicast_node);
18210 install_node(&bgp_vpnv4_node);
18211 install_node(&bgp_vpnv6_node);
18212 install_node(&bgp_evpn_node);
18213 install_node(&bgp_evpn_vni_node);
18214 install_node(&bgp_flowspecv4_node);
18215 install_node(&bgp_flowspecv6_node);
18216 install_node(&bgp_srv6_node);
18217
18218 /* Install default VTY commands to new nodes. */
18219 install_default(BGP_NODE);
18220 install_default(BGP_IPV4_NODE);
18221 install_default(BGP_IPV4M_NODE);
18222 install_default(BGP_IPV4L_NODE);
18223 install_default(BGP_IPV6_NODE);
18224 install_default(BGP_IPV6M_NODE);
18225 install_default(BGP_IPV6L_NODE);
18226 install_default(BGP_VPNV4_NODE);
18227 install_default(BGP_VPNV6_NODE);
18228 install_default(BGP_FLOWSPECV4_NODE);
18229 install_default(BGP_FLOWSPECV6_NODE);
18230 install_default(BGP_EVPN_NODE);
18231 install_default(BGP_EVPN_VNI_NODE);
18232 install_default(BGP_SRV6_NODE);
18233
18234 /* "bgp local-mac" hidden commands. */
18235 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18236 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18237
18238 /* "bgp suppress-fib-pending" global */
18239 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18240
18241 /* bgp route-map delay-timer commands. */
18242 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18243 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18244
18245 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18246
18247 /* bgp fast-convergence command */
18248 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18249 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18250
18251 /* global bgp update-delay command */
18252 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18253 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18254
18255 /* global bgp graceful-shutdown command */
18256 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18257 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18258
18259 /* Dummy commands (Currently not supported) */
18260 install_element(BGP_NODE, &no_synchronization_cmd);
18261 install_element(BGP_NODE, &no_auto_summary_cmd);
18262
18263 /* "router bgp" commands. */
18264 install_element(CONFIG_NODE, &router_bgp_cmd);
18265
18266 /* "no router bgp" commands. */
18267 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18268
18269 /* "bgp session-dscp command */
18270 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18271 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18272
18273 /* "bgp router-id" commands. */
18274 install_element(BGP_NODE, &bgp_router_id_cmd);
18275 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18276
18277 /* "bgp suppress-fib-pending" command */
18278 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18279
18280 /* "bgp cluster-id" commands. */
18281 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18282 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18283
18284 /* "bgp no-rib" commands. */
18285 install_element(CONFIG_NODE, &bgp_norib_cmd);
18286 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18287
18288 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18289
18290 /* "bgp confederation" commands. */
18291 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18292 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18293
18294 /* "bgp confederation peers" commands. */
18295 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18296 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18297
18298 /* bgp max-med command */
18299 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18300 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18301 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18302 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18303 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18304
18305 /* "neighbor role" commands. */
18306 install_element(BGP_NODE, &neighbor_role_cmd);
18307 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18308 install_element(BGP_NODE, &no_neighbor_role_cmd);
18309
18310 /* bgp disable-ebgp-connected-nh-check */
18311 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18312 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18313
18314 /* bgp update-delay command */
18315 install_element(BGP_NODE, &bgp_update_delay_cmd);
18316 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18317
18318 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18319 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18320
18321 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18322 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18323
18324 /* "maximum-paths" commands. */
18325 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18326 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18327 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18328 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18329 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18330 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18331 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18332 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18333 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18334 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18335 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18336 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18337 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18338 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18339 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18340
18341 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18342 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18343 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18344 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18345 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18346 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18347 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18348 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18349 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18350 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18351
18352 /* "timers bgp" commands. */
18353 install_element(BGP_NODE, &bgp_timers_cmd);
18354 install_element(BGP_NODE, &no_bgp_timers_cmd);
18355
18356 /* "minimum-holdtime" commands. */
18357 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18358 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18359
18360 /* route-map delay-timer commands - per instance for backwards compat.
18361 */
18362 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18363 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18364
18365 /* "bgp client-to-client reflection" commands */
18366 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18367 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18368
18369 /* "bgp always-compare-med" commands */
18370 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18371 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18372
18373 /* bgp ebgp-requires-policy */
18374 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18375 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18376
18377 /* bgp suppress-duplicates */
18378 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18379 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18380
18381 /* bgp reject-as-sets */
18382 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18383 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18384
18385 /* "bgp deterministic-med" commands */
18386 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18387 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18388
18389 /* "bgp graceful-restart" command */
18390 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18391 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18392
18393 /* "bgp graceful-restart-disable" command */
18394 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18395 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18396
18397 /* "neighbor a:b:c:d graceful-restart" command */
18398 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18399 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18400
18401 /* "neighbor a:b:c:d graceful-restart-disable" command */
18402 install_element(BGP_NODE,
18403 &bgp_neighbor_graceful_restart_disable_set_cmd);
18404 install_element(BGP_NODE,
18405 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18406
18407 /* "neighbor a:b:c:d graceful-restart-helper" command */
18408 install_element(BGP_NODE,
18409 &bgp_neighbor_graceful_restart_helper_set_cmd);
18410 install_element(BGP_NODE,
18411 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18412
18413 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18414 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18415 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18416 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18417 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18418 install_element(BGP_NODE,
18419 &no_bgp_graceful_restart_select_defer_time_cmd);
18420 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18421 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18422 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18423
18424 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18425 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18426 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18427 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18428
18429 /* "bgp graceful-shutdown" commands */
18430 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18431 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18432
18433 /* "bgp hard-administrative-reset" commands */
18434 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18435
18436 /* "bgp long-lived-graceful-restart" commands */
18437 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18438 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18439
18440 /* "bgp fast-external-failover" commands */
18441 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18442 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18443
18444 /* "bgp bestpath compare-routerid" commands */
18445 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18446 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18447
18448 /* "bgp bestpath as-path ignore" commands */
18449 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18450 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18451
18452 /* "bgp bestpath as-path confed" commands */
18453 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18454 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18455
18456 /* "bgp bestpath as-path multipath-relax" commands */
18457 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18458 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18459
18460 /* "bgp bestpath peer-type multipath-relax" commands */
18461 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18462 install_element(BGP_NODE,
18463 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18464
18465 /* "bgp log-neighbor-changes" commands */
18466 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18467 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18468
18469 /* "bgp bestpath med" commands */
18470 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18471 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18472
18473 /* "bgp bestpath bandwidth" commands */
18474 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18475 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18476
18477 /* "no bgp default <afi>-<safi>" commands. */
18478 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18479
18480 /* "bgp network import-check" commands. */
18481 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18482 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18483 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18484
18485 /* "bgp default local-preference" commands. */
18486 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18487 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18488
18489 /* bgp default show-hostname */
18490 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18491 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18492
18493 /* bgp default show-nexthop-hostname */
18494 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18495 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18496
18497 /* "bgp default subgroup-pkt-queue-max" commands. */
18498 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18499 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18500
18501 /* bgp ibgp-allow-policy-mods command */
18502 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18503 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18504
18505 /* "bgp listen limit" commands. */
18506 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18507 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18508
18509 /* "bgp listen range" commands. */
18510 install_element(BGP_NODE, &bgp_listen_range_cmd);
18511 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18512
18513 /* "bgp default shutdown" command */
18514 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18515
18516 /* "bgp shutdown" commands */
18517 install_element(BGP_NODE, &bgp_shutdown_cmd);
18518 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18519 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18520 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18521
18522 /* "neighbor remote-as" commands. */
18523 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18524 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18525 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18526 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18527 install_element(BGP_NODE,
18528 &neighbor_interface_v6only_config_remote_as_cmd);
18529 install_element(BGP_NODE, &no_neighbor_cmd);
18530 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18531
18532 /* "neighbor peer-group" commands. */
18533 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18534 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18535 install_element(BGP_NODE,
18536 &no_neighbor_interface_peer_group_remote_as_cmd);
18537
18538 /* "neighbor local-as" commands. */
18539 install_element(BGP_NODE, &neighbor_local_as_cmd);
18540 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18541 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18542 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18543
18544 /* "neighbor solo" commands. */
18545 install_element(BGP_NODE, &neighbor_solo_cmd);
18546 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18547
18548 /* "neighbor password" commands. */
18549 install_element(BGP_NODE, &neighbor_password_cmd);
18550 install_element(BGP_NODE, &no_neighbor_password_cmd);
18551
18552 /* "neighbor activate" commands. */
18553 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18554 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18555 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18556 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18557 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18558 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18559 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18560 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18561 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18562 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18563 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18564 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18565
18566 /* "no neighbor activate" commands. */
18567 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18568 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18569 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18570 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18571 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18572 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18573 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18574 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18575 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18576 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18577 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18578 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18579
18580 /* "neighbor peer-group" set commands. */
18581 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18582 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18583 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18584 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18585 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18586 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18587 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18588 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18589 install_element(BGP_FLOWSPECV4_NODE,
18590 &neighbor_set_peer_group_hidden_cmd);
18591 install_element(BGP_FLOWSPECV6_NODE,
18592 &neighbor_set_peer_group_hidden_cmd);
18593
18594 /* "no neighbor peer-group unset" commands. */
18595 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18596 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18597 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18598 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18599 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18600 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18601 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18602 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18603 install_element(BGP_FLOWSPECV4_NODE,
18604 &no_neighbor_set_peer_group_hidden_cmd);
18605 install_element(BGP_FLOWSPECV6_NODE,
18606 &no_neighbor_set_peer_group_hidden_cmd);
18607
18608 /* "neighbor softreconfiguration inbound" commands.*/
18609 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18610 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18611 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18612 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18613 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18614 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18615 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18616 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18617 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18618 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18619 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18620 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18621 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18622 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18623 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18624 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18625 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18626 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18627 install_element(BGP_FLOWSPECV4_NODE,
18628 &neighbor_soft_reconfiguration_cmd);
18629 install_element(BGP_FLOWSPECV4_NODE,
18630 &no_neighbor_soft_reconfiguration_cmd);
18631 install_element(BGP_FLOWSPECV6_NODE,
18632 &neighbor_soft_reconfiguration_cmd);
18633 install_element(BGP_FLOWSPECV6_NODE,
18634 &no_neighbor_soft_reconfiguration_cmd);
18635 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18636 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18637
18638 /* "neighbor attribute-unchanged" commands. */
18639 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18640 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18641 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18642 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18643 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18644 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18645 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18646 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18647 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18648 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18649 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18650 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18651 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18652 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18653 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18654 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18655 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18656 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18657
18658 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18659 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18660
18661 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18662 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18663 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18664 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18665
18666 /* "nexthop-local unchanged" commands */
18667 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18668 install_element(BGP_IPV6_NODE,
18669 &no_neighbor_nexthop_local_unchanged_cmd);
18670
18671 /* "neighbor next-hop-self" commands. */
18672 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18673 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18674 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18675 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18676 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18677 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18678 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18679 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18680 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18681 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18682 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18683 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18684 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18685 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18686 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18687 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18688 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18689 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18690 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18691 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18692
18693 /* "neighbor next-hop-self force" commands. */
18694 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18695 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18696 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18697 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18698 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18699 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18700 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18701 install_element(BGP_IPV4_NODE,
18702 &no_neighbor_nexthop_self_all_hidden_cmd);
18703 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18704 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18705 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18706 install_element(BGP_IPV4M_NODE,
18707 &no_neighbor_nexthop_self_all_hidden_cmd);
18708 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18709 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18710 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18711 install_element(BGP_IPV4L_NODE,
18712 &no_neighbor_nexthop_self_all_hidden_cmd);
18713 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18714 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18715 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18716 install_element(BGP_IPV6_NODE,
18717 &no_neighbor_nexthop_self_all_hidden_cmd);
18718 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18719 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18720 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18721 install_element(BGP_IPV6M_NODE,
18722 &no_neighbor_nexthop_self_all_hidden_cmd);
18723 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18724 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18725 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18726 install_element(BGP_IPV6L_NODE,
18727 &no_neighbor_nexthop_self_all_hidden_cmd);
18728 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18729 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18730 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18731 install_element(BGP_VPNV4_NODE,
18732 &no_neighbor_nexthop_self_all_hidden_cmd);
18733 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18734 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18735 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18736 install_element(BGP_VPNV6_NODE,
18737 &no_neighbor_nexthop_self_all_hidden_cmd);
18738 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18739 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18740
18741 /* "neighbor as-override" commands. */
18742 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18743 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18744 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18745 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18746 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18747 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18748 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18749 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18750 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18751 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18752 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18753 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18754 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18755 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18756 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18757 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18758 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18759 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18760
18761 /* "neighbor remove-private-AS" commands. */
18762 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18763 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18764 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18765 install_element(BGP_NODE,
18766 &no_neighbor_remove_private_as_all_hidden_cmd);
18767 install_element(BGP_NODE,
18768 &neighbor_remove_private_as_replace_as_hidden_cmd);
18769 install_element(BGP_NODE,
18770 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18771 install_element(BGP_NODE,
18772 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18773 install_element(
18774 BGP_NODE,
18775 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18776 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18777 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18778 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18779 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18780 install_element(BGP_IPV4_NODE,
18781 &neighbor_remove_private_as_replace_as_cmd);
18782 install_element(BGP_IPV4_NODE,
18783 &no_neighbor_remove_private_as_replace_as_cmd);
18784 install_element(BGP_IPV4_NODE,
18785 &neighbor_remove_private_as_all_replace_as_cmd);
18786 install_element(BGP_IPV4_NODE,
18787 &no_neighbor_remove_private_as_all_replace_as_cmd);
18788 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18789 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18790 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18791 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18792 install_element(BGP_IPV4M_NODE,
18793 &neighbor_remove_private_as_replace_as_cmd);
18794 install_element(BGP_IPV4M_NODE,
18795 &no_neighbor_remove_private_as_replace_as_cmd);
18796 install_element(BGP_IPV4M_NODE,
18797 &neighbor_remove_private_as_all_replace_as_cmd);
18798 install_element(BGP_IPV4M_NODE,
18799 &no_neighbor_remove_private_as_all_replace_as_cmd);
18800 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18801 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18802 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18803 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18804 install_element(BGP_IPV4L_NODE,
18805 &neighbor_remove_private_as_replace_as_cmd);
18806 install_element(BGP_IPV4L_NODE,
18807 &no_neighbor_remove_private_as_replace_as_cmd);
18808 install_element(BGP_IPV4L_NODE,
18809 &neighbor_remove_private_as_all_replace_as_cmd);
18810 install_element(BGP_IPV4L_NODE,
18811 &no_neighbor_remove_private_as_all_replace_as_cmd);
18812 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18813 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18814 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18815 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18816 install_element(BGP_IPV6_NODE,
18817 &neighbor_remove_private_as_replace_as_cmd);
18818 install_element(BGP_IPV6_NODE,
18819 &no_neighbor_remove_private_as_replace_as_cmd);
18820 install_element(BGP_IPV6_NODE,
18821 &neighbor_remove_private_as_all_replace_as_cmd);
18822 install_element(BGP_IPV6_NODE,
18823 &no_neighbor_remove_private_as_all_replace_as_cmd);
18824 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18825 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18826 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18827 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18828 install_element(BGP_IPV6M_NODE,
18829 &neighbor_remove_private_as_replace_as_cmd);
18830 install_element(BGP_IPV6M_NODE,
18831 &no_neighbor_remove_private_as_replace_as_cmd);
18832 install_element(BGP_IPV6M_NODE,
18833 &neighbor_remove_private_as_all_replace_as_cmd);
18834 install_element(BGP_IPV6M_NODE,
18835 &no_neighbor_remove_private_as_all_replace_as_cmd);
18836 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18837 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18838 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18839 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18840 install_element(BGP_IPV6L_NODE,
18841 &neighbor_remove_private_as_replace_as_cmd);
18842 install_element(BGP_IPV6L_NODE,
18843 &no_neighbor_remove_private_as_replace_as_cmd);
18844 install_element(BGP_IPV6L_NODE,
18845 &neighbor_remove_private_as_all_replace_as_cmd);
18846 install_element(BGP_IPV6L_NODE,
18847 &no_neighbor_remove_private_as_all_replace_as_cmd);
18848 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18849 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18850 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18851 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18852 install_element(BGP_VPNV4_NODE,
18853 &neighbor_remove_private_as_replace_as_cmd);
18854 install_element(BGP_VPNV4_NODE,
18855 &no_neighbor_remove_private_as_replace_as_cmd);
18856 install_element(BGP_VPNV4_NODE,
18857 &neighbor_remove_private_as_all_replace_as_cmd);
18858 install_element(BGP_VPNV4_NODE,
18859 &no_neighbor_remove_private_as_all_replace_as_cmd);
18860 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18861 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18862 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18863 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18864 install_element(BGP_VPNV6_NODE,
18865 &neighbor_remove_private_as_replace_as_cmd);
18866 install_element(BGP_VPNV6_NODE,
18867 &no_neighbor_remove_private_as_replace_as_cmd);
18868 install_element(BGP_VPNV6_NODE,
18869 &neighbor_remove_private_as_all_replace_as_cmd);
18870 install_element(BGP_VPNV6_NODE,
18871 &no_neighbor_remove_private_as_all_replace_as_cmd);
18872
18873 /* "neighbor send-community" commands.*/
18874 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18875 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18876 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18877 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18878 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18879 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18880 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18881 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18882 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18883 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18884 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18885 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18886 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18887 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18888 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18889 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18890 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18891 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18892 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18893 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18894 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18895 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18896 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18897 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18898 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18899 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18900 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18901 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18902 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18903 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18904 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18905 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18906 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18907 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18908 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18909 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18910
18911 /* "neighbor route-reflector" commands.*/
18912 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18913 install_element(BGP_NODE,
18914 &no_neighbor_route_reflector_client_hidden_cmd);
18915 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18916 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18917 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18918 install_element(BGP_IPV4M_NODE,
18919 &no_neighbor_route_reflector_client_cmd);
18920 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18921 install_element(BGP_IPV4L_NODE,
18922 &no_neighbor_route_reflector_client_cmd);
18923 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18924 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18925 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18926 install_element(BGP_IPV6M_NODE,
18927 &no_neighbor_route_reflector_client_cmd);
18928 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18929 install_element(BGP_IPV6L_NODE,
18930 &no_neighbor_route_reflector_client_cmd);
18931 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18932 install_element(BGP_VPNV4_NODE,
18933 &no_neighbor_route_reflector_client_cmd);
18934 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18935 install_element(BGP_VPNV6_NODE,
18936 &no_neighbor_route_reflector_client_cmd);
18937 install_element(BGP_FLOWSPECV4_NODE,
18938 &neighbor_route_reflector_client_cmd);
18939 install_element(BGP_FLOWSPECV4_NODE,
18940 &no_neighbor_route_reflector_client_cmd);
18941 install_element(BGP_FLOWSPECV6_NODE,
18942 &neighbor_route_reflector_client_cmd);
18943 install_element(BGP_FLOWSPECV6_NODE,
18944 &no_neighbor_route_reflector_client_cmd);
18945 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18946 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18947
18948 /* "neighbor route-server" commands.*/
18949 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18950 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18951 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18952 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18953 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18954 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18955 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18956 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18957 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18958 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18959 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18960 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18961 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18962 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18963 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18964 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18965 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18966 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18967 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18968 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18969 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18970 install_element(BGP_FLOWSPECV4_NODE,
18971 &no_neighbor_route_server_client_cmd);
18972 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18973 install_element(BGP_FLOWSPECV6_NODE,
18974 &no_neighbor_route_server_client_cmd);
18975
18976 /* "neighbor disable-addpath-rx" commands. */
18977 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18978 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18979 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18980 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18981 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18982 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18983 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18984 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18985 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18986 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18987 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18988 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18989 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18990 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18991 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18992 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18993
18994 /* "neighbor addpath-tx-all-paths" commands.*/
18995 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18996 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18997 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18998 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18999 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19000 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19001 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19002 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19003 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19004 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19005 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19006 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19007 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19008 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19009 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19010 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19011 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19012 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19013
19014 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19015 install_element(BGP_NODE,
19016 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19017 install_element(BGP_NODE,
19018 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19019 install_element(BGP_IPV4_NODE,
19020 &neighbor_addpath_tx_bestpath_per_as_cmd);
19021 install_element(BGP_IPV4_NODE,
19022 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19023 install_element(BGP_IPV4M_NODE,
19024 &neighbor_addpath_tx_bestpath_per_as_cmd);
19025 install_element(BGP_IPV4M_NODE,
19026 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19027 install_element(BGP_IPV4L_NODE,
19028 &neighbor_addpath_tx_bestpath_per_as_cmd);
19029 install_element(BGP_IPV4L_NODE,
19030 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19031 install_element(BGP_IPV6_NODE,
19032 &neighbor_addpath_tx_bestpath_per_as_cmd);
19033 install_element(BGP_IPV6_NODE,
19034 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19035 install_element(BGP_IPV6M_NODE,
19036 &neighbor_addpath_tx_bestpath_per_as_cmd);
19037 install_element(BGP_IPV6M_NODE,
19038 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19039 install_element(BGP_IPV6L_NODE,
19040 &neighbor_addpath_tx_bestpath_per_as_cmd);
19041 install_element(BGP_IPV6L_NODE,
19042 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19043 install_element(BGP_VPNV4_NODE,
19044 &neighbor_addpath_tx_bestpath_per_as_cmd);
19045 install_element(BGP_VPNV4_NODE,
19046 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19047 install_element(BGP_VPNV6_NODE,
19048 &neighbor_addpath_tx_bestpath_per_as_cmd);
19049 install_element(BGP_VPNV6_NODE,
19050 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19051
19052 /* "neighbor sender-as-path-loop-detection" commands. */
19053 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19054 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19055
19056 /* "neighbor passive" commands. */
19057 install_element(BGP_NODE, &neighbor_passive_cmd);
19058 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19059
19060
19061 /* "neighbor shutdown" commands. */
19062 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19063 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19064 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19065 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19066 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19067 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19068
19069 /* "neighbor capability extended-nexthop" commands.*/
19070 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19071 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19072
19073 /* "neighbor capability orf prefix-list" commands.*/
19074 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19075 install_element(BGP_NODE,
19076 &no_neighbor_capability_orf_prefix_hidden_cmd);
19077 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19078 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19079 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19080 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19081 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19082 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19083 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19084 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19085 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19086 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19087 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19088 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19089
19090 /* "neighbor capability dynamic" commands.*/
19091 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19092 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19093
19094 /* "neighbor dont-capability-negotiate" commands. */
19095 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19096 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19097
19098 /* "neighbor ebgp-multihop" commands. */
19099 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19100 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19101 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19102
19103 /* "neighbor disable-connected-check" commands. */
19104 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19105 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19106
19107 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19108 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19109 install_element(BGP_NODE,
19110 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19111
19112 /* "neighbor extended-optional-parameters" commands. */
19113 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19114 install_element(BGP_NODE,
19115 &no_neighbor_extended_optional_parameters_cmd);
19116
19117 /* "neighbor enforce-first-as" commands. */
19118 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19119 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19120
19121 /* "neighbor description" commands. */
19122 install_element(BGP_NODE, &neighbor_description_cmd);
19123 install_element(BGP_NODE, &no_neighbor_description_cmd);
19124 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19125
19126 /* "neighbor update-source" commands. "*/
19127 install_element(BGP_NODE, &neighbor_update_source_cmd);
19128 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19129
19130 /* "neighbor default-originate" commands. */
19131 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19132 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19133 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19134 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19135 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19136 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19137 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19138 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19139 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19140 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19141 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19142 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19143 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19144 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19145 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19146 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19147 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19148 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19149 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19150 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19151 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19152
19153 /* "neighbor port" commands. */
19154 install_element(BGP_NODE, &neighbor_port_cmd);
19155 install_element(BGP_NODE, &no_neighbor_port_cmd);
19156
19157 /* "neighbor weight" commands. */
19158 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19159 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19160
19161 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19162 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19163 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19164 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19165 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19166 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19167 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19168 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19169 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19170 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19171 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19172 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19173 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19174 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19175 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19176 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19177
19178 /* "neighbor override-capability" commands. */
19179 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19180 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19181
19182 /* "neighbor strict-capability-match" commands. */
19183 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19184 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19185
19186 /* "neighbor timers" commands. */
19187 install_element(BGP_NODE, &neighbor_timers_cmd);
19188 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19189
19190 /* "neighbor timers connect" commands. */
19191 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19192 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19193
19194 /* "neighbor timers delayopen" commands. */
19195 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19196 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19197
19198 /* "neighbor advertisement-interval" commands. */
19199 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19200 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19201
19202 /* "neighbor interface" commands. */
19203 install_element(BGP_NODE, &neighbor_interface_cmd);
19204 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19205
19206 /* "neighbor distribute" commands. */
19207 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19208 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19209 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19210 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19211 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19212 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19213 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19214 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19215 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19216 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19217 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19218 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19219 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19220 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19221 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19222 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19223 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19224 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19225
19226 /* "neighbor prefix-list" commands. */
19227 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19228 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19229 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19230 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19231 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19232 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19233 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19234 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19235 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19236 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19237 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19238 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19239 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19240 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19241 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19242 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19243 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19244 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19245 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19246 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19247 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19248 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19249
19250 /* "neighbor filter-list" commands. */
19251 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19252 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19253 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19254 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19255 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19256 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19257 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19258 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19259 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19260 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19261 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19262 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19263 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19264 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19265 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19266 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19267 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19268 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19269 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19270 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19271 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19272 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19273
19274 /* "neighbor route-map" commands. */
19275 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19276 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19277 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19278 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19279 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19280 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19281 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19282 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19283 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19284 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19285 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19286 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19287 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19288 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19289 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19290 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19291 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19292 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19293 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19294 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19295 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19296 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19297 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19298 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19299
19300 /* "neighbor unsuppress-map" commands. */
19301 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19302 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19303 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19304 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19305 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19306 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19307 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19308 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19309 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19310 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19311 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19312 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19313 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19314 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19315 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19316 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19317 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19318 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19319
19320 /* "neighbor advertise-map" commands. */
19321 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19322 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19323 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19324 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19325 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19326 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19327 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19328 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19329 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19330 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19331
19332 /* neighbor maximum-prefix-out commands. */
19333 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19334 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19335 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19336 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19337 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19338 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19339 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19340 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19341 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19342 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19343 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19344 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19345 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19346 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19347 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19348 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19349 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19350 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19351
19352 /* "neighbor maximum-prefix" commands. */
19353 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19354 install_element(BGP_NODE,
19355 &neighbor_maximum_prefix_threshold_hidden_cmd);
19356 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19357 install_element(BGP_NODE,
19358 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19359 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19360 install_element(BGP_NODE,
19361 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19362 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19363 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19364 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19365 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19366 install_element(BGP_IPV4_NODE,
19367 &neighbor_maximum_prefix_threshold_warning_cmd);
19368 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19369 install_element(BGP_IPV4_NODE,
19370 &neighbor_maximum_prefix_threshold_restart_cmd);
19371 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19372 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19373 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19374 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19375 install_element(BGP_IPV4M_NODE,
19376 &neighbor_maximum_prefix_threshold_warning_cmd);
19377 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19378 install_element(BGP_IPV4M_NODE,
19379 &neighbor_maximum_prefix_threshold_restart_cmd);
19380 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19381 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19382 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19383 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19384 install_element(BGP_IPV4L_NODE,
19385 &neighbor_maximum_prefix_threshold_warning_cmd);
19386 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19387 install_element(BGP_IPV4L_NODE,
19388 &neighbor_maximum_prefix_threshold_restart_cmd);
19389 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19390 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19391 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19392 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19393 install_element(BGP_IPV6_NODE,
19394 &neighbor_maximum_prefix_threshold_warning_cmd);
19395 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19396 install_element(BGP_IPV6_NODE,
19397 &neighbor_maximum_prefix_threshold_restart_cmd);
19398 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19399 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19400 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19401 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19402 install_element(BGP_IPV6M_NODE,
19403 &neighbor_maximum_prefix_threshold_warning_cmd);
19404 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19405 install_element(BGP_IPV6M_NODE,
19406 &neighbor_maximum_prefix_threshold_restart_cmd);
19407 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19408 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19409 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19410 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19411 install_element(BGP_IPV6L_NODE,
19412 &neighbor_maximum_prefix_threshold_warning_cmd);
19413 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19414 install_element(BGP_IPV6L_NODE,
19415 &neighbor_maximum_prefix_threshold_restart_cmd);
19416 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19417 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19418 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19419 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19420 install_element(BGP_VPNV4_NODE,
19421 &neighbor_maximum_prefix_threshold_warning_cmd);
19422 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19423 install_element(BGP_VPNV4_NODE,
19424 &neighbor_maximum_prefix_threshold_restart_cmd);
19425 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19426 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19427 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19428 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19429 install_element(BGP_VPNV6_NODE,
19430 &neighbor_maximum_prefix_threshold_warning_cmd);
19431 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19432 install_element(BGP_VPNV6_NODE,
19433 &neighbor_maximum_prefix_threshold_restart_cmd);
19434 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19435
19436 /* "neighbor allowas-in" */
19437 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19438 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19439 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19440 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19441 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19442 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19443 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19444 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19445 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19446 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19447 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19448 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19449 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19450 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19451 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19452 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19453 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19454 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19455 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19456 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19457
19458 /* "neighbor soo" */
19459 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19460 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19461 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19462 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19463 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19464 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19465 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19466 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19467 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19468 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19469 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19470 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19471 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19472 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19473 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19474 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19475 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19476 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19477
19478 /* address-family commands. */
19479 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19480 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19481 #ifdef KEEP_OLD_VPN_COMMANDS
19482 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19483 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19484 #endif /* KEEP_OLD_VPN_COMMANDS */
19485
19486 install_element(BGP_NODE, &address_family_evpn_cmd);
19487
19488 /* "exit-address-family" command. */
19489 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19490 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19491 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19492 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19493 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19494 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19495 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19496 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19497 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19498 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19499 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19500
19501 /* BGP retain all route-target */
19502 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19503 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19504
19505 /* "clear ip bgp commands" */
19506 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19507
19508 /* clear ip bgp prefix */
19509 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19510 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19511 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19512
19513 /* "show [ip] bgp summary" commands. */
19514 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19515 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19516 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19517 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19518 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19519 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19520 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19521
19522 /* "show [ip] bgp neighbors" commands. */
19523 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19524
19525 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19526
19527 /* "show [ip] bgp peer-group" commands. */
19528 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19529
19530 /* "show [ip] bgp paths" commands. */
19531 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19532
19533 /* "show [ip] bgp community" commands. */
19534 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19535
19536 /* "show ip bgp large-community" commands. */
19537 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19538 /* "show [ip] bgp attribute-info" commands. */
19539 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19540 /* "show [ip] bgp route-leak" command */
19541 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19542
19543 /* "redistribute" commands. */
19544 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19545 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19546 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19547 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19548 install_element(BGP_NODE,
19549 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19550 install_element(BGP_NODE,
19551 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19552 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19553 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19554 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19555 install_element(BGP_NODE,
19556 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19557 install_element(BGP_NODE,
19558 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19559 install_element(BGP_NODE,
19560 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19561 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19562 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19563 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19564 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19565 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19566 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19567 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19568 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19569 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19570 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19571 install_element(BGP_IPV4_NODE,
19572 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19573 install_element(BGP_IPV4_NODE,
19574 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19575 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19576 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19577 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19578 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19579 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19580 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19581
19582 /* import|export vpn [route-map RMAP_NAME] */
19583 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19584 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19585
19586 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19587 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19588
19589 /* ttl_security commands */
19590 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19591 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19592
19593 /* "show [ip] bgp memory" commands. */
19594 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19595
19596 /* "show bgp martian next-hop" */
19597 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19598
19599 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19600
19601 /* "show [ip] bgp views" commands. */
19602 install_element(VIEW_NODE, &show_bgp_views_cmd);
19603
19604 /* "show [ip] bgp vrfs" commands. */
19605 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19606
19607 /* Community-list. */
19608 community_list_vty();
19609
19610 community_alias_vty();
19611
19612 /* vpn-policy commands */
19613 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19614 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19615 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19616 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19617 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19618 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19619 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19620 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19621 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19622 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19623 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19624 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19625
19626 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19627 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19628
19629 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19630 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19631 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19632 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19633 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19634 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19635 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19636 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19637 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19638 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19639
19640 /* tcp-mss command */
19641 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19642 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19643
19644 /* srv6 commands */
19645 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19646 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19647 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19648 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19649 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19650 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19651 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19652
19653 bgp_vty_if_init();
19654 }
19655
19656 #include "memory.h"
19657 #include "bgp_regex.h"
19658 #include "bgp_clist.h"
19659 #include "bgp_ecommunity.h"
19660
19661 /* VTY functions. */
19662
19663 /* Direction value to string conversion. */
19664 static const char *community_direct_str(int direct)
19665 {
19666 switch (direct) {
19667 case COMMUNITY_DENY:
19668 return "deny";
19669 case COMMUNITY_PERMIT:
19670 return "permit";
19671 default:
19672 return "unknown";
19673 }
19674 }
19675
19676 /* Display error string. */
19677 static void community_list_perror(struct vty *vty, int ret)
19678 {
19679 switch (ret) {
19680 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19681 vty_out(vty, "%% Can't find community-list\n");
19682 break;
19683 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19684 vty_out(vty, "%% Malformed community-list value\n");
19685 break;
19686 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19687 vty_out(vty,
19688 "%% Community name conflict, previously defined as standard community\n");
19689 break;
19690 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19691 vty_out(vty,
19692 "%% Community name conflict, previously defined as expanded community\n");
19693 break;
19694 }
19695 }
19696
19697 /* "community-list" keyword help string. */
19698 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19699
19700 /*community-list standard */
19701 DEFUN (community_list_standard,
19702 bgp_community_list_standard_cmd,
19703 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19704 BGP_STR
19705 COMMUNITY_LIST_STR
19706 "Community list number (standard)\n"
19707 "Add an standard community-list entry\n"
19708 "Community list name\n"
19709 "Sequence number of an entry\n"
19710 "Sequence number\n"
19711 "Specify community to reject\n"
19712 "Specify community to accept\n"
19713 COMMUNITY_VAL_STR)
19714 {
19715 char *cl_name_or_number = NULL;
19716 char *seq = NULL;
19717 int direct = 0;
19718 int style = COMMUNITY_LIST_STANDARD;
19719 int idx = 0;
19720
19721 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19722 seq = argv[idx]->arg;
19723
19724 idx = 0;
19725 argv_find(argv, argc, "(1-99)", &idx);
19726 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19727 cl_name_or_number = argv[idx]->arg;
19728 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19729 : COMMUNITY_DENY;
19730 argv_find(argv, argc, "AA:NN", &idx);
19731 char *str = argv_concat(argv, argc, idx);
19732
19733 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19734 direct, style);
19735
19736 XFREE(MTYPE_TMP, str);
19737
19738 if (ret < 0) {
19739 /* Display error string. */
19740 community_list_perror(vty, ret);
19741 return CMD_WARNING_CONFIG_FAILED;
19742 }
19743
19744 return CMD_SUCCESS;
19745 }
19746
19747 DEFUN (no_community_list_standard_all,
19748 no_bgp_community_list_standard_all_cmd,
19749 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19750 NO_STR
19751 BGP_STR
19752 COMMUNITY_LIST_STR
19753 "Community list number (standard)\n"
19754 "Add an standard community-list entry\n"
19755 "Community list name\n"
19756 "Sequence number of an entry\n"
19757 "Sequence number\n"
19758 "Specify community to reject\n"
19759 "Specify community to accept\n"
19760 COMMUNITY_VAL_STR)
19761 {
19762 char *cl_name_or_number = NULL;
19763 char *str = NULL;
19764 int direct = 0;
19765 int style = COMMUNITY_LIST_STANDARD;
19766 char *seq = NULL;
19767 int idx = 0;
19768
19769 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19770 seq = argv[idx]->arg;
19771
19772 idx = 0;
19773 argv_find(argv, argc, "permit", &idx);
19774 argv_find(argv, argc, "deny", &idx);
19775
19776 if (idx) {
19777 direct = argv_find(argv, argc, "permit", &idx)
19778 ? COMMUNITY_PERMIT
19779 : COMMUNITY_DENY;
19780
19781 idx = 0;
19782 argv_find(argv, argc, "AA:NN", &idx);
19783 str = argv_concat(argv, argc, idx);
19784 }
19785
19786 idx = 0;
19787 argv_find(argv, argc, "(1-99)", &idx);
19788 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19789 cl_name_or_number = argv[idx]->arg;
19790
19791 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19792 direct, style);
19793
19794 XFREE(MTYPE_TMP, str);
19795
19796 if (ret < 0) {
19797 community_list_perror(vty, ret);
19798 return CMD_WARNING_CONFIG_FAILED;
19799 }
19800
19801 return CMD_SUCCESS;
19802 }
19803
19804 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19805 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19806 NO_STR BGP_STR COMMUNITY_LIST_STR
19807 "Community list number (standard)\n"
19808 "Add an standard community-list entry\n"
19809 "Community list name\n")
19810
19811 /*community-list expanded */
19812 DEFUN (community_list_expanded_all,
19813 bgp_community_list_expanded_all_cmd,
19814 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19815 BGP_STR
19816 COMMUNITY_LIST_STR
19817 "Community list number (expanded)\n"
19818 "Add an expanded community-list entry\n"
19819 "Community list name\n"
19820 "Sequence number of an entry\n"
19821 "Sequence number\n"
19822 "Specify community to reject\n"
19823 "Specify community to accept\n"
19824 COMMUNITY_VAL_STR)
19825 {
19826 char *cl_name_or_number = NULL;
19827 char *seq = NULL;
19828 int direct = 0;
19829 int style = COMMUNITY_LIST_EXPANDED;
19830 int idx = 0;
19831
19832 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19833 seq = argv[idx]->arg;
19834
19835 idx = 0;
19836
19837 argv_find(argv, argc, "(100-500)", &idx);
19838 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19839 cl_name_or_number = argv[idx]->arg;
19840 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19841 : COMMUNITY_DENY;
19842 argv_find(argv, argc, "AA:NN", &idx);
19843 char *str = argv_concat(argv, argc, idx);
19844
19845 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19846 direct, style);
19847
19848 XFREE(MTYPE_TMP, str);
19849
19850 if (ret < 0) {
19851 /* Display error string. */
19852 community_list_perror(vty, ret);
19853 return CMD_WARNING_CONFIG_FAILED;
19854 }
19855
19856 return CMD_SUCCESS;
19857 }
19858
19859 DEFUN (no_community_list_expanded_all,
19860 no_bgp_community_list_expanded_all_cmd,
19861 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19862 NO_STR
19863 BGP_STR
19864 COMMUNITY_LIST_STR
19865 "Community list number (expanded)\n"
19866 "Add an expanded community-list entry\n"
19867 "Community list name\n"
19868 "Sequence number of an entry\n"
19869 "Sequence number\n"
19870 "Specify community to reject\n"
19871 "Specify community to accept\n"
19872 COMMUNITY_VAL_STR)
19873 {
19874 char *cl_name_or_number = NULL;
19875 char *seq = NULL;
19876 char *str = NULL;
19877 int direct = 0;
19878 int style = COMMUNITY_LIST_EXPANDED;
19879 int idx = 0;
19880
19881 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19882 seq = argv[idx]->arg;
19883
19884 idx = 0;
19885 argv_find(argv, argc, "permit", &idx);
19886 argv_find(argv, argc, "deny", &idx);
19887
19888 if (idx) {
19889 direct = argv_find(argv, argc, "permit", &idx)
19890 ? COMMUNITY_PERMIT
19891 : COMMUNITY_DENY;
19892
19893 idx = 0;
19894 argv_find(argv, argc, "AA:NN", &idx);
19895 str = argv_concat(argv, argc, idx);
19896 }
19897
19898 idx = 0;
19899 argv_find(argv, argc, "(100-500)", &idx);
19900 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19901 cl_name_or_number = argv[idx]->arg;
19902
19903 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19904 direct, style);
19905
19906 XFREE(MTYPE_TMP, str);
19907
19908 if (ret < 0) {
19909 community_list_perror(vty, ret);
19910 return CMD_WARNING_CONFIG_FAILED;
19911 }
19912
19913 return CMD_SUCCESS;
19914 }
19915
19916 ALIAS(no_community_list_expanded_all,
19917 no_bgp_community_list_expanded_all_list_cmd,
19918 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19919 NO_STR BGP_STR COMMUNITY_LIST_STR
19920 "Community list number (expanded)\n"
19921 "Add an expanded community-list entry\n"
19922 "Community list name\n")
19923
19924 /* Return configuration string of community-list entry. */
19925 static const char *community_list_config_str(struct community_entry *entry)
19926 {
19927 const char *str;
19928
19929 if (entry->any)
19930 str = "";
19931 else {
19932 if (entry->style == COMMUNITY_LIST_STANDARD)
19933 str = community_str(entry->u.com, false, false);
19934 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19935 str = lcommunity_str(entry->u.lcom, false, false);
19936 else
19937 str = entry->config;
19938 }
19939 return str;
19940 }
19941
19942 static void community_list_show(struct vty *vty, struct community_list *list)
19943 {
19944 struct community_entry *entry;
19945
19946 for (entry = list->head; entry; entry = entry->next) {
19947 if (entry == list->head) {
19948 if (all_digit(list->name))
19949 vty_out(vty, "Community %s list %s\n",
19950 entry->style == COMMUNITY_LIST_STANDARD
19951 ? "standard"
19952 : "(expanded) access",
19953 list->name);
19954 else
19955 vty_out(vty, "Named Community %s list %s\n",
19956 entry->style == COMMUNITY_LIST_STANDARD
19957 ? "standard"
19958 : "expanded",
19959 list->name);
19960 }
19961 if (entry->any)
19962 vty_out(vty, " %s\n",
19963 community_direct_str(entry->direct));
19964 else
19965 vty_out(vty, " %s %s\n",
19966 community_direct_str(entry->direct),
19967 community_list_config_str(entry));
19968 }
19969 }
19970
19971 DEFUN (show_community_list,
19972 show_bgp_community_list_cmd,
19973 "show bgp community-list",
19974 SHOW_STR
19975 BGP_STR
19976 "List community-list\n")
19977 {
19978 struct community_list *list;
19979 struct community_list_master *cm;
19980
19981 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19982 if (!cm)
19983 return CMD_SUCCESS;
19984
19985 for (list = cm->num.head; list; list = list->next)
19986 community_list_show(vty, list);
19987
19988 for (list = cm->str.head; list; list = list->next)
19989 community_list_show(vty, list);
19990
19991 return CMD_SUCCESS;
19992 }
19993
19994 DEFUN (show_community_list_arg,
19995 show_bgp_community_list_arg_cmd,
19996 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
19997 SHOW_STR
19998 BGP_STR
19999 "List community-list\n"
20000 "Community-list number\n"
20001 "Community-list name\n"
20002 "Detailed information on community-list\n")
20003 {
20004 int idx_comm_list = 3;
20005 struct community_list *list;
20006
20007 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20008 COMMUNITY_LIST_MASTER);
20009 if (!list) {
20010 vty_out(vty, "%% Can't find community-list\n");
20011 return CMD_WARNING;
20012 }
20013
20014 community_list_show(vty, list);
20015
20016 return CMD_SUCCESS;
20017 }
20018
20019 /*
20020 * Large Community code.
20021 */
20022 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20023 struct cmd_token **argv, int style,
20024 int reject_all_digit_name)
20025 {
20026 int ret;
20027 int direct;
20028 char *str;
20029 int idx = 0;
20030 char *cl_name;
20031 char *seq = NULL;
20032
20033 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20034 seq = argv[idx]->arg;
20035
20036 idx = 0;
20037 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20038 : COMMUNITY_DENY;
20039
20040 /* All digit name check. */
20041 idx = 0;
20042 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20043 argv_find(argv, argc, "(1-99)", &idx);
20044 argv_find(argv, argc, "(100-500)", &idx);
20045 cl_name = argv[idx]->arg;
20046 if (reject_all_digit_name && all_digit(cl_name)) {
20047 vty_out(vty, "%% Community name cannot have all digits\n");
20048 return CMD_WARNING_CONFIG_FAILED;
20049 }
20050
20051 idx = 0;
20052 argv_find(argv, argc, "AA:BB:CC", &idx);
20053 argv_find(argv, argc, "LINE", &idx);
20054 /* Concat community string argument. */
20055 if (idx)
20056 str = argv_concat(argv, argc, idx);
20057 else
20058 str = NULL;
20059
20060 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20061
20062 /* Free temporary community list string allocated by
20063 argv_concat(). */
20064 XFREE(MTYPE_TMP, str);
20065
20066 if (ret < 0) {
20067 community_list_perror(vty, ret);
20068 return CMD_WARNING_CONFIG_FAILED;
20069 }
20070 return CMD_SUCCESS;
20071 }
20072
20073 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20074 struct cmd_token **argv, int style)
20075 {
20076 int ret;
20077 int direct = 0;
20078 char *str = NULL;
20079 int idx = 0;
20080 char *seq = NULL;
20081
20082 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20083 seq = argv[idx]->arg;
20084
20085 idx = 0;
20086 argv_find(argv, argc, "permit", &idx);
20087 argv_find(argv, argc, "deny", &idx);
20088
20089 if (idx) {
20090 /* Check the list direct. */
20091 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20092 direct = COMMUNITY_PERMIT;
20093 else
20094 direct = COMMUNITY_DENY;
20095
20096 idx = 0;
20097 argv_find(argv, argc, "LINE", &idx);
20098 argv_find(argv, argc, "AA:AA:NN", &idx);
20099 /* Concat community string argument. */
20100 str = argv_concat(argv, argc, idx);
20101 }
20102
20103 idx = 0;
20104 argv_find(argv, argc, "(1-99)", &idx);
20105 argv_find(argv, argc, "(100-500)", &idx);
20106 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20107
20108 /* Unset community list. */
20109 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20110 style);
20111
20112 /* Free temporary community list string allocated by
20113 argv_concat(). */
20114 XFREE(MTYPE_TMP, str);
20115
20116 if (ret < 0) {
20117 community_list_perror(vty, ret);
20118 return CMD_WARNING_CONFIG_FAILED;
20119 }
20120
20121 return CMD_SUCCESS;
20122 }
20123
20124 /* "large-community-list" keyword help string. */
20125 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20126 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20127
20128 DEFUN (lcommunity_list_standard,
20129 bgp_lcommunity_list_standard_cmd,
20130 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20131 BGP_STR
20132 LCOMMUNITY_LIST_STR
20133 "Large Community list number (standard)\n"
20134 "Sequence number of an entry\n"
20135 "Sequence number\n"
20136 "Specify large community to reject\n"
20137 "Specify large community to accept\n"
20138 LCOMMUNITY_VAL_STR)
20139 {
20140 return lcommunity_list_set_vty(vty, argc, argv,
20141 LARGE_COMMUNITY_LIST_STANDARD, 0);
20142 }
20143
20144 DEFUN (lcommunity_list_expanded,
20145 bgp_lcommunity_list_expanded_cmd,
20146 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20147 BGP_STR
20148 LCOMMUNITY_LIST_STR
20149 "Large Community list number (expanded)\n"
20150 "Sequence number of an entry\n"
20151 "Sequence number\n"
20152 "Specify large community to reject\n"
20153 "Specify large community to accept\n"
20154 "An ordered list as a regular-expression\n")
20155 {
20156 return lcommunity_list_set_vty(vty, argc, argv,
20157 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20158 }
20159
20160 DEFUN (lcommunity_list_name_standard,
20161 bgp_lcommunity_list_name_standard_cmd,
20162 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20163 BGP_STR
20164 LCOMMUNITY_LIST_STR
20165 "Specify standard large-community-list\n"
20166 "Large Community list name\n"
20167 "Sequence number of an entry\n"
20168 "Sequence number\n"
20169 "Specify large community to reject\n"
20170 "Specify large community to accept\n"
20171 LCOMMUNITY_VAL_STR)
20172 {
20173 return lcommunity_list_set_vty(vty, argc, argv,
20174 LARGE_COMMUNITY_LIST_STANDARD, 1);
20175 }
20176
20177 DEFUN (lcommunity_list_name_expanded,
20178 bgp_lcommunity_list_name_expanded_cmd,
20179 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20180 BGP_STR
20181 LCOMMUNITY_LIST_STR
20182 "Specify expanded large-community-list\n"
20183 "Large Community list name\n"
20184 "Sequence number of an entry\n"
20185 "Sequence number\n"
20186 "Specify large community to reject\n"
20187 "Specify large community to accept\n"
20188 "An ordered list as a regular-expression\n")
20189 {
20190 return lcommunity_list_set_vty(vty, argc, argv,
20191 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20192 }
20193
20194 DEFUN (no_lcommunity_list_all,
20195 no_bgp_lcommunity_list_all_cmd,
20196 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20197 NO_STR
20198 BGP_STR
20199 LCOMMUNITY_LIST_STR
20200 "Large Community list number (standard)\n"
20201 "Large Community list number (expanded)\n"
20202 "Large Community list name\n")
20203 {
20204 return lcommunity_list_unset_vty(vty, argc, argv,
20205 LARGE_COMMUNITY_LIST_STANDARD);
20206 }
20207
20208 DEFUN (no_lcommunity_list_name_standard_all,
20209 no_bgp_lcommunity_list_name_standard_all_cmd,
20210 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20211 NO_STR
20212 BGP_STR
20213 LCOMMUNITY_LIST_STR
20214 "Specify standard large-community-list\n"
20215 "Large Community list name\n")
20216 {
20217 return lcommunity_list_unset_vty(vty, argc, argv,
20218 LARGE_COMMUNITY_LIST_STANDARD);
20219 }
20220
20221 DEFUN (no_lcommunity_list_name_expanded_all,
20222 no_bgp_lcommunity_list_name_expanded_all_cmd,
20223 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20224 NO_STR
20225 BGP_STR
20226 LCOMMUNITY_LIST_STR
20227 "Specify expanded large-community-list\n"
20228 "Large Community list name\n")
20229 {
20230 return lcommunity_list_unset_vty(vty, argc, argv,
20231 LARGE_COMMUNITY_LIST_EXPANDED);
20232 }
20233
20234 DEFUN (no_lcommunity_list_standard,
20235 no_bgp_lcommunity_list_standard_cmd,
20236 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20237 NO_STR
20238 BGP_STR
20239 LCOMMUNITY_LIST_STR
20240 "Large Community list number (standard)\n"
20241 "Sequence number of an entry\n"
20242 "Sequence number\n"
20243 "Specify large community to reject\n"
20244 "Specify large community to accept\n"
20245 LCOMMUNITY_VAL_STR)
20246 {
20247 return lcommunity_list_unset_vty(vty, argc, argv,
20248 LARGE_COMMUNITY_LIST_STANDARD);
20249 }
20250
20251 DEFUN (no_lcommunity_list_expanded,
20252 no_bgp_lcommunity_list_expanded_cmd,
20253 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20254 NO_STR
20255 BGP_STR
20256 LCOMMUNITY_LIST_STR
20257 "Large Community list number (expanded)\n"
20258 "Sequence number of an entry\n"
20259 "Sequence number\n"
20260 "Specify large community to reject\n"
20261 "Specify large community to accept\n"
20262 "An ordered list as a regular-expression\n")
20263 {
20264 return lcommunity_list_unset_vty(vty, argc, argv,
20265 LARGE_COMMUNITY_LIST_EXPANDED);
20266 }
20267
20268 DEFUN (no_lcommunity_list_name_standard,
20269 no_bgp_lcommunity_list_name_standard_cmd,
20270 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20271 NO_STR
20272 BGP_STR
20273 LCOMMUNITY_LIST_STR
20274 "Specify standard large-community-list\n"
20275 "Large Community list name\n"
20276 "Sequence number of an entry\n"
20277 "Sequence number\n"
20278 "Specify large community to reject\n"
20279 "Specify large community to accept\n"
20280 LCOMMUNITY_VAL_STR)
20281 {
20282 return lcommunity_list_unset_vty(vty, argc, argv,
20283 LARGE_COMMUNITY_LIST_STANDARD);
20284 }
20285
20286 DEFUN (no_lcommunity_list_name_expanded,
20287 no_bgp_lcommunity_list_name_expanded_cmd,
20288 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20289 NO_STR
20290 BGP_STR
20291 LCOMMUNITY_LIST_STR
20292 "Specify expanded large-community-list\n"
20293 "Large community list name\n"
20294 "Sequence number of an entry\n"
20295 "Sequence number\n"
20296 "Specify large community to reject\n"
20297 "Specify large community to accept\n"
20298 "An ordered list as a regular-expression\n")
20299 {
20300 return lcommunity_list_unset_vty(vty, argc, argv,
20301 LARGE_COMMUNITY_LIST_EXPANDED);
20302 }
20303
20304 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20305 {
20306 struct community_entry *entry;
20307
20308 for (entry = list->head; entry; entry = entry->next) {
20309 if (entry == list->head) {
20310 if (all_digit(list->name))
20311 vty_out(vty, "Large community %s list %s\n",
20312 entry->style ==
20313 LARGE_COMMUNITY_LIST_STANDARD
20314 ? "standard"
20315 : "(expanded) access",
20316 list->name);
20317 else
20318 vty_out(vty,
20319 "Named large community %s list %s\n",
20320 entry->style ==
20321 LARGE_COMMUNITY_LIST_STANDARD
20322 ? "standard"
20323 : "expanded",
20324 list->name);
20325 }
20326 if (entry->any)
20327 vty_out(vty, " %s\n",
20328 community_direct_str(entry->direct));
20329 else
20330 vty_out(vty, " %s %s\n",
20331 community_direct_str(entry->direct),
20332 community_list_config_str(entry));
20333 }
20334 }
20335
20336 DEFUN (show_lcommunity_list,
20337 show_bgp_lcommunity_list_cmd,
20338 "show bgp large-community-list",
20339 SHOW_STR
20340 BGP_STR
20341 "List large-community list\n")
20342 {
20343 struct community_list *list;
20344 struct community_list_master *cm;
20345
20346 cm = community_list_master_lookup(bgp_clist,
20347 LARGE_COMMUNITY_LIST_MASTER);
20348 if (!cm)
20349 return CMD_SUCCESS;
20350
20351 for (list = cm->num.head; list; list = list->next)
20352 lcommunity_list_show(vty, list);
20353
20354 for (list = cm->str.head; list; list = list->next)
20355 lcommunity_list_show(vty, list);
20356
20357 return CMD_SUCCESS;
20358 }
20359
20360 DEFUN (show_lcommunity_list_arg,
20361 show_bgp_lcommunity_list_arg_cmd,
20362 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20363 SHOW_STR
20364 BGP_STR
20365 "List large-community list\n"
20366 "Large-community-list number\n"
20367 "Large-community-list name\n"
20368 "Detailed information on large-community-list\n")
20369 {
20370 struct community_list *list;
20371
20372 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20373 LARGE_COMMUNITY_LIST_MASTER);
20374 if (!list) {
20375 vty_out(vty, "%% Can't find large-community-list\n");
20376 return CMD_WARNING;
20377 }
20378
20379 lcommunity_list_show(vty, list);
20380
20381 return CMD_SUCCESS;
20382 }
20383
20384 /* "extcommunity-list" keyword help string. */
20385 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20386 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20387
20388 DEFUN (extcommunity_list_standard,
20389 bgp_extcommunity_list_standard_cmd,
20390 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20391 BGP_STR
20392 EXTCOMMUNITY_LIST_STR
20393 "Extended Community list number (standard)\n"
20394 "Specify standard extcommunity-list\n"
20395 "Community list name\n"
20396 "Sequence number of an entry\n"
20397 "Sequence number\n"
20398 "Specify community to reject\n"
20399 "Specify community to accept\n"
20400 EXTCOMMUNITY_VAL_STR)
20401 {
20402 int style = EXTCOMMUNITY_LIST_STANDARD;
20403 int direct = 0;
20404 char *cl_number_or_name = NULL;
20405 char *seq = NULL;
20406
20407 int idx = 0;
20408
20409 argv_find(argv, argc, "(1-99)", &idx);
20410 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20411 cl_number_or_name = argv[idx]->arg;
20412
20413 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20414 seq = argv[idx]->arg;
20415
20416 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20417 : COMMUNITY_DENY;
20418 argv_find(argv, argc, "AA:NN", &idx);
20419 char *str = argv_concat(argv, argc, idx);
20420
20421 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20422 direct, style);
20423
20424 XFREE(MTYPE_TMP, str);
20425
20426 if (ret < 0) {
20427 community_list_perror(vty, ret);
20428 return CMD_WARNING_CONFIG_FAILED;
20429 }
20430
20431 return CMD_SUCCESS;
20432 }
20433
20434 DEFUN (extcommunity_list_name_expanded,
20435 bgp_extcommunity_list_name_expanded_cmd,
20436 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20437 BGP_STR
20438 EXTCOMMUNITY_LIST_STR
20439 "Extended Community list number (expanded)\n"
20440 "Specify expanded extcommunity-list\n"
20441 "Extended Community list name\n"
20442 "Sequence number of an entry\n"
20443 "Sequence number\n"
20444 "Specify community to reject\n"
20445 "Specify community to accept\n"
20446 "An ordered list as a regular-expression\n")
20447 {
20448 int style = EXTCOMMUNITY_LIST_EXPANDED;
20449 int direct = 0;
20450 char *cl_number_or_name = NULL;
20451 char *seq = NULL;
20452 int idx = 0;
20453
20454 argv_find(argv, argc, "(100-500)", &idx);
20455 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20456 cl_number_or_name = argv[idx]->arg;
20457
20458 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20459 seq = argv[idx]->arg;
20460
20461 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20462 : COMMUNITY_DENY;
20463 argv_find(argv, argc, "LINE", &idx);
20464 char *str = argv_concat(argv, argc, idx);
20465
20466 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20467 direct, style);
20468
20469 XFREE(MTYPE_TMP, str);
20470
20471 if (ret < 0) {
20472 community_list_perror(vty, ret);
20473 return CMD_WARNING_CONFIG_FAILED;
20474 }
20475
20476 return CMD_SUCCESS;
20477 }
20478
20479 DEFUN (no_extcommunity_list_standard_all,
20480 no_bgp_extcommunity_list_standard_all_cmd,
20481 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20482 NO_STR
20483 BGP_STR
20484 EXTCOMMUNITY_LIST_STR
20485 "Extended Community list number (standard)\n"
20486 "Specify standard extcommunity-list\n"
20487 "Community list name\n"
20488 "Sequence number of an entry\n"
20489 "Sequence number\n"
20490 "Specify community to reject\n"
20491 "Specify community to accept\n"
20492 EXTCOMMUNITY_VAL_STR)
20493 {
20494 int style = EXTCOMMUNITY_LIST_STANDARD;
20495 int direct = 0;
20496 char *cl_number_or_name = NULL;
20497 char *str = NULL;
20498 char *seq = NULL;
20499 int idx = 0;
20500
20501 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20502 seq = argv[idx]->arg;
20503
20504 idx = 0;
20505 argv_find(argv, argc, "permit", &idx);
20506 argv_find(argv, argc, "deny", &idx);
20507 if (idx) {
20508 direct = argv_find(argv, argc, "permit", &idx)
20509 ? COMMUNITY_PERMIT
20510 : COMMUNITY_DENY;
20511
20512 idx = 0;
20513 argv_find(argv, argc, "AA:NN", &idx);
20514 str = argv_concat(argv, argc, idx);
20515 }
20516
20517 idx = 0;
20518 argv_find(argv, argc, "(1-99)", &idx);
20519 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20520 cl_number_or_name = argv[idx]->arg;
20521
20522 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20523 seq, direct, style);
20524
20525 XFREE(MTYPE_TMP, str);
20526
20527 if (ret < 0) {
20528 community_list_perror(vty, ret);
20529 return CMD_WARNING_CONFIG_FAILED;
20530 }
20531
20532 return CMD_SUCCESS;
20533 }
20534
20535 ALIAS(no_extcommunity_list_standard_all,
20536 no_bgp_extcommunity_list_standard_all_list_cmd,
20537 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20538 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20539 "Extended Community list number (standard)\n"
20540 "Specify standard extcommunity-list\n"
20541 "Community list name\n")
20542
20543 DEFUN (no_extcommunity_list_expanded_all,
20544 no_bgp_extcommunity_list_expanded_all_cmd,
20545 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20546 NO_STR
20547 BGP_STR
20548 EXTCOMMUNITY_LIST_STR
20549 "Extended Community list number (expanded)\n"
20550 "Specify expanded extcommunity-list\n"
20551 "Extended Community list name\n"
20552 "Sequence number of an entry\n"
20553 "Sequence number\n"
20554 "Specify community to reject\n"
20555 "Specify community to accept\n"
20556 "An ordered list as a regular-expression\n")
20557 {
20558 int style = EXTCOMMUNITY_LIST_EXPANDED;
20559 int direct = 0;
20560 char *cl_number_or_name = NULL;
20561 char *str = NULL;
20562 char *seq = NULL;
20563 int idx = 0;
20564
20565 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20566 seq = argv[idx]->arg;
20567
20568 idx = 0;
20569 argv_find(argv, argc, "permit", &idx);
20570 argv_find(argv, argc, "deny", &idx);
20571
20572 if (idx) {
20573 direct = argv_find(argv, argc, "permit", &idx)
20574 ? COMMUNITY_PERMIT
20575 : COMMUNITY_DENY;
20576
20577 idx = 0;
20578 argv_find(argv, argc, "LINE", &idx);
20579 str = argv_concat(argv, argc, idx);
20580 }
20581
20582 idx = 0;
20583 argv_find(argv, argc, "(100-500)", &idx);
20584 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20585 cl_number_or_name = argv[idx]->arg;
20586
20587 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20588 seq, direct, style);
20589
20590 XFREE(MTYPE_TMP, str);
20591
20592 if (ret < 0) {
20593 community_list_perror(vty, ret);
20594 return CMD_WARNING_CONFIG_FAILED;
20595 }
20596
20597 return CMD_SUCCESS;
20598 }
20599
20600 ALIAS(no_extcommunity_list_expanded_all,
20601 no_bgp_extcommunity_list_expanded_all_list_cmd,
20602 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20603 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20604 "Extended Community list number (expanded)\n"
20605 "Specify expanded extcommunity-list\n"
20606 "Extended Community list name\n")
20607
20608 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20609 {
20610 struct community_entry *entry;
20611
20612 for (entry = list->head; entry; entry = entry->next) {
20613 if (entry == list->head) {
20614 if (all_digit(list->name))
20615 vty_out(vty, "Extended community %s list %s\n",
20616 entry->style == EXTCOMMUNITY_LIST_STANDARD
20617 ? "standard"
20618 : "(expanded) access",
20619 list->name);
20620 else
20621 vty_out(vty,
20622 "Named extended community %s list %s\n",
20623 entry->style == EXTCOMMUNITY_LIST_STANDARD
20624 ? "standard"
20625 : "expanded",
20626 list->name);
20627 }
20628 if (entry->any)
20629 vty_out(vty, " %s\n",
20630 community_direct_str(entry->direct));
20631 else
20632 vty_out(vty, " %s %s\n",
20633 community_direct_str(entry->direct),
20634 community_list_config_str(entry));
20635 }
20636 }
20637
20638 DEFUN (show_extcommunity_list,
20639 show_bgp_extcommunity_list_cmd,
20640 "show bgp extcommunity-list",
20641 SHOW_STR
20642 BGP_STR
20643 "List extended-community list\n")
20644 {
20645 struct community_list *list;
20646 struct community_list_master *cm;
20647
20648 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20649 if (!cm)
20650 return CMD_SUCCESS;
20651
20652 for (list = cm->num.head; list; list = list->next)
20653 extcommunity_list_show(vty, list);
20654
20655 for (list = cm->str.head; list; list = list->next)
20656 extcommunity_list_show(vty, list);
20657
20658 return CMD_SUCCESS;
20659 }
20660
20661 DEFUN (show_extcommunity_list_arg,
20662 show_bgp_extcommunity_list_arg_cmd,
20663 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20664 SHOW_STR
20665 BGP_STR
20666 "List extended-community list\n"
20667 "Extcommunity-list number\n"
20668 "Extcommunity-list name\n"
20669 "Detailed information on extcommunity-list\n")
20670 {
20671 int idx_comm_list = 3;
20672 struct community_list *list;
20673
20674 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20675 EXTCOMMUNITY_LIST_MASTER);
20676 if (!list) {
20677 vty_out(vty, "%% Can't find extcommunity-list\n");
20678 return CMD_WARNING;
20679 }
20680
20681 extcommunity_list_show(vty, list);
20682
20683 return CMD_SUCCESS;
20684 }
20685
20686 /* Display community-list and extcommunity-list configuration. */
20687 static int community_list_config_write(struct vty *vty)
20688 {
20689 struct community_list *list;
20690 struct community_entry *entry;
20691 struct community_list_master *cm;
20692 int write = 0;
20693
20694 /* Community-list. */
20695 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20696
20697 for (list = cm->num.head; list; list = list->next)
20698 for (entry = list->head; entry; entry = entry->next) {
20699 vty_out(vty,
20700 "bgp community-list %s seq %" PRId64 " %s %s\n",
20701 list->name, entry->seq,
20702 community_direct_str(entry->direct),
20703 community_list_config_str(entry));
20704 write++;
20705 }
20706 for (list = cm->str.head; list; list = list->next)
20707 for (entry = list->head; entry; entry = entry->next) {
20708 vty_out(vty,
20709 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20710 entry->style == COMMUNITY_LIST_STANDARD
20711 ? "standard"
20712 : "expanded",
20713 list->name, entry->seq,
20714 community_direct_str(entry->direct),
20715 community_list_config_str(entry));
20716 write++;
20717 }
20718
20719 /* Extcommunity-list. */
20720 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20721
20722 for (list = cm->num.head; list; list = list->next)
20723 for (entry = list->head; entry; entry = entry->next) {
20724 vty_out(vty,
20725 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20726 list->name, entry->seq,
20727 community_direct_str(entry->direct),
20728 community_list_config_str(entry));
20729 write++;
20730 }
20731 for (list = cm->str.head; list; list = list->next)
20732 for (entry = list->head; entry; entry = entry->next) {
20733 vty_out(vty,
20734 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20735 entry->style == EXTCOMMUNITY_LIST_STANDARD
20736 ? "standard"
20737 : "expanded",
20738 list->name, entry->seq,
20739 community_direct_str(entry->direct),
20740 community_list_config_str(entry));
20741 write++;
20742 }
20743
20744
20745 /* lcommunity-list. */
20746 cm = community_list_master_lookup(bgp_clist,
20747 LARGE_COMMUNITY_LIST_MASTER);
20748
20749 for (list = cm->num.head; list; list = list->next)
20750 for (entry = list->head; entry; entry = entry->next) {
20751 vty_out(vty,
20752 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20753 list->name, entry->seq,
20754 community_direct_str(entry->direct),
20755 community_list_config_str(entry));
20756 write++;
20757 }
20758 for (list = cm->str.head; list; list = list->next)
20759 for (entry = list->head; entry; entry = entry->next) {
20760 vty_out(vty,
20761 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20762
20763 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20764 ? "standard"
20765 : "expanded",
20766 list->name, entry->seq, community_direct_str(entry->direct),
20767 community_list_config_str(entry));
20768 write++;
20769 }
20770
20771 return write;
20772 }
20773
20774 static int community_list_config_write(struct vty *vty);
20775 static struct cmd_node community_list_node = {
20776 .name = "community list",
20777 .node = COMMUNITY_LIST_NODE,
20778 .prompt = "",
20779 .config_write = community_list_config_write,
20780 };
20781
20782 static void community_list_vty(void)
20783 {
20784 install_node(&community_list_node);
20785
20786 /* Community-list. */
20787 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20788 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20789 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20790 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20791 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20792 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20793 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20794 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20795
20796 /* Extcommunity-list. */
20797 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20798 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20799 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20800 install_element(CONFIG_NODE,
20801 &no_bgp_extcommunity_list_standard_all_list_cmd);
20802 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20803 install_element(CONFIG_NODE,
20804 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20805 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20806 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20807
20808 /* Large Community List */
20809 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20810 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20811 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20812 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20813 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20814 install_element(CONFIG_NODE,
20815 &no_bgp_lcommunity_list_name_standard_all_cmd);
20816 install_element(CONFIG_NODE,
20817 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20818 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20819 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20820 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20821 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20822 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20823 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20824
20825 bgp_community_list_command_completion_setup();
20826 }
20827
20828 static struct cmd_node community_alias_node = {
20829 .name = "community alias",
20830 .node = COMMUNITY_ALIAS_NODE,
20831 .prompt = "",
20832 .config_write = bgp_community_alias_write,
20833 };
20834
20835 void community_alias_vty(void)
20836 {
20837 install_node(&community_alias_node);
20838
20839 /* Community-list. */
20840 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20841
20842 bgp_community_alias_command_completion_setup();
20843 }