]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Don't check for NULL when removing SRv6 SIDs
[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
302 /* release chunk notification via ZAPI */
303 ret = bgp_zebra_srv6_manager_release_locator_chunk(
304 bgp->srv6_locator_name);
305 if (ret < 0)
306 return -1;
307
308 /* refresh chunks */
309 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
310 listnode_delete(bgp->srv6_locator_chunks, chunk);
311 srv6_locator_chunk_free(chunk);
312 }
313
314 /* refresh functions */
315 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
316 listnode_delete(bgp->srv6_functions, func);
317 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
318 }
319
320 /* refresh tovpn_sid */
321 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
322 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
323 continue;
324
325 /* refresh vpnv4 tovpn_sid */
326 XFREE(MTYPE_BGP_SRV6_SID,
327 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
328
329 /* refresh vpnv6 tovpn_sid */
330 XFREE(MTYPE_BGP_SRV6_SID,
331 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
332 }
333
334 /* update vpn bgp processes */
335 vpn_leak_postchange_all();
336
337 /* refresh tovpn_sid_locator */
338 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
339 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
340 continue;
341
342 /* refresh vpnv4 tovpn_sid_locator */
343 XFREE(MTYPE_BGP_SRV6_SID,
344 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
345
346 /* refresh vpnv6 tovpn_sid_locator */
347 XFREE(MTYPE_BGP_SRV6_SID,
348 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
349 }
350
351 /* clear locator name */
352 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
353
354 return 0;
355 }
356
357 /* Utility function to get address family from current node. */
358 afi_t bgp_node_afi(struct vty *vty)
359 {
360 afi_t afi;
361 switch (vty->node) {
362 case BGP_IPV6_NODE:
363 case BGP_IPV6M_NODE:
364 case BGP_IPV6L_NODE:
365 case BGP_VPNV6_NODE:
366 case BGP_FLOWSPECV6_NODE:
367 afi = AFI_IP6;
368 break;
369 case BGP_EVPN_NODE:
370 afi = AFI_L2VPN;
371 break;
372 default:
373 afi = AFI_IP;
374 break;
375 }
376 return afi;
377 }
378
379 /* Utility function to get subsequent address family from current
380 node. */
381 safi_t bgp_node_safi(struct vty *vty)
382 {
383 safi_t safi;
384 switch (vty->node) {
385 case BGP_VPNV4_NODE:
386 case BGP_VPNV6_NODE:
387 safi = SAFI_MPLS_VPN;
388 break;
389 case BGP_IPV4M_NODE:
390 case BGP_IPV6M_NODE:
391 safi = SAFI_MULTICAST;
392 break;
393 case BGP_EVPN_NODE:
394 safi = SAFI_EVPN;
395 break;
396 case BGP_IPV4L_NODE:
397 case BGP_IPV6L_NODE:
398 safi = SAFI_LABELED_UNICAST;
399 break;
400 case BGP_FLOWSPECV4_NODE:
401 case BGP_FLOWSPECV6_NODE:
402 safi = SAFI_FLOWSPEC;
403 break;
404 default:
405 safi = SAFI_UNICAST;
406 break;
407 }
408 return safi;
409 }
410
411 /**
412 * Converts an AFI in string form to afi_t
413 *
414 * @param afi string, one of
415 * - "ipv4"
416 * - "ipv6"
417 * - "l2vpn"
418 * @return the corresponding afi_t
419 */
420 afi_t bgp_vty_afi_from_str(const char *afi_str)
421 {
422 afi_t afi = AFI_MAX; /* unknown */
423 if (strmatch(afi_str, "ipv4"))
424 afi = AFI_IP;
425 else if (strmatch(afi_str, "ipv6"))
426 afi = AFI_IP6;
427 else if (strmatch(afi_str, "l2vpn"))
428 afi = AFI_L2VPN;
429 return afi;
430 }
431
432 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
433 afi_t *afi)
434 {
435 int ret = 0;
436 if (argv_find(argv, argc, "ipv4", index)) {
437 ret = 1;
438 if (afi)
439 *afi = AFI_IP;
440 } else if (argv_find(argv, argc, "ipv6", index)) {
441 ret = 1;
442 if (afi)
443 *afi = AFI_IP6;
444 } else if (argv_find(argv, argc, "l2vpn", index)) {
445 ret = 1;
446 if (afi)
447 *afi = AFI_L2VPN;
448 }
449 return ret;
450 }
451
452 /* supports <unicast|multicast|vpn|labeled-unicast> */
453 safi_t bgp_vty_safi_from_str(const char *safi_str)
454 {
455 safi_t safi = SAFI_MAX; /* unknown */
456 if (strmatch(safi_str, "multicast"))
457 safi = SAFI_MULTICAST;
458 else if (strmatch(safi_str, "unicast"))
459 safi = SAFI_UNICAST;
460 else if (strmatch(safi_str, "vpn"))
461 safi = SAFI_MPLS_VPN;
462 else if (strmatch(safi_str, "evpn"))
463 safi = SAFI_EVPN;
464 else if (strmatch(safi_str, "labeled-unicast"))
465 safi = SAFI_LABELED_UNICAST;
466 else if (strmatch(safi_str, "flowspec"))
467 safi = SAFI_FLOWSPEC;
468 return safi;
469 }
470
471 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
472 safi_t *safi)
473 {
474 int ret = 0;
475 if (argv_find(argv, argc, "unicast", index)) {
476 ret = 1;
477 if (safi)
478 *safi = SAFI_UNICAST;
479 } else if (argv_find(argv, argc, "multicast", index)) {
480 ret = 1;
481 if (safi)
482 *safi = SAFI_MULTICAST;
483 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
484 ret = 1;
485 if (safi)
486 *safi = SAFI_LABELED_UNICAST;
487 } else if (argv_find(argv, argc, "vpn", index)) {
488 ret = 1;
489 if (safi)
490 *safi = SAFI_MPLS_VPN;
491 } else if (argv_find(argv, argc, "evpn", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_EVPN;
495 } else if (argv_find(argv, argc, "flowspec", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_FLOWSPEC;
499 }
500 return ret;
501 }
502
503 /*
504 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
505 *
506 * afi
507 * address-family identifier
508 *
509 * safi
510 * subsequent address-family identifier
511 *
512 * Returns:
513 * default_af string corresponding to the supplied afi/safi pair.
514 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
515 * return -1.
516 */
517 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
518 {
519 switch (afi) {
520 case AFI_IP:
521 switch (safi) {
522 case SAFI_UNICAST:
523 return "ipv4-unicast";
524 case SAFI_MULTICAST:
525 return "ipv4-multicast";
526 case SAFI_MPLS_VPN:
527 return "ipv4-vpn";
528 case SAFI_ENCAP:
529 return "ipv4-encap";
530 case SAFI_LABELED_UNICAST:
531 return "ipv4-labeled-unicast";
532 case SAFI_FLOWSPEC:
533 return "ipv4-flowspec";
534 default:
535 return "unknown-afi/safi";
536 }
537 break;
538 case AFI_IP6:
539 switch (safi) {
540 case SAFI_UNICAST:
541 return "ipv6-unicast";
542 case SAFI_MULTICAST:
543 return "ipv6-multicast";
544 case SAFI_MPLS_VPN:
545 return "ipv6-vpn";
546 case SAFI_ENCAP:
547 return "ipv6-encap";
548 case SAFI_LABELED_UNICAST:
549 return "ipv6-labeled-unicast";
550 case SAFI_FLOWSPEC:
551 return "ipv6-flowspec";
552 default:
553 return "unknown-afi/safi";
554 }
555 break;
556 case AFI_L2VPN:
557 switch (safi) {
558 case SAFI_EVPN:
559 return "l2vpn-evpn";
560 default:
561 return "unknown-afi/safi";
562 }
563 case AFI_UNSPEC:
564 case AFI_MAX:
565 return "unknown-afi/safi";
566 }
567 /* all AFIs are accounted for above, so this shouldn't happen */
568 return "unknown-afi/safi";
569 }
570
571 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
572 enum bgp_instance_type inst_type)
573 {
574 int ret = bgp_get(bgp, as, name, inst_type);
575
576 if (ret == BGP_CREATED) {
577 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
578 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
579
580 if (DFLT_BGP_IMPORT_CHECK)
581 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
582 if (DFLT_BGP_SHOW_HOSTNAME)
583 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
584 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
585 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
586 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
587 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
588 if (DFLT_BGP_DETERMINISTIC_MED)
589 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
590 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
592 if (DFLT_BGP_SUPPRESS_DUPLICATES)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
594 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
596 if (DFLT_BGP_HARD_ADMIN_RESET)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
598
599 ret = BGP_SUCCESS;
600 }
601 return ret;
602 }
603
604 /*
605 * bgp_vty_find_and_parse_afi_safi_bgp
606 *
607 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
608 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
609 * to appropriate values for the calling function. This is to allow the
610 * calling function to make decisions appropriate for the show command
611 * that is being parsed.
612 *
613 * The show commands are generally of the form:
614 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
615 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
616 *
617 * Since we use argv_find if the show command in particular doesn't have:
618 * [ip]
619 * [<view|vrf> VIEWVRFNAME]
620 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
621 * The command parsing should still be ok.
622 *
623 * vty -> The vty for the command so we can output some useful data in
624 * the event of a parse error in the vrf.
625 * argv -> The command tokens
626 * argc -> How many command tokens we have
627 * idx -> The current place in the command, generally should be 0 for this
628 * function
629 * afi -> The parsed afi if it was included in the show command, returned here
630 * safi -> The parsed safi if it was included in the show command, returned here
631 * bgp -> Pointer to the bgp data structure we need to fill in.
632 * use_json -> json is configured or not
633 *
634 * The function returns the correct location in the parse tree for the
635 * last token found.
636 *
637 * Returns 0 for failure to parse correctly, else the idx position of where
638 * it found the last token.
639 */
640 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
641 struct cmd_token **argv, int argc,
642 int *idx, afi_t *afi, safi_t *safi,
643 struct bgp **bgp, bool use_json)
644 {
645 char *vrf_name = NULL;
646
647 assert(afi);
648 assert(safi);
649 assert(bgp);
650
651 if (argv_find(argv, argc, "ip", idx))
652 *afi = AFI_IP;
653
654 if (argv_find(argv, argc, "view", idx))
655 vrf_name = argv[*idx + 1]->arg;
656 else if (argv_find(argv, argc, "vrf", idx)) {
657 vrf_name = argv[*idx + 1]->arg;
658 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
659 vrf_name = NULL;
660 }
661 if (vrf_name) {
662 if (strmatch(vrf_name, "all"))
663 *bgp = NULL;
664 else {
665 *bgp = bgp_lookup_by_name(vrf_name);
666 if (!*bgp) {
667 if (use_json) {
668 json_object *json = NULL;
669 json = json_object_new_object();
670 json_object_string_add(
671 json, "warning",
672 "View/Vrf is unknown");
673 vty_json(vty, json);
674 }
675 else
676 vty_out(vty, "View/Vrf %s is unknown\n",
677 vrf_name);
678 *idx = 0;
679 return 0;
680 }
681 }
682 } else {
683 *bgp = bgp_get_default();
684 if (!*bgp) {
685 if (use_json) {
686 json_object *json = NULL;
687 json = json_object_new_object();
688 json_object_string_add(
689 json, "warning",
690 "Default BGP instance not found");
691 vty_json(vty, json);
692 }
693 else
694 vty_out(vty,
695 "Default BGP instance not found\n");
696 *idx = 0;
697 return 0;
698 }
699 }
700
701 if (argv_find_and_parse_afi(argv, argc, idx, afi))
702 argv_find_and_parse_safi(argv, argc, idx, safi);
703
704 *idx += 1;
705 return *idx;
706 }
707
708 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
709 {
710 struct interface *ifp = NULL;
711 struct listnode *node;
712 struct bgp_listener *listener;
713 union sockunion all_su;
714
715 if (su->sa.sa_family == AF_INET) {
716 (void)str2sockunion("0.0.0.0", &all_su);
717 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
718 } else if (su->sa.sa_family == AF_INET6) {
719 (void)str2sockunion("::", &all_su);
720 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
721 su->sin6.sin6_scope_id,
722 bgp->vrf_id);
723 }
724
725 if (ifp) {
726 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
727 if (sockunion_family(su) !=
728 sockunion_family(&listener->su))
729 continue;
730
731 /* If 0.0.0.0/:: is a listener, then treat as self and
732 * reject.
733 */
734 if (!sockunion_cmp(&listener->su, su) ||
735 !sockunion_cmp(&listener->su, &all_su))
736 return true;
737 }
738 }
739
740 return false;
741 }
742
743 /* Utility function for looking up peer from VTY. */
744 /* This is used only for configuration, so disallow if attempted on
745 * a dynamic neighbor.
746 */
747 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
748 {
749 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
750 int ret;
751 union sockunion su;
752 struct peer *peer;
753
754 if (!bgp) {
755 return NULL;
756 }
757
758 ret = str2sockunion(ip_str, &su);
759 if (ret < 0) {
760 peer = peer_lookup_by_conf_if(bgp, ip_str);
761 if (!peer) {
762 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
763 == NULL) {
764 vty_out(vty,
765 "%% Malformed address or name: %s\n",
766 ip_str);
767 return NULL;
768 }
769 }
770 } else {
771 peer = peer_lookup(bgp, &su);
772 if (!peer) {
773 vty_out(vty,
774 "%% Specify remote-as or peer-group commands first\n");
775 return NULL;
776 }
777 if (peer_dynamic_neighbor(peer)) {
778 vty_out(vty,
779 "%% Operation not allowed on a dynamic neighbor\n");
780 return NULL;
781 }
782 }
783 return peer;
784 }
785
786 /* Utility function for looking up peer or peer group. */
787 /* This is used only for configuration, so disallow if attempted on
788 * a dynamic neighbor.
789 */
790 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
791 {
792 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
793 int ret;
794 union sockunion su;
795 struct peer *peer = NULL;
796 struct peer_group *group = NULL;
797
798 if (!bgp) {
799 return NULL;
800 }
801
802 ret = str2sockunion(peer_str, &su);
803 if (ret == 0) {
804 /* IP address, locate peer. */
805 peer = peer_lookup(bgp, &su);
806 } else {
807 /* Not IP, could match either peer configured on interface or a
808 * group. */
809 peer = peer_lookup_by_conf_if(bgp, peer_str);
810 if (!peer)
811 group = peer_group_lookup(bgp, peer_str);
812 }
813
814 if (peer) {
815 if (peer_dynamic_neighbor(peer)) {
816 vty_out(vty,
817 "%% Operation not allowed on a dynamic neighbor\n");
818 return NULL;
819 }
820
821 return peer;
822 }
823
824 if (group)
825 return group->conf;
826
827 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
828
829 return NULL;
830 }
831
832 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
833 {
834 const char *str = NULL;
835
836 switch (ret) {
837 case BGP_SUCCESS:
838 case BGP_CREATED:
839 case BGP_GR_NO_OPERATION:
840 break;
841 case BGP_ERR_INVALID_VALUE:
842 str = "Invalid value";
843 break;
844 case BGP_ERR_INVALID_FLAG:
845 str = "Invalid flag";
846 break;
847 case BGP_ERR_PEER_GROUP_SHUTDOWN:
848 str = "Peer-group has been shutdown. Activate the peer-group first";
849 break;
850 case BGP_ERR_PEER_FLAG_CONFLICT:
851 str = "Can't set override-capability and strict-capability-match at the same time";
852 break;
853 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
854 str = "Specify remote-as or peer-group remote AS first";
855 break;
856 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
857 str = "Cannot change the peer-group. Deconfigure first";
858 break;
859 case BGP_ERR_PEER_GROUP_MISMATCH:
860 str = "Peer is not a member of this peer-group";
861 break;
862 case BGP_ERR_PEER_FILTER_CONFLICT:
863 str = "Prefix/distribute list can not co-exist";
864 break;
865 case BGP_ERR_NOT_INTERNAL_PEER:
866 str = "Invalid command. Not an internal neighbor";
867 break;
868 case BGP_ERR_REMOVE_PRIVATE_AS:
869 str = "remove-private-AS cannot be configured for IBGP peers";
870 break;
871 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
872 str = "Cannot have local-as same as BGP AS number";
873 break;
874 case BGP_ERR_TCPSIG_FAILED:
875 str = "Error while applying TCP-Sig to session(s)";
876 break;
877 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
878 str = "ebgp-multihop and ttl-security cannot be configured together";
879 break;
880 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
881 str = "ttl-security only allowed for EBGP peers";
882 break;
883 case BGP_ERR_AS_OVERRIDE:
884 str = "as-override cannot be configured for IBGP peers";
885 break;
886 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
887 str = "Invalid limit for number of dynamic neighbors";
888 break;
889 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
890 str = "Dynamic neighbor listen range already exists";
891 break;
892 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
893 str = "Operation not allowed on a dynamic neighbor";
894 break;
895 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
896 str = "Operation not allowed on a directly connected neighbor";
897 break;
898 case BGP_ERR_PEER_SAFI_CONFLICT:
899 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
900 break;
901 case BGP_ERR_GR_INVALID_CMD:
902 str = "The Graceful Restart command used is not valid at this moment.";
903 break;
904 case BGP_ERR_GR_OPERATION_FAILED:
905 str = "The Graceful Restart Operation failed due to an err.";
906 break;
907 case BGP_ERR_PEER_GROUP_MEMBER:
908 str = "Peer-group member cannot override remote-as of peer-group.";
909 break;
910 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
911 str = "Peer-group members must be all internal or all external.";
912 break;
913 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
914 str = "Range specified cannot be deleted because it is not part of current config.";
915 break;
916 case BGP_ERR_INSTANCE_MISMATCH:
917 str = "Instance specified does not match the current instance.";
918 break;
919 case BGP_ERR_NO_INTERFACE_CONFIG:
920 str = "Interface specified is not being used for interface based peer.";
921 break;
922 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
923 str = "No configuration already specified for soft reconfiguration.";
924 break;
925 case BGP_ERR_AS_MISMATCH:
926 str = "BGP is already running.";
927 break;
928 case BGP_ERR_AF_UNCONFIGURED:
929 str = "AFI/SAFI specified is not currently configured.";
930 break;
931 case BGP_ERR_INVALID_AS:
932 str = "Confederation AS specified is the same AS as our AS.";
933 break;
934 case BGP_ERR_INVALID_ROLE_NAME:
935 str = "Invalid role name";
936 break;
937 case BGP_ERR_INVALID_INTERNAL_ROLE:
938 str = "External roles can be set only on eBGP session";
939 break;
940 }
941 if (str) {
942 vty_out(vty, "%% %s\n", str);
943 return CMD_WARNING_CONFIG_FAILED;
944 }
945 return CMD_SUCCESS;
946 }
947
948 /* BGP clear sort. */
949 enum clear_sort {
950 clear_all,
951 clear_peer,
952 clear_group,
953 clear_external,
954 clear_as
955 };
956
957 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
958 safi_t safi, int error)
959 {
960 switch (error) {
961 case BGP_ERR_AF_UNCONFIGURED:
962 if (vty)
963 vty_out(vty,
964 "%% BGP: Enable %s address family for the neighbor %s\n",
965 get_afi_safi_str(afi, safi, false), peer->host);
966 else
967 zlog_warn(
968 "%% BGP: Enable %s address family for the neighbor %s",
969 get_afi_safi_str(afi, safi, false), peer->host);
970 break;
971 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
972 if (vty)
973 vty_out(vty,
974 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
975 peer->host);
976 else
977 zlog_warn(
978 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
979 peer->host);
980 break;
981 default:
982 break;
983 }
984 }
985
986 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
987 struct listnode **nnode, enum bgp_clear_type stype)
988 {
989 int ret = 0;
990 struct peer_af *paf;
991
992 /* if afi/.safi not specified, spin thru all of them */
993 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
994 afi_t tmp_afi;
995 safi_t tmp_safi;
996 enum bgp_af_index index;
997
998 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
999 paf = peer->peer_af_array[index];
1000 if (!paf)
1001 continue;
1002
1003 if (paf && paf->subgroup)
1004 SET_FLAG(paf->subgroup->sflags,
1005 SUBGRP_STATUS_FORCE_UPDATES);
1006
1007 tmp_afi = paf->afi;
1008 tmp_safi = paf->safi;
1009 if (!peer->afc[tmp_afi][tmp_safi])
1010 continue;
1011
1012 if (stype == BGP_CLEAR_SOFT_NONE)
1013 ret = peer_clear(peer, nnode);
1014 else
1015 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1016 stype);
1017 }
1018 /* if afi specified and safi not, spin thru safis on this afi */
1019 } else if (safi == SAFI_UNSPEC) {
1020 safi_t tmp_safi;
1021
1022 for (tmp_safi = SAFI_UNICAST;
1023 tmp_safi < SAFI_MAX; tmp_safi++) {
1024 if (!peer->afc[afi][tmp_safi])
1025 continue;
1026
1027 paf = peer_af_find(peer, afi, tmp_safi);
1028 if (paf && paf->subgroup)
1029 SET_FLAG(paf->subgroup->sflags,
1030 SUBGRP_STATUS_FORCE_UPDATES);
1031
1032 if (stype == BGP_CLEAR_SOFT_NONE)
1033 ret = peer_clear(peer, nnode);
1034 else
1035 ret = peer_clear_soft(peer, afi,
1036 tmp_safi, stype);
1037 }
1038 /* both afi/safi specified, let the caller know if not defined */
1039 } else {
1040 if (!peer->afc[afi][safi])
1041 return 1;
1042
1043 paf = peer_af_find(peer, afi, safi);
1044 if (paf && paf->subgroup)
1045 SET_FLAG(paf->subgroup->sflags,
1046 SUBGRP_STATUS_FORCE_UPDATES);
1047
1048 if (stype == BGP_CLEAR_SOFT_NONE)
1049 ret = peer_clear(peer, nnode);
1050 else
1051 ret = peer_clear_soft(peer, afi, safi, stype);
1052 }
1053
1054 return ret;
1055 }
1056
1057 /* `clear ip bgp' functions. */
1058 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1059 enum clear_sort sort, enum bgp_clear_type stype,
1060 const char *arg)
1061 {
1062 int ret = 0;
1063 bool found = false;
1064 struct peer *peer;
1065
1066 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1067
1068 /* Clear all neighbors. */
1069 /*
1070 * Pass along pointer to next node to peer_clear() when walking all
1071 * nodes on the BGP instance as that may get freed if it is a
1072 * doppelganger
1073 */
1074 if (sort == clear_all) {
1075 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1076
1077 bgp_peer_gr_flags_update(peer);
1078
1079 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1080 gr_router_detected = true;
1081
1082 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1083 stype);
1084
1085 if (ret < 0)
1086 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1087 }
1088
1089 if (gr_router_detected
1090 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1091 bgp_zebra_send_capabilities(bgp, false);
1092 } else if (!gr_router_detected
1093 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1094 bgp_zebra_send_capabilities(bgp, true);
1095 }
1096
1097 /* This is to apply read-only mode on this clear. */
1098 if (stype == BGP_CLEAR_SOFT_NONE)
1099 bgp->update_delay_over = 0;
1100
1101 return CMD_SUCCESS;
1102 }
1103
1104 /* Clear specified neighbor. */
1105 if (sort == clear_peer) {
1106 union sockunion su;
1107
1108 /* Make sockunion for lookup. */
1109 ret = str2sockunion(arg, &su);
1110 if (ret < 0) {
1111 peer = peer_lookup_by_conf_if(bgp, arg);
1112 if (!peer) {
1113 peer = peer_lookup_by_hostname(bgp, arg);
1114 if (!peer) {
1115 vty_out(vty,
1116 "Malformed address or name: %s\n",
1117 arg);
1118 return CMD_WARNING;
1119 }
1120 }
1121 } else {
1122 peer = peer_lookup(bgp, &su);
1123 if (!peer) {
1124 vty_out(vty,
1125 "%% BGP: Unknown neighbor - \"%s\"\n",
1126 arg);
1127 return CMD_WARNING;
1128 }
1129 }
1130
1131 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1132 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1133
1134 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1135
1136 /* if afi/safi not defined for this peer, let caller know */
1137 if (ret == 1)
1138 ret = BGP_ERR_AF_UNCONFIGURED;
1139
1140 if (ret < 0)
1141 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1142
1143 return CMD_SUCCESS;
1144 }
1145
1146 /* Clear all neighbors belonging to a specific peer-group. */
1147 if (sort == clear_group) {
1148 struct peer_group *group;
1149
1150 group = peer_group_lookup(bgp, arg);
1151 if (!group) {
1152 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1153 return CMD_WARNING;
1154 }
1155
1156 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1157 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1158
1159 if (ret < 0)
1160 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1161 else
1162 found = true;
1163 }
1164
1165 if (!found)
1166 vty_out(vty,
1167 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1168 get_afi_safi_str(afi, safi, false), arg);
1169
1170 return CMD_SUCCESS;
1171 }
1172
1173 /* Clear all external (eBGP) neighbors. */
1174 if (sort == clear_external) {
1175 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1176 if (peer->sort == BGP_PEER_IBGP)
1177 continue;
1178
1179 bgp_peer_gr_flags_update(peer);
1180
1181 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1182 gr_router_detected = true;
1183
1184 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1185
1186 if (ret < 0)
1187 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1188 else
1189 found = true;
1190 }
1191
1192 if (gr_router_detected
1193 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1194 bgp_zebra_send_capabilities(bgp, false);
1195 } else if (!gr_router_detected
1196 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1197 bgp_zebra_send_capabilities(bgp, true);
1198 }
1199
1200 if (!found)
1201 vty_out(vty,
1202 "%% BGP: No external %s peer is configured\n",
1203 get_afi_safi_str(afi, safi, false));
1204
1205 return CMD_SUCCESS;
1206 }
1207
1208 /* Clear all neighbors belonging to a specific AS. */
1209 if (sort == clear_as) {
1210 as_t as = strtoul(arg, NULL, 10);
1211
1212 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1213 if (peer->as != as)
1214 continue;
1215
1216 bgp_peer_gr_flags_update(peer);
1217
1218 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1219 gr_router_detected = true;
1220
1221 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1222
1223 if (ret < 0)
1224 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1225 else
1226 found = true;
1227 }
1228
1229 if (gr_router_detected
1230 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1231 bgp_zebra_send_capabilities(bgp, false);
1232 } else if (!gr_router_detected
1233 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1234 bgp_zebra_send_capabilities(bgp, true);
1235 }
1236
1237 if (!found)
1238 vty_out(vty,
1239 "%% BGP: No %s peer is configured with AS %s\n",
1240 get_afi_safi_str(afi, safi, false), arg);
1241
1242 return CMD_SUCCESS;
1243 }
1244
1245 return CMD_SUCCESS;
1246 }
1247
1248 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1249 safi_t safi, enum clear_sort sort,
1250 enum bgp_clear_type stype, const char *arg)
1251 {
1252 struct bgp *bgp;
1253
1254 /* BGP structure lookup. */
1255 if (name) {
1256 bgp = bgp_lookup_by_name(name);
1257 if (bgp == NULL) {
1258 vty_out(vty, "Can't find BGP instance %s\n", name);
1259 return CMD_WARNING;
1260 }
1261 } else {
1262 bgp = bgp_get_default();
1263 if (bgp == NULL) {
1264 vty_out(vty, "No BGP process is configured\n");
1265 return CMD_WARNING;
1266 }
1267 }
1268
1269 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1270 }
1271
1272 /* clear soft inbound */
1273 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1274 {
1275 afi_t afi;
1276 safi_t safi;
1277
1278 FOREACH_AFI_SAFI (afi, safi)
1279 bgp_clear_vty(vty, name, afi, safi, clear_all,
1280 BGP_CLEAR_SOFT_IN, NULL);
1281 }
1282
1283 /* clear soft outbound */
1284 static void bgp_clear_star_soft_out(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_OUT, NULL);
1292 }
1293
1294
1295 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1296 {
1297 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1298 }
1299
1300 #ifndef VTYSH_EXTRACT_PL
1301 #include "bgpd/bgp_vty_clippy.c"
1302 #endif
1303
1304 DEFUN_HIDDEN (bgp_local_mac,
1305 bgp_local_mac_cmd,
1306 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1307 BGP_STR
1308 "Local MAC config\n"
1309 "VxLAN Network Identifier\n"
1310 "VNI number\n"
1311 "local mac\n"
1312 "mac address\n"
1313 "mac-mobility sequence\n"
1314 "seq number\n")
1315 {
1316 int rv;
1317 vni_t vni;
1318 struct ethaddr mac;
1319 struct ipaddr ip;
1320 uint32_t seq;
1321 struct bgp *bgp;
1322
1323 vni = strtoul(argv[3]->arg, NULL, 10);
1324 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1325 vty_out(vty, "%% Malformed MAC address\n");
1326 return CMD_WARNING;
1327 }
1328 memset(&ip, 0, sizeof(ip));
1329 seq = strtoul(argv[7]->arg, NULL, 10);
1330
1331 bgp = bgp_get_default();
1332 if (!bgp) {
1333 vty_out(vty, "Default BGP instance is not there\n");
1334 return CMD_WARNING;
1335 }
1336
1337 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1338 zero_esi);
1339 if (rv < 0) {
1340 vty_out(vty, "Internal error\n");
1341 return CMD_WARNING;
1342 }
1343
1344 return CMD_SUCCESS;
1345 }
1346
1347 DEFUN_HIDDEN (no_bgp_local_mac,
1348 no_bgp_local_mac_cmd,
1349 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1350 NO_STR
1351 BGP_STR
1352 "Local MAC config\n"
1353 "VxLAN Network Identifier\n"
1354 "VNI number\n"
1355 "local mac\n"
1356 "mac address\n")
1357 {
1358 int rv;
1359 vni_t vni;
1360 struct ethaddr mac;
1361 struct ipaddr ip;
1362 struct bgp *bgp;
1363
1364 vni = strtoul(argv[4]->arg, NULL, 10);
1365 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1366 vty_out(vty, "%% Malformed MAC address\n");
1367 return CMD_WARNING;
1368 }
1369 memset(&ip, 0, sizeof(ip));
1370
1371 bgp = bgp_get_default();
1372 if (!bgp) {
1373 vty_out(vty, "Default BGP instance is not there\n");
1374 return CMD_WARNING;
1375 }
1376
1377 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1378 if (rv < 0) {
1379 vty_out(vty, "Internal error\n");
1380 return CMD_WARNING;
1381 }
1382
1383 return CMD_SUCCESS;
1384 }
1385
1386 DEFUN (no_synchronization,
1387 no_synchronization_cmd,
1388 "no synchronization",
1389 NO_STR
1390 "Perform IGP synchronization\n")
1391 {
1392 return CMD_SUCCESS;
1393 }
1394
1395 DEFUN (no_auto_summary,
1396 no_auto_summary_cmd,
1397 "no auto-summary",
1398 NO_STR
1399 "Enable automatic network number summarization\n")
1400 {
1401 return CMD_SUCCESS;
1402 }
1403
1404 /* "router bgp" commands. */
1405 DEFUN_NOSH (router_bgp,
1406 router_bgp_cmd,
1407 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1408 ROUTER_STR
1409 BGP_STR
1410 AS_STR
1411 BGP_INSTANCE_HELP_STR)
1412 {
1413 int idx_asn = 2;
1414 int idx_view_vrf = 3;
1415 int idx_vrf = 4;
1416 int is_new_bgp = 0;
1417 int ret;
1418 as_t as;
1419 struct bgp *bgp;
1420 const char *name = NULL;
1421 enum bgp_instance_type inst_type;
1422
1423 // "router bgp" without an ASN
1424 if (argc == 2) {
1425 // Pending: Make VRF option available for ASN less config
1426 bgp = bgp_get_default();
1427
1428 if (bgp == NULL) {
1429 vty_out(vty, "%% No BGP process is configured\n");
1430 return CMD_WARNING_CONFIG_FAILED;
1431 }
1432
1433 if (listcount(bm->bgp) > 1) {
1434 vty_out(vty, "%% Please specify ASN and VRF\n");
1435 return CMD_WARNING_CONFIG_FAILED;
1436 }
1437 }
1438
1439 // "router bgp X"
1440 else {
1441 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1442
1443 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1444 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1445 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1446
1447 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1448 if (argc > 3) {
1449 name = argv[idx_vrf]->arg;
1450
1451 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1452 if (strmatch(name, VRF_DEFAULT_NAME))
1453 name = NULL;
1454 else
1455 inst_type = BGP_INSTANCE_TYPE_VRF;
1456 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1457 inst_type = BGP_INSTANCE_TYPE_VIEW;
1458 }
1459
1460 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1461 is_new_bgp = (bgp_lookup(as, name) == NULL);
1462
1463 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1464 switch (ret) {
1465 case BGP_ERR_AS_MISMATCH:
1466 vty_out(vty, "BGP is already running; AS is %u\n", as);
1467 return CMD_WARNING_CONFIG_FAILED;
1468 case BGP_ERR_INSTANCE_MISMATCH:
1469 vty_out(vty,
1470 "BGP instance name and AS number mismatch\n");
1471 vty_out(vty,
1472 "BGP instance is already running; AS is %u\n",
1473 as);
1474 return CMD_WARNING_CONFIG_FAILED;
1475 }
1476
1477 /*
1478 * If we just instantiated the default instance, complete
1479 * any pending VRF-VPN leaking that was configured via
1480 * earlier "router bgp X vrf FOO" blocks.
1481 */
1482 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1483 vpn_leak_postchange_all();
1484
1485 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1486 bgp_vpn_leak_export(bgp);
1487 /* Pending: handle when user tries to change a view to vrf n vv.
1488 */
1489 }
1490
1491 /* unset the auto created flag as the user config is now present */
1492 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1493 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1494
1495 return CMD_SUCCESS;
1496 }
1497
1498 /* "no router bgp" commands. */
1499 DEFUN (no_router_bgp,
1500 no_router_bgp_cmd,
1501 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1502 NO_STR
1503 ROUTER_STR
1504 BGP_STR
1505 AS_STR
1506 BGP_INSTANCE_HELP_STR)
1507 {
1508 int idx_asn = 3;
1509 int idx_vrf = 5;
1510 as_t as;
1511 struct bgp *bgp;
1512 const char *name = NULL;
1513
1514 // "no router bgp" without an ASN
1515 if (argc == 3) {
1516 // Pending: Make VRF option available for ASN less config
1517 bgp = bgp_get_default();
1518
1519 if (bgp == NULL) {
1520 vty_out(vty, "%% No BGP process is configured\n");
1521 return CMD_WARNING_CONFIG_FAILED;
1522 }
1523
1524 if (listcount(bm->bgp) > 1) {
1525 vty_out(vty, "%% Please specify ASN and VRF\n");
1526 return CMD_WARNING_CONFIG_FAILED;
1527 }
1528
1529 if (bgp->l3vni) {
1530 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1531 bgp->l3vni);
1532 return CMD_WARNING_CONFIG_FAILED;
1533 }
1534 } else {
1535 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1536
1537 if (argc > 4) {
1538 name = argv[idx_vrf]->arg;
1539 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1540 && strmatch(name, VRF_DEFAULT_NAME))
1541 name = NULL;
1542 }
1543
1544 /* Lookup bgp structure. */
1545 bgp = bgp_lookup(as, name);
1546 if (!bgp) {
1547 vty_out(vty, "%% Can't find BGP instance\n");
1548 return CMD_WARNING_CONFIG_FAILED;
1549 }
1550
1551 if (bgp->l3vni) {
1552 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1553 bgp->l3vni);
1554 return CMD_WARNING_CONFIG_FAILED;
1555 }
1556
1557 /* Cannot delete default instance if vrf instances exist */
1558 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1559 struct listnode *node;
1560 struct bgp *tmp_bgp;
1561
1562 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1563 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1564 continue;
1565 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1566 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1567 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1568 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1569 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1570 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1571 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1572 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1573 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1574 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1575 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1576 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1577 (bgp == bgp_get_evpn() &&
1578 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1579 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1580 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1581 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1582 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1583 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1584 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1585 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1586 (hashcount(tmp_bgp->vnihash))) {
1587 vty_out(vty,
1588 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1589 return CMD_WARNING_CONFIG_FAILED;
1590 }
1591 }
1592 }
1593 }
1594
1595 bgp_delete(bgp);
1596
1597 return CMD_SUCCESS;
1598 }
1599
1600 /* bgp session-dscp */
1601
1602 DEFPY (bgp_session_dscp,
1603 bgp_session_dscp_cmd,
1604 "bgp session-dscp (0-63)$dscp",
1605 BGP_STR
1606 "Override default (C6) bgp TCP session DSCP value\n"
1607 "Manually configured dscp parameter\n")
1608 {
1609 bm->tcp_dscp = dscp << 2;
1610
1611 return CMD_SUCCESS;
1612 }
1613
1614 DEFPY (no_bgp_session_dscp,
1615 no_bgp_session_dscp_cmd,
1616 "no bgp session-dscp [(0-63)]",
1617 NO_STR
1618 BGP_STR
1619 "Override default (C6) bgp TCP session DSCP value\n"
1620 "Manually configured dscp parameter\n")
1621 {
1622 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1623
1624 return CMD_SUCCESS;
1625 }
1626
1627 /* BGP router-id. */
1628
1629 DEFPY (bgp_router_id,
1630 bgp_router_id_cmd,
1631 "bgp router-id A.B.C.D",
1632 BGP_STR
1633 "Override configured router identifier\n"
1634 "Manually configured router identifier\n")
1635 {
1636 VTY_DECLVAR_CONTEXT(bgp, bgp);
1637 bgp_router_id_static_set(bgp, router_id);
1638 return CMD_SUCCESS;
1639 }
1640
1641 DEFPY (no_bgp_router_id,
1642 no_bgp_router_id_cmd,
1643 "no bgp router-id [A.B.C.D]",
1644 NO_STR
1645 BGP_STR
1646 "Override configured router identifier\n"
1647 "Manually configured router identifier\n")
1648 {
1649 VTY_DECLVAR_CONTEXT(bgp, bgp);
1650
1651 if (router_id_str) {
1652 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1653 vty_out(vty, "%% BGP router-id doesn't match\n");
1654 return CMD_WARNING_CONFIG_FAILED;
1655 }
1656 }
1657
1658 router_id.s_addr = 0;
1659 bgp_router_id_static_set(bgp, router_id);
1660
1661 return CMD_SUCCESS;
1662 }
1663
1664 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1665 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1666 NO_STR BGP_STR
1667 "Add community specific parameters\n"
1668 "Create an alias for a community\n"
1669 "Community (AA:BB or AA:BB:CC)\n"
1670 "Alias name\n")
1671 {
1672 struct community_alias ca = {};
1673 struct community_alias *lookup_community;
1674 struct community_alias *lookup_alias;
1675 struct community *comm;
1676 struct lcommunity *lcomm;
1677 uint8_t invalid = 0;
1678
1679 comm = community_str2com(community);
1680 if (!comm)
1681 invalid++;
1682 community_free(&comm);
1683
1684 lcomm = lcommunity_str2com(community);
1685 if (!lcomm)
1686 invalid++;
1687 lcommunity_free(&lcomm);
1688
1689 if (invalid > 1) {
1690 vty_out(vty, "Invalid community format\n");
1691 return CMD_WARNING;
1692 }
1693
1694 strlcpy(ca.community, community, sizeof(ca.community));
1695 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1696
1697 lookup_community = bgp_ca_community_lookup(&ca);
1698 lookup_alias = bgp_ca_alias_lookup(&ca);
1699
1700 if (no) {
1701 bgp_ca_alias_delete(&ca);
1702 bgp_ca_community_delete(&ca);
1703 } else {
1704 if (lookup_alias) {
1705 /* Lookup if community hash table has an item
1706 * with the same alias name.
1707 */
1708 strlcpy(ca.community, lookup_alias->community,
1709 sizeof(ca.community));
1710 if (bgp_ca_community_lookup(&ca)) {
1711 vty_out(vty,
1712 "community (%s) already has this alias (%s)\n",
1713 lookup_alias->community,
1714 lookup_alias->alias);
1715 return CMD_WARNING;
1716 }
1717 bgp_ca_alias_delete(&ca);
1718 }
1719
1720 if (lookup_community) {
1721 /* Lookup if alias hash table has an item
1722 * with the same community.
1723 */
1724 strlcpy(ca.alias, lookup_community->alias,
1725 sizeof(ca.alias));
1726 if (bgp_ca_alias_lookup(&ca)) {
1727 vty_out(vty,
1728 "alias (%s) already has this community (%s)\n",
1729 lookup_community->alias,
1730 lookup_community->community);
1731 return CMD_WARNING;
1732 }
1733 bgp_ca_community_delete(&ca);
1734 }
1735
1736 bgp_ca_alias_insert(&ca);
1737 bgp_ca_community_insert(&ca);
1738 }
1739
1740 return CMD_SUCCESS;
1741 }
1742
1743 DEFPY (bgp_global_suppress_fib_pending,
1744 bgp_global_suppress_fib_pending_cmd,
1745 "[no] bgp suppress-fib-pending",
1746 NO_STR
1747 BGP_STR
1748 "Advertise only routes that are programmed in kernel to peers globally\n")
1749 {
1750 bm_wait_for_fib_set(!no);
1751
1752 return CMD_SUCCESS;
1753 }
1754
1755 DEFPY (bgp_suppress_fib_pending,
1756 bgp_suppress_fib_pending_cmd,
1757 "[no] bgp suppress-fib-pending",
1758 NO_STR
1759 BGP_STR
1760 "Advertise only routes that are programmed in kernel to peers\n")
1761 {
1762 VTY_DECLVAR_CONTEXT(bgp, bgp);
1763
1764 bgp_suppress_fib_pending_set(bgp, !no);
1765 return CMD_SUCCESS;
1766 }
1767
1768
1769 /* BGP Cluster ID. */
1770 DEFUN (bgp_cluster_id,
1771 bgp_cluster_id_cmd,
1772 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1773 BGP_STR
1774 "Configure Route-Reflector Cluster-id\n"
1775 "Route-Reflector Cluster-id in IP address format\n"
1776 "Route-Reflector Cluster-id as 32 bit quantity\n")
1777 {
1778 VTY_DECLVAR_CONTEXT(bgp, bgp);
1779 int idx_ipv4 = 2;
1780 int ret;
1781 struct in_addr cluster;
1782
1783 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1784 if (!ret) {
1785 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1786 return CMD_WARNING_CONFIG_FAILED;
1787 }
1788
1789 bgp_cluster_id_set(bgp, &cluster);
1790 bgp_clear_star_soft_out(vty, bgp->name);
1791
1792 return CMD_SUCCESS;
1793 }
1794
1795 DEFUN (no_bgp_cluster_id,
1796 no_bgp_cluster_id_cmd,
1797 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1798 NO_STR
1799 BGP_STR
1800 "Configure Route-Reflector Cluster-id\n"
1801 "Route-Reflector Cluster-id in IP address format\n"
1802 "Route-Reflector Cluster-id as 32 bit quantity\n")
1803 {
1804 VTY_DECLVAR_CONTEXT(bgp, bgp);
1805 bgp_cluster_id_unset(bgp);
1806 bgp_clear_star_soft_out(vty, bgp->name);
1807
1808 return CMD_SUCCESS;
1809 }
1810
1811 DEFPY (bgp_norib,
1812 bgp_norib_cmd,
1813 "bgp no-rib",
1814 BGP_STR
1815 "Disable BGP route installation to RIB (Zebra)\n")
1816 {
1817 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1818 vty_out(vty,
1819 "%% No-RIB option is already set, nothing to do here.\n");
1820 return CMD_SUCCESS;
1821 }
1822
1823 bgp_option_norib_set_runtime();
1824
1825 return CMD_SUCCESS;
1826 }
1827
1828 DEFPY (no_bgp_norib,
1829 no_bgp_norib_cmd,
1830 "no bgp no-rib",
1831 NO_STR
1832 BGP_STR
1833 "Disable BGP route installation to RIB (Zebra)\n")
1834 {
1835 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1836 vty_out(vty,
1837 "%% No-RIB option is not set, nothing to do here.\n");
1838 return CMD_SUCCESS;
1839 }
1840
1841 bgp_option_norib_unset_runtime();
1842
1843 return CMD_SUCCESS;
1844 }
1845
1846 DEFPY (no_bgp_send_extra_data,
1847 no_bgp_send_extra_data_cmd,
1848 "[no] bgp send-extra-data zebra",
1849 NO_STR
1850 BGP_STR
1851 "Extra data to Zebra for display/use\n"
1852 "To zebra\n")
1853 {
1854 if (no)
1855 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1856 else
1857 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1858
1859 return CMD_SUCCESS;
1860 }
1861
1862 DEFUN (bgp_confederation_identifier,
1863 bgp_confederation_identifier_cmd,
1864 "bgp confederation identifier (1-4294967295)",
1865 BGP_STR
1866 "AS confederation parameters\n"
1867 "AS number\n"
1868 "Set routing domain confederation AS\n")
1869 {
1870 VTY_DECLVAR_CONTEXT(bgp, bgp);
1871 int idx_number = 3;
1872 as_t as;
1873
1874 as = strtoul(argv[idx_number]->arg, NULL, 10);
1875
1876 bgp_confederation_id_set(bgp, as);
1877
1878 return CMD_SUCCESS;
1879 }
1880
1881 DEFUN (no_bgp_confederation_identifier,
1882 no_bgp_confederation_identifier_cmd,
1883 "no bgp confederation identifier [(1-4294967295)]",
1884 NO_STR
1885 BGP_STR
1886 "AS confederation parameters\n"
1887 "AS number\n"
1888 "Set routing domain confederation AS\n")
1889 {
1890 VTY_DECLVAR_CONTEXT(bgp, bgp);
1891 bgp_confederation_id_unset(bgp);
1892
1893 return CMD_SUCCESS;
1894 }
1895
1896 DEFUN (bgp_confederation_peers,
1897 bgp_confederation_peers_cmd,
1898 "bgp confederation peers (1-4294967295)...",
1899 BGP_STR
1900 "AS confederation parameters\n"
1901 "Peer ASs in BGP confederation\n"
1902 AS_STR)
1903 {
1904 VTY_DECLVAR_CONTEXT(bgp, bgp);
1905 int idx_asn = 3;
1906 as_t as;
1907 int i;
1908
1909 for (i = idx_asn; i < argc; i++) {
1910 as = strtoul(argv[i]->arg, NULL, 10);
1911
1912 if (bgp->as == as) {
1913 vty_out(vty,
1914 "%% Local member-AS not allowed in confed peer list\n");
1915 continue;
1916 }
1917
1918 bgp_confederation_peers_add(bgp, as);
1919 }
1920 return CMD_SUCCESS;
1921 }
1922
1923 DEFUN (no_bgp_confederation_peers,
1924 no_bgp_confederation_peers_cmd,
1925 "no bgp confederation peers (1-4294967295)...",
1926 NO_STR
1927 BGP_STR
1928 "AS confederation parameters\n"
1929 "Peer ASs in BGP confederation\n"
1930 AS_STR)
1931 {
1932 VTY_DECLVAR_CONTEXT(bgp, bgp);
1933 int idx_asn = 4;
1934 as_t as;
1935 int i;
1936
1937 for (i = idx_asn; i < argc; i++) {
1938 as = strtoul(argv[i]->arg, NULL, 10);
1939
1940 bgp_confederation_peers_remove(bgp, as);
1941 }
1942 return CMD_SUCCESS;
1943 }
1944
1945 /**
1946 * Central routine for maximum-paths configuration.
1947 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1948 * @set: 1 for setting values, 0 for removing the max-paths config.
1949 */
1950 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1951 const char *mpaths, uint16_t options,
1952 int set)
1953 {
1954 VTY_DECLVAR_CONTEXT(bgp, bgp);
1955 uint16_t maxpaths = 0;
1956 int ret;
1957 afi_t afi;
1958 safi_t safi;
1959
1960 afi = bgp_node_afi(vty);
1961 safi = bgp_node_safi(vty);
1962
1963 if (set) {
1964 maxpaths = strtol(mpaths, NULL, 10);
1965 if (maxpaths > multipath_num) {
1966 vty_out(vty,
1967 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1968 maxpaths, multipath_num);
1969 return CMD_WARNING_CONFIG_FAILED;
1970 }
1971 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1972 options);
1973 } else
1974 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1975
1976 if (ret < 0) {
1977 vty_out(vty,
1978 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1979 (set == 1) ? "" : "un",
1980 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1981 maxpaths, afi, safi);
1982 return CMD_WARNING_CONFIG_FAILED;
1983 }
1984
1985 bgp_recalculate_all_bestpaths(bgp);
1986
1987 return CMD_SUCCESS;
1988 }
1989
1990 DEFUN (bgp_maxmed_admin,
1991 bgp_maxmed_admin_cmd,
1992 "bgp max-med administrative ",
1993 BGP_STR
1994 "Advertise routes with max-med\n"
1995 "Administratively applied, for an indefinite period\n")
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998
1999 bgp->v_maxmed_admin = 1;
2000 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2001
2002 bgp_maxmed_update(bgp);
2003
2004 return CMD_SUCCESS;
2005 }
2006
2007 DEFUN (bgp_maxmed_admin_medv,
2008 bgp_maxmed_admin_medv_cmd,
2009 "bgp max-med administrative (0-4294967295)",
2010 BGP_STR
2011 "Advertise routes with max-med\n"
2012 "Administratively applied, for an indefinite period\n"
2013 "Max MED value to be used\n")
2014 {
2015 VTY_DECLVAR_CONTEXT(bgp, bgp);
2016 int idx_number = 3;
2017
2018 bgp->v_maxmed_admin = 1;
2019 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2020
2021 bgp_maxmed_update(bgp);
2022
2023 return CMD_SUCCESS;
2024 }
2025
2026 DEFUN (no_bgp_maxmed_admin,
2027 no_bgp_maxmed_admin_cmd,
2028 "no bgp max-med administrative [(0-4294967295)]",
2029 NO_STR
2030 BGP_STR
2031 "Advertise routes with max-med\n"
2032 "Administratively applied, for an indefinite period\n"
2033 "Max MED value to be used\n")
2034 {
2035 VTY_DECLVAR_CONTEXT(bgp, bgp);
2036 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2037 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2038 bgp_maxmed_update(bgp);
2039
2040 return CMD_SUCCESS;
2041 }
2042
2043 DEFUN (bgp_maxmed_onstartup,
2044 bgp_maxmed_onstartup_cmd,
2045 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2046 BGP_STR
2047 "Advertise routes with max-med\n"
2048 "Effective on a startup\n"
2049 "Time (seconds) period for max-med\n"
2050 "Max MED value to be used\n")
2051 {
2052 VTY_DECLVAR_CONTEXT(bgp, bgp);
2053 int idx = 0;
2054
2055 if (argv_find(argv, argc, "(5-86400)", &idx))
2056 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2057 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2058 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2059 else
2060 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2061
2062 bgp_maxmed_update(bgp);
2063
2064 return CMD_SUCCESS;
2065 }
2066
2067 DEFUN (no_bgp_maxmed_onstartup,
2068 no_bgp_maxmed_onstartup_cmd,
2069 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2070 NO_STR
2071 BGP_STR
2072 "Advertise routes with max-med\n"
2073 "Effective on a startup\n"
2074 "Time (seconds) period for max-med\n"
2075 "Max MED value to be used\n")
2076 {
2077 VTY_DECLVAR_CONTEXT(bgp, bgp);
2078
2079 /* Cancel max-med onstartup if its on */
2080 if (bgp->t_maxmed_onstartup) {
2081 THREAD_OFF(bgp->t_maxmed_onstartup);
2082 bgp->maxmed_onstartup_over = 1;
2083 }
2084
2085 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2086 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2087
2088 bgp_maxmed_update(bgp);
2089
2090 return CMD_SUCCESS;
2091 }
2092
2093 static int bgp_global_update_delay_config_vty(struct vty *vty,
2094 uint16_t update_delay,
2095 uint16_t establish_wait)
2096 {
2097 struct listnode *node, *nnode;
2098 struct bgp *bgp;
2099 bool vrf_cfg = false;
2100
2101 /*
2102 * See if update-delay is set per-vrf and warn user to delete it
2103 * Note that we only need to check this if this is the first time
2104 * setting the global config.
2105 */
2106 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2107 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2108 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2109 vty_out(vty,
2110 "%% update-delay configuration found in vrf %s\n",
2111 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2112 ? VRF_DEFAULT_NAME
2113 : bgp->name);
2114 vrf_cfg = true;
2115 }
2116 }
2117 }
2118
2119 if (vrf_cfg) {
2120 vty_out(vty,
2121 "%%Failed: global update-delay config not permitted\n");
2122 return CMD_WARNING;
2123 }
2124
2125 if (!establish_wait) { /* update-delay <delay> */
2126 bm->v_update_delay = update_delay;
2127 bm->v_establish_wait = bm->v_update_delay;
2128 } else {
2129 /* update-delay <delay> <establish-wait> */
2130 if (update_delay < establish_wait) {
2131 vty_out(vty,
2132 "%%Failed: update-delay less than the establish-wait!\n");
2133 return CMD_WARNING_CONFIG_FAILED;
2134 }
2135
2136 bm->v_update_delay = update_delay;
2137 bm->v_establish_wait = establish_wait;
2138 }
2139
2140 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2141 bgp->v_update_delay = bm->v_update_delay;
2142 bgp->v_establish_wait = bm->v_establish_wait;
2143 }
2144
2145 return CMD_SUCCESS;
2146 }
2147
2148 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2149 {
2150 struct listnode *node, *nnode;
2151 struct bgp *bgp;
2152
2153 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2154 bm->v_establish_wait = bm->v_update_delay;
2155
2156 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2157 bgp->v_update_delay = bm->v_update_delay;
2158 bgp->v_establish_wait = bm->v_establish_wait;
2159 }
2160
2161 return CMD_SUCCESS;
2162 }
2163
2164 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2165 uint16_t establish_wait)
2166 {
2167 VTY_DECLVAR_CONTEXT(bgp, bgp);
2168
2169 /* if configured globally, per-instance config is not allowed */
2170 if (bm->v_update_delay) {
2171 vty_out(vty,
2172 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2173 return CMD_WARNING_CONFIG_FAILED;
2174 }
2175
2176
2177 if (!establish_wait) /* update-delay <delay> */
2178 {
2179 bgp->v_update_delay = update_delay;
2180 bgp->v_establish_wait = bgp->v_update_delay;
2181 return CMD_SUCCESS;
2182 }
2183
2184 /* update-delay <delay> <establish-wait> */
2185 if (update_delay < establish_wait) {
2186 vty_out(vty,
2187 "%%Failed: update-delay less than the establish-wait!\n");
2188 return CMD_WARNING_CONFIG_FAILED;
2189 }
2190
2191 bgp->v_update_delay = update_delay;
2192 bgp->v_establish_wait = establish_wait;
2193
2194 return CMD_SUCCESS;
2195 }
2196
2197 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2198 {
2199 VTY_DECLVAR_CONTEXT(bgp, bgp);
2200
2201 /* If configured globally, cannot remove from one bgp instance */
2202 if (bm->v_update_delay) {
2203 vty_out(vty,
2204 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2205 return CMD_WARNING_CONFIG_FAILED;
2206 }
2207 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2208 bgp->v_establish_wait = bgp->v_update_delay;
2209
2210 return CMD_SUCCESS;
2211 }
2212
2213 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2214 {
2215 /* If configured globally, no need to display per-instance value */
2216 if (bgp->v_update_delay != bm->v_update_delay) {
2217 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2218 if (bgp->v_update_delay != bgp->v_establish_wait)
2219 vty_out(vty, " %d", bgp->v_establish_wait);
2220 vty_out(vty, "\n");
2221 }
2222 }
2223
2224 /* Global update-delay configuration */
2225 DEFPY (bgp_global_update_delay,
2226 bgp_global_update_delay_cmd,
2227 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2228 BGP_STR
2229 "Force initial delay for best-path and updates for all bgp instances\n"
2230 "Max delay in seconds\n"
2231 "Establish wait in seconds\n")
2232 {
2233 return bgp_global_update_delay_config_vty(vty, delay, wait);
2234 }
2235
2236 /* Global update-delay deconfiguration */
2237 DEFPY (no_bgp_global_update_delay,
2238 no_bgp_global_update_delay_cmd,
2239 "no bgp update-delay [(0-3600) [(1-3600)]]",
2240 NO_STR
2241 BGP_STR
2242 "Force initial delay for best-path and updates\n"
2243 "Max delay in seconds\n"
2244 "Establish wait in seconds\n")
2245 {
2246 return bgp_global_update_delay_deconfig_vty(vty);
2247 }
2248
2249 /* Update-delay configuration */
2250
2251 DEFPY (bgp_update_delay,
2252 bgp_update_delay_cmd,
2253 "update-delay (0-3600)$delay [(1-3600)$wait]",
2254 "Force initial delay for best-path and updates\n"
2255 "Max delay in seconds\n"
2256 "Establish wait in seconds\n")
2257 {
2258 return bgp_update_delay_config_vty(vty, delay, wait);
2259 }
2260
2261 /* Update-delay deconfiguration */
2262 DEFPY (no_bgp_update_delay,
2263 no_bgp_update_delay_cmd,
2264 "no update-delay [(0-3600) [(1-3600)]]",
2265 NO_STR
2266 "Force initial delay for best-path and updates\n"
2267 "Max delay in seconds\n"
2268 "Establish wait in seconds\n")
2269 {
2270 return bgp_update_delay_deconfig_vty(vty);
2271 }
2272
2273
2274 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2275 bool set)
2276 {
2277 VTY_DECLVAR_CONTEXT(bgp, bgp);
2278
2279 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2280 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2281
2282 return CMD_SUCCESS;
2283 }
2284
2285 static int bgp_rpkt_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_READ_PACKET_MAX;
2291 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2292
2293 return CMD_SUCCESS;
2294 }
2295
2296 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2297 {
2298 uint32_t quanta =
2299 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2300 if (quanta != BGP_WRITE_PACKET_MAX)
2301 vty_out(vty, " write-quanta %d\n", quanta);
2302 }
2303
2304 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2305 {
2306 uint32_t quanta =
2307 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2308 if (quanta != BGP_READ_PACKET_MAX)
2309 vty_out(vty, " read-quanta %d\n", quanta);
2310 }
2311
2312 /* Packet quanta configuration
2313 *
2314 * XXX: The value set here controls the size of a stack buffer in the IO
2315 * thread. When changing these limits be careful to prevent stack overflow.
2316 *
2317 * Furthermore, the maximums used here should correspond to
2318 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2319 */
2320 DEFPY (bgp_wpkt_quanta,
2321 bgp_wpkt_quanta_cmd,
2322 "[no] write-quanta (1-64)$quanta",
2323 NO_STR
2324 "How many packets to write to peer socket per run\n"
2325 "Number of packets\n")
2326 {
2327 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2328 }
2329
2330 DEFPY (bgp_rpkt_quanta,
2331 bgp_rpkt_quanta_cmd,
2332 "[no] read-quanta (1-10)$quanta",
2333 NO_STR
2334 "How many packets to read from peer socket per I/O cycle\n"
2335 "Number of packets\n")
2336 {
2337 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2338 }
2339
2340 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2341 {
2342 if (!bgp->heuristic_coalesce)
2343 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2344 }
2345
2346 /* BGP TCP keepalive */
2347 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2348 {
2349 if (bgp->tcp_keepalive_idle) {
2350 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2351 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2352 bgp->tcp_keepalive_probes);
2353 }
2354 }
2355
2356 DEFUN (bgp_coalesce_time,
2357 bgp_coalesce_time_cmd,
2358 "coalesce-time (0-4294967295)",
2359 "Subgroup coalesce timer\n"
2360 "Subgroup coalesce timer value (in ms)\n")
2361 {
2362 VTY_DECLVAR_CONTEXT(bgp, bgp);
2363
2364 int idx = 0;
2365
2366 bgp->heuristic_coalesce = false;
2367
2368 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2369 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2370
2371 return CMD_SUCCESS;
2372 }
2373
2374 DEFUN (no_bgp_coalesce_time,
2375 no_bgp_coalesce_time_cmd,
2376 "no coalesce-time (0-4294967295)",
2377 NO_STR
2378 "Subgroup coalesce timer\n"
2379 "Subgroup coalesce timer value (in ms)\n")
2380 {
2381 VTY_DECLVAR_CONTEXT(bgp, bgp);
2382
2383 bgp->heuristic_coalesce = true;
2384 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2385 return CMD_SUCCESS;
2386 }
2387
2388 /* Maximum-paths configuration */
2389 DEFUN (bgp_maxpaths,
2390 bgp_maxpaths_cmd,
2391 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2392 "Forward packets over multiple paths\n"
2393 "Number of paths\n")
2394 {
2395 int idx_number = 1;
2396 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2397 argv[idx_number]->arg, 0, 1);
2398 }
2399
2400 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2401 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2402 "Forward packets over multiple paths\n"
2403 "Number of paths\n")
2404
2405 DEFUN (bgp_maxpaths_ibgp,
2406 bgp_maxpaths_ibgp_cmd,
2407 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2408 "Forward packets over multiple paths\n"
2409 "iBGP-multipath\n"
2410 "Number of paths\n")
2411 {
2412 int idx_number = 2;
2413 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2414 argv[idx_number]->arg, 0, 1);
2415 }
2416
2417 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2418 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2419 "Forward packets over multiple paths\n"
2420 "iBGP-multipath\n"
2421 "Number of paths\n")
2422
2423 DEFUN (bgp_maxpaths_ibgp_cluster,
2424 bgp_maxpaths_ibgp_cluster_cmd,
2425 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2426 "Forward packets over multiple paths\n"
2427 "iBGP-multipath\n"
2428 "Number of paths\n"
2429 "Match the cluster length\n")
2430 {
2431 int idx_number = 2;
2432 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2433 argv[idx_number]->arg, true, 1);
2434 }
2435
2436 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2437 "maximum-paths ibgp " CMD_RANGE_STR(
2438 1, MULTIPATH_NUM) " equal-cluster-length",
2439 "Forward packets over multiple paths\n"
2440 "iBGP-multipath\n"
2441 "Number of paths\n"
2442 "Match the cluster length\n")
2443
2444 DEFUN (no_bgp_maxpaths,
2445 no_bgp_maxpaths_cmd,
2446 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2447 NO_STR
2448 "Forward packets over multiple paths\n"
2449 "Number of paths\n")
2450 {
2451 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2452 }
2453
2454 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2455 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2456 "Forward packets over multiple paths\n"
2457 "Number of paths\n")
2458
2459 DEFUN (no_bgp_maxpaths_ibgp,
2460 no_bgp_maxpaths_ibgp_cmd,
2461 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2462 NO_STR
2463 "Forward packets over multiple paths\n"
2464 "iBGP-multipath\n"
2465 "Number of paths\n"
2466 "Match the cluster length\n")
2467 {
2468 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2469 }
2470
2471 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2472 "no maximum-paths ibgp [" CMD_RANGE_STR(
2473 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2474 NO_STR
2475 "Forward packets over multiple paths\n"
2476 "iBGP-multipath\n"
2477 "Number of paths\n"
2478 "Match the cluster length\n")
2479
2480 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2481 afi_t afi, safi_t safi)
2482 {
2483 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2484 vty_out(vty, " maximum-paths %d\n",
2485 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2486 }
2487
2488 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2489 vty_out(vty, " maximum-paths ibgp %d",
2490 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2491 if (bgp->maxpaths[afi][safi].same_clusterlen)
2492 vty_out(vty, " equal-cluster-length");
2493 vty_out(vty, "\n");
2494 }
2495 }
2496
2497 /* BGP timers. */
2498
2499 DEFUN (bgp_timers,
2500 bgp_timers_cmd,
2501 "timers bgp (0-65535) (0-65535)",
2502 "Adjust routing timers\n"
2503 "BGP timers\n"
2504 "Keepalive interval\n"
2505 "Holdtime\n")
2506 {
2507 VTY_DECLVAR_CONTEXT(bgp, bgp);
2508 int idx_number = 2;
2509 int idx_number_2 = 3;
2510 unsigned long keepalive = 0;
2511 unsigned long holdtime = 0;
2512
2513 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2514 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2515
2516 /* Holdtime value check. */
2517 if (holdtime < 3 && holdtime != 0) {
2518 vty_out(vty,
2519 "%% hold time value must be either 0 or greater than 3\n");
2520 return CMD_WARNING_CONFIG_FAILED;
2521 }
2522
2523 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2524 BGP_DEFAULT_DELAYOPEN);
2525
2526 return CMD_SUCCESS;
2527 }
2528
2529 DEFUN (no_bgp_timers,
2530 no_bgp_timers_cmd,
2531 "no timers bgp [(0-65535) (0-65535)]",
2532 NO_STR
2533 "Adjust routing timers\n"
2534 "BGP timers\n"
2535 "Keepalive interval\n"
2536 "Holdtime\n")
2537 {
2538 VTY_DECLVAR_CONTEXT(bgp, bgp);
2539 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2540 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2541
2542 return CMD_SUCCESS;
2543 }
2544
2545 /* BGP minimum holdtime. */
2546
2547 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2548 "bgp minimum-holdtime (1-65535)",
2549 "BGP specific commands\n"
2550 "BGP minimum holdtime\n"
2551 "Seconds\n")
2552 {
2553 VTY_DECLVAR_CONTEXT(bgp, bgp);
2554 int idx_number = 2;
2555 unsigned long min_holdtime;
2556
2557 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2558
2559 bgp->default_min_holdtime = min_holdtime;
2560
2561 return CMD_SUCCESS;
2562 }
2563
2564 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2565 "no bgp minimum-holdtime [(1-65535)]",
2566 NO_STR
2567 "BGP specific commands\n"
2568 "BGP minimum holdtime\n"
2569 "Seconds\n")
2570 {
2571 VTY_DECLVAR_CONTEXT(bgp, bgp);
2572
2573 bgp->default_min_holdtime = 0;
2574
2575 return CMD_SUCCESS;
2576 }
2577
2578 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2579 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2580 BGP_STR
2581 "TCP keepalive parameters\n"
2582 "TCP keepalive idle time (seconds)\n"
2583 "TCP keepalive interval (seconds)\n"
2584 "TCP keepalive maximum probes\n")
2585 {
2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587
2588 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2589 (uint16_t)probes);
2590
2591 return CMD_SUCCESS;
2592 }
2593
2594 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2595 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2596 NO_STR
2597 BGP_STR
2598 "TCP keepalive parameters\n"
2599 "TCP keepalive idle time (seconds)\n"
2600 "TCP keepalive interval (seconds)\n"
2601 "TCP keepalive maximum probes\n")
2602 {
2603 VTY_DECLVAR_CONTEXT(bgp, bgp);
2604
2605 bgp_tcp_keepalive_unset(bgp);
2606
2607 return CMD_SUCCESS;
2608 }
2609
2610 DEFUN (bgp_client_to_client_reflection,
2611 bgp_client_to_client_reflection_cmd,
2612 "bgp client-to-client reflection",
2613 BGP_STR
2614 "Configure client to client route reflection\n"
2615 "reflection of routes allowed\n")
2616 {
2617 VTY_DECLVAR_CONTEXT(bgp, bgp);
2618 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2619 bgp_clear_star_soft_out(vty, bgp->name);
2620
2621 return CMD_SUCCESS;
2622 }
2623
2624 DEFUN (no_bgp_client_to_client_reflection,
2625 no_bgp_client_to_client_reflection_cmd,
2626 "no bgp client-to-client reflection",
2627 NO_STR
2628 BGP_STR
2629 "Configure client to client route reflection\n"
2630 "reflection of routes allowed\n")
2631 {
2632 VTY_DECLVAR_CONTEXT(bgp, bgp);
2633 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2634 bgp_clear_star_soft_out(vty, bgp->name);
2635
2636 return CMD_SUCCESS;
2637 }
2638
2639 /* "bgp always-compare-med" configuration. */
2640 DEFUN (bgp_always_compare_med,
2641 bgp_always_compare_med_cmd,
2642 "bgp always-compare-med",
2643 BGP_STR
2644 "Allow comparing MED from different neighbors\n")
2645 {
2646 VTY_DECLVAR_CONTEXT(bgp, bgp);
2647 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2648 bgp_recalculate_all_bestpaths(bgp);
2649
2650 return CMD_SUCCESS;
2651 }
2652
2653 DEFUN (no_bgp_always_compare_med,
2654 no_bgp_always_compare_med_cmd,
2655 "no bgp always-compare-med",
2656 NO_STR
2657 BGP_STR
2658 "Allow comparing MED from different neighbors\n")
2659 {
2660 VTY_DECLVAR_CONTEXT(bgp, bgp);
2661 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2662 bgp_recalculate_all_bestpaths(bgp);
2663
2664 return CMD_SUCCESS;
2665 }
2666
2667
2668 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2669 "bgp ebgp-requires-policy",
2670 BGP_STR
2671 "Require in and out policy for eBGP peers (RFC8212)\n")
2672 {
2673 VTY_DECLVAR_CONTEXT(bgp, bgp);
2674 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2675 return CMD_SUCCESS;
2676 }
2677
2678 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2679 "no bgp ebgp-requires-policy",
2680 NO_STR
2681 BGP_STR
2682 "Require in and out policy for eBGP peers (RFC8212)\n")
2683 {
2684 VTY_DECLVAR_CONTEXT(bgp, bgp);
2685 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2686 return CMD_SUCCESS;
2687 }
2688
2689 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2690 "bgp suppress-duplicates",
2691 BGP_STR
2692 "Suppress duplicate updates if the route actually not changed\n")
2693 {
2694 VTY_DECLVAR_CONTEXT(bgp, bgp);
2695 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2696 return CMD_SUCCESS;
2697 }
2698
2699 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2700 "no bgp suppress-duplicates",
2701 NO_STR
2702 BGP_STR
2703 "Suppress duplicate updates if the route actually not changed\n")
2704 {
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2707 return CMD_SUCCESS;
2708 }
2709
2710 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2711 "bgp reject-as-sets",
2712 BGP_STR
2713 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2714 {
2715 VTY_DECLVAR_CONTEXT(bgp, bgp);
2716 struct listnode *node, *nnode;
2717 struct peer *peer;
2718
2719 bgp->reject_as_sets = true;
2720
2721 /* Reset existing BGP sessions to reject routes
2722 * with aspath containing AS_SET or AS_CONFED_SET.
2723 */
2724 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2725 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2726 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2727 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2728 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2729 }
2730 }
2731
2732 return CMD_SUCCESS;
2733 }
2734
2735 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2736 "no bgp reject-as-sets",
2737 NO_STR
2738 BGP_STR
2739 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2740 {
2741 VTY_DECLVAR_CONTEXT(bgp, bgp);
2742 struct listnode *node, *nnode;
2743 struct peer *peer;
2744
2745 bgp->reject_as_sets = false;
2746
2747 /* Reset existing BGP sessions to reject routes
2748 * with aspath containing AS_SET or AS_CONFED_SET.
2749 */
2750 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2751 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2752 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2753 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2754 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2755 }
2756 }
2757
2758 return CMD_SUCCESS;
2759 }
2760
2761 /* "bgp deterministic-med" configuration. */
2762 DEFUN (bgp_deterministic_med,
2763 bgp_deterministic_med_cmd,
2764 "bgp deterministic-med",
2765 BGP_STR
2766 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2767 {
2768 VTY_DECLVAR_CONTEXT(bgp, bgp);
2769
2770 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2771 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2772 bgp_recalculate_all_bestpaths(bgp);
2773 }
2774
2775 return CMD_SUCCESS;
2776 }
2777
2778 DEFUN (no_bgp_deterministic_med,
2779 no_bgp_deterministic_med_cmd,
2780 "no bgp deterministic-med",
2781 NO_STR
2782 BGP_STR
2783 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2784 {
2785 VTY_DECLVAR_CONTEXT(bgp, bgp);
2786 int bestpath_per_as_used;
2787 afi_t afi;
2788 safi_t safi;
2789 struct peer *peer;
2790 struct listnode *node, *nnode;
2791
2792 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2793 bestpath_per_as_used = 0;
2794
2795 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2796 FOREACH_AFI_SAFI (afi, safi)
2797 if (bgp_addpath_dmed_required(
2798 peer->addpath_type[afi][safi])) {
2799 bestpath_per_as_used = 1;
2800 break;
2801 }
2802
2803 if (bestpath_per_as_used)
2804 break;
2805 }
2806
2807 if (bestpath_per_as_used) {
2808 vty_out(vty,
2809 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2810 return CMD_WARNING_CONFIG_FAILED;
2811 } else {
2812 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2813 bgp_recalculate_all_bestpaths(bgp);
2814 }
2815 }
2816
2817 return CMD_SUCCESS;
2818 }
2819
2820 /* "bgp graceful-restart mode" configuration. */
2821 DEFUN (bgp_graceful_restart,
2822 bgp_graceful_restart_cmd,
2823 "bgp graceful-restart",
2824 BGP_STR
2825 GR_CMD
2826 )
2827 {
2828 int ret = BGP_GR_FAILURE;
2829
2830 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2831 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2832
2833 VTY_DECLVAR_CONTEXT(bgp, bgp);
2834
2835 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2836
2837 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2838 ret);
2839
2840 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2841 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2842 vty_out(vty,
2843 "Graceful restart configuration changed, reset all peers to take effect\n");
2844 return bgp_vty_return(vty, ret);
2845 }
2846
2847 DEFUN (no_bgp_graceful_restart,
2848 no_bgp_graceful_restart_cmd,
2849 "no bgp graceful-restart",
2850 NO_STR
2851 BGP_STR
2852 NO_GR_CMD
2853 )
2854 {
2855 VTY_DECLVAR_CONTEXT(bgp, bgp);
2856
2857 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2858 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2859
2860 int ret = BGP_GR_FAILURE;
2861
2862 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2863
2864 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2865 ret);
2866
2867 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2868 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2869 vty_out(vty,
2870 "Graceful restart configuration changed, reset all peers to take effect\n");
2871
2872 return bgp_vty_return(vty, ret);
2873 }
2874
2875 DEFUN (bgp_graceful_restart_stalepath_time,
2876 bgp_graceful_restart_stalepath_time_cmd,
2877 "bgp graceful-restart stalepath-time (1-4095)",
2878 BGP_STR
2879 "Graceful restart capability parameters\n"
2880 "Set the max time to hold onto restarting peer's stale paths\n"
2881 "Delay value (seconds)\n")
2882 {
2883 VTY_DECLVAR_CONTEXT(bgp, bgp);
2884 int idx_number = 3;
2885 uint32_t stalepath;
2886
2887 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2888 bgp->stalepath_time = stalepath;
2889 return CMD_SUCCESS;
2890 }
2891
2892 DEFUN (bgp_graceful_restart_restart_time,
2893 bgp_graceful_restart_restart_time_cmd,
2894 "bgp graceful-restart restart-time (0-4095)",
2895 BGP_STR
2896 "Graceful restart capability parameters\n"
2897 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2898 "Delay value (seconds)\n")
2899 {
2900 VTY_DECLVAR_CONTEXT(bgp, bgp);
2901 int idx_number = 3;
2902 uint32_t restart;
2903
2904 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2905 bgp->restart_time = restart;
2906 return CMD_SUCCESS;
2907 }
2908
2909 DEFUN (bgp_graceful_restart_select_defer_time,
2910 bgp_graceful_restart_select_defer_time_cmd,
2911 "bgp graceful-restart select-defer-time (0-3600)",
2912 BGP_STR
2913 "Graceful restart capability parameters\n"
2914 "Set the time to defer the BGP route selection after restart\n"
2915 "Delay value (seconds, 0 - disable)\n")
2916 {
2917 VTY_DECLVAR_CONTEXT(bgp, bgp);
2918 int idx_number = 3;
2919 uint32_t defer_time;
2920
2921 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2922 bgp->select_defer_time = defer_time;
2923 if (defer_time == 0)
2924 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2925 else
2926 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2927
2928 return CMD_SUCCESS;
2929 }
2930
2931 DEFUN (no_bgp_graceful_restart_stalepath_time,
2932 no_bgp_graceful_restart_stalepath_time_cmd,
2933 "no bgp graceful-restart stalepath-time [(1-4095)]",
2934 NO_STR
2935 BGP_STR
2936 "Graceful restart capability parameters\n"
2937 "Set the max time to hold onto restarting peer's stale paths\n"
2938 "Delay value (seconds)\n")
2939 {
2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941
2942 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2943 return CMD_SUCCESS;
2944 }
2945
2946 DEFUN (no_bgp_graceful_restart_restart_time,
2947 no_bgp_graceful_restart_restart_time_cmd,
2948 "no bgp graceful-restart restart-time [(0-4095)]",
2949 NO_STR
2950 BGP_STR
2951 "Graceful restart capability parameters\n"
2952 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2953 "Delay value (seconds)\n")
2954 {
2955 VTY_DECLVAR_CONTEXT(bgp, bgp);
2956
2957 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2958 return CMD_SUCCESS;
2959 }
2960
2961 DEFUN (no_bgp_graceful_restart_select_defer_time,
2962 no_bgp_graceful_restart_select_defer_time_cmd,
2963 "no bgp graceful-restart select-defer-time [(0-3600)]",
2964 NO_STR
2965 BGP_STR
2966 "Graceful restart capability parameters\n"
2967 "Set the time to defer the BGP route selection after restart\n"
2968 "Delay value (seconds)\n")
2969 {
2970 VTY_DECLVAR_CONTEXT(bgp, bgp);
2971
2972 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2973 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2974
2975 return CMD_SUCCESS;
2976 }
2977
2978 DEFUN (bgp_graceful_restart_preserve_fw,
2979 bgp_graceful_restart_preserve_fw_cmd,
2980 "bgp graceful-restart preserve-fw-state",
2981 BGP_STR
2982 "Graceful restart capability parameters\n"
2983 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2984 {
2985 VTY_DECLVAR_CONTEXT(bgp, bgp);
2986 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2987 return CMD_SUCCESS;
2988 }
2989
2990 DEFUN (no_bgp_graceful_restart_preserve_fw,
2991 no_bgp_graceful_restart_preserve_fw_cmd,
2992 "no bgp graceful-restart preserve-fw-state",
2993 NO_STR
2994 BGP_STR
2995 "Graceful restart capability parameters\n"
2996 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2997 {
2998 VTY_DECLVAR_CONTEXT(bgp, bgp);
2999 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3000 return CMD_SUCCESS;
3001 }
3002
3003 DEFPY (bgp_graceful_restart_notification,
3004 bgp_graceful_restart_notification_cmd,
3005 "[no$no] bgp graceful-restart notification",
3006 NO_STR
3007 BGP_STR
3008 "Graceful restart capability parameters\n"
3009 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3010 {
3011 VTY_DECLVAR_CONTEXT(bgp, bgp);
3012
3013 if (no)
3014 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3015 else
3016 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3017
3018 return CMD_SUCCESS;
3019 }
3020
3021 DEFPY (bgp_administrative_reset,
3022 bgp_administrative_reset_cmd,
3023 "[no$no] bgp hard-administrative-reset",
3024 NO_STR
3025 BGP_STR
3026 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3027 {
3028 VTY_DECLVAR_CONTEXT(bgp, bgp);
3029
3030 if (no)
3031 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3032 else
3033 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3034
3035 return CMD_SUCCESS;
3036 }
3037
3038 DEFUN (bgp_graceful_restart_disable,
3039 bgp_graceful_restart_disable_cmd,
3040 "bgp graceful-restart-disable",
3041 BGP_STR
3042 GR_DISABLE)
3043 {
3044 int ret = BGP_GR_FAILURE;
3045
3046 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3047 zlog_debug(
3048 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3049
3050 VTY_DECLVAR_CONTEXT(bgp, bgp);
3051
3052 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3053
3054 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3055 bgp->peer, ret);
3056
3057 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3058 zlog_debug(
3059 "[BGP_GR] 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 (no_bgp_graceful_restart_disable,
3067 no_bgp_graceful_restart_disable_cmd,
3068 "no bgp graceful-restart-disable",
3069 NO_STR
3070 BGP_STR
3071 NO_GR_DISABLE
3072 )
3073 {
3074 VTY_DECLVAR_CONTEXT(bgp, bgp);
3075
3076 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3077 zlog_debug(
3078 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3079
3080 int ret = BGP_GR_FAILURE;
3081
3082 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3083
3084 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3085 ret);
3086
3087 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3088 zlog_debug(
3089 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3090 vty_out(vty,
3091 "Graceful restart configuration changed, reset all peers to take effect\n");
3092
3093 return bgp_vty_return(vty, ret);
3094 }
3095
3096 DEFUN (bgp_neighbor_graceful_restart_set,
3097 bgp_neighbor_graceful_restart_set_cmd,
3098 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3099 NEIGHBOR_STR
3100 NEIGHBOR_ADDR_STR2
3101 GR_NEIGHBOR_CMD
3102 )
3103 {
3104 int idx_peer = 1;
3105 struct peer *peer;
3106 int ret = BGP_GR_FAILURE;
3107
3108 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3109
3110 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3111 zlog_debug(
3112 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3113
3114 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3115 if (!peer)
3116 return CMD_WARNING_CONFIG_FAILED;
3117
3118 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3119
3120 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3121 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3122
3123 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3124 zlog_debug(
3125 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3126 vty_out(vty,
3127 "Graceful restart configuration changed, reset this peer to take effect\n");
3128
3129 return bgp_vty_return(vty, ret);
3130 }
3131
3132 DEFUN (no_bgp_neighbor_graceful_restart,
3133 no_bgp_neighbor_graceful_restart_set_cmd,
3134 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3135 NO_STR
3136 NEIGHBOR_STR
3137 NEIGHBOR_ADDR_STR2
3138 NO_GR_NEIGHBOR_CMD
3139 )
3140 {
3141 int idx_peer = 2;
3142 int ret = BGP_GR_FAILURE;
3143 struct peer *peer;
3144
3145 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3146
3147 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3148 if (!peer)
3149 return CMD_WARNING_CONFIG_FAILED;
3150
3151 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3152 zlog_debug(
3153 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3154
3155 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3156
3157 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3158 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3159
3160 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3161 zlog_debug(
3162 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3163 vty_out(vty,
3164 "Graceful restart configuration changed, reset this peer to take effect\n");
3165
3166 return bgp_vty_return(vty, ret);
3167 }
3168
3169 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3170 bgp_neighbor_graceful_restart_helper_set_cmd,
3171 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3172 NEIGHBOR_STR
3173 NEIGHBOR_ADDR_STR2
3174 GR_NEIGHBOR_HELPER_CMD
3175 )
3176 {
3177 int idx_peer = 1;
3178 struct peer *peer;
3179 int ret = BGP_GR_FAILURE;
3180
3181 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3182
3183 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3184 zlog_debug(
3185 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3186
3187 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3188
3189 if (!peer)
3190 return CMD_WARNING_CONFIG_FAILED;
3191
3192
3193 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3194
3195 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3196 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3197
3198 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3199 zlog_debug(
3200 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3201 vty_out(vty,
3202 "Graceful restart configuration changed, reset this peer to take effect\n");
3203
3204 return bgp_vty_return(vty, ret);
3205 }
3206
3207 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3208 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3209 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3210 NO_STR
3211 NEIGHBOR_STR
3212 NEIGHBOR_ADDR_STR2
3213 NO_GR_NEIGHBOR_HELPER_CMD
3214 )
3215 {
3216 int idx_peer = 2;
3217 int ret = BGP_GR_FAILURE;
3218 struct peer *peer;
3219
3220 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3221
3222 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3223 if (!peer)
3224 return CMD_WARNING_CONFIG_FAILED;
3225
3226 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3227 zlog_debug(
3228 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3229
3230 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3231
3232 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3233 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3234
3235 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3236 zlog_debug(
3237 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3238 vty_out(vty,
3239 "Graceful restart configuration changed, reset this peer to take effect\n");
3240
3241 return bgp_vty_return(vty, ret);
3242 }
3243
3244 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3245 bgp_neighbor_graceful_restart_disable_set_cmd,
3246 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3247 NEIGHBOR_STR
3248 NEIGHBOR_ADDR_STR2
3249 GR_NEIGHBOR_DISABLE_CMD
3250 )
3251 {
3252 int idx_peer = 1;
3253 struct peer *peer;
3254 int ret = BGP_GR_FAILURE;
3255
3256 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3257
3258 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3259 zlog_debug(
3260 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3261
3262 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3263 if (!peer)
3264 return CMD_WARNING_CONFIG_FAILED;
3265
3266 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3267
3268 if (peer->bgp->t_startup)
3269 bgp_peer_gr_flags_update(peer);
3270
3271 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3272 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3273
3274 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3275 zlog_debug(
3276 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3277 vty_out(vty,
3278 "Graceful restart configuration changed, reset this peer to take effect\n");
3279
3280 return bgp_vty_return(vty, ret);
3281 }
3282
3283 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3284 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3285 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3286 NO_STR
3287 NEIGHBOR_STR
3288 NEIGHBOR_ADDR_STR2
3289 NO_GR_NEIGHBOR_DISABLE_CMD
3290 )
3291 {
3292 int idx_peer = 2;
3293 int ret = BGP_GR_FAILURE;
3294 struct peer *peer;
3295
3296 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3297
3298 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3299 if (!peer)
3300 return CMD_WARNING_CONFIG_FAILED;
3301
3302 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3303 zlog_debug(
3304 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3305
3306 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3307
3308 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3309 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3310
3311 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3312 zlog_debug(
3313 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3314 vty_out(vty,
3315 "Graceful restart configuration changed, reset this peer to take effect\n");
3316
3317 return bgp_vty_return(vty, ret);
3318 }
3319
3320 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3321 bgp_graceful_restart_disable_eor_cmd,
3322 "bgp graceful-restart disable-eor",
3323 BGP_STR
3324 "Graceful restart configuration parameters\n"
3325 "Disable EOR Check\n")
3326 {
3327 VTY_DECLVAR_CONTEXT(bgp, bgp);
3328 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3329
3330 return CMD_SUCCESS;
3331 }
3332
3333 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3334 no_bgp_graceful_restart_disable_eor_cmd,
3335 "no bgp graceful-restart disable-eor",
3336 NO_STR
3337 BGP_STR
3338 "Graceful restart configuration parameters\n"
3339 "Disable EOR Check\n")
3340 {
3341 VTY_DECLVAR_CONTEXT(bgp, bgp);
3342 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3343
3344 return CMD_SUCCESS;
3345 }
3346
3347 DEFUN (bgp_graceful_restart_rib_stale_time,
3348 bgp_graceful_restart_rib_stale_time_cmd,
3349 "bgp graceful-restart rib-stale-time (1-3600)",
3350 BGP_STR
3351 "Graceful restart configuration parameters\n"
3352 "Specify the stale route removal timer in rib\n"
3353 "Delay value (seconds)\n")
3354 {
3355 VTY_DECLVAR_CONTEXT(bgp, bgp);
3356 int idx_number = 3;
3357 uint32_t stale_time;
3358
3359 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3360 bgp->rib_stale_time = stale_time;
3361 /* Send the stale timer update message to RIB */
3362 if (bgp_zebra_stale_timer_update(bgp))
3363 return CMD_WARNING;
3364
3365 return CMD_SUCCESS;
3366 }
3367
3368 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3369 no_bgp_graceful_restart_rib_stale_time_cmd,
3370 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3371 NO_STR
3372 BGP_STR
3373 "Graceful restart configuration parameters\n"
3374 "Specify the stale route removal timer in rib\n"
3375 "Delay value (seconds)\n")
3376 {
3377 VTY_DECLVAR_CONTEXT(bgp, bgp);
3378
3379 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3380 /* Send the stale timer update message to RIB */
3381 if (bgp_zebra_stale_timer_update(bgp))
3382 return CMD_WARNING;
3383
3384 return CMD_SUCCESS;
3385 }
3386
3387 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3388 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3389 BGP_STR
3390 "Enable Long-lived Graceful Restart\n"
3391 "Specifies maximum time to wait before purging long-lived stale routes\n"
3392 "Stale time value (seconds)\n")
3393 {
3394 VTY_DECLVAR_CONTEXT(bgp, bgp);
3395
3396 uint32_t llgr_stale_time;
3397
3398 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3399 bgp->llgr_stale_time = llgr_stale_time;
3400
3401 return CMD_SUCCESS;
3402 }
3403
3404 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3405 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3406 NO_STR BGP_STR
3407 "Enable Long-lived Graceful Restart\n"
3408 "Specifies maximum time to wait before purging long-lived stale routes\n"
3409 "Stale time value (seconds)\n")
3410 {
3411 VTY_DECLVAR_CONTEXT(bgp, bgp);
3412
3413 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3414
3415 return CMD_SUCCESS;
3416 }
3417
3418 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3419 struct bgp *bgp)
3420 {
3421 bgp_static_redo_import_check(bgp);
3422 bgp_redistribute_redo(bgp);
3423 bgp_clear_star_soft_out(vty, bgp->name);
3424 bgp_clear_star_soft_in(vty, bgp->name);
3425 }
3426
3427 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3428 {
3429 struct listnode *node, *nnode;
3430 struct bgp *bgp;
3431 bool vrf_cfg = false;
3432
3433 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3434 return CMD_SUCCESS;
3435
3436 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3437 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3438 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3439 vty_out(vty,
3440 "%% graceful-shutdown configuration found in vrf %s\n",
3441 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3442 VRF_DEFAULT_NAME : bgp->name);
3443 vrf_cfg = true;
3444 }
3445 }
3446
3447 if (vrf_cfg) {
3448 vty_out(vty,
3449 "%%Failed: global graceful-shutdown not permitted\n");
3450 return CMD_WARNING;
3451 }
3452
3453 /* Set flag globally */
3454 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3455
3456 /* Initiate processing for all BGP instances. */
3457 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3458 bgp_initiate_graceful_shut_unshut(vty, bgp);
3459
3460 return CMD_SUCCESS;
3461 }
3462
3463 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3464 {
3465 struct listnode *node, *nnode;
3466 struct bgp *bgp;
3467
3468 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3469 return CMD_SUCCESS;
3470
3471 /* Unset flag globally */
3472 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3473
3474 /* Initiate processing for all BGP instances. */
3475 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3476 bgp_initiate_graceful_shut_unshut(vty, bgp);
3477
3478 return CMD_SUCCESS;
3479 }
3480
3481 /* "bgp graceful-shutdown" configuration */
3482 DEFUN (bgp_graceful_shutdown,
3483 bgp_graceful_shutdown_cmd,
3484 "bgp graceful-shutdown",
3485 BGP_STR
3486 "Graceful shutdown parameters\n")
3487 {
3488 if (vty->node == CONFIG_NODE)
3489 return bgp_global_graceful_shutdown_config_vty(vty);
3490
3491 VTY_DECLVAR_CONTEXT(bgp, bgp);
3492
3493 /* if configured globally, per-instance config is not allowed */
3494 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3495 vty_out(vty,
3496 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3497 return CMD_WARNING_CONFIG_FAILED;
3498 }
3499
3500 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3501 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3502 bgp_initiate_graceful_shut_unshut(vty, bgp);
3503 }
3504
3505 return CMD_SUCCESS;
3506 }
3507
3508 DEFUN (no_bgp_graceful_shutdown,
3509 no_bgp_graceful_shutdown_cmd,
3510 "no bgp graceful-shutdown",
3511 NO_STR
3512 BGP_STR
3513 "Graceful shutdown parameters\n")
3514 {
3515 if (vty->node == CONFIG_NODE)
3516 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3517
3518 VTY_DECLVAR_CONTEXT(bgp, bgp);
3519
3520 /* If configured globally, cannot remove from one bgp instance */
3521 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3522 vty_out(vty,
3523 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3524 return CMD_WARNING_CONFIG_FAILED;
3525 }
3526
3527 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3528 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3529 bgp_initiate_graceful_shut_unshut(vty, bgp);
3530 }
3531
3532 return CMD_SUCCESS;
3533 }
3534
3535 /* "bgp fast-external-failover" configuration. */
3536 DEFUN (bgp_fast_external_failover,
3537 bgp_fast_external_failover_cmd,
3538 "bgp fast-external-failover",
3539 BGP_STR
3540 "Immediately reset session if a link to a directly connected external peer goes down\n")
3541 {
3542 VTY_DECLVAR_CONTEXT(bgp, bgp);
3543 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3544 return CMD_SUCCESS;
3545 }
3546
3547 DEFUN (no_bgp_fast_external_failover,
3548 no_bgp_fast_external_failover_cmd,
3549 "no bgp fast-external-failover",
3550 NO_STR
3551 BGP_STR
3552 "Immediately reset session if a link to a directly connected external peer goes down\n")
3553 {
3554 VTY_DECLVAR_CONTEXT(bgp, bgp);
3555 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3556 return CMD_SUCCESS;
3557 }
3558
3559 /* "bgp bestpath compare-routerid" configuration. */
3560 DEFUN (bgp_bestpath_compare_router_id,
3561 bgp_bestpath_compare_router_id_cmd,
3562 "bgp bestpath compare-routerid",
3563 BGP_STR
3564 "Change the default bestpath selection\n"
3565 "Compare router-id for identical EBGP paths\n")
3566 {
3567 VTY_DECLVAR_CONTEXT(bgp, bgp);
3568 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3569 bgp_recalculate_all_bestpaths(bgp);
3570
3571 return CMD_SUCCESS;
3572 }
3573
3574 DEFUN (no_bgp_bestpath_compare_router_id,
3575 no_bgp_bestpath_compare_router_id_cmd,
3576 "no bgp bestpath compare-routerid",
3577 NO_STR
3578 BGP_STR
3579 "Change the default bestpath selection\n"
3580 "Compare router-id for identical EBGP paths\n")
3581 {
3582 VTY_DECLVAR_CONTEXT(bgp, bgp);
3583 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3584 bgp_recalculate_all_bestpaths(bgp);
3585
3586 return CMD_SUCCESS;
3587 }
3588
3589 /* "bgp bestpath as-path ignore" configuration. */
3590 DEFUN (bgp_bestpath_aspath_ignore,
3591 bgp_bestpath_aspath_ignore_cmd,
3592 "bgp bestpath as-path ignore",
3593 BGP_STR
3594 "Change the default bestpath selection\n"
3595 "AS-path attribute\n"
3596 "Ignore as-path length in selecting a route\n")
3597 {
3598 VTY_DECLVAR_CONTEXT(bgp, bgp);
3599 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3600 bgp_recalculate_all_bestpaths(bgp);
3601
3602 return CMD_SUCCESS;
3603 }
3604
3605 DEFUN (no_bgp_bestpath_aspath_ignore,
3606 no_bgp_bestpath_aspath_ignore_cmd,
3607 "no bgp bestpath as-path ignore",
3608 NO_STR
3609 BGP_STR
3610 "Change the default bestpath selection\n"
3611 "AS-path attribute\n"
3612 "Ignore as-path length in selecting a route\n")
3613 {
3614 VTY_DECLVAR_CONTEXT(bgp, bgp);
3615 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3616 bgp_recalculate_all_bestpaths(bgp);
3617
3618 return CMD_SUCCESS;
3619 }
3620
3621 /* "bgp bestpath as-path confed" configuration. */
3622 DEFUN (bgp_bestpath_aspath_confed,
3623 bgp_bestpath_aspath_confed_cmd,
3624 "bgp bestpath as-path confed",
3625 BGP_STR
3626 "Change the default bestpath selection\n"
3627 "AS-path attribute\n"
3628 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3629 {
3630 VTY_DECLVAR_CONTEXT(bgp, bgp);
3631 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3632 bgp_recalculate_all_bestpaths(bgp);
3633
3634 return CMD_SUCCESS;
3635 }
3636
3637 DEFUN (no_bgp_bestpath_aspath_confed,
3638 no_bgp_bestpath_aspath_confed_cmd,
3639 "no bgp bestpath as-path confed",
3640 NO_STR
3641 BGP_STR
3642 "Change the default bestpath selection\n"
3643 "AS-path attribute\n"
3644 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3645 {
3646 VTY_DECLVAR_CONTEXT(bgp, bgp);
3647 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3648 bgp_recalculate_all_bestpaths(bgp);
3649
3650 return CMD_SUCCESS;
3651 }
3652
3653 /* "bgp bestpath as-path multipath-relax" configuration. */
3654 DEFUN (bgp_bestpath_aspath_multipath_relax,
3655 bgp_bestpath_aspath_multipath_relax_cmd,
3656 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3657 BGP_STR
3658 "Change the default bestpath selection\n"
3659 "AS-path attribute\n"
3660 "Allow load sharing across routes that have different AS paths (but same length)\n"
3661 "Generate an AS_SET\n"
3662 "Do not generate an AS_SET\n")
3663 {
3664 VTY_DECLVAR_CONTEXT(bgp, bgp);
3665 int idx = 0;
3666 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3667
3668 /* no-as-set is now the default behavior so we can silently
3669 * ignore it */
3670 if (argv_find(argv, argc, "as-set", &idx))
3671 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3672 else
3673 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3674
3675 bgp_recalculate_all_bestpaths(bgp);
3676
3677 return CMD_SUCCESS;
3678 }
3679
3680 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3681 no_bgp_bestpath_aspath_multipath_relax_cmd,
3682 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3683 NO_STR
3684 BGP_STR
3685 "Change the default bestpath selection\n"
3686 "AS-path attribute\n"
3687 "Allow load sharing across routes that have different AS paths (but same length)\n"
3688 "Generate an AS_SET\n"
3689 "Do not generate an AS_SET\n")
3690 {
3691 VTY_DECLVAR_CONTEXT(bgp, bgp);
3692 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3693 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3694 bgp_recalculate_all_bestpaths(bgp);
3695
3696 return CMD_SUCCESS;
3697 }
3698
3699 /* "bgp bestpath peer-type multipath-relax" configuration. */
3700 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3701 bgp_bestpath_peer_type_multipath_relax_cmd,
3702 "bgp bestpath peer-type multipath-relax",
3703 BGP_STR
3704 "Change the default bestpath selection\n"
3705 "Peer type\n"
3706 "Allow load sharing across routes learned from different peer types\n")
3707 {
3708 VTY_DECLVAR_CONTEXT(bgp, bgp);
3709 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3710 bgp_recalculate_all_bestpaths(bgp);
3711
3712 return CMD_SUCCESS;
3713 }
3714
3715 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3716 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3717 "no bgp bestpath peer-type multipath-relax",
3718 NO_STR BGP_STR
3719 "Change the default bestpath selection\n"
3720 "Peer type\n"
3721 "Allow load sharing across routes learned from different peer types\n")
3722 {
3723 VTY_DECLVAR_CONTEXT(bgp, bgp);
3724 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3725 bgp_recalculate_all_bestpaths(bgp);
3726
3727 return CMD_SUCCESS;
3728 }
3729
3730 /* "bgp log-neighbor-changes" configuration. */
3731 DEFUN (bgp_log_neighbor_changes,
3732 bgp_log_neighbor_changes_cmd,
3733 "bgp log-neighbor-changes",
3734 BGP_STR
3735 "Log neighbor up/down and reset reason\n")
3736 {
3737 VTY_DECLVAR_CONTEXT(bgp, bgp);
3738 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3739 return CMD_SUCCESS;
3740 }
3741
3742 DEFUN (no_bgp_log_neighbor_changes,
3743 no_bgp_log_neighbor_changes_cmd,
3744 "no bgp log-neighbor-changes",
3745 NO_STR
3746 BGP_STR
3747 "Log neighbor up/down and reset reason\n")
3748 {
3749 VTY_DECLVAR_CONTEXT(bgp, bgp);
3750 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3751 return CMD_SUCCESS;
3752 }
3753
3754 /* "bgp bestpath med" configuration. */
3755 DEFUN (bgp_bestpath_med,
3756 bgp_bestpath_med_cmd,
3757 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3758 BGP_STR
3759 "Change the default bestpath selection\n"
3760 "MED attribute\n"
3761 "Compare MED among confederation paths\n"
3762 "Treat missing MED as the least preferred one\n"
3763 "Treat missing MED as the least preferred one\n"
3764 "Compare MED among confederation paths\n")
3765 {
3766 VTY_DECLVAR_CONTEXT(bgp, bgp);
3767
3768 int idx = 0;
3769 if (argv_find(argv, argc, "confed", &idx))
3770 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3771 idx = 0;
3772 if (argv_find(argv, argc, "missing-as-worst", &idx))
3773 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3774
3775 bgp_recalculate_all_bestpaths(bgp);
3776
3777 return CMD_SUCCESS;
3778 }
3779
3780 DEFUN (no_bgp_bestpath_med,
3781 no_bgp_bestpath_med_cmd,
3782 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3783 NO_STR
3784 BGP_STR
3785 "Change the default bestpath selection\n"
3786 "MED attribute\n"
3787 "Compare MED among confederation paths\n"
3788 "Treat missing MED as the least preferred one\n"
3789 "Treat missing MED as the least preferred one\n"
3790 "Compare MED among confederation paths\n")
3791 {
3792 VTY_DECLVAR_CONTEXT(bgp, bgp);
3793
3794 int idx = 0;
3795 if (argv_find(argv, argc, "confed", &idx))
3796 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3797 idx = 0;
3798 if (argv_find(argv, argc, "missing-as-worst", &idx))
3799 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3800
3801 bgp_recalculate_all_bestpaths(bgp);
3802
3803 return CMD_SUCCESS;
3804 }
3805
3806 /* "bgp bestpath bandwidth" configuration. */
3807 DEFPY (bgp_bestpath_bw,
3808 bgp_bestpath_bw_cmd,
3809 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3810 BGP_STR
3811 "Change the default bestpath selection\n"
3812 "Link Bandwidth attribute\n"
3813 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3814 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3815 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3816 {
3817 VTY_DECLVAR_CONTEXT(bgp, bgp);
3818 afi_t afi;
3819 safi_t safi;
3820
3821 if (!bw_cfg) {
3822 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3823 return CMD_ERR_INCOMPLETE;
3824 }
3825 if (!strcmp(bw_cfg, "ignore"))
3826 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3827 else if (!strcmp(bw_cfg, "skip-missing"))
3828 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3829 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3830 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3831 else
3832 return CMD_ERR_NO_MATCH;
3833
3834 /* This config is used in route install, so redo that. */
3835 FOREACH_AFI_SAFI (afi, safi) {
3836 if (!bgp_fibupd_safi(safi))
3837 continue;
3838 bgp_zebra_announce_table(bgp, afi, safi);
3839 }
3840
3841 return CMD_SUCCESS;
3842 }
3843
3844 DEFPY (no_bgp_bestpath_bw,
3845 no_bgp_bestpath_bw_cmd,
3846 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3847 NO_STR
3848 BGP_STR
3849 "Change the default bestpath selection\n"
3850 "Link Bandwidth attribute\n"
3851 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3852 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3853 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3854 {
3855 VTY_DECLVAR_CONTEXT(bgp, bgp);
3856 afi_t afi;
3857 safi_t safi;
3858
3859 bgp->lb_handling = BGP_LINK_BW_ECMP;
3860
3861 /* This config is used in route install, so redo that. */
3862 FOREACH_AFI_SAFI (afi, safi) {
3863 if (!bgp_fibupd_safi(safi))
3864 continue;
3865 bgp_zebra_announce_table(bgp, afi, safi);
3866 }
3867 return CMD_SUCCESS;
3868 }
3869
3870 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3871 "[no] bgp default <ipv4-unicast|"
3872 "ipv4-multicast|"
3873 "ipv4-vpn|"
3874 "ipv4-labeled-unicast|"
3875 "ipv4-flowspec|"
3876 "ipv6-unicast|"
3877 "ipv6-multicast|"
3878 "ipv6-vpn|"
3879 "ipv6-labeled-unicast|"
3880 "ipv6-flowspec|"
3881 "l2vpn-evpn>$afi_safi",
3882 NO_STR
3883 BGP_STR
3884 "Configure BGP defaults\n"
3885 "Activate ipv4-unicast for a peer by default\n"
3886 "Activate ipv4-multicast for a peer by default\n"
3887 "Activate ipv4-vpn for a peer by default\n"
3888 "Activate ipv4-labeled-unicast for a peer by default\n"
3889 "Activate ipv4-flowspec for a peer by default\n"
3890 "Activate ipv6-unicast for a peer by default\n"
3891 "Activate ipv6-multicast for a peer by default\n"
3892 "Activate ipv6-vpn for a peer by default\n"
3893 "Activate ipv6-labeled-unicast for a peer by default\n"
3894 "Activate ipv6-flowspec for a peer by default\n"
3895 "Activate l2vpn-evpn for a peer by default\n")
3896 {
3897 VTY_DECLVAR_CONTEXT(bgp, bgp);
3898 char afi_safi_str[strlen(afi_safi) + 1];
3899 char *afi_safi_str_tok;
3900
3901 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3902 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3903 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3904 afi_t afi = bgp_vty_afi_from_str(afi_str);
3905 safi_t safi;
3906
3907 /*
3908 * Impossible situation but making coverity happy
3909 */
3910 assert(afi != AFI_MAX);
3911
3912 if (strmatch(safi_str, "labeled"))
3913 safi = bgp_vty_safi_from_str("labeled-unicast");
3914 else
3915 safi = bgp_vty_safi_from_str(safi_str);
3916
3917 assert(safi != SAFI_MAX);
3918 if (no)
3919 bgp->default_af[afi][safi] = false;
3920 else {
3921 if ((safi == SAFI_LABELED_UNICAST
3922 && bgp->default_af[afi][SAFI_UNICAST])
3923 || (safi == SAFI_UNICAST
3924 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3925 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3926 else
3927 bgp->default_af[afi][safi] = true;
3928 }
3929
3930 return CMD_SUCCESS;
3931 }
3932
3933 /* Display hostname in certain command outputs */
3934 DEFUN (bgp_default_show_hostname,
3935 bgp_default_show_hostname_cmd,
3936 "bgp default show-hostname",
3937 BGP_STR
3938 "Configure BGP defaults\n"
3939 "Show hostname in certain command outputs\n")
3940 {
3941 VTY_DECLVAR_CONTEXT(bgp, bgp);
3942 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3943 return CMD_SUCCESS;
3944 }
3945
3946 DEFUN (no_bgp_default_show_hostname,
3947 no_bgp_default_show_hostname_cmd,
3948 "no bgp default show-hostname",
3949 NO_STR
3950 BGP_STR
3951 "Configure BGP defaults\n"
3952 "Show hostname in certain command outputs\n")
3953 {
3954 VTY_DECLVAR_CONTEXT(bgp, bgp);
3955 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3956 return CMD_SUCCESS;
3957 }
3958
3959 /* Display hostname in certain command outputs */
3960 DEFUN (bgp_default_show_nexthop_hostname,
3961 bgp_default_show_nexthop_hostname_cmd,
3962 "bgp default show-nexthop-hostname",
3963 BGP_STR
3964 "Configure BGP defaults\n"
3965 "Show hostname for nexthop in certain command outputs\n")
3966 {
3967 VTY_DECLVAR_CONTEXT(bgp, bgp);
3968 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3969 return CMD_SUCCESS;
3970 }
3971
3972 DEFUN (no_bgp_default_show_nexthop_hostname,
3973 no_bgp_default_show_nexthop_hostname_cmd,
3974 "no bgp default show-nexthop-hostname",
3975 NO_STR
3976 BGP_STR
3977 "Configure BGP defaults\n"
3978 "Show hostname for nexthop in certain command outputs\n")
3979 {
3980 VTY_DECLVAR_CONTEXT(bgp, bgp);
3981 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3982 return CMD_SUCCESS;
3983 }
3984
3985 /* "bgp network import-check" configuration. */
3986 DEFUN (bgp_network_import_check,
3987 bgp_network_import_check_cmd,
3988 "bgp network import-check",
3989 BGP_STR
3990 "BGP network command\n"
3991 "Check BGP network route exists in IGP\n")
3992 {
3993 VTY_DECLVAR_CONTEXT(bgp, bgp);
3994 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3995 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3996 bgp_static_redo_import_check(bgp);
3997 }
3998
3999 return CMD_SUCCESS;
4000 }
4001
4002 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4003 "bgp network import-check exact",
4004 BGP_STR
4005 "BGP network command\n"
4006 "Check BGP network route exists in IGP\n"
4007 "Match route precisely\n")
4008
4009 DEFUN (no_bgp_network_import_check,
4010 no_bgp_network_import_check_cmd,
4011 "no bgp network import-check",
4012 NO_STR
4013 BGP_STR
4014 "BGP network command\n"
4015 "Check BGP network route exists in IGP\n")
4016 {
4017 VTY_DECLVAR_CONTEXT(bgp, bgp);
4018 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4019 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4020 bgp_static_redo_import_check(bgp);
4021 }
4022
4023 return CMD_SUCCESS;
4024 }
4025
4026 DEFUN (bgp_default_local_preference,
4027 bgp_default_local_preference_cmd,
4028 "bgp default local-preference (0-4294967295)",
4029 BGP_STR
4030 "Configure BGP defaults\n"
4031 "local preference (higher=more preferred)\n"
4032 "Configure default local preference value\n")
4033 {
4034 VTY_DECLVAR_CONTEXT(bgp, bgp);
4035 int idx_number = 3;
4036 uint32_t local_pref;
4037
4038 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4039
4040 bgp_default_local_preference_set(bgp, local_pref);
4041 bgp_clear_star_soft_in(vty, bgp->name);
4042
4043 return CMD_SUCCESS;
4044 }
4045
4046 DEFUN (no_bgp_default_local_preference,
4047 no_bgp_default_local_preference_cmd,
4048 "no bgp default local-preference [(0-4294967295)]",
4049 NO_STR
4050 BGP_STR
4051 "Configure BGP defaults\n"
4052 "local preference (higher=more preferred)\n"
4053 "Configure default local preference value\n")
4054 {
4055 VTY_DECLVAR_CONTEXT(bgp, bgp);
4056 bgp_default_local_preference_unset(bgp);
4057 bgp_clear_star_soft_in(vty, bgp->name);
4058
4059 return CMD_SUCCESS;
4060 }
4061
4062
4063 DEFUN (bgp_default_subgroup_pkt_queue_max,
4064 bgp_default_subgroup_pkt_queue_max_cmd,
4065 "bgp default subgroup-pkt-queue-max (20-100)",
4066 BGP_STR
4067 "Configure BGP defaults\n"
4068 "subgroup-pkt-queue-max\n"
4069 "Configure subgroup packet queue max\n")
4070 {
4071 VTY_DECLVAR_CONTEXT(bgp, bgp);
4072 int idx_number = 3;
4073 uint32_t max_size;
4074
4075 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4076
4077 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4078
4079 return CMD_SUCCESS;
4080 }
4081
4082 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4083 no_bgp_default_subgroup_pkt_queue_max_cmd,
4084 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4085 NO_STR
4086 BGP_STR
4087 "Configure BGP defaults\n"
4088 "subgroup-pkt-queue-max\n"
4089 "Configure subgroup packet queue max\n")
4090 {
4091 VTY_DECLVAR_CONTEXT(bgp, bgp);
4092 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4093 return CMD_SUCCESS;
4094 }
4095
4096
4097 DEFUN (bgp_rr_allow_outbound_policy,
4098 bgp_rr_allow_outbound_policy_cmd,
4099 "bgp route-reflector allow-outbound-policy",
4100 BGP_STR
4101 "Allow modifications made by out route-map\n"
4102 "on ibgp neighbors\n")
4103 {
4104 VTY_DECLVAR_CONTEXT(bgp, bgp);
4105
4106 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4107 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4108 update_group_announce_rrclients(bgp);
4109 bgp_clear_star_soft_out(vty, bgp->name);
4110 }
4111
4112 return CMD_SUCCESS;
4113 }
4114
4115 DEFUN (no_bgp_rr_allow_outbound_policy,
4116 no_bgp_rr_allow_outbound_policy_cmd,
4117 "no bgp route-reflector allow-outbound-policy",
4118 NO_STR
4119 BGP_STR
4120 "Allow modifications made by out route-map\n"
4121 "on ibgp neighbors\n")
4122 {
4123 VTY_DECLVAR_CONTEXT(bgp, bgp);
4124
4125 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4126 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4127 update_group_announce_rrclients(bgp);
4128 bgp_clear_star_soft_out(vty, bgp->name);
4129 }
4130
4131 return CMD_SUCCESS;
4132 }
4133
4134 DEFUN (bgp_listen_limit,
4135 bgp_listen_limit_cmd,
4136 "bgp listen limit (1-65535)",
4137 BGP_STR
4138 "BGP Dynamic Neighbors listen commands\n"
4139 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4140 "Configure Dynamic Neighbors listen limit value\n")
4141 {
4142 VTY_DECLVAR_CONTEXT(bgp, bgp);
4143 int idx_number = 3;
4144 int listen_limit;
4145
4146 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4147
4148 bgp_listen_limit_set(bgp, listen_limit);
4149
4150 return CMD_SUCCESS;
4151 }
4152
4153 DEFUN (no_bgp_listen_limit,
4154 no_bgp_listen_limit_cmd,
4155 "no bgp listen limit [(1-65535)]",
4156 NO_STR
4157 BGP_STR
4158 "BGP Dynamic Neighbors listen commands\n"
4159 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4160 "Configure Dynamic Neighbors listen limit value\n")
4161 {
4162 VTY_DECLVAR_CONTEXT(bgp, bgp);
4163 bgp_listen_limit_unset(bgp);
4164 return CMD_SUCCESS;
4165 }
4166
4167
4168 /*
4169 * Check if this listen range is already configured. Check for exact
4170 * match or overlap based on input.
4171 */
4172 static struct peer_group *listen_range_exists(struct bgp *bgp,
4173 struct prefix *range, int exact)
4174 {
4175 struct listnode *node, *nnode;
4176 struct listnode *node1, *nnode1;
4177 struct peer_group *group;
4178 struct prefix *lr;
4179 afi_t afi;
4180 int match;
4181
4182 afi = family2afi(range->family);
4183 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4184 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4185 lr)) {
4186 if (exact)
4187 match = prefix_same(range, lr);
4188 else
4189 match = (prefix_match(range, lr)
4190 || prefix_match(lr, range));
4191 if (match)
4192 return group;
4193 }
4194 }
4195
4196 return NULL;
4197 }
4198
4199 DEFUN (bgp_listen_range,
4200 bgp_listen_range_cmd,
4201 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4202 BGP_STR
4203 "Configure BGP dynamic neighbors listen range\n"
4204 "Configure BGP dynamic neighbors listen range\n"
4205 NEIGHBOR_ADDR_STR
4206 "Member of the peer-group\n"
4207 "Peer-group name\n")
4208 {
4209 VTY_DECLVAR_CONTEXT(bgp, bgp);
4210 struct prefix range;
4211 struct peer_group *group, *existing_group;
4212 afi_t afi;
4213 int ret;
4214 int idx = 0;
4215
4216 argv_find(argv, argc, "A.B.C.D/M", &idx);
4217 argv_find(argv, argc, "X:X::X:X/M", &idx);
4218 char *prefix = argv[idx]->arg;
4219 argv_find(argv, argc, "PGNAME", &idx);
4220 char *peergroup = argv[idx]->arg;
4221
4222 /* Convert IP prefix string to struct prefix. */
4223 ret = str2prefix(prefix, &range);
4224 if (!ret) {
4225 vty_out(vty, "%% Malformed listen range\n");
4226 return CMD_WARNING_CONFIG_FAILED;
4227 }
4228
4229 afi = family2afi(range.family);
4230
4231 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4232 vty_out(vty,
4233 "%% Malformed listen range (link-local address)\n");
4234 return CMD_WARNING_CONFIG_FAILED;
4235 }
4236
4237 apply_mask(&range);
4238
4239 /* Check if same listen range is already configured. */
4240 existing_group = listen_range_exists(bgp, &range, 1);
4241 if (existing_group) {
4242 if (strcmp(existing_group->name, peergroup) == 0)
4243 return CMD_SUCCESS;
4244 else {
4245 vty_out(vty,
4246 "%% Same listen range is attached to peer-group %s\n",
4247 existing_group->name);
4248 return CMD_WARNING_CONFIG_FAILED;
4249 }
4250 }
4251
4252 /* Check if an overlapping listen range exists. */
4253 if (listen_range_exists(bgp, &range, 0)) {
4254 vty_out(vty,
4255 "%% Listen range overlaps with existing listen range\n");
4256 return CMD_WARNING_CONFIG_FAILED;
4257 }
4258
4259 group = peer_group_lookup(bgp, peergroup);
4260 if (!group) {
4261 vty_out(vty, "%% Configure the peer-group first\n");
4262 return CMD_WARNING_CONFIG_FAILED;
4263 }
4264
4265 ret = peer_group_listen_range_add(group, &range);
4266 return bgp_vty_return(vty, ret);
4267 }
4268
4269 DEFUN (no_bgp_listen_range,
4270 no_bgp_listen_range_cmd,
4271 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4272 NO_STR
4273 BGP_STR
4274 "Unconfigure BGP dynamic neighbors listen range\n"
4275 "Unconfigure BGP dynamic neighbors listen range\n"
4276 NEIGHBOR_ADDR_STR
4277 "Member of the peer-group\n"
4278 "Peer-group name\n")
4279 {
4280 VTY_DECLVAR_CONTEXT(bgp, bgp);
4281 struct prefix range;
4282 struct peer_group *group;
4283 afi_t afi;
4284 int ret;
4285 int idx = 0;
4286
4287 argv_find(argv, argc, "A.B.C.D/M", &idx);
4288 argv_find(argv, argc, "X:X::X:X/M", &idx);
4289 char *prefix = argv[idx]->arg;
4290 argv_find(argv, argc, "PGNAME", &idx);
4291 char *peergroup = argv[idx]->arg;
4292
4293 /* Convert IP prefix string to struct prefix. */
4294 ret = str2prefix(prefix, &range);
4295 if (!ret) {
4296 vty_out(vty, "%% Malformed listen range\n");
4297 return CMD_WARNING_CONFIG_FAILED;
4298 }
4299
4300 afi = family2afi(range.family);
4301
4302 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4303 vty_out(vty,
4304 "%% Malformed listen range (link-local address)\n");
4305 return CMD_WARNING_CONFIG_FAILED;
4306 }
4307
4308 apply_mask(&range);
4309
4310 group = peer_group_lookup(bgp, peergroup);
4311 if (!group) {
4312 vty_out(vty, "%% Peer-group does not exist\n");
4313 return CMD_WARNING_CONFIG_FAILED;
4314 }
4315
4316 ret = peer_group_listen_range_del(group, &range);
4317 return bgp_vty_return(vty, ret);
4318 }
4319
4320 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4321 {
4322 struct peer_group *group;
4323 struct listnode *node, *nnode, *rnode, *nrnode;
4324 struct prefix *range;
4325 afi_t afi;
4326
4327 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4328 vty_out(vty, " bgp listen limit %d\n",
4329 bgp->dynamic_neighbors_limit);
4330
4331 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4332 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4333 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4334 nrnode, range)) {
4335 vty_out(vty,
4336 " bgp listen range %pFX peer-group %s\n",
4337 range, group->name);
4338 }
4339 }
4340 }
4341 }
4342
4343
4344 DEFUN (bgp_disable_connected_route_check,
4345 bgp_disable_connected_route_check_cmd,
4346 "bgp disable-ebgp-connected-route-check",
4347 BGP_STR
4348 "Disable checking if nexthop is connected on ebgp sessions\n")
4349 {
4350 VTY_DECLVAR_CONTEXT(bgp, bgp);
4351 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4352 bgp_clear_star_soft_in(vty, bgp->name);
4353
4354 return CMD_SUCCESS;
4355 }
4356
4357 DEFUN (no_bgp_disable_connected_route_check,
4358 no_bgp_disable_connected_route_check_cmd,
4359 "no bgp disable-ebgp-connected-route-check",
4360 NO_STR
4361 BGP_STR
4362 "Disable checking if nexthop is connected on ebgp sessions\n")
4363 {
4364 VTY_DECLVAR_CONTEXT(bgp, bgp);
4365 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4366 bgp_clear_star_soft_in(vty, bgp->name);
4367
4368 return CMD_SUCCESS;
4369 }
4370
4371
4372 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4373 const char *as_str)
4374 {
4375 VTY_DECLVAR_CONTEXT(bgp, bgp);
4376 int ret;
4377 as_t as;
4378 int as_type = AS_SPECIFIED;
4379 union sockunion su;
4380
4381 if (as_str[0] == 'i') {
4382 as = 0;
4383 as_type = AS_INTERNAL;
4384 } else if (as_str[0] == 'e') {
4385 as = 0;
4386 as_type = AS_EXTERNAL;
4387 } else {
4388 /* Get AS number. */
4389 as = strtoul(as_str, NULL, 10);
4390 }
4391
4392 /* If peer is peer group or interface peer, call proper function. */
4393 ret = str2sockunion(peer_str, &su);
4394 if (ret < 0) {
4395 struct peer *peer;
4396
4397 /* Check if existing interface peer */
4398 peer = peer_lookup_by_conf_if(bgp, peer_str);
4399
4400 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4401
4402 /* if not interface peer, check peer-group settings */
4403 if (ret < 0 && !peer) {
4404 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4405 if (ret < 0) {
4406 vty_out(vty,
4407 "%% Create the peer-group or interface first\n");
4408 return CMD_WARNING_CONFIG_FAILED;
4409 }
4410 return CMD_SUCCESS;
4411 }
4412 } else {
4413 if (peer_address_self_check(bgp, &su)) {
4414 vty_out(vty,
4415 "%% Can not configure the local system as neighbor\n");
4416 return CMD_WARNING_CONFIG_FAILED;
4417 }
4418 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4419 }
4420
4421 return bgp_vty_return(vty, ret);
4422 }
4423
4424 DEFUN (bgp_default_shutdown,
4425 bgp_default_shutdown_cmd,
4426 "[no] bgp default shutdown",
4427 NO_STR
4428 BGP_STR
4429 "Configure BGP defaults\n"
4430 "Apply administrative shutdown to newly configured peers\n")
4431 {
4432 VTY_DECLVAR_CONTEXT(bgp, bgp);
4433 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4434 return CMD_SUCCESS;
4435 }
4436
4437 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4438 BGP_STR
4439 "Administrative shutdown of the BGP instance\n"
4440 "Add a shutdown message (RFC 8203)\n"
4441 "Shutdown message\n")
4442 {
4443 char *msgstr = NULL;
4444
4445 VTY_DECLVAR_CONTEXT(bgp, bgp);
4446
4447 if (argc > 3)
4448 msgstr = argv_concat(argv, argc, 3);
4449
4450 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4451 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4452 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4453 return CMD_WARNING_CONFIG_FAILED;
4454 }
4455
4456 bgp_shutdown_enable(bgp, msgstr);
4457 XFREE(MTYPE_TMP, msgstr);
4458
4459 return CMD_SUCCESS;
4460 }
4461
4462 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4463 BGP_STR "Administrative shutdown of the BGP instance\n")
4464 {
4465 VTY_DECLVAR_CONTEXT(bgp, bgp);
4466
4467 bgp_shutdown_enable(bgp, NULL);
4468
4469 return CMD_SUCCESS;
4470 }
4471
4472 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4473 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4474 {
4475 VTY_DECLVAR_CONTEXT(bgp, bgp);
4476
4477 bgp_shutdown_disable(bgp);
4478
4479 return CMD_SUCCESS;
4480 }
4481
4482 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4483 "no bgp shutdown message MSG...", NO_STR BGP_STR
4484 "Administrative shutdown of the BGP instance\n"
4485 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4486
4487 DEFUN (neighbor_remote_as,
4488 neighbor_remote_as_cmd,
4489 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4490 NEIGHBOR_STR
4491 NEIGHBOR_ADDR_STR2
4492 "Specify a BGP neighbor\n"
4493 AS_STR
4494 "Internal BGP peer\n"
4495 "External BGP peer\n")
4496 {
4497 int idx_peer = 1;
4498 int idx_remote_as = 3;
4499 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4500 argv[idx_remote_as]->arg);
4501 }
4502
4503 DEFPY (bgp_allow_martian,
4504 bgp_allow_martian_cmd,
4505 "[no]$no bgp allow-martian-nexthop",
4506 NO_STR
4507 BGP_STR
4508 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4509 {
4510 VTY_DECLVAR_CONTEXT(bgp, bgp);
4511
4512 if (no)
4513 bgp->allow_martian = false;
4514 else
4515 bgp->allow_martian = true;
4516
4517 return CMD_SUCCESS;
4518 }
4519
4520 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4521 * sessions do not wait for hold timer expiry to bring down the sessions
4522 * when nexthop becomes unreachable
4523 */
4524 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4525 BGP_STR "Fast convergence for bgp sessions\n")
4526 {
4527 VTY_DECLVAR_CONTEXT(bgp, bgp);
4528 bgp->fast_convergence = true;
4529
4530 return CMD_SUCCESS;
4531 }
4532
4533 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4534 "no bgp fast-convergence",
4535 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4536 {
4537 VTY_DECLVAR_CONTEXT(bgp, bgp);
4538 bgp->fast_convergence = false;
4539
4540 return CMD_SUCCESS;
4541 }
4542
4543 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4544 int v6only,
4545 const char *peer_group_name,
4546 const char *as_str)
4547 {
4548 VTY_DECLVAR_CONTEXT(bgp, bgp);
4549 as_t as = 0;
4550 int as_type = AS_UNSPECIFIED;
4551 struct peer *peer;
4552 struct peer_group *group;
4553 int ret = 0;
4554
4555 group = peer_group_lookup(bgp, conf_if);
4556
4557 if (group) {
4558 vty_out(vty, "%% Name conflict with peer-group \n");
4559 return CMD_WARNING_CONFIG_FAILED;
4560 }
4561
4562 if (as_str) {
4563 if (as_str[0] == 'i') {
4564 as_type = AS_INTERNAL;
4565 } else if (as_str[0] == 'e') {
4566 as_type = AS_EXTERNAL;
4567 } else {
4568 /* Get AS number. */
4569 as = strtoul(as_str, NULL, 10);
4570 as_type = AS_SPECIFIED;
4571 }
4572 }
4573
4574 peer = peer_lookup_by_conf_if(bgp, conf_if);
4575 if (peer) {
4576 if (as_str)
4577 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4578 } else {
4579 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4580 NULL);
4581
4582 if (!peer) {
4583 vty_out(vty, "%% BGP failed to create peer\n");
4584 return CMD_WARNING_CONFIG_FAILED;
4585 }
4586
4587 if (v6only)
4588 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4589
4590 /* Request zebra to initiate IPv6 RAs on this interface. We do
4591 * this
4592 * any unnumbered peer in order to not worry about run-time
4593 * transitions
4594 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4595 * address
4596 * gets deleted later etc.)
4597 */
4598 if (peer->ifp)
4599 bgp_zebra_initiate_radv(bgp, peer);
4600 }
4601
4602 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4603 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4604 if (v6only)
4605 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4606 else
4607 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4608
4609 /* v6only flag changed. Reset bgp seesion */
4610 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4611 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4612 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4613 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4614 } else
4615 bgp_session_reset(peer);
4616 }
4617
4618 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4619 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4620 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4621 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4622 }
4623
4624 if (peer_group_name) {
4625 group = peer_group_lookup(bgp, peer_group_name);
4626 if (!group) {
4627 vty_out(vty, "%% Configure the peer-group first\n");
4628 return CMD_WARNING_CONFIG_FAILED;
4629 }
4630
4631 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4632 }
4633
4634 return bgp_vty_return(vty, ret);
4635 }
4636
4637 DEFUN (neighbor_interface_config,
4638 neighbor_interface_config_cmd,
4639 "neighbor WORD interface [peer-group PGNAME]",
4640 NEIGHBOR_STR
4641 "Interface name or neighbor tag\n"
4642 "Enable BGP on interface\n"
4643 "Member of the peer-group\n"
4644 "Peer-group name\n")
4645 {
4646 int idx_word = 1;
4647 int idx_peer_group_word = 4;
4648
4649 if (argc > idx_peer_group_word)
4650 return peer_conf_interface_get(
4651 vty, argv[idx_word]->arg, 0,
4652 argv[idx_peer_group_word]->arg, NULL);
4653 else
4654 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4655 NULL, NULL);
4656 }
4657
4658 DEFUN (neighbor_interface_config_v6only,
4659 neighbor_interface_config_v6only_cmd,
4660 "neighbor WORD interface v6only [peer-group PGNAME]",
4661 NEIGHBOR_STR
4662 "Interface name or neighbor tag\n"
4663 "Enable BGP on interface\n"
4664 "Enable BGP with v6 link-local only\n"
4665 "Member of the peer-group\n"
4666 "Peer-group name\n")
4667 {
4668 int idx_word = 1;
4669 int idx_peer_group_word = 5;
4670
4671 if (argc > idx_peer_group_word)
4672 return peer_conf_interface_get(
4673 vty, argv[idx_word]->arg, 1,
4674 argv[idx_peer_group_word]->arg, NULL);
4675
4676 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4677 }
4678
4679
4680 DEFUN (neighbor_interface_config_remote_as,
4681 neighbor_interface_config_remote_as_cmd,
4682 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4683 NEIGHBOR_STR
4684 "Interface name or neighbor tag\n"
4685 "Enable BGP on interface\n"
4686 "Specify a BGP neighbor\n"
4687 AS_STR
4688 "Internal BGP peer\n"
4689 "External BGP peer\n")
4690 {
4691 int idx_word = 1;
4692 int idx_remote_as = 4;
4693 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4694 argv[idx_remote_as]->arg);
4695 }
4696
4697 DEFUN (neighbor_interface_v6only_config_remote_as,
4698 neighbor_interface_v6only_config_remote_as_cmd,
4699 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4700 NEIGHBOR_STR
4701 "Interface name or neighbor tag\n"
4702 "Enable BGP with v6 link-local only\n"
4703 "Enable BGP on interface\n"
4704 "Specify a BGP neighbor\n"
4705 AS_STR
4706 "Internal BGP peer\n"
4707 "External BGP peer\n")
4708 {
4709 int idx_word = 1;
4710 int idx_remote_as = 5;
4711 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4712 argv[idx_remote_as]->arg);
4713 }
4714
4715 DEFUN (neighbor_peer_group,
4716 neighbor_peer_group_cmd,
4717 "neighbor WORD peer-group",
4718 NEIGHBOR_STR
4719 "Interface name or neighbor tag\n"
4720 "Configure peer-group\n")
4721 {
4722 VTY_DECLVAR_CONTEXT(bgp, bgp);
4723 int idx_word = 1;
4724 struct peer *peer;
4725 struct peer_group *group;
4726
4727 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4728 if (peer) {
4729 vty_out(vty, "%% Name conflict with interface: \n");
4730 return CMD_WARNING_CONFIG_FAILED;
4731 }
4732
4733 group = peer_group_get(bgp, argv[idx_word]->arg);
4734 if (!group) {
4735 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4736 return CMD_WARNING_CONFIG_FAILED;
4737 }
4738
4739 return CMD_SUCCESS;
4740 }
4741
4742 DEFUN (no_neighbor,
4743 no_neighbor_cmd,
4744 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4745 NO_STR
4746 NEIGHBOR_STR
4747 NEIGHBOR_ADDR_STR2
4748 "Specify a BGP neighbor\n"
4749 AS_STR
4750 "Internal BGP peer\n"
4751 "External BGP peer\n")
4752 {
4753 VTY_DECLVAR_CONTEXT(bgp, bgp);
4754 int idx_peer = 2;
4755 int ret;
4756 union sockunion su;
4757 struct peer_group *group;
4758 struct peer *peer;
4759 struct peer *other;
4760
4761 ret = str2sockunion(argv[idx_peer]->arg, &su);
4762 if (ret < 0) {
4763 /* look up for neighbor by interface name config. */
4764 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4765 if (peer) {
4766 /* Request zebra to terminate IPv6 RAs on this
4767 * interface. */
4768 if (peer->ifp)
4769 bgp_zebra_terminate_radv(peer->bgp, peer);
4770 peer_notify_unconfig(peer);
4771 peer_delete(peer);
4772 return CMD_SUCCESS;
4773 }
4774
4775 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4776 if (group) {
4777 peer_group_notify_unconfig(group);
4778 peer_group_delete(group);
4779 } else {
4780 vty_out(vty, "%% Create the peer-group first\n");
4781 return CMD_WARNING_CONFIG_FAILED;
4782 }
4783 } else {
4784 peer = peer_lookup(bgp, &su);
4785 if (peer) {
4786 if (peer_dynamic_neighbor(peer)) {
4787 vty_out(vty,
4788 "%% Operation not allowed on a dynamic neighbor\n");
4789 return CMD_WARNING_CONFIG_FAILED;
4790 }
4791
4792 other = peer->doppelganger;
4793
4794 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4795 bgp_zebra_terminate_radv(peer->bgp, peer);
4796
4797 peer_notify_unconfig(peer);
4798 peer_delete(peer);
4799 if (other && other->status != Deleted) {
4800 peer_notify_unconfig(other);
4801 peer_delete(other);
4802 }
4803 }
4804 }
4805
4806 return CMD_SUCCESS;
4807 }
4808
4809 DEFUN (no_neighbor_interface_config,
4810 no_neighbor_interface_config_cmd,
4811 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4812 NO_STR
4813 NEIGHBOR_STR
4814 "Interface name\n"
4815 "Configure BGP on interface\n"
4816 "Enable BGP with v6 link-local only\n"
4817 "Member of the peer-group\n"
4818 "Peer-group name\n"
4819 "Specify a BGP neighbor\n"
4820 AS_STR
4821 "Internal BGP peer\n"
4822 "External BGP peer\n")
4823 {
4824 VTY_DECLVAR_CONTEXT(bgp, bgp);
4825 int idx_word = 2;
4826 struct peer *peer;
4827
4828 /* look up for neighbor by interface name config. */
4829 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4830 if (peer) {
4831 /* Request zebra to terminate IPv6 RAs on this interface. */
4832 if (peer->ifp)
4833 bgp_zebra_terminate_radv(peer->bgp, peer);
4834 peer_notify_unconfig(peer);
4835 peer_delete(peer);
4836 } else {
4837 vty_out(vty, "%% Create the bgp interface first\n");
4838 return CMD_WARNING_CONFIG_FAILED;
4839 }
4840 return CMD_SUCCESS;
4841 }
4842
4843 DEFUN (no_neighbor_peer_group,
4844 no_neighbor_peer_group_cmd,
4845 "no neighbor WORD peer-group",
4846 NO_STR
4847 NEIGHBOR_STR
4848 "Neighbor tag\n"
4849 "Configure peer-group\n")
4850 {
4851 VTY_DECLVAR_CONTEXT(bgp, bgp);
4852 int idx_word = 2;
4853 struct peer_group *group;
4854
4855 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4856 if (group) {
4857 peer_group_notify_unconfig(group);
4858 peer_group_delete(group);
4859 } else {
4860 vty_out(vty, "%% Create the peer-group first\n");
4861 return CMD_WARNING_CONFIG_FAILED;
4862 }
4863 return CMD_SUCCESS;
4864 }
4865
4866 DEFUN (no_neighbor_interface_peer_group_remote_as,
4867 no_neighbor_interface_peer_group_remote_as_cmd,
4868 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4869 NO_STR
4870 NEIGHBOR_STR
4871 "Interface name or neighbor tag\n"
4872 "Specify a BGP neighbor\n"
4873 AS_STR
4874 "Internal BGP peer\n"
4875 "External BGP peer\n")
4876 {
4877 VTY_DECLVAR_CONTEXT(bgp, bgp);
4878 int idx_word = 2;
4879 struct peer_group *group;
4880 struct peer *peer;
4881
4882 /* look up for neighbor by interface name config. */
4883 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4884 if (peer) {
4885 peer_as_change(peer, 0, AS_UNSPECIFIED);
4886 return CMD_SUCCESS;
4887 }
4888
4889 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4890 if (group)
4891 peer_group_remote_as_delete(group);
4892 else {
4893 vty_out(vty, "%% Create the peer-group or interface first\n");
4894 return CMD_WARNING_CONFIG_FAILED;
4895 }
4896 return CMD_SUCCESS;
4897 }
4898
4899 DEFUN (neighbor_local_as,
4900 neighbor_local_as_cmd,
4901 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4902 NEIGHBOR_STR
4903 NEIGHBOR_ADDR_STR2
4904 "Specify a local-as number\n"
4905 "AS number used as local AS\n")
4906 {
4907 int idx_peer = 1;
4908 int idx_number = 3;
4909 struct peer *peer;
4910 int ret;
4911 as_t as;
4912
4913 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4914 if (!peer)
4915 return CMD_WARNING_CONFIG_FAILED;
4916
4917 as = strtoul(argv[idx_number]->arg, NULL, 10);
4918 ret = peer_local_as_set(peer, as, 0, 0);
4919 return bgp_vty_return(vty, ret);
4920 }
4921
4922 DEFUN (neighbor_local_as_no_prepend,
4923 neighbor_local_as_no_prepend_cmd,
4924 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4925 NEIGHBOR_STR
4926 NEIGHBOR_ADDR_STR2
4927 "Specify a local-as number\n"
4928 "AS number used as local AS\n"
4929 "Do not prepend local-as to updates from ebgp peers\n")
4930 {
4931 int idx_peer = 1;
4932 int idx_number = 3;
4933 struct peer *peer;
4934 int ret;
4935 as_t as;
4936
4937 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4938 if (!peer)
4939 return CMD_WARNING_CONFIG_FAILED;
4940
4941 as = strtoul(argv[idx_number]->arg, NULL, 10);
4942 ret = peer_local_as_set(peer, as, 1, 0);
4943 return bgp_vty_return(vty, ret);
4944 }
4945
4946 DEFUN (neighbor_local_as_no_prepend_replace_as,
4947 neighbor_local_as_no_prepend_replace_as_cmd,
4948 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4949 NEIGHBOR_STR
4950 NEIGHBOR_ADDR_STR2
4951 "Specify a local-as number\n"
4952 "AS number used as local AS\n"
4953 "Do not prepend local-as to updates from ebgp peers\n"
4954 "Do not prepend local-as to updates from ibgp peers\n")
4955 {
4956 int idx_peer = 1;
4957 int idx_number = 3;
4958 struct peer *peer;
4959 int ret;
4960 as_t as;
4961
4962 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4963 if (!peer)
4964 return CMD_WARNING_CONFIG_FAILED;
4965
4966 as = strtoul(argv[idx_number]->arg, NULL, 10);
4967 ret = peer_local_as_set(peer, as, 1, 1);
4968 return bgp_vty_return(vty, ret);
4969 }
4970
4971 DEFUN (no_neighbor_local_as,
4972 no_neighbor_local_as_cmd,
4973 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4974 NO_STR
4975 NEIGHBOR_STR
4976 NEIGHBOR_ADDR_STR2
4977 "Specify a local-as number\n"
4978 "AS number used as local AS\n"
4979 "Do not prepend local-as to updates from ebgp peers\n"
4980 "Do not prepend local-as to updates from ibgp peers\n")
4981 {
4982 int idx_peer = 2;
4983 struct peer *peer;
4984 int ret;
4985
4986 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4987 if (!peer)
4988 return CMD_WARNING_CONFIG_FAILED;
4989
4990 ret = peer_local_as_unset(peer);
4991 return bgp_vty_return(vty, ret);
4992 }
4993
4994
4995 DEFUN (neighbor_solo,
4996 neighbor_solo_cmd,
4997 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4998 NEIGHBOR_STR
4999 NEIGHBOR_ADDR_STR2
5000 "Solo peer - part of its own update group\n")
5001 {
5002 int idx_peer = 1;
5003 struct peer *peer;
5004 int ret;
5005
5006 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5007 if (!peer)
5008 return CMD_WARNING_CONFIG_FAILED;
5009
5010 ret = update_group_adjust_soloness(peer, 1);
5011 return bgp_vty_return(vty, ret);
5012 }
5013
5014 DEFUN (no_neighbor_solo,
5015 no_neighbor_solo_cmd,
5016 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5017 NO_STR
5018 NEIGHBOR_STR
5019 NEIGHBOR_ADDR_STR2
5020 "Solo peer - part of its own update group\n")
5021 {
5022 int idx_peer = 2;
5023 struct peer *peer;
5024 int ret;
5025
5026 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5027 if (!peer)
5028 return CMD_WARNING_CONFIG_FAILED;
5029
5030 ret = update_group_adjust_soloness(peer, 0);
5031 return bgp_vty_return(vty, ret);
5032 }
5033
5034 DEFUN (neighbor_password,
5035 neighbor_password_cmd,
5036 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5037 NEIGHBOR_STR
5038 NEIGHBOR_ADDR_STR2
5039 "Set a password\n"
5040 "The password\n")
5041 {
5042 int idx_peer = 1;
5043 int idx_line = 3;
5044 struct peer *peer;
5045 int ret;
5046
5047 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5048 if (!peer)
5049 return CMD_WARNING_CONFIG_FAILED;
5050
5051 ret = peer_password_set(peer, argv[idx_line]->arg);
5052 return bgp_vty_return(vty, ret);
5053 }
5054
5055 DEFUN (no_neighbor_password,
5056 no_neighbor_password_cmd,
5057 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5058 NO_STR
5059 NEIGHBOR_STR
5060 NEIGHBOR_ADDR_STR2
5061 "Set a password\n"
5062 "The password\n")
5063 {
5064 int idx_peer = 2;
5065 struct peer *peer;
5066 int ret;
5067
5068 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5069 if (!peer)
5070 return CMD_WARNING_CONFIG_FAILED;
5071
5072 ret = peer_password_unset(peer);
5073 return bgp_vty_return(vty, ret);
5074 }
5075
5076 DEFUN (neighbor_activate,
5077 neighbor_activate_cmd,
5078 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5079 NEIGHBOR_STR
5080 NEIGHBOR_ADDR_STR2
5081 "Enable the Address Family for this Neighbor\n")
5082 {
5083 int idx_peer = 1;
5084 int ret;
5085 struct peer *peer;
5086
5087 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5088 if (!peer)
5089 return CMD_WARNING_CONFIG_FAILED;
5090
5091 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5092 return bgp_vty_return(vty, ret);
5093 }
5094
5095 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5096 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5097 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5098 "Enable the Address Family for this Neighbor\n")
5099
5100 DEFUN (no_neighbor_activate,
5101 no_neighbor_activate_cmd,
5102 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5103 NO_STR
5104 NEIGHBOR_STR
5105 NEIGHBOR_ADDR_STR2
5106 "Enable the Address Family for this Neighbor\n")
5107 {
5108 int idx_peer = 2;
5109 int ret;
5110 struct peer *peer;
5111
5112 /* Lookup peer. */
5113 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5114 if (!peer)
5115 return CMD_WARNING_CONFIG_FAILED;
5116
5117 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5118 return bgp_vty_return(vty, ret);
5119 }
5120
5121 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5122 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5123 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5124 "Enable the Address Family for this Neighbor\n")
5125
5126 DEFUN (neighbor_set_peer_group,
5127 neighbor_set_peer_group_cmd,
5128 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5129 NEIGHBOR_STR
5130 NEIGHBOR_ADDR_STR2
5131 "Member of the peer-group\n"
5132 "Peer-group name\n")
5133 {
5134 VTY_DECLVAR_CONTEXT(bgp, bgp);
5135 int idx_peer = 1;
5136 int idx_word = 3;
5137 int ret;
5138 as_t as;
5139 union sockunion su;
5140 struct peer *peer;
5141 struct peer_group *group;
5142
5143 ret = str2sockunion(argv[idx_peer]->arg, &su);
5144 if (ret < 0) {
5145 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5146 if (!peer) {
5147 vty_out(vty, "%% Malformed address or name: %s\n",
5148 argv[idx_peer]->arg);
5149 return CMD_WARNING_CONFIG_FAILED;
5150 }
5151 } else {
5152 if (peer_address_self_check(bgp, &su)) {
5153 vty_out(vty,
5154 "%% Can not configure the local system as neighbor\n");
5155 return CMD_WARNING_CONFIG_FAILED;
5156 }
5157
5158 /* Disallow for dynamic neighbor. */
5159 peer = peer_lookup(bgp, &su);
5160 if (peer && peer_dynamic_neighbor(peer)) {
5161 vty_out(vty,
5162 "%% Operation not allowed on a dynamic neighbor\n");
5163 return CMD_WARNING_CONFIG_FAILED;
5164 }
5165 }
5166
5167 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5168 if (!group) {
5169 vty_out(vty, "%% Configure the peer-group first\n");
5170 return CMD_WARNING_CONFIG_FAILED;
5171 }
5172
5173 ret = peer_group_bind(bgp, &su, peer, group, &as);
5174
5175 return bgp_vty_return(vty, ret);
5176 }
5177
5178 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5179 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5180 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5181 "Member of the peer-group\n"
5182 "Peer-group name\n")
5183
5184 DEFUN (no_neighbor_set_peer_group,
5185 no_neighbor_set_peer_group_cmd,
5186 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5187 NO_STR
5188 NEIGHBOR_STR
5189 NEIGHBOR_ADDR_STR2
5190 "Member of the peer-group\n"
5191 "Peer-group name\n")
5192 {
5193 VTY_DECLVAR_CONTEXT(bgp, bgp);
5194 int idx_peer = 2;
5195 int idx_word = 4;
5196 int ret;
5197 struct peer *peer;
5198 struct peer_group *group;
5199
5200 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5201 if (!peer)
5202 return CMD_WARNING_CONFIG_FAILED;
5203
5204 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5205 if (!group) {
5206 vty_out(vty, "%% Configure the peer-group first\n");
5207 return CMD_WARNING_CONFIG_FAILED;
5208 }
5209
5210 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5211 bgp_zebra_terminate_radv(peer->bgp, peer);
5212
5213 peer_notify_unconfig(peer);
5214 ret = peer_delete(peer);
5215
5216 return bgp_vty_return(vty, ret);
5217 }
5218
5219 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5220 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5221 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5222 "Member of the peer-group\n"
5223 "Peer-group name\n")
5224
5225 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5226 uint64_t flag, int set)
5227 {
5228 int ret;
5229 struct peer *peer;
5230
5231 peer = peer_and_group_lookup_vty(vty, ip_str);
5232 if (!peer)
5233 return CMD_WARNING_CONFIG_FAILED;
5234
5235 /*
5236 * If 'neighbor <interface>', then this is for directly connected peers,
5237 * we should not accept disable-connected-check.
5238 */
5239 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5240 vty_out(vty,
5241 "%s is directly connected peer, cannot accept disable-connected-check\n",
5242 ip_str);
5243 return CMD_WARNING_CONFIG_FAILED;
5244 }
5245
5246 if (!set && flag == PEER_FLAG_SHUTDOWN)
5247 peer_tx_shutdown_message_unset(peer);
5248
5249 if (set)
5250 ret = peer_flag_set(peer, flag);
5251 else
5252 ret = peer_flag_unset(peer, flag);
5253
5254 return bgp_vty_return(vty, ret);
5255 }
5256
5257 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5258 {
5259 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5260 }
5261
5262 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5263 uint64_t flag)
5264 {
5265 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5266 }
5267
5268 /* neighbor passive. */
5269 DEFUN (neighbor_passive,
5270 neighbor_passive_cmd,
5271 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5272 NEIGHBOR_STR
5273 NEIGHBOR_ADDR_STR2
5274 "Don't send open messages to this neighbor\n")
5275 {
5276 int idx_peer = 1;
5277 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5278 }
5279
5280 DEFUN (no_neighbor_passive,
5281 no_neighbor_passive_cmd,
5282 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5283 NO_STR
5284 NEIGHBOR_STR
5285 NEIGHBOR_ADDR_STR2
5286 "Don't send open messages to this neighbor\n")
5287 {
5288 int idx_peer = 2;
5289 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5290 }
5291
5292 /* neighbor shutdown. */
5293 DEFUN (neighbor_shutdown_msg,
5294 neighbor_shutdown_msg_cmd,
5295 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5296 NEIGHBOR_STR
5297 NEIGHBOR_ADDR_STR2
5298 "Administratively shut down this neighbor\n"
5299 "Add a shutdown message (RFC 8203)\n"
5300 "Shutdown message\n")
5301 {
5302 int idx_peer = 1;
5303
5304 if (argc >= 5) {
5305 struct peer *peer =
5306 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5307 char *message;
5308
5309 if (!peer)
5310 return CMD_WARNING_CONFIG_FAILED;
5311 message = argv_concat(argv, argc, 4);
5312 peer_tx_shutdown_message_set(peer, message);
5313 XFREE(MTYPE_TMP, message);
5314 }
5315
5316 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5317 }
5318
5319 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5320 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5321 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5322 "Administratively shut down this neighbor\n")
5323
5324 DEFUN (no_neighbor_shutdown_msg,
5325 no_neighbor_shutdown_msg_cmd,
5326 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5327 NO_STR
5328 NEIGHBOR_STR
5329 NEIGHBOR_ADDR_STR2
5330 "Administratively shut down this neighbor\n"
5331 "Remove a shutdown message (RFC 8203)\n"
5332 "Shutdown message\n")
5333 {
5334 int idx_peer = 2;
5335
5336 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5337 PEER_FLAG_SHUTDOWN);
5338 }
5339
5340 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5341 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5342 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5343 "Administratively shut down this neighbor\n")
5344
5345 DEFUN(neighbor_shutdown_rtt,
5346 neighbor_shutdown_rtt_cmd,
5347 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5348 NEIGHBOR_STR
5349 NEIGHBOR_ADDR_STR2
5350 "Administratively shut down this neighbor\n"
5351 "Shutdown if round-trip-time is higher than expected\n"
5352 "Round-trip-time in milliseconds\n"
5353 "Specify the number of keepalives before shutdown\n"
5354 "The number of keepalives with higher RTT to shutdown\n")
5355 {
5356 int idx_peer = 1;
5357 int idx_rtt = 4;
5358 int idx_count = 0;
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 = strtol(argv[idx_rtt]->arg, NULL, 10);
5367
5368 if (argv_find(argv, argc, "count", &idx_count))
5369 peer->rtt_keepalive_conf =
5370 strtol(argv[idx_count + 1]->arg, NULL, 10);
5371
5372 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5373 PEER_FLAG_RTT_SHUTDOWN);
5374 }
5375
5376 DEFUN(no_neighbor_shutdown_rtt,
5377 no_neighbor_shutdown_rtt_cmd,
5378 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5379 NO_STR
5380 NEIGHBOR_STR
5381 NEIGHBOR_ADDR_STR2
5382 "Administratively shut down this neighbor\n"
5383 "Shutdown if round-trip-time is higher than expected\n"
5384 "Round-trip-time in milliseconds\n"
5385 "Specify the number of keepalives before shutdown\n"
5386 "The number of keepalives with higher RTT to shutdown\n")
5387 {
5388 int idx_peer = 2;
5389 struct peer *peer;
5390
5391 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5392
5393 if (!peer)
5394 return CMD_WARNING_CONFIG_FAILED;
5395
5396 peer->rtt_expected = 0;
5397 peer->rtt_keepalive_conf = 1;
5398
5399 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5400 PEER_FLAG_RTT_SHUTDOWN);
5401 }
5402
5403 /* neighbor capability dynamic. */
5404 DEFUN (neighbor_capability_dynamic,
5405 neighbor_capability_dynamic_cmd,
5406 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5407 NEIGHBOR_STR
5408 NEIGHBOR_ADDR_STR2
5409 "Advertise capability to the peer\n"
5410 "Advertise dynamic capability to this neighbor\n")
5411 {
5412 int idx_peer = 1;
5413 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5414 PEER_FLAG_DYNAMIC_CAPABILITY);
5415 }
5416
5417 DEFUN (no_neighbor_capability_dynamic,
5418 no_neighbor_capability_dynamic_cmd,
5419 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5420 NO_STR
5421 NEIGHBOR_STR
5422 NEIGHBOR_ADDR_STR2
5423 "Advertise capability to the peer\n"
5424 "Advertise dynamic capability to this neighbor\n")
5425 {
5426 int idx_peer = 2;
5427 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5428 PEER_FLAG_DYNAMIC_CAPABILITY);
5429 }
5430
5431 /* neighbor dont-capability-negotiate */
5432 DEFUN (neighbor_dont_capability_negotiate,
5433 neighbor_dont_capability_negotiate_cmd,
5434 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5435 NEIGHBOR_STR
5436 NEIGHBOR_ADDR_STR2
5437 "Do not perform capability negotiation\n")
5438 {
5439 int idx_peer = 1;
5440 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5441 PEER_FLAG_DONT_CAPABILITY);
5442 }
5443
5444 DEFUN (no_neighbor_dont_capability_negotiate,
5445 no_neighbor_dont_capability_negotiate_cmd,
5446 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5447 NO_STR
5448 NEIGHBOR_STR
5449 NEIGHBOR_ADDR_STR2
5450 "Do not perform capability negotiation\n")
5451 {
5452 int idx_peer = 2;
5453 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5454 PEER_FLAG_DONT_CAPABILITY);
5455 }
5456
5457 /* neighbor capability extended next hop encoding */
5458 DEFUN (neighbor_capability_enhe,
5459 neighbor_capability_enhe_cmd,
5460 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5461 NEIGHBOR_STR
5462 NEIGHBOR_ADDR_STR2
5463 "Advertise capability to the peer\n"
5464 "Advertise extended next-hop capability to the peer\n")
5465 {
5466 int idx_peer = 1;
5467 struct peer *peer;
5468
5469 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5470 if (peer && peer->conf_if)
5471 return CMD_SUCCESS;
5472
5473 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5474 PEER_FLAG_CAPABILITY_ENHE);
5475 }
5476
5477 DEFUN (no_neighbor_capability_enhe,
5478 no_neighbor_capability_enhe_cmd,
5479 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5480 NO_STR
5481 NEIGHBOR_STR
5482 NEIGHBOR_ADDR_STR2
5483 "Advertise capability to the peer\n"
5484 "Advertise extended next-hop capability to the peer\n")
5485 {
5486 int idx_peer = 2;
5487 struct peer *peer;
5488
5489 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5490 if (peer && peer->conf_if) {
5491 vty_out(vty,
5492 "Peer %s cannot have capability extended-nexthop turned off\n",
5493 argv[idx_peer]->arg);
5494 return CMD_WARNING_CONFIG_FAILED;
5495 }
5496
5497 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5498 PEER_FLAG_CAPABILITY_ENHE);
5499 }
5500
5501 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5502 afi_t afi, safi_t safi, uint32_t flag,
5503 int set)
5504 {
5505 int ret;
5506 struct peer *peer;
5507
5508 peer = peer_and_group_lookup_vty(vty, peer_str);
5509 if (!peer)
5510 return CMD_WARNING_CONFIG_FAILED;
5511
5512 if (set)
5513 ret = peer_af_flag_set(peer, afi, safi, flag);
5514 else
5515 ret = peer_af_flag_unset(peer, afi, safi, flag);
5516
5517 return bgp_vty_return(vty, ret);
5518 }
5519
5520 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5521 afi_t afi, safi_t safi, uint32_t flag)
5522 {
5523 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5524 }
5525
5526 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5527 afi_t afi, safi_t safi, uint32_t flag)
5528 {
5529 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5530 }
5531
5532 /* neighbor capability orf prefix-list. */
5533 DEFUN (neighbor_capability_orf_prefix,
5534 neighbor_capability_orf_prefix_cmd,
5535 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5536 NEIGHBOR_STR
5537 NEIGHBOR_ADDR_STR2
5538 "Advertise capability to the peer\n"
5539 "Advertise ORF capability to the peer\n"
5540 "Advertise prefixlist ORF capability to this neighbor\n"
5541 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5542 "Capability to RECEIVE the ORF from this neighbor\n"
5543 "Capability to SEND the ORF to this neighbor\n")
5544 {
5545 int idx_send_recv = 5;
5546 char *peer_str = argv[1]->arg;
5547 struct peer *peer;
5548 afi_t afi = bgp_node_afi(vty);
5549 safi_t safi = bgp_node_safi(vty);
5550
5551 peer = peer_and_group_lookup_vty(vty, peer_str);
5552 if (!peer)
5553 return CMD_WARNING_CONFIG_FAILED;
5554
5555 if (strmatch(argv[idx_send_recv]->text, "send"))
5556 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5557 PEER_FLAG_ORF_PREFIX_SM);
5558
5559 if (strmatch(argv[idx_send_recv]->text, "receive"))
5560 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5561 PEER_FLAG_ORF_PREFIX_RM);
5562
5563 if (strmatch(argv[idx_send_recv]->text, "both"))
5564 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5565 PEER_FLAG_ORF_PREFIX_SM)
5566 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5567 PEER_FLAG_ORF_PREFIX_RM);
5568
5569 return CMD_WARNING_CONFIG_FAILED;
5570 }
5571
5572 ALIAS_HIDDEN(
5573 neighbor_capability_orf_prefix,
5574 neighbor_capability_orf_prefix_hidden_cmd,
5575 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5576 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5577 "Advertise capability to the peer\n"
5578 "Advertise ORF capability to the peer\n"
5579 "Advertise prefixlist ORF capability to this neighbor\n"
5580 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5581 "Capability to RECEIVE the ORF from this neighbor\n"
5582 "Capability to SEND the ORF to this neighbor\n")
5583
5584 DEFUN (no_neighbor_capability_orf_prefix,
5585 no_neighbor_capability_orf_prefix_cmd,
5586 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5587 NO_STR
5588 NEIGHBOR_STR
5589 NEIGHBOR_ADDR_STR2
5590 "Advertise capability to the peer\n"
5591 "Advertise ORF capability to the peer\n"
5592 "Advertise prefixlist ORF capability to this neighbor\n"
5593 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5594 "Capability to RECEIVE the ORF from this neighbor\n"
5595 "Capability to SEND the ORF to this neighbor\n")
5596 {
5597 int idx_send_recv = 6;
5598 char *peer_str = argv[2]->arg;
5599 struct peer *peer;
5600 afi_t afi = bgp_node_afi(vty);
5601 safi_t safi = bgp_node_safi(vty);
5602
5603 peer = peer_and_group_lookup_vty(vty, peer_str);
5604 if (!peer)
5605 return CMD_WARNING_CONFIG_FAILED;
5606
5607 if (strmatch(argv[idx_send_recv]->text, "send"))
5608 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5609 PEER_FLAG_ORF_PREFIX_SM);
5610
5611 if (strmatch(argv[idx_send_recv]->text, "receive"))
5612 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5613 PEER_FLAG_ORF_PREFIX_RM);
5614
5615 if (strmatch(argv[idx_send_recv]->text, "both"))
5616 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5617 PEER_FLAG_ORF_PREFIX_SM)
5618 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5619 PEER_FLAG_ORF_PREFIX_RM);
5620
5621 return CMD_WARNING_CONFIG_FAILED;
5622 }
5623
5624 ALIAS_HIDDEN(
5625 no_neighbor_capability_orf_prefix,
5626 no_neighbor_capability_orf_prefix_hidden_cmd,
5627 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5628 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5629 "Advertise capability to the peer\n"
5630 "Advertise ORF capability to the peer\n"
5631 "Advertise prefixlist ORF capability to this neighbor\n"
5632 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5633 "Capability to RECEIVE the ORF from this neighbor\n"
5634 "Capability to SEND the ORF to this neighbor\n")
5635
5636 /* neighbor next-hop-self. */
5637 DEFUN (neighbor_nexthop_self,
5638 neighbor_nexthop_self_cmd,
5639 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5640 NEIGHBOR_STR
5641 NEIGHBOR_ADDR_STR2
5642 "Disable the next hop calculation for this neighbor\n")
5643 {
5644 int idx_peer = 1;
5645 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5646 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5647 }
5648
5649 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5650 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5651 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5652 "Disable the next hop calculation for this neighbor\n")
5653
5654 /* neighbor next-hop-self. */
5655 DEFUN (neighbor_nexthop_self_force,
5656 neighbor_nexthop_self_force_cmd,
5657 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5658 NEIGHBOR_STR
5659 NEIGHBOR_ADDR_STR2
5660 "Disable the next hop calculation for this neighbor\n"
5661 "Set the next hop to self for reflected routes\n")
5662 {
5663 int idx_peer = 1;
5664 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5665 bgp_node_safi(vty),
5666 PEER_FLAG_FORCE_NEXTHOP_SELF);
5667 }
5668
5669 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5670 neighbor_nexthop_self_force_hidden_cmd,
5671 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5672 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5673 "Disable the next hop calculation for this neighbor\n"
5674 "Set the next hop to self for reflected routes\n")
5675
5676 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5677 neighbor_nexthop_self_all_hidden_cmd,
5678 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5679 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5680 "Disable the next hop calculation for this neighbor\n"
5681 "Set the next hop to self for reflected routes\n")
5682
5683 DEFUN (no_neighbor_nexthop_self,
5684 no_neighbor_nexthop_self_cmd,
5685 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5686 NO_STR
5687 NEIGHBOR_STR
5688 NEIGHBOR_ADDR_STR2
5689 "Disable the next hop calculation for this neighbor\n")
5690 {
5691 int idx_peer = 2;
5692 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5693 bgp_node_afi(vty), bgp_node_safi(vty),
5694 PEER_FLAG_NEXTHOP_SELF);
5695 }
5696
5697 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5698 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5699 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5700 "Disable the next hop calculation for this neighbor\n")
5701
5702 DEFUN (no_neighbor_nexthop_self_force,
5703 no_neighbor_nexthop_self_force_cmd,
5704 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5705 NO_STR
5706 NEIGHBOR_STR
5707 NEIGHBOR_ADDR_STR2
5708 "Disable the next hop calculation for this neighbor\n"
5709 "Set the next hop to self for reflected routes\n")
5710 {
5711 int idx_peer = 2;
5712 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5713 bgp_node_afi(vty), bgp_node_safi(vty),
5714 PEER_FLAG_FORCE_NEXTHOP_SELF);
5715 }
5716
5717 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5718 no_neighbor_nexthop_self_force_hidden_cmd,
5719 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5721 "Disable the next hop calculation for this neighbor\n"
5722 "Set the next hop to self for reflected routes\n")
5723
5724 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5725 no_neighbor_nexthop_self_all_hidden_cmd,
5726 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5727 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5728 "Disable the next hop calculation for this neighbor\n"
5729 "Set the next hop to self for reflected routes\n")
5730
5731 /* neighbor as-override */
5732 DEFUN (neighbor_as_override,
5733 neighbor_as_override_cmd,
5734 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5735 NEIGHBOR_STR
5736 NEIGHBOR_ADDR_STR2
5737 "Override ASNs in outbound updates if aspath equals remote-as\n")
5738 {
5739 int idx_peer = 1;
5740 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5741 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5742 }
5743
5744 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5745 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5746 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Override ASNs in outbound updates if aspath equals remote-as\n")
5748
5749 DEFUN (no_neighbor_as_override,
5750 no_neighbor_as_override_cmd,
5751 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5752 NO_STR
5753 NEIGHBOR_STR
5754 NEIGHBOR_ADDR_STR2
5755 "Override ASNs in outbound updates if aspath equals remote-as\n")
5756 {
5757 int idx_peer = 2;
5758 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5759 bgp_node_afi(vty), bgp_node_safi(vty),
5760 PEER_FLAG_AS_OVERRIDE);
5761 }
5762
5763 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5764 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5765 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5766 "Override ASNs in outbound updates if aspath equals remote-as\n")
5767
5768 /* neighbor remove-private-AS. */
5769 DEFUN (neighbor_remove_private_as,
5770 neighbor_remove_private_as_cmd,
5771 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5772 NEIGHBOR_STR
5773 NEIGHBOR_ADDR_STR2
5774 "Remove private ASNs in outbound updates\n")
5775 {
5776 int idx_peer = 1;
5777 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5778 bgp_node_safi(vty),
5779 PEER_FLAG_REMOVE_PRIVATE_AS);
5780 }
5781
5782 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5783 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5784 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5785 "Remove private ASNs in outbound updates\n")
5786
5787 DEFUN (neighbor_remove_private_as_all,
5788 neighbor_remove_private_as_all_cmd,
5789 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5790 NEIGHBOR_STR
5791 NEIGHBOR_ADDR_STR2
5792 "Remove private ASNs in outbound updates\n"
5793 "Apply to all AS numbers\n")
5794 {
5795 int idx_peer = 1;
5796 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5797 bgp_node_safi(vty),
5798 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5799 }
5800
5801 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5802 neighbor_remove_private_as_all_hidden_cmd,
5803 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5805 "Remove private ASNs in outbound updates\n"
5806 "Apply to all AS numbers")
5807
5808 DEFUN (neighbor_remove_private_as_replace_as,
5809 neighbor_remove_private_as_replace_as_cmd,
5810 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5811 NEIGHBOR_STR
5812 NEIGHBOR_ADDR_STR2
5813 "Remove private ASNs in outbound updates\n"
5814 "Replace private ASNs with our ASN in outbound updates\n")
5815 {
5816 int idx_peer = 1;
5817 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5818 bgp_node_safi(vty),
5819 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5820 }
5821
5822 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5823 neighbor_remove_private_as_replace_as_hidden_cmd,
5824 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5825 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5826 "Remove private ASNs in outbound updates\n"
5827 "Replace private ASNs with our ASN in outbound updates\n")
5828
5829 DEFUN (neighbor_remove_private_as_all_replace_as,
5830 neighbor_remove_private_as_all_replace_as_cmd,
5831 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5832 NEIGHBOR_STR
5833 NEIGHBOR_ADDR_STR2
5834 "Remove private ASNs in outbound updates\n"
5835 "Apply to all AS numbers\n"
5836 "Replace private ASNs with our ASN in outbound updates\n")
5837 {
5838 int idx_peer = 1;
5839 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5840 bgp_node_safi(vty),
5841 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5842 }
5843
5844 ALIAS_HIDDEN(
5845 neighbor_remove_private_as_all_replace_as,
5846 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5847 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5848 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5849 "Remove private ASNs in outbound updates\n"
5850 "Apply to all AS numbers\n"
5851 "Replace private ASNs with our ASN in outbound updates\n")
5852
5853 DEFUN (no_neighbor_remove_private_as,
5854 no_neighbor_remove_private_as_cmd,
5855 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5856 NO_STR
5857 NEIGHBOR_STR
5858 NEIGHBOR_ADDR_STR2
5859 "Remove private ASNs in outbound updates\n")
5860 {
5861 int idx_peer = 2;
5862 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5863 bgp_node_afi(vty), bgp_node_safi(vty),
5864 PEER_FLAG_REMOVE_PRIVATE_AS);
5865 }
5866
5867 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5868 no_neighbor_remove_private_as_hidden_cmd,
5869 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5870 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5871 "Remove private ASNs in outbound updates\n")
5872
5873 DEFUN (no_neighbor_remove_private_as_all,
5874 no_neighbor_remove_private_as_all_cmd,
5875 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5876 NO_STR
5877 NEIGHBOR_STR
5878 NEIGHBOR_ADDR_STR2
5879 "Remove private ASNs in outbound updates\n"
5880 "Apply to all AS numbers\n")
5881 {
5882 int idx_peer = 2;
5883 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5884 bgp_node_afi(vty), bgp_node_safi(vty),
5885 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5886 }
5887
5888 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5889 no_neighbor_remove_private_as_all_hidden_cmd,
5890 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5891 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5892 "Remove private ASNs in outbound updates\n"
5893 "Apply to all AS numbers\n")
5894
5895 DEFUN (no_neighbor_remove_private_as_replace_as,
5896 no_neighbor_remove_private_as_replace_as_cmd,
5897 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5898 NO_STR
5899 NEIGHBOR_STR
5900 NEIGHBOR_ADDR_STR2
5901 "Remove private ASNs in outbound updates\n"
5902 "Replace private ASNs with our ASN in outbound updates\n")
5903 {
5904 int idx_peer = 2;
5905 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5906 bgp_node_afi(vty), bgp_node_safi(vty),
5907 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5908 }
5909
5910 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5911 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5912 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5913 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5914 "Remove private ASNs in outbound updates\n"
5915 "Replace private ASNs with our ASN in outbound updates\n")
5916
5917 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5918 no_neighbor_remove_private_as_all_replace_as_cmd,
5919 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5920 NO_STR
5921 NEIGHBOR_STR
5922 NEIGHBOR_ADDR_STR2
5923 "Remove private ASNs in outbound updates\n"
5924 "Apply to all AS numbers\n"
5925 "Replace private ASNs with our ASN in outbound updates\n")
5926 {
5927 int idx_peer = 2;
5928 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5929 bgp_node_afi(vty), bgp_node_safi(vty),
5930 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5931 }
5932
5933 ALIAS_HIDDEN(
5934 no_neighbor_remove_private_as_all_replace_as,
5935 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5936 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5937 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5938 "Remove private ASNs in outbound updates\n"
5939 "Apply to all AS numbers\n"
5940 "Replace private ASNs with our ASN in outbound updates\n")
5941
5942
5943 /* neighbor send-community. */
5944 DEFUN (neighbor_send_community,
5945 neighbor_send_community_cmd,
5946 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5947 NEIGHBOR_STR
5948 NEIGHBOR_ADDR_STR2
5949 "Send Community attribute to this neighbor\n")
5950 {
5951 int idx_peer = 1;
5952
5953 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5954 bgp_node_safi(vty),
5955 PEER_FLAG_SEND_COMMUNITY);
5956 }
5957
5958 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5959 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5960 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5961 "Send Community attribute to this neighbor\n")
5962
5963 DEFUN (no_neighbor_send_community,
5964 no_neighbor_send_community_cmd,
5965 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5966 NO_STR
5967 NEIGHBOR_STR
5968 NEIGHBOR_ADDR_STR2
5969 "Send Community attribute to this neighbor\n")
5970 {
5971 int idx_peer = 2;
5972
5973 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5974 bgp_node_afi(vty), bgp_node_safi(vty),
5975 PEER_FLAG_SEND_COMMUNITY);
5976 }
5977
5978 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5979 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5980 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5981 "Send Community attribute to this neighbor\n")
5982
5983 /* neighbor send-community extended. */
5984 DEFUN (neighbor_send_community_type,
5985 neighbor_send_community_type_cmd,
5986 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5987 NEIGHBOR_STR
5988 NEIGHBOR_ADDR_STR2
5989 "Send Community attribute to this neighbor\n"
5990 "Send Standard and Extended Community attributes\n"
5991 "Send Standard, Large and Extended Community attributes\n"
5992 "Send Extended Community attributes\n"
5993 "Send Standard Community attributes\n"
5994 "Send Large Community attributes\n")
5995 {
5996 const char *type = argv[argc - 1]->text;
5997 char *peer_str = argv[1]->arg;
5998 struct peer *peer;
5999 afi_t afi = bgp_node_afi(vty);
6000 safi_t safi = bgp_node_safi(vty);
6001
6002 peer = peer_and_group_lookup_vty(vty, peer_str);
6003 if (!peer)
6004 return CMD_WARNING_CONFIG_FAILED;
6005
6006 if (strmatch(type, "standard"))
6007 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6008 PEER_FLAG_SEND_COMMUNITY);
6009
6010 if (strmatch(type, "extended"))
6011 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6012 PEER_FLAG_SEND_EXT_COMMUNITY);
6013
6014 if (strmatch(type, "large"))
6015 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6016 PEER_FLAG_SEND_LARGE_COMMUNITY);
6017
6018 if (strmatch(type, "both")) {
6019 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6020 PEER_FLAG_SEND_COMMUNITY)
6021 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6022 PEER_FLAG_SEND_EXT_COMMUNITY);
6023 }
6024 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6025 PEER_FLAG_SEND_COMMUNITY)
6026 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6027 PEER_FLAG_SEND_EXT_COMMUNITY)
6028 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6029 PEER_FLAG_SEND_LARGE_COMMUNITY);
6030 }
6031
6032 ALIAS_HIDDEN(
6033 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6034 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6036 "Send Community attribute to this neighbor\n"
6037 "Send Standard and Extended Community attributes\n"
6038 "Send Standard, Large and Extended Community attributes\n"
6039 "Send Extended Community attributes\n"
6040 "Send Standard Community attributes\n"
6041 "Send Large Community attributes\n")
6042
6043 DEFUN (no_neighbor_send_community_type,
6044 no_neighbor_send_community_type_cmd,
6045 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6046 NO_STR
6047 NEIGHBOR_STR
6048 NEIGHBOR_ADDR_STR2
6049 "Send Community attribute to this neighbor\n"
6050 "Send Standard and Extended Community attributes\n"
6051 "Send Standard, Large and Extended Community attributes\n"
6052 "Send Extended Community attributes\n"
6053 "Send Standard Community attributes\n"
6054 "Send Large Community attributes\n")
6055 {
6056 const char *type = argv[argc - 1]->text;
6057 char *peer_str = argv[2]->arg;
6058 struct peer *peer;
6059 afi_t afi = bgp_node_afi(vty);
6060 safi_t safi = bgp_node_safi(vty);
6061
6062 peer = peer_and_group_lookup_vty(vty, peer_str);
6063 if (!peer)
6064 return CMD_WARNING_CONFIG_FAILED;
6065
6066 if (strmatch(type, "standard"))
6067 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6068 PEER_FLAG_SEND_COMMUNITY);
6069
6070 if (strmatch(type, "extended"))
6071 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6072 PEER_FLAG_SEND_EXT_COMMUNITY);
6073
6074 if (strmatch(type, "large"))
6075 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6076 PEER_FLAG_SEND_LARGE_COMMUNITY);
6077
6078 if (strmatch(type, "both")) {
6079
6080 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6081 PEER_FLAG_SEND_COMMUNITY)
6082 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6083 PEER_FLAG_SEND_EXT_COMMUNITY);
6084 }
6085
6086 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6087 PEER_FLAG_SEND_COMMUNITY)
6088 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6089 PEER_FLAG_SEND_EXT_COMMUNITY)
6090 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6091 PEER_FLAG_SEND_LARGE_COMMUNITY);
6092 }
6093
6094 ALIAS_HIDDEN(
6095 no_neighbor_send_community_type,
6096 no_neighbor_send_community_type_hidden_cmd,
6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6098 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6099 "Send Community attribute to this neighbor\n"
6100 "Send Standard and Extended Community attributes\n"
6101 "Send Standard, Large and Extended Community attributes\n"
6102 "Send Extended Community attributes\n"
6103 "Send Standard Community attributes\n"
6104 "Send Large Community attributes\n")
6105
6106 /* neighbor soft-reconfig. */
6107 DEFUN (neighbor_soft_reconfiguration,
6108 neighbor_soft_reconfiguration_cmd,
6109 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6110 NEIGHBOR_STR
6111 NEIGHBOR_ADDR_STR2
6112 "Per neighbor soft reconfiguration\n"
6113 "Allow inbound soft reconfiguration for this neighbor\n")
6114 {
6115 int idx_peer = 1;
6116 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6117 bgp_node_safi(vty),
6118 PEER_FLAG_SOFT_RECONFIG);
6119 }
6120
6121 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6122 neighbor_soft_reconfiguration_hidden_cmd,
6123 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6124 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6125 "Per neighbor soft reconfiguration\n"
6126 "Allow inbound soft reconfiguration for this neighbor\n")
6127
6128 DEFUN (no_neighbor_soft_reconfiguration,
6129 no_neighbor_soft_reconfiguration_cmd,
6130 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6131 NO_STR
6132 NEIGHBOR_STR
6133 NEIGHBOR_ADDR_STR2
6134 "Per neighbor soft reconfiguration\n"
6135 "Allow inbound soft reconfiguration for this neighbor\n")
6136 {
6137 int idx_peer = 2;
6138 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6139 bgp_node_afi(vty), bgp_node_safi(vty),
6140 PEER_FLAG_SOFT_RECONFIG);
6141 }
6142
6143 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6144 no_neighbor_soft_reconfiguration_hidden_cmd,
6145 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6146 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6147 "Per neighbor soft reconfiguration\n"
6148 "Allow inbound soft reconfiguration for this neighbor\n")
6149
6150 DEFUN (neighbor_route_reflector_client,
6151 neighbor_route_reflector_client_cmd,
6152 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6153 NEIGHBOR_STR
6154 NEIGHBOR_ADDR_STR2
6155 "Configure a neighbor as Route Reflector client\n")
6156 {
6157 int idx_peer = 1;
6158 struct peer *peer;
6159
6160
6161 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6162 if (!peer)
6163 return CMD_WARNING_CONFIG_FAILED;
6164
6165 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6166 bgp_node_safi(vty),
6167 PEER_FLAG_REFLECTOR_CLIENT);
6168 }
6169
6170 ALIAS_HIDDEN(neighbor_route_reflector_client,
6171 neighbor_route_reflector_client_hidden_cmd,
6172 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6173 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6174 "Configure a neighbor as Route Reflector client\n")
6175
6176 DEFUN (no_neighbor_route_reflector_client,
6177 no_neighbor_route_reflector_client_cmd,
6178 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6179 NO_STR
6180 NEIGHBOR_STR
6181 NEIGHBOR_ADDR_STR2
6182 "Configure a neighbor as Route Reflector client\n")
6183 {
6184 int idx_peer = 2;
6185 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6186 bgp_node_afi(vty), bgp_node_safi(vty),
6187 PEER_FLAG_REFLECTOR_CLIENT);
6188 }
6189
6190 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6191 no_neighbor_route_reflector_client_hidden_cmd,
6192 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6193 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6194 "Configure a neighbor as Route Reflector client\n")
6195
6196 /* neighbor route-server-client. */
6197 DEFUN (neighbor_route_server_client,
6198 neighbor_route_server_client_cmd,
6199 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6200 NEIGHBOR_STR
6201 NEIGHBOR_ADDR_STR2
6202 "Configure a neighbor as Route Server client\n")
6203 {
6204 int idx_peer = 1;
6205 struct peer *peer;
6206
6207 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6208 if (!peer)
6209 return CMD_WARNING_CONFIG_FAILED;
6210 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6211 bgp_node_safi(vty),
6212 PEER_FLAG_RSERVER_CLIENT);
6213 }
6214
6215 ALIAS_HIDDEN(neighbor_route_server_client,
6216 neighbor_route_server_client_hidden_cmd,
6217 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6218 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6219 "Configure a neighbor as Route Server client\n")
6220
6221 DEFUN (no_neighbor_route_server_client,
6222 no_neighbor_route_server_client_cmd,
6223 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6224 NO_STR
6225 NEIGHBOR_STR
6226 NEIGHBOR_ADDR_STR2
6227 "Configure a neighbor as Route Server client\n")
6228 {
6229 int idx_peer = 2;
6230 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6231 bgp_node_afi(vty), bgp_node_safi(vty),
6232 PEER_FLAG_RSERVER_CLIENT);
6233 }
6234
6235 ALIAS_HIDDEN(no_neighbor_route_server_client,
6236 no_neighbor_route_server_client_hidden_cmd,
6237 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6238 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6239 "Configure a neighbor as Route Server client\n")
6240
6241 DEFUN (neighbor_nexthop_local_unchanged,
6242 neighbor_nexthop_local_unchanged_cmd,
6243 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6244 NEIGHBOR_STR
6245 NEIGHBOR_ADDR_STR2
6246 "Configure treatment of outgoing link-local nexthop attribute\n"
6247 "Leave link-local nexthop unchanged for this peer\n")
6248 {
6249 int idx_peer = 1;
6250 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6251 bgp_node_safi(vty),
6252 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6253 }
6254
6255 DEFUN (no_neighbor_nexthop_local_unchanged,
6256 no_neighbor_nexthop_local_unchanged_cmd,
6257 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6258 NO_STR
6259 NEIGHBOR_STR
6260 NEIGHBOR_ADDR_STR2
6261 "Configure treatment of outgoing link-local-nexthop attribute\n"
6262 "Leave link-local nexthop unchanged for this peer\n")
6263 {
6264 int idx_peer = 2;
6265 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6266 bgp_node_afi(vty), bgp_node_safi(vty),
6267 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6268 }
6269
6270 DEFUN (neighbor_attr_unchanged,
6271 neighbor_attr_unchanged_cmd,
6272 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6273 NEIGHBOR_STR
6274 NEIGHBOR_ADDR_STR2
6275 "BGP attribute is propagated unchanged to this neighbor\n"
6276 "As-path attribute\n"
6277 "Nexthop attribute\n"
6278 "Med attribute\n")
6279 {
6280 int idx = 0;
6281 char *peer_str = argv[1]->arg;
6282 struct peer *peer;
6283 bool aspath = false;
6284 bool nexthop = false;
6285 bool med = false;
6286 afi_t afi = bgp_node_afi(vty);
6287 safi_t safi = bgp_node_safi(vty);
6288 int ret = 0;
6289
6290 peer = peer_and_group_lookup_vty(vty, peer_str);
6291 if (!peer)
6292 return CMD_WARNING_CONFIG_FAILED;
6293
6294 if (argv_find(argv, argc, "as-path", &idx))
6295 aspath = true;
6296
6297 idx = 0;
6298 if (argv_find(argv, argc, "next-hop", &idx))
6299 nexthop = true;
6300
6301 idx = 0;
6302 if (argv_find(argv, argc, "med", &idx))
6303 med = true;
6304
6305 /* no flags means all of them! */
6306 if (!aspath && !nexthop && !med) {
6307 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6308 PEER_FLAG_AS_PATH_UNCHANGED);
6309 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6310 PEER_FLAG_NEXTHOP_UNCHANGED);
6311 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6312 PEER_FLAG_MED_UNCHANGED);
6313 } else {
6314 if (!aspath) {
6315 if (peer_af_flag_check(peer, afi, safi,
6316 PEER_FLAG_AS_PATH_UNCHANGED)) {
6317 ret |= peer_af_flag_unset_vty(
6318 vty, peer_str, afi, safi,
6319 PEER_FLAG_AS_PATH_UNCHANGED);
6320 }
6321 } else
6322 ret |= peer_af_flag_set_vty(
6323 vty, peer_str, afi, safi,
6324 PEER_FLAG_AS_PATH_UNCHANGED);
6325
6326 if (!nexthop) {
6327 if (peer_af_flag_check(peer, afi, safi,
6328 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6329 ret |= peer_af_flag_unset_vty(
6330 vty, peer_str, afi, safi,
6331 PEER_FLAG_NEXTHOP_UNCHANGED);
6332 }
6333 } else
6334 ret |= peer_af_flag_set_vty(
6335 vty, peer_str, afi, safi,
6336 PEER_FLAG_NEXTHOP_UNCHANGED);
6337
6338 if (!med) {
6339 if (peer_af_flag_check(peer, afi, safi,
6340 PEER_FLAG_MED_UNCHANGED)) {
6341 ret |= peer_af_flag_unset_vty(
6342 vty, peer_str, afi, safi,
6343 PEER_FLAG_MED_UNCHANGED);
6344 }
6345 } else
6346 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6347 PEER_FLAG_MED_UNCHANGED);
6348 }
6349
6350 return ret;
6351 }
6352
6353 ALIAS_HIDDEN(
6354 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6355 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6356 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6357 "BGP attribute is propagated unchanged to this neighbor\n"
6358 "As-path attribute\n"
6359 "Nexthop attribute\n"
6360 "Med attribute\n")
6361
6362 DEFUN (no_neighbor_attr_unchanged,
6363 no_neighbor_attr_unchanged_cmd,
6364 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6365 NO_STR
6366 NEIGHBOR_STR
6367 NEIGHBOR_ADDR_STR2
6368 "BGP attribute is propagated unchanged to this neighbor\n"
6369 "As-path attribute\n"
6370 "Nexthop attribute\n"
6371 "Med attribute\n")
6372 {
6373 int idx = 0;
6374 char *peer_str = argv[2]->arg;
6375 struct peer *peer;
6376 bool aspath = false;
6377 bool nexthop = false;
6378 bool med = false;
6379 afi_t afi = bgp_node_afi(vty);
6380 safi_t safi = bgp_node_safi(vty);
6381 int ret = 0;
6382
6383 peer = peer_and_group_lookup_vty(vty, peer_str);
6384 if (!peer)
6385 return CMD_WARNING_CONFIG_FAILED;
6386
6387 if (argv_find(argv, argc, "as-path", &idx))
6388 aspath = true;
6389
6390 idx = 0;
6391 if (argv_find(argv, argc, "next-hop", &idx))
6392 nexthop = true;
6393
6394 idx = 0;
6395 if (argv_find(argv, argc, "med", &idx))
6396 med = true;
6397
6398 if (!aspath && !nexthop && !med) // no flags means all of them!
6399 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6400 PEER_FLAG_AS_PATH_UNCHANGED)
6401 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6402 PEER_FLAG_NEXTHOP_UNCHANGED)
6403 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6404 PEER_FLAG_MED_UNCHANGED);
6405
6406 if (aspath)
6407 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6408 PEER_FLAG_AS_PATH_UNCHANGED);
6409
6410 if (nexthop)
6411 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6412 PEER_FLAG_NEXTHOP_UNCHANGED);
6413
6414 if (med)
6415 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6416 PEER_FLAG_MED_UNCHANGED);
6417
6418 return ret;
6419 }
6420
6421 ALIAS_HIDDEN(
6422 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6423 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6424 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6425 "BGP attribute is propagated unchanged to this neighbor\n"
6426 "As-path attribute\n"
6427 "Nexthop attribute\n"
6428 "Med attribute\n")
6429
6430 /* EBGP multihop configuration. */
6431 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6432 const char *ttl_str)
6433 {
6434 struct peer *peer;
6435 unsigned int ttl;
6436
6437 peer = peer_and_group_lookup_vty(vty, ip_str);
6438 if (!peer)
6439 return CMD_WARNING_CONFIG_FAILED;
6440
6441 if (peer->conf_if)
6442 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6443
6444 if (!ttl_str)
6445 ttl = MAXTTL;
6446 else
6447 ttl = strtoul(ttl_str, NULL, 10);
6448
6449 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6450 }
6451
6452 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6453 {
6454 struct peer *peer;
6455
6456 peer = peer_and_group_lookup_vty(vty, ip_str);
6457 if (!peer)
6458 return CMD_WARNING_CONFIG_FAILED;
6459
6460 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6461 }
6462
6463 /* neighbor ebgp-multihop. */
6464 DEFUN (neighbor_ebgp_multihop,
6465 neighbor_ebgp_multihop_cmd,
6466 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6467 NEIGHBOR_STR
6468 NEIGHBOR_ADDR_STR2
6469 "Allow EBGP neighbors not on directly connected networks\n")
6470 {
6471 int idx_peer = 1;
6472 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6473 }
6474
6475 DEFUN (neighbor_ebgp_multihop_ttl,
6476 neighbor_ebgp_multihop_ttl_cmd,
6477 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6478 NEIGHBOR_STR
6479 NEIGHBOR_ADDR_STR2
6480 "Allow EBGP neighbors not on directly connected networks\n"
6481 "maximum hop count\n")
6482 {
6483 int idx_peer = 1;
6484 int idx_number = 3;
6485 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6486 argv[idx_number]->arg);
6487 }
6488
6489 DEFUN (no_neighbor_ebgp_multihop,
6490 no_neighbor_ebgp_multihop_cmd,
6491 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6492 NO_STR
6493 NEIGHBOR_STR
6494 NEIGHBOR_ADDR_STR2
6495 "Allow EBGP neighbors not on directly connected networks\n"
6496 "maximum hop count\n")
6497 {
6498 int idx_peer = 2;
6499 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6500 }
6501
6502 static uint8_t get_role_by_name(const char *role_str)
6503 {
6504 if (strncmp(role_str, "peer", 2) == 0)
6505 return ROLE_PEER;
6506 if (strncmp(role_str, "provider", 2) == 0)
6507 return ROLE_PROVIDER;
6508 if (strncmp(role_str, "customer", 2) == 0)
6509 return ROLE_CUSTOMER;
6510 if (strncmp(role_str, "rs-server", 4) == 0)
6511 return ROLE_RS_SERVER;
6512 if (strncmp(role_str, "rs-client", 4) == 0)
6513 return ROLE_RS_CLIENT;
6514 return ROLE_UNDEFINED;
6515 }
6516
6517 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6518 const char *role_str, bool strict_mode)
6519 {
6520 struct peer *peer;
6521
6522 peer = peer_and_group_lookup_vty(vty, ip_str);
6523 if (!peer)
6524 return CMD_WARNING_CONFIG_FAILED;
6525 uint8_t role = get_role_by_name(role_str);
6526
6527 if (role == ROLE_UNDEFINED)
6528 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6529 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6530 }
6531
6532 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6533 {
6534 struct peer *peer;
6535
6536 peer = peer_and_group_lookup_vty(vty, ip_str);
6537 if (!peer)
6538 return CMD_WARNING_CONFIG_FAILED;
6539 return bgp_vty_return(vty, peer_role_unset(peer));
6540 }
6541
6542 DEFPY(neighbor_role,
6543 neighbor_role_cmd,
6544 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6545 NEIGHBOR_STR
6546 NEIGHBOR_ADDR_STR2
6547 "Set session role\n"
6548 ROLE_STR)
6549 {
6550 int idx_peer = 1;
6551 int idx_role = 3;
6552
6553 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6554 false);
6555 }
6556
6557 DEFPY(neighbor_role_strict,
6558 neighbor_role_strict_cmd,
6559 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6560 NEIGHBOR_STR
6561 NEIGHBOR_ADDR_STR2
6562 "Set session role\n"
6563 ROLE_STR
6564 "Use additional restriction on peer\n")
6565 {
6566 int idx_peer = 1;
6567 int idx_role = 3;
6568
6569 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6570 true);
6571 }
6572
6573 DEFPY(no_neighbor_role,
6574 no_neighbor_role_cmd,
6575 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6576 NO_STR
6577 NEIGHBOR_STR
6578 NEIGHBOR_ADDR_STR2
6579 "Set session role\n"
6580 ROLE_STR
6581 "Use additional restriction on peer\n")
6582 {
6583 int idx_peer = 2;
6584
6585 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6586 }
6587
6588 /* disable-connected-check */
6589 DEFUN (neighbor_disable_connected_check,
6590 neighbor_disable_connected_check_cmd,
6591 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6592 NEIGHBOR_STR
6593 NEIGHBOR_ADDR_STR2
6594 "one-hop away EBGP peer using loopback address\n"
6595 "Enforce EBGP neighbors perform multihop\n")
6596 {
6597 int idx_peer = 1;
6598 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6599 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6600 }
6601
6602 DEFUN (no_neighbor_disable_connected_check,
6603 no_neighbor_disable_connected_check_cmd,
6604 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6605 NO_STR
6606 NEIGHBOR_STR
6607 NEIGHBOR_ADDR_STR2
6608 "one-hop away EBGP peer using loopback address\n"
6609 "Enforce EBGP neighbors perform multihop\n")
6610 {
6611 int idx_peer = 2;
6612 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6613 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6614 }
6615
6616 /* disable-link-bw-encoding-ieee */
6617 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6618 neighbor_disable_link_bw_encoding_ieee_cmd,
6619 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6620 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6621 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6622 {
6623 int idx_peer = 1;
6624
6625 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6626 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6627 }
6628
6629 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6630 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6631 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6632 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6633 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6634 {
6635 int idx_peer = 2;
6636
6637 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6638 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6639 }
6640
6641 /* extended-optional-parameters */
6642 DEFUN(neighbor_extended_optional_parameters,
6643 neighbor_extended_optional_parameters_cmd,
6644 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6646 "Force the extended optional parameters format for OPEN messages\n")
6647 {
6648 int idx_peer = 1;
6649
6650 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6651 PEER_FLAG_EXTENDED_OPT_PARAMS);
6652 }
6653
6654 DEFUN(no_neighbor_extended_optional_parameters,
6655 no_neighbor_extended_optional_parameters_cmd,
6656 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6657 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6658 "Force the extended optional parameters format for OPEN messages\n")
6659 {
6660 int idx_peer = 2;
6661
6662 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6663 PEER_FLAG_EXTENDED_OPT_PARAMS);
6664 }
6665
6666 /* enforce-first-as */
6667 DEFUN (neighbor_enforce_first_as,
6668 neighbor_enforce_first_as_cmd,
6669 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6670 NEIGHBOR_STR
6671 NEIGHBOR_ADDR_STR2
6672 "Enforce the first AS for EBGP routes\n")
6673 {
6674 int idx_peer = 1;
6675
6676 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6677 PEER_FLAG_ENFORCE_FIRST_AS);
6678 }
6679
6680 DEFUN (no_neighbor_enforce_first_as,
6681 no_neighbor_enforce_first_as_cmd,
6682 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6683 NO_STR
6684 NEIGHBOR_STR
6685 NEIGHBOR_ADDR_STR2
6686 "Enforce the first AS for EBGP routes\n")
6687 {
6688 int idx_peer = 2;
6689
6690 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6691 PEER_FLAG_ENFORCE_FIRST_AS);
6692 }
6693
6694
6695 DEFUN (neighbor_description,
6696 neighbor_description_cmd,
6697 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6698 NEIGHBOR_STR
6699 NEIGHBOR_ADDR_STR2
6700 "Neighbor specific description\n"
6701 "Up to 80 characters describing this neighbor\n")
6702 {
6703 int idx_peer = 1;
6704 int idx_line = 3;
6705 struct peer *peer;
6706 char *str;
6707
6708 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6709 if (!peer)
6710 return CMD_WARNING_CONFIG_FAILED;
6711
6712 str = argv_concat(argv, argc, idx_line);
6713
6714 peer_description_set(peer, str);
6715
6716 XFREE(MTYPE_TMP, str);
6717
6718 return CMD_SUCCESS;
6719 }
6720
6721 DEFUN (no_neighbor_description,
6722 no_neighbor_description_cmd,
6723 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6724 NO_STR
6725 NEIGHBOR_STR
6726 NEIGHBOR_ADDR_STR2
6727 "Neighbor specific description\n")
6728 {
6729 int idx_peer = 2;
6730 struct peer *peer;
6731
6732 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6733 if (!peer)
6734 return CMD_WARNING_CONFIG_FAILED;
6735
6736 peer_description_unset(peer);
6737
6738 return CMD_SUCCESS;
6739 }
6740
6741 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6742 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6743 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6744 "Neighbor specific description\n"
6745 "Up to 80 characters describing this neighbor\n")
6746
6747 /* Neighbor update-source. */
6748 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6749 const char *source_str)
6750 {
6751 struct peer *peer;
6752 struct prefix p;
6753 union sockunion su;
6754
6755 peer = peer_and_group_lookup_vty(vty, peer_str);
6756 if (!peer)
6757 return CMD_WARNING_CONFIG_FAILED;
6758
6759 if (peer->conf_if)
6760 return CMD_WARNING;
6761
6762 if (source_str) {
6763 if (str2sockunion(source_str, &su) == 0)
6764 peer_update_source_addr_set(peer, &su);
6765 else {
6766 if (str2prefix(source_str, &p)) {
6767 vty_out(vty,
6768 "%% Invalid update-source, remove prefix length \n");
6769 return CMD_WARNING_CONFIG_FAILED;
6770 } else
6771 peer_update_source_if_set(peer, source_str);
6772 }
6773 } else
6774 peer_update_source_unset(peer);
6775
6776 return CMD_SUCCESS;
6777 }
6778
6779 #define BGP_UPDATE_SOURCE_HELP_STR \
6780 "IPv4 address\n" \
6781 "IPv6 address\n" \
6782 "Interface name (requires zebra to be running)\n"
6783
6784 DEFUN (neighbor_update_source,
6785 neighbor_update_source_cmd,
6786 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6787 NEIGHBOR_STR
6788 NEIGHBOR_ADDR_STR2
6789 "Source of routing updates\n"
6790 BGP_UPDATE_SOURCE_HELP_STR)
6791 {
6792 int idx_peer = 1;
6793 int idx_peer_2 = 3;
6794 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6795 argv[idx_peer_2]->arg);
6796 }
6797
6798 DEFUN (no_neighbor_update_source,
6799 no_neighbor_update_source_cmd,
6800 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6801 NO_STR
6802 NEIGHBOR_STR
6803 NEIGHBOR_ADDR_STR2
6804 "Source of routing updates\n"
6805 BGP_UPDATE_SOURCE_HELP_STR)
6806 {
6807 int idx_peer = 2;
6808 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6809 }
6810
6811 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6812 afi_t afi, safi_t safi,
6813 const char *rmap, int set)
6814 {
6815 int ret;
6816 struct peer *peer;
6817 struct route_map *route_map = NULL;
6818
6819 peer = peer_and_group_lookup_vty(vty, peer_str);
6820 if (!peer)
6821 return CMD_WARNING_CONFIG_FAILED;
6822
6823 if (set) {
6824 if (rmap)
6825 route_map = route_map_lookup_warn_noexist(vty, rmap);
6826 ret = peer_default_originate_set(peer, afi, safi,
6827 rmap, route_map);
6828 } else
6829 ret = peer_default_originate_unset(peer, afi, safi);
6830
6831 return bgp_vty_return(vty, ret);
6832 }
6833
6834 /* neighbor default-originate. */
6835 DEFUN (neighbor_default_originate,
6836 neighbor_default_originate_cmd,
6837 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6838 NEIGHBOR_STR
6839 NEIGHBOR_ADDR_STR2
6840 "Originate default route to this neighbor\n")
6841 {
6842 int idx_peer = 1;
6843 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6844 bgp_node_afi(vty),
6845 bgp_node_safi(vty), NULL, 1);
6846 }
6847
6848 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6849 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6850 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6851 "Originate default route to this neighbor\n")
6852
6853 DEFUN (neighbor_default_originate_rmap,
6854 neighbor_default_originate_rmap_cmd,
6855 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6856 NEIGHBOR_STR
6857 NEIGHBOR_ADDR_STR2
6858 "Originate default route to this neighbor\n"
6859 "Route-map to specify criteria to originate default\n"
6860 "route-map name\n")
6861 {
6862 int idx_peer = 1;
6863 int idx_word = 4;
6864 return peer_default_originate_set_vty(
6865 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6866 argv[idx_word]->arg, 1);
6867 }
6868
6869 ALIAS_HIDDEN(
6870 neighbor_default_originate_rmap,
6871 neighbor_default_originate_rmap_hidden_cmd,
6872 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6873 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6874 "Originate default route to this neighbor\n"
6875 "Route-map to specify criteria to originate default\n"
6876 "route-map name\n")
6877
6878 DEFUN (no_neighbor_default_originate,
6879 no_neighbor_default_originate_cmd,
6880 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6881 NO_STR
6882 NEIGHBOR_STR
6883 NEIGHBOR_ADDR_STR2
6884 "Originate default route to this neighbor\n"
6885 "Route-map to specify criteria to originate default\n"
6886 "route-map name\n")
6887 {
6888 int idx_peer = 2;
6889 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6890 bgp_node_afi(vty),
6891 bgp_node_safi(vty), NULL, 0);
6892 }
6893
6894 ALIAS_HIDDEN(
6895 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6896 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6897 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6898 "Originate default route to this neighbor\n"
6899 "Route-map to specify criteria to originate default\n"
6900 "route-map name\n")
6901
6902
6903 /* Set neighbor's BGP port. */
6904 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6905 const char *port_str)
6906 {
6907 struct peer *peer;
6908 uint16_t port;
6909 struct servent *sp;
6910
6911 peer = peer_and_group_lookup_vty(vty, ip_str);
6912 if (!peer)
6913 return CMD_WARNING_CONFIG_FAILED;
6914
6915 if (!port_str) {
6916 sp = getservbyname("bgp", "tcp");
6917 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6918 } else {
6919 port = strtoul(port_str, NULL, 10);
6920 }
6921
6922 peer_port_set(peer, port);
6923
6924 return CMD_SUCCESS;
6925 }
6926
6927 /* Set specified peer's BGP port. */
6928 DEFUN (neighbor_port,
6929 neighbor_port_cmd,
6930 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6931 NEIGHBOR_STR
6932 NEIGHBOR_ADDR_STR2
6933 "Neighbor's BGP port\n"
6934 "TCP port number\n")
6935 {
6936 int idx_ip = 1;
6937 int idx_number = 3;
6938 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6939 argv[idx_number]->arg);
6940 }
6941
6942 DEFUN (no_neighbor_port,
6943 no_neighbor_port_cmd,
6944 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6945 NO_STR
6946 NEIGHBOR_STR
6947 NEIGHBOR_ADDR_STR2
6948 "Neighbor's BGP port\n"
6949 "TCP port number\n")
6950 {
6951 int idx_ip = 2;
6952 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6953 }
6954
6955
6956 /* neighbor weight. */
6957 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6958 safi_t safi, const char *weight_str)
6959 {
6960 int ret;
6961 struct peer *peer;
6962 unsigned long weight;
6963
6964 peer = peer_and_group_lookup_vty(vty, ip_str);
6965 if (!peer)
6966 return CMD_WARNING_CONFIG_FAILED;
6967
6968 weight = strtoul(weight_str, NULL, 10);
6969
6970 ret = peer_weight_set(peer, afi, safi, weight);
6971 return bgp_vty_return(vty, ret);
6972 }
6973
6974 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6975 safi_t safi)
6976 {
6977 int ret;
6978 struct peer *peer;
6979
6980 peer = peer_and_group_lookup_vty(vty, ip_str);
6981 if (!peer)
6982 return CMD_WARNING_CONFIG_FAILED;
6983
6984 ret = peer_weight_unset(peer, afi, safi);
6985 return bgp_vty_return(vty, ret);
6986 }
6987
6988 DEFUN (neighbor_weight,
6989 neighbor_weight_cmd,
6990 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6991 NEIGHBOR_STR
6992 NEIGHBOR_ADDR_STR2
6993 "Set default weight for routes from this neighbor\n"
6994 "default weight\n")
6995 {
6996 int idx_peer = 1;
6997 int idx_number = 3;
6998 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6999 bgp_node_safi(vty), argv[idx_number]->arg);
7000 }
7001
7002 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7003 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7004 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7005 "Set default weight for routes from this neighbor\n"
7006 "default weight\n")
7007
7008 DEFUN (no_neighbor_weight,
7009 no_neighbor_weight_cmd,
7010 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7011 NO_STR
7012 NEIGHBOR_STR
7013 NEIGHBOR_ADDR_STR2
7014 "Set default weight for routes from this neighbor\n"
7015 "default weight\n")
7016 {
7017 int idx_peer = 2;
7018 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7019 bgp_node_afi(vty), bgp_node_safi(vty));
7020 }
7021
7022 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7023 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7024 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7025 "Set default weight for routes from this neighbor\n"
7026 "default weight\n")
7027
7028
7029 /* Override capability negotiation. */
7030 DEFUN (neighbor_override_capability,
7031 neighbor_override_capability_cmd,
7032 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7033 NEIGHBOR_STR
7034 NEIGHBOR_ADDR_STR2
7035 "Override capability negotiation result\n")
7036 {
7037 int idx_peer = 1;
7038 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7039 PEER_FLAG_OVERRIDE_CAPABILITY);
7040 }
7041
7042 DEFUN (no_neighbor_override_capability,
7043 no_neighbor_override_capability_cmd,
7044 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7045 NO_STR
7046 NEIGHBOR_STR
7047 NEIGHBOR_ADDR_STR2
7048 "Override capability negotiation result\n")
7049 {
7050 int idx_peer = 2;
7051 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7052 PEER_FLAG_OVERRIDE_CAPABILITY);
7053 }
7054
7055 DEFUN (neighbor_strict_capability,
7056 neighbor_strict_capability_cmd,
7057 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7058 NEIGHBOR_STR
7059 NEIGHBOR_ADDR_STR2
7060 "Strict capability negotiation match\n")
7061 {
7062 int idx_peer = 1;
7063
7064 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7065 PEER_FLAG_STRICT_CAP_MATCH);
7066 }
7067
7068 DEFUN (no_neighbor_strict_capability,
7069 no_neighbor_strict_capability_cmd,
7070 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7071 NO_STR
7072 NEIGHBOR_STR
7073 NEIGHBOR_ADDR_STR2
7074 "Strict capability negotiation match\n")
7075 {
7076 int idx_peer = 2;
7077
7078 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7079 PEER_FLAG_STRICT_CAP_MATCH);
7080 }
7081
7082 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7083 const char *keep_str, const char *hold_str)
7084 {
7085 int ret;
7086 struct peer *peer;
7087 uint32_t keepalive;
7088 uint32_t holdtime;
7089
7090 peer = peer_and_group_lookup_vty(vty, ip_str);
7091 if (!peer)
7092 return CMD_WARNING_CONFIG_FAILED;
7093
7094 keepalive = strtoul(keep_str, NULL, 10);
7095 holdtime = strtoul(hold_str, NULL, 10);
7096
7097 ret = peer_timers_set(peer, keepalive, holdtime);
7098
7099 return bgp_vty_return(vty, ret);
7100 }
7101
7102 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7103 {
7104 int ret;
7105 struct peer *peer;
7106
7107 peer = peer_and_group_lookup_vty(vty, ip_str);
7108 if (!peer)
7109 return CMD_WARNING_CONFIG_FAILED;
7110
7111 ret = peer_timers_unset(peer);
7112
7113 return bgp_vty_return(vty, ret);
7114 }
7115
7116 DEFUN (neighbor_timers,
7117 neighbor_timers_cmd,
7118 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7119 NEIGHBOR_STR
7120 NEIGHBOR_ADDR_STR2
7121 "BGP per neighbor timers\n"
7122 "Keepalive interval\n"
7123 "Holdtime\n")
7124 {
7125 int idx_peer = 1;
7126 int idx_number = 3;
7127 int idx_number_2 = 4;
7128 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7129 argv[idx_number]->arg,
7130 argv[idx_number_2]->arg);
7131 }
7132
7133 DEFUN (no_neighbor_timers,
7134 no_neighbor_timers_cmd,
7135 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7136 NO_STR
7137 NEIGHBOR_STR
7138 NEIGHBOR_ADDR_STR2
7139 "BGP per neighbor timers\n"
7140 "Keepalive interval\n"
7141 "Holdtime\n")
7142 {
7143 int idx_peer = 2;
7144 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7145 }
7146
7147
7148 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7149 const char *time_str)
7150 {
7151 int ret;
7152 struct peer *peer;
7153 uint32_t connect;
7154
7155 peer = peer_and_group_lookup_vty(vty, ip_str);
7156 if (!peer)
7157 return CMD_WARNING_CONFIG_FAILED;
7158
7159 connect = strtoul(time_str, NULL, 10);
7160
7161 ret = peer_timers_connect_set(peer, connect);
7162
7163 return bgp_vty_return(vty, ret);
7164 }
7165
7166 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7167 {
7168 int ret;
7169 struct peer *peer;
7170
7171 peer = peer_and_group_lookup_vty(vty, ip_str);
7172 if (!peer)
7173 return CMD_WARNING_CONFIG_FAILED;
7174
7175 ret = peer_timers_connect_unset(peer);
7176
7177 return bgp_vty_return(vty, ret);
7178 }
7179
7180 DEFUN (neighbor_timers_connect,
7181 neighbor_timers_connect_cmd,
7182 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7183 NEIGHBOR_STR
7184 NEIGHBOR_ADDR_STR2
7185 "BGP per neighbor timers\n"
7186 "BGP connect timer\n"
7187 "Connect timer\n")
7188 {
7189 int idx_peer = 1;
7190 int idx_number = 4;
7191 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7192 argv[idx_number]->arg);
7193 }
7194
7195 DEFUN (no_neighbor_timers_connect,
7196 no_neighbor_timers_connect_cmd,
7197 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7198 NO_STR
7199 NEIGHBOR_STR
7200 NEIGHBOR_ADDR_STR2
7201 "BGP per neighbor timers\n"
7202 "BGP connect timer\n"
7203 "Connect timer\n")
7204 {
7205 int idx_peer = 2;
7206 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7207 }
7208
7209 DEFPY (neighbor_timers_delayopen,
7210 neighbor_timers_delayopen_cmd,
7211 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7212 NEIGHBOR_STR
7213 NEIGHBOR_ADDR_STR2
7214 "BGP per neighbor timers\n"
7215 "RFC 4271 DelayOpenTimer\n"
7216 "DelayOpenTime timer interval\n")
7217 {
7218 struct peer *peer;
7219
7220 peer = peer_and_group_lookup_vty(vty, neighbor);
7221 if (!peer)
7222 return CMD_WARNING_CONFIG_FAILED;
7223
7224 if (!interval) {
7225 if (peer_timers_delayopen_unset(peer))
7226 return CMD_WARNING_CONFIG_FAILED;
7227 } else {
7228 if (peer_timers_delayopen_set(peer, interval))
7229 return CMD_WARNING_CONFIG_FAILED;
7230 }
7231
7232 return CMD_SUCCESS;
7233 }
7234
7235 DEFPY (no_neighbor_timers_delayopen,
7236 no_neighbor_timers_delayopen_cmd,
7237 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7238 NO_STR
7239 NEIGHBOR_STR
7240 NEIGHBOR_ADDR_STR2
7241 "BGP per neighbor timers\n"
7242 "RFC 4271 DelayOpenTimer\n"
7243 "DelayOpenTime timer interval\n")
7244 {
7245 struct peer *peer;
7246
7247 peer = peer_and_group_lookup_vty(vty, neighbor);
7248 if (!peer)
7249 return CMD_WARNING_CONFIG_FAILED;
7250
7251 if (peer_timers_delayopen_unset(peer))
7252 return CMD_WARNING_CONFIG_FAILED;
7253
7254 return CMD_SUCCESS;
7255 }
7256
7257 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7258 const char *time_str, int set)
7259 {
7260 int ret;
7261 struct peer *peer;
7262 uint32_t routeadv = 0;
7263
7264 peer = peer_and_group_lookup_vty(vty, ip_str);
7265 if (!peer)
7266 return CMD_WARNING_CONFIG_FAILED;
7267
7268 if (time_str)
7269 routeadv = strtoul(time_str, NULL, 10);
7270
7271 if (set)
7272 ret = peer_advertise_interval_set(peer, routeadv);
7273 else
7274 ret = peer_advertise_interval_unset(peer);
7275
7276 return bgp_vty_return(vty, ret);
7277 }
7278
7279 DEFUN (neighbor_advertise_interval,
7280 neighbor_advertise_interval_cmd,
7281 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7282 NEIGHBOR_STR
7283 NEIGHBOR_ADDR_STR2
7284 "Minimum interval between sending BGP routing updates\n"
7285 "time in seconds\n")
7286 {
7287 int idx_peer = 1;
7288 int idx_number = 3;
7289 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7290 argv[idx_number]->arg, 1);
7291 }
7292
7293 DEFUN (no_neighbor_advertise_interval,
7294 no_neighbor_advertise_interval_cmd,
7295 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7296 NO_STR
7297 NEIGHBOR_STR
7298 NEIGHBOR_ADDR_STR2
7299 "Minimum interval between sending BGP routing updates\n"
7300 "time in seconds\n")
7301 {
7302 int idx_peer = 2;
7303 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7304 }
7305
7306
7307 /* Time to wait before processing route-map updates */
7308 DEFUN (bgp_set_route_map_delay_timer,
7309 bgp_set_route_map_delay_timer_cmd,
7310 "bgp route-map delay-timer (0-600)",
7311 SET_STR
7312 "BGP route-map delay timer\n"
7313 "Time in secs to wait before processing route-map changes\n"
7314 "0 disables the timer, no route updates happen when route-maps change\n")
7315 {
7316 int idx_number = 3;
7317 uint32_t rmap_delay_timer;
7318
7319 if (argv[idx_number]->arg) {
7320 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7321 bm->rmap_update_timer = rmap_delay_timer;
7322
7323 /* if the dynamic update handling is being disabled, and a timer
7324 * is
7325 * running, stop the timer and act as if the timer has already
7326 * fired.
7327 */
7328 if (!rmap_delay_timer && bm->t_rmap_update) {
7329 THREAD_OFF(bm->t_rmap_update);
7330 thread_execute(bm->master, bgp_route_map_update_timer,
7331 NULL, 0);
7332 }
7333 return CMD_SUCCESS;
7334 } else {
7335 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7336 return CMD_WARNING_CONFIG_FAILED;
7337 }
7338 }
7339
7340 DEFUN (no_bgp_set_route_map_delay_timer,
7341 no_bgp_set_route_map_delay_timer_cmd,
7342 "no bgp route-map delay-timer [(0-600)]",
7343 NO_STR
7344 BGP_STR
7345 "Default BGP route-map delay timer\n"
7346 "Reset to default time to wait for processing route-map changes\n"
7347 "0 disables the timer, no route updates happen when route-maps change\n")
7348 {
7349
7350 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7351
7352 return CMD_SUCCESS;
7353 }
7354
7355 /* neighbor interface */
7356 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7357 const char *str)
7358 {
7359 struct peer *peer;
7360
7361 peer = peer_lookup_vty(vty, ip_str);
7362 if (!peer || peer->conf_if) {
7363 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7364 return CMD_WARNING_CONFIG_FAILED;
7365 }
7366
7367 if (str)
7368 peer_interface_set(peer, str);
7369 else
7370 peer_interface_unset(peer);
7371
7372 return CMD_SUCCESS;
7373 }
7374
7375 DEFUN (neighbor_interface,
7376 neighbor_interface_cmd,
7377 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7378 NEIGHBOR_STR
7379 NEIGHBOR_ADDR_STR
7380 "Interface\n"
7381 "Interface name\n")
7382 {
7383 int idx_ip = 1;
7384 int idx_word = 3;
7385
7386 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7387 }
7388
7389 DEFUN (no_neighbor_interface,
7390 no_neighbor_interface_cmd,
7391 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7392 NO_STR
7393 NEIGHBOR_STR
7394 NEIGHBOR_ADDR_STR
7395 "Interface\n"
7396 "Interface name\n")
7397 {
7398 int idx_peer = 2;
7399
7400 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7401 }
7402
7403 DEFUN (neighbor_distribute_list,
7404 neighbor_distribute_list_cmd,
7405 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7406 NEIGHBOR_STR
7407 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 int idx_peer = 1;
7414 int idx_acl = 3;
7415 int direct, ret;
7416 struct peer *peer;
7417
7418 const char *pstr = argv[idx_peer]->arg;
7419 const char *acl = argv[idx_acl]->arg;
7420 const char *inout = argv[argc - 1]->text;
7421
7422 peer = peer_and_group_lookup_vty(vty, pstr);
7423 if (!peer)
7424 return CMD_WARNING_CONFIG_FAILED;
7425
7426 /* Check filter direction. */
7427 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7428 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7429 direct, acl);
7430
7431 return bgp_vty_return(vty, ret);
7432 }
7433
7434 ALIAS_HIDDEN(
7435 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7436 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7437 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7438 "Filter updates to/from this neighbor\n"
7439 "IP Access-list name\n"
7440 "Filter incoming updates\n"
7441 "Filter outgoing updates\n")
7442
7443 DEFUN (no_neighbor_distribute_list,
7444 no_neighbor_distribute_list_cmd,
7445 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7446 NO_STR
7447 NEIGHBOR_STR
7448 NEIGHBOR_ADDR_STR2
7449 "Filter updates to/from this neighbor\n"
7450 "IP Access-list name\n"
7451 "Filter incoming updates\n"
7452 "Filter outgoing updates\n")
7453 {
7454 int idx_peer = 2;
7455 int direct, ret;
7456 struct peer *peer;
7457
7458 const char *pstr = argv[idx_peer]->arg;
7459 const char *inout = argv[argc - 1]->text;
7460
7461 peer = peer_and_group_lookup_vty(vty, pstr);
7462 if (!peer)
7463 return CMD_WARNING_CONFIG_FAILED;
7464
7465 /* Check filter direction. */
7466 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7467 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7468 direct);
7469
7470 return bgp_vty_return(vty, ret);
7471 }
7472
7473 ALIAS_HIDDEN(
7474 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7475 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7476 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7477 "Filter updates to/from this neighbor\n"
7478 "IP Access-list name\n"
7479 "Filter incoming updates\n"
7480 "Filter outgoing updates\n")
7481
7482 /* Set prefix list to the peer. */
7483 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7484 afi_t afi, safi_t safi,
7485 const char *name_str,
7486 const char *direct_str)
7487 {
7488 int ret;
7489 int direct = FILTER_IN;
7490 struct peer *peer;
7491
7492 peer = peer_and_group_lookup_vty(vty, ip_str);
7493 if (!peer)
7494 return CMD_WARNING_CONFIG_FAILED;
7495
7496 /* Check filter direction. */
7497 if (strncmp(direct_str, "i", 1) == 0)
7498 direct = FILTER_IN;
7499 else if (strncmp(direct_str, "o", 1) == 0)
7500 direct = FILTER_OUT;
7501
7502 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7503
7504 return bgp_vty_return(vty, ret);
7505 }
7506
7507 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7508 afi_t afi, safi_t safi,
7509 const char *direct_str)
7510 {
7511 int ret;
7512 struct peer *peer;
7513 int direct = FILTER_IN;
7514
7515 peer = peer_and_group_lookup_vty(vty, ip_str);
7516 if (!peer)
7517 return CMD_WARNING_CONFIG_FAILED;
7518
7519 /* Check filter direction. */
7520 if (strncmp(direct_str, "i", 1) == 0)
7521 direct = FILTER_IN;
7522 else if (strncmp(direct_str, "o", 1) == 0)
7523 direct = FILTER_OUT;
7524
7525 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7526
7527 return bgp_vty_return(vty, ret);
7528 }
7529
7530 DEFUN (neighbor_prefix_list,
7531 neighbor_prefix_list_cmd,
7532 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7533 NEIGHBOR_STR
7534 NEIGHBOR_ADDR_STR2
7535 "Filter updates to/from this neighbor\n"
7536 "Name of a prefix list\n"
7537 "Filter incoming updates\n"
7538 "Filter outgoing updates\n")
7539 {
7540 int idx_peer = 1;
7541 int idx_word = 3;
7542 int idx_in_out = 4;
7543 return peer_prefix_list_set_vty(
7544 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7545 argv[idx_word]->arg, argv[idx_in_out]->arg);
7546 }
7547
7548 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7549 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7550 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7551 "Filter updates to/from this neighbor\n"
7552 "Name of a prefix list\n"
7553 "Filter incoming updates\n"
7554 "Filter outgoing updates\n")
7555
7556 DEFUN (no_neighbor_prefix_list,
7557 no_neighbor_prefix_list_cmd,
7558 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7559 NO_STR
7560 NEIGHBOR_STR
7561 NEIGHBOR_ADDR_STR2
7562 "Filter updates to/from this neighbor\n"
7563 "Name of a prefix list\n"
7564 "Filter incoming updates\n"
7565 "Filter outgoing updates\n")
7566 {
7567 int idx_peer = 2;
7568 int idx_in_out = 5;
7569 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7570 bgp_node_afi(vty), bgp_node_safi(vty),
7571 argv[idx_in_out]->arg);
7572 }
7573
7574 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7575 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7576 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7577 "Filter updates to/from this neighbor\n"
7578 "Name of a prefix list\n"
7579 "Filter incoming updates\n"
7580 "Filter outgoing updates\n")
7581
7582 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7583 safi_t safi, const char *name_str,
7584 const char *direct_str)
7585 {
7586 int ret;
7587 struct peer *peer;
7588 int direct = FILTER_IN;
7589
7590 peer = peer_and_group_lookup_vty(vty, ip_str);
7591 if (!peer)
7592 return CMD_WARNING_CONFIG_FAILED;
7593
7594 /* Check filter direction. */
7595 if (strncmp(direct_str, "i", 1) == 0)
7596 direct = FILTER_IN;
7597 else if (strncmp(direct_str, "o", 1) == 0)
7598 direct = FILTER_OUT;
7599
7600 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7601
7602 return bgp_vty_return(vty, ret);
7603 }
7604
7605 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7606 safi_t safi, const char *direct_str)
7607 {
7608 int ret;
7609 struct peer *peer;
7610 int direct = FILTER_IN;
7611
7612 peer = peer_and_group_lookup_vty(vty, ip_str);
7613 if (!peer)
7614 return CMD_WARNING_CONFIG_FAILED;
7615
7616 /* Check filter direction. */
7617 if (strncmp(direct_str, "i", 1) == 0)
7618 direct = FILTER_IN;
7619 else if (strncmp(direct_str, "o", 1) == 0)
7620 direct = FILTER_OUT;
7621
7622 ret = peer_aslist_unset(peer, afi, safi, direct);
7623
7624 return bgp_vty_return(vty, ret);
7625 }
7626
7627 DEFUN (neighbor_filter_list,
7628 neighbor_filter_list_cmd,
7629 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7630 NEIGHBOR_STR
7631 NEIGHBOR_ADDR_STR2
7632 "Establish BGP filters\n"
7633 "AS path access-list name\n"
7634 "Filter incoming routes\n"
7635 "Filter outgoing routes\n")
7636 {
7637 int idx_peer = 1;
7638 int idx_word = 3;
7639 int idx_in_out = 4;
7640 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7641 bgp_node_safi(vty), argv[idx_word]->arg,
7642 argv[idx_in_out]->arg);
7643 }
7644
7645 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7646 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7647 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7648 "Establish BGP filters\n"
7649 "AS path access-list name\n"
7650 "Filter incoming routes\n"
7651 "Filter outgoing routes\n")
7652
7653 DEFUN (no_neighbor_filter_list,
7654 no_neighbor_filter_list_cmd,
7655 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7656 NO_STR
7657 NEIGHBOR_STR
7658 NEIGHBOR_ADDR_STR2
7659 "Establish BGP filters\n"
7660 "AS path access-list name\n"
7661 "Filter incoming routes\n"
7662 "Filter outgoing routes\n")
7663 {
7664 int idx_peer = 2;
7665 int idx_in_out = 5;
7666 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7667 bgp_node_afi(vty), bgp_node_safi(vty),
7668 argv[idx_in_out]->arg);
7669 }
7670
7671 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7672 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7674 "Establish BGP filters\n"
7675 "AS path access-list name\n"
7676 "Filter incoming routes\n"
7677 "Filter outgoing routes\n")
7678
7679 /* Set advertise-map to the peer. */
7680 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7681 afi_t afi, safi_t safi,
7682 const char *advertise_str,
7683 const char *condition_str, bool condition,
7684 bool set)
7685 {
7686 int ret = CMD_WARNING_CONFIG_FAILED;
7687 struct peer *peer;
7688 struct route_map *advertise_map;
7689 struct route_map *condition_map;
7690
7691 peer = peer_and_group_lookup_vty(vty, ip_str);
7692 if (!peer)
7693 return ret;
7694
7695 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7696 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7697
7698 if (set)
7699 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7700 advertise_map, condition_str,
7701 condition_map, condition);
7702 else
7703 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7704 advertise_map, condition_str,
7705 condition_map, condition);
7706
7707 return bgp_vty_return(vty, ret);
7708 }
7709
7710 DEFPY (bgp_condadv_period,
7711 bgp_condadv_period_cmd,
7712 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7713 NO_STR
7714 BGP_STR
7715 "Conditional advertisement settings\n"
7716 "Set period to rescan BGP table to check if condition is met\n"
7717 "Period between BGP table scans, in seconds; default 60\n")
7718 {
7719 VTY_DECLVAR_CONTEXT(bgp, bgp);
7720
7721 bgp->condition_check_period =
7722 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7723
7724 return CMD_SUCCESS;
7725 }
7726
7727 DEFPY (neighbor_advertise_map,
7728 neighbor_advertise_map_cmd,
7729 "[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",
7730 NO_STR
7731 NEIGHBOR_STR
7732 NEIGHBOR_ADDR_STR2
7733 "Route-map to conditionally advertise routes\n"
7734 "Name of advertise map\n"
7735 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7736 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7737 "Name of the exist or non exist map\n")
7738 {
7739 bool condition = CONDITION_EXIST;
7740
7741 if (!strcmp(exist, "non-exist-map"))
7742 condition = CONDITION_NON_EXIST;
7743
7744 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7745 bgp_node_safi(vty), advertise_str,
7746 condition_str, condition, !no);
7747 }
7748
7749 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7750 "[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",
7751 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7752 "Route-map to conditionally advertise routes\n"
7753 "Name of advertise map\n"
7754 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7755 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7756 "Name of the exist or non exist map\n")
7757
7758 /* Set route-map to the peer. */
7759 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7760 afi_t afi, safi_t safi, const char *name_str,
7761 const char *direct_str)
7762 {
7763 int ret;
7764 struct peer *peer;
7765 int direct = RMAP_IN;
7766 struct route_map *route_map;
7767
7768 peer = peer_and_group_lookup_vty(vty, ip_str);
7769 if (!peer)
7770 return CMD_WARNING_CONFIG_FAILED;
7771
7772 /* Check filter direction. */
7773 if (strncmp(direct_str, "in", 2) == 0)
7774 direct = RMAP_IN;
7775 else if (strncmp(direct_str, "o", 1) == 0)
7776 direct = RMAP_OUT;
7777
7778 route_map = route_map_lookup_warn_noexist(vty, name_str);
7779 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7780
7781 return bgp_vty_return(vty, ret);
7782 }
7783
7784 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7785 afi_t afi, safi_t safi,
7786 const char *direct_str)
7787 {
7788 int ret;
7789 struct peer *peer;
7790 int direct = RMAP_IN;
7791
7792 peer = peer_and_group_lookup_vty(vty, ip_str);
7793 if (!peer)
7794 return CMD_WARNING_CONFIG_FAILED;
7795
7796 /* Check filter direction. */
7797 if (strncmp(direct_str, "in", 2) == 0)
7798 direct = RMAP_IN;
7799 else if (strncmp(direct_str, "o", 1) == 0)
7800 direct = RMAP_OUT;
7801
7802 ret = peer_route_map_unset(peer, afi, safi, direct);
7803
7804 return bgp_vty_return(vty, ret);
7805 }
7806
7807 DEFUN (neighbor_route_map,
7808 neighbor_route_map_cmd,
7809 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7810 NEIGHBOR_STR
7811 NEIGHBOR_ADDR_STR2
7812 "Apply route map to neighbor\n"
7813 "Name of route map\n"
7814 "Apply map to incoming routes\n"
7815 "Apply map to outbound routes\n")
7816 {
7817 int idx_peer = 1;
7818 int idx_word = 3;
7819 int idx_in_out = 4;
7820 return peer_route_map_set_vty(
7821 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7822 argv[idx_word]->arg, argv[idx_in_out]->arg);
7823 }
7824
7825 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7826 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7827 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7828 "Apply route map to neighbor\n"
7829 "Name of route map\n"
7830 "Apply map to incoming routes\n"
7831 "Apply map to outbound routes\n")
7832
7833 DEFUN (no_neighbor_route_map,
7834 no_neighbor_route_map_cmd,
7835 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7836 NO_STR
7837 NEIGHBOR_STR
7838 NEIGHBOR_ADDR_STR2
7839 "Apply route map to neighbor\n"
7840 "Name of route map\n"
7841 "Apply map to incoming routes\n"
7842 "Apply map to outbound routes\n")
7843 {
7844 int idx_peer = 2;
7845 int idx_in_out = 5;
7846 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7847 bgp_node_afi(vty), bgp_node_safi(vty),
7848 argv[idx_in_out]->arg);
7849 }
7850
7851 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7852 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7853 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7854 "Apply route map to neighbor\n"
7855 "Name of route map\n"
7856 "Apply map to incoming routes\n"
7857 "Apply map to outbound routes\n")
7858
7859 /* Set unsuppress-map to the peer. */
7860 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7861 afi_t afi, safi_t safi,
7862 const char *name_str)
7863 {
7864 int ret;
7865 struct peer *peer;
7866 struct route_map *route_map;
7867
7868 peer = peer_and_group_lookup_vty(vty, ip_str);
7869 if (!peer)
7870 return CMD_WARNING_CONFIG_FAILED;
7871
7872 route_map = route_map_lookup_warn_noexist(vty, name_str);
7873 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7874
7875 return bgp_vty_return(vty, ret);
7876 }
7877
7878 /* Unset route-map from the peer. */
7879 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7880 afi_t afi, safi_t safi)
7881 {
7882 int ret;
7883 struct peer *peer;
7884
7885 peer = peer_and_group_lookup_vty(vty, ip_str);
7886 if (!peer)
7887 return CMD_WARNING_CONFIG_FAILED;
7888
7889 ret = peer_unsuppress_map_unset(peer, afi, safi);
7890
7891 return bgp_vty_return(vty, ret);
7892 }
7893
7894 DEFUN (neighbor_unsuppress_map,
7895 neighbor_unsuppress_map_cmd,
7896 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7897 NEIGHBOR_STR
7898 NEIGHBOR_ADDR_STR2
7899 "Route-map to selectively unsuppress suppressed routes\n"
7900 "Name of route map\n")
7901 {
7902 int idx_peer = 1;
7903 int idx_word = 3;
7904 return peer_unsuppress_map_set_vty(
7905 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7906 argv[idx_word]->arg);
7907 }
7908
7909 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7910 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7912 "Route-map to selectively unsuppress suppressed routes\n"
7913 "Name of route map\n")
7914
7915 DEFUN (no_neighbor_unsuppress_map,
7916 no_neighbor_unsuppress_map_cmd,
7917 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7918 NO_STR
7919 NEIGHBOR_STR
7920 NEIGHBOR_ADDR_STR2
7921 "Route-map to selectively unsuppress suppressed routes\n"
7922 "Name of route map\n")
7923 {
7924 int idx_peer = 2;
7925 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7926 bgp_node_afi(vty),
7927 bgp_node_safi(vty));
7928 }
7929
7930 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7931 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7932 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7933 "Route-map to selectively unsuppress suppressed routes\n"
7934 "Name of route map\n")
7935
7936 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7937 afi_t afi, safi_t safi,
7938 const char *num_str,
7939 const char *threshold_str, int warning,
7940 const char *restart_str,
7941 const char *force_str)
7942 {
7943 int ret;
7944 struct peer *peer;
7945 uint32_t max;
7946 uint8_t threshold;
7947 uint16_t restart;
7948
7949 peer = peer_and_group_lookup_vty(vty, ip_str);
7950 if (!peer)
7951 return CMD_WARNING_CONFIG_FAILED;
7952
7953 max = strtoul(num_str, NULL, 10);
7954 if (threshold_str)
7955 threshold = atoi(threshold_str);
7956 else
7957 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7958
7959 if (restart_str)
7960 restart = atoi(restart_str);
7961 else
7962 restart = 0;
7963
7964 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7965 restart, force_str ? true : false);
7966
7967 return bgp_vty_return(vty, ret);
7968 }
7969
7970 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7971 afi_t afi, safi_t safi)
7972 {
7973 int ret;
7974 struct peer *peer;
7975
7976 peer = peer_and_group_lookup_vty(vty, ip_str);
7977 if (!peer)
7978 return CMD_WARNING_CONFIG_FAILED;
7979
7980 ret = peer_maximum_prefix_unset(peer, afi, safi);
7981
7982 return bgp_vty_return(vty, ret);
7983 }
7984
7985 /* Maximum number of prefix to be sent to the neighbor. */
7986 DEFUN(neighbor_maximum_prefix_out,
7987 neighbor_maximum_prefix_out_cmd,
7988 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7989 NEIGHBOR_STR
7990 NEIGHBOR_ADDR_STR2
7991 "Maximum number of prefixes to be sent to this peer\n"
7992 "Maximum no. of prefix limit\n")
7993 {
7994 int ret;
7995 int idx_peer = 1;
7996 int idx_number = 3;
7997 struct peer *peer;
7998 uint32_t max;
7999 afi_t afi = bgp_node_afi(vty);
8000 safi_t safi = bgp_node_safi(vty);
8001
8002 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8003 if (!peer)
8004 return CMD_WARNING_CONFIG_FAILED;
8005
8006 max = strtoul(argv[idx_number]->arg, NULL, 10);
8007
8008 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8009
8010 return bgp_vty_return(vty, ret);
8011 }
8012
8013 DEFUN(no_neighbor_maximum_prefix_out,
8014 no_neighbor_maximum_prefix_out_cmd,
8015 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8016 NO_STR
8017 NEIGHBOR_STR
8018 NEIGHBOR_ADDR_STR2
8019 "Maximum number of prefixes to be sent to this peer\n"
8020 "Maximum no. of prefix limit\n")
8021 {
8022 int ret;
8023 int idx_peer = 2;
8024 struct peer *peer;
8025 afi_t afi = bgp_node_afi(vty);
8026 safi_t safi = bgp_node_safi(vty);
8027
8028 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8029 if (!peer)
8030 return CMD_WARNING_CONFIG_FAILED;
8031
8032 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8033
8034 return bgp_vty_return(vty, ret);
8035 }
8036
8037 /* Maximum number of prefix configuration. Prefix count is different
8038 for each peer configuration. So this configuration can be set for
8039 each peer configuration. */
8040 DEFUN (neighbor_maximum_prefix,
8041 neighbor_maximum_prefix_cmd,
8042 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8043 NEIGHBOR_STR
8044 NEIGHBOR_ADDR_STR2
8045 "Maximum number of prefix accept from this peer\n"
8046 "maximum no. of prefix limit\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_force = 0;
8052 char *force = NULL;
8053
8054 if (argv_find(argv, argc, "force", &idx_force))
8055 force = argv[idx_force]->arg;
8056
8057 return peer_maximum_prefix_set_vty(
8058 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8059 argv[idx_number]->arg, NULL, 0, NULL, force);
8060 }
8061
8062 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8063 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8064 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8065 "Maximum number of prefix accept from this peer\n"
8066 "maximum no. of prefix limit\n"
8067 "Force checking all received routes not only accepted\n")
8068
8069 DEFUN (neighbor_maximum_prefix_threshold,
8070 neighbor_maximum_prefix_threshold_cmd,
8071 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8072 NEIGHBOR_STR
8073 NEIGHBOR_ADDR_STR2
8074 "Maximum number of prefix accept from this peer\n"
8075 "maximum no. of prefix limit\n"
8076 "Threshold value (%) at which to generate a warning msg\n"
8077 "Force checking all received routes not only accepted\n")
8078 {
8079 int idx_peer = 1;
8080 int idx_number = 3;
8081 int idx_number_2 = 4;
8082 int idx_force = 0;
8083 char *force = NULL;
8084
8085 if (argv_find(argv, argc, "force", &idx_force))
8086 force = argv[idx_force]->arg;
8087
8088 return peer_maximum_prefix_set_vty(
8089 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8090 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8091 }
8092
8093 ALIAS_HIDDEN(
8094 neighbor_maximum_prefix_threshold,
8095 neighbor_maximum_prefix_threshold_hidden_cmd,
8096 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8097 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8098 "Maximum number of prefix accept from this peer\n"
8099 "maximum no. of prefix limit\n"
8100 "Threshold value (%) at which to generate a warning msg\n"
8101 "Force checking all received routes not only accepted\n")
8102
8103 DEFUN (neighbor_maximum_prefix_warning,
8104 neighbor_maximum_prefix_warning_cmd,
8105 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8106 NEIGHBOR_STR
8107 NEIGHBOR_ADDR_STR2
8108 "Maximum number of prefix accept from this peer\n"
8109 "maximum no. of prefix limit\n"
8110 "Only give warning message when limit is exceeded\n"
8111 "Force checking all received routes not only accepted\n")
8112 {
8113 int idx_peer = 1;
8114 int idx_number = 3;
8115 int idx_force = 0;
8116 char *force = NULL;
8117
8118 if (argv_find(argv, argc, "force", &idx_force))
8119 force = argv[idx_force]->arg;
8120
8121 return peer_maximum_prefix_set_vty(
8122 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8123 argv[idx_number]->arg, NULL, 1, NULL, force);
8124 }
8125
8126 ALIAS_HIDDEN(
8127 neighbor_maximum_prefix_warning,
8128 neighbor_maximum_prefix_warning_hidden_cmd,
8129 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8130 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8131 "Maximum number of prefix accept from this peer\n"
8132 "maximum no. of prefix limit\n"
8133 "Only give warning message when limit is exceeded\n"
8134 "Force checking all received routes not only accepted\n")
8135
8136 DEFUN (neighbor_maximum_prefix_threshold_warning,
8137 neighbor_maximum_prefix_threshold_warning_cmd,
8138 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8139 NEIGHBOR_STR
8140 NEIGHBOR_ADDR_STR2
8141 "Maximum number of prefix accept from this peer\n"
8142 "maximum no. of prefix limit\n"
8143 "Threshold value (%) at which to generate a warning msg\n"
8144 "Only give warning message when limit is exceeded\n"
8145 "Force checking all received routes not only accepted\n")
8146 {
8147 int idx_peer = 1;
8148 int idx_number = 3;
8149 int idx_number_2 = 4;
8150 int idx_force = 0;
8151 char *force = NULL;
8152
8153 if (argv_find(argv, argc, "force", &idx_force))
8154 force = argv[idx_force]->arg;
8155
8156 return peer_maximum_prefix_set_vty(
8157 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8158 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8159 }
8160
8161 ALIAS_HIDDEN(
8162 neighbor_maximum_prefix_threshold_warning,
8163 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8164 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8166 "Maximum number of prefix accept from this peer\n"
8167 "maximum no. of prefix limit\n"
8168 "Threshold value (%) at which to generate a warning msg\n"
8169 "Only give warning message when limit is exceeded\n"
8170 "Force checking all received routes not only accepted\n")
8171
8172 DEFUN (neighbor_maximum_prefix_restart,
8173 neighbor_maximum_prefix_restart_cmd,
8174 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8175 NEIGHBOR_STR
8176 NEIGHBOR_ADDR_STR2
8177 "Maximum number of prefix accept from this peer\n"
8178 "maximum no. of prefix limit\n"
8179 "Restart bgp connection after limit is exceeded\n"
8180 "Restart interval in minutes\n"
8181 "Force checking all received routes not only accepted\n")
8182 {
8183 int idx_peer = 1;
8184 int idx_number = 3;
8185 int idx_number_2 = 5;
8186 int idx_force = 0;
8187 char *force = NULL;
8188
8189 if (argv_find(argv, argc, "force", &idx_force))
8190 force = argv[idx_force]->arg;
8191
8192 return peer_maximum_prefix_set_vty(
8193 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8194 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8195 }
8196
8197 ALIAS_HIDDEN(
8198 neighbor_maximum_prefix_restart,
8199 neighbor_maximum_prefix_restart_hidden_cmd,
8200 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8201 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8202 "Maximum number of prefix accept from this peer\n"
8203 "maximum no. of prefix limit\n"
8204 "Restart bgp connection after limit is exceeded\n"
8205 "Restart interval in minutes\n"
8206 "Force checking all received routes not only accepted\n")
8207
8208 DEFUN (neighbor_maximum_prefix_threshold_restart,
8209 neighbor_maximum_prefix_threshold_restart_cmd,
8210 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8211 NEIGHBOR_STR
8212 NEIGHBOR_ADDR_STR2
8213 "Maximum number of prefixes to accept from this peer\n"
8214 "maximum no. of prefix limit\n"
8215 "Threshold value (%) at which to generate a warning msg\n"
8216 "Restart bgp connection after limit is exceeded\n"
8217 "Restart interval in minutes\n"
8218 "Force checking all received routes not only accepted\n")
8219 {
8220 int idx_peer = 1;
8221 int idx_number = 3;
8222 int idx_number_2 = 4;
8223 int idx_number_3 = 6;
8224 int idx_force = 0;
8225 char *force = NULL;
8226
8227 if (argv_find(argv, argc, "force", &idx_force))
8228 force = argv[idx_force]->arg;
8229
8230 return peer_maximum_prefix_set_vty(
8231 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8232 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8233 argv[idx_number_3]->arg, force);
8234 }
8235
8236 ALIAS_HIDDEN(
8237 neighbor_maximum_prefix_threshold_restart,
8238 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8239 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8240 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8241 "Maximum number of prefixes to accept from this peer\n"
8242 "maximum no. of prefix limit\n"
8243 "Threshold value (%) at which to generate a warning msg\n"
8244 "Restart bgp connection after limit is exceeded\n"
8245 "Restart interval in minutes\n"
8246 "Force checking all received routes not only accepted\n")
8247
8248 DEFUN (no_neighbor_maximum_prefix,
8249 no_neighbor_maximum_prefix_cmd,
8250 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8251 NO_STR
8252 NEIGHBOR_STR
8253 NEIGHBOR_ADDR_STR2
8254 "Maximum number of prefixes to accept from this peer\n"
8255 "maximum no. of prefix limit\n"
8256 "Threshold value (%) at which to generate a warning msg\n"
8257 "Restart bgp connection after limit is exceeded\n"
8258 "Restart interval in minutes\n"
8259 "Only give warning message when limit is exceeded\n"
8260 "Force checking all received routes not only accepted\n")
8261 {
8262 int idx_peer = 2;
8263 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8264 bgp_node_afi(vty),
8265 bgp_node_safi(vty));
8266 }
8267
8268 ALIAS_HIDDEN(
8269 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8270 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8271 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8272 "Maximum number of prefixes to accept from this peer\n"
8273 "maximum no. of prefix limit\n"
8274 "Threshold value (%) at which to generate a warning msg\n"
8275 "Restart bgp connection after limit is exceeded\n"
8276 "Restart interval in minutes\n"
8277 "Only give warning message when limit is exceeded\n"
8278 "Force checking all received routes not only accepted\n")
8279
8280 /* "neighbor soo" */
8281 DEFPY (neighbor_soo,
8282 neighbor_soo_cmd,
8283 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8284 NEIGHBOR_STR
8285 NEIGHBOR_ADDR_STR2
8286 "Set the Site-of-Origin (SoO) extended community\n"
8287 "VPN extended community\n")
8288 {
8289 struct peer *peer;
8290 afi_t afi = bgp_node_afi(vty);
8291 safi_t safi = bgp_node_safi(vty);
8292 struct ecommunity *ecomm_soo;
8293
8294 peer = peer_and_group_lookup_vty(vty, neighbor);
8295 if (!peer)
8296 return CMD_WARNING_CONFIG_FAILED;
8297
8298 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8299 if (!ecomm_soo) {
8300 vty_out(vty, "%% Malformed SoO extended community\n");
8301 return CMD_WARNING;
8302 }
8303 ecommunity_str(ecomm_soo);
8304
8305 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8306 ecommunity_free(&peer->soo[afi][safi]);
8307 peer->soo[afi][safi] = ecomm_soo;
8308 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8309 }
8310
8311 return bgp_vty_return(vty,
8312 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8313 }
8314
8315 DEFPY (no_neighbor_soo,
8316 no_neighbor_soo_cmd,
8317 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8318 NO_STR
8319 NEIGHBOR_STR
8320 NEIGHBOR_ADDR_STR2
8321 "Set the Site-of-Origin (SoO) extended community\n"
8322 "VPN extended community\n")
8323 {
8324 struct peer *peer;
8325 afi_t afi = bgp_node_afi(vty);
8326 safi_t safi = bgp_node_safi(vty);
8327
8328 peer = peer_and_group_lookup_vty(vty, neighbor);
8329 if (!peer)
8330 return CMD_WARNING_CONFIG_FAILED;
8331
8332 ecommunity_free(&peer->soo[afi][safi]);
8333
8334 return bgp_vty_return(
8335 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8336 }
8337
8338 /* "neighbor allowas-in" */
8339 DEFUN (neighbor_allowas_in,
8340 neighbor_allowas_in_cmd,
8341 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8342 NEIGHBOR_STR
8343 NEIGHBOR_ADDR_STR2
8344 "Accept as-path with my AS present in it\n"
8345 "Number of occurrences of AS number\n"
8346 "Only accept my AS in the as-path if the route was originated in my AS\n")
8347 {
8348 int idx_peer = 1;
8349 int idx_number_origin = 3;
8350 int ret;
8351 int origin = 0;
8352 struct peer *peer;
8353 int allow_num = 0;
8354
8355 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8356 if (!peer)
8357 return CMD_WARNING_CONFIG_FAILED;
8358
8359 if (argc <= idx_number_origin)
8360 allow_num = 3;
8361 else {
8362 if (argv[idx_number_origin]->type == WORD_TKN)
8363 origin = 1;
8364 else
8365 allow_num = atoi(argv[idx_number_origin]->arg);
8366 }
8367
8368 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8369 allow_num, origin);
8370
8371 return bgp_vty_return(vty, ret);
8372 }
8373
8374 ALIAS_HIDDEN(
8375 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8376 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8377 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8378 "Accept as-path with my AS present in it\n"
8379 "Number of occurrences of AS number\n"
8380 "Only accept my AS in the as-path if the route was originated in my AS\n")
8381
8382 DEFUN (no_neighbor_allowas_in,
8383 no_neighbor_allowas_in_cmd,
8384 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8385 NO_STR
8386 NEIGHBOR_STR
8387 NEIGHBOR_ADDR_STR2
8388 "allow local ASN appears in aspath attribute\n"
8389 "Number of occurrences of AS number\n"
8390 "Only accept my AS in the as-path if the route was originated in my AS\n")
8391 {
8392 int idx_peer = 2;
8393 int ret;
8394 struct peer *peer;
8395
8396 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8397 if (!peer)
8398 return CMD_WARNING_CONFIG_FAILED;
8399
8400 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8401 bgp_node_safi(vty));
8402
8403 return bgp_vty_return(vty, ret);
8404 }
8405
8406 ALIAS_HIDDEN(
8407 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8408 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8409 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8410 "allow local ASN appears in aspath attribute\n"
8411 "Number of occurrences of AS number\n"
8412 "Only accept my AS in the as-path if the route was originated in my AS\n")
8413
8414 DEFUN (neighbor_ttl_security,
8415 neighbor_ttl_security_cmd,
8416 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8417 NEIGHBOR_STR
8418 NEIGHBOR_ADDR_STR2
8419 "BGP ttl-security parameters\n"
8420 "Specify the maximum number of hops to the BGP peer\n"
8421 "Number of hops to BGP peer\n")
8422 {
8423 int idx_peer = 1;
8424 int idx_number = 4;
8425 struct peer *peer;
8426 int gtsm_hops;
8427
8428 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8429 if (!peer)
8430 return CMD_WARNING_CONFIG_FAILED;
8431
8432 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8433
8434 /*
8435 * If 'neighbor swpX', then this is for directly connected peers,
8436 * we should not accept a ttl-security hops value greater than 1.
8437 */
8438 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8439 vty_out(vty,
8440 "%s is directly connected peer, hops cannot exceed 1\n",
8441 argv[idx_peer]->arg);
8442 return CMD_WARNING_CONFIG_FAILED;
8443 }
8444
8445 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8446 }
8447
8448 DEFUN (no_neighbor_ttl_security,
8449 no_neighbor_ttl_security_cmd,
8450 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8451 NO_STR
8452 NEIGHBOR_STR
8453 NEIGHBOR_ADDR_STR2
8454 "BGP ttl-security parameters\n"
8455 "Specify the maximum number of hops to the BGP peer\n"
8456 "Number of hops to BGP peer\n")
8457 {
8458 int idx_peer = 2;
8459 struct peer *peer;
8460
8461 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8462 if (!peer)
8463 return CMD_WARNING_CONFIG_FAILED;
8464
8465 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8466 }
8467
8468 /* disable-addpath-rx */
8469 DEFUN(neighbor_disable_addpath_rx,
8470 neighbor_disable_addpath_rx_cmd,
8471 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8472 NEIGHBOR_STR
8473 NEIGHBOR_ADDR_STR2
8474 "Do not accept additional paths\n")
8475 {
8476 char *peer_str = argv[1]->arg;
8477 struct peer *peer;
8478 afi_t afi = bgp_node_afi(vty);
8479 safi_t safi = bgp_node_safi(vty);
8480
8481 peer = peer_and_group_lookup_vty(vty, peer_str);
8482 if (!peer)
8483 return CMD_WARNING_CONFIG_FAILED;
8484
8485 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8486 PEER_FLAG_DISABLE_ADDPATH_RX);
8487 }
8488
8489 DEFUN(no_neighbor_disable_addpath_rx,
8490 no_neighbor_disable_addpath_rx_cmd,
8491 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8492 NO_STR
8493 NEIGHBOR_STR
8494 NEIGHBOR_ADDR_STR2
8495 "Do not accept additional paths\n")
8496 {
8497 char *peer_str = argv[2]->arg;
8498 struct peer *peer;
8499 afi_t afi = bgp_node_afi(vty);
8500 safi_t safi = bgp_node_safi(vty);
8501
8502 peer = peer_and_group_lookup_vty(vty, peer_str);
8503 if (!peer)
8504 return CMD_WARNING_CONFIG_FAILED;
8505
8506 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8507 PEER_FLAG_DISABLE_ADDPATH_RX);
8508 }
8509
8510 DEFUN (neighbor_addpath_tx_all_paths,
8511 neighbor_addpath_tx_all_paths_cmd,
8512 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8513 NEIGHBOR_STR
8514 NEIGHBOR_ADDR_STR2
8515 "Use addpath to advertise all paths to a neighbor\n")
8516 {
8517 int idx_peer = 1;
8518 struct peer *peer;
8519
8520 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8521 if (!peer)
8522 return CMD_WARNING_CONFIG_FAILED;
8523
8524 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8525 BGP_ADDPATH_ALL);
8526 return CMD_SUCCESS;
8527 }
8528
8529 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8530 neighbor_addpath_tx_all_paths_hidden_cmd,
8531 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8532 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8533 "Use addpath to advertise all paths to a neighbor\n")
8534
8535 DEFUN (no_neighbor_addpath_tx_all_paths,
8536 no_neighbor_addpath_tx_all_paths_cmd,
8537 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8538 NO_STR
8539 NEIGHBOR_STR
8540 NEIGHBOR_ADDR_STR2
8541 "Use addpath to advertise all paths to a neighbor\n")
8542 {
8543 int idx_peer = 2;
8544 struct peer *peer;
8545
8546 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8547 if (!peer)
8548 return CMD_WARNING_CONFIG_FAILED;
8549
8550 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8551 != BGP_ADDPATH_ALL) {
8552 vty_out(vty,
8553 "%% Peer not currently configured to transmit all paths.");
8554 return CMD_WARNING_CONFIG_FAILED;
8555 }
8556
8557 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8558 BGP_ADDPATH_NONE);
8559
8560 return CMD_SUCCESS;
8561 }
8562
8563 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8564 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8565 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8566 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8567 "Use addpath to advertise all paths to a neighbor\n")
8568
8569 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8570 neighbor_addpath_tx_bestpath_per_as_cmd,
8571 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8572 NEIGHBOR_STR
8573 NEIGHBOR_ADDR_STR2
8574 "Use addpath to advertise the bestpath per each neighboring AS\n")
8575 {
8576 int idx_peer = 1;
8577 struct peer *peer;
8578
8579 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8580 if (!peer)
8581 return CMD_WARNING_CONFIG_FAILED;
8582
8583 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8584 BGP_ADDPATH_BEST_PER_AS);
8585
8586 return CMD_SUCCESS;
8587 }
8588
8589 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8590 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8591 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8592 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8593 "Use addpath to advertise the bestpath per each neighboring AS\n")
8594
8595 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8596 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8597 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8598 NO_STR
8599 NEIGHBOR_STR
8600 NEIGHBOR_ADDR_STR2
8601 "Use addpath to advertise the bestpath per each neighboring AS\n")
8602 {
8603 int idx_peer = 2;
8604 struct peer *peer;
8605
8606 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8607 if (!peer)
8608 return CMD_WARNING_CONFIG_FAILED;
8609
8610 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8611 != BGP_ADDPATH_BEST_PER_AS) {
8612 vty_out(vty,
8613 "%% Peer not currently configured to transmit all best path per as.");
8614 return CMD_WARNING_CONFIG_FAILED;
8615 }
8616
8617 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8618 BGP_ADDPATH_NONE);
8619
8620 return CMD_SUCCESS;
8621 }
8622
8623 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8624 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8625 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8626 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8627 "Use addpath to advertise the bestpath per each neighboring AS\n")
8628
8629 DEFPY(
8630 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8631 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8632 NEIGHBOR_STR
8633 NEIGHBOR_ADDR_STR2
8634 "Detect AS loops before sending to neighbor\n")
8635 {
8636 struct peer *peer;
8637
8638 peer = peer_and_group_lookup_vty(vty, neighbor);
8639 if (!peer)
8640 return CMD_WARNING_CONFIG_FAILED;
8641
8642 peer->as_path_loop_detection = true;
8643
8644 return CMD_SUCCESS;
8645 }
8646
8647 DEFPY(
8648 no_neighbor_aspath_loop_detection,
8649 no_neighbor_aspath_loop_detection_cmd,
8650 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8651 NO_STR
8652 NEIGHBOR_STR
8653 NEIGHBOR_ADDR_STR2
8654 "Detect AS loops before sending to neighbor\n")
8655 {
8656 struct peer *peer;
8657
8658 peer = peer_and_group_lookup_vty(vty, neighbor);
8659 if (!peer)
8660 return CMD_WARNING_CONFIG_FAILED;
8661
8662 peer->as_path_loop_detection = false;
8663
8664 return CMD_SUCCESS;
8665 }
8666
8667 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8668 struct ecommunity **list, bool is_rt6)
8669 {
8670 struct ecommunity *ecom = NULL;
8671 struct ecommunity *ecomadd;
8672
8673 for (; argc; --argc, ++argv) {
8674 if (is_rt6)
8675 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8676 ECOMMUNITY_ROUTE_TARGET,
8677 0);
8678 else
8679 ecomadd = ecommunity_str2com(argv[0]->arg,
8680 ECOMMUNITY_ROUTE_TARGET,
8681 0);
8682 if (!ecomadd) {
8683 vty_out(vty, "Malformed community-list value\n");
8684 if (ecom)
8685 ecommunity_free(&ecom);
8686 return CMD_WARNING_CONFIG_FAILED;
8687 }
8688
8689 if (ecom) {
8690 ecommunity_merge(ecom, ecomadd);
8691 ecommunity_free(&ecomadd);
8692 } else {
8693 ecom = ecomadd;
8694 }
8695 }
8696
8697 if (*list) {
8698 ecommunity_free(&*list);
8699 }
8700 *list = ecom;
8701
8702 return CMD_SUCCESS;
8703 }
8704
8705 /*
8706 * v2vimport is true if we are handling a `import vrf ...` command
8707 */
8708 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8709 {
8710 afi_t afi;
8711
8712 switch (vty->node) {
8713 case BGP_IPV4_NODE:
8714 afi = AFI_IP;
8715 break;
8716 case BGP_IPV6_NODE:
8717 afi = AFI_IP6;
8718 break;
8719 default:
8720 vty_out(vty,
8721 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8722 return AFI_MAX;
8723 }
8724
8725 if (!v2vimport) {
8726 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8727 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8728 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8729 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8730 vty_out(vty,
8731 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8732 return AFI_MAX;
8733 }
8734 } else {
8735 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8736 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8737 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8738 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8739 vty_out(vty,
8740 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8741 return AFI_MAX;
8742 }
8743 }
8744 return afi;
8745 }
8746
8747 DEFPY (af_rd_vpn_export,
8748 af_rd_vpn_export_cmd,
8749 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8750 NO_STR
8751 "Specify route distinguisher\n"
8752 "Between current address-family and vpn\n"
8753 "For routes leaked from current address-family to vpn\n"
8754 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8755 {
8756 VTY_DECLVAR_CONTEXT(bgp, bgp);
8757 struct prefix_rd prd;
8758 int ret;
8759 afi_t afi;
8760 int idx = 0;
8761 bool yes = true;
8762
8763 if (argv_find(argv, argc, "no", &idx))
8764 yes = false;
8765
8766 if (yes) {
8767 ret = str2prefix_rd(rd_str, &prd);
8768 if (!ret) {
8769 vty_out(vty, "%% Malformed rd\n");
8770 return CMD_WARNING_CONFIG_FAILED;
8771 }
8772 }
8773
8774 afi = vpn_policy_getafi(vty, bgp, false);
8775 if (afi == AFI_MAX)
8776 return CMD_WARNING_CONFIG_FAILED;
8777
8778 /*
8779 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8780 */
8781 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8782 bgp_get_default(), bgp);
8783
8784 if (yes) {
8785 bgp->vpn_policy[afi].tovpn_rd = prd;
8786 SET_FLAG(bgp->vpn_policy[afi].flags,
8787 BGP_VPN_POLICY_TOVPN_RD_SET);
8788 } else {
8789 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8790 BGP_VPN_POLICY_TOVPN_RD_SET);
8791 }
8792
8793 /* post-change: re-export vpn routes */
8794 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8795 bgp_get_default(), bgp);
8796
8797 return CMD_SUCCESS;
8798 }
8799
8800 ALIAS (af_rd_vpn_export,
8801 af_no_rd_vpn_export_cmd,
8802 "no rd vpn export",
8803 NO_STR
8804 "Specify route distinguisher\n"
8805 "Between current address-family and vpn\n"
8806 "For routes leaked from current address-family to vpn\n")
8807
8808 DEFPY (af_label_vpn_export,
8809 af_label_vpn_export_cmd,
8810 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8811 NO_STR
8812 "label value for VRF\n"
8813 "Between current address-family and vpn\n"
8814 "For routes leaked from current address-family to vpn\n"
8815 "Label Value <0-1048575>\n"
8816 "Automatically assign a label\n")
8817 {
8818 VTY_DECLVAR_CONTEXT(bgp, bgp);
8819 mpls_label_t label = MPLS_LABEL_NONE;
8820 afi_t afi;
8821 int idx = 0;
8822 bool yes = true;
8823
8824 if (argv_find(argv, argc, "no", &idx))
8825 yes = false;
8826
8827 /* If "no ...", squash trailing parameter */
8828 if (!yes)
8829 label_auto = NULL;
8830
8831 if (yes) {
8832 if (!label_auto)
8833 label = label_val; /* parser should force unsigned */
8834 }
8835
8836 afi = vpn_policy_getafi(vty, bgp, false);
8837 if (afi == AFI_MAX)
8838 return CMD_WARNING_CONFIG_FAILED;
8839
8840
8841 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8842 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8843 /* no change */
8844 return CMD_SUCCESS;
8845
8846 /*
8847 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8848 */
8849 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8850 bgp_get_default(), bgp);
8851
8852 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8853 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8854
8855 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8856
8857 /*
8858 * label has previously been automatically
8859 * assigned by labelpool: release it
8860 *
8861 * NB if tovpn_label == MPLS_LABEL_NONE it
8862 * means the automatic assignment is in flight
8863 * and therefore the labelpool callback must
8864 * detect that the auto label is not needed.
8865 */
8866
8867 bgp_lp_release(LP_TYPE_VRF,
8868 &bgp->vpn_policy[afi],
8869 bgp->vpn_policy[afi].tovpn_label);
8870 }
8871 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8872 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8873 }
8874
8875 bgp->vpn_policy[afi].tovpn_label = label;
8876 if (label_auto) {
8877 SET_FLAG(bgp->vpn_policy[afi].flags,
8878 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8879 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8880 vpn_leak_label_callback);
8881 }
8882
8883 /* post-change: re-export vpn routes */
8884 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8885 bgp_get_default(), bgp);
8886
8887 hook_call(bgp_snmp_update_last_changed, bgp);
8888 return CMD_SUCCESS;
8889 }
8890
8891 DEFPY (af_sid_vpn_export,
8892 af_sid_vpn_export_cmd,
8893 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8894 NO_STR
8895 "sid value for VRF\n"
8896 "Between current address-family and vpn\n"
8897 "For routes leaked from current address-family to vpn\n"
8898 "Sid allocation index\n"
8899 "Automatically assign a label\n")
8900 {
8901 VTY_DECLVAR_CONTEXT(bgp, bgp);
8902 afi_t afi;
8903 int debug = 0;
8904 int idx = 0;
8905 bool yes = true;
8906
8907 if (argv_find(argv, argc, "no", &idx))
8908 yes = false;
8909 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8910 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8911
8912 afi = vpn_policy_getafi(vty, bgp, false);
8913 if (afi == AFI_MAX)
8914 return CMD_WARNING_CONFIG_FAILED;
8915
8916 if (!yes) {
8917 /* implement me */
8918 vty_out(vty, "It's not implemented\n");
8919 return CMD_WARNING_CONFIG_FAILED;
8920 }
8921
8922 /* skip when it's already configured */
8923 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8924 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8925 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8926 return CMD_SUCCESS;
8927
8928 /*
8929 * mode change between sid_idx and sid_auto isn't supported.
8930 * user must negate sid vpn export when they want to change the mode
8931 */
8932 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8933 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8934 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8935 vty_out(vty, "it's already configured as %s.\n",
8936 sid_auto ? "auto-mode" : "idx-mode");
8937 return CMD_WARNING_CONFIG_FAILED;
8938 }
8939
8940 /* pre-change */
8941 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8942 bgp_get_default(), bgp);
8943
8944 if (sid_auto) {
8945 /* SID allocation auto-mode */
8946 if (debug)
8947 zlog_debug("%s: auto sid alloc.", __func__);
8948 SET_FLAG(bgp->vpn_policy[afi].flags,
8949 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8950 } else {
8951 /* SID allocation index-mode */
8952 if (debug)
8953 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8954 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8955 }
8956
8957 /* post-change */
8958 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8959 bgp_get_default(), bgp);
8960 return CMD_SUCCESS;
8961 }
8962
8963 ALIAS (af_label_vpn_export,
8964 af_no_label_vpn_export_cmd,
8965 "no label vpn export",
8966 NO_STR
8967 "label value for VRF\n"
8968 "Between current address-family and vpn\n"
8969 "For routes leaked from current address-family to vpn\n")
8970
8971 DEFPY (af_nexthop_vpn_export,
8972 af_nexthop_vpn_export_cmd,
8973 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8974 NO_STR
8975 "Specify next hop to use for VRF advertised prefixes\n"
8976 "Between current address-family and vpn\n"
8977 "For routes leaked from current address-family to vpn\n"
8978 "IPv4 prefix\n"
8979 "IPv6 prefix\n")
8980 {
8981 VTY_DECLVAR_CONTEXT(bgp, bgp);
8982 afi_t afi;
8983 struct prefix p;
8984
8985 if (!no) {
8986 if (!nexthop_su) {
8987 vty_out(vty, "%% Nexthop required\n");
8988 return CMD_WARNING_CONFIG_FAILED;
8989 }
8990 if (!sockunion2hostprefix(nexthop_su, &p))
8991 return CMD_WARNING_CONFIG_FAILED;
8992 }
8993
8994 afi = vpn_policy_getafi(vty, bgp, false);
8995 if (afi == AFI_MAX)
8996 return CMD_WARNING_CONFIG_FAILED;
8997
8998 /*
8999 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9000 */
9001 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9002 bgp_get_default(), bgp);
9003
9004 if (!no) {
9005 bgp->vpn_policy[afi].tovpn_nexthop = p;
9006 SET_FLAG(bgp->vpn_policy[afi].flags,
9007 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9008 } else {
9009 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9010 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9011 }
9012
9013 /* post-change: re-export vpn routes */
9014 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9015 bgp_get_default(), bgp);
9016
9017 return CMD_SUCCESS;
9018 }
9019
9020 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9021 {
9022 if (!strcmp(dstr, "import")) {
9023 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9024 } else if (!strcmp(dstr, "export")) {
9025 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9026 } else if (!strcmp(dstr, "both")) {
9027 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9028 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9029 } else {
9030 vty_out(vty, "%% direction parse error\n");
9031 return CMD_WARNING_CONFIG_FAILED;
9032 }
9033 return CMD_SUCCESS;
9034 }
9035
9036 DEFPY (af_rt_vpn_imexport,
9037 af_rt_vpn_imexport_cmd,
9038 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9039 NO_STR
9040 "Specify route target list\n"
9041 "Specify route target list\n"
9042 "Between current address-family and vpn\n"
9043 "For routes leaked from vpn to current address-family: match any\n"
9044 "For routes leaked from current address-family to vpn: set\n"
9045 "both import: match any and export: set\n"
9046 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9047 {
9048 VTY_DECLVAR_CONTEXT(bgp, bgp);
9049 int ret;
9050 struct ecommunity *ecom = NULL;
9051 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9052 enum vpn_policy_direction dir;
9053 afi_t afi;
9054 int idx = 0;
9055 bool yes = true;
9056
9057 if (argv_find(argv, argc, "no", &idx))
9058 yes = false;
9059
9060 afi = vpn_policy_getafi(vty, bgp, false);
9061 if (afi == AFI_MAX)
9062 return CMD_WARNING_CONFIG_FAILED;
9063
9064 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9065 if (ret != CMD_SUCCESS)
9066 return ret;
9067
9068 if (yes) {
9069 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9070 vty_out(vty, "%% Missing RTLIST\n");
9071 return CMD_WARNING_CONFIG_FAILED;
9072 }
9073 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9074 if (ret != CMD_SUCCESS) {
9075 return ret;
9076 }
9077 }
9078
9079 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9080 if (!dodir[dir])
9081 continue;
9082
9083 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9084
9085 if (yes) {
9086 if (bgp->vpn_policy[afi].rtlist[dir])
9087 ecommunity_free(
9088 &bgp->vpn_policy[afi].rtlist[dir]);
9089 bgp->vpn_policy[afi].rtlist[dir] =
9090 ecommunity_dup(ecom);
9091 } else {
9092 if (bgp->vpn_policy[afi].rtlist[dir])
9093 ecommunity_free(
9094 &bgp->vpn_policy[afi].rtlist[dir]);
9095 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9096 }
9097
9098 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9099 }
9100
9101 if (ecom)
9102 ecommunity_free(&ecom);
9103
9104 return CMD_SUCCESS;
9105 }
9106
9107 ALIAS (af_rt_vpn_imexport,
9108 af_no_rt_vpn_imexport_cmd,
9109 "no <rt|route-target> vpn <import|export|both>$direction_str",
9110 NO_STR
9111 "Specify route target list\n"
9112 "Specify route target list\n"
9113 "Between current address-family and vpn\n"
9114 "For routes leaked from vpn to current address-family\n"
9115 "For routes leaked from current address-family to vpn\n"
9116 "both import and export\n")
9117
9118 DEFPY (af_route_map_vpn_imexport,
9119 af_route_map_vpn_imexport_cmd,
9120 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9121 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9122 NO_STR
9123 "Specify route map\n"
9124 "Between current address-family and vpn\n"
9125 "For routes leaked from vpn to current address-family\n"
9126 "For routes leaked from current address-family to vpn\n"
9127 "name of route-map\n")
9128 {
9129 VTY_DECLVAR_CONTEXT(bgp, bgp);
9130 int ret;
9131 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9132 enum vpn_policy_direction dir;
9133 afi_t afi;
9134 int idx = 0;
9135 bool yes = true;
9136
9137 if (argv_find(argv, argc, "no", &idx))
9138 yes = false;
9139
9140 afi = vpn_policy_getafi(vty, bgp, false);
9141 if (afi == AFI_MAX)
9142 return CMD_WARNING_CONFIG_FAILED;
9143
9144 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9145 if (ret != CMD_SUCCESS)
9146 return ret;
9147
9148 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9149 if (!dodir[dir])
9150 continue;
9151
9152 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9153
9154 if (yes) {
9155 if (bgp->vpn_policy[afi].rmap_name[dir])
9156 XFREE(MTYPE_ROUTE_MAP_NAME,
9157 bgp->vpn_policy[afi].rmap_name[dir]);
9158 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9159 MTYPE_ROUTE_MAP_NAME, rmap_str);
9160 bgp->vpn_policy[afi].rmap[dir] =
9161 route_map_lookup_warn_noexist(vty, rmap_str);
9162 if (!bgp->vpn_policy[afi].rmap[dir])
9163 return CMD_SUCCESS;
9164 } else {
9165 if (bgp->vpn_policy[afi].rmap_name[dir])
9166 XFREE(MTYPE_ROUTE_MAP_NAME,
9167 bgp->vpn_policy[afi].rmap_name[dir]);
9168 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9169 bgp->vpn_policy[afi].rmap[dir] = NULL;
9170 }
9171
9172 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9173 }
9174
9175 return CMD_SUCCESS;
9176 }
9177
9178 ALIAS (af_route_map_vpn_imexport,
9179 af_no_route_map_vpn_imexport_cmd,
9180 "no route-map vpn <import|export>$direction_str",
9181 NO_STR
9182 "Specify route map\n"
9183 "Between current address-family and vpn\n"
9184 "For routes leaked from vpn to current address-family\n"
9185 "For routes leaked from current address-family to vpn\n")
9186
9187 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9188 "import vrf route-map RMAP$rmap_str",
9189 "Import routes from another VRF\n"
9190 "Vrf routes being filtered\n"
9191 "Specify route map\n"
9192 "name of route-map\n")
9193 {
9194 VTY_DECLVAR_CONTEXT(bgp, bgp);
9195 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9196 afi_t afi;
9197 struct bgp *bgp_default;
9198
9199 afi = vpn_policy_getafi(vty, bgp, true);
9200 if (afi == AFI_MAX)
9201 return CMD_WARNING_CONFIG_FAILED;
9202
9203 bgp_default = bgp_get_default();
9204 if (!bgp_default) {
9205 int32_t ret;
9206 as_t as = bgp->as;
9207
9208 /* Auto-create assuming the same AS */
9209 ret = bgp_get_vty(&bgp_default, &as, NULL,
9210 BGP_INSTANCE_TYPE_DEFAULT);
9211
9212 if (ret) {
9213 vty_out(vty,
9214 "VRF default is not configured as a bgp instance\n");
9215 return CMD_WARNING;
9216 }
9217 }
9218
9219 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9220
9221 if (bgp->vpn_policy[afi].rmap_name[dir])
9222 XFREE(MTYPE_ROUTE_MAP_NAME,
9223 bgp->vpn_policy[afi].rmap_name[dir]);
9224 bgp->vpn_policy[afi].rmap_name[dir] =
9225 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9226 bgp->vpn_policy[afi].rmap[dir] =
9227 route_map_lookup_warn_noexist(vty, rmap_str);
9228 if (!bgp->vpn_policy[afi].rmap[dir])
9229 return CMD_SUCCESS;
9230
9231 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9232 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9233
9234 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9235
9236 return CMD_SUCCESS;
9237 }
9238
9239 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9240 "no import vrf route-map [RMAP$rmap_str]",
9241 NO_STR
9242 "Import routes from another VRF\n"
9243 "Vrf routes being filtered\n"
9244 "Specify route map\n"
9245 "name of route-map\n")
9246 {
9247 VTY_DECLVAR_CONTEXT(bgp, bgp);
9248 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9249 afi_t afi;
9250
9251 afi = vpn_policy_getafi(vty, bgp, true);
9252 if (afi == AFI_MAX)
9253 return CMD_WARNING_CONFIG_FAILED;
9254
9255 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9256
9257 if (bgp->vpn_policy[afi].rmap_name[dir])
9258 XFREE(MTYPE_ROUTE_MAP_NAME,
9259 bgp->vpn_policy[afi].rmap_name[dir]);
9260 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9261 bgp->vpn_policy[afi].rmap[dir] = NULL;
9262
9263 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9264 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9265 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9266
9267 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9268
9269 return CMD_SUCCESS;
9270 }
9271
9272 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9273 "[no] import vrf VIEWVRFNAME$import_name",
9274 NO_STR
9275 "Import routes from another VRF\n"
9276 "VRF to import from\n"
9277 "The name of the VRF\n")
9278 {
9279 VTY_DECLVAR_CONTEXT(bgp, bgp);
9280 struct listnode *node;
9281 struct bgp *vrf_bgp, *bgp_default;
9282 int32_t ret = 0;
9283 as_t as = bgp->as;
9284 bool remove = false;
9285 int32_t idx = 0;
9286 char *vname;
9287 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9288 safi_t safi;
9289 afi_t afi;
9290
9291 if (import_name == NULL) {
9292 vty_out(vty, "%% Missing import name\n");
9293 return CMD_WARNING;
9294 }
9295
9296 if (strcmp(import_name, "route-map") == 0) {
9297 vty_out(vty, "%% Must include route-map name\n");
9298 return CMD_WARNING;
9299 }
9300
9301 if (argv_find(argv, argc, "no", &idx))
9302 remove = true;
9303
9304 afi = vpn_policy_getafi(vty, bgp, true);
9305 if (afi == AFI_MAX)
9306 return CMD_WARNING_CONFIG_FAILED;
9307
9308 safi = bgp_node_safi(vty);
9309
9310 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9311 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9312 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9313 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9314 remove ? "unimport" : "import", import_name);
9315 return CMD_WARNING;
9316 }
9317
9318 bgp_default = bgp_get_default();
9319 if (!bgp_default) {
9320 /* Auto-create assuming the same AS */
9321 ret = bgp_get_vty(&bgp_default, &as, NULL,
9322 BGP_INSTANCE_TYPE_DEFAULT);
9323
9324 if (ret) {
9325 vty_out(vty,
9326 "VRF default is not configured as a bgp instance\n");
9327 return CMD_WARNING;
9328 }
9329 }
9330
9331 vrf_bgp = bgp_lookup_by_name(import_name);
9332 if (!vrf_bgp) {
9333 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9334 vrf_bgp = bgp_default;
9335 else
9336 /* Auto-create assuming the same AS */
9337 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9338
9339 if (ret) {
9340 vty_out(vty,
9341 "VRF %s is not configured as a bgp instance\n",
9342 import_name);
9343 return CMD_WARNING;
9344 }
9345 }
9346
9347 if (remove) {
9348 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9349 } else {
9350 /* Already importing from "import_vrf"? */
9351 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9352 vname)) {
9353 if (strcmp(vname, import_name) == 0)
9354 return CMD_WARNING;
9355 }
9356
9357 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9358 }
9359
9360 return CMD_SUCCESS;
9361 }
9362
9363 /* This command is valid only in a bgp vrf instance or the default instance */
9364 DEFPY (bgp_imexport_vpn,
9365 bgp_imexport_vpn_cmd,
9366 "[no] <import|export>$direction_str vpn",
9367 NO_STR
9368 "Import routes to this address-family\n"
9369 "Export routes from this address-family\n"
9370 "to/from default instance VPN RIB\n")
9371 {
9372 VTY_DECLVAR_CONTEXT(bgp, bgp);
9373 int previous_state;
9374 afi_t afi;
9375 safi_t safi;
9376 int idx = 0;
9377 bool yes = true;
9378 int flag;
9379 enum vpn_policy_direction dir;
9380
9381 if (argv_find(argv, argc, "no", &idx))
9382 yes = false;
9383
9384 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9385 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9386
9387 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9388 return CMD_WARNING_CONFIG_FAILED;
9389 }
9390
9391 afi = bgp_node_afi(vty);
9392 safi = bgp_node_safi(vty);
9393 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9394 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9395 return CMD_WARNING_CONFIG_FAILED;
9396 }
9397
9398 if (!strcmp(direction_str, "import")) {
9399 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9400 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9401 } else if (!strcmp(direction_str, "export")) {
9402 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9403 dir = BGP_VPN_POLICY_DIR_TOVPN;
9404 } else {
9405 vty_out(vty, "%% unknown direction %s\n", direction_str);
9406 return CMD_WARNING_CONFIG_FAILED;
9407 }
9408
9409 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9410
9411 if (yes) {
9412 SET_FLAG(bgp->af_flags[afi][safi], flag);
9413 if (!previous_state) {
9414 /* trigger export current vrf */
9415 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9416 }
9417 } else {
9418 if (previous_state) {
9419 /* trigger un-export current vrf */
9420 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9421 }
9422 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9423 }
9424
9425 hook_call(bgp_snmp_init_stats, bgp);
9426
9427 return CMD_SUCCESS;
9428 }
9429
9430 DEFPY (af_routetarget_import,
9431 af_routetarget_import_cmd,
9432 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9433 NO_STR
9434 "Specify route target list\n"
9435 "Specify route target list\n"
9436 "Specify route target list\n"
9437 "Specify route target list\n"
9438 "Flow-spec redirect type route target\n"
9439 "Import routes to this address-family\n"
9440 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9441 {
9442 VTY_DECLVAR_CONTEXT(bgp, bgp);
9443 int ret;
9444 struct ecommunity *ecom = NULL;
9445 afi_t afi;
9446 int idx = 0, idx_unused = 0;
9447 bool yes = true;
9448 bool rt6 = false;
9449
9450 if (argv_find(argv, argc, "no", &idx))
9451 yes = false;
9452
9453 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9454 argv_find(argv, argc, "route-target6", &idx_unused))
9455 rt6 = true;
9456
9457 afi = vpn_policy_getafi(vty, bgp, false);
9458 if (afi == AFI_MAX)
9459 return CMD_WARNING_CONFIG_FAILED;
9460
9461 if (rt6 && afi != AFI_IP6)
9462 return CMD_WARNING_CONFIG_FAILED;
9463
9464 if (yes) {
9465 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9466 vty_out(vty, "%% Missing RTLIST\n");
9467 return CMD_WARNING_CONFIG_FAILED;
9468 }
9469 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9470 if (ret != CMD_SUCCESS)
9471 return ret;
9472 }
9473
9474 if (yes) {
9475 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9476 ecommunity_free(&bgp->vpn_policy[afi]
9477 .import_redirect_rtlist);
9478 bgp->vpn_policy[afi].import_redirect_rtlist =
9479 ecommunity_dup(ecom);
9480 } else {
9481 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9482 ecommunity_free(&bgp->vpn_policy[afi]
9483 .import_redirect_rtlist);
9484 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9485 }
9486
9487 if (ecom)
9488 ecommunity_free(&ecom);
9489
9490 return CMD_SUCCESS;
9491 }
9492
9493 DEFUN_NOSH (address_family_ipv4_safi,
9494 address_family_ipv4_safi_cmd,
9495 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9496 "Enter Address Family command mode\n"
9497 BGP_AF_STR
9498 BGP_SAFI_WITH_LABEL_HELP_STR)
9499 {
9500
9501 if (argc == 3) {
9502 VTY_DECLVAR_CONTEXT(bgp, bgp);
9503 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9504 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9505 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9506 && safi != SAFI_EVPN) {
9507 vty_out(vty,
9508 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9509 return CMD_WARNING_CONFIG_FAILED;
9510 }
9511 vty->node = bgp_node_type(AFI_IP, safi);
9512 } else
9513 vty->node = BGP_IPV4_NODE;
9514
9515 return CMD_SUCCESS;
9516 }
9517
9518 DEFUN_NOSH (address_family_ipv6_safi,
9519 address_family_ipv6_safi_cmd,
9520 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9521 "Enter Address Family command mode\n"
9522 BGP_AF_STR
9523 BGP_SAFI_WITH_LABEL_HELP_STR)
9524 {
9525 if (argc == 3) {
9526 VTY_DECLVAR_CONTEXT(bgp, bgp);
9527 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9528 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9529 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9530 && safi != SAFI_EVPN) {
9531 vty_out(vty,
9532 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9533 return CMD_WARNING_CONFIG_FAILED;
9534 }
9535 vty->node = bgp_node_type(AFI_IP6, safi);
9536 } else
9537 vty->node = BGP_IPV6_NODE;
9538
9539 return CMD_SUCCESS;
9540 }
9541
9542 #ifdef KEEP_OLD_VPN_COMMANDS
9543 DEFUN_NOSH (address_family_vpnv4,
9544 address_family_vpnv4_cmd,
9545 "address-family vpnv4 [unicast]",
9546 "Enter Address Family command mode\n"
9547 BGP_AF_STR
9548 BGP_AF_MODIFIER_STR)
9549 {
9550 vty->node = BGP_VPNV4_NODE;
9551 return CMD_SUCCESS;
9552 }
9553
9554 DEFUN_NOSH (address_family_vpnv6,
9555 address_family_vpnv6_cmd,
9556 "address-family vpnv6 [unicast]",
9557 "Enter Address Family command mode\n"
9558 BGP_AF_STR
9559 BGP_AF_MODIFIER_STR)
9560 {
9561 vty->node = BGP_VPNV6_NODE;
9562 return CMD_SUCCESS;
9563 }
9564 #endif /* KEEP_OLD_VPN_COMMANDS */
9565
9566 DEFUN_NOSH (address_family_evpn,
9567 address_family_evpn_cmd,
9568 "address-family l2vpn evpn",
9569 "Enter Address Family command mode\n"
9570 BGP_AF_STR
9571 BGP_AF_MODIFIER_STR)
9572 {
9573 VTY_DECLVAR_CONTEXT(bgp, bgp);
9574 vty->node = BGP_EVPN_NODE;
9575 return CMD_SUCCESS;
9576 }
9577
9578 DEFUN_NOSH (bgp_segment_routing_srv6,
9579 bgp_segment_routing_srv6_cmd,
9580 "segment-routing srv6",
9581 "Segment-Routing configuration\n"
9582 "Segment-Routing SRv6 configuration\n")
9583 {
9584 VTY_DECLVAR_CONTEXT(bgp, bgp);
9585 bgp->srv6_enabled = true;
9586 vty->node = BGP_SRV6_NODE;
9587 return CMD_SUCCESS;
9588 }
9589
9590 DEFUN (no_bgp_segment_routing_srv6,
9591 no_bgp_segment_routing_srv6_cmd,
9592 "no segment-routing srv6",
9593 NO_STR
9594 "Segment-Routing configuration\n"
9595 "Segment-Routing SRv6 configuration\n")
9596 {
9597 VTY_DECLVAR_CONTEXT(bgp, bgp);
9598
9599 if (strlen(bgp->srv6_locator_name) > 0)
9600 if (bgp_srv6_locator_unset(bgp) < 0)
9601 return CMD_WARNING_CONFIG_FAILED;
9602
9603 bgp->srv6_enabled = false;
9604 return CMD_SUCCESS;
9605 }
9606
9607 DEFPY (bgp_srv6_locator,
9608 bgp_srv6_locator_cmd,
9609 "locator NAME$name",
9610 "Specify SRv6 locator\n"
9611 "Specify SRv6 locator\n")
9612 {
9613 VTY_DECLVAR_CONTEXT(bgp, bgp);
9614 int ret;
9615
9616 if (strlen(bgp->srv6_locator_name) > 0
9617 && strcmp(name, bgp->srv6_locator_name) != 0) {
9618 vty_out(vty, "srv6 locator is already configured\n");
9619 return CMD_WARNING_CONFIG_FAILED;
9620 }
9621
9622 snprintf(bgp->srv6_locator_name,
9623 sizeof(bgp->srv6_locator_name), "%s", name);
9624
9625 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9626 if (ret < 0)
9627 return CMD_WARNING_CONFIG_FAILED;
9628
9629 return CMD_SUCCESS;
9630 }
9631
9632 DEFPY (no_bgp_srv6_locator,
9633 no_bgp_srv6_locator_cmd,
9634 "no locator NAME$name",
9635 NO_STR
9636 "Specify SRv6 locator\n"
9637 "Specify SRv6 locator\n")
9638 {
9639 VTY_DECLVAR_CONTEXT(bgp, bgp);
9640
9641 /* when locator isn't configured, do nothing */
9642 if (strlen(bgp->srv6_locator_name) < 1)
9643 return CMD_SUCCESS;
9644
9645 /* name validation */
9646 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9647 vty_out(vty, "%% No srv6 locator is configured\n");
9648 return CMD_WARNING_CONFIG_FAILED;
9649 }
9650
9651 /* unset locator */
9652 if (bgp_srv6_locator_unset(bgp) < 0)
9653 return CMD_WARNING_CONFIG_FAILED;
9654
9655 return CMD_SUCCESS;
9656 }
9657
9658 DEFPY (show_bgp_srv6,
9659 show_bgp_srv6_cmd,
9660 "show bgp segment-routing srv6",
9661 SHOW_STR
9662 BGP_STR
9663 "BGP Segment Routing\n"
9664 "BGP Segment Routing SRv6\n")
9665 {
9666 struct bgp *bgp;
9667 struct listnode *node;
9668 struct srv6_locator_chunk *chunk;
9669 struct bgp_srv6_function *func;
9670 char buf[256];
9671
9672 bgp = bgp_get_default();
9673 if (!bgp)
9674 return CMD_SUCCESS;
9675
9676 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9677 vty_out(vty, "locator_chunks:\n");
9678 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk))
9679 vty_out(vty, "- %pFX\n", &chunk->prefix);
9680
9681 vty_out(vty, "functions:\n");
9682 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9683 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9684 vty_out(vty, "- sid: %s\n", buf);
9685 vty_out(vty, " locator: %s\n", func->locator_name);
9686 }
9687
9688 vty_out(vty, "bgps:\n");
9689 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9690 vty_out(vty, "- name: %s\n",
9691 bgp->name ? bgp->name : "default");
9692
9693 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9694 bgp->vpn_policy[AFI_IP].tovpn_sid);
9695 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9696 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9697 }
9698
9699 return CMD_SUCCESS;
9700 }
9701
9702 DEFUN_NOSH (exit_address_family,
9703 exit_address_family_cmd,
9704 "exit-address-family",
9705 "Exit from Address Family configuration mode\n")
9706 {
9707 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9708 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9709 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9710 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9711 || vty->node == BGP_EVPN_NODE
9712 || vty->node == BGP_FLOWSPECV4_NODE
9713 || vty->node == BGP_FLOWSPECV6_NODE)
9714 vty->node = BGP_NODE;
9715 return CMD_SUCCESS;
9716 }
9717
9718 /* Recalculate bestpath and re-advertise a prefix */
9719 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9720 const char *ip_str, afi_t afi, safi_t safi,
9721 struct prefix_rd *prd)
9722 {
9723 int ret;
9724 struct prefix match;
9725 struct bgp_dest *dest;
9726 struct bgp_dest *rm;
9727 struct bgp *bgp;
9728 struct bgp_table *table;
9729 struct bgp_table *rib;
9730
9731 /* BGP structure lookup. */
9732 if (view_name) {
9733 bgp = bgp_lookup_by_name(view_name);
9734 if (bgp == NULL) {
9735 vty_out(vty, "%% Can't find BGP instance %s\n",
9736 view_name);
9737 return CMD_WARNING;
9738 }
9739 } else {
9740 bgp = bgp_get_default();
9741 if (bgp == NULL) {
9742 vty_out(vty, "%% No BGP process is configured\n");
9743 return CMD_WARNING;
9744 }
9745 }
9746
9747 /* Check IP address argument. */
9748 ret = str2prefix(ip_str, &match);
9749 if (!ret) {
9750 vty_out(vty, "%% address is malformed\n");
9751 return CMD_WARNING;
9752 }
9753
9754 match.family = afi2family(afi);
9755 rib = bgp->rib[afi][safi];
9756
9757 if (safi == SAFI_MPLS_VPN) {
9758 for (dest = bgp_table_top(rib); dest;
9759 dest = bgp_route_next(dest)) {
9760 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9761
9762 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9763 continue;
9764
9765 table = bgp_dest_get_bgp_table_info(dest);
9766 if (table == NULL)
9767 continue;
9768
9769 rm = bgp_node_match(table, &match);
9770 if (rm != NULL) {
9771 const struct prefix *rm_p =
9772 bgp_dest_get_prefix(rm);
9773
9774 if (rm_p->prefixlen == match.prefixlen) {
9775 SET_FLAG(rm->flags,
9776 BGP_NODE_USER_CLEAR);
9777 bgp_process(bgp, rm, afi, safi);
9778 }
9779 bgp_dest_unlock_node(rm);
9780 }
9781 }
9782 } else {
9783 dest = bgp_node_match(rib, &match);
9784 if (dest != NULL) {
9785 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9786
9787 if (dest_p->prefixlen == match.prefixlen) {
9788 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9789 bgp_process(bgp, dest, afi, safi);
9790 }
9791 bgp_dest_unlock_node(dest);
9792 }
9793 }
9794
9795 return CMD_SUCCESS;
9796 }
9797
9798 /* one clear bgp command to rule them all */
9799 DEFUN (clear_ip_bgp_all,
9800 clear_ip_bgp_all_cmd,
9801 "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>]",
9802 CLEAR_STR
9803 IP_STR
9804 BGP_STR
9805 BGP_INSTANCE_HELP_STR
9806 BGP_AFI_HELP_STR
9807 BGP_AF_STR
9808 BGP_SAFI_WITH_LABEL_HELP_STR
9809 BGP_AF_MODIFIER_STR
9810 "Clear all peers\n"
9811 "BGP IPv4 neighbor to clear\n"
9812 "BGP IPv6 neighbor to clear\n"
9813 "BGP neighbor on interface to clear\n"
9814 "Clear peers with the AS number\n"
9815 "Clear all external peers\n"
9816 "Clear all members of peer-group\n"
9817 "BGP peer-group name\n"
9818 BGP_SOFT_STR
9819 BGP_SOFT_IN_STR
9820 BGP_SOFT_OUT_STR
9821 BGP_SOFT_IN_STR
9822 "Push out prefix-list ORF and do inbound soft reconfig\n"
9823 BGP_SOFT_OUT_STR
9824 "Reset message statistics\n")
9825 {
9826 char *vrf = NULL;
9827
9828 afi_t afi = AFI_UNSPEC;
9829 safi_t safi = SAFI_UNSPEC;
9830 enum clear_sort clr_sort = clear_peer;
9831 enum bgp_clear_type clr_type;
9832 char *clr_arg = NULL;
9833
9834 int idx = 0;
9835
9836 /* clear [ip] bgp */
9837 if (argv_find(argv, argc, "ip", &idx))
9838 afi = AFI_IP;
9839
9840 /* [<vrf> VIEWVRFNAME] */
9841 if (argv_find(argv, argc, "vrf", &idx)) {
9842 vrf = argv[idx + 1]->arg;
9843 idx += 2;
9844 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9845 vrf = NULL;
9846 } else if (argv_find(argv, argc, "view", &idx)) {
9847 /* [<view> VIEWVRFNAME] */
9848 vrf = argv[idx + 1]->arg;
9849 idx += 2;
9850 }
9851 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9852 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9853 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9854
9855 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9856 if (argv_find(argv, argc, "*", &idx)) {
9857 clr_sort = clear_all;
9858 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9859 clr_sort = clear_peer;
9860 clr_arg = argv[idx]->arg;
9861 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9862 clr_sort = clear_peer;
9863 clr_arg = argv[idx]->arg;
9864 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9865 clr_sort = clear_group;
9866 idx++;
9867 clr_arg = argv[idx]->arg;
9868 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9869 clr_sort = clear_peer;
9870 clr_arg = argv[idx]->arg;
9871 } else if (argv_find(argv, argc, "WORD", &idx)) {
9872 clr_sort = clear_peer;
9873 clr_arg = argv[idx]->arg;
9874 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9875 clr_sort = clear_as;
9876 clr_arg = argv[idx]->arg;
9877 } else if (argv_find(argv, argc, "external", &idx)) {
9878 clr_sort = clear_external;
9879 }
9880
9881 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9882 if (argv_find(argv, argc, "soft", &idx)) {
9883 if (argv_find(argv, argc, "in", &idx)
9884 || argv_find(argv, argc, "out", &idx))
9885 clr_type = strmatch(argv[idx]->text, "in")
9886 ? BGP_CLEAR_SOFT_IN
9887 : BGP_CLEAR_SOFT_OUT;
9888 else
9889 clr_type = BGP_CLEAR_SOFT_BOTH;
9890 } else if (argv_find(argv, argc, "in", &idx)) {
9891 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9892 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9893 : BGP_CLEAR_SOFT_IN;
9894 } else if (argv_find(argv, argc, "out", &idx)) {
9895 clr_type = BGP_CLEAR_SOFT_OUT;
9896 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9897 clr_type = BGP_CLEAR_MESSAGE_STATS;
9898 } else
9899 clr_type = BGP_CLEAR_SOFT_NONE;
9900
9901 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9902 }
9903
9904 DEFUN (clear_ip_bgp_prefix,
9905 clear_ip_bgp_prefix_cmd,
9906 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9907 CLEAR_STR
9908 IP_STR
9909 BGP_STR
9910 BGP_INSTANCE_HELP_STR
9911 "Clear bestpath and re-advertise\n"
9912 "IPv4 prefix\n")
9913 {
9914 char *vrf = NULL;
9915 char *prefix = NULL;
9916
9917 int idx = 0;
9918
9919 /* [<view|vrf> VIEWVRFNAME] */
9920 if (argv_find(argv, argc, "vrf", &idx)) {
9921 vrf = argv[idx + 1]->arg;
9922 idx += 2;
9923 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9924 vrf = NULL;
9925 } else if (argv_find(argv, argc, "view", &idx)) {
9926 /* [<view> VIEWVRFNAME] */
9927 vrf = argv[idx + 1]->arg;
9928 idx += 2;
9929 }
9930
9931 prefix = argv[argc - 1]->arg;
9932
9933 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9934 }
9935
9936 DEFUN (clear_bgp_ipv6_safi_prefix,
9937 clear_bgp_ipv6_safi_prefix_cmd,
9938 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9939 CLEAR_STR
9940 IP_STR
9941 BGP_STR
9942 BGP_AF_STR
9943 BGP_SAFI_HELP_STR
9944 "Clear bestpath and re-advertise\n"
9945 "IPv6 prefix\n")
9946 {
9947 int idx_safi = 0;
9948 int idx_ipv6_prefix = 0;
9949 safi_t safi = SAFI_UNICAST;
9950 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9951 argv[idx_ipv6_prefix]->arg : NULL;
9952
9953 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9954 return bgp_clear_prefix(
9955 vty, NULL, prefix, AFI_IP6,
9956 safi, NULL);
9957 }
9958
9959 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9960 clear_bgp_instance_ipv6_safi_prefix_cmd,
9961 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9962 CLEAR_STR
9963 IP_STR
9964 BGP_STR
9965 BGP_INSTANCE_HELP_STR
9966 BGP_AF_STR
9967 BGP_SAFI_HELP_STR
9968 "Clear bestpath and re-advertise\n"
9969 "IPv6 prefix\n")
9970 {
9971 int idx_safi = 0;
9972 int idx_vrfview = 0;
9973 int idx_ipv6_prefix = 0;
9974 safi_t safi = SAFI_UNICAST;
9975 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9976 argv[idx_ipv6_prefix]->arg : NULL;
9977 char *vrfview = NULL;
9978
9979 /* [<view|vrf> VIEWVRFNAME] */
9980 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9981 vrfview = argv[idx_vrfview + 1]->arg;
9982 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9983 vrfview = NULL;
9984 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9985 /* [<view> VIEWVRFNAME] */
9986 vrfview = argv[idx_vrfview + 1]->arg;
9987 }
9988 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9989
9990 return bgp_clear_prefix(
9991 vty, vrfview, prefix,
9992 AFI_IP6, safi, NULL);
9993 }
9994
9995 DEFUN (show_bgp_views,
9996 show_bgp_views_cmd,
9997 "show [ip] bgp views",
9998 SHOW_STR
9999 IP_STR
10000 BGP_STR
10001 "Show the defined BGP views\n")
10002 {
10003 struct list *inst = bm->bgp;
10004 struct listnode *node;
10005 struct bgp *bgp;
10006
10007 vty_out(vty, "Defined BGP views:\n");
10008 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10009 /* Skip VRFs. */
10010 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10011 continue;
10012 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10013 bgp->as);
10014 }
10015
10016 return CMD_SUCCESS;
10017 }
10018
10019 DEFUN (show_bgp_vrfs,
10020 show_bgp_vrfs_cmd,
10021 "show [ip] bgp vrfs [json]",
10022 SHOW_STR
10023 IP_STR
10024 BGP_STR
10025 "Show BGP VRFs\n"
10026 JSON_STR)
10027 {
10028 char buf[ETHER_ADDR_STRLEN];
10029 struct list *inst = bm->bgp;
10030 struct listnode *node;
10031 struct bgp *bgp;
10032 bool uj = use_json(argc, argv);
10033 json_object *json = NULL;
10034 json_object *json_vrfs = NULL;
10035 int count = 0;
10036
10037 if (uj) {
10038 json = json_object_new_object();
10039 json_vrfs = json_object_new_object();
10040 }
10041
10042 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10043 const char *name, *type;
10044 struct peer *peer;
10045 struct listnode *node2, *nnode2;
10046 int peers_cfg, peers_estb;
10047 json_object *json_vrf = NULL;
10048
10049 /* Skip Views. */
10050 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10051 continue;
10052
10053 count++;
10054 if (!uj && count == 1) {
10055 vty_out(vty,
10056 "%4s %-5s %-16s %9s %10s %-37s\n",
10057 "Type", "Id", "routerId", "#PeersCfg",
10058 "#PeersEstb", "Name");
10059 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10060 "L3-VNI", "RouterMAC", "Interface");
10061 }
10062
10063 peers_cfg = peers_estb = 0;
10064 if (uj)
10065 json_vrf = json_object_new_object();
10066
10067
10068 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10069 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10070 continue;
10071 peers_cfg++;
10072 if (peer_established(peer))
10073 peers_estb++;
10074 }
10075
10076 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10077 name = VRF_DEFAULT_NAME;
10078 type = "DFLT";
10079 } else {
10080 name = bgp->name;
10081 type = "VRF";
10082 }
10083
10084
10085 if (uj) {
10086 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10087 ? -1
10088 : (int64_t)bgp->vrf_id;
10089 char buf[BUFSIZ] = {0};
10090
10091 json_object_string_add(json_vrf, "type", type);
10092 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10093 json_object_string_addf(json_vrf, "routerId", "%pI4",
10094 &bgp->router_id);
10095 json_object_int_add(json_vrf, "numConfiguredPeers",
10096 peers_cfg);
10097 json_object_int_add(json_vrf, "numEstablishedPeers",
10098 peers_estb);
10099
10100 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10101 json_object_string_add(
10102 json_vrf, "rmac",
10103 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10104 json_object_string_add(json_vrf, "interface",
10105 ifindex2ifname(bgp->l3vni_svi_ifindex,
10106 bgp->vrf_id));
10107 json_object_object_add(json_vrfs, name, json_vrf);
10108 } else {
10109 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10110 type,
10111 bgp->vrf_id == VRF_UNKNOWN ? -1
10112 : (int)bgp->vrf_id,
10113 &bgp->router_id, peers_cfg, peers_estb, name);
10114 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10115 bgp->l3vni,
10116 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10117 ifindex2ifname(bgp->l3vni_svi_ifindex,
10118 bgp->vrf_id));
10119 }
10120 }
10121
10122 if (uj) {
10123 json_object_object_add(json, "vrfs", json_vrfs);
10124
10125 json_object_int_add(json, "totalVrfs", count);
10126
10127 vty_json(vty, json);
10128 } else {
10129 if (count)
10130 vty_out(vty,
10131 "\nTotal number of VRFs (including default): %d\n",
10132 count);
10133 }
10134
10135 return CMD_SUCCESS;
10136 }
10137
10138 DEFUN (show_bgp_mac_hash,
10139 show_bgp_mac_hash_cmd,
10140 "show bgp mac hash",
10141 SHOW_STR
10142 BGP_STR
10143 "Mac Address\n"
10144 "Mac Address database\n")
10145 {
10146 bgp_mac_dump_table(vty);
10147
10148 return CMD_SUCCESS;
10149 }
10150
10151 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10152 {
10153 struct vty *vty = (struct vty *)args;
10154 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10155
10156 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10157 }
10158
10159 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10160 {
10161 vty_out(vty, "self nexthop database:\n");
10162 bgp_nexthop_show_address_hash(vty, bgp);
10163
10164 vty_out(vty, "Tunnel-ip database:\n");
10165 hash_iterate(bgp->tip_hash,
10166 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10167 vty);
10168 }
10169
10170 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10171 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10172 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10173 "martian next-hops\n"
10174 "martian next-hop database\n")
10175 {
10176 struct bgp *bgp = NULL;
10177 int idx = 0;
10178 char *name = NULL;
10179
10180 /* [<vrf> VIEWVRFNAME] */
10181 if (argv_find(argv, argc, "vrf", &idx)) {
10182 name = argv[idx + 1]->arg;
10183 if (name && strmatch(name, VRF_DEFAULT_NAME))
10184 name = NULL;
10185 } else if (argv_find(argv, argc, "view", &idx))
10186 /* [<view> VIEWVRFNAME] */
10187 name = argv[idx + 1]->arg;
10188 if (name)
10189 bgp = bgp_lookup_by_name(name);
10190 else
10191 bgp = bgp_get_default();
10192
10193 if (!bgp) {
10194 vty_out(vty, "%% No BGP process is configured\n");
10195 return CMD_WARNING;
10196 }
10197 bgp_show_martian_nexthops(vty, bgp);
10198
10199 return CMD_SUCCESS;
10200 }
10201
10202 DEFUN (show_bgp_memory,
10203 show_bgp_memory_cmd,
10204 "show [ip] bgp memory",
10205 SHOW_STR
10206 IP_STR
10207 BGP_STR
10208 "Global BGP memory statistics\n")
10209 {
10210 char memstrbuf[MTYPE_MEMSTR_LEN];
10211 unsigned long count;
10212
10213 /* RIB related usage stats */
10214 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10215 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10216 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10217 count * sizeof(struct bgp_dest)));
10218
10219 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10220 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10221 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10222 count * sizeof(struct bgp_path_info)));
10223 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10224 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10225 count,
10226 mtype_memstr(
10227 memstrbuf, sizeof(memstrbuf),
10228 count * sizeof(struct bgp_path_info_extra)));
10229
10230 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10231 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10232 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10233 count * sizeof(struct bgp_static)));
10234
10235 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10236 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10237 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10238 count * sizeof(struct bpacket)));
10239
10240 /* Adj-In/Out */
10241 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10242 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10243 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10244 count * sizeof(struct bgp_adj_in)));
10245 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10246 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10247 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10248 count * sizeof(struct bgp_adj_out)));
10249
10250 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10251 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10252 count,
10253 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10254 count * sizeof(struct bgp_nexthop_cache)));
10255
10256 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10257 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10258 count,
10259 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10260 count * sizeof(struct bgp_damp_info)));
10261
10262 /* Attributes */
10263 count = attr_count();
10264 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10265 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10266 count * sizeof(struct attr)));
10267
10268 if ((count = attr_unknown_count()))
10269 vty_out(vty, "%ld unknown attributes\n", count);
10270
10271 /* AS_PATH attributes */
10272 count = aspath_count();
10273 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10274 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10275 count * sizeof(struct aspath)));
10276
10277 count = mtype_stats_alloc(MTYPE_AS_SEG);
10278 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10279 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10280 count * sizeof(struct assegment)));
10281
10282 /* Other attributes */
10283 if ((count = community_count()))
10284 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10285 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10286 count * sizeof(struct community)));
10287 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10288 vty_out(vty,
10289 "%ld BGP ext-community entries, using %s of memory\n",
10290 count,
10291 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10292 count * sizeof(struct ecommunity)));
10293 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10294 vty_out(vty,
10295 "%ld BGP large-community entries, using %s of memory\n",
10296 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10297 count * sizeof(struct lcommunity)));
10298
10299 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10300 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10301 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10302 count * sizeof(struct cluster_list)));
10303
10304 /* Peer related usage */
10305 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10306 vty_out(vty, "%ld peers, using %s of memory\n", count,
10307 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10308 count * sizeof(struct peer)));
10309
10310 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10311 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10312 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10313 count * sizeof(struct peer_group)));
10314
10315 /* Other */
10316 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10317 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10318 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10319 count * sizeof(regex_t)));
10320 return CMD_SUCCESS;
10321 }
10322
10323 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10324 {
10325 json_object *bestpath = json_object_new_object();
10326
10327 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10328 json_object_string_add(bestpath, "asPath", "ignore");
10329
10330 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10331 json_object_string_add(bestpath, "asPath", "confed");
10332
10333 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10334 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10335 json_object_string_add(bestpath, "multiPathRelax",
10336 "as-set");
10337 else
10338 json_object_string_add(bestpath, "multiPathRelax",
10339 "true");
10340 } else
10341 json_object_string_add(bestpath, "multiPathRelax", "false");
10342
10343 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10344 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10345
10346 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10347 json_object_string_add(bestpath, "compareRouterId", "true");
10348 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10349 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10350 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10351 json_object_string_add(bestpath, "med", "confed");
10352 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10353 json_object_string_add(bestpath, "med",
10354 "missing-as-worst");
10355 else
10356 json_object_string_add(bestpath, "med", "true");
10357 }
10358
10359 json_object_object_add(json, "bestPath", bestpath);
10360 }
10361
10362 /* Print the error code/subcode for why the peer is down */
10363 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10364 json_object *json_peer, bool use_json)
10365 {
10366 const char *code_str;
10367 const char *subcode_str;
10368
10369 if (use_json) {
10370 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10371 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10372 char errorcodesubcode_hexstr[5];
10373 char errorcodesubcode_str[256];
10374
10375 code_str = bgp_notify_code_str(peer->notify.code);
10376 subcode_str = bgp_notify_subcode_str(
10377 peer->notify.code,
10378 peer->notify.subcode);
10379
10380 snprintf(errorcodesubcode_hexstr,
10381 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10382 peer->notify.code, peer->notify.subcode);
10383 json_object_string_add(json_peer,
10384 "lastErrorCodeSubcode",
10385 errorcodesubcode_hexstr);
10386 snprintf(errorcodesubcode_str, 255, "%s%s",
10387 code_str, subcode_str);
10388 json_object_string_add(json_peer,
10389 "lastNotificationReason",
10390 errorcodesubcode_str);
10391 json_object_boolean_add(json_peer,
10392 "lastNotificationHardReset",
10393 peer->notify.hard_reset);
10394 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10395 && peer->notify.code == BGP_NOTIFY_CEASE
10396 && (peer->notify.subcode
10397 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10398 || peer->notify.subcode
10399 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10400 && peer->notify.length) {
10401 char msgbuf[1024];
10402 const char *msg_str;
10403
10404 msg_str = bgp_notify_admin_message(
10405 msgbuf, sizeof(msgbuf),
10406 (uint8_t *)peer->notify.data,
10407 peer->notify.length);
10408 if (msg_str)
10409 json_object_string_add(
10410 json_peer,
10411 "lastShutdownDescription",
10412 msg_str);
10413 }
10414
10415 }
10416 json_object_string_add(json_peer, "lastResetDueTo",
10417 peer_down_str[(int)peer->last_reset]);
10418 json_object_int_add(json_peer, "lastResetCode",
10419 peer->last_reset);
10420 } else {
10421 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10422 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10423 code_str = bgp_notify_code_str(peer->notify.code);
10424 subcode_str =
10425 bgp_notify_subcode_str(peer->notify.code,
10426 peer->notify.subcode);
10427 vty_out(vty, " Notification %s (%s%s%s)\n",
10428 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10429 ? "sent"
10430 : "received",
10431 code_str, subcode_str,
10432 peer->notify.hard_reset
10433 ? bgp_notify_subcode_str(
10434 BGP_NOTIFY_CEASE,
10435 BGP_NOTIFY_CEASE_HARD_RESET)
10436 : "");
10437 } else {
10438 vty_out(vty, " %s\n",
10439 peer_down_str[(int)peer->last_reset]);
10440 }
10441 }
10442 }
10443
10444 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10445 safi_t safi)
10446 {
10447 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10448 }
10449
10450 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10451 struct peer *peer, json_object *json_peer,
10452 int max_neighbor_width, bool use_json)
10453 {
10454 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10455 int len;
10456
10457 if (use_json) {
10458 if (peer_dynamic_neighbor(peer))
10459 json_object_boolean_true_add(json_peer,
10460 "dynamicPeer");
10461 if (peer->hostname)
10462 json_object_string_add(json_peer, "hostname",
10463 peer->hostname);
10464
10465 if (peer->domainname)
10466 json_object_string_add(json_peer, "domainname",
10467 peer->domainname);
10468 json_object_int_add(json_peer, "connectionsEstablished",
10469 peer->established);
10470 json_object_int_add(json_peer, "connectionsDropped",
10471 peer->dropped);
10472 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10473 use_json, json_peer);
10474 if (peer_established(peer))
10475 json_object_string_add(json_peer, "lastResetDueTo",
10476 "AFI/SAFI Not Negotiated");
10477 else
10478 bgp_show_peer_reset(NULL, peer, json_peer, true);
10479 } else {
10480 dn_flag[1] = '\0';
10481 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10482 if (peer->hostname
10483 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10484 len = vty_out(vty, "%s%s(%s)", dn_flag,
10485 peer->hostname, peer->host);
10486 else
10487 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10488
10489 /* pad the neighbor column with spaces */
10490 if (len < max_neighbor_width)
10491 vty_out(vty, "%*s", max_neighbor_width - len,
10492 " ");
10493 vty_out(vty, "%7d %7d %9s", peer->established,
10494 peer->dropped,
10495 peer_uptime(peer->uptime, timebuf,
10496 BGP_UPTIME_LEN, 0, NULL));
10497 if (peer_established(peer))
10498 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10499 else
10500 bgp_show_peer_reset(vty, peer, NULL,
10501 false);
10502 }
10503 }
10504
10505 /* Strip peer's description to the given size. */
10506 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10507 {
10508 static char stripped[BUFSIZ];
10509 uint32_t i = 0;
10510 uint32_t last_space = 0;
10511
10512 while (i < size) {
10513 if (*(desc + i) == 0) {
10514 stripped[i] = '\0';
10515 return stripped;
10516 }
10517 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10518 last_space = i;
10519 stripped[i] = *(desc + i);
10520 i++;
10521 }
10522
10523 if (last_space > size)
10524 stripped[size + 1] = '\0';
10525 else
10526 stripped[last_space] = '\0';
10527
10528 return stripped;
10529 }
10530
10531 /* Determine whether var peer should be filtered out of the summary. */
10532 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10533 struct peer *fpeer, int as_type,
10534 as_t as)
10535 {
10536
10537 /* filter neighbor XXXX */
10538 if (fpeer && fpeer != peer)
10539 return true;
10540
10541 /* filter remote-as (internal|external) */
10542 if (as_type != AS_UNSPECIFIED) {
10543 if (peer->as_type == AS_SPECIFIED) {
10544 if (as_type == AS_INTERNAL) {
10545 if (peer->as != peer->local_as)
10546 return true;
10547 } else if (peer->as == peer->local_as)
10548 return true;
10549 } else if (as_type != peer->as_type)
10550 return true;
10551 } else if (as && as != peer->as) /* filter remote-as XXX */
10552 return true;
10553
10554 return false;
10555 }
10556
10557 /* Show BGP peer's summary information.
10558 *
10559 * Peer's description is stripped according to if `wide` option is given
10560 * or not.
10561 *
10562 * When adding new columns to `show bgp summary` output, please make
10563 * sure `Desc` is the lastest column to show because it can contain
10564 * whitespaces and the whole output will be tricky.
10565 */
10566 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10567 struct peer *fpeer, int as_type, as_t as,
10568 uint16_t show_flags)
10569 {
10570 struct peer *peer;
10571 struct listnode *node, *nnode;
10572 unsigned int count = 0, dn_count = 0;
10573 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10574 char neighbor_buf[VTY_BUFSIZ];
10575 int neighbor_col_default_width = 16;
10576 int len, failed_count = 0;
10577 unsigned int filtered_count = 0;
10578 int max_neighbor_width = 0;
10579 int pfx_rcd_safi;
10580 json_object *json = NULL;
10581 json_object *json_peer = NULL;
10582 json_object *json_peers = NULL;
10583 struct peer_af *paf;
10584 struct bgp_filter *filter;
10585 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10586 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10587 bool show_established =
10588 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10589 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10590 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10591
10592 /* labeled-unicast routes are installed in the unicast table so in order
10593 * to
10594 * display the correct PfxRcd value we must look at SAFI_UNICAST
10595 */
10596
10597 if (safi == SAFI_LABELED_UNICAST)
10598 pfx_rcd_safi = SAFI_UNICAST;
10599 else
10600 pfx_rcd_safi = safi;
10601
10602 if (use_json) {
10603 json = json_object_new_object();
10604 json_peers = json_object_new_object();
10605 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10606 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10607 as_type, as)) {
10608 filtered_count++;
10609 count++;
10610 continue;
10611 }
10612
10613 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10614 continue;
10615
10616 if (peer->afc[afi][safi]) {
10617 /* See if we have at least a single failed peer */
10618 if (bgp_has_peer_failed(peer, afi, safi))
10619 failed_count++;
10620 count++;
10621 }
10622 if (peer_dynamic_neighbor(peer))
10623 dn_count++;
10624 }
10625
10626 } else {
10627 /* Loop over all neighbors that will be displayed to determine
10628 * how many
10629 * characters are needed for the Neighbor column
10630 */
10631 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10632 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10633 as_type, as)) {
10634 filtered_count++;
10635 count++;
10636 continue;
10637 }
10638
10639 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10640 continue;
10641
10642 if (peer->afc[afi][safi]) {
10643 memset(dn_flag, '\0', sizeof(dn_flag));
10644 if (peer_dynamic_neighbor(peer))
10645 dn_flag[0] = '*';
10646
10647 if (peer->hostname
10648 && CHECK_FLAG(bgp->flags,
10649 BGP_FLAG_SHOW_HOSTNAME))
10650 snprintf(neighbor_buf,
10651 sizeof(neighbor_buf),
10652 "%s%s(%s) ", dn_flag,
10653 peer->hostname, peer->host);
10654 else
10655 snprintf(neighbor_buf,
10656 sizeof(neighbor_buf), "%s%s ",
10657 dn_flag, peer->host);
10658
10659 len = strlen(neighbor_buf);
10660
10661 if (len > max_neighbor_width)
10662 max_neighbor_width = len;
10663
10664 /* See if we have at least a single failed peer */
10665 if (bgp_has_peer_failed(peer, afi, safi))
10666 failed_count++;
10667 count++;
10668 }
10669 }
10670
10671 /* Originally we displayed the Neighbor column as 16
10672 * characters wide so make that the default
10673 */
10674 if (max_neighbor_width < neighbor_col_default_width)
10675 max_neighbor_width = neighbor_col_default_width;
10676 }
10677
10678 if (show_failed && !failed_count) {
10679 if (use_json) {
10680 json_object_int_add(json, "failedPeersCount", 0);
10681 json_object_int_add(json, "dynamicPeers", dn_count);
10682 json_object_int_add(json, "totalPeers", count);
10683
10684 vty_json(vty, json);
10685 } else {
10686 vty_out(vty, "%% No failed BGP neighbors found\n");
10687 }
10688 return CMD_SUCCESS;
10689 }
10690
10691 count = 0; /* Reset the value as its used again */
10692 filtered_count = 0;
10693 dn_count = 0;
10694 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10695 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10696 continue;
10697
10698 if (!peer->afc[afi][safi])
10699 continue;
10700
10701 if (!count) {
10702 unsigned long ents;
10703 char memstrbuf[MTYPE_MEMSTR_LEN];
10704 int64_t vrf_id_ui;
10705
10706 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10707 ? -1
10708 : (int64_t)bgp->vrf_id;
10709
10710 /* Usage summary and header */
10711 if (use_json) {
10712 json_object_string_addf(json, "routerId",
10713 "%pI4",
10714 &bgp->router_id);
10715 json_object_int_add(json, "as", bgp->as);
10716 json_object_int_add(json, "vrfId", vrf_id_ui);
10717 json_object_string_add(
10718 json, "vrfName",
10719 (bgp->inst_type
10720 == BGP_INSTANCE_TYPE_DEFAULT)
10721 ? VRF_DEFAULT_NAME
10722 : bgp->name);
10723 } else {
10724 vty_out(vty,
10725 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10726 &bgp->router_id, bgp->as,
10727 bgp->vrf_id == VRF_UNKNOWN
10728 ? -1
10729 : (int)bgp->vrf_id);
10730 vty_out(vty, "\n");
10731 }
10732
10733 if (bgp_update_delay_configured(bgp)) {
10734 if (use_json) {
10735 json_object_int_add(
10736 json, "updateDelayLimit",
10737 bgp->v_update_delay);
10738
10739 if (bgp->v_update_delay
10740 != bgp->v_establish_wait)
10741 json_object_int_add(
10742 json,
10743 "updateDelayEstablishWait",
10744 bgp->v_establish_wait);
10745
10746 if (bgp_update_delay_active(bgp)) {
10747 json_object_string_add(
10748 json,
10749 "updateDelayFirstNeighbor",
10750 bgp->update_delay_begin_time);
10751 json_object_boolean_true_add(
10752 json,
10753 "updateDelayInProgress");
10754 } else {
10755 if (bgp->update_delay_over) {
10756 json_object_string_add(
10757 json,
10758 "updateDelayFirstNeighbor",
10759 bgp->update_delay_begin_time);
10760 json_object_string_add(
10761 json,
10762 "updateDelayBestpathResumed",
10763 bgp->update_delay_end_time);
10764 json_object_string_add(
10765 json,
10766 "updateDelayZebraUpdateResume",
10767 bgp->update_delay_zebra_resume_time);
10768 json_object_string_add(
10769 json,
10770 "updateDelayPeerUpdateResume",
10771 bgp->update_delay_peers_resume_time);
10772 }
10773 }
10774 } else {
10775 vty_out(vty,
10776 "Read-only mode update-delay limit: %d seconds\n",
10777 bgp->v_update_delay);
10778 if (bgp->v_update_delay
10779 != bgp->v_establish_wait)
10780 vty_out(vty,
10781 " Establish wait: %d seconds\n",
10782 bgp->v_establish_wait);
10783
10784 if (bgp_update_delay_active(bgp)) {
10785 vty_out(vty,
10786 " First neighbor established: %s\n",
10787 bgp->update_delay_begin_time);
10788 vty_out(vty,
10789 " Delay in progress\n");
10790 } else {
10791 if (bgp->update_delay_over) {
10792 vty_out(vty,
10793 " First neighbor established: %s\n",
10794 bgp->update_delay_begin_time);
10795 vty_out(vty,
10796 " Best-paths resumed: %s\n",
10797 bgp->update_delay_end_time);
10798 vty_out(vty,
10799 " zebra update resumed: %s\n",
10800 bgp->update_delay_zebra_resume_time);
10801 vty_out(vty,
10802 " peers update resumed: %s\n",
10803 bgp->update_delay_peers_resume_time);
10804 }
10805 }
10806 }
10807 }
10808
10809 if (use_json) {
10810 if (bgp_maxmed_onstartup_configured(bgp)
10811 && bgp->maxmed_active)
10812 json_object_boolean_true_add(
10813 json, "maxMedOnStartup");
10814 if (bgp->v_maxmed_admin)
10815 json_object_boolean_true_add(
10816 json, "maxMedAdministrative");
10817
10818 json_object_int_add(
10819 json, "tableVersion",
10820 bgp_table_version(bgp->rib[afi][safi]));
10821
10822 ents = bgp_table_count(bgp->rib[afi][safi]);
10823 json_object_int_add(json, "ribCount", ents);
10824 json_object_int_add(
10825 json, "ribMemory",
10826 ents * sizeof(struct bgp_dest));
10827
10828 ents = bgp->af_peer_count[afi][safi];
10829 json_object_int_add(json, "peerCount", ents);
10830 json_object_int_add(json, "peerMemory",
10831 ents * sizeof(struct peer));
10832
10833 if ((ents = listcount(bgp->group))) {
10834 json_object_int_add(
10835 json, "peerGroupCount", ents);
10836 json_object_int_add(
10837 json, "peerGroupMemory",
10838 ents * sizeof(struct
10839 peer_group));
10840 }
10841
10842 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10843 BGP_CONFIG_DAMPENING))
10844 json_object_boolean_true_add(
10845 json, "dampeningEnabled");
10846 } else {
10847 if (!show_terse) {
10848 if (bgp_maxmed_onstartup_configured(bgp)
10849 && bgp->maxmed_active)
10850 vty_out(vty,
10851 "Max-med on-startup active\n");
10852 if (bgp->v_maxmed_admin)
10853 vty_out(vty,
10854 "Max-med administrative active\n");
10855
10856 vty_out(vty,
10857 "BGP table version %" PRIu64
10858 "\n",
10859 bgp_table_version(
10860 bgp->rib[afi][safi]));
10861
10862 ents = bgp_table_count(
10863 bgp->rib[afi][safi]);
10864 vty_out(vty,
10865 "RIB entries %ld, using %s of memory\n",
10866 ents,
10867 mtype_memstr(
10868 memstrbuf,
10869 sizeof(memstrbuf),
10870 ents
10871 * sizeof(
10872 struct
10873 bgp_dest)));
10874
10875 /* Peer related usage */
10876 ents = bgp->af_peer_count[afi][safi];
10877 vty_out(vty,
10878 "Peers %ld, using %s of memory\n",
10879 ents,
10880 mtype_memstr(
10881 memstrbuf,
10882 sizeof(memstrbuf),
10883 ents
10884 * sizeof(
10885 struct
10886 peer)));
10887
10888 if ((ents = listcount(bgp->group)))
10889 vty_out(vty,
10890 "Peer groups %ld, using %s of memory\n",
10891 ents,
10892 mtype_memstr(
10893 memstrbuf,
10894 sizeof(memstrbuf),
10895 ents
10896 * sizeof(
10897 struct
10898 peer_group)));
10899
10900 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10901 BGP_CONFIG_DAMPENING))
10902 vty_out(vty,
10903 "Dampening enabled.\n");
10904 }
10905 if (show_failed) {
10906 vty_out(vty, "\n");
10907
10908 /* Subtract 8 here because 'Neighbor' is
10909 * 8 characters */
10910 vty_out(vty, "Neighbor");
10911 vty_out(vty, "%*s",
10912 max_neighbor_width - 8, " ");
10913 vty_out(vty,
10914 BGP_SHOW_SUMMARY_HEADER_FAILED);
10915 }
10916 }
10917 }
10918
10919 paf = peer_af_find(peer, afi, safi);
10920 filter = &peer->filter[afi][safi];
10921
10922 count++;
10923 /* Works for both failed & successful cases */
10924 if (peer_dynamic_neighbor(peer))
10925 dn_count++;
10926
10927 if (use_json) {
10928 json_peer = NULL;
10929 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10930 as_type, as)) {
10931 filtered_count++;
10932 continue;
10933 }
10934 if (show_failed &&
10935 bgp_has_peer_failed(peer, afi, safi)) {
10936 json_peer = json_object_new_object();
10937 bgp_show_failed_summary(vty, bgp, peer,
10938 json_peer, 0, use_json);
10939 } else if (!show_failed) {
10940 if (show_established
10941 && bgp_has_peer_failed(peer, afi, safi)) {
10942 filtered_count++;
10943 continue;
10944 }
10945
10946 json_peer = json_object_new_object();
10947 if (peer_dynamic_neighbor(peer)) {
10948 json_object_boolean_true_add(json_peer,
10949 "dynamicPeer");
10950 }
10951
10952 if (peer->hostname)
10953 json_object_string_add(json_peer, "hostname",
10954 peer->hostname);
10955
10956 if (peer->domainname)
10957 json_object_string_add(json_peer, "domainname",
10958 peer->domainname);
10959
10960 json_object_int_add(json_peer, "remoteAs", peer->as);
10961 json_object_int_add(
10962 json_peer, "localAs",
10963 peer->change_local_as
10964 ? peer->change_local_as
10965 : peer->local_as);
10966 json_object_int_add(json_peer, "version", 4);
10967 json_object_int_add(json_peer, "msgRcvd",
10968 PEER_TOTAL_RX(peer));
10969 json_object_int_add(json_peer, "msgSent",
10970 PEER_TOTAL_TX(peer));
10971
10972 atomic_size_t outq_count, inq_count;
10973 outq_count = atomic_load_explicit(
10974 &peer->obuf->count,
10975 memory_order_relaxed);
10976 inq_count = atomic_load_explicit(
10977 &peer->ibuf->count,
10978 memory_order_relaxed);
10979
10980 json_object_int_add(json_peer, "tableVersion",
10981 peer->version[afi][safi]);
10982 json_object_int_add(json_peer, "outq",
10983 outq_count);
10984 json_object_int_add(json_peer, "inq",
10985 inq_count);
10986 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10987 use_json, json_peer);
10988
10989 json_object_int_add(json_peer, "pfxRcd",
10990 peer->pcount[afi][pfx_rcd_safi]);
10991
10992 if (paf && PAF_SUBGRP(paf))
10993 json_object_int_add(
10994 json_peer, "pfxSnt",
10995 (PAF_SUBGRP(paf))->scount);
10996 else
10997 json_object_int_add(json_peer, "pfxSnt",
10998 0);
10999
11000 /* BGP FSM state */
11001 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11002 || CHECK_FLAG(peer->bgp->flags,
11003 BGP_FLAG_SHUTDOWN))
11004 json_object_string_add(json_peer,
11005 "state",
11006 "Idle (Admin)");
11007 else if (peer->afc_recv[afi][safi])
11008 json_object_string_add(
11009 json_peer, "state",
11010 lookup_msg(bgp_status_msg,
11011 peer->status, NULL));
11012 else if (CHECK_FLAG(
11013 peer->sflags,
11014 PEER_STATUS_PREFIX_OVERFLOW))
11015 json_object_string_add(json_peer,
11016 "state",
11017 "Idle (PfxCt)");
11018 else
11019 json_object_string_add(
11020 json_peer, "state",
11021 lookup_msg(bgp_status_msg,
11022 peer->status, NULL));
11023
11024 /* BGP peer state */
11025 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11026 || CHECK_FLAG(peer->bgp->flags,
11027 BGP_FLAG_SHUTDOWN))
11028 json_object_string_add(json_peer,
11029 "peerState",
11030 "Admin");
11031 else if (CHECK_FLAG(
11032 peer->sflags,
11033 PEER_STATUS_PREFIX_OVERFLOW))
11034 json_object_string_add(json_peer,
11035 "peerState",
11036 "PfxCt");
11037 else if (CHECK_FLAG(peer->flags,
11038 PEER_FLAG_PASSIVE))
11039 json_object_string_add(json_peer,
11040 "peerState",
11041 "Passive");
11042 else if (CHECK_FLAG(peer->sflags,
11043 PEER_STATUS_NSF_WAIT))
11044 json_object_string_add(json_peer,
11045 "peerState",
11046 "NSF passive");
11047 else if (CHECK_FLAG(
11048 peer->bgp->flags,
11049 BGP_FLAG_EBGP_REQUIRES_POLICY)
11050 && (!bgp_inbound_policy_exists(peer,
11051 filter)
11052 || !bgp_outbound_policy_exists(
11053 peer, filter)))
11054 json_object_string_add(json_peer,
11055 "peerState",
11056 "Policy");
11057 else
11058 json_object_string_add(
11059 json_peer, "peerState", "OK");
11060
11061 json_object_int_add(json_peer, "connectionsEstablished",
11062 peer->established);
11063 json_object_int_add(json_peer, "connectionsDropped",
11064 peer->dropped);
11065 if (peer->desc)
11066 json_object_string_add(
11067 json_peer, "desc", peer->desc);
11068 }
11069 /* Avoid creating empty peer dicts in JSON */
11070 if (json_peer == NULL)
11071 continue;
11072
11073 if (peer->conf_if)
11074 json_object_string_add(json_peer, "idType",
11075 "interface");
11076 else if (peer->su.sa.sa_family == AF_INET)
11077 json_object_string_add(json_peer, "idType",
11078 "ipv4");
11079 else if (peer->su.sa.sa_family == AF_INET6)
11080 json_object_string_add(json_peer, "idType",
11081 "ipv6");
11082 json_object_object_add(json_peers, peer->host,
11083 json_peer);
11084 } else {
11085 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11086 as_type, as)) {
11087 filtered_count++;
11088 continue;
11089 }
11090 if (show_failed &&
11091 bgp_has_peer_failed(peer, afi, safi)) {
11092 bgp_show_failed_summary(vty, bgp, peer, NULL,
11093 max_neighbor_width,
11094 use_json);
11095 } else if (!show_failed) {
11096 if (show_established
11097 && bgp_has_peer_failed(peer, afi, safi)) {
11098 filtered_count++;
11099 continue;
11100 }
11101
11102 if ((count - filtered_count) == 1) {
11103 /* display headline before the first
11104 * neighbor line */
11105 vty_out(vty, "\n");
11106
11107 /* Subtract 8 here because 'Neighbor' is
11108 * 8 characters */
11109 vty_out(vty, "Neighbor");
11110 vty_out(vty, "%*s",
11111 max_neighbor_width - 8, " ");
11112 vty_out(vty,
11113 show_wide
11114 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11115 : BGP_SHOW_SUMMARY_HEADER_ALL);
11116 }
11117
11118 memset(dn_flag, '\0', sizeof(dn_flag));
11119 if (peer_dynamic_neighbor(peer)) {
11120 dn_flag[0] = '*';
11121 }
11122
11123 if (peer->hostname
11124 && CHECK_FLAG(bgp->flags,
11125 BGP_FLAG_SHOW_HOSTNAME))
11126 len = vty_out(vty, "%s%s(%s)", dn_flag,
11127 peer->hostname,
11128 peer->host);
11129 else
11130 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11131
11132 /* pad the neighbor column with spaces */
11133 if (len < max_neighbor_width)
11134 vty_out(vty, "%*s", max_neighbor_width - len,
11135 " ");
11136
11137 atomic_size_t outq_count, inq_count;
11138 outq_count = atomic_load_explicit(
11139 &peer->obuf->count,
11140 memory_order_relaxed);
11141 inq_count = atomic_load_explicit(
11142 &peer->ibuf->count,
11143 memory_order_relaxed);
11144
11145 if (show_wide)
11146 vty_out(vty,
11147 "4 %10u %10u %9u %9u %8" PRIu64
11148 " %4zu %4zu %8s",
11149 peer->as,
11150 peer->change_local_as
11151 ? peer->change_local_as
11152 : peer->local_as,
11153 PEER_TOTAL_RX(peer),
11154 PEER_TOTAL_TX(peer),
11155 peer->version[afi][safi],
11156 inq_count, outq_count,
11157 peer_uptime(peer->uptime,
11158 timebuf,
11159 BGP_UPTIME_LEN, 0,
11160 NULL));
11161 else
11162 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11163 " %4zu %4zu %8s",
11164 peer->as, PEER_TOTAL_RX(peer),
11165 PEER_TOTAL_TX(peer),
11166 peer->version[afi][safi],
11167 inq_count, outq_count,
11168 peer_uptime(peer->uptime,
11169 timebuf,
11170 BGP_UPTIME_LEN, 0,
11171 NULL));
11172
11173 if (peer_established(peer)) {
11174 if (peer->afc_recv[afi][safi]) {
11175 if (CHECK_FLAG(
11176 bgp->flags,
11177 BGP_FLAG_EBGP_REQUIRES_POLICY)
11178 && !bgp_inbound_policy_exists(
11179 peer, filter))
11180 vty_out(vty, " %12s",
11181 "(Policy)");
11182 else
11183 vty_out(vty,
11184 " %12u",
11185 peer->pcount
11186 [afi]
11187 [pfx_rcd_safi]);
11188 } else {
11189 vty_out(vty, " NoNeg");
11190 }
11191
11192 if (paf && PAF_SUBGRP(paf)) {
11193 if (CHECK_FLAG(
11194 bgp->flags,
11195 BGP_FLAG_EBGP_REQUIRES_POLICY)
11196 && !bgp_outbound_policy_exists(
11197 peer, filter))
11198 vty_out(vty, " %8s",
11199 "(Policy)");
11200 else
11201 vty_out(vty,
11202 " %8u",
11203 (PAF_SUBGRP(
11204 paf))
11205 ->scount);
11206 } else {
11207 vty_out(vty, " NoNeg");
11208 }
11209 } else {
11210 if (CHECK_FLAG(peer->flags,
11211 PEER_FLAG_SHUTDOWN)
11212 || CHECK_FLAG(peer->bgp->flags,
11213 BGP_FLAG_SHUTDOWN))
11214 vty_out(vty, " Idle (Admin)");
11215 else if (CHECK_FLAG(
11216 peer->sflags,
11217 PEER_STATUS_PREFIX_OVERFLOW))
11218 vty_out(vty, " Idle (PfxCt)");
11219 else
11220 vty_out(vty, " %12s",
11221 lookup_msg(bgp_status_msg,
11222 peer->status, NULL));
11223
11224 vty_out(vty, " %8u", 0);
11225 }
11226 /* Make sure `Desc` column is the lastest in
11227 * the output.
11228 */
11229 if (peer->desc)
11230 vty_out(vty, " %s",
11231 bgp_peer_description_stripped(
11232 peer->desc,
11233 show_wide ? 64 : 20));
11234 else
11235 vty_out(vty, " N/A");
11236 vty_out(vty, "\n");
11237 }
11238
11239 }
11240 }
11241
11242 if (use_json) {
11243 json_object_object_add(json, "peers", json_peers);
11244 json_object_int_add(json, "failedPeers", failed_count);
11245 json_object_int_add(json, "displayedPeers",
11246 count - filtered_count);
11247 json_object_int_add(json, "totalPeers", count);
11248 json_object_int_add(json, "dynamicPeers", dn_count);
11249
11250 if (!show_failed)
11251 bgp_show_bestpath_json(bgp, json);
11252
11253 vty_json(vty, json);
11254 } else {
11255 if (count) {
11256 if (filtered_count == count)
11257 vty_out(vty, "\n%% No matching neighbor\n");
11258 else {
11259 if (show_failed)
11260 vty_out(vty, "\nDisplayed neighbors %d",
11261 failed_count);
11262 else if (as_type != AS_UNSPECIFIED || as
11263 || fpeer || show_established)
11264 vty_out(vty, "\nDisplayed neighbors %d",
11265 count - filtered_count);
11266
11267 vty_out(vty, "\nTotal number of neighbors %d\n",
11268 count);
11269 }
11270 } else {
11271 vty_out(vty, "No %s neighbor is configured\n",
11272 get_afi_safi_str(afi, safi, false));
11273 }
11274
11275 if (dn_count) {
11276 vty_out(vty, "* - dynamic neighbor\n");
11277 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11278 dn_count, bgp->dynamic_neighbors_limit);
11279 }
11280 }
11281
11282 return CMD_SUCCESS;
11283 }
11284
11285 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11286 int safi, struct peer *fpeer, int as_type,
11287 as_t as, uint16_t show_flags)
11288 {
11289 int is_first = 1;
11290 int afi_wildcard = (afi == AFI_MAX);
11291 int safi_wildcard = (safi == SAFI_MAX);
11292 int is_wildcard = (afi_wildcard || safi_wildcard);
11293 bool nbr_output = false;
11294 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11295
11296 if (use_json && is_wildcard)
11297 vty_out(vty, "{\n");
11298 if (afi_wildcard)
11299 afi = 1; /* AFI_IP */
11300 while (afi < AFI_MAX) {
11301 if (safi_wildcard)
11302 safi = 1; /* SAFI_UNICAST */
11303 while (safi < SAFI_MAX) {
11304 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11305 nbr_output = true;
11306
11307 if (is_wildcard) {
11308 /*
11309 * So limit output to those afi/safi
11310 * pairs that
11311 * actualy have something interesting in
11312 * them
11313 */
11314 if (use_json) {
11315 if (!is_first)
11316 vty_out(vty, ",\n");
11317 else
11318 is_first = 0;
11319
11320 vty_out(vty, "\"%s\":",
11321 get_afi_safi_str(afi,
11322 safi,
11323 true));
11324 } else {
11325 vty_out(vty,
11326 "\n%s Summary (%s):\n",
11327 get_afi_safi_str(afi,
11328 safi,
11329 false),
11330 bgp->name_pretty);
11331 }
11332 }
11333 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11334 as_type, as, show_flags);
11335 }
11336 safi++;
11337 if (!safi_wildcard)
11338 safi = SAFI_MAX;
11339 }
11340 afi++;
11341 if (!afi_wildcard)
11342 afi = AFI_MAX;
11343 }
11344
11345 if (use_json && is_wildcard)
11346 vty_out(vty, "}\n");
11347 else if (!nbr_output) {
11348 if (use_json)
11349 vty_out(vty, "{}\n");
11350 else
11351 vty_out(vty, "%% No BGP neighbors found in %s\n",
11352 bgp->name_pretty);
11353 }
11354 }
11355
11356 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11357 safi_t safi,
11358 const char *neighbor,
11359 int as_type, as_t as,
11360 uint16_t show_flags)
11361 {
11362 struct listnode *node, *nnode;
11363 struct bgp *bgp;
11364 struct peer *fpeer = NULL;
11365 int is_first = 1;
11366 bool nbr_output = false;
11367 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11368
11369 if (use_json)
11370 vty_out(vty, "{\n");
11371
11372 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11373 nbr_output = true;
11374 if (use_json) {
11375 if (!is_first)
11376 vty_out(vty, ",\n");
11377 else
11378 is_first = 0;
11379
11380 vty_out(vty, "\"%s\":",
11381 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11382 ? VRF_DEFAULT_NAME
11383 : bgp->name);
11384 }
11385 if (neighbor) {
11386 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11387 use_json);
11388 if (!fpeer)
11389 continue;
11390 }
11391 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11392 as, show_flags);
11393 }
11394
11395 if (use_json)
11396 vty_out(vty, "}\n");
11397 else if (!nbr_output)
11398 vty_out(vty, "%% BGP instance not found\n");
11399 }
11400
11401 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11402 safi_t safi, const char *neighbor, int as_type,
11403 as_t as, uint16_t show_flags)
11404 {
11405 struct bgp *bgp;
11406 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11407 struct peer *fpeer = NULL;
11408
11409 if (name) {
11410 if (strmatch(name, "all")) {
11411 bgp_show_all_instances_summary_vty(vty, afi, safi,
11412 neighbor, as_type,
11413 as, show_flags);
11414 return CMD_SUCCESS;
11415 } else {
11416 bgp = bgp_lookup_by_name(name);
11417
11418 if (!bgp) {
11419 if (use_json)
11420 vty_out(vty, "{}\n");
11421 else
11422 vty_out(vty,
11423 "%% BGP instance not found\n");
11424 return CMD_WARNING;
11425 }
11426
11427 if (neighbor) {
11428 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11429 use_json);
11430 if (!fpeer)
11431 return CMD_WARNING;
11432 }
11433 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11434 as_type, as, show_flags);
11435 return CMD_SUCCESS;
11436 }
11437 }
11438
11439 bgp = bgp_get_default();
11440
11441 if (bgp) {
11442 if (neighbor) {
11443 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11444 use_json);
11445 if (!fpeer)
11446 return CMD_WARNING;
11447 }
11448 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11449 as, show_flags);
11450 } else {
11451 if (use_json)
11452 vty_out(vty, "{}\n");
11453 else
11454 vty_out(vty, "%% BGP instance not found\n");
11455 return CMD_WARNING;
11456 }
11457
11458 return CMD_SUCCESS;
11459 }
11460
11461 /* `show [ip] bgp summary' commands. */
11462 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11463 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11464 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11465 "]] [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]",
11466 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11467 BGP_SAFI_WITH_LABEL_HELP_STR
11468 "Display the entries for all address families\n"
11469 "Summary of BGP neighbor status\n"
11470 "Show only sessions in Established state\n"
11471 "Show only sessions not in Established state\n"
11472 "Show only the specified neighbor session\n"
11473 "Neighbor to display information about\n"
11474 "Neighbor to display information about\n"
11475 "Neighbor on BGP configured interface\n"
11476 "Show only the specified remote AS sessions\n"
11477 "AS number\n"
11478 "Internal (iBGP) AS sessions\n"
11479 "External (eBGP) AS sessions\n"
11480 "Shorten the information on BGP instances\n"
11481 "Increase table width for longer output\n" JSON_STR)
11482 {
11483 char *vrf = NULL;
11484 afi_t afi = AFI_MAX;
11485 safi_t safi = SAFI_MAX;
11486 as_t as = 0; /* 0 means AS filter not set */
11487 int as_type = AS_UNSPECIFIED;
11488 uint16_t show_flags = 0;
11489
11490 int idx = 0;
11491
11492 /* show [ip] bgp */
11493 if (!all && argv_find(argv, argc, "ip", &idx))
11494 afi = AFI_IP;
11495 /* [<vrf> VIEWVRFNAME] */
11496 if (argv_find(argv, argc, "vrf", &idx)) {
11497 vrf = argv[idx + 1]->arg;
11498 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11499 vrf = NULL;
11500 } else if (argv_find(argv, argc, "view", &idx))
11501 /* [<view> VIEWVRFNAME] */
11502 vrf = argv[idx + 1]->arg;
11503 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11504 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11505 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11506 }
11507
11508 if (argv_find(argv, argc, "failed", &idx))
11509 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11510
11511 if (argv_find(argv, argc, "established", &idx))
11512 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11513
11514 if (argv_find(argv, argc, "remote-as", &idx)) {
11515 if (argv[idx + 1]->arg[0] == 'i')
11516 as_type = AS_INTERNAL;
11517 else if (argv[idx + 1]->arg[0] == 'e')
11518 as_type = AS_EXTERNAL;
11519 else
11520 as = (as_t)atoi(argv[idx + 1]->arg);
11521 }
11522
11523 if (argv_find(argv, argc, "terse", &idx))
11524 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11525
11526 if (argv_find(argv, argc, "wide", &idx))
11527 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11528
11529 if (argv_find(argv, argc, "json", &idx))
11530 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11531
11532 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11533 show_flags);
11534 }
11535
11536 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11537 {
11538 if (for_json)
11539 return get_afi_safi_json_str(afi, safi);
11540 else
11541 return get_afi_safi_vty_str(afi, safi);
11542 }
11543
11544
11545 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11546 afi_t afi, safi_t safi,
11547 uint16_t adv_smcap, uint16_t adv_rmcap,
11548 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11549 bool use_json, json_object *json_pref)
11550 {
11551 /* Send-Mode */
11552 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11553 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11554 if (use_json) {
11555 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11556 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11557 json_object_string_add(json_pref, "sendMode",
11558 "advertisedAndReceived");
11559 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11560 json_object_string_add(json_pref, "sendMode",
11561 "advertised");
11562 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11563 json_object_string_add(json_pref, "sendMode",
11564 "received");
11565 } else {
11566 vty_out(vty, " Send-mode: ");
11567 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11568 vty_out(vty, "advertised");
11569 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11570 vty_out(vty, "%sreceived",
11571 CHECK_FLAG(p->af_cap[afi][safi],
11572 adv_smcap)
11573 ? ", "
11574 : "");
11575 vty_out(vty, "\n");
11576 }
11577 }
11578
11579 /* Receive-Mode */
11580 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11581 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11582 if (use_json) {
11583 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11584 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11585 json_object_string_add(json_pref, "recvMode",
11586 "advertisedAndReceived");
11587 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11588 json_object_string_add(json_pref, "recvMode",
11589 "advertised");
11590 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11591 json_object_string_add(json_pref, "recvMode",
11592 "received");
11593 } else {
11594 vty_out(vty, " Receive-mode: ");
11595 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11596 vty_out(vty, "advertised");
11597 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11598 vty_out(vty, "%sreceived",
11599 CHECK_FLAG(p->af_cap[afi][safi],
11600 adv_rmcap)
11601 ? ", "
11602 : "");
11603 vty_out(vty, "\n");
11604 }
11605 }
11606 }
11607
11608 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11609 struct peer *p,
11610 bool use_json,
11611 json_object *json)
11612 {
11613 bool rbit = false;
11614 bool nbit = false;
11615
11616 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11617 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11618 && (peer_established(p))) {
11619 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11620 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11621 }
11622
11623 if (use_json) {
11624 json_object_boolean_add(json, "rBit", rbit);
11625 json_object_boolean_add(json, "nBit", nbit);
11626 } else {
11627 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11628 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11629 }
11630 }
11631
11632 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11633 struct peer *peer,
11634 bool use_json,
11635 json_object *json)
11636 {
11637 const char *mode = "NotApplicable";
11638
11639 if (!use_json)
11640 vty_out(vty, "\n Remote GR Mode: ");
11641
11642 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11643 && (peer_established(peer))) {
11644
11645 if ((peer->nsf_af_count == 0)
11646 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11647
11648 mode = "Disable";
11649
11650 } else if (peer->nsf_af_count == 0
11651 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11652
11653 mode = "Helper";
11654
11655 } else if (peer->nsf_af_count != 0
11656 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11657
11658 mode = "Restart";
11659 }
11660 }
11661
11662 if (use_json) {
11663 json_object_string_add(json, "remoteGrMode", mode);
11664 } else
11665 vty_out(vty, mode, "\n");
11666 }
11667
11668 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11669 struct peer *p,
11670 bool use_json,
11671 json_object *json)
11672 {
11673 const char *mode = "Invalid";
11674
11675 if (!use_json)
11676 vty_out(vty, " Local GR Mode: ");
11677
11678 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11679 mode = "Helper";
11680 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11681 mode = "Restart";
11682 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11683 mode = "Disable";
11684 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11685 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11686 mode = "Helper*";
11687 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11688 mode = "Restart*";
11689 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11690 mode = "Disable*";
11691 else
11692 mode = "Invalid*";
11693 }
11694
11695 if (use_json) {
11696 json_object_string_add(json, "localGrMode", mode);
11697 } else {
11698 vty_out(vty, mode, "\n");
11699 }
11700 }
11701
11702 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11703 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11704 {
11705 afi_t afi;
11706 safi_t safi;
11707 json_object *json_afi_safi = NULL;
11708 json_object *json_timer = NULL;
11709 json_object *json_endofrib_status = NULL;
11710 bool eor_flag = false;
11711
11712 FOREACH_AFI_SAFI_NSF (afi, safi) {
11713 if (!peer->afc[afi][safi])
11714 continue;
11715
11716 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11717 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11718 continue;
11719
11720 if (use_json) {
11721 json_afi_safi = json_object_new_object();
11722 json_endofrib_status = json_object_new_object();
11723 json_timer = json_object_new_object();
11724 }
11725
11726 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11727 eor_flag = true;
11728 else
11729 eor_flag = false;
11730
11731 if (!use_json) {
11732 vty_out(vty, " %s:\n",
11733 get_afi_safi_str(afi, safi, false));
11734
11735 vty_out(vty, " F bit: ");
11736 }
11737
11738 if (peer->nsf[afi][safi] &&
11739 CHECK_FLAG(peer->af_cap[afi][safi],
11740 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11741
11742 if (use_json) {
11743 json_object_boolean_true_add(json_afi_safi,
11744 "fBit");
11745 } else
11746 vty_out(vty, "True\n");
11747 } else {
11748 if (use_json)
11749 json_object_boolean_false_add(json_afi_safi,
11750 "fBit");
11751 else
11752 vty_out(vty, "False\n");
11753 }
11754
11755 if (!use_json)
11756 vty_out(vty, " End-of-RIB sent: ");
11757
11758 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11759 PEER_STATUS_EOR_SEND)) {
11760 if (use_json) {
11761 json_object_boolean_true_add(
11762 json_endofrib_status, "endOfRibSend");
11763
11764 PRINT_EOR_JSON(eor_flag);
11765 } else {
11766 vty_out(vty, "Yes\n");
11767 vty_out(vty,
11768 " End-of-RIB sent after update: ");
11769
11770 PRINT_EOR(eor_flag);
11771 }
11772 } else {
11773 if (use_json) {
11774 json_object_boolean_false_add(
11775 json_endofrib_status, "endOfRibSend");
11776 json_object_boolean_false_add(
11777 json_endofrib_status,
11778 "endOfRibSentAfterUpdate");
11779 } else {
11780 vty_out(vty, "No\n");
11781 vty_out(vty,
11782 " End-of-RIB sent after update: ");
11783 vty_out(vty, "No\n");
11784 }
11785 }
11786
11787 if (!use_json)
11788 vty_out(vty, " End-of-RIB received: ");
11789
11790 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11791 PEER_STATUS_EOR_RECEIVED)) {
11792 if (use_json)
11793 json_object_boolean_true_add(
11794 json_endofrib_status, "endOfRibRecv");
11795 else
11796 vty_out(vty, "Yes\n");
11797 } else {
11798 if (use_json)
11799 json_object_boolean_false_add(
11800 json_endofrib_status, "endOfRibRecv");
11801 else
11802 vty_out(vty, "No\n");
11803 }
11804
11805 if (use_json) {
11806 json_object_int_add(json_timer, "stalePathTimer",
11807 peer->bgp->stalepath_time);
11808
11809 if (peer->t_gr_stale != NULL) {
11810 json_object_int_add(json_timer,
11811 "stalePathTimerRemaining",
11812 thread_timer_remain_second(
11813 peer->t_gr_stale));
11814 }
11815
11816 /* Display Configured Selection
11817 * Deferral only when when
11818 * Gr mode is enabled.
11819 */
11820 if (CHECK_FLAG(peer->flags,
11821 PEER_FLAG_GRACEFUL_RESTART)) {
11822 json_object_int_add(json_timer,
11823 "selectionDeferralTimer",
11824 peer->bgp->stalepath_time);
11825 }
11826
11827 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11828 NULL) {
11829
11830 json_object_int_add(
11831 json_timer,
11832 "selectionDeferralTimerRemaining",
11833 thread_timer_remain_second(
11834 peer->bgp->gr_info[afi][safi]
11835 .t_select_deferral));
11836 }
11837 } else {
11838 vty_out(vty, " Timers:\n");
11839 vty_out(vty,
11840 " Configured Stale Path Time(sec): %u\n",
11841 peer->bgp->stalepath_time);
11842
11843 if (peer->t_gr_stale != NULL)
11844 vty_out(vty,
11845 " Stale Path Remaining(sec): %ld\n",
11846 thread_timer_remain_second(
11847 peer->t_gr_stale));
11848 /* Display Configured Selection
11849 * Deferral only when when
11850 * Gr mode is enabled.
11851 */
11852 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11853 vty_out(vty,
11854 " Configured Selection Deferral Time(sec): %u\n",
11855 peer->bgp->select_defer_time);
11856
11857 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11858 NULL)
11859 vty_out(vty,
11860 " Selection Deferral Time Remaining(sec): %ld\n",
11861 thread_timer_remain_second(
11862 peer->bgp->gr_info[afi][safi]
11863 .t_select_deferral));
11864 }
11865 if (use_json) {
11866 json_object_object_add(json_afi_safi, "endOfRibStatus",
11867 json_endofrib_status);
11868 json_object_object_add(json_afi_safi, "timers",
11869 json_timer);
11870 json_object_object_add(
11871 json, get_afi_safi_str(afi, safi, true),
11872 json_afi_safi);
11873 }
11874 }
11875 }
11876
11877 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11878 struct peer *p,
11879 bool use_json,
11880 json_object *json)
11881 {
11882 if (use_json) {
11883 json_object *json_timer = NULL;
11884
11885 json_timer = json_object_new_object();
11886
11887 json_object_int_add(json_timer, "configuredRestartTimer",
11888 p->bgp->restart_time);
11889
11890 json_object_int_add(json_timer, "receivedRestartTimer",
11891 p->v_gr_restart);
11892
11893 if (p->t_gr_restart != NULL)
11894 json_object_int_add(
11895 json_timer, "restartTimerRemaining",
11896 thread_timer_remain_second(p->t_gr_restart));
11897
11898 json_object_object_add(json, "timers", json_timer);
11899 } else {
11900
11901 vty_out(vty, " Timers:\n");
11902 vty_out(vty, " Configured Restart Time(sec): %u\n",
11903 p->bgp->restart_time);
11904
11905 vty_out(vty, " Received Restart Time(sec): %u\n",
11906 p->v_gr_restart);
11907 if (p->t_gr_restart != NULL)
11908 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11909 thread_timer_remain_second(p->t_gr_restart));
11910 if (p->t_gr_restart != NULL) {
11911 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11912 thread_timer_remain_second(p->t_gr_restart));
11913 }
11914 }
11915 }
11916
11917 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11918 bool use_json, json_object *json)
11919 {
11920 char dn_flag[2] = {0};
11921 /* '*' + v6 address of neighbor */
11922 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11923
11924 if (!p->conf_if && peer_dynamic_neighbor(p))
11925 dn_flag[0] = '*';
11926
11927 if (p->conf_if) {
11928 if (use_json)
11929 json_object_string_addf(json, "neighborAddr", "%pSU",
11930 &p->su);
11931 else
11932 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11933 &p->su);
11934 } else {
11935 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11936 p->host);
11937
11938 if (use_json)
11939 json_object_string_add(json, "neighborAddr",
11940 neighborAddr);
11941 else
11942 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11943 }
11944
11945 /* more gr info in new format */
11946 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11947 }
11948
11949 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11950 safi_t safi, bool use_json,
11951 json_object *json_neigh)
11952 {
11953 struct bgp_filter *filter;
11954 struct peer_af *paf;
11955 char orf_pfx_name[BUFSIZ];
11956 int orf_pfx_count;
11957 json_object *json_af = NULL;
11958 json_object *json_prefA = NULL;
11959 json_object *json_prefB = NULL;
11960 json_object *json_addr = NULL;
11961 json_object *json_advmap = NULL;
11962
11963 if (use_json) {
11964 json_addr = json_object_new_object();
11965 json_af = json_object_new_object();
11966 filter = &p->filter[afi][safi];
11967
11968 if (peer_group_active(p))
11969 json_object_string_add(json_addr, "peerGroupMember",
11970 p->group->name);
11971
11972 paf = peer_af_find(p, afi, safi);
11973 if (paf && PAF_SUBGRP(paf)) {
11974 json_object_int_add(json_addr, "updateGroupId",
11975 PAF_UPDGRP(paf)->id);
11976 json_object_int_add(json_addr, "subGroupId",
11977 PAF_SUBGRP(paf)->id);
11978 json_object_int_add(json_addr, "packetQueueLength",
11979 bpacket_queue_virtual_length(paf));
11980 }
11981
11982 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11983 || CHECK_FLAG(p->af_cap[afi][safi],
11984 PEER_CAP_ORF_PREFIX_SM_RCV)
11985 || CHECK_FLAG(p->af_cap[afi][safi],
11986 PEER_CAP_ORF_PREFIX_RM_ADV)
11987 || CHECK_FLAG(p->af_cap[afi][safi],
11988 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11989 json_object_int_add(json_af, "orfType",
11990 ORF_TYPE_PREFIX);
11991 json_prefA = json_object_new_object();
11992 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11993 PEER_CAP_ORF_PREFIX_SM_ADV,
11994 PEER_CAP_ORF_PREFIX_RM_ADV,
11995 PEER_CAP_ORF_PREFIX_SM_RCV,
11996 PEER_CAP_ORF_PREFIX_RM_RCV,
11997 use_json, json_prefA);
11998 json_object_object_add(json_af, "orfPrefixList",
11999 json_prefA);
12000 }
12001
12002 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12003 || CHECK_FLAG(p->af_cap[afi][safi],
12004 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12005 || CHECK_FLAG(p->af_cap[afi][safi],
12006 PEER_CAP_ORF_PREFIX_RM_ADV)
12007 || CHECK_FLAG(p->af_cap[afi][safi],
12008 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12009 json_object_int_add(json_af, "orfOldType",
12010 ORF_TYPE_PREFIX_OLD);
12011 json_prefB = json_object_new_object();
12012 bgp_show_peer_afi_orf_cap(
12013 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12014 PEER_CAP_ORF_PREFIX_RM_ADV,
12015 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12016 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12017 json_prefB);
12018 json_object_object_add(json_af, "orfOldPrefixList",
12019 json_prefB);
12020 }
12021
12022 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12023 || CHECK_FLAG(p->af_cap[afi][safi],
12024 PEER_CAP_ORF_PREFIX_SM_RCV)
12025 || CHECK_FLAG(p->af_cap[afi][safi],
12026 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12027 || CHECK_FLAG(p->af_cap[afi][safi],
12028 PEER_CAP_ORF_PREFIX_RM_ADV)
12029 || CHECK_FLAG(p->af_cap[afi][safi],
12030 PEER_CAP_ORF_PREFIX_RM_RCV)
12031 || CHECK_FLAG(p->af_cap[afi][safi],
12032 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12033 json_object_object_add(json_addr, "afDependentCap",
12034 json_af);
12035 else
12036 json_object_free(json_af);
12037
12038 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12039 p->host, afi, safi);
12040 orf_pfx_count = prefix_bgp_show_prefix_list(
12041 NULL, afi, orf_pfx_name, use_json);
12042
12043 if (CHECK_FLAG(p->af_sflags[afi][safi],
12044 PEER_STATUS_ORF_PREFIX_SEND)
12045 || orf_pfx_count) {
12046 if (CHECK_FLAG(p->af_sflags[afi][safi],
12047 PEER_STATUS_ORF_PREFIX_SEND))
12048 json_object_boolean_true_add(json_neigh,
12049 "orfSent");
12050 if (orf_pfx_count)
12051 json_object_int_add(json_addr, "orfRecvCounter",
12052 orf_pfx_count);
12053 }
12054 if (CHECK_FLAG(p->af_sflags[afi][safi],
12055 PEER_STATUS_ORF_WAIT_REFRESH))
12056 json_object_string_add(
12057 json_addr, "orfFirstUpdate",
12058 "deferredUntilORFOrRouteRefreshRecvd");
12059
12060 if (CHECK_FLAG(p->af_flags[afi][safi],
12061 PEER_FLAG_REFLECTOR_CLIENT))
12062 json_object_boolean_true_add(json_addr,
12063 "routeReflectorClient");
12064 if (CHECK_FLAG(p->af_flags[afi][safi],
12065 PEER_FLAG_RSERVER_CLIENT))
12066 json_object_boolean_true_add(json_addr,
12067 "routeServerClient");
12068 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12069 json_object_boolean_true_add(json_addr,
12070 "inboundSoftConfigPermit");
12071
12072 if (CHECK_FLAG(p->af_flags[afi][safi],
12073 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12074 json_object_boolean_true_add(
12075 json_addr,
12076 "privateAsNumsAllReplacedInUpdatesToNbr");
12077 else if (CHECK_FLAG(p->af_flags[afi][safi],
12078 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12079 json_object_boolean_true_add(
12080 json_addr,
12081 "privateAsNumsReplacedInUpdatesToNbr");
12082 else if (CHECK_FLAG(p->af_flags[afi][safi],
12083 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12084 json_object_boolean_true_add(
12085 json_addr,
12086 "privateAsNumsAllRemovedInUpdatesToNbr");
12087 else if (CHECK_FLAG(p->af_flags[afi][safi],
12088 PEER_FLAG_REMOVE_PRIVATE_AS))
12089 json_object_boolean_true_add(
12090 json_addr,
12091 "privateAsNumsRemovedInUpdatesToNbr");
12092
12093 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12094 json_object_boolean_true_add(
12095 json_addr,
12096 bgp_addpath_names(p->addpath_type[afi][safi])
12097 ->type_json_name);
12098
12099 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12100 json_object_string_add(json_addr,
12101 "overrideASNsInOutboundUpdates",
12102 "ifAspathEqualRemoteAs");
12103
12104 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12105 || CHECK_FLAG(p->af_flags[afi][safi],
12106 PEER_FLAG_FORCE_NEXTHOP_SELF))
12107 json_object_boolean_true_add(json_addr,
12108 "routerAlwaysNextHop");
12109 if (CHECK_FLAG(p->af_flags[afi][safi],
12110 PEER_FLAG_AS_PATH_UNCHANGED))
12111 json_object_boolean_true_add(
12112 json_addr, "unchangedAsPathPropogatedToNbr");
12113 if (CHECK_FLAG(p->af_flags[afi][safi],
12114 PEER_FLAG_NEXTHOP_UNCHANGED))
12115 json_object_boolean_true_add(
12116 json_addr, "unchangedNextHopPropogatedToNbr");
12117 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12118 json_object_boolean_true_add(
12119 json_addr, "unchangedMedPropogatedToNbr");
12120 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12121 || CHECK_FLAG(p->af_flags[afi][safi],
12122 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12123 if (CHECK_FLAG(p->af_flags[afi][safi],
12124 PEER_FLAG_SEND_COMMUNITY)
12125 && CHECK_FLAG(p->af_flags[afi][safi],
12126 PEER_FLAG_SEND_EXT_COMMUNITY))
12127 json_object_string_add(json_addr,
12128 "commAttriSentToNbr",
12129 "extendedAndStandard");
12130 else if (CHECK_FLAG(p->af_flags[afi][safi],
12131 PEER_FLAG_SEND_EXT_COMMUNITY))
12132 json_object_string_add(json_addr,
12133 "commAttriSentToNbr",
12134 "extended");
12135 else
12136 json_object_string_add(json_addr,
12137 "commAttriSentToNbr",
12138 "standard");
12139 }
12140 if (CHECK_FLAG(p->af_flags[afi][safi],
12141 PEER_FLAG_DEFAULT_ORIGINATE)) {
12142 if (p->default_rmap[afi][safi].name)
12143 json_object_string_add(
12144 json_addr, "defaultRouteMap",
12145 p->default_rmap[afi][safi].name);
12146
12147 if (paf && PAF_SUBGRP(paf)
12148 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12149 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12150 json_object_boolean_true_add(json_addr,
12151 "defaultSent");
12152 else
12153 json_object_boolean_true_add(json_addr,
12154 "defaultNotSent");
12155 }
12156
12157 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12158 if (is_evpn_enabled())
12159 json_object_boolean_true_add(
12160 json_addr, "advertiseAllVnis");
12161 }
12162
12163 if (filter->plist[FILTER_IN].name
12164 || filter->dlist[FILTER_IN].name
12165 || filter->aslist[FILTER_IN].name
12166 || filter->map[RMAP_IN].name)
12167 json_object_boolean_true_add(json_addr,
12168 "inboundPathPolicyConfig");
12169 if (filter->plist[FILTER_OUT].name
12170 || filter->dlist[FILTER_OUT].name
12171 || filter->aslist[FILTER_OUT].name
12172 || filter->map[RMAP_OUT].name || filter->usmap.name)
12173 json_object_boolean_true_add(
12174 json_addr, "outboundPathPolicyConfig");
12175
12176 /* prefix-list */
12177 if (filter->plist[FILTER_IN].name)
12178 json_object_string_add(json_addr,
12179 "incomingUpdatePrefixFilterList",
12180 filter->plist[FILTER_IN].name);
12181 if (filter->plist[FILTER_OUT].name)
12182 json_object_string_add(json_addr,
12183 "outgoingUpdatePrefixFilterList",
12184 filter->plist[FILTER_OUT].name);
12185
12186 /* distribute-list */
12187 if (filter->dlist[FILTER_IN].name)
12188 json_object_string_add(
12189 json_addr, "incomingUpdateNetworkFilterList",
12190 filter->dlist[FILTER_IN].name);
12191 if (filter->dlist[FILTER_OUT].name)
12192 json_object_string_add(
12193 json_addr, "outgoingUpdateNetworkFilterList",
12194 filter->dlist[FILTER_OUT].name);
12195
12196 /* filter-list. */
12197 if (filter->aslist[FILTER_IN].name)
12198 json_object_string_add(json_addr,
12199 "incomingUpdateAsPathFilterList",
12200 filter->aslist[FILTER_IN].name);
12201 if (filter->aslist[FILTER_OUT].name)
12202 json_object_string_add(json_addr,
12203 "outgoingUpdateAsPathFilterList",
12204 filter->aslist[FILTER_OUT].name);
12205
12206 /* route-map. */
12207 if (filter->map[RMAP_IN].name)
12208 json_object_string_add(
12209 json_addr, "routeMapForIncomingAdvertisements",
12210 filter->map[RMAP_IN].name);
12211 if (filter->map[RMAP_OUT].name)
12212 json_object_string_add(
12213 json_addr, "routeMapForOutgoingAdvertisements",
12214 filter->map[RMAP_OUT].name);
12215
12216 /* ebgp-requires-policy (inbound) */
12217 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12218 && !bgp_inbound_policy_exists(p, filter))
12219 json_object_string_add(
12220 json_addr, "inboundEbgpRequiresPolicy",
12221 "Inbound updates discarded due to missing policy");
12222
12223 /* ebgp-requires-policy (outbound) */
12224 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12225 && (!bgp_outbound_policy_exists(p, filter)))
12226 json_object_string_add(
12227 json_addr, "outboundEbgpRequiresPolicy",
12228 "Outbound updates discarded due to missing policy");
12229
12230 /* unsuppress-map */
12231 if (filter->usmap.name)
12232 json_object_string_add(json_addr,
12233 "selectiveUnsuppressRouteMap",
12234 filter->usmap.name);
12235
12236 /* advertise-map */
12237 if (filter->advmap.aname) {
12238 json_advmap = json_object_new_object();
12239 json_object_string_add(json_advmap, "condition",
12240 filter->advmap.condition
12241 ? "EXIST"
12242 : "NON_EXIST");
12243 json_object_string_add(json_advmap, "conditionMap",
12244 filter->advmap.cname);
12245 json_object_string_add(json_advmap, "advertiseMap",
12246 filter->advmap.aname);
12247 json_object_string_add(
12248 json_advmap, "advertiseStatus",
12249 filter->advmap.update_type ==
12250 UPDATE_TYPE_ADVERTISE
12251 ? "Advertise"
12252 : "Withdraw");
12253 json_object_object_add(json_addr, "advertiseMap",
12254 json_advmap);
12255 }
12256
12257 /* Receive prefix count */
12258 json_object_int_add(json_addr, "acceptedPrefixCounter",
12259 p->pcount[afi][safi]);
12260 if (paf && PAF_SUBGRP(paf))
12261 json_object_int_add(json_addr, "sentPrefixCounter",
12262 (PAF_SUBGRP(paf))->scount);
12263
12264 /* Maximum prefix */
12265 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12266 json_object_int_add(json_addr, "prefixOutAllowedMax",
12267 p->pmax_out[afi][safi]);
12268
12269 /* Maximum prefix */
12270 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12271 json_object_int_add(json_addr, "prefixAllowedMax",
12272 p->pmax[afi][safi]);
12273 if (CHECK_FLAG(p->af_flags[afi][safi],
12274 PEER_FLAG_MAX_PREFIX_WARNING))
12275 json_object_boolean_true_add(
12276 json_addr, "prefixAllowedMaxWarning");
12277 json_object_int_add(json_addr,
12278 "prefixAllowedWarningThresh",
12279 p->pmax_threshold[afi][safi]);
12280 if (p->pmax_restart[afi][safi])
12281 json_object_int_add(
12282 json_addr,
12283 "prefixAllowedRestartIntervalMsecs",
12284 p->pmax_restart[afi][safi] * 60000);
12285 }
12286 json_object_object_add(json_neigh,
12287 get_afi_safi_str(afi, safi, true),
12288 json_addr);
12289
12290 } else {
12291 filter = &p->filter[afi][safi];
12292
12293 vty_out(vty, " For address family: %s\n",
12294 get_afi_safi_str(afi, safi, false));
12295
12296 if (peer_group_active(p))
12297 vty_out(vty, " %s peer-group member\n",
12298 p->group->name);
12299
12300 paf = peer_af_find(p, afi, safi);
12301 if (paf && PAF_SUBGRP(paf)) {
12302 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12303 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12304 vty_out(vty, " Packet Queue length %d\n",
12305 bpacket_queue_virtual_length(paf));
12306 } else {
12307 vty_out(vty, " Not part of any update group\n");
12308 }
12309 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12310 || CHECK_FLAG(p->af_cap[afi][safi],
12311 PEER_CAP_ORF_PREFIX_SM_RCV)
12312 || CHECK_FLAG(p->af_cap[afi][safi],
12313 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12314 || CHECK_FLAG(p->af_cap[afi][safi],
12315 PEER_CAP_ORF_PREFIX_RM_ADV)
12316 || CHECK_FLAG(p->af_cap[afi][safi],
12317 PEER_CAP_ORF_PREFIX_RM_RCV)
12318 || CHECK_FLAG(p->af_cap[afi][safi],
12319 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12320 vty_out(vty, " AF-dependant capabilities:\n");
12321
12322 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12323 || CHECK_FLAG(p->af_cap[afi][safi],
12324 PEER_CAP_ORF_PREFIX_SM_RCV)
12325 || CHECK_FLAG(p->af_cap[afi][safi],
12326 PEER_CAP_ORF_PREFIX_RM_ADV)
12327 || CHECK_FLAG(p->af_cap[afi][safi],
12328 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12329 vty_out(vty,
12330 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12331 ORF_TYPE_PREFIX);
12332 bgp_show_peer_afi_orf_cap(
12333 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12334 PEER_CAP_ORF_PREFIX_RM_ADV,
12335 PEER_CAP_ORF_PREFIX_SM_RCV,
12336 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12337 }
12338 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12339 || CHECK_FLAG(p->af_cap[afi][safi],
12340 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12341 || CHECK_FLAG(p->af_cap[afi][safi],
12342 PEER_CAP_ORF_PREFIX_RM_ADV)
12343 || CHECK_FLAG(p->af_cap[afi][safi],
12344 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12345 vty_out(vty,
12346 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12347 ORF_TYPE_PREFIX_OLD);
12348 bgp_show_peer_afi_orf_cap(
12349 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12350 PEER_CAP_ORF_PREFIX_RM_ADV,
12351 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12352 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12353 }
12354
12355 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12356 p->host, afi, safi);
12357 orf_pfx_count = prefix_bgp_show_prefix_list(
12358 NULL, afi, orf_pfx_name, use_json);
12359
12360 if (CHECK_FLAG(p->af_sflags[afi][safi],
12361 PEER_STATUS_ORF_PREFIX_SEND)
12362 || orf_pfx_count) {
12363 vty_out(vty, " Outbound Route Filter (ORF):");
12364 if (CHECK_FLAG(p->af_sflags[afi][safi],
12365 PEER_STATUS_ORF_PREFIX_SEND))
12366 vty_out(vty, " sent;");
12367 if (orf_pfx_count)
12368 vty_out(vty, " received (%d entries)",
12369 orf_pfx_count);
12370 vty_out(vty, "\n");
12371 }
12372 if (CHECK_FLAG(p->af_sflags[afi][safi],
12373 PEER_STATUS_ORF_WAIT_REFRESH))
12374 vty_out(vty,
12375 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12376
12377 if (CHECK_FLAG(p->af_flags[afi][safi],
12378 PEER_FLAG_REFLECTOR_CLIENT))
12379 vty_out(vty, " Route-Reflector Client\n");
12380 if (CHECK_FLAG(p->af_flags[afi][safi],
12381 PEER_FLAG_RSERVER_CLIENT))
12382 vty_out(vty, " Route-Server Client\n");
12383 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12384 vty_out(vty,
12385 " Inbound soft reconfiguration allowed\n");
12386
12387 if (CHECK_FLAG(p->af_flags[afi][safi],
12388 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12389 vty_out(vty,
12390 " Private AS numbers (all) replaced in updates to this neighbor\n");
12391 else if (CHECK_FLAG(p->af_flags[afi][safi],
12392 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12393 vty_out(vty,
12394 " Private AS numbers replaced in updates to this neighbor\n");
12395 else if (CHECK_FLAG(p->af_flags[afi][safi],
12396 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12397 vty_out(vty,
12398 " Private AS numbers (all) removed in updates to this neighbor\n");
12399 else if (CHECK_FLAG(p->af_flags[afi][safi],
12400 PEER_FLAG_REMOVE_PRIVATE_AS))
12401 vty_out(vty,
12402 " Private AS numbers removed in updates to this neighbor\n");
12403
12404 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12405 vty_out(vty, " %s\n",
12406 bgp_addpath_names(p->addpath_type[afi][safi])
12407 ->human_description);
12408
12409 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12410 vty_out(vty,
12411 " Override ASNs in outbound updates if aspath equals remote-as\n");
12412
12413 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12414 || CHECK_FLAG(p->af_flags[afi][safi],
12415 PEER_FLAG_FORCE_NEXTHOP_SELF))
12416 vty_out(vty, " NEXT_HOP is always this router\n");
12417 if (CHECK_FLAG(p->af_flags[afi][safi],
12418 PEER_FLAG_AS_PATH_UNCHANGED))
12419 vty_out(vty,
12420 " AS_PATH is propagated unchanged to this neighbor\n");
12421 if (CHECK_FLAG(p->af_flags[afi][safi],
12422 PEER_FLAG_NEXTHOP_UNCHANGED))
12423 vty_out(vty,
12424 " NEXT_HOP is propagated unchanged to this neighbor\n");
12425 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12426 vty_out(vty,
12427 " MED is propagated unchanged to this neighbor\n");
12428 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12429 || CHECK_FLAG(p->af_flags[afi][safi],
12430 PEER_FLAG_SEND_EXT_COMMUNITY)
12431 || CHECK_FLAG(p->af_flags[afi][safi],
12432 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12433 vty_out(vty,
12434 " Community attribute sent to this neighbor");
12435 if (CHECK_FLAG(p->af_flags[afi][safi],
12436 PEER_FLAG_SEND_COMMUNITY)
12437 && CHECK_FLAG(p->af_flags[afi][safi],
12438 PEER_FLAG_SEND_EXT_COMMUNITY)
12439 && CHECK_FLAG(p->af_flags[afi][safi],
12440 PEER_FLAG_SEND_LARGE_COMMUNITY))
12441 vty_out(vty, "(all)\n");
12442 else if (CHECK_FLAG(p->af_flags[afi][safi],
12443 PEER_FLAG_SEND_LARGE_COMMUNITY))
12444 vty_out(vty, "(large)\n");
12445 else if (CHECK_FLAG(p->af_flags[afi][safi],
12446 PEER_FLAG_SEND_EXT_COMMUNITY))
12447 vty_out(vty, "(extended)\n");
12448 else
12449 vty_out(vty, "(standard)\n");
12450 }
12451 if (CHECK_FLAG(p->af_flags[afi][safi],
12452 PEER_FLAG_DEFAULT_ORIGINATE)) {
12453 vty_out(vty, " Default information originate,");
12454
12455 if (p->default_rmap[afi][safi].name)
12456 vty_out(vty, " default route-map %s%s,",
12457 p->default_rmap[afi][safi].map ? "*"
12458 : "",
12459 p->default_rmap[afi][safi].name);
12460 if (paf && PAF_SUBGRP(paf)
12461 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12462 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12463 vty_out(vty, " default sent\n");
12464 else
12465 vty_out(vty, " default not sent\n");
12466 }
12467
12468 /* advertise-vni-all */
12469 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12470 if (is_evpn_enabled())
12471 vty_out(vty, " advertise-all-vni\n");
12472 }
12473
12474 if (filter->plist[FILTER_IN].name
12475 || filter->dlist[FILTER_IN].name
12476 || filter->aslist[FILTER_IN].name
12477 || filter->map[RMAP_IN].name)
12478 vty_out(vty, " Inbound path policy configured\n");
12479 if (filter->plist[FILTER_OUT].name
12480 || filter->dlist[FILTER_OUT].name
12481 || filter->aslist[FILTER_OUT].name
12482 || filter->map[RMAP_OUT].name || filter->usmap.name)
12483 vty_out(vty, " Outbound path policy configured\n");
12484
12485 /* prefix-list */
12486 if (filter->plist[FILTER_IN].name)
12487 vty_out(vty,
12488 " Incoming update prefix filter list is %s%s\n",
12489 filter->plist[FILTER_IN].plist ? "*" : "",
12490 filter->plist[FILTER_IN].name);
12491 if (filter->plist[FILTER_OUT].name)
12492 vty_out(vty,
12493 " Outgoing update prefix filter list is %s%s\n",
12494 filter->plist[FILTER_OUT].plist ? "*" : "",
12495 filter->plist[FILTER_OUT].name);
12496
12497 /* distribute-list */
12498 if (filter->dlist[FILTER_IN].name)
12499 vty_out(vty,
12500 " Incoming update network filter list is %s%s\n",
12501 filter->dlist[FILTER_IN].alist ? "*" : "",
12502 filter->dlist[FILTER_IN].name);
12503 if (filter->dlist[FILTER_OUT].name)
12504 vty_out(vty,
12505 " Outgoing update network filter list is %s%s\n",
12506 filter->dlist[FILTER_OUT].alist ? "*" : "",
12507 filter->dlist[FILTER_OUT].name);
12508
12509 /* filter-list. */
12510 if (filter->aslist[FILTER_IN].name)
12511 vty_out(vty,
12512 " Incoming update AS path filter list is %s%s\n",
12513 filter->aslist[FILTER_IN].aslist ? "*" : "",
12514 filter->aslist[FILTER_IN].name);
12515 if (filter->aslist[FILTER_OUT].name)
12516 vty_out(vty,
12517 " Outgoing update AS path filter list is %s%s\n",
12518 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12519 filter->aslist[FILTER_OUT].name);
12520
12521 /* route-map. */
12522 if (filter->map[RMAP_IN].name)
12523 vty_out(vty,
12524 " Route map for incoming advertisements is %s%s\n",
12525 filter->map[RMAP_IN].map ? "*" : "",
12526 filter->map[RMAP_IN].name);
12527 if (filter->map[RMAP_OUT].name)
12528 vty_out(vty,
12529 " Route map for outgoing advertisements is %s%s\n",
12530 filter->map[RMAP_OUT].map ? "*" : "",
12531 filter->map[RMAP_OUT].name);
12532
12533 /* ebgp-requires-policy (inbound) */
12534 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12535 && !bgp_inbound_policy_exists(p, filter))
12536 vty_out(vty,
12537 " Inbound updates discarded due to missing policy\n");
12538
12539 /* ebgp-requires-policy (outbound) */
12540 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12541 && !bgp_outbound_policy_exists(p, filter))
12542 vty_out(vty,
12543 " Outbound updates discarded due to missing policy\n");
12544
12545 /* unsuppress-map */
12546 if (filter->usmap.name)
12547 vty_out(vty,
12548 " Route map for selective unsuppress is %s%s\n",
12549 filter->usmap.map ? "*" : "",
12550 filter->usmap.name);
12551
12552 /* advertise-map */
12553 if (filter->advmap.aname && filter->advmap.cname)
12554 vty_out(vty,
12555 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12556 filter->advmap.condition ? "EXIST"
12557 : "NON_EXIST",
12558 filter->advmap.cmap ? "*" : "",
12559 filter->advmap.cname,
12560 filter->advmap.amap ? "*" : "",
12561 filter->advmap.aname,
12562 filter->advmap.update_type ==
12563 UPDATE_TYPE_ADVERTISE
12564 ? "Advertise"
12565 : "Withdraw");
12566
12567 /* Receive prefix count */
12568 vty_out(vty, " %u accepted prefixes\n",
12569 p->pcount[afi][safi]);
12570
12571 /* maximum-prefix-out */
12572 if (CHECK_FLAG(p->af_flags[afi][safi],
12573 PEER_FLAG_MAX_PREFIX_OUT))
12574 vty_out(vty,
12575 " Maximum allowed prefixes sent %u\n",
12576 p->pmax_out[afi][safi]);
12577
12578 /* Maximum prefix */
12579 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12580 vty_out(vty,
12581 " Maximum prefixes allowed %u%s\n",
12582 p->pmax[afi][safi],
12583 CHECK_FLAG(p->af_flags[afi][safi],
12584 PEER_FLAG_MAX_PREFIX_WARNING)
12585 ? " (warning-only)"
12586 : "");
12587 vty_out(vty, " Threshold for warning message %d%%",
12588 p->pmax_threshold[afi][safi]);
12589 if (p->pmax_restart[afi][safi])
12590 vty_out(vty, ", restart interval %d min",
12591 p->pmax_restart[afi][safi]);
12592 vty_out(vty, "\n");
12593 }
12594
12595 vty_out(vty, "\n");
12596 }
12597 }
12598
12599 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12600 json_object *json)
12601 {
12602 struct bgp *bgp;
12603 char buf1[PREFIX2STR_BUFFER];
12604 char timebuf[BGP_UPTIME_LEN];
12605 char dn_flag[2];
12606 afi_t afi;
12607 safi_t safi;
12608 uint16_t i;
12609 uint8_t *msg;
12610 json_object *json_neigh = NULL;
12611 time_t epoch_tbuf;
12612 uint32_t sync_tcp_mss;
12613
12614 bgp = p->bgp;
12615
12616 if (use_json)
12617 json_neigh = json_object_new_object();
12618
12619 memset(dn_flag, '\0', sizeof(dn_flag));
12620 if (!p->conf_if && peer_dynamic_neighbor(p))
12621 dn_flag[0] = '*';
12622
12623 if (!use_json) {
12624 if (p->conf_if) /* Configured interface name. */
12625 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12626 &p->su);
12627 else /* Configured IP address. */
12628 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12629 p->host);
12630 }
12631
12632 if (use_json) {
12633 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12634 json_object_string_add(json_neigh, "bgpNeighborAddr",
12635 "none");
12636 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12637 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12638 "%pSU", &p->su);
12639
12640 json_object_int_add(json_neigh, "remoteAs", p->as);
12641
12642 if (p->change_local_as)
12643 json_object_int_add(json_neigh, "localAs",
12644 p->change_local_as);
12645 else
12646 json_object_int_add(json_neigh, "localAs", p->local_as);
12647
12648 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12649 json_object_boolean_true_add(json_neigh,
12650 "localAsNoPrepend");
12651
12652 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12653 json_object_boolean_true_add(json_neigh,
12654 "localAsReplaceAs");
12655 } else {
12656 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12657 || (p->as_type == AS_INTERNAL))
12658 vty_out(vty, "remote AS %u, ", p->as);
12659 else
12660 vty_out(vty, "remote AS Unspecified, ");
12661 vty_out(vty, "local AS %u%s%s, ",
12662 p->change_local_as ? p->change_local_as : p->local_as,
12663 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12664 ? " no-prepend"
12665 : "",
12666 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12667 ? " replace-as"
12668 : "");
12669 }
12670 /* peer type internal or confed-internal */
12671 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12672 if (use_json) {
12673 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12674 json_object_boolean_true_add(
12675 json_neigh, "nbrConfedInternalLink");
12676 else
12677 json_object_boolean_true_add(json_neigh,
12678 "nbrInternalLink");
12679 } else {
12680 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12681 vty_out(vty, "confed-internal link\n");
12682 else
12683 vty_out(vty, "internal link\n");
12684 }
12685 /* peer type external or confed-external */
12686 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12687 if (use_json) {
12688 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12689 json_object_boolean_true_add(
12690 json_neigh, "nbrConfedExternalLink");
12691 else
12692 json_object_boolean_true_add(json_neigh,
12693 "nbrExternalLink");
12694 } else {
12695 if (bgp_confederation_peers_check(bgp, p->as))
12696 vty_out(vty, "confed-external link\n");
12697 else
12698 vty_out(vty, "external link\n");
12699 }
12700 } else {
12701 if (use_json)
12702 json_object_boolean_true_add(json_neigh,
12703 "nbrUnspecifiedLink");
12704 else
12705 vty_out(vty, "unspecified link\n");
12706 }
12707
12708 /* Roles */
12709 if (use_json) {
12710 json_object_string_add(json_neigh, "localRole",
12711 bgp_get_name_by_role(p->local_role));
12712 json_object_string_add(json_neigh, "remoteRole",
12713 bgp_get_name_by_role(p->remote_role));
12714 } else {
12715 vty_out(vty, " Local Role: %s\n",
12716 bgp_get_name_by_role(p->local_role));
12717 vty_out(vty, " Remote Role: %s\n",
12718 bgp_get_name_by_role(p->remote_role));
12719 }
12720
12721
12722 /* Description. */
12723 if (p->desc) {
12724 if (use_json)
12725 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12726 else
12727 vty_out(vty, " Description: %s\n", p->desc);
12728 }
12729
12730 if (p->hostname) {
12731 if (use_json) {
12732 if (p->hostname)
12733 json_object_string_add(json_neigh, "hostname",
12734 p->hostname);
12735
12736 if (p->domainname)
12737 json_object_string_add(json_neigh, "domainname",
12738 p->domainname);
12739 } else {
12740 if (p->domainname && (p->domainname[0] != '\0'))
12741 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12742 p->domainname);
12743 else
12744 vty_out(vty, "Hostname: %s\n", p->hostname);
12745 }
12746 }
12747
12748 /* Peer-group */
12749 if (p->group) {
12750 if (use_json) {
12751 json_object_string_add(json_neigh, "peerGroup",
12752 p->group->name);
12753
12754 if (dn_flag[0]) {
12755 struct prefix prefix, *range = NULL;
12756
12757 if (sockunion2hostprefix(&(p->su), &prefix))
12758 range = peer_group_lookup_dynamic_neighbor_range(
12759 p->group, &prefix);
12760
12761 if (range) {
12762 json_object_string_addf(
12763 json_neigh,
12764 "peerSubnetRangeGroup", "%pFX",
12765 range);
12766 }
12767 }
12768 } else {
12769 vty_out(vty,
12770 " Member of peer-group %s for session parameters\n",
12771 p->group->name);
12772
12773 if (dn_flag[0]) {
12774 struct prefix prefix, *range = NULL;
12775
12776 if (sockunion2hostprefix(&(p->su), &prefix))
12777 range = peer_group_lookup_dynamic_neighbor_range(
12778 p->group, &prefix);
12779
12780 if (range) {
12781 vty_out(vty,
12782 " Belongs to the subnet range group: %pFX\n",
12783 range);
12784 }
12785 }
12786 }
12787 }
12788
12789 if (use_json) {
12790 /* Administrative shutdown. */
12791 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12792 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12793 json_object_boolean_true_add(json_neigh,
12794 "adminShutDown");
12795
12796 /* BGP Version. */
12797 json_object_int_add(json_neigh, "bgpVersion", 4);
12798 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12799 &p->remote_id);
12800 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12801 &bgp->router_id);
12802
12803 /* Confederation */
12804 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12805 && bgp_confederation_peers_check(bgp, p->as))
12806 json_object_boolean_true_add(json_neigh,
12807 "nbrCommonAdmin");
12808
12809 /* Status. */
12810 json_object_string_add(
12811 json_neigh, "bgpState",
12812 lookup_msg(bgp_status_msg, p->status, NULL));
12813
12814 if (peer_established(p)) {
12815 time_t uptime;
12816
12817 uptime = monotime(NULL);
12818 uptime -= p->uptime;
12819 epoch_tbuf = time(NULL) - uptime;
12820
12821 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12822 uptime * 1000);
12823 json_object_string_add(json_neigh, "bgpTimerUpString",
12824 peer_uptime(p->uptime, timebuf,
12825 BGP_UPTIME_LEN, 0,
12826 NULL));
12827 json_object_int_add(json_neigh,
12828 "bgpTimerUpEstablishedEpoch",
12829 epoch_tbuf);
12830 }
12831
12832 else if (p->status == Active) {
12833 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12834 json_object_string_add(json_neigh, "bgpStateIs",
12835 "passive");
12836 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12837 json_object_string_add(json_neigh, "bgpStateIs",
12838 "passiveNSF");
12839 }
12840
12841 /* read timer */
12842 time_t uptime;
12843 struct tm tm;
12844
12845 uptime = monotime(NULL);
12846 uptime -= p->readtime;
12847 gmtime_r(&uptime, &tm);
12848
12849 json_object_int_add(json_neigh, "bgpTimerLastRead",
12850 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12851 + (tm.tm_hour * 3600000));
12852
12853 uptime = monotime(NULL);
12854 uptime -= p->last_write;
12855 gmtime_r(&uptime, &tm);
12856
12857 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12858 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12859 + (tm.tm_hour * 3600000));
12860
12861 uptime = monotime(NULL);
12862 uptime -= p->update_time;
12863 gmtime_r(&uptime, &tm);
12864
12865 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12866 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12867 + (tm.tm_hour * 3600000));
12868
12869 /* Configured timer values. */
12870 json_object_int_add(json_neigh,
12871 "bgpTimerConfiguredHoldTimeMsecs",
12872 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12873 ? p->holdtime * 1000
12874 : bgp->default_holdtime * 1000);
12875 json_object_int_add(json_neigh,
12876 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12877 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12878 ? p->keepalive * 1000
12879 : bgp->default_keepalive * 1000);
12880 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12881 p->v_holdtime * 1000);
12882 json_object_int_add(json_neigh,
12883 "bgpTimerKeepAliveIntervalMsecs",
12884 p->v_keepalive * 1000);
12885 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12886 json_object_int_add(json_neigh,
12887 "bgpTimerDelayOpenTimeMsecs",
12888 p->v_delayopen * 1000);
12889 }
12890
12891 /* Configured and Synced tcp-mss value for peer */
12892 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12893 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12894 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12895 p->tcp_mss);
12896 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12897 sync_tcp_mss);
12898 }
12899
12900 /* Extended Optional Parameters Length for BGP OPEN Message */
12901 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12902 json_object_boolean_true_add(
12903 json_neigh, "extendedOptionalParametersLength");
12904 else
12905 json_object_boolean_false_add(
12906 json_neigh, "extendedOptionalParametersLength");
12907
12908 /* Conditional advertisements */
12909 json_object_int_add(
12910 json_neigh,
12911 "bgpTimerConfiguredConditionalAdvertisementsSec",
12912 bgp->condition_check_period);
12913 if (thread_is_scheduled(bgp->t_condition_check))
12914 json_object_int_add(
12915 json_neigh,
12916 "bgpTimerUntilConditionalAdvertisementsSec",
12917 thread_timer_remain_second(
12918 bgp->t_condition_check));
12919 } else {
12920 /* Administrative shutdown. */
12921 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12922 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12923 vty_out(vty, " Administratively shut down\n");
12924
12925 /* BGP Version. */
12926 vty_out(vty, " BGP version 4");
12927 vty_out(vty, ", remote router ID %s",
12928 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12929 vty_out(vty, ", local router ID %s\n",
12930 inet_ntop(AF_INET, &bgp->router_id, buf1,
12931 sizeof(buf1)));
12932
12933 /* Confederation */
12934 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12935 && bgp_confederation_peers_check(bgp, p->as))
12936 vty_out(vty,
12937 " Neighbor under common administration\n");
12938
12939 /* Status. */
12940 vty_out(vty, " BGP state = %s",
12941 lookup_msg(bgp_status_msg, p->status, NULL));
12942
12943 if (peer_established(p))
12944 vty_out(vty, ", up for %8s",
12945 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12946 0, NULL));
12947
12948 else if (p->status == Active) {
12949 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12950 vty_out(vty, " (passive)");
12951 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12952 vty_out(vty, " (NSF passive)");
12953 }
12954 vty_out(vty, "\n");
12955
12956 /* read timer */
12957 vty_out(vty, " Last read %s",
12958 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12959 NULL));
12960 vty_out(vty, ", Last write %s\n",
12961 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12962 NULL));
12963
12964 /* Configured timer values. */
12965 vty_out(vty,
12966 " Hold time is %d seconds, keepalive interval is %d seconds\n",
12967 p->v_holdtime, p->v_keepalive);
12968 vty_out(vty, " Configured hold time is %d seconds",
12969 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12970 ? p->holdtime
12971 : bgp->default_holdtime);
12972 vty_out(vty, ", keepalive interval is %d seconds\n",
12973 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12974 ? p->keepalive
12975 : bgp->default_keepalive);
12976 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12977 vty_out(vty,
12978 " Configured DelayOpenTime is %d seconds\n",
12979 p->delayopen);
12980
12981 /* Configured and synced tcp-mss value for peer */
12982 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12983 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12984 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12985 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12986 }
12987
12988 /* Extended Optional Parameters Length for BGP OPEN Message */
12989 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12990 vty_out(vty,
12991 " Extended Optional Parameters Length is enabled\n");
12992
12993 /* Conditional advertisements */
12994 vty_out(vty,
12995 " Configured conditional advertisements interval is %d seconds\n",
12996 bgp->condition_check_period);
12997 if (thread_is_scheduled(bgp->t_condition_check))
12998 vty_out(vty,
12999 " Time until conditional advertisements begin is %lu seconds\n",
13000 thread_timer_remain_second(
13001 bgp->t_condition_check));
13002 }
13003 /* Capability. */
13004 if (peer_established(p) &&
13005 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13006 if (use_json) {
13007 json_object *json_cap = NULL;
13008
13009 json_cap = json_object_new_object();
13010
13011 /* AS4 */
13012 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13013 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13014 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13015 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13016 json_object_string_add(
13017 json_cap, "4byteAs",
13018 "advertisedAndReceived");
13019 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13020 json_object_string_add(json_cap,
13021 "4byteAs",
13022 "advertised");
13023 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13024 json_object_string_add(json_cap,
13025 "4byteAs",
13026 "received");
13027 }
13028
13029 /* Extended Message Support */
13030 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13031 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13032 json_object_string_add(json_cap,
13033 "extendedMessage",
13034 "advertisedAndReceived");
13035 else if (CHECK_FLAG(p->cap,
13036 PEER_CAP_EXTENDED_MESSAGE_ADV))
13037 json_object_string_add(json_cap,
13038 "extendedMessage",
13039 "advertised");
13040 else if (CHECK_FLAG(p->cap,
13041 PEER_CAP_EXTENDED_MESSAGE_RCV))
13042 json_object_string_add(json_cap,
13043 "extendedMessage",
13044 "received");
13045
13046 /* AddPath */
13047 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13048 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13049 json_object *json_add = NULL;
13050 const char *print_store;
13051
13052 json_add = json_object_new_object();
13053
13054 FOREACH_AFI_SAFI (afi, safi) {
13055 json_object *json_sub = NULL;
13056 json_sub = json_object_new_object();
13057 print_store = get_afi_safi_str(
13058 afi, safi, true);
13059
13060 if (CHECK_FLAG(
13061 p->af_cap[afi][safi],
13062 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13063 CHECK_FLAG(
13064 p->af_cap[afi][safi],
13065 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13066 if (CHECK_FLAG(
13067 p->af_cap[afi]
13068 [safi],
13069 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13070 CHECK_FLAG(
13071 p->af_cap[afi]
13072 [safi],
13073 PEER_CAP_ADDPATH_AF_TX_RCV))
13074 json_object_boolean_true_add(
13075 json_sub,
13076 "txAdvertisedAndReceived");
13077 else if (
13078 CHECK_FLAG(
13079 p->af_cap[afi]
13080 [safi],
13081 PEER_CAP_ADDPATH_AF_TX_ADV))
13082 json_object_boolean_true_add(
13083 json_sub,
13084 "txAdvertised");
13085 else if (
13086 CHECK_FLAG(
13087 p->af_cap[afi]
13088 [safi],
13089 PEER_CAP_ADDPATH_AF_TX_RCV))
13090 json_object_boolean_true_add(
13091 json_sub,
13092 "txReceived");
13093 }
13094
13095 if (CHECK_FLAG(
13096 p->af_cap[afi][safi],
13097 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13098 CHECK_FLAG(
13099 p->af_cap[afi][safi],
13100 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13101 if (CHECK_FLAG(
13102 p->af_cap[afi]
13103 [safi],
13104 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13105 CHECK_FLAG(
13106 p->af_cap[afi]
13107 [safi],
13108 PEER_CAP_ADDPATH_AF_RX_RCV))
13109 json_object_boolean_true_add(
13110 json_sub,
13111 "rxAdvertisedAndReceived");
13112 else if (
13113 CHECK_FLAG(
13114 p->af_cap[afi]
13115 [safi],
13116 PEER_CAP_ADDPATH_AF_RX_ADV))
13117 json_object_boolean_true_add(
13118 json_sub,
13119 "rxAdvertised");
13120 else if (
13121 CHECK_FLAG(
13122 p->af_cap[afi]
13123 [safi],
13124 PEER_CAP_ADDPATH_AF_RX_RCV))
13125 json_object_boolean_true_add(
13126 json_sub,
13127 "rxReceived");
13128 }
13129
13130 if (CHECK_FLAG(
13131 p->af_cap[afi][safi],
13132 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13133 CHECK_FLAG(
13134 p->af_cap[afi][safi],
13135 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13136 CHECK_FLAG(
13137 p->af_cap[afi][safi],
13138 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13139 CHECK_FLAG(
13140 p->af_cap[afi][safi],
13141 PEER_CAP_ADDPATH_AF_RX_RCV))
13142 json_object_object_add(
13143 json_add, print_store,
13144 json_sub);
13145 else
13146 json_object_free(json_sub);
13147 }
13148
13149 json_object_object_add(json_cap, "addPath",
13150 json_add);
13151 }
13152
13153 /* Dynamic */
13154 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13155 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13156 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13157 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13158 json_object_string_add(
13159 json_cap, "dynamic",
13160 "advertisedAndReceived");
13161 else if (CHECK_FLAG(p->cap,
13162 PEER_CAP_DYNAMIC_ADV))
13163 json_object_string_add(json_cap,
13164 "dynamic",
13165 "advertised");
13166 else if (CHECK_FLAG(p->cap,
13167 PEER_CAP_DYNAMIC_RCV))
13168 json_object_string_add(json_cap,
13169 "dynamic",
13170 "received");
13171 }
13172
13173 /* Role */
13174 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13175 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13176 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13177 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13178 json_object_string_add(
13179 json_cap, "role",
13180 "advertisedAndReceived");
13181 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13182 json_object_string_add(json_cap, "role",
13183 "advertised");
13184 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13185 json_object_string_add(json_cap, "role",
13186 "received");
13187 }
13188
13189 /* Extended nexthop */
13190 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13191 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13192 json_object *json_nxt = NULL;
13193 const char *print_store;
13194
13195
13196 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13197 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13198 json_object_string_add(
13199 json_cap, "extendedNexthop",
13200 "advertisedAndReceived");
13201 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13202 json_object_string_add(
13203 json_cap, "extendedNexthop",
13204 "advertised");
13205 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13206 json_object_string_add(
13207 json_cap, "extendedNexthop",
13208 "received");
13209
13210 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13211 json_nxt = json_object_new_object();
13212
13213 for (safi = SAFI_UNICAST;
13214 safi < SAFI_MAX; safi++) {
13215 if (CHECK_FLAG(
13216 p->af_cap[AFI_IP]
13217 [safi],
13218 PEER_CAP_ENHE_AF_RCV)) {
13219 print_store =
13220 get_afi_safi_str(
13221 AFI_IP,
13222 safi,
13223 true);
13224 json_object_string_add(
13225 json_nxt,
13226 print_store,
13227 "recieved"); /* misspelled for compatibility */
13228 }
13229 }
13230 json_object_object_add(
13231 json_cap,
13232 "extendedNexthopFamililesByPeer",
13233 json_nxt);
13234 }
13235 }
13236
13237 /* Long-lived Graceful Restart */
13238 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13239 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13240 json_object *json_llgr = NULL;
13241 const char *afi_safi_str;
13242
13243 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13244 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13245 json_object_string_add(
13246 json_cap,
13247 "longLivedGracefulRestart",
13248 "advertisedAndReceived");
13249 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13250 json_object_string_add(
13251 json_cap,
13252 "longLivedGracefulRestart",
13253 "advertised");
13254 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13255 json_object_string_add(
13256 json_cap,
13257 "longLivedGracefulRestart",
13258 "received");
13259
13260 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13261 json_llgr = json_object_new_object();
13262
13263 FOREACH_AFI_SAFI (afi, safi) {
13264 if (CHECK_FLAG(
13265 p->af_cap[afi]
13266 [safi],
13267 PEER_CAP_ENHE_AF_RCV)) {
13268 afi_safi_str =
13269 get_afi_safi_str(
13270 afi,
13271 safi,
13272 true);
13273 json_object_string_add(
13274 json_llgr,
13275 afi_safi_str,
13276 "received");
13277 }
13278 }
13279 json_object_object_add(
13280 json_cap,
13281 "longLivedGracefulRestartByPeer",
13282 json_llgr);
13283 }
13284 }
13285
13286 /* Route Refresh */
13287 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13288 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13289 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13290 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13291 (CHECK_FLAG(p->cap,
13292 PEER_CAP_REFRESH_NEW_RCV) ||
13293 CHECK_FLAG(p->cap,
13294 PEER_CAP_REFRESH_OLD_RCV))) {
13295 if (CHECK_FLAG(
13296 p->cap,
13297 PEER_CAP_REFRESH_OLD_RCV) &&
13298 CHECK_FLAG(
13299 p->cap,
13300 PEER_CAP_REFRESH_NEW_RCV))
13301 json_object_string_add(
13302 json_cap,
13303 "routeRefresh",
13304 "advertisedAndReceivedOldNew");
13305 else {
13306 if (CHECK_FLAG(
13307 p->cap,
13308 PEER_CAP_REFRESH_OLD_RCV))
13309 json_object_string_add(
13310 json_cap,
13311 "routeRefresh",
13312 "advertisedAndReceivedOld");
13313 else
13314 json_object_string_add(
13315 json_cap,
13316 "routeRefresh",
13317 "advertisedAndReceivedNew");
13318 }
13319 } else if (CHECK_FLAG(p->cap,
13320 PEER_CAP_REFRESH_ADV))
13321 json_object_string_add(json_cap,
13322 "routeRefresh",
13323 "advertised");
13324 else if (CHECK_FLAG(p->cap,
13325 PEER_CAP_REFRESH_NEW_RCV) ||
13326 CHECK_FLAG(p->cap,
13327 PEER_CAP_REFRESH_OLD_RCV))
13328 json_object_string_add(json_cap,
13329 "routeRefresh",
13330 "received");
13331 }
13332
13333 /* Enhanced Route Refresh */
13334 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13335 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13336 if (CHECK_FLAG(p->cap,
13337 PEER_CAP_ENHANCED_RR_ADV) &&
13338 CHECK_FLAG(p->cap,
13339 PEER_CAP_ENHANCED_RR_RCV))
13340 json_object_string_add(
13341 json_cap,
13342 "enhancedRouteRefresh",
13343 "advertisedAndReceived");
13344 else if (CHECK_FLAG(p->cap,
13345 PEER_CAP_ENHANCED_RR_ADV))
13346 json_object_string_add(
13347 json_cap,
13348 "enhancedRouteRefresh",
13349 "advertised");
13350 else if (CHECK_FLAG(p->cap,
13351 PEER_CAP_ENHANCED_RR_RCV))
13352 json_object_string_add(
13353 json_cap,
13354 "enhancedRouteRefresh",
13355 "received");
13356 }
13357
13358 /* Multiprotocol Extensions */
13359 json_object *json_multi = NULL;
13360
13361 json_multi = json_object_new_object();
13362
13363 FOREACH_AFI_SAFI (afi, safi) {
13364 if (p->afc_adv[afi][safi] ||
13365 p->afc_recv[afi][safi]) {
13366 json_object *json_exten = NULL;
13367 json_exten = json_object_new_object();
13368
13369 if (p->afc_adv[afi][safi] &&
13370 p->afc_recv[afi][safi])
13371 json_object_boolean_true_add(
13372 json_exten,
13373 "advertisedAndReceived");
13374 else if (p->afc_adv[afi][safi])
13375 json_object_boolean_true_add(
13376 json_exten,
13377 "advertised");
13378 else if (p->afc_recv[afi][safi])
13379 json_object_boolean_true_add(
13380 json_exten, "received");
13381
13382 json_object_object_add(
13383 json_multi,
13384 get_afi_safi_str(afi, safi,
13385 true),
13386 json_exten);
13387 }
13388 }
13389 json_object_object_add(json_cap,
13390 "multiprotocolExtensions",
13391 json_multi);
13392
13393 /* Hostname capabilities */
13394 json_object *json_hname = NULL;
13395
13396 json_hname = json_object_new_object();
13397
13398 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13399 json_object_string_add(
13400 json_hname, "advHostName",
13401 bgp->peer_self->hostname
13402 ? bgp->peer_self->hostname
13403 : "n/a");
13404 json_object_string_add(
13405 json_hname, "advDomainName",
13406 bgp->peer_self->domainname
13407 ? bgp->peer_self->domainname
13408 : "n/a");
13409 }
13410
13411
13412 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13413 json_object_string_add(
13414 json_hname, "rcvHostName",
13415 p->hostname ? p->hostname : "n/a");
13416 json_object_string_add(
13417 json_hname, "rcvDomainName",
13418 p->domainname ? p->domainname : "n/a");
13419 }
13420
13421 json_object_object_add(json_cap, "hostName",
13422 json_hname);
13423
13424 /* Graceful Restart */
13425 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13426 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13427 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13428 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13429 json_object_string_add(
13430 json_cap, "gracefulRestart",
13431 "advertisedAndReceived");
13432 else if (CHECK_FLAG(p->cap,
13433 PEER_CAP_RESTART_ADV))
13434 json_object_string_add(
13435 json_cap,
13436 "gracefulRestartCapability",
13437 "advertised");
13438 else if (CHECK_FLAG(p->cap,
13439 PEER_CAP_RESTART_RCV))
13440 json_object_string_add(
13441 json_cap,
13442 "gracefulRestartCapability",
13443 "received");
13444
13445 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13446 int restart_af_count = 0;
13447 json_object *json_restart = NULL;
13448 json_restart = json_object_new_object();
13449
13450 json_object_int_add(
13451 json_cap,
13452 "gracefulRestartRemoteTimerMsecs",
13453 p->v_gr_restart * 1000);
13454
13455 FOREACH_AFI_SAFI (afi, safi) {
13456 if (CHECK_FLAG(
13457 p->af_cap[afi]
13458 [safi],
13459 PEER_CAP_RESTART_AF_RCV)) {
13460 json_object *json_sub =
13461 NULL;
13462 json_sub =
13463 json_object_new_object();
13464
13465 if (CHECK_FLAG(
13466 p->af_cap
13467 [afi]
13468 [safi],
13469 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13470 json_object_boolean_true_add(
13471 json_sub,
13472 "preserved");
13473 restart_af_count++;
13474 json_object_object_add(
13475 json_restart,
13476 get_afi_safi_str(
13477 afi,
13478 safi,
13479 true),
13480 json_sub);
13481 }
13482 }
13483 if (!restart_af_count) {
13484 json_object_string_add(
13485 json_cap,
13486 "addressFamiliesByPeer",
13487 "none");
13488 json_object_free(json_restart);
13489 } else
13490 json_object_object_add(
13491 json_cap,
13492 "addressFamiliesByPeer",
13493 json_restart);
13494 }
13495 }
13496 json_object_object_add(
13497 json_neigh, "neighborCapabilities", json_cap);
13498 } else {
13499 vty_out(vty, " Neighbor capabilities:\n");
13500
13501 /* AS4 */
13502 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13503 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13504 vty_out(vty, " 4 Byte AS:");
13505 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13506 vty_out(vty, " advertised");
13507 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13508 vty_out(vty, " %sreceived",
13509 CHECK_FLAG(p->cap,
13510 PEER_CAP_AS4_ADV)
13511 ? "and "
13512 : "");
13513 vty_out(vty, "\n");
13514 }
13515
13516 /* Extended Message Support */
13517 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13518 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13519 vty_out(vty, " Extended Message:");
13520 if (CHECK_FLAG(p->cap,
13521 PEER_CAP_EXTENDED_MESSAGE_ADV))
13522 vty_out(vty, " advertised");
13523 if (CHECK_FLAG(p->cap,
13524 PEER_CAP_EXTENDED_MESSAGE_RCV))
13525 vty_out(vty, " %sreceived",
13526 CHECK_FLAG(
13527 p->cap,
13528 PEER_CAP_EXTENDED_MESSAGE_ADV)
13529 ? "and "
13530 : "");
13531 vty_out(vty, "\n");
13532 }
13533
13534 /* AddPath */
13535 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13536 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13537 vty_out(vty, " AddPath:\n");
13538
13539 FOREACH_AFI_SAFI (afi, safi) {
13540 if (CHECK_FLAG(
13541 p->af_cap[afi][safi],
13542 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13543 CHECK_FLAG(
13544 p->af_cap[afi][safi],
13545 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13546 vty_out(vty, " %s: TX ",
13547 get_afi_safi_str(
13548 afi, safi,
13549 false));
13550
13551 if (CHECK_FLAG(
13552 p->af_cap[afi]
13553 [safi],
13554 PEER_CAP_ADDPATH_AF_TX_ADV))
13555 vty_out(vty,
13556 "advertised");
13557
13558 if (CHECK_FLAG(
13559 p->af_cap[afi]
13560 [safi],
13561 PEER_CAP_ADDPATH_AF_TX_RCV))
13562 vty_out(vty,
13563 "%sreceived",
13564 CHECK_FLAG(
13565 p->af_cap
13566 [afi]
13567 [safi],
13568 PEER_CAP_ADDPATH_AF_TX_ADV)
13569 ? " and "
13570 : "");
13571
13572 vty_out(vty, "\n");
13573 }
13574
13575 if (CHECK_FLAG(
13576 p->af_cap[afi][safi],
13577 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13578 CHECK_FLAG(
13579 p->af_cap[afi][safi],
13580 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13581 vty_out(vty, " %s: RX ",
13582 get_afi_safi_str(
13583 afi, safi,
13584 false));
13585
13586 if (CHECK_FLAG(
13587 p->af_cap[afi]
13588 [safi],
13589 PEER_CAP_ADDPATH_AF_RX_ADV))
13590 vty_out(vty,
13591 "advertised");
13592
13593 if (CHECK_FLAG(
13594 p->af_cap[afi]
13595 [safi],
13596 PEER_CAP_ADDPATH_AF_RX_RCV))
13597 vty_out(vty,
13598 "%sreceived",
13599 CHECK_FLAG(
13600 p->af_cap
13601 [afi]
13602 [safi],
13603 PEER_CAP_ADDPATH_AF_RX_ADV)
13604 ? " and "
13605 : "");
13606
13607 vty_out(vty, "\n");
13608 }
13609 }
13610 }
13611
13612 /* Dynamic */
13613 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13614 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13615 vty_out(vty, " Dynamic:");
13616 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13617 vty_out(vty, " advertised");
13618 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13619 vty_out(vty, " %sreceived",
13620 CHECK_FLAG(p->cap,
13621 PEER_CAP_DYNAMIC_ADV)
13622 ? "and "
13623 : "");
13624 vty_out(vty, "\n");
13625 }
13626
13627 /* Role */
13628 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13629 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13630 vty_out(vty, " Role:");
13631 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13632 vty_out(vty, " advertised");
13633 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13634 vty_out(vty, " %sreceived",
13635 CHECK_FLAG(p->cap,
13636 PEER_CAP_ROLE_ADV)
13637 ? "and "
13638 : "");
13639 vty_out(vty, "\n");
13640 }
13641
13642 /* Extended nexthop */
13643 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13644 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13645 vty_out(vty, " Extended nexthop:");
13646 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13647 vty_out(vty, " advertised");
13648 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13649 vty_out(vty, " %sreceived",
13650 CHECK_FLAG(p->cap,
13651 PEER_CAP_ENHE_ADV)
13652 ? "and "
13653 : "");
13654 vty_out(vty, "\n");
13655
13656 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13657 vty_out(vty,
13658 " Address families by peer:\n ");
13659 for (safi = SAFI_UNICAST;
13660 safi < SAFI_MAX; safi++)
13661 if (CHECK_FLAG(
13662 p->af_cap[AFI_IP]
13663 [safi],
13664 PEER_CAP_ENHE_AF_RCV))
13665 vty_out(vty,
13666 " %s\n",
13667 get_afi_safi_str(
13668 AFI_IP,
13669 safi,
13670 false));
13671 }
13672 }
13673
13674 /* Long-lived Graceful Restart */
13675 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13676 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13677 vty_out(vty,
13678 " Long-lived Graceful Restart:");
13679 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13680 vty_out(vty, " advertised");
13681 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13682 vty_out(vty, " %sreceived",
13683 CHECK_FLAG(p->cap,
13684 PEER_CAP_LLGR_ADV)
13685 ? "and "
13686 : "");
13687 vty_out(vty, "\n");
13688
13689 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13690 vty_out(vty,
13691 " Address families by peer:\n");
13692 FOREACH_AFI_SAFI (afi, safi)
13693 if (CHECK_FLAG(
13694 p->af_cap[afi]
13695 [safi],
13696 PEER_CAP_LLGR_AF_RCV))
13697 vty_out(vty,
13698 " %s\n",
13699 get_afi_safi_str(
13700 afi,
13701 safi,
13702 false));
13703 }
13704 }
13705
13706 /* Route Refresh */
13707 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13708 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13709 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13710 vty_out(vty, " Route refresh:");
13711 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13712 vty_out(vty, " advertised");
13713 if (CHECK_FLAG(p->cap,
13714 PEER_CAP_REFRESH_NEW_RCV) ||
13715 CHECK_FLAG(p->cap,
13716 PEER_CAP_REFRESH_OLD_RCV))
13717 vty_out(vty, " %sreceived(%s)",
13718 CHECK_FLAG(p->cap,
13719 PEER_CAP_REFRESH_ADV)
13720 ? "and "
13721 : "",
13722 (CHECK_FLAG(
13723 p->cap,
13724 PEER_CAP_REFRESH_OLD_RCV) &&
13725 CHECK_FLAG(
13726 p->cap,
13727 PEER_CAP_REFRESH_NEW_RCV))
13728 ? "old & new"
13729 : CHECK_FLAG(
13730 p->cap,
13731 PEER_CAP_REFRESH_OLD_RCV)
13732 ? "old"
13733 : "new");
13734
13735 vty_out(vty, "\n");
13736 }
13737
13738 /* Enhanced Route Refresh */
13739 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13740 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13741 vty_out(vty, " Enhanced Route Refresh:");
13742 if (CHECK_FLAG(p->cap,
13743 PEER_CAP_ENHANCED_RR_ADV))
13744 vty_out(vty, " advertised");
13745 if (CHECK_FLAG(p->cap,
13746 PEER_CAP_ENHANCED_RR_RCV))
13747 vty_out(vty, " %sreceived",
13748 CHECK_FLAG(p->cap,
13749 PEER_CAP_REFRESH_ADV)
13750 ? "and "
13751 : "");
13752 vty_out(vty, "\n");
13753 }
13754
13755 /* Multiprotocol Extensions */
13756 FOREACH_AFI_SAFI (afi, safi)
13757 if (p->afc_adv[afi][safi] ||
13758 p->afc_recv[afi][safi]) {
13759 vty_out(vty, " Address Family %s:",
13760 get_afi_safi_str(afi, safi,
13761 false));
13762 if (p->afc_adv[afi][safi])
13763 vty_out(vty, " advertised");
13764 if (p->afc_recv[afi][safi])
13765 vty_out(vty, " %sreceived",
13766 p->afc_adv[afi][safi]
13767 ? "and "
13768 : "");
13769 vty_out(vty, "\n");
13770 }
13771
13772 /* Hostname capability */
13773 vty_out(vty, " Hostname Capability:");
13774
13775 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13776 vty_out(vty,
13777 " advertised (name: %s,domain name: %s)",
13778 bgp->peer_self->hostname
13779 ? bgp->peer_self->hostname
13780 : "n/a",
13781 bgp->peer_self->domainname
13782 ? bgp->peer_self->domainname
13783 : "n/a");
13784 } else {
13785 vty_out(vty, " not advertised");
13786 }
13787
13788 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13789 vty_out(vty,
13790 " received (name: %s,domain name: %s)",
13791 p->hostname ? p->hostname : "n/a",
13792 p->domainname ? p->domainname : "n/a");
13793 } else {
13794 vty_out(vty, " not received");
13795 }
13796
13797 vty_out(vty, "\n");
13798
13799 /* Graceful Restart */
13800 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13801 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13802 vty_out(vty,
13803 " Graceful Restart Capability:");
13804 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13805 vty_out(vty, " advertised");
13806 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13807 vty_out(vty, " %sreceived",
13808 CHECK_FLAG(p->cap,
13809 PEER_CAP_RESTART_ADV)
13810 ? "and "
13811 : "");
13812 vty_out(vty, "\n");
13813
13814 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13815 int restart_af_count = 0;
13816
13817 vty_out(vty,
13818 " Remote Restart timer is %d seconds\n",
13819 p->v_gr_restart);
13820 vty_out(vty,
13821 " Address families by peer:\n ");
13822
13823 FOREACH_AFI_SAFI (afi, safi)
13824 if (CHECK_FLAG(
13825 p->af_cap[afi]
13826 [safi],
13827 PEER_CAP_RESTART_AF_RCV)) {
13828 vty_out(vty, "%s%s(%s)",
13829 restart_af_count
13830 ? ", "
13831 : "",
13832 get_afi_safi_str(
13833 afi,
13834 safi,
13835 false),
13836 CHECK_FLAG(
13837 p->af_cap
13838 [afi]
13839 [safi],
13840 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13841 ? "preserved"
13842 : "not preserved");
13843 restart_af_count++;
13844 }
13845 if (!restart_af_count)
13846 vty_out(vty, "none");
13847 vty_out(vty, "\n");
13848 }
13849 } /* Graceful Restart */
13850 }
13851 }
13852
13853 /* graceful restart information */
13854 json_object *json_grace = NULL;
13855 json_object *json_grace_send = NULL;
13856 json_object *json_grace_recv = NULL;
13857 int eor_send_af_count = 0;
13858 int eor_receive_af_count = 0;
13859
13860 if (use_json) {
13861 json_grace = json_object_new_object();
13862 json_grace_send = json_object_new_object();
13863 json_grace_recv = json_object_new_object();
13864
13865 if ((peer_established(p)) &&
13866 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13867 FOREACH_AFI_SAFI (afi, safi) {
13868 if (CHECK_FLAG(p->af_sflags[afi][safi],
13869 PEER_STATUS_EOR_SEND)) {
13870 json_object_boolean_true_add(
13871 json_grace_send,
13872 get_afi_safi_str(afi, safi,
13873 true));
13874 eor_send_af_count++;
13875 }
13876 }
13877 FOREACH_AFI_SAFI (afi, safi) {
13878 if (CHECK_FLAG(p->af_sflags[afi][safi],
13879 PEER_STATUS_EOR_RECEIVED)) {
13880 json_object_boolean_true_add(
13881 json_grace_recv,
13882 get_afi_safi_str(afi, safi,
13883 true));
13884 eor_receive_af_count++;
13885 }
13886 }
13887 }
13888 json_object_object_add(json_grace, "endOfRibSend",
13889 json_grace_send);
13890 json_object_object_add(json_grace, "endOfRibRecv",
13891 json_grace_recv);
13892
13893
13894 if (p->t_gr_restart)
13895 json_object_int_add(
13896 json_grace, "gracefulRestartTimerMsecs",
13897 thread_timer_remain_second(p->t_gr_restart) *
13898 1000);
13899
13900 if (p->t_gr_stale)
13901 json_object_int_add(
13902 json_grace, "gracefulStalepathTimerMsecs",
13903 thread_timer_remain_second(p->t_gr_stale) *
13904 1000);
13905 /* more gr info in new format */
13906 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13907 json_object_object_add(json_neigh, "gracefulRestartInfo",
13908 json_grace);
13909 } else {
13910 vty_out(vty, " Graceful restart information:\n");
13911 if ((peer_established(p)) &&
13912 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13913
13914 vty_out(vty, " End-of-RIB send: ");
13915 FOREACH_AFI_SAFI (afi, safi) {
13916 if (CHECK_FLAG(p->af_sflags[afi][safi],
13917 PEER_STATUS_EOR_SEND)) {
13918 vty_out(vty, "%s%s",
13919 eor_send_af_count ? ", " : "",
13920 get_afi_safi_str(afi, safi,
13921 false));
13922 eor_send_af_count++;
13923 }
13924 }
13925 vty_out(vty, "\n");
13926 vty_out(vty, " End-of-RIB received: ");
13927 FOREACH_AFI_SAFI (afi, safi) {
13928 if (CHECK_FLAG(p->af_sflags[afi][safi],
13929 PEER_STATUS_EOR_RECEIVED)) {
13930 vty_out(vty, "%s%s",
13931 eor_receive_af_count ? ", "
13932 : "",
13933 get_afi_safi_str(afi, safi,
13934 false));
13935 eor_receive_af_count++;
13936 }
13937 }
13938 vty_out(vty, "\n");
13939 }
13940
13941 if (p->t_gr_restart)
13942 vty_out(vty,
13943 " The remaining time of restart timer is %ld\n",
13944 thread_timer_remain_second(p->t_gr_restart));
13945
13946 if (p->t_gr_stale)
13947 vty_out(vty,
13948 " The remaining time of stalepath timer is %ld\n",
13949 thread_timer_remain_second(p->t_gr_stale));
13950
13951 /* more gr info in new format */
13952 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13953 }
13954
13955 if (use_json) {
13956 json_object *json_stat = NULL;
13957 json_stat = json_object_new_object();
13958 /* Packet counts. */
13959
13960 atomic_size_t outq_count, inq_count;
13961 outq_count = atomic_load_explicit(&p->obuf->count,
13962 memory_order_relaxed);
13963 inq_count = atomic_load_explicit(&p->ibuf->count,
13964 memory_order_relaxed);
13965
13966 json_object_int_add(json_stat, "depthInq",
13967 (unsigned long)inq_count);
13968 json_object_int_add(json_stat, "depthOutq",
13969 (unsigned long)outq_count);
13970 json_object_int_add(json_stat, "opensSent",
13971 atomic_load_explicit(&p->open_out,
13972 memory_order_relaxed));
13973 json_object_int_add(json_stat, "opensRecv",
13974 atomic_load_explicit(&p->open_in,
13975 memory_order_relaxed));
13976 json_object_int_add(json_stat, "notificationsSent",
13977 atomic_load_explicit(&p->notify_out,
13978 memory_order_relaxed));
13979 json_object_int_add(json_stat, "notificationsRecv",
13980 atomic_load_explicit(&p->notify_in,
13981 memory_order_relaxed));
13982 json_object_int_add(json_stat, "updatesSent",
13983 atomic_load_explicit(&p->update_out,
13984 memory_order_relaxed));
13985 json_object_int_add(json_stat, "updatesRecv",
13986 atomic_load_explicit(&p->update_in,
13987 memory_order_relaxed));
13988 json_object_int_add(json_stat, "keepalivesSent",
13989 atomic_load_explicit(&p->keepalive_out,
13990 memory_order_relaxed));
13991 json_object_int_add(json_stat, "keepalivesRecv",
13992 atomic_load_explicit(&p->keepalive_in,
13993 memory_order_relaxed));
13994 json_object_int_add(json_stat, "routeRefreshSent",
13995 atomic_load_explicit(&p->refresh_out,
13996 memory_order_relaxed));
13997 json_object_int_add(json_stat, "routeRefreshRecv",
13998 atomic_load_explicit(&p->refresh_in,
13999 memory_order_relaxed));
14000 json_object_int_add(json_stat, "capabilitySent",
14001 atomic_load_explicit(&p->dynamic_cap_out,
14002 memory_order_relaxed));
14003 json_object_int_add(json_stat, "capabilityRecv",
14004 atomic_load_explicit(&p->dynamic_cap_in,
14005 memory_order_relaxed));
14006 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14007 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14008 json_object_object_add(json_neigh, "messageStats", json_stat);
14009 } else {
14010 atomic_size_t outq_count, inq_count, open_out, open_in,
14011 notify_out, notify_in, update_out, update_in,
14012 keepalive_out, keepalive_in, refresh_out, refresh_in,
14013 dynamic_cap_out, dynamic_cap_in;
14014 outq_count = atomic_load_explicit(&p->obuf->count,
14015 memory_order_relaxed);
14016 inq_count = atomic_load_explicit(&p->ibuf->count,
14017 memory_order_relaxed);
14018 open_out = atomic_load_explicit(&p->open_out,
14019 memory_order_relaxed);
14020 open_in =
14021 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14022 notify_out = atomic_load_explicit(&p->notify_out,
14023 memory_order_relaxed);
14024 notify_in = atomic_load_explicit(&p->notify_in,
14025 memory_order_relaxed);
14026 update_out = atomic_load_explicit(&p->update_out,
14027 memory_order_relaxed);
14028 update_in = atomic_load_explicit(&p->update_in,
14029 memory_order_relaxed);
14030 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14031 memory_order_relaxed);
14032 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14033 memory_order_relaxed);
14034 refresh_out = atomic_load_explicit(&p->refresh_out,
14035 memory_order_relaxed);
14036 refresh_in = atomic_load_explicit(&p->refresh_in,
14037 memory_order_relaxed);
14038 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14039 memory_order_relaxed);
14040 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14041 memory_order_relaxed);
14042
14043 /* Packet counts. */
14044 vty_out(vty, " Message statistics:\n");
14045 vty_out(vty, " Inq depth is %zu\n", inq_count);
14046 vty_out(vty, " Outq depth is %zu\n", outq_count);
14047 vty_out(vty, " Sent Rcvd\n");
14048 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14049 open_in);
14050 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14051 notify_in);
14052 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14053 update_in);
14054 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14055 keepalive_in);
14056 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14057 refresh_in);
14058 vty_out(vty, " Capability: %10zu %10zu\n",
14059 dynamic_cap_out, dynamic_cap_in);
14060 vty_out(vty, " Total: %10u %10u\n",
14061 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14062 }
14063
14064 if (use_json) {
14065 /* advertisement-interval */
14066 json_object_int_add(json_neigh,
14067 "minBtwnAdvertisementRunsTimerMsecs",
14068 p->v_routeadv * 1000);
14069
14070 /* Update-source. */
14071 if (p->update_if || p->update_source) {
14072 if (p->update_if)
14073 json_object_string_add(json_neigh,
14074 "updateSource",
14075 p->update_if);
14076 else if (p->update_source)
14077 json_object_string_addf(json_neigh,
14078 "updateSource", "%pSU",
14079 p->update_source);
14080 }
14081 } else {
14082 /* advertisement-interval */
14083 vty_out(vty,
14084 " Minimum time between advertisement runs is %d seconds\n",
14085 p->v_routeadv);
14086
14087 /* Update-source. */
14088 if (p->update_if || p->update_source) {
14089 vty_out(vty, " Update source is ");
14090 if (p->update_if)
14091 vty_out(vty, "%s", p->update_if);
14092 else if (p->update_source)
14093 vty_out(vty, "%pSU", p->update_source);
14094 vty_out(vty, "\n");
14095 }
14096
14097 vty_out(vty, "\n");
14098 }
14099
14100 /* Address Family Information */
14101 json_object *json_hold = NULL;
14102
14103 if (use_json)
14104 json_hold = json_object_new_object();
14105
14106 FOREACH_AFI_SAFI (afi, safi)
14107 if (p->afc[afi][safi])
14108 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14109 json_hold);
14110
14111 if (use_json) {
14112 json_object_object_add(json_neigh, "addressFamilyInfo",
14113 json_hold);
14114 json_object_int_add(json_neigh, "connectionsEstablished",
14115 p->established);
14116 json_object_int_add(json_neigh, "connectionsDropped",
14117 p->dropped);
14118 } else
14119 vty_out(vty, " Connections established %d; dropped %d\n",
14120 p->established, p->dropped);
14121
14122 if (!p->last_reset) {
14123 if (use_json)
14124 json_object_string_add(json_neigh, "lastReset",
14125 "never");
14126 else
14127 vty_out(vty, " Last reset never\n");
14128 } else {
14129 if (use_json) {
14130 time_t uptime;
14131 struct tm tm;
14132
14133 uptime = monotime(NULL);
14134 uptime -= p->resettime;
14135 gmtime_r(&uptime, &tm);
14136
14137 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14138 (tm.tm_sec * 1000)
14139 + (tm.tm_min * 60000)
14140 + (tm.tm_hour * 3600000));
14141 bgp_show_peer_reset(NULL, p, json_neigh, true);
14142 } else {
14143 vty_out(vty, " Last reset %s, ",
14144 peer_uptime(p->resettime, timebuf,
14145 BGP_UPTIME_LEN, 0, NULL));
14146
14147 bgp_show_peer_reset(vty, p, NULL, false);
14148 if (p->last_reset_cause_size) {
14149 msg = p->last_reset_cause;
14150 vty_out(vty,
14151 " Message received that caused BGP to send a NOTIFICATION:\n ");
14152 for (i = 1; i <= p->last_reset_cause_size;
14153 i++) {
14154 vty_out(vty, "%02X", *msg++);
14155
14156 if (i != p->last_reset_cause_size) {
14157 if (i % 16 == 0) {
14158 vty_out(vty, "\n ");
14159 } else if (i % 4 == 0) {
14160 vty_out(vty, " ");
14161 }
14162 }
14163 }
14164 vty_out(vty, "\n");
14165 }
14166 }
14167 }
14168
14169 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14170 if (use_json)
14171 json_object_boolean_true_add(json_neigh,
14172 "prefixesConfigExceedMax");
14173 else
14174 vty_out(vty,
14175 " Peer had exceeded the max. no. of prefixes configured.\n");
14176
14177 if (p->t_pmax_restart) {
14178 if (use_json) {
14179 json_object_boolean_true_add(
14180 json_neigh, "reducePrefixNumFrom");
14181 json_object_int_add(json_neigh,
14182 "restartInTimerMsec",
14183 thread_timer_remain_second(
14184 p->t_pmax_restart)
14185 * 1000);
14186 } else
14187 vty_out(vty,
14188 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14189 p->host, thread_timer_remain_second(
14190 p->t_pmax_restart));
14191 } else {
14192 if (use_json)
14193 json_object_boolean_true_add(
14194 json_neigh,
14195 "reducePrefixNumAndClearIpBgp");
14196 else
14197 vty_out(vty,
14198 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14199 p->host);
14200 }
14201 }
14202
14203 /* EBGP Multihop and GTSM */
14204 if (p->sort != BGP_PEER_IBGP) {
14205 if (use_json) {
14206 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14207 json_object_int_add(json_neigh,
14208 "externalBgpNbrMaxHopsAway",
14209 p->gtsm_hops);
14210 else
14211 json_object_int_add(json_neigh,
14212 "externalBgpNbrMaxHopsAway",
14213 p->ttl);
14214 } else {
14215 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14216 vty_out(vty,
14217 " External BGP neighbor may be up to %d hops away.\n",
14218 p->gtsm_hops);
14219 else
14220 vty_out(vty,
14221 " External BGP neighbor may be up to %d hops away.\n",
14222 p->ttl);
14223 }
14224 } else {
14225 if (use_json) {
14226 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14227 json_object_int_add(json_neigh,
14228 "internalBgpNbrMaxHopsAway",
14229 p->gtsm_hops);
14230 else
14231 json_object_int_add(json_neigh,
14232 "internalBgpNbrMaxHopsAway",
14233 p->ttl);
14234 } else {
14235 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14236 vty_out(vty,
14237 " Internal BGP neighbor may be up to %d hops away.\n",
14238 p->gtsm_hops);
14239 else
14240 vty_out(vty,
14241 " Internal BGP neighbor may be up to %d hops away.\n",
14242 p->ttl);
14243 }
14244 }
14245
14246 /* Local address. */
14247 if (p->su_local) {
14248 if (use_json) {
14249 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14250 p->su_local);
14251 json_object_int_add(json_neigh, "portLocal",
14252 ntohs(p->su_local->sin.sin_port));
14253 } else
14254 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14255 p->su_local, ntohs(p->su_local->sin.sin_port));
14256 } else {
14257 if (use_json) {
14258 json_object_string_add(json_neigh, "hostLocal",
14259 "Unknown");
14260 json_object_int_add(json_neigh, "portLocal", -1);
14261 }
14262 }
14263
14264 /* Remote address. */
14265 if (p->su_remote) {
14266 if (use_json) {
14267 json_object_string_addf(json_neigh, "hostForeign",
14268 "%pSU", p->su_remote);
14269 json_object_int_add(json_neigh, "portForeign",
14270 ntohs(p->su_remote->sin.sin_port));
14271 } else
14272 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14273 p->su_remote,
14274 ntohs(p->su_remote->sin.sin_port));
14275 } else {
14276 if (use_json) {
14277 json_object_string_add(json_neigh, "hostForeign",
14278 "Unknown");
14279 json_object_int_add(json_neigh, "portForeign", -1);
14280 }
14281 }
14282
14283 /* Nexthop display. */
14284 if (p->su_local) {
14285 if (use_json) {
14286 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14287 &p->nexthop.v4);
14288 json_object_string_addf(json_neigh, "nexthopGlobal",
14289 "%pI6", &p->nexthop.v6_global);
14290 json_object_string_addf(json_neigh, "nexthopLocal",
14291 "%pI6", &p->nexthop.v6_local);
14292 if (p->shared_network)
14293 json_object_string_add(json_neigh,
14294 "bgpConnection",
14295 "sharedNetwork");
14296 else
14297 json_object_string_add(json_neigh,
14298 "bgpConnection",
14299 "nonSharedNetwork");
14300 } else {
14301 vty_out(vty, "Nexthop: %s\n",
14302 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14303 sizeof(buf1)));
14304 vty_out(vty, "Nexthop global: %s\n",
14305 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14306 sizeof(buf1)));
14307 vty_out(vty, "Nexthop local: %s\n",
14308 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14309 sizeof(buf1)));
14310 vty_out(vty, "BGP connection: %s\n",
14311 p->shared_network ? "shared network"
14312 : "non shared network");
14313 }
14314 }
14315
14316 /* Timer information. */
14317 if (use_json) {
14318 json_object_int_add(json_neigh, "connectRetryTimer",
14319 p->v_connect);
14320 if (peer_established(p) && p->rtt)
14321 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14322 p->rtt);
14323 if (p->t_start)
14324 json_object_int_add(
14325 json_neigh, "nextStartTimerDueInMsecs",
14326 thread_timer_remain_second(p->t_start) * 1000);
14327 if (p->t_connect)
14328 json_object_int_add(
14329 json_neigh, "nextConnectTimerDueInMsecs",
14330 thread_timer_remain_second(p->t_connect)
14331 * 1000);
14332 if (p->t_routeadv) {
14333 json_object_int_add(json_neigh, "mraiInterval",
14334 p->v_routeadv);
14335 json_object_int_add(
14336 json_neigh, "mraiTimerExpireInMsecs",
14337 thread_timer_remain_second(p->t_routeadv)
14338 * 1000);
14339 }
14340 if (p->password)
14341 json_object_int_add(json_neigh, "authenticationEnabled",
14342 1);
14343
14344 if (p->t_read)
14345 json_object_string_add(json_neigh, "readThread", "on");
14346 else
14347 json_object_string_add(json_neigh, "readThread", "off");
14348
14349 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14350 json_object_string_add(json_neigh, "writeThread", "on");
14351 else
14352 json_object_string_add(json_neigh, "writeThread",
14353 "off");
14354 } else {
14355 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14356 p->v_connect);
14357 if (peer_established(p) && p->rtt)
14358 vty_out(vty, "Estimated round trip time: %d ms\n",
14359 p->rtt);
14360 if (p->t_start)
14361 vty_out(vty, "Next start timer due in %ld seconds\n",
14362 thread_timer_remain_second(p->t_start));
14363 if (p->t_connect)
14364 vty_out(vty, "Next connect timer due in %ld seconds\n",
14365 thread_timer_remain_second(p->t_connect));
14366 if (p->t_routeadv)
14367 vty_out(vty,
14368 "MRAI (interval %u) timer expires in %ld seconds\n",
14369 p->v_routeadv,
14370 thread_timer_remain_second(p->t_routeadv));
14371 if (p->password)
14372 vty_out(vty, "Peer Authentication Enabled\n");
14373
14374 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14375 p->t_read ? "on" : "off",
14376 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14377 ? "on"
14378 : "off", p->fd);
14379 }
14380
14381 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14382 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14383 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14384
14385 if (!use_json)
14386 vty_out(vty, "\n");
14387
14388 /* BFD information. */
14389 if (p->bfd_config)
14390 bgp_bfd_show_info(vty, p, json_neigh);
14391
14392 if (use_json) {
14393 if (p->conf_if) /* Configured interface name. */
14394 json_object_object_add(json, p->conf_if, json_neigh);
14395 else /* Configured IP address. */
14396 json_object_object_add(json, p->host, json_neigh);
14397 }
14398 }
14399
14400 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14401 enum show_type type,
14402 union sockunion *su,
14403 const char *conf_if, afi_t afi,
14404 bool use_json)
14405 {
14406 struct listnode *node, *nnode;
14407 struct peer *peer;
14408 int find = 0;
14409 safi_t safi = SAFI_UNICAST;
14410 json_object *json = NULL;
14411 json_object *json_neighbor = NULL;
14412
14413 if (use_json) {
14414 json = json_object_new_object();
14415 json_neighbor = json_object_new_object();
14416 }
14417
14418 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14419
14420 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14421 continue;
14422
14423 if ((peer->afc[afi][safi]) == 0)
14424 continue;
14425
14426 if (type == show_all) {
14427 bgp_show_peer_gr_status(vty, peer, use_json,
14428 json_neighbor);
14429
14430 if (use_json) {
14431 json_object_object_add(json, peer->host,
14432 json_neighbor);
14433 json_neighbor = NULL;
14434 }
14435
14436 } else if (type == show_peer) {
14437 if (conf_if) {
14438 if ((peer->conf_if
14439 && !strcmp(peer->conf_if, conf_if))
14440 || (peer->hostname
14441 && !strcmp(peer->hostname, conf_if))) {
14442 find = 1;
14443 bgp_show_peer_gr_status(vty, peer,
14444 use_json,
14445 json_neighbor);
14446 }
14447 } else {
14448 if (sockunion_same(&peer->su, su)) {
14449 find = 1;
14450 bgp_show_peer_gr_status(vty, peer,
14451 use_json,
14452 json_neighbor);
14453 }
14454 }
14455 if (use_json && find)
14456 json_object_object_add(json, peer->host,
14457 json_neighbor);
14458 }
14459
14460 if (find) {
14461 json_neighbor = NULL;
14462 break;
14463 }
14464 }
14465
14466 if (type == show_peer && !find) {
14467 if (use_json)
14468 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14469 else
14470 vty_out(vty, "%% No such neighbor\n");
14471 }
14472 if (use_json) {
14473 if (json_neighbor)
14474 json_object_free(json_neighbor);
14475 vty_json(vty, json);
14476 } else {
14477 vty_out(vty, "\n");
14478 }
14479
14480 return CMD_SUCCESS;
14481 }
14482
14483 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14484 enum show_type type, union sockunion *su,
14485 const char *conf_if, bool use_json,
14486 json_object *json)
14487 {
14488 struct listnode *node, *nnode;
14489 struct peer *peer;
14490 int find = 0;
14491 bool nbr_output = false;
14492 afi_t afi = AFI_MAX;
14493 safi_t safi = SAFI_MAX;
14494
14495 if (type == show_ipv4_peer || type == show_ipv4_all) {
14496 afi = AFI_IP;
14497 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14498 afi = AFI_IP6;
14499 }
14500
14501 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14502 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14503 continue;
14504
14505 switch (type) {
14506 case show_all:
14507 bgp_show_peer(vty, peer, use_json, json);
14508 nbr_output = true;
14509 break;
14510 case show_peer:
14511 if (conf_if) {
14512 if ((peer->conf_if
14513 && !strcmp(peer->conf_if, conf_if))
14514 || (peer->hostname
14515 && !strcmp(peer->hostname, conf_if))) {
14516 find = 1;
14517 bgp_show_peer(vty, peer, use_json,
14518 json);
14519 }
14520 } else {
14521 if (sockunion_same(&peer->su, su)) {
14522 find = 1;
14523 bgp_show_peer(vty, peer, use_json,
14524 json);
14525 }
14526 }
14527 break;
14528 case show_ipv4_peer:
14529 case show_ipv6_peer:
14530 FOREACH_SAFI (safi) {
14531 if (peer->afc[afi][safi]) {
14532 if (conf_if) {
14533 if ((peer->conf_if
14534 && !strcmp(peer->conf_if, conf_if))
14535 || (peer->hostname
14536 && !strcmp(peer->hostname, conf_if))) {
14537 find = 1;
14538 bgp_show_peer(vty, peer, use_json,
14539 json);
14540 break;
14541 }
14542 } else {
14543 if (sockunion_same(&peer->su, su)) {
14544 find = 1;
14545 bgp_show_peer(vty, peer, use_json,
14546 json);
14547 break;
14548 }
14549 }
14550 }
14551 }
14552 break;
14553 case show_ipv4_all:
14554 case show_ipv6_all:
14555 FOREACH_SAFI (safi) {
14556 if (peer->afc[afi][safi]) {
14557 bgp_show_peer(vty, peer, use_json, json);
14558 nbr_output = true;
14559 break;
14560 }
14561 }
14562 break;
14563 }
14564 }
14565
14566 if ((type == show_peer || type == show_ipv4_peer ||
14567 type == show_ipv6_peer) && !find) {
14568 if (use_json)
14569 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14570 else
14571 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14572 }
14573
14574 if (type != show_peer && type != show_ipv4_peer &&
14575 type != show_ipv6_peer && !nbr_output && !use_json)
14576 vty_out(vty, "%% No BGP neighbors found\n");
14577
14578 if (use_json) {
14579 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14580 json, JSON_C_TO_STRING_PRETTY));
14581 } else {
14582 vty_out(vty, "\n");
14583 }
14584
14585 return CMD_SUCCESS;
14586 }
14587
14588 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14589 enum show_type type,
14590 const char *ip_str,
14591 afi_t afi, bool use_json)
14592 {
14593
14594 int ret;
14595 struct bgp *bgp;
14596 union sockunion su;
14597
14598 bgp = bgp_get_default();
14599
14600 if (!bgp)
14601 return;
14602
14603 if (!use_json)
14604 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14605 NULL);
14606
14607 if (ip_str) {
14608 ret = str2sockunion(ip_str, &su);
14609 if (ret < 0)
14610 bgp_show_neighbor_graceful_restart(
14611 vty, bgp, type, NULL, ip_str, afi, use_json);
14612 else
14613 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14614 NULL, afi, use_json);
14615 } else
14616 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14617 afi, use_json);
14618 }
14619
14620 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14621 enum show_type type,
14622 const char *ip_str,
14623 bool use_json)
14624 {
14625 struct listnode *node, *nnode;
14626 struct bgp *bgp;
14627 union sockunion su;
14628 json_object *json = NULL;
14629 int ret, is_first = 1;
14630 bool nbr_output = false;
14631
14632 if (use_json)
14633 vty_out(vty, "{\n");
14634
14635 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14636 nbr_output = true;
14637 if (use_json) {
14638 if (!(json = json_object_new_object())) {
14639 flog_err(
14640 EC_BGP_JSON_MEM_ERROR,
14641 "Unable to allocate memory for JSON object");
14642 vty_out(vty,
14643 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14644 return;
14645 }
14646
14647 json_object_int_add(json, "vrfId",
14648 (bgp->vrf_id == VRF_UNKNOWN)
14649 ? -1
14650 : (int64_t)bgp->vrf_id);
14651 json_object_string_add(
14652 json, "vrfName",
14653 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14654 ? VRF_DEFAULT_NAME
14655 : bgp->name);
14656
14657 if (!is_first)
14658 vty_out(vty, ",\n");
14659 else
14660 is_first = 0;
14661
14662 vty_out(vty, "\"%s\":",
14663 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14664 ? VRF_DEFAULT_NAME
14665 : bgp->name);
14666 } else {
14667 vty_out(vty, "\nInstance %s:\n",
14668 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14669 ? VRF_DEFAULT_NAME
14670 : bgp->name);
14671 }
14672
14673 if (type == show_peer || type == show_ipv4_peer ||
14674 type == show_ipv6_peer) {
14675 ret = str2sockunion(ip_str, &su);
14676 if (ret < 0)
14677 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14678 use_json, json);
14679 else
14680 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14681 use_json, json);
14682 } else {
14683 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14684 use_json, json);
14685 }
14686 json_object_free(json);
14687 json = NULL;
14688 }
14689
14690 if (use_json)
14691 vty_out(vty, "}\n");
14692 else if (!nbr_output)
14693 vty_out(vty, "%% BGP instance not found\n");
14694 }
14695
14696 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14697 enum show_type type, const char *ip_str,
14698 bool use_json)
14699 {
14700 int ret;
14701 struct bgp *bgp;
14702 union sockunion su;
14703 json_object *json = NULL;
14704
14705 if (name) {
14706 if (strmatch(name, "all")) {
14707 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14708 use_json);
14709 return CMD_SUCCESS;
14710 } else {
14711 bgp = bgp_lookup_by_name(name);
14712 if (!bgp) {
14713 if (use_json) {
14714 json = json_object_new_object();
14715 vty_json(vty, json);
14716 } else
14717 vty_out(vty,
14718 "%% BGP instance not found\n");
14719
14720 return CMD_WARNING;
14721 }
14722 }
14723 } else {
14724 bgp = bgp_get_default();
14725 }
14726
14727 if (bgp) {
14728 json = json_object_new_object();
14729 if (ip_str) {
14730 ret = str2sockunion(ip_str, &su);
14731 if (ret < 0)
14732 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14733 use_json, json);
14734 else
14735 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14736 use_json, json);
14737 } else {
14738 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14739 json);
14740 }
14741 json_object_free(json);
14742 } else {
14743 if (use_json)
14744 vty_out(vty, "{}\n");
14745 else
14746 vty_out(vty, "%% BGP instance not found\n");
14747 }
14748
14749 return CMD_SUCCESS;
14750 }
14751
14752
14753
14754 /* "show [ip] bgp neighbors graceful-restart" commands. */
14755 DEFUN (show_ip_bgp_neighbors_graceful_restart,
14756 show_ip_bgp_neighbors_graceful_restart_cmd,
14757 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14758 SHOW_STR
14759 BGP_STR
14760 IP_STR
14761 IPV6_STR
14762 NEIGHBOR_STR
14763 "Neighbor to display information about\n"
14764 "Neighbor to display information about\n"
14765 "Neighbor on BGP configured interface\n"
14766 GR_SHOW
14767 JSON_STR)
14768 {
14769 char *sh_arg = NULL;
14770 enum show_type sh_type;
14771 int idx = 0;
14772 afi_t afi = AFI_MAX;
14773 bool uj = use_json(argc, argv);
14774
14775 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14776 afi = AFI_MAX;
14777
14778 idx++;
14779
14780 if (argv_find(argv, argc, "A.B.C.D", &idx)
14781 || argv_find(argv, argc, "X:X::X:X", &idx)
14782 || argv_find(argv, argc, "WORD", &idx)) {
14783 sh_type = show_peer;
14784 sh_arg = argv[idx]->arg;
14785 } else
14786 sh_type = show_all;
14787
14788 if (!argv_find(argv, argc, "graceful-restart", &idx))
14789 return CMD_SUCCESS;
14790
14791
14792 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14793 afi, uj);
14794 }
14795
14796 /* "show [ip] bgp neighbors" commands. */
14797 DEFUN (show_ip_bgp_neighbors,
14798 show_ip_bgp_neighbors_cmd,
14799 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14800 SHOW_STR
14801 IP_STR
14802 BGP_STR
14803 BGP_INSTANCE_HELP_STR
14804 BGP_AF_STR
14805 BGP_AF_STR
14806 "Detailed information on TCP and BGP neighbor connections\n"
14807 "Neighbor to display information about\n"
14808 "Neighbor to display information about\n"
14809 "Neighbor on BGP configured interface\n"
14810 JSON_STR)
14811 {
14812 char *vrf = NULL;
14813 char *sh_arg = NULL;
14814 enum show_type sh_type;
14815 afi_t afi = AFI_MAX;
14816
14817 bool uj = use_json(argc, argv);
14818
14819 int idx = 0;
14820
14821 /* [<vrf> VIEWVRFNAME] */
14822 if (argv_find(argv, argc, "vrf", &idx)) {
14823 vrf = argv[idx + 1]->arg;
14824 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14825 vrf = NULL;
14826 } else if (argv_find(argv, argc, "view", &idx))
14827 /* [<view> VIEWVRFNAME] */
14828 vrf = argv[idx + 1]->arg;
14829
14830 idx++;
14831
14832 if (argv_find(argv, argc, "ipv4", &idx)) {
14833 sh_type = show_ipv4_all;
14834 afi = AFI_IP;
14835 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14836 sh_type = show_ipv6_all;
14837 afi = AFI_IP6;
14838 } else {
14839 sh_type = show_all;
14840 }
14841
14842 if (argv_find(argv, argc, "A.B.C.D", &idx)
14843 || argv_find(argv, argc, "X:X::X:X", &idx)
14844 || argv_find(argv, argc, "WORD", &idx)) {
14845 sh_type = show_peer;
14846 sh_arg = argv[idx]->arg;
14847 }
14848
14849 if (sh_type == show_peer && afi == AFI_IP) {
14850 sh_type = show_ipv4_peer;
14851 } else if (sh_type == show_peer && afi == AFI_IP6) {
14852 sh_type = show_ipv6_peer;
14853 }
14854
14855 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14856 }
14857
14858 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14859 paths' and `show ip mbgp paths'. Those functions results are the
14860 same.*/
14861 DEFUN (show_ip_bgp_paths,
14862 show_ip_bgp_paths_cmd,
14863 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14864 SHOW_STR
14865 IP_STR
14866 BGP_STR
14867 BGP_SAFI_HELP_STR
14868 "Path information\n")
14869 {
14870 vty_out(vty, "Address Refcnt Path\n");
14871 aspath_print_all_vty(vty);
14872 return CMD_SUCCESS;
14873 }
14874
14875 #include "hash.h"
14876
14877 static void community_show_all_iterator(struct hash_bucket *bucket,
14878 struct vty *vty)
14879 {
14880 struct community *com;
14881
14882 com = (struct community *)bucket->data;
14883 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14884 community_str(com, false, false));
14885 }
14886
14887 /* Show BGP's community internal data. */
14888 DEFUN (show_ip_bgp_community_info,
14889 show_ip_bgp_community_info_cmd,
14890 "show [ip] bgp community-info",
14891 SHOW_STR
14892 IP_STR
14893 BGP_STR
14894 "List all bgp community information\n")
14895 {
14896 vty_out(vty, "Address Refcnt Community\n");
14897
14898 hash_iterate(community_hash(),
14899 (void (*)(struct hash_bucket *,
14900 void *))community_show_all_iterator,
14901 vty);
14902
14903 return CMD_SUCCESS;
14904 }
14905
14906 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14907 struct vty *vty)
14908 {
14909 struct lcommunity *lcom;
14910
14911 lcom = (struct lcommunity *)bucket->data;
14912 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14913 lcommunity_str(lcom, false, false));
14914 }
14915
14916 /* Show BGP's community internal data. */
14917 DEFUN (show_ip_bgp_lcommunity_info,
14918 show_ip_bgp_lcommunity_info_cmd,
14919 "show ip bgp large-community-info",
14920 SHOW_STR
14921 IP_STR
14922 BGP_STR
14923 "List all bgp large-community information\n")
14924 {
14925 vty_out(vty, "Address Refcnt Large-community\n");
14926
14927 hash_iterate(lcommunity_hash(),
14928 (void (*)(struct hash_bucket *,
14929 void *))lcommunity_show_all_iterator,
14930 vty);
14931
14932 return CMD_SUCCESS;
14933 }
14934 /* Graceful Restart */
14935
14936 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14937 struct bgp *bgp,
14938 bool use_json,
14939 json_object *json)
14940 {
14941
14942
14943 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14944
14945 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14946
14947 switch (bgp_global_gr_mode) {
14948
14949 case GLOBAL_HELPER:
14950 vty_out(vty, "Global BGP GR Mode : Helper\n");
14951 break;
14952
14953 case GLOBAL_GR:
14954 vty_out(vty, "Global BGP GR Mode : Restart\n");
14955 break;
14956
14957 case GLOBAL_DISABLE:
14958 vty_out(vty, "Global BGP GR Mode : Disable\n");
14959 break;
14960
14961 case GLOBAL_INVALID:
14962 vty_out(vty,
14963 "Global BGP GR Mode Invalid\n");
14964 break;
14965 }
14966 vty_out(vty, "\n");
14967 }
14968
14969 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14970 enum show_type type,
14971 const char *ip_str,
14972 afi_t afi, bool use_json)
14973 {
14974 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14975 afi = AFI_IP;
14976
14977 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14978
14979 bgp_show_neighbor_graceful_restart_vty(
14980 vty, type, ip_str, afi, use_json);
14981 afi++;
14982 }
14983 } else if (afi != AFI_MAX) {
14984 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14985 use_json);
14986 } else {
14987 return CMD_ERR_INCOMPLETE;
14988 }
14989
14990 return CMD_SUCCESS;
14991 }
14992 /* Graceful Restart */
14993
14994 DEFUN (show_ip_bgp_attr_info,
14995 show_ip_bgp_attr_info_cmd,
14996 "show [ip] bgp attribute-info",
14997 SHOW_STR
14998 IP_STR
14999 BGP_STR
15000 "List all bgp attribute information\n")
15001 {
15002 attr_show_all(vty);
15003 return CMD_SUCCESS;
15004 }
15005
15006 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15007 afi_t afi, safi_t safi,
15008 bool use_json, json_object *json)
15009 {
15010 struct bgp *bgp;
15011 struct listnode *node;
15012 char *vname;
15013 char *ecom_str;
15014 enum vpn_policy_direction dir;
15015
15016 if (json) {
15017 json_object *json_import_vrfs = NULL;
15018 json_object *json_export_vrfs = NULL;
15019
15020 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15021
15022 if (!bgp) {
15023 vty_json(vty, json);
15024
15025 return CMD_WARNING;
15026 }
15027
15028 /* Provide context for the block */
15029 json_object_string_add(json, "vrf", name ? name : "default");
15030 json_object_string_add(json, "afiSafi",
15031 get_afi_safi_str(afi, safi, true));
15032
15033 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15034 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15035 json_object_string_add(json, "importFromVrfs", "none");
15036 json_object_string_add(json, "importRts", "none");
15037 } else {
15038 json_import_vrfs = json_object_new_array();
15039
15040 for (ALL_LIST_ELEMENTS_RO(
15041 bgp->vpn_policy[afi].import_vrf,
15042 node, vname))
15043 json_object_array_add(json_import_vrfs,
15044 json_object_new_string(vname));
15045
15046 json_object_object_add(json, "importFromVrfs",
15047 json_import_vrfs);
15048 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15049 if (bgp->vpn_policy[afi].rtlist[dir]) {
15050 ecom_str = ecommunity_ecom2str(
15051 bgp->vpn_policy[afi].rtlist[dir],
15052 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15053 json_object_string_add(json, "importRts",
15054 ecom_str);
15055 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15056 } else
15057 json_object_string_add(json, "importRts",
15058 "none");
15059 }
15060
15061 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15062 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15063 json_object_string_add(json, "exportToVrfs", "none");
15064 json_object_string_add(json, "routeDistinguisher",
15065 "none");
15066 json_object_string_add(json, "exportRts", "none");
15067 } else {
15068 json_export_vrfs = json_object_new_array();
15069
15070 for (ALL_LIST_ELEMENTS_RO(
15071 bgp->vpn_policy[afi].export_vrf,
15072 node, vname))
15073 json_object_array_add(json_export_vrfs,
15074 json_object_new_string(vname));
15075 json_object_object_add(json, "exportToVrfs",
15076 json_export_vrfs);
15077 json_object_string_addf(json, "routeDistinguisher",
15078 "%pRD",
15079 &bgp->vpn_policy[afi].tovpn_rd);
15080
15081 dir = BGP_VPN_POLICY_DIR_TOVPN;
15082 if (bgp->vpn_policy[afi].rtlist[dir]) {
15083 ecom_str = ecommunity_ecom2str(
15084 bgp->vpn_policy[afi].rtlist[dir],
15085 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15086 json_object_string_add(json, "exportRts",
15087 ecom_str);
15088 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15089 } else
15090 json_object_string_add(json, "exportRts",
15091 "none");
15092 }
15093
15094 if (use_json) {
15095 vty_json(vty, json);
15096 }
15097 } else {
15098 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15099
15100 if (!bgp) {
15101 vty_out(vty, "%% No such BGP instance exist\n");
15102 return CMD_WARNING;
15103 }
15104
15105 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15106 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15107 vty_out(vty,
15108 "This VRF is not importing %s routes from any other VRF\n",
15109 get_afi_safi_str(afi, safi, false));
15110 else {
15111 vty_out(vty,
15112 "This VRF is importing %s routes from the following VRFs:\n",
15113 get_afi_safi_str(afi, safi, false));
15114
15115 for (ALL_LIST_ELEMENTS_RO(
15116 bgp->vpn_policy[afi].import_vrf,
15117 node, vname))
15118 vty_out(vty, " %s\n", vname);
15119
15120 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15121 ecom_str = NULL;
15122 if (bgp->vpn_policy[afi].rtlist[dir]) {
15123 ecom_str = ecommunity_ecom2str(
15124 bgp->vpn_policy[afi].rtlist[dir],
15125 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15126 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15127
15128 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15129 } else
15130 vty_out(vty, "Import RT(s):\n");
15131 }
15132
15133 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15134 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15135 vty_out(vty,
15136 "This VRF is not exporting %s routes to any other VRF\n",
15137 get_afi_safi_str(afi, safi, false));
15138 else {
15139 vty_out(vty,
15140 "This VRF is exporting %s routes to the following VRFs:\n",
15141 get_afi_safi_str(afi, safi, false));
15142
15143 for (ALL_LIST_ELEMENTS_RO(
15144 bgp->vpn_policy[afi].export_vrf,
15145 node, vname))
15146 vty_out(vty, " %s\n", vname);
15147
15148 vty_out(vty, "RD: %pRD\n",
15149 &bgp->vpn_policy[afi].tovpn_rd);
15150
15151 dir = BGP_VPN_POLICY_DIR_TOVPN;
15152 if (bgp->vpn_policy[afi].rtlist[dir]) {
15153 ecom_str = ecommunity_ecom2str(
15154 bgp->vpn_policy[afi].rtlist[dir],
15155 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15156 vty_out(vty, "Export RT: %s\n", ecom_str);
15157 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15158 } else
15159 vty_out(vty, "Import RT(s):\n");
15160 }
15161 }
15162
15163 return CMD_SUCCESS;
15164 }
15165
15166 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15167 safi_t safi, bool use_json)
15168 {
15169 struct listnode *node, *nnode;
15170 struct bgp *bgp;
15171 char *vrf_name = NULL;
15172 json_object *json = NULL;
15173 json_object *json_vrf = NULL;
15174 json_object *json_vrfs = NULL;
15175
15176 if (use_json) {
15177 json = json_object_new_object();
15178 json_vrfs = json_object_new_object();
15179 }
15180
15181 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15182
15183 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15184 vrf_name = bgp->name;
15185
15186 if (use_json) {
15187 json_vrf = json_object_new_object();
15188 } else {
15189 vty_out(vty, "\nInstance %s:\n",
15190 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15191 ? VRF_DEFAULT_NAME : bgp->name);
15192 }
15193 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15194 if (use_json) {
15195 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15196 json_object_object_add(json_vrfs,
15197 VRF_DEFAULT_NAME, json_vrf);
15198 else
15199 json_object_object_add(json_vrfs, vrf_name,
15200 json_vrf);
15201 }
15202 }
15203
15204 if (use_json) {
15205 json_object_object_add(json, "vrfs", json_vrfs);
15206 vty_json(vty, json);
15207 }
15208
15209 return CMD_SUCCESS;
15210 }
15211
15212 /* "show [ip] bgp route-leak" command. */
15213 DEFUN (show_ip_bgp_route_leak,
15214 show_ip_bgp_route_leak_cmd,
15215 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15216 SHOW_STR
15217 IP_STR
15218 BGP_STR
15219 BGP_INSTANCE_HELP_STR
15220 BGP_AFI_HELP_STR
15221 BGP_SAFI_HELP_STR
15222 "Route leaking information\n"
15223 JSON_STR)
15224 {
15225 char *vrf = NULL;
15226 afi_t afi = AFI_MAX;
15227 safi_t safi = SAFI_MAX;
15228
15229 bool uj = use_json(argc, argv);
15230 int idx = 0;
15231 json_object *json = NULL;
15232
15233 /* show [ip] bgp */
15234 if (argv_find(argv, argc, "ip", &idx)) {
15235 afi = AFI_IP;
15236 safi = SAFI_UNICAST;
15237 }
15238 /* [vrf VIEWVRFNAME] */
15239 if (argv_find(argv, argc, "view", &idx)) {
15240 vty_out(vty,
15241 "%% This command is not applicable to BGP views\n");
15242 return CMD_WARNING;
15243 }
15244
15245 if (argv_find(argv, argc, "vrf", &idx)) {
15246 vrf = argv[idx + 1]->arg;
15247 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15248 vrf = NULL;
15249 }
15250 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15251 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15252 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15253
15254 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15255 vty_out(vty,
15256 "%% This command is applicable only for unicast ipv4|ipv6\n");
15257 return CMD_WARNING;
15258 }
15259
15260 if (vrf && strmatch(vrf, "all"))
15261 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15262
15263 if (uj)
15264 json = json_object_new_object();
15265
15266 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15267 }
15268
15269 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15270 safi_t safi)
15271 {
15272 struct listnode *node, *nnode;
15273 struct bgp *bgp;
15274
15275 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15276 vty_out(vty, "\nInstance %s:\n",
15277 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15278 ? VRF_DEFAULT_NAME
15279 : bgp->name);
15280 update_group_show(bgp, afi, safi, vty, 0);
15281 }
15282 }
15283
15284 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15285 int safi, uint64_t subgrp_id)
15286 {
15287 struct bgp *bgp;
15288
15289 if (name) {
15290 if (strmatch(name, "all")) {
15291 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15292 return CMD_SUCCESS;
15293 } else {
15294 bgp = bgp_lookup_by_name(name);
15295 }
15296 } else {
15297 bgp = bgp_get_default();
15298 }
15299
15300 if (bgp)
15301 update_group_show(bgp, afi, safi, vty, subgrp_id);
15302 return CMD_SUCCESS;
15303 }
15304
15305 DEFUN (show_ip_bgp_updgrps,
15306 show_ip_bgp_updgrps_cmd,
15307 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15308 SHOW_STR
15309 IP_STR
15310 BGP_STR
15311 BGP_INSTANCE_HELP_STR
15312 BGP_AFI_HELP_STR
15313 BGP_SAFI_WITH_LABEL_HELP_STR
15314 "Detailed info about dynamic update groups\n"
15315 "Specific subgroup to display detailed info for\n")
15316 {
15317 char *vrf = NULL;
15318 afi_t afi = AFI_IP6;
15319 safi_t safi = SAFI_UNICAST;
15320 uint64_t subgrp_id = 0;
15321
15322 int idx = 0;
15323
15324 /* show [ip] bgp */
15325 if (argv_find(argv, argc, "ip", &idx))
15326 afi = AFI_IP;
15327 /* [<vrf> VIEWVRFNAME] */
15328 if (argv_find(argv, argc, "vrf", &idx)) {
15329 vrf = argv[idx + 1]->arg;
15330 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15331 vrf = NULL;
15332 } else if (argv_find(argv, argc, "view", &idx))
15333 /* [<view> VIEWVRFNAME] */
15334 vrf = argv[idx + 1]->arg;
15335 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15336 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15337 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15338 }
15339
15340 /* get subgroup id, if provided */
15341 idx = argc - 1;
15342 if (argv[idx]->type == VARIABLE_TKN)
15343 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15344
15345 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15346 }
15347
15348 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15349 show_bgp_instance_all_ipv6_updgrps_cmd,
15350 "show [ip] bgp <view|vrf> all update-groups",
15351 SHOW_STR
15352 IP_STR
15353 BGP_STR
15354 BGP_INSTANCE_ALL_HELP_STR
15355 "Detailed info about dynamic update groups\n")
15356 {
15357 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15358 return CMD_SUCCESS;
15359 }
15360
15361 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15362 show_bgp_l2vpn_evpn_updgrps_cmd,
15363 "show [ip] bgp l2vpn evpn update-groups",
15364 SHOW_STR
15365 IP_STR
15366 BGP_STR
15367 "l2vpn address family\n"
15368 "evpn sub-address family\n"
15369 "Detailed info about dynamic update groups\n")
15370 {
15371 char *vrf = NULL;
15372 uint64_t subgrp_id = 0;
15373
15374 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15375 return CMD_SUCCESS;
15376 }
15377
15378 DEFUN (show_bgp_updgrps_stats,
15379 show_bgp_updgrps_stats_cmd,
15380 "show [ip] bgp update-groups statistics",
15381 SHOW_STR
15382 IP_STR
15383 BGP_STR
15384 "Detailed info about dynamic update groups\n"
15385 "Statistics\n")
15386 {
15387 struct bgp *bgp;
15388
15389 bgp = bgp_get_default();
15390 if (bgp)
15391 update_group_show_stats(bgp, vty);
15392
15393 return CMD_SUCCESS;
15394 }
15395
15396 DEFUN (show_bgp_instance_updgrps_stats,
15397 show_bgp_instance_updgrps_stats_cmd,
15398 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15399 SHOW_STR
15400 IP_STR
15401 BGP_STR
15402 BGP_INSTANCE_HELP_STR
15403 "Detailed info about dynamic update groups\n"
15404 "Statistics\n")
15405 {
15406 int idx_word = 3;
15407 struct bgp *bgp;
15408
15409 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15410 if (bgp)
15411 update_group_show_stats(bgp, vty);
15412
15413 return CMD_SUCCESS;
15414 }
15415
15416 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15417 afi_t afi, safi_t safi,
15418 const char *what, uint64_t subgrp_id)
15419 {
15420 struct bgp *bgp;
15421
15422 if (name)
15423 bgp = bgp_lookup_by_name(name);
15424 else
15425 bgp = bgp_get_default();
15426
15427 if (bgp) {
15428 if (!strcmp(what, "advertise-queue"))
15429 update_group_show_adj_queue(bgp, afi, safi, vty,
15430 subgrp_id);
15431 else if (!strcmp(what, "advertised-routes"))
15432 update_group_show_advertised(bgp, afi, safi, vty,
15433 subgrp_id);
15434 else if (!strcmp(what, "packet-queue"))
15435 update_group_show_packet_queue(bgp, afi, safi, vty,
15436 subgrp_id);
15437 }
15438 }
15439
15440 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15441 show_ip_bgp_instance_updgrps_adj_s_cmd,
15442 "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",
15443 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15444 BGP_SAFI_HELP_STR
15445 "Detailed info about dynamic update groups\n"
15446 "Specific subgroup to display info for\n"
15447 "Advertisement queue\n"
15448 "Announced routes\n"
15449 "Packet queue\n")
15450 {
15451 uint64_t subgrp_id = 0;
15452 afi_t afiz;
15453 safi_t safiz;
15454 if (sgid)
15455 subgrp_id = strtoull(sgid, NULL, 10);
15456
15457 if (!ip && !afi)
15458 afiz = AFI_IP6;
15459 if (!ip && afi)
15460 afiz = bgp_vty_afi_from_str(afi);
15461 if (ip && !afi)
15462 afiz = AFI_IP;
15463 if (ip && afi) {
15464 afiz = bgp_vty_afi_from_str(afi);
15465 if (afiz != AFI_IP)
15466 vty_out(vty,
15467 "%% Cannot specify both 'ip' and 'ipv6'\n");
15468 return CMD_WARNING;
15469 }
15470
15471 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15472
15473 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15474 return CMD_SUCCESS;
15475 }
15476
15477 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15478 json_object *json)
15479 {
15480 struct listnode *node, *nnode;
15481 struct prefix *range;
15482 struct peer *conf;
15483 struct peer *peer;
15484 afi_t afi;
15485 safi_t safi;
15486 const char *peer_status;
15487 int lr_count;
15488 int dynamic;
15489 bool af_cfgd;
15490 json_object *json_peer_group = NULL;
15491 json_object *json_peer_group_afc = NULL;
15492 json_object *json_peer_group_members = NULL;
15493 json_object *json_peer_group_dynamic = NULL;
15494 json_object *json_peer_group_dynamic_af = NULL;
15495 json_object *json_peer_group_ranges = NULL;
15496
15497 conf = group->conf;
15498
15499 if (json) {
15500 json_peer_group = json_object_new_object();
15501 json_peer_group_afc = json_object_new_array();
15502 }
15503
15504 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15505 if (json)
15506 json_object_int_add(json_peer_group, "remoteAs",
15507 conf->as);
15508 else
15509 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15510 group->name, conf->as);
15511 } else if (conf->as_type == AS_INTERNAL) {
15512 if (json)
15513 json_object_int_add(json_peer_group, "remoteAs",
15514 group->bgp->as);
15515 else
15516 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15517 group->name, group->bgp->as);
15518 } else {
15519 if (!json)
15520 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15521 }
15522
15523 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15524 if (json)
15525 json_object_string_add(json_peer_group, "type",
15526 "internal");
15527 else
15528 vty_out(vty, " Peer-group type is internal\n");
15529 } else {
15530 if (json)
15531 json_object_string_add(json_peer_group, "type",
15532 "external");
15533 else
15534 vty_out(vty, " Peer-group type is external\n");
15535 }
15536
15537 /* Display AFs configured. */
15538 if (!json)
15539 vty_out(vty, " Configured address-families:");
15540
15541 FOREACH_AFI_SAFI (afi, safi) {
15542 if (conf->afc[afi][safi]) {
15543 af_cfgd = true;
15544 if (json)
15545 json_object_array_add(
15546 json_peer_group_afc,
15547 json_object_new_string(get_afi_safi_str(
15548 afi, safi, false)));
15549 else
15550 vty_out(vty, " %s;",
15551 get_afi_safi_str(afi, safi, false));
15552 }
15553 }
15554
15555 if (json) {
15556 json_object_object_add(json_peer_group,
15557 "addressFamiliesConfigured",
15558 json_peer_group_afc);
15559 } else {
15560 if (!af_cfgd)
15561 vty_out(vty, " none\n");
15562 else
15563 vty_out(vty, "\n");
15564 }
15565
15566 /* Display listen ranges (for dynamic neighbors), if any */
15567 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15568 lr_count = listcount(group->listen_range[afi]);
15569 if (lr_count) {
15570 if (json) {
15571 if (!json_peer_group_dynamic)
15572 json_peer_group_dynamic =
15573 json_object_new_object();
15574
15575 json_peer_group_dynamic_af =
15576 json_object_new_object();
15577 json_peer_group_ranges =
15578 json_object_new_array();
15579 json_object_int_add(json_peer_group_dynamic_af,
15580 "count", lr_count);
15581 } else {
15582 vty_out(vty, " %d %s listen range(s)\n",
15583 lr_count, afi2str(afi));
15584 }
15585
15586 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15587 nnode, range)) {
15588 if (json) {
15589 char buf[BUFSIZ];
15590
15591 snprintfrr(buf, sizeof(buf), "%pFX",
15592 range);
15593
15594 json_object_array_add(
15595 json_peer_group_ranges,
15596 json_object_new_string(buf));
15597 } else {
15598 vty_out(vty, " %pFX\n", range);
15599 }
15600 }
15601
15602 if (json) {
15603 json_object_object_add(
15604 json_peer_group_dynamic_af, "ranges",
15605 json_peer_group_ranges);
15606
15607 json_object_object_add(
15608 json_peer_group_dynamic, afi2str(afi),
15609 json_peer_group_dynamic_af);
15610 }
15611 }
15612 }
15613
15614 if (json_peer_group_dynamic)
15615 json_object_object_add(json_peer_group, "dynamicRanges",
15616 json_peer_group_dynamic);
15617
15618 /* Display group members and their status */
15619 if (listcount(group->peer)) {
15620 if (json)
15621 json_peer_group_members = json_object_new_object();
15622 else
15623 vty_out(vty, " Peer-group members:\n");
15624 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15625 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15626 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15627 peer_status = "Idle (Admin)";
15628 else if (CHECK_FLAG(peer->sflags,
15629 PEER_STATUS_PREFIX_OVERFLOW))
15630 peer_status = "Idle (PfxCt)";
15631 else
15632 peer_status = lookup_msg(bgp_status_msg,
15633 peer->status, NULL);
15634
15635 dynamic = peer_dynamic_neighbor(peer);
15636
15637 if (json) {
15638 json_object *json_peer_group_member =
15639 json_object_new_object();
15640
15641 json_object_string_add(json_peer_group_member,
15642 "status", peer_status);
15643
15644 if (dynamic)
15645 json_object_boolean_true_add(
15646 json_peer_group_member,
15647 "dynamic");
15648
15649 json_object_object_add(json_peer_group_members,
15650 peer->host,
15651 json_peer_group_member);
15652 } else {
15653 vty_out(vty, " %s %s %s \n", peer->host,
15654 dynamic ? "(dynamic)" : "",
15655 peer_status);
15656 }
15657 }
15658 if (json)
15659 json_object_object_add(json_peer_group, "members",
15660 json_peer_group_members);
15661 }
15662
15663 if (json)
15664 json_object_object_add(json, group->name, json_peer_group);
15665
15666 return CMD_SUCCESS;
15667 }
15668
15669 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15670 const char *group_name, bool uj)
15671 {
15672 struct bgp *bgp;
15673 struct listnode *node, *nnode;
15674 struct peer_group *group;
15675 bool found = false;
15676 json_object *json = NULL;
15677
15678 if (uj)
15679 json = json_object_new_object();
15680
15681 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15682
15683 if (!bgp) {
15684 if (uj)
15685 vty_json(vty, json);
15686 else
15687 vty_out(vty, "%% BGP instance not found\n");
15688
15689 return CMD_WARNING;
15690 }
15691
15692 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15693 if (group_name) {
15694 if (strmatch(group->name, group_name)) {
15695 bgp_show_one_peer_group(vty, group, json);
15696 found = true;
15697 break;
15698 }
15699 } else {
15700 bgp_show_one_peer_group(vty, group, json);
15701 }
15702 }
15703
15704 if (group_name && !found && !uj)
15705 vty_out(vty, "%% No such peer-group\n");
15706
15707 if (uj)
15708 vty_json(vty, json);
15709
15710 return CMD_SUCCESS;
15711 }
15712
15713 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15714 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15715 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15716 "Detailed information on BGP peer groups\n"
15717 "Peer group name\n" JSON_STR)
15718 {
15719 char *vrf, *pg;
15720 int idx = 0;
15721 bool uj = use_json(argc, argv);
15722
15723 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15724 : NULL;
15725 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15726
15727 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15728 }
15729
15730
15731 /* Redistribute VTY commands. */
15732
15733 DEFUN (bgp_redistribute_ipv4,
15734 bgp_redistribute_ipv4_cmd,
15735 "redistribute " FRR_IP_REDIST_STR_BGPD,
15736 "Redistribute information from another routing protocol\n"
15737 FRR_IP_REDIST_HELP_STR_BGPD)
15738 {
15739 VTY_DECLVAR_CONTEXT(bgp, bgp);
15740 int idx_protocol = 1;
15741 int type;
15742
15743 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15744 if (type < 0) {
15745 vty_out(vty, "%% Invalid route type\n");
15746 return CMD_WARNING_CONFIG_FAILED;
15747 }
15748
15749 bgp_redist_add(bgp, AFI_IP, type, 0);
15750 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15751 }
15752
15753 ALIAS_HIDDEN(
15754 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15755 "redistribute " FRR_IP_REDIST_STR_BGPD,
15756 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15757
15758 DEFUN (bgp_redistribute_ipv4_rmap,
15759 bgp_redistribute_ipv4_rmap_cmd,
15760 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15761 "Redistribute information from another routing protocol\n"
15762 FRR_IP_REDIST_HELP_STR_BGPD
15763 "Route map reference\n"
15764 "Pointer to route-map entries\n")
15765 {
15766 VTY_DECLVAR_CONTEXT(bgp, bgp);
15767 int idx_protocol = 1;
15768 int idx_word = 3;
15769 int type;
15770 struct bgp_redist *red;
15771 bool changed;
15772 struct route_map *route_map = route_map_lookup_warn_noexist(
15773 vty, argv[idx_word]->arg);
15774
15775 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15776 if (type < 0) {
15777 vty_out(vty, "%% Invalid route type\n");
15778 return CMD_WARNING_CONFIG_FAILED;
15779 }
15780
15781 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15782 changed =
15783 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15784 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15785 }
15786
15787 ALIAS_HIDDEN(
15788 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15789 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15790 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15791 "Route map reference\n"
15792 "Pointer to route-map entries\n")
15793
15794 DEFUN (bgp_redistribute_ipv4_metric,
15795 bgp_redistribute_ipv4_metric_cmd,
15796 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15797 "Redistribute information from another routing protocol\n"
15798 FRR_IP_REDIST_HELP_STR_BGPD
15799 "Metric for redistributed routes\n"
15800 "Default metric\n")
15801 {
15802 VTY_DECLVAR_CONTEXT(bgp, bgp);
15803 int idx_protocol = 1;
15804 int idx_number = 3;
15805 int type;
15806 uint32_t metric;
15807 struct bgp_redist *red;
15808 bool changed;
15809
15810 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15811 if (type < 0) {
15812 vty_out(vty, "%% Invalid route type\n");
15813 return CMD_WARNING_CONFIG_FAILED;
15814 }
15815 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15816
15817 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15818 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15819 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15820 }
15821
15822 ALIAS_HIDDEN(
15823 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15824 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15825 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15826 "Metric for redistributed routes\n"
15827 "Default metric\n")
15828
15829 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15830 bgp_redistribute_ipv4_rmap_metric_cmd,
15831 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15832 "Redistribute information from another routing protocol\n"
15833 FRR_IP_REDIST_HELP_STR_BGPD
15834 "Route map reference\n"
15835 "Pointer to route-map entries\n"
15836 "Metric for redistributed routes\n"
15837 "Default metric\n")
15838 {
15839 VTY_DECLVAR_CONTEXT(bgp, bgp);
15840 int idx_protocol = 1;
15841 int idx_word = 3;
15842 int idx_number = 5;
15843 int type;
15844 uint32_t metric;
15845 struct bgp_redist *red;
15846 bool changed;
15847 struct route_map *route_map =
15848 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15849
15850 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15851 if (type < 0) {
15852 vty_out(vty, "%% Invalid route type\n");
15853 return CMD_WARNING_CONFIG_FAILED;
15854 }
15855 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15856
15857 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15858 changed =
15859 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15860 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15861 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15862 }
15863
15864 ALIAS_HIDDEN(
15865 bgp_redistribute_ipv4_rmap_metric,
15866 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15867 "redistribute " FRR_IP_REDIST_STR_BGPD
15868 " route-map RMAP_NAME metric (0-4294967295)",
15869 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15870 "Route map reference\n"
15871 "Pointer to route-map entries\n"
15872 "Metric for redistributed routes\n"
15873 "Default metric\n")
15874
15875 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15876 bgp_redistribute_ipv4_metric_rmap_cmd,
15877 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15878 "Redistribute information from another routing protocol\n"
15879 FRR_IP_REDIST_HELP_STR_BGPD
15880 "Metric for redistributed routes\n"
15881 "Default metric\n"
15882 "Route map reference\n"
15883 "Pointer to route-map entries\n")
15884 {
15885 VTY_DECLVAR_CONTEXT(bgp, bgp);
15886 int idx_protocol = 1;
15887 int idx_number = 3;
15888 int idx_word = 5;
15889 int type;
15890 uint32_t metric;
15891 struct bgp_redist *red;
15892 bool changed;
15893 struct route_map *route_map =
15894 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15895
15896 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15897 if (type < 0) {
15898 vty_out(vty, "%% Invalid route type\n");
15899 return CMD_WARNING_CONFIG_FAILED;
15900 }
15901 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15902
15903 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15904 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15905 changed |=
15906 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15907 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15908 }
15909
15910 ALIAS_HIDDEN(
15911 bgp_redistribute_ipv4_metric_rmap,
15912 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15913 "redistribute " FRR_IP_REDIST_STR_BGPD
15914 " metric (0-4294967295) route-map RMAP_NAME",
15915 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15916 "Metric for redistributed routes\n"
15917 "Default metric\n"
15918 "Route map reference\n"
15919 "Pointer to route-map entries\n")
15920
15921 DEFUN (bgp_redistribute_ipv4_ospf,
15922 bgp_redistribute_ipv4_ospf_cmd,
15923 "redistribute <ospf|table> (1-65535)",
15924 "Redistribute information from another routing protocol\n"
15925 "Open Shortest Path First (OSPFv2)\n"
15926 "Non-main Kernel Routing Table\n"
15927 "Instance ID/Table ID\n")
15928 {
15929 VTY_DECLVAR_CONTEXT(bgp, bgp);
15930 int idx_ospf_table = 1;
15931 int idx_number = 2;
15932 unsigned short instance;
15933 unsigned short protocol;
15934
15935 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15936
15937 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15938 protocol = ZEBRA_ROUTE_OSPF;
15939 else
15940 protocol = ZEBRA_ROUTE_TABLE;
15941
15942 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15943 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15944 }
15945
15946 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15947 "redistribute <ospf|table> (1-65535)",
15948 "Redistribute information from another routing protocol\n"
15949 "Open Shortest Path First (OSPFv2)\n"
15950 "Non-main Kernel Routing Table\n"
15951 "Instance ID/Table ID\n")
15952
15953 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15954 bgp_redistribute_ipv4_ospf_rmap_cmd,
15955 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15956 "Redistribute information from another routing protocol\n"
15957 "Open Shortest Path First (OSPFv2)\n"
15958 "Non-main Kernel Routing Table\n"
15959 "Instance ID/Table ID\n"
15960 "Route map reference\n"
15961 "Pointer to route-map entries\n")
15962 {
15963 VTY_DECLVAR_CONTEXT(bgp, bgp);
15964 int idx_ospf_table = 1;
15965 int idx_number = 2;
15966 int idx_word = 4;
15967 struct bgp_redist *red;
15968 unsigned short instance;
15969 int protocol;
15970 bool changed;
15971 struct route_map *route_map =
15972 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15973
15974 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15975 protocol = ZEBRA_ROUTE_OSPF;
15976 else
15977 protocol = ZEBRA_ROUTE_TABLE;
15978
15979 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15980 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15981 changed =
15982 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15983 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15984 }
15985
15986 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15987 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15988 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15989 "Redistribute information from another routing protocol\n"
15990 "Open Shortest Path First (OSPFv2)\n"
15991 "Non-main Kernel Routing Table\n"
15992 "Instance ID/Table ID\n"
15993 "Route map reference\n"
15994 "Pointer to route-map entries\n")
15995
15996 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15997 bgp_redistribute_ipv4_ospf_metric_cmd,
15998 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15999 "Redistribute information from another routing protocol\n"
16000 "Open Shortest Path First (OSPFv2)\n"
16001 "Non-main Kernel Routing Table\n"
16002 "Instance ID/Table ID\n"
16003 "Metric for redistributed routes\n"
16004 "Default metric\n")
16005 {
16006 VTY_DECLVAR_CONTEXT(bgp, bgp);
16007 int idx_ospf_table = 1;
16008 int idx_number = 2;
16009 int idx_number_2 = 4;
16010 uint32_t metric;
16011 struct bgp_redist *red;
16012 unsigned short instance;
16013 int protocol;
16014 bool changed;
16015
16016 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16017 protocol = ZEBRA_ROUTE_OSPF;
16018 else
16019 protocol = ZEBRA_ROUTE_TABLE;
16020
16021 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16022 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16023
16024 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16025 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16026 metric);
16027 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16028 }
16029
16030 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16031 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16032 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16033 "Redistribute information from another routing protocol\n"
16034 "Open Shortest Path First (OSPFv2)\n"
16035 "Non-main Kernel Routing Table\n"
16036 "Instance ID/Table ID\n"
16037 "Metric for redistributed routes\n"
16038 "Default metric\n")
16039
16040 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16041 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16042 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16043 "Redistribute information from another routing protocol\n"
16044 "Open Shortest Path First (OSPFv2)\n"
16045 "Non-main Kernel Routing Table\n"
16046 "Instance ID/Table ID\n"
16047 "Route map reference\n"
16048 "Pointer to route-map entries\n"
16049 "Metric for redistributed routes\n"
16050 "Default metric\n")
16051 {
16052 VTY_DECLVAR_CONTEXT(bgp, bgp);
16053 int idx_ospf_table = 1;
16054 int idx_number = 2;
16055 int idx_word = 4;
16056 int idx_number_2 = 6;
16057 uint32_t metric;
16058 struct bgp_redist *red;
16059 unsigned short instance;
16060 int protocol;
16061 bool changed;
16062 struct route_map *route_map =
16063 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16064
16065 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16066 protocol = ZEBRA_ROUTE_OSPF;
16067 else
16068 protocol = ZEBRA_ROUTE_TABLE;
16069
16070 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16071 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16072
16073 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16074 changed =
16075 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16076 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16077 metric);
16078 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16079 }
16080
16081 ALIAS_HIDDEN(
16082 bgp_redistribute_ipv4_ospf_rmap_metric,
16083 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16084 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16085 "Redistribute information from another routing protocol\n"
16086 "Open Shortest Path First (OSPFv2)\n"
16087 "Non-main Kernel Routing Table\n"
16088 "Instance ID/Table ID\n"
16089 "Route map reference\n"
16090 "Pointer to route-map entries\n"
16091 "Metric for redistributed routes\n"
16092 "Default metric\n")
16093
16094 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16095 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16096 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16097 "Redistribute information from another routing protocol\n"
16098 "Open Shortest Path First (OSPFv2)\n"
16099 "Non-main Kernel Routing Table\n"
16100 "Instance ID/Table ID\n"
16101 "Metric for redistributed routes\n"
16102 "Default metric\n"
16103 "Route map reference\n"
16104 "Pointer to route-map entries\n")
16105 {
16106 VTY_DECLVAR_CONTEXT(bgp, bgp);
16107 int idx_ospf_table = 1;
16108 int idx_number = 2;
16109 int idx_number_2 = 4;
16110 int idx_word = 6;
16111 uint32_t metric;
16112 struct bgp_redist *red;
16113 unsigned short instance;
16114 int protocol;
16115 bool changed;
16116 struct route_map *route_map =
16117 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16118
16119 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16120 protocol = ZEBRA_ROUTE_OSPF;
16121 else
16122 protocol = ZEBRA_ROUTE_TABLE;
16123
16124 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16125 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16126
16127 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16128 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16129 metric);
16130 changed |=
16131 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16132 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16133 }
16134
16135 ALIAS_HIDDEN(
16136 bgp_redistribute_ipv4_ospf_metric_rmap,
16137 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16138 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16139 "Redistribute information from another routing protocol\n"
16140 "Open Shortest Path First (OSPFv2)\n"
16141 "Non-main Kernel Routing Table\n"
16142 "Instance ID/Table ID\n"
16143 "Metric for redistributed routes\n"
16144 "Default metric\n"
16145 "Route map reference\n"
16146 "Pointer to route-map entries\n")
16147
16148 DEFUN (no_bgp_redistribute_ipv4_ospf,
16149 no_bgp_redistribute_ipv4_ospf_cmd,
16150 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16151 NO_STR
16152 "Redistribute information from another routing protocol\n"
16153 "Open Shortest Path First (OSPFv2)\n"
16154 "Non-main Kernel Routing Table\n"
16155 "Instance ID/Table ID\n"
16156 "Metric for redistributed routes\n"
16157 "Default metric\n"
16158 "Route map reference\n"
16159 "Pointer to route-map entries\n")
16160 {
16161 VTY_DECLVAR_CONTEXT(bgp, bgp);
16162 int idx_ospf_table = 2;
16163 int idx_number = 3;
16164 unsigned short instance;
16165 int protocol;
16166
16167 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16168 protocol = ZEBRA_ROUTE_OSPF;
16169 else
16170 protocol = ZEBRA_ROUTE_TABLE;
16171
16172 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16173 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16174 }
16175
16176 ALIAS_HIDDEN(
16177 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16178 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16179 NO_STR
16180 "Redistribute information from another routing protocol\n"
16181 "Open Shortest Path First (OSPFv2)\n"
16182 "Non-main Kernel Routing Table\n"
16183 "Instance ID/Table ID\n"
16184 "Metric for redistributed routes\n"
16185 "Default metric\n"
16186 "Route map reference\n"
16187 "Pointer to route-map entries\n")
16188
16189 DEFUN (no_bgp_redistribute_ipv4,
16190 no_bgp_redistribute_ipv4_cmd,
16191 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16192 NO_STR
16193 "Redistribute information from another routing protocol\n"
16194 FRR_IP_REDIST_HELP_STR_BGPD
16195 "Metric for redistributed routes\n"
16196 "Default metric\n"
16197 "Route map reference\n"
16198 "Pointer to route-map entries\n")
16199 {
16200 VTY_DECLVAR_CONTEXT(bgp, bgp);
16201 int idx_protocol = 2;
16202 int type;
16203
16204 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16205 if (type < 0) {
16206 vty_out(vty, "%% Invalid route type\n");
16207 return CMD_WARNING_CONFIG_FAILED;
16208 }
16209 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16210 }
16211
16212 ALIAS_HIDDEN(
16213 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16214 "no redistribute " FRR_IP_REDIST_STR_BGPD
16215 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16216 NO_STR
16217 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16218 "Metric for redistributed routes\n"
16219 "Default metric\n"
16220 "Route map reference\n"
16221 "Pointer to route-map entries\n")
16222
16223 DEFUN (bgp_redistribute_ipv6,
16224 bgp_redistribute_ipv6_cmd,
16225 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16226 "Redistribute information from another routing protocol\n"
16227 FRR_IP6_REDIST_HELP_STR_BGPD)
16228 {
16229 VTY_DECLVAR_CONTEXT(bgp, bgp);
16230 int idx_protocol = 1;
16231 int type;
16232
16233 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16234 if (type < 0) {
16235 vty_out(vty, "%% Invalid route type\n");
16236 return CMD_WARNING_CONFIG_FAILED;
16237 }
16238
16239 bgp_redist_add(bgp, AFI_IP6, type, 0);
16240 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16241 }
16242
16243 DEFUN (bgp_redistribute_ipv6_rmap,
16244 bgp_redistribute_ipv6_rmap_cmd,
16245 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16246 "Redistribute information from another routing protocol\n"
16247 FRR_IP6_REDIST_HELP_STR_BGPD
16248 "Route map reference\n"
16249 "Pointer to route-map entries\n")
16250 {
16251 VTY_DECLVAR_CONTEXT(bgp, bgp);
16252 int idx_protocol = 1;
16253 int idx_word = 3;
16254 int type;
16255 struct bgp_redist *red;
16256 bool changed;
16257 struct route_map *route_map =
16258 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16259
16260 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16261 if (type < 0) {
16262 vty_out(vty, "%% Invalid route type\n");
16263 return CMD_WARNING_CONFIG_FAILED;
16264 }
16265
16266 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16267 changed =
16268 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16269 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16270 }
16271
16272 DEFUN (bgp_redistribute_ipv6_metric,
16273 bgp_redistribute_ipv6_metric_cmd,
16274 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16275 "Redistribute information from another routing protocol\n"
16276 FRR_IP6_REDIST_HELP_STR_BGPD
16277 "Metric for redistributed routes\n"
16278 "Default metric\n")
16279 {
16280 VTY_DECLVAR_CONTEXT(bgp, bgp);
16281 int idx_protocol = 1;
16282 int idx_number = 3;
16283 int type;
16284 uint32_t metric;
16285 struct bgp_redist *red;
16286 bool changed;
16287
16288 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16289 if (type < 0) {
16290 vty_out(vty, "%% Invalid route type\n");
16291 return CMD_WARNING_CONFIG_FAILED;
16292 }
16293 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16294
16295 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16296 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16297 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16298 }
16299
16300 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16301 bgp_redistribute_ipv6_rmap_metric_cmd,
16302 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16303 "Redistribute information from another routing protocol\n"
16304 FRR_IP6_REDIST_HELP_STR_BGPD
16305 "Route map reference\n"
16306 "Pointer to route-map entries\n"
16307 "Metric for redistributed routes\n"
16308 "Default metric\n")
16309 {
16310 VTY_DECLVAR_CONTEXT(bgp, bgp);
16311 int idx_protocol = 1;
16312 int idx_word = 3;
16313 int idx_number = 5;
16314 int type;
16315 uint32_t metric;
16316 struct bgp_redist *red;
16317 bool changed;
16318 struct route_map *route_map =
16319 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16320
16321 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16322 if (type < 0) {
16323 vty_out(vty, "%% Invalid route type\n");
16324 return CMD_WARNING_CONFIG_FAILED;
16325 }
16326 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16327
16328 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16329 changed =
16330 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16331 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16332 metric);
16333 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16334 }
16335
16336 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16337 bgp_redistribute_ipv6_metric_rmap_cmd,
16338 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16339 "Redistribute information from another routing protocol\n"
16340 FRR_IP6_REDIST_HELP_STR_BGPD
16341 "Metric for redistributed routes\n"
16342 "Default metric\n"
16343 "Route map reference\n"
16344 "Pointer to route-map entries\n")
16345 {
16346 VTY_DECLVAR_CONTEXT(bgp, bgp);
16347 int idx_protocol = 1;
16348 int idx_number = 3;
16349 int idx_word = 5;
16350 int type;
16351 uint32_t metric;
16352 struct bgp_redist *red;
16353 bool changed;
16354 struct route_map *route_map =
16355 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16356
16357 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16358 if (type < 0) {
16359 vty_out(vty, "%% Invalid route type\n");
16360 return CMD_WARNING_CONFIG_FAILED;
16361 }
16362 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16363
16364 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16365 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16366 metric);
16367 changed |=
16368 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16369 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16370 }
16371
16372 DEFUN (no_bgp_redistribute_ipv6,
16373 no_bgp_redistribute_ipv6_cmd,
16374 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16375 NO_STR
16376 "Redistribute information from another routing protocol\n"
16377 FRR_IP6_REDIST_HELP_STR_BGPD
16378 "Metric for redistributed routes\n"
16379 "Default metric\n"
16380 "Route map reference\n"
16381 "Pointer to route-map entries\n")
16382 {
16383 VTY_DECLVAR_CONTEXT(bgp, bgp);
16384 int idx_protocol = 2;
16385 int type;
16386
16387 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16388 if (type < 0) {
16389 vty_out(vty, "%% Invalid route type\n");
16390 return CMD_WARNING_CONFIG_FAILED;
16391 }
16392
16393 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16394 }
16395
16396 /* Neighbor update tcp-mss. */
16397 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16398 const char *tcp_mss_str)
16399 {
16400 struct peer *peer;
16401 uint32_t tcp_mss_val = 0;
16402
16403 peer = peer_and_group_lookup_vty(vty, peer_str);
16404 if (!peer)
16405 return CMD_WARNING_CONFIG_FAILED;
16406
16407 if (tcp_mss_str) {
16408 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16409 peer_tcp_mss_set(peer, tcp_mss_val);
16410 } else {
16411 peer_tcp_mss_unset(peer);
16412 }
16413
16414 return CMD_SUCCESS;
16415 }
16416
16417 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16418 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16419 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16420 "TCP max segment size\n"
16421 "TCP MSS value\n")
16422 {
16423 int peer_index = 1;
16424 int mss_index = 3;
16425
16426 vty_out(vty,
16427 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16428 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16429 argv[mss_index]->arg);
16430 }
16431
16432 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16433 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16434 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16435 "TCP max segment size\n"
16436 "TCP MSS value\n")
16437 {
16438 int peer_index = 2;
16439
16440 vty_out(vty,
16441 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16442 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16443 }
16444
16445 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16446 "[no$no] bgp retain route-target all",
16447 NO_STR BGP_STR
16448 "Retain BGP updates\n"
16449 "Retain BGP updates based on route-target values\n"
16450 "Retain all BGP updates\n")
16451 {
16452 bool check;
16453 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16454
16455 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16456 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16457 if (check != !no) {
16458 if (!no)
16459 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16460 [bgp_node_safi(vty)],
16461 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16462 else
16463 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16464 [bgp_node_safi(vty)],
16465 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16466 /* trigger a flush to re-sync with ADJ-RIB-in */
16467 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16468 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16469 }
16470 return CMD_SUCCESS;
16471 }
16472
16473 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16474 afi_t afi, safi_t safi)
16475 {
16476 int i;
16477
16478 /* Unicast redistribution only. */
16479 if (safi != SAFI_UNICAST)
16480 return;
16481
16482 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16483 /* Redistribute BGP does not make sense. */
16484 if (i != ZEBRA_ROUTE_BGP) {
16485 struct list *red_list;
16486 struct listnode *node;
16487 struct bgp_redist *red;
16488
16489 red_list = bgp->redist[afi][i];
16490 if (!red_list)
16491 continue;
16492
16493 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16494 /* "redistribute" configuration. */
16495 vty_out(vty, " redistribute %s",
16496 zebra_route_string(i));
16497 if (red->instance)
16498 vty_out(vty, " %d", red->instance);
16499 if (red->redist_metric_flag)
16500 vty_out(vty, " metric %u",
16501 red->redist_metric);
16502 if (red->rmap.name)
16503 vty_out(vty, " route-map %s",
16504 red->rmap.name);
16505 vty_out(vty, "\n");
16506 }
16507 }
16508 }
16509 }
16510
16511 /* peer-group helpers for config-write */
16512
16513 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16514 {
16515 if (!peer_group_active(peer)) {
16516 if (CHECK_FLAG(peer->flags_invert, flag))
16517 return !CHECK_FLAG(peer->flags, flag);
16518 else
16519 return !!CHECK_FLAG(peer->flags, flag);
16520 }
16521
16522 return !!CHECK_FLAG(peer->flags_override, flag);
16523 }
16524
16525 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16526 uint64_t flag)
16527 {
16528 if (!peer_group_active(peer)) {
16529 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16530 return !peer_af_flag_check(peer, afi, safi, flag);
16531 else
16532 return !!peer_af_flag_check(peer, afi, safi, flag);
16533 }
16534
16535 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16536 }
16537
16538 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16539 uint8_t type, int direct)
16540 {
16541 struct bgp_filter *filter;
16542
16543 if (peer_group_active(peer))
16544 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16545 type);
16546
16547 filter = &peer->filter[afi][safi];
16548 switch (type) {
16549 case PEER_FT_DISTRIBUTE_LIST:
16550 return !!(filter->dlist[direct].name);
16551 case PEER_FT_FILTER_LIST:
16552 return !!(filter->aslist[direct].name);
16553 case PEER_FT_PREFIX_LIST:
16554 return !!(filter->plist[direct].name);
16555 case PEER_FT_ROUTE_MAP:
16556 return !!(filter->map[direct].name);
16557 case PEER_FT_UNSUPPRESS_MAP:
16558 return !!(filter->usmap.name);
16559 case PEER_FT_ADVERTISE_MAP:
16560 return !!(filter->advmap.aname
16561 && ((filter->advmap.condition == direct)
16562 && filter->advmap.cname));
16563 default:
16564 return false;
16565 }
16566 }
16567
16568 /* Return true if the addpath type is set for peer and different from
16569 * peer-group.
16570 */
16571 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16572 safi_t safi)
16573 {
16574 enum bgp_addpath_strat type, g_type;
16575
16576 type = peer->addpath_type[afi][safi];
16577
16578 if (type != BGP_ADDPATH_NONE) {
16579 if (peer_group_active(peer)) {
16580 g_type = peer->group->conf->addpath_type[afi][safi];
16581
16582 if (type != g_type)
16583 return true;
16584 else
16585 return false;
16586 }
16587
16588 return true;
16589 }
16590
16591 return false;
16592 }
16593
16594 /* This is part of the address-family block (unicast only) */
16595 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16596 afi_t afi)
16597 {
16598 int indent = 2;
16599 uint32_t tovpn_sid_index = 0;
16600
16601 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16602 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16603 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16604 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16605 bgp->vpn_policy[afi]
16606 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16607 else
16608 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16609 bgp->vpn_policy[afi]
16610 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16611 }
16612 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16613 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16614 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16615 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16616 return;
16617
16618 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16619 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16620
16621 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16622
16623 } else {
16624 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16625 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16626 bgp->vpn_policy[afi].tovpn_label);
16627 }
16628 }
16629
16630 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16631 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16632 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16633 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16634 } else if (tovpn_sid_index != 0) {
16635 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16636 tovpn_sid_index);
16637 }
16638
16639 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16640 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16641 &bgp->vpn_policy[afi].tovpn_rd);
16642
16643 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16644 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16645
16646 char buf[PREFIX_STRLEN];
16647 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16648 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16649 sizeof(buf))) {
16650
16651 vty_out(vty, "%*snexthop vpn export %s\n",
16652 indent, "", buf);
16653 }
16654 }
16655 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16656 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16657 && ecommunity_cmp(
16658 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16659 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16660
16661 char *b = ecommunity_ecom2str(
16662 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16663 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16664 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16665 XFREE(MTYPE_ECOMMUNITY_STR, b);
16666 } else {
16667 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16668 char *b = ecommunity_ecom2str(
16669 bgp->vpn_policy[afi]
16670 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16671 ECOMMUNITY_FORMAT_ROUTE_MAP,
16672 ECOMMUNITY_ROUTE_TARGET);
16673 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16674 XFREE(MTYPE_ECOMMUNITY_STR, b);
16675 }
16676 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16677 char *b = ecommunity_ecom2str(
16678 bgp->vpn_policy[afi]
16679 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16680 ECOMMUNITY_FORMAT_ROUTE_MAP,
16681 ECOMMUNITY_ROUTE_TARGET);
16682 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16683 XFREE(MTYPE_ECOMMUNITY_STR, b);
16684 }
16685 }
16686
16687 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16688 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16689 bgp->vpn_policy[afi]
16690 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16691
16692 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16693 char *b = ecommunity_ecom2str(
16694 bgp->vpn_policy[afi]
16695 .import_redirect_rtlist,
16696 ECOMMUNITY_FORMAT_ROUTE_MAP,
16697 ECOMMUNITY_ROUTE_TARGET);
16698
16699 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16700 != ECOMMUNITY_SIZE)
16701 vty_out(vty, "%*srt6 redirect import %s\n",
16702 indent, "", b);
16703 else
16704 vty_out(vty, "%*srt redirect import %s\n",
16705 indent, "", b);
16706 XFREE(MTYPE_ECOMMUNITY_STR, b);
16707 }
16708 }
16709
16710 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16711 afi_t afi, safi_t safi)
16712 {
16713 struct bgp_filter *filter;
16714 char *addr;
16715
16716 addr = peer->host;
16717 filter = &peer->filter[afi][safi];
16718
16719 /* distribute-list. */
16720 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16721 FILTER_IN))
16722 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16723 filter->dlist[FILTER_IN].name);
16724
16725 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16726 FILTER_OUT))
16727 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16728 filter->dlist[FILTER_OUT].name);
16729
16730 /* prefix-list. */
16731 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16732 FILTER_IN))
16733 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16734 filter->plist[FILTER_IN].name);
16735
16736 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16737 FILTER_OUT))
16738 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16739 filter->plist[FILTER_OUT].name);
16740
16741 /* route-map. */
16742 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16743 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16744 filter->map[RMAP_IN].name);
16745
16746 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16747 RMAP_OUT))
16748 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16749 filter->map[RMAP_OUT].name);
16750
16751 /* unsuppress-map */
16752 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16753 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16754 filter->usmap.name);
16755
16756 /* advertise-map : always applied in OUT direction*/
16757 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16758 CONDITION_NON_EXIST))
16759 vty_out(vty,
16760 " neighbor %s advertise-map %s non-exist-map %s\n",
16761 addr, filter->advmap.aname, filter->advmap.cname);
16762
16763 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16764 CONDITION_EXIST))
16765 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16766 addr, filter->advmap.aname, filter->advmap.cname);
16767
16768 /* filter-list. */
16769 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16770 FILTER_IN))
16771 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16772 filter->aslist[FILTER_IN].name);
16773
16774 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16775 FILTER_OUT))
16776 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16777 filter->aslist[FILTER_OUT].name);
16778 }
16779
16780 /* BGP peer configuration display function. */
16781 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16782 struct peer *peer)
16783 {
16784 struct peer *g_peer = NULL;
16785 char *addr;
16786 int if_pg_printed = false;
16787 int if_ras_printed = false;
16788
16789 /* Skip dynamic neighbors. */
16790 if (peer_dynamic_neighbor(peer))
16791 return;
16792
16793 if (peer->conf_if)
16794 addr = peer->conf_if;
16795 else
16796 addr = peer->host;
16797
16798 /************************************
16799 ****** Global to the neighbor ******
16800 ************************************/
16801 if (peer->conf_if) {
16802 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16803 vty_out(vty, " neighbor %s interface v6only", addr);
16804 else
16805 vty_out(vty, " neighbor %s interface", addr);
16806
16807 if (peer_group_active(peer)) {
16808 vty_out(vty, " peer-group %s", peer->group->name);
16809 if_pg_printed = true;
16810 } else if (peer->as_type == AS_SPECIFIED) {
16811 vty_out(vty, " remote-as %u", peer->as);
16812 if_ras_printed = true;
16813 } else if (peer->as_type == AS_INTERNAL) {
16814 vty_out(vty, " remote-as internal");
16815 if_ras_printed = true;
16816 } else if (peer->as_type == AS_EXTERNAL) {
16817 vty_out(vty, " remote-as external");
16818 if_ras_printed = true;
16819 }
16820
16821 vty_out(vty, "\n");
16822 }
16823
16824 /* remote-as and peer-group */
16825 /* peer is a member of a peer-group */
16826 if (peer_group_active(peer)) {
16827 g_peer = peer->group->conf;
16828
16829 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16830 if (peer->as_type == AS_SPECIFIED) {
16831 vty_out(vty, " neighbor %s remote-as %u\n",
16832 addr, peer->as);
16833 } else if (peer->as_type == AS_INTERNAL) {
16834 vty_out(vty,
16835 " neighbor %s remote-as internal\n",
16836 addr);
16837 } else if (peer->as_type == AS_EXTERNAL) {
16838 vty_out(vty,
16839 " neighbor %s remote-as external\n",
16840 addr);
16841 }
16842 }
16843
16844 /* For swpX peers we displayed the peer-group
16845 * via 'neighbor swpX interface peer-group PGNAME' */
16846 if (!if_pg_printed)
16847 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16848 peer->group->name);
16849 }
16850
16851 /* peer is NOT a member of a peer-group */
16852 else {
16853 /* peer is a peer-group, declare the peer-group */
16854 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16855 vty_out(vty, " neighbor %s peer-group\n", addr);
16856 }
16857
16858 if (!if_ras_printed) {
16859 if (peer->as_type == AS_SPECIFIED) {
16860 vty_out(vty, " neighbor %s remote-as %u\n",
16861 addr, peer->as);
16862 } else if (peer->as_type == AS_INTERNAL) {
16863 vty_out(vty,
16864 " neighbor %s remote-as internal\n",
16865 addr);
16866 } else if (peer->as_type == AS_EXTERNAL) {
16867 vty_out(vty,
16868 " neighbor %s remote-as external\n",
16869 addr);
16870 }
16871 }
16872 }
16873
16874 /* local-as */
16875 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16876 vty_out(vty, " neighbor %s local-as %u", addr,
16877 peer->change_local_as);
16878 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16879 vty_out(vty, " no-prepend");
16880 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16881 vty_out(vty, " replace-as");
16882 vty_out(vty, "\n");
16883 }
16884
16885 /* description */
16886 if (peer->desc) {
16887 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16888 }
16889
16890 /* shutdown */
16891 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16892 if (peer->tx_shutdown_message)
16893 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16894 peer->tx_shutdown_message);
16895 else
16896 vty_out(vty, " neighbor %s shutdown\n", addr);
16897 }
16898
16899 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16900 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16901 peer->rtt_expected, peer->rtt_keepalive_conf);
16902
16903 /* bfd */
16904 if (peer->bfd_config)
16905 bgp_bfd_peer_config_write(vty, peer, addr);
16906
16907 /* password */
16908 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16909 vty_out(vty, " neighbor %s password %s\n", addr,
16910 peer->password);
16911
16912 /* neighbor solo */
16913 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16914 if (!peer_group_active(peer)) {
16915 vty_out(vty, " neighbor %s solo\n", addr);
16916 }
16917 }
16918
16919 /* BGP port */
16920 if (peer->port != BGP_PORT_DEFAULT) {
16921 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16922 }
16923
16924 /* Local interface name */
16925 if (peer->ifname) {
16926 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16927 }
16928
16929 /* TCP max segment size */
16930 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16931 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16932
16933 /* passive */
16934 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16935 vty_out(vty, " neighbor %s passive\n", addr);
16936
16937 /* ebgp-multihop */
16938 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16939 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16940 && peer->ttl == MAXTTL)) {
16941 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16942 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16943 peer->ttl);
16944 }
16945 }
16946
16947 /* role */
16948 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16949 peer->local_role != ROLE_UNDEFINED)
16950 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16951 bgp_get_name_by_role(peer->local_role),
16952 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
16953 ? " strict-mode"
16954 : "");
16955
16956 /* ttl-security hops */
16957 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16958 if (!peer_group_active(peer)
16959 || g_peer->gtsm_hops != peer->gtsm_hops) {
16960 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16961 addr, peer->gtsm_hops);
16962 }
16963 }
16964
16965 /* disable-connected-check */
16966 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16967 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16968
16969 /* link-bw-encoding-ieee */
16970 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16971 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16972 addr);
16973
16974 /* extended-optional-parameters */
16975 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16976 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16977 addr);
16978
16979 /* enforce-first-as */
16980 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16981 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16982
16983 /* update-source */
16984 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16985 if (peer->update_source)
16986 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16987 peer->update_source);
16988 else if (peer->update_if)
16989 vty_out(vty, " neighbor %s update-source %s\n", addr,
16990 peer->update_if);
16991 }
16992
16993 /* advertisement-interval */
16994 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16995 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16996 peer->routeadv);
16997
16998 /* timers */
16999 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17000 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17001 peer->keepalive, peer->holdtime);
17002
17003 /* timers connect */
17004 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17005 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17006 peer->connect);
17007 /* need special-case handling for changed default values due to
17008 * config profile / version (because there is no "timers bgp connect"
17009 * command, we need to save this per-peer :/)
17010 */
17011 else if (!peer_group_active(peer) && !peer->connect &&
17012 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17013 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17014 peer->bgp->default_connect_retry);
17015
17016 /* timers delayopen */
17017 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17018 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17019 peer->delayopen);
17020 /* Save config even though flag is not set if default values have been
17021 * changed
17022 */
17023 else if (!peer_group_active(peer) && !peer->delayopen
17024 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17025 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17026 peer->bgp->default_delayopen);
17027
17028 /* capability dynamic */
17029 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17030 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17031
17032 /* capability extended-nexthop */
17033 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17034 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17035 !peer->conf_if)
17036 vty_out(vty,
17037 " no neighbor %s capability extended-nexthop\n",
17038 addr);
17039 else if (!peer->conf_if)
17040 vty_out(vty,
17041 " neighbor %s capability extended-nexthop\n",
17042 addr);
17043 }
17044
17045 /* dont-capability-negotiation */
17046 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17047 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17048
17049 /* override-capability */
17050 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17051 vty_out(vty, " neighbor %s override-capability\n", addr);
17052
17053 /* strict-capability-match */
17054 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17055 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17056
17057 /* Sender side AS path loop detection. */
17058 if (peer->as_path_loop_detection)
17059 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17060 addr);
17061
17062 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17063 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17064
17065 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17066 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17067 vty_out(vty,
17068 " neighbor %s graceful-restart-helper\n", addr);
17069 } else if (CHECK_FLAG(
17070 peer->peer_gr_new_status_flag,
17071 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17072 vty_out(vty,
17073 " neighbor %s graceful-restart\n", addr);
17074 } else if (
17075 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17076 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17077 && !(CHECK_FLAG(
17078 peer->peer_gr_new_status_flag,
17079 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17080 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17081 addr);
17082 }
17083 }
17084 }
17085
17086 /* BGP peer configuration display function. */
17087 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17088 struct peer *peer, afi_t afi, safi_t safi)
17089 {
17090 struct peer *g_peer = NULL;
17091 char *addr;
17092 bool flag_scomm, flag_secomm, flag_slcomm;
17093
17094 /* Skip dynamic neighbors. */
17095 if (peer_dynamic_neighbor(peer))
17096 return;
17097
17098 if (peer->conf_if)
17099 addr = peer->conf_if;
17100 else
17101 addr = peer->host;
17102
17103 /************************************
17104 ****** Per AF to the neighbor ******
17105 ************************************/
17106 if (peer_group_active(peer)) {
17107 g_peer = peer->group->conf;
17108
17109 /* If the peer-group is active but peer is not, print a 'no
17110 * activate' */
17111 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17112 vty_out(vty, " no neighbor %s activate\n", addr);
17113 }
17114
17115 /* If the peer-group is not active but peer is, print an
17116 'activate' */
17117 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17118 vty_out(vty, " neighbor %s activate\n", addr);
17119 }
17120 } else {
17121 if (peer->afc[afi][safi]) {
17122 if (safi == SAFI_ENCAP)
17123 vty_out(vty, " neighbor %s activate\n", addr);
17124 else if (!bgp->default_af[afi][safi])
17125 vty_out(vty, " neighbor %s activate\n", addr);
17126 } else {
17127 if (bgp->default_af[afi][safi])
17128 vty_out(vty, " no neighbor %s activate\n",
17129 addr);
17130 }
17131 }
17132
17133 /* addpath TX knobs */
17134 if (peergroup_af_addpath_check(peer, afi, safi)) {
17135 switch (peer->addpath_type[afi][safi]) {
17136 case BGP_ADDPATH_ALL:
17137 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17138 addr);
17139 break;
17140 case BGP_ADDPATH_BEST_PER_AS:
17141 vty_out(vty,
17142 " neighbor %s addpath-tx-bestpath-per-AS\n",
17143 addr);
17144 break;
17145 case BGP_ADDPATH_MAX:
17146 case BGP_ADDPATH_NONE:
17147 break;
17148 }
17149 }
17150
17151 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17152 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17153
17154 /* ORF capability. */
17155 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17156 || peergroup_af_flag_check(peer, afi, safi,
17157 PEER_FLAG_ORF_PREFIX_RM)) {
17158 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17159
17160 if (peergroup_af_flag_check(peer, afi, safi,
17161 PEER_FLAG_ORF_PREFIX_SM)
17162 && peergroup_af_flag_check(peer, afi, safi,
17163 PEER_FLAG_ORF_PREFIX_RM))
17164 vty_out(vty, " both");
17165 else if (peergroup_af_flag_check(peer, afi, safi,
17166 PEER_FLAG_ORF_PREFIX_SM))
17167 vty_out(vty, " send");
17168 else
17169 vty_out(vty, " receive");
17170 vty_out(vty, "\n");
17171 }
17172
17173 /* Route reflector client. */
17174 if (peergroup_af_flag_check(peer, afi, safi,
17175 PEER_FLAG_REFLECTOR_CLIENT)) {
17176 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17177 }
17178
17179 /* next-hop-self force */
17180 if (peergroup_af_flag_check(peer, afi, safi,
17181 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17182 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17183 }
17184
17185 /* next-hop-self */
17186 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17187 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17188 }
17189
17190 /* remove-private-AS */
17191 if (peergroup_af_flag_check(peer, afi, safi,
17192 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17193 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17194 addr);
17195 }
17196
17197 else if (peergroup_af_flag_check(peer, afi, safi,
17198 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17199 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17200 addr);
17201 }
17202
17203 else if (peergroup_af_flag_check(peer, afi, safi,
17204 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17205 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17206 }
17207
17208 else if (peergroup_af_flag_check(peer, afi, safi,
17209 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17210 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17211 }
17212
17213 /* as-override */
17214 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17215 vty_out(vty, " neighbor %s as-override\n", addr);
17216 }
17217
17218 /* send-community print. */
17219 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17220 PEER_FLAG_SEND_COMMUNITY);
17221 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17222 PEER_FLAG_SEND_EXT_COMMUNITY);
17223 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17224 PEER_FLAG_SEND_LARGE_COMMUNITY);
17225
17226 if (flag_scomm && flag_secomm && flag_slcomm) {
17227 vty_out(vty, " no neighbor %s send-community all\n", addr);
17228 } else {
17229 if (flag_scomm)
17230 vty_out(vty, " no neighbor %s send-community\n", addr);
17231 if (flag_secomm)
17232 vty_out(vty,
17233 " no neighbor %s send-community extended\n",
17234 addr);
17235
17236 if (flag_slcomm)
17237 vty_out(vty, " no neighbor %s send-community large\n",
17238 addr);
17239 }
17240
17241 /* Default information */
17242 if (peergroup_af_flag_check(peer, afi, safi,
17243 PEER_FLAG_DEFAULT_ORIGINATE)) {
17244 vty_out(vty, " neighbor %s default-originate", addr);
17245
17246 if (peer->default_rmap[afi][safi].name)
17247 vty_out(vty, " route-map %s",
17248 peer->default_rmap[afi][safi].name);
17249
17250 vty_out(vty, "\n");
17251 }
17252
17253 /* Soft reconfiguration inbound. */
17254 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17255 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17256 addr);
17257 }
17258
17259 /* maximum-prefix. */
17260 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17261 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17262 peer->pmax[afi][safi]);
17263
17264 if (peer->pmax_threshold[afi][safi]
17265 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17266 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17267 if (peer_af_flag_check(peer, afi, safi,
17268 PEER_FLAG_MAX_PREFIX_WARNING))
17269 vty_out(vty, " warning-only");
17270 if (peer->pmax_restart[afi][safi])
17271 vty_out(vty, " restart %u",
17272 peer->pmax_restart[afi][safi]);
17273 if (peer_af_flag_check(peer, afi, safi,
17274 PEER_FLAG_MAX_PREFIX_FORCE))
17275 vty_out(vty, " force");
17276
17277 vty_out(vty, "\n");
17278 }
17279
17280 /* maximum-prefix-out */
17281 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17282 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17283 addr, peer->pmax_out[afi][safi]);
17284
17285 /* Route server client. */
17286 if (peergroup_af_flag_check(peer, afi, safi,
17287 PEER_FLAG_RSERVER_CLIENT)) {
17288 vty_out(vty, " neighbor %s route-server-client\n", addr);
17289 }
17290
17291 /* Nexthop-local unchanged. */
17292 if (peergroup_af_flag_check(peer, afi, safi,
17293 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17294 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17295 }
17296
17297 /* allowas-in <1-10> */
17298 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17299 if (peer_af_flag_check(peer, afi, safi,
17300 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17301 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17302 } else if (peer->allowas_in[afi][safi] == 3) {
17303 vty_out(vty, " neighbor %s allowas-in\n", addr);
17304 } else {
17305 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17306 peer->allowas_in[afi][safi]);
17307 }
17308 }
17309
17310 /* soo */
17311 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17312 char *soo_str = ecommunity_ecom2str(
17313 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17314
17315 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17316 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17317 }
17318
17319 /* weight */
17320 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17321 vty_out(vty, " neighbor %s weight %lu\n", addr,
17322 peer->weight[afi][safi]);
17323
17324 /* Filter. */
17325 bgp_config_write_filter(vty, peer, afi, safi);
17326
17327 /* atribute-unchanged. */
17328 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17329 || (safi != SAFI_EVPN
17330 && peer_af_flag_check(peer, afi, safi,
17331 PEER_FLAG_NEXTHOP_UNCHANGED))
17332 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17333
17334 if (!peer_group_active(peer)
17335 || peergroup_af_flag_check(peer, afi, safi,
17336 PEER_FLAG_AS_PATH_UNCHANGED)
17337 || peergroup_af_flag_check(peer, afi, safi,
17338 PEER_FLAG_NEXTHOP_UNCHANGED)
17339 || peergroup_af_flag_check(peer, afi, safi,
17340 PEER_FLAG_MED_UNCHANGED)) {
17341
17342 vty_out(vty,
17343 " neighbor %s attribute-unchanged%s%s%s\n",
17344 addr,
17345 peer_af_flag_check(peer, afi, safi,
17346 PEER_FLAG_AS_PATH_UNCHANGED)
17347 ? " as-path"
17348 : "",
17349 peer_af_flag_check(peer, afi, safi,
17350 PEER_FLAG_NEXTHOP_UNCHANGED)
17351 ? " next-hop"
17352 : "",
17353 peer_af_flag_check(peer, afi, safi,
17354 PEER_FLAG_MED_UNCHANGED)
17355 ? " med"
17356 : "");
17357 }
17358 }
17359 }
17360
17361 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17362 safi_t safi)
17363 {
17364 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17365 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17366 vty_out(vty, " no bgp retain route-target all\n");
17367 }
17368
17369 /* Address family based peer configuration display. */
17370 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17371 safi_t safi)
17372 {
17373 struct peer *peer;
17374 struct peer_group *group;
17375 struct listnode *node, *nnode;
17376
17377
17378 vty_frame(vty, " !\n address-family ");
17379 if (afi == AFI_IP) {
17380 if (safi == SAFI_UNICAST)
17381 vty_frame(vty, "ipv4 unicast");
17382 else if (safi == SAFI_LABELED_UNICAST)
17383 vty_frame(vty, "ipv4 labeled-unicast");
17384 else if (safi == SAFI_MULTICAST)
17385 vty_frame(vty, "ipv4 multicast");
17386 else if (safi == SAFI_MPLS_VPN)
17387 vty_frame(vty, "ipv4 vpn");
17388 else if (safi == SAFI_ENCAP)
17389 vty_frame(vty, "ipv4 encap");
17390 else if (safi == SAFI_FLOWSPEC)
17391 vty_frame(vty, "ipv4 flowspec");
17392 } else if (afi == AFI_IP6) {
17393 if (safi == SAFI_UNICAST)
17394 vty_frame(vty, "ipv6 unicast");
17395 else if (safi == SAFI_LABELED_UNICAST)
17396 vty_frame(vty, "ipv6 labeled-unicast");
17397 else if (safi == SAFI_MULTICAST)
17398 vty_frame(vty, "ipv6 multicast");
17399 else if (safi == SAFI_MPLS_VPN)
17400 vty_frame(vty, "ipv6 vpn");
17401 else if (safi == SAFI_ENCAP)
17402 vty_frame(vty, "ipv6 encap");
17403 else if (safi == SAFI_FLOWSPEC)
17404 vty_frame(vty, "ipv6 flowspec");
17405 } else if (afi == AFI_L2VPN) {
17406 if (safi == SAFI_EVPN)
17407 vty_frame(vty, "l2vpn evpn");
17408 }
17409 vty_frame(vty, "\n");
17410
17411 bgp_config_write_distance(vty, bgp, afi, safi);
17412
17413 bgp_config_write_network(vty, bgp, afi, safi);
17414
17415 bgp_config_write_redistribute(vty, bgp, afi, safi);
17416
17417 /* BGP flag dampening. */
17418 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17419 bgp_config_write_damp(vty, afi, safi);
17420
17421 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17422 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17423
17424 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17425 /* Do not display doppelganger peers */
17426 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17427 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17428 }
17429
17430 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17431 bgp_config_write_table_map(vty, bgp, afi, safi);
17432
17433 if (safi == SAFI_EVPN)
17434 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17435
17436 if (safi == SAFI_FLOWSPEC)
17437 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17438
17439 if (safi == SAFI_MPLS_VPN)
17440 bgp_vpn_config_write(vty, bgp, afi, safi);
17441
17442 if (safi == SAFI_UNICAST) {
17443 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17444 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17445 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17446
17447 vty_out(vty, " export vpn\n");
17448 }
17449 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17450 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17451
17452 vty_out(vty, " import vpn\n");
17453 }
17454 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17455 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17456 char *name;
17457
17458 for (ALL_LIST_ELEMENTS_RO(
17459 bgp->vpn_policy[afi].import_vrf, node,
17460 name))
17461 vty_out(vty, " import vrf %s\n", name);
17462 }
17463 }
17464
17465 vty_endframe(vty, " exit-address-family\n");
17466 }
17467
17468 int bgp_config_write(struct vty *vty)
17469 {
17470 struct bgp *bgp;
17471 struct peer_group *group;
17472 struct peer *peer;
17473 struct listnode *node, *nnode;
17474 struct listnode *mnode, *mnnode;
17475 afi_t afi;
17476 safi_t safi;
17477
17478 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17479 vty_out(vty, "bgp route-map delay-timer %u\n",
17480 bm->rmap_update_timer);
17481
17482 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17483 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17484 if (bm->v_update_delay != bm->v_establish_wait)
17485 vty_out(vty, " %d", bm->v_establish_wait);
17486 vty_out(vty, "\n");
17487 }
17488
17489 if (bm->wait_for_fib)
17490 vty_out(vty, "bgp suppress-fib-pending\n");
17491
17492 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17493 vty_out(vty, "bgp graceful-shutdown\n");
17494
17495 /* No-RIB (Zebra) option flag configuration */
17496 if (bgp_option_check(BGP_OPT_NO_FIB))
17497 vty_out(vty, "bgp no-rib\n");
17498
17499 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17500 vty_out(vty, "bgp send-extra-data zebra\n");
17501
17502 /* BGP session DSCP value */
17503 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17504 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17505
17506 /* BGP configuration. */
17507 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17508
17509 /* skip all auto created vrf as they dont have user config */
17510 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17511 continue;
17512
17513 /* Router bgp ASN */
17514 vty_out(vty, "router bgp %u", bgp->as);
17515
17516 if (bgp->name)
17517 vty_out(vty, " %s %s",
17518 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17519 ? "view" : "vrf", bgp->name);
17520 vty_out(vty, "\n");
17521
17522 /* BGP fast-external-failover. */
17523 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17524 vty_out(vty, " no bgp fast-external-failover\n");
17525
17526 /* BGP router ID. */
17527 if (bgp->router_id_static.s_addr != INADDR_ANY)
17528 vty_out(vty, " bgp router-id %pI4\n",
17529 &bgp->router_id_static);
17530
17531 /* Suppress fib pending */
17532 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17533 vty_out(vty, " bgp suppress-fib-pending\n");
17534
17535 /* BGP log-neighbor-changes. */
17536 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17537 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17538 vty_out(vty, " %sbgp log-neighbor-changes\n",
17539 CHECK_FLAG(bgp->flags,
17540 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17541 ? ""
17542 : "no ");
17543
17544 /* BGP configuration. */
17545 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17546 vty_out(vty, " bgp always-compare-med\n");
17547
17548 /* RFC8212 default eBGP policy. */
17549 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17550 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17551 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17552 CHECK_FLAG(bgp->flags,
17553 BGP_FLAG_EBGP_REQUIRES_POLICY)
17554 ? ""
17555 : "no ");
17556
17557 /* draft-ietf-idr-deprecate-as-set-confed-set */
17558 if (bgp->reject_as_sets)
17559 vty_out(vty, " bgp reject-as-sets\n");
17560
17561 /* Suppress duplicate updates if the route actually not changed
17562 */
17563 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17564 != SAVE_BGP_SUPPRESS_DUPLICATES)
17565 vty_out(vty, " %sbgp suppress-duplicates\n",
17566 CHECK_FLAG(bgp->flags,
17567 BGP_FLAG_SUPPRESS_DUPLICATES)
17568 ? ""
17569 : "no ");
17570
17571 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17572 */
17573 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17574 SAVE_BGP_HARD_ADMIN_RESET)
17575 vty_out(vty, " %sbgp hard-administrative-reset\n",
17576 CHECK_FLAG(bgp->flags,
17577 BGP_FLAG_HARD_ADMIN_RESET)
17578 ? ""
17579 : "no ");
17580
17581 /* BGP default <afi>-<safi> */
17582 FOREACH_AFI_SAFI (afi, safi) {
17583 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17584 if (!bgp->default_af[afi][safi])
17585 vty_out(vty, " no bgp default %s\n",
17586 get_bgp_default_af_flag(afi,
17587 safi));
17588 } else if (bgp->default_af[afi][safi])
17589 vty_out(vty, " bgp default %s\n",
17590 get_bgp_default_af_flag(afi, safi));
17591 }
17592
17593 /* BGP default local-preference. */
17594 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17595 vty_out(vty, " bgp default local-preference %u\n",
17596 bgp->default_local_pref);
17597
17598 /* BGP default show-hostname */
17599 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17600 != SAVE_BGP_SHOW_HOSTNAME)
17601 vty_out(vty, " %sbgp default show-hostname\n",
17602 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17603 ? ""
17604 : "no ");
17605
17606 /* BGP default show-nexthop-hostname */
17607 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17608 != SAVE_BGP_SHOW_HOSTNAME)
17609 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17610 CHECK_FLAG(bgp->flags,
17611 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17612 ? ""
17613 : "no ");
17614
17615 /* BGP default subgroup-pkt-queue-max. */
17616 if (bgp->default_subgroup_pkt_queue_max
17617 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17618 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17619 bgp->default_subgroup_pkt_queue_max);
17620
17621 /* BGP client-to-client reflection. */
17622 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17623 vty_out(vty, " no bgp client-to-client reflection\n");
17624
17625 /* BGP cluster ID. */
17626 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17627 vty_out(vty, " bgp cluster-id %pI4\n",
17628 &bgp->cluster_id);
17629
17630 /* Disable ebgp connected nexthop check */
17631 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17632 vty_out(vty,
17633 " bgp disable-ebgp-connected-route-check\n");
17634
17635 /* Confederation identifier*/
17636 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17637 vty_out(vty, " bgp confederation identifier %u\n",
17638 bgp->confed_id);
17639
17640 /* Confederation peer */
17641 if (bgp->confed_peers_cnt > 0) {
17642 int i;
17643
17644 vty_out(vty, " bgp confederation peers");
17645
17646 for (i = 0; i < bgp->confed_peers_cnt; i++)
17647 vty_out(vty, " %u", bgp->confed_peers[i]);
17648
17649 vty_out(vty, "\n");
17650 }
17651
17652 /* BGP deterministic-med. */
17653 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17654 != SAVE_BGP_DETERMINISTIC_MED)
17655 vty_out(vty, " %sbgp deterministic-med\n",
17656 CHECK_FLAG(bgp->flags,
17657 BGP_FLAG_DETERMINISTIC_MED)
17658 ? ""
17659 : "no ");
17660
17661 /* BGP update-delay. */
17662 bgp_config_write_update_delay(vty, bgp);
17663
17664 if (bgp->v_maxmed_onstartup
17665 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17666 vty_out(vty, " bgp max-med on-startup %u",
17667 bgp->v_maxmed_onstartup);
17668 if (bgp->maxmed_onstartup_value
17669 != BGP_MAXMED_VALUE_DEFAULT)
17670 vty_out(vty, " %u",
17671 bgp->maxmed_onstartup_value);
17672 vty_out(vty, "\n");
17673 }
17674 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17675 vty_out(vty, " bgp max-med administrative");
17676 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17677 vty_out(vty, " %u", bgp->maxmed_admin_value);
17678 vty_out(vty, "\n");
17679 }
17680
17681 /* write quanta */
17682 bgp_config_write_wpkt_quanta(vty, bgp);
17683 /* read quanta */
17684 bgp_config_write_rpkt_quanta(vty, bgp);
17685
17686 /* coalesce time */
17687 bgp_config_write_coalesce_time(vty, bgp);
17688
17689 /* BGP per-instance graceful-shutdown */
17690 /* BGP-wide settings and per-instance settings are mutually
17691 * exclusive.
17692 */
17693 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17694 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17695 vty_out(vty, " bgp graceful-shutdown\n");
17696
17697 /* Long-lived Graceful Restart */
17698 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17699 vty_out(vty,
17700 " bgp long-lived-graceful-restart stale-time %u\n",
17701 bgp->llgr_stale_time);
17702
17703 /* BGP graceful-restart. */
17704 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17705 vty_out(vty,
17706 " bgp graceful-restart stalepath-time %u\n",
17707 bgp->stalepath_time);
17708
17709 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17710 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17711 bgp->restart_time);
17712
17713 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17714 SAVE_BGP_GRACEFUL_NOTIFICATION)
17715 vty_out(vty, " %sbgp graceful-restart notification\n",
17716 CHECK_FLAG(bgp->flags,
17717 BGP_FLAG_GRACEFUL_NOTIFICATION)
17718 ? ""
17719 : "no ");
17720
17721 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17722 vty_out(vty,
17723 " bgp graceful-restart select-defer-time %u\n",
17724 bgp->select_defer_time);
17725
17726 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17727 vty_out(vty, " bgp graceful-restart\n");
17728
17729 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17730 vty_out(vty, " bgp graceful-restart-disable\n");
17731
17732 /* BGP graceful-restart Preserve State F bit. */
17733 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17734 vty_out(vty,
17735 " bgp graceful-restart preserve-fw-state\n");
17736
17737 /* BGP TCP keepalive */
17738 bgp_config_tcp_keepalive(vty, bgp);
17739
17740 /* Stale timer for RIB */
17741 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17742 vty_out(vty,
17743 " bgp graceful-restart rib-stale-time %u\n",
17744 bgp->rib_stale_time);
17745
17746 /* BGP bestpath method. */
17747 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17748 vty_out(vty, " bgp bestpath as-path ignore\n");
17749 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17750 vty_out(vty, " bgp bestpath as-path confed\n");
17751
17752 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17753 if (CHECK_FLAG(bgp->flags,
17754 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17755 vty_out(vty,
17756 " bgp bestpath as-path multipath-relax as-set\n");
17757 } else {
17758 vty_out(vty,
17759 " bgp bestpath as-path multipath-relax\n");
17760 }
17761 }
17762
17763 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17764 vty_out(vty,
17765 " bgp route-reflector allow-outbound-policy\n");
17766 }
17767 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17768 vty_out(vty, " bgp bestpath compare-routerid\n");
17769 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17770 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17771 vty_out(vty, " bgp bestpath med");
17772 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17773 vty_out(vty, " confed");
17774 if (CHECK_FLAG(bgp->flags,
17775 BGP_FLAG_MED_MISSING_AS_WORST))
17776 vty_out(vty, " missing-as-worst");
17777 vty_out(vty, "\n");
17778 }
17779
17780 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17781 vty_out(vty,
17782 " bgp bestpath peer-type multipath-relax\n");
17783
17784 /* Link bandwidth handling. */
17785 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17786 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17787 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17788 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17789 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17790 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17791
17792 /* BGP network import check. */
17793 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17794 != SAVE_BGP_IMPORT_CHECK)
17795 vty_out(vty, " %sbgp network import-check\n",
17796 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17797 ? ""
17798 : "no ");
17799
17800 /* BGP timers configuration. */
17801 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17802 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17803 vty_out(vty, " timers bgp %u %u\n",
17804 bgp->default_keepalive, bgp->default_holdtime);
17805
17806 /* BGP minimum holdtime configuration. */
17807 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17808 && bgp->default_min_holdtime != 0)
17809 vty_out(vty, " bgp minimum-holdtime %u\n",
17810 bgp->default_min_holdtime);
17811
17812 /* Conditional advertisement timer configuration */
17813 if (bgp->condition_check_period
17814 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17815 vty_out(vty,
17816 " bgp conditional-advertisement timer %u\n",
17817 bgp->condition_check_period);
17818
17819 /* peer-group */
17820 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17821 bgp_config_write_peer_global(vty, bgp, group->conf);
17822 }
17823
17824 /* Normal neighbor configuration. */
17825 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17826 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17827 bgp_config_write_peer_global(vty, bgp, peer);
17828 }
17829
17830 /* listen range and limit for dynamic BGP neighbors */
17831 bgp_config_write_listen(vty, bgp);
17832
17833 /*
17834 * BGP default autoshutdown neighbors
17835 *
17836 * This must be placed after any peer and peer-group
17837 * configuration, to avoid setting all peers to shutdown after
17838 * a daemon restart, which is undesired behavior. (see #2286)
17839 */
17840 if (bgp->autoshutdown)
17841 vty_out(vty, " bgp default shutdown\n");
17842
17843 /* BGP instance administrative shutdown */
17844 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17845 vty_out(vty, " bgp shutdown\n");
17846
17847 if (bgp->allow_martian)
17848 vty_out(vty, " bgp allow-martian-nexthop\n");
17849
17850 if (bgp->fast_convergence)
17851 vty_out(vty, " bgp fast-convergence\n");
17852
17853 if (bgp->srv6_enabled) {
17854 vty_frame(vty, " !\n segment-routing srv6\n");
17855 if (strlen(bgp->srv6_locator_name))
17856 vty_out(vty, " locator %s\n",
17857 bgp->srv6_locator_name);
17858 vty_endframe(vty, " exit\n");
17859 }
17860
17861
17862 /* IPv4 unicast configuration. */
17863 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17864
17865 /* IPv4 multicast configuration. */
17866 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17867
17868 /* IPv4 labeled-unicast configuration. */
17869 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17870
17871 /* IPv4 VPN configuration. */
17872 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17873
17874 /* ENCAPv4 configuration. */
17875 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17876
17877 /* FLOWSPEC v4 configuration. */
17878 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17879
17880 /* IPv6 unicast configuration. */
17881 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17882
17883 /* IPv6 multicast configuration. */
17884 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17885
17886 /* IPv6 labeled-unicast configuration. */
17887 bgp_config_write_family(vty, bgp, AFI_IP6,
17888 SAFI_LABELED_UNICAST);
17889
17890 /* IPv6 VPN configuration. */
17891 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17892
17893 /* ENCAPv6 configuration. */
17894 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17895
17896 /* FLOWSPEC v6 configuration. */
17897 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17898
17899 /* EVPN configuration. */
17900 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17901
17902 hook_call(bgp_inst_config_write, bgp, vty);
17903
17904 #ifdef ENABLE_BGP_VNC
17905 bgp_rfapi_cfg_write(vty, bgp);
17906 #endif
17907
17908 vty_out(vty, "exit\n");
17909 vty_out(vty, "!\n");
17910 }
17911 return 0;
17912 }
17913
17914
17915 /* BGP node structure. */
17916 static struct cmd_node bgp_node = {
17917 .name = "bgp",
17918 .node = BGP_NODE,
17919 .parent_node = CONFIG_NODE,
17920 .prompt = "%s(config-router)# ",
17921 .config_write = bgp_config_write,
17922 };
17923
17924 static struct cmd_node bgp_ipv4_unicast_node = {
17925 .name = "bgp ipv4 unicast",
17926 .node = BGP_IPV4_NODE,
17927 .parent_node = BGP_NODE,
17928 .prompt = "%s(config-router-af)# ",
17929 .no_xpath = true,
17930 };
17931
17932 static struct cmd_node bgp_ipv4_multicast_node = {
17933 .name = "bgp ipv4 multicast",
17934 .node = BGP_IPV4M_NODE,
17935 .parent_node = BGP_NODE,
17936 .prompt = "%s(config-router-af)# ",
17937 .no_xpath = true,
17938 };
17939
17940 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17941 .name = "bgp ipv4 labeled unicast",
17942 .node = BGP_IPV4L_NODE,
17943 .parent_node = BGP_NODE,
17944 .prompt = "%s(config-router-af)# ",
17945 .no_xpath = true,
17946 };
17947
17948 static struct cmd_node bgp_ipv6_unicast_node = {
17949 .name = "bgp ipv6 unicast",
17950 .node = BGP_IPV6_NODE,
17951 .parent_node = BGP_NODE,
17952 .prompt = "%s(config-router-af)# ",
17953 .no_xpath = true,
17954 };
17955
17956 static struct cmd_node bgp_ipv6_multicast_node = {
17957 .name = "bgp ipv6 multicast",
17958 .node = BGP_IPV6M_NODE,
17959 .parent_node = BGP_NODE,
17960 .prompt = "%s(config-router-af)# ",
17961 .no_xpath = true,
17962 };
17963
17964 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17965 .name = "bgp ipv6 labeled unicast",
17966 .node = BGP_IPV6L_NODE,
17967 .parent_node = BGP_NODE,
17968 .prompt = "%s(config-router-af)# ",
17969 .no_xpath = true,
17970 };
17971
17972 static struct cmd_node bgp_vpnv4_node = {
17973 .name = "bgp vpnv4",
17974 .node = BGP_VPNV4_NODE,
17975 .parent_node = BGP_NODE,
17976 .prompt = "%s(config-router-af)# ",
17977 .no_xpath = true,
17978 };
17979
17980 static struct cmd_node bgp_vpnv6_node = {
17981 .name = "bgp vpnv6",
17982 .node = BGP_VPNV6_NODE,
17983 .parent_node = BGP_NODE,
17984 .prompt = "%s(config-router-af-vpnv6)# ",
17985 .no_xpath = true,
17986 };
17987
17988 static struct cmd_node bgp_evpn_node = {
17989 .name = "bgp evpn",
17990 .node = BGP_EVPN_NODE,
17991 .parent_node = BGP_NODE,
17992 .prompt = "%s(config-router-evpn)# ",
17993 .no_xpath = true,
17994 };
17995
17996 static struct cmd_node bgp_evpn_vni_node = {
17997 .name = "bgp evpn vni",
17998 .node = BGP_EVPN_VNI_NODE,
17999 .parent_node = BGP_EVPN_NODE,
18000 .prompt = "%s(config-router-af-vni)# ",
18001 };
18002
18003 static struct cmd_node bgp_flowspecv4_node = {
18004 .name = "bgp ipv4 flowspec",
18005 .node = BGP_FLOWSPECV4_NODE,
18006 .parent_node = BGP_NODE,
18007 .prompt = "%s(config-router-af)# ",
18008 .no_xpath = true,
18009 };
18010
18011 static struct cmd_node bgp_flowspecv6_node = {
18012 .name = "bgp ipv6 flowspec",
18013 .node = BGP_FLOWSPECV6_NODE,
18014 .parent_node = BGP_NODE,
18015 .prompt = "%s(config-router-af-vpnv6)# ",
18016 .no_xpath = true,
18017 };
18018
18019 static struct cmd_node bgp_srv6_node = {
18020 .name = "bgp srv6",
18021 .node = BGP_SRV6_NODE,
18022 .parent_node = BGP_NODE,
18023 .prompt = "%s(config-router-srv6)# ",
18024 };
18025
18026 static void community_list_vty(void);
18027
18028 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18029 {
18030 struct bgp *bgp;
18031 struct peer_group *group;
18032 struct listnode *lnbgp, *lnpeer;
18033
18034 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18035 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18036 vector_set(comps,
18037 XSTRDUP(MTYPE_COMPLETION, group->name));
18038 }
18039 }
18040
18041 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18042 {
18043 struct bgp *bgp;
18044 struct peer *peer;
18045 struct listnode *lnbgp, *lnpeer;
18046
18047 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18048 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18049 /* only provide suggestions on the appropriate input
18050 * token type,
18051 * they'll otherwise show up multiple times */
18052 enum cmd_token_type match_type;
18053 char *name = peer->host;
18054
18055 if (peer->conf_if) {
18056 match_type = VARIABLE_TKN;
18057 name = peer->conf_if;
18058 } else if (strchr(peer->host, ':'))
18059 match_type = IPV6_TKN;
18060 else
18061 match_type = IPV4_TKN;
18062
18063 if (token->type != match_type)
18064 continue;
18065
18066 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18067 }
18068 }
18069 }
18070
18071 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18072 {
18073 bgp_ac_peer(comps, token);
18074
18075 if (token->type == VARIABLE_TKN)
18076 bgp_ac_peergroup(comps, token);
18077 }
18078
18079 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18080 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18081 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18082 {.varname = "peer", .completions = bgp_ac_neighbor},
18083 {.completions = NULL}};
18084
18085 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18086 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18087 {.completions = NULL} };
18088
18089 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18090
18091 static struct thread *t_bgp_cfg;
18092
18093 bool bgp_config_inprocess(void)
18094 {
18095 return thread_is_scheduled(t_bgp_cfg);
18096 }
18097
18098 static void bgp_config_finish(struct thread *t)
18099 {
18100 struct listnode *node;
18101 struct bgp *bgp;
18102
18103 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18104 hook_call(bgp_config_end, bgp);
18105 }
18106
18107 static void bgp_config_start(void)
18108 {
18109 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18110 THREAD_OFF(t_bgp_cfg);
18111 thread_add_timer(bm->master, bgp_config_finish, NULL,
18112 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18113 }
18114
18115 /* When we receive a hook the configuration is read,
18116 * we start a timer to make sure we postpone sending
18117 * EoR before route-maps are processed.
18118 * This is especially valid if using `bgp route-map delay-timer`.
18119 */
18120 static void bgp_config_end(void)
18121 {
18122 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18123 uint32_t bgp_post_config_delay =
18124 thread_is_scheduled(bm->t_rmap_update)
18125 ? thread_timer_remain_second(bm->t_rmap_update)
18126 : BGP_POST_CONFIG_DELAY_SECONDS;
18127
18128 /* If BGP config processing thread isn't running, then
18129 * we can return and rely it's properly handled.
18130 */
18131 if (!bgp_config_inprocess())
18132 return;
18133
18134 THREAD_OFF(t_bgp_cfg);
18135
18136 /* Start a new timer to make sure we don't send EoR
18137 * before route-maps are processed.
18138 */
18139 thread_add_timer(bm->master, bgp_config_finish, NULL,
18140 bgp_post_config_delay, &t_bgp_cfg);
18141 }
18142
18143 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18144 {
18145 int write = 0;
18146 struct interface *ifp;
18147 struct bgp_interface *iifp;
18148
18149 FOR_ALL_INTERFACES (vrf, ifp) {
18150 iifp = ifp->info;
18151 if (!iifp)
18152 continue;
18153
18154 if_vty_config_start(vty, ifp);
18155
18156 if (CHECK_FLAG(iifp->flags,
18157 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18158 vty_out(vty, " mpls bgp forwarding\n");
18159 write++;
18160 }
18161
18162 if_vty_config_end(vty);
18163 }
18164
18165 return write;
18166 }
18167
18168 /* Configuration write function for bgpd. */
18169 static int config_write_interface(struct vty *vty)
18170 {
18171 int write = 0;
18172 struct vrf *vrf = NULL;
18173
18174 /* Display all VRF aware OSPF interface configuration */
18175 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18176 write += config_write_interface_one(vty, vrf);
18177 }
18178
18179 return write;
18180 }
18181
18182 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18183 "[no$no] mpls bgp forwarding",
18184 NO_STR MPLS_STR BGP_STR
18185 "Enable MPLS forwarding for eBGP directly connected peers\n")
18186 {
18187 bool check;
18188 struct bgp_interface *iifp;
18189
18190 VTY_DECLVAR_CONTEXT(interface, ifp);
18191 iifp = ifp->info;
18192 if (!iifp) {
18193 vty_out(vty, "Interface %s not available\n", ifp->name);
18194 return CMD_WARNING_CONFIG_FAILED;
18195 }
18196 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18197 if (check != !no) {
18198 if (no)
18199 UNSET_FLAG(iifp->flags,
18200 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18201 else
18202 SET_FLAG(iifp->flags,
18203 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18204 /* trigger a nht update on eBGP sessions */
18205 if (if_is_operative(ifp))
18206 bgp_nht_ifp_up(ifp);
18207 }
18208 return CMD_SUCCESS;
18209 }
18210
18211 /* Initialization of BGP interface. */
18212 static void bgp_vty_if_init(void)
18213 {
18214 /* Install interface node. */
18215 if_cmd_init(config_write_interface);
18216
18217 /* "mpls bgp forwarding" commands. */
18218 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18219 }
18220
18221 void bgp_vty_init(void)
18222 {
18223 cmd_variable_handler_register(bgp_var_neighbor);
18224 cmd_variable_handler_register(bgp_var_peergroup);
18225
18226 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18227
18228 /* Install bgp top node. */
18229 install_node(&bgp_node);
18230 install_node(&bgp_ipv4_unicast_node);
18231 install_node(&bgp_ipv4_multicast_node);
18232 install_node(&bgp_ipv4_labeled_unicast_node);
18233 install_node(&bgp_ipv6_unicast_node);
18234 install_node(&bgp_ipv6_multicast_node);
18235 install_node(&bgp_ipv6_labeled_unicast_node);
18236 install_node(&bgp_vpnv4_node);
18237 install_node(&bgp_vpnv6_node);
18238 install_node(&bgp_evpn_node);
18239 install_node(&bgp_evpn_vni_node);
18240 install_node(&bgp_flowspecv4_node);
18241 install_node(&bgp_flowspecv6_node);
18242 install_node(&bgp_srv6_node);
18243
18244 /* Install default VTY commands to new nodes. */
18245 install_default(BGP_NODE);
18246 install_default(BGP_IPV4_NODE);
18247 install_default(BGP_IPV4M_NODE);
18248 install_default(BGP_IPV4L_NODE);
18249 install_default(BGP_IPV6_NODE);
18250 install_default(BGP_IPV6M_NODE);
18251 install_default(BGP_IPV6L_NODE);
18252 install_default(BGP_VPNV4_NODE);
18253 install_default(BGP_VPNV6_NODE);
18254 install_default(BGP_FLOWSPECV4_NODE);
18255 install_default(BGP_FLOWSPECV6_NODE);
18256 install_default(BGP_EVPN_NODE);
18257 install_default(BGP_EVPN_VNI_NODE);
18258 install_default(BGP_SRV6_NODE);
18259
18260 /* "bgp local-mac" hidden commands. */
18261 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18262 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18263
18264 /* "bgp suppress-fib-pending" global */
18265 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18266
18267 /* bgp route-map delay-timer commands. */
18268 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18269 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18270
18271 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18272
18273 /* bgp fast-convergence command */
18274 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18275 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18276
18277 /* global bgp update-delay command */
18278 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18279 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18280
18281 /* global bgp graceful-shutdown command */
18282 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18283 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18284
18285 /* Dummy commands (Currently not supported) */
18286 install_element(BGP_NODE, &no_synchronization_cmd);
18287 install_element(BGP_NODE, &no_auto_summary_cmd);
18288
18289 /* "router bgp" commands. */
18290 install_element(CONFIG_NODE, &router_bgp_cmd);
18291
18292 /* "no router bgp" commands. */
18293 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18294
18295 /* "bgp session-dscp command */
18296 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18297 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18298
18299 /* "bgp router-id" commands. */
18300 install_element(BGP_NODE, &bgp_router_id_cmd);
18301 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18302
18303 /* "bgp suppress-fib-pending" command */
18304 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18305
18306 /* "bgp cluster-id" commands. */
18307 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18308 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18309
18310 /* "bgp no-rib" commands. */
18311 install_element(CONFIG_NODE, &bgp_norib_cmd);
18312 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18313
18314 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18315
18316 /* "bgp confederation" commands. */
18317 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18318 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18319
18320 /* "bgp confederation peers" commands. */
18321 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18322 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18323
18324 /* bgp max-med command */
18325 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18326 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18327 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18328 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18329 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18330
18331 /* "neighbor role" commands. */
18332 install_element(BGP_NODE, &neighbor_role_cmd);
18333 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18334 install_element(BGP_NODE, &no_neighbor_role_cmd);
18335
18336 /* bgp disable-ebgp-connected-nh-check */
18337 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18338 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18339
18340 /* bgp update-delay command */
18341 install_element(BGP_NODE, &bgp_update_delay_cmd);
18342 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18343
18344 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18345 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18346
18347 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18348 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18349
18350 /* "maximum-paths" commands. */
18351 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18352 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18353 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18354 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18355 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18356 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18357 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18358 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18359 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18360 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18361 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18362 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18363 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18364 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18365 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18366
18367 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18368 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18369 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18370 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18371 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18372 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18373 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18374 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18375 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18376 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18377
18378 /* "timers bgp" commands. */
18379 install_element(BGP_NODE, &bgp_timers_cmd);
18380 install_element(BGP_NODE, &no_bgp_timers_cmd);
18381
18382 /* "minimum-holdtime" commands. */
18383 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18384 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18385
18386 /* route-map delay-timer commands - per instance for backwards compat.
18387 */
18388 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18389 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18390
18391 /* "bgp client-to-client reflection" commands */
18392 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18393 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18394
18395 /* "bgp always-compare-med" commands */
18396 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18397 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18398
18399 /* bgp ebgp-requires-policy */
18400 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18401 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18402
18403 /* bgp suppress-duplicates */
18404 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18405 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18406
18407 /* bgp reject-as-sets */
18408 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18409 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18410
18411 /* "bgp deterministic-med" commands */
18412 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18413 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18414
18415 /* "bgp graceful-restart" command */
18416 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18417 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18418
18419 /* "bgp graceful-restart-disable" command */
18420 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18421 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18422
18423 /* "neighbor a:b:c:d graceful-restart" command */
18424 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18425 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18426
18427 /* "neighbor a:b:c:d graceful-restart-disable" command */
18428 install_element(BGP_NODE,
18429 &bgp_neighbor_graceful_restart_disable_set_cmd);
18430 install_element(BGP_NODE,
18431 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18432
18433 /* "neighbor a:b:c:d graceful-restart-helper" command */
18434 install_element(BGP_NODE,
18435 &bgp_neighbor_graceful_restart_helper_set_cmd);
18436 install_element(BGP_NODE,
18437 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18438
18439 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18440 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18441 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18442 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18443 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18444 install_element(BGP_NODE,
18445 &no_bgp_graceful_restart_select_defer_time_cmd);
18446 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18447 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18448 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18449
18450 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18451 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18452 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18453 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18454
18455 /* "bgp graceful-shutdown" commands */
18456 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18457 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18458
18459 /* "bgp hard-administrative-reset" commands */
18460 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18461
18462 /* "bgp long-lived-graceful-restart" commands */
18463 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18464 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18465
18466 /* "bgp fast-external-failover" commands */
18467 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18468 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18469
18470 /* "bgp bestpath compare-routerid" commands */
18471 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18472 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18473
18474 /* "bgp bestpath as-path ignore" commands */
18475 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18476 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18477
18478 /* "bgp bestpath as-path confed" commands */
18479 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18480 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18481
18482 /* "bgp bestpath as-path multipath-relax" commands */
18483 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18484 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18485
18486 /* "bgp bestpath peer-type multipath-relax" commands */
18487 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18488 install_element(BGP_NODE,
18489 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18490
18491 /* "bgp log-neighbor-changes" commands */
18492 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18493 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18494
18495 /* "bgp bestpath med" commands */
18496 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18497 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18498
18499 /* "bgp bestpath bandwidth" commands */
18500 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18501 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18502
18503 /* "no bgp default <afi>-<safi>" commands. */
18504 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18505
18506 /* "bgp network import-check" commands. */
18507 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18508 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18509 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18510
18511 /* "bgp default local-preference" commands. */
18512 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18513 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18514
18515 /* bgp default show-hostname */
18516 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18517 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18518
18519 /* bgp default show-nexthop-hostname */
18520 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18521 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18522
18523 /* "bgp default subgroup-pkt-queue-max" commands. */
18524 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18525 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18526
18527 /* bgp ibgp-allow-policy-mods command */
18528 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18529 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18530
18531 /* "bgp listen limit" commands. */
18532 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18533 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18534
18535 /* "bgp listen range" commands. */
18536 install_element(BGP_NODE, &bgp_listen_range_cmd);
18537 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18538
18539 /* "bgp default shutdown" command */
18540 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18541
18542 /* "bgp shutdown" commands */
18543 install_element(BGP_NODE, &bgp_shutdown_cmd);
18544 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18545 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18546 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18547
18548 /* "neighbor remote-as" commands. */
18549 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18550 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18551 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18552 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18553 install_element(BGP_NODE,
18554 &neighbor_interface_v6only_config_remote_as_cmd);
18555 install_element(BGP_NODE, &no_neighbor_cmd);
18556 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18557
18558 /* "neighbor peer-group" commands. */
18559 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18560 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18561 install_element(BGP_NODE,
18562 &no_neighbor_interface_peer_group_remote_as_cmd);
18563
18564 /* "neighbor local-as" commands. */
18565 install_element(BGP_NODE, &neighbor_local_as_cmd);
18566 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18567 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18568 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18569
18570 /* "neighbor solo" commands. */
18571 install_element(BGP_NODE, &neighbor_solo_cmd);
18572 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18573
18574 /* "neighbor password" commands. */
18575 install_element(BGP_NODE, &neighbor_password_cmd);
18576 install_element(BGP_NODE, &no_neighbor_password_cmd);
18577
18578 /* "neighbor activate" commands. */
18579 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18580 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18581 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18582 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18583 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18584 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18585 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18586 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18587 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18588 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18589 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18590 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18591
18592 /* "no neighbor activate" commands. */
18593 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18594 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18595 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18596 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18597 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18598 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18599 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18600 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18601 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18602 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18603 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18604 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18605
18606 /* "neighbor peer-group" set commands. */
18607 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18608 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18609 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18610 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18611 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18612 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18613 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18614 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18615 install_element(BGP_FLOWSPECV4_NODE,
18616 &neighbor_set_peer_group_hidden_cmd);
18617 install_element(BGP_FLOWSPECV6_NODE,
18618 &neighbor_set_peer_group_hidden_cmd);
18619
18620 /* "no neighbor peer-group unset" commands. */
18621 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18622 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18623 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18624 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18625 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18626 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18627 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18628 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18629 install_element(BGP_FLOWSPECV4_NODE,
18630 &no_neighbor_set_peer_group_hidden_cmd);
18631 install_element(BGP_FLOWSPECV6_NODE,
18632 &no_neighbor_set_peer_group_hidden_cmd);
18633
18634 /* "neighbor softreconfiguration inbound" commands.*/
18635 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18636 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18637 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18638 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18639 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18640 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18641 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18642 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18643 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18644 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18645 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18646 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18647 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18648 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18649 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18650 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18651 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18652 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18653 install_element(BGP_FLOWSPECV4_NODE,
18654 &neighbor_soft_reconfiguration_cmd);
18655 install_element(BGP_FLOWSPECV4_NODE,
18656 &no_neighbor_soft_reconfiguration_cmd);
18657 install_element(BGP_FLOWSPECV6_NODE,
18658 &neighbor_soft_reconfiguration_cmd);
18659 install_element(BGP_FLOWSPECV6_NODE,
18660 &no_neighbor_soft_reconfiguration_cmd);
18661 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18662 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18663
18664 /* "neighbor attribute-unchanged" commands. */
18665 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18666 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18667 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18668 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18669 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18670 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18671 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18672 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18673 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18674 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18675 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18676 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18677 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18678 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18679 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18680 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18681 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18682 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18683
18684 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18685 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18686
18687 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18688 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18689 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18690 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18691
18692 /* "nexthop-local unchanged" commands */
18693 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18694 install_element(BGP_IPV6_NODE,
18695 &no_neighbor_nexthop_local_unchanged_cmd);
18696
18697 /* "neighbor next-hop-self" commands. */
18698 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18699 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18700 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18701 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18702 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18703 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18704 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18705 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18706 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18707 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18708 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18709 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18710 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18711 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18712 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18713 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18714 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18715 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18716 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18717 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18718
18719 /* "neighbor next-hop-self force" commands. */
18720 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18721 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18722 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18723 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18724 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18725 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18726 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18727 install_element(BGP_IPV4_NODE,
18728 &no_neighbor_nexthop_self_all_hidden_cmd);
18729 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18730 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18731 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18732 install_element(BGP_IPV4M_NODE,
18733 &no_neighbor_nexthop_self_all_hidden_cmd);
18734 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18735 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18736 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18737 install_element(BGP_IPV4L_NODE,
18738 &no_neighbor_nexthop_self_all_hidden_cmd);
18739 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18740 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18741 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18742 install_element(BGP_IPV6_NODE,
18743 &no_neighbor_nexthop_self_all_hidden_cmd);
18744 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18745 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18746 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18747 install_element(BGP_IPV6M_NODE,
18748 &no_neighbor_nexthop_self_all_hidden_cmd);
18749 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18750 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18751 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18752 install_element(BGP_IPV6L_NODE,
18753 &no_neighbor_nexthop_self_all_hidden_cmd);
18754 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18755 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18756 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18757 install_element(BGP_VPNV4_NODE,
18758 &no_neighbor_nexthop_self_all_hidden_cmd);
18759 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18760 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18761 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18762 install_element(BGP_VPNV6_NODE,
18763 &no_neighbor_nexthop_self_all_hidden_cmd);
18764 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18765 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18766
18767 /* "neighbor as-override" commands. */
18768 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18769 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18770 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18771 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18772 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18773 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18774 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18775 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18776 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18777 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18778 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18779 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18780 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18781 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18782 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18783 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18784 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18785 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18786
18787 /* "neighbor remove-private-AS" commands. */
18788 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18789 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18790 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18791 install_element(BGP_NODE,
18792 &no_neighbor_remove_private_as_all_hidden_cmd);
18793 install_element(BGP_NODE,
18794 &neighbor_remove_private_as_replace_as_hidden_cmd);
18795 install_element(BGP_NODE,
18796 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18797 install_element(BGP_NODE,
18798 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18799 install_element(
18800 BGP_NODE,
18801 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18802 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18803 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18804 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18805 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18806 install_element(BGP_IPV4_NODE,
18807 &neighbor_remove_private_as_replace_as_cmd);
18808 install_element(BGP_IPV4_NODE,
18809 &no_neighbor_remove_private_as_replace_as_cmd);
18810 install_element(BGP_IPV4_NODE,
18811 &neighbor_remove_private_as_all_replace_as_cmd);
18812 install_element(BGP_IPV4_NODE,
18813 &no_neighbor_remove_private_as_all_replace_as_cmd);
18814 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18815 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18816 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18817 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18818 install_element(BGP_IPV4M_NODE,
18819 &neighbor_remove_private_as_replace_as_cmd);
18820 install_element(BGP_IPV4M_NODE,
18821 &no_neighbor_remove_private_as_replace_as_cmd);
18822 install_element(BGP_IPV4M_NODE,
18823 &neighbor_remove_private_as_all_replace_as_cmd);
18824 install_element(BGP_IPV4M_NODE,
18825 &no_neighbor_remove_private_as_all_replace_as_cmd);
18826 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18827 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18828 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18829 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18830 install_element(BGP_IPV4L_NODE,
18831 &neighbor_remove_private_as_replace_as_cmd);
18832 install_element(BGP_IPV4L_NODE,
18833 &no_neighbor_remove_private_as_replace_as_cmd);
18834 install_element(BGP_IPV4L_NODE,
18835 &neighbor_remove_private_as_all_replace_as_cmd);
18836 install_element(BGP_IPV4L_NODE,
18837 &no_neighbor_remove_private_as_all_replace_as_cmd);
18838 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18839 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18840 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18841 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18842 install_element(BGP_IPV6_NODE,
18843 &neighbor_remove_private_as_replace_as_cmd);
18844 install_element(BGP_IPV6_NODE,
18845 &no_neighbor_remove_private_as_replace_as_cmd);
18846 install_element(BGP_IPV6_NODE,
18847 &neighbor_remove_private_as_all_replace_as_cmd);
18848 install_element(BGP_IPV6_NODE,
18849 &no_neighbor_remove_private_as_all_replace_as_cmd);
18850 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18851 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18852 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18853 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18854 install_element(BGP_IPV6M_NODE,
18855 &neighbor_remove_private_as_replace_as_cmd);
18856 install_element(BGP_IPV6M_NODE,
18857 &no_neighbor_remove_private_as_replace_as_cmd);
18858 install_element(BGP_IPV6M_NODE,
18859 &neighbor_remove_private_as_all_replace_as_cmd);
18860 install_element(BGP_IPV6M_NODE,
18861 &no_neighbor_remove_private_as_all_replace_as_cmd);
18862 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18863 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18864 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18865 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18866 install_element(BGP_IPV6L_NODE,
18867 &neighbor_remove_private_as_replace_as_cmd);
18868 install_element(BGP_IPV6L_NODE,
18869 &no_neighbor_remove_private_as_replace_as_cmd);
18870 install_element(BGP_IPV6L_NODE,
18871 &neighbor_remove_private_as_all_replace_as_cmd);
18872 install_element(BGP_IPV6L_NODE,
18873 &no_neighbor_remove_private_as_all_replace_as_cmd);
18874 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18875 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18876 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18877 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18878 install_element(BGP_VPNV4_NODE,
18879 &neighbor_remove_private_as_replace_as_cmd);
18880 install_element(BGP_VPNV4_NODE,
18881 &no_neighbor_remove_private_as_replace_as_cmd);
18882 install_element(BGP_VPNV4_NODE,
18883 &neighbor_remove_private_as_all_replace_as_cmd);
18884 install_element(BGP_VPNV4_NODE,
18885 &no_neighbor_remove_private_as_all_replace_as_cmd);
18886 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18887 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18888 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18889 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18890 install_element(BGP_VPNV6_NODE,
18891 &neighbor_remove_private_as_replace_as_cmd);
18892 install_element(BGP_VPNV6_NODE,
18893 &no_neighbor_remove_private_as_replace_as_cmd);
18894 install_element(BGP_VPNV6_NODE,
18895 &neighbor_remove_private_as_all_replace_as_cmd);
18896 install_element(BGP_VPNV6_NODE,
18897 &no_neighbor_remove_private_as_all_replace_as_cmd);
18898
18899 /* "neighbor send-community" commands.*/
18900 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18901 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18902 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18903 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18904 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18905 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18906 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18907 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18908 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18909 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18910 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18911 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18912 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18913 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18914 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18915 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18916 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18917 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18918 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18919 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18920 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18921 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18922 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18923 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18924 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18925 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18926 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18927 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18928 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18929 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18930 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18931 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18932 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18933 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18934 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18935 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18936
18937 /* "neighbor route-reflector" commands.*/
18938 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18939 install_element(BGP_NODE,
18940 &no_neighbor_route_reflector_client_hidden_cmd);
18941 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18942 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18943 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18944 install_element(BGP_IPV4M_NODE,
18945 &no_neighbor_route_reflector_client_cmd);
18946 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18947 install_element(BGP_IPV4L_NODE,
18948 &no_neighbor_route_reflector_client_cmd);
18949 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18950 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18951 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18952 install_element(BGP_IPV6M_NODE,
18953 &no_neighbor_route_reflector_client_cmd);
18954 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18955 install_element(BGP_IPV6L_NODE,
18956 &no_neighbor_route_reflector_client_cmd);
18957 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18958 install_element(BGP_VPNV4_NODE,
18959 &no_neighbor_route_reflector_client_cmd);
18960 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18961 install_element(BGP_VPNV6_NODE,
18962 &no_neighbor_route_reflector_client_cmd);
18963 install_element(BGP_FLOWSPECV4_NODE,
18964 &neighbor_route_reflector_client_cmd);
18965 install_element(BGP_FLOWSPECV4_NODE,
18966 &no_neighbor_route_reflector_client_cmd);
18967 install_element(BGP_FLOWSPECV6_NODE,
18968 &neighbor_route_reflector_client_cmd);
18969 install_element(BGP_FLOWSPECV6_NODE,
18970 &no_neighbor_route_reflector_client_cmd);
18971 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18972 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18973
18974 /* "neighbor route-server" commands.*/
18975 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18976 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18977 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18978 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18979 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18980 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18981 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18982 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18983 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18984 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18985 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18986 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18987 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18988 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18989 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18990 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18991 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18992 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18993 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18994 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18995 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18996 install_element(BGP_FLOWSPECV4_NODE,
18997 &no_neighbor_route_server_client_cmd);
18998 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18999 install_element(BGP_FLOWSPECV6_NODE,
19000 &no_neighbor_route_server_client_cmd);
19001
19002 /* "neighbor disable-addpath-rx" commands. */
19003 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19004 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19005 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19006 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19007 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19008 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19009 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19010 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19011 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19012 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19013 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19014 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19015 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19016 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19017 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19018 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19019
19020 /* "neighbor addpath-tx-all-paths" commands.*/
19021 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19022 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19023 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19024 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19025 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19026 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19027 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19028 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19029 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19030 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19031 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19032 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19033 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19034 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19035 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19036 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19037 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19038 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19039
19040 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19041 install_element(BGP_NODE,
19042 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19043 install_element(BGP_NODE,
19044 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19045 install_element(BGP_IPV4_NODE,
19046 &neighbor_addpath_tx_bestpath_per_as_cmd);
19047 install_element(BGP_IPV4_NODE,
19048 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19049 install_element(BGP_IPV4M_NODE,
19050 &neighbor_addpath_tx_bestpath_per_as_cmd);
19051 install_element(BGP_IPV4M_NODE,
19052 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19053 install_element(BGP_IPV4L_NODE,
19054 &neighbor_addpath_tx_bestpath_per_as_cmd);
19055 install_element(BGP_IPV4L_NODE,
19056 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19057 install_element(BGP_IPV6_NODE,
19058 &neighbor_addpath_tx_bestpath_per_as_cmd);
19059 install_element(BGP_IPV6_NODE,
19060 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19061 install_element(BGP_IPV6M_NODE,
19062 &neighbor_addpath_tx_bestpath_per_as_cmd);
19063 install_element(BGP_IPV6M_NODE,
19064 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19065 install_element(BGP_IPV6L_NODE,
19066 &neighbor_addpath_tx_bestpath_per_as_cmd);
19067 install_element(BGP_IPV6L_NODE,
19068 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19069 install_element(BGP_VPNV4_NODE,
19070 &neighbor_addpath_tx_bestpath_per_as_cmd);
19071 install_element(BGP_VPNV4_NODE,
19072 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19073 install_element(BGP_VPNV6_NODE,
19074 &neighbor_addpath_tx_bestpath_per_as_cmd);
19075 install_element(BGP_VPNV6_NODE,
19076 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19077
19078 /* "neighbor sender-as-path-loop-detection" commands. */
19079 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19080 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19081
19082 /* "neighbor passive" commands. */
19083 install_element(BGP_NODE, &neighbor_passive_cmd);
19084 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19085
19086
19087 /* "neighbor shutdown" commands. */
19088 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19089 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19090 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19091 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19092 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19093 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19094
19095 /* "neighbor capability extended-nexthop" commands.*/
19096 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19097 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19098
19099 /* "neighbor capability orf prefix-list" commands.*/
19100 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19101 install_element(BGP_NODE,
19102 &no_neighbor_capability_orf_prefix_hidden_cmd);
19103 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19104 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19105 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19106 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19107 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19108 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19109 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19110 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19111 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19112 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19113 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19114 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19115
19116 /* "neighbor capability dynamic" commands.*/
19117 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19118 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19119
19120 /* "neighbor dont-capability-negotiate" commands. */
19121 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19122 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19123
19124 /* "neighbor ebgp-multihop" commands. */
19125 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19126 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19127 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19128
19129 /* "neighbor disable-connected-check" commands. */
19130 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19131 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19132
19133 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19134 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19135 install_element(BGP_NODE,
19136 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19137
19138 /* "neighbor extended-optional-parameters" commands. */
19139 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19140 install_element(BGP_NODE,
19141 &no_neighbor_extended_optional_parameters_cmd);
19142
19143 /* "neighbor enforce-first-as" commands. */
19144 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19145 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19146
19147 /* "neighbor description" commands. */
19148 install_element(BGP_NODE, &neighbor_description_cmd);
19149 install_element(BGP_NODE, &no_neighbor_description_cmd);
19150 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19151
19152 /* "neighbor update-source" commands. "*/
19153 install_element(BGP_NODE, &neighbor_update_source_cmd);
19154 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19155
19156 /* "neighbor default-originate" commands. */
19157 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19158 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19159 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19160 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19161 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19162 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19163 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19164 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19165 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19166 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19167 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19168 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19169 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19170 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19171 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19172 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19173 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19174 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19175 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19176 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19177 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19178
19179 /* "neighbor port" commands. */
19180 install_element(BGP_NODE, &neighbor_port_cmd);
19181 install_element(BGP_NODE, &no_neighbor_port_cmd);
19182
19183 /* "neighbor weight" commands. */
19184 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19185 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19186
19187 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19188 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19189 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19190 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19191 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19192 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19193 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19194 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19195 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19196 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19197 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19198 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19199 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19200 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19201 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19202 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19203
19204 /* "neighbor override-capability" commands. */
19205 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19206 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19207
19208 /* "neighbor strict-capability-match" commands. */
19209 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19210 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19211
19212 /* "neighbor timers" commands. */
19213 install_element(BGP_NODE, &neighbor_timers_cmd);
19214 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19215
19216 /* "neighbor timers connect" commands. */
19217 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19218 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19219
19220 /* "neighbor timers delayopen" commands. */
19221 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19222 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19223
19224 /* "neighbor advertisement-interval" commands. */
19225 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19226 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19227
19228 /* "neighbor interface" commands. */
19229 install_element(BGP_NODE, &neighbor_interface_cmd);
19230 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19231
19232 /* "neighbor distribute" commands. */
19233 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19234 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19235 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19236 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19237 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19238 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19239 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19240 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19241 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19242 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19243 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19244 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19245 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19246 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19247 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19248 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19249 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19250 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19251
19252 /* "neighbor prefix-list" commands. */
19253 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19254 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19255 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19256 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19257 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19258 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19259 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19260 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19261 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19262 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19263 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19264 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19265 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19266 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19267 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19268 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19269 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19270 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19271 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19272 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19273 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19274 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19275
19276 /* "neighbor filter-list" commands. */
19277 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19278 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19279 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19280 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19281 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19282 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19283 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19284 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19285 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19286 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19287 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19288 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19289 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19290 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19291 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19292 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19293 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19294 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19295 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19296 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19297 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19298 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19299
19300 /* "neighbor route-map" commands. */
19301 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19302 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19303 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19304 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19305 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19306 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19307 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19308 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19309 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19310 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19311 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19312 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19313 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19314 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19315 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19316 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19317 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19318 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19319 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19320 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19321 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19322 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19323 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19324 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19325
19326 /* "neighbor unsuppress-map" commands. */
19327 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19328 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19329 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19330 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19331 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19332 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19333 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19334 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19335 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19336 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19337 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19338 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19339 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19340 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19341 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19342 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19343 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19344 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19345
19346 /* "neighbor advertise-map" commands. */
19347 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19348 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19349 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19350 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19351 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19352 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19353 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19354 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19355 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19356 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19357
19358 /* neighbor maximum-prefix-out commands. */
19359 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19360 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19361 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19362 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19363 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19364 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19365 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19366 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19367 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19368 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19369 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19370 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19371 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19372 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19373 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19374 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19375 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19376 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19377
19378 /* "neighbor maximum-prefix" commands. */
19379 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19380 install_element(BGP_NODE,
19381 &neighbor_maximum_prefix_threshold_hidden_cmd);
19382 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19383 install_element(BGP_NODE,
19384 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19385 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19386 install_element(BGP_NODE,
19387 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19388 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19389 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19390 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19391 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19392 install_element(BGP_IPV4_NODE,
19393 &neighbor_maximum_prefix_threshold_warning_cmd);
19394 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19395 install_element(BGP_IPV4_NODE,
19396 &neighbor_maximum_prefix_threshold_restart_cmd);
19397 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19398 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19399 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19400 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19401 install_element(BGP_IPV4M_NODE,
19402 &neighbor_maximum_prefix_threshold_warning_cmd);
19403 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19404 install_element(BGP_IPV4M_NODE,
19405 &neighbor_maximum_prefix_threshold_restart_cmd);
19406 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19407 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19408 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19409 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19410 install_element(BGP_IPV4L_NODE,
19411 &neighbor_maximum_prefix_threshold_warning_cmd);
19412 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19413 install_element(BGP_IPV4L_NODE,
19414 &neighbor_maximum_prefix_threshold_restart_cmd);
19415 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19416 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19417 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19418 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19419 install_element(BGP_IPV6_NODE,
19420 &neighbor_maximum_prefix_threshold_warning_cmd);
19421 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19422 install_element(BGP_IPV6_NODE,
19423 &neighbor_maximum_prefix_threshold_restart_cmd);
19424 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19425 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19426 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19427 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19428 install_element(BGP_IPV6M_NODE,
19429 &neighbor_maximum_prefix_threshold_warning_cmd);
19430 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19431 install_element(BGP_IPV6M_NODE,
19432 &neighbor_maximum_prefix_threshold_restart_cmd);
19433 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19434 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19435 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19436 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19437 install_element(BGP_IPV6L_NODE,
19438 &neighbor_maximum_prefix_threshold_warning_cmd);
19439 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19440 install_element(BGP_IPV6L_NODE,
19441 &neighbor_maximum_prefix_threshold_restart_cmd);
19442 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19443 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19444 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19445 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19446 install_element(BGP_VPNV4_NODE,
19447 &neighbor_maximum_prefix_threshold_warning_cmd);
19448 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19449 install_element(BGP_VPNV4_NODE,
19450 &neighbor_maximum_prefix_threshold_restart_cmd);
19451 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19452 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19453 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19454 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19455 install_element(BGP_VPNV6_NODE,
19456 &neighbor_maximum_prefix_threshold_warning_cmd);
19457 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19458 install_element(BGP_VPNV6_NODE,
19459 &neighbor_maximum_prefix_threshold_restart_cmd);
19460 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19461
19462 /* "neighbor allowas-in" */
19463 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19464 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19465 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19466 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19467 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19468 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19469 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19470 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19471 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19472 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19473 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19474 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19475 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19476 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19477 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19478 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19479 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19480 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19481 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19482 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19483
19484 /* "neighbor soo" */
19485 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19486 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19487 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19488 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19489 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19490 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19491 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19492 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19493 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19494 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19495 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19496 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19497 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19498 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19499 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19500 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19501 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19502 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19503
19504 /* address-family commands. */
19505 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19506 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19507 #ifdef KEEP_OLD_VPN_COMMANDS
19508 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19509 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19510 #endif /* KEEP_OLD_VPN_COMMANDS */
19511
19512 install_element(BGP_NODE, &address_family_evpn_cmd);
19513
19514 /* "exit-address-family" command. */
19515 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19516 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19517 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19518 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19519 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19520 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19521 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19522 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19523 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19524 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19525 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19526
19527 /* BGP retain all route-target */
19528 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19529 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19530
19531 /* "clear ip bgp commands" */
19532 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19533
19534 /* clear ip bgp prefix */
19535 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19536 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19537 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19538
19539 /* "show [ip] bgp summary" commands. */
19540 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19541 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19542 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19543 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19544 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19545 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19546 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19547
19548 /* "show [ip] bgp neighbors" commands. */
19549 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19550
19551 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19552
19553 /* "show [ip] bgp peer-group" commands. */
19554 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19555
19556 /* "show [ip] bgp paths" commands. */
19557 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19558
19559 /* "show [ip] bgp community" commands. */
19560 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19561
19562 /* "show ip bgp large-community" commands. */
19563 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19564 /* "show [ip] bgp attribute-info" commands. */
19565 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19566 /* "show [ip] bgp route-leak" command */
19567 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19568
19569 /* "redistribute" commands. */
19570 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19571 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19572 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19573 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19574 install_element(BGP_NODE,
19575 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19576 install_element(BGP_NODE,
19577 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19578 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19579 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19580 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19581 install_element(BGP_NODE,
19582 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19583 install_element(BGP_NODE,
19584 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19585 install_element(BGP_NODE,
19586 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19587 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19588 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19589 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19590 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19591 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19592 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19593 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19594 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19595 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19596 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19597 install_element(BGP_IPV4_NODE,
19598 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19599 install_element(BGP_IPV4_NODE,
19600 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19601 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19602 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19603 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19604 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19605 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19606 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19607
19608 /* import|export vpn [route-map RMAP_NAME] */
19609 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19610 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19611
19612 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19613 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19614
19615 /* ttl_security commands */
19616 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19617 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19618
19619 /* "bgp tcp-keepalive" commands */
19620 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
19621 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
19622
19623 /* "show [ip] bgp memory" commands. */
19624 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19625
19626 /* "show bgp martian next-hop" */
19627 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19628
19629 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19630
19631 /* "show [ip] bgp views" commands. */
19632 install_element(VIEW_NODE, &show_bgp_views_cmd);
19633
19634 /* "show [ip] bgp vrfs" commands. */
19635 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19636
19637 /* Community-list. */
19638 community_list_vty();
19639
19640 community_alias_vty();
19641
19642 /* vpn-policy commands */
19643 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19644 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19645 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19646 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19647 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19648 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19649 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19650 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19651 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19652 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19653 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19654 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19655
19656 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19657 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19658
19659 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19660 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19661 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19662 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19663 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19664 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19665 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19666 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19667 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19668 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19669
19670 /* tcp-mss command */
19671 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19672 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19673
19674 /* srv6 commands */
19675 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19676 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19677 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19678 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19679 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19680 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19681 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19682
19683 bgp_vty_if_init();
19684 }
19685
19686 #include "memory.h"
19687 #include "bgp_regex.h"
19688 #include "bgp_clist.h"
19689 #include "bgp_ecommunity.h"
19690
19691 /* VTY functions. */
19692
19693 /* Direction value to string conversion. */
19694 static const char *community_direct_str(int direct)
19695 {
19696 switch (direct) {
19697 case COMMUNITY_DENY:
19698 return "deny";
19699 case COMMUNITY_PERMIT:
19700 return "permit";
19701 default:
19702 return "unknown";
19703 }
19704 }
19705
19706 /* Display error string. */
19707 static void community_list_perror(struct vty *vty, int ret)
19708 {
19709 switch (ret) {
19710 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19711 vty_out(vty, "%% Can't find community-list\n");
19712 break;
19713 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19714 vty_out(vty, "%% Malformed community-list value\n");
19715 break;
19716 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19717 vty_out(vty,
19718 "%% Community name conflict, previously defined as standard community\n");
19719 break;
19720 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19721 vty_out(vty,
19722 "%% Community name conflict, previously defined as expanded community\n");
19723 break;
19724 }
19725 }
19726
19727 /* "community-list" keyword help string. */
19728 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19729
19730 /*community-list standard */
19731 DEFUN (community_list_standard,
19732 bgp_community_list_standard_cmd,
19733 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19734 BGP_STR
19735 COMMUNITY_LIST_STR
19736 "Community list number (standard)\n"
19737 "Add an standard community-list entry\n"
19738 "Community list name\n"
19739 "Sequence number of an entry\n"
19740 "Sequence number\n"
19741 "Specify community to reject\n"
19742 "Specify community to accept\n"
19743 COMMUNITY_VAL_STR)
19744 {
19745 char *cl_name_or_number = NULL;
19746 char *seq = NULL;
19747 int direct = 0;
19748 int style = COMMUNITY_LIST_STANDARD;
19749 int idx = 0;
19750
19751 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19752 seq = argv[idx]->arg;
19753
19754 idx = 0;
19755 argv_find(argv, argc, "(1-99)", &idx);
19756 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19757 cl_name_or_number = argv[idx]->arg;
19758 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19759 : COMMUNITY_DENY;
19760 argv_find(argv, argc, "AA:NN", &idx);
19761 char *str = argv_concat(argv, argc, idx);
19762
19763 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19764 direct, style);
19765
19766 XFREE(MTYPE_TMP, str);
19767
19768 if (ret < 0) {
19769 /* Display error string. */
19770 community_list_perror(vty, ret);
19771 return CMD_WARNING_CONFIG_FAILED;
19772 }
19773
19774 return CMD_SUCCESS;
19775 }
19776
19777 DEFUN (no_community_list_standard_all,
19778 no_bgp_community_list_standard_all_cmd,
19779 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19780 NO_STR
19781 BGP_STR
19782 COMMUNITY_LIST_STR
19783 "Community list number (standard)\n"
19784 "Add an standard community-list entry\n"
19785 "Community list name\n"
19786 "Sequence number of an entry\n"
19787 "Sequence number\n"
19788 "Specify community to reject\n"
19789 "Specify community to accept\n"
19790 COMMUNITY_VAL_STR)
19791 {
19792 char *cl_name_or_number = NULL;
19793 char *str = NULL;
19794 int direct = 0;
19795 int style = COMMUNITY_LIST_STANDARD;
19796 char *seq = NULL;
19797 int idx = 0;
19798
19799 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19800 seq = argv[idx]->arg;
19801
19802 idx = 0;
19803 argv_find(argv, argc, "permit", &idx);
19804 argv_find(argv, argc, "deny", &idx);
19805
19806 if (idx) {
19807 direct = argv_find(argv, argc, "permit", &idx)
19808 ? COMMUNITY_PERMIT
19809 : COMMUNITY_DENY;
19810
19811 idx = 0;
19812 argv_find(argv, argc, "AA:NN", &idx);
19813 str = argv_concat(argv, argc, idx);
19814 }
19815
19816 idx = 0;
19817 argv_find(argv, argc, "(1-99)", &idx);
19818 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19819 cl_name_or_number = argv[idx]->arg;
19820
19821 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19822 direct, style);
19823
19824 XFREE(MTYPE_TMP, str);
19825
19826 if (ret < 0) {
19827 community_list_perror(vty, ret);
19828 return CMD_WARNING_CONFIG_FAILED;
19829 }
19830
19831 return CMD_SUCCESS;
19832 }
19833
19834 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19835 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19836 NO_STR BGP_STR COMMUNITY_LIST_STR
19837 "Community list number (standard)\n"
19838 "Add an standard community-list entry\n"
19839 "Community list name\n")
19840
19841 /*community-list expanded */
19842 DEFUN (community_list_expanded_all,
19843 bgp_community_list_expanded_all_cmd,
19844 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19845 BGP_STR
19846 COMMUNITY_LIST_STR
19847 "Community list number (expanded)\n"
19848 "Add an expanded community-list entry\n"
19849 "Community list name\n"
19850 "Sequence number of an entry\n"
19851 "Sequence number\n"
19852 "Specify community to reject\n"
19853 "Specify community to accept\n"
19854 COMMUNITY_VAL_STR)
19855 {
19856 char *cl_name_or_number = NULL;
19857 char *seq = NULL;
19858 int direct = 0;
19859 int style = COMMUNITY_LIST_EXPANDED;
19860 int idx = 0;
19861
19862 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19863 seq = argv[idx]->arg;
19864
19865 idx = 0;
19866
19867 argv_find(argv, argc, "(100-500)", &idx);
19868 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19869 cl_name_or_number = argv[idx]->arg;
19870 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19871 : COMMUNITY_DENY;
19872 argv_find(argv, argc, "AA:NN", &idx);
19873 char *str = argv_concat(argv, argc, idx);
19874
19875 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19876 direct, style);
19877
19878 XFREE(MTYPE_TMP, str);
19879
19880 if (ret < 0) {
19881 /* Display error string. */
19882 community_list_perror(vty, ret);
19883 return CMD_WARNING_CONFIG_FAILED;
19884 }
19885
19886 return CMD_SUCCESS;
19887 }
19888
19889 DEFUN (no_community_list_expanded_all,
19890 no_bgp_community_list_expanded_all_cmd,
19891 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19892 NO_STR
19893 BGP_STR
19894 COMMUNITY_LIST_STR
19895 "Community list number (expanded)\n"
19896 "Add an expanded community-list entry\n"
19897 "Community list name\n"
19898 "Sequence number of an entry\n"
19899 "Sequence number\n"
19900 "Specify community to reject\n"
19901 "Specify community to accept\n"
19902 COMMUNITY_VAL_STR)
19903 {
19904 char *cl_name_or_number = NULL;
19905 char *seq = NULL;
19906 char *str = NULL;
19907 int direct = 0;
19908 int style = COMMUNITY_LIST_EXPANDED;
19909 int idx = 0;
19910
19911 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19912 seq = argv[idx]->arg;
19913
19914 idx = 0;
19915 argv_find(argv, argc, "permit", &idx);
19916 argv_find(argv, argc, "deny", &idx);
19917
19918 if (idx) {
19919 direct = argv_find(argv, argc, "permit", &idx)
19920 ? COMMUNITY_PERMIT
19921 : COMMUNITY_DENY;
19922
19923 idx = 0;
19924 argv_find(argv, argc, "AA:NN", &idx);
19925 str = argv_concat(argv, argc, idx);
19926 }
19927
19928 idx = 0;
19929 argv_find(argv, argc, "(100-500)", &idx);
19930 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19931 cl_name_or_number = argv[idx]->arg;
19932
19933 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19934 direct, style);
19935
19936 XFREE(MTYPE_TMP, str);
19937
19938 if (ret < 0) {
19939 community_list_perror(vty, ret);
19940 return CMD_WARNING_CONFIG_FAILED;
19941 }
19942
19943 return CMD_SUCCESS;
19944 }
19945
19946 ALIAS(no_community_list_expanded_all,
19947 no_bgp_community_list_expanded_all_list_cmd,
19948 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19949 NO_STR BGP_STR COMMUNITY_LIST_STR
19950 "Community list number (expanded)\n"
19951 "Add an expanded community-list entry\n"
19952 "Community list name\n")
19953
19954 /* Return configuration string of community-list entry. */
19955 static const char *community_list_config_str(struct community_entry *entry)
19956 {
19957 const char *str;
19958
19959 if (entry->any)
19960 str = "";
19961 else {
19962 if (entry->style == COMMUNITY_LIST_STANDARD)
19963 str = community_str(entry->u.com, false, false);
19964 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19965 str = lcommunity_str(entry->u.lcom, false, false);
19966 else
19967 str = entry->config;
19968 }
19969 return str;
19970 }
19971
19972 static void community_list_show(struct vty *vty, struct community_list *list)
19973 {
19974 struct community_entry *entry;
19975
19976 for (entry = list->head; entry; entry = entry->next) {
19977 if (entry == list->head) {
19978 if (all_digit(list->name))
19979 vty_out(vty, "Community %s list %s\n",
19980 entry->style == COMMUNITY_LIST_STANDARD
19981 ? "standard"
19982 : "(expanded) access",
19983 list->name);
19984 else
19985 vty_out(vty, "Named Community %s list %s\n",
19986 entry->style == COMMUNITY_LIST_STANDARD
19987 ? "standard"
19988 : "expanded",
19989 list->name);
19990 }
19991 if (entry->any)
19992 vty_out(vty, " %s\n",
19993 community_direct_str(entry->direct));
19994 else
19995 vty_out(vty, " %s %s\n",
19996 community_direct_str(entry->direct),
19997 community_list_config_str(entry));
19998 }
19999 }
20000
20001 DEFUN (show_community_list,
20002 show_bgp_community_list_cmd,
20003 "show bgp community-list",
20004 SHOW_STR
20005 BGP_STR
20006 "List community-list\n")
20007 {
20008 struct community_list *list;
20009 struct community_list_master *cm;
20010
20011 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20012 if (!cm)
20013 return CMD_SUCCESS;
20014
20015 for (list = cm->num.head; list; list = list->next)
20016 community_list_show(vty, list);
20017
20018 for (list = cm->str.head; list; list = list->next)
20019 community_list_show(vty, list);
20020
20021 return CMD_SUCCESS;
20022 }
20023
20024 DEFUN (show_community_list_arg,
20025 show_bgp_community_list_arg_cmd,
20026 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20027 SHOW_STR
20028 BGP_STR
20029 "List community-list\n"
20030 "Community-list number\n"
20031 "Community-list name\n"
20032 "Detailed information on community-list\n")
20033 {
20034 int idx_comm_list = 3;
20035 struct community_list *list;
20036
20037 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20038 COMMUNITY_LIST_MASTER);
20039 if (!list) {
20040 vty_out(vty, "%% Can't find community-list\n");
20041 return CMD_WARNING;
20042 }
20043
20044 community_list_show(vty, list);
20045
20046 return CMD_SUCCESS;
20047 }
20048
20049 /*
20050 * Large Community code.
20051 */
20052 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20053 struct cmd_token **argv, int style,
20054 int reject_all_digit_name)
20055 {
20056 int ret;
20057 int direct;
20058 char *str;
20059 int idx = 0;
20060 char *cl_name;
20061 char *seq = NULL;
20062
20063 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20064 seq = argv[idx]->arg;
20065
20066 idx = 0;
20067 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20068 : COMMUNITY_DENY;
20069
20070 /* All digit name check. */
20071 idx = 0;
20072 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20073 argv_find(argv, argc, "(1-99)", &idx);
20074 argv_find(argv, argc, "(100-500)", &idx);
20075 cl_name = argv[idx]->arg;
20076 if (reject_all_digit_name && all_digit(cl_name)) {
20077 vty_out(vty, "%% Community name cannot have all digits\n");
20078 return CMD_WARNING_CONFIG_FAILED;
20079 }
20080
20081 idx = 0;
20082 argv_find(argv, argc, "AA:BB:CC", &idx);
20083 argv_find(argv, argc, "LINE", &idx);
20084 /* Concat community string argument. */
20085 if (idx)
20086 str = argv_concat(argv, argc, idx);
20087 else
20088 str = NULL;
20089
20090 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20091
20092 /* Free temporary community list string allocated by
20093 argv_concat(). */
20094 XFREE(MTYPE_TMP, str);
20095
20096 if (ret < 0) {
20097 community_list_perror(vty, ret);
20098 return CMD_WARNING_CONFIG_FAILED;
20099 }
20100 return CMD_SUCCESS;
20101 }
20102
20103 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20104 struct cmd_token **argv, int style)
20105 {
20106 int ret;
20107 int direct = 0;
20108 char *str = NULL;
20109 int idx = 0;
20110 char *seq = NULL;
20111
20112 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20113 seq = argv[idx]->arg;
20114
20115 idx = 0;
20116 argv_find(argv, argc, "permit", &idx);
20117 argv_find(argv, argc, "deny", &idx);
20118
20119 if (idx) {
20120 /* Check the list direct. */
20121 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20122 direct = COMMUNITY_PERMIT;
20123 else
20124 direct = COMMUNITY_DENY;
20125
20126 idx = 0;
20127 argv_find(argv, argc, "LINE", &idx);
20128 argv_find(argv, argc, "AA:AA:NN", &idx);
20129 /* Concat community string argument. */
20130 str = argv_concat(argv, argc, idx);
20131 }
20132
20133 idx = 0;
20134 argv_find(argv, argc, "(1-99)", &idx);
20135 argv_find(argv, argc, "(100-500)", &idx);
20136 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20137
20138 /* Unset community list. */
20139 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20140 style);
20141
20142 /* Free temporary community list string allocated by
20143 argv_concat(). */
20144 XFREE(MTYPE_TMP, str);
20145
20146 if (ret < 0) {
20147 community_list_perror(vty, ret);
20148 return CMD_WARNING_CONFIG_FAILED;
20149 }
20150
20151 return CMD_SUCCESS;
20152 }
20153
20154 /* "large-community-list" keyword help string. */
20155 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20156 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20157
20158 DEFUN (lcommunity_list_standard,
20159 bgp_lcommunity_list_standard_cmd,
20160 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20161 BGP_STR
20162 LCOMMUNITY_LIST_STR
20163 "Large Community list number (standard)\n"
20164 "Sequence number of an entry\n"
20165 "Sequence number\n"
20166 "Specify large community to reject\n"
20167 "Specify large community to accept\n"
20168 LCOMMUNITY_VAL_STR)
20169 {
20170 return lcommunity_list_set_vty(vty, argc, argv,
20171 LARGE_COMMUNITY_LIST_STANDARD, 0);
20172 }
20173
20174 DEFUN (lcommunity_list_expanded,
20175 bgp_lcommunity_list_expanded_cmd,
20176 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20177 BGP_STR
20178 LCOMMUNITY_LIST_STR
20179 "Large Community list number (expanded)\n"
20180 "Sequence number of an entry\n"
20181 "Sequence number\n"
20182 "Specify large community to reject\n"
20183 "Specify large community to accept\n"
20184 "An ordered list as a regular-expression\n")
20185 {
20186 return lcommunity_list_set_vty(vty, argc, argv,
20187 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20188 }
20189
20190 DEFUN (lcommunity_list_name_standard,
20191 bgp_lcommunity_list_name_standard_cmd,
20192 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20193 BGP_STR
20194 LCOMMUNITY_LIST_STR
20195 "Specify standard large-community-list\n"
20196 "Large Community list name\n"
20197 "Sequence number of an entry\n"
20198 "Sequence number\n"
20199 "Specify large community to reject\n"
20200 "Specify large community to accept\n"
20201 LCOMMUNITY_VAL_STR)
20202 {
20203 return lcommunity_list_set_vty(vty, argc, argv,
20204 LARGE_COMMUNITY_LIST_STANDARD, 1);
20205 }
20206
20207 DEFUN (lcommunity_list_name_expanded,
20208 bgp_lcommunity_list_name_expanded_cmd,
20209 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20210 BGP_STR
20211 LCOMMUNITY_LIST_STR
20212 "Specify expanded large-community-list\n"
20213 "Large Community list name\n"
20214 "Sequence number of an entry\n"
20215 "Sequence number\n"
20216 "Specify large community to reject\n"
20217 "Specify large community to accept\n"
20218 "An ordered list as a regular-expression\n")
20219 {
20220 return lcommunity_list_set_vty(vty, argc, argv,
20221 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20222 }
20223
20224 DEFUN (no_lcommunity_list_all,
20225 no_bgp_lcommunity_list_all_cmd,
20226 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20227 NO_STR
20228 BGP_STR
20229 LCOMMUNITY_LIST_STR
20230 "Large Community list number (standard)\n"
20231 "Large Community list number (expanded)\n"
20232 "Large Community list name\n")
20233 {
20234 return lcommunity_list_unset_vty(vty, argc, argv,
20235 LARGE_COMMUNITY_LIST_STANDARD);
20236 }
20237
20238 DEFUN (no_lcommunity_list_name_standard_all,
20239 no_bgp_lcommunity_list_name_standard_all_cmd,
20240 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20241 NO_STR
20242 BGP_STR
20243 LCOMMUNITY_LIST_STR
20244 "Specify standard large-community-list\n"
20245 "Large Community list name\n")
20246 {
20247 return lcommunity_list_unset_vty(vty, argc, argv,
20248 LARGE_COMMUNITY_LIST_STANDARD);
20249 }
20250
20251 DEFUN (no_lcommunity_list_name_expanded_all,
20252 no_bgp_lcommunity_list_name_expanded_all_cmd,
20253 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20254 NO_STR
20255 BGP_STR
20256 LCOMMUNITY_LIST_STR
20257 "Specify expanded large-community-list\n"
20258 "Large Community list name\n")
20259 {
20260 return lcommunity_list_unset_vty(vty, argc, argv,
20261 LARGE_COMMUNITY_LIST_EXPANDED);
20262 }
20263
20264 DEFUN (no_lcommunity_list_standard,
20265 no_bgp_lcommunity_list_standard_cmd,
20266 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20267 NO_STR
20268 BGP_STR
20269 LCOMMUNITY_LIST_STR
20270 "Large Community list number (standard)\n"
20271 "Sequence number of an entry\n"
20272 "Sequence number\n"
20273 "Specify large community to reject\n"
20274 "Specify large community to accept\n"
20275 LCOMMUNITY_VAL_STR)
20276 {
20277 return lcommunity_list_unset_vty(vty, argc, argv,
20278 LARGE_COMMUNITY_LIST_STANDARD);
20279 }
20280
20281 DEFUN (no_lcommunity_list_expanded,
20282 no_bgp_lcommunity_list_expanded_cmd,
20283 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20284 NO_STR
20285 BGP_STR
20286 LCOMMUNITY_LIST_STR
20287 "Large Community list number (expanded)\n"
20288 "Sequence number of an entry\n"
20289 "Sequence number\n"
20290 "Specify large community to reject\n"
20291 "Specify large community to accept\n"
20292 "An ordered list as a regular-expression\n")
20293 {
20294 return lcommunity_list_unset_vty(vty, argc, argv,
20295 LARGE_COMMUNITY_LIST_EXPANDED);
20296 }
20297
20298 DEFUN (no_lcommunity_list_name_standard,
20299 no_bgp_lcommunity_list_name_standard_cmd,
20300 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20301 NO_STR
20302 BGP_STR
20303 LCOMMUNITY_LIST_STR
20304 "Specify standard large-community-list\n"
20305 "Large Community list name\n"
20306 "Sequence number of an entry\n"
20307 "Sequence number\n"
20308 "Specify large community to reject\n"
20309 "Specify large community to accept\n"
20310 LCOMMUNITY_VAL_STR)
20311 {
20312 return lcommunity_list_unset_vty(vty, argc, argv,
20313 LARGE_COMMUNITY_LIST_STANDARD);
20314 }
20315
20316 DEFUN (no_lcommunity_list_name_expanded,
20317 no_bgp_lcommunity_list_name_expanded_cmd,
20318 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20319 NO_STR
20320 BGP_STR
20321 LCOMMUNITY_LIST_STR
20322 "Specify expanded large-community-list\n"
20323 "Large community list name\n"
20324 "Sequence number of an entry\n"
20325 "Sequence number\n"
20326 "Specify large community to reject\n"
20327 "Specify large community to accept\n"
20328 "An ordered list as a regular-expression\n")
20329 {
20330 return lcommunity_list_unset_vty(vty, argc, argv,
20331 LARGE_COMMUNITY_LIST_EXPANDED);
20332 }
20333
20334 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20335 {
20336 struct community_entry *entry;
20337
20338 for (entry = list->head; entry; entry = entry->next) {
20339 if (entry == list->head) {
20340 if (all_digit(list->name))
20341 vty_out(vty, "Large community %s list %s\n",
20342 entry->style ==
20343 LARGE_COMMUNITY_LIST_STANDARD
20344 ? "standard"
20345 : "(expanded) access",
20346 list->name);
20347 else
20348 vty_out(vty,
20349 "Named large community %s list %s\n",
20350 entry->style ==
20351 LARGE_COMMUNITY_LIST_STANDARD
20352 ? "standard"
20353 : "expanded",
20354 list->name);
20355 }
20356 if (entry->any)
20357 vty_out(vty, " %s\n",
20358 community_direct_str(entry->direct));
20359 else
20360 vty_out(vty, " %s %s\n",
20361 community_direct_str(entry->direct),
20362 community_list_config_str(entry));
20363 }
20364 }
20365
20366 DEFUN (show_lcommunity_list,
20367 show_bgp_lcommunity_list_cmd,
20368 "show bgp large-community-list",
20369 SHOW_STR
20370 BGP_STR
20371 "List large-community list\n")
20372 {
20373 struct community_list *list;
20374 struct community_list_master *cm;
20375
20376 cm = community_list_master_lookup(bgp_clist,
20377 LARGE_COMMUNITY_LIST_MASTER);
20378 if (!cm)
20379 return CMD_SUCCESS;
20380
20381 for (list = cm->num.head; list; list = list->next)
20382 lcommunity_list_show(vty, list);
20383
20384 for (list = cm->str.head; list; list = list->next)
20385 lcommunity_list_show(vty, list);
20386
20387 return CMD_SUCCESS;
20388 }
20389
20390 DEFUN (show_lcommunity_list_arg,
20391 show_bgp_lcommunity_list_arg_cmd,
20392 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20393 SHOW_STR
20394 BGP_STR
20395 "List large-community list\n"
20396 "Large-community-list number\n"
20397 "Large-community-list name\n"
20398 "Detailed information on large-community-list\n")
20399 {
20400 struct community_list *list;
20401
20402 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20403 LARGE_COMMUNITY_LIST_MASTER);
20404 if (!list) {
20405 vty_out(vty, "%% Can't find large-community-list\n");
20406 return CMD_WARNING;
20407 }
20408
20409 lcommunity_list_show(vty, list);
20410
20411 return CMD_SUCCESS;
20412 }
20413
20414 /* "extcommunity-list" keyword help string. */
20415 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20416 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20417
20418 DEFUN (extcommunity_list_standard,
20419 bgp_extcommunity_list_standard_cmd,
20420 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20421 BGP_STR
20422 EXTCOMMUNITY_LIST_STR
20423 "Extended Community list number (standard)\n"
20424 "Specify standard extcommunity-list\n"
20425 "Community list name\n"
20426 "Sequence number of an entry\n"
20427 "Sequence number\n"
20428 "Specify community to reject\n"
20429 "Specify community to accept\n"
20430 EXTCOMMUNITY_VAL_STR)
20431 {
20432 int style = EXTCOMMUNITY_LIST_STANDARD;
20433 int direct = 0;
20434 char *cl_number_or_name = NULL;
20435 char *seq = NULL;
20436
20437 int idx = 0;
20438
20439 argv_find(argv, argc, "(1-99)", &idx);
20440 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20441 cl_number_or_name = argv[idx]->arg;
20442
20443 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20444 seq = argv[idx]->arg;
20445
20446 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20447 : COMMUNITY_DENY;
20448 argv_find(argv, argc, "AA:NN", &idx);
20449 char *str = argv_concat(argv, argc, idx);
20450
20451 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20452 direct, style);
20453
20454 XFREE(MTYPE_TMP, str);
20455
20456 if (ret < 0) {
20457 community_list_perror(vty, ret);
20458 return CMD_WARNING_CONFIG_FAILED;
20459 }
20460
20461 return CMD_SUCCESS;
20462 }
20463
20464 DEFUN (extcommunity_list_name_expanded,
20465 bgp_extcommunity_list_name_expanded_cmd,
20466 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20467 BGP_STR
20468 EXTCOMMUNITY_LIST_STR
20469 "Extended Community list number (expanded)\n"
20470 "Specify expanded extcommunity-list\n"
20471 "Extended Community list name\n"
20472 "Sequence number of an entry\n"
20473 "Sequence number\n"
20474 "Specify community to reject\n"
20475 "Specify community to accept\n"
20476 "An ordered list as a regular-expression\n")
20477 {
20478 int style = EXTCOMMUNITY_LIST_EXPANDED;
20479 int direct = 0;
20480 char *cl_number_or_name = NULL;
20481 char *seq = NULL;
20482 int idx = 0;
20483
20484 argv_find(argv, argc, "(100-500)", &idx);
20485 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20486 cl_number_or_name = argv[idx]->arg;
20487
20488 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20489 seq = argv[idx]->arg;
20490
20491 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20492 : COMMUNITY_DENY;
20493 argv_find(argv, argc, "LINE", &idx);
20494 char *str = argv_concat(argv, argc, idx);
20495
20496 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20497 direct, style);
20498
20499 XFREE(MTYPE_TMP, str);
20500
20501 if (ret < 0) {
20502 community_list_perror(vty, ret);
20503 return CMD_WARNING_CONFIG_FAILED;
20504 }
20505
20506 return CMD_SUCCESS;
20507 }
20508
20509 DEFUN (no_extcommunity_list_standard_all,
20510 no_bgp_extcommunity_list_standard_all_cmd,
20511 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20512 NO_STR
20513 BGP_STR
20514 EXTCOMMUNITY_LIST_STR
20515 "Extended Community list number (standard)\n"
20516 "Specify standard extcommunity-list\n"
20517 "Community list name\n"
20518 "Sequence number of an entry\n"
20519 "Sequence number\n"
20520 "Specify community to reject\n"
20521 "Specify community to accept\n"
20522 EXTCOMMUNITY_VAL_STR)
20523 {
20524 int style = EXTCOMMUNITY_LIST_STANDARD;
20525 int direct = 0;
20526 char *cl_number_or_name = NULL;
20527 char *str = NULL;
20528 char *seq = NULL;
20529 int idx = 0;
20530
20531 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20532 seq = argv[idx]->arg;
20533
20534 idx = 0;
20535 argv_find(argv, argc, "permit", &idx);
20536 argv_find(argv, argc, "deny", &idx);
20537 if (idx) {
20538 direct = argv_find(argv, argc, "permit", &idx)
20539 ? COMMUNITY_PERMIT
20540 : COMMUNITY_DENY;
20541
20542 idx = 0;
20543 argv_find(argv, argc, "AA:NN", &idx);
20544 str = argv_concat(argv, argc, idx);
20545 }
20546
20547 idx = 0;
20548 argv_find(argv, argc, "(1-99)", &idx);
20549 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20550 cl_number_or_name = argv[idx]->arg;
20551
20552 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20553 seq, direct, style);
20554
20555 XFREE(MTYPE_TMP, str);
20556
20557 if (ret < 0) {
20558 community_list_perror(vty, ret);
20559 return CMD_WARNING_CONFIG_FAILED;
20560 }
20561
20562 return CMD_SUCCESS;
20563 }
20564
20565 ALIAS(no_extcommunity_list_standard_all,
20566 no_bgp_extcommunity_list_standard_all_list_cmd,
20567 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20568 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20569 "Extended Community list number (standard)\n"
20570 "Specify standard extcommunity-list\n"
20571 "Community list name\n")
20572
20573 DEFUN (no_extcommunity_list_expanded_all,
20574 no_bgp_extcommunity_list_expanded_all_cmd,
20575 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20576 NO_STR
20577 BGP_STR
20578 EXTCOMMUNITY_LIST_STR
20579 "Extended Community list number (expanded)\n"
20580 "Specify expanded extcommunity-list\n"
20581 "Extended Community list name\n"
20582 "Sequence number of an entry\n"
20583 "Sequence number\n"
20584 "Specify community to reject\n"
20585 "Specify community to accept\n"
20586 "An ordered list as a regular-expression\n")
20587 {
20588 int style = EXTCOMMUNITY_LIST_EXPANDED;
20589 int direct = 0;
20590 char *cl_number_or_name = NULL;
20591 char *str = NULL;
20592 char *seq = NULL;
20593 int idx = 0;
20594
20595 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20596 seq = argv[idx]->arg;
20597
20598 idx = 0;
20599 argv_find(argv, argc, "permit", &idx);
20600 argv_find(argv, argc, "deny", &idx);
20601
20602 if (idx) {
20603 direct = argv_find(argv, argc, "permit", &idx)
20604 ? COMMUNITY_PERMIT
20605 : COMMUNITY_DENY;
20606
20607 idx = 0;
20608 argv_find(argv, argc, "LINE", &idx);
20609 str = argv_concat(argv, argc, idx);
20610 }
20611
20612 idx = 0;
20613 argv_find(argv, argc, "(100-500)", &idx);
20614 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20615 cl_number_or_name = argv[idx]->arg;
20616
20617 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20618 seq, direct, style);
20619
20620 XFREE(MTYPE_TMP, str);
20621
20622 if (ret < 0) {
20623 community_list_perror(vty, ret);
20624 return CMD_WARNING_CONFIG_FAILED;
20625 }
20626
20627 return CMD_SUCCESS;
20628 }
20629
20630 ALIAS(no_extcommunity_list_expanded_all,
20631 no_bgp_extcommunity_list_expanded_all_list_cmd,
20632 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20633 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20634 "Extended Community list number (expanded)\n"
20635 "Specify expanded extcommunity-list\n"
20636 "Extended Community list name\n")
20637
20638 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20639 {
20640 struct community_entry *entry;
20641
20642 for (entry = list->head; entry; entry = entry->next) {
20643 if (entry == list->head) {
20644 if (all_digit(list->name))
20645 vty_out(vty, "Extended community %s list %s\n",
20646 entry->style == EXTCOMMUNITY_LIST_STANDARD
20647 ? "standard"
20648 : "(expanded) access",
20649 list->name);
20650 else
20651 vty_out(vty,
20652 "Named extended community %s list %s\n",
20653 entry->style == EXTCOMMUNITY_LIST_STANDARD
20654 ? "standard"
20655 : "expanded",
20656 list->name);
20657 }
20658 if (entry->any)
20659 vty_out(vty, " %s\n",
20660 community_direct_str(entry->direct));
20661 else
20662 vty_out(vty, " %s %s\n",
20663 community_direct_str(entry->direct),
20664 community_list_config_str(entry));
20665 }
20666 }
20667
20668 DEFUN (show_extcommunity_list,
20669 show_bgp_extcommunity_list_cmd,
20670 "show bgp extcommunity-list",
20671 SHOW_STR
20672 BGP_STR
20673 "List extended-community list\n")
20674 {
20675 struct community_list *list;
20676 struct community_list_master *cm;
20677
20678 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20679 if (!cm)
20680 return CMD_SUCCESS;
20681
20682 for (list = cm->num.head; list; list = list->next)
20683 extcommunity_list_show(vty, list);
20684
20685 for (list = cm->str.head; list; list = list->next)
20686 extcommunity_list_show(vty, list);
20687
20688 return CMD_SUCCESS;
20689 }
20690
20691 DEFUN (show_extcommunity_list_arg,
20692 show_bgp_extcommunity_list_arg_cmd,
20693 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20694 SHOW_STR
20695 BGP_STR
20696 "List extended-community list\n"
20697 "Extcommunity-list number\n"
20698 "Extcommunity-list name\n"
20699 "Detailed information on extcommunity-list\n")
20700 {
20701 int idx_comm_list = 3;
20702 struct community_list *list;
20703
20704 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20705 EXTCOMMUNITY_LIST_MASTER);
20706 if (!list) {
20707 vty_out(vty, "%% Can't find extcommunity-list\n");
20708 return CMD_WARNING;
20709 }
20710
20711 extcommunity_list_show(vty, list);
20712
20713 return CMD_SUCCESS;
20714 }
20715
20716 /* Display community-list and extcommunity-list configuration. */
20717 static int community_list_config_write(struct vty *vty)
20718 {
20719 struct community_list *list;
20720 struct community_entry *entry;
20721 struct community_list_master *cm;
20722 int write = 0;
20723
20724 /* Community-list. */
20725 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20726
20727 for (list = cm->num.head; list; list = list->next)
20728 for (entry = list->head; entry; entry = entry->next) {
20729 vty_out(vty,
20730 "bgp community-list %s seq %" PRId64 " %s %s\n",
20731 list->name, entry->seq,
20732 community_direct_str(entry->direct),
20733 community_list_config_str(entry));
20734 write++;
20735 }
20736 for (list = cm->str.head; list; list = list->next)
20737 for (entry = list->head; entry; entry = entry->next) {
20738 vty_out(vty,
20739 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20740 entry->style == COMMUNITY_LIST_STANDARD
20741 ? "standard"
20742 : "expanded",
20743 list->name, entry->seq,
20744 community_direct_str(entry->direct),
20745 community_list_config_str(entry));
20746 write++;
20747 }
20748
20749 /* Extcommunity-list. */
20750 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20751
20752 for (list = cm->num.head; list; list = list->next)
20753 for (entry = list->head; entry; entry = entry->next) {
20754 vty_out(vty,
20755 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20756 list->name, entry->seq,
20757 community_direct_str(entry->direct),
20758 community_list_config_str(entry));
20759 write++;
20760 }
20761 for (list = cm->str.head; list; list = list->next)
20762 for (entry = list->head; entry; entry = entry->next) {
20763 vty_out(vty,
20764 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20765 entry->style == EXTCOMMUNITY_LIST_STANDARD
20766 ? "standard"
20767 : "expanded",
20768 list->name, entry->seq,
20769 community_direct_str(entry->direct),
20770 community_list_config_str(entry));
20771 write++;
20772 }
20773
20774
20775 /* lcommunity-list. */
20776 cm = community_list_master_lookup(bgp_clist,
20777 LARGE_COMMUNITY_LIST_MASTER);
20778
20779 for (list = cm->num.head; list; list = list->next)
20780 for (entry = list->head; entry; entry = entry->next) {
20781 vty_out(vty,
20782 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20783 list->name, entry->seq,
20784 community_direct_str(entry->direct),
20785 community_list_config_str(entry));
20786 write++;
20787 }
20788 for (list = cm->str.head; list; list = list->next)
20789 for (entry = list->head; entry; entry = entry->next) {
20790 vty_out(vty,
20791 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20792
20793 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20794 ? "standard"
20795 : "expanded",
20796 list->name, entry->seq, community_direct_str(entry->direct),
20797 community_list_config_str(entry));
20798 write++;
20799 }
20800
20801 return write;
20802 }
20803
20804 static int community_list_config_write(struct vty *vty);
20805 static struct cmd_node community_list_node = {
20806 .name = "community list",
20807 .node = COMMUNITY_LIST_NODE,
20808 .prompt = "",
20809 .config_write = community_list_config_write,
20810 };
20811
20812 static void community_list_vty(void)
20813 {
20814 install_node(&community_list_node);
20815
20816 /* Community-list. */
20817 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20818 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20819 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20820 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20821 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20822 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20823 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20824 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20825
20826 /* Extcommunity-list. */
20827 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20828 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20829 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20830 install_element(CONFIG_NODE,
20831 &no_bgp_extcommunity_list_standard_all_list_cmd);
20832 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20833 install_element(CONFIG_NODE,
20834 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20835 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20836 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20837
20838 /* Large Community List */
20839 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20840 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20841 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20842 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20843 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20844 install_element(CONFIG_NODE,
20845 &no_bgp_lcommunity_list_name_standard_all_cmd);
20846 install_element(CONFIG_NODE,
20847 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20848 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20849 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20850 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20851 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20852 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20853 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20854
20855 bgp_community_list_command_completion_setup();
20856 }
20857
20858 static struct cmd_node community_alias_node = {
20859 .name = "community alias",
20860 .node = COMMUNITY_ALIAS_NODE,
20861 .prompt = "",
20862 .config_write = bgp_community_alias_write,
20863 };
20864
20865 void community_alias_vty(void)
20866 {
20867 install_node(&community_alias_node);
20868
20869 /* Community-list. */
20870 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20871
20872 bgp_community_alias_command_completion_setup();
20873 }