]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12084 from ak503/bgp_show_lc
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_attr_evpn.h"
45 #include "bgpd/bgp_advertise.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_community_alias.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_debug.h"
54 #include "bgpd/bgp_errors.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_nht.h"
57 #include "bgpd/bgp_nexthop.h"
58 #include "bgpd/bgp_network.h"
59 #include "bgpd/bgp_open.h"
60 #include "bgpd/bgp_regex.h"
61 #include "bgpd/bgp_route.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_zebra.h"
64 #include "bgpd/bgp_table.h"
65 #include "bgpd/bgp_vty.h"
66 #include "bgpd/bgp_mpath.h"
67 #include "bgpd/bgp_packet.h"
68 #include "bgpd/bgp_updgrp.h"
69 #include "bgpd/bgp_bfd.h"
70 #include "bgpd/bgp_io.h"
71 #include "bgpd/bgp_evpn.h"
72 #include "bgpd/bgp_evpn_vty.h"
73 #include "bgpd/bgp_evpn_mh.h"
74 #include "bgpd/bgp_addpath.h"
75 #include "bgpd/bgp_mac.h"
76 #include "bgpd/bgp_flowspec.h"
77 #include "bgpd/bgp_conditional_adv.h"
78 #ifdef ENABLE_BGP_VNC
79 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
80 #endif
81
82 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
83 {
84 .val_bool = false,
85 .match_profile = "traditional",
86 .match_version = "< 7.4",
87 },
88 { .val_bool = true },
89 );
90 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
91 { .val_bool = true, .match_profile = "datacenter", },
92 { .val_bool = false },
93 );
94 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
95 { .val_bool = true, .match_profile = "datacenter", },
96 { .val_bool = false },
97 );
98 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
99 { .val_bool = true, .match_profile = "datacenter", },
100 { .val_bool = false },
101 );
102 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
103 { .val_bool = true, .match_profile = "datacenter", },
104 { .val_bool = false },
105 );
106 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
107 { .val_ulong = 10, .match_profile = "datacenter", },
108 { .val_ulong = 120 },
109 );
110 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
111 { .val_ulong = 9, .match_profile = "datacenter", },
112 { .val_ulong = 180 },
113 );
114 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
115 { .val_ulong = 3, .match_profile = "datacenter", },
116 { .val_ulong = 60 },
117 );
118 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
119 { .val_bool = false, .match_profile = "datacenter", },
120 { .val_bool = false, .match_version = "< 7.4", },
121 { .val_bool = true },
122 );
123 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
124 { .val_bool = false, .match_version = "< 7.6", },
125 { .val_bool = true },
126 );
127 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
128 { .val_bool = false, .match_version = "< 8.3", },
129 { .val_bool = true },
130 );
131 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
132 { .val_bool = false, .match_version = "< 8.3", },
133 { .val_bool = true },
134 );
135
136 DEFINE_HOOK(bgp_inst_config_write,
137 (struct bgp *bgp, struct vty *vty),
138 (bgp, vty));
139 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
140 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
141
142 static struct peer_group *listen_range_exists(struct bgp *bgp,
143 struct prefix *range, int exact);
144
145 /* Show BGP peer's information. */
146 enum show_type {
147 show_all,
148 show_peer,
149 show_ipv4_all,
150 show_ipv6_all,
151 show_ipv4_peer,
152 show_ipv6_peer
153 };
154
155 static struct peer_group *listen_range_exists(struct bgp *bgp,
156 struct prefix *range, int exact);
157
158 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
159 struct bgp *bgp,
160 bool use_json,
161 json_object *json);
162
163 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
164 enum show_type type,
165 const char *ip_str,
166 afi_t afi, bool use_json);
167
168 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
169 {
170 switch (afi) {
171 case AFI_IP:
172 switch (safi) {
173 case SAFI_UNICAST:
174 return BGP_IPV4_NODE;
175 case SAFI_MULTICAST:
176 return BGP_IPV4M_NODE;
177 case SAFI_LABELED_UNICAST:
178 return BGP_IPV4L_NODE;
179 case SAFI_MPLS_VPN:
180 return BGP_VPNV4_NODE;
181 case SAFI_FLOWSPEC:
182 return BGP_FLOWSPECV4_NODE;
183 default:
184 /* not expected */
185 return BGP_IPV4_NODE;
186 }
187 case AFI_IP6:
188 switch (safi) {
189 case SAFI_UNICAST:
190 return BGP_IPV6_NODE;
191 case SAFI_MULTICAST:
192 return BGP_IPV6M_NODE;
193 case SAFI_LABELED_UNICAST:
194 return BGP_IPV6L_NODE;
195 case SAFI_MPLS_VPN:
196 return BGP_VPNV6_NODE;
197 case SAFI_FLOWSPEC:
198 return BGP_FLOWSPECV6_NODE;
199 default:
200 /* not expected */
201 return BGP_IPV4_NODE;
202 }
203 case AFI_L2VPN:
204 return BGP_EVPN_NODE;
205 case AFI_UNSPEC:
206 case AFI_MAX:
207 // We should never be here but to clarify the switch statement..
208 return BGP_IPV4_NODE;
209 }
210
211 // Impossible to happen
212 return BGP_IPV4_NODE;
213 }
214
215 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
216 {
217 if (afi == AFI_IP) {
218 if (safi == SAFI_UNICAST)
219 return "IPv4 Unicast";
220 if (safi == SAFI_MULTICAST)
221 return "IPv4 Multicast";
222 if (safi == SAFI_LABELED_UNICAST)
223 return "IPv4 Labeled Unicast";
224 if (safi == SAFI_MPLS_VPN)
225 return "IPv4 VPN";
226 if (safi == SAFI_ENCAP)
227 return "IPv4 Encap";
228 if (safi == SAFI_FLOWSPEC)
229 return "IPv4 Flowspec";
230 } else if (afi == AFI_IP6) {
231 if (safi == SAFI_UNICAST)
232 return "IPv6 Unicast";
233 if (safi == SAFI_MULTICAST)
234 return "IPv6 Multicast";
235 if (safi == SAFI_LABELED_UNICAST)
236 return "IPv6 Labeled Unicast";
237 if (safi == SAFI_MPLS_VPN)
238 return "IPv6 VPN";
239 if (safi == SAFI_ENCAP)
240 return "IPv6 Encap";
241 if (safi == SAFI_FLOWSPEC)
242 return "IPv6 Flowspec";
243 } else if (afi == AFI_L2VPN) {
244 if (safi == SAFI_EVPN)
245 return "L2VPN EVPN";
246 }
247
248 return "Unknown";
249 }
250
251 /*
252 * Please note that we have intentionally camelCased
253 * the return strings here. So if you want
254 * to use this function, please ensure you
255 * are doing this within json output
256 */
257 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
258 {
259 if (afi == AFI_IP) {
260 if (safi == SAFI_UNICAST)
261 return "ipv4Unicast";
262 if (safi == SAFI_MULTICAST)
263 return "ipv4Multicast";
264 if (safi == SAFI_LABELED_UNICAST)
265 return "ipv4LabeledUnicast";
266 if (safi == SAFI_MPLS_VPN)
267 return "ipv4Vpn";
268 if (safi == SAFI_ENCAP)
269 return "ipv4Encap";
270 if (safi == SAFI_FLOWSPEC)
271 return "ipv4Flowspec";
272 } else if (afi == AFI_IP6) {
273 if (safi == SAFI_UNICAST)
274 return "ipv6Unicast";
275 if (safi == SAFI_MULTICAST)
276 return "ipv6Multicast";
277 if (safi == SAFI_LABELED_UNICAST)
278 return "ipv6LabeledUnicast";
279 if (safi == SAFI_MPLS_VPN)
280 return "ipv6Vpn";
281 if (safi == SAFI_ENCAP)
282 return "ipv6Encap";
283 if (safi == SAFI_FLOWSPEC)
284 return "ipv6Flowspec";
285 } else if (afi == AFI_L2VPN) {
286 if (safi == SAFI_EVPN)
287 return "l2VpnEvpn";
288 }
289
290 return "Unknown";
291 }
292
293 /* unset srv6 locator */
294 static int bgp_srv6_locator_unset(struct bgp *bgp)
295 {
296 int ret;
297 struct listnode *node, *nnode;
298 struct srv6_locator_chunk *chunk;
299 struct bgp_srv6_function *func;
300 struct bgp *bgp_vrf;
301 struct in6_addr *tovpn_sid;
302
303 /* release chunk notification via ZAPI */
304 ret = bgp_zebra_srv6_manager_release_locator_chunk(
305 bgp->srv6_locator_name);
306 if (ret < 0)
307 return -1;
308
309 /* refresh chunks */
310 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
311 listnode_delete(bgp->srv6_locator_chunks, chunk);
312 srv6_locator_chunk_free(chunk);
313 }
314
315 /* refresh functions */
316 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
317 listnode_delete(bgp->srv6_functions, func);
318 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
319 }
320
321 /* refresh tovpn_sid */
322 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
323 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
324 continue;
325
326 /* refresh vpnv4 tovpn_sid */
327 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
328 if (tovpn_sid)
329 XFREE(MTYPE_BGP_SRV6_SID,
330 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
331
332 /* refresh vpnv6 tovpn_sid */
333 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
334 if (tovpn_sid)
335 XFREE(MTYPE_BGP_SRV6_SID,
336 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
337 }
338
339 /* update vpn bgp processes */
340 vpn_leak_postchange_all();
341
342 /* refresh tovpn_sid_locator */
343 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
344 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
345 continue;
346
347 /* refresh vpnv4 tovpn_sid_locator */
348 XFREE(MTYPE_BGP_SRV6_SID,
349 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
350
351 /* refresh vpnv6 tovpn_sid_locator */
352 XFREE(MTYPE_BGP_SRV6_SID,
353 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
354 }
355
356 /* clear locator name */
357 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
358
359 return 0;
360 }
361
362 /* Utility function to get address family from current node. */
363 afi_t bgp_node_afi(struct vty *vty)
364 {
365 afi_t afi;
366 switch (vty->node) {
367 case BGP_IPV6_NODE:
368 case BGP_IPV6M_NODE:
369 case BGP_IPV6L_NODE:
370 case BGP_VPNV6_NODE:
371 case BGP_FLOWSPECV6_NODE:
372 afi = AFI_IP6;
373 break;
374 case BGP_EVPN_NODE:
375 afi = AFI_L2VPN;
376 break;
377 default:
378 afi = AFI_IP;
379 break;
380 }
381 return afi;
382 }
383
384 /* Utility function to get subsequent address family from current
385 node. */
386 safi_t bgp_node_safi(struct vty *vty)
387 {
388 safi_t safi;
389 switch (vty->node) {
390 case BGP_VPNV4_NODE:
391 case BGP_VPNV6_NODE:
392 safi = SAFI_MPLS_VPN;
393 break;
394 case BGP_IPV4M_NODE:
395 case BGP_IPV6M_NODE:
396 safi = SAFI_MULTICAST;
397 break;
398 case BGP_EVPN_NODE:
399 safi = SAFI_EVPN;
400 break;
401 case BGP_IPV4L_NODE:
402 case BGP_IPV6L_NODE:
403 safi = SAFI_LABELED_UNICAST;
404 break;
405 case BGP_FLOWSPECV4_NODE:
406 case BGP_FLOWSPECV6_NODE:
407 safi = SAFI_FLOWSPEC;
408 break;
409 default:
410 safi = SAFI_UNICAST;
411 break;
412 }
413 return safi;
414 }
415
416 /**
417 * Converts an AFI in string form to afi_t
418 *
419 * @param afi string, one of
420 * - "ipv4"
421 * - "ipv6"
422 * - "l2vpn"
423 * @return the corresponding afi_t
424 */
425 afi_t bgp_vty_afi_from_str(const char *afi_str)
426 {
427 afi_t afi = AFI_MAX; /* unknown */
428 if (strmatch(afi_str, "ipv4"))
429 afi = AFI_IP;
430 else if (strmatch(afi_str, "ipv6"))
431 afi = AFI_IP6;
432 else if (strmatch(afi_str, "l2vpn"))
433 afi = AFI_L2VPN;
434 return afi;
435 }
436
437 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
438 afi_t *afi)
439 {
440 int ret = 0;
441 if (argv_find(argv, argc, "ipv4", index)) {
442 ret = 1;
443 if (afi)
444 *afi = AFI_IP;
445 } else if (argv_find(argv, argc, "ipv6", index)) {
446 ret = 1;
447 if (afi)
448 *afi = AFI_IP6;
449 } else if (argv_find(argv, argc, "l2vpn", index)) {
450 ret = 1;
451 if (afi)
452 *afi = AFI_L2VPN;
453 }
454 return ret;
455 }
456
457 /* supports <unicast|multicast|vpn|labeled-unicast> */
458 safi_t bgp_vty_safi_from_str(const char *safi_str)
459 {
460 safi_t safi = SAFI_MAX; /* unknown */
461 if (strmatch(safi_str, "multicast"))
462 safi = SAFI_MULTICAST;
463 else if (strmatch(safi_str, "unicast"))
464 safi = SAFI_UNICAST;
465 else if (strmatch(safi_str, "vpn"))
466 safi = SAFI_MPLS_VPN;
467 else if (strmatch(safi_str, "evpn"))
468 safi = SAFI_EVPN;
469 else if (strmatch(safi_str, "labeled-unicast"))
470 safi = SAFI_LABELED_UNICAST;
471 else if (strmatch(safi_str, "flowspec"))
472 safi = SAFI_FLOWSPEC;
473 return safi;
474 }
475
476 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
477 safi_t *safi)
478 {
479 int ret = 0;
480 if (argv_find(argv, argc, "unicast", index)) {
481 ret = 1;
482 if (safi)
483 *safi = SAFI_UNICAST;
484 } else if (argv_find(argv, argc, "multicast", index)) {
485 ret = 1;
486 if (safi)
487 *safi = SAFI_MULTICAST;
488 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
489 ret = 1;
490 if (safi)
491 *safi = SAFI_LABELED_UNICAST;
492 } else if (argv_find(argv, argc, "vpn", index)) {
493 ret = 1;
494 if (safi)
495 *safi = SAFI_MPLS_VPN;
496 } else if (argv_find(argv, argc, "evpn", index)) {
497 ret = 1;
498 if (safi)
499 *safi = SAFI_EVPN;
500 } else if (argv_find(argv, argc, "flowspec", index)) {
501 ret = 1;
502 if (safi)
503 *safi = SAFI_FLOWSPEC;
504 }
505 return ret;
506 }
507
508 /*
509 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
510 *
511 * afi
512 * address-family identifier
513 *
514 * safi
515 * subsequent address-family identifier
516 *
517 * Returns:
518 * default_af string corresponding to the supplied afi/safi pair.
519 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
520 * return -1.
521 */
522 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
523 {
524 switch (afi) {
525 case AFI_IP:
526 switch (safi) {
527 case SAFI_UNICAST:
528 return "ipv4-unicast";
529 case SAFI_MULTICAST:
530 return "ipv4-multicast";
531 case SAFI_MPLS_VPN:
532 return "ipv4-vpn";
533 case SAFI_ENCAP:
534 return "ipv4-encap";
535 case SAFI_LABELED_UNICAST:
536 return "ipv4-labeled-unicast";
537 case SAFI_FLOWSPEC:
538 return "ipv4-flowspec";
539 default:
540 return "unknown-afi/safi";
541 }
542 break;
543 case AFI_IP6:
544 switch (safi) {
545 case SAFI_UNICAST:
546 return "ipv6-unicast";
547 case SAFI_MULTICAST:
548 return "ipv6-multicast";
549 case SAFI_MPLS_VPN:
550 return "ipv6-vpn";
551 case SAFI_ENCAP:
552 return "ipv6-encap";
553 case SAFI_LABELED_UNICAST:
554 return "ipv6-labeled-unicast";
555 case SAFI_FLOWSPEC:
556 return "ipv6-flowspec";
557 default:
558 return "unknown-afi/safi";
559 }
560 break;
561 case AFI_L2VPN:
562 switch (safi) {
563 case SAFI_EVPN:
564 return "l2vpn-evpn";
565 default:
566 return "unknown-afi/safi";
567 }
568 case AFI_UNSPEC:
569 case AFI_MAX:
570 return "unknown-afi/safi";
571 }
572 /* all AFIs are accounted for above, so this shouldn't happen */
573 return "unknown-afi/safi";
574 }
575
576 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
577 enum bgp_instance_type inst_type)
578 {
579 int ret = bgp_get(bgp, as, name, inst_type);
580
581 if (ret == BGP_CREATED) {
582 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
583 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
584
585 if (DFLT_BGP_IMPORT_CHECK)
586 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
587 if (DFLT_BGP_SHOW_HOSTNAME)
588 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
589 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
590 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
591 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
592 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
593 if (DFLT_BGP_DETERMINISTIC_MED)
594 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
595 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
596 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
597 if (DFLT_BGP_SUPPRESS_DUPLICATES)
598 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
599 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
600 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
601 if (DFLT_BGP_HARD_ADMIN_RESET)
602 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
603
604 ret = BGP_SUCCESS;
605 }
606 return ret;
607 }
608
609 /*
610 * bgp_vty_find_and_parse_afi_safi_bgp
611 *
612 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
613 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
614 * to appropriate values for the calling function. This is to allow the
615 * calling function to make decisions appropriate for the show command
616 * that is being parsed.
617 *
618 * The show commands are generally of the form:
619 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
620 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
621 *
622 * Since we use argv_find if the show command in particular doesn't have:
623 * [ip]
624 * [<view|vrf> VIEWVRFNAME]
625 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
626 * The command parsing should still be ok.
627 *
628 * vty -> The vty for the command so we can output some useful data in
629 * the event of a parse error in the vrf.
630 * argv -> The command tokens
631 * argc -> How many command tokens we have
632 * idx -> The current place in the command, generally should be 0 for this
633 * function
634 * afi -> The parsed afi if it was included in the show command, returned here
635 * safi -> The parsed safi if it was included in the show command, returned here
636 * bgp -> Pointer to the bgp data structure we need to fill in.
637 * use_json -> json is configured or not
638 *
639 * The function returns the correct location in the parse tree for the
640 * last token found.
641 *
642 * Returns 0 for failure to parse correctly, else the idx position of where
643 * it found the last token.
644 */
645 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
646 struct cmd_token **argv, int argc,
647 int *idx, afi_t *afi, safi_t *safi,
648 struct bgp **bgp, bool use_json)
649 {
650 char *vrf_name = NULL;
651
652 assert(afi);
653 assert(safi);
654 assert(bgp);
655
656 if (argv_find(argv, argc, "ip", idx))
657 *afi = AFI_IP;
658
659 if (argv_find(argv, argc, "view", idx))
660 vrf_name = argv[*idx + 1]->arg;
661 else if (argv_find(argv, argc, "vrf", idx)) {
662 vrf_name = argv[*idx + 1]->arg;
663 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
664 vrf_name = NULL;
665 }
666 if (vrf_name) {
667 if (strmatch(vrf_name, "all"))
668 *bgp = NULL;
669 else {
670 *bgp = bgp_lookup_by_name(vrf_name);
671 if (!*bgp) {
672 if (use_json) {
673 json_object *json = NULL;
674 json = json_object_new_object();
675 json_object_string_add(
676 json, "warning",
677 "View/Vrf is unknown");
678 vty_json(vty, json);
679 }
680 else
681 vty_out(vty, "View/Vrf %s is unknown\n",
682 vrf_name);
683 *idx = 0;
684 return 0;
685 }
686 }
687 } else {
688 *bgp = bgp_get_default();
689 if (!*bgp) {
690 if (use_json) {
691 json_object *json = NULL;
692 json = json_object_new_object();
693 json_object_string_add(
694 json, "warning",
695 "Default BGP instance not found");
696 vty_json(vty, json);
697 }
698 else
699 vty_out(vty,
700 "Default BGP instance not found\n");
701 *idx = 0;
702 return 0;
703 }
704 }
705
706 if (argv_find_and_parse_afi(argv, argc, idx, afi))
707 argv_find_and_parse_safi(argv, argc, idx, safi);
708
709 *idx += 1;
710 return *idx;
711 }
712
713 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
714 {
715 struct interface *ifp = NULL;
716 struct listnode *node;
717 struct bgp_listener *listener;
718 union sockunion all_su;
719
720 if (su->sa.sa_family == AF_INET) {
721 (void)str2sockunion("0.0.0.0", &all_su);
722 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
723 } else if (su->sa.sa_family == AF_INET6) {
724 (void)str2sockunion("::", &all_su);
725 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
726 su->sin6.sin6_scope_id,
727 bgp->vrf_id);
728 }
729
730 if (ifp) {
731 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
732 if (sockunion_family(su) !=
733 sockunion_family(&listener->su))
734 continue;
735
736 /* If 0.0.0.0/:: is a listener, then treat as self and
737 * reject.
738 */
739 if (!sockunion_cmp(&listener->su, su) ||
740 !sockunion_cmp(&listener->su, &all_su))
741 return true;
742 }
743 }
744
745 return false;
746 }
747
748 /* Utility function for looking up peer from VTY. */
749 /* This is used only for configuration, so disallow if attempted on
750 * a dynamic neighbor.
751 */
752 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
753 {
754 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
755 int ret;
756 union sockunion su;
757 struct peer *peer;
758
759 if (!bgp) {
760 return NULL;
761 }
762
763 ret = str2sockunion(ip_str, &su);
764 if (ret < 0) {
765 peer = peer_lookup_by_conf_if(bgp, ip_str);
766 if (!peer) {
767 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
768 == NULL) {
769 vty_out(vty,
770 "%% Malformed address or name: %s\n",
771 ip_str);
772 return NULL;
773 }
774 }
775 } else {
776 peer = peer_lookup(bgp, &su);
777 if (!peer) {
778 vty_out(vty,
779 "%% Specify remote-as or peer-group commands first\n");
780 return NULL;
781 }
782 if (peer_dynamic_neighbor(peer)) {
783 vty_out(vty,
784 "%% Operation not allowed on a dynamic neighbor\n");
785 return NULL;
786 }
787 }
788 return peer;
789 }
790
791 /* Utility function for looking up peer or peer group. */
792 /* This is used only for configuration, so disallow if attempted on
793 * a dynamic neighbor.
794 */
795 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
796 {
797 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
798 int ret;
799 union sockunion su;
800 struct peer *peer = NULL;
801 struct peer_group *group = NULL;
802
803 if (!bgp) {
804 return NULL;
805 }
806
807 ret = str2sockunion(peer_str, &su);
808 if (ret == 0) {
809 /* IP address, locate peer. */
810 peer = peer_lookup(bgp, &su);
811 } else {
812 /* Not IP, could match either peer configured on interface or a
813 * group. */
814 peer = peer_lookup_by_conf_if(bgp, peer_str);
815 if (!peer)
816 group = peer_group_lookup(bgp, peer_str);
817 }
818
819 if (peer) {
820 if (peer_dynamic_neighbor(peer)) {
821 vty_out(vty,
822 "%% Operation not allowed on a dynamic neighbor\n");
823 return NULL;
824 }
825
826 return peer;
827 }
828
829 if (group)
830 return group->conf;
831
832 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
833
834 return NULL;
835 }
836
837 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
838 {
839 const char *str = NULL;
840
841 switch (ret) {
842 case BGP_SUCCESS:
843 case BGP_CREATED:
844 case BGP_GR_NO_OPERATION:
845 break;
846 case BGP_ERR_INVALID_VALUE:
847 str = "Invalid value";
848 break;
849 case BGP_ERR_INVALID_FLAG:
850 str = "Invalid flag";
851 break;
852 case BGP_ERR_PEER_GROUP_SHUTDOWN:
853 str = "Peer-group has been shutdown. Activate the peer-group first";
854 break;
855 case BGP_ERR_PEER_FLAG_CONFLICT:
856 str = "Can't set override-capability and strict-capability-match at the same time";
857 break;
858 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
859 str = "Specify remote-as or peer-group remote AS first";
860 break;
861 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
862 str = "Cannot change the peer-group. Deconfigure first";
863 break;
864 case BGP_ERR_PEER_GROUP_MISMATCH:
865 str = "Peer is not a member of this peer-group";
866 break;
867 case BGP_ERR_PEER_FILTER_CONFLICT:
868 str = "Prefix/distribute list can not co-exist";
869 break;
870 case BGP_ERR_NOT_INTERNAL_PEER:
871 str = "Invalid command. Not an internal neighbor";
872 break;
873 case BGP_ERR_REMOVE_PRIVATE_AS:
874 str = "remove-private-AS cannot be configured for IBGP peers";
875 break;
876 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
877 str = "Cannot have local-as same as BGP AS number";
878 break;
879 case BGP_ERR_TCPSIG_FAILED:
880 str = "Error while applying TCP-Sig to session(s)";
881 break;
882 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
883 str = "ebgp-multihop and ttl-security cannot be configured together";
884 break;
885 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
886 str = "ttl-security only allowed for EBGP peers";
887 break;
888 case BGP_ERR_AS_OVERRIDE:
889 str = "as-override cannot be configured for IBGP peers";
890 break;
891 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
892 str = "Invalid limit for number of dynamic neighbors";
893 break;
894 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
895 str = "Dynamic neighbor listen range already exists";
896 break;
897 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
898 str = "Operation not allowed on a dynamic neighbor";
899 break;
900 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
901 str = "Operation not allowed on a directly connected neighbor";
902 break;
903 case BGP_ERR_PEER_SAFI_CONFLICT:
904 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
905 break;
906 case BGP_ERR_GR_INVALID_CMD:
907 str = "The Graceful Restart command used is not valid at this moment.";
908 break;
909 case BGP_ERR_GR_OPERATION_FAILED:
910 str = "The Graceful Restart Operation failed due to an err.";
911 break;
912 case BGP_ERR_PEER_GROUP_MEMBER:
913 str = "Peer-group member cannot override remote-as of peer-group.";
914 break;
915 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
916 str = "Peer-group members must be all internal or all external.";
917 break;
918 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
919 str = "Range specified cannot be deleted because it is not part of current config.";
920 break;
921 case BGP_ERR_INSTANCE_MISMATCH:
922 str = "Instance specified does not match the current instance.";
923 break;
924 case BGP_ERR_NO_INTERFACE_CONFIG:
925 str = "Interface specified is not being used for interface based peer.";
926 break;
927 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
928 str = "No configuration already specified for soft reconfiguration.";
929 break;
930 case BGP_ERR_AS_MISMATCH:
931 str = "BGP is already running.";
932 break;
933 case BGP_ERR_AF_UNCONFIGURED:
934 str = "AFI/SAFI specified is not currently configured.";
935 break;
936 case BGP_ERR_INVALID_AS:
937 str = "Confederation AS specified is the same AS as our AS.";
938 break;
939 case BGP_ERR_INVALID_ROLE_NAME:
940 str = "Invalid role name";
941 break;
942 case BGP_ERR_INVALID_INTERNAL_ROLE:
943 str = "External roles can be set only on eBGP session";
944 break;
945 }
946 if (str) {
947 vty_out(vty, "%% %s\n", str);
948 return CMD_WARNING_CONFIG_FAILED;
949 }
950 return CMD_SUCCESS;
951 }
952
953 /* BGP clear sort. */
954 enum clear_sort {
955 clear_all,
956 clear_peer,
957 clear_group,
958 clear_external,
959 clear_as
960 };
961
962 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
963 safi_t safi, int error)
964 {
965 switch (error) {
966 case BGP_ERR_AF_UNCONFIGURED:
967 if (vty)
968 vty_out(vty,
969 "%% BGP: Enable %s address family for the neighbor %s\n",
970 get_afi_safi_str(afi, safi, false), peer->host);
971 else
972 zlog_warn(
973 "%% BGP: Enable %s address family for the neighbor %s",
974 get_afi_safi_str(afi, safi, false), peer->host);
975 break;
976 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
977 if (vty)
978 vty_out(vty,
979 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
980 peer->host);
981 else
982 zlog_warn(
983 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
984 peer->host);
985 break;
986 default:
987 break;
988 }
989 }
990
991 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
992 struct listnode **nnode, enum bgp_clear_type stype)
993 {
994 int ret = 0;
995 struct peer_af *paf;
996
997 /* if afi/.safi not specified, spin thru all of them */
998 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
999 afi_t tmp_afi;
1000 safi_t tmp_safi;
1001 enum bgp_af_index index;
1002
1003 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1004 paf = peer->peer_af_array[index];
1005 if (!paf)
1006 continue;
1007
1008 if (paf && paf->subgroup)
1009 SET_FLAG(paf->subgroup->sflags,
1010 SUBGRP_STATUS_FORCE_UPDATES);
1011
1012 tmp_afi = paf->afi;
1013 tmp_safi = paf->safi;
1014 if (!peer->afc[tmp_afi][tmp_safi])
1015 continue;
1016
1017 if (stype == BGP_CLEAR_SOFT_NONE)
1018 ret = peer_clear(peer, nnode);
1019 else
1020 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1021 stype);
1022 }
1023 /* if afi specified and safi not, spin thru safis on this afi */
1024 } else if (safi == SAFI_UNSPEC) {
1025 safi_t tmp_safi;
1026
1027 for (tmp_safi = SAFI_UNICAST;
1028 tmp_safi < SAFI_MAX; tmp_safi++) {
1029 if (!peer->afc[afi][tmp_safi])
1030 continue;
1031
1032 paf = peer_af_find(peer, afi, tmp_safi);
1033 if (paf && paf->subgroup)
1034 SET_FLAG(paf->subgroup->sflags,
1035 SUBGRP_STATUS_FORCE_UPDATES);
1036
1037 if (stype == BGP_CLEAR_SOFT_NONE)
1038 ret = peer_clear(peer, nnode);
1039 else
1040 ret = peer_clear_soft(peer, afi,
1041 tmp_safi, stype);
1042 }
1043 /* both afi/safi specified, let the caller know if not defined */
1044 } else {
1045 if (!peer->afc[afi][safi])
1046 return 1;
1047
1048 paf = peer_af_find(peer, afi, safi);
1049 if (paf && paf->subgroup)
1050 SET_FLAG(paf->subgroup->sflags,
1051 SUBGRP_STATUS_FORCE_UPDATES);
1052
1053 if (stype == BGP_CLEAR_SOFT_NONE)
1054 ret = peer_clear(peer, nnode);
1055 else
1056 ret = peer_clear_soft(peer, afi, safi, stype);
1057 }
1058
1059 return ret;
1060 }
1061
1062 /* `clear ip bgp' functions. */
1063 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1064 enum clear_sort sort, enum bgp_clear_type stype,
1065 const char *arg)
1066 {
1067 int ret = 0;
1068 bool found = false;
1069 struct peer *peer;
1070
1071 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1072
1073 /* Clear all neighbors. */
1074 /*
1075 * Pass along pointer to next node to peer_clear() when walking all
1076 * nodes on the BGP instance as that may get freed if it is a
1077 * doppelganger
1078 */
1079 if (sort == clear_all) {
1080 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1081
1082 bgp_peer_gr_flags_update(peer);
1083
1084 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1085 gr_router_detected = true;
1086
1087 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1088 stype);
1089
1090 if (ret < 0)
1091 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1092 }
1093
1094 if (gr_router_detected
1095 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1096 bgp_zebra_send_capabilities(bgp, false);
1097 } else if (!gr_router_detected
1098 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1099 bgp_zebra_send_capabilities(bgp, true);
1100 }
1101
1102 /* This is to apply read-only mode on this clear. */
1103 if (stype == BGP_CLEAR_SOFT_NONE)
1104 bgp->update_delay_over = 0;
1105
1106 return CMD_SUCCESS;
1107 }
1108
1109 /* Clear specified neighbor. */
1110 if (sort == clear_peer) {
1111 union sockunion su;
1112
1113 /* Make sockunion for lookup. */
1114 ret = str2sockunion(arg, &su);
1115 if (ret < 0) {
1116 peer = peer_lookup_by_conf_if(bgp, arg);
1117 if (!peer) {
1118 peer = peer_lookup_by_hostname(bgp, arg);
1119 if (!peer) {
1120 vty_out(vty,
1121 "Malformed address or name: %s\n",
1122 arg);
1123 return CMD_WARNING;
1124 }
1125 }
1126 } else {
1127 peer = peer_lookup(bgp, &su);
1128 if (!peer) {
1129 vty_out(vty,
1130 "%% BGP: Unknown neighbor - \"%s\"\n",
1131 arg);
1132 return CMD_WARNING;
1133 }
1134 }
1135
1136 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1137 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1138
1139 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1140
1141 /* if afi/safi not defined for this peer, let caller know */
1142 if (ret == 1)
1143 ret = BGP_ERR_AF_UNCONFIGURED;
1144
1145 if (ret < 0)
1146 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1147
1148 return CMD_SUCCESS;
1149 }
1150
1151 /* Clear all neighbors belonging to a specific peer-group. */
1152 if (sort == clear_group) {
1153 struct peer_group *group;
1154
1155 group = peer_group_lookup(bgp, arg);
1156 if (!group) {
1157 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1158 return CMD_WARNING;
1159 }
1160
1161 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1162 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1163
1164 if (ret < 0)
1165 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1166 else
1167 found = true;
1168 }
1169
1170 if (!found)
1171 vty_out(vty,
1172 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1173 get_afi_safi_str(afi, safi, false), arg);
1174
1175 return CMD_SUCCESS;
1176 }
1177
1178 /* Clear all external (eBGP) neighbors. */
1179 if (sort == clear_external) {
1180 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1181 if (peer->sort == BGP_PEER_IBGP)
1182 continue;
1183
1184 bgp_peer_gr_flags_update(peer);
1185
1186 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1187 gr_router_detected = true;
1188
1189 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1190
1191 if (ret < 0)
1192 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1193 else
1194 found = true;
1195 }
1196
1197 if (gr_router_detected
1198 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1199 bgp_zebra_send_capabilities(bgp, false);
1200 } else if (!gr_router_detected
1201 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1202 bgp_zebra_send_capabilities(bgp, true);
1203 }
1204
1205 if (!found)
1206 vty_out(vty,
1207 "%% BGP: No external %s peer is configured\n",
1208 get_afi_safi_str(afi, safi, false));
1209
1210 return CMD_SUCCESS;
1211 }
1212
1213 /* Clear all neighbors belonging to a specific AS. */
1214 if (sort == clear_as) {
1215 as_t as = strtoul(arg, NULL, 10);
1216
1217 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1218 if (peer->as != as)
1219 continue;
1220
1221 bgp_peer_gr_flags_update(peer);
1222
1223 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1224 gr_router_detected = true;
1225
1226 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1227
1228 if (ret < 0)
1229 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1230 else
1231 found = true;
1232 }
1233
1234 if (gr_router_detected
1235 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1236 bgp_zebra_send_capabilities(bgp, false);
1237 } else if (!gr_router_detected
1238 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1239 bgp_zebra_send_capabilities(bgp, true);
1240 }
1241
1242 if (!found)
1243 vty_out(vty,
1244 "%% BGP: No %s peer is configured with AS %s\n",
1245 get_afi_safi_str(afi, safi, false), arg);
1246
1247 return CMD_SUCCESS;
1248 }
1249
1250 return CMD_SUCCESS;
1251 }
1252
1253 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1254 safi_t safi, enum clear_sort sort,
1255 enum bgp_clear_type stype, const char *arg)
1256 {
1257 struct bgp *bgp;
1258
1259 /* BGP structure lookup. */
1260 if (name) {
1261 bgp = bgp_lookup_by_name(name);
1262 if (bgp == NULL) {
1263 vty_out(vty, "Can't find BGP instance %s\n", name);
1264 return CMD_WARNING;
1265 }
1266 } else {
1267 bgp = bgp_get_default();
1268 if (bgp == NULL) {
1269 vty_out(vty, "No BGP process is configured\n");
1270 return CMD_WARNING;
1271 }
1272 }
1273
1274 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1275 }
1276
1277 /* clear soft inbound */
1278 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1279 {
1280 afi_t afi;
1281 safi_t safi;
1282
1283 FOREACH_AFI_SAFI (afi, safi)
1284 bgp_clear_vty(vty, name, afi, safi, clear_all,
1285 BGP_CLEAR_SOFT_IN, NULL);
1286 }
1287
1288 /* clear soft outbound */
1289 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1290 {
1291 afi_t afi;
1292 safi_t safi;
1293
1294 FOREACH_AFI_SAFI (afi, safi)
1295 bgp_clear_vty(vty, name, afi, safi, clear_all,
1296 BGP_CLEAR_SOFT_OUT, NULL);
1297 }
1298
1299
1300 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1301 {
1302 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1303 }
1304
1305 #ifndef VTYSH_EXTRACT_PL
1306 #include "bgpd/bgp_vty_clippy.c"
1307 #endif
1308
1309 DEFUN_HIDDEN (bgp_local_mac,
1310 bgp_local_mac_cmd,
1311 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1312 BGP_STR
1313 "Local MAC config\n"
1314 "VxLAN Network Identifier\n"
1315 "VNI number\n"
1316 "local mac\n"
1317 "mac address\n"
1318 "mac-mobility sequence\n"
1319 "seq number\n")
1320 {
1321 int rv;
1322 vni_t vni;
1323 struct ethaddr mac;
1324 struct ipaddr ip;
1325 uint32_t seq;
1326 struct bgp *bgp;
1327
1328 vni = strtoul(argv[3]->arg, NULL, 10);
1329 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1330 vty_out(vty, "%% Malformed MAC address\n");
1331 return CMD_WARNING;
1332 }
1333 memset(&ip, 0, sizeof(ip));
1334 seq = strtoul(argv[7]->arg, NULL, 10);
1335
1336 bgp = bgp_get_default();
1337 if (!bgp) {
1338 vty_out(vty, "Default BGP instance is not there\n");
1339 return CMD_WARNING;
1340 }
1341
1342 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1343 zero_esi);
1344 if (rv < 0) {
1345 vty_out(vty, "Internal error\n");
1346 return CMD_WARNING;
1347 }
1348
1349 return CMD_SUCCESS;
1350 }
1351
1352 DEFUN_HIDDEN (no_bgp_local_mac,
1353 no_bgp_local_mac_cmd,
1354 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1355 NO_STR
1356 BGP_STR
1357 "Local MAC config\n"
1358 "VxLAN Network Identifier\n"
1359 "VNI number\n"
1360 "local mac\n"
1361 "mac address\n")
1362 {
1363 int rv;
1364 vni_t vni;
1365 struct ethaddr mac;
1366 struct ipaddr ip;
1367 struct bgp *bgp;
1368
1369 vni = strtoul(argv[4]->arg, NULL, 10);
1370 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1371 vty_out(vty, "%% Malformed MAC address\n");
1372 return CMD_WARNING;
1373 }
1374 memset(&ip, 0, sizeof(ip));
1375
1376 bgp = bgp_get_default();
1377 if (!bgp) {
1378 vty_out(vty, "Default BGP instance is not there\n");
1379 return CMD_WARNING;
1380 }
1381
1382 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1383 if (rv < 0) {
1384 vty_out(vty, "Internal error\n");
1385 return CMD_WARNING;
1386 }
1387
1388 return CMD_SUCCESS;
1389 }
1390
1391 DEFUN (no_synchronization,
1392 no_synchronization_cmd,
1393 "no synchronization",
1394 NO_STR
1395 "Perform IGP synchronization\n")
1396 {
1397 return CMD_SUCCESS;
1398 }
1399
1400 DEFUN (no_auto_summary,
1401 no_auto_summary_cmd,
1402 "no auto-summary",
1403 NO_STR
1404 "Enable automatic network number summarization\n")
1405 {
1406 return CMD_SUCCESS;
1407 }
1408
1409 /* "router bgp" commands. */
1410 DEFUN_NOSH (router_bgp,
1411 router_bgp_cmd,
1412 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1413 ROUTER_STR
1414 BGP_STR
1415 AS_STR
1416 BGP_INSTANCE_HELP_STR)
1417 {
1418 int idx_asn = 2;
1419 int idx_view_vrf = 3;
1420 int idx_vrf = 4;
1421 int is_new_bgp = 0;
1422 int ret;
1423 as_t as;
1424 struct bgp *bgp;
1425 const char *name = NULL;
1426 enum bgp_instance_type inst_type;
1427
1428 // "router bgp" without an ASN
1429 if (argc == 2) {
1430 // Pending: Make VRF option available for ASN less config
1431 bgp = bgp_get_default();
1432
1433 if (bgp == NULL) {
1434 vty_out(vty, "%% No BGP process is configured\n");
1435 return CMD_WARNING_CONFIG_FAILED;
1436 }
1437
1438 if (listcount(bm->bgp) > 1) {
1439 vty_out(vty, "%% Please specify ASN and VRF\n");
1440 return CMD_WARNING_CONFIG_FAILED;
1441 }
1442 }
1443
1444 // "router bgp X"
1445 else {
1446 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1447
1448 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1449 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1450 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1451
1452 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1453 if (argc > 3) {
1454 name = argv[idx_vrf]->arg;
1455
1456 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1457 if (strmatch(name, VRF_DEFAULT_NAME))
1458 name = NULL;
1459 else
1460 inst_type = BGP_INSTANCE_TYPE_VRF;
1461 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1462 inst_type = BGP_INSTANCE_TYPE_VIEW;
1463 }
1464
1465 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1466 is_new_bgp = (bgp_lookup(as, name) == NULL);
1467
1468 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1469 switch (ret) {
1470 case BGP_ERR_AS_MISMATCH:
1471 vty_out(vty, "BGP is already running; AS is %u\n", as);
1472 return CMD_WARNING_CONFIG_FAILED;
1473 case BGP_ERR_INSTANCE_MISMATCH:
1474 vty_out(vty,
1475 "BGP instance name and AS number mismatch\n");
1476 vty_out(vty,
1477 "BGP instance is already running; AS is %u\n",
1478 as);
1479 return CMD_WARNING_CONFIG_FAILED;
1480 }
1481
1482 /*
1483 * If we just instantiated the default instance, complete
1484 * any pending VRF-VPN leaking that was configured via
1485 * earlier "router bgp X vrf FOO" blocks.
1486 */
1487 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1488 vpn_leak_postchange_all();
1489
1490 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1491 bgp_vpn_leak_export(bgp);
1492 /* Pending: handle when user tries to change a view to vrf n vv.
1493 */
1494 }
1495
1496 /* unset the auto created flag as the user config is now present */
1497 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1498 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1499
1500 return CMD_SUCCESS;
1501 }
1502
1503 /* "no router bgp" commands. */
1504 DEFUN (no_router_bgp,
1505 no_router_bgp_cmd,
1506 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1507 NO_STR
1508 ROUTER_STR
1509 BGP_STR
1510 AS_STR
1511 BGP_INSTANCE_HELP_STR)
1512 {
1513 int idx_asn = 3;
1514 int idx_vrf = 5;
1515 as_t as;
1516 struct bgp *bgp;
1517 const char *name = NULL;
1518
1519 // "no router bgp" without an ASN
1520 if (argc == 3) {
1521 // Pending: Make VRF option available for ASN less config
1522 bgp = bgp_get_default();
1523
1524 if (bgp == NULL) {
1525 vty_out(vty, "%% No BGP process is configured\n");
1526 return CMD_WARNING_CONFIG_FAILED;
1527 }
1528
1529 if (listcount(bm->bgp) > 1) {
1530 vty_out(vty, "%% Please specify ASN and VRF\n");
1531 return CMD_WARNING_CONFIG_FAILED;
1532 }
1533
1534 if (bgp->l3vni) {
1535 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1536 bgp->l3vni);
1537 return CMD_WARNING_CONFIG_FAILED;
1538 }
1539 } else {
1540 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1541
1542 if (argc > 4) {
1543 name = argv[idx_vrf]->arg;
1544 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1545 && strmatch(name, VRF_DEFAULT_NAME))
1546 name = NULL;
1547 }
1548
1549 /* Lookup bgp structure. */
1550 bgp = bgp_lookup(as, name);
1551 if (!bgp) {
1552 vty_out(vty, "%% Can't find BGP instance\n");
1553 return CMD_WARNING_CONFIG_FAILED;
1554 }
1555
1556 if (bgp->l3vni) {
1557 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1558 bgp->l3vni);
1559 return CMD_WARNING_CONFIG_FAILED;
1560 }
1561
1562 /* Cannot delete default instance if vrf instances exist */
1563 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1564 struct listnode *node;
1565 struct bgp *tmp_bgp;
1566
1567 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1568 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1569 continue;
1570 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1571 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1572 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1573 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1574 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1575 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1576 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1577 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1578 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1579 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1580 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1581 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1582 (bgp == bgp_get_evpn() &&
1583 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1584 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1585 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1586 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1587 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1588 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1589 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1590 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1591 (hashcount(tmp_bgp->vnihash))) {
1592 vty_out(vty,
1593 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1594 return CMD_WARNING_CONFIG_FAILED;
1595 }
1596 }
1597 }
1598 }
1599
1600 bgp_delete(bgp);
1601
1602 return CMD_SUCCESS;
1603 }
1604
1605 /* bgp session-dscp */
1606
1607 DEFPY (bgp_session_dscp,
1608 bgp_session_dscp_cmd,
1609 "bgp session-dscp (0-63)$dscp",
1610 BGP_STR
1611 "Override default (C6) bgp TCP session DSCP value\n"
1612 "Manually configured dscp parameter\n")
1613 {
1614 bm->tcp_dscp = dscp << 2;
1615
1616 return CMD_SUCCESS;
1617 }
1618
1619 DEFPY (no_bgp_session_dscp,
1620 no_bgp_session_dscp_cmd,
1621 "no bgp session-dscp [(0-63)]",
1622 NO_STR
1623 BGP_STR
1624 "Override default (C6) bgp TCP session DSCP value\n"
1625 "Manually configured dscp parameter\n")
1626 {
1627 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1628
1629 return CMD_SUCCESS;
1630 }
1631
1632 /* BGP router-id. */
1633
1634 DEFPY (bgp_router_id,
1635 bgp_router_id_cmd,
1636 "bgp router-id A.B.C.D",
1637 BGP_STR
1638 "Override configured router identifier\n"
1639 "Manually configured router identifier\n")
1640 {
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642 bgp_router_id_static_set(bgp, router_id);
1643 return CMD_SUCCESS;
1644 }
1645
1646 DEFPY (no_bgp_router_id,
1647 no_bgp_router_id_cmd,
1648 "no bgp router-id [A.B.C.D]",
1649 NO_STR
1650 BGP_STR
1651 "Override configured router identifier\n"
1652 "Manually configured router identifier\n")
1653 {
1654 VTY_DECLVAR_CONTEXT(bgp, bgp);
1655
1656 if (router_id_str) {
1657 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1658 vty_out(vty, "%% BGP router-id doesn't match\n");
1659 return CMD_WARNING_CONFIG_FAILED;
1660 }
1661 }
1662
1663 router_id.s_addr = 0;
1664 bgp_router_id_static_set(bgp, router_id);
1665
1666 return CMD_SUCCESS;
1667 }
1668
1669 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1670 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1671 NO_STR BGP_STR
1672 "Add community specific parameters\n"
1673 "Create an alias for a community\n"
1674 "Community (AA:BB or AA:BB:CC)\n"
1675 "Alias name\n")
1676 {
1677 struct community_alias ca = {};
1678 struct community_alias *lookup_community;
1679 struct community_alias *lookup_alias;
1680 struct community *comm;
1681 struct lcommunity *lcomm;
1682 uint8_t invalid = 0;
1683
1684 comm = community_str2com(community);
1685 if (!comm)
1686 invalid++;
1687 community_free(&comm);
1688
1689 lcomm = lcommunity_str2com(community);
1690 if (!lcomm)
1691 invalid++;
1692 lcommunity_free(&lcomm);
1693
1694 if (invalid > 1) {
1695 vty_out(vty, "Invalid community format\n");
1696 return CMD_WARNING;
1697 }
1698
1699 strlcpy(ca.community, community, sizeof(ca.community));
1700 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1701
1702 lookup_community = bgp_ca_community_lookup(&ca);
1703 lookup_alias = bgp_ca_alias_lookup(&ca);
1704
1705 if (no) {
1706 bgp_ca_alias_delete(&ca);
1707 bgp_ca_community_delete(&ca);
1708 } else {
1709 if (lookup_alias) {
1710 /* Lookup if community hash table has an item
1711 * with the same alias name.
1712 */
1713 strlcpy(ca.community, lookup_alias->community,
1714 sizeof(ca.community));
1715 if (bgp_ca_community_lookup(&ca)) {
1716 vty_out(vty,
1717 "community (%s) already has this alias (%s)\n",
1718 lookup_alias->community,
1719 lookup_alias->alias);
1720 return CMD_WARNING;
1721 }
1722 bgp_ca_alias_delete(&ca);
1723 }
1724
1725 if (lookup_community) {
1726 /* Lookup if alias hash table has an item
1727 * with the same community.
1728 */
1729 strlcpy(ca.alias, lookup_community->alias,
1730 sizeof(ca.alias));
1731 if (bgp_ca_alias_lookup(&ca)) {
1732 vty_out(vty,
1733 "alias (%s) already has this community (%s)\n",
1734 lookup_community->alias,
1735 lookup_community->community);
1736 return CMD_WARNING;
1737 }
1738 bgp_ca_community_delete(&ca);
1739 }
1740
1741 bgp_ca_alias_insert(&ca);
1742 bgp_ca_community_insert(&ca);
1743 }
1744
1745 return CMD_SUCCESS;
1746 }
1747
1748 DEFPY (bgp_global_suppress_fib_pending,
1749 bgp_global_suppress_fib_pending_cmd,
1750 "[no] bgp suppress-fib-pending",
1751 NO_STR
1752 BGP_STR
1753 "Advertise only routes that are programmed in kernel to peers globally\n")
1754 {
1755 bm_wait_for_fib_set(!no);
1756
1757 return CMD_SUCCESS;
1758 }
1759
1760 DEFPY (bgp_suppress_fib_pending,
1761 bgp_suppress_fib_pending_cmd,
1762 "[no] bgp suppress-fib-pending",
1763 NO_STR
1764 BGP_STR
1765 "Advertise only routes that are programmed in kernel to peers\n")
1766 {
1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768
1769 bgp_suppress_fib_pending_set(bgp, !no);
1770 return CMD_SUCCESS;
1771 }
1772
1773
1774 /* BGP Cluster ID. */
1775 DEFUN (bgp_cluster_id,
1776 bgp_cluster_id_cmd,
1777 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1778 BGP_STR
1779 "Configure Route-Reflector Cluster-id\n"
1780 "Route-Reflector Cluster-id in IP address format\n"
1781 "Route-Reflector Cluster-id as 32 bit quantity\n")
1782 {
1783 VTY_DECLVAR_CONTEXT(bgp, bgp);
1784 int idx_ipv4 = 2;
1785 int ret;
1786 struct in_addr cluster;
1787
1788 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1789 if (!ret) {
1790 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1791 return CMD_WARNING_CONFIG_FAILED;
1792 }
1793
1794 bgp_cluster_id_set(bgp, &cluster);
1795 bgp_clear_star_soft_out(vty, bgp->name);
1796
1797 return CMD_SUCCESS;
1798 }
1799
1800 DEFUN (no_bgp_cluster_id,
1801 no_bgp_cluster_id_cmd,
1802 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1803 NO_STR
1804 BGP_STR
1805 "Configure Route-Reflector Cluster-id\n"
1806 "Route-Reflector Cluster-id in IP address format\n"
1807 "Route-Reflector Cluster-id as 32 bit quantity\n")
1808 {
1809 VTY_DECLVAR_CONTEXT(bgp, bgp);
1810 bgp_cluster_id_unset(bgp);
1811 bgp_clear_star_soft_out(vty, bgp->name);
1812
1813 return CMD_SUCCESS;
1814 }
1815
1816 DEFPY (bgp_norib,
1817 bgp_norib_cmd,
1818 "bgp no-rib",
1819 BGP_STR
1820 "Disable BGP route installation to RIB (Zebra)\n")
1821 {
1822 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1823 vty_out(vty,
1824 "%% No-RIB option is already set, nothing to do here.\n");
1825 return CMD_SUCCESS;
1826 }
1827
1828 bgp_option_norib_set_runtime();
1829
1830 return CMD_SUCCESS;
1831 }
1832
1833 DEFPY (no_bgp_norib,
1834 no_bgp_norib_cmd,
1835 "no bgp no-rib",
1836 NO_STR
1837 BGP_STR
1838 "Disable BGP route installation to RIB (Zebra)\n")
1839 {
1840 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1841 vty_out(vty,
1842 "%% No-RIB option is not set, nothing to do here.\n");
1843 return CMD_SUCCESS;
1844 }
1845
1846 bgp_option_norib_unset_runtime();
1847
1848 return CMD_SUCCESS;
1849 }
1850
1851 DEFPY (no_bgp_send_extra_data,
1852 no_bgp_send_extra_data_cmd,
1853 "[no] bgp send-extra-data zebra",
1854 NO_STR
1855 BGP_STR
1856 "Extra data to Zebra for display/use\n"
1857 "To zebra\n")
1858 {
1859 if (no)
1860 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1861 else
1862 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1863
1864 return CMD_SUCCESS;
1865 }
1866
1867 DEFUN (bgp_confederation_identifier,
1868 bgp_confederation_identifier_cmd,
1869 "bgp confederation identifier (1-4294967295)",
1870 BGP_STR
1871 "AS confederation parameters\n"
1872 "AS number\n"
1873 "Set routing domain confederation AS\n")
1874 {
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876 int idx_number = 3;
1877 as_t as;
1878
1879 as = strtoul(argv[idx_number]->arg, NULL, 10);
1880
1881 bgp_confederation_id_set(bgp, as);
1882
1883 return CMD_SUCCESS;
1884 }
1885
1886 DEFUN (no_bgp_confederation_identifier,
1887 no_bgp_confederation_identifier_cmd,
1888 "no bgp confederation identifier [(1-4294967295)]",
1889 NO_STR
1890 BGP_STR
1891 "AS confederation parameters\n"
1892 "AS number\n"
1893 "Set routing domain confederation AS\n")
1894 {
1895 VTY_DECLVAR_CONTEXT(bgp, bgp);
1896 bgp_confederation_id_unset(bgp);
1897
1898 return CMD_SUCCESS;
1899 }
1900
1901 DEFUN (bgp_confederation_peers,
1902 bgp_confederation_peers_cmd,
1903 "bgp confederation peers (1-4294967295)...",
1904 BGP_STR
1905 "AS confederation parameters\n"
1906 "Peer ASs in BGP confederation\n"
1907 AS_STR)
1908 {
1909 VTY_DECLVAR_CONTEXT(bgp, bgp);
1910 int idx_asn = 3;
1911 as_t as;
1912 int i;
1913
1914 for (i = idx_asn; i < argc; i++) {
1915 as = strtoul(argv[i]->arg, NULL, 10);
1916
1917 if (bgp->as == as) {
1918 vty_out(vty,
1919 "%% Local member-AS not allowed in confed peer list\n");
1920 continue;
1921 }
1922
1923 bgp_confederation_peers_add(bgp, as);
1924 }
1925 return CMD_SUCCESS;
1926 }
1927
1928 DEFUN (no_bgp_confederation_peers,
1929 no_bgp_confederation_peers_cmd,
1930 "no bgp confederation peers (1-4294967295)...",
1931 NO_STR
1932 BGP_STR
1933 "AS confederation parameters\n"
1934 "Peer ASs in BGP confederation\n"
1935 AS_STR)
1936 {
1937 VTY_DECLVAR_CONTEXT(bgp, bgp);
1938 int idx_asn = 4;
1939 as_t as;
1940 int i;
1941
1942 for (i = idx_asn; i < argc; i++) {
1943 as = strtoul(argv[i]->arg, NULL, 10);
1944
1945 bgp_confederation_peers_remove(bgp, as);
1946 }
1947 return CMD_SUCCESS;
1948 }
1949
1950 /**
1951 * Central routine for maximum-paths configuration.
1952 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1953 * @set: 1 for setting values, 0 for removing the max-paths config.
1954 */
1955 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1956 const char *mpaths, uint16_t options,
1957 int set)
1958 {
1959 VTY_DECLVAR_CONTEXT(bgp, bgp);
1960 uint16_t maxpaths = 0;
1961 int ret;
1962 afi_t afi;
1963 safi_t safi;
1964
1965 afi = bgp_node_afi(vty);
1966 safi = bgp_node_safi(vty);
1967
1968 if (set) {
1969 maxpaths = strtol(mpaths, NULL, 10);
1970 if (maxpaths > multipath_num) {
1971 vty_out(vty,
1972 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1973 maxpaths, multipath_num);
1974 return CMD_WARNING_CONFIG_FAILED;
1975 }
1976 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1977 options);
1978 } else
1979 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1980
1981 if (ret < 0) {
1982 vty_out(vty,
1983 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1984 (set == 1) ? "" : "un",
1985 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1986 maxpaths, afi, safi);
1987 return CMD_WARNING_CONFIG_FAILED;
1988 }
1989
1990 bgp_recalculate_all_bestpaths(bgp);
1991
1992 return CMD_SUCCESS;
1993 }
1994
1995 DEFUN (bgp_maxmed_admin,
1996 bgp_maxmed_admin_cmd,
1997 "bgp max-med administrative ",
1998 BGP_STR
1999 "Advertise routes with max-med\n"
2000 "Administratively applied, for an indefinite period\n")
2001 {
2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003
2004 bgp->v_maxmed_admin = 1;
2005 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2006
2007 bgp_maxmed_update(bgp);
2008
2009 return CMD_SUCCESS;
2010 }
2011
2012 DEFUN (bgp_maxmed_admin_medv,
2013 bgp_maxmed_admin_medv_cmd,
2014 "bgp max-med administrative (0-4294967295)",
2015 BGP_STR
2016 "Advertise routes with max-med\n"
2017 "Administratively applied, for an indefinite period\n"
2018 "Max MED value to be used\n")
2019 {
2020 VTY_DECLVAR_CONTEXT(bgp, bgp);
2021 int idx_number = 3;
2022
2023 bgp->v_maxmed_admin = 1;
2024 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2025
2026 bgp_maxmed_update(bgp);
2027
2028 return CMD_SUCCESS;
2029 }
2030
2031 DEFUN (no_bgp_maxmed_admin,
2032 no_bgp_maxmed_admin_cmd,
2033 "no bgp max-med administrative [(0-4294967295)]",
2034 NO_STR
2035 BGP_STR
2036 "Advertise routes with max-med\n"
2037 "Administratively applied, for an indefinite period\n"
2038 "Max MED value to be used\n")
2039 {
2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2042 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2043 bgp_maxmed_update(bgp);
2044
2045 return CMD_SUCCESS;
2046 }
2047
2048 DEFUN (bgp_maxmed_onstartup,
2049 bgp_maxmed_onstartup_cmd,
2050 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2051 BGP_STR
2052 "Advertise routes with max-med\n"
2053 "Effective on a startup\n"
2054 "Time (seconds) period for max-med\n"
2055 "Max MED value to be used\n")
2056 {
2057 VTY_DECLVAR_CONTEXT(bgp, bgp);
2058 int idx = 0;
2059
2060 if (argv_find(argv, argc, "(5-86400)", &idx))
2061 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2062 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2063 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2064 else
2065 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2066
2067 bgp_maxmed_update(bgp);
2068
2069 return CMD_SUCCESS;
2070 }
2071
2072 DEFUN (no_bgp_maxmed_onstartup,
2073 no_bgp_maxmed_onstartup_cmd,
2074 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2075 NO_STR
2076 BGP_STR
2077 "Advertise routes with max-med\n"
2078 "Effective on a startup\n"
2079 "Time (seconds) period for max-med\n"
2080 "Max MED value to be used\n")
2081 {
2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083
2084 /* Cancel max-med onstartup if its on */
2085 if (bgp->t_maxmed_onstartup) {
2086 THREAD_OFF(bgp->t_maxmed_onstartup);
2087 bgp->maxmed_onstartup_over = 1;
2088 }
2089
2090 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2091 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2092
2093 bgp_maxmed_update(bgp);
2094
2095 return CMD_SUCCESS;
2096 }
2097
2098 static int bgp_global_update_delay_config_vty(struct vty *vty,
2099 uint16_t update_delay,
2100 uint16_t establish_wait)
2101 {
2102 struct listnode *node, *nnode;
2103 struct bgp *bgp;
2104 bool vrf_cfg = false;
2105
2106 /*
2107 * See if update-delay is set per-vrf and warn user to delete it
2108 * Note that we only need to check this if this is the first time
2109 * setting the global config.
2110 */
2111 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2112 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2113 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2114 vty_out(vty,
2115 "%% update-delay configuration found in vrf %s\n",
2116 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2117 ? VRF_DEFAULT_NAME
2118 : bgp->name);
2119 vrf_cfg = true;
2120 }
2121 }
2122 }
2123
2124 if (vrf_cfg) {
2125 vty_out(vty,
2126 "%%Failed: global update-delay config not permitted\n");
2127 return CMD_WARNING;
2128 }
2129
2130 if (!establish_wait) { /* update-delay <delay> */
2131 bm->v_update_delay = update_delay;
2132 bm->v_establish_wait = bm->v_update_delay;
2133 } else {
2134 /* update-delay <delay> <establish-wait> */
2135 if (update_delay < establish_wait) {
2136 vty_out(vty,
2137 "%%Failed: update-delay less than the establish-wait!\n");
2138 return CMD_WARNING_CONFIG_FAILED;
2139 }
2140
2141 bm->v_update_delay = update_delay;
2142 bm->v_establish_wait = establish_wait;
2143 }
2144
2145 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2146 bgp->v_update_delay = bm->v_update_delay;
2147 bgp->v_establish_wait = bm->v_establish_wait;
2148 }
2149
2150 return CMD_SUCCESS;
2151 }
2152
2153 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2154 {
2155 struct listnode *node, *nnode;
2156 struct bgp *bgp;
2157
2158 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2159 bm->v_establish_wait = bm->v_update_delay;
2160
2161 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2162 bgp->v_update_delay = bm->v_update_delay;
2163 bgp->v_establish_wait = bm->v_establish_wait;
2164 }
2165
2166 return CMD_SUCCESS;
2167 }
2168
2169 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2170 uint16_t establish_wait)
2171 {
2172 VTY_DECLVAR_CONTEXT(bgp, bgp);
2173
2174 /* if configured globally, per-instance config is not allowed */
2175 if (bm->v_update_delay) {
2176 vty_out(vty,
2177 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2178 return CMD_WARNING_CONFIG_FAILED;
2179 }
2180
2181
2182 if (!establish_wait) /* update-delay <delay> */
2183 {
2184 bgp->v_update_delay = update_delay;
2185 bgp->v_establish_wait = bgp->v_update_delay;
2186 return CMD_SUCCESS;
2187 }
2188
2189 /* update-delay <delay> <establish-wait> */
2190 if (update_delay < establish_wait) {
2191 vty_out(vty,
2192 "%%Failed: update-delay less than the establish-wait!\n");
2193 return CMD_WARNING_CONFIG_FAILED;
2194 }
2195
2196 bgp->v_update_delay = update_delay;
2197 bgp->v_establish_wait = establish_wait;
2198
2199 return CMD_SUCCESS;
2200 }
2201
2202 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2203 {
2204 VTY_DECLVAR_CONTEXT(bgp, bgp);
2205
2206 /* If configured globally, cannot remove from one bgp instance */
2207 if (bm->v_update_delay) {
2208 vty_out(vty,
2209 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2210 return CMD_WARNING_CONFIG_FAILED;
2211 }
2212 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2213 bgp->v_establish_wait = bgp->v_update_delay;
2214
2215 return CMD_SUCCESS;
2216 }
2217
2218 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2219 {
2220 /* If configured globally, no need to display per-instance value */
2221 if (bgp->v_update_delay != bm->v_update_delay) {
2222 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2223 if (bgp->v_update_delay != bgp->v_establish_wait)
2224 vty_out(vty, " %d", bgp->v_establish_wait);
2225 vty_out(vty, "\n");
2226 }
2227 }
2228
2229 /* Global update-delay configuration */
2230 DEFPY (bgp_global_update_delay,
2231 bgp_global_update_delay_cmd,
2232 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2233 BGP_STR
2234 "Force initial delay for best-path and updates for all bgp instances\n"
2235 "Max delay in seconds\n"
2236 "Establish wait in seconds\n")
2237 {
2238 return bgp_global_update_delay_config_vty(vty, delay, wait);
2239 }
2240
2241 /* Global update-delay deconfiguration */
2242 DEFPY (no_bgp_global_update_delay,
2243 no_bgp_global_update_delay_cmd,
2244 "no bgp update-delay [(0-3600) [(1-3600)]]",
2245 NO_STR
2246 BGP_STR
2247 "Force initial delay for best-path and updates\n"
2248 "Max delay in seconds\n"
2249 "Establish wait in seconds\n")
2250 {
2251 return bgp_global_update_delay_deconfig_vty(vty);
2252 }
2253
2254 /* Update-delay configuration */
2255
2256 DEFPY (bgp_update_delay,
2257 bgp_update_delay_cmd,
2258 "update-delay (0-3600)$delay [(1-3600)$wait]",
2259 "Force initial delay for best-path and updates\n"
2260 "Max delay in seconds\n"
2261 "Establish wait in seconds\n")
2262 {
2263 return bgp_update_delay_config_vty(vty, delay, wait);
2264 }
2265
2266 /* Update-delay deconfiguration */
2267 DEFPY (no_bgp_update_delay,
2268 no_bgp_update_delay_cmd,
2269 "no update-delay [(0-3600) [(1-3600)]]",
2270 NO_STR
2271 "Force initial delay for best-path and updates\n"
2272 "Max delay in seconds\n"
2273 "Establish wait in seconds\n")
2274 {
2275 return bgp_update_delay_deconfig_vty(vty);
2276 }
2277
2278
2279 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2280 bool set)
2281 {
2282 VTY_DECLVAR_CONTEXT(bgp, bgp);
2283
2284 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2285 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2286
2287 return CMD_SUCCESS;
2288 }
2289
2290 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2291 bool set)
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294
2295 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2296 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2297
2298 return CMD_SUCCESS;
2299 }
2300
2301 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2302 {
2303 uint32_t quanta =
2304 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2305 if (quanta != BGP_WRITE_PACKET_MAX)
2306 vty_out(vty, " write-quanta %d\n", quanta);
2307 }
2308
2309 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2310 {
2311 uint32_t quanta =
2312 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2313 if (quanta != BGP_READ_PACKET_MAX)
2314 vty_out(vty, " read-quanta %d\n", quanta);
2315 }
2316
2317 /* Packet quanta configuration
2318 *
2319 * XXX: The value set here controls the size of a stack buffer in the IO
2320 * thread. When changing these limits be careful to prevent stack overflow.
2321 *
2322 * Furthermore, the maximums used here should correspond to
2323 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2324 */
2325 DEFPY (bgp_wpkt_quanta,
2326 bgp_wpkt_quanta_cmd,
2327 "[no] write-quanta (1-64)$quanta",
2328 NO_STR
2329 "How many packets to write to peer socket per run\n"
2330 "Number of packets\n")
2331 {
2332 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2333 }
2334
2335 DEFPY (bgp_rpkt_quanta,
2336 bgp_rpkt_quanta_cmd,
2337 "[no] read-quanta (1-10)$quanta",
2338 NO_STR
2339 "How many packets to read from peer socket per I/O cycle\n"
2340 "Number of packets\n")
2341 {
2342 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2343 }
2344
2345 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2346 {
2347 if (!bgp->heuristic_coalesce)
2348 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2349 }
2350
2351 /* BGP TCP keepalive */
2352 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2353 {
2354 if (bgp->tcp_keepalive_idle) {
2355 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2356 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2357 bgp->tcp_keepalive_probes);
2358 }
2359 }
2360
2361 DEFUN (bgp_coalesce_time,
2362 bgp_coalesce_time_cmd,
2363 "coalesce-time (0-4294967295)",
2364 "Subgroup coalesce timer\n"
2365 "Subgroup coalesce timer value (in ms)\n")
2366 {
2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
2368
2369 int idx = 0;
2370
2371 bgp->heuristic_coalesce = false;
2372
2373 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2374 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2375
2376 return CMD_SUCCESS;
2377 }
2378
2379 DEFUN (no_bgp_coalesce_time,
2380 no_bgp_coalesce_time_cmd,
2381 "no coalesce-time (0-4294967295)",
2382 NO_STR
2383 "Subgroup coalesce timer\n"
2384 "Subgroup coalesce timer value (in ms)\n")
2385 {
2386 VTY_DECLVAR_CONTEXT(bgp, bgp);
2387
2388 bgp->heuristic_coalesce = true;
2389 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2390 return CMD_SUCCESS;
2391 }
2392
2393 /* Maximum-paths configuration */
2394 DEFUN (bgp_maxpaths,
2395 bgp_maxpaths_cmd,
2396 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2397 "Forward packets over multiple paths\n"
2398 "Number of paths\n")
2399 {
2400 int idx_number = 1;
2401 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2402 argv[idx_number]->arg, 0, 1);
2403 }
2404
2405 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2406 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2407 "Forward packets over multiple paths\n"
2408 "Number of paths\n")
2409
2410 DEFUN (bgp_maxpaths_ibgp,
2411 bgp_maxpaths_ibgp_cmd,
2412 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2413 "Forward packets over multiple paths\n"
2414 "iBGP-multipath\n"
2415 "Number of paths\n")
2416 {
2417 int idx_number = 2;
2418 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2419 argv[idx_number]->arg, 0, 1);
2420 }
2421
2422 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2423 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2424 "Forward packets over multiple paths\n"
2425 "iBGP-multipath\n"
2426 "Number of paths\n")
2427
2428 DEFUN (bgp_maxpaths_ibgp_cluster,
2429 bgp_maxpaths_ibgp_cluster_cmd,
2430 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2431 "Forward packets over multiple paths\n"
2432 "iBGP-multipath\n"
2433 "Number of paths\n"
2434 "Match the cluster length\n")
2435 {
2436 int idx_number = 2;
2437 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2438 argv[idx_number]->arg, true, 1);
2439 }
2440
2441 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2442 "maximum-paths ibgp " CMD_RANGE_STR(
2443 1, MULTIPATH_NUM) " equal-cluster-length",
2444 "Forward packets over multiple paths\n"
2445 "iBGP-multipath\n"
2446 "Number of paths\n"
2447 "Match the cluster length\n")
2448
2449 DEFUN (no_bgp_maxpaths,
2450 no_bgp_maxpaths_cmd,
2451 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2452 NO_STR
2453 "Forward packets over multiple paths\n"
2454 "Number of paths\n")
2455 {
2456 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2457 }
2458
2459 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2460 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2461 "Forward packets over multiple paths\n"
2462 "Number of paths\n")
2463
2464 DEFUN (no_bgp_maxpaths_ibgp,
2465 no_bgp_maxpaths_ibgp_cmd,
2466 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2467 NO_STR
2468 "Forward packets over multiple paths\n"
2469 "iBGP-multipath\n"
2470 "Number of paths\n"
2471 "Match the cluster length\n")
2472 {
2473 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2474 }
2475
2476 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2477 "no maximum-paths ibgp [" CMD_RANGE_STR(
2478 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2479 NO_STR
2480 "Forward packets over multiple paths\n"
2481 "iBGP-multipath\n"
2482 "Number of paths\n"
2483 "Match the cluster length\n")
2484
2485 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2486 afi_t afi, safi_t safi)
2487 {
2488 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2489 vty_out(vty, " maximum-paths %d\n",
2490 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2491 }
2492
2493 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2494 vty_out(vty, " maximum-paths ibgp %d",
2495 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2496 if (bgp->maxpaths[afi][safi].same_clusterlen)
2497 vty_out(vty, " equal-cluster-length");
2498 vty_out(vty, "\n");
2499 }
2500 }
2501
2502 /* BGP timers. */
2503
2504 DEFUN (bgp_timers,
2505 bgp_timers_cmd,
2506 "timers bgp (0-65535) (0-65535)",
2507 "Adjust routing timers\n"
2508 "BGP timers\n"
2509 "Keepalive interval\n"
2510 "Holdtime\n")
2511 {
2512 VTY_DECLVAR_CONTEXT(bgp, bgp);
2513 int idx_number = 2;
2514 int idx_number_2 = 3;
2515 unsigned long keepalive = 0;
2516 unsigned long holdtime = 0;
2517
2518 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2519 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2520
2521 /* Holdtime value check. */
2522 if (holdtime < 3 && holdtime != 0) {
2523 vty_out(vty,
2524 "%% hold time value must be either 0 or greater than 3\n");
2525 return CMD_WARNING_CONFIG_FAILED;
2526 }
2527
2528 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2529 BGP_DEFAULT_DELAYOPEN);
2530
2531 return CMD_SUCCESS;
2532 }
2533
2534 DEFUN (no_bgp_timers,
2535 no_bgp_timers_cmd,
2536 "no timers bgp [(0-65535) (0-65535)]",
2537 NO_STR
2538 "Adjust routing timers\n"
2539 "BGP timers\n"
2540 "Keepalive interval\n"
2541 "Holdtime\n")
2542 {
2543 VTY_DECLVAR_CONTEXT(bgp, bgp);
2544 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2545 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2546
2547 return CMD_SUCCESS;
2548 }
2549
2550 /* BGP minimum holdtime. */
2551
2552 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2553 "bgp minimum-holdtime (1-65535)",
2554 "BGP specific commands\n"
2555 "BGP minimum holdtime\n"
2556 "Seconds\n")
2557 {
2558 VTY_DECLVAR_CONTEXT(bgp, bgp);
2559 int idx_number = 2;
2560 unsigned long min_holdtime;
2561
2562 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2563
2564 bgp->default_min_holdtime = min_holdtime;
2565
2566 return CMD_SUCCESS;
2567 }
2568
2569 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2570 "no bgp minimum-holdtime [(1-65535)]",
2571 NO_STR
2572 "BGP specific commands\n"
2573 "BGP minimum holdtime\n"
2574 "Seconds\n")
2575 {
2576 VTY_DECLVAR_CONTEXT(bgp, bgp);
2577
2578 bgp->default_min_holdtime = 0;
2579
2580 return CMD_SUCCESS;
2581 }
2582
2583 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2584 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2585 BGP_STR
2586 "TCP keepalive parameters\n"
2587 "TCP keepalive idle time (seconds)\n"
2588 "TCP keepalive interval (seconds)\n"
2589 "TCP keepalive maximum probes\n")
2590 {
2591 VTY_DECLVAR_CONTEXT(bgp, bgp);
2592
2593 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2594 (uint16_t)probes);
2595
2596 return CMD_SUCCESS;
2597 }
2598
2599 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2600 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2601 NO_STR
2602 BGP_STR
2603 "TCP keepalive parameters\n"
2604 "TCP keepalive idle time (seconds)\n"
2605 "TCP keepalive interval (seconds)\n"
2606 "TCP keepalive maximum probes\n")
2607 {
2608 VTY_DECLVAR_CONTEXT(bgp, bgp);
2609
2610 bgp_tcp_keepalive_unset(bgp);
2611
2612 return CMD_SUCCESS;
2613 }
2614
2615 DEFUN (bgp_client_to_client_reflection,
2616 bgp_client_to_client_reflection_cmd,
2617 "bgp client-to-client reflection",
2618 BGP_STR
2619 "Configure client to client route reflection\n"
2620 "reflection of routes allowed\n")
2621 {
2622 VTY_DECLVAR_CONTEXT(bgp, bgp);
2623 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2624 bgp_clear_star_soft_out(vty, bgp->name);
2625
2626 return CMD_SUCCESS;
2627 }
2628
2629 DEFUN (no_bgp_client_to_client_reflection,
2630 no_bgp_client_to_client_reflection_cmd,
2631 "no bgp client-to-client reflection",
2632 NO_STR
2633 BGP_STR
2634 "Configure client to client route reflection\n"
2635 "reflection of routes allowed\n")
2636 {
2637 VTY_DECLVAR_CONTEXT(bgp, bgp);
2638 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2639 bgp_clear_star_soft_out(vty, bgp->name);
2640
2641 return CMD_SUCCESS;
2642 }
2643
2644 /* "bgp always-compare-med" configuration. */
2645 DEFUN (bgp_always_compare_med,
2646 bgp_always_compare_med_cmd,
2647 "bgp always-compare-med",
2648 BGP_STR
2649 "Allow comparing MED from different neighbors\n")
2650 {
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2653 bgp_recalculate_all_bestpaths(bgp);
2654
2655 return CMD_SUCCESS;
2656 }
2657
2658 DEFUN (no_bgp_always_compare_med,
2659 no_bgp_always_compare_med_cmd,
2660 "no bgp always-compare-med",
2661 NO_STR
2662 BGP_STR
2663 "Allow comparing MED from different neighbors\n")
2664 {
2665 VTY_DECLVAR_CONTEXT(bgp, bgp);
2666 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2667 bgp_recalculate_all_bestpaths(bgp);
2668
2669 return CMD_SUCCESS;
2670 }
2671
2672
2673 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2674 "bgp ebgp-requires-policy",
2675 BGP_STR
2676 "Require in and out policy for eBGP peers (RFC8212)\n")
2677 {
2678 VTY_DECLVAR_CONTEXT(bgp, bgp);
2679 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2680 return CMD_SUCCESS;
2681 }
2682
2683 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2684 "no bgp ebgp-requires-policy",
2685 NO_STR
2686 BGP_STR
2687 "Require in and out policy for eBGP peers (RFC8212)\n")
2688 {
2689 VTY_DECLVAR_CONTEXT(bgp, bgp);
2690 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2691 return CMD_SUCCESS;
2692 }
2693
2694 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2695 "bgp suppress-duplicates",
2696 BGP_STR
2697 "Suppress duplicate updates if the route actually not changed\n")
2698 {
2699 VTY_DECLVAR_CONTEXT(bgp, bgp);
2700 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2701 return CMD_SUCCESS;
2702 }
2703
2704 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2705 "no bgp suppress-duplicates",
2706 NO_STR
2707 BGP_STR
2708 "Suppress duplicate updates if the route actually not changed\n")
2709 {
2710 VTY_DECLVAR_CONTEXT(bgp, bgp);
2711 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2712 return CMD_SUCCESS;
2713 }
2714
2715 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2716 "bgp reject-as-sets",
2717 BGP_STR
2718 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2719 {
2720 VTY_DECLVAR_CONTEXT(bgp, bgp);
2721 struct listnode *node, *nnode;
2722 struct peer *peer;
2723
2724 bgp->reject_as_sets = true;
2725
2726 /* Reset existing BGP sessions to reject routes
2727 * with aspath containing AS_SET or AS_CONFED_SET.
2728 */
2729 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2730 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2731 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2732 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2733 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2734 }
2735 }
2736
2737 return CMD_SUCCESS;
2738 }
2739
2740 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2741 "no bgp reject-as-sets",
2742 NO_STR
2743 BGP_STR
2744 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2745 {
2746 VTY_DECLVAR_CONTEXT(bgp, bgp);
2747 struct listnode *node, *nnode;
2748 struct peer *peer;
2749
2750 bgp->reject_as_sets = false;
2751
2752 /* Reset existing BGP sessions to reject routes
2753 * with aspath containing AS_SET or AS_CONFED_SET.
2754 */
2755 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2756 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2757 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2758 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2759 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2760 }
2761 }
2762
2763 return CMD_SUCCESS;
2764 }
2765
2766 /* "bgp deterministic-med" configuration. */
2767 DEFUN (bgp_deterministic_med,
2768 bgp_deterministic_med_cmd,
2769 "bgp deterministic-med",
2770 BGP_STR
2771 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2772 {
2773 VTY_DECLVAR_CONTEXT(bgp, bgp);
2774
2775 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2776 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2777 bgp_recalculate_all_bestpaths(bgp);
2778 }
2779
2780 return CMD_SUCCESS;
2781 }
2782
2783 DEFUN (no_bgp_deterministic_med,
2784 no_bgp_deterministic_med_cmd,
2785 "no bgp deterministic-med",
2786 NO_STR
2787 BGP_STR
2788 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2789 {
2790 VTY_DECLVAR_CONTEXT(bgp, bgp);
2791 int bestpath_per_as_used;
2792 afi_t afi;
2793 safi_t safi;
2794 struct peer *peer;
2795 struct listnode *node, *nnode;
2796
2797 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2798 bestpath_per_as_used = 0;
2799
2800 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2801 FOREACH_AFI_SAFI (afi, safi)
2802 if (bgp_addpath_dmed_required(
2803 peer->addpath_type[afi][safi])) {
2804 bestpath_per_as_used = 1;
2805 break;
2806 }
2807
2808 if (bestpath_per_as_used)
2809 break;
2810 }
2811
2812 if (bestpath_per_as_used) {
2813 vty_out(vty,
2814 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2815 return CMD_WARNING_CONFIG_FAILED;
2816 } else {
2817 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2818 bgp_recalculate_all_bestpaths(bgp);
2819 }
2820 }
2821
2822 return CMD_SUCCESS;
2823 }
2824
2825 /* "bgp graceful-restart mode" configuration. */
2826 DEFUN (bgp_graceful_restart,
2827 bgp_graceful_restart_cmd,
2828 "bgp graceful-restart",
2829 BGP_STR
2830 GR_CMD
2831 )
2832 {
2833 int ret = BGP_GR_FAILURE;
2834
2835 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2836 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2837
2838 VTY_DECLVAR_CONTEXT(bgp, bgp);
2839
2840 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2841
2842 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2843 ret);
2844
2845 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2846 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2847 vty_out(vty,
2848 "Graceful restart configuration changed, reset all peers to take effect\n");
2849 return bgp_vty_return(vty, ret);
2850 }
2851
2852 DEFUN (no_bgp_graceful_restart,
2853 no_bgp_graceful_restart_cmd,
2854 "no bgp graceful-restart",
2855 NO_STR
2856 BGP_STR
2857 NO_GR_CMD
2858 )
2859 {
2860 VTY_DECLVAR_CONTEXT(bgp, bgp);
2861
2862 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2863 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2864
2865 int ret = BGP_GR_FAILURE;
2866
2867 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2868
2869 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2870 ret);
2871
2872 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2873 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2874 vty_out(vty,
2875 "Graceful restart configuration changed, reset all peers to take effect\n");
2876
2877 return bgp_vty_return(vty, ret);
2878 }
2879
2880 DEFUN (bgp_graceful_restart_stalepath_time,
2881 bgp_graceful_restart_stalepath_time_cmd,
2882 "bgp graceful-restart stalepath-time (1-4095)",
2883 BGP_STR
2884 "Graceful restart capability parameters\n"
2885 "Set the max time to hold onto restarting peer's stale paths\n"
2886 "Delay value (seconds)\n")
2887 {
2888 VTY_DECLVAR_CONTEXT(bgp, bgp);
2889 int idx_number = 3;
2890 uint32_t stalepath;
2891
2892 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2893 bgp->stalepath_time = stalepath;
2894 return CMD_SUCCESS;
2895 }
2896
2897 DEFUN (bgp_graceful_restart_restart_time,
2898 bgp_graceful_restart_restart_time_cmd,
2899 "bgp graceful-restart restart-time (0-4095)",
2900 BGP_STR
2901 "Graceful restart capability parameters\n"
2902 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2903 "Delay value (seconds)\n")
2904 {
2905 VTY_DECLVAR_CONTEXT(bgp, bgp);
2906 int idx_number = 3;
2907 uint32_t restart;
2908
2909 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2910 bgp->restart_time = restart;
2911 return CMD_SUCCESS;
2912 }
2913
2914 DEFUN (bgp_graceful_restart_select_defer_time,
2915 bgp_graceful_restart_select_defer_time_cmd,
2916 "bgp graceful-restart select-defer-time (0-3600)",
2917 BGP_STR
2918 "Graceful restart capability parameters\n"
2919 "Set the time to defer the BGP route selection after restart\n"
2920 "Delay value (seconds, 0 - disable)\n")
2921 {
2922 VTY_DECLVAR_CONTEXT(bgp, bgp);
2923 int idx_number = 3;
2924 uint32_t defer_time;
2925
2926 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2927 bgp->select_defer_time = defer_time;
2928 if (defer_time == 0)
2929 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2930 else
2931 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2932
2933 return CMD_SUCCESS;
2934 }
2935
2936 DEFUN (no_bgp_graceful_restart_stalepath_time,
2937 no_bgp_graceful_restart_stalepath_time_cmd,
2938 "no bgp graceful-restart stalepath-time [(1-4095)]",
2939 NO_STR
2940 BGP_STR
2941 "Graceful restart capability parameters\n"
2942 "Set the max time to hold onto restarting peer's stale paths\n"
2943 "Delay value (seconds)\n")
2944 {
2945 VTY_DECLVAR_CONTEXT(bgp, bgp);
2946
2947 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2948 return CMD_SUCCESS;
2949 }
2950
2951 DEFUN (no_bgp_graceful_restart_restart_time,
2952 no_bgp_graceful_restart_restart_time_cmd,
2953 "no bgp graceful-restart restart-time [(0-4095)]",
2954 NO_STR
2955 BGP_STR
2956 "Graceful restart capability parameters\n"
2957 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2958 "Delay value (seconds)\n")
2959 {
2960 VTY_DECLVAR_CONTEXT(bgp, bgp);
2961
2962 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2963 return CMD_SUCCESS;
2964 }
2965
2966 DEFUN (no_bgp_graceful_restart_select_defer_time,
2967 no_bgp_graceful_restart_select_defer_time_cmd,
2968 "no bgp graceful-restart select-defer-time [(0-3600)]",
2969 NO_STR
2970 BGP_STR
2971 "Graceful restart capability parameters\n"
2972 "Set the time to defer the BGP route selection after restart\n"
2973 "Delay value (seconds)\n")
2974 {
2975 VTY_DECLVAR_CONTEXT(bgp, bgp);
2976
2977 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2978 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2979
2980 return CMD_SUCCESS;
2981 }
2982
2983 DEFUN (bgp_graceful_restart_preserve_fw,
2984 bgp_graceful_restart_preserve_fw_cmd,
2985 "bgp graceful-restart preserve-fw-state",
2986 BGP_STR
2987 "Graceful restart capability parameters\n"
2988 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2989 {
2990 VTY_DECLVAR_CONTEXT(bgp, bgp);
2991 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2992 return CMD_SUCCESS;
2993 }
2994
2995 DEFUN (no_bgp_graceful_restart_preserve_fw,
2996 no_bgp_graceful_restart_preserve_fw_cmd,
2997 "no bgp graceful-restart preserve-fw-state",
2998 NO_STR
2999 BGP_STR
3000 "Graceful restart capability parameters\n"
3001 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3002 {
3003 VTY_DECLVAR_CONTEXT(bgp, bgp);
3004 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3005 return CMD_SUCCESS;
3006 }
3007
3008 DEFPY (bgp_graceful_restart_notification,
3009 bgp_graceful_restart_notification_cmd,
3010 "[no$no] bgp graceful-restart notification",
3011 NO_STR
3012 BGP_STR
3013 "Graceful restart capability parameters\n"
3014 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3015 {
3016 VTY_DECLVAR_CONTEXT(bgp, bgp);
3017
3018 if (no)
3019 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3020 else
3021 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3022
3023 return CMD_SUCCESS;
3024 }
3025
3026 DEFPY (bgp_administrative_reset,
3027 bgp_administrative_reset_cmd,
3028 "[no$no] bgp hard-administrative-reset",
3029 NO_STR
3030 BGP_STR
3031 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3032 {
3033 VTY_DECLVAR_CONTEXT(bgp, bgp);
3034
3035 if (no)
3036 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3037 else
3038 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3039
3040 return CMD_SUCCESS;
3041 }
3042
3043 DEFUN (bgp_graceful_restart_disable,
3044 bgp_graceful_restart_disable_cmd,
3045 "bgp graceful-restart-disable",
3046 BGP_STR
3047 GR_DISABLE)
3048 {
3049 int ret = BGP_GR_FAILURE;
3050
3051 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3052 zlog_debug(
3053 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3054
3055 VTY_DECLVAR_CONTEXT(bgp, bgp);
3056
3057 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3058
3059 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3060 bgp->peer, ret);
3061
3062 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3063 zlog_debug(
3064 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3065 vty_out(vty,
3066 "Graceful restart configuration changed, reset all peers to take effect\n");
3067
3068 return bgp_vty_return(vty, ret);
3069 }
3070
3071 DEFUN (no_bgp_graceful_restart_disable,
3072 no_bgp_graceful_restart_disable_cmd,
3073 "no bgp graceful-restart-disable",
3074 NO_STR
3075 BGP_STR
3076 NO_GR_DISABLE
3077 )
3078 {
3079 VTY_DECLVAR_CONTEXT(bgp, bgp);
3080
3081 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3082 zlog_debug(
3083 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3084
3085 int ret = BGP_GR_FAILURE;
3086
3087 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3088
3089 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3090 ret);
3091
3092 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3093 zlog_debug(
3094 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3095 vty_out(vty,
3096 "Graceful restart configuration changed, reset all peers to take effect\n");
3097
3098 return bgp_vty_return(vty, ret);
3099 }
3100
3101 DEFUN (bgp_neighbor_graceful_restart_set,
3102 bgp_neighbor_graceful_restart_set_cmd,
3103 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3104 NEIGHBOR_STR
3105 NEIGHBOR_ADDR_STR2
3106 GR_NEIGHBOR_CMD
3107 )
3108 {
3109 int idx_peer = 1;
3110 struct peer *peer;
3111 int ret = BGP_GR_FAILURE;
3112
3113 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3114
3115 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3116 zlog_debug(
3117 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3118
3119 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3120 if (!peer)
3121 return CMD_WARNING_CONFIG_FAILED;
3122
3123 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3124
3125 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3126 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3127
3128 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3129 zlog_debug(
3130 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3131 vty_out(vty,
3132 "Graceful restart configuration changed, reset this peer to take effect\n");
3133
3134 return bgp_vty_return(vty, ret);
3135 }
3136
3137 DEFUN (no_bgp_neighbor_graceful_restart,
3138 no_bgp_neighbor_graceful_restart_set_cmd,
3139 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3140 NO_STR
3141 NEIGHBOR_STR
3142 NEIGHBOR_ADDR_STR2
3143 NO_GR_NEIGHBOR_CMD
3144 )
3145 {
3146 int idx_peer = 2;
3147 int ret = BGP_GR_FAILURE;
3148 struct peer *peer;
3149
3150 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3151
3152 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3153 if (!peer)
3154 return CMD_WARNING_CONFIG_FAILED;
3155
3156 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3157 zlog_debug(
3158 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3159
3160 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3161
3162 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3163 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3164
3165 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3166 zlog_debug(
3167 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3168 vty_out(vty,
3169 "Graceful restart configuration changed, reset this peer to take effect\n");
3170
3171 return bgp_vty_return(vty, ret);
3172 }
3173
3174 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3175 bgp_neighbor_graceful_restart_helper_set_cmd,
3176 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3177 NEIGHBOR_STR
3178 NEIGHBOR_ADDR_STR2
3179 GR_NEIGHBOR_HELPER_CMD
3180 )
3181 {
3182 int idx_peer = 1;
3183 struct peer *peer;
3184 int ret = BGP_GR_FAILURE;
3185
3186 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3187
3188 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3189 zlog_debug(
3190 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3191
3192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3193
3194 if (!peer)
3195 return CMD_WARNING_CONFIG_FAILED;
3196
3197
3198 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3199
3200 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3201 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3202
3203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3204 zlog_debug(
3205 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3206 vty_out(vty,
3207 "Graceful restart configuration changed, reset this peer to take effect\n");
3208
3209 return bgp_vty_return(vty, ret);
3210 }
3211
3212 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3213 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3214 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3215 NO_STR
3216 NEIGHBOR_STR
3217 NEIGHBOR_ADDR_STR2
3218 NO_GR_NEIGHBOR_HELPER_CMD
3219 )
3220 {
3221 int idx_peer = 2;
3222 int ret = BGP_GR_FAILURE;
3223 struct peer *peer;
3224
3225 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3226
3227 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3228 if (!peer)
3229 return CMD_WARNING_CONFIG_FAILED;
3230
3231 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3232 zlog_debug(
3233 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3234
3235 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3236
3237 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3238 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3239
3240 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3241 zlog_debug(
3242 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3243 vty_out(vty,
3244 "Graceful restart configuration changed, reset this peer to take effect\n");
3245
3246 return bgp_vty_return(vty, ret);
3247 }
3248
3249 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3250 bgp_neighbor_graceful_restart_disable_set_cmd,
3251 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3252 NEIGHBOR_STR
3253 NEIGHBOR_ADDR_STR2
3254 GR_NEIGHBOR_DISABLE_CMD
3255 )
3256 {
3257 int idx_peer = 1;
3258 struct peer *peer;
3259 int ret = BGP_GR_FAILURE;
3260
3261 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3262
3263 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3264 zlog_debug(
3265 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3266
3267 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3268 if (!peer)
3269 return CMD_WARNING_CONFIG_FAILED;
3270
3271 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3272
3273 if (peer->bgp->t_startup)
3274 bgp_peer_gr_flags_update(peer);
3275
3276 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3277 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3278
3279 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3280 zlog_debug(
3281 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3282 vty_out(vty,
3283 "Graceful restart configuration changed, reset this peer to take effect\n");
3284
3285 return bgp_vty_return(vty, ret);
3286 }
3287
3288 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3289 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3290 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3291 NO_STR
3292 NEIGHBOR_STR
3293 NEIGHBOR_ADDR_STR2
3294 NO_GR_NEIGHBOR_DISABLE_CMD
3295 )
3296 {
3297 int idx_peer = 2;
3298 int ret = BGP_GR_FAILURE;
3299 struct peer *peer;
3300
3301 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3302
3303 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3304 if (!peer)
3305 return CMD_WARNING_CONFIG_FAILED;
3306
3307 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3308 zlog_debug(
3309 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3310
3311 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3312
3313 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3314 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3315
3316 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3317 zlog_debug(
3318 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3319 vty_out(vty,
3320 "Graceful restart configuration changed, reset this peer to take effect\n");
3321
3322 return bgp_vty_return(vty, ret);
3323 }
3324
3325 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3326 bgp_graceful_restart_disable_eor_cmd,
3327 "bgp graceful-restart disable-eor",
3328 BGP_STR
3329 "Graceful restart configuration parameters\n"
3330 "Disable EOR Check\n")
3331 {
3332 VTY_DECLVAR_CONTEXT(bgp, bgp);
3333 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3334
3335 return CMD_SUCCESS;
3336 }
3337
3338 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3339 no_bgp_graceful_restart_disable_eor_cmd,
3340 "no bgp graceful-restart disable-eor",
3341 NO_STR
3342 BGP_STR
3343 "Graceful restart configuration parameters\n"
3344 "Disable EOR Check\n")
3345 {
3346 VTY_DECLVAR_CONTEXT(bgp, bgp);
3347 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3348
3349 return CMD_SUCCESS;
3350 }
3351
3352 DEFUN (bgp_graceful_restart_rib_stale_time,
3353 bgp_graceful_restart_rib_stale_time_cmd,
3354 "bgp graceful-restart rib-stale-time (1-3600)",
3355 BGP_STR
3356 "Graceful restart configuration parameters\n"
3357 "Specify the stale route removal timer in rib\n"
3358 "Delay value (seconds)\n")
3359 {
3360 VTY_DECLVAR_CONTEXT(bgp, bgp);
3361 int idx_number = 3;
3362 uint32_t stale_time;
3363
3364 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3365 bgp->rib_stale_time = stale_time;
3366 /* Send the stale timer update message to RIB */
3367 if (bgp_zebra_stale_timer_update(bgp))
3368 return CMD_WARNING;
3369
3370 return CMD_SUCCESS;
3371 }
3372
3373 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3374 no_bgp_graceful_restart_rib_stale_time_cmd,
3375 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3376 NO_STR
3377 BGP_STR
3378 "Graceful restart configuration parameters\n"
3379 "Specify the stale route removal timer in rib\n"
3380 "Delay value (seconds)\n")
3381 {
3382 VTY_DECLVAR_CONTEXT(bgp, bgp);
3383
3384 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3385 /* Send the stale timer update message to RIB */
3386 if (bgp_zebra_stale_timer_update(bgp))
3387 return CMD_WARNING;
3388
3389 return CMD_SUCCESS;
3390 }
3391
3392 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3393 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3394 BGP_STR
3395 "Enable Long-lived Graceful Restart\n"
3396 "Specifies maximum time to wait before purging long-lived stale routes\n"
3397 "Stale time value (seconds)\n")
3398 {
3399 VTY_DECLVAR_CONTEXT(bgp, bgp);
3400
3401 uint32_t llgr_stale_time;
3402
3403 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3404 bgp->llgr_stale_time = llgr_stale_time;
3405
3406 return CMD_SUCCESS;
3407 }
3408
3409 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3410 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3411 NO_STR BGP_STR
3412 "Enable Long-lived Graceful Restart\n"
3413 "Specifies maximum time to wait before purging long-lived stale routes\n"
3414 "Stale time value (seconds)\n")
3415 {
3416 VTY_DECLVAR_CONTEXT(bgp, bgp);
3417
3418 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3419
3420 return CMD_SUCCESS;
3421 }
3422
3423 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3424 struct bgp *bgp)
3425 {
3426 bgp_static_redo_import_check(bgp);
3427 bgp_redistribute_redo(bgp);
3428 bgp_clear_star_soft_out(vty, bgp->name);
3429 bgp_clear_star_soft_in(vty, bgp->name);
3430 }
3431
3432 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3433 {
3434 struct listnode *node, *nnode;
3435 struct bgp *bgp;
3436 bool vrf_cfg = false;
3437
3438 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3439 return CMD_SUCCESS;
3440
3441 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3442 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3443 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3444 vty_out(vty,
3445 "%% graceful-shutdown configuration found in vrf %s\n",
3446 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3447 VRF_DEFAULT_NAME : bgp->name);
3448 vrf_cfg = true;
3449 }
3450 }
3451
3452 if (vrf_cfg) {
3453 vty_out(vty,
3454 "%%Failed: global graceful-shutdown not permitted\n");
3455 return CMD_WARNING;
3456 }
3457
3458 /* Set flag globally */
3459 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3460
3461 /* Initiate processing for all BGP instances. */
3462 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3463 bgp_initiate_graceful_shut_unshut(vty, bgp);
3464
3465 return CMD_SUCCESS;
3466 }
3467
3468 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3469 {
3470 struct listnode *node, *nnode;
3471 struct bgp *bgp;
3472
3473 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3474 return CMD_SUCCESS;
3475
3476 /* Unset flag globally */
3477 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3478
3479 /* Initiate processing for all BGP instances. */
3480 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3481 bgp_initiate_graceful_shut_unshut(vty, bgp);
3482
3483 return CMD_SUCCESS;
3484 }
3485
3486 /* "bgp graceful-shutdown" configuration */
3487 DEFUN (bgp_graceful_shutdown,
3488 bgp_graceful_shutdown_cmd,
3489 "bgp graceful-shutdown",
3490 BGP_STR
3491 "Graceful shutdown parameters\n")
3492 {
3493 if (vty->node == CONFIG_NODE)
3494 return bgp_global_graceful_shutdown_config_vty(vty);
3495
3496 VTY_DECLVAR_CONTEXT(bgp, bgp);
3497
3498 /* if configured globally, per-instance config is not allowed */
3499 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3500 vty_out(vty,
3501 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3502 return CMD_WARNING_CONFIG_FAILED;
3503 }
3504
3505 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3506 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3507 bgp_initiate_graceful_shut_unshut(vty, bgp);
3508 }
3509
3510 return CMD_SUCCESS;
3511 }
3512
3513 DEFUN (no_bgp_graceful_shutdown,
3514 no_bgp_graceful_shutdown_cmd,
3515 "no bgp graceful-shutdown",
3516 NO_STR
3517 BGP_STR
3518 "Graceful shutdown parameters\n")
3519 {
3520 if (vty->node == CONFIG_NODE)
3521 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3522
3523 VTY_DECLVAR_CONTEXT(bgp, bgp);
3524
3525 /* If configured globally, cannot remove from one bgp instance */
3526 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3527 vty_out(vty,
3528 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3529 return CMD_WARNING_CONFIG_FAILED;
3530 }
3531
3532 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3533 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3534 bgp_initiate_graceful_shut_unshut(vty, bgp);
3535 }
3536
3537 return CMD_SUCCESS;
3538 }
3539
3540 /* "bgp fast-external-failover" configuration. */
3541 DEFUN (bgp_fast_external_failover,
3542 bgp_fast_external_failover_cmd,
3543 "bgp fast-external-failover",
3544 BGP_STR
3545 "Immediately reset session if a link to a directly connected external peer goes down\n")
3546 {
3547 VTY_DECLVAR_CONTEXT(bgp, bgp);
3548 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3549 return CMD_SUCCESS;
3550 }
3551
3552 DEFUN (no_bgp_fast_external_failover,
3553 no_bgp_fast_external_failover_cmd,
3554 "no bgp fast-external-failover",
3555 NO_STR
3556 BGP_STR
3557 "Immediately reset session if a link to a directly connected external peer goes down\n")
3558 {
3559 VTY_DECLVAR_CONTEXT(bgp, bgp);
3560 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3561 return CMD_SUCCESS;
3562 }
3563
3564 /* "bgp bestpath compare-routerid" configuration. */
3565 DEFUN (bgp_bestpath_compare_router_id,
3566 bgp_bestpath_compare_router_id_cmd,
3567 "bgp bestpath compare-routerid",
3568 BGP_STR
3569 "Change the default bestpath selection\n"
3570 "Compare router-id for identical EBGP paths\n")
3571 {
3572 VTY_DECLVAR_CONTEXT(bgp, bgp);
3573 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3574 bgp_recalculate_all_bestpaths(bgp);
3575
3576 return CMD_SUCCESS;
3577 }
3578
3579 DEFUN (no_bgp_bestpath_compare_router_id,
3580 no_bgp_bestpath_compare_router_id_cmd,
3581 "no bgp bestpath compare-routerid",
3582 NO_STR
3583 BGP_STR
3584 "Change the default bestpath selection\n"
3585 "Compare router-id for identical EBGP paths\n")
3586 {
3587 VTY_DECLVAR_CONTEXT(bgp, bgp);
3588 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3589 bgp_recalculate_all_bestpaths(bgp);
3590
3591 return CMD_SUCCESS;
3592 }
3593
3594 /* "bgp bestpath as-path ignore" configuration. */
3595 DEFUN (bgp_bestpath_aspath_ignore,
3596 bgp_bestpath_aspath_ignore_cmd,
3597 "bgp bestpath as-path ignore",
3598 BGP_STR
3599 "Change the default bestpath selection\n"
3600 "AS-path attribute\n"
3601 "Ignore as-path length in selecting a route\n")
3602 {
3603 VTY_DECLVAR_CONTEXT(bgp, bgp);
3604 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3605 bgp_recalculate_all_bestpaths(bgp);
3606
3607 return CMD_SUCCESS;
3608 }
3609
3610 DEFUN (no_bgp_bestpath_aspath_ignore,
3611 no_bgp_bestpath_aspath_ignore_cmd,
3612 "no bgp bestpath as-path ignore",
3613 NO_STR
3614 BGP_STR
3615 "Change the default bestpath selection\n"
3616 "AS-path attribute\n"
3617 "Ignore as-path length in selecting a route\n")
3618 {
3619 VTY_DECLVAR_CONTEXT(bgp, bgp);
3620 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3621 bgp_recalculate_all_bestpaths(bgp);
3622
3623 return CMD_SUCCESS;
3624 }
3625
3626 /* "bgp bestpath as-path confed" configuration. */
3627 DEFUN (bgp_bestpath_aspath_confed,
3628 bgp_bestpath_aspath_confed_cmd,
3629 "bgp bestpath as-path confed",
3630 BGP_STR
3631 "Change the default bestpath selection\n"
3632 "AS-path attribute\n"
3633 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3634 {
3635 VTY_DECLVAR_CONTEXT(bgp, bgp);
3636 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3637 bgp_recalculate_all_bestpaths(bgp);
3638
3639 return CMD_SUCCESS;
3640 }
3641
3642 DEFUN (no_bgp_bestpath_aspath_confed,
3643 no_bgp_bestpath_aspath_confed_cmd,
3644 "no bgp bestpath as-path confed",
3645 NO_STR
3646 BGP_STR
3647 "Change the default bestpath selection\n"
3648 "AS-path attribute\n"
3649 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3650 {
3651 VTY_DECLVAR_CONTEXT(bgp, bgp);
3652 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3653 bgp_recalculate_all_bestpaths(bgp);
3654
3655 return CMD_SUCCESS;
3656 }
3657
3658 /* "bgp bestpath as-path multipath-relax" configuration. */
3659 DEFUN (bgp_bestpath_aspath_multipath_relax,
3660 bgp_bestpath_aspath_multipath_relax_cmd,
3661 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3662 BGP_STR
3663 "Change the default bestpath selection\n"
3664 "AS-path attribute\n"
3665 "Allow load sharing across routes that have different AS paths (but same length)\n"
3666 "Generate an AS_SET\n"
3667 "Do not generate an AS_SET\n")
3668 {
3669 VTY_DECLVAR_CONTEXT(bgp, bgp);
3670 int idx = 0;
3671 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3672
3673 /* no-as-set is now the default behavior so we can silently
3674 * ignore it */
3675 if (argv_find(argv, argc, "as-set", &idx))
3676 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3677 else
3678 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3679
3680 bgp_recalculate_all_bestpaths(bgp);
3681
3682 return CMD_SUCCESS;
3683 }
3684
3685 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3686 no_bgp_bestpath_aspath_multipath_relax_cmd,
3687 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3688 NO_STR
3689 BGP_STR
3690 "Change the default bestpath selection\n"
3691 "AS-path attribute\n"
3692 "Allow load sharing across routes that have different AS paths (but same length)\n"
3693 "Generate an AS_SET\n"
3694 "Do not generate an AS_SET\n")
3695 {
3696 VTY_DECLVAR_CONTEXT(bgp, bgp);
3697 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3698 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3699 bgp_recalculate_all_bestpaths(bgp);
3700
3701 return CMD_SUCCESS;
3702 }
3703
3704 /* "bgp bestpath peer-type multipath-relax" configuration. */
3705 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3706 bgp_bestpath_peer_type_multipath_relax_cmd,
3707 "bgp bestpath peer-type multipath-relax",
3708 BGP_STR
3709 "Change the default bestpath selection\n"
3710 "Peer type\n"
3711 "Allow load sharing across routes learned from different peer types\n")
3712 {
3713 VTY_DECLVAR_CONTEXT(bgp, bgp);
3714 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3715 bgp_recalculate_all_bestpaths(bgp);
3716
3717 return CMD_SUCCESS;
3718 }
3719
3720 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3721 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3722 "no bgp bestpath peer-type multipath-relax",
3723 NO_STR BGP_STR
3724 "Change the default bestpath selection\n"
3725 "Peer type\n"
3726 "Allow load sharing across routes learned from different peer types\n")
3727 {
3728 VTY_DECLVAR_CONTEXT(bgp, bgp);
3729 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3730 bgp_recalculate_all_bestpaths(bgp);
3731
3732 return CMD_SUCCESS;
3733 }
3734
3735 /* "bgp log-neighbor-changes" configuration. */
3736 DEFUN (bgp_log_neighbor_changes,
3737 bgp_log_neighbor_changes_cmd,
3738 "bgp log-neighbor-changes",
3739 BGP_STR
3740 "Log neighbor up/down and reset reason\n")
3741 {
3742 VTY_DECLVAR_CONTEXT(bgp, bgp);
3743 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3744 return CMD_SUCCESS;
3745 }
3746
3747 DEFUN (no_bgp_log_neighbor_changes,
3748 no_bgp_log_neighbor_changes_cmd,
3749 "no bgp log-neighbor-changes",
3750 NO_STR
3751 BGP_STR
3752 "Log neighbor up/down and reset reason\n")
3753 {
3754 VTY_DECLVAR_CONTEXT(bgp, bgp);
3755 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3756 return CMD_SUCCESS;
3757 }
3758
3759 /* "bgp bestpath med" configuration. */
3760 DEFUN (bgp_bestpath_med,
3761 bgp_bestpath_med_cmd,
3762 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3763 BGP_STR
3764 "Change the default bestpath selection\n"
3765 "MED attribute\n"
3766 "Compare MED among confederation paths\n"
3767 "Treat missing MED as the least preferred one\n"
3768 "Treat missing MED as the least preferred one\n"
3769 "Compare MED among confederation paths\n")
3770 {
3771 VTY_DECLVAR_CONTEXT(bgp, bgp);
3772
3773 int idx = 0;
3774 if (argv_find(argv, argc, "confed", &idx))
3775 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3776 idx = 0;
3777 if (argv_find(argv, argc, "missing-as-worst", &idx))
3778 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3779
3780 bgp_recalculate_all_bestpaths(bgp);
3781
3782 return CMD_SUCCESS;
3783 }
3784
3785 DEFUN (no_bgp_bestpath_med,
3786 no_bgp_bestpath_med_cmd,
3787 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3788 NO_STR
3789 BGP_STR
3790 "Change the default bestpath selection\n"
3791 "MED attribute\n"
3792 "Compare MED among confederation paths\n"
3793 "Treat missing MED as the least preferred one\n"
3794 "Treat missing MED as the least preferred one\n"
3795 "Compare MED among confederation paths\n")
3796 {
3797 VTY_DECLVAR_CONTEXT(bgp, bgp);
3798
3799 int idx = 0;
3800 if (argv_find(argv, argc, "confed", &idx))
3801 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3802 idx = 0;
3803 if (argv_find(argv, argc, "missing-as-worst", &idx))
3804 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3805
3806 bgp_recalculate_all_bestpaths(bgp);
3807
3808 return CMD_SUCCESS;
3809 }
3810
3811 /* "bgp bestpath bandwidth" configuration. */
3812 DEFPY (bgp_bestpath_bw,
3813 bgp_bestpath_bw_cmd,
3814 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3815 BGP_STR
3816 "Change the default bestpath selection\n"
3817 "Link Bandwidth attribute\n"
3818 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3819 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3820 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3821 {
3822 VTY_DECLVAR_CONTEXT(bgp, bgp);
3823 afi_t afi;
3824 safi_t safi;
3825
3826 if (!bw_cfg) {
3827 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3828 return CMD_ERR_INCOMPLETE;
3829 }
3830 if (!strcmp(bw_cfg, "ignore"))
3831 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3832 else if (!strcmp(bw_cfg, "skip-missing"))
3833 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3834 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3835 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3836 else
3837 return CMD_ERR_NO_MATCH;
3838
3839 /* This config is used in route install, so redo that. */
3840 FOREACH_AFI_SAFI (afi, safi) {
3841 if (!bgp_fibupd_safi(safi))
3842 continue;
3843 bgp_zebra_announce_table(bgp, afi, safi);
3844 }
3845
3846 return CMD_SUCCESS;
3847 }
3848
3849 DEFPY (no_bgp_bestpath_bw,
3850 no_bgp_bestpath_bw_cmd,
3851 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3852 NO_STR
3853 BGP_STR
3854 "Change the default bestpath selection\n"
3855 "Link Bandwidth attribute\n"
3856 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3857 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3858 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3859 {
3860 VTY_DECLVAR_CONTEXT(bgp, bgp);
3861 afi_t afi;
3862 safi_t safi;
3863
3864 bgp->lb_handling = BGP_LINK_BW_ECMP;
3865
3866 /* This config is used in route install, so redo that. */
3867 FOREACH_AFI_SAFI (afi, safi) {
3868 if (!bgp_fibupd_safi(safi))
3869 continue;
3870 bgp_zebra_announce_table(bgp, afi, safi);
3871 }
3872 return CMD_SUCCESS;
3873 }
3874
3875 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3876 "[no] bgp default <ipv4-unicast|"
3877 "ipv4-multicast|"
3878 "ipv4-vpn|"
3879 "ipv4-labeled-unicast|"
3880 "ipv4-flowspec|"
3881 "ipv6-unicast|"
3882 "ipv6-multicast|"
3883 "ipv6-vpn|"
3884 "ipv6-labeled-unicast|"
3885 "ipv6-flowspec|"
3886 "l2vpn-evpn>$afi_safi",
3887 NO_STR
3888 BGP_STR
3889 "Configure BGP defaults\n"
3890 "Activate ipv4-unicast for a peer by default\n"
3891 "Activate ipv4-multicast for a peer by default\n"
3892 "Activate ipv4-vpn for a peer by default\n"
3893 "Activate ipv4-labeled-unicast for a peer by default\n"
3894 "Activate ipv4-flowspec for a peer by default\n"
3895 "Activate ipv6-unicast for a peer by default\n"
3896 "Activate ipv6-multicast for a peer by default\n"
3897 "Activate ipv6-vpn for a peer by default\n"
3898 "Activate ipv6-labeled-unicast for a peer by default\n"
3899 "Activate ipv6-flowspec for a peer by default\n"
3900 "Activate l2vpn-evpn for a peer by default\n")
3901 {
3902 VTY_DECLVAR_CONTEXT(bgp, bgp);
3903 char afi_safi_str[strlen(afi_safi) + 1];
3904 char *afi_safi_str_tok;
3905
3906 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3907 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3908 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3909 afi_t afi = bgp_vty_afi_from_str(afi_str);
3910 safi_t safi;
3911
3912 /*
3913 * Impossible situation but making coverity happy
3914 */
3915 assert(afi != AFI_MAX);
3916
3917 if (strmatch(safi_str, "labeled"))
3918 safi = bgp_vty_safi_from_str("labeled-unicast");
3919 else
3920 safi = bgp_vty_safi_from_str(safi_str);
3921
3922 assert(safi != SAFI_MAX);
3923 if (no)
3924 bgp->default_af[afi][safi] = false;
3925 else {
3926 if ((safi == SAFI_LABELED_UNICAST
3927 && bgp->default_af[afi][SAFI_UNICAST])
3928 || (safi == SAFI_UNICAST
3929 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3930 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3931 else
3932 bgp->default_af[afi][safi] = true;
3933 }
3934
3935 return CMD_SUCCESS;
3936 }
3937
3938 /* Display hostname in certain command outputs */
3939 DEFUN (bgp_default_show_hostname,
3940 bgp_default_show_hostname_cmd,
3941 "bgp default show-hostname",
3942 BGP_STR
3943 "Configure BGP defaults\n"
3944 "Show hostname in certain command outputs\n")
3945 {
3946 VTY_DECLVAR_CONTEXT(bgp, bgp);
3947 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3948 return CMD_SUCCESS;
3949 }
3950
3951 DEFUN (no_bgp_default_show_hostname,
3952 no_bgp_default_show_hostname_cmd,
3953 "no bgp default show-hostname",
3954 NO_STR
3955 BGP_STR
3956 "Configure BGP defaults\n"
3957 "Show hostname in certain command outputs\n")
3958 {
3959 VTY_DECLVAR_CONTEXT(bgp, bgp);
3960 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3961 return CMD_SUCCESS;
3962 }
3963
3964 /* Display hostname in certain command outputs */
3965 DEFUN (bgp_default_show_nexthop_hostname,
3966 bgp_default_show_nexthop_hostname_cmd,
3967 "bgp default show-nexthop-hostname",
3968 BGP_STR
3969 "Configure BGP defaults\n"
3970 "Show hostname for nexthop in certain command outputs\n")
3971 {
3972 VTY_DECLVAR_CONTEXT(bgp, bgp);
3973 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3974 return CMD_SUCCESS;
3975 }
3976
3977 DEFUN (no_bgp_default_show_nexthop_hostname,
3978 no_bgp_default_show_nexthop_hostname_cmd,
3979 "no bgp default show-nexthop-hostname",
3980 NO_STR
3981 BGP_STR
3982 "Configure BGP defaults\n"
3983 "Show hostname for nexthop in certain command outputs\n")
3984 {
3985 VTY_DECLVAR_CONTEXT(bgp, bgp);
3986 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3987 return CMD_SUCCESS;
3988 }
3989
3990 /* "bgp network import-check" configuration. */
3991 DEFUN (bgp_network_import_check,
3992 bgp_network_import_check_cmd,
3993 "bgp network import-check",
3994 BGP_STR
3995 "BGP network command\n"
3996 "Check BGP network route exists in IGP\n")
3997 {
3998 VTY_DECLVAR_CONTEXT(bgp, bgp);
3999 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4000 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4001 bgp_static_redo_import_check(bgp);
4002 }
4003
4004 return CMD_SUCCESS;
4005 }
4006
4007 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4008 "bgp network import-check exact",
4009 BGP_STR
4010 "BGP network command\n"
4011 "Check BGP network route exists in IGP\n"
4012 "Match route precisely\n")
4013
4014 DEFUN (no_bgp_network_import_check,
4015 no_bgp_network_import_check_cmd,
4016 "no bgp network import-check",
4017 NO_STR
4018 BGP_STR
4019 "BGP network command\n"
4020 "Check BGP network route exists in IGP\n")
4021 {
4022 VTY_DECLVAR_CONTEXT(bgp, bgp);
4023 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4024 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4025 bgp_static_redo_import_check(bgp);
4026 }
4027
4028 return CMD_SUCCESS;
4029 }
4030
4031 DEFUN (bgp_default_local_preference,
4032 bgp_default_local_preference_cmd,
4033 "bgp default local-preference (0-4294967295)",
4034 BGP_STR
4035 "Configure BGP defaults\n"
4036 "local preference (higher=more preferred)\n"
4037 "Configure default local preference value\n")
4038 {
4039 VTY_DECLVAR_CONTEXT(bgp, bgp);
4040 int idx_number = 3;
4041 uint32_t local_pref;
4042
4043 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4044
4045 bgp_default_local_preference_set(bgp, local_pref);
4046 bgp_clear_star_soft_in(vty, bgp->name);
4047
4048 return CMD_SUCCESS;
4049 }
4050
4051 DEFUN (no_bgp_default_local_preference,
4052 no_bgp_default_local_preference_cmd,
4053 "no bgp default local-preference [(0-4294967295)]",
4054 NO_STR
4055 BGP_STR
4056 "Configure BGP defaults\n"
4057 "local preference (higher=more preferred)\n"
4058 "Configure default local preference value\n")
4059 {
4060 VTY_DECLVAR_CONTEXT(bgp, bgp);
4061 bgp_default_local_preference_unset(bgp);
4062 bgp_clear_star_soft_in(vty, bgp->name);
4063
4064 return CMD_SUCCESS;
4065 }
4066
4067
4068 DEFUN (bgp_default_subgroup_pkt_queue_max,
4069 bgp_default_subgroup_pkt_queue_max_cmd,
4070 "bgp default subgroup-pkt-queue-max (20-100)",
4071 BGP_STR
4072 "Configure BGP defaults\n"
4073 "subgroup-pkt-queue-max\n"
4074 "Configure subgroup packet queue max\n")
4075 {
4076 VTY_DECLVAR_CONTEXT(bgp, bgp);
4077 int idx_number = 3;
4078 uint32_t max_size;
4079
4080 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4081
4082 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4083
4084 return CMD_SUCCESS;
4085 }
4086
4087 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4088 no_bgp_default_subgroup_pkt_queue_max_cmd,
4089 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4090 NO_STR
4091 BGP_STR
4092 "Configure BGP defaults\n"
4093 "subgroup-pkt-queue-max\n"
4094 "Configure subgroup packet queue max\n")
4095 {
4096 VTY_DECLVAR_CONTEXT(bgp, bgp);
4097 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4098 return CMD_SUCCESS;
4099 }
4100
4101
4102 DEFUN (bgp_rr_allow_outbound_policy,
4103 bgp_rr_allow_outbound_policy_cmd,
4104 "bgp route-reflector allow-outbound-policy",
4105 BGP_STR
4106 "Allow modifications made by out route-map\n"
4107 "on ibgp neighbors\n")
4108 {
4109 VTY_DECLVAR_CONTEXT(bgp, bgp);
4110
4111 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4112 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4113 update_group_announce_rrclients(bgp);
4114 bgp_clear_star_soft_out(vty, bgp->name);
4115 }
4116
4117 return CMD_SUCCESS;
4118 }
4119
4120 DEFUN (no_bgp_rr_allow_outbound_policy,
4121 no_bgp_rr_allow_outbound_policy_cmd,
4122 "no bgp route-reflector allow-outbound-policy",
4123 NO_STR
4124 BGP_STR
4125 "Allow modifications made by out route-map\n"
4126 "on ibgp neighbors\n")
4127 {
4128 VTY_DECLVAR_CONTEXT(bgp, bgp);
4129
4130 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4131 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4132 update_group_announce_rrclients(bgp);
4133 bgp_clear_star_soft_out(vty, bgp->name);
4134 }
4135
4136 return CMD_SUCCESS;
4137 }
4138
4139 DEFUN (bgp_listen_limit,
4140 bgp_listen_limit_cmd,
4141 "bgp listen limit (1-65535)",
4142 BGP_STR
4143 "BGP Dynamic Neighbors listen commands\n"
4144 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4145 "Configure Dynamic Neighbors listen limit value\n")
4146 {
4147 VTY_DECLVAR_CONTEXT(bgp, bgp);
4148 int idx_number = 3;
4149 int listen_limit;
4150
4151 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4152
4153 bgp_listen_limit_set(bgp, listen_limit);
4154
4155 return CMD_SUCCESS;
4156 }
4157
4158 DEFUN (no_bgp_listen_limit,
4159 no_bgp_listen_limit_cmd,
4160 "no bgp listen limit [(1-65535)]",
4161 NO_STR
4162 BGP_STR
4163 "BGP Dynamic Neighbors listen commands\n"
4164 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4165 "Configure Dynamic Neighbors listen limit value\n")
4166 {
4167 VTY_DECLVAR_CONTEXT(bgp, bgp);
4168 bgp_listen_limit_unset(bgp);
4169 return CMD_SUCCESS;
4170 }
4171
4172
4173 /*
4174 * Check if this listen range is already configured. Check for exact
4175 * match or overlap based on input.
4176 */
4177 static struct peer_group *listen_range_exists(struct bgp *bgp,
4178 struct prefix *range, int exact)
4179 {
4180 struct listnode *node, *nnode;
4181 struct listnode *node1, *nnode1;
4182 struct peer_group *group;
4183 struct prefix *lr;
4184 afi_t afi;
4185 int match;
4186
4187 afi = family2afi(range->family);
4188 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4189 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4190 lr)) {
4191 if (exact)
4192 match = prefix_same(range, lr);
4193 else
4194 match = (prefix_match(range, lr)
4195 || prefix_match(lr, range));
4196 if (match)
4197 return group;
4198 }
4199 }
4200
4201 return NULL;
4202 }
4203
4204 DEFUN (bgp_listen_range,
4205 bgp_listen_range_cmd,
4206 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4207 BGP_STR
4208 "Configure BGP dynamic neighbors listen range\n"
4209 "Configure BGP dynamic neighbors listen range\n"
4210 NEIGHBOR_ADDR_STR
4211 "Member of the peer-group\n"
4212 "Peer-group name\n")
4213 {
4214 VTY_DECLVAR_CONTEXT(bgp, bgp);
4215 struct prefix range;
4216 struct peer_group *group, *existing_group;
4217 afi_t afi;
4218 int ret;
4219 int idx = 0;
4220
4221 argv_find(argv, argc, "A.B.C.D/M", &idx);
4222 argv_find(argv, argc, "X:X::X:X/M", &idx);
4223 char *prefix = argv[idx]->arg;
4224 argv_find(argv, argc, "PGNAME", &idx);
4225 char *peergroup = argv[idx]->arg;
4226
4227 /* Convert IP prefix string to struct prefix. */
4228 ret = str2prefix(prefix, &range);
4229 if (!ret) {
4230 vty_out(vty, "%% Malformed listen range\n");
4231 return CMD_WARNING_CONFIG_FAILED;
4232 }
4233
4234 afi = family2afi(range.family);
4235
4236 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4237 vty_out(vty,
4238 "%% Malformed listen range (link-local address)\n");
4239 return CMD_WARNING_CONFIG_FAILED;
4240 }
4241
4242 apply_mask(&range);
4243
4244 /* Check if same listen range is already configured. */
4245 existing_group = listen_range_exists(bgp, &range, 1);
4246 if (existing_group) {
4247 if (strcmp(existing_group->name, peergroup) == 0)
4248 return CMD_SUCCESS;
4249 else {
4250 vty_out(vty,
4251 "%% Same listen range is attached to peer-group %s\n",
4252 existing_group->name);
4253 return CMD_WARNING_CONFIG_FAILED;
4254 }
4255 }
4256
4257 /* Check if an overlapping listen range exists. */
4258 if (listen_range_exists(bgp, &range, 0)) {
4259 vty_out(vty,
4260 "%% Listen range overlaps with existing listen range\n");
4261 return CMD_WARNING_CONFIG_FAILED;
4262 }
4263
4264 group = peer_group_lookup(bgp, peergroup);
4265 if (!group) {
4266 vty_out(vty, "%% Configure the peer-group first\n");
4267 return CMD_WARNING_CONFIG_FAILED;
4268 }
4269
4270 ret = peer_group_listen_range_add(group, &range);
4271 return bgp_vty_return(vty, ret);
4272 }
4273
4274 DEFUN (no_bgp_listen_range,
4275 no_bgp_listen_range_cmd,
4276 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4277 NO_STR
4278 BGP_STR
4279 "Unconfigure BGP dynamic neighbors listen range\n"
4280 "Unconfigure BGP dynamic neighbors listen range\n"
4281 NEIGHBOR_ADDR_STR
4282 "Member of the peer-group\n"
4283 "Peer-group name\n")
4284 {
4285 VTY_DECLVAR_CONTEXT(bgp, bgp);
4286 struct prefix range;
4287 struct peer_group *group;
4288 afi_t afi;
4289 int ret;
4290 int idx = 0;
4291
4292 argv_find(argv, argc, "A.B.C.D/M", &idx);
4293 argv_find(argv, argc, "X:X::X:X/M", &idx);
4294 char *prefix = argv[idx]->arg;
4295 argv_find(argv, argc, "PGNAME", &idx);
4296 char *peergroup = argv[idx]->arg;
4297
4298 /* Convert IP prefix string to struct prefix. */
4299 ret = str2prefix(prefix, &range);
4300 if (!ret) {
4301 vty_out(vty, "%% Malformed listen range\n");
4302 return CMD_WARNING_CONFIG_FAILED;
4303 }
4304
4305 afi = family2afi(range.family);
4306
4307 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4308 vty_out(vty,
4309 "%% Malformed listen range (link-local address)\n");
4310 return CMD_WARNING_CONFIG_FAILED;
4311 }
4312
4313 apply_mask(&range);
4314
4315 group = peer_group_lookup(bgp, peergroup);
4316 if (!group) {
4317 vty_out(vty, "%% Peer-group does not exist\n");
4318 return CMD_WARNING_CONFIG_FAILED;
4319 }
4320
4321 ret = peer_group_listen_range_del(group, &range);
4322 return bgp_vty_return(vty, ret);
4323 }
4324
4325 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4326 {
4327 struct peer_group *group;
4328 struct listnode *node, *nnode, *rnode, *nrnode;
4329 struct prefix *range;
4330 afi_t afi;
4331
4332 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4333 vty_out(vty, " bgp listen limit %d\n",
4334 bgp->dynamic_neighbors_limit);
4335
4336 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4337 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4338 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4339 nrnode, range)) {
4340 vty_out(vty,
4341 " bgp listen range %pFX peer-group %s\n",
4342 range, group->name);
4343 }
4344 }
4345 }
4346 }
4347
4348
4349 DEFUN (bgp_disable_connected_route_check,
4350 bgp_disable_connected_route_check_cmd,
4351 "bgp disable-ebgp-connected-route-check",
4352 BGP_STR
4353 "Disable checking if nexthop is connected on ebgp sessions\n")
4354 {
4355 VTY_DECLVAR_CONTEXT(bgp, bgp);
4356 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4357 bgp_clear_star_soft_in(vty, bgp->name);
4358
4359 return CMD_SUCCESS;
4360 }
4361
4362 DEFUN (no_bgp_disable_connected_route_check,
4363 no_bgp_disable_connected_route_check_cmd,
4364 "no bgp disable-ebgp-connected-route-check",
4365 NO_STR
4366 BGP_STR
4367 "Disable checking if nexthop is connected on ebgp sessions\n")
4368 {
4369 VTY_DECLVAR_CONTEXT(bgp, bgp);
4370 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4371 bgp_clear_star_soft_in(vty, bgp->name);
4372
4373 return CMD_SUCCESS;
4374 }
4375
4376
4377 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4378 const char *as_str)
4379 {
4380 VTY_DECLVAR_CONTEXT(bgp, bgp);
4381 int ret;
4382 as_t as;
4383 int as_type = AS_SPECIFIED;
4384 union sockunion su;
4385
4386 if (as_str[0] == 'i') {
4387 as = 0;
4388 as_type = AS_INTERNAL;
4389 } else if (as_str[0] == 'e') {
4390 as = 0;
4391 as_type = AS_EXTERNAL;
4392 } else {
4393 /* Get AS number. */
4394 as = strtoul(as_str, NULL, 10);
4395 }
4396
4397 /* If peer is peer group or interface peer, call proper function. */
4398 ret = str2sockunion(peer_str, &su);
4399 if (ret < 0) {
4400 struct peer *peer;
4401
4402 /* Check if existing interface peer */
4403 peer = peer_lookup_by_conf_if(bgp, peer_str);
4404
4405 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4406
4407 /* if not interface peer, check peer-group settings */
4408 if (ret < 0 && !peer) {
4409 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4410 if (ret < 0) {
4411 vty_out(vty,
4412 "%% Create the peer-group or interface first\n");
4413 return CMD_WARNING_CONFIG_FAILED;
4414 }
4415 return CMD_SUCCESS;
4416 }
4417 } else {
4418 if (peer_address_self_check(bgp, &su)) {
4419 vty_out(vty,
4420 "%% Can not configure the local system as neighbor\n");
4421 return CMD_WARNING_CONFIG_FAILED;
4422 }
4423 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4424 }
4425
4426 return bgp_vty_return(vty, ret);
4427 }
4428
4429 DEFUN (bgp_default_shutdown,
4430 bgp_default_shutdown_cmd,
4431 "[no] bgp default shutdown",
4432 NO_STR
4433 BGP_STR
4434 "Configure BGP defaults\n"
4435 "Apply administrative shutdown to newly configured peers\n")
4436 {
4437 VTY_DECLVAR_CONTEXT(bgp, bgp);
4438 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4439 return CMD_SUCCESS;
4440 }
4441
4442 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4443 BGP_STR
4444 "Administrative shutdown of the BGP instance\n"
4445 "Add a shutdown message (RFC 8203)\n"
4446 "Shutdown message\n")
4447 {
4448 char *msgstr = NULL;
4449
4450 VTY_DECLVAR_CONTEXT(bgp, bgp);
4451
4452 if (argc > 3)
4453 msgstr = argv_concat(argv, argc, 3);
4454
4455 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4456 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4457 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4458 return CMD_WARNING_CONFIG_FAILED;
4459 }
4460
4461 bgp_shutdown_enable(bgp, msgstr);
4462 XFREE(MTYPE_TMP, msgstr);
4463
4464 return CMD_SUCCESS;
4465 }
4466
4467 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4468 BGP_STR "Administrative shutdown of the BGP instance\n")
4469 {
4470 VTY_DECLVAR_CONTEXT(bgp, bgp);
4471
4472 bgp_shutdown_enable(bgp, NULL);
4473
4474 return CMD_SUCCESS;
4475 }
4476
4477 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4478 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4479 {
4480 VTY_DECLVAR_CONTEXT(bgp, bgp);
4481
4482 bgp_shutdown_disable(bgp);
4483
4484 return CMD_SUCCESS;
4485 }
4486
4487 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4488 "no bgp shutdown message MSG...", NO_STR BGP_STR
4489 "Administrative shutdown of the BGP instance\n"
4490 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4491
4492 DEFUN (neighbor_remote_as,
4493 neighbor_remote_as_cmd,
4494 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4495 NEIGHBOR_STR
4496 NEIGHBOR_ADDR_STR2
4497 "Specify a BGP neighbor\n"
4498 AS_STR
4499 "Internal BGP peer\n"
4500 "External BGP peer\n")
4501 {
4502 int idx_peer = 1;
4503 int idx_remote_as = 3;
4504 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4505 argv[idx_remote_as]->arg);
4506 }
4507
4508 DEFPY (bgp_allow_martian,
4509 bgp_allow_martian_cmd,
4510 "[no]$no bgp allow-martian-nexthop",
4511 NO_STR
4512 BGP_STR
4513 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4514 {
4515 VTY_DECLVAR_CONTEXT(bgp, bgp);
4516
4517 if (no)
4518 bgp->allow_martian = false;
4519 else
4520 bgp->allow_martian = true;
4521
4522 return CMD_SUCCESS;
4523 }
4524
4525 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4526 * sessions do not wait for hold timer expiry to bring down the sessions
4527 * when nexthop becomes unreachable
4528 */
4529 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4530 BGP_STR "Fast convergence for bgp sessions\n")
4531 {
4532 VTY_DECLVAR_CONTEXT(bgp, bgp);
4533 bgp->fast_convergence = true;
4534
4535 return CMD_SUCCESS;
4536 }
4537
4538 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4539 "no bgp fast-convergence",
4540 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4541 {
4542 VTY_DECLVAR_CONTEXT(bgp, bgp);
4543 bgp->fast_convergence = false;
4544
4545 return CMD_SUCCESS;
4546 }
4547
4548 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4549 int v6only,
4550 const char *peer_group_name,
4551 const char *as_str)
4552 {
4553 VTY_DECLVAR_CONTEXT(bgp, bgp);
4554 as_t as = 0;
4555 int as_type = AS_UNSPECIFIED;
4556 struct peer *peer;
4557 struct peer_group *group;
4558 int ret = 0;
4559
4560 group = peer_group_lookup(bgp, conf_if);
4561
4562 if (group) {
4563 vty_out(vty, "%% Name conflict with peer-group \n");
4564 return CMD_WARNING_CONFIG_FAILED;
4565 }
4566
4567 if (as_str) {
4568 if (as_str[0] == 'i') {
4569 as_type = AS_INTERNAL;
4570 } else if (as_str[0] == 'e') {
4571 as_type = AS_EXTERNAL;
4572 } else {
4573 /* Get AS number. */
4574 as = strtoul(as_str, NULL, 10);
4575 as_type = AS_SPECIFIED;
4576 }
4577 }
4578
4579 peer = peer_lookup_by_conf_if(bgp, conf_if);
4580 if (peer) {
4581 if (as_str)
4582 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4583 } else {
4584 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4585 NULL);
4586
4587 if (!peer) {
4588 vty_out(vty, "%% BGP failed to create peer\n");
4589 return CMD_WARNING_CONFIG_FAILED;
4590 }
4591
4592 if (v6only)
4593 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4594
4595 /* Request zebra to initiate IPv6 RAs on this interface. We do
4596 * this
4597 * any unnumbered peer in order to not worry about run-time
4598 * transitions
4599 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4600 * address
4601 * gets deleted later etc.)
4602 */
4603 if (peer->ifp)
4604 bgp_zebra_initiate_radv(bgp, peer);
4605 }
4606
4607 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4608 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4609 if (v6only)
4610 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4611 else
4612 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4613
4614 /* v6only flag changed. Reset bgp seesion */
4615 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4616 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4617 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4618 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4619 } else
4620 bgp_session_reset(peer);
4621 }
4622
4623 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4624 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4625 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4626 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4627 }
4628
4629 if (peer_group_name) {
4630 group = peer_group_lookup(bgp, peer_group_name);
4631 if (!group) {
4632 vty_out(vty, "%% Configure the peer-group first\n");
4633 return CMD_WARNING_CONFIG_FAILED;
4634 }
4635
4636 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4637 }
4638
4639 return bgp_vty_return(vty, ret);
4640 }
4641
4642 DEFUN (neighbor_interface_config,
4643 neighbor_interface_config_cmd,
4644 "neighbor WORD interface [peer-group PGNAME]",
4645 NEIGHBOR_STR
4646 "Interface name or neighbor tag\n"
4647 "Enable BGP on interface\n"
4648 "Member of the peer-group\n"
4649 "Peer-group name\n")
4650 {
4651 int idx_word = 1;
4652 int idx_peer_group_word = 4;
4653
4654 if (argc > idx_peer_group_word)
4655 return peer_conf_interface_get(
4656 vty, argv[idx_word]->arg, 0,
4657 argv[idx_peer_group_word]->arg, NULL);
4658 else
4659 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4660 NULL, NULL);
4661 }
4662
4663 DEFUN (neighbor_interface_config_v6only,
4664 neighbor_interface_config_v6only_cmd,
4665 "neighbor WORD interface v6only [peer-group PGNAME]",
4666 NEIGHBOR_STR
4667 "Interface name or neighbor tag\n"
4668 "Enable BGP on interface\n"
4669 "Enable BGP with v6 link-local only\n"
4670 "Member of the peer-group\n"
4671 "Peer-group name\n")
4672 {
4673 int idx_word = 1;
4674 int idx_peer_group_word = 5;
4675
4676 if (argc > idx_peer_group_word)
4677 return peer_conf_interface_get(
4678 vty, argv[idx_word]->arg, 1,
4679 argv[idx_peer_group_word]->arg, NULL);
4680
4681 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4682 }
4683
4684
4685 DEFUN (neighbor_interface_config_remote_as,
4686 neighbor_interface_config_remote_as_cmd,
4687 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4688 NEIGHBOR_STR
4689 "Interface name or neighbor tag\n"
4690 "Enable BGP on interface\n"
4691 "Specify a BGP neighbor\n"
4692 AS_STR
4693 "Internal BGP peer\n"
4694 "External BGP peer\n")
4695 {
4696 int idx_word = 1;
4697 int idx_remote_as = 4;
4698 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4699 argv[idx_remote_as]->arg);
4700 }
4701
4702 DEFUN (neighbor_interface_v6only_config_remote_as,
4703 neighbor_interface_v6only_config_remote_as_cmd,
4704 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4705 NEIGHBOR_STR
4706 "Interface name or neighbor tag\n"
4707 "Enable BGP with v6 link-local only\n"
4708 "Enable BGP on interface\n"
4709 "Specify a BGP neighbor\n"
4710 AS_STR
4711 "Internal BGP peer\n"
4712 "External BGP peer\n")
4713 {
4714 int idx_word = 1;
4715 int idx_remote_as = 5;
4716 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4717 argv[idx_remote_as]->arg);
4718 }
4719
4720 DEFUN (neighbor_peer_group,
4721 neighbor_peer_group_cmd,
4722 "neighbor WORD peer-group",
4723 NEIGHBOR_STR
4724 "Interface name or neighbor tag\n"
4725 "Configure peer-group\n")
4726 {
4727 VTY_DECLVAR_CONTEXT(bgp, bgp);
4728 int idx_word = 1;
4729 struct peer *peer;
4730 struct peer_group *group;
4731
4732 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4733 if (peer) {
4734 vty_out(vty, "%% Name conflict with interface: \n");
4735 return CMD_WARNING_CONFIG_FAILED;
4736 }
4737
4738 group = peer_group_get(bgp, argv[idx_word]->arg);
4739 if (!group) {
4740 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4741 return CMD_WARNING_CONFIG_FAILED;
4742 }
4743
4744 return CMD_SUCCESS;
4745 }
4746
4747 DEFUN (no_neighbor,
4748 no_neighbor_cmd,
4749 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4750 NO_STR
4751 NEIGHBOR_STR
4752 NEIGHBOR_ADDR_STR2
4753 "Specify a BGP neighbor\n"
4754 AS_STR
4755 "Internal BGP peer\n"
4756 "External BGP peer\n")
4757 {
4758 VTY_DECLVAR_CONTEXT(bgp, bgp);
4759 int idx_peer = 2;
4760 int ret;
4761 union sockunion su;
4762 struct peer_group *group;
4763 struct peer *peer;
4764 struct peer *other;
4765
4766 ret = str2sockunion(argv[idx_peer]->arg, &su);
4767 if (ret < 0) {
4768 /* look up for neighbor by interface name config. */
4769 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4770 if (peer) {
4771 /* Request zebra to terminate IPv6 RAs on this
4772 * interface. */
4773 if (peer->ifp)
4774 bgp_zebra_terminate_radv(peer->bgp, peer);
4775 peer_notify_unconfig(peer);
4776 peer_delete(peer);
4777 return CMD_SUCCESS;
4778 }
4779
4780 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4781 if (group) {
4782 peer_group_notify_unconfig(group);
4783 peer_group_delete(group);
4784 } else {
4785 vty_out(vty, "%% Create the peer-group first\n");
4786 return CMD_WARNING_CONFIG_FAILED;
4787 }
4788 } else {
4789 peer = peer_lookup(bgp, &su);
4790 if (peer) {
4791 if (peer_dynamic_neighbor(peer)) {
4792 vty_out(vty,
4793 "%% Operation not allowed on a dynamic neighbor\n");
4794 return CMD_WARNING_CONFIG_FAILED;
4795 }
4796
4797 other = peer->doppelganger;
4798
4799 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4800 bgp_zebra_terminate_radv(peer->bgp, peer);
4801
4802 peer_notify_unconfig(peer);
4803 peer_delete(peer);
4804 if (other && other->status != Deleted) {
4805 peer_notify_unconfig(other);
4806 peer_delete(other);
4807 }
4808 }
4809 }
4810
4811 return CMD_SUCCESS;
4812 }
4813
4814 DEFUN (no_neighbor_interface_config,
4815 no_neighbor_interface_config_cmd,
4816 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4817 NO_STR
4818 NEIGHBOR_STR
4819 "Interface name\n"
4820 "Configure BGP on interface\n"
4821 "Enable BGP with v6 link-local only\n"
4822 "Member of the peer-group\n"
4823 "Peer-group name\n"
4824 "Specify a BGP neighbor\n"
4825 AS_STR
4826 "Internal BGP peer\n"
4827 "External BGP peer\n")
4828 {
4829 VTY_DECLVAR_CONTEXT(bgp, bgp);
4830 int idx_word = 2;
4831 struct peer *peer;
4832
4833 /* look up for neighbor by interface name config. */
4834 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4835 if (peer) {
4836 /* Request zebra to terminate IPv6 RAs on this interface. */
4837 if (peer->ifp)
4838 bgp_zebra_terminate_radv(peer->bgp, peer);
4839 peer_notify_unconfig(peer);
4840 peer_delete(peer);
4841 } else {
4842 vty_out(vty, "%% Create the bgp interface first\n");
4843 return CMD_WARNING_CONFIG_FAILED;
4844 }
4845 return CMD_SUCCESS;
4846 }
4847
4848 DEFUN (no_neighbor_peer_group,
4849 no_neighbor_peer_group_cmd,
4850 "no neighbor WORD peer-group",
4851 NO_STR
4852 NEIGHBOR_STR
4853 "Neighbor tag\n"
4854 "Configure peer-group\n")
4855 {
4856 VTY_DECLVAR_CONTEXT(bgp, bgp);
4857 int idx_word = 2;
4858 struct peer_group *group;
4859
4860 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4861 if (group) {
4862 peer_group_notify_unconfig(group);
4863 peer_group_delete(group);
4864 } else {
4865 vty_out(vty, "%% Create the peer-group first\n");
4866 return CMD_WARNING_CONFIG_FAILED;
4867 }
4868 return CMD_SUCCESS;
4869 }
4870
4871 DEFUN (no_neighbor_interface_peer_group_remote_as,
4872 no_neighbor_interface_peer_group_remote_as_cmd,
4873 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4874 NO_STR
4875 NEIGHBOR_STR
4876 "Interface name or neighbor tag\n"
4877 "Specify a BGP neighbor\n"
4878 AS_STR
4879 "Internal BGP peer\n"
4880 "External BGP peer\n")
4881 {
4882 VTY_DECLVAR_CONTEXT(bgp, bgp);
4883 int idx_word = 2;
4884 struct peer_group *group;
4885 struct peer *peer;
4886
4887 /* look up for neighbor by interface name config. */
4888 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4889 if (peer) {
4890 peer_as_change(peer, 0, AS_UNSPECIFIED);
4891 return CMD_SUCCESS;
4892 }
4893
4894 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4895 if (group)
4896 peer_group_remote_as_delete(group);
4897 else {
4898 vty_out(vty, "%% Create the peer-group or interface first\n");
4899 return CMD_WARNING_CONFIG_FAILED;
4900 }
4901 return CMD_SUCCESS;
4902 }
4903
4904 DEFUN (neighbor_local_as,
4905 neighbor_local_as_cmd,
4906 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4907 NEIGHBOR_STR
4908 NEIGHBOR_ADDR_STR2
4909 "Specify a local-as number\n"
4910 "AS number used as local AS\n")
4911 {
4912 int idx_peer = 1;
4913 int idx_number = 3;
4914 struct peer *peer;
4915 int ret;
4916 as_t as;
4917
4918 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4919 if (!peer)
4920 return CMD_WARNING_CONFIG_FAILED;
4921
4922 as = strtoul(argv[idx_number]->arg, NULL, 10);
4923 ret = peer_local_as_set(peer, as, 0, 0);
4924 return bgp_vty_return(vty, ret);
4925 }
4926
4927 DEFUN (neighbor_local_as_no_prepend,
4928 neighbor_local_as_no_prepend_cmd,
4929 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4930 NEIGHBOR_STR
4931 NEIGHBOR_ADDR_STR2
4932 "Specify a local-as number\n"
4933 "AS number used as local AS\n"
4934 "Do not prepend local-as to updates from ebgp peers\n")
4935 {
4936 int idx_peer = 1;
4937 int idx_number = 3;
4938 struct peer *peer;
4939 int ret;
4940 as_t as;
4941
4942 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4943 if (!peer)
4944 return CMD_WARNING_CONFIG_FAILED;
4945
4946 as = strtoul(argv[idx_number]->arg, NULL, 10);
4947 ret = peer_local_as_set(peer, as, 1, 0);
4948 return bgp_vty_return(vty, ret);
4949 }
4950
4951 DEFUN (neighbor_local_as_no_prepend_replace_as,
4952 neighbor_local_as_no_prepend_replace_as_cmd,
4953 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4954 NEIGHBOR_STR
4955 NEIGHBOR_ADDR_STR2
4956 "Specify a local-as number\n"
4957 "AS number used as local AS\n"
4958 "Do not prepend local-as to updates from ebgp peers\n"
4959 "Do not prepend local-as to updates from ibgp peers\n")
4960 {
4961 int idx_peer = 1;
4962 int idx_number = 3;
4963 struct peer *peer;
4964 int ret;
4965 as_t as;
4966
4967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4968 if (!peer)
4969 return CMD_WARNING_CONFIG_FAILED;
4970
4971 as = strtoul(argv[idx_number]->arg, NULL, 10);
4972 ret = peer_local_as_set(peer, as, 1, 1);
4973 return bgp_vty_return(vty, ret);
4974 }
4975
4976 DEFUN (no_neighbor_local_as,
4977 no_neighbor_local_as_cmd,
4978 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4979 NO_STR
4980 NEIGHBOR_STR
4981 NEIGHBOR_ADDR_STR2
4982 "Specify a local-as number\n"
4983 "AS number used as local AS\n"
4984 "Do not prepend local-as to updates from ebgp peers\n"
4985 "Do not prepend local-as to updates from ibgp peers\n")
4986 {
4987 int idx_peer = 2;
4988 struct peer *peer;
4989 int ret;
4990
4991 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4992 if (!peer)
4993 return CMD_WARNING_CONFIG_FAILED;
4994
4995 ret = peer_local_as_unset(peer);
4996 return bgp_vty_return(vty, ret);
4997 }
4998
4999
5000 DEFUN (neighbor_solo,
5001 neighbor_solo_cmd,
5002 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5003 NEIGHBOR_STR
5004 NEIGHBOR_ADDR_STR2
5005 "Solo peer - part of its own update group\n")
5006 {
5007 int idx_peer = 1;
5008 struct peer *peer;
5009 int ret;
5010
5011 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5012 if (!peer)
5013 return CMD_WARNING_CONFIG_FAILED;
5014
5015 ret = update_group_adjust_soloness(peer, 1);
5016 return bgp_vty_return(vty, ret);
5017 }
5018
5019 DEFUN (no_neighbor_solo,
5020 no_neighbor_solo_cmd,
5021 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5022 NO_STR
5023 NEIGHBOR_STR
5024 NEIGHBOR_ADDR_STR2
5025 "Solo peer - part of its own update group\n")
5026 {
5027 int idx_peer = 2;
5028 struct peer *peer;
5029 int ret;
5030
5031 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
5034
5035 ret = update_group_adjust_soloness(peer, 0);
5036 return bgp_vty_return(vty, ret);
5037 }
5038
5039 DEFUN (neighbor_password,
5040 neighbor_password_cmd,
5041 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5042 NEIGHBOR_STR
5043 NEIGHBOR_ADDR_STR2
5044 "Set a password\n"
5045 "The password\n")
5046 {
5047 int idx_peer = 1;
5048 int idx_line = 3;
5049 struct peer *peer;
5050 int ret;
5051
5052 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5053 if (!peer)
5054 return CMD_WARNING_CONFIG_FAILED;
5055
5056 ret = peer_password_set(peer, argv[idx_line]->arg);
5057 return bgp_vty_return(vty, ret);
5058 }
5059
5060 DEFUN (no_neighbor_password,
5061 no_neighbor_password_cmd,
5062 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5063 NO_STR
5064 NEIGHBOR_STR
5065 NEIGHBOR_ADDR_STR2
5066 "Set a password\n"
5067 "The password\n")
5068 {
5069 int idx_peer = 2;
5070 struct peer *peer;
5071 int ret;
5072
5073 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5074 if (!peer)
5075 return CMD_WARNING_CONFIG_FAILED;
5076
5077 ret = peer_password_unset(peer);
5078 return bgp_vty_return(vty, ret);
5079 }
5080
5081 DEFUN (neighbor_activate,
5082 neighbor_activate_cmd,
5083 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5084 NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Enable the Address Family for this Neighbor\n")
5087 {
5088 int idx_peer = 1;
5089 int ret;
5090 struct peer *peer;
5091
5092 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5093 if (!peer)
5094 return CMD_WARNING_CONFIG_FAILED;
5095
5096 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5097 return bgp_vty_return(vty, ret);
5098 }
5099
5100 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5101 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5102 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5103 "Enable the Address Family for this Neighbor\n")
5104
5105 DEFUN (no_neighbor_activate,
5106 no_neighbor_activate_cmd,
5107 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5108 NO_STR
5109 NEIGHBOR_STR
5110 NEIGHBOR_ADDR_STR2
5111 "Enable the Address Family for this Neighbor\n")
5112 {
5113 int idx_peer = 2;
5114 int ret;
5115 struct peer *peer;
5116
5117 /* Lookup peer. */
5118 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5119 if (!peer)
5120 return CMD_WARNING_CONFIG_FAILED;
5121
5122 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5123 return bgp_vty_return(vty, ret);
5124 }
5125
5126 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5127 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5128 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5129 "Enable the Address Family for this Neighbor\n")
5130
5131 DEFUN (neighbor_set_peer_group,
5132 neighbor_set_peer_group_cmd,
5133 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "Member of the peer-group\n"
5137 "Peer-group name\n")
5138 {
5139 VTY_DECLVAR_CONTEXT(bgp, bgp);
5140 int idx_peer = 1;
5141 int idx_word = 3;
5142 int ret;
5143 as_t as;
5144 union sockunion su;
5145 struct peer *peer;
5146 struct peer_group *group;
5147
5148 ret = str2sockunion(argv[idx_peer]->arg, &su);
5149 if (ret < 0) {
5150 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5151 if (!peer) {
5152 vty_out(vty, "%% Malformed address or name: %s\n",
5153 argv[idx_peer]->arg);
5154 return CMD_WARNING_CONFIG_FAILED;
5155 }
5156 } else {
5157 if (peer_address_self_check(bgp, &su)) {
5158 vty_out(vty,
5159 "%% Can not configure the local system as neighbor\n");
5160 return CMD_WARNING_CONFIG_FAILED;
5161 }
5162
5163 /* Disallow for dynamic neighbor. */
5164 peer = peer_lookup(bgp, &su);
5165 if (peer && peer_dynamic_neighbor(peer)) {
5166 vty_out(vty,
5167 "%% Operation not allowed on a dynamic neighbor\n");
5168 return CMD_WARNING_CONFIG_FAILED;
5169 }
5170 }
5171
5172 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5173 if (!group) {
5174 vty_out(vty, "%% Configure the peer-group first\n");
5175 return CMD_WARNING_CONFIG_FAILED;
5176 }
5177
5178 ret = peer_group_bind(bgp, &su, peer, group, &as);
5179
5180 return bgp_vty_return(vty, ret);
5181 }
5182
5183 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5184 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5186 "Member of the peer-group\n"
5187 "Peer-group name\n")
5188
5189 DEFUN (no_neighbor_set_peer_group,
5190 no_neighbor_set_peer_group_cmd,
5191 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5192 NO_STR
5193 NEIGHBOR_STR
5194 NEIGHBOR_ADDR_STR2
5195 "Member of the peer-group\n"
5196 "Peer-group name\n")
5197 {
5198 VTY_DECLVAR_CONTEXT(bgp, bgp);
5199 int idx_peer = 2;
5200 int idx_word = 4;
5201 int ret;
5202 struct peer *peer;
5203 struct peer_group *group;
5204
5205 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5206 if (!peer)
5207 return CMD_WARNING_CONFIG_FAILED;
5208
5209 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5210 if (!group) {
5211 vty_out(vty, "%% Configure the peer-group first\n");
5212 return CMD_WARNING_CONFIG_FAILED;
5213 }
5214
5215 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5216 bgp_zebra_terminate_radv(peer->bgp, peer);
5217
5218 peer_notify_unconfig(peer);
5219 ret = peer_delete(peer);
5220
5221 return bgp_vty_return(vty, ret);
5222 }
5223
5224 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5225 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5227 "Member of the peer-group\n"
5228 "Peer-group name\n")
5229
5230 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5231 uint64_t flag, int set)
5232 {
5233 int ret;
5234 struct peer *peer;
5235
5236 peer = peer_and_group_lookup_vty(vty, ip_str);
5237 if (!peer)
5238 return CMD_WARNING_CONFIG_FAILED;
5239
5240 /*
5241 * If 'neighbor <interface>', then this is for directly connected peers,
5242 * we should not accept disable-connected-check.
5243 */
5244 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5245 vty_out(vty,
5246 "%s is directly connected peer, cannot accept disable-connected-check\n",
5247 ip_str);
5248 return CMD_WARNING_CONFIG_FAILED;
5249 }
5250
5251 if (!set && flag == PEER_FLAG_SHUTDOWN)
5252 peer_tx_shutdown_message_unset(peer);
5253
5254 if (set)
5255 ret = peer_flag_set(peer, flag);
5256 else
5257 ret = peer_flag_unset(peer, flag);
5258
5259 return bgp_vty_return(vty, ret);
5260 }
5261
5262 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5263 {
5264 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5265 }
5266
5267 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5268 uint64_t flag)
5269 {
5270 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5271 }
5272
5273 /* neighbor passive. */
5274 DEFUN (neighbor_passive,
5275 neighbor_passive_cmd,
5276 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5277 NEIGHBOR_STR
5278 NEIGHBOR_ADDR_STR2
5279 "Don't send open messages to this neighbor\n")
5280 {
5281 int idx_peer = 1;
5282 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5283 }
5284
5285 DEFUN (no_neighbor_passive,
5286 no_neighbor_passive_cmd,
5287 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5288 NO_STR
5289 NEIGHBOR_STR
5290 NEIGHBOR_ADDR_STR2
5291 "Don't send open messages to this neighbor\n")
5292 {
5293 int idx_peer = 2;
5294 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5295 }
5296
5297 /* neighbor shutdown. */
5298 DEFUN (neighbor_shutdown_msg,
5299 neighbor_shutdown_msg_cmd,
5300 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5301 NEIGHBOR_STR
5302 NEIGHBOR_ADDR_STR2
5303 "Administratively shut down this neighbor\n"
5304 "Add a shutdown message (RFC 8203)\n"
5305 "Shutdown message\n")
5306 {
5307 int idx_peer = 1;
5308
5309 if (argc >= 5) {
5310 struct peer *peer =
5311 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5312 char *message;
5313
5314 if (!peer)
5315 return CMD_WARNING_CONFIG_FAILED;
5316 message = argv_concat(argv, argc, 4);
5317 peer_tx_shutdown_message_set(peer, message);
5318 XFREE(MTYPE_TMP, message);
5319 }
5320
5321 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5322 }
5323
5324 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5325 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5327 "Administratively shut down this neighbor\n")
5328
5329 DEFUN (no_neighbor_shutdown_msg,
5330 no_neighbor_shutdown_msg_cmd,
5331 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5332 NO_STR
5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Administratively shut down this neighbor\n"
5336 "Remove a shutdown message (RFC 8203)\n"
5337 "Shutdown message\n")
5338 {
5339 int idx_peer = 2;
5340
5341 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5342 PEER_FLAG_SHUTDOWN);
5343 }
5344
5345 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5346 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5347 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5348 "Administratively shut down this neighbor\n")
5349
5350 DEFUN(neighbor_shutdown_rtt,
5351 neighbor_shutdown_rtt_cmd,
5352 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5353 NEIGHBOR_STR
5354 NEIGHBOR_ADDR_STR2
5355 "Administratively shut down this neighbor\n"
5356 "Shutdown if round-trip-time is higher than expected\n"
5357 "Round-trip-time in milliseconds\n"
5358 "Specify the number of keepalives before shutdown\n"
5359 "The number of keepalives with higher RTT to shutdown\n")
5360 {
5361 int idx_peer = 1;
5362 int idx_rtt = 4;
5363 int idx_count = 0;
5364 struct peer *peer;
5365
5366 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5367
5368 if (!peer)
5369 return CMD_WARNING_CONFIG_FAILED;
5370
5371 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5372
5373 if (argv_find(argv, argc, "count", &idx_count))
5374 peer->rtt_keepalive_conf =
5375 strtol(argv[idx_count + 1]->arg, NULL, 10);
5376
5377 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5378 PEER_FLAG_RTT_SHUTDOWN);
5379 }
5380
5381 DEFUN(no_neighbor_shutdown_rtt,
5382 no_neighbor_shutdown_rtt_cmd,
5383 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5384 NO_STR
5385 NEIGHBOR_STR
5386 NEIGHBOR_ADDR_STR2
5387 "Administratively shut down this neighbor\n"
5388 "Shutdown if round-trip-time is higher than expected\n"
5389 "Round-trip-time in milliseconds\n"
5390 "Specify the number of keepalives before shutdown\n"
5391 "The number of keepalives with higher RTT to shutdown\n")
5392 {
5393 int idx_peer = 2;
5394 struct peer *peer;
5395
5396 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5397
5398 if (!peer)
5399 return CMD_WARNING_CONFIG_FAILED;
5400
5401 peer->rtt_expected = 0;
5402 peer->rtt_keepalive_conf = 1;
5403
5404 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5405 PEER_FLAG_RTT_SHUTDOWN);
5406 }
5407
5408 /* neighbor capability dynamic. */
5409 DEFUN (neighbor_capability_dynamic,
5410 neighbor_capability_dynamic_cmd,
5411 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5412 NEIGHBOR_STR
5413 NEIGHBOR_ADDR_STR2
5414 "Advertise capability to the peer\n"
5415 "Advertise dynamic capability to this neighbor\n")
5416 {
5417 int idx_peer = 1;
5418 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5419 PEER_FLAG_DYNAMIC_CAPABILITY);
5420 }
5421
5422 DEFUN (no_neighbor_capability_dynamic,
5423 no_neighbor_capability_dynamic_cmd,
5424 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5425 NO_STR
5426 NEIGHBOR_STR
5427 NEIGHBOR_ADDR_STR2
5428 "Advertise capability to the peer\n"
5429 "Advertise dynamic capability to this neighbor\n")
5430 {
5431 int idx_peer = 2;
5432 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5433 PEER_FLAG_DYNAMIC_CAPABILITY);
5434 }
5435
5436 /* neighbor dont-capability-negotiate */
5437 DEFUN (neighbor_dont_capability_negotiate,
5438 neighbor_dont_capability_negotiate_cmd,
5439 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5440 NEIGHBOR_STR
5441 NEIGHBOR_ADDR_STR2
5442 "Do not perform capability negotiation\n")
5443 {
5444 int idx_peer = 1;
5445 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5446 PEER_FLAG_DONT_CAPABILITY);
5447 }
5448
5449 DEFUN (no_neighbor_dont_capability_negotiate,
5450 no_neighbor_dont_capability_negotiate_cmd,
5451 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5452 NO_STR
5453 NEIGHBOR_STR
5454 NEIGHBOR_ADDR_STR2
5455 "Do not perform capability negotiation\n")
5456 {
5457 int idx_peer = 2;
5458 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5459 PEER_FLAG_DONT_CAPABILITY);
5460 }
5461
5462 /* neighbor capability extended next hop encoding */
5463 DEFUN (neighbor_capability_enhe,
5464 neighbor_capability_enhe_cmd,
5465 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5466 NEIGHBOR_STR
5467 NEIGHBOR_ADDR_STR2
5468 "Advertise capability to the peer\n"
5469 "Advertise extended next-hop capability to the peer\n")
5470 {
5471 int idx_peer = 1;
5472 struct peer *peer;
5473
5474 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5475 if (peer && peer->conf_if)
5476 return CMD_SUCCESS;
5477
5478 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5479 PEER_FLAG_CAPABILITY_ENHE);
5480 }
5481
5482 DEFUN (no_neighbor_capability_enhe,
5483 no_neighbor_capability_enhe_cmd,
5484 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5485 NO_STR
5486 NEIGHBOR_STR
5487 NEIGHBOR_ADDR_STR2
5488 "Advertise capability to the peer\n"
5489 "Advertise extended next-hop capability to the peer\n")
5490 {
5491 int idx_peer = 2;
5492 struct peer *peer;
5493
5494 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5495 if (peer && peer->conf_if) {
5496 vty_out(vty,
5497 "Peer %s cannot have capability extended-nexthop turned off\n",
5498 argv[idx_peer]->arg);
5499 return CMD_WARNING_CONFIG_FAILED;
5500 }
5501
5502 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5503 PEER_FLAG_CAPABILITY_ENHE);
5504 }
5505
5506 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5507 afi_t afi, safi_t safi, uint32_t flag,
5508 int set)
5509 {
5510 int ret;
5511 struct peer *peer;
5512
5513 peer = peer_and_group_lookup_vty(vty, peer_str);
5514 if (!peer)
5515 return CMD_WARNING_CONFIG_FAILED;
5516
5517 if (set)
5518 ret = peer_af_flag_set(peer, afi, safi, flag);
5519 else
5520 ret = peer_af_flag_unset(peer, afi, safi, flag);
5521
5522 return bgp_vty_return(vty, ret);
5523 }
5524
5525 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5526 afi_t afi, safi_t safi, uint32_t flag)
5527 {
5528 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5529 }
5530
5531 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5532 afi_t afi, safi_t safi, uint32_t flag)
5533 {
5534 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5535 }
5536
5537 /* neighbor capability orf prefix-list. */
5538 DEFUN (neighbor_capability_orf_prefix,
5539 neighbor_capability_orf_prefix_cmd,
5540 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Advertise capability to the peer\n"
5544 "Advertise ORF capability to the peer\n"
5545 "Advertise prefixlist ORF capability to this neighbor\n"
5546 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5547 "Capability to RECEIVE the ORF from this neighbor\n"
5548 "Capability to SEND the ORF to this neighbor\n")
5549 {
5550 int idx_send_recv = 5;
5551 char *peer_str = argv[1]->arg;
5552 struct peer *peer;
5553 afi_t afi = bgp_node_afi(vty);
5554 safi_t safi = bgp_node_safi(vty);
5555
5556 peer = peer_and_group_lookup_vty(vty, peer_str);
5557 if (!peer)
5558 return CMD_WARNING_CONFIG_FAILED;
5559
5560 if (strmatch(argv[idx_send_recv]->text, "send"))
5561 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5562 PEER_FLAG_ORF_PREFIX_SM);
5563
5564 if (strmatch(argv[idx_send_recv]->text, "receive"))
5565 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5566 PEER_FLAG_ORF_PREFIX_RM);
5567
5568 if (strmatch(argv[idx_send_recv]->text, "both"))
5569 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5570 PEER_FLAG_ORF_PREFIX_SM)
5571 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5572 PEER_FLAG_ORF_PREFIX_RM);
5573
5574 return CMD_WARNING_CONFIG_FAILED;
5575 }
5576
5577 ALIAS_HIDDEN(
5578 neighbor_capability_orf_prefix,
5579 neighbor_capability_orf_prefix_hidden_cmd,
5580 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5582 "Advertise capability to the peer\n"
5583 "Advertise ORF capability to the peer\n"
5584 "Advertise prefixlist ORF capability to this neighbor\n"
5585 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5586 "Capability to RECEIVE the ORF from this neighbor\n"
5587 "Capability to SEND the ORF to this neighbor\n")
5588
5589 DEFUN (no_neighbor_capability_orf_prefix,
5590 no_neighbor_capability_orf_prefix_cmd,
5591 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5592 NO_STR
5593 NEIGHBOR_STR
5594 NEIGHBOR_ADDR_STR2
5595 "Advertise capability to the peer\n"
5596 "Advertise ORF capability to the peer\n"
5597 "Advertise prefixlist ORF capability to this neighbor\n"
5598 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5599 "Capability to RECEIVE the ORF from this neighbor\n"
5600 "Capability to SEND the ORF to this neighbor\n")
5601 {
5602 int idx_send_recv = 6;
5603 char *peer_str = argv[2]->arg;
5604 struct peer *peer;
5605 afi_t afi = bgp_node_afi(vty);
5606 safi_t safi = bgp_node_safi(vty);
5607
5608 peer = peer_and_group_lookup_vty(vty, peer_str);
5609 if (!peer)
5610 return CMD_WARNING_CONFIG_FAILED;
5611
5612 if (strmatch(argv[idx_send_recv]->text, "send"))
5613 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5614 PEER_FLAG_ORF_PREFIX_SM);
5615
5616 if (strmatch(argv[idx_send_recv]->text, "receive"))
5617 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5618 PEER_FLAG_ORF_PREFIX_RM);
5619
5620 if (strmatch(argv[idx_send_recv]->text, "both"))
5621 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5622 PEER_FLAG_ORF_PREFIX_SM)
5623 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5624 PEER_FLAG_ORF_PREFIX_RM);
5625
5626 return CMD_WARNING_CONFIG_FAILED;
5627 }
5628
5629 ALIAS_HIDDEN(
5630 no_neighbor_capability_orf_prefix,
5631 no_neighbor_capability_orf_prefix_hidden_cmd,
5632 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5633 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5634 "Advertise capability to the peer\n"
5635 "Advertise ORF capability to the peer\n"
5636 "Advertise prefixlist ORF capability to this neighbor\n"
5637 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5638 "Capability to RECEIVE the ORF from this neighbor\n"
5639 "Capability to SEND the ORF to this neighbor\n")
5640
5641 /* neighbor next-hop-self. */
5642 DEFUN (neighbor_nexthop_self,
5643 neighbor_nexthop_self_cmd,
5644 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5645 NEIGHBOR_STR
5646 NEIGHBOR_ADDR_STR2
5647 "Disable the next hop calculation for this neighbor\n")
5648 {
5649 int idx_peer = 1;
5650 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5651 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5652 }
5653
5654 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5655 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5656 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5657 "Disable the next hop calculation for this neighbor\n")
5658
5659 /* neighbor next-hop-self. */
5660 DEFUN (neighbor_nexthop_self_force,
5661 neighbor_nexthop_self_force_cmd,
5662 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5663 NEIGHBOR_STR
5664 NEIGHBOR_ADDR_STR2
5665 "Disable the next hop calculation for this neighbor\n"
5666 "Set the next hop to self for reflected routes\n")
5667 {
5668 int idx_peer = 1;
5669 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5670 bgp_node_safi(vty),
5671 PEER_FLAG_FORCE_NEXTHOP_SELF);
5672 }
5673
5674 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5675 neighbor_nexthop_self_force_hidden_cmd,
5676 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5677 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5678 "Disable the next hop calculation for this neighbor\n"
5679 "Set the next hop to self for reflected routes\n")
5680
5681 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5682 neighbor_nexthop_self_all_hidden_cmd,
5683 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5684 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5685 "Disable the next hop calculation for this neighbor\n"
5686 "Set the next hop to self for reflected routes\n")
5687
5688 DEFUN (no_neighbor_nexthop_self,
5689 no_neighbor_nexthop_self_cmd,
5690 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5691 NO_STR
5692 NEIGHBOR_STR
5693 NEIGHBOR_ADDR_STR2
5694 "Disable the next hop calculation for this neighbor\n")
5695 {
5696 int idx_peer = 2;
5697 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5698 bgp_node_afi(vty), bgp_node_safi(vty),
5699 PEER_FLAG_NEXTHOP_SELF);
5700 }
5701
5702 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5703 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5704 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5705 "Disable the next hop calculation for this neighbor\n")
5706
5707 DEFUN (no_neighbor_nexthop_self_force,
5708 no_neighbor_nexthop_self_force_cmd,
5709 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5710 NO_STR
5711 NEIGHBOR_STR
5712 NEIGHBOR_ADDR_STR2
5713 "Disable the next hop calculation for this neighbor\n"
5714 "Set the next hop to self for reflected routes\n")
5715 {
5716 int idx_peer = 2;
5717 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5718 bgp_node_afi(vty), bgp_node_safi(vty),
5719 PEER_FLAG_FORCE_NEXTHOP_SELF);
5720 }
5721
5722 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5723 no_neighbor_nexthop_self_force_hidden_cmd,
5724 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5725 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5726 "Disable the next hop calculation for this neighbor\n"
5727 "Set the next hop to self for reflected routes\n")
5728
5729 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5730 no_neighbor_nexthop_self_all_hidden_cmd,
5731 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5732 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5733 "Disable the next hop calculation for this neighbor\n"
5734 "Set the next hop to self for reflected routes\n")
5735
5736 /* neighbor as-override */
5737 DEFUN (neighbor_as_override,
5738 neighbor_as_override_cmd,
5739 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5740 NEIGHBOR_STR
5741 NEIGHBOR_ADDR_STR2
5742 "Override ASNs in outbound updates if aspath equals remote-as\n")
5743 {
5744 int idx_peer = 1;
5745 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5746 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5747 }
5748
5749 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5750 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5751 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5752 "Override ASNs in outbound updates if aspath equals remote-as\n")
5753
5754 DEFUN (no_neighbor_as_override,
5755 no_neighbor_as_override_cmd,
5756 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5757 NO_STR
5758 NEIGHBOR_STR
5759 NEIGHBOR_ADDR_STR2
5760 "Override ASNs in outbound updates if aspath equals remote-as\n")
5761 {
5762 int idx_peer = 2;
5763 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5764 bgp_node_afi(vty), bgp_node_safi(vty),
5765 PEER_FLAG_AS_OVERRIDE);
5766 }
5767
5768 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5769 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5770 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5771 "Override ASNs in outbound updates if aspath equals remote-as\n")
5772
5773 /* neighbor remove-private-AS. */
5774 DEFUN (neighbor_remove_private_as,
5775 neighbor_remove_private_as_cmd,
5776 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5777 NEIGHBOR_STR
5778 NEIGHBOR_ADDR_STR2
5779 "Remove private ASNs in outbound updates\n")
5780 {
5781 int idx_peer = 1;
5782 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5783 bgp_node_safi(vty),
5784 PEER_FLAG_REMOVE_PRIVATE_AS);
5785 }
5786
5787 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5788 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5789 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5790 "Remove private ASNs in outbound updates\n")
5791
5792 DEFUN (neighbor_remove_private_as_all,
5793 neighbor_remove_private_as_all_cmd,
5794 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5795 NEIGHBOR_STR
5796 NEIGHBOR_ADDR_STR2
5797 "Remove private ASNs in outbound updates\n"
5798 "Apply to all AS numbers\n")
5799 {
5800 int idx_peer = 1;
5801 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5802 bgp_node_safi(vty),
5803 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5804 }
5805
5806 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5807 neighbor_remove_private_as_all_hidden_cmd,
5808 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5809 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5810 "Remove private ASNs in outbound updates\n"
5811 "Apply to all AS numbers")
5812
5813 DEFUN (neighbor_remove_private_as_replace_as,
5814 neighbor_remove_private_as_replace_as_cmd,
5815 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
5818 "Remove private ASNs in outbound updates\n"
5819 "Replace private ASNs with our ASN in outbound updates\n")
5820 {
5821 int idx_peer = 1;
5822 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5823 bgp_node_safi(vty),
5824 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5825 }
5826
5827 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5828 neighbor_remove_private_as_replace_as_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Remove private ASNs in outbound updates\n"
5832 "Replace private ASNs with our ASN in outbound updates\n")
5833
5834 DEFUN (neighbor_remove_private_as_all_replace_as,
5835 neighbor_remove_private_as_all_replace_as_cmd,
5836 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5837 NEIGHBOR_STR
5838 NEIGHBOR_ADDR_STR2
5839 "Remove private ASNs in outbound updates\n"
5840 "Apply to all AS numbers\n"
5841 "Replace private ASNs with our ASN in outbound updates\n")
5842 {
5843 int idx_peer = 1;
5844 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5845 bgp_node_safi(vty),
5846 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5847 }
5848
5849 ALIAS_HIDDEN(
5850 neighbor_remove_private_as_all_replace_as,
5851 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5852 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5853 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5854 "Remove private ASNs in outbound updates\n"
5855 "Apply to all AS numbers\n"
5856 "Replace private ASNs with our ASN in outbound updates\n")
5857
5858 DEFUN (no_neighbor_remove_private_as,
5859 no_neighbor_remove_private_as_cmd,
5860 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5861 NO_STR
5862 NEIGHBOR_STR
5863 NEIGHBOR_ADDR_STR2
5864 "Remove private ASNs in outbound updates\n")
5865 {
5866 int idx_peer = 2;
5867 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5868 bgp_node_afi(vty), bgp_node_safi(vty),
5869 PEER_FLAG_REMOVE_PRIVATE_AS);
5870 }
5871
5872 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5873 no_neighbor_remove_private_as_hidden_cmd,
5874 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5875 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5876 "Remove private ASNs in outbound updates\n")
5877
5878 DEFUN (no_neighbor_remove_private_as_all,
5879 no_neighbor_remove_private_as_all_cmd,
5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
5884 "Remove private ASNs in outbound updates\n"
5885 "Apply to all AS numbers\n")
5886 {
5887 int idx_peer = 2;
5888 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5889 bgp_node_afi(vty), bgp_node_safi(vty),
5890 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5891 }
5892
5893 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5894 no_neighbor_remove_private_as_all_hidden_cmd,
5895 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5896 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5897 "Remove private ASNs in outbound updates\n"
5898 "Apply to all AS numbers\n")
5899
5900 DEFUN (no_neighbor_remove_private_as_replace_as,
5901 no_neighbor_remove_private_as_replace_as_cmd,
5902 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5903 NO_STR
5904 NEIGHBOR_STR
5905 NEIGHBOR_ADDR_STR2
5906 "Remove private ASNs in outbound updates\n"
5907 "Replace private ASNs with our ASN in outbound updates\n")
5908 {
5909 int idx_peer = 2;
5910 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5911 bgp_node_afi(vty), bgp_node_safi(vty),
5912 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5913 }
5914
5915 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5916 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5917 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5918 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5919 "Remove private ASNs in outbound updates\n"
5920 "Replace private ASNs with our ASN in outbound updates\n")
5921
5922 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5923 no_neighbor_remove_private_as_all_replace_as_cmd,
5924 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5925 NO_STR
5926 NEIGHBOR_STR
5927 NEIGHBOR_ADDR_STR2
5928 "Remove private ASNs in outbound updates\n"
5929 "Apply to all AS numbers\n"
5930 "Replace private ASNs with our ASN in outbound updates\n")
5931 {
5932 int idx_peer = 2;
5933 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5934 bgp_node_afi(vty), bgp_node_safi(vty),
5935 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5936 }
5937
5938 ALIAS_HIDDEN(
5939 no_neighbor_remove_private_as_all_replace_as,
5940 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5941 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5942 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5943 "Remove private ASNs in outbound updates\n"
5944 "Apply to all AS numbers\n"
5945 "Replace private ASNs with our ASN in outbound updates\n")
5946
5947
5948 /* neighbor send-community. */
5949 DEFUN (neighbor_send_community,
5950 neighbor_send_community_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Send Community attribute to this neighbor\n")
5955 {
5956 int idx_peer = 1;
5957
5958 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5959 bgp_node_safi(vty),
5960 PEER_FLAG_SEND_COMMUNITY);
5961 }
5962
5963 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5964 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5966 "Send Community attribute to this neighbor\n")
5967
5968 DEFUN (no_neighbor_send_community,
5969 no_neighbor_send_community_cmd,
5970 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5971 NO_STR
5972 NEIGHBOR_STR
5973 NEIGHBOR_ADDR_STR2
5974 "Send Community attribute to this neighbor\n")
5975 {
5976 int idx_peer = 2;
5977
5978 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5979 bgp_node_afi(vty), bgp_node_safi(vty),
5980 PEER_FLAG_SEND_COMMUNITY);
5981 }
5982
5983 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5984 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5985 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5986 "Send Community attribute to this neighbor\n")
5987
5988 /* neighbor send-community extended. */
5989 DEFUN (neighbor_send_community_type,
5990 neighbor_send_community_type_cmd,
5991 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5992 NEIGHBOR_STR
5993 NEIGHBOR_ADDR_STR2
5994 "Send Community attribute to this neighbor\n"
5995 "Send Standard and Extended Community attributes\n"
5996 "Send Standard, Large and Extended Community attributes\n"
5997 "Send Extended Community attributes\n"
5998 "Send Standard Community attributes\n"
5999 "Send Large Community attributes\n")
6000 {
6001 const char *type = argv[argc - 1]->text;
6002 char *peer_str = argv[1]->arg;
6003 struct peer *peer;
6004 afi_t afi = bgp_node_afi(vty);
6005 safi_t safi = bgp_node_safi(vty);
6006
6007 peer = peer_and_group_lookup_vty(vty, peer_str);
6008 if (!peer)
6009 return CMD_WARNING_CONFIG_FAILED;
6010
6011 if (strmatch(type, "standard"))
6012 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6013 PEER_FLAG_SEND_COMMUNITY);
6014
6015 if (strmatch(type, "extended"))
6016 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6017 PEER_FLAG_SEND_EXT_COMMUNITY);
6018
6019 if (strmatch(type, "large"))
6020 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6021 PEER_FLAG_SEND_LARGE_COMMUNITY);
6022
6023 if (strmatch(type, "both")) {
6024 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6025 PEER_FLAG_SEND_COMMUNITY)
6026 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6027 PEER_FLAG_SEND_EXT_COMMUNITY);
6028 }
6029 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6030 PEER_FLAG_SEND_COMMUNITY)
6031 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6032 PEER_FLAG_SEND_EXT_COMMUNITY)
6033 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6034 PEER_FLAG_SEND_LARGE_COMMUNITY);
6035 }
6036
6037 ALIAS_HIDDEN(
6038 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6039 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6040 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6041 "Send Community attribute to this neighbor\n"
6042 "Send Standard and Extended Community attributes\n"
6043 "Send Standard, Large and Extended Community attributes\n"
6044 "Send Extended Community attributes\n"
6045 "Send Standard Community attributes\n"
6046 "Send Large Community attributes\n")
6047
6048 DEFUN (no_neighbor_send_community_type,
6049 no_neighbor_send_community_type_cmd,
6050 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6051 NO_STR
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Send Community attribute to this neighbor\n"
6055 "Send Standard and Extended Community attributes\n"
6056 "Send Standard, Large and Extended Community attributes\n"
6057 "Send Extended Community attributes\n"
6058 "Send Standard Community attributes\n"
6059 "Send Large Community attributes\n")
6060 {
6061 const char *type = argv[argc - 1]->text;
6062 char *peer_str = argv[2]->arg;
6063 struct peer *peer;
6064 afi_t afi = bgp_node_afi(vty);
6065 safi_t safi = bgp_node_safi(vty);
6066
6067 peer = peer_and_group_lookup_vty(vty, peer_str);
6068 if (!peer)
6069 return CMD_WARNING_CONFIG_FAILED;
6070
6071 if (strmatch(type, "standard"))
6072 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6073 PEER_FLAG_SEND_COMMUNITY);
6074
6075 if (strmatch(type, "extended"))
6076 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6077 PEER_FLAG_SEND_EXT_COMMUNITY);
6078
6079 if (strmatch(type, "large"))
6080 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6081 PEER_FLAG_SEND_LARGE_COMMUNITY);
6082
6083 if (strmatch(type, "both")) {
6084
6085 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6086 PEER_FLAG_SEND_COMMUNITY)
6087 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6088 PEER_FLAG_SEND_EXT_COMMUNITY);
6089 }
6090
6091 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6092 PEER_FLAG_SEND_COMMUNITY)
6093 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6094 PEER_FLAG_SEND_EXT_COMMUNITY)
6095 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6096 PEER_FLAG_SEND_LARGE_COMMUNITY);
6097 }
6098
6099 ALIAS_HIDDEN(
6100 no_neighbor_send_community_type,
6101 no_neighbor_send_community_type_hidden_cmd,
6102 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6103 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6104 "Send Community attribute to this neighbor\n"
6105 "Send Standard and Extended Community attributes\n"
6106 "Send Standard, Large and Extended Community attributes\n"
6107 "Send Extended Community attributes\n"
6108 "Send Standard Community attributes\n"
6109 "Send Large Community attributes\n")
6110
6111 /* neighbor soft-reconfig. */
6112 DEFUN (neighbor_soft_reconfiguration,
6113 neighbor_soft_reconfiguration_cmd,
6114 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6115 NEIGHBOR_STR
6116 NEIGHBOR_ADDR_STR2
6117 "Per neighbor soft reconfiguration\n"
6118 "Allow inbound soft reconfiguration for this neighbor\n")
6119 {
6120 int idx_peer = 1;
6121 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6122 bgp_node_safi(vty),
6123 PEER_FLAG_SOFT_RECONFIG);
6124 }
6125
6126 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6127 neighbor_soft_reconfiguration_hidden_cmd,
6128 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6130 "Per neighbor soft reconfiguration\n"
6131 "Allow inbound soft reconfiguration for this neighbor\n")
6132
6133 DEFUN (no_neighbor_soft_reconfiguration,
6134 no_neighbor_soft_reconfiguration_cmd,
6135 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6136 NO_STR
6137 NEIGHBOR_STR
6138 NEIGHBOR_ADDR_STR2
6139 "Per neighbor soft reconfiguration\n"
6140 "Allow inbound soft reconfiguration for this neighbor\n")
6141 {
6142 int idx_peer = 2;
6143 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6144 bgp_node_afi(vty), bgp_node_safi(vty),
6145 PEER_FLAG_SOFT_RECONFIG);
6146 }
6147
6148 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6149 no_neighbor_soft_reconfiguration_hidden_cmd,
6150 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6152 "Per neighbor soft reconfiguration\n"
6153 "Allow inbound soft reconfiguration for this neighbor\n")
6154
6155 DEFUN (neighbor_route_reflector_client,
6156 neighbor_route_reflector_client_cmd,
6157 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6158 NEIGHBOR_STR
6159 NEIGHBOR_ADDR_STR2
6160 "Configure a neighbor as Route Reflector client\n")
6161 {
6162 int idx_peer = 1;
6163 struct peer *peer;
6164
6165
6166 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6167 if (!peer)
6168 return CMD_WARNING_CONFIG_FAILED;
6169
6170 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6171 bgp_node_safi(vty),
6172 PEER_FLAG_REFLECTOR_CLIENT);
6173 }
6174
6175 ALIAS_HIDDEN(neighbor_route_reflector_client,
6176 neighbor_route_reflector_client_hidden_cmd,
6177 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6178 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6179 "Configure a neighbor as Route Reflector client\n")
6180
6181 DEFUN (no_neighbor_route_reflector_client,
6182 no_neighbor_route_reflector_client_cmd,
6183 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6184 NO_STR
6185 NEIGHBOR_STR
6186 NEIGHBOR_ADDR_STR2
6187 "Configure a neighbor as Route Reflector client\n")
6188 {
6189 int idx_peer = 2;
6190 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6191 bgp_node_afi(vty), bgp_node_safi(vty),
6192 PEER_FLAG_REFLECTOR_CLIENT);
6193 }
6194
6195 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6196 no_neighbor_route_reflector_client_hidden_cmd,
6197 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6198 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6199 "Configure a neighbor as Route Reflector client\n")
6200
6201 /* neighbor route-server-client. */
6202 DEFUN (neighbor_route_server_client,
6203 neighbor_route_server_client_cmd,
6204 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6205 NEIGHBOR_STR
6206 NEIGHBOR_ADDR_STR2
6207 "Configure a neighbor as Route Server client\n")
6208 {
6209 int idx_peer = 1;
6210 struct peer *peer;
6211
6212 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6213 if (!peer)
6214 return CMD_WARNING_CONFIG_FAILED;
6215 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6216 bgp_node_safi(vty),
6217 PEER_FLAG_RSERVER_CLIENT);
6218 }
6219
6220 ALIAS_HIDDEN(neighbor_route_server_client,
6221 neighbor_route_server_client_hidden_cmd,
6222 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6223 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6224 "Configure a neighbor as Route Server client\n")
6225
6226 DEFUN (no_neighbor_route_server_client,
6227 no_neighbor_route_server_client_cmd,
6228 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6229 NO_STR
6230 NEIGHBOR_STR
6231 NEIGHBOR_ADDR_STR2
6232 "Configure a neighbor as Route Server client\n")
6233 {
6234 int idx_peer = 2;
6235 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6236 bgp_node_afi(vty), bgp_node_safi(vty),
6237 PEER_FLAG_RSERVER_CLIENT);
6238 }
6239
6240 ALIAS_HIDDEN(no_neighbor_route_server_client,
6241 no_neighbor_route_server_client_hidden_cmd,
6242 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6243 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6244 "Configure a neighbor as Route Server client\n")
6245
6246 DEFUN (neighbor_nexthop_local_unchanged,
6247 neighbor_nexthop_local_unchanged_cmd,
6248 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6249 NEIGHBOR_STR
6250 NEIGHBOR_ADDR_STR2
6251 "Configure treatment of outgoing link-local nexthop attribute\n"
6252 "Leave link-local nexthop unchanged for this peer\n")
6253 {
6254 int idx_peer = 1;
6255 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6256 bgp_node_safi(vty),
6257 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6258 }
6259
6260 DEFUN (no_neighbor_nexthop_local_unchanged,
6261 no_neighbor_nexthop_local_unchanged_cmd,
6262 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6263 NO_STR
6264 NEIGHBOR_STR
6265 NEIGHBOR_ADDR_STR2
6266 "Configure treatment of outgoing link-local-nexthop attribute\n"
6267 "Leave link-local nexthop unchanged for this peer\n")
6268 {
6269 int idx_peer = 2;
6270 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6271 bgp_node_afi(vty), bgp_node_safi(vty),
6272 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6273 }
6274
6275 DEFUN (neighbor_attr_unchanged,
6276 neighbor_attr_unchanged_cmd,
6277 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6278 NEIGHBOR_STR
6279 NEIGHBOR_ADDR_STR2
6280 "BGP attribute is propagated unchanged to this neighbor\n"
6281 "As-path attribute\n"
6282 "Nexthop attribute\n"
6283 "Med attribute\n")
6284 {
6285 int idx = 0;
6286 char *peer_str = argv[1]->arg;
6287 struct peer *peer;
6288 bool aspath = false;
6289 bool nexthop = false;
6290 bool med = false;
6291 afi_t afi = bgp_node_afi(vty);
6292 safi_t safi = bgp_node_safi(vty);
6293 int ret = 0;
6294
6295 peer = peer_and_group_lookup_vty(vty, peer_str);
6296 if (!peer)
6297 return CMD_WARNING_CONFIG_FAILED;
6298
6299 if (argv_find(argv, argc, "as-path", &idx))
6300 aspath = true;
6301
6302 idx = 0;
6303 if (argv_find(argv, argc, "next-hop", &idx))
6304 nexthop = true;
6305
6306 idx = 0;
6307 if (argv_find(argv, argc, "med", &idx))
6308 med = true;
6309
6310 /* no flags means all of them! */
6311 if (!aspath && !nexthop && !med) {
6312 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6313 PEER_FLAG_AS_PATH_UNCHANGED);
6314 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6315 PEER_FLAG_NEXTHOP_UNCHANGED);
6316 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6317 PEER_FLAG_MED_UNCHANGED);
6318 } else {
6319 if (!aspath) {
6320 if (peer_af_flag_check(peer, afi, safi,
6321 PEER_FLAG_AS_PATH_UNCHANGED)) {
6322 ret |= peer_af_flag_unset_vty(
6323 vty, peer_str, afi, safi,
6324 PEER_FLAG_AS_PATH_UNCHANGED);
6325 }
6326 } else
6327 ret |= peer_af_flag_set_vty(
6328 vty, peer_str, afi, safi,
6329 PEER_FLAG_AS_PATH_UNCHANGED);
6330
6331 if (!nexthop) {
6332 if (peer_af_flag_check(peer, afi, safi,
6333 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6334 ret |= peer_af_flag_unset_vty(
6335 vty, peer_str, afi, safi,
6336 PEER_FLAG_NEXTHOP_UNCHANGED);
6337 }
6338 } else
6339 ret |= peer_af_flag_set_vty(
6340 vty, peer_str, afi, safi,
6341 PEER_FLAG_NEXTHOP_UNCHANGED);
6342
6343 if (!med) {
6344 if (peer_af_flag_check(peer, afi, safi,
6345 PEER_FLAG_MED_UNCHANGED)) {
6346 ret |= peer_af_flag_unset_vty(
6347 vty, peer_str, afi, safi,
6348 PEER_FLAG_MED_UNCHANGED);
6349 }
6350 } else
6351 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6352 PEER_FLAG_MED_UNCHANGED);
6353 }
6354
6355 return ret;
6356 }
6357
6358 ALIAS_HIDDEN(
6359 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6360 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6361 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6362 "BGP attribute is propagated unchanged to this neighbor\n"
6363 "As-path attribute\n"
6364 "Nexthop attribute\n"
6365 "Med attribute\n")
6366
6367 DEFUN (no_neighbor_attr_unchanged,
6368 no_neighbor_attr_unchanged_cmd,
6369 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6370 NO_STR
6371 NEIGHBOR_STR
6372 NEIGHBOR_ADDR_STR2
6373 "BGP attribute is propagated unchanged to this neighbor\n"
6374 "As-path attribute\n"
6375 "Nexthop attribute\n"
6376 "Med attribute\n")
6377 {
6378 int idx = 0;
6379 char *peer_str = argv[2]->arg;
6380 struct peer *peer;
6381 bool aspath = false;
6382 bool nexthop = false;
6383 bool med = false;
6384 afi_t afi = bgp_node_afi(vty);
6385 safi_t safi = bgp_node_safi(vty);
6386 int ret = 0;
6387
6388 peer = peer_and_group_lookup_vty(vty, peer_str);
6389 if (!peer)
6390 return CMD_WARNING_CONFIG_FAILED;
6391
6392 if (argv_find(argv, argc, "as-path", &idx))
6393 aspath = true;
6394
6395 idx = 0;
6396 if (argv_find(argv, argc, "next-hop", &idx))
6397 nexthop = true;
6398
6399 idx = 0;
6400 if (argv_find(argv, argc, "med", &idx))
6401 med = true;
6402
6403 if (!aspath && !nexthop && !med) // no flags means all of them!
6404 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6405 PEER_FLAG_AS_PATH_UNCHANGED)
6406 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6407 PEER_FLAG_NEXTHOP_UNCHANGED)
6408 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6409 PEER_FLAG_MED_UNCHANGED);
6410
6411 if (aspath)
6412 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6413 PEER_FLAG_AS_PATH_UNCHANGED);
6414
6415 if (nexthop)
6416 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6417 PEER_FLAG_NEXTHOP_UNCHANGED);
6418
6419 if (med)
6420 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6421 PEER_FLAG_MED_UNCHANGED);
6422
6423 return ret;
6424 }
6425
6426 ALIAS_HIDDEN(
6427 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6428 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6429 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6430 "BGP attribute is propagated unchanged to this neighbor\n"
6431 "As-path attribute\n"
6432 "Nexthop attribute\n"
6433 "Med attribute\n")
6434
6435 /* EBGP multihop configuration. */
6436 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6437 const char *ttl_str)
6438 {
6439 struct peer *peer;
6440 unsigned int ttl;
6441
6442 peer = peer_and_group_lookup_vty(vty, ip_str);
6443 if (!peer)
6444 return CMD_WARNING_CONFIG_FAILED;
6445
6446 if (peer->conf_if)
6447 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6448
6449 if (!ttl_str)
6450 ttl = MAXTTL;
6451 else
6452 ttl = strtoul(ttl_str, NULL, 10);
6453
6454 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6455 }
6456
6457 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6458 {
6459 struct peer *peer;
6460
6461 peer = peer_and_group_lookup_vty(vty, ip_str);
6462 if (!peer)
6463 return CMD_WARNING_CONFIG_FAILED;
6464
6465 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6466 }
6467
6468 /* neighbor ebgp-multihop. */
6469 DEFUN (neighbor_ebgp_multihop,
6470 neighbor_ebgp_multihop_cmd,
6471 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6472 NEIGHBOR_STR
6473 NEIGHBOR_ADDR_STR2
6474 "Allow EBGP neighbors not on directly connected networks\n")
6475 {
6476 int idx_peer = 1;
6477 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6478 }
6479
6480 DEFUN (neighbor_ebgp_multihop_ttl,
6481 neighbor_ebgp_multihop_ttl_cmd,
6482 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6483 NEIGHBOR_STR
6484 NEIGHBOR_ADDR_STR2
6485 "Allow EBGP neighbors not on directly connected networks\n"
6486 "maximum hop count\n")
6487 {
6488 int idx_peer = 1;
6489 int idx_number = 3;
6490 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6491 argv[idx_number]->arg);
6492 }
6493
6494 DEFUN (no_neighbor_ebgp_multihop,
6495 no_neighbor_ebgp_multihop_cmd,
6496 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6497 NO_STR
6498 NEIGHBOR_STR
6499 NEIGHBOR_ADDR_STR2
6500 "Allow EBGP neighbors not on directly connected networks\n"
6501 "maximum hop count\n")
6502 {
6503 int idx_peer = 2;
6504 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6505 }
6506
6507 static uint8_t get_role_by_name(const char *role_str)
6508 {
6509 if (strncmp(role_str, "peer", 2) == 0)
6510 return ROLE_PEER;
6511 if (strncmp(role_str, "provider", 2) == 0)
6512 return ROLE_PROVIDER;
6513 if (strncmp(role_str, "customer", 2) == 0)
6514 return ROLE_CUSTOMER;
6515 if (strncmp(role_str, "rs-server", 4) == 0)
6516 return ROLE_RS_SERVER;
6517 if (strncmp(role_str, "rs-client", 4) == 0)
6518 return ROLE_RS_CLIENT;
6519 return ROLE_UNDEFINED;
6520 }
6521
6522 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6523 const char *role_str, bool strict_mode)
6524 {
6525 struct peer *peer;
6526
6527 peer = peer_and_group_lookup_vty(vty, ip_str);
6528 if (!peer)
6529 return CMD_WARNING_CONFIG_FAILED;
6530 uint8_t role = get_role_by_name(role_str);
6531
6532 if (role == ROLE_UNDEFINED)
6533 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6534 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6535 }
6536
6537 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6538 {
6539 struct peer *peer;
6540
6541 peer = peer_and_group_lookup_vty(vty, ip_str);
6542 if (!peer)
6543 return CMD_WARNING_CONFIG_FAILED;
6544 return bgp_vty_return(vty, peer_role_unset(peer));
6545 }
6546
6547 DEFPY(neighbor_role,
6548 neighbor_role_cmd,
6549 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6550 NEIGHBOR_STR
6551 NEIGHBOR_ADDR_STR2
6552 "Set session role\n"
6553 ROLE_STR)
6554 {
6555 int idx_peer = 1;
6556 int idx_role = 3;
6557
6558 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6559 false);
6560 }
6561
6562 DEFPY(neighbor_role_strict,
6563 neighbor_role_strict_cmd,
6564 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6565 NEIGHBOR_STR
6566 NEIGHBOR_ADDR_STR2
6567 "Set session role\n"
6568 ROLE_STR
6569 "Use additional restriction on peer\n")
6570 {
6571 int idx_peer = 1;
6572 int idx_role = 3;
6573
6574 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6575 true);
6576 }
6577
6578 DEFPY(no_neighbor_role,
6579 no_neighbor_role_cmd,
6580 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6581 NO_STR
6582 NEIGHBOR_STR
6583 NEIGHBOR_ADDR_STR2
6584 "Set session role\n"
6585 ROLE_STR
6586 "Use additional restriction on peer\n")
6587 {
6588 int idx_peer = 2;
6589
6590 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6591 }
6592
6593 /* disable-connected-check */
6594 DEFUN (neighbor_disable_connected_check,
6595 neighbor_disable_connected_check_cmd,
6596 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6597 NEIGHBOR_STR
6598 NEIGHBOR_ADDR_STR2
6599 "one-hop away EBGP peer using loopback address\n"
6600 "Enforce EBGP neighbors perform multihop\n")
6601 {
6602 int idx_peer = 1;
6603 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6604 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6605 }
6606
6607 DEFUN (no_neighbor_disable_connected_check,
6608 no_neighbor_disable_connected_check_cmd,
6609 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6610 NO_STR
6611 NEIGHBOR_STR
6612 NEIGHBOR_ADDR_STR2
6613 "one-hop away EBGP peer using loopback address\n"
6614 "Enforce EBGP neighbors perform multihop\n")
6615 {
6616 int idx_peer = 2;
6617 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6618 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6619 }
6620
6621 /* disable-link-bw-encoding-ieee */
6622 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6623 neighbor_disable_link_bw_encoding_ieee_cmd,
6624 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6625 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6626 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6627 {
6628 int idx_peer = 1;
6629
6630 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6631 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6632 }
6633
6634 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6635 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6636 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6637 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6638 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6639 {
6640 int idx_peer = 2;
6641
6642 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6643 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6644 }
6645
6646 /* extended-optional-parameters */
6647 DEFUN(neighbor_extended_optional_parameters,
6648 neighbor_extended_optional_parameters_cmd,
6649 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6650 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6651 "Force the extended optional parameters format for OPEN messages\n")
6652 {
6653 int idx_peer = 1;
6654
6655 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6656 PEER_FLAG_EXTENDED_OPT_PARAMS);
6657 }
6658
6659 DEFUN(no_neighbor_extended_optional_parameters,
6660 no_neighbor_extended_optional_parameters_cmd,
6661 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6662 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6663 "Force the extended optional parameters format for OPEN messages\n")
6664 {
6665 int idx_peer = 2;
6666
6667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6668 PEER_FLAG_EXTENDED_OPT_PARAMS);
6669 }
6670
6671 /* enforce-first-as */
6672 DEFUN (neighbor_enforce_first_as,
6673 neighbor_enforce_first_as_cmd,
6674 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6675 NEIGHBOR_STR
6676 NEIGHBOR_ADDR_STR2
6677 "Enforce the first AS for EBGP routes\n")
6678 {
6679 int idx_peer = 1;
6680
6681 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6682 PEER_FLAG_ENFORCE_FIRST_AS);
6683 }
6684
6685 DEFUN (no_neighbor_enforce_first_as,
6686 no_neighbor_enforce_first_as_cmd,
6687 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6688 NO_STR
6689 NEIGHBOR_STR
6690 NEIGHBOR_ADDR_STR2
6691 "Enforce the first AS for EBGP routes\n")
6692 {
6693 int idx_peer = 2;
6694
6695 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6696 PEER_FLAG_ENFORCE_FIRST_AS);
6697 }
6698
6699
6700 DEFUN (neighbor_description,
6701 neighbor_description_cmd,
6702 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6703 NEIGHBOR_STR
6704 NEIGHBOR_ADDR_STR2
6705 "Neighbor specific description\n"
6706 "Up to 80 characters describing this neighbor\n")
6707 {
6708 int idx_peer = 1;
6709 int idx_line = 3;
6710 struct peer *peer;
6711 char *str;
6712
6713 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6714 if (!peer)
6715 return CMD_WARNING_CONFIG_FAILED;
6716
6717 str = argv_concat(argv, argc, idx_line);
6718
6719 peer_description_set(peer, str);
6720
6721 XFREE(MTYPE_TMP, str);
6722
6723 return CMD_SUCCESS;
6724 }
6725
6726 DEFUN (no_neighbor_description,
6727 no_neighbor_description_cmd,
6728 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6729 NO_STR
6730 NEIGHBOR_STR
6731 NEIGHBOR_ADDR_STR2
6732 "Neighbor specific description\n")
6733 {
6734 int idx_peer = 2;
6735 struct peer *peer;
6736
6737 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6738 if (!peer)
6739 return CMD_WARNING_CONFIG_FAILED;
6740
6741 peer_description_unset(peer);
6742
6743 return CMD_SUCCESS;
6744 }
6745
6746 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6747 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6748 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6749 "Neighbor specific description\n"
6750 "Up to 80 characters describing this neighbor\n")
6751
6752 /* Neighbor update-source. */
6753 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6754 const char *source_str)
6755 {
6756 struct peer *peer;
6757 struct prefix p;
6758 union sockunion su;
6759
6760 peer = peer_and_group_lookup_vty(vty, peer_str);
6761 if (!peer)
6762 return CMD_WARNING_CONFIG_FAILED;
6763
6764 if (peer->conf_if)
6765 return CMD_WARNING;
6766
6767 if (source_str) {
6768 if (str2sockunion(source_str, &su) == 0)
6769 peer_update_source_addr_set(peer, &su);
6770 else {
6771 if (str2prefix(source_str, &p)) {
6772 vty_out(vty,
6773 "%% Invalid update-source, remove prefix length \n");
6774 return CMD_WARNING_CONFIG_FAILED;
6775 } else
6776 peer_update_source_if_set(peer, source_str);
6777 }
6778 } else
6779 peer_update_source_unset(peer);
6780
6781 return CMD_SUCCESS;
6782 }
6783
6784 #define BGP_UPDATE_SOURCE_HELP_STR \
6785 "IPv4 address\n" \
6786 "IPv6 address\n" \
6787 "Interface name (requires zebra to be running)\n"
6788
6789 DEFUN (neighbor_update_source,
6790 neighbor_update_source_cmd,
6791 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6792 NEIGHBOR_STR
6793 NEIGHBOR_ADDR_STR2
6794 "Source of routing updates\n"
6795 BGP_UPDATE_SOURCE_HELP_STR)
6796 {
6797 int idx_peer = 1;
6798 int idx_peer_2 = 3;
6799 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6800 argv[idx_peer_2]->arg);
6801 }
6802
6803 DEFUN (no_neighbor_update_source,
6804 no_neighbor_update_source_cmd,
6805 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6806 NO_STR
6807 NEIGHBOR_STR
6808 NEIGHBOR_ADDR_STR2
6809 "Source of routing updates\n"
6810 BGP_UPDATE_SOURCE_HELP_STR)
6811 {
6812 int idx_peer = 2;
6813 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6814 }
6815
6816 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6817 afi_t afi, safi_t safi,
6818 const char *rmap, int set)
6819 {
6820 int ret;
6821 struct peer *peer;
6822 struct route_map *route_map = NULL;
6823
6824 peer = peer_and_group_lookup_vty(vty, peer_str);
6825 if (!peer)
6826 return CMD_WARNING_CONFIG_FAILED;
6827
6828 if (set) {
6829 if (rmap)
6830 route_map = route_map_lookup_warn_noexist(vty, rmap);
6831 ret = peer_default_originate_set(peer, afi, safi,
6832 rmap, route_map);
6833 } else
6834 ret = peer_default_originate_unset(peer, afi, safi);
6835
6836 return bgp_vty_return(vty, ret);
6837 }
6838
6839 /* neighbor default-originate. */
6840 DEFUN (neighbor_default_originate,
6841 neighbor_default_originate_cmd,
6842 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6843 NEIGHBOR_STR
6844 NEIGHBOR_ADDR_STR2
6845 "Originate default route to this neighbor\n")
6846 {
6847 int idx_peer = 1;
6848 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6849 bgp_node_afi(vty),
6850 bgp_node_safi(vty), NULL, 1);
6851 }
6852
6853 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6854 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6856 "Originate default route to this neighbor\n")
6857
6858 DEFUN (neighbor_default_originate_rmap,
6859 neighbor_default_originate_rmap_cmd,
6860 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6861 NEIGHBOR_STR
6862 NEIGHBOR_ADDR_STR2
6863 "Originate default route to this neighbor\n"
6864 "Route-map to specify criteria to originate default\n"
6865 "route-map name\n")
6866 {
6867 int idx_peer = 1;
6868 int idx_word = 4;
6869 return peer_default_originate_set_vty(
6870 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6871 argv[idx_word]->arg, 1);
6872 }
6873
6874 ALIAS_HIDDEN(
6875 neighbor_default_originate_rmap,
6876 neighbor_default_originate_rmap_hidden_cmd,
6877 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6878 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6879 "Originate default route to this neighbor\n"
6880 "Route-map to specify criteria to originate default\n"
6881 "route-map name\n")
6882
6883 DEFUN (no_neighbor_default_originate,
6884 no_neighbor_default_originate_cmd,
6885 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6886 NO_STR
6887 NEIGHBOR_STR
6888 NEIGHBOR_ADDR_STR2
6889 "Originate default route to this neighbor\n"
6890 "Route-map to specify criteria to originate default\n"
6891 "route-map name\n")
6892 {
6893 int idx_peer = 2;
6894 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6895 bgp_node_afi(vty),
6896 bgp_node_safi(vty), NULL, 0);
6897 }
6898
6899 ALIAS_HIDDEN(
6900 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6901 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6902 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6903 "Originate default route to this neighbor\n"
6904 "Route-map to specify criteria to originate default\n"
6905 "route-map name\n")
6906
6907
6908 /* Set neighbor's BGP port. */
6909 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6910 const char *port_str)
6911 {
6912 struct peer *peer;
6913 uint16_t port;
6914 struct servent *sp;
6915
6916 peer = peer_and_group_lookup_vty(vty, ip_str);
6917 if (!peer)
6918 return CMD_WARNING_CONFIG_FAILED;
6919
6920 if (!port_str) {
6921 sp = getservbyname("bgp", "tcp");
6922 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6923 } else {
6924 port = strtoul(port_str, NULL, 10);
6925 }
6926
6927 peer_port_set(peer, port);
6928
6929 return CMD_SUCCESS;
6930 }
6931
6932 /* Set specified peer's BGP port. */
6933 DEFUN (neighbor_port,
6934 neighbor_port_cmd,
6935 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
6936 NEIGHBOR_STR
6937 NEIGHBOR_ADDR_STR2
6938 "Neighbor's BGP port\n"
6939 "TCP port number\n")
6940 {
6941 int idx_ip = 1;
6942 int idx_number = 3;
6943 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6944 argv[idx_number]->arg);
6945 }
6946
6947 DEFUN (no_neighbor_port,
6948 no_neighbor_port_cmd,
6949 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
6950 NO_STR
6951 NEIGHBOR_STR
6952 NEIGHBOR_ADDR_STR2
6953 "Neighbor's BGP port\n"
6954 "TCP port number\n")
6955 {
6956 int idx_ip = 2;
6957 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6958 }
6959
6960
6961 /* neighbor weight. */
6962 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6963 safi_t safi, const char *weight_str)
6964 {
6965 int ret;
6966 struct peer *peer;
6967 unsigned long weight;
6968
6969 peer = peer_and_group_lookup_vty(vty, ip_str);
6970 if (!peer)
6971 return CMD_WARNING_CONFIG_FAILED;
6972
6973 weight = strtoul(weight_str, NULL, 10);
6974
6975 ret = peer_weight_set(peer, afi, safi, weight);
6976 return bgp_vty_return(vty, ret);
6977 }
6978
6979 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6980 safi_t safi)
6981 {
6982 int ret;
6983 struct peer *peer;
6984
6985 peer = peer_and_group_lookup_vty(vty, ip_str);
6986 if (!peer)
6987 return CMD_WARNING_CONFIG_FAILED;
6988
6989 ret = peer_weight_unset(peer, afi, safi);
6990 return bgp_vty_return(vty, ret);
6991 }
6992
6993 DEFUN (neighbor_weight,
6994 neighbor_weight_cmd,
6995 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6996 NEIGHBOR_STR
6997 NEIGHBOR_ADDR_STR2
6998 "Set default weight for routes from this neighbor\n"
6999 "default weight\n")
7000 {
7001 int idx_peer = 1;
7002 int idx_number = 3;
7003 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7004 bgp_node_safi(vty), argv[idx_number]->arg);
7005 }
7006
7007 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7008 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7009 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7010 "Set default weight for routes from this neighbor\n"
7011 "default weight\n")
7012
7013 DEFUN (no_neighbor_weight,
7014 no_neighbor_weight_cmd,
7015 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7016 NO_STR
7017 NEIGHBOR_STR
7018 NEIGHBOR_ADDR_STR2
7019 "Set default weight for routes from this neighbor\n"
7020 "default weight\n")
7021 {
7022 int idx_peer = 2;
7023 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7024 bgp_node_afi(vty), bgp_node_safi(vty));
7025 }
7026
7027 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7028 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7029 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7030 "Set default weight for routes from this neighbor\n"
7031 "default weight\n")
7032
7033
7034 /* Override capability negotiation. */
7035 DEFUN (neighbor_override_capability,
7036 neighbor_override_capability_cmd,
7037 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7038 NEIGHBOR_STR
7039 NEIGHBOR_ADDR_STR2
7040 "Override capability negotiation result\n")
7041 {
7042 int idx_peer = 1;
7043 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7044 PEER_FLAG_OVERRIDE_CAPABILITY);
7045 }
7046
7047 DEFUN (no_neighbor_override_capability,
7048 no_neighbor_override_capability_cmd,
7049 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7050 NO_STR
7051 NEIGHBOR_STR
7052 NEIGHBOR_ADDR_STR2
7053 "Override capability negotiation result\n")
7054 {
7055 int idx_peer = 2;
7056 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7057 PEER_FLAG_OVERRIDE_CAPABILITY);
7058 }
7059
7060 DEFUN (neighbor_strict_capability,
7061 neighbor_strict_capability_cmd,
7062 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7063 NEIGHBOR_STR
7064 NEIGHBOR_ADDR_STR2
7065 "Strict capability negotiation match\n")
7066 {
7067 int idx_peer = 1;
7068
7069 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7070 PEER_FLAG_STRICT_CAP_MATCH);
7071 }
7072
7073 DEFUN (no_neighbor_strict_capability,
7074 no_neighbor_strict_capability_cmd,
7075 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7076 NO_STR
7077 NEIGHBOR_STR
7078 NEIGHBOR_ADDR_STR2
7079 "Strict capability negotiation match\n")
7080 {
7081 int idx_peer = 2;
7082
7083 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7084 PEER_FLAG_STRICT_CAP_MATCH);
7085 }
7086
7087 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7088 const char *keep_str, const char *hold_str)
7089 {
7090 int ret;
7091 struct peer *peer;
7092 uint32_t keepalive;
7093 uint32_t holdtime;
7094
7095 peer = peer_and_group_lookup_vty(vty, ip_str);
7096 if (!peer)
7097 return CMD_WARNING_CONFIG_FAILED;
7098
7099 keepalive = strtoul(keep_str, NULL, 10);
7100 holdtime = strtoul(hold_str, NULL, 10);
7101
7102 ret = peer_timers_set(peer, keepalive, holdtime);
7103
7104 return bgp_vty_return(vty, ret);
7105 }
7106
7107 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7108 {
7109 int ret;
7110 struct peer *peer;
7111
7112 peer = peer_and_group_lookup_vty(vty, ip_str);
7113 if (!peer)
7114 return CMD_WARNING_CONFIG_FAILED;
7115
7116 ret = peer_timers_unset(peer);
7117
7118 return bgp_vty_return(vty, ret);
7119 }
7120
7121 DEFUN (neighbor_timers,
7122 neighbor_timers_cmd,
7123 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7124 NEIGHBOR_STR
7125 NEIGHBOR_ADDR_STR2
7126 "BGP per neighbor timers\n"
7127 "Keepalive interval\n"
7128 "Holdtime\n")
7129 {
7130 int idx_peer = 1;
7131 int idx_number = 3;
7132 int idx_number_2 = 4;
7133 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7134 argv[idx_number]->arg,
7135 argv[idx_number_2]->arg);
7136 }
7137
7138 DEFUN (no_neighbor_timers,
7139 no_neighbor_timers_cmd,
7140 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7141 NO_STR
7142 NEIGHBOR_STR
7143 NEIGHBOR_ADDR_STR2
7144 "BGP per neighbor timers\n"
7145 "Keepalive interval\n"
7146 "Holdtime\n")
7147 {
7148 int idx_peer = 2;
7149 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7150 }
7151
7152
7153 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7154 const char *time_str)
7155 {
7156 int ret;
7157 struct peer *peer;
7158 uint32_t connect;
7159
7160 peer = peer_and_group_lookup_vty(vty, ip_str);
7161 if (!peer)
7162 return CMD_WARNING_CONFIG_FAILED;
7163
7164 connect = strtoul(time_str, NULL, 10);
7165
7166 ret = peer_timers_connect_set(peer, connect);
7167
7168 return bgp_vty_return(vty, ret);
7169 }
7170
7171 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7172 {
7173 int ret;
7174 struct peer *peer;
7175
7176 peer = peer_and_group_lookup_vty(vty, ip_str);
7177 if (!peer)
7178 return CMD_WARNING_CONFIG_FAILED;
7179
7180 ret = peer_timers_connect_unset(peer);
7181
7182 return bgp_vty_return(vty, ret);
7183 }
7184
7185 DEFUN (neighbor_timers_connect,
7186 neighbor_timers_connect_cmd,
7187 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7188 NEIGHBOR_STR
7189 NEIGHBOR_ADDR_STR2
7190 "BGP per neighbor timers\n"
7191 "BGP connect timer\n"
7192 "Connect timer\n")
7193 {
7194 int idx_peer = 1;
7195 int idx_number = 4;
7196 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7197 argv[idx_number]->arg);
7198 }
7199
7200 DEFUN (no_neighbor_timers_connect,
7201 no_neighbor_timers_connect_cmd,
7202 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7203 NO_STR
7204 NEIGHBOR_STR
7205 NEIGHBOR_ADDR_STR2
7206 "BGP per neighbor timers\n"
7207 "BGP connect timer\n"
7208 "Connect timer\n")
7209 {
7210 int idx_peer = 2;
7211 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7212 }
7213
7214 DEFPY (neighbor_timers_delayopen,
7215 neighbor_timers_delayopen_cmd,
7216 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7217 NEIGHBOR_STR
7218 NEIGHBOR_ADDR_STR2
7219 "BGP per neighbor timers\n"
7220 "RFC 4271 DelayOpenTimer\n"
7221 "DelayOpenTime timer interval\n")
7222 {
7223 struct peer *peer;
7224
7225 peer = peer_and_group_lookup_vty(vty, neighbor);
7226 if (!peer)
7227 return CMD_WARNING_CONFIG_FAILED;
7228
7229 if (!interval) {
7230 if (peer_timers_delayopen_unset(peer))
7231 return CMD_WARNING_CONFIG_FAILED;
7232 } else {
7233 if (peer_timers_delayopen_set(peer, interval))
7234 return CMD_WARNING_CONFIG_FAILED;
7235 }
7236
7237 return CMD_SUCCESS;
7238 }
7239
7240 DEFPY (no_neighbor_timers_delayopen,
7241 no_neighbor_timers_delayopen_cmd,
7242 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7243 NO_STR
7244 NEIGHBOR_STR
7245 NEIGHBOR_ADDR_STR2
7246 "BGP per neighbor timers\n"
7247 "RFC 4271 DelayOpenTimer\n"
7248 "DelayOpenTime timer interval\n")
7249 {
7250 struct peer *peer;
7251
7252 peer = peer_and_group_lookup_vty(vty, neighbor);
7253 if (!peer)
7254 return CMD_WARNING_CONFIG_FAILED;
7255
7256 if (peer_timers_delayopen_unset(peer))
7257 return CMD_WARNING_CONFIG_FAILED;
7258
7259 return CMD_SUCCESS;
7260 }
7261
7262 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7263 const char *time_str, int set)
7264 {
7265 int ret;
7266 struct peer *peer;
7267 uint32_t routeadv = 0;
7268
7269 peer = peer_and_group_lookup_vty(vty, ip_str);
7270 if (!peer)
7271 return CMD_WARNING_CONFIG_FAILED;
7272
7273 if (time_str)
7274 routeadv = strtoul(time_str, NULL, 10);
7275
7276 if (set)
7277 ret = peer_advertise_interval_set(peer, routeadv);
7278 else
7279 ret = peer_advertise_interval_unset(peer);
7280
7281 return bgp_vty_return(vty, ret);
7282 }
7283
7284 DEFUN (neighbor_advertise_interval,
7285 neighbor_advertise_interval_cmd,
7286 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7287 NEIGHBOR_STR
7288 NEIGHBOR_ADDR_STR2
7289 "Minimum interval between sending BGP routing updates\n"
7290 "time in seconds\n")
7291 {
7292 int idx_peer = 1;
7293 int idx_number = 3;
7294 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7295 argv[idx_number]->arg, 1);
7296 }
7297
7298 DEFUN (no_neighbor_advertise_interval,
7299 no_neighbor_advertise_interval_cmd,
7300 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7301 NO_STR
7302 NEIGHBOR_STR
7303 NEIGHBOR_ADDR_STR2
7304 "Minimum interval between sending BGP routing updates\n"
7305 "time in seconds\n")
7306 {
7307 int idx_peer = 2;
7308 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7309 }
7310
7311
7312 /* Time to wait before processing route-map updates */
7313 DEFUN (bgp_set_route_map_delay_timer,
7314 bgp_set_route_map_delay_timer_cmd,
7315 "bgp route-map delay-timer (0-600)",
7316 SET_STR
7317 "BGP route-map delay timer\n"
7318 "Time in secs to wait before processing route-map changes\n"
7319 "0 disables the timer, no route updates happen when route-maps change\n")
7320 {
7321 int idx_number = 3;
7322 uint32_t rmap_delay_timer;
7323
7324 if (argv[idx_number]->arg) {
7325 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7326 bm->rmap_update_timer = rmap_delay_timer;
7327
7328 /* if the dynamic update handling is being disabled, and a timer
7329 * is
7330 * running, stop the timer and act as if the timer has already
7331 * fired.
7332 */
7333 if (!rmap_delay_timer && bm->t_rmap_update) {
7334 THREAD_OFF(bm->t_rmap_update);
7335 thread_execute(bm->master, bgp_route_map_update_timer,
7336 NULL, 0);
7337 }
7338 return CMD_SUCCESS;
7339 } else {
7340 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7341 return CMD_WARNING_CONFIG_FAILED;
7342 }
7343 }
7344
7345 DEFUN (no_bgp_set_route_map_delay_timer,
7346 no_bgp_set_route_map_delay_timer_cmd,
7347 "no bgp route-map delay-timer [(0-600)]",
7348 NO_STR
7349 BGP_STR
7350 "Default BGP route-map delay timer\n"
7351 "Reset to default time to wait for processing route-map changes\n"
7352 "0 disables the timer, no route updates happen when route-maps change\n")
7353 {
7354
7355 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7356
7357 return CMD_SUCCESS;
7358 }
7359
7360 /* neighbor interface */
7361 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7362 const char *str)
7363 {
7364 struct peer *peer;
7365
7366 peer = peer_lookup_vty(vty, ip_str);
7367 if (!peer || peer->conf_if) {
7368 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7369 return CMD_WARNING_CONFIG_FAILED;
7370 }
7371
7372 if (str)
7373 peer_interface_set(peer, str);
7374 else
7375 peer_interface_unset(peer);
7376
7377 return CMD_SUCCESS;
7378 }
7379
7380 DEFUN (neighbor_interface,
7381 neighbor_interface_cmd,
7382 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7383 NEIGHBOR_STR
7384 NEIGHBOR_ADDR_STR
7385 "Interface\n"
7386 "Interface name\n")
7387 {
7388 int idx_ip = 1;
7389 int idx_word = 3;
7390
7391 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7392 }
7393
7394 DEFUN (no_neighbor_interface,
7395 no_neighbor_interface_cmd,
7396 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7397 NO_STR
7398 NEIGHBOR_STR
7399 NEIGHBOR_ADDR_STR
7400 "Interface\n"
7401 "Interface name\n")
7402 {
7403 int idx_peer = 2;
7404
7405 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7406 }
7407
7408 DEFUN (neighbor_distribute_list,
7409 neighbor_distribute_list_cmd,
7410 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7411 NEIGHBOR_STR
7412 NEIGHBOR_ADDR_STR2
7413 "Filter updates to/from this neighbor\n"
7414 "IP Access-list name\n"
7415 "Filter incoming updates\n"
7416 "Filter outgoing updates\n")
7417 {
7418 int idx_peer = 1;
7419 int idx_acl = 3;
7420 int direct, ret;
7421 struct peer *peer;
7422
7423 const char *pstr = argv[idx_peer]->arg;
7424 const char *acl = argv[idx_acl]->arg;
7425 const char *inout = argv[argc - 1]->text;
7426
7427 peer = peer_and_group_lookup_vty(vty, pstr);
7428 if (!peer)
7429 return CMD_WARNING_CONFIG_FAILED;
7430
7431 /* Check filter direction. */
7432 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7433 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7434 direct, acl);
7435
7436 return bgp_vty_return(vty, ret);
7437 }
7438
7439 ALIAS_HIDDEN(
7440 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7441 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7443 "Filter updates to/from this neighbor\n"
7444 "IP Access-list name\n"
7445 "Filter incoming updates\n"
7446 "Filter outgoing updates\n")
7447
7448 DEFUN (no_neighbor_distribute_list,
7449 no_neighbor_distribute_list_cmd,
7450 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7451 NO_STR
7452 NEIGHBOR_STR
7453 NEIGHBOR_ADDR_STR2
7454 "Filter updates to/from this neighbor\n"
7455 "IP Access-list name\n"
7456 "Filter incoming updates\n"
7457 "Filter outgoing updates\n")
7458 {
7459 int idx_peer = 2;
7460 int direct, ret;
7461 struct peer *peer;
7462
7463 const char *pstr = argv[idx_peer]->arg;
7464 const char *inout = argv[argc - 1]->text;
7465
7466 peer = peer_and_group_lookup_vty(vty, pstr);
7467 if (!peer)
7468 return CMD_WARNING_CONFIG_FAILED;
7469
7470 /* Check filter direction. */
7471 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7472 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7473 direct);
7474
7475 return bgp_vty_return(vty, ret);
7476 }
7477
7478 ALIAS_HIDDEN(
7479 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7480 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7481 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7482 "Filter updates to/from this neighbor\n"
7483 "IP Access-list name\n"
7484 "Filter incoming updates\n"
7485 "Filter outgoing updates\n")
7486
7487 /* Set prefix list to the peer. */
7488 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7489 afi_t afi, safi_t safi,
7490 const char *name_str,
7491 const char *direct_str)
7492 {
7493 int ret;
7494 int direct = FILTER_IN;
7495 struct peer *peer;
7496
7497 peer = peer_and_group_lookup_vty(vty, ip_str);
7498 if (!peer)
7499 return CMD_WARNING_CONFIG_FAILED;
7500
7501 /* Check filter direction. */
7502 if (strncmp(direct_str, "i", 1) == 0)
7503 direct = FILTER_IN;
7504 else if (strncmp(direct_str, "o", 1) == 0)
7505 direct = FILTER_OUT;
7506
7507 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7508
7509 return bgp_vty_return(vty, ret);
7510 }
7511
7512 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7513 afi_t afi, safi_t safi,
7514 const char *direct_str)
7515 {
7516 int ret;
7517 struct peer *peer;
7518 int direct = FILTER_IN;
7519
7520 peer = peer_and_group_lookup_vty(vty, ip_str);
7521 if (!peer)
7522 return CMD_WARNING_CONFIG_FAILED;
7523
7524 /* Check filter direction. */
7525 if (strncmp(direct_str, "i", 1) == 0)
7526 direct = FILTER_IN;
7527 else if (strncmp(direct_str, "o", 1) == 0)
7528 direct = FILTER_OUT;
7529
7530 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7531
7532 return bgp_vty_return(vty, ret);
7533 }
7534
7535 DEFUN (neighbor_prefix_list,
7536 neighbor_prefix_list_cmd,
7537 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7538 NEIGHBOR_STR
7539 NEIGHBOR_ADDR_STR2
7540 "Filter updates to/from this neighbor\n"
7541 "Name of a prefix list\n"
7542 "Filter incoming updates\n"
7543 "Filter outgoing updates\n")
7544 {
7545 int idx_peer = 1;
7546 int idx_word = 3;
7547 int idx_in_out = 4;
7548 return peer_prefix_list_set_vty(
7549 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7550 argv[idx_word]->arg, argv[idx_in_out]->arg);
7551 }
7552
7553 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7554 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7555 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7556 "Filter updates to/from this neighbor\n"
7557 "Name of a prefix list\n"
7558 "Filter incoming updates\n"
7559 "Filter outgoing updates\n")
7560
7561 DEFUN (no_neighbor_prefix_list,
7562 no_neighbor_prefix_list_cmd,
7563 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7564 NO_STR
7565 NEIGHBOR_STR
7566 NEIGHBOR_ADDR_STR2
7567 "Filter updates to/from this neighbor\n"
7568 "Name of a prefix list\n"
7569 "Filter incoming updates\n"
7570 "Filter outgoing updates\n")
7571 {
7572 int idx_peer = 2;
7573 int idx_in_out = 5;
7574 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7575 bgp_node_afi(vty), bgp_node_safi(vty),
7576 argv[idx_in_out]->arg);
7577 }
7578
7579 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7580 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7581 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7582 "Filter updates to/from this neighbor\n"
7583 "Name of a prefix list\n"
7584 "Filter incoming updates\n"
7585 "Filter outgoing updates\n")
7586
7587 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7588 safi_t safi, const char *name_str,
7589 const char *direct_str)
7590 {
7591 int ret;
7592 struct peer *peer;
7593 int direct = FILTER_IN;
7594
7595 peer = peer_and_group_lookup_vty(vty, ip_str);
7596 if (!peer)
7597 return CMD_WARNING_CONFIG_FAILED;
7598
7599 /* Check filter direction. */
7600 if (strncmp(direct_str, "i", 1) == 0)
7601 direct = FILTER_IN;
7602 else if (strncmp(direct_str, "o", 1) == 0)
7603 direct = FILTER_OUT;
7604
7605 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7606
7607 return bgp_vty_return(vty, ret);
7608 }
7609
7610 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7611 safi_t safi, const char *direct_str)
7612 {
7613 int ret;
7614 struct peer *peer;
7615 int direct = FILTER_IN;
7616
7617 peer = peer_and_group_lookup_vty(vty, ip_str);
7618 if (!peer)
7619 return CMD_WARNING_CONFIG_FAILED;
7620
7621 /* Check filter direction. */
7622 if (strncmp(direct_str, "i", 1) == 0)
7623 direct = FILTER_IN;
7624 else if (strncmp(direct_str, "o", 1) == 0)
7625 direct = FILTER_OUT;
7626
7627 ret = peer_aslist_unset(peer, afi, safi, direct);
7628
7629 return bgp_vty_return(vty, ret);
7630 }
7631
7632 DEFUN (neighbor_filter_list,
7633 neighbor_filter_list_cmd,
7634 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7635 NEIGHBOR_STR
7636 NEIGHBOR_ADDR_STR2
7637 "Establish BGP filters\n"
7638 "AS path access-list name\n"
7639 "Filter incoming routes\n"
7640 "Filter outgoing routes\n")
7641 {
7642 int idx_peer = 1;
7643 int idx_word = 3;
7644 int idx_in_out = 4;
7645 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7646 bgp_node_safi(vty), argv[idx_word]->arg,
7647 argv[idx_in_out]->arg);
7648 }
7649
7650 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7651 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7652 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7653 "Establish BGP filters\n"
7654 "AS path access-list name\n"
7655 "Filter incoming routes\n"
7656 "Filter outgoing routes\n")
7657
7658 DEFUN (no_neighbor_filter_list,
7659 no_neighbor_filter_list_cmd,
7660 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7661 NO_STR
7662 NEIGHBOR_STR
7663 NEIGHBOR_ADDR_STR2
7664 "Establish BGP filters\n"
7665 "AS path access-list name\n"
7666 "Filter incoming routes\n"
7667 "Filter outgoing routes\n")
7668 {
7669 int idx_peer = 2;
7670 int idx_in_out = 5;
7671 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7672 bgp_node_afi(vty), bgp_node_safi(vty),
7673 argv[idx_in_out]->arg);
7674 }
7675
7676 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7677 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7678 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7679 "Establish BGP filters\n"
7680 "AS path access-list name\n"
7681 "Filter incoming routes\n"
7682 "Filter outgoing routes\n")
7683
7684 /* Set advertise-map to the peer. */
7685 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7686 afi_t afi, safi_t safi,
7687 const char *advertise_str,
7688 const char *condition_str, bool condition,
7689 bool set)
7690 {
7691 int ret = CMD_WARNING_CONFIG_FAILED;
7692 struct peer *peer;
7693 struct route_map *advertise_map;
7694 struct route_map *condition_map;
7695
7696 peer = peer_and_group_lookup_vty(vty, ip_str);
7697 if (!peer)
7698 return ret;
7699
7700 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7701 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7702
7703 if (set)
7704 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7705 advertise_map, condition_str,
7706 condition_map, condition);
7707 else
7708 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7709 advertise_map, condition_str,
7710 condition_map, condition);
7711
7712 return bgp_vty_return(vty, ret);
7713 }
7714
7715 DEFPY (bgp_condadv_period,
7716 bgp_condadv_period_cmd,
7717 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7718 NO_STR
7719 BGP_STR
7720 "Conditional advertisement settings\n"
7721 "Set period to rescan BGP table to check if condition is met\n"
7722 "Period between BGP table scans, in seconds; default 60\n")
7723 {
7724 VTY_DECLVAR_CONTEXT(bgp, bgp);
7725
7726 bgp->condition_check_period =
7727 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7728
7729 return CMD_SUCCESS;
7730 }
7731
7732 DEFPY (neighbor_advertise_map,
7733 neighbor_advertise_map_cmd,
7734 "[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",
7735 NO_STR
7736 NEIGHBOR_STR
7737 NEIGHBOR_ADDR_STR2
7738 "Route-map to conditionally advertise routes\n"
7739 "Name of advertise map\n"
7740 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7741 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7742 "Name of the exist or non exist map\n")
7743 {
7744 bool condition = CONDITION_EXIST;
7745
7746 if (!strcmp(exist, "non-exist-map"))
7747 condition = CONDITION_NON_EXIST;
7748
7749 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7750 bgp_node_safi(vty), advertise_str,
7751 condition_str, condition, !no);
7752 }
7753
7754 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7755 "[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",
7756 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7757 "Route-map to conditionally advertise routes\n"
7758 "Name of advertise map\n"
7759 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7760 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7761 "Name of the exist or non exist map\n")
7762
7763 /* Set route-map to the peer. */
7764 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7765 afi_t afi, safi_t safi, const char *name_str,
7766 const char *direct_str)
7767 {
7768 int ret;
7769 struct peer *peer;
7770 int direct = RMAP_IN;
7771 struct route_map *route_map;
7772
7773 peer = peer_and_group_lookup_vty(vty, ip_str);
7774 if (!peer)
7775 return CMD_WARNING_CONFIG_FAILED;
7776
7777 /* Check filter direction. */
7778 if (strncmp(direct_str, "in", 2) == 0)
7779 direct = RMAP_IN;
7780 else if (strncmp(direct_str, "o", 1) == 0)
7781 direct = RMAP_OUT;
7782
7783 route_map = route_map_lookup_warn_noexist(vty, name_str);
7784 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7785
7786 return bgp_vty_return(vty, ret);
7787 }
7788
7789 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7790 afi_t afi, safi_t safi,
7791 const char *direct_str)
7792 {
7793 int ret;
7794 struct peer *peer;
7795 int direct = RMAP_IN;
7796
7797 peer = peer_and_group_lookup_vty(vty, ip_str);
7798 if (!peer)
7799 return CMD_WARNING_CONFIG_FAILED;
7800
7801 /* Check filter direction. */
7802 if (strncmp(direct_str, "in", 2) == 0)
7803 direct = RMAP_IN;
7804 else if (strncmp(direct_str, "o", 1) == 0)
7805 direct = RMAP_OUT;
7806
7807 ret = peer_route_map_unset(peer, afi, safi, direct);
7808
7809 return bgp_vty_return(vty, ret);
7810 }
7811
7812 DEFUN (neighbor_route_map,
7813 neighbor_route_map_cmd,
7814 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7815 NEIGHBOR_STR
7816 NEIGHBOR_ADDR_STR2
7817 "Apply route map to neighbor\n"
7818 "Name of route map\n"
7819 "Apply map to incoming routes\n"
7820 "Apply map to outbound routes\n")
7821 {
7822 int idx_peer = 1;
7823 int idx_word = 3;
7824 int idx_in_out = 4;
7825 return peer_route_map_set_vty(
7826 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7827 argv[idx_word]->arg, argv[idx_in_out]->arg);
7828 }
7829
7830 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7831 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7832 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7833 "Apply route map to neighbor\n"
7834 "Name of route map\n"
7835 "Apply map to incoming routes\n"
7836 "Apply map to outbound routes\n")
7837
7838 DEFUN (no_neighbor_route_map,
7839 no_neighbor_route_map_cmd,
7840 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7841 NO_STR
7842 NEIGHBOR_STR
7843 NEIGHBOR_ADDR_STR2
7844 "Apply route map to neighbor\n"
7845 "Name of route map\n"
7846 "Apply map to incoming routes\n"
7847 "Apply map to outbound routes\n")
7848 {
7849 int idx_peer = 2;
7850 int idx_in_out = 5;
7851 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7852 bgp_node_afi(vty), bgp_node_safi(vty),
7853 argv[idx_in_out]->arg);
7854 }
7855
7856 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7857 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7858 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7859 "Apply route map to neighbor\n"
7860 "Name of route map\n"
7861 "Apply map to incoming routes\n"
7862 "Apply map to outbound routes\n")
7863
7864 /* Set unsuppress-map to the peer. */
7865 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7866 afi_t afi, safi_t safi,
7867 const char *name_str)
7868 {
7869 int ret;
7870 struct peer *peer;
7871 struct route_map *route_map;
7872
7873 peer = peer_and_group_lookup_vty(vty, ip_str);
7874 if (!peer)
7875 return CMD_WARNING_CONFIG_FAILED;
7876
7877 route_map = route_map_lookup_warn_noexist(vty, name_str);
7878 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7879
7880 return bgp_vty_return(vty, ret);
7881 }
7882
7883 /* Unset route-map from the peer. */
7884 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7885 afi_t afi, safi_t safi)
7886 {
7887 int ret;
7888 struct peer *peer;
7889
7890 peer = peer_and_group_lookup_vty(vty, ip_str);
7891 if (!peer)
7892 return CMD_WARNING_CONFIG_FAILED;
7893
7894 ret = peer_unsuppress_map_unset(peer, afi, safi);
7895
7896 return bgp_vty_return(vty, ret);
7897 }
7898
7899 DEFUN (neighbor_unsuppress_map,
7900 neighbor_unsuppress_map_cmd,
7901 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7902 NEIGHBOR_STR
7903 NEIGHBOR_ADDR_STR2
7904 "Route-map to selectively unsuppress suppressed routes\n"
7905 "Name of route map\n")
7906 {
7907 int idx_peer = 1;
7908 int idx_word = 3;
7909 return peer_unsuppress_map_set_vty(
7910 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7911 argv[idx_word]->arg);
7912 }
7913
7914 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7915 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7916 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7917 "Route-map to selectively unsuppress suppressed routes\n"
7918 "Name of route map\n")
7919
7920 DEFUN (no_neighbor_unsuppress_map,
7921 no_neighbor_unsuppress_map_cmd,
7922 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7923 NO_STR
7924 NEIGHBOR_STR
7925 NEIGHBOR_ADDR_STR2
7926 "Route-map to selectively unsuppress suppressed routes\n"
7927 "Name of route map\n")
7928 {
7929 int idx_peer = 2;
7930 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7931 bgp_node_afi(vty),
7932 bgp_node_safi(vty));
7933 }
7934
7935 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7936 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7937 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7938 "Route-map to selectively unsuppress suppressed routes\n"
7939 "Name of route map\n")
7940
7941 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7942 afi_t afi, safi_t safi,
7943 const char *num_str,
7944 const char *threshold_str, int warning,
7945 const char *restart_str,
7946 const char *force_str)
7947 {
7948 int ret;
7949 struct peer *peer;
7950 uint32_t max;
7951 uint8_t threshold;
7952 uint16_t restart;
7953
7954 peer = peer_and_group_lookup_vty(vty, ip_str);
7955 if (!peer)
7956 return CMD_WARNING_CONFIG_FAILED;
7957
7958 max = strtoul(num_str, NULL, 10);
7959 if (threshold_str)
7960 threshold = atoi(threshold_str);
7961 else
7962 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7963
7964 if (restart_str)
7965 restart = atoi(restart_str);
7966 else
7967 restart = 0;
7968
7969 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7970 restart, force_str ? true : false);
7971
7972 return bgp_vty_return(vty, ret);
7973 }
7974
7975 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7976 afi_t afi, safi_t safi)
7977 {
7978 int ret;
7979 struct peer *peer;
7980
7981 peer = peer_and_group_lookup_vty(vty, ip_str);
7982 if (!peer)
7983 return CMD_WARNING_CONFIG_FAILED;
7984
7985 ret = peer_maximum_prefix_unset(peer, afi, safi);
7986
7987 return bgp_vty_return(vty, ret);
7988 }
7989
7990 /* Maximum number of prefix to be sent to the neighbor. */
7991 DEFUN(neighbor_maximum_prefix_out,
7992 neighbor_maximum_prefix_out_cmd,
7993 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7994 NEIGHBOR_STR
7995 NEIGHBOR_ADDR_STR2
7996 "Maximum number of prefixes to be sent to this peer\n"
7997 "Maximum no. of prefix limit\n")
7998 {
7999 int ret;
8000 int idx_peer = 1;
8001 int idx_number = 3;
8002 struct peer *peer;
8003 uint32_t max;
8004 afi_t afi = bgp_node_afi(vty);
8005 safi_t safi = bgp_node_safi(vty);
8006
8007 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8008 if (!peer)
8009 return CMD_WARNING_CONFIG_FAILED;
8010
8011 max = strtoul(argv[idx_number]->arg, NULL, 10);
8012
8013 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8014
8015 return bgp_vty_return(vty, ret);
8016 }
8017
8018 DEFUN(no_neighbor_maximum_prefix_out,
8019 no_neighbor_maximum_prefix_out_cmd,
8020 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8021 NO_STR
8022 NEIGHBOR_STR
8023 NEIGHBOR_ADDR_STR2
8024 "Maximum number of prefixes to be sent to this peer\n"
8025 "Maximum no. of prefix limit\n")
8026 {
8027 int ret;
8028 int idx_peer = 2;
8029 struct peer *peer;
8030 afi_t afi = bgp_node_afi(vty);
8031 safi_t safi = bgp_node_safi(vty);
8032
8033 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8034 if (!peer)
8035 return CMD_WARNING_CONFIG_FAILED;
8036
8037 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8038
8039 return bgp_vty_return(vty, ret);
8040 }
8041
8042 /* Maximum number of prefix configuration. Prefix count is different
8043 for each peer configuration. So this configuration can be set for
8044 each peer configuration. */
8045 DEFUN (neighbor_maximum_prefix,
8046 neighbor_maximum_prefix_cmd,
8047 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8048 NEIGHBOR_STR
8049 NEIGHBOR_ADDR_STR2
8050 "Maximum number of prefix accept from this peer\n"
8051 "maximum no. of prefix limit\n"
8052 "Force checking all received routes not only accepted\n")
8053 {
8054 int idx_peer = 1;
8055 int idx_number = 3;
8056 int idx_force = 0;
8057 char *force = NULL;
8058
8059 if (argv_find(argv, argc, "force", &idx_force))
8060 force = argv[idx_force]->arg;
8061
8062 return peer_maximum_prefix_set_vty(
8063 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8064 argv[idx_number]->arg, NULL, 0, NULL, force);
8065 }
8066
8067 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8068 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8069 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8070 "Maximum number of prefix accept from this peer\n"
8071 "maximum no. of prefix limit\n"
8072 "Force checking all received routes not only accepted\n")
8073
8074 DEFUN (neighbor_maximum_prefix_threshold,
8075 neighbor_maximum_prefix_threshold_cmd,
8076 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8077 NEIGHBOR_STR
8078 NEIGHBOR_ADDR_STR2
8079 "Maximum number of prefix accept from this peer\n"
8080 "maximum no. of prefix limit\n"
8081 "Threshold value (%) at which to generate a warning msg\n"
8082 "Force checking all received routes not only accepted\n")
8083 {
8084 int idx_peer = 1;
8085 int idx_number = 3;
8086 int idx_number_2 = 4;
8087 int idx_force = 0;
8088 char *force = NULL;
8089
8090 if (argv_find(argv, argc, "force", &idx_force))
8091 force = argv[idx_force]->arg;
8092
8093 return peer_maximum_prefix_set_vty(
8094 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8095 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8096 }
8097
8098 ALIAS_HIDDEN(
8099 neighbor_maximum_prefix_threshold,
8100 neighbor_maximum_prefix_threshold_hidden_cmd,
8101 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8102 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8103 "Maximum number of prefix accept from this peer\n"
8104 "maximum no. of prefix limit\n"
8105 "Threshold value (%) at which to generate a warning msg\n"
8106 "Force checking all received routes not only accepted\n")
8107
8108 DEFUN (neighbor_maximum_prefix_warning,
8109 neighbor_maximum_prefix_warning_cmd,
8110 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8111 NEIGHBOR_STR
8112 NEIGHBOR_ADDR_STR2
8113 "Maximum number of prefix accept from this peer\n"
8114 "maximum no. of prefix limit\n"
8115 "Only give warning message when limit is exceeded\n"
8116 "Force checking all received routes not only accepted\n")
8117 {
8118 int idx_peer = 1;
8119 int idx_number = 3;
8120 int idx_force = 0;
8121 char *force = NULL;
8122
8123 if (argv_find(argv, argc, "force", &idx_force))
8124 force = argv[idx_force]->arg;
8125
8126 return peer_maximum_prefix_set_vty(
8127 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8128 argv[idx_number]->arg, NULL, 1, NULL, force);
8129 }
8130
8131 ALIAS_HIDDEN(
8132 neighbor_maximum_prefix_warning,
8133 neighbor_maximum_prefix_warning_hidden_cmd,
8134 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8135 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8136 "Maximum number of prefix accept from this peer\n"
8137 "maximum no. of prefix limit\n"
8138 "Only give warning message when limit is exceeded\n"
8139 "Force checking all received routes not only accepted\n")
8140
8141 DEFUN (neighbor_maximum_prefix_threshold_warning,
8142 neighbor_maximum_prefix_threshold_warning_cmd,
8143 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8144 NEIGHBOR_STR
8145 NEIGHBOR_ADDR_STR2
8146 "Maximum number of prefix accept from this peer\n"
8147 "maximum no. of prefix limit\n"
8148 "Threshold value (%) at which to generate a warning msg\n"
8149 "Only give warning message when limit is exceeded\n"
8150 "Force checking all received routes not only accepted\n")
8151 {
8152 int idx_peer = 1;
8153 int idx_number = 3;
8154 int idx_number_2 = 4;
8155 int idx_force = 0;
8156 char *force = NULL;
8157
8158 if (argv_find(argv, argc, "force", &idx_force))
8159 force = argv[idx_force]->arg;
8160
8161 return peer_maximum_prefix_set_vty(
8162 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8163 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8164 }
8165
8166 ALIAS_HIDDEN(
8167 neighbor_maximum_prefix_threshold_warning,
8168 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8169 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8170 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8171 "Maximum number of prefix accept from this peer\n"
8172 "maximum no. of prefix limit\n"
8173 "Threshold value (%) at which to generate a warning msg\n"
8174 "Only give warning message when limit is exceeded\n"
8175 "Force checking all received routes not only accepted\n")
8176
8177 DEFUN (neighbor_maximum_prefix_restart,
8178 neighbor_maximum_prefix_restart_cmd,
8179 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8180 NEIGHBOR_STR
8181 NEIGHBOR_ADDR_STR2
8182 "Maximum number of prefix accept from this peer\n"
8183 "maximum no. of prefix limit\n"
8184 "Restart bgp connection after limit is exceeded\n"
8185 "Restart interval in minutes\n"
8186 "Force checking all received routes not only accepted\n")
8187 {
8188 int idx_peer = 1;
8189 int idx_number = 3;
8190 int idx_number_2 = 5;
8191 int idx_force = 0;
8192 char *force = NULL;
8193
8194 if (argv_find(argv, argc, "force", &idx_force))
8195 force = argv[idx_force]->arg;
8196
8197 return peer_maximum_prefix_set_vty(
8198 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8199 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8200 }
8201
8202 ALIAS_HIDDEN(
8203 neighbor_maximum_prefix_restart,
8204 neighbor_maximum_prefix_restart_hidden_cmd,
8205 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8206 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8207 "Maximum number of prefix accept from this peer\n"
8208 "maximum no. of prefix limit\n"
8209 "Restart bgp connection after limit is exceeded\n"
8210 "Restart interval in minutes\n"
8211 "Force checking all received routes not only accepted\n")
8212
8213 DEFUN (neighbor_maximum_prefix_threshold_restart,
8214 neighbor_maximum_prefix_threshold_restart_cmd,
8215 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8216 NEIGHBOR_STR
8217 NEIGHBOR_ADDR_STR2
8218 "Maximum number of prefixes to accept from this peer\n"
8219 "maximum no. of prefix limit\n"
8220 "Threshold value (%) at which to generate a warning msg\n"
8221 "Restart bgp connection after limit is exceeded\n"
8222 "Restart interval in minutes\n"
8223 "Force checking all received routes not only accepted\n")
8224 {
8225 int idx_peer = 1;
8226 int idx_number = 3;
8227 int idx_number_2 = 4;
8228 int idx_number_3 = 6;
8229 int idx_force = 0;
8230 char *force = NULL;
8231
8232 if (argv_find(argv, argc, "force", &idx_force))
8233 force = argv[idx_force]->arg;
8234
8235 return peer_maximum_prefix_set_vty(
8236 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8237 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8238 argv[idx_number_3]->arg, force);
8239 }
8240
8241 ALIAS_HIDDEN(
8242 neighbor_maximum_prefix_threshold_restart,
8243 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8244 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8246 "Maximum number of prefixes to accept from this peer\n"
8247 "maximum no. of prefix limit\n"
8248 "Threshold value (%) at which to generate a warning msg\n"
8249 "Restart bgp connection after limit is exceeded\n"
8250 "Restart interval in minutes\n"
8251 "Force checking all received routes not only accepted\n")
8252
8253 DEFUN (no_neighbor_maximum_prefix,
8254 no_neighbor_maximum_prefix_cmd,
8255 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8256 NO_STR
8257 NEIGHBOR_STR
8258 NEIGHBOR_ADDR_STR2
8259 "Maximum number of prefixes to accept from this peer\n"
8260 "maximum no. of prefix limit\n"
8261 "Threshold value (%) at which to generate a warning msg\n"
8262 "Restart bgp connection after limit is exceeded\n"
8263 "Restart interval in minutes\n"
8264 "Only give warning message when limit is exceeded\n"
8265 "Force checking all received routes not only accepted\n")
8266 {
8267 int idx_peer = 2;
8268 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8269 bgp_node_afi(vty),
8270 bgp_node_safi(vty));
8271 }
8272
8273 ALIAS_HIDDEN(
8274 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8275 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8276 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8277 "Maximum number of prefixes to accept from this peer\n"
8278 "maximum no. of prefix limit\n"
8279 "Threshold value (%) at which to generate a warning msg\n"
8280 "Restart bgp connection after limit is exceeded\n"
8281 "Restart interval in minutes\n"
8282 "Only give warning message when limit is exceeded\n"
8283 "Force checking all received routes not only accepted\n")
8284
8285 /* "neighbor soo" */
8286 DEFPY (neighbor_soo,
8287 neighbor_soo_cmd,
8288 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8289 NEIGHBOR_STR
8290 NEIGHBOR_ADDR_STR2
8291 "Set the Site-of-Origin (SoO) extended community\n"
8292 "VPN extended community\n")
8293 {
8294 struct peer *peer;
8295 afi_t afi = bgp_node_afi(vty);
8296 safi_t safi = bgp_node_safi(vty);
8297 struct ecommunity *ecomm_soo;
8298
8299 peer = peer_and_group_lookup_vty(vty, neighbor);
8300 if (!peer)
8301 return CMD_WARNING_CONFIG_FAILED;
8302
8303 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8304 if (!ecomm_soo) {
8305 vty_out(vty, "%% Malformed SoO extended community\n");
8306 return CMD_WARNING;
8307 }
8308 ecommunity_str(ecomm_soo);
8309
8310 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8311 ecommunity_free(&peer->soo[afi][safi]);
8312 peer->soo[afi][safi] = ecomm_soo;
8313 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8314 }
8315
8316 return bgp_vty_return(vty,
8317 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8318 }
8319
8320 DEFPY (no_neighbor_soo,
8321 no_neighbor_soo_cmd,
8322 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8323 NO_STR
8324 NEIGHBOR_STR
8325 NEIGHBOR_ADDR_STR2
8326 "Set the Site-of-Origin (SoO) extended community\n"
8327 "VPN extended community\n")
8328 {
8329 struct peer *peer;
8330 afi_t afi = bgp_node_afi(vty);
8331 safi_t safi = bgp_node_safi(vty);
8332
8333 peer = peer_and_group_lookup_vty(vty, neighbor);
8334 if (!peer)
8335 return CMD_WARNING_CONFIG_FAILED;
8336
8337 ecommunity_free(&peer->soo[afi][safi]);
8338
8339 return bgp_vty_return(
8340 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8341 }
8342
8343 /* "neighbor allowas-in" */
8344 DEFUN (neighbor_allowas_in,
8345 neighbor_allowas_in_cmd,
8346 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8347 NEIGHBOR_STR
8348 NEIGHBOR_ADDR_STR2
8349 "Accept as-path with my AS present in it\n"
8350 "Number of occurrences of AS number\n"
8351 "Only accept my AS in the as-path if the route was originated in my AS\n")
8352 {
8353 int idx_peer = 1;
8354 int idx_number_origin = 3;
8355 int ret;
8356 int origin = 0;
8357 struct peer *peer;
8358 int allow_num = 0;
8359
8360 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8361 if (!peer)
8362 return CMD_WARNING_CONFIG_FAILED;
8363
8364 if (argc <= idx_number_origin)
8365 allow_num = 3;
8366 else {
8367 if (argv[idx_number_origin]->type == WORD_TKN)
8368 origin = 1;
8369 else
8370 allow_num = atoi(argv[idx_number_origin]->arg);
8371 }
8372
8373 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8374 allow_num, origin);
8375
8376 return bgp_vty_return(vty, ret);
8377 }
8378
8379 ALIAS_HIDDEN(
8380 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8381 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8382 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8383 "Accept as-path with my AS present in it\n"
8384 "Number of occurrences of AS number\n"
8385 "Only accept my AS in the as-path if the route was originated in my AS\n")
8386
8387 DEFUN (no_neighbor_allowas_in,
8388 no_neighbor_allowas_in_cmd,
8389 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8390 NO_STR
8391 NEIGHBOR_STR
8392 NEIGHBOR_ADDR_STR2
8393 "allow local ASN appears in aspath attribute\n"
8394 "Number of occurrences of AS number\n"
8395 "Only accept my AS in the as-path if the route was originated in my AS\n")
8396 {
8397 int idx_peer = 2;
8398 int ret;
8399 struct peer *peer;
8400
8401 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8402 if (!peer)
8403 return CMD_WARNING_CONFIG_FAILED;
8404
8405 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8406 bgp_node_safi(vty));
8407
8408 return bgp_vty_return(vty, ret);
8409 }
8410
8411 ALIAS_HIDDEN(
8412 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8413 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8414 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8415 "allow local ASN appears in aspath attribute\n"
8416 "Number of occurrences of AS number\n"
8417 "Only accept my AS in the as-path if the route was originated in my AS\n")
8418
8419 DEFUN (neighbor_ttl_security,
8420 neighbor_ttl_security_cmd,
8421 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8422 NEIGHBOR_STR
8423 NEIGHBOR_ADDR_STR2
8424 "BGP ttl-security parameters\n"
8425 "Specify the maximum number of hops to the BGP peer\n"
8426 "Number of hops to BGP peer\n")
8427 {
8428 int idx_peer = 1;
8429 int idx_number = 4;
8430 struct peer *peer;
8431 int gtsm_hops;
8432
8433 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8434 if (!peer)
8435 return CMD_WARNING_CONFIG_FAILED;
8436
8437 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8438
8439 /*
8440 * If 'neighbor swpX', then this is for directly connected peers,
8441 * we should not accept a ttl-security hops value greater than 1.
8442 */
8443 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8444 vty_out(vty,
8445 "%s is directly connected peer, hops cannot exceed 1\n",
8446 argv[idx_peer]->arg);
8447 return CMD_WARNING_CONFIG_FAILED;
8448 }
8449
8450 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8451 }
8452
8453 DEFUN (no_neighbor_ttl_security,
8454 no_neighbor_ttl_security_cmd,
8455 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8456 NO_STR
8457 NEIGHBOR_STR
8458 NEIGHBOR_ADDR_STR2
8459 "BGP ttl-security parameters\n"
8460 "Specify the maximum number of hops to the BGP peer\n"
8461 "Number of hops to BGP peer\n")
8462 {
8463 int idx_peer = 2;
8464 struct peer *peer;
8465
8466 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8467 if (!peer)
8468 return CMD_WARNING_CONFIG_FAILED;
8469
8470 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8471 }
8472
8473 /* disable-addpath-rx */
8474 DEFUN(neighbor_disable_addpath_rx,
8475 neighbor_disable_addpath_rx_cmd,
8476 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8477 NEIGHBOR_STR
8478 NEIGHBOR_ADDR_STR2
8479 "Do not accept additional paths\n")
8480 {
8481 char *peer_str = argv[1]->arg;
8482 struct peer *peer;
8483 afi_t afi = bgp_node_afi(vty);
8484 safi_t safi = bgp_node_safi(vty);
8485
8486 peer = peer_and_group_lookup_vty(vty, peer_str);
8487 if (!peer)
8488 return CMD_WARNING_CONFIG_FAILED;
8489
8490 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8491 PEER_FLAG_DISABLE_ADDPATH_RX);
8492 }
8493
8494 DEFUN(no_neighbor_disable_addpath_rx,
8495 no_neighbor_disable_addpath_rx_cmd,
8496 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8497 NO_STR
8498 NEIGHBOR_STR
8499 NEIGHBOR_ADDR_STR2
8500 "Do not accept additional paths\n")
8501 {
8502 char *peer_str = argv[2]->arg;
8503 struct peer *peer;
8504 afi_t afi = bgp_node_afi(vty);
8505 safi_t safi = bgp_node_safi(vty);
8506
8507 peer = peer_and_group_lookup_vty(vty, peer_str);
8508 if (!peer)
8509 return CMD_WARNING_CONFIG_FAILED;
8510
8511 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8512 PEER_FLAG_DISABLE_ADDPATH_RX);
8513 }
8514
8515 DEFUN (neighbor_addpath_tx_all_paths,
8516 neighbor_addpath_tx_all_paths_cmd,
8517 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8518 NEIGHBOR_STR
8519 NEIGHBOR_ADDR_STR2
8520 "Use addpath to advertise all paths to a neighbor\n")
8521 {
8522 int idx_peer = 1;
8523 struct peer *peer;
8524
8525 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8526 if (!peer)
8527 return CMD_WARNING_CONFIG_FAILED;
8528
8529 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8530 BGP_ADDPATH_ALL);
8531 return CMD_SUCCESS;
8532 }
8533
8534 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8535 neighbor_addpath_tx_all_paths_hidden_cmd,
8536 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8537 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8538 "Use addpath to advertise all paths to a neighbor\n")
8539
8540 DEFUN (no_neighbor_addpath_tx_all_paths,
8541 no_neighbor_addpath_tx_all_paths_cmd,
8542 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8543 NO_STR
8544 NEIGHBOR_STR
8545 NEIGHBOR_ADDR_STR2
8546 "Use addpath to advertise all paths to a neighbor\n")
8547 {
8548 int idx_peer = 2;
8549 struct peer *peer;
8550
8551 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8552 if (!peer)
8553 return CMD_WARNING_CONFIG_FAILED;
8554
8555 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8556 != BGP_ADDPATH_ALL) {
8557 vty_out(vty,
8558 "%% Peer not currently configured to transmit all paths.");
8559 return CMD_WARNING_CONFIG_FAILED;
8560 }
8561
8562 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8563 BGP_ADDPATH_NONE);
8564
8565 return CMD_SUCCESS;
8566 }
8567
8568 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8569 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8570 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8571 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8572 "Use addpath to advertise all paths to a neighbor\n")
8573
8574 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8575 neighbor_addpath_tx_bestpath_per_as_cmd,
8576 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8577 NEIGHBOR_STR
8578 NEIGHBOR_ADDR_STR2
8579 "Use addpath to advertise the bestpath per each neighboring AS\n")
8580 {
8581 int idx_peer = 1;
8582 struct peer *peer;
8583
8584 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8585 if (!peer)
8586 return CMD_WARNING_CONFIG_FAILED;
8587
8588 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8589 BGP_ADDPATH_BEST_PER_AS);
8590
8591 return CMD_SUCCESS;
8592 }
8593
8594 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8595 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8596 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8597 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8598 "Use addpath to advertise the bestpath per each neighboring AS\n")
8599
8600 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8601 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8602 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8603 NO_STR
8604 NEIGHBOR_STR
8605 NEIGHBOR_ADDR_STR2
8606 "Use addpath to advertise the bestpath per each neighboring AS\n")
8607 {
8608 int idx_peer = 2;
8609 struct peer *peer;
8610
8611 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8612 if (!peer)
8613 return CMD_WARNING_CONFIG_FAILED;
8614
8615 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8616 != BGP_ADDPATH_BEST_PER_AS) {
8617 vty_out(vty,
8618 "%% Peer not currently configured to transmit all best path per as.");
8619 return CMD_WARNING_CONFIG_FAILED;
8620 }
8621
8622 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8623 BGP_ADDPATH_NONE);
8624
8625 return CMD_SUCCESS;
8626 }
8627
8628 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8629 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8630 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8631 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8632 "Use addpath to advertise the bestpath per each neighboring AS\n")
8633
8634 DEFPY(
8635 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8636 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8637 NEIGHBOR_STR
8638 NEIGHBOR_ADDR_STR2
8639 "Detect AS loops before sending to neighbor\n")
8640 {
8641 struct peer *peer;
8642
8643 peer = peer_and_group_lookup_vty(vty, neighbor);
8644 if (!peer)
8645 return CMD_WARNING_CONFIG_FAILED;
8646
8647 peer->as_path_loop_detection = true;
8648
8649 return CMD_SUCCESS;
8650 }
8651
8652 DEFPY(
8653 no_neighbor_aspath_loop_detection,
8654 no_neighbor_aspath_loop_detection_cmd,
8655 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8656 NO_STR
8657 NEIGHBOR_STR
8658 NEIGHBOR_ADDR_STR2
8659 "Detect AS loops before sending to neighbor\n")
8660 {
8661 struct peer *peer;
8662
8663 peer = peer_and_group_lookup_vty(vty, neighbor);
8664 if (!peer)
8665 return CMD_WARNING_CONFIG_FAILED;
8666
8667 peer->as_path_loop_detection = false;
8668
8669 return CMD_SUCCESS;
8670 }
8671
8672 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8673 struct ecommunity **list, bool is_rt6)
8674 {
8675 struct ecommunity *ecom = NULL;
8676 struct ecommunity *ecomadd;
8677
8678 for (; argc; --argc, ++argv) {
8679 if (is_rt6)
8680 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8681 ECOMMUNITY_ROUTE_TARGET,
8682 0);
8683 else
8684 ecomadd = ecommunity_str2com(argv[0]->arg,
8685 ECOMMUNITY_ROUTE_TARGET,
8686 0);
8687 if (!ecomadd) {
8688 vty_out(vty, "Malformed community-list value\n");
8689 if (ecom)
8690 ecommunity_free(&ecom);
8691 return CMD_WARNING_CONFIG_FAILED;
8692 }
8693
8694 if (ecom) {
8695 ecommunity_merge(ecom, ecomadd);
8696 ecommunity_free(&ecomadd);
8697 } else {
8698 ecom = ecomadd;
8699 }
8700 }
8701
8702 if (*list) {
8703 ecommunity_free(&*list);
8704 }
8705 *list = ecom;
8706
8707 return CMD_SUCCESS;
8708 }
8709
8710 /*
8711 * v2vimport is true if we are handling a `import vrf ...` command
8712 */
8713 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8714 {
8715 afi_t afi;
8716
8717 switch (vty->node) {
8718 case BGP_IPV4_NODE:
8719 afi = AFI_IP;
8720 break;
8721 case BGP_IPV6_NODE:
8722 afi = AFI_IP6;
8723 break;
8724 default:
8725 vty_out(vty,
8726 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8727 return AFI_MAX;
8728 }
8729
8730 if (!v2vimport) {
8731 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8732 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8733 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8734 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8735 vty_out(vty,
8736 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8737 return AFI_MAX;
8738 }
8739 } else {
8740 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8741 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8742 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8743 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8744 vty_out(vty,
8745 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8746 return AFI_MAX;
8747 }
8748 }
8749 return afi;
8750 }
8751
8752 DEFPY (af_rd_vpn_export,
8753 af_rd_vpn_export_cmd,
8754 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8755 NO_STR
8756 "Specify route distinguisher\n"
8757 "Between current address-family and vpn\n"
8758 "For routes leaked from current address-family to vpn\n"
8759 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8760 {
8761 VTY_DECLVAR_CONTEXT(bgp, bgp);
8762 struct prefix_rd prd;
8763 int ret;
8764 afi_t afi;
8765 int idx = 0;
8766 bool yes = true;
8767
8768 if (argv_find(argv, argc, "no", &idx))
8769 yes = false;
8770
8771 if (yes) {
8772 ret = str2prefix_rd(rd_str, &prd);
8773 if (!ret) {
8774 vty_out(vty, "%% Malformed rd\n");
8775 return CMD_WARNING_CONFIG_FAILED;
8776 }
8777 }
8778
8779 afi = vpn_policy_getafi(vty, bgp, false);
8780 if (afi == AFI_MAX)
8781 return CMD_WARNING_CONFIG_FAILED;
8782
8783 /*
8784 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8785 */
8786 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8787 bgp_get_default(), bgp);
8788
8789 if (yes) {
8790 bgp->vpn_policy[afi].tovpn_rd = prd;
8791 SET_FLAG(bgp->vpn_policy[afi].flags,
8792 BGP_VPN_POLICY_TOVPN_RD_SET);
8793 } else {
8794 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8795 BGP_VPN_POLICY_TOVPN_RD_SET);
8796 }
8797
8798 /* post-change: re-export vpn routes */
8799 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8800 bgp_get_default(), bgp);
8801
8802 return CMD_SUCCESS;
8803 }
8804
8805 ALIAS (af_rd_vpn_export,
8806 af_no_rd_vpn_export_cmd,
8807 "no rd vpn export",
8808 NO_STR
8809 "Specify route distinguisher\n"
8810 "Between current address-family and vpn\n"
8811 "For routes leaked from current address-family to vpn\n")
8812
8813 DEFPY (af_label_vpn_export,
8814 af_label_vpn_export_cmd,
8815 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8816 NO_STR
8817 "label value for VRF\n"
8818 "Between current address-family and vpn\n"
8819 "For routes leaked from current address-family to vpn\n"
8820 "Label Value <0-1048575>\n"
8821 "Automatically assign a label\n")
8822 {
8823 VTY_DECLVAR_CONTEXT(bgp, bgp);
8824 mpls_label_t label = MPLS_LABEL_NONE;
8825 afi_t afi;
8826 int idx = 0;
8827 bool yes = true;
8828
8829 if (argv_find(argv, argc, "no", &idx))
8830 yes = false;
8831
8832 /* If "no ...", squash trailing parameter */
8833 if (!yes)
8834 label_auto = NULL;
8835
8836 if (yes) {
8837 if (!label_auto)
8838 label = label_val; /* parser should force unsigned */
8839 }
8840
8841 afi = vpn_policy_getafi(vty, bgp, false);
8842 if (afi == AFI_MAX)
8843 return CMD_WARNING_CONFIG_FAILED;
8844
8845
8846 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8847 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8848 /* no change */
8849 return CMD_SUCCESS;
8850
8851 /*
8852 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8853 */
8854 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8855 bgp_get_default(), bgp);
8856
8857 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8858 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8859
8860 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8861
8862 /*
8863 * label has previously been automatically
8864 * assigned by labelpool: release it
8865 *
8866 * NB if tovpn_label == MPLS_LABEL_NONE it
8867 * means the automatic assignment is in flight
8868 * and therefore the labelpool callback must
8869 * detect that the auto label is not needed.
8870 */
8871
8872 bgp_lp_release(LP_TYPE_VRF,
8873 &bgp->vpn_policy[afi],
8874 bgp->vpn_policy[afi].tovpn_label);
8875 }
8876 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8877 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8878 }
8879
8880 bgp->vpn_policy[afi].tovpn_label = label;
8881 if (label_auto) {
8882 SET_FLAG(bgp->vpn_policy[afi].flags,
8883 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8884 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8885 vpn_leak_label_callback);
8886 }
8887
8888 /* post-change: re-export vpn routes */
8889 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8890 bgp_get_default(), bgp);
8891
8892 hook_call(bgp_snmp_update_last_changed, bgp);
8893 return CMD_SUCCESS;
8894 }
8895
8896 DEFPY (af_sid_vpn_export,
8897 af_sid_vpn_export_cmd,
8898 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8899 NO_STR
8900 "sid value for VRF\n"
8901 "Between current address-family and vpn\n"
8902 "For routes leaked from current address-family to vpn\n"
8903 "Sid allocation index\n"
8904 "Automatically assign a label\n")
8905 {
8906 VTY_DECLVAR_CONTEXT(bgp, bgp);
8907 afi_t afi;
8908 int debug = 0;
8909 int idx = 0;
8910 bool yes = true;
8911
8912 if (argv_find(argv, argc, "no", &idx))
8913 yes = false;
8914 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8915 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8916
8917 afi = vpn_policy_getafi(vty, bgp, false);
8918 if (afi == AFI_MAX)
8919 return CMD_WARNING_CONFIG_FAILED;
8920
8921 if (!yes) {
8922 /* implement me */
8923 vty_out(vty, "It's not implemented\n");
8924 return CMD_WARNING_CONFIG_FAILED;
8925 }
8926
8927 /* skip when it's already configured */
8928 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8929 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8930 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8931 return CMD_SUCCESS;
8932
8933 /*
8934 * mode change between sid_idx and sid_auto isn't supported.
8935 * user must negate sid vpn export when they want to change the mode
8936 */
8937 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8938 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8939 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8940 vty_out(vty, "it's already configured as %s.\n",
8941 sid_auto ? "auto-mode" : "idx-mode");
8942 return CMD_WARNING_CONFIG_FAILED;
8943 }
8944
8945 /* pre-change */
8946 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8947 bgp_get_default(), bgp);
8948
8949 if (sid_auto) {
8950 /* SID allocation auto-mode */
8951 if (debug)
8952 zlog_debug("%s: auto sid alloc.", __func__);
8953 SET_FLAG(bgp->vpn_policy[afi].flags,
8954 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8955 } else {
8956 /* SID allocation index-mode */
8957 if (debug)
8958 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8959 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8960 }
8961
8962 /* post-change */
8963 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8964 bgp_get_default(), bgp);
8965 return CMD_SUCCESS;
8966 }
8967
8968 ALIAS (af_label_vpn_export,
8969 af_no_label_vpn_export_cmd,
8970 "no label vpn export",
8971 NO_STR
8972 "label value for VRF\n"
8973 "Between current address-family and vpn\n"
8974 "For routes leaked from current address-family to vpn\n")
8975
8976 DEFPY (af_nexthop_vpn_export,
8977 af_nexthop_vpn_export_cmd,
8978 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8979 NO_STR
8980 "Specify next hop to use for VRF advertised prefixes\n"
8981 "Between current address-family and vpn\n"
8982 "For routes leaked from current address-family to vpn\n"
8983 "IPv4 prefix\n"
8984 "IPv6 prefix\n")
8985 {
8986 VTY_DECLVAR_CONTEXT(bgp, bgp);
8987 afi_t afi;
8988 struct prefix p;
8989
8990 if (!no) {
8991 if (!nexthop_su) {
8992 vty_out(vty, "%% Nexthop required\n");
8993 return CMD_WARNING_CONFIG_FAILED;
8994 }
8995 if (!sockunion2hostprefix(nexthop_su, &p))
8996 return CMD_WARNING_CONFIG_FAILED;
8997 }
8998
8999 afi = vpn_policy_getafi(vty, bgp, false);
9000 if (afi == AFI_MAX)
9001 return CMD_WARNING_CONFIG_FAILED;
9002
9003 /*
9004 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9005 */
9006 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9007 bgp_get_default(), bgp);
9008
9009 if (!no) {
9010 bgp->vpn_policy[afi].tovpn_nexthop = p;
9011 SET_FLAG(bgp->vpn_policy[afi].flags,
9012 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9013 } else {
9014 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9015 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9016 }
9017
9018 /* post-change: re-export vpn routes */
9019 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9020 bgp_get_default(), bgp);
9021
9022 return CMD_SUCCESS;
9023 }
9024
9025 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9026 {
9027 if (!strcmp(dstr, "import")) {
9028 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9029 } else if (!strcmp(dstr, "export")) {
9030 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9031 } else if (!strcmp(dstr, "both")) {
9032 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9033 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9034 } else {
9035 vty_out(vty, "%% direction parse error\n");
9036 return CMD_WARNING_CONFIG_FAILED;
9037 }
9038 return CMD_SUCCESS;
9039 }
9040
9041 DEFPY (af_rt_vpn_imexport,
9042 af_rt_vpn_imexport_cmd,
9043 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9044 NO_STR
9045 "Specify route target list\n"
9046 "Specify route target list\n"
9047 "Between current address-family and vpn\n"
9048 "For routes leaked from vpn to current address-family: match any\n"
9049 "For routes leaked from current address-family to vpn: set\n"
9050 "both import: match any and export: set\n"
9051 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9052 {
9053 VTY_DECLVAR_CONTEXT(bgp, bgp);
9054 int ret;
9055 struct ecommunity *ecom = NULL;
9056 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9057 enum vpn_policy_direction dir;
9058 afi_t afi;
9059 int idx = 0;
9060 bool yes = true;
9061
9062 if (argv_find(argv, argc, "no", &idx))
9063 yes = false;
9064
9065 afi = vpn_policy_getafi(vty, bgp, false);
9066 if (afi == AFI_MAX)
9067 return CMD_WARNING_CONFIG_FAILED;
9068
9069 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9070 if (ret != CMD_SUCCESS)
9071 return ret;
9072
9073 if (yes) {
9074 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9075 vty_out(vty, "%% Missing RTLIST\n");
9076 return CMD_WARNING_CONFIG_FAILED;
9077 }
9078 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9079 if (ret != CMD_SUCCESS) {
9080 return ret;
9081 }
9082 }
9083
9084 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9085 if (!dodir[dir])
9086 continue;
9087
9088 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9089
9090 if (yes) {
9091 if (bgp->vpn_policy[afi].rtlist[dir])
9092 ecommunity_free(
9093 &bgp->vpn_policy[afi].rtlist[dir]);
9094 bgp->vpn_policy[afi].rtlist[dir] =
9095 ecommunity_dup(ecom);
9096 } else {
9097 if (bgp->vpn_policy[afi].rtlist[dir])
9098 ecommunity_free(
9099 &bgp->vpn_policy[afi].rtlist[dir]);
9100 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9101 }
9102
9103 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9104 }
9105
9106 if (ecom)
9107 ecommunity_free(&ecom);
9108
9109 return CMD_SUCCESS;
9110 }
9111
9112 ALIAS (af_rt_vpn_imexport,
9113 af_no_rt_vpn_imexport_cmd,
9114 "no <rt|route-target> vpn <import|export|both>$direction_str",
9115 NO_STR
9116 "Specify route target list\n"
9117 "Specify route target list\n"
9118 "Between current address-family and vpn\n"
9119 "For routes leaked from vpn to current address-family\n"
9120 "For routes leaked from current address-family to vpn\n"
9121 "both import and export\n")
9122
9123 DEFPY (af_route_map_vpn_imexport,
9124 af_route_map_vpn_imexport_cmd,
9125 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9126 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9127 NO_STR
9128 "Specify route map\n"
9129 "Between current address-family and vpn\n"
9130 "For routes leaked from vpn to current address-family\n"
9131 "For routes leaked from current address-family to vpn\n"
9132 "name of route-map\n")
9133 {
9134 VTY_DECLVAR_CONTEXT(bgp, bgp);
9135 int ret;
9136 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9137 enum vpn_policy_direction dir;
9138 afi_t afi;
9139 int idx = 0;
9140 bool yes = true;
9141
9142 if (argv_find(argv, argc, "no", &idx))
9143 yes = false;
9144
9145 afi = vpn_policy_getafi(vty, bgp, false);
9146 if (afi == AFI_MAX)
9147 return CMD_WARNING_CONFIG_FAILED;
9148
9149 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9150 if (ret != CMD_SUCCESS)
9151 return ret;
9152
9153 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9154 if (!dodir[dir])
9155 continue;
9156
9157 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9158
9159 if (yes) {
9160 if (bgp->vpn_policy[afi].rmap_name[dir])
9161 XFREE(MTYPE_ROUTE_MAP_NAME,
9162 bgp->vpn_policy[afi].rmap_name[dir]);
9163 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9164 MTYPE_ROUTE_MAP_NAME, rmap_str);
9165 bgp->vpn_policy[afi].rmap[dir] =
9166 route_map_lookup_warn_noexist(vty, rmap_str);
9167 if (!bgp->vpn_policy[afi].rmap[dir])
9168 return CMD_SUCCESS;
9169 } else {
9170 if (bgp->vpn_policy[afi].rmap_name[dir])
9171 XFREE(MTYPE_ROUTE_MAP_NAME,
9172 bgp->vpn_policy[afi].rmap_name[dir]);
9173 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9174 bgp->vpn_policy[afi].rmap[dir] = NULL;
9175 }
9176
9177 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9178 }
9179
9180 return CMD_SUCCESS;
9181 }
9182
9183 ALIAS (af_route_map_vpn_imexport,
9184 af_no_route_map_vpn_imexport_cmd,
9185 "no route-map vpn <import|export>$direction_str",
9186 NO_STR
9187 "Specify route map\n"
9188 "Between current address-family and vpn\n"
9189 "For routes leaked from vpn to current address-family\n"
9190 "For routes leaked from current address-family to vpn\n")
9191
9192 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9193 "import vrf route-map RMAP$rmap_str",
9194 "Import routes from another VRF\n"
9195 "Vrf routes being filtered\n"
9196 "Specify route map\n"
9197 "name of route-map\n")
9198 {
9199 VTY_DECLVAR_CONTEXT(bgp, bgp);
9200 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9201 afi_t afi;
9202 struct bgp *bgp_default;
9203
9204 afi = vpn_policy_getafi(vty, bgp, true);
9205 if (afi == AFI_MAX)
9206 return CMD_WARNING_CONFIG_FAILED;
9207
9208 bgp_default = bgp_get_default();
9209 if (!bgp_default) {
9210 int32_t ret;
9211 as_t as = bgp->as;
9212
9213 /* Auto-create assuming the same AS */
9214 ret = bgp_get_vty(&bgp_default, &as, NULL,
9215 BGP_INSTANCE_TYPE_DEFAULT);
9216
9217 if (ret) {
9218 vty_out(vty,
9219 "VRF default is not configured as a bgp instance\n");
9220 return CMD_WARNING;
9221 }
9222 }
9223
9224 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9225
9226 if (bgp->vpn_policy[afi].rmap_name[dir])
9227 XFREE(MTYPE_ROUTE_MAP_NAME,
9228 bgp->vpn_policy[afi].rmap_name[dir]);
9229 bgp->vpn_policy[afi].rmap_name[dir] =
9230 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9231 bgp->vpn_policy[afi].rmap[dir] =
9232 route_map_lookup_warn_noexist(vty, rmap_str);
9233 if (!bgp->vpn_policy[afi].rmap[dir])
9234 return CMD_SUCCESS;
9235
9236 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9237 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9238
9239 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9240
9241 return CMD_SUCCESS;
9242 }
9243
9244 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9245 "no import vrf route-map [RMAP$rmap_str]",
9246 NO_STR
9247 "Import routes from another VRF\n"
9248 "Vrf routes being filtered\n"
9249 "Specify route map\n"
9250 "name of route-map\n")
9251 {
9252 VTY_DECLVAR_CONTEXT(bgp, bgp);
9253 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9254 afi_t afi;
9255
9256 afi = vpn_policy_getafi(vty, bgp, true);
9257 if (afi == AFI_MAX)
9258 return CMD_WARNING_CONFIG_FAILED;
9259
9260 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9261
9262 if (bgp->vpn_policy[afi].rmap_name[dir])
9263 XFREE(MTYPE_ROUTE_MAP_NAME,
9264 bgp->vpn_policy[afi].rmap_name[dir]);
9265 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9266 bgp->vpn_policy[afi].rmap[dir] = NULL;
9267
9268 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9269 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9270 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9271
9272 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9273
9274 return CMD_SUCCESS;
9275 }
9276
9277 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9278 "[no] import vrf VIEWVRFNAME$import_name",
9279 NO_STR
9280 "Import routes from another VRF\n"
9281 "VRF to import from\n"
9282 "The name of the VRF\n")
9283 {
9284 VTY_DECLVAR_CONTEXT(bgp, bgp);
9285 struct listnode *node;
9286 struct bgp *vrf_bgp, *bgp_default;
9287 int32_t ret = 0;
9288 as_t as = bgp->as;
9289 bool remove = false;
9290 int32_t idx = 0;
9291 char *vname;
9292 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9293 safi_t safi;
9294 afi_t afi;
9295
9296 if (import_name == NULL) {
9297 vty_out(vty, "%% Missing import name\n");
9298 return CMD_WARNING;
9299 }
9300
9301 if (strcmp(import_name, "route-map") == 0) {
9302 vty_out(vty, "%% Must include route-map name\n");
9303 return CMD_WARNING;
9304 }
9305
9306 if (argv_find(argv, argc, "no", &idx))
9307 remove = true;
9308
9309 afi = vpn_policy_getafi(vty, bgp, true);
9310 if (afi == AFI_MAX)
9311 return CMD_WARNING_CONFIG_FAILED;
9312
9313 safi = bgp_node_safi(vty);
9314
9315 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9316 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9317 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9318 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9319 remove ? "unimport" : "import", import_name);
9320 return CMD_WARNING;
9321 }
9322
9323 bgp_default = bgp_get_default();
9324 if (!bgp_default) {
9325 /* Auto-create assuming the same AS */
9326 ret = bgp_get_vty(&bgp_default, &as, NULL,
9327 BGP_INSTANCE_TYPE_DEFAULT);
9328
9329 if (ret) {
9330 vty_out(vty,
9331 "VRF default is not configured as a bgp instance\n");
9332 return CMD_WARNING;
9333 }
9334 }
9335
9336 vrf_bgp = bgp_lookup_by_name(import_name);
9337 if (!vrf_bgp) {
9338 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9339 vrf_bgp = bgp_default;
9340 else
9341 /* Auto-create assuming the same AS */
9342 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9343
9344 if (ret) {
9345 vty_out(vty,
9346 "VRF %s is not configured as a bgp instance\n",
9347 import_name);
9348 return CMD_WARNING;
9349 }
9350 }
9351
9352 if (remove) {
9353 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9354 } else {
9355 /* Already importing from "import_vrf"? */
9356 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9357 vname)) {
9358 if (strcmp(vname, import_name) == 0)
9359 return CMD_WARNING;
9360 }
9361
9362 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9363 }
9364
9365 return CMD_SUCCESS;
9366 }
9367
9368 /* This command is valid only in a bgp vrf instance or the default instance */
9369 DEFPY (bgp_imexport_vpn,
9370 bgp_imexport_vpn_cmd,
9371 "[no] <import|export>$direction_str vpn",
9372 NO_STR
9373 "Import routes to this address-family\n"
9374 "Export routes from this address-family\n"
9375 "to/from default instance VPN RIB\n")
9376 {
9377 VTY_DECLVAR_CONTEXT(bgp, bgp);
9378 int previous_state;
9379 afi_t afi;
9380 safi_t safi;
9381 int idx = 0;
9382 bool yes = true;
9383 int flag;
9384 enum vpn_policy_direction dir;
9385
9386 if (argv_find(argv, argc, "no", &idx))
9387 yes = false;
9388
9389 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9390 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9391
9392 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9393 return CMD_WARNING_CONFIG_FAILED;
9394 }
9395
9396 afi = bgp_node_afi(vty);
9397 safi = bgp_node_safi(vty);
9398 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9399 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9400 return CMD_WARNING_CONFIG_FAILED;
9401 }
9402
9403 if (!strcmp(direction_str, "import")) {
9404 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9405 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9406 } else if (!strcmp(direction_str, "export")) {
9407 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9408 dir = BGP_VPN_POLICY_DIR_TOVPN;
9409 } else {
9410 vty_out(vty, "%% unknown direction %s\n", direction_str);
9411 return CMD_WARNING_CONFIG_FAILED;
9412 }
9413
9414 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9415
9416 if (yes) {
9417 SET_FLAG(bgp->af_flags[afi][safi], flag);
9418 if (!previous_state) {
9419 /* trigger export current vrf */
9420 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9421 }
9422 } else {
9423 if (previous_state) {
9424 /* trigger un-export current vrf */
9425 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9426 }
9427 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9428 }
9429
9430 hook_call(bgp_snmp_init_stats, bgp);
9431
9432 return CMD_SUCCESS;
9433 }
9434
9435 DEFPY (af_routetarget_import,
9436 af_routetarget_import_cmd,
9437 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9438 NO_STR
9439 "Specify route target list\n"
9440 "Specify route target list\n"
9441 "Specify route target list\n"
9442 "Specify route target list\n"
9443 "Flow-spec redirect type route target\n"
9444 "Import routes to this address-family\n"
9445 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9446 {
9447 VTY_DECLVAR_CONTEXT(bgp, bgp);
9448 int ret;
9449 struct ecommunity *ecom = NULL;
9450 afi_t afi;
9451 int idx = 0, idx_unused = 0;
9452 bool yes = true;
9453 bool rt6 = false;
9454
9455 if (argv_find(argv, argc, "no", &idx))
9456 yes = false;
9457
9458 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9459 argv_find(argv, argc, "route-target6", &idx_unused))
9460 rt6 = true;
9461
9462 afi = vpn_policy_getafi(vty, bgp, false);
9463 if (afi == AFI_MAX)
9464 return CMD_WARNING_CONFIG_FAILED;
9465
9466 if (rt6 && afi != AFI_IP6)
9467 return CMD_WARNING_CONFIG_FAILED;
9468
9469 if (yes) {
9470 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9471 vty_out(vty, "%% Missing RTLIST\n");
9472 return CMD_WARNING_CONFIG_FAILED;
9473 }
9474 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9475 if (ret != CMD_SUCCESS)
9476 return ret;
9477 }
9478
9479 if (yes) {
9480 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9481 ecommunity_free(&bgp->vpn_policy[afi]
9482 .import_redirect_rtlist);
9483 bgp->vpn_policy[afi].import_redirect_rtlist =
9484 ecommunity_dup(ecom);
9485 } else {
9486 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9487 ecommunity_free(&bgp->vpn_policy[afi]
9488 .import_redirect_rtlist);
9489 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9490 }
9491
9492 if (ecom)
9493 ecommunity_free(&ecom);
9494
9495 return CMD_SUCCESS;
9496 }
9497
9498 DEFUN_NOSH (address_family_ipv4_safi,
9499 address_family_ipv4_safi_cmd,
9500 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9501 "Enter Address Family command mode\n"
9502 BGP_AF_STR
9503 BGP_SAFI_WITH_LABEL_HELP_STR)
9504 {
9505
9506 if (argc == 3) {
9507 VTY_DECLVAR_CONTEXT(bgp, bgp);
9508 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9509 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9510 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9511 && safi != SAFI_EVPN) {
9512 vty_out(vty,
9513 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9514 return CMD_WARNING_CONFIG_FAILED;
9515 }
9516 vty->node = bgp_node_type(AFI_IP, safi);
9517 } else
9518 vty->node = BGP_IPV4_NODE;
9519
9520 return CMD_SUCCESS;
9521 }
9522
9523 DEFUN_NOSH (address_family_ipv6_safi,
9524 address_family_ipv6_safi_cmd,
9525 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9526 "Enter Address Family command mode\n"
9527 BGP_AF_STR
9528 BGP_SAFI_WITH_LABEL_HELP_STR)
9529 {
9530 if (argc == 3) {
9531 VTY_DECLVAR_CONTEXT(bgp, bgp);
9532 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9533 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9534 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9535 && safi != SAFI_EVPN) {
9536 vty_out(vty,
9537 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9538 return CMD_WARNING_CONFIG_FAILED;
9539 }
9540 vty->node = bgp_node_type(AFI_IP6, safi);
9541 } else
9542 vty->node = BGP_IPV6_NODE;
9543
9544 return CMD_SUCCESS;
9545 }
9546
9547 #ifdef KEEP_OLD_VPN_COMMANDS
9548 DEFUN_NOSH (address_family_vpnv4,
9549 address_family_vpnv4_cmd,
9550 "address-family vpnv4 [unicast]",
9551 "Enter Address Family command mode\n"
9552 BGP_AF_STR
9553 BGP_AF_MODIFIER_STR)
9554 {
9555 vty->node = BGP_VPNV4_NODE;
9556 return CMD_SUCCESS;
9557 }
9558
9559 DEFUN_NOSH (address_family_vpnv6,
9560 address_family_vpnv6_cmd,
9561 "address-family vpnv6 [unicast]",
9562 "Enter Address Family command mode\n"
9563 BGP_AF_STR
9564 BGP_AF_MODIFIER_STR)
9565 {
9566 vty->node = BGP_VPNV6_NODE;
9567 return CMD_SUCCESS;
9568 }
9569 #endif /* KEEP_OLD_VPN_COMMANDS */
9570
9571 DEFUN_NOSH (address_family_evpn,
9572 address_family_evpn_cmd,
9573 "address-family l2vpn evpn",
9574 "Enter Address Family command mode\n"
9575 BGP_AF_STR
9576 BGP_AF_MODIFIER_STR)
9577 {
9578 VTY_DECLVAR_CONTEXT(bgp, bgp);
9579 vty->node = BGP_EVPN_NODE;
9580 return CMD_SUCCESS;
9581 }
9582
9583 DEFUN_NOSH (bgp_segment_routing_srv6,
9584 bgp_segment_routing_srv6_cmd,
9585 "segment-routing srv6",
9586 "Segment-Routing configuration\n"
9587 "Segment-Routing SRv6 configuration\n")
9588 {
9589 VTY_DECLVAR_CONTEXT(bgp, bgp);
9590 bgp->srv6_enabled = true;
9591 vty->node = BGP_SRV6_NODE;
9592 return CMD_SUCCESS;
9593 }
9594
9595 DEFUN (no_bgp_segment_routing_srv6,
9596 no_bgp_segment_routing_srv6_cmd,
9597 "no segment-routing srv6",
9598 NO_STR
9599 "Segment-Routing configuration\n"
9600 "Segment-Routing SRv6 configuration\n")
9601 {
9602 VTY_DECLVAR_CONTEXT(bgp, bgp);
9603
9604 if (strlen(bgp->srv6_locator_name) > 0)
9605 if (bgp_srv6_locator_unset(bgp) < 0)
9606 return CMD_WARNING_CONFIG_FAILED;
9607
9608 bgp->srv6_enabled = false;
9609 return CMD_SUCCESS;
9610 }
9611
9612 DEFPY (bgp_srv6_locator,
9613 bgp_srv6_locator_cmd,
9614 "locator NAME$name",
9615 "Specify SRv6 locator\n"
9616 "Specify SRv6 locator\n")
9617 {
9618 VTY_DECLVAR_CONTEXT(bgp, bgp);
9619 int ret;
9620
9621 if (strlen(bgp->srv6_locator_name) > 0
9622 && strcmp(name, bgp->srv6_locator_name) != 0) {
9623 vty_out(vty, "srv6 locator is already configured\n");
9624 return CMD_WARNING_CONFIG_FAILED;
9625 }
9626
9627 snprintf(bgp->srv6_locator_name,
9628 sizeof(bgp->srv6_locator_name), "%s", name);
9629
9630 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9631 if (ret < 0)
9632 return CMD_WARNING_CONFIG_FAILED;
9633
9634 return CMD_SUCCESS;
9635 }
9636
9637 DEFPY (no_bgp_srv6_locator,
9638 no_bgp_srv6_locator_cmd,
9639 "no locator NAME$name",
9640 NO_STR
9641 "Specify SRv6 locator\n"
9642 "Specify SRv6 locator\n")
9643 {
9644 VTY_DECLVAR_CONTEXT(bgp, bgp);
9645
9646 /* when locator isn't configured, do nothing */
9647 if (strlen(bgp->srv6_locator_name) < 1)
9648 return CMD_SUCCESS;
9649
9650 /* name validation */
9651 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9652 vty_out(vty, "%% No srv6 locator is configured\n");
9653 return CMD_WARNING_CONFIG_FAILED;
9654 }
9655
9656 /* unset locator */
9657 if (bgp_srv6_locator_unset(bgp) < 0)
9658 return CMD_WARNING_CONFIG_FAILED;
9659
9660 return CMD_SUCCESS;
9661 }
9662
9663 DEFPY (show_bgp_srv6,
9664 show_bgp_srv6_cmd,
9665 "show bgp segment-routing srv6",
9666 SHOW_STR
9667 BGP_STR
9668 "BGP Segment Routing\n"
9669 "BGP Segment Routing SRv6\n")
9670 {
9671 struct bgp *bgp;
9672 struct listnode *node;
9673 struct srv6_locator_chunk *chunk;
9674 struct bgp_srv6_function *func;
9675 char buf[256];
9676
9677 bgp = bgp_get_default();
9678 if (!bgp)
9679 return CMD_SUCCESS;
9680
9681 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9682 vty_out(vty, "locator_chunks:\n");
9683 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk))
9684 vty_out(vty, "- %pFX\n", &chunk->prefix);
9685
9686 vty_out(vty, "functions:\n");
9687 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9688 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9689 vty_out(vty, "- sid: %s\n", buf);
9690 vty_out(vty, " locator: %s\n", func->locator_name);
9691 }
9692
9693 vty_out(vty, "bgps:\n");
9694 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9695 vty_out(vty, "- name: %s\n",
9696 bgp->name ? bgp->name : "default");
9697
9698 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9699 bgp->vpn_policy[AFI_IP].tovpn_sid);
9700 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9701 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9702 }
9703
9704 return CMD_SUCCESS;
9705 }
9706
9707 DEFUN_NOSH (exit_address_family,
9708 exit_address_family_cmd,
9709 "exit-address-family",
9710 "Exit from Address Family configuration mode\n")
9711 {
9712 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9713 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9714 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9715 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9716 || vty->node == BGP_EVPN_NODE
9717 || vty->node == BGP_FLOWSPECV4_NODE
9718 || vty->node == BGP_FLOWSPECV6_NODE)
9719 vty->node = BGP_NODE;
9720 return CMD_SUCCESS;
9721 }
9722
9723 /* Recalculate bestpath and re-advertise a prefix */
9724 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9725 const char *ip_str, afi_t afi, safi_t safi,
9726 struct prefix_rd *prd)
9727 {
9728 int ret;
9729 struct prefix match;
9730 struct bgp_dest *dest;
9731 struct bgp_dest *rm;
9732 struct bgp *bgp;
9733 struct bgp_table *table;
9734 struct bgp_table *rib;
9735
9736 /* BGP structure lookup. */
9737 if (view_name) {
9738 bgp = bgp_lookup_by_name(view_name);
9739 if (bgp == NULL) {
9740 vty_out(vty, "%% Can't find BGP instance %s\n",
9741 view_name);
9742 return CMD_WARNING;
9743 }
9744 } else {
9745 bgp = bgp_get_default();
9746 if (bgp == NULL) {
9747 vty_out(vty, "%% No BGP process is configured\n");
9748 return CMD_WARNING;
9749 }
9750 }
9751
9752 /* Check IP address argument. */
9753 ret = str2prefix(ip_str, &match);
9754 if (!ret) {
9755 vty_out(vty, "%% address is malformed\n");
9756 return CMD_WARNING;
9757 }
9758
9759 match.family = afi2family(afi);
9760 rib = bgp->rib[afi][safi];
9761
9762 if (safi == SAFI_MPLS_VPN) {
9763 for (dest = bgp_table_top(rib); dest;
9764 dest = bgp_route_next(dest)) {
9765 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9766
9767 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9768 continue;
9769
9770 table = bgp_dest_get_bgp_table_info(dest);
9771 if (table == NULL)
9772 continue;
9773
9774 rm = bgp_node_match(table, &match);
9775 if (rm != NULL) {
9776 const struct prefix *rm_p =
9777 bgp_dest_get_prefix(rm);
9778
9779 if (rm_p->prefixlen == match.prefixlen) {
9780 SET_FLAG(rm->flags,
9781 BGP_NODE_USER_CLEAR);
9782 bgp_process(bgp, rm, afi, safi);
9783 }
9784 bgp_dest_unlock_node(rm);
9785 }
9786 }
9787 } else {
9788 dest = bgp_node_match(rib, &match);
9789 if (dest != NULL) {
9790 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9791
9792 if (dest_p->prefixlen == match.prefixlen) {
9793 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9794 bgp_process(bgp, dest, afi, safi);
9795 }
9796 bgp_dest_unlock_node(dest);
9797 }
9798 }
9799
9800 return CMD_SUCCESS;
9801 }
9802
9803 /* one clear bgp command to rule them all */
9804 DEFUN (clear_ip_bgp_all,
9805 clear_ip_bgp_all_cmd,
9806 "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>]",
9807 CLEAR_STR
9808 IP_STR
9809 BGP_STR
9810 BGP_INSTANCE_HELP_STR
9811 BGP_AFI_HELP_STR
9812 BGP_AF_STR
9813 BGP_SAFI_WITH_LABEL_HELP_STR
9814 BGP_AF_MODIFIER_STR
9815 "Clear all peers\n"
9816 "BGP IPv4 neighbor to clear\n"
9817 "BGP IPv6 neighbor to clear\n"
9818 "BGP neighbor on interface to clear\n"
9819 "Clear peers with the AS number\n"
9820 "Clear all external peers\n"
9821 "Clear all members of peer-group\n"
9822 "BGP peer-group name\n"
9823 BGP_SOFT_STR
9824 BGP_SOFT_IN_STR
9825 BGP_SOFT_OUT_STR
9826 BGP_SOFT_IN_STR
9827 "Push out prefix-list ORF and do inbound soft reconfig\n"
9828 BGP_SOFT_OUT_STR
9829 "Reset message statistics\n")
9830 {
9831 char *vrf = NULL;
9832
9833 afi_t afi = AFI_UNSPEC;
9834 safi_t safi = SAFI_UNSPEC;
9835 enum clear_sort clr_sort = clear_peer;
9836 enum bgp_clear_type clr_type;
9837 char *clr_arg = NULL;
9838
9839 int idx = 0;
9840
9841 /* clear [ip] bgp */
9842 if (argv_find(argv, argc, "ip", &idx))
9843 afi = AFI_IP;
9844
9845 /* [<vrf> VIEWVRFNAME] */
9846 if (argv_find(argv, argc, "vrf", &idx)) {
9847 vrf = argv[idx + 1]->arg;
9848 idx += 2;
9849 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9850 vrf = NULL;
9851 } else if (argv_find(argv, argc, "view", &idx)) {
9852 /* [<view> VIEWVRFNAME] */
9853 vrf = argv[idx + 1]->arg;
9854 idx += 2;
9855 }
9856 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9857 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9858 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9859
9860 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9861 if (argv_find(argv, argc, "*", &idx)) {
9862 clr_sort = clear_all;
9863 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9864 clr_sort = clear_peer;
9865 clr_arg = argv[idx]->arg;
9866 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9867 clr_sort = clear_peer;
9868 clr_arg = argv[idx]->arg;
9869 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9870 clr_sort = clear_group;
9871 idx++;
9872 clr_arg = argv[idx]->arg;
9873 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9874 clr_sort = clear_peer;
9875 clr_arg = argv[idx]->arg;
9876 } else if (argv_find(argv, argc, "WORD", &idx)) {
9877 clr_sort = clear_peer;
9878 clr_arg = argv[idx]->arg;
9879 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9880 clr_sort = clear_as;
9881 clr_arg = argv[idx]->arg;
9882 } else if (argv_find(argv, argc, "external", &idx)) {
9883 clr_sort = clear_external;
9884 }
9885
9886 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9887 if (argv_find(argv, argc, "soft", &idx)) {
9888 if (argv_find(argv, argc, "in", &idx)
9889 || argv_find(argv, argc, "out", &idx))
9890 clr_type = strmatch(argv[idx]->text, "in")
9891 ? BGP_CLEAR_SOFT_IN
9892 : BGP_CLEAR_SOFT_OUT;
9893 else
9894 clr_type = BGP_CLEAR_SOFT_BOTH;
9895 } else if (argv_find(argv, argc, "in", &idx)) {
9896 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9897 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9898 : BGP_CLEAR_SOFT_IN;
9899 } else if (argv_find(argv, argc, "out", &idx)) {
9900 clr_type = BGP_CLEAR_SOFT_OUT;
9901 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9902 clr_type = BGP_CLEAR_MESSAGE_STATS;
9903 } else
9904 clr_type = BGP_CLEAR_SOFT_NONE;
9905
9906 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9907 }
9908
9909 DEFUN (clear_ip_bgp_prefix,
9910 clear_ip_bgp_prefix_cmd,
9911 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9912 CLEAR_STR
9913 IP_STR
9914 BGP_STR
9915 BGP_INSTANCE_HELP_STR
9916 "Clear bestpath and re-advertise\n"
9917 "IPv4 prefix\n")
9918 {
9919 char *vrf = NULL;
9920 char *prefix = NULL;
9921
9922 int idx = 0;
9923
9924 /* [<view|vrf> VIEWVRFNAME] */
9925 if (argv_find(argv, argc, "vrf", &idx)) {
9926 vrf = argv[idx + 1]->arg;
9927 idx += 2;
9928 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9929 vrf = NULL;
9930 } else if (argv_find(argv, argc, "view", &idx)) {
9931 /* [<view> VIEWVRFNAME] */
9932 vrf = argv[idx + 1]->arg;
9933 idx += 2;
9934 }
9935
9936 prefix = argv[argc - 1]->arg;
9937
9938 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9939 }
9940
9941 DEFUN (clear_bgp_ipv6_safi_prefix,
9942 clear_bgp_ipv6_safi_prefix_cmd,
9943 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9944 CLEAR_STR
9945 IP_STR
9946 BGP_STR
9947 BGP_AF_STR
9948 BGP_SAFI_HELP_STR
9949 "Clear bestpath and re-advertise\n"
9950 "IPv6 prefix\n")
9951 {
9952 int idx_safi = 0;
9953 int idx_ipv6_prefix = 0;
9954 safi_t safi = SAFI_UNICAST;
9955 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9956 argv[idx_ipv6_prefix]->arg : NULL;
9957
9958 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9959 return bgp_clear_prefix(
9960 vty, NULL, prefix, AFI_IP6,
9961 safi, NULL);
9962 }
9963
9964 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9965 clear_bgp_instance_ipv6_safi_prefix_cmd,
9966 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9967 CLEAR_STR
9968 IP_STR
9969 BGP_STR
9970 BGP_INSTANCE_HELP_STR
9971 BGP_AF_STR
9972 BGP_SAFI_HELP_STR
9973 "Clear bestpath and re-advertise\n"
9974 "IPv6 prefix\n")
9975 {
9976 int idx_safi = 0;
9977 int idx_vrfview = 0;
9978 int idx_ipv6_prefix = 0;
9979 safi_t safi = SAFI_UNICAST;
9980 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9981 argv[idx_ipv6_prefix]->arg : NULL;
9982 char *vrfview = NULL;
9983
9984 /* [<view|vrf> VIEWVRFNAME] */
9985 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9986 vrfview = argv[idx_vrfview + 1]->arg;
9987 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9988 vrfview = NULL;
9989 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9990 /* [<view> VIEWVRFNAME] */
9991 vrfview = argv[idx_vrfview + 1]->arg;
9992 }
9993 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9994
9995 return bgp_clear_prefix(
9996 vty, vrfview, prefix,
9997 AFI_IP6, safi, NULL);
9998 }
9999
10000 DEFUN (show_bgp_views,
10001 show_bgp_views_cmd,
10002 "show [ip] bgp views",
10003 SHOW_STR
10004 IP_STR
10005 BGP_STR
10006 "Show the defined BGP views\n")
10007 {
10008 struct list *inst = bm->bgp;
10009 struct listnode *node;
10010 struct bgp *bgp;
10011
10012 vty_out(vty, "Defined BGP views:\n");
10013 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10014 /* Skip VRFs. */
10015 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10016 continue;
10017 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10018 bgp->as);
10019 }
10020
10021 return CMD_SUCCESS;
10022 }
10023
10024 DEFUN (show_bgp_vrfs,
10025 show_bgp_vrfs_cmd,
10026 "show [ip] bgp vrfs [json]",
10027 SHOW_STR
10028 IP_STR
10029 BGP_STR
10030 "Show BGP VRFs\n"
10031 JSON_STR)
10032 {
10033 char buf[ETHER_ADDR_STRLEN];
10034 struct list *inst = bm->bgp;
10035 struct listnode *node;
10036 struct bgp *bgp;
10037 bool uj = use_json(argc, argv);
10038 json_object *json = NULL;
10039 json_object *json_vrfs = NULL;
10040 int count = 0;
10041
10042 if (uj) {
10043 json = json_object_new_object();
10044 json_vrfs = json_object_new_object();
10045 }
10046
10047 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10048 const char *name, *type;
10049 struct peer *peer;
10050 struct listnode *node2, *nnode2;
10051 int peers_cfg, peers_estb;
10052 json_object *json_vrf = NULL;
10053
10054 /* Skip Views. */
10055 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10056 continue;
10057
10058 count++;
10059 if (!uj && count == 1) {
10060 vty_out(vty,
10061 "%4s %-5s %-16s %9s %10s %-37s\n",
10062 "Type", "Id", "routerId", "#PeersCfg",
10063 "#PeersEstb", "Name");
10064 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10065 "L3-VNI", "RouterMAC", "Interface");
10066 }
10067
10068 peers_cfg = peers_estb = 0;
10069 if (uj)
10070 json_vrf = json_object_new_object();
10071
10072
10073 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10074 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10075 continue;
10076 peers_cfg++;
10077 if (peer_established(peer))
10078 peers_estb++;
10079 }
10080
10081 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10082 name = VRF_DEFAULT_NAME;
10083 type = "DFLT";
10084 } else {
10085 name = bgp->name;
10086 type = "VRF";
10087 }
10088
10089
10090 if (uj) {
10091 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10092 ? -1
10093 : (int64_t)bgp->vrf_id;
10094 char buf[BUFSIZ] = {0};
10095
10096 json_object_string_add(json_vrf, "type", type);
10097 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10098 json_object_string_addf(json_vrf, "routerId", "%pI4",
10099 &bgp->router_id);
10100 json_object_int_add(json_vrf, "numConfiguredPeers",
10101 peers_cfg);
10102 json_object_int_add(json_vrf, "numEstablishedPeers",
10103 peers_estb);
10104
10105 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10106 json_object_string_add(
10107 json_vrf, "rmac",
10108 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10109 json_object_string_add(json_vrf, "interface",
10110 ifindex2ifname(bgp->l3vni_svi_ifindex,
10111 bgp->vrf_id));
10112 json_object_object_add(json_vrfs, name, json_vrf);
10113 } else {
10114 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10115 type,
10116 bgp->vrf_id == VRF_UNKNOWN ? -1
10117 : (int)bgp->vrf_id,
10118 &bgp->router_id, peers_cfg, peers_estb, name);
10119 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10120 bgp->l3vni,
10121 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10122 ifindex2ifname(bgp->l3vni_svi_ifindex,
10123 bgp->vrf_id));
10124 }
10125 }
10126
10127 if (uj) {
10128 json_object_object_add(json, "vrfs", json_vrfs);
10129
10130 json_object_int_add(json, "totalVrfs", count);
10131
10132 vty_json(vty, json);
10133 } else {
10134 if (count)
10135 vty_out(vty,
10136 "\nTotal number of VRFs (including default): %d\n",
10137 count);
10138 }
10139
10140 return CMD_SUCCESS;
10141 }
10142
10143 DEFUN (show_bgp_mac_hash,
10144 show_bgp_mac_hash_cmd,
10145 "show bgp mac hash",
10146 SHOW_STR
10147 BGP_STR
10148 "Mac Address\n"
10149 "Mac Address database\n")
10150 {
10151 bgp_mac_dump_table(vty);
10152
10153 return CMD_SUCCESS;
10154 }
10155
10156 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10157 {
10158 struct vty *vty = (struct vty *)args;
10159 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10160
10161 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10162 }
10163
10164 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10165 {
10166 vty_out(vty, "self nexthop database:\n");
10167 bgp_nexthop_show_address_hash(vty, bgp);
10168
10169 vty_out(vty, "Tunnel-ip database:\n");
10170 hash_iterate(bgp->tip_hash,
10171 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10172 vty);
10173 }
10174
10175 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10176 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10177 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10178 "martian next-hops\n"
10179 "martian next-hop database\n")
10180 {
10181 struct bgp *bgp = NULL;
10182 int idx = 0;
10183 char *name = NULL;
10184
10185 /* [<vrf> VIEWVRFNAME] */
10186 if (argv_find(argv, argc, "vrf", &idx)) {
10187 name = argv[idx + 1]->arg;
10188 if (name && strmatch(name, VRF_DEFAULT_NAME))
10189 name = NULL;
10190 } else if (argv_find(argv, argc, "view", &idx))
10191 /* [<view> VIEWVRFNAME] */
10192 name = argv[idx + 1]->arg;
10193 if (name)
10194 bgp = bgp_lookup_by_name(name);
10195 else
10196 bgp = bgp_get_default();
10197
10198 if (!bgp) {
10199 vty_out(vty, "%% No BGP process is configured\n");
10200 return CMD_WARNING;
10201 }
10202 bgp_show_martian_nexthops(vty, bgp);
10203
10204 return CMD_SUCCESS;
10205 }
10206
10207 DEFUN (show_bgp_memory,
10208 show_bgp_memory_cmd,
10209 "show [ip] bgp memory",
10210 SHOW_STR
10211 IP_STR
10212 BGP_STR
10213 "Global BGP memory statistics\n")
10214 {
10215 char memstrbuf[MTYPE_MEMSTR_LEN];
10216 unsigned long count;
10217
10218 /* RIB related usage stats */
10219 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10220 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10221 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10222 count * sizeof(struct bgp_dest)));
10223
10224 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10225 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10226 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10227 count * sizeof(struct bgp_path_info)));
10228 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10229 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10230 count,
10231 mtype_memstr(
10232 memstrbuf, sizeof(memstrbuf),
10233 count * sizeof(struct bgp_path_info_extra)));
10234
10235 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10236 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10237 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10238 count * sizeof(struct bgp_static)));
10239
10240 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10241 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10242 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10243 count * sizeof(struct bpacket)));
10244
10245 /* Adj-In/Out */
10246 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10247 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10248 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10249 count * sizeof(struct bgp_adj_in)));
10250 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10251 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10252 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10253 count * sizeof(struct bgp_adj_out)));
10254
10255 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10256 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10257 count,
10258 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10259 count * sizeof(struct bgp_nexthop_cache)));
10260
10261 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10262 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10263 count,
10264 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10265 count * sizeof(struct bgp_damp_info)));
10266
10267 /* Attributes */
10268 count = attr_count();
10269 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10270 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10271 count * sizeof(struct attr)));
10272
10273 if ((count = attr_unknown_count()))
10274 vty_out(vty, "%ld unknown attributes\n", count);
10275
10276 /* AS_PATH attributes */
10277 count = aspath_count();
10278 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10279 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10280 count * sizeof(struct aspath)));
10281
10282 count = mtype_stats_alloc(MTYPE_AS_SEG);
10283 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10284 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10285 count * sizeof(struct assegment)));
10286
10287 /* Other attributes */
10288 if ((count = community_count()))
10289 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10290 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10291 count * sizeof(struct community)));
10292 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10293 vty_out(vty,
10294 "%ld BGP ext-community entries, using %s of memory\n",
10295 count,
10296 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10297 count * sizeof(struct ecommunity)));
10298 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10299 vty_out(vty,
10300 "%ld BGP large-community entries, using %s of memory\n",
10301 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10302 count * sizeof(struct lcommunity)));
10303
10304 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10305 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10306 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10307 count * sizeof(struct cluster_list)));
10308
10309 /* Peer related usage */
10310 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10311 vty_out(vty, "%ld peers, using %s of memory\n", count,
10312 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10313 count * sizeof(struct peer)));
10314
10315 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10316 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10317 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10318 count * sizeof(struct peer_group)));
10319
10320 /* Other */
10321 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10322 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10323 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10324 count * sizeof(regex_t)));
10325 return CMD_SUCCESS;
10326 }
10327
10328 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10329 {
10330 json_object *bestpath = json_object_new_object();
10331
10332 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10333 json_object_string_add(bestpath, "asPath", "ignore");
10334
10335 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10336 json_object_string_add(bestpath, "asPath", "confed");
10337
10338 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10339 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10340 json_object_string_add(bestpath, "multiPathRelax",
10341 "as-set");
10342 else
10343 json_object_string_add(bestpath, "multiPathRelax",
10344 "true");
10345 } else
10346 json_object_string_add(bestpath, "multiPathRelax", "false");
10347
10348 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10349 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10350
10351 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10352 json_object_string_add(bestpath, "compareRouterId", "true");
10353 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10354 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10355 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10356 json_object_string_add(bestpath, "med", "confed");
10357 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10358 json_object_string_add(bestpath, "med",
10359 "missing-as-worst");
10360 else
10361 json_object_string_add(bestpath, "med", "true");
10362 }
10363
10364 json_object_object_add(json, "bestPath", bestpath);
10365 }
10366
10367 /* Print the error code/subcode for why the peer is down */
10368 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10369 json_object *json_peer, bool use_json)
10370 {
10371 const char *code_str;
10372 const char *subcode_str;
10373
10374 if (use_json) {
10375 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10376 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10377 char errorcodesubcode_hexstr[5];
10378 char errorcodesubcode_str[256];
10379
10380 code_str = bgp_notify_code_str(peer->notify.code);
10381 subcode_str = bgp_notify_subcode_str(
10382 peer->notify.code,
10383 peer->notify.subcode);
10384
10385 snprintf(errorcodesubcode_hexstr,
10386 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10387 peer->notify.code, peer->notify.subcode);
10388 json_object_string_add(json_peer,
10389 "lastErrorCodeSubcode",
10390 errorcodesubcode_hexstr);
10391 snprintf(errorcodesubcode_str, 255, "%s%s",
10392 code_str, subcode_str);
10393 json_object_string_add(json_peer,
10394 "lastNotificationReason",
10395 errorcodesubcode_str);
10396 json_object_boolean_add(json_peer,
10397 "lastNotificationHardReset",
10398 peer->notify.hard_reset);
10399 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10400 && peer->notify.code == BGP_NOTIFY_CEASE
10401 && (peer->notify.subcode
10402 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10403 || peer->notify.subcode
10404 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10405 && peer->notify.length) {
10406 char msgbuf[1024];
10407 const char *msg_str;
10408
10409 msg_str = bgp_notify_admin_message(
10410 msgbuf, sizeof(msgbuf),
10411 (uint8_t *)peer->notify.data,
10412 peer->notify.length);
10413 if (msg_str)
10414 json_object_string_add(
10415 json_peer,
10416 "lastShutdownDescription",
10417 msg_str);
10418 }
10419
10420 }
10421 json_object_string_add(json_peer, "lastResetDueTo",
10422 peer_down_str[(int)peer->last_reset]);
10423 json_object_int_add(json_peer, "lastResetCode",
10424 peer->last_reset);
10425 } else {
10426 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10427 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10428 code_str = bgp_notify_code_str(peer->notify.code);
10429 subcode_str =
10430 bgp_notify_subcode_str(peer->notify.code,
10431 peer->notify.subcode);
10432 vty_out(vty, " Notification %s (%s%s%s)\n",
10433 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10434 ? "sent"
10435 : "received",
10436 code_str, subcode_str,
10437 peer->notify.hard_reset
10438 ? bgp_notify_subcode_str(
10439 BGP_NOTIFY_CEASE,
10440 BGP_NOTIFY_CEASE_HARD_RESET)
10441 : "");
10442 } else {
10443 vty_out(vty, " %s\n",
10444 peer_down_str[(int)peer->last_reset]);
10445 }
10446 }
10447 }
10448
10449 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10450 safi_t safi)
10451 {
10452 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10453 }
10454
10455 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10456 struct peer *peer, json_object *json_peer,
10457 int max_neighbor_width, bool use_json)
10458 {
10459 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10460 int len;
10461
10462 if (use_json) {
10463 if (peer_dynamic_neighbor(peer))
10464 json_object_boolean_true_add(json_peer,
10465 "dynamicPeer");
10466 if (peer->hostname)
10467 json_object_string_add(json_peer, "hostname",
10468 peer->hostname);
10469
10470 if (peer->domainname)
10471 json_object_string_add(json_peer, "domainname",
10472 peer->domainname);
10473 json_object_int_add(json_peer, "connectionsEstablished",
10474 peer->established);
10475 json_object_int_add(json_peer, "connectionsDropped",
10476 peer->dropped);
10477 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10478 use_json, json_peer);
10479 if (peer_established(peer))
10480 json_object_string_add(json_peer, "lastResetDueTo",
10481 "AFI/SAFI Not Negotiated");
10482 else
10483 bgp_show_peer_reset(NULL, peer, json_peer, true);
10484 } else {
10485 dn_flag[1] = '\0';
10486 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10487 if (peer->hostname
10488 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10489 len = vty_out(vty, "%s%s(%s)", dn_flag,
10490 peer->hostname, peer->host);
10491 else
10492 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10493
10494 /* pad the neighbor column with spaces */
10495 if (len < max_neighbor_width)
10496 vty_out(vty, "%*s", max_neighbor_width - len,
10497 " ");
10498 vty_out(vty, "%7d %7d %9s", peer->established,
10499 peer->dropped,
10500 peer_uptime(peer->uptime, timebuf,
10501 BGP_UPTIME_LEN, 0, NULL));
10502 if (peer_established(peer))
10503 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10504 else
10505 bgp_show_peer_reset(vty, peer, NULL,
10506 false);
10507 }
10508 }
10509
10510 /* Strip peer's description to the given size. */
10511 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10512 {
10513 static char stripped[BUFSIZ];
10514 uint32_t i = 0;
10515 uint32_t last_space = 0;
10516
10517 while (i < size) {
10518 if (*(desc + i) == 0) {
10519 stripped[i] = '\0';
10520 return stripped;
10521 }
10522 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10523 last_space = i;
10524 stripped[i] = *(desc + i);
10525 i++;
10526 }
10527
10528 if (last_space > size)
10529 stripped[size + 1] = '\0';
10530 else
10531 stripped[last_space] = '\0';
10532
10533 return stripped;
10534 }
10535
10536 /* Determine whether var peer should be filtered out of the summary. */
10537 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10538 struct peer *fpeer, int as_type,
10539 as_t as)
10540 {
10541
10542 /* filter neighbor XXXX */
10543 if (fpeer && fpeer != peer)
10544 return true;
10545
10546 /* filter remote-as (internal|external) */
10547 if (as_type != AS_UNSPECIFIED) {
10548 if (peer->as_type == AS_SPECIFIED) {
10549 if (as_type == AS_INTERNAL) {
10550 if (peer->as != peer->local_as)
10551 return true;
10552 } else if (peer->as == peer->local_as)
10553 return true;
10554 } else if (as_type != peer->as_type)
10555 return true;
10556 } else if (as && as != peer->as) /* filter remote-as XXX */
10557 return true;
10558
10559 return false;
10560 }
10561
10562 /* Show BGP peer's summary information.
10563 *
10564 * Peer's description is stripped according to if `wide` option is given
10565 * or not.
10566 *
10567 * When adding new columns to `show bgp summary` output, please make
10568 * sure `Desc` is the lastest column to show because it can contain
10569 * whitespaces and the whole output will be tricky.
10570 */
10571 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10572 struct peer *fpeer, int as_type, as_t as,
10573 uint16_t show_flags)
10574 {
10575 struct peer *peer;
10576 struct listnode *node, *nnode;
10577 unsigned int count = 0, dn_count = 0;
10578 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10579 char neighbor_buf[VTY_BUFSIZ];
10580 int neighbor_col_default_width = 16;
10581 int len, failed_count = 0;
10582 unsigned int filtered_count = 0;
10583 int max_neighbor_width = 0;
10584 int pfx_rcd_safi;
10585 json_object *json = NULL;
10586 json_object *json_peer = NULL;
10587 json_object *json_peers = NULL;
10588 struct peer_af *paf;
10589 struct bgp_filter *filter;
10590 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10591 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10592 bool show_established =
10593 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10594 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10595 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10596
10597 /* labeled-unicast routes are installed in the unicast table so in order
10598 * to
10599 * display the correct PfxRcd value we must look at SAFI_UNICAST
10600 */
10601
10602 if (safi == SAFI_LABELED_UNICAST)
10603 pfx_rcd_safi = SAFI_UNICAST;
10604 else
10605 pfx_rcd_safi = safi;
10606
10607 if (use_json) {
10608 json = json_object_new_object();
10609 json_peers = json_object_new_object();
10610 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10611 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10612 as_type, as)) {
10613 filtered_count++;
10614 count++;
10615 continue;
10616 }
10617
10618 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10619 continue;
10620
10621 if (peer->afc[afi][safi]) {
10622 /* See if we have at least a single failed peer */
10623 if (bgp_has_peer_failed(peer, afi, safi))
10624 failed_count++;
10625 count++;
10626 }
10627 if (peer_dynamic_neighbor(peer))
10628 dn_count++;
10629 }
10630
10631 } else {
10632 /* Loop over all neighbors that will be displayed to determine
10633 * how many
10634 * characters are needed for the Neighbor column
10635 */
10636 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10637 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10638 as_type, as)) {
10639 filtered_count++;
10640 count++;
10641 continue;
10642 }
10643
10644 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10645 continue;
10646
10647 if (peer->afc[afi][safi]) {
10648 memset(dn_flag, '\0', sizeof(dn_flag));
10649 if (peer_dynamic_neighbor(peer))
10650 dn_flag[0] = '*';
10651
10652 if (peer->hostname
10653 && CHECK_FLAG(bgp->flags,
10654 BGP_FLAG_SHOW_HOSTNAME))
10655 snprintf(neighbor_buf,
10656 sizeof(neighbor_buf),
10657 "%s%s(%s) ", dn_flag,
10658 peer->hostname, peer->host);
10659 else
10660 snprintf(neighbor_buf,
10661 sizeof(neighbor_buf), "%s%s ",
10662 dn_flag, peer->host);
10663
10664 len = strlen(neighbor_buf);
10665
10666 if (len > max_neighbor_width)
10667 max_neighbor_width = len;
10668
10669 /* See if we have at least a single failed peer */
10670 if (bgp_has_peer_failed(peer, afi, safi))
10671 failed_count++;
10672 count++;
10673 }
10674 }
10675
10676 /* Originally we displayed the Neighbor column as 16
10677 * characters wide so make that the default
10678 */
10679 if (max_neighbor_width < neighbor_col_default_width)
10680 max_neighbor_width = neighbor_col_default_width;
10681 }
10682
10683 if (show_failed && !failed_count) {
10684 if (use_json) {
10685 json_object_int_add(json, "failedPeersCount", 0);
10686 json_object_int_add(json, "dynamicPeers", dn_count);
10687 json_object_int_add(json, "totalPeers", count);
10688
10689 vty_json(vty, json);
10690 } else {
10691 vty_out(vty, "%% No failed BGP neighbors found\n");
10692 }
10693 return CMD_SUCCESS;
10694 }
10695
10696 count = 0; /* Reset the value as its used again */
10697 filtered_count = 0;
10698 dn_count = 0;
10699 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10700 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10701 continue;
10702
10703 if (!peer->afc[afi][safi])
10704 continue;
10705
10706 if (!count) {
10707 unsigned long ents;
10708 char memstrbuf[MTYPE_MEMSTR_LEN];
10709 int64_t vrf_id_ui;
10710
10711 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10712 ? -1
10713 : (int64_t)bgp->vrf_id;
10714
10715 /* Usage summary and header */
10716 if (use_json) {
10717 json_object_string_addf(json, "routerId",
10718 "%pI4",
10719 &bgp->router_id);
10720 json_object_int_add(json, "as", bgp->as);
10721 json_object_int_add(json, "vrfId", vrf_id_ui);
10722 json_object_string_add(
10723 json, "vrfName",
10724 (bgp->inst_type
10725 == BGP_INSTANCE_TYPE_DEFAULT)
10726 ? VRF_DEFAULT_NAME
10727 : bgp->name);
10728 } else {
10729 vty_out(vty,
10730 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10731 &bgp->router_id, bgp->as,
10732 bgp->vrf_id == VRF_UNKNOWN
10733 ? -1
10734 : (int)bgp->vrf_id);
10735 vty_out(vty, "\n");
10736 }
10737
10738 if (bgp_update_delay_configured(bgp)) {
10739 if (use_json) {
10740 json_object_int_add(
10741 json, "updateDelayLimit",
10742 bgp->v_update_delay);
10743
10744 if (bgp->v_update_delay
10745 != bgp->v_establish_wait)
10746 json_object_int_add(
10747 json,
10748 "updateDelayEstablishWait",
10749 bgp->v_establish_wait);
10750
10751 if (bgp_update_delay_active(bgp)) {
10752 json_object_string_add(
10753 json,
10754 "updateDelayFirstNeighbor",
10755 bgp->update_delay_begin_time);
10756 json_object_boolean_true_add(
10757 json,
10758 "updateDelayInProgress");
10759 } else {
10760 if (bgp->update_delay_over) {
10761 json_object_string_add(
10762 json,
10763 "updateDelayFirstNeighbor",
10764 bgp->update_delay_begin_time);
10765 json_object_string_add(
10766 json,
10767 "updateDelayBestpathResumed",
10768 bgp->update_delay_end_time);
10769 json_object_string_add(
10770 json,
10771 "updateDelayZebraUpdateResume",
10772 bgp->update_delay_zebra_resume_time);
10773 json_object_string_add(
10774 json,
10775 "updateDelayPeerUpdateResume",
10776 bgp->update_delay_peers_resume_time);
10777 }
10778 }
10779 } else {
10780 vty_out(vty,
10781 "Read-only mode update-delay limit: %d seconds\n",
10782 bgp->v_update_delay);
10783 if (bgp->v_update_delay
10784 != bgp->v_establish_wait)
10785 vty_out(vty,
10786 " Establish wait: %d seconds\n",
10787 bgp->v_establish_wait);
10788
10789 if (bgp_update_delay_active(bgp)) {
10790 vty_out(vty,
10791 " First neighbor established: %s\n",
10792 bgp->update_delay_begin_time);
10793 vty_out(vty,
10794 " Delay in progress\n");
10795 } else {
10796 if (bgp->update_delay_over) {
10797 vty_out(vty,
10798 " First neighbor established: %s\n",
10799 bgp->update_delay_begin_time);
10800 vty_out(vty,
10801 " Best-paths resumed: %s\n",
10802 bgp->update_delay_end_time);
10803 vty_out(vty,
10804 " zebra update resumed: %s\n",
10805 bgp->update_delay_zebra_resume_time);
10806 vty_out(vty,
10807 " peers update resumed: %s\n",
10808 bgp->update_delay_peers_resume_time);
10809 }
10810 }
10811 }
10812 }
10813
10814 if (use_json) {
10815 if (bgp_maxmed_onstartup_configured(bgp)
10816 && bgp->maxmed_active)
10817 json_object_boolean_true_add(
10818 json, "maxMedOnStartup");
10819 if (bgp->v_maxmed_admin)
10820 json_object_boolean_true_add(
10821 json, "maxMedAdministrative");
10822
10823 json_object_int_add(
10824 json, "tableVersion",
10825 bgp_table_version(bgp->rib[afi][safi]));
10826
10827 ents = bgp_table_count(bgp->rib[afi][safi]);
10828 json_object_int_add(json, "ribCount", ents);
10829 json_object_int_add(
10830 json, "ribMemory",
10831 ents * sizeof(struct bgp_dest));
10832
10833 ents = bgp->af_peer_count[afi][safi];
10834 json_object_int_add(json, "peerCount", ents);
10835 json_object_int_add(json, "peerMemory",
10836 ents * sizeof(struct peer));
10837
10838 if ((ents = listcount(bgp->group))) {
10839 json_object_int_add(
10840 json, "peerGroupCount", ents);
10841 json_object_int_add(
10842 json, "peerGroupMemory",
10843 ents * sizeof(struct
10844 peer_group));
10845 }
10846
10847 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10848 BGP_CONFIG_DAMPENING))
10849 json_object_boolean_true_add(
10850 json, "dampeningEnabled");
10851 } else {
10852 if (!show_terse) {
10853 if (bgp_maxmed_onstartup_configured(bgp)
10854 && bgp->maxmed_active)
10855 vty_out(vty,
10856 "Max-med on-startup active\n");
10857 if (bgp->v_maxmed_admin)
10858 vty_out(vty,
10859 "Max-med administrative active\n");
10860
10861 vty_out(vty,
10862 "BGP table version %" PRIu64
10863 "\n",
10864 bgp_table_version(
10865 bgp->rib[afi][safi]));
10866
10867 ents = bgp_table_count(
10868 bgp->rib[afi][safi]);
10869 vty_out(vty,
10870 "RIB entries %ld, using %s of memory\n",
10871 ents,
10872 mtype_memstr(
10873 memstrbuf,
10874 sizeof(memstrbuf),
10875 ents
10876 * sizeof(
10877 struct
10878 bgp_dest)));
10879
10880 /* Peer related usage */
10881 ents = bgp->af_peer_count[afi][safi];
10882 vty_out(vty,
10883 "Peers %ld, using %s of memory\n",
10884 ents,
10885 mtype_memstr(
10886 memstrbuf,
10887 sizeof(memstrbuf),
10888 ents
10889 * sizeof(
10890 struct
10891 peer)));
10892
10893 if ((ents = listcount(bgp->group)))
10894 vty_out(vty,
10895 "Peer groups %ld, using %s of memory\n",
10896 ents,
10897 mtype_memstr(
10898 memstrbuf,
10899 sizeof(memstrbuf),
10900 ents
10901 * sizeof(
10902 struct
10903 peer_group)));
10904
10905 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10906 BGP_CONFIG_DAMPENING))
10907 vty_out(vty,
10908 "Dampening enabled.\n");
10909 }
10910 if (show_failed) {
10911 vty_out(vty, "\n");
10912
10913 /* Subtract 8 here because 'Neighbor' is
10914 * 8 characters */
10915 vty_out(vty, "Neighbor");
10916 vty_out(vty, "%*s",
10917 max_neighbor_width - 8, " ");
10918 vty_out(vty,
10919 BGP_SHOW_SUMMARY_HEADER_FAILED);
10920 }
10921 }
10922 }
10923
10924 paf = peer_af_find(peer, afi, safi);
10925 filter = &peer->filter[afi][safi];
10926
10927 count++;
10928 /* Works for both failed & successful cases */
10929 if (peer_dynamic_neighbor(peer))
10930 dn_count++;
10931
10932 if (use_json) {
10933 json_peer = NULL;
10934 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10935 as_type, as)) {
10936 filtered_count++;
10937 continue;
10938 }
10939 if (show_failed &&
10940 bgp_has_peer_failed(peer, afi, safi)) {
10941 json_peer = json_object_new_object();
10942 bgp_show_failed_summary(vty, bgp, peer,
10943 json_peer, 0, use_json);
10944 } else if (!show_failed) {
10945 if (show_established
10946 && bgp_has_peer_failed(peer, afi, safi)) {
10947 filtered_count++;
10948 continue;
10949 }
10950
10951 json_peer = json_object_new_object();
10952 if (peer_dynamic_neighbor(peer)) {
10953 json_object_boolean_true_add(json_peer,
10954 "dynamicPeer");
10955 }
10956
10957 if (peer->hostname)
10958 json_object_string_add(json_peer, "hostname",
10959 peer->hostname);
10960
10961 if (peer->domainname)
10962 json_object_string_add(json_peer, "domainname",
10963 peer->domainname);
10964
10965 json_object_int_add(json_peer, "remoteAs", peer->as);
10966 json_object_int_add(
10967 json_peer, "localAs",
10968 peer->change_local_as
10969 ? peer->change_local_as
10970 : peer->local_as);
10971 json_object_int_add(json_peer, "version", 4);
10972 json_object_int_add(json_peer, "msgRcvd",
10973 PEER_TOTAL_RX(peer));
10974 json_object_int_add(json_peer, "msgSent",
10975 PEER_TOTAL_TX(peer));
10976
10977 atomic_size_t outq_count, inq_count;
10978 outq_count = atomic_load_explicit(
10979 &peer->obuf->count,
10980 memory_order_relaxed);
10981 inq_count = atomic_load_explicit(
10982 &peer->ibuf->count,
10983 memory_order_relaxed);
10984
10985 json_object_int_add(json_peer, "tableVersion",
10986 peer->version[afi][safi]);
10987 json_object_int_add(json_peer, "outq",
10988 outq_count);
10989 json_object_int_add(json_peer, "inq",
10990 inq_count);
10991 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10992 use_json, json_peer);
10993
10994 json_object_int_add(json_peer, "pfxRcd",
10995 peer->pcount[afi][pfx_rcd_safi]);
10996
10997 if (paf && PAF_SUBGRP(paf))
10998 json_object_int_add(
10999 json_peer, "pfxSnt",
11000 (PAF_SUBGRP(paf))->scount);
11001 else
11002 json_object_int_add(json_peer, "pfxSnt",
11003 0);
11004
11005 /* BGP FSM state */
11006 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11007 || CHECK_FLAG(peer->bgp->flags,
11008 BGP_FLAG_SHUTDOWN))
11009 json_object_string_add(json_peer,
11010 "state",
11011 "Idle (Admin)");
11012 else if (peer->afc_recv[afi][safi])
11013 json_object_string_add(
11014 json_peer, "state",
11015 lookup_msg(bgp_status_msg,
11016 peer->status, NULL));
11017 else if (CHECK_FLAG(
11018 peer->sflags,
11019 PEER_STATUS_PREFIX_OVERFLOW))
11020 json_object_string_add(json_peer,
11021 "state",
11022 "Idle (PfxCt)");
11023 else
11024 json_object_string_add(
11025 json_peer, "state",
11026 lookup_msg(bgp_status_msg,
11027 peer->status, NULL));
11028
11029 /* BGP peer state */
11030 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11031 || CHECK_FLAG(peer->bgp->flags,
11032 BGP_FLAG_SHUTDOWN))
11033 json_object_string_add(json_peer,
11034 "peerState",
11035 "Admin");
11036 else if (CHECK_FLAG(
11037 peer->sflags,
11038 PEER_STATUS_PREFIX_OVERFLOW))
11039 json_object_string_add(json_peer,
11040 "peerState",
11041 "PfxCt");
11042 else if (CHECK_FLAG(peer->flags,
11043 PEER_FLAG_PASSIVE))
11044 json_object_string_add(json_peer,
11045 "peerState",
11046 "Passive");
11047 else if (CHECK_FLAG(peer->sflags,
11048 PEER_STATUS_NSF_WAIT))
11049 json_object_string_add(json_peer,
11050 "peerState",
11051 "NSF passive");
11052 else if (CHECK_FLAG(
11053 peer->bgp->flags,
11054 BGP_FLAG_EBGP_REQUIRES_POLICY)
11055 && (!bgp_inbound_policy_exists(peer,
11056 filter)
11057 || !bgp_outbound_policy_exists(
11058 peer, filter)))
11059 json_object_string_add(json_peer,
11060 "peerState",
11061 "Policy");
11062 else
11063 json_object_string_add(
11064 json_peer, "peerState", "OK");
11065
11066 json_object_int_add(json_peer, "connectionsEstablished",
11067 peer->established);
11068 json_object_int_add(json_peer, "connectionsDropped",
11069 peer->dropped);
11070 if (peer->desc)
11071 json_object_string_add(
11072 json_peer, "desc", peer->desc);
11073 }
11074 /* Avoid creating empty peer dicts in JSON */
11075 if (json_peer == NULL)
11076 continue;
11077
11078 if (peer->conf_if)
11079 json_object_string_add(json_peer, "idType",
11080 "interface");
11081 else if (peer->su.sa.sa_family == AF_INET)
11082 json_object_string_add(json_peer, "idType",
11083 "ipv4");
11084 else if (peer->su.sa.sa_family == AF_INET6)
11085 json_object_string_add(json_peer, "idType",
11086 "ipv6");
11087 json_object_object_add(json_peers, peer->host,
11088 json_peer);
11089 } else {
11090 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11091 as_type, as)) {
11092 filtered_count++;
11093 continue;
11094 }
11095 if (show_failed &&
11096 bgp_has_peer_failed(peer, afi, safi)) {
11097 bgp_show_failed_summary(vty, bgp, peer, NULL,
11098 max_neighbor_width,
11099 use_json);
11100 } else if (!show_failed) {
11101 if (show_established
11102 && bgp_has_peer_failed(peer, afi, safi)) {
11103 filtered_count++;
11104 continue;
11105 }
11106
11107 if ((count - filtered_count) == 1) {
11108 /* display headline before the first
11109 * neighbor line */
11110 vty_out(vty, "\n");
11111
11112 /* Subtract 8 here because 'Neighbor' is
11113 * 8 characters */
11114 vty_out(vty, "Neighbor");
11115 vty_out(vty, "%*s",
11116 max_neighbor_width - 8, " ");
11117 vty_out(vty,
11118 show_wide
11119 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11120 : BGP_SHOW_SUMMARY_HEADER_ALL);
11121 }
11122
11123 memset(dn_flag, '\0', sizeof(dn_flag));
11124 if (peer_dynamic_neighbor(peer)) {
11125 dn_flag[0] = '*';
11126 }
11127
11128 if (peer->hostname
11129 && CHECK_FLAG(bgp->flags,
11130 BGP_FLAG_SHOW_HOSTNAME))
11131 len = vty_out(vty, "%s%s(%s)", dn_flag,
11132 peer->hostname,
11133 peer->host);
11134 else
11135 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11136
11137 /* pad the neighbor column with spaces */
11138 if (len < max_neighbor_width)
11139 vty_out(vty, "%*s", max_neighbor_width - len,
11140 " ");
11141
11142 atomic_size_t outq_count, inq_count;
11143 outq_count = atomic_load_explicit(
11144 &peer->obuf->count,
11145 memory_order_relaxed);
11146 inq_count = atomic_load_explicit(
11147 &peer->ibuf->count,
11148 memory_order_relaxed);
11149
11150 if (show_wide)
11151 vty_out(vty,
11152 "4 %10u %10u %9u %9u %8" PRIu64
11153 " %4zu %4zu %8s",
11154 peer->as,
11155 peer->change_local_as
11156 ? peer->change_local_as
11157 : peer->local_as,
11158 PEER_TOTAL_RX(peer),
11159 PEER_TOTAL_TX(peer),
11160 peer->version[afi][safi],
11161 inq_count, outq_count,
11162 peer_uptime(peer->uptime,
11163 timebuf,
11164 BGP_UPTIME_LEN, 0,
11165 NULL));
11166 else
11167 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11168 " %4zu %4zu %8s",
11169 peer->as, PEER_TOTAL_RX(peer),
11170 PEER_TOTAL_TX(peer),
11171 peer->version[afi][safi],
11172 inq_count, outq_count,
11173 peer_uptime(peer->uptime,
11174 timebuf,
11175 BGP_UPTIME_LEN, 0,
11176 NULL));
11177
11178 if (peer_established(peer)) {
11179 if (peer->afc_recv[afi][safi]) {
11180 if (CHECK_FLAG(
11181 bgp->flags,
11182 BGP_FLAG_EBGP_REQUIRES_POLICY)
11183 && !bgp_inbound_policy_exists(
11184 peer, filter))
11185 vty_out(vty, " %12s",
11186 "(Policy)");
11187 else
11188 vty_out(vty,
11189 " %12u",
11190 peer->pcount
11191 [afi]
11192 [pfx_rcd_safi]);
11193 } else {
11194 vty_out(vty, " NoNeg");
11195 }
11196
11197 if (paf && PAF_SUBGRP(paf)) {
11198 if (CHECK_FLAG(
11199 bgp->flags,
11200 BGP_FLAG_EBGP_REQUIRES_POLICY)
11201 && !bgp_outbound_policy_exists(
11202 peer, filter))
11203 vty_out(vty, " %8s",
11204 "(Policy)");
11205 else
11206 vty_out(vty,
11207 " %8u",
11208 (PAF_SUBGRP(
11209 paf))
11210 ->scount);
11211 } else {
11212 vty_out(vty, " NoNeg");
11213 }
11214 } else {
11215 if (CHECK_FLAG(peer->flags,
11216 PEER_FLAG_SHUTDOWN)
11217 || CHECK_FLAG(peer->bgp->flags,
11218 BGP_FLAG_SHUTDOWN))
11219 vty_out(vty, " Idle (Admin)");
11220 else if (CHECK_FLAG(
11221 peer->sflags,
11222 PEER_STATUS_PREFIX_OVERFLOW))
11223 vty_out(vty, " Idle (PfxCt)");
11224 else
11225 vty_out(vty, " %12s",
11226 lookup_msg(bgp_status_msg,
11227 peer->status, NULL));
11228
11229 vty_out(vty, " %8u", 0);
11230 }
11231 /* Make sure `Desc` column is the lastest in
11232 * the output.
11233 */
11234 if (peer->desc)
11235 vty_out(vty, " %s",
11236 bgp_peer_description_stripped(
11237 peer->desc,
11238 show_wide ? 64 : 20));
11239 else
11240 vty_out(vty, " N/A");
11241 vty_out(vty, "\n");
11242 }
11243
11244 }
11245 }
11246
11247 if (use_json) {
11248 json_object_object_add(json, "peers", json_peers);
11249 json_object_int_add(json, "failedPeers", failed_count);
11250 json_object_int_add(json, "displayedPeers",
11251 count - filtered_count);
11252 json_object_int_add(json, "totalPeers", count);
11253 json_object_int_add(json, "dynamicPeers", dn_count);
11254
11255 if (!show_failed)
11256 bgp_show_bestpath_json(bgp, json);
11257
11258 vty_json(vty, json);
11259 } else {
11260 if (count) {
11261 if (filtered_count == count)
11262 vty_out(vty, "\n%% No matching neighbor\n");
11263 else {
11264 if (show_failed)
11265 vty_out(vty, "\nDisplayed neighbors %d",
11266 failed_count);
11267 else if (as_type != AS_UNSPECIFIED || as
11268 || fpeer || show_established)
11269 vty_out(vty, "\nDisplayed neighbors %d",
11270 count - filtered_count);
11271
11272 vty_out(vty, "\nTotal number of neighbors %d\n",
11273 count);
11274 }
11275 } else {
11276 vty_out(vty, "No %s neighbor is configured\n",
11277 get_afi_safi_str(afi, safi, false));
11278 }
11279
11280 if (dn_count) {
11281 vty_out(vty, "* - dynamic neighbor\n");
11282 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11283 dn_count, bgp->dynamic_neighbors_limit);
11284 }
11285 }
11286
11287 return CMD_SUCCESS;
11288 }
11289
11290 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11291 int safi, struct peer *fpeer, int as_type,
11292 as_t as, uint16_t show_flags)
11293 {
11294 int is_first = 1;
11295 int afi_wildcard = (afi == AFI_MAX);
11296 int safi_wildcard = (safi == SAFI_MAX);
11297 int is_wildcard = (afi_wildcard || safi_wildcard);
11298 bool nbr_output = false;
11299 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11300
11301 if (use_json && is_wildcard)
11302 vty_out(vty, "{\n");
11303 if (afi_wildcard)
11304 afi = 1; /* AFI_IP */
11305 while (afi < AFI_MAX) {
11306 if (safi_wildcard)
11307 safi = 1; /* SAFI_UNICAST */
11308 while (safi < SAFI_MAX) {
11309 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11310 nbr_output = true;
11311
11312 if (is_wildcard) {
11313 /*
11314 * So limit output to those afi/safi
11315 * pairs that
11316 * actualy have something interesting in
11317 * them
11318 */
11319 if (use_json) {
11320 if (!is_first)
11321 vty_out(vty, ",\n");
11322 else
11323 is_first = 0;
11324
11325 vty_out(vty, "\"%s\":",
11326 get_afi_safi_str(afi,
11327 safi,
11328 true));
11329 } else {
11330 vty_out(vty,
11331 "\n%s Summary (%s):\n",
11332 get_afi_safi_str(afi,
11333 safi,
11334 false),
11335 bgp->name_pretty);
11336 }
11337 }
11338 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11339 as_type, as, show_flags);
11340 }
11341 safi++;
11342 if (!safi_wildcard)
11343 safi = SAFI_MAX;
11344 }
11345 afi++;
11346 if (!afi_wildcard)
11347 afi = AFI_MAX;
11348 }
11349
11350 if (use_json && is_wildcard)
11351 vty_out(vty, "}\n");
11352 else if (!nbr_output) {
11353 if (use_json)
11354 vty_out(vty, "{}\n");
11355 else
11356 vty_out(vty, "%% No BGP neighbors found in %s\n",
11357 bgp->name_pretty);
11358 }
11359 }
11360
11361 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11362 safi_t safi,
11363 const char *neighbor,
11364 int as_type, as_t as,
11365 uint16_t show_flags)
11366 {
11367 struct listnode *node, *nnode;
11368 struct bgp *bgp;
11369 struct peer *fpeer = NULL;
11370 int is_first = 1;
11371 bool nbr_output = false;
11372 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11373
11374 if (use_json)
11375 vty_out(vty, "{\n");
11376
11377 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11378 nbr_output = true;
11379 if (use_json) {
11380 if (!is_first)
11381 vty_out(vty, ",\n");
11382 else
11383 is_first = 0;
11384
11385 vty_out(vty, "\"%s\":",
11386 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11387 ? VRF_DEFAULT_NAME
11388 : bgp->name);
11389 }
11390 if (neighbor) {
11391 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11392 use_json);
11393 if (!fpeer)
11394 continue;
11395 }
11396 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11397 as, show_flags);
11398 }
11399
11400 if (use_json)
11401 vty_out(vty, "}\n");
11402 else if (!nbr_output)
11403 vty_out(vty, "%% BGP instance not found\n");
11404 }
11405
11406 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11407 safi_t safi, const char *neighbor, int as_type,
11408 as_t as, uint16_t show_flags)
11409 {
11410 struct bgp *bgp;
11411 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11412 struct peer *fpeer = NULL;
11413
11414 if (name) {
11415 if (strmatch(name, "all")) {
11416 bgp_show_all_instances_summary_vty(vty, afi, safi,
11417 neighbor, as_type,
11418 as, show_flags);
11419 return CMD_SUCCESS;
11420 } else {
11421 bgp = bgp_lookup_by_name(name);
11422
11423 if (!bgp) {
11424 if (use_json)
11425 vty_out(vty, "{}\n");
11426 else
11427 vty_out(vty,
11428 "%% BGP instance not found\n");
11429 return CMD_WARNING;
11430 }
11431
11432 if (neighbor) {
11433 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11434 use_json);
11435 if (!fpeer)
11436 return CMD_WARNING;
11437 }
11438 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11439 as_type, as, show_flags);
11440 return CMD_SUCCESS;
11441 }
11442 }
11443
11444 bgp = bgp_get_default();
11445
11446 if (bgp) {
11447 if (neighbor) {
11448 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11449 use_json);
11450 if (!fpeer)
11451 return CMD_WARNING;
11452 }
11453 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11454 as, show_flags);
11455 } else {
11456 if (use_json)
11457 vty_out(vty, "{}\n");
11458 else
11459 vty_out(vty, "%% BGP instance not found\n");
11460 return CMD_WARNING;
11461 }
11462
11463 return CMD_SUCCESS;
11464 }
11465
11466 /* `show [ip] bgp summary' commands. */
11467 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11468 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11469 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11470 "]] [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]",
11471 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11472 BGP_SAFI_WITH_LABEL_HELP_STR
11473 "Display the entries for all address families\n"
11474 "Summary of BGP neighbor status\n"
11475 "Show only sessions in Established state\n"
11476 "Show only sessions not in Established state\n"
11477 "Show only the specified neighbor session\n"
11478 "Neighbor to display information about\n"
11479 "Neighbor to display information about\n"
11480 "Neighbor on BGP configured interface\n"
11481 "Show only the specified remote AS sessions\n"
11482 "AS number\n"
11483 "Internal (iBGP) AS sessions\n"
11484 "External (eBGP) AS sessions\n"
11485 "Shorten the information on BGP instances\n"
11486 "Increase table width for longer output\n" JSON_STR)
11487 {
11488 char *vrf = NULL;
11489 afi_t afi = AFI_MAX;
11490 safi_t safi = SAFI_MAX;
11491 as_t as = 0; /* 0 means AS filter not set */
11492 int as_type = AS_UNSPECIFIED;
11493 uint16_t show_flags = 0;
11494
11495 int idx = 0;
11496
11497 /* show [ip] bgp */
11498 if (!all && argv_find(argv, argc, "ip", &idx))
11499 afi = AFI_IP;
11500 /* [<vrf> VIEWVRFNAME] */
11501 if (argv_find(argv, argc, "vrf", &idx)) {
11502 vrf = argv[idx + 1]->arg;
11503 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11504 vrf = NULL;
11505 } else if (argv_find(argv, argc, "view", &idx))
11506 /* [<view> VIEWVRFNAME] */
11507 vrf = argv[idx + 1]->arg;
11508 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11509 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11510 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11511 }
11512
11513 if (argv_find(argv, argc, "failed", &idx))
11514 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11515
11516 if (argv_find(argv, argc, "established", &idx))
11517 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11518
11519 if (argv_find(argv, argc, "remote-as", &idx)) {
11520 if (argv[idx + 1]->arg[0] == 'i')
11521 as_type = AS_INTERNAL;
11522 else if (argv[idx + 1]->arg[0] == 'e')
11523 as_type = AS_EXTERNAL;
11524 else
11525 as = (as_t)atoi(argv[idx + 1]->arg);
11526 }
11527
11528 if (argv_find(argv, argc, "terse", &idx))
11529 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11530
11531 if (argv_find(argv, argc, "wide", &idx))
11532 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11533
11534 if (argv_find(argv, argc, "json", &idx))
11535 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11536
11537 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11538 show_flags);
11539 }
11540
11541 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11542 {
11543 if (for_json)
11544 return get_afi_safi_json_str(afi, safi);
11545 else
11546 return get_afi_safi_vty_str(afi, safi);
11547 }
11548
11549
11550 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11551 afi_t afi, safi_t safi,
11552 uint16_t adv_smcap, uint16_t adv_rmcap,
11553 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11554 bool use_json, json_object *json_pref)
11555 {
11556 /* Send-Mode */
11557 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11558 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11559 if (use_json) {
11560 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11561 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11562 json_object_string_add(json_pref, "sendMode",
11563 "advertisedAndReceived");
11564 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11565 json_object_string_add(json_pref, "sendMode",
11566 "advertised");
11567 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11568 json_object_string_add(json_pref, "sendMode",
11569 "received");
11570 } else {
11571 vty_out(vty, " Send-mode: ");
11572 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11573 vty_out(vty, "advertised");
11574 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11575 vty_out(vty, "%sreceived",
11576 CHECK_FLAG(p->af_cap[afi][safi],
11577 adv_smcap)
11578 ? ", "
11579 : "");
11580 vty_out(vty, "\n");
11581 }
11582 }
11583
11584 /* Receive-Mode */
11585 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11586 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11587 if (use_json) {
11588 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11589 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11590 json_object_string_add(json_pref, "recvMode",
11591 "advertisedAndReceived");
11592 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11593 json_object_string_add(json_pref, "recvMode",
11594 "advertised");
11595 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11596 json_object_string_add(json_pref, "recvMode",
11597 "received");
11598 } else {
11599 vty_out(vty, " Receive-mode: ");
11600 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11601 vty_out(vty, "advertised");
11602 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11603 vty_out(vty, "%sreceived",
11604 CHECK_FLAG(p->af_cap[afi][safi],
11605 adv_rmcap)
11606 ? ", "
11607 : "");
11608 vty_out(vty, "\n");
11609 }
11610 }
11611 }
11612
11613 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11614 struct peer *p,
11615 bool use_json,
11616 json_object *json)
11617 {
11618 bool rbit = false;
11619 bool nbit = false;
11620
11621 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11622 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11623 && (peer_established(p))) {
11624 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11625 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11626 }
11627
11628 if (use_json) {
11629 json_object_boolean_add(json, "rBit", rbit);
11630 json_object_boolean_add(json, "nBit", nbit);
11631 } else {
11632 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11633 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11634 }
11635 }
11636
11637 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11638 struct peer *peer,
11639 bool use_json,
11640 json_object *json)
11641 {
11642 const char *mode = "NotApplicable";
11643
11644 if (!use_json)
11645 vty_out(vty, "\n Remote GR Mode: ");
11646
11647 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11648 && (peer_established(peer))) {
11649
11650 if ((peer->nsf_af_count == 0)
11651 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11652
11653 mode = "Disable";
11654
11655 } else if (peer->nsf_af_count == 0
11656 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11657
11658 mode = "Helper";
11659
11660 } else if (peer->nsf_af_count != 0
11661 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11662
11663 mode = "Restart";
11664 }
11665 }
11666
11667 if (use_json) {
11668 json_object_string_add(json, "remoteGrMode", mode);
11669 } else
11670 vty_out(vty, mode, "\n");
11671 }
11672
11673 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11674 struct peer *p,
11675 bool use_json,
11676 json_object *json)
11677 {
11678 const char *mode = "Invalid";
11679
11680 if (!use_json)
11681 vty_out(vty, " Local GR Mode: ");
11682
11683 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11684 mode = "Helper";
11685 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11686 mode = "Restart";
11687 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11688 mode = "Disable";
11689 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11690 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11691 mode = "Helper*";
11692 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11693 mode = "Restart*";
11694 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11695 mode = "Disable*";
11696 else
11697 mode = "Invalid*";
11698 }
11699
11700 if (use_json) {
11701 json_object_string_add(json, "localGrMode", mode);
11702 } else {
11703 vty_out(vty, mode, "\n");
11704 }
11705 }
11706
11707 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11708 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11709 {
11710 afi_t afi;
11711 safi_t safi;
11712 json_object *json_afi_safi = NULL;
11713 json_object *json_timer = NULL;
11714 json_object *json_endofrib_status = NULL;
11715 bool eor_flag = false;
11716
11717 FOREACH_AFI_SAFI_NSF (afi, safi) {
11718 if (!peer->afc[afi][safi])
11719 continue;
11720
11721 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11722 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11723 continue;
11724
11725 if (use_json) {
11726 json_afi_safi = json_object_new_object();
11727 json_endofrib_status = json_object_new_object();
11728 json_timer = json_object_new_object();
11729 }
11730
11731 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11732 eor_flag = true;
11733 else
11734 eor_flag = false;
11735
11736 if (!use_json) {
11737 vty_out(vty, " %s:\n",
11738 get_afi_safi_str(afi, safi, false));
11739
11740 vty_out(vty, " F bit: ");
11741 }
11742
11743 if (peer->nsf[afi][safi] &&
11744 CHECK_FLAG(peer->af_cap[afi][safi],
11745 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11746
11747 if (use_json) {
11748 json_object_boolean_true_add(json_afi_safi,
11749 "fBit");
11750 } else
11751 vty_out(vty, "True\n");
11752 } else {
11753 if (use_json)
11754 json_object_boolean_false_add(json_afi_safi,
11755 "fBit");
11756 else
11757 vty_out(vty, "False\n");
11758 }
11759
11760 if (!use_json)
11761 vty_out(vty, " End-of-RIB sent: ");
11762
11763 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11764 PEER_STATUS_EOR_SEND)) {
11765 if (use_json) {
11766 json_object_boolean_true_add(
11767 json_endofrib_status, "endOfRibSend");
11768
11769 PRINT_EOR_JSON(eor_flag);
11770 } else {
11771 vty_out(vty, "Yes\n");
11772 vty_out(vty,
11773 " End-of-RIB sent after update: ");
11774
11775 PRINT_EOR(eor_flag);
11776 }
11777 } else {
11778 if (use_json) {
11779 json_object_boolean_false_add(
11780 json_endofrib_status, "endOfRibSend");
11781 json_object_boolean_false_add(
11782 json_endofrib_status,
11783 "endOfRibSentAfterUpdate");
11784 } else {
11785 vty_out(vty, "No\n");
11786 vty_out(vty,
11787 " End-of-RIB sent after update: ");
11788 vty_out(vty, "No\n");
11789 }
11790 }
11791
11792 if (!use_json)
11793 vty_out(vty, " End-of-RIB received: ");
11794
11795 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11796 PEER_STATUS_EOR_RECEIVED)) {
11797 if (use_json)
11798 json_object_boolean_true_add(
11799 json_endofrib_status, "endOfRibRecv");
11800 else
11801 vty_out(vty, "Yes\n");
11802 } else {
11803 if (use_json)
11804 json_object_boolean_false_add(
11805 json_endofrib_status, "endOfRibRecv");
11806 else
11807 vty_out(vty, "No\n");
11808 }
11809
11810 if (use_json) {
11811 json_object_int_add(json_timer, "stalePathTimer",
11812 peer->bgp->stalepath_time);
11813
11814 if (peer->t_gr_stale != NULL) {
11815 json_object_int_add(json_timer,
11816 "stalePathTimerRemaining",
11817 thread_timer_remain_second(
11818 peer->t_gr_stale));
11819 }
11820
11821 /* Display Configured Selection
11822 * Deferral only when when
11823 * Gr mode is enabled.
11824 */
11825 if (CHECK_FLAG(peer->flags,
11826 PEER_FLAG_GRACEFUL_RESTART)) {
11827 json_object_int_add(json_timer,
11828 "selectionDeferralTimer",
11829 peer->bgp->stalepath_time);
11830 }
11831
11832 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11833 NULL) {
11834
11835 json_object_int_add(
11836 json_timer,
11837 "selectionDeferralTimerRemaining",
11838 thread_timer_remain_second(
11839 peer->bgp->gr_info[afi][safi]
11840 .t_select_deferral));
11841 }
11842 } else {
11843 vty_out(vty, " Timers:\n");
11844 vty_out(vty,
11845 " Configured Stale Path Time(sec): %u\n",
11846 peer->bgp->stalepath_time);
11847
11848 if (peer->t_gr_stale != NULL)
11849 vty_out(vty,
11850 " Stale Path Remaining(sec): %ld\n",
11851 thread_timer_remain_second(
11852 peer->t_gr_stale));
11853 /* Display Configured Selection
11854 * Deferral only when when
11855 * Gr mode is enabled.
11856 */
11857 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11858 vty_out(vty,
11859 " Configured Selection Deferral Time(sec): %u\n",
11860 peer->bgp->select_defer_time);
11861
11862 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11863 NULL)
11864 vty_out(vty,
11865 " Selection Deferral Time Remaining(sec): %ld\n",
11866 thread_timer_remain_second(
11867 peer->bgp->gr_info[afi][safi]
11868 .t_select_deferral));
11869 }
11870 if (use_json) {
11871 json_object_object_add(json_afi_safi, "endOfRibStatus",
11872 json_endofrib_status);
11873 json_object_object_add(json_afi_safi, "timers",
11874 json_timer);
11875 json_object_object_add(
11876 json, get_afi_safi_str(afi, safi, true),
11877 json_afi_safi);
11878 }
11879 }
11880 }
11881
11882 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11883 struct peer *p,
11884 bool use_json,
11885 json_object *json)
11886 {
11887 if (use_json) {
11888 json_object *json_timer = NULL;
11889
11890 json_timer = json_object_new_object();
11891
11892 json_object_int_add(json_timer, "configuredRestartTimer",
11893 p->bgp->restart_time);
11894
11895 json_object_int_add(json_timer, "receivedRestartTimer",
11896 p->v_gr_restart);
11897
11898 if (p->t_gr_restart != NULL)
11899 json_object_int_add(
11900 json_timer, "restartTimerRemaining",
11901 thread_timer_remain_second(p->t_gr_restart));
11902
11903 json_object_object_add(json, "timers", json_timer);
11904 } else {
11905
11906 vty_out(vty, " Timers:\n");
11907 vty_out(vty, " Configured Restart Time(sec): %u\n",
11908 p->bgp->restart_time);
11909
11910 vty_out(vty, " Received Restart Time(sec): %u\n",
11911 p->v_gr_restart);
11912 if (p->t_gr_restart != NULL)
11913 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11914 thread_timer_remain_second(p->t_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 }
11919 }
11920 }
11921
11922 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11923 bool use_json, json_object *json)
11924 {
11925 char dn_flag[2] = {0};
11926 /* '*' + v6 address of neighbor */
11927 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11928
11929 if (!p->conf_if && peer_dynamic_neighbor(p))
11930 dn_flag[0] = '*';
11931
11932 if (p->conf_if) {
11933 if (use_json)
11934 json_object_string_addf(json, "neighborAddr", "%pSU",
11935 &p->su);
11936 else
11937 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11938 &p->su);
11939 } else {
11940 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11941 p->host);
11942
11943 if (use_json)
11944 json_object_string_add(json, "neighborAddr",
11945 neighborAddr);
11946 else
11947 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11948 }
11949
11950 /* more gr info in new format */
11951 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11952 }
11953
11954 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11955 safi_t safi, bool use_json,
11956 json_object *json_neigh)
11957 {
11958 struct bgp_filter *filter;
11959 struct peer_af *paf;
11960 char orf_pfx_name[BUFSIZ];
11961 int orf_pfx_count;
11962 json_object *json_af = NULL;
11963 json_object *json_prefA = NULL;
11964 json_object *json_prefB = NULL;
11965 json_object *json_addr = NULL;
11966 json_object *json_advmap = NULL;
11967
11968 if (use_json) {
11969 json_addr = json_object_new_object();
11970 json_af = json_object_new_object();
11971 filter = &p->filter[afi][safi];
11972
11973 if (peer_group_active(p))
11974 json_object_string_add(json_addr, "peerGroupMember",
11975 p->group->name);
11976
11977 paf = peer_af_find(p, afi, safi);
11978 if (paf && PAF_SUBGRP(paf)) {
11979 json_object_int_add(json_addr, "updateGroupId",
11980 PAF_UPDGRP(paf)->id);
11981 json_object_int_add(json_addr, "subGroupId",
11982 PAF_SUBGRP(paf)->id);
11983 json_object_int_add(json_addr, "packetQueueLength",
11984 bpacket_queue_virtual_length(paf));
11985 }
11986
11987 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11988 || CHECK_FLAG(p->af_cap[afi][safi],
11989 PEER_CAP_ORF_PREFIX_SM_RCV)
11990 || CHECK_FLAG(p->af_cap[afi][safi],
11991 PEER_CAP_ORF_PREFIX_RM_ADV)
11992 || CHECK_FLAG(p->af_cap[afi][safi],
11993 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11994 json_object_int_add(json_af, "orfType",
11995 ORF_TYPE_PREFIX);
11996 json_prefA = json_object_new_object();
11997 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11998 PEER_CAP_ORF_PREFIX_SM_ADV,
11999 PEER_CAP_ORF_PREFIX_RM_ADV,
12000 PEER_CAP_ORF_PREFIX_SM_RCV,
12001 PEER_CAP_ORF_PREFIX_RM_RCV,
12002 use_json, json_prefA);
12003 json_object_object_add(json_af, "orfPrefixList",
12004 json_prefA);
12005 }
12006
12007 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12008 || CHECK_FLAG(p->af_cap[afi][safi],
12009 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12010 || CHECK_FLAG(p->af_cap[afi][safi],
12011 PEER_CAP_ORF_PREFIX_RM_ADV)
12012 || CHECK_FLAG(p->af_cap[afi][safi],
12013 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12014 json_object_int_add(json_af, "orfOldType",
12015 ORF_TYPE_PREFIX_OLD);
12016 json_prefB = json_object_new_object();
12017 bgp_show_peer_afi_orf_cap(
12018 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12019 PEER_CAP_ORF_PREFIX_RM_ADV,
12020 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12021 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12022 json_prefB);
12023 json_object_object_add(json_af, "orfOldPrefixList",
12024 json_prefB);
12025 }
12026
12027 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12028 || CHECK_FLAG(p->af_cap[afi][safi],
12029 PEER_CAP_ORF_PREFIX_SM_RCV)
12030 || CHECK_FLAG(p->af_cap[afi][safi],
12031 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12032 || CHECK_FLAG(p->af_cap[afi][safi],
12033 PEER_CAP_ORF_PREFIX_RM_ADV)
12034 || CHECK_FLAG(p->af_cap[afi][safi],
12035 PEER_CAP_ORF_PREFIX_RM_RCV)
12036 || CHECK_FLAG(p->af_cap[afi][safi],
12037 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12038 json_object_object_add(json_addr, "afDependentCap",
12039 json_af);
12040 else
12041 json_object_free(json_af);
12042
12043 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12044 p->host, afi, safi);
12045 orf_pfx_count = prefix_bgp_show_prefix_list(
12046 NULL, afi, orf_pfx_name, use_json);
12047
12048 if (CHECK_FLAG(p->af_sflags[afi][safi],
12049 PEER_STATUS_ORF_PREFIX_SEND)
12050 || orf_pfx_count) {
12051 if (CHECK_FLAG(p->af_sflags[afi][safi],
12052 PEER_STATUS_ORF_PREFIX_SEND))
12053 json_object_boolean_true_add(json_neigh,
12054 "orfSent");
12055 if (orf_pfx_count)
12056 json_object_int_add(json_addr, "orfRecvCounter",
12057 orf_pfx_count);
12058 }
12059 if (CHECK_FLAG(p->af_sflags[afi][safi],
12060 PEER_STATUS_ORF_WAIT_REFRESH))
12061 json_object_string_add(
12062 json_addr, "orfFirstUpdate",
12063 "deferredUntilORFOrRouteRefreshRecvd");
12064
12065 if (CHECK_FLAG(p->af_flags[afi][safi],
12066 PEER_FLAG_REFLECTOR_CLIENT))
12067 json_object_boolean_true_add(json_addr,
12068 "routeReflectorClient");
12069 if (CHECK_FLAG(p->af_flags[afi][safi],
12070 PEER_FLAG_RSERVER_CLIENT))
12071 json_object_boolean_true_add(json_addr,
12072 "routeServerClient");
12073 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12074 json_object_boolean_true_add(json_addr,
12075 "inboundSoftConfigPermit");
12076
12077 if (CHECK_FLAG(p->af_flags[afi][safi],
12078 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12079 json_object_boolean_true_add(
12080 json_addr,
12081 "privateAsNumsAllReplacedInUpdatesToNbr");
12082 else if (CHECK_FLAG(p->af_flags[afi][safi],
12083 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12084 json_object_boolean_true_add(
12085 json_addr,
12086 "privateAsNumsReplacedInUpdatesToNbr");
12087 else if (CHECK_FLAG(p->af_flags[afi][safi],
12088 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12089 json_object_boolean_true_add(
12090 json_addr,
12091 "privateAsNumsAllRemovedInUpdatesToNbr");
12092 else if (CHECK_FLAG(p->af_flags[afi][safi],
12093 PEER_FLAG_REMOVE_PRIVATE_AS))
12094 json_object_boolean_true_add(
12095 json_addr,
12096 "privateAsNumsRemovedInUpdatesToNbr");
12097
12098 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12099 json_object_boolean_true_add(
12100 json_addr,
12101 bgp_addpath_names(p->addpath_type[afi][safi])
12102 ->type_json_name);
12103
12104 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12105 json_object_string_add(json_addr,
12106 "overrideASNsInOutboundUpdates",
12107 "ifAspathEqualRemoteAs");
12108
12109 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12110 || CHECK_FLAG(p->af_flags[afi][safi],
12111 PEER_FLAG_FORCE_NEXTHOP_SELF))
12112 json_object_boolean_true_add(json_addr,
12113 "routerAlwaysNextHop");
12114 if (CHECK_FLAG(p->af_flags[afi][safi],
12115 PEER_FLAG_AS_PATH_UNCHANGED))
12116 json_object_boolean_true_add(
12117 json_addr, "unchangedAsPathPropogatedToNbr");
12118 if (CHECK_FLAG(p->af_flags[afi][safi],
12119 PEER_FLAG_NEXTHOP_UNCHANGED))
12120 json_object_boolean_true_add(
12121 json_addr, "unchangedNextHopPropogatedToNbr");
12122 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12123 json_object_boolean_true_add(
12124 json_addr, "unchangedMedPropogatedToNbr");
12125 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12126 || CHECK_FLAG(p->af_flags[afi][safi],
12127 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12128 if (CHECK_FLAG(p->af_flags[afi][safi],
12129 PEER_FLAG_SEND_COMMUNITY)
12130 && CHECK_FLAG(p->af_flags[afi][safi],
12131 PEER_FLAG_SEND_EXT_COMMUNITY))
12132 json_object_string_add(json_addr,
12133 "commAttriSentToNbr",
12134 "extendedAndStandard");
12135 else if (CHECK_FLAG(p->af_flags[afi][safi],
12136 PEER_FLAG_SEND_EXT_COMMUNITY))
12137 json_object_string_add(json_addr,
12138 "commAttriSentToNbr",
12139 "extended");
12140 else
12141 json_object_string_add(json_addr,
12142 "commAttriSentToNbr",
12143 "standard");
12144 }
12145 if (CHECK_FLAG(p->af_flags[afi][safi],
12146 PEER_FLAG_DEFAULT_ORIGINATE)) {
12147 if (p->default_rmap[afi][safi].name)
12148 json_object_string_add(
12149 json_addr, "defaultRouteMap",
12150 p->default_rmap[afi][safi].name);
12151
12152 if (paf && PAF_SUBGRP(paf)
12153 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12154 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12155 json_object_boolean_true_add(json_addr,
12156 "defaultSent");
12157 else
12158 json_object_boolean_true_add(json_addr,
12159 "defaultNotSent");
12160 }
12161
12162 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12163 if (is_evpn_enabled())
12164 json_object_boolean_true_add(
12165 json_addr, "advertiseAllVnis");
12166 }
12167
12168 if (filter->plist[FILTER_IN].name
12169 || filter->dlist[FILTER_IN].name
12170 || filter->aslist[FILTER_IN].name
12171 || filter->map[RMAP_IN].name)
12172 json_object_boolean_true_add(json_addr,
12173 "inboundPathPolicyConfig");
12174 if (filter->plist[FILTER_OUT].name
12175 || filter->dlist[FILTER_OUT].name
12176 || filter->aslist[FILTER_OUT].name
12177 || filter->map[RMAP_OUT].name || filter->usmap.name)
12178 json_object_boolean_true_add(
12179 json_addr, "outboundPathPolicyConfig");
12180
12181 /* prefix-list */
12182 if (filter->plist[FILTER_IN].name)
12183 json_object_string_add(json_addr,
12184 "incomingUpdatePrefixFilterList",
12185 filter->plist[FILTER_IN].name);
12186 if (filter->plist[FILTER_OUT].name)
12187 json_object_string_add(json_addr,
12188 "outgoingUpdatePrefixFilterList",
12189 filter->plist[FILTER_OUT].name);
12190
12191 /* distribute-list */
12192 if (filter->dlist[FILTER_IN].name)
12193 json_object_string_add(
12194 json_addr, "incomingUpdateNetworkFilterList",
12195 filter->dlist[FILTER_IN].name);
12196 if (filter->dlist[FILTER_OUT].name)
12197 json_object_string_add(
12198 json_addr, "outgoingUpdateNetworkFilterList",
12199 filter->dlist[FILTER_OUT].name);
12200
12201 /* filter-list. */
12202 if (filter->aslist[FILTER_IN].name)
12203 json_object_string_add(json_addr,
12204 "incomingUpdateAsPathFilterList",
12205 filter->aslist[FILTER_IN].name);
12206 if (filter->aslist[FILTER_OUT].name)
12207 json_object_string_add(json_addr,
12208 "outgoingUpdateAsPathFilterList",
12209 filter->aslist[FILTER_OUT].name);
12210
12211 /* route-map. */
12212 if (filter->map[RMAP_IN].name)
12213 json_object_string_add(
12214 json_addr, "routeMapForIncomingAdvertisements",
12215 filter->map[RMAP_IN].name);
12216 if (filter->map[RMAP_OUT].name)
12217 json_object_string_add(
12218 json_addr, "routeMapForOutgoingAdvertisements",
12219 filter->map[RMAP_OUT].name);
12220
12221 /* ebgp-requires-policy (inbound) */
12222 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12223 && !bgp_inbound_policy_exists(p, filter))
12224 json_object_string_add(
12225 json_addr, "inboundEbgpRequiresPolicy",
12226 "Inbound updates discarded due to missing policy");
12227
12228 /* ebgp-requires-policy (outbound) */
12229 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12230 && (!bgp_outbound_policy_exists(p, filter)))
12231 json_object_string_add(
12232 json_addr, "outboundEbgpRequiresPolicy",
12233 "Outbound updates discarded due to missing policy");
12234
12235 /* unsuppress-map */
12236 if (filter->usmap.name)
12237 json_object_string_add(json_addr,
12238 "selectiveUnsuppressRouteMap",
12239 filter->usmap.name);
12240
12241 /* advertise-map */
12242 if (filter->advmap.aname) {
12243 json_advmap = json_object_new_object();
12244 json_object_string_add(json_advmap, "condition",
12245 filter->advmap.condition
12246 ? "EXIST"
12247 : "NON_EXIST");
12248 json_object_string_add(json_advmap, "conditionMap",
12249 filter->advmap.cname);
12250 json_object_string_add(json_advmap, "advertiseMap",
12251 filter->advmap.aname);
12252 json_object_string_add(
12253 json_advmap, "advertiseStatus",
12254 filter->advmap.update_type ==
12255 UPDATE_TYPE_ADVERTISE
12256 ? "Advertise"
12257 : "Withdraw");
12258 json_object_object_add(json_addr, "advertiseMap",
12259 json_advmap);
12260 }
12261
12262 /* Receive prefix count */
12263 json_object_int_add(json_addr, "acceptedPrefixCounter",
12264 p->pcount[afi][safi]);
12265 if (paf && PAF_SUBGRP(paf))
12266 json_object_int_add(json_addr, "sentPrefixCounter",
12267 (PAF_SUBGRP(paf))->scount);
12268
12269 /* Maximum prefix */
12270 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12271 json_object_int_add(json_addr, "prefixOutAllowedMax",
12272 p->pmax_out[afi][safi]);
12273
12274 /* Maximum prefix */
12275 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12276 json_object_int_add(json_addr, "prefixAllowedMax",
12277 p->pmax[afi][safi]);
12278 if (CHECK_FLAG(p->af_flags[afi][safi],
12279 PEER_FLAG_MAX_PREFIX_WARNING))
12280 json_object_boolean_true_add(
12281 json_addr, "prefixAllowedMaxWarning");
12282 json_object_int_add(json_addr,
12283 "prefixAllowedWarningThresh",
12284 p->pmax_threshold[afi][safi]);
12285 if (p->pmax_restart[afi][safi])
12286 json_object_int_add(
12287 json_addr,
12288 "prefixAllowedRestartIntervalMsecs",
12289 p->pmax_restart[afi][safi] * 60000);
12290 }
12291 json_object_object_add(json_neigh,
12292 get_afi_safi_str(afi, safi, true),
12293 json_addr);
12294
12295 } else {
12296 filter = &p->filter[afi][safi];
12297
12298 vty_out(vty, " For address family: %s\n",
12299 get_afi_safi_str(afi, safi, false));
12300
12301 if (peer_group_active(p))
12302 vty_out(vty, " %s peer-group member\n",
12303 p->group->name);
12304
12305 paf = peer_af_find(p, afi, safi);
12306 if (paf && PAF_SUBGRP(paf)) {
12307 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12308 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12309 vty_out(vty, " Packet Queue length %d\n",
12310 bpacket_queue_virtual_length(paf));
12311 } else {
12312 vty_out(vty, " Not part of any update group\n");
12313 }
12314 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12315 || CHECK_FLAG(p->af_cap[afi][safi],
12316 PEER_CAP_ORF_PREFIX_SM_RCV)
12317 || CHECK_FLAG(p->af_cap[afi][safi],
12318 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12319 || CHECK_FLAG(p->af_cap[afi][safi],
12320 PEER_CAP_ORF_PREFIX_RM_ADV)
12321 || CHECK_FLAG(p->af_cap[afi][safi],
12322 PEER_CAP_ORF_PREFIX_RM_RCV)
12323 || CHECK_FLAG(p->af_cap[afi][safi],
12324 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12325 vty_out(vty, " AF-dependant capabilities:\n");
12326
12327 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12328 || CHECK_FLAG(p->af_cap[afi][safi],
12329 PEER_CAP_ORF_PREFIX_SM_RCV)
12330 || CHECK_FLAG(p->af_cap[afi][safi],
12331 PEER_CAP_ORF_PREFIX_RM_ADV)
12332 || CHECK_FLAG(p->af_cap[afi][safi],
12333 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12334 vty_out(vty,
12335 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12336 ORF_TYPE_PREFIX);
12337 bgp_show_peer_afi_orf_cap(
12338 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12339 PEER_CAP_ORF_PREFIX_RM_ADV,
12340 PEER_CAP_ORF_PREFIX_SM_RCV,
12341 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12342 }
12343 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12344 || CHECK_FLAG(p->af_cap[afi][safi],
12345 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12346 || CHECK_FLAG(p->af_cap[afi][safi],
12347 PEER_CAP_ORF_PREFIX_RM_ADV)
12348 || CHECK_FLAG(p->af_cap[afi][safi],
12349 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12350 vty_out(vty,
12351 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12352 ORF_TYPE_PREFIX_OLD);
12353 bgp_show_peer_afi_orf_cap(
12354 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12355 PEER_CAP_ORF_PREFIX_RM_ADV,
12356 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12357 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12358 }
12359
12360 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12361 p->host, afi, safi);
12362 orf_pfx_count = prefix_bgp_show_prefix_list(
12363 NULL, afi, orf_pfx_name, use_json);
12364
12365 if (CHECK_FLAG(p->af_sflags[afi][safi],
12366 PEER_STATUS_ORF_PREFIX_SEND)
12367 || orf_pfx_count) {
12368 vty_out(vty, " Outbound Route Filter (ORF):");
12369 if (CHECK_FLAG(p->af_sflags[afi][safi],
12370 PEER_STATUS_ORF_PREFIX_SEND))
12371 vty_out(vty, " sent;");
12372 if (orf_pfx_count)
12373 vty_out(vty, " received (%d entries)",
12374 orf_pfx_count);
12375 vty_out(vty, "\n");
12376 }
12377 if (CHECK_FLAG(p->af_sflags[afi][safi],
12378 PEER_STATUS_ORF_WAIT_REFRESH))
12379 vty_out(vty,
12380 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12381
12382 if (CHECK_FLAG(p->af_flags[afi][safi],
12383 PEER_FLAG_REFLECTOR_CLIENT))
12384 vty_out(vty, " Route-Reflector Client\n");
12385 if (CHECK_FLAG(p->af_flags[afi][safi],
12386 PEER_FLAG_RSERVER_CLIENT))
12387 vty_out(vty, " Route-Server Client\n");
12388 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12389 vty_out(vty,
12390 " Inbound soft reconfiguration allowed\n");
12391
12392 if (CHECK_FLAG(p->af_flags[afi][safi],
12393 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12394 vty_out(vty,
12395 " Private AS numbers (all) replaced in updates to this neighbor\n");
12396 else if (CHECK_FLAG(p->af_flags[afi][safi],
12397 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12398 vty_out(vty,
12399 " Private AS numbers replaced in updates to this neighbor\n");
12400 else if (CHECK_FLAG(p->af_flags[afi][safi],
12401 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12402 vty_out(vty,
12403 " Private AS numbers (all) removed in updates to this neighbor\n");
12404 else if (CHECK_FLAG(p->af_flags[afi][safi],
12405 PEER_FLAG_REMOVE_PRIVATE_AS))
12406 vty_out(vty,
12407 " Private AS numbers removed in updates to this neighbor\n");
12408
12409 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12410 vty_out(vty, " %s\n",
12411 bgp_addpath_names(p->addpath_type[afi][safi])
12412 ->human_description);
12413
12414 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12415 vty_out(vty,
12416 " Override ASNs in outbound updates if aspath equals remote-as\n");
12417
12418 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12419 || CHECK_FLAG(p->af_flags[afi][safi],
12420 PEER_FLAG_FORCE_NEXTHOP_SELF))
12421 vty_out(vty, " NEXT_HOP is always this router\n");
12422 if (CHECK_FLAG(p->af_flags[afi][safi],
12423 PEER_FLAG_AS_PATH_UNCHANGED))
12424 vty_out(vty,
12425 " AS_PATH is propagated unchanged to this neighbor\n");
12426 if (CHECK_FLAG(p->af_flags[afi][safi],
12427 PEER_FLAG_NEXTHOP_UNCHANGED))
12428 vty_out(vty,
12429 " NEXT_HOP is propagated unchanged to this neighbor\n");
12430 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12431 vty_out(vty,
12432 " MED is propagated unchanged to this neighbor\n");
12433 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12434 || CHECK_FLAG(p->af_flags[afi][safi],
12435 PEER_FLAG_SEND_EXT_COMMUNITY)
12436 || CHECK_FLAG(p->af_flags[afi][safi],
12437 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12438 vty_out(vty,
12439 " Community attribute sent to this neighbor");
12440 if (CHECK_FLAG(p->af_flags[afi][safi],
12441 PEER_FLAG_SEND_COMMUNITY)
12442 && CHECK_FLAG(p->af_flags[afi][safi],
12443 PEER_FLAG_SEND_EXT_COMMUNITY)
12444 && CHECK_FLAG(p->af_flags[afi][safi],
12445 PEER_FLAG_SEND_LARGE_COMMUNITY))
12446 vty_out(vty, "(all)\n");
12447 else if (CHECK_FLAG(p->af_flags[afi][safi],
12448 PEER_FLAG_SEND_LARGE_COMMUNITY))
12449 vty_out(vty, "(large)\n");
12450 else if (CHECK_FLAG(p->af_flags[afi][safi],
12451 PEER_FLAG_SEND_EXT_COMMUNITY))
12452 vty_out(vty, "(extended)\n");
12453 else
12454 vty_out(vty, "(standard)\n");
12455 }
12456 if (CHECK_FLAG(p->af_flags[afi][safi],
12457 PEER_FLAG_DEFAULT_ORIGINATE)) {
12458 vty_out(vty, " Default information originate,");
12459
12460 if (p->default_rmap[afi][safi].name)
12461 vty_out(vty, " default route-map %s%s,",
12462 p->default_rmap[afi][safi].map ? "*"
12463 : "",
12464 p->default_rmap[afi][safi].name);
12465 if (paf && PAF_SUBGRP(paf)
12466 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12467 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12468 vty_out(vty, " default sent\n");
12469 else
12470 vty_out(vty, " default not sent\n");
12471 }
12472
12473 /* advertise-vni-all */
12474 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12475 if (is_evpn_enabled())
12476 vty_out(vty, " advertise-all-vni\n");
12477 }
12478
12479 if (filter->plist[FILTER_IN].name
12480 || filter->dlist[FILTER_IN].name
12481 || filter->aslist[FILTER_IN].name
12482 || filter->map[RMAP_IN].name)
12483 vty_out(vty, " Inbound path policy configured\n");
12484 if (filter->plist[FILTER_OUT].name
12485 || filter->dlist[FILTER_OUT].name
12486 || filter->aslist[FILTER_OUT].name
12487 || filter->map[RMAP_OUT].name || filter->usmap.name)
12488 vty_out(vty, " Outbound path policy configured\n");
12489
12490 /* prefix-list */
12491 if (filter->plist[FILTER_IN].name)
12492 vty_out(vty,
12493 " Incoming update prefix filter list is %s%s\n",
12494 filter->plist[FILTER_IN].plist ? "*" : "",
12495 filter->plist[FILTER_IN].name);
12496 if (filter->plist[FILTER_OUT].name)
12497 vty_out(vty,
12498 " Outgoing update prefix filter list is %s%s\n",
12499 filter->plist[FILTER_OUT].plist ? "*" : "",
12500 filter->plist[FILTER_OUT].name);
12501
12502 /* distribute-list */
12503 if (filter->dlist[FILTER_IN].name)
12504 vty_out(vty,
12505 " Incoming update network filter list is %s%s\n",
12506 filter->dlist[FILTER_IN].alist ? "*" : "",
12507 filter->dlist[FILTER_IN].name);
12508 if (filter->dlist[FILTER_OUT].name)
12509 vty_out(vty,
12510 " Outgoing update network filter list is %s%s\n",
12511 filter->dlist[FILTER_OUT].alist ? "*" : "",
12512 filter->dlist[FILTER_OUT].name);
12513
12514 /* filter-list. */
12515 if (filter->aslist[FILTER_IN].name)
12516 vty_out(vty,
12517 " Incoming update AS path filter list is %s%s\n",
12518 filter->aslist[FILTER_IN].aslist ? "*" : "",
12519 filter->aslist[FILTER_IN].name);
12520 if (filter->aslist[FILTER_OUT].name)
12521 vty_out(vty,
12522 " Outgoing update AS path filter list is %s%s\n",
12523 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12524 filter->aslist[FILTER_OUT].name);
12525
12526 /* route-map. */
12527 if (filter->map[RMAP_IN].name)
12528 vty_out(vty,
12529 " Route map for incoming advertisements is %s%s\n",
12530 filter->map[RMAP_IN].map ? "*" : "",
12531 filter->map[RMAP_IN].name);
12532 if (filter->map[RMAP_OUT].name)
12533 vty_out(vty,
12534 " Route map for outgoing advertisements is %s%s\n",
12535 filter->map[RMAP_OUT].map ? "*" : "",
12536 filter->map[RMAP_OUT].name);
12537
12538 /* ebgp-requires-policy (inbound) */
12539 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12540 && !bgp_inbound_policy_exists(p, filter))
12541 vty_out(vty,
12542 " Inbound updates discarded due to missing policy\n");
12543
12544 /* ebgp-requires-policy (outbound) */
12545 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12546 && !bgp_outbound_policy_exists(p, filter))
12547 vty_out(vty,
12548 " Outbound updates discarded due to missing policy\n");
12549
12550 /* unsuppress-map */
12551 if (filter->usmap.name)
12552 vty_out(vty,
12553 " Route map for selective unsuppress is %s%s\n",
12554 filter->usmap.map ? "*" : "",
12555 filter->usmap.name);
12556
12557 /* advertise-map */
12558 if (filter->advmap.aname && filter->advmap.cname)
12559 vty_out(vty,
12560 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12561 filter->advmap.condition ? "EXIST"
12562 : "NON_EXIST",
12563 filter->advmap.cmap ? "*" : "",
12564 filter->advmap.cname,
12565 filter->advmap.amap ? "*" : "",
12566 filter->advmap.aname,
12567 filter->advmap.update_type ==
12568 UPDATE_TYPE_ADVERTISE
12569 ? "Advertise"
12570 : "Withdraw");
12571
12572 /* Receive prefix count */
12573 vty_out(vty, " %u accepted prefixes\n",
12574 p->pcount[afi][safi]);
12575
12576 /* maximum-prefix-out */
12577 if (CHECK_FLAG(p->af_flags[afi][safi],
12578 PEER_FLAG_MAX_PREFIX_OUT))
12579 vty_out(vty,
12580 " Maximum allowed prefixes sent %u\n",
12581 p->pmax_out[afi][safi]);
12582
12583 /* Maximum prefix */
12584 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12585 vty_out(vty,
12586 " Maximum prefixes allowed %u%s\n",
12587 p->pmax[afi][safi],
12588 CHECK_FLAG(p->af_flags[afi][safi],
12589 PEER_FLAG_MAX_PREFIX_WARNING)
12590 ? " (warning-only)"
12591 : "");
12592 vty_out(vty, " Threshold for warning message %d%%",
12593 p->pmax_threshold[afi][safi]);
12594 if (p->pmax_restart[afi][safi])
12595 vty_out(vty, ", restart interval %d min",
12596 p->pmax_restart[afi][safi]);
12597 vty_out(vty, "\n");
12598 }
12599
12600 vty_out(vty, "\n");
12601 }
12602 }
12603
12604 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12605 json_object *json)
12606 {
12607 struct bgp *bgp;
12608 char buf1[PREFIX2STR_BUFFER];
12609 char timebuf[BGP_UPTIME_LEN];
12610 char dn_flag[2];
12611 afi_t afi;
12612 safi_t safi;
12613 uint16_t i;
12614 uint8_t *msg;
12615 json_object *json_neigh = NULL;
12616 time_t epoch_tbuf;
12617 uint32_t sync_tcp_mss;
12618
12619 bgp = p->bgp;
12620
12621 if (use_json)
12622 json_neigh = json_object_new_object();
12623
12624 memset(dn_flag, '\0', sizeof(dn_flag));
12625 if (!p->conf_if && peer_dynamic_neighbor(p))
12626 dn_flag[0] = '*';
12627
12628 if (!use_json) {
12629 if (p->conf_if) /* Configured interface name. */
12630 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12631 &p->su);
12632 else /* Configured IP address. */
12633 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12634 p->host);
12635 }
12636
12637 if (use_json) {
12638 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12639 json_object_string_add(json_neigh, "bgpNeighborAddr",
12640 "none");
12641 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12642 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12643 "%pSU", &p->su);
12644
12645 json_object_int_add(json_neigh, "remoteAs", p->as);
12646
12647 if (p->change_local_as)
12648 json_object_int_add(json_neigh, "localAs",
12649 p->change_local_as);
12650 else
12651 json_object_int_add(json_neigh, "localAs", p->local_as);
12652
12653 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12654 json_object_boolean_true_add(json_neigh,
12655 "localAsNoPrepend");
12656
12657 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12658 json_object_boolean_true_add(json_neigh,
12659 "localAsReplaceAs");
12660 } else {
12661 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12662 || (p->as_type == AS_INTERNAL))
12663 vty_out(vty, "remote AS %u, ", p->as);
12664 else
12665 vty_out(vty, "remote AS Unspecified, ");
12666 vty_out(vty, "local AS %u%s%s, ",
12667 p->change_local_as ? p->change_local_as : p->local_as,
12668 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12669 ? " no-prepend"
12670 : "",
12671 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12672 ? " replace-as"
12673 : "");
12674 }
12675 /* peer type internal or confed-internal */
12676 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12677 if (use_json) {
12678 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12679 json_object_boolean_true_add(
12680 json_neigh, "nbrConfedInternalLink");
12681 else
12682 json_object_boolean_true_add(json_neigh,
12683 "nbrInternalLink");
12684 } else {
12685 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12686 vty_out(vty, "confed-internal link\n");
12687 else
12688 vty_out(vty, "internal link\n");
12689 }
12690 /* peer type external or confed-external */
12691 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12692 if (use_json) {
12693 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12694 json_object_boolean_true_add(
12695 json_neigh, "nbrConfedExternalLink");
12696 else
12697 json_object_boolean_true_add(json_neigh,
12698 "nbrExternalLink");
12699 } else {
12700 if (bgp_confederation_peers_check(bgp, p->as))
12701 vty_out(vty, "confed-external link\n");
12702 else
12703 vty_out(vty, "external link\n");
12704 }
12705 } else {
12706 if (use_json)
12707 json_object_boolean_true_add(json_neigh,
12708 "nbrUnspecifiedLink");
12709 else
12710 vty_out(vty, "unspecified link\n");
12711 }
12712
12713 /* Roles */
12714 if (use_json) {
12715 json_object_string_add(json_neigh, "localRole",
12716 bgp_get_name_by_role(p->local_role));
12717 json_object_string_add(json_neigh, "remoteRole",
12718 bgp_get_name_by_role(p->remote_role));
12719 } else {
12720 vty_out(vty, " Local Role: %s\n",
12721 bgp_get_name_by_role(p->local_role));
12722 vty_out(vty, " Remote Role: %s\n",
12723 bgp_get_name_by_role(p->remote_role));
12724 }
12725
12726
12727 /* Description. */
12728 if (p->desc) {
12729 if (use_json)
12730 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12731 else
12732 vty_out(vty, " Description: %s\n", p->desc);
12733 }
12734
12735 if (p->hostname) {
12736 if (use_json) {
12737 if (p->hostname)
12738 json_object_string_add(json_neigh, "hostname",
12739 p->hostname);
12740
12741 if (p->domainname)
12742 json_object_string_add(json_neigh, "domainname",
12743 p->domainname);
12744 } else {
12745 if (p->domainname && (p->domainname[0] != '\0'))
12746 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12747 p->domainname);
12748 else
12749 vty_out(vty, "Hostname: %s\n", p->hostname);
12750 }
12751 }
12752
12753 /* Peer-group */
12754 if (p->group) {
12755 if (use_json) {
12756 json_object_string_add(json_neigh, "peerGroup",
12757 p->group->name);
12758
12759 if (dn_flag[0]) {
12760 struct prefix prefix, *range = NULL;
12761
12762 if (sockunion2hostprefix(&(p->su), &prefix))
12763 range = peer_group_lookup_dynamic_neighbor_range(
12764 p->group, &prefix);
12765
12766 if (range) {
12767 json_object_string_addf(
12768 json_neigh,
12769 "peerSubnetRangeGroup", "%pFX",
12770 range);
12771 }
12772 }
12773 } else {
12774 vty_out(vty,
12775 " Member of peer-group %s for session parameters\n",
12776 p->group->name);
12777
12778 if (dn_flag[0]) {
12779 struct prefix prefix, *range = NULL;
12780
12781 if (sockunion2hostprefix(&(p->su), &prefix))
12782 range = peer_group_lookup_dynamic_neighbor_range(
12783 p->group, &prefix);
12784
12785 if (range) {
12786 vty_out(vty,
12787 " Belongs to the subnet range group: %pFX\n",
12788 range);
12789 }
12790 }
12791 }
12792 }
12793
12794 if (use_json) {
12795 /* Administrative shutdown. */
12796 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12797 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12798 json_object_boolean_true_add(json_neigh,
12799 "adminShutDown");
12800
12801 /* BGP Version. */
12802 json_object_int_add(json_neigh, "bgpVersion", 4);
12803 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12804 &p->remote_id);
12805 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12806 &bgp->router_id);
12807
12808 /* Confederation */
12809 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12810 && bgp_confederation_peers_check(bgp, p->as))
12811 json_object_boolean_true_add(json_neigh,
12812 "nbrCommonAdmin");
12813
12814 /* Status. */
12815 json_object_string_add(
12816 json_neigh, "bgpState",
12817 lookup_msg(bgp_status_msg, p->status, NULL));
12818
12819 if (peer_established(p)) {
12820 time_t uptime;
12821
12822 uptime = monotime(NULL);
12823 uptime -= p->uptime;
12824 epoch_tbuf = time(NULL) - uptime;
12825
12826 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12827 uptime * 1000);
12828 json_object_string_add(json_neigh, "bgpTimerUpString",
12829 peer_uptime(p->uptime, timebuf,
12830 BGP_UPTIME_LEN, 0,
12831 NULL));
12832 json_object_int_add(json_neigh,
12833 "bgpTimerUpEstablishedEpoch",
12834 epoch_tbuf);
12835 }
12836
12837 else if (p->status == Active) {
12838 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12839 json_object_string_add(json_neigh, "bgpStateIs",
12840 "passive");
12841 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12842 json_object_string_add(json_neigh, "bgpStateIs",
12843 "passiveNSF");
12844 }
12845
12846 /* read timer */
12847 time_t uptime;
12848 struct tm tm;
12849
12850 uptime = monotime(NULL);
12851 uptime -= p->readtime;
12852 gmtime_r(&uptime, &tm);
12853
12854 json_object_int_add(json_neigh, "bgpTimerLastRead",
12855 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12856 + (tm.tm_hour * 3600000));
12857
12858 uptime = monotime(NULL);
12859 uptime -= p->last_write;
12860 gmtime_r(&uptime, &tm);
12861
12862 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12863 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12864 + (tm.tm_hour * 3600000));
12865
12866 uptime = monotime(NULL);
12867 uptime -= p->update_time;
12868 gmtime_r(&uptime, &tm);
12869
12870 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12871 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12872 + (tm.tm_hour * 3600000));
12873
12874 /* Configured timer values. */
12875 json_object_int_add(json_neigh,
12876 "bgpTimerConfiguredHoldTimeMsecs",
12877 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12878 ? p->holdtime * 1000
12879 : bgp->default_holdtime * 1000);
12880 json_object_int_add(json_neigh,
12881 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12882 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12883 ? p->keepalive * 1000
12884 : bgp->default_keepalive * 1000);
12885 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12886 p->v_holdtime * 1000);
12887 json_object_int_add(json_neigh,
12888 "bgpTimerKeepAliveIntervalMsecs",
12889 p->v_keepalive * 1000);
12890 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12891 json_object_int_add(json_neigh,
12892 "bgpTimerDelayOpenTimeMsecs",
12893 p->v_delayopen * 1000);
12894 }
12895
12896 /* Configured and Synced tcp-mss value for peer */
12897 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12898 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12899 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12900 p->tcp_mss);
12901 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12902 sync_tcp_mss);
12903 }
12904
12905 /* Extended Optional Parameters Length for BGP OPEN Message */
12906 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12907 json_object_boolean_true_add(
12908 json_neigh, "extendedOptionalParametersLength");
12909 else
12910 json_object_boolean_false_add(
12911 json_neigh, "extendedOptionalParametersLength");
12912
12913 /* Conditional advertisements */
12914 json_object_int_add(
12915 json_neigh,
12916 "bgpTimerConfiguredConditionalAdvertisementsSec",
12917 bgp->condition_check_period);
12918 if (thread_is_scheduled(bgp->t_condition_check))
12919 json_object_int_add(
12920 json_neigh,
12921 "bgpTimerUntilConditionalAdvertisementsSec",
12922 thread_timer_remain_second(
12923 bgp->t_condition_check));
12924 } else {
12925 /* Administrative shutdown. */
12926 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12927 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12928 vty_out(vty, " Administratively shut down\n");
12929
12930 /* BGP Version. */
12931 vty_out(vty, " BGP version 4");
12932 vty_out(vty, ", remote router ID %s",
12933 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12934 vty_out(vty, ", local router ID %s\n",
12935 inet_ntop(AF_INET, &bgp->router_id, buf1,
12936 sizeof(buf1)));
12937
12938 /* Confederation */
12939 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12940 && bgp_confederation_peers_check(bgp, p->as))
12941 vty_out(vty,
12942 " Neighbor under common administration\n");
12943
12944 /* Status. */
12945 vty_out(vty, " BGP state = %s",
12946 lookup_msg(bgp_status_msg, p->status, NULL));
12947
12948 if (peer_established(p))
12949 vty_out(vty, ", up for %8s",
12950 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12951 0, NULL));
12952
12953 else if (p->status == Active) {
12954 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12955 vty_out(vty, " (passive)");
12956 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12957 vty_out(vty, " (NSF passive)");
12958 }
12959 vty_out(vty, "\n");
12960
12961 /* read timer */
12962 vty_out(vty, " Last read %s",
12963 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12964 NULL));
12965 vty_out(vty, ", Last write %s\n",
12966 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12967 NULL));
12968
12969 /* Configured timer values. */
12970 vty_out(vty,
12971 " Hold time is %d seconds, keepalive interval is %d seconds\n",
12972 p->v_holdtime, p->v_keepalive);
12973 vty_out(vty, " Configured hold time is %d seconds",
12974 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12975 ? p->holdtime
12976 : bgp->default_holdtime);
12977 vty_out(vty, ", keepalive interval is %d seconds\n",
12978 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12979 ? p->keepalive
12980 : bgp->default_keepalive);
12981 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12982 vty_out(vty,
12983 " Configured DelayOpenTime is %d seconds\n",
12984 p->delayopen);
12985
12986 /* Configured and synced tcp-mss value for peer */
12987 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12988 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12989 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12990 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12991 }
12992
12993 /* Extended Optional Parameters Length for BGP OPEN Message */
12994 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12995 vty_out(vty,
12996 " Extended Optional Parameters Length is enabled\n");
12997
12998 /* Conditional advertisements */
12999 vty_out(vty,
13000 " Configured conditional advertisements interval is %d seconds\n",
13001 bgp->condition_check_period);
13002 if (thread_is_scheduled(bgp->t_condition_check))
13003 vty_out(vty,
13004 " Time until conditional advertisements begin is %lu seconds\n",
13005 thread_timer_remain_second(
13006 bgp->t_condition_check));
13007 }
13008 /* Capability. */
13009 if (peer_established(p) &&
13010 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13011 if (use_json) {
13012 json_object *json_cap = NULL;
13013
13014 json_cap = json_object_new_object();
13015
13016 /* AS4 */
13017 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13018 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13019 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13020 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13021 json_object_string_add(
13022 json_cap, "4byteAs",
13023 "advertisedAndReceived");
13024 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13025 json_object_string_add(json_cap,
13026 "4byteAs",
13027 "advertised");
13028 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13029 json_object_string_add(json_cap,
13030 "4byteAs",
13031 "received");
13032 }
13033
13034 /* Extended Message Support */
13035 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13036 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13037 json_object_string_add(json_cap,
13038 "extendedMessage",
13039 "advertisedAndReceived");
13040 else if (CHECK_FLAG(p->cap,
13041 PEER_CAP_EXTENDED_MESSAGE_ADV))
13042 json_object_string_add(json_cap,
13043 "extendedMessage",
13044 "advertised");
13045 else if (CHECK_FLAG(p->cap,
13046 PEER_CAP_EXTENDED_MESSAGE_RCV))
13047 json_object_string_add(json_cap,
13048 "extendedMessage",
13049 "received");
13050
13051 /* AddPath */
13052 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13053 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13054 json_object *json_add = NULL;
13055 const char *print_store;
13056
13057 json_add = json_object_new_object();
13058
13059 FOREACH_AFI_SAFI (afi, safi) {
13060 json_object *json_sub = NULL;
13061 json_sub = json_object_new_object();
13062 print_store = get_afi_safi_str(
13063 afi, safi, true);
13064
13065 if (CHECK_FLAG(
13066 p->af_cap[afi][safi],
13067 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13068 CHECK_FLAG(
13069 p->af_cap[afi][safi],
13070 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13071 if (CHECK_FLAG(
13072 p->af_cap[afi]
13073 [safi],
13074 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13075 CHECK_FLAG(
13076 p->af_cap[afi]
13077 [safi],
13078 PEER_CAP_ADDPATH_AF_TX_RCV))
13079 json_object_boolean_true_add(
13080 json_sub,
13081 "txAdvertisedAndReceived");
13082 else if (
13083 CHECK_FLAG(
13084 p->af_cap[afi]
13085 [safi],
13086 PEER_CAP_ADDPATH_AF_TX_ADV))
13087 json_object_boolean_true_add(
13088 json_sub,
13089 "txAdvertised");
13090 else if (
13091 CHECK_FLAG(
13092 p->af_cap[afi]
13093 [safi],
13094 PEER_CAP_ADDPATH_AF_TX_RCV))
13095 json_object_boolean_true_add(
13096 json_sub,
13097 "txReceived");
13098 }
13099
13100 if (CHECK_FLAG(
13101 p->af_cap[afi][safi],
13102 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13103 CHECK_FLAG(
13104 p->af_cap[afi][safi],
13105 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13106 if (CHECK_FLAG(
13107 p->af_cap[afi]
13108 [safi],
13109 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13110 CHECK_FLAG(
13111 p->af_cap[afi]
13112 [safi],
13113 PEER_CAP_ADDPATH_AF_RX_RCV))
13114 json_object_boolean_true_add(
13115 json_sub,
13116 "rxAdvertisedAndReceived");
13117 else if (
13118 CHECK_FLAG(
13119 p->af_cap[afi]
13120 [safi],
13121 PEER_CAP_ADDPATH_AF_RX_ADV))
13122 json_object_boolean_true_add(
13123 json_sub,
13124 "rxAdvertised");
13125 else if (
13126 CHECK_FLAG(
13127 p->af_cap[afi]
13128 [safi],
13129 PEER_CAP_ADDPATH_AF_RX_RCV))
13130 json_object_boolean_true_add(
13131 json_sub,
13132 "rxReceived");
13133 }
13134
13135 if (CHECK_FLAG(
13136 p->af_cap[afi][safi],
13137 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13138 CHECK_FLAG(
13139 p->af_cap[afi][safi],
13140 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13141 CHECK_FLAG(
13142 p->af_cap[afi][safi],
13143 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13144 CHECK_FLAG(
13145 p->af_cap[afi][safi],
13146 PEER_CAP_ADDPATH_AF_RX_RCV))
13147 json_object_object_add(
13148 json_add, print_store,
13149 json_sub);
13150 else
13151 json_object_free(json_sub);
13152 }
13153
13154 json_object_object_add(json_cap, "addPath",
13155 json_add);
13156 }
13157
13158 /* Dynamic */
13159 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13160 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13161 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13162 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13163 json_object_string_add(
13164 json_cap, "dynamic",
13165 "advertisedAndReceived");
13166 else if (CHECK_FLAG(p->cap,
13167 PEER_CAP_DYNAMIC_ADV))
13168 json_object_string_add(json_cap,
13169 "dynamic",
13170 "advertised");
13171 else if (CHECK_FLAG(p->cap,
13172 PEER_CAP_DYNAMIC_RCV))
13173 json_object_string_add(json_cap,
13174 "dynamic",
13175 "received");
13176 }
13177
13178 /* Role */
13179 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13180 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13181 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13182 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13183 json_object_string_add(
13184 json_cap, "role",
13185 "advertisedAndReceived");
13186 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13187 json_object_string_add(json_cap, "role",
13188 "advertised");
13189 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13190 json_object_string_add(json_cap, "role",
13191 "received");
13192 }
13193
13194 /* Extended nexthop */
13195 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13196 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13197 json_object *json_nxt = NULL;
13198 const char *print_store;
13199
13200
13201 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13202 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13203 json_object_string_add(
13204 json_cap, "extendedNexthop",
13205 "advertisedAndReceived");
13206 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13207 json_object_string_add(
13208 json_cap, "extendedNexthop",
13209 "advertised");
13210 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13211 json_object_string_add(
13212 json_cap, "extendedNexthop",
13213 "received");
13214
13215 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13216 json_nxt = json_object_new_object();
13217
13218 for (safi = SAFI_UNICAST;
13219 safi < SAFI_MAX; safi++) {
13220 if (CHECK_FLAG(
13221 p->af_cap[AFI_IP]
13222 [safi],
13223 PEER_CAP_ENHE_AF_RCV)) {
13224 print_store =
13225 get_afi_safi_str(
13226 AFI_IP,
13227 safi,
13228 true);
13229 json_object_string_add(
13230 json_nxt,
13231 print_store,
13232 "recieved"); /* misspelled for compatibility */
13233 }
13234 }
13235 json_object_object_add(
13236 json_cap,
13237 "extendedNexthopFamililesByPeer",
13238 json_nxt);
13239 }
13240 }
13241
13242 /* Long-lived Graceful Restart */
13243 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13244 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13245 json_object *json_llgr = NULL;
13246 const char *afi_safi_str;
13247
13248 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13249 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13250 json_object_string_add(
13251 json_cap,
13252 "longLivedGracefulRestart",
13253 "advertisedAndReceived");
13254 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13255 json_object_string_add(
13256 json_cap,
13257 "longLivedGracefulRestart",
13258 "advertised");
13259 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13260 json_object_string_add(
13261 json_cap,
13262 "longLivedGracefulRestart",
13263 "received");
13264
13265 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13266 json_llgr = json_object_new_object();
13267
13268 FOREACH_AFI_SAFI (afi, safi) {
13269 if (CHECK_FLAG(
13270 p->af_cap[afi]
13271 [safi],
13272 PEER_CAP_ENHE_AF_RCV)) {
13273 afi_safi_str =
13274 get_afi_safi_str(
13275 afi,
13276 safi,
13277 true);
13278 json_object_string_add(
13279 json_llgr,
13280 afi_safi_str,
13281 "received");
13282 }
13283 }
13284 json_object_object_add(
13285 json_cap,
13286 "longLivedGracefulRestartByPeer",
13287 json_llgr);
13288 }
13289 }
13290
13291 /* Route Refresh */
13292 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13293 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13294 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13295 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13296 (CHECK_FLAG(p->cap,
13297 PEER_CAP_REFRESH_NEW_RCV) ||
13298 CHECK_FLAG(p->cap,
13299 PEER_CAP_REFRESH_OLD_RCV))) {
13300 if (CHECK_FLAG(
13301 p->cap,
13302 PEER_CAP_REFRESH_OLD_RCV) &&
13303 CHECK_FLAG(
13304 p->cap,
13305 PEER_CAP_REFRESH_NEW_RCV))
13306 json_object_string_add(
13307 json_cap,
13308 "routeRefresh",
13309 "advertisedAndReceivedOldNew");
13310 else {
13311 if (CHECK_FLAG(
13312 p->cap,
13313 PEER_CAP_REFRESH_OLD_RCV))
13314 json_object_string_add(
13315 json_cap,
13316 "routeRefresh",
13317 "advertisedAndReceivedOld");
13318 else
13319 json_object_string_add(
13320 json_cap,
13321 "routeRefresh",
13322 "advertisedAndReceivedNew");
13323 }
13324 } else if (CHECK_FLAG(p->cap,
13325 PEER_CAP_REFRESH_ADV))
13326 json_object_string_add(json_cap,
13327 "routeRefresh",
13328 "advertised");
13329 else if (CHECK_FLAG(p->cap,
13330 PEER_CAP_REFRESH_NEW_RCV) ||
13331 CHECK_FLAG(p->cap,
13332 PEER_CAP_REFRESH_OLD_RCV))
13333 json_object_string_add(json_cap,
13334 "routeRefresh",
13335 "received");
13336 }
13337
13338 /* Enhanced Route Refresh */
13339 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13340 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13341 if (CHECK_FLAG(p->cap,
13342 PEER_CAP_ENHANCED_RR_ADV) &&
13343 CHECK_FLAG(p->cap,
13344 PEER_CAP_ENHANCED_RR_RCV))
13345 json_object_string_add(
13346 json_cap,
13347 "enhancedRouteRefresh",
13348 "advertisedAndReceived");
13349 else if (CHECK_FLAG(p->cap,
13350 PEER_CAP_ENHANCED_RR_ADV))
13351 json_object_string_add(
13352 json_cap,
13353 "enhancedRouteRefresh",
13354 "advertised");
13355 else if (CHECK_FLAG(p->cap,
13356 PEER_CAP_ENHANCED_RR_RCV))
13357 json_object_string_add(
13358 json_cap,
13359 "enhancedRouteRefresh",
13360 "received");
13361 }
13362
13363 /* Multiprotocol Extensions */
13364 json_object *json_multi = NULL;
13365
13366 json_multi = json_object_new_object();
13367
13368 FOREACH_AFI_SAFI (afi, safi) {
13369 if (p->afc_adv[afi][safi] ||
13370 p->afc_recv[afi][safi]) {
13371 json_object *json_exten = NULL;
13372 json_exten = json_object_new_object();
13373
13374 if (p->afc_adv[afi][safi] &&
13375 p->afc_recv[afi][safi])
13376 json_object_boolean_true_add(
13377 json_exten,
13378 "advertisedAndReceived");
13379 else if (p->afc_adv[afi][safi])
13380 json_object_boolean_true_add(
13381 json_exten,
13382 "advertised");
13383 else if (p->afc_recv[afi][safi])
13384 json_object_boolean_true_add(
13385 json_exten, "received");
13386
13387 json_object_object_add(
13388 json_multi,
13389 get_afi_safi_str(afi, safi,
13390 true),
13391 json_exten);
13392 }
13393 }
13394 json_object_object_add(json_cap,
13395 "multiprotocolExtensions",
13396 json_multi);
13397
13398 /* Hostname capabilities */
13399 json_object *json_hname = NULL;
13400
13401 json_hname = json_object_new_object();
13402
13403 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13404 json_object_string_add(
13405 json_hname, "advHostName",
13406 bgp->peer_self->hostname
13407 ? bgp->peer_self->hostname
13408 : "n/a");
13409 json_object_string_add(
13410 json_hname, "advDomainName",
13411 bgp->peer_self->domainname
13412 ? bgp->peer_self->domainname
13413 : "n/a");
13414 }
13415
13416
13417 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13418 json_object_string_add(
13419 json_hname, "rcvHostName",
13420 p->hostname ? p->hostname : "n/a");
13421 json_object_string_add(
13422 json_hname, "rcvDomainName",
13423 p->domainname ? p->domainname : "n/a");
13424 }
13425
13426 json_object_object_add(json_cap, "hostName",
13427 json_hname);
13428
13429 /* Graceful Restart */
13430 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13431 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13432 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13433 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13434 json_object_string_add(
13435 json_cap, "gracefulRestart",
13436 "advertisedAndReceived");
13437 else if (CHECK_FLAG(p->cap,
13438 PEER_CAP_RESTART_ADV))
13439 json_object_string_add(
13440 json_cap,
13441 "gracefulRestartCapability",
13442 "advertised");
13443 else if (CHECK_FLAG(p->cap,
13444 PEER_CAP_RESTART_RCV))
13445 json_object_string_add(
13446 json_cap,
13447 "gracefulRestartCapability",
13448 "received");
13449
13450 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13451 int restart_af_count = 0;
13452 json_object *json_restart = NULL;
13453 json_restart = json_object_new_object();
13454
13455 json_object_int_add(
13456 json_cap,
13457 "gracefulRestartRemoteTimerMsecs",
13458 p->v_gr_restart * 1000);
13459
13460 FOREACH_AFI_SAFI (afi, safi) {
13461 if (CHECK_FLAG(
13462 p->af_cap[afi]
13463 [safi],
13464 PEER_CAP_RESTART_AF_RCV)) {
13465 json_object *json_sub =
13466 NULL;
13467 json_sub =
13468 json_object_new_object();
13469
13470 if (CHECK_FLAG(
13471 p->af_cap
13472 [afi]
13473 [safi],
13474 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13475 json_object_boolean_true_add(
13476 json_sub,
13477 "preserved");
13478 restart_af_count++;
13479 json_object_object_add(
13480 json_restart,
13481 get_afi_safi_str(
13482 afi,
13483 safi,
13484 true),
13485 json_sub);
13486 }
13487 }
13488 if (!restart_af_count) {
13489 json_object_string_add(
13490 json_cap,
13491 "addressFamiliesByPeer",
13492 "none");
13493 json_object_free(json_restart);
13494 } else
13495 json_object_object_add(
13496 json_cap,
13497 "addressFamiliesByPeer",
13498 json_restart);
13499 }
13500 }
13501 json_object_object_add(
13502 json_neigh, "neighborCapabilities", json_cap);
13503 } else {
13504 vty_out(vty, " Neighbor capabilities:\n");
13505
13506 /* AS4 */
13507 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13508 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13509 vty_out(vty, " 4 Byte AS:");
13510 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13511 vty_out(vty, " advertised");
13512 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13513 vty_out(vty, " %sreceived",
13514 CHECK_FLAG(p->cap,
13515 PEER_CAP_AS4_ADV)
13516 ? "and "
13517 : "");
13518 vty_out(vty, "\n");
13519 }
13520
13521 /* Extended Message Support */
13522 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13523 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13524 vty_out(vty, " Extended Message:");
13525 if (CHECK_FLAG(p->cap,
13526 PEER_CAP_EXTENDED_MESSAGE_ADV))
13527 vty_out(vty, " advertised");
13528 if (CHECK_FLAG(p->cap,
13529 PEER_CAP_EXTENDED_MESSAGE_RCV))
13530 vty_out(vty, " %sreceived",
13531 CHECK_FLAG(
13532 p->cap,
13533 PEER_CAP_EXTENDED_MESSAGE_ADV)
13534 ? "and "
13535 : "");
13536 vty_out(vty, "\n");
13537 }
13538
13539 /* AddPath */
13540 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13541 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13542 vty_out(vty, " AddPath:\n");
13543
13544 FOREACH_AFI_SAFI (afi, safi) {
13545 if (CHECK_FLAG(
13546 p->af_cap[afi][safi],
13547 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13548 CHECK_FLAG(
13549 p->af_cap[afi][safi],
13550 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13551 vty_out(vty, " %s: TX ",
13552 get_afi_safi_str(
13553 afi, safi,
13554 false));
13555
13556 if (CHECK_FLAG(
13557 p->af_cap[afi]
13558 [safi],
13559 PEER_CAP_ADDPATH_AF_TX_ADV))
13560 vty_out(vty,
13561 "advertised");
13562
13563 if (CHECK_FLAG(
13564 p->af_cap[afi]
13565 [safi],
13566 PEER_CAP_ADDPATH_AF_TX_RCV))
13567 vty_out(vty,
13568 "%sreceived",
13569 CHECK_FLAG(
13570 p->af_cap
13571 [afi]
13572 [safi],
13573 PEER_CAP_ADDPATH_AF_TX_ADV)
13574 ? " and "
13575 : "");
13576
13577 vty_out(vty, "\n");
13578 }
13579
13580 if (CHECK_FLAG(
13581 p->af_cap[afi][safi],
13582 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13583 CHECK_FLAG(
13584 p->af_cap[afi][safi],
13585 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13586 vty_out(vty, " %s: RX ",
13587 get_afi_safi_str(
13588 afi, safi,
13589 false));
13590
13591 if (CHECK_FLAG(
13592 p->af_cap[afi]
13593 [safi],
13594 PEER_CAP_ADDPATH_AF_RX_ADV))
13595 vty_out(vty,
13596 "advertised");
13597
13598 if (CHECK_FLAG(
13599 p->af_cap[afi]
13600 [safi],
13601 PEER_CAP_ADDPATH_AF_RX_RCV))
13602 vty_out(vty,
13603 "%sreceived",
13604 CHECK_FLAG(
13605 p->af_cap
13606 [afi]
13607 [safi],
13608 PEER_CAP_ADDPATH_AF_RX_ADV)
13609 ? " and "
13610 : "");
13611
13612 vty_out(vty, "\n");
13613 }
13614 }
13615 }
13616
13617 /* Dynamic */
13618 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13619 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13620 vty_out(vty, " Dynamic:");
13621 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13622 vty_out(vty, " advertised");
13623 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13624 vty_out(vty, " %sreceived",
13625 CHECK_FLAG(p->cap,
13626 PEER_CAP_DYNAMIC_ADV)
13627 ? "and "
13628 : "");
13629 vty_out(vty, "\n");
13630 }
13631
13632 /* Role */
13633 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13634 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13635 vty_out(vty, " Role:");
13636 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13637 vty_out(vty, " advertised");
13638 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13639 vty_out(vty, " %sreceived",
13640 CHECK_FLAG(p->cap,
13641 PEER_CAP_ROLE_ADV)
13642 ? "and "
13643 : "");
13644 vty_out(vty, "\n");
13645 }
13646
13647 /* Extended nexthop */
13648 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13649 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13650 vty_out(vty, " Extended nexthop:");
13651 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13652 vty_out(vty, " advertised");
13653 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13654 vty_out(vty, " %sreceived",
13655 CHECK_FLAG(p->cap,
13656 PEER_CAP_ENHE_ADV)
13657 ? "and "
13658 : "");
13659 vty_out(vty, "\n");
13660
13661 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13662 vty_out(vty,
13663 " Address families by peer:\n ");
13664 for (safi = SAFI_UNICAST;
13665 safi < SAFI_MAX; safi++)
13666 if (CHECK_FLAG(
13667 p->af_cap[AFI_IP]
13668 [safi],
13669 PEER_CAP_ENHE_AF_RCV))
13670 vty_out(vty,
13671 " %s\n",
13672 get_afi_safi_str(
13673 AFI_IP,
13674 safi,
13675 false));
13676 }
13677 }
13678
13679 /* Long-lived Graceful Restart */
13680 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13681 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13682 vty_out(vty,
13683 " Long-lived Graceful Restart:");
13684 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13685 vty_out(vty, " advertised");
13686 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13687 vty_out(vty, " %sreceived",
13688 CHECK_FLAG(p->cap,
13689 PEER_CAP_LLGR_ADV)
13690 ? "and "
13691 : "");
13692 vty_out(vty, "\n");
13693
13694 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13695 vty_out(vty,
13696 " Address families by peer:\n");
13697 FOREACH_AFI_SAFI (afi, safi)
13698 if (CHECK_FLAG(
13699 p->af_cap[afi]
13700 [safi],
13701 PEER_CAP_LLGR_AF_RCV))
13702 vty_out(vty,
13703 " %s\n",
13704 get_afi_safi_str(
13705 afi,
13706 safi,
13707 false));
13708 }
13709 }
13710
13711 /* Route Refresh */
13712 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13713 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13714 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13715 vty_out(vty, " Route refresh:");
13716 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13717 vty_out(vty, " advertised");
13718 if (CHECK_FLAG(p->cap,
13719 PEER_CAP_REFRESH_NEW_RCV) ||
13720 CHECK_FLAG(p->cap,
13721 PEER_CAP_REFRESH_OLD_RCV))
13722 vty_out(vty, " %sreceived(%s)",
13723 CHECK_FLAG(p->cap,
13724 PEER_CAP_REFRESH_ADV)
13725 ? "and "
13726 : "",
13727 (CHECK_FLAG(
13728 p->cap,
13729 PEER_CAP_REFRESH_OLD_RCV) &&
13730 CHECK_FLAG(
13731 p->cap,
13732 PEER_CAP_REFRESH_NEW_RCV))
13733 ? "old & new"
13734 : CHECK_FLAG(
13735 p->cap,
13736 PEER_CAP_REFRESH_OLD_RCV)
13737 ? "old"
13738 : "new");
13739
13740 vty_out(vty, "\n");
13741 }
13742
13743 /* Enhanced Route Refresh */
13744 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13745 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13746 vty_out(vty, " Enhanced Route Refresh:");
13747 if (CHECK_FLAG(p->cap,
13748 PEER_CAP_ENHANCED_RR_ADV))
13749 vty_out(vty, " advertised");
13750 if (CHECK_FLAG(p->cap,
13751 PEER_CAP_ENHANCED_RR_RCV))
13752 vty_out(vty, " %sreceived",
13753 CHECK_FLAG(p->cap,
13754 PEER_CAP_REFRESH_ADV)
13755 ? "and "
13756 : "");
13757 vty_out(vty, "\n");
13758 }
13759
13760 /* Multiprotocol Extensions */
13761 FOREACH_AFI_SAFI (afi, safi)
13762 if (p->afc_adv[afi][safi] ||
13763 p->afc_recv[afi][safi]) {
13764 vty_out(vty, " Address Family %s:",
13765 get_afi_safi_str(afi, safi,
13766 false));
13767 if (p->afc_adv[afi][safi])
13768 vty_out(vty, " advertised");
13769 if (p->afc_recv[afi][safi])
13770 vty_out(vty, " %sreceived",
13771 p->afc_adv[afi][safi]
13772 ? "and "
13773 : "");
13774 vty_out(vty, "\n");
13775 }
13776
13777 /* Hostname capability */
13778 vty_out(vty, " Hostname Capability:");
13779
13780 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13781 vty_out(vty,
13782 " advertised (name: %s,domain name: %s)",
13783 bgp->peer_self->hostname
13784 ? bgp->peer_self->hostname
13785 : "n/a",
13786 bgp->peer_self->domainname
13787 ? bgp->peer_self->domainname
13788 : "n/a");
13789 } else {
13790 vty_out(vty, " not advertised");
13791 }
13792
13793 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13794 vty_out(vty,
13795 " received (name: %s,domain name: %s)",
13796 p->hostname ? p->hostname : "n/a",
13797 p->domainname ? p->domainname : "n/a");
13798 } else {
13799 vty_out(vty, " not received");
13800 }
13801
13802 vty_out(vty, "\n");
13803
13804 /* Graceful Restart */
13805 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13806 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13807 vty_out(vty,
13808 " Graceful Restart Capability:");
13809 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13810 vty_out(vty, " advertised");
13811 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13812 vty_out(vty, " %sreceived",
13813 CHECK_FLAG(p->cap,
13814 PEER_CAP_RESTART_ADV)
13815 ? "and "
13816 : "");
13817 vty_out(vty, "\n");
13818
13819 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13820 int restart_af_count = 0;
13821
13822 vty_out(vty,
13823 " Remote Restart timer is %d seconds\n",
13824 p->v_gr_restart);
13825 vty_out(vty,
13826 " Address families by peer:\n ");
13827
13828 FOREACH_AFI_SAFI (afi, safi)
13829 if (CHECK_FLAG(
13830 p->af_cap[afi]
13831 [safi],
13832 PEER_CAP_RESTART_AF_RCV)) {
13833 vty_out(vty, "%s%s(%s)",
13834 restart_af_count
13835 ? ", "
13836 : "",
13837 get_afi_safi_str(
13838 afi,
13839 safi,
13840 false),
13841 CHECK_FLAG(
13842 p->af_cap
13843 [afi]
13844 [safi],
13845 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13846 ? "preserved"
13847 : "not preserved");
13848 restart_af_count++;
13849 }
13850 if (!restart_af_count)
13851 vty_out(vty, "none");
13852 vty_out(vty, "\n");
13853 }
13854 } /* Graceful Restart */
13855 }
13856 }
13857
13858 /* graceful restart information */
13859 json_object *json_grace = NULL;
13860 json_object *json_grace_send = NULL;
13861 json_object *json_grace_recv = NULL;
13862 int eor_send_af_count = 0;
13863 int eor_receive_af_count = 0;
13864
13865 if (use_json) {
13866 json_grace = json_object_new_object();
13867 json_grace_send = json_object_new_object();
13868 json_grace_recv = json_object_new_object();
13869
13870 if ((peer_established(p)) &&
13871 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13872 FOREACH_AFI_SAFI (afi, safi) {
13873 if (CHECK_FLAG(p->af_sflags[afi][safi],
13874 PEER_STATUS_EOR_SEND)) {
13875 json_object_boolean_true_add(
13876 json_grace_send,
13877 get_afi_safi_str(afi, safi,
13878 true));
13879 eor_send_af_count++;
13880 }
13881 }
13882 FOREACH_AFI_SAFI (afi, safi) {
13883 if (CHECK_FLAG(p->af_sflags[afi][safi],
13884 PEER_STATUS_EOR_RECEIVED)) {
13885 json_object_boolean_true_add(
13886 json_grace_recv,
13887 get_afi_safi_str(afi, safi,
13888 true));
13889 eor_receive_af_count++;
13890 }
13891 }
13892 }
13893 json_object_object_add(json_grace, "endOfRibSend",
13894 json_grace_send);
13895 json_object_object_add(json_grace, "endOfRibRecv",
13896 json_grace_recv);
13897
13898
13899 if (p->t_gr_restart)
13900 json_object_int_add(
13901 json_grace, "gracefulRestartTimerMsecs",
13902 thread_timer_remain_second(p->t_gr_restart) *
13903 1000);
13904
13905 if (p->t_gr_stale)
13906 json_object_int_add(
13907 json_grace, "gracefulStalepathTimerMsecs",
13908 thread_timer_remain_second(p->t_gr_stale) *
13909 1000);
13910 /* more gr info in new format */
13911 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13912 json_object_object_add(json_neigh, "gracefulRestartInfo",
13913 json_grace);
13914 } else {
13915 vty_out(vty, " Graceful restart information:\n");
13916 if ((peer_established(p)) &&
13917 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13918
13919 vty_out(vty, " End-of-RIB send: ");
13920 FOREACH_AFI_SAFI (afi, safi) {
13921 if (CHECK_FLAG(p->af_sflags[afi][safi],
13922 PEER_STATUS_EOR_SEND)) {
13923 vty_out(vty, "%s%s",
13924 eor_send_af_count ? ", " : "",
13925 get_afi_safi_str(afi, safi,
13926 false));
13927 eor_send_af_count++;
13928 }
13929 }
13930 vty_out(vty, "\n");
13931 vty_out(vty, " End-of-RIB received: ");
13932 FOREACH_AFI_SAFI (afi, safi) {
13933 if (CHECK_FLAG(p->af_sflags[afi][safi],
13934 PEER_STATUS_EOR_RECEIVED)) {
13935 vty_out(vty, "%s%s",
13936 eor_receive_af_count ? ", "
13937 : "",
13938 get_afi_safi_str(afi, safi,
13939 false));
13940 eor_receive_af_count++;
13941 }
13942 }
13943 vty_out(vty, "\n");
13944 }
13945
13946 if (p->t_gr_restart)
13947 vty_out(vty,
13948 " The remaining time of restart timer is %ld\n",
13949 thread_timer_remain_second(p->t_gr_restart));
13950
13951 if (p->t_gr_stale)
13952 vty_out(vty,
13953 " The remaining time of stalepath timer is %ld\n",
13954 thread_timer_remain_second(p->t_gr_stale));
13955
13956 /* more gr info in new format */
13957 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13958 }
13959
13960 if (use_json) {
13961 json_object *json_stat = NULL;
13962 json_stat = json_object_new_object();
13963 /* Packet counts. */
13964
13965 atomic_size_t outq_count, inq_count;
13966 outq_count = atomic_load_explicit(&p->obuf->count,
13967 memory_order_relaxed);
13968 inq_count = atomic_load_explicit(&p->ibuf->count,
13969 memory_order_relaxed);
13970
13971 json_object_int_add(json_stat, "depthInq",
13972 (unsigned long)inq_count);
13973 json_object_int_add(json_stat, "depthOutq",
13974 (unsigned long)outq_count);
13975 json_object_int_add(json_stat, "opensSent",
13976 atomic_load_explicit(&p->open_out,
13977 memory_order_relaxed));
13978 json_object_int_add(json_stat, "opensRecv",
13979 atomic_load_explicit(&p->open_in,
13980 memory_order_relaxed));
13981 json_object_int_add(json_stat, "notificationsSent",
13982 atomic_load_explicit(&p->notify_out,
13983 memory_order_relaxed));
13984 json_object_int_add(json_stat, "notificationsRecv",
13985 atomic_load_explicit(&p->notify_in,
13986 memory_order_relaxed));
13987 json_object_int_add(json_stat, "updatesSent",
13988 atomic_load_explicit(&p->update_out,
13989 memory_order_relaxed));
13990 json_object_int_add(json_stat, "updatesRecv",
13991 atomic_load_explicit(&p->update_in,
13992 memory_order_relaxed));
13993 json_object_int_add(json_stat, "keepalivesSent",
13994 atomic_load_explicit(&p->keepalive_out,
13995 memory_order_relaxed));
13996 json_object_int_add(json_stat, "keepalivesRecv",
13997 atomic_load_explicit(&p->keepalive_in,
13998 memory_order_relaxed));
13999 json_object_int_add(json_stat, "routeRefreshSent",
14000 atomic_load_explicit(&p->refresh_out,
14001 memory_order_relaxed));
14002 json_object_int_add(json_stat, "routeRefreshRecv",
14003 atomic_load_explicit(&p->refresh_in,
14004 memory_order_relaxed));
14005 json_object_int_add(json_stat, "capabilitySent",
14006 atomic_load_explicit(&p->dynamic_cap_out,
14007 memory_order_relaxed));
14008 json_object_int_add(json_stat, "capabilityRecv",
14009 atomic_load_explicit(&p->dynamic_cap_in,
14010 memory_order_relaxed));
14011 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14012 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14013 json_object_object_add(json_neigh, "messageStats", json_stat);
14014 } else {
14015 atomic_size_t outq_count, inq_count, open_out, open_in,
14016 notify_out, notify_in, update_out, update_in,
14017 keepalive_out, keepalive_in, refresh_out, refresh_in,
14018 dynamic_cap_out, dynamic_cap_in;
14019 outq_count = atomic_load_explicit(&p->obuf->count,
14020 memory_order_relaxed);
14021 inq_count = atomic_load_explicit(&p->ibuf->count,
14022 memory_order_relaxed);
14023 open_out = atomic_load_explicit(&p->open_out,
14024 memory_order_relaxed);
14025 open_in =
14026 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14027 notify_out = atomic_load_explicit(&p->notify_out,
14028 memory_order_relaxed);
14029 notify_in = atomic_load_explicit(&p->notify_in,
14030 memory_order_relaxed);
14031 update_out = atomic_load_explicit(&p->update_out,
14032 memory_order_relaxed);
14033 update_in = atomic_load_explicit(&p->update_in,
14034 memory_order_relaxed);
14035 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14036 memory_order_relaxed);
14037 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14038 memory_order_relaxed);
14039 refresh_out = atomic_load_explicit(&p->refresh_out,
14040 memory_order_relaxed);
14041 refresh_in = atomic_load_explicit(&p->refresh_in,
14042 memory_order_relaxed);
14043 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14044 memory_order_relaxed);
14045 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14046 memory_order_relaxed);
14047
14048 /* Packet counts. */
14049 vty_out(vty, " Message statistics:\n");
14050 vty_out(vty, " Inq depth is %zu\n", inq_count);
14051 vty_out(vty, " Outq depth is %zu\n", outq_count);
14052 vty_out(vty, " Sent Rcvd\n");
14053 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14054 open_in);
14055 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14056 notify_in);
14057 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14058 update_in);
14059 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14060 keepalive_in);
14061 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14062 refresh_in);
14063 vty_out(vty, " Capability: %10zu %10zu\n",
14064 dynamic_cap_out, dynamic_cap_in);
14065 vty_out(vty, " Total: %10u %10u\n",
14066 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14067 }
14068
14069 if (use_json) {
14070 /* advertisement-interval */
14071 json_object_int_add(json_neigh,
14072 "minBtwnAdvertisementRunsTimerMsecs",
14073 p->v_routeadv * 1000);
14074
14075 /* Update-source. */
14076 if (p->update_if || p->update_source) {
14077 if (p->update_if)
14078 json_object_string_add(json_neigh,
14079 "updateSource",
14080 p->update_if);
14081 else if (p->update_source)
14082 json_object_string_addf(json_neigh,
14083 "updateSource", "%pSU",
14084 p->update_source);
14085 }
14086 } else {
14087 /* advertisement-interval */
14088 vty_out(vty,
14089 " Minimum time between advertisement runs is %d seconds\n",
14090 p->v_routeadv);
14091
14092 /* Update-source. */
14093 if (p->update_if || p->update_source) {
14094 vty_out(vty, " Update source is ");
14095 if (p->update_if)
14096 vty_out(vty, "%s", p->update_if);
14097 else if (p->update_source)
14098 vty_out(vty, "%pSU", p->update_source);
14099 vty_out(vty, "\n");
14100 }
14101
14102 vty_out(vty, "\n");
14103 }
14104
14105 /* Address Family Information */
14106 json_object *json_hold = NULL;
14107
14108 if (use_json)
14109 json_hold = json_object_new_object();
14110
14111 FOREACH_AFI_SAFI (afi, safi)
14112 if (p->afc[afi][safi])
14113 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14114 json_hold);
14115
14116 if (use_json) {
14117 json_object_object_add(json_neigh, "addressFamilyInfo",
14118 json_hold);
14119 json_object_int_add(json_neigh, "connectionsEstablished",
14120 p->established);
14121 json_object_int_add(json_neigh, "connectionsDropped",
14122 p->dropped);
14123 } else
14124 vty_out(vty, " Connections established %d; dropped %d\n",
14125 p->established, p->dropped);
14126
14127 if (!p->last_reset) {
14128 if (use_json)
14129 json_object_string_add(json_neigh, "lastReset",
14130 "never");
14131 else
14132 vty_out(vty, " Last reset never\n");
14133 } else {
14134 if (use_json) {
14135 time_t uptime;
14136 struct tm tm;
14137
14138 uptime = monotime(NULL);
14139 uptime -= p->resettime;
14140 gmtime_r(&uptime, &tm);
14141
14142 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14143 (tm.tm_sec * 1000)
14144 + (tm.tm_min * 60000)
14145 + (tm.tm_hour * 3600000));
14146 bgp_show_peer_reset(NULL, p, json_neigh, true);
14147 } else {
14148 vty_out(vty, " Last reset %s, ",
14149 peer_uptime(p->resettime, timebuf,
14150 BGP_UPTIME_LEN, 0, NULL));
14151
14152 bgp_show_peer_reset(vty, p, NULL, false);
14153 if (p->last_reset_cause_size) {
14154 msg = p->last_reset_cause;
14155 vty_out(vty,
14156 " Message received that caused BGP to send a NOTIFICATION:\n ");
14157 for (i = 1; i <= p->last_reset_cause_size;
14158 i++) {
14159 vty_out(vty, "%02X", *msg++);
14160
14161 if (i != p->last_reset_cause_size) {
14162 if (i % 16 == 0) {
14163 vty_out(vty, "\n ");
14164 } else if (i % 4 == 0) {
14165 vty_out(vty, " ");
14166 }
14167 }
14168 }
14169 vty_out(vty, "\n");
14170 }
14171 }
14172 }
14173
14174 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14175 if (use_json)
14176 json_object_boolean_true_add(json_neigh,
14177 "prefixesConfigExceedMax");
14178 else
14179 vty_out(vty,
14180 " Peer had exceeded the max. no. of prefixes configured.\n");
14181
14182 if (p->t_pmax_restart) {
14183 if (use_json) {
14184 json_object_boolean_true_add(
14185 json_neigh, "reducePrefixNumFrom");
14186 json_object_int_add(json_neigh,
14187 "restartInTimerMsec",
14188 thread_timer_remain_second(
14189 p->t_pmax_restart)
14190 * 1000);
14191 } else
14192 vty_out(vty,
14193 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14194 p->host, thread_timer_remain_second(
14195 p->t_pmax_restart));
14196 } else {
14197 if (use_json)
14198 json_object_boolean_true_add(
14199 json_neigh,
14200 "reducePrefixNumAndClearIpBgp");
14201 else
14202 vty_out(vty,
14203 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14204 p->host);
14205 }
14206 }
14207
14208 /* EBGP Multihop and GTSM */
14209 if (p->sort != BGP_PEER_IBGP) {
14210 if (use_json) {
14211 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14212 json_object_int_add(json_neigh,
14213 "externalBgpNbrMaxHopsAway",
14214 p->gtsm_hops);
14215 else
14216 json_object_int_add(json_neigh,
14217 "externalBgpNbrMaxHopsAway",
14218 p->ttl);
14219 } else {
14220 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14221 vty_out(vty,
14222 " External BGP neighbor may be up to %d hops away.\n",
14223 p->gtsm_hops);
14224 else
14225 vty_out(vty,
14226 " External BGP neighbor may be up to %d hops away.\n",
14227 p->ttl);
14228 }
14229 } else {
14230 if (use_json) {
14231 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14232 json_object_int_add(json_neigh,
14233 "internalBgpNbrMaxHopsAway",
14234 p->gtsm_hops);
14235 else
14236 json_object_int_add(json_neigh,
14237 "internalBgpNbrMaxHopsAway",
14238 p->ttl);
14239 } else {
14240 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14241 vty_out(vty,
14242 " Internal BGP neighbor may be up to %d hops away.\n",
14243 p->gtsm_hops);
14244 else
14245 vty_out(vty,
14246 " Internal BGP neighbor may be up to %d hops away.\n",
14247 p->ttl);
14248 }
14249 }
14250
14251 /* Local address. */
14252 if (p->su_local) {
14253 if (use_json) {
14254 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14255 p->su_local);
14256 json_object_int_add(json_neigh, "portLocal",
14257 ntohs(p->su_local->sin.sin_port));
14258 } else
14259 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14260 p->su_local, ntohs(p->su_local->sin.sin_port));
14261 } else {
14262 if (use_json) {
14263 json_object_string_add(json_neigh, "hostLocal",
14264 "Unknown");
14265 json_object_int_add(json_neigh, "portLocal", -1);
14266 }
14267 }
14268
14269 /* Remote address. */
14270 if (p->su_remote) {
14271 if (use_json) {
14272 json_object_string_addf(json_neigh, "hostForeign",
14273 "%pSU", p->su_remote);
14274 json_object_int_add(json_neigh, "portForeign",
14275 ntohs(p->su_remote->sin.sin_port));
14276 } else
14277 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14278 p->su_remote,
14279 ntohs(p->su_remote->sin.sin_port));
14280 } else {
14281 if (use_json) {
14282 json_object_string_add(json_neigh, "hostForeign",
14283 "Unknown");
14284 json_object_int_add(json_neigh, "portForeign", -1);
14285 }
14286 }
14287
14288 /* Nexthop display. */
14289 if (p->su_local) {
14290 if (use_json) {
14291 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14292 &p->nexthop.v4);
14293 json_object_string_addf(json_neigh, "nexthopGlobal",
14294 "%pI6", &p->nexthop.v6_global);
14295 json_object_string_addf(json_neigh, "nexthopLocal",
14296 "%pI6", &p->nexthop.v6_local);
14297 if (p->shared_network)
14298 json_object_string_add(json_neigh,
14299 "bgpConnection",
14300 "sharedNetwork");
14301 else
14302 json_object_string_add(json_neigh,
14303 "bgpConnection",
14304 "nonSharedNetwork");
14305 } else {
14306 vty_out(vty, "Nexthop: %s\n",
14307 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14308 sizeof(buf1)));
14309 vty_out(vty, "Nexthop global: %s\n",
14310 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14311 sizeof(buf1)));
14312 vty_out(vty, "Nexthop local: %s\n",
14313 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14314 sizeof(buf1)));
14315 vty_out(vty, "BGP connection: %s\n",
14316 p->shared_network ? "shared network"
14317 : "non shared network");
14318 }
14319 }
14320
14321 /* Timer information. */
14322 if (use_json) {
14323 json_object_int_add(json_neigh, "connectRetryTimer",
14324 p->v_connect);
14325 if (peer_established(p) && p->rtt)
14326 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14327 p->rtt);
14328 if (p->t_start)
14329 json_object_int_add(
14330 json_neigh, "nextStartTimerDueInMsecs",
14331 thread_timer_remain_second(p->t_start) * 1000);
14332 if (p->t_connect)
14333 json_object_int_add(
14334 json_neigh, "nextConnectTimerDueInMsecs",
14335 thread_timer_remain_second(p->t_connect)
14336 * 1000);
14337 if (p->t_routeadv) {
14338 json_object_int_add(json_neigh, "mraiInterval",
14339 p->v_routeadv);
14340 json_object_int_add(
14341 json_neigh, "mraiTimerExpireInMsecs",
14342 thread_timer_remain_second(p->t_routeadv)
14343 * 1000);
14344 }
14345 if (p->password)
14346 json_object_int_add(json_neigh, "authenticationEnabled",
14347 1);
14348
14349 if (p->t_read)
14350 json_object_string_add(json_neigh, "readThread", "on");
14351 else
14352 json_object_string_add(json_neigh, "readThread", "off");
14353
14354 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14355 json_object_string_add(json_neigh, "writeThread", "on");
14356 else
14357 json_object_string_add(json_neigh, "writeThread",
14358 "off");
14359 } else {
14360 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14361 p->v_connect);
14362 if (peer_established(p) && p->rtt)
14363 vty_out(vty, "Estimated round trip time: %d ms\n",
14364 p->rtt);
14365 if (p->t_start)
14366 vty_out(vty, "Next start timer due in %ld seconds\n",
14367 thread_timer_remain_second(p->t_start));
14368 if (p->t_connect)
14369 vty_out(vty, "Next connect timer due in %ld seconds\n",
14370 thread_timer_remain_second(p->t_connect));
14371 if (p->t_routeadv)
14372 vty_out(vty,
14373 "MRAI (interval %u) timer expires in %ld seconds\n",
14374 p->v_routeadv,
14375 thread_timer_remain_second(p->t_routeadv));
14376 if (p->password)
14377 vty_out(vty, "Peer Authentication Enabled\n");
14378
14379 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14380 p->t_read ? "on" : "off",
14381 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14382 ? "on"
14383 : "off", p->fd);
14384 }
14385
14386 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14387 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14388 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14389
14390 if (!use_json)
14391 vty_out(vty, "\n");
14392
14393 /* BFD information. */
14394 if (p->bfd_config)
14395 bgp_bfd_show_info(vty, p, json_neigh);
14396
14397 if (use_json) {
14398 if (p->conf_if) /* Configured interface name. */
14399 json_object_object_add(json, p->conf_if, json_neigh);
14400 else /* Configured IP address. */
14401 json_object_object_add(json, p->host, json_neigh);
14402 }
14403 }
14404
14405 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14406 enum show_type type,
14407 union sockunion *su,
14408 const char *conf_if, afi_t afi,
14409 bool use_json)
14410 {
14411 struct listnode *node, *nnode;
14412 struct peer *peer;
14413 int find = 0;
14414 safi_t safi = SAFI_UNICAST;
14415 json_object *json = NULL;
14416 json_object *json_neighbor = NULL;
14417
14418 if (use_json) {
14419 json = json_object_new_object();
14420 json_neighbor = json_object_new_object();
14421 }
14422
14423 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14424
14425 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14426 continue;
14427
14428 if ((peer->afc[afi][safi]) == 0)
14429 continue;
14430
14431 if (type == show_all) {
14432 bgp_show_peer_gr_status(vty, peer, use_json,
14433 json_neighbor);
14434
14435 if (use_json) {
14436 json_object_object_add(json, peer->host,
14437 json_neighbor);
14438 json_neighbor = NULL;
14439 }
14440
14441 } else if (type == show_peer) {
14442 if (conf_if) {
14443 if ((peer->conf_if
14444 && !strcmp(peer->conf_if, conf_if))
14445 || (peer->hostname
14446 && !strcmp(peer->hostname, conf_if))) {
14447 find = 1;
14448 bgp_show_peer_gr_status(vty, peer,
14449 use_json,
14450 json_neighbor);
14451 }
14452 } else {
14453 if (sockunion_same(&peer->su, su)) {
14454 find = 1;
14455 bgp_show_peer_gr_status(vty, peer,
14456 use_json,
14457 json_neighbor);
14458 }
14459 }
14460 if (use_json && find)
14461 json_object_object_add(json, peer->host,
14462 json_neighbor);
14463 }
14464
14465 if (find) {
14466 json_neighbor = NULL;
14467 break;
14468 }
14469 }
14470
14471 if (type == show_peer && !find) {
14472 if (use_json)
14473 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14474 else
14475 vty_out(vty, "%% No such neighbor\n");
14476 }
14477 if (use_json) {
14478 if (json_neighbor)
14479 json_object_free(json_neighbor);
14480 vty_json(vty, json);
14481 } else {
14482 vty_out(vty, "\n");
14483 }
14484
14485 return CMD_SUCCESS;
14486 }
14487
14488 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14489 enum show_type type, union sockunion *su,
14490 const char *conf_if, bool use_json,
14491 json_object *json)
14492 {
14493 struct listnode *node, *nnode;
14494 struct peer *peer;
14495 int find = 0;
14496 bool nbr_output = false;
14497 afi_t afi = AFI_MAX;
14498 safi_t safi = SAFI_MAX;
14499
14500 if (type == show_ipv4_peer || type == show_ipv4_all) {
14501 afi = AFI_IP;
14502 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14503 afi = AFI_IP6;
14504 }
14505
14506 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14507 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14508 continue;
14509
14510 switch (type) {
14511 case show_all:
14512 bgp_show_peer(vty, peer, use_json, json);
14513 nbr_output = true;
14514 break;
14515 case show_peer:
14516 if (conf_if) {
14517 if ((peer->conf_if
14518 && !strcmp(peer->conf_if, conf_if))
14519 || (peer->hostname
14520 && !strcmp(peer->hostname, conf_if))) {
14521 find = 1;
14522 bgp_show_peer(vty, peer, use_json,
14523 json);
14524 }
14525 } else {
14526 if (sockunion_same(&peer->su, su)) {
14527 find = 1;
14528 bgp_show_peer(vty, peer, use_json,
14529 json);
14530 }
14531 }
14532 break;
14533 case show_ipv4_peer:
14534 case show_ipv6_peer:
14535 FOREACH_SAFI (safi) {
14536 if (peer->afc[afi][safi]) {
14537 if (conf_if) {
14538 if ((peer->conf_if
14539 && !strcmp(peer->conf_if, conf_if))
14540 || (peer->hostname
14541 && !strcmp(peer->hostname, conf_if))) {
14542 find = 1;
14543 bgp_show_peer(vty, peer, use_json,
14544 json);
14545 break;
14546 }
14547 } else {
14548 if (sockunion_same(&peer->su, su)) {
14549 find = 1;
14550 bgp_show_peer(vty, peer, use_json,
14551 json);
14552 break;
14553 }
14554 }
14555 }
14556 }
14557 break;
14558 case show_ipv4_all:
14559 case show_ipv6_all:
14560 FOREACH_SAFI (safi) {
14561 if (peer->afc[afi][safi]) {
14562 bgp_show_peer(vty, peer, use_json, json);
14563 nbr_output = true;
14564 break;
14565 }
14566 }
14567 break;
14568 }
14569 }
14570
14571 if ((type == show_peer || type == show_ipv4_peer ||
14572 type == show_ipv6_peer) && !find) {
14573 if (use_json)
14574 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14575 else
14576 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14577 }
14578
14579 if (type != show_peer && type != show_ipv4_peer &&
14580 type != show_ipv6_peer && !nbr_output && !use_json)
14581 vty_out(vty, "%% No BGP neighbors found\n");
14582
14583 if (use_json) {
14584 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14585 json, JSON_C_TO_STRING_PRETTY));
14586 } else {
14587 vty_out(vty, "\n");
14588 }
14589
14590 return CMD_SUCCESS;
14591 }
14592
14593 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14594 enum show_type type,
14595 const char *ip_str,
14596 afi_t afi, bool use_json)
14597 {
14598
14599 int ret;
14600 struct bgp *bgp;
14601 union sockunion su;
14602
14603 bgp = bgp_get_default();
14604
14605 if (!bgp)
14606 return;
14607
14608 if (!use_json)
14609 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14610 NULL);
14611
14612 if (ip_str) {
14613 ret = str2sockunion(ip_str, &su);
14614 if (ret < 0)
14615 bgp_show_neighbor_graceful_restart(
14616 vty, bgp, type, NULL, ip_str, afi, use_json);
14617 else
14618 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14619 NULL, afi, use_json);
14620 } else
14621 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14622 afi, use_json);
14623 }
14624
14625 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14626 enum show_type type,
14627 const char *ip_str,
14628 bool use_json)
14629 {
14630 struct listnode *node, *nnode;
14631 struct bgp *bgp;
14632 union sockunion su;
14633 json_object *json = NULL;
14634 int ret, is_first = 1;
14635 bool nbr_output = false;
14636
14637 if (use_json)
14638 vty_out(vty, "{\n");
14639
14640 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14641 nbr_output = true;
14642 if (use_json) {
14643 if (!(json = json_object_new_object())) {
14644 flog_err(
14645 EC_BGP_JSON_MEM_ERROR,
14646 "Unable to allocate memory for JSON object");
14647 vty_out(vty,
14648 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14649 return;
14650 }
14651
14652 json_object_int_add(json, "vrfId",
14653 (bgp->vrf_id == VRF_UNKNOWN)
14654 ? -1
14655 : (int64_t)bgp->vrf_id);
14656 json_object_string_add(
14657 json, "vrfName",
14658 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14659 ? VRF_DEFAULT_NAME
14660 : bgp->name);
14661
14662 if (!is_first)
14663 vty_out(vty, ",\n");
14664 else
14665 is_first = 0;
14666
14667 vty_out(vty, "\"%s\":",
14668 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14669 ? VRF_DEFAULT_NAME
14670 : bgp->name);
14671 } else {
14672 vty_out(vty, "\nInstance %s:\n",
14673 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14674 ? VRF_DEFAULT_NAME
14675 : bgp->name);
14676 }
14677
14678 if (type == show_peer || type == show_ipv4_peer ||
14679 type == show_ipv6_peer) {
14680 ret = str2sockunion(ip_str, &su);
14681 if (ret < 0)
14682 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14683 use_json, json);
14684 else
14685 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14686 use_json, json);
14687 } else {
14688 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14689 use_json, json);
14690 }
14691 json_object_free(json);
14692 json = NULL;
14693 }
14694
14695 if (use_json)
14696 vty_out(vty, "}\n");
14697 else if (!nbr_output)
14698 vty_out(vty, "%% BGP instance not found\n");
14699 }
14700
14701 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14702 enum show_type type, const char *ip_str,
14703 bool use_json)
14704 {
14705 int ret;
14706 struct bgp *bgp;
14707 union sockunion su;
14708 json_object *json = NULL;
14709
14710 if (name) {
14711 if (strmatch(name, "all")) {
14712 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14713 use_json);
14714 return CMD_SUCCESS;
14715 } else {
14716 bgp = bgp_lookup_by_name(name);
14717 if (!bgp) {
14718 if (use_json) {
14719 json = json_object_new_object();
14720 vty_json(vty, json);
14721 } else
14722 vty_out(vty,
14723 "%% BGP instance not found\n");
14724
14725 return CMD_WARNING;
14726 }
14727 }
14728 } else {
14729 bgp = bgp_get_default();
14730 }
14731
14732 if (bgp) {
14733 json = json_object_new_object();
14734 if (ip_str) {
14735 ret = str2sockunion(ip_str, &su);
14736 if (ret < 0)
14737 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14738 use_json, json);
14739 else
14740 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14741 use_json, json);
14742 } else {
14743 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14744 json);
14745 }
14746 json_object_free(json);
14747 } else {
14748 if (use_json)
14749 vty_out(vty, "{}\n");
14750 else
14751 vty_out(vty, "%% BGP instance not found\n");
14752 }
14753
14754 return CMD_SUCCESS;
14755 }
14756
14757
14758
14759 /* "show [ip] bgp neighbors graceful-restart" commands. */
14760 DEFUN (show_ip_bgp_neighbors_graceful_restart,
14761 show_ip_bgp_neighbors_graceful_restart_cmd,
14762 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14763 SHOW_STR
14764 BGP_STR
14765 IP_STR
14766 IPV6_STR
14767 NEIGHBOR_STR
14768 "Neighbor to display information about\n"
14769 "Neighbor to display information about\n"
14770 "Neighbor on BGP configured interface\n"
14771 GR_SHOW
14772 JSON_STR)
14773 {
14774 char *sh_arg = NULL;
14775 enum show_type sh_type;
14776 int idx = 0;
14777 afi_t afi = AFI_MAX;
14778 bool uj = use_json(argc, argv);
14779
14780 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14781 afi = AFI_MAX;
14782
14783 idx++;
14784
14785 if (argv_find(argv, argc, "A.B.C.D", &idx)
14786 || argv_find(argv, argc, "X:X::X:X", &idx)
14787 || argv_find(argv, argc, "WORD", &idx)) {
14788 sh_type = show_peer;
14789 sh_arg = argv[idx]->arg;
14790 } else
14791 sh_type = show_all;
14792
14793 if (!argv_find(argv, argc, "graceful-restart", &idx))
14794 return CMD_SUCCESS;
14795
14796
14797 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14798 afi, uj);
14799 }
14800
14801 /* "show [ip] bgp neighbors" commands. */
14802 DEFUN (show_ip_bgp_neighbors,
14803 show_ip_bgp_neighbors_cmd,
14804 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14805 SHOW_STR
14806 IP_STR
14807 BGP_STR
14808 BGP_INSTANCE_HELP_STR
14809 BGP_AF_STR
14810 BGP_AF_STR
14811 "Detailed information on TCP and BGP neighbor connections\n"
14812 "Neighbor to display information about\n"
14813 "Neighbor to display information about\n"
14814 "Neighbor on BGP configured interface\n"
14815 JSON_STR)
14816 {
14817 char *vrf = NULL;
14818 char *sh_arg = NULL;
14819 enum show_type sh_type;
14820 afi_t afi = AFI_MAX;
14821
14822 bool uj = use_json(argc, argv);
14823
14824 int idx = 0;
14825
14826 /* [<vrf> VIEWVRFNAME] */
14827 if (argv_find(argv, argc, "vrf", &idx)) {
14828 vrf = argv[idx + 1]->arg;
14829 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14830 vrf = NULL;
14831 } else if (argv_find(argv, argc, "view", &idx))
14832 /* [<view> VIEWVRFNAME] */
14833 vrf = argv[idx + 1]->arg;
14834
14835 idx++;
14836
14837 if (argv_find(argv, argc, "ipv4", &idx)) {
14838 sh_type = show_ipv4_all;
14839 afi = AFI_IP;
14840 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14841 sh_type = show_ipv6_all;
14842 afi = AFI_IP6;
14843 } else {
14844 sh_type = show_all;
14845 }
14846
14847 if (argv_find(argv, argc, "A.B.C.D", &idx)
14848 || argv_find(argv, argc, "X:X::X:X", &idx)
14849 || argv_find(argv, argc, "WORD", &idx)) {
14850 sh_type = show_peer;
14851 sh_arg = argv[idx]->arg;
14852 }
14853
14854 if (sh_type == show_peer && afi == AFI_IP) {
14855 sh_type = show_ipv4_peer;
14856 } else if (sh_type == show_peer && afi == AFI_IP6) {
14857 sh_type = show_ipv6_peer;
14858 }
14859
14860 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14861 }
14862
14863 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14864 paths' and `show ip mbgp paths'. Those functions results are the
14865 same.*/
14866 DEFUN (show_ip_bgp_paths,
14867 show_ip_bgp_paths_cmd,
14868 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14869 SHOW_STR
14870 IP_STR
14871 BGP_STR
14872 BGP_SAFI_HELP_STR
14873 "Path information\n")
14874 {
14875 vty_out(vty, "Address Refcnt Path\n");
14876 aspath_print_all_vty(vty);
14877 return CMD_SUCCESS;
14878 }
14879
14880 #include "hash.h"
14881
14882 static void community_show_all_iterator(struct hash_bucket *bucket,
14883 struct vty *vty)
14884 {
14885 struct community *com;
14886
14887 com = (struct community *)bucket->data;
14888 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14889 community_str(com, false, false));
14890 }
14891
14892 /* Show BGP's community internal data. */
14893 DEFUN (show_ip_bgp_community_info,
14894 show_ip_bgp_community_info_cmd,
14895 "show [ip] bgp community-info",
14896 SHOW_STR
14897 IP_STR
14898 BGP_STR
14899 "List all bgp community information\n")
14900 {
14901 vty_out(vty, "Address Refcnt Community\n");
14902
14903 hash_iterate(community_hash(),
14904 (void (*)(struct hash_bucket *,
14905 void *))community_show_all_iterator,
14906 vty);
14907
14908 return CMD_SUCCESS;
14909 }
14910
14911 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14912 struct vty *vty)
14913 {
14914 struct lcommunity *lcom;
14915
14916 lcom = (struct lcommunity *)bucket->data;
14917 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14918 lcommunity_str(lcom, false, false));
14919 }
14920
14921 /* Show BGP's community internal data. */
14922 DEFUN (show_ip_bgp_lcommunity_info,
14923 show_ip_bgp_lcommunity_info_cmd,
14924 "show ip bgp large-community-info",
14925 SHOW_STR
14926 IP_STR
14927 BGP_STR
14928 "List all bgp large-community information\n")
14929 {
14930 vty_out(vty, "Address Refcnt Large-community\n");
14931
14932 hash_iterate(lcommunity_hash(),
14933 (void (*)(struct hash_bucket *,
14934 void *))lcommunity_show_all_iterator,
14935 vty);
14936
14937 return CMD_SUCCESS;
14938 }
14939 /* Graceful Restart */
14940
14941 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14942 struct bgp *bgp,
14943 bool use_json,
14944 json_object *json)
14945 {
14946
14947
14948 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14949
14950 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14951
14952 switch (bgp_global_gr_mode) {
14953
14954 case GLOBAL_HELPER:
14955 vty_out(vty, "Global BGP GR Mode : Helper\n");
14956 break;
14957
14958 case GLOBAL_GR:
14959 vty_out(vty, "Global BGP GR Mode : Restart\n");
14960 break;
14961
14962 case GLOBAL_DISABLE:
14963 vty_out(vty, "Global BGP GR Mode : Disable\n");
14964 break;
14965
14966 case GLOBAL_INVALID:
14967 vty_out(vty,
14968 "Global BGP GR Mode Invalid\n");
14969 break;
14970 }
14971 vty_out(vty, "\n");
14972 }
14973
14974 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14975 enum show_type type,
14976 const char *ip_str,
14977 afi_t afi, bool use_json)
14978 {
14979 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14980 afi = AFI_IP;
14981
14982 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14983
14984 bgp_show_neighbor_graceful_restart_vty(
14985 vty, type, ip_str, afi, use_json);
14986 afi++;
14987 }
14988 } else if (afi != AFI_MAX) {
14989 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14990 use_json);
14991 } else {
14992 return CMD_ERR_INCOMPLETE;
14993 }
14994
14995 return CMD_SUCCESS;
14996 }
14997 /* Graceful Restart */
14998
14999 DEFUN (show_ip_bgp_attr_info,
15000 show_ip_bgp_attr_info_cmd,
15001 "show [ip] bgp attribute-info",
15002 SHOW_STR
15003 IP_STR
15004 BGP_STR
15005 "List all bgp attribute information\n")
15006 {
15007 attr_show_all(vty);
15008 return CMD_SUCCESS;
15009 }
15010
15011 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15012 afi_t afi, safi_t safi,
15013 bool use_json, json_object *json)
15014 {
15015 struct bgp *bgp;
15016 struct listnode *node;
15017 char *vname;
15018 char *ecom_str;
15019 enum vpn_policy_direction dir;
15020
15021 if (json) {
15022 json_object *json_import_vrfs = NULL;
15023 json_object *json_export_vrfs = NULL;
15024
15025 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15026
15027 if (!bgp) {
15028 vty_json(vty, json);
15029
15030 return CMD_WARNING;
15031 }
15032
15033 /* Provide context for the block */
15034 json_object_string_add(json, "vrf", name ? name : "default");
15035 json_object_string_add(json, "afiSafi",
15036 get_afi_safi_str(afi, safi, true));
15037
15038 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15039 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15040 json_object_string_add(json, "importFromVrfs", "none");
15041 json_object_string_add(json, "importRts", "none");
15042 } else {
15043 json_import_vrfs = json_object_new_array();
15044
15045 for (ALL_LIST_ELEMENTS_RO(
15046 bgp->vpn_policy[afi].import_vrf,
15047 node, vname))
15048 json_object_array_add(json_import_vrfs,
15049 json_object_new_string(vname));
15050
15051 json_object_object_add(json, "importFromVrfs",
15052 json_import_vrfs);
15053 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15054 if (bgp->vpn_policy[afi].rtlist[dir]) {
15055 ecom_str = ecommunity_ecom2str(
15056 bgp->vpn_policy[afi].rtlist[dir],
15057 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15058 json_object_string_add(json, "importRts",
15059 ecom_str);
15060 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15061 } else
15062 json_object_string_add(json, "importRts",
15063 "none");
15064 }
15065
15066 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15067 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15068 json_object_string_add(json, "exportToVrfs", "none");
15069 json_object_string_add(json, "routeDistinguisher",
15070 "none");
15071 json_object_string_add(json, "exportRts", "none");
15072 } else {
15073 json_export_vrfs = json_object_new_array();
15074
15075 for (ALL_LIST_ELEMENTS_RO(
15076 bgp->vpn_policy[afi].export_vrf,
15077 node, vname))
15078 json_object_array_add(json_export_vrfs,
15079 json_object_new_string(vname));
15080 json_object_object_add(json, "exportToVrfs",
15081 json_export_vrfs);
15082 json_object_string_addf(json, "routeDistinguisher",
15083 "%pRD",
15084 &bgp->vpn_policy[afi].tovpn_rd);
15085
15086 dir = BGP_VPN_POLICY_DIR_TOVPN;
15087 if (bgp->vpn_policy[afi].rtlist[dir]) {
15088 ecom_str = ecommunity_ecom2str(
15089 bgp->vpn_policy[afi].rtlist[dir],
15090 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15091 json_object_string_add(json, "exportRts",
15092 ecom_str);
15093 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15094 } else
15095 json_object_string_add(json, "exportRts",
15096 "none");
15097 }
15098
15099 if (use_json) {
15100 vty_json(vty, json);
15101 }
15102 } else {
15103 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15104
15105 if (!bgp) {
15106 vty_out(vty, "%% No such BGP instance exist\n");
15107 return CMD_WARNING;
15108 }
15109
15110 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15111 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15112 vty_out(vty,
15113 "This VRF is not importing %s routes from any other VRF\n",
15114 get_afi_safi_str(afi, safi, false));
15115 else {
15116 vty_out(vty,
15117 "This VRF is importing %s routes from the following VRFs:\n",
15118 get_afi_safi_str(afi, safi, false));
15119
15120 for (ALL_LIST_ELEMENTS_RO(
15121 bgp->vpn_policy[afi].import_vrf,
15122 node, vname))
15123 vty_out(vty, " %s\n", vname);
15124
15125 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15126 ecom_str = NULL;
15127 if (bgp->vpn_policy[afi].rtlist[dir]) {
15128 ecom_str = ecommunity_ecom2str(
15129 bgp->vpn_policy[afi].rtlist[dir],
15130 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15131 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15132
15133 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15134 } else
15135 vty_out(vty, "Import RT(s):\n");
15136 }
15137
15138 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15139 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15140 vty_out(vty,
15141 "This VRF is not exporting %s routes to any other VRF\n",
15142 get_afi_safi_str(afi, safi, false));
15143 else {
15144 vty_out(vty,
15145 "This VRF is exporting %s routes to the following VRFs:\n",
15146 get_afi_safi_str(afi, safi, false));
15147
15148 for (ALL_LIST_ELEMENTS_RO(
15149 bgp->vpn_policy[afi].export_vrf,
15150 node, vname))
15151 vty_out(vty, " %s\n", vname);
15152
15153 vty_out(vty, "RD: %pRD\n",
15154 &bgp->vpn_policy[afi].tovpn_rd);
15155
15156 dir = BGP_VPN_POLICY_DIR_TOVPN;
15157 if (bgp->vpn_policy[afi].rtlist[dir]) {
15158 ecom_str = ecommunity_ecom2str(
15159 bgp->vpn_policy[afi].rtlist[dir],
15160 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15161 vty_out(vty, "Export RT: %s\n", ecom_str);
15162 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15163 } else
15164 vty_out(vty, "Import RT(s):\n");
15165 }
15166 }
15167
15168 return CMD_SUCCESS;
15169 }
15170
15171 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15172 safi_t safi, bool use_json)
15173 {
15174 struct listnode *node, *nnode;
15175 struct bgp *bgp;
15176 char *vrf_name = NULL;
15177 json_object *json = NULL;
15178 json_object *json_vrf = NULL;
15179 json_object *json_vrfs = NULL;
15180
15181 if (use_json) {
15182 json = json_object_new_object();
15183 json_vrfs = json_object_new_object();
15184 }
15185
15186 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15187
15188 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15189 vrf_name = bgp->name;
15190
15191 if (use_json) {
15192 json_vrf = json_object_new_object();
15193 } else {
15194 vty_out(vty, "\nInstance %s:\n",
15195 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15196 ? VRF_DEFAULT_NAME : bgp->name);
15197 }
15198 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15199 if (use_json) {
15200 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15201 json_object_object_add(json_vrfs,
15202 VRF_DEFAULT_NAME, json_vrf);
15203 else
15204 json_object_object_add(json_vrfs, vrf_name,
15205 json_vrf);
15206 }
15207 }
15208
15209 if (use_json) {
15210 json_object_object_add(json, "vrfs", json_vrfs);
15211 vty_json(vty, json);
15212 }
15213
15214 return CMD_SUCCESS;
15215 }
15216
15217 /* "show [ip] bgp route-leak" command. */
15218 DEFUN (show_ip_bgp_route_leak,
15219 show_ip_bgp_route_leak_cmd,
15220 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15221 SHOW_STR
15222 IP_STR
15223 BGP_STR
15224 BGP_INSTANCE_HELP_STR
15225 BGP_AFI_HELP_STR
15226 BGP_SAFI_HELP_STR
15227 "Route leaking information\n"
15228 JSON_STR)
15229 {
15230 char *vrf = NULL;
15231 afi_t afi = AFI_MAX;
15232 safi_t safi = SAFI_MAX;
15233
15234 bool uj = use_json(argc, argv);
15235 int idx = 0;
15236 json_object *json = NULL;
15237
15238 /* show [ip] bgp */
15239 if (argv_find(argv, argc, "ip", &idx)) {
15240 afi = AFI_IP;
15241 safi = SAFI_UNICAST;
15242 }
15243 /* [vrf VIEWVRFNAME] */
15244 if (argv_find(argv, argc, "view", &idx)) {
15245 vty_out(vty,
15246 "%% This command is not applicable to BGP views\n");
15247 return CMD_WARNING;
15248 }
15249
15250 if (argv_find(argv, argc, "vrf", &idx)) {
15251 vrf = argv[idx + 1]->arg;
15252 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15253 vrf = NULL;
15254 }
15255 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15256 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15257 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15258
15259 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15260 vty_out(vty,
15261 "%% This command is applicable only for unicast ipv4|ipv6\n");
15262 return CMD_WARNING;
15263 }
15264
15265 if (vrf && strmatch(vrf, "all"))
15266 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15267
15268 if (uj)
15269 json = json_object_new_object();
15270
15271 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15272 }
15273
15274 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15275 safi_t safi)
15276 {
15277 struct listnode *node, *nnode;
15278 struct bgp *bgp;
15279
15280 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15281 vty_out(vty, "\nInstance %s:\n",
15282 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15283 ? VRF_DEFAULT_NAME
15284 : bgp->name);
15285 update_group_show(bgp, afi, safi, vty, 0);
15286 }
15287 }
15288
15289 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15290 int safi, uint64_t subgrp_id)
15291 {
15292 struct bgp *bgp;
15293
15294 if (name) {
15295 if (strmatch(name, "all")) {
15296 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15297 return CMD_SUCCESS;
15298 } else {
15299 bgp = bgp_lookup_by_name(name);
15300 }
15301 } else {
15302 bgp = bgp_get_default();
15303 }
15304
15305 if (bgp)
15306 update_group_show(bgp, afi, safi, vty, subgrp_id);
15307 return CMD_SUCCESS;
15308 }
15309
15310 DEFUN (show_ip_bgp_updgrps,
15311 show_ip_bgp_updgrps_cmd,
15312 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15313 SHOW_STR
15314 IP_STR
15315 BGP_STR
15316 BGP_INSTANCE_HELP_STR
15317 BGP_AFI_HELP_STR
15318 BGP_SAFI_WITH_LABEL_HELP_STR
15319 "Detailed info about dynamic update groups\n"
15320 "Specific subgroup to display detailed info for\n")
15321 {
15322 char *vrf = NULL;
15323 afi_t afi = AFI_IP6;
15324 safi_t safi = SAFI_UNICAST;
15325 uint64_t subgrp_id = 0;
15326
15327 int idx = 0;
15328
15329 /* show [ip] bgp */
15330 if (argv_find(argv, argc, "ip", &idx))
15331 afi = AFI_IP;
15332 /* [<vrf> VIEWVRFNAME] */
15333 if (argv_find(argv, argc, "vrf", &idx)) {
15334 vrf = argv[idx + 1]->arg;
15335 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15336 vrf = NULL;
15337 } else if (argv_find(argv, argc, "view", &idx))
15338 /* [<view> VIEWVRFNAME] */
15339 vrf = argv[idx + 1]->arg;
15340 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15341 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15342 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15343 }
15344
15345 /* get subgroup id, if provided */
15346 idx = argc - 1;
15347 if (argv[idx]->type == VARIABLE_TKN)
15348 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15349
15350 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15351 }
15352
15353 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15354 show_bgp_instance_all_ipv6_updgrps_cmd,
15355 "show [ip] bgp <view|vrf> all update-groups",
15356 SHOW_STR
15357 IP_STR
15358 BGP_STR
15359 BGP_INSTANCE_ALL_HELP_STR
15360 "Detailed info about dynamic update groups\n")
15361 {
15362 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15363 return CMD_SUCCESS;
15364 }
15365
15366 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15367 show_bgp_l2vpn_evpn_updgrps_cmd,
15368 "show [ip] bgp l2vpn evpn update-groups",
15369 SHOW_STR
15370 IP_STR
15371 BGP_STR
15372 "l2vpn address family\n"
15373 "evpn sub-address family\n"
15374 "Detailed info about dynamic update groups\n")
15375 {
15376 char *vrf = NULL;
15377 uint64_t subgrp_id = 0;
15378
15379 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15380 return CMD_SUCCESS;
15381 }
15382
15383 DEFUN (show_bgp_updgrps_stats,
15384 show_bgp_updgrps_stats_cmd,
15385 "show [ip] bgp update-groups statistics",
15386 SHOW_STR
15387 IP_STR
15388 BGP_STR
15389 "Detailed info about dynamic update groups\n"
15390 "Statistics\n")
15391 {
15392 struct bgp *bgp;
15393
15394 bgp = bgp_get_default();
15395 if (bgp)
15396 update_group_show_stats(bgp, vty);
15397
15398 return CMD_SUCCESS;
15399 }
15400
15401 DEFUN (show_bgp_instance_updgrps_stats,
15402 show_bgp_instance_updgrps_stats_cmd,
15403 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15404 SHOW_STR
15405 IP_STR
15406 BGP_STR
15407 BGP_INSTANCE_HELP_STR
15408 "Detailed info about dynamic update groups\n"
15409 "Statistics\n")
15410 {
15411 int idx_word = 3;
15412 struct bgp *bgp;
15413
15414 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15415 if (bgp)
15416 update_group_show_stats(bgp, vty);
15417
15418 return CMD_SUCCESS;
15419 }
15420
15421 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15422 afi_t afi, safi_t safi,
15423 const char *what, uint64_t subgrp_id)
15424 {
15425 struct bgp *bgp;
15426
15427 if (name)
15428 bgp = bgp_lookup_by_name(name);
15429 else
15430 bgp = bgp_get_default();
15431
15432 if (bgp) {
15433 if (!strcmp(what, "advertise-queue"))
15434 update_group_show_adj_queue(bgp, afi, safi, vty,
15435 subgrp_id);
15436 else if (!strcmp(what, "advertised-routes"))
15437 update_group_show_advertised(bgp, afi, safi, vty,
15438 subgrp_id);
15439 else if (!strcmp(what, "packet-queue"))
15440 update_group_show_packet_queue(bgp, afi, safi, vty,
15441 subgrp_id);
15442 }
15443 }
15444
15445 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15446 show_ip_bgp_instance_updgrps_adj_s_cmd,
15447 "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",
15448 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15449 BGP_SAFI_HELP_STR
15450 "Detailed info about dynamic update groups\n"
15451 "Specific subgroup to display info for\n"
15452 "Advertisement queue\n"
15453 "Announced routes\n"
15454 "Packet queue\n")
15455 {
15456 uint64_t subgrp_id = 0;
15457 afi_t afiz;
15458 safi_t safiz;
15459 if (sgid)
15460 subgrp_id = strtoull(sgid, NULL, 10);
15461
15462 if (!ip && !afi)
15463 afiz = AFI_IP6;
15464 if (!ip && afi)
15465 afiz = bgp_vty_afi_from_str(afi);
15466 if (ip && !afi)
15467 afiz = AFI_IP;
15468 if (ip && afi) {
15469 afiz = bgp_vty_afi_from_str(afi);
15470 if (afiz != AFI_IP)
15471 vty_out(vty,
15472 "%% Cannot specify both 'ip' and 'ipv6'\n");
15473 return CMD_WARNING;
15474 }
15475
15476 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15477
15478 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15479 return CMD_SUCCESS;
15480 }
15481
15482 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15483 json_object *json)
15484 {
15485 struct listnode *node, *nnode;
15486 struct prefix *range;
15487 struct peer *conf;
15488 struct peer *peer;
15489 afi_t afi;
15490 safi_t safi;
15491 const char *peer_status;
15492 int lr_count;
15493 int dynamic;
15494 bool af_cfgd;
15495 json_object *json_peer_group = NULL;
15496 json_object *json_peer_group_afc = NULL;
15497 json_object *json_peer_group_members = NULL;
15498 json_object *json_peer_group_dynamic = NULL;
15499 json_object *json_peer_group_dynamic_af = NULL;
15500 json_object *json_peer_group_ranges = NULL;
15501
15502 conf = group->conf;
15503
15504 if (json) {
15505 json_peer_group = json_object_new_object();
15506 json_peer_group_afc = json_object_new_array();
15507 }
15508
15509 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15510 if (json)
15511 json_object_int_add(json_peer_group, "remoteAs",
15512 conf->as);
15513 else
15514 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15515 group->name, conf->as);
15516 } else if (conf->as_type == AS_INTERNAL) {
15517 if (json)
15518 json_object_int_add(json_peer_group, "remoteAs",
15519 group->bgp->as);
15520 else
15521 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15522 group->name, group->bgp->as);
15523 } else {
15524 if (!json)
15525 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15526 }
15527
15528 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15529 if (json)
15530 json_object_string_add(json_peer_group, "type",
15531 "internal");
15532 else
15533 vty_out(vty, " Peer-group type is internal\n");
15534 } else {
15535 if (json)
15536 json_object_string_add(json_peer_group, "type",
15537 "external");
15538 else
15539 vty_out(vty, " Peer-group type is external\n");
15540 }
15541
15542 /* Display AFs configured. */
15543 if (!json)
15544 vty_out(vty, " Configured address-families:");
15545
15546 FOREACH_AFI_SAFI (afi, safi) {
15547 if (conf->afc[afi][safi]) {
15548 af_cfgd = true;
15549 if (json)
15550 json_object_array_add(
15551 json_peer_group_afc,
15552 json_object_new_string(get_afi_safi_str(
15553 afi, safi, false)));
15554 else
15555 vty_out(vty, " %s;",
15556 get_afi_safi_str(afi, safi, false));
15557 }
15558 }
15559
15560 if (json) {
15561 json_object_object_add(json_peer_group,
15562 "addressFamiliesConfigured",
15563 json_peer_group_afc);
15564 } else {
15565 if (!af_cfgd)
15566 vty_out(vty, " none\n");
15567 else
15568 vty_out(vty, "\n");
15569 }
15570
15571 /* Display listen ranges (for dynamic neighbors), if any */
15572 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15573 lr_count = listcount(group->listen_range[afi]);
15574 if (lr_count) {
15575 if (json) {
15576 if (!json_peer_group_dynamic)
15577 json_peer_group_dynamic =
15578 json_object_new_object();
15579
15580 json_peer_group_dynamic_af =
15581 json_object_new_object();
15582 json_peer_group_ranges =
15583 json_object_new_array();
15584 json_object_int_add(json_peer_group_dynamic_af,
15585 "count", lr_count);
15586 } else {
15587 vty_out(vty, " %d %s listen range(s)\n",
15588 lr_count, afi2str(afi));
15589 }
15590
15591 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15592 nnode, range)) {
15593 if (json) {
15594 char buf[BUFSIZ];
15595
15596 snprintfrr(buf, sizeof(buf), "%pFX",
15597 range);
15598
15599 json_object_array_add(
15600 json_peer_group_ranges,
15601 json_object_new_string(buf));
15602 } else {
15603 vty_out(vty, " %pFX\n", range);
15604 }
15605 }
15606
15607 if (json) {
15608 json_object_object_add(
15609 json_peer_group_dynamic_af, "ranges",
15610 json_peer_group_ranges);
15611
15612 json_object_object_add(
15613 json_peer_group_dynamic, afi2str(afi),
15614 json_peer_group_dynamic_af);
15615 }
15616 }
15617 }
15618
15619 if (json_peer_group_dynamic)
15620 json_object_object_add(json_peer_group, "dynamicRanges",
15621 json_peer_group_dynamic);
15622
15623 /* Display group members and their status */
15624 if (listcount(group->peer)) {
15625 if (json)
15626 json_peer_group_members = json_object_new_object();
15627 else
15628 vty_out(vty, " Peer-group members:\n");
15629 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15630 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15631 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15632 peer_status = "Idle (Admin)";
15633 else if (CHECK_FLAG(peer->sflags,
15634 PEER_STATUS_PREFIX_OVERFLOW))
15635 peer_status = "Idle (PfxCt)";
15636 else
15637 peer_status = lookup_msg(bgp_status_msg,
15638 peer->status, NULL);
15639
15640 dynamic = peer_dynamic_neighbor(peer);
15641
15642 if (json) {
15643 json_object *json_peer_group_member =
15644 json_object_new_object();
15645
15646 json_object_string_add(json_peer_group_member,
15647 "status", peer_status);
15648
15649 if (dynamic)
15650 json_object_boolean_true_add(
15651 json_peer_group_member,
15652 "dynamic");
15653
15654 json_object_object_add(json_peer_group_members,
15655 peer->host,
15656 json_peer_group_member);
15657 } else {
15658 vty_out(vty, " %s %s %s \n", peer->host,
15659 dynamic ? "(dynamic)" : "",
15660 peer_status);
15661 }
15662 }
15663 if (json)
15664 json_object_object_add(json_peer_group, "members",
15665 json_peer_group_members);
15666 }
15667
15668 if (json)
15669 json_object_object_add(json, group->name, json_peer_group);
15670
15671 return CMD_SUCCESS;
15672 }
15673
15674 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15675 const char *group_name, bool uj)
15676 {
15677 struct bgp *bgp;
15678 struct listnode *node, *nnode;
15679 struct peer_group *group;
15680 bool found = false;
15681 json_object *json = NULL;
15682
15683 if (uj)
15684 json = json_object_new_object();
15685
15686 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15687
15688 if (!bgp) {
15689 if (uj)
15690 vty_json(vty, json);
15691 else
15692 vty_out(vty, "%% BGP instance not found\n");
15693
15694 return CMD_WARNING;
15695 }
15696
15697 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15698 if (group_name) {
15699 if (strmatch(group->name, group_name)) {
15700 bgp_show_one_peer_group(vty, group, json);
15701 found = true;
15702 break;
15703 }
15704 } else {
15705 bgp_show_one_peer_group(vty, group, json);
15706 }
15707 }
15708
15709 if (group_name && !found && !uj)
15710 vty_out(vty, "%% No such peer-group\n");
15711
15712 if (uj)
15713 vty_json(vty, json);
15714
15715 return CMD_SUCCESS;
15716 }
15717
15718 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15719 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15720 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15721 "Detailed information on BGP peer groups\n"
15722 "Peer group name\n" JSON_STR)
15723 {
15724 char *vrf, *pg;
15725 int idx = 0;
15726 bool uj = use_json(argc, argv);
15727
15728 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15729 : NULL;
15730 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15731
15732 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15733 }
15734
15735
15736 /* Redistribute VTY commands. */
15737
15738 DEFUN (bgp_redistribute_ipv4,
15739 bgp_redistribute_ipv4_cmd,
15740 "redistribute " FRR_IP_REDIST_STR_BGPD,
15741 "Redistribute information from another routing protocol\n"
15742 FRR_IP_REDIST_HELP_STR_BGPD)
15743 {
15744 VTY_DECLVAR_CONTEXT(bgp, bgp);
15745 int idx_protocol = 1;
15746 int type;
15747
15748 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15749 if (type < 0) {
15750 vty_out(vty, "%% Invalid route type\n");
15751 return CMD_WARNING_CONFIG_FAILED;
15752 }
15753
15754 bgp_redist_add(bgp, AFI_IP, type, 0);
15755 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15756 }
15757
15758 ALIAS_HIDDEN(
15759 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15760 "redistribute " FRR_IP_REDIST_STR_BGPD,
15761 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15762
15763 DEFUN (bgp_redistribute_ipv4_rmap,
15764 bgp_redistribute_ipv4_rmap_cmd,
15765 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15766 "Redistribute information from another routing protocol\n"
15767 FRR_IP_REDIST_HELP_STR_BGPD
15768 "Route map reference\n"
15769 "Pointer to route-map entries\n")
15770 {
15771 VTY_DECLVAR_CONTEXT(bgp, bgp);
15772 int idx_protocol = 1;
15773 int idx_word = 3;
15774 int type;
15775 struct bgp_redist *red;
15776 bool changed;
15777 struct route_map *route_map = route_map_lookup_warn_noexist(
15778 vty, argv[idx_word]->arg);
15779
15780 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15781 if (type < 0) {
15782 vty_out(vty, "%% Invalid route type\n");
15783 return CMD_WARNING_CONFIG_FAILED;
15784 }
15785
15786 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15787 changed =
15788 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15789 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15790 }
15791
15792 ALIAS_HIDDEN(
15793 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15794 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15795 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15796 "Route map reference\n"
15797 "Pointer to route-map entries\n")
15798
15799 DEFUN (bgp_redistribute_ipv4_metric,
15800 bgp_redistribute_ipv4_metric_cmd,
15801 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15802 "Redistribute information from another routing protocol\n"
15803 FRR_IP_REDIST_HELP_STR_BGPD
15804 "Metric for redistributed routes\n"
15805 "Default metric\n")
15806 {
15807 VTY_DECLVAR_CONTEXT(bgp, bgp);
15808 int idx_protocol = 1;
15809 int idx_number = 3;
15810 int type;
15811 uint32_t metric;
15812 struct bgp_redist *red;
15813 bool changed;
15814
15815 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15816 if (type < 0) {
15817 vty_out(vty, "%% Invalid route type\n");
15818 return CMD_WARNING_CONFIG_FAILED;
15819 }
15820 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15821
15822 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15823 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15824 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15825 }
15826
15827 ALIAS_HIDDEN(
15828 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15829 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15830 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15831 "Metric for redistributed routes\n"
15832 "Default metric\n")
15833
15834 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15835 bgp_redistribute_ipv4_rmap_metric_cmd,
15836 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15837 "Redistribute information from another routing protocol\n"
15838 FRR_IP_REDIST_HELP_STR_BGPD
15839 "Route map reference\n"
15840 "Pointer to route-map entries\n"
15841 "Metric for redistributed routes\n"
15842 "Default metric\n")
15843 {
15844 VTY_DECLVAR_CONTEXT(bgp, bgp);
15845 int idx_protocol = 1;
15846 int idx_word = 3;
15847 int idx_number = 5;
15848 int type;
15849 uint32_t metric;
15850 struct bgp_redist *red;
15851 bool changed;
15852 struct route_map *route_map =
15853 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15854
15855 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15856 if (type < 0) {
15857 vty_out(vty, "%% Invalid route type\n");
15858 return CMD_WARNING_CONFIG_FAILED;
15859 }
15860 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15861
15862 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15863 changed =
15864 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15865 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15866 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15867 }
15868
15869 ALIAS_HIDDEN(
15870 bgp_redistribute_ipv4_rmap_metric,
15871 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15872 "redistribute " FRR_IP_REDIST_STR_BGPD
15873 " route-map RMAP_NAME metric (0-4294967295)",
15874 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15875 "Route map reference\n"
15876 "Pointer to route-map entries\n"
15877 "Metric for redistributed routes\n"
15878 "Default metric\n")
15879
15880 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15881 bgp_redistribute_ipv4_metric_rmap_cmd,
15882 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15883 "Redistribute information from another routing protocol\n"
15884 FRR_IP_REDIST_HELP_STR_BGPD
15885 "Metric for redistributed routes\n"
15886 "Default metric\n"
15887 "Route map reference\n"
15888 "Pointer to route-map entries\n")
15889 {
15890 VTY_DECLVAR_CONTEXT(bgp, bgp);
15891 int idx_protocol = 1;
15892 int idx_number = 3;
15893 int idx_word = 5;
15894 int type;
15895 uint32_t metric;
15896 struct bgp_redist *red;
15897 bool changed;
15898 struct route_map *route_map =
15899 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15900
15901 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15902 if (type < 0) {
15903 vty_out(vty, "%% Invalid route type\n");
15904 return CMD_WARNING_CONFIG_FAILED;
15905 }
15906 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15907
15908 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15909 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15910 changed |=
15911 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15912 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15913 }
15914
15915 ALIAS_HIDDEN(
15916 bgp_redistribute_ipv4_metric_rmap,
15917 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15918 "redistribute " FRR_IP_REDIST_STR_BGPD
15919 " metric (0-4294967295) route-map RMAP_NAME",
15920 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15921 "Metric for redistributed routes\n"
15922 "Default metric\n"
15923 "Route map reference\n"
15924 "Pointer to route-map entries\n")
15925
15926 DEFUN (bgp_redistribute_ipv4_ospf,
15927 bgp_redistribute_ipv4_ospf_cmd,
15928 "redistribute <ospf|table> (1-65535)",
15929 "Redistribute information from another routing protocol\n"
15930 "Open Shortest Path First (OSPFv2)\n"
15931 "Non-main Kernel Routing Table\n"
15932 "Instance ID/Table ID\n")
15933 {
15934 VTY_DECLVAR_CONTEXT(bgp, bgp);
15935 int idx_ospf_table = 1;
15936 int idx_number = 2;
15937 unsigned short instance;
15938 unsigned short protocol;
15939
15940 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15941
15942 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15943 protocol = ZEBRA_ROUTE_OSPF;
15944 else
15945 protocol = ZEBRA_ROUTE_TABLE;
15946
15947 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15948 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15949 }
15950
15951 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15952 "redistribute <ospf|table> (1-65535)",
15953 "Redistribute information from another routing protocol\n"
15954 "Open Shortest Path First (OSPFv2)\n"
15955 "Non-main Kernel Routing Table\n"
15956 "Instance ID/Table ID\n")
15957
15958 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15959 bgp_redistribute_ipv4_ospf_rmap_cmd,
15960 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15961 "Redistribute information from another routing protocol\n"
15962 "Open Shortest Path First (OSPFv2)\n"
15963 "Non-main Kernel Routing Table\n"
15964 "Instance ID/Table ID\n"
15965 "Route map reference\n"
15966 "Pointer to route-map entries\n")
15967 {
15968 VTY_DECLVAR_CONTEXT(bgp, bgp);
15969 int idx_ospf_table = 1;
15970 int idx_number = 2;
15971 int idx_word = 4;
15972 struct bgp_redist *red;
15973 unsigned short instance;
15974 int protocol;
15975 bool changed;
15976 struct route_map *route_map =
15977 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15978
15979 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15980 protocol = ZEBRA_ROUTE_OSPF;
15981 else
15982 protocol = ZEBRA_ROUTE_TABLE;
15983
15984 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15985 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15986 changed =
15987 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15988 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15989 }
15990
15991 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15992 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15993 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15994 "Redistribute information from another routing protocol\n"
15995 "Open Shortest Path First (OSPFv2)\n"
15996 "Non-main Kernel Routing Table\n"
15997 "Instance ID/Table ID\n"
15998 "Route map reference\n"
15999 "Pointer to route-map entries\n")
16000
16001 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16002 bgp_redistribute_ipv4_ospf_metric_cmd,
16003 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16004 "Redistribute information from another routing protocol\n"
16005 "Open Shortest Path First (OSPFv2)\n"
16006 "Non-main Kernel Routing Table\n"
16007 "Instance ID/Table ID\n"
16008 "Metric for redistributed routes\n"
16009 "Default metric\n")
16010 {
16011 VTY_DECLVAR_CONTEXT(bgp, bgp);
16012 int idx_ospf_table = 1;
16013 int idx_number = 2;
16014 int idx_number_2 = 4;
16015 uint32_t metric;
16016 struct bgp_redist *red;
16017 unsigned short instance;
16018 int protocol;
16019 bool changed;
16020
16021 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16022 protocol = ZEBRA_ROUTE_OSPF;
16023 else
16024 protocol = ZEBRA_ROUTE_TABLE;
16025
16026 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16027 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16028
16029 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16030 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16031 metric);
16032 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16033 }
16034
16035 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16036 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16037 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16038 "Redistribute information from another routing protocol\n"
16039 "Open Shortest Path First (OSPFv2)\n"
16040 "Non-main Kernel Routing Table\n"
16041 "Instance ID/Table ID\n"
16042 "Metric for redistributed routes\n"
16043 "Default metric\n")
16044
16045 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16046 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16047 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16048 "Redistribute information from another routing protocol\n"
16049 "Open Shortest Path First (OSPFv2)\n"
16050 "Non-main Kernel Routing Table\n"
16051 "Instance ID/Table ID\n"
16052 "Route map reference\n"
16053 "Pointer to route-map entries\n"
16054 "Metric for redistributed routes\n"
16055 "Default metric\n")
16056 {
16057 VTY_DECLVAR_CONTEXT(bgp, bgp);
16058 int idx_ospf_table = 1;
16059 int idx_number = 2;
16060 int idx_word = 4;
16061 int idx_number_2 = 6;
16062 uint32_t metric;
16063 struct bgp_redist *red;
16064 unsigned short instance;
16065 int protocol;
16066 bool changed;
16067 struct route_map *route_map =
16068 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16069
16070 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16071 protocol = ZEBRA_ROUTE_OSPF;
16072 else
16073 protocol = ZEBRA_ROUTE_TABLE;
16074
16075 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16076 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16077
16078 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16079 changed =
16080 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16081 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16082 metric);
16083 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16084 }
16085
16086 ALIAS_HIDDEN(
16087 bgp_redistribute_ipv4_ospf_rmap_metric,
16088 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16089 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16090 "Redistribute information from another routing protocol\n"
16091 "Open Shortest Path First (OSPFv2)\n"
16092 "Non-main Kernel Routing Table\n"
16093 "Instance ID/Table ID\n"
16094 "Route map reference\n"
16095 "Pointer to route-map entries\n"
16096 "Metric for redistributed routes\n"
16097 "Default metric\n")
16098
16099 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16100 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16101 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16102 "Redistribute information from another routing protocol\n"
16103 "Open Shortest Path First (OSPFv2)\n"
16104 "Non-main Kernel Routing Table\n"
16105 "Instance ID/Table ID\n"
16106 "Metric for redistributed routes\n"
16107 "Default metric\n"
16108 "Route map reference\n"
16109 "Pointer to route-map entries\n")
16110 {
16111 VTY_DECLVAR_CONTEXT(bgp, bgp);
16112 int idx_ospf_table = 1;
16113 int idx_number = 2;
16114 int idx_number_2 = 4;
16115 int idx_word = 6;
16116 uint32_t metric;
16117 struct bgp_redist *red;
16118 unsigned short instance;
16119 int protocol;
16120 bool changed;
16121 struct route_map *route_map =
16122 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16123
16124 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16125 protocol = ZEBRA_ROUTE_OSPF;
16126 else
16127 protocol = ZEBRA_ROUTE_TABLE;
16128
16129 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16130 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16131
16132 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16133 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16134 metric);
16135 changed |=
16136 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16137 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16138 }
16139
16140 ALIAS_HIDDEN(
16141 bgp_redistribute_ipv4_ospf_metric_rmap,
16142 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16143 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16144 "Redistribute information from another routing protocol\n"
16145 "Open Shortest Path First (OSPFv2)\n"
16146 "Non-main Kernel Routing Table\n"
16147 "Instance ID/Table ID\n"
16148 "Metric for redistributed routes\n"
16149 "Default metric\n"
16150 "Route map reference\n"
16151 "Pointer to route-map entries\n")
16152
16153 DEFUN (no_bgp_redistribute_ipv4_ospf,
16154 no_bgp_redistribute_ipv4_ospf_cmd,
16155 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16156 NO_STR
16157 "Redistribute information from another routing protocol\n"
16158 "Open Shortest Path First (OSPFv2)\n"
16159 "Non-main Kernel Routing Table\n"
16160 "Instance ID/Table ID\n"
16161 "Metric for redistributed routes\n"
16162 "Default metric\n"
16163 "Route map reference\n"
16164 "Pointer to route-map entries\n")
16165 {
16166 VTY_DECLVAR_CONTEXT(bgp, bgp);
16167 int idx_ospf_table = 2;
16168 int idx_number = 3;
16169 unsigned short instance;
16170 int protocol;
16171
16172 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16173 protocol = ZEBRA_ROUTE_OSPF;
16174 else
16175 protocol = ZEBRA_ROUTE_TABLE;
16176
16177 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16178 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16179 }
16180
16181 ALIAS_HIDDEN(
16182 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16183 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16184 NO_STR
16185 "Redistribute information from another routing protocol\n"
16186 "Open Shortest Path First (OSPFv2)\n"
16187 "Non-main Kernel Routing Table\n"
16188 "Instance ID/Table ID\n"
16189 "Metric for redistributed routes\n"
16190 "Default metric\n"
16191 "Route map reference\n"
16192 "Pointer to route-map entries\n")
16193
16194 DEFUN (no_bgp_redistribute_ipv4,
16195 no_bgp_redistribute_ipv4_cmd,
16196 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16197 NO_STR
16198 "Redistribute information from another routing protocol\n"
16199 FRR_IP_REDIST_HELP_STR_BGPD
16200 "Metric for redistributed routes\n"
16201 "Default metric\n"
16202 "Route map reference\n"
16203 "Pointer to route-map entries\n")
16204 {
16205 VTY_DECLVAR_CONTEXT(bgp, bgp);
16206 int idx_protocol = 2;
16207 int type;
16208
16209 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16210 if (type < 0) {
16211 vty_out(vty, "%% Invalid route type\n");
16212 return CMD_WARNING_CONFIG_FAILED;
16213 }
16214 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16215 }
16216
16217 ALIAS_HIDDEN(
16218 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16219 "no redistribute " FRR_IP_REDIST_STR_BGPD
16220 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16221 NO_STR
16222 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16223 "Metric for redistributed routes\n"
16224 "Default metric\n"
16225 "Route map reference\n"
16226 "Pointer to route-map entries\n")
16227
16228 DEFUN (bgp_redistribute_ipv6,
16229 bgp_redistribute_ipv6_cmd,
16230 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16231 "Redistribute information from another routing protocol\n"
16232 FRR_IP6_REDIST_HELP_STR_BGPD)
16233 {
16234 VTY_DECLVAR_CONTEXT(bgp, bgp);
16235 int idx_protocol = 1;
16236 int type;
16237
16238 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16239 if (type < 0) {
16240 vty_out(vty, "%% Invalid route type\n");
16241 return CMD_WARNING_CONFIG_FAILED;
16242 }
16243
16244 bgp_redist_add(bgp, AFI_IP6, type, 0);
16245 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16246 }
16247
16248 DEFUN (bgp_redistribute_ipv6_rmap,
16249 bgp_redistribute_ipv6_rmap_cmd,
16250 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16251 "Redistribute information from another routing protocol\n"
16252 FRR_IP6_REDIST_HELP_STR_BGPD
16253 "Route map reference\n"
16254 "Pointer to route-map entries\n")
16255 {
16256 VTY_DECLVAR_CONTEXT(bgp, bgp);
16257 int idx_protocol = 1;
16258 int idx_word = 3;
16259 int type;
16260 struct bgp_redist *red;
16261 bool changed;
16262 struct route_map *route_map =
16263 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16264
16265 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16266 if (type < 0) {
16267 vty_out(vty, "%% Invalid route type\n");
16268 return CMD_WARNING_CONFIG_FAILED;
16269 }
16270
16271 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16272 changed =
16273 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16274 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16275 }
16276
16277 DEFUN (bgp_redistribute_ipv6_metric,
16278 bgp_redistribute_ipv6_metric_cmd,
16279 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16280 "Redistribute information from another routing protocol\n"
16281 FRR_IP6_REDIST_HELP_STR_BGPD
16282 "Metric for redistributed routes\n"
16283 "Default metric\n")
16284 {
16285 VTY_DECLVAR_CONTEXT(bgp, bgp);
16286 int idx_protocol = 1;
16287 int idx_number = 3;
16288 int type;
16289 uint32_t metric;
16290 struct bgp_redist *red;
16291 bool changed;
16292
16293 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16294 if (type < 0) {
16295 vty_out(vty, "%% Invalid route type\n");
16296 return CMD_WARNING_CONFIG_FAILED;
16297 }
16298 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16299
16300 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16301 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16302 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16303 }
16304
16305 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16306 bgp_redistribute_ipv6_rmap_metric_cmd,
16307 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16308 "Redistribute information from another routing protocol\n"
16309 FRR_IP6_REDIST_HELP_STR_BGPD
16310 "Route map reference\n"
16311 "Pointer to route-map entries\n"
16312 "Metric for redistributed routes\n"
16313 "Default metric\n")
16314 {
16315 VTY_DECLVAR_CONTEXT(bgp, bgp);
16316 int idx_protocol = 1;
16317 int idx_word = 3;
16318 int idx_number = 5;
16319 int type;
16320 uint32_t metric;
16321 struct bgp_redist *red;
16322 bool changed;
16323 struct route_map *route_map =
16324 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16325
16326 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16327 if (type < 0) {
16328 vty_out(vty, "%% Invalid route type\n");
16329 return CMD_WARNING_CONFIG_FAILED;
16330 }
16331 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16332
16333 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16334 changed =
16335 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16336 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16337 metric);
16338 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16339 }
16340
16341 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16342 bgp_redistribute_ipv6_metric_rmap_cmd,
16343 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16344 "Redistribute information from another routing protocol\n"
16345 FRR_IP6_REDIST_HELP_STR_BGPD
16346 "Metric for redistributed routes\n"
16347 "Default metric\n"
16348 "Route map reference\n"
16349 "Pointer to route-map entries\n")
16350 {
16351 VTY_DECLVAR_CONTEXT(bgp, bgp);
16352 int idx_protocol = 1;
16353 int idx_number = 3;
16354 int idx_word = 5;
16355 int type;
16356 uint32_t metric;
16357 struct bgp_redist *red;
16358 bool changed;
16359 struct route_map *route_map =
16360 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16361
16362 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16363 if (type < 0) {
16364 vty_out(vty, "%% Invalid route type\n");
16365 return CMD_WARNING_CONFIG_FAILED;
16366 }
16367 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16368
16369 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16370 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16371 metric);
16372 changed |=
16373 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16374 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16375 }
16376
16377 DEFUN (no_bgp_redistribute_ipv6,
16378 no_bgp_redistribute_ipv6_cmd,
16379 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16380 NO_STR
16381 "Redistribute information from another routing protocol\n"
16382 FRR_IP6_REDIST_HELP_STR_BGPD
16383 "Metric for redistributed routes\n"
16384 "Default metric\n"
16385 "Route map reference\n"
16386 "Pointer to route-map entries\n")
16387 {
16388 VTY_DECLVAR_CONTEXT(bgp, bgp);
16389 int idx_protocol = 2;
16390 int type;
16391
16392 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16393 if (type < 0) {
16394 vty_out(vty, "%% Invalid route type\n");
16395 return CMD_WARNING_CONFIG_FAILED;
16396 }
16397
16398 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16399 }
16400
16401 /* Neighbor update tcp-mss. */
16402 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16403 const char *tcp_mss_str)
16404 {
16405 struct peer *peer;
16406 uint32_t tcp_mss_val = 0;
16407
16408 peer = peer_and_group_lookup_vty(vty, peer_str);
16409 if (!peer)
16410 return CMD_WARNING_CONFIG_FAILED;
16411
16412 if (tcp_mss_str) {
16413 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16414 peer_tcp_mss_set(peer, tcp_mss_val);
16415 } else {
16416 peer_tcp_mss_unset(peer);
16417 }
16418
16419 return CMD_SUCCESS;
16420 }
16421
16422 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16423 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16424 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16425 "TCP max segment size\n"
16426 "TCP MSS value\n")
16427 {
16428 int peer_index = 1;
16429 int mss_index = 3;
16430
16431 vty_out(vty,
16432 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16433 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16434 argv[mss_index]->arg);
16435 }
16436
16437 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16438 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16439 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16440 "TCP max segment size\n"
16441 "TCP MSS value\n")
16442 {
16443 int peer_index = 2;
16444
16445 vty_out(vty,
16446 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16447 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16448 }
16449
16450 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16451 "[no$no] bgp retain route-target all",
16452 NO_STR BGP_STR
16453 "Retain BGP updates\n"
16454 "Retain BGP updates based on route-target values\n"
16455 "Retain all BGP updates\n")
16456 {
16457 bool check;
16458 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16459
16460 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16461 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16462 if (check != !no) {
16463 if (!no)
16464 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16465 [bgp_node_safi(vty)],
16466 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16467 else
16468 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16469 [bgp_node_safi(vty)],
16470 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16471 /* trigger a flush to re-sync with ADJ-RIB-in */
16472 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16473 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16474 }
16475 return CMD_SUCCESS;
16476 }
16477
16478 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16479 afi_t afi, safi_t safi)
16480 {
16481 int i;
16482
16483 /* Unicast redistribution only. */
16484 if (safi != SAFI_UNICAST)
16485 return;
16486
16487 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16488 /* Redistribute BGP does not make sense. */
16489 if (i != ZEBRA_ROUTE_BGP) {
16490 struct list *red_list;
16491 struct listnode *node;
16492 struct bgp_redist *red;
16493
16494 red_list = bgp->redist[afi][i];
16495 if (!red_list)
16496 continue;
16497
16498 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16499 /* "redistribute" configuration. */
16500 vty_out(vty, " redistribute %s",
16501 zebra_route_string(i));
16502 if (red->instance)
16503 vty_out(vty, " %d", red->instance);
16504 if (red->redist_metric_flag)
16505 vty_out(vty, " metric %u",
16506 red->redist_metric);
16507 if (red->rmap.name)
16508 vty_out(vty, " route-map %s",
16509 red->rmap.name);
16510 vty_out(vty, "\n");
16511 }
16512 }
16513 }
16514 }
16515
16516 /* peer-group helpers for config-write */
16517
16518 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16519 {
16520 if (!peer_group_active(peer)) {
16521 if (CHECK_FLAG(peer->flags_invert, flag))
16522 return !CHECK_FLAG(peer->flags, flag);
16523 else
16524 return !!CHECK_FLAG(peer->flags, flag);
16525 }
16526
16527 return !!CHECK_FLAG(peer->flags_override, flag);
16528 }
16529
16530 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16531 uint64_t flag)
16532 {
16533 if (!peer_group_active(peer)) {
16534 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16535 return !peer_af_flag_check(peer, afi, safi, flag);
16536 else
16537 return !!peer_af_flag_check(peer, afi, safi, flag);
16538 }
16539
16540 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16541 }
16542
16543 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16544 uint8_t type, int direct)
16545 {
16546 struct bgp_filter *filter;
16547
16548 if (peer_group_active(peer))
16549 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16550 type);
16551
16552 filter = &peer->filter[afi][safi];
16553 switch (type) {
16554 case PEER_FT_DISTRIBUTE_LIST:
16555 return !!(filter->dlist[direct].name);
16556 case PEER_FT_FILTER_LIST:
16557 return !!(filter->aslist[direct].name);
16558 case PEER_FT_PREFIX_LIST:
16559 return !!(filter->plist[direct].name);
16560 case PEER_FT_ROUTE_MAP:
16561 return !!(filter->map[direct].name);
16562 case PEER_FT_UNSUPPRESS_MAP:
16563 return !!(filter->usmap.name);
16564 case PEER_FT_ADVERTISE_MAP:
16565 return !!(filter->advmap.aname
16566 && ((filter->advmap.condition == direct)
16567 && filter->advmap.cname));
16568 default:
16569 return false;
16570 }
16571 }
16572
16573 /* Return true if the addpath type is set for peer and different from
16574 * peer-group.
16575 */
16576 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16577 safi_t safi)
16578 {
16579 enum bgp_addpath_strat type, g_type;
16580
16581 type = peer->addpath_type[afi][safi];
16582
16583 if (type != BGP_ADDPATH_NONE) {
16584 if (peer_group_active(peer)) {
16585 g_type = peer->group->conf->addpath_type[afi][safi];
16586
16587 if (type != g_type)
16588 return true;
16589 else
16590 return false;
16591 }
16592
16593 return true;
16594 }
16595
16596 return false;
16597 }
16598
16599 /* This is part of the address-family block (unicast only) */
16600 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16601 afi_t afi)
16602 {
16603 int indent = 2;
16604 uint32_t tovpn_sid_index = 0;
16605
16606 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16607 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16608 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16609 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16610 bgp->vpn_policy[afi]
16611 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16612 else
16613 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16614 bgp->vpn_policy[afi]
16615 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16616 }
16617 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16618 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16619 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16620 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16621 return;
16622
16623 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16624 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16625
16626 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16627
16628 } else {
16629 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16630 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16631 bgp->vpn_policy[afi].tovpn_label);
16632 }
16633 }
16634
16635 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16636 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16637 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16638 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16639 } else if (tovpn_sid_index != 0) {
16640 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16641 tovpn_sid_index);
16642 }
16643
16644 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16645 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16646 &bgp->vpn_policy[afi].tovpn_rd);
16647
16648 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16649 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16650
16651 char buf[PREFIX_STRLEN];
16652 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16653 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16654 sizeof(buf))) {
16655
16656 vty_out(vty, "%*snexthop vpn export %s\n",
16657 indent, "", buf);
16658 }
16659 }
16660 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16661 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16662 && ecommunity_cmp(
16663 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16664 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16665
16666 char *b = ecommunity_ecom2str(
16667 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16668 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16669 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16670 XFREE(MTYPE_ECOMMUNITY_STR, b);
16671 } else {
16672 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16673 char *b = ecommunity_ecom2str(
16674 bgp->vpn_policy[afi]
16675 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16676 ECOMMUNITY_FORMAT_ROUTE_MAP,
16677 ECOMMUNITY_ROUTE_TARGET);
16678 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16679 XFREE(MTYPE_ECOMMUNITY_STR, b);
16680 }
16681 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16682 char *b = ecommunity_ecom2str(
16683 bgp->vpn_policy[afi]
16684 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16685 ECOMMUNITY_FORMAT_ROUTE_MAP,
16686 ECOMMUNITY_ROUTE_TARGET);
16687 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16688 XFREE(MTYPE_ECOMMUNITY_STR, b);
16689 }
16690 }
16691
16692 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16693 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16694 bgp->vpn_policy[afi]
16695 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16696
16697 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16698 char *b = ecommunity_ecom2str(
16699 bgp->vpn_policy[afi]
16700 .import_redirect_rtlist,
16701 ECOMMUNITY_FORMAT_ROUTE_MAP,
16702 ECOMMUNITY_ROUTE_TARGET);
16703
16704 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16705 != ECOMMUNITY_SIZE)
16706 vty_out(vty, "%*srt6 redirect import %s\n",
16707 indent, "", b);
16708 else
16709 vty_out(vty, "%*srt redirect import %s\n",
16710 indent, "", b);
16711 XFREE(MTYPE_ECOMMUNITY_STR, b);
16712 }
16713 }
16714
16715 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16716 afi_t afi, safi_t safi)
16717 {
16718 struct bgp_filter *filter;
16719 char *addr;
16720
16721 addr = peer->host;
16722 filter = &peer->filter[afi][safi];
16723
16724 /* distribute-list. */
16725 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16726 FILTER_IN))
16727 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16728 filter->dlist[FILTER_IN].name);
16729
16730 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16731 FILTER_OUT))
16732 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16733 filter->dlist[FILTER_OUT].name);
16734
16735 /* prefix-list. */
16736 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16737 FILTER_IN))
16738 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16739 filter->plist[FILTER_IN].name);
16740
16741 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16742 FILTER_OUT))
16743 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16744 filter->plist[FILTER_OUT].name);
16745
16746 /* route-map. */
16747 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16748 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16749 filter->map[RMAP_IN].name);
16750
16751 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16752 RMAP_OUT))
16753 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16754 filter->map[RMAP_OUT].name);
16755
16756 /* unsuppress-map */
16757 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16758 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16759 filter->usmap.name);
16760
16761 /* advertise-map : always applied in OUT direction*/
16762 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16763 CONDITION_NON_EXIST))
16764 vty_out(vty,
16765 " neighbor %s advertise-map %s non-exist-map %s\n",
16766 addr, filter->advmap.aname, filter->advmap.cname);
16767
16768 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16769 CONDITION_EXIST))
16770 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16771 addr, filter->advmap.aname, filter->advmap.cname);
16772
16773 /* filter-list. */
16774 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16775 FILTER_IN))
16776 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16777 filter->aslist[FILTER_IN].name);
16778
16779 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16780 FILTER_OUT))
16781 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16782 filter->aslist[FILTER_OUT].name);
16783 }
16784
16785 /* BGP peer configuration display function. */
16786 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16787 struct peer *peer)
16788 {
16789 struct peer *g_peer = NULL;
16790 char *addr;
16791 int if_pg_printed = false;
16792 int if_ras_printed = false;
16793
16794 /* Skip dynamic neighbors. */
16795 if (peer_dynamic_neighbor(peer))
16796 return;
16797
16798 if (peer->conf_if)
16799 addr = peer->conf_if;
16800 else
16801 addr = peer->host;
16802
16803 /************************************
16804 ****** Global to the neighbor ******
16805 ************************************/
16806 if (peer->conf_if) {
16807 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16808 vty_out(vty, " neighbor %s interface v6only", addr);
16809 else
16810 vty_out(vty, " neighbor %s interface", addr);
16811
16812 if (peer_group_active(peer)) {
16813 vty_out(vty, " peer-group %s", peer->group->name);
16814 if_pg_printed = true;
16815 } else if (peer->as_type == AS_SPECIFIED) {
16816 vty_out(vty, " remote-as %u", peer->as);
16817 if_ras_printed = true;
16818 } else if (peer->as_type == AS_INTERNAL) {
16819 vty_out(vty, " remote-as internal");
16820 if_ras_printed = true;
16821 } else if (peer->as_type == AS_EXTERNAL) {
16822 vty_out(vty, " remote-as external");
16823 if_ras_printed = true;
16824 }
16825
16826 vty_out(vty, "\n");
16827 }
16828
16829 /* remote-as and peer-group */
16830 /* peer is a member of a peer-group */
16831 if (peer_group_active(peer)) {
16832 g_peer = peer->group->conf;
16833
16834 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16835 if (peer->as_type == AS_SPECIFIED) {
16836 vty_out(vty, " neighbor %s remote-as %u\n",
16837 addr, peer->as);
16838 } else if (peer->as_type == AS_INTERNAL) {
16839 vty_out(vty,
16840 " neighbor %s remote-as internal\n",
16841 addr);
16842 } else if (peer->as_type == AS_EXTERNAL) {
16843 vty_out(vty,
16844 " neighbor %s remote-as external\n",
16845 addr);
16846 }
16847 }
16848
16849 /* For swpX peers we displayed the peer-group
16850 * via 'neighbor swpX interface peer-group PGNAME' */
16851 if (!if_pg_printed)
16852 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16853 peer->group->name);
16854 }
16855
16856 /* peer is NOT a member of a peer-group */
16857 else {
16858 /* peer is a peer-group, declare the peer-group */
16859 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16860 vty_out(vty, " neighbor %s peer-group\n", addr);
16861 }
16862
16863 if (!if_ras_printed) {
16864 if (peer->as_type == AS_SPECIFIED) {
16865 vty_out(vty, " neighbor %s remote-as %u\n",
16866 addr, peer->as);
16867 } else if (peer->as_type == AS_INTERNAL) {
16868 vty_out(vty,
16869 " neighbor %s remote-as internal\n",
16870 addr);
16871 } else if (peer->as_type == AS_EXTERNAL) {
16872 vty_out(vty,
16873 " neighbor %s remote-as external\n",
16874 addr);
16875 }
16876 }
16877 }
16878
16879 /* local-as */
16880 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16881 vty_out(vty, " neighbor %s local-as %u", addr,
16882 peer->change_local_as);
16883 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16884 vty_out(vty, " no-prepend");
16885 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16886 vty_out(vty, " replace-as");
16887 vty_out(vty, "\n");
16888 }
16889
16890 /* description */
16891 if (peer->desc) {
16892 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16893 }
16894
16895 /* shutdown */
16896 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16897 if (peer->tx_shutdown_message)
16898 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16899 peer->tx_shutdown_message);
16900 else
16901 vty_out(vty, " neighbor %s shutdown\n", addr);
16902 }
16903
16904 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16905 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16906 peer->rtt_expected, peer->rtt_keepalive_conf);
16907
16908 /* bfd */
16909 if (peer->bfd_config)
16910 bgp_bfd_peer_config_write(vty, peer, addr);
16911
16912 /* password */
16913 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16914 vty_out(vty, " neighbor %s password %s\n", addr,
16915 peer->password);
16916
16917 /* neighbor solo */
16918 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16919 if (!peer_group_active(peer)) {
16920 vty_out(vty, " neighbor %s solo\n", addr);
16921 }
16922 }
16923
16924 /* BGP port */
16925 if (peer->port != BGP_PORT_DEFAULT) {
16926 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16927 }
16928
16929 /* Local interface name */
16930 if (peer->ifname) {
16931 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16932 }
16933
16934 /* TCP max segment size */
16935 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16936 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16937
16938 /* passive */
16939 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16940 vty_out(vty, " neighbor %s passive\n", addr);
16941
16942 /* ebgp-multihop */
16943 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16944 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16945 && peer->ttl == MAXTTL)) {
16946 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16947 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16948 peer->ttl);
16949 }
16950 }
16951
16952 /* role */
16953 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16954 peer->local_role != ROLE_UNDEFINED)
16955 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16956 bgp_get_name_by_role(peer->local_role),
16957 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
16958 ? " strict-mode"
16959 : "");
16960
16961 /* ttl-security hops */
16962 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16963 if (!peer_group_active(peer)
16964 || g_peer->gtsm_hops != peer->gtsm_hops) {
16965 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16966 addr, peer->gtsm_hops);
16967 }
16968 }
16969
16970 /* disable-connected-check */
16971 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16972 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16973
16974 /* link-bw-encoding-ieee */
16975 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16976 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16977 addr);
16978
16979 /* extended-optional-parameters */
16980 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16981 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16982 addr);
16983
16984 /* enforce-first-as */
16985 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16986 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16987
16988 /* update-source */
16989 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16990 if (peer->update_source)
16991 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16992 peer->update_source);
16993 else if (peer->update_if)
16994 vty_out(vty, " neighbor %s update-source %s\n", addr,
16995 peer->update_if);
16996 }
16997
16998 /* advertisement-interval */
16999 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17000 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17001 peer->routeadv);
17002
17003 /* timers */
17004 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17005 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17006 peer->keepalive, peer->holdtime);
17007
17008 /* timers connect */
17009 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17010 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17011 peer->connect);
17012 /* need special-case handling for changed default values due to
17013 * config profile / version (because there is no "timers bgp connect"
17014 * command, we need to save this per-peer :/)
17015 */
17016 else if (!peer_group_active(peer) && !peer->connect &&
17017 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17018 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17019 peer->bgp->default_connect_retry);
17020
17021 /* timers delayopen */
17022 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17023 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17024 peer->delayopen);
17025 /* Save config even though flag is not set if default values have been
17026 * changed
17027 */
17028 else if (!peer_group_active(peer) && !peer->delayopen
17029 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17030 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17031 peer->bgp->default_delayopen);
17032
17033 /* capability dynamic */
17034 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17035 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17036
17037 /* capability extended-nexthop */
17038 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17039 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17040 !peer->conf_if)
17041 vty_out(vty,
17042 " no neighbor %s capability extended-nexthop\n",
17043 addr);
17044 else if (!peer->conf_if)
17045 vty_out(vty,
17046 " neighbor %s capability extended-nexthop\n",
17047 addr);
17048 }
17049
17050 /* dont-capability-negotiation */
17051 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17052 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17053
17054 /* override-capability */
17055 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17056 vty_out(vty, " neighbor %s override-capability\n", addr);
17057
17058 /* strict-capability-match */
17059 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17060 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17061
17062 /* Sender side AS path loop detection. */
17063 if (peer->as_path_loop_detection)
17064 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17065 addr);
17066
17067 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17068 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17069
17070 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17071 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17072 vty_out(vty,
17073 " neighbor %s graceful-restart-helper\n", addr);
17074 } else if (CHECK_FLAG(
17075 peer->peer_gr_new_status_flag,
17076 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17077 vty_out(vty,
17078 " neighbor %s graceful-restart\n", addr);
17079 } else if (
17080 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17081 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17082 && !(CHECK_FLAG(
17083 peer->peer_gr_new_status_flag,
17084 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17085 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17086 addr);
17087 }
17088 }
17089 }
17090
17091 /* BGP peer configuration display function. */
17092 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17093 struct peer *peer, afi_t afi, safi_t safi)
17094 {
17095 struct peer *g_peer = NULL;
17096 char *addr;
17097 bool flag_scomm, flag_secomm, flag_slcomm;
17098
17099 /* Skip dynamic neighbors. */
17100 if (peer_dynamic_neighbor(peer))
17101 return;
17102
17103 if (peer->conf_if)
17104 addr = peer->conf_if;
17105 else
17106 addr = peer->host;
17107
17108 /************************************
17109 ****** Per AF to the neighbor ******
17110 ************************************/
17111 if (peer_group_active(peer)) {
17112 g_peer = peer->group->conf;
17113
17114 /* If the peer-group is active but peer is not, print a 'no
17115 * activate' */
17116 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17117 vty_out(vty, " no neighbor %s activate\n", addr);
17118 }
17119
17120 /* If the peer-group is not active but peer is, print an
17121 'activate' */
17122 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17123 vty_out(vty, " neighbor %s activate\n", addr);
17124 }
17125 } else {
17126 if (peer->afc[afi][safi]) {
17127 if (safi == SAFI_ENCAP)
17128 vty_out(vty, " neighbor %s activate\n", addr);
17129 else if (!bgp->default_af[afi][safi])
17130 vty_out(vty, " neighbor %s activate\n", addr);
17131 } else {
17132 if (bgp->default_af[afi][safi])
17133 vty_out(vty, " no neighbor %s activate\n",
17134 addr);
17135 }
17136 }
17137
17138 /* addpath TX knobs */
17139 if (peergroup_af_addpath_check(peer, afi, safi)) {
17140 switch (peer->addpath_type[afi][safi]) {
17141 case BGP_ADDPATH_ALL:
17142 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17143 addr);
17144 break;
17145 case BGP_ADDPATH_BEST_PER_AS:
17146 vty_out(vty,
17147 " neighbor %s addpath-tx-bestpath-per-AS\n",
17148 addr);
17149 break;
17150 case BGP_ADDPATH_MAX:
17151 case BGP_ADDPATH_NONE:
17152 break;
17153 }
17154 }
17155
17156 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17157 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17158
17159 /* ORF capability. */
17160 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17161 || peergroup_af_flag_check(peer, afi, safi,
17162 PEER_FLAG_ORF_PREFIX_RM)) {
17163 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17164
17165 if (peergroup_af_flag_check(peer, afi, safi,
17166 PEER_FLAG_ORF_PREFIX_SM)
17167 && peergroup_af_flag_check(peer, afi, safi,
17168 PEER_FLAG_ORF_PREFIX_RM))
17169 vty_out(vty, " both");
17170 else if (peergroup_af_flag_check(peer, afi, safi,
17171 PEER_FLAG_ORF_PREFIX_SM))
17172 vty_out(vty, " send");
17173 else
17174 vty_out(vty, " receive");
17175 vty_out(vty, "\n");
17176 }
17177
17178 /* Route reflector client. */
17179 if (peergroup_af_flag_check(peer, afi, safi,
17180 PEER_FLAG_REFLECTOR_CLIENT)) {
17181 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17182 }
17183
17184 /* next-hop-self force */
17185 if (peergroup_af_flag_check(peer, afi, safi,
17186 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17187 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17188 }
17189
17190 /* next-hop-self */
17191 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17192 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17193 }
17194
17195 /* remove-private-AS */
17196 if (peergroup_af_flag_check(peer, afi, safi,
17197 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17198 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17199 addr);
17200 }
17201
17202 else if (peergroup_af_flag_check(peer, afi, safi,
17203 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17204 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17205 addr);
17206 }
17207
17208 else if (peergroup_af_flag_check(peer, afi, safi,
17209 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17210 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17211 }
17212
17213 else if (peergroup_af_flag_check(peer, afi, safi,
17214 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17215 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17216 }
17217
17218 /* as-override */
17219 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17220 vty_out(vty, " neighbor %s as-override\n", addr);
17221 }
17222
17223 /* send-community print. */
17224 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17225 PEER_FLAG_SEND_COMMUNITY);
17226 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17227 PEER_FLAG_SEND_EXT_COMMUNITY);
17228 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17229 PEER_FLAG_SEND_LARGE_COMMUNITY);
17230
17231 if (flag_scomm && flag_secomm && flag_slcomm) {
17232 vty_out(vty, " no neighbor %s send-community all\n", addr);
17233 } else {
17234 if (flag_scomm)
17235 vty_out(vty, " no neighbor %s send-community\n", addr);
17236 if (flag_secomm)
17237 vty_out(vty,
17238 " no neighbor %s send-community extended\n",
17239 addr);
17240
17241 if (flag_slcomm)
17242 vty_out(vty, " no neighbor %s send-community large\n",
17243 addr);
17244 }
17245
17246 /* Default information */
17247 if (peergroup_af_flag_check(peer, afi, safi,
17248 PEER_FLAG_DEFAULT_ORIGINATE)) {
17249 vty_out(vty, " neighbor %s default-originate", addr);
17250
17251 if (peer->default_rmap[afi][safi].name)
17252 vty_out(vty, " route-map %s",
17253 peer->default_rmap[afi][safi].name);
17254
17255 vty_out(vty, "\n");
17256 }
17257
17258 /* Soft reconfiguration inbound. */
17259 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17260 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17261 addr);
17262 }
17263
17264 /* maximum-prefix. */
17265 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17266 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17267 peer->pmax[afi][safi]);
17268
17269 if (peer->pmax_threshold[afi][safi]
17270 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17271 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17272 if (peer_af_flag_check(peer, afi, safi,
17273 PEER_FLAG_MAX_PREFIX_WARNING))
17274 vty_out(vty, " warning-only");
17275 if (peer->pmax_restart[afi][safi])
17276 vty_out(vty, " restart %u",
17277 peer->pmax_restart[afi][safi]);
17278 if (peer_af_flag_check(peer, afi, safi,
17279 PEER_FLAG_MAX_PREFIX_FORCE))
17280 vty_out(vty, " force");
17281
17282 vty_out(vty, "\n");
17283 }
17284
17285 /* maximum-prefix-out */
17286 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17287 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17288 addr, peer->pmax_out[afi][safi]);
17289
17290 /* Route server client. */
17291 if (peergroup_af_flag_check(peer, afi, safi,
17292 PEER_FLAG_RSERVER_CLIENT)) {
17293 vty_out(vty, " neighbor %s route-server-client\n", addr);
17294 }
17295
17296 /* Nexthop-local unchanged. */
17297 if (peergroup_af_flag_check(peer, afi, safi,
17298 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17299 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17300 }
17301
17302 /* allowas-in <1-10> */
17303 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17304 if (peer_af_flag_check(peer, afi, safi,
17305 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17306 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17307 } else if (peer->allowas_in[afi][safi] == 3) {
17308 vty_out(vty, " neighbor %s allowas-in\n", addr);
17309 } else {
17310 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17311 peer->allowas_in[afi][safi]);
17312 }
17313 }
17314
17315 /* soo */
17316 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17317 char *soo_str = ecommunity_ecom2str(
17318 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17319
17320 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17321 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17322 }
17323
17324 /* weight */
17325 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17326 vty_out(vty, " neighbor %s weight %lu\n", addr,
17327 peer->weight[afi][safi]);
17328
17329 /* Filter. */
17330 bgp_config_write_filter(vty, peer, afi, safi);
17331
17332 /* atribute-unchanged. */
17333 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17334 || (safi != SAFI_EVPN
17335 && peer_af_flag_check(peer, afi, safi,
17336 PEER_FLAG_NEXTHOP_UNCHANGED))
17337 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17338
17339 if (!peer_group_active(peer)
17340 || peergroup_af_flag_check(peer, afi, safi,
17341 PEER_FLAG_AS_PATH_UNCHANGED)
17342 || peergroup_af_flag_check(peer, afi, safi,
17343 PEER_FLAG_NEXTHOP_UNCHANGED)
17344 || peergroup_af_flag_check(peer, afi, safi,
17345 PEER_FLAG_MED_UNCHANGED)) {
17346
17347 vty_out(vty,
17348 " neighbor %s attribute-unchanged%s%s%s\n",
17349 addr,
17350 peer_af_flag_check(peer, afi, safi,
17351 PEER_FLAG_AS_PATH_UNCHANGED)
17352 ? " as-path"
17353 : "",
17354 peer_af_flag_check(peer, afi, safi,
17355 PEER_FLAG_NEXTHOP_UNCHANGED)
17356 ? " next-hop"
17357 : "",
17358 peer_af_flag_check(peer, afi, safi,
17359 PEER_FLAG_MED_UNCHANGED)
17360 ? " med"
17361 : "");
17362 }
17363 }
17364 }
17365
17366 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17367 safi_t safi)
17368 {
17369 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17370 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17371 vty_out(vty, " no bgp retain route-target all\n");
17372 }
17373
17374 /* Address family based peer configuration display. */
17375 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17376 safi_t safi)
17377 {
17378 struct peer *peer;
17379 struct peer_group *group;
17380 struct listnode *node, *nnode;
17381
17382
17383 vty_frame(vty, " !\n address-family ");
17384 if (afi == AFI_IP) {
17385 if (safi == SAFI_UNICAST)
17386 vty_frame(vty, "ipv4 unicast");
17387 else if (safi == SAFI_LABELED_UNICAST)
17388 vty_frame(vty, "ipv4 labeled-unicast");
17389 else if (safi == SAFI_MULTICAST)
17390 vty_frame(vty, "ipv4 multicast");
17391 else if (safi == SAFI_MPLS_VPN)
17392 vty_frame(vty, "ipv4 vpn");
17393 else if (safi == SAFI_ENCAP)
17394 vty_frame(vty, "ipv4 encap");
17395 else if (safi == SAFI_FLOWSPEC)
17396 vty_frame(vty, "ipv4 flowspec");
17397 } else if (afi == AFI_IP6) {
17398 if (safi == SAFI_UNICAST)
17399 vty_frame(vty, "ipv6 unicast");
17400 else if (safi == SAFI_LABELED_UNICAST)
17401 vty_frame(vty, "ipv6 labeled-unicast");
17402 else if (safi == SAFI_MULTICAST)
17403 vty_frame(vty, "ipv6 multicast");
17404 else if (safi == SAFI_MPLS_VPN)
17405 vty_frame(vty, "ipv6 vpn");
17406 else if (safi == SAFI_ENCAP)
17407 vty_frame(vty, "ipv6 encap");
17408 else if (safi == SAFI_FLOWSPEC)
17409 vty_frame(vty, "ipv6 flowspec");
17410 } else if (afi == AFI_L2VPN) {
17411 if (safi == SAFI_EVPN)
17412 vty_frame(vty, "l2vpn evpn");
17413 }
17414 vty_frame(vty, "\n");
17415
17416 bgp_config_write_distance(vty, bgp, afi, safi);
17417
17418 bgp_config_write_network(vty, bgp, afi, safi);
17419
17420 bgp_config_write_redistribute(vty, bgp, afi, safi);
17421
17422 /* BGP flag dampening. */
17423 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17424 bgp_config_write_damp(vty, afi, safi);
17425
17426 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17427 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17428
17429 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17430 /* Do not display doppelganger peers */
17431 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17432 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17433 }
17434
17435 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17436 bgp_config_write_table_map(vty, bgp, afi, safi);
17437
17438 if (safi == SAFI_EVPN)
17439 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17440
17441 if (safi == SAFI_FLOWSPEC)
17442 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17443
17444 if (safi == SAFI_MPLS_VPN)
17445 bgp_vpn_config_write(vty, bgp, afi, safi);
17446
17447 if (safi == SAFI_UNICAST) {
17448 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17449 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17450 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17451
17452 vty_out(vty, " export vpn\n");
17453 }
17454 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17455 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17456
17457 vty_out(vty, " import vpn\n");
17458 }
17459 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17460 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17461 char *name;
17462
17463 for (ALL_LIST_ELEMENTS_RO(
17464 bgp->vpn_policy[afi].import_vrf, node,
17465 name))
17466 vty_out(vty, " import vrf %s\n", name);
17467 }
17468 }
17469
17470 vty_endframe(vty, " exit-address-family\n");
17471 }
17472
17473 int bgp_config_write(struct vty *vty)
17474 {
17475 struct bgp *bgp;
17476 struct peer_group *group;
17477 struct peer *peer;
17478 struct listnode *node, *nnode;
17479 struct listnode *mnode, *mnnode;
17480 afi_t afi;
17481 safi_t safi;
17482
17483 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17484 vty_out(vty, "bgp route-map delay-timer %u\n",
17485 bm->rmap_update_timer);
17486
17487 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17488 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17489 if (bm->v_update_delay != bm->v_establish_wait)
17490 vty_out(vty, " %d", bm->v_establish_wait);
17491 vty_out(vty, "\n");
17492 }
17493
17494 if (bm->wait_for_fib)
17495 vty_out(vty, "bgp suppress-fib-pending\n");
17496
17497 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17498 vty_out(vty, "bgp graceful-shutdown\n");
17499
17500 /* No-RIB (Zebra) option flag configuration */
17501 if (bgp_option_check(BGP_OPT_NO_FIB))
17502 vty_out(vty, "bgp no-rib\n");
17503
17504 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17505 vty_out(vty, "bgp send-extra-data zebra\n");
17506
17507 /* BGP session DSCP value */
17508 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17509 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17510
17511 /* BGP configuration. */
17512 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17513
17514 /* skip all auto created vrf as they dont have user config */
17515 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17516 continue;
17517
17518 /* Router bgp ASN */
17519 vty_out(vty, "router bgp %u", bgp->as);
17520
17521 if (bgp->name)
17522 vty_out(vty, " %s %s",
17523 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17524 ? "view" : "vrf", bgp->name);
17525 vty_out(vty, "\n");
17526
17527 /* BGP fast-external-failover. */
17528 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17529 vty_out(vty, " no bgp fast-external-failover\n");
17530
17531 /* BGP router ID. */
17532 if (bgp->router_id_static.s_addr != INADDR_ANY)
17533 vty_out(vty, " bgp router-id %pI4\n",
17534 &bgp->router_id_static);
17535
17536 /* Suppress fib pending */
17537 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17538 vty_out(vty, " bgp suppress-fib-pending\n");
17539
17540 /* BGP log-neighbor-changes. */
17541 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17542 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17543 vty_out(vty, " %sbgp log-neighbor-changes\n",
17544 CHECK_FLAG(bgp->flags,
17545 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17546 ? ""
17547 : "no ");
17548
17549 /* BGP configuration. */
17550 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17551 vty_out(vty, " bgp always-compare-med\n");
17552
17553 /* RFC8212 default eBGP policy. */
17554 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17555 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17556 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17557 CHECK_FLAG(bgp->flags,
17558 BGP_FLAG_EBGP_REQUIRES_POLICY)
17559 ? ""
17560 : "no ");
17561
17562 /* draft-ietf-idr-deprecate-as-set-confed-set */
17563 if (bgp->reject_as_sets)
17564 vty_out(vty, " bgp reject-as-sets\n");
17565
17566 /* Suppress duplicate updates if the route actually not changed
17567 */
17568 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17569 != SAVE_BGP_SUPPRESS_DUPLICATES)
17570 vty_out(vty, " %sbgp suppress-duplicates\n",
17571 CHECK_FLAG(bgp->flags,
17572 BGP_FLAG_SUPPRESS_DUPLICATES)
17573 ? ""
17574 : "no ");
17575
17576 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17577 */
17578 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17579 SAVE_BGP_HARD_ADMIN_RESET)
17580 vty_out(vty, " %sbgp hard-administrative-reset\n",
17581 CHECK_FLAG(bgp->flags,
17582 BGP_FLAG_HARD_ADMIN_RESET)
17583 ? ""
17584 : "no ");
17585
17586 /* BGP default <afi>-<safi> */
17587 FOREACH_AFI_SAFI (afi, safi) {
17588 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17589 if (!bgp->default_af[afi][safi])
17590 vty_out(vty, " no bgp default %s\n",
17591 get_bgp_default_af_flag(afi,
17592 safi));
17593 } else if (bgp->default_af[afi][safi])
17594 vty_out(vty, " bgp default %s\n",
17595 get_bgp_default_af_flag(afi, safi));
17596 }
17597
17598 /* BGP default local-preference. */
17599 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17600 vty_out(vty, " bgp default local-preference %u\n",
17601 bgp->default_local_pref);
17602
17603 /* BGP default show-hostname */
17604 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17605 != SAVE_BGP_SHOW_HOSTNAME)
17606 vty_out(vty, " %sbgp default show-hostname\n",
17607 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17608 ? ""
17609 : "no ");
17610
17611 /* BGP default show-nexthop-hostname */
17612 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17613 != SAVE_BGP_SHOW_HOSTNAME)
17614 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17615 CHECK_FLAG(bgp->flags,
17616 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17617 ? ""
17618 : "no ");
17619
17620 /* BGP default subgroup-pkt-queue-max. */
17621 if (bgp->default_subgroup_pkt_queue_max
17622 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17623 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17624 bgp->default_subgroup_pkt_queue_max);
17625
17626 /* BGP client-to-client reflection. */
17627 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17628 vty_out(vty, " no bgp client-to-client reflection\n");
17629
17630 /* BGP cluster ID. */
17631 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17632 vty_out(vty, " bgp cluster-id %pI4\n",
17633 &bgp->cluster_id);
17634
17635 /* Disable ebgp connected nexthop check */
17636 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17637 vty_out(vty,
17638 " bgp disable-ebgp-connected-route-check\n");
17639
17640 /* Confederation identifier*/
17641 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17642 vty_out(vty, " bgp confederation identifier %u\n",
17643 bgp->confed_id);
17644
17645 /* Confederation peer */
17646 if (bgp->confed_peers_cnt > 0) {
17647 int i;
17648
17649 vty_out(vty, " bgp confederation peers");
17650
17651 for (i = 0; i < bgp->confed_peers_cnt; i++)
17652 vty_out(vty, " %u", bgp->confed_peers[i]);
17653
17654 vty_out(vty, "\n");
17655 }
17656
17657 /* BGP deterministic-med. */
17658 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17659 != SAVE_BGP_DETERMINISTIC_MED)
17660 vty_out(vty, " %sbgp deterministic-med\n",
17661 CHECK_FLAG(bgp->flags,
17662 BGP_FLAG_DETERMINISTIC_MED)
17663 ? ""
17664 : "no ");
17665
17666 /* BGP update-delay. */
17667 bgp_config_write_update_delay(vty, bgp);
17668
17669 if (bgp->v_maxmed_onstartup
17670 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17671 vty_out(vty, " bgp max-med on-startup %u",
17672 bgp->v_maxmed_onstartup);
17673 if (bgp->maxmed_onstartup_value
17674 != BGP_MAXMED_VALUE_DEFAULT)
17675 vty_out(vty, " %u",
17676 bgp->maxmed_onstartup_value);
17677 vty_out(vty, "\n");
17678 }
17679 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17680 vty_out(vty, " bgp max-med administrative");
17681 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17682 vty_out(vty, " %u", bgp->maxmed_admin_value);
17683 vty_out(vty, "\n");
17684 }
17685
17686 /* write quanta */
17687 bgp_config_write_wpkt_quanta(vty, bgp);
17688 /* read quanta */
17689 bgp_config_write_rpkt_quanta(vty, bgp);
17690
17691 /* coalesce time */
17692 bgp_config_write_coalesce_time(vty, bgp);
17693
17694 /* BGP per-instance graceful-shutdown */
17695 /* BGP-wide settings and per-instance settings are mutually
17696 * exclusive.
17697 */
17698 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17699 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17700 vty_out(vty, " bgp graceful-shutdown\n");
17701
17702 /* Long-lived Graceful Restart */
17703 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17704 vty_out(vty,
17705 " bgp long-lived-graceful-restart stale-time %u\n",
17706 bgp->llgr_stale_time);
17707
17708 /* BGP graceful-restart. */
17709 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17710 vty_out(vty,
17711 " bgp graceful-restart stalepath-time %u\n",
17712 bgp->stalepath_time);
17713
17714 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17715 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17716 bgp->restart_time);
17717
17718 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17719 SAVE_BGP_GRACEFUL_NOTIFICATION)
17720 vty_out(vty, " %sbgp graceful-restart notification\n",
17721 CHECK_FLAG(bgp->flags,
17722 BGP_FLAG_GRACEFUL_NOTIFICATION)
17723 ? ""
17724 : "no ");
17725
17726 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17727 vty_out(vty,
17728 " bgp graceful-restart select-defer-time %u\n",
17729 bgp->select_defer_time);
17730
17731 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17732 vty_out(vty, " bgp graceful-restart\n");
17733
17734 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17735 vty_out(vty, " bgp graceful-restart-disable\n");
17736
17737 /* BGP graceful-restart Preserve State F bit. */
17738 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17739 vty_out(vty,
17740 " bgp graceful-restart preserve-fw-state\n");
17741
17742 /* BGP TCP keepalive */
17743 bgp_config_tcp_keepalive(vty, bgp);
17744
17745 /* Stale timer for RIB */
17746 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17747 vty_out(vty,
17748 " bgp graceful-restart rib-stale-time %u\n",
17749 bgp->rib_stale_time);
17750
17751 /* BGP bestpath method. */
17752 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17753 vty_out(vty, " bgp bestpath as-path ignore\n");
17754 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17755 vty_out(vty, " bgp bestpath as-path confed\n");
17756
17757 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17758 if (CHECK_FLAG(bgp->flags,
17759 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17760 vty_out(vty,
17761 " bgp bestpath as-path multipath-relax as-set\n");
17762 } else {
17763 vty_out(vty,
17764 " bgp bestpath as-path multipath-relax\n");
17765 }
17766 }
17767
17768 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17769 vty_out(vty,
17770 " bgp route-reflector allow-outbound-policy\n");
17771 }
17772 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17773 vty_out(vty, " bgp bestpath compare-routerid\n");
17774 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17775 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17776 vty_out(vty, " bgp bestpath med");
17777 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17778 vty_out(vty, " confed");
17779 if (CHECK_FLAG(bgp->flags,
17780 BGP_FLAG_MED_MISSING_AS_WORST))
17781 vty_out(vty, " missing-as-worst");
17782 vty_out(vty, "\n");
17783 }
17784
17785 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17786 vty_out(vty,
17787 " bgp bestpath peer-type multipath-relax\n");
17788
17789 /* Link bandwidth handling. */
17790 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17791 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17792 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17793 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17794 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17795 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17796
17797 /* BGP network import check. */
17798 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17799 != SAVE_BGP_IMPORT_CHECK)
17800 vty_out(vty, " %sbgp network import-check\n",
17801 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17802 ? ""
17803 : "no ");
17804
17805 /* BGP timers configuration. */
17806 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17807 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17808 vty_out(vty, " timers bgp %u %u\n",
17809 bgp->default_keepalive, bgp->default_holdtime);
17810
17811 /* BGP minimum holdtime configuration. */
17812 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17813 && bgp->default_min_holdtime != 0)
17814 vty_out(vty, " bgp minimum-holdtime %u\n",
17815 bgp->default_min_holdtime);
17816
17817 /* Conditional advertisement timer configuration */
17818 if (bgp->condition_check_period
17819 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17820 vty_out(vty,
17821 " bgp conditional-advertisement timer %u\n",
17822 bgp->condition_check_period);
17823
17824 /* peer-group */
17825 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17826 bgp_config_write_peer_global(vty, bgp, group->conf);
17827 }
17828
17829 /* Normal neighbor configuration. */
17830 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17831 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17832 bgp_config_write_peer_global(vty, bgp, peer);
17833 }
17834
17835 /* listen range and limit for dynamic BGP neighbors */
17836 bgp_config_write_listen(vty, bgp);
17837
17838 /*
17839 * BGP default autoshutdown neighbors
17840 *
17841 * This must be placed after any peer and peer-group
17842 * configuration, to avoid setting all peers to shutdown after
17843 * a daemon restart, which is undesired behavior. (see #2286)
17844 */
17845 if (bgp->autoshutdown)
17846 vty_out(vty, " bgp default shutdown\n");
17847
17848 /* BGP instance administrative shutdown */
17849 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17850 vty_out(vty, " bgp shutdown\n");
17851
17852 if (bgp->allow_martian)
17853 vty_out(vty, " bgp allow-martian-nexthop\n");
17854
17855 if (bgp->fast_convergence)
17856 vty_out(vty, " bgp fast-convergence\n");
17857
17858 if (bgp->srv6_enabled) {
17859 vty_frame(vty, " !\n segment-routing srv6\n");
17860 if (strlen(bgp->srv6_locator_name))
17861 vty_out(vty, " locator %s\n",
17862 bgp->srv6_locator_name);
17863 vty_endframe(vty, " exit\n");
17864 }
17865
17866
17867 /* IPv4 unicast configuration. */
17868 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17869
17870 /* IPv4 multicast configuration. */
17871 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17872
17873 /* IPv4 labeled-unicast configuration. */
17874 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17875
17876 /* IPv4 VPN configuration. */
17877 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17878
17879 /* ENCAPv4 configuration. */
17880 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17881
17882 /* FLOWSPEC v4 configuration. */
17883 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17884
17885 /* IPv6 unicast configuration. */
17886 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17887
17888 /* IPv6 multicast configuration. */
17889 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17890
17891 /* IPv6 labeled-unicast configuration. */
17892 bgp_config_write_family(vty, bgp, AFI_IP6,
17893 SAFI_LABELED_UNICAST);
17894
17895 /* IPv6 VPN configuration. */
17896 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17897
17898 /* ENCAPv6 configuration. */
17899 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17900
17901 /* FLOWSPEC v6 configuration. */
17902 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17903
17904 /* EVPN configuration. */
17905 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17906
17907 hook_call(bgp_inst_config_write, bgp, vty);
17908
17909 #ifdef ENABLE_BGP_VNC
17910 bgp_rfapi_cfg_write(vty, bgp);
17911 #endif
17912
17913 vty_out(vty, "exit\n");
17914 vty_out(vty, "!\n");
17915 }
17916 return 0;
17917 }
17918
17919
17920 /* BGP node structure. */
17921 static struct cmd_node bgp_node = {
17922 .name = "bgp",
17923 .node = BGP_NODE,
17924 .parent_node = CONFIG_NODE,
17925 .prompt = "%s(config-router)# ",
17926 .config_write = bgp_config_write,
17927 };
17928
17929 static struct cmd_node bgp_ipv4_unicast_node = {
17930 .name = "bgp ipv4 unicast",
17931 .node = BGP_IPV4_NODE,
17932 .parent_node = BGP_NODE,
17933 .prompt = "%s(config-router-af)# ",
17934 .no_xpath = true,
17935 };
17936
17937 static struct cmd_node bgp_ipv4_multicast_node = {
17938 .name = "bgp ipv4 multicast",
17939 .node = BGP_IPV4M_NODE,
17940 .parent_node = BGP_NODE,
17941 .prompt = "%s(config-router-af)# ",
17942 .no_xpath = true,
17943 };
17944
17945 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17946 .name = "bgp ipv4 labeled unicast",
17947 .node = BGP_IPV4L_NODE,
17948 .parent_node = BGP_NODE,
17949 .prompt = "%s(config-router-af)# ",
17950 .no_xpath = true,
17951 };
17952
17953 static struct cmd_node bgp_ipv6_unicast_node = {
17954 .name = "bgp ipv6 unicast",
17955 .node = BGP_IPV6_NODE,
17956 .parent_node = BGP_NODE,
17957 .prompt = "%s(config-router-af)# ",
17958 .no_xpath = true,
17959 };
17960
17961 static struct cmd_node bgp_ipv6_multicast_node = {
17962 .name = "bgp ipv6 multicast",
17963 .node = BGP_IPV6M_NODE,
17964 .parent_node = BGP_NODE,
17965 .prompt = "%s(config-router-af)# ",
17966 .no_xpath = true,
17967 };
17968
17969 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17970 .name = "bgp ipv6 labeled unicast",
17971 .node = BGP_IPV6L_NODE,
17972 .parent_node = BGP_NODE,
17973 .prompt = "%s(config-router-af)# ",
17974 .no_xpath = true,
17975 };
17976
17977 static struct cmd_node bgp_vpnv4_node = {
17978 .name = "bgp vpnv4",
17979 .node = BGP_VPNV4_NODE,
17980 .parent_node = BGP_NODE,
17981 .prompt = "%s(config-router-af)# ",
17982 .no_xpath = true,
17983 };
17984
17985 static struct cmd_node bgp_vpnv6_node = {
17986 .name = "bgp vpnv6",
17987 .node = BGP_VPNV6_NODE,
17988 .parent_node = BGP_NODE,
17989 .prompt = "%s(config-router-af-vpnv6)# ",
17990 .no_xpath = true,
17991 };
17992
17993 static struct cmd_node bgp_evpn_node = {
17994 .name = "bgp evpn",
17995 .node = BGP_EVPN_NODE,
17996 .parent_node = BGP_NODE,
17997 .prompt = "%s(config-router-evpn)# ",
17998 .no_xpath = true,
17999 };
18000
18001 static struct cmd_node bgp_evpn_vni_node = {
18002 .name = "bgp evpn vni",
18003 .node = BGP_EVPN_VNI_NODE,
18004 .parent_node = BGP_EVPN_NODE,
18005 .prompt = "%s(config-router-af-vni)# ",
18006 };
18007
18008 static struct cmd_node bgp_flowspecv4_node = {
18009 .name = "bgp ipv4 flowspec",
18010 .node = BGP_FLOWSPECV4_NODE,
18011 .parent_node = BGP_NODE,
18012 .prompt = "%s(config-router-af)# ",
18013 .no_xpath = true,
18014 };
18015
18016 static struct cmd_node bgp_flowspecv6_node = {
18017 .name = "bgp ipv6 flowspec",
18018 .node = BGP_FLOWSPECV6_NODE,
18019 .parent_node = BGP_NODE,
18020 .prompt = "%s(config-router-af-vpnv6)# ",
18021 .no_xpath = true,
18022 };
18023
18024 static struct cmd_node bgp_srv6_node = {
18025 .name = "bgp srv6",
18026 .node = BGP_SRV6_NODE,
18027 .parent_node = BGP_NODE,
18028 .prompt = "%s(config-router-srv6)# ",
18029 };
18030
18031 static void community_list_vty(void);
18032
18033 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18034 {
18035 struct bgp *bgp;
18036 struct peer_group *group;
18037 struct listnode *lnbgp, *lnpeer;
18038
18039 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18040 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18041 vector_set(comps,
18042 XSTRDUP(MTYPE_COMPLETION, group->name));
18043 }
18044 }
18045
18046 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18047 {
18048 struct bgp *bgp;
18049 struct peer *peer;
18050 struct listnode *lnbgp, *lnpeer;
18051
18052 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18053 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18054 /* only provide suggestions on the appropriate input
18055 * token type,
18056 * they'll otherwise show up multiple times */
18057 enum cmd_token_type match_type;
18058 char *name = peer->host;
18059
18060 if (peer->conf_if) {
18061 match_type = VARIABLE_TKN;
18062 name = peer->conf_if;
18063 } else if (strchr(peer->host, ':'))
18064 match_type = IPV6_TKN;
18065 else
18066 match_type = IPV4_TKN;
18067
18068 if (token->type != match_type)
18069 continue;
18070
18071 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18072 }
18073 }
18074 }
18075
18076 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18077 {
18078 bgp_ac_peer(comps, token);
18079
18080 if (token->type == VARIABLE_TKN)
18081 bgp_ac_peergroup(comps, token);
18082 }
18083
18084 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18085 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18086 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18087 {.varname = "peer", .completions = bgp_ac_neighbor},
18088 {.completions = NULL}};
18089
18090 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18091 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18092 {.completions = NULL} };
18093
18094 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18095
18096 static struct thread *t_bgp_cfg;
18097
18098 bool bgp_config_inprocess(void)
18099 {
18100 return thread_is_scheduled(t_bgp_cfg);
18101 }
18102
18103 static void bgp_config_finish(struct thread *t)
18104 {
18105 struct listnode *node;
18106 struct bgp *bgp;
18107
18108 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18109 hook_call(bgp_config_end, bgp);
18110 }
18111
18112 static void bgp_config_start(void)
18113 {
18114 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18115 THREAD_OFF(t_bgp_cfg);
18116 thread_add_timer(bm->master, bgp_config_finish, NULL,
18117 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18118 }
18119
18120 /* When we receive a hook the configuration is read,
18121 * we start a timer to make sure we postpone sending
18122 * EoR before route-maps are processed.
18123 * This is especially valid if using `bgp route-map delay-timer`.
18124 */
18125 static void bgp_config_end(void)
18126 {
18127 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18128 uint32_t bgp_post_config_delay =
18129 thread_is_scheduled(bm->t_rmap_update)
18130 ? thread_timer_remain_second(bm->t_rmap_update)
18131 : BGP_POST_CONFIG_DELAY_SECONDS;
18132
18133 /* If BGP config processing thread isn't running, then
18134 * we can return and rely it's properly handled.
18135 */
18136 if (!bgp_config_inprocess())
18137 return;
18138
18139 THREAD_OFF(t_bgp_cfg);
18140
18141 /* Start a new timer to make sure we don't send EoR
18142 * before route-maps are processed.
18143 */
18144 thread_add_timer(bm->master, bgp_config_finish, NULL,
18145 bgp_post_config_delay, &t_bgp_cfg);
18146 }
18147
18148 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18149 {
18150 int write = 0;
18151 struct interface *ifp;
18152 struct bgp_interface *iifp;
18153
18154 FOR_ALL_INTERFACES (vrf, ifp) {
18155 iifp = ifp->info;
18156 if (!iifp)
18157 continue;
18158
18159 if_vty_config_start(vty, ifp);
18160
18161 if (CHECK_FLAG(iifp->flags,
18162 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18163 vty_out(vty, " mpls bgp forwarding\n");
18164 write++;
18165 }
18166
18167 if_vty_config_end(vty);
18168 }
18169
18170 return write;
18171 }
18172
18173 /* Configuration write function for bgpd. */
18174 static int config_write_interface(struct vty *vty)
18175 {
18176 int write = 0;
18177 struct vrf *vrf = NULL;
18178
18179 /* Display all VRF aware OSPF interface configuration */
18180 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18181 write += config_write_interface_one(vty, vrf);
18182 }
18183
18184 return write;
18185 }
18186
18187 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18188 "[no$no] mpls bgp forwarding",
18189 NO_STR MPLS_STR BGP_STR
18190 "Enable MPLS forwarding for eBGP directly connected peers\n")
18191 {
18192 bool check;
18193 struct bgp_interface *iifp;
18194
18195 VTY_DECLVAR_CONTEXT(interface, ifp);
18196 iifp = ifp->info;
18197 if (!iifp) {
18198 vty_out(vty, "Interface %s not available\n", ifp->name);
18199 return CMD_WARNING_CONFIG_FAILED;
18200 }
18201 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18202 if (check != !no) {
18203 if (no)
18204 UNSET_FLAG(iifp->flags,
18205 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18206 else
18207 SET_FLAG(iifp->flags,
18208 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18209 /* trigger a nht update on eBGP sessions */
18210 if (if_is_operative(ifp))
18211 bgp_nht_ifp_up(ifp);
18212 }
18213 return CMD_SUCCESS;
18214 }
18215
18216 /* Initialization of BGP interface. */
18217 static void bgp_vty_if_init(void)
18218 {
18219 /* Install interface node. */
18220 if_cmd_init(config_write_interface);
18221
18222 /* "mpls bgp forwarding" commands. */
18223 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18224 }
18225
18226 void bgp_vty_init(void)
18227 {
18228 cmd_variable_handler_register(bgp_var_neighbor);
18229 cmd_variable_handler_register(bgp_var_peergroup);
18230
18231 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18232
18233 /* Install bgp top node. */
18234 install_node(&bgp_node);
18235 install_node(&bgp_ipv4_unicast_node);
18236 install_node(&bgp_ipv4_multicast_node);
18237 install_node(&bgp_ipv4_labeled_unicast_node);
18238 install_node(&bgp_ipv6_unicast_node);
18239 install_node(&bgp_ipv6_multicast_node);
18240 install_node(&bgp_ipv6_labeled_unicast_node);
18241 install_node(&bgp_vpnv4_node);
18242 install_node(&bgp_vpnv6_node);
18243 install_node(&bgp_evpn_node);
18244 install_node(&bgp_evpn_vni_node);
18245 install_node(&bgp_flowspecv4_node);
18246 install_node(&bgp_flowspecv6_node);
18247 install_node(&bgp_srv6_node);
18248
18249 /* Install default VTY commands to new nodes. */
18250 install_default(BGP_NODE);
18251 install_default(BGP_IPV4_NODE);
18252 install_default(BGP_IPV4M_NODE);
18253 install_default(BGP_IPV4L_NODE);
18254 install_default(BGP_IPV6_NODE);
18255 install_default(BGP_IPV6M_NODE);
18256 install_default(BGP_IPV6L_NODE);
18257 install_default(BGP_VPNV4_NODE);
18258 install_default(BGP_VPNV6_NODE);
18259 install_default(BGP_FLOWSPECV4_NODE);
18260 install_default(BGP_FLOWSPECV6_NODE);
18261 install_default(BGP_EVPN_NODE);
18262 install_default(BGP_EVPN_VNI_NODE);
18263 install_default(BGP_SRV6_NODE);
18264
18265 /* "bgp local-mac" hidden commands. */
18266 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18267 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18268
18269 /* "bgp suppress-fib-pending" global */
18270 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18271
18272 /* bgp route-map delay-timer commands. */
18273 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18274 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18275
18276 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18277
18278 /* bgp fast-convergence command */
18279 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18280 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18281
18282 /* global bgp update-delay command */
18283 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18284 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18285
18286 /* global bgp graceful-shutdown command */
18287 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18288 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18289
18290 /* Dummy commands (Currently not supported) */
18291 install_element(BGP_NODE, &no_synchronization_cmd);
18292 install_element(BGP_NODE, &no_auto_summary_cmd);
18293
18294 /* "router bgp" commands. */
18295 install_element(CONFIG_NODE, &router_bgp_cmd);
18296
18297 /* "no router bgp" commands. */
18298 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18299
18300 /* "bgp session-dscp command */
18301 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18302 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18303
18304 /* "bgp router-id" commands. */
18305 install_element(BGP_NODE, &bgp_router_id_cmd);
18306 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18307
18308 /* "bgp suppress-fib-pending" command */
18309 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18310
18311 /* "bgp cluster-id" commands. */
18312 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18313 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18314
18315 /* "bgp no-rib" commands. */
18316 install_element(CONFIG_NODE, &bgp_norib_cmd);
18317 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18318
18319 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18320
18321 /* "bgp confederation" commands. */
18322 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18323 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18324
18325 /* "bgp confederation peers" commands. */
18326 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18327 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18328
18329 /* bgp max-med command */
18330 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18331 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18332 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18333 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18334 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18335
18336 /* "neighbor role" commands. */
18337 install_element(BGP_NODE, &neighbor_role_cmd);
18338 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18339 install_element(BGP_NODE, &no_neighbor_role_cmd);
18340
18341 /* bgp disable-ebgp-connected-nh-check */
18342 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18343 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18344
18345 /* bgp update-delay command */
18346 install_element(BGP_NODE, &bgp_update_delay_cmd);
18347 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18348
18349 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18350 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18351
18352 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18353 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18354
18355 /* "maximum-paths" commands. */
18356 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18357 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18358 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18359 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18360 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18361 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18362 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18363 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18364 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18365 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18366 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18367 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18368 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18369 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18370 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18371
18372 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18373 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18374 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18375 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18376 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18377 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18378 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18379 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18380 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18381 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18382
18383 /* "timers bgp" commands. */
18384 install_element(BGP_NODE, &bgp_timers_cmd);
18385 install_element(BGP_NODE, &no_bgp_timers_cmd);
18386
18387 /* "minimum-holdtime" commands. */
18388 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18389 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18390
18391 /* route-map delay-timer commands - per instance for backwards compat.
18392 */
18393 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18394 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18395
18396 /* "bgp client-to-client reflection" commands */
18397 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18398 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18399
18400 /* "bgp always-compare-med" commands */
18401 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18402 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18403
18404 /* bgp ebgp-requires-policy */
18405 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18406 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18407
18408 /* bgp suppress-duplicates */
18409 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18410 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18411
18412 /* bgp reject-as-sets */
18413 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18414 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18415
18416 /* "bgp deterministic-med" commands */
18417 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18418 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18419
18420 /* "bgp graceful-restart" command */
18421 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18422 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18423
18424 /* "bgp graceful-restart-disable" command */
18425 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18426 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18427
18428 /* "neighbor a:b:c:d graceful-restart" command */
18429 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18430 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18431
18432 /* "neighbor a:b:c:d graceful-restart-disable" command */
18433 install_element(BGP_NODE,
18434 &bgp_neighbor_graceful_restart_disable_set_cmd);
18435 install_element(BGP_NODE,
18436 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18437
18438 /* "neighbor a:b:c:d graceful-restart-helper" command */
18439 install_element(BGP_NODE,
18440 &bgp_neighbor_graceful_restart_helper_set_cmd);
18441 install_element(BGP_NODE,
18442 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18443
18444 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18445 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18446 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18447 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18448 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18449 install_element(BGP_NODE,
18450 &no_bgp_graceful_restart_select_defer_time_cmd);
18451 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18452 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18453 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18454
18455 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18456 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18457 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18458 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18459
18460 /* "bgp graceful-shutdown" commands */
18461 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18462 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18463
18464 /* "bgp hard-administrative-reset" commands */
18465 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18466
18467 /* "bgp long-lived-graceful-restart" commands */
18468 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18469 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18470
18471 /* "bgp fast-external-failover" commands */
18472 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18473 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18474
18475 /* "bgp bestpath compare-routerid" commands */
18476 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18477 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18478
18479 /* "bgp bestpath as-path ignore" commands */
18480 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18481 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18482
18483 /* "bgp bestpath as-path confed" commands */
18484 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18485 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18486
18487 /* "bgp bestpath as-path multipath-relax" commands */
18488 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18489 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18490
18491 /* "bgp bestpath peer-type multipath-relax" commands */
18492 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18493 install_element(BGP_NODE,
18494 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18495
18496 /* "bgp log-neighbor-changes" commands */
18497 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18498 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18499
18500 /* "bgp bestpath med" commands */
18501 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18502 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18503
18504 /* "bgp bestpath bandwidth" commands */
18505 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18506 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18507
18508 /* "no bgp default <afi>-<safi>" commands. */
18509 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18510
18511 /* "bgp network import-check" commands. */
18512 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18513 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18514 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18515
18516 /* "bgp default local-preference" commands. */
18517 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18518 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18519
18520 /* bgp default show-hostname */
18521 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18522 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18523
18524 /* bgp default show-nexthop-hostname */
18525 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18526 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18527
18528 /* "bgp default subgroup-pkt-queue-max" commands. */
18529 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18530 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18531
18532 /* bgp ibgp-allow-policy-mods command */
18533 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18534 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18535
18536 /* "bgp listen limit" commands. */
18537 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18538 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18539
18540 /* "bgp listen range" commands. */
18541 install_element(BGP_NODE, &bgp_listen_range_cmd);
18542 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18543
18544 /* "bgp default shutdown" command */
18545 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18546
18547 /* "bgp shutdown" commands */
18548 install_element(BGP_NODE, &bgp_shutdown_cmd);
18549 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18550 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18551 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18552
18553 /* "neighbor remote-as" commands. */
18554 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18555 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18556 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18557 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18558 install_element(BGP_NODE,
18559 &neighbor_interface_v6only_config_remote_as_cmd);
18560 install_element(BGP_NODE, &no_neighbor_cmd);
18561 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18562
18563 /* "neighbor peer-group" commands. */
18564 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18565 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18566 install_element(BGP_NODE,
18567 &no_neighbor_interface_peer_group_remote_as_cmd);
18568
18569 /* "neighbor local-as" commands. */
18570 install_element(BGP_NODE, &neighbor_local_as_cmd);
18571 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18572 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18573 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18574
18575 /* "neighbor solo" commands. */
18576 install_element(BGP_NODE, &neighbor_solo_cmd);
18577 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18578
18579 /* "neighbor password" commands. */
18580 install_element(BGP_NODE, &neighbor_password_cmd);
18581 install_element(BGP_NODE, &no_neighbor_password_cmd);
18582
18583 /* "neighbor activate" commands. */
18584 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18585 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18586 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18587 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18588 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18589 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18590 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18591 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18592 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18593 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18594 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18595 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18596
18597 /* "no neighbor activate" commands. */
18598 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18599 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18600 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18601 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18602 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18603 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18604 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18605 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18606 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18607 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18608 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18609 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18610
18611 /* "neighbor peer-group" set commands. */
18612 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18613 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18614 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18615 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18616 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18617 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18618 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18619 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18620 install_element(BGP_FLOWSPECV4_NODE,
18621 &neighbor_set_peer_group_hidden_cmd);
18622 install_element(BGP_FLOWSPECV6_NODE,
18623 &neighbor_set_peer_group_hidden_cmd);
18624
18625 /* "no neighbor peer-group unset" commands. */
18626 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18627 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18628 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18629 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18630 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18631 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18632 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18633 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18634 install_element(BGP_FLOWSPECV4_NODE,
18635 &no_neighbor_set_peer_group_hidden_cmd);
18636 install_element(BGP_FLOWSPECV6_NODE,
18637 &no_neighbor_set_peer_group_hidden_cmd);
18638
18639 /* "neighbor softreconfiguration inbound" commands.*/
18640 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18641 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18642 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18643 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18644 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18645 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18646 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18647 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18648 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18649 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18650 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18651 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18652 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18653 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18654 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18655 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18656 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18657 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18658 install_element(BGP_FLOWSPECV4_NODE,
18659 &neighbor_soft_reconfiguration_cmd);
18660 install_element(BGP_FLOWSPECV4_NODE,
18661 &no_neighbor_soft_reconfiguration_cmd);
18662 install_element(BGP_FLOWSPECV6_NODE,
18663 &neighbor_soft_reconfiguration_cmd);
18664 install_element(BGP_FLOWSPECV6_NODE,
18665 &no_neighbor_soft_reconfiguration_cmd);
18666 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18667 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18668
18669 /* "neighbor attribute-unchanged" commands. */
18670 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18671 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18672 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18673 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18674 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18675 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18676 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18677 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18678 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18679 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18680 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18681 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18682 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18683 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18684 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18685 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18686 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18687 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18688
18689 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18690 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18691
18692 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18693 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18694 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18695 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18696
18697 /* "nexthop-local unchanged" commands */
18698 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18699 install_element(BGP_IPV6_NODE,
18700 &no_neighbor_nexthop_local_unchanged_cmd);
18701
18702 /* "neighbor next-hop-self" commands. */
18703 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18704 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18705 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18706 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18707 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18708 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18709 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18710 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18711 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18712 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18713 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18714 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18715 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18716 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18717 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18718 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18719 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18720 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18721 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18722 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18723
18724 /* "neighbor next-hop-self force" commands. */
18725 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18726 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18727 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18728 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18729 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18730 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18731 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18732 install_element(BGP_IPV4_NODE,
18733 &no_neighbor_nexthop_self_all_hidden_cmd);
18734 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18735 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18736 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18737 install_element(BGP_IPV4M_NODE,
18738 &no_neighbor_nexthop_self_all_hidden_cmd);
18739 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18740 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18741 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18742 install_element(BGP_IPV4L_NODE,
18743 &no_neighbor_nexthop_self_all_hidden_cmd);
18744 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18745 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18746 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18747 install_element(BGP_IPV6_NODE,
18748 &no_neighbor_nexthop_self_all_hidden_cmd);
18749 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18750 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18751 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18752 install_element(BGP_IPV6M_NODE,
18753 &no_neighbor_nexthop_self_all_hidden_cmd);
18754 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18755 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18756 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18757 install_element(BGP_IPV6L_NODE,
18758 &no_neighbor_nexthop_self_all_hidden_cmd);
18759 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18760 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18761 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18762 install_element(BGP_VPNV4_NODE,
18763 &no_neighbor_nexthop_self_all_hidden_cmd);
18764 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18765 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18766 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18767 install_element(BGP_VPNV6_NODE,
18768 &no_neighbor_nexthop_self_all_hidden_cmd);
18769 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18770 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18771
18772 /* "neighbor as-override" commands. */
18773 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18774 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18775 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18776 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18777 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18778 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18779 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18780 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18781 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18782 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18783 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18784 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18785 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18786 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18787 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18788 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18789 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18790 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18791
18792 /* "neighbor remove-private-AS" commands. */
18793 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18794 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18795 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18796 install_element(BGP_NODE,
18797 &no_neighbor_remove_private_as_all_hidden_cmd);
18798 install_element(BGP_NODE,
18799 &neighbor_remove_private_as_replace_as_hidden_cmd);
18800 install_element(BGP_NODE,
18801 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18802 install_element(BGP_NODE,
18803 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18804 install_element(
18805 BGP_NODE,
18806 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18807 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18808 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18809 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18810 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18811 install_element(BGP_IPV4_NODE,
18812 &neighbor_remove_private_as_replace_as_cmd);
18813 install_element(BGP_IPV4_NODE,
18814 &no_neighbor_remove_private_as_replace_as_cmd);
18815 install_element(BGP_IPV4_NODE,
18816 &neighbor_remove_private_as_all_replace_as_cmd);
18817 install_element(BGP_IPV4_NODE,
18818 &no_neighbor_remove_private_as_all_replace_as_cmd);
18819 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18820 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18821 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18822 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18823 install_element(BGP_IPV4M_NODE,
18824 &neighbor_remove_private_as_replace_as_cmd);
18825 install_element(BGP_IPV4M_NODE,
18826 &no_neighbor_remove_private_as_replace_as_cmd);
18827 install_element(BGP_IPV4M_NODE,
18828 &neighbor_remove_private_as_all_replace_as_cmd);
18829 install_element(BGP_IPV4M_NODE,
18830 &no_neighbor_remove_private_as_all_replace_as_cmd);
18831 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18832 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18833 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18834 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18835 install_element(BGP_IPV4L_NODE,
18836 &neighbor_remove_private_as_replace_as_cmd);
18837 install_element(BGP_IPV4L_NODE,
18838 &no_neighbor_remove_private_as_replace_as_cmd);
18839 install_element(BGP_IPV4L_NODE,
18840 &neighbor_remove_private_as_all_replace_as_cmd);
18841 install_element(BGP_IPV4L_NODE,
18842 &no_neighbor_remove_private_as_all_replace_as_cmd);
18843 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18844 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18845 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18846 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18847 install_element(BGP_IPV6_NODE,
18848 &neighbor_remove_private_as_replace_as_cmd);
18849 install_element(BGP_IPV6_NODE,
18850 &no_neighbor_remove_private_as_replace_as_cmd);
18851 install_element(BGP_IPV6_NODE,
18852 &neighbor_remove_private_as_all_replace_as_cmd);
18853 install_element(BGP_IPV6_NODE,
18854 &no_neighbor_remove_private_as_all_replace_as_cmd);
18855 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18856 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18857 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18858 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18859 install_element(BGP_IPV6M_NODE,
18860 &neighbor_remove_private_as_replace_as_cmd);
18861 install_element(BGP_IPV6M_NODE,
18862 &no_neighbor_remove_private_as_replace_as_cmd);
18863 install_element(BGP_IPV6M_NODE,
18864 &neighbor_remove_private_as_all_replace_as_cmd);
18865 install_element(BGP_IPV6M_NODE,
18866 &no_neighbor_remove_private_as_all_replace_as_cmd);
18867 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18868 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18869 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18870 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18871 install_element(BGP_IPV6L_NODE,
18872 &neighbor_remove_private_as_replace_as_cmd);
18873 install_element(BGP_IPV6L_NODE,
18874 &no_neighbor_remove_private_as_replace_as_cmd);
18875 install_element(BGP_IPV6L_NODE,
18876 &neighbor_remove_private_as_all_replace_as_cmd);
18877 install_element(BGP_IPV6L_NODE,
18878 &no_neighbor_remove_private_as_all_replace_as_cmd);
18879 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18880 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18881 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18882 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18883 install_element(BGP_VPNV4_NODE,
18884 &neighbor_remove_private_as_replace_as_cmd);
18885 install_element(BGP_VPNV4_NODE,
18886 &no_neighbor_remove_private_as_replace_as_cmd);
18887 install_element(BGP_VPNV4_NODE,
18888 &neighbor_remove_private_as_all_replace_as_cmd);
18889 install_element(BGP_VPNV4_NODE,
18890 &no_neighbor_remove_private_as_all_replace_as_cmd);
18891 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18892 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18893 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18894 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18895 install_element(BGP_VPNV6_NODE,
18896 &neighbor_remove_private_as_replace_as_cmd);
18897 install_element(BGP_VPNV6_NODE,
18898 &no_neighbor_remove_private_as_replace_as_cmd);
18899 install_element(BGP_VPNV6_NODE,
18900 &neighbor_remove_private_as_all_replace_as_cmd);
18901 install_element(BGP_VPNV6_NODE,
18902 &no_neighbor_remove_private_as_all_replace_as_cmd);
18903
18904 /* "neighbor send-community" commands.*/
18905 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18906 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18907 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18908 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18909 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18910 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18911 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18912 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18913 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18914 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18915 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18916 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18917 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18918 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18919 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18920 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18921 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18922 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18923 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18924 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18925 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18926 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18927 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18928 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18929 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18930 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18931 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18932 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18933 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18934 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18935 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18936 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18937 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18938 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18939 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18940 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18941
18942 /* "neighbor route-reflector" commands.*/
18943 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18944 install_element(BGP_NODE,
18945 &no_neighbor_route_reflector_client_hidden_cmd);
18946 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18947 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18948 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18949 install_element(BGP_IPV4M_NODE,
18950 &no_neighbor_route_reflector_client_cmd);
18951 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18952 install_element(BGP_IPV4L_NODE,
18953 &no_neighbor_route_reflector_client_cmd);
18954 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18955 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18956 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18957 install_element(BGP_IPV6M_NODE,
18958 &no_neighbor_route_reflector_client_cmd);
18959 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18960 install_element(BGP_IPV6L_NODE,
18961 &no_neighbor_route_reflector_client_cmd);
18962 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18963 install_element(BGP_VPNV4_NODE,
18964 &no_neighbor_route_reflector_client_cmd);
18965 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18966 install_element(BGP_VPNV6_NODE,
18967 &no_neighbor_route_reflector_client_cmd);
18968 install_element(BGP_FLOWSPECV4_NODE,
18969 &neighbor_route_reflector_client_cmd);
18970 install_element(BGP_FLOWSPECV4_NODE,
18971 &no_neighbor_route_reflector_client_cmd);
18972 install_element(BGP_FLOWSPECV6_NODE,
18973 &neighbor_route_reflector_client_cmd);
18974 install_element(BGP_FLOWSPECV6_NODE,
18975 &no_neighbor_route_reflector_client_cmd);
18976 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18977 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18978
18979 /* "neighbor route-server" commands.*/
18980 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18981 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18982 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18983 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18984 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18985 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18986 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18987 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18988 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18989 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18990 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18991 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18992 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18993 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18994 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18995 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18996 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18997 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18998 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18999 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19000 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19001 install_element(BGP_FLOWSPECV4_NODE,
19002 &no_neighbor_route_server_client_cmd);
19003 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19004 install_element(BGP_FLOWSPECV6_NODE,
19005 &no_neighbor_route_server_client_cmd);
19006
19007 /* "neighbor disable-addpath-rx" commands. */
19008 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19009 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19010 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19011 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19012 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19013 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19014 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19015 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19016 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19017 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19018 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19019 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19020 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19021 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19022 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19023 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19024
19025 /* "neighbor addpath-tx-all-paths" commands.*/
19026 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19027 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19028 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19029 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19030 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19031 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19032 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19033 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19034 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19035 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19036 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19037 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19038 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19039 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19040 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19041 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19042 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19043 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19044
19045 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19046 install_element(BGP_NODE,
19047 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19048 install_element(BGP_NODE,
19049 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19050 install_element(BGP_IPV4_NODE,
19051 &neighbor_addpath_tx_bestpath_per_as_cmd);
19052 install_element(BGP_IPV4_NODE,
19053 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19054 install_element(BGP_IPV4M_NODE,
19055 &neighbor_addpath_tx_bestpath_per_as_cmd);
19056 install_element(BGP_IPV4M_NODE,
19057 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19058 install_element(BGP_IPV4L_NODE,
19059 &neighbor_addpath_tx_bestpath_per_as_cmd);
19060 install_element(BGP_IPV4L_NODE,
19061 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19062 install_element(BGP_IPV6_NODE,
19063 &neighbor_addpath_tx_bestpath_per_as_cmd);
19064 install_element(BGP_IPV6_NODE,
19065 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19066 install_element(BGP_IPV6M_NODE,
19067 &neighbor_addpath_tx_bestpath_per_as_cmd);
19068 install_element(BGP_IPV6M_NODE,
19069 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19070 install_element(BGP_IPV6L_NODE,
19071 &neighbor_addpath_tx_bestpath_per_as_cmd);
19072 install_element(BGP_IPV6L_NODE,
19073 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19074 install_element(BGP_VPNV4_NODE,
19075 &neighbor_addpath_tx_bestpath_per_as_cmd);
19076 install_element(BGP_VPNV4_NODE,
19077 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19078 install_element(BGP_VPNV6_NODE,
19079 &neighbor_addpath_tx_bestpath_per_as_cmd);
19080 install_element(BGP_VPNV6_NODE,
19081 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19082
19083 /* "neighbor sender-as-path-loop-detection" commands. */
19084 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19085 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19086
19087 /* "neighbor passive" commands. */
19088 install_element(BGP_NODE, &neighbor_passive_cmd);
19089 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19090
19091
19092 /* "neighbor shutdown" commands. */
19093 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19094 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19095 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19096 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19097 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19098 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19099
19100 /* "neighbor capability extended-nexthop" commands.*/
19101 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19102 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19103
19104 /* "neighbor capability orf prefix-list" commands.*/
19105 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19106 install_element(BGP_NODE,
19107 &no_neighbor_capability_orf_prefix_hidden_cmd);
19108 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19109 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19110 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19111 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19112 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19113 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19114 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19115 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19116 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19117 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19118 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19119 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19120
19121 /* "neighbor capability dynamic" commands.*/
19122 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19123 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19124
19125 /* "neighbor dont-capability-negotiate" commands. */
19126 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19127 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19128
19129 /* "neighbor ebgp-multihop" commands. */
19130 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19131 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19132 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19133
19134 /* "neighbor disable-connected-check" commands. */
19135 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19136 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19137
19138 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19139 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19140 install_element(BGP_NODE,
19141 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19142
19143 /* "neighbor extended-optional-parameters" commands. */
19144 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19145 install_element(BGP_NODE,
19146 &no_neighbor_extended_optional_parameters_cmd);
19147
19148 /* "neighbor enforce-first-as" commands. */
19149 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19150 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19151
19152 /* "neighbor description" commands. */
19153 install_element(BGP_NODE, &neighbor_description_cmd);
19154 install_element(BGP_NODE, &no_neighbor_description_cmd);
19155 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19156
19157 /* "neighbor update-source" commands. "*/
19158 install_element(BGP_NODE, &neighbor_update_source_cmd);
19159 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19160
19161 /* "neighbor default-originate" commands. */
19162 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19163 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19164 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19165 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19166 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19167 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19168 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19169 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19170 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19171 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19172 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19173 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19174 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19175 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19176 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19177 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19178 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19179 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19180 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19181 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19182 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19183
19184 /* "neighbor port" commands. */
19185 install_element(BGP_NODE, &neighbor_port_cmd);
19186 install_element(BGP_NODE, &no_neighbor_port_cmd);
19187
19188 /* "neighbor weight" commands. */
19189 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19190 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19191
19192 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19193 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19194 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19195 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19196 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19197 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19198 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19199 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19200 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19201 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19202 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19203 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19204 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19205 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19206 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19207 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19208
19209 /* "neighbor override-capability" commands. */
19210 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19211 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19212
19213 /* "neighbor strict-capability-match" commands. */
19214 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19215 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19216
19217 /* "neighbor timers" commands. */
19218 install_element(BGP_NODE, &neighbor_timers_cmd);
19219 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19220
19221 /* "neighbor timers connect" commands. */
19222 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19223 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19224
19225 /* "neighbor timers delayopen" commands. */
19226 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19227 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19228
19229 /* "neighbor advertisement-interval" commands. */
19230 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19231 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19232
19233 /* "neighbor interface" commands. */
19234 install_element(BGP_NODE, &neighbor_interface_cmd);
19235 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19236
19237 /* "neighbor distribute" commands. */
19238 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19239 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19240 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19241 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19242 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19243 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19244 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19245 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19246 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19247 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19248 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19249 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19250 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19251 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19252 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19253 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19254 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19255 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19256
19257 /* "neighbor prefix-list" commands. */
19258 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19259 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19260 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19261 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19262 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19263 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19264 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19265 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19266 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19267 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19268 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19269 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19270 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19271 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19272 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19273 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19274 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19275 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19276 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19277 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19278 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19279 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19280
19281 /* "neighbor filter-list" commands. */
19282 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19283 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19284 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19285 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19286 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19287 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19288 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19289 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19290 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19291 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19292 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19293 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19294 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19295 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19296 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19297 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19298 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19299 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19300 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19301 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19302 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19303 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19304
19305 /* "neighbor route-map" commands. */
19306 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19307 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19308 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19309 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19310 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19311 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19312 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19313 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19314 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19315 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19316 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19317 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19318 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19319 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19320 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19321 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19322 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19323 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19324 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19325 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19326 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19327 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19328 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19329 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19330
19331 /* "neighbor unsuppress-map" commands. */
19332 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19333 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19334 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19335 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19336 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19337 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19338 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19339 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19340 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19341 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19342 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19343 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19344 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19345 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19346 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19347 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19348 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19349 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19350
19351 /* "neighbor advertise-map" commands. */
19352 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19353 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19354 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19355 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19356 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19357 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19358 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19359 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19360 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19361 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19362
19363 /* neighbor maximum-prefix-out commands. */
19364 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19365 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19366 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19367 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19368 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19369 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19370 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19371 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19372 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19373 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19374 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19375 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19376 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19377 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19378 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19379 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19380 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19381 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19382
19383 /* "neighbor maximum-prefix" commands. */
19384 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19385 install_element(BGP_NODE,
19386 &neighbor_maximum_prefix_threshold_hidden_cmd);
19387 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19388 install_element(BGP_NODE,
19389 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19390 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19391 install_element(BGP_NODE,
19392 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19393 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19394 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19395 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19396 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19397 install_element(BGP_IPV4_NODE,
19398 &neighbor_maximum_prefix_threshold_warning_cmd);
19399 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19400 install_element(BGP_IPV4_NODE,
19401 &neighbor_maximum_prefix_threshold_restart_cmd);
19402 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19403 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19404 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19405 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19406 install_element(BGP_IPV4M_NODE,
19407 &neighbor_maximum_prefix_threshold_warning_cmd);
19408 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19409 install_element(BGP_IPV4M_NODE,
19410 &neighbor_maximum_prefix_threshold_restart_cmd);
19411 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19412 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19413 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19414 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19415 install_element(BGP_IPV4L_NODE,
19416 &neighbor_maximum_prefix_threshold_warning_cmd);
19417 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19418 install_element(BGP_IPV4L_NODE,
19419 &neighbor_maximum_prefix_threshold_restart_cmd);
19420 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19421 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19422 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19423 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19424 install_element(BGP_IPV6_NODE,
19425 &neighbor_maximum_prefix_threshold_warning_cmd);
19426 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19427 install_element(BGP_IPV6_NODE,
19428 &neighbor_maximum_prefix_threshold_restart_cmd);
19429 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19430 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19431 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19432 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19433 install_element(BGP_IPV6M_NODE,
19434 &neighbor_maximum_prefix_threshold_warning_cmd);
19435 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19436 install_element(BGP_IPV6M_NODE,
19437 &neighbor_maximum_prefix_threshold_restart_cmd);
19438 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19439 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19440 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19441 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19442 install_element(BGP_IPV6L_NODE,
19443 &neighbor_maximum_prefix_threshold_warning_cmd);
19444 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19445 install_element(BGP_IPV6L_NODE,
19446 &neighbor_maximum_prefix_threshold_restart_cmd);
19447 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19448 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19449 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19450 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19451 install_element(BGP_VPNV4_NODE,
19452 &neighbor_maximum_prefix_threshold_warning_cmd);
19453 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19454 install_element(BGP_VPNV4_NODE,
19455 &neighbor_maximum_prefix_threshold_restart_cmd);
19456 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19457 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19458 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19459 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19460 install_element(BGP_VPNV6_NODE,
19461 &neighbor_maximum_prefix_threshold_warning_cmd);
19462 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19463 install_element(BGP_VPNV6_NODE,
19464 &neighbor_maximum_prefix_threshold_restart_cmd);
19465 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19466
19467 /* "neighbor allowas-in" */
19468 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19469 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19470 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19471 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19472 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19473 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19474 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19475 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19476 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19477 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19478 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19479 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19480 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19481 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19482 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19483 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19484 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19485 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19486 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19487 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19488
19489 /* "neighbor soo" */
19490 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19491 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19492 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19493 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19494 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19495 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19496 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19497 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19498 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19499 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19500 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19501 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19502 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19503 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19504 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19505 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19506 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19507 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19508
19509 /* address-family commands. */
19510 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19511 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19512 #ifdef KEEP_OLD_VPN_COMMANDS
19513 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19514 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19515 #endif /* KEEP_OLD_VPN_COMMANDS */
19516
19517 install_element(BGP_NODE, &address_family_evpn_cmd);
19518
19519 /* "exit-address-family" command. */
19520 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19521 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19522 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19523 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19524 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19525 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19526 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19527 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19528 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19529 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19530 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19531
19532 /* BGP retain all route-target */
19533 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19534 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19535
19536 /* "clear ip bgp commands" */
19537 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19538
19539 /* clear ip bgp prefix */
19540 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19541 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19542 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19543
19544 /* "show [ip] bgp summary" commands. */
19545 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19546 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19547 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19548 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19549 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19550 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19551 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19552
19553 /* "show [ip] bgp neighbors" commands. */
19554 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19555
19556 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19557
19558 /* "show [ip] bgp peer-group" commands. */
19559 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19560
19561 /* "show [ip] bgp paths" commands. */
19562 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19563
19564 /* "show [ip] bgp community" commands. */
19565 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19566
19567 /* "show ip bgp large-community" commands. */
19568 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19569 /* "show [ip] bgp attribute-info" commands. */
19570 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19571 /* "show [ip] bgp route-leak" command */
19572 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19573
19574 /* "redistribute" commands. */
19575 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19576 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19577 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19578 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19579 install_element(BGP_NODE,
19580 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19581 install_element(BGP_NODE,
19582 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19583 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19584 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19585 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19586 install_element(BGP_NODE,
19587 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19588 install_element(BGP_NODE,
19589 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19590 install_element(BGP_NODE,
19591 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19592 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19593 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19594 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19595 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19596 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19597 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19598 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19599 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19600 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19601 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19602 install_element(BGP_IPV4_NODE,
19603 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19604 install_element(BGP_IPV4_NODE,
19605 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19606 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19607 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19608 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19609 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19610 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19611 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19612
19613 /* import|export vpn [route-map RMAP_NAME] */
19614 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19615 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19616
19617 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19618 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19619
19620 /* ttl_security commands */
19621 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19622 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19623
19624 /* "bgp tcp-keepalive" commands */
19625 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
19626 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
19627
19628 /* "show [ip] bgp memory" commands. */
19629 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19630
19631 /* "show bgp martian next-hop" */
19632 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19633
19634 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19635
19636 /* "show [ip] bgp views" commands. */
19637 install_element(VIEW_NODE, &show_bgp_views_cmd);
19638
19639 /* "show [ip] bgp vrfs" commands. */
19640 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19641
19642 /* Community-list. */
19643 community_list_vty();
19644
19645 community_alias_vty();
19646
19647 /* vpn-policy commands */
19648 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19649 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19650 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19651 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19652 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19653 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19654 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19655 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19656 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19657 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19658 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19659 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19660
19661 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19662 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19663
19664 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19665 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19666 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19667 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19668 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19669 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19670 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19671 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19672 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19673 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19674
19675 /* tcp-mss command */
19676 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19677 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19678
19679 /* srv6 commands */
19680 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19681 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19682 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19683 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19684 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19685 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19686 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19687
19688 bgp_vty_if_init();
19689 }
19690
19691 #include "memory.h"
19692 #include "bgp_regex.h"
19693 #include "bgp_clist.h"
19694 #include "bgp_ecommunity.h"
19695
19696 /* VTY functions. */
19697
19698 /* Direction value to string conversion. */
19699 static const char *community_direct_str(int direct)
19700 {
19701 switch (direct) {
19702 case COMMUNITY_DENY:
19703 return "deny";
19704 case COMMUNITY_PERMIT:
19705 return "permit";
19706 default:
19707 return "unknown";
19708 }
19709 }
19710
19711 /* Display error string. */
19712 static void community_list_perror(struct vty *vty, int ret)
19713 {
19714 switch (ret) {
19715 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19716 vty_out(vty, "%% Can't find community-list\n");
19717 break;
19718 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19719 vty_out(vty, "%% Malformed community-list value\n");
19720 break;
19721 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19722 vty_out(vty,
19723 "%% Community name conflict, previously defined as standard community\n");
19724 break;
19725 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19726 vty_out(vty,
19727 "%% Community name conflict, previously defined as expanded community\n");
19728 break;
19729 }
19730 }
19731
19732 /* "community-list" keyword help string. */
19733 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19734
19735 /*community-list standard */
19736 DEFUN (community_list_standard,
19737 bgp_community_list_standard_cmd,
19738 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19739 BGP_STR
19740 COMMUNITY_LIST_STR
19741 "Community list number (standard)\n"
19742 "Add an standard community-list entry\n"
19743 "Community list name\n"
19744 "Sequence number of an entry\n"
19745 "Sequence number\n"
19746 "Specify community to reject\n"
19747 "Specify community to accept\n"
19748 COMMUNITY_VAL_STR)
19749 {
19750 char *cl_name_or_number = NULL;
19751 char *seq = NULL;
19752 int direct = 0;
19753 int style = COMMUNITY_LIST_STANDARD;
19754 int idx = 0;
19755
19756 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19757 seq = argv[idx]->arg;
19758
19759 idx = 0;
19760 argv_find(argv, argc, "(1-99)", &idx);
19761 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19762 cl_name_or_number = argv[idx]->arg;
19763 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19764 : COMMUNITY_DENY;
19765 argv_find(argv, argc, "AA:NN", &idx);
19766 char *str = argv_concat(argv, argc, idx);
19767
19768 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19769 direct, style);
19770
19771 XFREE(MTYPE_TMP, str);
19772
19773 if (ret < 0) {
19774 /* Display error string. */
19775 community_list_perror(vty, ret);
19776 return CMD_WARNING_CONFIG_FAILED;
19777 }
19778
19779 return CMD_SUCCESS;
19780 }
19781
19782 DEFUN (no_community_list_standard_all,
19783 no_bgp_community_list_standard_all_cmd,
19784 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19785 NO_STR
19786 BGP_STR
19787 COMMUNITY_LIST_STR
19788 "Community list number (standard)\n"
19789 "Add an standard community-list entry\n"
19790 "Community list name\n"
19791 "Sequence number of an entry\n"
19792 "Sequence number\n"
19793 "Specify community to reject\n"
19794 "Specify community to accept\n"
19795 COMMUNITY_VAL_STR)
19796 {
19797 char *cl_name_or_number = NULL;
19798 char *str = NULL;
19799 int direct = 0;
19800 int style = COMMUNITY_LIST_STANDARD;
19801 char *seq = NULL;
19802 int idx = 0;
19803
19804 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19805 seq = argv[idx]->arg;
19806
19807 idx = 0;
19808 argv_find(argv, argc, "permit", &idx);
19809 argv_find(argv, argc, "deny", &idx);
19810
19811 if (idx) {
19812 direct = argv_find(argv, argc, "permit", &idx)
19813 ? COMMUNITY_PERMIT
19814 : COMMUNITY_DENY;
19815
19816 idx = 0;
19817 argv_find(argv, argc, "AA:NN", &idx);
19818 str = argv_concat(argv, argc, idx);
19819 }
19820
19821 idx = 0;
19822 argv_find(argv, argc, "(1-99)", &idx);
19823 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19824 cl_name_or_number = argv[idx]->arg;
19825
19826 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19827 direct, style);
19828
19829 XFREE(MTYPE_TMP, str);
19830
19831 if (ret < 0) {
19832 community_list_perror(vty, ret);
19833 return CMD_WARNING_CONFIG_FAILED;
19834 }
19835
19836 return CMD_SUCCESS;
19837 }
19838
19839 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19840 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19841 NO_STR BGP_STR COMMUNITY_LIST_STR
19842 "Community list number (standard)\n"
19843 "Add an standard community-list entry\n"
19844 "Community list name\n")
19845
19846 /*community-list expanded */
19847 DEFUN (community_list_expanded_all,
19848 bgp_community_list_expanded_all_cmd,
19849 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19850 BGP_STR
19851 COMMUNITY_LIST_STR
19852 "Community list number (expanded)\n"
19853 "Add an expanded community-list entry\n"
19854 "Community list name\n"
19855 "Sequence number of an entry\n"
19856 "Sequence number\n"
19857 "Specify community to reject\n"
19858 "Specify community to accept\n"
19859 COMMUNITY_VAL_STR)
19860 {
19861 char *cl_name_or_number = NULL;
19862 char *seq = NULL;
19863 int direct = 0;
19864 int style = COMMUNITY_LIST_EXPANDED;
19865 int idx = 0;
19866
19867 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19868 seq = argv[idx]->arg;
19869
19870 idx = 0;
19871
19872 argv_find(argv, argc, "(100-500)", &idx);
19873 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19874 cl_name_or_number = argv[idx]->arg;
19875 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19876 : COMMUNITY_DENY;
19877 argv_find(argv, argc, "AA:NN", &idx);
19878 char *str = argv_concat(argv, argc, idx);
19879
19880 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19881 direct, style);
19882
19883 XFREE(MTYPE_TMP, str);
19884
19885 if (ret < 0) {
19886 /* Display error string. */
19887 community_list_perror(vty, ret);
19888 return CMD_WARNING_CONFIG_FAILED;
19889 }
19890
19891 return CMD_SUCCESS;
19892 }
19893
19894 DEFUN (no_community_list_expanded_all,
19895 no_bgp_community_list_expanded_all_cmd,
19896 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19897 NO_STR
19898 BGP_STR
19899 COMMUNITY_LIST_STR
19900 "Community list number (expanded)\n"
19901 "Add an expanded community-list entry\n"
19902 "Community list name\n"
19903 "Sequence number of an entry\n"
19904 "Sequence number\n"
19905 "Specify community to reject\n"
19906 "Specify community to accept\n"
19907 COMMUNITY_VAL_STR)
19908 {
19909 char *cl_name_or_number = NULL;
19910 char *seq = NULL;
19911 char *str = NULL;
19912 int direct = 0;
19913 int style = COMMUNITY_LIST_EXPANDED;
19914 int idx = 0;
19915
19916 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19917 seq = argv[idx]->arg;
19918
19919 idx = 0;
19920 argv_find(argv, argc, "permit", &idx);
19921 argv_find(argv, argc, "deny", &idx);
19922
19923 if (idx) {
19924 direct = argv_find(argv, argc, "permit", &idx)
19925 ? COMMUNITY_PERMIT
19926 : COMMUNITY_DENY;
19927
19928 idx = 0;
19929 argv_find(argv, argc, "AA:NN", &idx);
19930 str = argv_concat(argv, argc, idx);
19931 }
19932
19933 idx = 0;
19934 argv_find(argv, argc, "(100-500)", &idx);
19935 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19936 cl_name_or_number = argv[idx]->arg;
19937
19938 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19939 direct, style);
19940
19941 XFREE(MTYPE_TMP, str);
19942
19943 if (ret < 0) {
19944 community_list_perror(vty, ret);
19945 return CMD_WARNING_CONFIG_FAILED;
19946 }
19947
19948 return CMD_SUCCESS;
19949 }
19950
19951 ALIAS(no_community_list_expanded_all,
19952 no_bgp_community_list_expanded_all_list_cmd,
19953 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19954 NO_STR BGP_STR COMMUNITY_LIST_STR
19955 "Community list number (expanded)\n"
19956 "Add an expanded community-list entry\n"
19957 "Community list name\n")
19958
19959 /* Return configuration string of community-list entry. */
19960 static const char *community_list_config_str(struct community_entry *entry)
19961 {
19962 const char *str;
19963
19964 if (entry->any)
19965 str = "";
19966 else {
19967 if (entry->style == COMMUNITY_LIST_STANDARD)
19968 str = community_str(entry->u.com, false, false);
19969 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19970 str = lcommunity_str(entry->u.lcom, false, false);
19971 else
19972 str = entry->config;
19973 }
19974 return str;
19975 }
19976
19977 static void community_list_show(struct vty *vty, struct community_list *list)
19978 {
19979 struct community_entry *entry;
19980
19981 for (entry = list->head; entry; entry = entry->next) {
19982 if (entry == list->head) {
19983 if (all_digit(list->name))
19984 vty_out(vty, "Community %s list %s\n",
19985 entry->style == COMMUNITY_LIST_STANDARD
19986 ? "standard"
19987 : "(expanded) access",
19988 list->name);
19989 else
19990 vty_out(vty, "Named Community %s list %s\n",
19991 entry->style == COMMUNITY_LIST_STANDARD
19992 ? "standard"
19993 : "expanded",
19994 list->name);
19995 }
19996 if (entry->any)
19997 vty_out(vty, " %s\n",
19998 community_direct_str(entry->direct));
19999 else
20000 vty_out(vty, " %s %s\n",
20001 community_direct_str(entry->direct),
20002 community_list_config_str(entry));
20003 }
20004 }
20005
20006 DEFUN (show_community_list,
20007 show_bgp_community_list_cmd,
20008 "show bgp community-list",
20009 SHOW_STR
20010 BGP_STR
20011 "List community-list\n")
20012 {
20013 struct community_list *list;
20014 struct community_list_master *cm;
20015
20016 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20017 if (!cm)
20018 return CMD_SUCCESS;
20019
20020 for (list = cm->num.head; list; list = list->next)
20021 community_list_show(vty, list);
20022
20023 for (list = cm->str.head; list; list = list->next)
20024 community_list_show(vty, list);
20025
20026 return CMD_SUCCESS;
20027 }
20028
20029 DEFUN (show_community_list_arg,
20030 show_bgp_community_list_arg_cmd,
20031 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20032 SHOW_STR
20033 BGP_STR
20034 "List community-list\n"
20035 "Community-list number\n"
20036 "Community-list name\n"
20037 "Detailed information on community-list\n")
20038 {
20039 int idx_comm_list = 3;
20040 struct community_list *list;
20041
20042 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20043 COMMUNITY_LIST_MASTER);
20044 if (!list) {
20045 vty_out(vty, "%% Can't find community-list\n");
20046 return CMD_WARNING;
20047 }
20048
20049 community_list_show(vty, list);
20050
20051 return CMD_SUCCESS;
20052 }
20053
20054 /*
20055 * Large Community code.
20056 */
20057 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20058 struct cmd_token **argv, int style,
20059 int reject_all_digit_name)
20060 {
20061 int ret;
20062 int direct;
20063 char *str;
20064 int idx = 0;
20065 char *cl_name;
20066 char *seq = NULL;
20067
20068 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20069 seq = argv[idx]->arg;
20070
20071 idx = 0;
20072 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20073 : COMMUNITY_DENY;
20074
20075 /* All digit name check. */
20076 idx = 0;
20077 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20078 argv_find(argv, argc, "(1-99)", &idx);
20079 argv_find(argv, argc, "(100-500)", &idx);
20080 cl_name = argv[idx]->arg;
20081 if (reject_all_digit_name && all_digit(cl_name)) {
20082 vty_out(vty, "%% Community name cannot have all digits\n");
20083 return CMD_WARNING_CONFIG_FAILED;
20084 }
20085
20086 idx = 0;
20087 argv_find(argv, argc, "AA:BB:CC", &idx);
20088 argv_find(argv, argc, "LINE", &idx);
20089 /* Concat community string argument. */
20090 if (idx)
20091 str = argv_concat(argv, argc, idx);
20092 else
20093 str = NULL;
20094
20095 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20096
20097 /* Free temporary community list string allocated by
20098 argv_concat(). */
20099 XFREE(MTYPE_TMP, str);
20100
20101 if (ret < 0) {
20102 community_list_perror(vty, ret);
20103 return CMD_WARNING_CONFIG_FAILED;
20104 }
20105 return CMD_SUCCESS;
20106 }
20107
20108 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20109 struct cmd_token **argv, int style)
20110 {
20111 int ret;
20112 int direct = 0;
20113 char *str = NULL;
20114 int idx = 0;
20115 char *seq = NULL;
20116
20117 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20118 seq = argv[idx]->arg;
20119
20120 idx = 0;
20121 argv_find(argv, argc, "permit", &idx);
20122 argv_find(argv, argc, "deny", &idx);
20123
20124 if (idx) {
20125 /* Check the list direct. */
20126 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20127 direct = COMMUNITY_PERMIT;
20128 else
20129 direct = COMMUNITY_DENY;
20130
20131 idx = 0;
20132 argv_find(argv, argc, "LINE", &idx);
20133 argv_find(argv, argc, "AA:AA:NN", &idx);
20134 /* Concat community string argument. */
20135 str = argv_concat(argv, argc, idx);
20136 }
20137
20138 idx = 0;
20139 argv_find(argv, argc, "(1-99)", &idx);
20140 argv_find(argv, argc, "(100-500)", &idx);
20141 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20142
20143 /* Unset community list. */
20144 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20145 style);
20146
20147 /* Free temporary community list string allocated by
20148 argv_concat(). */
20149 XFREE(MTYPE_TMP, str);
20150
20151 if (ret < 0) {
20152 community_list_perror(vty, ret);
20153 return CMD_WARNING_CONFIG_FAILED;
20154 }
20155
20156 return CMD_SUCCESS;
20157 }
20158
20159 /* "large-community-list" keyword help string. */
20160 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20161 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20162
20163 DEFUN (lcommunity_list_standard,
20164 bgp_lcommunity_list_standard_cmd,
20165 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20166 BGP_STR
20167 LCOMMUNITY_LIST_STR
20168 "Large Community list number (standard)\n"
20169 "Sequence number of an entry\n"
20170 "Sequence number\n"
20171 "Specify large community to reject\n"
20172 "Specify large community to accept\n"
20173 LCOMMUNITY_VAL_STR)
20174 {
20175 return lcommunity_list_set_vty(vty, argc, argv,
20176 LARGE_COMMUNITY_LIST_STANDARD, 0);
20177 }
20178
20179 DEFUN (lcommunity_list_expanded,
20180 bgp_lcommunity_list_expanded_cmd,
20181 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20182 BGP_STR
20183 LCOMMUNITY_LIST_STR
20184 "Large Community list number (expanded)\n"
20185 "Sequence number of an entry\n"
20186 "Sequence number\n"
20187 "Specify large community to reject\n"
20188 "Specify large community to accept\n"
20189 "An ordered list as a regular-expression\n")
20190 {
20191 return lcommunity_list_set_vty(vty, argc, argv,
20192 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20193 }
20194
20195 DEFUN (lcommunity_list_name_standard,
20196 bgp_lcommunity_list_name_standard_cmd,
20197 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20198 BGP_STR
20199 LCOMMUNITY_LIST_STR
20200 "Specify standard large-community-list\n"
20201 "Large Community list name\n"
20202 "Sequence number of an entry\n"
20203 "Sequence number\n"
20204 "Specify large community to reject\n"
20205 "Specify large community to accept\n"
20206 LCOMMUNITY_VAL_STR)
20207 {
20208 return lcommunity_list_set_vty(vty, argc, argv,
20209 LARGE_COMMUNITY_LIST_STANDARD, 1);
20210 }
20211
20212 DEFUN (lcommunity_list_name_expanded,
20213 bgp_lcommunity_list_name_expanded_cmd,
20214 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20215 BGP_STR
20216 LCOMMUNITY_LIST_STR
20217 "Specify expanded large-community-list\n"
20218 "Large Community list name\n"
20219 "Sequence number of an entry\n"
20220 "Sequence number\n"
20221 "Specify large community to reject\n"
20222 "Specify large community to accept\n"
20223 "An ordered list as a regular-expression\n")
20224 {
20225 return lcommunity_list_set_vty(vty, argc, argv,
20226 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20227 }
20228
20229 DEFUN (no_lcommunity_list_all,
20230 no_bgp_lcommunity_list_all_cmd,
20231 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20232 NO_STR
20233 BGP_STR
20234 LCOMMUNITY_LIST_STR
20235 "Large Community list number (standard)\n"
20236 "Large Community list number (expanded)\n"
20237 "Large Community list name\n")
20238 {
20239 return lcommunity_list_unset_vty(vty, argc, argv,
20240 LARGE_COMMUNITY_LIST_STANDARD);
20241 }
20242
20243 DEFUN (no_lcommunity_list_name_standard_all,
20244 no_bgp_lcommunity_list_name_standard_all_cmd,
20245 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20246 NO_STR
20247 BGP_STR
20248 LCOMMUNITY_LIST_STR
20249 "Specify standard large-community-list\n"
20250 "Large Community list name\n")
20251 {
20252 return lcommunity_list_unset_vty(vty, argc, argv,
20253 LARGE_COMMUNITY_LIST_STANDARD);
20254 }
20255
20256 DEFUN (no_lcommunity_list_name_expanded_all,
20257 no_bgp_lcommunity_list_name_expanded_all_cmd,
20258 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20259 NO_STR
20260 BGP_STR
20261 LCOMMUNITY_LIST_STR
20262 "Specify expanded large-community-list\n"
20263 "Large Community list name\n")
20264 {
20265 return lcommunity_list_unset_vty(vty, argc, argv,
20266 LARGE_COMMUNITY_LIST_EXPANDED);
20267 }
20268
20269 DEFUN (no_lcommunity_list_standard,
20270 no_bgp_lcommunity_list_standard_cmd,
20271 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20272 NO_STR
20273 BGP_STR
20274 LCOMMUNITY_LIST_STR
20275 "Large Community list number (standard)\n"
20276 "Sequence number of an entry\n"
20277 "Sequence number\n"
20278 "Specify large community to reject\n"
20279 "Specify large community to accept\n"
20280 LCOMMUNITY_VAL_STR)
20281 {
20282 return lcommunity_list_unset_vty(vty, argc, argv,
20283 LARGE_COMMUNITY_LIST_STANDARD);
20284 }
20285
20286 DEFUN (no_lcommunity_list_expanded,
20287 no_bgp_lcommunity_list_expanded_cmd,
20288 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20289 NO_STR
20290 BGP_STR
20291 LCOMMUNITY_LIST_STR
20292 "Large Community list number (expanded)\n"
20293 "Sequence number of an entry\n"
20294 "Sequence number\n"
20295 "Specify large community to reject\n"
20296 "Specify large community to accept\n"
20297 "An ordered list as a regular-expression\n")
20298 {
20299 return lcommunity_list_unset_vty(vty, argc, argv,
20300 LARGE_COMMUNITY_LIST_EXPANDED);
20301 }
20302
20303 DEFUN (no_lcommunity_list_name_standard,
20304 no_bgp_lcommunity_list_name_standard_cmd,
20305 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20306 NO_STR
20307 BGP_STR
20308 LCOMMUNITY_LIST_STR
20309 "Specify standard large-community-list\n"
20310 "Large Community list name\n"
20311 "Sequence number of an entry\n"
20312 "Sequence number\n"
20313 "Specify large community to reject\n"
20314 "Specify large community to accept\n"
20315 LCOMMUNITY_VAL_STR)
20316 {
20317 return lcommunity_list_unset_vty(vty, argc, argv,
20318 LARGE_COMMUNITY_LIST_STANDARD);
20319 }
20320
20321 DEFUN (no_lcommunity_list_name_expanded,
20322 no_bgp_lcommunity_list_name_expanded_cmd,
20323 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20324 NO_STR
20325 BGP_STR
20326 LCOMMUNITY_LIST_STR
20327 "Specify expanded large-community-list\n"
20328 "Large community list name\n"
20329 "Sequence number of an entry\n"
20330 "Sequence number\n"
20331 "Specify large community to reject\n"
20332 "Specify large community to accept\n"
20333 "An ordered list as a regular-expression\n")
20334 {
20335 return lcommunity_list_unset_vty(vty, argc, argv,
20336 LARGE_COMMUNITY_LIST_EXPANDED);
20337 }
20338
20339 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20340 {
20341 struct community_entry *entry;
20342
20343 for (entry = list->head; entry; entry = entry->next) {
20344 if (entry == list->head) {
20345 if (all_digit(list->name))
20346 vty_out(vty, "Large community %s list %s\n",
20347 entry->style ==
20348 LARGE_COMMUNITY_LIST_STANDARD
20349 ? "standard"
20350 : "(expanded) access",
20351 list->name);
20352 else
20353 vty_out(vty,
20354 "Named large community %s list %s\n",
20355 entry->style ==
20356 LARGE_COMMUNITY_LIST_STANDARD
20357 ? "standard"
20358 : "expanded",
20359 list->name);
20360 }
20361 if (entry->any)
20362 vty_out(vty, " %s\n",
20363 community_direct_str(entry->direct));
20364 else
20365 vty_out(vty, " %s %s\n",
20366 community_direct_str(entry->direct),
20367 community_list_config_str(entry));
20368 }
20369 }
20370
20371 DEFUN (show_lcommunity_list,
20372 show_bgp_lcommunity_list_cmd,
20373 "show bgp large-community-list",
20374 SHOW_STR
20375 BGP_STR
20376 "List large-community list\n")
20377 {
20378 struct community_list *list;
20379 struct community_list_master *cm;
20380
20381 cm = community_list_master_lookup(bgp_clist,
20382 LARGE_COMMUNITY_LIST_MASTER);
20383 if (!cm)
20384 return CMD_SUCCESS;
20385
20386 for (list = cm->num.head; list; list = list->next)
20387 lcommunity_list_show(vty, list);
20388
20389 for (list = cm->str.head; list; list = list->next)
20390 lcommunity_list_show(vty, list);
20391
20392 return CMD_SUCCESS;
20393 }
20394
20395 DEFUN (show_lcommunity_list_arg,
20396 show_bgp_lcommunity_list_arg_cmd,
20397 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20398 SHOW_STR
20399 BGP_STR
20400 "List large-community list\n"
20401 "Large-community-list number\n"
20402 "Large-community-list name\n"
20403 "Detailed information on large-community-list\n")
20404 {
20405 struct community_list *list;
20406
20407 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20408 LARGE_COMMUNITY_LIST_MASTER);
20409 if (!list) {
20410 vty_out(vty, "%% Can't find large-community-list\n");
20411 return CMD_WARNING;
20412 }
20413
20414 lcommunity_list_show(vty, list);
20415
20416 return CMD_SUCCESS;
20417 }
20418
20419 /* "extcommunity-list" keyword help string. */
20420 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20421 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20422
20423 DEFUN (extcommunity_list_standard,
20424 bgp_extcommunity_list_standard_cmd,
20425 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20426 BGP_STR
20427 EXTCOMMUNITY_LIST_STR
20428 "Extended Community list number (standard)\n"
20429 "Specify standard extcommunity-list\n"
20430 "Community list name\n"
20431 "Sequence number of an entry\n"
20432 "Sequence number\n"
20433 "Specify community to reject\n"
20434 "Specify community to accept\n"
20435 EXTCOMMUNITY_VAL_STR)
20436 {
20437 int style = EXTCOMMUNITY_LIST_STANDARD;
20438 int direct = 0;
20439 char *cl_number_or_name = NULL;
20440 char *seq = NULL;
20441
20442 int idx = 0;
20443
20444 argv_find(argv, argc, "(1-99)", &idx);
20445 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20446 cl_number_or_name = argv[idx]->arg;
20447
20448 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20449 seq = argv[idx]->arg;
20450
20451 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20452 : COMMUNITY_DENY;
20453 argv_find(argv, argc, "AA:NN", &idx);
20454 char *str = argv_concat(argv, argc, idx);
20455
20456 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20457 direct, style);
20458
20459 XFREE(MTYPE_TMP, str);
20460
20461 if (ret < 0) {
20462 community_list_perror(vty, ret);
20463 return CMD_WARNING_CONFIG_FAILED;
20464 }
20465
20466 return CMD_SUCCESS;
20467 }
20468
20469 DEFUN (extcommunity_list_name_expanded,
20470 bgp_extcommunity_list_name_expanded_cmd,
20471 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20472 BGP_STR
20473 EXTCOMMUNITY_LIST_STR
20474 "Extended Community list number (expanded)\n"
20475 "Specify expanded extcommunity-list\n"
20476 "Extended Community list name\n"
20477 "Sequence number of an entry\n"
20478 "Sequence number\n"
20479 "Specify community to reject\n"
20480 "Specify community to accept\n"
20481 "An ordered list as a regular-expression\n")
20482 {
20483 int style = EXTCOMMUNITY_LIST_EXPANDED;
20484 int direct = 0;
20485 char *cl_number_or_name = NULL;
20486 char *seq = NULL;
20487 int idx = 0;
20488
20489 argv_find(argv, argc, "(100-500)", &idx);
20490 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20491 cl_number_or_name = argv[idx]->arg;
20492
20493 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20494 seq = argv[idx]->arg;
20495
20496 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20497 : COMMUNITY_DENY;
20498 argv_find(argv, argc, "LINE", &idx);
20499 char *str = argv_concat(argv, argc, idx);
20500
20501 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20502 direct, style);
20503
20504 XFREE(MTYPE_TMP, str);
20505
20506 if (ret < 0) {
20507 community_list_perror(vty, ret);
20508 return CMD_WARNING_CONFIG_FAILED;
20509 }
20510
20511 return CMD_SUCCESS;
20512 }
20513
20514 DEFUN (no_extcommunity_list_standard_all,
20515 no_bgp_extcommunity_list_standard_all_cmd,
20516 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20517 NO_STR
20518 BGP_STR
20519 EXTCOMMUNITY_LIST_STR
20520 "Extended Community list number (standard)\n"
20521 "Specify standard extcommunity-list\n"
20522 "Community list name\n"
20523 "Sequence number of an entry\n"
20524 "Sequence number\n"
20525 "Specify community to reject\n"
20526 "Specify community to accept\n"
20527 EXTCOMMUNITY_VAL_STR)
20528 {
20529 int style = EXTCOMMUNITY_LIST_STANDARD;
20530 int direct = 0;
20531 char *cl_number_or_name = NULL;
20532 char *str = NULL;
20533 char *seq = NULL;
20534 int idx = 0;
20535
20536 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20537 seq = argv[idx]->arg;
20538
20539 idx = 0;
20540 argv_find(argv, argc, "permit", &idx);
20541 argv_find(argv, argc, "deny", &idx);
20542 if (idx) {
20543 direct = argv_find(argv, argc, "permit", &idx)
20544 ? COMMUNITY_PERMIT
20545 : COMMUNITY_DENY;
20546
20547 idx = 0;
20548 argv_find(argv, argc, "AA:NN", &idx);
20549 str = argv_concat(argv, argc, idx);
20550 }
20551
20552 idx = 0;
20553 argv_find(argv, argc, "(1-99)", &idx);
20554 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20555 cl_number_or_name = argv[idx]->arg;
20556
20557 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20558 seq, direct, style);
20559
20560 XFREE(MTYPE_TMP, str);
20561
20562 if (ret < 0) {
20563 community_list_perror(vty, ret);
20564 return CMD_WARNING_CONFIG_FAILED;
20565 }
20566
20567 return CMD_SUCCESS;
20568 }
20569
20570 ALIAS(no_extcommunity_list_standard_all,
20571 no_bgp_extcommunity_list_standard_all_list_cmd,
20572 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20573 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20574 "Extended Community list number (standard)\n"
20575 "Specify standard extcommunity-list\n"
20576 "Community list name\n")
20577
20578 DEFUN (no_extcommunity_list_expanded_all,
20579 no_bgp_extcommunity_list_expanded_all_cmd,
20580 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20581 NO_STR
20582 BGP_STR
20583 EXTCOMMUNITY_LIST_STR
20584 "Extended Community list number (expanded)\n"
20585 "Specify expanded extcommunity-list\n"
20586 "Extended Community list name\n"
20587 "Sequence number of an entry\n"
20588 "Sequence number\n"
20589 "Specify community to reject\n"
20590 "Specify community to accept\n"
20591 "An ordered list as a regular-expression\n")
20592 {
20593 int style = EXTCOMMUNITY_LIST_EXPANDED;
20594 int direct = 0;
20595 char *cl_number_or_name = NULL;
20596 char *str = NULL;
20597 char *seq = NULL;
20598 int idx = 0;
20599
20600 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20601 seq = argv[idx]->arg;
20602
20603 idx = 0;
20604 argv_find(argv, argc, "permit", &idx);
20605 argv_find(argv, argc, "deny", &idx);
20606
20607 if (idx) {
20608 direct = argv_find(argv, argc, "permit", &idx)
20609 ? COMMUNITY_PERMIT
20610 : COMMUNITY_DENY;
20611
20612 idx = 0;
20613 argv_find(argv, argc, "LINE", &idx);
20614 str = argv_concat(argv, argc, idx);
20615 }
20616
20617 idx = 0;
20618 argv_find(argv, argc, "(100-500)", &idx);
20619 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20620 cl_number_or_name = argv[idx]->arg;
20621
20622 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20623 seq, direct, style);
20624
20625 XFREE(MTYPE_TMP, str);
20626
20627 if (ret < 0) {
20628 community_list_perror(vty, ret);
20629 return CMD_WARNING_CONFIG_FAILED;
20630 }
20631
20632 return CMD_SUCCESS;
20633 }
20634
20635 ALIAS(no_extcommunity_list_expanded_all,
20636 no_bgp_extcommunity_list_expanded_all_list_cmd,
20637 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20638 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20639 "Extended Community list number (expanded)\n"
20640 "Specify expanded extcommunity-list\n"
20641 "Extended Community list name\n")
20642
20643 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20644 {
20645 struct community_entry *entry;
20646
20647 for (entry = list->head; entry; entry = entry->next) {
20648 if (entry == list->head) {
20649 if (all_digit(list->name))
20650 vty_out(vty, "Extended community %s list %s\n",
20651 entry->style == EXTCOMMUNITY_LIST_STANDARD
20652 ? "standard"
20653 : "(expanded) access",
20654 list->name);
20655 else
20656 vty_out(vty,
20657 "Named extended community %s list %s\n",
20658 entry->style == EXTCOMMUNITY_LIST_STANDARD
20659 ? "standard"
20660 : "expanded",
20661 list->name);
20662 }
20663 if (entry->any)
20664 vty_out(vty, " %s\n",
20665 community_direct_str(entry->direct));
20666 else
20667 vty_out(vty, " %s %s\n",
20668 community_direct_str(entry->direct),
20669 community_list_config_str(entry));
20670 }
20671 }
20672
20673 DEFUN (show_extcommunity_list,
20674 show_bgp_extcommunity_list_cmd,
20675 "show bgp extcommunity-list",
20676 SHOW_STR
20677 BGP_STR
20678 "List extended-community list\n")
20679 {
20680 struct community_list *list;
20681 struct community_list_master *cm;
20682
20683 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20684 if (!cm)
20685 return CMD_SUCCESS;
20686
20687 for (list = cm->num.head; list; list = list->next)
20688 extcommunity_list_show(vty, list);
20689
20690 for (list = cm->str.head; list; list = list->next)
20691 extcommunity_list_show(vty, list);
20692
20693 return CMD_SUCCESS;
20694 }
20695
20696 DEFUN (show_extcommunity_list_arg,
20697 show_bgp_extcommunity_list_arg_cmd,
20698 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20699 SHOW_STR
20700 BGP_STR
20701 "List extended-community list\n"
20702 "Extcommunity-list number\n"
20703 "Extcommunity-list name\n"
20704 "Detailed information on extcommunity-list\n")
20705 {
20706 int idx_comm_list = 3;
20707 struct community_list *list;
20708
20709 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20710 EXTCOMMUNITY_LIST_MASTER);
20711 if (!list) {
20712 vty_out(vty, "%% Can't find extcommunity-list\n");
20713 return CMD_WARNING;
20714 }
20715
20716 extcommunity_list_show(vty, list);
20717
20718 return CMD_SUCCESS;
20719 }
20720
20721 /* Display community-list and extcommunity-list configuration. */
20722 static int community_list_config_write(struct vty *vty)
20723 {
20724 struct community_list *list;
20725 struct community_entry *entry;
20726 struct community_list_master *cm;
20727 int write = 0;
20728
20729 /* Community-list. */
20730 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20731
20732 for (list = cm->num.head; list; list = list->next)
20733 for (entry = list->head; entry; entry = entry->next) {
20734 vty_out(vty,
20735 "bgp community-list %s seq %" PRId64 " %s %s\n",
20736 list->name, entry->seq,
20737 community_direct_str(entry->direct),
20738 community_list_config_str(entry));
20739 write++;
20740 }
20741 for (list = cm->str.head; list; list = list->next)
20742 for (entry = list->head; entry; entry = entry->next) {
20743 vty_out(vty,
20744 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20745 entry->style == COMMUNITY_LIST_STANDARD
20746 ? "standard"
20747 : "expanded",
20748 list->name, entry->seq,
20749 community_direct_str(entry->direct),
20750 community_list_config_str(entry));
20751 write++;
20752 }
20753
20754 /* Extcommunity-list. */
20755 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20756
20757 for (list = cm->num.head; list; list = list->next)
20758 for (entry = list->head; entry; entry = entry->next) {
20759 vty_out(vty,
20760 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20761 list->name, entry->seq,
20762 community_direct_str(entry->direct),
20763 community_list_config_str(entry));
20764 write++;
20765 }
20766 for (list = cm->str.head; list; list = list->next)
20767 for (entry = list->head; entry; entry = entry->next) {
20768 vty_out(vty,
20769 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20770 entry->style == EXTCOMMUNITY_LIST_STANDARD
20771 ? "standard"
20772 : "expanded",
20773 list->name, entry->seq,
20774 community_direct_str(entry->direct),
20775 community_list_config_str(entry));
20776 write++;
20777 }
20778
20779
20780 /* lcommunity-list. */
20781 cm = community_list_master_lookup(bgp_clist,
20782 LARGE_COMMUNITY_LIST_MASTER);
20783
20784 for (list = cm->num.head; list; list = list->next)
20785 for (entry = list->head; entry; entry = entry->next) {
20786 vty_out(vty,
20787 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20788 list->name, entry->seq,
20789 community_direct_str(entry->direct),
20790 community_list_config_str(entry));
20791 write++;
20792 }
20793 for (list = cm->str.head; list; list = list->next)
20794 for (entry = list->head; entry; entry = entry->next) {
20795 vty_out(vty,
20796 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20797
20798 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20799 ? "standard"
20800 : "expanded",
20801 list->name, entry->seq, community_direct_str(entry->direct),
20802 community_list_config_str(entry));
20803 write++;
20804 }
20805
20806 return write;
20807 }
20808
20809 static int community_list_config_write(struct vty *vty);
20810 static struct cmd_node community_list_node = {
20811 .name = "community list",
20812 .node = COMMUNITY_LIST_NODE,
20813 .prompt = "",
20814 .config_write = community_list_config_write,
20815 };
20816
20817 static void community_list_vty(void)
20818 {
20819 install_node(&community_list_node);
20820
20821 /* Community-list. */
20822 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20823 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20824 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20825 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20826 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20827 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20828 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20829 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20830
20831 /* Extcommunity-list. */
20832 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20833 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20834 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20835 install_element(CONFIG_NODE,
20836 &no_bgp_extcommunity_list_standard_all_list_cmd);
20837 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20838 install_element(CONFIG_NODE,
20839 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20840 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20841 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20842
20843 /* Large Community List */
20844 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20845 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20846 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20847 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20848 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20849 install_element(CONFIG_NODE,
20850 &no_bgp_lcommunity_list_name_standard_all_cmd);
20851 install_element(CONFIG_NODE,
20852 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20853 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20854 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20855 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20856 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20857 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20858 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20859
20860 bgp_community_list_command_completion_setup();
20861 }
20862
20863 static struct cmd_node community_alias_node = {
20864 .name = "community alias",
20865 .node = COMMUNITY_ALIAS_NODE,
20866 .prompt = "",
20867 .config_write = bgp_community_alias_write,
20868 };
20869
20870 void community_alias_vty(void)
20871 {
20872 install_node(&community_alias_node);
20873
20874 /* Community-list. */
20875 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20876
20877 bgp_community_alias_command_completion_setup();
20878 }