]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #11997 from sri-mohan1/sri-zebra-dbg1
[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_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
877 str = "Local-AS allowed only for EBGP peers";
878 break;
879 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
880 str = "Cannot have local-as same as BGP AS number";
881 break;
882 case BGP_ERR_TCPSIG_FAILED:
883 str = "Error while applying TCP-Sig to session(s)";
884 break;
885 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
886 str = "ebgp-multihop and ttl-security cannot be configured together";
887 break;
888 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
889 str = "ttl-security only allowed for EBGP peers";
890 break;
891 case BGP_ERR_AS_OVERRIDE:
892 str = "as-override cannot be configured for IBGP peers";
893 break;
894 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
895 str = "Invalid limit for number of dynamic neighbors";
896 break;
897 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
898 str = "Dynamic neighbor listen range already exists";
899 break;
900 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
901 str = "Operation not allowed on a dynamic neighbor";
902 break;
903 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
904 str = "Operation not allowed on a directly connected neighbor";
905 break;
906 case BGP_ERR_PEER_SAFI_CONFLICT:
907 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
908 break;
909 case BGP_ERR_GR_INVALID_CMD:
910 str = "The Graceful Restart command used is not valid at this moment.";
911 break;
912 case BGP_ERR_GR_OPERATION_FAILED:
913 str = "The Graceful Restart Operation failed due to an err.";
914 break;
915 case BGP_ERR_PEER_GROUP_MEMBER:
916 str = "Peer-group member cannot override remote-as of peer-group.";
917 break;
918 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
919 str = "Peer-group members must be all internal or all external.";
920 break;
921 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
922 str = "Range specified cannot be deleted because it is not part of current config.";
923 break;
924 case BGP_ERR_INSTANCE_MISMATCH:
925 str = "Instance specified does not match the current instance.";
926 break;
927 case BGP_ERR_NO_INTERFACE_CONFIG:
928 str = "Interface specified is not being used for interface based peer.";
929 break;
930 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
931 str = "No configuration already specified for soft reconfiguration.";
932 break;
933 case BGP_ERR_AS_MISMATCH:
934 str = "BGP is already running.";
935 break;
936 case BGP_ERR_AF_UNCONFIGURED:
937 str = "AFI/SAFI specified is not currently configured.";
938 break;
939 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS:
940 str = "AS specified for local as is the same as the remote as and this is not allowed.";
941 break;
942 case BGP_ERR_INVALID_AS:
943 str = "Confederation AS specified is the same AS as our AS.";
944 break;
945 case BGP_ERR_INVALID_ROLE_NAME:
946 str = "Invalid role name";
947 break;
948 case BGP_ERR_INVALID_INTERNAL_ROLE:
949 str = "External roles can be set only on eBGP session";
950 break;
951 }
952 if (str) {
953 vty_out(vty, "%% %s\n", str);
954 return CMD_WARNING_CONFIG_FAILED;
955 }
956 return CMD_SUCCESS;
957 }
958
959 /* BGP clear sort. */
960 enum clear_sort {
961 clear_all,
962 clear_peer,
963 clear_group,
964 clear_external,
965 clear_as
966 };
967
968 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
969 safi_t safi, int error)
970 {
971 switch (error) {
972 case BGP_ERR_AF_UNCONFIGURED:
973 if (vty)
974 vty_out(vty,
975 "%% BGP: Enable %s address family for the neighbor %s\n",
976 get_afi_safi_str(afi, safi, false), peer->host);
977 else
978 zlog_warn(
979 "%% BGP: Enable %s address family for the neighbor %s",
980 get_afi_safi_str(afi, safi, false), peer->host);
981 break;
982 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
983 if (vty)
984 vty_out(vty,
985 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
986 peer->host);
987 else
988 zlog_warn(
989 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
990 peer->host);
991 break;
992 default:
993 break;
994 }
995 }
996
997 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
998 struct listnode **nnode, enum bgp_clear_type stype)
999 {
1000 int ret = 0;
1001 struct peer_af *paf;
1002
1003 /* if afi/.safi not specified, spin thru all of them */
1004 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1005 afi_t tmp_afi;
1006 safi_t tmp_safi;
1007 enum bgp_af_index index;
1008
1009 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1010 paf = peer->peer_af_array[index];
1011 if (!paf)
1012 continue;
1013
1014 if (paf && paf->subgroup)
1015 SET_FLAG(paf->subgroup->sflags,
1016 SUBGRP_STATUS_FORCE_UPDATES);
1017
1018 tmp_afi = paf->afi;
1019 tmp_safi = paf->safi;
1020 if (!peer->afc[tmp_afi][tmp_safi])
1021 continue;
1022
1023 if (stype == BGP_CLEAR_SOFT_NONE)
1024 ret = peer_clear(peer, nnode);
1025 else
1026 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1027 stype);
1028 }
1029 /* if afi specified and safi not, spin thru safis on this afi */
1030 } else if (safi == SAFI_UNSPEC) {
1031 safi_t tmp_safi;
1032
1033 for (tmp_safi = SAFI_UNICAST;
1034 tmp_safi < SAFI_MAX; tmp_safi++) {
1035 if (!peer->afc[afi][tmp_safi])
1036 continue;
1037
1038 paf = peer_af_find(peer, afi, tmp_safi);
1039 if (paf && paf->subgroup)
1040 SET_FLAG(paf->subgroup->sflags,
1041 SUBGRP_STATUS_FORCE_UPDATES);
1042
1043 if (stype == BGP_CLEAR_SOFT_NONE)
1044 ret = peer_clear(peer, nnode);
1045 else
1046 ret = peer_clear_soft(peer, afi,
1047 tmp_safi, stype);
1048 }
1049 /* both afi/safi specified, let the caller know if not defined */
1050 } else {
1051 if (!peer->afc[afi][safi])
1052 return 1;
1053
1054 paf = peer_af_find(peer, afi, safi);
1055 if (paf && paf->subgroup)
1056 SET_FLAG(paf->subgroup->sflags,
1057 SUBGRP_STATUS_FORCE_UPDATES);
1058
1059 if (stype == BGP_CLEAR_SOFT_NONE)
1060 ret = peer_clear(peer, nnode);
1061 else
1062 ret = peer_clear_soft(peer, afi, safi, stype);
1063 }
1064
1065 return ret;
1066 }
1067
1068 /* `clear ip bgp' functions. */
1069 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1070 enum clear_sort sort, enum bgp_clear_type stype,
1071 const char *arg)
1072 {
1073 int ret = 0;
1074 bool found = false;
1075 struct peer *peer;
1076
1077 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1078
1079 /* Clear all neighbors. */
1080 /*
1081 * Pass along pointer to next node to peer_clear() when walking all
1082 * nodes on the BGP instance as that may get freed if it is a
1083 * doppelganger
1084 */
1085 if (sort == clear_all) {
1086 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1087
1088 bgp_peer_gr_flags_update(peer);
1089
1090 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1091 gr_router_detected = true;
1092
1093 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1094 stype);
1095
1096 if (ret < 0)
1097 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1098 }
1099
1100 if (gr_router_detected
1101 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1102 bgp_zebra_send_capabilities(bgp, false);
1103 } else if (!gr_router_detected
1104 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1105 bgp_zebra_send_capabilities(bgp, true);
1106 }
1107
1108 /* This is to apply read-only mode on this clear. */
1109 if (stype == BGP_CLEAR_SOFT_NONE)
1110 bgp->update_delay_over = 0;
1111
1112 return CMD_SUCCESS;
1113 }
1114
1115 /* Clear specified neighbor. */
1116 if (sort == clear_peer) {
1117 union sockunion su;
1118
1119 /* Make sockunion for lookup. */
1120 ret = str2sockunion(arg, &su);
1121 if (ret < 0) {
1122 peer = peer_lookup_by_conf_if(bgp, arg);
1123 if (!peer) {
1124 peer = peer_lookup_by_hostname(bgp, arg);
1125 if (!peer) {
1126 vty_out(vty,
1127 "Malformed address or name: %s\n",
1128 arg);
1129 return CMD_WARNING;
1130 }
1131 }
1132 } else {
1133 peer = peer_lookup(bgp, &su);
1134 if (!peer) {
1135 vty_out(vty,
1136 "%% BGP: Unknown neighbor - \"%s\"\n",
1137 arg);
1138 return CMD_WARNING;
1139 }
1140 }
1141
1142 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1143 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1144
1145 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1146
1147 /* if afi/safi not defined for this peer, let caller know */
1148 if (ret == 1)
1149 ret = BGP_ERR_AF_UNCONFIGURED;
1150
1151 if (ret < 0)
1152 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1153
1154 return CMD_SUCCESS;
1155 }
1156
1157 /* Clear all neighbors belonging to a specific peer-group. */
1158 if (sort == clear_group) {
1159 struct peer_group *group;
1160
1161 group = peer_group_lookup(bgp, arg);
1162 if (!group) {
1163 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1164 return CMD_WARNING;
1165 }
1166
1167 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1168 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1169
1170 if (ret < 0)
1171 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1172 else
1173 found = true;
1174 }
1175
1176 if (!found)
1177 vty_out(vty,
1178 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1179 get_afi_safi_str(afi, safi, false), arg);
1180
1181 return CMD_SUCCESS;
1182 }
1183
1184 /* Clear all external (eBGP) neighbors. */
1185 if (sort == clear_external) {
1186 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1187 if (peer->sort == BGP_PEER_IBGP)
1188 continue;
1189
1190 bgp_peer_gr_flags_update(peer);
1191
1192 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1193 gr_router_detected = true;
1194
1195 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1196
1197 if (ret < 0)
1198 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1199 else
1200 found = true;
1201 }
1202
1203 if (gr_router_detected
1204 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1205 bgp_zebra_send_capabilities(bgp, false);
1206 } else if (!gr_router_detected
1207 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1208 bgp_zebra_send_capabilities(bgp, true);
1209 }
1210
1211 if (!found)
1212 vty_out(vty,
1213 "%% BGP: No external %s peer is configured\n",
1214 get_afi_safi_str(afi, safi, false));
1215
1216 return CMD_SUCCESS;
1217 }
1218
1219 /* Clear all neighbors belonging to a specific AS. */
1220 if (sort == clear_as) {
1221 as_t as = strtoul(arg, NULL, 10);
1222
1223 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1224 if (peer->as != as)
1225 continue;
1226
1227 bgp_peer_gr_flags_update(peer);
1228
1229 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1230 gr_router_detected = true;
1231
1232 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1233
1234 if (ret < 0)
1235 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1236 else
1237 found = true;
1238 }
1239
1240 if (gr_router_detected
1241 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1242 bgp_zebra_send_capabilities(bgp, false);
1243 } else if (!gr_router_detected
1244 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1245 bgp_zebra_send_capabilities(bgp, true);
1246 }
1247
1248 if (!found)
1249 vty_out(vty,
1250 "%% BGP: No %s peer is configured with AS %s\n",
1251 get_afi_safi_str(afi, safi, false), arg);
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 return CMD_SUCCESS;
1257 }
1258
1259 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1260 safi_t safi, enum clear_sort sort,
1261 enum bgp_clear_type stype, const char *arg)
1262 {
1263 struct bgp *bgp;
1264
1265 /* BGP structure lookup. */
1266 if (name) {
1267 bgp = bgp_lookup_by_name(name);
1268 if (bgp == NULL) {
1269 vty_out(vty, "Can't find BGP instance %s\n", name);
1270 return CMD_WARNING;
1271 }
1272 } else {
1273 bgp = bgp_get_default();
1274 if (bgp == NULL) {
1275 vty_out(vty, "No BGP process is configured\n");
1276 return CMD_WARNING;
1277 }
1278 }
1279
1280 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1281 }
1282
1283 /* clear soft inbound */
1284 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1285 {
1286 afi_t afi;
1287 safi_t safi;
1288
1289 FOREACH_AFI_SAFI (afi, safi)
1290 bgp_clear_vty(vty, name, afi, safi, clear_all,
1291 BGP_CLEAR_SOFT_IN, NULL);
1292 }
1293
1294 /* clear soft outbound */
1295 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1296 {
1297 afi_t afi;
1298 safi_t safi;
1299
1300 FOREACH_AFI_SAFI (afi, safi)
1301 bgp_clear_vty(vty, name, afi, safi, clear_all,
1302 BGP_CLEAR_SOFT_OUT, NULL);
1303 }
1304
1305
1306 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1307 {
1308 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1309 }
1310
1311 #ifndef VTYSH_EXTRACT_PL
1312 #include "bgpd/bgp_vty_clippy.c"
1313 #endif
1314
1315 DEFUN_HIDDEN (bgp_local_mac,
1316 bgp_local_mac_cmd,
1317 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1318 BGP_STR
1319 "Local MAC config\n"
1320 "VxLAN Network Identifier\n"
1321 "VNI number\n"
1322 "local mac\n"
1323 "mac address\n"
1324 "mac-mobility sequence\n"
1325 "seq number\n")
1326 {
1327 int rv;
1328 vni_t vni;
1329 struct ethaddr mac;
1330 struct ipaddr ip;
1331 uint32_t seq;
1332 struct bgp *bgp;
1333
1334 vni = strtoul(argv[3]->arg, NULL, 10);
1335 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1336 vty_out(vty, "%% Malformed MAC address\n");
1337 return CMD_WARNING;
1338 }
1339 memset(&ip, 0, sizeof(ip));
1340 seq = strtoul(argv[7]->arg, NULL, 10);
1341
1342 bgp = bgp_get_default();
1343 if (!bgp) {
1344 vty_out(vty, "Default BGP instance is not there\n");
1345 return CMD_WARNING;
1346 }
1347
1348 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1349 zero_esi);
1350 if (rv < 0) {
1351 vty_out(vty, "Internal error\n");
1352 return CMD_WARNING;
1353 }
1354
1355 return CMD_SUCCESS;
1356 }
1357
1358 DEFUN_HIDDEN (no_bgp_local_mac,
1359 no_bgp_local_mac_cmd,
1360 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1361 NO_STR
1362 BGP_STR
1363 "Local MAC config\n"
1364 "VxLAN Network Identifier\n"
1365 "VNI number\n"
1366 "local mac\n"
1367 "mac address\n")
1368 {
1369 int rv;
1370 vni_t vni;
1371 struct ethaddr mac;
1372 struct ipaddr ip;
1373 struct bgp *bgp;
1374
1375 vni = strtoul(argv[4]->arg, NULL, 10);
1376 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1377 vty_out(vty, "%% Malformed MAC address\n");
1378 return CMD_WARNING;
1379 }
1380 memset(&ip, 0, sizeof(ip));
1381
1382 bgp = bgp_get_default();
1383 if (!bgp) {
1384 vty_out(vty, "Default BGP instance is not there\n");
1385 return CMD_WARNING;
1386 }
1387
1388 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1389 if (rv < 0) {
1390 vty_out(vty, "Internal error\n");
1391 return CMD_WARNING;
1392 }
1393
1394 return CMD_SUCCESS;
1395 }
1396
1397 DEFUN (no_synchronization,
1398 no_synchronization_cmd,
1399 "no synchronization",
1400 NO_STR
1401 "Perform IGP synchronization\n")
1402 {
1403 return CMD_SUCCESS;
1404 }
1405
1406 DEFUN (no_auto_summary,
1407 no_auto_summary_cmd,
1408 "no auto-summary",
1409 NO_STR
1410 "Enable automatic network number summarization\n")
1411 {
1412 return CMD_SUCCESS;
1413 }
1414
1415 /* "router bgp" commands. */
1416 DEFUN_NOSH (router_bgp,
1417 router_bgp_cmd,
1418 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1419 ROUTER_STR
1420 BGP_STR
1421 AS_STR
1422 BGP_INSTANCE_HELP_STR)
1423 {
1424 int idx_asn = 2;
1425 int idx_view_vrf = 3;
1426 int idx_vrf = 4;
1427 int is_new_bgp = 0;
1428 int ret;
1429 as_t as;
1430 struct bgp *bgp;
1431 const char *name = NULL;
1432 enum bgp_instance_type inst_type;
1433
1434 // "router bgp" without an ASN
1435 if (argc == 2) {
1436 // Pending: Make VRF option available for ASN less config
1437 bgp = bgp_get_default();
1438
1439 if (bgp == NULL) {
1440 vty_out(vty, "%% No BGP process is configured\n");
1441 return CMD_WARNING_CONFIG_FAILED;
1442 }
1443
1444 if (listcount(bm->bgp) > 1) {
1445 vty_out(vty, "%% Please specify ASN and VRF\n");
1446 return CMD_WARNING_CONFIG_FAILED;
1447 }
1448 }
1449
1450 // "router bgp X"
1451 else {
1452 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1453
1454 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1455 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1456 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1457
1458 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1459 if (argc > 3) {
1460 name = argv[idx_vrf]->arg;
1461
1462 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1463 if (strmatch(name, VRF_DEFAULT_NAME))
1464 name = NULL;
1465 else
1466 inst_type = BGP_INSTANCE_TYPE_VRF;
1467 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1468 inst_type = BGP_INSTANCE_TYPE_VIEW;
1469 }
1470
1471 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1472 is_new_bgp = (bgp_lookup(as, name) == NULL);
1473
1474 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1475 switch (ret) {
1476 case BGP_ERR_AS_MISMATCH:
1477 vty_out(vty, "BGP is already running; AS is %u\n", as);
1478 return CMD_WARNING_CONFIG_FAILED;
1479 case BGP_ERR_INSTANCE_MISMATCH:
1480 vty_out(vty,
1481 "BGP instance name and AS number mismatch\n");
1482 vty_out(vty,
1483 "BGP instance is already running; AS is %u\n",
1484 as);
1485 return CMD_WARNING_CONFIG_FAILED;
1486 }
1487
1488 /*
1489 * If we just instantiated the default instance, complete
1490 * any pending VRF-VPN leaking that was configured via
1491 * earlier "router bgp X vrf FOO" blocks.
1492 */
1493 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1494 vpn_leak_postchange_all();
1495
1496 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1497 bgp_vpn_leak_export(bgp);
1498 /* Pending: handle when user tries to change a view to vrf n vv.
1499 */
1500 }
1501
1502 /* unset the auto created flag as the user config is now present */
1503 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1504 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1505
1506 return CMD_SUCCESS;
1507 }
1508
1509 /* "no router bgp" commands. */
1510 DEFUN (no_router_bgp,
1511 no_router_bgp_cmd,
1512 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1513 NO_STR
1514 ROUTER_STR
1515 BGP_STR
1516 AS_STR
1517 BGP_INSTANCE_HELP_STR)
1518 {
1519 int idx_asn = 3;
1520 int idx_vrf = 5;
1521 as_t as;
1522 struct bgp *bgp;
1523 const char *name = NULL;
1524
1525 // "no router bgp" without an ASN
1526 if (argc == 3) {
1527 // Pending: Make VRF option available for ASN less config
1528 bgp = bgp_get_default();
1529
1530 if (bgp == NULL) {
1531 vty_out(vty, "%% No BGP process is configured\n");
1532 return CMD_WARNING_CONFIG_FAILED;
1533 }
1534
1535 if (listcount(bm->bgp) > 1) {
1536 vty_out(vty, "%% Please specify ASN and VRF\n");
1537 return CMD_WARNING_CONFIG_FAILED;
1538 }
1539
1540 if (bgp->l3vni) {
1541 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1542 bgp->l3vni);
1543 return CMD_WARNING_CONFIG_FAILED;
1544 }
1545 } else {
1546 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1547
1548 if (argc > 4) {
1549 name = argv[idx_vrf]->arg;
1550 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1551 && strmatch(name, VRF_DEFAULT_NAME))
1552 name = NULL;
1553 }
1554
1555 /* Lookup bgp structure. */
1556 bgp = bgp_lookup(as, name);
1557 if (!bgp) {
1558 vty_out(vty, "%% Can't find BGP instance\n");
1559 return CMD_WARNING_CONFIG_FAILED;
1560 }
1561
1562 if (bgp->l3vni) {
1563 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1564 bgp->l3vni);
1565 return CMD_WARNING_CONFIG_FAILED;
1566 }
1567
1568 /* Cannot delete default instance if vrf instances exist */
1569 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1570 struct listnode *node;
1571 struct bgp *tmp_bgp;
1572
1573 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1574 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1575 continue;
1576 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1577 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1578 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1579 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1580 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1581 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1582 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1583 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1584 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1585 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1586 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1587 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1588 (bgp == bgp_get_evpn() &&
1589 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1590 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1591 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1592 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1593 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1594 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1595 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1596 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1597 (hashcount(tmp_bgp->vnihash))) {
1598 vty_out(vty,
1599 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1600 return CMD_WARNING_CONFIG_FAILED;
1601 }
1602 }
1603 }
1604 }
1605
1606 bgp_delete(bgp);
1607
1608 return CMD_SUCCESS;
1609 }
1610
1611 /* bgp session-dscp */
1612
1613 DEFPY (bgp_session_dscp,
1614 bgp_session_dscp_cmd,
1615 "bgp session-dscp (0-63)$dscp",
1616 BGP_STR
1617 "Override default (C6) bgp TCP session DSCP value\n"
1618 "Manually configured dscp parameter\n")
1619 {
1620 bm->tcp_dscp = dscp << 2;
1621
1622 return CMD_SUCCESS;
1623 }
1624
1625 DEFPY (no_bgp_session_dscp,
1626 no_bgp_session_dscp_cmd,
1627 "no bgp session-dscp [(0-63)]",
1628 NO_STR
1629 BGP_STR
1630 "Override default (C6) bgp TCP session DSCP value\n"
1631 "Manually configured dscp parameter\n")
1632 {
1633 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1634
1635 return CMD_SUCCESS;
1636 }
1637
1638 /* BGP router-id. */
1639
1640 DEFPY (bgp_router_id,
1641 bgp_router_id_cmd,
1642 "bgp router-id A.B.C.D",
1643 BGP_STR
1644 "Override configured router identifier\n"
1645 "Manually configured router identifier\n")
1646 {
1647 VTY_DECLVAR_CONTEXT(bgp, bgp);
1648 bgp_router_id_static_set(bgp, router_id);
1649 return CMD_SUCCESS;
1650 }
1651
1652 DEFPY (no_bgp_router_id,
1653 no_bgp_router_id_cmd,
1654 "no bgp router-id [A.B.C.D]",
1655 NO_STR
1656 BGP_STR
1657 "Override configured router identifier\n"
1658 "Manually configured router identifier\n")
1659 {
1660 VTY_DECLVAR_CONTEXT(bgp, bgp);
1661
1662 if (router_id_str) {
1663 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1664 vty_out(vty, "%% BGP router-id doesn't match\n");
1665 return CMD_WARNING_CONFIG_FAILED;
1666 }
1667 }
1668
1669 router_id.s_addr = 0;
1670 bgp_router_id_static_set(bgp, router_id);
1671
1672 return CMD_SUCCESS;
1673 }
1674
1675 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1676 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1677 NO_STR BGP_STR
1678 "Add community specific parameters\n"
1679 "Create an alias for a community\n"
1680 "Community (AA:BB or AA:BB:CC)\n"
1681 "Alias name\n")
1682 {
1683 struct community_alias ca = {};
1684 struct community_alias *lookup_community;
1685 struct community_alias *lookup_alias;
1686 struct community *comm;
1687 struct lcommunity *lcomm;
1688 uint8_t invalid = 0;
1689
1690 comm = community_str2com(community);
1691 if (!comm)
1692 invalid++;
1693 community_free(&comm);
1694
1695 lcomm = lcommunity_str2com(community);
1696 if (!lcomm)
1697 invalid++;
1698 lcommunity_free(&lcomm);
1699
1700 if (invalid > 1) {
1701 vty_out(vty, "Invalid community format\n");
1702 return CMD_WARNING;
1703 }
1704
1705 strlcpy(ca.community, community, sizeof(ca.community));
1706 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1707
1708 lookup_community = bgp_ca_community_lookup(&ca);
1709 lookup_alias = bgp_ca_alias_lookup(&ca);
1710
1711 if (no) {
1712 bgp_ca_alias_delete(&ca);
1713 bgp_ca_community_delete(&ca);
1714 } else {
1715 if (lookup_alias) {
1716 /* Lookup if community hash table has an item
1717 * with the same alias name.
1718 */
1719 strlcpy(ca.community, lookup_alias->community,
1720 sizeof(ca.community));
1721 if (bgp_ca_community_lookup(&ca)) {
1722 vty_out(vty,
1723 "community (%s) already has this alias (%s)\n",
1724 lookup_alias->community,
1725 lookup_alias->alias);
1726 return CMD_WARNING;
1727 }
1728 bgp_ca_alias_delete(&ca);
1729 }
1730
1731 if (lookup_community) {
1732 /* Lookup if alias hash table has an item
1733 * with the same community.
1734 */
1735 strlcpy(ca.alias, lookup_community->alias,
1736 sizeof(ca.alias));
1737 if (bgp_ca_alias_lookup(&ca)) {
1738 vty_out(vty,
1739 "alias (%s) already has this community (%s)\n",
1740 lookup_community->alias,
1741 lookup_community->community);
1742 return CMD_WARNING;
1743 }
1744 bgp_ca_community_delete(&ca);
1745 }
1746
1747 bgp_ca_alias_insert(&ca);
1748 bgp_ca_community_insert(&ca);
1749 }
1750
1751 return CMD_SUCCESS;
1752 }
1753
1754 DEFPY (bgp_global_suppress_fib_pending,
1755 bgp_global_suppress_fib_pending_cmd,
1756 "[no] bgp suppress-fib-pending",
1757 NO_STR
1758 BGP_STR
1759 "Advertise only routes that are programmed in kernel to peers globally\n")
1760 {
1761 bm_wait_for_fib_set(!no);
1762
1763 return CMD_SUCCESS;
1764 }
1765
1766 DEFPY (bgp_suppress_fib_pending,
1767 bgp_suppress_fib_pending_cmd,
1768 "[no] bgp suppress-fib-pending",
1769 NO_STR
1770 BGP_STR
1771 "Advertise only routes that are programmed in kernel to peers\n")
1772 {
1773 VTY_DECLVAR_CONTEXT(bgp, bgp);
1774
1775 bgp_suppress_fib_pending_set(bgp, !no);
1776 return CMD_SUCCESS;
1777 }
1778
1779
1780 /* BGP Cluster ID. */
1781 DEFUN (bgp_cluster_id,
1782 bgp_cluster_id_cmd,
1783 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1784 BGP_STR
1785 "Configure Route-Reflector Cluster-id\n"
1786 "Route-Reflector Cluster-id in IP address format\n"
1787 "Route-Reflector Cluster-id as 32 bit quantity\n")
1788 {
1789 VTY_DECLVAR_CONTEXT(bgp, bgp);
1790 int idx_ipv4 = 2;
1791 int ret;
1792 struct in_addr cluster;
1793
1794 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1795 if (!ret) {
1796 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1797 return CMD_WARNING_CONFIG_FAILED;
1798 }
1799
1800 bgp_cluster_id_set(bgp, &cluster);
1801 bgp_clear_star_soft_out(vty, bgp->name);
1802
1803 return CMD_SUCCESS;
1804 }
1805
1806 DEFUN (no_bgp_cluster_id,
1807 no_bgp_cluster_id_cmd,
1808 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1809 NO_STR
1810 BGP_STR
1811 "Configure Route-Reflector Cluster-id\n"
1812 "Route-Reflector Cluster-id in IP address format\n"
1813 "Route-Reflector Cluster-id as 32 bit quantity\n")
1814 {
1815 VTY_DECLVAR_CONTEXT(bgp, bgp);
1816 bgp_cluster_id_unset(bgp);
1817 bgp_clear_star_soft_out(vty, bgp->name);
1818
1819 return CMD_SUCCESS;
1820 }
1821
1822 DEFPY (bgp_norib,
1823 bgp_norib_cmd,
1824 "bgp no-rib",
1825 BGP_STR
1826 "Disable BGP route installation to RIB (Zebra)\n")
1827 {
1828 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1829 vty_out(vty,
1830 "%% No-RIB option is already set, nothing to do here.\n");
1831 return CMD_SUCCESS;
1832 }
1833
1834 bgp_option_norib_set_runtime();
1835
1836 return CMD_SUCCESS;
1837 }
1838
1839 DEFPY (no_bgp_norib,
1840 no_bgp_norib_cmd,
1841 "no bgp no-rib",
1842 NO_STR
1843 BGP_STR
1844 "Disable BGP route installation to RIB (Zebra)\n")
1845 {
1846 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1847 vty_out(vty,
1848 "%% No-RIB option is not set, nothing to do here.\n");
1849 return CMD_SUCCESS;
1850 }
1851
1852 bgp_option_norib_unset_runtime();
1853
1854 return CMD_SUCCESS;
1855 }
1856
1857 DEFPY (no_bgp_send_extra_data,
1858 no_bgp_send_extra_data_cmd,
1859 "[no] bgp send-extra-data zebra",
1860 NO_STR
1861 BGP_STR
1862 "Extra data to Zebra for display/use\n"
1863 "To zebra\n")
1864 {
1865 if (no)
1866 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1867 else
1868 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1869
1870 return CMD_SUCCESS;
1871 }
1872
1873 DEFUN (bgp_confederation_identifier,
1874 bgp_confederation_identifier_cmd,
1875 "bgp confederation identifier (1-4294967295)",
1876 BGP_STR
1877 "AS confederation parameters\n"
1878 "AS number\n"
1879 "Set routing domain confederation AS\n")
1880 {
1881 VTY_DECLVAR_CONTEXT(bgp, bgp);
1882 int idx_number = 3;
1883 as_t as;
1884
1885 as = strtoul(argv[idx_number]->arg, NULL, 10);
1886
1887 bgp_confederation_id_set(bgp, as);
1888
1889 return CMD_SUCCESS;
1890 }
1891
1892 DEFUN (no_bgp_confederation_identifier,
1893 no_bgp_confederation_identifier_cmd,
1894 "no bgp confederation identifier [(1-4294967295)]",
1895 NO_STR
1896 BGP_STR
1897 "AS confederation parameters\n"
1898 "AS number\n"
1899 "Set routing domain confederation AS\n")
1900 {
1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902 bgp_confederation_id_unset(bgp);
1903
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (bgp_confederation_peers,
1908 bgp_confederation_peers_cmd,
1909 "bgp confederation peers (1-4294967295)...",
1910 BGP_STR
1911 "AS confederation parameters\n"
1912 "Peer ASs in BGP confederation\n"
1913 AS_STR)
1914 {
1915 VTY_DECLVAR_CONTEXT(bgp, bgp);
1916 int idx_asn = 3;
1917 as_t as;
1918 int i;
1919
1920 for (i = idx_asn; i < argc; i++) {
1921 as = strtoul(argv[i]->arg, NULL, 10);
1922
1923 if (bgp->as == as) {
1924 vty_out(vty,
1925 "%% Local member-AS not allowed in confed peer list\n");
1926 continue;
1927 }
1928
1929 bgp_confederation_peers_add(bgp, as);
1930 }
1931 return CMD_SUCCESS;
1932 }
1933
1934 DEFUN (no_bgp_confederation_peers,
1935 no_bgp_confederation_peers_cmd,
1936 "no bgp confederation peers (1-4294967295)...",
1937 NO_STR
1938 BGP_STR
1939 "AS confederation parameters\n"
1940 "Peer ASs in BGP confederation\n"
1941 AS_STR)
1942 {
1943 VTY_DECLVAR_CONTEXT(bgp, bgp);
1944 int idx_asn = 4;
1945 as_t as;
1946 int i;
1947
1948 for (i = idx_asn; i < argc; i++) {
1949 as = strtoul(argv[i]->arg, NULL, 10);
1950
1951 bgp_confederation_peers_remove(bgp, as);
1952 }
1953 return CMD_SUCCESS;
1954 }
1955
1956 /**
1957 * Central routine for maximum-paths configuration.
1958 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1959 * @set: 1 for setting values, 0 for removing the max-paths config.
1960 */
1961 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1962 const char *mpaths, uint16_t options,
1963 int set)
1964 {
1965 VTY_DECLVAR_CONTEXT(bgp, bgp);
1966 uint16_t maxpaths = 0;
1967 int ret;
1968 afi_t afi;
1969 safi_t safi;
1970
1971 afi = bgp_node_afi(vty);
1972 safi = bgp_node_safi(vty);
1973
1974 if (set) {
1975 maxpaths = strtol(mpaths, NULL, 10);
1976 if (maxpaths > multipath_num) {
1977 vty_out(vty,
1978 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1979 maxpaths, multipath_num);
1980 return CMD_WARNING_CONFIG_FAILED;
1981 }
1982 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1983 options);
1984 } else
1985 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1986
1987 if (ret < 0) {
1988 vty_out(vty,
1989 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1990 (set == 1) ? "" : "un",
1991 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1992 maxpaths, afi, safi);
1993 return CMD_WARNING_CONFIG_FAILED;
1994 }
1995
1996 bgp_recalculate_all_bestpaths(bgp);
1997
1998 return CMD_SUCCESS;
1999 }
2000
2001 DEFUN (bgp_maxmed_admin,
2002 bgp_maxmed_admin_cmd,
2003 "bgp max-med administrative ",
2004 BGP_STR
2005 "Advertise routes with max-med\n"
2006 "Administratively applied, for an indefinite period\n")
2007 {
2008 VTY_DECLVAR_CONTEXT(bgp, bgp);
2009
2010 bgp->v_maxmed_admin = 1;
2011 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2012
2013 bgp_maxmed_update(bgp);
2014
2015 return CMD_SUCCESS;
2016 }
2017
2018 DEFUN (bgp_maxmed_admin_medv,
2019 bgp_maxmed_admin_medv_cmd,
2020 "bgp max-med administrative (0-4294967295)",
2021 BGP_STR
2022 "Advertise routes with max-med\n"
2023 "Administratively applied, for an indefinite period\n"
2024 "Max MED value to be used\n")
2025 {
2026 VTY_DECLVAR_CONTEXT(bgp, bgp);
2027 int idx_number = 3;
2028
2029 bgp->v_maxmed_admin = 1;
2030 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2031
2032 bgp_maxmed_update(bgp);
2033
2034 return CMD_SUCCESS;
2035 }
2036
2037 DEFUN (no_bgp_maxmed_admin,
2038 no_bgp_maxmed_admin_cmd,
2039 "no bgp max-med administrative [(0-4294967295)]",
2040 NO_STR
2041 BGP_STR
2042 "Advertise routes with max-med\n"
2043 "Administratively applied, for an indefinite period\n"
2044 "Max MED value to be used\n")
2045 {
2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
2047 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2048 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2049 bgp_maxmed_update(bgp);
2050
2051 return CMD_SUCCESS;
2052 }
2053
2054 DEFUN (bgp_maxmed_onstartup,
2055 bgp_maxmed_onstartup_cmd,
2056 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2057 BGP_STR
2058 "Advertise routes with max-med\n"
2059 "Effective on a startup\n"
2060 "Time (seconds) period for max-med\n"
2061 "Max MED value to be used\n")
2062 {
2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
2064 int idx = 0;
2065
2066 if (argv_find(argv, argc, "(5-86400)", &idx))
2067 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2068 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2069 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2070 else
2071 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2072
2073 bgp_maxmed_update(bgp);
2074
2075 return CMD_SUCCESS;
2076 }
2077
2078 DEFUN (no_bgp_maxmed_onstartup,
2079 no_bgp_maxmed_onstartup_cmd,
2080 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2081 NO_STR
2082 BGP_STR
2083 "Advertise routes with max-med\n"
2084 "Effective on a startup\n"
2085 "Time (seconds) period for max-med\n"
2086 "Max MED value to be used\n")
2087 {
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
2090 /* Cancel max-med onstartup if its on */
2091 if (bgp->t_maxmed_onstartup) {
2092 THREAD_OFF(bgp->t_maxmed_onstartup);
2093 bgp->maxmed_onstartup_over = 1;
2094 }
2095
2096 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2097 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2098
2099 bgp_maxmed_update(bgp);
2100
2101 return CMD_SUCCESS;
2102 }
2103
2104 static int bgp_global_update_delay_config_vty(struct vty *vty,
2105 uint16_t update_delay,
2106 uint16_t establish_wait)
2107 {
2108 struct listnode *node, *nnode;
2109 struct bgp *bgp;
2110 bool vrf_cfg = false;
2111
2112 /*
2113 * See if update-delay is set per-vrf and warn user to delete it
2114 * Note that we only need to check this if this is the first time
2115 * setting the global config.
2116 */
2117 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2118 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2119 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2120 vty_out(vty,
2121 "%% update-delay configuration found in vrf %s\n",
2122 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2123 ? VRF_DEFAULT_NAME
2124 : bgp->name);
2125 vrf_cfg = true;
2126 }
2127 }
2128 }
2129
2130 if (vrf_cfg) {
2131 vty_out(vty,
2132 "%%Failed: global update-delay config not permitted\n");
2133 return CMD_WARNING;
2134 }
2135
2136 if (!establish_wait) { /* update-delay <delay> */
2137 bm->v_update_delay = update_delay;
2138 bm->v_establish_wait = bm->v_update_delay;
2139 } else {
2140 /* update-delay <delay> <establish-wait> */
2141 if (update_delay < establish_wait) {
2142 vty_out(vty,
2143 "%%Failed: update-delay less than the establish-wait!\n");
2144 return CMD_WARNING_CONFIG_FAILED;
2145 }
2146
2147 bm->v_update_delay = update_delay;
2148 bm->v_establish_wait = establish_wait;
2149 }
2150
2151 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2152 bgp->v_update_delay = bm->v_update_delay;
2153 bgp->v_establish_wait = bm->v_establish_wait;
2154 }
2155
2156 return CMD_SUCCESS;
2157 }
2158
2159 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2160 {
2161 struct listnode *node, *nnode;
2162 struct bgp *bgp;
2163
2164 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2165 bm->v_establish_wait = bm->v_update_delay;
2166
2167 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2168 bgp->v_update_delay = bm->v_update_delay;
2169 bgp->v_establish_wait = bm->v_establish_wait;
2170 }
2171
2172 return CMD_SUCCESS;
2173 }
2174
2175 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2176 uint16_t establish_wait)
2177 {
2178 VTY_DECLVAR_CONTEXT(bgp, bgp);
2179
2180 /* if configured globally, per-instance config is not allowed */
2181 if (bm->v_update_delay) {
2182 vty_out(vty,
2183 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2184 return CMD_WARNING_CONFIG_FAILED;
2185 }
2186
2187
2188 if (!establish_wait) /* update-delay <delay> */
2189 {
2190 bgp->v_update_delay = update_delay;
2191 bgp->v_establish_wait = bgp->v_update_delay;
2192 return CMD_SUCCESS;
2193 }
2194
2195 /* update-delay <delay> <establish-wait> */
2196 if (update_delay < establish_wait) {
2197 vty_out(vty,
2198 "%%Failed: update-delay less than the establish-wait!\n");
2199 return CMD_WARNING_CONFIG_FAILED;
2200 }
2201
2202 bgp->v_update_delay = update_delay;
2203 bgp->v_establish_wait = establish_wait;
2204
2205 return CMD_SUCCESS;
2206 }
2207
2208 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2209 {
2210 VTY_DECLVAR_CONTEXT(bgp, bgp);
2211
2212 /* If configured globally, cannot remove from one bgp instance */
2213 if (bm->v_update_delay) {
2214 vty_out(vty,
2215 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2216 return CMD_WARNING_CONFIG_FAILED;
2217 }
2218 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2219 bgp->v_establish_wait = bgp->v_update_delay;
2220
2221 return CMD_SUCCESS;
2222 }
2223
2224 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2225 {
2226 /* If configured globally, no need to display per-instance value */
2227 if (bgp->v_update_delay != bm->v_update_delay) {
2228 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2229 if (bgp->v_update_delay != bgp->v_establish_wait)
2230 vty_out(vty, " %d", bgp->v_establish_wait);
2231 vty_out(vty, "\n");
2232 }
2233 }
2234
2235 /* Global update-delay configuration */
2236 DEFPY (bgp_global_update_delay,
2237 bgp_global_update_delay_cmd,
2238 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2239 BGP_STR
2240 "Force initial delay for best-path and updates for all bgp instances\n"
2241 "Max delay in seconds\n"
2242 "Establish wait in seconds\n")
2243 {
2244 return bgp_global_update_delay_config_vty(vty, delay, wait);
2245 }
2246
2247 /* Global update-delay deconfiguration */
2248 DEFPY (no_bgp_global_update_delay,
2249 no_bgp_global_update_delay_cmd,
2250 "no bgp update-delay [(0-3600) [(1-3600)]]",
2251 NO_STR
2252 BGP_STR
2253 "Force initial delay for best-path and updates\n"
2254 "Max delay in seconds\n"
2255 "Establish wait in seconds\n")
2256 {
2257 return bgp_global_update_delay_deconfig_vty(vty);
2258 }
2259
2260 /* Update-delay configuration */
2261
2262 DEFPY (bgp_update_delay,
2263 bgp_update_delay_cmd,
2264 "update-delay (0-3600)$delay [(1-3600)$wait]",
2265 "Force initial delay for best-path and updates\n"
2266 "Max delay in seconds\n"
2267 "Establish wait in seconds\n")
2268 {
2269 return bgp_update_delay_config_vty(vty, delay, wait);
2270 }
2271
2272 /* Update-delay deconfiguration */
2273 DEFPY (no_bgp_update_delay,
2274 no_bgp_update_delay_cmd,
2275 "no update-delay [(0-3600) [(1-3600)]]",
2276 NO_STR
2277 "Force initial delay for best-path and updates\n"
2278 "Max delay in seconds\n"
2279 "Establish wait in seconds\n")
2280 {
2281 return bgp_update_delay_deconfig_vty(vty);
2282 }
2283
2284
2285 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2286 bool set)
2287 {
2288 VTY_DECLVAR_CONTEXT(bgp, bgp);
2289
2290 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2291 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2292
2293 return CMD_SUCCESS;
2294 }
2295
2296 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2297 bool set)
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300
2301 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2302 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2303
2304 return CMD_SUCCESS;
2305 }
2306
2307 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2308 {
2309 uint32_t quanta =
2310 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2311 if (quanta != BGP_WRITE_PACKET_MAX)
2312 vty_out(vty, " write-quanta %d\n", quanta);
2313 }
2314
2315 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2316 {
2317 uint32_t quanta =
2318 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2319 if (quanta != BGP_READ_PACKET_MAX)
2320 vty_out(vty, " read-quanta %d\n", quanta);
2321 }
2322
2323 /* Packet quanta configuration
2324 *
2325 * XXX: The value set here controls the size of a stack buffer in the IO
2326 * thread. When changing these limits be careful to prevent stack overflow.
2327 *
2328 * Furthermore, the maximums used here should correspond to
2329 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2330 */
2331 DEFPY (bgp_wpkt_quanta,
2332 bgp_wpkt_quanta_cmd,
2333 "[no] write-quanta (1-64)$quanta",
2334 NO_STR
2335 "How many packets to write to peer socket per run\n"
2336 "Number of packets\n")
2337 {
2338 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2339 }
2340
2341 DEFPY (bgp_rpkt_quanta,
2342 bgp_rpkt_quanta_cmd,
2343 "[no] read-quanta (1-10)$quanta",
2344 NO_STR
2345 "How many packets to read from peer socket per I/O cycle\n"
2346 "Number of packets\n")
2347 {
2348 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2349 }
2350
2351 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2352 {
2353 if (!bgp->heuristic_coalesce)
2354 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2355 }
2356
2357
2358 DEFUN (bgp_coalesce_time,
2359 bgp_coalesce_time_cmd,
2360 "coalesce-time (0-4294967295)",
2361 "Subgroup coalesce timer\n"
2362 "Subgroup coalesce timer value (in ms)\n")
2363 {
2364 VTY_DECLVAR_CONTEXT(bgp, bgp);
2365
2366 int idx = 0;
2367
2368 bgp->heuristic_coalesce = false;
2369
2370 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2371 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2372
2373 return CMD_SUCCESS;
2374 }
2375
2376 DEFUN (no_bgp_coalesce_time,
2377 no_bgp_coalesce_time_cmd,
2378 "no coalesce-time (0-4294967295)",
2379 NO_STR
2380 "Subgroup coalesce timer\n"
2381 "Subgroup coalesce timer value (in ms)\n")
2382 {
2383 VTY_DECLVAR_CONTEXT(bgp, bgp);
2384
2385 bgp->heuristic_coalesce = true;
2386 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2387 return CMD_SUCCESS;
2388 }
2389
2390 /* Maximum-paths configuration */
2391 DEFUN (bgp_maxpaths,
2392 bgp_maxpaths_cmd,
2393 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2394 "Forward packets over multiple paths\n"
2395 "Number of paths\n")
2396 {
2397 int idx_number = 1;
2398 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2399 argv[idx_number]->arg, 0, 1);
2400 }
2401
2402 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2403 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2404 "Forward packets over multiple paths\n"
2405 "Number of paths\n")
2406
2407 DEFUN (bgp_maxpaths_ibgp,
2408 bgp_maxpaths_ibgp_cmd,
2409 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2410 "Forward packets over multiple paths\n"
2411 "iBGP-multipath\n"
2412 "Number of paths\n")
2413 {
2414 int idx_number = 2;
2415 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2416 argv[idx_number]->arg, 0, 1);
2417 }
2418
2419 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2420 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2421 "Forward packets over multiple paths\n"
2422 "iBGP-multipath\n"
2423 "Number of paths\n")
2424
2425 DEFUN (bgp_maxpaths_ibgp_cluster,
2426 bgp_maxpaths_ibgp_cluster_cmd,
2427 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2428 "Forward packets over multiple paths\n"
2429 "iBGP-multipath\n"
2430 "Number of paths\n"
2431 "Match the cluster length\n")
2432 {
2433 int idx_number = 2;
2434 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2435 argv[idx_number]->arg, true, 1);
2436 }
2437
2438 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2439 "maximum-paths ibgp " CMD_RANGE_STR(
2440 1, MULTIPATH_NUM) " equal-cluster-length",
2441 "Forward packets over multiple paths\n"
2442 "iBGP-multipath\n"
2443 "Number of paths\n"
2444 "Match the cluster length\n")
2445
2446 DEFUN (no_bgp_maxpaths,
2447 no_bgp_maxpaths_cmd,
2448 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2449 NO_STR
2450 "Forward packets over multiple paths\n"
2451 "Number of paths\n")
2452 {
2453 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2454 }
2455
2456 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2457 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2458 "Forward packets over multiple paths\n"
2459 "Number of paths\n")
2460
2461 DEFUN (no_bgp_maxpaths_ibgp,
2462 no_bgp_maxpaths_ibgp_cmd,
2463 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2464 NO_STR
2465 "Forward packets over multiple paths\n"
2466 "iBGP-multipath\n"
2467 "Number of paths\n"
2468 "Match the cluster length\n")
2469 {
2470 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2471 }
2472
2473 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2474 "no maximum-paths ibgp [" CMD_RANGE_STR(
2475 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2476 NO_STR
2477 "Forward packets over multiple paths\n"
2478 "iBGP-multipath\n"
2479 "Number of paths\n"
2480 "Match the cluster length\n")
2481
2482 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2483 afi_t afi, safi_t safi)
2484 {
2485 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2486 vty_out(vty, " maximum-paths %d\n",
2487 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2488 }
2489
2490 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2491 vty_out(vty, " maximum-paths ibgp %d",
2492 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2493 if (bgp->maxpaths[afi][safi].same_clusterlen)
2494 vty_out(vty, " equal-cluster-length");
2495 vty_out(vty, "\n");
2496 }
2497 }
2498
2499 /* BGP timers. */
2500
2501 DEFUN (bgp_timers,
2502 bgp_timers_cmd,
2503 "timers bgp (0-65535) (0-65535)",
2504 "Adjust routing timers\n"
2505 "BGP timers\n"
2506 "Keepalive interval\n"
2507 "Holdtime\n")
2508 {
2509 VTY_DECLVAR_CONTEXT(bgp, bgp);
2510 int idx_number = 2;
2511 int idx_number_2 = 3;
2512 unsigned long keepalive = 0;
2513 unsigned long holdtime = 0;
2514
2515 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2516 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2517
2518 /* Holdtime value check. */
2519 if (holdtime < 3 && holdtime != 0) {
2520 vty_out(vty,
2521 "%% hold time value must be either 0 or greater than 3\n");
2522 return CMD_WARNING_CONFIG_FAILED;
2523 }
2524
2525 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2526 BGP_DEFAULT_DELAYOPEN);
2527
2528 return CMD_SUCCESS;
2529 }
2530
2531 DEFUN (no_bgp_timers,
2532 no_bgp_timers_cmd,
2533 "no timers bgp [(0-65535) (0-65535)]",
2534 NO_STR
2535 "Adjust routing timers\n"
2536 "BGP timers\n"
2537 "Keepalive interval\n"
2538 "Holdtime\n")
2539 {
2540 VTY_DECLVAR_CONTEXT(bgp, bgp);
2541 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2542 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2543
2544 return CMD_SUCCESS;
2545 }
2546
2547 /* BGP minimum holdtime. */
2548
2549 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2550 "bgp minimum-holdtime (1-65535)",
2551 "BGP specific commands\n"
2552 "BGP minimum holdtime\n"
2553 "Seconds\n")
2554 {
2555 VTY_DECLVAR_CONTEXT(bgp, bgp);
2556 int idx_number = 2;
2557 unsigned long min_holdtime;
2558
2559 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2560
2561 bgp->default_min_holdtime = min_holdtime;
2562
2563 return CMD_SUCCESS;
2564 }
2565
2566 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2567 "no bgp minimum-holdtime [(1-65535)]",
2568 NO_STR
2569 "BGP specific commands\n"
2570 "BGP minimum holdtime\n"
2571 "Seconds\n")
2572 {
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574
2575 bgp->default_min_holdtime = 0;
2576
2577 return CMD_SUCCESS;
2578 }
2579
2580 DEFUN (bgp_client_to_client_reflection,
2581 bgp_client_to_client_reflection_cmd,
2582 "bgp client-to-client reflection",
2583 BGP_STR
2584 "Configure client to client route reflection\n"
2585 "reflection of routes allowed\n")
2586 {
2587 VTY_DECLVAR_CONTEXT(bgp, bgp);
2588 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2589 bgp_clear_star_soft_out(vty, bgp->name);
2590
2591 return CMD_SUCCESS;
2592 }
2593
2594 DEFUN (no_bgp_client_to_client_reflection,
2595 no_bgp_client_to_client_reflection_cmd,
2596 "no bgp client-to-client reflection",
2597 NO_STR
2598 BGP_STR
2599 "Configure client to client route reflection\n"
2600 "reflection of routes allowed\n")
2601 {
2602 VTY_DECLVAR_CONTEXT(bgp, bgp);
2603 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2604 bgp_clear_star_soft_out(vty, bgp->name);
2605
2606 return CMD_SUCCESS;
2607 }
2608
2609 /* "bgp always-compare-med" configuration. */
2610 DEFUN (bgp_always_compare_med,
2611 bgp_always_compare_med_cmd,
2612 "bgp always-compare-med",
2613 BGP_STR
2614 "Allow comparing MED from different neighbors\n")
2615 {
2616 VTY_DECLVAR_CONTEXT(bgp, bgp);
2617 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2618 bgp_recalculate_all_bestpaths(bgp);
2619
2620 return CMD_SUCCESS;
2621 }
2622
2623 DEFUN (no_bgp_always_compare_med,
2624 no_bgp_always_compare_med_cmd,
2625 "no bgp always-compare-med",
2626 NO_STR
2627 BGP_STR
2628 "Allow comparing MED from different neighbors\n")
2629 {
2630 VTY_DECLVAR_CONTEXT(bgp, bgp);
2631 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2632 bgp_recalculate_all_bestpaths(bgp);
2633
2634 return CMD_SUCCESS;
2635 }
2636
2637
2638 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2639 "bgp ebgp-requires-policy",
2640 BGP_STR
2641 "Require in and out policy for eBGP peers (RFC8212)\n")
2642 {
2643 VTY_DECLVAR_CONTEXT(bgp, bgp);
2644 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2645 return CMD_SUCCESS;
2646 }
2647
2648 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2649 "no bgp ebgp-requires-policy",
2650 NO_STR
2651 BGP_STR
2652 "Require in and out policy for eBGP peers (RFC8212)\n")
2653 {
2654 VTY_DECLVAR_CONTEXT(bgp, bgp);
2655 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2656 return CMD_SUCCESS;
2657 }
2658
2659 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2660 "bgp suppress-duplicates",
2661 BGP_STR
2662 "Suppress duplicate updates if the route actually not changed\n")
2663 {
2664 VTY_DECLVAR_CONTEXT(bgp, bgp);
2665 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2666 return CMD_SUCCESS;
2667 }
2668
2669 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2670 "no bgp suppress-duplicates",
2671 NO_STR
2672 BGP_STR
2673 "Suppress duplicate updates if the route actually not changed\n")
2674 {
2675 VTY_DECLVAR_CONTEXT(bgp, bgp);
2676 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2677 return CMD_SUCCESS;
2678 }
2679
2680 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2681 "bgp reject-as-sets",
2682 BGP_STR
2683 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2684 {
2685 VTY_DECLVAR_CONTEXT(bgp, bgp);
2686 struct listnode *node, *nnode;
2687 struct peer *peer;
2688
2689 bgp->reject_as_sets = true;
2690
2691 /* Reset existing BGP sessions to reject routes
2692 * with aspath containing AS_SET or AS_CONFED_SET.
2693 */
2694 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2695 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2696 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2697 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2698 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2699 }
2700 }
2701
2702 return CMD_SUCCESS;
2703 }
2704
2705 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2706 "no bgp reject-as-sets",
2707 NO_STR
2708 BGP_STR
2709 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2710 {
2711 VTY_DECLVAR_CONTEXT(bgp, bgp);
2712 struct listnode *node, *nnode;
2713 struct peer *peer;
2714
2715 bgp->reject_as_sets = false;
2716
2717 /* Reset existing BGP sessions to reject routes
2718 * with aspath containing AS_SET or AS_CONFED_SET.
2719 */
2720 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2721 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2722 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2723 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2724 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2725 }
2726 }
2727
2728 return CMD_SUCCESS;
2729 }
2730
2731 /* "bgp deterministic-med" configuration. */
2732 DEFUN (bgp_deterministic_med,
2733 bgp_deterministic_med_cmd,
2734 "bgp deterministic-med",
2735 BGP_STR
2736 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2737 {
2738 VTY_DECLVAR_CONTEXT(bgp, bgp);
2739
2740 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2741 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2742 bgp_recalculate_all_bestpaths(bgp);
2743 }
2744
2745 return CMD_SUCCESS;
2746 }
2747
2748 DEFUN (no_bgp_deterministic_med,
2749 no_bgp_deterministic_med_cmd,
2750 "no bgp deterministic-med",
2751 NO_STR
2752 BGP_STR
2753 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2754 {
2755 VTY_DECLVAR_CONTEXT(bgp, bgp);
2756 int bestpath_per_as_used;
2757 afi_t afi;
2758 safi_t safi;
2759 struct peer *peer;
2760 struct listnode *node, *nnode;
2761
2762 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2763 bestpath_per_as_used = 0;
2764
2765 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2766 FOREACH_AFI_SAFI (afi, safi)
2767 if (bgp_addpath_dmed_required(
2768 peer->addpath_type[afi][safi])) {
2769 bestpath_per_as_used = 1;
2770 break;
2771 }
2772
2773 if (bestpath_per_as_used)
2774 break;
2775 }
2776
2777 if (bestpath_per_as_used) {
2778 vty_out(vty,
2779 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2780 return CMD_WARNING_CONFIG_FAILED;
2781 } else {
2782 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2783 bgp_recalculate_all_bestpaths(bgp);
2784 }
2785 }
2786
2787 return CMD_SUCCESS;
2788 }
2789
2790 /* "bgp graceful-restart mode" configuration. */
2791 DEFUN (bgp_graceful_restart,
2792 bgp_graceful_restart_cmd,
2793 "bgp graceful-restart",
2794 BGP_STR
2795 GR_CMD
2796 )
2797 {
2798 int ret = BGP_GR_FAILURE;
2799
2800 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2801 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2802
2803 VTY_DECLVAR_CONTEXT(bgp, bgp);
2804
2805 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2806
2807 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2808 ret);
2809
2810 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2811 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2812 vty_out(vty,
2813 "Graceful restart configuration changed, reset all peers to take effect\n");
2814 return bgp_vty_return(vty, ret);
2815 }
2816
2817 DEFUN (no_bgp_graceful_restart,
2818 no_bgp_graceful_restart_cmd,
2819 "no bgp graceful-restart",
2820 NO_STR
2821 BGP_STR
2822 NO_GR_CMD
2823 )
2824 {
2825 VTY_DECLVAR_CONTEXT(bgp, bgp);
2826
2827 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2828 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2829
2830 int ret = BGP_GR_FAILURE;
2831
2832 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2833
2834 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2835 ret);
2836
2837 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2838 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2839 vty_out(vty,
2840 "Graceful restart configuration changed, reset all peers to take effect\n");
2841
2842 return bgp_vty_return(vty, ret);
2843 }
2844
2845 DEFUN (bgp_graceful_restart_stalepath_time,
2846 bgp_graceful_restart_stalepath_time_cmd,
2847 "bgp graceful-restart stalepath-time (1-4095)",
2848 BGP_STR
2849 "Graceful restart capability parameters\n"
2850 "Set the max time to hold onto restarting peer's stale paths\n"
2851 "Delay value (seconds)\n")
2852 {
2853 VTY_DECLVAR_CONTEXT(bgp, bgp);
2854 int idx_number = 3;
2855 uint32_t stalepath;
2856
2857 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2858 bgp->stalepath_time = stalepath;
2859 return CMD_SUCCESS;
2860 }
2861
2862 DEFUN (bgp_graceful_restart_restart_time,
2863 bgp_graceful_restart_restart_time_cmd,
2864 "bgp graceful-restart restart-time (0-4095)",
2865 BGP_STR
2866 "Graceful restart capability parameters\n"
2867 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2868 "Delay value (seconds)\n")
2869 {
2870 VTY_DECLVAR_CONTEXT(bgp, bgp);
2871 int idx_number = 3;
2872 uint32_t restart;
2873
2874 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2875 bgp->restart_time = restart;
2876 return CMD_SUCCESS;
2877 }
2878
2879 DEFUN (bgp_graceful_restart_select_defer_time,
2880 bgp_graceful_restart_select_defer_time_cmd,
2881 "bgp graceful-restart select-defer-time (0-3600)",
2882 BGP_STR
2883 "Graceful restart capability parameters\n"
2884 "Set the time to defer the BGP route selection after restart\n"
2885 "Delay value (seconds, 0 - disable)\n")
2886 {
2887 VTY_DECLVAR_CONTEXT(bgp, bgp);
2888 int idx_number = 3;
2889 uint32_t defer_time;
2890
2891 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2892 bgp->select_defer_time = defer_time;
2893 if (defer_time == 0)
2894 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2895 else
2896 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2897
2898 return CMD_SUCCESS;
2899 }
2900
2901 DEFUN (no_bgp_graceful_restart_stalepath_time,
2902 no_bgp_graceful_restart_stalepath_time_cmd,
2903 "no bgp graceful-restart stalepath-time [(1-4095)]",
2904 NO_STR
2905 BGP_STR
2906 "Graceful restart capability parameters\n"
2907 "Set the max time to hold onto restarting peer's stale paths\n"
2908 "Delay value (seconds)\n")
2909 {
2910 VTY_DECLVAR_CONTEXT(bgp, bgp);
2911
2912 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2913 return CMD_SUCCESS;
2914 }
2915
2916 DEFUN (no_bgp_graceful_restart_restart_time,
2917 no_bgp_graceful_restart_restart_time_cmd,
2918 "no bgp graceful-restart restart-time [(0-4095)]",
2919 NO_STR
2920 BGP_STR
2921 "Graceful restart capability parameters\n"
2922 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2923 "Delay value (seconds)\n")
2924 {
2925 VTY_DECLVAR_CONTEXT(bgp, bgp);
2926
2927 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2928 return CMD_SUCCESS;
2929 }
2930
2931 DEFUN (no_bgp_graceful_restart_select_defer_time,
2932 no_bgp_graceful_restart_select_defer_time_cmd,
2933 "no bgp graceful-restart select-defer-time [(0-3600)]",
2934 NO_STR
2935 BGP_STR
2936 "Graceful restart capability parameters\n"
2937 "Set the time to defer the BGP route selection after restart\n"
2938 "Delay value (seconds)\n")
2939 {
2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941
2942 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2943 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2944
2945 return CMD_SUCCESS;
2946 }
2947
2948 DEFUN (bgp_graceful_restart_preserve_fw,
2949 bgp_graceful_restart_preserve_fw_cmd,
2950 "bgp graceful-restart preserve-fw-state",
2951 BGP_STR
2952 "Graceful restart capability parameters\n"
2953 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2954 {
2955 VTY_DECLVAR_CONTEXT(bgp, bgp);
2956 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2957 return CMD_SUCCESS;
2958 }
2959
2960 DEFUN (no_bgp_graceful_restart_preserve_fw,
2961 no_bgp_graceful_restart_preserve_fw_cmd,
2962 "no bgp graceful-restart preserve-fw-state",
2963 NO_STR
2964 BGP_STR
2965 "Graceful restart capability parameters\n"
2966 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2967 {
2968 VTY_DECLVAR_CONTEXT(bgp, bgp);
2969 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2970 return CMD_SUCCESS;
2971 }
2972
2973 DEFPY (bgp_graceful_restart_notification,
2974 bgp_graceful_restart_notification_cmd,
2975 "[no$no] bgp graceful-restart notification",
2976 NO_STR
2977 BGP_STR
2978 "Graceful restart capability parameters\n"
2979 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2980 {
2981 VTY_DECLVAR_CONTEXT(bgp, bgp);
2982
2983 if (no)
2984 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2985 else
2986 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2987
2988 return CMD_SUCCESS;
2989 }
2990
2991 DEFPY (bgp_administrative_reset,
2992 bgp_administrative_reset_cmd,
2993 "[no$no] bgp hard-administrative-reset",
2994 NO_STR
2995 BGP_STR
2996 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2997 {
2998 VTY_DECLVAR_CONTEXT(bgp, bgp);
2999
3000 if (no)
3001 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3002 else
3003 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3004
3005 return CMD_SUCCESS;
3006 }
3007
3008 DEFUN (bgp_graceful_restart_disable,
3009 bgp_graceful_restart_disable_cmd,
3010 "bgp graceful-restart-disable",
3011 BGP_STR
3012 GR_DISABLE)
3013 {
3014 int ret = BGP_GR_FAILURE;
3015
3016 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3017 zlog_debug(
3018 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3019
3020 VTY_DECLVAR_CONTEXT(bgp, bgp);
3021
3022 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3023
3024 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3025 bgp->peer, ret);
3026
3027 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3028 zlog_debug(
3029 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3030 vty_out(vty,
3031 "Graceful restart configuration changed, reset all peers to take effect\n");
3032
3033 return bgp_vty_return(vty, ret);
3034 }
3035
3036 DEFUN (no_bgp_graceful_restart_disable,
3037 no_bgp_graceful_restart_disable_cmd,
3038 "no bgp graceful-restart-disable",
3039 NO_STR
3040 BGP_STR
3041 NO_GR_DISABLE
3042 )
3043 {
3044 VTY_DECLVAR_CONTEXT(bgp, bgp);
3045
3046 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3047 zlog_debug(
3048 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3049
3050 int ret = BGP_GR_FAILURE;
3051
3052 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3053
3054 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3055 ret);
3056
3057 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3058 zlog_debug(
3059 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3060 vty_out(vty,
3061 "Graceful restart configuration changed, reset all peers to take effect\n");
3062
3063 return bgp_vty_return(vty, ret);
3064 }
3065
3066 DEFUN (bgp_neighbor_graceful_restart_set,
3067 bgp_neighbor_graceful_restart_set_cmd,
3068 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3069 NEIGHBOR_STR
3070 NEIGHBOR_ADDR_STR2
3071 GR_NEIGHBOR_CMD
3072 )
3073 {
3074 int idx_peer = 1;
3075 struct peer *peer;
3076 int ret = BGP_GR_FAILURE;
3077
3078 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3079
3080 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3081 zlog_debug(
3082 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3083
3084 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3085 if (!peer)
3086 return CMD_WARNING_CONFIG_FAILED;
3087
3088 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3089
3090 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3091 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3092
3093 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3094 zlog_debug(
3095 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3096 vty_out(vty,
3097 "Graceful restart configuration changed, reset this peer to take effect\n");
3098
3099 return bgp_vty_return(vty, ret);
3100 }
3101
3102 DEFUN (no_bgp_neighbor_graceful_restart,
3103 no_bgp_neighbor_graceful_restart_set_cmd,
3104 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3105 NO_STR
3106 NEIGHBOR_STR
3107 NEIGHBOR_ADDR_STR2
3108 NO_GR_NEIGHBOR_CMD
3109 )
3110 {
3111 int idx_peer = 2;
3112 int ret = BGP_GR_FAILURE;
3113 struct peer *peer;
3114
3115 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3116
3117 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3118 if (!peer)
3119 return CMD_WARNING_CONFIG_FAILED;
3120
3121 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3122 zlog_debug(
3123 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3124
3125 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3126
3127 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3128 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3129
3130 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3131 zlog_debug(
3132 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3133 vty_out(vty,
3134 "Graceful restart configuration changed, reset this peer to take effect\n");
3135
3136 return bgp_vty_return(vty, ret);
3137 }
3138
3139 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3140 bgp_neighbor_graceful_restart_helper_set_cmd,
3141 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3142 NEIGHBOR_STR
3143 NEIGHBOR_ADDR_STR2
3144 GR_NEIGHBOR_HELPER_CMD
3145 )
3146 {
3147 int idx_peer = 1;
3148 struct peer *peer;
3149 int ret = BGP_GR_FAILURE;
3150
3151 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3152
3153 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3154 zlog_debug(
3155 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3156
3157 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3158
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
3161
3162
3163 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3164
3165 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3166 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3167
3168 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3169 zlog_debug(
3170 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3171 vty_out(vty,
3172 "Graceful restart configuration changed, reset this peer to take effect\n");
3173
3174 return bgp_vty_return(vty, ret);
3175 }
3176
3177 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3178 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3179 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3180 NO_STR
3181 NEIGHBOR_STR
3182 NEIGHBOR_ADDR_STR2
3183 NO_GR_NEIGHBOR_HELPER_CMD
3184 )
3185 {
3186 int idx_peer = 2;
3187 int ret = BGP_GR_FAILURE;
3188 struct peer *peer;
3189
3190 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3191
3192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3193 if (!peer)
3194 return CMD_WARNING_CONFIG_FAILED;
3195
3196 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3197 zlog_debug(
3198 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3199
3200 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3201
3202 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3203 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3204
3205 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3206 zlog_debug(
3207 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3208 vty_out(vty,
3209 "Graceful restart configuration changed, reset this peer to take effect\n");
3210
3211 return bgp_vty_return(vty, ret);
3212 }
3213
3214 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3215 bgp_neighbor_graceful_restart_disable_set_cmd,
3216 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3217 NEIGHBOR_STR
3218 NEIGHBOR_ADDR_STR2
3219 GR_NEIGHBOR_DISABLE_CMD
3220 )
3221 {
3222 int idx_peer = 1;
3223 struct peer *peer;
3224 int ret = BGP_GR_FAILURE;
3225
3226 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3227
3228 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3229 zlog_debug(
3230 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3231
3232 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3233 if (!peer)
3234 return CMD_WARNING_CONFIG_FAILED;
3235
3236 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3237
3238 if (peer->bgp->t_startup)
3239 bgp_peer_gr_flags_update(peer);
3240
3241 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3242 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3243
3244 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3245 zlog_debug(
3246 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3247 vty_out(vty,
3248 "Graceful restart configuration changed, reset this peer to take effect\n");
3249
3250 return bgp_vty_return(vty, ret);
3251 }
3252
3253 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3254 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3255 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3256 NO_STR
3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 NO_GR_NEIGHBOR_DISABLE_CMD
3260 )
3261 {
3262 int idx_peer = 2;
3263 int ret = BGP_GR_FAILURE;
3264 struct peer *peer;
3265
3266 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3267
3268 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3269 if (!peer)
3270 return CMD_WARNING_CONFIG_FAILED;
3271
3272 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3273 zlog_debug(
3274 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3275
3276 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3277
3278 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3279 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3280
3281 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3282 zlog_debug(
3283 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3284 vty_out(vty,
3285 "Graceful restart configuration changed, reset this peer to take effect\n");
3286
3287 return bgp_vty_return(vty, ret);
3288 }
3289
3290 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3291 bgp_graceful_restart_disable_eor_cmd,
3292 "bgp graceful-restart disable-eor",
3293 BGP_STR
3294 "Graceful restart configuration parameters\n"
3295 "Disable EOR Check\n")
3296 {
3297 VTY_DECLVAR_CONTEXT(bgp, bgp);
3298 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3299
3300 return CMD_SUCCESS;
3301 }
3302
3303 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3304 no_bgp_graceful_restart_disable_eor_cmd,
3305 "no bgp graceful-restart disable-eor",
3306 NO_STR
3307 BGP_STR
3308 "Graceful restart configuration parameters\n"
3309 "Disable EOR Check\n")
3310 {
3311 VTY_DECLVAR_CONTEXT(bgp, bgp);
3312 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3313
3314 return CMD_SUCCESS;
3315 }
3316
3317 DEFUN (bgp_graceful_restart_rib_stale_time,
3318 bgp_graceful_restart_rib_stale_time_cmd,
3319 "bgp graceful-restart rib-stale-time (1-3600)",
3320 BGP_STR
3321 "Graceful restart configuration parameters\n"
3322 "Specify the stale route removal timer in rib\n"
3323 "Delay value (seconds)\n")
3324 {
3325 VTY_DECLVAR_CONTEXT(bgp, bgp);
3326 int idx_number = 3;
3327 uint32_t stale_time;
3328
3329 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3330 bgp->rib_stale_time = stale_time;
3331 /* Send the stale timer update message to RIB */
3332 if (bgp_zebra_stale_timer_update(bgp))
3333 return CMD_WARNING;
3334
3335 return CMD_SUCCESS;
3336 }
3337
3338 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3339 no_bgp_graceful_restart_rib_stale_time_cmd,
3340 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3341 NO_STR
3342 BGP_STR
3343 "Graceful restart configuration parameters\n"
3344 "Specify the stale route removal timer in rib\n"
3345 "Delay value (seconds)\n")
3346 {
3347 VTY_DECLVAR_CONTEXT(bgp, bgp);
3348
3349 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3350 /* Send the stale timer update message to RIB */
3351 if (bgp_zebra_stale_timer_update(bgp))
3352 return CMD_WARNING;
3353
3354 return CMD_SUCCESS;
3355 }
3356
3357 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3358 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3359 BGP_STR
3360 "Enable Long-lived Graceful Restart\n"
3361 "Specifies maximum time to wait before purging long-lived stale routes\n"
3362 "Stale time value (seconds)\n")
3363 {
3364 VTY_DECLVAR_CONTEXT(bgp, bgp);
3365
3366 uint32_t llgr_stale_time;
3367
3368 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3369 bgp->llgr_stale_time = llgr_stale_time;
3370
3371 return CMD_SUCCESS;
3372 }
3373
3374 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3375 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3376 NO_STR BGP_STR
3377 "Enable Long-lived Graceful Restart\n"
3378 "Specifies maximum time to wait before purging long-lived stale routes\n"
3379 "Stale time value (seconds)\n")
3380 {
3381 VTY_DECLVAR_CONTEXT(bgp, bgp);
3382
3383 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3384
3385 return CMD_SUCCESS;
3386 }
3387
3388 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3389 struct bgp *bgp)
3390 {
3391 bgp_static_redo_import_check(bgp);
3392 bgp_redistribute_redo(bgp);
3393 bgp_clear_star_soft_out(vty, bgp->name);
3394 bgp_clear_star_soft_in(vty, bgp->name);
3395 }
3396
3397 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3398 {
3399 struct listnode *node, *nnode;
3400 struct bgp *bgp;
3401 bool vrf_cfg = false;
3402
3403 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3404 return CMD_SUCCESS;
3405
3406 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3407 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3408 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3409 vty_out(vty,
3410 "%% graceful-shutdown configuration found in vrf %s\n",
3411 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3412 VRF_DEFAULT_NAME : bgp->name);
3413 vrf_cfg = true;
3414 }
3415 }
3416
3417 if (vrf_cfg) {
3418 vty_out(vty,
3419 "%%Failed: global graceful-shutdown not permitted\n");
3420 return CMD_WARNING;
3421 }
3422
3423 /* Set flag globally */
3424 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3425
3426 /* Initiate processing for all BGP instances. */
3427 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3428 bgp_initiate_graceful_shut_unshut(vty, bgp);
3429
3430 return CMD_SUCCESS;
3431 }
3432
3433 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3434 {
3435 struct listnode *node, *nnode;
3436 struct bgp *bgp;
3437
3438 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3439 return CMD_SUCCESS;
3440
3441 /* Unset flag globally */
3442 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3443
3444 /* Initiate processing for all BGP instances. */
3445 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3446 bgp_initiate_graceful_shut_unshut(vty, bgp);
3447
3448 return CMD_SUCCESS;
3449 }
3450
3451 /* "bgp graceful-shutdown" configuration */
3452 DEFUN (bgp_graceful_shutdown,
3453 bgp_graceful_shutdown_cmd,
3454 "bgp graceful-shutdown",
3455 BGP_STR
3456 "Graceful shutdown parameters\n")
3457 {
3458 if (vty->node == CONFIG_NODE)
3459 return bgp_global_graceful_shutdown_config_vty(vty);
3460
3461 VTY_DECLVAR_CONTEXT(bgp, bgp);
3462
3463 /* if configured globally, per-instance config is not allowed */
3464 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3465 vty_out(vty,
3466 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3467 return CMD_WARNING_CONFIG_FAILED;
3468 }
3469
3470 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3471 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3472 bgp_initiate_graceful_shut_unshut(vty, bgp);
3473 }
3474
3475 return CMD_SUCCESS;
3476 }
3477
3478 DEFUN (no_bgp_graceful_shutdown,
3479 no_bgp_graceful_shutdown_cmd,
3480 "no bgp graceful-shutdown",
3481 NO_STR
3482 BGP_STR
3483 "Graceful shutdown parameters\n")
3484 {
3485 if (vty->node == CONFIG_NODE)
3486 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3487
3488 VTY_DECLVAR_CONTEXT(bgp, bgp);
3489
3490 /* If configured globally, cannot remove from one bgp instance */
3491 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3492 vty_out(vty,
3493 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3494 return CMD_WARNING_CONFIG_FAILED;
3495 }
3496
3497 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3498 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3499 bgp_initiate_graceful_shut_unshut(vty, bgp);
3500 }
3501
3502 return CMD_SUCCESS;
3503 }
3504
3505 /* "bgp fast-external-failover" configuration. */
3506 DEFUN (bgp_fast_external_failover,
3507 bgp_fast_external_failover_cmd,
3508 "bgp fast-external-failover",
3509 BGP_STR
3510 "Immediately reset session if a link to a directly connected external peer goes down\n")
3511 {
3512 VTY_DECLVAR_CONTEXT(bgp, bgp);
3513 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3514 return CMD_SUCCESS;
3515 }
3516
3517 DEFUN (no_bgp_fast_external_failover,
3518 no_bgp_fast_external_failover_cmd,
3519 "no bgp fast-external-failover",
3520 NO_STR
3521 BGP_STR
3522 "Immediately reset session if a link to a directly connected external peer goes down\n")
3523 {
3524 VTY_DECLVAR_CONTEXT(bgp, bgp);
3525 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3526 return CMD_SUCCESS;
3527 }
3528
3529 /* "bgp bestpath compare-routerid" configuration. */
3530 DEFUN (bgp_bestpath_compare_router_id,
3531 bgp_bestpath_compare_router_id_cmd,
3532 "bgp bestpath compare-routerid",
3533 BGP_STR
3534 "Change the default bestpath selection\n"
3535 "Compare router-id for identical EBGP paths\n")
3536 {
3537 VTY_DECLVAR_CONTEXT(bgp, bgp);
3538 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3539 bgp_recalculate_all_bestpaths(bgp);
3540
3541 return CMD_SUCCESS;
3542 }
3543
3544 DEFUN (no_bgp_bestpath_compare_router_id,
3545 no_bgp_bestpath_compare_router_id_cmd,
3546 "no bgp bestpath compare-routerid",
3547 NO_STR
3548 BGP_STR
3549 "Change the default bestpath selection\n"
3550 "Compare router-id for identical EBGP paths\n")
3551 {
3552 VTY_DECLVAR_CONTEXT(bgp, bgp);
3553 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3554 bgp_recalculate_all_bestpaths(bgp);
3555
3556 return CMD_SUCCESS;
3557 }
3558
3559 /* "bgp bestpath as-path ignore" configuration. */
3560 DEFUN (bgp_bestpath_aspath_ignore,
3561 bgp_bestpath_aspath_ignore_cmd,
3562 "bgp bestpath as-path ignore",
3563 BGP_STR
3564 "Change the default bestpath selection\n"
3565 "AS-path attribute\n"
3566 "Ignore as-path length in selecting a route\n")
3567 {
3568 VTY_DECLVAR_CONTEXT(bgp, bgp);
3569 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3570 bgp_recalculate_all_bestpaths(bgp);
3571
3572 return CMD_SUCCESS;
3573 }
3574
3575 DEFUN (no_bgp_bestpath_aspath_ignore,
3576 no_bgp_bestpath_aspath_ignore_cmd,
3577 "no bgp bestpath as-path ignore",
3578 NO_STR
3579 BGP_STR
3580 "Change the default bestpath selection\n"
3581 "AS-path attribute\n"
3582 "Ignore as-path length in selecting a route\n")
3583 {
3584 VTY_DECLVAR_CONTEXT(bgp, bgp);
3585 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3586 bgp_recalculate_all_bestpaths(bgp);
3587
3588 return CMD_SUCCESS;
3589 }
3590
3591 /* "bgp bestpath as-path confed" configuration. */
3592 DEFUN (bgp_bestpath_aspath_confed,
3593 bgp_bestpath_aspath_confed_cmd,
3594 "bgp bestpath as-path confed",
3595 BGP_STR
3596 "Change the default bestpath selection\n"
3597 "AS-path attribute\n"
3598 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3599 {
3600 VTY_DECLVAR_CONTEXT(bgp, bgp);
3601 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3602 bgp_recalculate_all_bestpaths(bgp);
3603
3604 return CMD_SUCCESS;
3605 }
3606
3607 DEFUN (no_bgp_bestpath_aspath_confed,
3608 no_bgp_bestpath_aspath_confed_cmd,
3609 "no bgp bestpath as-path confed",
3610 NO_STR
3611 BGP_STR
3612 "Change the default bestpath selection\n"
3613 "AS-path attribute\n"
3614 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3615 {
3616 VTY_DECLVAR_CONTEXT(bgp, bgp);
3617 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3618 bgp_recalculate_all_bestpaths(bgp);
3619
3620 return CMD_SUCCESS;
3621 }
3622
3623 /* "bgp bestpath as-path multipath-relax" configuration. */
3624 DEFUN (bgp_bestpath_aspath_multipath_relax,
3625 bgp_bestpath_aspath_multipath_relax_cmd,
3626 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3627 BGP_STR
3628 "Change the default bestpath selection\n"
3629 "AS-path attribute\n"
3630 "Allow load sharing across routes that have different AS paths (but same length)\n"
3631 "Generate an AS_SET\n"
3632 "Do not generate an AS_SET\n")
3633 {
3634 VTY_DECLVAR_CONTEXT(bgp, bgp);
3635 int idx = 0;
3636 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3637
3638 /* no-as-set is now the default behavior so we can silently
3639 * ignore it */
3640 if (argv_find(argv, argc, "as-set", &idx))
3641 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3642 else
3643 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3644
3645 bgp_recalculate_all_bestpaths(bgp);
3646
3647 return CMD_SUCCESS;
3648 }
3649
3650 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3651 no_bgp_bestpath_aspath_multipath_relax_cmd,
3652 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3653 NO_STR
3654 BGP_STR
3655 "Change the default bestpath selection\n"
3656 "AS-path attribute\n"
3657 "Allow load sharing across routes that have different AS paths (but same length)\n"
3658 "Generate an AS_SET\n"
3659 "Do not generate an AS_SET\n")
3660 {
3661 VTY_DECLVAR_CONTEXT(bgp, bgp);
3662 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3663 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3664 bgp_recalculate_all_bestpaths(bgp);
3665
3666 return CMD_SUCCESS;
3667 }
3668
3669 /* "bgp bestpath peer-type multipath-relax" configuration. */
3670 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3671 bgp_bestpath_peer_type_multipath_relax_cmd,
3672 "bgp bestpath peer-type multipath-relax",
3673 BGP_STR
3674 "Change the default bestpath selection\n"
3675 "Peer type\n"
3676 "Allow load sharing across routes learned from different peer types\n")
3677 {
3678 VTY_DECLVAR_CONTEXT(bgp, bgp);
3679 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3680 bgp_recalculate_all_bestpaths(bgp);
3681
3682 return CMD_SUCCESS;
3683 }
3684
3685 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3686 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3687 "no bgp bestpath peer-type multipath-relax",
3688 NO_STR BGP_STR
3689 "Change the default bestpath selection\n"
3690 "Peer type\n"
3691 "Allow load sharing across routes learned from different peer types\n")
3692 {
3693 VTY_DECLVAR_CONTEXT(bgp, bgp);
3694 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3695 bgp_recalculate_all_bestpaths(bgp);
3696
3697 return CMD_SUCCESS;
3698 }
3699
3700 /* "bgp log-neighbor-changes" configuration. */
3701 DEFUN (bgp_log_neighbor_changes,
3702 bgp_log_neighbor_changes_cmd,
3703 "bgp log-neighbor-changes",
3704 BGP_STR
3705 "Log neighbor up/down and reset reason\n")
3706 {
3707 VTY_DECLVAR_CONTEXT(bgp, bgp);
3708 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3709 return CMD_SUCCESS;
3710 }
3711
3712 DEFUN (no_bgp_log_neighbor_changes,
3713 no_bgp_log_neighbor_changes_cmd,
3714 "no bgp log-neighbor-changes",
3715 NO_STR
3716 BGP_STR
3717 "Log neighbor up/down and reset reason\n")
3718 {
3719 VTY_DECLVAR_CONTEXT(bgp, bgp);
3720 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3721 return CMD_SUCCESS;
3722 }
3723
3724 /* "bgp bestpath med" configuration. */
3725 DEFUN (bgp_bestpath_med,
3726 bgp_bestpath_med_cmd,
3727 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3728 BGP_STR
3729 "Change the default bestpath selection\n"
3730 "MED attribute\n"
3731 "Compare MED among confederation paths\n"
3732 "Treat missing MED as the least preferred one\n"
3733 "Treat missing MED as the least preferred one\n"
3734 "Compare MED among confederation paths\n")
3735 {
3736 VTY_DECLVAR_CONTEXT(bgp, bgp);
3737
3738 int idx = 0;
3739 if (argv_find(argv, argc, "confed", &idx))
3740 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3741 idx = 0;
3742 if (argv_find(argv, argc, "missing-as-worst", &idx))
3743 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3744
3745 bgp_recalculate_all_bestpaths(bgp);
3746
3747 return CMD_SUCCESS;
3748 }
3749
3750 DEFUN (no_bgp_bestpath_med,
3751 no_bgp_bestpath_med_cmd,
3752 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3753 NO_STR
3754 BGP_STR
3755 "Change the default bestpath selection\n"
3756 "MED attribute\n"
3757 "Compare MED among confederation paths\n"
3758 "Treat missing MED as the least preferred one\n"
3759 "Treat missing MED as the least preferred one\n"
3760 "Compare MED among confederation paths\n")
3761 {
3762 VTY_DECLVAR_CONTEXT(bgp, bgp);
3763
3764 int idx = 0;
3765 if (argv_find(argv, argc, "confed", &idx))
3766 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3767 idx = 0;
3768 if (argv_find(argv, argc, "missing-as-worst", &idx))
3769 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3770
3771 bgp_recalculate_all_bestpaths(bgp);
3772
3773 return CMD_SUCCESS;
3774 }
3775
3776 /* "bgp bestpath bandwidth" configuration. */
3777 DEFPY (bgp_bestpath_bw,
3778 bgp_bestpath_bw_cmd,
3779 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3780 BGP_STR
3781 "Change the default bestpath selection\n"
3782 "Link Bandwidth attribute\n"
3783 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3784 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3785 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3786 {
3787 VTY_DECLVAR_CONTEXT(bgp, bgp);
3788 afi_t afi;
3789 safi_t safi;
3790
3791 if (!bw_cfg) {
3792 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3793 return CMD_ERR_INCOMPLETE;
3794 }
3795 if (!strcmp(bw_cfg, "ignore"))
3796 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3797 else if (!strcmp(bw_cfg, "skip-missing"))
3798 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3799 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3800 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3801 else
3802 return CMD_ERR_NO_MATCH;
3803
3804 /* This config is used in route install, so redo that. */
3805 FOREACH_AFI_SAFI (afi, safi) {
3806 if (!bgp_fibupd_safi(safi))
3807 continue;
3808 bgp_zebra_announce_table(bgp, afi, safi);
3809 }
3810
3811 return CMD_SUCCESS;
3812 }
3813
3814 DEFPY (no_bgp_bestpath_bw,
3815 no_bgp_bestpath_bw_cmd,
3816 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3817 NO_STR
3818 BGP_STR
3819 "Change the default bestpath selection\n"
3820 "Link Bandwidth attribute\n"
3821 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3822 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3823 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3824 {
3825 VTY_DECLVAR_CONTEXT(bgp, bgp);
3826 afi_t afi;
3827 safi_t safi;
3828
3829 bgp->lb_handling = BGP_LINK_BW_ECMP;
3830
3831 /* This config is used in route install, so redo that. */
3832 FOREACH_AFI_SAFI (afi, safi) {
3833 if (!bgp_fibupd_safi(safi))
3834 continue;
3835 bgp_zebra_announce_table(bgp, afi, safi);
3836 }
3837 return CMD_SUCCESS;
3838 }
3839
3840 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3841 "[no] bgp default <ipv4-unicast|"
3842 "ipv4-multicast|"
3843 "ipv4-vpn|"
3844 "ipv4-labeled-unicast|"
3845 "ipv4-flowspec|"
3846 "ipv6-unicast|"
3847 "ipv6-multicast|"
3848 "ipv6-vpn|"
3849 "ipv6-labeled-unicast|"
3850 "ipv6-flowspec|"
3851 "l2vpn-evpn>$afi_safi",
3852 NO_STR
3853 BGP_STR
3854 "Configure BGP defaults\n"
3855 "Activate ipv4-unicast for a peer by default\n"
3856 "Activate ipv4-multicast for a peer by default\n"
3857 "Activate ipv4-vpn for a peer by default\n"
3858 "Activate ipv4-labeled-unicast for a peer by default\n"
3859 "Activate ipv4-flowspec for a peer by default\n"
3860 "Activate ipv6-unicast for a peer by default\n"
3861 "Activate ipv6-multicast for a peer by default\n"
3862 "Activate ipv6-vpn for a peer by default\n"
3863 "Activate ipv6-labeled-unicast for a peer by default\n"
3864 "Activate ipv6-flowspec for a peer by default\n"
3865 "Activate l2vpn-evpn for a peer by default\n")
3866 {
3867 VTY_DECLVAR_CONTEXT(bgp, bgp);
3868 char afi_safi_str[strlen(afi_safi) + 1];
3869 char *afi_safi_str_tok;
3870
3871 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3872 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3873 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3874 afi_t afi = bgp_vty_afi_from_str(afi_str);
3875 safi_t safi;
3876
3877 /*
3878 * Impossible situation but making coverity happy
3879 */
3880 assert(afi != AFI_MAX);
3881
3882 if (strmatch(safi_str, "labeled"))
3883 safi = bgp_vty_safi_from_str("labeled-unicast");
3884 else
3885 safi = bgp_vty_safi_from_str(safi_str);
3886
3887 assert(safi != SAFI_MAX);
3888 if (no)
3889 bgp->default_af[afi][safi] = false;
3890 else {
3891 if ((safi == SAFI_LABELED_UNICAST
3892 && bgp->default_af[afi][SAFI_UNICAST])
3893 || (safi == SAFI_UNICAST
3894 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3895 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3896 else
3897 bgp->default_af[afi][safi] = true;
3898 }
3899
3900 return CMD_SUCCESS;
3901 }
3902
3903 /* Display hostname in certain command outputs */
3904 DEFUN (bgp_default_show_hostname,
3905 bgp_default_show_hostname_cmd,
3906 "bgp default show-hostname",
3907 BGP_STR
3908 "Configure BGP defaults\n"
3909 "Show hostname in certain command outputs\n")
3910 {
3911 VTY_DECLVAR_CONTEXT(bgp, bgp);
3912 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3913 return CMD_SUCCESS;
3914 }
3915
3916 DEFUN (no_bgp_default_show_hostname,
3917 no_bgp_default_show_hostname_cmd,
3918 "no bgp default show-hostname",
3919 NO_STR
3920 BGP_STR
3921 "Configure BGP defaults\n"
3922 "Show hostname in certain command outputs\n")
3923 {
3924 VTY_DECLVAR_CONTEXT(bgp, bgp);
3925 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3926 return CMD_SUCCESS;
3927 }
3928
3929 /* Display hostname in certain command outputs */
3930 DEFUN (bgp_default_show_nexthop_hostname,
3931 bgp_default_show_nexthop_hostname_cmd,
3932 "bgp default show-nexthop-hostname",
3933 BGP_STR
3934 "Configure BGP defaults\n"
3935 "Show hostname for nexthop in certain command outputs\n")
3936 {
3937 VTY_DECLVAR_CONTEXT(bgp, bgp);
3938 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3939 return CMD_SUCCESS;
3940 }
3941
3942 DEFUN (no_bgp_default_show_nexthop_hostname,
3943 no_bgp_default_show_nexthop_hostname_cmd,
3944 "no bgp default show-nexthop-hostname",
3945 NO_STR
3946 BGP_STR
3947 "Configure BGP defaults\n"
3948 "Show hostname for nexthop in certain command outputs\n")
3949 {
3950 VTY_DECLVAR_CONTEXT(bgp, bgp);
3951 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3952 return CMD_SUCCESS;
3953 }
3954
3955 /* "bgp network import-check" configuration. */
3956 DEFUN (bgp_network_import_check,
3957 bgp_network_import_check_cmd,
3958 "bgp network import-check",
3959 BGP_STR
3960 "BGP network command\n"
3961 "Check BGP network route exists in IGP\n")
3962 {
3963 VTY_DECLVAR_CONTEXT(bgp, bgp);
3964 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3965 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3966 bgp_static_redo_import_check(bgp);
3967 }
3968
3969 return CMD_SUCCESS;
3970 }
3971
3972 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3973 "bgp network import-check exact",
3974 BGP_STR
3975 "BGP network command\n"
3976 "Check BGP network route exists in IGP\n"
3977 "Match route precisely\n")
3978
3979 DEFUN (no_bgp_network_import_check,
3980 no_bgp_network_import_check_cmd,
3981 "no bgp network import-check",
3982 NO_STR
3983 BGP_STR
3984 "BGP network command\n"
3985 "Check BGP network route exists in IGP\n")
3986 {
3987 VTY_DECLVAR_CONTEXT(bgp, bgp);
3988 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3989 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3990 bgp_static_redo_import_check(bgp);
3991 }
3992
3993 return CMD_SUCCESS;
3994 }
3995
3996 DEFUN (bgp_default_local_preference,
3997 bgp_default_local_preference_cmd,
3998 "bgp default local-preference (0-4294967295)",
3999 BGP_STR
4000 "Configure BGP defaults\n"
4001 "local preference (higher=more preferred)\n"
4002 "Configure default local preference value\n")
4003 {
4004 VTY_DECLVAR_CONTEXT(bgp, bgp);
4005 int idx_number = 3;
4006 uint32_t local_pref;
4007
4008 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4009
4010 bgp_default_local_preference_set(bgp, local_pref);
4011 bgp_clear_star_soft_in(vty, bgp->name);
4012
4013 return CMD_SUCCESS;
4014 }
4015
4016 DEFUN (no_bgp_default_local_preference,
4017 no_bgp_default_local_preference_cmd,
4018 "no bgp default local-preference [(0-4294967295)]",
4019 NO_STR
4020 BGP_STR
4021 "Configure BGP defaults\n"
4022 "local preference (higher=more preferred)\n"
4023 "Configure default local preference value\n")
4024 {
4025 VTY_DECLVAR_CONTEXT(bgp, bgp);
4026 bgp_default_local_preference_unset(bgp);
4027 bgp_clear_star_soft_in(vty, bgp->name);
4028
4029 return CMD_SUCCESS;
4030 }
4031
4032
4033 DEFUN (bgp_default_subgroup_pkt_queue_max,
4034 bgp_default_subgroup_pkt_queue_max_cmd,
4035 "bgp default subgroup-pkt-queue-max (20-100)",
4036 BGP_STR
4037 "Configure BGP defaults\n"
4038 "subgroup-pkt-queue-max\n"
4039 "Configure subgroup packet queue max\n")
4040 {
4041 VTY_DECLVAR_CONTEXT(bgp, bgp);
4042 int idx_number = 3;
4043 uint32_t max_size;
4044
4045 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4046
4047 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4048
4049 return CMD_SUCCESS;
4050 }
4051
4052 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4053 no_bgp_default_subgroup_pkt_queue_max_cmd,
4054 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4055 NO_STR
4056 BGP_STR
4057 "Configure BGP defaults\n"
4058 "subgroup-pkt-queue-max\n"
4059 "Configure subgroup packet queue max\n")
4060 {
4061 VTY_DECLVAR_CONTEXT(bgp, bgp);
4062 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4063 return CMD_SUCCESS;
4064 }
4065
4066
4067 DEFUN (bgp_rr_allow_outbound_policy,
4068 bgp_rr_allow_outbound_policy_cmd,
4069 "bgp route-reflector allow-outbound-policy",
4070 BGP_STR
4071 "Allow modifications made by out route-map\n"
4072 "on ibgp neighbors\n")
4073 {
4074 VTY_DECLVAR_CONTEXT(bgp, bgp);
4075
4076 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4077 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4078 update_group_announce_rrclients(bgp);
4079 bgp_clear_star_soft_out(vty, bgp->name);
4080 }
4081
4082 return CMD_SUCCESS;
4083 }
4084
4085 DEFUN (no_bgp_rr_allow_outbound_policy,
4086 no_bgp_rr_allow_outbound_policy_cmd,
4087 "no bgp route-reflector allow-outbound-policy",
4088 NO_STR
4089 BGP_STR
4090 "Allow modifications made by out route-map\n"
4091 "on ibgp neighbors\n")
4092 {
4093 VTY_DECLVAR_CONTEXT(bgp, bgp);
4094
4095 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4096 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4097 update_group_announce_rrclients(bgp);
4098 bgp_clear_star_soft_out(vty, bgp->name);
4099 }
4100
4101 return CMD_SUCCESS;
4102 }
4103
4104 DEFUN (bgp_listen_limit,
4105 bgp_listen_limit_cmd,
4106 "bgp listen limit (1-65535)",
4107 BGP_STR
4108 "BGP Dynamic Neighbors listen commands\n"
4109 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4110 "Configure Dynamic Neighbors listen limit value\n")
4111 {
4112 VTY_DECLVAR_CONTEXT(bgp, bgp);
4113 int idx_number = 3;
4114 int listen_limit;
4115
4116 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4117
4118 bgp_listen_limit_set(bgp, listen_limit);
4119
4120 return CMD_SUCCESS;
4121 }
4122
4123 DEFUN (no_bgp_listen_limit,
4124 no_bgp_listen_limit_cmd,
4125 "no bgp listen limit [(1-65535)]",
4126 NO_STR
4127 BGP_STR
4128 "BGP Dynamic Neighbors listen commands\n"
4129 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4130 "Configure Dynamic Neighbors listen limit value\n")
4131 {
4132 VTY_DECLVAR_CONTEXT(bgp, bgp);
4133 bgp_listen_limit_unset(bgp);
4134 return CMD_SUCCESS;
4135 }
4136
4137
4138 /*
4139 * Check if this listen range is already configured. Check for exact
4140 * match or overlap based on input.
4141 */
4142 static struct peer_group *listen_range_exists(struct bgp *bgp,
4143 struct prefix *range, int exact)
4144 {
4145 struct listnode *node, *nnode;
4146 struct listnode *node1, *nnode1;
4147 struct peer_group *group;
4148 struct prefix *lr;
4149 afi_t afi;
4150 int match;
4151
4152 afi = family2afi(range->family);
4153 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4154 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4155 lr)) {
4156 if (exact)
4157 match = prefix_same(range, lr);
4158 else
4159 match = (prefix_match(range, lr)
4160 || prefix_match(lr, range));
4161 if (match)
4162 return group;
4163 }
4164 }
4165
4166 return NULL;
4167 }
4168
4169 DEFUN (bgp_listen_range,
4170 bgp_listen_range_cmd,
4171 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4172 BGP_STR
4173 "Configure BGP dynamic neighbors listen range\n"
4174 "Configure BGP dynamic neighbors listen range\n"
4175 NEIGHBOR_ADDR_STR
4176 "Member of the peer-group\n"
4177 "Peer-group name\n")
4178 {
4179 VTY_DECLVAR_CONTEXT(bgp, bgp);
4180 struct prefix range;
4181 struct peer_group *group, *existing_group;
4182 afi_t afi;
4183 int ret;
4184 int idx = 0;
4185
4186 argv_find(argv, argc, "A.B.C.D/M", &idx);
4187 argv_find(argv, argc, "X:X::X:X/M", &idx);
4188 char *prefix = argv[idx]->arg;
4189 argv_find(argv, argc, "PGNAME", &idx);
4190 char *peergroup = argv[idx]->arg;
4191
4192 /* Convert IP prefix string to struct prefix. */
4193 ret = str2prefix(prefix, &range);
4194 if (!ret) {
4195 vty_out(vty, "%% Malformed listen range\n");
4196 return CMD_WARNING_CONFIG_FAILED;
4197 }
4198
4199 afi = family2afi(range.family);
4200
4201 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4202 vty_out(vty,
4203 "%% Malformed listen range (link-local address)\n");
4204 return CMD_WARNING_CONFIG_FAILED;
4205 }
4206
4207 apply_mask(&range);
4208
4209 /* Check if same listen range is already configured. */
4210 existing_group = listen_range_exists(bgp, &range, 1);
4211 if (existing_group) {
4212 if (strcmp(existing_group->name, peergroup) == 0)
4213 return CMD_SUCCESS;
4214 else {
4215 vty_out(vty,
4216 "%% Same listen range is attached to peer-group %s\n",
4217 existing_group->name);
4218 return CMD_WARNING_CONFIG_FAILED;
4219 }
4220 }
4221
4222 /* Check if an overlapping listen range exists. */
4223 if (listen_range_exists(bgp, &range, 0)) {
4224 vty_out(vty,
4225 "%% Listen range overlaps with existing listen range\n");
4226 return CMD_WARNING_CONFIG_FAILED;
4227 }
4228
4229 group = peer_group_lookup(bgp, peergroup);
4230 if (!group) {
4231 vty_out(vty, "%% Configure the peer-group first\n");
4232 return CMD_WARNING_CONFIG_FAILED;
4233 }
4234
4235 ret = peer_group_listen_range_add(group, &range);
4236 return bgp_vty_return(vty, ret);
4237 }
4238
4239 DEFUN (no_bgp_listen_range,
4240 no_bgp_listen_range_cmd,
4241 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4242 NO_STR
4243 BGP_STR
4244 "Unconfigure BGP dynamic neighbors listen range\n"
4245 "Unconfigure BGP dynamic neighbors listen range\n"
4246 NEIGHBOR_ADDR_STR
4247 "Member of the peer-group\n"
4248 "Peer-group name\n")
4249 {
4250 VTY_DECLVAR_CONTEXT(bgp, bgp);
4251 struct prefix range;
4252 struct peer_group *group;
4253 afi_t afi;
4254 int ret;
4255 int idx = 0;
4256
4257 argv_find(argv, argc, "A.B.C.D/M", &idx);
4258 argv_find(argv, argc, "X:X::X:X/M", &idx);
4259 char *prefix = argv[idx]->arg;
4260 argv_find(argv, argc, "PGNAME", &idx);
4261 char *peergroup = argv[idx]->arg;
4262
4263 /* Convert IP prefix string to struct prefix. */
4264 ret = str2prefix(prefix, &range);
4265 if (!ret) {
4266 vty_out(vty, "%% Malformed listen range\n");
4267 return CMD_WARNING_CONFIG_FAILED;
4268 }
4269
4270 afi = family2afi(range.family);
4271
4272 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4273 vty_out(vty,
4274 "%% Malformed listen range (link-local address)\n");
4275 return CMD_WARNING_CONFIG_FAILED;
4276 }
4277
4278 apply_mask(&range);
4279
4280 group = peer_group_lookup(bgp, peergroup);
4281 if (!group) {
4282 vty_out(vty, "%% Peer-group does not exist\n");
4283 return CMD_WARNING_CONFIG_FAILED;
4284 }
4285
4286 ret = peer_group_listen_range_del(group, &range);
4287 return bgp_vty_return(vty, ret);
4288 }
4289
4290 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4291 {
4292 struct peer_group *group;
4293 struct listnode *node, *nnode, *rnode, *nrnode;
4294 struct prefix *range;
4295 afi_t afi;
4296
4297 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4298 vty_out(vty, " bgp listen limit %d\n",
4299 bgp->dynamic_neighbors_limit);
4300
4301 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4302 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4303 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4304 nrnode, range)) {
4305 vty_out(vty,
4306 " bgp listen range %pFX peer-group %s\n",
4307 range, group->name);
4308 }
4309 }
4310 }
4311 }
4312
4313
4314 DEFUN (bgp_disable_connected_route_check,
4315 bgp_disable_connected_route_check_cmd,
4316 "bgp disable-ebgp-connected-route-check",
4317 BGP_STR
4318 "Disable checking if nexthop is connected on ebgp sessions\n")
4319 {
4320 VTY_DECLVAR_CONTEXT(bgp, bgp);
4321 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4322 bgp_clear_star_soft_in(vty, bgp->name);
4323
4324 return CMD_SUCCESS;
4325 }
4326
4327 DEFUN (no_bgp_disable_connected_route_check,
4328 no_bgp_disable_connected_route_check_cmd,
4329 "no bgp disable-ebgp-connected-route-check",
4330 NO_STR
4331 BGP_STR
4332 "Disable checking if nexthop is connected on ebgp sessions\n")
4333 {
4334 VTY_DECLVAR_CONTEXT(bgp, bgp);
4335 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4336 bgp_clear_star_soft_in(vty, bgp->name);
4337
4338 return CMD_SUCCESS;
4339 }
4340
4341
4342 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4343 const char *as_str)
4344 {
4345 VTY_DECLVAR_CONTEXT(bgp, bgp);
4346 int ret;
4347 as_t as;
4348 int as_type = AS_SPECIFIED;
4349 union sockunion su;
4350
4351 if (as_str[0] == 'i') {
4352 as = 0;
4353 as_type = AS_INTERNAL;
4354 } else if (as_str[0] == 'e') {
4355 as = 0;
4356 as_type = AS_EXTERNAL;
4357 } else {
4358 /* Get AS number. */
4359 as = strtoul(as_str, NULL, 10);
4360 }
4361
4362 /* If peer is peer group or interface peer, call proper function. */
4363 ret = str2sockunion(peer_str, &su);
4364 if (ret < 0) {
4365 struct peer *peer;
4366
4367 /* Check if existing interface peer */
4368 peer = peer_lookup_by_conf_if(bgp, peer_str);
4369
4370 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4371
4372 /* if not interface peer, check peer-group settings */
4373 if (ret < 0 && !peer) {
4374 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4375 if (ret < 0) {
4376 vty_out(vty,
4377 "%% Create the peer-group or interface first\n");
4378 return CMD_WARNING_CONFIG_FAILED;
4379 }
4380 return CMD_SUCCESS;
4381 }
4382 } else {
4383 if (peer_address_self_check(bgp, &su)) {
4384 vty_out(vty,
4385 "%% Can not configure the local system as neighbor\n");
4386 return CMD_WARNING_CONFIG_FAILED;
4387 }
4388 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4389 }
4390
4391 return bgp_vty_return(vty, ret);
4392 }
4393
4394 DEFUN (bgp_default_shutdown,
4395 bgp_default_shutdown_cmd,
4396 "[no] bgp default shutdown",
4397 NO_STR
4398 BGP_STR
4399 "Configure BGP defaults\n"
4400 "Apply administrative shutdown to newly configured peers\n")
4401 {
4402 VTY_DECLVAR_CONTEXT(bgp, bgp);
4403 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4404 return CMD_SUCCESS;
4405 }
4406
4407 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4408 BGP_STR
4409 "Administrative shutdown of the BGP instance\n"
4410 "Add a shutdown message (RFC 8203)\n"
4411 "Shutdown message\n")
4412 {
4413 char *msgstr = NULL;
4414
4415 VTY_DECLVAR_CONTEXT(bgp, bgp);
4416
4417 if (argc > 3)
4418 msgstr = argv_concat(argv, argc, 3);
4419
4420 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4421 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4422 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4423 return CMD_WARNING_CONFIG_FAILED;
4424 }
4425
4426 bgp_shutdown_enable(bgp, msgstr);
4427 XFREE(MTYPE_TMP, msgstr);
4428
4429 return CMD_SUCCESS;
4430 }
4431
4432 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4433 BGP_STR "Administrative shutdown of the BGP instance\n")
4434 {
4435 VTY_DECLVAR_CONTEXT(bgp, bgp);
4436
4437 bgp_shutdown_enable(bgp, NULL);
4438
4439 return CMD_SUCCESS;
4440 }
4441
4442 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4443 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4444 {
4445 VTY_DECLVAR_CONTEXT(bgp, bgp);
4446
4447 bgp_shutdown_disable(bgp);
4448
4449 return CMD_SUCCESS;
4450 }
4451
4452 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4453 "no bgp shutdown message MSG...", NO_STR BGP_STR
4454 "Administrative shutdown of the BGP instance\n"
4455 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4456
4457 DEFUN (neighbor_remote_as,
4458 neighbor_remote_as_cmd,
4459 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4460 NEIGHBOR_STR
4461 NEIGHBOR_ADDR_STR2
4462 "Specify a BGP neighbor\n"
4463 AS_STR
4464 "Internal BGP peer\n"
4465 "External BGP peer\n")
4466 {
4467 int idx_peer = 1;
4468 int idx_remote_as = 3;
4469 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4470 argv[idx_remote_as]->arg);
4471 }
4472
4473 DEFPY (bgp_allow_martian,
4474 bgp_allow_martian_cmd,
4475 "[no]$no bgp allow-martian-nexthop",
4476 NO_STR
4477 BGP_STR
4478 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4479 {
4480 VTY_DECLVAR_CONTEXT(bgp, bgp);
4481
4482 if (no)
4483 bgp->allow_martian = false;
4484 else
4485 bgp->allow_martian = true;
4486
4487 return CMD_SUCCESS;
4488 }
4489
4490 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4491 * sessions do not wait for hold timer expiry to bring down the sessions
4492 * when nexthop becomes unreachable
4493 */
4494 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4495 BGP_STR "Fast convergence for bgp sessions\n")
4496 {
4497 VTY_DECLVAR_CONTEXT(bgp, bgp);
4498 bgp->fast_convergence = true;
4499
4500 return CMD_SUCCESS;
4501 }
4502
4503 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4504 "no bgp fast-convergence",
4505 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4506 {
4507 VTY_DECLVAR_CONTEXT(bgp, bgp);
4508 bgp->fast_convergence = false;
4509
4510 return CMD_SUCCESS;
4511 }
4512
4513 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4514 int v6only,
4515 const char *peer_group_name,
4516 const char *as_str)
4517 {
4518 VTY_DECLVAR_CONTEXT(bgp, bgp);
4519 as_t as = 0;
4520 int as_type = AS_UNSPECIFIED;
4521 struct peer *peer;
4522 struct peer_group *group;
4523 int ret = 0;
4524
4525 group = peer_group_lookup(bgp, conf_if);
4526
4527 if (group) {
4528 vty_out(vty, "%% Name conflict with peer-group \n");
4529 return CMD_WARNING_CONFIG_FAILED;
4530 }
4531
4532 if (as_str) {
4533 if (as_str[0] == 'i') {
4534 as_type = AS_INTERNAL;
4535 } else if (as_str[0] == 'e') {
4536 as_type = AS_EXTERNAL;
4537 } else {
4538 /* Get AS number. */
4539 as = strtoul(as_str, NULL, 10);
4540 as_type = AS_SPECIFIED;
4541 }
4542 }
4543
4544 peer = peer_lookup_by_conf_if(bgp, conf_if);
4545 if (peer) {
4546 if (as_str)
4547 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4548 } else {
4549 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4550 NULL);
4551
4552 if (!peer) {
4553 vty_out(vty, "%% BGP failed to create peer\n");
4554 return CMD_WARNING_CONFIG_FAILED;
4555 }
4556
4557 if (v6only)
4558 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4559
4560 /* Request zebra to initiate IPv6 RAs on this interface. We do
4561 * this
4562 * any unnumbered peer in order to not worry about run-time
4563 * transitions
4564 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4565 * address
4566 * gets deleted later etc.)
4567 */
4568 if (peer->ifp)
4569 bgp_zebra_initiate_radv(bgp, peer);
4570 }
4571
4572 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4573 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4574 if (v6only)
4575 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4576 else
4577 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4578
4579 /* v6only flag changed. Reset bgp seesion */
4580 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4581 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4582 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4583 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4584 } else
4585 bgp_session_reset(peer);
4586 }
4587
4588 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4589 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4590 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4591 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4592 }
4593
4594 if (peer_group_name) {
4595 group = peer_group_lookup(bgp, peer_group_name);
4596 if (!group) {
4597 vty_out(vty, "%% Configure the peer-group first\n");
4598 return CMD_WARNING_CONFIG_FAILED;
4599 }
4600
4601 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4602 }
4603
4604 return bgp_vty_return(vty, ret);
4605 }
4606
4607 DEFUN (neighbor_interface_config,
4608 neighbor_interface_config_cmd,
4609 "neighbor WORD interface [peer-group PGNAME]",
4610 NEIGHBOR_STR
4611 "Interface name or neighbor tag\n"
4612 "Enable BGP on interface\n"
4613 "Member of the peer-group\n"
4614 "Peer-group name\n")
4615 {
4616 int idx_word = 1;
4617 int idx_peer_group_word = 4;
4618
4619 if (argc > idx_peer_group_word)
4620 return peer_conf_interface_get(
4621 vty, argv[idx_word]->arg, 0,
4622 argv[idx_peer_group_word]->arg, NULL);
4623 else
4624 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4625 NULL, NULL);
4626 }
4627
4628 DEFUN (neighbor_interface_config_v6only,
4629 neighbor_interface_config_v6only_cmd,
4630 "neighbor WORD interface v6only [peer-group PGNAME]",
4631 NEIGHBOR_STR
4632 "Interface name or neighbor tag\n"
4633 "Enable BGP on interface\n"
4634 "Enable BGP with v6 link-local only\n"
4635 "Member of the peer-group\n"
4636 "Peer-group name\n")
4637 {
4638 int idx_word = 1;
4639 int idx_peer_group_word = 5;
4640
4641 if (argc > idx_peer_group_word)
4642 return peer_conf_interface_get(
4643 vty, argv[idx_word]->arg, 1,
4644 argv[idx_peer_group_word]->arg, NULL);
4645
4646 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4647 }
4648
4649
4650 DEFUN (neighbor_interface_config_remote_as,
4651 neighbor_interface_config_remote_as_cmd,
4652 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4653 NEIGHBOR_STR
4654 "Interface name or neighbor tag\n"
4655 "Enable BGP on interface\n"
4656 "Specify a BGP neighbor\n"
4657 AS_STR
4658 "Internal BGP peer\n"
4659 "External BGP peer\n")
4660 {
4661 int idx_word = 1;
4662 int idx_remote_as = 4;
4663 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4664 argv[idx_remote_as]->arg);
4665 }
4666
4667 DEFUN (neighbor_interface_v6only_config_remote_as,
4668 neighbor_interface_v6only_config_remote_as_cmd,
4669 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4670 NEIGHBOR_STR
4671 "Interface name or neighbor tag\n"
4672 "Enable BGP with v6 link-local only\n"
4673 "Enable BGP on interface\n"
4674 "Specify a BGP neighbor\n"
4675 AS_STR
4676 "Internal BGP peer\n"
4677 "External BGP peer\n")
4678 {
4679 int idx_word = 1;
4680 int idx_remote_as = 5;
4681 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4682 argv[idx_remote_as]->arg);
4683 }
4684
4685 DEFUN (neighbor_peer_group,
4686 neighbor_peer_group_cmd,
4687 "neighbor WORD peer-group",
4688 NEIGHBOR_STR
4689 "Interface name or neighbor tag\n"
4690 "Configure peer-group\n")
4691 {
4692 VTY_DECLVAR_CONTEXT(bgp, bgp);
4693 int idx_word = 1;
4694 struct peer *peer;
4695 struct peer_group *group;
4696
4697 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4698 if (peer) {
4699 vty_out(vty, "%% Name conflict with interface: \n");
4700 return CMD_WARNING_CONFIG_FAILED;
4701 }
4702
4703 group = peer_group_get(bgp, argv[idx_word]->arg);
4704 if (!group) {
4705 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4706 return CMD_WARNING_CONFIG_FAILED;
4707 }
4708
4709 return CMD_SUCCESS;
4710 }
4711
4712 DEFUN (no_neighbor,
4713 no_neighbor_cmd,
4714 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4715 NO_STR
4716 NEIGHBOR_STR
4717 NEIGHBOR_ADDR_STR2
4718 "Specify a BGP neighbor\n"
4719 AS_STR
4720 "Internal BGP peer\n"
4721 "External BGP peer\n")
4722 {
4723 VTY_DECLVAR_CONTEXT(bgp, bgp);
4724 int idx_peer = 2;
4725 int ret;
4726 union sockunion su;
4727 struct peer_group *group;
4728 struct peer *peer;
4729 struct peer *other;
4730
4731 ret = str2sockunion(argv[idx_peer]->arg, &su);
4732 if (ret < 0) {
4733 /* look up for neighbor by interface name config. */
4734 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4735 if (peer) {
4736 /* Request zebra to terminate IPv6 RAs on this
4737 * interface. */
4738 if (peer->ifp)
4739 bgp_zebra_terminate_radv(peer->bgp, peer);
4740 peer_notify_unconfig(peer);
4741 peer_delete(peer);
4742 return CMD_SUCCESS;
4743 }
4744
4745 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4746 if (group) {
4747 peer_group_notify_unconfig(group);
4748 peer_group_delete(group);
4749 } else {
4750 vty_out(vty, "%% Create the peer-group first\n");
4751 return CMD_WARNING_CONFIG_FAILED;
4752 }
4753 } else {
4754 peer = peer_lookup(bgp, &su);
4755 if (peer) {
4756 if (peer_dynamic_neighbor(peer)) {
4757 vty_out(vty,
4758 "%% Operation not allowed on a dynamic neighbor\n");
4759 return CMD_WARNING_CONFIG_FAILED;
4760 }
4761
4762 other = peer->doppelganger;
4763
4764 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4765 bgp_zebra_terminate_radv(peer->bgp, peer);
4766
4767 peer_notify_unconfig(peer);
4768 peer_delete(peer);
4769 if (other && other->status != Deleted) {
4770 peer_notify_unconfig(other);
4771 peer_delete(other);
4772 }
4773 }
4774 }
4775
4776 return CMD_SUCCESS;
4777 }
4778
4779 DEFUN (no_neighbor_interface_config,
4780 no_neighbor_interface_config_cmd,
4781 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4782 NO_STR
4783 NEIGHBOR_STR
4784 "Interface name\n"
4785 "Configure BGP on interface\n"
4786 "Enable BGP with v6 link-local only\n"
4787 "Member of the peer-group\n"
4788 "Peer-group name\n"
4789 "Specify a BGP neighbor\n"
4790 AS_STR
4791 "Internal BGP peer\n"
4792 "External BGP peer\n")
4793 {
4794 VTY_DECLVAR_CONTEXT(bgp, bgp);
4795 int idx_word = 2;
4796 struct peer *peer;
4797
4798 /* look up for neighbor by interface name config. */
4799 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4800 if (peer) {
4801 /* Request zebra to terminate IPv6 RAs on this interface. */
4802 if (peer->ifp)
4803 bgp_zebra_terminate_radv(peer->bgp, peer);
4804 peer_notify_unconfig(peer);
4805 peer_delete(peer);
4806 } else {
4807 vty_out(vty, "%% Create the bgp interface first\n");
4808 return CMD_WARNING_CONFIG_FAILED;
4809 }
4810 return CMD_SUCCESS;
4811 }
4812
4813 DEFUN (no_neighbor_peer_group,
4814 no_neighbor_peer_group_cmd,
4815 "no neighbor WORD peer-group",
4816 NO_STR
4817 NEIGHBOR_STR
4818 "Neighbor tag\n"
4819 "Configure peer-group\n")
4820 {
4821 VTY_DECLVAR_CONTEXT(bgp, bgp);
4822 int idx_word = 2;
4823 struct peer_group *group;
4824
4825 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4826 if (group) {
4827 peer_group_notify_unconfig(group);
4828 peer_group_delete(group);
4829 } else {
4830 vty_out(vty, "%% Create the peer-group first\n");
4831 return CMD_WARNING_CONFIG_FAILED;
4832 }
4833 return CMD_SUCCESS;
4834 }
4835
4836 DEFUN (no_neighbor_interface_peer_group_remote_as,
4837 no_neighbor_interface_peer_group_remote_as_cmd,
4838 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4839 NO_STR
4840 NEIGHBOR_STR
4841 "Interface name or neighbor tag\n"
4842 "Specify a BGP neighbor\n"
4843 AS_STR
4844 "Internal BGP peer\n"
4845 "External BGP peer\n")
4846 {
4847 VTY_DECLVAR_CONTEXT(bgp, bgp);
4848 int idx_word = 2;
4849 struct peer_group *group;
4850 struct peer *peer;
4851
4852 /* look up for neighbor by interface name config. */
4853 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4854 if (peer) {
4855 peer_as_change(peer, 0, AS_UNSPECIFIED);
4856 return CMD_SUCCESS;
4857 }
4858
4859 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4860 if (group)
4861 peer_group_remote_as_delete(group);
4862 else {
4863 vty_out(vty, "%% Create the peer-group or interface first\n");
4864 return CMD_WARNING_CONFIG_FAILED;
4865 }
4866 return CMD_SUCCESS;
4867 }
4868
4869 DEFUN (neighbor_local_as,
4870 neighbor_local_as_cmd,
4871 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4872 NEIGHBOR_STR
4873 NEIGHBOR_ADDR_STR2
4874 "Specify a local-as number\n"
4875 "AS number used as local AS\n")
4876 {
4877 int idx_peer = 1;
4878 int idx_number = 3;
4879 struct peer *peer;
4880 int ret;
4881 as_t as;
4882
4883 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4884 if (!peer)
4885 return CMD_WARNING_CONFIG_FAILED;
4886
4887 as = strtoul(argv[idx_number]->arg, NULL, 10);
4888 ret = peer_local_as_set(peer, as, 0, 0);
4889 return bgp_vty_return(vty, ret);
4890 }
4891
4892 DEFUN (neighbor_local_as_no_prepend,
4893 neighbor_local_as_no_prepend_cmd,
4894 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4895 NEIGHBOR_STR
4896 NEIGHBOR_ADDR_STR2
4897 "Specify a local-as number\n"
4898 "AS number used as local AS\n"
4899 "Do not prepend local-as to updates from ebgp peers\n")
4900 {
4901 int idx_peer = 1;
4902 int idx_number = 3;
4903 struct peer *peer;
4904 int ret;
4905 as_t as;
4906
4907 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4908 if (!peer)
4909 return CMD_WARNING_CONFIG_FAILED;
4910
4911 as = strtoul(argv[idx_number]->arg, NULL, 10);
4912 ret = peer_local_as_set(peer, as, 1, 0);
4913 return bgp_vty_return(vty, ret);
4914 }
4915
4916 DEFUN (neighbor_local_as_no_prepend_replace_as,
4917 neighbor_local_as_no_prepend_replace_as_cmd,
4918 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4919 NEIGHBOR_STR
4920 NEIGHBOR_ADDR_STR2
4921 "Specify a local-as number\n"
4922 "AS number used as local AS\n"
4923 "Do not prepend local-as to updates from ebgp peers\n"
4924 "Do not prepend local-as to updates from ibgp peers\n")
4925 {
4926 int idx_peer = 1;
4927 int idx_number = 3;
4928 struct peer *peer;
4929 int ret;
4930 as_t as;
4931
4932 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4933 if (!peer)
4934 return CMD_WARNING_CONFIG_FAILED;
4935
4936 as = strtoul(argv[idx_number]->arg, NULL, 10);
4937 ret = peer_local_as_set(peer, as, 1, 1);
4938 return bgp_vty_return(vty, ret);
4939 }
4940
4941 DEFUN (no_neighbor_local_as,
4942 no_neighbor_local_as_cmd,
4943 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4944 NO_STR
4945 NEIGHBOR_STR
4946 NEIGHBOR_ADDR_STR2
4947 "Specify a local-as number\n"
4948 "AS number used as local AS\n"
4949 "Do not prepend local-as to updates from ebgp peers\n"
4950 "Do not prepend local-as to updates from ibgp peers\n")
4951 {
4952 int idx_peer = 2;
4953 struct peer *peer;
4954 int ret;
4955
4956 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4957 if (!peer)
4958 return CMD_WARNING_CONFIG_FAILED;
4959
4960 ret = peer_local_as_unset(peer);
4961 return bgp_vty_return(vty, ret);
4962 }
4963
4964
4965 DEFUN (neighbor_solo,
4966 neighbor_solo_cmd,
4967 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4968 NEIGHBOR_STR
4969 NEIGHBOR_ADDR_STR2
4970 "Solo peer - part of its own update group\n")
4971 {
4972 int idx_peer = 1;
4973 struct peer *peer;
4974 int ret;
4975
4976 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4977 if (!peer)
4978 return CMD_WARNING_CONFIG_FAILED;
4979
4980 ret = update_group_adjust_soloness(peer, 1);
4981 return bgp_vty_return(vty, ret);
4982 }
4983
4984 DEFUN (no_neighbor_solo,
4985 no_neighbor_solo_cmd,
4986 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4987 NO_STR
4988 NEIGHBOR_STR
4989 NEIGHBOR_ADDR_STR2
4990 "Solo peer - part of its own update group\n")
4991 {
4992 int idx_peer = 2;
4993 struct peer *peer;
4994 int ret;
4995
4996 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4997 if (!peer)
4998 return CMD_WARNING_CONFIG_FAILED;
4999
5000 ret = update_group_adjust_soloness(peer, 0);
5001 return bgp_vty_return(vty, ret);
5002 }
5003
5004 DEFUN (neighbor_password,
5005 neighbor_password_cmd,
5006 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5007 NEIGHBOR_STR
5008 NEIGHBOR_ADDR_STR2
5009 "Set a password\n"
5010 "The password\n")
5011 {
5012 int idx_peer = 1;
5013 int idx_line = 3;
5014 struct peer *peer;
5015 int ret;
5016
5017 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5018 if (!peer)
5019 return CMD_WARNING_CONFIG_FAILED;
5020
5021 ret = peer_password_set(peer, argv[idx_line]->arg);
5022 return bgp_vty_return(vty, ret);
5023 }
5024
5025 DEFUN (no_neighbor_password,
5026 no_neighbor_password_cmd,
5027 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5028 NO_STR
5029 NEIGHBOR_STR
5030 NEIGHBOR_ADDR_STR2
5031 "Set a password\n"
5032 "The password\n")
5033 {
5034 int idx_peer = 2;
5035 struct peer *peer;
5036 int ret;
5037
5038 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5039 if (!peer)
5040 return CMD_WARNING_CONFIG_FAILED;
5041
5042 ret = peer_password_unset(peer);
5043 return bgp_vty_return(vty, ret);
5044 }
5045
5046 DEFUN (neighbor_activate,
5047 neighbor_activate_cmd,
5048 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5049 NEIGHBOR_STR
5050 NEIGHBOR_ADDR_STR2
5051 "Enable the Address Family for this Neighbor\n")
5052 {
5053 int idx_peer = 1;
5054 int ret;
5055 struct peer *peer;
5056
5057 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5058 if (!peer)
5059 return CMD_WARNING_CONFIG_FAILED;
5060
5061 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5062 return bgp_vty_return(vty, ret);
5063 }
5064
5065 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5066 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5067 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5068 "Enable the Address Family for this Neighbor\n")
5069
5070 DEFUN (no_neighbor_activate,
5071 no_neighbor_activate_cmd,
5072 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5073 NO_STR
5074 NEIGHBOR_STR
5075 NEIGHBOR_ADDR_STR2
5076 "Enable the Address Family for this Neighbor\n")
5077 {
5078 int idx_peer = 2;
5079 int ret;
5080 struct peer *peer;
5081
5082 /* Lookup peer. */
5083 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5084 if (!peer)
5085 return CMD_WARNING_CONFIG_FAILED;
5086
5087 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5088 return bgp_vty_return(vty, ret);
5089 }
5090
5091 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5092 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5093 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5094 "Enable the Address Family for this Neighbor\n")
5095
5096 DEFUN (neighbor_set_peer_group,
5097 neighbor_set_peer_group_cmd,
5098 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5099 NEIGHBOR_STR
5100 NEIGHBOR_ADDR_STR2
5101 "Member of the peer-group\n"
5102 "Peer-group name\n")
5103 {
5104 VTY_DECLVAR_CONTEXT(bgp, bgp);
5105 int idx_peer = 1;
5106 int idx_word = 3;
5107 int ret;
5108 as_t as;
5109 union sockunion su;
5110 struct peer *peer;
5111 struct peer_group *group;
5112
5113 ret = str2sockunion(argv[idx_peer]->arg, &su);
5114 if (ret < 0) {
5115 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5116 if (!peer) {
5117 vty_out(vty, "%% Malformed address or name: %s\n",
5118 argv[idx_peer]->arg);
5119 return CMD_WARNING_CONFIG_FAILED;
5120 }
5121 } else {
5122 if (peer_address_self_check(bgp, &su)) {
5123 vty_out(vty,
5124 "%% Can not configure the local system as neighbor\n");
5125 return CMD_WARNING_CONFIG_FAILED;
5126 }
5127
5128 /* Disallow for dynamic neighbor. */
5129 peer = peer_lookup(bgp, &su);
5130 if (peer && peer_dynamic_neighbor(peer)) {
5131 vty_out(vty,
5132 "%% Operation not allowed on a dynamic neighbor\n");
5133 return CMD_WARNING_CONFIG_FAILED;
5134 }
5135 }
5136
5137 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5138 if (!group) {
5139 vty_out(vty, "%% Configure the peer-group first\n");
5140 return CMD_WARNING_CONFIG_FAILED;
5141 }
5142
5143 ret = peer_group_bind(bgp, &su, peer, group, &as);
5144
5145 return bgp_vty_return(vty, ret);
5146 }
5147
5148 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5149 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5150 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5151 "Member of the peer-group\n"
5152 "Peer-group name\n")
5153
5154 DEFUN (no_neighbor_set_peer_group,
5155 no_neighbor_set_peer_group_cmd,
5156 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5157 NO_STR
5158 NEIGHBOR_STR
5159 NEIGHBOR_ADDR_STR2
5160 "Member of the peer-group\n"
5161 "Peer-group name\n")
5162 {
5163 VTY_DECLVAR_CONTEXT(bgp, bgp);
5164 int idx_peer = 2;
5165 int idx_word = 4;
5166 int ret;
5167 struct peer *peer;
5168 struct peer_group *group;
5169
5170 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5171 if (!peer)
5172 return CMD_WARNING_CONFIG_FAILED;
5173
5174 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5175 if (!group) {
5176 vty_out(vty, "%% Configure the peer-group first\n");
5177 return CMD_WARNING_CONFIG_FAILED;
5178 }
5179
5180 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5181 bgp_zebra_terminate_radv(peer->bgp, peer);
5182
5183 peer_notify_unconfig(peer);
5184 ret = peer_delete(peer);
5185
5186 return bgp_vty_return(vty, ret);
5187 }
5188
5189 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5190 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5191 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5192 "Member of the peer-group\n"
5193 "Peer-group name\n")
5194
5195 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5196 uint64_t flag, int set)
5197 {
5198 int ret;
5199 struct peer *peer;
5200
5201 peer = peer_and_group_lookup_vty(vty, ip_str);
5202 if (!peer)
5203 return CMD_WARNING_CONFIG_FAILED;
5204
5205 /*
5206 * If 'neighbor <interface>', then this is for directly connected peers,
5207 * we should not accept disable-connected-check.
5208 */
5209 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5210 vty_out(vty,
5211 "%s is directly connected peer, cannot accept disable-connected-check\n",
5212 ip_str);
5213 return CMD_WARNING_CONFIG_FAILED;
5214 }
5215
5216 if (!set && flag == PEER_FLAG_SHUTDOWN)
5217 peer_tx_shutdown_message_unset(peer);
5218
5219 if (set)
5220 ret = peer_flag_set(peer, flag);
5221 else
5222 ret = peer_flag_unset(peer, flag);
5223
5224 return bgp_vty_return(vty, ret);
5225 }
5226
5227 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5228 {
5229 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5230 }
5231
5232 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5233 uint64_t flag)
5234 {
5235 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5236 }
5237
5238 /* neighbor passive. */
5239 DEFUN (neighbor_passive,
5240 neighbor_passive_cmd,
5241 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5242 NEIGHBOR_STR
5243 NEIGHBOR_ADDR_STR2
5244 "Don't send open messages to this neighbor\n")
5245 {
5246 int idx_peer = 1;
5247 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5248 }
5249
5250 DEFUN (no_neighbor_passive,
5251 no_neighbor_passive_cmd,
5252 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5253 NO_STR
5254 NEIGHBOR_STR
5255 NEIGHBOR_ADDR_STR2
5256 "Don't send open messages to this neighbor\n")
5257 {
5258 int idx_peer = 2;
5259 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5260 }
5261
5262 /* neighbor shutdown. */
5263 DEFUN (neighbor_shutdown_msg,
5264 neighbor_shutdown_msg_cmd,
5265 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5266 NEIGHBOR_STR
5267 NEIGHBOR_ADDR_STR2
5268 "Administratively shut down this neighbor\n"
5269 "Add a shutdown message (RFC 8203)\n"
5270 "Shutdown message\n")
5271 {
5272 int idx_peer = 1;
5273
5274 if (argc >= 5) {
5275 struct peer *peer =
5276 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5277 char *message;
5278
5279 if (!peer)
5280 return CMD_WARNING_CONFIG_FAILED;
5281 message = argv_concat(argv, argc, 4);
5282 peer_tx_shutdown_message_set(peer, message);
5283 XFREE(MTYPE_TMP, message);
5284 }
5285
5286 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5287 }
5288
5289 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5290 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5291 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5292 "Administratively shut down this neighbor\n")
5293
5294 DEFUN (no_neighbor_shutdown_msg,
5295 no_neighbor_shutdown_msg_cmd,
5296 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5297 NO_STR
5298 NEIGHBOR_STR
5299 NEIGHBOR_ADDR_STR2
5300 "Administratively shut down this neighbor\n"
5301 "Remove a shutdown message (RFC 8203)\n"
5302 "Shutdown message\n")
5303 {
5304 int idx_peer = 2;
5305
5306 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5307 PEER_FLAG_SHUTDOWN);
5308 }
5309
5310 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5311 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5312 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5313 "Administratively shut down this neighbor\n")
5314
5315 DEFUN(neighbor_shutdown_rtt,
5316 neighbor_shutdown_rtt_cmd,
5317 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5318 NEIGHBOR_STR
5319 NEIGHBOR_ADDR_STR2
5320 "Administratively shut down this neighbor\n"
5321 "Shutdown if round-trip-time is higher than expected\n"
5322 "Round-trip-time in milliseconds\n"
5323 "Specify the number of keepalives before shutdown\n"
5324 "The number of keepalives with higher RTT to shutdown\n")
5325 {
5326 int idx_peer = 1;
5327 int idx_rtt = 4;
5328 int idx_count = 0;
5329 struct peer *peer;
5330
5331 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5332
5333 if (!peer)
5334 return CMD_WARNING_CONFIG_FAILED;
5335
5336 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5337
5338 if (argv_find(argv, argc, "count", &idx_count))
5339 peer->rtt_keepalive_conf =
5340 strtol(argv[idx_count + 1]->arg, NULL, 10);
5341
5342 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5343 PEER_FLAG_RTT_SHUTDOWN);
5344 }
5345
5346 DEFUN(no_neighbor_shutdown_rtt,
5347 no_neighbor_shutdown_rtt_cmd,
5348 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5349 NO_STR
5350 NEIGHBOR_STR
5351 NEIGHBOR_ADDR_STR2
5352 "Administratively shut down this neighbor\n"
5353 "Shutdown if round-trip-time is higher than expected\n"
5354 "Round-trip-time in milliseconds\n"
5355 "Specify the number of keepalives before shutdown\n"
5356 "The number of keepalives with higher RTT to shutdown\n")
5357 {
5358 int idx_peer = 2;
5359 struct peer *peer;
5360
5361 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5362
5363 if (!peer)
5364 return CMD_WARNING_CONFIG_FAILED;
5365
5366 peer->rtt_expected = 0;
5367 peer->rtt_keepalive_conf = 1;
5368
5369 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5370 PEER_FLAG_RTT_SHUTDOWN);
5371 }
5372
5373 /* neighbor capability dynamic. */
5374 DEFUN (neighbor_capability_dynamic,
5375 neighbor_capability_dynamic_cmd,
5376 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5377 NEIGHBOR_STR
5378 NEIGHBOR_ADDR_STR2
5379 "Advertise capability to the peer\n"
5380 "Advertise dynamic capability to this neighbor\n")
5381 {
5382 int idx_peer = 1;
5383 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5384 PEER_FLAG_DYNAMIC_CAPABILITY);
5385 }
5386
5387 DEFUN (no_neighbor_capability_dynamic,
5388 no_neighbor_capability_dynamic_cmd,
5389 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5390 NO_STR
5391 NEIGHBOR_STR
5392 NEIGHBOR_ADDR_STR2
5393 "Advertise capability to the peer\n"
5394 "Advertise dynamic capability to this neighbor\n")
5395 {
5396 int idx_peer = 2;
5397 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5398 PEER_FLAG_DYNAMIC_CAPABILITY);
5399 }
5400
5401 /* neighbor dont-capability-negotiate */
5402 DEFUN (neighbor_dont_capability_negotiate,
5403 neighbor_dont_capability_negotiate_cmd,
5404 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5405 NEIGHBOR_STR
5406 NEIGHBOR_ADDR_STR2
5407 "Do not perform capability negotiation\n")
5408 {
5409 int idx_peer = 1;
5410 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5411 PEER_FLAG_DONT_CAPABILITY);
5412 }
5413
5414 DEFUN (no_neighbor_dont_capability_negotiate,
5415 no_neighbor_dont_capability_negotiate_cmd,
5416 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5417 NO_STR
5418 NEIGHBOR_STR
5419 NEIGHBOR_ADDR_STR2
5420 "Do not perform capability negotiation\n")
5421 {
5422 int idx_peer = 2;
5423 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5424 PEER_FLAG_DONT_CAPABILITY);
5425 }
5426
5427 /* neighbor capability extended next hop encoding */
5428 DEFUN (neighbor_capability_enhe,
5429 neighbor_capability_enhe_cmd,
5430 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5431 NEIGHBOR_STR
5432 NEIGHBOR_ADDR_STR2
5433 "Advertise capability to the peer\n"
5434 "Advertise extended next-hop capability to the peer\n")
5435 {
5436 int idx_peer = 1;
5437 struct peer *peer;
5438
5439 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5440 if (peer && peer->conf_if)
5441 return CMD_SUCCESS;
5442
5443 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5444 PEER_FLAG_CAPABILITY_ENHE);
5445 }
5446
5447 DEFUN (no_neighbor_capability_enhe,
5448 no_neighbor_capability_enhe_cmd,
5449 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5450 NO_STR
5451 NEIGHBOR_STR
5452 NEIGHBOR_ADDR_STR2
5453 "Advertise capability to the peer\n"
5454 "Advertise extended next-hop capability to the peer\n")
5455 {
5456 int idx_peer = 2;
5457 struct peer *peer;
5458
5459 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5460 if (peer && peer->conf_if) {
5461 vty_out(vty,
5462 "Peer %s cannot have capability extended-nexthop turned off\n",
5463 argv[idx_peer]->arg);
5464 return CMD_WARNING_CONFIG_FAILED;
5465 }
5466
5467 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5468 PEER_FLAG_CAPABILITY_ENHE);
5469 }
5470
5471 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5472 afi_t afi, safi_t safi, uint32_t flag,
5473 int set)
5474 {
5475 int ret;
5476 struct peer *peer;
5477
5478 peer = peer_and_group_lookup_vty(vty, peer_str);
5479 if (!peer)
5480 return CMD_WARNING_CONFIG_FAILED;
5481
5482 if (set)
5483 ret = peer_af_flag_set(peer, afi, safi, flag);
5484 else
5485 ret = peer_af_flag_unset(peer, afi, safi, flag);
5486
5487 return bgp_vty_return(vty, ret);
5488 }
5489
5490 static int peer_af_flag_set_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, 1);
5494 }
5495
5496 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5497 afi_t afi, safi_t safi, uint32_t flag)
5498 {
5499 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5500 }
5501
5502 /* neighbor capability orf prefix-list. */
5503 DEFUN (neighbor_capability_orf_prefix,
5504 neighbor_capability_orf_prefix_cmd,
5505 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5506 NEIGHBOR_STR
5507 NEIGHBOR_ADDR_STR2
5508 "Advertise capability to the peer\n"
5509 "Advertise ORF capability to the peer\n"
5510 "Advertise prefixlist ORF capability to this neighbor\n"
5511 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5512 "Capability to RECEIVE the ORF from this neighbor\n"
5513 "Capability to SEND the ORF to this neighbor\n")
5514 {
5515 int idx_send_recv = 5;
5516 char *peer_str = argv[1]->arg;
5517 struct peer *peer;
5518 afi_t afi = bgp_node_afi(vty);
5519 safi_t safi = bgp_node_safi(vty);
5520
5521 peer = peer_and_group_lookup_vty(vty, peer_str);
5522 if (!peer)
5523 return CMD_WARNING_CONFIG_FAILED;
5524
5525 if (strmatch(argv[idx_send_recv]->text, "send"))
5526 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5527 PEER_FLAG_ORF_PREFIX_SM);
5528
5529 if (strmatch(argv[idx_send_recv]->text, "receive"))
5530 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5531 PEER_FLAG_ORF_PREFIX_RM);
5532
5533 if (strmatch(argv[idx_send_recv]->text, "both"))
5534 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5535 PEER_FLAG_ORF_PREFIX_SM)
5536 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5537 PEER_FLAG_ORF_PREFIX_RM);
5538
5539 return CMD_WARNING_CONFIG_FAILED;
5540 }
5541
5542 ALIAS_HIDDEN(
5543 neighbor_capability_orf_prefix,
5544 neighbor_capability_orf_prefix_hidden_cmd,
5545 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5546 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5547 "Advertise capability to the peer\n"
5548 "Advertise ORF capability to the peer\n"
5549 "Advertise prefixlist ORF capability to this neighbor\n"
5550 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5551 "Capability to RECEIVE the ORF from this neighbor\n"
5552 "Capability to SEND the ORF to this neighbor\n")
5553
5554 DEFUN (no_neighbor_capability_orf_prefix,
5555 no_neighbor_capability_orf_prefix_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5557 NO_STR
5558 NEIGHBOR_STR
5559 NEIGHBOR_ADDR_STR2
5560 "Advertise capability to the peer\n"
5561 "Advertise ORF capability to the peer\n"
5562 "Advertise prefixlist ORF capability to this neighbor\n"
5563 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5564 "Capability to RECEIVE the ORF from this neighbor\n"
5565 "Capability to SEND the ORF to this neighbor\n")
5566 {
5567 int idx_send_recv = 6;
5568 char *peer_str = argv[2]->arg;
5569 struct peer *peer;
5570 afi_t afi = bgp_node_afi(vty);
5571 safi_t safi = bgp_node_safi(vty);
5572
5573 peer = peer_and_group_lookup_vty(vty, peer_str);
5574 if (!peer)
5575 return CMD_WARNING_CONFIG_FAILED;
5576
5577 if (strmatch(argv[idx_send_recv]->text, "send"))
5578 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5579 PEER_FLAG_ORF_PREFIX_SM);
5580
5581 if (strmatch(argv[idx_send_recv]->text, "receive"))
5582 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5583 PEER_FLAG_ORF_PREFIX_RM);
5584
5585 if (strmatch(argv[idx_send_recv]->text, "both"))
5586 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5587 PEER_FLAG_ORF_PREFIX_SM)
5588 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5589 PEER_FLAG_ORF_PREFIX_RM);
5590
5591 return CMD_WARNING_CONFIG_FAILED;
5592 }
5593
5594 ALIAS_HIDDEN(
5595 no_neighbor_capability_orf_prefix,
5596 no_neighbor_capability_orf_prefix_hidden_cmd,
5597 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5598 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5599 "Advertise capability to the peer\n"
5600 "Advertise ORF capability to the peer\n"
5601 "Advertise prefixlist ORF capability to this neighbor\n"
5602 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5603 "Capability to RECEIVE the ORF from this neighbor\n"
5604 "Capability to SEND the ORF to this neighbor\n")
5605
5606 /* neighbor next-hop-self. */
5607 DEFUN (neighbor_nexthop_self,
5608 neighbor_nexthop_self_cmd,
5609 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5610 NEIGHBOR_STR
5611 NEIGHBOR_ADDR_STR2
5612 "Disable the next hop calculation for this neighbor\n")
5613 {
5614 int idx_peer = 1;
5615 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5616 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5617 }
5618
5619 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5620 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5621 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5622 "Disable the next hop calculation for this neighbor\n")
5623
5624 /* neighbor next-hop-self. */
5625 DEFUN (neighbor_nexthop_self_force,
5626 neighbor_nexthop_self_force_cmd,
5627 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5628 NEIGHBOR_STR
5629 NEIGHBOR_ADDR_STR2
5630 "Disable the next hop calculation for this neighbor\n"
5631 "Set the next hop to self for reflected routes\n")
5632 {
5633 int idx_peer = 1;
5634 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5635 bgp_node_safi(vty),
5636 PEER_FLAG_FORCE_NEXTHOP_SELF);
5637 }
5638
5639 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5640 neighbor_nexthop_self_force_hidden_cmd,
5641 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5642 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5643 "Disable the next hop calculation for this neighbor\n"
5644 "Set the next hop to self for reflected routes\n")
5645
5646 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5647 neighbor_nexthop_self_all_hidden_cmd,
5648 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5649 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5650 "Disable the next hop calculation for this neighbor\n"
5651 "Set the next hop to self for reflected routes\n")
5652
5653 DEFUN (no_neighbor_nexthop_self,
5654 no_neighbor_nexthop_self_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5656 NO_STR
5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Disable the next hop calculation for this neighbor\n")
5660 {
5661 int idx_peer = 2;
5662 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5663 bgp_node_afi(vty), bgp_node_safi(vty),
5664 PEER_FLAG_NEXTHOP_SELF);
5665 }
5666
5667 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5668 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5669 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5670 "Disable the next hop calculation for this neighbor\n")
5671
5672 DEFUN (no_neighbor_nexthop_self_force,
5673 no_neighbor_nexthop_self_force_cmd,
5674 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5675 NO_STR
5676 NEIGHBOR_STR
5677 NEIGHBOR_ADDR_STR2
5678 "Disable the next hop calculation for this neighbor\n"
5679 "Set the next hop to self for reflected routes\n")
5680 {
5681 int idx_peer = 2;
5682 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5683 bgp_node_afi(vty), bgp_node_safi(vty),
5684 PEER_FLAG_FORCE_NEXTHOP_SELF);
5685 }
5686
5687 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5688 no_neighbor_nexthop_self_force_hidden_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5690 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Disable the next hop calculation for this neighbor\n"
5692 "Set the next hop to self for reflected routes\n")
5693
5694 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5695 no_neighbor_nexthop_self_all_hidden_cmd,
5696 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5697 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5698 "Disable the next hop calculation for this neighbor\n"
5699 "Set the next hop to self for reflected routes\n")
5700
5701 /* neighbor as-override */
5702 DEFUN (neighbor_as_override,
5703 neighbor_as_override_cmd,
5704 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5705 NEIGHBOR_STR
5706 NEIGHBOR_ADDR_STR2
5707 "Override ASNs in outbound updates if aspath equals remote-as\n")
5708 {
5709 int idx_peer = 1;
5710 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5711 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5712 }
5713
5714 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5715 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5716 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5717 "Override ASNs in outbound updates if aspath equals remote-as\n")
5718
5719 DEFUN (no_neighbor_as_override,
5720 no_neighbor_as_override_cmd,
5721 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5722 NO_STR
5723 NEIGHBOR_STR
5724 NEIGHBOR_ADDR_STR2
5725 "Override ASNs in outbound updates if aspath equals remote-as\n")
5726 {
5727 int idx_peer = 2;
5728 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5729 bgp_node_afi(vty), bgp_node_safi(vty),
5730 PEER_FLAG_AS_OVERRIDE);
5731 }
5732
5733 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5734 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5735 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Override ASNs in outbound updates if aspath equals remote-as\n")
5737
5738 /* neighbor remove-private-AS. */
5739 DEFUN (neighbor_remove_private_as,
5740 neighbor_remove_private_as_cmd,
5741 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5742 NEIGHBOR_STR
5743 NEIGHBOR_ADDR_STR2
5744 "Remove private ASNs in outbound updates\n")
5745 {
5746 int idx_peer = 1;
5747 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5748 bgp_node_safi(vty),
5749 PEER_FLAG_REMOVE_PRIVATE_AS);
5750 }
5751
5752 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5753 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5754 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5755 "Remove private ASNs in outbound updates\n")
5756
5757 DEFUN (neighbor_remove_private_as_all,
5758 neighbor_remove_private_as_all_cmd,
5759 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5760 NEIGHBOR_STR
5761 NEIGHBOR_ADDR_STR2
5762 "Remove private ASNs in outbound updates\n"
5763 "Apply to all AS numbers\n")
5764 {
5765 int idx_peer = 1;
5766 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5767 bgp_node_safi(vty),
5768 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5769 }
5770
5771 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5772 neighbor_remove_private_as_all_hidden_cmd,
5773 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5774 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5775 "Remove private ASNs in outbound updates\n"
5776 "Apply to all AS numbers")
5777
5778 DEFUN (neighbor_remove_private_as_replace_as,
5779 neighbor_remove_private_as_replace_as_cmd,
5780 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5781 NEIGHBOR_STR
5782 NEIGHBOR_ADDR_STR2
5783 "Remove private ASNs in outbound updates\n"
5784 "Replace private ASNs with our ASN in outbound updates\n")
5785 {
5786 int idx_peer = 1;
5787 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5788 bgp_node_safi(vty),
5789 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5790 }
5791
5792 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5793 neighbor_remove_private_as_replace_as_hidden_cmd,
5794 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5795 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5796 "Remove private ASNs in outbound updates\n"
5797 "Replace private ASNs with our ASN in outbound updates\n")
5798
5799 DEFUN (neighbor_remove_private_as_all_replace_as,
5800 neighbor_remove_private_as_all_replace_as_cmd,
5801 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5802 NEIGHBOR_STR
5803 NEIGHBOR_ADDR_STR2
5804 "Remove private ASNs in outbound updates\n"
5805 "Apply to all AS numbers\n"
5806 "Replace private ASNs with our ASN in outbound updates\n")
5807 {
5808 int idx_peer = 1;
5809 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5810 bgp_node_safi(vty),
5811 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5812 }
5813
5814 ALIAS_HIDDEN(
5815 neighbor_remove_private_as_all_replace_as,
5816 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5817 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5818 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5819 "Remove private ASNs in outbound updates\n"
5820 "Apply to all AS numbers\n"
5821 "Replace private ASNs with our ASN in outbound updates\n")
5822
5823 DEFUN (no_neighbor_remove_private_as,
5824 no_neighbor_remove_private_as_cmd,
5825 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5826 NO_STR
5827 NEIGHBOR_STR
5828 NEIGHBOR_ADDR_STR2
5829 "Remove private ASNs in outbound updates\n")
5830 {
5831 int idx_peer = 2;
5832 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5833 bgp_node_afi(vty), bgp_node_safi(vty),
5834 PEER_FLAG_REMOVE_PRIVATE_AS);
5835 }
5836
5837 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5838 no_neighbor_remove_private_as_hidden_cmd,
5839 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5840 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5841 "Remove private ASNs in outbound updates\n")
5842
5843 DEFUN (no_neighbor_remove_private_as_all,
5844 no_neighbor_remove_private_as_all_cmd,
5845 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5846 NO_STR
5847 NEIGHBOR_STR
5848 NEIGHBOR_ADDR_STR2
5849 "Remove private ASNs in outbound updates\n"
5850 "Apply to all AS numbers\n")
5851 {
5852 int idx_peer = 2;
5853 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5854 bgp_node_afi(vty), bgp_node_safi(vty),
5855 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5856 }
5857
5858 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5859 no_neighbor_remove_private_as_all_hidden_cmd,
5860 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5861 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5862 "Remove private ASNs in outbound updates\n"
5863 "Apply to all AS numbers\n")
5864
5865 DEFUN (no_neighbor_remove_private_as_replace_as,
5866 no_neighbor_remove_private_as_replace_as_cmd,
5867 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5868 NO_STR
5869 NEIGHBOR_STR
5870 NEIGHBOR_ADDR_STR2
5871 "Remove private ASNs in outbound updates\n"
5872 "Replace private ASNs with our ASN in outbound updates\n")
5873 {
5874 int idx_peer = 2;
5875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5876 bgp_node_afi(vty), bgp_node_safi(vty),
5877 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5878 }
5879
5880 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5881 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5882 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5883 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5884 "Remove private ASNs in outbound updates\n"
5885 "Replace private ASNs with our ASN in outbound updates\n")
5886
5887 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5888 no_neighbor_remove_private_as_all_replace_as_cmd,
5889 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5890 NO_STR
5891 NEIGHBOR_STR
5892 NEIGHBOR_ADDR_STR2
5893 "Remove private ASNs in outbound updates\n"
5894 "Apply to all AS numbers\n"
5895 "Replace private ASNs with our ASN in outbound updates\n")
5896 {
5897 int idx_peer = 2;
5898 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5899 bgp_node_afi(vty), bgp_node_safi(vty),
5900 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5901 }
5902
5903 ALIAS_HIDDEN(
5904 no_neighbor_remove_private_as_all_replace_as,
5905 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5906 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5907 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5908 "Remove private ASNs in outbound updates\n"
5909 "Apply to all AS numbers\n"
5910 "Replace private ASNs with our ASN in outbound updates\n")
5911
5912
5913 /* neighbor send-community. */
5914 DEFUN (neighbor_send_community,
5915 neighbor_send_community_cmd,
5916 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5917 NEIGHBOR_STR
5918 NEIGHBOR_ADDR_STR2
5919 "Send Community attribute to this neighbor\n")
5920 {
5921 int idx_peer = 1;
5922
5923 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5924 bgp_node_safi(vty),
5925 PEER_FLAG_SEND_COMMUNITY);
5926 }
5927
5928 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5929 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5931 "Send Community attribute to this neighbor\n")
5932
5933 DEFUN (no_neighbor_send_community,
5934 no_neighbor_send_community_cmd,
5935 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5936 NO_STR
5937 NEIGHBOR_STR
5938 NEIGHBOR_ADDR_STR2
5939 "Send Community attribute to this neighbor\n")
5940 {
5941 int idx_peer = 2;
5942
5943 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5944 bgp_node_afi(vty), bgp_node_safi(vty),
5945 PEER_FLAG_SEND_COMMUNITY);
5946 }
5947
5948 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5949 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5950 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5951 "Send Community attribute to this neighbor\n")
5952
5953 /* neighbor send-community extended. */
5954 DEFUN (neighbor_send_community_type,
5955 neighbor_send_community_type_cmd,
5956 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5957 NEIGHBOR_STR
5958 NEIGHBOR_ADDR_STR2
5959 "Send Community attribute to this neighbor\n"
5960 "Send Standard and Extended Community attributes\n"
5961 "Send Standard, Large and Extended Community attributes\n"
5962 "Send Extended Community attributes\n"
5963 "Send Standard Community attributes\n"
5964 "Send Large Community attributes\n")
5965 {
5966 const char *type = argv[argc - 1]->text;
5967 char *peer_str = argv[1]->arg;
5968 struct peer *peer;
5969 afi_t afi = bgp_node_afi(vty);
5970 safi_t safi = bgp_node_safi(vty);
5971
5972 peer = peer_and_group_lookup_vty(vty, peer_str);
5973 if (!peer)
5974 return CMD_WARNING_CONFIG_FAILED;
5975
5976 if (strmatch(type, "standard"))
5977 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5978 PEER_FLAG_SEND_COMMUNITY);
5979
5980 if (strmatch(type, "extended"))
5981 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5982 PEER_FLAG_SEND_EXT_COMMUNITY);
5983
5984 if (strmatch(type, "large"))
5985 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5986 PEER_FLAG_SEND_LARGE_COMMUNITY);
5987
5988 if (strmatch(type, "both")) {
5989 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5990 PEER_FLAG_SEND_COMMUNITY)
5991 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5992 PEER_FLAG_SEND_EXT_COMMUNITY);
5993 }
5994 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5995 PEER_FLAG_SEND_COMMUNITY)
5996 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5997 PEER_FLAG_SEND_EXT_COMMUNITY)
5998 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5999 PEER_FLAG_SEND_LARGE_COMMUNITY);
6000 }
6001
6002 ALIAS_HIDDEN(
6003 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6004 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6005 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6006 "Send Community attribute to this neighbor\n"
6007 "Send Standard and Extended Community attributes\n"
6008 "Send Standard, Large and Extended Community attributes\n"
6009 "Send Extended Community attributes\n"
6010 "Send Standard Community attributes\n"
6011 "Send Large Community attributes\n")
6012
6013 DEFUN (no_neighbor_send_community_type,
6014 no_neighbor_send_community_type_cmd,
6015 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6016 NO_STR
6017 NEIGHBOR_STR
6018 NEIGHBOR_ADDR_STR2
6019 "Send Community attribute to this neighbor\n"
6020 "Send Standard and Extended Community attributes\n"
6021 "Send Standard, Large and Extended Community attributes\n"
6022 "Send Extended Community attributes\n"
6023 "Send Standard Community attributes\n"
6024 "Send Large Community attributes\n")
6025 {
6026 const char *type = argv[argc - 1]->text;
6027 char *peer_str = argv[2]->arg;
6028 struct peer *peer;
6029 afi_t afi = bgp_node_afi(vty);
6030 safi_t safi = bgp_node_safi(vty);
6031
6032 peer = peer_and_group_lookup_vty(vty, peer_str);
6033 if (!peer)
6034 return CMD_WARNING_CONFIG_FAILED;
6035
6036 if (strmatch(type, "standard"))
6037 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6038 PEER_FLAG_SEND_COMMUNITY);
6039
6040 if (strmatch(type, "extended"))
6041 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6042 PEER_FLAG_SEND_EXT_COMMUNITY);
6043
6044 if (strmatch(type, "large"))
6045 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6046 PEER_FLAG_SEND_LARGE_COMMUNITY);
6047
6048 if (strmatch(type, "both")) {
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 }
6055
6056 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6057 PEER_FLAG_SEND_COMMUNITY)
6058 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6059 PEER_FLAG_SEND_EXT_COMMUNITY)
6060 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6061 PEER_FLAG_SEND_LARGE_COMMUNITY);
6062 }
6063
6064 ALIAS_HIDDEN(
6065 no_neighbor_send_community_type,
6066 no_neighbor_send_community_type_hidden_cmd,
6067 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6068 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6069 "Send Community attribute to this neighbor\n"
6070 "Send Standard and Extended Community attributes\n"
6071 "Send Standard, Large and Extended Community attributes\n"
6072 "Send Extended Community attributes\n"
6073 "Send Standard Community attributes\n"
6074 "Send Large Community attributes\n")
6075
6076 /* neighbor soft-reconfig. */
6077 DEFUN (neighbor_soft_reconfiguration,
6078 neighbor_soft_reconfiguration_cmd,
6079 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6080 NEIGHBOR_STR
6081 NEIGHBOR_ADDR_STR2
6082 "Per neighbor soft reconfiguration\n"
6083 "Allow inbound soft reconfiguration for this neighbor\n")
6084 {
6085 int idx_peer = 1;
6086 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6087 bgp_node_safi(vty),
6088 PEER_FLAG_SOFT_RECONFIG);
6089 }
6090
6091 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6092 neighbor_soft_reconfiguration_hidden_cmd,
6093 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6094 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6095 "Per neighbor soft reconfiguration\n"
6096 "Allow inbound soft reconfiguration for this neighbor\n")
6097
6098 DEFUN (no_neighbor_soft_reconfiguration,
6099 no_neighbor_soft_reconfiguration_cmd,
6100 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6101 NO_STR
6102 NEIGHBOR_STR
6103 NEIGHBOR_ADDR_STR2
6104 "Per neighbor soft reconfiguration\n"
6105 "Allow inbound soft reconfiguration for this neighbor\n")
6106 {
6107 int idx_peer = 2;
6108 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6109 bgp_node_afi(vty), bgp_node_safi(vty),
6110 PEER_FLAG_SOFT_RECONFIG);
6111 }
6112
6113 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6114 no_neighbor_soft_reconfiguration_hidden_cmd,
6115 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6116 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6117 "Per neighbor soft reconfiguration\n"
6118 "Allow inbound soft reconfiguration for this neighbor\n")
6119
6120 DEFUN (neighbor_route_reflector_client,
6121 neighbor_route_reflector_client_cmd,
6122 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6123 NEIGHBOR_STR
6124 NEIGHBOR_ADDR_STR2
6125 "Configure a neighbor as Route Reflector client\n")
6126 {
6127 int idx_peer = 1;
6128 struct peer *peer;
6129
6130
6131 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6132 if (!peer)
6133 return CMD_WARNING_CONFIG_FAILED;
6134
6135 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6136 bgp_node_safi(vty),
6137 PEER_FLAG_REFLECTOR_CLIENT);
6138 }
6139
6140 ALIAS_HIDDEN(neighbor_route_reflector_client,
6141 neighbor_route_reflector_client_hidden_cmd,
6142 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6143 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6144 "Configure a neighbor as Route Reflector client\n")
6145
6146 DEFUN (no_neighbor_route_reflector_client,
6147 no_neighbor_route_reflector_client_cmd,
6148 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6149 NO_STR
6150 NEIGHBOR_STR
6151 NEIGHBOR_ADDR_STR2
6152 "Configure a neighbor as Route Reflector client\n")
6153 {
6154 int idx_peer = 2;
6155 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6156 bgp_node_afi(vty), bgp_node_safi(vty),
6157 PEER_FLAG_REFLECTOR_CLIENT);
6158 }
6159
6160 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6161 no_neighbor_route_reflector_client_hidden_cmd,
6162 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6163 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6164 "Configure a neighbor as Route Reflector client\n")
6165
6166 /* neighbor route-server-client. */
6167 DEFUN (neighbor_route_server_client,
6168 neighbor_route_server_client_cmd,
6169 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6170 NEIGHBOR_STR
6171 NEIGHBOR_ADDR_STR2
6172 "Configure a neighbor as Route Server client\n")
6173 {
6174 int idx_peer = 1;
6175 struct peer *peer;
6176
6177 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6178 if (!peer)
6179 return CMD_WARNING_CONFIG_FAILED;
6180 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6181 bgp_node_safi(vty),
6182 PEER_FLAG_RSERVER_CLIENT);
6183 }
6184
6185 ALIAS_HIDDEN(neighbor_route_server_client,
6186 neighbor_route_server_client_hidden_cmd,
6187 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6188 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6189 "Configure a neighbor as Route Server client\n")
6190
6191 DEFUN (no_neighbor_route_server_client,
6192 no_neighbor_route_server_client_cmd,
6193 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6194 NO_STR
6195 NEIGHBOR_STR
6196 NEIGHBOR_ADDR_STR2
6197 "Configure a neighbor as Route Server client\n")
6198 {
6199 int idx_peer = 2;
6200 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6201 bgp_node_afi(vty), bgp_node_safi(vty),
6202 PEER_FLAG_RSERVER_CLIENT);
6203 }
6204
6205 ALIAS_HIDDEN(no_neighbor_route_server_client,
6206 no_neighbor_route_server_client_hidden_cmd,
6207 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6208 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6209 "Configure a neighbor as Route Server client\n")
6210
6211 DEFUN (neighbor_nexthop_local_unchanged,
6212 neighbor_nexthop_local_unchanged_cmd,
6213 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6214 NEIGHBOR_STR
6215 NEIGHBOR_ADDR_STR2
6216 "Configure treatment of outgoing link-local nexthop attribute\n"
6217 "Leave link-local nexthop unchanged for this peer\n")
6218 {
6219 int idx_peer = 1;
6220 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6221 bgp_node_safi(vty),
6222 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6223 }
6224
6225 DEFUN (no_neighbor_nexthop_local_unchanged,
6226 no_neighbor_nexthop_local_unchanged_cmd,
6227 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6228 NO_STR
6229 NEIGHBOR_STR
6230 NEIGHBOR_ADDR_STR2
6231 "Configure treatment of outgoing link-local-nexthop attribute\n"
6232 "Leave link-local nexthop unchanged for this peer\n")
6233 {
6234 int idx_peer = 2;
6235 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6236 bgp_node_afi(vty), bgp_node_safi(vty),
6237 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6238 }
6239
6240 DEFUN (neighbor_attr_unchanged,
6241 neighbor_attr_unchanged_cmd,
6242 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6243 NEIGHBOR_STR
6244 NEIGHBOR_ADDR_STR2
6245 "BGP attribute is propagated unchanged to this neighbor\n"
6246 "As-path attribute\n"
6247 "Nexthop attribute\n"
6248 "Med attribute\n")
6249 {
6250 int idx = 0;
6251 char *peer_str = argv[1]->arg;
6252 struct peer *peer;
6253 bool aspath = false;
6254 bool nexthop = false;
6255 bool med = false;
6256 afi_t afi = bgp_node_afi(vty);
6257 safi_t safi = bgp_node_safi(vty);
6258 int ret = 0;
6259
6260 peer = peer_and_group_lookup_vty(vty, peer_str);
6261 if (!peer)
6262 return CMD_WARNING_CONFIG_FAILED;
6263
6264 if (argv_find(argv, argc, "as-path", &idx))
6265 aspath = true;
6266
6267 idx = 0;
6268 if (argv_find(argv, argc, "next-hop", &idx))
6269 nexthop = true;
6270
6271 idx = 0;
6272 if (argv_find(argv, argc, "med", &idx))
6273 med = true;
6274
6275 /* no flags means all of them! */
6276 if (!aspath && !nexthop && !med) {
6277 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6278 PEER_FLAG_AS_PATH_UNCHANGED);
6279 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6280 PEER_FLAG_NEXTHOP_UNCHANGED);
6281 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6282 PEER_FLAG_MED_UNCHANGED);
6283 } else {
6284 if (!aspath) {
6285 if (peer_af_flag_check(peer, afi, safi,
6286 PEER_FLAG_AS_PATH_UNCHANGED)) {
6287 ret |= peer_af_flag_unset_vty(
6288 vty, peer_str, afi, safi,
6289 PEER_FLAG_AS_PATH_UNCHANGED);
6290 }
6291 } else
6292 ret |= peer_af_flag_set_vty(
6293 vty, peer_str, afi, safi,
6294 PEER_FLAG_AS_PATH_UNCHANGED);
6295
6296 if (!nexthop) {
6297 if (peer_af_flag_check(peer, afi, safi,
6298 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6299 ret |= peer_af_flag_unset_vty(
6300 vty, peer_str, afi, safi,
6301 PEER_FLAG_NEXTHOP_UNCHANGED);
6302 }
6303 } else
6304 ret |= peer_af_flag_set_vty(
6305 vty, peer_str, afi, safi,
6306 PEER_FLAG_NEXTHOP_UNCHANGED);
6307
6308 if (!med) {
6309 if (peer_af_flag_check(peer, afi, safi,
6310 PEER_FLAG_MED_UNCHANGED)) {
6311 ret |= peer_af_flag_unset_vty(
6312 vty, peer_str, afi, safi,
6313 PEER_FLAG_MED_UNCHANGED);
6314 }
6315 } else
6316 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6317 PEER_FLAG_MED_UNCHANGED);
6318 }
6319
6320 return ret;
6321 }
6322
6323 ALIAS_HIDDEN(
6324 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6325 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6327 "BGP attribute is propagated unchanged to this neighbor\n"
6328 "As-path attribute\n"
6329 "Nexthop attribute\n"
6330 "Med attribute\n")
6331
6332 DEFUN (no_neighbor_attr_unchanged,
6333 no_neighbor_attr_unchanged_cmd,
6334 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6335 NO_STR
6336 NEIGHBOR_STR
6337 NEIGHBOR_ADDR_STR2
6338 "BGP attribute is propagated unchanged to this neighbor\n"
6339 "As-path attribute\n"
6340 "Nexthop attribute\n"
6341 "Med attribute\n")
6342 {
6343 int idx = 0;
6344 char *peer_str = argv[2]->arg;
6345 struct peer *peer;
6346 bool aspath = false;
6347 bool nexthop = false;
6348 bool med = false;
6349 afi_t afi = bgp_node_afi(vty);
6350 safi_t safi = bgp_node_safi(vty);
6351 int ret = 0;
6352
6353 peer = peer_and_group_lookup_vty(vty, peer_str);
6354 if (!peer)
6355 return CMD_WARNING_CONFIG_FAILED;
6356
6357 if (argv_find(argv, argc, "as-path", &idx))
6358 aspath = true;
6359
6360 idx = 0;
6361 if (argv_find(argv, argc, "next-hop", &idx))
6362 nexthop = true;
6363
6364 idx = 0;
6365 if (argv_find(argv, argc, "med", &idx))
6366 med = true;
6367
6368 if (!aspath && !nexthop && !med) // no flags means all of them!
6369 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6370 PEER_FLAG_AS_PATH_UNCHANGED)
6371 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6372 PEER_FLAG_NEXTHOP_UNCHANGED)
6373 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6374 PEER_FLAG_MED_UNCHANGED);
6375
6376 if (aspath)
6377 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6378 PEER_FLAG_AS_PATH_UNCHANGED);
6379
6380 if (nexthop)
6381 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6382 PEER_FLAG_NEXTHOP_UNCHANGED);
6383
6384 if (med)
6385 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6386 PEER_FLAG_MED_UNCHANGED);
6387
6388 return ret;
6389 }
6390
6391 ALIAS_HIDDEN(
6392 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6393 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6394 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6395 "BGP attribute is propagated unchanged to this neighbor\n"
6396 "As-path attribute\n"
6397 "Nexthop attribute\n"
6398 "Med attribute\n")
6399
6400 /* EBGP multihop configuration. */
6401 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6402 const char *ttl_str)
6403 {
6404 struct peer *peer;
6405 unsigned int ttl;
6406
6407 peer = peer_and_group_lookup_vty(vty, ip_str);
6408 if (!peer)
6409 return CMD_WARNING_CONFIG_FAILED;
6410
6411 if (peer->conf_if)
6412 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6413
6414 if (!ttl_str)
6415 ttl = MAXTTL;
6416 else
6417 ttl = strtoul(ttl_str, NULL, 10);
6418
6419 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6420 }
6421
6422 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6423 {
6424 struct peer *peer;
6425
6426 peer = peer_and_group_lookup_vty(vty, ip_str);
6427 if (!peer)
6428 return CMD_WARNING_CONFIG_FAILED;
6429
6430 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6431 }
6432
6433 /* neighbor ebgp-multihop. */
6434 DEFUN (neighbor_ebgp_multihop,
6435 neighbor_ebgp_multihop_cmd,
6436 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6437 NEIGHBOR_STR
6438 NEIGHBOR_ADDR_STR2
6439 "Allow EBGP neighbors not on directly connected networks\n")
6440 {
6441 int idx_peer = 1;
6442 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6443 }
6444
6445 DEFUN (neighbor_ebgp_multihop_ttl,
6446 neighbor_ebgp_multihop_ttl_cmd,
6447 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6448 NEIGHBOR_STR
6449 NEIGHBOR_ADDR_STR2
6450 "Allow EBGP neighbors not on directly connected networks\n"
6451 "maximum hop count\n")
6452 {
6453 int idx_peer = 1;
6454 int idx_number = 3;
6455 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6456 argv[idx_number]->arg);
6457 }
6458
6459 DEFUN (no_neighbor_ebgp_multihop,
6460 no_neighbor_ebgp_multihop_cmd,
6461 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6462 NO_STR
6463 NEIGHBOR_STR
6464 NEIGHBOR_ADDR_STR2
6465 "Allow EBGP neighbors not on directly connected networks\n"
6466 "maximum hop count\n")
6467 {
6468 int idx_peer = 2;
6469 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6470 }
6471
6472 static uint8_t get_role_by_name(const char *role_str)
6473 {
6474 if (strncmp(role_str, "peer", 2) == 0)
6475 return ROLE_PEER;
6476 if (strncmp(role_str, "provider", 2) == 0)
6477 return ROLE_PROVIDER;
6478 if (strncmp(role_str, "customer", 2) == 0)
6479 return ROLE_CUSTOMER;
6480 if (strncmp(role_str, "rs-server", 4) == 0)
6481 return ROLE_RS_SERVER;
6482 if (strncmp(role_str, "rs-client", 4) == 0)
6483 return ROLE_RS_CLIENT;
6484 return ROLE_UNDEFINED;
6485 }
6486
6487 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6488 const char *role_str, bool strict_mode)
6489 {
6490 struct peer *peer;
6491
6492 peer = peer_and_group_lookup_vty(vty, ip_str);
6493 if (!peer)
6494 return CMD_WARNING_CONFIG_FAILED;
6495 uint8_t role = get_role_by_name(role_str);
6496
6497 if (role == ROLE_UNDEFINED)
6498 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6499 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6500 }
6501
6502 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6503 {
6504 struct peer *peer;
6505
6506 peer = peer_and_group_lookup_vty(vty, ip_str);
6507 if (!peer)
6508 return CMD_WARNING_CONFIG_FAILED;
6509 return bgp_vty_return(vty, peer_role_unset(peer));
6510 }
6511
6512 DEFPY(neighbor_role,
6513 neighbor_role_cmd,
6514 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6515 NEIGHBOR_STR
6516 NEIGHBOR_ADDR_STR2
6517 "Set session role\n"
6518 ROLE_STR)
6519 {
6520 int idx_peer = 1;
6521 int idx_role = 3;
6522
6523 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6524 false);
6525 }
6526
6527 DEFPY(neighbor_role_strict,
6528 neighbor_role_strict_cmd,
6529 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6530 NEIGHBOR_STR
6531 NEIGHBOR_ADDR_STR2
6532 "Set session role\n"
6533 ROLE_STR
6534 "Use additional restriction on peer\n")
6535 {
6536 int idx_peer = 1;
6537 int idx_role = 3;
6538
6539 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6540 true);
6541 }
6542
6543 DEFPY(no_neighbor_role,
6544 no_neighbor_role_cmd,
6545 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6546 NO_STR
6547 NEIGHBOR_STR
6548 NEIGHBOR_ADDR_STR2
6549 "Set session role\n"
6550 ROLE_STR
6551 "Use additional restriction on peer\n")
6552 {
6553 int idx_peer = 2;
6554
6555 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6556 }
6557
6558 /* disable-connected-check */
6559 DEFUN (neighbor_disable_connected_check,
6560 neighbor_disable_connected_check_cmd,
6561 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6562 NEIGHBOR_STR
6563 NEIGHBOR_ADDR_STR2
6564 "one-hop away EBGP peer using loopback address\n"
6565 "Enforce EBGP neighbors perform multihop\n")
6566 {
6567 int idx_peer = 1;
6568 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6569 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6570 }
6571
6572 DEFUN (no_neighbor_disable_connected_check,
6573 no_neighbor_disable_connected_check_cmd,
6574 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6575 NO_STR
6576 NEIGHBOR_STR
6577 NEIGHBOR_ADDR_STR2
6578 "one-hop away EBGP peer using loopback address\n"
6579 "Enforce EBGP neighbors perform multihop\n")
6580 {
6581 int idx_peer = 2;
6582 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6583 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6584 }
6585
6586 /* disable-link-bw-encoding-ieee */
6587 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6588 neighbor_disable_link_bw_encoding_ieee_cmd,
6589 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6590 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6591 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6592 {
6593 int idx_peer = 1;
6594
6595 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6596 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6597 }
6598
6599 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6600 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6601 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6602 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6603 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6604 {
6605 int idx_peer = 2;
6606
6607 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6608 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6609 }
6610
6611 /* extended-optional-parameters */
6612 DEFUN(neighbor_extended_optional_parameters,
6613 neighbor_extended_optional_parameters_cmd,
6614 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6615 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6616 "Force the extended optional parameters format for OPEN messages\n")
6617 {
6618 int idx_peer = 1;
6619
6620 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6621 PEER_FLAG_EXTENDED_OPT_PARAMS);
6622 }
6623
6624 DEFUN(no_neighbor_extended_optional_parameters,
6625 no_neighbor_extended_optional_parameters_cmd,
6626 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6627 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6628 "Force the extended optional parameters format for OPEN messages\n")
6629 {
6630 int idx_peer = 2;
6631
6632 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6633 PEER_FLAG_EXTENDED_OPT_PARAMS);
6634 }
6635
6636 /* enforce-first-as */
6637 DEFUN (neighbor_enforce_first_as,
6638 neighbor_enforce_first_as_cmd,
6639 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6640 NEIGHBOR_STR
6641 NEIGHBOR_ADDR_STR2
6642 "Enforce the first AS for EBGP routes\n")
6643 {
6644 int idx_peer = 1;
6645
6646 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6647 PEER_FLAG_ENFORCE_FIRST_AS);
6648 }
6649
6650 DEFUN (no_neighbor_enforce_first_as,
6651 no_neighbor_enforce_first_as_cmd,
6652 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6653 NO_STR
6654 NEIGHBOR_STR
6655 NEIGHBOR_ADDR_STR2
6656 "Enforce the first AS for EBGP routes\n")
6657 {
6658 int idx_peer = 2;
6659
6660 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6661 PEER_FLAG_ENFORCE_FIRST_AS);
6662 }
6663
6664
6665 DEFUN (neighbor_description,
6666 neighbor_description_cmd,
6667 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6668 NEIGHBOR_STR
6669 NEIGHBOR_ADDR_STR2
6670 "Neighbor specific description\n"
6671 "Up to 80 characters describing this neighbor\n")
6672 {
6673 int idx_peer = 1;
6674 int idx_line = 3;
6675 struct peer *peer;
6676 char *str;
6677
6678 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6679 if (!peer)
6680 return CMD_WARNING_CONFIG_FAILED;
6681
6682 str = argv_concat(argv, argc, idx_line);
6683
6684 peer_description_set(peer, str);
6685
6686 XFREE(MTYPE_TMP, str);
6687
6688 return CMD_SUCCESS;
6689 }
6690
6691 DEFUN (no_neighbor_description,
6692 no_neighbor_description_cmd,
6693 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6694 NO_STR
6695 NEIGHBOR_STR
6696 NEIGHBOR_ADDR_STR2
6697 "Neighbor specific description\n")
6698 {
6699 int idx_peer = 2;
6700 struct peer *peer;
6701
6702 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6703 if (!peer)
6704 return CMD_WARNING_CONFIG_FAILED;
6705
6706 peer_description_unset(peer);
6707
6708 return CMD_SUCCESS;
6709 }
6710
6711 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6712 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6713 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6714 "Neighbor specific description\n"
6715 "Up to 80 characters describing this neighbor\n")
6716
6717 /* Neighbor update-source. */
6718 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6719 const char *source_str)
6720 {
6721 struct peer *peer;
6722 struct prefix p;
6723 union sockunion su;
6724
6725 peer = peer_and_group_lookup_vty(vty, peer_str);
6726 if (!peer)
6727 return CMD_WARNING_CONFIG_FAILED;
6728
6729 if (peer->conf_if)
6730 return CMD_WARNING;
6731
6732 if (source_str) {
6733 if (str2sockunion(source_str, &su) == 0)
6734 peer_update_source_addr_set(peer, &su);
6735 else {
6736 if (str2prefix(source_str, &p)) {
6737 vty_out(vty,
6738 "%% Invalid update-source, remove prefix length \n");
6739 return CMD_WARNING_CONFIG_FAILED;
6740 } else
6741 peer_update_source_if_set(peer, source_str);
6742 }
6743 } else
6744 peer_update_source_unset(peer);
6745
6746 return CMD_SUCCESS;
6747 }
6748
6749 #define BGP_UPDATE_SOURCE_HELP_STR \
6750 "IPv4 address\n" \
6751 "IPv6 address\n" \
6752 "Interface name (requires zebra to be running)\n"
6753
6754 DEFUN (neighbor_update_source,
6755 neighbor_update_source_cmd,
6756 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6757 NEIGHBOR_STR
6758 NEIGHBOR_ADDR_STR2
6759 "Source of routing updates\n"
6760 BGP_UPDATE_SOURCE_HELP_STR)
6761 {
6762 int idx_peer = 1;
6763 int idx_peer_2 = 3;
6764 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6765 argv[idx_peer_2]->arg);
6766 }
6767
6768 DEFUN (no_neighbor_update_source,
6769 no_neighbor_update_source_cmd,
6770 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6771 NO_STR
6772 NEIGHBOR_STR
6773 NEIGHBOR_ADDR_STR2
6774 "Source of routing updates\n"
6775 BGP_UPDATE_SOURCE_HELP_STR)
6776 {
6777 int idx_peer = 2;
6778 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6779 }
6780
6781 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6782 afi_t afi, safi_t safi,
6783 const char *rmap, int set)
6784 {
6785 int ret;
6786 struct peer *peer;
6787 struct route_map *route_map = NULL;
6788
6789 peer = peer_and_group_lookup_vty(vty, peer_str);
6790 if (!peer)
6791 return CMD_WARNING_CONFIG_FAILED;
6792
6793 if (set) {
6794 if (rmap)
6795 route_map = route_map_lookup_warn_noexist(vty, rmap);
6796 ret = peer_default_originate_set(peer, afi, safi,
6797 rmap, route_map);
6798 } else
6799 ret = peer_default_originate_unset(peer, afi, safi);
6800
6801 return bgp_vty_return(vty, ret);
6802 }
6803
6804 /* neighbor default-originate. */
6805 DEFUN (neighbor_default_originate,
6806 neighbor_default_originate_cmd,
6807 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6808 NEIGHBOR_STR
6809 NEIGHBOR_ADDR_STR2
6810 "Originate default route to this neighbor\n")
6811 {
6812 int idx_peer = 1;
6813 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6814 bgp_node_afi(vty),
6815 bgp_node_safi(vty), NULL, 1);
6816 }
6817
6818 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6819 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6820 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6821 "Originate default route to this neighbor\n")
6822
6823 DEFUN (neighbor_default_originate_rmap,
6824 neighbor_default_originate_rmap_cmd,
6825 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6826 NEIGHBOR_STR
6827 NEIGHBOR_ADDR_STR2
6828 "Originate default route to this neighbor\n"
6829 "Route-map to specify criteria to originate default\n"
6830 "route-map name\n")
6831 {
6832 int idx_peer = 1;
6833 int idx_word = 4;
6834 return peer_default_originate_set_vty(
6835 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6836 argv[idx_word]->arg, 1);
6837 }
6838
6839 ALIAS_HIDDEN(
6840 neighbor_default_originate_rmap,
6841 neighbor_default_originate_rmap_hidden_cmd,
6842 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6843 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6844 "Originate default route to this neighbor\n"
6845 "Route-map to specify criteria to originate default\n"
6846 "route-map name\n")
6847
6848 DEFUN (no_neighbor_default_originate,
6849 no_neighbor_default_originate_cmd,
6850 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6851 NO_STR
6852 NEIGHBOR_STR
6853 NEIGHBOR_ADDR_STR2
6854 "Originate default route to this neighbor\n"
6855 "Route-map to specify criteria to originate default\n"
6856 "route-map name\n")
6857 {
6858 int idx_peer = 2;
6859 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6860 bgp_node_afi(vty),
6861 bgp_node_safi(vty), NULL, 0);
6862 }
6863
6864 ALIAS_HIDDEN(
6865 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6866 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6867 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6868 "Originate default route to this neighbor\n"
6869 "Route-map to specify criteria to originate default\n"
6870 "route-map name\n")
6871
6872
6873 /* Set neighbor's BGP port. */
6874 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6875 const char *port_str)
6876 {
6877 struct peer *peer;
6878 uint16_t port;
6879 struct servent *sp;
6880
6881 peer = peer_and_group_lookup_vty(vty, ip_str);
6882 if (!peer)
6883 return CMD_WARNING_CONFIG_FAILED;
6884
6885 if (!port_str) {
6886 sp = getservbyname("bgp", "tcp");
6887 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6888 } else {
6889 port = strtoul(port_str, NULL, 10);
6890 }
6891
6892 peer_port_set(peer, port);
6893
6894 return CMD_SUCCESS;
6895 }
6896
6897 /* Set specified peer's BGP port. */
6898 DEFUN (neighbor_port,
6899 neighbor_port_cmd,
6900 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6901 NEIGHBOR_STR
6902 NEIGHBOR_ADDR_STR2
6903 "Neighbor's BGP port\n"
6904 "TCP port number\n")
6905 {
6906 int idx_ip = 1;
6907 int idx_number = 3;
6908 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6909 argv[idx_number]->arg);
6910 }
6911
6912 DEFUN (no_neighbor_port,
6913 no_neighbor_port_cmd,
6914 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6915 NO_STR
6916 NEIGHBOR_STR
6917 NEIGHBOR_ADDR_STR2
6918 "Neighbor's BGP port\n"
6919 "TCP port number\n")
6920 {
6921 int idx_ip = 2;
6922 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6923 }
6924
6925
6926 /* neighbor weight. */
6927 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6928 safi_t safi, const char *weight_str)
6929 {
6930 int ret;
6931 struct peer *peer;
6932 unsigned long weight;
6933
6934 peer = peer_and_group_lookup_vty(vty, ip_str);
6935 if (!peer)
6936 return CMD_WARNING_CONFIG_FAILED;
6937
6938 weight = strtoul(weight_str, NULL, 10);
6939
6940 ret = peer_weight_set(peer, afi, safi, weight);
6941 return bgp_vty_return(vty, ret);
6942 }
6943
6944 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6945 safi_t safi)
6946 {
6947 int ret;
6948 struct peer *peer;
6949
6950 peer = peer_and_group_lookup_vty(vty, ip_str);
6951 if (!peer)
6952 return CMD_WARNING_CONFIG_FAILED;
6953
6954 ret = peer_weight_unset(peer, afi, safi);
6955 return bgp_vty_return(vty, ret);
6956 }
6957
6958 DEFUN (neighbor_weight,
6959 neighbor_weight_cmd,
6960 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6961 NEIGHBOR_STR
6962 NEIGHBOR_ADDR_STR2
6963 "Set default weight for routes from this neighbor\n"
6964 "default weight\n")
6965 {
6966 int idx_peer = 1;
6967 int idx_number = 3;
6968 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6969 bgp_node_safi(vty), argv[idx_number]->arg);
6970 }
6971
6972 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6973 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6975 "Set default weight for routes from this neighbor\n"
6976 "default weight\n")
6977
6978 DEFUN (no_neighbor_weight,
6979 no_neighbor_weight_cmd,
6980 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6981 NO_STR
6982 NEIGHBOR_STR
6983 NEIGHBOR_ADDR_STR2
6984 "Set default weight for routes from this neighbor\n"
6985 "default weight\n")
6986 {
6987 int idx_peer = 2;
6988 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6989 bgp_node_afi(vty), bgp_node_safi(vty));
6990 }
6991
6992 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6993 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6994 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6995 "Set default weight for routes from this neighbor\n"
6996 "default weight\n")
6997
6998
6999 /* Override capability negotiation. */
7000 DEFUN (neighbor_override_capability,
7001 neighbor_override_capability_cmd,
7002 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7003 NEIGHBOR_STR
7004 NEIGHBOR_ADDR_STR2
7005 "Override capability negotiation result\n")
7006 {
7007 int idx_peer = 1;
7008 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7009 PEER_FLAG_OVERRIDE_CAPABILITY);
7010 }
7011
7012 DEFUN (no_neighbor_override_capability,
7013 no_neighbor_override_capability_cmd,
7014 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7015 NO_STR
7016 NEIGHBOR_STR
7017 NEIGHBOR_ADDR_STR2
7018 "Override capability negotiation result\n")
7019 {
7020 int idx_peer = 2;
7021 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7022 PEER_FLAG_OVERRIDE_CAPABILITY);
7023 }
7024
7025 DEFUN (neighbor_strict_capability,
7026 neighbor_strict_capability_cmd,
7027 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7028 NEIGHBOR_STR
7029 NEIGHBOR_ADDR_STR2
7030 "Strict capability negotiation match\n")
7031 {
7032 int idx_peer = 1;
7033
7034 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7035 PEER_FLAG_STRICT_CAP_MATCH);
7036 }
7037
7038 DEFUN (no_neighbor_strict_capability,
7039 no_neighbor_strict_capability_cmd,
7040 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7041 NO_STR
7042 NEIGHBOR_STR
7043 NEIGHBOR_ADDR_STR2
7044 "Strict capability negotiation match\n")
7045 {
7046 int idx_peer = 2;
7047
7048 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7049 PEER_FLAG_STRICT_CAP_MATCH);
7050 }
7051
7052 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7053 const char *keep_str, const char *hold_str)
7054 {
7055 int ret;
7056 struct peer *peer;
7057 uint32_t keepalive;
7058 uint32_t holdtime;
7059
7060 peer = peer_and_group_lookup_vty(vty, ip_str);
7061 if (!peer)
7062 return CMD_WARNING_CONFIG_FAILED;
7063
7064 keepalive = strtoul(keep_str, NULL, 10);
7065 holdtime = strtoul(hold_str, NULL, 10);
7066
7067 ret = peer_timers_set(peer, keepalive, holdtime);
7068
7069 return bgp_vty_return(vty, ret);
7070 }
7071
7072 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7073 {
7074 int ret;
7075 struct peer *peer;
7076
7077 peer = peer_and_group_lookup_vty(vty, ip_str);
7078 if (!peer)
7079 return CMD_WARNING_CONFIG_FAILED;
7080
7081 ret = peer_timers_unset(peer);
7082
7083 return bgp_vty_return(vty, ret);
7084 }
7085
7086 DEFUN (neighbor_timers,
7087 neighbor_timers_cmd,
7088 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7089 NEIGHBOR_STR
7090 NEIGHBOR_ADDR_STR2
7091 "BGP per neighbor timers\n"
7092 "Keepalive interval\n"
7093 "Holdtime\n")
7094 {
7095 int idx_peer = 1;
7096 int idx_number = 3;
7097 int idx_number_2 = 4;
7098 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7099 argv[idx_number]->arg,
7100 argv[idx_number_2]->arg);
7101 }
7102
7103 DEFUN (no_neighbor_timers,
7104 no_neighbor_timers_cmd,
7105 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7106 NO_STR
7107 NEIGHBOR_STR
7108 NEIGHBOR_ADDR_STR2
7109 "BGP per neighbor timers\n"
7110 "Keepalive interval\n"
7111 "Holdtime\n")
7112 {
7113 int idx_peer = 2;
7114 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7115 }
7116
7117
7118 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7119 const char *time_str)
7120 {
7121 int ret;
7122 struct peer *peer;
7123 uint32_t connect;
7124
7125 peer = peer_and_group_lookup_vty(vty, ip_str);
7126 if (!peer)
7127 return CMD_WARNING_CONFIG_FAILED;
7128
7129 connect = strtoul(time_str, NULL, 10);
7130
7131 ret = peer_timers_connect_set(peer, connect);
7132
7133 return bgp_vty_return(vty, ret);
7134 }
7135
7136 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7137 {
7138 int ret;
7139 struct peer *peer;
7140
7141 peer = peer_and_group_lookup_vty(vty, ip_str);
7142 if (!peer)
7143 return CMD_WARNING_CONFIG_FAILED;
7144
7145 ret = peer_timers_connect_unset(peer);
7146
7147 return bgp_vty_return(vty, ret);
7148 }
7149
7150 DEFUN (neighbor_timers_connect,
7151 neighbor_timers_connect_cmd,
7152 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7153 NEIGHBOR_STR
7154 NEIGHBOR_ADDR_STR2
7155 "BGP per neighbor timers\n"
7156 "BGP connect timer\n"
7157 "Connect timer\n")
7158 {
7159 int idx_peer = 1;
7160 int idx_number = 4;
7161 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7162 argv[idx_number]->arg);
7163 }
7164
7165 DEFUN (no_neighbor_timers_connect,
7166 no_neighbor_timers_connect_cmd,
7167 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7168 NO_STR
7169 NEIGHBOR_STR
7170 NEIGHBOR_ADDR_STR2
7171 "BGP per neighbor timers\n"
7172 "BGP connect timer\n"
7173 "Connect timer\n")
7174 {
7175 int idx_peer = 2;
7176 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7177 }
7178
7179 DEFPY (neighbor_timers_delayopen,
7180 neighbor_timers_delayopen_cmd,
7181 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7182 NEIGHBOR_STR
7183 NEIGHBOR_ADDR_STR2
7184 "BGP per neighbor timers\n"
7185 "RFC 4271 DelayOpenTimer\n"
7186 "DelayOpenTime timer interval\n")
7187 {
7188 struct peer *peer;
7189
7190 peer = peer_and_group_lookup_vty(vty, neighbor);
7191 if (!peer)
7192 return CMD_WARNING_CONFIG_FAILED;
7193
7194 if (!interval) {
7195 if (peer_timers_delayopen_unset(peer))
7196 return CMD_WARNING_CONFIG_FAILED;
7197 } else {
7198 if (peer_timers_delayopen_set(peer, interval))
7199 return CMD_WARNING_CONFIG_FAILED;
7200 }
7201
7202 return CMD_SUCCESS;
7203 }
7204
7205 DEFPY (no_neighbor_timers_delayopen,
7206 no_neighbor_timers_delayopen_cmd,
7207 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7208 NO_STR
7209 NEIGHBOR_STR
7210 NEIGHBOR_ADDR_STR2
7211 "BGP per neighbor timers\n"
7212 "RFC 4271 DelayOpenTimer\n"
7213 "DelayOpenTime timer interval\n")
7214 {
7215 struct peer *peer;
7216
7217 peer = peer_and_group_lookup_vty(vty, neighbor);
7218 if (!peer)
7219 return CMD_WARNING_CONFIG_FAILED;
7220
7221 if (peer_timers_delayopen_unset(peer))
7222 return CMD_WARNING_CONFIG_FAILED;
7223
7224 return CMD_SUCCESS;
7225 }
7226
7227 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7228 const char *time_str, int set)
7229 {
7230 int ret;
7231 struct peer *peer;
7232 uint32_t routeadv = 0;
7233
7234 peer = peer_and_group_lookup_vty(vty, ip_str);
7235 if (!peer)
7236 return CMD_WARNING_CONFIG_FAILED;
7237
7238 if (time_str)
7239 routeadv = strtoul(time_str, NULL, 10);
7240
7241 if (set)
7242 ret = peer_advertise_interval_set(peer, routeadv);
7243 else
7244 ret = peer_advertise_interval_unset(peer);
7245
7246 return bgp_vty_return(vty, ret);
7247 }
7248
7249 DEFUN (neighbor_advertise_interval,
7250 neighbor_advertise_interval_cmd,
7251 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7252 NEIGHBOR_STR
7253 NEIGHBOR_ADDR_STR2
7254 "Minimum interval between sending BGP routing updates\n"
7255 "time in seconds\n")
7256 {
7257 int idx_peer = 1;
7258 int idx_number = 3;
7259 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7260 argv[idx_number]->arg, 1);
7261 }
7262
7263 DEFUN (no_neighbor_advertise_interval,
7264 no_neighbor_advertise_interval_cmd,
7265 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7266 NO_STR
7267 NEIGHBOR_STR
7268 NEIGHBOR_ADDR_STR2
7269 "Minimum interval between sending BGP routing updates\n"
7270 "time in seconds\n")
7271 {
7272 int idx_peer = 2;
7273 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7274 }
7275
7276
7277 /* Time to wait before processing route-map updates */
7278 DEFUN (bgp_set_route_map_delay_timer,
7279 bgp_set_route_map_delay_timer_cmd,
7280 "bgp route-map delay-timer (0-600)",
7281 SET_STR
7282 "BGP route-map delay timer\n"
7283 "Time in secs to wait before processing route-map changes\n"
7284 "0 disables the timer, no route updates happen when route-maps change\n")
7285 {
7286 int idx_number = 3;
7287 uint32_t rmap_delay_timer;
7288
7289 if (argv[idx_number]->arg) {
7290 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7291 bm->rmap_update_timer = rmap_delay_timer;
7292
7293 /* if the dynamic update handling is being disabled, and a timer
7294 * is
7295 * running, stop the timer and act as if the timer has already
7296 * fired.
7297 */
7298 if (!rmap_delay_timer && bm->t_rmap_update) {
7299 THREAD_OFF(bm->t_rmap_update);
7300 thread_execute(bm->master, bgp_route_map_update_timer,
7301 NULL, 0);
7302 }
7303 return CMD_SUCCESS;
7304 } else {
7305 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7306 return CMD_WARNING_CONFIG_FAILED;
7307 }
7308 }
7309
7310 DEFUN (no_bgp_set_route_map_delay_timer,
7311 no_bgp_set_route_map_delay_timer_cmd,
7312 "no bgp route-map delay-timer [(0-600)]",
7313 NO_STR
7314 BGP_STR
7315 "Default BGP route-map delay timer\n"
7316 "Reset to default time to wait for processing route-map changes\n"
7317 "0 disables the timer, no route updates happen when route-maps change\n")
7318 {
7319
7320 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7321
7322 return CMD_SUCCESS;
7323 }
7324
7325 /* neighbor interface */
7326 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7327 const char *str)
7328 {
7329 struct peer *peer;
7330
7331 peer = peer_lookup_vty(vty, ip_str);
7332 if (!peer || peer->conf_if) {
7333 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7334 return CMD_WARNING_CONFIG_FAILED;
7335 }
7336
7337 if (str)
7338 peer_interface_set(peer, str);
7339 else
7340 peer_interface_unset(peer);
7341
7342 return CMD_SUCCESS;
7343 }
7344
7345 DEFUN (neighbor_interface,
7346 neighbor_interface_cmd,
7347 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7348 NEIGHBOR_STR
7349 NEIGHBOR_ADDR_STR
7350 "Interface\n"
7351 "Interface name\n")
7352 {
7353 int idx_ip = 1;
7354 int idx_word = 3;
7355
7356 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7357 }
7358
7359 DEFUN (no_neighbor_interface,
7360 no_neighbor_interface_cmd,
7361 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7362 NO_STR
7363 NEIGHBOR_STR
7364 NEIGHBOR_ADDR_STR
7365 "Interface\n"
7366 "Interface name\n")
7367 {
7368 int idx_peer = 2;
7369
7370 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7371 }
7372
7373 DEFUN (neighbor_distribute_list,
7374 neighbor_distribute_list_cmd,
7375 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7376 NEIGHBOR_STR
7377 NEIGHBOR_ADDR_STR2
7378 "Filter updates to/from this neighbor\n"
7379 "IP Access-list name\n"
7380 "Filter incoming updates\n"
7381 "Filter outgoing updates\n")
7382 {
7383 int idx_peer = 1;
7384 int idx_acl = 3;
7385 int direct, ret;
7386 struct peer *peer;
7387
7388 const char *pstr = argv[idx_peer]->arg;
7389 const char *acl = argv[idx_acl]->arg;
7390 const char *inout = argv[argc - 1]->text;
7391
7392 peer = peer_and_group_lookup_vty(vty, pstr);
7393 if (!peer)
7394 return CMD_WARNING_CONFIG_FAILED;
7395
7396 /* Check filter direction. */
7397 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7398 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7399 direct, acl);
7400
7401 return bgp_vty_return(vty, ret);
7402 }
7403
7404 ALIAS_HIDDEN(
7405 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7406 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7407 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7408 "Filter updates to/from this neighbor\n"
7409 "IP Access-list name\n"
7410 "Filter incoming updates\n"
7411 "Filter outgoing updates\n")
7412
7413 DEFUN (no_neighbor_distribute_list,
7414 no_neighbor_distribute_list_cmd,
7415 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7416 NO_STR
7417 NEIGHBOR_STR
7418 NEIGHBOR_ADDR_STR2
7419 "Filter updates to/from this neighbor\n"
7420 "IP Access-list name\n"
7421 "Filter incoming updates\n"
7422 "Filter outgoing updates\n")
7423 {
7424 int idx_peer = 2;
7425 int direct, ret;
7426 struct peer *peer;
7427
7428 const char *pstr = argv[idx_peer]->arg;
7429 const char *inout = argv[argc - 1]->text;
7430
7431 peer = peer_and_group_lookup_vty(vty, pstr);
7432 if (!peer)
7433 return CMD_WARNING_CONFIG_FAILED;
7434
7435 /* Check filter direction. */
7436 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7437 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7438 direct);
7439
7440 return bgp_vty_return(vty, ret);
7441 }
7442
7443 ALIAS_HIDDEN(
7444 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7445 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7446 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7447 "Filter updates to/from this neighbor\n"
7448 "IP Access-list name\n"
7449 "Filter incoming updates\n"
7450 "Filter outgoing updates\n")
7451
7452 /* Set prefix list to the peer. */
7453 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7454 afi_t afi, safi_t safi,
7455 const char *name_str,
7456 const char *direct_str)
7457 {
7458 int ret;
7459 int direct = FILTER_IN;
7460 struct peer *peer;
7461
7462 peer = peer_and_group_lookup_vty(vty, ip_str);
7463 if (!peer)
7464 return CMD_WARNING_CONFIG_FAILED;
7465
7466 /* Check filter direction. */
7467 if (strncmp(direct_str, "i", 1) == 0)
7468 direct = FILTER_IN;
7469 else if (strncmp(direct_str, "o", 1) == 0)
7470 direct = FILTER_OUT;
7471
7472 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7473
7474 return bgp_vty_return(vty, ret);
7475 }
7476
7477 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7478 afi_t afi, safi_t safi,
7479 const char *direct_str)
7480 {
7481 int ret;
7482 struct peer *peer;
7483 int direct = FILTER_IN;
7484
7485 peer = peer_and_group_lookup_vty(vty, ip_str);
7486 if (!peer)
7487 return CMD_WARNING_CONFIG_FAILED;
7488
7489 /* Check filter direction. */
7490 if (strncmp(direct_str, "i", 1) == 0)
7491 direct = FILTER_IN;
7492 else if (strncmp(direct_str, "o", 1) == 0)
7493 direct = FILTER_OUT;
7494
7495 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7496
7497 return bgp_vty_return(vty, ret);
7498 }
7499
7500 DEFUN (neighbor_prefix_list,
7501 neighbor_prefix_list_cmd,
7502 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7503 NEIGHBOR_STR
7504 NEIGHBOR_ADDR_STR2
7505 "Filter updates to/from this neighbor\n"
7506 "Name of a prefix list\n"
7507 "Filter incoming updates\n"
7508 "Filter outgoing updates\n")
7509 {
7510 int idx_peer = 1;
7511 int idx_word = 3;
7512 int idx_in_out = 4;
7513 return peer_prefix_list_set_vty(
7514 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7515 argv[idx_word]->arg, argv[idx_in_out]->arg);
7516 }
7517
7518 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7519 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7520 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7521 "Filter updates to/from this neighbor\n"
7522 "Name of a prefix list\n"
7523 "Filter incoming updates\n"
7524 "Filter outgoing updates\n")
7525
7526 DEFUN (no_neighbor_prefix_list,
7527 no_neighbor_prefix_list_cmd,
7528 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7529 NO_STR
7530 NEIGHBOR_STR
7531 NEIGHBOR_ADDR_STR2
7532 "Filter updates to/from this neighbor\n"
7533 "Name of a prefix list\n"
7534 "Filter incoming updates\n"
7535 "Filter outgoing updates\n")
7536 {
7537 int idx_peer = 2;
7538 int idx_in_out = 5;
7539 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7540 bgp_node_afi(vty), bgp_node_safi(vty),
7541 argv[idx_in_out]->arg);
7542 }
7543
7544 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7545 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7546 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7547 "Filter updates to/from this neighbor\n"
7548 "Name of a prefix list\n"
7549 "Filter incoming updates\n"
7550 "Filter outgoing updates\n")
7551
7552 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7553 safi_t safi, const char *name_str,
7554 const char *direct_str)
7555 {
7556 int ret;
7557 struct peer *peer;
7558 int direct = FILTER_IN;
7559
7560 peer = peer_and_group_lookup_vty(vty, ip_str);
7561 if (!peer)
7562 return CMD_WARNING_CONFIG_FAILED;
7563
7564 /* Check filter direction. */
7565 if (strncmp(direct_str, "i", 1) == 0)
7566 direct = FILTER_IN;
7567 else if (strncmp(direct_str, "o", 1) == 0)
7568 direct = FILTER_OUT;
7569
7570 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7571
7572 return bgp_vty_return(vty, ret);
7573 }
7574
7575 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7576 safi_t safi, const char *direct_str)
7577 {
7578 int ret;
7579 struct peer *peer;
7580 int direct = FILTER_IN;
7581
7582 peer = peer_and_group_lookup_vty(vty, ip_str);
7583 if (!peer)
7584 return CMD_WARNING_CONFIG_FAILED;
7585
7586 /* Check filter direction. */
7587 if (strncmp(direct_str, "i", 1) == 0)
7588 direct = FILTER_IN;
7589 else if (strncmp(direct_str, "o", 1) == 0)
7590 direct = FILTER_OUT;
7591
7592 ret = peer_aslist_unset(peer, afi, safi, direct);
7593
7594 return bgp_vty_return(vty, ret);
7595 }
7596
7597 DEFUN (neighbor_filter_list,
7598 neighbor_filter_list_cmd,
7599 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7600 NEIGHBOR_STR
7601 NEIGHBOR_ADDR_STR2
7602 "Establish BGP filters\n"
7603 "AS path access-list name\n"
7604 "Filter incoming routes\n"
7605 "Filter outgoing routes\n")
7606 {
7607 int idx_peer = 1;
7608 int idx_word = 3;
7609 int idx_in_out = 4;
7610 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7611 bgp_node_safi(vty), argv[idx_word]->arg,
7612 argv[idx_in_out]->arg);
7613 }
7614
7615 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7616 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7617 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7618 "Establish BGP filters\n"
7619 "AS path access-list name\n"
7620 "Filter incoming routes\n"
7621 "Filter outgoing routes\n")
7622
7623 DEFUN (no_neighbor_filter_list,
7624 no_neighbor_filter_list_cmd,
7625 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7626 NO_STR
7627 NEIGHBOR_STR
7628 NEIGHBOR_ADDR_STR2
7629 "Establish BGP filters\n"
7630 "AS path access-list name\n"
7631 "Filter incoming routes\n"
7632 "Filter outgoing routes\n")
7633 {
7634 int idx_peer = 2;
7635 int idx_in_out = 5;
7636 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7637 bgp_node_afi(vty), bgp_node_safi(vty),
7638 argv[idx_in_out]->arg);
7639 }
7640
7641 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7642 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7643 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7644 "Establish BGP filters\n"
7645 "AS path access-list name\n"
7646 "Filter incoming routes\n"
7647 "Filter outgoing routes\n")
7648
7649 /* Set advertise-map to the peer. */
7650 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7651 afi_t afi, safi_t safi,
7652 const char *advertise_str,
7653 const char *condition_str, bool condition,
7654 bool set)
7655 {
7656 int ret = CMD_WARNING_CONFIG_FAILED;
7657 struct peer *peer;
7658 struct route_map *advertise_map;
7659 struct route_map *condition_map;
7660
7661 peer = peer_and_group_lookup_vty(vty, ip_str);
7662 if (!peer)
7663 return ret;
7664
7665 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7666 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7667
7668 if (set)
7669 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7670 advertise_map, condition_str,
7671 condition_map, condition);
7672 else
7673 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7674 advertise_map, condition_str,
7675 condition_map, condition);
7676
7677 return bgp_vty_return(vty, ret);
7678 }
7679
7680 DEFPY (bgp_condadv_period,
7681 bgp_condadv_period_cmd,
7682 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7683 NO_STR
7684 BGP_STR
7685 "Conditional advertisement settings\n"
7686 "Set period to rescan BGP table to check if condition is met\n"
7687 "Period between BGP table scans, in seconds; default 60\n")
7688 {
7689 VTY_DECLVAR_CONTEXT(bgp, bgp);
7690
7691 bgp->condition_check_period =
7692 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7693
7694 return CMD_SUCCESS;
7695 }
7696
7697 DEFPY (neighbor_advertise_map,
7698 neighbor_advertise_map_cmd,
7699 "[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",
7700 NO_STR
7701 NEIGHBOR_STR
7702 NEIGHBOR_ADDR_STR2
7703 "Route-map to conditionally advertise routes\n"
7704 "Name of advertise map\n"
7705 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7706 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7707 "Name of the exist or non exist map\n")
7708 {
7709 bool condition = CONDITION_EXIST;
7710
7711 if (!strcmp(exist, "non-exist-map"))
7712 condition = CONDITION_NON_EXIST;
7713
7714 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7715 bgp_node_safi(vty), advertise_str,
7716 condition_str, condition, !no);
7717 }
7718
7719 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7720 "[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",
7721 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7722 "Route-map to conditionally advertise routes\n"
7723 "Name of advertise map\n"
7724 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7725 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7726 "Name of the exist or non exist map\n")
7727
7728 /* Set route-map to the peer. */
7729 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7730 afi_t afi, safi_t safi, const char *name_str,
7731 const char *direct_str)
7732 {
7733 int ret;
7734 struct peer *peer;
7735 int direct = RMAP_IN;
7736 struct route_map *route_map;
7737
7738 peer = peer_and_group_lookup_vty(vty, ip_str);
7739 if (!peer)
7740 return CMD_WARNING_CONFIG_FAILED;
7741
7742 /* Check filter direction. */
7743 if (strncmp(direct_str, "in", 2) == 0)
7744 direct = RMAP_IN;
7745 else if (strncmp(direct_str, "o", 1) == 0)
7746 direct = RMAP_OUT;
7747
7748 route_map = route_map_lookup_warn_noexist(vty, name_str);
7749 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7750
7751 return bgp_vty_return(vty, ret);
7752 }
7753
7754 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7755 afi_t afi, safi_t safi,
7756 const char *direct_str)
7757 {
7758 int ret;
7759 struct peer *peer;
7760 int direct = RMAP_IN;
7761
7762 peer = peer_and_group_lookup_vty(vty, ip_str);
7763 if (!peer)
7764 return CMD_WARNING_CONFIG_FAILED;
7765
7766 /* Check filter direction. */
7767 if (strncmp(direct_str, "in", 2) == 0)
7768 direct = RMAP_IN;
7769 else if (strncmp(direct_str, "o", 1) == 0)
7770 direct = RMAP_OUT;
7771
7772 ret = peer_route_map_unset(peer, afi, safi, direct);
7773
7774 return bgp_vty_return(vty, ret);
7775 }
7776
7777 DEFUN (neighbor_route_map,
7778 neighbor_route_map_cmd,
7779 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7780 NEIGHBOR_STR
7781 NEIGHBOR_ADDR_STR2
7782 "Apply route map to neighbor\n"
7783 "Name of route map\n"
7784 "Apply map to incoming routes\n"
7785 "Apply map to outbound routes\n")
7786 {
7787 int idx_peer = 1;
7788 int idx_word = 3;
7789 int idx_in_out = 4;
7790 return peer_route_map_set_vty(
7791 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7792 argv[idx_word]->arg, argv[idx_in_out]->arg);
7793 }
7794
7795 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7796 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7797 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7798 "Apply route map to neighbor\n"
7799 "Name of route map\n"
7800 "Apply map to incoming routes\n"
7801 "Apply map to outbound routes\n")
7802
7803 DEFUN (no_neighbor_route_map,
7804 no_neighbor_route_map_cmd,
7805 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7806 NO_STR
7807 NEIGHBOR_STR
7808 NEIGHBOR_ADDR_STR2
7809 "Apply route map to neighbor\n"
7810 "Name of route map\n"
7811 "Apply map to incoming routes\n"
7812 "Apply map to outbound routes\n")
7813 {
7814 int idx_peer = 2;
7815 int idx_in_out = 5;
7816 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7817 bgp_node_afi(vty), bgp_node_safi(vty),
7818 argv[idx_in_out]->arg);
7819 }
7820
7821 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7822 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7823 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7824 "Apply route map to neighbor\n"
7825 "Name of route map\n"
7826 "Apply map to incoming routes\n"
7827 "Apply map to outbound routes\n")
7828
7829 /* Set unsuppress-map to the peer. */
7830 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7831 afi_t afi, safi_t safi,
7832 const char *name_str)
7833 {
7834 int ret;
7835 struct peer *peer;
7836 struct route_map *route_map;
7837
7838 peer = peer_and_group_lookup_vty(vty, ip_str);
7839 if (!peer)
7840 return CMD_WARNING_CONFIG_FAILED;
7841
7842 route_map = route_map_lookup_warn_noexist(vty, name_str);
7843 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7844
7845 return bgp_vty_return(vty, ret);
7846 }
7847
7848 /* Unset route-map from the peer. */
7849 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7850 afi_t afi, safi_t safi)
7851 {
7852 int ret;
7853 struct peer *peer;
7854
7855 peer = peer_and_group_lookup_vty(vty, ip_str);
7856 if (!peer)
7857 return CMD_WARNING_CONFIG_FAILED;
7858
7859 ret = peer_unsuppress_map_unset(peer, afi, safi);
7860
7861 return bgp_vty_return(vty, ret);
7862 }
7863
7864 DEFUN (neighbor_unsuppress_map,
7865 neighbor_unsuppress_map_cmd,
7866 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7867 NEIGHBOR_STR
7868 NEIGHBOR_ADDR_STR2
7869 "Route-map to selectively unsuppress suppressed routes\n"
7870 "Name of route map\n")
7871 {
7872 int idx_peer = 1;
7873 int idx_word = 3;
7874 return peer_unsuppress_map_set_vty(
7875 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7876 argv[idx_word]->arg);
7877 }
7878
7879 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7880 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7882 "Route-map to selectively unsuppress suppressed routes\n"
7883 "Name of route map\n")
7884
7885 DEFUN (no_neighbor_unsuppress_map,
7886 no_neighbor_unsuppress_map_cmd,
7887 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7888 NO_STR
7889 NEIGHBOR_STR
7890 NEIGHBOR_ADDR_STR2
7891 "Route-map to selectively unsuppress suppressed routes\n"
7892 "Name of route map\n")
7893 {
7894 int idx_peer = 2;
7895 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7896 bgp_node_afi(vty),
7897 bgp_node_safi(vty));
7898 }
7899
7900 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7901 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7902 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7903 "Route-map to selectively unsuppress suppressed routes\n"
7904 "Name of route map\n")
7905
7906 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7907 afi_t afi, safi_t safi,
7908 const char *num_str,
7909 const char *threshold_str, int warning,
7910 const char *restart_str,
7911 const char *force_str)
7912 {
7913 int ret;
7914 struct peer *peer;
7915 uint32_t max;
7916 uint8_t threshold;
7917 uint16_t restart;
7918
7919 peer = peer_and_group_lookup_vty(vty, ip_str);
7920 if (!peer)
7921 return CMD_WARNING_CONFIG_FAILED;
7922
7923 max = strtoul(num_str, NULL, 10);
7924 if (threshold_str)
7925 threshold = atoi(threshold_str);
7926 else
7927 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7928
7929 if (restart_str)
7930 restart = atoi(restart_str);
7931 else
7932 restart = 0;
7933
7934 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7935 restart, force_str ? true : false);
7936
7937 return bgp_vty_return(vty, ret);
7938 }
7939
7940 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7941 afi_t afi, safi_t safi)
7942 {
7943 int ret;
7944 struct peer *peer;
7945
7946 peer = peer_and_group_lookup_vty(vty, ip_str);
7947 if (!peer)
7948 return CMD_WARNING_CONFIG_FAILED;
7949
7950 ret = peer_maximum_prefix_unset(peer, afi, safi);
7951
7952 return bgp_vty_return(vty, ret);
7953 }
7954
7955 /* Maximum number of prefix to be sent to the neighbor. */
7956 DEFUN(neighbor_maximum_prefix_out,
7957 neighbor_maximum_prefix_out_cmd,
7958 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7959 NEIGHBOR_STR
7960 NEIGHBOR_ADDR_STR2
7961 "Maximum number of prefixes to be sent to this peer\n"
7962 "Maximum no. of prefix limit\n")
7963 {
7964 int ret;
7965 int idx_peer = 1;
7966 int idx_number = 3;
7967 struct peer *peer;
7968 uint32_t max;
7969 afi_t afi = bgp_node_afi(vty);
7970 safi_t safi = bgp_node_safi(vty);
7971
7972 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7973 if (!peer)
7974 return CMD_WARNING_CONFIG_FAILED;
7975
7976 max = strtoul(argv[idx_number]->arg, NULL, 10);
7977
7978 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
7979
7980 return bgp_vty_return(vty, ret);
7981 }
7982
7983 DEFUN(no_neighbor_maximum_prefix_out,
7984 no_neighbor_maximum_prefix_out_cmd,
7985 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
7986 NO_STR
7987 NEIGHBOR_STR
7988 NEIGHBOR_ADDR_STR2
7989 "Maximum number of prefixes to be sent to this peer\n"
7990 "Maximum no. of prefix limit\n")
7991 {
7992 int ret;
7993 int idx_peer = 2;
7994 struct peer *peer;
7995 afi_t afi = bgp_node_afi(vty);
7996 safi_t safi = bgp_node_safi(vty);
7997
7998 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7999 if (!peer)
8000 return CMD_WARNING_CONFIG_FAILED;
8001
8002 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8003
8004 return bgp_vty_return(vty, ret);
8005 }
8006
8007 /* Maximum number of prefix configuration. Prefix count is different
8008 for each peer configuration. So this configuration can be set for
8009 each peer configuration. */
8010 DEFUN (neighbor_maximum_prefix,
8011 neighbor_maximum_prefix_cmd,
8012 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8013 NEIGHBOR_STR
8014 NEIGHBOR_ADDR_STR2
8015 "Maximum number of prefix accept from this peer\n"
8016 "maximum no. of prefix limit\n"
8017 "Force checking all received routes not only accepted\n")
8018 {
8019 int idx_peer = 1;
8020 int idx_number = 3;
8021 int idx_force = 0;
8022 char *force = NULL;
8023
8024 if (argv_find(argv, argc, "force", &idx_force))
8025 force = argv[idx_force]->arg;
8026
8027 return peer_maximum_prefix_set_vty(
8028 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8029 argv[idx_number]->arg, NULL, 0, NULL, force);
8030 }
8031
8032 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8033 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8034 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8035 "Maximum number of prefix accept from this peer\n"
8036 "maximum no. of prefix limit\n"
8037 "Force checking all received routes not only accepted\n")
8038
8039 DEFUN (neighbor_maximum_prefix_threshold,
8040 neighbor_maximum_prefix_threshold_cmd,
8041 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8042 NEIGHBOR_STR
8043 NEIGHBOR_ADDR_STR2
8044 "Maximum number of prefix accept from this peer\n"
8045 "maximum no. of prefix limit\n"
8046 "Threshold value (%) at which to generate a warning msg\n"
8047 "Force checking all received routes not only accepted\n")
8048 {
8049 int idx_peer = 1;
8050 int idx_number = 3;
8051 int idx_number_2 = 4;
8052 int idx_force = 0;
8053 char *force = NULL;
8054
8055 if (argv_find(argv, argc, "force", &idx_force))
8056 force = argv[idx_force]->arg;
8057
8058 return peer_maximum_prefix_set_vty(
8059 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8060 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8061 }
8062
8063 ALIAS_HIDDEN(
8064 neighbor_maximum_prefix_threshold,
8065 neighbor_maximum_prefix_threshold_hidden_cmd,
8066 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8067 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8068 "Maximum number of prefix accept from this peer\n"
8069 "maximum no. of prefix limit\n"
8070 "Threshold value (%) at which to generate a warning msg\n"
8071 "Force checking all received routes not only accepted\n")
8072
8073 DEFUN (neighbor_maximum_prefix_warning,
8074 neighbor_maximum_prefix_warning_cmd,
8075 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8076 NEIGHBOR_STR
8077 NEIGHBOR_ADDR_STR2
8078 "Maximum number of prefix accept from this peer\n"
8079 "maximum no. of prefix limit\n"
8080 "Only give warning message when limit is exceeded\n"
8081 "Force checking all received routes not only accepted\n")
8082 {
8083 int idx_peer = 1;
8084 int idx_number = 3;
8085 int idx_force = 0;
8086 char *force = NULL;
8087
8088 if (argv_find(argv, argc, "force", &idx_force))
8089 force = argv[idx_force]->arg;
8090
8091 return peer_maximum_prefix_set_vty(
8092 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8093 argv[idx_number]->arg, NULL, 1, NULL, force);
8094 }
8095
8096 ALIAS_HIDDEN(
8097 neighbor_maximum_prefix_warning,
8098 neighbor_maximum_prefix_warning_hidden_cmd,
8099 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8100 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8101 "Maximum number of prefix accept from this peer\n"
8102 "maximum no. of prefix limit\n"
8103 "Only give warning message when limit is exceeded\n"
8104 "Force checking all received routes not only accepted\n")
8105
8106 DEFUN (neighbor_maximum_prefix_threshold_warning,
8107 neighbor_maximum_prefix_threshold_warning_cmd,
8108 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8109 NEIGHBOR_STR
8110 NEIGHBOR_ADDR_STR2
8111 "Maximum number of prefix accept from this peer\n"
8112 "maximum no. of prefix limit\n"
8113 "Threshold value (%) at which to generate a warning msg\n"
8114 "Only give warning message when limit is exceeded\n"
8115 "Force checking all received routes not only accepted\n")
8116 {
8117 int idx_peer = 1;
8118 int idx_number = 3;
8119 int idx_number_2 = 4;
8120 int idx_force = 0;
8121 char *force = NULL;
8122
8123 if (argv_find(argv, argc, "force", &idx_force))
8124 force = argv[idx_force]->arg;
8125
8126 return peer_maximum_prefix_set_vty(
8127 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8128 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8129 }
8130
8131 ALIAS_HIDDEN(
8132 neighbor_maximum_prefix_threshold_warning,
8133 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8134 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8135 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8136 "Maximum number of prefix accept from this peer\n"
8137 "maximum no. of prefix limit\n"
8138 "Threshold value (%) at which to generate a warning msg\n"
8139 "Only give warning message when limit is exceeded\n"
8140 "Force checking all received routes not only accepted\n")
8141
8142 DEFUN (neighbor_maximum_prefix_restart,
8143 neighbor_maximum_prefix_restart_cmd,
8144 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8145 NEIGHBOR_STR
8146 NEIGHBOR_ADDR_STR2
8147 "Maximum number of prefix accept from this peer\n"
8148 "maximum no. of prefix limit\n"
8149 "Restart bgp connection after limit is exceeded\n"
8150 "Restart interval in minutes\n"
8151 "Force checking all received routes not only accepted\n")
8152 {
8153 int idx_peer = 1;
8154 int idx_number = 3;
8155 int idx_number_2 = 5;
8156 int idx_force = 0;
8157 char *force = NULL;
8158
8159 if (argv_find(argv, argc, "force", &idx_force))
8160 force = argv[idx_force]->arg;
8161
8162 return peer_maximum_prefix_set_vty(
8163 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8164 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8165 }
8166
8167 ALIAS_HIDDEN(
8168 neighbor_maximum_prefix_restart,
8169 neighbor_maximum_prefix_restart_hidden_cmd,
8170 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8171 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8172 "Maximum number of prefix accept from this peer\n"
8173 "maximum no. of prefix limit\n"
8174 "Restart bgp connection after limit is exceeded\n"
8175 "Restart interval in minutes\n"
8176 "Force checking all received routes not only accepted\n")
8177
8178 DEFUN (neighbor_maximum_prefix_threshold_restart,
8179 neighbor_maximum_prefix_threshold_restart_cmd,
8180 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8181 NEIGHBOR_STR
8182 NEIGHBOR_ADDR_STR2
8183 "Maximum number of prefixes to accept from this peer\n"
8184 "maximum no. of prefix limit\n"
8185 "Threshold value (%) at which to generate a warning msg\n"
8186 "Restart bgp connection after limit is exceeded\n"
8187 "Restart interval in minutes\n"
8188 "Force checking all received routes not only accepted\n")
8189 {
8190 int idx_peer = 1;
8191 int idx_number = 3;
8192 int idx_number_2 = 4;
8193 int idx_number_3 = 6;
8194 int idx_force = 0;
8195 char *force = NULL;
8196
8197 if (argv_find(argv, argc, "force", &idx_force))
8198 force = argv[idx_force]->arg;
8199
8200 return peer_maximum_prefix_set_vty(
8201 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8202 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8203 argv[idx_number_3]->arg, force);
8204 }
8205
8206 ALIAS_HIDDEN(
8207 neighbor_maximum_prefix_threshold_restart,
8208 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8209 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8210 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8211 "Maximum number of prefixes to accept from this peer\n"
8212 "maximum no. of prefix limit\n"
8213 "Threshold value (%) at which to generate a warning msg\n"
8214 "Restart bgp connection after limit is exceeded\n"
8215 "Restart interval in minutes\n"
8216 "Force checking all received routes not only accepted\n")
8217
8218 DEFUN (no_neighbor_maximum_prefix,
8219 no_neighbor_maximum_prefix_cmd,
8220 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8221 NO_STR
8222 NEIGHBOR_STR
8223 NEIGHBOR_ADDR_STR2
8224 "Maximum number of prefixes to accept from this peer\n"
8225 "maximum no. of prefix limit\n"
8226 "Threshold value (%) at which to generate a warning msg\n"
8227 "Restart bgp connection after limit is exceeded\n"
8228 "Restart interval in minutes\n"
8229 "Only give warning message when limit is exceeded\n"
8230 "Force checking all received routes not only accepted\n")
8231 {
8232 int idx_peer = 2;
8233 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8234 bgp_node_afi(vty),
8235 bgp_node_safi(vty));
8236 }
8237
8238 ALIAS_HIDDEN(
8239 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8240 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8241 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8242 "Maximum number of prefixes to accept from this peer\n"
8243 "maximum no. of prefix limit\n"
8244 "Threshold value (%) at which to generate a warning msg\n"
8245 "Restart bgp connection after limit is exceeded\n"
8246 "Restart interval in minutes\n"
8247 "Only give warning message when limit is exceeded\n"
8248 "Force checking all received routes not only accepted\n")
8249
8250 /* "neighbor soo" */
8251 DEFPY (neighbor_soo,
8252 neighbor_soo_cmd,
8253 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8254 NEIGHBOR_STR
8255 NEIGHBOR_ADDR_STR2
8256 "Set the Site-of-Origin (SoO) extended community\n"
8257 "VPN extended community\n")
8258 {
8259 struct peer *peer;
8260 afi_t afi = bgp_node_afi(vty);
8261 safi_t safi = bgp_node_safi(vty);
8262 struct ecommunity *ecomm_soo;
8263
8264 peer = peer_and_group_lookup_vty(vty, neighbor);
8265 if (!peer)
8266 return CMD_WARNING_CONFIG_FAILED;
8267
8268 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8269 if (!ecomm_soo) {
8270 vty_out(vty, "%% Malformed SoO extended community\n");
8271 return CMD_WARNING;
8272 }
8273 ecommunity_str(ecomm_soo);
8274
8275 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8276 ecommunity_free(&peer->soo[afi][safi]);
8277 peer->soo[afi][safi] = ecomm_soo;
8278 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8279 }
8280
8281 return bgp_vty_return(vty,
8282 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8283 }
8284
8285 DEFPY (no_neighbor_soo,
8286 no_neighbor_soo_cmd,
8287 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8288 NO_STR
8289 NEIGHBOR_STR
8290 NEIGHBOR_ADDR_STR2
8291 "Set the Site-of-Origin (SoO) extended community\n"
8292 "VPN extended community\n")
8293 {
8294 struct peer *peer;
8295 afi_t afi = bgp_node_afi(vty);
8296 safi_t safi = bgp_node_safi(vty);
8297
8298 peer = peer_and_group_lookup_vty(vty, neighbor);
8299 if (!peer)
8300 return CMD_WARNING_CONFIG_FAILED;
8301
8302 ecommunity_free(&peer->soo[afi][safi]);
8303
8304 return bgp_vty_return(
8305 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8306 }
8307
8308 /* "neighbor allowas-in" */
8309 DEFUN (neighbor_allowas_in,
8310 neighbor_allowas_in_cmd,
8311 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8312 NEIGHBOR_STR
8313 NEIGHBOR_ADDR_STR2
8314 "Accept as-path with my AS present in it\n"
8315 "Number of occurrences of AS number\n"
8316 "Only accept my AS in the as-path if the route was originated in my AS\n")
8317 {
8318 int idx_peer = 1;
8319 int idx_number_origin = 3;
8320 int ret;
8321 int origin = 0;
8322 struct peer *peer;
8323 int allow_num = 0;
8324
8325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8326 if (!peer)
8327 return CMD_WARNING_CONFIG_FAILED;
8328
8329 if (argc <= idx_number_origin)
8330 allow_num = 3;
8331 else {
8332 if (argv[idx_number_origin]->type == WORD_TKN)
8333 origin = 1;
8334 else
8335 allow_num = atoi(argv[idx_number_origin]->arg);
8336 }
8337
8338 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8339 allow_num, origin);
8340
8341 return bgp_vty_return(vty, ret);
8342 }
8343
8344 ALIAS_HIDDEN(
8345 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8346 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8347 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8348 "Accept as-path with my AS present in it\n"
8349 "Number of occurrences of AS number\n"
8350 "Only accept my AS in the as-path if the route was originated in my AS\n")
8351
8352 DEFUN (no_neighbor_allowas_in,
8353 no_neighbor_allowas_in_cmd,
8354 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8355 NO_STR
8356 NEIGHBOR_STR
8357 NEIGHBOR_ADDR_STR2
8358 "allow local ASN appears in aspath attribute\n"
8359 "Number of occurrences of AS number\n"
8360 "Only accept my AS in the as-path if the route was originated in my AS\n")
8361 {
8362 int idx_peer = 2;
8363 int ret;
8364 struct peer *peer;
8365
8366 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8367 if (!peer)
8368 return CMD_WARNING_CONFIG_FAILED;
8369
8370 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8371 bgp_node_safi(vty));
8372
8373 return bgp_vty_return(vty, ret);
8374 }
8375
8376 ALIAS_HIDDEN(
8377 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8378 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8379 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8380 "allow local ASN appears in aspath attribute\n"
8381 "Number of occurrences of AS number\n"
8382 "Only accept my AS in the as-path if the route was originated in my AS\n")
8383
8384 DEFUN (neighbor_ttl_security,
8385 neighbor_ttl_security_cmd,
8386 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8387 NEIGHBOR_STR
8388 NEIGHBOR_ADDR_STR2
8389 "BGP ttl-security parameters\n"
8390 "Specify the maximum number of hops to the BGP peer\n"
8391 "Number of hops to BGP peer\n")
8392 {
8393 int idx_peer = 1;
8394 int idx_number = 4;
8395 struct peer *peer;
8396 int gtsm_hops;
8397
8398 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8399 if (!peer)
8400 return CMD_WARNING_CONFIG_FAILED;
8401
8402 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8403
8404 /*
8405 * If 'neighbor swpX', then this is for directly connected peers,
8406 * we should not accept a ttl-security hops value greater than 1.
8407 */
8408 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8409 vty_out(vty,
8410 "%s is directly connected peer, hops cannot exceed 1\n",
8411 argv[idx_peer]->arg);
8412 return CMD_WARNING_CONFIG_FAILED;
8413 }
8414
8415 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8416 }
8417
8418 DEFUN (no_neighbor_ttl_security,
8419 no_neighbor_ttl_security_cmd,
8420 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8421 NO_STR
8422 NEIGHBOR_STR
8423 NEIGHBOR_ADDR_STR2
8424 "BGP ttl-security parameters\n"
8425 "Specify the maximum number of hops to the BGP peer\n"
8426 "Number of hops to BGP peer\n")
8427 {
8428 int idx_peer = 2;
8429 struct peer *peer;
8430
8431 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8432 if (!peer)
8433 return CMD_WARNING_CONFIG_FAILED;
8434
8435 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8436 }
8437
8438 /* disable-addpath-rx */
8439 DEFUN(neighbor_disable_addpath_rx,
8440 neighbor_disable_addpath_rx_cmd,
8441 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8442 NEIGHBOR_STR
8443 NEIGHBOR_ADDR_STR2
8444 "Do not accept additional paths\n")
8445 {
8446 char *peer_str = argv[1]->arg;
8447 struct peer *peer;
8448 afi_t afi = bgp_node_afi(vty);
8449 safi_t safi = bgp_node_safi(vty);
8450
8451 peer = peer_and_group_lookup_vty(vty, peer_str);
8452 if (!peer)
8453 return CMD_WARNING_CONFIG_FAILED;
8454
8455 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8456 PEER_FLAG_DISABLE_ADDPATH_RX);
8457 }
8458
8459 DEFUN(no_neighbor_disable_addpath_rx,
8460 no_neighbor_disable_addpath_rx_cmd,
8461 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8462 NO_STR
8463 NEIGHBOR_STR
8464 NEIGHBOR_ADDR_STR2
8465 "Do not accept additional paths\n")
8466 {
8467 char *peer_str = argv[2]->arg;
8468 struct peer *peer;
8469 afi_t afi = bgp_node_afi(vty);
8470 safi_t safi = bgp_node_safi(vty);
8471
8472 peer = peer_and_group_lookup_vty(vty, peer_str);
8473 if (!peer)
8474 return CMD_WARNING_CONFIG_FAILED;
8475
8476 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8477 PEER_FLAG_DISABLE_ADDPATH_RX);
8478 }
8479
8480 DEFUN (neighbor_addpath_tx_all_paths,
8481 neighbor_addpath_tx_all_paths_cmd,
8482 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8483 NEIGHBOR_STR
8484 NEIGHBOR_ADDR_STR2
8485 "Use addpath to advertise all paths to a neighbor\n")
8486 {
8487 int idx_peer = 1;
8488 struct peer *peer;
8489
8490 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8491 if (!peer)
8492 return CMD_WARNING_CONFIG_FAILED;
8493
8494 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8495 BGP_ADDPATH_ALL);
8496 return CMD_SUCCESS;
8497 }
8498
8499 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8500 neighbor_addpath_tx_all_paths_hidden_cmd,
8501 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8502 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8503 "Use addpath to advertise all paths to a neighbor\n")
8504
8505 DEFUN (no_neighbor_addpath_tx_all_paths,
8506 no_neighbor_addpath_tx_all_paths_cmd,
8507 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8508 NO_STR
8509 NEIGHBOR_STR
8510 NEIGHBOR_ADDR_STR2
8511 "Use addpath to advertise all paths to a neighbor\n")
8512 {
8513 int idx_peer = 2;
8514 struct peer *peer;
8515
8516 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8517 if (!peer)
8518 return CMD_WARNING_CONFIG_FAILED;
8519
8520 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8521 != BGP_ADDPATH_ALL) {
8522 vty_out(vty,
8523 "%% Peer not currently configured to transmit all paths.");
8524 return CMD_WARNING_CONFIG_FAILED;
8525 }
8526
8527 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8528 BGP_ADDPATH_NONE);
8529
8530 return CMD_SUCCESS;
8531 }
8532
8533 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8534 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8535 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8536 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8537 "Use addpath to advertise all paths to a neighbor\n")
8538
8539 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8540 neighbor_addpath_tx_bestpath_per_as_cmd,
8541 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8542 NEIGHBOR_STR
8543 NEIGHBOR_ADDR_STR2
8544 "Use addpath to advertise the bestpath per each neighboring AS\n")
8545 {
8546 int idx_peer = 1;
8547 struct peer *peer;
8548
8549 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8550 if (!peer)
8551 return CMD_WARNING_CONFIG_FAILED;
8552
8553 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8554 BGP_ADDPATH_BEST_PER_AS);
8555
8556 return CMD_SUCCESS;
8557 }
8558
8559 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8560 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8561 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8562 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8563 "Use addpath to advertise the bestpath per each neighboring AS\n")
8564
8565 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8566 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8567 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8568 NO_STR
8569 NEIGHBOR_STR
8570 NEIGHBOR_ADDR_STR2
8571 "Use addpath to advertise the bestpath per each neighboring AS\n")
8572 {
8573 int idx_peer = 2;
8574 struct peer *peer;
8575
8576 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8577 if (!peer)
8578 return CMD_WARNING_CONFIG_FAILED;
8579
8580 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8581 != BGP_ADDPATH_BEST_PER_AS) {
8582 vty_out(vty,
8583 "%% Peer not currently configured to transmit all best path per as.");
8584 return CMD_WARNING_CONFIG_FAILED;
8585 }
8586
8587 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8588 BGP_ADDPATH_NONE);
8589
8590 return CMD_SUCCESS;
8591 }
8592
8593 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8594 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8595 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8596 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8597 "Use addpath to advertise the bestpath per each neighboring AS\n")
8598
8599 DEFPY(
8600 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8601 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8602 NEIGHBOR_STR
8603 NEIGHBOR_ADDR_STR2
8604 "Detect AS loops before sending to neighbor\n")
8605 {
8606 struct peer *peer;
8607
8608 peer = peer_and_group_lookup_vty(vty, neighbor);
8609 if (!peer)
8610 return CMD_WARNING_CONFIG_FAILED;
8611
8612 peer->as_path_loop_detection = true;
8613
8614 return CMD_SUCCESS;
8615 }
8616
8617 DEFPY(
8618 no_neighbor_aspath_loop_detection,
8619 no_neighbor_aspath_loop_detection_cmd,
8620 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8621 NO_STR
8622 NEIGHBOR_STR
8623 NEIGHBOR_ADDR_STR2
8624 "Detect AS loops before sending to neighbor\n")
8625 {
8626 struct peer *peer;
8627
8628 peer = peer_and_group_lookup_vty(vty, neighbor);
8629 if (!peer)
8630 return CMD_WARNING_CONFIG_FAILED;
8631
8632 peer->as_path_loop_detection = false;
8633
8634 return CMD_SUCCESS;
8635 }
8636
8637 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8638 struct ecommunity **list, bool is_rt6)
8639 {
8640 struct ecommunity *ecom = NULL;
8641 struct ecommunity *ecomadd;
8642
8643 for (; argc; --argc, ++argv) {
8644 if (is_rt6)
8645 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8646 ECOMMUNITY_ROUTE_TARGET,
8647 0);
8648 else
8649 ecomadd = ecommunity_str2com(argv[0]->arg,
8650 ECOMMUNITY_ROUTE_TARGET,
8651 0);
8652 if (!ecomadd) {
8653 vty_out(vty, "Malformed community-list value\n");
8654 if (ecom)
8655 ecommunity_free(&ecom);
8656 return CMD_WARNING_CONFIG_FAILED;
8657 }
8658
8659 if (ecom) {
8660 ecommunity_merge(ecom, ecomadd);
8661 ecommunity_free(&ecomadd);
8662 } else {
8663 ecom = ecomadd;
8664 }
8665 }
8666
8667 if (*list) {
8668 ecommunity_free(&*list);
8669 }
8670 *list = ecom;
8671
8672 return CMD_SUCCESS;
8673 }
8674
8675 /*
8676 * v2vimport is true if we are handling a `import vrf ...` command
8677 */
8678 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8679 {
8680 afi_t afi;
8681
8682 switch (vty->node) {
8683 case BGP_IPV4_NODE:
8684 afi = AFI_IP;
8685 break;
8686 case BGP_IPV6_NODE:
8687 afi = AFI_IP6;
8688 break;
8689 default:
8690 vty_out(vty,
8691 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8692 return AFI_MAX;
8693 }
8694
8695 if (!v2vimport) {
8696 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8697 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8698 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8699 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8700 vty_out(vty,
8701 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8702 return AFI_MAX;
8703 }
8704 } else {
8705 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8706 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8707 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8708 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8709 vty_out(vty,
8710 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8711 return AFI_MAX;
8712 }
8713 }
8714 return afi;
8715 }
8716
8717 DEFPY (af_rd_vpn_export,
8718 af_rd_vpn_export_cmd,
8719 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8720 NO_STR
8721 "Specify route distinguisher\n"
8722 "Between current address-family and vpn\n"
8723 "For routes leaked from current address-family to vpn\n"
8724 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8725 {
8726 VTY_DECLVAR_CONTEXT(bgp, bgp);
8727 struct prefix_rd prd;
8728 int ret;
8729 afi_t afi;
8730 int idx = 0;
8731 bool yes = true;
8732
8733 if (argv_find(argv, argc, "no", &idx))
8734 yes = false;
8735
8736 if (yes) {
8737 ret = str2prefix_rd(rd_str, &prd);
8738 if (!ret) {
8739 vty_out(vty, "%% Malformed rd\n");
8740 return CMD_WARNING_CONFIG_FAILED;
8741 }
8742 }
8743
8744 afi = vpn_policy_getafi(vty, bgp, false);
8745 if (afi == AFI_MAX)
8746 return CMD_WARNING_CONFIG_FAILED;
8747
8748 /*
8749 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8750 */
8751 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8752 bgp_get_default(), bgp);
8753
8754 if (yes) {
8755 bgp->vpn_policy[afi].tovpn_rd = prd;
8756 SET_FLAG(bgp->vpn_policy[afi].flags,
8757 BGP_VPN_POLICY_TOVPN_RD_SET);
8758 } else {
8759 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8760 BGP_VPN_POLICY_TOVPN_RD_SET);
8761 }
8762
8763 /* post-change: re-export vpn routes */
8764 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8765 bgp_get_default(), bgp);
8766
8767 return CMD_SUCCESS;
8768 }
8769
8770 ALIAS (af_rd_vpn_export,
8771 af_no_rd_vpn_export_cmd,
8772 "no rd vpn export",
8773 NO_STR
8774 "Specify route distinguisher\n"
8775 "Between current address-family and vpn\n"
8776 "For routes leaked from current address-family to vpn\n")
8777
8778 DEFPY (af_label_vpn_export,
8779 af_label_vpn_export_cmd,
8780 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8781 NO_STR
8782 "label value for VRF\n"
8783 "Between current address-family and vpn\n"
8784 "For routes leaked from current address-family to vpn\n"
8785 "Label Value <0-1048575>\n"
8786 "Automatically assign a label\n")
8787 {
8788 VTY_DECLVAR_CONTEXT(bgp, bgp);
8789 mpls_label_t label = MPLS_LABEL_NONE;
8790 afi_t afi;
8791 int idx = 0;
8792 bool yes = true;
8793
8794 if (argv_find(argv, argc, "no", &idx))
8795 yes = false;
8796
8797 /* If "no ...", squash trailing parameter */
8798 if (!yes)
8799 label_auto = NULL;
8800
8801 if (yes) {
8802 if (!label_auto)
8803 label = label_val; /* parser should force unsigned */
8804 }
8805
8806 afi = vpn_policy_getafi(vty, bgp, false);
8807 if (afi == AFI_MAX)
8808 return CMD_WARNING_CONFIG_FAILED;
8809
8810
8811 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8812 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8813 /* no change */
8814 return CMD_SUCCESS;
8815
8816 /*
8817 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8818 */
8819 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8820 bgp_get_default(), bgp);
8821
8822 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8823 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8824
8825 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8826
8827 /*
8828 * label has previously been automatically
8829 * assigned by labelpool: release it
8830 *
8831 * NB if tovpn_label == MPLS_LABEL_NONE it
8832 * means the automatic assignment is in flight
8833 * and therefore the labelpool callback must
8834 * detect that the auto label is not needed.
8835 */
8836
8837 bgp_lp_release(LP_TYPE_VRF,
8838 &bgp->vpn_policy[afi],
8839 bgp->vpn_policy[afi].tovpn_label);
8840 }
8841 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8842 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8843 }
8844
8845 bgp->vpn_policy[afi].tovpn_label = label;
8846 if (label_auto) {
8847 SET_FLAG(bgp->vpn_policy[afi].flags,
8848 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8849 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8850 vpn_leak_label_callback);
8851 }
8852
8853 /* post-change: re-export vpn routes */
8854 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8855 bgp_get_default(), bgp);
8856
8857 hook_call(bgp_snmp_update_last_changed, bgp);
8858 return CMD_SUCCESS;
8859 }
8860
8861 DEFPY (af_sid_vpn_export,
8862 af_sid_vpn_export_cmd,
8863 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8864 NO_STR
8865 "sid value for VRF\n"
8866 "Between current address-family and vpn\n"
8867 "For routes leaked from current address-family to vpn\n"
8868 "Sid allocation index\n"
8869 "Automatically assign a label\n")
8870 {
8871 VTY_DECLVAR_CONTEXT(bgp, bgp);
8872 afi_t afi;
8873 int debug = 0;
8874 int idx = 0;
8875 bool yes = true;
8876
8877 if (argv_find(argv, argc, "no", &idx))
8878 yes = false;
8879 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8880 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8881
8882 afi = vpn_policy_getafi(vty, bgp, false);
8883 if (afi == AFI_MAX)
8884 return CMD_WARNING_CONFIG_FAILED;
8885
8886 if (!yes) {
8887 /* implement me */
8888 vty_out(vty, "It's not implemented\n");
8889 return CMD_WARNING_CONFIG_FAILED;
8890 }
8891
8892 /* skip when it's already configured */
8893 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8894 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8895 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8896 return CMD_SUCCESS;
8897
8898 /*
8899 * mode change between sid_idx and sid_auto isn't supported.
8900 * user must negate sid vpn export when they want to change the mode
8901 */
8902 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8903 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8904 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8905 vty_out(vty, "it's already configured as %s.\n",
8906 sid_auto ? "auto-mode" : "idx-mode");
8907 return CMD_WARNING_CONFIG_FAILED;
8908 }
8909
8910 /* pre-change */
8911 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8912 bgp_get_default(), bgp);
8913
8914 if (sid_auto) {
8915 /* SID allocation auto-mode */
8916 if (debug)
8917 zlog_debug("%s: auto sid alloc.", __func__);
8918 SET_FLAG(bgp->vpn_policy[afi].flags,
8919 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8920 } else {
8921 /* SID allocation index-mode */
8922 if (debug)
8923 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8924 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8925 }
8926
8927 /* post-change */
8928 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8929 bgp_get_default(), bgp);
8930 return CMD_SUCCESS;
8931 }
8932
8933 ALIAS (af_label_vpn_export,
8934 af_no_label_vpn_export_cmd,
8935 "no label vpn export",
8936 NO_STR
8937 "label value for VRF\n"
8938 "Between current address-family and vpn\n"
8939 "For routes leaked from current address-family to vpn\n")
8940
8941 DEFPY (af_nexthop_vpn_export,
8942 af_nexthop_vpn_export_cmd,
8943 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8944 NO_STR
8945 "Specify next hop to use for VRF advertised prefixes\n"
8946 "Between current address-family and vpn\n"
8947 "For routes leaked from current address-family to vpn\n"
8948 "IPv4 prefix\n"
8949 "IPv6 prefix\n")
8950 {
8951 VTY_DECLVAR_CONTEXT(bgp, bgp);
8952 afi_t afi;
8953 struct prefix p;
8954
8955 if (!no) {
8956 if (!nexthop_su) {
8957 vty_out(vty, "%% Nexthop required\n");
8958 return CMD_WARNING_CONFIG_FAILED;
8959 }
8960 if (!sockunion2hostprefix(nexthop_su, &p))
8961 return CMD_WARNING_CONFIG_FAILED;
8962 }
8963
8964 afi = vpn_policy_getafi(vty, bgp, false);
8965 if (afi == AFI_MAX)
8966 return CMD_WARNING_CONFIG_FAILED;
8967
8968 /*
8969 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8970 */
8971 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8972 bgp_get_default(), bgp);
8973
8974 if (!no) {
8975 bgp->vpn_policy[afi].tovpn_nexthop = p;
8976 SET_FLAG(bgp->vpn_policy[afi].flags,
8977 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8978 } else {
8979 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8980 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8981 }
8982
8983 /* post-change: re-export vpn routes */
8984 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8985 bgp_get_default(), bgp);
8986
8987 return CMD_SUCCESS;
8988 }
8989
8990 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8991 {
8992 if (!strcmp(dstr, "import")) {
8993 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8994 } else if (!strcmp(dstr, "export")) {
8995 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8996 } else if (!strcmp(dstr, "both")) {
8997 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8998 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8999 } else {
9000 vty_out(vty, "%% direction parse error\n");
9001 return CMD_WARNING_CONFIG_FAILED;
9002 }
9003 return CMD_SUCCESS;
9004 }
9005
9006 DEFPY (af_rt_vpn_imexport,
9007 af_rt_vpn_imexport_cmd,
9008 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9009 NO_STR
9010 "Specify route target list\n"
9011 "Specify route target list\n"
9012 "Between current address-family and vpn\n"
9013 "For routes leaked from vpn to current address-family: match any\n"
9014 "For routes leaked from current address-family to vpn: set\n"
9015 "both import: match any and export: set\n"
9016 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9017 {
9018 VTY_DECLVAR_CONTEXT(bgp, bgp);
9019 int ret;
9020 struct ecommunity *ecom = NULL;
9021 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9022 enum vpn_policy_direction dir;
9023 afi_t afi;
9024 int idx = 0;
9025 bool yes = true;
9026
9027 if (argv_find(argv, argc, "no", &idx))
9028 yes = false;
9029
9030 afi = vpn_policy_getafi(vty, bgp, false);
9031 if (afi == AFI_MAX)
9032 return CMD_WARNING_CONFIG_FAILED;
9033
9034 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9035 if (ret != CMD_SUCCESS)
9036 return ret;
9037
9038 if (yes) {
9039 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9040 vty_out(vty, "%% Missing RTLIST\n");
9041 return CMD_WARNING_CONFIG_FAILED;
9042 }
9043 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9044 if (ret != CMD_SUCCESS) {
9045 return ret;
9046 }
9047 }
9048
9049 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9050 if (!dodir[dir])
9051 continue;
9052
9053 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9054
9055 if (yes) {
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] =
9060 ecommunity_dup(ecom);
9061 } else {
9062 if (bgp->vpn_policy[afi].rtlist[dir])
9063 ecommunity_free(
9064 &bgp->vpn_policy[afi].rtlist[dir]);
9065 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9066 }
9067
9068 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9069 }
9070
9071 if (ecom)
9072 ecommunity_free(&ecom);
9073
9074 return CMD_SUCCESS;
9075 }
9076
9077 ALIAS (af_rt_vpn_imexport,
9078 af_no_rt_vpn_imexport_cmd,
9079 "no <rt|route-target> vpn <import|export|both>$direction_str",
9080 NO_STR
9081 "Specify route target list\n"
9082 "Specify route target list\n"
9083 "Between current address-family and vpn\n"
9084 "For routes leaked from vpn to current address-family\n"
9085 "For routes leaked from current address-family to vpn\n"
9086 "both import and export\n")
9087
9088 DEFPY (af_route_map_vpn_imexport,
9089 af_route_map_vpn_imexport_cmd,
9090 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9091 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9092 NO_STR
9093 "Specify route map\n"
9094 "Between current address-family and vpn\n"
9095 "For routes leaked from vpn to current address-family\n"
9096 "For routes leaked from current address-family to vpn\n"
9097 "name of route-map\n")
9098 {
9099 VTY_DECLVAR_CONTEXT(bgp, bgp);
9100 int ret;
9101 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9102 enum vpn_policy_direction dir;
9103 afi_t afi;
9104 int idx = 0;
9105 bool yes = true;
9106
9107 if (argv_find(argv, argc, "no", &idx))
9108 yes = false;
9109
9110 afi = vpn_policy_getafi(vty, bgp, false);
9111 if (afi == AFI_MAX)
9112 return CMD_WARNING_CONFIG_FAILED;
9113
9114 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9115 if (ret != CMD_SUCCESS)
9116 return ret;
9117
9118 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9119 if (!dodir[dir])
9120 continue;
9121
9122 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9123
9124 if (yes) {
9125 if (bgp->vpn_policy[afi].rmap_name[dir])
9126 XFREE(MTYPE_ROUTE_MAP_NAME,
9127 bgp->vpn_policy[afi].rmap_name[dir]);
9128 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9129 MTYPE_ROUTE_MAP_NAME, rmap_str);
9130 bgp->vpn_policy[afi].rmap[dir] =
9131 route_map_lookup_warn_noexist(vty, rmap_str);
9132 if (!bgp->vpn_policy[afi].rmap[dir])
9133 return CMD_SUCCESS;
9134 } else {
9135 if (bgp->vpn_policy[afi].rmap_name[dir])
9136 XFREE(MTYPE_ROUTE_MAP_NAME,
9137 bgp->vpn_policy[afi].rmap_name[dir]);
9138 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9139 bgp->vpn_policy[afi].rmap[dir] = NULL;
9140 }
9141
9142 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9143 }
9144
9145 return CMD_SUCCESS;
9146 }
9147
9148 ALIAS (af_route_map_vpn_imexport,
9149 af_no_route_map_vpn_imexport_cmd,
9150 "no route-map vpn <import|export>$direction_str",
9151 NO_STR
9152 "Specify route map\n"
9153 "Between current address-family and vpn\n"
9154 "For routes leaked from vpn to current address-family\n"
9155 "For routes leaked from current address-family to vpn\n")
9156
9157 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9158 "import vrf route-map RMAP$rmap_str",
9159 "Import routes from another VRF\n"
9160 "Vrf routes being filtered\n"
9161 "Specify route map\n"
9162 "name of route-map\n")
9163 {
9164 VTY_DECLVAR_CONTEXT(bgp, bgp);
9165 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9166 afi_t afi;
9167 struct bgp *bgp_default;
9168
9169 afi = vpn_policy_getafi(vty, bgp, true);
9170 if (afi == AFI_MAX)
9171 return CMD_WARNING_CONFIG_FAILED;
9172
9173 bgp_default = bgp_get_default();
9174 if (!bgp_default) {
9175 int32_t ret;
9176 as_t as = bgp->as;
9177
9178 /* Auto-create assuming the same AS */
9179 ret = bgp_get_vty(&bgp_default, &as, NULL,
9180 BGP_INSTANCE_TYPE_DEFAULT);
9181
9182 if (ret) {
9183 vty_out(vty,
9184 "VRF default is not configured as a bgp instance\n");
9185 return CMD_WARNING;
9186 }
9187 }
9188
9189 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9190
9191 if (bgp->vpn_policy[afi].rmap_name[dir])
9192 XFREE(MTYPE_ROUTE_MAP_NAME,
9193 bgp->vpn_policy[afi].rmap_name[dir]);
9194 bgp->vpn_policy[afi].rmap_name[dir] =
9195 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9196 bgp->vpn_policy[afi].rmap[dir] =
9197 route_map_lookup_warn_noexist(vty, rmap_str);
9198 if (!bgp->vpn_policy[afi].rmap[dir])
9199 return CMD_SUCCESS;
9200
9201 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9202 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9203
9204 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9205
9206 return CMD_SUCCESS;
9207 }
9208
9209 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9210 "no import vrf route-map [RMAP$rmap_str]",
9211 NO_STR
9212 "Import routes from another VRF\n"
9213 "Vrf routes being filtered\n"
9214 "Specify route map\n"
9215 "name of route-map\n")
9216 {
9217 VTY_DECLVAR_CONTEXT(bgp, bgp);
9218 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9219 afi_t afi;
9220
9221 afi = vpn_policy_getafi(vty, bgp, true);
9222 if (afi == AFI_MAX)
9223 return CMD_WARNING_CONFIG_FAILED;
9224
9225 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9226
9227 if (bgp->vpn_policy[afi].rmap_name[dir])
9228 XFREE(MTYPE_ROUTE_MAP_NAME,
9229 bgp->vpn_policy[afi].rmap_name[dir]);
9230 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9231 bgp->vpn_policy[afi].rmap[dir] = NULL;
9232
9233 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9234 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9235 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9236
9237 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9238
9239 return CMD_SUCCESS;
9240 }
9241
9242 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9243 "[no] import vrf VIEWVRFNAME$import_name",
9244 NO_STR
9245 "Import routes from another VRF\n"
9246 "VRF to import from\n"
9247 "The name of the VRF\n")
9248 {
9249 VTY_DECLVAR_CONTEXT(bgp, bgp);
9250 struct listnode *node;
9251 struct bgp *vrf_bgp, *bgp_default;
9252 int32_t ret = 0;
9253 as_t as = bgp->as;
9254 bool remove = false;
9255 int32_t idx = 0;
9256 char *vname;
9257 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9258 safi_t safi;
9259 afi_t afi;
9260
9261 if (import_name == NULL) {
9262 vty_out(vty, "%% Missing import name\n");
9263 return CMD_WARNING;
9264 }
9265
9266 if (strcmp(import_name, "route-map") == 0) {
9267 vty_out(vty, "%% Must include route-map name\n");
9268 return CMD_WARNING;
9269 }
9270
9271 if (argv_find(argv, argc, "no", &idx))
9272 remove = true;
9273
9274 afi = vpn_policy_getafi(vty, bgp, true);
9275 if (afi == AFI_MAX)
9276 return CMD_WARNING_CONFIG_FAILED;
9277
9278 safi = bgp_node_safi(vty);
9279
9280 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9281 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9282 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9283 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9284 remove ? "unimport" : "import", import_name);
9285 return CMD_WARNING;
9286 }
9287
9288 bgp_default = bgp_get_default();
9289 if (!bgp_default) {
9290 /* Auto-create assuming the same AS */
9291 ret = bgp_get_vty(&bgp_default, &as, NULL,
9292 BGP_INSTANCE_TYPE_DEFAULT);
9293
9294 if (ret) {
9295 vty_out(vty,
9296 "VRF default is not configured as a bgp instance\n");
9297 return CMD_WARNING;
9298 }
9299 }
9300
9301 vrf_bgp = bgp_lookup_by_name(import_name);
9302 if (!vrf_bgp) {
9303 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9304 vrf_bgp = bgp_default;
9305 else
9306 /* Auto-create assuming the same AS */
9307 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9308
9309 if (ret) {
9310 vty_out(vty,
9311 "VRF %s is not configured as a bgp instance\n",
9312 import_name);
9313 return CMD_WARNING;
9314 }
9315 }
9316
9317 if (remove) {
9318 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9319 } else {
9320 /* Already importing from "import_vrf"? */
9321 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9322 vname)) {
9323 if (strcmp(vname, import_name) == 0)
9324 return CMD_WARNING;
9325 }
9326
9327 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9328 }
9329
9330 return CMD_SUCCESS;
9331 }
9332
9333 /* This command is valid only in a bgp vrf instance or the default instance */
9334 DEFPY (bgp_imexport_vpn,
9335 bgp_imexport_vpn_cmd,
9336 "[no] <import|export>$direction_str vpn",
9337 NO_STR
9338 "Import routes to this address-family\n"
9339 "Export routes from this address-family\n"
9340 "to/from default instance VPN RIB\n")
9341 {
9342 VTY_DECLVAR_CONTEXT(bgp, bgp);
9343 int previous_state;
9344 afi_t afi;
9345 safi_t safi;
9346 int idx = 0;
9347 bool yes = true;
9348 int flag;
9349 enum vpn_policy_direction dir;
9350
9351 if (argv_find(argv, argc, "no", &idx))
9352 yes = false;
9353
9354 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9355 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9356
9357 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9358 return CMD_WARNING_CONFIG_FAILED;
9359 }
9360
9361 afi = bgp_node_afi(vty);
9362 safi = bgp_node_safi(vty);
9363 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9364 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9365 return CMD_WARNING_CONFIG_FAILED;
9366 }
9367
9368 if (!strcmp(direction_str, "import")) {
9369 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9370 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9371 } else if (!strcmp(direction_str, "export")) {
9372 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9373 dir = BGP_VPN_POLICY_DIR_TOVPN;
9374 } else {
9375 vty_out(vty, "%% unknown direction %s\n", direction_str);
9376 return CMD_WARNING_CONFIG_FAILED;
9377 }
9378
9379 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9380
9381 if (yes) {
9382 SET_FLAG(bgp->af_flags[afi][safi], flag);
9383 if (!previous_state) {
9384 /* trigger export current vrf */
9385 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9386 }
9387 } else {
9388 if (previous_state) {
9389 /* trigger un-export current vrf */
9390 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9391 }
9392 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9393 }
9394
9395 hook_call(bgp_snmp_init_stats, bgp);
9396
9397 return CMD_SUCCESS;
9398 }
9399
9400 DEFPY (af_routetarget_import,
9401 af_routetarget_import_cmd,
9402 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9403 NO_STR
9404 "Specify route target list\n"
9405 "Specify route target list\n"
9406 "Specify route target list\n"
9407 "Specify route target list\n"
9408 "Flow-spec redirect type route target\n"
9409 "Import routes to this address-family\n"
9410 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9411 {
9412 VTY_DECLVAR_CONTEXT(bgp, bgp);
9413 int ret;
9414 struct ecommunity *ecom = NULL;
9415 afi_t afi;
9416 int idx = 0, idx_unused = 0;
9417 bool yes = true;
9418 bool rt6 = false;
9419
9420 if (argv_find(argv, argc, "no", &idx))
9421 yes = false;
9422
9423 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9424 argv_find(argv, argc, "route-target6", &idx_unused))
9425 rt6 = true;
9426
9427 afi = vpn_policy_getafi(vty, bgp, false);
9428 if (afi == AFI_MAX)
9429 return CMD_WARNING_CONFIG_FAILED;
9430
9431 if (rt6 && afi != AFI_IP6)
9432 return CMD_WARNING_CONFIG_FAILED;
9433
9434 if (yes) {
9435 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9436 vty_out(vty, "%% Missing RTLIST\n");
9437 return CMD_WARNING_CONFIG_FAILED;
9438 }
9439 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9440 if (ret != CMD_SUCCESS)
9441 return ret;
9442 }
9443
9444 if (yes) {
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 =
9449 ecommunity_dup(ecom);
9450 } else {
9451 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9452 ecommunity_free(&bgp->vpn_policy[afi]
9453 .import_redirect_rtlist);
9454 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9455 }
9456
9457 if (ecom)
9458 ecommunity_free(&ecom);
9459
9460 return CMD_SUCCESS;
9461 }
9462
9463 DEFUN_NOSH (address_family_ipv4_safi,
9464 address_family_ipv4_safi_cmd,
9465 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9466 "Enter Address Family command mode\n"
9467 BGP_AF_STR
9468 BGP_SAFI_WITH_LABEL_HELP_STR)
9469 {
9470
9471 if (argc == 3) {
9472 VTY_DECLVAR_CONTEXT(bgp, bgp);
9473 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9474 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9475 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9476 && safi != SAFI_EVPN) {
9477 vty_out(vty,
9478 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9479 return CMD_WARNING_CONFIG_FAILED;
9480 }
9481 vty->node = bgp_node_type(AFI_IP, safi);
9482 } else
9483 vty->node = BGP_IPV4_NODE;
9484
9485 return CMD_SUCCESS;
9486 }
9487
9488 DEFUN_NOSH (address_family_ipv6_safi,
9489 address_family_ipv6_safi_cmd,
9490 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9491 "Enter Address Family command mode\n"
9492 BGP_AF_STR
9493 BGP_SAFI_WITH_LABEL_HELP_STR)
9494 {
9495 if (argc == 3) {
9496 VTY_DECLVAR_CONTEXT(bgp, bgp);
9497 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9498 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9499 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9500 && safi != SAFI_EVPN) {
9501 vty_out(vty,
9502 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9503 return CMD_WARNING_CONFIG_FAILED;
9504 }
9505 vty->node = bgp_node_type(AFI_IP6, safi);
9506 } else
9507 vty->node = BGP_IPV6_NODE;
9508
9509 return CMD_SUCCESS;
9510 }
9511
9512 #ifdef KEEP_OLD_VPN_COMMANDS
9513 DEFUN_NOSH (address_family_vpnv4,
9514 address_family_vpnv4_cmd,
9515 "address-family vpnv4 [unicast]",
9516 "Enter Address Family command mode\n"
9517 BGP_AF_STR
9518 BGP_AF_MODIFIER_STR)
9519 {
9520 vty->node = BGP_VPNV4_NODE;
9521 return CMD_SUCCESS;
9522 }
9523
9524 DEFUN_NOSH (address_family_vpnv6,
9525 address_family_vpnv6_cmd,
9526 "address-family vpnv6 [unicast]",
9527 "Enter Address Family command mode\n"
9528 BGP_AF_STR
9529 BGP_AF_MODIFIER_STR)
9530 {
9531 vty->node = BGP_VPNV6_NODE;
9532 return CMD_SUCCESS;
9533 }
9534 #endif /* KEEP_OLD_VPN_COMMANDS */
9535
9536 DEFUN_NOSH (address_family_evpn,
9537 address_family_evpn_cmd,
9538 "address-family l2vpn evpn",
9539 "Enter Address Family command mode\n"
9540 BGP_AF_STR
9541 BGP_AF_MODIFIER_STR)
9542 {
9543 VTY_DECLVAR_CONTEXT(bgp, bgp);
9544 vty->node = BGP_EVPN_NODE;
9545 return CMD_SUCCESS;
9546 }
9547
9548 DEFUN_NOSH (bgp_segment_routing_srv6,
9549 bgp_segment_routing_srv6_cmd,
9550 "segment-routing srv6",
9551 "Segment-Routing configuration\n"
9552 "Segment-Routing SRv6 configuration\n")
9553 {
9554 VTY_DECLVAR_CONTEXT(bgp, bgp);
9555 bgp->srv6_enabled = true;
9556 vty->node = BGP_SRV6_NODE;
9557 return CMD_SUCCESS;
9558 }
9559
9560 DEFUN (no_bgp_segment_routing_srv6,
9561 no_bgp_segment_routing_srv6_cmd,
9562 "no segment-routing srv6",
9563 NO_STR
9564 "Segment-Routing configuration\n"
9565 "Segment-Routing SRv6 configuration\n")
9566 {
9567 VTY_DECLVAR_CONTEXT(bgp, bgp);
9568
9569 if (strlen(bgp->srv6_locator_name) > 0)
9570 if (bgp_srv6_locator_unset(bgp) < 0)
9571 return CMD_WARNING_CONFIG_FAILED;
9572
9573 bgp->srv6_enabled = false;
9574 return CMD_SUCCESS;
9575 }
9576
9577 DEFPY (bgp_srv6_locator,
9578 bgp_srv6_locator_cmd,
9579 "locator NAME$name",
9580 "Specify SRv6 locator\n"
9581 "Specify SRv6 locator\n")
9582 {
9583 VTY_DECLVAR_CONTEXT(bgp, bgp);
9584 int ret;
9585
9586 if (strlen(bgp->srv6_locator_name) > 0
9587 && strcmp(name, bgp->srv6_locator_name) != 0) {
9588 vty_out(vty, "srv6 locator is already configured\n");
9589 return CMD_WARNING_CONFIG_FAILED;
9590 }
9591
9592 snprintf(bgp->srv6_locator_name,
9593 sizeof(bgp->srv6_locator_name), "%s", name);
9594
9595 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9596 if (ret < 0)
9597 return CMD_WARNING_CONFIG_FAILED;
9598
9599 return CMD_SUCCESS;
9600 }
9601
9602 DEFPY (no_bgp_srv6_locator,
9603 no_bgp_srv6_locator_cmd,
9604 "no locator NAME$name",
9605 NO_STR
9606 "Specify SRv6 locator\n"
9607 "Specify SRv6 locator\n")
9608 {
9609 VTY_DECLVAR_CONTEXT(bgp, bgp);
9610
9611 /* when locator isn't configured, do nothing */
9612 if (strlen(bgp->srv6_locator_name) < 1)
9613 return CMD_SUCCESS;
9614
9615 /* name validation */
9616 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9617 vty_out(vty, "%% No srv6 locator is configured\n");
9618 return CMD_WARNING_CONFIG_FAILED;
9619 }
9620
9621 /* unset locator */
9622 if (bgp_srv6_locator_unset(bgp) < 0)
9623 return CMD_WARNING_CONFIG_FAILED;
9624
9625 return CMD_SUCCESS;
9626 }
9627
9628 DEFPY (show_bgp_srv6,
9629 show_bgp_srv6_cmd,
9630 "show bgp segment-routing srv6",
9631 SHOW_STR
9632 BGP_STR
9633 "BGP Segment Routing\n"
9634 "BGP Segment Routing SRv6\n")
9635 {
9636 struct bgp *bgp;
9637 struct listnode *node;
9638 struct srv6_locator_chunk *chunk;
9639 struct bgp_srv6_function *func;
9640 struct in6_addr *tovpn4_sid;
9641 struct in6_addr *tovpn6_sid;
9642 char buf[256];
9643 char buf_tovpn4_sid[256];
9644 char buf_tovpn6_sid[256];
9645
9646 bgp = bgp_get_default();
9647 if (!bgp)
9648 return CMD_SUCCESS;
9649
9650 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9651 vty_out(vty, "locator_chunks:\n");
9652 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk))
9653 vty_out(vty, "- %pFX\n", &chunk->prefix);
9654
9655 vty_out(vty, "functions:\n");
9656 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9657 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9658 vty_out(vty, "- sid: %s\n", buf);
9659 vty_out(vty, " locator: %s\n", func->locator_name);
9660 }
9661
9662 vty_out(vty, "bgps:\n");
9663 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9664 vty_out(vty, "- name: %s\n",
9665 bgp->name ? bgp->name : "default");
9666
9667 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9668 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9669 if (tovpn4_sid)
9670 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9671 sizeof(buf_tovpn4_sid));
9672 if (tovpn6_sid)
9673 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9674 sizeof(buf_tovpn6_sid));
9675
9676 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9677 tovpn4_sid ? buf_tovpn4_sid : "none");
9678 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9679 tovpn6_sid ? buf_tovpn6_sid : "none");
9680 }
9681
9682 return CMD_SUCCESS;
9683 }
9684
9685 DEFUN_NOSH (exit_address_family,
9686 exit_address_family_cmd,
9687 "exit-address-family",
9688 "Exit from Address Family configuration mode\n")
9689 {
9690 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9691 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9692 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9693 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9694 || vty->node == BGP_EVPN_NODE
9695 || vty->node == BGP_FLOWSPECV4_NODE
9696 || vty->node == BGP_FLOWSPECV6_NODE)
9697 vty->node = BGP_NODE;
9698 return CMD_SUCCESS;
9699 }
9700
9701 /* Recalculate bestpath and re-advertise a prefix */
9702 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9703 const char *ip_str, afi_t afi, safi_t safi,
9704 struct prefix_rd *prd)
9705 {
9706 int ret;
9707 struct prefix match;
9708 struct bgp_dest *dest;
9709 struct bgp_dest *rm;
9710 struct bgp *bgp;
9711 struct bgp_table *table;
9712 struct bgp_table *rib;
9713
9714 /* BGP structure lookup. */
9715 if (view_name) {
9716 bgp = bgp_lookup_by_name(view_name);
9717 if (bgp == NULL) {
9718 vty_out(vty, "%% Can't find BGP instance %s\n",
9719 view_name);
9720 return CMD_WARNING;
9721 }
9722 } else {
9723 bgp = bgp_get_default();
9724 if (bgp == NULL) {
9725 vty_out(vty, "%% No BGP process is configured\n");
9726 return CMD_WARNING;
9727 }
9728 }
9729
9730 /* Check IP address argument. */
9731 ret = str2prefix(ip_str, &match);
9732 if (!ret) {
9733 vty_out(vty, "%% address is malformed\n");
9734 return CMD_WARNING;
9735 }
9736
9737 match.family = afi2family(afi);
9738 rib = bgp->rib[afi][safi];
9739
9740 if (safi == SAFI_MPLS_VPN) {
9741 for (dest = bgp_table_top(rib); dest;
9742 dest = bgp_route_next(dest)) {
9743 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9744
9745 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9746 continue;
9747
9748 table = bgp_dest_get_bgp_table_info(dest);
9749 if (table == NULL)
9750 continue;
9751
9752 rm = bgp_node_match(table, &match);
9753 if (rm != NULL) {
9754 const struct prefix *rm_p =
9755 bgp_dest_get_prefix(rm);
9756
9757 if (rm_p->prefixlen == match.prefixlen) {
9758 SET_FLAG(rm->flags,
9759 BGP_NODE_USER_CLEAR);
9760 bgp_process(bgp, rm, afi, safi);
9761 }
9762 bgp_dest_unlock_node(rm);
9763 }
9764 }
9765 } else {
9766 dest = bgp_node_match(rib, &match);
9767 if (dest != NULL) {
9768 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9769
9770 if (dest_p->prefixlen == match.prefixlen) {
9771 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9772 bgp_process(bgp, dest, afi, safi);
9773 }
9774 bgp_dest_unlock_node(dest);
9775 }
9776 }
9777
9778 return CMD_SUCCESS;
9779 }
9780
9781 /* one clear bgp command to rule them all */
9782 DEFUN (clear_ip_bgp_all,
9783 clear_ip_bgp_all_cmd,
9784 "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>]",
9785 CLEAR_STR
9786 IP_STR
9787 BGP_STR
9788 BGP_INSTANCE_HELP_STR
9789 BGP_AFI_HELP_STR
9790 BGP_AF_STR
9791 BGP_SAFI_WITH_LABEL_HELP_STR
9792 BGP_AF_MODIFIER_STR
9793 "Clear all peers\n"
9794 "BGP IPv4 neighbor to clear\n"
9795 "BGP IPv6 neighbor to clear\n"
9796 "BGP neighbor on interface to clear\n"
9797 "Clear peers with the AS number\n"
9798 "Clear all external peers\n"
9799 "Clear all members of peer-group\n"
9800 "BGP peer-group name\n"
9801 BGP_SOFT_STR
9802 BGP_SOFT_IN_STR
9803 BGP_SOFT_OUT_STR
9804 BGP_SOFT_IN_STR
9805 "Push out prefix-list ORF and do inbound soft reconfig\n"
9806 BGP_SOFT_OUT_STR
9807 "Reset message statistics\n")
9808 {
9809 char *vrf = NULL;
9810
9811 afi_t afi = AFI_UNSPEC;
9812 safi_t safi = SAFI_UNSPEC;
9813 enum clear_sort clr_sort = clear_peer;
9814 enum bgp_clear_type clr_type;
9815 char *clr_arg = NULL;
9816
9817 int idx = 0;
9818
9819 /* clear [ip] bgp */
9820 if (argv_find(argv, argc, "ip", &idx))
9821 afi = AFI_IP;
9822
9823 /* [<vrf> VIEWVRFNAME] */
9824 if (argv_find(argv, argc, "vrf", &idx)) {
9825 vrf = argv[idx + 1]->arg;
9826 idx += 2;
9827 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9828 vrf = NULL;
9829 } else if (argv_find(argv, argc, "view", &idx)) {
9830 /* [<view> VIEWVRFNAME] */
9831 vrf = argv[idx + 1]->arg;
9832 idx += 2;
9833 }
9834 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9835 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9836 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9837
9838 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9839 if (argv_find(argv, argc, "*", &idx)) {
9840 clr_sort = clear_all;
9841 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9842 clr_sort = clear_peer;
9843 clr_arg = argv[idx]->arg;
9844 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9845 clr_sort = clear_peer;
9846 clr_arg = argv[idx]->arg;
9847 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9848 clr_sort = clear_group;
9849 idx++;
9850 clr_arg = argv[idx]->arg;
9851 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9852 clr_sort = clear_peer;
9853 clr_arg = argv[idx]->arg;
9854 } else if (argv_find(argv, argc, "WORD", &idx)) {
9855 clr_sort = clear_peer;
9856 clr_arg = argv[idx]->arg;
9857 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9858 clr_sort = clear_as;
9859 clr_arg = argv[idx]->arg;
9860 } else if (argv_find(argv, argc, "external", &idx)) {
9861 clr_sort = clear_external;
9862 }
9863
9864 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9865 if (argv_find(argv, argc, "soft", &idx)) {
9866 if (argv_find(argv, argc, "in", &idx)
9867 || argv_find(argv, argc, "out", &idx))
9868 clr_type = strmatch(argv[idx]->text, "in")
9869 ? BGP_CLEAR_SOFT_IN
9870 : BGP_CLEAR_SOFT_OUT;
9871 else
9872 clr_type = BGP_CLEAR_SOFT_BOTH;
9873 } else if (argv_find(argv, argc, "in", &idx)) {
9874 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9875 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9876 : BGP_CLEAR_SOFT_IN;
9877 } else if (argv_find(argv, argc, "out", &idx)) {
9878 clr_type = BGP_CLEAR_SOFT_OUT;
9879 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9880 clr_type = BGP_CLEAR_MESSAGE_STATS;
9881 } else
9882 clr_type = BGP_CLEAR_SOFT_NONE;
9883
9884 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9885 }
9886
9887 DEFUN (clear_ip_bgp_prefix,
9888 clear_ip_bgp_prefix_cmd,
9889 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9890 CLEAR_STR
9891 IP_STR
9892 BGP_STR
9893 BGP_INSTANCE_HELP_STR
9894 "Clear bestpath and re-advertise\n"
9895 "IPv4 prefix\n")
9896 {
9897 char *vrf = NULL;
9898 char *prefix = NULL;
9899
9900 int idx = 0;
9901
9902 /* [<view|vrf> VIEWVRFNAME] */
9903 if (argv_find(argv, argc, "vrf", &idx)) {
9904 vrf = argv[idx + 1]->arg;
9905 idx += 2;
9906 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9907 vrf = NULL;
9908 } else if (argv_find(argv, argc, "view", &idx)) {
9909 /* [<view> VIEWVRFNAME] */
9910 vrf = argv[idx + 1]->arg;
9911 idx += 2;
9912 }
9913
9914 prefix = argv[argc - 1]->arg;
9915
9916 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9917 }
9918
9919 DEFUN (clear_bgp_ipv6_safi_prefix,
9920 clear_bgp_ipv6_safi_prefix_cmd,
9921 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9922 CLEAR_STR
9923 IP_STR
9924 BGP_STR
9925 BGP_AF_STR
9926 BGP_SAFI_HELP_STR
9927 "Clear bestpath and re-advertise\n"
9928 "IPv6 prefix\n")
9929 {
9930 int idx_safi = 0;
9931 int idx_ipv6_prefix = 0;
9932 safi_t safi = SAFI_UNICAST;
9933 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9934 argv[idx_ipv6_prefix]->arg : NULL;
9935
9936 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9937 return bgp_clear_prefix(
9938 vty, NULL, prefix, AFI_IP6,
9939 safi, NULL);
9940 }
9941
9942 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9943 clear_bgp_instance_ipv6_safi_prefix_cmd,
9944 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9945 CLEAR_STR
9946 IP_STR
9947 BGP_STR
9948 BGP_INSTANCE_HELP_STR
9949 BGP_AF_STR
9950 BGP_SAFI_HELP_STR
9951 "Clear bestpath and re-advertise\n"
9952 "IPv6 prefix\n")
9953 {
9954 int idx_safi = 0;
9955 int idx_vrfview = 0;
9956 int idx_ipv6_prefix = 0;
9957 safi_t safi = SAFI_UNICAST;
9958 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9959 argv[idx_ipv6_prefix]->arg : NULL;
9960 char *vrfview = NULL;
9961
9962 /* [<view|vrf> VIEWVRFNAME] */
9963 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9964 vrfview = argv[idx_vrfview + 1]->arg;
9965 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9966 vrfview = NULL;
9967 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9968 /* [<view> VIEWVRFNAME] */
9969 vrfview = argv[idx_vrfview + 1]->arg;
9970 }
9971 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9972
9973 return bgp_clear_prefix(
9974 vty, vrfview, prefix,
9975 AFI_IP6, safi, NULL);
9976 }
9977
9978 DEFUN (show_bgp_views,
9979 show_bgp_views_cmd,
9980 "show [ip] bgp views",
9981 SHOW_STR
9982 IP_STR
9983 BGP_STR
9984 "Show the defined BGP views\n")
9985 {
9986 struct list *inst = bm->bgp;
9987 struct listnode *node;
9988 struct bgp *bgp;
9989
9990 vty_out(vty, "Defined BGP views:\n");
9991 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9992 /* Skip VRFs. */
9993 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9994 continue;
9995 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9996 bgp->as);
9997 }
9998
9999 return CMD_SUCCESS;
10000 }
10001
10002 DEFUN (show_bgp_vrfs,
10003 show_bgp_vrfs_cmd,
10004 "show [ip] bgp vrfs [json]",
10005 SHOW_STR
10006 IP_STR
10007 BGP_STR
10008 "Show BGP VRFs\n"
10009 JSON_STR)
10010 {
10011 char buf[ETHER_ADDR_STRLEN];
10012 struct list *inst = bm->bgp;
10013 struct listnode *node;
10014 struct bgp *bgp;
10015 bool uj = use_json(argc, argv);
10016 json_object *json = NULL;
10017 json_object *json_vrfs = NULL;
10018 int count = 0;
10019
10020 if (uj) {
10021 json = json_object_new_object();
10022 json_vrfs = json_object_new_object();
10023 }
10024
10025 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10026 const char *name, *type;
10027 struct peer *peer;
10028 struct listnode *node2, *nnode2;
10029 int peers_cfg, peers_estb;
10030 json_object *json_vrf = NULL;
10031
10032 /* Skip Views. */
10033 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10034 continue;
10035
10036 count++;
10037 if (!uj && count == 1) {
10038 vty_out(vty,
10039 "%4s %-5s %-16s %9s %10s %-37s\n",
10040 "Type", "Id", "routerId", "#PeersCfg",
10041 "#PeersEstb", "Name");
10042 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10043 "L3-VNI", "RouterMAC", "Interface");
10044 }
10045
10046 peers_cfg = peers_estb = 0;
10047 if (uj)
10048 json_vrf = json_object_new_object();
10049
10050
10051 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10052 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10053 continue;
10054 peers_cfg++;
10055 if (peer_established(peer))
10056 peers_estb++;
10057 }
10058
10059 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10060 name = VRF_DEFAULT_NAME;
10061 type = "DFLT";
10062 } else {
10063 name = bgp->name;
10064 type = "VRF";
10065 }
10066
10067
10068 if (uj) {
10069 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10070 ? -1
10071 : (int64_t)bgp->vrf_id;
10072 char buf[BUFSIZ] = {0};
10073
10074 json_object_string_add(json_vrf, "type", type);
10075 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10076 json_object_string_addf(json_vrf, "routerId", "%pI4",
10077 &bgp->router_id);
10078 json_object_int_add(json_vrf, "numConfiguredPeers",
10079 peers_cfg);
10080 json_object_int_add(json_vrf, "numEstablishedPeers",
10081 peers_estb);
10082
10083 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10084 json_object_string_add(
10085 json_vrf, "rmac",
10086 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10087 json_object_string_add(json_vrf, "interface",
10088 ifindex2ifname(bgp->l3vni_svi_ifindex,
10089 bgp->vrf_id));
10090 json_object_object_add(json_vrfs, name, json_vrf);
10091 } else {
10092 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10093 type,
10094 bgp->vrf_id == VRF_UNKNOWN ? -1
10095 : (int)bgp->vrf_id,
10096 &bgp->router_id, peers_cfg, peers_estb, name);
10097 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10098 bgp->l3vni,
10099 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10100 ifindex2ifname(bgp->l3vni_svi_ifindex,
10101 bgp->vrf_id));
10102 }
10103 }
10104
10105 if (uj) {
10106 json_object_object_add(json, "vrfs", json_vrfs);
10107
10108 json_object_int_add(json, "totalVrfs", count);
10109
10110 vty_json(vty, json);
10111 } else {
10112 if (count)
10113 vty_out(vty,
10114 "\nTotal number of VRFs (including default): %d\n",
10115 count);
10116 }
10117
10118 return CMD_SUCCESS;
10119 }
10120
10121 DEFUN (show_bgp_mac_hash,
10122 show_bgp_mac_hash_cmd,
10123 "show bgp mac hash",
10124 SHOW_STR
10125 BGP_STR
10126 "Mac Address\n"
10127 "Mac Address database\n")
10128 {
10129 bgp_mac_dump_table(vty);
10130
10131 return CMD_SUCCESS;
10132 }
10133
10134 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10135 {
10136 struct vty *vty = (struct vty *)args;
10137 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10138
10139 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10140 }
10141
10142 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10143 {
10144 vty_out(vty, "self nexthop database:\n");
10145 bgp_nexthop_show_address_hash(vty, bgp);
10146
10147 vty_out(vty, "Tunnel-ip database:\n");
10148 hash_iterate(bgp->tip_hash,
10149 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10150 vty);
10151 }
10152
10153 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10154 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10155 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10156 "martian next-hops\n"
10157 "martian next-hop database\n")
10158 {
10159 struct bgp *bgp = NULL;
10160 int idx = 0;
10161 char *name = NULL;
10162
10163 /* [<vrf> VIEWVRFNAME] */
10164 if (argv_find(argv, argc, "vrf", &idx)) {
10165 name = argv[idx + 1]->arg;
10166 if (name && strmatch(name, VRF_DEFAULT_NAME))
10167 name = NULL;
10168 } else if (argv_find(argv, argc, "view", &idx))
10169 /* [<view> VIEWVRFNAME] */
10170 name = argv[idx + 1]->arg;
10171 if (name)
10172 bgp = bgp_lookup_by_name(name);
10173 else
10174 bgp = bgp_get_default();
10175
10176 if (!bgp) {
10177 vty_out(vty, "%% No BGP process is configured\n");
10178 return CMD_WARNING;
10179 }
10180 bgp_show_martian_nexthops(vty, bgp);
10181
10182 return CMD_SUCCESS;
10183 }
10184
10185 DEFUN (show_bgp_memory,
10186 show_bgp_memory_cmd,
10187 "show [ip] bgp memory",
10188 SHOW_STR
10189 IP_STR
10190 BGP_STR
10191 "Global BGP memory statistics\n")
10192 {
10193 char memstrbuf[MTYPE_MEMSTR_LEN];
10194 unsigned long count;
10195
10196 /* RIB related usage stats */
10197 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10198 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10199 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10200 count * sizeof(struct bgp_dest)));
10201
10202 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10203 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10204 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10205 count * sizeof(struct bgp_path_info)));
10206 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10207 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10208 count,
10209 mtype_memstr(
10210 memstrbuf, sizeof(memstrbuf),
10211 count * sizeof(struct bgp_path_info_extra)));
10212
10213 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10214 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10215 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10216 count * sizeof(struct bgp_static)));
10217
10218 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10219 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10220 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10221 count * sizeof(struct bpacket)));
10222
10223 /* Adj-In/Out */
10224 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10225 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10226 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10227 count * sizeof(struct bgp_adj_in)));
10228 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10229 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10230 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10231 count * sizeof(struct bgp_adj_out)));
10232
10233 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10234 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10235 count,
10236 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10237 count * sizeof(struct bgp_nexthop_cache)));
10238
10239 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10240 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10241 count,
10242 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10243 count * sizeof(struct bgp_damp_info)));
10244
10245 /* Attributes */
10246 count = attr_count();
10247 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10248 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10249 count * sizeof(struct attr)));
10250
10251 if ((count = attr_unknown_count()))
10252 vty_out(vty, "%ld unknown attributes\n", count);
10253
10254 /* AS_PATH attributes */
10255 count = aspath_count();
10256 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10257 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10258 count * sizeof(struct aspath)));
10259
10260 count = mtype_stats_alloc(MTYPE_AS_SEG);
10261 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10262 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10263 count * sizeof(struct assegment)));
10264
10265 /* Other attributes */
10266 if ((count = community_count()))
10267 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10268 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10269 count * sizeof(struct community)));
10270 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10271 vty_out(vty,
10272 "%ld BGP ext-community entries, using %s of memory\n",
10273 count,
10274 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10275 count * sizeof(struct ecommunity)));
10276 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10277 vty_out(vty,
10278 "%ld BGP large-community entries, using %s of memory\n",
10279 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10280 count * sizeof(struct lcommunity)));
10281
10282 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10283 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10284 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10285 count * sizeof(struct cluster_list)));
10286
10287 /* Peer related usage */
10288 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10289 vty_out(vty, "%ld peers, using %s of memory\n", count,
10290 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10291 count * sizeof(struct peer)));
10292
10293 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10294 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10295 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10296 count * sizeof(struct peer_group)));
10297
10298 /* Other */
10299 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10300 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10301 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10302 count * sizeof(regex_t)));
10303 return CMD_SUCCESS;
10304 }
10305
10306 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10307 {
10308 json_object *bestpath = json_object_new_object();
10309
10310 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10311 json_object_string_add(bestpath, "asPath", "ignore");
10312
10313 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10314 json_object_string_add(bestpath, "asPath", "confed");
10315
10316 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10317 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10318 json_object_string_add(bestpath, "multiPathRelax",
10319 "as-set");
10320 else
10321 json_object_string_add(bestpath, "multiPathRelax",
10322 "true");
10323 } else
10324 json_object_string_add(bestpath, "multiPathRelax", "false");
10325
10326 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10327 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10328
10329 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10330 json_object_string_add(bestpath, "compareRouterId", "true");
10331 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10332 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10333 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10334 json_object_string_add(bestpath, "med", "confed");
10335 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10336 json_object_string_add(bestpath, "med",
10337 "missing-as-worst");
10338 else
10339 json_object_string_add(bestpath, "med", "true");
10340 }
10341
10342 json_object_object_add(json, "bestPath", bestpath);
10343 }
10344
10345 /* Print the error code/subcode for why the peer is down */
10346 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10347 json_object *json_peer, bool use_json)
10348 {
10349 const char *code_str;
10350 const char *subcode_str;
10351
10352 if (use_json) {
10353 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10354 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10355 char errorcodesubcode_hexstr[5];
10356 char errorcodesubcode_str[256];
10357
10358 code_str = bgp_notify_code_str(peer->notify.code);
10359 subcode_str = bgp_notify_subcode_str(
10360 peer->notify.code,
10361 peer->notify.subcode);
10362
10363 snprintf(errorcodesubcode_hexstr,
10364 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10365 peer->notify.code, peer->notify.subcode);
10366 json_object_string_add(json_peer,
10367 "lastErrorCodeSubcode",
10368 errorcodesubcode_hexstr);
10369 snprintf(errorcodesubcode_str, 255, "%s%s",
10370 code_str, subcode_str);
10371 json_object_string_add(json_peer,
10372 "lastNotificationReason",
10373 errorcodesubcode_str);
10374 json_object_boolean_add(json_peer,
10375 "lastNotificationHardReset",
10376 peer->notify.hard_reset);
10377 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10378 && peer->notify.code == BGP_NOTIFY_CEASE
10379 && (peer->notify.subcode
10380 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10381 || peer->notify.subcode
10382 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10383 && peer->notify.length) {
10384 char msgbuf[1024];
10385 const char *msg_str;
10386
10387 msg_str = bgp_notify_admin_message(
10388 msgbuf, sizeof(msgbuf),
10389 (uint8_t *)peer->notify.data,
10390 peer->notify.length);
10391 if (msg_str)
10392 json_object_string_add(
10393 json_peer,
10394 "lastShutdownDescription",
10395 msg_str);
10396 }
10397
10398 }
10399 json_object_string_add(json_peer, "lastResetDueTo",
10400 peer_down_str[(int)peer->last_reset]);
10401 json_object_int_add(json_peer, "lastResetCode",
10402 peer->last_reset);
10403 } else {
10404 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10405 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10406 code_str = bgp_notify_code_str(peer->notify.code);
10407 subcode_str =
10408 bgp_notify_subcode_str(peer->notify.code,
10409 peer->notify.subcode);
10410 vty_out(vty, " Notification %s (%s%s%s)\n",
10411 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10412 ? "sent"
10413 : "received",
10414 code_str, subcode_str,
10415 peer->notify.hard_reset
10416 ? bgp_notify_subcode_str(
10417 BGP_NOTIFY_CEASE,
10418 BGP_NOTIFY_CEASE_HARD_RESET)
10419 : "");
10420 } else {
10421 vty_out(vty, " %s\n",
10422 peer_down_str[(int)peer->last_reset]);
10423 }
10424 }
10425 }
10426
10427 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10428 safi_t safi)
10429 {
10430 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10431 }
10432
10433 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10434 struct peer *peer, json_object *json_peer,
10435 int max_neighbor_width, bool use_json)
10436 {
10437 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10438 int len;
10439
10440 if (use_json) {
10441 if (peer_dynamic_neighbor(peer))
10442 json_object_boolean_true_add(json_peer,
10443 "dynamicPeer");
10444 if (peer->hostname)
10445 json_object_string_add(json_peer, "hostname",
10446 peer->hostname);
10447
10448 if (peer->domainname)
10449 json_object_string_add(json_peer, "domainname",
10450 peer->domainname);
10451 json_object_int_add(json_peer, "connectionsEstablished",
10452 peer->established);
10453 json_object_int_add(json_peer, "connectionsDropped",
10454 peer->dropped);
10455 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10456 use_json, json_peer);
10457 if (peer_established(peer))
10458 json_object_string_add(json_peer, "lastResetDueTo",
10459 "AFI/SAFI Not Negotiated");
10460 else
10461 bgp_show_peer_reset(NULL, peer, json_peer, true);
10462 } else {
10463 dn_flag[1] = '\0';
10464 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10465 if (peer->hostname
10466 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10467 len = vty_out(vty, "%s%s(%s)", dn_flag,
10468 peer->hostname, peer->host);
10469 else
10470 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10471
10472 /* pad the neighbor column with spaces */
10473 if (len < max_neighbor_width)
10474 vty_out(vty, "%*s", max_neighbor_width - len,
10475 " ");
10476 vty_out(vty, "%7d %7d %9s", peer->established,
10477 peer->dropped,
10478 peer_uptime(peer->uptime, timebuf,
10479 BGP_UPTIME_LEN, 0, NULL));
10480 if (peer_established(peer))
10481 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10482 else
10483 bgp_show_peer_reset(vty, peer, NULL,
10484 false);
10485 }
10486 }
10487
10488 /* Strip peer's description to the given size. */
10489 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10490 {
10491 static char stripped[BUFSIZ];
10492 uint32_t i = 0;
10493 uint32_t last_space = 0;
10494
10495 while (i < size) {
10496 if (*(desc + i) == 0) {
10497 stripped[i] = '\0';
10498 return stripped;
10499 }
10500 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10501 last_space = i;
10502 stripped[i] = *(desc + i);
10503 i++;
10504 }
10505
10506 if (last_space > size)
10507 stripped[size + 1] = '\0';
10508 else
10509 stripped[last_space] = '\0';
10510
10511 return stripped;
10512 }
10513
10514 /* Determine whether var peer should be filtered out of the summary. */
10515 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10516 struct peer *fpeer, int as_type,
10517 as_t as)
10518 {
10519
10520 /* filter neighbor XXXX */
10521 if (fpeer && fpeer != peer)
10522 return true;
10523
10524 /* filter remote-as (internal|external) */
10525 if (as_type != AS_UNSPECIFIED) {
10526 if (peer->as_type == AS_SPECIFIED) {
10527 if (as_type == AS_INTERNAL) {
10528 if (peer->as != peer->local_as)
10529 return true;
10530 } else if (peer->as == peer->local_as)
10531 return true;
10532 } else if (as_type != peer->as_type)
10533 return true;
10534 } else if (as && as != peer->as) /* filter remote-as XXX */
10535 return true;
10536
10537 return false;
10538 }
10539
10540 /* Show BGP peer's summary information.
10541 *
10542 * Peer's description is stripped according to if `wide` option is given
10543 * or not.
10544 *
10545 * When adding new columns to `show bgp summary` output, please make
10546 * sure `Desc` is the lastest column to show because it can contain
10547 * whitespaces and the whole output will be tricky.
10548 */
10549 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10550 struct peer *fpeer, int as_type, as_t as,
10551 uint16_t show_flags)
10552 {
10553 struct peer *peer;
10554 struct listnode *node, *nnode;
10555 unsigned int count = 0, dn_count = 0;
10556 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10557 char neighbor_buf[VTY_BUFSIZ];
10558 int neighbor_col_default_width = 16;
10559 int len, failed_count = 0;
10560 unsigned int filtered_count = 0;
10561 int max_neighbor_width = 0;
10562 int pfx_rcd_safi;
10563 json_object *json = NULL;
10564 json_object *json_peer = NULL;
10565 json_object *json_peers = NULL;
10566 struct peer_af *paf;
10567 struct bgp_filter *filter;
10568 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10569 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10570 bool show_established =
10571 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10572 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10573 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10574
10575 /* labeled-unicast routes are installed in the unicast table so in order
10576 * to
10577 * display the correct PfxRcd value we must look at SAFI_UNICAST
10578 */
10579
10580 if (safi == SAFI_LABELED_UNICAST)
10581 pfx_rcd_safi = SAFI_UNICAST;
10582 else
10583 pfx_rcd_safi = safi;
10584
10585 if (use_json) {
10586 json = json_object_new_object();
10587 json_peers = json_object_new_object();
10588 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10589 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10590 as_type, as)) {
10591 filtered_count++;
10592 count++;
10593 continue;
10594 }
10595
10596 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10597 continue;
10598
10599 if (peer->afc[afi][safi]) {
10600 /* See if we have at least a single failed peer */
10601 if (bgp_has_peer_failed(peer, afi, safi))
10602 failed_count++;
10603 count++;
10604 }
10605 if (peer_dynamic_neighbor(peer))
10606 dn_count++;
10607 }
10608
10609 } else {
10610 /* Loop over all neighbors that will be displayed to determine
10611 * how many
10612 * characters are needed for the Neighbor column
10613 */
10614 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10615 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10616 as_type, as)) {
10617 filtered_count++;
10618 count++;
10619 continue;
10620 }
10621
10622 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10623 continue;
10624
10625 if (peer->afc[afi][safi]) {
10626 memset(dn_flag, '\0', sizeof(dn_flag));
10627 if (peer_dynamic_neighbor(peer))
10628 dn_flag[0] = '*';
10629
10630 if (peer->hostname
10631 && CHECK_FLAG(bgp->flags,
10632 BGP_FLAG_SHOW_HOSTNAME))
10633 snprintf(neighbor_buf,
10634 sizeof(neighbor_buf),
10635 "%s%s(%s) ", dn_flag,
10636 peer->hostname, peer->host);
10637 else
10638 snprintf(neighbor_buf,
10639 sizeof(neighbor_buf), "%s%s ",
10640 dn_flag, peer->host);
10641
10642 len = strlen(neighbor_buf);
10643
10644 if (len > max_neighbor_width)
10645 max_neighbor_width = len;
10646
10647 /* See if we have at least a single failed peer */
10648 if (bgp_has_peer_failed(peer, afi, safi))
10649 failed_count++;
10650 count++;
10651 }
10652 }
10653
10654 /* Originally we displayed the Neighbor column as 16
10655 * characters wide so make that the default
10656 */
10657 if (max_neighbor_width < neighbor_col_default_width)
10658 max_neighbor_width = neighbor_col_default_width;
10659 }
10660
10661 if (show_failed && !failed_count) {
10662 if (use_json) {
10663 json_object_int_add(json, "failedPeersCount", 0);
10664 json_object_int_add(json, "dynamicPeers", dn_count);
10665 json_object_int_add(json, "totalPeers", count);
10666
10667 vty_json(vty, json);
10668 } else {
10669 vty_out(vty, "%% No failed BGP neighbors found\n");
10670 }
10671 return CMD_SUCCESS;
10672 }
10673
10674 count = 0; /* Reset the value as its used again */
10675 filtered_count = 0;
10676 dn_count = 0;
10677 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10678 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10679 continue;
10680
10681 if (!peer->afc[afi][safi])
10682 continue;
10683
10684 if (!count) {
10685 unsigned long ents;
10686 char memstrbuf[MTYPE_MEMSTR_LEN];
10687 int64_t vrf_id_ui;
10688
10689 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10690 ? -1
10691 : (int64_t)bgp->vrf_id;
10692
10693 /* Usage summary and header */
10694 if (use_json) {
10695 json_object_string_addf(json, "routerId",
10696 "%pI4",
10697 &bgp->router_id);
10698 json_object_int_add(json, "as", bgp->as);
10699 json_object_int_add(json, "vrfId", vrf_id_ui);
10700 json_object_string_add(
10701 json, "vrfName",
10702 (bgp->inst_type
10703 == BGP_INSTANCE_TYPE_DEFAULT)
10704 ? VRF_DEFAULT_NAME
10705 : bgp->name);
10706 } else {
10707 vty_out(vty,
10708 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10709 &bgp->router_id, bgp->as,
10710 bgp->vrf_id == VRF_UNKNOWN
10711 ? -1
10712 : (int)bgp->vrf_id);
10713 vty_out(vty, "\n");
10714 }
10715
10716 if (bgp_update_delay_configured(bgp)) {
10717 if (use_json) {
10718 json_object_int_add(
10719 json, "updateDelayLimit",
10720 bgp->v_update_delay);
10721
10722 if (bgp->v_update_delay
10723 != bgp->v_establish_wait)
10724 json_object_int_add(
10725 json,
10726 "updateDelayEstablishWait",
10727 bgp->v_establish_wait);
10728
10729 if (bgp_update_delay_active(bgp)) {
10730 json_object_string_add(
10731 json,
10732 "updateDelayFirstNeighbor",
10733 bgp->update_delay_begin_time);
10734 json_object_boolean_true_add(
10735 json,
10736 "updateDelayInProgress");
10737 } else {
10738 if (bgp->update_delay_over) {
10739 json_object_string_add(
10740 json,
10741 "updateDelayFirstNeighbor",
10742 bgp->update_delay_begin_time);
10743 json_object_string_add(
10744 json,
10745 "updateDelayBestpathResumed",
10746 bgp->update_delay_end_time);
10747 json_object_string_add(
10748 json,
10749 "updateDelayZebraUpdateResume",
10750 bgp->update_delay_zebra_resume_time);
10751 json_object_string_add(
10752 json,
10753 "updateDelayPeerUpdateResume",
10754 bgp->update_delay_peers_resume_time);
10755 }
10756 }
10757 } else {
10758 vty_out(vty,
10759 "Read-only mode update-delay limit: %d seconds\n",
10760 bgp->v_update_delay);
10761 if (bgp->v_update_delay
10762 != bgp->v_establish_wait)
10763 vty_out(vty,
10764 " Establish wait: %d seconds\n",
10765 bgp->v_establish_wait);
10766
10767 if (bgp_update_delay_active(bgp)) {
10768 vty_out(vty,
10769 " First neighbor established: %s\n",
10770 bgp->update_delay_begin_time);
10771 vty_out(vty,
10772 " Delay in progress\n");
10773 } else {
10774 if (bgp->update_delay_over) {
10775 vty_out(vty,
10776 " First neighbor established: %s\n",
10777 bgp->update_delay_begin_time);
10778 vty_out(vty,
10779 " Best-paths resumed: %s\n",
10780 bgp->update_delay_end_time);
10781 vty_out(vty,
10782 " zebra update resumed: %s\n",
10783 bgp->update_delay_zebra_resume_time);
10784 vty_out(vty,
10785 " peers update resumed: %s\n",
10786 bgp->update_delay_peers_resume_time);
10787 }
10788 }
10789 }
10790 }
10791
10792 if (use_json) {
10793 if (bgp_maxmed_onstartup_configured(bgp)
10794 && bgp->maxmed_active)
10795 json_object_boolean_true_add(
10796 json, "maxMedOnStartup");
10797 if (bgp->v_maxmed_admin)
10798 json_object_boolean_true_add(
10799 json, "maxMedAdministrative");
10800
10801 json_object_int_add(
10802 json, "tableVersion",
10803 bgp_table_version(bgp->rib[afi][safi]));
10804
10805 ents = bgp_table_count(bgp->rib[afi][safi]);
10806 json_object_int_add(json, "ribCount", ents);
10807 json_object_int_add(
10808 json, "ribMemory",
10809 ents * sizeof(struct bgp_dest));
10810
10811 ents = bgp->af_peer_count[afi][safi];
10812 json_object_int_add(json, "peerCount", ents);
10813 json_object_int_add(json, "peerMemory",
10814 ents * sizeof(struct peer));
10815
10816 if ((ents = listcount(bgp->group))) {
10817 json_object_int_add(
10818 json, "peerGroupCount", ents);
10819 json_object_int_add(
10820 json, "peerGroupMemory",
10821 ents * sizeof(struct
10822 peer_group));
10823 }
10824
10825 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10826 BGP_CONFIG_DAMPENING))
10827 json_object_boolean_true_add(
10828 json, "dampeningEnabled");
10829 } else {
10830 if (!show_terse) {
10831 if (bgp_maxmed_onstartup_configured(bgp)
10832 && bgp->maxmed_active)
10833 vty_out(vty,
10834 "Max-med on-startup active\n");
10835 if (bgp->v_maxmed_admin)
10836 vty_out(vty,
10837 "Max-med administrative active\n");
10838
10839 vty_out(vty,
10840 "BGP table version %" PRIu64
10841 "\n",
10842 bgp_table_version(
10843 bgp->rib[afi][safi]));
10844
10845 ents = bgp_table_count(
10846 bgp->rib[afi][safi]);
10847 vty_out(vty,
10848 "RIB entries %ld, using %s of memory\n",
10849 ents,
10850 mtype_memstr(
10851 memstrbuf,
10852 sizeof(memstrbuf),
10853 ents
10854 * sizeof(
10855 struct
10856 bgp_dest)));
10857
10858 /* Peer related usage */
10859 ents = bgp->af_peer_count[afi][safi];
10860 vty_out(vty,
10861 "Peers %ld, using %s of memory\n",
10862 ents,
10863 mtype_memstr(
10864 memstrbuf,
10865 sizeof(memstrbuf),
10866 ents
10867 * sizeof(
10868 struct
10869 peer)));
10870
10871 if ((ents = listcount(bgp->group)))
10872 vty_out(vty,
10873 "Peer groups %ld, using %s of memory\n",
10874 ents,
10875 mtype_memstr(
10876 memstrbuf,
10877 sizeof(memstrbuf),
10878 ents
10879 * sizeof(
10880 struct
10881 peer_group)));
10882
10883 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10884 BGP_CONFIG_DAMPENING))
10885 vty_out(vty,
10886 "Dampening enabled.\n");
10887 }
10888 if (show_failed) {
10889 vty_out(vty, "\n");
10890
10891 /* Subtract 8 here because 'Neighbor' is
10892 * 8 characters */
10893 vty_out(vty, "Neighbor");
10894 vty_out(vty, "%*s",
10895 max_neighbor_width - 8, " ");
10896 vty_out(vty,
10897 BGP_SHOW_SUMMARY_HEADER_FAILED);
10898 }
10899 }
10900 }
10901
10902 paf = peer_af_find(peer, afi, safi);
10903 filter = &peer->filter[afi][safi];
10904
10905 count++;
10906 /* Works for both failed & successful cases */
10907 if (peer_dynamic_neighbor(peer))
10908 dn_count++;
10909
10910 if (use_json) {
10911 json_peer = NULL;
10912 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10913 as_type, as)) {
10914 filtered_count++;
10915 continue;
10916 }
10917 if (show_failed &&
10918 bgp_has_peer_failed(peer, afi, safi)) {
10919 json_peer = json_object_new_object();
10920 bgp_show_failed_summary(vty, bgp, peer,
10921 json_peer, 0, use_json);
10922 } else if (!show_failed) {
10923 if (show_established
10924 && bgp_has_peer_failed(peer, afi, safi)) {
10925 filtered_count++;
10926 continue;
10927 }
10928
10929 json_peer = json_object_new_object();
10930 if (peer_dynamic_neighbor(peer)) {
10931 json_object_boolean_true_add(json_peer,
10932 "dynamicPeer");
10933 }
10934
10935 if (peer->hostname)
10936 json_object_string_add(json_peer, "hostname",
10937 peer->hostname);
10938
10939 if (peer->domainname)
10940 json_object_string_add(json_peer, "domainname",
10941 peer->domainname);
10942
10943 json_object_int_add(json_peer, "remoteAs", peer->as);
10944 json_object_int_add(
10945 json_peer, "localAs",
10946 peer->change_local_as
10947 ? peer->change_local_as
10948 : peer->local_as);
10949 json_object_int_add(json_peer, "version", 4);
10950 json_object_int_add(json_peer, "msgRcvd",
10951 PEER_TOTAL_RX(peer));
10952 json_object_int_add(json_peer, "msgSent",
10953 PEER_TOTAL_TX(peer));
10954
10955 atomic_size_t outq_count, inq_count;
10956 outq_count = atomic_load_explicit(
10957 &peer->obuf->count,
10958 memory_order_relaxed);
10959 inq_count = atomic_load_explicit(
10960 &peer->ibuf->count,
10961 memory_order_relaxed);
10962
10963 json_object_int_add(json_peer, "tableVersion",
10964 peer->version[afi][safi]);
10965 json_object_int_add(json_peer, "outq",
10966 outq_count);
10967 json_object_int_add(json_peer, "inq",
10968 inq_count);
10969 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10970 use_json, json_peer);
10971
10972 json_object_int_add(json_peer, "pfxRcd",
10973 peer->pcount[afi][pfx_rcd_safi]);
10974
10975 if (paf && PAF_SUBGRP(paf))
10976 json_object_int_add(
10977 json_peer, "pfxSnt",
10978 (PAF_SUBGRP(paf))->scount);
10979 else
10980 json_object_int_add(json_peer, "pfxSnt",
10981 0);
10982
10983 /* BGP FSM state */
10984 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10985 || CHECK_FLAG(peer->bgp->flags,
10986 BGP_FLAG_SHUTDOWN))
10987 json_object_string_add(json_peer,
10988 "state",
10989 "Idle (Admin)");
10990 else if (peer->afc_recv[afi][safi])
10991 json_object_string_add(
10992 json_peer, "state",
10993 lookup_msg(bgp_status_msg,
10994 peer->status, NULL));
10995 else if (CHECK_FLAG(
10996 peer->sflags,
10997 PEER_STATUS_PREFIX_OVERFLOW))
10998 json_object_string_add(json_peer,
10999 "state",
11000 "Idle (PfxCt)");
11001 else
11002 json_object_string_add(
11003 json_peer, "state",
11004 lookup_msg(bgp_status_msg,
11005 peer->status, NULL));
11006
11007 /* BGP peer state */
11008 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11009 || CHECK_FLAG(peer->bgp->flags,
11010 BGP_FLAG_SHUTDOWN))
11011 json_object_string_add(json_peer,
11012 "peerState",
11013 "Admin");
11014 else if (CHECK_FLAG(
11015 peer->sflags,
11016 PEER_STATUS_PREFIX_OVERFLOW))
11017 json_object_string_add(json_peer,
11018 "peerState",
11019 "PfxCt");
11020 else if (CHECK_FLAG(peer->flags,
11021 PEER_FLAG_PASSIVE))
11022 json_object_string_add(json_peer,
11023 "peerState",
11024 "Passive");
11025 else if (CHECK_FLAG(peer->sflags,
11026 PEER_STATUS_NSF_WAIT))
11027 json_object_string_add(json_peer,
11028 "peerState",
11029 "NSF passive");
11030 else if (CHECK_FLAG(
11031 peer->bgp->flags,
11032 BGP_FLAG_EBGP_REQUIRES_POLICY)
11033 && (!bgp_inbound_policy_exists(peer,
11034 filter)
11035 || !bgp_outbound_policy_exists(
11036 peer, filter)))
11037 json_object_string_add(json_peer,
11038 "peerState",
11039 "Policy");
11040 else
11041 json_object_string_add(
11042 json_peer, "peerState", "OK");
11043
11044 json_object_int_add(json_peer, "connectionsEstablished",
11045 peer->established);
11046 json_object_int_add(json_peer, "connectionsDropped",
11047 peer->dropped);
11048 if (peer->desc)
11049 json_object_string_add(
11050 json_peer, "desc", peer->desc);
11051 }
11052 /* Avoid creating empty peer dicts in JSON */
11053 if (json_peer == NULL)
11054 continue;
11055
11056 if (peer->conf_if)
11057 json_object_string_add(json_peer, "idType",
11058 "interface");
11059 else if (peer->su.sa.sa_family == AF_INET)
11060 json_object_string_add(json_peer, "idType",
11061 "ipv4");
11062 else if (peer->su.sa.sa_family == AF_INET6)
11063 json_object_string_add(json_peer, "idType",
11064 "ipv6");
11065 json_object_object_add(json_peers, peer->host,
11066 json_peer);
11067 } else {
11068 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11069 as_type, as)) {
11070 filtered_count++;
11071 continue;
11072 }
11073 if (show_failed &&
11074 bgp_has_peer_failed(peer, afi, safi)) {
11075 bgp_show_failed_summary(vty, bgp, peer, NULL,
11076 max_neighbor_width,
11077 use_json);
11078 } else if (!show_failed) {
11079 if (show_established
11080 && bgp_has_peer_failed(peer, afi, safi)) {
11081 filtered_count++;
11082 continue;
11083 }
11084
11085 if ((count - filtered_count) == 1) {
11086 /* display headline before the first
11087 * neighbor line */
11088 vty_out(vty, "\n");
11089
11090 /* Subtract 8 here because 'Neighbor' is
11091 * 8 characters */
11092 vty_out(vty, "Neighbor");
11093 vty_out(vty, "%*s",
11094 max_neighbor_width - 8, " ");
11095 vty_out(vty,
11096 show_wide
11097 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11098 : BGP_SHOW_SUMMARY_HEADER_ALL);
11099 }
11100
11101 memset(dn_flag, '\0', sizeof(dn_flag));
11102 if (peer_dynamic_neighbor(peer)) {
11103 dn_flag[0] = '*';
11104 }
11105
11106 if (peer->hostname
11107 && CHECK_FLAG(bgp->flags,
11108 BGP_FLAG_SHOW_HOSTNAME))
11109 len = vty_out(vty, "%s%s(%s)", dn_flag,
11110 peer->hostname,
11111 peer->host);
11112 else
11113 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11114
11115 /* pad the neighbor column with spaces */
11116 if (len < max_neighbor_width)
11117 vty_out(vty, "%*s", max_neighbor_width - len,
11118 " ");
11119
11120 atomic_size_t outq_count, inq_count;
11121 outq_count = atomic_load_explicit(
11122 &peer->obuf->count,
11123 memory_order_relaxed);
11124 inq_count = atomic_load_explicit(
11125 &peer->ibuf->count,
11126 memory_order_relaxed);
11127
11128 if (show_wide)
11129 vty_out(vty,
11130 "4 %10u %10u %9u %9u %8" PRIu64
11131 " %4zu %4zu %8s",
11132 peer->as,
11133 peer->change_local_as
11134 ? peer->change_local_as
11135 : peer->local_as,
11136 PEER_TOTAL_RX(peer),
11137 PEER_TOTAL_TX(peer),
11138 peer->version[afi][safi],
11139 inq_count, outq_count,
11140 peer_uptime(peer->uptime,
11141 timebuf,
11142 BGP_UPTIME_LEN, 0,
11143 NULL));
11144 else
11145 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11146 " %4zu %4zu %8s",
11147 peer->as, PEER_TOTAL_RX(peer),
11148 PEER_TOTAL_TX(peer),
11149 peer->version[afi][safi],
11150 inq_count, outq_count,
11151 peer_uptime(peer->uptime,
11152 timebuf,
11153 BGP_UPTIME_LEN, 0,
11154 NULL));
11155
11156 if (peer_established(peer)) {
11157 if (peer->afc_recv[afi][safi]) {
11158 if (CHECK_FLAG(
11159 bgp->flags,
11160 BGP_FLAG_EBGP_REQUIRES_POLICY)
11161 && !bgp_inbound_policy_exists(
11162 peer, filter))
11163 vty_out(vty, " %12s",
11164 "(Policy)");
11165 else
11166 vty_out(vty,
11167 " %12u",
11168 peer->pcount
11169 [afi]
11170 [pfx_rcd_safi]);
11171 } else {
11172 vty_out(vty, " NoNeg");
11173 }
11174
11175 if (paf && PAF_SUBGRP(paf)) {
11176 if (CHECK_FLAG(
11177 bgp->flags,
11178 BGP_FLAG_EBGP_REQUIRES_POLICY)
11179 && !bgp_outbound_policy_exists(
11180 peer, filter))
11181 vty_out(vty, " %8s",
11182 "(Policy)");
11183 else
11184 vty_out(vty,
11185 " %8u",
11186 (PAF_SUBGRP(
11187 paf))
11188 ->scount);
11189 } else {
11190 vty_out(vty, " NoNeg");
11191 }
11192 } else {
11193 if (CHECK_FLAG(peer->flags,
11194 PEER_FLAG_SHUTDOWN)
11195 || CHECK_FLAG(peer->bgp->flags,
11196 BGP_FLAG_SHUTDOWN))
11197 vty_out(vty, " Idle (Admin)");
11198 else if (CHECK_FLAG(
11199 peer->sflags,
11200 PEER_STATUS_PREFIX_OVERFLOW))
11201 vty_out(vty, " Idle (PfxCt)");
11202 else
11203 vty_out(vty, " %12s",
11204 lookup_msg(bgp_status_msg,
11205 peer->status, NULL));
11206
11207 vty_out(vty, " %8u", 0);
11208 }
11209 /* Make sure `Desc` column is the lastest in
11210 * the output.
11211 */
11212 if (peer->desc)
11213 vty_out(vty, " %s",
11214 bgp_peer_description_stripped(
11215 peer->desc,
11216 show_wide ? 64 : 20));
11217 else
11218 vty_out(vty, " N/A");
11219 vty_out(vty, "\n");
11220 }
11221
11222 }
11223 }
11224
11225 if (use_json) {
11226 json_object_object_add(json, "peers", json_peers);
11227 json_object_int_add(json, "failedPeers", failed_count);
11228 json_object_int_add(json, "displayedPeers",
11229 count - filtered_count);
11230 json_object_int_add(json, "totalPeers", count);
11231 json_object_int_add(json, "dynamicPeers", dn_count);
11232
11233 if (!show_failed)
11234 bgp_show_bestpath_json(bgp, json);
11235
11236 vty_json(vty, json);
11237 } else {
11238 if (count) {
11239 if (filtered_count == count)
11240 vty_out(vty, "\n%% No matching neighbor\n");
11241 else {
11242 if (show_failed)
11243 vty_out(vty, "\nDisplayed neighbors %d",
11244 failed_count);
11245 else if (as_type != AS_UNSPECIFIED || as
11246 || fpeer || show_established)
11247 vty_out(vty, "\nDisplayed neighbors %d",
11248 count - filtered_count);
11249
11250 vty_out(vty, "\nTotal number of neighbors %d\n",
11251 count);
11252 }
11253 } else {
11254 vty_out(vty, "No %s neighbor is configured\n",
11255 get_afi_safi_str(afi, safi, false));
11256 }
11257
11258 if (dn_count) {
11259 vty_out(vty, "* - dynamic neighbor\n");
11260 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11261 dn_count, bgp->dynamic_neighbors_limit);
11262 }
11263 }
11264
11265 return CMD_SUCCESS;
11266 }
11267
11268 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11269 int safi, struct peer *fpeer, int as_type,
11270 as_t as, uint16_t show_flags)
11271 {
11272 int is_first = 1;
11273 int afi_wildcard = (afi == AFI_MAX);
11274 int safi_wildcard = (safi == SAFI_MAX);
11275 int is_wildcard = (afi_wildcard || safi_wildcard);
11276 bool nbr_output = false;
11277 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11278
11279 if (use_json && is_wildcard)
11280 vty_out(vty, "{\n");
11281 if (afi_wildcard)
11282 afi = 1; /* AFI_IP */
11283 while (afi < AFI_MAX) {
11284 if (safi_wildcard)
11285 safi = 1; /* SAFI_UNICAST */
11286 while (safi < SAFI_MAX) {
11287 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11288 nbr_output = true;
11289
11290 if (is_wildcard) {
11291 /*
11292 * So limit output to those afi/safi
11293 * pairs that
11294 * actualy have something interesting in
11295 * them
11296 */
11297 if (use_json) {
11298 if (!is_first)
11299 vty_out(vty, ",\n");
11300 else
11301 is_first = 0;
11302
11303 vty_out(vty, "\"%s\":",
11304 get_afi_safi_str(afi,
11305 safi,
11306 true));
11307 } else {
11308 vty_out(vty,
11309 "\n%s Summary (%s):\n",
11310 get_afi_safi_str(afi,
11311 safi,
11312 false),
11313 bgp->name_pretty);
11314 }
11315 }
11316 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11317 as_type, as, show_flags);
11318 }
11319 safi++;
11320 if (!safi_wildcard)
11321 safi = SAFI_MAX;
11322 }
11323 afi++;
11324 if (!afi_wildcard)
11325 afi = AFI_MAX;
11326 }
11327
11328 if (use_json && is_wildcard)
11329 vty_out(vty, "}\n");
11330 else if (!nbr_output) {
11331 if (use_json)
11332 vty_out(vty, "{}\n");
11333 else
11334 vty_out(vty, "%% No BGP neighbors found in %s\n",
11335 bgp->name_pretty);
11336 }
11337 }
11338
11339 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11340 safi_t safi,
11341 const char *neighbor,
11342 int as_type, as_t as,
11343 uint16_t show_flags)
11344 {
11345 struct listnode *node, *nnode;
11346 struct bgp *bgp;
11347 struct peer *fpeer = NULL;
11348 int is_first = 1;
11349 bool nbr_output = false;
11350 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11351
11352 if (use_json)
11353 vty_out(vty, "{\n");
11354
11355 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11356 nbr_output = true;
11357 if (use_json) {
11358 if (!is_first)
11359 vty_out(vty, ",\n");
11360 else
11361 is_first = 0;
11362
11363 vty_out(vty, "\"%s\":",
11364 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11365 ? VRF_DEFAULT_NAME
11366 : bgp->name);
11367 }
11368 if (neighbor) {
11369 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11370 use_json);
11371 if (!fpeer)
11372 continue;
11373 }
11374 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11375 as, show_flags);
11376 }
11377
11378 if (use_json)
11379 vty_out(vty, "}\n");
11380 else if (!nbr_output)
11381 vty_out(vty, "%% BGP instance not found\n");
11382 }
11383
11384 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11385 safi_t safi, const char *neighbor, int as_type,
11386 as_t as, uint16_t show_flags)
11387 {
11388 struct bgp *bgp;
11389 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11390 struct peer *fpeer = NULL;
11391
11392 if (name) {
11393 if (strmatch(name, "all")) {
11394 bgp_show_all_instances_summary_vty(vty, afi, safi,
11395 neighbor, as_type,
11396 as, show_flags);
11397 return CMD_SUCCESS;
11398 } else {
11399 bgp = bgp_lookup_by_name(name);
11400
11401 if (!bgp) {
11402 if (use_json)
11403 vty_out(vty, "{}\n");
11404 else
11405 vty_out(vty,
11406 "%% BGP instance not found\n");
11407 return CMD_WARNING;
11408 }
11409
11410 if (neighbor) {
11411 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11412 use_json);
11413 if (!fpeer)
11414 return CMD_WARNING;
11415 }
11416 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11417 as_type, as, show_flags);
11418 return CMD_SUCCESS;
11419 }
11420 }
11421
11422 bgp = bgp_get_default();
11423
11424 if (bgp) {
11425 if (neighbor) {
11426 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11427 use_json);
11428 if (!fpeer)
11429 return CMD_WARNING;
11430 }
11431 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11432 as, show_flags);
11433 } else {
11434 if (use_json)
11435 vty_out(vty, "{}\n");
11436 else
11437 vty_out(vty, "%% BGP instance not found\n");
11438 return CMD_WARNING;
11439 }
11440
11441 return CMD_SUCCESS;
11442 }
11443
11444 /* `show [ip] bgp summary' commands. */
11445 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11446 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11447 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11448 "]] [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]",
11449 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11450 BGP_SAFI_WITH_LABEL_HELP_STR
11451 "Display the entries for all address families\n"
11452 "Summary of BGP neighbor status\n"
11453 "Show only sessions in Established state\n"
11454 "Show only sessions not in Established state\n"
11455 "Show only the specified neighbor session\n"
11456 "Neighbor to display information about\n"
11457 "Neighbor to display information about\n"
11458 "Neighbor on BGP configured interface\n"
11459 "Show only the specified remote AS sessions\n"
11460 "AS number\n"
11461 "Internal (iBGP) AS sessions\n"
11462 "External (eBGP) AS sessions\n"
11463 "Shorten the information on BGP instances\n"
11464 "Increase table width for longer output\n" JSON_STR)
11465 {
11466 char *vrf = NULL;
11467 afi_t afi = AFI_MAX;
11468 safi_t safi = SAFI_MAX;
11469 as_t as = 0; /* 0 means AS filter not set */
11470 int as_type = AS_UNSPECIFIED;
11471 uint16_t show_flags = 0;
11472
11473 int idx = 0;
11474
11475 /* show [ip] bgp */
11476 if (!all && argv_find(argv, argc, "ip", &idx))
11477 afi = AFI_IP;
11478 /* [<vrf> VIEWVRFNAME] */
11479 if (argv_find(argv, argc, "vrf", &idx)) {
11480 vrf = argv[idx + 1]->arg;
11481 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11482 vrf = NULL;
11483 } else if (argv_find(argv, argc, "view", &idx))
11484 /* [<view> VIEWVRFNAME] */
11485 vrf = argv[idx + 1]->arg;
11486 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11487 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11488 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11489 }
11490
11491 if (argv_find(argv, argc, "failed", &idx))
11492 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11493
11494 if (argv_find(argv, argc, "established", &idx))
11495 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11496
11497 if (argv_find(argv, argc, "remote-as", &idx)) {
11498 if (argv[idx + 1]->arg[0] == 'i')
11499 as_type = AS_INTERNAL;
11500 else if (argv[idx + 1]->arg[0] == 'e')
11501 as_type = AS_EXTERNAL;
11502 else
11503 as = (as_t)atoi(argv[idx + 1]->arg);
11504 }
11505
11506 if (argv_find(argv, argc, "terse", &idx))
11507 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11508
11509 if (argv_find(argv, argc, "wide", &idx))
11510 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11511
11512 if (argv_find(argv, argc, "json", &idx))
11513 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11514
11515 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11516 show_flags);
11517 }
11518
11519 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11520 {
11521 if (for_json)
11522 return get_afi_safi_json_str(afi, safi);
11523 else
11524 return get_afi_safi_vty_str(afi, safi);
11525 }
11526
11527
11528 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11529 afi_t afi, safi_t safi,
11530 uint16_t adv_smcap, uint16_t adv_rmcap,
11531 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11532 bool use_json, json_object *json_pref)
11533 {
11534 /* Send-Mode */
11535 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11536 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11537 if (use_json) {
11538 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11539 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11540 json_object_string_add(json_pref, "sendMode",
11541 "advertisedAndReceived");
11542 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11543 json_object_string_add(json_pref, "sendMode",
11544 "advertised");
11545 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11546 json_object_string_add(json_pref, "sendMode",
11547 "received");
11548 } else {
11549 vty_out(vty, " Send-mode: ");
11550 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11551 vty_out(vty, "advertised");
11552 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11553 vty_out(vty, "%sreceived",
11554 CHECK_FLAG(p->af_cap[afi][safi],
11555 adv_smcap)
11556 ? ", "
11557 : "");
11558 vty_out(vty, "\n");
11559 }
11560 }
11561
11562 /* Receive-Mode */
11563 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11564 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11565 if (use_json) {
11566 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11567 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11568 json_object_string_add(json_pref, "recvMode",
11569 "advertisedAndReceived");
11570 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11571 json_object_string_add(json_pref, "recvMode",
11572 "advertised");
11573 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11574 json_object_string_add(json_pref, "recvMode",
11575 "received");
11576 } else {
11577 vty_out(vty, " Receive-mode: ");
11578 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11579 vty_out(vty, "advertised");
11580 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11581 vty_out(vty, "%sreceived",
11582 CHECK_FLAG(p->af_cap[afi][safi],
11583 adv_rmcap)
11584 ? ", "
11585 : "");
11586 vty_out(vty, "\n");
11587 }
11588 }
11589 }
11590
11591 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11592 struct peer *p,
11593 bool use_json,
11594 json_object *json)
11595 {
11596 bool rbit = false;
11597 bool nbit = false;
11598
11599 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11600 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11601 && (peer_established(p))) {
11602 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11603 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11604 }
11605
11606 if (use_json) {
11607 json_object_boolean_add(json, "rBit", rbit);
11608 json_object_boolean_add(json, "nBit", nbit);
11609 } else {
11610 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11611 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11612 }
11613 }
11614
11615 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11616 struct peer *peer,
11617 bool use_json,
11618 json_object *json)
11619 {
11620 const char *mode = "NotApplicable";
11621
11622 if (!use_json)
11623 vty_out(vty, "\n Remote GR Mode: ");
11624
11625 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11626 && (peer_established(peer))) {
11627
11628 if ((peer->nsf_af_count == 0)
11629 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11630
11631 mode = "Disable";
11632
11633 } else if (peer->nsf_af_count == 0
11634 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11635
11636 mode = "Helper";
11637
11638 } else if (peer->nsf_af_count != 0
11639 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11640
11641 mode = "Restart";
11642 }
11643 }
11644
11645 if (use_json) {
11646 json_object_string_add(json, "remoteGrMode", mode);
11647 } else
11648 vty_out(vty, mode, "\n");
11649 }
11650
11651 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11652 struct peer *p,
11653 bool use_json,
11654 json_object *json)
11655 {
11656 const char *mode = "Invalid";
11657
11658 if (!use_json)
11659 vty_out(vty, " Local GR Mode: ");
11660
11661 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11662 mode = "Helper";
11663 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11664 mode = "Restart";
11665 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11666 mode = "Disable";
11667 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11668 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11669 mode = "Helper*";
11670 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11671 mode = "Restart*";
11672 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11673 mode = "Disable*";
11674 else
11675 mode = "Invalid*";
11676 }
11677
11678 if (use_json) {
11679 json_object_string_add(json, "localGrMode", mode);
11680 } else {
11681 vty_out(vty, mode, "\n");
11682 }
11683 }
11684
11685 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11686 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11687 {
11688 afi_t afi;
11689 safi_t safi;
11690 json_object *json_afi_safi = NULL;
11691 json_object *json_timer = NULL;
11692 json_object *json_endofrib_status = NULL;
11693 bool eor_flag = false;
11694
11695 FOREACH_AFI_SAFI_NSF (afi, safi) {
11696 if (!peer->afc[afi][safi])
11697 continue;
11698
11699 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11700 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11701 continue;
11702
11703 if (use_json) {
11704 json_afi_safi = json_object_new_object();
11705 json_endofrib_status = json_object_new_object();
11706 json_timer = json_object_new_object();
11707 }
11708
11709 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11710 eor_flag = true;
11711 else
11712 eor_flag = false;
11713
11714 if (!use_json) {
11715 vty_out(vty, " %s:\n",
11716 get_afi_safi_str(afi, safi, false));
11717
11718 vty_out(vty, " F bit: ");
11719 }
11720
11721 if (peer->nsf[afi][safi] &&
11722 CHECK_FLAG(peer->af_cap[afi][safi],
11723 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11724
11725 if (use_json) {
11726 json_object_boolean_true_add(json_afi_safi,
11727 "fBit");
11728 } else
11729 vty_out(vty, "True\n");
11730 } else {
11731 if (use_json)
11732 json_object_boolean_false_add(json_afi_safi,
11733 "fBit");
11734 else
11735 vty_out(vty, "False\n");
11736 }
11737
11738 if (!use_json)
11739 vty_out(vty, " End-of-RIB sent: ");
11740
11741 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11742 PEER_STATUS_EOR_SEND)) {
11743 if (use_json) {
11744 json_object_boolean_true_add(
11745 json_endofrib_status, "endOfRibSend");
11746
11747 PRINT_EOR_JSON(eor_flag);
11748 } else {
11749 vty_out(vty, "Yes\n");
11750 vty_out(vty,
11751 " End-of-RIB sent after update: ");
11752
11753 PRINT_EOR(eor_flag);
11754 }
11755 } else {
11756 if (use_json) {
11757 json_object_boolean_false_add(
11758 json_endofrib_status, "endOfRibSend");
11759 json_object_boolean_false_add(
11760 json_endofrib_status,
11761 "endOfRibSentAfterUpdate");
11762 } else {
11763 vty_out(vty, "No\n");
11764 vty_out(vty,
11765 " End-of-RIB sent after update: ");
11766 vty_out(vty, "No\n");
11767 }
11768 }
11769
11770 if (!use_json)
11771 vty_out(vty, " End-of-RIB received: ");
11772
11773 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11774 PEER_STATUS_EOR_RECEIVED)) {
11775 if (use_json)
11776 json_object_boolean_true_add(
11777 json_endofrib_status, "endOfRibRecv");
11778 else
11779 vty_out(vty, "Yes\n");
11780 } else {
11781 if (use_json)
11782 json_object_boolean_false_add(
11783 json_endofrib_status, "endOfRibRecv");
11784 else
11785 vty_out(vty, "No\n");
11786 }
11787
11788 if (use_json) {
11789 json_object_int_add(json_timer, "stalePathTimer",
11790 peer->bgp->stalepath_time);
11791
11792 if (peer->t_gr_stale != NULL) {
11793 json_object_int_add(json_timer,
11794 "stalePathTimerRemaining",
11795 thread_timer_remain_second(
11796 peer->t_gr_stale));
11797 }
11798
11799 /* Display Configured Selection
11800 * Deferral only when when
11801 * Gr mode is enabled.
11802 */
11803 if (CHECK_FLAG(peer->flags,
11804 PEER_FLAG_GRACEFUL_RESTART)) {
11805 json_object_int_add(json_timer,
11806 "selectionDeferralTimer",
11807 peer->bgp->stalepath_time);
11808 }
11809
11810 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11811 NULL) {
11812
11813 json_object_int_add(
11814 json_timer,
11815 "selectionDeferralTimerRemaining",
11816 thread_timer_remain_second(
11817 peer->bgp->gr_info[afi][safi]
11818 .t_select_deferral));
11819 }
11820 } else {
11821 vty_out(vty, " Timers:\n");
11822 vty_out(vty,
11823 " Configured Stale Path Time(sec): %u\n",
11824 peer->bgp->stalepath_time);
11825
11826 if (peer->t_gr_stale != NULL)
11827 vty_out(vty,
11828 " Stale Path Remaining(sec): %ld\n",
11829 thread_timer_remain_second(
11830 peer->t_gr_stale));
11831 /* Display Configured Selection
11832 * Deferral only when when
11833 * Gr mode is enabled.
11834 */
11835 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11836 vty_out(vty,
11837 " Configured Selection Deferral Time(sec): %u\n",
11838 peer->bgp->select_defer_time);
11839
11840 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11841 NULL)
11842 vty_out(vty,
11843 " Selection Deferral Time Remaining(sec): %ld\n",
11844 thread_timer_remain_second(
11845 peer->bgp->gr_info[afi][safi]
11846 .t_select_deferral));
11847 }
11848 if (use_json) {
11849 json_object_object_add(json_afi_safi, "endOfRibStatus",
11850 json_endofrib_status);
11851 json_object_object_add(json_afi_safi, "timers",
11852 json_timer);
11853 json_object_object_add(
11854 json, get_afi_safi_str(afi, safi, true),
11855 json_afi_safi);
11856 }
11857 }
11858 }
11859
11860 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11861 struct peer *p,
11862 bool use_json,
11863 json_object *json)
11864 {
11865 if (use_json) {
11866 json_object *json_timer = NULL;
11867
11868 json_timer = json_object_new_object();
11869
11870 json_object_int_add(json_timer, "configuredRestartTimer",
11871 p->bgp->restart_time);
11872
11873 json_object_int_add(json_timer, "receivedRestartTimer",
11874 p->v_gr_restart);
11875
11876 if (p->t_gr_restart != NULL)
11877 json_object_int_add(
11878 json_timer, "restartTimerRemaining",
11879 thread_timer_remain_second(p->t_gr_restart));
11880
11881 json_object_object_add(json, "timers", json_timer);
11882 } else {
11883
11884 vty_out(vty, " Timers:\n");
11885 vty_out(vty, " Configured Restart Time(sec): %u\n",
11886 p->bgp->restart_time);
11887
11888 vty_out(vty, " Received Restart Time(sec): %u\n",
11889 p->v_gr_restart);
11890 if (p->t_gr_restart != NULL)
11891 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11892 thread_timer_remain_second(p->t_gr_restart));
11893 if (p->t_gr_restart != NULL) {
11894 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11895 thread_timer_remain_second(p->t_gr_restart));
11896 }
11897 }
11898 }
11899
11900 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11901 bool use_json, json_object *json)
11902 {
11903 char dn_flag[2] = {0};
11904 /* '*' + v6 address of neighbor */
11905 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11906
11907 if (!p->conf_if && peer_dynamic_neighbor(p))
11908 dn_flag[0] = '*';
11909
11910 if (p->conf_if) {
11911 if (use_json)
11912 json_object_string_addf(json, "neighborAddr", "%pSU",
11913 &p->su);
11914 else
11915 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11916 &p->su);
11917 } else {
11918 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11919 p->host);
11920
11921 if (use_json)
11922 json_object_string_add(json, "neighborAddr",
11923 neighborAddr);
11924 else
11925 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11926 }
11927
11928 /* more gr info in new format */
11929 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11930 }
11931
11932 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11933 safi_t safi, bool use_json,
11934 json_object *json_neigh)
11935 {
11936 struct bgp_filter *filter;
11937 struct peer_af *paf;
11938 char orf_pfx_name[BUFSIZ];
11939 int orf_pfx_count;
11940 json_object *json_af = NULL;
11941 json_object *json_prefA = NULL;
11942 json_object *json_prefB = NULL;
11943 json_object *json_addr = NULL;
11944 json_object *json_advmap = NULL;
11945
11946 if (use_json) {
11947 json_addr = json_object_new_object();
11948 json_af = json_object_new_object();
11949 filter = &p->filter[afi][safi];
11950
11951 if (peer_group_active(p))
11952 json_object_string_add(json_addr, "peerGroupMember",
11953 p->group->name);
11954
11955 paf = peer_af_find(p, afi, safi);
11956 if (paf && PAF_SUBGRP(paf)) {
11957 json_object_int_add(json_addr, "updateGroupId",
11958 PAF_UPDGRP(paf)->id);
11959 json_object_int_add(json_addr, "subGroupId",
11960 PAF_SUBGRP(paf)->id);
11961 json_object_int_add(json_addr, "packetQueueLength",
11962 bpacket_queue_virtual_length(paf));
11963 }
11964
11965 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11966 || CHECK_FLAG(p->af_cap[afi][safi],
11967 PEER_CAP_ORF_PREFIX_SM_RCV)
11968 || CHECK_FLAG(p->af_cap[afi][safi],
11969 PEER_CAP_ORF_PREFIX_RM_ADV)
11970 || CHECK_FLAG(p->af_cap[afi][safi],
11971 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11972 json_object_int_add(json_af, "orfType",
11973 ORF_TYPE_PREFIX);
11974 json_prefA = json_object_new_object();
11975 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11976 PEER_CAP_ORF_PREFIX_SM_ADV,
11977 PEER_CAP_ORF_PREFIX_RM_ADV,
11978 PEER_CAP_ORF_PREFIX_SM_RCV,
11979 PEER_CAP_ORF_PREFIX_RM_RCV,
11980 use_json, json_prefA);
11981 json_object_object_add(json_af, "orfPrefixList",
11982 json_prefA);
11983 }
11984
11985 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11986 || CHECK_FLAG(p->af_cap[afi][safi],
11987 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11988 || CHECK_FLAG(p->af_cap[afi][safi],
11989 PEER_CAP_ORF_PREFIX_RM_ADV)
11990 || CHECK_FLAG(p->af_cap[afi][safi],
11991 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11992 json_object_int_add(json_af, "orfOldType",
11993 ORF_TYPE_PREFIX_OLD);
11994 json_prefB = json_object_new_object();
11995 bgp_show_peer_afi_orf_cap(
11996 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11997 PEER_CAP_ORF_PREFIX_RM_ADV,
11998 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11999 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12000 json_prefB);
12001 json_object_object_add(json_af, "orfOldPrefixList",
12002 json_prefB);
12003 }
12004
12005 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12006 || CHECK_FLAG(p->af_cap[afi][safi],
12007 PEER_CAP_ORF_PREFIX_SM_RCV)
12008 || CHECK_FLAG(p->af_cap[afi][safi],
12009 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12010 || CHECK_FLAG(p->af_cap[afi][safi],
12011 PEER_CAP_ORF_PREFIX_RM_ADV)
12012 || CHECK_FLAG(p->af_cap[afi][safi],
12013 PEER_CAP_ORF_PREFIX_RM_RCV)
12014 || CHECK_FLAG(p->af_cap[afi][safi],
12015 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12016 json_object_object_add(json_addr, "afDependentCap",
12017 json_af);
12018 else
12019 json_object_free(json_af);
12020
12021 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12022 p->host, afi, safi);
12023 orf_pfx_count = prefix_bgp_show_prefix_list(
12024 NULL, afi, orf_pfx_name, use_json);
12025
12026 if (CHECK_FLAG(p->af_sflags[afi][safi],
12027 PEER_STATUS_ORF_PREFIX_SEND)
12028 || orf_pfx_count) {
12029 if (CHECK_FLAG(p->af_sflags[afi][safi],
12030 PEER_STATUS_ORF_PREFIX_SEND))
12031 json_object_boolean_true_add(json_neigh,
12032 "orfSent");
12033 if (orf_pfx_count)
12034 json_object_int_add(json_addr, "orfRecvCounter",
12035 orf_pfx_count);
12036 }
12037 if (CHECK_FLAG(p->af_sflags[afi][safi],
12038 PEER_STATUS_ORF_WAIT_REFRESH))
12039 json_object_string_add(
12040 json_addr, "orfFirstUpdate",
12041 "deferredUntilORFOrRouteRefreshRecvd");
12042
12043 if (CHECK_FLAG(p->af_flags[afi][safi],
12044 PEER_FLAG_REFLECTOR_CLIENT))
12045 json_object_boolean_true_add(json_addr,
12046 "routeReflectorClient");
12047 if (CHECK_FLAG(p->af_flags[afi][safi],
12048 PEER_FLAG_RSERVER_CLIENT))
12049 json_object_boolean_true_add(json_addr,
12050 "routeServerClient");
12051 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12052 json_object_boolean_true_add(json_addr,
12053 "inboundSoftConfigPermit");
12054
12055 if (CHECK_FLAG(p->af_flags[afi][safi],
12056 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12057 json_object_boolean_true_add(
12058 json_addr,
12059 "privateAsNumsAllReplacedInUpdatesToNbr");
12060 else if (CHECK_FLAG(p->af_flags[afi][safi],
12061 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12062 json_object_boolean_true_add(
12063 json_addr,
12064 "privateAsNumsReplacedInUpdatesToNbr");
12065 else if (CHECK_FLAG(p->af_flags[afi][safi],
12066 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12067 json_object_boolean_true_add(
12068 json_addr,
12069 "privateAsNumsAllRemovedInUpdatesToNbr");
12070 else if (CHECK_FLAG(p->af_flags[afi][safi],
12071 PEER_FLAG_REMOVE_PRIVATE_AS))
12072 json_object_boolean_true_add(
12073 json_addr,
12074 "privateAsNumsRemovedInUpdatesToNbr");
12075
12076 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12077 json_object_boolean_true_add(
12078 json_addr,
12079 bgp_addpath_names(p->addpath_type[afi][safi])
12080 ->type_json_name);
12081
12082 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12083 json_object_string_add(json_addr,
12084 "overrideASNsInOutboundUpdates",
12085 "ifAspathEqualRemoteAs");
12086
12087 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12088 || CHECK_FLAG(p->af_flags[afi][safi],
12089 PEER_FLAG_FORCE_NEXTHOP_SELF))
12090 json_object_boolean_true_add(json_addr,
12091 "routerAlwaysNextHop");
12092 if (CHECK_FLAG(p->af_flags[afi][safi],
12093 PEER_FLAG_AS_PATH_UNCHANGED))
12094 json_object_boolean_true_add(
12095 json_addr, "unchangedAsPathPropogatedToNbr");
12096 if (CHECK_FLAG(p->af_flags[afi][safi],
12097 PEER_FLAG_NEXTHOP_UNCHANGED))
12098 json_object_boolean_true_add(
12099 json_addr, "unchangedNextHopPropogatedToNbr");
12100 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12101 json_object_boolean_true_add(
12102 json_addr, "unchangedMedPropogatedToNbr");
12103 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12104 || CHECK_FLAG(p->af_flags[afi][safi],
12105 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12106 if (CHECK_FLAG(p->af_flags[afi][safi],
12107 PEER_FLAG_SEND_COMMUNITY)
12108 && CHECK_FLAG(p->af_flags[afi][safi],
12109 PEER_FLAG_SEND_EXT_COMMUNITY))
12110 json_object_string_add(json_addr,
12111 "commAttriSentToNbr",
12112 "extendedAndStandard");
12113 else if (CHECK_FLAG(p->af_flags[afi][safi],
12114 PEER_FLAG_SEND_EXT_COMMUNITY))
12115 json_object_string_add(json_addr,
12116 "commAttriSentToNbr",
12117 "extended");
12118 else
12119 json_object_string_add(json_addr,
12120 "commAttriSentToNbr",
12121 "standard");
12122 }
12123 if (CHECK_FLAG(p->af_flags[afi][safi],
12124 PEER_FLAG_DEFAULT_ORIGINATE)) {
12125 if (p->default_rmap[afi][safi].name)
12126 json_object_string_add(
12127 json_addr, "defaultRouteMap",
12128 p->default_rmap[afi][safi].name);
12129
12130 if (paf && PAF_SUBGRP(paf)
12131 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12132 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12133 json_object_boolean_true_add(json_addr,
12134 "defaultSent");
12135 else
12136 json_object_boolean_true_add(json_addr,
12137 "defaultNotSent");
12138 }
12139
12140 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12141 if (is_evpn_enabled())
12142 json_object_boolean_true_add(
12143 json_addr, "advertiseAllVnis");
12144 }
12145
12146 if (filter->plist[FILTER_IN].name
12147 || filter->dlist[FILTER_IN].name
12148 || filter->aslist[FILTER_IN].name
12149 || filter->map[RMAP_IN].name)
12150 json_object_boolean_true_add(json_addr,
12151 "inboundPathPolicyConfig");
12152 if (filter->plist[FILTER_OUT].name
12153 || filter->dlist[FILTER_OUT].name
12154 || filter->aslist[FILTER_OUT].name
12155 || filter->map[RMAP_OUT].name || filter->usmap.name)
12156 json_object_boolean_true_add(
12157 json_addr, "outboundPathPolicyConfig");
12158
12159 /* prefix-list */
12160 if (filter->plist[FILTER_IN].name)
12161 json_object_string_add(json_addr,
12162 "incomingUpdatePrefixFilterList",
12163 filter->plist[FILTER_IN].name);
12164 if (filter->plist[FILTER_OUT].name)
12165 json_object_string_add(json_addr,
12166 "outgoingUpdatePrefixFilterList",
12167 filter->plist[FILTER_OUT].name);
12168
12169 /* distribute-list */
12170 if (filter->dlist[FILTER_IN].name)
12171 json_object_string_add(
12172 json_addr, "incomingUpdateNetworkFilterList",
12173 filter->dlist[FILTER_IN].name);
12174 if (filter->dlist[FILTER_OUT].name)
12175 json_object_string_add(
12176 json_addr, "outgoingUpdateNetworkFilterList",
12177 filter->dlist[FILTER_OUT].name);
12178
12179 /* filter-list. */
12180 if (filter->aslist[FILTER_IN].name)
12181 json_object_string_add(json_addr,
12182 "incomingUpdateAsPathFilterList",
12183 filter->aslist[FILTER_IN].name);
12184 if (filter->aslist[FILTER_OUT].name)
12185 json_object_string_add(json_addr,
12186 "outgoingUpdateAsPathFilterList",
12187 filter->aslist[FILTER_OUT].name);
12188
12189 /* route-map. */
12190 if (filter->map[RMAP_IN].name)
12191 json_object_string_add(
12192 json_addr, "routeMapForIncomingAdvertisements",
12193 filter->map[RMAP_IN].name);
12194 if (filter->map[RMAP_OUT].name)
12195 json_object_string_add(
12196 json_addr, "routeMapForOutgoingAdvertisements",
12197 filter->map[RMAP_OUT].name);
12198
12199 /* ebgp-requires-policy (inbound) */
12200 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12201 && !bgp_inbound_policy_exists(p, filter))
12202 json_object_string_add(
12203 json_addr, "inboundEbgpRequiresPolicy",
12204 "Inbound updates discarded due to missing policy");
12205
12206 /* ebgp-requires-policy (outbound) */
12207 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12208 && (!bgp_outbound_policy_exists(p, filter)))
12209 json_object_string_add(
12210 json_addr, "outboundEbgpRequiresPolicy",
12211 "Outbound updates discarded due to missing policy");
12212
12213 /* unsuppress-map */
12214 if (filter->usmap.name)
12215 json_object_string_add(json_addr,
12216 "selectiveUnsuppressRouteMap",
12217 filter->usmap.name);
12218
12219 /* advertise-map */
12220 if (filter->advmap.aname) {
12221 json_advmap = json_object_new_object();
12222 json_object_string_add(json_advmap, "condition",
12223 filter->advmap.condition
12224 ? "EXIST"
12225 : "NON_EXIST");
12226 json_object_string_add(json_advmap, "conditionMap",
12227 filter->advmap.cname);
12228 json_object_string_add(json_advmap, "advertiseMap",
12229 filter->advmap.aname);
12230 json_object_string_add(
12231 json_advmap, "advertiseStatus",
12232 filter->advmap.update_type ==
12233 UPDATE_TYPE_ADVERTISE
12234 ? "Advertise"
12235 : "Withdraw");
12236 json_object_object_add(json_addr, "advertiseMap",
12237 json_advmap);
12238 }
12239
12240 /* Receive prefix count */
12241 json_object_int_add(json_addr, "acceptedPrefixCounter",
12242 p->pcount[afi][safi]);
12243 if (paf && PAF_SUBGRP(paf))
12244 json_object_int_add(json_addr, "sentPrefixCounter",
12245 (PAF_SUBGRP(paf))->scount);
12246
12247 /* Maximum prefix */
12248 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12249 json_object_int_add(json_addr, "prefixOutAllowedMax",
12250 p->pmax_out[afi][safi]);
12251
12252 /* Maximum prefix */
12253 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12254 json_object_int_add(json_addr, "prefixAllowedMax",
12255 p->pmax[afi][safi]);
12256 if (CHECK_FLAG(p->af_flags[afi][safi],
12257 PEER_FLAG_MAX_PREFIX_WARNING))
12258 json_object_boolean_true_add(
12259 json_addr, "prefixAllowedMaxWarning");
12260 json_object_int_add(json_addr,
12261 "prefixAllowedWarningThresh",
12262 p->pmax_threshold[afi][safi]);
12263 if (p->pmax_restart[afi][safi])
12264 json_object_int_add(
12265 json_addr,
12266 "prefixAllowedRestartIntervalMsecs",
12267 p->pmax_restart[afi][safi] * 60000);
12268 }
12269 json_object_object_add(json_neigh,
12270 get_afi_safi_str(afi, safi, true),
12271 json_addr);
12272
12273 } else {
12274 filter = &p->filter[afi][safi];
12275
12276 vty_out(vty, " For address family: %s\n",
12277 get_afi_safi_str(afi, safi, false));
12278
12279 if (peer_group_active(p))
12280 vty_out(vty, " %s peer-group member\n",
12281 p->group->name);
12282
12283 paf = peer_af_find(p, afi, safi);
12284 if (paf && PAF_SUBGRP(paf)) {
12285 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12286 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12287 vty_out(vty, " Packet Queue length %d\n",
12288 bpacket_queue_virtual_length(paf));
12289 } else {
12290 vty_out(vty, " Not part of any update group\n");
12291 }
12292 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12293 || CHECK_FLAG(p->af_cap[afi][safi],
12294 PEER_CAP_ORF_PREFIX_SM_RCV)
12295 || CHECK_FLAG(p->af_cap[afi][safi],
12296 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12297 || CHECK_FLAG(p->af_cap[afi][safi],
12298 PEER_CAP_ORF_PREFIX_RM_ADV)
12299 || CHECK_FLAG(p->af_cap[afi][safi],
12300 PEER_CAP_ORF_PREFIX_RM_RCV)
12301 || CHECK_FLAG(p->af_cap[afi][safi],
12302 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12303 vty_out(vty, " AF-dependant capabilities:\n");
12304
12305 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12306 || CHECK_FLAG(p->af_cap[afi][safi],
12307 PEER_CAP_ORF_PREFIX_SM_RCV)
12308 || CHECK_FLAG(p->af_cap[afi][safi],
12309 PEER_CAP_ORF_PREFIX_RM_ADV)
12310 || CHECK_FLAG(p->af_cap[afi][safi],
12311 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12312 vty_out(vty,
12313 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12314 ORF_TYPE_PREFIX);
12315 bgp_show_peer_afi_orf_cap(
12316 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12317 PEER_CAP_ORF_PREFIX_RM_ADV,
12318 PEER_CAP_ORF_PREFIX_SM_RCV,
12319 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12320 }
12321 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12322 || CHECK_FLAG(p->af_cap[afi][safi],
12323 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12324 || CHECK_FLAG(p->af_cap[afi][safi],
12325 PEER_CAP_ORF_PREFIX_RM_ADV)
12326 || CHECK_FLAG(p->af_cap[afi][safi],
12327 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12328 vty_out(vty,
12329 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12330 ORF_TYPE_PREFIX_OLD);
12331 bgp_show_peer_afi_orf_cap(
12332 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12333 PEER_CAP_ORF_PREFIX_RM_ADV,
12334 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12335 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12336 }
12337
12338 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12339 p->host, afi, safi);
12340 orf_pfx_count = prefix_bgp_show_prefix_list(
12341 NULL, afi, orf_pfx_name, use_json);
12342
12343 if (CHECK_FLAG(p->af_sflags[afi][safi],
12344 PEER_STATUS_ORF_PREFIX_SEND)
12345 || orf_pfx_count) {
12346 vty_out(vty, " Outbound Route Filter (ORF):");
12347 if (CHECK_FLAG(p->af_sflags[afi][safi],
12348 PEER_STATUS_ORF_PREFIX_SEND))
12349 vty_out(vty, " sent;");
12350 if (orf_pfx_count)
12351 vty_out(vty, " received (%d entries)",
12352 orf_pfx_count);
12353 vty_out(vty, "\n");
12354 }
12355 if (CHECK_FLAG(p->af_sflags[afi][safi],
12356 PEER_STATUS_ORF_WAIT_REFRESH))
12357 vty_out(vty,
12358 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12359
12360 if (CHECK_FLAG(p->af_flags[afi][safi],
12361 PEER_FLAG_REFLECTOR_CLIENT))
12362 vty_out(vty, " Route-Reflector Client\n");
12363 if (CHECK_FLAG(p->af_flags[afi][safi],
12364 PEER_FLAG_RSERVER_CLIENT))
12365 vty_out(vty, " Route-Server Client\n");
12366 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12367 vty_out(vty,
12368 " Inbound soft reconfiguration allowed\n");
12369
12370 if (CHECK_FLAG(p->af_flags[afi][safi],
12371 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12372 vty_out(vty,
12373 " Private AS numbers (all) replaced in updates to this neighbor\n");
12374 else if (CHECK_FLAG(p->af_flags[afi][safi],
12375 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12376 vty_out(vty,
12377 " Private AS numbers replaced in updates to this neighbor\n");
12378 else if (CHECK_FLAG(p->af_flags[afi][safi],
12379 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12380 vty_out(vty,
12381 " Private AS numbers (all) removed in updates to this neighbor\n");
12382 else if (CHECK_FLAG(p->af_flags[afi][safi],
12383 PEER_FLAG_REMOVE_PRIVATE_AS))
12384 vty_out(vty,
12385 " Private AS numbers removed in updates to this neighbor\n");
12386
12387 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12388 vty_out(vty, " %s\n",
12389 bgp_addpath_names(p->addpath_type[afi][safi])
12390 ->human_description);
12391
12392 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12393 vty_out(vty,
12394 " Override ASNs in outbound updates if aspath equals remote-as\n");
12395
12396 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12397 || CHECK_FLAG(p->af_flags[afi][safi],
12398 PEER_FLAG_FORCE_NEXTHOP_SELF))
12399 vty_out(vty, " NEXT_HOP is always this router\n");
12400 if (CHECK_FLAG(p->af_flags[afi][safi],
12401 PEER_FLAG_AS_PATH_UNCHANGED))
12402 vty_out(vty,
12403 " AS_PATH is propagated unchanged to this neighbor\n");
12404 if (CHECK_FLAG(p->af_flags[afi][safi],
12405 PEER_FLAG_NEXTHOP_UNCHANGED))
12406 vty_out(vty,
12407 " NEXT_HOP is propagated unchanged to this neighbor\n");
12408 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12409 vty_out(vty,
12410 " MED is propagated unchanged to this neighbor\n");
12411 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12412 || CHECK_FLAG(p->af_flags[afi][safi],
12413 PEER_FLAG_SEND_EXT_COMMUNITY)
12414 || CHECK_FLAG(p->af_flags[afi][safi],
12415 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12416 vty_out(vty,
12417 " Community attribute sent to this neighbor");
12418 if (CHECK_FLAG(p->af_flags[afi][safi],
12419 PEER_FLAG_SEND_COMMUNITY)
12420 && CHECK_FLAG(p->af_flags[afi][safi],
12421 PEER_FLAG_SEND_EXT_COMMUNITY)
12422 && CHECK_FLAG(p->af_flags[afi][safi],
12423 PEER_FLAG_SEND_LARGE_COMMUNITY))
12424 vty_out(vty, "(all)\n");
12425 else if (CHECK_FLAG(p->af_flags[afi][safi],
12426 PEER_FLAG_SEND_LARGE_COMMUNITY))
12427 vty_out(vty, "(large)\n");
12428 else if (CHECK_FLAG(p->af_flags[afi][safi],
12429 PEER_FLAG_SEND_EXT_COMMUNITY))
12430 vty_out(vty, "(extended)\n");
12431 else
12432 vty_out(vty, "(standard)\n");
12433 }
12434 if (CHECK_FLAG(p->af_flags[afi][safi],
12435 PEER_FLAG_DEFAULT_ORIGINATE)) {
12436 vty_out(vty, " Default information originate,");
12437
12438 if (p->default_rmap[afi][safi].name)
12439 vty_out(vty, " default route-map %s%s,",
12440 p->default_rmap[afi][safi].map ? "*"
12441 : "",
12442 p->default_rmap[afi][safi].name);
12443 if (paf && PAF_SUBGRP(paf)
12444 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12445 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12446 vty_out(vty, " default sent\n");
12447 else
12448 vty_out(vty, " default not sent\n");
12449 }
12450
12451 /* advertise-vni-all */
12452 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12453 if (is_evpn_enabled())
12454 vty_out(vty, " advertise-all-vni\n");
12455 }
12456
12457 if (filter->plist[FILTER_IN].name
12458 || filter->dlist[FILTER_IN].name
12459 || filter->aslist[FILTER_IN].name
12460 || filter->map[RMAP_IN].name)
12461 vty_out(vty, " Inbound path policy configured\n");
12462 if (filter->plist[FILTER_OUT].name
12463 || filter->dlist[FILTER_OUT].name
12464 || filter->aslist[FILTER_OUT].name
12465 || filter->map[RMAP_OUT].name || filter->usmap.name)
12466 vty_out(vty, " Outbound path policy configured\n");
12467
12468 /* prefix-list */
12469 if (filter->plist[FILTER_IN].name)
12470 vty_out(vty,
12471 " Incoming update prefix filter list is %s%s\n",
12472 filter->plist[FILTER_IN].plist ? "*" : "",
12473 filter->plist[FILTER_IN].name);
12474 if (filter->plist[FILTER_OUT].name)
12475 vty_out(vty,
12476 " Outgoing update prefix filter list is %s%s\n",
12477 filter->plist[FILTER_OUT].plist ? "*" : "",
12478 filter->plist[FILTER_OUT].name);
12479
12480 /* distribute-list */
12481 if (filter->dlist[FILTER_IN].name)
12482 vty_out(vty,
12483 " Incoming update network filter list is %s%s\n",
12484 filter->dlist[FILTER_IN].alist ? "*" : "",
12485 filter->dlist[FILTER_IN].name);
12486 if (filter->dlist[FILTER_OUT].name)
12487 vty_out(vty,
12488 " Outgoing update network filter list is %s%s\n",
12489 filter->dlist[FILTER_OUT].alist ? "*" : "",
12490 filter->dlist[FILTER_OUT].name);
12491
12492 /* filter-list. */
12493 if (filter->aslist[FILTER_IN].name)
12494 vty_out(vty,
12495 " Incoming update AS path filter list is %s%s\n",
12496 filter->aslist[FILTER_IN].aslist ? "*" : "",
12497 filter->aslist[FILTER_IN].name);
12498 if (filter->aslist[FILTER_OUT].name)
12499 vty_out(vty,
12500 " Outgoing update AS path filter list is %s%s\n",
12501 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12502 filter->aslist[FILTER_OUT].name);
12503
12504 /* route-map. */
12505 if (filter->map[RMAP_IN].name)
12506 vty_out(vty,
12507 " Route map for incoming advertisements is %s%s\n",
12508 filter->map[RMAP_IN].map ? "*" : "",
12509 filter->map[RMAP_IN].name);
12510 if (filter->map[RMAP_OUT].name)
12511 vty_out(vty,
12512 " Route map for outgoing advertisements is %s%s\n",
12513 filter->map[RMAP_OUT].map ? "*" : "",
12514 filter->map[RMAP_OUT].name);
12515
12516 /* ebgp-requires-policy (inbound) */
12517 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12518 && !bgp_inbound_policy_exists(p, filter))
12519 vty_out(vty,
12520 " Inbound updates discarded due to missing policy\n");
12521
12522 /* ebgp-requires-policy (outbound) */
12523 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12524 && !bgp_outbound_policy_exists(p, filter))
12525 vty_out(vty,
12526 " Outbound updates discarded due to missing policy\n");
12527
12528 /* unsuppress-map */
12529 if (filter->usmap.name)
12530 vty_out(vty,
12531 " Route map for selective unsuppress is %s%s\n",
12532 filter->usmap.map ? "*" : "",
12533 filter->usmap.name);
12534
12535 /* advertise-map */
12536 if (filter->advmap.aname && filter->advmap.cname)
12537 vty_out(vty,
12538 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12539 filter->advmap.condition ? "EXIST"
12540 : "NON_EXIST",
12541 filter->advmap.cmap ? "*" : "",
12542 filter->advmap.cname,
12543 filter->advmap.amap ? "*" : "",
12544 filter->advmap.aname,
12545 filter->advmap.update_type ==
12546 UPDATE_TYPE_ADVERTISE
12547 ? "Advertise"
12548 : "Withdraw");
12549
12550 /* Receive prefix count */
12551 vty_out(vty, " %u accepted prefixes\n",
12552 p->pcount[afi][safi]);
12553
12554 /* maximum-prefix-out */
12555 if (CHECK_FLAG(p->af_flags[afi][safi],
12556 PEER_FLAG_MAX_PREFIX_OUT))
12557 vty_out(vty,
12558 " Maximum allowed prefixes sent %u\n",
12559 p->pmax_out[afi][safi]);
12560
12561 /* Maximum prefix */
12562 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12563 vty_out(vty,
12564 " Maximum prefixes allowed %u%s\n",
12565 p->pmax[afi][safi],
12566 CHECK_FLAG(p->af_flags[afi][safi],
12567 PEER_FLAG_MAX_PREFIX_WARNING)
12568 ? " (warning-only)"
12569 : "");
12570 vty_out(vty, " Threshold for warning message %d%%",
12571 p->pmax_threshold[afi][safi]);
12572 if (p->pmax_restart[afi][safi])
12573 vty_out(vty, ", restart interval %d min",
12574 p->pmax_restart[afi][safi]);
12575 vty_out(vty, "\n");
12576 }
12577
12578 vty_out(vty, "\n");
12579 }
12580 }
12581
12582 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12583 json_object *json)
12584 {
12585 struct bgp *bgp;
12586 char buf1[PREFIX2STR_BUFFER];
12587 char timebuf[BGP_UPTIME_LEN];
12588 char dn_flag[2];
12589 afi_t afi;
12590 safi_t safi;
12591 uint16_t i;
12592 uint8_t *msg;
12593 json_object *json_neigh = NULL;
12594 time_t epoch_tbuf;
12595 uint32_t sync_tcp_mss;
12596
12597 bgp = p->bgp;
12598
12599 if (use_json)
12600 json_neigh = json_object_new_object();
12601
12602 memset(dn_flag, '\0', sizeof(dn_flag));
12603 if (!p->conf_if && peer_dynamic_neighbor(p))
12604 dn_flag[0] = '*';
12605
12606 if (!use_json) {
12607 if (p->conf_if) /* Configured interface name. */
12608 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12609 &p->su);
12610 else /* Configured IP address. */
12611 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12612 p->host);
12613 }
12614
12615 if (use_json) {
12616 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12617 json_object_string_add(json_neigh, "bgpNeighborAddr",
12618 "none");
12619 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12620 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12621 "%pSU", &p->su);
12622
12623 json_object_int_add(json_neigh, "remoteAs", p->as);
12624
12625 if (p->change_local_as)
12626 json_object_int_add(json_neigh, "localAs",
12627 p->change_local_as);
12628 else
12629 json_object_int_add(json_neigh, "localAs", p->local_as);
12630
12631 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12632 json_object_boolean_true_add(json_neigh,
12633 "localAsNoPrepend");
12634
12635 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12636 json_object_boolean_true_add(json_neigh,
12637 "localAsReplaceAs");
12638 } else {
12639 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12640 || (p->as_type == AS_INTERNAL))
12641 vty_out(vty, "remote AS %u, ", p->as);
12642 else
12643 vty_out(vty, "remote AS Unspecified, ");
12644 vty_out(vty, "local AS %u%s%s, ",
12645 p->change_local_as ? p->change_local_as : p->local_as,
12646 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12647 ? " no-prepend"
12648 : "",
12649 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12650 ? " replace-as"
12651 : "");
12652 }
12653 /* peer type internal or confed-internal */
12654 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12655 if (use_json) {
12656 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12657 json_object_boolean_true_add(
12658 json_neigh, "nbrConfedInternalLink");
12659 else
12660 json_object_boolean_true_add(json_neigh,
12661 "nbrInternalLink");
12662 } else {
12663 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12664 vty_out(vty, "confed-internal link\n");
12665 else
12666 vty_out(vty, "internal link\n");
12667 }
12668 /* peer type external or confed-external */
12669 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12670 if (use_json) {
12671 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12672 json_object_boolean_true_add(
12673 json_neigh, "nbrConfedExternalLink");
12674 else
12675 json_object_boolean_true_add(json_neigh,
12676 "nbrExternalLink");
12677 } else {
12678 if (bgp_confederation_peers_check(bgp, p->as))
12679 vty_out(vty, "confed-external link\n");
12680 else
12681 vty_out(vty, "external link\n");
12682 }
12683 } else {
12684 if (use_json)
12685 json_object_boolean_true_add(json_neigh,
12686 "nbrUnspecifiedLink");
12687 else
12688 vty_out(vty, "unspecified link\n");
12689 }
12690
12691 /* Roles */
12692 if (use_json) {
12693 json_object_string_add(json_neigh, "localRole",
12694 bgp_get_name_by_role(p->local_role));
12695 json_object_string_add(json_neigh, "remoteRole",
12696 bgp_get_name_by_role(p->remote_role));
12697 } else {
12698 vty_out(vty, " Local Role: %s\n",
12699 bgp_get_name_by_role(p->local_role));
12700 vty_out(vty, " Remote Role: %s\n",
12701 bgp_get_name_by_role(p->remote_role));
12702 }
12703
12704
12705 /* Description. */
12706 if (p->desc) {
12707 if (use_json)
12708 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12709 else
12710 vty_out(vty, " Description: %s\n", p->desc);
12711 }
12712
12713 if (p->hostname) {
12714 if (use_json) {
12715 if (p->hostname)
12716 json_object_string_add(json_neigh, "hostname",
12717 p->hostname);
12718
12719 if (p->domainname)
12720 json_object_string_add(json_neigh, "domainname",
12721 p->domainname);
12722 } else {
12723 if (p->domainname && (p->domainname[0] != '\0'))
12724 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12725 p->domainname);
12726 else
12727 vty_out(vty, "Hostname: %s\n", p->hostname);
12728 }
12729 }
12730
12731 /* Peer-group */
12732 if (p->group) {
12733 if (use_json) {
12734 json_object_string_add(json_neigh, "peerGroup",
12735 p->group->name);
12736
12737 if (dn_flag[0]) {
12738 struct prefix prefix, *range = NULL;
12739
12740 if (sockunion2hostprefix(&(p->su), &prefix))
12741 range = peer_group_lookup_dynamic_neighbor_range(
12742 p->group, &prefix);
12743
12744 if (range) {
12745 json_object_string_addf(
12746 json_neigh,
12747 "peerSubnetRangeGroup", "%pFX",
12748 range);
12749 }
12750 }
12751 } else {
12752 vty_out(vty,
12753 " Member of peer-group %s for session parameters\n",
12754 p->group->name);
12755
12756 if (dn_flag[0]) {
12757 struct prefix prefix, *range = NULL;
12758
12759 if (sockunion2hostprefix(&(p->su), &prefix))
12760 range = peer_group_lookup_dynamic_neighbor_range(
12761 p->group, &prefix);
12762
12763 if (range) {
12764 vty_out(vty,
12765 " Belongs to the subnet range group: %pFX\n",
12766 range);
12767 }
12768 }
12769 }
12770 }
12771
12772 if (use_json) {
12773 /* Administrative shutdown. */
12774 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12775 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12776 json_object_boolean_true_add(json_neigh,
12777 "adminShutDown");
12778
12779 /* BGP Version. */
12780 json_object_int_add(json_neigh, "bgpVersion", 4);
12781 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12782 &p->remote_id);
12783 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12784 &bgp->router_id);
12785
12786 /* Confederation */
12787 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12788 && bgp_confederation_peers_check(bgp, p->as))
12789 json_object_boolean_true_add(json_neigh,
12790 "nbrCommonAdmin");
12791
12792 /* Status. */
12793 json_object_string_add(
12794 json_neigh, "bgpState",
12795 lookup_msg(bgp_status_msg, p->status, NULL));
12796
12797 if (peer_established(p)) {
12798 time_t uptime;
12799
12800 uptime = monotime(NULL);
12801 uptime -= p->uptime;
12802 epoch_tbuf = time(NULL) - uptime;
12803
12804 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12805 uptime * 1000);
12806 json_object_string_add(json_neigh, "bgpTimerUpString",
12807 peer_uptime(p->uptime, timebuf,
12808 BGP_UPTIME_LEN, 0,
12809 NULL));
12810 json_object_int_add(json_neigh,
12811 "bgpTimerUpEstablishedEpoch",
12812 epoch_tbuf);
12813 }
12814
12815 else if (p->status == Active) {
12816 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12817 json_object_string_add(json_neigh, "bgpStateIs",
12818 "passive");
12819 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12820 json_object_string_add(json_neigh, "bgpStateIs",
12821 "passiveNSF");
12822 }
12823
12824 /* read timer */
12825 time_t uptime;
12826 struct tm tm;
12827
12828 uptime = monotime(NULL);
12829 uptime -= p->readtime;
12830 gmtime_r(&uptime, &tm);
12831
12832 json_object_int_add(json_neigh, "bgpTimerLastRead",
12833 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12834 + (tm.tm_hour * 3600000));
12835
12836 uptime = monotime(NULL);
12837 uptime -= p->last_write;
12838 gmtime_r(&uptime, &tm);
12839
12840 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12841 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12842 + (tm.tm_hour * 3600000));
12843
12844 uptime = monotime(NULL);
12845 uptime -= p->update_time;
12846 gmtime_r(&uptime, &tm);
12847
12848 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12849 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12850 + (tm.tm_hour * 3600000));
12851
12852 /* Configured timer values. */
12853 json_object_int_add(json_neigh,
12854 "bgpTimerConfiguredHoldTimeMsecs",
12855 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12856 ? p->holdtime * 1000
12857 : bgp->default_holdtime * 1000);
12858 json_object_int_add(json_neigh,
12859 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12860 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12861 ? p->keepalive * 1000
12862 : bgp->default_keepalive * 1000);
12863 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12864 p->v_holdtime * 1000);
12865 json_object_int_add(json_neigh,
12866 "bgpTimerKeepAliveIntervalMsecs",
12867 p->v_keepalive * 1000);
12868 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12869 json_object_int_add(json_neigh,
12870 "bgpTimerDelayOpenTimeMsecs",
12871 p->v_delayopen * 1000);
12872 }
12873
12874 /* Configured and Synced tcp-mss value for peer */
12875 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12876 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12877 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12878 p->tcp_mss);
12879 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12880 sync_tcp_mss);
12881 }
12882
12883 /* Extended Optional Parameters Length for BGP OPEN Message */
12884 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12885 json_object_boolean_true_add(
12886 json_neigh, "extendedOptionalParametersLength");
12887 else
12888 json_object_boolean_false_add(
12889 json_neigh, "extendedOptionalParametersLength");
12890
12891 /* Conditional advertisements */
12892 json_object_int_add(
12893 json_neigh,
12894 "bgpTimerConfiguredConditionalAdvertisementsSec",
12895 bgp->condition_check_period);
12896 if (thread_is_scheduled(bgp->t_condition_check))
12897 json_object_int_add(
12898 json_neigh,
12899 "bgpTimerUntilConditionalAdvertisementsSec",
12900 thread_timer_remain_second(
12901 bgp->t_condition_check));
12902 } else {
12903 /* Administrative shutdown. */
12904 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12905 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12906 vty_out(vty, " Administratively shut down\n");
12907
12908 /* BGP Version. */
12909 vty_out(vty, " BGP version 4");
12910 vty_out(vty, ", remote router ID %s",
12911 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12912 vty_out(vty, ", local router ID %s\n",
12913 inet_ntop(AF_INET, &bgp->router_id, buf1,
12914 sizeof(buf1)));
12915
12916 /* Confederation */
12917 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12918 && bgp_confederation_peers_check(bgp, p->as))
12919 vty_out(vty,
12920 " Neighbor under common administration\n");
12921
12922 /* Status. */
12923 vty_out(vty, " BGP state = %s",
12924 lookup_msg(bgp_status_msg, p->status, NULL));
12925
12926 if (peer_established(p))
12927 vty_out(vty, ", up for %8s",
12928 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12929 0, NULL));
12930
12931 else if (p->status == Active) {
12932 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12933 vty_out(vty, " (passive)");
12934 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12935 vty_out(vty, " (NSF passive)");
12936 }
12937 vty_out(vty, "\n");
12938
12939 /* read timer */
12940 vty_out(vty, " Last read %s",
12941 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12942 NULL));
12943 vty_out(vty, ", Last write %s\n",
12944 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12945 NULL));
12946
12947 /* Configured timer values. */
12948 vty_out(vty,
12949 " Hold time is %d seconds, keepalive interval is %d seconds\n",
12950 p->v_holdtime, p->v_keepalive);
12951 vty_out(vty, " Configured hold time is %d seconds",
12952 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12953 ? p->holdtime
12954 : bgp->default_holdtime);
12955 vty_out(vty, ", keepalive interval is %d seconds\n",
12956 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12957 ? p->keepalive
12958 : bgp->default_keepalive);
12959 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12960 vty_out(vty,
12961 " Configured DelayOpenTime is %d seconds\n",
12962 p->delayopen);
12963
12964 /* Configured and synced tcp-mss value for peer */
12965 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12966 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12967 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12968 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12969 }
12970
12971 /* Extended Optional Parameters Length for BGP OPEN Message */
12972 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12973 vty_out(vty,
12974 " Extended Optional Parameters Length is enabled\n");
12975
12976 /* Conditional advertisements */
12977 vty_out(vty,
12978 " Configured conditional advertisements interval is %d seconds\n",
12979 bgp->condition_check_period);
12980 if (thread_is_scheduled(bgp->t_condition_check))
12981 vty_out(vty,
12982 " Time until conditional advertisements begin is %lu seconds\n",
12983 thread_timer_remain_second(
12984 bgp->t_condition_check));
12985 }
12986 /* Capability. */
12987 if (peer_established(p) &&
12988 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12989 if (use_json) {
12990 json_object *json_cap = NULL;
12991
12992 json_cap = json_object_new_object();
12993
12994 /* AS4 */
12995 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12996 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12997 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12998 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12999 json_object_string_add(
13000 json_cap, "4byteAs",
13001 "advertisedAndReceived");
13002 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13003 json_object_string_add(json_cap,
13004 "4byteAs",
13005 "advertised");
13006 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13007 json_object_string_add(json_cap,
13008 "4byteAs",
13009 "received");
13010 }
13011
13012 /* Extended Message Support */
13013 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13014 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13015 json_object_string_add(json_cap,
13016 "extendedMessage",
13017 "advertisedAndReceived");
13018 else if (CHECK_FLAG(p->cap,
13019 PEER_CAP_EXTENDED_MESSAGE_ADV))
13020 json_object_string_add(json_cap,
13021 "extendedMessage",
13022 "advertised");
13023 else if (CHECK_FLAG(p->cap,
13024 PEER_CAP_EXTENDED_MESSAGE_RCV))
13025 json_object_string_add(json_cap,
13026 "extendedMessage",
13027 "received");
13028
13029 /* AddPath */
13030 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13031 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13032 json_object *json_add = NULL;
13033 const char *print_store;
13034
13035 json_add = json_object_new_object();
13036
13037 FOREACH_AFI_SAFI (afi, safi) {
13038 json_object *json_sub = NULL;
13039 json_sub = json_object_new_object();
13040 print_store = get_afi_safi_str(
13041 afi, safi, true);
13042
13043 if (CHECK_FLAG(
13044 p->af_cap[afi][safi],
13045 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13046 CHECK_FLAG(
13047 p->af_cap[afi][safi],
13048 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13049 if (CHECK_FLAG(
13050 p->af_cap[afi]
13051 [safi],
13052 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13053 CHECK_FLAG(
13054 p->af_cap[afi]
13055 [safi],
13056 PEER_CAP_ADDPATH_AF_TX_RCV))
13057 json_object_boolean_true_add(
13058 json_sub,
13059 "txAdvertisedAndReceived");
13060 else if (
13061 CHECK_FLAG(
13062 p->af_cap[afi]
13063 [safi],
13064 PEER_CAP_ADDPATH_AF_TX_ADV))
13065 json_object_boolean_true_add(
13066 json_sub,
13067 "txAdvertised");
13068 else if (
13069 CHECK_FLAG(
13070 p->af_cap[afi]
13071 [safi],
13072 PEER_CAP_ADDPATH_AF_TX_RCV))
13073 json_object_boolean_true_add(
13074 json_sub,
13075 "txReceived");
13076 }
13077
13078 if (CHECK_FLAG(
13079 p->af_cap[afi][safi],
13080 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13081 CHECK_FLAG(
13082 p->af_cap[afi][safi],
13083 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13084 if (CHECK_FLAG(
13085 p->af_cap[afi]
13086 [safi],
13087 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13088 CHECK_FLAG(
13089 p->af_cap[afi]
13090 [safi],
13091 PEER_CAP_ADDPATH_AF_RX_RCV))
13092 json_object_boolean_true_add(
13093 json_sub,
13094 "rxAdvertisedAndReceived");
13095 else if (
13096 CHECK_FLAG(
13097 p->af_cap[afi]
13098 [safi],
13099 PEER_CAP_ADDPATH_AF_RX_ADV))
13100 json_object_boolean_true_add(
13101 json_sub,
13102 "rxAdvertised");
13103 else if (
13104 CHECK_FLAG(
13105 p->af_cap[afi]
13106 [safi],
13107 PEER_CAP_ADDPATH_AF_RX_RCV))
13108 json_object_boolean_true_add(
13109 json_sub,
13110 "rxReceived");
13111 }
13112
13113 if (CHECK_FLAG(
13114 p->af_cap[afi][safi],
13115 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13116 CHECK_FLAG(
13117 p->af_cap[afi][safi],
13118 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13119 CHECK_FLAG(
13120 p->af_cap[afi][safi],
13121 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13122 CHECK_FLAG(
13123 p->af_cap[afi][safi],
13124 PEER_CAP_ADDPATH_AF_RX_RCV))
13125 json_object_object_add(
13126 json_add, print_store,
13127 json_sub);
13128 else
13129 json_object_free(json_sub);
13130 }
13131
13132 json_object_object_add(json_cap, "addPath",
13133 json_add);
13134 }
13135
13136 /* Dynamic */
13137 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13138 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13139 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13140 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13141 json_object_string_add(
13142 json_cap, "dynamic",
13143 "advertisedAndReceived");
13144 else if (CHECK_FLAG(p->cap,
13145 PEER_CAP_DYNAMIC_ADV))
13146 json_object_string_add(json_cap,
13147 "dynamic",
13148 "advertised");
13149 else if (CHECK_FLAG(p->cap,
13150 PEER_CAP_DYNAMIC_RCV))
13151 json_object_string_add(json_cap,
13152 "dynamic",
13153 "received");
13154 }
13155
13156 /* Role */
13157 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13158 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13159 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13160 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13161 json_object_string_add(
13162 json_cap, "role",
13163 "advertisedAndReceived");
13164 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13165 json_object_string_add(json_cap, "role",
13166 "advertised");
13167 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13168 json_object_string_add(json_cap, "role",
13169 "received");
13170 }
13171
13172 /* Extended nexthop */
13173 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13174 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13175 json_object *json_nxt = NULL;
13176 const char *print_store;
13177
13178
13179 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13180 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13181 json_object_string_add(
13182 json_cap, "extendedNexthop",
13183 "advertisedAndReceived");
13184 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13185 json_object_string_add(
13186 json_cap, "extendedNexthop",
13187 "advertised");
13188 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13189 json_object_string_add(
13190 json_cap, "extendedNexthop",
13191 "received");
13192
13193 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13194 json_nxt = json_object_new_object();
13195
13196 for (safi = SAFI_UNICAST;
13197 safi < SAFI_MAX; safi++) {
13198 if (CHECK_FLAG(
13199 p->af_cap[AFI_IP]
13200 [safi],
13201 PEER_CAP_ENHE_AF_RCV)) {
13202 print_store =
13203 get_afi_safi_str(
13204 AFI_IP,
13205 safi,
13206 true);
13207 json_object_string_add(
13208 json_nxt,
13209 print_store,
13210 "recieved"); /* misspelled for compatibility */
13211 }
13212 }
13213 json_object_object_add(
13214 json_cap,
13215 "extendedNexthopFamililesByPeer",
13216 json_nxt);
13217 }
13218 }
13219
13220 /* Long-lived Graceful Restart */
13221 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13222 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13223 json_object *json_llgr = NULL;
13224 const char *afi_safi_str;
13225
13226 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13227 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13228 json_object_string_add(
13229 json_cap,
13230 "longLivedGracefulRestart",
13231 "advertisedAndReceived");
13232 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13233 json_object_string_add(
13234 json_cap,
13235 "longLivedGracefulRestart",
13236 "advertised");
13237 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13238 json_object_string_add(
13239 json_cap,
13240 "longLivedGracefulRestart",
13241 "received");
13242
13243 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13244 json_llgr = json_object_new_object();
13245
13246 FOREACH_AFI_SAFI (afi, safi) {
13247 if (CHECK_FLAG(
13248 p->af_cap[afi]
13249 [safi],
13250 PEER_CAP_ENHE_AF_RCV)) {
13251 afi_safi_str =
13252 get_afi_safi_str(
13253 afi,
13254 safi,
13255 true);
13256 json_object_string_add(
13257 json_llgr,
13258 afi_safi_str,
13259 "received");
13260 }
13261 }
13262 json_object_object_add(
13263 json_cap,
13264 "longLivedGracefulRestartByPeer",
13265 json_llgr);
13266 }
13267 }
13268
13269 /* Route Refresh */
13270 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13271 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13272 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13273 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13274 (CHECK_FLAG(p->cap,
13275 PEER_CAP_REFRESH_NEW_RCV) ||
13276 CHECK_FLAG(p->cap,
13277 PEER_CAP_REFRESH_OLD_RCV))) {
13278 if (CHECK_FLAG(
13279 p->cap,
13280 PEER_CAP_REFRESH_OLD_RCV) &&
13281 CHECK_FLAG(
13282 p->cap,
13283 PEER_CAP_REFRESH_NEW_RCV))
13284 json_object_string_add(
13285 json_cap,
13286 "routeRefresh",
13287 "advertisedAndReceivedOldNew");
13288 else {
13289 if (CHECK_FLAG(
13290 p->cap,
13291 PEER_CAP_REFRESH_OLD_RCV))
13292 json_object_string_add(
13293 json_cap,
13294 "routeRefresh",
13295 "advertisedAndReceivedOld");
13296 else
13297 json_object_string_add(
13298 json_cap,
13299 "routeRefresh",
13300 "advertisedAndReceivedNew");
13301 }
13302 } else if (CHECK_FLAG(p->cap,
13303 PEER_CAP_REFRESH_ADV))
13304 json_object_string_add(json_cap,
13305 "routeRefresh",
13306 "advertised");
13307 else if (CHECK_FLAG(p->cap,
13308 PEER_CAP_REFRESH_NEW_RCV) ||
13309 CHECK_FLAG(p->cap,
13310 PEER_CAP_REFRESH_OLD_RCV))
13311 json_object_string_add(json_cap,
13312 "routeRefresh",
13313 "received");
13314 }
13315
13316 /* Enhanced Route Refresh */
13317 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13318 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13319 if (CHECK_FLAG(p->cap,
13320 PEER_CAP_ENHANCED_RR_ADV) &&
13321 CHECK_FLAG(p->cap,
13322 PEER_CAP_ENHANCED_RR_RCV))
13323 json_object_string_add(
13324 json_cap,
13325 "enhancedRouteRefresh",
13326 "advertisedAndReceived");
13327 else if (CHECK_FLAG(p->cap,
13328 PEER_CAP_ENHANCED_RR_ADV))
13329 json_object_string_add(
13330 json_cap,
13331 "enhancedRouteRefresh",
13332 "advertised");
13333 else if (CHECK_FLAG(p->cap,
13334 PEER_CAP_ENHANCED_RR_RCV))
13335 json_object_string_add(
13336 json_cap,
13337 "enhancedRouteRefresh",
13338 "received");
13339 }
13340
13341 /* Multiprotocol Extensions */
13342 json_object *json_multi = NULL;
13343
13344 json_multi = json_object_new_object();
13345
13346 FOREACH_AFI_SAFI (afi, safi) {
13347 if (p->afc_adv[afi][safi] ||
13348 p->afc_recv[afi][safi]) {
13349 json_object *json_exten = NULL;
13350 json_exten = json_object_new_object();
13351
13352 if (p->afc_adv[afi][safi] &&
13353 p->afc_recv[afi][safi])
13354 json_object_boolean_true_add(
13355 json_exten,
13356 "advertisedAndReceived");
13357 else if (p->afc_adv[afi][safi])
13358 json_object_boolean_true_add(
13359 json_exten,
13360 "advertised");
13361 else if (p->afc_recv[afi][safi])
13362 json_object_boolean_true_add(
13363 json_exten, "received");
13364
13365 json_object_object_add(
13366 json_multi,
13367 get_afi_safi_str(afi, safi,
13368 true),
13369 json_exten);
13370 }
13371 }
13372 json_object_object_add(json_cap,
13373 "multiprotocolExtensions",
13374 json_multi);
13375
13376 /* Hostname capabilities */
13377 json_object *json_hname = NULL;
13378
13379 json_hname = json_object_new_object();
13380
13381 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13382 json_object_string_add(
13383 json_hname, "advHostName",
13384 bgp->peer_self->hostname
13385 ? bgp->peer_self->hostname
13386 : "n/a");
13387 json_object_string_add(
13388 json_hname, "advDomainName",
13389 bgp->peer_self->domainname
13390 ? bgp->peer_self->domainname
13391 : "n/a");
13392 }
13393
13394
13395 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13396 json_object_string_add(
13397 json_hname, "rcvHostName",
13398 p->hostname ? p->hostname : "n/a");
13399 json_object_string_add(
13400 json_hname, "rcvDomainName",
13401 p->domainname ? p->domainname : "n/a");
13402 }
13403
13404 json_object_object_add(json_cap, "hostName",
13405 json_hname);
13406
13407 /* Graceful Restart */
13408 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13409 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13410 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13411 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13412 json_object_string_add(
13413 json_cap, "gracefulRestart",
13414 "advertisedAndReceived");
13415 else if (CHECK_FLAG(p->cap,
13416 PEER_CAP_RESTART_ADV))
13417 json_object_string_add(
13418 json_cap,
13419 "gracefulRestartCapability",
13420 "advertised");
13421 else if (CHECK_FLAG(p->cap,
13422 PEER_CAP_RESTART_RCV))
13423 json_object_string_add(
13424 json_cap,
13425 "gracefulRestartCapability",
13426 "received");
13427
13428 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13429 int restart_af_count = 0;
13430 json_object *json_restart = NULL;
13431 json_restart = json_object_new_object();
13432
13433 json_object_int_add(
13434 json_cap,
13435 "gracefulRestartRemoteTimerMsecs",
13436 p->v_gr_restart * 1000);
13437
13438 FOREACH_AFI_SAFI (afi, safi) {
13439 if (CHECK_FLAG(
13440 p->af_cap[afi]
13441 [safi],
13442 PEER_CAP_RESTART_AF_RCV)) {
13443 json_object *json_sub =
13444 NULL;
13445 json_sub =
13446 json_object_new_object();
13447
13448 if (CHECK_FLAG(
13449 p->af_cap
13450 [afi]
13451 [safi],
13452 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13453 json_object_boolean_true_add(
13454 json_sub,
13455 "preserved");
13456 restart_af_count++;
13457 json_object_object_add(
13458 json_restart,
13459 get_afi_safi_str(
13460 afi,
13461 safi,
13462 true),
13463 json_sub);
13464 }
13465 }
13466 if (!restart_af_count) {
13467 json_object_string_add(
13468 json_cap,
13469 "addressFamiliesByPeer",
13470 "none");
13471 json_object_free(json_restart);
13472 } else
13473 json_object_object_add(
13474 json_cap,
13475 "addressFamiliesByPeer",
13476 json_restart);
13477 }
13478 }
13479 json_object_object_add(
13480 json_neigh, "neighborCapabilities", json_cap);
13481 } else {
13482 vty_out(vty, " Neighbor capabilities:\n");
13483
13484 /* AS4 */
13485 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13486 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13487 vty_out(vty, " 4 Byte AS:");
13488 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13489 vty_out(vty, " advertised");
13490 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13491 vty_out(vty, " %sreceived",
13492 CHECK_FLAG(p->cap,
13493 PEER_CAP_AS4_ADV)
13494 ? "and "
13495 : "");
13496 vty_out(vty, "\n");
13497 }
13498
13499 /* Extended Message Support */
13500 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13501 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13502 vty_out(vty, " Extended Message:");
13503 if (CHECK_FLAG(p->cap,
13504 PEER_CAP_EXTENDED_MESSAGE_ADV))
13505 vty_out(vty, " advertised");
13506 if (CHECK_FLAG(p->cap,
13507 PEER_CAP_EXTENDED_MESSAGE_RCV))
13508 vty_out(vty, " %sreceived",
13509 CHECK_FLAG(
13510 p->cap,
13511 PEER_CAP_EXTENDED_MESSAGE_ADV)
13512 ? "and "
13513 : "");
13514 vty_out(vty, "\n");
13515 }
13516
13517 /* AddPath */
13518 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13519 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13520 vty_out(vty, " AddPath:\n");
13521
13522 FOREACH_AFI_SAFI (afi, safi) {
13523 if (CHECK_FLAG(
13524 p->af_cap[afi][safi],
13525 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13526 CHECK_FLAG(
13527 p->af_cap[afi][safi],
13528 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13529 vty_out(vty, " %s: TX ",
13530 get_afi_safi_str(
13531 afi, safi,
13532 false));
13533
13534 if (CHECK_FLAG(
13535 p->af_cap[afi]
13536 [safi],
13537 PEER_CAP_ADDPATH_AF_TX_ADV))
13538 vty_out(vty,
13539 "advertised");
13540
13541 if (CHECK_FLAG(
13542 p->af_cap[afi]
13543 [safi],
13544 PEER_CAP_ADDPATH_AF_TX_RCV))
13545 vty_out(vty,
13546 "%sreceived",
13547 CHECK_FLAG(
13548 p->af_cap
13549 [afi]
13550 [safi],
13551 PEER_CAP_ADDPATH_AF_TX_ADV)
13552 ? " and "
13553 : "");
13554
13555 vty_out(vty, "\n");
13556 }
13557
13558 if (CHECK_FLAG(
13559 p->af_cap[afi][safi],
13560 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13561 CHECK_FLAG(
13562 p->af_cap[afi][safi],
13563 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13564 vty_out(vty, " %s: RX ",
13565 get_afi_safi_str(
13566 afi, safi,
13567 false));
13568
13569 if (CHECK_FLAG(
13570 p->af_cap[afi]
13571 [safi],
13572 PEER_CAP_ADDPATH_AF_RX_ADV))
13573 vty_out(vty,
13574 "advertised");
13575
13576 if (CHECK_FLAG(
13577 p->af_cap[afi]
13578 [safi],
13579 PEER_CAP_ADDPATH_AF_RX_RCV))
13580 vty_out(vty,
13581 "%sreceived",
13582 CHECK_FLAG(
13583 p->af_cap
13584 [afi]
13585 [safi],
13586 PEER_CAP_ADDPATH_AF_RX_ADV)
13587 ? " and "
13588 : "");
13589
13590 vty_out(vty, "\n");
13591 }
13592 }
13593 }
13594
13595 /* Dynamic */
13596 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13597 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13598 vty_out(vty, " Dynamic:");
13599 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13600 vty_out(vty, " advertised");
13601 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13602 vty_out(vty, " %sreceived",
13603 CHECK_FLAG(p->cap,
13604 PEER_CAP_DYNAMIC_ADV)
13605 ? "and "
13606 : "");
13607 vty_out(vty, "\n");
13608 }
13609
13610 /* Role */
13611 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13612 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13613 vty_out(vty, " Role:");
13614 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13615 vty_out(vty, " advertised");
13616 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13617 vty_out(vty, " %sreceived",
13618 CHECK_FLAG(p->cap,
13619 PEER_CAP_ROLE_ADV)
13620 ? "and "
13621 : "");
13622 vty_out(vty, "\n");
13623 }
13624
13625 /* Extended nexthop */
13626 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13627 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13628 vty_out(vty, " Extended nexthop:");
13629 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13630 vty_out(vty, " advertised");
13631 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13632 vty_out(vty, " %sreceived",
13633 CHECK_FLAG(p->cap,
13634 PEER_CAP_ENHE_ADV)
13635 ? "and "
13636 : "");
13637 vty_out(vty, "\n");
13638
13639 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13640 vty_out(vty,
13641 " Address families by peer:\n ");
13642 for (safi = SAFI_UNICAST;
13643 safi < SAFI_MAX; safi++)
13644 if (CHECK_FLAG(
13645 p->af_cap[AFI_IP]
13646 [safi],
13647 PEER_CAP_ENHE_AF_RCV))
13648 vty_out(vty,
13649 " %s\n",
13650 get_afi_safi_str(
13651 AFI_IP,
13652 safi,
13653 false));
13654 }
13655 }
13656
13657 /* Long-lived Graceful Restart */
13658 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13659 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13660 vty_out(vty,
13661 " Long-lived Graceful Restart:");
13662 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13663 vty_out(vty, " advertised");
13664 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13665 vty_out(vty, " %sreceived",
13666 CHECK_FLAG(p->cap,
13667 PEER_CAP_LLGR_ADV)
13668 ? "and "
13669 : "");
13670 vty_out(vty, "\n");
13671
13672 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13673 vty_out(vty,
13674 " Address families by peer:\n");
13675 FOREACH_AFI_SAFI (afi, safi)
13676 if (CHECK_FLAG(
13677 p->af_cap[afi]
13678 [safi],
13679 PEER_CAP_LLGR_AF_RCV))
13680 vty_out(vty,
13681 " %s\n",
13682 get_afi_safi_str(
13683 afi,
13684 safi,
13685 false));
13686 }
13687 }
13688
13689 /* Route Refresh */
13690 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13691 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13692 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13693 vty_out(vty, " Route refresh:");
13694 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13695 vty_out(vty, " advertised");
13696 if (CHECK_FLAG(p->cap,
13697 PEER_CAP_REFRESH_NEW_RCV) ||
13698 CHECK_FLAG(p->cap,
13699 PEER_CAP_REFRESH_OLD_RCV))
13700 vty_out(vty, " %sreceived(%s)",
13701 CHECK_FLAG(p->cap,
13702 PEER_CAP_REFRESH_ADV)
13703 ? "and "
13704 : "",
13705 (CHECK_FLAG(
13706 p->cap,
13707 PEER_CAP_REFRESH_OLD_RCV) &&
13708 CHECK_FLAG(
13709 p->cap,
13710 PEER_CAP_REFRESH_NEW_RCV))
13711 ? "old & new"
13712 : CHECK_FLAG(
13713 p->cap,
13714 PEER_CAP_REFRESH_OLD_RCV)
13715 ? "old"
13716 : "new");
13717
13718 vty_out(vty, "\n");
13719 }
13720
13721 /* Enhanced Route Refresh */
13722 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13723 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13724 vty_out(vty, " Enhanced Route Refresh:");
13725 if (CHECK_FLAG(p->cap,
13726 PEER_CAP_ENHANCED_RR_ADV))
13727 vty_out(vty, " advertised");
13728 if (CHECK_FLAG(p->cap,
13729 PEER_CAP_ENHANCED_RR_RCV))
13730 vty_out(vty, " %sreceived",
13731 CHECK_FLAG(p->cap,
13732 PEER_CAP_REFRESH_ADV)
13733 ? "and "
13734 : "");
13735 vty_out(vty, "\n");
13736 }
13737
13738 /* Multiprotocol Extensions */
13739 FOREACH_AFI_SAFI (afi, safi)
13740 if (p->afc_adv[afi][safi] ||
13741 p->afc_recv[afi][safi]) {
13742 vty_out(vty, " Address Family %s:",
13743 get_afi_safi_str(afi, safi,
13744 false));
13745 if (p->afc_adv[afi][safi])
13746 vty_out(vty, " advertised");
13747 if (p->afc_recv[afi][safi])
13748 vty_out(vty, " %sreceived",
13749 p->afc_adv[afi][safi]
13750 ? "and "
13751 : "");
13752 vty_out(vty, "\n");
13753 }
13754
13755 /* Hostname capability */
13756 vty_out(vty, " Hostname Capability:");
13757
13758 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13759 vty_out(vty,
13760 " advertised (name: %s,domain name: %s)",
13761 bgp->peer_self->hostname
13762 ? bgp->peer_self->hostname
13763 : "n/a",
13764 bgp->peer_self->domainname
13765 ? bgp->peer_self->domainname
13766 : "n/a");
13767 } else {
13768 vty_out(vty, " not advertised");
13769 }
13770
13771 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13772 vty_out(vty,
13773 " received (name: %s,domain name: %s)",
13774 p->hostname ? p->hostname : "n/a",
13775 p->domainname ? p->domainname : "n/a");
13776 } else {
13777 vty_out(vty, " not received");
13778 }
13779
13780 vty_out(vty, "\n");
13781
13782 /* Graceful Restart */
13783 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13784 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13785 vty_out(vty,
13786 " Graceful Restart Capability:");
13787 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13788 vty_out(vty, " advertised");
13789 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13790 vty_out(vty, " %sreceived",
13791 CHECK_FLAG(p->cap,
13792 PEER_CAP_RESTART_ADV)
13793 ? "and "
13794 : "");
13795 vty_out(vty, "\n");
13796
13797 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13798 int restart_af_count = 0;
13799
13800 vty_out(vty,
13801 " Remote Restart timer is %d seconds\n",
13802 p->v_gr_restart);
13803 vty_out(vty,
13804 " Address families by peer:\n ");
13805
13806 FOREACH_AFI_SAFI (afi, safi)
13807 if (CHECK_FLAG(
13808 p->af_cap[afi]
13809 [safi],
13810 PEER_CAP_RESTART_AF_RCV)) {
13811 vty_out(vty, "%s%s(%s)",
13812 restart_af_count
13813 ? ", "
13814 : "",
13815 get_afi_safi_str(
13816 afi,
13817 safi,
13818 false),
13819 CHECK_FLAG(
13820 p->af_cap
13821 [afi]
13822 [safi],
13823 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13824 ? "preserved"
13825 : "not preserved");
13826 restart_af_count++;
13827 }
13828 if (!restart_af_count)
13829 vty_out(vty, "none");
13830 vty_out(vty, "\n");
13831 }
13832 } /* Graceful Restart */
13833 }
13834 }
13835
13836 /* graceful restart information */
13837 json_object *json_grace = NULL;
13838 json_object *json_grace_send = NULL;
13839 json_object *json_grace_recv = NULL;
13840 int eor_send_af_count = 0;
13841 int eor_receive_af_count = 0;
13842
13843 if (use_json) {
13844 json_grace = json_object_new_object();
13845 json_grace_send = json_object_new_object();
13846 json_grace_recv = json_object_new_object();
13847
13848 if ((peer_established(p)) &&
13849 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13850 FOREACH_AFI_SAFI (afi, safi) {
13851 if (CHECK_FLAG(p->af_sflags[afi][safi],
13852 PEER_STATUS_EOR_SEND)) {
13853 json_object_boolean_true_add(
13854 json_grace_send,
13855 get_afi_safi_str(afi, safi,
13856 true));
13857 eor_send_af_count++;
13858 }
13859 }
13860 FOREACH_AFI_SAFI (afi, safi) {
13861 if (CHECK_FLAG(p->af_sflags[afi][safi],
13862 PEER_STATUS_EOR_RECEIVED)) {
13863 json_object_boolean_true_add(
13864 json_grace_recv,
13865 get_afi_safi_str(afi, safi,
13866 true));
13867 eor_receive_af_count++;
13868 }
13869 }
13870 }
13871 json_object_object_add(json_grace, "endOfRibSend",
13872 json_grace_send);
13873 json_object_object_add(json_grace, "endOfRibRecv",
13874 json_grace_recv);
13875
13876
13877 if (p->t_gr_restart)
13878 json_object_int_add(
13879 json_grace, "gracefulRestartTimerMsecs",
13880 thread_timer_remain_second(p->t_gr_restart) *
13881 1000);
13882
13883 if (p->t_gr_stale)
13884 json_object_int_add(
13885 json_grace, "gracefulStalepathTimerMsecs",
13886 thread_timer_remain_second(p->t_gr_stale) *
13887 1000);
13888 /* more gr info in new format */
13889 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13890 json_object_object_add(json_neigh, "gracefulRestartInfo",
13891 json_grace);
13892 } else {
13893 vty_out(vty, " Graceful restart information:\n");
13894 if ((peer_established(p)) &&
13895 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13896
13897 vty_out(vty, " End-of-RIB send: ");
13898 FOREACH_AFI_SAFI (afi, safi) {
13899 if (CHECK_FLAG(p->af_sflags[afi][safi],
13900 PEER_STATUS_EOR_SEND)) {
13901 vty_out(vty, "%s%s",
13902 eor_send_af_count ? ", " : "",
13903 get_afi_safi_str(afi, safi,
13904 false));
13905 eor_send_af_count++;
13906 }
13907 }
13908 vty_out(vty, "\n");
13909 vty_out(vty, " End-of-RIB received: ");
13910 FOREACH_AFI_SAFI (afi, safi) {
13911 if (CHECK_FLAG(p->af_sflags[afi][safi],
13912 PEER_STATUS_EOR_RECEIVED)) {
13913 vty_out(vty, "%s%s",
13914 eor_receive_af_count ? ", "
13915 : "",
13916 get_afi_safi_str(afi, safi,
13917 false));
13918 eor_receive_af_count++;
13919 }
13920 }
13921 vty_out(vty, "\n");
13922 }
13923
13924 if (p->t_gr_restart)
13925 vty_out(vty,
13926 " The remaining time of restart timer is %ld\n",
13927 thread_timer_remain_second(p->t_gr_restart));
13928
13929 if (p->t_gr_stale)
13930 vty_out(vty,
13931 " The remaining time of stalepath timer is %ld\n",
13932 thread_timer_remain_second(p->t_gr_stale));
13933
13934 /* more gr info in new format */
13935 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13936 }
13937
13938 if (use_json) {
13939 json_object *json_stat = NULL;
13940 json_stat = json_object_new_object();
13941 /* Packet counts. */
13942
13943 atomic_size_t outq_count, inq_count;
13944 outq_count = atomic_load_explicit(&p->obuf->count,
13945 memory_order_relaxed);
13946 inq_count = atomic_load_explicit(&p->ibuf->count,
13947 memory_order_relaxed);
13948
13949 json_object_int_add(json_stat, "depthInq",
13950 (unsigned long)inq_count);
13951 json_object_int_add(json_stat, "depthOutq",
13952 (unsigned long)outq_count);
13953 json_object_int_add(json_stat, "opensSent",
13954 atomic_load_explicit(&p->open_out,
13955 memory_order_relaxed));
13956 json_object_int_add(json_stat, "opensRecv",
13957 atomic_load_explicit(&p->open_in,
13958 memory_order_relaxed));
13959 json_object_int_add(json_stat, "notificationsSent",
13960 atomic_load_explicit(&p->notify_out,
13961 memory_order_relaxed));
13962 json_object_int_add(json_stat, "notificationsRecv",
13963 atomic_load_explicit(&p->notify_in,
13964 memory_order_relaxed));
13965 json_object_int_add(json_stat, "updatesSent",
13966 atomic_load_explicit(&p->update_out,
13967 memory_order_relaxed));
13968 json_object_int_add(json_stat, "updatesRecv",
13969 atomic_load_explicit(&p->update_in,
13970 memory_order_relaxed));
13971 json_object_int_add(json_stat, "keepalivesSent",
13972 atomic_load_explicit(&p->keepalive_out,
13973 memory_order_relaxed));
13974 json_object_int_add(json_stat, "keepalivesRecv",
13975 atomic_load_explicit(&p->keepalive_in,
13976 memory_order_relaxed));
13977 json_object_int_add(json_stat, "routeRefreshSent",
13978 atomic_load_explicit(&p->refresh_out,
13979 memory_order_relaxed));
13980 json_object_int_add(json_stat, "routeRefreshRecv",
13981 atomic_load_explicit(&p->refresh_in,
13982 memory_order_relaxed));
13983 json_object_int_add(json_stat, "capabilitySent",
13984 atomic_load_explicit(&p->dynamic_cap_out,
13985 memory_order_relaxed));
13986 json_object_int_add(json_stat, "capabilityRecv",
13987 atomic_load_explicit(&p->dynamic_cap_in,
13988 memory_order_relaxed));
13989 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13990 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13991 json_object_object_add(json_neigh, "messageStats", json_stat);
13992 } else {
13993 atomic_size_t outq_count, inq_count, open_out, open_in,
13994 notify_out, notify_in, update_out, update_in,
13995 keepalive_out, keepalive_in, refresh_out, refresh_in,
13996 dynamic_cap_out, dynamic_cap_in;
13997 outq_count = atomic_load_explicit(&p->obuf->count,
13998 memory_order_relaxed);
13999 inq_count = atomic_load_explicit(&p->ibuf->count,
14000 memory_order_relaxed);
14001 open_out = atomic_load_explicit(&p->open_out,
14002 memory_order_relaxed);
14003 open_in =
14004 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14005 notify_out = atomic_load_explicit(&p->notify_out,
14006 memory_order_relaxed);
14007 notify_in = atomic_load_explicit(&p->notify_in,
14008 memory_order_relaxed);
14009 update_out = atomic_load_explicit(&p->update_out,
14010 memory_order_relaxed);
14011 update_in = atomic_load_explicit(&p->update_in,
14012 memory_order_relaxed);
14013 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14014 memory_order_relaxed);
14015 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14016 memory_order_relaxed);
14017 refresh_out = atomic_load_explicit(&p->refresh_out,
14018 memory_order_relaxed);
14019 refresh_in = atomic_load_explicit(&p->refresh_in,
14020 memory_order_relaxed);
14021 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14022 memory_order_relaxed);
14023 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14024 memory_order_relaxed);
14025
14026 /* Packet counts. */
14027 vty_out(vty, " Message statistics:\n");
14028 vty_out(vty, " Inq depth is %zu\n", inq_count);
14029 vty_out(vty, " Outq depth is %zu\n", outq_count);
14030 vty_out(vty, " Sent Rcvd\n");
14031 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14032 open_in);
14033 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14034 notify_in);
14035 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14036 update_in);
14037 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14038 keepalive_in);
14039 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14040 refresh_in);
14041 vty_out(vty, " Capability: %10zu %10zu\n",
14042 dynamic_cap_out, dynamic_cap_in);
14043 vty_out(vty, " Total: %10u %10u\n",
14044 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14045 }
14046
14047 if (use_json) {
14048 /* advertisement-interval */
14049 json_object_int_add(json_neigh,
14050 "minBtwnAdvertisementRunsTimerMsecs",
14051 p->v_routeadv * 1000);
14052
14053 /* Update-source. */
14054 if (p->update_if || p->update_source) {
14055 if (p->update_if)
14056 json_object_string_add(json_neigh,
14057 "updateSource",
14058 p->update_if);
14059 else if (p->update_source)
14060 json_object_string_addf(json_neigh,
14061 "updateSource", "%pSU",
14062 p->update_source);
14063 }
14064 } else {
14065 /* advertisement-interval */
14066 vty_out(vty,
14067 " Minimum time between advertisement runs is %d seconds\n",
14068 p->v_routeadv);
14069
14070 /* Update-source. */
14071 if (p->update_if || p->update_source) {
14072 vty_out(vty, " Update source is ");
14073 if (p->update_if)
14074 vty_out(vty, "%s", p->update_if);
14075 else if (p->update_source)
14076 vty_out(vty, "%pSU", p->update_source);
14077 vty_out(vty, "\n");
14078 }
14079
14080 vty_out(vty, "\n");
14081 }
14082
14083 /* Address Family Information */
14084 json_object *json_hold = NULL;
14085
14086 if (use_json)
14087 json_hold = json_object_new_object();
14088
14089 FOREACH_AFI_SAFI (afi, safi)
14090 if (p->afc[afi][safi])
14091 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14092 json_hold);
14093
14094 if (use_json) {
14095 json_object_object_add(json_neigh, "addressFamilyInfo",
14096 json_hold);
14097 json_object_int_add(json_neigh, "connectionsEstablished",
14098 p->established);
14099 json_object_int_add(json_neigh, "connectionsDropped",
14100 p->dropped);
14101 } else
14102 vty_out(vty, " Connections established %d; dropped %d\n",
14103 p->established, p->dropped);
14104
14105 if (!p->last_reset) {
14106 if (use_json)
14107 json_object_string_add(json_neigh, "lastReset",
14108 "never");
14109 else
14110 vty_out(vty, " Last reset never\n");
14111 } else {
14112 if (use_json) {
14113 time_t uptime;
14114 struct tm tm;
14115
14116 uptime = monotime(NULL);
14117 uptime -= p->resettime;
14118 gmtime_r(&uptime, &tm);
14119
14120 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14121 (tm.tm_sec * 1000)
14122 + (tm.tm_min * 60000)
14123 + (tm.tm_hour * 3600000));
14124 bgp_show_peer_reset(NULL, p, json_neigh, true);
14125 } else {
14126 vty_out(vty, " Last reset %s, ",
14127 peer_uptime(p->resettime, timebuf,
14128 BGP_UPTIME_LEN, 0, NULL));
14129
14130 bgp_show_peer_reset(vty, p, NULL, false);
14131 if (p->last_reset_cause_size) {
14132 msg = p->last_reset_cause;
14133 vty_out(vty,
14134 " Message received that caused BGP to send a NOTIFICATION:\n ");
14135 for (i = 1; i <= p->last_reset_cause_size;
14136 i++) {
14137 vty_out(vty, "%02X", *msg++);
14138
14139 if (i != p->last_reset_cause_size) {
14140 if (i % 16 == 0) {
14141 vty_out(vty, "\n ");
14142 } else if (i % 4 == 0) {
14143 vty_out(vty, " ");
14144 }
14145 }
14146 }
14147 vty_out(vty, "\n");
14148 }
14149 }
14150 }
14151
14152 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14153 if (use_json)
14154 json_object_boolean_true_add(json_neigh,
14155 "prefixesConfigExceedMax");
14156 else
14157 vty_out(vty,
14158 " Peer had exceeded the max. no. of prefixes configured.\n");
14159
14160 if (p->t_pmax_restart) {
14161 if (use_json) {
14162 json_object_boolean_true_add(
14163 json_neigh, "reducePrefixNumFrom");
14164 json_object_int_add(json_neigh,
14165 "restartInTimerMsec",
14166 thread_timer_remain_second(
14167 p->t_pmax_restart)
14168 * 1000);
14169 } else
14170 vty_out(vty,
14171 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14172 p->host, thread_timer_remain_second(
14173 p->t_pmax_restart));
14174 } else {
14175 if (use_json)
14176 json_object_boolean_true_add(
14177 json_neigh,
14178 "reducePrefixNumAndClearIpBgp");
14179 else
14180 vty_out(vty,
14181 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14182 p->host);
14183 }
14184 }
14185
14186 /* EBGP Multihop and GTSM */
14187 if (p->sort != BGP_PEER_IBGP) {
14188 if (use_json) {
14189 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14190 json_object_int_add(json_neigh,
14191 "externalBgpNbrMaxHopsAway",
14192 p->gtsm_hops);
14193 else
14194 json_object_int_add(json_neigh,
14195 "externalBgpNbrMaxHopsAway",
14196 p->ttl);
14197 } else {
14198 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14199 vty_out(vty,
14200 " External BGP neighbor may be up to %d hops away.\n",
14201 p->gtsm_hops);
14202 else
14203 vty_out(vty,
14204 " External BGP neighbor may be up to %d hops away.\n",
14205 p->ttl);
14206 }
14207 } else {
14208 if (use_json) {
14209 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14210 json_object_int_add(json_neigh,
14211 "internalBgpNbrMaxHopsAway",
14212 p->gtsm_hops);
14213 else
14214 json_object_int_add(json_neigh,
14215 "internalBgpNbrMaxHopsAway",
14216 p->ttl);
14217 } else {
14218 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14219 vty_out(vty,
14220 " Internal BGP neighbor may be up to %d hops away.\n",
14221 p->gtsm_hops);
14222 else
14223 vty_out(vty,
14224 " Internal BGP neighbor may be up to %d hops away.\n",
14225 p->ttl);
14226 }
14227 }
14228
14229 /* Local address. */
14230 if (p->su_local) {
14231 if (use_json) {
14232 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14233 p->su_local);
14234 json_object_int_add(json_neigh, "portLocal",
14235 ntohs(p->su_local->sin.sin_port));
14236 } else
14237 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14238 p->su_local, ntohs(p->su_local->sin.sin_port));
14239 } else {
14240 if (use_json) {
14241 json_object_string_add(json_neigh, "hostLocal",
14242 "Unknown");
14243 json_object_int_add(json_neigh, "portLocal", -1);
14244 }
14245 }
14246
14247 /* Remote address. */
14248 if (p->su_remote) {
14249 if (use_json) {
14250 json_object_string_addf(json_neigh, "hostForeign",
14251 "%pSU", p->su_remote);
14252 json_object_int_add(json_neigh, "portForeign",
14253 ntohs(p->su_remote->sin.sin_port));
14254 } else
14255 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14256 p->su_remote,
14257 ntohs(p->su_remote->sin.sin_port));
14258 } else {
14259 if (use_json) {
14260 json_object_string_add(json_neigh, "hostForeign",
14261 "Unknown");
14262 json_object_int_add(json_neigh, "portForeign", -1);
14263 }
14264 }
14265
14266 /* Nexthop display. */
14267 if (p->su_local) {
14268 if (use_json) {
14269 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14270 &p->nexthop.v4);
14271 json_object_string_addf(json_neigh, "nexthopGlobal",
14272 "%pI6", &p->nexthop.v6_global);
14273 json_object_string_addf(json_neigh, "nexthopLocal",
14274 "%pI6", &p->nexthop.v6_local);
14275 if (p->shared_network)
14276 json_object_string_add(json_neigh,
14277 "bgpConnection",
14278 "sharedNetwork");
14279 else
14280 json_object_string_add(json_neigh,
14281 "bgpConnection",
14282 "nonSharedNetwork");
14283 } else {
14284 vty_out(vty, "Nexthop: %s\n",
14285 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14286 sizeof(buf1)));
14287 vty_out(vty, "Nexthop global: %s\n",
14288 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14289 sizeof(buf1)));
14290 vty_out(vty, "Nexthop local: %s\n",
14291 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14292 sizeof(buf1)));
14293 vty_out(vty, "BGP connection: %s\n",
14294 p->shared_network ? "shared network"
14295 : "non shared network");
14296 }
14297 }
14298
14299 /* Timer information. */
14300 if (use_json) {
14301 json_object_int_add(json_neigh, "connectRetryTimer",
14302 p->v_connect);
14303 if (peer_established(p) && p->rtt)
14304 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14305 p->rtt);
14306 if (p->t_start)
14307 json_object_int_add(
14308 json_neigh, "nextStartTimerDueInMsecs",
14309 thread_timer_remain_second(p->t_start) * 1000);
14310 if (p->t_connect)
14311 json_object_int_add(
14312 json_neigh, "nextConnectTimerDueInMsecs",
14313 thread_timer_remain_second(p->t_connect)
14314 * 1000);
14315 if (p->t_routeadv) {
14316 json_object_int_add(json_neigh, "mraiInterval",
14317 p->v_routeadv);
14318 json_object_int_add(
14319 json_neigh, "mraiTimerExpireInMsecs",
14320 thread_timer_remain_second(p->t_routeadv)
14321 * 1000);
14322 }
14323 if (p->password)
14324 json_object_int_add(json_neigh, "authenticationEnabled",
14325 1);
14326
14327 if (p->t_read)
14328 json_object_string_add(json_neigh, "readThread", "on");
14329 else
14330 json_object_string_add(json_neigh, "readThread", "off");
14331
14332 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14333 json_object_string_add(json_neigh, "writeThread", "on");
14334 else
14335 json_object_string_add(json_neigh, "writeThread",
14336 "off");
14337 } else {
14338 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14339 p->v_connect);
14340 if (peer_established(p) && p->rtt)
14341 vty_out(vty, "Estimated round trip time: %d ms\n",
14342 p->rtt);
14343 if (p->t_start)
14344 vty_out(vty, "Next start timer due in %ld seconds\n",
14345 thread_timer_remain_second(p->t_start));
14346 if (p->t_connect)
14347 vty_out(vty, "Next connect timer due in %ld seconds\n",
14348 thread_timer_remain_second(p->t_connect));
14349 if (p->t_routeadv)
14350 vty_out(vty,
14351 "MRAI (interval %u) timer expires in %ld seconds\n",
14352 p->v_routeadv,
14353 thread_timer_remain_second(p->t_routeadv));
14354 if (p->password)
14355 vty_out(vty, "Peer Authentication Enabled\n");
14356
14357 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14358 p->t_read ? "on" : "off",
14359 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14360 ? "on"
14361 : "off", p->fd);
14362 }
14363
14364 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14365 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14366 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14367
14368 if (!use_json)
14369 vty_out(vty, "\n");
14370
14371 /* BFD information. */
14372 if (p->bfd_config)
14373 bgp_bfd_show_info(vty, p, json_neigh);
14374
14375 if (use_json) {
14376 if (p->conf_if) /* Configured interface name. */
14377 json_object_object_add(json, p->conf_if, json_neigh);
14378 else /* Configured IP address. */
14379 json_object_object_add(json, p->host, json_neigh);
14380 }
14381 }
14382
14383 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14384 enum show_type type,
14385 union sockunion *su,
14386 const char *conf_if, afi_t afi,
14387 bool use_json)
14388 {
14389 struct listnode *node, *nnode;
14390 struct peer *peer;
14391 int find = 0;
14392 safi_t safi = SAFI_UNICAST;
14393 json_object *json = NULL;
14394 json_object *json_neighbor = NULL;
14395
14396 if (use_json) {
14397 json = json_object_new_object();
14398 json_neighbor = json_object_new_object();
14399 }
14400
14401 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14402
14403 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14404 continue;
14405
14406 if ((peer->afc[afi][safi]) == 0)
14407 continue;
14408
14409 if (type == show_all) {
14410 bgp_show_peer_gr_status(vty, peer, use_json,
14411 json_neighbor);
14412
14413 if (use_json) {
14414 json_object_object_add(json, peer->host,
14415 json_neighbor);
14416 json_neighbor = NULL;
14417 }
14418
14419 } else if (type == show_peer) {
14420 if (conf_if) {
14421 if ((peer->conf_if
14422 && !strcmp(peer->conf_if, conf_if))
14423 || (peer->hostname
14424 && !strcmp(peer->hostname, conf_if))) {
14425 find = 1;
14426 bgp_show_peer_gr_status(vty, peer,
14427 use_json,
14428 json_neighbor);
14429 }
14430 } else {
14431 if (sockunion_same(&peer->su, su)) {
14432 find = 1;
14433 bgp_show_peer_gr_status(vty, peer,
14434 use_json,
14435 json_neighbor);
14436 }
14437 }
14438 if (use_json && find)
14439 json_object_object_add(json, peer->host,
14440 json_neighbor);
14441 }
14442
14443 if (find) {
14444 json_neighbor = NULL;
14445 break;
14446 }
14447 }
14448
14449 if (type == show_peer && !find) {
14450 if (use_json)
14451 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14452 else
14453 vty_out(vty, "%% No such neighbor\n");
14454 }
14455 if (use_json) {
14456 if (json_neighbor)
14457 json_object_free(json_neighbor);
14458 vty_json(vty, json);
14459 } else {
14460 vty_out(vty, "\n");
14461 }
14462
14463 return CMD_SUCCESS;
14464 }
14465
14466 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14467 enum show_type type, union sockunion *su,
14468 const char *conf_if, bool use_json,
14469 json_object *json)
14470 {
14471 struct listnode *node, *nnode;
14472 struct peer *peer;
14473 int find = 0;
14474 bool nbr_output = false;
14475 afi_t afi = AFI_MAX;
14476 safi_t safi = SAFI_MAX;
14477
14478 if (type == show_ipv4_peer || type == show_ipv4_all) {
14479 afi = AFI_IP;
14480 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14481 afi = AFI_IP6;
14482 }
14483
14484 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14485 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14486 continue;
14487
14488 switch (type) {
14489 case show_all:
14490 bgp_show_peer(vty, peer, use_json, json);
14491 nbr_output = true;
14492 break;
14493 case show_peer:
14494 if (conf_if) {
14495 if ((peer->conf_if
14496 && !strcmp(peer->conf_if, conf_if))
14497 || (peer->hostname
14498 && !strcmp(peer->hostname, conf_if))) {
14499 find = 1;
14500 bgp_show_peer(vty, peer, use_json,
14501 json);
14502 }
14503 } else {
14504 if (sockunion_same(&peer->su, su)) {
14505 find = 1;
14506 bgp_show_peer(vty, peer, use_json,
14507 json);
14508 }
14509 }
14510 break;
14511 case show_ipv4_peer:
14512 case show_ipv6_peer:
14513 FOREACH_SAFI (safi) {
14514 if (peer->afc[afi][safi]) {
14515 if (conf_if) {
14516 if ((peer->conf_if
14517 && !strcmp(peer->conf_if, conf_if))
14518 || (peer->hostname
14519 && !strcmp(peer->hostname, conf_if))) {
14520 find = 1;
14521 bgp_show_peer(vty, peer, use_json,
14522 json);
14523 break;
14524 }
14525 } else {
14526 if (sockunion_same(&peer->su, su)) {
14527 find = 1;
14528 bgp_show_peer(vty, peer, use_json,
14529 json);
14530 break;
14531 }
14532 }
14533 }
14534 }
14535 break;
14536 case show_ipv4_all:
14537 case show_ipv6_all:
14538 FOREACH_SAFI (safi) {
14539 if (peer->afc[afi][safi]) {
14540 bgp_show_peer(vty, peer, use_json, json);
14541 nbr_output = true;
14542 break;
14543 }
14544 }
14545 break;
14546 }
14547 }
14548
14549 if ((type == show_peer || type == show_ipv4_peer ||
14550 type == show_ipv6_peer) && !find) {
14551 if (use_json)
14552 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14553 else
14554 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14555 }
14556
14557 if (type != show_peer && type != show_ipv4_peer &&
14558 type != show_ipv6_peer && !nbr_output && !use_json)
14559 vty_out(vty, "%% No BGP neighbors found\n");
14560
14561 if (use_json) {
14562 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14563 json, JSON_C_TO_STRING_PRETTY));
14564 } else {
14565 vty_out(vty, "\n");
14566 }
14567
14568 return CMD_SUCCESS;
14569 }
14570
14571 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14572 enum show_type type,
14573 const char *ip_str,
14574 afi_t afi, bool use_json)
14575 {
14576
14577 int ret;
14578 struct bgp *bgp;
14579 union sockunion su;
14580
14581 bgp = bgp_get_default();
14582
14583 if (!bgp)
14584 return;
14585
14586 if (!use_json)
14587 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14588 NULL);
14589
14590 if (ip_str) {
14591 ret = str2sockunion(ip_str, &su);
14592 if (ret < 0)
14593 bgp_show_neighbor_graceful_restart(
14594 vty, bgp, type, NULL, ip_str, afi, use_json);
14595 else
14596 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14597 NULL, afi, use_json);
14598 } else
14599 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14600 afi, use_json);
14601 }
14602
14603 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14604 enum show_type type,
14605 const char *ip_str,
14606 bool use_json)
14607 {
14608 struct listnode *node, *nnode;
14609 struct bgp *bgp;
14610 union sockunion su;
14611 json_object *json = NULL;
14612 int ret, is_first = 1;
14613 bool nbr_output = false;
14614
14615 if (use_json)
14616 vty_out(vty, "{\n");
14617
14618 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14619 nbr_output = true;
14620 if (use_json) {
14621 if (!(json = json_object_new_object())) {
14622 flog_err(
14623 EC_BGP_JSON_MEM_ERROR,
14624 "Unable to allocate memory for JSON object");
14625 vty_out(vty,
14626 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14627 return;
14628 }
14629
14630 json_object_int_add(json, "vrfId",
14631 (bgp->vrf_id == VRF_UNKNOWN)
14632 ? -1
14633 : (int64_t)bgp->vrf_id);
14634 json_object_string_add(
14635 json, "vrfName",
14636 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14637 ? VRF_DEFAULT_NAME
14638 : bgp->name);
14639
14640 if (!is_first)
14641 vty_out(vty, ",\n");
14642 else
14643 is_first = 0;
14644
14645 vty_out(vty, "\"%s\":",
14646 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14647 ? VRF_DEFAULT_NAME
14648 : bgp->name);
14649 } else {
14650 vty_out(vty, "\nInstance %s:\n",
14651 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14652 ? VRF_DEFAULT_NAME
14653 : bgp->name);
14654 }
14655
14656 if (type == show_peer || type == show_ipv4_peer ||
14657 type == show_ipv6_peer) {
14658 ret = str2sockunion(ip_str, &su);
14659 if (ret < 0)
14660 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14661 use_json, json);
14662 else
14663 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14664 use_json, json);
14665 } else {
14666 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14667 use_json, json);
14668 }
14669 json_object_free(json);
14670 json = NULL;
14671 }
14672
14673 if (use_json)
14674 vty_out(vty, "}\n");
14675 else if (!nbr_output)
14676 vty_out(vty, "%% BGP instance not found\n");
14677 }
14678
14679 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14680 enum show_type type, const char *ip_str,
14681 bool use_json)
14682 {
14683 int ret;
14684 struct bgp *bgp;
14685 union sockunion su;
14686 json_object *json = NULL;
14687
14688 if (name) {
14689 if (strmatch(name, "all")) {
14690 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14691 use_json);
14692 return CMD_SUCCESS;
14693 } else {
14694 bgp = bgp_lookup_by_name(name);
14695 if (!bgp) {
14696 if (use_json) {
14697 json = json_object_new_object();
14698 vty_json(vty, json);
14699 } else
14700 vty_out(vty,
14701 "%% BGP instance not found\n");
14702
14703 return CMD_WARNING;
14704 }
14705 }
14706 } else {
14707 bgp = bgp_get_default();
14708 }
14709
14710 if (bgp) {
14711 json = json_object_new_object();
14712 if (ip_str) {
14713 ret = str2sockunion(ip_str, &su);
14714 if (ret < 0)
14715 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14716 use_json, json);
14717 else
14718 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14719 use_json, json);
14720 } else {
14721 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14722 json);
14723 }
14724 json_object_free(json);
14725 } else {
14726 if (use_json)
14727 vty_out(vty, "{}\n");
14728 else
14729 vty_out(vty, "%% BGP instance not found\n");
14730 }
14731
14732 return CMD_SUCCESS;
14733 }
14734
14735
14736
14737 /* "show [ip] bgp neighbors graceful-restart" commands. */
14738 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14739 show_ip_bgp_neighbors_graceful_restart_cmd,
14740 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14741 SHOW_STR
14742 BGP_STR
14743 IP_STR
14744 IPV6_STR
14745 NEIGHBOR_STR
14746 "Neighbor to display information about\n"
14747 "Neighbor to display information about\n"
14748 "Neighbor on BGP configured interface\n"
14749 GR_SHOW
14750 JSON_STR)
14751 {
14752 char *sh_arg = NULL;
14753 enum show_type sh_type;
14754 int idx = 0;
14755 afi_t afi = AFI_MAX;
14756 bool uj = use_json(argc, argv);
14757
14758 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14759 afi = AFI_MAX;
14760
14761 idx++;
14762
14763 if (argv_find(argv, argc, "A.B.C.D", &idx)
14764 || argv_find(argv, argc, "X:X::X:X", &idx)
14765 || argv_find(argv, argc, "WORD", &idx)) {
14766 sh_type = show_peer;
14767 sh_arg = argv[idx]->arg;
14768 } else
14769 sh_type = show_all;
14770
14771 if (!argv_find(argv, argc, "graceful-restart", &idx))
14772 return CMD_SUCCESS;
14773
14774
14775 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14776 afi, uj);
14777 }
14778
14779 /* "show [ip] bgp neighbors" commands. */
14780 DEFUN (show_ip_bgp_neighbors,
14781 show_ip_bgp_neighbors_cmd,
14782 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14783 SHOW_STR
14784 IP_STR
14785 BGP_STR
14786 BGP_INSTANCE_HELP_STR
14787 BGP_AF_STR
14788 BGP_AF_STR
14789 "Detailed information on TCP and BGP neighbor connections\n"
14790 "Neighbor to display information about\n"
14791 "Neighbor to display information about\n"
14792 "Neighbor on BGP configured interface\n"
14793 JSON_STR)
14794 {
14795 char *vrf = NULL;
14796 char *sh_arg = NULL;
14797 enum show_type sh_type;
14798 afi_t afi = AFI_MAX;
14799
14800 bool uj = use_json(argc, argv);
14801
14802 int idx = 0;
14803
14804 /* [<vrf> VIEWVRFNAME] */
14805 if (argv_find(argv, argc, "vrf", &idx)) {
14806 vrf = argv[idx + 1]->arg;
14807 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14808 vrf = NULL;
14809 } else if (argv_find(argv, argc, "view", &idx))
14810 /* [<view> VIEWVRFNAME] */
14811 vrf = argv[idx + 1]->arg;
14812
14813 idx++;
14814
14815 if (argv_find(argv, argc, "ipv4", &idx)) {
14816 sh_type = show_ipv4_all;
14817 afi = AFI_IP;
14818 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14819 sh_type = show_ipv6_all;
14820 afi = AFI_IP6;
14821 } else {
14822 sh_type = show_all;
14823 }
14824
14825 if (argv_find(argv, argc, "A.B.C.D", &idx)
14826 || argv_find(argv, argc, "X:X::X:X", &idx)
14827 || argv_find(argv, argc, "WORD", &idx)) {
14828 sh_type = show_peer;
14829 sh_arg = argv[idx]->arg;
14830 }
14831
14832 if (sh_type == show_peer && afi == AFI_IP) {
14833 sh_type = show_ipv4_peer;
14834 } else if (sh_type == show_peer && afi == AFI_IP6) {
14835 sh_type = show_ipv6_peer;
14836 }
14837
14838 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14839 }
14840
14841 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14842 paths' and `show ip mbgp paths'. Those functions results are the
14843 same.*/
14844 DEFUN (show_ip_bgp_paths,
14845 show_ip_bgp_paths_cmd,
14846 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14847 SHOW_STR
14848 IP_STR
14849 BGP_STR
14850 BGP_SAFI_HELP_STR
14851 "Path information\n")
14852 {
14853 vty_out(vty, "Address Refcnt Path\n");
14854 aspath_print_all_vty(vty);
14855 return CMD_SUCCESS;
14856 }
14857
14858 #include "hash.h"
14859
14860 static void community_show_all_iterator(struct hash_bucket *bucket,
14861 struct vty *vty)
14862 {
14863 struct community *com;
14864
14865 com = (struct community *)bucket->data;
14866 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14867 community_str(com, false, false));
14868 }
14869
14870 /* Show BGP's community internal data. */
14871 DEFUN (show_ip_bgp_community_info,
14872 show_ip_bgp_community_info_cmd,
14873 "show [ip] bgp community-info",
14874 SHOW_STR
14875 IP_STR
14876 BGP_STR
14877 "List all bgp community information\n")
14878 {
14879 vty_out(vty, "Address Refcnt Community\n");
14880
14881 hash_iterate(community_hash(),
14882 (void (*)(struct hash_bucket *,
14883 void *))community_show_all_iterator,
14884 vty);
14885
14886 return CMD_SUCCESS;
14887 }
14888
14889 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14890 struct vty *vty)
14891 {
14892 struct lcommunity *lcom;
14893
14894 lcom = (struct lcommunity *)bucket->data;
14895 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14896 lcommunity_str(lcom, false, false));
14897 }
14898
14899 /* Show BGP's community internal data. */
14900 DEFUN (show_ip_bgp_lcommunity_info,
14901 show_ip_bgp_lcommunity_info_cmd,
14902 "show ip bgp large-community-info",
14903 SHOW_STR
14904 IP_STR
14905 BGP_STR
14906 "List all bgp large-community information\n")
14907 {
14908 vty_out(vty, "Address Refcnt Large-community\n");
14909
14910 hash_iterate(lcommunity_hash(),
14911 (void (*)(struct hash_bucket *,
14912 void *))lcommunity_show_all_iterator,
14913 vty);
14914
14915 return CMD_SUCCESS;
14916 }
14917 /* Graceful Restart */
14918
14919 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14920 struct bgp *bgp,
14921 bool use_json,
14922 json_object *json)
14923 {
14924
14925
14926 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14927
14928 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14929
14930 switch (bgp_global_gr_mode) {
14931
14932 case GLOBAL_HELPER:
14933 vty_out(vty, "Global BGP GR Mode : Helper\n");
14934 break;
14935
14936 case GLOBAL_GR:
14937 vty_out(vty, "Global BGP GR Mode : Restart\n");
14938 break;
14939
14940 case GLOBAL_DISABLE:
14941 vty_out(vty, "Global BGP GR Mode : Disable\n");
14942 break;
14943
14944 case GLOBAL_INVALID:
14945 vty_out(vty,
14946 "Global BGP GR Mode Invalid\n");
14947 break;
14948 }
14949 vty_out(vty, "\n");
14950 }
14951
14952 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14953 enum show_type type,
14954 const char *ip_str,
14955 afi_t afi, bool use_json)
14956 {
14957 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14958 afi = AFI_IP;
14959
14960 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14961
14962 bgp_show_neighbor_graceful_restart_vty(
14963 vty, type, ip_str, afi, use_json);
14964 afi++;
14965 }
14966 } else if (afi != AFI_MAX) {
14967 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14968 use_json);
14969 } else {
14970 return CMD_ERR_INCOMPLETE;
14971 }
14972
14973 return CMD_SUCCESS;
14974 }
14975 /* Graceful Restart */
14976
14977 DEFUN (show_ip_bgp_attr_info,
14978 show_ip_bgp_attr_info_cmd,
14979 "show [ip] bgp attribute-info",
14980 SHOW_STR
14981 IP_STR
14982 BGP_STR
14983 "List all bgp attribute information\n")
14984 {
14985 attr_show_all(vty);
14986 return CMD_SUCCESS;
14987 }
14988
14989 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14990 afi_t afi, safi_t safi,
14991 bool use_json, json_object *json)
14992 {
14993 struct bgp *bgp;
14994 struct listnode *node;
14995 char *vname;
14996 char *ecom_str;
14997 enum vpn_policy_direction dir;
14998
14999 if (json) {
15000 json_object *json_import_vrfs = NULL;
15001 json_object *json_export_vrfs = NULL;
15002
15003 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15004
15005 if (!bgp) {
15006 vty_json(vty, json);
15007
15008 return CMD_WARNING;
15009 }
15010
15011 /* Provide context for the block */
15012 json_object_string_add(json, "vrf", name ? name : "default");
15013 json_object_string_add(json, "afiSafi",
15014 get_afi_safi_str(afi, safi, true));
15015
15016 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15017 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15018 json_object_string_add(json, "importFromVrfs", "none");
15019 json_object_string_add(json, "importRts", "none");
15020 } else {
15021 json_import_vrfs = json_object_new_array();
15022
15023 for (ALL_LIST_ELEMENTS_RO(
15024 bgp->vpn_policy[afi].import_vrf,
15025 node, vname))
15026 json_object_array_add(json_import_vrfs,
15027 json_object_new_string(vname));
15028
15029 json_object_object_add(json, "importFromVrfs",
15030 json_import_vrfs);
15031 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15032 if (bgp->vpn_policy[afi].rtlist[dir]) {
15033 ecom_str = ecommunity_ecom2str(
15034 bgp->vpn_policy[afi].rtlist[dir],
15035 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15036 json_object_string_add(json, "importRts",
15037 ecom_str);
15038 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15039 } else
15040 json_object_string_add(json, "importRts",
15041 "none");
15042 }
15043
15044 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15045 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15046 json_object_string_add(json, "exportToVrfs", "none");
15047 json_object_string_add(json, "routeDistinguisher",
15048 "none");
15049 json_object_string_add(json, "exportRts", "none");
15050 } else {
15051 json_export_vrfs = json_object_new_array();
15052
15053 for (ALL_LIST_ELEMENTS_RO(
15054 bgp->vpn_policy[afi].export_vrf,
15055 node, vname))
15056 json_object_array_add(json_export_vrfs,
15057 json_object_new_string(vname));
15058 json_object_object_add(json, "exportToVrfs",
15059 json_export_vrfs);
15060 json_object_string_addf(json, "routeDistinguisher",
15061 "%pRD",
15062 &bgp->vpn_policy[afi].tovpn_rd);
15063
15064 dir = BGP_VPN_POLICY_DIR_TOVPN;
15065 if (bgp->vpn_policy[afi].rtlist[dir]) {
15066 ecom_str = ecommunity_ecom2str(
15067 bgp->vpn_policy[afi].rtlist[dir],
15068 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15069 json_object_string_add(json, "exportRts",
15070 ecom_str);
15071 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15072 } else
15073 json_object_string_add(json, "exportRts",
15074 "none");
15075 }
15076
15077 if (use_json) {
15078 vty_json(vty, json);
15079 }
15080 } else {
15081 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15082
15083 if (!bgp) {
15084 vty_out(vty, "%% No such BGP instance exist\n");
15085 return CMD_WARNING;
15086 }
15087
15088 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15089 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15090 vty_out(vty,
15091 "This VRF is not importing %s routes from any other VRF\n",
15092 get_afi_safi_str(afi, safi, false));
15093 else {
15094 vty_out(vty,
15095 "This VRF is importing %s routes from the following VRFs:\n",
15096 get_afi_safi_str(afi, safi, false));
15097
15098 for (ALL_LIST_ELEMENTS_RO(
15099 bgp->vpn_policy[afi].import_vrf,
15100 node, vname))
15101 vty_out(vty, " %s\n", vname);
15102
15103 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15104 ecom_str = NULL;
15105 if (bgp->vpn_policy[afi].rtlist[dir]) {
15106 ecom_str = ecommunity_ecom2str(
15107 bgp->vpn_policy[afi].rtlist[dir],
15108 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15109 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15110
15111 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15112 } else
15113 vty_out(vty, "Import RT(s):\n");
15114 }
15115
15116 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15117 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15118 vty_out(vty,
15119 "This VRF is not exporting %s routes to any other VRF\n",
15120 get_afi_safi_str(afi, safi, false));
15121 else {
15122 vty_out(vty,
15123 "This VRF is exporting %s routes to the following VRFs:\n",
15124 get_afi_safi_str(afi, safi, false));
15125
15126 for (ALL_LIST_ELEMENTS_RO(
15127 bgp->vpn_policy[afi].export_vrf,
15128 node, vname))
15129 vty_out(vty, " %s\n", vname);
15130
15131 vty_out(vty, "RD: %pRD\n",
15132 &bgp->vpn_policy[afi].tovpn_rd);
15133
15134 dir = BGP_VPN_POLICY_DIR_TOVPN;
15135 if (bgp->vpn_policy[afi].rtlist[dir]) {
15136 ecom_str = ecommunity_ecom2str(
15137 bgp->vpn_policy[afi].rtlist[dir],
15138 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15139 vty_out(vty, "Export RT: %s\n", ecom_str);
15140 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15141 } else
15142 vty_out(vty, "Import RT(s):\n");
15143 }
15144 }
15145
15146 return CMD_SUCCESS;
15147 }
15148
15149 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15150 safi_t safi, bool use_json)
15151 {
15152 struct listnode *node, *nnode;
15153 struct bgp *bgp;
15154 char *vrf_name = NULL;
15155 json_object *json = NULL;
15156 json_object *json_vrf = NULL;
15157 json_object *json_vrfs = NULL;
15158
15159 if (use_json) {
15160 json = json_object_new_object();
15161 json_vrfs = json_object_new_object();
15162 }
15163
15164 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15165
15166 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15167 vrf_name = bgp->name;
15168
15169 if (use_json) {
15170 json_vrf = json_object_new_object();
15171 } else {
15172 vty_out(vty, "\nInstance %s:\n",
15173 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15174 ? VRF_DEFAULT_NAME : bgp->name);
15175 }
15176 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15177 if (use_json) {
15178 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15179 json_object_object_add(json_vrfs,
15180 VRF_DEFAULT_NAME, json_vrf);
15181 else
15182 json_object_object_add(json_vrfs, vrf_name,
15183 json_vrf);
15184 }
15185 }
15186
15187 if (use_json) {
15188 json_object_object_add(json, "vrfs", json_vrfs);
15189 vty_json(vty, json);
15190 }
15191
15192 return CMD_SUCCESS;
15193 }
15194
15195 /* "show [ip] bgp route-leak" command. */
15196 DEFUN (show_ip_bgp_route_leak,
15197 show_ip_bgp_route_leak_cmd,
15198 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15199 SHOW_STR
15200 IP_STR
15201 BGP_STR
15202 BGP_INSTANCE_HELP_STR
15203 BGP_AFI_HELP_STR
15204 BGP_SAFI_HELP_STR
15205 "Route leaking information\n"
15206 JSON_STR)
15207 {
15208 char *vrf = NULL;
15209 afi_t afi = AFI_MAX;
15210 safi_t safi = SAFI_MAX;
15211
15212 bool uj = use_json(argc, argv);
15213 int idx = 0;
15214 json_object *json = NULL;
15215
15216 /* show [ip] bgp */
15217 if (argv_find(argv, argc, "ip", &idx)) {
15218 afi = AFI_IP;
15219 safi = SAFI_UNICAST;
15220 }
15221 /* [vrf VIEWVRFNAME] */
15222 if (argv_find(argv, argc, "view", &idx)) {
15223 vty_out(vty,
15224 "%% This command is not applicable to BGP views\n");
15225 return CMD_WARNING;
15226 }
15227
15228 if (argv_find(argv, argc, "vrf", &idx)) {
15229 vrf = argv[idx + 1]->arg;
15230 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15231 vrf = NULL;
15232 }
15233 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15234 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15235 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15236
15237 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15238 vty_out(vty,
15239 "%% This command is applicable only for unicast ipv4|ipv6\n");
15240 return CMD_WARNING;
15241 }
15242
15243 if (vrf && strmatch(vrf, "all"))
15244 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15245
15246 if (uj)
15247 json = json_object_new_object();
15248
15249 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15250 }
15251
15252 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15253 safi_t safi)
15254 {
15255 struct listnode *node, *nnode;
15256 struct bgp *bgp;
15257
15258 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15259 vty_out(vty, "\nInstance %s:\n",
15260 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15261 ? VRF_DEFAULT_NAME
15262 : bgp->name);
15263 update_group_show(bgp, afi, safi, vty, 0);
15264 }
15265 }
15266
15267 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15268 int safi, uint64_t subgrp_id)
15269 {
15270 struct bgp *bgp;
15271
15272 if (name) {
15273 if (strmatch(name, "all")) {
15274 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15275 return CMD_SUCCESS;
15276 } else {
15277 bgp = bgp_lookup_by_name(name);
15278 }
15279 } else {
15280 bgp = bgp_get_default();
15281 }
15282
15283 if (bgp)
15284 update_group_show(bgp, afi, safi, vty, subgrp_id);
15285 return CMD_SUCCESS;
15286 }
15287
15288 DEFUN (show_ip_bgp_updgrps,
15289 show_ip_bgp_updgrps_cmd,
15290 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15291 SHOW_STR
15292 IP_STR
15293 BGP_STR
15294 BGP_INSTANCE_HELP_STR
15295 BGP_AFI_HELP_STR
15296 BGP_SAFI_WITH_LABEL_HELP_STR
15297 "Detailed info about dynamic update groups\n"
15298 "Specific subgroup to display detailed info for\n")
15299 {
15300 char *vrf = NULL;
15301 afi_t afi = AFI_IP6;
15302 safi_t safi = SAFI_UNICAST;
15303 uint64_t subgrp_id = 0;
15304
15305 int idx = 0;
15306
15307 /* show [ip] bgp */
15308 if (argv_find(argv, argc, "ip", &idx))
15309 afi = AFI_IP;
15310 /* [<vrf> VIEWVRFNAME] */
15311 if (argv_find(argv, argc, "vrf", &idx)) {
15312 vrf = argv[idx + 1]->arg;
15313 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15314 vrf = NULL;
15315 } else if (argv_find(argv, argc, "view", &idx))
15316 /* [<view> VIEWVRFNAME] */
15317 vrf = argv[idx + 1]->arg;
15318 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15319 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15320 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15321 }
15322
15323 /* get subgroup id, if provided */
15324 idx = argc - 1;
15325 if (argv[idx]->type == VARIABLE_TKN)
15326 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15327
15328 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15329 }
15330
15331 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15332 show_bgp_instance_all_ipv6_updgrps_cmd,
15333 "show [ip] bgp <view|vrf> all update-groups",
15334 SHOW_STR
15335 IP_STR
15336 BGP_STR
15337 BGP_INSTANCE_ALL_HELP_STR
15338 "Detailed info about dynamic update groups\n")
15339 {
15340 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15341 return CMD_SUCCESS;
15342 }
15343
15344 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15345 show_bgp_l2vpn_evpn_updgrps_cmd,
15346 "show [ip] bgp l2vpn evpn update-groups",
15347 SHOW_STR
15348 IP_STR
15349 BGP_STR
15350 "l2vpn address family\n"
15351 "evpn sub-address family\n"
15352 "Detailed info about dynamic update groups\n")
15353 {
15354 char *vrf = NULL;
15355 uint64_t subgrp_id = 0;
15356
15357 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15358 return CMD_SUCCESS;
15359 }
15360
15361 DEFUN (show_bgp_updgrps_stats,
15362 show_bgp_updgrps_stats_cmd,
15363 "show [ip] bgp update-groups statistics",
15364 SHOW_STR
15365 IP_STR
15366 BGP_STR
15367 "Detailed info about dynamic update groups\n"
15368 "Statistics\n")
15369 {
15370 struct bgp *bgp;
15371
15372 bgp = bgp_get_default();
15373 if (bgp)
15374 update_group_show_stats(bgp, vty);
15375
15376 return CMD_SUCCESS;
15377 }
15378
15379 DEFUN (show_bgp_instance_updgrps_stats,
15380 show_bgp_instance_updgrps_stats_cmd,
15381 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15382 SHOW_STR
15383 IP_STR
15384 BGP_STR
15385 BGP_INSTANCE_HELP_STR
15386 "Detailed info about dynamic update groups\n"
15387 "Statistics\n")
15388 {
15389 int idx_word = 3;
15390 struct bgp *bgp;
15391
15392 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15393 if (bgp)
15394 update_group_show_stats(bgp, vty);
15395
15396 return CMD_SUCCESS;
15397 }
15398
15399 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15400 afi_t afi, safi_t safi,
15401 const char *what, uint64_t subgrp_id)
15402 {
15403 struct bgp *bgp;
15404
15405 if (name)
15406 bgp = bgp_lookup_by_name(name);
15407 else
15408 bgp = bgp_get_default();
15409
15410 if (bgp) {
15411 if (!strcmp(what, "advertise-queue"))
15412 update_group_show_adj_queue(bgp, afi, safi, vty,
15413 subgrp_id);
15414 else if (!strcmp(what, "advertised-routes"))
15415 update_group_show_advertised(bgp, afi, safi, vty,
15416 subgrp_id);
15417 else if (!strcmp(what, "packet-queue"))
15418 update_group_show_packet_queue(bgp, afi, safi, vty,
15419 subgrp_id);
15420 }
15421 }
15422
15423 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15424 show_ip_bgp_instance_updgrps_adj_s_cmd,
15425 "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",
15426 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15427 BGP_SAFI_HELP_STR
15428 "Detailed info about dynamic update groups\n"
15429 "Specific subgroup to display info for\n"
15430 "Advertisement queue\n"
15431 "Announced routes\n"
15432 "Packet queue\n")
15433 {
15434 uint64_t subgrp_id = 0;
15435 afi_t afiz;
15436 safi_t safiz;
15437 if (sgid)
15438 subgrp_id = strtoull(sgid, NULL, 10);
15439
15440 if (!ip && !afi)
15441 afiz = AFI_IP6;
15442 if (!ip && afi)
15443 afiz = bgp_vty_afi_from_str(afi);
15444 if (ip && !afi)
15445 afiz = AFI_IP;
15446 if (ip && afi) {
15447 afiz = bgp_vty_afi_from_str(afi);
15448 if (afiz != AFI_IP)
15449 vty_out(vty,
15450 "%% Cannot specify both 'ip' and 'ipv6'\n");
15451 return CMD_WARNING;
15452 }
15453
15454 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15455
15456 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15457 return CMD_SUCCESS;
15458 }
15459
15460 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15461 json_object *json)
15462 {
15463 struct listnode *node, *nnode;
15464 struct prefix *range;
15465 struct peer *conf;
15466 struct peer *peer;
15467 afi_t afi;
15468 safi_t safi;
15469 const char *peer_status;
15470 int lr_count;
15471 int dynamic;
15472 bool af_cfgd;
15473 json_object *json_peer_group = NULL;
15474 json_object *json_peer_group_afc = NULL;
15475 json_object *json_peer_group_members = NULL;
15476 json_object *json_peer_group_dynamic = NULL;
15477 json_object *json_peer_group_dynamic_af = NULL;
15478 json_object *json_peer_group_ranges = NULL;
15479
15480 conf = group->conf;
15481
15482 if (json) {
15483 json_peer_group = json_object_new_object();
15484 json_peer_group_afc = json_object_new_array();
15485 }
15486
15487 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15488 if (json)
15489 json_object_int_add(json_peer_group, "remoteAs",
15490 conf->as);
15491 else
15492 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15493 group->name, conf->as);
15494 } else if (conf->as_type == AS_INTERNAL) {
15495 if (json)
15496 json_object_int_add(json_peer_group, "remoteAs",
15497 group->bgp->as);
15498 else
15499 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15500 group->name, group->bgp->as);
15501 } else {
15502 if (!json)
15503 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15504 }
15505
15506 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15507 if (json)
15508 json_object_string_add(json_peer_group, "type",
15509 "internal");
15510 else
15511 vty_out(vty, " Peer-group type is internal\n");
15512 } else {
15513 if (json)
15514 json_object_string_add(json_peer_group, "type",
15515 "external");
15516 else
15517 vty_out(vty, " Peer-group type is external\n");
15518 }
15519
15520 /* Display AFs configured. */
15521 if (!json)
15522 vty_out(vty, " Configured address-families:");
15523
15524 FOREACH_AFI_SAFI (afi, safi) {
15525 if (conf->afc[afi][safi]) {
15526 af_cfgd = true;
15527 if (json)
15528 json_object_array_add(
15529 json_peer_group_afc,
15530 json_object_new_string(get_afi_safi_str(
15531 afi, safi, false)));
15532 else
15533 vty_out(vty, " %s;",
15534 get_afi_safi_str(afi, safi, false));
15535 }
15536 }
15537
15538 if (json) {
15539 json_object_object_add(json_peer_group,
15540 "addressFamiliesConfigured",
15541 json_peer_group_afc);
15542 } else {
15543 if (!af_cfgd)
15544 vty_out(vty, " none\n");
15545 else
15546 vty_out(vty, "\n");
15547 }
15548
15549 /* Display listen ranges (for dynamic neighbors), if any */
15550 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15551 lr_count = listcount(group->listen_range[afi]);
15552 if (lr_count) {
15553 if (json) {
15554 if (!json_peer_group_dynamic)
15555 json_peer_group_dynamic =
15556 json_object_new_object();
15557
15558 json_peer_group_dynamic_af =
15559 json_object_new_object();
15560 json_peer_group_ranges =
15561 json_object_new_array();
15562 json_object_int_add(json_peer_group_dynamic_af,
15563 "count", lr_count);
15564 } else {
15565 vty_out(vty, " %d %s listen range(s)\n",
15566 lr_count, afi2str(afi));
15567 }
15568
15569 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15570 nnode, range)) {
15571 if (json) {
15572 char buf[BUFSIZ];
15573
15574 snprintfrr(buf, sizeof(buf), "%pFX",
15575 range);
15576
15577 json_object_array_add(
15578 json_peer_group_ranges,
15579 json_object_new_string(buf));
15580 } else {
15581 vty_out(vty, " %pFX\n", range);
15582 }
15583 }
15584
15585 if (json) {
15586 json_object_object_add(
15587 json_peer_group_dynamic_af, "ranges",
15588 json_peer_group_ranges);
15589
15590 json_object_object_add(
15591 json_peer_group_dynamic, afi2str(afi),
15592 json_peer_group_dynamic_af);
15593 }
15594 }
15595 }
15596
15597 if (json_peer_group_dynamic)
15598 json_object_object_add(json_peer_group, "dynamicRanges",
15599 json_peer_group_dynamic);
15600
15601 /* Display group members and their status */
15602 if (listcount(group->peer)) {
15603 if (json)
15604 json_peer_group_members = json_object_new_object();
15605 else
15606 vty_out(vty, " Peer-group members:\n");
15607 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15608 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15609 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15610 peer_status = "Idle (Admin)";
15611 else if (CHECK_FLAG(peer->sflags,
15612 PEER_STATUS_PREFIX_OVERFLOW))
15613 peer_status = "Idle (PfxCt)";
15614 else
15615 peer_status = lookup_msg(bgp_status_msg,
15616 peer->status, NULL);
15617
15618 dynamic = peer_dynamic_neighbor(peer);
15619
15620 if (json) {
15621 json_object *json_peer_group_member =
15622 json_object_new_object();
15623
15624 json_object_string_add(json_peer_group_member,
15625 "status", peer_status);
15626
15627 if (dynamic)
15628 json_object_boolean_true_add(
15629 json_peer_group_member,
15630 "dynamic");
15631
15632 json_object_object_add(json_peer_group_members,
15633 peer->host,
15634 json_peer_group_member);
15635 } else {
15636 vty_out(vty, " %s %s %s \n", peer->host,
15637 dynamic ? "(dynamic)" : "",
15638 peer_status);
15639 }
15640 }
15641 if (json)
15642 json_object_object_add(json_peer_group, "members",
15643 json_peer_group_members);
15644 }
15645
15646 if (json)
15647 json_object_object_add(json, group->name, json_peer_group);
15648
15649 return CMD_SUCCESS;
15650 }
15651
15652 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15653 const char *group_name, bool uj)
15654 {
15655 struct bgp *bgp;
15656 struct listnode *node, *nnode;
15657 struct peer_group *group;
15658 bool found = false;
15659 json_object *json = NULL;
15660
15661 if (uj)
15662 json = json_object_new_object();
15663
15664 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15665
15666 if (!bgp) {
15667 if (uj)
15668 vty_json(vty, json);
15669 else
15670 vty_out(vty, "%% BGP instance not found\n");
15671
15672 return CMD_WARNING;
15673 }
15674
15675 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15676 if (group_name) {
15677 if (strmatch(group->name, group_name)) {
15678 bgp_show_one_peer_group(vty, group, json);
15679 found = true;
15680 break;
15681 }
15682 } else {
15683 bgp_show_one_peer_group(vty, group, json);
15684 }
15685 }
15686
15687 if (group_name && !found && !uj)
15688 vty_out(vty, "%% No such peer-group\n");
15689
15690 if (uj)
15691 vty_json(vty, json);
15692
15693 return CMD_SUCCESS;
15694 }
15695
15696 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15697 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15698 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15699 "Detailed information on BGP peer groups\n"
15700 "Peer group name\n" JSON_STR)
15701 {
15702 char *vrf, *pg;
15703 int idx = 0;
15704 bool uj = use_json(argc, argv);
15705
15706 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15707 : NULL;
15708 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15709
15710 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15711 }
15712
15713
15714 /* Redistribute VTY commands. */
15715
15716 DEFUN (bgp_redistribute_ipv4,
15717 bgp_redistribute_ipv4_cmd,
15718 "redistribute " FRR_IP_REDIST_STR_BGPD,
15719 "Redistribute information from another routing protocol\n"
15720 FRR_IP_REDIST_HELP_STR_BGPD)
15721 {
15722 VTY_DECLVAR_CONTEXT(bgp, bgp);
15723 int idx_protocol = 1;
15724 int type;
15725
15726 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15727 if (type < 0) {
15728 vty_out(vty, "%% Invalid route type\n");
15729 return CMD_WARNING_CONFIG_FAILED;
15730 }
15731
15732 bgp_redist_add(bgp, AFI_IP, type, 0);
15733 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15734 }
15735
15736 ALIAS_HIDDEN(
15737 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15738 "redistribute " FRR_IP_REDIST_STR_BGPD,
15739 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15740
15741 DEFUN (bgp_redistribute_ipv4_rmap,
15742 bgp_redistribute_ipv4_rmap_cmd,
15743 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15744 "Redistribute information from another routing protocol\n"
15745 FRR_IP_REDIST_HELP_STR_BGPD
15746 "Route map reference\n"
15747 "Pointer to route-map entries\n")
15748 {
15749 VTY_DECLVAR_CONTEXT(bgp, bgp);
15750 int idx_protocol = 1;
15751 int idx_word = 3;
15752 int type;
15753 struct bgp_redist *red;
15754 bool changed;
15755 struct route_map *route_map = route_map_lookup_warn_noexist(
15756 vty, argv[idx_word]->arg);
15757
15758 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15759 if (type < 0) {
15760 vty_out(vty, "%% Invalid route type\n");
15761 return CMD_WARNING_CONFIG_FAILED;
15762 }
15763
15764 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15765 changed =
15766 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15767 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15768 }
15769
15770 ALIAS_HIDDEN(
15771 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15772 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15773 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15774 "Route map reference\n"
15775 "Pointer to route-map entries\n")
15776
15777 DEFUN (bgp_redistribute_ipv4_metric,
15778 bgp_redistribute_ipv4_metric_cmd,
15779 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15780 "Redistribute information from another routing protocol\n"
15781 FRR_IP_REDIST_HELP_STR_BGPD
15782 "Metric for redistributed routes\n"
15783 "Default metric\n")
15784 {
15785 VTY_DECLVAR_CONTEXT(bgp, bgp);
15786 int idx_protocol = 1;
15787 int idx_number = 3;
15788 int type;
15789 uint32_t metric;
15790 struct bgp_redist *red;
15791 bool changed;
15792
15793 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15794 if (type < 0) {
15795 vty_out(vty, "%% Invalid route type\n");
15796 return CMD_WARNING_CONFIG_FAILED;
15797 }
15798 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15799
15800 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15801 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15802 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15803 }
15804
15805 ALIAS_HIDDEN(
15806 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15807 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15808 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15809 "Metric for redistributed routes\n"
15810 "Default metric\n")
15811
15812 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15813 bgp_redistribute_ipv4_rmap_metric_cmd,
15814 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15815 "Redistribute information from another routing protocol\n"
15816 FRR_IP_REDIST_HELP_STR_BGPD
15817 "Route map reference\n"
15818 "Pointer to route-map entries\n"
15819 "Metric for redistributed routes\n"
15820 "Default metric\n")
15821 {
15822 VTY_DECLVAR_CONTEXT(bgp, bgp);
15823 int idx_protocol = 1;
15824 int idx_word = 3;
15825 int idx_number = 5;
15826 int type;
15827 uint32_t metric;
15828 struct bgp_redist *red;
15829 bool changed;
15830 struct route_map *route_map =
15831 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15832
15833 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15834 if (type < 0) {
15835 vty_out(vty, "%% Invalid route type\n");
15836 return CMD_WARNING_CONFIG_FAILED;
15837 }
15838 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15839
15840 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15841 changed =
15842 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15843 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15844 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15845 }
15846
15847 ALIAS_HIDDEN(
15848 bgp_redistribute_ipv4_rmap_metric,
15849 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15850 "redistribute " FRR_IP_REDIST_STR_BGPD
15851 " route-map RMAP_NAME metric (0-4294967295)",
15852 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15853 "Route map reference\n"
15854 "Pointer to route-map entries\n"
15855 "Metric for redistributed routes\n"
15856 "Default metric\n")
15857
15858 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15859 bgp_redistribute_ipv4_metric_rmap_cmd,
15860 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15861 "Redistribute information from another routing protocol\n"
15862 FRR_IP_REDIST_HELP_STR_BGPD
15863 "Metric for redistributed routes\n"
15864 "Default metric\n"
15865 "Route map reference\n"
15866 "Pointer to route-map entries\n")
15867 {
15868 VTY_DECLVAR_CONTEXT(bgp, bgp);
15869 int idx_protocol = 1;
15870 int idx_number = 3;
15871 int idx_word = 5;
15872 int type;
15873 uint32_t metric;
15874 struct bgp_redist *red;
15875 bool changed;
15876 struct route_map *route_map =
15877 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15878
15879 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15880 if (type < 0) {
15881 vty_out(vty, "%% Invalid route type\n");
15882 return CMD_WARNING_CONFIG_FAILED;
15883 }
15884 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15885
15886 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15887 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15888 changed |=
15889 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15890 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15891 }
15892
15893 ALIAS_HIDDEN(
15894 bgp_redistribute_ipv4_metric_rmap,
15895 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15896 "redistribute " FRR_IP_REDIST_STR_BGPD
15897 " metric (0-4294967295) route-map RMAP_NAME",
15898 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15899 "Metric for redistributed routes\n"
15900 "Default metric\n"
15901 "Route map reference\n"
15902 "Pointer to route-map entries\n")
15903
15904 DEFUN (bgp_redistribute_ipv4_ospf,
15905 bgp_redistribute_ipv4_ospf_cmd,
15906 "redistribute <ospf|table> (1-65535)",
15907 "Redistribute information from another routing protocol\n"
15908 "Open Shortest Path First (OSPFv2)\n"
15909 "Non-main Kernel Routing Table\n"
15910 "Instance ID/Table ID\n")
15911 {
15912 VTY_DECLVAR_CONTEXT(bgp, bgp);
15913 int idx_ospf_table = 1;
15914 int idx_number = 2;
15915 unsigned short instance;
15916 unsigned short protocol;
15917
15918 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15919
15920 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15921 protocol = ZEBRA_ROUTE_OSPF;
15922 else
15923 protocol = ZEBRA_ROUTE_TABLE;
15924
15925 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15926 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15927 }
15928
15929 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15930 "redistribute <ospf|table> (1-65535)",
15931 "Redistribute information from another routing protocol\n"
15932 "Open Shortest Path First (OSPFv2)\n"
15933 "Non-main Kernel Routing Table\n"
15934 "Instance ID/Table ID\n")
15935
15936 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15937 bgp_redistribute_ipv4_ospf_rmap_cmd,
15938 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15939 "Redistribute information from another routing protocol\n"
15940 "Open Shortest Path First (OSPFv2)\n"
15941 "Non-main Kernel Routing Table\n"
15942 "Instance ID/Table ID\n"
15943 "Route map reference\n"
15944 "Pointer to route-map entries\n")
15945 {
15946 VTY_DECLVAR_CONTEXT(bgp, bgp);
15947 int idx_ospf_table = 1;
15948 int idx_number = 2;
15949 int idx_word = 4;
15950 struct bgp_redist *red;
15951 unsigned short instance;
15952 int protocol;
15953 bool changed;
15954 struct route_map *route_map =
15955 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15956
15957 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15958 protocol = ZEBRA_ROUTE_OSPF;
15959 else
15960 protocol = ZEBRA_ROUTE_TABLE;
15961
15962 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15963 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15964 changed =
15965 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15966 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15967 }
15968
15969 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15970 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15971 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15972 "Redistribute information from another routing protocol\n"
15973 "Open Shortest Path First (OSPFv2)\n"
15974 "Non-main Kernel Routing Table\n"
15975 "Instance ID/Table ID\n"
15976 "Route map reference\n"
15977 "Pointer to route-map entries\n")
15978
15979 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15980 bgp_redistribute_ipv4_ospf_metric_cmd,
15981 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15982 "Redistribute information from another routing protocol\n"
15983 "Open Shortest Path First (OSPFv2)\n"
15984 "Non-main Kernel Routing Table\n"
15985 "Instance ID/Table ID\n"
15986 "Metric for redistributed routes\n"
15987 "Default metric\n")
15988 {
15989 VTY_DECLVAR_CONTEXT(bgp, bgp);
15990 int idx_ospf_table = 1;
15991 int idx_number = 2;
15992 int idx_number_2 = 4;
15993 uint32_t metric;
15994 struct bgp_redist *red;
15995 unsigned short instance;
15996 int protocol;
15997 bool changed;
15998
15999 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16000 protocol = ZEBRA_ROUTE_OSPF;
16001 else
16002 protocol = ZEBRA_ROUTE_TABLE;
16003
16004 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16005 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16006
16007 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16008 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16009 metric);
16010 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16011 }
16012
16013 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16014 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16015 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16016 "Redistribute information from another routing protocol\n"
16017 "Open Shortest Path First (OSPFv2)\n"
16018 "Non-main Kernel Routing Table\n"
16019 "Instance ID/Table ID\n"
16020 "Metric for redistributed routes\n"
16021 "Default metric\n")
16022
16023 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16024 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16025 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16026 "Redistribute information from another routing protocol\n"
16027 "Open Shortest Path First (OSPFv2)\n"
16028 "Non-main Kernel Routing Table\n"
16029 "Instance ID/Table ID\n"
16030 "Route map reference\n"
16031 "Pointer to route-map entries\n"
16032 "Metric for redistributed routes\n"
16033 "Default metric\n")
16034 {
16035 VTY_DECLVAR_CONTEXT(bgp, bgp);
16036 int idx_ospf_table = 1;
16037 int idx_number = 2;
16038 int idx_word = 4;
16039 int idx_number_2 = 6;
16040 uint32_t metric;
16041 struct bgp_redist *red;
16042 unsigned short instance;
16043 int protocol;
16044 bool changed;
16045 struct route_map *route_map =
16046 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16047
16048 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16049 protocol = ZEBRA_ROUTE_OSPF;
16050 else
16051 protocol = ZEBRA_ROUTE_TABLE;
16052
16053 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16054 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16055
16056 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16057 changed =
16058 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16059 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16060 metric);
16061 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16062 }
16063
16064 ALIAS_HIDDEN(
16065 bgp_redistribute_ipv4_ospf_rmap_metric,
16066 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16067 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16068 "Redistribute information from another routing protocol\n"
16069 "Open Shortest Path First (OSPFv2)\n"
16070 "Non-main Kernel Routing Table\n"
16071 "Instance ID/Table ID\n"
16072 "Route map reference\n"
16073 "Pointer to route-map entries\n"
16074 "Metric for redistributed routes\n"
16075 "Default metric\n")
16076
16077 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16078 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16079 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16080 "Redistribute information from another routing protocol\n"
16081 "Open Shortest Path First (OSPFv2)\n"
16082 "Non-main Kernel Routing Table\n"
16083 "Instance ID/Table ID\n"
16084 "Metric for redistributed routes\n"
16085 "Default metric\n"
16086 "Route map reference\n"
16087 "Pointer to route-map entries\n")
16088 {
16089 VTY_DECLVAR_CONTEXT(bgp, bgp);
16090 int idx_ospf_table = 1;
16091 int idx_number = 2;
16092 int idx_number_2 = 4;
16093 int idx_word = 6;
16094 uint32_t metric;
16095 struct bgp_redist *red;
16096 unsigned short instance;
16097 int protocol;
16098 bool changed;
16099 struct route_map *route_map =
16100 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16101
16102 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16103 protocol = ZEBRA_ROUTE_OSPF;
16104 else
16105 protocol = ZEBRA_ROUTE_TABLE;
16106
16107 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16108 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16109
16110 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16111 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16112 metric);
16113 changed |=
16114 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16115 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16116 }
16117
16118 ALIAS_HIDDEN(
16119 bgp_redistribute_ipv4_ospf_metric_rmap,
16120 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16121 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16122 "Redistribute information from another routing protocol\n"
16123 "Open Shortest Path First (OSPFv2)\n"
16124 "Non-main Kernel Routing Table\n"
16125 "Instance ID/Table ID\n"
16126 "Metric for redistributed routes\n"
16127 "Default metric\n"
16128 "Route map reference\n"
16129 "Pointer to route-map entries\n")
16130
16131 DEFUN (no_bgp_redistribute_ipv4_ospf,
16132 no_bgp_redistribute_ipv4_ospf_cmd,
16133 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16134 NO_STR
16135 "Redistribute information from another routing protocol\n"
16136 "Open Shortest Path First (OSPFv2)\n"
16137 "Non-main Kernel Routing Table\n"
16138 "Instance ID/Table ID\n"
16139 "Metric for redistributed routes\n"
16140 "Default metric\n"
16141 "Route map reference\n"
16142 "Pointer to route-map entries\n")
16143 {
16144 VTY_DECLVAR_CONTEXT(bgp, bgp);
16145 int idx_ospf_table = 2;
16146 int idx_number = 3;
16147 unsigned short instance;
16148 int protocol;
16149
16150 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16151 protocol = ZEBRA_ROUTE_OSPF;
16152 else
16153 protocol = ZEBRA_ROUTE_TABLE;
16154
16155 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16156 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16157 }
16158
16159 ALIAS_HIDDEN(
16160 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16161 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16162 NO_STR
16163 "Redistribute information from another routing protocol\n"
16164 "Open Shortest Path First (OSPFv2)\n"
16165 "Non-main Kernel Routing Table\n"
16166 "Instance ID/Table ID\n"
16167 "Metric for redistributed routes\n"
16168 "Default metric\n"
16169 "Route map reference\n"
16170 "Pointer to route-map entries\n")
16171
16172 DEFUN (no_bgp_redistribute_ipv4,
16173 no_bgp_redistribute_ipv4_cmd,
16174 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16175 NO_STR
16176 "Redistribute information from another routing protocol\n"
16177 FRR_IP_REDIST_HELP_STR_BGPD
16178 "Metric for redistributed routes\n"
16179 "Default metric\n"
16180 "Route map reference\n"
16181 "Pointer to route-map entries\n")
16182 {
16183 VTY_DECLVAR_CONTEXT(bgp, bgp);
16184 int idx_protocol = 2;
16185 int type;
16186
16187 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16188 if (type < 0) {
16189 vty_out(vty, "%% Invalid route type\n");
16190 return CMD_WARNING_CONFIG_FAILED;
16191 }
16192 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16193 }
16194
16195 ALIAS_HIDDEN(
16196 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16197 "no redistribute " FRR_IP_REDIST_STR_BGPD
16198 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16199 NO_STR
16200 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16201 "Metric for redistributed routes\n"
16202 "Default metric\n"
16203 "Route map reference\n"
16204 "Pointer to route-map entries\n")
16205
16206 DEFUN (bgp_redistribute_ipv6,
16207 bgp_redistribute_ipv6_cmd,
16208 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16209 "Redistribute information from another routing protocol\n"
16210 FRR_IP6_REDIST_HELP_STR_BGPD)
16211 {
16212 VTY_DECLVAR_CONTEXT(bgp, bgp);
16213 int idx_protocol = 1;
16214 int type;
16215
16216 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16217 if (type < 0) {
16218 vty_out(vty, "%% Invalid route type\n");
16219 return CMD_WARNING_CONFIG_FAILED;
16220 }
16221
16222 bgp_redist_add(bgp, AFI_IP6, type, 0);
16223 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16224 }
16225
16226 DEFUN (bgp_redistribute_ipv6_rmap,
16227 bgp_redistribute_ipv6_rmap_cmd,
16228 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16229 "Redistribute information from another routing protocol\n"
16230 FRR_IP6_REDIST_HELP_STR_BGPD
16231 "Route map reference\n"
16232 "Pointer to route-map entries\n")
16233 {
16234 VTY_DECLVAR_CONTEXT(bgp, bgp);
16235 int idx_protocol = 1;
16236 int idx_word = 3;
16237 int type;
16238 struct bgp_redist *red;
16239 bool changed;
16240 struct route_map *route_map =
16241 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16242
16243 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16244 if (type < 0) {
16245 vty_out(vty, "%% Invalid route type\n");
16246 return CMD_WARNING_CONFIG_FAILED;
16247 }
16248
16249 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16250 changed =
16251 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16252 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16253 }
16254
16255 DEFUN (bgp_redistribute_ipv6_metric,
16256 bgp_redistribute_ipv6_metric_cmd,
16257 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16258 "Redistribute information from another routing protocol\n"
16259 FRR_IP6_REDIST_HELP_STR_BGPD
16260 "Metric for redistributed routes\n"
16261 "Default metric\n")
16262 {
16263 VTY_DECLVAR_CONTEXT(bgp, bgp);
16264 int idx_protocol = 1;
16265 int idx_number = 3;
16266 int type;
16267 uint32_t metric;
16268 struct bgp_redist *red;
16269 bool changed;
16270
16271 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16272 if (type < 0) {
16273 vty_out(vty, "%% Invalid route type\n");
16274 return CMD_WARNING_CONFIG_FAILED;
16275 }
16276 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16277
16278 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16279 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16280 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16281 }
16282
16283 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16284 bgp_redistribute_ipv6_rmap_metric_cmd,
16285 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16286 "Redistribute information from another routing protocol\n"
16287 FRR_IP6_REDIST_HELP_STR_BGPD
16288 "Route map reference\n"
16289 "Pointer to route-map entries\n"
16290 "Metric for redistributed routes\n"
16291 "Default metric\n")
16292 {
16293 VTY_DECLVAR_CONTEXT(bgp, bgp);
16294 int idx_protocol = 1;
16295 int idx_word = 3;
16296 int idx_number = 5;
16297 int type;
16298 uint32_t metric;
16299 struct bgp_redist *red;
16300 bool changed;
16301 struct route_map *route_map =
16302 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16303
16304 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16305 if (type < 0) {
16306 vty_out(vty, "%% Invalid route type\n");
16307 return CMD_WARNING_CONFIG_FAILED;
16308 }
16309 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16310
16311 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16312 changed =
16313 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16314 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16315 metric);
16316 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16317 }
16318
16319 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16320 bgp_redistribute_ipv6_metric_rmap_cmd,
16321 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16322 "Redistribute information from another routing protocol\n"
16323 FRR_IP6_REDIST_HELP_STR_BGPD
16324 "Metric for redistributed routes\n"
16325 "Default metric\n"
16326 "Route map reference\n"
16327 "Pointer to route-map entries\n")
16328 {
16329 VTY_DECLVAR_CONTEXT(bgp, bgp);
16330 int idx_protocol = 1;
16331 int idx_number = 3;
16332 int idx_word = 5;
16333 int type;
16334 uint32_t metric;
16335 struct bgp_redist *red;
16336 bool changed;
16337 struct route_map *route_map =
16338 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16339
16340 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16341 if (type < 0) {
16342 vty_out(vty, "%% Invalid route type\n");
16343 return CMD_WARNING_CONFIG_FAILED;
16344 }
16345 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16346
16347 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16348 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16349 metric);
16350 changed |=
16351 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16352 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16353 }
16354
16355 DEFUN (no_bgp_redistribute_ipv6,
16356 no_bgp_redistribute_ipv6_cmd,
16357 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16358 NO_STR
16359 "Redistribute information from another routing protocol\n"
16360 FRR_IP6_REDIST_HELP_STR_BGPD
16361 "Metric for redistributed routes\n"
16362 "Default metric\n"
16363 "Route map reference\n"
16364 "Pointer to route-map entries\n")
16365 {
16366 VTY_DECLVAR_CONTEXT(bgp, bgp);
16367 int idx_protocol = 2;
16368 int type;
16369
16370 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16371 if (type < 0) {
16372 vty_out(vty, "%% Invalid route type\n");
16373 return CMD_WARNING_CONFIG_FAILED;
16374 }
16375
16376 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16377 }
16378
16379 /* Neighbor update tcp-mss. */
16380 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16381 const char *tcp_mss_str)
16382 {
16383 struct peer *peer;
16384 uint32_t tcp_mss_val = 0;
16385
16386 peer = peer_and_group_lookup_vty(vty, peer_str);
16387 if (!peer)
16388 return CMD_WARNING_CONFIG_FAILED;
16389
16390 if (tcp_mss_str) {
16391 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16392 peer_tcp_mss_set(peer, tcp_mss_val);
16393 } else {
16394 peer_tcp_mss_unset(peer);
16395 }
16396
16397 return CMD_SUCCESS;
16398 }
16399
16400 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16401 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16402 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16403 "TCP max segment size\n"
16404 "TCP MSS value\n")
16405 {
16406 int peer_index = 1;
16407 int mss_index = 3;
16408
16409 vty_out(vty,
16410 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16411 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16412 argv[mss_index]->arg);
16413 }
16414
16415 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16416 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16417 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16418 "TCP max segment size\n"
16419 "TCP MSS value\n")
16420 {
16421 int peer_index = 2;
16422
16423 vty_out(vty,
16424 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16425 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16426 }
16427
16428 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16429 "[no$no] bgp retain route-target all",
16430 NO_STR BGP_STR
16431 "Retain BGP updates\n"
16432 "Retain BGP updates based on route-target values\n"
16433 "Retain all BGP updates\n")
16434 {
16435 bool check;
16436 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16437
16438 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16439 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16440 if (check != !no) {
16441 if (!no)
16442 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16443 [bgp_node_safi(vty)],
16444 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16445 else
16446 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16447 [bgp_node_safi(vty)],
16448 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16449 /* trigger a flush to re-sync with ADJ-RIB-in */
16450 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16451 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16452 }
16453 return CMD_SUCCESS;
16454 }
16455
16456 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16457 afi_t afi, safi_t safi)
16458 {
16459 int i;
16460
16461 /* Unicast redistribution only. */
16462 if (safi != SAFI_UNICAST)
16463 return;
16464
16465 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16466 /* Redistribute BGP does not make sense. */
16467 if (i != ZEBRA_ROUTE_BGP) {
16468 struct list *red_list;
16469 struct listnode *node;
16470 struct bgp_redist *red;
16471
16472 red_list = bgp->redist[afi][i];
16473 if (!red_list)
16474 continue;
16475
16476 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16477 /* "redistribute" configuration. */
16478 vty_out(vty, " redistribute %s",
16479 zebra_route_string(i));
16480 if (red->instance)
16481 vty_out(vty, " %d", red->instance);
16482 if (red->redist_metric_flag)
16483 vty_out(vty, " metric %u",
16484 red->redist_metric);
16485 if (red->rmap.name)
16486 vty_out(vty, " route-map %s",
16487 red->rmap.name);
16488 vty_out(vty, "\n");
16489 }
16490 }
16491 }
16492 }
16493
16494 /* peer-group helpers for config-write */
16495
16496 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16497 {
16498 if (!peer_group_active(peer)) {
16499 if (CHECK_FLAG(peer->flags_invert, flag))
16500 return !CHECK_FLAG(peer->flags, flag);
16501 else
16502 return !!CHECK_FLAG(peer->flags, flag);
16503 }
16504
16505 return !!CHECK_FLAG(peer->flags_override, flag);
16506 }
16507
16508 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16509 uint64_t flag)
16510 {
16511 if (!peer_group_active(peer)) {
16512 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16513 return !peer_af_flag_check(peer, afi, safi, flag);
16514 else
16515 return !!peer_af_flag_check(peer, afi, safi, flag);
16516 }
16517
16518 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16519 }
16520
16521 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16522 uint8_t type, int direct)
16523 {
16524 struct bgp_filter *filter;
16525
16526 if (peer_group_active(peer))
16527 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16528 type);
16529
16530 filter = &peer->filter[afi][safi];
16531 switch (type) {
16532 case PEER_FT_DISTRIBUTE_LIST:
16533 return !!(filter->dlist[direct].name);
16534 case PEER_FT_FILTER_LIST:
16535 return !!(filter->aslist[direct].name);
16536 case PEER_FT_PREFIX_LIST:
16537 return !!(filter->plist[direct].name);
16538 case PEER_FT_ROUTE_MAP:
16539 return !!(filter->map[direct].name);
16540 case PEER_FT_UNSUPPRESS_MAP:
16541 return !!(filter->usmap.name);
16542 case PEER_FT_ADVERTISE_MAP:
16543 return !!(filter->advmap.aname
16544 && ((filter->advmap.condition == direct)
16545 && filter->advmap.cname));
16546 default:
16547 return false;
16548 }
16549 }
16550
16551 /* Return true if the addpath type is set for peer and different from
16552 * peer-group.
16553 */
16554 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16555 safi_t safi)
16556 {
16557 enum bgp_addpath_strat type, g_type;
16558
16559 type = peer->addpath_type[afi][safi];
16560
16561 if (type != BGP_ADDPATH_NONE) {
16562 if (peer_group_active(peer)) {
16563 g_type = peer->group->conf->addpath_type[afi][safi];
16564
16565 if (type != g_type)
16566 return true;
16567 else
16568 return false;
16569 }
16570
16571 return true;
16572 }
16573
16574 return false;
16575 }
16576
16577 /* This is part of the address-family block (unicast only) */
16578 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16579 afi_t afi)
16580 {
16581 int indent = 2;
16582 uint32_t tovpn_sid_index = 0;
16583
16584 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16585 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16586 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16587 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16588 bgp->vpn_policy[afi]
16589 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16590 else
16591 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16592 bgp->vpn_policy[afi]
16593 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16594 }
16595 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16596 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16597 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16598 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16599 return;
16600
16601 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16602 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16603
16604 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16605
16606 } else {
16607 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16608 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16609 bgp->vpn_policy[afi].tovpn_label);
16610 }
16611 }
16612
16613 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16614 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16615 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16616 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16617 } else if (tovpn_sid_index != 0) {
16618 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16619 tovpn_sid_index);
16620 }
16621
16622 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16623 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16624 &bgp->vpn_policy[afi].tovpn_rd);
16625
16626 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16627 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16628
16629 char buf[PREFIX_STRLEN];
16630 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16631 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16632 sizeof(buf))) {
16633
16634 vty_out(vty, "%*snexthop vpn export %s\n",
16635 indent, "", buf);
16636 }
16637 }
16638 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16639 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16640 && ecommunity_cmp(
16641 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16642 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16643
16644 char *b = ecommunity_ecom2str(
16645 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16646 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16647 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16648 XFREE(MTYPE_ECOMMUNITY_STR, b);
16649 } else {
16650 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16651 char *b = ecommunity_ecom2str(
16652 bgp->vpn_policy[afi]
16653 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16654 ECOMMUNITY_FORMAT_ROUTE_MAP,
16655 ECOMMUNITY_ROUTE_TARGET);
16656 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16657 XFREE(MTYPE_ECOMMUNITY_STR, b);
16658 }
16659 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16660 char *b = ecommunity_ecom2str(
16661 bgp->vpn_policy[afi]
16662 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16663 ECOMMUNITY_FORMAT_ROUTE_MAP,
16664 ECOMMUNITY_ROUTE_TARGET);
16665 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16666 XFREE(MTYPE_ECOMMUNITY_STR, b);
16667 }
16668 }
16669
16670 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16671 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16672 bgp->vpn_policy[afi]
16673 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16674
16675 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16676 char *b = ecommunity_ecom2str(
16677 bgp->vpn_policy[afi]
16678 .import_redirect_rtlist,
16679 ECOMMUNITY_FORMAT_ROUTE_MAP,
16680 ECOMMUNITY_ROUTE_TARGET);
16681
16682 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16683 != ECOMMUNITY_SIZE)
16684 vty_out(vty, "%*srt6 redirect import %s\n",
16685 indent, "", b);
16686 else
16687 vty_out(vty, "%*srt redirect import %s\n",
16688 indent, "", b);
16689 XFREE(MTYPE_ECOMMUNITY_STR, b);
16690 }
16691 }
16692
16693 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16694 afi_t afi, safi_t safi)
16695 {
16696 struct bgp_filter *filter;
16697 char *addr;
16698
16699 addr = peer->host;
16700 filter = &peer->filter[afi][safi];
16701
16702 /* distribute-list. */
16703 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16704 FILTER_IN))
16705 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16706 filter->dlist[FILTER_IN].name);
16707
16708 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16709 FILTER_OUT))
16710 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16711 filter->dlist[FILTER_OUT].name);
16712
16713 /* prefix-list. */
16714 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16715 FILTER_IN))
16716 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16717 filter->plist[FILTER_IN].name);
16718
16719 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16720 FILTER_OUT))
16721 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16722 filter->plist[FILTER_OUT].name);
16723
16724 /* route-map. */
16725 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16726 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16727 filter->map[RMAP_IN].name);
16728
16729 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16730 RMAP_OUT))
16731 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16732 filter->map[RMAP_OUT].name);
16733
16734 /* unsuppress-map */
16735 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16736 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16737 filter->usmap.name);
16738
16739 /* advertise-map : always applied in OUT direction*/
16740 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16741 CONDITION_NON_EXIST))
16742 vty_out(vty,
16743 " neighbor %s advertise-map %s non-exist-map %s\n",
16744 addr, filter->advmap.aname, filter->advmap.cname);
16745
16746 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16747 CONDITION_EXIST))
16748 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16749 addr, filter->advmap.aname, filter->advmap.cname);
16750
16751 /* filter-list. */
16752 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16753 FILTER_IN))
16754 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16755 filter->aslist[FILTER_IN].name);
16756
16757 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16758 FILTER_OUT))
16759 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16760 filter->aslist[FILTER_OUT].name);
16761 }
16762
16763 /* BGP peer configuration display function. */
16764 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16765 struct peer *peer)
16766 {
16767 struct peer *g_peer = NULL;
16768 char *addr;
16769 int if_pg_printed = false;
16770 int if_ras_printed = false;
16771
16772 /* Skip dynamic neighbors. */
16773 if (peer_dynamic_neighbor(peer))
16774 return;
16775
16776 if (peer->conf_if)
16777 addr = peer->conf_if;
16778 else
16779 addr = peer->host;
16780
16781 /************************************
16782 ****** Global to the neighbor ******
16783 ************************************/
16784 if (peer->conf_if) {
16785 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16786 vty_out(vty, " neighbor %s interface v6only", addr);
16787 else
16788 vty_out(vty, " neighbor %s interface", addr);
16789
16790 if (peer_group_active(peer)) {
16791 vty_out(vty, " peer-group %s", peer->group->name);
16792 if_pg_printed = true;
16793 } else if (peer->as_type == AS_SPECIFIED) {
16794 vty_out(vty, " remote-as %u", peer->as);
16795 if_ras_printed = true;
16796 } else if (peer->as_type == AS_INTERNAL) {
16797 vty_out(vty, " remote-as internal");
16798 if_ras_printed = true;
16799 } else if (peer->as_type == AS_EXTERNAL) {
16800 vty_out(vty, " remote-as external");
16801 if_ras_printed = true;
16802 }
16803
16804 vty_out(vty, "\n");
16805 }
16806
16807 /* remote-as and peer-group */
16808 /* peer is a member of a peer-group */
16809 if (peer_group_active(peer)) {
16810 g_peer = peer->group->conf;
16811
16812 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16813 if (peer->as_type == AS_SPECIFIED) {
16814 vty_out(vty, " neighbor %s remote-as %u\n",
16815 addr, peer->as);
16816 } else if (peer->as_type == AS_INTERNAL) {
16817 vty_out(vty,
16818 " neighbor %s remote-as internal\n",
16819 addr);
16820 } else if (peer->as_type == AS_EXTERNAL) {
16821 vty_out(vty,
16822 " neighbor %s remote-as external\n",
16823 addr);
16824 }
16825 }
16826
16827 /* For swpX peers we displayed the peer-group
16828 * via 'neighbor swpX interface peer-group PGNAME' */
16829 if (!if_pg_printed)
16830 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16831 peer->group->name);
16832 }
16833
16834 /* peer is NOT a member of a peer-group */
16835 else {
16836 /* peer is a peer-group, declare the peer-group */
16837 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16838 vty_out(vty, " neighbor %s peer-group\n", addr);
16839 }
16840
16841 if (!if_ras_printed) {
16842 if (peer->as_type == AS_SPECIFIED) {
16843 vty_out(vty, " neighbor %s remote-as %u\n",
16844 addr, peer->as);
16845 } else if (peer->as_type == AS_INTERNAL) {
16846 vty_out(vty,
16847 " neighbor %s remote-as internal\n",
16848 addr);
16849 } else if (peer->as_type == AS_EXTERNAL) {
16850 vty_out(vty,
16851 " neighbor %s remote-as external\n",
16852 addr);
16853 }
16854 }
16855 }
16856
16857 /* local-as */
16858 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16859 vty_out(vty, " neighbor %s local-as %u", addr,
16860 peer->change_local_as);
16861 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16862 vty_out(vty, " no-prepend");
16863 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16864 vty_out(vty, " replace-as");
16865 vty_out(vty, "\n");
16866 }
16867
16868 /* description */
16869 if (peer->desc) {
16870 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16871 }
16872
16873 /* shutdown */
16874 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16875 if (peer->tx_shutdown_message)
16876 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16877 peer->tx_shutdown_message);
16878 else
16879 vty_out(vty, " neighbor %s shutdown\n", addr);
16880 }
16881
16882 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16883 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16884 peer->rtt_expected, peer->rtt_keepalive_conf);
16885
16886 /* bfd */
16887 if (peer->bfd_config)
16888 bgp_bfd_peer_config_write(vty, peer, addr);
16889
16890 /* password */
16891 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16892 vty_out(vty, " neighbor %s password %s\n", addr,
16893 peer->password);
16894
16895 /* neighbor solo */
16896 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16897 if (!peer_group_active(peer)) {
16898 vty_out(vty, " neighbor %s solo\n", addr);
16899 }
16900 }
16901
16902 /* BGP port */
16903 if (peer->port != BGP_PORT_DEFAULT) {
16904 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16905 }
16906
16907 /* Local interface name */
16908 if (peer->ifname) {
16909 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16910 }
16911
16912 /* TCP max segment size */
16913 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16914 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16915
16916 /* passive */
16917 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16918 vty_out(vty, " neighbor %s passive\n", addr);
16919
16920 /* ebgp-multihop */
16921 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16922 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16923 && peer->ttl == MAXTTL)) {
16924 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16925 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16926 peer->ttl);
16927 }
16928 }
16929
16930 /* role */
16931 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16932 peer->local_role != ROLE_UNDEFINED)
16933 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16934 bgp_get_name_by_role(peer->local_role),
16935 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
16936 ? " strict-mode"
16937 : "");
16938
16939 /* ttl-security hops */
16940 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16941 if (!peer_group_active(peer)
16942 || g_peer->gtsm_hops != peer->gtsm_hops) {
16943 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16944 addr, peer->gtsm_hops);
16945 }
16946 }
16947
16948 /* disable-connected-check */
16949 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16950 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16951
16952 /* link-bw-encoding-ieee */
16953 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16954 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16955 addr);
16956
16957 /* extended-optional-parameters */
16958 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16959 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16960 addr);
16961
16962 /* enforce-first-as */
16963 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16964 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16965
16966 /* update-source */
16967 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16968 if (peer->update_source)
16969 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16970 peer->update_source);
16971 else if (peer->update_if)
16972 vty_out(vty, " neighbor %s update-source %s\n", addr,
16973 peer->update_if);
16974 }
16975
16976 /* advertisement-interval */
16977 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16978 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16979 peer->routeadv);
16980
16981 /* timers */
16982 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16983 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16984 peer->keepalive, peer->holdtime);
16985
16986 /* timers connect */
16987 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16988 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16989 peer->connect);
16990 /* need special-case handling for changed default values due to
16991 * config profile / version (because there is no "timers bgp connect"
16992 * command, we need to save this per-peer :/)
16993 */
16994 else if (!peer_group_active(peer) && !peer->connect &&
16995 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16996 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16997 peer->bgp->default_connect_retry);
16998
16999 /* timers delayopen */
17000 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17001 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17002 peer->delayopen);
17003 /* Save config even though flag is not set if default values have been
17004 * changed
17005 */
17006 else if (!peer_group_active(peer) && !peer->delayopen
17007 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17008 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17009 peer->bgp->default_delayopen);
17010
17011 /* capability dynamic */
17012 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17013 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17014
17015 /* capability extended-nexthop */
17016 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17017 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17018 !peer->conf_if)
17019 vty_out(vty,
17020 " no neighbor %s capability extended-nexthop\n",
17021 addr);
17022 else if (!peer->conf_if)
17023 vty_out(vty,
17024 " neighbor %s capability extended-nexthop\n",
17025 addr);
17026 }
17027
17028 /* dont-capability-negotiation */
17029 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17030 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17031
17032 /* override-capability */
17033 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17034 vty_out(vty, " neighbor %s override-capability\n", addr);
17035
17036 /* strict-capability-match */
17037 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17038 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17039
17040 /* Sender side AS path loop detection. */
17041 if (peer->as_path_loop_detection)
17042 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17043 addr);
17044
17045 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17046 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17047
17048 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17049 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17050 vty_out(vty,
17051 " neighbor %s graceful-restart-helper\n", addr);
17052 } else if (CHECK_FLAG(
17053 peer->peer_gr_new_status_flag,
17054 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17055 vty_out(vty,
17056 " neighbor %s graceful-restart\n", addr);
17057 } else if (
17058 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17059 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17060 && !(CHECK_FLAG(
17061 peer->peer_gr_new_status_flag,
17062 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17063 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17064 addr);
17065 }
17066 }
17067 }
17068
17069 /* BGP peer configuration display function. */
17070 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17071 struct peer *peer, afi_t afi, safi_t safi)
17072 {
17073 struct peer *g_peer = NULL;
17074 char *addr;
17075 bool flag_scomm, flag_secomm, flag_slcomm;
17076
17077 /* Skip dynamic neighbors. */
17078 if (peer_dynamic_neighbor(peer))
17079 return;
17080
17081 if (peer->conf_if)
17082 addr = peer->conf_if;
17083 else
17084 addr = peer->host;
17085
17086 /************************************
17087 ****** Per AF to the neighbor ******
17088 ************************************/
17089 if (peer_group_active(peer)) {
17090 g_peer = peer->group->conf;
17091
17092 /* If the peer-group is active but peer is not, print a 'no
17093 * activate' */
17094 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17095 vty_out(vty, " no neighbor %s activate\n", addr);
17096 }
17097
17098 /* If the peer-group is not active but peer is, print an
17099 'activate' */
17100 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17101 vty_out(vty, " neighbor %s activate\n", addr);
17102 }
17103 } else {
17104 if (peer->afc[afi][safi]) {
17105 if (safi == SAFI_ENCAP)
17106 vty_out(vty, " neighbor %s activate\n", addr);
17107 else if (!bgp->default_af[afi][safi])
17108 vty_out(vty, " neighbor %s activate\n", addr);
17109 } else {
17110 if (bgp->default_af[afi][safi])
17111 vty_out(vty, " no neighbor %s activate\n",
17112 addr);
17113 }
17114 }
17115
17116 /* addpath TX knobs */
17117 if (peergroup_af_addpath_check(peer, afi, safi)) {
17118 switch (peer->addpath_type[afi][safi]) {
17119 case BGP_ADDPATH_ALL:
17120 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17121 addr);
17122 break;
17123 case BGP_ADDPATH_BEST_PER_AS:
17124 vty_out(vty,
17125 " neighbor %s addpath-tx-bestpath-per-AS\n",
17126 addr);
17127 break;
17128 case BGP_ADDPATH_MAX:
17129 case BGP_ADDPATH_NONE:
17130 break;
17131 }
17132 }
17133
17134 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17135 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17136
17137 /* ORF capability. */
17138 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17139 || peergroup_af_flag_check(peer, afi, safi,
17140 PEER_FLAG_ORF_PREFIX_RM)) {
17141 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17142
17143 if (peergroup_af_flag_check(peer, afi, safi,
17144 PEER_FLAG_ORF_PREFIX_SM)
17145 && peergroup_af_flag_check(peer, afi, safi,
17146 PEER_FLAG_ORF_PREFIX_RM))
17147 vty_out(vty, " both");
17148 else if (peergroup_af_flag_check(peer, afi, safi,
17149 PEER_FLAG_ORF_PREFIX_SM))
17150 vty_out(vty, " send");
17151 else
17152 vty_out(vty, " receive");
17153 vty_out(vty, "\n");
17154 }
17155
17156 /* Route reflector client. */
17157 if (peergroup_af_flag_check(peer, afi, safi,
17158 PEER_FLAG_REFLECTOR_CLIENT)) {
17159 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17160 }
17161
17162 /* next-hop-self force */
17163 if (peergroup_af_flag_check(peer, afi, safi,
17164 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17165 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17166 }
17167
17168 /* next-hop-self */
17169 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17170 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17171 }
17172
17173 /* remove-private-AS */
17174 if (peergroup_af_flag_check(peer, afi, safi,
17175 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17176 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17177 addr);
17178 }
17179
17180 else if (peergroup_af_flag_check(peer, afi, safi,
17181 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17182 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17183 addr);
17184 }
17185
17186 else if (peergroup_af_flag_check(peer, afi, safi,
17187 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17188 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17189 }
17190
17191 else if (peergroup_af_flag_check(peer, afi, safi,
17192 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17193 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17194 }
17195
17196 /* as-override */
17197 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17198 vty_out(vty, " neighbor %s as-override\n", addr);
17199 }
17200
17201 /* send-community print. */
17202 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17203 PEER_FLAG_SEND_COMMUNITY);
17204 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17205 PEER_FLAG_SEND_EXT_COMMUNITY);
17206 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17207 PEER_FLAG_SEND_LARGE_COMMUNITY);
17208
17209 if (flag_scomm && flag_secomm && flag_slcomm) {
17210 vty_out(vty, " no neighbor %s send-community all\n", addr);
17211 } else {
17212 if (flag_scomm)
17213 vty_out(vty, " no neighbor %s send-community\n", addr);
17214 if (flag_secomm)
17215 vty_out(vty,
17216 " no neighbor %s send-community extended\n",
17217 addr);
17218
17219 if (flag_slcomm)
17220 vty_out(vty, " no neighbor %s send-community large\n",
17221 addr);
17222 }
17223
17224 /* Default information */
17225 if (peergroup_af_flag_check(peer, afi, safi,
17226 PEER_FLAG_DEFAULT_ORIGINATE)) {
17227 vty_out(vty, " neighbor %s default-originate", addr);
17228
17229 if (peer->default_rmap[afi][safi].name)
17230 vty_out(vty, " route-map %s",
17231 peer->default_rmap[afi][safi].name);
17232
17233 vty_out(vty, "\n");
17234 }
17235
17236 /* Soft reconfiguration inbound. */
17237 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17238 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17239 addr);
17240 }
17241
17242 /* maximum-prefix. */
17243 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17244 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17245 peer->pmax[afi][safi]);
17246
17247 if (peer->pmax_threshold[afi][safi]
17248 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17249 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17250 if (peer_af_flag_check(peer, afi, safi,
17251 PEER_FLAG_MAX_PREFIX_WARNING))
17252 vty_out(vty, " warning-only");
17253 if (peer->pmax_restart[afi][safi])
17254 vty_out(vty, " restart %u",
17255 peer->pmax_restart[afi][safi]);
17256 if (peer_af_flag_check(peer, afi, safi,
17257 PEER_FLAG_MAX_PREFIX_FORCE))
17258 vty_out(vty, " force");
17259
17260 vty_out(vty, "\n");
17261 }
17262
17263 /* maximum-prefix-out */
17264 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17265 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17266 addr, peer->pmax_out[afi][safi]);
17267
17268 /* Route server client. */
17269 if (peergroup_af_flag_check(peer, afi, safi,
17270 PEER_FLAG_RSERVER_CLIENT)) {
17271 vty_out(vty, " neighbor %s route-server-client\n", addr);
17272 }
17273
17274 /* Nexthop-local unchanged. */
17275 if (peergroup_af_flag_check(peer, afi, safi,
17276 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17277 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17278 }
17279
17280 /* allowas-in <1-10> */
17281 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17282 if (peer_af_flag_check(peer, afi, safi,
17283 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17284 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17285 } else if (peer->allowas_in[afi][safi] == 3) {
17286 vty_out(vty, " neighbor %s allowas-in\n", addr);
17287 } else {
17288 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17289 peer->allowas_in[afi][safi]);
17290 }
17291 }
17292
17293 /* soo */
17294 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17295 char *soo_str = ecommunity_ecom2str(
17296 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17297
17298 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17299 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17300 }
17301
17302 /* weight */
17303 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17304 vty_out(vty, " neighbor %s weight %lu\n", addr,
17305 peer->weight[afi][safi]);
17306
17307 /* Filter. */
17308 bgp_config_write_filter(vty, peer, afi, safi);
17309
17310 /* atribute-unchanged. */
17311 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17312 || (safi != SAFI_EVPN
17313 && peer_af_flag_check(peer, afi, safi,
17314 PEER_FLAG_NEXTHOP_UNCHANGED))
17315 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17316
17317 if (!peer_group_active(peer)
17318 || peergroup_af_flag_check(peer, afi, safi,
17319 PEER_FLAG_AS_PATH_UNCHANGED)
17320 || peergroup_af_flag_check(peer, afi, safi,
17321 PEER_FLAG_NEXTHOP_UNCHANGED)
17322 || peergroup_af_flag_check(peer, afi, safi,
17323 PEER_FLAG_MED_UNCHANGED)) {
17324
17325 vty_out(vty,
17326 " neighbor %s attribute-unchanged%s%s%s\n",
17327 addr,
17328 peer_af_flag_check(peer, afi, safi,
17329 PEER_FLAG_AS_PATH_UNCHANGED)
17330 ? " as-path"
17331 : "",
17332 peer_af_flag_check(peer, afi, safi,
17333 PEER_FLAG_NEXTHOP_UNCHANGED)
17334 ? " next-hop"
17335 : "",
17336 peer_af_flag_check(peer, afi, safi,
17337 PEER_FLAG_MED_UNCHANGED)
17338 ? " med"
17339 : "");
17340 }
17341 }
17342 }
17343
17344 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17345 safi_t safi)
17346 {
17347 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17348 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17349 vty_out(vty, " no bgp retain route-target all\n");
17350 }
17351
17352 /* Address family based peer configuration display. */
17353 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17354 safi_t safi)
17355 {
17356 struct peer *peer;
17357 struct peer_group *group;
17358 struct listnode *node, *nnode;
17359
17360
17361 vty_frame(vty, " !\n address-family ");
17362 if (afi == AFI_IP) {
17363 if (safi == SAFI_UNICAST)
17364 vty_frame(vty, "ipv4 unicast");
17365 else if (safi == SAFI_LABELED_UNICAST)
17366 vty_frame(vty, "ipv4 labeled-unicast");
17367 else if (safi == SAFI_MULTICAST)
17368 vty_frame(vty, "ipv4 multicast");
17369 else if (safi == SAFI_MPLS_VPN)
17370 vty_frame(vty, "ipv4 vpn");
17371 else if (safi == SAFI_ENCAP)
17372 vty_frame(vty, "ipv4 encap");
17373 else if (safi == SAFI_FLOWSPEC)
17374 vty_frame(vty, "ipv4 flowspec");
17375 } else if (afi == AFI_IP6) {
17376 if (safi == SAFI_UNICAST)
17377 vty_frame(vty, "ipv6 unicast");
17378 else if (safi == SAFI_LABELED_UNICAST)
17379 vty_frame(vty, "ipv6 labeled-unicast");
17380 else if (safi == SAFI_MULTICAST)
17381 vty_frame(vty, "ipv6 multicast");
17382 else if (safi == SAFI_MPLS_VPN)
17383 vty_frame(vty, "ipv6 vpn");
17384 else if (safi == SAFI_ENCAP)
17385 vty_frame(vty, "ipv6 encap");
17386 else if (safi == SAFI_FLOWSPEC)
17387 vty_frame(vty, "ipv6 flowspec");
17388 } else if (afi == AFI_L2VPN) {
17389 if (safi == SAFI_EVPN)
17390 vty_frame(vty, "l2vpn evpn");
17391 }
17392 vty_frame(vty, "\n");
17393
17394 bgp_config_write_distance(vty, bgp, afi, safi);
17395
17396 bgp_config_write_network(vty, bgp, afi, safi);
17397
17398 bgp_config_write_redistribute(vty, bgp, afi, safi);
17399
17400 /* BGP flag dampening. */
17401 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17402 bgp_config_write_damp(vty, afi, safi);
17403
17404 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17405 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17406
17407 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17408 /* Do not display doppelganger peers */
17409 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17410 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17411 }
17412
17413 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17414 bgp_config_write_table_map(vty, bgp, afi, safi);
17415
17416 if (safi == SAFI_EVPN)
17417 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17418
17419 if (safi == SAFI_FLOWSPEC)
17420 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17421
17422 if (safi == SAFI_MPLS_VPN)
17423 bgp_vpn_config_write(vty, bgp, afi, safi);
17424
17425 if (safi == SAFI_UNICAST) {
17426 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17427 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17428 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17429
17430 vty_out(vty, " export vpn\n");
17431 }
17432 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17433 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17434
17435 vty_out(vty, " import vpn\n");
17436 }
17437 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17438 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17439 char *name;
17440
17441 for (ALL_LIST_ELEMENTS_RO(
17442 bgp->vpn_policy[afi].import_vrf, node,
17443 name))
17444 vty_out(vty, " import vrf %s\n", name);
17445 }
17446 }
17447
17448 vty_endframe(vty, " exit-address-family\n");
17449 }
17450
17451 int bgp_config_write(struct vty *vty)
17452 {
17453 struct bgp *bgp;
17454 struct peer_group *group;
17455 struct peer *peer;
17456 struct listnode *node, *nnode;
17457 struct listnode *mnode, *mnnode;
17458 afi_t afi;
17459 safi_t safi;
17460
17461 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17462 vty_out(vty, "bgp route-map delay-timer %u\n",
17463 bm->rmap_update_timer);
17464
17465 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17466 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17467 if (bm->v_update_delay != bm->v_establish_wait)
17468 vty_out(vty, " %d", bm->v_establish_wait);
17469 vty_out(vty, "\n");
17470 }
17471
17472 if (bm->wait_for_fib)
17473 vty_out(vty, "bgp suppress-fib-pending\n");
17474
17475 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17476 vty_out(vty, "bgp graceful-shutdown\n");
17477
17478 /* No-RIB (Zebra) option flag configuration */
17479 if (bgp_option_check(BGP_OPT_NO_FIB))
17480 vty_out(vty, "bgp no-rib\n");
17481
17482 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17483 vty_out(vty, "bgp send-extra-data zebra\n");
17484
17485 /* BGP session DSCP value */
17486 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17487 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17488
17489 /* BGP configuration. */
17490 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17491
17492 /* skip all auto created vrf as they dont have user config */
17493 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17494 continue;
17495
17496 /* Router bgp ASN */
17497 vty_out(vty, "router bgp %u", bgp->as);
17498
17499 if (bgp->name)
17500 vty_out(vty, " %s %s",
17501 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17502 ? "view" : "vrf", bgp->name);
17503 vty_out(vty, "\n");
17504
17505 /* BGP fast-external-failover. */
17506 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17507 vty_out(vty, " no bgp fast-external-failover\n");
17508
17509 /* BGP router ID. */
17510 if (bgp->router_id_static.s_addr != INADDR_ANY)
17511 vty_out(vty, " bgp router-id %pI4\n",
17512 &bgp->router_id_static);
17513
17514 /* Suppress fib pending */
17515 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17516 vty_out(vty, " bgp suppress-fib-pending\n");
17517
17518 /* BGP log-neighbor-changes. */
17519 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17520 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17521 vty_out(vty, " %sbgp log-neighbor-changes\n",
17522 CHECK_FLAG(bgp->flags,
17523 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17524 ? ""
17525 : "no ");
17526
17527 /* BGP configuration. */
17528 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17529 vty_out(vty, " bgp always-compare-med\n");
17530
17531 /* RFC8212 default eBGP policy. */
17532 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17533 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17534 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17535 CHECK_FLAG(bgp->flags,
17536 BGP_FLAG_EBGP_REQUIRES_POLICY)
17537 ? ""
17538 : "no ");
17539
17540 /* draft-ietf-idr-deprecate-as-set-confed-set */
17541 if (bgp->reject_as_sets)
17542 vty_out(vty, " bgp reject-as-sets\n");
17543
17544 /* Suppress duplicate updates if the route actually not changed
17545 */
17546 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17547 != SAVE_BGP_SUPPRESS_DUPLICATES)
17548 vty_out(vty, " %sbgp suppress-duplicates\n",
17549 CHECK_FLAG(bgp->flags,
17550 BGP_FLAG_SUPPRESS_DUPLICATES)
17551 ? ""
17552 : "no ");
17553
17554 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17555 */
17556 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17557 SAVE_BGP_HARD_ADMIN_RESET)
17558 vty_out(vty, " %sbgp hard-administrative-reset\n",
17559 CHECK_FLAG(bgp->flags,
17560 BGP_FLAG_HARD_ADMIN_RESET)
17561 ? ""
17562 : "no ");
17563
17564 /* BGP default <afi>-<safi> */
17565 FOREACH_AFI_SAFI (afi, safi) {
17566 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17567 if (!bgp->default_af[afi][safi])
17568 vty_out(vty, " no bgp default %s\n",
17569 get_bgp_default_af_flag(afi,
17570 safi));
17571 } else if (bgp->default_af[afi][safi])
17572 vty_out(vty, " bgp default %s\n",
17573 get_bgp_default_af_flag(afi, safi));
17574 }
17575
17576 /* BGP default local-preference. */
17577 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17578 vty_out(vty, " bgp default local-preference %u\n",
17579 bgp->default_local_pref);
17580
17581 /* BGP default show-hostname */
17582 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17583 != SAVE_BGP_SHOW_HOSTNAME)
17584 vty_out(vty, " %sbgp default show-hostname\n",
17585 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17586 ? ""
17587 : "no ");
17588
17589 /* BGP default show-nexthop-hostname */
17590 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17591 != SAVE_BGP_SHOW_HOSTNAME)
17592 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17593 CHECK_FLAG(bgp->flags,
17594 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17595 ? ""
17596 : "no ");
17597
17598 /* BGP default subgroup-pkt-queue-max. */
17599 if (bgp->default_subgroup_pkt_queue_max
17600 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17601 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17602 bgp->default_subgroup_pkt_queue_max);
17603
17604 /* BGP client-to-client reflection. */
17605 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17606 vty_out(vty, " no bgp client-to-client reflection\n");
17607
17608 /* BGP cluster ID. */
17609 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17610 vty_out(vty, " bgp cluster-id %pI4\n",
17611 &bgp->cluster_id);
17612
17613 /* Disable ebgp connected nexthop check */
17614 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17615 vty_out(vty,
17616 " bgp disable-ebgp-connected-route-check\n");
17617
17618 /* Confederation identifier*/
17619 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17620 vty_out(vty, " bgp confederation identifier %u\n",
17621 bgp->confed_id);
17622
17623 /* Confederation peer */
17624 if (bgp->confed_peers_cnt > 0) {
17625 int i;
17626
17627 vty_out(vty, " bgp confederation peers");
17628
17629 for (i = 0; i < bgp->confed_peers_cnt; i++)
17630 vty_out(vty, " %u", bgp->confed_peers[i]);
17631
17632 vty_out(vty, "\n");
17633 }
17634
17635 /* BGP deterministic-med. */
17636 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17637 != SAVE_BGP_DETERMINISTIC_MED)
17638 vty_out(vty, " %sbgp deterministic-med\n",
17639 CHECK_FLAG(bgp->flags,
17640 BGP_FLAG_DETERMINISTIC_MED)
17641 ? ""
17642 : "no ");
17643
17644 /* BGP update-delay. */
17645 bgp_config_write_update_delay(vty, bgp);
17646
17647 if (bgp->v_maxmed_onstartup
17648 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17649 vty_out(vty, " bgp max-med on-startup %u",
17650 bgp->v_maxmed_onstartup);
17651 if (bgp->maxmed_onstartup_value
17652 != BGP_MAXMED_VALUE_DEFAULT)
17653 vty_out(vty, " %u",
17654 bgp->maxmed_onstartup_value);
17655 vty_out(vty, "\n");
17656 }
17657 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17658 vty_out(vty, " bgp max-med administrative");
17659 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17660 vty_out(vty, " %u", bgp->maxmed_admin_value);
17661 vty_out(vty, "\n");
17662 }
17663
17664 /* write quanta */
17665 bgp_config_write_wpkt_quanta(vty, bgp);
17666 /* read quanta */
17667 bgp_config_write_rpkt_quanta(vty, bgp);
17668
17669 /* coalesce time */
17670 bgp_config_write_coalesce_time(vty, bgp);
17671
17672 /* BGP per-instance graceful-shutdown */
17673 /* BGP-wide settings and per-instance settings are mutually
17674 * exclusive.
17675 */
17676 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17677 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17678 vty_out(vty, " bgp graceful-shutdown\n");
17679
17680 /* Long-lived Graceful Restart */
17681 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17682 vty_out(vty,
17683 " bgp long-lived-graceful-restart stale-time %u\n",
17684 bgp->llgr_stale_time);
17685
17686 /* BGP graceful-restart. */
17687 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17688 vty_out(vty,
17689 " bgp graceful-restart stalepath-time %u\n",
17690 bgp->stalepath_time);
17691
17692 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17693 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17694 bgp->restart_time);
17695
17696 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17697 SAVE_BGP_GRACEFUL_NOTIFICATION)
17698 vty_out(vty, " %sbgp graceful-restart notification\n",
17699 CHECK_FLAG(bgp->flags,
17700 BGP_FLAG_GRACEFUL_NOTIFICATION)
17701 ? ""
17702 : "no ");
17703
17704 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17705 vty_out(vty,
17706 " bgp graceful-restart select-defer-time %u\n",
17707 bgp->select_defer_time);
17708
17709 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17710 vty_out(vty, " bgp graceful-restart\n");
17711
17712 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17713 vty_out(vty, " bgp graceful-restart-disable\n");
17714
17715 /* BGP graceful-restart Preserve State F bit. */
17716 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17717 vty_out(vty,
17718 " bgp graceful-restart preserve-fw-state\n");
17719
17720 /* Stale timer for RIB */
17721 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17722 vty_out(vty,
17723 " bgp graceful-restart rib-stale-time %u\n",
17724 bgp->rib_stale_time);
17725
17726 /* BGP bestpath method. */
17727 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17728 vty_out(vty, " bgp bestpath as-path ignore\n");
17729 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17730 vty_out(vty, " bgp bestpath as-path confed\n");
17731
17732 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17733 if (CHECK_FLAG(bgp->flags,
17734 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17735 vty_out(vty,
17736 " bgp bestpath as-path multipath-relax as-set\n");
17737 } else {
17738 vty_out(vty,
17739 " bgp bestpath as-path multipath-relax\n");
17740 }
17741 }
17742
17743 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17744 vty_out(vty,
17745 " bgp route-reflector allow-outbound-policy\n");
17746 }
17747 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17748 vty_out(vty, " bgp bestpath compare-routerid\n");
17749 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17750 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17751 vty_out(vty, " bgp bestpath med");
17752 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17753 vty_out(vty, " confed");
17754 if (CHECK_FLAG(bgp->flags,
17755 BGP_FLAG_MED_MISSING_AS_WORST))
17756 vty_out(vty, " missing-as-worst");
17757 vty_out(vty, "\n");
17758 }
17759
17760 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17761 vty_out(vty,
17762 " bgp bestpath peer-type multipath-relax\n");
17763
17764 /* Link bandwidth handling. */
17765 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17766 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17767 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17768 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17769 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17770 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17771
17772 /* BGP network import check. */
17773 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17774 != SAVE_BGP_IMPORT_CHECK)
17775 vty_out(vty, " %sbgp network import-check\n",
17776 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17777 ? ""
17778 : "no ");
17779
17780 /* BGP timers configuration. */
17781 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17782 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17783 vty_out(vty, " timers bgp %u %u\n",
17784 bgp->default_keepalive, bgp->default_holdtime);
17785
17786 /* BGP minimum holdtime configuration. */
17787 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17788 && bgp->default_min_holdtime != 0)
17789 vty_out(vty, " bgp minimum-holdtime %u\n",
17790 bgp->default_min_holdtime);
17791
17792 /* Conditional advertisement timer configuration */
17793 if (bgp->condition_check_period
17794 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17795 vty_out(vty,
17796 " bgp conditional-advertisement timer %u\n",
17797 bgp->condition_check_period);
17798
17799 /* peer-group */
17800 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17801 bgp_config_write_peer_global(vty, bgp, group->conf);
17802 }
17803
17804 /* Normal neighbor configuration. */
17805 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17806 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17807 bgp_config_write_peer_global(vty, bgp, peer);
17808 }
17809
17810 /* listen range and limit for dynamic BGP neighbors */
17811 bgp_config_write_listen(vty, bgp);
17812
17813 /*
17814 * BGP default autoshutdown neighbors
17815 *
17816 * This must be placed after any peer and peer-group
17817 * configuration, to avoid setting all peers to shutdown after
17818 * a daemon restart, which is undesired behavior. (see #2286)
17819 */
17820 if (bgp->autoshutdown)
17821 vty_out(vty, " bgp default shutdown\n");
17822
17823 /* BGP instance administrative shutdown */
17824 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17825 vty_out(vty, " bgp shutdown\n");
17826
17827 if (bgp->allow_martian)
17828 vty_out(vty, " bgp allow-martian-nexthop\n");
17829
17830 if (bgp->fast_convergence)
17831 vty_out(vty, " bgp fast-convergence\n");
17832
17833 if (bgp->srv6_enabled) {
17834 vty_frame(vty, " !\n segment-routing srv6\n");
17835 if (strlen(bgp->srv6_locator_name))
17836 vty_out(vty, " locator %s\n",
17837 bgp->srv6_locator_name);
17838 vty_endframe(vty, " exit\n");
17839 }
17840
17841
17842 /* IPv4 unicast configuration. */
17843 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17844
17845 /* IPv4 multicast configuration. */
17846 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17847
17848 /* IPv4 labeled-unicast configuration. */
17849 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17850
17851 /* IPv4 VPN configuration. */
17852 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17853
17854 /* ENCAPv4 configuration. */
17855 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17856
17857 /* FLOWSPEC v4 configuration. */
17858 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17859
17860 /* IPv6 unicast configuration. */
17861 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17862
17863 /* IPv6 multicast configuration. */
17864 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17865
17866 /* IPv6 labeled-unicast configuration. */
17867 bgp_config_write_family(vty, bgp, AFI_IP6,
17868 SAFI_LABELED_UNICAST);
17869
17870 /* IPv6 VPN configuration. */
17871 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17872
17873 /* ENCAPv6 configuration. */
17874 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17875
17876 /* FLOWSPEC v6 configuration. */
17877 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17878
17879 /* EVPN configuration. */
17880 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17881
17882 hook_call(bgp_inst_config_write, bgp, vty);
17883
17884 #ifdef ENABLE_BGP_VNC
17885 bgp_rfapi_cfg_write(vty, bgp);
17886 #endif
17887
17888 vty_out(vty, "exit\n");
17889 vty_out(vty, "!\n");
17890 }
17891 return 0;
17892 }
17893
17894
17895 /* BGP node structure. */
17896 static struct cmd_node bgp_node = {
17897 .name = "bgp",
17898 .node = BGP_NODE,
17899 .parent_node = CONFIG_NODE,
17900 .prompt = "%s(config-router)# ",
17901 .config_write = bgp_config_write,
17902 };
17903
17904 static struct cmd_node bgp_ipv4_unicast_node = {
17905 .name = "bgp ipv4 unicast",
17906 .node = BGP_IPV4_NODE,
17907 .parent_node = BGP_NODE,
17908 .prompt = "%s(config-router-af)# ",
17909 .no_xpath = true,
17910 };
17911
17912 static struct cmd_node bgp_ipv4_multicast_node = {
17913 .name = "bgp ipv4 multicast",
17914 .node = BGP_IPV4M_NODE,
17915 .parent_node = BGP_NODE,
17916 .prompt = "%s(config-router-af)# ",
17917 .no_xpath = true,
17918 };
17919
17920 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17921 .name = "bgp ipv4 labeled unicast",
17922 .node = BGP_IPV4L_NODE,
17923 .parent_node = BGP_NODE,
17924 .prompt = "%s(config-router-af)# ",
17925 .no_xpath = true,
17926 };
17927
17928 static struct cmd_node bgp_ipv6_unicast_node = {
17929 .name = "bgp ipv6 unicast",
17930 .node = BGP_IPV6_NODE,
17931 .parent_node = BGP_NODE,
17932 .prompt = "%s(config-router-af)# ",
17933 .no_xpath = true,
17934 };
17935
17936 static struct cmd_node bgp_ipv6_multicast_node = {
17937 .name = "bgp ipv6 multicast",
17938 .node = BGP_IPV6M_NODE,
17939 .parent_node = BGP_NODE,
17940 .prompt = "%s(config-router-af)# ",
17941 .no_xpath = true,
17942 };
17943
17944 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17945 .name = "bgp ipv6 labeled unicast",
17946 .node = BGP_IPV6L_NODE,
17947 .parent_node = BGP_NODE,
17948 .prompt = "%s(config-router-af)# ",
17949 .no_xpath = true,
17950 };
17951
17952 static struct cmd_node bgp_vpnv4_node = {
17953 .name = "bgp vpnv4",
17954 .node = BGP_VPNV4_NODE,
17955 .parent_node = BGP_NODE,
17956 .prompt = "%s(config-router-af)# ",
17957 .no_xpath = true,
17958 };
17959
17960 static struct cmd_node bgp_vpnv6_node = {
17961 .name = "bgp vpnv6",
17962 .node = BGP_VPNV6_NODE,
17963 .parent_node = BGP_NODE,
17964 .prompt = "%s(config-router-af-vpnv6)# ",
17965 .no_xpath = true,
17966 };
17967
17968 static struct cmd_node bgp_evpn_node = {
17969 .name = "bgp evpn",
17970 .node = BGP_EVPN_NODE,
17971 .parent_node = BGP_NODE,
17972 .prompt = "%s(config-router-evpn)# ",
17973 .no_xpath = true,
17974 };
17975
17976 static struct cmd_node bgp_evpn_vni_node = {
17977 .name = "bgp evpn vni",
17978 .node = BGP_EVPN_VNI_NODE,
17979 .parent_node = BGP_EVPN_NODE,
17980 .prompt = "%s(config-router-af-vni)# ",
17981 };
17982
17983 static struct cmd_node bgp_flowspecv4_node = {
17984 .name = "bgp ipv4 flowspec",
17985 .node = BGP_FLOWSPECV4_NODE,
17986 .parent_node = BGP_NODE,
17987 .prompt = "%s(config-router-af)# ",
17988 .no_xpath = true,
17989 };
17990
17991 static struct cmd_node bgp_flowspecv6_node = {
17992 .name = "bgp ipv6 flowspec",
17993 .node = BGP_FLOWSPECV6_NODE,
17994 .parent_node = BGP_NODE,
17995 .prompt = "%s(config-router-af-vpnv6)# ",
17996 .no_xpath = true,
17997 };
17998
17999 static struct cmd_node bgp_srv6_node = {
18000 .name = "bgp srv6",
18001 .node = BGP_SRV6_NODE,
18002 .parent_node = BGP_NODE,
18003 .prompt = "%s(config-router-srv6)# ",
18004 };
18005
18006 static void community_list_vty(void);
18007
18008 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18009 {
18010 struct bgp *bgp;
18011 struct peer_group *group;
18012 struct listnode *lnbgp, *lnpeer;
18013
18014 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18015 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18016 vector_set(comps,
18017 XSTRDUP(MTYPE_COMPLETION, group->name));
18018 }
18019 }
18020
18021 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18022 {
18023 struct bgp *bgp;
18024 struct peer *peer;
18025 struct listnode *lnbgp, *lnpeer;
18026
18027 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18028 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18029 /* only provide suggestions on the appropriate input
18030 * token type,
18031 * they'll otherwise show up multiple times */
18032 enum cmd_token_type match_type;
18033 char *name = peer->host;
18034
18035 if (peer->conf_if) {
18036 match_type = VARIABLE_TKN;
18037 name = peer->conf_if;
18038 } else if (strchr(peer->host, ':'))
18039 match_type = IPV6_TKN;
18040 else
18041 match_type = IPV4_TKN;
18042
18043 if (token->type != match_type)
18044 continue;
18045
18046 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18047 }
18048 }
18049 }
18050
18051 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18052 {
18053 bgp_ac_peer(comps, token);
18054
18055 if (token->type == VARIABLE_TKN)
18056 bgp_ac_peergroup(comps, token);
18057 }
18058
18059 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18060 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18061 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18062 {.varname = "peer", .completions = bgp_ac_neighbor},
18063 {.completions = NULL}};
18064
18065 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18066 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18067 {.completions = NULL} };
18068
18069 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18070
18071 static struct thread *t_bgp_cfg;
18072
18073 bool bgp_config_inprocess(void)
18074 {
18075 return thread_is_scheduled(t_bgp_cfg);
18076 }
18077
18078 static void bgp_config_finish(struct thread *t)
18079 {
18080 struct listnode *node;
18081 struct bgp *bgp;
18082
18083 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18084 hook_call(bgp_config_end, bgp);
18085 }
18086
18087 static void bgp_config_start(void)
18088 {
18089 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18090 THREAD_OFF(t_bgp_cfg);
18091 thread_add_timer(bm->master, bgp_config_finish, NULL,
18092 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18093 }
18094
18095 /* When we receive a hook the configuration is read,
18096 * we start a timer to make sure we postpone sending
18097 * EoR before route-maps are processed.
18098 * This is especially valid if using `bgp route-map delay-timer`.
18099 */
18100 static void bgp_config_end(void)
18101 {
18102 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18103 uint32_t bgp_post_config_delay =
18104 thread_is_scheduled(bm->t_rmap_update)
18105 ? thread_timer_remain_second(bm->t_rmap_update)
18106 : BGP_POST_CONFIG_DELAY_SECONDS;
18107
18108 /* If BGP config processing thread isn't running, then
18109 * we can return and rely it's properly handled.
18110 */
18111 if (!bgp_config_inprocess())
18112 return;
18113
18114 THREAD_OFF(t_bgp_cfg);
18115
18116 /* Start a new timer to make sure we don't send EoR
18117 * before route-maps are processed.
18118 */
18119 thread_add_timer(bm->master, bgp_config_finish, NULL,
18120 bgp_post_config_delay, &t_bgp_cfg);
18121 }
18122
18123 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18124 {
18125 int write = 0;
18126 struct interface *ifp;
18127 struct bgp_interface *iifp;
18128
18129 FOR_ALL_INTERFACES (vrf, ifp) {
18130 iifp = ifp->info;
18131 if (!iifp)
18132 continue;
18133
18134 if_vty_config_start(vty, ifp);
18135
18136 if (CHECK_FLAG(iifp->flags,
18137 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18138 vty_out(vty, " mpls bgp forwarding\n");
18139 write++;
18140 }
18141
18142 if_vty_config_end(vty);
18143 }
18144
18145 return write;
18146 }
18147
18148 /* Configuration write function for bgpd. */
18149 static int config_write_interface(struct vty *vty)
18150 {
18151 int write = 0;
18152 struct vrf *vrf = NULL;
18153
18154 /* Display all VRF aware OSPF interface configuration */
18155 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18156 write += config_write_interface_one(vty, vrf);
18157 }
18158
18159 return write;
18160 }
18161
18162 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18163 "[no$no] mpls bgp forwarding",
18164 NO_STR MPLS_STR BGP_STR
18165 "Enable MPLS forwarding for eBGP directly connected peers\n")
18166 {
18167 bool check;
18168 struct bgp_interface *iifp;
18169
18170 VTY_DECLVAR_CONTEXT(interface, ifp);
18171 iifp = ifp->info;
18172 if (!iifp) {
18173 vty_out(vty, "Interface %s not available\n", ifp->name);
18174 return CMD_WARNING_CONFIG_FAILED;
18175 }
18176 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18177 if (check != !no) {
18178 if (no)
18179 UNSET_FLAG(iifp->flags,
18180 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18181 else
18182 SET_FLAG(iifp->flags,
18183 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18184 /* trigger a nht update on eBGP sessions */
18185 if (if_is_operative(ifp))
18186 bgp_nht_ifp_up(ifp);
18187 }
18188 return CMD_SUCCESS;
18189 }
18190
18191 /* Initialization of BGP interface. */
18192 static void bgp_vty_if_init(void)
18193 {
18194 /* Install interface node. */
18195 if_cmd_init(config_write_interface);
18196
18197 /* "mpls bgp forwarding" commands. */
18198 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18199 }
18200
18201 void bgp_vty_init(void)
18202 {
18203 cmd_variable_handler_register(bgp_var_neighbor);
18204 cmd_variable_handler_register(bgp_var_peergroup);
18205
18206 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18207
18208 /* Install bgp top node. */
18209 install_node(&bgp_node);
18210 install_node(&bgp_ipv4_unicast_node);
18211 install_node(&bgp_ipv4_multicast_node);
18212 install_node(&bgp_ipv4_labeled_unicast_node);
18213 install_node(&bgp_ipv6_unicast_node);
18214 install_node(&bgp_ipv6_multicast_node);
18215 install_node(&bgp_ipv6_labeled_unicast_node);
18216 install_node(&bgp_vpnv4_node);
18217 install_node(&bgp_vpnv6_node);
18218 install_node(&bgp_evpn_node);
18219 install_node(&bgp_evpn_vni_node);
18220 install_node(&bgp_flowspecv4_node);
18221 install_node(&bgp_flowspecv6_node);
18222 install_node(&bgp_srv6_node);
18223
18224 /* Install default VTY commands to new nodes. */
18225 install_default(BGP_NODE);
18226 install_default(BGP_IPV4_NODE);
18227 install_default(BGP_IPV4M_NODE);
18228 install_default(BGP_IPV4L_NODE);
18229 install_default(BGP_IPV6_NODE);
18230 install_default(BGP_IPV6M_NODE);
18231 install_default(BGP_IPV6L_NODE);
18232 install_default(BGP_VPNV4_NODE);
18233 install_default(BGP_VPNV6_NODE);
18234 install_default(BGP_FLOWSPECV4_NODE);
18235 install_default(BGP_FLOWSPECV6_NODE);
18236 install_default(BGP_EVPN_NODE);
18237 install_default(BGP_EVPN_VNI_NODE);
18238 install_default(BGP_SRV6_NODE);
18239
18240 /* "bgp local-mac" hidden commands. */
18241 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18242 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18243
18244 /* "bgp suppress-fib-pending" global */
18245 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18246
18247 /* bgp route-map delay-timer commands. */
18248 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18249 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18250
18251 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18252
18253 /* bgp fast-convergence command */
18254 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18255 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18256
18257 /* global bgp update-delay command */
18258 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18259 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18260
18261 /* global bgp graceful-shutdown command */
18262 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18263 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18264
18265 /* Dummy commands (Currently not supported) */
18266 install_element(BGP_NODE, &no_synchronization_cmd);
18267 install_element(BGP_NODE, &no_auto_summary_cmd);
18268
18269 /* "router bgp" commands. */
18270 install_element(CONFIG_NODE, &router_bgp_cmd);
18271
18272 /* "no router bgp" commands. */
18273 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18274
18275 /* "bgp session-dscp command */
18276 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18277 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18278
18279 /* "bgp router-id" commands. */
18280 install_element(BGP_NODE, &bgp_router_id_cmd);
18281 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18282
18283 /* "bgp suppress-fib-pending" command */
18284 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18285
18286 /* "bgp cluster-id" commands. */
18287 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18288 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18289
18290 /* "bgp no-rib" commands. */
18291 install_element(CONFIG_NODE, &bgp_norib_cmd);
18292 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18293
18294 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18295
18296 /* "bgp confederation" commands. */
18297 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18298 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18299
18300 /* "bgp confederation peers" commands. */
18301 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18302 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18303
18304 /* bgp max-med command */
18305 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18306 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18307 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18308 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18309 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18310
18311 /* "neighbor role" commands. */
18312 install_element(BGP_NODE, &neighbor_role_cmd);
18313 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18314 install_element(BGP_NODE, &no_neighbor_role_cmd);
18315
18316 /* bgp disable-ebgp-connected-nh-check */
18317 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18318 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18319
18320 /* bgp update-delay command */
18321 install_element(BGP_NODE, &bgp_update_delay_cmd);
18322 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18323
18324 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18325 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18326
18327 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18328 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18329
18330 /* "maximum-paths" commands. */
18331 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18332 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18333 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18334 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18335 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18336 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18337 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18338 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18339 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18340 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18341 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18342 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18343 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18344 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18345 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18346
18347 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18348 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18349 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18350 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18351 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18352 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18353 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18354 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18355 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18356 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18357
18358 /* "timers bgp" commands. */
18359 install_element(BGP_NODE, &bgp_timers_cmd);
18360 install_element(BGP_NODE, &no_bgp_timers_cmd);
18361
18362 /* "minimum-holdtime" commands. */
18363 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18364 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18365
18366 /* route-map delay-timer commands - per instance for backwards compat.
18367 */
18368 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18369 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18370
18371 /* "bgp client-to-client reflection" commands */
18372 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18373 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18374
18375 /* "bgp always-compare-med" commands */
18376 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18377 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18378
18379 /* bgp ebgp-requires-policy */
18380 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18381 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18382
18383 /* bgp suppress-duplicates */
18384 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18385 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18386
18387 /* bgp reject-as-sets */
18388 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18389 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18390
18391 /* "bgp deterministic-med" commands */
18392 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18393 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18394
18395 /* "bgp graceful-restart" command */
18396 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18397 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18398
18399 /* "bgp graceful-restart-disable" command */
18400 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18401 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18402
18403 /* "neighbor a:b:c:d graceful-restart" command */
18404 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18405 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18406
18407 /* "neighbor a:b:c:d graceful-restart-disable" command */
18408 install_element(BGP_NODE,
18409 &bgp_neighbor_graceful_restart_disable_set_cmd);
18410 install_element(BGP_NODE,
18411 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18412
18413 /* "neighbor a:b:c:d graceful-restart-helper" command */
18414 install_element(BGP_NODE,
18415 &bgp_neighbor_graceful_restart_helper_set_cmd);
18416 install_element(BGP_NODE,
18417 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18418
18419 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18420 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18421 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18422 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18423 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18424 install_element(BGP_NODE,
18425 &no_bgp_graceful_restart_select_defer_time_cmd);
18426 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18427 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18428 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18429
18430 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18431 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18432 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18433 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18434
18435 /* "bgp graceful-shutdown" commands */
18436 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18437 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18438
18439 /* "bgp hard-administrative-reset" commands */
18440 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18441
18442 /* "bgp long-lived-graceful-restart" commands */
18443 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18444 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18445
18446 /* "bgp fast-external-failover" commands */
18447 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18448 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18449
18450 /* "bgp bestpath compare-routerid" commands */
18451 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18452 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18453
18454 /* "bgp bestpath as-path ignore" commands */
18455 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18456 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18457
18458 /* "bgp bestpath as-path confed" commands */
18459 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18460 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18461
18462 /* "bgp bestpath as-path multipath-relax" commands */
18463 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18464 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18465
18466 /* "bgp bestpath peer-type multipath-relax" commands */
18467 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18468 install_element(BGP_NODE,
18469 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18470
18471 /* "bgp log-neighbor-changes" commands */
18472 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18473 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18474
18475 /* "bgp bestpath med" commands */
18476 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18477 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18478
18479 /* "bgp bestpath bandwidth" commands */
18480 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18481 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18482
18483 /* "no bgp default <afi>-<safi>" commands. */
18484 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18485
18486 /* "bgp network import-check" commands. */
18487 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18488 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18489 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18490
18491 /* "bgp default local-preference" commands. */
18492 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18493 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18494
18495 /* bgp default show-hostname */
18496 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18497 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18498
18499 /* bgp default show-nexthop-hostname */
18500 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18501 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18502
18503 /* "bgp default subgroup-pkt-queue-max" commands. */
18504 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18505 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18506
18507 /* bgp ibgp-allow-policy-mods command */
18508 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18509 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18510
18511 /* "bgp listen limit" commands. */
18512 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18513 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18514
18515 /* "bgp listen range" commands. */
18516 install_element(BGP_NODE, &bgp_listen_range_cmd);
18517 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18518
18519 /* "bgp default shutdown" command */
18520 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18521
18522 /* "bgp shutdown" commands */
18523 install_element(BGP_NODE, &bgp_shutdown_cmd);
18524 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18525 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18526 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18527
18528 /* "neighbor remote-as" commands. */
18529 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18530 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18531 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18532 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18533 install_element(BGP_NODE,
18534 &neighbor_interface_v6only_config_remote_as_cmd);
18535 install_element(BGP_NODE, &no_neighbor_cmd);
18536 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18537
18538 /* "neighbor peer-group" commands. */
18539 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18540 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18541 install_element(BGP_NODE,
18542 &no_neighbor_interface_peer_group_remote_as_cmd);
18543
18544 /* "neighbor local-as" commands. */
18545 install_element(BGP_NODE, &neighbor_local_as_cmd);
18546 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18547 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18548 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18549
18550 /* "neighbor solo" commands. */
18551 install_element(BGP_NODE, &neighbor_solo_cmd);
18552 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18553
18554 /* "neighbor password" commands. */
18555 install_element(BGP_NODE, &neighbor_password_cmd);
18556 install_element(BGP_NODE, &no_neighbor_password_cmd);
18557
18558 /* "neighbor activate" commands. */
18559 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18560 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18561 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18562 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18563 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18564 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18565 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18566 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18567 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18568 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18569 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18570 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18571
18572 /* "no neighbor activate" commands. */
18573 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18574 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18575 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18576 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18577 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18578 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18579 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18580 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18581 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18582 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18583 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18584 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18585
18586 /* "neighbor peer-group" set commands. */
18587 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18588 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18589 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18590 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18591 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18592 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18593 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18594 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18595 install_element(BGP_FLOWSPECV4_NODE,
18596 &neighbor_set_peer_group_hidden_cmd);
18597 install_element(BGP_FLOWSPECV6_NODE,
18598 &neighbor_set_peer_group_hidden_cmd);
18599
18600 /* "no neighbor peer-group unset" commands. */
18601 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18602 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18603 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18604 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18605 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18606 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18607 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18608 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18609 install_element(BGP_FLOWSPECV4_NODE,
18610 &no_neighbor_set_peer_group_hidden_cmd);
18611 install_element(BGP_FLOWSPECV6_NODE,
18612 &no_neighbor_set_peer_group_hidden_cmd);
18613
18614 /* "neighbor softreconfiguration inbound" commands.*/
18615 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18616 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18617 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18618 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18619 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18620 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18621 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18622 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18623 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18624 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18625 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18626 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18627 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18628 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18629 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18630 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18631 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18632 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18633 install_element(BGP_FLOWSPECV4_NODE,
18634 &neighbor_soft_reconfiguration_cmd);
18635 install_element(BGP_FLOWSPECV4_NODE,
18636 &no_neighbor_soft_reconfiguration_cmd);
18637 install_element(BGP_FLOWSPECV6_NODE,
18638 &neighbor_soft_reconfiguration_cmd);
18639 install_element(BGP_FLOWSPECV6_NODE,
18640 &no_neighbor_soft_reconfiguration_cmd);
18641 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18642 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18643
18644 /* "neighbor attribute-unchanged" commands. */
18645 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18646 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18647 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18648 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18649 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18650 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18651 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18652 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18653 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18654 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18655 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18656 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18657 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18658 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18659 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18660 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18661 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18662 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18663
18664 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18665 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18666
18667 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18668 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18669 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18670 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18671
18672 /* "nexthop-local unchanged" commands */
18673 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18674 install_element(BGP_IPV6_NODE,
18675 &no_neighbor_nexthop_local_unchanged_cmd);
18676
18677 /* "neighbor next-hop-self" commands. */
18678 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18679 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18680 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18681 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18682 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18683 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18684 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18685 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18686 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18687 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18688 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18689 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18690 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18691 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18692 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18693 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18694 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18695 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18696 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18697 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18698
18699 /* "neighbor next-hop-self force" commands. */
18700 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18701 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18702 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18703 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18704 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18705 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18706 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18707 install_element(BGP_IPV4_NODE,
18708 &no_neighbor_nexthop_self_all_hidden_cmd);
18709 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18710 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18711 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18712 install_element(BGP_IPV4M_NODE,
18713 &no_neighbor_nexthop_self_all_hidden_cmd);
18714 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18715 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18716 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18717 install_element(BGP_IPV4L_NODE,
18718 &no_neighbor_nexthop_self_all_hidden_cmd);
18719 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18720 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18721 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18722 install_element(BGP_IPV6_NODE,
18723 &no_neighbor_nexthop_self_all_hidden_cmd);
18724 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18725 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18726 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18727 install_element(BGP_IPV6M_NODE,
18728 &no_neighbor_nexthop_self_all_hidden_cmd);
18729 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18730 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18731 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18732 install_element(BGP_IPV6L_NODE,
18733 &no_neighbor_nexthop_self_all_hidden_cmd);
18734 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18735 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18736 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18737 install_element(BGP_VPNV4_NODE,
18738 &no_neighbor_nexthop_self_all_hidden_cmd);
18739 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18740 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18741 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18742 install_element(BGP_VPNV6_NODE,
18743 &no_neighbor_nexthop_self_all_hidden_cmd);
18744 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18745 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18746
18747 /* "neighbor as-override" commands. */
18748 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18749 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18750 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18751 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18752 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18753 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18754 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18755 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18756 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18757 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18758 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18759 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18760 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18761 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18762 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18763 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18764 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18765 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18766
18767 /* "neighbor remove-private-AS" commands. */
18768 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18769 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18770 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18771 install_element(BGP_NODE,
18772 &no_neighbor_remove_private_as_all_hidden_cmd);
18773 install_element(BGP_NODE,
18774 &neighbor_remove_private_as_replace_as_hidden_cmd);
18775 install_element(BGP_NODE,
18776 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18777 install_element(BGP_NODE,
18778 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18779 install_element(
18780 BGP_NODE,
18781 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18782 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18783 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18784 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18785 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18786 install_element(BGP_IPV4_NODE,
18787 &neighbor_remove_private_as_replace_as_cmd);
18788 install_element(BGP_IPV4_NODE,
18789 &no_neighbor_remove_private_as_replace_as_cmd);
18790 install_element(BGP_IPV4_NODE,
18791 &neighbor_remove_private_as_all_replace_as_cmd);
18792 install_element(BGP_IPV4_NODE,
18793 &no_neighbor_remove_private_as_all_replace_as_cmd);
18794 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18795 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18796 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18797 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18798 install_element(BGP_IPV4M_NODE,
18799 &neighbor_remove_private_as_replace_as_cmd);
18800 install_element(BGP_IPV4M_NODE,
18801 &no_neighbor_remove_private_as_replace_as_cmd);
18802 install_element(BGP_IPV4M_NODE,
18803 &neighbor_remove_private_as_all_replace_as_cmd);
18804 install_element(BGP_IPV4M_NODE,
18805 &no_neighbor_remove_private_as_all_replace_as_cmd);
18806 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18807 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18808 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18809 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18810 install_element(BGP_IPV4L_NODE,
18811 &neighbor_remove_private_as_replace_as_cmd);
18812 install_element(BGP_IPV4L_NODE,
18813 &no_neighbor_remove_private_as_replace_as_cmd);
18814 install_element(BGP_IPV4L_NODE,
18815 &neighbor_remove_private_as_all_replace_as_cmd);
18816 install_element(BGP_IPV4L_NODE,
18817 &no_neighbor_remove_private_as_all_replace_as_cmd);
18818 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18819 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18820 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18821 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18822 install_element(BGP_IPV6_NODE,
18823 &neighbor_remove_private_as_replace_as_cmd);
18824 install_element(BGP_IPV6_NODE,
18825 &no_neighbor_remove_private_as_replace_as_cmd);
18826 install_element(BGP_IPV6_NODE,
18827 &neighbor_remove_private_as_all_replace_as_cmd);
18828 install_element(BGP_IPV6_NODE,
18829 &no_neighbor_remove_private_as_all_replace_as_cmd);
18830 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18831 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18832 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18833 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18834 install_element(BGP_IPV6M_NODE,
18835 &neighbor_remove_private_as_replace_as_cmd);
18836 install_element(BGP_IPV6M_NODE,
18837 &no_neighbor_remove_private_as_replace_as_cmd);
18838 install_element(BGP_IPV6M_NODE,
18839 &neighbor_remove_private_as_all_replace_as_cmd);
18840 install_element(BGP_IPV6M_NODE,
18841 &no_neighbor_remove_private_as_all_replace_as_cmd);
18842 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18843 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18844 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18845 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18846 install_element(BGP_IPV6L_NODE,
18847 &neighbor_remove_private_as_replace_as_cmd);
18848 install_element(BGP_IPV6L_NODE,
18849 &no_neighbor_remove_private_as_replace_as_cmd);
18850 install_element(BGP_IPV6L_NODE,
18851 &neighbor_remove_private_as_all_replace_as_cmd);
18852 install_element(BGP_IPV6L_NODE,
18853 &no_neighbor_remove_private_as_all_replace_as_cmd);
18854 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18855 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18856 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18857 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18858 install_element(BGP_VPNV4_NODE,
18859 &neighbor_remove_private_as_replace_as_cmd);
18860 install_element(BGP_VPNV4_NODE,
18861 &no_neighbor_remove_private_as_replace_as_cmd);
18862 install_element(BGP_VPNV4_NODE,
18863 &neighbor_remove_private_as_all_replace_as_cmd);
18864 install_element(BGP_VPNV4_NODE,
18865 &no_neighbor_remove_private_as_all_replace_as_cmd);
18866 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18867 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18868 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18869 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18870 install_element(BGP_VPNV6_NODE,
18871 &neighbor_remove_private_as_replace_as_cmd);
18872 install_element(BGP_VPNV6_NODE,
18873 &no_neighbor_remove_private_as_replace_as_cmd);
18874 install_element(BGP_VPNV6_NODE,
18875 &neighbor_remove_private_as_all_replace_as_cmd);
18876 install_element(BGP_VPNV6_NODE,
18877 &no_neighbor_remove_private_as_all_replace_as_cmd);
18878
18879 /* "neighbor send-community" commands.*/
18880 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18881 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18882 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18883 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18884 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18885 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18886 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18887 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18888 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18889 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18890 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18891 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18892 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18893 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18894 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18895 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18896 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18897 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18898 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18899 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18900 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18901 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18902 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18903 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18904 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18905 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18906 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18907 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18908 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18909 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18910 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18911 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18912 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18913 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18914 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18915 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18916
18917 /* "neighbor route-reflector" commands.*/
18918 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18919 install_element(BGP_NODE,
18920 &no_neighbor_route_reflector_client_hidden_cmd);
18921 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18922 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18923 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18924 install_element(BGP_IPV4M_NODE,
18925 &no_neighbor_route_reflector_client_cmd);
18926 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18927 install_element(BGP_IPV4L_NODE,
18928 &no_neighbor_route_reflector_client_cmd);
18929 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18930 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18931 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18932 install_element(BGP_IPV6M_NODE,
18933 &no_neighbor_route_reflector_client_cmd);
18934 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18935 install_element(BGP_IPV6L_NODE,
18936 &no_neighbor_route_reflector_client_cmd);
18937 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18938 install_element(BGP_VPNV4_NODE,
18939 &no_neighbor_route_reflector_client_cmd);
18940 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18941 install_element(BGP_VPNV6_NODE,
18942 &no_neighbor_route_reflector_client_cmd);
18943 install_element(BGP_FLOWSPECV4_NODE,
18944 &neighbor_route_reflector_client_cmd);
18945 install_element(BGP_FLOWSPECV4_NODE,
18946 &no_neighbor_route_reflector_client_cmd);
18947 install_element(BGP_FLOWSPECV6_NODE,
18948 &neighbor_route_reflector_client_cmd);
18949 install_element(BGP_FLOWSPECV6_NODE,
18950 &no_neighbor_route_reflector_client_cmd);
18951 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18952 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18953
18954 /* "neighbor route-server" commands.*/
18955 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18956 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18957 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18958 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18959 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18960 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18961 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18962 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18963 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18964 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18965 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18966 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18967 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18968 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18969 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18970 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18971 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18972 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18973 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18974 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18975 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18976 install_element(BGP_FLOWSPECV4_NODE,
18977 &no_neighbor_route_server_client_cmd);
18978 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18979 install_element(BGP_FLOWSPECV6_NODE,
18980 &no_neighbor_route_server_client_cmd);
18981
18982 /* "neighbor disable-addpath-rx" commands. */
18983 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18984 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18985 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18986 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18987 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18988 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18989 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18990 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18991 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18992 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18993 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18994 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18995 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18996 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18997 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18998 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18999
19000 /* "neighbor addpath-tx-all-paths" commands.*/
19001 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19002 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19003 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19004 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19005 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19006 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19007 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19008 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19009 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19010 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19011 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19012 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19013 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19014 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19015 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19016 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19017 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19018 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19019
19020 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19021 install_element(BGP_NODE,
19022 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19023 install_element(BGP_NODE,
19024 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19025 install_element(BGP_IPV4_NODE,
19026 &neighbor_addpath_tx_bestpath_per_as_cmd);
19027 install_element(BGP_IPV4_NODE,
19028 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19029 install_element(BGP_IPV4M_NODE,
19030 &neighbor_addpath_tx_bestpath_per_as_cmd);
19031 install_element(BGP_IPV4M_NODE,
19032 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19033 install_element(BGP_IPV4L_NODE,
19034 &neighbor_addpath_tx_bestpath_per_as_cmd);
19035 install_element(BGP_IPV4L_NODE,
19036 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19037 install_element(BGP_IPV6_NODE,
19038 &neighbor_addpath_tx_bestpath_per_as_cmd);
19039 install_element(BGP_IPV6_NODE,
19040 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19041 install_element(BGP_IPV6M_NODE,
19042 &neighbor_addpath_tx_bestpath_per_as_cmd);
19043 install_element(BGP_IPV6M_NODE,
19044 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19045 install_element(BGP_IPV6L_NODE,
19046 &neighbor_addpath_tx_bestpath_per_as_cmd);
19047 install_element(BGP_IPV6L_NODE,
19048 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19049 install_element(BGP_VPNV4_NODE,
19050 &neighbor_addpath_tx_bestpath_per_as_cmd);
19051 install_element(BGP_VPNV4_NODE,
19052 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19053 install_element(BGP_VPNV6_NODE,
19054 &neighbor_addpath_tx_bestpath_per_as_cmd);
19055 install_element(BGP_VPNV6_NODE,
19056 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19057
19058 /* "neighbor sender-as-path-loop-detection" commands. */
19059 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19060 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19061
19062 /* "neighbor passive" commands. */
19063 install_element(BGP_NODE, &neighbor_passive_cmd);
19064 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19065
19066
19067 /* "neighbor shutdown" commands. */
19068 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19069 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19070 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19071 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19072 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19073 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19074
19075 /* "neighbor capability extended-nexthop" commands.*/
19076 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19077 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19078
19079 /* "neighbor capability orf prefix-list" commands.*/
19080 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19081 install_element(BGP_NODE,
19082 &no_neighbor_capability_orf_prefix_hidden_cmd);
19083 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19084 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19085 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19086 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19087 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19088 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19089 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19090 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19091 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19092 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19093 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19094 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19095
19096 /* "neighbor capability dynamic" commands.*/
19097 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19098 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19099
19100 /* "neighbor dont-capability-negotiate" commands. */
19101 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19102 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19103
19104 /* "neighbor ebgp-multihop" commands. */
19105 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19106 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19107 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19108
19109 /* "neighbor disable-connected-check" commands. */
19110 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19111 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19112
19113 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19114 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19115 install_element(BGP_NODE,
19116 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19117
19118 /* "neighbor extended-optional-parameters" commands. */
19119 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19120 install_element(BGP_NODE,
19121 &no_neighbor_extended_optional_parameters_cmd);
19122
19123 /* "neighbor enforce-first-as" commands. */
19124 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19125 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19126
19127 /* "neighbor description" commands. */
19128 install_element(BGP_NODE, &neighbor_description_cmd);
19129 install_element(BGP_NODE, &no_neighbor_description_cmd);
19130 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19131
19132 /* "neighbor update-source" commands. "*/
19133 install_element(BGP_NODE, &neighbor_update_source_cmd);
19134 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19135
19136 /* "neighbor default-originate" commands. */
19137 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19138 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19139 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19140 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19141 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19142 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19143 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19144 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19145 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19146 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19147 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19148 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19149 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19150 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19151 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19152 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19153 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19154 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19155 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19156 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19157 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19158
19159 /* "neighbor port" commands. */
19160 install_element(BGP_NODE, &neighbor_port_cmd);
19161 install_element(BGP_NODE, &no_neighbor_port_cmd);
19162
19163 /* "neighbor weight" commands. */
19164 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19165 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19166
19167 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19168 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19169 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19170 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19171 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19172 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19173 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19174 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19175 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19176 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19177 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19178 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19179 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19180 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19181 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19182 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19183
19184 /* "neighbor override-capability" commands. */
19185 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19186 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19187
19188 /* "neighbor strict-capability-match" commands. */
19189 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19190 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19191
19192 /* "neighbor timers" commands. */
19193 install_element(BGP_NODE, &neighbor_timers_cmd);
19194 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19195
19196 /* "neighbor timers connect" commands. */
19197 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19198 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19199
19200 /* "neighbor timers delayopen" commands. */
19201 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19202 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19203
19204 /* "neighbor advertisement-interval" commands. */
19205 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19206 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19207
19208 /* "neighbor interface" commands. */
19209 install_element(BGP_NODE, &neighbor_interface_cmd);
19210 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19211
19212 /* "neighbor distribute" commands. */
19213 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19214 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19215 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19216 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19217 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19218 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19219 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19220 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19221 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19222 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19223 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19224 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19225 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19226 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19227 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19228 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19229 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19230 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19231
19232 /* "neighbor prefix-list" commands. */
19233 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19234 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19235 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19236 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19237 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19238 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19239 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19240 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19241 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19242 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19243 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19244 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19245 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19246 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19247 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19248 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19249 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19250 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19251 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19252 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19253 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19254 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19255
19256 /* "neighbor filter-list" commands. */
19257 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19258 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19259 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19260 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19261 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19262 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19263 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19264 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19265 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19266 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19267 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19268 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19269 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19270 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19271 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19272 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19273 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19274 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19275 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19276 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19277 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19278 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19279
19280 /* "neighbor route-map" commands. */
19281 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19282 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19283 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19284 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19285 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19286 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19287 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19288 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19289 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19290 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19291 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19292 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19293 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19294 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19295 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19296 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19297 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19298 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19299 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19300 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19301 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19302 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19303 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19304 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19305
19306 /* "neighbor unsuppress-map" commands. */
19307 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19308 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19309 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19310 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19311 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19312 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19313 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19314 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19315 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19316 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19317 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19318 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19319 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19320 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19321 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19322 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19323 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19324 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19325
19326 /* "neighbor advertise-map" commands. */
19327 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19328 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19329 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19330 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19331 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19332 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19333 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19334 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19335 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19336 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19337
19338 /* neighbor maximum-prefix-out commands. */
19339 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19340 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19341 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19342 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19343 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19344 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19345 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19346 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19347 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19348 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19349 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19350 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19351 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19352 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19353 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19354 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19355 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19356 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19357
19358 /* "neighbor maximum-prefix" commands. */
19359 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19360 install_element(BGP_NODE,
19361 &neighbor_maximum_prefix_threshold_hidden_cmd);
19362 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19363 install_element(BGP_NODE,
19364 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19365 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19366 install_element(BGP_NODE,
19367 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19368 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19369 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19370 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19371 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19372 install_element(BGP_IPV4_NODE,
19373 &neighbor_maximum_prefix_threshold_warning_cmd);
19374 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19375 install_element(BGP_IPV4_NODE,
19376 &neighbor_maximum_prefix_threshold_restart_cmd);
19377 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19378 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19379 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19380 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19381 install_element(BGP_IPV4M_NODE,
19382 &neighbor_maximum_prefix_threshold_warning_cmd);
19383 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19384 install_element(BGP_IPV4M_NODE,
19385 &neighbor_maximum_prefix_threshold_restart_cmd);
19386 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19387 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19388 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19389 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19390 install_element(BGP_IPV4L_NODE,
19391 &neighbor_maximum_prefix_threshold_warning_cmd);
19392 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19393 install_element(BGP_IPV4L_NODE,
19394 &neighbor_maximum_prefix_threshold_restart_cmd);
19395 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19396 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19397 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19398 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19399 install_element(BGP_IPV6_NODE,
19400 &neighbor_maximum_prefix_threshold_warning_cmd);
19401 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19402 install_element(BGP_IPV6_NODE,
19403 &neighbor_maximum_prefix_threshold_restart_cmd);
19404 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19405 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19406 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19407 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19408 install_element(BGP_IPV6M_NODE,
19409 &neighbor_maximum_prefix_threshold_warning_cmd);
19410 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19411 install_element(BGP_IPV6M_NODE,
19412 &neighbor_maximum_prefix_threshold_restart_cmd);
19413 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19414 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19415 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19416 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19417 install_element(BGP_IPV6L_NODE,
19418 &neighbor_maximum_prefix_threshold_warning_cmd);
19419 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19420 install_element(BGP_IPV6L_NODE,
19421 &neighbor_maximum_prefix_threshold_restart_cmd);
19422 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19423 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19424 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19425 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19426 install_element(BGP_VPNV4_NODE,
19427 &neighbor_maximum_prefix_threshold_warning_cmd);
19428 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19429 install_element(BGP_VPNV4_NODE,
19430 &neighbor_maximum_prefix_threshold_restart_cmd);
19431 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19432 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19433 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19434 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19435 install_element(BGP_VPNV6_NODE,
19436 &neighbor_maximum_prefix_threshold_warning_cmd);
19437 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19438 install_element(BGP_VPNV6_NODE,
19439 &neighbor_maximum_prefix_threshold_restart_cmd);
19440 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19441
19442 /* "neighbor allowas-in" */
19443 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19444 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19445 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19446 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19447 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19448 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19449 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19450 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19451 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19452 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19453 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19454 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19455 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19456 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19457 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19458 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19459 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19460 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19461 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19462 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19463
19464 /* "neighbor soo" */
19465 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19466 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19467 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19468 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19469 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19470 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19471 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19472 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19473 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19474 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19475 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19476 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19477 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19478 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19479 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19480 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19481 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19482 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19483
19484 /* address-family commands. */
19485 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19486 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19487 #ifdef KEEP_OLD_VPN_COMMANDS
19488 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19489 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19490 #endif /* KEEP_OLD_VPN_COMMANDS */
19491
19492 install_element(BGP_NODE, &address_family_evpn_cmd);
19493
19494 /* "exit-address-family" command. */
19495 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19496 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19497 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19498 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19499 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19500 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19501 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19502 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19503 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19504 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19505 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19506
19507 /* BGP retain all route-target */
19508 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19509 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19510
19511 /* "clear ip bgp commands" */
19512 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19513
19514 /* clear ip bgp prefix */
19515 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19516 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19517 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19518
19519 /* "show [ip] bgp summary" commands. */
19520 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19521 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19522 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19523 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19524 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19525 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19526 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19527
19528 /* "show [ip] bgp neighbors" commands. */
19529 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19530
19531 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19532
19533 /* "show [ip] bgp peer-group" commands. */
19534 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19535
19536 /* "show [ip] bgp paths" commands. */
19537 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19538
19539 /* "show [ip] bgp community" commands. */
19540 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19541
19542 /* "show ip bgp large-community" commands. */
19543 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19544 /* "show [ip] bgp attribute-info" commands. */
19545 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19546 /* "show [ip] bgp route-leak" command */
19547 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19548
19549 /* "redistribute" commands. */
19550 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19551 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19552 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19553 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19554 install_element(BGP_NODE,
19555 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19556 install_element(BGP_NODE,
19557 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19558 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19559 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19560 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19561 install_element(BGP_NODE,
19562 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19563 install_element(BGP_NODE,
19564 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19565 install_element(BGP_NODE,
19566 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19567 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19568 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19569 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19570 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19571 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19572 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19573 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19574 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19575 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19576 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19577 install_element(BGP_IPV4_NODE,
19578 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19579 install_element(BGP_IPV4_NODE,
19580 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19581 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19582 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19583 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19584 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19585 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19586 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19587
19588 /* import|export vpn [route-map RMAP_NAME] */
19589 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19590 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19591
19592 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19593 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19594
19595 /* ttl_security commands */
19596 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19597 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19598
19599 /* "show [ip] bgp memory" commands. */
19600 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19601
19602 /* "show bgp martian next-hop" */
19603 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19604
19605 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19606
19607 /* "show [ip] bgp views" commands. */
19608 install_element(VIEW_NODE, &show_bgp_views_cmd);
19609
19610 /* "show [ip] bgp vrfs" commands. */
19611 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19612
19613 /* Community-list. */
19614 community_list_vty();
19615
19616 community_alias_vty();
19617
19618 /* vpn-policy commands */
19619 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19620 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19621 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19622 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19623 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19624 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19625 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19626 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19627 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19628 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19629 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19630 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19631
19632 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19633 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19634
19635 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19636 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19637 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19638 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19639 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19640 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19641 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19642 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19643 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19644 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19645
19646 /* tcp-mss command */
19647 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19648 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19649
19650 /* srv6 commands */
19651 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19652 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19653 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19654 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19655 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19656 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19657 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19658
19659 bgp_vty_if_init();
19660 }
19661
19662 #include "memory.h"
19663 #include "bgp_regex.h"
19664 #include "bgp_clist.h"
19665 #include "bgp_ecommunity.h"
19666
19667 /* VTY functions. */
19668
19669 /* Direction value to string conversion. */
19670 static const char *community_direct_str(int direct)
19671 {
19672 switch (direct) {
19673 case COMMUNITY_DENY:
19674 return "deny";
19675 case COMMUNITY_PERMIT:
19676 return "permit";
19677 default:
19678 return "unknown";
19679 }
19680 }
19681
19682 /* Display error string. */
19683 static void community_list_perror(struct vty *vty, int ret)
19684 {
19685 switch (ret) {
19686 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19687 vty_out(vty, "%% Can't find community-list\n");
19688 break;
19689 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19690 vty_out(vty, "%% Malformed community-list value\n");
19691 break;
19692 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19693 vty_out(vty,
19694 "%% Community name conflict, previously defined as standard community\n");
19695 break;
19696 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19697 vty_out(vty,
19698 "%% Community name conflict, previously defined as expanded community\n");
19699 break;
19700 }
19701 }
19702
19703 /* "community-list" keyword help string. */
19704 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19705
19706 /*community-list standard */
19707 DEFUN (community_list_standard,
19708 bgp_community_list_standard_cmd,
19709 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19710 BGP_STR
19711 COMMUNITY_LIST_STR
19712 "Community list number (standard)\n"
19713 "Add an standard community-list entry\n"
19714 "Community list name\n"
19715 "Sequence number of an entry\n"
19716 "Sequence number\n"
19717 "Specify community to reject\n"
19718 "Specify community to accept\n"
19719 COMMUNITY_VAL_STR)
19720 {
19721 char *cl_name_or_number = NULL;
19722 char *seq = NULL;
19723 int direct = 0;
19724 int style = COMMUNITY_LIST_STANDARD;
19725 int idx = 0;
19726
19727 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19728 seq = argv[idx]->arg;
19729
19730 idx = 0;
19731 argv_find(argv, argc, "(1-99)", &idx);
19732 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19733 cl_name_or_number = argv[idx]->arg;
19734 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19735 : COMMUNITY_DENY;
19736 argv_find(argv, argc, "AA:NN", &idx);
19737 char *str = argv_concat(argv, argc, idx);
19738
19739 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19740 direct, style);
19741
19742 XFREE(MTYPE_TMP, str);
19743
19744 if (ret < 0) {
19745 /* Display error string. */
19746 community_list_perror(vty, ret);
19747 return CMD_WARNING_CONFIG_FAILED;
19748 }
19749
19750 return CMD_SUCCESS;
19751 }
19752
19753 DEFUN (no_community_list_standard_all,
19754 no_bgp_community_list_standard_all_cmd,
19755 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19756 NO_STR
19757 BGP_STR
19758 COMMUNITY_LIST_STR
19759 "Community list number (standard)\n"
19760 "Add an standard community-list entry\n"
19761 "Community list name\n"
19762 "Sequence number of an entry\n"
19763 "Sequence number\n"
19764 "Specify community to reject\n"
19765 "Specify community to accept\n"
19766 COMMUNITY_VAL_STR)
19767 {
19768 char *cl_name_or_number = NULL;
19769 char *str = NULL;
19770 int direct = 0;
19771 int style = COMMUNITY_LIST_STANDARD;
19772 char *seq = NULL;
19773 int idx = 0;
19774
19775 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19776 seq = argv[idx]->arg;
19777
19778 idx = 0;
19779 argv_find(argv, argc, "permit", &idx);
19780 argv_find(argv, argc, "deny", &idx);
19781
19782 if (idx) {
19783 direct = argv_find(argv, argc, "permit", &idx)
19784 ? COMMUNITY_PERMIT
19785 : COMMUNITY_DENY;
19786
19787 idx = 0;
19788 argv_find(argv, argc, "AA:NN", &idx);
19789 str = argv_concat(argv, argc, idx);
19790 }
19791
19792 idx = 0;
19793 argv_find(argv, argc, "(1-99)", &idx);
19794 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19795 cl_name_or_number = argv[idx]->arg;
19796
19797 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19798 direct, style);
19799
19800 XFREE(MTYPE_TMP, str);
19801
19802 if (ret < 0) {
19803 community_list_perror(vty, ret);
19804 return CMD_WARNING_CONFIG_FAILED;
19805 }
19806
19807 return CMD_SUCCESS;
19808 }
19809
19810 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19811 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19812 NO_STR BGP_STR COMMUNITY_LIST_STR
19813 "Community list number (standard)\n"
19814 "Add an standard community-list entry\n"
19815 "Community list name\n")
19816
19817 /*community-list expanded */
19818 DEFUN (community_list_expanded_all,
19819 bgp_community_list_expanded_all_cmd,
19820 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19821 BGP_STR
19822 COMMUNITY_LIST_STR
19823 "Community list number (expanded)\n"
19824 "Add an expanded community-list entry\n"
19825 "Community list name\n"
19826 "Sequence number of an entry\n"
19827 "Sequence number\n"
19828 "Specify community to reject\n"
19829 "Specify community to accept\n"
19830 COMMUNITY_VAL_STR)
19831 {
19832 char *cl_name_or_number = NULL;
19833 char *seq = NULL;
19834 int direct = 0;
19835 int style = COMMUNITY_LIST_EXPANDED;
19836 int idx = 0;
19837
19838 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19839 seq = argv[idx]->arg;
19840
19841 idx = 0;
19842
19843 argv_find(argv, argc, "(100-500)", &idx);
19844 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19845 cl_name_or_number = argv[idx]->arg;
19846 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19847 : COMMUNITY_DENY;
19848 argv_find(argv, argc, "AA:NN", &idx);
19849 char *str = argv_concat(argv, argc, idx);
19850
19851 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19852 direct, style);
19853
19854 XFREE(MTYPE_TMP, str);
19855
19856 if (ret < 0) {
19857 /* Display error string. */
19858 community_list_perror(vty, ret);
19859 return CMD_WARNING_CONFIG_FAILED;
19860 }
19861
19862 return CMD_SUCCESS;
19863 }
19864
19865 DEFUN (no_community_list_expanded_all,
19866 no_bgp_community_list_expanded_all_cmd,
19867 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19868 NO_STR
19869 BGP_STR
19870 COMMUNITY_LIST_STR
19871 "Community list number (expanded)\n"
19872 "Add an expanded community-list entry\n"
19873 "Community list name\n"
19874 "Sequence number of an entry\n"
19875 "Sequence number\n"
19876 "Specify community to reject\n"
19877 "Specify community to accept\n"
19878 COMMUNITY_VAL_STR)
19879 {
19880 char *cl_name_or_number = NULL;
19881 char *seq = NULL;
19882 char *str = NULL;
19883 int direct = 0;
19884 int style = COMMUNITY_LIST_EXPANDED;
19885 int idx = 0;
19886
19887 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19888 seq = argv[idx]->arg;
19889
19890 idx = 0;
19891 argv_find(argv, argc, "permit", &idx);
19892 argv_find(argv, argc, "deny", &idx);
19893
19894 if (idx) {
19895 direct = argv_find(argv, argc, "permit", &idx)
19896 ? COMMUNITY_PERMIT
19897 : COMMUNITY_DENY;
19898
19899 idx = 0;
19900 argv_find(argv, argc, "AA:NN", &idx);
19901 str = argv_concat(argv, argc, idx);
19902 }
19903
19904 idx = 0;
19905 argv_find(argv, argc, "(100-500)", &idx);
19906 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19907 cl_name_or_number = argv[idx]->arg;
19908
19909 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19910 direct, style);
19911
19912 XFREE(MTYPE_TMP, str);
19913
19914 if (ret < 0) {
19915 community_list_perror(vty, ret);
19916 return CMD_WARNING_CONFIG_FAILED;
19917 }
19918
19919 return CMD_SUCCESS;
19920 }
19921
19922 ALIAS(no_community_list_expanded_all,
19923 no_bgp_community_list_expanded_all_list_cmd,
19924 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19925 NO_STR BGP_STR COMMUNITY_LIST_STR
19926 "Community list number (expanded)\n"
19927 "Add an expanded community-list entry\n"
19928 "Community list name\n")
19929
19930 /* Return configuration string of community-list entry. */
19931 static const char *community_list_config_str(struct community_entry *entry)
19932 {
19933 const char *str;
19934
19935 if (entry->any)
19936 str = "";
19937 else {
19938 if (entry->style == COMMUNITY_LIST_STANDARD)
19939 str = community_str(entry->u.com, false, false);
19940 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19941 str = lcommunity_str(entry->u.lcom, false, false);
19942 else
19943 str = entry->config;
19944 }
19945 return str;
19946 }
19947
19948 static void community_list_show(struct vty *vty, struct community_list *list)
19949 {
19950 struct community_entry *entry;
19951
19952 for (entry = list->head; entry; entry = entry->next) {
19953 if (entry == list->head) {
19954 if (all_digit(list->name))
19955 vty_out(vty, "Community %s list %s\n",
19956 entry->style == COMMUNITY_LIST_STANDARD
19957 ? "standard"
19958 : "(expanded) access",
19959 list->name);
19960 else
19961 vty_out(vty, "Named Community %s list %s\n",
19962 entry->style == COMMUNITY_LIST_STANDARD
19963 ? "standard"
19964 : "expanded",
19965 list->name);
19966 }
19967 if (entry->any)
19968 vty_out(vty, " %s\n",
19969 community_direct_str(entry->direct));
19970 else
19971 vty_out(vty, " %s %s\n",
19972 community_direct_str(entry->direct),
19973 community_list_config_str(entry));
19974 }
19975 }
19976
19977 DEFUN (show_community_list,
19978 show_bgp_community_list_cmd,
19979 "show bgp community-list",
19980 SHOW_STR
19981 BGP_STR
19982 "List community-list\n")
19983 {
19984 struct community_list *list;
19985 struct community_list_master *cm;
19986
19987 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19988 if (!cm)
19989 return CMD_SUCCESS;
19990
19991 for (list = cm->num.head; list; list = list->next)
19992 community_list_show(vty, list);
19993
19994 for (list = cm->str.head; list; list = list->next)
19995 community_list_show(vty, list);
19996
19997 return CMD_SUCCESS;
19998 }
19999
20000 DEFUN (show_community_list_arg,
20001 show_bgp_community_list_arg_cmd,
20002 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20003 SHOW_STR
20004 BGP_STR
20005 "List community-list\n"
20006 "Community-list number\n"
20007 "Community-list name\n"
20008 "Detailed information on community-list\n")
20009 {
20010 int idx_comm_list = 3;
20011 struct community_list *list;
20012
20013 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20014 COMMUNITY_LIST_MASTER);
20015 if (!list) {
20016 vty_out(vty, "%% Can't find community-list\n");
20017 return CMD_WARNING;
20018 }
20019
20020 community_list_show(vty, list);
20021
20022 return CMD_SUCCESS;
20023 }
20024
20025 /*
20026 * Large Community code.
20027 */
20028 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20029 struct cmd_token **argv, int style,
20030 int reject_all_digit_name)
20031 {
20032 int ret;
20033 int direct;
20034 char *str;
20035 int idx = 0;
20036 char *cl_name;
20037 char *seq = NULL;
20038
20039 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20040 seq = argv[idx]->arg;
20041
20042 idx = 0;
20043 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20044 : COMMUNITY_DENY;
20045
20046 /* All digit name check. */
20047 idx = 0;
20048 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20049 argv_find(argv, argc, "(1-99)", &idx);
20050 argv_find(argv, argc, "(100-500)", &idx);
20051 cl_name = argv[idx]->arg;
20052 if (reject_all_digit_name && all_digit(cl_name)) {
20053 vty_out(vty, "%% Community name cannot have all digits\n");
20054 return CMD_WARNING_CONFIG_FAILED;
20055 }
20056
20057 idx = 0;
20058 argv_find(argv, argc, "AA:BB:CC", &idx);
20059 argv_find(argv, argc, "LINE", &idx);
20060 /* Concat community string argument. */
20061 if (idx)
20062 str = argv_concat(argv, argc, idx);
20063 else
20064 str = NULL;
20065
20066 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20067
20068 /* Free temporary community list string allocated by
20069 argv_concat(). */
20070 XFREE(MTYPE_TMP, str);
20071
20072 if (ret < 0) {
20073 community_list_perror(vty, ret);
20074 return CMD_WARNING_CONFIG_FAILED;
20075 }
20076 return CMD_SUCCESS;
20077 }
20078
20079 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20080 struct cmd_token **argv, int style)
20081 {
20082 int ret;
20083 int direct = 0;
20084 char *str = NULL;
20085 int idx = 0;
20086 char *seq = NULL;
20087
20088 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20089 seq = argv[idx]->arg;
20090
20091 idx = 0;
20092 argv_find(argv, argc, "permit", &idx);
20093 argv_find(argv, argc, "deny", &idx);
20094
20095 if (idx) {
20096 /* Check the list direct. */
20097 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20098 direct = COMMUNITY_PERMIT;
20099 else
20100 direct = COMMUNITY_DENY;
20101
20102 idx = 0;
20103 argv_find(argv, argc, "LINE", &idx);
20104 argv_find(argv, argc, "AA:AA:NN", &idx);
20105 /* Concat community string argument. */
20106 str = argv_concat(argv, argc, idx);
20107 }
20108
20109 idx = 0;
20110 argv_find(argv, argc, "(1-99)", &idx);
20111 argv_find(argv, argc, "(100-500)", &idx);
20112 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20113
20114 /* Unset community list. */
20115 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20116 style);
20117
20118 /* Free temporary community list string allocated by
20119 argv_concat(). */
20120 XFREE(MTYPE_TMP, str);
20121
20122 if (ret < 0) {
20123 community_list_perror(vty, ret);
20124 return CMD_WARNING_CONFIG_FAILED;
20125 }
20126
20127 return CMD_SUCCESS;
20128 }
20129
20130 /* "large-community-list" keyword help string. */
20131 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20132 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20133
20134 DEFUN (lcommunity_list_standard,
20135 bgp_lcommunity_list_standard_cmd,
20136 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20137 BGP_STR
20138 LCOMMUNITY_LIST_STR
20139 "Large Community list number (standard)\n"
20140 "Sequence number of an entry\n"
20141 "Sequence number\n"
20142 "Specify large community to reject\n"
20143 "Specify large community to accept\n"
20144 LCOMMUNITY_VAL_STR)
20145 {
20146 return lcommunity_list_set_vty(vty, argc, argv,
20147 LARGE_COMMUNITY_LIST_STANDARD, 0);
20148 }
20149
20150 DEFUN (lcommunity_list_expanded,
20151 bgp_lcommunity_list_expanded_cmd,
20152 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20153 BGP_STR
20154 LCOMMUNITY_LIST_STR
20155 "Large Community list number (expanded)\n"
20156 "Sequence number of an entry\n"
20157 "Sequence number\n"
20158 "Specify large community to reject\n"
20159 "Specify large community to accept\n"
20160 "An ordered list as a regular-expression\n")
20161 {
20162 return lcommunity_list_set_vty(vty, argc, argv,
20163 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20164 }
20165
20166 DEFUN (lcommunity_list_name_standard,
20167 bgp_lcommunity_list_name_standard_cmd,
20168 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20169 BGP_STR
20170 LCOMMUNITY_LIST_STR
20171 "Specify standard large-community-list\n"
20172 "Large Community list name\n"
20173 "Sequence number of an entry\n"
20174 "Sequence number\n"
20175 "Specify large community to reject\n"
20176 "Specify large community to accept\n"
20177 LCOMMUNITY_VAL_STR)
20178 {
20179 return lcommunity_list_set_vty(vty, argc, argv,
20180 LARGE_COMMUNITY_LIST_STANDARD, 1);
20181 }
20182
20183 DEFUN (lcommunity_list_name_expanded,
20184 bgp_lcommunity_list_name_expanded_cmd,
20185 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20186 BGP_STR
20187 LCOMMUNITY_LIST_STR
20188 "Specify expanded large-community-list\n"
20189 "Large Community list name\n"
20190 "Sequence number of an entry\n"
20191 "Sequence number\n"
20192 "Specify large community to reject\n"
20193 "Specify large community to accept\n"
20194 "An ordered list as a regular-expression\n")
20195 {
20196 return lcommunity_list_set_vty(vty, argc, argv,
20197 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20198 }
20199
20200 DEFUN (no_lcommunity_list_all,
20201 no_bgp_lcommunity_list_all_cmd,
20202 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20203 NO_STR
20204 BGP_STR
20205 LCOMMUNITY_LIST_STR
20206 "Large Community list number (standard)\n"
20207 "Large Community list number (expanded)\n"
20208 "Large Community list name\n")
20209 {
20210 return lcommunity_list_unset_vty(vty, argc, argv,
20211 LARGE_COMMUNITY_LIST_STANDARD);
20212 }
20213
20214 DEFUN (no_lcommunity_list_name_standard_all,
20215 no_bgp_lcommunity_list_name_standard_all_cmd,
20216 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20217 NO_STR
20218 BGP_STR
20219 LCOMMUNITY_LIST_STR
20220 "Specify standard large-community-list\n"
20221 "Large Community list name\n")
20222 {
20223 return lcommunity_list_unset_vty(vty, argc, argv,
20224 LARGE_COMMUNITY_LIST_STANDARD);
20225 }
20226
20227 DEFUN (no_lcommunity_list_name_expanded_all,
20228 no_bgp_lcommunity_list_name_expanded_all_cmd,
20229 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20230 NO_STR
20231 BGP_STR
20232 LCOMMUNITY_LIST_STR
20233 "Specify expanded large-community-list\n"
20234 "Large Community list name\n")
20235 {
20236 return lcommunity_list_unset_vty(vty, argc, argv,
20237 LARGE_COMMUNITY_LIST_EXPANDED);
20238 }
20239
20240 DEFUN (no_lcommunity_list_standard,
20241 no_bgp_lcommunity_list_standard_cmd,
20242 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20243 NO_STR
20244 BGP_STR
20245 LCOMMUNITY_LIST_STR
20246 "Large Community list number (standard)\n"
20247 "Sequence number of an entry\n"
20248 "Sequence number\n"
20249 "Specify large community to reject\n"
20250 "Specify large community to accept\n"
20251 LCOMMUNITY_VAL_STR)
20252 {
20253 return lcommunity_list_unset_vty(vty, argc, argv,
20254 LARGE_COMMUNITY_LIST_STANDARD);
20255 }
20256
20257 DEFUN (no_lcommunity_list_expanded,
20258 no_bgp_lcommunity_list_expanded_cmd,
20259 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20260 NO_STR
20261 BGP_STR
20262 LCOMMUNITY_LIST_STR
20263 "Large Community list number (expanded)\n"
20264 "Sequence number of an entry\n"
20265 "Sequence number\n"
20266 "Specify large community to reject\n"
20267 "Specify large community to accept\n"
20268 "An ordered list as a regular-expression\n")
20269 {
20270 return lcommunity_list_unset_vty(vty, argc, argv,
20271 LARGE_COMMUNITY_LIST_EXPANDED);
20272 }
20273
20274 DEFUN (no_lcommunity_list_name_standard,
20275 no_bgp_lcommunity_list_name_standard_cmd,
20276 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20277 NO_STR
20278 BGP_STR
20279 LCOMMUNITY_LIST_STR
20280 "Specify standard large-community-list\n"
20281 "Large Community list name\n"
20282 "Sequence number of an entry\n"
20283 "Sequence number\n"
20284 "Specify large community to reject\n"
20285 "Specify large community to accept\n"
20286 LCOMMUNITY_VAL_STR)
20287 {
20288 return lcommunity_list_unset_vty(vty, argc, argv,
20289 LARGE_COMMUNITY_LIST_STANDARD);
20290 }
20291
20292 DEFUN (no_lcommunity_list_name_expanded,
20293 no_bgp_lcommunity_list_name_expanded_cmd,
20294 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20295 NO_STR
20296 BGP_STR
20297 LCOMMUNITY_LIST_STR
20298 "Specify expanded large-community-list\n"
20299 "Large community list name\n"
20300 "Sequence number of an entry\n"
20301 "Sequence number\n"
20302 "Specify large community to reject\n"
20303 "Specify large community to accept\n"
20304 "An ordered list as a regular-expression\n")
20305 {
20306 return lcommunity_list_unset_vty(vty, argc, argv,
20307 LARGE_COMMUNITY_LIST_EXPANDED);
20308 }
20309
20310 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20311 {
20312 struct community_entry *entry;
20313
20314 for (entry = list->head; entry; entry = entry->next) {
20315 if (entry == list->head) {
20316 if (all_digit(list->name))
20317 vty_out(vty, "Large community %s list %s\n",
20318 entry->style ==
20319 LARGE_COMMUNITY_LIST_STANDARD
20320 ? "standard"
20321 : "(expanded) access",
20322 list->name);
20323 else
20324 vty_out(vty,
20325 "Named large community %s list %s\n",
20326 entry->style ==
20327 LARGE_COMMUNITY_LIST_STANDARD
20328 ? "standard"
20329 : "expanded",
20330 list->name);
20331 }
20332 if (entry->any)
20333 vty_out(vty, " %s\n",
20334 community_direct_str(entry->direct));
20335 else
20336 vty_out(vty, " %s %s\n",
20337 community_direct_str(entry->direct),
20338 community_list_config_str(entry));
20339 }
20340 }
20341
20342 DEFUN (show_lcommunity_list,
20343 show_bgp_lcommunity_list_cmd,
20344 "show bgp large-community-list",
20345 SHOW_STR
20346 BGP_STR
20347 "List large-community list\n")
20348 {
20349 struct community_list *list;
20350 struct community_list_master *cm;
20351
20352 cm = community_list_master_lookup(bgp_clist,
20353 LARGE_COMMUNITY_LIST_MASTER);
20354 if (!cm)
20355 return CMD_SUCCESS;
20356
20357 for (list = cm->num.head; list; list = list->next)
20358 lcommunity_list_show(vty, list);
20359
20360 for (list = cm->str.head; list; list = list->next)
20361 lcommunity_list_show(vty, list);
20362
20363 return CMD_SUCCESS;
20364 }
20365
20366 DEFUN (show_lcommunity_list_arg,
20367 show_bgp_lcommunity_list_arg_cmd,
20368 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20369 SHOW_STR
20370 BGP_STR
20371 "List large-community list\n"
20372 "Large-community-list number\n"
20373 "Large-community-list name\n"
20374 "Detailed information on large-community-list\n")
20375 {
20376 struct community_list *list;
20377
20378 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20379 LARGE_COMMUNITY_LIST_MASTER);
20380 if (!list) {
20381 vty_out(vty, "%% Can't find large-community-list\n");
20382 return CMD_WARNING;
20383 }
20384
20385 lcommunity_list_show(vty, list);
20386
20387 return CMD_SUCCESS;
20388 }
20389
20390 /* "extcommunity-list" keyword help string. */
20391 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20392 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20393
20394 DEFUN (extcommunity_list_standard,
20395 bgp_extcommunity_list_standard_cmd,
20396 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20397 BGP_STR
20398 EXTCOMMUNITY_LIST_STR
20399 "Extended Community list number (standard)\n"
20400 "Specify standard extcommunity-list\n"
20401 "Community list name\n"
20402 "Sequence number of an entry\n"
20403 "Sequence number\n"
20404 "Specify community to reject\n"
20405 "Specify community to accept\n"
20406 EXTCOMMUNITY_VAL_STR)
20407 {
20408 int style = EXTCOMMUNITY_LIST_STANDARD;
20409 int direct = 0;
20410 char *cl_number_or_name = NULL;
20411 char *seq = NULL;
20412
20413 int idx = 0;
20414
20415 argv_find(argv, argc, "(1-99)", &idx);
20416 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20417 cl_number_or_name = argv[idx]->arg;
20418
20419 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20420 seq = argv[idx]->arg;
20421
20422 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20423 : COMMUNITY_DENY;
20424 argv_find(argv, argc, "AA:NN", &idx);
20425 char *str = argv_concat(argv, argc, idx);
20426
20427 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20428 direct, style);
20429
20430 XFREE(MTYPE_TMP, str);
20431
20432 if (ret < 0) {
20433 community_list_perror(vty, ret);
20434 return CMD_WARNING_CONFIG_FAILED;
20435 }
20436
20437 return CMD_SUCCESS;
20438 }
20439
20440 DEFUN (extcommunity_list_name_expanded,
20441 bgp_extcommunity_list_name_expanded_cmd,
20442 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20443 BGP_STR
20444 EXTCOMMUNITY_LIST_STR
20445 "Extended Community list number (expanded)\n"
20446 "Specify expanded extcommunity-list\n"
20447 "Extended Community list name\n"
20448 "Sequence number of an entry\n"
20449 "Sequence number\n"
20450 "Specify community to reject\n"
20451 "Specify community to accept\n"
20452 "An ordered list as a regular-expression\n")
20453 {
20454 int style = EXTCOMMUNITY_LIST_EXPANDED;
20455 int direct = 0;
20456 char *cl_number_or_name = NULL;
20457 char *seq = NULL;
20458 int idx = 0;
20459
20460 argv_find(argv, argc, "(100-500)", &idx);
20461 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20462 cl_number_or_name = argv[idx]->arg;
20463
20464 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20465 seq = argv[idx]->arg;
20466
20467 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20468 : COMMUNITY_DENY;
20469 argv_find(argv, argc, "LINE", &idx);
20470 char *str = argv_concat(argv, argc, idx);
20471
20472 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20473 direct, style);
20474
20475 XFREE(MTYPE_TMP, str);
20476
20477 if (ret < 0) {
20478 community_list_perror(vty, ret);
20479 return CMD_WARNING_CONFIG_FAILED;
20480 }
20481
20482 return CMD_SUCCESS;
20483 }
20484
20485 DEFUN (no_extcommunity_list_standard_all,
20486 no_bgp_extcommunity_list_standard_all_cmd,
20487 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20488 NO_STR
20489 BGP_STR
20490 EXTCOMMUNITY_LIST_STR
20491 "Extended Community list number (standard)\n"
20492 "Specify standard extcommunity-list\n"
20493 "Community list name\n"
20494 "Sequence number of an entry\n"
20495 "Sequence number\n"
20496 "Specify community to reject\n"
20497 "Specify community to accept\n"
20498 EXTCOMMUNITY_VAL_STR)
20499 {
20500 int style = EXTCOMMUNITY_LIST_STANDARD;
20501 int direct = 0;
20502 char *cl_number_or_name = NULL;
20503 char *str = NULL;
20504 char *seq = NULL;
20505 int idx = 0;
20506
20507 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20508 seq = argv[idx]->arg;
20509
20510 idx = 0;
20511 argv_find(argv, argc, "permit", &idx);
20512 argv_find(argv, argc, "deny", &idx);
20513 if (idx) {
20514 direct = argv_find(argv, argc, "permit", &idx)
20515 ? COMMUNITY_PERMIT
20516 : COMMUNITY_DENY;
20517
20518 idx = 0;
20519 argv_find(argv, argc, "AA:NN", &idx);
20520 str = argv_concat(argv, argc, idx);
20521 }
20522
20523 idx = 0;
20524 argv_find(argv, argc, "(1-99)", &idx);
20525 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20526 cl_number_or_name = argv[idx]->arg;
20527
20528 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20529 seq, direct, style);
20530
20531 XFREE(MTYPE_TMP, str);
20532
20533 if (ret < 0) {
20534 community_list_perror(vty, ret);
20535 return CMD_WARNING_CONFIG_FAILED;
20536 }
20537
20538 return CMD_SUCCESS;
20539 }
20540
20541 ALIAS(no_extcommunity_list_standard_all,
20542 no_bgp_extcommunity_list_standard_all_list_cmd,
20543 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20544 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20545 "Extended Community list number (standard)\n"
20546 "Specify standard extcommunity-list\n"
20547 "Community list name\n")
20548
20549 DEFUN (no_extcommunity_list_expanded_all,
20550 no_bgp_extcommunity_list_expanded_all_cmd,
20551 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20552 NO_STR
20553 BGP_STR
20554 EXTCOMMUNITY_LIST_STR
20555 "Extended Community list number (expanded)\n"
20556 "Specify expanded extcommunity-list\n"
20557 "Extended Community list name\n"
20558 "Sequence number of an entry\n"
20559 "Sequence number\n"
20560 "Specify community to reject\n"
20561 "Specify community to accept\n"
20562 "An ordered list as a regular-expression\n")
20563 {
20564 int style = EXTCOMMUNITY_LIST_EXPANDED;
20565 int direct = 0;
20566 char *cl_number_or_name = NULL;
20567 char *str = NULL;
20568 char *seq = NULL;
20569 int idx = 0;
20570
20571 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20572 seq = argv[idx]->arg;
20573
20574 idx = 0;
20575 argv_find(argv, argc, "permit", &idx);
20576 argv_find(argv, argc, "deny", &idx);
20577
20578 if (idx) {
20579 direct = argv_find(argv, argc, "permit", &idx)
20580 ? COMMUNITY_PERMIT
20581 : COMMUNITY_DENY;
20582
20583 idx = 0;
20584 argv_find(argv, argc, "LINE", &idx);
20585 str = argv_concat(argv, argc, idx);
20586 }
20587
20588 idx = 0;
20589 argv_find(argv, argc, "(100-500)", &idx);
20590 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20591 cl_number_or_name = argv[idx]->arg;
20592
20593 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20594 seq, direct, style);
20595
20596 XFREE(MTYPE_TMP, str);
20597
20598 if (ret < 0) {
20599 community_list_perror(vty, ret);
20600 return CMD_WARNING_CONFIG_FAILED;
20601 }
20602
20603 return CMD_SUCCESS;
20604 }
20605
20606 ALIAS(no_extcommunity_list_expanded_all,
20607 no_bgp_extcommunity_list_expanded_all_list_cmd,
20608 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20609 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20610 "Extended Community list number (expanded)\n"
20611 "Specify expanded extcommunity-list\n"
20612 "Extended Community list name\n")
20613
20614 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20615 {
20616 struct community_entry *entry;
20617
20618 for (entry = list->head; entry; entry = entry->next) {
20619 if (entry == list->head) {
20620 if (all_digit(list->name))
20621 vty_out(vty, "Extended community %s list %s\n",
20622 entry->style == EXTCOMMUNITY_LIST_STANDARD
20623 ? "standard"
20624 : "(expanded) access",
20625 list->name);
20626 else
20627 vty_out(vty,
20628 "Named extended community %s list %s\n",
20629 entry->style == EXTCOMMUNITY_LIST_STANDARD
20630 ? "standard"
20631 : "expanded",
20632 list->name);
20633 }
20634 if (entry->any)
20635 vty_out(vty, " %s\n",
20636 community_direct_str(entry->direct));
20637 else
20638 vty_out(vty, " %s %s\n",
20639 community_direct_str(entry->direct),
20640 community_list_config_str(entry));
20641 }
20642 }
20643
20644 DEFUN (show_extcommunity_list,
20645 show_bgp_extcommunity_list_cmd,
20646 "show bgp extcommunity-list",
20647 SHOW_STR
20648 BGP_STR
20649 "List extended-community list\n")
20650 {
20651 struct community_list *list;
20652 struct community_list_master *cm;
20653
20654 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20655 if (!cm)
20656 return CMD_SUCCESS;
20657
20658 for (list = cm->num.head; list; list = list->next)
20659 extcommunity_list_show(vty, list);
20660
20661 for (list = cm->str.head; list; list = list->next)
20662 extcommunity_list_show(vty, list);
20663
20664 return CMD_SUCCESS;
20665 }
20666
20667 DEFUN (show_extcommunity_list_arg,
20668 show_bgp_extcommunity_list_arg_cmd,
20669 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20670 SHOW_STR
20671 BGP_STR
20672 "List extended-community list\n"
20673 "Extcommunity-list number\n"
20674 "Extcommunity-list name\n"
20675 "Detailed information on extcommunity-list\n")
20676 {
20677 int idx_comm_list = 3;
20678 struct community_list *list;
20679
20680 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20681 EXTCOMMUNITY_LIST_MASTER);
20682 if (!list) {
20683 vty_out(vty, "%% Can't find extcommunity-list\n");
20684 return CMD_WARNING;
20685 }
20686
20687 extcommunity_list_show(vty, list);
20688
20689 return CMD_SUCCESS;
20690 }
20691
20692 /* Display community-list and extcommunity-list configuration. */
20693 static int community_list_config_write(struct vty *vty)
20694 {
20695 struct community_list *list;
20696 struct community_entry *entry;
20697 struct community_list_master *cm;
20698 int write = 0;
20699
20700 /* Community-list. */
20701 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20702
20703 for (list = cm->num.head; list; list = list->next)
20704 for (entry = list->head; entry; entry = entry->next) {
20705 vty_out(vty,
20706 "bgp community-list %s seq %" PRId64 " %s %s\n",
20707 list->name, entry->seq,
20708 community_direct_str(entry->direct),
20709 community_list_config_str(entry));
20710 write++;
20711 }
20712 for (list = cm->str.head; list; list = list->next)
20713 for (entry = list->head; entry; entry = entry->next) {
20714 vty_out(vty,
20715 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20716 entry->style == COMMUNITY_LIST_STANDARD
20717 ? "standard"
20718 : "expanded",
20719 list->name, entry->seq,
20720 community_direct_str(entry->direct),
20721 community_list_config_str(entry));
20722 write++;
20723 }
20724
20725 /* Extcommunity-list. */
20726 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20727
20728 for (list = cm->num.head; list; list = list->next)
20729 for (entry = list->head; entry; entry = entry->next) {
20730 vty_out(vty,
20731 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20732 list->name, entry->seq,
20733 community_direct_str(entry->direct),
20734 community_list_config_str(entry));
20735 write++;
20736 }
20737 for (list = cm->str.head; list; list = list->next)
20738 for (entry = list->head; entry; entry = entry->next) {
20739 vty_out(vty,
20740 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20741 entry->style == EXTCOMMUNITY_LIST_STANDARD
20742 ? "standard"
20743 : "expanded",
20744 list->name, entry->seq,
20745 community_direct_str(entry->direct),
20746 community_list_config_str(entry));
20747 write++;
20748 }
20749
20750
20751 /* lcommunity-list. */
20752 cm = community_list_master_lookup(bgp_clist,
20753 LARGE_COMMUNITY_LIST_MASTER);
20754
20755 for (list = cm->num.head; list; list = list->next)
20756 for (entry = list->head; entry; entry = entry->next) {
20757 vty_out(vty,
20758 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20759 list->name, entry->seq,
20760 community_direct_str(entry->direct),
20761 community_list_config_str(entry));
20762 write++;
20763 }
20764 for (list = cm->str.head; list; list = list->next)
20765 for (entry = list->head; entry; entry = entry->next) {
20766 vty_out(vty,
20767 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20768
20769 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20770 ? "standard"
20771 : "expanded",
20772 list->name, entry->seq, community_direct_str(entry->direct),
20773 community_list_config_str(entry));
20774 write++;
20775 }
20776
20777 return write;
20778 }
20779
20780 static int community_list_config_write(struct vty *vty);
20781 static struct cmd_node community_list_node = {
20782 .name = "community list",
20783 .node = COMMUNITY_LIST_NODE,
20784 .prompt = "",
20785 .config_write = community_list_config_write,
20786 };
20787
20788 static void community_list_vty(void)
20789 {
20790 install_node(&community_list_node);
20791
20792 /* Community-list. */
20793 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20794 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20795 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20796 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20797 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20798 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20799 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20800 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20801
20802 /* Extcommunity-list. */
20803 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20804 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20805 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20806 install_element(CONFIG_NODE,
20807 &no_bgp_extcommunity_list_standard_all_list_cmd);
20808 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20809 install_element(CONFIG_NODE,
20810 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20811 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20812 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20813
20814 /* Large Community List */
20815 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20816 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20817 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20818 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20819 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20820 install_element(CONFIG_NODE,
20821 &no_bgp_lcommunity_list_name_standard_all_cmd);
20822 install_element(CONFIG_NODE,
20823 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20824 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20825 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20826 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20827 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20828 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20829 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20830
20831 bgp_community_list_command_completion_setup();
20832 }
20833
20834 static struct cmd_node community_alias_node = {
20835 .name = "community alias",
20836 .node = COMMUNITY_ALIAS_NODE,
20837 .prompt = "",
20838 .config_write = bgp_community_alias_write,
20839 };
20840
20841 void community_alias_vty(void)
20842 {
20843 install_node(&community_alias_node);
20844
20845 /* Community-list. */
20846 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20847
20848 bgp_community_alias_command_completion_setup();
20849 }