]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12059 from achernavin22/fix-max-med-on-startup
[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, *tovpn_sid_locator;
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 tovpn_sid_locator =
344 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator;
345 if (tovpn_sid_locator) {
346 srv6_locator_chunk_free(tovpn_sid_locator);
347 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator = NULL;
348 }
349
350 /* refresh vpnv6 tovpn_sid_locator */
351 tovpn_sid_locator =
352 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator;
353 if (tovpn_sid_locator) {
354 srv6_locator_chunk_free(tovpn_sid_locator);
355 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator = NULL;
356 }
357 }
358
359 /* clear locator name */
360 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
361
362 return 0;
363 }
364
365 /* Utility function to get address family from current node. */
366 afi_t bgp_node_afi(struct vty *vty)
367 {
368 afi_t afi;
369 switch (vty->node) {
370 case BGP_IPV6_NODE:
371 case BGP_IPV6M_NODE:
372 case BGP_IPV6L_NODE:
373 case BGP_VPNV6_NODE:
374 case BGP_FLOWSPECV6_NODE:
375 afi = AFI_IP6;
376 break;
377 case BGP_EVPN_NODE:
378 afi = AFI_L2VPN;
379 break;
380 default:
381 afi = AFI_IP;
382 break;
383 }
384 return afi;
385 }
386
387 /* Utility function to get subsequent address family from current
388 node. */
389 safi_t bgp_node_safi(struct vty *vty)
390 {
391 safi_t safi;
392 switch (vty->node) {
393 case BGP_VPNV4_NODE:
394 case BGP_VPNV6_NODE:
395 safi = SAFI_MPLS_VPN;
396 break;
397 case BGP_IPV4M_NODE:
398 case BGP_IPV6M_NODE:
399 safi = SAFI_MULTICAST;
400 break;
401 case BGP_EVPN_NODE:
402 safi = SAFI_EVPN;
403 break;
404 case BGP_IPV4L_NODE:
405 case BGP_IPV6L_NODE:
406 safi = SAFI_LABELED_UNICAST;
407 break;
408 case BGP_FLOWSPECV4_NODE:
409 case BGP_FLOWSPECV6_NODE:
410 safi = SAFI_FLOWSPEC;
411 break;
412 default:
413 safi = SAFI_UNICAST;
414 break;
415 }
416 return safi;
417 }
418
419 /**
420 * Converts an AFI in string form to afi_t
421 *
422 * @param afi string, one of
423 * - "ipv4"
424 * - "ipv6"
425 * - "l2vpn"
426 * @return the corresponding afi_t
427 */
428 afi_t bgp_vty_afi_from_str(const char *afi_str)
429 {
430 afi_t afi = AFI_MAX; /* unknown */
431 if (strmatch(afi_str, "ipv4"))
432 afi = AFI_IP;
433 else if (strmatch(afi_str, "ipv6"))
434 afi = AFI_IP6;
435 else if (strmatch(afi_str, "l2vpn"))
436 afi = AFI_L2VPN;
437 return afi;
438 }
439
440 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
441 afi_t *afi)
442 {
443 int ret = 0;
444 if (argv_find(argv, argc, "ipv4", index)) {
445 ret = 1;
446 if (afi)
447 *afi = AFI_IP;
448 } else if (argv_find(argv, argc, "ipv6", index)) {
449 ret = 1;
450 if (afi)
451 *afi = AFI_IP6;
452 } else if (argv_find(argv, argc, "l2vpn", index)) {
453 ret = 1;
454 if (afi)
455 *afi = AFI_L2VPN;
456 }
457 return ret;
458 }
459
460 /* supports <unicast|multicast|vpn|labeled-unicast> */
461 safi_t bgp_vty_safi_from_str(const char *safi_str)
462 {
463 safi_t safi = SAFI_MAX; /* unknown */
464 if (strmatch(safi_str, "multicast"))
465 safi = SAFI_MULTICAST;
466 else if (strmatch(safi_str, "unicast"))
467 safi = SAFI_UNICAST;
468 else if (strmatch(safi_str, "vpn"))
469 safi = SAFI_MPLS_VPN;
470 else if (strmatch(safi_str, "evpn"))
471 safi = SAFI_EVPN;
472 else if (strmatch(safi_str, "labeled-unicast"))
473 safi = SAFI_LABELED_UNICAST;
474 else if (strmatch(safi_str, "flowspec"))
475 safi = SAFI_FLOWSPEC;
476 return safi;
477 }
478
479 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
480 safi_t *safi)
481 {
482 int ret = 0;
483 if (argv_find(argv, argc, "unicast", index)) {
484 ret = 1;
485 if (safi)
486 *safi = SAFI_UNICAST;
487 } else if (argv_find(argv, argc, "multicast", index)) {
488 ret = 1;
489 if (safi)
490 *safi = SAFI_MULTICAST;
491 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_LABELED_UNICAST;
495 } else if (argv_find(argv, argc, "vpn", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_MPLS_VPN;
499 } else if (argv_find(argv, argc, "evpn", index)) {
500 ret = 1;
501 if (safi)
502 *safi = SAFI_EVPN;
503 } else if (argv_find(argv, argc, "flowspec", index)) {
504 ret = 1;
505 if (safi)
506 *safi = SAFI_FLOWSPEC;
507 }
508 return ret;
509 }
510
511 /*
512 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
513 *
514 * afi
515 * address-family identifier
516 *
517 * safi
518 * subsequent address-family identifier
519 *
520 * Returns:
521 * default_af string corresponding to the supplied afi/safi pair.
522 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
523 * return -1.
524 */
525 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
526 {
527 switch (afi) {
528 case AFI_IP:
529 switch (safi) {
530 case SAFI_UNICAST:
531 return "ipv4-unicast";
532 case SAFI_MULTICAST:
533 return "ipv4-multicast";
534 case SAFI_MPLS_VPN:
535 return "ipv4-vpn";
536 case SAFI_ENCAP:
537 return "ipv4-encap";
538 case SAFI_LABELED_UNICAST:
539 return "ipv4-labeled-unicast";
540 case SAFI_FLOWSPEC:
541 return "ipv4-flowspec";
542 default:
543 return "unknown-afi/safi";
544 }
545 break;
546 case AFI_IP6:
547 switch (safi) {
548 case SAFI_UNICAST:
549 return "ipv6-unicast";
550 case SAFI_MULTICAST:
551 return "ipv6-multicast";
552 case SAFI_MPLS_VPN:
553 return "ipv6-vpn";
554 case SAFI_ENCAP:
555 return "ipv6-encap";
556 case SAFI_LABELED_UNICAST:
557 return "ipv6-labeled-unicast";
558 case SAFI_FLOWSPEC:
559 return "ipv6-flowspec";
560 default:
561 return "unknown-afi/safi";
562 }
563 break;
564 case AFI_L2VPN:
565 switch (safi) {
566 case SAFI_EVPN:
567 return "l2vpn-evpn";
568 default:
569 return "unknown-afi/safi";
570 }
571 case AFI_UNSPEC:
572 case AFI_MAX:
573 return "unknown-afi/safi";
574 }
575 /* all AFIs are accounted for above, so this shouldn't happen */
576 return "unknown-afi/safi";
577 }
578
579 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
580 enum bgp_instance_type inst_type)
581 {
582 int ret = bgp_get(bgp, as, name, inst_type);
583
584 if (ret == BGP_CREATED) {
585 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
586 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
587
588 if (DFLT_BGP_IMPORT_CHECK)
589 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
590 if (DFLT_BGP_SHOW_HOSTNAME)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
592 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
594 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
596 if (DFLT_BGP_DETERMINISTIC_MED)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
598 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
600 if (DFLT_BGP_SUPPRESS_DUPLICATES)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
602 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
604 if (DFLT_BGP_HARD_ADMIN_RESET)
605 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
606
607 ret = BGP_SUCCESS;
608 }
609 return ret;
610 }
611
612 /*
613 * bgp_vty_find_and_parse_afi_safi_bgp
614 *
615 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
616 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
617 * to appropriate values for the calling function. This is to allow the
618 * calling function to make decisions appropriate for the show command
619 * that is being parsed.
620 *
621 * The show commands are generally of the form:
622 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
623 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
624 *
625 * Since we use argv_find if the show command in particular doesn't have:
626 * [ip]
627 * [<view|vrf> VIEWVRFNAME]
628 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
629 * The command parsing should still be ok.
630 *
631 * vty -> The vty for the command so we can output some useful data in
632 * the event of a parse error in the vrf.
633 * argv -> The command tokens
634 * argc -> How many command tokens we have
635 * idx -> The current place in the command, generally should be 0 for this
636 * function
637 * afi -> The parsed afi if it was included in the show command, returned here
638 * safi -> The parsed safi if it was included in the show command, returned here
639 * bgp -> Pointer to the bgp data structure we need to fill in.
640 * use_json -> json is configured or not
641 *
642 * The function returns the correct location in the parse tree for the
643 * last token found.
644 *
645 * Returns 0 for failure to parse correctly, else the idx position of where
646 * it found the last token.
647 */
648 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
649 struct cmd_token **argv, int argc,
650 int *idx, afi_t *afi, safi_t *safi,
651 struct bgp **bgp, bool use_json)
652 {
653 char *vrf_name = NULL;
654
655 assert(afi);
656 assert(safi);
657 assert(bgp);
658
659 if (argv_find(argv, argc, "ip", idx))
660 *afi = AFI_IP;
661
662 if (argv_find(argv, argc, "view", idx))
663 vrf_name = argv[*idx + 1]->arg;
664 else if (argv_find(argv, argc, "vrf", idx)) {
665 vrf_name = argv[*idx + 1]->arg;
666 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
667 vrf_name = NULL;
668 }
669 if (vrf_name) {
670 if (strmatch(vrf_name, "all"))
671 *bgp = NULL;
672 else {
673 *bgp = bgp_lookup_by_name(vrf_name);
674 if (!*bgp) {
675 if (use_json) {
676 json_object *json = NULL;
677 json = json_object_new_object();
678 json_object_string_add(
679 json, "warning",
680 "View/Vrf is unknown");
681 vty_json(vty, json);
682 }
683 else
684 vty_out(vty, "View/Vrf %s is unknown\n",
685 vrf_name);
686 *idx = 0;
687 return 0;
688 }
689 }
690 } else {
691 *bgp = bgp_get_default();
692 if (!*bgp) {
693 if (use_json) {
694 json_object *json = NULL;
695 json = json_object_new_object();
696 json_object_string_add(
697 json, "warning",
698 "Default BGP instance not found");
699 vty_json(vty, json);
700 }
701 else
702 vty_out(vty,
703 "Default BGP instance not found\n");
704 *idx = 0;
705 return 0;
706 }
707 }
708
709 if (argv_find_and_parse_afi(argv, argc, idx, afi))
710 argv_find_and_parse_safi(argv, argc, idx, safi);
711
712 *idx += 1;
713 return *idx;
714 }
715
716 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
717 {
718 struct interface *ifp = NULL;
719 struct listnode *node;
720 struct bgp_listener *listener;
721 union sockunion all_su;
722
723 if (su->sa.sa_family == AF_INET) {
724 (void)str2sockunion("0.0.0.0", &all_su);
725 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
726 } else if (su->sa.sa_family == AF_INET6) {
727 (void)str2sockunion("::", &all_su);
728 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
729 su->sin6.sin6_scope_id,
730 bgp->vrf_id);
731 }
732
733 if (ifp) {
734 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
735 if (sockunion_family(su) !=
736 sockunion_family(&listener->su))
737 continue;
738
739 /* If 0.0.0.0/:: is a listener, then treat as self and
740 * reject.
741 */
742 if (!sockunion_cmp(&listener->su, su) ||
743 !sockunion_cmp(&listener->su, &all_su))
744 return true;
745 }
746 }
747
748 return false;
749 }
750
751 /* Utility function for looking up peer from VTY. */
752 /* This is used only for configuration, so disallow if attempted on
753 * a dynamic neighbor.
754 */
755 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
756 {
757 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
758 int ret;
759 union sockunion su;
760 struct peer *peer;
761
762 if (!bgp) {
763 return NULL;
764 }
765
766 ret = str2sockunion(ip_str, &su);
767 if (ret < 0) {
768 peer = peer_lookup_by_conf_if(bgp, ip_str);
769 if (!peer) {
770 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
771 == NULL) {
772 vty_out(vty,
773 "%% Malformed address or name: %s\n",
774 ip_str);
775 return NULL;
776 }
777 }
778 } else {
779 peer = peer_lookup(bgp, &su);
780 if (!peer) {
781 vty_out(vty,
782 "%% Specify remote-as or peer-group commands first\n");
783 return NULL;
784 }
785 if (peer_dynamic_neighbor(peer)) {
786 vty_out(vty,
787 "%% Operation not allowed on a dynamic neighbor\n");
788 return NULL;
789 }
790 }
791 return peer;
792 }
793
794 /* Utility function for looking up peer or peer group. */
795 /* This is used only for configuration, so disallow if attempted on
796 * a dynamic neighbor.
797 */
798 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
799 {
800 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
801 int ret;
802 union sockunion su;
803 struct peer *peer = NULL;
804 struct peer_group *group = NULL;
805
806 if (!bgp) {
807 return NULL;
808 }
809
810 ret = str2sockunion(peer_str, &su);
811 if (ret == 0) {
812 /* IP address, locate peer. */
813 peer = peer_lookup(bgp, &su);
814 } else {
815 /* Not IP, could match either peer configured on interface or a
816 * group. */
817 peer = peer_lookup_by_conf_if(bgp, peer_str);
818 if (!peer)
819 group = peer_group_lookup(bgp, peer_str);
820 }
821
822 if (peer) {
823 if (peer_dynamic_neighbor(peer)) {
824 vty_out(vty,
825 "%% Operation not allowed on a dynamic neighbor\n");
826 return NULL;
827 }
828
829 return peer;
830 }
831
832 if (group)
833 return group->conf;
834
835 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
836
837 return NULL;
838 }
839
840 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
841 {
842 const char *str = NULL;
843
844 switch (ret) {
845 case BGP_SUCCESS:
846 case BGP_CREATED:
847 case BGP_GR_NO_OPERATION:
848 break;
849 case BGP_ERR_INVALID_VALUE:
850 str = "Invalid value";
851 break;
852 case BGP_ERR_INVALID_FLAG:
853 str = "Invalid flag";
854 break;
855 case BGP_ERR_PEER_GROUP_SHUTDOWN:
856 str = "Peer-group has been shutdown. Activate the peer-group first";
857 break;
858 case BGP_ERR_PEER_FLAG_CONFLICT:
859 str = "Can't set override-capability and strict-capability-match at the same time";
860 break;
861 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
862 str = "Specify remote-as or peer-group remote AS first";
863 break;
864 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
865 str = "Cannot change the peer-group. Deconfigure first";
866 break;
867 case BGP_ERR_PEER_GROUP_MISMATCH:
868 str = "Peer is not a member of this peer-group";
869 break;
870 case BGP_ERR_PEER_FILTER_CONFLICT:
871 str = "Prefix/distribute list can not co-exist";
872 break;
873 case BGP_ERR_NOT_INTERNAL_PEER:
874 str = "Invalid command. Not an internal neighbor";
875 break;
876 case BGP_ERR_REMOVE_PRIVATE_AS:
877 str = "remove-private-AS cannot be configured for IBGP peers";
878 break;
879 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
880 str = "Cannot have local-as same as BGP AS number";
881 break;
882 case BGP_ERR_TCPSIG_FAILED:
883 str = "Error while applying TCP-Sig to session(s)";
884 break;
885 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
886 str = "ebgp-multihop and ttl-security cannot be configured together";
887 break;
888 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
889 str = "ttl-security only allowed for EBGP peers";
890 break;
891 case BGP_ERR_AS_OVERRIDE:
892 str = "as-override cannot be configured for IBGP peers";
893 break;
894 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
895 str = "Invalid limit for number of dynamic neighbors";
896 break;
897 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
898 str = "Dynamic neighbor listen range already exists";
899 break;
900 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
901 str = "Operation not allowed on a dynamic neighbor";
902 break;
903 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
904 str = "Operation not allowed on a directly connected neighbor";
905 break;
906 case BGP_ERR_PEER_SAFI_CONFLICT:
907 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
908 break;
909 case BGP_ERR_GR_INVALID_CMD:
910 str = "The Graceful Restart command used is not valid at this moment.";
911 break;
912 case BGP_ERR_GR_OPERATION_FAILED:
913 str = "The Graceful Restart Operation failed due to an err.";
914 break;
915 case BGP_ERR_PEER_GROUP_MEMBER:
916 str = "Peer-group member cannot override remote-as of peer-group.";
917 break;
918 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
919 str = "Peer-group members must be all internal or all external.";
920 break;
921 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
922 str = "Range specified cannot be deleted because it is not part of current config.";
923 break;
924 case BGP_ERR_INSTANCE_MISMATCH:
925 str = "Instance specified does not match the current instance.";
926 break;
927 case BGP_ERR_NO_INTERFACE_CONFIG:
928 str = "Interface specified is not being used for interface based peer.";
929 break;
930 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
931 str = "No configuration already specified for soft reconfiguration.";
932 break;
933 case BGP_ERR_AS_MISMATCH:
934 str = "BGP is already running.";
935 break;
936 case BGP_ERR_AF_UNCONFIGURED:
937 str = "AFI/SAFI specified is not currently configured.";
938 break;
939 case BGP_ERR_INVALID_AS:
940 str = "Confederation AS specified is the same AS as our AS.";
941 break;
942 case BGP_ERR_INVALID_ROLE_NAME:
943 str = "Invalid role name";
944 break;
945 case BGP_ERR_INVALID_INTERNAL_ROLE:
946 str = "External roles can be set only on eBGP session";
947 break;
948 }
949 if (str) {
950 vty_out(vty, "%% %s\n", str);
951 return CMD_WARNING_CONFIG_FAILED;
952 }
953 return CMD_SUCCESS;
954 }
955
956 /* BGP clear sort. */
957 enum clear_sort {
958 clear_all,
959 clear_peer,
960 clear_group,
961 clear_external,
962 clear_as
963 };
964
965 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
966 safi_t safi, int error)
967 {
968 switch (error) {
969 case BGP_ERR_AF_UNCONFIGURED:
970 if (vty)
971 vty_out(vty,
972 "%% BGP: Enable %s address family for the neighbor %s\n",
973 get_afi_safi_str(afi, safi, false), peer->host);
974 else
975 zlog_warn(
976 "%% BGP: Enable %s address family for the neighbor %s",
977 get_afi_safi_str(afi, safi, false), peer->host);
978 break;
979 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
980 if (vty)
981 vty_out(vty,
982 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
983 peer->host);
984 else
985 zlog_warn(
986 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
987 peer->host);
988 break;
989 default:
990 break;
991 }
992 }
993
994 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
995 struct listnode **nnode, enum bgp_clear_type stype)
996 {
997 int ret = 0;
998 struct peer_af *paf;
999
1000 /* if afi/.safi not specified, spin thru all of them */
1001 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1002 afi_t tmp_afi;
1003 safi_t tmp_safi;
1004 enum bgp_af_index index;
1005
1006 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1007 paf = peer->peer_af_array[index];
1008 if (!paf)
1009 continue;
1010
1011 if (paf && paf->subgroup)
1012 SET_FLAG(paf->subgroup->sflags,
1013 SUBGRP_STATUS_FORCE_UPDATES);
1014
1015 tmp_afi = paf->afi;
1016 tmp_safi = paf->safi;
1017 if (!peer->afc[tmp_afi][tmp_safi])
1018 continue;
1019
1020 if (stype == BGP_CLEAR_SOFT_NONE)
1021 ret = peer_clear(peer, nnode);
1022 else
1023 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1024 stype);
1025 }
1026 /* if afi specified and safi not, spin thru safis on this afi */
1027 } else if (safi == SAFI_UNSPEC) {
1028 safi_t tmp_safi;
1029
1030 for (tmp_safi = SAFI_UNICAST;
1031 tmp_safi < SAFI_MAX; tmp_safi++) {
1032 if (!peer->afc[afi][tmp_safi])
1033 continue;
1034
1035 paf = peer_af_find(peer, afi, tmp_safi);
1036 if (paf && paf->subgroup)
1037 SET_FLAG(paf->subgroup->sflags,
1038 SUBGRP_STATUS_FORCE_UPDATES);
1039
1040 if (stype == BGP_CLEAR_SOFT_NONE)
1041 ret = peer_clear(peer, nnode);
1042 else
1043 ret = peer_clear_soft(peer, afi,
1044 tmp_safi, stype);
1045 }
1046 /* both afi/safi specified, let the caller know if not defined */
1047 } else {
1048 if (!peer->afc[afi][safi])
1049 return 1;
1050
1051 paf = peer_af_find(peer, afi, safi);
1052 if (paf && paf->subgroup)
1053 SET_FLAG(paf->subgroup->sflags,
1054 SUBGRP_STATUS_FORCE_UPDATES);
1055
1056 if (stype == BGP_CLEAR_SOFT_NONE)
1057 ret = peer_clear(peer, nnode);
1058 else
1059 ret = peer_clear_soft(peer, afi, safi, stype);
1060 }
1061
1062 return ret;
1063 }
1064
1065 /* `clear ip bgp' functions. */
1066 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1067 enum clear_sort sort, enum bgp_clear_type stype,
1068 const char *arg)
1069 {
1070 int ret = 0;
1071 bool found = false;
1072 struct peer *peer;
1073
1074 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1075
1076 /* Clear all neighbors. */
1077 /*
1078 * Pass along pointer to next node to peer_clear() when walking all
1079 * nodes on the BGP instance as that may get freed if it is a
1080 * doppelganger
1081 */
1082 if (sort == clear_all) {
1083 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1084
1085 bgp_peer_gr_flags_update(peer);
1086
1087 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1088 gr_router_detected = true;
1089
1090 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1091 stype);
1092
1093 if (ret < 0)
1094 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1095 }
1096
1097 if (gr_router_detected
1098 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1099 bgp_zebra_send_capabilities(bgp, false);
1100 } else if (!gr_router_detected
1101 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1102 bgp_zebra_send_capabilities(bgp, true);
1103 }
1104
1105 /* This is to apply read-only mode on this clear. */
1106 if (stype == BGP_CLEAR_SOFT_NONE)
1107 bgp->update_delay_over = 0;
1108
1109 return CMD_SUCCESS;
1110 }
1111
1112 /* Clear specified neighbor. */
1113 if (sort == clear_peer) {
1114 union sockunion su;
1115
1116 /* Make sockunion for lookup. */
1117 ret = str2sockunion(arg, &su);
1118 if (ret < 0) {
1119 peer = peer_lookup_by_conf_if(bgp, arg);
1120 if (!peer) {
1121 peer = peer_lookup_by_hostname(bgp, arg);
1122 if (!peer) {
1123 vty_out(vty,
1124 "Malformed address or name: %s\n",
1125 arg);
1126 return CMD_WARNING;
1127 }
1128 }
1129 } else {
1130 peer = peer_lookup(bgp, &su);
1131 if (!peer) {
1132 vty_out(vty,
1133 "%% BGP: Unknown neighbor - \"%s\"\n",
1134 arg);
1135 return CMD_WARNING;
1136 }
1137 }
1138
1139 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1140 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1141
1142 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1143
1144 /* if afi/safi not defined for this peer, let caller know */
1145 if (ret == 1)
1146 ret = BGP_ERR_AF_UNCONFIGURED;
1147
1148 if (ret < 0)
1149 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1150
1151 return CMD_SUCCESS;
1152 }
1153
1154 /* Clear all neighbors belonging to a specific peer-group. */
1155 if (sort == clear_group) {
1156 struct peer_group *group;
1157
1158 group = peer_group_lookup(bgp, arg);
1159 if (!group) {
1160 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1161 return CMD_WARNING;
1162 }
1163
1164 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1165 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1166
1167 if (ret < 0)
1168 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1169 else
1170 found = true;
1171 }
1172
1173 if (!found)
1174 vty_out(vty,
1175 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1176 get_afi_safi_str(afi, safi, false), arg);
1177
1178 return CMD_SUCCESS;
1179 }
1180
1181 /* Clear all external (eBGP) neighbors. */
1182 if (sort == clear_external) {
1183 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1184 if (peer->sort == BGP_PEER_IBGP)
1185 continue;
1186
1187 bgp_peer_gr_flags_update(peer);
1188
1189 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1190 gr_router_detected = true;
1191
1192 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1193
1194 if (ret < 0)
1195 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1196 else
1197 found = true;
1198 }
1199
1200 if (gr_router_detected
1201 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1202 bgp_zebra_send_capabilities(bgp, false);
1203 } else if (!gr_router_detected
1204 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1205 bgp_zebra_send_capabilities(bgp, true);
1206 }
1207
1208 if (!found)
1209 vty_out(vty,
1210 "%% BGP: No external %s peer is configured\n",
1211 get_afi_safi_str(afi, safi, false));
1212
1213 return CMD_SUCCESS;
1214 }
1215
1216 /* Clear all neighbors belonging to a specific AS. */
1217 if (sort == clear_as) {
1218 as_t as = strtoul(arg, NULL, 10);
1219
1220 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1221 if (peer->as != as)
1222 continue;
1223
1224 bgp_peer_gr_flags_update(peer);
1225
1226 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1227 gr_router_detected = true;
1228
1229 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1230
1231 if (ret < 0)
1232 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1233 else
1234 found = true;
1235 }
1236
1237 if (gr_router_detected
1238 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1239 bgp_zebra_send_capabilities(bgp, false);
1240 } else if (!gr_router_detected
1241 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1242 bgp_zebra_send_capabilities(bgp, true);
1243 }
1244
1245 if (!found)
1246 vty_out(vty,
1247 "%% BGP: No %s peer is configured with AS %s\n",
1248 get_afi_safi_str(afi, safi, false), arg);
1249
1250 return CMD_SUCCESS;
1251 }
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1257 safi_t safi, enum clear_sort sort,
1258 enum bgp_clear_type stype, const char *arg)
1259 {
1260 struct bgp *bgp;
1261
1262 /* BGP structure lookup. */
1263 if (name) {
1264 bgp = bgp_lookup_by_name(name);
1265 if (bgp == NULL) {
1266 vty_out(vty, "Can't find BGP instance %s\n", name);
1267 return CMD_WARNING;
1268 }
1269 } else {
1270 bgp = bgp_get_default();
1271 if (bgp == NULL) {
1272 vty_out(vty, "No BGP process is configured\n");
1273 return CMD_WARNING;
1274 }
1275 }
1276
1277 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1278 }
1279
1280 /* clear soft inbound */
1281 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1282 {
1283 afi_t afi;
1284 safi_t safi;
1285
1286 FOREACH_AFI_SAFI (afi, safi)
1287 bgp_clear_vty(vty, name, afi, safi, clear_all,
1288 BGP_CLEAR_SOFT_IN, NULL);
1289 }
1290
1291 /* clear soft outbound */
1292 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1293 {
1294 afi_t afi;
1295 safi_t safi;
1296
1297 FOREACH_AFI_SAFI (afi, safi)
1298 bgp_clear_vty(vty, name, afi, safi, clear_all,
1299 BGP_CLEAR_SOFT_OUT, NULL);
1300 }
1301
1302
1303 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1304 {
1305 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1306 }
1307
1308 #ifndef VTYSH_EXTRACT_PL
1309 #include "bgpd/bgp_vty_clippy.c"
1310 #endif
1311
1312 DEFUN_HIDDEN (bgp_local_mac,
1313 bgp_local_mac_cmd,
1314 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1315 BGP_STR
1316 "Local MAC config\n"
1317 "VxLAN Network Identifier\n"
1318 "VNI number\n"
1319 "local mac\n"
1320 "mac address\n"
1321 "mac-mobility sequence\n"
1322 "seq number\n")
1323 {
1324 int rv;
1325 vni_t vni;
1326 struct ethaddr mac;
1327 struct ipaddr ip;
1328 uint32_t seq;
1329 struct bgp *bgp;
1330
1331 vni = strtoul(argv[3]->arg, NULL, 10);
1332 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1333 vty_out(vty, "%% Malformed MAC address\n");
1334 return CMD_WARNING;
1335 }
1336 memset(&ip, 0, sizeof(ip));
1337 seq = strtoul(argv[7]->arg, NULL, 10);
1338
1339 bgp = bgp_get_default();
1340 if (!bgp) {
1341 vty_out(vty, "Default BGP instance is not there\n");
1342 return CMD_WARNING;
1343 }
1344
1345 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1346 zero_esi);
1347 if (rv < 0) {
1348 vty_out(vty, "Internal error\n");
1349 return CMD_WARNING;
1350 }
1351
1352 return CMD_SUCCESS;
1353 }
1354
1355 DEFUN_HIDDEN (no_bgp_local_mac,
1356 no_bgp_local_mac_cmd,
1357 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1358 NO_STR
1359 BGP_STR
1360 "Local MAC config\n"
1361 "VxLAN Network Identifier\n"
1362 "VNI number\n"
1363 "local mac\n"
1364 "mac address\n")
1365 {
1366 int rv;
1367 vni_t vni;
1368 struct ethaddr mac;
1369 struct ipaddr ip;
1370 struct bgp *bgp;
1371
1372 vni = strtoul(argv[4]->arg, NULL, 10);
1373 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1374 vty_out(vty, "%% Malformed MAC address\n");
1375 return CMD_WARNING;
1376 }
1377 memset(&ip, 0, sizeof(ip));
1378
1379 bgp = bgp_get_default();
1380 if (!bgp) {
1381 vty_out(vty, "Default BGP instance is not there\n");
1382 return CMD_WARNING;
1383 }
1384
1385 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1386 if (rv < 0) {
1387 vty_out(vty, "Internal error\n");
1388 return CMD_WARNING;
1389 }
1390
1391 return CMD_SUCCESS;
1392 }
1393
1394 DEFUN (no_synchronization,
1395 no_synchronization_cmd,
1396 "no synchronization",
1397 NO_STR
1398 "Perform IGP synchronization\n")
1399 {
1400 return CMD_SUCCESS;
1401 }
1402
1403 DEFUN (no_auto_summary,
1404 no_auto_summary_cmd,
1405 "no auto-summary",
1406 NO_STR
1407 "Enable automatic network number summarization\n")
1408 {
1409 return CMD_SUCCESS;
1410 }
1411
1412 /* "router bgp" commands. */
1413 DEFUN_NOSH (router_bgp,
1414 router_bgp_cmd,
1415 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1416 ROUTER_STR
1417 BGP_STR
1418 AS_STR
1419 BGP_INSTANCE_HELP_STR)
1420 {
1421 int idx_asn = 2;
1422 int idx_view_vrf = 3;
1423 int idx_vrf = 4;
1424 int is_new_bgp = 0;
1425 int ret;
1426 as_t as;
1427 struct bgp *bgp;
1428 const char *name = NULL;
1429 enum bgp_instance_type inst_type;
1430
1431 // "router bgp" without an ASN
1432 if (argc == 2) {
1433 // Pending: Make VRF option available for ASN less config
1434 bgp = bgp_get_default();
1435
1436 if (bgp == NULL) {
1437 vty_out(vty, "%% No BGP process is configured\n");
1438 return CMD_WARNING_CONFIG_FAILED;
1439 }
1440
1441 if (listcount(bm->bgp) > 1) {
1442 vty_out(vty, "%% Please specify ASN and VRF\n");
1443 return CMD_WARNING_CONFIG_FAILED;
1444 }
1445 }
1446
1447 // "router bgp X"
1448 else {
1449 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1450
1451 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1452 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1453 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1454
1455 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1456 if (argc > 3) {
1457 name = argv[idx_vrf]->arg;
1458
1459 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1460 if (strmatch(name, VRF_DEFAULT_NAME))
1461 name = NULL;
1462 else
1463 inst_type = BGP_INSTANCE_TYPE_VRF;
1464 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1465 inst_type = BGP_INSTANCE_TYPE_VIEW;
1466 }
1467
1468 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1469 is_new_bgp = (bgp_lookup(as, name) == NULL);
1470
1471 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1472 switch (ret) {
1473 case BGP_ERR_AS_MISMATCH:
1474 vty_out(vty, "BGP is already running; AS is %u\n", as);
1475 return CMD_WARNING_CONFIG_FAILED;
1476 case BGP_ERR_INSTANCE_MISMATCH:
1477 vty_out(vty,
1478 "BGP instance name and AS number mismatch\n");
1479 vty_out(vty,
1480 "BGP instance is already running; AS is %u\n",
1481 as);
1482 return CMD_WARNING_CONFIG_FAILED;
1483 }
1484
1485 /*
1486 * If we just instantiated the default instance, complete
1487 * any pending VRF-VPN leaking that was configured via
1488 * earlier "router bgp X vrf FOO" blocks.
1489 */
1490 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1491 vpn_leak_postchange_all();
1492
1493 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1494 bgp_vpn_leak_export(bgp);
1495 /* Pending: handle when user tries to change a view to vrf n vv.
1496 */
1497 }
1498
1499 /* unset the auto created flag as the user config is now present */
1500 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1501 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1502
1503 return CMD_SUCCESS;
1504 }
1505
1506 /* "no router bgp" commands. */
1507 DEFUN (no_router_bgp,
1508 no_router_bgp_cmd,
1509 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1510 NO_STR
1511 ROUTER_STR
1512 BGP_STR
1513 AS_STR
1514 BGP_INSTANCE_HELP_STR)
1515 {
1516 int idx_asn = 3;
1517 int idx_vrf = 5;
1518 as_t as;
1519 struct bgp *bgp;
1520 const char *name = NULL;
1521
1522 // "no router bgp" without an ASN
1523 if (argc == 3) {
1524 // Pending: Make VRF option available for ASN less config
1525 bgp = bgp_get_default();
1526
1527 if (bgp == NULL) {
1528 vty_out(vty, "%% No BGP process is configured\n");
1529 return CMD_WARNING_CONFIG_FAILED;
1530 }
1531
1532 if (listcount(bm->bgp) > 1) {
1533 vty_out(vty, "%% Please specify ASN and VRF\n");
1534 return CMD_WARNING_CONFIG_FAILED;
1535 }
1536
1537 if (bgp->l3vni) {
1538 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1539 bgp->l3vni);
1540 return CMD_WARNING_CONFIG_FAILED;
1541 }
1542 } else {
1543 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1544
1545 if (argc > 4) {
1546 name = argv[idx_vrf]->arg;
1547 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1548 && strmatch(name, VRF_DEFAULT_NAME))
1549 name = NULL;
1550 }
1551
1552 /* Lookup bgp structure. */
1553 bgp = bgp_lookup(as, name);
1554 if (!bgp) {
1555 vty_out(vty, "%% Can't find BGP instance\n");
1556 return CMD_WARNING_CONFIG_FAILED;
1557 }
1558
1559 if (bgp->l3vni) {
1560 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1561 bgp->l3vni);
1562 return CMD_WARNING_CONFIG_FAILED;
1563 }
1564
1565 /* Cannot delete default instance if vrf instances exist */
1566 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1567 struct listnode *node;
1568 struct bgp *tmp_bgp;
1569
1570 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1571 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1572 continue;
1573 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1574 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1575 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1576 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1577 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1578 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1579 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1580 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1581 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1582 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1583 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1584 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1585 (bgp == bgp_get_evpn() &&
1586 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1587 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1588 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1589 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1590 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1591 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1592 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1593 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1594 (hashcount(tmp_bgp->vnihash))) {
1595 vty_out(vty,
1596 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1597 return CMD_WARNING_CONFIG_FAILED;
1598 }
1599 }
1600 }
1601 }
1602
1603 bgp_delete(bgp);
1604
1605 return CMD_SUCCESS;
1606 }
1607
1608 /* bgp session-dscp */
1609
1610 DEFPY (bgp_session_dscp,
1611 bgp_session_dscp_cmd,
1612 "bgp session-dscp (0-63)$dscp",
1613 BGP_STR
1614 "Override default (C6) bgp TCP session DSCP value\n"
1615 "Manually configured dscp parameter\n")
1616 {
1617 bm->tcp_dscp = dscp << 2;
1618
1619 return CMD_SUCCESS;
1620 }
1621
1622 DEFPY (no_bgp_session_dscp,
1623 no_bgp_session_dscp_cmd,
1624 "no bgp session-dscp [(0-63)]",
1625 NO_STR
1626 BGP_STR
1627 "Override default (C6) bgp TCP session DSCP value\n"
1628 "Manually configured dscp parameter\n")
1629 {
1630 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1631
1632 return CMD_SUCCESS;
1633 }
1634
1635 /* BGP router-id. */
1636
1637 DEFPY (bgp_router_id,
1638 bgp_router_id_cmd,
1639 "bgp router-id A.B.C.D",
1640 BGP_STR
1641 "Override configured router identifier\n"
1642 "Manually configured router identifier\n")
1643 {
1644 VTY_DECLVAR_CONTEXT(bgp, bgp);
1645 bgp_router_id_static_set(bgp, router_id);
1646 return CMD_SUCCESS;
1647 }
1648
1649 DEFPY (no_bgp_router_id,
1650 no_bgp_router_id_cmd,
1651 "no bgp router-id [A.B.C.D]",
1652 NO_STR
1653 BGP_STR
1654 "Override configured router identifier\n"
1655 "Manually configured router identifier\n")
1656 {
1657 VTY_DECLVAR_CONTEXT(bgp, bgp);
1658
1659 if (router_id_str) {
1660 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1661 vty_out(vty, "%% BGP router-id doesn't match\n");
1662 return CMD_WARNING_CONFIG_FAILED;
1663 }
1664 }
1665
1666 router_id.s_addr = 0;
1667 bgp_router_id_static_set(bgp, router_id);
1668
1669 return CMD_SUCCESS;
1670 }
1671
1672 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1673 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1674 NO_STR BGP_STR
1675 "Add community specific parameters\n"
1676 "Create an alias for a community\n"
1677 "Community (AA:BB or AA:BB:CC)\n"
1678 "Alias name\n")
1679 {
1680 struct community_alias ca = {};
1681 struct community_alias *lookup_community;
1682 struct community_alias *lookup_alias;
1683 struct community *comm;
1684 struct lcommunity *lcomm;
1685 uint8_t invalid = 0;
1686
1687 comm = community_str2com(community);
1688 if (!comm)
1689 invalid++;
1690 community_free(&comm);
1691
1692 lcomm = lcommunity_str2com(community);
1693 if (!lcomm)
1694 invalid++;
1695 lcommunity_free(&lcomm);
1696
1697 if (invalid > 1) {
1698 vty_out(vty, "Invalid community format\n");
1699 return CMD_WARNING;
1700 }
1701
1702 strlcpy(ca.community, community, sizeof(ca.community));
1703 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1704
1705 lookup_community = bgp_ca_community_lookup(&ca);
1706 lookup_alias = bgp_ca_alias_lookup(&ca);
1707
1708 if (no) {
1709 bgp_ca_alias_delete(&ca);
1710 bgp_ca_community_delete(&ca);
1711 } else {
1712 if (lookup_alias) {
1713 /* Lookup if community hash table has an item
1714 * with the same alias name.
1715 */
1716 strlcpy(ca.community, lookup_alias->community,
1717 sizeof(ca.community));
1718 if (bgp_ca_community_lookup(&ca)) {
1719 vty_out(vty,
1720 "community (%s) already has this alias (%s)\n",
1721 lookup_alias->community,
1722 lookup_alias->alias);
1723 return CMD_WARNING;
1724 }
1725 bgp_ca_alias_delete(&ca);
1726 }
1727
1728 if (lookup_community) {
1729 /* Lookup if alias hash table has an item
1730 * with the same community.
1731 */
1732 strlcpy(ca.alias, lookup_community->alias,
1733 sizeof(ca.alias));
1734 if (bgp_ca_alias_lookup(&ca)) {
1735 vty_out(vty,
1736 "alias (%s) already has this community (%s)\n",
1737 lookup_community->alias,
1738 lookup_community->community);
1739 return CMD_WARNING;
1740 }
1741 bgp_ca_community_delete(&ca);
1742 }
1743
1744 bgp_ca_alias_insert(&ca);
1745 bgp_ca_community_insert(&ca);
1746 }
1747
1748 return CMD_SUCCESS;
1749 }
1750
1751 DEFPY (bgp_global_suppress_fib_pending,
1752 bgp_global_suppress_fib_pending_cmd,
1753 "[no] bgp suppress-fib-pending",
1754 NO_STR
1755 BGP_STR
1756 "Advertise only routes that are programmed in kernel to peers globally\n")
1757 {
1758 bm_wait_for_fib_set(!no);
1759
1760 return CMD_SUCCESS;
1761 }
1762
1763 DEFPY (bgp_suppress_fib_pending,
1764 bgp_suppress_fib_pending_cmd,
1765 "[no] bgp suppress-fib-pending",
1766 NO_STR
1767 BGP_STR
1768 "Advertise only routes that are programmed in kernel to peers\n")
1769 {
1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1771
1772 bgp_suppress_fib_pending_set(bgp, !no);
1773 return CMD_SUCCESS;
1774 }
1775
1776
1777 /* BGP Cluster ID. */
1778 DEFUN (bgp_cluster_id,
1779 bgp_cluster_id_cmd,
1780 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1781 BGP_STR
1782 "Configure Route-Reflector Cluster-id\n"
1783 "Route-Reflector Cluster-id in IP address format\n"
1784 "Route-Reflector Cluster-id as 32 bit quantity\n")
1785 {
1786 VTY_DECLVAR_CONTEXT(bgp, bgp);
1787 int idx_ipv4 = 2;
1788 int ret;
1789 struct in_addr cluster;
1790
1791 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1792 if (!ret) {
1793 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1794 return CMD_WARNING_CONFIG_FAILED;
1795 }
1796
1797 bgp_cluster_id_set(bgp, &cluster);
1798 bgp_clear_star_soft_out(vty, bgp->name);
1799
1800 return CMD_SUCCESS;
1801 }
1802
1803 DEFUN (no_bgp_cluster_id,
1804 no_bgp_cluster_id_cmd,
1805 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1806 NO_STR
1807 BGP_STR
1808 "Configure Route-Reflector Cluster-id\n"
1809 "Route-Reflector Cluster-id in IP address format\n"
1810 "Route-Reflector Cluster-id as 32 bit quantity\n")
1811 {
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 bgp_cluster_id_unset(bgp);
1814 bgp_clear_star_soft_out(vty, bgp->name);
1815
1816 return CMD_SUCCESS;
1817 }
1818
1819 DEFPY (bgp_norib,
1820 bgp_norib_cmd,
1821 "bgp no-rib",
1822 BGP_STR
1823 "Disable BGP route installation to RIB (Zebra)\n")
1824 {
1825 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1826 vty_out(vty,
1827 "%% No-RIB option is already set, nothing to do here.\n");
1828 return CMD_SUCCESS;
1829 }
1830
1831 bgp_option_norib_set_runtime();
1832
1833 return CMD_SUCCESS;
1834 }
1835
1836 DEFPY (no_bgp_norib,
1837 no_bgp_norib_cmd,
1838 "no bgp no-rib",
1839 NO_STR
1840 BGP_STR
1841 "Disable BGP route installation to RIB (Zebra)\n")
1842 {
1843 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1844 vty_out(vty,
1845 "%% No-RIB option is not set, nothing to do here.\n");
1846 return CMD_SUCCESS;
1847 }
1848
1849 bgp_option_norib_unset_runtime();
1850
1851 return CMD_SUCCESS;
1852 }
1853
1854 DEFPY (no_bgp_send_extra_data,
1855 no_bgp_send_extra_data_cmd,
1856 "[no] bgp send-extra-data zebra",
1857 NO_STR
1858 BGP_STR
1859 "Extra data to Zebra for display/use\n"
1860 "To zebra\n")
1861 {
1862 if (no)
1863 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1864 else
1865 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1866
1867 return CMD_SUCCESS;
1868 }
1869
1870 DEFUN (bgp_confederation_identifier,
1871 bgp_confederation_identifier_cmd,
1872 "bgp confederation identifier (1-4294967295)",
1873 BGP_STR
1874 "AS confederation parameters\n"
1875 "AS number\n"
1876 "Set routing domain confederation AS\n")
1877 {
1878 VTY_DECLVAR_CONTEXT(bgp, bgp);
1879 int idx_number = 3;
1880 as_t as;
1881
1882 as = strtoul(argv[idx_number]->arg, NULL, 10);
1883
1884 bgp_confederation_id_set(bgp, as);
1885
1886 return CMD_SUCCESS;
1887 }
1888
1889 DEFUN (no_bgp_confederation_identifier,
1890 no_bgp_confederation_identifier_cmd,
1891 "no bgp confederation identifier [(1-4294967295)]",
1892 NO_STR
1893 BGP_STR
1894 "AS confederation parameters\n"
1895 "AS number\n"
1896 "Set routing domain confederation AS\n")
1897 {
1898 VTY_DECLVAR_CONTEXT(bgp, bgp);
1899 bgp_confederation_id_unset(bgp);
1900
1901 return CMD_SUCCESS;
1902 }
1903
1904 DEFUN (bgp_confederation_peers,
1905 bgp_confederation_peers_cmd,
1906 "bgp confederation peers (1-4294967295)...",
1907 BGP_STR
1908 "AS confederation parameters\n"
1909 "Peer ASs in BGP confederation\n"
1910 AS_STR)
1911 {
1912 VTY_DECLVAR_CONTEXT(bgp, bgp);
1913 int idx_asn = 3;
1914 as_t as;
1915 int i;
1916
1917 for (i = idx_asn; i < argc; i++) {
1918 as = strtoul(argv[i]->arg, NULL, 10);
1919
1920 if (bgp->as == as) {
1921 vty_out(vty,
1922 "%% Local member-AS not allowed in confed peer list\n");
1923 continue;
1924 }
1925
1926 bgp_confederation_peers_add(bgp, as);
1927 }
1928 return CMD_SUCCESS;
1929 }
1930
1931 DEFUN (no_bgp_confederation_peers,
1932 no_bgp_confederation_peers_cmd,
1933 "no bgp confederation peers (1-4294967295)...",
1934 NO_STR
1935 BGP_STR
1936 "AS confederation parameters\n"
1937 "Peer ASs in BGP confederation\n"
1938 AS_STR)
1939 {
1940 VTY_DECLVAR_CONTEXT(bgp, bgp);
1941 int idx_asn = 4;
1942 as_t as;
1943 int i;
1944
1945 for (i = idx_asn; i < argc; i++) {
1946 as = strtoul(argv[i]->arg, NULL, 10);
1947
1948 bgp_confederation_peers_remove(bgp, as);
1949 }
1950 return CMD_SUCCESS;
1951 }
1952
1953 /**
1954 * Central routine for maximum-paths configuration.
1955 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1956 * @set: 1 for setting values, 0 for removing the max-paths config.
1957 */
1958 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1959 const char *mpaths, uint16_t options,
1960 int set)
1961 {
1962 VTY_DECLVAR_CONTEXT(bgp, bgp);
1963 uint16_t maxpaths = 0;
1964 int ret;
1965 afi_t afi;
1966 safi_t safi;
1967
1968 afi = bgp_node_afi(vty);
1969 safi = bgp_node_safi(vty);
1970
1971 if (set) {
1972 maxpaths = strtol(mpaths, NULL, 10);
1973 if (maxpaths > multipath_num) {
1974 vty_out(vty,
1975 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1976 maxpaths, multipath_num);
1977 return CMD_WARNING_CONFIG_FAILED;
1978 }
1979 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1980 options);
1981 } else
1982 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1983
1984 if (ret < 0) {
1985 vty_out(vty,
1986 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1987 (set == 1) ? "" : "un",
1988 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1989 maxpaths, afi, safi);
1990 return CMD_WARNING_CONFIG_FAILED;
1991 }
1992
1993 bgp_recalculate_all_bestpaths(bgp);
1994
1995 return CMD_SUCCESS;
1996 }
1997
1998 DEFUN (bgp_maxmed_admin,
1999 bgp_maxmed_admin_cmd,
2000 "bgp max-med administrative ",
2001 BGP_STR
2002 "Advertise routes with max-med\n"
2003 "Administratively applied, for an indefinite period\n")
2004 {
2005 VTY_DECLVAR_CONTEXT(bgp, bgp);
2006
2007 bgp->v_maxmed_admin = 1;
2008 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2009
2010 bgp_maxmed_update(bgp);
2011
2012 return CMD_SUCCESS;
2013 }
2014
2015 DEFUN (bgp_maxmed_admin_medv,
2016 bgp_maxmed_admin_medv_cmd,
2017 "bgp max-med administrative (0-4294967295)",
2018 BGP_STR
2019 "Advertise routes with max-med\n"
2020 "Administratively applied, for an indefinite period\n"
2021 "Max MED value to be used\n")
2022 {
2023 VTY_DECLVAR_CONTEXT(bgp, bgp);
2024 int idx_number = 3;
2025
2026 bgp->v_maxmed_admin = 1;
2027 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2028
2029 bgp_maxmed_update(bgp);
2030
2031 return CMD_SUCCESS;
2032 }
2033
2034 DEFUN (no_bgp_maxmed_admin,
2035 no_bgp_maxmed_admin_cmd,
2036 "no bgp max-med administrative [(0-4294967295)]",
2037 NO_STR
2038 BGP_STR
2039 "Advertise routes with max-med\n"
2040 "Administratively applied, for an indefinite period\n"
2041 "Max MED value to be used\n")
2042 {
2043 VTY_DECLVAR_CONTEXT(bgp, bgp);
2044 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2045 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2046 bgp_maxmed_update(bgp);
2047
2048 return CMD_SUCCESS;
2049 }
2050
2051 DEFUN (bgp_maxmed_onstartup,
2052 bgp_maxmed_onstartup_cmd,
2053 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2054 BGP_STR
2055 "Advertise routes with max-med\n"
2056 "Effective on a startup\n"
2057 "Time (seconds) period for max-med\n"
2058 "Max MED value to be used\n")
2059 {
2060 VTY_DECLVAR_CONTEXT(bgp, bgp);
2061 int idx = 0;
2062
2063 if (argv_find(argv, argc, "(5-86400)", &idx))
2064 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2065 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2066 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2067 else
2068 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2069
2070 bgp_maxmed_update(bgp);
2071
2072 return CMD_SUCCESS;
2073 }
2074
2075 DEFUN (no_bgp_maxmed_onstartup,
2076 no_bgp_maxmed_onstartup_cmd,
2077 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2078 NO_STR
2079 BGP_STR
2080 "Advertise routes with max-med\n"
2081 "Effective on a startup\n"
2082 "Time (seconds) period for max-med\n"
2083 "Max MED value to be used\n")
2084 {
2085 VTY_DECLVAR_CONTEXT(bgp, bgp);
2086
2087 /* Cancel max-med onstartup if its on */
2088 if (bgp->t_maxmed_onstartup) {
2089 THREAD_OFF(bgp->t_maxmed_onstartup);
2090 bgp->maxmed_onstartup_over = 1;
2091 }
2092
2093 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2094 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2095
2096 bgp_maxmed_update(bgp);
2097
2098 return CMD_SUCCESS;
2099 }
2100
2101 static int bgp_global_update_delay_config_vty(struct vty *vty,
2102 uint16_t update_delay,
2103 uint16_t establish_wait)
2104 {
2105 struct listnode *node, *nnode;
2106 struct bgp *bgp;
2107 bool vrf_cfg = false;
2108
2109 /*
2110 * See if update-delay is set per-vrf and warn user to delete it
2111 * Note that we only need to check this if this is the first time
2112 * setting the global config.
2113 */
2114 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2115 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2116 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2117 vty_out(vty,
2118 "%% update-delay configuration found in vrf %s\n",
2119 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2120 ? VRF_DEFAULT_NAME
2121 : bgp->name);
2122 vrf_cfg = true;
2123 }
2124 }
2125 }
2126
2127 if (vrf_cfg) {
2128 vty_out(vty,
2129 "%%Failed: global update-delay config not permitted\n");
2130 return CMD_WARNING;
2131 }
2132
2133 if (!establish_wait) { /* update-delay <delay> */
2134 bm->v_update_delay = update_delay;
2135 bm->v_establish_wait = bm->v_update_delay;
2136 } else {
2137 /* update-delay <delay> <establish-wait> */
2138 if (update_delay < establish_wait) {
2139 vty_out(vty,
2140 "%%Failed: update-delay less than the establish-wait!\n");
2141 return CMD_WARNING_CONFIG_FAILED;
2142 }
2143
2144 bm->v_update_delay = update_delay;
2145 bm->v_establish_wait = establish_wait;
2146 }
2147
2148 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2149 bgp->v_update_delay = bm->v_update_delay;
2150 bgp->v_establish_wait = bm->v_establish_wait;
2151 }
2152
2153 return CMD_SUCCESS;
2154 }
2155
2156 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2157 {
2158 struct listnode *node, *nnode;
2159 struct bgp *bgp;
2160
2161 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2162 bm->v_establish_wait = bm->v_update_delay;
2163
2164 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2165 bgp->v_update_delay = bm->v_update_delay;
2166 bgp->v_establish_wait = bm->v_establish_wait;
2167 }
2168
2169 return CMD_SUCCESS;
2170 }
2171
2172 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2173 uint16_t establish_wait)
2174 {
2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176
2177 /* if configured globally, per-instance config is not allowed */
2178 if (bm->v_update_delay) {
2179 vty_out(vty,
2180 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2181 return CMD_WARNING_CONFIG_FAILED;
2182 }
2183
2184
2185 if (!establish_wait) /* update-delay <delay> */
2186 {
2187 bgp->v_update_delay = update_delay;
2188 bgp->v_establish_wait = bgp->v_update_delay;
2189 return CMD_SUCCESS;
2190 }
2191
2192 /* update-delay <delay> <establish-wait> */
2193 if (update_delay < establish_wait) {
2194 vty_out(vty,
2195 "%%Failed: update-delay less than the establish-wait!\n");
2196 return CMD_WARNING_CONFIG_FAILED;
2197 }
2198
2199 bgp->v_update_delay = update_delay;
2200 bgp->v_establish_wait = establish_wait;
2201
2202 return CMD_SUCCESS;
2203 }
2204
2205 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2206 {
2207 VTY_DECLVAR_CONTEXT(bgp, bgp);
2208
2209 /* If configured globally, cannot remove from one bgp instance */
2210 if (bm->v_update_delay) {
2211 vty_out(vty,
2212 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2213 return CMD_WARNING_CONFIG_FAILED;
2214 }
2215 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2216 bgp->v_establish_wait = bgp->v_update_delay;
2217
2218 return CMD_SUCCESS;
2219 }
2220
2221 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2222 {
2223 /* If configured globally, no need to display per-instance value */
2224 if (bgp->v_update_delay != bm->v_update_delay) {
2225 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2226 if (bgp->v_update_delay != bgp->v_establish_wait)
2227 vty_out(vty, " %d", bgp->v_establish_wait);
2228 vty_out(vty, "\n");
2229 }
2230 }
2231
2232 /* Global update-delay configuration */
2233 DEFPY (bgp_global_update_delay,
2234 bgp_global_update_delay_cmd,
2235 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2236 BGP_STR
2237 "Force initial delay for best-path and updates for all bgp instances\n"
2238 "Max delay in seconds\n"
2239 "Establish wait in seconds\n")
2240 {
2241 return bgp_global_update_delay_config_vty(vty, delay, wait);
2242 }
2243
2244 /* Global update-delay deconfiguration */
2245 DEFPY (no_bgp_global_update_delay,
2246 no_bgp_global_update_delay_cmd,
2247 "no bgp update-delay [(0-3600) [(1-3600)]]",
2248 NO_STR
2249 BGP_STR
2250 "Force initial delay for best-path and updates\n"
2251 "Max delay in seconds\n"
2252 "Establish wait in seconds\n")
2253 {
2254 return bgp_global_update_delay_deconfig_vty(vty);
2255 }
2256
2257 /* Update-delay configuration */
2258
2259 DEFPY (bgp_update_delay,
2260 bgp_update_delay_cmd,
2261 "update-delay (0-3600)$delay [(1-3600)$wait]",
2262 "Force initial delay for best-path and updates\n"
2263 "Max delay in seconds\n"
2264 "Establish wait in seconds\n")
2265 {
2266 return bgp_update_delay_config_vty(vty, delay, wait);
2267 }
2268
2269 /* Update-delay deconfiguration */
2270 DEFPY (no_bgp_update_delay,
2271 no_bgp_update_delay_cmd,
2272 "no update-delay [(0-3600) [(1-3600)]]",
2273 NO_STR
2274 "Force initial delay for best-path and updates\n"
2275 "Max delay in seconds\n"
2276 "Establish wait in seconds\n")
2277 {
2278 return bgp_update_delay_deconfig_vty(vty);
2279 }
2280
2281
2282 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2283 bool set)
2284 {
2285 VTY_DECLVAR_CONTEXT(bgp, bgp);
2286
2287 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2288 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2289
2290 return CMD_SUCCESS;
2291 }
2292
2293 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2294 bool set)
2295 {
2296 VTY_DECLVAR_CONTEXT(bgp, bgp);
2297
2298 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2299 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2300
2301 return CMD_SUCCESS;
2302 }
2303
2304 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2305 {
2306 uint32_t quanta =
2307 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2308 if (quanta != BGP_WRITE_PACKET_MAX)
2309 vty_out(vty, " write-quanta %d\n", quanta);
2310 }
2311
2312 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2313 {
2314 uint32_t quanta =
2315 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2316 if (quanta != BGP_READ_PACKET_MAX)
2317 vty_out(vty, " read-quanta %d\n", quanta);
2318 }
2319
2320 /* Packet quanta configuration
2321 *
2322 * XXX: The value set here controls the size of a stack buffer in the IO
2323 * thread. When changing these limits be careful to prevent stack overflow.
2324 *
2325 * Furthermore, the maximums used here should correspond to
2326 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2327 */
2328 DEFPY (bgp_wpkt_quanta,
2329 bgp_wpkt_quanta_cmd,
2330 "[no] write-quanta (1-64)$quanta",
2331 NO_STR
2332 "How many packets to write to peer socket per run\n"
2333 "Number of packets\n")
2334 {
2335 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2336 }
2337
2338 DEFPY (bgp_rpkt_quanta,
2339 bgp_rpkt_quanta_cmd,
2340 "[no] read-quanta (1-10)$quanta",
2341 NO_STR
2342 "How many packets to read from peer socket per I/O cycle\n"
2343 "Number of packets\n")
2344 {
2345 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2346 }
2347
2348 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2349 {
2350 if (!bgp->heuristic_coalesce)
2351 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2352 }
2353
2354 /* BGP TCP keepalive */
2355 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2356 {
2357 if (bgp->tcp_keepalive_idle) {
2358 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2359 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2360 bgp->tcp_keepalive_probes);
2361 }
2362 }
2363
2364 DEFUN (bgp_coalesce_time,
2365 bgp_coalesce_time_cmd,
2366 "coalesce-time (0-4294967295)",
2367 "Subgroup coalesce timer\n"
2368 "Subgroup coalesce timer value (in ms)\n")
2369 {
2370 VTY_DECLVAR_CONTEXT(bgp, bgp);
2371
2372 int idx = 0;
2373
2374 bgp->heuristic_coalesce = false;
2375
2376 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2377 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2378
2379 return CMD_SUCCESS;
2380 }
2381
2382 DEFUN (no_bgp_coalesce_time,
2383 no_bgp_coalesce_time_cmd,
2384 "no coalesce-time (0-4294967295)",
2385 NO_STR
2386 "Subgroup coalesce timer\n"
2387 "Subgroup coalesce timer value (in ms)\n")
2388 {
2389 VTY_DECLVAR_CONTEXT(bgp, bgp);
2390
2391 bgp->heuristic_coalesce = true;
2392 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2393 return CMD_SUCCESS;
2394 }
2395
2396 /* Maximum-paths configuration */
2397 DEFUN (bgp_maxpaths,
2398 bgp_maxpaths_cmd,
2399 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2400 "Forward packets over multiple paths\n"
2401 "Number of paths\n")
2402 {
2403 int idx_number = 1;
2404 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2405 argv[idx_number]->arg, 0, 1);
2406 }
2407
2408 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2409 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2410 "Forward packets over multiple paths\n"
2411 "Number of paths\n")
2412
2413 DEFUN (bgp_maxpaths_ibgp,
2414 bgp_maxpaths_ibgp_cmd,
2415 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2416 "Forward packets over multiple paths\n"
2417 "iBGP-multipath\n"
2418 "Number of paths\n")
2419 {
2420 int idx_number = 2;
2421 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2422 argv[idx_number]->arg, 0, 1);
2423 }
2424
2425 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2426 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2427 "Forward packets over multiple paths\n"
2428 "iBGP-multipath\n"
2429 "Number of paths\n")
2430
2431 DEFUN (bgp_maxpaths_ibgp_cluster,
2432 bgp_maxpaths_ibgp_cluster_cmd,
2433 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2434 "Forward packets over multiple paths\n"
2435 "iBGP-multipath\n"
2436 "Number of paths\n"
2437 "Match the cluster length\n")
2438 {
2439 int idx_number = 2;
2440 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2441 argv[idx_number]->arg, true, 1);
2442 }
2443
2444 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2445 "maximum-paths ibgp " CMD_RANGE_STR(
2446 1, MULTIPATH_NUM) " equal-cluster-length",
2447 "Forward packets over multiple paths\n"
2448 "iBGP-multipath\n"
2449 "Number of paths\n"
2450 "Match the cluster length\n")
2451
2452 DEFUN (no_bgp_maxpaths,
2453 no_bgp_maxpaths_cmd,
2454 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2455 NO_STR
2456 "Forward packets over multiple paths\n"
2457 "Number of paths\n")
2458 {
2459 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2460 }
2461
2462 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2463 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2464 "Forward packets over multiple paths\n"
2465 "Number of paths\n")
2466
2467 DEFUN (no_bgp_maxpaths_ibgp,
2468 no_bgp_maxpaths_ibgp_cmd,
2469 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2470 NO_STR
2471 "Forward packets over multiple paths\n"
2472 "iBGP-multipath\n"
2473 "Number of paths\n"
2474 "Match the cluster length\n")
2475 {
2476 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2477 }
2478
2479 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2480 "no maximum-paths ibgp [" CMD_RANGE_STR(
2481 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2482 NO_STR
2483 "Forward packets over multiple paths\n"
2484 "iBGP-multipath\n"
2485 "Number of paths\n"
2486 "Match the cluster length\n")
2487
2488 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2489 afi_t afi, safi_t safi)
2490 {
2491 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2492 vty_out(vty, " maximum-paths %d\n",
2493 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2494 }
2495
2496 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2497 vty_out(vty, " maximum-paths ibgp %d",
2498 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2499 if (bgp->maxpaths[afi][safi].same_clusterlen)
2500 vty_out(vty, " equal-cluster-length");
2501 vty_out(vty, "\n");
2502 }
2503 }
2504
2505 /* BGP timers. */
2506
2507 DEFUN (bgp_timers,
2508 bgp_timers_cmd,
2509 "timers bgp (0-65535) (0-65535)",
2510 "Adjust routing timers\n"
2511 "BGP timers\n"
2512 "Keepalive interval\n"
2513 "Holdtime\n")
2514 {
2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
2516 int idx_number = 2;
2517 int idx_number_2 = 3;
2518 unsigned long keepalive = 0;
2519 unsigned long holdtime = 0;
2520
2521 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2522 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2523
2524 /* Holdtime value check. */
2525 if (holdtime < 3 && holdtime != 0) {
2526 vty_out(vty,
2527 "%% hold time value must be either 0 or greater than 3\n");
2528 return CMD_WARNING_CONFIG_FAILED;
2529 }
2530
2531 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2532 BGP_DEFAULT_DELAYOPEN);
2533
2534 return CMD_SUCCESS;
2535 }
2536
2537 DEFUN (no_bgp_timers,
2538 no_bgp_timers_cmd,
2539 "no timers bgp [(0-65535) (0-65535)]",
2540 NO_STR
2541 "Adjust routing timers\n"
2542 "BGP timers\n"
2543 "Keepalive interval\n"
2544 "Holdtime\n")
2545 {
2546 VTY_DECLVAR_CONTEXT(bgp, bgp);
2547 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2548 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2549
2550 return CMD_SUCCESS;
2551 }
2552
2553 /* BGP minimum holdtime. */
2554
2555 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2556 "bgp minimum-holdtime (1-65535)",
2557 "BGP specific commands\n"
2558 "BGP minimum holdtime\n"
2559 "Seconds\n")
2560 {
2561 VTY_DECLVAR_CONTEXT(bgp, bgp);
2562 int idx_number = 2;
2563 unsigned long min_holdtime;
2564
2565 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2566
2567 bgp->default_min_holdtime = min_holdtime;
2568
2569 return CMD_SUCCESS;
2570 }
2571
2572 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2573 "no bgp minimum-holdtime [(1-65535)]",
2574 NO_STR
2575 "BGP specific commands\n"
2576 "BGP minimum holdtime\n"
2577 "Seconds\n")
2578 {
2579 VTY_DECLVAR_CONTEXT(bgp, bgp);
2580
2581 bgp->default_min_holdtime = 0;
2582
2583 return CMD_SUCCESS;
2584 }
2585
2586 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2587 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2588 BGP_STR
2589 "TCP keepalive parameters\n"
2590 "TCP keepalive idle time (seconds)\n"
2591 "TCP keepalive interval (seconds)\n"
2592 "TCP keepalive maximum probes\n")
2593 {
2594 VTY_DECLVAR_CONTEXT(bgp, bgp);
2595
2596 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2597 (uint16_t)probes);
2598
2599 return CMD_SUCCESS;
2600 }
2601
2602 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2603 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2604 NO_STR
2605 BGP_STR
2606 "TCP keepalive parameters\n"
2607 "TCP keepalive idle time (seconds)\n"
2608 "TCP keepalive interval (seconds)\n"
2609 "TCP keepalive maximum probes\n")
2610 {
2611 VTY_DECLVAR_CONTEXT(bgp, bgp);
2612
2613 bgp_tcp_keepalive_unset(bgp);
2614
2615 return CMD_SUCCESS;
2616 }
2617
2618 DEFUN (bgp_client_to_client_reflection,
2619 bgp_client_to_client_reflection_cmd,
2620 "bgp client-to-client reflection",
2621 BGP_STR
2622 "Configure client to client route reflection\n"
2623 "reflection of routes allowed\n")
2624 {
2625 VTY_DECLVAR_CONTEXT(bgp, bgp);
2626 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2627 bgp_clear_star_soft_out(vty, bgp->name);
2628
2629 return CMD_SUCCESS;
2630 }
2631
2632 DEFUN (no_bgp_client_to_client_reflection,
2633 no_bgp_client_to_client_reflection_cmd,
2634 "no bgp client-to-client reflection",
2635 NO_STR
2636 BGP_STR
2637 "Configure client to client route reflection\n"
2638 "reflection of routes allowed\n")
2639 {
2640 VTY_DECLVAR_CONTEXT(bgp, bgp);
2641 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2642 bgp_clear_star_soft_out(vty, bgp->name);
2643
2644 return CMD_SUCCESS;
2645 }
2646
2647 /* "bgp always-compare-med" configuration. */
2648 DEFUN (bgp_always_compare_med,
2649 bgp_always_compare_med_cmd,
2650 "bgp always-compare-med",
2651 BGP_STR
2652 "Allow comparing MED from different neighbors\n")
2653 {
2654 VTY_DECLVAR_CONTEXT(bgp, bgp);
2655 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2656 bgp_recalculate_all_bestpaths(bgp);
2657
2658 return CMD_SUCCESS;
2659 }
2660
2661 DEFUN (no_bgp_always_compare_med,
2662 no_bgp_always_compare_med_cmd,
2663 "no bgp always-compare-med",
2664 NO_STR
2665 BGP_STR
2666 "Allow comparing MED from different neighbors\n")
2667 {
2668 VTY_DECLVAR_CONTEXT(bgp, bgp);
2669 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2670 bgp_recalculate_all_bestpaths(bgp);
2671
2672 return CMD_SUCCESS;
2673 }
2674
2675
2676 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2677 "bgp ebgp-requires-policy",
2678 BGP_STR
2679 "Require in and out policy for eBGP peers (RFC8212)\n")
2680 {
2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
2682 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2683 return CMD_SUCCESS;
2684 }
2685
2686 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2687 "no bgp ebgp-requires-policy",
2688 NO_STR
2689 BGP_STR
2690 "Require in and out policy for eBGP peers (RFC8212)\n")
2691 {
2692 VTY_DECLVAR_CONTEXT(bgp, bgp);
2693 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2694 return CMD_SUCCESS;
2695 }
2696
2697 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2698 "bgp suppress-duplicates",
2699 BGP_STR
2700 "Suppress duplicate updates if the route actually not changed\n")
2701 {
2702 VTY_DECLVAR_CONTEXT(bgp, bgp);
2703 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2704 return CMD_SUCCESS;
2705 }
2706
2707 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2708 "no bgp suppress-duplicates",
2709 NO_STR
2710 BGP_STR
2711 "Suppress duplicate updates if the route actually not changed\n")
2712 {
2713 VTY_DECLVAR_CONTEXT(bgp, bgp);
2714 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2715 return CMD_SUCCESS;
2716 }
2717
2718 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2719 "bgp reject-as-sets",
2720 BGP_STR
2721 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2722 {
2723 VTY_DECLVAR_CONTEXT(bgp, bgp);
2724 struct listnode *node, *nnode;
2725 struct peer *peer;
2726
2727 bgp->reject_as_sets = true;
2728
2729 /* Reset existing BGP sessions to reject routes
2730 * with aspath containing AS_SET or AS_CONFED_SET.
2731 */
2732 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2733 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2734 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2735 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2736 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2737 }
2738 }
2739
2740 return CMD_SUCCESS;
2741 }
2742
2743 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2744 "no bgp reject-as-sets",
2745 NO_STR
2746 BGP_STR
2747 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2748 {
2749 VTY_DECLVAR_CONTEXT(bgp, bgp);
2750 struct listnode *node, *nnode;
2751 struct peer *peer;
2752
2753 bgp->reject_as_sets = false;
2754
2755 /* Reset existing BGP sessions to reject routes
2756 * with aspath containing AS_SET or AS_CONFED_SET.
2757 */
2758 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2759 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2760 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2761 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2762 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2763 }
2764 }
2765
2766 return CMD_SUCCESS;
2767 }
2768
2769 /* "bgp deterministic-med" configuration. */
2770 DEFUN (bgp_deterministic_med,
2771 bgp_deterministic_med_cmd,
2772 "bgp deterministic-med",
2773 BGP_STR
2774 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2775 {
2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777
2778 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2779 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2780 bgp_recalculate_all_bestpaths(bgp);
2781 }
2782
2783 return CMD_SUCCESS;
2784 }
2785
2786 DEFUN (no_bgp_deterministic_med,
2787 no_bgp_deterministic_med_cmd,
2788 "no bgp deterministic-med",
2789 NO_STR
2790 BGP_STR
2791 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2792 {
2793 VTY_DECLVAR_CONTEXT(bgp, bgp);
2794 int bestpath_per_as_used;
2795 afi_t afi;
2796 safi_t safi;
2797 struct peer *peer;
2798 struct listnode *node, *nnode;
2799
2800 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2801 bestpath_per_as_used = 0;
2802
2803 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2804 FOREACH_AFI_SAFI (afi, safi)
2805 if (bgp_addpath_dmed_required(
2806 peer->addpath_type[afi][safi])) {
2807 bestpath_per_as_used = 1;
2808 break;
2809 }
2810
2811 if (bestpath_per_as_used)
2812 break;
2813 }
2814
2815 if (bestpath_per_as_used) {
2816 vty_out(vty,
2817 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2818 return CMD_WARNING_CONFIG_FAILED;
2819 } else {
2820 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2821 bgp_recalculate_all_bestpaths(bgp);
2822 }
2823 }
2824
2825 return CMD_SUCCESS;
2826 }
2827
2828 /* "bgp graceful-restart mode" configuration. */
2829 DEFUN (bgp_graceful_restart,
2830 bgp_graceful_restart_cmd,
2831 "bgp graceful-restart",
2832 BGP_STR
2833 GR_CMD
2834 )
2835 {
2836 int ret = BGP_GR_FAILURE;
2837
2838 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2839 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2840
2841 VTY_DECLVAR_CONTEXT(bgp, bgp);
2842
2843 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2844
2845 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2846 ret);
2847
2848 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2849 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2850 vty_out(vty,
2851 "Graceful restart configuration changed, reset all peers to take effect\n");
2852 return bgp_vty_return(vty, ret);
2853 }
2854
2855 DEFUN (no_bgp_graceful_restart,
2856 no_bgp_graceful_restart_cmd,
2857 "no bgp graceful-restart",
2858 NO_STR
2859 BGP_STR
2860 NO_GR_CMD
2861 )
2862 {
2863 VTY_DECLVAR_CONTEXT(bgp, bgp);
2864
2865 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2866 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2867
2868 int ret = BGP_GR_FAILURE;
2869
2870 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2871
2872 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2873 ret);
2874
2875 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2876 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2877 vty_out(vty,
2878 "Graceful restart configuration changed, reset all peers to take effect\n");
2879
2880 return bgp_vty_return(vty, ret);
2881 }
2882
2883 DEFUN (bgp_graceful_restart_stalepath_time,
2884 bgp_graceful_restart_stalepath_time_cmd,
2885 "bgp graceful-restart stalepath-time (1-4095)",
2886 BGP_STR
2887 "Graceful restart capability parameters\n"
2888 "Set the max time to hold onto restarting peer's stale paths\n"
2889 "Delay value (seconds)\n")
2890 {
2891 VTY_DECLVAR_CONTEXT(bgp, bgp);
2892 int idx_number = 3;
2893 uint32_t stalepath;
2894
2895 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2896 bgp->stalepath_time = stalepath;
2897 return CMD_SUCCESS;
2898 }
2899
2900 DEFUN (bgp_graceful_restart_restart_time,
2901 bgp_graceful_restart_restart_time_cmd,
2902 "bgp graceful-restart restart-time (0-4095)",
2903 BGP_STR
2904 "Graceful restart capability parameters\n"
2905 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2906 "Delay value (seconds)\n")
2907 {
2908 VTY_DECLVAR_CONTEXT(bgp, bgp);
2909 int idx_number = 3;
2910 uint32_t restart;
2911
2912 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2913 bgp->restart_time = restart;
2914 return CMD_SUCCESS;
2915 }
2916
2917 DEFUN (bgp_graceful_restart_select_defer_time,
2918 bgp_graceful_restart_select_defer_time_cmd,
2919 "bgp graceful-restart select-defer-time (0-3600)",
2920 BGP_STR
2921 "Graceful restart capability parameters\n"
2922 "Set the time to defer the BGP route selection after restart\n"
2923 "Delay value (seconds, 0 - disable)\n")
2924 {
2925 VTY_DECLVAR_CONTEXT(bgp, bgp);
2926 int idx_number = 3;
2927 uint32_t defer_time;
2928
2929 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2930 bgp->select_defer_time = defer_time;
2931 if (defer_time == 0)
2932 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2933 else
2934 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2935
2936 return CMD_SUCCESS;
2937 }
2938
2939 DEFUN (no_bgp_graceful_restart_stalepath_time,
2940 no_bgp_graceful_restart_stalepath_time_cmd,
2941 "no bgp graceful-restart stalepath-time [(1-4095)]",
2942 NO_STR
2943 BGP_STR
2944 "Graceful restart capability parameters\n"
2945 "Set the max time to hold onto restarting peer's stale paths\n"
2946 "Delay value (seconds)\n")
2947 {
2948 VTY_DECLVAR_CONTEXT(bgp, bgp);
2949
2950 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2951 return CMD_SUCCESS;
2952 }
2953
2954 DEFUN (no_bgp_graceful_restart_restart_time,
2955 no_bgp_graceful_restart_restart_time_cmd,
2956 "no bgp graceful-restart restart-time [(0-4095)]",
2957 NO_STR
2958 BGP_STR
2959 "Graceful restart capability parameters\n"
2960 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2961 "Delay value (seconds)\n")
2962 {
2963 VTY_DECLVAR_CONTEXT(bgp, bgp);
2964
2965 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2966 return CMD_SUCCESS;
2967 }
2968
2969 DEFUN (no_bgp_graceful_restart_select_defer_time,
2970 no_bgp_graceful_restart_select_defer_time_cmd,
2971 "no bgp graceful-restart select-defer-time [(0-3600)]",
2972 NO_STR
2973 BGP_STR
2974 "Graceful restart capability parameters\n"
2975 "Set the time to defer the BGP route selection after restart\n"
2976 "Delay value (seconds)\n")
2977 {
2978 VTY_DECLVAR_CONTEXT(bgp, bgp);
2979
2980 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2981 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2982
2983 return CMD_SUCCESS;
2984 }
2985
2986 DEFUN (bgp_graceful_restart_preserve_fw,
2987 bgp_graceful_restart_preserve_fw_cmd,
2988 "bgp graceful-restart preserve-fw-state",
2989 BGP_STR
2990 "Graceful restart capability parameters\n"
2991 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2992 {
2993 VTY_DECLVAR_CONTEXT(bgp, bgp);
2994 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2995 return CMD_SUCCESS;
2996 }
2997
2998 DEFUN (no_bgp_graceful_restart_preserve_fw,
2999 no_bgp_graceful_restart_preserve_fw_cmd,
3000 "no bgp graceful-restart preserve-fw-state",
3001 NO_STR
3002 BGP_STR
3003 "Graceful restart capability parameters\n"
3004 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3005 {
3006 VTY_DECLVAR_CONTEXT(bgp, bgp);
3007 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3008 return CMD_SUCCESS;
3009 }
3010
3011 DEFPY (bgp_graceful_restart_notification,
3012 bgp_graceful_restart_notification_cmd,
3013 "[no$no] bgp graceful-restart notification",
3014 NO_STR
3015 BGP_STR
3016 "Graceful restart capability parameters\n"
3017 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3018 {
3019 VTY_DECLVAR_CONTEXT(bgp, bgp);
3020
3021 if (no)
3022 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3023 else
3024 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3025
3026 return CMD_SUCCESS;
3027 }
3028
3029 DEFPY (bgp_administrative_reset,
3030 bgp_administrative_reset_cmd,
3031 "[no$no] bgp hard-administrative-reset",
3032 NO_STR
3033 BGP_STR
3034 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3035 {
3036 VTY_DECLVAR_CONTEXT(bgp, bgp);
3037
3038 if (no)
3039 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3040 else
3041 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3042
3043 return CMD_SUCCESS;
3044 }
3045
3046 DEFUN (bgp_graceful_restart_disable,
3047 bgp_graceful_restart_disable_cmd,
3048 "bgp graceful-restart-disable",
3049 BGP_STR
3050 GR_DISABLE)
3051 {
3052 int ret = BGP_GR_FAILURE;
3053
3054 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3055 zlog_debug(
3056 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3057
3058 VTY_DECLVAR_CONTEXT(bgp, bgp);
3059
3060 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3061
3062 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3063 bgp->peer, ret);
3064
3065 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3066 zlog_debug(
3067 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3068 vty_out(vty,
3069 "Graceful restart configuration changed, reset all peers to take effect\n");
3070
3071 return bgp_vty_return(vty, ret);
3072 }
3073
3074 DEFUN (no_bgp_graceful_restart_disable,
3075 no_bgp_graceful_restart_disable_cmd,
3076 "no bgp graceful-restart-disable",
3077 NO_STR
3078 BGP_STR
3079 NO_GR_DISABLE
3080 )
3081 {
3082 VTY_DECLVAR_CONTEXT(bgp, bgp);
3083
3084 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3085 zlog_debug(
3086 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3087
3088 int ret = BGP_GR_FAILURE;
3089
3090 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3091
3092 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3093 ret);
3094
3095 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3096 zlog_debug(
3097 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3098 vty_out(vty,
3099 "Graceful restart configuration changed, reset all peers to take effect\n");
3100
3101 return bgp_vty_return(vty, ret);
3102 }
3103
3104 DEFUN (bgp_neighbor_graceful_restart_set,
3105 bgp_neighbor_graceful_restart_set_cmd,
3106 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3107 NEIGHBOR_STR
3108 NEIGHBOR_ADDR_STR2
3109 GR_NEIGHBOR_CMD
3110 )
3111 {
3112 int idx_peer = 1;
3113 struct peer *peer;
3114 int ret = BGP_GR_FAILURE;
3115
3116 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3117
3118 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3119 zlog_debug(
3120 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3121
3122 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3123 if (!peer)
3124 return CMD_WARNING_CONFIG_FAILED;
3125
3126 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3127
3128 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3129 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3130
3131 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3132 zlog_debug(
3133 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3134 vty_out(vty,
3135 "Graceful restart configuration changed, reset this peer to take effect\n");
3136
3137 return bgp_vty_return(vty, ret);
3138 }
3139
3140 DEFUN (no_bgp_neighbor_graceful_restart,
3141 no_bgp_neighbor_graceful_restart_set_cmd,
3142 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3143 NO_STR
3144 NEIGHBOR_STR
3145 NEIGHBOR_ADDR_STR2
3146 NO_GR_NEIGHBOR_CMD
3147 )
3148 {
3149 int idx_peer = 2;
3150 int ret = BGP_GR_FAILURE;
3151 struct peer *peer;
3152
3153 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3154
3155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3156 if (!peer)
3157 return CMD_WARNING_CONFIG_FAILED;
3158
3159 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3160 zlog_debug(
3161 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3162
3163 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3164
3165 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3166 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3167
3168 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3169 zlog_debug(
3170 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3171 vty_out(vty,
3172 "Graceful restart configuration changed, reset this peer to take effect\n");
3173
3174 return bgp_vty_return(vty, ret);
3175 }
3176
3177 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3178 bgp_neighbor_graceful_restart_helper_set_cmd,
3179 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3180 NEIGHBOR_STR
3181 NEIGHBOR_ADDR_STR2
3182 GR_NEIGHBOR_HELPER_CMD
3183 )
3184 {
3185 int idx_peer = 1;
3186 struct peer *peer;
3187 int ret = BGP_GR_FAILURE;
3188
3189 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3190
3191 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3192 zlog_debug(
3193 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3194
3195 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3196
3197 if (!peer)
3198 return CMD_WARNING_CONFIG_FAILED;
3199
3200
3201 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3202
3203 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3204 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3205
3206 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3207 zlog_debug(
3208 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3209 vty_out(vty,
3210 "Graceful restart configuration changed, reset this peer to take effect\n");
3211
3212 return bgp_vty_return(vty, ret);
3213 }
3214
3215 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3216 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3217 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3218 NO_STR
3219 NEIGHBOR_STR
3220 NEIGHBOR_ADDR_STR2
3221 NO_GR_NEIGHBOR_HELPER_CMD
3222 )
3223 {
3224 int idx_peer = 2;
3225 int ret = BGP_GR_FAILURE;
3226 struct peer *peer;
3227
3228 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3229
3230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3231 if (!peer)
3232 return CMD_WARNING_CONFIG_FAILED;
3233
3234 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3235 zlog_debug(
3236 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3237
3238 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3239
3240 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3241 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3242
3243 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3244 zlog_debug(
3245 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3246 vty_out(vty,
3247 "Graceful restart configuration changed, reset this peer to take effect\n");
3248
3249 return bgp_vty_return(vty, ret);
3250 }
3251
3252 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3253 bgp_neighbor_graceful_restart_disable_set_cmd,
3254 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3255 NEIGHBOR_STR
3256 NEIGHBOR_ADDR_STR2
3257 GR_NEIGHBOR_DISABLE_CMD
3258 )
3259 {
3260 int idx_peer = 1;
3261 struct peer *peer;
3262 int ret = BGP_GR_FAILURE;
3263
3264 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3265
3266 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3267 zlog_debug(
3268 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3269
3270 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3271 if (!peer)
3272 return CMD_WARNING_CONFIG_FAILED;
3273
3274 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3275
3276 if (peer->bgp->t_startup)
3277 bgp_peer_gr_flags_update(peer);
3278
3279 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3280 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3281
3282 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3283 zlog_debug(
3284 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3285 vty_out(vty,
3286 "Graceful restart configuration changed, reset this peer to take effect\n");
3287
3288 return bgp_vty_return(vty, ret);
3289 }
3290
3291 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3292 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3293 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3294 NO_STR
3295 NEIGHBOR_STR
3296 NEIGHBOR_ADDR_STR2
3297 NO_GR_NEIGHBOR_DISABLE_CMD
3298 )
3299 {
3300 int idx_peer = 2;
3301 int ret = BGP_GR_FAILURE;
3302 struct peer *peer;
3303
3304 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3305
3306 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3307 if (!peer)
3308 return CMD_WARNING_CONFIG_FAILED;
3309
3310 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3311 zlog_debug(
3312 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3313
3314 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3315
3316 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3317 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3318
3319 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3320 zlog_debug(
3321 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3322 vty_out(vty,
3323 "Graceful restart configuration changed, reset this peer to take effect\n");
3324
3325 return bgp_vty_return(vty, ret);
3326 }
3327
3328 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3329 bgp_graceful_restart_disable_eor_cmd,
3330 "bgp graceful-restart disable-eor",
3331 BGP_STR
3332 "Graceful restart configuration parameters\n"
3333 "Disable EOR Check\n")
3334 {
3335 VTY_DECLVAR_CONTEXT(bgp, bgp);
3336 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3337
3338 return CMD_SUCCESS;
3339 }
3340
3341 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3342 no_bgp_graceful_restart_disable_eor_cmd,
3343 "no bgp graceful-restart disable-eor",
3344 NO_STR
3345 BGP_STR
3346 "Graceful restart configuration parameters\n"
3347 "Disable EOR Check\n")
3348 {
3349 VTY_DECLVAR_CONTEXT(bgp, bgp);
3350 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3351
3352 return CMD_SUCCESS;
3353 }
3354
3355 DEFUN (bgp_graceful_restart_rib_stale_time,
3356 bgp_graceful_restart_rib_stale_time_cmd,
3357 "bgp graceful-restart rib-stale-time (1-3600)",
3358 BGP_STR
3359 "Graceful restart configuration parameters\n"
3360 "Specify the stale route removal timer in rib\n"
3361 "Delay value (seconds)\n")
3362 {
3363 VTY_DECLVAR_CONTEXT(bgp, bgp);
3364 int idx_number = 3;
3365 uint32_t stale_time;
3366
3367 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3368 bgp->rib_stale_time = stale_time;
3369 /* Send the stale timer update message to RIB */
3370 if (bgp_zebra_stale_timer_update(bgp))
3371 return CMD_WARNING;
3372
3373 return CMD_SUCCESS;
3374 }
3375
3376 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3377 no_bgp_graceful_restart_rib_stale_time_cmd,
3378 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3379 NO_STR
3380 BGP_STR
3381 "Graceful restart configuration parameters\n"
3382 "Specify the stale route removal timer in rib\n"
3383 "Delay value (seconds)\n")
3384 {
3385 VTY_DECLVAR_CONTEXT(bgp, bgp);
3386
3387 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3388 /* Send the stale timer update message to RIB */
3389 if (bgp_zebra_stale_timer_update(bgp))
3390 return CMD_WARNING;
3391
3392 return CMD_SUCCESS;
3393 }
3394
3395 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3396 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3397 BGP_STR
3398 "Enable Long-lived Graceful Restart\n"
3399 "Specifies maximum time to wait before purging long-lived stale routes\n"
3400 "Stale time value (seconds)\n")
3401 {
3402 VTY_DECLVAR_CONTEXT(bgp, bgp);
3403
3404 uint32_t llgr_stale_time;
3405
3406 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3407 bgp->llgr_stale_time = llgr_stale_time;
3408
3409 return CMD_SUCCESS;
3410 }
3411
3412 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3413 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3414 NO_STR BGP_STR
3415 "Enable Long-lived Graceful Restart\n"
3416 "Specifies maximum time to wait before purging long-lived stale routes\n"
3417 "Stale time value (seconds)\n")
3418 {
3419 VTY_DECLVAR_CONTEXT(bgp, bgp);
3420
3421 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3422
3423 return CMD_SUCCESS;
3424 }
3425
3426 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3427 struct bgp *bgp)
3428 {
3429 bgp_static_redo_import_check(bgp);
3430 bgp_redistribute_redo(bgp);
3431 bgp_clear_star_soft_out(vty, bgp->name);
3432 bgp_clear_star_soft_in(vty, bgp->name);
3433 }
3434
3435 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3436 {
3437 struct listnode *node, *nnode;
3438 struct bgp *bgp;
3439 bool vrf_cfg = false;
3440
3441 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3442 return CMD_SUCCESS;
3443
3444 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3445 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3446 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3447 vty_out(vty,
3448 "%% graceful-shutdown configuration found in vrf %s\n",
3449 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3450 VRF_DEFAULT_NAME : bgp->name);
3451 vrf_cfg = true;
3452 }
3453 }
3454
3455 if (vrf_cfg) {
3456 vty_out(vty,
3457 "%%Failed: global graceful-shutdown not permitted\n");
3458 return CMD_WARNING;
3459 }
3460
3461 /* Set flag globally */
3462 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3463
3464 /* Initiate processing for all BGP instances. */
3465 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3466 bgp_initiate_graceful_shut_unshut(vty, bgp);
3467
3468 return CMD_SUCCESS;
3469 }
3470
3471 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3472 {
3473 struct listnode *node, *nnode;
3474 struct bgp *bgp;
3475
3476 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3477 return CMD_SUCCESS;
3478
3479 /* Unset flag globally */
3480 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3481
3482 /* Initiate processing for all BGP instances. */
3483 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3484 bgp_initiate_graceful_shut_unshut(vty, bgp);
3485
3486 return CMD_SUCCESS;
3487 }
3488
3489 /* "bgp graceful-shutdown" configuration */
3490 DEFUN (bgp_graceful_shutdown,
3491 bgp_graceful_shutdown_cmd,
3492 "bgp graceful-shutdown",
3493 BGP_STR
3494 "Graceful shutdown parameters\n")
3495 {
3496 if (vty->node == CONFIG_NODE)
3497 return bgp_global_graceful_shutdown_config_vty(vty);
3498
3499 VTY_DECLVAR_CONTEXT(bgp, bgp);
3500
3501 /* if configured globally, per-instance config is not allowed */
3502 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3503 vty_out(vty,
3504 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3505 return CMD_WARNING_CONFIG_FAILED;
3506 }
3507
3508 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3509 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3510 bgp_initiate_graceful_shut_unshut(vty, bgp);
3511 }
3512
3513 return CMD_SUCCESS;
3514 }
3515
3516 DEFUN (no_bgp_graceful_shutdown,
3517 no_bgp_graceful_shutdown_cmd,
3518 "no bgp graceful-shutdown",
3519 NO_STR
3520 BGP_STR
3521 "Graceful shutdown parameters\n")
3522 {
3523 if (vty->node == CONFIG_NODE)
3524 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3525
3526 VTY_DECLVAR_CONTEXT(bgp, bgp);
3527
3528 /* If configured globally, cannot remove from one bgp instance */
3529 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3530 vty_out(vty,
3531 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3532 return CMD_WARNING_CONFIG_FAILED;
3533 }
3534
3535 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3536 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3537 bgp_initiate_graceful_shut_unshut(vty, bgp);
3538 }
3539
3540 return CMD_SUCCESS;
3541 }
3542
3543 /* "bgp fast-external-failover" configuration. */
3544 DEFUN (bgp_fast_external_failover,
3545 bgp_fast_external_failover_cmd,
3546 "bgp fast-external-failover",
3547 BGP_STR
3548 "Immediately reset session if a link to a directly connected external peer goes down\n")
3549 {
3550 VTY_DECLVAR_CONTEXT(bgp, bgp);
3551 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3552 return CMD_SUCCESS;
3553 }
3554
3555 DEFUN (no_bgp_fast_external_failover,
3556 no_bgp_fast_external_failover_cmd,
3557 "no bgp fast-external-failover",
3558 NO_STR
3559 BGP_STR
3560 "Immediately reset session if a link to a directly connected external peer goes down\n")
3561 {
3562 VTY_DECLVAR_CONTEXT(bgp, bgp);
3563 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3564 return CMD_SUCCESS;
3565 }
3566
3567 /* "bgp bestpath compare-routerid" configuration. */
3568 DEFUN (bgp_bestpath_compare_router_id,
3569 bgp_bestpath_compare_router_id_cmd,
3570 "bgp bestpath compare-routerid",
3571 BGP_STR
3572 "Change the default bestpath selection\n"
3573 "Compare router-id for identical EBGP paths\n")
3574 {
3575 VTY_DECLVAR_CONTEXT(bgp, bgp);
3576 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3577 bgp_recalculate_all_bestpaths(bgp);
3578
3579 return CMD_SUCCESS;
3580 }
3581
3582 DEFUN (no_bgp_bestpath_compare_router_id,
3583 no_bgp_bestpath_compare_router_id_cmd,
3584 "no bgp bestpath compare-routerid",
3585 NO_STR
3586 BGP_STR
3587 "Change the default bestpath selection\n"
3588 "Compare router-id for identical EBGP paths\n")
3589 {
3590 VTY_DECLVAR_CONTEXT(bgp, bgp);
3591 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3592 bgp_recalculate_all_bestpaths(bgp);
3593
3594 return CMD_SUCCESS;
3595 }
3596
3597 /* "bgp bestpath as-path ignore" configuration. */
3598 DEFUN (bgp_bestpath_aspath_ignore,
3599 bgp_bestpath_aspath_ignore_cmd,
3600 "bgp bestpath as-path ignore",
3601 BGP_STR
3602 "Change the default bestpath selection\n"
3603 "AS-path attribute\n"
3604 "Ignore as-path length in selecting a route\n")
3605 {
3606 VTY_DECLVAR_CONTEXT(bgp, bgp);
3607 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3608 bgp_recalculate_all_bestpaths(bgp);
3609
3610 return CMD_SUCCESS;
3611 }
3612
3613 DEFUN (no_bgp_bestpath_aspath_ignore,
3614 no_bgp_bestpath_aspath_ignore_cmd,
3615 "no bgp bestpath as-path ignore",
3616 NO_STR
3617 BGP_STR
3618 "Change the default bestpath selection\n"
3619 "AS-path attribute\n"
3620 "Ignore as-path length in selecting a route\n")
3621 {
3622 VTY_DECLVAR_CONTEXT(bgp, bgp);
3623 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3624 bgp_recalculate_all_bestpaths(bgp);
3625
3626 return CMD_SUCCESS;
3627 }
3628
3629 /* "bgp bestpath as-path confed" configuration. */
3630 DEFUN (bgp_bestpath_aspath_confed,
3631 bgp_bestpath_aspath_confed_cmd,
3632 "bgp bestpath as-path confed",
3633 BGP_STR
3634 "Change the default bestpath selection\n"
3635 "AS-path attribute\n"
3636 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3637 {
3638 VTY_DECLVAR_CONTEXT(bgp, bgp);
3639 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3640 bgp_recalculate_all_bestpaths(bgp);
3641
3642 return CMD_SUCCESS;
3643 }
3644
3645 DEFUN (no_bgp_bestpath_aspath_confed,
3646 no_bgp_bestpath_aspath_confed_cmd,
3647 "no bgp bestpath as-path confed",
3648 NO_STR
3649 BGP_STR
3650 "Change the default bestpath selection\n"
3651 "AS-path attribute\n"
3652 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3653 {
3654 VTY_DECLVAR_CONTEXT(bgp, bgp);
3655 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3656 bgp_recalculate_all_bestpaths(bgp);
3657
3658 return CMD_SUCCESS;
3659 }
3660
3661 /* "bgp bestpath as-path multipath-relax" configuration. */
3662 DEFUN (bgp_bestpath_aspath_multipath_relax,
3663 bgp_bestpath_aspath_multipath_relax_cmd,
3664 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3665 BGP_STR
3666 "Change the default bestpath selection\n"
3667 "AS-path attribute\n"
3668 "Allow load sharing across routes that have different AS paths (but same length)\n"
3669 "Generate an AS_SET\n"
3670 "Do not generate an AS_SET\n")
3671 {
3672 VTY_DECLVAR_CONTEXT(bgp, bgp);
3673 int idx = 0;
3674 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3675
3676 /* no-as-set is now the default behavior so we can silently
3677 * ignore it */
3678 if (argv_find(argv, argc, "as-set", &idx))
3679 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3680 else
3681 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3682
3683 bgp_recalculate_all_bestpaths(bgp);
3684
3685 return CMD_SUCCESS;
3686 }
3687
3688 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3689 no_bgp_bestpath_aspath_multipath_relax_cmd,
3690 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3691 NO_STR
3692 BGP_STR
3693 "Change the default bestpath selection\n"
3694 "AS-path attribute\n"
3695 "Allow load sharing across routes that have different AS paths (but same length)\n"
3696 "Generate an AS_SET\n"
3697 "Do not generate an AS_SET\n")
3698 {
3699 VTY_DECLVAR_CONTEXT(bgp, bgp);
3700 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3701 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3702 bgp_recalculate_all_bestpaths(bgp);
3703
3704 return CMD_SUCCESS;
3705 }
3706
3707 /* "bgp bestpath peer-type multipath-relax" configuration. */
3708 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3709 bgp_bestpath_peer_type_multipath_relax_cmd,
3710 "bgp bestpath peer-type multipath-relax",
3711 BGP_STR
3712 "Change the default bestpath selection\n"
3713 "Peer type\n"
3714 "Allow load sharing across routes learned from different peer types\n")
3715 {
3716 VTY_DECLVAR_CONTEXT(bgp, bgp);
3717 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3718 bgp_recalculate_all_bestpaths(bgp);
3719
3720 return CMD_SUCCESS;
3721 }
3722
3723 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3724 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3725 "no bgp bestpath peer-type multipath-relax",
3726 NO_STR BGP_STR
3727 "Change the default bestpath selection\n"
3728 "Peer type\n"
3729 "Allow load sharing across routes learned from different peer types\n")
3730 {
3731 VTY_DECLVAR_CONTEXT(bgp, bgp);
3732 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3733 bgp_recalculate_all_bestpaths(bgp);
3734
3735 return CMD_SUCCESS;
3736 }
3737
3738 /* "bgp log-neighbor-changes" configuration. */
3739 DEFUN (bgp_log_neighbor_changes,
3740 bgp_log_neighbor_changes_cmd,
3741 "bgp log-neighbor-changes",
3742 BGP_STR
3743 "Log neighbor up/down and reset reason\n")
3744 {
3745 VTY_DECLVAR_CONTEXT(bgp, bgp);
3746 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3747 return CMD_SUCCESS;
3748 }
3749
3750 DEFUN (no_bgp_log_neighbor_changes,
3751 no_bgp_log_neighbor_changes_cmd,
3752 "no bgp log-neighbor-changes",
3753 NO_STR
3754 BGP_STR
3755 "Log neighbor up/down and reset reason\n")
3756 {
3757 VTY_DECLVAR_CONTEXT(bgp, bgp);
3758 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3759 return CMD_SUCCESS;
3760 }
3761
3762 /* "bgp bestpath med" configuration. */
3763 DEFUN (bgp_bestpath_med,
3764 bgp_bestpath_med_cmd,
3765 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3766 BGP_STR
3767 "Change the default bestpath selection\n"
3768 "MED attribute\n"
3769 "Compare MED among confederation paths\n"
3770 "Treat missing MED as the least preferred one\n"
3771 "Treat missing MED as the least preferred one\n"
3772 "Compare MED among confederation paths\n")
3773 {
3774 VTY_DECLVAR_CONTEXT(bgp, bgp);
3775
3776 int idx = 0;
3777 if (argv_find(argv, argc, "confed", &idx))
3778 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3779 idx = 0;
3780 if (argv_find(argv, argc, "missing-as-worst", &idx))
3781 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3782
3783 bgp_recalculate_all_bestpaths(bgp);
3784
3785 return CMD_SUCCESS;
3786 }
3787
3788 DEFUN (no_bgp_bestpath_med,
3789 no_bgp_bestpath_med_cmd,
3790 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3791 NO_STR
3792 BGP_STR
3793 "Change the default bestpath selection\n"
3794 "MED attribute\n"
3795 "Compare MED among confederation paths\n"
3796 "Treat missing MED as the least preferred one\n"
3797 "Treat missing MED as the least preferred one\n"
3798 "Compare MED among confederation paths\n")
3799 {
3800 VTY_DECLVAR_CONTEXT(bgp, bgp);
3801
3802 int idx = 0;
3803 if (argv_find(argv, argc, "confed", &idx))
3804 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3805 idx = 0;
3806 if (argv_find(argv, argc, "missing-as-worst", &idx))
3807 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3808
3809 bgp_recalculate_all_bestpaths(bgp);
3810
3811 return CMD_SUCCESS;
3812 }
3813
3814 /* "bgp bestpath bandwidth" configuration. */
3815 DEFPY (bgp_bestpath_bw,
3816 bgp_bestpath_bw_cmd,
3817 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3818 BGP_STR
3819 "Change the default bestpath selection\n"
3820 "Link Bandwidth attribute\n"
3821 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3822 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3823 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3824 {
3825 VTY_DECLVAR_CONTEXT(bgp, bgp);
3826 afi_t afi;
3827 safi_t safi;
3828
3829 if (!bw_cfg) {
3830 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3831 return CMD_ERR_INCOMPLETE;
3832 }
3833 if (!strcmp(bw_cfg, "ignore"))
3834 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3835 else if (!strcmp(bw_cfg, "skip-missing"))
3836 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3837 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3838 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3839 else
3840 return CMD_ERR_NO_MATCH;
3841
3842 /* This config is used in route install, so redo that. */
3843 FOREACH_AFI_SAFI (afi, safi) {
3844 if (!bgp_fibupd_safi(safi))
3845 continue;
3846 bgp_zebra_announce_table(bgp, afi, safi);
3847 }
3848
3849 return CMD_SUCCESS;
3850 }
3851
3852 DEFPY (no_bgp_bestpath_bw,
3853 no_bgp_bestpath_bw_cmd,
3854 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3855 NO_STR
3856 BGP_STR
3857 "Change the default bestpath selection\n"
3858 "Link Bandwidth attribute\n"
3859 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3860 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3861 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3862 {
3863 VTY_DECLVAR_CONTEXT(bgp, bgp);
3864 afi_t afi;
3865 safi_t safi;
3866
3867 bgp->lb_handling = BGP_LINK_BW_ECMP;
3868
3869 /* This config is used in route install, so redo that. */
3870 FOREACH_AFI_SAFI (afi, safi) {
3871 if (!bgp_fibupd_safi(safi))
3872 continue;
3873 bgp_zebra_announce_table(bgp, afi, safi);
3874 }
3875 return CMD_SUCCESS;
3876 }
3877
3878 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3879 "[no] bgp default <ipv4-unicast|"
3880 "ipv4-multicast|"
3881 "ipv4-vpn|"
3882 "ipv4-labeled-unicast|"
3883 "ipv4-flowspec|"
3884 "ipv6-unicast|"
3885 "ipv6-multicast|"
3886 "ipv6-vpn|"
3887 "ipv6-labeled-unicast|"
3888 "ipv6-flowspec|"
3889 "l2vpn-evpn>$afi_safi",
3890 NO_STR
3891 BGP_STR
3892 "Configure BGP defaults\n"
3893 "Activate ipv4-unicast for a peer by default\n"
3894 "Activate ipv4-multicast for a peer by default\n"
3895 "Activate ipv4-vpn for a peer by default\n"
3896 "Activate ipv4-labeled-unicast for a peer by default\n"
3897 "Activate ipv4-flowspec for a peer by default\n"
3898 "Activate ipv6-unicast for a peer by default\n"
3899 "Activate ipv6-multicast for a peer by default\n"
3900 "Activate ipv6-vpn for a peer by default\n"
3901 "Activate ipv6-labeled-unicast for a peer by default\n"
3902 "Activate ipv6-flowspec for a peer by default\n"
3903 "Activate l2vpn-evpn for a peer by default\n")
3904 {
3905 VTY_DECLVAR_CONTEXT(bgp, bgp);
3906 char afi_safi_str[strlen(afi_safi) + 1];
3907 char *afi_safi_str_tok;
3908
3909 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3910 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3911 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3912 afi_t afi = bgp_vty_afi_from_str(afi_str);
3913 safi_t safi;
3914
3915 /*
3916 * Impossible situation but making coverity happy
3917 */
3918 assert(afi != AFI_MAX);
3919
3920 if (strmatch(safi_str, "labeled"))
3921 safi = bgp_vty_safi_from_str("labeled-unicast");
3922 else
3923 safi = bgp_vty_safi_from_str(safi_str);
3924
3925 assert(safi != SAFI_MAX);
3926 if (no)
3927 bgp->default_af[afi][safi] = false;
3928 else {
3929 if ((safi == SAFI_LABELED_UNICAST
3930 && bgp->default_af[afi][SAFI_UNICAST])
3931 || (safi == SAFI_UNICAST
3932 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3933 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3934 else
3935 bgp->default_af[afi][safi] = true;
3936 }
3937
3938 return CMD_SUCCESS;
3939 }
3940
3941 /* Display hostname in certain command outputs */
3942 DEFUN (bgp_default_show_hostname,
3943 bgp_default_show_hostname_cmd,
3944 "bgp default show-hostname",
3945 BGP_STR
3946 "Configure BGP defaults\n"
3947 "Show hostname in certain command outputs\n")
3948 {
3949 VTY_DECLVAR_CONTEXT(bgp, bgp);
3950 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3951 return CMD_SUCCESS;
3952 }
3953
3954 DEFUN (no_bgp_default_show_hostname,
3955 no_bgp_default_show_hostname_cmd,
3956 "no bgp default show-hostname",
3957 NO_STR
3958 BGP_STR
3959 "Configure BGP defaults\n"
3960 "Show hostname in certain command outputs\n")
3961 {
3962 VTY_DECLVAR_CONTEXT(bgp, bgp);
3963 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3964 return CMD_SUCCESS;
3965 }
3966
3967 /* Display hostname in certain command outputs */
3968 DEFUN (bgp_default_show_nexthop_hostname,
3969 bgp_default_show_nexthop_hostname_cmd,
3970 "bgp default show-nexthop-hostname",
3971 BGP_STR
3972 "Configure BGP defaults\n"
3973 "Show hostname for nexthop in certain command outputs\n")
3974 {
3975 VTY_DECLVAR_CONTEXT(bgp, bgp);
3976 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3977 return CMD_SUCCESS;
3978 }
3979
3980 DEFUN (no_bgp_default_show_nexthop_hostname,
3981 no_bgp_default_show_nexthop_hostname_cmd,
3982 "no bgp default show-nexthop-hostname",
3983 NO_STR
3984 BGP_STR
3985 "Configure BGP defaults\n"
3986 "Show hostname for nexthop in certain command outputs\n")
3987 {
3988 VTY_DECLVAR_CONTEXT(bgp, bgp);
3989 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3990 return CMD_SUCCESS;
3991 }
3992
3993 /* "bgp network import-check" configuration. */
3994 DEFUN (bgp_network_import_check,
3995 bgp_network_import_check_cmd,
3996 "bgp network import-check",
3997 BGP_STR
3998 "BGP network command\n"
3999 "Check BGP network route exists in IGP\n")
4000 {
4001 VTY_DECLVAR_CONTEXT(bgp, bgp);
4002 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4003 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4004 bgp_static_redo_import_check(bgp);
4005 }
4006
4007 return CMD_SUCCESS;
4008 }
4009
4010 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4011 "bgp network import-check exact",
4012 BGP_STR
4013 "BGP network command\n"
4014 "Check BGP network route exists in IGP\n"
4015 "Match route precisely\n")
4016
4017 DEFUN (no_bgp_network_import_check,
4018 no_bgp_network_import_check_cmd,
4019 "no bgp network import-check",
4020 NO_STR
4021 BGP_STR
4022 "BGP network command\n"
4023 "Check BGP network route exists in IGP\n")
4024 {
4025 VTY_DECLVAR_CONTEXT(bgp, bgp);
4026 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4027 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4028 bgp_static_redo_import_check(bgp);
4029 }
4030
4031 return CMD_SUCCESS;
4032 }
4033
4034 DEFUN (bgp_default_local_preference,
4035 bgp_default_local_preference_cmd,
4036 "bgp default local-preference (0-4294967295)",
4037 BGP_STR
4038 "Configure BGP defaults\n"
4039 "local preference (higher=more preferred)\n"
4040 "Configure default local preference value\n")
4041 {
4042 VTY_DECLVAR_CONTEXT(bgp, bgp);
4043 int idx_number = 3;
4044 uint32_t local_pref;
4045
4046 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4047
4048 bgp_default_local_preference_set(bgp, local_pref);
4049 bgp_clear_star_soft_in(vty, bgp->name);
4050
4051 return CMD_SUCCESS;
4052 }
4053
4054 DEFUN (no_bgp_default_local_preference,
4055 no_bgp_default_local_preference_cmd,
4056 "no bgp default local-preference [(0-4294967295)]",
4057 NO_STR
4058 BGP_STR
4059 "Configure BGP defaults\n"
4060 "local preference (higher=more preferred)\n"
4061 "Configure default local preference value\n")
4062 {
4063 VTY_DECLVAR_CONTEXT(bgp, bgp);
4064 bgp_default_local_preference_unset(bgp);
4065 bgp_clear_star_soft_in(vty, bgp->name);
4066
4067 return CMD_SUCCESS;
4068 }
4069
4070
4071 DEFUN (bgp_default_subgroup_pkt_queue_max,
4072 bgp_default_subgroup_pkt_queue_max_cmd,
4073 "bgp default subgroup-pkt-queue-max (20-100)",
4074 BGP_STR
4075 "Configure BGP defaults\n"
4076 "subgroup-pkt-queue-max\n"
4077 "Configure subgroup packet queue max\n")
4078 {
4079 VTY_DECLVAR_CONTEXT(bgp, bgp);
4080 int idx_number = 3;
4081 uint32_t max_size;
4082
4083 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4084
4085 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4086
4087 return CMD_SUCCESS;
4088 }
4089
4090 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4091 no_bgp_default_subgroup_pkt_queue_max_cmd,
4092 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4093 NO_STR
4094 BGP_STR
4095 "Configure BGP defaults\n"
4096 "subgroup-pkt-queue-max\n"
4097 "Configure subgroup packet queue max\n")
4098 {
4099 VTY_DECLVAR_CONTEXT(bgp, bgp);
4100 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4101 return CMD_SUCCESS;
4102 }
4103
4104
4105 DEFUN (bgp_rr_allow_outbound_policy,
4106 bgp_rr_allow_outbound_policy_cmd,
4107 "bgp route-reflector allow-outbound-policy",
4108 BGP_STR
4109 "Allow modifications made by out route-map\n"
4110 "on ibgp neighbors\n")
4111 {
4112 VTY_DECLVAR_CONTEXT(bgp, bgp);
4113
4114 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4115 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4116 update_group_announce_rrclients(bgp);
4117 bgp_clear_star_soft_out(vty, bgp->name);
4118 }
4119
4120 return CMD_SUCCESS;
4121 }
4122
4123 DEFUN (no_bgp_rr_allow_outbound_policy,
4124 no_bgp_rr_allow_outbound_policy_cmd,
4125 "no bgp route-reflector allow-outbound-policy",
4126 NO_STR
4127 BGP_STR
4128 "Allow modifications made by out route-map\n"
4129 "on ibgp neighbors\n")
4130 {
4131 VTY_DECLVAR_CONTEXT(bgp, bgp);
4132
4133 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4134 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4135 update_group_announce_rrclients(bgp);
4136 bgp_clear_star_soft_out(vty, bgp->name);
4137 }
4138
4139 return CMD_SUCCESS;
4140 }
4141
4142 DEFUN (bgp_listen_limit,
4143 bgp_listen_limit_cmd,
4144 "bgp listen limit (1-65535)",
4145 BGP_STR
4146 "BGP Dynamic Neighbors listen commands\n"
4147 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4148 "Configure Dynamic Neighbors listen limit value\n")
4149 {
4150 VTY_DECLVAR_CONTEXT(bgp, bgp);
4151 int idx_number = 3;
4152 int listen_limit;
4153
4154 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4155
4156 bgp_listen_limit_set(bgp, listen_limit);
4157
4158 return CMD_SUCCESS;
4159 }
4160
4161 DEFUN (no_bgp_listen_limit,
4162 no_bgp_listen_limit_cmd,
4163 "no bgp listen limit [(1-65535)]",
4164 NO_STR
4165 BGP_STR
4166 "BGP Dynamic Neighbors listen commands\n"
4167 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4168 "Configure Dynamic Neighbors listen limit value\n")
4169 {
4170 VTY_DECLVAR_CONTEXT(bgp, bgp);
4171 bgp_listen_limit_unset(bgp);
4172 return CMD_SUCCESS;
4173 }
4174
4175
4176 /*
4177 * Check if this listen range is already configured. Check for exact
4178 * match or overlap based on input.
4179 */
4180 static struct peer_group *listen_range_exists(struct bgp *bgp,
4181 struct prefix *range, int exact)
4182 {
4183 struct listnode *node, *nnode;
4184 struct listnode *node1, *nnode1;
4185 struct peer_group *group;
4186 struct prefix *lr;
4187 afi_t afi;
4188 int match;
4189
4190 afi = family2afi(range->family);
4191 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4192 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4193 lr)) {
4194 if (exact)
4195 match = prefix_same(range, lr);
4196 else
4197 match = (prefix_match(range, lr)
4198 || prefix_match(lr, range));
4199 if (match)
4200 return group;
4201 }
4202 }
4203
4204 return NULL;
4205 }
4206
4207 DEFUN (bgp_listen_range,
4208 bgp_listen_range_cmd,
4209 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4210 BGP_STR
4211 "Configure BGP dynamic neighbors listen range\n"
4212 "Configure BGP dynamic neighbors listen range\n"
4213 NEIGHBOR_ADDR_STR
4214 "Member of the peer-group\n"
4215 "Peer-group name\n")
4216 {
4217 VTY_DECLVAR_CONTEXT(bgp, bgp);
4218 struct prefix range;
4219 struct peer_group *group, *existing_group;
4220 afi_t afi;
4221 int ret;
4222 int idx = 0;
4223
4224 argv_find(argv, argc, "A.B.C.D/M", &idx);
4225 argv_find(argv, argc, "X:X::X:X/M", &idx);
4226 char *prefix = argv[idx]->arg;
4227 argv_find(argv, argc, "PGNAME", &idx);
4228 char *peergroup = argv[idx]->arg;
4229
4230 /* Convert IP prefix string to struct prefix. */
4231 ret = str2prefix(prefix, &range);
4232 if (!ret) {
4233 vty_out(vty, "%% Malformed listen range\n");
4234 return CMD_WARNING_CONFIG_FAILED;
4235 }
4236
4237 afi = family2afi(range.family);
4238
4239 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4240 vty_out(vty,
4241 "%% Malformed listen range (link-local address)\n");
4242 return CMD_WARNING_CONFIG_FAILED;
4243 }
4244
4245 apply_mask(&range);
4246
4247 /* Check if same listen range is already configured. */
4248 existing_group = listen_range_exists(bgp, &range, 1);
4249 if (existing_group) {
4250 if (strcmp(existing_group->name, peergroup) == 0)
4251 return CMD_SUCCESS;
4252 else {
4253 vty_out(vty,
4254 "%% Same listen range is attached to peer-group %s\n",
4255 existing_group->name);
4256 return CMD_WARNING_CONFIG_FAILED;
4257 }
4258 }
4259
4260 /* Check if an overlapping listen range exists. */
4261 if (listen_range_exists(bgp, &range, 0)) {
4262 vty_out(vty,
4263 "%% Listen range overlaps with existing listen range\n");
4264 return CMD_WARNING_CONFIG_FAILED;
4265 }
4266
4267 group = peer_group_lookup(bgp, peergroup);
4268 if (!group) {
4269 vty_out(vty, "%% Configure the peer-group first\n");
4270 return CMD_WARNING_CONFIG_FAILED;
4271 }
4272
4273 ret = peer_group_listen_range_add(group, &range);
4274 return bgp_vty_return(vty, ret);
4275 }
4276
4277 DEFUN (no_bgp_listen_range,
4278 no_bgp_listen_range_cmd,
4279 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4280 NO_STR
4281 BGP_STR
4282 "Unconfigure BGP dynamic neighbors listen range\n"
4283 "Unconfigure BGP dynamic neighbors listen range\n"
4284 NEIGHBOR_ADDR_STR
4285 "Member of the peer-group\n"
4286 "Peer-group name\n")
4287 {
4288 VTY_DECLVAR_CONTEXT(bgp, bgp);
4289 struct prefix range;
4290 struct peer_group *group;
4291 afi_t afi;
4292 int ret;
4293 int idx = 0;
4294
4295 argv_find(argv, argc, "A.B.C.D/M", &idx);
4296 argv_find(argv, argc, "X:X::X:X/M", &idx);
4297 char *prefix = argv[idx]->arg;
4298 argv_find(argv, argc, "PGNAME", &idx);
4299 char *peergroup = argv[idx]->arg;
4300
4301 /* Convert IP prefix string to struct prefix. */
4302 ret = str2prefix(prefix, &range);
4303 if (!ret) {
4304 vty_out(vty, "%% Malformed listen range\n");
4305 return CMD_WARNING_CONFIG_FAILED;
4306 }
4307
4308 afi = family2afi(range.family);
4309
4310 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4311 vty_out(vty,
4312 "%% Malformed listen range (link-local address)\n");
4313 return CMD_WARNING_CONFIG_FAILED;
4314 }
4315
4316 apply_mask(&range);
4317
4318 group = peer_group_lookup(bgp, peergroup);
4319 if (!group) {
4320 vty_out(vty, "%% Peer-group does not exist\n");
4321 return CMD_WARNING_CONFIG_FAILED;
4322 }
4323
4324 ret = peer_group_listen_range_del(group, &range);
4325 return bgp_vty_return(vty, ret);
4326 }
4327
4328 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4329 {
4330 struct peer_group *group;
4331 struct listnode *node, *nnode, *rnode, *nrnode;
4332 struct prefix *range;
4333 afi_t afi;
4334
4335 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4336 vty_out(vty, " bgp listen limit %d\n",
4337 bgp->dynamic_neighbors_limit);
4338
4339 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4340 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4341 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4342 nrnode, range)) {
4343 vty_out(vty,
4344 " bgp listen range %pFX peer-group %s\n",
4345 range, group->name);
4346 }
4347 }
4348 }
4349 }
4350
4351
4352 DEFUN (bgp_disable_connected_route_check,
4353 bgp_disable_connected_route_check_cmd,
4354 "bgp disable-ebgp-connected-route-check",
4355 BGP_STR
4356 "Disable checking if nexthop is connected on ebgp sessions\n")
4357 {
4358 VTY_DECLVAR_CONTEXT(bgp, bgp);
4359 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4360 bgp_clear_star_soft_in(vty, bgp->name);
4361
4362 return CMD_SUCCESS;
4363 }
4364
4365 DEFUN (no_bgp_disable_connected_route_check,
4366 no_bgp_disable_connected_route_check_cmd,
4367 "no bgp disable-ebgp-connected-route-check",
4368 NO_STR
4369 BGP_STR
4370 "Disable checking if nexthop is connected on ebgp sessions\n")
4371 {
4372 VTY_DECLVAR_CONTEXT(bgp, bgp);
4373 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4374 bgp_clear_star_soft_in(vty, bgp->name);
4375
4376 return CMD_SUCCESS;
4377 }
4378
4379
4380 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4381 const char *as_str)
4382 {
4383 VTY_DECLVAR_CONTEXT(bgp, bgp);
4384 int ret;
4385 as_t as;
4386 int as_type = AS_SPECIFIED;
4387 union sockunion su;
4388
4389 if (as_str[0] == 'i') {
4390 as = 0;
4391 as_type = AS_INTERNAL;
4392 } else if (as_str[0] == 'e') {
4393 as = 0;
4394 as_type = AS_EXTERNAL;
4395 } else {
4396 /* Get AS number. */
4397 as = strtoul(as_str, NULL, 10);
4398 }
4399
4400 /* If peer is peer group or interface peer, call proper function. */
4401 ret = str2sockunion(peer_str, &su);
4402 if (ret < 0) {
4403 struct peer *peer;
4404
4405 /* Check if existing interface peer */
4406 peer = peer_lookup_by_conf_if(bgp, peer_str);
4407
4408 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4409
4410 /* if not interface peer, check peer-group settings */
4411 if (ret < 0 && !peer) {
4412 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4413 if (ret < 0) {
4414 vty_out(vty,
4415 "%% Create the peer-group or interface first\n");
4416 return CMD_WARNING_CONFIG_FAILED;
4417 }
4418 return CMD_SUCCESS;
4419 }
4420 } else {
4421 if (peer_address_self_check(bgp, &su)) {
4422 vty_out(vty,
4423 "%% Can not configure the local system as neighbor\n");
4424 return CMD_WARNING_CONFIG_FAILED;
4425 }
4426 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4427 }
4428
4429 return bgp_vty_return(vty, ret);
4430 }
4431
4432 DEFUN (bgp_default_shutdown,
4433 bgp_default_shutdown_cmd,
4434 "[no] bgp default shutdown",
4435 NO_STR
4436 BGP_STR
4437 "Configure BGP defaults\n"
4438 "Apply administrative shutdown to newly configured peers\n")
4439 {
4440 VTY_DECLVAR_CONTEXT(bgp, bgp);
4441 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4442 return CMD_SUCCESS;
4443 }
4444
4445 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4446 BGP_STR
4447 "Administrative shutdown of the BGP instance\n"
4448 "Add a shutdown message (RFC 8203)\n"
4449 "Shutdown message\n")
4450 {
4451 char *msgstr = NULL;
4452
4453 VTY_DECLVAR_CONTEXT(bgp, bgp);
4454
4455 if (argc > 3)
4456 msgstr = argv_concat(argv, argc, 3);
4457
4458 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4459 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4460 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4461 return CMD_WARNING_CONFIG_FAILED;
4462 }
4463
4464 bgp_shutdown_enable(bgp, msgstr);
4465 XFREE(MTYPE_TMP, msgstr);
4466
4467 return CMD_SUCCESS;
4468 }
4469
4470 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4471 BGP_STR "Administrative shutdown of the BGP instance\n")
4472 {
4473 VTY_DECLVAR_CONTEXT(bgp, bgp);
4474
4475 bgp_shutdown_enable(bgp, NULL);
4476
4477 return CMD_SUCCESS;
4478 }
4479
4480 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4481 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4482 {
4483 VTY_DECLVAR_CONTEXT(bgp, bgp);
4484
4485 bgp_shutdown_disable(bgp);
4486
4487 return CMD_SUCCESS;
4488 }
4489
4490 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4491 "no bgp shutdown message MSG...", NO_STR BGP_STR
4492 "Administrative shutdown of the BGP instance\n"
4493 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4494
4495 DEFUN (neighbor_remote_as,
4496 neighbor_remote_as_cmd,
4497 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4498 NEIGHBOR_STR
4499 NEIGHBOR_ADDR_STR2
4500 "Specify a BGP neighbor\n"
4501 AS_STR
4502 "Internal BGP peer\n"
4503 "External BGP peer\n")
4504 {
4505 int idx_peer = 1;
4506 int idx_remote_as = 3;
4507 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4508 argv[idx_remote_as]->arg);
4509 }
4510
4511 DEFPY (bgp_allow_martian,
4512 bgp_allow_martian_cmd,
4513 "[no]$no bgp allow-martian-nexthop",
4514 NO_STR
4515 BGP_STR
4516 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4517 {
4518 VTY_DECLVAR_CONTEXT(bgp, bgp);
4519
4520 if (no)
4521 bgp->allow_martian = false;
4522 else
4523 bgp->allow_martian = true;
4524
4525 return CMD_SUCCESS;
4526 }
4527
4528 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4529 * sessions do not wait for hold timer expiry to bring down the sessions
4530 * when nexthop becomes unreachable
4531 */
4532 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4533 BGP_STR "Fast convergence for bgp sessions\n")
4534 {
4535 VTY_DECLVAR_CONTEXT(bgp, bgp);
4536 bgp->fast_convergence = true;
4537
4538 return CMD_SUCCESS;
4539 }
4540
4541 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4542 "no bgp fast-convergence",
4543 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4544 {
4545 VTY_DECLVAR_CONTEXT(bgp, bgp);
4546 bgp->fast_convergence = false;
4547
4548 return CMD_SUCCESS;
4549 }
4550
4551 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4552 int v6only,
4553 const char *peer_group_name,
4554 const char *as_str)
4555 {
4556 VTY_DECLVAR_CONTEXT(bgp, bgp);
4557 as_t as = 0;
4558 int as_type = AS_UNSPECIFIED;
4559 struct peer *peer;
4560 struct peer_group *group;
4561 int ret = 0;
4562
4563 group = peer_group_lookup(bgp, conf_if);
4564
4565 if (group) {
4566 vty_out(vty, "%% Name conflict with peer-group \n");
4567 return CMD_WARNING_CONFIG_FAILED;
4568 }
4569
4570 if (as_str) {
4571 if (as_str[0] == 'i') {
4572 as_type = AS_INTERNAL;
4573 } else if (as_str[0] == 'e') {
4574 as_type = AS_EXTERNAL;
4575 } else {
4576 /* Get AS number. */
4577 as = strtoul(as_str, NULL, 10);
4578 as_type = AS_SPECIFIED;
4579 }
4580 }
4581
4582 peer = peer_lookup_by_conf_if(bgp, conf_if);
4583 if (peer) {
4584 if (as_str)
4585 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4586 } else {
4587 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4588 NULL);
4589
4590 if (!peer) {
4591 vty_out(vty, "%% BGP failed to create peer\n");
4592 return CMD_WARNING_CONFIG_FAILED;
4593 }
4594
4595 if (v6only)
4596 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4597
4598 /* Request zebra to initiate IPv6 RAs on this interface. We do
4599 * this
4600 * any unnumbered peer in order to not worry about run-time
4601 * transitions
4602 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4603 * address
4604 * gets deleted later etc.)
4605 */
4606 if (peer->ifp)
4607 bgp_zebra_initiate_radv(bgp, peer);
4608 }
4609
4610 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4611 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4612 if (v6only)
4613 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4614 else
4615 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4616
4617 /* v6only flag changed. Reset bgp seesion */
4618 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4619 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4620 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4621 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4622 } else
4623 bgp_session_reset(peer);
4624 }
4625
4626 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4627 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4628 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4629 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4630 }
4631
4632 if (peer_group_name) {
4633 group = peer_group_lookup(bgp, peer_group_name);
4634 if (!group) {
4635 vty_out(vty, "%% Configure the peer-group first\n");
4636 return CMD_WARNING_CONFIG_FAILED;
4637 }
4638
4639 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4640 }
4641
4642 return bgp_vty_return(vty, ret);
4643 }
4644
4645 DEFUN (neighbor_interface_config,
4646 neighbor_interface_config_cmd,
4647 "neighbor WORD interface [peer-group PGNAME]",
4648 NEIGHBOR_STR
4649 "Interface name or neighbor tag\n"
4650 "Enable BGP on interface\n"
4651 "Member of the peer-group\n"
4652 "Peer-group name\n")
4653 {
4654 int idx_word = 1;
4655 int idx_peer_group_word = 4;
4656
4657 if (argc > idx_peer_group_word)
4658 return peer_conf_interface_get(
4659 vty, argv[idx_word]->arg, 0,
4660 argv[idx_peer_group_word]->arg, NULL);
4661 else
4662 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4663 NULL, NULL);
4664 }
4665
4666 DEFUN (neighbor_interface_config_v6only,
4667 neighbor_interface_config_v6only_cmd,
4668 "neighbor WORD interface v6only [peer-group PGNAME]",
4669 NEIGHBOR_STR
4670 "Interface name or neighbor tag\n"
4671 "Enable BGP on interface\n"
4672 "Enable BGP with v6 link-local only\n"
4673 "Member of the peer-group\n"
4674 "Peer-group name\n")
4675 {
4676 int idx_word = 1;
4677 int idx_peer_group_word = 5;
4678
4679 if (argc > idx_peer_group_word)
4680 return peer_conf_interface_get(
4681 vty, argv[idx_word]->arg, 1,
4682 argv[idx_peer_group_word]->arg, NULL);
4683
4684 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4685 }
4686
4687
4688 DEFUN (neighbor_interface_config_remote_as,
4689 neighbor_interface_config_remote_as_cmd,
4690 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4691 NEIGHBOR_STR
4692 "Interface name or neighbor tag\n"
4693 "Enable BGP on interface\n"
4694 "Specify a BGP neighbor\n"
4695 AS_STR
4696 "Internal BGP peer\n"
4697 "External BGP peer\n")
4698 {
4699 int idx_word = 1;
4700 int idx_remote_as = 4;
4701 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4702 argv[idx_remote_as]->arg);
4703 }
4704
4705 DEFUN (neighbor_interface_v6only_config_remote_as,
4706 neighbor_interface_v6only_config_remote_as_cmd,
4707 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4708 NEIGHBOR_STR
4709 "Interface name or neighbor tag\n"
4710 "Enable BGP with v6 link-local only\n"
4711 "Enable BGP on interface\n"
4712 "Specify a BGP neighbor\n"
4713 AS_STR
4714 "Internal BGP peer\n"
4715 "External BGP peer\n")
4716 {
4717 int idx_word = 1;
4718 int idx_remote_as = 5;
4719 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4720 argv[idx_remote_as]->arg);
4721 }
4722
4723 DEFUN (neighbor_peer_group,
4724 neighbor_peer_group_cmd,
4725 "neighbor WORD peer-group",
4726 NEIGHBOR_STR
4727 "Interface name or neighbor tag\n"
4728 "Configure peer-group\n")
4729 {
4730 VTY_DECLVAR_CONTEXT(bgp, bgp);
4731 int idx_word = 1;
4732 struct peer *peer;
4733 struct peer_group *group;
4734
4735 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4736 if (peer) {
4737 vty_out(vty, "%% Name conflict with interface: \n");
4738 return CMD_WARNING_CONFIG_FAILED;
4739 }
4740
4741 group = peer_group_get(bgp, argv[idx_word]->arg);
4742 if (!group) {
4743 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4744 return CMD_WARNING_CONFIG_FAILED;
4745 }
4746
4747 return CMD_SUCCESS;
4748 }
4749
4750 DEFUN (no_neighbor,
4751 no_neighbor_cmd,
4752 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4753 NO_STR
4754 NEIGHBOR_STR
4755 NEIGHBOR_ADDR_STR2
4756 "Specify a BGP neighbor\n"
4757 AS_STR
4758 "Internal BGP peer\n"
4759 "External BGP peer\n")
4760 {
4761 VTY_DECLVAR_CONTEXT(bgp, bgp);
4762 int idx_peer = 2;
4763 int ret;
4764 union sockunion su;
4765 struct peer_group *group;
4766 struct peer *peer;
4767 struct peer *other;
4768
4769 ret = str2sockunion(argv[idx_peer]->arg, &su);
4770 if (ret < 0) {
4771 /* look up for neighbor by interface name config. */
4772 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4773 if (peer) {
4774 /* Request zebra to terminate IPv6 RAs on this
4775 * interface. */
4776 if (peer->ifp)
4777 bgp_zebra_terminate_radv(peer->bgp, peer);
4778 peer_notify_unconfig(peer);
4779 peer_delete(peer);
4780 return CMD_SUCCESS;
4781 }
4782
4783 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4784 if (group) {
4785 peer_group_notify_unconfig(group);
4786 peer_group_delete(group);
4787 } else {
4788 vty_out(vty, "%% Create the peer-group first\n");
4789 return CMD_WARNING_CONFIG_FAILED;
4790 }
4791 } else {
4792 peer = peer_lookup(bgp, &su);
4793 if (peer) {
4794 if (peer_dynamic_neighbor(peer)) {
4795 vty_out(vty,
4796 "%% Operation not allowed on a dynamic neighbor\n");
4797 return CMD_WARNING_CONFIG_FAILED;
4798 }
4799
4800 other = peer->doppelganger;
4801
4802 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4803 bgp_zebra_terminate_radv(peer->bgp, peer);
4804
4805 peer_notify_unconfig(peer);
4806 peer_delete(peer);
4807 if (other && other->status != Deleted) {
4808 peer_notify_unconfig(other);
4809 peer_delete(other);
4810 }
4811 }
4812 }
4813
4814 return CMD_SUCCESS;
4815 }
4816
4817 DEFUN (no_neighbor_interface_config,
4818 no_neighbor_interface_config_cmd,
4819 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4820 NO_STR
4821 NEIGHBOR_STR
4822 "Interface name\n"
4823 "Configure BGP on interface\n"
4824 "Enable BGP with v6 link-local only\n"
4825 "Member of the peer-group\n"
4826 "Peer-group name\n"
4827 "Specify a BGP neighbor\n"
4828 AS_STR
4829 "Internal BGP peer\n"
4830 "External BGP peer\n")
4831 {
4832 VTY_DECLVAR_CONTEXT(bgp, bgp);
4833 int idx_word = 2;
4834 struct peer *peer;
4835
4836 /* look up for neighbor by interface name config. */
4837 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4838 if (peer) {
4839 /* Request zebra to terminate IPv6 RAs on this interface. */
4840 if (peer->ifp)
4841 bgp_zebra_terminate_radv(peer->bgp, peer);
4842 peer_notify_unconfig(peer);
4843 peer_delete(peer);
4844 } else {
4845 vty_out(vty, "%% Create the bgp interface first\n");
4846 return CMD_WARNING_CONFIG_FAILED;
4847 }
4848 return CMD_SUCCESS;
4849 }
4850
4851 DEFUN (no_neighbor_peer_group,
4852 no_neighbor_peer_group_cmd,
4853 "no neighbor WORD peer-group",
4854 NO_STR
4855 NEIGHBOR_STR
4856 "Neighbor tag\n"
4857 "Configure peer-group\n")
4858 {
4859 VTY_DECLVAR_CONTEXT(bgp, bgp);
4860 int idx_word = 2;
4861 struct peer_group *group;
4862
4863 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4864 if (group) {
4865 peer_group_notify_unconfig(group);
4866 peer_group_delete(group);
4867 } else {
4868 vty_out(vty, "%% Create the peer-group first\n");
4869 return CMD_WARNING_CONFIG_FAILED;
4870 }
4871 return CMD_SUCCESS;
4872 }
4873
4874 DEFUN (no_neighbor_interface_peer_group_remote_as,
4875 no_neighbor_interface_peer_group_remote_as_cmd,
4876 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4877 NO_STR
4878 NEIGHBOR_STR
4879 "Interface name or neighbor tag\n"
4880 "Specify a BGP neighbor\n"
4881 AS_STR
4882 "Internal BGP peer\n"
4883 "External BGP peer\n")
4884 {
4885 VTY_DECLVAR_CONTEXT(bgp, bgp);
4886 int idx_word = 2;
4887 struct peer_group *group;
4888 struct peer *peer;
4889
4890 /* look up for neighbor by interface name config. */
4891 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4892 if (peer) {
4893 peer_as_change(peer, 0, AS_UNSPECIFIED);
4894 return CMD_SUCCESS;
4895 }
4896
4897 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4898 if (group)
4899 peer_group_remote_as_delete(group);
4900 else {
4901 vty_out(vty, "%% Create the peer-group or interface first\n");
4902 return CMD_WARNING_CONFIG_FAILED;
4903 }
4904 return CMD_SUCCESS;
4905 }
4906
4907 DEFUN (neighbor_local_as,
4908 neighbor_local_as_cmd,
4909 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4910 NEIGHBOR_STR
4911 NEIGHBOR_ADDR_STR2
4912 "Specify a local-as number\n"
4913 "AS number used as local AS\n")
4914 {
4915 int idx_peer = 1;
4916 int idx_number = 3;
4917 struct peer *peer;
4918 int ret;
4919 as_t as;
4920
4921 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4922 if (!peer)
4923 return CMD_WARNING_CONFIG_FAILED;
4924
4925 as = strtoul(argv[idx_number]->arg, NULL, 10);
4926 ret = peer_local_as_set(peer, as, 0, 0);
4927 return bgp_vty_return(vty, ret);
4928 }
4929
4930 DEFUN (neighbor_local_as_no_prepend,
4931 neighbor_local_as_no_prepend_cmd,
4932 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4933 NEIGHBOR_STR
4934 NEIGHBOR_ADDR_STR2
4935 "Specify a local-as number\n"
4936 "AS number used as local AS\n"
4937 "Do not prepend local-as to updates from ebgp peers\n")
4938 {
4939 int idx_peer = 1;
4940 int idx_number = 3;
4941 struct peer *peer;
4942 int ret;
4943 as_t as;
4944
4945 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4946 if (!peer)
4947 return CMD_WARNING_CONFIG_FAILED;
4948
4949 as = strtoul(argv[idx_number]->arg, NULL, 10);
4950 ret = peer_local_as_set(peer, as, 1, 0);
4951 return bgp_vty_return(vty, ret);
4952 }
4953
4954 DEFUN (neighbor_local_as_no_prepend_replace_as,
4955 neighbor_local_as_no_prepend_replace_as_cmd,
4956 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4957 NEIGHBOR_STR
4958 NEIGHBOR_ADDR_STR2
4959 "Specify a local-as number\n"
4960 "AS number used as local AS\n"
4961 "Do not prepend local-as to updates from ebgp peers\n"
4962 "Do not prepend local-as to updates from ibgp peers\n")
4963 {
4964 int idx_peer = 1;
4965 int idx_number = 3;
4966 struct peer *peer;
4967 int ret;
4968 as_t as;
4969
4970 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4971 if (!peer)
4972 return CMD_WARNING_CONFIG_FAILED;
4973
4974 as = strtoul(argv[idx_number]->arg, NULL, 10);
4975 ret = peer_local_as_set(peer, as, 1, 1);
4976 return bgp_vty_return(vty, ret);
4977 }
4978
4979 DEFUN (no_neighbor_local_as,
4980 no_neighbor_local_as_cmd,
4981 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4982 NO_STR
4983 NEIGHBOR_STR
4984 NEIGHBOR_ADDR_STR2
4985 "Specify a local-as number\n"
4986 "AS number used as local AS\n"
4987 "Do not prepend local-as to updates from ebgp peers\n"
4988 "Do not prepend local-as to updates from ibgp peers\n")
4989 {
4990 int idx_peer = 2;
4991 struct peer *peer;
4992 int ret;
4993
4994 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4995 if (!peer)
4996 return CMD_WARNING_CONFIG_FAILED;
4997
4998 ret = peer_local_as_unset(peer);
4999 return bgp_vty_return(vty, ret);
5000 }
5001
5002
5003 DEFUN (neighbor_solo,
5004 neighbor_solo_cmd,
5005 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5006 NEIGHBOR_STR
5007 NEIGHBOR_ADDR_STR2
5008 "Solo peer - part of its own update group\n")
5009 {
5010 int idx_peer = 1;
5011 struct peer *peer;
5012 int ret;
5013
5014 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
5017
5018 ret = update_group_adjust_soloness(peer, 1);
5019 return bgp_vty_return(vty, ret);
5020 }
5021
5022 DEFUN (no_neighbor_solo,
5023 no_neighbor_solo_cmd,
5024 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5025 NO_STR
5026 NEIGHBOR_STR
5027 NEIGHBOR_ADDR_STR2
5028 "Solo peer - part of its own update group\n")
5029 {
5030 int idx_peer = 2;
5031 struct peer *peer;
5032 int ret;
5033
5034 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5035 if (!peer)
5036 return CMD_WARNING_CONFIG_FAILED;
5037
5038 ret = update_group_adjust_soloness(peer, 0);
5039 return bgp_vty_return(vty, ret);
5040 }
5041
5042 DEFUN (neighbor_password,
5043 neighbor_password_cmd,
5044 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5045 NEIGHBOR_STR
5046 NEIGHBOR_ADDR_STR2
5047 "Set a password\n"
5048 "The password\n")
5049 {
5050 int idx_peer = 1;
5051 int idx_line = 3;
5052 struct peer *peer;
5053 int ret;
5054
5055 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5056 if (!peer)
5057 return CMD_WARNING_CONFIG_FAILED;
5058
5059 ret = peer_password_set(peer, argv[idx_line]->arg);
5060 return bgp_vty_return(vty, ret);
5061 }
5062
5063 DEFUN (no_neighbor_password,
5064 no_neighbor_password_cmd,
5065 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5066 NO_STR
5067 NEIGHBOR_STR
5068 NEIGHBOR_ADDR_STR2
5069 "Set a password\n"
5070 "The password\n")
5071 {
5072 int idx_peer = 2;
5073 struct peer *peer;
5074 int ret;
5075
5076 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5077 if (!peer)
5078 return CMD_WARNING_CONFIG_FAILED;
5079
5080 ret = peer_password_unset(peer);
5081 return bgp_vty_return(vty, ret);
5082 }
5083
5084 DEFUN (neighbor_activate,
5085 neighbor_activate_cmd,
5086 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5087 NEIGHBOR_STR
5088 NEIGHBOR_ADDR_STR2
5089 "Enable the Address Family for this Neighbor\n")
5090 {
5091 int idx_peer = 1;
5092 int ret;
5093 struct peer *peer;
5094
5095 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5096 if (!peer)
5097 return CMD_WARNING_CONFIG_FAILED;
5098
5099 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5100 return bgp_vty_return(vty, ret);
5101 }
5102
5103 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5104 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5105 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5106 "Enable the Address Family for this Neighbor\n")
5107
5108 DEFUN (no_neighbor_activate,
5109 no_neighbor_activate_cmd,
5110 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5111 NO_STR
5112 NEIGHBOR_STR
5113 NEIGHBOR_ADDR_STR2
5114 "Enable the Address Family for this Neighbor\n")
5115 {
5116 int idx_peer = 2;
5117 int ret;
5118 struct peer *peer;
5119
5120 /* Lookup peer. */
5121 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5122 if (!peer)
5123 return CMD_WARNING_CONFIG_FAILED;
5124
5125 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5126 return bgp_vty_return(vty, ret);
5127 }
5128
5129 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5130 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5131 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5132 "Enable the Address Family for this Neighbor\n")
5133
5134 DEFUN (neighbor_set_peer_group,
5135 neighbor_set_peer_group_cmd,
5136 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5137 NEIGHBOR_STR
5138 NEIGHBOR_ADDR_STR2
5139 "Member of the peer-group\n"
5140 "Peer-group name\n")
5141 {
5142 VTY_DECLVAR_CONTEXT(bgp, bgp);
5143 int idx_peer = 1;
5144 int idx_word = 3;
5145 int ret;
5146 as_t as;
5147 union sockunion su;
5148 struct peer *peer;
5149 struct peer_group *group;
5150
5151 ret = str2sockunion(argv[idx_peer]->arg, &su);
5152 if (ret < 0) {
5153 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5154 if (!peer) {
5155 vty_out(vty, "%% Malformed address or name: %s\n",
5156 argv[idx_peer]->arg);
5157 return CMD_WARNING_CONFIG_FAILED;
5158 }
5159 } else {
5160 if (peer_address_self_check(bgp, &su)) {
5161 vty_out(vty,
5162 "%% Can not configure the local system as neighbor\n");
5163 return CMD_WARNING_CONFIG_FAILED;
5164 }
5165
5166 /* Disallow for dynamic neighbor. */
5167 peer = peer_lookup(bgp, &su);
5168 if (peer && peer_dynamic_neighbor(peer)) {
5169 vty_out(vty,
5170 "%% Operation not allowed on a dynamic neighbor\n");
5171 return CMD_WARNING_CONFIG_FAILED;
5172 }
5173 }
5174
5175 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5176 if (!group) {
5177 vty_out(vty, "%% Configure the peer-group first\n");
5178 return CMD_WARNING_CONFIG_FAILED;
5179 }
5180
5181 ret = peer_group_bind(bgp, &su, peer, group, &as);
5182
5183 return bgp_vty_return(vty, ret);
5184 }
5185
5186 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5187 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5188 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5189 "Member of the peer-group\n"
5190 "Peer-group name\n")
5191
5192 DEFUN (no_neighbor_set_peer_group,
5193 no_neighbor_set_peer_group_cmd,
5194 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5195 NO_STR
5196 NEIGHBOR_STR
5197 NEIGHBOR_ADDR_STR2
5198 "Member of the peer-group\n"
5199 "Peer-group name\n")
5200 {
5201 VTY_DECLVAR_CONTEXT(bgp, bgp);
5202 int idx_peer = 2;
5203 int idx_word = 4;
5204 int ret;
5205 struct peer *peer;
5206 struct peer_group *group;
5207
5208 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5209 if (!peer)
5210 return CMD_WARNING_CONFIG_FAILED;
5211
5212 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5213 if (!group) {
5214 vty_out(vty, "%% Configure the peer-group first\n");
5215 return CMD_WARNING_CONFIG_FAILED;
5216 }
5217
5218 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5219 bgp_zebra_terminate_radv(peer->bgp, peer);
5220
5221 peer_notify_unconfig(peer);
5222 ret = peer_delete(peer);
5223
5224 return bgp_vty_return(vty, ret);
5225 }
5226
5227 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5228 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5229 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5230 "Member of the peer-group\n"
5231 "Peer-group name\n")
5232
5233 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5234 uint64_t flag, int set)
5235 {
5236 int ret;
5237 struct peer *peer;
5238
5239 peer = peer_and_group_lookup_vty(vty, ip_str);
5240 if (!peer)
5241 return CMD_WARNING_CONFIG_FAILED;
5242
5243 /*
5244 * If 'neighbor <interface>', then this is for directly connected peers,
5245 * we should not accept disable-connected-check.
5246 */
5247 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5248 vty_out(vty,
5249 "%s is directly connected peer, cannot accept disable-connected-check\n",
5250 ip_str);
5251 return CMD_WARNING_CONFIG_FAILED;
5252 }
5253
5254 if (!set && flag == PEER_FLAG_SHUTDOWN)
5255 peer_tx_shutdown_message_unset(peer);
5256
5257 if (set)
5258 ret = peer_flag_set(peer, flag);
5259 else
5260 ret = peer_flag_unset(peer, flag);
5261
5262 return bgp_vty_return(vty, ret);
5263 }
5264
5265 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5266 {
5267 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5268 }
5269
5270 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5271 uint64_t flag)
5272 {
5273 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5274 }
5275
5276 /* neighbor passive. */
5277 DEFUN (neighbor_passive,
5278 neighbor_passive_cmd,
5279 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5280 NEIGHBOR_STR
5281 NEIGHBOR_ADDR_STR2
5282 "Don't send open messages to this neighbor\n")
5283 {
5284 int idx_peer = 1;
5285 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5286 }
5287
5288 DEFUN (no_neighbor_passive,
5289 no_neighbor_passive_cmd,
5290 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5291 NO_STR
5292 NEIGHBOR_STR
5293 NEIGHBOR_ADDR_STR2
5294 "Don't send open messages to this neighbor\n")
5295 {
5296 int idx_peer = 2;
5297 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5298 }
5299
5300 /* neighbor shutdown. */
5301 DEFUN (neighbor_shutdown_msg,
5302 neighbor_shutdown_msg_cmd,
5303 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5304 NEIGHBOR_STR
5305 NEIGHBOR_ADDR_STR2
5306 "Administratively shut down this neighbor\n"
5307 "Add a shutdown message (RFC 8203)\n"
5308 "Shutdown message\n")
5309 {
5310 int idx_peer = 1;
5311
5312 if (argc >= 5) {
5313 struct peer *peer =
5314 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5315 char *message;
5316
5317 if (!peer)
5318 return CMD_WARNING_CONFIG_FAILED;
5319 message = argv_concat(argv, argc, 4);
5320 peer_tx_shutdown_message_set(peer, message);
5321 XFREE(MTYPE_TMP, message);
5322 }
5323
5324 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5325 }
5326
5327 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5328 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5329 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5330 "Administratively shut down this neighbor\n")
5331
5332 DEFUN (no_neighbor_shutdown_msg,
5333 no_neighbor_shutdown_msg_cmd,
5334 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5335 NO_STR
5336 NEIGHBOR_STR
5337 NEIGHBOR_ADDR_STR2
5338 "Administratively shut down this neighbor\n"
5339 "Remove a shutdown message (RFC 8203)\n"
5340 "Shutdown message\n")
5341 {
5342 int idx_peer = 2;
5343
5344 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5345 PEER_FLAG_SHUTDOWN);
5346 }
5347
5348 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5349 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5350 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5351 "Administratively shut down this neighbor\n")
5352
5353 DEFUN(neighbor_shutdown_rtt,
5354 neighbor_shutdown_rtt_cmd,
5355 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5356 NEIGHBOR_STR
5357 NEIGHBOR_ADDR_STR2
5358 "Administratively shut down this neighbor\n"
5359 "Shutdown if round-trip-time is higher than expected\n"
5360 "Round-trip-time in milliseconds\n"
5361 "Specify the number of keepalives before shutdown\n"
5362 "The number of keepalives with higher RTT to shutdown\n")
5363 {
5364 int idx_peer = 1;
5365 int idx_rtt = 4;
5366 int idx_count = 0;
5367 struct peer *peer;
5368
5369 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5370
5371 if (!peer)
5372 return CMD_WARNING_CONFIG_FAILED;
5373
5374 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5375
5376 if (argv_find(argv, argc, "count", &idx_count))
5377 peer->rtt_keepalive_conf =
5378 strtol(argv[idx_count + 1]->arg, NULL, 10);
5379
5380 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5381 PEER_FLAG_RTT_SHUTDOWN);
5382 }
5383
5384 DEFUN(no_neighbor_shutdown_rtt,
5385 no_neighbor_shutdown_rtt_cmd,
5386 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5387 NO_STR
5388 NEIGHBOR_STR
5389 NEIGHBOR_ADDR_STR2
5390 "Administratively shut down this neighbor\n"
5391 "Shutdown if round-trip-time is higher than expected\n"
5392 "Round-trip-time in milliseconds\n"
5393 "Specify the number of keepalives before shutdown\n"
5394 "The number of keepalives with higher RTT to shutdown\n")
5395 {
5396 int idx_peer = 2;
5397 struct peer *peer;
5398
5399 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5400
5401 if (!peer)
5402 return CMD_WARNING_CONFIG_FAILED;
5403
5404 peer->rtt_expected = 0;
5405 peer->rtt_keepalive_conf = 1;
5406
5407 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5408 PEER_FLAG_RTT_SHUTDOWN);
5409 }
5410
5411 /* neighbor capability dynamic. */
5412 DEFUN (neighbor_capability_dynamic,
5413 neighbor_capability_dynamic_cmd,
5414 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5415 NEIGHBOR_STR
5416 NEIGHBOR_ADDR_STR2
5417 "Advertise capability to the peer\n"
5418 "Advertise dynamic capability to this neighbor\n")
5419 {
5420 int idx_peer = 1;
5421 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5422 PEER_FLAG_DYNAMIC_CAPABILITY);
5423 }
5424
5425 DEFUN (no_neighbor_capability_dynamic,
5426 no_neighbor_capability_dynamic_cmd,
5427 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5428 NO_STR
5429 NEIGHBOR_STR
5430 NEIGHBOR_ADDR_STR2
5431 "Advertise capability to the peer\n"
5432 "Advertise dynamic capability to this neighbor\n")
5433 {
5434 int idx_peer = 2;
5435 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5436 PEER_FLAG_DYNAMIC_CAPABILITY);
5437 }
5438
5439 /* neighbor dont-capability-negotiate */
5440 DEFUN (neighbor_dont_capability_negotiate,
5441 neighbor_dont_capability_negotiate_cmd,
5442 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5443 NEIGHBOR_STR
5444 NEIGHBOR_ADDR_STR2
5445 "Do not perform capability negotiation\n")
5446 {
5447 int idx_peer = 1;
5448 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5449 PEER_FLAG_DONT_CAPABILITY);
5450 }
5451
5452 DEFUN (no_neighbor_dont_capability_negotiate,
5453 no_neighbor_dont_capability_negotiate_cmd,
5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5455 NO_STR
5456 NEIGHBOR_STR
5457 NEIGHBOR_ADDR_STR2
5458 "Do not perform capability negotiation\n")
5459 {
5460 int idx_peer = 2;
5461 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5462 PEER_FLAG_DONT_CAPABILITY);
5463 }
5464
5465 /* neighbor capability extended next hop encoding */
5466 DEFUN (neighbor_capability_enhe,
5467 neighbor_capability_enhe_cmd,
5468 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5469 NEIGHBOR_STR
5470 NEIGHBOR_ADDR_STR2
5471 "Advertise capability to the peer\n"
5472 "Advertise extended next-hop capability to the peer\n")
5473 {
5474 int idx_peer = 1;
5475 struct peer *peer;
5476
5477 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5478 if (peer && peer->conf_if)
5479 return CMD_SUCCESS;
5480
5481 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5482 PEER_FLAG_CAPABILITY_ENHE);
5483 }
5484
5485 DEFUN (no_neighbor_capability_enhe,
5486 no_neighbor_capability_enhe_cmd,
5487 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5488 NO_STR
5489 NEIGHBOR_STR
5490 NEIGHBOR_ADDR_STR2
5491 "Advertise capability to the peer\n"
5492 "Advertise extended next-hop capability to the peer\n")
5493 {
5494 int idx_peer = 2;
5495 struct peer *peer;
5496
5497 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5498 if (peer && peer->conf_if) {
5499 vty_out(vty,
5500 "Peer %s cannot have capability extended-nexthop turned off\n",
5501 argv[idx_peer]->arg);
5502 return CMD_WARNING_CONFIG_FAILED;
5503 }
5504
5505 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5506 PEER_FLAG_CAPABILITY_ENHE);
5507 }
5508
5509 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5510 afi_t afi, safi_t safi, uint32_t flag,
5511 int set)
5512 {
5513 int ret;
5514 struct peer *peer;
5515
5516 peer = peer_and_group_lookup_vty(vty, peer_str);
5517 if (!peer)
5518 return CMD_WARNING_CONFIG_FAILED;
5519
5520 if (set)
5521 ret = peer_af_flag_set(peer, afi, safi, flag);
5522 else
5523 ret = peer_af_flag_unset(peer, afi, safi, flag);
5524
5525 return bgp_vty_return(vty, ret);
5526 }
5527
5528 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5529 afi_t afi, safi_t safi, uint32_t flag)
5530 {
5531 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5532 }
5533
5534 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5535 afi_t afi, safi_t safi, uint32_t flag)
5536 {
5537 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5538 }
5539
5540 /* neighbor capability orf prefix-list. */
5541 DEFUN (neighbor_capability_orf_prefix,
5542 neighbor_capability_orf_prefix_cmd,
5543 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5544 NEIGHBOR_STR
5545 NEIGHBOR_ADDR_STR2
5546 "Advertise capability to the peer\n"
5547 "Advertise ORF capability to the peer\n"
5548 "Advertise prefixlist ORF capability to this neighbor\n"
5549 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5550 "Capability to RECEIVE the ORF from this neighbor\n"
5551 "Capability to SEND the ORF to this neighbor\n")
5552 {
5553 int idx_send_recv = 5;
5554 char *peer_str = argv[1]->arg;
5555 struct peer *peer;
5556 afi_t afi = bgp_node_afi(vty);
5557 safi_t safi = bgp_node_safi(vty);
5558
5559 peer = peer_and_group_lookup_vty(vty, peer_str);
5560 if (!peer)
5561 return CMD_WARNING_CONFIG_FAILED;
5562
5563 if (strmatch(argv[idx_send_recv]->text, "send"))
5564 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5565 PEER_FLAG_ORF_PREFIX_SM);
5566
5567 if (strmatch(argv[idx_send_recv]->text, "receive"))
5568 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5569 PEER_FLAG_ORF_PREFIX_RM);
5570
5571 if (strmatch(argv[idx_send_recv]->text, "both"))
5572 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5573 PEER_FLAG_ORF_PREFIX_SM)
5574 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5575 PEER_FLAG_ORF_PREFIX_RM);
5576
5577 return CMD_WARNING_CONFIG_FAILED;
5578 }
5579
5580 ALIAS_HIDDEN(
5581 neighbor_capability_orf_prefix,
5582 neighbor_capability_orf_prefix_hidden_cmd,
5583 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5584 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5585 "Advertise capability to the peer\n"
5586 "Advertise ORF capability to the peer\n"
5587 "Advertise prefixlist ORF capability to this neighbor\n"
5588 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5589 "Capability to RECEIVE the ORF from this neighbor\n"
5590 "Capability to SEND the ORF to this neighbor\n")
5591
5592 DEFUN (no_neighbor_capability_orf_prefix,
5593 no_neighbor_capability_orf_prefix_cmd,
5594 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5595 NO_STR
5596 NEIGHBOR_STR
5597 NEIGHBOR_ADDR_STR2
5598 "Advertise capability to the peer\n"
5599 "Advertise ORF capability to the peer\n"
5600 "Advertise prefixlist ORF capability to this neighbor\n"
5601 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5602 "Capability to RECEIVE the ORF from this neighbor\n"
5603 "Capability to SEND the ORF to this neighbor\n")
5604 {
5605 int idx_send_recv = 6;
5606 char *peer_str = argv[2]->arg;
5607 struct peer *peer;
5608 afi_t afi = bgp_node_afi(vty);
5609 safi_t safi = bgp_node_safi(vty);
5610
5611 peer = peer_and_group_lookup_vty(vty, peer_str);
5612 if (!peer)
5613 return CMD_WARNING_CONFIG_FAILED;
5614
5615 if (strmatch(argv[idx_send_recv]->text, "send"))
5616 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5617 PEER_FLAG_ORF_PREFIX_SM);
5618
5619 if (strmatch(argv[idx_send_recv]->text, "receive"))
5620 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5621 PEER_FLAG_ORF_PREFIX_RM);
5622
5623 if (strmatch(argv[idx_send_recv]->text, "both"))
5624 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5625 PEER_FLAG_ORF_PREFIX_SM)
5626 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5627 PEER_FLAG_ORF_PREFIX_RM);
5628
5629 return CMD_WARNING_CONFIG_FAILED;
5630 }
5631
5632 ALIAS_HIDDEN(
5633 no_neighbor_capability_orf_prefix,
5634 no_neighbor_capability_orf_prefix_hidden_cmd,
5635 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5636 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5637 "Advertise capability to the peer\n"
5638 "Advertise ORF capability to the peer\n"
5639 "Advertise prefixlist ORF capability to this neighbor\n"
5640 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5641 "Capability to RECEIVE the ORF from this neighbor\n"
5642 "Capability to SEND the ORF to this neighbor\n")
5643
5644 /* neighbor next-hop-self. */
5645 DEFUN (neighbor_nexthop_self,
5646 neighbor_nexthop_self_cmd,
5647 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5648 NEIGHBOR_STR
5649 NEIGHBOR_ADDR_STR2
5650 "Disable the next hop calculation for this neighbor\n")
5651 {
5652 int idx_peer = 1;
5653 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5654 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5655 }
5656
5657 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5658 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5659 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5660 "Disable the next hop calculation for this neighbor\n")
5661
5662 /* neighbor next-hop-self. */
5663 DEFUN (neighbor_nexthop_self_force,
5664 neighbor_nexthop_self_force_cmd,
5665 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5666 NEIGHBOR_STR
5667 NEIGHBOR_ADDR_STR2
5668 "Disable the next hop calculation for this neighbor\n"
5669 "Set the next hop to self for reflected routes\n")
5670 {
5671 int idx_peer = 1;
5672 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5673 bgp_node_safi(vty),
5674 PEER_FLAG_FORCE_NEXTHOP_SELF);
5675 }
5676
5677 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5678 neighbor_nexthop_self_force_hidden_cmd,
5679 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5680 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5681 "Disable the next hop calculation for this neighbor\n"
5682 "Set the next hop to self for reflected routes\n")
5683
5684 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5685 neighbor_nexthop_self_all_hidden_cmd,
5686 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5687 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5688 "Disable the next hop calculation for this neighbor\n"
5689 "Set the next hop to self for reflected routes\n")
5690
5691 DEFUN (no_neighbor_nexthop_self,
5692 no_neighbor_nexthop_self_cmd,
5693 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5694 NO_STR
5695 NEIGHBOR_STR
5696 NEIGHBOR_ADDR_STR2
5697 "Disable the next hop calculation for this neighbor\n")
5698 {
5699 int idx_peer = 2;
5700 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5701 bgp_node_afi(vty), bgp_node_safi(vty),
5702 PEER_FLAG_NEXTHOP_SELF);
5703 }
5704
5705 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5706 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5707 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5708 "Disable the next hop calculation for this neighbor\n")
5709
5710 DEFUN (no_neighbor_nexthop_self_force,
5711 no_neighbor_nexthop_self_force_cmd,
5712 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5713 NO_STR
5714 NEIGHBOR_STR
5715 NEIGHBOR_ADDR_STR2
5716 "Disable the next hop calculation for this neighbor\n"
5717 "Set the next hop to self for reflected routes\n")
5718 {
5719 int idx_peer = 2;
5720 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5721 bgp_node_afi(vty), bgp_node_safi(vty),
5722 PEER_FLAG_FORCE_NEXTHOP_SELF);
5723 }
5724
5725 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5726 no_neighbor_nexthop_self_force_hidden_cmd,
5727 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5728 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5729 "Disable the next hop calculation for this neighbor\n"
5730 "Set the next hop to self for reflected routes\n")
5731
5732 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5733 no_neighbor_nexthop_self_all_hidden_cmd,
5734 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5735 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Disable the next hop calculation for this neighbor\n"
5737 "Set the next hop to self for reflected routes\n")
5738
5739 /* neighbor as-override */
5740 DEFUN (neighbor_as_override,
5741 neighbor_as_override_cmd,
5742 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5743 NEIGHBOR_STR
5744 NEIGHBOR_ADDR_STR2
5745 "Override ASNs in outbound updates if aspath equals remote-as\n")
5746 {
5747 int idx_peer = 1;
5748 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5749 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5750 }
5751
5752 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5753 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5754 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5755 "Override ASNs in outbound updates if aspath equals remote-as\n")
5756
5757 DEFUN (no_neighbor_as_override,
5758 no_neighbor_as_override_cmd,
5759 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5760 NO_STR
5761 NEIGHBOR_STR
5762 NEIGHBOR_ADDR_STR2
5763 "Override ASNs in outbound updates if aspath equals remote-as\n")
5764 {
5765 int idx_peer = 2;
5766 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5767 bgp_node_afi(vty), bgp_node_safi(vty),
5768 PEER_FLAG_AS_OVERRIDE);
5769 }
5770
5771 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5772 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5773 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5774 "Override ASNs in outbound updates if aspath equals remote-as\n")
5775
5776 /* neighbor remove-private-AS. */
5777 DEFUN (neighbor_remove_private_as,
5778 neighbor_remove_private_as_cmd,
5779 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Remove private ASNs in outbound updates\n")
5783 {
5784 int idx_peer = 1;
5785 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5786 bgp_node_safi(vty),
5787 PEER_FLAG_REMOVE_PRIVATE_AS);
5788 }
5789
5790 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5791 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5792 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5793 "Remove private ASNs in outbound updates\n")
5794
5795 DEFUN (neighbor_remove_private_as_all,
5796 neighbor_remove_private_as_all_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5798 NEIGHBOR_STR
5799 NEIGHBOR_ADDR_STR2
5800 "Remove private ASNs in outbound updates\n"
5801 "Apply to all AS numbers\n")
5802 {
5803 int idx_peer = 1;
5804 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5805 bgp_node_safi(vty),
5806 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5807 }
5808
5809 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5810 neighbor_remove_private_as_all_hidden_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5813 "Remove private ASNs in outbound updates\n"
5814 "Apply to all AS numbers")
5815
5816 DEFUN (neighbor_remove_private_as_replace_as,
5817 neighbor_remove_private_as_replace_as_cmd,
5818 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5819 NEIGHBOR_STR
5820 NEIGHBOR_ADDR_STR2
5821 "Remove private ASNs in outbound updates\n"
5822 "Replace private ASNs with our ASN in outbound updates\n")
5823 {
5824 int idx_peer = 1;
5825 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5826 bgp_node_safi(vty),
5827 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5828 }
5829
5830 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5831 neighbor_remove_private_as_replace_as_hidden_cmd,
5832 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5833 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5834 "Remove private ASNs in outbound updates\n"
5835 "Replace private ASNs with our ASN in outbound updates\n")
5836
5837 DEFUN (neighbor_remove_private_as_all_replace_as,
5838 neighbor_remove_private_as_all_replace_as_cmd,
5839 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5840 NEIGHBOR_STR
5841 NEIGHBOR_ADDR_STR2
5842 "Remove private ASNs in outbound updates\n"
5843 "Apply to all AS numbers\n"
5844 "Replace private ASNs with our ASN in outbound updates\n")
5845 {
5846 int idx_peer = 1;
5847 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5848 bgp_node_safi(vty),
5849 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5850 }
5851
5852 ALIAS_HIDDEN(
5853 neighbor_remove_private_as_all_replace_as,
5854 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5855 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5856 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5857 "Remove private ASNs in outbound updates\n"
5858 "Apply to all AS numbers\n"
5859 "Replace private ASNs with our ASN in outbound updates\n")
5860
5861 DEFUN (no_neighbor_remove_private_as,
5862 no_neighbor_remove_private_as_cmd,
5863 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5864 NO_STR
5865 NEIGHBOR_STR
5866 NEIGHBOR_ADDR_STR2
5867 "Remove private ASNs in outbound updates\n")
5868 {
5869 int idx_peer = 2;
5870 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5871 bgp_node_afi(vty), bgp_node_safi(vty),
5872 PEER_FLAG_REMOVE_PRIVATE_AS);
5873 }
5874
5875 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5876 no_neighbor_remove_private_as_hidden_cmd,
5877 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5878 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5879 "Remove private ASNs in outbound updates\n")
5880
5881 DEFUN (no_neighbor_remove_private_as_all,
5882 no_neighbor_remove_private_as_all_cmd,
5883 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5884 NO_STR
5885 NEIGHBOR_STR
5886 NEIGHBOR_ADDR_STR2
5887 "Remove private ASNs in outbound updates\n"
5888 "Apply to all AS numbers\n")
5889 {
5890 int idx_peer = 2;
5891 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5892 bgp_node_afi(vty), bgp_node_safi(vty),
5893 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5894 }
5895
5896 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5897 no_neighbor_remove_private_as_all_hidden_cmd,
5898 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5899 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5900 "Remove private ASNs in outbound updates\n"
5901 "Apply to all AS numbers\n")
5902
5903 DEFUN (no_neighbor_remove_private_as_replace_as,
5904 no_neighbor_remove_private_as_replace_as_cmd,
5905 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5906 NO_STR
5907 NEIGHBOR_STR
5908 NEIGHBOR_ADDR_STR2
5909 "Remove private ASNs in outbound updates\n"
5910 "Replace private ASNs with our ASN in outbound updates\n")
5911 {
5912 int idx_peer = 2;
5913 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5914 bgp_node_afi(vty), bgp_node_safi(vty),
5915 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5916 }
5917
5918 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5919 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5920 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5921 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5922 "Remove private ASNs in outbound updates\n"
5923 "Replace private ASNs with our ASN in outbound updates\n")
5924
5925 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5926 no_neighbor_remove_private_as_all_replace_as_cmd,
5927 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5928 NO_STR
5929 NEIGHBOR_STR
5930 NEIGHBOR_ADDR_STR2
5931 "Remove private ASNs in outbound updates\n"
5932 "Apply to all AS numbers\n"
5933 "Replace private ASNs with our ASN in outbound updates\n")
5934 {
5935 int idx_peer = 2;
5936 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5937 bgp_node_afi(vty), bgp_node_safi(vty),
5938 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5939 }
5940
5941 ALIAS_HIDDEN(
5942 no_neighbor_remove_private_as_all_replace_as,
5943 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5944 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5946 "Remove private ASNs in outbound updates\n"
5947 "Apply to all AS numbers\n"
5948 "Replace private ASNs with our ASN in outbound updates\n")
5949
5950
5951 /* neighbor send-community. */
5952 DEFUN (neighbor_send_community,
5953 neighbor_send_community_cmd,
5954 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5955 NEIGHBOR_STR
5956 NEIGHBOR_ADDR_STR2
5957 "Send Community attribute to this neighbor\n")
5958 {
5959 int idx_peer = 1;
5960
5961 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5962 bgp_node_safi(vty),
5963 PEER_FLAG_SEND_COMMUNITY);
5964 }
5965
5966 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5967 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "Send Community attribute to this neighbor\n")
5970
5971 DEFUN (no_neighbor_send_community,
5972 no_neighbor_send_community_cmd,
5973 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5974 NO_STR
5975 NEIGHBOR_STR
5976 NEIGHBOR_ADDR_STR2
5977 "Send Community attribute to this neighbor\n")
5978 {
5979 int idx_peer = 2;
5980
5981 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5982 bgp_node_afi(vty), bgp_node_safi(vty),
5983 PEER_FLAG_SEND_COMMUNITY);
5984 }
5985
5986 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5987 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5988 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5989 "Send Community attribute to this neighbor\n")
5990
5991 /* neighbor send-community extended. */
5992 DEFUN (neighbor_send_community_type,
5993 neighbor_send_community_type_cmd,
5994 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5995 NEIGHBOR_STR
5996 NEIGHBOR_ADDR_STR2
5997 "Send Community attribute to this neighbor\n"
5998 "Send Standard and Extended Community attributes\n"
5999 "Send Standard, Large and Extended Community attributes\n"
6000 "Send Extended Community attributes\n"
6001 "Send Standard Community attributes\n"
6002 "Send Large Community attributes\n")
6003 {
6004 const char *type = argv[argc - 1]->text;
6005 char *peer_str = argv[1]->arg;
6006 struct peer *peer;
6007 afi_t afi = bgp_node_afi(vty);
6008 safi_t safi = bgp_node_safi(vty);
6009
6010 peer = peer_and_group_lookup_vty(vty, peer_str);
6011 if (!peer)
6012 return CMD_WARNING_CONFIG_FAILED;
6013
6014 if (strmatch(type, "standard"))
6015 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6016 PEER_FLAG_SEND_COMMUNITY);
6017
6018 if (strmatch(type, "extended"))
6019 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6020 PEER_FLAG_SEND_EXT_COMMUNITY);
6021
6022 if (strmatch(type, "large"))
6023 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6024 PEER_FLAG_SEND_LARGE_COMMUNITY);
6025
6026 if (strmatch(type, "both")) {
6027 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6028 PEER_FLAG_SEND_COMMUNITY)
6029 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6030 PEER_FLAG_SEND_EXT_COMMUNITY);
6031 }
6032 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6033 PEER_FLAG_SEND_COMMUNITY)
6034 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6035 PEER_FLAG_SEND_EXT_COMMUNITY)
6036 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6037 PEER_FLAG_SEND_LARGE_COMMUNITY);
6038 }
6039
6040 ALIAS_HIDDEN(
6041 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6042 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6043 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6044 "Send Community attribute to this neighbor\n"
6045 "Send Standard and Extended Community attributes\n"
6046 "Send Standard, Large and Extended Community attributes\n"
6047 "Send Extended Community attributes\n"
6048 "Send Standard Community attributes\n"
6049 "Send Large Community attributes\n")
6050
6051 DEFUN (no_neighbor_send_community_type,
6052 no_neighbor_send_community_type_cmd,
6053 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6054 NO_STR
6055 NEIGHBOR_STR
6056 NEIGHBOR_ADDR_STR2
6057 "Send Community attribute to this neighbor\n"
6058 "Send Standard and Extended Community attributes\n"
6059 "Send Standard, Large and Extended Community attributes\n"
6060 "Send Extended Community attributes\n"
6061 "Send Standard Community attributes\n"
6062 "Send Large Community attributes\n")
6063 {
6064 const char *type = argv[argc - 1]->text;
6065 char *peer_str = argv[2]->arg;
6066 struct peer *peer;
6067 afi_t afi = bgp_node_afi(vty);
6068 safi_t safi = bgp_node_safi(vty);
6069
6070 peer = peer_and_group_lookup_vty(vty, peer_str);
6071 if (!peer)
6072 return CMD_WARNING_CONFIG_FAILED;
6073
6074 if (strmatch(type, "standard"))
6075 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6076 PEER_FLAG_SEND_COMMUNITY);
6077
6078 if (strmatch(type, "extended"))
6079 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6080 PEER_FLAG_SEND_EXT_COMMUNITY);
6081
6082 if (strmatch(type, "large"))
6083 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6084 PEER_FLAG_SEND_LARGE_COMMUNITY);
6085
6086 if (strmatch(type, "both")) {
6087
6088 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6089 PEER_FLAG_SEND_COMMUNITY)
6090 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6091 PEER_FLAG_SEND_EXT_COMMUNITY);
6092 }
6093
6094 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6095 PEER_FLAG_SEND_COMMUNITY)
6096 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6097 PEER_FLAG_SEND_EXT_COMMUNITY)
6098 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6099 PEER_FLAG_SEND_LARGE_COMMUNITY);
6100 }
6101
6102 ALIAS_HIDDEN(
6103 no_neighbor_send_community_type,
6104 no_neighbor_send_community_type_hidden_cmd,
6105 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6107 "Send Community attribute to this neighbor\n"
6108 "Send Standard and Extended Community attributes\n"
6109 "Send Standard, Large and Extended Community attributes\n"
6110 "Send Extended Community attributes\n"
6111 "Send Standard Community attributes\n"
6112 "Send Large Community attributes\n")
6113
6114 /* neighbor soft-reconfig. */
6115 DEFUN (neighbor_soft_reconfiguration,
6116 neighbor_soft_reconfiguration_cmd,
6117 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6118 NEIGHBOR_STR
6119 NEIGHBOR_ADDR_STR2
6120 "Per neighbor soft reconfiguration\n"
6121 "Allow inbound soft reconfiguration for this neighbor\n")
6122 {
6123 int idx_peer = 1;
6124 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6125 bgp_node_safi(vty),
6126 PEER_FLAG_SOFT_RECONFIG);
6127 }
6128
6129 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6130 neighbor_soft_reconfiguration_hidden_cmd,
6131 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6132 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Per neighbor soft reconfiguration\n"
6134 "Allow inbound soft reconfiguration for this neighbor\n")
6135
6136 DEFUN (no_neighbor_soft_reconfiguration,
6137 no_neighbor_soft_reconfiguration_cmd,
6138 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6139 NO_STR
6140 NEIGHBOR_STR
6141 NEIGHBOR_ADDR_STR2
6142 "Per neighbor soft reconfiguration\n"
6143 "Allow inbound soft reconfiguration for this neighbor\n")
6144 {
6145 int idx_peer = 2;
6146 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6147 bgp_node_afi(vty), bgp_node_safi(vty),
6148 PEER_FLAG_SOFT_RECONFIG);
6149 }
6150
6151 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6152 no_neighbor_soft_reconfiguration_hidden_cmd,
6153 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6154 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6155 "Per neighbor soft reconfiguration\n"
6156 "Allow inbound soft reconfiguration for this neighbor\n")
6157
6158 DEFUN (neighbor_route_reflector_client,
6159 neighbor_route_reflector_client_cmd,
6160 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6161 NEIGHBOR_STR
6162 NEIGHBOR_ADDR_STR2
6163 "Configure a neighbor as Route Reflector client\n")
6164 {
6165 int idx_peer = 1;
6166 struct peer *peer;
6167
6168
6169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6170 if (!peer)
6171 return CMD_WARNING_CONFIG_FAILED;
6172
6173 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6174 bgp_node_safi(vty),
6175 PEER_FLAG_REFLECTOR_CLIENT);
6176 }
6177
6178 ALIAS_HIDDEN(neighbor_route_reflector_client,
6179 neighbor_route_reflector_client_hidden_cmd,
6180 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6181 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6182 "Configure a neighbor as Route Reflector client\n")
6183
6184 DEFUN (no_neighbor_route_reflector_client,
6185 no_neighbor_route_reflector_client_cmd,
6186 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6187 NO_STR
6188 NEIGHBOR_STR
6189 NEIGHBOR_ADDR_STR2
6190 "Configure a neighbor as Route Reflector client\n")
6191 {
6192 int idx_peer = 2;
6193 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6194 bgp_node_afi(vty), bgp_node_safi(vty),
6195 PEER_FLAG_REFLECTOR_CLIENT);
6196 }
6197
6198 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6199 no_neighbor_route_reflector_client_hidden_cmd,
6200 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6201 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6202 "Configure a neighbor as Route Reflector client\n")
6203
6204 /* neighbor route-server-client. */
6205 DEFUN (neighbor_route_server_client,
6206 neighbor_route_server_client_cmd,
6207 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6208 NEIGHBOR_STR
6209 NEIGHBOR_ADDR_STR2
6210 "Configure a neighbor as Route Server client\n")
6211 {
6212 int idx_peer = 1;
6213 struct peer *peer;
6214
6215 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6216 if (!peer)
6217 return CMD_WARNING_CONFIG_FAILED;
6218 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6219 bgp_node_safi(vty),
6220 PEER_FLAG_RSERVER_CLIENT);
6221 }
6222
6223 ALIAS_HIDDEN(neighbor_route_server_client,
6224 neighbor_route_server_client_hidden_cmd,
6225 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6226 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6227 "Configure a neighbor as Route Server client\n")
6228
6229 DEFUN (no_neighbor_route_server_client,
6230 no_neighbor_route_server_client_cmd,
6231 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6232 NO_STR
6233 NEIGHBOR_STR
6234 NEIGHBOR_ADDR_STR2
6235 "Configure a neighbor as Route Server client\n")
6236 {
6237 int idx_peer = 2;
6238 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6239 bgp_node_afi(vty), bgp_node_safi(vty),
6240 PEER_FLAG_RSERVER_CLIENT);
6241 }
6242
6243 ALIAS_HIDDEN(no_neighbor_route_server_client,
6244 no_neighbor_route_server_client_hidden_cmd,
6245 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6246 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6247 "Configure a neighbor as Route Server client\n")
6248
6249 DEFUN (neighbor_nexthop_local_unchanged,
6250 neighbor_nexthop_local_unchanged_cmd,
6251 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6252 NEIGHBOR_STR
6253 NEIGHBOR_ADDR_STR2
6254 "Configure treatment of outgoing link-local nexthop attribute\n"
6255 "Leave link-local nexthop unchanged for this peer\n")
6256 {
6257 int idx_peer = 1;
6258 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6259 bgp_node_safi(vty),
6260 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6261 }
6262
6263 DEFUN (no_neighbor_nexthop_local_unchanged,
6264 no_neighbor_nexthop_local_unchanged_cmd,
6265 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6266 NO_STR
6267 NEIGHBOR_STR
6268 NEIGHBOR_ADDR_STR2
6269 "Configure treatment of outgoing link-local-nexthop attribute\n"
6270 "Leave link-local nexthop unchanged for this peer\n")
6271 {
6272 int idx_peer = 2;
6273 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6274 bgp_node_afi(vty), bgp_node_safi(vty),
6275 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6276 }
6277
6278 DEFUN (neighbor_attr_unchanged,
6279 neighbor_attr_unchanged_cmd,
6280 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6281 NEIGHBOR_STR
6282 NEIGHBOR_ADDR_STR2
6283 "BGP attribute is propagated unchanged to this neighbor\n"
6284 "As-path attribute\n"
6285 "Nexthop attribute\n"
6286 "Med attribute\n")
6287 {
6288 int idx = 0;
6289 char *peer_str = argv[1]->arg;
6290 struct peer *peer;
6291 bool aspath = false;
6292 bool nexthop = false;
6293 bool med = false;
6294 afi_t afi = bgp_node_afi(vty);
6295 safi_t safi = bgp_node_safi(vty);
6296 int ret = 0;
6297
6298 peer = peer_and_group_lookup_vty(vty, peer_str);
6299 if (!peer)
6300 return CMD_WARNING_CONFIG_FAILED;
6301
6302 if (argv_find(argv, argc, "as-path", &idx))
6303 aspath = true;
6304
6305 idx = 0;
6306 if (argv_find(argv, argc, "next-hop", &idx))
6307 nexthop = true;
6308
6309 idx = 0;
6310 if (argv_find(argv, argc, "med", &idx))
6311 med = true;
6312
6313 /* no flags means all of them! */
6314 if (!aspath && !nexthop && !med) {
6315 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6316 PEER_FLAG_AS_PATH_UNCHANGED);
6317 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6318 PEER_FLAG_NEXTHOP_UNCHANGED);
6319 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6320 PEER_FLAG_MED_UNCHANGED);
6321 } else {
6322 if (!aspath) {
6323 if (peer_af_flag_check(peer, afi, safi,
6324 PEER_FLAG_AS_PATH_UNCHANGED)) {
6325 ret |= peer_af_flag_unset_vty(
6326 vty, peer_str, afi, safi,
6327 PEER_FLAG_AS_PATH_UNCHANGED);
6328 }
6329 } else
6330 ret |= peer_af_flag_set_vty(
6331 vty, peer_str, afi, safi,
6332 PEER_FLAG_AS_PATH_UNCHANGED);
6333
6334 if (!nexthop) {
6335 if (peer_af_flag_check(peer, afi, safi,
6336 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6337 ret |= peer_af_flag_unset_vty(
6338 vty, peer_str, afi, safi,
6339 PEER_FLAG_NEXTHOP_UNCHANGED);
6340 }
6341 } else
6342 ret |= peer_af_flag_set_vty(
6343 vty, peer_str, afi, safi,
6344 PEER_FLAG_NEXTHOP_UNCHANGED);
6345
6346 if (!med) {
6347 if (peer_af_flag_check(peer, afi, safi,
6348 PEER_FLAG_MED_UNCHANGED)) {
6349 ret |= peer_af_flag_unset_vty(
6350 vty, peer_str, afi, safi,
6351 PEER_FLAG_MED_UNCHANGED);
6352 }
6353 } else
6354 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6355 PEER_FLAG_MED_UNCHANGED);
6356 }
6357
6358 return ret;
6359 }
6360
6361 ALIAS_HIDDEN(
6362 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6363 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6364 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6365 "BGP attribute is propagated unchanged to this neighbor\n"
6366 "As-path attribute\n"
6367 "Nexthop attribute\n"
6368 "Med attribute\n")
6369
6370 DEFUN (no_neighbor_attr_unchanged,
6371 no_neighbor_attr_unchanged_cmd,
6372 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6373 NO_STR
6374 NEIGHBOR_STR
6375 NEIGHBOR_ADDR_STR2
6376 "BGP attribute is propagated unchanged to this neighbor\n"
6377 "As-path attribute\n"
6378 "Nexthop attribute\n"
6379 "Med attribute\n")
6380 {
6381 int idx = 0;
6382 char *peer_str = argv[2]->arg;
6383 struct peer *peer;
6384 bool aspath = false;
6385 bool nexthop = false;
6386 bool med = false;
6387 afi_t afi = bgp_node_afi(vty);
6388 safi_t safi = bgp_node_safi(vty);
6389 int ret = 0;
6390
6391 peer = peer_and_group_lookup_vty(vty, peer_str);
6392 if (!peer)
6393 return CMD_WARNING_CONFIG_FAILED;
6394
6395 if (argv_find(argv, argc, "as-path", &idx))
6396 aspath = true;
6397
6398 idx = 0;
6399 if (argv_find(argv, argc, "next-hop", &idx))
6400 nexthop = true;
6401
6402 idx = 0;
6403 if (argv_find(argv, argc, "med", &idx))
6404 med = true;
6405
6406 if (!aspath && !nexthop && !med) // no flags means all of them!
6407 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6408 PEER_FLAG_AS_PATH_UNCHANGED)
6409 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6410 PEER_FLAG_NEXTHOP_UNCHANGED)
6411 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6412 PEER_FLAG_MED_UNCHANGED);
6413
6414 if (aspath)
6415 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6416 PEER_FLAG_AS_PATH_UNCHANGED);
6417
6418 if (nexthop)
6419 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6420 PEER_FLAG_NEXTHOP_UNCHANGED);
6421
6422 if (med)
6423 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6424 PEER_FLAG_MED_UNCHANGED);
6425
6426 return ret;
6427 }
6428
6429 ALIAS_HIDDEN(
6430 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6431 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6432 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6433 "BGP attribute is propagated unchanged to this neighbor\n"
6434 "As-path attribute\n"
6435 "Nexthop attribute\n"
6436 "Med attribute\n")
6437
6438 /* EBGP multihop configuration. */
6439 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6440 const char *ttl_str)
6441 {
6442 struct peer *peer;
6443 unsigned int ttl;
6444
6445 peer = peer_and_group_lookup_vty(vty, ip_str);
6446 if (!peer)
6447 return CMD_WARNING_CONFIG_FAILED;
6448
6449 if (peer->conf_if)
6450 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6451
6452 if (!ttl_str)
6453 ttl = MAXTTL;
6454 else
6455 ttl = strtoul(ttl_str, NULL, 10);
6456
6457 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6458 }
6459
6460 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6461 {
6462 struct peer *peer;
6463
6464 peer = peer_and_group_lookup_vty(vty, ip_str);
6465 if (!peer)
6466 return CMD_WARNING_CONFIG_FAILED;
6467
6468 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6469 }
6470
6471 /* neighbor ebgp-multihop. */
6472 DEFUN (neighbor_ebgp_multihop,
6473 neighbor_ebgp_multihop_cmd,
6474 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6475 NEIGHBOR_STR
6476 NEIGHBOR_ADDR_STR2
6477 "Allow EBGP neighbors not on directly connected networks\n")
6478 {
6479 int idx_peer = 1;
6480 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6481 }
6482
6483 DEFUN (neighbor_ebgp_multihop_ttl,
6484 neighbor_ebgp_multihop_ttl_cmd,
6485 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6486 NEIGHBOR_STR
6487 NEIGHBOR_ADDR_STR2
6488 "Allow EBGP neighbors not on directly connected networks\n"
6489 "maximum hop count\n")
6490 {
6491 int idx_peer = 1;
6492 int idx_number = 3;
6493 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6494 argv[idx_number]->arg);
6495 }
6496
6497 DEFUN (no_neighbor_ebgp_multihop,
6498 no_neighbor_ebgp_multihop_cmd,
6499 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6500 NO_STR
6501 NEIGHBOR_STR
6502 NEIGHBOR_ADDR_STR2
6503 "Allow EBGP neighbors not on directly connected networks\n"
6504 "maximum hop count\n")
6505 {
6506 int idx_peer = 2;
6507 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6508 }
6509
6510 static uint8_t get_role_by_name(const char *role_str)
6511 {
6512 if (strncmp(role_str, "peer", 2) == 0)
6513 return ROLE_PEER;
6514 if (strncmp(role_str, "provider", 2) == 0)
6515 return ROLE_PROVIDER;
6516 if (strncmp(role_str, "customer", 2) == 0)
6517 return ROLE_CUSTOMER;
6518 if (strncmp(role_str, "rs-server", 4) == 0)
6519 return ROLE_RS_SERVER;
6520 if (strncmp(role_str, "rs-client", 4) == 0)
6521 return ROLE_RS_CLIENT;
6522 return ROLE_UNDEFINED;
6523 }
6524
6525 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6526 const char *role_str, bool strict_mode)
6527 {
6528 struct peer *peer;
6529
6530 peer = peer_and_group_lookup_vty(vty, ip_str);
6531 if (!peer)
6532 return CMD_WARNING_CONFIG_FAILED;
6533 uint8_t role = get_role_by_name(role_str);
6534
6535 if (role == ROLE_UNDEFINED)
6536 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6537 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6538 }
6539
6540 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6541 {
6542 struct peer *peer;
6543
6544 peer = peer_and_group_lookup_vty(vty, ip_str);
6545 if (!peer)
6546 return CMD_WARNING_CONFIG_FAILED;
6547 return bgp_vty_return(vty, peer_role_unset(peer));
6548 }
6549
6550 DEFPY(neighbor_role,
6551 neighbor_role_cmd,
6552 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6553 NEIGHBOR_STR
6554 NEIGHBOR_ADDR_STR2
6555 "Set session role\n"
6556 ROLE_STR)
6557 {
6558 int idx_peer = 1;
6559 int idx_role = 3;
6560
6561 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6562 false);
6563 }
6564
6565 DEFPY(neighbor_role_strict,
6566 neighbor_role_strict_cmd,
6567 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6568 NEIGHBOR_STR
6569 NEIGHBOR_ADDR_STR2
6570 "Set session role\n"
6571 ROLE_STR
6572 "Use additional restriction on peer\n")
6573 {
6574 int idx_peer = 1;
6575 int idx_role = 3;
6576
6577 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6578 true);
6579 }
6580
6581 DEFPY(no_neighbor_role,
6582 no_neighbor_role_cmd,
6583 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6584 NO_STR
6585 NEIGHBOR_STR
6586 NEIGHBOR_ADDR_STR2
6587 "Set session role\n"
6588 ROLE_STR
6589 "Use additional restriction on peer\n")
6590 {
6591 int idx_peer = 2;
6592
6593 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6594 }
6595
6596 /* disable-connected-check */
6597 DEFUN (neighbor_disable_connected_check,
6598 neighbor_disable_connected_check_cmd,
6599 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6600 NEIGHBOR_STR
6601 NEIGHBOR_ADDR_STR2
6602 "one-hop away EBGP peer using loopback address\n"
6603 "Enforce EBGP neighbors perform multihop\n")
6604 {
6605 int idx_peer = 1;
6606 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6607 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6608 }
6609
6610 DEFUN (no_neighbor_disable_connected_check,
6611 no_neighbor_disable_connected_check_cmd,
6612 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6613 NO_STR
6614 NEIGHBOR_STR
6615 NEIGHBOR_ADDR_STR2
6616 "one-hop away EBGP peer using loopback address\n"
6617 "Enforce EBGP neighbors perform multihop\n")
6618 {
6619 int idx_peer = 2;
6620 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6621 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6622 }
6623
6624 /* disable-link-bw-encoding-ieee */
6625 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6626 neighbor_disable_link_bw_encoding_ieee_cmd,
6627 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6628 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6629 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6630 {
6631 int idx_peer = 1;
6632
6633 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6634 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6635 }
6636
6637 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6638 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6639 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6640 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6641 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6642 {
6643 int idx_peer = 2;
6644
6645 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6646 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6647 }
6648
6649 /* extended-optional-parameters */
6650 DEFUN(neighbor_extended_optional_parameters,
6651 neighbor_extended_optional_parameters_cmd,
6652 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6653 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6654 "Force the extended optional parameters format for OPEN messages\n")
6655 {
6656 int idx_peer = 1;
6657
6658 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6659 PEER_FLAG_EXTENDED_OPT_PARAMS);
6660 }
6661
6662 DEFUN(no_neighbor_extended_optional_parameters,
6663 no_neighbor_extended_optional_parameters_cmd,
6664 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6665 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6666 "Force the extended optional parameters format for OPEN messages\n")
6667 {
6668 int idx_peer = 2;
6669
6670 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6671 PEER_FLAG_EXTENDED_OPT_PARAMS);
6672 }
6673
6674 /* enforce-first-as */
6675 DEFUN (neighbor_enforce_first_as,
6676 neighbor_enforce_first_as_cmd,
6677 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6678 NEIGHBOR_STR
6679 NEIGHBOR_ADDR_STR2
6680 "Enforce the first AS for EBGP routes\n")
6681 {
6682 int idx_peer = 1;
6683
6684 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6685 PEER_FLAG_ENFORCE_FIRST_AS);
6686 }
6687
6688 DEFUN (no_neighbor_enforce_first_as,
6689 no_neighbor_enforce_first_as_cmd,
6690 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6691 NO_STR
6692 NEIGHBOR_STR
6693 NEIGHBOR_ADDR_STR2
6694 "Enforce the first AS for EBGP routes\n")
6695 {
6696 int idx_peer = 2;
6697
6698 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6699 PEER_FLAG_ENFORCE_FIRST_AS);
6700 }
6701
6702
6703 DEFUN (neighbor_description,
6704 neighbor_description_cmd,
6705 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6706 NEIGHBOR_STR
6707 NEIGHBOR_ADDR_STR2
6708 "Neighbor specific description\n"
6709 "Up to 80 characters describing this neighbor\n")
6710 {
6711 int idx_peer = 1;
6712 int idx_line = 3;
6713 struct peer *peer;
6714 char *str;
6715
6716 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6717 if (!peer)
6718 return CMD_WARNING_CONFIG_FAILED;
6719
6720 str = argv_concat(argv, argc, idx_line);
6721
6722 peer_description_set(peer, str);
6723
6724 XFREE(MTYPE_TMP, str);
6725
6726 return CMD_SUCCESS;
6727 }
6728
6729 DEFUN (no_neighbor_description,
6730 no_neighbor_description_cmd,
6731 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6732 NO_STR
6733 NEIGHBOR_STR
6734 NEIGHBOR_ADDR_STR2
6735 "Neighbor specific description\n")
6736 {
6737 int idx_peer = 2;
6738 struct peer *peer;
6739
6740 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6741 if (!peer)
6742 return CMD_WARNING_CONFIG_FAILED;
6743
6744 peer_description_unset(peer);
6745
6746 return CMD_SUCCESS;
6747 }
6748
6749 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6750 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6751 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6752 "Neighbor specific description\n"
6753 "Up to 80 characters describing this neighbor\n")
6754
6755 /* Neighbor update-source. */
6756 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6757 const char *source_str)
6758 {
6759 struct peer *peer;
6760 struct prefix p;
6761 union sockunion su;
6762
6763 peer = peer_and_group_lookup_vty(vty, peer_str);
6764 if (!peer)
6765 return CMD_WARNING_CONFIG_FAILED;
6766
6767 if (peer->conf_if)
6768 return CMD_WARNING;
6769
6770 if (source_str) {
6771 if (str2sockunion(source_str, &su) == 0)
6772 peer_update_source_addr_set(peer, &su);
6773 else {
6774 if (str2prefix(source_str, &p)) {
6775 vty_out(vty,
6776 "%% Invalid update-source, remove prefix length \n");
6777 return CMD_WARNING_CONFIG_FAILED;
6778 } else
6779 peer_update_source_if_set(peer, source_str);
6780 }
6781 } else
6782 peer_update_source_unset(peer);
6783
6784 return CMD_SUCCESS;
6785 }
6786
6787 #define BGP_UPDATE_SOURCE_HELP_STR \
6788 "IPv4 address\n" \
6789 "IPv6 address\n" \
6790 "Interface name (requires zebra to be running)\n"
6791
6792 DEFUN (neighbor_update_source,
6793 neighbor_update_source_cmd,
6794 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6795 NEIGHBOR_STR
6796 NEIGHBOR_ADDR_STR2
6797 "Source of routing updates\n"
6798 BGP_UPDATE_SOURCE_HELP_STR)
6799 {
6800 int idx_peer = 1;
6801 int idx_peer_2 = 3;
6802 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6803 argv[idx_peer_2]->arg);
6804 }
6805
6806 DEFUN (no_neighbor_update_source,
6807 no_neighbor_update_source_cmd,
6808 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6809 NO_STR
6810 NEIGHBOR_STR
6811 NEIGHBOR_ADDR_STR2
6812 "Source of routing updates\n"
6813 BGP_UPDATE_SOURCE_HELP_STR)
6814 {
6815 int idx_peer = 2;
6816 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6817 }
6818
6819 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6820 afi_t afi, safi_t safi,
6821 const char *rmap, int set)
6822 {
6823 int ret;
6824 struct peer *peer;
6825 struct route_map *route_map = NULL;
6826
6827 peer = peer_and_group_lookup_vty(vty, peer_str);
6828 if (!peer)
6829 return CMD_WARNING_CONFIG_FAILED;
6830
6831 if (set) {
6832 if (rmap)
6833 route_map = route_map_lookup_warn_noexist(vty, rmap);
6834 ret = peer_default_originate_set(peer, afi, safi,
6835 rmap, route_map);
6836 } else
6837 ret = peer_default_originate_unset(peer, afi, safi);
6838
6839 return bgp_vty_return(vty, ret);
6840 }
6841
6842 /* neighbor default-originate. */
6843 DEFUN (neighbor_default_originate,
6844 neighbor_default_originate_cmd,
6845 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6846 NEIGHBOR_STR
6847 NEIGHBOR_ADDR_STR2
6848 "Originate default route to this neighbor\n")
6849 {
6850 int idx_peer = 1;
6851 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6852 bgp_node_afi(vty),
6853 bgp_node_safi(vty), NULL, 1);
6854 }
6855
6856 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6857 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6858 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6859 "Originate default route to this neighbor\n")
6860
6861 DEFUN (neighbor_default_originate_rmap,
6862 neighbor_default_originate_rmap_cmd,
6863 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6864 NEIGHBOR_STR
6865 NEIGHBOR_ADDR_STR2
6866 "Originate default route to this neighbor\n"
6867 "Route-map to specify criteria to originate default\n"
6868 "route-map name\n")
6869 {
6870 int idx_peer = 1;
6871 int idx_word = 4;
6872 return peer_default_originate_set_vty(
6873 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6874 argv[idx_word]->arg, 1);
6875 }
6876
6877 ALIAS_HIDDEN(
6878 neighbor_default_originate_rmap,
6879 neighbor_default_originate_rmap_hidden_cmd,
6880 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6882 "Originate default route to this neighbor\n"
6883 "Route-map to specify criteria to originate default\n"
6884 "route-map name\n")
6885
6886 DEFUN (no_neighbor_default_originate,
6887 no_neighbor_default_originate_cmd,
6888 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6889 NO_STR
6890 NEIGHBOR_STR
6891 NEIGHBOR_ADDR_STR2
6892 "Originate default route to this neighbor\n"
6893 "Route-map to specify criteria to originate default\n"
6894 "route-map name\n")
6895 {
6896 int idx_peer = 2;
6897 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6898 bgp_node_afi(vty),
6899 bgp_node_safi(vty), NULL, 0);
6900 }
6901
6902 ALIAS_HIDDEN(
6903 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6904 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6905 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6906 "Originate default route to this neighbor\n"
6907 "Route-map to specify criteria to originate default\n"
6908 "route-map name\n")
6909
6910
6911 /* Set neighbor's BGP port. */
6912 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6913 const char *port_str)
6914 {
6915 struct peer *peer;
6916 uint16_t port;
6917 struct servent *sp;
6918
6919 peer = peer_and_group_lookup_vty(vty, ip_str);
6920 if (!peer)
6921 return CMD_WARNING_CONFIG_FAILED;
6922
6923 if (!port_str) {
6924 sp = getservbyname("bgp", "tcp");
6925 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6926 } else {
6927 port = strtoul(port_str, NULL, 10);
6928 }
6929
6930 peer_port_set(peer, port);
6931
6932 return CMD_SUCCESS;
6933 }
6934
6935 /* Set specified peer's BGP port. */
6936 DEFUN (neighbor_port,
6937 neighbor_port_cmd,
6938 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6939 NEIGHBOR_STR
6940 NEIGHBOR_ADDR_STR2
6941 "Neighbor's BGP port\n"
6942 "TCP port number\n")
6943 {
6944 int idx_ip = 1;
6945 int idx_number = 3;
6946 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6947 argv[idx_number]->arg);
6948 }
6949
6950 DEFUN (no_neighbor_port,
6951 no_neighbor_port_cmd,
6952 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6953 NO_STR
6954 NEIGHBOR_STR
6955 NEIGHBOR_ADDR_STR2
6956 "Neighbor's BGP port\n"
6957 "TCP port number\n")
6958 {
6959 int idx_ip = 2;
6960 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6961 }
6962
6963
6964 /* neighbor weight. */
6965 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6966 safi_t safi, const char *weight_str)
6967 {
6968 int ret;
6969 struct peer *peer;
6970 unsigned long weight;
6971
6972 peer = peer_and_group_lookup_vty(vty, ip_str);
6973 if (!peer)
6974 return CMD_WARNING_CONFIG_FAILED;
6975
6976 weight = strtoul(weight_str, NULL, 10);
6977
6978 ret = peer_weight_set(peer, afi, safi, weight);
6979 return bgp_vty_return(vty, ret);
6980 }
6981
6982 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6983 safi_t safi)
6984 {
6985 int ret;
6986 struct peer *peer;
6987
6988 peer = peer_and_group_lookup_vty(vty, ip_str);
6989 if (!peer)
6990 return CMD_WARNING_CONFIG_FAILED;
6991
6992 ret = peer_weight_unset(peer, afi, safi);
6993 return bgp_vty_return(vty, ret);
6994 }
6995
6996 DEFUN (neighbor_weight,
6997 neighbor_weight_cmd,
6998 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6999 NEIGHBOR_STR
7000 NEIGHBOR_ADDR_STR2
7001 "Set default weight for routes from this neighbor\n"
7002 "default weight\n")
7003 {
7004 int idx_peer = 1;
7005 int idx_number = 3;
7006 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7007 bgp_node_safi(vty), argv[idx_number]->arg);
7008 }
7009
7010 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7011 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7012 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7013 "Set default weight for routes from this neighbor\n"
7014 "default weight\n")
7015
7016 DEFUN (no_neighbor_weight,
7017 no_neighbor_weight_cmd,
7018 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7019 NO_STR
7020 NEIGHBOR_STR
7021 NEIGHBOR_ADDR_STR2
7022 "Set default weight for routes from this neighbor\n"
7023 "default weight\n")
7024 {
7025 int idx_peer = 2;
7026 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7027 bgp_node_afi(vty), bgp_node_safi(vty));
7028 }
7029
7030 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7031 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7032 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7033 "Set default weight for routes from this neighbor\n"
7034 "default weight\n")
7035
7036
7037 /* Override capability negotiation. */
7038 DEFUN (neighbor_override_capability,
7039 neighbor_override_capability_cmd,
7040 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7041 NEIGHBOR_STR
7042 NEIGHBOR_ADDR_STR2
7043 "Override capability negotiation result\n")
7044 {
7045 int idx_peer = 1;
7046 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7047 PEER_FLAG_OVERRIDE_CAPABILITY);
7048 }
7049
7050 DEFUN (no_neighbor_override_capability,
7051 no_neighbor_override_capability_cmd,
7052 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7053 NO_STR
7054 NEIGHBOR_STR
7055 NEIGHBOR_ADDR_STR2
7056 "Override capability negotiation result\n")
7057 {
7058 int idx_peer = 2;
7059 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7060 PEER_FLAG_OVERRIDE_CAPABILITY);
7061 }
7062
7063 DEFUN (neighbor_strict_capability,
7064 neighbor_strict_capability_cmd,
7065 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7066 NEIGHBOR_STR
7067 NEIGHBOR_ADDR_STR2
7068 "Strict capability negotiation match\n")
7069 {
7070 int idx_peer = 1;
7071
7072 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7073 PEER_FLAG_STRICT_CAP_MATCH);
7074 }
7075
7076 DEFUN (no_neighbor_strict_capability,
7077 no_neighbor_strict_capability_cmd,
7078 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7079 NO_STR
7080 NEIGHBOR_STR
7081 NEIGHBOR_ADDR_STR2
7082 "Strict capability negotiation match\n")
7083 {
7084 int idx_peer = 2;
7085
7086 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7087 PEER_FLAG_STRICT_CAP_MATCH);
7088 }
7089
7090 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7091 const char *keep_str, const char *hold_str)
7092 {
7093 int ret;
7094 struct peer *peer;
7095 uint32_t keepalive;
7096 uint32_t holdtime;
7097
7098 peer = peer_and_group_lookup_vty(vty, ip_str);
7099 if (!peer)
7100 return CMD_WARNING_CONFIG_FAILED;
7101
7102 keepalive = strtoul(keep_str, NULL, 10);
7103 holdtime = strtoul(hold_str, NULL, 10);
7104
7105 ret = peer_timers_set(peer, keepalive, holdtime);
7106
7107 return bgp_vty_return(vty, ret);
7108 }
7109
7110 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7111 {
7112 int ret;
7113 struct peer *peer;
7114
7115 peer = peer_and_group_lookup_vty(vty, ip_str);
7116 if (!peer)
7117 return CMD_WARNING_CONFIG_FAILED;
7118
7119 ret = peer_timers_unset(peer);
7120
7121 return bgp_vty_return(vty, ret);
7122 }
7123
7124 DEFUN (neighbor_timers,
7125 neighbor_timers_cmd,
7126 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7127 NEIGHBOR_STR
7128 NEIGHBOR_ADDR_STR2
7129 "BGP per neighbor timers\n"
7130 "Keepalive interval\n"
7131 "Holdtime\n")
7132 {
7133 int idx_peer = 1;
7134 int idx_number = 3;
7135 int idx_number_2 = 4;
7136 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7137 argv[idx_number]->arg,
7138 argv[idx_number_2]->arg);
7139 }
7140
7141 DEFUN (no_neighbor_timers,
7142 no_neighbor_timers_cmd,
7143 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7144 NO_STR
7145 NEIGHBOR_STR
7146 NEIGHBOR_ADDR_STR2
7147 "BGP per neighbor timers\n"
7148 "Keepalive interval\n"
7149 "Holdtime\n")
7150 {
7151 int idx_peer = 2;
7152 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7153 }
7154
7155
7156 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7157 const char *time_str)
7158 {
7159 int ret;
7160 struct peer *peer;
7161 uint32_t connect;
7162
7163 peer = peer_and_group_lookup_vty(vty, ip_str);
7164 if (!peer)
7165 return CMD_WARNING_CONFIG_FAILED;
7166
7167 connect = strtoul(time_str, NULL, 10);
7168
7169 ret = peer_timers_connect_set(peer, connect);
7170
7171 return bgp_vty_return(vty, ret);
7172 }
7173
7174 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7175 {
7176 int ret;
7177 struct peer *peer;
7178
7179 peer = peer_and_group_lookup_vty(vty, ip_str);
7180 if (!peer)
7181 return CMD_WARNING_CONFIG_FAILED;
7182
7183 ret = peer_timers_connect_unset(peer);
7184
7185 return bgp_vty_return(vty, ret);
7186 }
7187
7188 DEFUN (neighbor_timers_connect,
7189 neighbor_timers_connect_cmd,
7190 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7191 NEIGHBOR_STR
7192 NEIGHBOR_ADDR_STR2
7193 "BGP per neighbor timers\n"
7194 "BGP connect timer\n"
7195 "Connect timer\n")
7196 {
7197 int idx_peer = 1;
7198 int idx_number = 4;
7199 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7200 argv[idx_number]->arg);
7201 }
7202
7203 DEFUN (no_neighbor_timers_connect,
7204 no_neighbor_timers_connect_cmd,
7205 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7206 NO_STR
7207 NEIGHBOR_STR
7208 NEIGHBOR_ADDR_STR2
7209 "BGP per neighbor timers\n"
7210 "BGP connect timer\n"
7211 "Connect timer\n")
7212 {
7213 int idx_peer = 2;
7214 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7215 }
7216
7217 DEFPY (neighbor_timers_delayopen,
7218 neighbor_timers_delayopen_cmd,
7219 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7220 NEIGHBOR_STR
7221 NEIGHBOR_ADDR_STR2
7222 "BGP per neighbor timers\n"
7223 "RFC 4271 DelayOpenTimer\n"
7224 "DelayOpenTime timer interval\n")
7225 {
7226 struct peer *peer;
7227
7228 peer = peer_and_group_lookup_vty(vty, neighbor);
7229 if (!peer)
7230 return CMD_WARNING_CONFIG_FAILED;
7231
7232 if (!interval) {
7233 if (peer_timers_delayopen_unset(peer))
7234 return CMD_WARNING_CONFIG_FAILED;
7235 } else {
7236 if (peer_timers_delayopen_set(peer, interval))
7237 return CMD_WARNING_CONFIG_FAILED;
7238 }
7239
7240 return CMD_SUCCESS;
7241 }
7242
7243 DEFPY (no_neighbor_timers_delayopen,
7244 no_neighbor_timers_delayopen_cmd,
7245 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7246 NO_STR
7247 NEIGHBOR_STR
7248 NEIGHBOR_ADDR_STR2
7249 "BGP per neighbor timers\n"
7250 "RFC 4271 DelayOpenTimer\n"
7251 "DelayOpenTime timer interval\n")
7252 {
7253 struct peer *peer;
7254
7255 peer = peer_and_group_lookup_vty(vty, neighbor);
7256 if (!peer)
7257 return CMD_WARNING_CONFIG_FAILED;
7258
7259 if (peer_timers_delayopen_unset(peer))
7260 return CMD_WARNING_CONFIG_FAILED;
7261
7262 return CMD_SUCCESS;
7263 }
7264
7265 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7266 const char *time_str, int set)
7267 {
7268 int ret;
7269 struct peer *peer;
7270 uint32_t routeadv = 0;
7271
7272 peer = peer_and_group_lookup_vty(vty, ip_str);
7273 if (!peer)
7274 return CMD_WARNING_CONFIG_FAILED;
7275
7276 if (time_str)
7277 routeadv = strtoul(time_str, NULL, 10);
7278
7279 if (set)
7280 ret = peer_advertise_interval_set(peer, routeadv);
7281 else
7282 ret = peer_advertise_interval_unset(peer);
7283
7284 return bgp_vty_return(vty, ret);
7285 }
7286
7287 DEFUN (neighbor_advertise_interval,
7288 neighbor_advertise_interval_cmd,
7289 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7290 NEIGHBOR_STR
7291 NEIGHBOR_ADDR_STR2
7292 "Minimum interval between sending BGP routing updates\n"
7293 "time in seconds\n")
7294 {
7295 int idx_peer = 1;
7296 int idx_number = 3;
7297 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7298 argv[idx_number]->arg, 1);
7299 }
7300
7301 DEFUN (no_neighbor_advertise_interval,
7302 no_neighbor_advertise_interval_cmd,
7303 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7304 NO_STR
7305 NEIGHBOR_STR
7306 NEIGHBOR_ADDR_STR2
7307 "Minimum interval between sending BGP routing updates\n"
7308 "time in seconds\n")
7309 {
7310 int idx_peer = 2;
7311 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7312 }
7313
7314
7315 /* Time to wait before processing route-map updates */
7316 DEFUN (bgp_set_route_map_delay_timer,
7317 bgp_set_route_map_delay_timer_cmd,
7318 "bgp route-map delay-timer (0-600)",
7319 SET_STR
7320 "BGP route-map delay timer\n"
7321 "Time in secs to wait before processing route-map changes\n"
7322 "0 disables the timer, no route updates happen when route-maps change\n")
7323 {
7324 int idx_number = 3;
7325 uint32_t rmap_delay_timer;
7326
7327 if (argv[idx_number]->arg) {
7328 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7329 bm->rmap_update_timer = rmap_delay_timer;
7330
7331 /* if the dynamic update handling is being disabled, and a timer
7332 * is
7333 * running, stop the timer and act as if the timer has already
7334 * fired.
7335 */
7336 if (!rmap_delay_timer && bm->t_rmap_update) {
7337 THREAD_OFF(bm->t_rmap_update);
7338 thread_execute(bm->master, bgp_route_map_update_timer,
7339 NULL, 0);
7340 }
7341 return CMD_SUCCESS;
7342 } else {
7343 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7344 return CMD_WARNING_CONFIG_FAILED;
7345 }
7346 }
7347
7348 DEFUN (no_bgp_set_route_map_delay_timer,
7349 no_bgp_set_route_map_delay_timer_cmd,
7350 "no bgp route-map delay-timer [(0-600)]",
7351 NO_STR
7352 BGP_STR
7353 "Default BGP route-map delay timer\n"
7354 "Reset to default time to wait for processing route-map changes\n"
7355 "0 disables the timer, no route updates happen when route-maps change\n")
7356 {
7357
7358 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7359
7360 return CMD_SUCCESS;
7361 }
7362
7363 /* neighbor interface */
7364 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7365 const char *str)
7366 {
7367 struct peer *peer;
7368
7369 peer = peer_lookup_vty(vty, ip_str);
7370 if (!peer || peer->conf_if) {
7371 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7372 return CMD_WARNING_CONFIG_FAILED;
7373 }
7374
7375 if (str)
7376 peer_interface_set(peer, str);
7377 else
7378 peer_interface_unset(peer);
7379
7380 return CMD_SUCCESS;
7381 }
7382
7383 DEFUN (neighbor_interface,
7384 neighbor_interface_cmd,
7385 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7386 NEIGHBOR_STR
7387 NEIGHBOR_ADDR_STR
7388 "Interface\n"
7389 "Interface name\n")
7390 {
7391 int idx_ip = 1;
7392 int idx_word = 3;
7393
7394 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7395 }
7396
7397 DEFUN (no_neighbor_interface,
7398 no_neighbor_interface_cmd,
7399 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7400 NO_STR
7401 NEIGHBOR_STR
7402 NEIGHBOR_ADDR_STR
7403 "Interface\n"
7404 "Interface name\n")
7405 {
7406 int idx_peer = 2;
7407
7408 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7409 }
7410
7411 DEFUN (neighbor_distribute_list,
7412 neighbor_distribute_list_cmd,
7413 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7414 NEIGHBOR_STR
7415 NEIGHBOR_ADDR_STR2
7416 "Filter updates to/from this neighbor\n"
7417 "IP Access-list name\n"
7418 "Filter incoming updates\n"
7419 "Filter outgoing updates\n")
7420 {
7421 int idx_peer = 1;
7422 int idx_acl = 3;
7423 int direct, ret;
7424 struct peer *peer;
7425
7426 const char *pstr = argv[idx_peer]->arg;
7427 const char *acl = argv[idx_acl]->arg;
7428 const char *inout = argv[argc - 1]->text;
7429
7430 peer = peer_and_group_lookup_vty(vty, pstr);
7431 if (!peer)
7432 return CMD_WARNING_CONFIG_FAILED;
7433
7434 /* Check filter direction. */
7435 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7436 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7437 direct, acl);
7438
7439 return bgp_vty_return(vty, ret);
7440 }
7441
7442 ALIAS_HIDDEN(
7443 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7444 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7445 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7446 "Filter updates to/from this neighbor\n"
7447 "IP Access-list name\n"
7448 "Filter incoming updates\n"
7449 "Filter outgoing updates\n")
7450
7451 DEFUN (no_neighbor_distribute_list,
7452 no_neighbor_distribute_list_cmd,
7453 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7454 NO_STR
7455 NEIGHBOR_STR
7456 NEIGHBOR_ADDR_STR2
7457 "Filter updates to/from this neighbor\n"
7458 "IP Access-list name\n"
7459 "Filter incoming updates\n"
7460 "Filter outgoing updates\n")
7461 {
7462 int idx_peer = 2;
7463 int direct, ret;
7464 struct peer *peer;
7465
7466 const char *pstr = argv[idx_peer]->arg;
7467 const char *inout = argv[argc - 1]->text;
7468
7469 peer = peer_and_group_lookup_vty(vty, pstr);
7470 if (!peer)
7471 return CMD_WARNING_CONFIG_FAILED;
7472
7473 /* Check filter direction. */
7474 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7475 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7476 direct);
7477
7478 return bgp_vty_return(vty, ret);
7479 }
7480
7481 ALIAS_HIDDEN(
7482 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7483 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7484 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7485 "Filter updates to/from this neighbor\n"
7486 "IP Access-list name\n"
7487 "Filter incoming updates\n"
7488 "Filter outgoing updates\n")
7489
7490 /* Set prefix list to the peer. */
7491 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7492 afi_t afi, safi_t safi,
7493 const char *name_str,
7494 const char *direct_str)
7495 {
7496 int ret;
7497 int direct = FILTER_IN;
7498 struct peer *peer;
7499
7500 peer = peer_and_group_lookup_vty(vty, ip_str);
7501 if (!peer)
7502 return CMD_WARNING_CONFIG_FAILED;
7503
7504 /* Check filter direction. */
7505 if (strncmp(direct_str, "i", 1) == 0)
7506 direct = FILTER_IN;
7507 else if (strncmp(direct_str, "o", 1) == 0)
7508 direct = FILTER_OUT;
7509
7510 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7511
7512 return bgp_vty_return(vty, ret);
7513 }
7514
7515 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7516 afi_t afi, safi_t safi,
7517 const char *direct_str)
7518 {
7519 int ret;
7520 struct peer *peer;
7521 int direct = FILTER_IN;
7522
7523 peer = peer_and_group_lookup_vty(vty, ip_str);
7524 if (!peer)
7525 return CMD_WARNING_CONFIG_FAILED;
7526
7527 /* Check filter direction. */
7528 if (strncmp(direct_str, "i", 1) == 0)
7529 direct = FILTER_IN;
7530 else if (strncmp(direct_str, "o", 1) == 0)
7531 direct = FILTER_OUT;
7532
7533 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7534
7535 return bgp_vty_return(vty, ret);
7536 }
7537
7538 DEFUN (neighbor_prefix_list,
7539 neighbor_prefix_list_cmd,
7540 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7541 NEIGHBOR_STR
7542 NEIGHBOR_ADDR_STR2
7543 "Filter updates to/from this neighbor\n"
7544 "Name of a prefix list\n"
7545 "Filter incoming updates\n"
7546 "Filter outgoing updates\n")
7547 {
7548 int idx_peer = 1;
7549 int idx_word = 3;
7550 int idx_in_out = 4;
7551 return peer_prefix_list_set_vty(
7552 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7553 argv[idx_word]->arg, argv[idx_in_out]->arg);
7554 }
7555
7556 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7557 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7558 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7559 "Filter updates to/from this neighbor\n"
7560 "Name of a prefix list\n"
7561 "Filter incoming updates\n"
7562 "Filter outgoing updates\n")
7563
7564 DEFUN (no_neighbor_prefix_list,
7565 no_neighbor_prefix_list_cmd,
7566 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7567 NO_STR
7568 NEIGHBOR_STR
7569 NEIGHBOR_ADDR_STR2
7570 "Filter updates to/from this neighbor\n"
7571 "Name of a prefix list\n"
7572 "Filter incoming updates\n"
7573 "Filter outgoing updates\n")
7574 {
7575 int idx_peer = 2;
7576 int idx_in_out = 5;
7577 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7578 bgp_node_afi(vty), bgp_node_safi(vty),
7579 argv[idx_in_out]->arg);
7580 }
7581
7582 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7583 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7584 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7585 "Filter updates to/from this neighbor\n"
7586 "Name of a prefix list\n"
7587 "Filter incoming updates\n"
7588 "Filter outgoing updates\n")
7589
7590 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7591 safi_t safi, const char *name_str,
7592 const char *direct_str)
7593 {
7594 int ret;
7595 struct peer *peer;
7596 int direct = FILTER_IN;
7597
7598 peer = peer_and_group_lookup_vty(vty, ip_str);
7599 if (!peer)
7600 return CMD_WARNING_CONFIG_FAILED;
7601
7602 /* Check filter direction. */
7603 if (strncmp(direct_str, "i", 1) == 0)
7604 direct = FILTER_IN;
7605 else if (strncmp(direct_str, "o", 1) == 0)
7606 direct = FILTER_OUT;
7607
7608 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7609
7610 return bgp_vty_return(vty, ret);
7611 }
7612
7613 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7614 safi_t safi, const char *direct_str)
7615 {
7616 int ret;
7617 struct peer *peer;
7618 int direct = FILTER_IN;
7619
7620 peer = peer_and_group_lookup_vty(vty, ip_str);
7621 if (!peer)
7622 return CMD_WARNING_CONFIG_FAILED;
7623
7624 /* Check filter direction. */
7625 if (strncmp(direct_str, "i", 1) == 0)
7626 direct = FILTER_IN;
7627 else if (strncmp(direct_str, "o", 1) == 0)
7628 direct = FILTER_OUT;
7629
7630 ret = peer_aslist_unset(peer, afi, safi, direct);
7631
7632 return bgp_vty_return(vty, ret);
7633 }
7634
7635 DEFUN (neighbor_filter_list,
7636 neighbor_filter_list_cmd,
7637 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7638 NEIGHBOR_STR
7639 NEIGHBOR_ADDR_STR2
7640 "Establish BGP filters\n"
7641 "AS path access-list name\n"
7642 "Filter incoming routes\n"
7643 "Filter outgoing routes\n")
7644 {
7645 int idx_peer = 1;
7646 int idx_word = 3;
7647 int idx_in_out = 4;
7648 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7649 bgp_node_safi(vty), argv[idx_word]->arg,
7650 argv[idx_in_out]->arg);
7651 }
7652
7653 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7654 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7655 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7656 "Establish BGP filters\n"
7657 "AS path access-list name\n"
7658 "Filter incoming routes\n"
7659 "Filter outgoing routes\n")
7660
7661 DEFUN (no_neighbor_filter_list,
7662 no_neighbor_filter_list_cmd,
7663 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7664 NO_STR
7665 NEIGHBOR_STR
7666 NEIGHBOR_ADDR_STR2
7667 "Establish BGP filters\n"
7668 "AS path access-list name\n"
7669 "Filter incoming routes\n"
7670 "Filter outgoing routes\n")
7671 {
7672 int idx_peer = 2;
7673 int idx_in_out = 5;
7674 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7675 bgp_node_afi(vty), bgp_node_safi(vty),
7676 argv[idx_in_out]->arg);
7677 }
7678
7679 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7680 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7681 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7682 "Establish BGP filters\n"
7683 "AS path access-list name\n"
7684 "Filter incoming routes\n"
7685 "Filter outgoing routes\n")
7686
7687 /* Set advertise-map to the peer. */
7688 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7689 afi_t afi, safi_t safi,
7690 const char *advertise_str,
7691 const char *condition_str, bool condition,
7692 bool set)
7693 {
7694 int ret = CMD_WARNING_CONFIG_FAILED;
7695 struct peer *peer;
7696 struct route_map *advertise_map;
7697 struct route_map *condition_map;
7698
7699 peer = peer_and_group_lookup_vty(vty, ip_str);
7700 if (!peer)
7701 return ret;
7702
7703 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7704 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7705
7706 if (set)
7707 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7708 advertise_map, condition_str,
7709 condition_map, condition);
7710 else
7711 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7712 advertise_map, condition_str,
7713 condition_map, condition);
7714
7715 return bgp_vty_return(vty, ret);
7716 }
7717
7718 DEFPY (bgp_condadv_period,
7719 bgp_condadv_period_cmd,
7720 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7721 NO_STR
7722 BGP_STR
7723 "Conditional advertisement settings\n"
7724 "Set period to rescan BGP table to check if condition is met\n"
7725 "Period between BGP table scans, in seconds; default 60\n")
7726 {
7727 VTY_DECLVAR_CONTEXT(bgp, bgp);
7728
7729 bgp->condition_check_period =
7730 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7731
7732 return CMD_SUCCESS;
7733 }
7734
7735 DEFPY (neighbor_advertise_map,
7736 neighbor_advertise_map_cmd,
7737 "[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",
7738 NO_STR
7739 NEIGHBOR_STR
7740 NEIGHBOR_ADDR_STR2
7741 "Route-map to conditionally advertise routes\n"
7742 "Name of advertise map\n"
7743 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7744 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7745 "Name of the exist or non exist map\n")
7746 {
7747 bool condition = CONDITION_EXIST;
7748
7749 if (!strcmp(exist, "non-exist-map"))
7750 condition = CONDITION_NON_EXIST;
7751
7752 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7753 bgp_node_safi(vty), advertise_str,
7754 condition_str, condition, !no);
7755 }
7756
7757 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7758 "[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",
7759 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7760 "Route-map to conditionally advertise routes\n"
7761 "Name of advertise map\n"
7762 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7763 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7764 "Name of the exist or non exist map\n")
7765
7766 /* Set route-map to the peer. */
7767 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7768 afi_t afi, safi_t safi, const char *name_str,
7769 const char *direct_str)
7770 {
7771 int ret;
7772 struct peer *peer;
7773 int direct = RMAP_IN;
7774 struct route_map *route_map;
7775
7776 peer = peer_and_group_lookup_vty(vty, ip_str);
7777 if (!peer)
7778 return CMD_WARNING_CONFIG_FAILED;
7779
7780 /* Check filter direction. */
7781 if (strncmp(direct_str, "in", 2) == 0)
7782 direct = RMAP_IN;
7783 else if (strncmp(direct_str, "o", 1) == 0)
7784 direct = RMAP_OUT;
7785
7786 route_map = route_map_lookup_warn_noexist(vty, name_str);
7787 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7788
7789 return bgp_vty_return(vty, ret);
7790 }
7791
7792 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7793 afi_t afi, safi_t safi,
7794 const char *direct_str)
7795 {
7796 int ret;
7797 struct peer *peer;
7798 int direct = RMAP_IN;
7799
7800 peer = peer_and_group_lookup_vty(vty, ip_str);
7801 if (!peer)
7802 return CMD_WARNING_CONFIG_FAILED;
7803
7804 /* Check filter direction. */
7805 if (strncmp(direct_str, "in", 2) == 0)
7806 direct = RMAP_IN;
7807 else if (strncmp(direct_str, "o", 1) == 0)
7808 direct = RMAP_OUT;
7809
7810 ret = peer_route_map_unset(peer, afi, safi, direct);
7811
7812 return bgp_vty_return(vty, ret);
7813 }
7814
7815 DEFUN (neighbor_route_map,
7816 neighbor_route_map_cmd,
7817 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7818 NEIGHBOR_STR
7819 NEIGHBOR_ADDR_STR2
7820 "Apply route map to neighbor\n"
7821 "Name of route map\n"
7822 "Apply map to incoming routes\n"
7823 "Apply map to outbound routes\n")
7824 {
7825 int idx_peer = 1;
7826 int idx_word = 3;
7827 int idx_in_out = 4;
7828 return peer_route_map_set_vty(
7829 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7830 argv[idx_word]->arg, argv[idx_in_out]->arg);
7831 }
7832
7833 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7834 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7835 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7836 "Apply route map to neighbor\n"
7837 "Name of route map\n"
7838 "Apply map to incoming routes\n"
7839 "Apply map to outbound routes\n")
7840
7841 DEFUN (no_neighbor_route_map,
7842 no_neighbor_route_map_cmd,
7843 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7844 NO_STR
7845 NEIGHBOR_STR
7846 NEIGHBOR_ADDR_STR2
7847 "Apply route map to neighbor\n"
7848 "Name of route map\n"
7849 "Apply map to incoming routes\n"
7850 "Apply map to outbound routes\n")
7851 {
7852 int idx_peer = 2;
7853 int idx_in_out = 5;
7854 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7855 bgp_node_afi(vty), bgp_node_safi(vty),
7856 argv[idx_in_out]->arg);
7857 }
7858
7859 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7860 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7861 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7862 "Apply route map to neighbor\n"
7863 "Name of route map\n"
7864 "Apply map to incoming routes\n"
7865 "Apply map to outbound routes\n")
7866
7867 /* Set unsuppress-map to the peer. */
7868 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7869 afi_t afi, safi_t safi,
7870 const char *name_str)
7871 {
7872 int ret;
7873 struct peer *peer;
7874 struct route_map *route_map;
7875
7876 peer = peer_and_group_lookup_vty(vty, ip_str);
7877 if (!peer)
7878 return CMD_WARNING_CONFIG_FAILED;
7879
7880 route_map = route_map_lookup_warn_noexist(vty, name_str);
7881 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7882
7883 return bgp_vty_return(vty, ret);
7884 }
7885
7886 /* Unset route-map from the peer. */
7887 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7888 afi_t afi, safi_t safi)
7889 {
7890 int ret;
7891 struct peer *peer;
7892
7893 peer = peer_and_group_lookup_vty(vty, ip_str);
7894 if (!peer)
7895 return CMD_WARNING_CONFIG_FAILED;
7896
7897 ret = peer_unsuppress_map_unset(peer, afi, safi);
7898
7899 return bgp_vty_return(vty, ret);
7900 }
7901
7902 DEFUN (neighbor_unsuppress_map,
7903 neighbor_unsuppress_map_cmd,
7904 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7905 NEIGHBOR_STR
7906 NEIGHBOR_ADDR_STR2
7907 "Route-map to selectively unsuppress suppressed routes\n"
7908 "Name of route map\n")
7909 {
7910 int idx_peer = 1;
7911 int idx_word = 3;
7912 return peer_unsuppress_map_set_vty(
7913 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7914 argv[idx_word]->arg);
7915 }
7916
7917 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7918 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7920 "Route-map to selectively unsuppress suppressed routes\n"
7921 "Name of route map\n")
7922
7923 DEFUN (no_neighbor_unsuppress_map,
7924 no_neighbor_unsuppress_map_cmd,
7925 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7926 NO_STR
7927 NEIGHBOR_STR
7928 NEIGHBOR_ADDR_STR2
7929 "Route-map to selectively unsuppress suppressed routes\n"
7930 "Name of route map\n")
7931 {
7932 int idx_peer = 2;
7933 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7934 bgp_node_afi(vty),
7935 bgp_node_safi(vty));
7936 }
7937
7938 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7939 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7940 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7941 "Route-map to selectively unsuppress suppressed routes\n"
7942 "Name of route map\n")
7943
7944 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7945 afi_t afi, safi_t safi,
7946 const char *num_str,
7947 const char *threshold_str, int warning,
7948 const char *restart_str,
7949 const char *force_str)
7950 {
7951 int ret;
7952 struct peer *peer;
7953 uint32_t max;
7954 uint8_t threshold;
7955 uint16_t restart;
7956
7957 peer = peer_and_group_lookup_vty(vty, ip_str);
7958 if (!peer)
7959 return CMD_WARNING_CONFIG_FAILED;
7960
7961 max = strtoul(num_str, NULL, 10);
7962 if (threshold_str)
7963 threshold = atoi(threshold_str);
7964 else
7965 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7966
7967 if (restart_str)
7968 restart = atoi(restart_str);
7969 else
7970 restart = 0;
7971
7972 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7973 restart, force_str ? true : false);
7974
7975 return bgp_vty_return(vty, ret);
7976 }
7977
7978 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7979 afi_t afi, safi_t safi)
7980 {
7981 int ret;
7982 struct peer *peer;
7983
7984 peer = peer_and_group_lookup_vty(vty, ip_str);
7985 if (!peer)
7986 return CMD_WARNING_CONFIG_FAILED;
7987
7988 ret = peer_maximum_prefix_unset(peer, afi, safi);
7989
7990 return bgp_vty_return(vty, ret);
7991 }
7992
7993 /* Maximum number of prefix to be sent to the neighbor. */
7994 DEFUN(neighbor_maximum_prefix_out,
7995 neighbor_maximum_prefix_out_cmd,
7996 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7997 NEIGHBOR_STR
7998 NEIGHBOR_ADDR_STR2
7999 "Maximum number of prefixes to be sent to this peer\n"
8000 "Maximum no. of prefix limit\n")
8001 {
8002 int ret;
8003 int idx_peer = 1;
8004 int idx_number = 3;
8005 struct peer *peer;
8006 uint32_t max;
8007 afi_t afi = bgp_node_afi(vty);
8008 safi_t safi = bgp_node_safi(vty);
8009
8010 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8011 if (!peer)
8012 return CMD_WARNING_CONFIG_FAILED;
8013
8014 max = strtoul(argv[idx_number]->arg, NULL, 10);
8015
8016 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8017
8018 return bgp_vty_return(vty, ret);
8019 }
8020
8021 DEFUN(no_neighbor_maximum_prefix_out,
8022 no_neighbor_maximum_prefix_out_cmd,
8023 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8024 NO_STR
8025 NEIGHBOR_STR
8026 NEIGHBOR_ADDR_STR2
8027 "Maximum number of prefixes to be sent to this peer\n"
8028 "Maximum no. of prefix limit\n")
8029 {
8030 int ret;
8031 int idx_peer = 2;
8032 struct peer *peer;
8033 afi_t afi = bgp_node_afi(vty);
8034 safi_t safi = bgp_node_safi(vty);
8035
8036 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8037 if (!peer)
8038 return CMD_WARNING_CONFIG_FAILED;
8039
8040 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8041
8042 return bgp_vty_return(vty, ret);
8043 }
8044
8045 /* Maximum number of prefix configuration. Prefix count is different
8046 for each peer configuration. So this configuration can be set for
8047 each peer configuration. */
8048 DEFUN (neighbor_maximum_prefix,
8049 neighbor_maximum_prefix_cmd,
8050 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8051 NEIGHBOR_STR
8052 NEIGHBOR_ADDR_STR2
8053 "Maximum number of prefix accept from this peer\n"
8054 "maximum no. of prefix limit\n"
8055 "Force checking all received routes not only accepted\n")
8056 {
8057 int idx_peer = 1;
8058 int idx_number = 3;
8059 int idx_force = 0;
8060 char *force = NULL;
8061
8062 if (argv_find(argv, argc, "force", &idx_force))
8063 force = argv[idx_force]->arg;
8064
8065 return peer_maximum_prefix_set_vty(
8066 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8067 argv[idx_number]->arg, NULL, 0, NULL, force);
8068 }
8069
8070 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8071 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8072 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8073 "Maximum number of prefix accept from this peer\n"
8074 "maximum no. of prefix limit\n"
8075 "Force checking all received routes not only accepted\n")
8076
8077 DEFUN (neighbor_maximum_prefix_threshold,
8078 neighbor_maximum_prefix_threshold_cmd,
8079 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8080 NEIGHBOR_STR
8081 NEIGHBOR_ADDR_STR2
8082 "Maximum number of prefix accept from this peer\n"
8083 "maximum no. of prefix limit\n"
8084 "Threshold value (%) at which to generate a warning msg\n"
8085 "Force checking all received routes not only accepted\n")
8086 {
8087 int idx_peer = 1;
8088 int idx_number = 3;
8089 int idx_number_2 = 4;
8090 int idx_force = 0;
8091 char *force = NULL;
8092
8093 if (argv_find(argv, argc, "force", &idx_force))
8094 force = argv[idx_force]->arg;
8095
8096 return peer_maximum_prefix_set_vty(
8097 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8098 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8099 }
8100
8101 ALIAS_HIDDEN(
8102 neighbor_maximum_prefix_threshold,
8103 neighbor_maximum_prefix_threshold_hidden_cmd,
8104 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8105 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8106 "Maximum number of prefix accept from this peer\n"
8107 "maximum no. of prefix limit\n"
8108 "Threshold value (%) at which to generate a warning msg\n"
8109 "Force checking all received routes not only accepted\n")
8110
8111 DEFUN (neighbor_maximum_prefix_warning,
8112 neighbor_maximum_prefix_warning_cmd,
8113 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8114 NEIGHBOR_STR
8115 NEIGHBOR_ADDR_STR2
8116 "Maximum number of prefix accept from this peer\n"
8117 "maximum no. of prefix limit\n"
8118 "Only give warning message when limit is exceeded\n"
8119 "Force checking all received routes not only accepted\n")
8120 {
8121 int idx_peer = 1;
8122 int idx_number = 3;
8123 int idx_force = 0;
8124 char *force = NULL;
8125
8126 if (argv_find(argv, argc, "force", &idx_force))
8127 force = argv[idx_force]->arg;
8128
8129 return peer_maximum_prefix_set_vty(
8130 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8131 argv[idx_number]->arg, NULL, 1, NULL, force);
8132 }
8133
8134 ALIAS_HIDDEN(
8135 neighbor_maximum_prefix_warning,
8136 neighbor_maximum_prefix_warning_hidden_cmd,
8137 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8138 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8139 "Maximum number of prefix accept from this peer\n"
8140 "maximum no. of prefix limit\n"
8141 "Only give warning message when limit is exceeded\n"
8142 "Force checking all received routes not only accepted\n")
8143
8144 DEFUN (neighbor_maximum_prefix_threshold_warning,
8145 neighbor_maximum_prefix_threshold_warning_cmd,
8146 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8147 NEIGHBOR_STR
8148 NEIGHBOR_ADDR_STR2
8149 "Maximum number of prefix accept from this peer\n"
8150 "maximum no. of prefix limit\n"
8151 "Threshold value (%) at which to generate a warning msg\n"
8152 "Only give warning message when limit is exceeded\n"
8153 "Force checking all received routes not only accepted\n")
8154 {
8155 int idx_peer = 1;
8156 int idx_number = 3;
8157 int idx_number_2 = 4;
8158 int idx_force = 0;
8159 char *force = NULL;
8160
8161 if (argv_find(argv, argc, "force", &idx_force))
8162 force = argv[idx_force]->arg;
8163
8164 return peer_maximum_prefix_set_vty(
8165 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8166 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8167 }
8168
8169 ALIAS_HIDDEN(
8170 neighbor_maximum_prefix_threshold_warning,
8171 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8172 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8173 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8174 "Maximum number of prefix accept from this peer\n"
8175 "maximum no. of prefix limit\n"
8176 "Threshold value (%) at which to generate a warning msg\n"
8177 "Only give warning message when limit is exceeded\n"
8178 "Force checking all received routes not only accepted\n")
8179
8180 DEFUN (neighbor_maximum_prefix_restart,
8181 neighbor_maximum_prefix_restart_cmd,
8182 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8183 NEIGHBOR_STR
8184 NEIGHBOR_ADDR_STR2
8185 "Maximum number of prefix accept from this peer\n"
8186 "maximum no. of prefix limit\n"
8187 "Restart bgp connection after limit is exceeded\n"
8188 "Restart interval in minutes\n"
8189 "Force checking all received routes not only accepted\n")
8190 {
8191 int idx_peer = 1;
8192 int idx_number = 3;
8193 int idx_number_2 = 5;
8194 int idx_force = 0;
8195 char *force = NULL;
8196
8197 if (argv_find(argv, argc, "force", &idx_force))
8198 force = argv[idx_force]->arg;
8199
8200 return peer_maximum_prefix_set_vty(
8201 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8202 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8203 }
8204
8205 ALIAS_HIDDEN(
8206 neighbor_maximum_prefix_restart,
8207 neighbor_maximum_prefix_restart_hidden_cmd,
8208 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8210 "Maximum number of prefix accept from this peer\n"
8211 "maximum no. of prefix limit\n"
8212 "Restart bgp connection after limit is exceeded\n"
8213 "Restart interval in minutes\n"
8214 "Force checking all received routes not only accepted\n")
8215
8216 DEFUN (neighbor_maximum_prefix_threshold_restart,
8217 neighbor_maximum_prefix_threshold_restart_cmd,
8218 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8219 NEIGHBOR_STR
8220 NEIGHBOR_ADDR_STR2
8221 "Maximum number of prefixes to accept from this peer\n"
8222 "maximum no. of prefix limit\n"
8223 "Threshold value (%) at which to generate a warning msg\n"
8224 "Restart bgp connection after limit is exceeded\n"
8225 "Restart interval in minutes\n"
8226 "Force checking all received routes not only accepted\n")
8227 {
8228 int idx_peer = 1;
8229 int idx_number = 3;
8230 int idx_number_2 = 4;
8231 int idx_number_3 = 6;
8232 int idx_force = 0;
8233 char *force = NULL;
8234
8235 if (argv_find(argv, argc, "force", &idx_force))
8236 force = argv[idx_force]->arg;
8237
8238 return peer_maximum_prefix_set_vty(
8239 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8240 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8241 argv[idx_number_3]->arg, force);
8242 }
8243
8244 ALIAS_HIDDEN(
8245 neighbor_maximum_prefix_threshold_restart,
8246 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8247 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8248 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8249 "Maximum number of prefixes to accept from this peer\n"
8250 "maximum no. of prefix limit\n"
8251 "Threshold value (%) at which to generate a warning msg\n"
8252 "Restart bgp connection after limit is exceeded\n"
8253 "Restart interval in minutes\n"
8254 "Force checking all received routes not only accepted\n")
8255
8256 DEFUN (no_neighbor_maximum_prefix,
8257 no_neighbor_maximum_prefix_cmd,
8258 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8259 NO_STR
8260 NEIGHBOR_STR
8261 NEIGHBOR_ADDR_STR2
8262 "Maximum number of prefixes to accept from this peer\n"
8263 "maximum no. of prefix limit\n"
8264 "Threshold value (%) at which to generate a warning msg\n"
8265 "Restart bgp connection after limit is exceeded\n"
8266 "Restart interval in minutes\n"
8267 "Only give warning message when limit is exceeded\n"
8268 "Force checking all received routes not only accepted\n")
8269 {
8270 int idx_peer = 2;
8271 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8272 bgp_node_afi(vty),
8273 bgp_node_safi(vty));
8274 }
8275
8276 ALIAS_HIDDEN(
8277 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8278 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8279 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8280 "Maximum number of prefixes to accept from this peer\n"
8281 "maximum no. of prefix limit\n"
8282 "Threshold value (%) at which to generate a warning msg\n"
8283 "Restart bgp connection after limit is exceeded\n"
8284 "Restart interval in minutes\n"
8285 "Only give warning message when limit is exceeded\n"
8286 "Force checking all received routes not only accepted\n")
8287
8288 /* "neighbor soo" */
8289 DEFPY (neighbor_soo,
8290 neighbor_soo_cmd,
8291 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8292 NEIGHBOR_STR
8293 NEIGHBOR_ADDR_STR2
8294 "Set the Site-of-Origin (SoO) extended community\n"
8295 "VPN extended community\n")
8296 {
8297 struct peer *peer;
8298 afi_t afi = bgp_node_afi(vty);
8299 safi_t safi = bgp_node_safi(vty);
8300 struct ecommunity *ecomm_soo;
8301
8302 peer = peer_and_group_lookup_vty(vty, neighbor);
8303 if (!peer)
8304 return CMD_WARNING_CONFIG_FAILED;
8305
8306 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8307 if (!ecomm_soo) {
8308 vty_out(vty, "%% Malformed SoO extended community\n");
8309 return CMD_WARNING;
8310 }
8311 ecommunity_str(ecomm_soo);
8312
8313 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8314 ecommunity_free(&peer->soo[afi][safi]);
8315 peer->soo[afi][safi] = ecomm_soo;
8316 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8317 }
8318
8319 return bgp_vty_return(vty,
8320 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8321 }
8322
8323 DEFPY (no_neighbor_soo,
8324 no_neighbor_soo_cmd,
8325 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8326 NO_STR
8327 NEIGHBOR_STR
8328 NEIGHBOR_ADDR_STR2
8329 "Set the Site-of-Origin (SoO) extended community\n"
8330 "VPN extended community\n")
8331 {
8332 struct peer *peer;
8333 afi_t afi = bgp_node_afi(vty);
8334 safi_t safi = bgp_node_safi(vty);
8335
8336 peer = peer_and_group_lookup_vty(vty, neighbor);
8337 if (!peer)
8338 return CMD_WARNING_CONFIG_FAILED;
8339
8340 ecommunity_free(&peer->soo[afi][safi]);
8341
8342 return bgp_vty_return(
8343 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8344 }
8345
8346 /* "neighbor allowas-in" */
8347 DEFUN (neighbor_allowas_in,
8348 neighbor_allowas_in_cmd,
8349 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8350 NEIGHBOR_STR
8351 NEIGHBOR_ADDR_STR2
8352 "Accept as-path with my AS present in it\n"
8353 "Number of occurrences of AS number\n"
8354 "Only accept my AS in the as-path if the route was originated in my AS\n")
8355 {
8356 int idx_peer = 1;
8357 int idx_number_origin = 3;
8358 int ret;
8359 int origin = 0;
8360 struct peer *peer;
8361 int allow_num = 0;
8362
8363 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8364 if (!peer)
8365 return CMD_WARNING_CONFIG_FAILED;
8366
8367 if (argc <= idx_number_origin)
8368 allow_num = 3;
8369 else {
8370 if (argv[idx_number_origin]->type == WORD_TKN)
8371 origin = 1;
8372 else
8373 allow_num = atoi(argv[idx_number_origin]->arg);
8374 }
8375
8376 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8377 allow_num, origin);
8378
8379 return bgp_vty_return(vty, ret);
8380 }
8381
8382 ALIAS_HIDDEN(
8383 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8384 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8385 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8386 "Accept as-path with my AS present in it\n"
8387 "Number of occurrences of AS number\n"
8388 "Only accept my AS in the as-path if the route was originated in my AS\n")
8389
8390 DEFUN (no_neighbor_allowas_in,
8391 no_neighbor_allowas_in_cmd,
8392 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8393 NO_STR
8394 NEIGHBOR_STR
8395 NEIGHBOR_ADDR_STR2
8396 "allow local ASN appears in aspath attribute\n"
8397 "Number of occurrences of AS number\n"
8398 "Only accept my AS in the as-path if the route was originated in my AS\n")
8399 {
8400 int idx_peer = 2;
8401 int ret;
8402 struct peer *peer;
8403
8404 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8405 if (!peer)
8406 return CMD_WARNING_CONFIG_FAILED;
8407
8408 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8409 bgp_node_safi(vty));
8410
8411 return bgp_vty_return(vty, ret);
8412 }
8413
8414 ALIAS_HIDDEN(
8415 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8416 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8417 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8418 "allow local ASN appears in aspath attribute\n"
8419 "Number of occurrences of AS number\n"
8420 "Only accept my AS in the as-path if the route was originated in my AS\n")
8421
8422 DEFUN (neighbor_ttl_security,
8423 neighbor_ttl_security_cmd,
8424 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8425 NEIGHBOR_STR
8426 NEIGHBOR_ADDR_STR2
8427 "BGP ttl-security parameters\n"
8428 "Specify the maximum number of hops to the BGP peer\n"
8429 "Number of hops to BGP peer\n")
8430 {
8431 int idx_peer = 1;
8432 int idx_number = 4;
8433 struct peer *peer;
8434 int gtsm_hops;
8435
8436 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8437 if (!peer)
8438 return CMD_WARNING_CONFIG_FAILED;
8439
8440 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8441
8442 /*
8443 * If 'neighbor swpX', then this is for directly connected peers,
8444 * we should not accept a ttl-security hops value greater than 1.
8445 */
8446 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8447 vty_out(vty,
8448 "%s is directly connected peer, hops cannot exceed 1\n",
8449 argv[idx_peer]->arg);
8450 return CMD_WARNING_CONFIG_FAILED;
8451 }
8452
8453 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8454 }
8455
8456 DEFUN (no_neighbor_ttl_security,
8457 no_neighbor_ttl_security_cmd,
8458 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8459 NO_STR
8460 NEIGHBOR_STR
8461 NEIGHBOR_ADDR_STR2
8462 "BGP ttl-security parameters\n"
8463 "Specify the maximum number of hops to the BGP peer\n"
8464 "Number of hops to BGP peer\n")
8465 {
8466 int idx_peer = 2;
8467 struct peer *peer;
8468
8469 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8470 if (!peer)
8471 return CMD_WARNING_CONFIG_FAILED;
8472
8473 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8474 }
8475
8476 /* disable-addpath-rx */
8477 DEFUN(neighbor_disable_addpath_rx,
8478 neighbor_disable_addpath_rx_cmd,
8479 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8480 NEIGHBOR_STR
8481 NEIGHBOR_ADDR_STR2
8482 "Do not accept additional paths\n")
8483 {
8484 char *peer_str = argv[1]->arg;
8485 struct peer *peer;
8486 afi_t afi = bgp_node_afi(vty);
8487 safi_t safi = bgp_node_safi(vty);
8488
8489 peer = peer_and_group_lookup_vty(vty, peer_str);
8490 if (!peer)
8491 return CMD_WARNING_CONFIG_FAILED;
8492
8493 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8494 PEER_FLAG_DISABLE_ADDPATH_RX);
8495 }
8496
8497 DEFUN(no_neighbor_disable_addpath_rx,
8498 no_neighbor_disable_addpath_rx_cmd,
8499 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8500 NO_STR
8501 NEIGHBOR_STR
8502 NEIGHBOR_ADDR_STR2
8503 "Do not accept additional paths\n")
8504 {
8505 char *peer_str = argv[2]->arg;
8506 struct peer *peer;
8507 afi_t afi = bgp_node_afi(vty);
8508 safi_t safi = bgp_node_safi(vty);
8509
8510 peer = peer_and_group_lookup_vty(vty, peer_str);
8511 if (!peer)
8512 return CMD_WARNING_CONFIG_FAILED;
8513
8514 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8515 PEER_FLAG_DISABLE_ADDPATH_RX);
8516 }
8517
8518 DEFUN (neighbor_addpath_tx_all_paths,
8519 neighbor_addpath_tx_all_paths_cmd,
8520 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8521 NEIGHBOR_STR
8522 NEIGHBOR_ADDR_STR2
8523 "Use addpath to advertise all paths to a neighbor\n")
8524 {
8525 int idx_peer = 1;
8526 struct peer *peer;
8527
8528 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8529 if (!peer)
8530 return CMD_WARNING_CONFIG_FAILED;
8531
8532 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8533 BGP_ADDPATH_ALL);
8534 return CMD_SUCCESS;
8535 }
8536
8537 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8538 neighbor_addpath_tx_all_paths_hidden_cmd,
8539 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8540 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8541 "Use addpath to advertise all paths to a neighbor\n")
8542
8543 DEFUN (no_neighbor_addpath_tx_all_paths,
8544 no_neighbor_addpath_tx_all_paths_cmd,
8545 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8546 NO_STR
8547 NEIGHBOR_STR
8548 NEIGHBOR_ADDR_STR2
8549 "Use addpath to advertise all paths to a neighbor\n")
8550 {
8551 int idx_peer = 2;
8552 struct peer *peer;
8553
8554 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8555 if (!peer)
8556 return CMD_WARNING_CONFIG_FAILED;
8557
8558 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8559 != BGP_ADDPATH_ALL) {
8560 vty_out(vty,
8561 "%% Peer not currently configured to transmit all paths.");
8562 return CMD_WARNING_CONFIG_FAILED;
8563 }
8564
8565 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8566 BGP_ADDPATH_NONE);
8567
8568 return CMD_SUCCESS;
8569 }
8570
8571 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8572 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8573 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8574 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8575 "Use addpath to advertise all paths to a neighbor\n")
8576
8577 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8578 neighbor_addpath_tx_bestpath_per_as_cmd,
8579 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8580 NEIGHBOR_STR
8581 NEIGHBOR_ADDR_STR2
8582 "Use addpath to advertise the bestpath per each neighboring AS\n")
8583 {
8584 int idx_peer = 1;
8585 struct peer *peer;
8586
8587 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8588 if (!peer)
8589 return CMD_WARNING_CONFIG_FAILED;
8590
8591 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8592 BGP_ADDPATH_BEST_PER_AS);
8593
8594 return CMD_SUCCESS;
8595 }
8596
8597 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8598 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8599 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8600 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8601 "Use addpath to advertise the bestpath per each neighboring AS\n")
8602
8603 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8604 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8605 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8606 NO_STR
8607 NEIGHBOR_STR
8608 NEIGHBOR_ADDR_STR2
8609 "Use addpath to advertise the bestpath per each neighboring AS\n")
8610 {
8611 int idx_peer = 2;
8612 struct peer *peer;
8613
8614 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8615 if (!peer)
8616 return CMD_WARNING_CONFIG_FAILED;
8617
8618 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8619 != BGP_ADDPATH_BEST_PER_AS) {
8620 vty_out(vty,
8621 "%% Peer not currently configured to transmit all best path per as.");
8622 return CMD_WARNING_CONFIG_FAILED;
8623 }
8624
8625 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8626 BGP_ADDPATH_NONE);
8627
8628 return CMD_SUCCESS;
8629 }
8630
8631 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8632 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8633 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8634 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8635 "Use addpath to advertise the bestpath per each neighboring AS\n")
8636
8637 DEFPY(
8638 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8639 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8640 NEIGHBOR_STR
8641 NEIGHBOR_ADDR_STR2
8642 "Detect AS loops before sending to neighbor\n")
8643 {
8644 struct peer *peer;
8645
8646 peer = peer_and_group_lookup_vty(vty, neighbor);
8647 if (!peer)
8648 return CMD_WARNING_CONFIG_FAILED;
8649
8650 peer->as_path_loop_detection = true;
8651
8652 return CMD_SUCCESS;
8653 }
8654
8655 DEFPY(
8656 no_neighbor_aspath_loop_detection,
8657 no_neighbor_aspath_loop_detection_cmd,
8658 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8659 NO_STR
8660 NEIGHBOR_STR
8661 NEIGHBOR_ADDR_STR2
8662 "Detect AS loops before sending to neighbor\n")
8663 {
8664 struct peer *peer;
8665
8666 peer = peer_and_group_lookup_vty(vty, neighbor);
8667 if (!peer)
8668 return CMD_WARNING_CONFIG_FAILED;
8669
8670 peer->as_path_loop_detection = false;
8671
8672 return CMD_SUCCESS;
8673 }
8674
8675 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8676 struct ecommunity **list, bool is_rt6)
8677 {
8678 struct ecommunity *ecom = NULL;
8679 struct ecommunity *ecomadd;
8680
8681 for (; argc; --argc, ++argv) {
8682 if (is_rt6)
8683 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8684 ECOMMUNITY_ROUTE_TARGET,
8685 0);
8686 else
8687 ecomadd = ecommunity_str2com(argv[0]->arg,
8688 ECOMMUNITY_ROUTE_TARGET,
8689 0);
8690 if (!ecomadd) {
8691 vty_out(vty, "Malformed community-list value\n");
8692 if (ecom)
8693 ecommunity_free(&ecom);
8694 return CMD_WARNING_CONFIG_FAILED;
8695 }
8696
8697 if (ecom) {
8698 ecommunity_merge(ecom, ecomadd);
8699 ecommunity_free(&ecomadd);
8700 } else {
8701 ecom = ecomadd;
8702 }
8703 }
8704
8705 if (*list) {
8706 ecommunity_free(&*list);
8707 }
8708 *list = ecom;
8709
8710 return CMD_SUCCESS;
8711 }
8712
8713 /*
8714 * v2vimport is true if we are handling a `import vrf ...` command
8715 */
8716 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8717 {
8718 afi_t afi;
8719
8720 switch (vty->node) {
8721 case BGP_IPV4_NODE:
8722 afi = AFI_IP;
8723 break;
8724 case BGP_IPV6_NODE:
8725 afi = AFI_IP6;
8726 break;
8727 default:
8728 vty_out(vty,
8729 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8730 return AFI_MAX;
8731 }
8732
8733 if (!v2vimport) {
8734 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8735 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8736 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8737 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8738 vty_out(vty,
8739 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8740 return AFI_MAX;
8741 }
8742 } else {
8743 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8744 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8745 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8746 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8747 vty_out(vty,
8748 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8749 return AFI_MAX;
8750 }
8751 }
8752 return afi;
8753 }
8754
8755 DEFPY (af_rd_vpn_export,
8756 af_rd_vpn_export_cmd,
8757 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8758 NO_STR
8759 "Specify route distinguisher\n"
8760 "Between current address-family and vpn\n"
8761 "For routes leaked from current address-family to vpn\n"
8762 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8763 {
8764 VTY_DECLVAR_CONTEXT(bgp, bgp);
8765 struct prefix_rd prd;
8766 int ret;
8767 afi_t afi;
8768 int idx = 0;
8769 bool yes = true;
8770
8771 if (argv_find(argv, argc, "no", &idx))
8772 yes = false;
8773
8774 if (yes) {
8775 ret = str2prefix_rd(rd_str, &prd);
8776 if (!ret) {
8777 vty_out(vty, "%% Malformed rd\n");
8778 return CMD_WARNING_CONFIG_FAILED;
8779 }
8780 }
8781
8782 afi = vpn_policy_getafi(vty, bgp, false);
8783 if (afi == AFI_MAX)
8784 return CMD_WARNING_CONFIG_FAILED;
8785
8786 /*
8787 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8788 */
8789 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8790 bgp_get_default(), bgp);
8791
8792 if (yes) {
8793 bgp->vpn_policy[afi].tovpn_rd = prd;
8794 SET_FLAG(bgp->vpn_policy[afi].flags,
8795 BGP_VPN_POLICY_TOVPN_RD_SET);
8796 } else {
8797 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8798 BGP_VPN_POLICY_TOVPN_RD_SET);
8799 }
8800
8801 /* post-change: re-export vpn routes */
8802 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8803 bgp_get_default(), bgp);
8804
8805 return CMD_SUCCESS;
8806 }
8807
8808 ALIAS (af_rd_vpn_export,
8809 af_no_rd_vpn_export_cmd,
8810 "no rd vpn export",
8811 NO_STR
8812 "Specify route distinguisher\n"
8813 "Between current address-family and vpn\n"
8814 "For routes leaked from current address-family to vpn\n")
8815
8816 DEFPY (af_label_vpn_export,
8817 af_label_vpn_export_cmd,
8818 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8819 NO_STR
8820 "label value for VRF\n"
8821 "Between current address-family and vpn\n"
8822 "For routes leaked from current address-family to vpn\n"
8823 "Label Value <0-1048575>\n"
8824 "Automatically assign a label\n")
8825 {
8826 VTY_DECLVAR_CONTEXT(bgp, bgp);
8827 mpls_label_t label = MPLS_LABEL_NONE;
8828 afi_t afi;
8829 int idx = 0;
8830 bool yes = true;
8831
8832 if (argv_find(argv, argc, "no", &idx))
8833 yes = false;
8834
8835 /* If "no ...", squash trailing parameter */
8836 if (!yes)
8837 label_auto = NULL;
8838
8839 if (yes) {
8840 if (!label_auto)
8841 label = label_val; /* parser should force unsigned */
8842 }
8843
8844 afi = vpn_policy_getafi(vty, bgp, false);
8845 if (afi == AFI_MAX)
8846 return CMD_WARNING_CONFIG_FAILED;
8847
8848
8849 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8850 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8851 /* no change */
8852 return CMD_SUCCESS;
8853
8854 /*
8855 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8856 */
8857 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8858 bgp_get_default(), bgp);
8859
8860 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8861 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8862
8863 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8864
8865 /*
8866 * label has previously been automatically
8867 * assigned by labelpool: release it
8868 *
8869 * NB if tovpn_label == MPLS_LABEL_NONE it
8870 * means the automatic assignment is in flight
8871 * and therefore the labelpool callback must
8872 * detect that the auto label is not needed.
8873 */
8874
8875 bgp_lp_release(LP_TYPE_VRF,
8876 &bgp->vpn_policy[afi],
8877 bgp->vpn_policy[afi].tovpn_label);
8878 }
8879 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8880 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8881 }
8882
8883 bgp->vpn_policy[afi].tovpn_label = label;
8884 if (label_auto) {
8885 SET_FLAG(bgp->vpn_policy[afi].flags,
8886 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8887 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8888 vpn_leak_label_callback);
8889 }
8890
8891 /* post-change: re-export vpn routes */
8892 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8893 bgp_get_default(), bgp);
8894
8895 hook_call(bgp_snmp_update_last_changed, bgp);
8896 return CMD_SUCCESS;
8897 }
8898
8899 DEFPY (af_sid_vpn_export,
8900 af_sid_vpn_export_cmd,
8901 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
8902 NO_STR
8903 "sid value for VRF\n"
8904 "Between current address-family and vpn\n"
8905 "For routes leaked from current address-family to vpn\n"
8906 "Sid allocation index\n"
8907 "Automatically assign a label\n")
8908 {
8909 VTY_DECLVAR_CONTEXT(bgp, bgp);
8910 afi_t afi;
8911 int debug = 0;
8912 int idx = 0;
8913 bool yes = true;
8914
8915 if (argv_find(argv, argc, "no", &idx))
8916 yes = false;
8917 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8918 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8919
8920 afi = vpn_policy_getafi(vty, bgp, false);
8921 if (afi == AFI_MAX)
8922 return CMD_WARNING_CONFIG_FAILED;
8923
8924 if (!yes) {
8925 /* implement me */
8926 vty_out(vty, "It's not implemented\n");
8927 return CMD_WARNING_CONFIG_FAILED;
8928 }
8929
8930 /* skip when it's already configured */
8931 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8932 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8933 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8934 return CMD_SUCCESS;
8935
8936 /*
8937 * mode change between sid_idx and sid_auto isn't supported.
8938 * user must negate sid vpn export when they want to change the mode
8939 */
8940 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8941 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8942 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8943 vty_out(vty, "it's already configured as %s.\n",
8944 sid_auto ? "auto-mode" : "idx-mode");
8945 return CMD_WARNING_CONFIG_FAILED;
8946 }
8947
8948 /* pre-change */
8949 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8950 bgp_get_default(), bgp);
8951
8952 if (sid_auto) {
8953 /* SID allocation auto-mode */
8954 if (debug)
8955 zlog_debug("%s: auto sid alloc.", __func__);
8956 SET_FLAG(bgp->vpn_policy[afi].flags,
8957 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8958 } else {
8959 /* SID allocation index-mode */
8960 if (debug)
8961 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8962 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8963 }
8964
8965 /* post-change */
8966 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8967 bgp_get_default(), bgp);
8968 return CMD_SUCCESS;
8969 }
8970
8971 ALIAS (af_label_vpn_export,
8972 af_no_label_vpn_export_cmd,
8973 "no label vpn export",
8974 NO_STR
8975 "label value for VRF\n"
8976 "Between current address-family and vpn\n"
8977 "For routes leaked from current address-family to vpn\n")
8978
8979 DEFPY (af_nexthop_vpn_export,
8980 af_nexthop_vpn_export_cmd,
8981 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8982 NO_STR
8983 "Specify next hop to use for VRF advertised prefixes\n"
8984 "Between current address-family and vpn\n"
8985 "For routes leaked from current address-family to vpn\n"
8986 "IPv4 prefix\n"
8987 "IPv6 prefix\n")
8988 {
8989 VTY_DECLVAR_CONTEXT(bgp, bgp);
8990 afi_t afi;
8991 struct prefix p;
8992
8993 if (!no) {
8994 if (!nexthop_su) {
8995 vty_out(vty, "%% Nexthop required\n");
8996 return CMD_WARNING_CONFIG_FAILED;
8997 }
8998 if (!sockunion2hostprefix(nexthop_su, &p))
8999 return CMD_WARNING_CONFIG_FAILED;
9000 }
9001
9002 afi = vpn_policy_getafi(vty, bgp, false);
9003 if (afi == AFI_MAX)
9004 return CMD_WARNING_CONFIG_FAILED;
9005
9006 /*
9007 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9008 */
9009 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9010 bgp_get_default(), bgp);
9011
9012 if (!no) {
9013 bgp->vpn_policy[afi].tovpn_nexthop = p;
9014 SET_FLAG(bgp->vpn_policy[afi].flags,
9015 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9016 } else {
9017 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9018 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9019 }
9020
9021 /* post-change: re-export vpn routes */
9022 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9023 bgp_get_default(), bgp);
9024
9025 return CMD_SUCCESS;
9026 }
9027
9028 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9029 {
9030 if (!strcmp(dstr, "import")) {
9031 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9032 } else if (!strcmp(dstr, "export")) {
9033 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9034 } else if (!strcmp(dstr, "both")) {
9035 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9036 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9037 } else {
9038 vty_out(vty, "%% direction parse error\n");
9039 return CMD_WARNING_CONFIG_FAILED;
9040 }
9041 return CMD_SUCCESS;
9042 }
9043
9044 DEFPY (af_rt_vpn_imexport,
9045 af_rt_vpn_imexport_cmd,
9046 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9047 NO_STR
9048 "Specify route target list\n"
9049 "Specify route target list\n"
9050 "Between current address-family and vpn\n"
9051 "For routes leaked from vpn to current address-family: match any\n"
9052 "For routes leaked from current address-family to vpn: set\n"
9053 "both import: match any and export: set\n"
9054 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9055 {
9056 VTY_DECLVAR_CONTEXT(bgp, bgp);
9057 int ret;
9058 struct ecommunity *ecom = NULL;
9059 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9060 enum vpn_policy_direction dir;
9061 afi_t afi;
9062 int idx = 0;
9063 bool yes = true;
9064
9065 if (argv_find(argv, argc, "no", &idx))
9066 yes = false;
9067
9068 afi = vpn_policy_getafi(vty, bgp, false);
9069 if (afi == AFI_MAX)
9070 return CMD_WARNING_CONFIG_FAILED;
9071
9072 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9073 if (ret != CMD_SUCCESS)
9074 return ret;
9075
9076 if (yes) {
9077 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9078 vty_out(vty, "%% Missing RTLIST\n");
9079 return CMD_WARNING_CONFIG_FAILED;
9080 }
9081 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9082 if (ret != CMD_SUCCESS) {
9083 return ret;
9084 }
9085 }
9086
9087 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9088 if (!dodir[dir])
9089 continue;
9090
9091 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9092
9093 if (yes) {
9094 if (bgp->vpn_policy[afi].rtlist[dir])
9095 ecommunity_free(
9096 &bgp->vpn_policy[afi].rtlist[dir]);
9097 bgp->vpn_policy[afi].rtlist[dir] =
9098 ecommunity_dup(ecom);
9099 } else {
9100 if (bgp->vpn_policy[afi].rtlist[dir])
9101 ecommunity_free(
9102 &bgp->vpn_policy[afi].rtlist[dir]);
9103 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9104 }
9105
9106 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9107 }
9108
9109 if (ecom)
9110 ecommunity_free(&ecom);
9111
9112 return CMD_SUCCESS;
9113 }
9114
9115 ALIAS (af_rt_vpn_imexport,
9116 af_no_rt_vpn_imexport_cmd,
9117 "no <rt|route-target> vpn <import|export|both>$direction_str",
9118 NO_STR
9119 "Specify route target list\n"
9120 "Specify route target list\n"
9121 "Between current address-family and vpn\n"
9122 "For routes leaked from vpn to current address-family\n"
9123 "For routes leaked from current address-family to vpn\n"
9124 "both import and export\n")
9125
9126 DEFPY (af_route_map_vpn_imexport,
9127 af_route_map_vpn_imexport_cmd,
9128 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9129 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9130 NO_STR
9131 "Specify route map\n"
9132 "Between current address-family and vpn\n"
9133 "For routes leaked from vpn to current address-family\n"
9134 "For routes leaked from current address-family to vpn\n"
9135 "name of route-map\n")
9136 {
9137 VTY_DECLVAR_CONTEXT(bgp, bgp);
9138 int ret;
9139 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9140 enum vpn_policy_direction dir;
9141 afi_t afi;
9142 int idx = 0;
9143 bool yes = true;
9144
9145 if (argv_find(argv, argc, "no", &idx))
9146 yes = false;
9147
9148 afi = vpn_policy_getafi(vty, bgp, false);
9149 if (afi == AFI_MAX)
9150 return CMD_WARNING_CONFIG_FAILED;
9151
9152 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9153 if (ret != CMD_SUCCESS)
9154 return ret;
9155
9156 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9157 if (!dodir[dir])
9158 continue;
9159
9160 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9161
9162 if (yes) {
9163 if (bgp->vpn_policy[afi].rmap_name[dir])
9164 XFREE(MTYPE_ROUTE_MAP_NAME,
9165 bgp->vpn_policy[afi].rmap_name[dir]);
9166 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9167 MTYPE_ROUTE_MAP_NAME, rmap_str);
9168 bgp->vpn_policy[afi].rmap[dir] =
9169 route_map_lookup_warn_noexist(vty, rmap_str);
9170 if (!bgp->vpn_policy[afi].rmap[dir])
9171 return CMD_SUCCESS;
9172 } else {
9173 if (bgp->vpn_policy[afi].rmap_name[dir])
9174 XFREE(MTYPE_ROUTE_MAP_NAME,
9175 bgp->vpn_policy[afi].rmap_name[dir]);
9176 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9177 bgp->vpn_policy[afi].rmap[dir] = NULL;
9178 }
9179
9180 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9181 }
9182
9183 return CMD_SUCCESS;
9184 }
9185
9186 ALIAS (af_route_map_vpn_imexport,
9187 af_no_route_map_vpn_imexport_cmd,
9188 "no route-map vpn <import|export>$direction_str",
9189 NO_STR
9190 "Specify route map\n"
9191 "Between current address-family and vpn\n"
9192 "For routes leaked from vpn to current address-family\n"
9193 "For routes leaked from current address-family to vpn\n")
9194
9195 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9196 "import vrf route-map RMAP$rmap_str",
9197 "Import routes from another VRF\n"
9198 "Vrf routes being filtered\n"
9199 "Specify route map\n"
9200 "name of route-map\n")
9201 {
9202 VTY_DECLVAR_CONTEXT(bgp, bgp);
9203 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9204 afi_t afi;
9205 struct bgp *bgp_default;
9206
9207 afi = vpn_policy_getafi(vty, bgp, true);
9208 if (afi == AFI_MAX)
9209 return CMD_WARNING_CONFIG_FAILED;
9210
9211 bgp_default = bgp_get_default();
9212 if (!bgp_default) {
9213 int32_t ret;
9214 as_t as = bgp->as;
9215
9216 /* Auto-create assuming the same AS */
9217 ret = bgp_get_vty(&bgp_default, &as, NULL,
9218 BGP_INSTANCE_TYPE_DEFAULT);
9219
9220 if (ret) {
9221 vty_out(vty,
9222 "VRF default is not configured as a bgp instance\n");
9223 return CMD_WARNING;
9224 }
9225 }
9226
9227 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9228
9229 if (bgp->vpn_policy[afi].rmap_name[dir])
9230 XFREE(MTYPE_ROUTE_MAP_NAME,
9231 bgp->vpn_policy[afi].rmap_name[dir]);
9232 bgp->vpn_policy[afi].rmap_name[dir] =
9233 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9234 bgp->vpn_policy[afi].rmap[dir] =
9235 route_map_lookup_warn_noexist(vty, rmap_str);
9236 if (!bgp->vpn_policy[afi].rmap[dir])
9237 return CMD_SUCCESS;
9238
9239 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9240 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9241
9242 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9243
9244 return CMD_SUCCESS;
9245 }
9246
9247 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9248 "no import vrf route-map [RMAP$rmap_str]",
9249 NO_STR
9250 "Import routes from another VRF\n"
9251 "Vrf routes being filtered\n"
9252 "Specify route map\n"
9253 "name of route-map\n")
9254 {
9255 VTY_DECLVAR_CONTEXT(bgp, bgp);
9256 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9257 afi_t afi;
9258
9259 afi = vpn_policy_getafi(vty, bgp, true);
9260 if (afi == AFI_MAX)
9261 return CMD_WARNING_CONFIG_FAILED;
9262
9263 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9264
9265 if (bgp->vpn_policy[afi].rmap_name[dir])
9266 XFREE(MTYPE_ROUTE_MAP_NAME,
9267 bgp->vpn_policy[afi].rmap_name[dir]);
9268 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9269 bgp->vpn_policy[afi].rmap[dir] = NULL;
9270
9271 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9272 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9273 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9274
9275 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9276
9277 return CMD_SUCCESS;
9278 }
9279
9280 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9281 "[no] import vrf VIEWVRFNAME$import_name",
9282 NO_STR
9283 "Import routes from another VRF\n"
9284 "VRF to import from\n"
9285 "The name of the VRF\n")
9286 {
9287 VTY_DECLVAR_CONTEXT(bgp, bgp);
9288 struct listnode *node;
9289 struct bgp *vrf_bgp, *bgp_default;
9290 int32_t ret = 0;
9291 as_t as = bgp->as;
9292 bool remove = false;
9293 int32_t idx = 0;
9294 char *vname;
9295 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9296 safi_t safi;
9297 afi_t afi;
9298
9299 if (import_name == NULL) {
9300 vty_out(vty, "%% Missing import name\n");
9301 return CMD_WARNING;
9302 }
9303
9304 if (strcmp(import_name, "route-map") == 0) {
9305 vty_out(vty, "%% Must include route-map name\n");
9306 return CMD_WARNING;
9307 }
9308
9309 if (argv_find(argv, argc, "no", &idx))
9310 remove = true;
9311
9312 afi = vpn_policy_getafi(vty, bgp, true);
9313 if (afi == AFI_MAX)
9314 return CMD_WARNING_CONFIG_FAILED;
9315
9316 safi = bgp_node_safi(vty);
9317
9318 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9319 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9320 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9321 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9322 remove ? "unimport" : "import", import_name);
9323 return CMD_WARNING;
9324 }
9325
9326 bgp_default = bgp_get_default();
9327 if (!bgp_default) {
9328 /* Auto-create assuming the same AS */
9329 ret = bgp_get_vty(&bgp_default, &as, NULL,
9330 BGP_INSTANCE_TYPE_DEFAULT);
9331
9332 if (ret) {
9333 vty_out(vty,
9334 "VRF default is not configured as a bgp instance\n");
9335 return CMD_WARNING;
9336 }
9337 }
9338
9339 vrf_bgp = bgp_lookup_by_name(import_name);
9340 if (!vrf_bgp) {
9341 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9342 vrf_bgp = bgp_default;
9343 else
9344 /* Auto-create assuming the same AS */
9345 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9346
9347 if (ret) {
9348 vty_out(vty,
9349 "VRF %s is not configured as a bgp instance\n",
9350 import_name);
9351 return CMD_WARNING;
9352 }
9353 }
9354
9355 if (remove) {
9356 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9357 } else {
9358 /* Already importing from "import_vrf"? */
9359 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9360 vname)) {
9361 if (strcmp(vname, import_name) == 0)
9362 return CMD_WARNING;
9363 }
9364
9365 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9366 }
9367
9368 return CMD_SUCCESS;
9369 }
9370
9371 /* This command is valid only in a bgp vrf instance or the default instance */
9372 DEFPY (bgp_imexport_vpn,
9373 bgp_imexport_vpn_cmd,
9374 "[no] <import|export>$direction_str vpn",
9375 NO_STR
9376 "Import routes to this address-family\n"
9377 "Export routes from this address-family\n"
9378 "to/from default instance VPN RIB\n")
9379 {
9380 VTY_DECLVAR_CONTEXT(bgp, bgp);
9381 int previous_state;
9382 afi_t afi;
9383 safi_t safi;
9384 int idx = 0;
9385 bool yes = true;
9386 int flag;
9387 enum vpn_policy_direction dir;
9388
9389 if (argv_find(argv, argc, "no", &idx))
9390 yes = false;
9391
9392 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9393 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9394
9395 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9396 return CMD_WARNING_CONFIG_FAILED;
9397 }
9398
9399 afi = bgp_node_afi(vty);
9400 safi = bgp_node_safi(vty);
9401 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9402 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9403 return CMD_WARNING_CONFIG_FAILED;
9404 }
9405
9406 if (!strcmp(direction_str, "import")) {
9407 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9408 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9409 } else if (!strcmp(direction_str, "export")) {
9410 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9411 dir = BGP_VPN_POLICY_DIR_TOVPN;
9412 } else {
9413 vty_out(vty, "%% unknown direction %s\n", direction_str);
9414 return CMD_WARNING_CONFIG_FAILED;
9415 }
9416
9417 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9418
9419 if (yes) {
9420 SET_FLAG(bgp->af_flags[afi][safi], flag);
9421 if (!previous_state) {
9422 /* trigger export current vrf */
9423 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9424 }
9425 } else {
9426 if (previous_state) {
9427 /* trigger un-export current vrf */
9428 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9429 }
9430 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9431 }
9432
9433 hook_call(bgp_snmp_init_stats, bgp);
9434
9435 return CMD_SUCCESS;
9436 }
9437
9438 DEFPY (af_routetarget_import,
9439 af_routetarget_import_cmd,
9440 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9441 NO_STR
9442 "Specify route target list\n"
9443 "Specify route target list\n"
9444 "Specify route target list\n"
9445 "Specify route target list\n"
9446 "Flow-spec redirect type route target\n"
9447 "Import routes to this address-family\n"
9448 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9449 {
9450 VTY_DECLVAR_CONTEXT(bgp, bgp);
9451 int ret;
9452 struct ecommunity *ecom = NULL;
9453 afi_t afi;
9454 int idx = 0, idx_unused = 0;
9455 bool yes = true;
9456 bool rt6 = false;
9457
9458 if (argv_find(argv, argc, "no", &idx))
9459 yes = false;
9460
9461 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9462 argv_find(argv, argc, "route-target6", &idx_unused))
9463 rt6 = true;
9464
9465 afi = vpn_policy_getafi(vty, bgp, false);
9466 if (afi == AFI_MAX)
9467 return CMD_WARNING_CONFIG_FAILED;
9468
9469 if (rt6 && afi != AFI_IP6)
9470 return CMD_WARNING_CONFIG_FAILED;
9471
9472 if (yes) {
9473 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9474 vty_out(vty, "%% Missing RTLIST\n");
9475 return CMD_WARNING_CONFIG_FAILED;
9476 }
9477 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9478 if (ret != CMD_SUCCESS)
9479 return ret;
9480 }
9481
9482 if (yes) {
9483 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9484 ecommunity_free(&bgp->vpn_policy[afi]
9485 .import_redirect_rtlist);
9486 bgp->vpn_policy[afi].import_redirect_rtlist =
9487 ecommunity_dup(ecom);
9488 } else {
9489 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9490 ecommunity_free(&bgp->vpn_policy[afi]
9491 .import_redirect_rtlist);
9492 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9493 }
9494
9495 if (ecom)
9496 ecommunity_free(&ecom);
9497
9498 return CMD_SUCCESS;
9499 }
9500
9501 DEFUN_NOSH (address_family_ipv4_safi,
9502 address_family_ipv4_safi_cmd,
9503 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9504 "Enter Address Family command mode\n"
9505 BGP_AF_STR
9506 BGP_SAFI_WITH_LABEL_HELP_STR)
9507 {
9508
9509 if (argc == 3) {
9510 VTY_DECLVAR_CONTEXT(bgp, bgp);
9511 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9512 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9513 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9514 && safi != SAFI_EVPN) {
9515 vty_out(vty,
9516 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9517 return CMD_WARNING_CONFIG_FAILED;
9518 }
9519 vty->node = bgp_node_type(AFI_IP, safi);
9520 } else
9521 vty->node = BGP_IPV4_NODE;
9522
9523 return CMD_SUCCESS;
9524 }
9525
9526 DEFUN_NOSH (address_family_ipv6_safi,
9527 address_family_ipv6_safi_cmd,
9528 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9529 "Enter Address Family command mode\n"
9530 BGP_AF_STR
9531 BGP_SAFI_WITH_LABEL_HELP_STR)
9532 {
9533 if (argc == 3) {
9534 VTY_DECLVAR_CONTEXT(bgp, bgp);
9535 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9536 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9537 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9538 && safi != SAFI_EVPN) {
9539 vty_out(vty,
9540 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9541 return CMD_WARNING_CONFIG_FAILED;
9542 }
9543 vty->node = bgp_node_type(AFI_IP6, safi);
9544 } else
9545 vty->node = BGP_IPV6_NODE;
9546
9547 return CMD_SUCCESS;
9548 }
9549
9550 #ifdef KEEP_OLD_VPN_COMMANDS
9551 DEFUN_NOSH (address_family_vpnv4,
9552 address_family_vpnv4_cmd,
9553 "address-family vpnv4 [unicast]",
9554 "Enter Address Family command mode\n"
9555 BGP_AF_STR
9556 BGP_AF_MODIFIER_STR)
9557 {
9558 vty->node = BGP_VPNV4_NODE;
9559 return CMD_SUCCESS;
9560 }
9561
9562 DEFUN_NOSH (address_family_vpnv6,
9563 address_family_vpnv6_cmd,
9564 "address-family vpnv6 [unicast]",
9565 "Enter Address Family command mode\n"
9566 BGP_AF_STR
9567 BGP_AF_MODIFIER_STR)
9568 {
9569 vty->node = BGP_VPNV6_NODE;
9570 return CMD_SUCCESS;
9571 }
9572 #endif /* KEEP_OLD_VPN_COMMANDS */
9573
9574 DEFUN_NOSH (address_family_evpn,
9575 address_family_evpn_cmd,
9576 "address-family l2vpn evpn",
9577 "Enter Address Family command mode\n"
9578 BGP_AF_STR
9579 BGP_AF_MODIFIER_STR)
9580 {
9581 VTY_DECLVAR_CONTEXT(bgp, bgp);
9582 vty->node = BGP_EVPN_NODE;
9583 return CMD_SUCCESS;
9584 }
9585
9586 DEFUN_NOSH (bgp_segment_routing_srv6,
9587 bgp_segment_routing_srv6_cmd,
9588 "segment-routing srv6",
9589 "Segment-Routing configuration\n"
9590 "Segment-Routing SRv6 configuration\n")
9591 {
9592 VTY_DECLVAR_CONTEXT(bgp, bgp);
9593 bgp->srv6_enabled = true;
9594 vty->node = BGP_SRV6_NODE;
9595 return CMD_SUCCESS;
9596 }
9597
9598 DEFUN (no_bgp_segment_routing_srv6,
9599 no_bgp_segment_routing_srv6_cmd,
9600 "no segment-routing srv6",
9601 NO_STR
9602 "Segment-Routing configuration\n"
9603 "Segment-Routing SRv6 configuration\n")
9604 {
9605 VTY_DECLVAR_CONTEXT(bgp, bgp);
9606
9607 if (strlen(bgp->srv6_locator_name) > 0)
9608 if (bgp_srv6_locator_unset(bgp) < 0)
9609 return CMD_WARNING_CONFIG_FAILED;
9610
9611 bgp->srv6_enabled = false;
9612 return CMD_SUCCESS;
9613 }
9614
9615 DEFPY (bgp_srv6_locator,
9616 bgp_srv6_locator_cmd,
9617 "locator NAME$name",
9618 "Specify SRv6 locator\n"
9619 "Specify SRv6 locator\n")
9620 {
9621 VTY_DECLVAR_CONTEXT(bgp, bgp);
9622 int ret;
9623
9624 if (strlen(bgp->srv6_locator_name) > 0
9625 && strcmp(name, bgp->srv6_locator_name) != 0) {
9626 vty_out(vty, "srv6 locator is already configured\n");
9627 return CMD_WARNING_CONFIG_FAILED;
9628 }
9629
9630 snprintf(bgp->srv6_locator_name,
9631 sizeof(bgp->srv6_locator_name), "%s", name);
9632
9633 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9634 if (ret < 0)
9635 return CMD_WARNING_CONFIG_FAILED;
9636
9637 return CMD_SUCCESS;
9638 }
9639
9640 DEFPY (no_bgp_srv6_locator,
9641 no_bgp_srv6_locator_cmd,
9642 "no locator NAME$name",
9643 NO_STR
9644 "Specify SRv6 locator\n"
9645 "Specify SRv6 locator\n")
9646 {
9647 VTY_DECLVAR_CONTEXT(bgp, bgp);
9648
9649 /* when locator isn't configured, do nothing */
9650 if (strlen(bgp->srv6_locator_name) < 1)
9651 return CMD_SUCCESS;
9652
9653 /* name validation */
9654 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9655 vty_out(vty, "%% No srv6 locator is configured\n");
9656 return CMD_WARNING_CONFIG_FAILED;
9657 }
9658
9659 /* unset locator */
9660 if (bgp_srv6_locator_unset(bgp) < 0)
9661 return CMD_WARNING_CONFIG_FAILED;
9662
9663 return CMD_SUCCESS;
9664 }
9665
9666 DEFPY (show_bgp_srv6,
9667 show_bgp_srv6_cmd,
9668 "show bgp segment-routing srv6",
9669 SHOW_STR
9670 BGP_STR
9671 "BGP Segment Routing\n"
9672 "BGP Segment Routing SRv6\n")
9673 {
9674 struct bgp *bgp;
9675 struct listnode *node;
9676 struct srv6_locator_chunk *chunk;
9677 struct bgp_srv6_function *func;
9678 char buf[256];
9679
9680 bgp = bgp_get_default();
9681 if (!bgp)
9682 return CMD_SUCCESS;
9683
9684 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9685 vty_out(vty, "locator_chunks:\n");
9686 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk))
9687 vty_out(vty, "- %pFX\n", &chunk->prefix);
9688
9689 vty_out(vty, "functions:\n");
9690 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9691 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9692 vty_out(vty, "- sid: %s\n", buf);
9693 vty_out(vty, " locator: %s\n", func->locator_name);
9694 }
9695
9696 vty_out(vty, "bgps:\n");
9697 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9698 vty_out(vty, "- name: %s\n",
9699 bgp->name ? bgp->name : "default");
9700
9701 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9702 bgp->vpn_policy[AFI_IP].tovpn_sid);
9703 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9704 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9705 }
9706
9707 return CMD_SUCCESS;
9708 }
9709
9710 DEFUN_NOSH (exit_address_family,
9711 exit_address_family_cmd,
9712 "exit-address-family",
9713 "Exit from Address Family configuration mode\n")
9714 {
9715 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9716 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9717 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9718 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9719 || vty->node == BGP_EVPN_NODE
9720 || vty->node == BGP_FLOWSPECV4_NODE
9721 || vty->node == BGP_FLOWSPECV6_NODE)
9722 vty->node = BGP_NODE;
9723 return CMD_SUCCESS;
9724 }
9725
9726 /* Recalculate bestpath and re-advertise a prefix */
9727 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9728 const char *ip_str, afi_t afi, safi_t safi,
9729 struct prefix_rd *prd)
9730 {
9731 int ret;
9732 struct prefix match;
9733 struct bgp_dest *dest;
9734 struct bgp_dest *rm;
9735 struct bgp *bgp;
9736 struct bgp_table *table;
9737 struct bgp_table *rib;
9738
9739 /* BGP structure lookup. */
9740 if (view_name) {
9741 bgp = bgp_lookup_by_name(view_name);
9742 if (bgp == NULL) {
9743 vty_out(vty, "%% Can't find BGP instance %s\n",
9744 view_name);
9745 return CMD_WARNING;
9746 }
9747 } else {
9748 bgp = bgp_get_default();
9749 if (bgp == NULL) {
9750 vty_out(vty, "%% No BGP process is configured\n");
9751 return CMD_WARNING;
9752 }
9753 }
9754
9755 /* Check IP address argument. */
9756 ret = str2prefix(ip_str, &match);
9757 if (!ret) {
9758 vty_out(vty, "%% address is malformed\n");
9759 return CMD_WARNING;
9760 }
9761
9762 match.family = afi2family(afi);
9763 rib = bgp->rib[afi][safi];
9764
9765 if (safi == SAFI_MPLS_VPN) {
9766 for (dest = bgp_table_top(rib); dest;
9767 dest = bgp_route_next(dest)) {
9768 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9769
9770 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9771 continue;
9772
9773 table = bgp_dest_get_bgp_table_info(dest);
9774 if (table == NULL)
9775 continue;
9776
9777 rm = bgp_node_match(table, &match);
9778 if (rm != NULL) {
9779 const struct prefix *rm_p =
9780 bgp_dest_get_prefix(rm);
9781
9782 if (rm_p->prefixlen == match.prefixlen) {
9783 SET_FLAG(rm->flags,
9784 BGP_NODE_USER_CLEAR);
9785 bgp_process(bgp, rm, afi, safi);
9786 }
9787 bgp_dest_unlock_node(rm);
9788 }
9789 }
9790 } else {
9791 dest = bgp_node_match(rib, &match);
9792 if (dest != NULL) {
9793 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9794
9795 if (dest_p->prefixlen == match.prefixlen) {
9796 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9797 bgp_process(bgp, dest, afi, safi);
9798 }
9799 bgp_dest_unlock_node(dest);
9800 }
9801 }
9802
9803 return CMD_SUCCESS;
9804 }
9805
9806 /* one clear bgp command to rule them all */
9807 DEFUN (clear_ip_bgp_all,
9808 clear_ip_bgp_all_cmd,
9809 "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>]",
9810 CLEAR_STR
9811 IP_STR
9812 BGP_STR
9813 BGP_INSTANCE_HELP_STR
9814 BGP_AFI_HELP_STR
9815 BGP_AF_STR
9816 BGP_SAFI_WITH_LABEL_HELP_STR
9817 BGP_AF_MODIFIER_STR
9818 "Clear all peers\n"
9819 "BGP IPv4 neighbor to clear\n"
9820 "BGP IPv6 neighbor to clear\n"
9821 "BGP neighbor on interface to clear\n"
9822 "Clear peers with the AS number\n"
9823 "Clear all external peers\n"
9824 "Clear all members of peer-group\n"
9825 "BGP peer-group name\n"
9826 BGP_SOFT_STR
9827 BGP_SOFT_IN_STR
9828 BGP_SOFT_OUT_STR
9829 BGP_SOFT_IN_STR
9830 "Push out prefix-list ORF and do inbound soft reconfig\n"
9831 BGP_SOFT_OUT_STR
9832 "Reset message statistics\n")
9833 {
9834 char *vrf = NULL;
9835
9836 afi_t afi = AFI_UNSPEC;
9837 safi_t safi = SAFI_UNSPEC;
9838 enum clear_sort clr_sort = clear_peer;
9839 enum bgp_clear_type clr_type;
9840 char *clr_arg = NULL;
9841
9842 int idx = 0;
9843
9844 /* clear [ip] bgp */
9845 if (argv_find(argv, argc, "ip", &idx))
9846 afi = AFI_IP;
9847
9848 /* [<vrf> VIEWVRFNAME] */
9849 if (argv_find(argv, argc, "vrf", &idx)) {
9850 vrf = argv[idx + 1]->arg;
9851 idx += 2;
9852 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9853 vrf = NULL;
9854 } else if (argv_find(argv, argc, "view", &idx)) {
9855 /* [<view> VIEWVRFNAME] */
9856 vrf = argv[idx + 1]->arg;
9857 idx += 2;
9858 }
9859 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9860 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9861 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9862
9863 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9864 if (argv_find(argv, argc, "*", &idx)) {
9865 clr_sort = clear_all;
9866 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9867 clr_sort = clear_peer;
9868 clr_arg = argv[idx]->arg;
9869 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9870 clr_sort = clear_peer;
9871 clr_arg = argv[idx]->arg;
9872 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9873 clr_sort = clear_group;
9874 idx++;
9875 clr_arg = argv[idx]->arg;
9876 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9877 clr_sort = clear_peer;
9878 clr_arg = argv[idx]->arg;
9879 } else if (argv_find(argv, argc, "WORD", &idx)) {
9880 clr_sort = clear_peer;
9881 clr_arg = argv[idx]->arg;
9882 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9883 clr_sort = clear_as;
9884 clr_arg = argv[idx]->arg;
9885 } else if (argv_find(argv, argc, "external", &idx)) {
9886 clr_sort = clear_external;
9887 }
9888
9889 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9890 if (argv_find(argv, argc, "soft", &idx)) {
9891 if (argv_find(argv, argc, "in", &idx)
9892 || argv_find(argv, argc, "out", &idx))
9893 clr_type = strmatch(argv[idx]->text, "in")
9894 ? BGP_CLEAR_SOFT_IN
9895 : BGP_CLEAR_SOFT_OUT;
9896 else
9897 clr_type = BGP_CLEAR_SOFT_BOTH;
9898 } else if (argv_find(argv, argc, "in", &idx)) {
9899 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9900 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9901 : BGP_CLEAR_SOFT_IN;
9902 } else if (argv_find(argv, argc, "out", &idx)) {
9903 clr_type = BGP_CLEAR_SOFT_OUT;
9904 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9905 clr_type = BGP_CLEAR_MESSAGE_STATS;
9906 } else
9907 clr_type = BGP_CLEAR_SOFT_NONE;
9908
9909 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9910 }
9911
9912 DEFUN (clear_ip_bgp_prefix,
9913 clear_ip_bgp_prefix_cmd,
9914 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9915 CLEAR_STR
9916 IP_STR
9917 BGP_STR
9918 BGP_INSTANCE_HELP_STR
9919 "Clear bestpath and re-advertise\n"
9920 "IPv4 prefix\n")
9921 {
9922 char *vrf = NULL;
9923 char *prefix = NULL;
9924
9925 int idx = 0;
9926
9927 /* [<view|vrf> VIEWVRFNAME] */
9928 if (argv_find(argv, argc, "vrf", &idx)) {
9929 vrf = argv[idx + 1]->arg;
9930 idx += 2;
9931 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9932 vrf = NULL;
9933 } else if (argv_find(argv, argc, "view", &idx)) {
9934 /* [<view> VIEWVRFNAME] */
9935 vrf = argv[idx + 1]->arg;
9936 idx += 2;
9937 }
9938
9939 prefix = argv[argc - 1]->arg;
9940
9941 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9942 }
9943
9944 DEFUN (clear_bgp_ipv6_safi_prefix,
9945 clear_bgp_ipv6_safi_prefix_cmd,
9946 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9947 CLEAR_STR
9948 IP_STR
9949 BGP_STR
9950 BGP_AF_STR
9951 BGP_SAFI_HELP_STR
9952 "Clear bestpath and re-advertise\n"
9953 "IPv6 prefix\n")
9954 {
9955 int idx_safi = 0;
9956 int idx_ipv6_prefix = 0;
9957 safi_t safi = SAFI_UNICAST;
9958 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9959 argv[idx_ipv6_prefix]->arg : NULL;
9960
9961 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9962 return bgp_clear_prefix(
9963 vty, NULL, prefix, AFI_IP6,
9964 safi, NULL);
9965 }
9966
9967 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9968 clear_bgp_instance_ipv6_safi_prefix_cmd,
9969 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9970 CLEAR_STR
9971 IP_STR
9972 BGP_STR
9973 BGP_INSTANCE_HELP_STR
9974 BGP_AF_STR
9975 BGP_SAFI_HELP_STR
9976 "Clear bestpath and re-advertise\n"
9977 "IPv6 prefix\n")
9978 {
9979 int idx_safi = 0;
9980 int idx_vrfview = 0;
9981 int idx_ipv6_prefix = 0;
9982 safi_t safi = SAFI_UNICAST;
9983 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9984 argv[idx_ipv6_prefix]->arg : NULL;
9985 char *vrfview = NULL;
9986
9987 /* [<view|vrf> VIEWVRFNAME] */
9988 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9989 vrfview = argv[idx_vrfview + 1]->arg;
9990 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9991 vrfview = NULL;
9992 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9993 /* [<view> VIEWVRFNAME] */
9994 vrfview = argv[idx_vrfview + 1]->arg;
9995 }
9996 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9997
9998 return bgp_clear_prefix(
9999 vty, vrfview, prefix,
10000 AFI_IP6, safi, NULL);
10001 }
10002
10003 DEFUN (show_bgp_views,
10004 show_bgp_views_cmd,
10005 "show [ip] bgp views",
10006 SHOW_STR
10007 IP_STR
10008 BGP_STR
10009 "Show the defined BGP views\n")
10010 {
10011 struct list *inst = bm->bgp;
10012 struct listnode *node;
10013 struct bgp *bgp;
10014
10015 vty_out(vty, "Defined BGP views:\n");
10016 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10017 /* Skip VRFs. */
10018 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10019 continue;
10020 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10021 bgp->as);
10022 }
10023
10024 return CMD_SUCCESS;
10025 }
10026
10027 DEFUN (show_bgp_vrfs,
10028 show_bgp_vrfs_cmd,
10029 "show [ip] bgp vrfs [json]",
10030 SHOW_STR
10031 IP_STR
10032 BGP_STR
10033 "Show BGP VRFs\n"
10034 JSON_STR)
10035 {
10036 char buf[ETHER_ADDR_STRLEN];
10037 struct list *inst = bm->bgp;
10038 struct listnode *node;
10039 struct bgp *bgp;
10040 bool uj = use_json(argc, argv);
10041 json_object *json = NULL;
10042 json_object *json_vrfs = NULL;
10043 int count = 0;
10044
10045 if (uj) {
10046 json = json_object_new_object();
10047 json_vrfs = json_object_new_object();
10048 }
10049
10050 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10051 const char *name, *type;
10052 struct peer *peer;
10053 struct listnode *node2, *nnode2;
10054 int peers_cfg, peers_estb;
10055 json_object *json_vrf = NULL;
10056
10057 /* Skip Views. */
10058 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10059 continue;
10060
10061 count++;
10062 if (!uj && count == 1) {
10063 vty_out(vty,
10064 "%4s %-5s %-16s %9s %10s %-37s\n",
10065 "Type", "Id", "routerId", "#PeersCfg",
10066 "#PeersEstb", "Name");
10067 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10068 "L3-VNI", "RouterMAC", "Interface");
10069 }
10070
10071 peers_cfg = peers_estb = 0;
10072 if (uj)
10073 json_vrf = json_object_new_object();
10074
10075
10076 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10077 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10078 continue;
10079 peers_cfg++;
10080 if (peer_established(peer))
10081 peers_estb++;
10082 }
10083
10084 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10085 name = VRF_DEFAULT_NAME;
10086 type = "DFLT";
10087 } else {
10088 name = bgp->name;
10089 type = "VRF";
10090 }
10091
10092
10093 if (uj) {
10094 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10095 ? -1
10096 : (int64_t)bgp->vrf_id;
10097 char buf[BUFSIZ] = {0};
10098
10099 json_object_string_add(json_vrf, "type", type);
10100 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10101 json_object_string_addf(json_vrf, "routerId", "%pI4",
10102 &bgp->router_id);
10103 json_object_int_add(json_vrf, "numConfiguredPeers",
10104 peers_cfg);
10105 json_object_int_add(json_vrf, "numEstablishedPeers",
10106 peers_estb);
10107
10108 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10109 json_object_string_add(
10110 json_vrf, "rmac",
10111 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10112 json_object_string_add(json_vrf, "interface",
10113 ifindex2ifname(bgp->l3vni_svi_ifindex,
10114 bgp->vrf_id));
10115 json_object_object_add(json_vrfs, name, json_vrf);
10116 } else {
10117 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10118 type,
10119 bgp->vrf_id == VRF_UNKNOWN ? -1
10120 : (int)bgp->vrf_id,
10121 &bgp->router_id, peers_cfg, peers_estb, name);
10122 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10123 bgp->l3vni,
10124 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10125 ifindex2ifname(bgp->l3vni_svi_ifindex,
10126 bgp->vrf_id));
10127 }
10128 }
10129
10130 if (uj) {
10131 json_object_object_add(json, "vrfs", json_vrfs);
10132
10133 json_object_int_add(json, "totalVrfs", count);
10134
10135 vty_json(vty, json);
10136 } else {
10137 if (count)
10138 vty_out(vty,
10139 "\nTotal number of VRFs (including default): %d\n",
10140 count);
10141 }
10142
10143 return CMD_SUCCESS;
10144 }
10145
10146 DEFUN (show_bgp_mac_hash,
10147 show_bgp_mac_hash_cmd,
10148 "show bgp mac hash",
10149 SHOW_STR
10150 BGP_STR
10151 "Mac Address\n"
10152 "Mac Address database\n")
10153 {
10154 bgp_mac_dump_table(vty);
10155
10156 return CMD_SUCCESS;
10157 }
10158
10159 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10160 {
10161 struct vty *vty = (struct vty *)args;
10162 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10163
10164 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10165 }
10166
10167 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10168 {
10169 vty_out(vty, "self nexthop database:\n");
10170 bgp_nexthop_show_address_hash(vty, bgp);
10171
10172 vty_out(vty, "Tunnel-ip database:\n");
10173 hash_iterate(bgp->tip_hash,
10174 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10175 vty);
10176 }
10177
10178 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10179 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10180 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10181 "martian next-hops\n"
10182 "martian next-hop database\n")
10183 {
10184 struct bgp *bgp = NULL;
10185 int idx = 0;
10186 char *name = NULL;
10187
10188 /* [<vrf> VIEWVRFNAME] */
10189 if (argv_find(argv, argc, "vrf", &idx)) {
10190 name = argv[idx + 1]->arg;
10191 if (name && strmatch(name, VRF_DEFAULT_NAME))
10192 name = NULL;
10193 } else if (argv_find(argv, argc, "view", &idx))
10194 /* [<view> VIEWVRFNAME] */
10195 name = argv[idx + 1]->arg;
10196 if (name)
10197 bgp = bgp_lookup_by_name(name);
10198 else
10199 bgp = bgp_get_default();
10200
10201 if (!bgp) {
10202 vty_out(vty, "%% No BGP process is configured\n");
10203 return CMD_WARNING;
10204 }
10205 bgp_show_martian_nexthops(vty, bgp);
10206
10207 return CMD_SUCCESS;
10208 }
10209
10210 DEFUN (show_bgp_memory,
10211 show_bgp_memory_cmd,
10212 "show [ip] bgp memory",
10213 SHOW_STR
10214 IP_STR
10215 BGP_STR
10216 "Global BGP memory statistics\n")
10217 {
10218 char memstrbuf[MTYPE_MEMSTR_LEN];
10219 unsigned long count;
10220
10221 /* RIB related usage stats */
10222 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10223 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10224 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10225 count * sizeof(struct bgp_dest)));
10226
10227 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10228 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10229 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10230 count * sizeof(struct bgp_path_info)));
10231 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10232 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10233 count,
10234 mtype_memstr(
10235 memstrbuf, sizeof(memstrbuf),
10236 count * sizeof(struct bgp_path_info_extra)));
10237
10238 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10239 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10240 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10241 count * sizeof(struct bgp_static)));
10242
10243 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10244 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10245 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10246 count * sizeof(struct bpacket)));
10247
10248 /* Adj-In/Out */
10249 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10250 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10251 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10252 count * sizeof(struct bgp_adj_in)));
10253 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10254 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10255 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10256 count * sizeof(struct bgp_adj_out)));
10257
10258 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10259 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10260 count,
10261 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10262 count * sizeof(struct bgp_nexthop_cache)));
10263
10264 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10265 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10266 count,
10267 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10268 count * sizeof(struct bgp_damp_info)));
10269
10270 /* Attributes */
10271 count = attr_count();
10272 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10273 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10274 count * sizeof(struct attr)));
10275
10276 if ((count = attr_unknown_count()))
10277 vty_out(vty, "%ld unknown attributes\n", count);
10278
10279 /* AS_PATH attributes */
10280 count = aspath_count();
10281 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10282 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10283 count * sizeof(struct aspath)));
10284
10285 count = mtype_stats_alloc(MTYPE_AS_SEG);
10286 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10287 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10288 count * sizeof(struct assegment)));
10289
10290 /* Other attributes */
10291 if ((count = community_count()))
10292 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10293 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10294 count * sizeof(struct community)));
10295 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10296 vty_out(vty,
10297 "%ld BGP ext-community entries, using %s of memory\n",
10298 count,
10299 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10300 count * sizeof(struct ecommunity)));
10301 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10302 vty_out(vty,
10303 "%ld BGP large-community entries, using %s of memory\n",
10304 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10305 count * sizeof(struct lcommunity)));
10306
10307 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10308 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10309 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10310 count * sizeof(struct cluster_list)));
10311
10312 /* Peer related usage */
10313 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10314 vty_out(vty, "%ld peers, using %s of memory\n", count,
10315 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10316 count * sizeof(struct peer)));
10317
10318 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10319 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10320 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10321 count * sizeof(struct peer_group)));
10322
10323 /* Other */
10324 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10325 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10326 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10327 count * sizeof(regex_t)));
10328 return CMD_SUCCESS;
10329 }
10330
10331 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10332 {
10333 json_object *bestpath = json_object_new_object();
10334
10335 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10336 json_object_string_add(bestpath, "asPath", "ignore");
10337
10338 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10339 json_object_string_add(bestpath, "asPath", "confed");
10340
10341 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10342 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10343 json_object_string_add(bestpath, "multiPathRelax",
10344 "as-set");
10345 else
10346 json_object_string_add(bestpath, "multiPathRelax",
10347 "true");
10348 } else
10349 json_object_string_add(bestpath, "multiPathRelax", "false");
10350
10351 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10352 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10353
10354 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10355 json_object_string_add(bestpath, "compareRouterId", "true");
10356 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10357 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10358 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10359 json_object_string_add(bestpath, "med", "confed");
10360 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10361 json_object_string_add(bestpath, "med",
10362 "missing-as-worst");
10363 else
10364 json_object_string_add(bestpath, "med", "true");
10365 }
10366
10367 json_object_object_add(json, "bestPath", bestpath);
10368 }
10369
10370 /* Print the error code/subcode for why the peer is down */
10371 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10372 json_object *json_peer, bool use_json)
10373 {
10374 const char *code_str;
10375 const char *subcode_str;
10376
10377 if (use_json) {
10378 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10379 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10380 char errorcodesubcode_hexstr[5];
10381 char errorcodesubcode_str[256];
10382
10383 code_str = bgp_notify_code_str(peer->notify.code);
10384 subcode_str = bgp_notify_subcode_str(
10385 peer->notify.code,
10386 peer->notify.subcode);
10387
10388 snprintf(errorcodesubcode_hexstr,
10389 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10390 peer->notify.code, peer->notify.subcode);
10391 json_object_string_add(json_peer,
10392 "lastErrorCodeSubcode",
10393 errorcodesubcode_hexstr);
10394 snprintf(errorcodesubcode_str, 255, "%s%s",
10395 code_str, subcode_str);
10396 json_object_string_add(json_peer,
10397 "lastNotificationReason",
10398 errorcodesubcode_str);
10399 json_object_boolean_add(json_peer,
10400 "lastNotificationHardReset",
10401 peer->notify.hard_reset);
10402 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10403 && peer->notify.code == BGP_NOTIFY_CEASE
10404 && (peer->notify.subcode
10405 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10406 || peer->notify.subcode
10407 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10408 && peer->notify.length) {
10409 char msgbuf[1024];
10410 const char *msg_str;
10411
10412 msg_str = bgp_notify_admin_message(
10413 msgbuf, sizeof(msgbuf),
10414 (uint8_t *)peer->notify.data,
10415 peer->notify.length);
10416 if (msg_str)
10417 json_object_string_add(
10418 json_peer,
10419 "lastShutdownDescription",
10420 msg_str);
10421 }
10422
10423 }
10424 json_object_string_add(json_peer, "lastResetDueTo",
10425 peer_down_str[(int)peer->last_reset]);
10426 json_object_int_add(json_peer, "lastResetCode",
10427 peer->last_reset);
10428 } else {
10429 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10430 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10431 code_str = bgp_notify_code_str(peer->notify.code);
10432 subcode_str =
10433 bgp_notify_subcode_str(peer->notify.code,
10434 peer->notify.subcode);
10435 vty_out(vty, " Notification %s (%s%s%s)\n",
10436 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10437 ? "sent"
10438 : "received",
10439 code_str, subcode_str,
10440 peer->notify.hard_reset
10441 ? bgp_notify_subcode_str(
10442 BGP_NOTIFY_CEASE,
10443 BGP_NOTIFY_CEASE_HARD_RESET)
10444 : "");
10445 } else {
10446 vty_out(vty, " %s\n",
10447 peer_down_str[(int)peer->last_reset]);
10448 }
10449 }
10450 }
10451
10452 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10453 safi_t safi)
10454 {
10455 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10456 }
10457
10458 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10459 struct peer *peer, json_object *json_peer,
10460 int max_neighbor_width, bool use_json)
10461 {
10462 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10463 int len;
10464
10465 if (use_json) {
10466 if (peer_dynamic_neighbor(peer))
10467 json_object_boolean_true_add(json_peer,
10468 "dynamicPeer");
10469 if (peer->hostname)
10470 json_object_string_add(json_peer, "hostname",
10471 peer->hostname);
10472
10473 if (peer->domainname)
10474 json_object_string_add(json_peer, "domainname",
10475 peer->domainname);
10476 json_object_int_add(json_peer, "connectionsEstablished",
10477 peer->established);
10478 json_object_int_add(json_peer, "connectionsDropped",
10479 peer->dropped);
10480 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10481 use_json, json_peer);
10482 if (peer_established(peer))
10483 json_object_string_add(json_peer, "lastResetDueTo",
10484 "AFI/SAFI Not Negotiated");
10485 else
10486 bgp_show_peer_reset(NULL, peer, json_peer, true);
10487 } else {
10488 dn_flag[1] = '\0';
10489 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10490 if (peer->hostname
10491 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10492 len = vty_out(vty, "%s%s(%s)", dn_flag,
10493 peer->hostname, peer->host);
10494 else
10495 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10496
10497 /* pad the neighbor column with spaces */
10498 if (len < max_neighbor_width)
10499 vty_out(vty, "%*s", max_neighbor_width - len,
10500 " ");
10501 vty_out(vty, "%7d %7d %9s", peer->established,
10502 peer->dropped,
10503 peer_uptime(peer->uptime, timebuf,
10504 BGP_UPTIME_LEN, 0, NULL));
10505 if (peer_established(peer))
10506 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10507 else
10508 bgp_show_peer_reset(vty, peer, NULL,
10509 false);
10510 }
10511 }
10512
10513 /* Strip peer's description to the given size. */
10514 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10515 {
10516 static char stripped[BUFSIZ];
10517 uint32_t i = 0;
10518 uint32_t last_space = 0;
10519
10520 while (i < size) {
10521 if (*(desc + i) == 0) {
10522 stripped[i] = '\0';
10523 return stripped;
10524 }
10525 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10526 last_space = i;
10527 stripped[i] = *(desc + i);
10528 i++;
10529 }
10530
10531 if (last_space > size)
10532 stripped[size + 1] = '\0';
10533 else
10534 stripped[last_space] = '\0';
10535
10536 return stripped;
10537 }
10538
10539 /* Determine whether var peer should be filtered out of the summary. */
10540 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10541 struct peer *fpeer, int as_type,
10542 as_t as)
10543 {
10544
10545 /* filter neighbor XXXX */
10546 if (fpeer && fpeer != peer)
10547 return true;
10548
10549 /* filter remote-as (internal|external) */
10550 if (as_type != AS_UNSPECIFIED) {
10551 if (peer->as_type == AS_SPECIFIED) {
10552 if (as_type == AS_INTERNAL) {
10553 if (peer->as != peer->local_as)
10554 return true;
10555 } else if (peer->as == peer->local_as)
10556 return true;
10557 } else if (as_type != peer->as_type)
10558 return true;
10559 } else if (as && as != peer->as) /* filter remote-as XXX */
10560 return true;
10561
10562 return false;
10563 }
10564
10565 /* Show BGP peer's summary information.
10566 *
10567 * Peer's description is stripped according to if `wide` option is given
10568 * or not.
10569 *
10570 * When adding new columns to `show bgp summary` output, please make
10571 * sure `Desc` is the lastest column to show because it can contain
10572 * whitespaces and the whole output will be tricky.
10573 */
10574 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10575 struct peer *fpeer, int as_type, as_t as,
10576 uint16_t show_flags)
10577 {
10578 struct peer *peer;
10579 struct listnode *node, *nnode;
10580 unsigned int count = 0, dn_count = 0;
10581 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10582 char neighbor_buf[VTY_BUFSIZ];
10583 int neighbor_col_default_width = 16;
10584 int len, failed_count = 0;
10585 unsigned int filtered_count = 0;
10586 int max_neighbor_width = 0;
10587 int pfx_rcd_safi;
10588 json_object *json = NULL;
10589 json_object *json_peer = NULL;
10590 json_object *json_peers = NULL;
10591 struct peer_af *paf;
10592 struct bgp_filter *filter;
10593 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10594 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10595 bool show_established =
10596 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10597 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10598 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10599
10600 /* labeled-unicast routes are installed in the unicast table so in order
10601 * to
10602 * display the correct PfxRcd value we must look at SAFI_UNICAST
10603 */
10604
10605 if (safi == SAFI_LABELED_UNICAST)
10606 pfx_rcd_safi = SAFI_UNICAST;
10607 else
10608 pfx_rcd_safi = safi;
10609
10610 if (use_json) {
10611 json = json_object_new_object();
10612 json_peers = json_object_new_object();
10613 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10614 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10615 as_type, as)) {
10616 filtered_count++;
10617 count++;
10618 continue;
10619 }
10620
10621 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10622 continue;
10623
10624 if (peer->afc[afi][safi]) {
10625 /* See if we have at least a single failed peer */
10626 if (bgp_has_peer_failed(peer, afi, safi))
10627 failed_count++;
10628 count++;
10629 }
10630 if (peer_dynamic_neighbor(peer))
10631 dn_count++;
10632 }
10633
10634 } else {
10635 /* Loop over all neighbors that will be displayed to determine
10636 * how many
10637 * characters are needed for the Neighbor column
10638 */
10639 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10640 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10641 as_type, as)) {
10642 filtered_count++;
10643 count++;
10644 continue;
10645 }
10646
10647 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10648 continue;
10649
10650 if (peer->afc[afi][safi]) {
10651 memset(dn_flag, '\0', sizeof(dn_flag));
10652 if (peer_dynamic_neighbor(peer))
10653 dn_flag[0] = '*';
10654
10655 if (peer->hostname
10656 && CHECK_FLAG(bgp->flags,
10657 BGP_FLAG_SHOW_HOSTNAME))
10658 snprintf(neighbor_buf,
10659 sizeof(neighbor_buf),
10660 "%s%s(%s) ", dn_flag,
10661 peer->hostname, peer->host);
10662 else
10663 snprintf(neighbor_buf,
10664 sizeof(neighbor_buf), "%s%s ",
10665 dn_flag, peer->host);
10666
10667 len = strlen(neighbor_buf);
10668
10669 if (len > max_neighbor_width)
10670 max_neighbor_width = len;
10671
10672 /* See if we have at least a single failed peer */
10673 if (bgp_has_peer_failed(peer, afi, safi))
10674 failed_count++;
10675 count++;
10676 }
10677 }
10678
10679 /* Originally we displayed the Neighbor column as 16
10680 * characters wide so make that the default
10681 */
10682 if (max_neighbor_width < neighbor_col_default_width)
10683 max_neighbor_width = neighbor_col_default_width;
10684 }
10685
10686 if (show_failed && !failed_count) {
10687 if (use_json) {
10688 json_object_int_add(json, "failedPeersCount", 0);
10689 json_object_int_add(json, "dynamicPeers", dn_count);
10690 json_object_int_add(json, "totalPeers", count);
10691
10692 vty_json(vty, json);
10693 } else {
10694 vty_out(vty, "%% No failed BGP neighbors found\n");
10695 }
10696 return CMD_SUCCESS;
10697 }
10698
10699 count = 0; /* Reset the value as its used again */
10700 filtered_count = 0;
10701 dn_count = 0;
10702 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10703 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10704 continue;
10705
10706 if (!peer->afc[afi][safi])
10707 continue;
10708
10709 if (!count) {
10710 unsigned long ents;
10711 char memstrbuf[MTYPE_MEMSTR_LEN];
10712 int64_t vrf_id_ui;
10713
10714 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10715 ? -1
10716 : (int64_t)bgp->vrf_id;
10717
10718 /* Usage summary and header */
10719 if (use_json) {
10720 json_object_string_addf(json, "routerId",
10721 "%pI4",
10722 &bgp->router_id);
10723 json_object_int_add(json, "as", bgp->as);
10724 json_object_int_add(json, "vrfId", vrf_id_ui);
10725 json_object_string_add(
10726 json, "vrfName",
10727 (bgp->inst_type
10728 == BGP_INSTANCE_TYPE_DEFAULT)
10729 ? VRF_DEFAULT_NAME
10730 : bgp->name);
10731 } else {
10732 vty_out(vty,
10733 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10734 &bgp->router_id, bgp->as,
10735 bgp->vrf_id == VRF_UNKNOWN
10736 ? -1
10737 : (int)bgp->vrf_id);
10738 vty_out(vty, "\n");
10739 }
10740
10741 if (bgp_update_delay_configured(bgp)) {
10742 if (use_json) {
10743 json_object_int_add(
10744 json, "updateDelayLimit",
10745 bgp->v_update_delay);
10746
10747 if (bgp->v_update_delay
10748 != bgp->v_establish_wait)
10749 json_object_int_add(
10750 json,
10751 "updateDelayEstablishWait",
10752 bgp->v_establish_wait);
10753
10754 if (bgp_update_delay_active(bgp)) {
10755 json_object_string_add(
10756 json,
10757 "updateDelayFirstNeighbor",
10758 bgp->update_delay_begin_time);
10759 json_object_boolean_true_add(
10760 json,
10761 "updateDelayInProgress");
10762 } else {
10763 if (bgp->update_delay_over) {
10764 json_object_string_add(
10765 json,
10766 "updateDelayFirstNeighbor",
10767 bgp->update_delay_begin_time);
10768 json_object_string_add(
10769 json,
10770 "updateDelayBestpathResumed",
10771 bgp->update_delay_end_time);
10772 json_object_string_add(
10773 json,
10774 "updateDelayZebraUpdateResume",
10775 bgp->update_delay_zebra_resume_time);
10776 json_object_string_add(
10777 json,
10778 "updateDelayPeerUpdateResume",
10779 bgp->update_delay_peers_resume_time);
10780 }
10781 }
10782 } else {
10783 vty_out(vty,
10784 "Read-only mode update-delay limit: %d seconds\n",
10785 bgp->v_update_delay);
10786 if (bgp->v_update_delay
10787 != bgp->v_establish_wait)
10788 vty_out(vty,
10789 " Establish wait: %d seconds\n",
10790 bgp->v_establish_wait);
10791
10792 if (bgp_update_delay_active(bgp)) {
10793 vty_out(vty,
10794 " First neighbor established: %s\n",
10795 bgp->update_delay_begin_time);
10796 vty_out(vty,
10797 " Delay in progress\n");
10798 } else {
10799 if (bgp->update_delay_over) {
10800 vty_out(vty,
10801 " First neighbor established: %s\n",
10802 bgp->update_delay_begin_time);
10803 vty_out(vty,
10804 " Best-paths resumed: %s\n",
10805 bgp->update_delay_end_time);
10806 vty_out(vty,
10807 " zebra update resumed: %s\n",
10808 bgp->update_delay_zebra_resume_time);
10809 vty_out(vty,
10810 " peers update resumed: %s\n",
10811 bgp->update_delay_peers_resume_time);
10812 }
10813 }
10814 }
10815 }
10816
10817 if (use_json) {
10818 if (bgp_maxmed_onstartup_configured(bgp)
10819 && bgp->maxmed_active)
10820 json_object_boolean_true_add(
10821 json, "maxMedOnStartup");
10822 if (bgp->v_maxmed_admin)
10823 json_object_boolean_true_add(
10824 json, "maxMedAdministrative");
10825
10826 json_object_int_add(
10827 json, "tableVersion",
10828 bgp_table_version(bgp->rib[afi][safi]));
10829
10830 ents = bgp_table_count(bgp->rib[afi][safi]);
10831 json_object_int_add(json, "ribCount", ents);
10832 json_object_int_add(
10833 json, "ribMemory",
10834 ents * sizeof(struct bgp_dest));
10835
10836 ents = bgp->af_peer_count[afi][safi];
10837 json_object_int_add(json, "peerCount", ents);
10838 json_object_int_add(json, "peerMemory",
10839 ents * sizeof(struct peer));
10840
10841 if ((ents = listcount(bgp->group))) {
10842 json_object_int_add(
10843 json, "peerGroupCount", ents);
10844 json_object_int_add(
10845 json, "peerGroupMemory",
10846 ents * sizeof(struct
10847 peer_group));
10848 }
10849
10850 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10851 BGP_CONFIG_DAMPENING))
10852 json_object_boolean_true_add(
10853 json, "dampeningEnabled");
10854 } else {
10855 if (!show_terse) {
10856 if (bgp_maxmed_onstartup_configured(bgp)
10857 && bgp->maxmed_active)
10858 vty_out(vty,
10859 "Max-med on-startup active\n");
10860 if (bgp->v_maxmed_admin)
10861 vty_out(vty,
10862 "Max-med administrative active\n");
10863
10864 vty_out(vty,
10865 "BGP table version %" PRIu64
10866 "\n",
10867 bgp_table_version(
10868 bgp->rib[afi][safi]));
10869
10870 ents = bgp_table_count(
10871 bgp->rib[afi][safi]);
10872 vty_out(vty,
10873 "RIB entries %ld, using %s of memory\n",
10874 ents,
10875 mtype_memstr(
10876 memstrbuf,
10877 sizeof(memstrbuf),
10878 ents
10879 * sizeof(
10880 struct
10881 bgp_dest)));
10882
10883 /* Peer related usage */
10884 ents = bgp->af_peer_count[afi][safi];
10885 vty_out(vty,
10886 "Peers %ld, using %s of memory\n",
10887 ents,
10888 mtype_memstr(
10889 memstrbuf,
10890 sizeof(memstrbuf),
10891 ents
10892 * sizeof(
10893 struct
10894 peer)));
10895
10896 if ((ents = listcount(bgp->group)))
10897 vty_out(vty,
10898 "Peer groups %ld, using %s of memory\n",
10899 ents,
10900 mtype_memstr(
10901 memstrbuf,
10902 sizeof(memstrbuf),
10903 ents
10904 * sizeof(
10905 struct
10906 peer_group)));
10907
10908 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10909 BGP_CONFIG_DAMPENING))
10910 vty_out(vty,
10911 "Dampening enabled.\n");
10912 }
10913 if (show_failed) {
10914 vty_out(vty, "\n");
10915
10916 /* Subtract 8 here because 'Neighbor' is
10917 * 8 characters */
10918 vty_out(vty, "Neighbor");
10919 vty_out(vty, "%*s",
10920 max_neighbor_width - 8, " ");
10921 vty_out(vty,
10922 BGP_SHOW_SUMMARY_HEADER_FAILED);
10923 }
10924 }
10925 }
10926
10927 paf = peer_af_find(peer, afi, safi);
10928 filter = &peer->filter[afi][safi];
10929
10930 count++;
10931 /* Works for both failed & successful cases */
10932 if (peer_dynamic_neighbor(peer))
10933 dn_count++;
10934
10935 if (use_json) {
10936 json_peer = NULL;
10937 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10938 as_type, as)) {
10939 filtered_count++;
10940 continue;
10941 }
10942 if (show_failed &&
10943 bgp_has_peer_failed(peer, afi, safi)) {
10944 json_peer = json_object_new_object();
10945 bgp_show_failed_summary(vty, bgp, peer,
10946 json_peer, 0, use_json);
10947 } else if (!show_failed) {
10948 if (show_established
10949 && bgp_has_peer_failed(peer, afi, safi)) {
10950 filtered_count++;
10951 continue;
10952 }
10953
10954 json_peer = json_object_new_object();
10955 if (peer_dynamic_neighbor(peer)) {
10956 json_object_boolean_true_add(json_peer,
10957 "dynamicPeer");
10958 }
10959
10960 if (peer->hostname)
10961 json_object_string_add(json_peer, "hostname",
10962 peer->hostname);
10963
10964 if (peer->domainname)
10965 json_object_string_add(json_peer, "domainname",
10966 peer->domainname);
10967
10968 json_object_int_add(json_peer, "remoteAs", peer->as);
10969 json_object_int_add(
10970 json_peer, "localAs",
10971 peer->change_local_as
10972 ? peer->change_local_as
10973 : peer->local_as);
10974 json_object_int_add(json_peer, "version", 4);
10975 json_object_int_add(json_peer, "msgRcvd",
10976 PEER_TOTAL_RX(peer));
10977 json_object_int_add(json_peer, "msgSent",
10978 PEER_TOTAL_TX(peer));
10979
10980 atomic_size_t outq_count, inq_count;
10981 outq_count = atomic_load_explicit(
10982 &peer->obuf->count,
10983 memory_order_relaxed);
10984 inq_count = atomic_load_explicit(
10985 &peer->ibuf->count,
10986 memory_order_relaxed);
10987
10988 json_object_int_add(json_peer, "tableVersion",
10989 peer->version[afi][safi]);
10990 json_object_int_add(json_peer, "outq",
10991 outq_count);
10992 json_object_int_add(json_peer, "inq",
10993 inq_count);
10994 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10995 use_json, json_peer);
10996
10997 json_object_int_add(json_peer, "pfxRcd",
10998 peer->pcount[afi][pfx_rcd_safi]);
10999
11000 if (paf && PAF_SUBGRP(paf))
11001 json_object_int_add(
11002 json_peer, "pfxSnt",
11003 (PAF_SUBGRP(paf))->scount);
11004 else
11005 json_object_int_add(json_peer, "pfxSnt",
11006 0);
11007
11008 /* BGP FSM state */
11009 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11010 || CHECK_FLAG(peer->bgp->flags,
11011 BGP_FLAG_SHUTDOWN))
11012 json_object_string_add(json_peer,
11013 "state",
11014 "Idle (Admin)");
11015 else if (peer->afc_recv[afi][safi])
11016 json_object_string_add(
11017 json_peer, "state",
11018 lookup_msg(bgp_status_msg,
11019 peer->status, NULL));
11020 else if (CHECK_FLAG(
11021 peer->sflags,
11022 PEER_STATUS_PREFIX_OVERFLOW))
11023 json_object_string_add(json_peer,
11024 "state",
11025 "Idle (PfxCt)");
11026 else
11027 json_object_string_add(
11028 json_peer, "state",
11029 lookup_msg(bgp_status_msg,
11030 peer->status, NULL));
11031
11032 /* BGP peer state */
11033 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11034 || CHECK_FLAG(peer->bgp->flags,
11035 BGP_FLAG_SHUTDOWN))
11036 json_object_string_add(json_peer,
11037 "peerState",
11038 "Admin");
11039 else if (CHECK_FLAG(
11040 peer->sflags,
11041 PEER_STATUS_PREFIX_OVERFLOW))
11042 json_object_string_add(json_peer,
11043 "peerState",
11044 "PfxCt");
11045 else if (CHECK_FLAG(peer->flags,
11046 PEER_FLAG_PASSIVE))
11047 json_object_string_add(json_peer,
11048 "peerState",
11049 "Passive");
11050 else if (CHECK_FLAG(peer->sflags,
11051 PEER_STATUS_NSF_WAIT))
11052 json_object_string_add(json_peer,
11053 "peerState",
11054 "NSF passive");
11055 else if (CHECK_FLAG(
11056 peer->bgp->flags,
11057 BGP_FLAG_EBGP_REQUIRES_POLICY)
11058 && (!bgp_inbound_policy_exists(peer,
11059 filter)
11060 || !bgp_outbound_policy_exists(
11061 peer, filter)))
11062 json_object_string_add(json_peer,
11063 "peerState",
11064 "Policy");
11065 else
11066 json_object_string_add(
11067 json_peer, "peerState", "OK");
11068
11069 json_object_int_add(json_peer, "connectionsEstablished",
11070 peer->established);
11071 json_object_int_add(json_peer, "connectionsDropped",
11072 peer->dropped);
11073 if (peer->desc)
11074 json_object_string_add(
11075 json_peer, "desc", peer->desc);
11076 }
11077 /* Avoid creating empty peer dicts in JSON */
11078 if (json_peer == NULL)
11079 continue;
11080
11081 if (peer->conf_if)
11082 json_object_string_add(json_peer, "idType",
11083 "interface");
11084 else if (peer->su.sa.sa_family == AF_INET)
11085 json_object_string_add(json_peer, "idType",
11086 "ipv4");
11087 else if (peer->su.sa.sa_family == AF_INET6)
11088 json_object_string_add(json_peer, "idType",
11089 "ipv6");
11090 json_object_object_add(json_peers, peer->host,
11091 json_peer);
11092 } else {
11093 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11094 as_type, as)) {
11095 filtered_count++;
11096 continue;
11097 }
11098 if (show_failed &&
11099 bgp_has_peer_failed(peer, afi, safi)) {
11100 bgp_show_failed_summary(vty, bgp, peer, NULL,
11101 max_neighbor_width,
11102 use_json);
11103 } else if (!show_failed) {
11104 if (show_established
11105 && bgp_has_peer_failed(peer, afi, safi)) {
11106 filtered_count++;
11107 continue;
11108 }
11109
11110 if ((count - filtered_count) == 1) {
11111 /* display headline before the first
11112 * neighbor line */
11113 vty_out(vty, "\n");
11114
11115 /* Subtract 8 here because 'Neighbor' is
11116 * 8 characters */
11117 vty_out(vty, "Neighbor");
11118 vty_out(vty, "%*s",
11119 max_neighbor_width - 8, " ");
11120 vty_out(vty,
11121 show_wide
11122 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11123 : BGP_SHOW_SUMMARY_HEADER_ALL);
11124 }
11125
11126 memset(dn_flag, '\0', sizeof(dn_flag));
11127 if (peer_dynamic_neighbor(peer)) {
11128 dn_flag[0] = '*';
11129 }
11130
11131 if (peer->hostname
11132 && CHECK_FLAG(bgp->flags,
11133 BGP_FLAG_SHOW_HOSTNAME))
11134 len = vty_out(vty, "%s%s(%s)", dn_flag,
11135 peer->hostname,
11136 peer->host);
11137 else
11138 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11139
11140 /* pad the neighbor column with spaces */
11141 if (len < max_neighbor_width)
11142 vty_out(vty, "%*s", max_neighbor_width - len,
11143 " ");
11144
11145 atomic_size_t outq_count, inq_count;
11146 outq_count = atomic_load_explicit(
11147 &peer->obuf->count,
11148 memory_order_relaxed);
11149 inq_count = atomic_load_explicit(
11150 &peer->ibuf->count,
11151 memory_order_relaxed);
11152
11153 if (show_wide)
11154 vty_out(vty,
11155 "4 %10u %10u %9u %9u %8" PRIu64
11156 " %4zu %4zu %8s",
11157 peer->as,
11158 peer->change_local_as
11159 ? peer->change_local_as
11160 : peer->local_as,
11161 PEER_TOTAL_RX(peer),
11162 PEER_TOTAL_TX(peer),
11163 peer->version[afi][safi],
11164 inq_count, outq_count,
11165 peer_uptime(peer->uptime,
11166 timebuf,
11167 BGP_UPTIME_LEN, 0,
11168 NULL));
11169 else
11170 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11171 " %4zu %4zu %8s",
11172 peer->as, PEER_TOTAL_RX(peer),
11173 PEER_TOTAL_TX(peer),
11174 peer->version[afi][safi],
11175 inq_count, outq_count,
11176 peer_uptime(peer->uptime,
11177 timebuf,
11178 BGP_UPTIME_LEN, 0,
11179 NULL));
11180
11181 if (peer_established(peer)) {
11182 if (peer->afc_recv[afi][safi]) {
11183 if (CHECK_FLAG(
11184 bgp->flags,
11185 BGP_FLAG_EBGP_REQUIRES_POLICY)
11186 && !bgp_inbound_policy_exists(
11187 peer, filter))
11188 vty_out(vty, " %12s",
11189 "(Policy)");
11190 else
11191 vty_out(vty,
11192 " %12u",
11193 peer->pcount
11194 [afi]
11195 [pfx_rcd_safi]);
11196 } else {
11197 vty_out(vty, " NoNeg");
11198 }
11199
11200 if (paf && PAF_SUBGRP(paf)) {
11201 if (CHECK_FLAG(
11202 bgp->flags,
11203 BGP_FLAG_EBGP_REQUIRES_POLICY)
11204 && !bgp_outbound_policy_exists(
11205 peer, filter))
11206 vty_out(vty, " %8s",
11207 "(Policy)");
11208 else
11209 vty_out(vty,
11210 " %8u",
11211 (PAF_SUBGRP(
11212 paf))
11213 ->scount);
11214 } else {
11215 vty_out(vty, " NoNeg");
11216 }
11217 } else {
11218 if (CHECK_FLAG(peer->flags,
11219 PEER_FLAG_SHUTDOWN)
11220 || CHECK_FLAG(peer->bgp->flags,
11221 BGP_FLAG_SHUTDOWN))
11222 vty_out(vty, " Idle (Admin)");
11223 else if (CHECK_FLAG(
11224 peer->sflags,
11225 PEER_STATUS_PREFIX_OVERFLOW))
11226 vty_out(vty, " Idle (PfxCt)");
11227 else
11228 vty_out(vty, " %12s",
11229 lookup_msg(bgp_status_msg,
11230 peer->status, NULL));
11231
11232 vty_out(vty, " %8u", 0);
11233 }
11234 /* Make sure `Desc` column is the lastest in
11235 * the output.
11236 */
11237 if (peer->desc)
11238 vty_out(vty, " %s",
11239 bgp_peer_description_stripped(
11240 peer->desc,
11241 show_wide ? 64 : 20));
11242 else
11243 vty_out(vty, " N/A");
11244 vty_out(vty, "\n");
11245 }
11246
11247 }
11248 }
11249
11250 if (use_json) {
11251 json_object_object_add(json, "peers", json_peers);
11252 json_object_int_add(json, "failedPeers", failed_count);
11253 json_object_int_add(json, "displayedPeers",
11254 count - filtered_count);
11255 json_object_int_add(json, "totalPeers", count);
11256 json_object_int_add(json, "dynamicPeers", dn_count);
11257
11258 if (!show_failed)
11259 bgp_show_bestpath_json(bgp, json);
11260
11261 vty_json(vty, json);
11262 } else {
11263 if (count) {
11264 if (filtered_count == count)
11265 vty_out(vty, "\n%% No matching neighbor\n");
11266 else {
11267 if (show_failed)
11268 vty_out(vty, "\nDisplayed neighbors %d",
11269 failed_count);
11270 else if (as_type != AS_UNSPECIFIED || as
11271 || fpeer || show_established)
11272 vty_out(vty, "\nDisplayed neighbors %d",
11273 count - filtered_count);
11274
11275 vty_out(vty, "\nTotal number of neighbors %d\n",
11276 count);
11277 }
11278 } else {
11279 vty_out(vty, "No %s neighbor is configured\n",
11280 get_afi_safi_str(afi, safi, false));
11281 }
11282
11283 if (dn_count) {
11284 vty_out(vty, "* - dynamic neighbor\n");
11285 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11286 dn_count, bgp->dynamic_neighbors_limit);
11287 }
11288 }
11289
11290 return CMD_SUCCESS;
11291 }
11292
11293 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11294 int safi, struct peer *fpeer, int as_type,
11295 as_t as, uint16_t show_flags)
11296 {
11297 int is_first = 1;
11298 int afi_wildcard = (afi == AFI_MAX);
11299 int safi_wildcard = (safi == SAFI_MAX);
11300 int is_wildcard = (afi_wildcard || safi_wildcard);
11301 bool nbr_output = false;
11302 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11303
11304 if (use_json && is_wildcard)
11305 vty_out(vty, "{\n");
11306 if (afi_wildcard)
11307 afi = 1; /* AFI_IP */
11308 while (afi < AFI_MAX) {
11309 if (safi_wildcard)
11310 safi = 1; /* SAFI_UNICAST */
11311 while (safi < SAFI_MAX) {
11312 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11313 nbr_output = true;
11314
11315 if (is_wildcard) {
11316 /*
11317 * So limit output to those afi/safi
11318 * pairs that
11319 * actualy have something interesting in
11320 * them
11321 */
11322 if (use_json) {
11323 if (!is_first)
11324 vty_out(vty, ",\n");
11325 else
11326 is_first = 0;
11327
11328 vty_out(vty, "\"%s\":",
11329 get_afi_safi_str(afi,
11330 safi,
11331 true));
11332 } else {
11333 vty_out(vty,
11334 "\n%s Summary (%s):\n",
11335 get_afi_safi_str(afi,
11336 safi,
11337 false),
11338 bgp->name_pretty);
11339 }
11340 }
11341 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11342 as_type, as, show_flags);
11343 }
11344 safi++;
11345 if (!safi_wildcard)
11346 safi = SAFI_MAX;
11347 }
11348 afi++;
11349 if (!afi_wildcard)
11350 afi = AFI_MAX;
11351 }
11352
11353 if (use_json && is_wildcard)
11354 vty_out(vty, "}\n");
11355 else if (!nbr_output) {
11356 if (use_json)
11357 vty_out(vty, "{}\n");
11358 else
11359 vty_out(vty, "%% No BGP neighbors found in %s\n",
11360 bgp->name_pretty);
11361 }
11362 }
11363
11364 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11365 safi_t safi,
11366 const char *neighbor,
11367 int as_type, as_t as,
11368 uint16_t show_flags)
11369 {
11370 struct listnode *node, *nnode;
11371 struct bgp *bgp;
11372 struct peer *fpeer = NULL;
11373 int is_first = 1;
11374 bool nbr_output = false;
11375 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11376
11377 if (use_json)
11378 vty_out(vty, "{\n");
11379
11380 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11381 nbr_output = true;
11382 if (use_json) {
11383 if (!is_first)
11384 vty_out(vty, ",\n");
11385 else
11386 is_first = 0;
11387
11388 vty_out(vty, "\"%s\":",
11389 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11390 ? VRF_DEFAULT_NAME
11391 : bgp->name);
11392 }
11393 if (neighbor) {
11394 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11395 use_json);
11396 if (!fpeer)
11397 continue;
11398 }
11399 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11400 as, show_flags);
11401 }
11402
11403 if (use_json)
11404 vty_out(vty, "}\n");
11405 else if (!nbr_output)
11406 vty_out(vty, "%% BGP instance not found\n");
11407 }
11408
11409 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11410 safi_t safi, const char *neighbor, int as_type,
11411 as_t as, uint16_t show_flags)
11412 {
11413 struct bgp *bgp;
11414 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11415 struct peer *fpeer = NULL;
11416
11417 if (name) {
11418 if (strmatch(name, "all")) {
11419 bgp_show_all_instances_summary_vty(vty, afi, safi,
11420 neighbor, as_type,
11421 as, show_flags);
11422 return CMD_SUCCESS;
11423 } else {
11424 bgp = bgp_lookup_by_name(name);
11425
11426 if (!bgp) {
11427 if (use_json)
11428 vty_out(vty, "{}\n");
11429 else
11430 vty_out(vty,
11431 "%% BGP instance not found\n");
11432 return CMD_WARNING;
11433 }
11434
11435 if (neighbor) {
11436 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11437 use_json);
11438 if (!fpeer)
11439 return CMD_WARNING;
11440 }
11441 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11442 as_type, as, show_flags);
11443 return CMD_SUCCESS;
11444 }
11445 }
11446
11447 bgp = bgp_get_default();
11448
11449 if (bgp) {
11450 if (neighbor) {
11451 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11452 use_json);
11453 if (!fpeer)
11454 return CMD_WARNING;
11455 }
11456 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11457 as, show_flags);
11458 } else {
11459 if (use_json)
11460 vty_out(vty, "{}\n");
11461 else
11462 vty_out(vty, "%% BGP instance not found\n");
11463 return CMD_WARNING;
11464 }
11465
11466 return CMD_SUCCESS;
11467 }
11468
11469 /* `show [ip] bgp summary' commands. */
11470 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11471 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11472 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11473 "]] [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]",
11474 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11475 BGP_SAFI_WITH_LABEL_HELP_STR
11476 "Display the entries for all address families\n"
11477 "Summary of BGP neighbor status\n"
11478 "Show only sessions in Established state\n"
11479 "Show only sessions not in Established state\n"
11480 "Show only the specified neighbor session\n"
11481 "Neighbor to display information about\n"
11482 "Neighbor to display information about\n"
11483 "Neighbor on BGP configured interface\n"
11484 "Show only the specified remote AS sessions\n"
11485 "AS number\n"
11486 "Internal (iBGP) AS sessions\n"
11487 "External (eBGP) AS sessions\n"
11488 "Shorten the information on BGP instances\n"
11489 "Increase table width for longer output\n" JSON_STR)
11490 {
11491 char *vrf = NULL;
11492 afi_t afi = AFI_MAX;
11493 safi_t safi = SAFI_MAX;
11494 as_t as = 0; /* 0 means AS filter not set */
11495 int as_type = AS_UNSPECIFIED;
11496 uint16_t show_flags = 0;
11497
11498 int idx = 0;
11499
11500 /* show [ip] bgp */
11501 if (!all && argv_find(argv, argc, "ip", &idx))
11502 afi = AFI_IP;
11503 /* [<vrf> VIEWVRFNAME] */
11504 if (argv_find(argv, argc, "vrf", &idx)) {
11505 vrf = argv[idx + 1]->arg;
11506 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11507 vrf = NULL;
11508 } else if (argv_find(argv, argc, "view", &idx))
11509 /* [<view> VIEWVRFNAME] */
11510 vrf = argv[idx + 1]->arg;
11511 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11512 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11513 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11514 }
11515
11516 if (argv_find(argv, argc, "failed", &idx))
11517 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11518
11519 if (argv_find(argv, argc, "established", &idx))
11520 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11521
11522 if (argv_find(argv, argc, "remote-as", &idx)) {
11523 if (argv[idx + 1]->arg[0] == 'i')
11524 as_type = AS_INTERNAL;
11525 else if (argv[idx + 1]->arg[0] == 'e')
11526 as_type = AS_EXTERNAL;
11527 else
11528 as = (as_t)atoi(argv[idx + 1]->arg);
11529 }
11530
11531 if (argv_find(argv, argc, "terse", &idx))
11532 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11533
11534 if (argv_find(argv, argc, "wide", &idx))
11535 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11536
11537 if (argv_find(argv, argc, "json", &idx))
11538 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11539
11540 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11541 show_flags);
11542 }
11543
11544 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11545 {
11546 if (for_json)
11547 return get_afi_safi_json_str(afi, safi);
11548 else
11549 return get_afi_safi_vty_str(afi, safi);
11550 }
11551
11552
11553 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11554 afi_t afi, safi_t safi,
11555 uint16_t adv_smcap, uint16_t adv_rmcap,
11556 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11557 bool use_json, json_object *json_pref)
11558 {
11559 /* Send-Mode */
11560 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11561 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11562 if (use_json) {
11563 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11564 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11565 json_object_string_add(json_pref, "sendMode",
11566 "advertisedAndReceived");
11567 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11568 json_object_string_add(json_pref, "sendMode",
11569 "advertised");
11570 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11571 json_object_string_add(json_pref, "sendMode",
11572 "received");
11573 } else {
11574 vty_out(vty, " Send-mode: ");
11575 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11576 vty_out(vty, "advertised");
11577 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11578 vty_out(vty, "%sreceived",
11579 CHECK_FLAG(p->af_cap[afi][safi],
11580 adv_smcap)
11581 ? ", "
11582 : "");
11583 vty_out(vty, "\n");
11584 }
11585 }
11586
11587 /* Receive-Mode */
11588 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11589 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11590 if (use_json) {
11591 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11592 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11593 json_object_string_add(json_pref, "recvMode",
11594 "advertisedAndReceived");
11595 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11596 json_object_string_add(json_pref, "recvMode",
11597 "advertised");
11598 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11599 json_object_string_add(json_pref, "recvMode",
11600 "received");
11601 } else {
11602 vty_out(vty, " Receive-mode: ");
11603 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11604 vty_out(vty, "advertised");
11605 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11606 vty_out(vty, "%sreceived",
11607 CHECK_FLAG(p->af_cap[afi][safi],
11608 adv_rmcap)
11609 ? ", "
11610 : "");
11611 vty_out(vty, "\n");
11612 }
11613 }
11614 }
11615
11616 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11617 struct peer *p,
11618 bool use_json,
11619 json_object *json)
11620 {
11621 bool rbit = false;
11622 bool nbit = false;
11623
11624 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11625 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11626 && (peer_established(p))) {
11627 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11628 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11629 }
11630
11631 if (use_json) {
11632 json_object_boolean_add(json, "rBit", rbit);
11633 json_object_boolean_add(json, "nBit", nbit);
11634 } else {
11635 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11636 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11637 }
11638 }
11639
11640 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11641 struct peer *peer,
11642 bool use_json,
11643 json_object *json)
11644 {
11645 const char *mode = "NotApplicable";
11646
11647 if (!use_json)
11648 vty_out(vty, "\n Remote GR Mode: ");
11649
11650 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11651 && (peer_established(peer))) {
11652
11653 if ((peer->nsf_af_count == 0)
11654 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11655
11656 mode = "Disable";
11657
11658 } else if (peer->nsf_af_count == 0
11659 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11660
11661 mode = "Helper";
11662
11663 } else if (peer->nsf_af_count != 0
11664 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11665
11666 mode = "Restart";
11667 }
11668 }
11669
11670 if (use_json) {
11671 json_object_string_add(json, "remoteGrMode", mode);
11672 } else
11673 vty_out(vty, mode, "\n");
11674 }
11675
11676 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11677 struct peer *p,
11678 bool use_json,
11679 json_object *json)
11680 {
11681 const char *mode = "Invalid";
11682
11683 if (!use_json)
11684 vty_out(vty, " Local GR Mode: ");
11685
11686 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11687 mode = "Helper";
11688 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11689 mode = "Restart";
11690 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11691 mode = "Disable";
11692 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11693 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11694 mode = "Helper*";
11695 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11696 mode = "Restart*";
11697 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11698 mode = "Disable*";
11699 else
11700 mode = "Invalid*";
11701 }
11702
11703 if (use_json) {
11704 json_object_string_add(json, "localGrMode", mode);
11705 } else {
11706 vty_out(vty, mode, "\n");
11707 }
11708 }
11709
11710 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11711 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11712 {
11713 afi_t afi;
11714 safi_t safi;
11715 json_object *json_afi_safi = NULL;
11716 json_object *json_timer = NULL;
11717 json_object *json_endofrib_status = NULL;
11718 bool eor_flag = false;
11719
11720 FOREACH_AFI_SAFI_NSF (afi, safi) {
11721 if (!peer->afc[afi][safi])
11722 continue;
11723
11724 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11725 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11726 continue;
11727
11728 if (use_json) {
11729 json_afi_safi = json_object_new_object();
11730 json_endofrib_status = json_object_new_object();
11731 json_timer = json_object_new_object();
11732 }
11733
11734 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11735 eor_flag = true;
11736 else
11737 eor_flag = false;
11738
11739 if (!use_json) {
11740 vty_out(vty, " %s:\n",
11741 get_afi_safi_str(afi, safi, false));
11742
11743 vty_out(vty, " F bit: ");
11744 }
11745
11746 if (peer->nsf[afi][safi] &&
11747 CHECK_FLAG(peer->af_cap[afi][safi],
11748 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11749
11750 if (use_json) {
11751 json_object_boolean_true_add(json_afi_safi,
11752 "fBit");
11753 } else
11754 vty_out(vty, "True\n");
11755 } else {
11756 if (use_json)
11757 json_object_boolean_false_add(json_afi_safi,
11758 "fBit");
11759 else
11760 vty_out(vty, "False\n");
11761 }
11762
11763 if (!use_json)
11764 vty_out(vty, " End-of-RIB sent: ");
11765
11766 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11767 PEER_STATUS_EOR_SEND)) {
11768 if (use_json) {
11769 json_object_boolean_true_add(
11770 json_endofrib_status, "endOfRibSend");
11771
11772 PRINT_EOR_JSON(eor_flag);
11773 } else {
11774 vty_out(vty, "Yes\n");
11775 vty_out(vty,
11776 " End-of-RIB sent after update: ");
11777
11778 PRINT_EOR(eor_flag);
11779 }
11780 } else {
11781 if (use_json) {
11782 json_object_boolean_false_add(
11783 json_endofrib_status, "endOfRibSend");
11784 json_object_boolean_false_add(
11785 json_endofrib_status,
11786 "endOfRibSentAfterUpdate");
11787 } else {
11788 vty_out(vty, "No\n");
11789 vty_out(vty,
11790 " End-of-RIB sent after update: ");
11791 vty_out(vty, "No\n");
11792 }
11793 }
11794
11795 if (!use_json)
11796 vty_out(vty, " End-of-RIB received: ");
11797
11798 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11799 PEER_STATUS_EOR_RECEIVED)) {
11800 if (use_json)
11801 json_object_boolean_true_add(
11802 json_endofrib_status, "endOfRibRecv");
11803 else
11804 vty_out(vty, "Yes\n");
11805 } else {
11806 if (use_json)
11807 json_object_boolean_false_add(
11808 json_endofrib_status, "endOfRibRecv");
11809 else
11810 vty_out(vty, "No\n");
11811 }
11812
11813 if (use_json) {
11814 json_object_int_add(json_timer, "stalePathTimer",
11815 peer->bgp->stalepath_time);
11816
11817 if (peer->t_gr_stale != NULL) {
11818 json_object_int_add(json_timer,
11819 "stalePathTimerRemaining",
11820 thread_timer_remain_second(
11821 peer->t_gr_stale));
11822 }
11823
11824 /* Display Configured Selection
11825 * Deferral only when when
11826 * Gr mode is enabled.
11827 */
11828 if (CHECK_FLAG(peer->flags,
11829 PEER_FLAG_GRACEFUL_RESTART)) {
11830 json_object_int_add(json_timer,
11831 "selectionDeferralTimer",
11832 peer->bgp->stalepath_time);
11833 }
11834
11835 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11836 NULL) {
11837
11838 json_object_int_add(
11839 json_timer,
11840 "selectionDeferralTimerRemaining",
11841 thread_timer_remain_second(
11842 peer->bgp->gr_info[afi][safi]
11843 .t_select_deferral));
11844 }
11845 } else {
11846 vty_out(vty, " Timers:\n");
11847 vty_out(vty,
11848 " Configured Stale Path Time(sec): %u\n",
11849 peer->bgp->stalepath_time);
11850
11851 if (peer->t_gr_stale != NULL)
11852 vty_out(vty,
11853 " Stale Path Remaining(sec): %ld\n",
11854 thread_timer_remain_second(
11855 peer->t_gr_stale));
11856 /* Display Configured Selection
11857 * Deferral only when when
11858 * Gr mode is enabled.
11859 */
11860 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11861 vty_out(vty,
11862 " Configured Selection Deferral Time(sec): %u\n",
11863 peer->bgp->select_defer_time);
11864
11865 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11866 NULL)
11867 vty_out(vty,
11868 " Selection Deferral Time Remaining(sec): %ld\n",
11869 thread_timer_remain_second(
11870 peer->bgp->gr_info[afi][safi]
11871 .t_select_deferral));
11872 }
11873 if (use_json) {
11874 json_object_object_add(json_afi_safi, "endOfRibStatus",
11875 json_endofrib_status);
11876 json_object_object_add(json_afi_safi, "timers",
11877 json_timer);
11878 json_object_object_add(
11879 json, get_afi_safi_str(afi, safi, true),
11880 json_afi_safi);
11881 }
11882 }
11883 }
11884
11885 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11886 struct peer *p,
11887 bool use_json,
11888 json_object *json)
11889 {
11890 if (use_json) {
11891 json_object *json_timer = NULL;
11892
11893 json_timer = json_object_new_object();
11894
11895 json_object_int_add(json_timer, "configuredRestartTimer",
11896 p->bgp->restart_time);
11897
11898 json_object_int_add(json_timer, "receivedRestartTimer",
11899 p->v_gr_restart);
11900
11901 if (p->t_gr_restart != NULL)
11902 json_object_int_add(
11903 json_timer, "restartTimerRemaining",
11904 thread_timer_remain_second(p->t_gr_restart));
11905
11906 json_object_object_add(json, "timers", json_timer);
11907 } else {
11908
11909 vty_out(vty, " Timers:\n");
11910 vty_out(vty, " Configured Restart Time(sec): %u\n",
11911 p->bgp->restart_time);
11912
11913 vty_out(vty, " Received Restart Time(sec): %u\n",
11914 p->v_gr_restart);
11915 if (p->t_gr_restart != NULL)
11916 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11917 thread_timer_remain_second(p->t_gr_restart));
11918 if (p->t_gr_restart != NULL) {
11919 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11920 thread_timer_remain_second(p->t_gr_restart));
11921 }
11922 }
11923 }
11924
11925 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11926 bool use_json, json_object *json)
11927 {
11928 char dn_flag[2] = {0};
11929 /* '*' + v6 address of neighbor */
11930 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11931
11932 if (!p->conf_if && peer_dynamic_neighbor(p))
11933 dn_flag[0] = '*';
11934
11935 if (p->conf_if) {
11936 if (use_json)
11937 json_object_string_addf(json, "neighborAddr", "%pSU",
11938 &p->su);
11939 else
11940 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11941 &p->su);
11942 } else {
11943 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11944 p->host);
11945
11946 if (use_json)
11947 json_object_string_add(json, "neighborAddr",
11948 neighborAddr);
11949 else
11950 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11951 }
11952
11953 /* more gr info in new format */
11954 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11955 }
11956
11957 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11958 safi_t safi, bool use_json,
11959 json_object *json_neigh)
11960 {
11961 struct bgp_filter *filter;
11962 struct peer_af *paf;
11963 char orf_pfx_name[BUFSIZ];
11964 int orf_pfx_count;
11965 json_object *json_af = NULL;
11966 json_object *json_prefA = NULL;
11967 json_object *json_prefB = NULL;
11968 json_object *json_addr = NULL;
11969 json_object *json_advmap = NULL;
11970
11971 if (use_json) {
11972 json_addr = json_object_new_object();
11973 json_af = json_object_new_object();
11974 filter = &p->filter[afi][safi];
11975
11976 if (peer_group_active(p))
11977 json_object_string_add(json_addr, "peerGroupMember",
11978 p->group->name);
11979
11980 paf = peer_af_find(p, afi, safi);
11981 if (paf && PAF_SUBGRP(paf)) {
11982 json_object_int_add(json_addr, "updateGroupId",
11983 PAF_UPDGRP(paf)->id);
11984 json_object_int_add(json_addr, "subGroupId",
11985 PAF_SUBGRP(paf)->id);
11986 json_object_int_add(json_addr, "packetQueueLength",
11987 bpacket_queue_virtual_length(paf));
11988 }
11989
11990 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11991 || CHECK_FLAG(p->af_cap[afi][safi],
11992 PEER_CAP_ORF_PREFIX_SM_RCV)
11993 || CHECK_FLAG(p->af_cap[afi][safi],
11994 PEER_CAP_ORF_PREFIX_RM_ADV)
11995 || CHECK_FLAG(p->af_cap[afi][safi],
11996 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11997 json_object_int_add(json_af, "orfType",
11998 ORF_TYPE_PREFIX);
11999 json_prefA = json_object_new_object();
12000 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12001 PEER_CAP_ORF_PREFIX_SM_ADV,
12002 PEER_CAP_ORF_PREFIX_RM_ADV,
12003 PEER_CAP_ORF_PREFIX_SM_RCV,
12004 PEER_CAP_ORF_PREFIX_RM_RCV,
12005 use_json, json_prefA);
12006 json_object_object_add(json_af, "orfPrefixList",
12007 json_prefA);
12008 }
12009
12010 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12011 || CHECK_FLAG(p->af_cap[afi][safi],
12012 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12013 || CHECK_FLAG(p->af_cap[afi][safi],
12014 PEER_CAP_ORF_PREFIX_RM_ADV)
12015 || CHECK_FLAG(p->af_cap[afi][safi],
12016 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12017 json_object_int_add(json_af, "orfOldType",
12018 ORF_TYPE_PREFIX_OLD);
12019 json_prefB = json_object_new_object();
12020 bgp_show_peer_afi_orf_cap(
12021 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12022 PEER_CAP_ORF_PREFIX_RM_ADV,
12023 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12024 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12025 json_prefB);
12026 json_object_object_add(json_af, "orfOldPrefixList",
12027 json_prefB);
12028 }
12029
12030 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12031 || CHECK_FLAG(p->af_cap[afi][safi],
12032 PEER_CAP_ORF_PREFIX_SM_RCV)
12033 || CHECK_FLAG(p->af_cap[afi][safi],
12034 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12035 || CHECK_FLAG(p->af_cap[afi][safi],
12036 PEER_CAP_ORF_PREFIX_RM_ADV)
12037 || CHECK_FLAG(p->af_cap[afi][safi],
12038 PEER_CAP_ORF_PREFIX_RM_RCV)
12039 || CHECK_FLAG(p->af_cap[afi][safi],
12040 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12041 json_object_object_add(json_addr, "afDependentCap",
12042 json_af);
12043 else
12044 json_object_free(json_af);
12045
12046 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12047 p->host, afi, safi);
12048 orf_pfx_count = prefix_bgp_show_prefix_list(
12049 NULL, afi, orf_pfx_name, use_json);
12050
12051 if (CHECK_FLAG(p->af_sflags[afi][safi],
12052 PEER_STATUS_ORF_PREFIX_SEND)
12053 || orf_pfx_count) {
12054 if (CHECK_FLAG(p->af_sflags[afi][safi],
12055 PEER_STATUS_ORF_PREFIX_SEND))
12056 json_object_boolean_true_add(json_neigh,
12057 "orfSent");
12058 if (orf_pfx_count)
12059 json_object_int_add(json_addr, "orfRecvCounter",
12060 orf_pfx_count);
12061 }
12062 if (CHECK_FLAG(p->af_sflags[afi][safi],
12063 PEER_STATUS_ORF_WAIT_REFRESH))
12064 json_object_string_add(
12065 json_addr, "orfFirstUpdate",
12066 "deferredUntilORFOrRouteRefreshRecvd");
12067
12068 if (CHECK_FLAG(p->af_flags[afi][safi],
12069 PEER_FLAG_REFLECTOR_CLIENT))
12070 json_object_boolean_true_add(json_addr,
12071 "routeReflectorClient");
12072 if (CHECK_FLAG(p->af_flags[afi][safi],
12073 PEER_FLAG_RSERVER_CLIENT))
12074 json_object_boolean_true_add(json_addr,
12075 "routeServerClient");
12076 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12077 json_object_boolean_true_add(json_addr,
12078 "inboundSoftConfigPermit");
12079
12080 if (CHECK_FLAG(p->af_flags[afi][safi],
12081 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12082 json_object_boolean_true_add(
12083 json_addr,
12084 "privateAsNumsAllReplacedInUpdatesToNbr");
12085 else if (CHECK_FLAG(p->af_flags[afi][safi],
12086 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12087 json_object_boolean_true_add(
12088 json_addr,
12089 "privateAsNumsReplacedInUpdatesToNbr");
12090 else if (CHECK_FLAG(p->af_flags[afi][safi],
12091 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12092 json_object_boolean_true_add(
12093 json_addr,
12094 "privateAsNumsAllRemovedInUpdatesToNbr");
12095 else if (CHECK_FLAG(p->af_flags[afi][safi],
12096 PEER_FLAG_REMOVE_PRIVATE_AS))
12097 json_object_boolean_true_add(
12098 json_addr,
12099 "privateAsNumsRemovedInUpdatesToNbr");
12100
12101 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12102 json_object_boolean_true_add(
12103 json_addr,
12104 bgp_addpath_names(p->addpath_type[afi][safi])
12105 ->type_json_name);
12106
12107 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12108 json_object_string_add(json_addr,
12109 "overrideASNsInOutboundUpdates",
12110 "ifAspathEqualRemoteAs");
12111
12112 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12113 || CHECK_FLAG(p->af_flags[afi][safi],
12114 PEER_FLAG_FORCE_NEXTHOP_SELF))
12115 json_object_boolean_true_add(json_addr,
12116 "routerAlwaysNextHop");
12117 if (CHECK_FLAG(p->af_flags[afi][safi],
12118 PEER_FLAG_AS_PATH_UNCHANGED))
12119 json_object_boolean_true_add(
12120 json_addr, "unchangedAsPathPropogatedToNbr");
12121 if (CHECK_FLAG(p->af_flags[afi][safi],
12122 PEER_FLAG_NEXTHOP_UNCHANGED))
12123 json_object_boolean_true_add(
12124 json_addr, "unchangedNextHopPropogatedToNbr");
12125 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12126 json_object_boolean_true_add(
12127 json_addr, "unchangedMedPropogatedToNbr");
12128 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12129 || CHECK_FLAG(p->af_flags[afi][safi],
12130 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12131 if (CHECK_FLAG(p->af_flags[afi][safi],
12132 PEER_FLAG_SEND_COMMUNITY)
12133 && CHECK_FLAG(p->af_flags[afi][safi],
12134 PEER_FLAG_SEND_EXT_COMMUNITY))
12135 json_object_string_add(json_addr,
12136 "commAttriSentToNbr",
12137 "extendedAndStandard");
12138 else if (CHECK_FLAG(p->af_flags[afi][safi],
12139 PEER_FLAG_SEND_EXT_COMMUNITY))
12140 json_object_string_add(json_addr,
12141 "commAttriSentToNbr",
12142 "extended");
12143 else
12144 json_object_string_add(json_addr,
12145 "commAttriSentToNbr",
12146 "standard");
12147 }
12148 if (CHECK_FLAG(p->af_flags[afi][safi],
12149 PEER_FLAG_DEFAULT_ORIGINATE)) {
12150 if (p->default_rmap[afi][safi].name)
12151 json_object_string_add(
12152 json_addr, "defaultRouteMap",
12153 p->default_rmap[afi][safi].name);
12154
12155 if (paf && PAF_SUBGRP(paf)
12156 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12157 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12158 json_object_boolean_true_add(json_addr,
12159 "defaultSent");
12160 else
12161 json_object_boolean_true_add(json_addr,
12162 "defaultNotSent");
12163 }
12164
12165 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12166 if (is_evpn_enabled())
12167 json_object_boolean_true_add(
12168 json_addr, "advertiseAllVnis");
12169 }
12170
12171 if (filter->plist[FILTER_IN].name
12172 || filter->dlist[FILTER_IN].name
12173 || filter->aslist[FILTER_IN].name
12174 || filter->map[RMAP_IN].name)
12175 json_object_boolean_true_add(json_addr,
12176 "inboundPathPolicyConfig");
12177 if (filter->plist[FILTER_OUT].name
12178 || filter->dlist[FILTER_OUT].name
12179 || filter->aslist[FILTER_OUT].name
12180 || filter->map[RMAP_OUT].name || filter->usmap.name)
12181 json_object_boolean_true_add(
12182 json_addr, "outboundPathPolicyConfig");
12183
12184 /* prefix-list */
12185 if (filter->plist[FILTER_IN].name)
12186 json_object_string_add(json_addr,
12187 "incomingUpdatePrefixFilterList",
12188 filter->plist[FILTER_IN].name);
12189 if (filter->plist[FILTER_OUT].name)
12190 json_object_string_add(json_addr,
12191 "outgoingUpdatePrefixFilterList",
12192 filter->plist[FILTER_OUT].name);
12193
12194 /* distribute-list */
12195 if (filter->dlist[FILTER_IN].name)
12196 json_object_string_add(
12197 json_addr, "incomingUpdateNetworkFilterList",
12198 filter->dlist[FILTER_IN].name);
12199 if (filter->dlist[FILTER_OUT].name)
12200 json_object_string_add(
12201 json_addr, "outgoingUpdateNetworkFilterList",
12202 filter->dlist[FILTER_OUT].name);
12203
12204 /* filter-list. */
12205 if (filter->aslist[FILTER_IN].name)
12206 json_object_string_add(json_addr,
12207 "incomingUpdateAsPathFilterList",
12208 filter->aslist[FILTER_IN].name);
12209 if (filter->aslist[FILTER_OUT].name)
12210 json_object_string_add(json_addr,
12211 "outgoingUpdateAsPathFilterList",
12212 filter->aslist[FILTER_OUT].name);
12213
12214 /* route-map. */
12215 if (filter->map[RMAP_IN].name)
12216 json_object_string_add(
12217 json_addr, "routeMapForIncomingAdvertisements",
12218 filter->map[RMAP_IN].name);
12219 if (filter->map[RMAP_OUT].name)
12220 json_object_string_add(
12221 json_addr, "routeMapForOutgoingAdvertisements",
12222 filter->map[RMAP_OUT].name);
12223
12224 /* ebgp-requires-policy (inbound) */
12225 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12226 && !bgp_inbound_policy_exists(p, filter))
12227 json_object_string_add(
12228 json_addr, "inboundEbgpRequiresPolicy",
12229 "Inbound updates discarded due to missing policy");
12230
12231 /* ebgp-requires-policy (outbound) */
12232 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12233 && (!bgp_outbound_policy_exists(p, filter)))
12234 json_object_string_add(
12235 json_addr, "outboundEbgpRequiresPolicy",
12236 "Outbound updates discarded due to missing policy");
12237
12238 /* unsuppress-map */
12239 if (filter->usmap.name)
12240 json_object_string_add(json_addr,
12241 "selectiveUnsuppressRouteMap",
12242 filter->usmap.name);
12243
12244 /* advertise-map */
12245 if (filter->advmap.aname) {
12246 json_advmap = json_object_new_object();
12247 json_object_string_add(json_advmap, "condition",
12248 filter->advmap.condition
12249 ? "EXIST"
12250 : "NON_EXIST");
12251 json_object_string_add(json_advmap, "conditionMap",
12252 filter->advmap.cname);
12253 json_object_string_add(json_advmap, "advertiseMap",
12254 filter->advmap.aname);
12255 json_object_string_add(
12256 json_advmap, "advertiseStatus",
12257 filter->advmap.update_type ==
12258 UPDATE_TYPE_ADVERTISE
12259 ? "Advertise"
12260 : "Withdraw");
12261 json_object_object_add(json_addr, "advertiseMap",
12262 json_advmap);
12263 }
12264
12265 /* Receive prefix count */
12266 json_object_int_add(json_addr, "acceptedPrefixCounter",
12267 p->pcount[afi][safi]);
12268 if (paf && PAF_SUBGRP(paf))
12269 json_object_int_add(json_addr, "sentPrefixCounter",
12270 (PAF_SUBGRP(paf))->scount);
12271
12272 /* Maximum prefix */
12273 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12274 json_object_int_add(json_addr, "prefixOutAllowedMax",
12275 p->pmax_out[afi][safi]);
12276
12277 /* Maximum prefix */
12278 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12279 json_object_int_add(json_addr, "prefixAllowedMax",
12280 p->pmax[afi][safi]);
12281 if (CHECK_FLAG(p->af_flags[afi][safi],
12282 PEER_FLAG_MAX_PREFIX_WARNING))
12283 json_object_boolean_true_add(
12284 json_addr, "prefixAllowedMaxWarning");
12285 json_object_int_add(json_addr,
12286 "prefixAllowedWarningThresh",
12287 p->pmax_threshold[afi][safi]);
12288 if (p->pmax_restart[afi][safi])
12289 json_object_int_add(
12290 json_addr,
12291 "prefixAllowedRestartIntervalMsecs",
12292 p->pmax_restart[afi][safi] * 60000);
12293 }
12294 json_object_object_add(json_neigh,
12295 get_afi_safi_str(afi, safi, true),
12296 json_addr);
12297
12298 } else {
12299 filter = &p->filter[afi][safi];
12300
12301 vty_out(vty, " For address family: %s\n",
12302 get_afi_safi_str(afi, safi, false));
12303
12304 if (peer_group_active(p))
12305 vty_out(vty, " %s peer-group member\n",
12306 p->group->name);
12307
12308 paf = peer_af_find(p, afi, safi);
12309 if (paf && PAF_SUBGRP(paf)) {
12310 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12311 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12312 vty_out(vty, " Packet Queue length %d\n",
12313 bpacket_queue_virtual_length(paf));
12314 } else {
12315 vty_out(vty, " Not part of any update group\n");
12316 }
12317 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12318 || CHECK_FLAG(p->af_cap[afi][safi],
12319 PEER_CAP_ORF_PREFIX_SM_RCV)
12320 || CHECK_FLAG(p->af_cap[afi][safi],
12321 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12322 || CHECK_FLAG(p->af_cap[afi][safi],
12323 PEER_CAP_ORF_PREFIX_RM_ADV)
12324 || CHECK_FLAG(p->af_cap[afi][safi],
12325 PEER_CAP_ORF_PREFIX_RM_RCV)
12326 || CHECK_FLAG(p->af_cap[afi][safi],
12327 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12328 vty_out(vty, " AF-dependant capabilities:\n");
12329
12330 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12331 || CHECK_FLAG(p->af_cap[afi][safi],
12332 PEER_CAP_ORF_PREFIX_SM_RCV)
12333 || CHECK_FLAG(p->af_cap[afi][safi],
12334 PEER_CAP_ORF_PREFIX_RM_ADV)
12335 || CHECK_FLAG(p->af_cap[afi][safi],
12336 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12337 vty_out(vty,
12338 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12339 ORF_TYPE_PREFIX);
12340 bgp_show_peer_afi_orf_cap(
12341 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12342 PEER_CAP_ORF_PREFIX_RM_ADV,
12343 PEER_CAP_ORF_PREFIX_SM_RCV,
12344 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12345 }
12346 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12347 || CHECK_FLAG(p->af_cap[afi][safi],
12348 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12349 || CHECK_FLAG(p->af_cap[afi][safi],
12350 PEER_CAP_ORF_PREFIX_RM_ADV)
12351 || CHECK_FLAG(p->af_cap[afi][safi],
12352 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12353 vty_out(vty,
12354 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12355 ORF_TYPE_PREFIX_OLD);
12356 bgp_show_peer_afi_orf_cap(
12357 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12358 PEER_CAP_ORF_PREFIX_RM_ADV,
12359 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12360 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12361 }
12362
12363 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12364 p->host, afi, safi);
12365 orf_pfx_count = prefix_bgp_show_prefix_list(
12366 NULL, afi, orf_pfx_name, use_json);
12367
12368 if (CHECK_FLAG(p->af_sflags[afi][safi],
12369 PEER_STATUS_ORF_PREFIX_SEND)
12370 || orf_pfx_count) {
12371 vty_out(vty, " Outbound Route Filter (ORF):");
12372 if (CHECK_FLAG(p->af_sflags[afi][safi],
12373 PEER_STATUS_ORF_PREFIX_SEND))
12374 vty_out(vty, " sent;");
12375 if (orf_pfx_count)
12376 vty_out(vty, " received (%d entries)",
12377 orf_pfx_count);
12378 vty_out(vty, "\n");
12379 }
12380 if (CHECK_FLAG(p->af_sflags[afi][safi],
12381 PEER_STATUS_ORF_WAIT_REFRESH))
12382 vty_out(vty,
12383 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12384
12385 if (CHECK_FLAG(p->af_flags[afi][safi],
12386 PEER_FLAG_REFLECTOR_CLIENT))
12387 vty_out(vty, " Route-Reflector Client\n");
12388 if (CHECK_FLAG(p->af_flags[afi][safi],
12389 PEER_FLAG_RSERVER_CLIENT))
12390 vty_out(vty, " Route-Server Client\n");
12391 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12392 vty_out(vty,
12393 " Inbound soft reconfiguration allowed\n");
12394
12395 if (CHECK_FLAG(p->af_flags[afi][safi],
12396 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12397 vty_out(vty,
12398 " Private AS numbers (all) replaced in updates to this neighbor\n");
12399 else if (CHECK_FLAG(p->af_flags[afi][safi],
12400 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12401 vty_out(vty,
12402 " Private AS numbers replaced in updates to this neighbor\n");
12403 else if (CHECK_FLAG(p->af_flags[afi][safi],
12404 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12405 vty_out(vty,
12406 " Private AS numbers (all) removed in updates to this neighbor\n");
12407 else if (CHECK_FLAG(p->af_flags[afi][safi],
12408 PEER_FLAG_REMOVE_PRIVATE_AS))
12409 vty_out(vty,
12410 " Private AS numbers removed in updates to this neighbor\n");
12411
12412 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12413 vty_out(vty, " %s\n",
12414 bgp_addpath_names(p->addpath_type[afi][safi])
12415 ->human_description);
12416
12417 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12418 vty_out(vty,
12419 " Override ASNs in outbound updates if aspath equals remote-as\n");
12420
12421 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12422 || CHECK_FLAG(p->af_flags[afi][safi],
12423 PEER_FLAG_FORCE_NEXTHOP_SELF))
12424 vty_out(vty, " NEXT_HOP is always this router\n");
12425 if (CHECK_FLAG(p->af_flags[afi][safi],
12426 PEER_FLAG_AS_PATH_UNCHANGED))
12427 vty_out(vty,
12428 " AS_PATH is propagated unchanged to this neighbor\n");
12429 if (CHECK_FLAG(p->af_flags[afi][safi],
12430 PEER_FLAG_NEXTHOP_UNCHANGED))
12431 vty_out(vty,
12432 " NEXT_HOP is propagated unchanged to this neighbor\n");
12433 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12434 vty_out(vty,
12435 " MED is propagated unchanged to this neighbor\n");
12436 if (CHECK_FLAG(p->af_flags[afi][safi], 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,
12442 " Community attribute sent to this neighbor");
12443 if (CHECK_FLAG(p->af_flags[afi][safi],
12444 PEER_FLAG_SEND_COMMUNITY)
12445 && CHECK_FLAG(p->af_flags[afi][safi],
12446 PEER_FLAG_SEND_EXT_COMMUNITY)
12447 && CHECK_FLAG(p->af_flags[afi][safi],
12448 PEER_FLAG_SEND_LARGE_COMMUNITY))
12449 vty_out(vty, "(all)\n");
12450 else if (CHECK_FLAG(p->af_flags[afi][safi],
12451 PEER_FLAG_SEND_LARGE_COMMUNITY))
12452 vty_out(vty, "(large)\n");
12453 else if (CHECK_FLAG(p->af_flags[afi][safi],
12454 PEER_FLAG_SEND_EXT_COMMUNITY))
12455 vty_out(vty, "(extended)\n");
12456 else
12457 vty_out(vty, "(standard)\n");
12458 }
12459 if (CHECK_FLAG(p->af_flags[afi][safi],
12460 PEER_FLAG_DEFAULT_ORIGINATE)) {
12461 vty_out(vty, " Default information originate,");
12462
12463 if (p->default_rmap[afi][safi].name)
12464 vty_out(vty, " default route-map %s%s,",
12465 p->default_rmap[afi][safi].map ? "*"
12466 : "",
12467 p->default_rmap[afi][safi].name);
12468 if (paf && PAF_SUBGRP(paf)
12469 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12470 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12471 vty_out(vty, " default sent\n");
12472 else
12473 vty_out(vty, " default not sent\n");
12474 }
12475
12476 /* advertise-vni-all */
12477 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12478 if (is_evpn_enabled())
12479 vty_out(vty, " advertise-all-vni\n");
12480 }
12481
12482 if (filter->plist[FILTER_IN].name
12483 || filter->dlist[FILTER_IN].name
12484 || filter->aslist[FILTER_IN].name
12485 || filter->map[RMAP_IN].name)
12486 vty_out(vty, " Inbound path policy configured\n");
12487 if (filter->plist[FILTER_OUT].name
12488 || filter->dlist[FILTER_OUT].name
12489 || filter->aslist[FILTER_OUT].name
12490 || filter->map[RMAP_OUT].name || filter->usmap.name)
12491 vty_out(vty, " Outbound path policy configured\n");
12492
12493 /* prefix-list */
12494 if (filter->plist[FILTER_IN].name)
12495 vty_out(vty,
12496 " Incoming update prefix filter list is %s%s\n",
12497 filter->plist[FILTER_IN].plist ? "*" : "",
12498 filter->plist[FILTER_IN].name);
12499 if (filter->plist[FILTER_OUT].name)
12500 vty_out(vty,
12501 " Outgoing update prefix filter list is %s%s\n",
12502 filter->plist[FILTER_OUT].plist ? "*" : "",
12503 filter->plist[FILTER_OUT].name);
12504
12505 /* distribute-list */
12506 if (filter->dlist[FILTER_IN].name)
12507 vty_out(vty,
12508 " Incoming update network filter list is %s%s\n",
12509 filter->dlist[FILTER_IN].alist ? "*" : "",
12510 filter->dlist[FILTER_IN].name);
12511 if (filter->dlist[FILTER_OUT].name)
12512 vty_out(vty,
12513 " Outgoing update network filter list is %s%s\n",
12514 filter->dlist[FILTER_OUT].alist ? "*" : "",
12515 filter->dlist[FILTER_OUT].name);
12516
12517 /* filter-list. */
12518 if (filter->aslist[FILTER_IN].name)
12519 vty_out(vty,
12520 " Incoming update AS path filter list is %s%s\n",
12521 filter->aslist[FILTER_IN].aslist ? "*" : "",
12522 filter->aslist[FILTER_IN].name);
12523 if (filter->aslist[FILTER_OUT].name)
12524 vty_out(vty,
12525 " Outgoing update AS path filter list is %s%s\n",
12526 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12527 filter->aslist[FILTER_OUT].name);
12528
12529 /* route-map. */
12530 if (filter->map[RMAP_IN].name)
12531 vty_out(vty,
12532 " Route map for incoming advertisements is %s%s\n",
12533 filter->map[RMAP_IN].map ? "*" : "",
12534 filter->map[RMAP_IN].name);
12535 if (filter->map[RMAP_OUT].name)
12536 vty_out(vty,
12537 " Route map for outgoing advertisements is %s%s\n",
12538 filter->map[RMAP_OUT].map ? "*" : "",
12539 filter->map[RMAP_OUT].name);
12540
12541 /* ebgp-requires-policy (inbound) */
12542 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12543 && !bgp_inbound_policy_exists(p, filter))
12544 vty_out(vty,
12545 " Inbound updates discarded due to missing policy\n");
12546
12547 /* ebgp-requires-policy (outbound) */
12548 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12549 && !bgp_outbound_policy_exists(p, filter))
12550 vty_out(vty,
12551 " Outbound updates discarded due to missing policy\n");
12552
12553 /* unsuppress-map */
12554 if (filter->usmap.name)
12555 vty_out(vty,
12556 " Route map for selective unsuppress is %s%s\n",
12557 filter->usmap.map ? "*" : "",
12558 filter->usmap.name);
12559
12560 /* advertise-map */
12561 if (filter->advmap.aname && filter->advmap.cname)
12562 vty_out(vty,
12563 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12564 filter->advmap.condition ? "EXIST"
12565 : "NON_EXIST",
12566 filter->advmap.cmap ? "*" : "",
12567 filter->advmap.cname,
12568 filter->advmap.amap ? "*" : "",
12569 filter->advmap.aname,
12570 filter->advmap.update_type ==
12571 UPDATE_TYPE_ADVERTISE
12572 ? "Advertise"
12573 : "Withdraw");
12574
12575 /* Receive prefix count */
12576 vty_out(vty, " %u accepted prefixes\n",
12577 p->pcount[afi][safi]);
12578
12579 /* maximum-prefix-out */
12580 if (CHECK_FLAG(p->af_flags[afi][safi],
12581 PEER_FLAG_MAX_PREFIX_OUT))
12582 vty_out(vty,
12583 " Maximum allowed prefixes sent %u\n",
12584 p->pmax_out[afi][safi]);
12585
12586 /* Maximum prefix */
12587 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12588 vty_out(vty,
12589 " Maximum prefixes allowed %u%s\n",
12590 p->pmax[afi][safi],
12591 CHECK_FLAG(p->af_flags[afi][safi],
12592 PEER_FLAG_MAX_PREFIX_WARNING)
12593 ? " (warning-only)"
12594 : "");
12595 vty_out(vty, " Threshold for warning message %d%%",
12596 p->pmax_threshold[afi][safi]);
12597 if (p->pmax_restart[afi][safi])
12598 vty_out(vty, ", restart interval %d min",
12599 p->pmax_restart[afi][safi]);
12600 vty_out(vty, "\n");
12601 }
12602
12603 vty_out(vty, "\n");
12604 }
12605 }
12606
12607 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12608 json_object *json)
12609 {
12610 struct bgp *bgp;
12611 char buf1[PREFIX2STR_BUFFER];
12612 char timebuf[BGP_UPTIME_LEN];
12613 char dn_flag[2];
12614 afi_t afi;
12615 safi_t safi;
12616 uint16_t i;
12617 uint8_t *msg;
12618 json_object *json_neigh = NULL;
12619 time_t epoch_tbuf;
12620 uint32_t sync_tcp_mss;
12621
12622 bgp = p->bgp;
12623
12624 if (use_json)
12625 json_neigh = json_object_new_object();
12626
12627 memset(dn_flag, '\0', sizeof(dn_flag));
12628 if (!p->conf_if && peer_dynamic_neighbor(p))
12629 dn_flag[0] = '*';
12630
12631 if (!use_json) {
12632 if (p->conf_if) /* Configured interface name. */
12633 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12634 &p->su);
12635 else /* Configured IP address. */
12636 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12637 p->host);
12638 }
12639
12640 if (use_json) {
12641 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12642 json_object_string_add(json_neigh, "bgpNeighborAddr",
12643 "none");
12644 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12645 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12646 "%pSU", &p->su);
12647
12648 json_object_int_add(json_neigh, "remoteAs", p->as);
12649
12650 if (p->change_local_as)
12651 json_object_int_add(json_neigh, "localAs",
12652 p->change_local_as);
12653 else
12654 json_object_int_add(json_neigh, "localAs", p->local_as);
12655
12656 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12657 json_object_boolean_true_add(json_neigh,
12658 "localAsNoPrepend");
12659
12660 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12661 json_object_boolean_true_add(json_neigh,
12662 "localAsReplaceAs");
12663 } else {
12664 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12665 || (p->as_type == AS_INTERNAL))
12666 vty_out(vty, "remote AS %u, ", p->as);
12667 else
12668 vty_out(vty, "remote AS Unspecified, ");
12669 vty_out(vty, "local AS %u%s%s, ",
12670 p->change_local_as ? p->change_local_as : p->local_as,
12671 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12672 ? " no-prepend"
12673 : "",
12674 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12675 ? " replace-as"
12676 : "");
12677 }
12678 /* peer type internal or confed-internal */
12679 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12680 if (use_json) {
12681 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12682 json_object_boolean_true_add(
12683 json_neigh, "nbrConfedInternalLink");
12684 else
12685 json_object_boolean_true_add(json_neigh,
12686 "nbrInternalLink");
12687 } else {
12688 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12689 vty_out(vty, "confed-internal link\n");
12690 else
12691 vty_out(vty, "internal link\n");
12692 }
12693 /* peer type external or confed-external */
12694 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12695 if (use_json) {
12696 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12697 json_object_boolean_true_add(
12698 json_neigh, "nbrConfedExternalLink");
12699 else
12700 json_object_boolean_true_add(json_neigh,
12701 "nbrExternalLink");
12702 } else {
12703 if (bgp_confederation_peers_check(bgp, p->as))
12704 vty_out(vty, "confed-external link\n");
12705 else
12706 vty_out(vty, "external link\n");
12707 }
12708 } else {
12709 if (use_json)
12710 json_object_boolean_true_add(json_neigh,
12711 "nbrUnspecifiedLink");
12712 else
12713 vty_out(vty, "unspecified link\n");
12714 }
12715
12716 /* Roles */
12717 if (use_json) {
12718 json_object_string_add(json_neigh, "localRole",
12719 bgp_get_name_by_role(p->local_role));
12720 json_object_string_add(json_neigh, "remoteRole",
12721 bgp_get_name_by_role(p->remote_role));
12722 } else {
12723 vty_out(vty, " Local Role: %s\n",
12724 bgp_get_name_by_role(p->local_role));
12725 vty_out(vty, " Remote Role: %s\n",
12726 bgp_get_name_by_role(p->remote_role));
12727 }
12728
12729
12730 /* Description. */
12731 if (p->desc) {
12732 if (use_json)
12733 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12734 else
12735 vty_out(vty, " Description: %s\n", p->desc);
12736 }
12737
12738 if (p->hostname) {
12739 if (use_json) {
12740 if (p->hostname)
12741 json_object_string_add(json_neigh, "hostname",
12742 p->hostname);
12743
12744 if (p->domainname)
12745 json_object_string_add(json_neigh, "domainname",
12746 p->domainname);
12747 } else {
12748 if (p->domainname && (p->domainname[0] != '\0'))
12749 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12750 p->domainname);
12751 else
12752 vty_out(vty, "Hostname: %s\n", p->hostname);
12753 }
12754 }
12755
12756 /* Peer-group */
12757 if (p->group) {
12758 if (use_json) {
12759 json_object_string_add(json_neigh, "peerGroup",
12760 p->group->name);
12761
12762 if (dn_flag[0]) {
12763 struct prefix prefix, *range = NULL;
12764
12765 if (sockunion2hostprefix(&(p->su), &prefix))
12766 range = peer_group_lookup_dynamic_neighbor_range(
12767 p->group, &prefix);
12768
12769 if (range) {
12770 json_object_string_addf(
12771 json_neigh,
12772 "peerSubnetRangeGroup", "%pFX",
12773 range);
12774 }
12775 }
12776 } else {
12777 vty_out(vty,
12778 " Member of peer-group %s for session parameters\n",
12779 p->group->name);
12780
12781 if (dn_flag[0]) {
12782 struct prefix prefix, *range = NULL;
12783
12784 if (sockunion2hostprefix(&(p->su), &prefix))
12785 range = peer_group_lookup_dynamic_neighbor_range(
12786 p->group, &prefix);
12787
12788 if (range) {
12789 vty_out(vty,
12790 " Belongs to the subnet range group: %pFX\n",
12791 range);
12792 }
12793 }
12794 }
12795 }
12796
12797 if (use_json) {
12798 /* Administrative shutdown. */
12799 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12800 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12801 json_object_boolean_true_add(json_neigh,
12802 "adminShutDown");
12803
12804 /* BGP Version. */
12805 json_object_int_add(json_neigh, "bgpVersion", 4);
12806 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12807 &p->remote_id);
12808 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12809 &bgp->router_id);
12810
12811 /* Confederation */
12812 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12813 && bgp_confederation_peers_check(bgp, p->as))
12814 json_object_boolean_true_add(json_neigh,
12815 "nbrCommonAdmin");
12816
12817 /* Status. */
12818 json_object_string_add(
12819 json_neigh, "bgpState",
12820 lookup_msg(bgp_status_msg, p->status, NULL));
12821
12822 if (peer_established(p)) {
12823 time_t uptime;
12824
12825 uptime = monotime(NULL);
12826 uptime -= p->uptime;
12827 epoch_tbuf = time(NULL) - uptime;
12828
12829 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12830 uptime * 1000);
12831 json_object_string_add(json_neigh, "bgpTimerUpString",
12832 peer_uptime(p->uptime, timebuf,
12833 BGP_UPTIME_LEN, 0,
12834 NULL));
12835 json_object_int_add(json_neigh,
12836 "bgpTimerUpEstablishedEpoch",
12837 epoch_tbuf);
12838 }
12839
12840 else if (p->status == Active) {
12841 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12842 json_object_string_add(json_neigh, "bgpStateIs",
12843 "passive");
12844 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12845 json_object_string_add(json_neigh, "bgpStateIs",
12846 "passiveNSF");
12847 }
12848
12849 /* read timer */
12850 time_t uptime;
12851 struct tm tm;
12852
12853 uptime = monotime(NULL);
12854 uptime -= p->readtime;
12855 gmtime_r(&uptime, &tm);
12856
12857 json_object_int_add(json_neigh, "bgpTimerLastRead",
12858 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12859 + (tm.tm_hour * 3600000));
12860
12861 uptime = monotime(NULL);
12862 uptime -= p->last_write;
12863 gmtime_r(&uptime, &tm);
12864
12865 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12866 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12867 + (tm.tm_hour * 3600000));
12868
12869 uptime = monotime(NULL);
12870 uptime -= p->update_time;
12871 gmtime_r(&uptime, &tm);
12872
12873 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12874 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12875 + (tm.tm_hour * 3600000));
12876
12877 /* Configured timer values. */
12878 json_object_int_add(json_neigh,
12879 "bgpTimerConfiguredHoldTimeMsecs",
12880 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12881 ? p->holdtime * 1000
12882 : bgp->default_holdtime * 1000);
12883 json_object_int_add(json_neigh,
12884 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12885 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12886 ? p->keepalive * 1000
12887 : bgp->default_keepalive * 1000);
12888 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12889 p->v_holdtime * 1000);
12890 json_object_int_add(json_neigh,
12891 "bgpTimerKeepAliveIntervalMsecs",
12892 p->v_keepalive * 1000);
12893 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12894 json_object_int_add(json_neigh,
12895 "bgpTimerDelayOpenTimeMsecs",
12896 p->v_delayopen * 1000);
12897 }
12898
12899 /* Configured and Synced tcp-mss value for peer */
12900 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12901 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12902 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12903 p->tcp_mss);
12904 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12905 sync_tcp_mss);
12906 }
12907
12908 /* Extended Optional Parameters Length for BGP OPEN Message */
12909 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12910 json_object_boolean_true_add(
12911 json_neigh, "extendedOptionalParametersLength");
12912 else
12913 json_object_boolean_false_add(
12914 json_neigh, "extendedOptionalParametersLength");
12915
12916 /* Conditional advertisements */
12917 json_object_int_add(
12918 json_neigh,
12919 "bgpTimerConfiguredConditionalAdvertisementsSec",
12920 bgp->condition_check_period);
12921 if (thread_is_scheduled(bgp->t_condition_check))
12922 json_object_int_add(
12923 json_neigh,
12924 "bgpTimerUntilConditionalAdvertisementsSec",
12925 thread_timer_remain_second(
12926 bgp->t_condition_check));
12927 } else {
12928 /* Administrative shutdown. */
12929 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12930 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12931 vty_out(vty, " Administratively shut down\n");
12932
12933 /* BGP Version. */
12934 vty_out(vty, " BGP version 4");
12935 vty_out(vty, ", remote router ID %s",
12936 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12937 vty_out(vty, ", local router ID %s\n",
12938 inet_ntop(AF_INET, &bgp->router_id, buf1,
12939 sizeof(buf1)));
12940
12941 /* Confederation */
12942 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12943 && bgp_confederation_peers_check(bgp, p->as))
12944 vty_out(vty,
12945 " Neighbor under common administration\n");
12946
12947 /* Status. */
12948 vty_out(vty, " BGP state = %s",
12949 lookup_msg(bgp_status_msg, p->status, NULL));
12950
12951 if (peer_established(p))
12952 vty_out(vty, ", up for %8s",
12953 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12954 0, NULL));
12955
12956 else if (p->status == Active) {
12957 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12958 vty_out(vty, " (passive)");
12959 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12960 vty_out(vty, " (NSF passive)");
12961 }
12962 vty_out(vty, "\n");
12963
12964 /* read timer */
12965 vty_out(vty, " Last read %s",
12966 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12967 NULL));
12968 vty_out(vty, ", Last write %s\n",
12969 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12970 NULL));
12971
12972 /* Configured timer values. */
12973 vty_out(vty,
12974 " Hold time is %d seconds, keepalive interval is %d seconds\n",
12975 p->v_holdtime, p->v_keepalive);
12976 vty_out(vty, " Configured hold time is %d seconds",
12977 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12978 ? p->holdtime
12979 : bgp->default_holdtime);
12980 vty_out(vty, ", keepalive interval is %d seconds\n",
12981 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12982 ? p->keepalive
12983 : bgp->default_keepalive);
12984 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12985 vty_out(vty,
12986 " Configured DelayOpenTime is %d seconds\n",
12987 p->delayopen);
12988
12989 /* Configured and synced tcp-mss value for peer */
12990 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12991 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12992 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12993 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12994 }
12995
12996 /* Extended Optional Parameters Length for BGP OPEN Message */
12997 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12998 vty_out(vty,
12999 " Extended Optional Parameters Length is enabled\n");
13000
13001 /* Conditional advertisements */
13002 vty_out(vty,
13003 " Configured conditional advertisements interval is %d seconds\n",
13004 bgp->condition_check_period);
13005 if (thread_is_scheduled(bgp->t_condition_check))
13006 vty_out(vty,
13007 " Time until conditional advertisements begin is %lu seconds\n",
13008 thread_timer_remain_second(
13009 bgp->t_condition_check));
13010 }
13011 /* Capability. */
13012 if (peer_established(p) &&
13013 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13014 if (use_json) {
13015 json_object *json_cap = NULL;
13016
13017 json_cap = json_object_new_object();
13018
13019 /* AS4 */
13020 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13021 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13022 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13023 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13024 json_object_string_add(
13025 json_cap, "4byteAs",
13026 "advertisedAndReceived");
13027 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13028 json_object_string_add(json_cap,
13029 "4byteAs",
13030 "advertised");
13031 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13032 json_object_string_add(json_cap,
13033 "4byteAs",
13034 "received");
13035 }
13036
13037 /* Extended Message Support */
13038 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13039 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13040 json_object_string_add(json_cap,
13041 "extendedMessage",
13042 "advertisedAndReceived");
13043 else if (CHECK_FLAG(p->cap,
13044 PEER_CAP_EXTENDED_MESSAGE_ADV))
13045 json_object_string_add(json_cap,
13046 "extendedMessage",
13047 "advertised");
13048 else if (CHECK_FLAG(p->cap,
13049 PEER_CAP_EXTENDED_MESSAGE_RCV))
13050 json_object_string_add(json_cap,
13051 "extendedMessage",
13052 "received");
13053
13054 /* AddPath */
13055 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13056 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13057 json_object *json_add = NULL;
13058 const char *print_store;
13059
13060 json_add = json_object_new_object();
13061
13062 FOREACH_AFI_SAFI (afi, safi) {
13063 json_object *json_sub = NULL;
13064 json_sub = json_object_new_object();
13065 print_store = get_afi_safi_str(
13066 afi, safi, true);
13067
13068 if (CHECK_FLAG(
13069 p->af_cap[afi][safi],
13070 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13071 CHECK_FLAG(
13072 p->af_cap[afi][safi],
13073 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13074 if (CHECK_FLAG(
13075 p->af_cap[afi]
13076 [safi],
13077 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13078 CHECK_FLAG(
13079 p->af_cap[afi]
13080 [safi],
13081 PEER_CAP_ADDPATH_AF_TX_RCV))
13082 json_object_boolean_true_add(
13083 json_sub,
13084 "txAdvertisedAndReceived");
13085 else if (
13086 CHECK_FLAG(
13087 p->af_cap[afi]
13088 [safi],
13089 PEER_CAP_ADDPATH_AF_TX_ADV))
13090 json_object_boolean_true_add(
13091 json_sub,
13092 "txAdvertised");
13093 else if (
13094 CHECK_FLAG(
13095 p->af_cap[afi]
13096 [safi],
13097 PEER_CAP_ADDPATH_AF_TX_RCV))
13098 json_object_boolean_true_add(
13099 json_sub,
13100 "txReceived");
13101 }
13102
13103 if (CHECK_FLAG(
13104 p->af_cap[afi][safi],
13105 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13106 CHECK_FLAG(
13107 p->af_cap[afi][safi],
13108 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13109 if (CHECK_FLAG(
13110 p->af_cap[afi]
13111 [safi],
13112 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13113 CHECK_FLAG(
13114 p->af_cap[afi]
13115 [safi],
13116 PEER_CAP_ADDPATH_AF_RX_RCV))
13117 json_object_boolean_true_add(
13118 json_sub,
13119 "rxAdvertisedAndReceived");
13120 else if (
13121 CHECK_FLAG(
13122 p->af_cap[afi]
13123 [safi],
13124 PEER_CAP_ADDPATH_AF_RX_ADV))
13125 json_object_boolean_true_add(
13126 json_sub,
13127 "rxAdvertised");
13128 else if (
13129 CHECK_FLAG(
13130 p->af_cap[afi]
13131 [safi],
13132 PEER_CAP_ADDPATH_AF_RX_RCV))
13133 json_object_boolean_true_add(
13134 json_sub,
13135 "rxReceived");
13136 }
13137
13138 if (CHECK_FLAG(
13139 p->af_cap[afi][safi],
13140 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13141 CHECK_FLAG(
13142 p->af_cap[afi][safi],
13143 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13144 CHECK_FLAG(
13145 p->af_cap[afi][safi],
13146 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13147 CHECK_FLAG(
13148 p->af_cap[afi][safi],
13149 PEER_CAP_ADDPATH_AF_RX_RCV))
13150 json_object_object_add(
13151 json_add, print_store,
13152 json_sub);
13153 else
13154 json_object_free(json_sub);
13155 }
13156
13157 json_object_object_add(json_cap, "addPath",
13158 json_add);
13159 }
13160
13161 /* Dynamic */
13162 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13163 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13164 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13165 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13166 json_object_string_add(
13167 json_cap, "dynamic",
13168 "advertisedAndReceived");
13169 else if (CHECK_FLAG(p->cap,
13170 PEER_CAP_DYNAMIC_ADV))
13171 json_object_string_add(json_cap,
13172 "dynamic",
13173 "advertised");
13174 else if (CHECK_FLAG(p->cap,
13175 PEER_CAP_DYNAMIC_RCV))
13176 json_object_string_add(json_cap,
13177 "dynamic",
13178 "received");
13179 }
13180
13181 /* Role */
13182 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13183 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13184 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13185 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13186 json_object_string_add(
13187 json_cap, "role",
13188 "advertisedAndReceived");
13189 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13190 json_object_string_add(json_cap, "role",
13191 "advertised");
13192 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13193 json_object_string_add(json_cap, "role",
13194 "received");
13195 }
13196
13197 /* Extended nexthop */
13198 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13199 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13200 json_object *json_nxt = NULL;
13201 const char *print_store;
13202
13203
13204 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13205 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13206 json_object_string_add(
13207 json_cap, "extendedNexthop",
13208 "advertisedAndReceived");
13209 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13210 json_object_string_add(
13211 json_cap, "extendedNexthop",
13212 "advertised");
13213 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13214 json_object_string_add(
13215 json_cap, "extendedNexthop",
13216 "received");
13217
13218 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13219 json_nxt = json_object_new_object();
13220
13221 for (safi = SAFI_UNICAST;
13222 safi < SAFI_MAX; safi++) {
13223 if (CHECK_FLAG(
13224 p->af_cap[AFI_IP]
13225 [safi],
13226 PEER_CAP_ENHE_AF_RCV)) {
13227 print_store =
13228 get_afi_safi_str(
13229 AFI_IP,
13230 safi,
13231 true);
13232 json_object_string_add(
13233 json_nxt,
13234 print_store,
13235 "recieved"); /* misspelled for compatibility */
13236 }
13237 }
13238 json_object_object_add(
13239 json_cap,
13240 "extendedNexthopFamililesByPeer",
13241 json_nxt);
13242 }
13243 }
13244
13245 /* Long-lived Graceful Restart */
13246 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13247 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13248 json_object *json_llgr = NULL;
13249 const char *afi_safi_str;
13250
13251 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13252 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13253 json_object_string_add(
13254 json_cap,
13255 "longLivedGracefulRestart",
13256 "advertisedAndReceived");
13257 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13258 json_object_string_add(
13259 json_cap,
13260 "longLivedGracefulRestart",
13261 "advertised");
13262 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13263 json_object_string_add(
13264 json_cap,
13265 "longLivedGracefulRestart",
13266 "received");
13267
13268 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13269 json_llgr = json_object_new_object();
13270
13271 FOREACH_AFI_SAFI (afi, safi) {
13272 if (CHECK_FLAG(
13273 p->af_cap[afi]
13274 [safi],
13275 PEER_CAP_ENHE_AF_RCV)) {
13276 afi_safi_str =
13277 get_afi_safi_str(
13278 afi,
13279 safi,
13280 true);
13281 json_object_string_add(
13282 json_llgr,
13283 afi_safi_str,
13284 "received");
13285 }
13286 }
13287 json_object_object_add(
13288 json_cap,
13289 "longLivedGracefulRestartByPeer",
13290 json_llgr);
13291 }
13292 }
13293
13294 /* Route Refresh */
13295 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13296 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13297 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13298 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13299 (CHECK_FLAG(p->cap,
13300 PEER_CAP_REFRESH_NEW_RCV) ||
13301 CHECK_FLAG(p->cap,
13302 PEER_CAP_REFRESH_OLD_RCV))) {
13303 if (CHECK_FLAG(
13304 p->cap,
13305 PEER_CAP_REFRESH_OLD_RCV) &&
13306 CHECK_FLAG(
13307 p->cap,
13308 PEER_CAP_REFRESH_NEW_RCV))
13309 json_object_string_add(
13310 json_cap,
13311 "routeRefresh",
13312 "advertisedAndReceivedOldNew");
13313 else {
13314 if (CHECK_FLAG(
13315 p->cap,
13316 PEER_CAP_REFRESH_OLD_RCV))
13317 json_object_string_add(
13318 json_cap,
13319 "routeRefresh",
13320 "advertisedAndReceivedOld");
13321 else
13322 json_object_string_add(
13323 json_cap,
13324 "routeRefresh",
13325 "advertisedAndReceivedNew");
13326 }
13327 } else if (CHECK_FLAG(p->cap,
13328 PEER_CAP_REFRESH_ADV))
13329 json_object_string_add(json_cap,
13330 "routeRefresh",
13331 "advertised");
13332 else if (CHECK_FLAG(p->cap,
13333 PEER_CAP_REFRESH_NEW_RCV) ||
13334 CHECK_FLAG(p->cap,
13335 PEER_CAP_REFRESH_OLD_RCV))
13336 json_object_string_add(json_cap,
13337 "routeRefresh",
13338 "received");
13339 }
13340
13341 /* Enhanced Route Refresh */
13342 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13343 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13344 if (CHECK_FLAG(p->cap,
13345 PEER_CAP_ENHANCED_RR_ADV) &&
13346 CHECK_FLAG(p->cap,
13347 PEER_CAP_ENHANCED_RR_RCV))
13348 json_object_string_add(
13349 json_cap,
13350 "enhancedRouteRefresh",
13351 "advertisedAndReceived");
13352 else if (CHECK_FLAG(p->cap,
13353 PEER_CAP_ENHANCED_RR_ADV))
13354 json_object_string_add(
13355 json_cap,
13356 "enhancedRouteRefresh",
13357 "advertised");
13358 else if (CHECK_FLAG(p->cap,
13359 PEER_CAP_ENHANCED_RR_RCV))
13360 json_object_string_add(
13361 json_cap,
13362 "enhancedRouteRefresh",
13363 "received");
13364 }
13365
13366 /* Multiprotocol Extensions */
13367 json_object *json_multi = NULL;
13368
13369 json_multi = json_object_new_object();
13370
13371 FOREACH_AFI_SAFI (afi, safi) {
13372 if (p->afc_adv[afi][safi] ||
13373 p->afc_recv[afi][safi]) {
13374 json_object *json_exten = NULL;
13375 json_exten = json_object_new_object();
13376
13377 if (p->afc_adv[afi][safi] &&
13378 p->afc_recv[afi][safi])
13379 json_object_boolean_true_add(
13380 json_exten,
13381 "advertisedAndReceived");
13382 else if (p->afc_adv[afi][safi])
13383 json_object_boolean_true_add(
13384 json_exten,
13385 "advertised");
13386 else if (p->afc_recv[afi][safi])
13387 json_object_boolean_true_add(
13388 json_exten, "received");
13389
13390 json_object_object_add(
13391 json_multi,
13392 get_afi_safi_str(afi, safi,
13393 true),
13394 json_exten);
13395 }
13396 }
13397 json_object_object_add(json_cap,
13398 "multiprotocolExtensions",
13399 json_multi);
13400
13401 /* Hostname capabilities */
13402 json_object *json_hname = NULL;
13403
13404 json_hname = json_object_new_object();
13405
13406 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13407 json_object_string_add(
13408 json_hname, "advHostName",
13409 bgp->peer_self->hostname
13410 ? bgp->peer_self->hostname
13411 : "n/a");
13412 json_object_string_add(
13413 json_hname, "advDomainName",
13414 bgp->peer_self->domainname
13415 ? bgp->peer_self->domainname
13416 : "n/a");
13417 }
13418
13419
13420 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13421 json_object_string_add(
13422 json_hname, "rcvHostName",
13423 p->hostname ? p->hostname : "n/a");
13424 json_object_string_add(
13425 json_hname, "rcvDomainName",
13426 p->domainname ? p->domainname : "n/a");
13427 }
13428
13429 json_object_object_add(json_cap, "hostName",
13430 json_hname);
13431
13432 /* Graceful Restart */
13433 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13434 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13435 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13436 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13437 json_object_string_add(
13438 json_cap, "gracefulRestart",
13439 "advertisedAndReceived");
13440 else if (CHECK_FLAG(p->cap,
13441 PEER_CAP_RESTART_ADV))
13442 json_object_string_add(
13443 json_cap,
13444 "gracefulRestartCapability",
13445 "advertised");
13446 else if (CHECK_FLAG(p->cap,
13447 PEER_CAP_RESTART_RCV))
13448 json_object_string_add(
13449 json_cap,
13450 "gracefulRestartCapability",
13451 "received");
13452
13453 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13454 int restart_af_count = 0;
13455 json_object *json_restart = NULL;
13456 json_restart = json_object_new_object();
13457
13458 json_object_int_add(
13459 json_cap,
13460 "gracefulRestartRemoteTimerMsecs",
13461 p->v_gr_restart * 1000);
13462
13463 FOREACH_AFI_SAFI (afi, safi) {
13464 if (CHECK_FLAG(
13465 p->af_cap[afi]
13466 [safi],
13467 PEER_CAP_RESTART_AF_RCV)) {
13468 json_object *json_sub =
13469 NULL;
13470 json_sub =
13471 json_object_new_object();
13472
13473 if (CHECK_FLAG(
13474 p->af_cap
13475 [afi]
13476 [safi],
13477 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13478 json_object_boolean_true_add(
13479 json_sub,
13480 "preserved");
13481 restart_af_count++;
13482 json_object_object_add(
13483 json_restart,
13484 get_afi_safi_str(
13485 afi,
13486 safi,
13487 true),
13488 json_sub);
13489 }
13490 }
13491 if (!restart_af_count) {
13492 json_object_string_add(
13493 json_cap,
13494 "addressFamiliesByPeer",
13495 "none");
13496 json_object_free(json_restart);
13497 } else
13498 json_object_object_add(
13499 json_cap,
13500 "addressFamiliesByPeer",
13501 json_restart);
13502 }
13503 }
13504 json_object_object_add(
13505 json_neigh, "neighborCapabilities", json_cap);
13506 } else {
13507 vty_out(vty, " Neighbor capabilities:\n");
13508
13509 /* AS4 */
13510 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13511 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13512 vty_out(vty, " 4 Byte AS:");
13513 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13514 vty_out(vty, " advertised");
13515 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13516 vty_out(vty, " %sreceived",
13517 CHECK_FLAG(p->cap,
13518 PEER_CAP_AS4_ADV)
13519 ? "and "
13520 : "");
13521 vty_out(vty, "\n");
13522 }
13523
13524 /* Extended Message Support */
13525 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13526 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13527 vty_out(vty, " Extended Message:");
13528 if (CHECK_FLAG(p->cap,
13529 PEER_CAP_EXTENDED_MESSAGE_ADV))
13530 vty_out(vty, " advertised");
13531 if (CHECK_FLAG(p->cap,
13532 PEER_CAP_EXTENDED_MESSAGE_RCV))
13533 vty_out(vty, " %sreceived",
13534 CHECK_FLAG(
13535 p->cap,
13536 PEER_CAP_EXTENDED_MESSAGE_ADV)
13537 ? "and "
13538 : "");
13539 vty_out(vty, "\n");
13540 }
13541
13542 /* AddPath */
13543 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13544 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13545 vty_out(vty, " AddPath:\n");
13546
13547 FOREACH_AFI_SAFI (afi, safi) {
13548 if (CHECK_FLAG(
13549 p->af_cap[afi][safi],
13550 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13551 CHECK_FLAG(
13552 p->af_cap[afi][safi],
13553 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13554 vty_out(vty, " %s: TX ",
13555 get_afi_safi_str(
13556 afi, safi,
13557 false));
13558
13559 if (CHECK_FLAG(
13560 p->af_cap[afi]
13561 [safi],
13562 PEER_CAP_ADDPATH_AF_TX_ADV))
13563 vty_out(vty,
13564 "advertised");
13565
13566 if (CHECK_FLAG(
13567 p->af_cap[afi]
13568 [safi],
13569 PEER_CAP_ADDPATH_AF_TX_RCV))
13570 vty_out(vty,
13571 "%sreceived",
13572 CHECK_FLAG(
13573 p->af_cap
13574 [afi]
13575 [safi],
13576 PEER_CAP_ADDPATH_AF_TX_ADV)
13577 ? " and "
13578 : "");
13579
13580 vty_out(vty, "\n");
13581 }
13582
13583 if (CHECK_FLAG(
13584 p->af_cap[afi][safi],
13585 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13586 CHECK_FLAG(
13587 p->af_cap[afi][safi],
13588 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13589 vty_out(vty, " %s: RX ",
13590 get_afi_safi_str(
13591 afi, safi,
13592 false));
13593
13594 if (CHECK_FLAG(
13595 p->af_cap[afi]
13596 [safi],
13597 PEER_CAP_ADDPATH_AF_RX_ADV))
13598 vty_out(vty,
13599 "advertised");
13600
13601 if (CHECK_FLAG(
13602 p->af_cap[afi]
13603 [safi],
13604 PEER_CAP_ADDPATH_AF_RX_RCV))
13605 vty_out(vty,
13606 "%sreceived",
13607 CHECK_FLAG(
13608 p->af_cap
13609 [afi]
13610 [safi],
13611 PEER_CAP_ADDPATH_AF_RX_ADV)
13612 ? " and "
13613 : "");
13614
13615 vty_out(vty, "\n");
13616 }
13617 }
13618 }
13619
13620 /* Dynamic */
13621 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13622 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13623 vty_out(vty, " Dynamic:");
13624 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13625 vty_out(vty, " advertised");
13626 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13627 vty_out(vty, " %sreceived",
13628 CHECK_FLAG(p->cap,
13629 PEER_CAP_DYNAMIC_ADV)
13630 ? "and "
13631 : "");
13632 vty_out(vty, "\n");
13633 }
13634
13635 /* Role */
13636 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13637 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13638 vty_out(vty, " Role:");
13639 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13640 vty_out(vty, " advertised");
13641 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13642 vty_out(vty, " %sreceived",
13643 CHECK_FLAG(p->cap,
13644 PEER_CAP_ROLE_ADV)
13645 ? "and "
13646 : "");
13647 vty_out(vty, "\n");
13648 }
13649
13650 /* Extended nexthop */
13651 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13652 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13653 vty_out(vty, " Extended nexthop:");
13654 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13655 vty_out(vty, " advertised");
13656 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13657 vty_out(vty, " %sreceived",
13658 CHECK_FLAG(p->cap,
13659 PEER_CAP_ENHE_ADV)
13660 ? "and "
13661 : "");
13662 vty_out(vty, "\n");
13663
13664 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13665 vty_out(vty,
13666 " Address families by peer:\n ");
13667 for (safi = SAFI_UNICAST;
13668 safi < SAFI_MAX; safi++)
13669 if (CHECK_FLAG(
13670 p->af_cap[AFI_IP]
13671 [safi],
13672 PEER_CAP_ENHE_AF_RCV))
13673 vty_out(vty,
13674 " %s\n",
13675 get_afi_safi_str(
13676 AFI_IP,
13677 safi,
13678 false));
13679 }
13680 }
13681
13682 /* Long-lived Graceful Restart */
13683 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13684 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13685 vty_out(vty,
13686 " Long-lived Graceful Restart:");
13687 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13688 vty_out(vty, " advertised");
13689 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13690 vty_out(vty, " %sreceived",
13691 CHECK_FLAG(p->cap,
13692 PEER_CAP_LLGR_ADV)
13693 ? "and "
13694 : "");
13695 vty_out(vty, "\n");
13696
13697 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13698 vty_out(vty,
13699 " Address families by peer:\n");
13700 FOREACH_AFI_SAFI (afi, safi)
13701 if (CHECK_FLAG(
13702 p->af_cap[afi]
13703 [safi],
13704 PEER_CAP_LLGR_AF_RCV))
13705 vty_out(vty,
13706 " %s\n",
13707 get_afi_safi_str(
13708 afi,
13709 safi,
13710 false));
13711 }
13712 }
13713
13714 /* Route Refresh */
13715 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13716 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13717 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13718 vty_out(vty, " Route refresh:");
13719 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13720 vty_out(vty, " advertised");
13721 if (CHECK_FLAG(p->cap,
13722 PEER_CAP_REFRESH_NEW_RCV) ||
13723 CHECK_FLAG(p->cap,
13724 PEER_CAP_REFRESH_OLD_RCV))
13725 vty_out(vty, " %sreceived(%s)",
13726 CHECK_FLAG(p->cap,
13727 PEER_CAP_REFRESH_ADV)
13728 ? "and "
13729 : "",
13730 (CHECK_FLAG(
13731 p->cap,
13732 PEER_CAP_REFRESH_OLD_RCV) &&
13733 CHECK_FLAG(
13734 p->cap,
13735 PEER_CAP_REFRESH_NEW_RCV))
13736 ? "old & new"
13737 : CHECK_FLAG(
13738 p->cap,
13739 PEER_CAP_REFRESH_OLD_RCV)
13740 ? "old"
13741 : "new");
13742
13743 vty_out(vty, "\n");
13744 }
13745
13746 /* Enhanced Route Refresh */
13747 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13748 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13749 vty_out(vty, " Enhanced Route Refresh:");
13750 if (CHECK_FLAG(p->cap,
13751 PEER_CAP_ENHANCED_RR_ADV))
13752 vty_out(vty, " advertised");
13753 if (CHECK_FLAG(p->cap,
13754 PEER_CAP_ENHANCED_RR_RCV))
13755 vty_out(vty, " %sreceived",
13756 CHECK_FLAG(p->cap,
13757 PEER_CAP_REFRESH_ADV)
13758 ? "and "
13759 : "");
13760 vty_out(vty, "\n");
13761 }
13762
13763 /* Multiprotocol Extensions */
13764 FOREACH_AFI_SAFI (afi, safi)
13765 if (p->afc_adv[afi][safi] ||
13766 p->afc_recv[afi][safi]) {
13767 vty_out(vty, " Address Family %s:",
13768 get_afi_safi_str(afi, safi,
13769 false));
13770 if (p->afc_adv[afi][safi])
13771 vty_out(vty, " advertised");
13772 if (p->afc_recv[afi][safi])
13773 vty_out(vty, " %sreceived",
13774 p->afc_adv[afi][safi]
13775 ? "and "
13776 : "");
13777 vty_out(vty, "\n");
13778 }
13779
13780 /* Hostname capability */
13781 vty_out(vty, " Hostname Capability:");
13782
13783 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13784 vty_out(vty,
13785 " advertised (name: %s,domain name: %s)",
13786 bgp->peer_self->hostname
13787 ? bgp->peer_self->hostname
13788 : "n/a",
13789 bgp->peer_self->domainname
13790 ? bgp->peer_self->domainname
13791 : "n/a");
13792 } else {
13793 vty_out(vty, " not advertised");
13794 }
13795
13796 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13797 vty_out(vty,
13798 " received (name: %s,domain name: %s)",
13799 p->hostname ? p->hostname : "n/a",
13800 p->domainname ? p->domainname : "n/a");
13801 } else {
13802 vty_out(vty, " not received");
13803 }
13804
13805 vty_out(vty, "\n");
13806
13807 /* Graceful Restart */
13808 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13809 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13810 vty_out(vty,
13811 " Graceful Restart Capability:");
13812 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13813 vty_out(vty, " advertised");
13814 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13815 vty_out(vty, " %sreceived",
13816 CHECK_FLAG(p->cap,
13817 PEER_CAP_RESTART_ADV)
13818 ? "and "
13819 : "");
13820 vty_out(vty, "\n");
13821
13822 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13823 int restart_af_count = 0;
13824
13825 vty_out(vty,
13826 " Remote Restart timer is %d seconds\n",
13827 p->v_gr_restart);
13828 vty_out(vty,
13829 " Address families by peer:\n ");
13830
13831 FOREACH_AFI_SAFI (afi, safi)
13832 if (CHECK_FLAG(
13833 p->af_cap[afi]
13834 [safi],
13835 PEER_CAP_RESTART_AF_RCV)) {
13836 vty_out(vty, "%s%s(%s)",
13837 restart_af_count
13838 ? ", "
13839 : "",
13840 get_afi_safi_str(
13841 afi,
13842 safi,
13843 false),
13844 CHECK_FLAG(
13845 p->af_cap
13846 [afi]
13847 [safi],
13848 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13849 ? "preserved"
13850 : "not preserved");
13851 restart_af_count++;
13852 }
13853 if (!restart_af_count)
13854 vty_out(vty, "none");
13855 vty_out(vty, "\n");
13856 }
13857 } /* Graceful Restart */
13858 }
13859 }
13860
13861 /* graceful restart information */
13862 json_object *json_grace = NULL;
13863 json_object *json_grace_send = NULL;
13864 json_object *json_grace_recv = NULL;
13865 int eor_send_af_count = 0;
13866 int eor_receive_af_count = 0;
13867
13868 if (use_json) {
13869 json_grace = json_object_new_object();
13870 json_grace_send = json_object_new_object();
13871 json_grace_recv = json_object_new_object();
13872
13873 if ((peer_established(p)) &&
13874 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13875 FOREACH_AFI_SAFI (afi, safi) {
13876 if (CHECK_FLAG(p->af_sflags[afi][safi],
13877 PEER_STATUS_EOR_SEND)) {
13878 json_object_boolean_true_add(
13879 json_grace_send,
13880 get_afi_safi_str(afi, safi,
13881 true));
13882 eor_send_af_count++;
13883 }
13884 }
13885 FOREACH_AFI_SAFI (afi, safi) {
13886 if (CHECK_FLAG(p->af_sflags[afi][safi],
13887 PEER_STATUS_EOR_RECEIVED)) {
13888 json_object_boolean_true_add(
13889 json_grace_recv,
13890 get_afi_safi_str(afi, safi,
13891 true));
13892 eor_receive_af_count++;
13893 }
13894 }
13895 }
13896 json_object_object_add(json_grace, "endOfRibSend",
13897 json_grace_send);
13898 json_object_object_add(json_grace, "endOfRibRecv",
13899 json_grace_recv);
13900
13901
13902 if (p->t_gr_restart)
13903 json_object_int_add(
13904 json_grace, "gracefulRestartTimerMsecs",
13905 thread_timer_remain_second(p->t_gr_restart) *
13906 1000);
13907
13908 if (p->t_gr_stale)
13909 json_object_int_add(
13910 json_grace, "gracefulStalepathTimerMsecs",
13911 thread_timer_remain_second(p->t_gr_stale) *
13912 1000);
13913 /* more gr info in new format */
13914 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13915 json_object_object_add(json_neigh, "gracefulRestartInfo",
13916 json_grace);
13917 } else {
13918 vty_out(vty, " Graceful restart information:\n");
13919 if ((peer_established(p)) &&
13920 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13921
13922 vty_out(vty, " End-of-RIB send: ");
13923 FOREACH_AFI_SAFI (afi, safi) {
13924 if (CHECK_FLAG(p->af_sflags[afi][safi],
13925 PEER_STATUS_EOR_SEND)) {
13926 vty_out(vty, "%s%s",
13927 eor_send_af_count ? ", " : "",
13928 get_afi_safi_str(afi, safi,
13929 false));
13930 eor_send_af_count++;
13931 }
13932 }
13933 vty_out(vty, "\n");
13934 vty_out(vty, " End-of-RIB received: ");
13935 FOREACH_AFI_SAFI (afi, safi) {
13936 if (CHECK_FLAG(p->af_sflags[afi][safi],
13937 PEER_STATUS_EOR_RECEIVED)) {
13938 vty_out(vty, "%s%s",
13939 eor_receive_af_count ? ", "
13940 : "",
13941 get_afi_safi_str(afi, safi,
13942 false));
13943 eor_receive_af_count++;
13944 }
13945 }
13946 vty_out(vty, "\n");
13947 }
13948
13949 if (p->t_gr_restart)
13950 vty_out(vty,
13951 " The remaining time of restart timer is %ld\n",
13952 thread_timer_remain_second(p->t_gr_restart));
13953
13954 if (p->t_gr_stale)
13955 vty_out(vty,
13956 " The remaining time of stalepath timer is %ld\n",
13957 thread_timer_remain_second(p->t_gr_stale));
13958
13959 /* more gr info in new format */
13960 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13961 }
13962
13963 if (use_json) {
13964 json_object *json_stat = NULL;
13965 json_stat = json_object_new_object();
13966 /* Packet counts. */
13967
13968 atomic_size_t outq_count, inq_count;
13969 outq_count = atomic_load_explicit(&p->obuf->count,
13970 memory_order_relaxed);
13971 inq_count = atomic_load_explicit(&p->ibuf->count,
13972 memory_order_relaxed);
13973
13974 json_object_int_add(json_stat, "depthInq",
13975 (unsigned long)inq_count);
13976 json_object_int_add(json_stat, "depthOutq",
13977 (unsigned long)outq_count);
13978 json_object_int_add(json_stat, "opensSent",
13979 atomic_load_explicit(&p->open_out,
13980 memory_order_relaxed));
13981 json_object_int_add(json_stat, "opensRecv",
13982 atomic_load_explicit(&p->open_in,
13983 memory_order_relaxed));
13984 json_object_int_add(json_stat, "notificationsSent",
13985 atomic_load_explicit(&p->notify_out,
13986 memory_order_relaxed));
13987 json_object_int_add(json_stat, "notificationsRecv",
13988 atomic_load_explicit(&p->notify_in,
13989 memory_order_relaxed));
13990 json_object_int_add(json_stat, "updatesSent",
13991 atomic_load_explicit(&p->update_out,
13992 memory_order_relaxed));
13993 json_object_int_add(json_stat, "updatesRecv",
13994 atomic_load_explicit(&p->update_in,
13995 memory_order_relaxed));
13996 json_object_int_add(json_stat, "keepalivesSent",
13997 atomic_load_explicit(&p->keepalive_out,
13998 memory_order_relaxed));
13999 json_object_int_add(json_stat, "keepalivesRecv",
14000 atomic_load_explicit(&p->keepalive_in,
14001 memory_order_relaxed));
14002 json_object_int_add(json_stat, "routeRefreshSent",
14003 atomic_load_explicit(&p->refresh_out,
14004 memory_order_relaxed));
14005 json_object_int_add(json_stat, "routeRefreshRecv",
14006 atomic_load_explicit(&p->refresh_in,
14007 memory_order_relaxed));
14008 json_object_int_add(json_stat, "capabilitySent",
14009 atomic_load_explicit(&p->dynamic_cap_out,
14010 memory_order_relaxed));
14011 json_object_int_add(json_stat, "capabilityRecv",
14012 atomic_load_explicit(&p->dynamic_cap_in,
14013 memory_order_relaxed));
14014 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14015 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14016 json_object_object_add(json_neigh, "messageStats", json_stat);
14017 } else {
14018 atomic_size_t outq_count, inq_count, open_out, open_in,
14019 notify_out, notify_in, update_out, update_in,
14020 keepalive_out, keepalive_in, refresh_out, refresh_in,
14021 dynamic_cap_out, dynamic_cap_in;
14022 outq_count = atomic_load_explicit(&p->obuf->count,
14023 memory_order_relaxed);
14024 inq_count = atomic_load_explicit(&p->ibuf->count,
14025 memory_order_relaxed);
14026 open_out = atomic_load_explicit(&p->open_out,
14027 memory_order_relaxed);
14028 open_in =
14029 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14030 notify_out = atomic_load_explicit(&p->notify_out,
14031 memory_order_relaxed);
14032 notify_in = atomic_load_explicit(&p->notify_in,
14033 memory_order_relaxed);
14034 update_out = atomic_load_explicit(&p->update_out,
14035 memory_order_relaxed);
14036 update_in = atomic_load_explicit(&p->update_in,
14037 memory_order_relaxed);
14038 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14039 memory_order_relaxed);
14040 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14041 memory_order_relaxed);
14042 refresh_out = atomic_load_explicit(&p->refresh_out,
14043 memory_order_relaxed);
14044 refresh_in = atomic_load_explicit(&p->refresh_in,
14045 memory_order_relaxed);
14046 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14047 memory_order_relaxed);
14048 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14049 memory_order_relaxed);
14050
14051 /* Packet counts. */
14052 vty_out(vty, " Message statistics:\n");
14053 vty_out(vty, " Inq depth is %zu\n", inq_count);
14054 vty_out(vty, " Outq depth is %zu\n", outq_count);
14055 vty_out(vty, " Sent Rcvd\n");
14056 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14057 open_in);
14058 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14059 notify_in);
14060 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14061 update_in);
14062 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14063 keepalive_in);
14064 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14065 refresh_in);
14066 vty_out(vty, " Capability: %10zu %10zu\n",
14067 dynamic_cap_out, dynamic_cap_in);
14068 vty_out(vty, " Total: %10u %10u\n",
14069 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14070 }
14071
14072 if (use_json) {
14073 /* advertisement-interval */
14074 json_object_int_add(json_neigh,
14075 "minBtwnAdvertisementRunsTimerMsecs",
14076 p->v_routeadv * 1000);
14077
14078 /* Update-source. */
14079 if (p->update_if || p->update_source) {
14080 if (p->update_if)
14081 json_object_string_add(json_neigh,
14082 "updateSource",
14083 p->update_if);
14084 else if (p->update_source)
14085 json_object_string_addf(json_neigh,
14086 "updateSource", "%pSU",
14087 p->update_source);
14088 }
14089 } else {
14090 /* advertisement-interval */
14091 vty_out(vty,
14092 " Minimum time between advertisement runs is %d seconds\n",
14093 p->v_routeadv);
14094
14095 /* Update-source. */
14096 if (p->update_if || p->update_source) {
14097 vty_out(vty, " Update source is ");
14098 if (p->update_if)
14099 vty_out(vty, "%s", p->update_if);
14100 else if (p->update_source)
14101 vty_out(vty, "%pSU", p->update_source);
14102 vty_out(vty, "\n");
14103 }
14104
14105 vty_out(vty, "\n");
14106 }
14107
14108 /* Address Family Information */
14109 json_object *json_hold = NULL;
14110
14111 if (use_json)
14112 json_hold = json_object_new_object();
14113
14114 FOREACH_AFI_SAFI (afi, safi)
14115 if (p->afc[afi][safi])
14116 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14117 json_hold);
14118
14119 if (use_json) {
14120 json_object_object_add(json_neigh, "addressFamilyInfo",
14121 json_hold);
14122 json_object_int_add(json_neigh, "connectionsEstablished",
14123 p->established);
14124 json_object_int_add(json_neigh, "connectionsDropped",
14125 p->dropped);
14126 } else
14127 vty_out(vty, " Connections established %d; dropped %d\n",
14128 p->established, p->dropped);
14129
14130 if (!p->last_reset) {
14131 if (use_json)
14132 json_object_string_add(json_neigh, "lastReset",
14133 "never");
14134 else
14135 vty_out(vty, " Last reset never\n");
14136 } else {
14137 if (use_json) {
14138 time_t uptime;
14139 struct tm tm;
14140
14141 uptime = monotime(NULL);
14142 uptime -= p->resettime;
14143 gmtime_r(&uptime, &tm);
14144
14145 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14146 (tm.tm_sec * 1000)
14147 + (tm.tm_min * 60000)
14148 + (tm.tm_hour * 3600000));
14149 bgp_show_peer_reset(NULL, p, json_neigh, true);
14150 } else {
14151 vty_out(vty, " Last reset %s, ",
14152 peer_uptime(p->resettime, timebuf,
14153 BGP_UPTIME_LEN, 0, NULL));
14154
14155 bgp_show_peer_reset(vty, p, NULL, false);
14156 if (p->last_reset_cause_size) {
14157 msg = p->last_reset_cause;
14158 vty_out(vty,
14159 " Message received that caused BGP to send a NOTIFICATION:\n ");
14160 for (i = 1; i <= p->last_reset_cause_size;
14161 i++) {
14162 vty_out(vty, "%02X", *msg++);
14163
14164 if (i != p->last_reset_cause_size) {
14165 if (i % 16 == 0) {
14166 vty_out(vty, "\n ");
14167 } else if (i % 4 == 0) {
14168 vty_out(vty, " ");
14169 }
14170 }
14171 }
14172 vty_out(vty, "\n");
14173 }
14174 }
14175 }
14176
14177 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14178 if (use_json)
14179 json_object_boolean_true_add(json_neigh,
14180 "prefixesConfigExceedMax");
14181 else
14182 vty_out(vty,
14183 " Peer had exceeded the max. no. of prefixes configured.\n");
14184
14185 if (p->t_pmax_restart) {
14186 if (use_json) {
14187 json_object_boolean_true_add(
14188 json_neigh, "reducePrefixNumFrom");
14189 json_object_int_add(json_neigh,
14190 "restartInTimerMsec",
14191 thread_timer_remain_second(
14192 p->t_pmax_restart)
14193 * 1000);
14194 } else
14195 vty_out(vty,
14196 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14197 p->host, thread_timer_remain_second(
14198 p->t_pmax_restart));
14199 } else {
14200 if (use_json)
14201 json_object_boolean_true_add(
14202 json_neigh,
14203 "reducePrefixNumAndClearIpBgp");
14204 else
14205 vty_out(vty,
14206 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14207 p->host);
14208 }
14209 }
14210
14211 /* EBGP Multihop and GTSM */
14212 if (p->sort != BGP_PEER_IBGP) {
14213 if (use_json) {
14214 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14215 json_object_int_add(json_neigh,
14216 "externalBgpNbrMaxHopsAway",
14217 p->gtsm_hops);
14218 else
14219 json_object_int_add(json_neigh,
14220 "externalBgpNbrMaxHopsAway",
14221 p->ttl);
14222 } else {
14223 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14224 vty_out(vty,
14225 " External BGP neighbor may be up to %d hops away.\n",
14226 p->gtsm_hops);
14227 else
14228 vty_out(vty,
14229 " External BGP neighbor may be up to %d hops away.\n",
14230 p->ttl);
14231 }
14232 } else {
14233 if (use_json) {
14234 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14235 json_object_int_add(json_neigh,
14236 "internalBgpNbrMaxHopsAway",
14237 p->gtsm_hops);
14238 else
14239 json_object_int_add(json_neigh,
14240 "internalBgpNbrMaxHopsAway",
14241 p->ttl);
14242 } else {
14243 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14244 vty_out(vty,
14245 " Internal BGP neighbor may be up to %d hops away.\n",
14246 p->gtsm_hops);
14247 else
14248 vty_out(vty,
14249 " Internal BGP neighbor may be up to %d hops away.\n",
14250 p->ttl);
14251 }
14252 }
14253
14254 /* Local address. */
14255 if (p->su_local) {
14256 if (use_json) {
14257 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14258 p->su_local);
14259 json_object_int_add(json_neigh, "portLocal",
14260 ntohs(p->su_local->sin.sin_port));
14261 } else
14262 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14263 p->su_local, ntohs(p->su_local->sin.sin_port));
14264 } else {
14265 if (use_json) {
14266 json_object_string_add(json_neigh, "hostLocal",
14267 "Unknown");
14268 json_object_int_add(json_neigh, "portLocal", -1);
14269 }
14270 }
14271
14272 /* Remote address. */
14273 if (p->su_remote) {
14274 if (use_json) {
14275 json_object_string_addf(json_neigh, "hostForeign",
14276 "%pSU", p->su_remote);
14277 json_object_int_add(json_neigh, "portForeign",
14278 ntohs(p->su_remote->sin.sin_port));
14279 } else
14280 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14281 p->su_remote,
14282 ntohs(p->su_remote->sin.sin_port));
14283 } else {
14284 if (use_json) {
14285 json_object_string_add(json_neigh, "hostForeign",
14286 "Unknown");
14287 json_object_int_add(json_neigh, "portForeign", -1);
14288 }
14289 }
14290
14291 /* Nexthop display. */
14292 if (p->su_local) {
14293 if (use_json) {
14294 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14295 &p->nexthop.v4);
14296 json_object_string_addf(json_neigh, "nexthopGlobal",
14297 "%pI6", &p->nexthop.v6_global);
14298 json_object_string_addf(json_neigh, "nexthopLocal",
14299 "%pI6", &p->nexthop.v6_local);
14300 if (p->shared_network)
14301 json_object_string_add(json_neigh,
14302 "bgpConnection",
14303 "sharedNetwork");
14304 else
14305 json_object_string_add(json_neigh,
14306 "bgpConnection",
14307 "nonSharedNetwork");
14308 } else {
14309 vty_out(vty, "Nexthop: %s\n",
14310 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14311 sizeof(buf1)));
14312 vty_out(vty, "Nexthop global: %s\n",
14313 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14314 sizeof(buf1)));
14315 vty_out(vty, "Nexthop local: %s\n",
14316 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14317 sizeof(buf1)));
14318 vty_out(vty, "BGP connection: %s\n",
14319 p->shared_network ? "shared network"
14320 : "non shared network");
14321 }
14322 }
14323
14324 /* Timer information. */
14325 if (use_json) {
14326 json_object_int_add(json_neigh, "connectRetryTimer",
14327 p->v_connect);
14328 if (peer_established(p) && p->rtt)
14329 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14330 p->rtt);
14331 if (p->t_start)
14332 json_object_int_add(
14333 json_neigh, "nextStartTimerDueInMsecs",
14334 thread_timer_remain_second(p->t_start) * 1000);
14335 if (p->t_connect)
14336 json_object_int_add(
14337 json_neigh, "nextConnectTimerDueInMsecs",
14338 thread_timer_remain_second(p->t_connect)
14339 * 1000);
14340 if (p->t_routeadv) {
14341 json_object_int_add(json_neigh, "mraiInterval",
14342 p->v_routeadv);
14343 json_object_int_add(
14344 json_neigh, "mraiTimerExpireInMsecs",
14345 thread_timer_remain_second(p->t_routeadv)
14346 * 1000);
14347 }
14348 if (p->password)
14349 json_object_int_add(json_neigh, "authenticationEnabled",
14350 1);
14351
14352 if (p->t_read)
14353 json_object_string_add(json_neigh, "readThread", "on");
14354 else
14355 json_object_string_add(json_neigh, "readThread", "off");
14356
14357 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14358 json_object_string_add(json_neigh, "writeThread", "on");
14359 else
14360 json_object_string_add(json_neigh, "writeThread",
14361 "off");
14362 } else {
14363 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14364 p->v_connect);
14365 if (peer_established(p) && p->rtt)
14366 vty_out(vty, "Estimated round trip time: %d ms\n",
14367 p->rtt);
14368 if (p->t_start)
14369 vty_out(vty, "Next start timer due in %ld seconds\n",
14370 thread_timer_remain_second(p->t_start));
14371 if (p->t_connect)
14372 vty_out(vty, "Next connect timer due in %ld seconds\n",
14373 thread_timer_remain_second(p->t_connect));
14374 if (p->t_routeadv)
14375 vty_out(vty,
14376 "MRAI (interval %u) timer expires in %ld seconds\n",
14377 p->v_routeadv,
14378 thread_timer_remain_second(p->t_routeadv));
14379 if (p->password)
14380 vty_out(vty, "Peer Authentication Enabled\n");
14381
14382 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14383 p->t_read ? "on" : "off",
14384 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14385 ? "on"
14386 : "off", p->fd);
14387 }
14388
14389 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14390 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14391 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14392
14393 if (!use_json)
14394 vty_out(vty, "\n");
14395
14396 /* BFD information. */
14397 if (p->bfd_config)
14398 bgp_bfd_show_info(vty, p, json_neigh);
14399
14400 if (use_json) {
14401 if (p->conf_if) /* Configured interface name. */
14402 json_object_object_add(json, p->conf_if, json_neigh);
14403 else /* Configured IP address. */
14404 json_object_object_add(json, p->host, json_neigh);
14405 }
14406 }
14407
14408 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14409 enum show_type type,
14410 union sockunion *su,
14411 const char *conf_if, afi_t afi,
14412 bool use_json)
14413 {
14414 struct listnode *node, *nnode;
14415 struct peer *peer;
14416 int find = 0;
14417 safi_t safi = SAFI_UNICAST;
14418 json_object *json = NULL;
14419 json_object *json_neighbor = NULL;
14420
14421 if (use_json) {
14422 json = json_object_new_object();
14423 json_neighbor = json_object_new_object();
14424 }
14425
14426 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14427
14428 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14429 continue;
14430
14431 if ((peer->afc[afi][safi]) == 0)
14432 continue;
14433
14434 if (type == show_all) {
14435 bgp_show_peer_gr_status(vty, peer, use_json,
14436 json_neighbor);
14437
14438 if (use_json) {
14439 json_object_object_add(json, peer->host,
14440 json_neighbor);
14441 json_neighbor = NULL;
14442 }
14443
14444 } else if (type == show_peer) {
14445 if (conf_if) {
14446 if ((peer->conf_if
14447 && !strcmp(peer->conf_if, conf_if))
14448 || (peer->hostname
14449 && !strcmp(peer->hostname, conf_if))) {
14450 find = 1;
14451 bgp_show_peer_gr_status(vty, peer,
14452 use_json,
14453 json_neighbor);
14454 }
14455 } else {
14456 if (sockunion_same(&peer->su, su)) {
14457 find = 1;
14458 bgp_show_peer_gr_status(vty, peer,
14459 use_json,
14460 json_neighbor);
14461 }
14462 }
14463 if (use_json && find)
14464 json_object_object_add(json, peer->host,
14465 json_neighbor);
14466 }
14467
14468 if (find) {
14469 json_neighbor = NULL;
14470 break;
14471 }
14472 }
14473
14474 if (type == show_peer && !find) {
14475 if (use_json)
14476 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14477 else
14478 vty_out(vty, "%% No such neighbor\n");
14479 }
14480 if (use_json) {
14481 if (json_neighbor)
14482 json_object_free(json_neighbor);
14483 vty_json(vty, json);
14484 } else {
14485 vty_out(vty, "\n");
14486 }
14487
14488 return CMD_SUCCESS;
14489 }
14490
14491 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14492 enum show_type type, union sockunion *su,
14493 const char *conf_if, bool use_json,
14494 json_object *json)
14495 {
14496 struct listnode *node, *nnode;
14497 struct peer *peer;
14498 int find = 0;
14499 bool nbr_output = false;
14500 afi_t afi = AFI_MAX;
14501 safi_t safi = SAFI_MAX;
14502
14503 if (type == show_ipv4_peer || type == show_ipv4_all) {
14504 afi = AFI_IP;
14505 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14506 afi = AFI_IP6;
14507 }
14508
14509 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14510 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14511 continue;
14512
14513 switch (type) {
14514 case show_all:
14515 bgp_show_peer(vty, peer, use_json, json);
14516 nbr_output = true;
14517 break;
14518 case show_peer:
14519 if (conf_if) {
14520 if ((peer->conf_if
14521 && !strcmp(peer->conf_if, conf_if))
14522 || (peer->hostname
14523 && !strcmp(peer->hostname, conf_if))) {
14524 find = 1;
14525 bgp_show_peer(vty, peer, use_json,
14526 json);
14527 }
14528 } else {
14529 if (sockunion_same(&peer->su, su)) {
14530 find = 1;
14531 bgp_show_peer(vty, peer, use_json,
14532 json);
14533 }
14534 }
14535 break;
14536 case show_ipv4_peer:
14537 case show_ipv6_peer:
14538 FOREACH_SAFI (safi) {
14539 if (peer->afc[afi][safi]) {
14540 if (conf_if) {
14541 if ((peer->conf_if
14542 && !strcmp(peer->conf_if, conf_if))
14543 || (peer->hostname
14544 && !strcmp(peer->hostname, conf_if))) {
14545 find = 1;
14546 bgp_show_peer(vty, peer, use_json,
14547 json);
14548 break;
14549 }
14550 } else {
14551 if (sockunion_same(&peer->su, su)) {
14552 find = 1;
14553 bgp_show_peer(vty, peer, use_json,
14554 json);
14555 break;
14556 }
14557 }
14558 }
14559 }
14560 break;
14561 case show_ipv4_all:
14562 case show_ipv6_all:
14563 FOREACH_SAFI (safi) {
14564 if (peer->afc[afi][safi]) {
14565 bgp_show_peer(vty, peer, use_json, json);
14566 nbr_output = true;
14567 break;
14568 }
14569 }
14570 break;
14571 }
14572 }
14573
14574 if ((type == show_peer || type == show_ipv4_peer ||
14575 type == show_ipv6_peer) && !find) {
14576 if (use_json)
14577 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14578 else
14579 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14580 }
14581
14582 if (type != show_peer && type != show_ipv4_peer &&
14583 type != show_ipv6_peer && !nbr_output && !use_json)
14584 vty_out(vty, "%% No BGP neighbors found\n");
14585
14586 if (use_json) {
14587 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14588 json, JSON_C_TO_STRING_PRETTY));
14589 } else {
14590 vty_out(vty, "\n");
14591 }
14592
14593 return CMD_SUCCESS;
14594 }
14595
14596 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14597 enum show_type type,
14598 const char *ip_str,
14599 afi_t afi, bool use_json)
14600 {
14601
14602 int ret;
14603 struct bgp *bgp;
14604 union sockunion su;
14605
14606 bgp = bgp_get_default();
14607
14608 if (!bgp)
14609 return;
14610
14611 if (!use_json)
14612 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14613 NULL);
14614
14615 if (ip_str) {
14616 ret = str2sockunion(ip_str, &su);
14617 if (ret < 0)
14618 bgp_show_neighbor_graceful_restart(
14619 vty, bgp, type, NULL, ip_str, afi, use_json);
14620 else
14621 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14622 NULL, afi, use_json);
14623 } else
14624 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14625 afi, use_json);
14626 }
14627
14628 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14629 enum show_type type,
14630 const char *ip_str,
14631 bool use_json)
14632 {
14633 struct listnode *node, *nnode;
14634 struct bgp *bgp;
14635 union sockunion su;
14636 json_object *json = NULL;
14637 int ret, is_first = 1;
14638 bool nbr_output = false;
14639
14640 if (use_json)
14641 vty_out(vty, "{\n");
14642
14643 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14644 nbr_output = true;
14645 if (use_json) {
14646 if (!(json = json_object_new_object())) {
14647 flog_err(
14648 EC_BGP_JSON_MEM_ERROR,
14649 "Unable to allocate memory for JSON object");
14650 vty_out(vty,
14651 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14652 return;
14653 }
14654
14655 json_object_int_add(json, "vrfId",
14656 (bgp->vrf_id == VRF_UNKNOWN)
14657 ? -1
14658 : (int64_t)bgp->vrf_id);
14659 json_object_string_add(
14660 json, "vrfName",
14661 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14662 ? VRF_DEFAULT_NAME
14663 : bgp->name);
14664
14665 if (!is_first)
14666 vty_out(vty, ",\n");
14667 else
14668 is_first = 0;
14669
14670 vty_out(vty, "\"%s\":",
14671 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14672 ? VRF_DEFAULT_NAME
14673 : bgp->name);
14674 } else {
14675 vty_out(vty, "\nInstance %s:\n",
14676 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14677 ? VRF_DEFAULT_NAME
14678 : bgp->name);
14679 }
14680
14681 if (type == show_peer || type == show_ipv4_peer ||
14682 type == show_ipv6_peer) {
14683 ret = str2sockunion(ip_str, &su);
14684 if (ret < 0)
14685 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14686 use_json, json);
14687 else
14688 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14689 use_json, json);
14690 } else {
14691 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14692 use_json, json);
14693 }
14694 json_object_free(json);
14695 json = NULL;
14696 }
14697
14698 if (use_json)
14699 vty_out(vty, "}\n");
14700 else if (!nbr_output)
14701 vty_out(vty, "%% BGP instance not found\n");
14702 }
14703
14704 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14705 enum show_type type, const char *ip_str,
14706 bool use_json)
14707 {
14708 int ret;
14709 struct bgp *bgp;
14710 union sockunion su;
14711 json_object *json = NULL;
14712
14713 if (name) {
14714 if (strmatch(name, "all")) {
14715 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14716 use_json);
14717 return CMD_SUCCESS;
14718 } else {
14719 bgp = bgp_lookup_by_name(name);
14720 if (!bgp) {
14721 if (use_json) {
14722 json = json_object_new_object();
14723 vty_json(vty, json);
14724 } else
14725 vty_out(vty,
14726 "%% BGP instance not found\n");
14727
14728 return CMD_WARNING;
14729 }
14730 }
14731 } else {
14732 bgp = bgp_get_default();
14733 }
14734
14735 if (bgp) {
14736 json = json_object_new_object();
14737 if (ip_str) {
14738 ret = str2sockunion(ip_str, &su);
14739 if (ret < 0)
14740 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14741 use_json, json);
14742 else
14743 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14744 use_json, json);
14745 } else {
14746 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14747 json);
14748 }
14749 json_object_free(json);
14750 } else {
14751 if (use_json)
14752 vty_out(vty, "{}\n");
14753 else
14754 vty_out(vty, "%% BGP instance not found\n");
14755 }
14756
14757 return CMD_SUCCESS;
14758 }
14759
14760
14761
14762 /* "show [ip] bgp neighbors graceful-restart" commands. */
14763 DEFUN (show_ip_bgp_neighbors_graceful_restart,
14764 show_ip_bgp_neighbors_graceful_restart_cmd,
14765 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14766 SHOW_STR
14767 BGP_STR
14768 IP_STR
14769 IPV6_STR
14770 NEIGHBOR_STR
14771 "Neighbor to display information about\n"
14772 "Neighbor to display information about\n"
14773 "Neighbor on BGP configured interface\n"
14774 GR_SHOW
14775 JSON_STR)
14776 {
14777 char *sh_arg = NULL;
14778 enum show_type sh_type;
14779 int idx = 0;
14780 afi_t afi = AFI_MAX;
14781 bool uj = use_json(argc, argv);
14782
14783 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14784 afi = AFI_MAX;
14785
14786 idx++;
14787
14788 if (argv_find(argv, argc, "A.B.C.D", &idx)
14789 || argv_find(argv, argc, "X:X::X:X", &idx)
14790 || argv_find(argv, argc, "WORD", &idx)) {
14791 sh_type = show_peer;
14792 sh_arg = argv[idx]->arg;
14793 } else
14794 sh_type = show_all;
14795
14796 if (!argv_find(argv, argc, "graceful-restart", &idx))
14797 return CMD_SUCCESS;
14798
14799
14800 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14801 afi, uj);
14802 }
14803
14804 /* "show [ip] bgp neighbors" commands. */
14805 DEFUN (show_ip_bgp_neighbors,
14806 show_ip_bgp_neighbors_cmd,
14807 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14808 SHOW_STR
14809 IP_STR
14810 BGP_STR
14811 BGP_INSTANCE_HELP_STR
14812 BGP_AF_STR
14813 BGP_AF_STR
14814 "Detailed information on TCP and BGP neighbor connections\n"
14815 "Neighbor to display information about\n"
14816 "Neighbor to display information about\n"
14817 "Neighbor on BGP configured interface\n"
14818 JSON_STR)
14819 {
14820 char *vrf = NULL;
14821 char *sh_arg = NULL;
14822 enum show_type sh_type;
14823 afi_t afi = AFI_MAX;
14824
14825 bool uj = use_json(argc, argv);
14826
14827 int idx = 0;
14828
14829 /* [<vrf> VIEWVRFNAME] */
14830 if (argv_find(argv, argc, "vrf", &idx)) {
14831 vrf = argv[idx + 1]->arg;
14832 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14833 vrf = NULL;
14834 } else if (argv_find(argv, argc, "view", &idx))
14835 /* [<view> VIEWVRFNAME] */
14836 vrf = argv[idx + 1]->arg;
14837
14838 idx++;
14839
14840 if (argv_find(argv, argc, "ipv4", &idx)) {
14841 sh_type = show_ipv4_all;
14842 afi = AFI_IP;
14843 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14844 sh_type = show_ipv6_all;
14845 afi = AFI_IP6;
14846 } else {
14847 sh_type = show_all;
14848 }
14849
14850 if (argv_find(argv, argc, "A.B.C.D", &idx)
14851 || argv_find(argv, argc, "X:X::X:X", &idx)
14852 || argv_find(argv, argc, "WORD", &idx)) {
14853 sh_type = show_peer;
14854 sh_arg = argv[idx]->arg;
14855 }
14856
14857 if (sh_type == show_peer && afi == AFI_IP) {
14858 sh_type = show_ipv4_peer;
14859 } else if (sh_type == show_peer && afi == AFI_IP6) {
14860 sh_type = show_ipv6_peer;
14861 }
14862
14863 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14864 }
14865
14866 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14867 paths' and `show ip mbgp paths'. Those functions results are the
14868 same.*/
14869 DEFUN (show_ip_bgp_paths,
14870 show_ip_bgp_paths_cmd,
14871 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14872 SHOW_STR
14873 IP_STR
14874 BGP_STR
14875 BGP_SAFI_HELP_STR
14876 "Path information\n")
14877 {
14878 vty_out(vty, "Address Refcnt Path\n");
14879 aspath_print_all_vty(vty);
14880 return CMD_SUCCESS;
14881 }
14882
14883 #include "hash.h"
14884
14885 static void community_show_all_iterator(struct hash_bucket *bucket,
14886 struct vty *vty)
14887 {
14888 struct community *com;
14889
14890 com = (struct community *)bucket->data;
14891 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14892 community_str(com, false, false));
14893 }
14894
14895 /* Show BGP's community internal data. */
14896 DEFUN (show_ip_bgp_community_info,
14897 show_ip_bgp_community_info_cmd,
14898 "show [ip] bgp community-info",
14899 SHOW_STR
14900 IP_STR
14901 BGP_STR
14902 "List all bgp community information\n")
14903 {
14904 vty_out(vty, "Address Refcnt Community\n");
14905
14906 hash_iterate(community_hash(),
14907 (void (*)(struct hash_bucket *,
14908 void *))community_show_all_iterator,
14909 vty);
14910
14911 return CMD_SUCCESS;
14912 }
14913
14914 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14915 struct vty *vty)
14916 {
14917 struct lcommunity *lcom;
14918
14919 lcom = (struct lcommunity *)bucket->data;
14920 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14921 lcommunity_str(lcom, false, false));
14922 }
14923
14924 /* Show BGP's community internal data. */
14925 DEFUN (show_ip_bgp_lcommunity_info,
14926 show_ip_bgp_lcommunity_info_cmd,
14927 "show ip bgp large-community-info",
14928 SHOW_STR
14929 IP_STR
14930 BGP_STR
14931 "List all bgp large-community information\n")
14932 {
14933 vty_out(vty, "Address Refcnt Large-community\n");
14934
14935 hash_iterate(lcommunity_hash(),
14936 (void (*)(struct hash_bucket *,
14937 void *))lcommunity_show_all_iterator,
14938 vty);
14939
14940 return CMD_SUCCESS;
14941 }
14942 /* Graceful Restart */
14943
14944 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14945 struct bgp *bgp,
14946 bool use_json,
14947 json_object *json)
14948 {
14949
14950
14951 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14952
14953 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14954
14955 switch (bgp_global_gr_mode) {
14956
14957 case GLOBAL_HELPER:
14958 vty_out(vty, "Global BGP GR Mode : Helper\n");
14959 break;
14960
14961 case GLOBAL_GR:
14962 vty_out(vty, "Global BGP GR Mode : Restart\n");
14963 break;
14964
14965 case GLOBAL_DISABLE:
14966 vty_out(vty, "Global BGP GR Mode : Disable\n");
14967 break;
14968
14969 case GLOBAL_INVALID:
14970 vty_out(vty,
14971 "Global BGP GR Mode Invalid\n");
14972 break;
14973 }
14974 vty_out(vty, "\n");
14975 }
14976
14977 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14978 enum show_type type,
14979 const char *ip_str,
14980 afi_t afi, bool use_json)
14981 {
14982 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14983 afi = AFI_IP;
14984
14985 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14986
14987 bgp_show_neighbor_graceful_restart_vty(
14988 vty, type, ip_str, afi, use_json);
14989 afi++;
14990 }
14991 } else if (afi != AFI_MAX) {
14992 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14993 use_json);
14994 } else {
14995 return CMD_ERR_INCOMPLETE;
14996 }
14997
14998 return CMD_SUCCESS;
14999 }
15000 /* Graceful Restart */
15001
15002 DEFUN (show_ip_bgp_attr_info,
15003 show_ip_bgp_attr_info_cmd,
15004 "show [ip] bgp attribute-info",
15005 SHOW_STR
15006 IP_STR
15007 BGP_STR
15008 "List all bgp attribute information\n")
15009 {
15010 attr_show_all(vty);
15011 return CMD_SUCCESS;
15012 }
15013
15014 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15015 afi_t afi, safi_t safi,
15016 bool use_json, json_object *json)
15017 {
15018 struct bgp *bgp;
15019 struct listnode *node;
15020 char *vname;
15021 char *ecom_str;
15022 enum vpn_policy_direction dir;
15023
15024 if (json) {
15025 json_object *json_import_vrfs = NULL;
15026 json_object *json_export_vrfs = NULL;
15027
15028 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15029
15030 if (!bgp) {
15031 vty_json(vty, json);
15032
15033 return CMD_WARNING;
15034 }
15035
15036 /* Provide context for the block */
15037 json_object_string_add(json, "vrf", name ? name : "default");
15038 json_object_string_add(json, "afiSafi",
15039 get_afi_safi_str(afi, safi, true));
15040
15041 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15042 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15043 json_object_string_add(json, "importFromVrfs", "none");
15044 json_object_string_add(json, "importRts", "none");
15045 } else {
15046 json_import_vrfs = json_object_new_array();
15047
15048 for (ALL_LIST_ELEMENTS_RO(
15049 bgp->vpn_policy[afi].import_vrf,
15050 node, vname))
15051 json_object_array_add(json_import_vrfs,
15052 json_object_new_string(vname));
15053
15054 json_object_object_add(json, "importFromVrfs",
15055 json_import_vrfs);
15056 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15057 if (bgp->vpn_policy[afi].rtlist[dir]) {
15058 ecom_str = ecommunity_ecom2str(
15059 bgp->vpn_policy[afi].rtlist[dir],
15060 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15061 json_object_string_add(json, "importRts",
15062 ecom_str);
15063 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15064 } else
15065 json_object_string_add(json, "importRts",
15066 "none");
15067 }
15068
15069 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15070 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15071 json_object_string_add(json, "exportToVrfs", "none");
15072 json_object_string_add(json, "routeDistinguisher",
15073 "none");
15074 json_object_string_add(json, "exportRts", "none");
15075 } else {
15076 json_export_vrfs = json_object_new_array();
15077
15078 for (ALL_LIST_ELEMENTS_RO(
15079 bgp->vpn_policy[afi].export_vrf,
15080 node, vname))
15081 json_object_array_add(json_export_vrfs,
15082 json_object_new_string(vname));
15083 json_object_object_add(json, "exportToVrfs",
15084 json_export_vrfs);
15085 json_object_string_addf(json, "routeDistinguisher",
15086 "%pRD",
15087 &bgp->vpn_policy[afi].tovpn_rd);
15088
15089 dir = BGP_VPN_POLICY_DIR_TOVPN;
15090 if (bgp->vpn_policy[afi].rtlist[dir]) {
15091 ecom_str = ecommunity_ecom2str(
15092 bgp->vpn_policy[afi].rtlist[dir],
15093 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15094 json_object_string_add(json, "exportRts",
15095 ecom_str);
15096 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15097 } else
15098 json_object_string_add(json, "exportRts",
15099 "none");
15100 }
15101
15102 if (use_json) {
15103 vty_json(vty, json);
15104 }
15105 } else {
15106 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15107
15108 if (!bgp) {
15109 vty_out(vty, "%% No such BGP instance exist\n");
15110 return CMD_WARNING;
15111 }
15112
15113 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15114 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15115 vty_out(vty,
15116 "This VRF is not importing %s routes from any other VRF\n",
15117 get_afi_safi_str(afi, safi, false));
15118 else {
15119 vty_out(vty,
15120 "This VRF is importing %s routes from the following VRFs:\n",
15121 get_afi_safi_str(afi, safi, false));
15122
15123 for (ALL_LIST_ELEMENTS_RO(
15124 bgp->vpn_policy[afi].import_vrf,
15125 node, vname))
15126 vty_out(vty, " %s\n", vname);
15127
15128 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15129 ecom_str = NULL;
15130 if (bgp->vpn_policy[afi].rtlist[dir]) {
15131 ecom_str = ecommunity_ecom2str(
15132 bgp->vpn_policy[afi].rtlist[dir],
15133 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15134 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15135
15136 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15137 } else
15138 vty_out(vty, "Import RT(s):\n");
15139 }
15140
15141 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15142 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15143 vty_out(vty,
15144 "This VRF is not exporting %s routes to any other VRF\n",
15145 get_afi_safi_str(afi, safi, false));
15146 else {
15147 vty_out(vty,
15148 "This VRF is exporting %s routes to the following VRFs:\n",
15149 get_afi_safi_str(afi, safi, false));
15150
15151 for (ALL_LIST_ELEMENTS_RO(
15152 bgp->vpn_policy[afi].export_vrf,
15153 node, vname))
15154 vty_out(vty, " %s\n", vname);
15155
15156 vty_out(vty, "RD: %pRD\n",
15157 &bgp->vpn_policy[afi].tovpn_rd);
15158
15159 dir = BGP_VPN_POLICY_DIR_TOVPN;
15160 if (bgp->vpn_policy[afi].rtlist[dir]) {
15161 ecom_str = ecommunity_ecom2str(
15162 bgp->vpn_policy[afi].rtlist[dir],
15163 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15164 vty_out(vty, "Export RT: %s\n", ecom_str);
15165 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15166 } else
15167 vty_out(vty, "Import RT(s):\n");
15168 }
15169 }
15170
15171 return CMD_SUCCESS;
15172 }
15173
15174 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15175 safi_t safi, bool use_json)
15176 {
15177 struct listnode *node, *nnode;
15178 struct bgp *bgp;
15179 char *vrf_name = NULL;
15180 json_object *json = NULL;
15181 json_object *json_vrf = NULL;
15182 json_object *json_vrfs = NULL;
15183
15184 if (use_json) {
15185 json = json_object_new_object();
15186 json_vrfs = json_object_new_object();
15187 }
15188
15189 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15190
15191 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15192 vrf_name = bgp->name;
15193
15194 if (use_json) {
15195 json_vrf = json_object_new_object();
15196 } else {
15197 vty_out(vty, "\nInstance %s:\n",
15198 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15199 ? VRF_DEFAULT_NAME : bgp->name);
15200 }
15201 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15202 if (use_json) {
15203 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15204 json_object_object_add(json_vrfs,
15205 VRF_DEFAULT_NAME, json_vrf);
15206 else
15207 json_object_object_add(json_vrfs, vrf_name,
15208 json_vrf);
15209 }
15210 }
15211
15212 if (use_json) {
15213 json_object_object_add(json, "vrfs", json_vrfs);
15214 vty_json(vty, json);
15215 }
15216
15217 return CMD_SUCCESS;
15218 }
15219
15220 /* "show [ip] bgp route-leak" command. */
15221 DEFUN (show_ip_bgp_route_leak,
15222 show_ip_bgp_route_leak_cmd,
15223 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15224 SHOW_STR
15225 IP_STR
15226 BGP_STR
15227 BGP_INSTANCE_HELP_STR
15228 BGP_AFI_HELP_STR
15229 BGP_SAFI_HELP_STR
15230 "Route leaking information\n"
15231 JSON_STR)
15232 {
15233 char *vrf = NULL;
15234 afi_t afi = AFI_MAX;
15235 safi_t safi = SAFI_MAX;
15236
15237 bool uj = use_json(argc, argv);
15238 int idx = 0;
15239 json_object *json = NULL;
15240
15241 /* show [ip] bgp */
15242 if (argv_find(argv, argc, "ip", &idx)) {
15243 afi = AFI_IP;
15244 safi = SAFI_UNICAST;
15245 }
15246 /* [vrf VIEWVRFNAME] */
15247 if (argv_find(argv, argc, "view", &idx)) {
15248 vty_out(vty,
15249 "%% This command is not applicable to BGP views\n");
15250 return CMD_WARNING;
15251 }
15252
15253 if (argv_find(argv, argc, "vrf", &idx)) {
15254 vrf = argv[idx + 1]->arg;
15255 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15256 vrf = NULL;
15257 }
15258 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15259 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15260 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15261
15262 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15263 vty_out(vty,
15264 "%% This command is applicable only for unicast ipv4|ipv6\n");
15265 return CMD_WARNING;
15266 }
15267
15268 if (vrf && strmatch(vrf, "all"))
15269 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15270
15271 if (uj)
15272 json = json_object_new_object();
15273
15274 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15275 }
15276
15277 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15278 safi_t safi)
15279 {
15280 struct listnode *node, *nnode;
15281 struct bgp *bgp;
15282
15283 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15284 vty_out(vty, "\nInstance %s:\n",
15285 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15286 ? VRF_DEFAULT_NAME
15287 : bgp->name);
15288 update_group_show(bgp, afi, safi, vty, 0);
15289 }
15290 }
15291
15292 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15293 int safi, uint64_t subgrp_id)
15294 {
15295 struct bgp *bgp;
15296
15297 if (name) {
15298 if (strmatch(name, "all")) {
15299 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15300 return CMD_SUCCESS;
15301 } else {
15302 bgp = bgp_lookup_by_name(name);
15303 }
15304 } else {
15305 bgp = bgp_get_default();
15306 }
15307
15308 if (bgp)
15309 update_group_show(bgp, afi, safi, vty, subgrp_id);
15310 return CMD_SUCCESS;
15311 }
15312
15313 DEFUN (show_ip_bgp_updgrps,
15314 show_ip_bgp_updgrps_cmd,
15315 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15316 SHOW_STR
15317 IP_STR
15318 BGP_STR
15319 BGP_INSTANCE_HELP_STR
15320 BGP_AFI_HELP_STR
15321 BGP_SAFI_WITH_LABEL_HELP_STR
15322 "Detailed info about dynamic update groups\n"
15323 "Specific subgroup to display detailed info for\n")
15324 {
15325 char *vrf = NULL;
15326 afi_t afi = AFI_IP6;
15327 safi_t safi = SAFI_UNICAST;
15328 uint64_t subgrp_id = 0;
15329
15330 int idx = 0;
15331
15332 /* show [ip] bgp */
15333 if (argv_find(argv, argc, "ip", &idx))
15334 afi = AFI_IP;
15335 /* [<vrf> VIEWVRFNAME] */
15336 if (argv_find(argv, argc, "vrf", &idx)) {
15337 vrf = argv[idx + 1]->arg;
15338 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15339 vrf = NULL;
15340 } else if (argv_find(argv, argc, "view", &idx))
15341 /* [<view> VIEWVRFNAME] */
15342 vrf = argv[idx + 1]->arg;
15343 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15344 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15345 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15346 }
15347
15348 /* get subgroup id, if provided */
15349 idx = argc - 1;
15350 if (argv[idx]->type == VARIABLE_TKN)
15351 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15352
15353 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15354 }
15355
15356 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15357 show_bgp_instance_all_ipv6_updgrps_cmd,
15358 "show [ip] bgp <view|vrf> all update-groups",
15359 SHOW_STR
15360 IP_STR
15361 BGP_STR
15362 BGP_INSTANCE_ALL_HELP_STR
15363 "Detailed info about dynamic update groups\n")
15364 {
15365 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15366 return CMD_SUCCESS;
15367 }
15368
15369 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15370 show_bgp_l2vpn_evpn_updgrps_cmd,
15371 "show [ip] bgp l2vpn evpn update-groups",
15372 SHOW_STR
15373 IP_STR
15374 BGP_STR
15375 "l2vpn address family\n"
15376 "evpn sub-address family\n"
15377 "Detailed info about dynamic update groups\n")
15378 {
15379 char *vrf = NULL;
15380 uint64_t subgrp_id = 0;
15381
15382 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15383 return CMD_SUCCESS;
15384 }
15385
15386 DEFUN (show_bgp_updgrps_stats,
15387 show_bgp_updgrps_stats_cmd,
15388 "show [ip] bgp update-groups statistics",
15389 SHOW_STR
15390 IP_STR
15391 BGP_STR
15392 "Detailed info about dynamic update groups\n"
15393 "Statistics\n")
15394 {
15395 struct bgp *bgp;
15396
15397 bgp = bgp_get_default();
15398 if (bgp)
15399 update_group_show_stats(bgp, vty);
15400
15401 return CMD_SUCCESS;
15402 }
15403
15404 DEFUN (show_bgp_instance_updgrps_stats,
15405 show_bgp_instance_updgrps_stats_cmd,
15406 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15407 SHOW_STR
15408 IP_STR
15409 BGP_STR
15410 BGP_INSTANCE_HELP_STR
15411 "Detailed info about dynamic update groups\n"
15412 "Statistics\n")
15413 {
15414 int idx_word = 3;
15415 struct bgp *bgp;
15416
15417 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15418 if (bgp)
15419 update_group_show_stats(bgp, vty);
15420
15421 return CMD_SUCCESS;
15422 }
15423
15424 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15425 afi_t afi, safi_t safi,
15426 const char *what, uint64_t subgrp_id)
15427 {
15428 struct bgp *bgp;
15429
15430 if (name)
15431 bgp = bgp_lookup_by_name(name);
15432 else
15433 bgp = bgp_get_default();
15434
15435 if (bgp) {
15436 if (!strcmp(what, "advertise-queue"))
15437 update_group_show_adj_queue(bgp, afi, safi, vty,
15438 subgrp_id);
15439 else if (!strcmp(what, "advertised-routes"))
15440 update_group_show_advertised(bgp, afi, safi, vty,
15441 subgrp_id);
15442 else if (!strcmp(what, "packet-queue"))
15443 update_group_show_packet_queue(bgp, afi, safi, vty,
15444 subgrp_id);
15445 }
15446 }
15447
15448 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15449 show_ip_bgp_instance_updgrps_adj_s_cmd,
15450 "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",
15451 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15452 BGP_SAFI_HELP_STR
15453 "Detailed info about dynamic update groups\n"
15454 "Specific subgroup to display info for\n"
15455 "Advertisement queue\n"
15456 "Announced routes\n"
15457 "Packet queue\n")
15458 {
15459 uint64_t subgrp_id = 0;
15460 afi_t afiz;
15461 safi_t safiz;
15462 if (sgid)
15463 subgrp_id = strtoull(sgid, NULL, 10);
15464
15465 if (!ip && !afi)
15466 afiz = AFI_IP6;
15467 if (!ip && afi)
15468 afiz = bgp_vty_afi_from_str(afi);
15469 if (ip && !afi)
15470 afiz = AFI_IP;
15471 if (ip && afi) {
15472 afiz = bgp_vty_afi_from_str(afi);
15473 if (afiz != AFI_IP)
15474 vty_out(vty,
15475 "%% Cannot specify both 'ip' and 'ipv6'\n");
15476 return CMD_WARNING;
15477 }
15478
15479 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15480
15481 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15482 return CMD_SUCCESS;
15483 }
15484
15485 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15486 json_object *json)
15487 {
15488 struct listnode *node, *nnode;
15489 struct prefix *range;
15490 struct peer *conf;
15491 struct peer *peer;
15492 afi_t afi;
15493 safi_t safi;
15494 const char *peer_status;
15495 int lr_count;
15496 int dynamic;
15497 bool af_cfgd;
15498 json_object *json_peer_group = NULL;
15499 json_object *json_peer_group_afc = NULL;
15500 json_object *json_peer_group_members = NULL;
15501 json_object *json_peer_group_dynamic = NULL;
15502 json_object *json_peer_group_dynamic_af = NULL;
15503 json_object *json_peer_group_ranges = NULL;
15504
15505 conf = group->conf;
15506
15507 if (json) {
15508 json_peer_group = json_object_new_object();
15509 json_peer_group_afc = json_object_new_array();
15510 }
15511
15512 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15513 if (json)
15514 json_object_int_add(json_peer_group, "remoteAs",
15515 conf->as);
15516 else
15517 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15518 group->name, conf->as);
15519 } else if (conf->as_type == AS_INTERNAL) {
15520 if (json)
15521 json_object_int_add(json_peer_group, "remoteAs",
15522 group->bgp->as);
15523 else
15524 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15525 group->name, group->bgp->as);
15526 } else {
15527 if (!json)
15528 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15529 }
15530
15531 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15532 if (json)
15533 json_object_string_add(json_peer_group, "type",
15534 "internal");
15535 else
15536 vty_out(vty, " Peer-group type is internal\n");
15537 } else {
15538 if (json)
15539 json_object_string_add(json_peer_group, "type",
15540 "external");
15541 else
15542 vty_out(vty, " Peer-group type is external\n");
15543 }
15544
15545 /* Display AFs configured. */
15546 if (!json)
15547 vty_out(vty, " Configured address-families:");
15548
15549 FOREACH_AFI_SAFI (afi, safi) {
15550 if (conf->afc[afi][safi]) {
15551 af_cfgd = true;
15552 if (json)
15553 json_object_array_add(
15554 json_peer_group_afc,
15555 json_object_new_string(get_afi_safi_str(
15556 afi, safi, false)));
15557 else
15558 vty_out(vty, " %s;",
15559 get_afi_safi_str(afi, safi, false));
15560 }
15561 }
15562
15563 if (json) {
15564 json_object_object_add(json_peer_group,
15565 "addressFamiliesConfigured",
15566 json_peer_group_afc);
15567 } else {
15568 if (!af_cfgd)
15569 vty_out(vty, " none\n");
15570 else
15571 vty_out(vty, "\n");
15572 }
15573
15574 /* Display listen ranges (for dynamic neighbors), if any */
15575 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15576 lr_count = listcount(group->listen_range[afi]);
15577 if (lr_count) {
15578 if (json) {
15579 if (!json_peer_group_dynamic)
15580 json_peer_group_dynamic =
15581 json_object_new_object();
15582
15583 json_peer_group_dynamic_af =
15584 json_object_new_object();
15585 json_peer_group_ranges =
15586 json_object_new_array();
15587 json_object_int_add(json_peer_group_dynamic_af,
15588 "count", lr_count);
15589 } else {
15590 vty_out(vty, " %d %s listen range(s)\n",
15591 lr_count, afi2str(afi));
15592 }
15593
15594 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15595 nnode, range)) {
15596 if (json) {
15597 char buf[BUFSIZ];
15598
15599 snprintfrr(buf, sizeof(buf), "%pFX",
15600 range);
15601
15602 json_object_array_add(
15603 json_peer_group_ranges,
15604 json_object_new_string(buf));
15605 } else {
15606 vty_out(vty, " %pFX\n", range);
15607 }
15608 }
15609
15610 if (json) {
15611 json_object_object_add(
15612 json_peer_group_dynamic_af, "ranges",
15613 json_peer_group_ranges);
15614
15615 json_object_object_add(
15616 json_peer_group_dynamic, afi2str(afi),
15617 json_peer_group_dynamic_af);
15618 }
15619 }
15620 }
15621
15622 if (json_peer_group_dynamic)
15623 json_object_object_add(json_peer_group, "dynamicRanges",
15624 json_peer_group_dynamic);
15625
15626 /* Display group members and their status */
15627 if (listcount(group->peer)) {
15628 if (json)
15629 json_peer_group_members = json_object_new_object();
15630 else
15631 vty_out(vty, " Peer-group members:\n");
15632 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15633 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15634 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15635 peer_status = "Idle (Admin)";
15636 else if (CHECK_FLAG(peer->sflags,
15637 PEER_STATUS_PREFIX_OVERFLOW))
15638 peer_status = "Idle (PfxCt)";
15639 else
15640 peer_status = lookup_msg(bgp_status_msg,
15641 peer->status, NULL);
15642
15643 dynamic = peer_dynamic_neighbor(peer);
15644
15645 if (json) {
15646 json_object *json_peer_group_member =
15647 json_object_new_object();
15648
15649 json_object_string_add(json_peer_group_member,
15650 "status", peer_status);
15651
15652 if (dynamic)
15653 json_object_boolean_true_add(
15654 json_peer_group_member,
15655 "dynamic");
15656
15657 json_object_object_add(json_peer_group_members,
15658 peer->host,
15659 json_peer_group_member);
15660 } else {
15661 vty_out(vty, " %s %s %s \n", peer->host,
15662 dynamic ? "(dynamic)" : "",
15663 peer_status);
15664 }
15665 }
15666 if (json)
15667 json_object_object_add(json_peer_group, "members",
15668 json_peer_group_members);
15669 }
15670
15671 if (json)
15672 json_object_object_add(json, group->name, json_peer_group);
15673
15674 return CMD_SUCCESS;
15675 }
15676
15677 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15678 const char *group_name, bool uj)
15679 {
15680 struct bgp *bgp;
15681 struct listnode *node, *nnode;
15682 struct peer_group *group;
15683 bool found = false;
15684 json_object *json = NULL;
15685
15686 if (uj)
15687 json = json_object_new_object();
15688
15689 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15690
15691 if (!bgp) {
15692 if (uj)
15693 vty_json(vty, json);
15694 else
15695 vty_out(vty, "%% BGP instance not found\n");
15696
15697 return CMD_WARNING;
15698 }
15699
15700 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15701 if (group_name) {
15702 if (strmatch(group->name, group_name)) {
15703 bgp_show_one_peer_group(vty, group, json);
15704 found = true;
15705 break;
15706 }
15707 } else {
15708 bgp_show_one_peer_group(vty, group, json);
15709 }
15710 }
15711
15712 if (group_name && !found && !uj)
15713 vty_out(vty, "%% No such peer-group\n");
15714
15715 if (uj)
15716 vty_json(vty, json);
15717
15718 return CMD_SUCCESS;
15719 }
15720
15721 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15722 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15723 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15724 "Detailed information on BGP peer groups\n"
15725 "Peer group name\n" JSON_STR)
15726 {
15727 char *vrf, *pg;
15728 int idx = 0;
15729 bool uj = use_json(argc, argv);
15730
15731 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15732 : NULL;
15733 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15734
15735 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15736 }
15737
15738
15739 /* Redistribute VTY commands. */
15740
15741 DEFUN (bgp_redistribute_ipv4,
15742 bgp_redistribute_ipv4_cmd,
15743 "redistribute " FRR_IP_REDIST_STR_BGPD,
15744 "Redistribute information from another routing protocol\n"
15745 FRR_IP_REDIST_HELP_STR_BGPD)
15746 {
15747 VTY_DECLVAR_CONTEXT(bgp, bgp);
15748 int idx_protocol = 1;
15749 int type;
15750
15751 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15752 if (type < 0) {
15753 vty_out(vty, "%% Invalid route type\n");
15754 return CMD_WARNING_CONFIG_FAILED;
15755 }
15756
15757 bgp_redist_add(bgp, AFI_IP, type, 0);
15758 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15759 }
15760
15761 ALIAS_HIDDEN(
15762 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15763 "redistribute " FRR_IP_REDIST_STR_BGPD,
15764 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15765
15766 DEFUN (bgp_redistribute_ipv4_rmap,
15767 bgp_redistribute_ipv4_rmap_cmd,
15768 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15769 "Redistribute information from another routing protocol\n"
15770 FRR_IP_REDIST_HELP_STR_BGPD
15771 "Route map reference\n"
15772 "Pointer to route-map entries\n")
15773 {
15774 VTY_DECLVAR_CONTEXT(bgp, bgp);
15775 int idx_protocol = 1;
15776 int idx_word = 3;
15777 int type;
15778 struct bgp_redist *red;
15779 bool changed;
15780 struct route_map *route_map = route_map_lookup_warn_noexist(
15781 vty, argv[idx_word]->arg);
15782
15783 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15784 if (type < 0) {
15785 vty_out(vty, "%% Invalid route type\n");
15786 return CMD_WARNING_CONFIG_FAILED;
15787 }
15788
15789 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15790 changed =
15791 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15792 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15793 }
15794
15795 ALIAS_HIDDEN(
15796 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15797 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15798 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15799 "Route map reference\n"
15800 "Pointer to route-map entries\n")
15801
15802 DEFUN (bgp_redistribute_ipv4_metric,
15803 bgp_redistribute_ipv4_metric_cmd,
15804 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15805 "Redistribute information from another routing protocol\n"
15806 FRR_IP_REDIST_HELP_STR_BGPD
15807 "Metric for redistributed routes\n"
15808 "Default metric\n")
15809 {
15810 VTY_DECLVAR_CONTEXT(bgp, bgp);
15811 int idx_protocol = 1;
15812 int idx_number = 3;
15813 int type;
15814 uint32_t metric;
15815 struct bgp_redist *red;
15816 bool changed;
15817
15818 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15819 if (type < 0) {
15820 vty_out(vty, "%% Invalid route type\n");
15821 return CMD_WARNING_CONFIG_FAILED;
15822 }
15823 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15824
15825 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15826 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15827 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15828 }
15829
15830 ALIAS_HIDDEN(
15831 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15832 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15833 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15834 "Metric for redistributed routes\n"
15835 "Default metric\n")
15836
15837 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15838 bgp_redistribute_ipv4_rmap_metric_cmd,
15839 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15840 "Redistribute information from another routing protocol\n"
15841 FRR_IP_REDIST_HELP_STR_BGPD
15842 "Route map reference\n"
15843 "Pointer to route-map entries\n"
15844 "Metric for redistributed routes\n"
15845 "Default metric\n")
15846 {
15847 VTY_DECLVAR_CONTEXT(bgp, bgp);
15848 int idx_protocol = 1;
15849 int idx_word = 3;
15850 int idx_number = 5;
15851 int type;
15852 uint32_t metric;
15853 struct bgp_redist *red;
15854 bool changed;
15855 struct route_map *route_map =
15856 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15857
15858 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15859 if (type < 0) {
15860 vty_out(vty, "%% Invalid route type\n");
15861 return CMD_WARNING_CONFIG_FAILED;
15862 }
15863 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15864
15865 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15866 changed =
15867 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15868 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15869 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15870 }
15871
15872 ALIAS_HIDDEN(
15873 bgp_redistribute_ipv4_rmap_metric,
15874 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15875 "redistribute " FRR_IP_REDIST_STR_BGPD
15876 " route-map RMAP_NAME metric (0-4294967295)",
15877 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15878 "Route map reference\n"
15879 "Pointer to route-map entries\n"
15880 "Metric for redistributed routes\n"
15881 "Default metric\n")
15882
15883 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15884 bgp_redistribute_ipv4_metric_rmap_cmd,
15885 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15886 "Redistribute information from another routing protocol\n"
15887 FRR_IP_REDIST_HELP_STR_BGPD
15888 "Metric for redistributed routes\n"
15889 "Default metric\n"
15890 "Route map reference\n"
15891 "Pointer to route-map entries\n")
15892 {
15893 VTY_DECLVAR_CONTEXT(bgp, bgp);
15894 int idx_protocol = 1;
15895 int idx_number = 3;
15896 int idx_word = 5;
15897 int type;
15898 uint32_t metric;
15899 struct bgp_redist *red;
15900 bool changed;
15901 struct route_map *route_map =
15902 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15903
15904 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15905 if (type < 0) {
15906 vty_out(vty, "%% Invalid route type\n");
15907 return CMD_WARNING_CONFIG_FAILED;
15908 }
15909 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15910
15911 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15912 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15913 changed |=
15914 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15915 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15916 }
15917
15918 ALIAS_HIDDEN(
15919 bgp_redistribute_ipv4_metric_rmap,
15920 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15921 "redistribute " FRR_IP_REDIST_STR_BGPD
15922 " metric (0-4294967295) route-map RMAP_NAME",
15923 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15924 "Metric for redistributed routes\n"
15925 "Default metric\n"
15926 "Route map reference\n"
15927 "Pointer to route-map entries\n")
15928
15929 DEFUN (bgp_redistribute_ipv4_ospf,
15930 bgp_redistribute_ipv4_ospf_cmd,
15931 "redistribute <ospf|table> (1-65535)",
15932 "Redistribute information from another routing protocol\n"
15933 "Open Shortest Path First (OSPFv2)\n"
15934 "Non-main Kernel Routing Table\n"
15935 "Instance ID/Table ID\n")
15936 {
15937 VTY_DECLVAR_CONTEXT(bgp, bgp);
15938 int idx_ospf_table = 1;
15939 int idx_number = 2;
15940 unsigned short instance;
15941 unsigned short protocol;
15942
15943 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15944
15945 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15946 protocol = ZEBRA_ROUTE_OSPF;
15947 else
15948 protocol = ZEBRA_ROUTE_TABLE;
15949
15950 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15951 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15952 }
15953
15954 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15955 "redistribute <ospf|table> (1-65535)",
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
15961 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15962 bgp_redistribute_ipv4_ospf_rmap_cmd,
15963 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15964 "Redistribute information from another routing protocol\n"
15965 "Open Shortest Path First (OSPFv2)\n"
15966 "Non-main Kernel Routing Table\n"
15967 "Instance ID/Table ID\n"
15968 "Route map reference\n"
15969 "Pointer to route-map entries\n")
15970 {
15971 VTY_DECLVAR_CONTEXT(bgp, bgp);
15972 int idx_ospf_table = 1;
15973 int idx_number = 2;
15974 int idx_word = 4;
15975 struct bgp_redist *red;
15976 unsigned short instance;
15977 int protocol;
15978 bool changed;
15979 struct route_map *route_map =
15980 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15981
15982 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15983 protocol = ZEBRA_ROUTE_OSPF;
15984 else
15985 protocol = ZEBRA_ROUTE_TABLE;
15986
15987 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15988 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15989 changed =
15990 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15991 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15992 }
15993
15994 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15995 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15996 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15997 "Redistribute information from another routing protocol\n"
15998 "Open Shortest Path First (OSPFv2)\n"
15999 "Non-main Kernel Routing Table\n"
16000 "Instance ID/Table ID\n"
16001 "Route map reference\n"
16002 "Pointer to route-map entries\n")
16003
16004 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16005 bgp_redistribute_ipv4_ospf_metric_cmd,
16006 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16007 "Redistribute information from another routing protocol\n"
16008 "Open Shortest Path First (OSPFv2)\n"
16009 "Non-main Kernel Routing Table\n"
16010 "Instance ID/Table ID\n"
16011 "Metric for redistributed routes\n"
16012 "Default metric\n")
16013 {
16014 VTY_DECLVAR_CONTEXT(bgp, bgp);
16015 int idx_ospf_table = 1;
16016 int idx_number = 2;
16017 int idx_number_2 = 4;
16018 uint32_t metric;
16019 struct bgp_redist *red;
16020 unsigned short instance;
16021 int protocol;
16022 bool changed;
16023
16024 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16025 protocol = ZEBRA_ROUTE_OSPF;
16026 else
16027 protocol = ZEBRA_ROUTE_TABLE;
16028
16029 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16030 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16031
16032 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16033 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16034 metric);
16035 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16036 }
16037
16038 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16039 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16040 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16041 "Redistribute information from another routing protocol\n"
16042 "Open Shortest Path First (OSPFv2)\n"
16043 "Non-main Kernel Routing Table\n"
16044 "Instance ID/Table ID\n"
16045 "Metric for redistributed routes\n"
16046 "Default metric\n")
16047
16048 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16049 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16050 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16051 "Redistribute information from another routing protocol\n"
16052 "Open Shortest Path First (OSPFv2)\n"
16053 "Non-main Kernel Routing Table\n"
16054 "Instance ID/Table ID\n"
16055 "Route map reference\n"
16056 "Pointer to route-map entries\n"
16057 "Metric for redistributed routes\n"
16058 "Default metric\n")
16059 {
16060 VTY_DECLVAR_CONTEXT(bgp, bgp);
16061 int idx_ospf_table = 1;
16062 int idx_number = 2;
16063 int idx_word = 4;
16064 int idx_number_2 = 6;
16065 uint32_t metric;
16066 struct bgp_redist *red;
16067 unsigned short instance;
16068 int protocol;
16069 bool changed;
16070 struct route_map *route_map =
16071 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16072
16073 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16074 protocol = ZEBRA_ROUTE_OSPF;
16075 else
16076 protocol = ZEBRA_ROUTE_TABLE;
16077
16078 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16079 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16080
16081 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16082 changed =
16083 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16084 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16085 metric);
16086 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16087 }
16088
16089 ALIAS_HIDDEN(
16090 bgp_redistribute_ipv4_ospf_rmap_metric,
16091 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16092 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16093 "Redistribute information from another routing protocol\n"
16094 "Open Shortest Path First (OSPFv2)\n"
16095 "Non-main Kernel Routing Table\n"
16096 "Instance ID/Table ID\n"
16097 "Route map reference\n"
16098 "Pointer to route-map entries\n"
16099 "Metric for redistributed routes\n"
16100 "Default metric\n")
16101
16102 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16103 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16104 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16105 "Redistribute information from another routing protocol\n"
16106 "Open Shortest Path First (OSPFv2)\n"
16107 "Non-main Kernel Routing Table\n"
16108 "Instance ID/Table ID\n"
16109 "Metric for redistributed routes\n"
16110 "Default metric\n"
16111 "Route map reference\n"
16112 "Pointer to route-map entries\n")
16113 {
16114 VTY_DECLVAR_CONTEXT(bgp, bgp);
16115 int idx_ospf_table = 1;
16116 int idx_number = 2;
16117 int idx_number_2 = 4;
16118 int idx_word = 6;
16119 uint32_t metric;
16120 struct bgp_redist *red;
16121 unsigned short instance;
16122 int protocol;
16123 bool changed;
16124 struct route_map *route_map =
16125 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16126
16127 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16128 protocol = ZEBRA_ROUTE_OSPF;
16129 else
16130 protocol = ZEBRA_ROUTE_TABLE;
16131
16132 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16133 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16134
16135 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16136 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16137 metric);
16138 changed |=
16139 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16140 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16141 }
16142
16143 ALIAS_HIDDEN(
16144 bgp_redistribute_ipv4_ospf_metric_rmap,
16145 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16146 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16147 "Redistribute information from another routing protocol\n"
16148 "Open Shortest Path First (OSPFv2)\n"
16149 "Non-main Kernel Routing Table\n"
16150 "Instance ID/Table ID\n"
16151 "Metric for redistributed routes\n"
16152 "Default metric\n"
16153 "Route map reference\n"
16154 "Pointer to route-map entries\n")
16155
16156 DEFUN (no_bgp_redistribute_ipv4_ospf,
16157 no_bgp_redistribute_ipv4_ospf_cmd,
16158 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16159 NO_STR
16160 "Redistribute information from another routing protocol\n"
16161 "Open Shortest Path First (OSPFv2)\n"
16162 "Non-main Kernel Routing Table\n"
16163 "Instance ID/Table ID\n"
16164 "Metric for redistributed routes\n"
16165 "Default metric\n"
16166 "Route map reference\n"
16167 "Pointer to route-map entries\n")
16168 {
16169 VTY_DECLVAR_CONTEXT(bgp, bgp);
16170 int idx_ospf_table = 2;
16171 int idx_number = 3;
16172 unsigned short instance;
16173 int protocol;
16174
16175 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16176 protocol = ZEBRA_ROUTE_OSPF;
16177 else
16178 protocol = ZEBRA_ROUTE_TABLE;
16179
16180 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16181 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16182 }
16183
16184 ALIAS_HIDDEN(
16185 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16186 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16187 NO_STR
16188 "Redistribute information from another routing protocol\n"
16189 "Open Shortest Path First (OSPFv2)\n"
16190 "Non-main Kernel Routing Table\n"
16191 "Instance ID/Table ID\n"
16192 "Metric for redistributed routes\n"
16193 "Default metric\n"
16194 "Route map reference\n"
16195 "Pointer to route-map entries\n")
16196
16197 DEFUN (no_bgp_redistribute_ipv4,
16198 no_bgp_redistribute_ipv4_cmd,
16199 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16200 NO_STR
16201 "Redistribute information from another routing protocol\n"
16202 FRR_IP_REDIST_HELP_STR_BGPD
16203 "Metric for redistributed routes\n"
16204 "Default metric\n"
16205 "Route map reference\n"
16206 "Pointer to route-map entries\n")
16207 {
16208 VTY_DECLVAR_CONTEXT(bgp, bgp);
16209 int idx_protocol = 2;
16210 int type;
16211
16212 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16213 if (type < 0) {
16214 vty_out(vty, "%% Invalid route type\n");
16215 return CMD_WARNING_CONFIG_FAILED;
16216 }
16217 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16218 }
16219
16220 ALIAS_HIDDEN(
16221 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16222 "no redistribute " FRR_IP_REDIST_STR_BGPD
16223 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16224 NO_STR
16225 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16226 "Metric for redistributed routes\n"
16227 "Default metric\n"
16228 "Route map reference\n"
16229 "Pointer to route-map entries\n")
16230
16231 DEFUN (bgp_redistribute_ipv6,
16232 bgp_redistribute_ipv6_cmd,
16233 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16234 "Redistribute information from another routing protocol\n"
16235 FRR_IP6_REDIST_HELP_STR_BGPD)
16236 {
16237 VTY_DECLVAR_CONTEXT(bgp, bgp);
16238 int idx_protocol = 1;
16239 int type;
16240
16241 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16242 if (type < 0) {
16243 vty_out(vty, "%% Invalid route type\n");
16244 return CMD_WARNING_CONFIG_FAILED;
16245 }
16246
16247 bgp_redist_add(bgp, AFI_IP6, type, 0);
16248 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16249 }
16250
16251 DEFUN (bgp_redistribute_ipv6_rmap,
16252 bgp_redistribute_ipv6_rmap_cmd,
16253 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16254 "Redistribute information from another routing protocol\n"
16255 FRR_IP6_REDIST_HELP_STR_BGPD
16256 "Route map reference\n"
16257 "Pointer to route-map entries\n")
16258 {
16259 VTY_DECLVAR_CONTEXT(bgp, bgp);
16260 int idx_protocol = 1;
16261 int idx_word = 3;
16262 int type;
16263 struct bgp_redist *red;
16264 bool changed;
16265 struct route_map *route_map =
16266 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16267
16268 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16269 if (type < 0) {
16270 vty_out(vty, "%% Invalid route type\n");
16271 return CMD_WARNING_CONFIG_FAILED;
16272 }
16273
16274 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16275 changed =
16276 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16277 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16278 }
16279
16280 DEFUN (bgp_redistribute_ipv6_metric,
16281 bgp_redistribute_ipv6_metric_cmd,
16282 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16283 "Redistribute information from another routing protocol\n"
16284 FRR_IP6_REDIST_HELP_STR_BGPD
16285 "Metric for redistributed routes\n"
16286 "Default metric\n")
16287 {
16288 VTY_DECLVAR_CONTEXT(bgp, bgp);
16289 int idx_protocol = 1;
16290 int idx_number = 3;
16291 int type;
16292 uint32_t metric;
16293 struct bgp_redist *red;
16294 bool changed;
16295
16296 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16297 if (type < 0) {
16298 vty_out(vty, "%% Invalid route type\n");
16299 return CMD_WARNING_CONFIG_FAILED;
16300 }
16301 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16302
16303 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16304 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16305 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16306 }
16307
16308 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16309 bgp_redistribute_ipv6_rmap_metric_cmd,
16310 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16311 "Redistribute information from another routing protocol\n"
16312 FRR_IP6_REDIST_HELP_STR_BGPD
16313 "Route map reference\n"
16314 "Pointer to route-map entries\n"
16315 "Metric for redistributed routes\n"
16316 "Default metric\n")
16317 {
16318 VTY_DECLVAR_CONTEXT(bgp, bgp);
16319 int idx_protocol = 1;
16320 int idx_word = 3;
16321 int idx_number = 5;
16322 int type;
16323 uint32_t metric;
16324 struct bgp_redist *red;
16325 bool changed;
16326 struct route_map *route_map =
16327 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16328
16329 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16330 if (type < 0) {
16331 vty_out(vty, "%% Invalid route type\n");
16332 return CMD_WARNING_CONFIG_FAILED;
16333 }
16334 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16335
16336 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16337 changed =
16338 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16339 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16340 metric);
16341 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16342 }
16343
16344 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16345 bgp_redistribute_ipv6_metric_rmap_cmd,
16346 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16347 "Redistribute information from another routing protocol\n"
16348 FRR_IP6_REDIST_HELP_STR_BGPD
16349 "Metric for redistributed routes\n"
16350 "Default metric\n"
16351 "Route map reference\n"
16352 "Pointer to route-map entries\n")
16353 {
16354 VTY_DECLVAR_CONTEXT(bgp, bgp);
16355 int idx_protocol = 1;
16356 int idx_number = 3;
16357 int idx_word = 5;
16358 int type;
16359 uint32_t metric;
16360 struct bgp_redist *red;
16361 bool changed;
16362 struct route_map *route_map =
16363 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16364
16365 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16366 if (type < 0) {
16367 vty_out(vty, "%% Invalid route type\n");
16368 return CMD_WARNING_CONFIG_FAILED;
16369 }
16370 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16371
16372 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16373 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16374 metric);
16375 changed |=
16376 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16377 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16378 }
16379
16380 DEFUN (no_bgp_redistribute_ipv6,
16381 no_bgp_redistribute_ipv6_cmd,
16382 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16383 NO_STR
16384 "Redistribute information from another routing protocol\n"
16385 FRR_IP6_REDIST_HELP_STR_BGPD
16386 "Metric for redistributed routes\n"
16387 "Default metric\n"
16388 "Route map reference\n"
16389 "Pointer to route-map entries\n")
16390 {
16391 VTY_DECLVAR_CONTEXT(bgp, bgp);
16392 int idx_protocol = 2;
16393 int type;
16394
16395 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16396 if (type < 0) {
16397 vty_out(vty, "%% Invalid route type\n");
16398 return CMD_WARNING_CONFIG_FAILED;
16399 }
16400
16401 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16402 }
16403
16404 /* Neighbor update tcp-mss. */
16405 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16406 const char *tcp_mss_str)
16407 {
16408 struct peer *peer;
16409 uint32_t tcp_mss_val = 0;
16410
16411 peer = peer_and_group_lookup_vty(vty, peer_str);
16412 if (!peer)
16413 return CMD_WARNING_CONFIG_FAILED;
16414
16415 if (tcp_mss_str) {
16416 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16417 peer_tcp_mss_set(peer, tcp_mss_val);
16418 } else {
16419 peer_tcp_mss_unset(peer);
16420 }
16421
16422 return CMD_SUCCESS;
16423 }
16424
16425 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16426 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16427 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16428 "TCP max segment size\n"
16429 "TCP MSS value\n")
16430 {
16431 int peer_index = 1;
16432 int mss_index = 3;
16433
16434 vty_out(vty,
16435 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16436 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16437 argv[mss_index]->arg);
16438 }
16439
16440 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16441 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16442 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16443 "TCP max segment size\n"
16444 "TCP MSS value\n")
16445 {
16446 int peer_index = 2;
16447
16448 vty_out(vty,
16449 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16450 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16451 }
16452
16453 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16454 "[no$no] bgp retain route-target all",
16455 NO_STR BGP_STR
16456 "Retain BGP updates\n"
16457 "Retain BGP updates based on route-target values\n"
16458 "Retain all BGP updates\n")
16459 {
16460 bool check;
16461 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16462
16463 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16464 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16465 if (check != !no) {
16466 if (!no)
16467 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16468 [bgp_node_safi(vty)],
16469 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16470 else
16471 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16472 [bgp_node_safi(vty)],
16473 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16474 /* trigger a flush to re-sync with ADJ-RIB-in */
16475 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16476 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16477 }
16478 return CMD_SUCCESS;
16479 }
16480
16481 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16482 afi_t afi, safi_t safi)
16483 {
16484 int i;
16485
16486 /* Unicast redistribution only. */
16487 if (safi != SAFI_UNICAST)
16488 return;
16489
16490 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16491 /* Redistribute BGP does not make sense. */
16492 if (i != ZEBRA_ROUTE_BGP) {
16493 struct list *red_list;
16494 struct listnode *node;
16495 struct bgp_redist *red;
16496
16497 red_list = bgp->redist[afi][i];
16498 if (!red_list)
16499 continue;
16500
16501 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16502 /* "redistribute" configuration. */
16503 vty_out(vty, " redistribute %s",
16504 zebra_route_string(i));
16505 if (red->instance)
16506 vty_out(vty, " %d", red->instance);
16507 if (red->redist_metric_flag)
16508 vty_out(vty, " metric %u",
16509 red->redist_metric);
16510 if (red->rmap.name)
16511 vty_out(vty, " route-map %s",
16512 red->rmap.name);
16513 vty_out(vty, "\n");
16514 }
16515 }
16516 }
16517 }
16518
16519 /* peer-group helpers for config-write */
16520
16521 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16522 {
16523 if (!peer_group_active(peer)) {
16524 if (CHECK_FLAG(peer->flags_invert, flag))
16525 return !CHECK_FLAG(peer->flags, flag);
16526 else
16527 return !!CHECK_FLAG(peer->flags, flag);
16528 }
16529
16530 return !!CHECK_FLAG(peer->flags_override, flag);
16531 }
16532
16533 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16534 uint64_t flag)
16535 {
16536 if (!peer_group_active(peer)) {
16537 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16538 return !peer_af_flag_check(peer, afi, safi, flag);
16539 else
16540 return !!peer_af_flag_check(peer, afi, safi, flag);
16541 }
16542
16543 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16544 }
16545
16546 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16547 uint8_t type, int direct)
16548 {
16549 struct bgp_filter *filter;
16550
16551 if (peer_group_active(peer))
16552 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16553 type);
16554
16555 filter = &peer->filter[afi][safi];
16556 switch (type) {
16557 case PEER_FT_DISTRIBUTE_LIST:
16558 return !!(filter->dlist[direct].name);
16559 case PEER_FT_FILTER_LIST:
16560 return !!(filter->aslist[direct].name);
16561 case PEER_FT_PREFIX_LIST:
16562 return !!(filter->plist[direct].name);
16563 case PEER_FT_ROUTE_MAP:
16564 return !!(filter->map[direct].name);
16565 case PEER_FT_UNSUPPRESS_MAP:
16566 return !!(filter->usmap.name);
16567 case PEER_FT_ADVERTISE_MAP:
16568 return !!(filter->advmap.aname
16569 && ((filter->advmap.condition == direct)
16570 && filter->advmap.cname));
16571 default:
16572 return false;
16573 }
16574 }
16575
16576 /* Return true if the addpath type is set for peer and different from
16577 * peer-group.
16578 */
16579 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16580 safi_t safi)
16581 {
16582 enum bgp_addpath_strat type, g_type;
16583
16584 type = peer->addpath_type[afi][safi];
16585
16586 if (type != BGP_ADDPATH_NONE) {
16587 if (peer_group_active(peer)) {
16588 g_type = peer->group->conf->addpath_type[afi][safi];
16589
16590 if (type != g_type)
16591 return true;
16592 else
16593 return false;
16594 }
16595
16596 return true;
16597 }
16598
16599 return false;
16600 }
16601
16602 /* This is part of the address-family block (unicast only) */
16603 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16604 afi_t afi)
16605 {
16606 int indent = 2;
16607 uint32_t tovpn_sid_index = 0;
16608
16609 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16610 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16611 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16612 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16613 bgp->vpn_policy[afi]
16614 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16615 else
16616 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16617 bgp->vpn_policy[afi]
16618 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16619 }
16620 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16621 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16622 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16623 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16624 return;
16625
16626 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16627 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16628
16629 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16630
16631 } else {
16632 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16633 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16634 bgp->vpn_policy[afi].tovpn_label);
16635 }
16636 }
16637
16638 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16639 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16640 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16641 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16642 } else if (tovpn_sid_index != 0) {
16643 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16644 tovpn_sid_index);
16645 }
16646
16647 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16648 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16649 &bgp->vpn_policy[afi].tovpn_rd);
16650
16651 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16652 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16653
16654 char buf[PREFIX_STRLEN];
16655 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16656 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16657 sizeof(buf))) {
16658
16659 vty_out(vty, "%*snexthop vpn export %s\n",
16660 indent, "", buf);
16661 }
16662 }
16663 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16664 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16665 && ecommunity_cmp(
16666 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16667 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16668
16669 char *b = ecommunity_ecom2str(
16670 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16671 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16672 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16673 XFREE(MTYPE_ECOMMUNITY_STR, b);
16674 } else {
16675 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16676 char *b = ecommunity_ecom2str(
16677 bgp->vpn_policy[afi]
16678 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16679 ECOMMUNITY_FORMAT_ROUTE_MAP,
16680 ECOMMUNITY_ROUTE_TARGET);
16681 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16682 XFREE(MTYPE_ECOMMUNITY_STR, b);
16683 }
16684 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16685 char *b = ecommunity_ecom2str(
16686 bgp->vpn_policy[afi]
16687 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16688 ECOMMUNITY_FORMAT_ROUTE_MAP,
16689 ECOMMUNITY_ROUTE_TARGET);
16690 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16691 XFREE(MTYPE_ECOMMUNITY_STR, b);
16692 }
16693 }
16694
16695 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16696 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16697 bgp->vpn_policy[afi]
16698 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16699
16700 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16701 char *b = ecommunity_ecom2str(
16702 bgp->vpn_policy[afi]
16703 .import_redirect_rtlist,
16704 ECOMMUNITY_FORMAT_ROUTE_MAP,
16705 ECOMMUNITY_ROUTE_TARGET);
16706
16707 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16708 != ECOMMUNITY_SIZE)
16709 vty_out(vty, "%*srt6 redirect import %s\n",
16710 indent, "", b);
16711 else
16712 vty_out(vty, "%*srt redirect import %s\n",
16713 indent, "", b);
16714 XFREE(MTYPE_ECOMMUNITY_STR, b);
16715 }
16716 }
16717
16718 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16719 afi_t afi, safi_t safi)
16720 {
16721 struct bgp_filter *filter;
16722 char *addr;
16723
16724 addr = peer->host;
16725 filter = &peer->filter[afi][safi];
16726
16727 /* distribute-list. */
16728 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16729 FILTER_IN))
16730 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16731 filter->dlist[FILTER_IN].name);
16732
16733 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16734 FILTER_OUT))
16735 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16736 filter->dlist[FILTER_OUT].name);
16737
16738 /* prefix-list. */
16739 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16740 FILTER_IN))
16741 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16742 filter->plist[FILTER_IN].name);
16743
16744 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16745 FILTER_OUT))
16746 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16747 filter->plist[FILTER_OUT].name);
16748
16749 /* route-map. */
16750 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16751 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16752 filter->map[RMAP_IN].name);
16753
16754 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16755 RMAP_OUT))
16756 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16757 filter->map[RMAP_OUT].name);
16758
16759 /* unsuppress-map */
16760 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16761 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16762 filter->usmap.name);
16763
16764 /* advertise-map : always applied in OUT direction*/
16765 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16766 CONDITION_NON_EXIST))
16767 vty_out(vty,
16768 " neighbor %s advertise-map %s non-exist-map %s\n",
16769 addr, filter->advmap.aname, filter->advmap.cname);
16770
16771 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16772 CONDITION_EXIST))
16773 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16774 addr, filter->advmap.aname, filter->advmap.cname);
16775
16776 /* filter-list. */
16777 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16778 FILTER_IN))
16779 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16780 filter->aslist[FILTER_IN].name);
16781
16782 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16783 FILTER_OUT))
16784 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16785 filter->aslist[FILTER_OUT].name);
16786 }
16787
16788 /* BGP peer configuration display function. */
16789 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16790 struct peer *peer)
16791 {
16792 struct peer *g_peer = NULL;
16793 char *addr;
16794 int if_pg_printed = false;
16795 int if_ras_printed = false;
16796
16797 /* Skip dynamic neighbors. */
16798 if (peer_dynamic_neighbor(peer))
16799 return;
16800
16801 if (peer->conf_if)
16802 addr = peer->conf_if;
16803 else
16804 addr = peer->host;
16805
16806 /************************************
16807 ****** Global to the neighbor ******
16808 ************************************/
16809 if (peer->conf_if) {
16810 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16811 vty_out(vty, " neighbor %s interface v6only", addr);
16812 else
16813 vty_out(vty, " neighbor %s interface", addr);
16814
16815 if (peer_group_active(peer)) {
16816 vty_out(vty, " peer-group %s", peer->group->name);
16817 if_pg_printed = true;
16818 } else if (peer->as_type == AS_SPECIFIED) {
16819 vty_out(vty, " remote-as %u", peer->as);
16820 if_ras_printed = true;
16821 } else if (peer->as_type == AS_INTERNAL) {
16822 vty_out(vty, " remote-as internal");
16823 if_ras_printed = true;
16824 } else if (peer->as_type == AS_EXTERNAL) {
16825 vty_out(vty, " remote-as external");
16826 if_ras_printed = true;
16827 }
16828
16829 vty_out(vty, "\n");
16830 }
16831
16832 /* remote-as and peer-group */
16833 /* peer is a member of a peer-group */
16834 if (peer_group_active(peer)) {
16835 g_peer = peer->group->conf;
16836
16837 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16838 if (peer->as_type == AS_SPECIFIED) {
16839 vty_out(vty, " neighbor %s remote-as %u\n",
16840 addr, peer->as);
16841 } else if (peer->as_type == AS_INTERNAL) {
16842 vty_out(vty,
16843 " neighbor %s remote-as internal\n",
16844 addr);
16845 } else if (peer->as_type == AS_EXTERNAL) {
16846 vty_out(vty,
16847 " neighbor %s remote-as external\n",
16848 addr);
16849 }
16850 }
16851
16852 /* For swpX peers we displayed the peer-group
16853 * via 'neighbor swpX interface peer-group PGNAME' */
16854 if (!if_pg_printed)
16855 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16856 peer->group->name);
16857 }
16858
16859 /* peer is NOT a member of a peer-group */
16860 else {
16861 /* peer is a peer-group, declare the peer-group */
16862 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16863 vty_out(vty, " neighbor %s peer-group\n", addr);
16864 }
16865
16866 if (!if_ras_printed) {
16867 if (peer->as_type == AS_SPECIFIED) {
16868 vty_out(vty, " neighbor %s remote-as %u\n",
16869 addr, peer->as);
16870 } else if (peer->as_type == AS_INTERNAL) {
16871 vty_out(vty,
16872 " neighbor %s remote-as internal\n",
16873 addr);
16874 } else if (peer->as_type == AS_EXTERNAL) {
16875 vty_out(vty,
16876 " neighbor %s remote-as external\n",
16877 addr);
16878 }
16879 }
16880 }
16881
16882 /* local-as */
16883 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16884 vty_out(vty, " neighbor %s local-as %u", addr,
16885 peer->change_local_as);
16886 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16887 vty_out(vty, " no-prepend");
16888 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16889 vty_out(vty, " replace-as");
16890 vty_out(vty, "\n");
16891 }
16892
16893 /* description */
16894 if (peer->desc) {
16895 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16896 }
16897
16898 /* shutdown */
16899 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16900 if (peer->tx_shutdown_message)
16901 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16902 peer->tx_shutdown_message);
16903 else
16904 vty_out(vty, " neighbor %s shutdown\n", addr);
16905 }
16906
16907 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16908 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16909 peer->rtt_expected, peer->rtt_keepalive_conf);
16910
16911 /* bfd */
16912 if (peer->bfd_config)
16913 bgp_bfd_peer_config_write(vty, peer, addr);
16914
16915 /* password */
16916 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16917 vty_out(vty, " neighbor %s password %s\n", addr,
16918 peer->password);
16919
16920 /* neighbor solo */
16921 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16922 if (!peer_group_active(peer)) {
16923 vty_out(vty, " neighbor %s solo\n", addr);
16924 }
16925 }
16926
16927 /* BGP port */
16928 if (peer->port != BGP_PORT_DEFAULT) {
16929 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16930 }
16931
16932 /* Local interface name */
16933 if (peer->ifname) {
16934 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16935 }
16936
16937 /* TCP max segment size */
16938 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16939 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16940
16941 /* passive */
16942 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16943 vty_out(vty, " neighbor %s passive\n", addr);
16944
16945 /* ebgp-multihop */
16946 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16947 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16948 && peer->ttl == MAXTTL)) {
16949 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16950 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16951 peer->ttl);
16952 }
16953 }
16954
16955 /* role */
16956 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16957 peer->local_role != ROLE_UNDEFINED)
16958 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16959 bgp_get_name_by_role(peer->local_role),
16960 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
16961 ? " strict-mode"
16962 : "");
16963
16964 /* ttl-security hops */
16965 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16966 if (!peer_group_active(peer)
16967 || g_peer->gtsm_hops != peer->gtsm_hops) {
16968 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16969 addr, peer->gtsm_hops);
16970 }
16971 }
16972
16973 /* disable-connected-check */
16974 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16975 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16976
16977 /* link-bw-encoding-ieee */
16978 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16979 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16980 addr);
16981
16982 /* extended-optional-parameters */
16983 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16984 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16985 addr);
16986
16987 /* enforce-first-as */
16988 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16989 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16990
16991 /* update-source */
16992 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16993 if (peer->update_source)
16994 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16995 peer->update_source);
16996 else if (peer->update_if)
16997 vty_out(vty, " neighbor %s update-source %s\n", addr,
16998 peer->update_if);
16999 }
17000
17001 /* advertisement-interval */
17002 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17003 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17004 peer->routeadv);
17005
17006 /* timers */
17007 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17008 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17009 peer->keepalive, peer->holdtime);
17010
17011 /* timers connect */
17012 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17013 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17014 peer->connect);
17015 /* need special-case handling for changed default values due to
17016 * config profile / version (because there is no "timers bgp connect"
17017 * command, we need to save this per-peer :/)
17018 */
17019 else if (!peer_group_active(peer) && !peer->connect &&
17020 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17021 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17022 peer->bgp->default_connect_retry);
17023
17024 /* timers delayopen */
17025 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17026 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17027 peer->delayopen);
17028 /* Save config even though flag is not set if default values have been
17029 * changed
17030 */
17031 else if (!peer_group_active(peer) && !peer->delayopen
17032 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17033 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17034 peer->bgp->default_delayopen);
17035
17036 /* capability dynamic */
17037 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17038 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17039
17040 /* capability extended-nexthop */
17041 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17042 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17043 !peer->conf_if)
17044 vty_out(vty,
17045 " no neighbor %s capability extended-nexthop\n",
17046 addr);
17047 else if (!peer->conf_if)
17048 vty_out(vty,
17049 " neighbor %s capability extended-nexthop\n",
17050 addr);
17051 }
17052
17053 /* dont-capability-negotiation */
17054 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17055 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17056
17057 /* override-capability */
17058 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17059 vty_out(vty, " neighbor %s override-capability\n", addr);
17060
17061 /* strict-capability-match */
17062 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17063 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17064
17065 /* Sender side AS path loop detection. */
17066 if (peer->as_path_loop_detection)
17067 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17068 addr);
17069
17070 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17071 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17072
17073 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17074 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17075 vty_out(vty,
17076 " neighbor %s graceful-restart-helper\n", addr);
17077 } else if (CHECK_FLAG(
17078 peer->peer_gr_new_status_flag,
17079 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17080 vty_out(vty,
17081 " neighbor %s graceful-restart\n", addr);
17082 } else if (
17083 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17084 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17085 && !(CHECK_FLAG(
17086 peer->peer_gr_new_status_flag,
17087 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17088 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17089 addr);
17090 }
17091 }
17092 }
17093
17094 /* BGP peer configuration display function. */
17095 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17096 struct peer *peer, afi_t afi, safi_t safi)
17097 {
17098 struct peer *g_peer = NULL;
17099 char *addr;
17100 bool flag_scomm, flag_secomm, flag_slcomm;
17101
17102 /* Skip dynamic neighbors. */
17103 if (peer_dynamic_neighbor(peer))
17104 return;
17105
17106 if (peer->conf_if)
17107 addr = peer->conf_if;
17108 else
17109 addr = peer->host;
17110
17111 /************************************
17112 ****** Per AF to the neighbor ******
17113 ************************************/
17114 if (peer_group_active(peer)) {
17115 g_peer = peer->group->conf;
17116
17117 /* If the peer-group is active but peer is not, print a 'no
17118 * activate' */
17119 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17120 vty_out(vty, " no neighbor %s activate\n", addr);
17121 }
17122
17123 /* If the peer-group is not active but peer is, print an
17124 'activate' */
17125 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17126 vty_out(vty, " neighbor %s activate\n", addr);
17127 }
17128 } else {
17129 if (peer->afc[afi][safi]) {
17130 if (safi == SAFI_ENCAP)
17131 vty_out(vty, " neighbor %s activate\n", addr);
17132 else if (!bgp->default_af[afi][safi])
17133 vty_out(vty, " neighbor %s activate\n", addr);
17134 } else {
17135 if (bgp->default_af[afi][safi])
17136 vty_out(vty, " no neighbor %s activate\n",
17137 addr);
17138 }
17139 }
17140
17141 /* addpath TX knobs */
17142 if (peergroup_af_addpath_check(peer, afi, safi)) {
17143 switch (peer->addpath_type[afi][safi]) {
17144 case BGP_ADDPATH_ALL:
17145 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17146 addr);
17147 break;
17148 case BGP_ADDPATH_BEST_PER_AS:
17149 vty_out(vty,
17150 " neighbor %s addpath-tx-bestpath-per-AS\n",
17151 addr);
17152 break;
17153 case BGP_ADDPATH_MAX:
17154 case BGP_ADDPATH_NONE:
17155 break;
17156 }
17157 }
17158
17159 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17160 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17161
17162 /* ORF capability. */
17163 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17164 || peergroup_af_flag_check(peer, afi, safi,
17165 PEER_FLAG_ORF_PREFIX_RM)) {
17166 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17167
17168 if (peergroup_af_flag_check(peer, afi, safi,
17169 PEER_FLAG_ORF_PREFIX_SM)
17170 && peergroup_af_flag_check(peer, afi, safi,
17171 PEER_FLAG_ORF_PREFIX_RM))
17172 vty_out(vty, " both");
17173 else if (peergroup_af_flag_check(peer, afi, safi,
17174 PEER_FLAG_ORF_PREFIX_SM))
17175 vty_out(vty, " send");
17176 else
17177 vty_out(vty, " receive");
17178 vty_out(vty, "\n");
17179 }
17180
17181 /* Route reflector client. */
17182 if (peergroup_af_flag_check(peer, afi, safi,
17183 PEER_FLAG_REFLECTOR_CLIENT)) {
17184 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17185 }
17186
17187 /* next-hop-self force */
17188 if (peergroup_af_flag_check(peer, afi, safi,
17189 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17190 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17191 }
17192
17193 /* next-hop-self */
17194 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17195 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17196 }
17197
17198 /* remove-private-AS */
17199 if (peergroup_af_flag_check(peer, afi, safi,
17200 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17201 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17202 addr);
17203 }
17204
17205 else if (peergroup_af_flag_check(peer, afi, safi,
17206 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17207 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17208 addr);
17209 }
17210
17211 else if (peergroup_af_flag_check(peer, afi, safi,
17212 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17213 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17214 }
17215
17216 else if (peergroup_af_flag_check(peer, afi, safi,
17217 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17218 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17219 }
17220
17221 /* as-override */
17222 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17223 vty_out(vty, " neighbor %s as-override\n", addr);
17224 }
17225
17226 /* send-community print. */
17227 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17228 PEER_FLAG_SEND_COMMUNITY);
17229 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17230 PEER_FLAG_SEND_EXT_COMMUNITY);
17231 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17232 PEER_FLAG_SEND_LARGE_COMMUNITY);
17233
17234 if (flag_scomm && flag_secomm && flag_slcomm) {
17235 vty_out(vty, " no neighbor %s send-community all\n", addr);
17236 } else {
17237 if (flag_scomm)
17238 vty_out(vty, " no neighbor %s send-community\n", addr);
17239 if (flag_secomm)
17240 vty_out(vty,
17241 " no neighbor %s send-community extended\n",
17242 addr);
17243
17244 if (flag_slcomm)
17245 vty_out(vty, " no neighbor %s send-community large\n",
17246 addr);
17247 }
17248
17249 /* Default information */
17250 if (peergroup_af_flag_check(peer, afi, safi,
17251 PEER_FLAG_DEFAULT_ORIGINATE)) {
17252 vty_out(vty, " neighbor %s default-originate", addr);
17253
17254 if (peer->default_rmap[afi][safi].name)
17255 vty_out(vty, " route-map %s",
17256 peer->default_rmap[afi][safi].name);
17257
17258 vty_out(vty, "\n");
17259 }
17260
17261 /* Soft reconfiguration inbound. */
17262 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17263 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17264 addr);
17265 }
17266
17267 /* maximum-prefix. */
17268 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17269 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17270 peer->pmax[afi][safi]);
17271
17272 if (peer->pmax_threshold[afi][safi]
17273 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17274 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17275 if (peer_af_flag_check(peer, afi, safi,
17276 PEER_FLAG_MAX_PREFIX_WARNING))
17277 vty_out(vty, " warning-only");
17278 if (peer->pmax_restart[afi][safi])
17279 vty_out(vty, " restart %u",
17280 peer->pmax_restart[afi][safi]);
17281 if (peer_af_flag_check(peer, afi, safi,
17282 PEER_FLAG_MAX_PREFIX_FORCE))
17283 vty_out(vty, " force");
17284
17285 vty_out(vty, "\n");
17286 }
17287
17288 /* maximum-prefix-out */
17289 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17290 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17291 addr, peer->pmax_out[afi][safi]);
17292
17293 /* Route server client. */
17294 if (peergroup_af_flag_check(peer, afi, safi,
17295 PEER_FLAG_RSERVER_CLIENT)) {
17296 vty_out(vty, " neighbor %s route-server-client\n", addr);
17297 }
17298
17299 /* Nexthop-local unchanged. */
17300 if (peergroup_af_flag_check(peer, afi, safi,
17301 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17302 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17303 }
17304
17305 /* allowas-in <1-10> */
17306 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17307 if (peer_af_flag_check(peer, afi, safi,
17308 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17309 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17310 } else if (peer->allowas_in[afi][safi] == 3) {
17311 vty_out(vty, " neighbor %s allowas-in\n", addr);
17312 } else {
17313 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17314 peer->allowas_in[afi][safi]);
17315 }
17316 }
17317
17318 /* soo */
17319 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17320 char *soo_str = ecommunity_ecom2str(
17321 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17322
17323 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17324 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17325 }
17326
17327 /* weight */
17328 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17329 vty_out(vty, " neighbor %s weight %lu\n", addr,
17330 peer->weight[afi][safi]);
17331
17332 /* Filter. */
17333 bgp_config_write_filter(vty, peer, afi, safi);
17334
17335 /* atribute-unchanged. */
17336 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17337 || (safi != SAFI_EVPN
17338 && peer_af_flag_check(peer, afi, safi,
17339 PEER_FLAG_NEXTHOP_UNCHANGED))
17340 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17341
17342 if (!peer_group_active(peer)
17343 || peergroup_af_flag_check(peer, afi, safi,
17344 PEER_FLAG_AS_PATH_UNCHANGED)
17345 || peergroup_af_flag_check(peer, afi, safi,
17346 PEER_FLAG_NEXTHOP_UNCHANGED)
17347 || peergroup_af_flag_check(peer, afi, safi,
17348 PEER_FLAG_MED_UNCHANGED)) {
17349
17350 vty_out(vty,
17351 " neighbor %s attribute-unchanged%s%s%s\n",
17352 addr,
17353 peer_af_flag_check(peer, afi, safi,
17354 PEER_FLAG_AS_PATH_UNCHANGED)
17355 ? " as-path"
17356 : "",
17357 peer_af_flag_check(peer, afi, safi,
17358 PEER_FLAG_NEXTHOP_UNCHANGED)
17359 ? " next-hop"
17360 : "",
17361 peer_af_flag_check(peer, afi, safi,
17362 PEER_FLAG_MED_UNCHANGED)
17363 ? " med"
17364 : "");
17365 }
17366 }
17367 }
17368
17369 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17370 safi_t safi)
17371 {
17372 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17373 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17374 vty_out(vty, " no bgp retain route-target all\n");
17375 }
17376
17377 /* Address family based peer configuration display. */
17378 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17379 safi_t safi)
17380 {
17381 struct peer *peer;
17382 struct peer_group *group;
17383 struct listnode *node, *nnode;
17384
17385
17386 vty_frame(vty, " !\n address-family ");
17387 if (afi == AFI_IP) {
17388 if (safi == SAFI_UNICAST)
17389 vty_frame(vty, "ipv4 unicast");
17390 else if (safi == SAFI_LABELED_UNICAST)
17391 vty_frame(vty, "ipv4 labeled-unicast");
17392 else if (safi == SAFI_MULTICAST)
17393 vty_frame(vty, "ipv4 multicast");
17394 else if (safi == SAFI_MPLS_VPN)
17395 vty_frame(vty, "ipv4 vpn");
17396 else if (safi == SAFI_ENCAP)
17397 vty_frame(vty, "ipv4 encap");
17398 else if (safi == SAFI_FLOWSPEC)
17399 vty_frame(vty, "ipv4 flowspec");
17400 } else if (afi == AFI_IP6) {
17401 if (safi == SAFI_UNICAST)
17402 vty_frame(vty, "ipv6 unicast");
17403 else if (safi == SAFI_LABELED_UNICAST)
17404 vty_frame(vty, "ipv6 labeled-unicast");
17405 else if (safi == SAFI_MULTICAST)
17406 vty_frame(vty, "ipv6 multicast");
17407 else if (safi == SAFI_MPLS_VPN)
17408 vty_frame(vty, "ipv6 vpn");
17409 else if (safi == SAFI_ENCAP)
17410 vty_frame(vty, "ipv6 encap");
17411 else if (safi == SAFI_FLOWSPEC)
17412 vty_frame(vty, "ipv6 flowspec");
17413 } else if (afi == AFI_L2VPN) {
17414 if (safi == SAFI_EVPN)
17415 vty_frame(vty, "l2vpn evpn");
17416 }
17417 vty_frame(vty, "\n");
17418
17419 bgp_config_write_distance(vty, bgp, afi, safi);
17420
17421 bgp_config_write_network(vty, bgp, afi, safi);
17422
17423 bgp_config_write_redistribute(vty, bgp, afi, safi);
17424
17425 /* BGP flag dampening. */
17426 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17427 bgp_config_write_damp(vty, afi, safi);
17428
17429 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17430 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17431
17432 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17433 /* Do not display doppelganger peers */
17434 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17435 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17436 }
17437
17438 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17439 bgp_config_write_table_map(vty, bgp, afi, safi);
17440
17441 if (safi == SAFI_EVPN)
17442 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17443
17444 if (safi == SAFI_FLOWSPEC)
17445 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17446
17447 if (safi == SAFI_MPLS_VPN)
17448 bgp_vpn_config_write(vty, bgp, afi, safi);
17449
17450 if (safi == SAFI_UNICAST) {
17451 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17452 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17453 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17454
17455 vty_out(vty, " export vpn\n");
17456 }
17457 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17458 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17459
17460 vty_out(vty, " import vpn\n");
17461 }
17462 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17463 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17464 char *name;
17465
17466 for (ALL_LIST_ELEMENTS_RO(
17467 bgp->vpn_policy[afi].import_vrf, node,
17468 name))
17469 vty_out(vty, " import vrf %s\n", name);
17470 }
17471 }
17472
17473 vty_endframe(vty, " exit-address-family\n");
17474 }
17475
17476 int bgp_config_write(struct vty *vty)
17477 {
17478 struct bgp *bgp;
17479 struct peer_group *group;
17480 struct peer *peer;
17481 struct listnode *node, *nnode;
17482 struct listnode *mnode, *mnnode;
17483 afi_t afi;
17484 safi_t safi;
17485
17486 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17487 vty_out(vty, "bgp route-map delay-timer %u\n",
17488 bm->rmap_update_timer);
17489
17490 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17491 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17492 if (bm->v_update_delay != bm->v_establish_wait)
17493 vty_out(vty, " %d", bm->v_establish_wait);
17494 vty_out(vty, "\n");
17495 }
17496
17497 if (bm->wait_for_fib)
17498 vty_out(vty, "bgp suppress-fib-pending\n");
17499
17500 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17501 vty_out(vty, "bgp graceful-shutdown\n");
17502
17503 /* No-RIB (Zebra) option flag configuration */
17504 if (bgp_option_check(BGP_OPT_NO_FIB))
17505 vty_out(vty, "bgp no-rib\n");
17506
17507 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17508 vty_out(vty, "bgp send-extra-data zebra\n");
17509
17510 /* BGP session DSCP value */
17511 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17512 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17513
17514 /* BGP configuration. */
17515 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17516
17517 /* skip all auto created vrf as they dont have user config */
17518 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17519 continue;
17520
17521 /* Router bgp ASN */
17522 vty_out(vty, "router bgp %u", bgp->as);
17523
17524 if (bgp->name)
17525 vty_out(vty, " %s %s",
17526 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17527 ? "view" : "vrf", bgp->name);
17528 vty_out(vty, "\n");
17529
17530 /* BGP fast-external-failover. */
17531 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17532 vty_out(vty, " no bgp fast-external-failover\n");
17533
17534 /* BGP router ID. */
17535 if (bgp->router_id_static.s_addr != INADDR_ANY)
17536 vty_out(vty, " bgp router-id %pI4\n",
17537 &bgp->router_id_static);
17538
17539 /* Suppress fib pending */
17540 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17541 vty_out(vty, " bgp suppress-fib-pending\n");
17542
17543 /* BGP log-neighbor-changes. */
17544 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17545 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17546 vty_out(vty, " %sbgp log-neighbor-changes\n",
17547 CHECK_FLAG(bgp->flags,
17548 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17549 ? ""
17550 : "no ");
17551
17552 /* BGP configuration. */
17553 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17554 vty_out(vty, " bgp always-compare-med\n");
17555
17556 /* RFC8212 default eBGP policy. */
17557 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17558 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17559 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17560 CHECK_FLAG(bgp->flags,
17561 BGP_FLAG_EBGP_REQUIRES_POLICY)
17562 ? ""
17563 : "no ");
17564
17565 /* draft-ietf-idr-deprecate-as-set-confed-set */
17566 if (bgp->reject_as_sets)
17567 vty_out(vty, " bgp reject-as-sets\n");
17568
17569 /* Suppress duplicate updates if the route actually not changed
17570 */
17571 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17572 != SAVE_BGP_SUPPRESS_DUPLICATES)
17573 vty_out(vty, " %sbgp suppress-duplicates\n",
17574 CHECK_FLAG(bgp->flags,
17575 BGP_FLAG_SUPPRESS_DUPLICATES)
17576 ? ""
17577 : "no ");
17578
17579 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17580 */
17581 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17582 SAVE_BGP_HARD_ADMIN_RESET)
17583 vty_out(vty, " %sbgp hard-administrative-reset\n",
17584 CHECK_FLAG(bgp->flags,
17585 BGP_FLAG_HARD_ADMIN_RESET)
17586 ? ""
17587 : "no ");
17588
17589 /* BGP default <afi>-<safi> */
17590 FOREACH_AFI_SAFI (afi, safi) {
17591 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17592 if (!bgp->default_af[afi][safi])
17593 vty_out(vty, " no bgp default %s\n",
17594 get_bgp_default_af_flag(afi,
17595 safi));
17596 } else if (bgp->default_af[afi][safi])
17597 vty_out(vty, " bgp default %s\n",
17598 get_bgp_default_af_flag(afi, safi));
17599 }
17600
17601 /* BGP default local-preference. */
17602 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17603 vty_out(vty, " bgp default local-preference %u\n",
17604 bgp->default_local_pref);
17605
17606 /* BGP default show-hostname */
17607 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17608 != SAVE_BGP_SHOW_HOSTNAME)
17609 vty_out(vty, " %sbgp default show-hostname\n",
17610 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17611 ? ""
17612 : "no ");
17613
17614 /* BGP default show-nexthop-hostname */
17615 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17616 != SAVE_BGP_SHOW_HOSTNAME)
17617 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17618 CHECK_FLAG(bgp->flags,
17619 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17620 ? ""
17621 : "no ");
17622
17623 /* BGP default subgroup-pkt-queue-max. */
17624 if (bgp->default_subgroup_pkt_queue_max
17625 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17626 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17627 bgp->default_subgroup_pkt_queue_max);
17628
17629 /* BGP client-to-client reflection. */
17630 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17631 vty_out(vty, " no bgp client-to-client reflection\n");
17632
17633 /* BGP cluster ID. */
17634 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17635 vty_out(vty, " bgp cluster-id %pI4\n",
17636 &bgp->cluster_id);
17637
17638 /* Disable ebgp connected nexthop check */
17639 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17640 vty_out(vty,
17641 " bgp disable-ebgp-connected-route-check\n");
17642
17643 /* Confederation identifier*/
17644 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17645 vty_out(vty, " bgp confederation identifier %u\n",
17646 bgp->confed_id);
17647
17648 /* Confederation peer */
17649 if (bgp->confed_peers_cnt > 0) {
17650 int i;
17651
17652 vty_out(vty, " bgp confederation peers");
17653
17654 for (i = 0; i < bgp->confed_peers_cnt; i++)
17655 vty_out(vty, " %u", bgp->confed_peers[i]);
17656
17657 vty_out(vty, "\n");
17658 }
17659
17660 /* BGP deterministic-med. */
17661 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17662 != SAVE_BGP_DETERMINISTIC_MED)
17663 vty_out(vty, " %sbgp deterministic-med\n",
17664 CHECK_FLAG(bgp->flags,
17665 BGP_FLAG_DETERMINISTIC_MED)
17666 ? ""
17667 : "no ");
17668
17669 /* BGP update-delay. */
17670 bgp_config_write_update_delay(vty, bgp);
17671
17672 if (bgp->v_maxmed_onstartup
17673 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17674 vty_out(vty, " bgp max-med on-startup %u",
17675 bgp->v_maxmed_onstartup);
17676 if (bgp->maxmed_onstartup_value
17677 != BGP_MAXMED_VALUE_DEFAULT)
17678 vty_out(vty, " %u",
17679 bgp->maxmed_onstartup_value);
17680 vty_out(vty, "\n");
17681 }
17682 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17683 vty_out(vty, " bgp max-med administrative");
17684 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17685 vty_out(vty, " %u", bgp->maxmed_admin_value);
17686 vty_out(vty, "\n");
17687 }
17688
17689 /* write quanta */
17690 bgp_config_write_wpkt_quanta(vty, bgp);
17691 /* read quanta */
17692 bgp_config_write_rpkt_quanta(vty, bgp);
17693
17694 /* coalesce time */
17695 bgp_config_write_coalesce_time(vty, bgp);
17696
17697 /* BGP per-instance graceful-shutdown */
17698 /* BGP-wide settings and per-instance settings are mutually
17699 * exclusive.
17700 */
17701 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17702 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17703 vty_out(vty, " bgp graceful-shutdown\n");
17704
17705 /* Long-lived Graceful Restart */
17706 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17707 vty_out(vty,
17708 " bgp long-lived-graceful-restart stale-time %u\n",
17709 bgp->llgr_stale_time);
17710
17711 /* BGP graceful-restart. */
17712 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17713 vty_out(vty,
17714 " bgp graceful-restart stalepath-time %u\n",
17715 bgp->stalepath_time);
17716
17717 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17718 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17719 bgp->restart_time);
17720
17721 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17722 SAVE_BGP_GRACEFUL_NOTIFICATION)
17723 vty_out(vty, " %sbgp graceful-restart notification\n",
17724 CHECK_FLAG(bgp->flags,
17725 BGP_FLAG_GRACEFUL_NOTIFICATION)
17726 ? ""
17727 : "no ");
17728
17729 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17730 vty_out(vty,
17731 " bgp graceful-restart select-defer-time %u\n",
17732 bgp->select_defer_time);
17733
17734 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17735 vty_out(vty, " bgp graceful-restart\n");
17736
17737 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17738 vty_out(vty, " bgp graceful-restart-disable\n");
17739
17740 /* BGP graceful-restart Preserve State F bit. */
17741 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17742 vty_out(vty,
17743 " bgp graceful-restart preserve-fw-state\n");
17744
17745 /* BGP TCP keepalive */
17746 bgp_config_tcp_keepalive(vty, bgp);
17747
17748 /* Stale timer for RIB */
17749 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17750 vty_out(vty,
17751 " bgp graceful-restart rib-stale-time %u\n",
17752 bgp->rib_stale_time);
17753
17754 /* BGP bestpath method. */
17755 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17756 vty_out(vty, " bgp bestpath as-path ignore\n");
17757 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17758 vty_out(vty, " bgp bestpath as-path confed\n");
17759
17760 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17761 if (CHECK_FLAG(bgp->flags,
17762 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17763 vty_out(vty,
17764 " bgp bestpath as-path multipath-relax as-set\n");
17765 } else {
17766 vty_out(vty,
17767 " bgp bestpath as-path multipath-relax\n");
17768 }
17769 }
17770
17771 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17772 vty_out(vty,
17773 " bgp route-reflector allow-outbound-policy\n");
17774 }
17775 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17776 vty_out(vty, " bgp bestpath compare-routerid\n");
17777 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17778 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17779 vty_out(vty, " bgp bestpath med");
17780 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17781 vty_out(vty, " confed");
17782 if (CHECK_FLAG(bgp->flags,
17783 BGP_FLAG_MED_MISSING_AS_WORST))
17784 vty_out(vty, " missing-as-worst");
17785 vty_out(vty, "\n");
17786 }
17787
17788 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17789 vty_out(vty,
17790 " bgp bestpath peer-type multipath-relax\n");
17791
17792 /* Link bandwidth handling. */
17793 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17794 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17795 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17796 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17797 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17798 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17799
17800 /* BGP network import check. */
17801 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17802 != SAVE_BGP_IMPORT_CHECK)
17803 vty_out(vty, " %sbgp network import-check\n",
17804 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17805 ? ""
17806 : "no ");
17807
17808 /* BGP timers configuration. */
17809 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17810 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17811 vty_out(vty, " timers bgp %u %u\n",
17812 bgp->default_keepalive, bgp->default_holdtime);
17813
17814 /* BGP minimum holdtime configuration. */
17815 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17816 && bgp->default_min_holdtime != 0)
17817 vty_out(vty, " bgp minimum-holdtime %u\n",
17818 bgp->default_min_holdtime);
17819
17820 /* Conditional advertisement timer configuration */
17821 if (bgp->condition_check_period
17822 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17823 vty_out(vty,
17824 " bgp conditional-advertisement timer %u\n",
17825 bgp->condition_check_period);
17826
17827 /* peer-group */
17828 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17829 bgp_config_write_peer_global(vty, bgp, group->conf);
17830 }
17831
17832 /* Normal neighbor configuration. */
17833 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17834 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17835 bgp_config_write_peer_global(vty, bgp, peer);
17836 }
17837
17838 /* listen range and limit for dynamic BGP neighbors */
17839 bgp_config_write_listen(vty, bgp);
17840
17841 /*
17842 * BGP default autoshutdown neighbors
17843 *
17844 * This must be placed after any peer and peer-group
17845 * configuration, to avoid setting all peers to shutdown after
17846 * a daemon restart, which is undesired behavior. (see #2286)
17847 */
17848 if (bgp->autoshutdown)
17849 vty_out(vty, " bgp default shutdown\n");
17850
17851 /* BGP instance administrative shutdown */
17852 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17853 vty_out(vty, " bgp shutdown\n");
17854
17855 if (bgp->allow_martian)
17856 vty_out(vty, " bgp allow-martian-nexthop\n");
17857
17858 if (bgp->fast_convergence)
17859 vty_out(vty, " bgp fast-convergence\n");
17860
17861 if (bgp->srv6_enabled) {
17862 vty_frame(vty, " !\n segment-routing srv6\n");
17863 if (strlen(bgp->srv6_locator_name))
17864 vty_out(vty, " locator %s\n",
17865 bgp->srv6_locator_name);
17866 vty_endframe(vty, " exit\n");
17867 }
17868
17869
17870 /* IPv4 unicast configuration. */
17871 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17872
17873 /* IPv4 multicast configuration. */
17874 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17875
17876 /* IPv4 labeled-unicast configuration. */
17877 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17878
17879 /* IPv4 VPN configuration. */
17880 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17881
17882 /* ENCAPv4 configuration. */
17883 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17884
17885 /* FLOWSPEC v4 configuration. */
17886 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17887
17888 /* IPv6 unicast configuration. */
17889 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17890
17891 /* IPv6 multicast configuration. */
17892 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17893
17894 /* IPv6 labeled-unicast configuration. */
17895 bgp_config_write_family(vty, bgp, AFI_IP6,
17896 SAFI_LABELED_UNICAST);
17897
17898 /* IPv6 VPN configuration. */
17899 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17900
17901 /* ENCAPv6 configuration. */
17902 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17903
17904 /* FLOWSPEC v6 configuration. */
17905 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17906
17907 /* EVPN configuration. */
17908 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17909
17910 hook_call(bgp_inst_config_write, bgp, vty);
17911
17912 #ifdef ENABLE_BGP_VNC
17913 bgp_rfapi_cfg_write(vty, bgp);
17914 #endif
17915
17916 vty_out(vty, "exit\n");
17917 vty_out(vty, "!\n");
17918 }
17919 return 0;
17920 }
17921
17922
17923 /* BGP node structure. */
17924 static struct cmd_node bgp_node = {
17925 .name = "bgp",
17926 .node = BGP_NODE,
17927 .parent_node = CONFIG_NODE,
17928 .prompt = "%s(config-router)# ",
17929 .config_write = bgp_config_write,
17930 };
17931
17932 static struct cmd_node bgp_ipv4_unicast_node = {
17933 .name = "bgp ipv4 unicast",
17934 .node = BGP_IPV4_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_multicast_node = {
17941 .name = "bgp ipv4 multicast",
17942 .node = BGP_IPV4M_NODE,
17943 .parent_node = BGP_NODE,
17944 .prompt = "%s(config-router-af)# ",
17945 .no_xpath = true,
17946 };
17947
17948 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17949 .name = "bgp ipv4 labeled unicast",
17950 .node = BGP_IPV4L_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_unicast_node = {
17957 .name = "bgp ipv6 unicast",
17958 .node = BGP_IPV6_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_multicast_node = {
17965 .name = "bgp ipv6 multicast",
17966 .node = BGP_IPV6M_NODE,
17967 .parent_node = BGP_NODE,
17968 .prompt = "%s(config-router-af)# ",
17969 .no_xpath = true,
17970 };
17971
17972 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17973 .name = "bgp ipv6 labeled unicast",
17974 .node = BGP_IPV6L_NODE,
17975 .parent_node = BGP_NODE,
17976 .prompt = "%s(config-router-af)# ",
17977 .no_xpath = true,
17978 };
17979
17980 static struct cmd_node bgp_vpnv4_node = {
17981 .name = "bgp vpnv4",
17982 .node = BGP_VPNV4_NODE,
17983 .parent_node = BGP_NODE,
17984 .prompt = "%s(config-router-af)# ",
17985 .no_xpath = true,
17986 };
17987
17988 static struct cmd_node bgp_vpnv6_node = {
17989 .name = "bgp vpnv6",
17990 .node = BGP_VPNV6_NODE,
17991 .parent_node = BGP_NODE,
17992 .prompt = "%s(config-router-af-vpnv6)# ",
17993 .no_xpath = true,
17994 };
17995
17996 static struct cmd_node bgp_evpn_node = {
17997 .name = "bgp evpn",
17998 .node = BGP_EVPN_NODE,
17999 .parent_node = BGP_NODE,
18000 .prompt = "%s(config-router-evpn)# ",
18001 .no_xpath = true,
18002 };
18003
18004 static struct cmd_node bgp_evpn_vni_node = {
18005 .name = "bgp evpn vni",
18006 .node = BGP_EVPN_VNI_NODE,
18007 .parent_node = BGP_EVPN_NODE,
18008 .prompt = "%s(config-router-af-vni)# ",
18009 };
18010
18011 static struct cmd_node bgp_flowspecv4_node = {
18012 .name = "bgp ipv4 flowspec",
18013 .node = BGP_FLOWSPECV4_NODE,
18014 .parent_node = BGP_NODE,
18015 .prompt = "%s(config-router-af)# ",
18016 .no_xpath = true,
18017 };
18018
18019 static struct cmd_node bgp_flowspecv6_node = {
18020 .name = "bgp ipv6 flowspec",
18021 .node = BGP_FLOWSPECV6_NODE,
18022 .parent_node = BGP_NODE,
18023 .prompt = "%s(config-router-af-vpnv6)# ",
18024 .no_xpath = true,
18025 };
18026
18027 static struct cmd_node bgp_srv6_node = {
18028 .name = "bgp srv6",
18029 .node = BGP_SRV6_NODE,
18030 .parent_node = BGP_NODE,
18031 .prompt = "%s(config-router-srv6)# ",
18032 };
18033
18034 static void community_list_vty(void);
18035
18036 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18037 {
18038 struct bgp *bgp;
18039 struct peer_group *group;
18040 struct listnode *lnbgp, *lnpeer;
18041
18042 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18043 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18044 vector_set(comps,
18045 XSTRDUP(MTYPE_COMPLETION, group->name));
18046 }
18047 }
18048
18049 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18050 {
18051 struct bgp *bgp;
18052 struct peer *peer;
18053 struct listnode *lnbgp, *lnpeer;
18054
18055 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18056 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18057 /* only provide suggestions on the appropriate input
18058 * token type,
18059 * they'll otherwise show up multiple times */
18060 enum cmd_token_type match_type;
18061 char *name = peer->host;
18062
18063 if (peer->conf_if) {
18064 match_type = VARIABLE_TKN;
18065 name = peer->conf_if;
18066 } else if (strchr(peer->host, ':'))
18067 match_type = IPV6_TKN;
18068 else
18069 match_type = IPV4_TKN;
18070
18071 if (token->type != match_type)
18072 continue;
18073
18074 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18075 }
18076 }
18077 }
18078
18079 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18080 {
18081 bgp_ac_peer(comps, token);
18082
18083 if (token->type == VARIABLE_TKN)
18084 bgp_ac_peergroup(comps, token);
18085 }
18086
18087 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18088 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18089 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18090 {.varname = "peer", .completions = bgp_ac_neighbor},
18091 {.completions = NULL}};
18092
18093 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18094 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18095 {.completions = NULL} };
18096
18097 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18098
18099 static struct thread *t_bgp_cfg;
18100
18101 bool bgp_config_inprocess(void)
18102 {
18103 return thread_is_scheduled(t_bgp_cfg);
18104 }
18105
18106 static void bgp_config_finish(struct thread *t)
18107 {
18108 struct listnode *node;
18109 struct bgp *bgp;
18110
18111 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18112 hook_call(bgp_config_end, bgp);
18113 }
18114
18115 static void bgp_config_start(void)
18116 {
18117 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18118 THREAD_OFF(t_bgp_cfg);
18119 thread_add_timer(bm->master, bgp_config_finish, NULL,
18120 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18121 }
18122
18123 /* When we receive a hook the configuration is read,
18124 * we start a timer to make sure we postpone sending
18125 * EoR before route-maps are processed.
18126 * This is especially valid if using `bgp route-map delay-timer`.
18127 */
18128 static void bgp_config_end(void)
18129 {
18130 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18131 uint32_t bgp_post_config_delay =
18132 thread_is_scheduled(bm->t_rmap_update)
18133 ? thread_timer_remain_second(bm->t_rmap_update)
18134 : BGP_POST_CONFIG_DELAY_SECONDS;
18135
18136 /* If BGP config processing thread isn't running, then
18137 * we can return and rely it's properly handled.
18138 */
18139 if (!bgp_config_inprocess())
18140 return;
18141
18142 THREAD_OFF(t_bgp_cfg);
18143
18144 /* Start a new timer to make sure we don't send EoR
18145 * before route-maps are processed.
18146 */
18147 thread_add_timer(bm->master, bgp_config_finish, NULL,
18148 bgp_post_config_delay, &t_bgp_cfg);
18149 }
18150
18151 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18152 {
18153 int write = 0;
18154 struct interface *ifp;
18155 struct bgp_interface *iifp;
18156
18157 FOR_ALL_INTERFACES (vrf, ifp) {
18158 iifp = ifp->info;
18159 if (!iifp)
18160 continue;
18161
18162 if_vty_config_start(vty, ifp);
18163
18164 if (CHECK_FLAG(iifp->flags,
18165 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18166 vty_out(vty, " mpls bgp forwarding\n");
18167 write++;
18168 }
18169
18170 if_vty_config_end(vty);
18171 }
18172
18173 return write;
18174 }
18175
18176 /* Configuration write function for bgpd. */
18177 static int config_write_interface(struct vty *vty)
18178 {
18179 int write = 0;
18180 struct vrf *vrf = NULL;
18181
18182 /* Display all VRF aware OSPF interface configuration */
18183 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18184 write += config_write_interface_one(vty, vrf);
18185 }
18186
18187 return write;
18188 }
18189
18190 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18191 "[no$no] mpls bgp forwarding",
18192 NO_STR MPLS_STR BGP_STR
18193 "Enable MPLS forwarding for eBGP directly connected peers\n")
18194 {
18195 bool check;
18196 struct bgp_interface *iifp;
18197
18198 VTY_DECLVAR_CONTEXT(interface, ifp);
18199 iifp = ifp->info;
18200 if (!iifp) {
18201 vty_out(vty, "Interface %s not available\n", ifp->name);
18202 return CMD_WARNING_CONFIG_FAILED;
18203 }
18204 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18205 if (check != !no) {
18206 if (no)
18207 UNSET_FLAG(iifp->flags,
18208 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18209 else
18210 SET_FLAG(iifp->flags,
18211 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18212 /* trigger a nht update on eBGP sessions */
18213 if (if_is_operative(ifp))
18214 bgp_nht_ifp_up(ifp);
18215 }
18216 return CMD_SUCCESS;
18217 }
18218
18219 /* Initialization of BGP interface. */
18220 static void bgp_vty_if_init(void)
18221 {
18222 /* Install interface node. */
18223 if_cmd_init(config_write_interface);
18224
18225 /* "mpls bgp forwarding" commands. */
18226 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18227 }
18228
18229 void bgp_vty_init(void)
18230 {
18231 cmd_variable_handler_register(bgp_var_neighbor);
18232 cmd_variable_handler_register(bgp_var_peergroup);
18233
18234 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18235
18236 /* Install bgp top node. */
18237 install_node(&bgp_node);
18238 install_node(&bgp_ipv4_unicast_node);
18239 install_node(&bgp_ipv4_multicast_node);
18240 install_node(&bgp_ipv4_labeled_unicast_node);
18241 install_node(&bgp_ipv6_unicast_node);
18242 install_node(&bgp_ipv6_multicast_node);
18243 install_node(&bgp_ipv6_labeled_unicast_node);
18244 install_node(&bgp_vpnv4_node);
18245 install_node(&bgp_vpnv6_node);
18246 install_node(&bgp_evpn_node);
18247 install_node(&bgp_evpn_vni_node);
18248 install_node(&bgp_flowspecv4_node);
18249 install_node(&bgp_flowspecv6_node);
18250 install_node(&bgp_srv6_node);
18251
18252 /* Install default VTY commands to new nodes. */
18253 install_default(BGP_NODE);
18254 install_default(BGP_IPV4_NODE);
18255 install_default(BGP_IPV4M_NODE);
18256 install_default(BGP_IPV4L_NODE);
18257 install_default(BGP_IPV6_NODE);
18258 install_default(BGP_IPV6M_NODE);
18259 install_default(BGP_IPV6L_NODE);
18260 install_default(BGP_VPNV4_NODE);
18261 install_default(BGP_VPNV6_NODE);
18262 install_default(BGP_FLOWSPECV4_NODE);
18263 install_default(BGP_FLOWSPECV6_NODE);
18264 install_default(BGP_EVPN_NODE);
18265 install_default(BGP_EVPN_VNI_NODE);
18266 install_default(BGP_SRV6_NODE);
18267
18268 /* "bgp local-mac" hidden commands. */
18269 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18270 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18271
18272 /* "bgp suppress-fib-pending" global */
18273 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18274
18275 /* bgp route-map delay-timer commands. */
18276 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18277 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18278
18279 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18280
18281 /* bgp fast-convergence command */
18282 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18283 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18284
18285 /* global bgp update-delay command */
18286 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18287 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18288
18289 /* global bgp graceful-shutdown command */
18290 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18291 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18292
18293 /* Dummy commands (Currently not supported) */
18294 install_element(BGP_NODE, &no_synchronization_cmd);
18295 install_element(BGP_NODE, &no_auto_summary_cmd);
18296
18297 /* "router bgp" commands. */
18298 install_element(CONFIG_NODE, &router_bgp_cmd);
18299
18300 /* "no router bgp" commands. */
18301 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18302
18303 /* "bgp session-dscp command */
18304 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18305 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18306
18307 /* "bgp router-id" commands. */
18308 install_element(BGP_NODE, &bgp_router_id_cmd);
18309 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18310
18311 /* "bgp suppress-fib-pending" command */
18312 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18313
18314 /* "bgp cluster-id" commands. */
18315 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18316 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18317
18318 /* "bgp no-rib" commands. */
18319 install_element(CONFIG_NODE, &bgp_norib_cmd);
18320 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18321
18322 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18323
18324 /* "bgp confederation" commands. */
18325 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18326 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18327
18328 /* "bgp confederation peers" commands. */
18329 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18330 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18331
18332 /* bgp max-med command */
18333 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18334 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18335 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18336 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18337 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18338
18339 /* "neighbor role" commands. */
18340 install_element(BGP_NODE, &neighbor_role_cmd);
18341 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18342 install_element(BGP_NODE, &no_neighbor_role_cmd);
18343
18344 /* bgp disable-ebgp-connected-nh-check */
18345 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18346 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18347
18348 /* bgp update-delay command */
18349 install_element(BGP_NODE, &bgp_update_delay_cmd);
18350 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18351
18352 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18353 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18354
18355 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18356 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18357
18358 /* "maximum-paths" commands. */
18359 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18360 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18361 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18362 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18363 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18364 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18365 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18366 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18367 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18368 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18369 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18370 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18371 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18372 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18373 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18374
18375 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18376 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18377 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18378 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18379 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18380 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18381 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18382 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18383 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18384 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18385
18386 /* "timers bgp" commands. */
18387 install_element(BGP_NODE, &bgp_timers_cmd);
18388 install_element(BGP_NODE, &no_bgp_timers_cmd);
18389
18390 /* "minimum-holdtime" commands. */
18391 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18392 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18393
18394 /* route-map delay-timer commands - per instance for backwards compat.
18395 */
18396 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18397 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18398
18399 /* "bgp client-to-client reflection" commands */
18400 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18401 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18402
18403 /* "bgp always-compare-med" commands */
18404 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18405 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18406
18407 /* bgp ebgp-requires-policy */
18408 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18409 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18410
18411 /* bgp suppress-duplicates */
18412 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18413 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18414
18415 /* bgp reject-as-sets */
18416 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18417 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18418
18419 /* "bgp deterministic-med" commands */
18420 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18421 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18422
18423 /* "bgp graceful-restart" command */
18424 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18425 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18426
18427 /* "bgp graceful-restart-disable" command */
18428 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18429 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18430
18431 /* "neighbor a:b:c:d graceful-restart" command */
18432 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18433 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18434
18435 /* "neighbor a:b:c:d graceful-restart-disable" command */
18436 install_element(BGP_NODE,
18437 &bgp_neighbor_graceful_restart_disable_set_cmd);
18438 install_element(BGP_NODE,
18439 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18440
18441 /* "neighbor a:b:c:d graceful-restart-helper" command */
18442 install_element(BGP_NODE,
18443 &bgp_neighbor_graceful_restart_helper_set_cmd);
18444 install_element(BGP_NODE,
18445 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18446
18447 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18448 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18449 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18450 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18451 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18452 install_element(BGP_NODE,
18453 &no_bgp_graceful_restart_select_defer_time_cmd);
18454 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18455 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18456 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18457
18458 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18459 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18460 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18461 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18462
18463 /* "bgp graceful-shutdown" commands */
18464 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18465 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18466
18467 /* "bgp hard-administrative-reset" commands */
18468 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18469
18470 /* "bgp long-lived-graceful-restart" commands */
18471 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18472 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18473
18474 /* "bgp fast-external-failover" commands */
18475 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18476 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18477
18478 /* "bgp bestpath compare-routerid" commands */
18479 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18480 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18481
18482 /* "bgp bestpath as-path ignore" commands */
18483 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18484 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18485
18486 /* "bgp bestpath as-path confed" commands */
18487 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18488 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18489
18490 /* "bgp bestpath as-path multipath-relax" commands */
18491 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18492 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18493
18494 /* "bgp bestpath peer-type multipath-relax" commands */
18495 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18496 install_element(BGP_NODE,
18497 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18498
18499 /* "bgp log-neighbor-changes" commands */
18500 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18501 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18502
18503 /* "bgp bestpath med" commands */
18504 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18505 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18506
18507 /* "bgp bestpath bandwidth" commands */
18508 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18509 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18510
18511 /* "no bgp default <afi>-<safi>" commands. */
18512 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18513
18514 /* "bgp network import-check" commands. */
18515 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18516 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18517 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18518
18519 /* "bgp default local-preference" commands. */
18520 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18521 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18522
18523 /* bgp default show-hostname */
18524 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18525 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18526
18527 /* bgp default show-nexthop-hostname */
18528 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18529 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18530
18531 /* "bgp default subgroup-pkt-queue-max" commands. */
18532 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18533 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18534
18535 /* bgp ibgp-allow-policy-mods command */
18536 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18537 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18538
18539 /* "bgp listen limit" commands. */
18540 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18541 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18542
18543 /* "bgp listen range" commands. */
18544 install_element(BGP_NODE, &bgp_listen_range_cmd);
18545 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18546
18547 /* "bgp default shutdown" command */
18548 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18549
18550 /* "bgp shutdown" commands */
18551 install_element(BGP_NODE, &bgp_shutdown_cmd);
18552 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18553 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18554 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18555
18556 /* "neighbor remote-as" commands. */
18557 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18558 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18559 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18560 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18561 install_element(BGP_NODE,
18562 &neighbor_interface_v6only_config_remote_as_cmd);
18563 install_element(BGP_NODE, &no_neighbor_cmd);
18564 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18565
18566 /* "neighbor peer-group" commands. */
18567 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18568 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18569 install_element(BGP_NODE,
18570 &no_neighbor_interface_peer_group_remote_as_cmd);
18571
18572 /* "neighbor local-as" commands. */
18573 install_element(BGP_NODE, &neighbor_local_as_cmd);
18574 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18575 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18576 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18577
18578 /* "neighbor solo" commands. */
18579 install_element(BGP_NODE, &neighbor_solo_cmd);
18580 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18581
18582 /* "neighbor password" commands. */
18583 install_element(BGP_NODE, &neighbor_password_cmd);
18584 install_element(BGP_NODE, &no_neighbor_password_cmd);
18585
18586 /* "neighbor activate" commands. */
18587 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18588 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18589 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18590 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18591 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18592 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18593 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18594 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18595 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18596 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18597 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18598 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18599
18600 /* "no neighbor activate" commands. */
18601 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18602 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18603 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18604 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18605 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18606 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18607 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18608 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18609 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18610 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18611 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18612 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18613
18614 /* "neighbor peer-group" set commands. */
18615 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18616 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18617 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18618 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18619 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18620 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18621 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18622 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18623 install_element(BGP_FLOWSPECV4_NODE,
18624 &neighbor_set_peer_group_hidden_cmd);
18625 install_element(BGP_FLOWSPECV6_NODE,
18626 &neighbor_set_peer_group_hidden_cmd);
18627
18628 /* "no neighbor peer-group unset" commands. */
18629 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18630 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18631 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18632 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18633 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18634 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18635 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18636 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18637 install_element(BGP_FLOWSPECV4_NODE,
18638 &no_neighbor_set_peer_group_hidden_cmd);
18639 install_element(BGP_FLOWSPECV6_NODE,
18640 &no_neighbor_set_peer_group_hidden_cmd);
18641
18642 /* "neighbor softreconfiguration inbound" commands.*/
18643 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18644 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18645 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18646 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18647 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18648 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18649 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18650 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18651 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18652 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18653 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18654 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18655 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18656 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18657 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18658 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18659 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18660 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18661 install_element(BGP_FLOWSPECV4_NODE,
18662 &neighbor_soft_reconfiguration_cmd);
18663 install_element(BGP_FLOWSPECV4_NODE,
18664 &no_neighbor_soft_reconfiguration_cmd);
18665 install_element(BGP_FLOWSPECV6_NODE,
18666 &neighbor_soft_reconfiguration_cmd);
18667 install_element(BGP_FLOWSPECV6_NODE,
18668 &no_neighbor_soft_reconfiguration_cmd);
18669 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18670 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18671
18672 /* "neighbor attribute-unchanged" commands. */
18673 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18674 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18675 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18676 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18677 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18678 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18679 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18680 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18681 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18682 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18683 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18684 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18685 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18686 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18687 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18688 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18689 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18690 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18691
18692 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18693 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18694
18695 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18696 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18697 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18698 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18699
18700 /* "nexthop-local unchanged" commands */
18701 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18702 install_element(BGP_IPV6_NODE,
18703 &no_neighbor_nexthop_local_unchanged_cmd);
18704
18705 /* "neighbor next-hop-self" commands. */
18706 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18707 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18708 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18709 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18710 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18711 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18712 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18713 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18714 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18715 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18716 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18717 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18718 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18719 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18720 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18721 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18722 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18723 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18724 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18725 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18726
18727 /* "neighbor next-hop-self force" commands. */
18728 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18729 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18730 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18731 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18732 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18733 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18734 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18735 install_element(BGP_IPV4_NODE,
18736 &no_neighbor_nexthop_self_all_hidden_cmd);
18737 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18738 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18739 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18740 install_element(BGP_IPV4M_NODE,
18741 &no_neighbor_nexthop_self_all_hidden_cmd);
18742 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18743 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18744 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18745 install_element(BGP_IPV4L_NODE,
18746 &no_neighbor_nexthop_self_all_hidden_cmd);
18747 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18748 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18749 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18750 install_element(BGP_IPV6_NODE,
18751 &no_neighbor_nexthop_self_all_hidden_cmd);
18752 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18753 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18754 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18755 install_element(BGP_IPV6M_NODE,
18756 &no_neighbor_nexthop_self_all_hidden_cmd);
18757 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18758 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18759 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18760 install_element(BGP_IPV6L_NODE,
18761 &no_neighbor_nexthop_self_all_hidden_cmd);
18762 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18763 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18764 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18765 install_element(BGP_VPNV4_NODE,
18766 &no_neighbor_nexthop_self_all_hidden_cmd);
18767 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18768 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18769 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18770 install_element(BGP_VPNV6_NODE,
18771 &no_neighbor_nexthop_self_all_hidden_cmd);
18772 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18773 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18774
18775 /* "neighbor as-override" commands. */
18776 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18777 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18778 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18779 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18780 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18781 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18782 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18783 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18784 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18785 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18786 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18787 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18788 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18789 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18790 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18791 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18792 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18793 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18794
18795 /* "neighbor remove-private-AS" commands. */
18796 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18797 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18798 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18799 install_element(BGP_NODE,
18800 &no_neighbor_remove_private_as_all_hidden_cmd);
18801 install_element(BGP_NODE,
18802 &neighbor_remove_private_as_replace_as_hidden_cmd);
18803 install_element(BGP_NODE,
18804 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18805 install_element(BGP_NODE,
18806 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18807 install_element(
18808 BGP_NODE,
18809 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18810 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18811 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18812 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18813 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18814 install_element(BGP_IPV4_NODE,
18815 &neighbor_remove_private_as_replace_as_cmd);
18816 install_element(BGP_IPV4_NODE,
18817 &no_neighbor_remove_private_as_replace_as_cmd);
18818 install_element(BGP_IPV4_NODE,
18819 &neighbor_remove_private_as_all_replace_as_cmd);
18820 install_element(BGP_IPV4_NODE,
18821 &no_neighbor_remove_private_as_all_replace_as_cmd);
18822 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18823 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18824 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18825 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18826 install_element(BGP_IPV4M_NODE,
18827 &neighbor_remove_private_as_replace_as_cmd);
18828 install_element(BGP_IPV4M_NODE,
18829 &no_neighbor_remove_private_as_replace_as_cmd);
18830 install_element(BGP_IPV4M_NODE,
18831 &neighbor_remove_private_as_all_replace_as_cmd);
18832 install_element(BGP_IPV4M_NODE,
18833 &no_neighbor_remove_private_as_all_replace_as_cmd);
18834 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18835 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18836 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18837 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18838 install_element(BGP_IPV4L_NODE,
18839 &neighbor_remove_private_as_replace_as_cmd);
18840 install_element(BGP_IPV4L_NODE,
18841 &no_neighbor_remove_private_as_replace_as_cmd);
18842 install_element(BGP_IPV4L_NODE,
18843 &neighbor_remove_private_as_all_replace_as_cmd);
18844 install_element(BGP_IPV4L_NODE,
18845 &no_neighbor_remove_private_as_all_replace_as_cmd);
18846 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18847 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18848 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18849 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18850 install_element(BGP_IPV6_NODE,
18851 &neighbor_remove_private_as_replace_as_cmd);
18852 install_element(BGP_IPV6_NODE,
18853 &no_neighbor_remove_private_as_replace_as_cmd);
18854 install_element(BGP_IPV6_NODE,
18855 &neighbor_remove_private_as_all_replace_as_cmd);
18856 install_element(BGP_IPV6_NODE,
18857 &no_neighbor_remove_private_as_all_replace_as_cmd);
18858 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18859 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18860 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18861 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18862 install_element(BGP_IPV6M_NODE,
18863 &neighbor_remove_private_as_replace_as_cmd);
18864 install_element(BGP_IPV6M_NODE,
18865 &no_neighbor_remove_private_as_replace_as_cmd);
18866 install_element(BGP_IPV6M_NODE,
18867 &neighbor_remove_private_as_all_replace_as_cmd);
18868 install_element(BGP_IPV6M_NODE,
18869 &no_neighbor_remove_private_as_all_replace_as_cmd);
18870 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18871 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18872 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18873 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18874 install_element(BGP_IPV6L_NODE,
18875 &neighbor_remove_private_as_replace_as_cmd);
18876 install_element(BGP_IPV6L_NODE,
18877 &no_neighbor_remove_private_as_replace_as_cmd);
18878 install_element(BGP_IPV6L_NODE,
18879 &neighbor_remove_private_as_all_replace_as_cmd);
18880 install_element(BGP_IPV6L_NODE,
18881 &no_neighbor_remove_private_as_all_replace_as_cmd);
18882 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18883 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18884 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18885 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18886 install_element(BGP_VPNV4_NODE,
18887 &neighbor_remove_private_as_replace_as_cmd);
18888 install_element(BGP_VPNV4_NODE,
18889 &no_neighbor_remove_private_as_replace_as_cmd);
18890 install_element(BGP_VPNV4_NODE,
18891 &neighbor_remove_private_as_all_replace_as_cmd);
18892 install_element(BGP_VPNV4_NODE,
18893 &no_neighbor_remove_private_as_all_replace_as_cmd);
18894 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18895 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18896 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18897 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18898 install_element(BGP_VPNV6_NODE,
18899 &neighbor_remove_private_as_replace_as_cmd);
18900 install_element(BGP_VPNV6_NODE,
18901 &no_neighbor_remove_private_as_replace_as_cmd);
18902 install_element(BGP_VPNV6_NODE,
18903 &neighbor_remove_private_as_all_replace_as_cmd);
18904 install_element(BGP_VPNV6_NODE,
18905 &no_neighbor_remove_private_as_all_replace_as_cmd);
18906
18907 /* "neighbor send-community" commands.*/
18908 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18909 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18910 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18911 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18912 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18913 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18914 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18915 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18916 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18917 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18918 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18919 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18920 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18921 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18922 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18923 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18924 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18925 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18926 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18927 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18928 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18929 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18930 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18931 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18932 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18933 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18934 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18935 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18936 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18937 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18938 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18939 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18940 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18941 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18942 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18943 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18944
18945 /* "neighbor route-reflector" commands.*/
18946 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18947 install_element(BGP_NODE,
18948 &no_neighbor_route_reflector_client_hidden_cmd);
18949 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18950 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18951 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18952 install_element(BGP_IPV4M_NODE,
18953 &no_neighbor_route_reflector_client_cmd);
18954 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18955 install_element(BGP_IPV4L_NODE,
18956 &no_neighbor_route_reflector_client_cmd);
18957 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18958 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18959 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18960 install_element(BGP_IPV6M_NODE,
18961 &no_neighbor_route_reflector_client_cmd);
18962 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18963 install_element(BGP_IPV6L_NODE,
18964 &no_neighbor_route_reflector_client_cmd);
18965 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18966 install_element(BGP_VPNV4_NODE,
18967 &no_neighbor_route_reflector_client_cmd);
18968 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18969 install_element(BGP_VPNV6_NODE,
18970 &no_neighbor_route_reflector_client_cmd);
18971 install_element(BGP_FLOWSPECV4_NODE,
18972 &neighbor_route_reflector_client_cmd);
18973 install_element(BGP_FLOWSPECV4_NODE,
18974 &no_neighbor_route_reflector_client_cmd);
18975 install_element(BGP_FLOWSPECV6_NODE,
18976 &neighbor_route_reflector_client_cmd);
18977 install_element(BGP_FLOWSPECV6_NODE,
18978 &no_neighbor_route_reflector_client_cmd);
18979 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18980 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18981
18982 /* "neighbor route-server" commands.*/
18983 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18984 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18985 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18986 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18987 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18988 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18989 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18990 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18991 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18992 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18993 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18994 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18995 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18996 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18997 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18998 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18999 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19000 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19001 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19002 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19003 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19004 install_element(BGP_FLOWSPECV4_NODE,
19005 &no_neighbor_route_server_client_cmd);
19006 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19007 install_element(BGP_FLOWSPECV6_NODE,
19008 &no_neighbor_route_server_client_cmd);
19009
19010 /* "neighbor disable-addpath-rx" commands. */
19011 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19012 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19013 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19014 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19015 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19016 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19017 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19018 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19019 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19020 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19021 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19022 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19023 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19024 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19025 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19026 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19027
19028 /* "neighbor addpath-tx-all-paths" commands.*/
19029 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19030 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19031 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19032 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19033 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19034 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19035 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19036 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19037 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19038 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19039 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19040 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19041 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19042 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19043 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19044 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19045 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19046 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19047
19048 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19049 install_element(BGP_NODE,
19050 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19051 install_element(BGP_NODE,
19052 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19053 install_element(BGP_IPV4_NODE,
19054 &neighbor_addpath_tx_bestpath_per_as_cmd);
19055 install_element(BGP_IPV4_NODE,
19056 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19057 install_element(BGP_IPV4M_NODE,
19058 &neighbor_addpath_tx_bestpath_per_as_cmd);
19059 install_element(BGP_IPV4M_NODE,
19060 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19061 install_element(BGP_IPV4L_NODE,
19062 &neighbor_addpath_tx_bestpath_per_as_cmd);
19063 install_element(BGP_IPV4L_NODE,
19064 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19065 install_element(BGP_IPV6_NODE,
19066 &neighbor_addpath_tx_bestpath_per_as_cmd);
19067 install_element(BGP_IPV6_NODE,
19068 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19069 install_element(BGP_IPV6M_NODE,
19070 &neighbor_addpath_tx_bestpath_per_as_cmd);
19071 install_element(BGP_IPV6M_NODE,
19072 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19073 install_element(BGP_IPV6L_NODE,
19074 &neighbor_addpath_tx_bestpath_per_as_cmd);
19075 install_element(BGP_IPV6L_NODE,
19076 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19077 install_element(BGP_VPNV4_NODE,
19078 &neighbor_addpath_tx_bestpath_per_as_cmd);
19079 install_element(BGP_VPNV4_NODE,
19080 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19081 install_element(BGP_VPNV6_NODE,
19082 &neighbor_addpath_tx_bestpath_per_as_cmd);
19083 install_element(BGP_VPNV6_NODE,
19084 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19085
19086 /* "neighbor sender-as-path-loop-detection" commands. */
19087 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19088 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19089
19090 /* "neighbor passive" commands. */
19091 install_element(BGP_NODE, &neighbor_passive_cmd);
19092 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19093
19094
19095 /* "neighbor shutdown" commands. */
19096 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19097 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19098 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19099 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19100 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19101 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19102
19103 /* "neighbor capability extended-nexthop" commands.*/
19104 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19105 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19106
19107 /* "neighbor capability orf prefix-list" commands.*/
19108 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19109 install_element(BGP_NODE,
19110 &no_neighbor_capability_orf_prefix_hidden_cmd);
19111 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19112 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19113 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19114 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19115 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19116 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19117 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19118 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19119 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19120 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19121 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19122 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19123
19124 /* "neighbor capability dynamic" commands.*/
19125 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19126 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19127
19128 /* "neighbor dont-capability-negotiate" commands. */
19129 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19130 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19131
19132 /* "neighbor ebgp-multihop" commands. */
19133 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19134 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19135 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19136
19137 /* "neighbor disable-connected-check" commands. */
19138 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19139 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19140
19141 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19142 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19143 install_element(BGP_NODE,
19144 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19145
19146 /* "neighbor extended-optional-parameters" commands. */
19147 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19148 install_element(BGP_NODE,
19149 &no_neighbor_extended_optional_parameters_cmd);
19150
19151 /* "neighbor enforce-first-as" commands. */
19152 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19153 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19154
19155 /* "neighbor description" commands. */
19156 install_element(BGP_NODE, &neighbor_description_cmd);
19157 install_element(BGP_NODE, &no_neighbor_description_cmd);
19158 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19159
19160 /* "neighbor update-source" commands. "*/
19161 install_element(BGP_NODE, &neighbor_update_source_cmd);
19162 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19163
19164 /* "neighbor default-originate" commands. */
19165 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19166 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19167 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19168 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19169 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19170 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19171 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19172 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19173 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19174 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19175 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19176 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19177 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19178 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19179 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19180 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19181 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19182 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19183 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19184 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19185 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19186
19187 /* "neighbor port" commands. */
19188 install_element(BGP_NODE, &neighbor_port_cmd);
19189 install_element(BGP_NODE, &no_neighbor_port_cmd);
19190
19191 /* "neighbor weight" commands. */
19192 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19193 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19194
19195 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19196 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19197 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19198 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19199 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19200 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19201 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19202 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19203 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19204 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19205 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19206 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19207 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19208 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19209 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19210 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19211
19212 /* "neighbor override-capability" commands. */
19213 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19214 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19215
19216 /* "neighbor strict-capability-match" commands. */
19217 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19218 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19219
19220 /* "neighbor timers" commands. */
19221 install_element(BGP_NODE, &neighbor_timers_cmd);
19222 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19223
19224 /* "neighbor timers connect" commands. */
19225 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19226 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19227
19228 /* "neighbor timers delayopen" commands. */
19229 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19230 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19231
19232 /* "neighbor advertisement-interval" commands. */
19233 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19234 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19235
19236 /* "neighbor interface" commands. */
19237 install_element(BGP_NODE, &neighbor_interface_cmd);
19238 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19239
19240 /* "neighbor distribute" commands. */
19241 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19242 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19243 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19244 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19245 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19246 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19247 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19248 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19249 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19250 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19251 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19252 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19253 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19254 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19255 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19256 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19257 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19258 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19259
19260 /* "neighbor prefix-list" commands. */
19261 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19262 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19263 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19264 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19265 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19266 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19267 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19268 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19269 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19270 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19271 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19272 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19273 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19274 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19275 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19276 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19277 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19278 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19279 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19280 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19281 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19282 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19283
19284 /* "neighbor filter-list" commands. */
19285 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19286 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19287 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19288 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19289 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19290 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19291 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19292 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19293 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19294 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19295 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19296 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19297 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19298 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19299 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19300 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19301 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19302 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19303 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19304 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19305 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19306 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19307
19308 /* "neighbor route-map" commands. */
19309 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19310 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19311 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19312 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19313 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19314 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19315 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19316 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19317 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19318 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19319 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19320 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19321 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19322 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19323 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19324 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19325 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19326 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19327 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19328 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19329 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19330 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19331 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19332 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19333
19334 /* "neighbor unsuppress-map" commands. */
19335 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19336 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19337 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19338 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19339 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19340 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19341 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19342 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19343 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19344 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19345 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19346 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19347 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19348 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19349 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19350 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19351 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19352 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19353
19354 /* "neighbor advertise-map" commands. */
19355 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19356 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19357 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19358 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19359 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19360 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19361 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19362 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19363 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19364 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19365
19366 /* neighbor maximum-prefix-out commands. */
19367 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19368 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19369 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19370 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19371 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19372 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19373 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19374 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19375 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19376 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19377 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19378 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19379 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19380 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19381 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19382 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19383 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19384 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19385
19386 /* "neighbor maximum-prefix" commands. */
19387 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19388 install_element(BGP_NODE,
19389 &neighbor_maximum_prefix_threshold_hidden_cmd);
19390 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19391 install_element(BGP_NODE,
19392 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19393 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19394 install_element(BGP_NODE,
19395 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19396 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19397 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19398 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19399 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19400 install_element(BGP_IPV4_NODE,
19401 &neighbor_maximum_prefix_threshold_warning_cmd);
19402 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19403 install_element(BGP_IPV4_NODE,
19404 &neighbor_maximum_prefix_threshold_restart_cmd);
19405 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19406 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19407 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19408 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19409 install_element(BGP_IPV4M_NODE,
19410 &neighbor_maximum_prefix_threshold_warning_cmd);
19411 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19412 install_element(BGP_IPV4M_NODE,
19413 &neighbor_maximum_prefix_threshold_restart_cmd);
19414 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19415 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19416 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19417 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19418 install_element(BGP_IPV4L_NODE,
19419 &neighbor_maximum_prefix_threshold_warning_cmd);
19420 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19421 install_element(BGP_IPV4L_NODE,
19422 &neighbor_maximum_prefix_threshold_restart_cmd);
19423 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19424 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19425 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19426 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19427 install_element(BGP_IPV6_NODE,
19428 &neighbor_maximum_prefix_threshold_warning_cmd);
19429 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19430 install_element(BGP_IPV6_NODE,
19431 &neighbor_maximum_prefix_threshold_restart_cmd);
19432 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19433 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19434 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19435 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19436 install_element(BGP_IPV6M_NODE,
19437 &neighbor_maximum_prefix_threshold_warning_cmd);
19438 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19439 install_element(BGP_IPV6M_NODE,
19440 &neighbor_maximum_prefix_threshold_restart_cmd);
19441 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19442 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19443 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19444 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19445 install_element(BGP_IPV6L_NODE,
19446 &neighbor_maximum_prefix_threshold_warning_cmd);
19447 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19448 install_element(BGP_IPV6L_NODE,
19449 &neighbor_maximum_prefix_threshold_restart_cmd);
19450 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19451 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19452 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19453 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19454 install_element(BGP_VPNV4_NODE,
19455 &neighbor_maximum_prefix_threshold_warning_cmd);
19456 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19457 install_element(BGP_VPNV4_NODE,
19458 &neighbor_maximum_prefix_threshold_restart_cmd);
19459 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19460 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19461 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19462 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19463 install_element(BGP_VPNV6_NODE,
19464 &neighbor_maximum_prefix_threshold_warning_cmd);
19465 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19466 install_element(BGP_VPNV6_NODE,
19467 &neighbor_maximum_prefix_threshold_restart_cmd);
19468 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19469
19470 /* "neighbor allowas-in" */
19471 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19472 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19473 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19474 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19475 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19476 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19477 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19478 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19479 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19480 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19481 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19482 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19483 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19484 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19485 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19486 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19487 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19488 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19489 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19490 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19491
19492 /* "neighbor soo" */
19493 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19494 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19495 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19496 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19497 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19498 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19499 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19500 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19501 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19502 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19503 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19504 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19505 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19506 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19507 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19508 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19509 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19510 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19511
19512 /* address-family commands. */
19513 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19514 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19515 #ifdef KEEP_OLD_VPN_COMMANDS
19516 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19517 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19518 #endif /* KEEP_OLD_VPN_COMMANDS */
19519
19520 install_element(BGP_NODE, &address_family_evpn_cmd);
19521
19522 /* "exit-address-family" command. */
19523 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19524 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19525 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19526 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19527 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19528 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19529 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19530 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19531 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19532 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19533 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19534
19535 /* BGP retain all route-target */
19536 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19537 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19538
19539 /* "clear ip bgp commands" */
19540 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19541
19542 /* clear ip bgp prefix */
19543 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19544 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19545 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19546
19547 /* "show [ip] bgp summary" commands. */
19548 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19549 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19550 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19551 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19552 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19553 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19554 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19555
19556 /* "show [ip] bgp neighbors" commands. */
19557 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19558
19559 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19560
19561 /* "show [ip] bgp peer-group" commands. */
19562 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19563
19564 /* "show [ip] bgp paths" commands. */
19565 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19566
19567 /* "show [ip] bgp community" commands. */
19568 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19569
19570 /* "show ip bgp large-community" commands. */
19571 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19572 /* "show [ip] bgp attribute-info" commands. */
19573 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19574 /* "show [ip] bgp route-leak" command */
19575 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19576
19577 /* "redistribute" commands. */
19578 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19579 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19580 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19581 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19582 install_element(BGP_NODE,
19583 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19584 install_element(BGP_NODE,
19585 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19586 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19587 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19588 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19589 install_element(BGP_NODE,
19590 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19591 install_element(BGP_NODE,
19592 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19593 install_element(BGP_NODE,
19594 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19595 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19596 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19597 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19598 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19599 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19600 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19601 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19602 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19603 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19604 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19605 install_element(BGP_IPV4_NODE,
19606 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19607 install_element(BGP_IPV4_NODE,
19608 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19609 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19610 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19611 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19612 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19613 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19614 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19615
19616 /* import|export vpn [route-map RMAP_NAME] */
19617 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19618 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19619
19620 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19621 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19622
19623 /* ttl_security commands */
19624 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19625 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19626
19627 /* "bgp tcp-keepalive" commands */
19628 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
19629 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
19630
19631 /* "show [ip] bgp memory" commands. */
19632 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19633
19634 /* "show bgp martian next-hop" */
19635 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19636
19637 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19638
19639 /* "show [ip] bgp views" commands. */
19640 install_element(VIEW_NODE, &show_bgp_views_cmd);
19641
19642 /* "show [ip] bgp vrfs" commands. */
19643 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19644
19645 /* Community-list. */
19646 community_list_vty();
19647
19648 community_alias_vty();
19649
19650 /* vpn-policy commands */
19651 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19652 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19653 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19654 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19655 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19656 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19657 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19658 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19659 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19660 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19661 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19662 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19663
19664 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19665 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19666
19667 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19668 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19669 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19670 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19671 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19672 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19673 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19674 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19675 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19676 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19677
19678 /* tcp-mss command */
19679 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19680 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19681
19682 /* srv6 commands */
19683 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19684 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19685 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19686 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19687 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19688 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19689 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19690
19691 bgp_vty_if_init();
19692 }
19693
19694 #include "memory.h"
19695 #include "bgp_regex.h"
19696 #include "bgp_clist.h"
19697 #include "bgp_ecommunity.h"
19698
19699 /* VTY functions. */
19700
19701 /* Direction value to string conversion. */
19702 static const char *community_direct_str(int direct)
19703 {
19704 switch (direct) {
19705 case COMMUNITY_DENY:
19706 return "deny";
19707 case COMMUNITY_PERMIT:
19708 return "permit";
19709 default:
19710 return "unknown";
19711 }
19712 }
19713
19714 /* Display error string. */
19715 static void community_list_perror(struct vty *vty, int ret)
19716 {
19717 switch (ret) {
19718 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19719 vty_out(vty, "%% Can't find community-list\n");
19720 break;
19721 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19722 vty_out(vty, "%% Malformed community-list value\n");
19723 break;
19724 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19725 vty_out(vty,
19726 "%% Community name conflict, previously defined as standard community\n");
19727 break;
19728 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19729 vty_out(vty,
19730 "%% Community name conflict, previously defined as expanded community\n");
19731 break;
19732 }
19733 }
19734
19735 /* "community-list" keyword help string. */
19736 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19737
19738 /*community-list standard */
19739 DEFUN (community_list_standard,
19740 bgp_community_list_standard_cmd,
19741 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19742 BGP_STR
19743 COMMUNITY_LIST_STR
19744 "Community list number (standard)\n"
19745 "Add an standard community-list entry\n"
19746 "Community list name\n"
19747 "Sequence number of an entry\n"
19748 "Sequence number\n"
19749 "Specify community to reject\n"
19750 "Specify community to accept\n"
19751 COMMUNITY_VAL_STR)
19752 {
19753 char *cl_name_or_number = NULL;
19754 char *seq = NULL;
19755 int direct = 0;
19756 int style = COMMUNITY_LIST_STANDARD;
19757 int idx = 0;
19758
19759 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19760 seq = argv[idx]->arg;
19761
19762 idx = 0;
19763 argv_find(argv, argc, "(1-99)", &idx);
19764 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19765 cl_name_or_number = argv[idx]->arg;
19766 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19767 : COMMUNITY_DENY;
19768 argv_find(argv, argc, "AA:NN", &idx);
19769 char *str = argv_concat(argv, argc, idx);
19770
19771 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19772 direct, style);
19773
19774 XFREE(MTYPE_TMP, str);
19775
19776 if (ret < 0) {
19777 /* Display error string. */
19778 community_list_perror(vty, ret);
19779 return CMD_WARNING_CONFIG_FAILED;
19780 }
19781
19782 return CMD_SUCCESS;
19783 }
19784
19785 DEFUN (no_community_list_standard_all,
19786 no_bgp_community_list_standard_all_cmd,
19787 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19788 NO_STR
19789 BGP_STR
19790 COMMUNITY_LIST_STR
19791 "Community list number (standard)\n"
19792 "Add an standard community-list entry\n"
19793 "Community list name\n"
19794 "Sequence number of an entry\n"
19795 "Sequence number\n"
19796 "Specify community to reject\n"
19797 "Specify community to accept\n"
19798 COMMUNITY_VAL_STR)
19799 {
19800 char *cl_name_or_number = NULL;
19801 char *str = NULL;
19802 int direct = 0;
19803 int style = COMMUNITY_LIST_STANDARD;
19804 char *seq = NULL;
19805 int idx = 0;
19806
19807 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19808 seq = argv[idx]->arg;
19809
19810 idx = 0;
19811 argv_find(argv, argc, "permit", &idx);
19812 argv_find(argv, argc, "deny", &idx);
19813
19814 if (idx) {
19815 direct = argv_find(argv, argc, "permit", &idx)
19816 ? COMMUNITY_PERMIT
19817 : COMMUNITY_DENY;
19818
19819 idx = 0;
19820 argv_find(argv, argc, "AA:NN", &idx);
19821 str = argv_concat(argv, argc, idx);
19822 }
19823
19824 idx = 0;
19825 argv_find(argv, argc, "(1-99)", &idx);
19826 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19827 cl_name_or_number = argv[idx]->arg;
19828
19829 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19830 direct, style);
19831
19832 XFREE(MTYPE_TMP, str);
19833
19834 if (ret < 0) {
19835 community_list_perror(vty, ret);
19836 return CMD_WARNING_CONFIG_FAILED;
19837 }
19838
19839 return CMD_SUCCESS;
19840 }
19841
19842 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19843 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19844 NO_STR BGP_STR COMMUNITY_LIST_STR
19845 "Community list number (standard)\n"
19846 "Add an standard community-list entry\n"
19847 "Community list name\n")
19848
19849 /*community-list expanded */
19850 DEFUN (community_list_expanded_all,
19851 bgp_community_list_expanded_all_cmd,
19852 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19853 BGP_STR
19854 COMMUNITY_LIST_STR
19855 "Community list number (expanded)\n"
19856 "Add an expanded community-list entry\n"
19857 "Community list name\n"
19858 "Sequence number of an entry\n"
19859 "Sequence number\n"
19860 "Specify community to reject\n"
19861 "Specify community to accept\n"
19862 COMMUNITY_VAL_STR)
19863 {
19864 char *cl_name_or_number = NULL;
19865 char *seq = NULL;
19866 int direct = 0;
19867 int style = COMMUNITY_LIST_EXPANDED;
19868 int idx = 0;
19869
19870 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19871 seq = argv[idx]->arg;
19872
19873 idx = 0;
19874
19875 argv_find(argv, argc, "(100-500)", &idx);
19876 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19877 cl_name_or_number = argv[idx]->arg;
19878 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19879 : COMMUNITY_DENY;
19880 argv_find(argv, argc, "AA:NN", &idx);
19881 char *str = argv_concat(argv, argc, idx);
19882
19883 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19884 direct, style);
19885
19886 XFREE(MTYPE_TMP, str);
19887
19888 if (ret < 0) {
19889 /* Display error string. */
19890 community_list_perror(vty, ret);
19891 return CMD_WARNING_CONFIG_FAILED;
19892 }
19893
19894 return CMD_SUCCESS;
19895 }
19896
19897 DEFUN (no_community_list_expanded_all,
19898 no_bgp_community_list_expanded_all_cmd,
19899 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19900 NO_STR
19901 BGP_STR
19902 COMMUNITY_LIST_STR
19903 "Community list number (expanded)\n"
19904 "Add an expanded community-list entry\n"
19905 "Community list name\n"
19906 "Sequence number of an entry\n"
19907 "Sequence number\n"
19908 "Specify community to reject\n"
19909 "Specify community to accept\n"
19910 COMMUNITY_VAL_STR)
19911 {
19912 char *cl_name_or_number = NULL;
19913 char *seq = NULL;
19914 char *str = NULL;
19915 int direct = 0;
19916 int style = COMMUNITY_LIST_EXPANDED;
19917 int idx = 0;
19918
19919 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19920 seq = argv[idx]->arg;
19921
19922 idx = 0;
19923 argv_find(argv, argc, "permit", &idx);
19924 argv_find(argv, argc, "deny", &idx);
19925
19926 if (idx) {
19927 direct = argv_find(argv, argc, "permit", &idx)
19928 ? COMMUNITY_PERMIT
19929 : COMMUNITY_DENY;
19930
19931 idx = 0;
19932 argv_find(argv, argc, "AA:NN", &idx);
19933 str = argv_concat(argv, argc, idx);
19934 }
19935
19936 idx = 0;
19937 argv_find(argv, argc, "(100-500)", &idx);
19938 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19939 cl_name_or_number = argv[idx]->arg;
19940
19941 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19942 direct, style);
19943
19944 XFREE(MTYPE_TMP, str);
19945
19946 if (ret < 0) {
19947 community_list_perror(vty, ret);
19948 return CMD_WARNING_CONFIG_FAILED;
19949 }
19950
19951 return CMD_SUCCESS;
19952 }
19953
19954 ALIAS(no_community_list_expanded_all,
19955 no_bgp_community_list_expanded_all_list_cmd,
19956 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19957 NO_STR BGP_STR COMMUNITY_LIST_STR
19958 "Community list number (expanded)\n"
19959 "Add an expanded community-list entry\n"
19960 "Community list name\n")
19961
19962 /* Return configuration string of community-list entry. */
19963 static const char *community_list_config_str(struct community_entry *entry)
19964 {
19965 const char *str;
19966
19967 if (entry->any)
19968 str = "";
19969 else {
19970 if (entry->style == COMMUNITY_LIST_STANDARD)
19971 str = community_str(entry->u.com, false, false);
19972 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19973 str = lcommunity_str(entry->u.lcom, false, false);
19974 else
19975 str = entry->config;
19976 }
19977 return str;
19978 }
19979
19980 static void community_list_show(struct vty *vty, struct community_list *list)
19981 {
19982 struct community_entry *entry;
19983
19984 for (entry = list->head; entry; entry = entry->next) {
19985 if (entry == list->head) {
19986 if (all_digit(list->name))
19987 vty_out(vty, "Community %s list %s\n",
19988 entry->style == COMMUNITY_LIST_STANDARD
19989 ? "standard"
19990 : "(expanded) access",
19991 list->name);
19992 else
19993 vty_out(vty, "Named Community %s list %s\n",
19994 entry->style == COMMUNITY_LIST_STANDARD
19995 ? "standard"
19996 : "expanded",
19997 list->name);
19998 }
19999 if (entry->any)
20000 vty_out(vty, " %s\n",
20001 community_direct_str(entry->direct));
20002 else
20003 vty_out(vty, " %s %s\n",
20004 community_direct_str(entry->direct),
20005 community_list_config_str(entry));
20006 }
20007 }
20008
20009 DEFUN (show_community_list,
20010 show_bgp_community_list_cmd,
20011 "show bgp community-list",
20012 SHOW_STR
20013 BGP_STR
20014 "List community-list\n")
20015 {
20016 struct community_list *list;
20017 struct community_list_master *cm;
20018
20019 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20020 if (!cm)
20021 return CMD_SUCCESS;
20022
20023 for (list = cm->num.head; list; list = list->next)
20024 community_list_show(vty, list);
20025
20026 for (list = cm->str.head; list; list = list->next)
20027 community_list_show(vty, list);
20028
20029 return CMD_SUCCESS;
20030 }
20031
20032 DEFUN (show_community_list_arg,
20033 show_bgp_community_list_arg_cmd,
20034 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20035 SHOW_STR
20036 BGP_STR
20037 "List community-list\n"
20038 "Community-list number\n"
20039 "Community-list name\n"
20040 "Detailed information on community-list\n")
20041 {
20042 int idx_comm_list = 3;
20043 struct community_list *list;
20044
20045 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20046 COMMUNITY_LIST_MASTER);
20047 if (!list) {
20048 vty_out(vty, "%% Can't find community-list\n");
20049 return CMD_WARNING;
20050 }
20051
20052 community_list_show(vty, list);
20053
20054 return CMD_SUCCESS;
20055 }
20056
20057 /*
20058 * Large Community code.
20059 */
20060 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20061 struct cmd_token **argv, int style,
20062 int reject_all_digit_name)
20063 {
20064 int ret;
20065 int direct;
20066 char *str;
20067 int idx = 0;
20068 char *cl_name;
20069 char *seq = NULL;
20070
20071 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20072 seq = argv[idx]->arg;
20073
20074 idx = 0;
20075 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20076 : COMMUNITY_DENY;
20077
20078 /* All digit name check. */
20079 idx = 0;
20080 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20081 argv_find(argv, argc, "(1-99)", &idx);
20082 argv_find(argv, argc, "(100-500)", &idx);
20083 cl_name = argv[idx]->arg;
20084 if (reject_all_digit_name && all_digit(cl_name)) {
20085 vty_out(vty, "%% Community name cannot have all digits\n");
20086 return CMD_WARNING_CONFIG_FAILED;
20087 }
20088
20089 idx = 0;
20090 argv_find(argv, argc, "AA:BB:CC", &idx);
20091 argv_find(argv, argc, "LINE", &idx);
20092 /* Concat community string argument. */
20093 if (idx)
20094 str = argv_concat(argv, argc, idx);
20095 else
20096 str = NULL;
20097
20098 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20099
20100 /* Free temporary community list string allocated by
20101 argv_concat(). */
20102 XFREE(MTYPE_TMP, str);
20103
20104 if (ret < 0) {
20105 community_list_perror(vty, ret);
20106 return CMD_WARNING_CONFIG_FAILED;
20107 }
20108 return CMD_SUCCESS;
20109 }
20110
20111 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20112 struct cmd_token **argv, int style)
20113 {
20114 int ret;
20115 int direct = 0;
20116 char *str = NULL;
20117 int idx = 0;
20118 char *seq = NULL;
20119
20120 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20121 seq = argv[idx]->arg;
20122
20123 idx = 0;
20124 argv_find(argv, argc, "permit", &idx);
20125 argv_find(argv, argc, "deny", &idx);
20126
20127 if (idx) {
20128 /* Check the list direct. */
20129 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20130 direct = COMMUNITY_PERMIT;
20131 else
20132 direct = COMMUNITY_DENY;
20133
20134 idx = 0;
20135 argv_find(argv, argc, "LINE", &idx);
20136 argv_find(argv, argc, "AA:AA:NN", &idx);
20137 /* Concat community string argument. */
20138 str = argv_concat(argv, argc, idx);
20139 }
20140
20141 idx = 0;
20142 argv_find(argv, argc, "(1-99)", &idx);
20143 argv_find(argv, argc, "(100-500)", &idx);
20144 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20145
20146 /* Unset community list. */
20147 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20148 style);
20149
20150 /* Free temporary community list string allocated by
20151 argv_concat(). */
20152 XFREE(MTYPE_TMP, str);
20153
20154 if (ret < 0) {
20155 community_list_perror(vty, ret);
20156 return CMD_WARNING_CONFIG_FAILED;
20157 }
20158
20159 return CMD_SUCCESS;
20160 }
20161
20162 /* "large-community-list" keyword help string. */
20163 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20164 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20165
20166 DEFUN (lcommunity_list_standard,
20167 bgp_lcommunity_list_standard_cmd,
20168 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20169 BGP_STR
20170 LCOMMUNITY_LIST_STR
20171 "Large Community list number (standard)\n"
20172 "Sequence number of an entry\n"
20173 "Sequence number\n"
20174 "Specify large community to reject\n"
20175 "Specify large community to accept\n"
20176 LCOMMUNITY_VAL_STR)
20177 {
20178 return lcommunity_list_set_vty(vty, argc, argv,
20179 LARGE_COMMUNITY_LIST_STANDARD, 0);
20180 }
20181
20182 DEFUN (lcommunity_list_expanded,
20183 bgp_lcommunity_list_expanded_cmd,
20184 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20185 BGP_STR
20186 LCOMMUNITY_LIST_STR
20187 "Large Community list number (expanded)\n"
20188 "Sequence number of an entry\n"
20189 "Sequence number\n"
20190 "Specify large community to reject\n"
20191 "Specify large community to accept\n"
20192 "An ordered list as a regular-expression\n")
20193 {
20194 return lcommunity_list_set_vty(vty, argc, argv,
20195 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20196 }
20197
20198 DEFUN (lcommunity_list_name_standard,
20199 bgp_lcommunity_list_name_standard_cmd,
20200 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20201 BGP_STR
20202 LCOMMUNITY_LIST_STR
20203 "Specify standard large-community-list\n"
20204 "Large Community list name\n"
20205 "Sequence number of an entry\n"
20206 "Sequence number\n"
20207 "Specify large community to reject\n"
20208 "Specify large community to accept\n"
20209 LCOMMUNITY_VAL_STR)
20210 {
20211 return lcommunity_list_set_vty(vty, argc, argv,
20212 LARGE_COMMUNITY_LIST_STANDARD, 1);
20213 }
20214
20215 DEFUN (lcommunity_list_name_expanded,
20216 bgp_lcommunity_list_name_expanded_cmd,
20217 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20218 BGP_STR
20219 LCOMMUNITY_LIST_STR
20220 "Specify expanded large-community-list\n"
20221 "Large Community list name\n"
20222 "Sequence number of an entry\n"
20223 "Sequence number\n"
20224 "Specify large community to reject\n"
20225 "Specify large community to accept\n"
20226 "An ordered list as a regular-expression\n")
20227 {
20228 return lcommunity_list_set_vty(vty, argc, argv,
20229 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20230 }
20231
20232 DEFUN (no_lcommunity_list_all,
20233 no_bgp_lcommunity_list_all_cmd,
20234 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20235 NO_STR
20236 BGP_STR
20237 LCOMMUNITY_LIST_STR
20238 "Large Community list number (standard)\n"
20239 "Large Community list number (expanded)\n"
20240 "Large Community list name\n")
20241 {
20242 return lcommunity_list_unset_vty(vty, argc, argv,
20243 LARGE_COMMUNITY_LIST_STANDARD);
20244 }
20245
20246 DEFUN (no_lcommunity_list_name_standard_all,
20247 no_bgp_lcommunity_list_name_standard_all_cmd,
20248 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20249 NO_STR
20250 BGP_STR
20251 LCOMMUNITY_LIST_STR
20252 "Specify standard large-community-list\n"
20253 "Large Community list name\n")
20254 {
20255 return lcommunity_list_unset_vty(vty, argc, argv,
20256 LARGE_COMMUNITY_LIST_STANDARD);
20257 }
20258
20259 DEFUN (no_lcommunity_list_name_expanded_all,
20260 no_bgp_lcommunity_list_name_expanded_all_cmd,
20261 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20262 NO_STR
20263 BGP_STR
20264 LCOMMUNITY_LIST_STR
20265 "Specify expanded large-community-list\n"
20266 "Large Community list name\n")
20267 {
20268 return lcommunity_list_unset_vty(vty, argc, argv,
20269 LARGE_COMMUNITY_LIST_EXPANDED);
20270 }
20271
20272 DEFUN (no_lcommunity_list_standard,
20273 no_bgp_lcommunity_list_standard_cmd,
20274 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20275 NO_STR
20276 BGP_STR
20277 LCOMMUNITY_LIST_STR
20278 "Large Community list number (standard)\n"
20279 "Sequence number of an entry\n"
20280 "Sequence number\n"
20281 "Specify large community to reject\n"
20282 "Specify large community to accept\n"
20283 LCOMMUNITY_VAL_STR)
20284 {
20285 return lcommunity_list_unset_vty(vty, argc, argv,
20286 LARGE_COMMUNITY_LIST_STANDARD);
20287 }
20288
20289 DEFUN (no_lcommunity_list_expanded,
20290 no_bgp_lcommunity_list_expanded_cmd,
20291 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20292 NO_STR
20293 BGP_STR
20294 LCOMMUNITY_LIST_STR
20295 "Large Community list number (expanded)\n"
20296 "Sequence number of an entry\n"
20297 "Sequence number\n"
20298 "Specify large community to reject\n"
20299 "Specify large community to accept\n"
20300 "An ordered list as a regular-expression\n")
20301 {
20302 return lcommunity_list_unset_vty(vty, argc, argv,
20303 LARGE_COMMUNITY_LIST_EXPANDED);
20304 }
20305
20306 DEFUN (no_lcommunity_list_name_standard,
20307 no_bgp_lcommunity_list_name_standard_cmd,
20308 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20309 NO_STR
20310 BGP_STR
20311 LCOMMUNITY_LIST_STR
20312 "Specify standard large-community-list\n"
20313 "Large Community list name\n"
20314 "Sequence number of an entry\n"
20315 "Sequence number\n"
20316 "Specify large community to reject\n"
20317 "Specify large community to accept\n"
20318 LCOMMUNITY_VAL_STR)
20319 {
20320 return lcommunity_list_unset_vty(vty, argc, argv,
20321 LARGE_COMMUNITY_LIST_STANDARD);
20322 }
20323
20324 DEFUN (no_lcommunity_list_name_expanded,
20325 no_bgp_lcommunity_list_name_expanded_cmd,
20326 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20327 NO_STR
20328 BGP_STR
20329 LCOMMUNITY_LIST_STR
20330 "Specify expanded large-community-list\n"
20331 "Large community list name\n"
20332 "Sequence number of an entry\n"
20333 "Sequence number\n"
20334 "Specify large community to reject\n"
20335 "Specify large community to accept\n"
20336 "An ordered list as a regular-expression\n")
20337 {
20338 return lcommunity_list_unset_vty(vty, argc, argv,
20339 LARGE_COMMUNITY_LIST_EXPANDED);
20340 }
20341
20342 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20343 {
20344 struct community_entry *entry;
20345
20346 for (entry = list->head; entry; entry = entry->next) {
20347 if (entry == list->head) {
20348 if (all_digit(list->name))
20349 vty_out(vty, "Large community %s list %s\n",
20350 entry->style ==
20351 LARGE_COMMUNITY_LIST_STANDARD
20352 ? "standard"
20353 : "(expanded) access",
20354 list->name);
20355 else
20356 vty_out(vty,
20357 "Named large community %s list %s\n",
20358 entry->style ==
20359 LARGE_COMMUNITY_LIST_STANDARD
20360 ? "standard"
20361 : "expanded",
20362 list->name);
20363 }
20364 if (entry->any)
20365 vty_out(vty, " %s\n",
20366 community_direct_str(entry->direct));
20367 else
20368 vty_out(vty, " %s %s\n",
20369 community_direct_str(entry->direct),
20370 community_list_config_str(entry));
20371 }
20372 }
20373
20374 DEFUN (show_lcommunity_list,
20375 show_bgp_lcommunity_list_cmd,
20376 "show bgp large-community-list",
20377 SHOW_STR
20378 BGP_STR
20379 "List large-community list\n")
20380 {
20381 struct community_list *list;
20382 struct community_list_master *cm;
20383
20384 cm = community_list_master_lookup(bgp_clist,
20385 LARGE_COMMUNITY_LIST_MASTER);
20386 if (!cm)
20387 return CMD_SUCCESS;
20388
20389 for (list = cm->num.head; list; list = list->next)
20390 lcommunity_list_show(vty, list);
20391
20392 for (list = cm->str.head; list; list = list->next)
20393 lcommunity_list_show(vty, list);
20394
20395 return CMD_SUCCESS;
20396 }
20397
20398 DEFUN (show_lcommunity_list_arg,
20399 show_bgp_lcommunity_list_arg_cmd,
20400 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20401 SHOW_STR
20402 BGP_STR
20403 "List large-community list\n"
20404 "Large-community-list number\n"
20405 "Large-community-list name\n"
20406 "Detailed information on large-community-list\n")
20407 {
20408 struct community_list *list;
20409
20410 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20411 LARGE_COMMUNITY_LIST_MASTER);
20412 if (!list) {
20413 vty_out(vty, "%% Can't find large-community-list\n");
20414 return CMD_WARNING;
20415 }
20416
20417 lcommunity_list_show(vty, list);
20418
20419 return CMD_SUCCESS;
20420 }
20421
20422 /* "extcommunity-list" keyword help string. */
20423 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20424 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20425
20426 DEFUN (extcommunity_list_standard,
20427 bgp_extcommunity_list_standard_cmd,
20428 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20429 BGP_STR
20430 EXTCOMMUNITY_LIST_STR
20431 "Extended Community list number (standard)\n"
20432 "Specify standard extcommunity-list\n"
20433 "Community list name\n"
20434 "Sequence number of an entry\n"
20435 "Sequence number\n"
20436 "Specify community to reject\n"
20437 "Specify community to accept\n"
20438 EXTCOMMUNITY_VAL_STR)
20439 {
20440 int style = EXTCOMMUNITY_LIST_STANDARD;
20441 int direct = 0;
20442 char *cl_number_or_name = NULL;
20443 char *seq = NULL;
20444
20445 int idx = 0;
20446
20447 argv_find(argv, argc, "(1-99)", &idx);
20448 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20449 cl_number_or_name = argv[idx]->arg;
20450
20451 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20452 seq = argv[idx]->arg;
20453
20454 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20455 : COMMUNITY_DENY;
20456 argv_find(argv, argc, "AA:NN", &idx);
20457 char *str = argv_concat(argv, argc, idx);
20458
20459 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20460 direct, style);
20461
20462 XFREE(MTYPE_TMP, str);
20463
20464 if (ret < 0) {
20465 community_list_perror(vty, ret);
20466 return CMD_WARNING_CONFIG_FAILED;
20467 }
20468
20469 return CMD_SUCCESS;
20470 }
20471
20472 DEFUN (extcommunity_list_name_expanded,
20473 bgp_extcommunity_list_name_expanded_cmd,
20474 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20475 BGP_STR
20476 EXTCOMMUNITY_LIST_STR
20477 "Extended Community list number (expanded)\n"
20478 "Specify expanded extcommunity-list\n"
20479 "Extended Community list name\n"
20480 "Sequence number of an entry\n"
20481 "Sequence number\n"
20482 "Specify community to reject\n"
20483 "Specify community to accept\n"
20484 "An ordered list as a regular-expression\n")
20485 {
20486 int style = EXTCOMMUNITY_LIST_EXPANDED;
20487 int direct = 0;
20488 char *cl_number_or_name = NULL;
20489 char *seq = NULL;
20490 int idx = 0;
20491
20492 argv_find(argv, argc, "(100-500)", &idx);
20493 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20494 cl_number_or_name = argv[idx]->arg;
20495
20496 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20497 seq = argv[idx]->arg;
20498
20499 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20500 : COMMUNITY_DENY;
20501 argv_find(argv, argc, "LINE", &idx);
20502 char *str = argv_concat(argv, argc, idx);
20503
20504 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20505 direct, style);
20506
20507 XFREE(MTYPE_TMP, str);
20508
20509 if (ret < 0) {
20510 community_list_perror(vty, ret);
20511 return CMD_WARNING_CONFIG_FAILED;
20512 }
20513
20514 return CMD_SUCCESS;
20515 }
20516
20517 DEFUN (no_extcommunity_list_standard_all,
20518 no_bgp_extcommunity_list_standard_all_cmd,
20519 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20520 NO_STR
20521 BGP_STR
20522 EXTCOMMUNITY_LIST_STR
20523 "Extended Community list number (standard)\n"
20524 "Specify standard extcommunity-list\n"
20525 "Community list name\n"
20526 "Sequence number of an entry\n"
20527 "Sequence number\n"
20528 "Specify community to reject\n"
20529 "Specify community to accept\n"
20530 EXTCOMMUNITY_VAL_STR)
20531 {
20532 int style = EXTCOMMUNITY_LIST_STANDARD;
20533 int direct = 0;
20534 char *cl_number_or_name = NULL;
20535 char *str = NULL;
20536 char *seq = NULL;
20537 int idx = 0;
20538
20539 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20540 seq = argv[idx]->arg;
20541
20542 idx = 0;
20543 argv_find(argv, argc, "permit", &idx);
20544 argv_find(argv, argc, "deny", &idx);
20545 if (idx) {
20546 direct = argv_find(argv, argc, "permit", &idx)
20547 ? COMMUNITY_PERMIT
20548 : COMMUNITY_DENY;
20549
20550 idx = 0;
20551 argv_find(argv, argc, "AA:NN", &idx);
20552 str = argv_concat(argv, argc, idx);
20553 }
20554
20555 idx = 0;
20556 argv_find(argv, argc, "(1-99)", &idx);
20557 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20558 cl_number_or_name = argv[idx]->arg;
20559
20560 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20561 seq, direct, style);
20562
20563 XFREE(MTYPE_TMP, str);
20564
20565 if (ret < 0) {
20566 community_list_perror(vty, ret);
20567 return CMD_WARNING_CONFIG_FAILED;
20568 }
20569
20570 return CMD_SUCCESS;
20571 }
20572
20573 ALIAS(no_extcommunity_list_standard_all,
20574 no_bgp_extcommunity_list_standard_all_list_cmd,
20575 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20576 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20577 "Extended Community list number (standard)\n"
20578 "Specify standard extcommunity-list\n"
20579 "Community list name\n")
20580
20581 DEFUN (no_extcommunity_list_expanded_all,
20582 no_bgp_extcommunity_list_expanded_all_cmd,
20583 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20584 NO_STR
20585 BGP_STR
20586 EXTCOMMUNITY_LIST_STR
20587 "Extended Community list number (expanded)\n"
20588 "Specify expanded extcommunity-list\n"
20589 "Extended Community list name\n"
20590 "Sequence number of an entry\n"
20591 "Sequence number\n"
20592 "Specify community to reject\n"
20593 "Specify community to accept\n"
20594 "An ordered list as a regular-expression\n")
20595 {
20596 int style = EXTCOMMUNITY_LIST_EXPANDED;
20597 int direct = 0;
20598 char *cl_number_or_name = NULL;
20599 char *str = NULL;
20600 char *seq = NULL;
20601 int idx = 0;
20602
20603 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20604 seq = argv[idx]->arg;
20605
20606 idx = 0;
20607 argv_find(argv, argc, "permit", &idx);
20608 argv_find(argv, argc, "deny", &idx);
20609
20610 if (idx) {
20611 direct = argv_find(argv, argc, "permit", &idx)
20612 ? COMMUNITY_PERMIT
20613 : COMMUNITY_DENY;
20614
20615 idx = 0;
20616 argv_find(argv, argc, "LINE", &idx);
20617 str = argv_concat(argv, argc, idx);
20618 }
20619
20620 idx = 0;
20621 argv_find(argv, argc, "(100-500)", &idx);
20622 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20623 cl_number_or_name = argv[idx]->arg;
20624
20625 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20626 seq, direct, style);
20627
20628 XFREE(MTYPE_TMP, str);
20629
20630 if (ret < 0) {
20631 community_list_perror(vty, ret);
20632 return CMD_WARNING_CONFIG_FAILED;
20633 }
20634
20635 return CMD_SUCCESS;
20636 }
20637
20638 ALIAS(no_extcommunity_list_expanded_all,
20639 no_bgp_extcommunity_list_expanded_all_list_cmd,
20640 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20641 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20642 "Extended Community list number (expanded)\n"
20643 "Specify expanded extcommunity-list\n"
20644 "Extended Community list name\n")
20645
20646 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20647 {
20648 struct community_entry *entry;
20649
20650 for (entry = list->head; entry; entry = entry->next) {
20651 if (entry == list->head) {
20652 if (all_digit(list->name))
20653 vty_out(vty, "Extended community %s list %s\n",
20654 entry->style == EXTCOMMUNITY_LIST_STANDARD
20655 ? "standard"
20656 : "(expanded) access",
20657 list->name);
20658 else
20659 vty_out(vty,
20660 "Named extended community %s list %s\n",
20661 entry->style == EXTCOMMUNITY_LIST_STANDARD
20662 ? "standard"
20663 : "expanded",
20664 list->name);
20665 }
20666 if (entry->any)
20667 vty_out(vty, " %s\n",
20668 community_direct_str(entry->direct));
20669 else
20670 vty_out(vty, " %s %s\n",
20671 community_direct_str(entry->direct),
20672 community_list_config_str(entry));
20673 }
20674 }
20675
20676 DEFUN (show_extcommunity_list,
20677 show_bgp_extcommunity_list_cmd,
20678 "show bgp extcommunity-list",
20679 SHOW_STR
20680 BGP_STR
20681 "List extended-community list\n")
20682 {
20683 struct community_list *list;
20684 struct community_list_master *cm;
20685
20686 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20687 if (!cm)
20688 return CMD_SUCCESS;
20689
20690 for (list = cm->num.head; list; list = list->next)
20691 extcommunity_list_show(vty, list);
20692
20693 for (list = cm->str.head; list; list = list->next)
20694 extcommunity_list_show(vty, list);
20695
20696 return CMD_SUCCESS;
20697 }
20698
20699 DEFUN (show_extcommunity_list_arg,
20700 show_bgp_extcommunity_list_arg_cmd,
20701 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20702 SHOW_STR
20703 BGP_STR
20704 "List extended-community list\n"
20705 "Extcommunity-list number\n"
20706 "Extcommunity-list name\n"
20707 "Detailed information on extcommunity-list\n")
20708 {
20709 int idx_comm_list = 3;
20710 struct community_list *list;
20711
20712 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20713 EXTCOMMUNITY_LIST_MASTER);
20714 if (!list) {
20715 vty_out(vty, "%% Can't find extcommunity-list\n");
20716 return CMD_WARNING;
20717 }
20718
20719 extcommunity_list_show(vty, list);
20720
20721 return CMD_SUCCESS;
20722 }
20723
20724 /* Display community-list and extcommunity-list configuration. */
20725 static int community_list_config_write(struct vty *vty)
20726 {
20727 struct community_list *list;
20728 struct community_entry *entry;
20729 struct community_list_master *cm;
20730 int write = 0;
20731
20732 /* Community-list. */
20733 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20734
20735 for (list = cm->num.head; list; list = list->next)
20736 for (entry = list->head; entry; entry = entry->next) {
20737 vty_out(vty,
20738 "bgp community-list %s seq %" PRId64 " %s %s\n",
20739 list->name, entry->seq,
20740 community_direct_str(entry->direct),
20741 community_list_config_str(entry));
20742 write++;
20743 }
20744 for (list = cm->str.head; list; list = list->next)
20745 for (entry = list->head; entry; entry = entry->next) {
20746 vty_out(vty,
20747 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20748 entry->style == COMMUNITY_LIST_STANDARD
20749 ? "standard"
20750 : "expanded",
20751 list->name, entry->seq,
20752 community_direct_str(entry->direct),
20753 community_list_config_str(entry));
20754 write++;
20755 }
20756
20757 /* Extcommunity-list. */
20758 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20759
20760 for (list = cm->num.head; list; list = list->next)
20761 for (entry = list->head; entry; entry = entry->next) {
20762 vty_out(vty,
20763 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20764 list->name, entry->seq,
20765 community_direct_str(entry->direct),
20766 community_list_config_str(entry));
20767 write++;
20768 }
20769 for (list = cm->str.head; list; list = list->next)
20770 for (entry = list->head; entry; entry = entry->next) {
20771 vty_out(vty,
20772 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20773 entry->style == EXTCOMMUNITY_LIST_STANDARD
20774 ? "standard"
20775 : "expanded",
20776 list->name, entry->seq,
20777 community_direct_str(entry->direct),
20778 community_list_config_str(entry));
20779 write++;
20780 }
20781
20782
20783 /* lcommunity-list. */
20784 cm = community_list_master_lookup(bgp_clist,
20785 LARGE_COMMUNITY_LIST_MASTER);
20786
20787 for (list = cm->num.head; list; list = list->next)
20788 for (entry = list->head; entry; entry = entry->next) {
20789 vty_out(vty,
20790 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20791 list->name, entry->seq,
20792 community_direct_str(entry->direct),
20793 community_list_config_str(entry));
20794 write++;
20795 }
20796 for (list = cm->str.head; list; list = list->next)
20797 for (entry = list->head; entry; entry = entry->next) {
20798 vty_out(vty,
20799 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20800
20801 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20802 ? "standard"
20803 : "expanded",
20804 list->name, entry->seq, community_direct_str(entry->direct),
20805 community_list_config_str(entry));
20806 write++;
20807 }
20808
20809 return write;
20810 }
20811
20812 static int community_list_config_write(struct vty *vty);
20813 static struct cmd_node community_list_node = {
20814 .name = "community list",
20815 .node = COMMUNITY_LIST_NODE,
20816 .prompt = "",
20817 .config_write = community_list_config_write,
20818 };
20819
20820 static void community_list_vty(void)
20821 {
20822 install_node(&community_list_node);
20823
20824 /* Community-list. */
20825 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20826 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20827 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20828 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20829 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20830 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20831 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20832 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20833
20834 /* Extcommunity-list. */
20835 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20836 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20837 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20838 install_element(CONFIG_NODE,
20839 &no_bgp_extcommunity_list_standard_all_list_cmd);
20840 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20841 install_element(CONFIG_NODE,
20842 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20843 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20844 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20845
20846 /* Large Community List */
20847 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20848 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20849 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20850 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20851 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20852 install_element(CONFIG_NODE,
20853 &no_bgp_lcommunity_list_name_standard_all_cmd);
20854 install_element(CONFIG_NODE,
20855 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20856 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20857 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20858 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20859 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20860 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20861 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20862
20863 bgp_community_list_command_completion_setup();
20864 }
20865
20866 static struct cmd_node community_alias_node = {
20867 .name = "community alias",
20868 .node = COMMUNITY_ALIAS_NODE,
20869 .prompt = "",
20870 .config_write = bgp_community_alias_write,
20871 };
20872
20873 void community_alias_vty(void)
20874 {
20875 install_node(&community_alias_node);
20876
20877 /* Community-list. */
20878 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20879
20880 bgp_community_alias_command_completion_setup();
20881 }