]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[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
161 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
162 enum show_type type,
163 const char *ip_str,
164 afi_t afi, bool use_json);
165
166 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
167 {
168 switch (afi) {
169 case AFI_IP:
170 switch (safi) {
171 case SAFI_UNICAST:
172 return BGP_IPV4_NODE;
173 case SAFI_MULTICAST:
174 return BGP_IPV4M_NODE;
175 case SAFI_LABELED_UNICAST:
176 return BGP_IPV4L_NODE;
177 case SAFI_MPLS_VPN:
178 return BGP_VPNV4_NODE;
179 case SAFI_FLOWSPEC:
180 return BGP_FLOWSPECV4_NODE;
181 case SAFI_UNSPEC:
182 case SAFI_ENCAP:
183 case SAFI_EVPN:
184 case SAFI_MAX:
185 /* not expected */
186 return BGP_IPV4_NODE;
187 }
188 break;
189 case AFI_IP6:
190 switch (safi) {
191 case SAFI_UNICAST:
192 return BGP_IPV6_NODE;
193 case SAFI_MULTICAST:
194 return BGP_IPV6M_NODE;
195 case SAFI_LABELED_UNICAST:
196 return BGP_IPV6L_NODE;
197 case SAFI_MPLS_VPN:
198 return BGP_VPNV6_NODE;
199 case SAFI_FLOWSPEC:
200 return BGP_FLOWSPECV6_NODE;
201 case SAFI_UNSPEC:
202 case SAFI_ENCAP:
203 case SAFI_EVPN:
204 case SAFI_MAX:
205 /* not expected and the return value seems wrong */
206 return BGP_IPV4_NODE;
207 }
208 break;
209 case AFI_L2VPN:
210 return BGP_EVPN_NODE;
211 case AFI_UNSPEC:
212 case AFI_MAX:
213 // We should never be here but to clarify the switch statement..
214 return BGP_IPV4_NODE;
215 }
216
217 // Impossible to happen
218 return BGP_IPV4_NODE;
219 }
220
221 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
222 {
223 if (afi == AFI_IP) {
224 if (safi == SAFI_UNICAST)
225 return "IPv4 Unicast";
226 if (safi == SAFI_MULTICAST)
227 return "IPv4 Multicast";
228 if (safi == SAFI_LABELED_UNICAST)
229 return "IPv4 Labeled Unicast";
230 if (safi == SAFI_MPLS_VPN)
231 return "IPv4 VPN";
232 if (safi == SAFI_ENCAP)
233 return "IPv4 Encap";
234 if (safi == SAFI_FLOWSPEC)
235 return "IPv4 Flowspec";
236 } else if (afi == AFI_IP6) {
237 if (safi == SAFI_UNICAST)
238 return "IPv6 Unicast";
239 if (safi == SAFI_MULTICAST)
240 return "IPv6 Multicast";
241 if (safi == SAFI_LABELED_UNICAST)
242 return "IPv6 Labeled Unicast";
243 if (safi == SAFI_MPLS_VPN)
244 return "IPv6 VPN";
245 if (safi == SAFI_ENCAP)
246 return "IPv6 Encap";
247 if (safi == SAFI_FLOWSPEC)
248 return "IPv6 Flowspec";
249 } else if (afi == AFI_L2VPN) {
250 if (safi == SAFI_EVPN)
251 return "L2VPN EVPN";
252 }
253
254 return "Unknown";
255 }
256
257 /*
258 * Please note that we have intentionally camelCased
259 * the return strings here. So if you want
260 * to use this function, please ensure you
261 * are doing this within json output
262 */
263 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
264 {
265 if (afi == AFI_IP) {
266 if (safi == SAFI_UNICAST)
267 return "ipv4Unicast";
268 if (safi == SAFI_MULTICAST)
269 return "ipv4Multicast";
270 if (safi == SAFI_LABELED_UNICAST)
271 return "ipv4LabeledUnicast";
272 if (safi == SAFI_MPLS_VPN)
273 return "ipv4Vpn";
274 if (safi == SAFI_ENCAP)
275 return "ipv4Encap";
276 if (safi == SAFI_FLOWSPEC)
277 return "ipv4Flowspec";
278 } else if (afi == AFI_IP6) {
279 if (safi == SAFI_UNICAST)
280 return "ipv6Unicast";
281 if (safi == SAFI_MULTICAST)
282 return "ipv6Multicast";
283 if (safi == SAFI_LABELED_UNICAST)
284 return "ipv6LabeledUnicast";
285 if (safi == SAFI_MPLS_VPN)
286 return "ipv6Vpn";
287 if (safi == SAFI_ENCAP)
288 return "ipv6Encap";
289 if (safi == SAFI_FLOWSPEC)
290 return "ipv6Flowspec";
291 } else if (afi == AFI_L2VPN) {
292 if (safi == SAFI_EVPN)
293 return "l2VpnEvpn";
294 }
295
296 return "Unknown";
297 }
298
299 /* unset srv6 locator */
300 static int bgp_srv6_locator_unset(struct bgp *bgp)
301 {
302 int ret;
303 struct listnode *node, *nnode;
304 struct srv6_locator_chunk *chunk;
305 struct bgp_srv6_function *func;
306 struct bgp *bgp_vrf;
307
308 /* release chunk notification via ZAPI */
309 ret = bgp_zebra_srv6_manager_release_locator_chunk(
310 bgp->srv6_locator_name);
311 if (ret < 0)
312 return -1;
313
314 /* refresh chunks */
315 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
316 listnode_delete(bgp->srv6_locator_chunks, chunk);
317 srv6_locator_chunk_free(&chunk);
318 }
319
320 /* refresh functions */
321 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
322 listnode_delete(bgp->srv6_functions, func);
323 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
324 }
325
326 /* refresh tovpn_sid */
327 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
328 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
329 continue;
330
331 /* refresh vpnv4 tovpn_sid */
332 XFREE(MTYPE_BGP_SRV6_SID,
333 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
334
335 /* refresh vpnv6 tovpn_sid */
336 XFREE(MTYPE_BGP_SRV6_SID,
337 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
338
339 /* refresh per-vrf tovpn_sid */
340 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
341 }
342
343 /* update vpn bgp processes */
344 vpn_leak_postchange_all();
345
346 /* refresh tovpn_sid_locator */
347 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
348 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
349 continue;
350
351 /* refresh vpnv4 tovpn_sid_locator */
352 srv6_locator_chunk_free(
353 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
354
355 /* refresh vpnv6 tovpn_sid_locator */
356 srv6_locator_chunk_free(
357 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
358
359 /* refresh per-vrf tovpn_sid_locator */
360 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
361 }
362
363 /* clear locator name */
364 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
365
366 return 0;
367 }
368
369 /* Utility function to get address family from current node. */
370 afi_t bgp_node_afi(struct vty *vty)
371 {
372 afi_t afi;
373 switch (vty->node) {
374 case BGP_IPV6_NODE:
375 case BGP_IPV6M_NODE:
376 case BGP_IPV6L_NODE:
377 case BGP_VPNV6_NODE:
378 case BGP_FLOWSPECV6_NODE:
379 afi = AFI_IP6;
380 break;
381 case BGP_EVPN_NODE:
382 afi = AFI_L2VPN;
383 break;
384 default:
385 afi = AFI_IP;
386 break;
387 }
388 return afi;
389 }
390
391 /* Utility function to get subsequent address family from current
392 node. */
393 safi_t bgp_node_safi(struct vty *vty)
394 {
395 safi_t safi;
396 switch (vty->node) {
397 case BGP_VPNV4_NODE:
398 case BGP_VPNV6_NODE:
399 safi = SAFI_MPLS_VPN;
400 break;
401 case BGP_IPV4M_NODE:
402 case BGP_IPV6M_NODE:
403 safi = SAFI_MULTICAST;
404 break;
405 case BGP_EVPN_NODE:
406 safi = SAFI_EVPN;
407 break;
408 case BGP_IPV4L_NODE:
409 case BGP_IPV6L_NODE:
410 safi = SAFI_LABELED_UNICAST;
411 break;
412 case BGP_FLOWSPECV4_NODE:
413 case BGP_FLOWSPECV6_NODE:
414 safi = SAFI_FLOWSPEC;
415 break;
416 default:
417 safi = SAFI_UNICAST;
418 break;
419 }
420 return safi;
421 }
422
423 /**
424 * Converts an AFI in string form to afi_t
425 *
426 * @param afi string, one of
427 * - "ipv4"
428 * - "ipv6"
429 * - "l2vpn"
430 * @return the corresponding afi_t
431 */
432 afi_t bgp_vty_afi_from_str(const char *afi_str)
433 {
434 afi_t afi = AFI_MAX; /* unknown */
435 if (strmatch(afi_str, "ipv4"))
436 afi = AFI_IP;
437 else if (strmatch(afi_str, "ipv6"))
438 afi = AFI_IP6;
439 else if (strmatch(afi_str, "l2vpn"))
440 afi = AFI_L2VPN;
441 return afi;
442 }
443
444 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
445 afi_t *afi)
446 {
447 int ret = 0;
448 if (argv_find(argv, argc, "ipv4", index)) {
449 ret = 1;
450 if (afi)
451 *afi = AFI_IP;
452 } else if (argv_find(argv, argc, "ipv6", index)) {
453 ret = 1;
454 if (afi)
455 *afi = AFI_IP6;
456 } else if (argv_find(argv, argc, "l2vpn", index)) {
457 ret = 1;
458 if (afi)
459 *afi = AFI_L2VPN;
460 }
461 return ret;
462 }
463
464 /* supports <unicast|multicast|vpn|labeled-unicast> */
465 safi_t bgp_vty_safi_from_str(const char *safi_str)
466 {
467 safi_t safi = SAFI_MAX; /* unknown */
468 if (strmatch(safi_str, "multicast"))
469 safi = SAFI_MULTICAST;
470 else if (strmatch(safi_str, "unicast"))
471 safi = SAFI_UNICAST;
472 else if (strmatch(safi_str, "vpn"))
473 safi = SAFI_MPLS_VPN;
474 else if (strmatch(safi_str, "evpn"))
475 safi = SAFI_EVPN;
476 else if (strmatch(safi_str, "labeled-unicast"))
477 safi = SAFI_LABELED_UNICAST;
478 else if (strmatch(safi_str, "flowspec"))
479 safi = SAFI_FLOWSPEC;
480 return safi;
481 }
482
483 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
484 safi_t *safi)
485 {
486 int ret = 0;
487 if (argv_find(argv, argc, "unicast", index)) {
488 ret = 1;
489 if (safi)
490 *safi = SAFI_UNICAST;
491 } else if (argv_find(argv, argc, "multicast", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_MULTICAST;
495 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_LABELED_UNICAST;
499 } else if (argv_find(argv, argc, "vpn", index)) {
500 ret = 1;
501 if (safi)
502 *safi = SAFI_MPLS_VPN;
503 } else if (argv_find(argv, argc, "evpn", index)) {
504 ret = 1;
505 if (safi)
506 *safi = SAFI_EVPN;
507 } else if (argv_find(argv, argc, "flowspec", index)) {
508 ret = 1;
509 if (safi)
510 *safi = SAFI_FLOWSPEC;
511 }
512 return ret;
513 }
514
515 /*
516 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
517 *
518 * afi
519 * address-family identifier
520 *
521 * safi
522 * subsequent address-family identifier
523 *
524 * Returns:
525 * default_af string corresponding to the supplied afi/safi pair.
526 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
527 * return -1.
528 */
529 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
530 {
531 switch (afi) {
532 case AFI_IP:
533 switch (safi) {
534 case SAFI_UNICAST:
535 return "ipv4-unicast";
536 case SAFI_MULTICAST:
537 return "ipv4-multicast";
538 case SAFI_MPLS_VPN:
539 return "ipv4-vpn";
540 case SAFI_ENCAP:
541 return "ipv4-encap";
542 case SAFI_LABELED_UNICAST:
543 return "ipv4-labeled-unicast";
544 case SAFI_FLOWSPEC:
545 return "ipv4-flowspec";
546 case SAFI_UNSPEC:
547 case SAFI_EVPN:
548 case SAFI_MAX:
549 return "unknown-afi/safi";
550 }
551 break;
552 case AFI_IP6:
553 switch (safi) {
554 case SAFI_UNICAST:
555 return "ipv6-unicast";
556 case SAFI_MULTICAST:
557 return "ipv6-multicast";
558 case SAFI_MPLS_VPN:
559 return "ipv6-vpn";
560 case SAFI_ENCAP:
561 return "ipv6-encap";
562 case SAFI_LABELED_UNICAST:
563 return "ipv6-labeled-unicast";
564 case SAFI_FLOWSPEC:
565 return "ipv6-flowspec";
566 case SAFI_UNSPEC:
567 case SAFI_EVPN:
568 case SAFI_MAX:
569 return "unknown-afi/safi";
570 }
571 break;
572 case AFI_L2VPN:
573 switch (safi) {
574 case SAFI_EVPN:
575 return "l2vpn-evpn";
576 case SAFI_UNICAST:
577 case SAFI_MULTICAST:
578 case SAFI_MPLS_VPN:
579 case SAFI_ENCAP:
580 case SAFI_LABELED_UNICAST:
581 case SAFI_FLOWSPEC:
582 case SAFI_UNSPEC:
583 case SAFI_MAX:
584 return "unknown-afi/safi";
585 }
586 break;
587 case AFI_UNSPEC:
588 case AFI_MAX:
589 return "unknown-afi/safi";
590 }
591 /* all AFIs are accounted for above, so this shouldn't happen */
592
593 assert(!"Reached end of function where we did not expect to");
594 }
595
596 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
597 enum bgp_instance_type inst_type)
598 {
599 int ret = bgp_get(bgp, as, name, inst_type);
600
601 if (ret == BGP_CREATED) {
602 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
603 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
604
605 if (DFLT_BGP_IMPORT_CHECK)
606 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
607 if (DFLT_BGP_SHOW_HOSTNAME)
608 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
609 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
610 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
611 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
612 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
613 if (DFLT_BGP_DETERMINISTIC_MED)
614 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
615 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
616 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
617 if (DFLT_BGP_SUPPRESS_DUPLICATES)
618 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
619 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
620 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
621 if (DFLT_BGP_HARD_ADMIN_RESET)
622 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
623
624 ret = BGP_SUCCESS;
625 }
626 return ret;
627 }
628
629 /*
630 * bgp_vty_find_and_parse_afi_safi_bgp
631 *
632 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
633 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
634 * to appropriate values for the calling function. This is to allow the
635 * calling function to make decisions appropriate for the show command
636 * that is being parsed.
637 *
638 * The show commands are generally of the form:
639 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
640 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
641 *
642 * Since we use argv_find if the show command in particular doesn't have:
643 * [ip]
644 * [<view|vrf> VIEWVRFNAME]
645 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
646 * The command parsing should still be ok.
647 *
648 * vty -> The vty for the command so we can output some useful data in
649 * the event of a parse error in the vrf.
650 * argv -> The command tokens
651 * argc -> How many command tokens we have
652 * idx -> The current place in the command, generally should be 0 for this
653 * function
654 * afi -> The parsed afi if it was included in the show command, returned here
655 * safi -> The parsed safi if it was included in the show command, returned here
656 * bgp -> Pointer to the bgp data structure we need to fill in.
657 * use_json -> json is configured or not
658 *
659 * The function returns the correct location in the parse tree for the
660 * last token found.
661 *
662 * Returns 0 for failure to parse correctly, else the idx position of where
663 * it found the last token.
664 */
665 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
666 struct cmd_token **argv, int argc,
667 int *idx, afi_t *afi, safi_t *safi,
668 struct bgp **bgp, bool use_json)
669 {
670 char *vrf_name = NULL;
671
672 assert(afi);
673 assert(safi);
674 assert(bgp);
675
676 if (argv_find(argv, argc, "ip", idx))
677 *afi = AFI_IP;
678
679 if (argv_find(argv, argc, "view", idx))
680 vrf_name = argv[*idx + 1]->arg;
681 else if (argv_find(argv, argc, "vrf", idx)) {
682 vrf_name = argv[*idx + 1]->arg;
683 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
684 vrf_name = NULL;
685 }
686 if (vrf_name) {
687 if (strmatch(vrf_name, "all"))
688 *bgp = NULL;
689 else {
690 *bgp = bgp_lookup_by_name(vrf_name);
691 if (!*bgp) {
692 if (use_json) {
693 json_object *json = NULL;
694 json = json_object_new_object();
695 json_object_string_add(
696 json, "warning",
697 "View/Vrf is unknown");
698 vty_json(vty, json);
699 }
700 else
701 vty_out(vty, "View/Vrf %s is unknown\n",
702 vrf_name);
703 *idx = 0;
704 return 0;
705 }
706 }
707 } else {
708 *bgp = bgp_get_default();
709 if (!*bgp) {
710 if (use_json) {
711 json_object *json = NULL;
712 json = json_object_new_object();
713 json_object_string_add(
714 json, "warning",
715 "Default BGP instance not found");
716 vty_json(vty, json);
717 }
718 else
719 vty_out(vty,
720 "Default BGP instance not found\n");
721 *idx = 0;
722 return 0;
723 }
724 }
725
726 if (argv_find_and_parse_afi(argv, argc, idx, afi))
727 argv_find_and_parse_safi(argv, argc, idx, safi);
728
729 *idx += 1;
730 return *idx;
731 }
732
733 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
734 {
735 struct interface *ifp = NULL;
736 struct listnode *node;
737 struct bgp_listener *listener;
738 union sockunion all_su;
739
740 if (su->sa.sa_family == AF_INET) {
741 (void)str2sockunion("0.0.0.0", &all_su);
742 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
743 } else if (su->sa.sa_family == AF_INET6) {
744 (void)str2sockunion("::", &all_su);
745 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
746 su->sin6.sin6_scope_id,
747 bgp->vrf_id);
748 }
749
750 if (ifp) {
751 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
752 if (sockunion_family(su) !=
753 sockunion_family(&listener->su))
754 continue;
755
756 /* If 0.0.0.0/:: is a listener, then treat as self and
757 * reject.
758 */
759 if (!sockunion_cmp(&listener->su, su) ||
760 !sockunion_cmp(&listener->su, &all_su))
761 return true;
762 }
763 }
764
765 return false;
766 }
767
768 /* Utility function for looking up peer from VTY. */
769 /* This is used only for configuration, so disallow if attempted on
770 * a dynamic neighbor.
771 */
772 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
773 {
774 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
775 int ret;
776 union sockunion su;
777 struct peer *peer;
778
779 if (!bgp) {
780 return NULL;
781 }
782
783 ret = str2sockunion(ip_str, &su);
784 if (ret < 0) {
785 peer = peer_lookup_by_conf_if(bgp, ip_str);
786 if (!peer) {
787 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
788 == NULL) {
789 vty_out(vty,
790 "%% Malformed address or name: %s\n",
791 ip_str);
792 return NULL;
793 }
794 }
795 } else {
796 peer = peer_lookup(bgp, &su);
797 if (!peer) {
798 vty_out(vty,
799 "%% Specify remote-as or peer-group commands first\n");
800 return NULL;
801 }
802 if (peer_dynamic_neighbor(peer)) {
803 vty_out(vty,
804 "%% Operation not allowed on a dynamic neighbor\n");
805 return NULL;
806 }
807 }
808 return peer;
809 }
810
811 /* Utility function for looking up peer or peer group. */
812 /* This is used only for configuration, so disallow if attempted on
813 * a dynamic neighbor.
814 */
815 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
816 {
817 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
818 int ret;
819 union sockunion su;
820 struct peer *peer = NULL;
821 struct peer_group *group = NULL;
822
823 if (!bgp) {
824 return NULL;
825 }
826
827 ret = str2sockunion(peer_str, &su);
828 if (ret == 0) {
829 /* IP address, locate peer. */
830 peer = peer_lookup(bgp, &su);
831 } else {
832 /* Not IP, could match either peer configured on interface or a
833 * group. */
834 peer = peer_lookup_by_conf_if(bgp, peer_str);
835 if (!peer)
836 group = peer_group_lookup(bgp, peer_str);
837 }
838
839 if (peer) {
840 if (peer_dynamic_neighbor(peer)) {
841 zlog_warn(
842 "%pBP: Operation not allowed on a dynamic neighbor",
843 peer);
844 vty_out(vty,
845 "%% Operation not allowed on a dynamic neighbor\n");
846 return NULL;
847 }
848
849 return peer;
850 }
851
852 if (group)
853 return group->conf;
854
855 zlog_warn("Specify remote-as or peer-group commands first before: %s",
856 vty->buf);
857 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
858
859 return NULL;
860 }
861
862 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
863 {
864 const char *str = NULL;
865
866 switch (ret) {
867 case BGP_SUCCESS:
868 case BGP_CREATED:
869 case BGP_GR_NO_OPERATION:
870 break;
871 case BGP_ERR_INVALID_VALUE:
872 str = "Invalid value";
873 break;
874 case BGP_ERR_INVALID_FLAG:
875 str = "Invalid flag";
876 break;
877 case BGP_ERR_PEER_GROUP_SHUTDOWN:
878 str = "Peer-group has been shutdown. Activate the peer-group first";
879 break;
880 case BGP_ERR_PEER_FLAG_CONFLICT:
881 str = "Can't set override-capability and strict-capability-match at the same time";
882 break;
883 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
884 str = "Specify remote-as or peer-group remote AS first";
885 break;
886 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
887 str = "Cannot change the peer-group. Deconfigure first";
888 break;
889 case BGP_ERR_PEER_GROUP_MISMATCH:
890 str = "Peer is not a member of this peer-group";
891 break;
892 case BGP_ERR_PEER_FILTER_CONFLICT:
893 str = "Prefix/distribute list can not co-exist";
894 break;
895 case BGP_ERR_NOT_INTERNAL_PEER:
896 str = "Invalid command. Not an internal neighbor";
897 break;
898 case BGP_ERR_REMOVE_PRIVATE_AS:
899 str = "remove-private-AS cannot be configured for IBGP peers";
900 break;
901 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
902 str = "Cannot have local-as same as BGP AS number";
903 break;
904 case BGP_ERR_TCPSIG_FAILED:
905 str = "Error while applying TCP-Sig to session(s)";
906 break;
907 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
908 str = "ebgp-multihop and ttl-security cannot be configured together";
909 break;
910 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
911 str = "ttl-security only allowed for EBGP peers";
912 break;
913 case BGP_ERR_AS_OVERRIDE:
914 str = "as-override cannot be configured for IBGP peers";
915 break;
916 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
917 str = "Invalid limit for number of dynamic neighbors";
918 break;
919 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
920 str = "Dynamic neighbor listen range already exists";
921 break;
922 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
923 str = "Operation not allowed on a dynamic neighbor";
924 break;
925 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
926 str = "Operation not allowed on a directly connected neighbor";
927 break;
928 case BGP_ERR_PEER_SAFI_CONFLICT:
929 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
930 break;
931 case BGP_ERR_GR_INVALID_CMD:
932 str = "The Graceful Restart command used is not valid at this moment.";
933 break;
934 case BGP_ERR_GR_OPERATION_FAILED:
935 str = "The Graceful Restart Operation failed due to an err.";
936 break;
937 case BGP_ERR_PEER_GROUP_MEMBER:
938 str = "Peer-group member cannot override remote-as of peer-group.";
939 break;
940 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
941 str = "Peer-group members must be all internal or all external.";
942 break;
943 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
944 str = "Range specified cannot be deleted because it is not part of current config.";
945 break;
946 case BGP_ERR_INSTANCE_MISMATCH:
947 str = "Instance specified does not match the current instance.";
948 break;
949 case BGP_ERR_NO_INTERFACE_CONFIG:
950 str = "Interface specified is not being used for interface based peer.";
951 break;
952 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
953 str = "No configuration already specified for soft reconfiguration.";
954 break;
955 case BGP_ERR_AS_MISMATCH:
956 str = "BGP is already running.";
957 break;
958 case BGP_ERR_AF_UNCONFIGURED:
959 str = "AFI/SAFI specified is not currently configured.";
960 break;
961 case BGP_ERR_INVALID_AS:
962 str = "Confederation AS specified is the same AS as our AS.";
963 break;
964 case BGP_ERR_INVALID_ROLE_NAME:
965 str = "Invalid role name";
966 break;
967 case BGP_ERR_INVALID_INTERNAL_ROLE:
968 str = "External roles can be set only on eBGP session";
969 break;
970 }
971 if (str) {
972 vty_out(vty, "%% %s\n", str);
973 return CMD_WARNING_CONFIG_FAILED;
974 }
975 return CMD_SUCCESS;
976 }
977
978 /* BGP clear sort. */
979 enum clear_sort {
980 clear_all,
981 clear_peer,
982 clear_group,
983 clear_external,
984 clear_as
985 };
986
987 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
988 safi_t safi, int error)
989 {
990 switch (error) {
991 case BGP_ERR_AF_UNCONFIGURED:
992 if (vty)
993 vty_out(vty,
994 "%% BGP: Enable %s address family for the neighbor %s\n",
995 get_afi_safi_str(afi, safi, false), peer->host);
996 else
997 zlog_warn(
998 "%% BGP: Enable %s address family for the neighbor %s",
999 get_afi_safi_str(afi, safi, false), peer->host);
1000 break;
1001 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1002 if (vty)
1003 vty_out(vty,
1004 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
1005 peer->host);
1006 else
1007 zlog_warn(
1008 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
1009 peer->host);
1010 break;
1011 default:
1012 break;
1013 }
1014 }
1015
1016 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
1017 struct listnode **nnode, enum bgp_clear_type stype)
1018 {
1019 int ret = 0;
1020 struct peer_af *paf;
1021
1022 /* if afi/.safi not specified, spin thru all of them */
1023 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1024 afi_t tmp_afi;
1025 safi_t tmp_safi;
1026 enum bgp_af_index index;
1027
1028 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1029 paf = peer->peer_af_array[index];
1030 if (!paf)
1031 continue;
1032
1033 if (paf && paf->subgroup)
1034 SET_FLAG(paf->subgroup->sflags,
1035 SUBGRP_STATUS_FORCE_UPDATES);
1036
1037 tmp_afi = paf->afi;
1038 tmp_safi = paf->safi;
1039 if (!peer->afc[tmp_afi][tmp_safi])
1040 continue;
1041
1042 if (stype == BGP_CLEAR_SOFT_NONE)
1043 ret = peer_clear(peer, nnode);
1044 else
1045 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1046 stype);
1047 }
1048 /* if afi specified and safi not, spin thru safis on this afi */
1049 } else if (safi == SAFI_UNSPEC) {
1050 safi_t tmp_safi;
1051
1052 for (tmp_safi = SAFI_UNICAST;
1053 tmp_safi < SAFI_MAX; tmp_safi++) {
1054 if (!peer->afc[afi][tmp_safi])
1055 continue;
1056
1057 paf = peer_af_find(peer, afi, tmp_safi);
1058 if (paf && paf->subgroup)
1059 SET_FLAG(paf->subgroup->sflags,
1060 SUBGRP_STATUS_FORCE_UPDATES);
1061
1062 if (stype == BGP_CLEAR_SOFT_NONE)
1063 ret = peer_clear(peer, nnode);
1064 else
1065 ret = peer_clear_soft(peer, afi,
1066 tmp_safi, stype);
1067 }
1068 /* both afi/safi specified, let the caller know if not defined */
1069 } else {
1070 if (!peer->afc[afi][safi])
1071 return 1;
1072
1073 paf = peer_af_find(peer, afi, safi);
1074 if (paf && paf->subgroup)
1075 SET_FLAG(paf->subgroup->sflags,
1076 SUBGRP_STATUS_FORCE_UPDATES);
1077
1078 if (stype == BGP_CLEAR_SOFT_NONE)
1079 ret = peer_clear(peer, nnode);
1080 else
1081 ret = peer_clear_soft(peer, afi, safi, stype);
1082 }
1083
1084 return ret;
1085 }
1086
1087 /* `clear ip bgp' functions. */
1088 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1089 enum clear_sort sort, enum bgp_clear_type stype,
1090 const char *arg)
1091 {
1092 int ret = 0;
1093 bool found = false;
1094 struct peer *peer;
1095
1096 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1097
1098 /* Clear all neighbors. */
1099 /*
1100 * Pass along pointer to next node to peer_clear() when walking all
1101 * nodes on the BGP instance as that may get freed if it is a
1102 * doppelganger
1103 */
1104 if (sort == clear_all) {
1105 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1106
1107 bgp_peer_gr_flags_update(peer);
1108
1109 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1110 gr_router_detected = true;
1111
1112 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1113 stype);
1114
1115 if (ret < 0)
1116 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1117 }
1118
1119 if (gr_router_detected
1120 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1121 bgp_zebra_send_capabilities(bgp, false);
1122 } else if (!gr_router_detected
1123 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1124 bgp_zebra_send_capabilities(bgp, true);
1125 }
1126
1127 /* This is to apply read-only mode on this clear. */
1128 if (stype == BGP_CLEAR_SOFT_NONE)
1129 bgp->update_delay_over = 0;
1130
1131 return CMD_SUCCESS;
1132 }
1133
1134 /* Clear specified neighbor. */
1135 if (sort == clear_peer) {
1136 union sockunion su;
1137
1138 /* Make sockunion for lookup. */
1139 ret = str2sockunion(arg, &su);
1140 if (ret < 0) {
1141 peer = peer_lookup_by_conf_if(bgp, arg);
1142 if (!peer) {
1143 peer = peer_lookup_by_hostname(bgp, arg);
1144 if (!peer) {
1145 vty_out(vty,
1146 "Malformed address or name: %s\n",
1147 arg);
1148 return CMD_WARNING;
1149 }
1150 }
1151 } else {
1152 peer = peer_lookup(bgp, &su);
1153 if (!peer) {
1154 vty_out(vty,
1155 "%% BGP: Unknown neighbor - \"%s\"\n",
1156 arg);
1157 return CMD_WARNING;
1158 }
1159 }
1160
1161 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1162 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1163
1164 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1165
1166 /* if afi/safi not defined for this peer, let caller know */
1167 if (ret == 1)
1168 ret = BGP_ERR_AF_UNCONFIGURED;
1169
1170 if (ret < 0)
1171 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1172
1173 return CMD_SUCCESS;
1174 }
1175
1176 /* Clear all neighbors belonging to a specific peer-group. */
1177 if (sort == clear_group) {
1178 struct peer_group *group;
1179
1180 group = peer_group_lookup(bgp, arg);
1181 if (!group) {
1182 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1183 return CMD_WARNING;
1184 }
1185
1186 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1187 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1188
1189 if (ret < 0)
1190 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1191 else
1192 found = true;
1193 }
1194
1195 if (!found)
1196 vty_out(vty,
1197 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1198 get_afi_safi_str(afi, safi, false), arg);
1199
1200 return CMD_SUCCESS;
1201 }
1202
1203 /* Clear all external (eBGP) neighbors. */
1204 if (sort == clear_external) {
1205 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1206 if (peer->sort == BGP_PEER_IBGP)
1207 continue;
1208
1209 bgp_peer_gr_flags_update(peer);
1210
1211 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1212 gr_router_detected = true;
1213
1214 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1215
1216 if (ret < 0)
1217 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1218 else
1219 found = true;
1220 }
1221
1222 if (gr_router_detected
1223 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1224 bgp_zebra_send_capabilities(bgp, false);
1225 } else if (!gr_router_detected
1226 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1227 bgp_zebra_send_capabilities(bgp, true);
1228 }
1229
1230 if (!found)
1231 vty_out(vty,
1232 "%% BGP: No external %s peer is configured\n",
1233 get_afi_safi_str(afi, safi, false));
1234
1235 return CMD_SUCCESS;
1236 }
1237
1238 /* Clear all neighbors belonging to a specific AS. */
1239 if (sort == clear_as) {
1240 as_t as = strtoul(arg, NULL, 10);
1241
1242 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1243 if (peer->as != as)
1244 continue;
1245
1246 bgp_peer_gr_flags_update(peer);
1247
1248 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1249 gr_router_detected = true;
1250
1251 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1252
1253 if (ret < 0)
1254 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1255 else
1256 found = true;
1257 }
1258
1259 if (gr_router_detected
1260 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1261 bgp_zebra_send_capabilities(bgp, false);
1262 } else if (!gr_router_detected
1263 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1264 bgp_zebra_send_capabilities(bgp, true);
1265 }
1266
1267 if (!found)
1268 vty_out(vty,
1269 "%% BGP: No %s peer is configured with AS %s\n",
1270 get_afi_safi_str(afi, safi, false), arg);
1271
1272 return CMD_SUCCESS;
1273 }
1274
1275 return CMD_SUCCESS;
1276 }
1277
1278 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1279 safi_t safi, enum clear_sort sort,
1280 enum bgp_clear_type stype, const char *arg)
1281 {
1282 struct bgp *bgp;
1283
1284 /* BGP structure lookup. */
1285 if (name) {
1286 bgp = bgp_lookup_by_name(name);
1287 if (bgp == NULL) {
1288 vty_out(vty, "Can't find BGP instance %s\n", name);
1289 return CMD_WARNING;
1290 }
1291 } else {
1292 bgp = bgp_get_default();
1293 if (bgp == NULL) {
1294 vty_out(vty, "No BGP process is configured\n");
1295 return CMD_WARNING;
1296 }
1297 }
1298
1299 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1300 }
1301
1302 /* clear soft inbound */
1303 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1304 {
1305 afi_t afi;
1306 safi_t safi;
1307
1308 FOREACH_AFI_SAFI (afi, safi)
1309 bgp_clear_vty(vty, name, afi, safi, clear_all,
1310 BGP_CLEAR_SOFT_IN, NULL);
1311 }
1312
1313 /* clear soft outbound */
1314 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1315 {
1316 afi_t afi;
1317 safi_t safi;
1318
1319 FOREACH_AFI_SAFI (afi, safi)
1320 bgp_clear_vty(vty, name, afi, safi, clear_all,
1321 BGP_CLEAR_SOFT_OUT, NULL);
1322 }
1323
1324
1325 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1326 {
1327 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1328 }
1329
1330 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1331 uint64_t flag, int set)
1332 {
1333 int ret;
1334 struct peer *peer;
1335
1336 peer = peer_and_group_lookup_vty(vty, ip_str);
1337 if (!peer)
1338 return CMD_WARNING_CONFIG_FAILED;
1339
1340 /*
1341 * If 'neighbor <interface>', then this is for directly connected peers,
1342 * we should not accept disable-connected-check.
1343 */
1344 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1345 vty_out(vty,
1346 "%s is directly connected peer, cannot accept disable-connected-check\n",
1347 ip_str);
1348 return CMD_WARNING_CONFIG_FAILED;
1349 }
1350
1351 if (!set && flag == PEER_FLAG_SHUTDOWN)
1352 peer_tx_shutdown_message_unset(peer);
1353
1354 if (set)
1355 ret = peer_flag_set(peer, flag);
1356 else
1357 ret = peer_flag_unset(peer, flag);
1358
1359 return bgp_vty_return(vty, ret);
1360 }
1361
1362 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1363 {
1364 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1365 }
1366
1367 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1368 uint64_t flag)
1369 {
1370 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1371 }
1372
1373 #include "bgpd/bgp_vty_clippy.c"
1374
1375 DEFUN_HIDDEN (bgp_local_mac,
1376 bgp_local_mac_cmd,
1377 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1378 BGP_STR
1379 "Local MAC config\n"
1380 "VxLAN Network Identifier\n"
1381 "VNI number\n"
1382 "local mac\n"
1383 "mac address\n"
1384 "mac-mobility sequence\n"
1385 "seq number\n")
1386 {
1387 int rv;
1388 vni_t vni;
1389 struct ethaddr mac;
1390 struct ipaddr ip;
1391 uint32_t seq;
1392 struct bgp *bgp;
1393
1394 vni = strtoul(argv[3]->arg, NULL, 10);
1395 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1396 vty_out(vty, "%% Malformed MAC address\n");
1397 return CMD_WARNING;
1398 }
1399 memset(&ip, 0, sizeof(ip));
1400 seq = strtoul(argv[7]->arg, NULL, 10);
1401
1402 bgp = bgp_get_default();
1403 if (!bgp) {
1404 vty_out(vty, "Default BGP instance is not there\n");
1405 return CMD_WARNING;
1406 }
1407
1408 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1409 zero_esi);
1410 if (rv < 0) {
1411 vty_out(vty, "Internal error\n");
1412 return CMD_WARNING;
1413 }
1414
1415 return CMD_SUCCESS;
1416 }
1417
1418 DEFUN_HIDDEN (no_bgp_local_mac,
1419 no_bgp_local_mac_cmd,
1420 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1421 NO_STR
1422 BGP_STR
1423 "Local MAC config\n"
1424 "VxLAN Network Identifier\n"
1425 "VNI number\n"
1426 "local mac\n"
1427 "mac address\n")
1428 {
1429 int rv;
1430 vni_t vni;
1431 struct ethaddr mac;
1432 struct ipaddr ip;
1433 struct bgp *bgp;
1434
1435 vni = strtoul(argv[4]->arg, NULL, 10);
1436 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1437 vty_out(vty, "%% Malformed MAC address\n");
1438 return CMD_WARNING;
1439 }
1440 memset(&ip, 0, sizeof(ip));
1441
1442 bgp = bgp_get_default();
1443 if (!bgp) {
1444 vty_out(vty, "Default BGP instance is not there\n");
1445 return CMD_WARNING;
1446 }
1447
1448 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1449 if (rv < 0) {
1450 vty_out(vty, "Internal error\n");
1451 return CMD_WARNING;
1452 }
1453
1454 return CMD_SUCCESS;
1455 }
1456
1457 DEFUN (no_synchronization,
1458 no_synchronization_cmd,
1459 "no synchronization",
1460 NO_STR
1461 "Perform IGP synchronization\n")
1462 {
1463 return CMD_SUCCESS;
1464 }
1465
1466 DEFUN (no_auto_summary,
1467 no_auto_summary_cmd,
1468 "no auto-summary",
1469 NO_STR
1470 "Enable automatic network number summarization\n")
1471 {
1472 return CMD_SUCCESS;
1473 }
1474
1475 /* "router bgp" commands. */
1476 DEFUN_NOSH (router_bgp,
1477 router_bgp_cmd,
1478 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1479 ROUTER_STR
1480 BGP_STR
1481 AS_STR
1482 BGP_INSTANCE_HELP_STR)
1483 {
1484 int idx_asn = 2;
1485 int idx_view_vrf = 3;
1486 int idx_vrf = 4;
1487 int is_new_bgp = 0;
1488 int ret;
1489 as_t as;
1490 struct bgp *bgp;
1491 const char *name = NULL;
1492 enum bgp_instance_type inst_type;
1493
1494 // "router bgp" without an ASN
1495 if (argc == 2) {
1496 // Pending: Make VRF option available for ASN less config
1497 bgp = bgp_get_default();
1498
1499 if (bgp == NULL) {
1500 vty_out(vty, "%% No BGP process is configured\n");
1501 return CMD_WARNING_CONFIG_FAILED;
1502 }
1503
1504 if (listcount(bm->bgp) > 1) {
1505 vty_out(vty, "%% Please specify ASN and VRF\n");
1506 return CMD_WARNING_CONFIG_FAILED;
1507 }
1508 }
1509
1510 // "router bgp X"
1511 else {
1512 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1513
1514 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1515 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1516 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1517
1518 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1519 if (argc > 3) {
1520 name = argv[idx_vrf]->arg;
1521
1522 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1523 if (strmatch(name, VRF_DEFAULT_NAME))
1524 name = NULL;
1525 else
1526 inst_type = BGP_INSTANCE_TYPE_VRF;
1527 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1528 inst_type = BGP_INSTANCE_TYPE_VIEW;
1529 }
1530
1531 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1532 is_new_bgp = (bgp_lookup(as, name) == NULL);
1533
1534 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1535 switch (ret) {
1536 case BGP_ERR_AS_MISMATCH:
1537 vty_out(vty, "BGP is already running; AS is %u\n", as);
1538 return CMD_WARNING_CONFIG_FAILED;
1539 case BGP_ERR_INSTANCE_MISMATCH:
1540 vty_out(vty,
1541 "BGP instance name and AS number mismatch\n");
1542 vty_out(vty,
1543 "BGP instance is already running; AS is %u\n",
1544 as);
1545 return CMD_WARNING_CONFIG_FAILED;
1546 }
1547
1548 /*
1549 * If we just instantiated the default instance, complete
1550 * any pending VRF-VPN leaking that was configured via
1551 * earlier "router bgp X vrf FOO" blocks.
1552 */
1553 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1554 vpn_leak_postchange_all();
1555
1556 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1557 bgp_vpn_leak_export(bgp);
1558 /* Pending: handle when user tries to change a view to vrf n vv.
1559 */
1560 }
1561
1562 /* unset the auto created flag as the user config is now present */
1563 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1564 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1565
1566 return CMD_SUCCESS;
1567 }
1568
1569 /* "no router bgp" commands. */
1570 DEFUN (no_router_bgp,
1571 no_router_bgp_cmd,
1572 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1573 NO_STR
1574 ROUTER_STR
1575 BGP_STR
1576 AS_STR
1577 BGP_INSTANCE_HELP_STR)
1578 {
1579 int idx_asn = 3;
1580 int idx_vrf = 5;
1581 as_t as;
1582 struct bgp *bgp;
1583 const char *name = NULL;
1584
1585 // "no router bgp" without an ASN
1586 if (argc == 3) {
1587 // Pending: Make VRF option available for ASN less config
1588 bgp = bgp_get_default();
1589
1590 if (bgp == NULL) {
1591 vty_out(vty, "%% No BGP process is configured\n");
1592 return CMD_WARNING_CONFIG_FAILED;
1593 }
1594
1595 if (listcount(bm->bgp) > 1) {
1596 vty_out(vty, "%% Please specify ASN and VRF\n");
1597 return CMD_WARNING_CONFIG_FAILED;
1598 }
1599
1600 if (bgp->l3vni) {
1601 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1602 bgp->l3vni);
1603 return CMD_WARNING_CONFIG_FAILED;
1604 }
1605 } else {
1606 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1607
1608 if (argc > 4) {
1609 name = argv[idx_vrf]->arg;
1610 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1611 && strmatch(name, VRF_DEFAULT_NAME))
1612 name = NULL;
1613 }
1614
1615 /* Lookup bgp structure. */
1616 bgp = bgp_lookup(as, name);
1617 if (!bgp) {
1618 vty_out(vty, "%% Can't find BGP instance\n");
1619 return CMD_WARNING_CONFIG_FAILED;
1620 }
1621
1622 if (bgp->l3vni) {
1623 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1624 bgp->l3vni);
1625 return CMD_WARNING_CONFIG_FAILED;
1626 }
1627
1628 /* Cannot delete default instance if vrf instances exist */
1629 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1630 struct listnode *node;
1631 struct bgp *tmp_bgp;
1632
1633 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1634 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1635 continue;
1636 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1637 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1638 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1639 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1640 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1641 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1642 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1643 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1644 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1645 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1646 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1647 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1648 (bgp == bgp_get_evpn() &&
1649 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1650 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1651 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1652 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1653 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1654 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1655 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1656 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1657 (hashcount(tmp_bgp->vnihash))) {
1658 vty_out(vty,
1659 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1660 return CMD_WARNING_CONFIG_FAILED;
1661 }
1662 }
1663 }
1664 }
1665
1666 bgp_delete(bgp);
1667
1668 return CMD_SUCCESS;
1669 }
1670
1671 /* bgp session-dscp */
1672
1673 DEFPY (bgp_session_dscp,
1674 bgp_session_dscp_cmd,
1675 "bgp session-dscp (0-63)$dscp",
1676 BGP_STR
1677 "Override default (C6) bgp TCP session DSCP value\n"
1678 "Manually configured dscp parameter\n")
1679 {
1680 bm->tcp_dscp = dscp << 2;
1681
1682 return CMD_SUCCESS;
1683 }
1684
1685 DEFPY (no_bgp_session_dscp,
1686 no_bgp_session_dscp_cmd,
1687 "no bgp session-dscp [(0-63)]",
1688 NO_STR
1689 BGP_STR
1690 "Override default (C6) bgp TCP session DSCP value\n"
1691 "Manually configured dscp parameter\n")
1692 {
1693 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1694
1695 return CMD_SUCCESS;
1696 }
1697
1698 /* BGP router-id. */
1699
1700 DEFPY (bgp_router_id,
1701 bgp_router_id_cmd,
1702 "bgp router-id A.B.C.D",
1703 BGP_STR
1704 "Override configured router identifier\n"
1705 "Manually configured router identifier\n")
1706 {
1707 VTY_DECLVAR_CONTEXT(bgp, bgp);
1708 bgp_router_id_static_set(bgp, router_id);
1709 return CMD_SUCCESS;
1710 }
1711
1712 DEFPY (no_bgp_router_id,
1713 no_bgp_router_id_cmd,
1714 "no bgp router-id [A.B.C.D]",
1715 NO_STR
1716 BGP_STR
1717 "Override configured router identifier\n"
1718 "Manually configured router identifier\n")
1719 {
1720 VTY_DECLVAR_CONTEXT(bgp, bgp);
1721
1722 if (router_id_str) {
1723 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1724 vty_out(vty, "%% BGP router-id doesn't match\n");
1725 return CMD_WARNING_CONFIG_FAILED;
1726 }
1727 }
1728
1729 router_id.s_addr = 0;
1730 bgp_router_id_static_set(bgp, router_id);
1731
1732 return CMD_SUCCESS;
1733 }
1734
1735 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1736 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1737 NO_STR BGP_STR
1738 "Add community specific parameters\n"
1739 "Create an alias for a community\n"
1740 "Community (AA:BB or AA:BB:CC)\n"
1741 "Alias name\n")
1742 {
1743 struct community_alias ca = {};
1744 struct community_alias *lookup_community;
1745 struct community_alias *lookup_alias;
1746 struct community *comm;
1747 struct lcommunity *lcomm;
1748 uint8_t invalid = 0;
1749
1750 comm = community_str2com(community);
1751 if (!comm)
1752 invalid++;
1753 community_free(&comm);
1754
1755 lcomm = lcommunity_str2com(community);
1756 if (!lcomm)
1757 invalid++;
1758 lcommunity_free(&lcomm);
1759
1760 if (invalid > 1) {
1761 vty_out(vty, "Invalid community format\n");
1762 return CMD_WARNING;
1763 }
1764
1765 strlcpy(ca.community, community, sizeof(ca.community));
1766 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1767
1768 lookup_community = bgp_ca_community_lookup(&ca);
1769 lookup_alias = bgp_ca_alias_lookup(&ca);
1770
1771 if (no) {
1772 bgp_ca_alias_delete(&ca);
1773 bgp_ca_community_delete(&ca);
1774 } else {
1775 if (lookup_alias) {
1776 /* Lookup if community hash table has an item
1777 * with the same alias name.
1778 */
1779 strlcpy(ca.community, lookup_alias->community,
1780 sizeof(ca.community));
1781 if (bgp_ca_community_lookup(&ca)) {
1782 vty_out(vty,
1783 "community (%s) already has this alias (%s)\n",
1784 lookup_alias->community,
1785 lookup_alias->alias);
1786 return CMD_WARNING;
1787 }
1788 bgp_ca_alias_delete(&ca);
1789 }
1790
1791 if (lookup_community) {
1792 /* Lookup if alias hash table has an item
1793 * with the same community.
1794 */
1795 strlcpy(ca.alias, lookup_community->alias,
1796 sizeof(ca.alias));
1797 if (bgp_ca_alias_lookup(&ca)) {
1798 vty_out(vty,
1799 "alias (%s) already has this community (%s)\n",
1800 lookup_community->alias,
1801 lookup_community->community);
1802 return CMD_WARNING;
1803 }
1804 bgp_ca_community_delete(&ca);
1805 }
1806
1807 bgp_ca_alias_insert(&ca);
1808 bgp_ca_community_insert(&ca);
1809 }
1810
1811 return CMD_SUCCESS;
1812 }
1813
1814 DEFPY (bgp_global_suppress_fib_pending,
1815 bgp_global_suppress_fib_pending_cmd,
1816 "[no] bgp suppress-fib-pending",
1817 NO_STR
1818 BGP_STR
1819 "Advertise only routes that are programmed in kernel to peers globally\n")
1820 {
1821 bm_wait_for_fib_set(!no);
1822
1823 return CMD_SUCCESS;
1824 }
1825
1826 DEFPY (bgp_suppress_fib_pending,
1827 bgp_suppress_fib_pending_cmd,
1828 "[no] bgp suppress-fib-pending",
1829 NO_STR
1830 BGP_STR
1831 "Advertise only routes that are programmed in kernel to peers\n")
1832 {
1833 VTY_DECLVAR_CONTEXT(bgp, bgp);
1834
1835 bgp_suppress_fib_pending_set(bgp, !no);
1836 return CMD_SUCCESS;
1837 }
1838
1839
1840 /* BGP Cluster ID. */
1841 DEFUN (bgp_cluster_id,
1842 bgp_cluster_id_cmd,
1843 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1844 BGP_STR
1845 "Configure Route-Reflector Cluster-id\n"
1846 "Route-Reflector Cluster-id in IP address format\n"
1847 "Route-Reflector Cluster-id as 32 bit quantity\n")
1848 {
1849 VTY_DECLVAR_CONTEXT(bgp, bgp);
1850 int idx_ipv4 = 2;
1851 int ret;
1852 struct in_addr cluster;
1853
1854 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1855 if (!ret) {
1856 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1857 return CMD_WARNING_CONFIG_FAILED;
1858 }
1859
1860 bgp_cluster_id_set(bgp, &cluster);
1861 bgp_clear_star_soft_out(vty, bgp->name);
1862
1863 return CMD_SUCCESS;
1864 }
1865
1866 DEFUN (no_bgp_cluster_id,
1867 no_bgp_cluster_id_cmd,
1868 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1869 NO_STR
1870 BGP_STR
1871 "Configure Route-Reflector Cluster-id\n"
1872 "Route-Reflector Cluster-id in IP address format\n"
1873 "Route-Reflector Cluster-id as 32 bit quantity\n")
1874 {
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876 bgp_cluster_id_unset(bgp);
1877 bgp_clear_star_soft_out(vty, bgp->name);
1878
1879 return CMD_SUCCESS;
1880 }
1881
1882 DEFPY (bgp_norib,
1883 bgp_norib_cmd,
1884 "bgp no-rib",
1885 BGP_STR
1886 "Disable BGP route installation to RIB (Zebra)\n")
1887 {
1888 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1889 vty_out(vty,
1890 "%% No-RIB option is already set, nothing to do here.\n");
1891 return CMD_SUCCESS;
1892 }
1893
1894 bgp_option_norib_set_runtime();
1895
1896 return CMD_SUCCESS;
1897 }
1898
1899 DEFPY (no_bgp_norib,
1900 no_bgp_norib_cmd,
1901 "no bgp no-rib",
1902 NO_STR
1903 BGP_STR
1904 "Disable BGP route installation to RIB (Zebra)\n")
1905 {
1906 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1907 vty_out(vty,
1908 "%% No-RIB option is not set, nothing to do here.\n");
1909 return CMD_SUCCESS;
1910 }
1911
1912 bgp_option_norib_unset_runtime();
1913
1914 return CMD_SUCCESS;
1915 }
1916
1917 DEFPY (no_bgp_send_extra_data,
1918 no_bgp_send_extra_data_cmd,
1919 "[no] bgp send-extra-data zebra",
1920 NO_STR
1921 BGP_STR
1922 "Extra data to Zebra for display/use\n"
1923 "To zebra\n")
1924 {
1925 if (no)
1926 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1927 else
1928 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1929
1930 return CMD_SUCCESS;
1931 }
1932
1933 DEFUN (bgp_confederation_identifier,
1934 bgp_confederation_identifier_cmd,
1935 "bgp confederation identifier (1-4294967295)",
1936 BGP_STR
1937 "AS confederation parameters\n"
1938 "AS number\n"
1939 "Set routing domain confederation AS\n")
1940 {
1941 VTY_DECLVAR_CONTEXT(bgp, bgp);
1942 int idx_number = 3;
1943 as_t as;
1944
1945 as = strtoul(argv[idx_number]->arg, NULL, 10);
1946
1947 bgp_confederation_id_set(bgp, as);
1948
1949 return CMD_SUCCESS;
1950 }
1951
1952 DEFUN (no_bgp_confederation_identifier,
1953 no_bgp_confederation_identifier_cmd,
1954 "no bgp confederation identifier [(1-4294967295)]",
1955 NO_STR
1956 BGP_STR
1957 "AS confederation parameters\n"
1958 "AS number\n"
1959 "Set routing domain confederation AS\n")
1960 {
1961 VTY_DECLVAR_CONTEXT(bgp, bgp);
1962 bgp_confederation_id_unset(bgp);
1963
1964 return CMD_SUCCESS;
1965 }
1966
1967 DEFUN (bgp_confederation_peers,
1968 bgp_confederation_peers_cmd,
1969 "bgp confederation peers (1-4294967295)...",
1970 BGP_STR
1971 "AS confederation parameters\n"
1972 "Peer ASs in BGP confederation\n"
1973 AS_STR)
1974 {
1975 VTY_DECLVAR_CONTEXT(bgp, bgp);
1976 int idx_asn = 3;
1977 as_t as;
1978 int i;
1979
1980 for (i = idx_asn; i < argc; i++) {
1981 as = strtoul(argv[i]->arg, NULL, 10);
1982 bgp_confederation_peers_add(bgp, as);
1983 }
1984 return CMD_SUCCESS;
1985 }
1986
1987 DEFUN (no_bgp_confederation_peers,
1988 no_bgp_confederation_peers_cmd,
1989 "no bgp confederation peers (1-4294967295)...",
1990 NO_STR
1991 BGP_STR
1992 "AS confederation parameters\n"
1993 "Peer ASs in BGP confederation\n"
1994 AS_STR)
1995 {
1996 VTY_DECLVAR_CONTEXT(bgp, bgp);
1997 int idx_asn = 4;
1998 as_t as;
1999 int i;
2000
2001 for (i = idx_asn; i < argc; i++) {
2002 as = strtoul(argv[i]->arg, NULL, 10);
2003
2004 bgp_confederation_peers_remove(bgp, as);
2005 }
2006 return CMD_SUCCESS;
2007 }
2008
2009 /**
2010 * Central routine for maximum-paths configuration.
2011 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
2012 * @set: 1 for setting values, 0 for removing the max-paths config.
2013 */
2014 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
2015 const char *mpaths, uint16_t options,
2016 int set)
2017 {
2018 VTY_DECLVAR_CONTEXT(bgp, bgp);
2019 uint16_t maxpaths = 0;
2020 int ret;
2021 afi_t afi;
2022 safi_t safi;
2023
2024 afi = bgp_node_afi(vty);
2025 safi = bgp_node_safi(vty);
2026
2027 if (set) {
2028 maxpaths = strtol(mpaths, NULL, 10);
2029 if (maxpaths > multipath_num) {
2030 vty_out(vty,
2031 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2032 maxpaths, multipath_num);
2033 return CMD_WARNING_CONFIG_FAILED;
2034 }
2035 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2036 options);
2037 } else
2038 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2039
2040 if (ret < 0) {
2041 vty_out(vty,
2042 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2043 (set == 1) ? "" : "un",
2044 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2045 maxpaths, afi, safi);
2046 return CMD_WARNING_CONFIG_FAILED;
2047 }
2048
2049 bgp_recalculate_all_bestpaths(bgp);
2050
2051 return CMD_SUCCESS;
2052 }
2053
2054 DEFUN (bgp_maxmed_admin,
2055 bgp_maxmed_admin_cmd,
2056 "bgp max-med administrative ",
2057 BGP_STR
2058 "Advertise routes with max-med\n"
2059 "Administratively applied, for an indefinite period\n")
2060 {
2061 VTY_DECLVAR_CONTEXT(bgp, bgp);
2062
2063 bgp->v_maxmed_admin = 1;
2064 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2065
2066 bgp_maxmed_update(bgp);
2067
2068 return CMD_SUCCESS;
2069 }
2070
2071 DEFUN (bgp_maxmed_admin_medv,
2072 bgp_maxmed_admin_medv_cmd,
2073 "bgp max-med administrative (0-4294967295)",
2074 BGP_STR
2075 "Advertise routes with max-med\n"
2076 "Administratively applied, for an indefinite period\n"
2077 "Max MED value to be used\n")
2078 {
2079 VTY_DECLVAR_CONTEXT(bgp, bgp);
2080 int idx_number = 3;
2081
2082 bgp->v_maxmed_admin = 1;
2083 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2084
2085 bgp_maxmed_update(bgp);
2086
2087 return CMD_SUCCESS;
2088 }
2089
2090 DEFUN (no_bgp_maxmed_admin,
2091 no_bgp_maxmed_admin_cmd,
2092 "no bgp max-med administrative [(0-4294967295)]",
2093 NO_STR
2094 BGP_STR
2095 "Advertise routes with max-med\n"
2096 "Administratively applied, for an indefinite period\n"
2097 "Max MED value to be used\n")
2098 {
2099 VTY_DECLVAR_CONTEXT(bgp, bgp);
2100 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2101 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2102 bgp_maxmed_update(bgp);
2103
2104 return CMD_SUCCESS;
2105 }
2106
2107 DEFUN (bgp_maxmed_onstartup,
2108 bgp_maxmed_onstartup_cmd,
2109 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2110 BGP_STR
2111 "Advertise routes with max-med\n"
2112 "Effective on a startup\n"
2113 "Time (seconds) period for max-med\n"
2114 "Max MED value to be used\n")
2115 {
2116 VTY_DECLVAR_CONTEXT(bgp, bgp);
2117 int idx = 0;
2118
2119 if (argv_find(argv, argc, "(5-86400)", &idx))
2120 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2121 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2122 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2123 else
2124 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2125
2126 bgp_maxmed_update(bgp);
2127
2128 return CMD_SUCCESS;
2129 }
2130
2131 DEFUN (no_bgp_maxmed_onstartup,
2132 no_bgp_maxmed_onstartup_cmd,
2133 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2134 NO_STR
2135 BGP_STR
2136 "Advertise routes with max-med\n"
2137 "Effective on a startup\n"
2138 "Time (seconds) period for max-med\n"
2139 "Max MED value to be used\n")
2140 {
2141 VTY_DECLVAR_CONTEXT(bgp, bgp);
2142
2143 /* Cancel max-med onstartup if its on */
2144 if (bgp->t_maxmed_onstartup) {
2145 THREAD_OFF(bgp->t_maxmed_onstartup);
2146 bgp->maxmed_onstartup_over = 1;
2147 }
2148
2149 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2150 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2151
2152 bgp_maxmed_update(bgp);
2153
2154 return CMD_SUCCESS;
2155 }
2156
2157 static int bgp_global_update_delay_config_vty(struct vty *vty,
2158 uint16_t update_delay,
2159 uint16_t establish_wait)
2160 {
2161 struct listnode *node, *nnode;
2162 struct bgp *bgp;
2163 bool vrf_cfg = false;
2164
2165 /*
2166 * See if update-delay is set per-vrf and warn user to delete it
2167 * Note that we only need to check this if this is the first time
2168 * setting the global config.
2169 */
2170 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2171 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2172 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2173 vty_out(vty,
2174 "%% update-delay configuration found in vrf %s\n",
2175 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2176 ? VRF_DEFAULT_NAME
2177 : bgp->name);
2178 vrf_cfg = true;
2179 }
2180 }
2181 }
2182
2183 if (vrf_cfg) {
2184 vty_out(vty,
2185 "%%Failed: global update-delay config not permitted\n");
2186 return CMD_WARNING;
2187 }
2188
2189 if (!establish_wait) { /* update-delay <delay> */
2190 bm->v_update_delay = update_delay;
2191 bm->v_establish_wait = bm->v_update_delay;
2192 } else {
2193 /* update-delay <delay> <establish-wait> */
2194 if (update_delay < establish_wait) {
2195 vty_out(vty,
2196 "%%Failed: update-delay less than the establish-wait!\n");
2197 return CMD_WARNING_CONFIG_FAILED;
2198 }
2199
2200 bm->v_update_delay = update_delay;
2201 bm->v_establish_wait = establish_wait;
2202 }
2203
2204 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2205 bgp->v_update_delay = bm->v_update_delay;
2206 bgp->v_establish_wait = bm->v_establish_wait;
2207 }
2208
2209 return CMD_SUCCESS;
2210 }
2211
2212 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2213 {
2214 struct listnode *node, *nnode;
2215 struct bgp *bgp;
2216
2217 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2218 bm->v_establish_wait = bm->v_update_delay;
2219
2220 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2221 bgp->v_update_delay = bm->v_update_delay;
2222 bgp->v_establish_wait = bm->v_establish_wait;
2223 }
2224
2225 return CMD_SUCCESS;
2226 }
2227
2228 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2229 uint16_t establish_wait)
2230 {
2231 VTY_DECLVAR_CONTEXT(bgp, bgp);
2232
2233 /* if configured globally, per-instance config is not allowed */
2234 if (bm->v_update_delay) {
2235 vty_out(vty,
2236 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2237 return CMD_WARNING_CONFIG_FAILED;
2238 }
2239
2240
2241 if (!establish_wait) /* update-delay <delay> */
2242 {
2243 bgp->v_update_delay = update_delay;
2244 bgp->v_establish_wait = bgp->v_update_delay;
2245 return CMD_SUCCESS;
2246 }
2247
2248 /* update-delay <delay> <establish-wait> */
2249 if (update_delay < establish_wait) {
2250 vty_out(vty,
2251 "%%Failed: update-delay less than the establish-wait!\n");
2252 return CMD_WARNING_CONFIG_FAILED;
2253 }
2254
2255 bgp->v_update_delay = update_delay;
2256 bgp->v_establish_wait = establish_wait;
2257
2258 return CMD_SUCCESS;
2259 }
2260
2261 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2262 {
2263 VTY_DECLVAR_CONTEXT(bgp, bgp);
2264
2265 /* If configured globally, cannot remove from one bgp instance */
2266 if (bm->v_update_delay) {
2267 vty_out(vty,
2268 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2269 return CMD_WARNING_CONFIG_FAILED;
2270 }
2271 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2272 bgp->v_establish_wait = bgp->v_update_delay;
2273
2274 return CMD_SUCCESS;
2275 }
2276
2277 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2278 {
2279 /* If configured globally, no need to display per-instance value */
2280 if (bgp->v_update_delay != bm->v_update_delay) {
2281 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2282 if (bgp->v_update_delay != bgp->v_establish_wait)
2283 vty_out(vty, " %d", bgp->v_establish_wait);
2284 vty_out(vty, "\n");
2285 }
2286 }
2287
2288 /* Global update-delay configuration */
2289 DEFPY (bgp_global_update_delay,
2290 bgp_global_update_delay_cmd,
2291 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2292 BGP_STR
2293 "Force initial delay for best-path and updates for all bgp instances\n"
2294 "Max delay in seconds\n"
2295 "Establish wait in seconds\n")
2296 {
2297 return bgp_global_update_delay_config_vty(vty, delay, wait);
2298 }
2299
2300 /* Global update-delay deconfiguration */
2301 DEFPY (no_bgp_global_update_delay,
2302 no_bgp_global_update_delay_cmd,
2303 "no bgp update-delay [(0-3600) [(1-3600)]]",
2304 NO_STR
2305 BGP_STR
2306 "Force initial delay for best-path and updates\n"
2307 "Max delay in seconds\n"
2308 "Establish wait in seconds\n")
2309 {
2310 return bgp_global_update_delay_deconfig_vty(vty);
2311 }
2312
2313 /* Update-delay configuration */
2314
2315 DEFPY (bgp_update_delay,
2316 bgp_update_delay_cmd,
2317 "update-delay (0-3600)$delay [(1-3600)$wait]",
2318 "Force initial delay for best-path and updates\n"
2319 "Max delay in seconds\n"
2320 "Establish wait in seconds\n")
2321 {
2322 return bgp_update_delay_config_vty(vty, delay, wait);
2323 }
2324
2325 /* Update-delay deconfiguration */
2326 DEFPY (no_bgp_update_delay,
2327 no_bgp_update_delay_cmd,
2328 "no update-delay [(0-3600) [(1-3600)]]",
2329 NO_STR
2330 "Force initial delay for best-path and updates\n"
2331 "Max delay in seconds\n"
2332 "Establish wait in seconds\n")
2333 {
2334 return bgp_update_delay_deconfig_vty(vty);
2335 }
2336
2337
2338 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2339 bool set)
2340 {
2341 VTY_DECLVAR_CONTEXT(bgp, bgp);
2342
2343 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2344 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2345
2346 return CMD_SUCCESS;
2347 }
2348
2349 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2350 bool set)
2351 {
2352 VTY_DECLVAR_CONTEXT(bgp, bgp);
2353
2354 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2355 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2356
2357 return CMD_SUCCESS;
2358 }
2359
2360 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2361 {
2362 uint32_t quanta =
2363 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2364 if (quanta != BGP_WRITE_PACKET_MAX)
2365 vty_out(vty, " write-quanta %d\n", quanta);
2366 }
2367
2368 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2369 {
2370 uint32_t quanta =
2371 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2372 if (quanta != BGP_READ_PACKET_MAX)
2373 vty_out(vty, " read-quanta %d\n", quanta);
2374 }
2375
2376 /* Packet quanta configuration
2377 *
2378 * XXX: The value set here controls the size of a stack buffer in the IO
2379 * thread. When changing these limits be careful to prevent stack overflow.
2380 *
2381 * Furthermore, the maximums used here should correspond to
2382 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2383 */
2384 DEFPY (bgp_wpkt_quanta,
2385 bgp_wpkt_quanta_cmd,
2386 "[no] write-quanta (1-64)$quanta",
2387 NO_STR
2388 "How many packets to write to peer socket per run\n"
2389 "Number of packets\n")
2390 {
2391 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2392 }
2393
2394 DEFPY (bgp_rpkt_quanta,
2395 bgp_rpkt_quanta_cmd,
2396 "[no] read-quanta (1-10)$quanta",
2397 NO_STR
2398 "How many packets to read from peer socket per I/O cycle\n"
2399 "Number of packets\n")
2400 {
2401 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2402 }
2403
2404 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2405 {
2406 if (!bgp->heuristic_coalesce)
2407 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2408 }
2409
2410 /* BGP TCP keepalive */
2411 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2412 {
2413 if (bgp->tcp_keepalive_idle) {
2414 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2415 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2416 bgp->tcp_keepalive_probes);
2417 }
2418 }
2419
2420 DEFUN (bgp_coalesce_time,
2421 bgp_coalesce_time_cmd,
2422 "coalesce-time (0-4294967295)",
2423 "Subgroup coalesce timer\n"
2424 "Subgroup coalesce timer value (in ms)\n")
2425 {
2426 VTY_DECLVAR_CONTEXT(bgp, bgp);
2427
2428 int idx = 0;
2429
2430 bgp->heuristic_coalesce = false;
2431
2432 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2433 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2434
2435 return CMD_SUCCESS;
2436 }
2437
2438 DEFUN (no_bgp_coalesce_time,
2439 no_bgp_coalesce_time_cmd,
2440 "no coalesce-time (0-4294967295)",
2441 NO_STR
2442 "Subgroup coalesce timer\n"
2443 "Subgroup coalesce timer value (in ms)\n")
2444 {
2445 VTY_DECLVAR_CONTEXT(bgp, bgp);
2446
2447 bgp->heuristic_coalesce = true;
2448 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2449 return CMD_SUCCESS;
2450 }
2451
2452 /* Maximum-paths configuration */
2453 DEFUN (bgp_maxpaths,
2454 bgp_maxpaths_cmd,
2455 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2456 "Forward packets over multiple paths\n"
2457 "Number of paths\n")
2458 {
2459 int idx_number = 1;
2460 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2461 argv[idx_number]->arg, 0, 1);
2462 }
2463
2464 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2465 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2466 "Forward packets over multiple paths\n"
2467 "Number of paths\n")
2468
2469 DEFUN (bgp_maxpaths_ibgp,
2470 bgp_maxpaths_ibgp_cmd,
2471 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2472 "Forward packets over multiple paths\n"
2473 "iBGP-multipath\n"
2474 "Number of paths\n")
2475 {
2476 int idx_number = 2;
2477 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2478 argv[idx_number]->arg, 0, 1);
2479 }
2480
2481 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2482 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2483 "Forward packets over multiple paths\n"
2484 "iBGP-multipath\n"
2485 "Number of paths\n")
2486
2487 DEFUN (bgp_maxpaths_ibgp_cluster,
2488 bgp_maxpaths_ibgp_cluster_cmd,
2489 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2490 "Forward packets over multiple paths\n"
2491 "iBGP-multipath\n"
2492 "Number of paths\n"
2493 "Match the cluster length\n")
2494 {
2495 int idx_number = 2;
2496 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2497 argv[idx_number]->arg, true, 1);
2498 }
2499
2500 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2501 "maximum-paths ibgp " CMD_RANGE_STR(
2502 1, MULTIPATH_NUM) " equal-cluster-length",
2503 "Forward packets over multiple paths\n"
2504 "iBGP-multipath\n"
2505 "Number of paths\n"
2506 "Match the cluster length\n")
2507
2508 DEFUN (no_bgp_maxpaths,
2509 no_bgp_maxpaths_cmd,
2510 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2511 NO_STR
2512 "Forward packets over multiple paths\n"
2513 "Number of paths\n")
2514 {
2515 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2516 }
2517
2518 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2519 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2520 "Forward packets over multiple paths\n"
2521 "Number of paths\n")
2522
2523 DEFUN (no_bgp_maxpaths_ibgp,
2524 no_bgp_maxpaths_ibgp_cmd,
2525 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2526 NO_STR
2527 "Forward packets over multiple paths\n"
2528 "iBGP-multipath\n"
2529 "Number of paths\n"
2530 "Match the cluster length\n")
2531 {
2532 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2533 }
2534
2535 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2536 "no maximum-paths ibgp [" CMD_RANGE_STR(
2537 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2538 NO_STR
2539 "Forward packets over multiple paths\n"
2540 "iBGP-multipath\n"
2541 "Number of paths\n"
2542 "Match the cluster length\n")
2543
2544 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2545 afi_t afi, safi_t safi)
2546 {
2547 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2548 vty_out(vty, " maximum-paths %d\n",
2549 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2550 }
2551
2552 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2553 vty_out(vty, " maximum-paths ibgp %d",
2554 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2555 if (bgp->maxpaths[afi][safi].same_clusterlen)
2556 vty_out(vty, " equal-cluster-length");
2557 vty_out(vty, "\n");
2558 }
2559 }
2560
2561 /* BGP timers. */
2562
2563 DEFUN (bgp_timers,
2564 bgp_timers_cmd,
2565 "timers bgp (0-65535) (0-65535)",
2566 "Adjust routing timers\n"
2567 "BGP timers\n"
2568 "Keepalive interval\n"
2569 "Holdtime\n")
2570 {
2571 VTY_DECLVAR_CONTEXT(bgp, bgp);
2572 int idx_number = 2;
2573 int idx_number_2 = 3;
2574 unsigned long keepalive = 0;
2575 unsigned long holdtime = 0;
2576
2577 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2578 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2579
2580 /* Holdtime value check. */
2581 if (holdtime < 3 && holdtime != 0) {
2582 vty_out(vty,
2583 "%% hold time value must be either 0 or greater than 3\n");
2584 return CMD_WARNING_CONFIG_FAILED;
2585 }
2586
2587 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2588 BGP_DEFAULT_DELAYOPEN);
2589
2590 return CMD_SUCCESS;
2591 }
2592
2593 DEFUN (no_bgp_timers,
2594 no_bgp_timers_cmd,
2595 "no timers bgp [(0-65535) (0-65535)]",
2596 NO_STR
2597 "Adjust routing timers\n"
2598 "BGP timers\n"
2599 "Keepalive interval\n"
2600 "Holdtime\n")
2601 {
2602 VTY_DECLVAR_CONTEXT(bgp, bgp);
2603 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2604 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2605
2606 return CMD_SUCCESS;
2607 }
2608
2609 /* BGP minimum holdtime. */
2610
2611 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2612 "bgp minimum-holdtime (1-65535)",
2613 "BGP specific commands\n"
2614 "BGP minimum holdtime\n"
2615 "Seconds\n")
2616 {
2617 VTY_DECLVAR_CONTEXT(bgp, bgp);
2618 int idx_number = 2;
2619 unsigned long min_holdtime;
2620
2621 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2622
2623 bgp->default_min_holdtime = min_holdtime;
2624
2625 return CMD_SUCCESS;
2626 }
2627
2628 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2629 "no bgp minimum-holdtime [(1-65535)]",
2630 NO_STR
2631 "BGP specific commands\n"
2632 "BGP minimum holdtime\n"
2633 "Seconds\n")
2634 {
2635 VTY_DECLVAR_CONTEXT(bgp, bgp);
2636
2637 bgp->default_min_holdtime = 0;
2638
2639 return CMD_SUCCESS;
2640 }
2641
2642 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2643 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2644 BGP_STR
2645 "TCP keepalive parameters\n"
2646 "TCP keepalive idle time (seconds)\n"
2647 "TCP keepalive interval (seconds)\n"
2648 "TCP keepalive maximum probes\n")
2649 {
2650 VTY_DECLVAR_CONTEXT(bgp, bgp);
2651
2652 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2653 (uint16_t)probes);
2654
2655 return CMD_SUCCESS;
2656 }
2657
2658 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2659 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2660 NO_STR
2661 BGP_STR
2662 "TCP keepalive parameters\n"
2663 "TCP keepalive idle time (seconds)\n"
2664 "TCP keepalive interval (seconds)\n"
2665 "TCP keepalive maximum probes\n")
2666 {
2667 VTY_DECLVAR_CONTEXT(bgp, bgp);
2668
2669 bgp_tcp_keepalive_unset(bgp);
2670
2671 return CMD_SUCCESS;
2672 }
2673
2674 DEFUN (bgp_client_to_client_reflection,
2675 bgp_client_to_client_reflection_cmd,
2676 "bgp client-to-client reflection",
2677 BGP_STR
2678 "Configure client to client route reflection\n"
2679 "reflection of routes allowed\n")
2680 {
2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
2682 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2683 bgp_clear_star_soft_out(vty, bgp->name);
2684
2685 return CMD_SUCCESS;
2686 }
2687
2688 DEFUN (no_bgp_client_to_client_reflection,
2689 no_bgp_client_to_client_reflection_cmd,
2690 "no bgp client-to-client reflection",
2691 NO_STR
2692 BGP_STR
2693 "Configure client to client route reflection\n"
2694 "reflection of routes allowed\n")
2695 {
2696 VTY_DECLVAR_CONTEXT(bgp, bgp);
2697 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2698 bgp_clear_star_soft_out(vty, bgp->name);
2699
2700 return CMD_SUCCESS;
2701 }
2702
2703 /* "bgp always-compare-med" configuration. */
2704 DEFUN (bgp_always_compare_med,
2705 bgp_always_compare_med_cmd,
2706 "bgp always-compare-med",
2707 BGP_STR
2708 "Allow comparing MED from different neighbors\n")
2709 {
2710 VTY_DECLVAR_CONTEXT(bgp, bgp);
2711 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2712 bgp_recalculate_all_bestpaths(bgp);
2713
2714 return CMD_SUCCESS;
2715 }
2716
2717 DEFUN (no_bgp_always_compare_med,
2718 no_bgp_always_compare_med_cmd,
2719 "no bgp always-compare-med",
2720 NO_STR
2721 BGP_STR
2722 "Allow comparing MED from different neighbors\n")
2723 {
2724 VTY_DECLVAR_CONTEXT(bgp, bgp);
2725 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2726 bgp_recalculate_all_bestpaths(bgp);
2727
2728 return CMD_SUCCESS;
2729 }
2730
2731
2732 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2733 "bgp ebgp-requires-policy",
2734 BGP_STR
2735 "Require in and out policy for eBGP peers (RFC8212)\n")
2736 {
2737 VTY_DECLVAR_CONTEXT(bgp, bgp);
2738 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2739 return CMD_SUCCESS;
2740 }
2741
2742 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2743 "no bgp ebgp-requires-policy",
2744 NO_STR
2745 BGP_STR
2746 "Require in and out policy for eBGP peers (RFC8212)\n")
2747 {
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2750 return CMD_SUCCESS;
2751 }
2752
2753 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2754 "bgp suppress-duplicates",
2755 BGP_STR
2756 "Suppress duplicate updates if the route actually not changed\n")
2757 {
2758 VTY_DECLVAR_CONTEXT(bgp, bgp);
2759 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2760 return CMD_SUCCESS;
2761 }
2762
2763 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2764 "no bgp suppress-duplicates",
2765 NO_STR
2766 BGP_STR
2767 "Suppress duplicate updates if the route actually not changed\n")
2768 {
2769 VTY_DECLVAR_CONTEXT(bgp, bgp);
2770 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2771 return CMD_SUCCESS;
2772 }
2773
2774 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2775 "bgp reject-as-sets",
2776 BGP_STR
2777 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2778 {
2779 VTY_DECLVAR_CONTEXT(bgp, bgp);
2780 struct listnode *node, *nnode;
2781 struct peer *peer;
2782
2783 bgp->reject_as_sets = true;
2784
2785 /* Reset existing BGP sessions to reject routes
2786 * with aspath containing AS_SET or AS_CONFED_SET.
2787 */
2788 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2789 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2790 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2791 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2792 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2793 }
2794 }
2795
2796 return CMD_SUCCESS;
2797 }
2798
2799 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2800 "no bgp reject-as-sets",
2801 NO_STR
2802 BGP_STR
2803 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2804 {
2805 VTY_DECLVAR_CONTEXT(bgp, bgp);
2806 struct listnode *node, *nnode;
2807 struct peer *peer;
2808
2809 bgp->reject_as_sets = false;
2810
2811 /* Reset existing BGP sessions to reject routes
2812 * with aspath containing AS_SET or AS_CONFED_SET.
2813 */
2814 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2815 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2816 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2817 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2818 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2819 }
2820 }
2821
2822 return CMD_SUCCESS;
2823 }
2824
2825 /* "bgp deterministic-med" configuration. */
2826 DEFUN (bgp_deterministic_med,
2827 bgp_deterministic_med_cmd,
2828 "bgp deterministic-med",
2829 BGP_STR
2830 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2831 {
2832 VTY_DECLVAR_CONTEXT(bgp, bgp);
2833
2834 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2835 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2836 bgp_recalculate_all_bestpaths(bgp);
2837 }
2838
2839 return CMD_SUCCESS;
2840 }
2841
2842 DEFUN (no_bgp_deterministic_med,
2843 no_bgp_deterministic_med_cmd,
2844 "no bgp deterministic-med",
2845 NO_STR
2846 BGP_STR
2847 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2848 {
2849 VTY_DECLVAR_CONTEXT(bgp, bgp);
2850 int bestpath_per_as_used;
2851 afi_t afi;
2852 safi_t safi;
2853 struct peer *peer;
2854 struct listnode *node, *nnode;
2855
2856 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2857 bestpath_per_as_used = 0;
2858
2859 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2860 FOREACH_AFI_SAFI (afi, safi)
2861 if (bgp_addpath_dmed_required(
2862 peer->addpath_type[afi][safi])) {
2863 bestpath_per_as_used = 1;
2864 break;
2865 }
2866
2867 if (bestpath_per_as_used)
2868 break;
2869 }
2870
2871 if (bestpath_per_as_used) {
2872 vty_out(vty,
2873 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2874 return CMD_WARNING_CONFIG_FAILED;
2875 } else {
2876 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2877 bgp_recalculate_all_bestpaths(bgp);
2878 }
2879 }
2880
2881 return CMD_SUCCESS;
2882 }
2883
2884 /* "bgp graceful-restart mode" configuration. */
2885 DEFUN (bgp_graceful_restart,
2886 bgp_graceful_restart_cmd,
2887 "bgp graceful-restart",
2888 BGP_STR
2889 GR_CMD
2890 )
2891 {
2892 int ret = BGP_GR_FAILURE;
2893
2894 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2895 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2896
2897 VTY_DECLVAR_CONTEXT(bgp, bgp);
2898
2899 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2900
2901 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2902 ret);
2903
2904 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2905 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2906 vty_out(vty,
2907 "Graceful restart configuration changed, reset all peers to take effect\n");
2908 return bgp_vty_return(vty, ret);
2909 }
2910
2911 DEFUN (no_bgp_graceful_restart,
2912 no_bgp_graceful_restart_cmd,
2913 "no bgp graceful-restart",
2914 NO_STR
2915 BGP_STR
2916 NO_GR_CMD
2917 )
2918 {
2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
2920
2921 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2922 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2923
2924 int ret = BGP_GR_FAILURE;
2925
2926 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2927
2928 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2929 ret);
2930
2931 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2932 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2933 vty_out(vty,
2934 "Graceful restart configuration changed, reset all peers to take effect\n");
2935
2936 return bgp_vty_return(vty, ret);
2937 }
2938
2939 DEFUN (bgp_graceful_restart_stalepath_time,
2940 bgp_graceful_restart_stalepath_time_cmd,
2941 "bgp graceful-restart stalepath-time (1-4095)",
2942 BGP_STR
2943 "Graceful restart capability parameters\n"
2944 "Set the max time to hold onto restarting peer's stale paths\n"
2945 "Delay value (seconds)\n")
2946 {
2947 VTY_DECLVAR_CONTEXT(bgp, bgp);
2948 int idx_number = 3;
2949 uint32_t stalepath;
2950
2951 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2952 bgp->stalepath_time = stalepath;
2953 return CMD_SUCCESS;
2954 }
2955
2956 DEFUN (bgp_graceful_restart_restart_time,
2957 bgp_graceful_restart_restart_time_cmd,
2958 "bgp graceful-restart restart-time (0-4095)",
2959 BGP_STR
2960 "Graceful restart capability parameters\n"
2961 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2962 "Delay value (seconds)\n")
2963 {
2964 VTY_DECLVAR_CONTEXT(bgp, bgp);
2965 int idx_number = 3;
2966 uint32_t restart;
2967
2968 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2969 bgp->restart_time = restart;
2970 return CMD_SUCCESS;
2971 }
2972
2973 DEFUN (bgp_graceful_restart_select_defer_time,
2974 bgp_graceful_restart_select_defer_time_cmd,
2975 "bgp graceful-restart select-defer-time (0-3600)",
2976 BGP_STR
2977 "Graceful restart capability parameters\n"
2978 "Set the time to defer the BGP route selection after restart\n"
2979 "Delay value (seconds, 0 - disable)\n")
2980 {
2981 VTY_DECLVAR_CONTEXT(bgp, bgp);
2982 int idx_number = 3;
2983 uint32_t defer_time;
2984
2985 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2986 bgp->select_defer_time = defer_time;
2987 if (defer_time == 0)
2988 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2989 else
2990 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2991
2992 return CMD_SUCCESS;
2993 }
2994
2995 DEFUN (no_bgp_graceful_restart_stalepath_time,
2996 no_bgp_graceful_restart_stalepath_time_cmd,
2997 "no bgp graceful-restart stalepath-time [(1-4095)]",
2998 NO_STR
2999 BGP_STR
3000 "Graceful restart capability parameters\n"
3001 "Set the max time to hold onto restarting peer's stale paths\n"
3002 "Delay value (seconds)\n")
3003 {
3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
3005
3006 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
3007 return CMD_SUCCESS;
3008 }
3009
3010 DEFUN (no_bgp_graceful_restart_restart_time,
3011 no_bgp_graceful_restart_restart_time_cmd,
3012 "no bgp graceful-restart restart-time [(0-4095)]",
3013 NO_STR
3014 BGP_STR
3015 "Graceful restart capability parameters\n"
3016 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3017 "Delay value (seconds)\n")
3018 {
3019 VTY_DECLVAR_CONTEXT(bgp, bgp);
3020
3021 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3022 return CMD_SUCCESS;
3023 }
3024
3025 DEFUN (no_bgp_graceful_restart_select_defer_time,
3026 no_bgp_graceful_restart_select_defer_time_cmd,
3027 "no bgp graceful-restart select-defer-time [(0-3600)]",
3028 NO_STR
3029 BGP_STR
3030 "Graceful restart capability parameters\n"
3031 "Set the time to defer the BGP route selection after restart\n"
3032 "Delay value (seconds)\n")
3033 {
3034 VTY_DECLVAR_CONTEXT(bgp, bgp);
3035
3036 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
3037 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3038
3039 return CMD_SUCCESS;
3040 }
3041
3042 DEFUN (bgp_graceful_restart_preserve_fw,
3043 bgp_graceful_restart_preserve_fw_cmd,
3044 "bgp graceful-restart preserve-fw-state",
3045 BGP_STR
3046 "Graceful restart capability parameters\n"
3047 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
3048 {
3049 VTY_DECLVAR_CONTEXT(bgp, bgp);
3050 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3051 return CMD_SUCCESS;
3052 }
3053
3054 DEFUN (no_bgp_graceful_restart_preserve_fw,
3055 no_bgp_graceful_restart_preserve_fw_cmd,
3056 "no bgp graceful-restart preserve-fw-state",
3057 NO_STR
3058 BGP_STR
3059 "Graceful restart capability parameters\n"
3060 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3061 {
3062 VTY_DECLVAR_CONTEXT(bgp, bgp);
3063 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3064 return CMD_SUCCESS;
3065 }
3066
3067 DEFPY (bgp_graceful_restart_notification,
3068 bgp_graceful_restart_notification_cmd,
3069 "[no$no] bgp graceful-restart notification",
3070 NO_STR
3071 BGP_STR
3072 "Graceful restart capability parameters\n"
3073 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3074 {
3075 VTY_DECLVAR_CONTEXT(bgp, bgp);
3076
3077 if (no)
3078 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3079 else
3080 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3081
3082 return CMD_SUCCESS;
3083 }
3084
3085 DEFPY (bgp_administrative_reset,
3086 bgp_administrative_reset_cmd,
3087 "[no$no] bgp hard-administrative-reset",
3088 NO_STR
3089 BGP_STR
3090 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3091 {
3092 VTY_DECLVAR_CONTEXT(bgp, bgp);
3093
3094 if (no)
3095 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3096 else
3097 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3098
3099 return CMD_SUCCESS;
3100 }
3101
3102 DEFUN (bgp_graceful_restart_disable,
3103 bgp_graceful_restart_disable_cmd,
3104 "bgp graceful-restart-disable",
3105 BGP_STR
3106 GR_DISABLE)
3107 {
3108 int ret = BGP_GR_FAILURE;
3109
3110 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3111 zlog_debug(
3112 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3113
3114 VTY_DECLVAR_CONTEXT(bgp, bgp);
3115
3116 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3117
3118 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3119 bgp->peer, ret);
3120
3121 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3122 zlog_debug(
3123 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3124 vty_out(vty,
3125 "Graceful restart configuration changed, reset all peers to take effect\n");
3126
3127 return bgp_vty_return(vty, ret);
3128 }
3129
3130 DEFUN (no_bgp_graceful_restart_disable,
3131 no_bgp_graceful_restart_disable_cmd,
3132 "no bgp graceful-restart-disable",
3133 NO_STR
3134 BGP_STR
3135 NO_GR_DISABLE
3136 )
3137 {
3138 VTY_DECLVAR_CONTEXT(bgp, bgp);
3139
3140 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3141 zlog_debug(
3142 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3143
3144 int ret = BGP_GR_FAILURE;
3145
3146 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3147
3148 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3149 ret);
3150
3151 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3152 zlog_debug(
3153 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3154 vty_out(vty,
3155 "Graceful restart configuration changed, reset all peers to take effect\n");
3156
3157 return bgp_vty_return(vty, ret);
3158 }
3159
3160 DEFUN (bgp_neighbor_graceful_restart_set,
3161 bgp_neighbor_graceful_restart_set_cmd,
3162 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3163 NEIGHBOR_STR
3164 NEIGHBOR_ADDR_STR2
3165 GR_NEIGHBOR_CMD
3166 )
3167 {
3168 int idx_peer = 1;
3169 struct peer *peer;
3170 int ret = BGP_GR_FAILURE;
3171
3172 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3173
3174 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3175 zlog_debug(
3176 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3177
3178 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3179 if (!peer)
3180 return CMD_WARNING_CONFIG_FAILED;
3181
3182 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3183
3184 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3185 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3186
3187 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3188 zlog_debug(
3189 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3190 vty_out(vty,
3191 "Graceful restart configuration changed, reset this peer to take effect\n");
3192
3193 return bgp_vty_return(vty, ret);
3194 }
3195
3196 DEFUN (no_bgp_neighbor_graceful_restart,
3197 no_bgp_neighbor_graceful_restart_set_cmd,
3198 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3199 NO_STR
3200 NEIGHBOR_STR
3201 NEIGHBOR_ADDR_STR2
3202 NO_GR_NEIGHBOR_CMD
3203 )
3204 {
3205 int idx_peer = 2;
3206 int ret = BGP_GR_FAILURE;
3207 struct peer *peer;
3208
3209 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3210
3211 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3212 if (!peer)
3213 return CMD_WARNING_CONFIG_FAILED;
3214
3215 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3216 zlog_debug(
3217 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3218
3219 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3220
3221 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3222 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3223
3224 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3225 zlog_debug(
3226 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3227 vty_out(vty,
3228 "Graceful restart configuration changed, reset this peer to take effect\n");
3229
3230 return bgp_vty_return(vty, ret);
3231 }
3232
3233 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3234 bgp_neighbor_graceful_restart_helper_set_cmd,
3235 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3236 NEIGHBOR_STR
3237 NEIGHBOR_ADDR_STR2
3238 GR_NEIGHBOR_HELPER_CMD
3239 )
3240 {
3241 int idx_peer = 1;
3242 struct peer *peer;
3243 int ret = BGP_GR_FAILURE;
3244
3245 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3246
3247 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3248 zlog_debug(
3249 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3250
3251 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3252
3253 if (!peer)
3254 return CMD_WARNING_CONFIG_FAILED;
3255
3256
3257 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3258
3259 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3260 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3261
3262 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3263 zlog_debug(
3264 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3265 vty_out(vty,
3266 "Graceful restart configuration changed, reset this peer to take effect\n");
3267
3268 return bgp_vty_return(vty, ret);
3269 }
3270
3271 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3272 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3273 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3274 NO_STR
3275 NEIGHBOR_STR
3276 NEIGHBOR_ADDR_STR2
3277 NO_GR_NEIGHBOR_HELPER_CMD
3278 )
3279 {
3280 int idx_peer = 2;
3281 int ret = BGP_GR_FAILURE;
3282 struct peer *peer;
3283
3284 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3285
3286 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3287 if (!peer)
3288 return CMD_WARNING_CONFIG_FAILED;
3289
3290 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3291 zlog_debug(
3292 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3293
3294 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3295
3296 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3297 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3298
3299 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3300 zlog_debug(
3301 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3302 vty_out(vty,
3303 "Graceful restart configuration changed, reset this peer to take effect\n");
3304
3305 return bgp_vty_return(vty, ret);
3306 }
3307
3308 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3309 bgp_neighbor_graceful_restart_disable_set_cmd,
3310 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3311 NEIGHBOR_STR
3312 NEIGHBOR_ADDR_STR2
3313 GR_NEIGHBOR_DISABLE_CMD
3314 )
3315 {
3316 int idx_peer = 1;
3317 struct peer *peer;
3318 int ret = BGP_GR_FAILURE;
3319
3320 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3321
3322 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3323 zlog_debug(
3324 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3325
3326 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3327 if (!peer)
3328 return CMD_WARNING_CONFIG_FAILED;
3329
3330 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3331
3332 if (peer->bgp->t_startup)
3333 bgp_peer_gr_flags_update(peer);
3334
3335 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3336 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3337
3338 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3339 zlog_debug(
3340 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3341 vty_out(vty,
3342 "Graceful restart configuration changed, reset this peer to take effect\n");
3343
3344 return bgp_vty_return(vty, ret);
3345 }
3346
3347 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3348 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3349 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3350 NO_STR
3351 NEIGHBOR_STR
3352 NEIGHBOR_ADDR_STR2
3353 NO_GR_NEIGHBOR_DISABLE_CMD
3354 )
3355 {
3356 int idx_peer = 2;
3357 int ret = BGP_GR_FAILURE;
3358 struct peer *peer;
3359
3360 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3361
3362 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3363 if (!peer)
3364 return CMD_WARNING_CONFIG_FAILED;
3365
3366 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3367 zlog_debug(
3368 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3369
3370 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3371
3372 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3373 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3374
3375 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3376 zlog_debug(
3377 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3378 vty_out(vty,
3379 "Graceful restart configuration changed, reset this peer to take effect\n");
3380
3381 return bgp_vty_return(vty, ret);
3382 }
3383
3384 DEFPY (neighbor_graceful_shutdown,
3385 neighbor_graceful_shutdown_cmd,
3386 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3387 NO_STR
3388 NEIGHBOR_STR
3389 NEIGHBOR_ADDR_STR2
3390 "Graceful shutdown\n")
3391 {
3392 afi_t afi;
3393 safi_t safi;
3394 struct peer *peer;
3395 VTY_DECLVAR_CONTEXT(bgp, bgp);
3396 int ret;
3397
3398 peer = peer_and_group_lookup_vty(vty, neighbor);
3399 if (!peer)
3400 return CMD_WARNING_CONFIG_FAILED;
3401
3402 if (no)
3403 ret = peer_flag_unset_vty(vty, neighbor,
3404 PEER_FLAG_GRACEFUL_SHUTDOWN);
3405 else
3406 ret = peer_flag_set_vty(vty, neighbor,
3407 PEER_FLAG_GRACEFUL_SHUTDOWN);
3408
3409 FOREACH_AFI_SAFI (afi, safi) {
3410 if (!peer->afc[afi][safi])
3411 continue;
3412
3413 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3414 neighbor);
3415 }
3416
3417 return ret;
3418 }
3419
3420 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3421 bgp_graceful_restart_disable_eor_cmd,
3422 "bgp graceful-restart disable-eor",
3423 BGP_STR
3424 "Graceful restart configuration parameters\n"
3425 "Disable EOR Check\n")
3426 {
3427 VTY_DECLVAR_CONTEXT(bgp, bgp);
3428 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3429
3430 return CMD_SUCCESS;
3431 }
3432
3433 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3434 no_bgp_graceful_restart_disable_eor_cmd,
3435 "no bgp graceful-restart disable-eor",
3436 NO_STR
3437 BGP_STR
3438 "Graceful restart configuration parameters\n"
3439 "Disable EOR Check\n")
3440 {
3441 VTY_DECLVAR_CONTEXT(bgp, bgp);
3442 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3443
3444 return CMD_SUCCESS;
3445 }
3446
3447 DEFUN (bgp_graceful_restart_rib_stale_time,
3448 bgp_graceful_restart_rib_stale_time_cmd,
3449 "bgp graceful-restart rib-stale-time (1-3600)",
3450 BGP_STR
3451 "Graceful restart configuration parameters\n"
3452 "Specify the stale route removal timer in rib\n"
3453 "Delay value (seconds)\n")
3454 {
3455 VTY_DECLVAR_CONTEXT(bgp, bgp);
3456 int idx_number = 3;
3457 uint32_t stale_time;
3458
3459 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3460 bgp->rib_stale_time = stale_time;
3461 /* Send the stale timer update message to RIB */
3462 if (bgp_zebra_stale_timer_update(bgp))
3463 return CMD_WARNING;
3464
3465 return CMD_SUCCESS;
3466 }
3467
3468 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3469 no_bgp_graceful_restart_rib_stale_time_cmd,
3470 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3471 NO_STR
3472 BGP_STR
3473 "Graceful restart configuration parameters\n"
3474 "Specify the stale route removal timer in rib\n"
3475 "Delay value (seconds)\n")
3476 {
3477 VTY_DECLVAR_CONTEXT(bgp, bgp);
3478
3479 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3480 /* Send the stale timer update message to RIB */
3481 if (bgp_zebra_stale_timer_update(bgp))
3482 return CMD_WARNING;
3483
3484 return CMD_SUCCESS;
3485 }
3486
3487 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3488 "bgp long-lived-graceful-restart stale-time (1-16777215)",
3489 BGP_STR
3490 "Enable Long-lived Graceful Restart\n"
3491 "Specifies maximum time to wait before purging long-lived stale routes\n"
3492 "Stale time value (seconds)\n")
3493 {
3494 VTY_DECLVAR_CONTEXT(bgp, bgp);
3495
3496 uint32_t llgr_stale_time;
3497
3498 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3499 bgp->llgr_stale_time = llgr_stale_time;
3500
3501 return CMD_SUCCESS;
3502 }
3503
3504 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3505 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
3506 NO_STR BGP_STR
3507 "Enable Long-lived Graceful Restart\n"
3508 "Specifies maximum time to wait before purging long-lived stale routes\n"
3509 "Stale time value (seconds)\n")
3510 {
3511 VTY_DECLVAR_CONTEXT(bgp, bgp);
3512
3513 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3514
3515 return CMD_SUCCESS;
3516 }
3517
3518 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3519 struct bgp *bgp)
3520 {
3521 bgp_static_redo_import_check(bgp);
3522 bgp_redistribute_redo(bgp);
3523 bgp_clear_star_soft_out(vty, bgp->name);
3524 bgp_clear_star_soft_in(vty, bgp->name);
3525 }
3526
3527 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3528 {
3529 struct listnode *node, *nnode;
3530 struct bgp *bgp;
3531 bool vrf_cfg = false;
3532
3533 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3534 return CMD_SUCCESS;
3535
3536 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3537 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3538 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3539 vty_out(vty,
3540 "%% graceful-shutdown configuration found in vrf %s\n",
3541 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3542 VRF_DEFAULT_NAME : bgp->name);
3543 vrf_cfg = true;
3544 }
3545 }
3546
3547 if (vrf_cfg) {
3548 vty_out(vty,
3549 "%%Failed: global graceful-shutdown not permitted\n");
3550 return CMD_WARNING;
3551 }
3552
3553 /* Set flag globally */
3554 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3555
3556 /* Initiate processing for all BGP instances. */
3557 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3558 bgp_initiate_graceful_shut_unshut(vty, bgp);
3559
3560 return CMD_SUCCESS;
3561 }
3562
3563 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3564 {
3565 struct listnode *node, *nnode;
3566 struct bgp *bgp;
3567
3568 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3569 return CMD_SUCCESS;
3570
3571 /* Unset flag globally */
3572 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3573
3574 /* Initiate processing for all BGP instances. */
3575 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3576 bgp_initiate_graceful_shut_unshut(vty, bgp);
3577
3578 return CMD_SUCCESS;
3579 }
3580
3581 /* "bgp graceful-shutdown" configuration */
3582 DEFUN (bgp_graceful_shutdown,
3583 bgp_graceful_shutdown_cmd,
3584 "bgp graceful-shutdown",
3585 BGP_STR
3586 "Graceful shutdown parameters\n")
3587 {
3588 if (vty->node == CONFIG_NODE)
3589 return bgp_global_graceful_shutdown_config_vty(vty);
3590
3591 VTY_DECLVAR_CONTEXT(bgp, bgp);
3592
3593 /* if configured globally, per-instance config is not allowed */
3594 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3595 vty_out(vty,
3596 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3597 return CMD_WARNING_CONFIG_FAILED;
3598 }
3599
3600 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3601 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3602 bgp_initiate_graceful_shut_unshut(vty, bgp);
3603 }
3604
3605 return CMD_SUCCESS;
3606 }
3607
3608 DEFUN (no_bgp_graceful_shutdown,
3609 no_bgp_graceful_shutdown_cmd,
3610 "no bgp graceful-shutdown",
3611 NO_STR
3612 BGP_STR
3613 "Graceful shutdown parameters\n")
3614 {
3615 if (vty->node == CONFIG_NODE)
3616 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3617
3618 VTY_DECLVAR_CONTEXT(bgp, bgp);
3619
3620 /* If configured globally, cannot remove from one bgp instance */
3621 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3622 vty_out(vty,
3623 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3624 return CMD_WARNING_CONFIG_FAILED;
3625 }
3626
3627 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3628 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3629 bgp_initiate_graceful_shut_unshut(vty, bgp);
3630 }
3631
3632 return CMD_SUCCESS;
3633 }
3634
3635 /* "bgp fast-external-failover" configuration. */
3636 DEFUN (bgp_fast_external_failover,
3637 bgp_fast_external_failover_cmd,
3638 "bgp fast-external-failover",
3639 BGP_STR
3640 "Immediately reset session if a link to a directly connected external peer goes down\n")
3641 {
3642 VTY_DECLVAR_CONTEXT(bgp, bgp);
3643 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3644 return CMD_SUCCESS;
3645 }
3646
3647 DEFUN (no_bgp_fast_external_failover,
3648 no_bgp_fast_external_failover_cmd,
3649 "no bgp fast-external-failover",
3650 NO_STR
3651 BGP_STR
3652 "Immediately reset session if a link to a directly connected external peer goes down\n")
3653 {
3654 VTY_DECLVAR_CONTEXT(bgp, bgp);
3655 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3656 return CMD_SUCCESS;
3657 }
3658
3659 DEFPY (bgp_bestpath_aigp,
3660 bgp_bestpath_aigp_cmd,
3661 "[no$no] bgp bestpath aigp",
3662 NO_STR
3663 BGP_STR
3664 "Change the default bestpath selection\n"
3665 "Evaluate the AIGP attribute during the best path selection process\n")
3666 {
3667 VTY_DECLVAR_CONTEXT(bgp, bgp);
3668
3669 if (no)
3670 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3671 else
3672 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3673
3674 bgp_recalculate_all_bestpaths(bgp);
3675
3676 return CMD_SUCCESS;
3677 }
3678
3679 /* "bgp bestpath compare-routerid" configuration. */
3680 DEFUN (bgp_bestpath_compare_router_id,
3681 bgp_bestpath_compare_router_id_cmd,
3682 "bgp bestpath compare-routerid",
3683 BGP_STR
3684 "Change the default bestpath selection\n"
3685 "Compare router-id for identical EBGP paths\n")
3686 {
3687 VTY_DECLVAR_CONTEXT(bgp, bgp);
3688 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3689 bgp_recalculate_all_bestpaths(bgp);
3690
3691 return CMD_SUCCESS;
3692 }
3693
3694 DEFUN (no_bgp_bestpath_compare_router_id,
3695 no_bgp_bestpath_compare_router_id_cmd,
3696 "no bgp bestpath compare-routerid",
3697 NO_STR
3698 BGP_STR
3699 "Change the default bestpath selection\n"
3700 "Compare router-id for identical EBGP paths\n")
3701 {
3702 VTY_DECLVAR_CONTEXT(bgp, bgp);
3703 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3704 bgp_recalculate_all_bestpaths(bgp);
3705
3706 return CMD_SUCCESS;
3707 }
3708
3709 /* "bgp bestpath as-path ignore" configuration. */
3710 DEFUN (bgp_bestpath_aspath_ignore,
3711 bgp_bestpath_aspath_ignore_cmd,
3712 "bgp bestpath as-path ignore",
3713 BGP_STR
3714 "Change the default bestpath selection\n"
3715 "AS-path attribute\n"
3716 "Ignore as-path length in selecting a route\n")
3717 {
3718 VTY_DECLVAR_CONTEXT(bgp, bgp);
3719 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3720 bgp_recalculate_all_bestpaths(bgp);
3721
3722 return CMD_SUCCESS;
3723 }
3724
3725 DEFUN (no_bgp_bestpath_aspath_ignore,
3726 no_bgp_bestpath_aspath_ignore_cmd,
3727 "no bgp bestpath as-path ignore",
3728 NO_STR
3729 BGP_STR
3730 "Change the default bestpath selection\n"
3731 "AS-path attribute\n"
3732 "Ignore as-path length in selecting a route\n")
3733 {
3734 VTY_DECLVAR_CONTEXT(bgp, bgp);
3735 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3736 bgp_recalculate_all_bestpaths(bgp);
3737
3738 return CMD_SUCCESS;
3739 }
3740
3741 /* "bgp bestpath as-path confed" configuration. */
3742 DEFUN (bgp_bestpath_aspath_confed,
3743 bgp_bestpath_aspath_confed_cmd,
3744 "bgp bestpath as-path confed",
3745 BGP_STR
3746 "Change the default bestpath selection\n"
3747 "AS-path attribute\n"
3748 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3749 {
3750 VTY_DECLVAR_CONTEXT(bgp, bgp);
3751 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3752 bgp_recalculate_all_bestpaths(bgp);
3753
3754 return CMD_SUCCESS;
3755 }
3756
3757 DEFUN (no_bgp_bestpath_aspath_confed,
3758 no_bgp_bestpath_aspath_confed_cmd,
3759 "no bgp bestpath as-path confed",
3760 NO_STR
3761 BGP_STR
3762 "Change the default bestpath selection\n"
3763 "AS-path attribute\n"
3764 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3765 {
3766 VTY_DECLVAR_CONTEXT(bgp, bgp);
3767 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3768 bgp_recalculate_all_bestpaths(bgp);
3769
3770 return CMD_SUCCESS;
3771 }
3772
3773 /* "bgp bestpath as-path multipath-relax" configuration. */
3774 DEFUN (bgp_bestpath_aspath_multipath_relax,
3775 bgp_bestpath_aspath_multipath_relax_cmd,
3776 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3777 BGP_STR
3778 "Change the default bestpath selection\n"
3779 "AS-path attribute\n"
3780 "Allow load sharing across routes that have different AS paths (but same length)\n"
3781 "Generate an AS_SET\n"
3782 "Do not generate an AS_SET\n")
3783 {
3784 VTY_DECLVAR_CONTEXT(bgp, bgp);
3785 int idx = 0;
3786 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3787
3788 /* no-as-set is now the default behavior so we can silently
3789 * ignore it */
3790 if (argv_find(argv, argc, "as-set", &idx))
3791 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3792 else
3793 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3794
3795 bgp_recalculate_all_bestpaths(bgp);
3796
3797 return CMD_SUCCESS;
3798 }
3799
3800 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3801 no_bgp_bestpath_aspath_multipath_relax_cmd,
3802 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3803 NO_STR
3804 BGP_STR
3805 "Change the default bestpath selection\n"
3806 "AS-path attribute\n"
3807 "Allow load sharing across routes that have different AS paths (but same length)\n"
3808 "Generate an AS_SET\n"
3809 "Do not generate an AS_SET\n")
3810 {
3811 VTY_DECLVAR_CONTEXT(bgp, bgp);
3812 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3813 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3814 bgp_recalculate_all_bestpaths(bgp);
3815
3816 return CMD_SUCCESS;
3817 }
3818
3819 /* "bgp bestpath peer-type multipath-relax" configuration. */
3820 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3821 bgp_bestpath_peer_type_multipath_relax_cmd,
3822 "bgp bestpath peer-type multipath-relax",
3823 BGP_STR
3824 "Change the default bestpath selection\n"
3825 "Peer type\n"
3826 "Allow load sharing across routes learned from different peer types\n")
3827 {
3828 VTY_DECLVAR_CONTEXT(bgp, bgp);
3829 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3830 bgp_recalculate_all_bestpaths(bgp);
3831
3832 return CMD_SUCCESS;
3833 }
3834
3835 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3836 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3837 "no bgp bestpath peer-type multipath-relax",
3838 NO_STR BGP_STR
3839 "Change the default bestpath selection\n"
3840 "Peer type\n"
3841 "Allow load sharing across routes learned from different peer types\n")
3842 {
3843 VTY_DECLVAR_CONTEXT(bgp, bgp);
3844 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3845 bgp_recalculate_all_bestpaths(bgp);
3846
3847 return CMD_SUCCESS;
3848 }
3849
3850 /* "bgp log-neighbor-changes" configuration. */
3851 DEFUN (bgp_log_neighbor_changes,
3852 bgp_log_neighbor_changes_cmd,
3853 "bgp log-neighbor-changes",
3854 BGP_STR
3855 "Log neighbor up/down and reset reason\n")
3856 {
3857 VTY_DECLVAR_CONTEXT(bgp, bgp);
3858 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3859 return CMD_SUCCESS;
3860 }
3861
3862 DEFUN (no_bgp_log_neighbor_changes,
3863 no_bgp_log_neighbor_changes_cmd,
3864 "no bgp log-neighbor-changes",
3865 NO_STR
3866 BGP_STR
3867 "Log neighbor up/down and reset reason\n")
3868 {
3869 VTY_DECLVAR_CONTEXT(bgp, bgp);
3870 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3871 return CMD_SUCCESS;
3872 }
3873
3874 /* "bgp bestpath med" configuration. */
3875 DEFUN (bgp_bestpath_med,
3876 bgp_bestpath_med_cmd,
3877 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3878 BGP_STR
3879 "Change the default bestpath selection\n"
3880 "MED attribute\n"
3881 "Compare MED among confederation paths\n"
3882 "Treat missing MED as the least preferred one\n"
3883 "Treat missing MED as the least preferred one\n"
3884 "Compare MED among confederation paths\n")
3885 {
3886 VTY_DECLVAR_CONTEXT(bgp, bgp);
3887
3888 int idx = 0;
3889 if (argv_find(argv, argc, "confed", &idx))
3890 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3891 idx = 0;
3892 if (argv_find(argv, argc, "missing-as-worst", &idx))
3893 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3894
3895 bgp_recalculate_all_bestpaths(bgp);
3896
3897 return CMD_SUCCESS;
3898 }
3899
3900 DEFUN (no_bgp_bestpath_med,
3901 no_bgp_bestpath_med_cmd,
3902 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3903 NO_STR
3904 BGP_STR
3905 "Change the default bestpath selection\n"
3906 "MED attribute\n"
3907 "Compare MED among confederation paths\n"
3908 "Treat missing MED as the least preferred one\n"
3909 "Treat missing MED as the least preferred one\n"
3910 "Compare MED among confederation paths\n")
3911 {
3912 VTY_DECLVAR_CONTEXT(bgp, bgp);
3913
3914 int idx = 0;
3915 if (argv_find(argv, argc, "confed", &idx))
3916 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3917 idx = 0;
3918 if (argv_find(argv, argc, "missing-as-worst", &idx))
3919 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3920
3921 bgp_recalculate_all_bestpaths(bgp);
3922
3923 return CMD_SUCCESS;
3924 }
3925
3926 /* "bgp bestpath bandwidth" configuration. */
3927 DEFPY (bgp_bestpath_bw,
3928 bgp_bestpath_bw_cmd,
3929 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3930 BGP_STR
3931 "Change the default bestpath selection\n"
3932 "Link Bandwidth attribute\n"
3933 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3934 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3935 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3936 {
3937 VTY_DECLVAR_CONTEXT(bgp, bgp);
3938 afi_t afi;
3939 safi_t safi;
3940
3941 if (!bw_cfg) {
3942 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3943 return CMD_ERR_INCOMPLETE;
3944 }
3945 if (!strcmp(bw_cfg, "ignore"))
3946 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3947 else if (!strcmp(bw_cfg, "skip-missing"))
3948 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3949 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3950 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3951 else
3952 return CMD_ERR_NO_MATCH;
3953
3954 /* This config is used in route install, so redo that. */
3955 FOREACH_AFI_SAFI (afi, safi) {
3956 if (!bgp_fibupd_safi(safi))
3957 continue;
3958 bgp_zebra_announce_table(bgp, afi, safi);
3959 }
3960
3961 return CMD_SUCCESS;
3962 }
3963
3964 DEFPY (no_bgp_bestpath_bw,
3965 no_bgp_bestpath_bw_cmd,
3966 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3967 NO_STR
3968 BGP_STR
3969 "Change the default bestpath selection\n"
3970 "Link Bandwidth attribute\n"
3971 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3972 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3973 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3974 {
3975 VTY_DECLVAR_CONTEXT(bgp, bgp);
3976 afi_t afi;
3977 safi_t safi;
3978
3979 bgp->lb_handling = BGP_LINK_BW_ECMP;
3980
3981 /* This config is used in route install, so redo that. */
3982 FOREACH_AFI_SAFI (afi, safi) {
3983 if (!bgp_fibupd_safi(safi))
3984 continue;
3985 bgp_zebra_announce_table(bgp, afi, safi);
3986 }
3987 return CMD_SUCCESS;
3988 }
3989
3990 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3991 "[no] bgp default <ipv4-unicast|"
3992 "ipv4-multicast|"
3993 "ipv4-vpn|"
3994 "ipv4-labeled-unicast|"
3995 "ipv4-flowspec|"
3996 "ipv6-unicast|"
3997 "ipv6-multicast|"
3998 "ipv6-vpn|"
3999 "ipv6-labeled-unicast|"
4000 "ipv6-flowspec|"
4001 "l2vpn-evpn>$afi_safi",
4002 NO_STR
4003 BGP_STR
4004 "Configure BGP defaults\n"
4005 "Activate ipv4-unicast for a peer by default\n"
4006 "Activate ipv4-multicast for a peer by default\n"
4007 "Activate ipv4-vpn for a peer by default\n"
4008 "Activate ipv4-labeled-unicast for a peer by default\n"
4009 "Activate ipv4-flowspec for a peer by default\n"
4010 "Activate ipv6-unicast for a peer by default\n"
4011 "Activate ipv6-multicast for a peer by default\n"
4012 "Activate ipv6-vpn for a peer by default\n"
4013 "Activate ipv6-labeled-unicast for a peer by default\n"
4014 "Activate ipv6-flowspec for a peer by default\n"
4015 "Activate l2vpn-evpn for a peer by default\n")
4016 {
4017 VTY_DECLVAR_CONTEXT(bgp, bgp);
4018 char afi_safi_str[strlen(afi_safi) + 1];
4019 char *afi_safi_str_tok;
4020
4021 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4022 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4023 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4024 afi_t afi = bgp_vty_afi_from_str(afi_str);
4025 safi_t safi;
4026
4027 /*
4028 * Impossible situation but making coverity happy
4029 */
4030 assert(afi != AFI_MAX);
4031
4032 if (strmatch(safi_str, "labeled"))
4033 safi = bgp_vty_safi_from_str("labeled-unicast");
4034 else
4035 safi = bgp_vty_safi_from_str(safi_str);
4036
4037 assert(safi != SAFI_MAX);
4038 if (no)
4039 bgp->default_af[afi][safi] = false;
4040 else {
4041 if ((safi == SAFI_LABELED_UNICAST
4042 && bgp->default_af[afi][SAFI_UNICAST])
4043 || (safi == SAFI_UNICAST
4044 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4045 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4046 else
4047 bgp->default_af[afi][safi] = true;
4048 }
4049
4050 return CMD_SUCCESS;
4051 }
4052
4053 /* Display hostname in certain command outputs */
4054 DEFUN (bgp_default_show_hostname,
4055 bgp_default_show_hostname_cmd,
4056 "bgp default show-hostname",
4057 BGP_STR
4058 "Configure BGP defaults\n"
4059 "Show hostname in certain command outputs\n")
4060 {
4061 VTY_DECLVAR_CONTEXT(bgp, bgp);
4062 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4063 return CMD_SUCCESS;
4064 }
4065
4066 DEFUN (no_bgp_default_show_hostname,
4067 no_bgp_default_show_hostname_cmd,
4068 "no bgp default show-hostname",
4069 NO_STR
4070 BGP_STR
4071 "Configure BGP defaults\n"
4072 "Show hostname in certain command outputs\n")
4073 {
4074 VTY_DECLVAR_CONTEXT(bgp, bgp);
4075 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4076 return CMD_SUCCESS;
4077 }
4078
4079 /* Display hostname in certain command outputs */
4080 DEFUN (bgp_default_show_nexthop_hostname,
4081 bgp_default_show_nexthop_hostname_cmd,
4082 "bgp default show-nexthop-hostname",
4083 BGP_STR
4084 "Configure BGP defaults\n"
4085 "Show hostname for nexthop in certain command outputs\n")
4086 {
4087 VTY_DECLVAR_CONTEXT(bgp, bgp);
4088 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4089 return CMD_SUCCESS;
4090 }
4091
4092 DEFUN (no_bgp_default_show_nexthop_hostname,
4093 no_bgp_default_show_nexthop_hostname_cmd,
4094 "no bgp default show-nexthop-hostname",
4095 NO_STR
4096 BGP_STR
4097 "Configure BGP defaults\n"
4098 "Show hostname for nexthop in certain command outputs\n")
4099 {
4100 VTY_DECLVAR_CONTEXT(bgp, bgp);
4101 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4102 return CMD_SUCCESS;
4103 }
4104
4105 /* "bgp network import-check" configuration. */
4106 DEFUN (bgp_network_import_check,
4107 bgp_network_import_check_cmd,
4108 "bgp network import-check",
4109 BGP_STR
4110 "BGP network command\n"
4111 "Check BGP network route exists in IGP\n")
4112 {
4113 VTY_DECLVAR_CONTEXT(bgp, bgp);
4114 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4115 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4116 bgp_static_redo_import_check(bgp);
4117 }
4118
4119 return CMD_SUCCESS;
4120 }
4121
4122 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4123 "bgp network import-check exact",
4124 BGP_STR
4125 "BGP network command\n"
4126 "Check BGP network route exists in IGP\n"
4127 "Match route precisely\n")
4128
4129 DEFUN (no_bgp_network_import_check,
4130 no_bgp_network_import_check_cmd,
4131 "no bgp network import-check",
4132 NO_STR
4133 BGP_STR
4134 "BGP network command\n"
4135 "Check BGP network route exists in IGP\n")
4136 {
4137 VTY_DECLVAR_CONTEXT(bgp, bgp);
4138 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4139 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4140 bgp_static_redo_import_check(bgp);
4141 }
4142
4143 return CMD_SUCCESS;
4144 }
4145
4146 DEFUN (bgp_default_local_preference,
4147 bgp_default_local_preference_cmd,
4148 "bgp default local-preference (0-4294967295)",
4149 BGP_STR
4150 "Configure BGP defaults\n"
4151 "local preference (higher=more preferred)\n"
4152 "Configure default local preference value\n")
4153 {
4154 VTY_DECLVAR_CONTEXT(bgp, bgp);
4155 int idx_number = 3;
4156 uint32_t local_pref;
4157
4158 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4159
4160 bgp_default_local_preference_set(bgp, local_pref);
4161 bgp_clear_star_soft_in(vty, bgp->name);
4162
4163 return CMD_SUCCESS;
4164 }
4165
4166 DEFUN (no_bgp_default_local_preference,
4167 no_bgp_default_local_preference_cmd,
4168 "no bgp default local-preference [(0-4294967295)]",
4169 NO_STR
4170 BGP_STR
4171 "Configure BGP defaults\n"
4172 "local preference (higher=more preferred)\n"
4173 "Configure default local preference value\n")
4174 {
4175 VTY_DECLVAR_CONTEXT(bgp, bgp);
4176 bgp_default_local_preference_unset(bgp);
4177 bgp_clear_star_soft_in(vty, bgp->name);
4178
4179 return CMD_SUCCESS;
4180 }
4181
4182
4183 DEFUN (bgp_default_subgroup_pkt_queue_max,
4184 bgp_default_subgroup_pkt_queue_max_cmd,
4185 "bgp default subgroup-pkt-queue-max (20-100)",
4186 BGP_STR
4187 "Configure BGP defaults\n"
4188 "subgroup-pkt-queue-max\n"
4189 "Configure subgroup packet queue max\n")
4190 {
4191 VTY_DECLVAR_CONTEXT(bgp, bgp);
4192 int idx_number = 3;
4193 uint32_t max_size;
4194
4195 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4196
4197 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4198
4199 return CMD_SUCCESS;
4200 }
4201
4202 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4203 no_bgp_default_subgroup_pkt_queue_max_cmd,
4204 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4205 NO_STR
4206 BGP_STR
4207 "Configure BGP defaults\n"
4208 "subgroup-pkt-queue-max\n"
4209 "Configure subgroup packet queue max\n")
4210 {
4211 VTY_DECLVAR_CONTEXT(bgp, bgp);
4212 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4213 return CMD_SUCCESS;
4214 }
4215
4216
4217 DEFUN (bgp_rr_allow_outbound_policy,
4218 bgp_rr_allow_outbound_policy_cmd,
4219 "bgp route-reflector allow-outbound-policy",
4220 BGP_STR
4221 "Allow modifications made by out route-map\n"
4222 "on ibgp neighbors\n")
4223 {
4224 VTY_DECLVAR_CONTEXT(bgp, bgp);
4225
4226 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4227 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4228 update_group_announce_rrclients(bgp);
4229 bgp_clear_star_soft_out(vty, bgp->name);
4230 }
4231
4232 return CMD_SUCCESS;
4233 }
4234
4235 DEFUN (no_bgp_rr_allow_outbound_policy,
4236 no_bgp_rr_allow_outbound_policy_cmd,
4237 "no bgp route-reflector allow-outbound-policy",
4238 NO_STR
4239 BGP_STR
4240 "Allow modifications made by out route-map\n"
4241 "on ibgp neighbors\n")
4242 {
4243 VTY_DECLVAR_CONTEXT(bgp, bgp);
4244
4245 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4246 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4247 update_group_announce_rrclients(bgp);
4248 bgp_clear_star_soft_out(vty, bgp->name);
4249 }
4250
4251 return CMD_SUCCESS;
4252 }
4253
4254 DEFUN (bgp_listen_limit,
4255 bgp_listen_limit_cmd,
4256 "bgp listen limit (1-65535)",
4257 BGP_STR
4258 "BGP Dynamic Neighbors listen commands\n"
4259 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4260 "Configure Dynamic Neighbors listen limit value\n")
4261 {
4262 VTY_DECLVAR_CONTEXT(bgp, bgp);
4263 int idx_number = 3;
4264 int listen_limit;
4265
4266 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4267
4268 bgp_listen_limit_set(bgp, listen_limit);
4269
4270 return CMD_SUCCESS;
4271 }
4272
4273 DEFUN (no_bgp_listen_limit,
4274 no_bgp_listen_limit_cmd,
4275 "no bgp listen limit [(1-65535)]",
4276 NO_STR
4277 BGP_STR
4278 "BGP Dynamic Neighbors listen commands\n"
4279 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4280 "Configure Dynamic Neighbors listen limit value\n")
4281 {
4282 VTY_DECLVAR_CONTEXT(bgp, bgp);
4283 bgp_listen_limit_unset(bgp);
4284 return CMD_SUCCESS;
4285 }
4286
4287
4288 /*
4289 * Check if this listen range is already configured. Check for exact
4290 * match or overlap based on input.
4291 */
4292 static struct peer_group *listen_range_exists(struct bgp *bgp,
4293 struct prefix *range, int exact)
4294 {
4295 struct listnode *node, *nnode;
4296 struct listnode *node1, *nnode1;
4297 struct peer_group *group;
4298 struct prefix *lr;
4299 afi_t afi;
4300 int match;
4301
4302 afi = family2afi(range->family);
4303 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4304 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4305 lr)) {
4306 if (exact)
4307 match = prefix_same(range, lr);
4308 else
4309 match = (prefix_match(range, lr)
4310 || prefix_match(lr, range));
4311 if (match)
4312 return group;
4313 }
4314 }
4315
4316 return NULL;
4317 }
4318
4319 DEFUN (bgp_listen_range,
4320 bgp_listen_range_cmd,
4321 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4322 BGP_STR
4323 "Configure BGP dynamic neighbors listen range\n"
4324 "Configure BGP dynamic neighbors listen range\n"
4325 NEIGHBOR_ADDR_STR
4326 "Member of the peer-group\n"
4327 "Peer-group name\n")
4328 {
4329 VTY_DECLVAR_CONTEXT(bgp, bgp);
4330 struct prefix range;
4331 struct peer_group *group, *existing_group;
4332 afi_t afi;
4333 int ret;
4334 int idx = 0;
4335
4336 argv_find(argv, argc, "A.B.C.D/M", &idx);
4337 argv_find(argv, argc, "X:X::X:X/M", &idx);
4338 char *prefix = argv[idx]->arg;
4339 argv_find(argv, argc, "PGNAME", &idx);
4340 char *peergroup = argv[idx]->arg;
4341
4342 /* Convert IP prefix string to struct prefix. */
4343 ret = str2prefix(prefix, &range);
4344 if (!ret) {
4345 vty_out(vty, "%% Malformed listen range\n");
4346 return CMD_WARNING_CONFIG_FAILED;
4347 }
4348
4349 afi = family2afi(range.family);
4350
4351 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4352 vty_out(vty,
4353 "%% Malformed listen range (link-local address)\n");
4354 return CMD_WARNING_CONFIG_FAILED;
4355 }
4356
4357 apply_mask(&range);
4358
4359 /* Check if same listen range is already configured. */
4360 existing_group = listen_range_exists(bgp, &range, 1);
4361 if (existing_group) {
4362 if (strcmp(existing_group->name, peergroup) == 0)
4363 return CMD_SUCCESS;
4364 else {
4365 vty_out(vty,
4366 "%% Same listen range is attached to peer-group %s\n",
4367 existing_group->name);
4368 return CMD_WARNING_CONFIG_FAILED;
4369 }
4370 }
4371
4372 /* Check if an overlapping listen range exists. */
4373 if (listen_range_exists(bgp, &range, 0)) {
4374 vty_out(vty,
4375 "%% Listen range overlaps with existing listen range\n");
4376 return CMD_WARNING_CONFIG_FAILED;
4377 }
4378
4379 group = peer_group_lookup(bgp, peergroup);
4380 if (!group) {
4381 vty_out(vty, "%% Configure the peer-group first\n");
4382 return CMD_WARNING_CONFIG_FAILED;
4383 }
4384
4385 ret = peer_group_listen_range_add(group, &range);
4386 return bgp_vty_return(vty, ret);
4387 }
4388
4389 DEFUN (no_bgp_listen_range,
4390 no_bgp_listen_range_cmd,
4391 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4392 NO_STR
4393 BGP_STR
4394 "Unconfigure BGP dynamic neighbors listen range\n"
4395 "Unconfigure BGP dynamic neighbors listen range\n"
4396 NEIGHBOR_ADDR_STR
4397 "Member of the peer-group\n"
4398 "Peer-group name\n")
4399 {
4400 VTY_DECLVAR_CONTEXT(bgp, bgp);
4401 struct prefix range;
4402 struct peer_group *group;
4403 afi_t afi;
4404 int ret;
4405 int idx = 0;
4406
4407 argv_find(argv, argc, "A.B.C.D/M", &idx);
4408 argv_find(argv, argc, "X:X::X:X/M", &idx);
4409 char *prefix = argv[idx]->arg;
4410 argv_find(argv, argc, "PGNAME", &idx);
4411 char *peergroup = argv[idx]->arg;
4412
4413 /* Convert IP prefix string to struct prefix. */
4414 ret = str2prefix(prefix, &range);
4415 if (!ret) {
4416 vty_out(vty, "%% Malformed listen range\n");
4417 return CMD_WARNING_CONFIG_FAILED;
4418 }
4419
4420 afi = family2afi(range.family);
4421
4422 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4423 vty_out(vty,
4424 "%% Malformed listen range (link-local address)\n");
4425 return CMD_WARNING_CONFIG_FAILED;
4426 }
4427
4428 apply_mask(&range);
4429
4430 group = peer_group_lookup(bgp, peergroup);
4431 if (!group) {
4432 vty_out(vty, "%% Peer-group does not exist\n");
4433 return CMD_WARNING_CONFIG_FAILED;
4434 }
4435
4436 ret = peer_group_listen_range_del(group, &range);
4437 return bgp_vty_return(vty, ret);
4438 }
4439
4440 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4441 {
4442 struct peer_group *group;
4443 struct listnode *node, *nnode, *rnode, *nrnode;
4444 struct prefix *range;
4445 afi_t afi;
4446
4447 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4448 vty_out(vty, " bgp listen limit %d\n",
4449 bgp->dynamic_neighbors_limit);
4450
4451 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4452 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4453 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4454 nrnode, range)) {
4455 vty_out(vty,
4456 " bgp listen range %pFX peer-group %s\n",
4457 range, group->name);
4458 }
4459 }
4460 }
4461 }
4462
4463
4464 DEFUN (bgp_disable_connected_route_check,
4465 bgp_disable_connected_route_check_cmd,
4466 "bgp disable-ebgp-connected-route-check",
4467 BGP_STR
4468 "Disable checking if nexthop is connected on ebgp sessions\n")
4469 {
4470 VTY_DECLVAR_CONTEXT(bgp, bgp);
4471 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4472 bgp_clear_star_soft_in(vty, bgp->name);
4473
4474 return CMD_SUCCESS;
4475 }
4476
4477 DEFUN (no_bgp_disable_connected_route_check,
4478 no_bgp_disable_connected_route_check_cmd,
4479 "no bgp disable-ebgp-connected-route-check",
4480 NO_STR
4481 BGP_STR
4482 "Disable checking if nexthop is connected on ebgp sessions\n")
4483 {
4484 VTY_DECLVAR_CONTEXT(bgp, bgp);
4485 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4486 bgp_clear_star_soft_in(vty, bgp->name);
4487
4488 return CMD_SUCCESS;
4489 }
4490
4491
4492 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4493 const char *as_str)
4494 {
4495 VTY_DECLVAR_CONTEXT(bgp, bgp);
4496 int ret;
4497 as_t as;
4498 int as_type = AS_SPECIFIED;
4499 union sockunion su;
4500
4501 if (as_str[0] == 'i') {
4502 as = 0;
4503 as_type = AS_INTERNAL;
4504 } else if (as_str[0] == 'e') {
4505 as = 0;
4506 as_type = AS_EXTERNAL;
4507 } else {
4508 /* Get AS number. */
4509 as = strtoul(as_str, NULL, 10);
4510 }
4511
4512 /* If peer is peer group or interface peer, call proper function. */
4513 ret = str2sockunion(peer_str, &su);
4514 if (ret < 0) {
4515 struct peer *peer;
4516
4517 /* Check if existing interface peer */
4518 peer = peer_lookup_by_conf_if(bgp, peer_str);
4519
4520 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4521
4522 /* if not interface peer, check peer-group settings */
4523 if (ret < 0 && !peer) {
4524 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4525 if (ret < 0) {
4526 vty_out(vty,
4527 "%% Create the peer-group or interface first\n");
4528 return CMD_WARNING_CONFIG_FAILED;
4529 }
4530 return CMD_SUCCESS;
4531 }
4532 } else {
4533 if (peer_address_self_check(bgp, &su)) {
4534 vty_out(vty,
4535 "%% Can not configure the local system as neighbor\n");
4536 return CMD_WARNING_CONFIG_FAILED;
4537 }
4538 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4539 }
4540
4541 return bgp_vty_return(vty, ret);
4542 }
4543
4544 DEFUN (bgp_default_shutdown,
4545 bgp_default_shutdown_cmd,
4546 "[no] bgp default shutdown",
4547 NO_STR
4548 BGP_STR
4549 "Configure BGP defaults\n"
4550 "Apply administrative shutdown to newly configured peers\n")
4551 {
4552 VTY_DECLVAR_CONTEXT(bgp, bgp);
4553 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4554 return CMD_SUCCESS;
4555 }
4556
4557 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4558 BGP_STR
4559 "Administrative shutdown of the BGP instance\n"
4560 "Add a shutdown message (RFC 8203)\n"
4561 "Shutdown message\n")
4562 {
4563 char *msgstr = NULL;
4564
4565 VTY_DECLVAR_CONTEXT(bgp, bgp);
4566
4567 if (argc > 3)
4568 msgstr = argv_concat(argv, argc, 3);
4569
4570 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4571 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4572 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4573 return CMD_WARNING_CONFIG_FAILED;
4574 }
4575
4576 bgp_shutdown_enable(bgp, msgstr);
4577 XFREE(MTYPE_TMP, msgstr);
4578
4579 return CMD_SUCCESS;
4580 }
4581
4582 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4583 BGP_STR "Administrative shutdown of the BGP instance\n")
4584 {
4585 VTY_DECLVAR_CONTEXT(bgp, bgp);
4586
4587 bgp_shutdown_enable(bgp, NULL);
4588
4589 return CMD_SUCCESS;
4590 }
4591
4592 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4593 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4594 {
4595 VTY_DECLVAR_CONTEXT(bgp, bgp);
4596
4597 bgp_shutdown_disable(bgp);
4598
4599 return CMD_SUCCESS;
4600 }
4601
4602 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4603 "no bgp shutdown message MSG...", NO_STR BGP_STR
4604 "Administrative shutdown of the BGP instance\n"
4605 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4606
4607 DEFUN (neighbor_remote_as,
4608 neighbor_remote_as_cmd,
4609 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4610 NEIGHBOR_STR
4611 NEIGHBOR_ADDR_STR2
4612 "Specify a BGP neighbor\n"
4613 AS_STR
4614 "Internal BGP peer\n"
4615 "External BGP peer\n")
4616 {
4617 int idx_peer = 1;
4618 int idx_remote_as = 3;
4619 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4620 argv[idx_remote_as]->arg);
4621 }
4622
4623 DEFPY (bgp_allow_martian,
4624 bgp_allow_martian_cmd,
4625 "[no]$no bgp allow-martian-nexthop",
4626 NO_STR
4627 BGP_STR
4628 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4629 {
4630 VTY_DECLVAR_CONTEXT(bgp, bgp);
4631
4632 if (no)
4633 bgp->allow_martian = false;
4634 else
4635 bgp->allow_martian = true;
4636
4637 return CMD_SUCCESS;
4638 }
4639
4640 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4641 * sessions do not wait for hold timer expiry to bring down the sessions
4642 * when nexthop becomes unreachable
4643 */
4644 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4645 BGP_STR "Fast convergence for bgp sessions\n")
4646 {
4647 VTY_DECLVAR_CONTEXT(bgp, bgp);
4648 bgp->fast_convergence = true;
4649
4650 return CMD_SUCCESS;
4651 }
4652
4653 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4654 "no bgp fast-convergence",
4655 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4656 {
4657 VTY_DECLVAR_CONTEXT(bgp, bgp);
4658 bgp->fast_convergence = false;
4659
4660 return CMD_SUCCESS;
4661 }
4662
4663 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4664 int v6only,
4665 const char *peer_group_name,
4666 const char *as_str)
4667 {
4668 VTY_DECLVAR_CONTEXT(bgp, bgp);
4669 as_t as = 0;
4670 int as_type = AS_UNSPECIFIED;
4671 struct peer *peer;
4672 struct peer_group *group;
4673 int ret = 0;
4674
4675 group = peer_group_lookup(bgp, conf_if);
4676
4677 if (group) {
4678 vty_out(vty, "%% Name conflict with peer-group \n");
4679 return CMD_WARNING_CONFIG_FAILED;
4680 }
4681
4682 if (as_str) {
4683 if (as_str[0] == 'i') {
4684 as_type = AS_INTERNAL;
4685 } else if (as_str[0] == 'e') {
4686 as_type = AS_EXTERNAL;
4687 } else {
4688 /* Get AS number. */
4689 as = strtoul(as_str, NULL, 10);
4690 as_type = AS_SPECIFIED;
4691 }
4692 }
4693
4694 peer = peer_lookup_by_conf_if(bgp, conf_if);
4695 if (peer) {
4696 if (as_str)
4697 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4698 } else {
4699 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4700 NULL, true);
4701
4702 if (!peer) {
4703 vty_out(vty, "%% BGP failed to create peer\n");
4704 return CMD_WARNING_CONFIG_FAILED;
4705 }
4706
4707 if (v6only)
4708 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4709
4710 /* Request zebra to initiate IPv6 RAs on this interface. We do
4711 * this
4712 * any unnumbered peer in order to not worry about run-time
4713 * transitions
4714 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4715 * address
4716 * gets deleted later etc.)
4717 */
4718 if (peer->ifp)
4719 bgp_zebra_initiate_radv(bgp, peer);
4720 }
4721
4722 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4723 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4724 if (v6only)
4725 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4726 else
4727 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4728
4729 /* v6only flag changed. Reset bgp seesion */
4730 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4731 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4732 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4733 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4734 } else
4735 bgp_session_reset(peer);
4736 }
4737
4738 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4739 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4740 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4741 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4742 }
4743
4744 if (peer_group_name) {
4745 group = peer_group_lookup(bgp, peer_group_name);
4746 if (!group) {
4747 vty_out(vty, "%% Configure the peer-group first\n");
4748 return CMD_WARNING_CONFIG_FAILED;
4749 }
4750
4751 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4752 }
4753
4754 return bgp_vty_return(vty, ret);
4755 }
4756
4757 DEFUN (neighbor_interface_config,
4758 neighbor_interface_config_cmd,
4759 "neighbor WORD interface [peer-group PGNAME]",
4760 NEIGHBOR_STR
4761 "Interface name or neighbor tag\n"
4762 "Enable BGP on interface\n"
4763 "Member of the peer-group\n"
4764 "Peer-group name\n")
4765 {
4766 int idx_word = 1;
4767 int idx_peer_group_word = 4;
4768
4769 if (argc > idx_peer_group_word)
4770 return peer_conf_interface_get(
4771 vty, argv[idx_word]->arg, 0,
4772 argv[idx_peer_group_word]->arg, NULL);
4773 else
4774 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4775 NULL, NULL);
4776 }
4777
4778 DEFUN (neighbor_interface_config_v6only,
4779 neighbor_interface_config_v6only_cmd,
4780 "neighbor WORD interface v6only [peer-group PGNAME]",
4781 NEIGHBOR_STR
4782 "Interface name or neighbor tag\n"
4783 "Enable BGP on interface\n"
4784 "Enable BGP with v6 link-local only\n"
4785 "Member of the peer-group\n"
4786 "Peer-group name\n")
4787 {
4788 int idx_word = 1;
4789 int idx_peer_group_word = 5;
4790
4791 if (argc > idx_peer_group_word)
4792 return peer_conf_interface_get(
4793 vty, argv[idx_word]->arg, 1,
4794 argv[idx_peer_group_word]->arg, NULL);
4795
4796 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4797 }
4798
4799
4800 DEFUN (neighbor_interface_config_remote_as,
4801 neighbor_interface_config_remote_as_cmd,
4802 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4803 NEIGHBOR_STR
4804 "Interface name or neighbor tag\n"
4805 "Enable BGP on interface\n"
4806 "Specify a BGP neighbor\n"
4807 AS_STR
4808 "Internal BGP peer\n"
4809 "External BGP peer\n")
4810 {
4811 int idx_word = 1;
4812 int idx_remote_as = 4;
4813 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4814 argv[idx_remote_as]->arg);
4815 }
4816
4817 DEFUN (neighbor_interface_v6only_config_remote_as,
4818 neighbor_interface_v6only_config_remote_as_cmd,
4819 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4820 NEIGHBOR_STR
4821 "Interface name or neighbor tag\n"
4822 "Enable BGP with v6 link-local only\n"
4823 "Enable BGP on interface\n"
4824 "Specify a BGP neighbor\n"
4825 AS_STR
4826 "Internal BGP peer\n"
4827 "External BGP peer\n")
4828 {
4829 int idx_word = 1;
4830 int idx_remote_as = 5;
4831 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4832 argv[idx_remote_as]->arg);
4833 }
4834
4835 DEFUN (neighbor_peer_group,
4836 neighbor_peer_group_cmd,
4837 "neighbor WORD peer-group",
4838 NEIGHBOR_STR
4839 "Interface name or neighbor tag\n"
4840 "Configure peer-group\n")
4841 {
4842 VTY_DECLVAR_CONTEXT(bgp, bgp);
4843 int idx_word = 1;
4844 struct peer *peer;
4845 struct peer_group *group;
4846
4847 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4848 if (peer) {
4849 vty_out(vty, "%% Name conflict with interface: \n");
4850 return CMD_WARNING_CONFIG_FAILED;
4851 }
4852
4853 group = peer_group_get(bgp, argv[idx_word]->arg);
4854 if (!group) {
4855 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4856 return CMD_WARNING_CONFIG_FAILED;
4857 }
4858
4859 return CMD_SUCCESS;
4860 }
4861
4862 DEFUN (no_neighbor,
4863 no_neighbor_cmd,
4864 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4865 NO_STR
4866 NEIGHBOR_STR
4867 NEIGHBOR_ADDR_STR2
4868 "Specify a BGP neighbor\n"
4869 AS_STR
4870 "Internal BGP peer\n"
4871 "External BGP peer\n")
4872 {
4873 VTY_DECLVAR_CONTEXT(bgp, bgp);
4874 int idx_peer = 2;
4875 int ret;
4876 union sockunion su;
4877 struct peer_group *group;
4878 struct peer *peer;
4879 struct peer *other;
4880
4881 ret = str2sockunion(argv[idx_peer]->arg, &su);
4882 if (ret < 0) {
4883 /* look up for neighbor by interface name config. */
4884 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4885 if (peer) {
4886 /* Request zebra to terminate IPv6 RAs on this
4887 * interface. */
4888 if (peer->ifp)
4889 bgp_zebra_terminate_radv(peer->bgp, peer);
4890 peer_notify_unconfig(peer);
4891 peer_delete(peer);
4892 return CMD_SUCCESS;
4893 }
4894
4895 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4896 if (group) {
4897 peer_group_notify_unconfig(group);
4898 peer_group_delete(group);
4899 } else {
4900 vty_out(vty, "%% Create the peer-group first\n");
4901 return CMD_WARNING_CONFIG_FAILED;
4902 }
4903 } else {
4904 peer = peer_lookup(bgp, &su);
4905 if (peer) {
4906 if (peer_dynamic_neighbor(peer)) {
4907 vty_out(vty,
4908 "%% Operation not allowed on a dynamic neighbor\n");
4909 return CMD_WARNING_CONFIG_FAILED;
4910 }
4911
4912 other = peer->doppelganger;
4913
4914 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4915 bgp_zebra_terminate_radv(peer->bgp, peer);
4916
4917 peer_notify_unconfig(peer);
4918 peer_delete(peer);
4919 if (other && other->status != Deleted) {
4920 peer_notify_unconfig(other);
4921 peer_delete(other);
4922 }
4923 }
4924 }
4925
4926 return CMD_SUCCESS;
4927 }
4928
4929 DEFUN (no_neighbor_interface_config,
4930 no_neighbor_interface_config_cmd,
4931 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4932 NO_STR
4933 NEIGHBOR_STR
4934 "Interface name\n"
4935 "Configure BGP on interface\n"
4936 "Enable BGP with v6 link-local only\n"
4937 "Member of the peer-group\n"
4938 "Peer-group name\n"
4939 "Specify a BGP neighbor\n"
4940 AS_STR
4941 "Internal BGP peer\n"
4942 "External BGP peer\n")
4943 {
4944 VTY_DECLVAR_CONTEXT(bgp, bgp);
4945 int idx_word = 2;
4946 struct peer *peer;
4947
4948 /* look up for neighbor by interface name config. */
4949 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4950 if (peer) {
4951 /* Request zebra to terminate IPv6 RAs on this interface. */
4952 if (peer->ifp)
4953 bgp_zebra_terminate_radv(peer->bgp, peer);
4954 peer_notify_unconfig(peer);
4955 peer_delete(peer);
4956 } else {
4957 vty_out(vty, "%% Create the bgp interface first\n");
4958 return CMD_WARNING_CONFIG_FAILED;
4959 }
4960 return CMD_SUCCESS;
4961 }
4962
4963 DEFUN (no_neighbor_peer_group,
4964 no_neighbor_peer_group_cmd,
4965 "no neighbor WORD peer-group",
4966 NO_STR
4967 NEIGHBOR_STR
4968 "Neighbor tag\n"
4969 "Configure peer-group\n")
4970 {
4971 VTY_DECLVAR_CONTEXT(bgp, bgp);
4972 int idx_word = 2;
4973 struct peer_group *group;
4974
4975 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4976 if (group) {
4977 peer_group_notify_unconfig(group);
4978 peer_group_delete(group);
4979 } else {
4980 vty_out(vty, "%% Create the peer-group first\n");
4981 return CMD_WARNING_CONFIG_FAILED;
4982 }
4983 return CMD_SUCCESS;
4984 }
4985
4986 DEFUN (no_neighbor_interface_peer_group_remote_as,
4987 no_neighbor_interface_peer_group_remote_as_cmd,
4988 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4989 NO_STR
4990 NEIGHBOR_STR
4991 "Interface name or neighbor tag\n"
4992 "Specify a BGP neighbor\n"
4993 AS_STR
4994 "Internal BGP peer\n"
4995 "External BGP peer\n")
4996 {
4997 VTY_DECLVAR_CONTEXT(bgp, bgp);
4998 int idx_word = 2;
4999 struct peer_group *group;
5000 struct peer *peer;
5001
5002 /* look up for neighbor by interface name config. */
5003 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5004 if (peer) {
5005 peer_as_change(peer, 0, AS_UNSPECIFIED);
5006 return CMD_SUCCESS;
5007 }
5008
5009 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5010 if (group)
5011 peer_group_remote_as_delete(group);
5012 else {
5013 vty_out(vty, "%% Create the peer-group or interface first\n");
5014 return CMD_WARNING_CONFIG_FAILED;
5015 }
5016 return CMD_SUCCESS;
5017 }
5018
5019 DEFUN (neighbor_local_as,
5020 neighbor_local_as_cmd,
5021 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
5022 NEIGHBOR_STR
5023 NEIGHBOR_ADDR_STR2
5024 "Specify a local-as number\n"
5025 "AS number used as local AS\n")
5026 {
5027 int idx_peer = 1;
5028 int idx_number = 3;
5029 struct peer *peer;
5030 int ret;
5031 as_t as;
5032
5033 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5034 if (!peer)
5035 return CMD_WARNING_CONFIG_FAILED;
5036
5037 as = strtoul(argv[idx_number]->arg, NULL, 10);
5038 ret = peer_local_as_set(peer, as, 0, 0);
5039 return bgp_vty_return(vty, ret);
5040 }
5041
5042 DEFUN (neighbor_local_as_no_prepend,
5043 neighbor_local_as_no_prepend_cmd,
5044 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
5045 NEIGHBOR_STR
5046 NEIGHBOR_ADDR_STR2
5047 "Specify a local-as number\n"
5048 "AS number used as local AS\n"
5049 "Do not prepend local-as to updates from ebgp peers\n")
5050 {
5051 int idx_peer = 1;
5052 int idx_number = 3;
5053 struct peer *peer;
5054 int ret;
5055 as_t as;
5056
5057 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5058 if (!peer)
5059 return CMD_WARNING_CONFIG_FAILED;
5060
5061 as = strtoul(argv[idx_number]->arg, NULL, 10);
5062 ret = peer_local_as_set(peer, as, 1, 0);
5063 return bgp_vty_return(vty, ret);
5064 }
5065
5066 DEFUN (neighbor_local_as_no_prepend_replace_as,
5067 neighbor_local_as_no_prepend_replace_as_cmd,
5068 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
5069 NEIGHBOR_STR
5070 NEIGHBOR_ADDR_STR2
5071 "Specify a local-as number\n"
5072 "AS number used as local AS\n"
5073 "Do not prepend local-as to updates from ebgp peers\n"
5074 "Do not prepend local-as to updates from ibgp peers\n")
5075 {
5076 int idx_peer = 1;
5077 int idx_number = 3;
5078 struct peer *peer;
5079 int ret;
5080 as_t as;
5081
5082 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5083 if (!peer)
5084 return CMD_WARNING_CONFIG_FAILED;
5085
5086 as = strtoul(argv[idx_number]->arg, NULL, 10);
5087 ret = peer_local_as_set(peer, as, 1, 1);
5088 return bgp_vty_return(vty, ret);
5089 }
5090
5091 DEFUN (no_neighbor_local_as,
5092 no_neighbor_local_as_cmd,
5093 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
5094 NO_STR
5095 NEIGHBOR_STR
5096 NEIGHBOR_ADDR_STR2
5097 "Specify a local-as number\n"
5098 "AS number used as local AS\n"
5099 "Do not prepend local-as to updates from ebgp peers\n"
5100 "Do not prepend local-as to updates from ibgp peers\n")
5101 {
5102 int idx_peer = 2;
5103 struct peer *peer;
5104 int ret;
5105
5106 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5107 if (!peer)
5108 return CMD_WARNING_CONFIG_FAILED;
5109
5110 ret = peer_local_as_unset(peer);
5111 return bgp_vty_return(vty, ret);
5112 }
5113
5114
5115 DEFUN (neighbor_solo,
5116 neighbor_solo_cmd,
5117 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5118 NEIGHBOR_STR
5119 NEIGHBOR_ADDR_STR2
5120 "Solo peer - part of its own update group\n")
5121 {
5122 int idx_peer = 1;
5123 struct peer *peer;
5124 int ret;
5125
5126 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5127 if (!peer)
5128 return CMD_WARNING_CONFIG_FAILED;
5129
5130 ret = update_group_adjust_soloness(peer, 1);
5131 return bgp_vty_return(vty, ret);
5132 }
5133
5134 DEFUN (no_neighbor_solo,
5135 no_neighbor_solo_cmd,
5136 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5137 NO_STR
5138 NEIGHBOR_STR
5139 NEIGHBOR_ADDR_STR2
5140 "Solo peer - part of its own update group\n")
5141 {
5142 int idx_peer = 2;
5143 struct peer *peer;
5144 int ret;
5145
5146 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5147 if (!peer)
5148 return CMD_WARNING_CONFIG_FAILED;
5149
5150 ret = update_group_adjust_soloness(peer, 0);
5151 return bgp_vty_return(vty, ret);
5152 }
5153
5154 DEFUN (neighbor_password,
5155 neighbor_password_cmd,
5156 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5157 NEIGHBOR_STR
5158 NEIGHBOR_ADDR_STR2
5159 "Set a password\n"
5160 "The password\n")
5161 {
5162 int idx_peer = 1;
5163 int idx_line = 3;
5164 struct peer *peer;
5165 int ret;
5166
5167 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5168 if (!peer)
5169 return CMD_WARNING_CONFIG_FAILED;
5170
5171 ret = peer_password_set(peer, argv[idx_line]->arg);
5172 return bgp_vty_return(vty, ret);
5173 }
5174
5175 DEFUN (no_neighbor_password,
5176 no_neighbor_password_cmd,
5177 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5178 NO_STR
5179 NEIGHBOR_STR
5180 NEIGHBOR_ADDR_STR2
5181 "Set a password\n"
5182 "The password\n")
5183 {
5184 int idx_peer = 2;
5185 struct peer *peer;
5186 int ret;
5187
5188 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5189 if (!peer)
5190 return CMD_WARNING_CONFIG_FAILED;
5191
5192 ret = peer_password_unset(peer);
5193 return bgp_vty_return(vty, ret);
5194 }
5195
5196 DEFUN (neighbor_activate,
5197 neighbor_activate_cmd,
5198 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5199 NEIGHBOR_STR
5200 NEIGHBOR_ADDR_STR2
5201 "Enable the Address Family for this Neighbor\n")
5202 {
5203 int idx_peer = 1;
5204 int ret;
5205 struct peer *peer;
5206
5207 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5208 if (!peer)
5209 return CMD_WARNING_CONFIG_FAILED;
5210
5211 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5212 return bgp_vty_return(vty, ret);
5213 }
5214
5215 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5216 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5217 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5218 "Enable the Address Family for this Neighbor\n")
5219
5220 DEFUN (no_neighbor_activate,
5221 no_neighbor_activate_cmd,
5222 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5223 NO_STR
5224 NEIGHBOR_STR
5225 NEIGHBOR_ADDR_STR2
5226 "Enable the Address Family for this Neighbor\n")
5227 {
5228 int idx_peer = 2;
5229 int ret;
5230 struct peer *peer;
5231
5232 /* Lookup peer. */
5233 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5234 if (!peer)
5235 return CMD_WARNING_CONFIG_FAILED;
5236
5237 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5238 return bgp_vty_return(vty, ret);
5239 }
5240
5241 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5242 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5243 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5244 "Enable the Address Family for this Neighbor\n")
5245
5246 DEFUN (neighbor_set_peer_group,
5247 neighbor_set_peer_group_cmd,
5248 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5249 NEIGHBOR_STR
5250 NEIGHBOR_ADDR_STR2
5251 "Member of the peer-group\n"
5252 "Peer-group name\n")
5253 {
5254 VTY_DECLVAR_CONTEXT(bgp, bgp);
5255 int idx_peer = 1;
5256 int idx_word = 3;
5257 int ret;
5258 as_t as;
5259 union sockunion su;
5260 struct peer *peer;
5261 struct peer_group *group;
5262
5263 ret = str2sockunion(argv[idx_peer]->arg, &su);
5264 if (ret < 0) {
5265 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5266 if (!peer) {
5267 vty_out(vty, "%% Malformed address or name: %s\n",
5268 argv[idx_peer]->arg);
5269 return CMD_WARNING_CONFIG_FAILED;
5270 }
5271 } else {
5272 if (peer_address_self_check(bgp, &su)) {
5273 vty_out(vty,
5274 "%% Can not configure the local system as neighbor\n");
5275 return CMD_WARNING_CONFIG_FAILED;
5276 }
5277
5278 /* Disallow for dynamic neighbor. */
5279 peer = peer_lookup(bgp, &su);
5280 if (peer && peer_dynamic_neighbor(peer)) {
5281 vty_out(vty,
5282 "%% Operation not allowed on a dynamic neighbor\n");
5283 return CMD_WARNING_CONFIG_FAILED;
5284 }
5285 }
5286
5287 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5288 if (!group) {
5289 vty_out(vty, "%% Configure the peer-group first\n");
5290 return CMD_WARNING_CONFIG_FAILED;
5291 }
5292
5293 ret = peer_group_bind(bgp, &su, peer, group, &as);
5294
5295 return bgp_vty_return(vty, ret);
5296 }
5297
5298 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5299 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5300 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5301 "Member of the peer-group\n"
5302 "Peer-group name\n")
5303
5304 DEFUN (no_neighbor_set_peer_group,
5305 no_neighbor_set_peer_group_cmd,
5306 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5307 NO_STR
5308 NEIGHBOR_STR
5309 NEIGHBOR_ADDR_STR2
5310 "Member of the peer-group\n"
5311 "Peer-group name\n")
5312 {
5313 VTY_DECLVAR_CONTEXT(bgp, bgp);
5314 int idx_peer = 2;
5315 int idx_word = 4;
5316 int ret;
5317 struct peer *peer;
5318 struct peer_group *group;
5319
5320 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5321 if (!peer)
5322 return CMD_WARNING_CONFIG_FAILED;
5323
5324 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5325 if (!group) {
5326 vty_out(vty, "%% Configure the peer-group first\n");
5327 return CMD_WARNING_CONFIG_FAILED;
5328 }
5329
5330 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5331 bgp_zebra_terminate_radv(peer->bgp, peer);
5332
5333 peer_notify_unconfig(peer);
5334 ret = peer_delete(peer);
5335
5336 return bgp_vty_return(vty, ret);
5337 }
5338
5339 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5340 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5341 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5342 "Member of the peer-group\n"
5343 "Peer-group name\n")
5344
5345 /* neighbor passive. */
5346 DEFUN (neighbor_passive,
5347 neighbor_passive_cmd,
5348 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5349 NEIGHBOR_STR
5350 NEIGHBOR_ADDR_STR2
5351 "Don't send open messages to this neighbor\n")
5352 {
5353 int idx_peer = 1;
5354 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5355 }
5356
5357 DEFUN (no_neighbor_passive,
5358 no_neighbor_passive_cmd,
5359 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5360 NO_STR
5361 NEIGHBOR_STR
5362 NEIGHBOR_ADDR_STR2
5363 "Don't send open messages to this neighbor\n")
5364 {
5365 int idx_peer = 2;
5366 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5367 }
5368
5369 /* neighbor shutdown. */
5370 DEFUN (neighbor_shutdown_msg,
5371 neighbor_shutdown_msg_cmd,
5372 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5373 NEIGHBOR_STR
5374 NEIGHBOR_ADDR_STR2
5375 "Administratively shut down this neighbor\n"
5376 "Add a shutdown message (RFC 8203)\n"
5377 "Shutdown message\n")
5378 {
5379 int idx_peer = 1;
5380
5381 if (argc >= 5) {
5382 struct peer *peer =
5383 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5384 char *message;
5385
5386 if (!peer)
5387 return CMD_WARNING_CONFIG_FAILED;
5388 message = argv_concat(argv, argc, 4);
5389 peer_tx_shutdown_message_set(peer, message);
5390 XFREE(MTYPE_TMP, message);
5391 }
5392
5393 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5394 }
5395
5396 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5397 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5398 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5399 "Administratively shut down this neighbor\n")
5400
5401 DEFUN (no_neighbor_shutdown_msg,
5402 no_neighbor_shutdown_msg_cmd,
5403 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5404 NO_STR
5405 NEIGHBOR_STR
5406 NEIGHBOR_ADDR_STR2
5407 "Administratively shut down this neighbor\n"
5408 "Remove a shutdown message (RFC 8203)\n"
5409 "Shutdown message\n")
5410 {
5411 int idx_peer = 2;
5412
5413 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5414 PEER_FLAG_SHUTDOWN);
5415 }
5416
5417 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5418 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5419 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5420 "Administratively shut down this neighbor\n")
5421
5422 DEFUN(neighbor_shutdown_rtt,
5423 neighbor_shutdown_rtt_cmd,
5424 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5425 NEIGHBOR_STR
5426 NEIGHBOR_ADDR_STR2
5427 "Administratively shut down this neighbor\n"
5428 "Shutdown if round-trip-time is higher than expected\n"
5429 "Round-trip-time in milliseconds\n"
5430 "Specify the number of keepalives before shutdown\n"
5431 "The number of keepalives with higher RTT to shutdown\n")
5432 {
5433 int idx_peer = 1;
5434 int idx_rtt = 4;
5435 int idx_count = 0;
5436 struct peer *peer;
5437
5438 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5439
5440 if (!peer)
5441 return CMD_WARNING_CONFIG_FAILED;
5442
5443 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5444
5445 if (argv_find(argv, argc, "count", &idx_count))
5446 peer->rtt_keepalive_conf =
5447 strtol(argv[idx_count + 1]->arg, NULL, 10);
5448
5449 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5450 PEER_FLAG_RTT_SHUTDOWN);
5451 }
5452
5453 DEFUN(no_neighbor_shutdown_rtt,
5454 no_neighbor_shutdown_rtt_cmd,
5455 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5456 NO_STR
5457 NEIGHBOR_STR
5458 NEIGHBOR_ADDR_STR2
5459 "Administratively shut down this neighbor\n"
5460 "Shutdown if round-trip-time is higher than expected\n"
5461 "Round-trip-time in milliseconds\n"
5462 "Specify the number of keepalives before shutdown\n"
5463 "The number of keepalives with higher RTT to shutdown\n")
5464 {
5465 int idx_peer = 2;
5466 struct peer *peer;
5467
5468 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5469
5470 if (!peer)
5471 return CMD_WARNING_CONFIG_FAILED;
5472
5473 peer->rtt_expected = 0;
5474 peer->rtt_keepalive_conf = 1;
5475
5476 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5477 PEER_FLAG_RTT_SHUTDOWN);
5478 }
5479
5480 /* neighbor capability dynamic. */
5481 DEFUN (neighbor_capability_dynamic,
5482 neighbor_capability_dynamic_cmd,
5483 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5484 NEIGHBOR_STR
5485 NEIGHBOR_ADDR_STR2
5486 "Advertise capability to the peer\n"
5487 "Advertise dynamic capability to this neighbor\n")
5488 {
5489 int idx_peer = 1;
5490 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5491 PEER_FLAG_DYNAMIC_CAPABILITY);
5492 }
5493
5494 DEFUN (no_neighbor_capability_dynamic,
5495 no_neighbor_capability_dynamic_cmd,
5496 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5497 NO_STR
5498 NEIGHBOR_STR
5499 NEIGHBOR_ADDR_STR2
5500 "Advertise capability to the peer\n"
5501 "Advertise dynamic capability to this neighbor\n")
5502 {
5503 int idx_peer = 2;
5504 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5505 PEER_FLAG_DYNAMIC_CAPABILITY);
5506 }
5507
5508 /* neighbor dont-capability-negotiate */
5509 DEFUN (neighbor_dont_capability_negotiate,
5510 neighbor_dont_capability_negotiate_cmd,
5511 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5512 NEIGHBOR_STR
5513 NEIGHBOR_ADDR_STR2
5514 "Do not perform capability negotiation\n")
5515 {
5516 int idx_peer = 1;
5517 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5518 PEER_FLAG_DONT_CAPABILITY);
5519 }
5520
5521 DEFUN (no_neighbor_dont_capability_negotiate,
5522 no_neighbor_dont_capability_negotiate_cmd,
5523 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5524 NO_STR
5525 NEIGHBOR_STR
5526 NEIGHBOR_ADDR_STR2
5527 "Do not perform capability negotiation\n")
5528 {
5529 int idx_peer = 2;
5530 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5531 PEER_FLAG_DONT_CAPABILITY);
5532 }
5533
5534 /* neighbor capability extended next hop encoding */
5535 DEFUN (neighbor_capability_enhe,
5536 neighbor_capability_enhe_cmd,
5537 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5538 NEIGHBOR_STR
5539 NEIGHBOR_ADDR_STR2
5540 "Advertise capability to the peer\n"
5541 "Advertise extended next-hop capability to the peer\n")
5542 {
5543 int idx_peer = 1;
5544 struct peer *peer;
5545
5546 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5547 if (peer && peer->conf_if)
5548 return CMD_SUCCESS;
5549
5550 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5551 PEER_FLAG_CAPABILITY_ENHE);
5552 }
5553
5554 DEFUN (no_neighbor_capability_enhe,
5555 no_neighbor_capability_enhe_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5557 NO_STR
5558 NEIGHBOR_STR
5559 NEIGHBOR_ADDR_STR2
5560 "Advertise capability to the peer\n"
5561 "Advertise extended next-hop capability to the peer\n")
5562 {
5563 int idx_peer = 2;
5564 struct peer *peer;
5565
5566 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5567 if (peer && peer->conf_if) {
5568 vty_out(vty,
5569 "Peer %s cannot have capability extended-nexthop turned off\n",
5570 argv[idx_peer]->arg);
5571 return CMD_WARNING_CONFIG_FAILED;
5572 }
5573
5574 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5575 PEER_FLAG_CAPABILITY_ENHE);
5576 }
5577
5578 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5579 afi_t afi, safi_t safi, uint32_t flag,
5580 int set)
5581 {
5582 int ret;
5583 struct peer *peer;
5584
5585 peer = peer_and_group_lookup_vty(vty, peer_str);
5586 if (!peer)
5587 return CMD_WARNING_CONFIG_FAILED;
5588
5589 if (set)
5590 ret = peer_af_flag_set(peer, afi, safi, flag);
5591 else
5592 ret = peer_af_flag_unset(peer, afi, safi, flag);
5593
5594 return bgp_vty_return(vty, ret);
5595 }
5596
5597 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5598 afi_t afi, safi_t safi, uint32_t flag)
5599 {
5600 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5601 }
5602
5603 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5604 afi_t afi, safi_t safi, uint32_t flag)
5605 {
5606 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5607 }
5608
5609 /* neighbor capability orf prefix-list. */
5610 DEFUN (neighbor_capability_orf_prefix,
5611 neighbor_capability_orf_prefix_cmd,
5612 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5613 NEIGHBOR_STR
5614 NEIGHBOR_ADDR_STR2
5615 "Advertise capability to the peer\n"
5616 "Advertise ORF capability to the peer\n"
5617 "Advertise prefixlist ORF capability to this neighbor\n"
5618 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5619 "Capability to RECEIVE the ORF from this neighbor\n"
5620 "Capability to SEND the ORF to this neighbor\n")
5621 {
5622 int idx_send_recv = 5;
5623 char *peer_str = argv[1]->arg;
5624 struct peer *peer;
5625 afi_t afi = bgp_node_afi(vty);
5626 safi_t safi = bgp_node_safi(vty);
5627
5628 peer = peer_and_group_lookup_vty(vty, peer_str);
5629 if (!peer)
5630 return CMD_WARNING_CONFIG_FAILED;
5631
5632 if (strmatch(argv[idx_send_recv]->text, "send"))
5633 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5634 PEER_FLAG_ORF_PREFIX_SM);
5635
5636 if (strmatch(argv[idx_send_recv]->text, "receive"))
5637 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5638 PEER_FLAG_ORF_PREFIX_RM);
5639
5640 if (strmatch(argv[idx_send_recv]->text, "both"))
5641 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5642 PEER_FLAG_ORF_PREFIX_SM)
5643 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5644 PEER_FLAG_ORF_PREFIX_RM);
5645
5646 return CMD_WARNING_CONFIG_FAILED;
5647 }
5648
5649 ALIAS_HIDDEN(
5650 neighbor_capability_orf_prefix,
5651 neighbor_capability_orf_prefix_hidden_cmd,
5652 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5653 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5654 "Advertise capability to the peer\n"
5655 "Advertise ORF capability to the peer\n"
5656 "Advertise prefixlist ORF capability to this neighbor\n"
5657 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5658 "Capability to RECEIVE the ORF from this neighbor\n"
5659 "Capability to SEND the ORF to this neighbor\n")
5660
5661 DEFUN (no_neighbor_capability_orf_prefix,
5662 no_neighbor_capability_orf_prefix_cmd,
5663 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5664 NO_STR
5665 NEIGHBOR_STR
5666 NEIGHBOR_ADDR_STR2
5667 "Advertise capability to the peer\n"
5668 "Advertise ORF capability to the peer\n"
5669 "Advertise prefixlist ORF capability to this neighbor\n"
5670 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5671 "Capability to RECEIVE the ORF from this neighbor\n"
5672 "Capability to SEND the ORF to this neighbor\n")
5673 {
5674 int idx_send_recv = 6;
5675 char *peer_str = argv[2]->arg;
5676 struct peer *peer;
5677 afi_t afi = bgp_node_afi(vty);
5678 safi_t safi = bgp_node_safi(vty);
5679
5680 peer = peer_and_group_lookup_vty(vty, peer_str);
5681 if (!peer)
5682 return CMD_WARNING_CONFIG_FAILED;
5683
5684 if (strmatch(argv[idx_send_recv]->text, "send"))
5685 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5686 PEER_FLAG_ORF_PREFIX_SM);
5687
5688 if (strmatch(argv[idx_send_recv]->text, "receive"))
5689 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5690 PEER_FLAG_ORF_PREFIX_RM);
5691
5692 if (strmatch(argv[idx_send_recv]->text, "both"))
5693 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5694 PEER_FLAG_ORF_PREFIX_SM)
5695 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5696 PEER_FLAG_ORF_PREFIX_RM);
5697
5698 return CMD_WARNING_CONFIG_FAILED;
5699 }
5700
5701 ALIAS_HIDDEN(
5702 no_neighbor_capability_orf_prefix,
5703 no_neighbor_capability_orf_prefix_hidden_cmd,
5704 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5705 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5706 "Advertise capability to the peer\n"
5707 "Advertise ORF capability to the peer\n"
5708 "Advertise prefixlist ORF capability to this neighbor\n"
5709 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5710 "Capability to RECEIVE the ORF from this neighbor\n"
5711 "Capability to SEND the ORF to this neighbor\n")
5712
5713 /* neighbor next-hop-self. */
5714 DEFUN (neighbor_nexthop_self,
5715 neighbor_nexthop_self_cmd,
5716 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5717 NEIGHBOR_STR
5718 NEIGHBOR_ADDR_STR2
5719 "Disable the next hop calculation for this neighbor\n")
5720 {
5721 int idx_peer = 1;
5722 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5723 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5724 }
5725
5726 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5727 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5728 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5729 "Disable the next hop calculation for this neighbor\n")
5730
5731 /* neighbor next-hop-self. */
5732 DEFUN (neighbor_nexthop_self_force,
5733 neighbor_nexthop_self_force_cmd,
5734 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5735 NEIGHBOR_STR
5736 NEIGHBOR_ADDR_STR2
5737 "Disable the next hop calculation for this neighbor\n"
5738 "Set the next hop to self for reflected routes\n")
5739 {
5740 int idx_peer = 1;
5741 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5742 bgp_node_safi(vty),
5743 PEER_FLAG_FORCE_NEXTHOP_SELF);
5744 }
5745
5746 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5747 neighbor_nexthop_self_force_hidden_cmd,
5748 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5749 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5750 "Disable the next hop calculation for this neighbor\n"
5751 "Set the next hop to self for reflected routes\n")
5752
5753 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5754 neighbor_nexthop_self_all_hidden_cmd,
5755 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5756 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5757 "Disable the next hop calculation for this neighbor\n"
5758 "Set the next hop to self for reflected routes\n")
5759
5760 DEFUN (no_neighbor_nexthop_self,
5761 no_neighbor_nexthop_self_cmd,
5762 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5763 NO_STR
5764 NEIGHBOR_STR
5765 NEIGHBOR_ADDR_STR2
5766 "Disable the next hop calculation for this neighbor\n")
5767 {
5768 int idx_peer = 2;
5769 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5770 bgp_node_afi(vty), bgp_node_safi(vty),
5771 PEER_FLAG_NEXTHOP_SELF);
5772 }
5773
5774 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5775 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5776 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5777 "Disable the next hop calculation for this neighbor\n")
5778
5779 DEFUN (no_neighbor_nexthop_self_force,
5780 no_neighbor_nexthop_self_force_cmd,
5781 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5782 NO_STR
5783 NEIGHBOR_STR
5784 NEIGHBOR_ADDR_STR2
5785 "Disable the next hop calculation for this neighbor\n"
5786 "Set the next hop to self for reflected routes\n")
5787 {
5788 int idx_peer = 2;
5789 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5790 bgp_node_afi(vty), bgp_node_safi(vty),
5791 PEER_FLAG_FORCE_NEXTHOP_SELF);
5792 }
5793
5794 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5795 no_neighbor_nexthop_self_force_hidden_cmd,
5796 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5797 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5798 "Disable the next hop calculation for this neighbor\n"
5799 "Set the next hop to self for reflected routes\n")
5800
5801 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5802 no_neighbor_nexthop_self_all_hidden_cmd,
5803 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5804 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5805 "Disable the next hop calculation for this neighbor\n"
5806 "Set the next hop to self for reflected routes\n")
5807
5808 /* neighbor as-override */
5809 DEFUN (neighbor_as_override,
5810 neighbor_as_override_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Override ASNs in outbound updates if aspath equals remote-as\n")
5815 {
5816 int idx_peer = 1;
5817 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5818 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5819 }
5820
5821 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5822 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5823 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5824 "Override ASNs in outbound updates if aspath equals remote-as\n")
5825
5826 DEFUN (no_neighbor_as_override,
5827 no_neighbor_as_override_cmd,
5828 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5829 NO_STR
5830 NEIGHBOR_STR
5831 NEIGHBOR_ADDR_STR2
5832 "Override ASNs in outbound updates if aspath equals remote-as\n")
5833 {
5834 int idx_peer = 2;
5835 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5836 bgp_node_afi(vty), bgp_node_safi(vty),
5837 PEER_FLAG_AS_OVERRIDE);
5838 }
5839
5840 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5841 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5842 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Override ASNs in outbound updates if aspath equals remote-as\n")
5844
5845 /* neighbor remove-private-AS. */
5846 DEFUN (neighbor_remove_private_as,
5847 neighbor_remove_private_as_cmd,
5848 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5849 NEIGHBOR_STR
5850 NEIGHBOR_ADDR_STR2
5851 "Remove private ASNs in outbound updates\n")
5852 {
5853 int idx_peer = 1;
5854 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5855 bgp_node_safi(vty),
5856 PEER_FLAG_REMOVE_PRIVATE_AS);
5857 }
5858
5859 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5860 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5861 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5862 "Remove private ASNs in outbound updates\n")
5863
5864 DEFUN (neighbor_remove_private_as_all,
5865 neighbor_remove_private_as_all_cmd,
5866 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5867 NEIGHBOR_STR
5868 NEIGHBOR_ADDR_STR2
5869 "Remove private ASNs in outbound updates\n"
5870 "Apply to all AS numbers\n")
5871 {
5872 int idx_peer = 1;
5873 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5874 bgp_node_safi(vty),
5875 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5876 }
5877
5878 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5879 neighbor_remove_private_as_all_hidden_cmd,
5880 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5882 "Remove private ASNs in outbound updates\n"
5883 "Apply to all AS numbers\n")
5884
5885 DEFUN (neighbor_remove_private_as_replace_as,
5886 neighbor_remove_private_as_replace_as_cmd,
5887 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5888 NEIGHBOR_STR
5889 NEIGHBOR_ADDR_STR2
5890 "Remove private ASNs in outbound updates\n"
5891 "Replace private ASNs with our ASN in outbound updates\n")
5892 {
5893 int idx_peer = 1;
5894 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5895 bgp_node_safi(vty),
5896 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5897 }
5898
5899 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5900 neighbor_remove_private_as_replace_as_hidden_cmd,
5901 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5902 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5903 "Remove private ASNs in outbound updates\n"
5904 "Replace private ASNs with our ASN in outbound updates\n")
5905
5906 DEFUN (neighbor_remove_private_as_all_replace_as,
5907 neighbor_remove_private_as_all_replace_as_cmd,
5908 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5909 NEIGHBOR_STR
5910 NEIGHBOR_ADDR_STR2
5911 "Remove private ASNs in outbound updates\n"
5912 "Apply to all AS numbers\n"
5913 "Replace private ASNs with our ASN in outbound updates\n")
5914 {
5915 int idx_peer = 1;
5916 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5917 bgp_node_safi(vty),
5918 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5919 }
5920
5921 ALIAS_HIDDEN(
5922 neighbor_remove_private_as_all_replace_as,
5923 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5924 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5925 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5926 "Remove private ASNs in outbound updates\n"
5927 "Apply to all AS numbers\n"
5928 "Replace private ASNs with our ASN in outbound updates\n")
5929
5930 DEFUN (no_neighbor_remove_private_as,
5931 no_neighbor_remove_private_as_cmd,
5932 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5933 NO_STR
5934 NEIGHBOR_STR
5935 NEIGHBOR_ADDR_STR2
5936 "Remove private ASNs in outbound updates\n")
5937 {
5938 int idx_peer = 2;
5939 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5940 bgp_node_afi(vty), bgp_node_safi(vty),
5941 PEER_FLAG_REMOVE_PRIVATE_AS);
5942 }
5943
5944 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5945 no_neighbor_remove_private_as_hidden_cmd,
5946 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5947 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Remove private ASNs in outbound updates\n")
5949
5950 DEFUN (no_neighbor_remove_private_as_all,
5951 no_neighbor_remove_private_as_all_cmd,
5952 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5953 NO_STR
5954 NEIGHBOR_STR
5955 NEIGHBOR_ADDR_STR2
5956 "Remove private ASNs in outbound updates\n"
5957 "Apply to all AS numbers\n")
5958 {
5959 int idx_peer = 2;
5960 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5961 bgp_node_afi(vty), bgp_node_safi(vty),
5962 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5963 }
5964
5965 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5966 no_neighbor_remove_private_as_all_hidden_cmd,
5967 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5968 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "Remove private ASNs in outbound updates\n"
5970 "Apply to all AS numbers\n")
5971
5972 DEFUN (no_neighbor_remove_private_as_replace_as,
5973 no_neighbor_remove_private_as_replace_as_cmd,
5974 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5975 NO_STR
5976 NEIGHBOR_STR
5977 NEIGHBOR_ADDR_STR2
5978 "Remove private ASNs in outbound updates\n"
5979 "Replace private ASNs with our ASN in outbound updates\n")
5980 {
5981 int idx_peer = 2;
5982 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5983 bgp_node_afi(vty), bgp_node_safi(vty),
5984 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5985 }
5986
5987 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5988 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5989 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5990 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5991 "Remove private ASNs in outbound updates\n"
5992 "Replace private ASNs with our ASN in outbound updates\n")
5993
5994 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5995 no_neighbor_remove_private_as_all_replace_as_cmd,
5996 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5997 NO_STR
5998 NEIGHBOR_STR
5999 NEIGHBOR_ADDR_STR2
6000 "Remove private ASNs in outbound updates\n"
6001 "Apply to all AS numbers\n"
6002 "Replace private ASNs with our ASN in outbound updates\n")
6003 {
6004 int idx_peer = 2;
6005 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6006 bgp_node_afi(vty), bgp_node_safi(vty),
6007 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
6008 }
6009
6010 ALIAS_HIDDEN(
6011 no_neighbor_remove_private_as_all_replace_as,
6012 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6013 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6014 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6015 "Remove private ASNs in outbound updates\n"
6016 "Apply to all AS numbers\n"
6017 "Replace private ASNs with our ASN in outbound updates\n")
6018
6019
6020 /* neighbor send-community. */
6021 DEFUN (neighbor_send_community,
6022 neighbor_send_community_cmd,
6023 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6024 NEIGHBOR_STR
6025 NEIGHBOR_ADDR_STR2
6026 "Send Community attribute to this neighbor\n")
6027 {
6028 int idx_peer = 1;
6029
6030 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6031 bgp_node_safi(vty),
6032 PEER_FLAG_SEND_COMMUNITY);
6033 }
6034
6035 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6036 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6037 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6038 "Send Community attribute to this neighbor\n")
6039
6040 DEFUN (no_neighbor_send_community,
6041 no_neighbor_send_community_cmd,
6042 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6043 NO_STR
6044 NEIGHBOR_STR
6045 NEIGHBOR_ADDR_STR2
6046 "Send Community attribute to this neighbor\n")
6047 {
6048 int idx_peer = 2;
6049
6050 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6051 bgp_node_afi(vty), bgp_node_safi(vty),
6052 PEER_FLAG_SEND_COMMUNITY);
6053 }
6054
6055 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6056 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6057 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6058 "Send Community attribute to this neighbor\n")
6059
6060 /* neighbor send-community extended. */
6061 DEFUN (neighbor_send_community_type,
6062 neighbor_send_community_type_cmd,
6063 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6064 NEIGHBOR_STR
6065 NEIGHBOR_ADDR_STR2
6066 "Send Community attribute to this neighbor\n"
6067 "Send Standard and Extended Community attributes\n"
6068 "Send Standard, Large and Extended Community attributes\n"
6069 "Send Extended Community attributes\n"
6070 "Send Standard Community attributes\n"
6071 "Send Large Community attributes\n")
6072 {
6073 const char *type = argv[argc - 1]->text;
6074 char *peer_str = argv[1]->arg;
6075 struct peer *peer;
6076 afi_t afi = bgp_node_afi(vty);
6077 safi_t safi = bgp_node_safi(vty);
6078
6079 peer = peer_and_group_lookup_vty(vty, peer_str);
6080 if (!peer)
6081 return CMD_WARNING_CONFIG_FAILED;
6082
6083 if (strmatch(type, "standard"))
6084 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6085 PEER_FLAG_SEND_COMMUNITY);
6086
6087 if (strmatch(type, "extended"))
6088 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6089 PEER_FLAG_SEND_EXT_COMMUNITY);
6090
6091 if (strmatch(type, "large"))
6092 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6093 PEER_FLAG_SEND_LARGE_COMMUNITY);
6094
6095 if (strmatch(type, "both")) {
6096 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6097 PEER_FLAG_SEND_COMMUNITY)
6098 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6099 PEER_FLAG_SEND_EXT_COMMUNITY);
6100 }
6101 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6102 PEER_FLAG_SEND_COMMUNITY)
6103 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6104 PEER_FLAG_SEND_EXT_COMMUNITY)
6105 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6106 PEER_FLAG_SEND_LARGE_COMMUNITY);
6107 }
6108
6109 ALIAS_HIDDEN(
6110 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6111 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6112 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6113 "Send Community attribute to this neighbor\n"
6114 "Send Standard and Extended Community attributes\n"
6115 "Send Standard, Large and Extended Community attributes\n"
6116 "Send Extended Community attributes\n"
6117 "Send Standard Community attributes\n"
6118 "Send Large Community attributes\n")
6119
6120 DEFUN (no_neighbor_send_community_type,
6121 no_neighbor_send_community_type_cmd,
6122 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6123 NO_STR
6124 NEIGHBOR_STR
6125 NEIGHBOR_ADDR_STR2
6126 "Send Community attribute to this neighbor\n"
6127 "Send Standard and Extended Community attributes\n"
6128 "Send Standard, Large and Extended Community attributes\n"
6129 "Send Extended Community attributes\n"
6130 "Send Standard Community attributes\n"
6131 "Send Large Community attributes\n")
6132 {
6133 const char *type = argv[argc - 1]->text;
6134 char *peer_str = argv[2]->arg;
6135 struct peer *peer;
6136 afi_t afi = bgp_node_afi(vty);
6137 safi_t safi = bgp_node_safi(vty);
6138
6139 peer = peer_and_group_lookup_vty(vty, peer_str);
6140 if (!peer)
6141 return CMD_WARNING_CONFIG_FAILED;
6142
6143 if (strmatch(type, "standard"))
6144 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6145 PEER_FLAG_SEND_COMMUNITY);
6146
6147 if (strmatch(type, "extended"))
6148 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6149 PEER_FLAG_SEND_EXT_COMMUNITY);
6150
6151 if (strmatch(type, "large"))
6152 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6153 PEER_FLAG_SEND_LARGE_COMMUNITY);
6154
6155 if (strmatch(type, "both")) {
6156
6157 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6158 PEER_FLAG_SEND_COMMUNITY)
6159 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6160 PEER_FLAG_SEND_EXT_COMMUNITY);
6161 }
6162
6163 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6164 PEER_FLAG_SEND_COMMUNITY)
6165 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6166 PEER_FLAG_SEND_EXT_COMMUNITY)
6167 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6168 PEER_FLAG_SEND_LARGE_COMMUNITY);
6169 }
6170
6171 ALIAS_HIDDEN(
6172 no_neighbor_send_community_type,
6173 no_neighbor_send_community_type_hidden_cmd,
6174 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6175 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6176 "Send Community attribute to this neighbor\n"
6177 "Send Standard and Extended Community attributes\n"
6178 "Send Standard, Large and Extended Community attributes\n"
6179 "Send Extended Community attributes\n"
6180 "Send Standard Community attributes\n"
6181 "Send Large Community attributes\n")
6182
6183 /* neighbor soft-reconfig. */
6184 DEFUN (neighbor_soft_reconfiguration,
6185 neighbor_soft_reconfiguration_cmd,
6186 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6187 NEIGHBOR_STR
6188 NEIGHBOR_ADDR_STR2
6189 "Per neighbor soft reconfiguration\n"
6190 "Allow inbound soft reconfiguration for this neighbor\n")
6191 {
6192 int idx_peer = 1;
6193 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6194 bgp_node_safi(vty),
6195 PEER_FLAG_SOFT_RECONFIG);
6196 }
6197
6198 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6199 neighbor_soft_reconfiguration_hidden_cmd,
6200 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6201 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6202 "Per neighbor soft reconfiguration\n"
6203 "Allow inbound soft reconfiguration for this neighbor\n")
6204
6205 DEFUN (no_neighbor_soft_reconfiguration,
6206 no_neighbor_soft_reconfiguration_cmd,
6207 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6208 NO_STR
6209 NEIGHBOR_STR
6210 NEIGHBOR_ADDR_STR2
6211 "Per neighbor soft reconfiguration\n"
6212 "Allow inbound soft reconfiguration for this neighbor\n")
6213 {
6214 int idx_peer = 2;
6215 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6216 bgp_node_afi(vty), bgp_node_safi(vty),
6217 PEER_FLAG_SOFT_RECONFIG);
6218 }
6219
6220 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6221 no_neighbor_soft_reconfiguration_hidden_cmd,
6222 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6223 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6224 "Per neighbor soft reconfiguration\n"
6225 "Allow inbound soft reconfiguration for this neighbor\n")
6226
6227 DEFUN (neighbor_route_reflector_client,
6228 neighbor_route_reflector_client_cmd,
6229 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6230 NEIGHBOR_STR
6231 NEIGHBOR_ADDR_STR2
6232 "Configure a neighbor as Route Reflector client\n")
6233 {
6234 int idx_peer = 1;
6235 struct peer *peer;
6236
6237
6238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6239 if (!peer)
6240 return CMD_WARNING_CONFIG_FAILED;
6241
6242 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6243 bgp_node_safi(vty),
6244 PEER_FLAG_REFLECTOR_CLIENT);
6245 }
6246
6247 ALIAS_HIDDEN(neighbor_route_reflector_client,
6248 neighbor_route_reflector_client_hidden_cmd,
6249 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6250 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6251 "Configure a neighbor as Route Reflector client\n")
6252
6253 DEFUN (no_neighbor_route_reflector_client,
6254 no_neighbor_route_reflector_client_cmd,
6255 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6256 NO_STR
6257 NEIGHBOR_STR
6258 NEIGHBOR_ADDR_STR2
6259 "Configure a neighbor as Route Reflector client\n")
6260 {
6261 int idx_peer = 2;
6262 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6263 bgp_node_afi(vty), bgp_node_safi(vty),
6264 PEER_FLAG_REFLECTOR_CLIENT);
6265 }
6266
6267 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6268 no_neighbor_route_reflector_client_hidden_cmd,
6269 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6270 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6271 "Configure a neighbor as Route Reflector client\n")
6272
6273 /* neighbor route-server-client. */
6274 DEFUN (neighbor_route_server_client,
6275 neighbor_route_server_client_cmd,
6276 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6277 NEIGHBOR_STR
6278 NEIGHBOR_ADDR_STR2
6279 "Configure a neighbor as Route Server client\n")
6280 {
6281 int idx_peer = 1;
6282 struct peer *peer;
6283
6284 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6285 if (!peer)
6286 return CMD_WARNING_CONFIG_FAILED;
6287 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6288 bgp_node_safi(vty),
6289 PEER_FLAG_RSERVER_CLIENT);
6290 }
6291
6292 ALIAS_HIDDEN(neighbor_route_server_client,
6293 neighbor_route_server_client_hidden_cmd,
6294 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6295 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6296 "Configure a neighbor as Route Server client\n")
6297
6298 DEFUN (no_neighbor_route_server_client,
6299 no_neighbor_route_server_client_cmd,
6300 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6301 NO_STR
6302 NEIGHBOR_STR
6303 NEIGHBOR_ADDR_STR2
6304 "Configure a neighbor as Route Server client\n")
6305 {
6306 int idx_peer = 2;
6307 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6308 bgp_node_afi(vty), bgp_node_safi(vty),
6309 PEER_FLAG_RSERVER_CLIENT);
6310 }
6311
6312 ALIAS_HIDDEN(no_neighbor_route_server_client,
6313 no_neighbor_route_server_client_hidden_cmd,
6314 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6315 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6316 "Configure a neighbor as Route Server client\n")
6317
6318 DEFUN (neighbor_nexthop_local_unchanged,
6319 neighbor_nexthop_local_unchanged_cmd,
6320 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6321 NEIGHBOR_STR
6322 NEIGHBOR_ADDR_STR2
6323 "Configure treatment of outgoing link-local nexthop attribute\n"
6324 "Leave link-local nexthop unchanged for this peer\n")
6325 {
6326 int idx_peer = 1;
6327 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6328 bgp_node_safi(vty),
6329 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6330 }
6331
6332 DEFUN (no_neighbor_nexthop_local_unchanged,
6333 no_neighbor_nexthop_local_unchanged_cmd,
6334 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6335 NO_STR
6336 NEIGHBOR_STR
6337 NEIGHBOR_ADDR_STR2
6338 "Configure treatment of outgoing link-local-nexthop attribute\n"
6339 "Leave link-local nexthop unchanged for this peer\n")
6340 {
6341 int idx_peer = 2;
6342 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6343 bgp_node_afi(vty), bgp_node_safi(vty),
6344 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6345 }
6346
6347 DEFUN (neighbor_attr_unchanged,
6348 neighbor_attr_unchanged_cmd,
6349 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6350 NEIGHBOR_STR
6351 NEIGHBOR_ADDR_STR2
6352 "BGP attribute is propagated unchanged to this neighbor\n"
6353 "As-path attribute\n"
6354 "Nexthop attribute\n"
6355 "Med attribute\n")
6356 {
6357 int idx = 0;
6358 char *peer_str = argv[1]->arg;
6359 struct peer *peer;
6360 bool aspath = false;
6361 bool nexthop = false;
6362 bool med = false;
6363 afi_t afi = bgp_node_afi(vty);
6364 safi_t safi = bgp_node_safi(vty);
6365 int ret = 0;
6366
6367 peer = peer_and_group_lookup_vty(vty, peer_str);
6368 if (!peer)
6369 return CMD_WARNING_CONFIG_FAILED;
6370
6371 if (argv_find(argv, argc, "as-path", &idx))
6372 aspath = true;
6373
6374 idx = 0;
6375 if (argv_find(argv, argc, "next-hop", &idx))
6376 nexthop = true;
6377
6378 idx = 0;
6379 if (argv_find(argv, argc, "med", &idx))
6380 med = true;
6381
6382 /* no flags means all of them! */
6383 if (!aspath && !nexthop && !med) {
6384 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6385 PEER_FLAG_AS_PATH_UNCHANGED);
6386 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6387 PEER_FLAG_NEXTHOP_UNCHANGED);
6388 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6389 PEER_FLAG_MED_UNCHANGED);
6390 } else {
6391 if (!aspath) {
6392 if (peer_af_flag_check(peer, afi, safi,
6393 PEER_FLAG_AS_PATH_UNCHANGED)) {
6394 ret |= peer_af_flag_unset_vty(
6395 vty, peer_str, afi, safi,
6396 PEER_FLAG_AS_PATH_UNCHANGED);
6397 }
6398 } else
6399 ret |= peer_af_flag_set_vty(
6400 vty, peer_str, afi, safi,
6401 PEER_FLAG_AS_PATH_UNCHANGED);
6402
6403 if (!nexthop) {
6404 if (peer_af_flag_check(peer, afi, safi,
6405 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6406 ret |= peer_af_flag_unset_vty(
6407 vty, peer_str, afi, safi,
6408 PEER_FLAG_NEXTHOP_UNCHANGED);
6409 }
6410 } else
6411 ret |= peer_af_flag_set_vty(
6412 vty, peer_str, afi, safi,
6413 PEER_FLAG_NEXTHOP_UNCHANGED);
6414
6415 if (!med) {
6416 if (peer_af_flag_check(peer, afi, safi,
6417 PEER_FLAG_MED_UNCHANGED)) {
6418 ret |= peer_af_flag_unset_vty(
6419 vty, peer_str, afi, safi,
6420 PEER_FLAG_MED_UNCHANGED);
6421 }
6422 } else
6423 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6424 PEER_FLAG_MED_UNCHANGED);
6425 }
6426
6427 return ret;
6428 }
6429
6430 ALIAS_HIDDEN(
6431 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6432 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6433 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6434 "BGP attribute is propagated unchanged to this neighbor\n"
6435 "As-path attribute\n"
6436 "Nexthop attribute\n"
6437 "Med attribute\n")
6438
6439 DEFUN (no_neighbor_attr_unchanged,
6440 no_neighbor_attr_unchanged_cmd,
6441 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6442 NO_STR
6443 NEIGHBOR_STR
6444 NEIGHBOR_ADDR_STR2
6445 "BGP attribute is propagated unchanged to this neighbor\n"
6446 "As-path attribute\n"
6447 "Nexthop attribute\n"
6448 "Med attribute\n")
6449 {
6450 int idx = 0;
6451 char *peer_str = argv[2]->arg;
6452 struct peer *peer;
6453 bool aspath = false;
6454 bool nexthop = false;
6455 bool med = false;
6456 afi_t afi = bgp_node_afi(vty);
6457 safi_t safi = bgp_node_safi(vty);
6458 int ret = 0;
6459
6460 peer = peer_and_group_lookup_vty(vty, peer_str);
6461 if (!peer)
6462 return CMD_WARNING_CONFIG_FAILED;
6463
6464 if (argv_find(argv, argc, "as-path", &idx))
6465 aspath = true;
6466
6467 idx = 0;
6468 if (argv_find(argv, argc, "next-hop", &idx))
6469 nexthop = true;
6470
6471 idx = 0;
6472 if (argv_find(argv, argc, "med", &idx))
6473 med = true;
6474
6475 if (!aspath && !nexthop && !med) // no flags means all of them!
6476 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6477 PEER_FLAG_AS_PATH_UNCHANGED)
6478 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6479 PEER_FLAG_NEXTHOP_UNCHANGED)
6480 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6481 PEER_FLAG_MED_UNCHANGED);
6482
6483 if (aspath)
6484 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6485 PEER_FLAG_AS_PATH_UNCHANGED);
6486
6487 if (nexthop)
6488 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6489 PEER_FLAG_NEXTHOP_UNCHANGED);
6490
6491 if (med)
6492 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6493 PEER_FLAG_MED_UNCHANGED);
6494
6495 return ret;
6496 }
6497
6498 ALIAS_HIDDEN(
6499 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6500 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6501 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6502 "BGP attribute is propagated unchanged to this neighbor\n"
6503 "As-path attribute\n"
6504 "Nexthop attribute\n"
6505 "Med attribute\n")
6506
6507 /* EBGP multihop configuration. */
6508 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6509 const char *ttl_str)
6510 {
6511 struct peer *peer;
6512 unsigned int ttl;
6513
6514 peer = peer_and_group_lookup_vty(vty, ip_str);
6515 if (!peer)
6516 return CMD_WARNING_CONFIG_FAILED;
6517
6518 if (peer->conf_if)
6519 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6520
6521 if (!ttl_str)
6522 ttl = MAXTTL;
6523 else
6524 ttl = strtoul(ttl_str, NULL, 10);
6525
6526 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6527 }
6528
6529 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6530 {
6531 struct peer *peer;
6532
6533 peer = peer_and_group_lookup_vty(vty, ip_str);
6534 if (!peer)
6535 return CMD_WARNING_CONFIG_FAILED;
6536
6537 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6538 }
6539
6540 /* neighbor ebgp-multihop. */
6541 DEFUN (neighbor_ebgp_multihop,
6542 neighbor_ebgp_multihop_cmd,
6543 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6544 NEIGHBOR_STR
6545 NEIGHBOR_ADDR_STR2
6546 "Allow EBGP neighbors not on directly connected networks\n")
6547 {
6548 int idx_peer = 1;
6549 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6550 }
6551
6552 DEFUN (neighbor_ebgp_multihop_ttl,
6553 neighbor_ebgp_multihop_ttl_cmd,
6554 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6555 NEIGHBOR_STR
6556 NEIGHBOR_ADDR_STR2
6557 "Allow EBGP neighbors not on directly connected networks\n"
6558 "maximum hop count\n")
6559 {
6560 int idx_peer = 1;
6561 int idx_number = 3;
6562 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6563 argv[idx_number]->arg);
6564 }
6565
6566 DEFUN (no_neighbor_ebgp_multihop,
6567 no_neighbor_ebgp_multihop_cmd,
6568 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6569 NO_STR
6570 NEIGHBOR_STR
6571 NEIGHBOR_ADDR_STR2
6572 "Allow EBGP neighbors not on directly connected networks\n"
6573 "maximum hop count\n")
6574 {
6575 int idx_peer = 2;
6576 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6577 }
6578
6579 DEFPY (neighbor_aigp,
6580 neighbor_aigp_cmd,
6581 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6582 NO_STR
6583 NEIGHBOR_STR
6584 NEIGHBOR_ADDR_STR2
6585 "Enable send and receive of the AIGP attribute per neighbor\n")
6586 {
6587 struct peer *peer;
6588
6589 peer = peer_and_group_lookup_vty(vty, neighbor);
6590 if (!peer)
6591 return CMD_WARNING_CONFIG_FAILED;
6592
6593 if (no)
6594 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6595 else
6596 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6597 }
6598
6599 static uint8_t get_role_by_name(const char *role_str)
6600 {
6601 if (strncmp(role_str, "peer", 2) == 0)
6602 return ROLE_PEER;
6603 if (strncmp(role_str, "provider", 2) == 0)
6604 return ROLE_PROVIDER;
6605 if (strncmp(role_str, "customer", 2) == 0)
6606 return ROLE_CUSTOMER;
6607 if (strncmp(role_str, "rs-server", 4) == 0)
6608 return ROLE_RS_SERVER;
6609 if (strncmp(role_str, "rs-client", 4) == 0)
6610 return ROLE_RS_CLIENT;
6611 return ROLE_UNDEFINED;
6612 }
6613
6614 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6615 const char *role_str, bool strict_mode)
6616 {
6617 struct peer *peer;
6618
6619 peer = peer_and_group_lookup_vty(vty, ip_str);
6620 if (!peer)
6621 return CMD_WARNING_CONFIG_FAILED;
6622 uint8_t role = get_role_by_name(role_str);
6623
6624 if (role == ROLE_UNDEFINED)
6625 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6626 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6627 }
6628
6629 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6630 {
6631 struct peer *peer;
6632
6633 peer = peer_and_group_lookup_vty(vty, ip_str);
6634 if (!peer)
6635 return CMD_WARNING_CONFIG_FAILED;
6636 return bgp_vty_return(vty, peer_role_unset(peer));
6637 }
6638
6639 DEFPY(neighbor_role,
6640 neighbor_role_cmd,
6641 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6642 NEIGHBOR_STR
6643 NEIGHBOR_ADDR_STR2
6644 "Set session role\n"
6645 ROLE_STR)
6646 {
6647 int idx_peer = 1;
6648 int idx_role = 3;
6649
6650 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6651 false);
6652 }
6653
6654 DEFPY(neighbor_role_strict,
6655 neighbor_role_strict_cmd,
6656 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6657 NEIGHBOR_STR
6658 NEIGHBOR_ADDR_STR2
6659 "Set session role\n"
6660 ROLE_STR
6661 "Use additional restriction on peer\n")
6662 {
6663 int idx_peer = 1;
6664 int idx_role = 3;
6665
6666 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6667 true);
6668 }
6669
6670 DEFPY(no_neighbor_role,
6671 no_neighbor_role_cmd,
6672 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6673 NO_STR
6674 NEIGHBOR_STR
6675 NEIGHBOR_ADDR_STR2
6676 "Set session role\n"
6677 ROLE_STR
6678 "Use additional restriction on peer\n")
6679 {
6680 int idx_peer = 2;
6681
6682 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6683 }
6684
6685 /* disable-connected-check */
6686 DEFUN (neighbor_disable_connected_check,
6687 neighbor_disable_connected_check_cmd,
6688 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6689 NEIGHBOR_STR
6690 NEIGHBOR_ADDR_STR2
6691 "one-hop away EBGP peer using loopback address\n"
6692 "Enforce EBGP neighbors perform multihop\n")
6693 {
6694 int idx_peer = 1;
6695 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6696 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6697 }
6698
6699 DEFUN (no_neighbor_disable_connected_check,
6700 no_neighbor_disable_connected_check_cmd,
6701 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6702 NO_STR
6703 NEIGHBOR_STR
6704 NEIGHBOR_ADDR_STR2
6705 "one-hop away EBGP peer using loopback address\n"
6706 "Enforce EBGP neighbors perform multihop\n")
6707 {
6708 int idx_peer = 2;
6709 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6710 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6711 }
6712
6713 /* disable-link-bw-encoding-ieee */
6714 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6715 neighbor_disable_link_bw_encoding_ieee_cmd,
6716 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6717 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6718 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6719 {
6720 int idx_peer = 1;
6721
6722 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6723 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6724 }
6725
6726 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6727 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6728 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6729 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6730 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6731 {
6732 int idx_peer = 2;
6733
6734 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6735 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6736 }
6737
6738 /* extended-optional-parameters */
6739 DEFUN(neighbor_extended_optional_parameters,
6740 neighbor_extended_optional_parameters_cmd,
6741 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6742 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6743 "Force the extended optional parameters format for OPEN messages\n")
6744 {
6745 int idx_peer = 1;
6746
6747 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6748 PEER_FLAG_EXTENDED_OPT_PARAMS);
6749 }
6750
6751 DEFUN(no_neighbor_extended_optional_parameters,
6752 no_neighbor_extended_optional_parameters_cmd,
6753 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6754 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6755 "Force the extended optional parameters format for OPEN messages\n")
6756 {
6757 int idx_peer = 2;
6758
6759 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6760 PEER_FLAG_EXTENDED_OPT_PARAMS);
6761 }
6762
6763 /* enforce-first-as */
6764 DEFUN (neighbor_enforce_first_as,
6765 neighbor_enforce_first_as_cmd,
6766 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6767 NEIGHBOR_STR
6768 NEIGHBOR_ADDR_STR2
6769 "Enforce the first AS for EBGP routes\n")
6770 {
6771 int idx_peer = 1;
6772
6773 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6774 PEER_FLAG_ENFORCE_FIRST_AS);
6775 }
6776
6777 DEFUN (no_neighbor_enforce_first_as,
6778 no_neighbor_enforce_first_as_cmd,
6779 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6780 NO_STR
6781 NEIGHBOR_STR
6782 NEIGHBOR_ADDR_STR2
6783 "Enforce the first AS for EBGP routes\n")
6784 {
6785 int idx_peer = 2;
6786
6787 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6788 PEER_FLAG_ENFORCE_FIRST_AS);
6789 }
6790
6791
6792 DEFUN (neighbor_description,
6793 neighbor_description_cmd,
6794 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6795 NEIGHBOR_STR
6796 NEIGHBOR_ADDR_STR2
6797 "Neighbor specific description\n"
6798 "Up to 80 characters describing this neighbor\n")
6799 {
6800 int idx_peer = 1;
6801 int idx_line = 3;
6802 struct peer *peer;
6803 char *str;
6804
6805 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6806 if (!peer)
6807 return CMD_WARNING_CONFIG_FAILED;
6808
6809 str = argv_concat(argv, argc, idx_line);
6810
6811 peer_description_set(peer, str);
6812
6813 XFREE(MTYPE_TMP, str);
6814
6815 return CMD_SUCCESS;
6816 }
6817
6818 DEFUN (no_neighbor_description,
6819 no_neighbor_description_cmd,
6820 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6821 NO_STR
6822 NEIGHBOR_STR
6823 NEIGHBOR_ADDR_STR2
6824 "Neighbor specific description\n")
6825 {
6826 int idx_peer = 2;
6827 struct peer *peer;
6828
6829 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6830 if (!peer)
6831 return CMD_WARNING_CONFIG_FAILED;
6832
6833 peer_description_unset(peer);
6834
6835 return CMD_SUCCESS;
6836 }
6837
6838 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6839 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6840 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6841 "Neighbor specific description\n"
6842 "Up to 80 characters describing this neighbor\n")
6843
6844 /* Neighbor update-source. */
6845 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6846 const char *source_str)
6847 {
6848 struct peer *peer;
6849 struct prefix p;
6850 union sockunion su;
6851
6852 peer = peer_and_group_lookup_vty(vty, peer_str);
6853 if (!peer)
6854 return CMD_WARNING_CONFIG_FAILED;
6855
6856 if (peer->conf_if)
6857 return CMD_WARNING;
6858
6859 if (source_str) {
6860 if (str2sockunion(source_str, &su) == 0)
6861 peer_update_source_addr_set(peer, &su);
6862 else {
6863 if (str2prefix(source_str, &p)) {
6864 vty_out(vty,
6865 "%% Invalid update-source, remove prefix length \n");
6866 return CMD_WARNING_CONFIG_FAILED;
6867 } else
6868 peer_update_source_if_set(peer, source_str);
6869 }
6870 } else
6871 peer_update_source_unset(peer);
6872
6873 return CMD_SUCCESS;
6874 }
6875
6876 #define BGP_UPDATE_SOURCE_HELP_STR \
6877 "IPv4 address\n" \
6878 "IPv6 address\n" \
6879 "Interface name (requires zebra to be running)\n"
6880
6881 DEFUN (neighbor_update_source,
6882 neighbor_update_source_cmd,
6883 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6884 NEIGHBOR_STR
6885 NEIGHBOR_ADDR_STR2
6886 "Source of routing updates\n"
6887 BGP_UPDATE_SOURCE_HELP_STR)
6888 {
6889 int idx_peer = 1;
6890 int idx_peer_2 = 3;
6891 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6892 argv[idx_peer_2]->arg);
6893 }
6894
6895 DEFUN (no_neighbor_update_source,
6896 no_neighbor_update_source_cmd,
6897 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6898 NO_STR
6899 NEIGHBOR_STR
6900 NEIGHBOR_ADDR_STR2
6901 "Source of routing updates\n"
6902 BGP_UPDATE_SOURCE_HELP_STR)
6903 {
6904 int idx_peer = 2;
6905 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6906 }
6907
6908 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6909 afi_t afi, safi_t safi,
6910 const char *rmap, int set)
6911 {
6912 int ret;
6913 struct peer *peer;
6914 struct route_map *route_map = NULL;
6915
6916 peer = peer_and_group_lookup_vty(vty, peer_str);
6917 if (!peer)
6918 return CMD_WARNING_CONFIG_FAILED;
6919
6920 if (set) {
6921 if (rmap)
6922 route_map = route_map_lookup_warn_noexist(vty, rmap);
6923 ret = peer_default_originate_set(peer, afi, safi,
6924 rmap, route_map);
6925 } else
6926 ret = peer_default_originate_unset(peer, afi, safi);
6927
6928 return bgp_vty_return(vty, ret);
6929 }
6930
6931 /* neighbor default-originate. */
6932 DEFUN (neighbor_default_originate,
6933 neighbor_default_originate_cmd,
6934 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6935 NEIGHBOR_STR
6936 NEIGHBOR_ADDR_STR2
6937 "Originate default route to this neighbor\n")
6938 {
6939 int idx_peer = 1;
6940 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6941 bgp_node_afi(vty),
6942 bgp_node_safi(vty), NULL, 1);
6943 }
6944
6945 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6946 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6948 "Originate default route to this neighbor\n")
6949
6950 DEFUN (neighbor_default_originate_rmap,
6951 neighbor_default_originate_rmap_cmd,
6952 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6953 NEIGHBOR_STR
6954 NEIGHBOR_ADDR_STR2
6955 "Originate default route to this neighbor\n"
6956 "Route-map to specify criteria to originate default\n"
6957 "route-map name\n")
6958 {
6959 int idx_peer = 1;
6960 int idx_word = 4;
6961 return peer_default_originate_set_vty(
6962 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6963 argv[idx_word]->arg, 1);
6964 }
6965
6966 ALIAS_HIDDEN(
6967 neighbor_default_originate_rmap,
6968 neighbor_default_originate_rmap_hidden_cmd,
6969 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6970 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6971 "Originate default route to this neighbor\n"
6972 "Route-map to specify criteria to originate default\n"
6973 "route-map name\n")
6974
6975 DEFUN (no_neighbor_default_originate,
6976 no_neighbor_default_originate_cmd,
6977 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6978 NO_STR
6979 NEIGHBOR_STR
6980 NEIGHBOR_ADDR_STR2
6981 "Originate default route to this neighbor\n"
6982 "Route-map to specify criteria to originate default\n"
6983 "route-map name\n")
6984 {
6985 int idx_peer = 2;
6986 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6987 bgp_node_afi(vty),
6988 bgp_node_safi(vty), NULL, 0);
6989 }
6990
6991 ALIAS_HIDDEN(
6992 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6993 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6994 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6995 "Originate default route to this neighbor\n"
6996 "Route-map to specify criteria to originate default\n"
6997 "route-map name\n")
6998
6999
7000 /* Set neighbor's BGP port. */
7001 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7002 const char *port_str)
7003 {
7004 struct peer *peer;
7005 uint16_t port;
7006 struct servent *sp;
7007
7008 peer = peer_and_group_lookup_vty(vty, ip_str);
7009 if (!peer)
7010 return CMD_WARNING_CONFIG_FAILED;
7011
7012 if (!port_str) {
7013 sp = getservbyname("bgp", "tcp");
7014 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7015 } else {
7016 port = strtoul(port_str, NULL, 10);
7017 }
7018
7019 peer_port_set(peer, port);
7020
7021 return CMD_SUCCESS;
7022 }
7023
7024 /* Set specified peer's BGP port. */
7025 DEFUN (neighbor_port,
7026 neighbor_port_cmd,
7027 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
7028 NEIGHBOR_STR
7029 NEIGHBOR_ADDR_STR2
7030 "Neighbor's BGP port\n"
7031 "TCP port number\n")
7032 {
7033 int idx_ip = 1;
7034 int idx_number = 3;
7035 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7036 argv[idx_number]->arg);
7037 }
7038
7039 DEFUN (no_neighbor_port,
7040 no_neighbor_port_cmd,
7041 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
7042 NO_STR
7043 NEIGHBOR_STR
7044 NEIGHBOR_ADDR_STR2
7045 "Neighbor's BGP port\n"
7046 "TCP port number\n")
7047 {
7048 int idx_ip = 2;
7049 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7050 }
7051
7052
7053 /* neighbor weight. */
7054 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7055 safi_t safi, const char *weight_str)
7056 {
7057 int ret;
7058 struct peer *peer;
7059 unsigned long weight;
7060
7061 peer = peer_and_group_lookup_vty(vty, ip_str);
7062 if (!peer)
7063 return CMD_WARNING_CONFIG_FAILED;
7064
7065 weight = strtoul(weight_str, NULL, 10);
7066
7067 ret = peer_weight_set(peer, afi, safi, weight);
7068 return bgp_vty_return(vty, ret);
7069 }
7070
7071 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7072 safi_t safi)
7073 {
7074 int ret;
7075 struct peer *peer;
7076
7077 peer = peer_and_group_lookup_vty(vty, ip_str);
7078 if (!peer)
7079 return CMD_WARNING_CONFIG_FAILED;
7080
7081 ret = peer_weight_unset(peer, afi, safi);
7082 return bgp_vty_return(vty, ret);
7083 }
7084
7085 DEFUN (neighbor_weight,
7086 neighbor_weight_cmd,
7087 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7088 NEIGHBOR_STR
7089 NEIGHBOR_ADDR_STR2
7090 "Set default weight for routes from this neighbor\n"
7091 "default weight\n")
7092 {
7093 int idx_peer = 1;
7094 int idx_number = 3;
7095 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7096 bgp_node_safi(vty), argv[idx_number]->arg);
7097 }
7098
7099 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7100 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7101 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7102 "Set default weight for routes from this neighbor\n"
7103 "default weight\n")
7104
7105 DEFUN (no_neighbor_weight,
7106 no_neighbor_weight_cmd,
7107 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7108 NO_STR
7109 NEIGHBOR_STR
7110 NEIGHBOR_ADDR_STR2
7111 "Set default weight for routes from this neighbor\n"
7112 "default weight\n")
7113 {
7114 int idx_peer = 2;
7115 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7116 bgp_node_afi(vty), bgp_node_safi(vty));
7117 }
7118
7119 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7120 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7121 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7122 "Set default weight for routes from this neighbor\n"
7123 "default weight\n")
7124
7125
7126 /* Override capability negotiation. */
7127 DEFUN (neighbor_override_capability,
7128 neighbor_override_capability_cmd,
7129 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7130 NEIGHBOR_STR
7131 NEIGHBOR_ADDR_STR2
7132 "Override capability negotiation result\n")
7133 {
7134 int idx_peer = 1;
7135 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7136 PEER_FLAG_OVERRIDE_CAPABILITY);
7137 }
7138
7139 DEFUN (no_neighbor_override_capability,
7140 no_neighbor_override_capability_cmd,
7141 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7142 NO_STR
7143 NEIGHBOR_STR
7144 NEIGHBOR_ADDR_STR2
7145 "Override capability negotiation result\n")
7146 {
7147 int idx_peer = 2;
7148 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7149 PEER_FLAG_OVERRIDE_CAPABILITY);
7150 }
7151
7152 DEFUN (neighbor_strict_capability,
7153 neighbor_strict_capability_cmd,
7154 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7155 NEIGHBOR_STR
7156 NEIGHBOR_ADDR_STR2
7157 "Strict capability negotiation match\n")
7158 {
7159 int idx_peer = 1;
7160
7161 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7162 PEER_FLAG_STRICT_CAP_MATCH);
7163 }
7164
7165 DEFUN (no_neighbor_strict_capability,
7166 no_neighbor_strict_capability_cmd,
7167 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7168 NO_STR
7169 NEIGHBOR_STR
7170 NEIGHBOR_ADDR_STR2
7171 "Strict capability negotiation match\n")
7172 {
7173 int idx_peer = 2;
7174
7175 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7176 PEER_FLAG_STRICT_CAP_MATCH);
7177 }
7178
7179 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7180 const char *keep_str, const char *hold_str)
7181 {
7182 int ret;
7183 struct peer *peer;
7184 uint32_t keepalive;
7185 uint32_t holdtime;
7186
7187 peer = peer_and_group_lookup_vty(vty, ip_str);
7188 if (!peer)
7189 return CMD_WARNING_CONFIG_FAILED;
7190
7191 keepalive = strtoul(keep_str, NULL, 10);
7192 holdtime = strtoul(hold_str, NULL, 10);
7193
7194 ret = peer_timers_set(peer, keepalive, holdtime);
7195
7196 return bgp_vty_return(vty, ret);
7197 }
7198
7199 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7200 {
7201 int ret;
7202 struct peer *peer;
7203
7204 peer = peer_and_group_lookup_vty(vty, ip_str);
7205 if (!peer)
7206 return CMD_WARNING_CONFIG_FAILED;
7207
7208 ret = peer_timers_unset(peer);
7209
7210 return bgp_vty_return(vty, ret);
7211 }
7212
7213 DEFUN (neighbor_timers,
7214 neighbor_timers_cmd,
7215 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7216 NEIGHBOR_STR
7217 NEIGHBOR_ADDR_STR2
7218 "BGP per neighbor timers\n"
7219 "Keepalive interval\n"
7220 "Holdtime\n")
7221 {
7222 int idx_peer = 1;
7223 int idx_number = 3;
7224 int idx_number_2 = 4;
7225 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7226 argv[idx_number]->arg,
7227 argv[idx_number_2]->arg);
7228 }
7229
7230 DEFUN (no_neighbor_timers,
7231 no_neighbor_timers_cmd,
7232 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7233 NO_STR
7234 NEIGHBOR_STR
7235 NEIGHBOR_ADDR_STR2
7236 "BGP per neighbor timers\n"
7237 "Keepalive interval\n"
7238 "Holdtime\n")
7239 {
7240 int idx_peer = 2;
7241 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7242 }
7243
7244
7245 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7246 const char *time_str)
7247 {
7248 int ret;
7249 struct peer *peer;
7250 uint32_t connect;
7251
7252 peer = peer_and_group_lookup_vty(vty, ip_str);
7253 if (!peer)
7254 return CMD_WARNING_CONFIG_FAILED;
7255
7256 connect = strtoul(time_str, NULL, 10);
7257
7258 ret = peer_timers_connect_set(peer, connect);
7259
7260 return bgp_vty_return(vty, ret);
7261 }
7262
7263 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7264 {
7265 int ret;
7266 struct peer *peer;
7267
7268 peer = peer_and_group_lookup_vty(vty, ip_str);
7269 if (!peer)
7270 return CMD_WARNING_CONFIG_FAILED;
7271
7272 ret = peer_timers_connect_unset(peer);
7273
7274 return bgp_vty_return(vty, ret);
7275 }
7276
7277 DEFUN (neighbor_timers_connect,
7278 neighbor_timers_connect_cmd,
7279 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7280 NEIGHBOR_STR
7281 NEIGHBOR_ADDR_STR2
7282 "BGP per neighbor timers\n"
7283 "BGP connect timer\n"
7284 "Connect timer\n")
7285 {
7286 int idx_peer = 1;
7287 int idx_number = 4;
7288 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7289 argv[idx_number]->arg);
7290 }
7291
7292 DEFUN (no_neighbor_timers_connect,
7293 no_neighbor_timers_connect_cmd,
7294 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7295 NO_STR
7296 NEIGHBOR_STR
7297 NEIGHBOR_ADDR_STR2
7298 "BGP per neighbor timers\n"
7299 "BGP connect timer\n"
7300 "Connect timer\n")
7301 {
7302 int idx_peer = 2;
7303 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7304 }
7305
7306 DEFPY (neighbor_timers_delayopen,
7307 neighbor_timers_delayopen_cmd,
7308 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7309 NEIGHBOR_STR
7310 NEIGHBOR_ADDR_STR2
7311 "BGP per neighbor timers\n"
7312 "RFC 4271 DelayOpenTimer\n"
7313 "DelayOpenTime timer interval\n")
7314 {
7315 struct peer *peer;
7316
7317 peer = peer_and_group_lookup_vty(vty, neighbor);
7318 if (!peer)
7319 return CMD_WARNING_CONFIG_FAILED;
7320
7321 if (!interval) {
7322 if (peer_timers_delayopen_unset(peer))
7323 return CMD_WARNING_CONFIG_FAILED;
7324 } else {
7325 if (peer_timers_delayopen_set(peer, interval))
7326 return CMD_WARNING_CONFIG_FAILED;
7327 }
7328
7329 return CMD_SUCCESS;
7330 }
7331
7332 DEFPY (no_neighbor_timers_delayopen,
7333 no_neighbor_timers_delayopen_cmd,
7334 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7335 NO_STR
7336 NEIGHBOR_STR
7337 NEIGHBOR_ADDR_STR2
7338 "BGP per neighbor timers\n"
7339 "RFC 4271 DelayOpenTimer\n"
7340 "DelayOpenTime timer interval\n")
7341 {
7342 struct peer *peer;
7343
7344 peer = peer_and_group_lookup_vty(vty, neighbor);
7345 if (!peer)
7346 return CMD_WARNING_CONFIG_FAILED;
7347
7348 if (peer_timers_delayopen_unset(peer))
7349 return CMD_WARNING_CONFIG_FAILED;
7350
7351 return CMD_SUCCESS;
7352 }
7353
7354 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7355 const char *time_str, int set)
7356 {
7357 int ret;
7358 struct peer *peer;
7359 uint32_t routeadv = 0;
7360
7361 peer = peer_and_group_lookup_vty(vty, ip_str);
7362 if (!peer)
7363 return CMD_WARNING_CONFIG_FAILED;
7364
7365 if (time_str)
7366 routeadv = strtoul(time_str, NULL, 10);
7367
7368 if (set)
7369 ret = peer_advertise_interval_set(peer, routeadv);
7370 else
7371 ret = peer_advertise_interval_unset(peer);
7372
7373 return bgp_vty_return(vty, ret);
7374 }
7375
7376 DEFUN (neighbor_advertise_interval,
7377 neighbor_advertise_interval_cmd,
7378 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7379 NEIGHBOR_STR
7380 NEIGHBOR_ADDR_STR2
7381 "Minimum interval between sending BGP routing updates\n"
7382 "time in seconds\n")
7383 {
7384 int idx_peer = 1;
7385 int idx_number = 3;
7386 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7387 argv[idx_number]->arg, 1);
7388 }
7389
7390 DEFUN (no_neighbor_advertise_interval,
7391 no_neighbor_advertise_interval_cmd,
7392 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7393 NO_STR
7394 NEIGHBOR_STR
7395 NEIGHBOR_ADDR_STR2
7396 "Minimum interval between sending BGP routing updates\n"
7397 "time in seconds\n")
7398 {
7399 int idx_peer = 2;
7400 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7401 }
7402
7403
7404 /* Time to wait before processing route-map updates */
7405 DEFUN (bgp_set_route_map_delay_timer,
7406 bgp_set_route_map_delay_timer_cmd,
7407 "bgp route-map delay-timer (0-600)",
7408 SET_STR
7409 "BGP route-map delay timer\n"
7410 "Time in secs to wait before processing route-map changes\n"
7411 "0 disables the timer, no route updates happen when route-maps change\n")
7412 {
7413 int idx_number = 3;
7414 uint32_t rmap_delay_timer;
7415
7416 if (argv[idx_number]->arg) {
7417 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7418 bm->rmap_update_timer = rmap_delay_timer;
7419
7420 /* if the dynamic update handling is being disabled, and a timer
7421 * is
7422 * running, stop the timer and act as if the timer has already
7423 * fired.
7424 */
7425 if (!rmap_delay_timer && bm->t_rmap_update) {
7426 THREAD_OFF(bm->t_rmap_update);
7427 thread_execute(bm->master, bgp_route_map_update_timer,
7428 NULL, 0);
7429 }
7430 return CMD_SUCCESS;
7431 } else {
7432 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7433 return CMD_WARNING_CONFIG_FAILED;
7434 }
7435 }
7436
7437 DEFUN (no_bgp_set_route_map_delay_timer,
7438 no_bgp_set_route_map_delay_timer_cmd,
7439 "no bgp route-map delay-timer [(0-600)]",
7440 NO_STR
7441 BGP_STR
7442 "Default BGP route-map delay timer\n"
7443 "Reset to default time to wait for processing route-map changes\n"
7444 "0 disables the timer, no route updates happen when route-maps change\n")
7445 {
7446
7447 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7448
7449 return CMD_SUCCESS;
7450 }
7451
7452 /* neighbor interface */
7453 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7454 const char *str)
7455 {
7456 struct peer *peer;
7457
7458 peer = peer_lookup_vty(vty, ip_str);
7459 if (!peer || peer->conf_if) {
7460 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7461 return CMD_WARNING_CONFIG_FAILED;
7462 }
7463
7464 if (str)
7465 peer_interface_set(peer, str);
7466 else
7467 peer_interface_unset(peer);
7468
7469 return CMD_SUCCESS;
7470 }
7471
7472 DEFUN (neighbor_interface,
7473 neighbor_interface_cmd,
7474 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7475 NEIGHBOR_STR
7476 NEIGHBOR_ADDR_STR
7477 "Interface\n"
7478 "Interface name\n")
7479 {
7480 int idx_ip = 1;
7481 int idx_word = 3;
7482
7483 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7484 }
7485
7486 DEFUN (no_neighbor_interface,
7487 no_neighbor_interface_cmd,
7488 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7489 NO_STR
7490 NEIGHBOR_STR
7491 NEIGHBOR_ADDR_STR
7492 "Interface\n"
7493 "Interface name\n")
7494 {
7495 int idx_peer = 2;
7496
7497 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7498 }
7499
7500 DEFUN (neighbor_distribute_list,
7501 neighbor_distribute_list_cmd,
7502 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7503 NEIGHBOR_STR
7504 NEIGHBOR_ADDR_STR2
7505 "Filter updates to/from this neighbor\n"
7506 "IP Access-list name\n"
7507 "Filter incoming updates\n"
7508 "Filter outgoing updates\n")
7509 {
7510 int idx_peer = 1;
7511 int idx_acl = 3;
7512 int direct, ret;
7513 struct peer *peer;
7514
7515 const char *pstr = argv[idx_peer]->arg;
7516 const char *acl = argv[idx_acl]->arg;
7517 const char *inout = argv[argc - 1]->text;
7518
7519 peer = peer_and_group_lookup_vty(vty, pstr);
7520 if (!peer)
7521 return CMD_WARNING_CONFIG_FAILED;
7522
7523 /* Check filter direction. */
7524 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7525 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7526 direct, acl);
7527
7528 return bgp_vty_return(vty, ret);
7529 }
7530
7531 ALIAS_HIDDEN(
7532 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7533 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7534 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7535 "Filter updates to/from this neighbor\n"
7536 "IP Access-list name\n"
7537 "Filter incoming updates\n"
7538 "Filter outgoing updates\n")
7539
7540 DEFUN (no_neighbor_distribute_list,
7541 no_neighbor_distribute_list_cmd,
7542 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7543 NO_STR
7544 NEIGHBOR_STR
7545 NEIGHBOR_ADDR_STR2
7546 "Filter updates to/from this neighbor\n"
7547 "IP Access-list name\n"
7548 "Filter incoming updates\n"
7549 "Filter outgoing updates\n")
7550 {
7551 int idx_peer = 2;
7552 int direct, ret;
7553 struct peer *peer;
7554
7555 const char *pstr = argv[idx_peer]->arg;
7556 const char *inout = argv[argc - 1]->text;
7557
7558 peer = peer_and_group_lookup_vty(vty, pstr);
7559 if (!peer)
7560 return CMD_WARNING_CONFIG_FAILED;
7561
7562 /* Check filter direction. */
7563 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7564 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7565 direct);
7566
7567 return bgp_vty_return(vty, ret);
7568 }
7569
7570 ALIAS_HIDDEN(
7571 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7572 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7573 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7574 "Filter updates to/from this neighbor\n"
7575 "IP Access-list name\n"
7576 "Filter incoming updates\n"
7577 "Filter outgoing updates\n")
7578
7579 /* Set prefix list to the peer. */
7580 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7581 afi_t afi, safi_t safi,
7582 const char *name_str,
7583 const char *direct_str)
7584 {
7585 int ret;
7586 int direct = FILTER_IN;
7587 struct peer *peer;
7588
7589 peer = peer_and_group_lookup_vty(vty, ip_str);
7590 if (!peer)
7591 return CMD_WARNING_CONFIG_FAILED;
7592
7593 /* Check filter direction. */
7594 if (strncmp(direct_str, "i", 1) == 0)
7595 direct = FILTER_IN;
7596 else if (strncmp(direct_str, "o", 1) == 0)
7597 direct = FILTER_OUT;
7598
7599 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7600
7601 return bgp_vty_return(vty, ret);
7602 }
7603
7604 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7605 afi_t afi, safi_t safi,
7606 const char *direct_str)
7607 {
7608 int ret;
7609 struct peer *peer;
7610 int direct = FILTER_IN;
7611
7612 peer = peer_and_group_lookup_vty(vty, ip_str);
7613 if (!peer)
7614 return CMD_WARNING_CONFIG_FAILED;
7615
7616 /* Check filter direction. */
7617 if (strncmp(direct_str, "i", 1) == 0)
7618 direct = FILTER_IN;
7619 else if (strncmp(direct_str, "o", 1) == 0)
7620 direct = FILTER_OUT;
7621
7622 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7623
7624 return bgp_vty_return(vty, ret);
7625 }
7626
7627 DEFUN (neighbor_prefix_list,
7628 neighbor_prefix_list_cmd,
7629 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7630 NEIGHBOR_STR
7631 NEIGHBOR_ADDR_STR2
7632 "Filter updates to/from this neighbor\n"
7633 "Name of a prefix list\n"
7634 "Filter incoming updates\n"
7635 "Filter outgoing updates\n")
7636 {
7637 int idx_peer = 1;
7638 int idx_word = 3;
7639 int idx_in_out = 4;
7640 return peer_prefix_list_set_vty(
7641 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7642 argv[idx_word]->arg, argv[idx_in_out]->arg);
7643 }
7644
7645 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7646 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7647 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7648 "Filter updates to/from this neighbor\n"
7649 "Name of a prefix list\n"
7650 "Filter incoming updates\n"
7651 "Filter outgoing updates\n")
7652
7653 DEFUN (no_neighbor_prefix_list,
7654 no_neighbor_prefix_list_cmd,
7655 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7656 NO_STR
7657 NEIGHBOR_STR
7658 NEIGHBOR_ADDR_STR2
7659 "Filter updates to/from this neighbor\n"
7660 "Name of a prefix list\n"
7661 "Filter incoming updates\n"
7662 "Filter outgoing updates\n")
7663 {
7664 int idx_peer = 2;
7665 int idx_in_out = 5;
7666 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7667 bgp_node_afi(vty), bgp_node_safi(vty),
7668 argv[idx_in_out]->arg);
7669 }
7670
7671 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7672 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7674 "Filter updates to/from this neighbor\n"
7675 "Name of a prefix list\n"
7676 "Filter incoming updates\n"
7677 "Filter outgoing updates\n")
7678
7679 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7680 safi_t safi, const char *name_str,
7681 const char *direct_str)
7682 {
7683 int ret;
7684 struct peer *peer;
7685 int direct = FILTER_IN;
7686
7687 peer = peer_and_group_lookup_vty(vty, ip_str);
7688 if (!peer)
7689 return CMD_WARNING_CONFIG_FAILED;
7690
7691 /* Check filter direction. */
7692 if (strncmp(direct_str, "i", 1) == 0)
7693 direct = FILTER_IN;
7694 else if (strncmp(direct_str, "o", 1) == 0)
7695 direct = FILTER_OUT;
7696
7697 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7698
7699 return bgp_vty_return(vty, ret);
7700 }
7701
7702 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7703 safi_t safi, const char *direct_str)
7704 {
7705 int ret;
7706 struct peer *peer;
7707 int direct = FILTER_IN;
7708
7709 peer = peer_and_group_lookup_vty(vty, ip_str);
7710 if (!peer)
7711 return CMD_WARNING_CONFIG_FAILED;
7712
7713 /* Check filter direction. */
7714 if (strncmp(direct_str, "i", 1) == 0)
7715 direct = FILTER_IN;
7716 else if (strncmp(direct_str, "o", 1) == 0)
7717 direct = FILTER_OUT;
7718
7719 ret = peer_aslist_unset(peer, afi, safi, direct);
7720
7721 return bgp_vty_return(vty, ret);
7722 }
7723
7724 DEFUN (neighbor_filter_list,
7725 neighbor_filter_list_cmd,
7726 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7727 NEIGHBOR_STR
7728 NEIGHBOR_ADDR_STR2
7729 "Establish BGP filters\n"
7730 "AS path access-list name\n"
7731 "Filter incoming routes\n"
7732 "Filter outgoing routes\n")
7733 {
7734 int idx_peer = 1;
7735 int idx_word = 3;
7736 int idx_in_out = 4;
7737 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7738 bgp_node_safi(vty), argv[idx_word]->arg,
7739 argv[idx_in_out]->arg);
7740 }
7741
7742 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7743 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7744 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7745 "Establish BGP filters\n"
7746 "AS path access-list name\n"
7747 "Filter incoming routes\n"
7748 "Filter outgoing routes\n")
7749
7750 DEFUN (no_neighbor_filter_list,
7751 no_neighbor_filter_list_cmd,
7752 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7753 NO_STR
7754 NEIGHBOR_STR
7755 NEIGHBOR_ADDR_STR2
7756 "Establish BGP filters\n"
7757 "AS path access-list name\n"
7758 "Filter incoming routes\n"
7759 "Filter outgoing routes\n")
7760 {
7761 int idx_peer = 2;
7762 int idx_in_out = 5;
7763 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7764 bgp_node_afi(vty), bgp_node_safi(vty),
7765 argv[idx_in_out]->arg);
7766 }
7767
7768 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7769 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7770 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7771 "Establish BGP filters\n"
7772 "AS path access-list name\n"
7773 "Filter incoming routes\n"
7774 "Filter outgoing routes\n")
7775
7776 /* Set advertise-map to the peer. */
7777 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7778 afi_t afi, safi_t safi,
7779 const char *advertise_str,
7780 const char *condition_str, bool condition,
7781 bool set)
7782 {
7783 int ret = CMD_WARNING_CONFIG_FAILED;
7784 struct peer *peer;
7785 struct route_map *advertise_map;
7786 struct route_map *condition_map;
7787
7788 peer = peer_and_group_lookup_vty(vty, ip_str);
7789 if (!peer)
7790 return ret;
7791
7792 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7793 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7794
7795 if (set)
7796 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7797 advertise_map, condition_str,
7798 condition_map, condition);
7799 else
7800 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7801 advertise_map, condition_str,
7802 condition_map, condition);
7803
7804 return bgp_vty_return(vty, ret);
7805 }
7806
7807 DEFPY (bgp_condadv_period,
7808 bgp_condadv_period_cmd,
7809 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7810 NO_STR
7811 BGP_STR
7812 "Conditional advertisement settings\n"
7813 "Set period to rescan BGP table to check if condition is met\n"
7814 "Period between BGP table scans, in seconds; default 60\n")
7815 {
7816 VTY_DECLVAR_CONTEXT(bgp, bgp);
7817
7818 bgp->condition_check_period =
7819 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7820
7821 return CMD_SUCCESS;
7822 }
7823
7824 DEFPY (neighbor_advertise_map,
7825 neighbor_advertise_map_cmd,
7826 "[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",
7827 NO_STR
7828 NEIGHBOR_STR
7829 NEIGHBOR_ADDR_STR2
7830 "Route-map to conditionally advertise routes\n"
7831 "Name of advertise map\n"
7832 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7833 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7834 "Name of the exist or non exist map\n")
7835 {
7836 bool condition = CONDITION_EXIST;
7837
7838 if (!strcmp(exist, "non-exist-map"))
7839 condition = CONDITION_NON_EXIST;
7840
7841 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7842 bgp_node_safi(vty), advertise_str,
7843 condition_str, condition, !no);
7844 }
7845
7846 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7847 "[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",
7848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7849 "Route-map to conditionally advertise routes\n"
7850 "Name of advertise map\n"
7851 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7852 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7853 "Name of the exist or non exist map\n")
7854
7855 /* Set route-map to the peer. */
7856 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7857 afi_t afi, safi_t safi, const char *name_str,
7858 const char *direct_str)
7859 {
7860 int ret;
7861 struct peer *peer;
7862 int direct = RMAP_IN;
7863 struct route_map *route_map;
7864
7865 peer = peer_and_group_lookup_vty(vty, ip_str);
7866 if (!peer)
7867 return CMD_WARNING_CONFIG_FAILED;
7868
7869 /* Check filter direction. */
7870 if (strncmp(direct_str, "in", 2) == 0)
7871 direct = RMAP_IN;
7872 else if (strncmp(direct_str, "o", 1) == 0)
7873 direct = RMAP_OUT;
7874
7875 route_map = route_map_lookup_warn_noexist(vty, name_str);
7876 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7877
7878 return bgp_vty_return(vty, ret);
7879 }
7880
7881 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7882 afi_t afi, safi_t safi,
7883 const char *direct_str)
7884 {
7885 int ret;
7886 struct peer *peer;
7887 int direct = RMAP_IN;
7888
7889 peer = peer_and_group_lookup_vty(vty, ip_str);
7890 if (!peer)
7891 return CMD_WARNING_CONFIG_FAILED;
7892
7893 /* Check filter direction. */
7894 if (strncmp(direct_str, "in", 2) == 0)
7895 direct = RMAP_IN;
7896 else if (strncmp(direct_str, "o", 1) == 0)
7897 direct = RMAP_OUT;
7898
7899 ret = peer_route_map_unset(peer, afi, safi, direct);
7900
7901 return bgp_vty_return(vty, ret);
7902 }
7903
7904 DEFUN (neighbor_route_map,
7905 neighbor_route_map_cmd,
7906 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7907 NEIGHBOR_STR
7908 NEIGHBOR_ADDR_STR2
7909 "Apply route map to neighbor\n"
7910 "Name of route map\n"
7911 "Apply map to incoming routes\n"
7912 "Apply map to outbound routes\n")
7913 {
7914 int idx_peer = 1;
7915 int idx_word = 3;
7916 int idx_in_out = 4;
7917 return peer_route_map_set_vty(
7918 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7919 argv[idx_word]->arg, argv[idx_in_out]->arg);
7920 }
7921
7922 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7923 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7925 "Apply route map to neighbor\n"
7926 "Name of route map\n"
7927 "Apply map to incoming routes\n"
7928 "Apply map to outbound routes\n")
7929
7930 DEFUN (no_neighbor_route_map,
7931 no_neighbor_route_map_cmd,
7932 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7933 NO_STR
7934 NEIGHBOR_STR
7935 NEIGHBOR_ADDR_STR2
7936 "Apply route map to neighbor\n"
7937 "Name of route map\n"
7938 "Apply map to incoming routes\n"
7939 "Apply map to outbound routes\n")
7940 {
7941 int idx_peer = 2;
7942 int idx_in_out = 5;
7943 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7944 bgp_node_afi(vty), bgp_node_safi(vty),
7945 argv[idx_in_out]->arg);
7946 }
7947
7948 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7949 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7950 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7951 "Apply route map to neighbor\n"
7952 "Name of route map\n"
7953 "Apply map to incoming routes\n"
7954 "Apply map to outbound routes\n")
7955
7956 /* Set unsuppress-map to the peer. */
7957 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7958 afi_t afi, safi_t safi,
7959 const char *name_str)
7960 {
7961 int ret;
7962 struct peer *peer;
7963 struct route_map *route_map;
7964
7965 peer = peer_and_group_lookup_vty(vty, ip_str);
7966 if (!peer)
7967 return CMD_WARNING_CONFIG_FAILED;
7968
7969 route_map = route_map_lookup_warn_noexist(vty, name_str);
7970 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7971
7972 return bgp_vty_return(vty, ret);
7973 }
7974
7975 /* Unset route-map from the peer. */
7976 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7977 afi_t afi, safi_t safi)
7978 {
7979 int ret;
7980 struct peer *peer;
7981
7982 peer = peer_and_group_lookup_vty(vty, ip_str);
7983 if (!peer)
7984 return CMD_WARNING_CONFIG_FAILED;
7985
7986 ret = peer_unsuppress_map_unset(peer, afi, safi);
7987
7988 return bgp_vty_return(vty, ret);
7989 }
7990
7991 DEFUN (neighbor_unsuppress_map,
7992 neighbor_unsuppress_map_cmd,
7993 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7994 NEIGHBOR_STR
7995 NEIGHBOR_ADDR_STR2
7996 "Route-map to selectively unsuppress suppressed routes\n"
7997 "Name of route map\n")
7998 {
7999 int idx_peer = 1;
8000 int idx_word = 3;
8001 return peer_unsuppress_map_set_vty(
8002 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8003 argv[idx_word]->arg);
8004 }
8005
8006 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8007 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8008 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8009 "Route-map to selectively unsuppress suppressed routes\n"
8010 "Name of route map\n")
8011
8012 DEFUN (no_neighbor_unsuppress_map,
8013 no_neighbor_unsuppress_map_cmd,
8014 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8015 NO_STR
8016 NEIGHBOR_STR
8017 NEIGHBOR_ADDR_STR2
8018 "Route-map to selectively unsuppress suppressed routes\n"
8019 "Name of route map\n")
8020 {
8021 int idx_peer = 2;
8022 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8023 bgp_node_afi(vty),
8024 bgp_node_safi(vty));
8025 }
8026
8027 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8028 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8029 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8030 "Route-map to selectively unsuppress suppressed routes\n"
8031 "Name of route map\n")
8032
8033 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8034 afi_t afi, safi_t safi,
8035 const char *num_str,
8036 const char *threshold_str, int warning,
8037 const char *restart_str,
8038 const char *force_str)
8039 {
8040 int ret;
8041 struct peer *peer;
8042 uint32_t max;
8043 uint8_t threshold;
8044 uint16_t restart;
8045
8046 peer = peer_and_group_lookup_vty(vty, ip_str);
8047 if (!peer)
8048 return CMD_WARNING_CONFIG_FAILED;
8049
8050 max = strtoul(num_str, NULL, 10);
8051 if (threshold_str)
8052 threshold = atoi(threshold_str);
8053 else
8054 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8055
8056 if (restart_str)
8057 restart = atoi(restart_str);
8058 else
8059 restart = 0;
8060
8061 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8062 restart, force_str ? true : false);
8063
8064 return bgp_vty_return(vty, ret);
8065 }
8066
8067 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8068 afi_t afi, safi_t safi)
8069 {
8070 int ret;
8071 struct peer *peer;
8072
8073 peer = peer_and_group_lookup_vty(vty, ip_str);
8074 if (!peer)
8075 return CMD_WARNING_CONFIG_FAILED;
8076
8077 ret = peer_maximum_prefix_unset(peer, afi, safi);
8078
8079 return bgp_vty_return(vty, ret);
8080 }
8081
8082 /* Maximum number of prefix to be sent to the neighbor. */
8083 DEFUN(neighbor_maximum_prefix_out,
8084 neighbor_maximum_prefix_out_cmd,
8085 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8086 NEIGHBOR_STR
8087 NEIGHBOR_ADDR_STR2
8088 "Maximum number of prefixes to be sent to this peer\n"
8089 "Maximum no. of prefix limit\n")
8090 {
8091 int ret;
8092 int idx_peer = 1;
8093 int idx_number = 3;
8094 struct peer *peer;
8095 uint32_t max;
8096 afi_t afi = bgp_node_afi(vty);
8097 safi_t safi = bgp_node_safi(vty);
8098
8099 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8100 if (!peer)
8101 return CMD_WARNING_CONFIG_FAILED;
8102
8103 max = strtoul(argv[idx_number]->arg, NULL, 10);
8104
8105 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8106
8107 return bgp_vty_return(vty, ret);
8108 }
8109
8110 DEFUN(no_neighbor_maximum_prefix_out,
8111 no_neighbor_maximum_prefix_out_cmd,
8112 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8113 NO_STR
8114 NEIGHBOR_STR
8115 NEIGHBOR_ADDR_STR2
8116 "Maximum number of prefixes to be sent to this peer\n"
8117 "Maximum no. of prefix limit\n")
8118 {
8119 int ret;
8120 int idx_peer = 2;
8121 struct peer *peer;
8122 afi_t afi = bgp_node_afi(vty);
8123 safi_t safi = bgp_node_safi(vty);
8124
8125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8126 if (!peer)
8127 return CMD_WARNING_CONFIG_FAILED;
8128
8129 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8130
8131 return bgp_vty_return(vty, ret);
8132 }
8133
8134 /* Maximum number of prefix configuration. Prefix count is different
8135 for each peer configuration. So this configuration can be set for
8136 each peer configuration. */
8137 DEFUN (neighbor_maximum_prefix,
8138 neighbor_maximum_prefix_cmd,
8139 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8140 NEIGHBOR_STR
8141 NEIGHBOR_ADDR_STR2
8142 "Maximum number of prefix accept from this peer\n"
8143 "maximum no. of prefix limit\n"
8144 "Force checking all received routes not only accepted\n")
8145 {
8146 int idx_peer = 1;
8147 int idx_number = 3;
8148 int idx_force = 0;
8149 char *force = NULL;
8150
8151 if (argv_find(argv, argc, "force", &idx_force))
8152 force = argv[idx_force]->arg;
8153
8154 return peer_maximum_prefix_set_vty(
8155 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8156 argv[idx_number]->arg, NULL, 0, NULL, force);
8157 }
8158
8159 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8160 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8161 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8162 "Maximum number of prefix accept from this peer\n"
8163 "maximum no. of prefix limit\n"
8164 "Force checking all received routes not only accepted\n")
8165
8166 DEFUN (neighbor_maximum_prefix_threshold,
8167 neighbor_maximum_prefix_threshold_cmd,
8168 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8169 NEIGHBOR_STR
8170 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 "Force checking all received routes not only accepted\n")
8175 {
8176 int idx_peer = 1;
8177 int idx_number = 3;
8178 int idx_number_2 = 4;
8179 int idx_force = 0;
8180 char *force = NULL;
8181
8182 if (argv_find(argv, argc, "force", &idx_force))
8183 force = argv[idx_force]->arg;
8184
8185 return peer_maximum_prefix_set_vty(
8186 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8187 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8188 }
8189
8190 ALIAS_HIDDEN(
8191 neighbor_maximum_prefix_threshold,
8192 neighbor_maximum_prefix_threshold_hidden_cmd,
8193 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8194 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8195 "Maximum number of prefix accept from this peer\n"
8196 "maximum no. of prefix limit\n"
8197 "Threshold value (%) at which to generate a warning msg\n"
8198 "Force checking all received routes not only accepted\n")
8199
8200 DEFUN (neighbor_maximum_prefix_warning,
8201 neighbor_maximum_prefix_warning_cmd,
8202 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8203 NEIGHBOR_STR
8204 NEIGHBOR_ADDR_STR2
8205 "Maximum number of prefix accept from this peer\n"
8206 "maximum no. of prefix limit\n"
8207 "Only give warning message when limit is exceeded\n"
8208 "Force checking all received routes not only accepted\n")
8209 {
8210 int idx_peer = 1;
8211 int idx_number = 3;
8212 int idx_force = 0;
8213 char *force = NULL;
8214
8215 if (argv_find(argv, argc, "force", &idx_force))
8216 force = argv[idx_force]->arg;
8217
8218 return peer_maximum_prefix_set_vty(
8219 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8220 argv[idx_number]->arg, NULL, 1, NULL, force);
8221 }
8222
8223 ALIAS_HIDDEN(
8224 neighbor_maximum_prefix_warning,
8225 neighbor_maximum_prefix_warning_hidden_cmd,
8226 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8227 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8228 "Maximum number of prefix accept from this peer\n"
8229 "maximum no. of prefix limit\n"
8230 "Only give warning message when limit is exceeded\n"
8231 "Force checking all received routes not only accepted\n")
8232
8233 DEFUN (neighbor_maximum_prefix_threshold_warning,
8234 neighbor_maximum_prefix_threshold_warning_cmd,
8235 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8236 NEIGHBOR_STR
8237 NEIGHBOR_ADDR_STR2
8238 "Maximum number of prefix accept from this peer\n"
8239 "maximum no. of prefix limit\n"
8240 "Threshold value (%) at which to generate a warning msg\n"
8241 "Only give warning message when limit is exceeded\n"
8242 "Force checking all received routes not only accepted\n")
8243 {
8244 int idx_peer = 1;
8245 int idx_number = 3;
8246 int idx_number_2 = 4;
8247 int idx_force = 0;
8248 char *force = NULL;
8249
8250 if (argv_find(argv, argc, "force", &idx_force))
8251 force = argv[idx_force]->arg;
8252
8253 return peer_maximum_prefix_set_vty(
8254 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8255 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8256 }
8257
8258 ALIAS_HIDDEN(
8259 neighbor_maximum_prefix_threshold_warning,
8260 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8261 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8262 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8263 "Maximum number of prefix accept from this peer\n"
8264 "maximum no. of prefix limit\n"
8265 "Threshold value (%) at which to generate a warning msg\n"
8266 "Only give warning message when limit is exceeded\n"
8267 "Force checking all received routes not only accepted\n")
8268
8269 DEFUN (neighbor_maximum_prefix_restart,
8270 neighbor_maximum_prefix_restart_cmd,
8271 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8272 NEIGHBOR_STR
8273 NEIGHBOR_ADDR_STR2
8274 "Maximum number of prefix accept from this peer\n"
8275 "maximum no. of prefix limit\n"
8276 "Restart bgp connection after limit is exceeded\n"
8277 "Restart interval in minutes\n"
8278 "Force checking all received routes not only accepted\n")
8279 {
8280 int idx_peer = 1;
8281 int idx_number = 3;
8282 int idx_number_2 = 5;
8283 int idx_force = 0;
8284 char *force = NULL;
8285
8286 if (argv_find(argv, argc, "force", &idx_force))
8287 force = argv[idx_force]->arg;
8288
8289 return peer_maximum_prefix_set_vty(
8290 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8291 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8292 }
8293
8294 ALIAS_HIDDEN(
8295 neighbor_maximum_prefix_restart,
8296 neighbor_maximum_prefix_restart_hidden_cmd,
8297 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8298 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8299 "Maximum number of prefix accept from this peer\n"
8300 "maximum no. of prefix limit\n"
8301 "Restart bgp connection after limit is exceeded\n"
8302 "Restart interval in minutes\n"
8303 "Force checking all received routes not only accepted\n")
8304
8305 DEFUN (neighbor_maximum_prefix_threshold_restart,
8306 neighbor_maximum_prefix_threshold_restart_cmd,
8307 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8308 NEIGHBOR_STR
8309 NEIGHBOR_ADDR_STR2
8310 "Maximum number of prefixes to accept from this peer\n"
8311 "maximum no. of prefix limit\n"
8312 "Threshold value (%) at which to generate a warning msg\n"
8313 "Restart bgp connection after limit is exceeded\n"
8314 "Restart interval in minutes\n"
8315 "Force checking all received routes not only accepted\n")
8316 {
8317 int idx_peer = 1;
8318 int idx_number = 3;
8319 int idx_number_2 = 4;
8320 int idx_number_3 = 6;
8321 int idx_force = 0;
8322 char *force = NULL;
8323
8324 if (argv_find(argv, argc, "force", &idx_force))
8325 force = argv[idx_force]->arg;
8326
8327 return peer_maximum_prefix_set_vty(
8328 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8329 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8330 argv[idx_number_3]->arg, force);
8331 }
8332
8333 ALIAS_HIDDEN(
8334 neighbor_maximum_prefix_threshold_restart,
8335 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8336 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8338 "Maximum number of prefixes to accept from this peer\n"
8339 "maximum no. of prefix limit\n"
8340 "Threshold value (%) at which to generate a warning msg\n"
8341 "Restart bgp connection after limit is exceeded\n"
8342 "Restart interval in minutes\n"
8343 "Force checking all received routes not only accepted\n")
8344
8345 DEFUN (no_neighbor_maximum_prefix,
8346 no_neighbor_maximum_prefix_cmd,
8347 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8348 NO_STR
8349 NEIGHBOR_STR
8350 NEIGHBOR_ADDR_STR2
8351 "Maximum number of prefixes to accept from this peer\n"
8352 "maximum no. of prefix limit\n"
8353 "Threshold value (%) at which to generate a warning msg\n"
8354 "Restart bgp connection after limit is exceeded\n"
8355 "Restart interval in minutes\n"
8356 "Only give warning message when limit is exceeded\n"
8357 "Force checking all received routes not only accepted\n")
8358 {
8359 int idx_peer = 2;
8360 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8361 bgp_node_afi(vty),
8362 bgp_node_safi(vty));
8363 }
8364
8365 ALIAS_HIDDEN(
8366 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8367 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8368 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8369 "Maximum number of prefixes to accept from this peer\n"
8370 "maximum no. of prefix limit\n"
8371 "Threshold value (%) at which to generate a warning msg\n"
8372 "Restart bgp connection after limit is exceeded\n"
8373 "Restart interval in minutes\n"
8374 "Only give warning message when limit is exceeded\n"
8375 "Force checking all received routes not only accepted\n")
8376
8377 /* "neighbor accept-own" */
8378 DEFPY (neighbor_accept_own,
8379 neighbor_accept_own_cmd,
8380 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8381 NO_STR
8382 NEIGHBOR_STR
8383 NEIGHBOR_ADDR_STR2
8384 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8385 {
8386 struct peer *peer;
8387 afi_t afi = bgp_node_afi(vty);
8388 safi_t safi = bgp_node_safi(vty);
8389 int ret;
8390
8391 peer = peer_and_group_lookup_vty(vty, neighbor);
8392 if (!peer)
8393 return CMD_WARNING_CONFIG_FAILED;
8394
8395 if (no)
8396 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8397 else
8398 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8399
8400 return bgp_vty_return(vty, ret);
8401 }
8402
8403 /* "neighbor soo" */
8404 DEFPY (neighbor_soo,
8405 neighbor_soo_cmd,
8406 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8407 NEIGHBOR_STR
8408 NEIGHBOR_ADDR_STR2
8409 "Set the Site-of-Origin (SoO) extended community\n"
8410 "VPN extended community\n")
8411 {
8412 struct peer *peer;
8413 afi_t afi = bgp_node_afi(vty);
8414 safi_t safi = bgp_node_safi(vty);
8415 struct ecommunity *ecomm_soo;
8416
8417 peer = peer_and_group_lookup_vty(vty, neighbor);
8418 if (!peer)
8419 return CMD_WARNING_CONFIG_FAILED;
8420
8421 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8422 if (!ecomm_soo) {
8423 vty_out(vty, "%% Malformed SoO extended community\n");
8424 return CMD_WARNING;
8425 }
8426 ecommunity_str(ecomm_soo);
8427
8428 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8429 ecommunity_free(&peer->soo[afi][safi]);
8430 peer->soo[afi][safi] = ecomm_soo;
8431 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8432 }
8433
8434 return bgp_vty_return(vty,
8435 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8436 }
8437
8438 DEFPY (no_neighbor_soo,
8439 no_neighbor_soo_cmd,
8440 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8441 NO_STR
8442 NEIGHBOR_STR
8443 NEIGHBOR_ADDR_STR2
8444 "Set the Site-of-Origin (SoO) extended community\n"
8445 "VPN extended community\n")
8446 {
8447 struct peer *peer;
8448 afi_t afi = bgp_node_afi(vty);
8449 safi_t safi = bgp_node_safi(vty);
8450
8451 peer = peer_and_group_lookup_vty(vty, neighbor);
8452 if (!peer)
8453 return CMD_WARNING_CONFIG_FAILED;
8454
8455 ecommunity_free(&peer->soo[afi][safi]);
8456
8457 return bgp_vty_return(
8458 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8459 }
8460
8461 /* "neighbor allowas-in" */
8462 DEFUN (neighbor_allowas_in,
8463 neighbor_allowas_in_cmd,
8464 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8465 NEIGHBOR_STR
8466 NEIGHBOR_ADDR_STR2
8467 "Accept as-path with my AS present in it\n"
8468 "Number of occurrences of AS number\n"
8469 "Only accept my AS in the as-path if the route was originated in my AS\n")
8470 {
8471 int idx_peer = 1;
8472 int idx_number_origin = 3;
8473 int ret;
8474 int origin = 0;
8475 struct peer *peer;
8476 int allow_num = 0;
8477
8478 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8479 if (!peer)
8480 return CMD_WARNING_CONFIG_FAILED;
8481
8482 if (argc <= idx_number_origin)
8483 allow_num = 3;
8484 else {
8485 if (argv[idx_number_origin]->type == WORD_TKN)
8486 origin = 1;
8487 else
8488 allow_num = atoi(argv[idx_number_origin]->arg);
8489 }
8490
8491 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8492 allow_num, origin);
8493
8494 return bgp_vty_return(vty, ret);
8495 }
8496
8497 ALIAS_HIDDEN(
8498 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8499 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8500 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8501 "Accept as-path with my AS present in it\n"
8502 "Number of occurrences of AS number\n"
8503 "Only accept my AS in the as-path if the route was originated in my AS\n")
8504
8505 DEFUN (no_neighbor_allowas_in,
8506 no_neighbor_allowas_in_cmd,
8507 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8508 NO_STR
8509 NEIGHBOR_STR
8510 NEIGHBOR_ADDR_STR2
8511 "allow local ASN appears in aspath attribute\n"
8512 "Number of occurrences of AS number\n"
8513 "Only accept my AS in the as-path if the route was originated in my AS\n")
8514 {
8515 int idx_peer = 2;
8516 int ret;
8517 struct peer *peer;
8518
8519 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8520 if (!peer)
8521 return CMD_WARNING_CONFIG_FAILED;
8522
8523 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8524 bgp_node_safi(vty));
8525
8526 return bgp_vty_return(vty, ret);
8527 }
8528
8529 ALIAS_HIDDEN(
8530 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8531 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8532 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8533 "allow local ASN appears in aspath attribute\n"
8534 "Number of occurrences of AS number\n"
8535 "Only accept my AS in the as-path if the route was originated in my AS\n")
8536
8537 DEFUN (neighbor_ttl_security,
8538 neighbor_ttl_security_cmd,
8539 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8540 NEIGHBOR_STR
8541 NEIGHBOR_ADDR_STR2
8542 "BGP ttl-security parameters\n"
8543 "Specify the maximum number of hops to the BGP peer\n"
8544 "Number of hops to BGP peer\n")
8545 {
8546 int idx_peer = 1;
8547 int idx_number = 4;
8548 struct peer *peer;
8549 int gtsm_hops;
8550
8551 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8552 if (!peer)
8553 return CMD_WARNING_CONFIG_FAILED;
8554
8555 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8556
8557 /*
8558 * If 'neighbor swpX', then this is for directly connected peers,
8559 * we should not accept a ttl-security hops value greater than 1.
8560 */
8561 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8562 vty_out(vty,
8563 "%s is directly connected peer, hops cannot exceed 1\n",
8564 argv[idx_peer]->arg);
8565 return CMD_WARNING_CONFIG_FAILED;
8566 }
8567
8568 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8569 }
8570
8571 DEFUN (no_neighbor_ttl_security,
8572 no_neighbor_ttl_security_cmd,
8573 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8574 NO_STR
8575 NEIGHBOR_STR
8576 NEIGHBOR_ADDR_STR2
8577 "BGP ttl-security parameters\n"
8578 "Specify the maximum number of hops to the BGP peer\n"
8579 "Number of hops to BGP peer\n")
8580 {
8581 int idx_peer = 2;
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 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8589 }
8590
8591 /* disable-addpath-rx */
8592 DEFUN(neighbor_disable_addpath_rx,
8593 neighbor_disable_addpath_rx_cmd,
8594 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8595 NEIGHBOR_STR
8596 NEIGHBOR_ADDR_STR2
8597 "Do not accept additional paths\n")
8598 {
8599 char *peer_str = argv[1]->arg;
8600 struct peer *peer;
8601 afi_t afi = bgp_node_afi(vty);
8602 safi_t safi = bgp_node_safi(vty);
8603
8604 peer = peer_and_group_lookup_vty(vty, peer_str);
8605 if (!peer)
8606 return CMD_WARNING_CONFIG_FAILED;
8607
8608 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8609 PEER_FLAG_DISABLE_ADDPATH_RX);
8610 }
8611
8612 DEFUN(no_neighbor_disable_addpath_rx,
8613 no_neighbor_disable_addpath_rx_cmd,
8614 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8615 NO_STR
8616 NEIGHBOR_STR
8617 NEIGHBOR_ADDR_STR2
8618 "Do not accept additional paths\n")
8619 {
8620 char *peer_str = argv[2]->arg;
8621 struct peer *peer;
8622 afi_t afi = bgp_node_afi(vty);
8623 safi_t safi = bgp_node_safi(vty);
8624
8625 peer = peer_and_group_lookup_vty(vty, peer_str);
8626 if (!peer)
8627 return CMD_WARNING_CONFIG_FAILED;
8628
8629 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8630 PEER_FLAG_DISABLE_ADDPATH_RX);
8631 }
8632
8633 DEFUN (neighbor_addpath_tx_all_paths,
8634 neighbor_addpath_tx_all_paths_cmd,
8635 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8636 NEIGHBOR_STR
8637 NEIGHBOR_ADDR_STR2
8638 "Use addpath to advertise all paths to a neighbor\n")
8639 {
8640 int idx_peer = 1;
8641 struct peer *peer;
8642
8643 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8644 if (!peer)
8645 return CMD_WARNING_CONFIG_FAILED;
8646
8647 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8648 BGP_ADDPATH_ALL);
8649 return CMD_SUCCESS;
8650 }
8651
8652 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8653 neighbor_addpath_tx_all_paths_hidden_cmd,
8654 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8655 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8656 "Use addpath to advertise all paths to a neighbor\n")
8657
8658 DEFUN (no_neighbor_addpath_tx_all_paths,
8659 no_neighbor_addpath_tx_all_paths_cmd,
8660 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8661 NO_STR
8662 NEIGHBOR_STR
8663 NEIGHBOR_ADDR_STR2
8664 "Use addpath to advertise all paths to a neighbor\n")
8665 {
8666 int idx_peer = 2;
8667 struct peer *peer;
8668
8669 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8670 if (!peer)
8671 return CMD_WARNING_CONFIG_FAILED;
8672
8673 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8674 != BGP_ADDPATH_ALL) {
8675 vty_out(vty,
8676 "%% Peer not currently configured to transmit all paths.");
8677 return CMD_WARNING_CONFIG_FAILED;
8678 }
8679
8680 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8681 BGP_ADDPATH_NONE);
8682
8683 return CMD_SUCCESS;
8684 }
8685
8686 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8687 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8688 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8689 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8690 "Use addpath to advertise all paths to a neighbor\n")
8691
8692 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8693 neighbor_addpath_tx_bestpath_per_as_cmd,
8694 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8695 NEIGHBOR_STR
8696 NEIGHBOR_ADDR_STR2
8697 "Use addpath to advertise the bestpath per each neighboring AS\n")
8698 {
8699 int idx_peer = 1;
8700 struct peer *peer;
8701
8702 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8703 if (!peer)
8704 return CMD_WARNING_CONFIG_FAILED;
8705
8706 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8707 BGP_ADDPATH_BEST_PER_AS);
8708
8709 return CMD_SUCCESS;
8710 }
8711
8712 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8713 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8714 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8716 "Use addpath to advertise the bestpath per each neighboring AS\n")
8717
8718 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8719 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8720 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8721 NO_STR
8722 NEIGHBOR_STR
8723 NEIGHBOR_ADDR_STR2
8724 "Use addpath to advertise the bestpath per each neighboring AS\n")
8725 {
8726 int idx_peer = 2;
8727 struct peer *peer;
8728
8729 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8730 if (!peer)
8731 return CMD_WARNING_CONFIG_FAILED;
8732
8733 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8734 != BGP_ADDPATH_BEST_PER_AS) {
8735 vty_out(vty,
8736 "%% Peer not currently configured to transmit all best path per as.");
8737 return CMD_WARNING_CONFIG_FAILED;
8738 }
8739
8740 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8741 BGP_ADDPATH_NONE);
8742
8743 return CMD_SUCCESS;
8744 }
8745
8746 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8747 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8748 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8749 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8750 "Use addpath to advertise the bestpath per each neighboring AS\n")
8751
8752 DEFPY(
8753 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8754 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8755 NEIGHBOR_STR
8756 NEIGHBOR_ADDR_STR2
8757 "Detect AS loops before sending to neighbor\n")
8758 {
8759 struct peer *peer;
8760
8761 peer = peer_and_group_lookup_vty(vty, neighbor);
8762 if (!peer)
8763 return CMD_WARNING_CONFIG_FAILED;
8764
8765 peer->as_path_loop_detection = true;
8766
8767 return CMD_SUCCESS;
8768 }
8769
8770 DEFPY(
8771 no_neighbor_aspath_loop_detection,
8772 no_neighbor_aspath_loop_detection_cmd,
8773 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8774 NO_STR
8775 NEIGHBOR_STR
8776 NEIGHBOR_ADDR_STR2
8777 "Detect AS loops before sending to neighbor\n")
8778 {
8779 struct peer *peer;
8780
8781 peer = peer_and_group_lookup_vty(vty, neighbor);
8782 if (!peer)
8783 return CMD_WARNING_CONFIG_FAILED;
8784
8785 peer->as_path_loop_detection = false;
8786
8787 return CMD_SUCCESS;
8788 }
8789
8790 DEFPY(neighbor_path_attribute_discard,
8791 neighbor_path_attribute_discard_cmd,
8792 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8793 NEIGHBOR_STR
8794 NEIGHBOR_ADDR_STR2
8795 "Manipulate path attributes from incoming UPDATE messages\n"
8796 "Drop specified attributes from incoming UPDATE messages\n"
8797 "Attribute number\n")
8798 {
8799 struct peer *peer;
8800 int idx = 0;
8801 const char *discard_attrs = NULL;
8802
8803 peer = peer_and_group_lookup_vty(vty, neighbor);
8804 if (!peer)
8805 return CMD_WARNING_CONFIG_FAILED;
8806
8807 argv_find(argv, argc, "(1-255)", &idx);
8808 if (idx)
8809 discard_attrs = argv_concat(argv, argc, idx);
8810
8811 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8812
8813 return CMD_SUCCESS;
8814 }
8815
8816 DEFPY(no_neighbor_path_attribute_discard,
8817 no_neighbor_path_attribute_discard_cmd,
8818 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8819 NO_STR
8820 NEIGHBOR_STR
8821 NEIGHBOR_ADDR_STR2
8822 "Manipulate path attributes from incoming UPDATE messages\n"
8823 "Drop specified attributes from incoming UPDATE messages\n"
8824 "Attribute number\n")
8825 {
8826 struct peer *peer;
8827 int idx = 0;
8828 const char *discard_attrs = NULL;
8829
8830 peer = peer_and_group_lookup_vty(vty, neighbor);
8831 if (!peer)
8832 return CMD_WARNING_CONFIG_FAILED;
8833
8834 argv_find(argv, argc, "(1-255)", &idx);
8835 if (idx)
8836 discard_attrs = argv[idx]->arg;
8837
8838 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
8839
8840 return CMD_SUCCESS;
8841 }
8842
8843 DEFPY(neighbor_path_attribute_treat_as_withdraw,
8844 neighbor_path_attribute_treat_as_withdraw_cmd,
8845 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8846 NEIGHBOR_STR
8847 NEIGHBOR_ADDR_STR2
8848 "Manipulate path attributes from incoming UPDATE messages\n"
8849 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8850 "Attribute number\n")
8851 {
8852 struct peer *peer;
8853 int idx = 0;
8854 const char *withdraw_attrs = NULL;
8855
8856 peer = peer_and_group_lookup_vty(vty, neighbor);
8857 if (!peer)
8858 return CMD_WARNING_CONFIG_FAILED;
8859
8860 argv_find(argv, argc, "(1-255)", &idx);
8861 if (idx)
8862 withdraw_attrs = argv_concat(argv, argc, idx);
8863
8864 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, true);
8865
8866 return CMD_SUCCESS;
8867 }
8868
8869 DEFPY(no_neighbor_path_attribute_treat_as_withdraw,
8870 no_neighbor_path_attribute_treat_as_withdraw_cmd,
8871 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8872 NO_STR
8873 NEIGHBOR_STR
8874 NEIGHBOR_ADDR_STR2
8875 "Manipulate path attributes from incoming UPDATE messages\n"
8876 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8877 "Attribute number\n")
8878 {
8879 struct peer *peer;
8880 int idx = 0;
8881 const char *withdraw_attrs = NULL;
8882
8883 peer = peer_and_group_lookup_vty(vty, neighbor);
8884 if (!peer)
8885 return CMD_WARNING_CONFIG_FAILED;
8886
8887 argv_find(argv, argc, "(1-255)", &idx);
8888 if (idx)
8889 withdraw_attrs = argv_concat(argv, argc, idx);
8890
8891 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, false);
8892
8893 return CMD_SUCCESS;
8894 }
8895
8896 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8897 struct ecommunity **list, bool is_rt6)
8898 {
8899 struct ecommunity *ecom = NULL;
8900 struct ecommunity *ecomadd;
8901
8902 for (; argc; --argc, ++argv) {
8903 if (is_rt6)
8904 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8905 ECOMMUNITY_ROUTE_TARGET,
8906 0);
8907 else
8908 ecomadd = ecommunity_str2com(argv[0]->arg,
8909 ECOMMUNITY_ROUTE_TARGET,
8910 0);
8911 if (!ecomadd) {
8912 vty_out(vty, "Malformed community-list value\n");
8913 if (ecom)
8914 ecommunity_free(&ecom);
8915 return CMD_WARNING_CONFIG_FAILED;
8916 }
8917
8918 if (ecom) {
8919 ecommunity_merge(ecom, ecomadd);
8920 ecommunity_free(&ecomadd);
8921 } else {
8922 ecom = ecomadd;
8923 }
8924 }
8925
8926 if (*list) {
8927 ecommunity_free(&*list);
8928 }
8929 *list = ecom;
8930
8931 return CMD_SUCCESS;
8932 }
8933
8934 /*
8935 * v2vimport is true if we are handling a `import vrf ...` command
8936 */
8937 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8938 {
8939 afi_t afi;
8940
8941 switch (vty->node) {
8942 case BGP_IPV4_NODE:
8943 afi = AFI_IP;
8944 break;
8945 case BGP_IPV6_NODE:
8946 afi = AFI_IP6;
8947 break;
8948 default:
8949 vty_out(vty,
8950 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8951 return AFI_MAX;
8952 }
8953
8954 if (!v2vimport) {
8955 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8956 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8957 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8958 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8959 vty_out(vty,
8960 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8961 return AFI_MAX;
8962 }
8963 } else {
8964 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8965 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8966 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8967 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8968 vty_out(vty,
8969 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8970 return AFI_MAX;
8971 }
8972 }
8973 return afi;
8974 }
8975
8976 DEFPY (af_rd_vpn_export,
8977 af_rd_vpn_export_cmd,
8978 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8979 NO_STR
8980 "Specify route distinguisher\n"
8981 "Between current address-family and vpn\n"
8982 "For routes leaked from current address-family to vpn\n"
8983 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8984 {
8985 VTY_DECLVAR_CONTEXT(bgp, bgp);
8986 struct prefix_rd prd;
8987 int ret;
8988 afi_t afi;
8989 int idx = 0;
8990 bool yes = true;
8991
8992 if (argv_find(argv, argc, "no", &idx))
8993 yes = false;
8994
8995 if (yes) {
8996 ret = str2prefix_rd(rd_str, &prd);
8997 if (!ret) {
8998 vty_out(vty, "%% Malformed rd\n");
8999 return CMD_WARNING_CONFIG_FAILED;
9000 }
9001 }
9002
9003 afi = vpn_policy_getafi(vty, bgp, false);
9004 if (afi == AFI_MAX)
9005 return CMD_WARNING_CONFIG_FAILED;
9006
9007 /*
9008 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9009 */
9010 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9011 bgp_get_default(), bgp);
9012
9013 if (yes) {
9014 bgp->vpn_policy[afi].tovpn_rd = prd;
9015 SET_FLAG(bgp->vpn_policy[afi].flags,
9016 BGP_VPN_POLICY_TOVPN_RD_SET);
9017 } else {
9018 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9019 BGP_VPN_POLICY_TOVPN_RD_SET);
9020 }
9021
9022 /* post-change: re-export vpn routes */
9023 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9024 bgp_get_default(), bgp);
9025
9026 return CMD_SUCCESS;
9027 }
9028
9029 ALIAS (af_rd_vpn_export,
9030 af_no_rd_vpn_export_cmd,
9031 "no rd vpn export",
9032 NO_STR
9033 "Specify route distinguisher\n"
9034 "Between current address-family and vpn\n"
9035 "For routes leaked from current address-family to vpn\n")
9036
9037 DEFPY (af_label_vpn_export,
9038 af_label_vpn_export_cmd,
9039 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9040 NO_STR
9041 "label value for VRF\n"
9042 "Between current address-family and vpn\n"
9043 "For routes leaked from current address-family to vpn\n"
9044 "Label Value <0-1048575>\n"
9045 "Automatically assign a label\n")
9046 {
9047 VTY_DECLVAR_CONTEXT(bgp, bgp);
9048 mpls_label_t label = MPLS_LABEL_NONE;
9049 afi_t afi;
9050 int idx = 0;
9051 bool yes = true;
9052
9053 if (argv_find(argv, argc, "no", &idx))
9054 yes = false;
9055
9056 /* If "no ...", squash trailing parameter */
9057 if (!yes)
9058 label_auto = NULL;
9059
9060 if (yes) {
9061 if (!label_auto)
9062 label = label_val; /* parser should force unsigned */
9063 }
9064
9065 afi = vpn_policy_getafi(vty, bgp, false);
9066 if (afi == AFI_MAX)
9067 return CMD_WARNING_CONFIG_FAILED;
9068
9069
9070 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9071 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9072 /* no change */
9073 return CMD_SUCCESS;
9074
9075 /*
9076 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9077 */
9078 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9079 bgp_get_default(), bgp);
9080
9081 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9082 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9083
9084 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9085
9086 /*
9087 * label has previously been automatically
9088 * assigned by labelpool: release it
9089 *
9090 * NB if tovpn_label == MPLS_LABEL_NONE it
9091 * means the automatic assignment is in flight
9092 * and therefore the labelpool callback must
9093 * detect that the auto label is not needed.
9094 */
9095
9096 bgp_lp_release(LP_TYPE_VRF,
9097 &bgp->vpn_policy[afi],
9098 bgp->vpn_policy[afi].tovpn_label);
9099 }
9100 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9101 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9102 }
9103
9104 bgp->vpn_policy[afi].tovpn_label = label;
9105 if (label_auto) {
9106 SET_FLAG(bgp->vpn_policy[afi].flags,
9107 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9108 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9109 vpn_leak_label_callback);
9110 }
9111
9112 /* post-change: re-export vpn routes */
9113 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9114 bgp_get_default(), bgp);
9115
9116 hook_call(bgp_snmp_update_last_changed, bgp);
9117 return CMD_SUCCESS;
9118 }
9119
9120 DEFPY (af_sid_vpn_export,
9121 af_sid_vpn_export_cmd,
9122 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9123 NO_STR
9124 "sid value for VRF\n"
9125 "Between current address-family and vpn\n"
9126 "For routes leaked from current address-family to vpn\n"
9127 "Sid allocation index\n"
9128 "Automatically assign a label\n")
9129 {
9130 VTY_DECLVAR_CONTEXT(bgp, bgp);
9131 afi_t afi;
9132 int debug = 0;
9133 int idx = 0;
9134 bool yes = true;
9135
9136 if (argv_find(argv, argc, "no", &idx))
9137 yes = false;
9138 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9139 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9140
9141 afi = vpn_policy_getafi(vty, bgp, false);
9142 if (afi == AFI_MAX)
9143 return CMD_WARNING_CONFIG_FAILED;
9144
9145 if (!yes) {
9146 /* implement me */
9147 vty_out(vty, "It's not implemented\n");
9148 return CMD_WARNING_CONFIG_FAILED;
9149 }
9150
9151 if (bgp->tovpn_sid_index != 0 ||
9152 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9153 vty_out(vty,
9154 "per-vrf sid and per-af sid are mutually exclusive\n"
9155 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9156 return CMD_WARNING_CONFIG_FAILED;
9157 }
9158
9159 /* skip when it's already configured */
9160 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9161 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9162 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9163 return CMD_SUCCESS;
9164
9165 /*
9166 * mode change between sid_idx and sid_auto isn't supported.
9167 * user must negate sid vpn export when they want to change the mode
9168 */
9169 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9170 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9171 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9172 vty_out(vty, "it's already configured as %s.\n",
9173 sid_auto ? "auto-mode" : "idx-mode");
9174 return CMD_WARNING_CONFIG_FAILED;
9175 }
9176
9177 /* pre-change */
9178 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9179 bgp_get_default(), bgp);
9180
9181 if (sid_auto) {
9182 /* SID allocation auto-mode */
9183 if (debug)
9184 zlog_debug("%s: auto sid alloc.", __func__);
9185 SET_FLAG(bgp->vpn_policy[afi].flags,
9186 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9187 } else {
9188 /* SID allocation index-mode */
9189 if (debug)
9190 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9191 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9192 }
9193
9194 /* post-change */
9195 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9196 bgp_get_default(), bgp);
9197 return CMD_SUCCESS;
9198 }
9199
9200 DEFPY (bgp_sid_vpn_export,
9201 bgp_sid_vpn_export_cmd,
9202 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9203 NO_STR
9204 "sid value for VRF\n"
9205 "Between current vrf and vpn\n"
9206 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9207 "For routes leaked from current vrf to vpn\n"
9208 "Sid allocation index\n"
9209 "Automatically assign a label\n")
9210 {
9211 VTY_DECLVAR_CONTEXT(bgp, bgp);
9212 int debug;
9213
9214 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9215 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9216
9217 if (no) {
9218 /* when per-VRF SID is not set, do nothing */
9219 if (bgp->tovpn_sid_index == 0 &&
9220 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9221 return CMD_SUCCESS;
9222
9223 sid_idx = 0;
9224 sid_auto = false;
9225 bgp->tovpn_sid_index = 0;
9226 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9227 }
9228
9229 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9230 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9231 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9232 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9233 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9234 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9235 vty_out(vty,
9236 "per-vrf sid and per-af sid are mutually exclusive\n"
9237 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9238 return CMD_WARNING_CONFIG_FAILED;
9239 }
9240
9241 /* skip when it's already configured */
9242 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9243 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9244 return CMD_SUCCESS;
9245
9246 /*
9247 * mode change between sid_idx and sid_auto isn't supported.
9248 * user must negate sid vpn export when they want to change the mode
9249 */
9250 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9251 (sid_idx != 0 &&
9252 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9253 vty_out(vty, "it's already configured as %s.\n",
9254 sid_auto ? "auto-mode" : "idx-mode");
9255 return CMD_WARNING_CONFIG_FAILED;
9256 }
9257
9258 /* pre-change */
9259 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9260 bgp);
9261 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9262 bgp);
9263
9264 if (sid_auto) {
9265 /* SID allocation auto-mode */
9266 if (debug)
9267 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9268 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9269 } else if (sid_idx != 0) {
9270 /* SID allocation index-mode */
9271 if (debug)
9272 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9273 sid_idx);
9274 bgp->tovpn_sid_index = sid_idx;
9275 }
9276
9277 /* post-change */
9278 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9279 bgp);
9280 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9281 bgp_get_default(), bgp);
9282
9283 return CMD_SUCCESS;
9284 }
9285
9286 ALIAS (af_label_vpn_export,
9287 af_no_label_vpn_export_cmd,
9288 "no label vpn export",
9289 NO_STR
9290 "label value for VRF\n"
9291 "Between current address-family and vpn\n"
9292 "For routes leaked from current address-family to vpn\n")
9293
9294 ALIAS (bgp_sid_vpn_export,
9295 no_bgp_sid_vpn_export_cmd,
9296 "no$no sid vpn per-vrf export",
9297 NO_STR
9298 "sid value for VRF\n"
9299 "Between current vrf and vpn\n"
9300 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9301 "For routes leaked from current vrf to vpn\n")
9302
9303 DEFPY (af_nexthop_vpn_export,
9304 af_nexthop_vpn_export_cmd,
9305 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9306 NO_STR
9307 "Specify next hop to use for VRF advertised prefixes\n"
9308 "Between current address-family and vpn\n"
9309 "For routes leaked from current address-family to vpn\n"
9310 "IPv4 prefix\n"
9311 "IPv6 prefix\n")
9312 {
9313 VTY_DECLVAR_CONTEXT(bgp, bgp);
9314 afi_t afi;
9315 struct prefix p;
9316
9317 if (!no) {
9318 if (!nexthop_su) {
9319 vty_out(vty, "%% Nexthop required\n");
9320 return CMD_WARNING_CONFIG_FAILED;
9321 }
9322 if (!sockunion2hostprefix(nexthop_su, &p))
9323 return CMD_WARNING_CONFIG_FAILED;
9324 }
9325
9326 afi = vpn_policy_getafi(vty, bgp, false);
9327 if (afi == AFI_MAX)
9328 return CMD_WARNING_CONFIG_FAILED;
9329
9330 /*
9331 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9332 */
9333 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9334 bgp_get_default(), bgp);
9335
9336 if (!no) {
9337 bgp->vpn_policy[afi].tovpn_nexthop = p;
9338 SET_FLAG(bgp->vpn_policy[afi].flags,
9339 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9340 } else {
9341 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9342 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9343 }
9344
9345 /* post-change: re-export vpn routes */
9346 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9347 bgp_get_default(), bgp);
9348
9349 return CMD_SUCCESS;
9350 }
9351
9352 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9353 {
9354 if (!strcmp(dstr, "import")) {
9355 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9356 } else if (!strcmp(dstr, "export")) {
9357 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9358 } else if (!strcmp(dstr, "both")) {
9359 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9360 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9361 } else {
9362 vty_out(vty, "%% direction parse error\n");
9363 return CMD_WARNING_CONFIG_FAILED;
9364 }
9365 return CMD_SUCCESS;
9366 }
9367
9368 DEFPY (af_rt_vpn_imexport,
9369 af_rt_vpn_imexport_cmd,
9370 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9371 NO_STR
9372 "Specify route target list\n"
9373 "Specify route target list\n"
9374 "Between current address-family and vpn\n"
9375 "For routes leaked from vpn to current address-family: match any\n"
9376 "For routes leaked from current address-family to vpn: set\n"
9377 "both import: match any and export: set\n"
9378 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9379 {
9380 VTY_DECLVAR_CONTEXT(bgp, bgp);
9381 int ret;
9382 struct ecommunity *ecom = NULL;
9383 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9384 enum vpn_policy_direction dir;
9385 afi_t afi;
9386 int idx = 0;
9387 bool yes = true;
9388
9389 if (argv_find(argv, argc, "no", &idx))
9390 yes = false;
9391
9392 afi = vpn_policy_getafi(vty, bgp, false);
9393 if (afi == AFI_MAX)
9394 return CMD_WARNING_CONFIG_FAILED;
9395
9396 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9397 if (ret != CMD_SUCCESS)
9398 return ret;
9399
9400 if (yes) {
9401 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9402 vty_out(vty, "%% Missing RTLIST\n");
9403 return CMD_WARNING_CONFIG_FAILED;
9404 }
9405 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9406 if (ret != CMD_SUCCESS) {
9407 return ret;
9408 }
9409 }
9410
9411 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9412 if (!dodir[dir])
9413 continue;
9414
9415 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9416
9417 if (yes) {
9418 if (bgp->vpn_policy[afi].rtlist[dir])
9419 ecommunity_free(
9420 &bgp->vpn_policy[afi].rtlist[dir]);
9421 bgp->vpn_policy[afi].rtlist[dir] =
9422 ecommunity_dup(ecom);
9423 } else {
9424 if (bgp->vpn_policy[afi].rtlist[dir])
9425 ecommunity_free(
9426 &bgp->vpn_policy[afi].rtlist[dir]);
9427 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9428 }
9429
9430 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9431 }
9432
9433 if (ecom)
9434 ecommunity_free(&ecom);
9435
9436 return CMD_SUCCESS;
9437 }
9438
9439 ALIAS (af_rt_vpn_imexport,
9440 af_no_rt_vpn_imexport_cmd,
9441 "no <rt|route-target> vpn <import|export|both>$direction_str",
9442 NO_STR
9443 "Specify route target list\n"
9444 "Specify route target list\n"
9445 "Between current address-family and vpn\n"
9446 "For routes leaked from vpn to current address-family\n"
9447 "For routes leaked from current address-family to vpn\n"
9448 "both import and export\n")
9449
9450 DEFPY (af_route_map_vpn_imexport,
9451 af_route_map_vpn_imexport_cmd,
9452 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9453 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9454 NO_STR
9455 "Specify route map\n"
9456 "Between current address-family and vpn\n"
9457 "For routes leaked from vpn to current address-family\n"
9458 "For routes leaked from current address-family to vpn\n"
9459 "name of route-map\n")
9460 {
9461 VTY_DECLVAR_CONTEXT(bgp, bgp);
9462 int ret;
9463 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9464 enum vpn_policy_direction dir;
9465 afi_t afi;
9466 int idx = 0;
9467 bool yes = true;
9468
9469 if (argv_find(argv, argc, "no", &idx))
9470 yes = false;
9471
9472 afi = vpn_policy_getafi(vty, bgp, false);
9473 if (afi == AFI_MAX)
9474 return CMD_WARNING_CONFIG_FAILED;
9475
9476 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9477 if (ret != CMD_SUCCESS)
9478 return ret;
9479
9480 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9481 if (!dodir[dir])
9482 continue;
9483
9484 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9485
9486 if (yes) {
9487 if (bgp->vpn_policy[afi].rmap_name[dir])
9488 XFREE(MTYPE_ROUTE_MAP_NAME,
9489 bgp->vpn_policy[afi].rmap_name[dir]);
9490 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9491 MTYPE_ROUTE_MAP_NAME, rmap_str);
9492 bgp->vpn_policy[afi].rmap[dir] =
9493 route_map_lookup_warn_noexist(vty, rmap_str);
9494 if (!bgp->vpn_policy[afi].rmap[dir])
9495 return CMD_SUCCESS;
9496 } else {
9497 if (bgp->vpn_policy[afi].rmap_name[dir])
9498 XFREE(MTYPE_ROUTE_MAP_NAME,
9499 bgp->vpn_policy[afi].rmap_name[dir]);
9500 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9501 bgp->vpn_policy[afi].rmap[dir] = NULL;
9502 }
9503
9504 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9505 }
9506
9507 return CMD_SUCCESS;
9508 }
9509
9510 ALIAS (af_route_map_vpn_imexport,
9511 af_no_route_map_vpn_imexport_cmd,
9512 "no route-map vpn <import|export>$direction_str",
9513 NO_STR
9514 "Specify route map\n"
9515 "Between current address-family and vpn\n"
9516 "For routes leaked from vpn to current address-family\n"
9517 "For routes leaked from current address-family to vpn\n")
9518
9519 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9520 "import vrf route-map RMAP$rmap_str",
9521 "Import routes from another VRF\n"
9522 "Vrf routes being filtered\n"
9523 "Specify route map\n"
9524 "name of route-map\n")
9525 {
9526 VTY_DECLVAR_CONTEXT(bgp, bgp);
9527 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9528 afi_t afi;
9529 struct bgp *bgp_default;
9530
9531 afi = vpn_policy_getafi(vty, bgp, true);
9532 if (afi == AFI_MAX)
9533 return CMD_WARNING_CONFIG_FAILED;
9534
9535 bgp_default = bgp_get_default();
9536 if (!bgp_default) {
9537 int32_t ret;
9538 as_t as = bgp->as;
9539
9540 /* Auto-create assuming the same AS */
9541 ret = bgp_get_vty(&bgp_default, &as, NULL,
9542 BGP_INSTANCE_TYPE_DEFAULT);
9543
9544 if (ret) {
9545 vty_out(vty,
9546 "VRF default is not configured as a bgp instance\n");
9547 return CMD_WARNING;
9548 }
9549 }
9550
9551 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9552
9553 if (bgp->vpn_policy[afi].rmap_name[dir])
9554 XFREE(MTYPE_ROUTE_MAP_NAME,
9555 bgp->vpn_policy[afi].rmap_name[dir]);
9556 bgp->vpn_policy[afi].rmap_name[dir] =
9557 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9558 bgp->vpn_policy[afi].rmap[dir] =
9559 route_map_lookup_warn_noexist(vty, rmap_str);
9560 if (!bgp->vpn_policy[afi].rmap[dir])
9561 return CMD_SUCCESS;
9562
9563 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9564 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9565
9566 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9567
9568 return CMD_SUCCESS;
9569 }
9570
9571 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9572 "no import vrf route-map [RMAP$rmap_str]",
9573 NO_STR
9574 "Import routes from another VRF\n"
9575 "Vrf routes being filtered\n"
9576 "Specify route map\n"
9577 "name of route-map\n")
9578 {
9579 VTY_DECLVAR_CONTEXT(bgp, bgp);
9580 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9581 afi_t afi;
9582
9583 afi = vpn_policy_getafi(vty, bgp, true);
9584 if (afi == AFI_MAX)
9585 return CMD_WARNING_CONFIG_FAILED;
9586
9587 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9588
9589 if (bgp->vpn_policy[afi].rmap_name[dir])
9590 XFREE(MTYPE_ROUTE_MAP_NAME,
9591 bgp->vpn_policy[afi].rmap_name[dir]);
9592 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9593 bgp->vpn_policy[afi].rmap[dir] = NULL;
9594
9595 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9596 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9597 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9598
9599 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9600
9601 return CMD_SUCCESS;
9602 }
9603
9604 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9605 "[no] import vrf VIEWVRFNAME$import_name",
9606 NO_STR
9607 "Import routes from another VRF\n"
9608 "VRF to import from\n"
9609 "The name of the VRF\n")
9610 {
9611 VTY_DECLVAR_CONTEXT(bgp, bgp);
9612 struct listnode *node;
9613 struct bgp *vrf_bgp, *bgp_default;
9614 int32_t ret = 0;
9615 as_t as = bgp->as;
9616 bool remove = false;
9617 int32_t idx = 0;
9618 char *vname;
9619 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9620 safi_t safi;
9621 afi_t afi;
9622
9623 if (import_name == NULL) {
9624 vty_out(vty, "%% Missing import name\n");
9625 return CMD_WARNING;
9626 }
9627
9628 if (strcmp(import_name, "route-map") == 0) {
9629 vty_out(vty, "%% Must include route-map name\n");
9630 return CMD_WARNING;
9631 }
9632
9633 if (argv_find(argv, argc, "no", &idx))
9634 remove = true;
9635
9636 afi = vpn_policy_getafi(vty, bgp, true);
9637 if (afi == AFI_MAX)
9638 return CMD_WARNING_CONFIG_FAILED;
9639
9640 safi = bgp_node_safi(vty);
9641
9642 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9643 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9644 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9645 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9646 remove ? "unimport" : "import", import_name);
9647 return CMD_WARNING;
9648 }
9649
9650 bgp_default = bgp_get_default();
9651 if (!bgp_default) {
9652 /* Auto-create assuming the same AS */
9653 ret = bgp_get_vty(&bgp_default, &as, NULL,
9654 BGP_INSTANCE_TYPE_DEFAULT);
9655
9656 if (ret) {
9657 vty_out(vty,
9658 "VRF default is not configured as a bgp instance\n");
9659 return CMD_WARNING;
9660 }
9661 }
9662
9663 vrf_bgp = bgp_lookup_by_name(import_name);
9664 if (!vrf_bgp) {
9665 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9666 vrf_bgp = bgp_default;
9667 else
9668 /* Auto-create assuming the same AS */
9669 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9670
9671 if (ret) {
9672 vty_out(vty,
9673 "VRF %s is not configured as a bgp instance\n",
9674 import_name);
9675 return CMD_WARNING;
9676 }
9677 }
9678
9679 if (remove) {
9680 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9681 } else {
9682 /* Already importing from "import_vrf"? */
9683 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9684 vname)) {
9685 if (strcmp(vname, import_name) == 0)
9686 return CMD_WARNING;
9687 }
9688
9689 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9690 }
9691
9692 return CMD_SUCCESS;
9693 }
9694
9695 /* This command is valid only in a bgp vrf instance or the default instance */
9696 DEFPY (bgp_imexport_vpn,
9697 bgp_imexport_vpn_cmd,
9698 "[no] <import|export>$direction_str vpn",
9699 NO_STR
9700 "Import routes to this address-family\n"
9701 "Export routes from this address-family\n"
9702 "to/from default instance VPN RIB\n")
9703 {
9704 VTY_DECLVAR_CONTEXT(bgp, bgp);
9705 int previous_state;
9706 afi_t afi;
9707 safi_t safi;
9708 int idx = 0;
9709 bool yes = true;
9710 int flag;
9711 enum vpn_policy_direction dir;
9712
9713 if (argv_find(argv, argc, "no", &idx))
9714 yes = false;
9715
9716 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9717 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9718
9719 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9720 return CMD_WARNING_CONFIG_FAILED;
9721 }
9722
9723 afi = bgp_node_afi(vty);
9724 safi = bgp_node_safi(vty);
9725 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9726 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9727 return CMD_WARNING_CONFIG_FAILED;
9728 }
9729
9730 if (!strcmp(direction_str, "import")) {
9731 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9732 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9733 } else if (!strcmp(direction_str, "export")) {
9734 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9735 dir = BGP_VPN_POLICY_DIR_TOVPN;
9736 } else {
9737 vty_out(vty, "%% unknown direction %s\n", direction_str);
9738 return CMD_WARNING_CONFIG_FAILED;
9739 }
9740
9741 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9742
9743 if (yes) {
9744 SET_FLAG(bgp->af_flags[afi][safi], flag);
9745 if (!previous_state) {
9746 /* trigger export current vrf */
9747 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9748 }
9749 } else {
9750 if (previous_state) {
9751 /* trigger un-export current vrf */
9752 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9753 }
9754 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9755 }
9756
9757 hook_call(bgp_snmp_init_stats, bgp);
9758
9759 return CMD_SUCCESS;
9760 }
9761
9762 DEFPY (af_routetarget_import,
9763 af_routetarget_import_cmd,
9764 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9765 NO_STR
9766 "Specify route target list\n"
9767 "Specify route target list\n"
9768 "Specify route target list\n"
9769 "Specify route target list\n"
9770 "Flow-spec redirect type route target\n"
9771 "Import routes to this address-family\n"
9772 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9773 {
9774 VTY_DECLVAR_CONTEXT(bgp, bgp);
9775 int ret;
9776 struct ecommunity *ecom = NULL;
9777 afi_t afi;
9778 int idx = 0, idx_unused = 0;
9779 bool yes = true;
9780 bool rt6 = false;
9781
9782 if (argv_find(argv, argc, "no", &idx))
9783 yes = false;
9784
9785 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9786 argv_find(argv, argc, "route-target6", &idx_unused))
9787 rt6 = true;
9788
9789 afi = vpn_policy_getafi(vty, bgp, false);
9790 if (afi == AFI_MAX)
9791 return CMD_WARNING_CONFIG_FAILED;
9792
9793 if (rt6 && afi != AFI_IP6)
9794 return CMD_WARNING_CONFIG_FAILED;
9795
9796 if (yes) {
9797 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9798 vty_out(vty, "%% Missing RTLIST\n");
9799 return CMD_WARNING_CONFIG_FAILED;
9800 }
9801 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9802 if (ret != CMD_SUCCESS)
9803 return ret;
9804 }
9805
9806 if (yes) {
9807 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9808 ecommunity_free(&bgp->vpn_policy[afi]
9809 .import_redirect_rtlist);
9810 bgp->vpn_policy[afi].import_redirect_rtlist =
9811 ecommunity_dup(ecom);
9812 } else {
9813 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9814 ecommunity_free(&bgp->vpn_policy[afi]
9815 .import_redirect_rtlist);
9816 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9817 }
9818
9819 if (ecom)
9820 ecommunity_free(&ecom);
9821
9822 return CMD_SUCCESS;
9823 }
9824
9825 DEFUN_NOSH (address_family_ipv4_safi,
9826 address_family_ipv4_safi_cmd,
9827 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9828 "Enter Address Family command mode\n"
9829 BGP_AF_STR
9830 BGP_SAFI_WITH_LABEL_HELP_STR)
9831 {
9832
9833 if (argc == 3) {
9834 VTY_DECLVAR_CONTEXT(bgp, bgp);
9835 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9836 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9837 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9838 && safi != SAFI_EVPN) {
9839 vty_out(vty,
9840 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9841 return CMD_WARNING_CONFIG_FAILED;
9842 }
9843 vty->node = bgp_node_type(AFI_IP, safi);
9844 } else
9845 vty->node = BGP_IPV4_NODE;
9846
9847 return CMD_SUCCESS;
9848 }
9849
9850 DEFUN_NOSH (address_family_ipv6_safi,
9851 address_family_ipv6_safi_cmd,
9852 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9853 "Enter Address Family command mode\n"
9854 BGP_AF_STR
9855 BGP_SAFI_WITH_LABEL_HELP_STR)
9856 {
9857 if (argc == 3) {
9858 VTY_DECLVAR_CONTEXT(bgp, bgp);
9859 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9860 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9861 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9862 && safi != SAFI_EVPN) {
9863 vty_out(vty,
9864 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9865 return CMD_WARNING_CONFIG_FAILED;
9866 }
9867 vty->node = bgp_node_type(AFI_IP6, safi);
9868 } else
9869 vty->node = BGP_IPV6_NODE;
9870
9871 return CMD_SUCCESS;
9872 }
9873
9874 #ifdef KEEP_OLD_VPN_COMMANDS
9875 DEFUN_NOSH (address_family_vpnv4,
9876 address_family_vpnv4_cmd,
9877 "address-family vpnv4 [unicast]",
9878 "Enter Address Family command mode\n"
9879 BGP_AF_STR
9880 BGP_AF_MODIFIER_STR)
9881 {
9882 vty->node = BGP_VPNV4_NODE;
9883 return CMD_SUCCESS;
9884 }
9885
9886 DEFUN_NOSH (address_family_vpnv6,
9887 address_family_vpnv6_cmd,
9888 "address-family vpnv6 [unicast]",
9889 "Enter Address Family command mode\n"
9890 BGP_AF_STR
9891 BGP_AF_MODIFIER_STR)
9892 {
9893 vty->node = BGP_VPNV6_NODE;
9894 return CMD_SUCCESS;
9895 }
9896 #endif /* KEEP_OLD_VPN_COMMANDS */
9897
9898 DEFUN_NOSH (address_family_evpn,
9899 address_family_evpn_cmd,
9900 "address-family l2vpn evpn",
9901 "Enter Address Family command mode\n"
9902 BGP_AF_STR
9903 BGP_AF_MODIFIER_STR)
9904 {
9905 VTY_DECLVAR_CONTEXT(bgp, bgp);
9906 vty->node = BGP_EVPN_NODE;
9907 return CMD_SUCCESS;
9908 }
9909
9910 DEFUN_NOSH (bgp_segment_routing_srv6,
9911 bgp_segment_routing_srv6_cmd,
9912 "segment-routing srv6",
9913 "Segment-Routing configuration\n"
9914 "Segment-Routing SRv6 configuration\n")
9915 {
9916 VTY_DECLVAR_CONTEXT(bgp, bgp);
9917 bgp->srv6_enabled = true;
9918 vty->node = BGP_SRV6_NODE;
9919 return CMD_SUCCESS;
9920 }
9921
9922 DEFUN (no_bgp_segment_routing_srv6,
9923 no_bgp_segment_routing_srv6_cmd,
9924 "no segment-routing srv6",
9925 NO_STR
9926 "Segment-Routing configuration\n"
9927 "Segment-Routing SRv6 configuration\n")
9928 {
9929 VTY_DECLVAR_CONTEXT(bgp, bgp);
9930
9931 if (strlen(bgp->srv6_locator_name) > 0)
9932 if (bgp_srv6_locator_unset(bgp) < 0)
9933 return CMD_WARNING_CONFIG_FAILED;
9934
9935 bgp->srv6_enabled = false;
9936 return CMD_SUCCESS;
9937 }
9938
9939 DEFPY (bgp_srv6_locator,
9940 bgp_srv6_locator_cmd,
9941 "locator NAME$name",
9942 "Specify SRv6 locator\n"
9943 "Specify SRv6 locator\n")
9944 {
9945 VTY_DECLVAR_CONTEXT(bgp, bgp);
9946 int ret;
9947
9948 if (strlen(bgp->srv6_locator_name) > 0
9949 && strcmp(name, bgp->srv6_locator_name) != 0) {
9950 vty_out(vty, "srv6 locator is already configured\n");
9951 return CMD_WARNING_CONFIG_FAILED;
9952 }
9953
9954 snprintf(bgp->srv6_locator_name,
9955 sizeof(bgp->srv6_locator_name), "%s", name);
9956
9957 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9958 if (ret < 0)
9959 return CMD_WARNING_CONFIG_FAILED;
9960
9961 return CMD_SUCCESS;
9962 }
9963
9964 DEFPY (no_bgp_srv6_locator,
9965 no_bgp_srv6_locator_cmd,
9966 "no locator NAME$name",
9967 NO_STR
9968 "Specify SRv6 locator\n"
9969 "Specify SRv6 locator\n")
9970 {
9971 VTY_DECLVAR_CONTEXT(bgp, bgp);
9972
9973 /* when locator isn't configured, do nothing */
9974 if (strlen(bgp->srv6_locator_name) < 1)
9975 return CMD_SUCCESS;
9976
9977 /* name validation */
9978 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9979 vty_out(vty, "%% No srv6 locator is configured\n");
9980 return CMD_WARNING_CONFIG_FAILED;
9981 }
9982
9983 /* unset locator */
9984 if (bgp_srv6_locator_unset(bgp) < 0)
9985 return CMD_WARNING_CONFIG_FAILED;
9986
9987 return CMD_SUCCESS;
9988 }
9989
9990 DEFPY (show_bgp_srv6,
9991 show_bgp_srv6_cmd,
9992 "show bgp segment-routing srv6",
9993 SHOW_STR
9994 BGP_STR
9995 "BGP Segment Routing\n"
9996 "BGP Segment Routing SRv6\n")
9997 {
9998 struct bgp *bgp;
9999 struct listnode *node;
10000 struct srv6_locator_chunk *chunk;
10001 struct bgp_srv6_function *func;
10002
10003 bgp = bgp_get_default();
10004 if (!bgp)
10005 return CMD_SUCCESS;
10006
10007 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10008 vty_out(vty, "locator_chunks:\n");
10009 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
10010 vty_out(vty, "- %pFX\n", &chunk->prefix);
10011 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
10012 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
10013 vty_out(vty, " func-length: %d\n",
10014 chunk->function_bits_length);
10015 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
10016 }
10017
10018 vty_out(vty, "functions:\n");
10019 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
10020 vty_out(vty, "- sid: %pI6\n", &func->sid);
10021 vty_out(vty, " locator: %s\n", func->locator_name);
10022 }
10023
10024 vty_out(vty, "bgps:\n");
10025 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10026 vty_out(vty, "- name: %s\n",
10027 bgp->name ? bgp->name : "default");
10028
10029 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
10030 bgp->vpn_policy[AFI_IP].tovpn_sid);
10031 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
10032 bgp->vpn_policy[AFI_IP6].tovpn_sid);
10033 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
10034 }
10035
10036 return CMD_SUCCESS;
10037 }
10038
10039 DEFUN_NOSH (exit_address_family,
10040 exit_address_family_cmd,
10041 "exit-address-family",
10042 "Exit from Address Family configuration mode\n")
10043 {
10044 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10045 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10046 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10047 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
10048 || vty->node == BGP_EVPN_NODE
10049 || vty->node == BGP_FLOWSPECV4_NODE
10050 || vty->node == BGP_FLOWSPECV6_NODE)
10051 vty->node = BGP_NODE;
10052 return CMD_SUCCESS;
10053 }
10054
10055 /* Recalculate bestpath and re-advertise a prefix */
10056 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10057 const char *ip_str, afi_t afi, safi_t safi,
10058 struct prefix_rd *prd)
10059 {
10060 int ret;
10061 struct prefix match;
10062 struct bgp_dest *dest;
10063 struct bgp_dest *rm;
10064 struct bgp *bgp;
10065 struct bgp_table *table;
10066 struct bgp_table *rib;
10067
10068 /* BGP structure lookup. */
10069 if (view_name) {
10070 bgp = bgp_lookup_by_name(view_name);
10071 if (bgp == NULL) {
10072 vty_out(vty, "%% Can't find BGP instance %s\n",
10073 view_name);
10074 return CMD_WARNING;
10075 }
10076 } else {
10077 bgp = bgp_get_default();
10078 if (bgp == NULL) {
10079 vty_out(vty, "%% No BGP process is configured\n");
10080 return CMD_WARNING;
10081 }
10082 }
10083
10084 /* Check IP address argument. */
10085 ret = str2prefix(ip_str, &match);
10086 if (!ret) {
10087 vty_out(vty, "%% address is malformed\n");
10088 return CMD_WARNING;
10089 }
10090
10091 match.family = afi2family(afi);
10092 rib = bgp->rib[afi][safi];
10093
10094 if (safi == SAFI_MPLS_VPN) {
10095 for (dest = bgp_table_top(rib); dest;
10096 dest = bgp_route_next(dest)) {
10097 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10098
10099 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10100 continue;
10101
10102 table = bgp_dest_get_bgp_table_info(dest);
10103 if (table == NULL)
10104 continue;
10105
10106 rm = bgp_node_match(table, &match);
10107 if (rm != NULL) {
10108 const struct prefix *rm_p =
10109 bgp_dest_get_prefix(rm);
10110
10111 if (rm_p->prefixlen == match.prefixlen) {
10112 SET_FLAG(rm->flags,
10113 BGP_NODE_USER_CLEAR);
10114 bgp_process(bgp, rm, afi, safi);
10115 }
10116 bgp_dest_unlock_node(rm);
10117 }
10118 }
10119 } else {
10120 dest = bgp_node_match(rib, &match);
10121 if (dest != NULL) {
10122 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10123
10124 if (dest_p->prefixlen == match.prefixlen) {
10125 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10126 bgp_process(bgp, dest, afi, safi);
10127 }
10128 bgp_dest_unlock_node(dest);
10129 }
10130 }
10131
10132 return CMD_SUCCESS;
10133 }
10134
10135 /* one clear bgp command to rule them all */
10136 DEFUN (clear_ip_bgp_all,
10137 clear_ip_bgp_all_cmd,
10138 "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>]",
10139 CLEAR_STR
10140 IP_STR
10141 BGP_STR
10142 BGP_INSTANCE_HELP_STR
10143 BGP_AFI_HELP_STR
10144 BGP_AF_STR
10145 BGP_SAFI_WITH_LABEL_HELP_STR
10146 BGP_AF_MODIFIER_STR
10147 "Clear all peers\n"
10148 "BGP IPv4 neighbor to clear\n"
10149 "BGP IPv6 neighbor to clear\n"
10150 "BGP neighbor on interface to clear\n"
10151 "Clear peers with the AS number\n"
10152 "Clear all external peers\n"
10153 "Clear all members of peer-group\n"
10154 "BGP peer-group name\n"
10155 BGP_SOFT_STR
10156 BGP_SOFT_IN_STR
10157 BGP_SOFT_OUT_STR
10158 BGP_SOFT_IN_STR
10159 "Push out prefix-list ORF and do inbound soft reconfig\n"
10160 BGP_SOFT_OUT_STR
10161 "Reset message statistics\n")
10162 {
10163 char *vrf = NULL;
10164
10165 afi_t afi = AFI_UNSPEC;
10166 safi_t safi = SAFI_UNSPEC;
10167 enum clear_sort clr_sort = clear_peer;
10168 enum bgp_clear_type clr_type;
10169 char *clr_arg = NULL;
10170
10171 int idx = 0;
10172
10173 /* clear [ip] bgp */
10174 if (argv_find(argv, argc, "ip", &idx))
10175 afi = AFI_IP;
10176
10177 /* [<vrf> VIEWVRFNAME] */
10178 if (argv_find(argv, argc, "vrf", &idx)) {
10179 vrf = argv[idx + 1]->arg;
10180 idx += 2;
10181 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10182 vrf = NULL;
10183 } else if (argv_find(argv, argc, "view", &idx)) {
10184 /* [<view> VIEWVRFNAME] */
10185 vrf = argv[idx + 1]->arg;
10186 idx += 2;
10187 }
10188 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10189 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10190 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10191
10192 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10193 if (argv_find(argv, argc, "*", &idx)) {
10194 clr_sort = clear_all;
10195 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10196 clr_sort = clear_peer;
10197 clr_arg = argv[idx]->arg;
10198 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10199 clr_sort = clear_peer;
10200 clr_arg = argv[idx]->arg;
10201 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10202 clr_sort = clear_group;
10203 idx++;
10204 clr_arg = argv[idx]->arg;
10205 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10206 clr_sort = clear_peer;
10207 clr_arg = argv[idx]->arg;
10208 } else if (argv_find(argv, argc, "WORD", &idx)) {
10209 clr_sort = clear_peer;
10210 clr_arg = argv[idx]->arg;
10211 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10212 clr_sort = clear_as;
10213 clr_arg = argv[idx]->arg;
10214 } else if (argv_find(argv, argc, "external", &idx)) {
10215 clr_sort = clear_external;
10216 }
10217
10218 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10219 if (argv_find(argv, argc, "soft", &idx)) {
10220 if (argv_find(argv, argc, "in", &idx)
10221 || argv_find(argv, argc, "out", &idx))
10222 clr_type = strmatch(argv[idx]->text, "in")
10223 ? BGP_CLEAR_SOFT_IN
10224 : BGP_CLEAR_SOFT_OUT;
10225 else
10226 clr_type = BGP_CLEAR_SOFT_BOTH;
10227 } else if (argv_find(argv, argc, "in", &idx)) {
10228 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10229 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10230 : BGP_CLEAR_SOFT_IN;
10231 } else if (argv_find(argv, argc, "out", &idx)) {
10232 clr_type = BGP_CLEAR_SOFT_OUT;
10233 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10234 clr_type = BGP_CLEAR_MESSAGE_STATS;
10235 } else
10236 clr_type = BGP_CLEAR_SOFT_NONE;
10237
10238 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10239 }
10240
10241 DEFUN (clear_ip_bgp_prefix,
10242 clear_ip_bgp_prefix_cmd,
10243 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10244 CLEAR_STR
10245 IP_STR
10246 BGP_STR
10247 BGP_INSTANCE_HELP_STR
10248 "Clear bestpath and re-advertise\n"
10249 "IPv4 prefix\n")
10250 {
10251 char *vrf = NULL;
10252 char *prefix = NULL;
10253
10254 int idx = 0;
10255
10256 /* [<view|vrf> VIEWVRFNAME] */
10257 if (argv_find(argv, argc, "vrf", &idx)) {
10258 vrf = argv[idx + 1]->arg;
10259 idx += 2;
10260 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10261 vrf = NULL;
10262 } else if (argv_find(argv, argc, "view", &idx)) {
10263 /* [<view> VIEWVRFNAME] */
10264 vrf = argv[idx + 1]->arg;
10265 idx += 2;
10266 }
10267
10268 prefix = argv[argc - 1]->arg;
10269
10270 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10271 }
10272
10273 DEFUN (clear_bgp_ipv6_safi_prefix,
10274 clear_bgp_ipv6_safi_prefix_cmd,
10275 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10276 CLEAR_STR
10277 IP_STR
10278 BGP_STR
10279 BGP_AF_STR
10280 BGP_SAFI_HELP_STR
10281 "Clear bestpath and re-advertise\n"
10282 "IPv6 prefix\n")
10283 {
10284 int idx_safi = 0;
10285 int idx_ipv6_prefix = 0;
10286 safi_t safi = SAFI_UNICAST;
10287 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10288 argv[idx_ipv6_prefix]->arg : NULL;
10289
10290 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10291 return bgp_clear_prefix(
10292 vty, NULL, prefix, AFI_IP6,
10293 safi, NULL);
10294 }
10295
10296 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10297 clear_bgp_instance_ipv6_safi_prefix_cmd,
10298 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10299 CLEAR_STR
10300 IP_STR
10301 BGP_STR
10302 BGP_INSTANCE_HELP_STR
10303 BGP_AF_STR
10304 BGP_SAFI_HELP_STR
10305 "Clear bestpath and re-advertise\n"
10306 "IPv6 prefix\n")
10307 {
10308 int idx_safi = 0;
10309 int idx_vrfview = 0;
10310 int idx_ipv6_prefix = 0;
10311 safi_t safi = SAFI_UNICAST;
10312 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10313 argv[idx_ipv6_prefix]->arg : NULL;
10314 char *vrfview = NULL;
10315
10316 /* [<view|vrf> VIEWVRFNAME] */
10317 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10318 vrfview = argv[idx_vrfview + 1]->arg;
10319 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10320 vrfview = NULL;
10321 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10322 /* [<view> VIEWVRFNAME] */
10323 vrfview = argv[idx_vrfview + 1]->arg;
10324 }
10325 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10326
10327 return bgp_clear_prefix(
10328 vty, vrfview, prefix,
10329 AFI_IP6, safi, NULL);
10330 }
10331
10332 DEFUN (show_bgp_views,
10333 show_bgp_views_cmd,
10334 "show [ip] bgp views",
10335 SHOW_STR
10336 IP_STR
10337 BGP_STR
10338 "Show the defined BGP views\n")
10339 {
10340 struct list *inst = bm->bgp;
10341 struct listnode *node;
10342 struct bgp *bgp;
10343
10344 vty_out(vty, "Defined BGP views:\n");
10345 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10346 /* Skip VRFs. */
10347 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10348 continue;
10349 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10350 bgp->as);
10351 }
10352
10353 return CMD_SUCCESS;
10354 }
10355
10356 static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10357 int *peers_estbd)
10358 {
10359 struct peer *peer;
10360 struct listnode *node;
10361
10362 *peers_cfgd = *peers_estbd = 0;
10363 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10364 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10365 continue;
10366 (*peers_cfgd)++;
10367 if (peer_established(peer))
10368 (*peers_estbd)++;
10369 }
10370 }
10371
10372 static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10373 const char *type)
10374 {
10375 int peers_cfg, peers_estb;
10376
10377 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10378
10379 if (json) {
10380 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10381 ? -1
10382 : (int64_t)bgp->vrf_id;
10383 json_object_string_add(json, "type", type);
10384 json_object_int_add(json, "vrfId", vrf_id_ui);
10385 json_object_string_addf(json, "routerId", "%pI4",
10386 &bgp->router_id);
10387 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10388 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10389 json_object_int_add(json, "l3vni", bgp->l3vni);
10390 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10391 json_object_string_add(
10392 json, "interface",
10393 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10394 }
10395 }
10396
10397 static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10398 json_object *json, const char *name,
10399 const char *type, bool use_vrf)
10400 {
10401 int peers_cfg, peers_estb;
10402
10403 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10404
10405 if (use_vrf) {
10406 if (json) {
10407 print_bgp_vrfs(bgp, vty, json, type);
10408 } else {
10409 vty_out(vty, "BGP instance %s VRF id %d\n",
10410 bgp->name_pretty,
10411 bgp->vrf_id == VRF_UNKNOWN ? -1
10412 : (int)bgp->vrf_id);
10413 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10414 vty_out(vty,
10415 "Num Configured Peers %d, Established %d\n",
10416 peers_cfg, peers_estb);
10417 if (bgp->l3vni) {
10418 vty_out(vty,
10419 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10420 bgp->l3vni,
10421 ifindex2ifname(bgp->l3vni_svi_ifindex,
10422 bgp->vrf_id),
10423 &bgp->rmac);
10424 }
10425 }
10426 } else {
10427 if (json) {
10428 print_bgp_vrfs(bgp, vty, json, type);
10429 } else {
10430 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10431 type,
10432 bgp->vrf_id == VRF_UNKNOWN ? -1
10433 : (int)bgp->vrf_id,
10434 &bgp->router_id, peers_cfg, peers_estb, name);
10435 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10436 bgp->l3vni, &bgp->rmac,
10437 ifindex2ifname(bgp->l3vni_svi_ifindex,
10438 bgp->vrf_id));
10439 }
10440 }
10441
10442 return CMD_SUCCESS;
10443 }
10444
10445 DEFPY (show_bgp_vrfs,
10446 show_bgp_vrfs_cmd,
10447 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
10448 SHOW_STR
10449 IP_STR
10450 BGP_STR
10451 "Show BGP VRFs\n"
10452 "Specific VRF name\n"
10453 JSON_STR)
10454 {
10455 struct list *inst = bm->bgp;
10456 struct listnode *node;
10457 struct bgp *bgp;
10458 bool uj = use_json(argc, argv);
10459 json_object *json = NULL;
10460 json_object *json_vrfs = NULL;
10461 json_object *json_vrf = NULL;
10462 int count = 0;
10463 const char *name = vrf_name;
10464 const char *type;
10465
10466 if (uj)
10467 json = json_object_new_object();
10468
10469 if (name) {
10470 if (strmatch(name, VRF_DEFAULT_NAME)) {
10471 bgp = bgp_get_default();
10472 type = "DFLT";
10473 } else {
10474 bgp = bgp_lookup_by_name(name);
10475 type = "VRF";
10476 }
10477 if (!bgp) {
10478 if (uj)
10479 vty_json(vty, json);
10480 else
10481 vty_out(vty,
10482 "%% Specified BGP instance not found\n");
10483
10484 return CMD_WARNING;
10485 }
10486 }
10487
10488 if (vrf_name) {
10489 if (uj)
10490 json_vrf = json_object_new_object();
10491
10492 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10493 true);
10494
10495 if (uj) {
10496 json_object_object_add(json, name, json_vrf);
10497 vty_json(vty, json);
10498 }
10499
10500 return CMD_SUCCESS;
10501 }
10502
10503 if (uj)
10504 json_vrfs = json_object_new_object();
10505
10506 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10507 const char *name;
10508
10509 /* Skip Views. */
10510 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10511 continue;
10512
10513 count++;
10514 if (!uj && count == 1) {
10515 vty_out(vty,
10516 "%4s %-5s %-16s %9s %10s %-37s\n",
10517 "Type", "Id", "routerId", "#PeersCfg",
10518 "#PeersEstb", "Name");
10519 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10520 "L3-VNI", "RouterMAC", "Interface");
10521 }
10522 if (uj)
10523 json_vrf = json_object_new_object();
10524
10525 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10526 name = VRF_DEFAULT_NAME;
10527 type = "DFLT";
10528 } else {
10529 name = bgp->name;
10530 type = "VRF";
10531 }
10532
10533 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10534 false);
10535
10536 if (uj)
10537 json_object_object_add(json_vrfs, name, json_vrf);
10538 }
10539
10540 if (uj) {
10541 json_object_object_add(json, "vrfs", json_vrfs);
10542 json_object_int_add(json, "totalVrfs", count);
10543 vty_json(vty, json);
10544 } else {
10545 if (count)
10546 vty_out(vty,
10547 "\nTotal number of VRFs (including default): %d\n",
10548 count);
10549 }
10550
10551 return CMD_SUCCESS;
10552 }
10553
10554 DEFUN (show_bgp_mac_hash,
10555 show_bgp_mac_hash_cmd,
10556 "show bgp mac hash",
10557 SHOW_STR
10558 BGP_STR
10559 "Mac Address\n"
10560 "Mac Address database\n")
10561 {
10562 bgp_mac_dump_table(vty);
10563
10564 return CMD_SUCCESS;
10565 }
10566
10567 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10568 {
10569 struct vty *vty = (struct vty *)args;
10570 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10571
10572 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10573 }
10574
10575 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10576 {
10577 vty_out(vty, "self nexthop database:\n");
10578 bgp_nexthop_show_address_hash(vty, bgp);
10579
10580 vty_out(vty, "Tunnel-ip database:\n");
10581 hash_iterate(bgp->tip_hash,
10582 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10583 vty);
10584 }
10585
10586 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10587 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10588 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10589 "martian next-hops\n"
10590 "martian next-hop database\n")
10591 {
10592 struct bgp *bgp = NULL;
10593 int idx = 0;
10594 char *name = NULL;
10595
10596 /* [<vrf> VIEWVRFNAME] */
10597 if (argv_find(argv, argc, "vrf", &idx)) {
10598 name = argv[idx + 1]->arg;
10599 if (name && strmatch(name, VRF_DEFAULT_NAME))
10600 name = NULL;
10601 } else if (argv_find(argv, argc, "view", &idx))
10602 /* [<view> VIEWVRFNAME] */
10603 name = argv[idx + 1]->arg;
10604 if (name)
10605 bgp = bgp_lookup_by_name(name);
10606 else
10607 bgp = bgp_get_default();
10608
10609 if (!bgp) {
10610 vty_out(vty, "%% No BGP process is configured\n");
10611 return CMD_WARNING;
10612 }
10613 bgp_show_martian_nexthops(vty, bgp);
10614
10615 return CMD_SUCCESS;
10616 }
10617
10618 DEFUN (show_bgp_memory,
10619 show_bgp_memory_cmd,
10620 "show [ip] bgp memory",
10621 SHOW_STR
10622 IP_STR
10623 BGP_STR
10624 "Global BGP memory statistics\n")
10625 {
10626 char memstrbuf[MTYPE_MEMSTR_LEN];
10627 unsigned long count;
10628
10629 /* RIB related usage stats */
10630 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10631 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10632 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10633 count * sizeof(struct bgp_dest)));
10634
10635 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10636 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10637 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10638 count * sizeof(struct bgp_path_info)));
10639 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10640 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10641 count,
10642 mtype_memstr(
10643 memstrbuf, sizeof(memstrbuf),
10644 count * sizeof(struct bgp_path_info_extra)));
10645
10646 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10647 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10648 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10649 count * sizeof(struct bgp_static)));
10650
10651 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10652 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10653 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10654 count * sizeof(struct bpacket)));
10655
10656 /* Adj-In/Out */
10657 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10658 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10659 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10660 count * sizeof(struct bgp_adj_in)));
10661 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10662 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10663 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10664 count * sizeof(struct bgp_adj_out)));
10665
10666 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10667 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10668 count,
10669 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10670 count * sizeof(struct bgp_nexthop_cache)));
10671
10672 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10673 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10674 count,
10675 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10676 count * sizeof(struct bgp_damp_info)));
10677
10678 /* Attributes */
10679 count = attr_count();
10680 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10681 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10682 count * sizeof(struct attr)));
10683
10684 if ((count = attr_unknown_count()))
10685 vty_out(vty, "%ld unknown attributes\n", count);
10686
10687 /* AS_PATH attributes */
10688 count = aspath_count();
10689 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10690 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10691 count * sizeof(struct aspath)));
10692
10693 count = mtype_stats_alloc(MTYPE_AS_SEG);
10694 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10695 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10696 count * sizeof(struct assegment)));
10697
10698 /* Other attributes */
10699 if ((count = community_count()))
10700 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10701 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10702 count * sizeof(struct community)));
10703 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10704 vty_out(vty,
10705 "%ld BGP ext-community entries, using %s of memory\n",
10706 count,
10707 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10708 count * sizeof(struct ecommunity)));
10709 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10710 vty_out(vty,
10711 "%ld BGP large-community entries, using %s of memory\n",
10712 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10713 count * sizeof(struct lcommunity)));
10714
10715 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10716 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10717 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10718 count * sizeof(struct cluster_list)));
10719
10720 /* Peer related usage */
10721 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10722 vty_out(vty, "%ld peers, using %s of memory\n", count,
10723 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10724 count * sizeof(struct peer)));
10725
10726 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10727 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10728 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10729 count * sizeof(struct peer_group)));
10730
10731 /* Other */
10732 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10733 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10734 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10735 count * sizeof(regex_t)));
10736 return CMD_SUCCESS;
10737 }
10738
10739 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10740 {
10741 json_object *bestpath = json_object_new_object();
10742
10743 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10744 json_object_string_add(bestpath, "asPath", "ignore");
10745
10746 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10747 json_object_string_add(bestpath, "asPath", "confed");
10748
10749 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10750 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10751 json_object_string_add(bestpath, "multiPathRelax",
10752 "as-set");
10753 else
10754 json_object_string_add(bestpath, "multiPathRelax",
10755 "true");
10756 } else
10757 json_object_string_add(bestpath, "multiPathRelax", "false");
10758
10759 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10760 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10761
10762 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10763 json_object_string_add(bestpath, "compareRouterId", "true");
10764 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10765 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10766 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10767 json_object_string_add(bestpath, "med", "confed");
10768 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10769 json_object_string_add(bestpath, "med",
10770 "missing-as-worst");
10771 else
10772 json_object_string_add(bestpath, "med", "true");
10773 }
10774
10775 json_object_object_add(json, "bestPath", bestpath);
10776 }
10777
10778 /* Print the error code/subcode for why the peer is down */
10779 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10780 json_object *json_peer, bool use_json)
10781 {
10782 const char *code_str;
10783 const char *subcode_str;
10784
10785 if (use_json) {
10786 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10787 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10788 char errorcodesubcode_hexstr[5];
10789 char errorcodesubcode_str[256];
10790
10791 code_str = bgp_notify_code_str(peer->notify.code);
10792 subcode_str = bgp_notify_subcode_str(
10793 peer->notify.code,
10794 peer->notify.subcode);
10795
10796 snprintf(errorcodesubcode_hexstr,
10797 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10798 peer->notify.code, peer->notify.subcode);
10799 json_object_string_add(json_peer,
10800 "lastErrorCodeSubcode",
10801 errorcodesubcode_hexstr);
10802 snprintf(errorcodesubcode_str, 255, "%s%s",
10803 code_str, subcode_str);
10804 json_object_string_add(json_peer,
10805 "lastNotificationReason",
10806 errorcodesubcode_str);
10807 json_object_boolean_add(json_peer,
10808 "lastNotificationHardReset",
10809 peer->notify.hard_reset);
10810 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10811 && peer->notify.code == BGP_NOTIFY_CEASE
10812 && (peer->notify.subcode
10813 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10814 || peer->notify.subcode
10815 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10816 && peer->notify.length) {
10817 char msgbuf[1024];
10818 const char *msg_str;
10819
10820 msg_str = bgp_notify_admin_message(
10821 msgbuf, sizeof(msgbuf),
10822 (uint8_t *)peer->notify.data,
10823 peer->notify.length);
10824 if (msg_str)
10825 json_object_string_add(
10826 json_peer,
10827 "lastShutdownDescription",
10828 msg_str);
10829 }
10830
10831 }
10832 json_object_string_add(json_peer, "lastResetDueTo",
10833 peer_down_str[(int)peer->last_reset]);
10834 json_object_int_add(json_peer, "lastResetCode",
10835 peer->last_reset);
10836 } else {
10837 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10838 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10839 code_str = bgp_notify_code_str(peer->notify.code);
10840 subcode_str =
10841 bgp_notify_subcode_str(peer->notify.code,
10842 peer->notify.subcode);
10843 vty_out(vty, " Notification %s (%s%s%s)\n",
10844 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10845 ? "sent"
10846 : "received",
10847 code_str, subcode_str,
10848 peer->notify.hard_reset
10849 ? bgp_notify_subcode_str(
10850 BGP_NOTIFY_CEASE,
10851 BGP_NOTIFY_CEASE_HARD_RESET)
10852 : "");
10853 } else {
10854 vty_out(vty, " %s\n",
10855 peer_down_str[(int)peer->last_reset]);
10856 }
10857 }
10858 }
10859
10860 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10861 safi_t safi)
10862 {
10863 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10864 }
10865
10866 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10867 struct peer *peer, json_object *json_peer,
10868 int max_neighbor_width, bool use_json)
10869 {
10870 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10871 int len;
10872
10873 if (use_json) {
10874 if (peer_dynamic_neighbor(peer))
10875 json_object_boolean_true_add(json_peer,
10876 "dynamicPeer");
10877 if (peer->hostname)
10878 json_object_string_add(json_peer, "hostname",
10879 peer->hostname);
10880
10881 if (peer->domainname)
10882 json_object_string_add(json_peer, "domainname",
10883 peer->domainname);
10884 json_object_int_add(json_peer, "connectionsEstablished",
10885 peer->established);
10886 json_object_int_add(json_peer, "connectionsDropped",
10887 peer->dropped);
10888 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10889 use_json, json_peer);
10890 if (peer_established(peer))
10891 json_object_string_add(json_peer, "lastResetDueTo",
10892 "AFI/SAFI Not Negotiated");
10893 else
10894 bgp_show_peer_reset(NULL, peer, json_peer, true);
10895 } else {
10896 dn_flag[1] = '\0';
10897 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10898 if (peer->hostname
10899 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10900 len = vty_out(vty, "%s%s(%s)", dn_flag,
10901 peer->hostname, peer->host);
10902 else
10903 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10904
10905 /* pad the neighbor column with spaces */
10906 if (len < max_neighbor_width)
10907 vty_out(vty, "%*s", max_neighbor_width - len,
10908 " ");
10909 vty_out(vty, "%7d %7d %9s", peer->established,
10910 peer->dropped,
10911 peer_uptime(peer->uptime, timebuf,
10912 BGP_UPTIME_LEN, 0, NULL));
10913 if (peer_established(peer))
10914 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10915 else
10916 bgp_show_peer_reset(vty, peer, NULL,
10917 false);
10918 }
10919 }
10920
10921 /* Strip peer's description to the given size. */
10922 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10923 {
10924 static char stripped[BUFSIZ];
10925 uint32_t i = 0;
10926 uint32_t last_space = 0;
10927
10928 while (i < size) {
10929 if (*(desc + i) == 0) {
10930 stripped[i] = '\0';
10931 return stripped;
10932 }
10933 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10934 last_space = i;
10935 stripped[i] = *(desc + i);
10936 i++;
10937 }
10938
10939 if (last_space > size)
10940 stripped[size + 1] = '\0';
10941 else
10942 stripped[last_space] = '\0';
10943
10944 return stripped;
10945 }
10946
10947 /* Determine whether var peer should be filtered out of the summary. */
10948 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10949 struct peer *fpeer, int as_type,
10950 as_t as)
10951 {
10952
10953 /* filter neighbor XXXX */
10954 if (fpeer && fpeer != peer)
10955 return true;
10956
10957 /* filter remote-as (internal|external) */
10958 if (as_type != AS_UNSPECIFIED) {
10959 if (peer->as_type == AS_SPECIFIED) {
10960 if (as_type == AS_INTERNAL) {
10961 if (peer->as != peer->local_as)
10962 return true;
10963 } else if (peer->as == peer->local_as)
10964 return true;
10965 } else if (as_type != peer->as_type)
10966 return true;
10967 } else if (as && as != peer->as) /* filter remote-as XXX */
10968 return true;
10969
10970 return false;
10971 }
10972
10973 /* Show BGP peer's summary information.
10974 *
10975 * Peer's description is stripped according to if `wide` option is given
10976 * or not.
10977 *
10978 * When adding new columns to `show bgp summary` output, please make
10979 * sure `Desc` is the lastest column to show because it can contain
10980 * whitespaces and the whole output will be tricky.
10981 */
10982 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10983 struct peer *fpeer, int as_type, as_t as,
10984 uint16_t show_flags)
10985 {
10986 struct peer *peer;
10987 struct listnode *node, *nnode;
10988 unsigned int count = 0, dn_count = 0;
10989 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10990 char neighbor_buf[VTY_BUFSIZ];
10991 int neighbor_col_default_width = 16;
10992 int len, failed_count = 0;
10993 unsigned int filtered_count = 0;
10994 int max_neighbor_width = 0;
10995 int pfx_rcd_safi;
10996 json_object *json = NULL;
10997 json_object *json_peer = NULL;
10998 json_object *json_peers = NULL;
10999 struct peer_af *paf;
11000 struct bgp_filter *filter;
11001 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11002 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11003 bool show_established =
11004 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11005 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11006 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11007
11008 /* labeled-unicast routes are installed in the unicast table so in order
11009 * to
11010 * display the correct PfxRcd value we must look at SAFI_UNICAST
11011 */
11012
11013 if (safi == SAFI_LABELED_UNICAST)
11014 pfx_rcd_safi = SAFI_UNICAST;
11015 else
11016 pfx_rcd_safi = safi;
11017
11018 if (use_json) {
11019 json = json_object_new_object();
11020 json_peers = json_object_new_object();
11021 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11022 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11023 as_type, as)) {
11024 filtered_count++;
11025 count++;
11026 continue;
11027 }
11028
11029 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11030 continue;
11031
11032 if (peer->afc[afi][safi]) {
11033 /* See if we have at least a single failed peer */
11034 if (bgp_has_peer_failed(peer, afi, safi))
11035 failed_count++;
11036 count++;
11037 }
11038 if (peer_dynamic_neighbor(peer))
11039 dn_count++;
11040 }
11041
11042 } else {
11043 /* Loop over all neighbors that will be displayed to determine
11044 * how many
11045 * characters are needed for the Neighbor column
11046 */
11047 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11048 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11049 as_type, as)) {
11050 filtered_count++;
11051 count++;
11052 continue;
11053 }
11054
11055 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11056 continue;
11057
11058 if (peer->afc[afi][safi]) {
11059 memset(dn_flag, '\0', sizeof(dn_flag));
11060 if (peer_dynamic_neighbor(peer))
11061 dn_flag[0] = '*';
11062
11063 if (peer->hostname
11064 && CHECK_FLAG(bgp->flags,
11065 BGP_FLAG_SHOW_HOSTNAME))
11066 snprintf(neighbor_buf,
11067 sizeof(neighbor_buf),
11068 "%s%s(%s) ", dn_flag,
11069 peer->hostname, peer->host);
11070 else
11071 snprintf(neighbor_buf,
11072 sizeof(neighbor_buf), "%s%s ",
11073 dn_flag, peer->host);
11074
11075 len = strlen(neighbor_buf);
11076
11077 if (len > max_neighbor_width)
11078 max_neighbor_width = len;
11079
11080 /* See if we have at least a single failed peer */
11081 if (bgp_has_peer_failed(peer, afi, safi))
11082 failed_count++;
11083 count++;
11084 }
11085 }
11086
11087 /* Originally we displayed the Neighbor column as 16
11088 * characters wide so make that the default
11089 */
11090 if (max_neighbor_width < neighbor_col_default_width)
11091 max_neighbor_width = neighbor_col_default_width;
11092 }
11093
11094 if (show_failed && !failed_count) {
11095 if (use_json) {
11096 json_object_int_add(json, "failedPeersCount", 0);
11097 json_object_int_add(json, "dynamicPeers", dn_count);
11098 json_object_int_add(json, "totalPeers", count);
11099
11100 vty_json(vty, json);
11101 } else {
11102 vty_out(vty, "%% No failed BGP neighbors found\n");
11103 }
11104 return CMD_SUCCESS;
11105 }
11106
11107 count = 0; /* Reset the value as its used again */
11108 filtered_count = 0;
11109 dn_count = 0;
11110 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11111 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11112 continue;
11113
11114 if (!peer->afc[afi][safi])
11115 continue;
11116
11117 if (!count) {
11118 unsigned long ents;
11119 char memstrbuf[MTYPE_MEMSTR_LEN];
11120 int64_t vrf_id_ui;
11121
11122 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11123 ? -1
11124 : (int64_t)bgp->vrf_id;
11125
11126 /* Usage summary and header */
11127 if (use_json) {
11128 json_object_string_addf(json, "routerId",
11129 "%pI4",
11130 &bgp->router_id);
11131 json_object_int_add(json, "as", bgp->as);
11132 json_object_int_add(json, "vrfId", vrf_id_ui);
11133 json_object_string_add(
11134 json, "vrfName",
11135 (bgp->inst_type
11136 == BGP_INSTANCE_TYPE_DEFAULT)
11137 ? VRF_DEFAULT_NAME
11138 : bgp->name);
11139 } else {
11140 vty_out(vty,
11141 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11142 &bgp->router_id, bgp->as,
11143 bgp->vrf_id == VRF_UNKNOWN
11144 ? -1
11145 : (int)bgp->vrf_id);
11146 vty_out(vty, "\n");
11147 }
11148
11149 if (bgp_update_delay_configured(bgp)) {
11150 if (use_json) {
11151 json_object_int_add(
11152 json, "updateDelayLimit",
11153 bgp->v_update_delay);
11154
11155 if (bgp->v_update_delay
11156 != bgp->v_establish_wait)
11157 json_object_int_add(
11158 json,
11159 "updateDelayEstablishWait",
11160 bgp->v_establish_wait);
11161
11162 if (bgp_update_delay_active(bgp)) {
11163 json_object_string_add(
11164 json,
11165 "updateDelayFirstNeighbor",
11166 bgp->update_delay_begin_time);
11167 json_object_boolean_true_add(
11168 json,
11169 "updateDelayInProgress");
11170 } else {
11171 if (bgp->update_delay_over) {
11172 json_object_string_add(
11173 json,
11174 "updateDelayFirstNeighbor",
11175 bgp->update_delay_begin_time);
11176 json_object_string_add(
11177 json,
11178 "updateDelayBestpathResumed",
11179 bgp->update_delay_end_time);
11180 json_object_string_add(
11181 json,
11182 "updateDelayZebraUpdateResume",
11183 bgp->update_delay_zebra_resume_time);
11184 json_object_string_add(
11185 json,
11186 "updateDelayPeerUpdateResume",
11187 bgp->update_delay_peers_resume_time);
11188 }
11189 }
11190 } else {
11191 vty_out(vty,
11192 "Read-only mode update-delay limit: %d seconds\n",
11193 bgp->v_update_delay);
11194 if (bgp->v_update_delay
11195 != bgp->v_establish_wait)
11196 vty_out(vty,
11197 " Establish wait: %d seconds\n",
11198 bgp->v_establish_wait);
11199
11200 if (bgp_update_delay_active(bgp)) {
11201 vty_out(vty,
11202 " First neighbor established: %s\n",
11203 bgp->update_delay_begin_time);
11204 vty_out(vty,
11205 " Delay in progress\n");
11206 } else {
11207 if (bgp->update_delay_over) {
11208 vty_out(vty,
11209 " First neighbor established: %s\n",
11210 bgp->update_delay_begin_time);
11211 vty_out(vty,
11212 " Best-paths resumed: %s\n",
11213 bgp->update_delay_end_time);
11214 vty_out(vty,
11215 " zebra update resumed: %s\n",
11216 bgp->update_delay_zebra_resume_time);
11217 vty_out(vty,
11218 " peers update resumed: %s\n",
11219 bgp->update_delay_peers_resume_time);
11220 }
11221 }
11222 }
11223 }
11224
11225 if (use_json) {
11226 if (bgp_maxmed_onstartup_configured(bgp)
11227 && bgp->maxmed_active)
11228 json_object_boolean_true_add(
11229 json, "maxMedOnStartup");
11230 if (bgp->v_maxmed_admin)
11231 json_object_boolean_true_add(
11232 json, "maxMedAdministrative");
11233
11234 json_object_int_add(
11235 json, "tableVersion",
11236 bgp_table_version(bgp->rib[afi][safi]));
11237
11238 ents = bgp_table_count(bgp->rib[afi][safi]);
11239 json_object_int_add(json, "ribCount", ents);
11240 json_object_int_add(
11241 json, "ribMemory",
11242 ents * sizeof(struct bgp_dest));
11243
11244 ents = bgp->af_peer_count[afi][safi];
11245 json_object_int_add(json, "peerCount", ents);
11246 json_object_int_add(json, "peerMemory",
11247 ents * sizeof(struct peer));
11248
11249 if ((ents = listcount(bgp->group))) {
11250 json_object_int_add(
11251 json, "peerGroupCount", ents);
11252 json_object_int_add(
11253 json, "peerGroupMemory",
11254 ents * sizeof(struct
11255 peer_group));
11256 }
11257
11258 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11259 BGP_CONFIG_DAMPENING))
11260 json_object_boolean_true_add(
11261 json, "dampeningEnabled");
11262 } else {
11263 if (!show_terse) {
11264 if (bgp_maxmed_onstartup_configured(bgp)
11265 && bgp->maxmed_active)
11266 vty_out(vty,
11267 "Max-med on-startup active\n");
11268 if (bgp->v_maxmed_admin)
11269 vty_out(vty,
11270 "Max-med administrative active\n");
11271
11272 vty_out(vty,
11273 "BGP table version %" PRIu64
11274 "\n",
11275 bgp_table_version(
11276 bgp->rib[afi][safi]));
11277
11278 ents = bgp_table_count(
11279 bgp->rib[afi][safi]);
11280 vty_out(vty,
11281 "RIB entries %ld, using %s of memory\n",
11282 ents,
11283 mtype_memstr(
11284 memstrbuf,
11285 sizeof(memstrbuf),
11286 ents
11287 * sizeof(
11288 struct
11289 bgp_dest)));
11290
11291 /* Peer related usage */
11292 ents = bgp->af_peer_count[afi][safi];
11293 vty_out(vty,
11294 "Peers %ld, using %s of memory\n",
11295 ents,
11296 mtype_memstr(
11297 memstrbuf,
11298 sizeof(memstrbuf),
11299 ents
11300 * sizeof(
11301 struct
11302 peer)));
11303
11304 if ((ents = listcount(bgp->group)))
11305 vty_out(vty,
11306 "Peer groups %ld, using %s of memory\n",
11307 ents,
11308 mtype_memstr(
11309 memstrbuf,
11310 sizeof(memstrbuf),
11311 ents
11312 * sizeof(
11313 struct
11314 peer_group)));
11315
11316 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11317 BGP_CONFIG_DAMPENING))
11318 vty_out(vty,
11319 "Dampening enabled.\n");
11320 }
11321 if (show_failed) {
11322 vty_out(vty, "\n");
11323
11324 /* Subtract 8 here because 'Neighbor' is
11325 * 8 characters */
11326 vty_out(vty, "Neighbor");
11327 vty_out(vty, "%*s",
11328 max_neighbor_width - 8, " ");
11329 vty_out(vty,
11330 BGP_SHOW_SUMMARY_HEADER_FAILED);
11331 }
11332 }
11333 }
11334
11335 paf = peer_af_find(peer, afi, safi);
11336 filter = &peer->filter[afi][safi];
11337
11338 count++;
11339 /* Works for both failed & successful cases */
11340 if (peer_dynamic_neighbor(peer))
11341 dn_count++;
11342
11343 if (use_json) {
11344 json_peer = NULL;
11345 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11346 as_type, as)) {
11347 filtered_count++;
11348 continue;
11349 }
11350 if (show_failed &&
11351 bgp_has_peer_failed(peer, afi, safi)) {
11352 json_peer = json_object_new_object();
11353 bgp_show_failed_summary(vty, bgp, peer,
11354 json_peer, 0, use_json);
11355 } else if (!show_failed) {
11356 if (show_established
11357 && bgp_has_peer_failed(peer, afi, safi)) {
11358 filtered_count++;
11359 continue;
11360 }
11361
11362 json_peer = json_object_new_object();
11363 if (peer_dynamic_neighbor(peer)) {
11364 json_object_boolean_true_add(json_peer,
11365 "dynamicPeer");
11366 }
11367
11368 if (peer->hostname)
11369 json_object_string_add(json_peer, "hostname",
11370 peer->hostname);
11371
11372 if (peer->domainname)
11373 json_object_string_add(json_peer, "domainname",
11374 peer->domainname);
11375
11376 json_object_int_add(json_peer, "remoteAs", peer->as);
11377 json_object_int_add(
11378 json_peer, "localAs",
11379 peer->change_local_as
11380 ? peer->change_local_as
11381 : peer->local_as);
11382 json_object_int_add(json_peer, "version", 4);
11383 json_object_int_add(json_peer, "msgRcvd",
11384 PEER_TOTAL_RX(peer));
11385 json_object_int_add(json_peer, "msgSent",
11386 PEER_TOTAL_TX(peer));
11387
11388 atomic_size_t outq_count, inq_count;
11389 outq_count = atomic_load_explicit(
11390 &peer->obuf->count,
11391 memory_order_relaxed);
11392 inq_count = atomic_load_explicit(
11393 &peer->ibuf->count,
11394 memory_order_relaxed);
11395
11396 json_object_int_add(json_peer, "tableVersion",
11397 peer->version[afi][safi]);
11398 json_object_int_add(json_peer, "outq",
11399 outq_count);
11400 json_object_int_add(json_peer, "inq",
11401 inq_count);
11402 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11403 use_json, json_peer);
11404
11405 json_object_int_add(json_peer, "pfxRcd",
11406 peer->pcount[afi][pfx_rcd_safi]);
11407
11408 if (paf && PAF_SUBGRP(paf))
11409 json_object_int_add(
11410 json_peer, "pfxSnt",
11411 (PAF_SUBGRP(paf))->scount);
11412 else
11413 json_object_int_add(json_peer, "pfxSnt",
11414 0);
11415
11416 /* BGP FSM state */
11417 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11418 || CHECK_FLAG(peer->bgp->flags,
11419 BGP_FLAG_SHUTDOWN))
11420 json_object_string_add(json_peer,
11421 "state",
11422 "Idle (Admin)");
11423 else if (peer->afc_recv[afi][safi])
11424 json_object_string_add(
11425 json_peer, "state",
11426 lookup_msg(bgp_status_msg,
11427 peer->status, NULL));
11428 else if (CHECK_FLAG(
11429 peer->sflags,
11430 PEER_STATUS_PREFIX_OVERFLOW))
11431 json_object_string_add(json_peer,
11432 "state",
11433 "Idle (PfxCt)");
11434 else
11435 json_object_string_add(
11436 json_peer, "state",
11437 lookup_msg(bgp_status_msg,
11438 peer->status, NULL));
11439
11440 /* BGP peer state */
11441 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11442 || CHECK_FLAG(peer->bgp->flags,
11443 BGP_FLAG_SHUTDOWN))
11444 json_object_string_add(json_peer,
11445 "peerState",
11446 "Admin");
11447 else if (CHECK_FLAG(
11448 peer->sflags,
11449 PEER_STATUS_PREFIX_OVERFLOW))
11450 json_object_string_add(json_peer,
11451 "peerState",
11452 "PfxCt");
11453 else if (CHECK_FLAG(peer->flags,
11454 PEER_FLAG_PASSIVE))
11455 json_object_string_add(json_peer,
11456 "peerState",
11457 "Passive");
11458 else if (CHECK_FLAG(peer->sflags,
11459 PEER_STATUS_NSF_WAIT))
11460 json_object_string_add(json_peer,
11461 "peerState",
11462 "NSF passive");
11463 else if (CHECK_FLAG(
11464 peer->bgp->flags,
11465 BGP_FLAG_EBGP_REQUIRES_POLICY)
11466 && (!bgp_inbound_policy_exists(peer,
11467 filter)
11468 || !bgp_outbound_policy_exists(
11469 peer, filter)))
11470 json_object_string_add(json_peer,
11471 "peerState",
11472 "Policy");
11473 else
11474 json_object_string_add(
11475 json_peer, "peerState", "OK");
11476
11477 json_object_int_add(json_peer, "connectionsEstablished",
11478 peer->established);
11479 json_object_int_add(json_peer, "connectionsDropped",
11480 peer->dropped);
11481 if (peer->desc)
11482 json_object_string_add(
11483 json_peer, "desc", peer->desc);
11484 }
11485 /* Avoid creating empty peer dicts in JSON */
11486 if (json_peer == NULL)
11487 continue;
11488
11489 if (peer->conf_if)
11490 json_object_string_add(json_peer, "idType",
11491 "interface");
11492 else if (peer->su.sa.sa_family == AF_INET)
11493 json_object_string_add(json_peer, "idType",
11494 "ipv4");
11495 else if (peer->su.sa.sa_family == AF_INET6)
11496 json_object_string_add(json_peer, "idType",
11497 "ipv6");
11498 json_object_object_add(json_peers, peer->host,
11499 json_peer);
11500 } else {
11501 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11502 as_type, as)) {
11503 filtered_count++;
11504 continue;
11505 }
11506 if (show_failed &&
11507 bgp_has_peer_failed(peer, afi, safi)) {
11508 bgp_show_failed_summary(vty, bgp, peer, NULL,
11509 max_neighbor_width,
11510 use_json);
11511 } else if (!show_failed) {
11512 if (show_established
11513 && bgp_has_peer_failed(peer, afi, safi)) {
11514 filtered_count++;
11515 continue;
11516 }
11517
11518 if ((count - filtered_count) == 1) {
11519 /* display headline before the first
11520 * neighbor line */
11521 vty_out(vty, "\n");
11522
11523 /* Subtract 8 here because 'Neighbor' is
11524 * 8 characters */
11525 vty_out(vty, "Neighbor");
11526 vty_out(vty, "%*s",
11527 max_neighbor_width - 8, " ");
11528 vty_out(vty,
11529 show_wide
11530 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11531 : BGP_SHOW_SUMMARY_HEADER_ALL);
11532 }
11533
11534 memset(dn_flag, '\0', sizeof(dn_flag));
11535 if (peer_dynamic_neighbor(peer)) {
11536 dn_flag[0] = '*';
11537 }
11538
11539 if (peer->hostname
11540 && CHECK_FLAG(bgp->flags,
11541 BGP_FLAG_SHOW_HOSTNAME))
11542 len = vty_out(vty, "%s%s(%s)", dn_flag,
11543 peer->hostname,
11544 peer->host);
11545 else
11546 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11547
11548 /* pad the neighbor column with spaces */
11549 if (len < max_neighbor_width)
11550 vty_out(vty, "%*s", max_neighbor_width - len,
11551 " ");
11552
11553 atomic_size_t outq_count, inq_count;
11554 outq_count = atomic_load_explicit(
11555 &peer->obuf->count,
11556 memory_order_relaxed);
11557 inq_count = atomic_load_explicit(
11558 &peer->ibuf->count,
11559 memory_order_relaxed);
11560
11561 if (show_wide)
11562 vty_out(vty,
11563 "4 %10u %10u %9u %9u %8" PRIu64
11564 " %4zu %4zu %8s",
11565 peer->as,
11566 peer->change_local_as
11567 ? peer->change_local_as
11568 : peer->local_as,
11569 PEER_TOTAL_RX(peer),
11570 PEER_TOTAL_TX(peer),
11571 peer->version[afi][safi],
11572 inq_count, outq_count,
11573 peer_uptime(peer->uptime,
11574 timebuf,
11575 BGP_UPTIME_LEN, 0,
11576 NULL));
11577 else
11578 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11579 " %4zu %4zu %8s",
11580 peer->as, PEER_TOTAL_RX(peer),
11581 PEER_TOTAL_TX(peer),
11582 peer->version[afi][safi],
11583 inq_count, outq_count,
11584 peer_uptime(peer->uptime,
11585 timebuf,
11586 BGP_UPTIME_LEN, 0,
11587 NULL));
11588
11589 if (peer_established(peer)) {
11590 if (peer->afc_recv[afi][safi]) {
11591 if (CHECK_FLAG(
11592 bgp->flags,
11593 BGP_FLAG_EBGP_REQUIRES_POLICY)
11594 && !bgp_inbound_policy_exists(
11595 peer, filter))
11596 vty_out(vty, " %12s",
11597 "(Policy)");
11598 else
11599 vty_out(vty,
11600 " %12u",
11601 peer->pcount
11602 [afi]
11603 [pfx_rcd_safi]);
11604 } else {
11605 vty_out(vty, " NoNeg");
11606 }
11607
11608 if (paf && PAF_SUBGRP(paf)) {
11609 if (CHECK_FLAG(
11610 bgp->flags,
11611 BGP_FLAG_EBGP_REQUIRES_POLICY)
11612 && !bgp_outbound_policy_exists(
11613 peer, filter))
11614 vty_out(vty, " %8s",
11615 "(Policy)");
11616 else
11617 vty_out(vty,
11618 " %8u",
11619 (PAF_SUBGRP(
11620 paf))
11621 ->scount);
11622 } else {
11623 vty_out(vty, " NoNeg");
11624 }
11625 } else {
11626 if (CHECK_FLAG(peer->flags,
11627 PEER_FLAG_SHUTDOWN)
11628 || CHECK_FLAG(peer->bgp->flags,
11629 BGP_FLAG_SHUTDOWN))
11630 vty_out(vty, " Idle (Admin)");
11631 else if (CHECK_FLAG(
11632 peer->sflags,
11633 PEER_STATUS_PREFIX_OVERFLOW))
11634 vty_out(vty, " Idle (PfxCt)");
11635 else
11636 vty_out(vty, " %12s",
11637 lookup_msg(bgp_status_msg,
11638 peer->status, NULL));
11639
11640 vty_out(vty, " %8u", 0);
11641 }
11642 /* Make sure `Desc` column is the lastest in
11643 * the output.
11644 */
11645 if (peer->desc)
11646 vty_out(vty, " %s",
11647 bgp_peer_description_stripped(
11648 peer->desc,
11649 show_wide ? 64 : 20));
11650 else
11651 vty_out(vty, " N/A");
11652 vty_out(vty, "\n");
11653 }
11654
11655 }
11656 }
11657
11658 if (use_json) {
11659 json_object_object_add(json, "peers", json_peers);
11660 json_object_int_add(json, "failedPeers", failed_count);
11661 json_object_int_add(json, "displayedPeers",
11662 count - filtered_count);
11663 json_object_int_add(json, "totalPeers", count);
11664 json_object_int_add(json, "dynamicPeers", dn_count);
11665
11666 if (!show_failed)
11667 bgp_show_bestpath_json(bgp, json);
11668
11669 vty_json(vty, json);
11670 } else {
11671 if (count) {
11672 if (filtered_count == count)
11673 vty_out(vty, "\n%% No matching neighbor\n");
11674 else {
11675 if (show_failed)
11676 vty_out(vty, "\nDisplayed neighbors %d",
11677 failed_count);
11678 else if (as_type != AS_UNSPECIFIED || as
11679 || fpeer || show_established)
11680 vty_out(vty, "\nDisplayed neighbors %d",
11681 count - filtered_count);
11682
11683 vty_out(vty, "\nTotal number of neighbors %d\n",
11684 count);
11685 }
11686 } else {
11687 vty_out(vty, "No %s neighbor is configured\n",
11688 get_afi_safi_str(afi, safi, false));
11689 }
11690
11691 if (dn_count) {
11692 vty_out(vty, "* - dynamic neighbor\n");
11693 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11694 dn_count, bgp->dynamic_neighbors_limit);
11695 }
11696 }
11697
11698 return CMD_SUCCESS;
11699 }
11700
11701 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11702 int safi, struct peer *fpeer, int as_type,
11703 as_t as, uint16_t show_flags)
11704 {
11705 int is_first = 1;
11706 int afi_wildcard = (afi == AFI_MAX);
11707 int safi_wildcard = (safi == SAFI_MAX);
11708 int is_wildcard = (afi_wildcard || safi_wildcard);
11709 bool nbr_output = false;
11710 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11711
11712 if (use_json && is_wildcard)
11713 vty_out(vty, "{\n");
11714 if (afi_wildcard)
11715 afi = 1; /* AFI_IP */
11716 while (afi < AFI_MAX) {
11717 if (safi_wildcard)
11718 safi = 1; /* SAFI_UNICAST */
11719 while (safi < SAFI_MAX) {
11720 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11721 nbr_output = true;
11722
11723 if (is_wildcard) {
11724 /*
11725 * So limit output to those afi/safi
11726 * pairs that
11727 * actualy have something interesting in
11728 * them
11729 */
11730 if (use_json) {
11731 if (!is_first)
11732 vty_out(vty, ",\n");
11733 else
11734 is_first = 0;
11735
11736 vty_out(vty, "\"%s\":",
11737 get_afi_safi_str(afi,
11738 safi,
11739 true));
11740 } else {
11741 vty_out(vty,
11742 "\n%s Summary (%s):\n",
11743 get_afi_safi_str(afi,
11744 safi,
11745 false),
11746 bgp->name_pretty);
11747 }
11748 }
11749 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11750 as_type, as, show_flags);
11751 }
11752 safi++;
11753 if (!safi_wildcard)
11754 safi = SAFI_MAX;
11755 }
11756 afi++;
11757 if (!afi_wildcard)
11758 afi = AFI_MAX;
11759 }
11760
11761 if (use_json && is_wildcard)
11762 vty_out(vty, "}\n");
11763 else if (!nbr_output) {
11764 if (use_json)
11765 vty_out(vty, "{}\n");
11766 else
11767 vty_out(vty, "%% No BGP neighbors found in %s\n",
11768 bgp->name_pretty);
11769 }
11770 }
11771
11772 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11773 safi_t safi,
11774 const char *neighbor,
11775 int as_type, as_t as,
11776 uint16_t show_flags)
11777 {
11778 struct listnode *node, *nnode;
11779 struct bgp *bgp;
11780 struct peer *fpeer = NULL;
11781 int is_first = 1;
11782 bool nbr_output = false;
11783 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11784
11785 if (use_json)
11786 vty_out(vty, "{\n");
11787
11788 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11789 nbr_output = true;
11790 if (use_json) {
11791 if (!is_first)
11792 vty_out(vty, ",\n");
11793 else
11794 is_first = 0;
11795
11796 vty_out(vty, "\"%s\":",
11797 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11798 ? VRF_DEFAULT_NAME
11799 : bgp->name);
11800 }
11801 if (neighbor) {
11802 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11803 use_json);
11804 if (!fpeer)
11805 continue;
11806 }
11807 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11808 as, show_flags);
11809 }
11810
11811 if (use_json)
11812 vty_out(vty, "}\n");
11813 else if (!nbr_output)
11814 vty_out(vty, "%% BGP instance not found\n");
11815 }
11816
11817 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11818 safi_t safi, const char *neighbor, int as_type,
11819 as_t as, uint16_t show_flags)
11820 {
11821 struct bgp *bgp;
11822 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11823 struct peer *fpeer = NULL;
11824
11825 if (name) {
11826 if (strmatch(name, "all")) {
11827 bgp_show_all_instances_summary_vty(vty, afi, safi,
11828 neighbor, as_type,
11829 as, show_flags);
11830 return CMD_SUCCESS;
11831 } else {
11832 bgp = bgp_lookup_by_name(name);
11833
11834 if (!bgp) {
11835 if (use_json)
11836 vty_out(vty, "{}\n");
11837 else
11838 vty_out(vty,
11839 "%% BGP instance not found\n");
11840 return CMD_WARNING;
11841 }
11842
11843 if (neighbor) {
11844 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11845 use_json);
11846 if (!fpeer)
11847 return CMD_WARNING;
11848 }
11849 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11850 as_type, as, show_flags);
11851 return CMD_SUCCESS;
11852 }
11853 }
11854
11855 bgp = bgp_get_default();
11856
11857 if (bgp) {
11858 if (neighbor) {
11859 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11860 use_json);
11861 if (!fpeer)
11862 return CMD_WARNING;
11863 }
11864 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11865 as, show_flags);
11866 } else {
11867 if (use_json)
11868 vty_out(vty, "{}\n");
11869 else
11870 vty_out(vty, "%% BGP instance not found\n");
11871 return CMD_WARNING;
11872 }
11873
11874 return CMD_SUCCESS;
11875 }
11876
11877 /* `show [ip] bgp summary' commands. */
11878 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11879 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11880 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11881 "]] [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]",
11882 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11883 BGP_SAFI_WITH_LABEL_HELP_STR
11884 "Display the entries for all address families\n"
11885 "Summary of BGP neighbor status\n"
11886 "Show only sessions in Established state\n"
11887 "Show only sessions not in Established state\n"
11888 "Show only the specified neighbor session\n"
11889 "Neighbor to display information about\n"
11890 "Neighbor to display information about\n"
11891 "Neighbor on BGP configured interface\n"
11892 "Show only the specified remote AS sessions\n"
11893 "AS number\n"
11894 "Internal (iBGP) AS sessions\n"
11895 "External (eBGP) AS sessions\n"
11896 "Shorten the information on BGP instances\n"
11897 "Increase table width for longer output\n" JSON_STR)
11898 {
11899 char *vrf = NULL;
11900 afi_t afi = AFI_MAX;
11901 safi_t safi = SAFI_MAX;
11902 as_t as = 0; /* 0 means AS filter not set */
11903 int as_type = AS_UNSPECIFIED;
11904 uint16_t show_flags = 0;
11905
11906 int idx = 0;
11907
11908 /* show [ip] bgp */
11909 if (!all && argv_find(argv, argc, "ip", &idx))
11910 afi = AFI_IP;
11911 /* [<vrf> VIEWVRFNAME] */
11912 if (argv_find(argv, argc, "vrf", &idx)) {
11913 vrf = argv[idx + 1]->arg;
11914 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11915 vrf = NULL;
11916 } else if (argv_find(argv, argc, "view", &idx))
11917 /* [<view> VIEWVRFNAME] */
11918 vrf = argv[idx + 1]->arg;
11919 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11920 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11921 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11922 }
11923
11924 if (argv_find(argv, argc, "failed", &idx))
11925 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11926
11927 if (argv_find(argv, argc, "established", &idx))
11928 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11929
11930 if (argv_find(argv, argc, "remote-as", &idx)) {
11931 if (argv[idx + 1]->arg[0] == 'i')
11932 as_type = AS_INTERNAL;
11933 else if (argv[idx + 1]->arg[0] == 'e')
11934 as_type = AS_EXTERNAL;
11935 else
11936 as = (as_t)atoi(argv[idx + 1]->arg);
11937 }
11938
11939 if (argv_find(argv, argc, "terse", &idx))
11940 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11941
11942 if (argv_find(argv, argc, "wide", &idx))
11943 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11944
11945 if (argv_find(argv, argc, "json", &idx))
11946 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11947
11948 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11949 show_flags);
11950 }
11951
11952 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11953 {
11954 if (for_json)
11955 return get_afi_safi_json_str(afi, safi);
11956 else
11957 return get_afi_safi_vty_str(afi, safi);
11958 }
11959
11960
11961 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11962 afi_t afi, safi_t safi,
11963 uint16_t adv_smcap, uint16_t adv_rmcap,
11964 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11965 bool use_json, json_object *json_pref)
11966 {
11967 /* Send-Mode */
11968 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11969 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11970 if (use_json) {
11971 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11972 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11973 json_object_string_add(json_pref, "sendMode",
11974 "advertisedAndReceived");
11975 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11976 json_object_string_add(json_pref, "sendMode",
11977 "advertised");
11978 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11979 json_object_string_add(json_pref, "sendMode",
11980 "received");
11981 } else {
11982 vty_out(vty, " Send-mode: ");
11983 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11984 vty_out(vty, "advertised");
11985 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11986 vty_out(vty, "%sreceived",
11987 CHECK_FLAG(p->af_cap[afi][safi],
11988 adv_smcap)
11989 ? ", "
11990 : "");
11991 vty_out(vty, "\n");
11992 }
11993 }
11994
11995 /* Receive-Mode */
11996 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11997 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11998 if (use_json) {
11999 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12000 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12001 json_object_string_add(json_pref, "recvMode",
12002 "advertisedAndReceived");
12003 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12004 json_object_string_add(json_pref, "recvMode",
12005 "advertised");
12006 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12007 json_object_string_add(json_pref, "recvMode",
12008 "received");
12009 } else {
12010 vty_out(vty, " Receive-mode: ");
12011 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12012 vty_out(vty, "advertised");
12013 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12014 vty_out(vty, "%sreceived",
12015 CHECK_FLAG(p->af_cap[afi][safi],
12016 adv_rmcap)
12017 ? ", "
12018 : "");
12019 vty_out(vty, "\n");
12020 }
12021 }
12022 }
12023
12024 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
12025 struct peer *p,
12026 json_object *json)
12027 {
12028 bool rbit = false;
12029 bool nbit = false;
12030
12031 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12032 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
12033 && (peer_established(p))) {
12034 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
12035 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
12036 }
12037
12038 if (json) {
12039 json_object_boolean_add(json, "rBit", rbit);
12040 json_object_boolean_add(json, "nBit", nbit);
12041 } else {
12042 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
12043 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
12044 }
12045 }
12046
12047 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12048 struct peer *peer,
12049 json_object *json)
12050 {
12051 const char *mode = "NotApplicable";
12052
12053 if (!json)
12054 vty_out(vty, "\n Remote GR Mode: ");
12055
12056 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12057 && (peer_established(peer))) {
12058
12059 if ((peer->nsf_af_count == 0)
12060 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12061
12062 mode = "Disable";
12063
12064 } else if (peer->nsf_af_count == 0
12065 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12066
12067 mode = "Helper";
12068
12069 } else if (peer->nsf_af_count != 0
12070 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12071
12072 mode = "Restart";
12073 }
12074 }
12075
12076 if (json)
12077 json_object_string_add(json, "remoteGrMode", mode);
12078 else
12079 vty_out(vty, "%s\n", mode);
12080 }
12081
12082 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12083 struct peer *p,
12084 json_object *json)
12085 {
12086 const char *mode = "Invalid";
12087
12088 if (!json)
12089 vty_out(vty, " Local GR Mode: ");
12090
12091 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12092 mode = "Helper";
12093 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12094 mode = "Restart";
12095 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12096 mode = "Disable";
12097 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12098 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12099 mode = "Helper*";
12100 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12101 mode = "Restart*";
12102 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12103 mode = "Disable*";
12104 else
12105 mode = "Invalid*";
12106 }
12107
12108 if (json)
12109 json_object_string_add(json, "localGrMode", mode);
12110 else
12111 vty_out(vty, "%s\n", mode);
12112 }
12113
12114 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12115 struct vty *vty, struct peer *peer, json_object *json)
12116 {
12117 afi_t afi;
12118 safi_t safi;
12119 json_object *json_afi_safi = NULL;
12120 json_object *json_timer = NULL;
12121 json_object *json_endofrib_status = NULL;
12122 bool eor_flag = false;
12123
12124 FOREACH_AFI_SAFI_NSF (afi, safi) {
12125 if (!peer->afc[afi][safi])
12126 continue;
12127
12128 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12129 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12130 continue;
12131
12132 if (json) {
12133 json_afi_safi = json_object_new_object();
12134 json_endofrib_status = json_object_new_object();
12135 json_timer = json_object_new_object();
12136 }
12137
12138 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12139 eor_flag = true;
12140 else
12141 eor_flag = false;
12142
12143 if (!json) {
12144 vty_out(vty, " %s:\n",
12145 get_afi_safi_str(afi, safi, false));
12146
12147 vty_out(vty, " F bit: ");
12148 }
12149
12150 if (peer->nsf[afi][safi] &&
12151 CHECK_FLAG(peer->af_cap[afi][safi],
12152 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12153
12154 if (json) {
12155 json_object_boolean_true_add(json_afi_safi,
12156 "fBit");
12157 } else
12158 vty_out(vty, "True\n");
12159 } else {
12160 if (json)
12161 json_object_boolean_false_add(json_afi_safi,
12162 "fBit");
12163 else
12164 vty_out(vty, "False\n");
12165 }
12166
12167 if (!json)
12168 vty_out(vty, " End-of-RIB sent: ");
12169
12170 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12171 PEER_STATUS_EOR_SEND)) {
12172 if (json) {
12173 json_object_boolean_true_add(
12174 json_endofrib_status, "endOfRibSend");
12175
12176 PRINT_EOR_JSON(eor_flag);
12177 } else {
12178 vty_out(vty, "Yes\n");
12179 vty_out(vty,
12180 " End-of-RIB sent after update: ");
12181
12182 PRINT_EOR(eor_flag);
12183 }
12184 } else {
12185 if (json) {
12186 json_object_boolean_false_add(
12187 json_endofrib_status, "endOfRibSend");
12188 json_object_boolean_false_add(
12189 json_endofrib_status,
12190 "endOfRibSentAfterUpdate");
12191 } else {
12192 vty_out(vty, "No\n");
12193 vty_out(vty,
12194 " End-of-RIB sent after update: ");
12195 vty_out(vty, "No\n");
12196 }
12197 }
12198
12199 if (!json)
12200 vty_out(vty, " End-of-RIB received: ");
12201
12202 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12203 PEER_STATUS_EOR_RECEIVED)) {
12204 if (json)
12205 json_object_boolean_true_add(
12206 json_endofrib_status, "endOfRibRecv");
12207 else
12208 vty_out(vty, "Yes\n");
12209 } else {
12210 if (json)
12211 json_object_boolean_false_add(
12212 json_endofrib_status, "endOfRibRecv");
12213 else
12214 vty_out(vty, "No\n");
12215 }
12216
12217 if (json) {
12218 json_object_int_add(json_timer, "stalePathTimer",
12219 peer->bgp->stalepath_time);
12220
12221 if (peer->t_gr_stale != NULL) {
12222 json_object_int_add(json_timer,
12223 "stalePathTimerRemaining",
12224 thread_timer_remain_second(
12225 peer->t_gr_stale));
12226 }
12227
12228 /* Display Configured Selection
12229 * Deferral only when when
12230 * Gr mode is enabled.
12231 */
12232 if (CHECK_FLAG(peer->flags,
12233 PEER_FLAG_GRACEFUL_RESTART)) {
12234 json_object_int_add(json_timer,
12235 "selectionDeferralTimer",
12236 peer->bgp->stalepath_time);
12237 }
12238
12239 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12240 NULL) {
12241
12242 json_object_int_add(
12243 json_timer,
12244 "selectionDeferralTimerRemaining",
12245 thread_timer_remain_second(
12246 peer->bgp->gr_info[afi][safi]
12247 .t_select_deferral));
12248 }
12249 } else {
12250 vty_out(vty, " Timers:\n");
12251 vty_out(vty,
12252 " Configured Stale Path Time(sec): %u\n",
12253 peer->bgp->stalepath_time);
12254
12255 if (peer->t_gr_stale != NULL)
12256 vty_out(vty,
12257 " Stale Path Remaining(sec): %ld\n",
12258 thread_timer_remain_second(
12259 peer->t_gr_stale));
12260 /* Display Configured Selection
12261 * Deferral only when when
12262 * Gr mode is enabled.
12263 */
12264 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12265 vty_out(vty,
12266 " Configured Selection Deferral Time(sec): %u\n",
12267 peer->bgp->select_defer_time);
12268
12269 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12270 NULL)
12271 vty_out(vty,
12272 " Selection Deferral Time Remaining(sec): %ld\n",
12273 thread_timer_remain_second(
12274 peer->bgp->gr_info[afi][safi]
12275 .t_select_deferral));
12276 }
12277 if (json) {
12278 json_object_object_add(json_afi_safi, "endOfRibStatus",
12279 json_endofrib_status);
12280 json_object_object_add(json_afi_safi, "timers",
12281 json_timer);
12282 json_object_object_add(
12283 json, get_afi_safi_str(afi, safi, true),
12284 json_afi_safi);
12285 }
12286 }
12287 }
12288
12289 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12290 struct peer *p,
12291 json_object *json)
12292 {
12293 if (json) {
12294 json_object *json_timer = NULL;
12295
12296 json_timer = json_object_new_object();
12297
12298 json_object_int_add(json_timer, "configuredRestartTimer",
12299 p->bgp->restart_time);
12300
12301 json_object_int_add(json_timer, "receivedRestartTimer",
12302 p->v_gr_restart);
12303
12304 if (p->t_gr_restart != NULL)
12305 json_object_int_add(
12306 json_timer, "restartTimerRemaining",
12307 thread_timer_remain_second(p->t_gr_restart));
12308
12309 json_object_object_add(json, "timers", json_timer);
12310 } else {
12311
12312 vty_out(vty, " Timers:\n");
12313 vty_out(vty, " Configured Restart Time(sec): %u\n",
12314 p->bgp->restart_time);
12315
12316 vty_out(vty, " Received Restart Time(sec): %u\n",
12317 p->v_gr_restart);
12318 if (p->t_gr_restart != NULL)
12319 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12320 thread_timer_remain_second(p->t_gr_restart));
12321 if (p->t_gr_restart != NULL) {
12322 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12323 thread_timer_remain_second(p->t_gr_restart));
12324 }
12325 }
12326 }
12327
12328 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12329 json_object *json)
12330 {
12331 char dn_flag[2] = {0};
12332 /* '*' + v6 address of neighbor */
12333 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12334
12335 if (!p->conf_if && peer_dynamic_neighbor(p))
12336 dn_flag[0] = '*';
12337
12338 if (p->conf_if) {
12339 if (json)
12340 json_object_string_addf(json, "neighborAddr", "%pSU",
12341 &p->su);
12342 else
12343 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12344 &p->su);
12345 } else {
12346 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12347 p->host);
12348
12349 if (json)
12350 json_object_string_add(json, "neighborAddr",
12351 neighborAddr);
12352 else
12353 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12354 }
12355
12356 /* more gr info in new format */
12357 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12358 }
12359
12360 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12361 safi_t safi, bool use_json,
12362 json_object *json_neigh)
12363 {
12364 struct bgp_filter *filter;
12365 struct peer_af *paf;
12366 char orf_pfx_name[BUFSIZ];
12367 int orf_pfx_count;
12368 json_object *json_af = NULL;
12369 json_object *json_prefA = NULL;
12370 json_object *json_prefB = NULL;
12371 json_object *json_addr = NULL;
12372 json_object *json_advmap = NULL;
12373
12374 if (use_json) {
12375 json_addr = json_object_new_object();
12376 json_af = json_object_new_object();
12377 filter = &p->filter[afi][safi];
12378
12379 if (peer_group_active(p))
12380 json_object_string_add(json_addr, "peerGroupMember",
12381 p->group->name);
12382
12383 paf = peer_af_find(p, afi, safi);
12384 if (paf && PAF_SUBGRP(paf)) {
12385 json_object_int_add(json_addr, "updateGroupId",
12386 PAF_UPDGRP(paf)->id);
12387 json_object_int_add(json_addr, "subGroupId",
12388 PAF_SUBGRP(paf)->id);
12389 json_object_int_add(json_addr, "packetQueueLength",
12390 bpacket_queue_virtual_length(paf));
12391 }
12392
12393 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12394 || CHECK_FLAG(p->af_cap[afi][safi],
12395 PEER_CAP_ORF_PREFIX_SM_RCV)
12396 || CHECK_FLAG(p->af_cap[afi][safi],
12397 PEER_CAP_ORF_PREFIX_RM_ADV)
12398 || CHECK_FLAG(p->af_cap[afi][safi],
12399 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12400 json_object_int_add(json_af, "orfType",
12401 ORF_TYPE_PREFIX);
12402 json_prefA = json_object_new_object();
12403 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12404 PEER_CAP_ORF_PREFIX_SM_ADV,
12405 PEER_CAP_ORF_PREFIX_RM_ADV,
12406 PEER_CAP_ORF_PREFIX_SM_RCV,
12407 PEER_CAP_ORF_PREFIX_RM_RCV,
12408 use_json, json_prefA);
12409 json_object_object_add(json_af, "orfPrefixList",
12410 json_prefA);
12411 }
12412
12413 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12414 || CHECK_FLAG(p->af_cap[afi][safi],
12415 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12416 || CHECK_FLAG(p->af_cap[afi][safi],
12417 PEER_CAP_ORF_PREFIX_RM_ADV)
12418 || CHECK_FLAG(p->af_cap[afi][safi],
12419 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12420 json_object_int_add(json_af, "orfOldType",
12421 ORF_TYPE_PREFIX_OLD);
12422 json_prefB = json_object_new_object();
12423 bgp_show_peer_afi_orf_cap(
12424 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12425 PEER_CAP_ORF_PREFIX_RM_ADV,
12426 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12427 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12428 json_prefB);
12429 json_object_object_add(json_af, "orfOldPrefixList",
12430 json_prefB);
12431 }
12432
12433 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12434 || CHECK_FLAG(p->af_cap[afi][safi],
12435 PEER_CAP_ORF_PREFIX_SM_RCV)
12436 || CHECK_FLAG(p->af_cap[afi][safi],
12437 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12438 || CHECK_FLAG(p->af_cap[afi][safi],
12439 PEER_CAP_ORF_PREFIX_RM_ADV)
12440 || CHECK_FLAG(p->af_cap[afi][safi],
12441 PEER_CAP_ORF_PREFIX_RM_RCV)
12442 || CHECK_FLAG(p->af_cap[afi][safi],
12443 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12444 json_object_object_add(json_addr, "afDependentCap",
12445 json_af);
12446 else
12447 json_object_free(json_af);
12448
12449 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12450 p->host, afi, safi);
12451 orf_pfx_count = prefix_bgp_show_prefix_list(
12452 NULL, afi, orf_pfx_name, use_json);
12453
12454 if (CHECK_FLAG(p->af_sflags[afi][safi],
12455 PEER_STATUS_ORF_PREFIX_SEND)
12456 || orf_pfx_count) {
12457 if (CHECK_FLAG(p->af_sflags[afi][safi],
12458 PEER_STATUS_ORF_PREFIX_SEND))
12459 json_object_boolean_true_add(json_neigh,
12460 "orfSent");
12461 if (orf_pfx_count)
12462 json_object_int_add(json_addr, "orfRecvCounter",
12463 orf_pfx_count);
12464 }
12465 if (CHECK_FLAG(p->af_sflags[afi][safi],
12466 PEER_STATUS_ORF_WAIT_REFRESH))
12467 json_object_string_add(
12468 json_addr, "orfFirstUpdate",
12469 "deferredUntilORFOrRouteRefreshRecvd");
12470
12471 if (CHECK_FLAG(p->af_flags[afi][safi],
12472 PEER_FLAG_REFLECTOR_CLIENT))
12473 json_object_boolean_true_add(json_addr,
12474 "routeReflectorClient");
12475 if (CHECK_FLAG(p->af_flags[afi][safi],
12476 PEER_FLAG_RSERVER_CLIENT))
12477 json_object_boolean_true_add(json_addr,
12478 "routeServerClient");
12479 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12480 json_object_boolean_true_add(json_addr,
12481 "inboundSoftConfigPermit");
12482
12483 if (CHECK_FLAG(p->af_flags[afi][safi],
12484 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12485 json_object_boolean_true_add(
12486 json_addr,
12487 "privateAsNumsAllReplacedInUpdatesToNbr");
12488 else if (CHECK_FLAG(p->af_flags[afi][safi],
12489 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12490 json_object_boolean_true_add(
12491 json_addr,
12492 "privateAsNumsReplacedInUpdatesToNbr");
12493 else if (CHECK_FLAG(p->af_flags[afi][safi],
12494 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12495 json_object_boolean_true_add(
12496 json_addr,
12497 "privateAsNumsAllRemovedInUpdatesToNbr");
12498 else if (CHECK_FLAG(p->af_flags[afi][safi],
12499 PEER_FLAG_REMOVE_PRIVATE_AS))
12500 json_object_boolean_true_add(
12501 json_addr,
12502 "privateAsNumsRemovedInUpdatesToNbr");
12503
12504 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12505 if (CHECK_FLAG(p->af_flags[afi][safi],
12506 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12507 json_object_boolean_true_add(json_addr,
12508 "allowAsInOrigin");
12509 else
12510 json_object_int_add(json_addr, "allowAsInCount",
12511 p->allowas_in[afi][safi]);
12512 }
12513
12514 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12515 json_object_boolean_true_add(
12516 json_addr,
12517 bgp_addpath_names(p->addpath_type[afi][safi])
12518 ->type_json_name);
12519
12520 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12521 json_object_string_add(json_addr,
12522 "overrideASNsInOutboundUpdates",
12523 "ifAspathEqualRemoteAs");
12524
12525 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12526 || CHECK_FLAG(p->af_flags[afi][safi],
12527 PEER_FLAG_FORCE_NEXTHOP_SELF))
12528 json_object_boolean_true_add(json_addr,
12529 "routerAlwaysNextHop");
12530 if (CHECK_FLAG(p->af_flags[afi][safi],
12531 PEER_FLAG_AS_PATH_UNCHANGED))
12532 json_object_boolean_true_add(
12533 json_addr, "unchangedAsPathPropogatedToNbr");
12534 if (CHECK_FLAG(p->af_flags[afi][safi],
12535 PEER_FLAG_NEXTHOP_UNCHANGED))
12536 json_object_boolean_true_add(
12537 json_addr, "unchangedNextHopPropogatedToNbr");
12538 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12539 json_object_boolean_true_add(
12540 json_addr, "unchangedMedPropogatedToNbr");
12541 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12542 || CHECK_FLAG(p->af_flags[afi][safi],
12543 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12544 if (CHECK_FLAG(p->af_flags[afi][safi],
12545 PEER_FLAG_SEND_COMMUNITY)
12546 && CHECK_FLAG(p->af_flags[afi][safi],
12547 PEER_FLAG_SEND_EXT_COMMUNITY))
12548 json_object_string_add(json_addr,
12549 "commAttriSentToNbr",
12550 "extendedAndStandard");
12551 else if (CHECK_FLAG(p->af_flags[afi][safi],
12552 PEER_FLAG_SEND_EXT_COMMUNITY))
12553 json_object_string_add(json_addr,
12554 "commAttriSentToNbr",
12555 "extended");
12556 else
12557 json_object_string_add(json_addr,
12558 "commAttriSentToNbr",
12559 "standard");
12560 }
12561 if (CHECK_FLAG(p->af_flags[afi][safi],
12562 PEER_FLAG_DEFAULT_ORIGINATE)) {
12563 if (p->default_rmap[afi][safi].name)
12564 json_object_string_add(
12565 json_addr, "defaultRouteMap",
12566 p->default_rmap[afi][safi].name);
12567
12568 if (paf && PAF_SUBGRP(paf)
12569 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12570 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12571 json_object_boolean_true_add(json_addr,
12572 "defaultSent");
12573 else
12574 json_object_boolean_true_add(json_addr,
12575 "defaultNotSent");
12576 }
12577
12578 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12579 if (is_evpn_enabled())
12580 json_object_boolean_true_add(
12581 json_addr, "advertiseAllVnis");
12582 }
12583
12584 if (filter->plist[FILTER_IN].name
12585 || filter->dlist[FILTER_IN].name
12586 || filter->aslist[FILTER_IN].name
12587 || filter->map[RMAP_IN].name)
12588 json_object_boolean_true_add(json_addr,
12589 "inboundPathPolicyConfig");
12590 if (filter->plist[FILTER_OUT].name
12591 || filter->dlist[FILTER_OUT].name
12592 || filter->aslist[FILTER_OUT].name
12593 || filter->map[RMAP_OUT].name || filter->usmap.name)
12594 json_object_boolean_true_add(
12595 json_addr, "outboundPathPolicyConfig");
12596
12597 /* prefix-list */
12598 if (filter->plist[FILTER_IN].name)
12599 json_object_string_add(json_addr,
12600 "incomingUpdatePrefixFilterList",
12601 filter->plist[FILTER_IN].name);
12602 if (filter->plist[FILTER_OUT].name)
12603 json_object_string_add(json_addr,
12604 "outgoingUpdatePrefixFilterList",
12605 filter->plist[FILTER_OUT].name);
12606
12607 /* distribute-list */
12608 if (filter->dlist[FILTER_IN].name)
12609 json_object_string_add(
12610 json_addr, "incomingUpdateNetworkFilterList",
12611 filter->dlist[FILTER_IN].name);
12612 if (filter->dlist[FILTER_OUT].name)
12613 json_object_string_add(
12614 json_addr, "outgoingUpdateNetworkFilterList",
12615 filter->dlist[FILTER_OUT].name);
12616
12617 /* filter-list. */
12618 if (filter->aslist[FILTER_IN].name)
12619 json_object_string_add(json_addr,
12620 "incomingUpdateAsPathFilterList",
12621 filter->aslist[FILTER_IN].name);
12622 if (filter->aslist[FILTER_OUT].name)
12623 json_object_string_add(json_addr,
12624 "outgoingUpdateAsPathFilterList",
12625 filter->aslist[FILTER_OUT].name);
12626
12627 /* route-map. */
12628 if (filter->map[RMAP_IN].name)
12629 json_object_string_add(
12630 json_addr, "routeMapForIncomingAdvertisements",
12631 filter->map[RMAP_IN].name);
12632 if (filter->map[RMAP_OUT].name)
12633 json_object_string_add(
12634 json_addr, "routeMapForOutgoingAdvertisements",
12635 filter->map[RMAP_OUT].name);
12636
12637 /* ebgp-requires-policy (inbound) */
12638 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12639 && !bgp_inbound_policy_exists(p, filter))
12640 json_object_string_add(
12641 json_addr, "inboundEbgpRequiresPolicy",
12642 "Inbound updates discarded due to missing policy");
12643
12644 /* ebgp-requires-policy (outbound) */
12645 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12646 && (!bgp_outbound_policy_exists(p, filter)))
12647 json_object_string_add(
12648 json_addr, "outboundEbgpRequiresPolicy",
12649 "Outbound updates discarded due to missing policy");
12650
12651 /* unsuppress-map */
12652 if (filter->usmap.name)
12653 json_object_string_add(json_addr,
12654 "selectiveUnsuppressRouteMap",
12655 filter->usmap.name);
12656
12657 /* advertise-map */
12658 if (filter->advmap.aname) {
12659 json_advmap = json_object_new_object();
12660 json_object_string_add(json_advmap, "condition",
12661 filter->advmap.condition
12662 ? "EXIST"
12663 : "NON_EXIST");
12664 json_object_string_add(json_advmap, "conditionMap",
12665 filter->advmap.cname);
12666 json_object_string_add(json_advmap, "advertiseMap",
12667 filter->advmap.aname);
12668 json_object_string_add(
12669 json_advmap, "advertiseStatus",
12670 filter->advmap.update_type ==
12671 UPDATE_TYPE_ADVERTISE
12672 ? "Advertise"
12673 : "Withdraw");
12674 json_object_object_add(json_addr, "advertiseMap",
12675 json_advmap);
12676 }
12677
12678 /* Receive prefix count */
12679 json_object_int_add(json_addr, "acceptedPrefixCounter",
12680 p->pcount[afi][safi]);
12681 if (paf && PAF_SUBGRP(paf))
12682 json_object_int_add(json_addr, "sentPrefixCounter",
12683 (PAF_SUBGRP(paf))->scount);
12684
12685 /* Maximum prefix */
12686 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12687 json_object_int_add(json_addr, "prefixOutAllowedMax",
12688 p->pmax_out[afi][safi]);
12689
12690 /* Maximum prefix */
12691 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12692 json_object_int_add(json_addr, "prefixAllowedMax",
12693 p->pmax[afi][safi]);
12694 if (CHECK_FLAG(p->af_flags[afi][safi],
12695 PEER_FLAG_MAX_PREFIX_WARNING))
12696 json_object_boolean_true_add(
12697 json_addr, "prefixAllowedMaxWarning");
12698 json_object_int_add(json_addr,
12699 "prefixAllowedWarningThresh",
12700 p->pmax_threshold[afi][safi]);
12701 if (p->pmax_restart[afi][safi])
12702 json_object_int_add(
12703 json_addr,
12704 "prefixAllowedRestartIntervalMsecs",
12705 p->pmax_restart[afi][safi] * 60000);
12706 }
12707 json_object_object_add(json_neigh,
12708 get_afi_safi_str(afi, safi, true),
12709 json_addr);
12710
12711 } else {
12712 filter = &p->filter[afi][safi];
12713
12714 vty_out(vty, " For address family: %s\n",
12715 get_afi_safi_str(afi, safi, false));
12716
12717 if (peer_group_active(p))
12718 vty_out(vty, " %s peer-group member\n",
12719 p->group->name);
12720
12721 paf = peer_af_find(p, afi, safi);
12722 if (paf && PAF_SUBGRP(paf)) {
12723 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12724 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12725 vty_out(vty, " Packet Queue length %d\n",
12726 bpacket_queue_virtual_length(paf));
12727 } else {
12728 vty_out(vty, " Not part of any update group\n");
12729 }
12730 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12731 || CHECK_FLAG(p->af_cap[afi][safi],
12732 PEER_CAP_ORF_PREFIX_SM_RCV)
12733 || CHECK_FLAG(p->af_cap[afi][safi],
12734 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12735 || CHECK_FLAG(p->af_cap[afi][safi],
12736 PEER_CAP_ORF_PREFIX_RM_ADV)
12737 || CHECK_FLAG(p->af_cap[afi][safi],
12738 PEER_CAP_ORF_PREFIX_RM_RCV)
12739 || CHECK_FLAG(p->af_cap[afi][safi],
12740 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12741 vty_out(vty, " AF-dependant capabilities:\n");
12742
12743 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12744 || CHECK_FLAG(p->af_cap[afi][safi],
12745 PEER_CAP_ORF_PREFIX_SM_RCV)
12746 || CHECK_FLAG(p->af_cap[afi][safi],
12747 PEER_CAP_ORF_PREFIX_RM_ADV)
12748 || CHECK_FLAG(p->af_cap[afi][safi],
12749 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12750 vty_out(vty,
12751 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12752 ORF_TYPE_PREFIX);
12753 bgp_show_peer_afi_orf_cap(
12754 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12755 PEER_CAP_ORF_PREFIX_RM_ADV,
12756 PEER_CAP_ORF_PREFIX_SM_RCV,
12757 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12758 }
12759 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12760 || CHECK_FLAG(p->af_cap[afi][safi],
12761 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12762 || CHECK_FLAG(p->af_cap[afi][safi],
12763 PEER_CAP_ORF_PREFIX_RM_ADV)
12764 || CHECK_FLAG(p->af_cap[afi][safi],
12765 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12766 vty_out(vty,
12767 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12768 ORF_TYPE_PREFIX_OLD);
12769 bgp_show_peer_afi_orf_cap(
12770 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12771 PEER_CAP_ORF_PREFIX_RM_ADV,
12772 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12773 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12774 }
12775
12776 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12777 p->host, afi, safi);
12778 orf_pfx_count = prefix_bgp_show_prefix_list(
12779 NULL, afi, orf_pfx_name, use_json);
12780
12781 if (CHECK_FLAG(p->af_sflags[afi][safi],
12782 PEER_STATUS_ORF_PREFIX_SEND)
12783 || orf_pfx_count) {
12784 vty_out(vty, " Outbound Route Filter (ORF):");
12785 if (CHECK_FLAG(p->af_sflags[afi][safi],
12786 PEER_STATUS_ORF_PREFIX_SEND))
12787 vty_out(vty, " sent;");
12788 if (orf_pfx_count)
12789 vty_out(vty, " received (%d entries)",
12790 orf_pfx_count);
12791 vty_out(vty, "\n");
12792 }
12793 if (CHECK_FLAG(p->af_sflags[afi][safi],
12794 PEER_STATUS_ORF_WAIT_REFRESH))
12795 vty_out(vty,
12796 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12797
12798 if (CHECK_FLAG(p->af_flags[afi][safi],
12799 PEER_FLAG_REFLECTOR_CLIENT))
12800 vty_out(vty, " Route-Reflector Client\n");
12801 if (CHECK_FLAG(p->af_flags[afi][safi],
12802 PEER_FLAG_RSERVER_CLIENT))
12803 vty_out(vty, " Route-Server Client\n");
12804 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12805 vty_out(vty,
12806 " Inbound soft reconfiguration allowed\n");
12807
12808 if (CHECK_FLAG(p->af_flags[afi][safi],
12809 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12810 vty_out(vty,
12811 " Private AS numbers (all) replaced in updates to this neighbor\n");
12812 else if (CHECK_FLAG(p->af_flags[afi][safi],
12813 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12814 vty_out(vty,
12815 " Private AS numbers replaced in updates to this neighbor\n");
12816 else if (CHECK_FLAG(p->af_flags[afi][safi],
12817 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12818 vty_out(vty,
12819 " Private AS numbers (all) removed in updates to this neighbor\n");
12820 else if (CHECK_FLAG(p->af_flags[afi][safi],
12821 PEER_FLAG_REMOVE_PRIVATE_AS))
12822 vty_out(vty,
12823 " Private AS numbers removed in updates to this neighbor\n");
12824
12825 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12826 if (CHECK_FLAG(p->af_flags[afi][safi],
12827 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12828 vty_out(vty,
12829 " Local AS allowed as path origin\n");
12830 else
12831 vty_out(vty,
12832 " Local AS allowed in path, %d occurrences\n",
12833 p->allowas_in[afi][safi]);
12834 }
12835
12836 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12837 vty_out(vty, " %s\n",
12838 bgp_addpath_names(p->addpath_type[afi][safi])
12839 ->human_description);
12840
12841 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12842 vty_out(vty,
12843 " Override ASNs in outbound updates if aspath equals remote-as\n");
12844
12845 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12846 || CHECK_FLAG(p->af_flags[afi][safi],
12847 PEER_FLAG_FORCE_NEXTHOP_SELF))
12848 vty_out(vty, " NEXT_HOP is always this router\n");
12849 if (CHECK_FLAG(p->af_flags[afi][safi],
12850 PEER_FLAG_AS_PATH_UNCHANGED))
12851 vty_out(vty,
12852 " AS_PATH is propagated unchanged to this neighbor\n");
12853 if (CHECK_FLAG(p->af_flags[afi][safi],
12854 PEER_FLAG_NEXTHOP_UNCHANGED))
12855 vty_out(vty,
12856 " NEXT_HOP is propagated unchanged to this neighbor\n");
12857 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12858 vty_out(vty,
12859 " MED is propagated unchanged to this neighbor\n");
12860 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12861 || CHECK_FLAG(p->af_flags[afi][safi],
12862 PEER_FLAG_SEND_EXT_COMMUNITY)
12863 || CHECK_FLAG(p->af_flags[afi][safi],
12864 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12865 vty_out(vty,
12866 " Community attribute sent to this neighbor");
12867 if (CHECK_FLAG(p->af_flags[afi][safi],
12868 PEER_FLAG_SEND_COMMUNITY)
12869 && CHECK_FLAG(p->af_flags[afi][safi],
12870 PEER_FLAG_SEND_EXT_COMMUNITY)
12871 && CHECK_FLAG(p->af_flags[afi][safi],
12872 PEER_FLAG_SEND_LARGE_COMMUNITY))
12873 vty_out(vty, "(all)\n");
12874 else if (CHECK_FLAG(p->af_flags[afi][safi],
12875 PEER_FLAG_SEND_LARGE_COMMUNITY))
12876 vty_out(vty, "(large)\n");
12877 else if (CHECK_FLAG(p->af_flags[afi][safi],
12878 PEER_FLAG_SEND_EXT_COMMUNITY))
12879 vty_out(vty, "(extended)\n");
12880 else
12881 vty_out(vty, "(standard)\n");
12882 }
12883 if (CHECK_FLAG(p->af_flags[afi][safi],
12884 PEER_FLAG_DEFAULT_ORIGINATE)) {
12885 vty_out(vty, " Default information originate,");
12886
12887 if (p->default_rmap[afi][safi].name)
12888 vty_out(vty, " default route-map %s%s,",
12889 p->default_rmap[afi][safi].map ? "*"
12890 : "",
12891 p->default_rmap[afi][safi].name);
12892 if (paf && PAF_SUBGRP(paf)
12893 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12894 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12895 vty_out(vty, " default sent\n");
12896 else
12897 vty_out(vty, " default not sent\n");
12898 }
12899
12900 /* advertise-vni-all */
12901 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12902 if (is_evpn_enabled())
12903 vty_out(vty, " advertise-all-vni\n");
12904 }
12905
12906 if (filter->plist[FILTER_IN].name
12907 || filter->dlist[FILTER_IN].name
12908 || filter->aslist[FILTER_IN].name
12909 || filter->map[RMAP_IN].name)
12910 vty_out(vty, " Inbound path policy configured\n");
12911 if (filter->plist[FILTER_OUT].name
12912 || filter->dlist[FILTER_OUT].name
12913 || filter->aslist[FILTER_OUT].name
12914 || filter->map[RMAP_OUT].name || filter->usmap.name)
12915 vty_out(vty, " Outbound path policy configured\n");
12916
12917 /* prefix-list */
12918 if (filter->plist[FILTER_IN].name)
12919 vty_out(vty,
12920 " Incoming update prefix filter list is %s%s\n",
12921 filter->plist[FILTER_IN].plist ? "*" : "",
12922 filter->plist[FILTER_IN].name);
12923 if (filter->plist[FILTER_OUT].name)
12924 vty_out(vty,
12925 " Outgoing update prefix filter list is %s%s\n",
12926 filter->plist[FILTER_OUT].plist ? "*" : "",
12927 filter->plist[FILTER_OUT].name);
12928
12929 /* distribute-list */
12930 if (filter->dlist[FILTER_IN].name)
12931 vty_out(vty,
12932 " Incoming update network filter list is %s%s\n",
12933 filter->dlist[FILTER_IN].alist ? "*" : "",
12934 filter->dlist[FILTER_IN].name);
12935 if (filter->dlist[FILTER_OUT].name)
12936 vty_out(vty,
12937 " Outgoing update network filter list is %s%s\n",
12938 filter->dlist[FILTER_OUT].alist ? "*" : "",
12939 filter->dlist[FILTER_OUT].name);
12940
12941 /* filter-list. */
12942 if (filter->aslist[FILTER_IN].name)
12943 vty_out(vty,
12944 " Incoming update AS path filter list is %s%s\n",
12945 filter->aslist[FILTER_IN].aslist ? "*" : "",
12946 filter->aslist[FILTER_IN].name);
12947 if (filter->aslist[FILTER_OUT].name)
12948 vty_out(vty,
12949 " Outgoing update AS path filter list is %s%s\n",
12950 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12951 filter->aslist[FILTER_OUT].name);
12952
12953 /* route-map. */
12954 if (filter->map[RMAP_IN].name)
12955 vty_out(vty,
12956 " Route map for incoming advertisements is %s%s\n",
12957 filter->map[RMAP_IN].map ? "*" : "",
12958 filter->map[RMAP_IN].name);
12959 if (filter->map[RMAP_OUT].name)
12960 vty_out(vty,
12961 " Route map for outgoing advertisements is %s%s\n",
12962 filter->map[RMAP_OUT].map ? "*" : "",
12963 filter->map[RMAP_OUT].name);
12964
12965 /* ebgp-requires-policy (inbound) */
12966 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12967 && !bgp_inbound_policy_exists(p, filter))
12968 vty_out(vty,
12969 " Inbound updates discarded due to missing policy\n");
12970
12971 /* ebgp-requires-policy (outbound) */
12972 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12973 && !bgp_outbound_policy_exists(p, filter))
12974 vty_out(vty,
12975 " Outbound updates discarded due to missing policy\n");
12976
12977 /* unsuppress-map */
12978 if (filter->usmap.name)
12979 vty_out(vty,
12980 " Route map for selective unsuppress is %s%s\n",
12981 filter->usmap.map ? "*" : "",
12982 filter->usmap.name);
12983
12984 /* advertise-map */
12985 if (filter->advmap.aname && filter->advmap.cname)
12986 vty_out(vty,
12987 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12988 filter->advmap.condition ? "EXIST"
12989 : "NON_EXIST",
12990 filter->advmap.cmap ? "*" : "",
12991 filter->advmap.cname,
12992 filter->advmap.amap ? "*" : "",
12993 filter->advmap.aname,
12994 filter->advmap.update_type ==
12995 UPDATE_TYPE_ADVERTISE
12996 ? "Advertise"
12997 : "Withdraw");
12998
12999 /* Receive prefix count */
13000 vty_out(vty, " %u accepted prefixes\n",
13001 p->pcount[afi][safi]);
13002
13003 /* maximum-prefix-out */
13004 if (CHECK_FLAG(p->af_flags[afi][safi],
13005 PEER_FLAG_MAX_PREFIX_OUT))
13006 vty_out(vty,
13007 " Maximum allowed prefixes sent %u\n",
13008 p->pmax_out[afi][safi]);
13009
13010 /* Maximum prefix */
13011 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
13012 vty_out(vty,
13013 " Maximum prefixes allowed %u%s\n",
13014 p->pmax[afi][safi],
13015 CHECK_FLAG(p->af_flags[afi][safi],
13016 PEER_FLAG_MAX_PREFIX_WARNING)
13017 ? " (warning-only)"
13018 : "");
13019 vty_out(vty, " Threshold for warning message %d%%",
13020 p->pmax_threshold[afi][safi]);
13021 if (p->pmax_restart[afi][safi])
13022 vty_out(vty, ", restart interval %d min",
13023 p->pmax_restart[afi][safi]);
13024 vty_out(vty, "\n");
13025 }
13026
13027 vty_out(vty, "\n");
13028 }
13029 }
13030
13031 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
13032 json_object *json)
13033 {
13034 struct bgp *bgp;
13035 char timebuf[BGP_UPTIME_LEN];
13036 char dn_flag[2];
13037 afi_t afi;
13038 safi_t safi;
13039 uint16_t i;
13040 uint8_t *msg;
13041 json_object *json_neigh = NULL;
13042 time_t epoch_tbuf;
13043 uint32_t sync_tcp_mss;
13044
13045 bgp = p->bgp;
13046
13047 if (use_json)
13048 json_neigh = json_object_new_object();
13049
13050 memset(dn_flag, '\0', sizeof(dn_flag));
13051 if (!p->conf_if && peer_dynamic_neighbor(p))
13052 dn_flag[0] = '*';
13053
13054 if (!use_json) {
13055 if (p->conf_if) /* Configured interface name. */
13056 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13057 &p->su);
13058 else /* Configured IP address. */
13059 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13060 p->host);
13061 }
13062
13063 if (use_json) {
13064 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13065 json_object_string_add(json_neigh, "bgpNeighborAddr",
13066 "none");
13067 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13068 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13069 "%pSU", &p->su);
13070
13071 json_object_int_add(json_neigh, "remoteAs", p->as);
13072
13073 if (p->change_local_as)
13074 json_object_int_add(json_neigh, "localAs",
13075 p->change_local_as);
13076 else
13077 json_object_int_add(json_neigh, "localAs", p->local_as);
13078
13079 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13080 json_object_boolean_true_add(json_neigh,
13081 "localAsNoPrepend");
13082
13083 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13084 json_object_boolean_true_add(json_neigh,
13085 "localAsReplaceAs");
13086 } else {
13087 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13088 || (p->as_type == AS_INTERNAL))
13089 vty_out(vty, "remote AS %u, ", p->as);
13090 else
13091 vty_out(vty, "remote AS Unspecified, ");
13092 vty_out(vty, "local AS %u%s%s, ",
13093 p->change_local_as ? p->change_local_as : p->local_as,
13094 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13095 ? " no-prepend"
13096 : "",
13097 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13098 ? " replace-as"
13099 : "");
13100 }
13101 /* peer type internal or confed-internal */
13102 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13103 if (use_json) {
13104 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13105 json_object_boolean_true_add(
13106 json_neigh, "nbrConfedInternalLink");
13107 else
13108 json_object_boolean_true_add(json_neigh,
13109 "nbrInternalLink");
13110 } else {
13111 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13112 vty_out(vty, "confed-internal link\n");
13113 else
13114 vty_out(vty, "internal link\n");
13115 }
13116 /* peer type external or confed-external */
13117 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13118 if (use_json) {
13119 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13120 json_object_boolean_true_add(
13121 json_neigh, "nbrConfedExternalLink");
13122 else
13123 json_object_boolean_true_add(json_neigh,
13124 "nbrExternalLink");
13125 } else {
13126 if (bgp_confederation_peers_check(bgp, p->as))
13127 vty_out(vty, "confed-external link\n");
13128 else
13129 vty_out(vty, "external link\n");
13130 }
13131 } else {
13132 if (use_json)
13133 json_object_boolean_true_add(json_neigh,
13134 "nbrUnspecifiedLink");
13135 else
13136 vty_out(vty, "unspecified link\n");
13137 }
13138
13139 /* Roles */
13140 if (use_json) {
13141 json_object_string_add(json_neigh, "localRole",
13142 bgp_get_name_by_role(p->local_role));
13143 json_object_string_add(json_neigh, "remoteRole",
13144 bgp_get_name_by_role(p->remote_role));
13145 } else {
13146 vty_out(vty, " Local Role: %s\n",
13147 bgp_get_name_by_role(p->local_role));
13148 vty_out(vty, " Remote Role: %s\n",
13149 bgp_get_name_by_role(p->remote_role));
13150 }
13151
13152
13153 /* Description. */
13154 if (p->desc) {
13155 if (use_json)
13156 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13157 else
13158 vty_out(vty, " Description: %s\n", p->desc);
13159 }
13160
13161 if (p->hostname) {
13162 if (use_json) {
13163 json_object_string_add(json_neigh, "hostname",
13164 p->hostname);
13165
13166 if (p->domainname)
13167 json_object_string_add(json_neigh, "domainname",
13168 p->domainname);
13169 } else {
13170 if (p->domainname && (p->domainname[0] != '\0'))
13171 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13172 p->domainname);
13173 else
13174 vty_out(vty, "Hostname: %s\n", p->hostname);
13175 }
13176 } else {
13177 if (use_json)
13178 json_object_string_add(json_neigh, "hostname",
13179 "Unknown");
13180 }
13181
13182 /* Peer-group */
13183 if (p->group) {
13184 if (use_json) {
13185 json_object_string_add(json_neigh, "peerGroup",
13186 p->group->name);
13187
13188 if (dn_flag[0]) {
13189 struct prefix prefix, *range = NULL;
13190
13191 if (sockunion2hostprefix(&(p->su), &prefix))
13192 range = peer_group_lookup_dynamic_neighbor_range(
13193 p->group, &prefix);
13194
13195 if (range) {
13196 json_object_string_addf(
13197 json_neigh,
13198 "peerSubnetRangeGroup", "%pFX",
13199 range);
13200 }
13201 }
13202 } else {
13203 vty_out(vty,
13204 " Member of peer-group %s for session parameters\n",
13205 p->group->name);
13206
13207 if (dn_flag[0]) {
13208 struct prefix prefix, *range = NULL;
13209
13210 if (sockunion2hostprefix(&(p->su), &prefix))
13211 range = peer_group_lookup_dynamic_neighbor_range(
13212 p->group, &prefix);
13213
13214 if (range) {
13215 vty_out(vty,
13216 " Belongs to the subnet range group: %pFX\n",
13217 range);
13218 }
13219 }
13220 }
13221 }
13222
13223 if (use_json) {
13224 /* Administrative shutdown. */
13225 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13226 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13227 json_object_boolean_true_add(json_neigh,
13228 "adminShutDown");
13229
13230 /* BGP Version. */
13231 json_object_int_add(json_neigh, "bgpVersion", 4);
13232 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13233 &p->remote_id);
13234 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13235 &bgp->router_id);
13236
13237 /* Confederation */
13238 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13239 && bgp_confederation_peers_check(bgp, p->as))
13240 json_object_boolean_true_add(json_neigh,
13241 "nbrCommonAdmin");
13242
13243 /* Status. */
13244 json_object_string_add(
13245 json_neigh, "bgpState",
13246 lookup_msg(bgp_status_msg, p->status, NULL));
13247
13248 if (peer_established(p)) {
13249 time_t uptime;
13250
13251 uptime = monotime(NULL);
13252 uptime -= p->uptime;
13253 epoch_tbuf = time(NULL) - uptime;
13254
13255 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13256 uptime * 1000);
13257 json_object_string_add(json_neigh, "bgpTimerUpString",
13258 peer_uptime(p->uptime, timebuf,
13259 BGP_UPTIME_LEN, 0,
13260 NULL));
13261 json_object_int_add(json_neigh,
13262 "bgpTimerUpEstablishedEpoch",
13263 epoch_tbuf);
13264 }
13265
13266 else if (p->status == Active) {
13267 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13268 json_object_string_add(json_neigh, "bgpStateIs",
13269 "passive");
13270 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13271 json_object_string_add(json_neigh, "bgpStateIs",
13272 "passiveNSF");
13273 }
13274
13275 /* read timer */
13276 time_t uptime;
13277 struct tm tm;
13278
13279 uptime = monotime(NULL);
13280 uptime -= p->readtime;
13281 gmtime_r(&uptime, &tm);
13282
13283 json_object_int_add(json_neigh, "bgpTimerLastRead",
13284 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13285 + (tm.tm_hour * 3600000));
13286
13287 uptime = monotime(NULL);
13288 uptime -= p->last_write;
13289 gmtime_r(&uptime, &tm);
13290
13291 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13292 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13293 + (tm.tm_hour * 3600000));
13294
13295 uptime = monotime(NULL);
13296 uptime -= p->update_time;
13297 gmtime_r(&uptime, &tm);
13298
13299 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13300 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13301 + (tm.tm_hour * 3600000));
13302
13303 /* Configured timer values. */
13304 json_object_int_add(json_neigh,
13305 "bgpTimerConfiguredHoldTimeMsecs",
13306 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13307 ? p->holdtime * 1000
13308 : bgp->default_holdtime * 1000);
13309 json_object_int_add(json_neigh,
13310 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13311 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13312 ? p->keepalive * 1000
13313 : bgp->default_keepalive * 1000);
13314 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13315 p->v_holdtime * 1000);
13316 json_object_int_add(json_neigh,
13317 "bgpTimerKeepAliveIntervalMsecs",
13318 p->v_keepalive * 1000);
13319 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13320 json_object_int_add(json_neigh,
13321 "bgpTimerDelayOpenTimeMsecs",
13322 p->v_delayopen * 1000);
13323 }
13324
13325 /* Configured and Synced tcp-mss value for peer */
13326 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13327 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13328 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13329 p->tcp_mss);
13330 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13331 sync_tcp_mss);
13332 }
13333
13334 /* Extended Optional Parameters Length for BGP OPEN Message */
13335 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13336 json_object_boolean_true_add(
13337 json_neigh, "extendedOptionalParametersLength");
13338 else
13339 json_object_boolean_false_add(
13340 json_neigh, "extendedOptionalParametersLength");
13341
13342 /* Conditional advertisements */
13343 json_object_int_add(
13344 json_neigh,
13345 "bgpTimerConfiguredConditionalAdvertisementsSec",
13346 bgp->condition_check_period);
13347 if (thread_is_scheduled(bgp->t_condition_check))
13348 json_object_int_add(
13349 json_neigh,
13350 "bgpTimerUntilConditionalAdvertisementsSec",
13351 thread_timer_remain_second(
13352 bgp->t_condition_check));
13353 } else {
13354 /* Administrative shutdown. */
13355 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13356 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13357 vty_out(vty, " Administratively shut down\n");
13358
13359 /* BGP Version. */
13360 vty_out(vty, " BGP version 4");
13361 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13362 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13363
13364 /* Confederation */
13365 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13366 && bgp_confederation_peers_check(bgp, p->as))
13367 vty_out(vty,
13368 " Neighbor under common administration\n");
13369
13370 /* Status. */
13371 vty_out(vty, " BGP state = %s",
13372 lookup_msg(bgp_status_msg, p->status, NULL));
13373
13374 if (peer_established(p))
13375 vty_out(vty, ", up for %8s",
13376 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13377 0, NULL));
13378
13379 else if (p->status == Active) {
13380 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13381 vty_out(vty, " (passive)");
13382 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13383 vty_out(vty, " (NSF passive)");
13384 }
13385 vty_out(vty, "\n");
13386
13387 /* read timer */
13388 vty_out(vty, " Last read %s",
13389 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13390 NULL));
13391 vty_out(vty, ", Last write %s\n",
13392 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13393 NULL));
13394
13395 /* Configured timer values. */
13396 vty_out(vty,
13397 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13398 p->v_holdtime, p->v_keepalive);
13399 vty_out(vty, " Configured hold time is %d seconds",
13400 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13401 ? p->holdtime
13402 : bgp->default_holdtime);
13403 vty_out(vty, ", keepalive interval is %d seconds\n",
13404 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13405 ? p->keepalive
13406 : bgp->default_keepalive);
13407 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13408 vty_out(vty,
13409 " Configured DelayOpenTime is %d seconds\n",
13410 p->delayopen);
13411
13412 /* Configured and synced tcp-mss value for peer */
13413 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13414 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13415 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13416 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13417 }
13418
13419 /* Extended Optional Parameters Length for BGP OPEN Message */
13420 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13421 vty_out(vty,
13422 " Extended Optional Parameters Length is enabled\n");
13423
13424 /* Conditional advertisements */
13425 vty_out(vty,
13426 " Configured conditional advertisements interval is %d seconds\n",
13427 bgp->condition_check_period);
13428 if (thread_is_scheduled(bgp->t_condition_check))
13429 vty_out(vty,
13430 " Time until conditional advertisements begin is %lu seconds\n",
13431 thread_timer_remain_second(
13432 bgp->t_condition_check));
13433 }
13434 /* Capability. */
13435 if (peer_established(p) &&
13436 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13437 if (use_json) {
13438 json_object *json_cap = NULL;
13439
13440 json_cap = json_object_new_object();
13441
13442 /* AS4 */
13443 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13444 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13445 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13446 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13447 json_object_string_add(
13448 json_cap, "4byteAs",
13449 "advertisedAndReceived");
13450 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13451 json_object_string_add(json_cap,
13452 "4byteAs",
13453 "advertised");
13454 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13455 json_object_string_add(json_cap,
13456 "4byteAs",
13457 "received");
13458 }
13459
13460 /* Extended Message Support */
13461 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13462 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13463 json_object_string_add(json_cap,
13464 "extendedMessage",
13465 "advertisedAndReceived");
13466 else if (CHECK_FLAG(p->cap,
13467 PEER_CAP_EXTENDED_MESSAGE_ADV))
13468 json_object_string_add(json_cap,
13469 "extendedMessage",
13470 "advertised");
13471 else if (CHECK_FLAG(p->cap,
13472 PEER_CAP_EXTENDED_MESSAGE_RCV))
13473 json_object_string_add(json_cap,
13474 "extendedMessage",
13475 "received");
13476
13477 /* AddPath */
13478 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13479 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13480 json_object *json_add = NULL;
13481 const char *print_store;
13482
13483 json_add = json_object_new_object();
13484
13485 FOREACH_AFI_SAFI (afi, safi) {
13486 json_object *json_sub = NULL;
13487 json_sub = json_object_new_object();
13488 print_store = get_afi_safi_str(
13489 afi, safi, true);
13490
13491 if (CHECK_FLAG(
13492 p->af_cap[afi][safi],
13493 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13494 CHECK_FLAG(
13495 p->af_cap[afi][safi],
13496 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13497 if (CHECK_FLAG(
13498 p->af_cap[afi]
13499 [safi],
13500 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13501 CHECK_FLAG(
13502 p->af_cap[afi]
13503 [safi],
13504 PEER_CAP_ADDPATH_AF_TX_RCV))
13505 json_object_boolean_true_add(
13506 json_sub,
13507 "txAdvertisedAndReceived");
13508 else if (
13509 CHECK_FLAG(
13510 p->af_cap[afi]
13511 [safi],
13512 PEER_CAP_ADDPATH_AF_TX_ADV))
13513 json_object_boolean_true_add(
13514 json_sub,
13515 "txAdvertised");
13516 else if (
13517 CHECK_FLAG(
13518 p->af_cap[afi]
13519 [safi],
13520 PEER_CAP_ADDPATH_AF_TX_RCV))
13521 json_object_boolean_true_add(
13522 json_sub,
13523 "txReceived");
13524 }
13525
13526 if (CHECK_FLAG(
13527 p->af_cap[afi][safi],
13528 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13529 CHECK_FLAG(
13530 p->af_cap[afi][safi],
13531 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13532 if (CHECK_FLAG(
13533 p->af_cap[afi]
13534 [safi],
13535 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13536 CHECK_FLAG(
13537 p->af_cap[afi]
13538 [safi],
13539 PEER_CAP_ADDPATH_AF_RX_RCV))
13540 json_object_boolean_true_add(
13541 json_sub,
13542 "rxAdvertisedAndReceived");
13543 else if (
13544 CHECK_FLAG(
13545 p->af_cap[afi]
13546 [safi],
13547 PEER_CAP_ADDPATH_AF_RX_ADV))
13548 json_object_boolean_true_add(
13549 json_sub,
13550 "rxAdvertised");
13551 else if (
13552 CHECK_FLAG(
13553 p->af_cap[afi]
13554 [safi],
13555 PEER_CAP_ADDPATH_AF_RX_RCV))
13556 json_object_boolean_true_add(
13557 json_sub,
13558 "rxReceived");
13559 }
13560
13561 if (CHECK_FLAG(
13562 p->af_cap[afi][safi],
13563 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13564 CHECK_FLAG(
13565 p->af_cap[afi][safi],
13566 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13567 CHECK_FLAG(
13568 p->af_cap[afi][safi],
13569 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13570 CHECK_FLAG(
13571 p->af_cap[afi][safi],
13572 PEER_CAP_ADDPATH_AF_RX_RCV))
13573 json_object_object_add(
13574 json_add, print_store,
13575 json_sub);
13576 else
13577 json_object_free(json_sub);
13578 }
13579
13580 json_object_object_add(json_cap, "addPath",
13581 json_add);
13582 }
13583
13584 /* Dynamic */
13585 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13586 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13587 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13588 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13589 json_object_string_add(
13590 json_cap, "dynamic",
13591 "advertisedAndReceived");
13592 else if (CHECK_FLAG(p->cap,
13593 PEER_CAP_DYNAMIC_ADV))
13594 json_object_string_add(json_cap,
13595 "dynamic",
13596 "advertised");
13597 else if (CHECK_FLAG(p->cap,
13598 PEER_CAP_DYNAMIC_RCV))
13599 json_object_string_add(json_cap,
13600 "dynamic",
13601 "received");
13602 }
13603
13604 /* Role */
13605 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13606 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13607 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13608 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13609 json_object_string_add(
13610 json_cap, "role",
13611 "advertisedAndReceived");
13612 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13613 json_object_string_add(json_cap, "role",
13614 "advertised");
13615 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13616 json_object_string_add(json_cap, "role",
13617 "received");
13618 }
13619
13620 /* Extended nexthop */
13621 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13622 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13623 json_object *json_nxt = NULL;
13624 const char *print_store;
13625
13626
13627 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13628 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13629 json_object_string_add(
13630 json_cap, "extendedNexthop",
13631 "advertisedAndReceived");
13632 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13633 json_object_string_add(
13634 json_cap, "extendedNexthop",
13635 "advertised");
13636 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13637 json_object_string_add(
13638 json_cap, "extendedNexthop",
13639 "received");
13640
13641 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13642 json_nxt = json_object_new_object();
13643
13644 for (safi = SAFI_UNICAST;
13645 safi < SAFI_MAX; safi++) {
13646 if (CHECK_FLAG(
13647 p->af_cap[AFI_IP]
13648 [safi],
13649 PEER_CAP_ENHE_AF_RCV)) {
13650 print_store =
13651 get_afi_safi_str(
13652 AFI_IP,
13653 safi,
13654 true);
13655 json_object_string_add(
13656 json_nxt,
13657 print_store,
13658 "recieved"); /* misspelled for compatibility */
13659 }
13660 }
13661 json_object_object_add(
13662 json_cap,
13663 "extendedNexthopFamililesByPeer",
13664 json_nxt);
13665 }
13666 }
13667
13668 /* Long-lived Graceful Restart */
13669 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13670 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13671 json_object *json_llgr = NULL;
13672 const char *afi_safi_str;
13673
13674 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13675 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13676 json_object_string_add(
13677 json_cap,
13678 "longLivedGracefulRestart",
13679 "advertisedAndReceived");
13680 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13681 json_object_string_add(
13682 json_cap,
13683 "longLivedGracefulRestart",
13684 "advertised");
13685 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13686 json_object_string_add(
13687 json_cap,
13688 "longLivedGracefulRestart",
13689 "received");
13690
13691 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13692 json_llgr = json_object_new_object();
13693
13694 FOREACH_AFI_SAFI (afi, safi) {
13695 if (CHECK_FLAG(
13696 p->af_cap[afi]
13697 [safi],
13698 PEER_CAP_ENHE_AF_RCV)) {
13699 afi_safi_str =
13700 get_afi_safi_str(
13701 afi,
13702 safi,
13703 true);
13704 json_object_string_add(
13705 json_llgr,
13706 afi_safi_str,
13707 "received");
13708 }
13709 }
13710 json_object_object_add(
13711 json_cap,
13712 "longLivedGracefulRestartByPeer",
13713 json_llgr);
13714 }
13715 }
13716
13717 /* Route Refresh */
13718 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13719 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13720 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13721 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13722 (CHECK_FLAG(p->cap,
13723 PEER_CAP_REFRESH_NEW_RCV) ||
13724 CHECK_FLAG(p->cap,
13725 PEER_CAP_REFRESH_OLD_RCV))) {
13726 if (CHECK_FLAG(
13727 p->cap,
13728 PEER_CAP_REFRESH_OLD_RCV) &&
13729 CHECK_FLAG(
13730 p->cap,
13731 PEER_CAP_REFRESH_NEW_RCV))
13732 json_object_string_add(
13733 json_cap,
13734 "routeRefresh",
13735 "advertisedAndReceivedOldNew");
13736 else {
13737 if (CHECK_FLAG(
13738 p->cap,
13739 PEER_CAP_REFRESH_OLD_RCV))
13740 json_object_string_add(
13741 json_cap,
13742 "routeRefresh",
13743 "advertisedAndReceivedOld");
13744 else
13745 json_object_string_add(
13746 json_cap,
13747 "routeRefresh",
13748 "advertisedAndReceivedNew");
13749 }
13750 } else if (CHECK_FLAG(p->cap,
13751 PEER_CAP_REFRESH_ADV))
13752 json_object_string_add(json_cap,
13753 "routeRefresh",
13754 "advertised");
13755 else if (CHECK_FLAG(p->cap,
13756 PEER_CAP_REFRESH_NEW_RCV) ||
13757 CHECK_FLAG(p->cap,
13758 PEER_CAP_REFRESH_OLD_RCV))
13759 json_object_string_add(json_cap,
13760 "routeRefresh",
13761 "received");
13762 }
13763
13764 /* Enhanced Route Refresh */
13765 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13766 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13767 if (CHECK_FLAG(p->cap,
13768 PEER_CAP_ENHANCED_RR_ADV) &&
13769 CHECK_FLAG(p->cap,
13770 PEER_CAP_ENHANCED_RR_RCV))
13771 json_object_string_add(
13772 json_cap,
13773 "enhancedRouteRefresh",
13774 "advertisedAndReceived");
13775 else if (CHECK_FLAG(p->cap,
13776 PEER_CAP_ENHANCED_RR_ADV))
13777 json_object_string_add(
13778 json_cap,
13779 "enhancedRouteRefresh",
13780 "advertised");
13781 else if (CHECK_FLAG(p->cap,
13782 PEER_CAP_ENHANCED_RR_RCV))
13783 json_object_string_add(
13784 json_cap,
13785 "enhancedRouteRefresh",
13786 "received");
13787 }
13788
13789 /* Multiprotocol Extensions */
13790 json_object *json_multi = NULL;
13791
13792 json_multi = json_object_new_object();
13793
13794 FOREACH_AFI_SAFI (afi, safi) {
13795 if (p->afc_adv[afi][safi] ||
13796 p->afc_recv[afi][safi]) {
13797 json_object *json_exten = NULL;
13798 json_exten = json_object_new_object();
13799
13800 if (p->afc_adv[afi][safi] &&
13801 p->afc_recv[afi][safi])
13802 json_object_boolean_true_add(
13803 json_exten,
13804 "advertisedAndReceived");
13805 else if (p->afc_adv[afi][safi])
13806 json_object_boolean_true_add(
13807 json_exten,
13808 "advertised");
13809 else if (p->afc_recv[afi][safi])
13810 json_object_boolean_true_add(
13811 json_exten, "received");
13812
13813 json_object_object_add(
13814 json_multi,
13815 get_afi_safi_str(afi, safi,
13816 true),
13817 json_exten);
13818 }
13819 }
13820 json_object_object_add(json_cap,
13821 "multiprotocolExtensions",
13822 json_multi);
13823
13824 /* Hostname capabilities */
13825 json_object *json_hname = NULL;
13826
13827 json_hname = json_object_new_object();
13828
13829 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13830 json_object_string_add(
13831 json_hname, "advHostName",
13832 bgp->peer_self->hostname
13833 ? bgp->peer_self->hostname
13834 : "n/a");
13835 json_object_string_add(
13836 json_hname, "advDomainName",
13837 bgp->peer_self->domainname
13838 ? bgp->peer_self->domainname
13839 : "n/a");
13840 }
13841
13842
13843 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13844 json_object_string_add(
13845 json_hname, "rcvHostName",
13846 p->hostname ? p->hostname : "n/a");
13847 json_object_string_add(
13848 json_hname, "rcvDomainName",
13849 p->domainname ? p->domainname : "n/a");
13850 }
13851
13852 json_object_object_add(json_cap, "hostName",
13853 json_hname);
13854
13855 /* Graceful Restart */
13856 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13857 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13858 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13859 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13860 json_object_string_add(
13861 json_cap, "gracefulRestart",
13862 "advertisedAndReceived");
13863 else if (CHECK_FLAG(p->cap,
13864 PEER_CAP_RESTART_ADV))
13865 json_object_string_add(
13866 json_cap,
13867 "gracefulRestartCapability",
13868 "advertised");
13869 else if (CHECK_FLAG(p->cap,
13870 PEER_CAP_RESTART_RCV))
13871 json_object_string_add(
13872 json_cap,
13873 "gracefulRestartCapability",
13874 "received");
13875
13876 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13877 int restart_af_count = 0;
13878 json_object *json_restart = NULL;
13879 json_restart = json_object_new_object();
13880
13881 json_object_int_add(
13882 json_cap,
13883 "gracefulRestartRemoteTimerMsecs",
13884 p->v_gr_restart * 1000);
13885
13886 FOREACH_AFI_SAFI (afi, safi) {
13887 if (CHECK_FLAG(
13888 p->af_cap[afi]
13889 [safi],
13890 PEER_CAP_RESTART_AF_RCV)) {
13891 json_object *json_sub =
13892 NULL;
13893 json_sub =
13894 json_object_new_object();
13895
13896 if (CHECK_FLAG(
13897 p->af_cap
13898 [afi]
13899 [safi],
13900 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13901 json_object_boolean_true_add(
13902 json_sub,
13903 "preserved");
13904 restart_af_count++;
13905 json_object_object_add(
13906 json_restart,
13907 get_afi_safi_str(
13908 afi,
13909 safi,
13910 true),
13911 json_sub);
13912 }
13913 }
13914 if (!restart_af_count) {
13915 json_object_string_add(
13916 json_cap,
13917 "addressFamiliesByPeer",
13918 "none");
13919 json_object_free(json_restart);
13920 } else
13921 json_object_object_add(
13922 json_cap,
13923 "addressFamiliesByPeer",
13924 json_restart);
13925 }
13926 }
13927 json_object_object_add(
13928 json_neigh, "neighborCapabilities", json_cap);
13929 } else {
13930 vty_out(vty, " Neighbor capabilities:\n");
13931
13932 /* AS4 */
13933 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13934 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13935 vty_out(vty, " 4 Byte AS:");
13936 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13937 vty_out(vty, " advertised");
13938 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13939 vty_out(vty, " %sreceived",
13940 CHECK_FLAG(p->cap,
13941 PEER_CAP_AS4_ADV)
13942 ? "and "
13943 : "");
13944 vty_out(vty, "\n");
13945 }
13946
13947 /* Extended Message Support */
13948 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13949 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13950 vty_out(vty, " Extended Message:");
13951 if (CHECK_FLAG(p->cap,
13952 PEER_CAP_EXTENDED_MESSAGE_ADV))
13953 vty_out(vty, " advertised");
13954 if (CHECK_FLAG(p->cap,
13955 PEER_CAP_EXTENDED_MESSAGE_RCV))
13956 vty_out(vty, " %sreceived",
13957 CHECK_FLAG(
13958 p->cap,
13959 PEER_CAP_EXTENDED_MESSAGE_ADV)
13960 ? "and "
13961 : "");
13962 vty_out(vty, "\n");
13963 }
13964
13965 /* AddPath */
13966 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13967 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13968 vty_out(vty, " AddPath:\n");
13969
13970 FOREACH_AFI_SAFI (afi, safi) {
13971 if (CHECK_FLAG(
13972 p->af_cap[afi][safi],
13973 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13974 CHECK_FLAG(
13975 p->af_cap[afi][safi],
13976 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13977 vty_out(vty, " %s: TX ",
13978 get_afi_safi_str(
13979 afi, safi,
13980 false));
13981
13982 if (CHECK_FLAG(
13983 p->af_cap[afi]
13984 [safi],
13985 PEER_CAP_ADDPATH_AF_TX_ADV))
13986 vty_out(vty,
13987 "advertised");
13988
13989 if (CHECK_FLAG(
13990 p->af_cap[afi]
13991 [safi],
13992 PEER_CAP_ADDPATH_AF_TX_RCV))
13993 vty_out(vty,
13994 "%sreceived",
13995 CHECK_FLAG(
13996 p->af_cap
13997 [afi]
13998 [safi],
13999 PEER_CAP_ADDPATH_AF_TX_ADV)
14000 ? " and "
14001 : "");
14002
14003 vty_out(vty, "\n");
14004 }
14005
14006 if (CHECK_FLAG(
14007 p->af_cap[afi][safi],
14008 PEER_CAP_ADDPATH_AF_RX_ADV) ||
14009 CHECK_FLAG(
14010 p->af_cap[afi][safi],
14011 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14012 vty_out(vty, " %s: RX ",
14013 get_afi_safi_str(
14014 afi, safi,
14015 false));
14016
14017 if (CHECK_FLAG(
14018 p->af_cap[afi]
14019 [safi],
14020 PEER_CAP_ADDPATH_AF_RX_ADV))
14021 vty_out(vty,
14022 "advertised");
14023
14024 if (CHECK_FLAG(
14025 p->af_cap[afi]
14026 [safi],
14027 PEER_CAP_ADDPATH_AF_RX_RCV))
14028 vty_out(vty,
14029 "%sreceived",
14030 CHECK_FLAG(
14031 p->af_cap
14032 [afi]
14033 [safi],
14034 PEER_CAP_ADDPATH_AF_RX_ADV)
14035 ? " and "
14036 : "");
14037
14038 vty_out(vty, "\n");
14039 }
14040 }
14041 }
14042
14043 /* Dynamic */
14044 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
14045 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
14046 vty_out(vty, " Dynamic:");
14047 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
14048 vty_out(vty, " advertised");
14049 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
14050 vty_out(vty, " %sreceived",
14051 CHECK_FLAG(p->cap,
14052 PEER_CAP_DYNAMIC_ADV)
14053 ? "and "
14054 : "");
14055 vty_out(vty, "\n");
14056 }
14057
14058 /* Role */
14059 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14060 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14061 vty_out(vty, " Role:");
14062 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14063 vty_out(vty, " advertised");
14064 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14065 vty_out(vty, " %sreceived",
14066 CHECK_FLAG(p->cap,
14067 PEER_CAP_ROLE_ADV)
14068 ? "and "
14069 : "");
14070 vty_out(vty, "\n");
14071 }
14072
14073 /* Extended nexthop */
14074 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14075 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14076 vty_out(vty, " Extended nexthop:");
14077 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14078 vty_out(vty, " advertised");
14079 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14080 vty_out(vty, " %sreceived",
14081 CHECK_FLAG(p->cap,
14082 PEER_CAP_ENHE_ADV)
14083 ? "and "
14084 : "");
14085 vty_out(vty, "\n");
14086
14087 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
14088 vty_out(vty,
14089 " Address families by peer:\n ");
14090 for (safi = SAFI_UNICAST;
14091 safi < SAFI_MAX; safi++)
14092 if (CHECK_FLAG(
14093 p->af_cap[AFI_IP]
14094 [safi],
14095 PEER_CAP_ENHE_AF_RCV))
14096 vty_out(vty,
14097 " %s\n",
14098 get_afi_safi_str(
14099 AFI_IP,
14100 safi,
14101 false));
14102 }
14103 }
14104
14105 /* Long-lived Graceful Restart */
14106 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14107 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14108 vty_out(vty,
14109 " Long-lived Graceful Restart:");
14110 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14111 vty_out(vty, " advertised");
14112 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14113 vty_out(vty, " %sreceived",
14114 CHECK_FLAG(p->cap,
14115 PEER_CAP_LLGR_ADV)
14116 ? "and "
14117 : "");
14118 vty_out(vty, "\n");
14119
14120 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
14121 vty_out(vty,
14122 " Address families by peer:\n");
14123 FOREACH_AFI_SAFI (afi, safi)
14124 if (CHECK_FLAG(
14125 p->af_cap[afi]
14126 [safi],
14127 PEER_CAP_LLGR_AF_RCV))
14128 vty_out(vty,
14129 " %s\n",
14130 get_afi_safi_str(
14131 afi,
14132 safi,
14133 false));
14134 }
14135 }
14136
14137 /* Route Refresh */
14138 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14139 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14140 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14141 vty_out(vty, " Route refresh:");
14142 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14143 vty_out(vty, " advertised");
14144 if (CHECK_FLAG(p->cap,
14145 PEER_CAP_REFRESH_NEW_RCV) ||
14146 CHECK_FLAG(p->cap,
14147 PEER_CAP_REFRESH_OLD_RCV))
14148 vty_out(vty, " %sreceived(%s)",
14149 CHECK_FLAG(p->cap,
14150 PEER_CAP_REFRESH_ADV)
14151 ? "and "
14152 : "",
14153 (CHECK_FLAG(
14154 p->cap,
14155 PEER_CAP_REFRESH_OLD_RCV) &&
14156 CHECK_FLAG(
14157 p->cap,
14158 PEER_CAP_REFRESH_NEW_RCV))
14159 ? "old & new"
14160 : CHECK_FLAG(
14161 p->cap,
14162 PEER_CAP_REFRESH_OLD_RCV)
14163 ? "old"
14164 : "new");
14165
14166 vty_out(vty, "\n");
14167 }
14168
14169 /* Enhanced Route Refresh */
14170 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14171 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14172 vty_out(vty, " Enhanced Route Refresh:");
14173 if (CHECK_FLAG(p->cap,
14174 PEER_CAP_ENHANCED_RR_ADV))
14175 vty_out(vty, " advertised");
14176 if (CHECK_FLAG(p->cap,
14177 PEER_CAP_ENHANCED_RR_RCV))
14178 vty_out(vty, " %sreceived",
14179 CHECK_FLAG(p->cap,
14180 PEER_CAP_REFRESH_ADV)
14181 ? "and "
14182 : "");
14183 vty_out(vty, "\n");
14184 }
14185
14186 /* Multiprotocol Extensions */
14187 FOREACH_AFI_SAFI (afi, safi)
14188 if (p->afc_adv[afi][safi] ||
14189 p->afc_recv[afi][safi]) {
14190 vty_out(vty, " Address Family %s:",
14191 get_afi_safi_str(afi, safi,
14192 false));
14193 if (p->afc_adv[afi][safi])
14194 vty_out(vty, " advertised");
14195 if (p->afc_recv[afi][safi])
14196 vty_out(vty, " %sreceived",
14197 p->afc_adv[afi][safi]
14198 ? "and "
14199 : "");
14200 vty_out(vty, "\n");
14201 }
14202
14203 /* Hostname capability */
14204 vty_out(vty, " Hostname Capability:");
14205
14206 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14207 vty_out(vty,
14208 " advertised (name: %s,domain name: %s)",
14209 bgp->peer_self->hostname
14210 ? bgp->peer_self->hostname
14211 : "n/a",
14212 bgp->peer_self->domainname
14213 ? bgp->peer_self->domainname
14214 : "n/a");
14215 } else {
14216 vty_out(vty, " not advertised");
14217 }
14218
14219 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14220 vty_out(vty,
14221 " received (name: %s,domain name: %s)",
14222 p->hostname ? p->hostname : "n/a",
14223 p->domainname ? p->domainname : "n/a");
14224 } else {
14225 vty_out(vty, " not received");
14226 }
14227
14228 vty_out(vty, "\n");
14229
14230 /* Graceful Restart */
14231 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14232 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14233 vty_out(vty,
14234 " Graceful Restart Capability:");
14235 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14236 vty_out(vty, " advertised");
14237 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14238 vty_out(vty, " %sreceived",
14239 CHECK_FLAG(p->cap,
14240 PEER_CAP_RESTART_ADV)
14241 ? "and "
14242 : "");
14243 vty_out(vty, "\n");
14244
14245 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14246 int restart_af_count = 0;
14247
14248 vty_out(vty,
14249 " Remote Restart timer is %d seconds\n",
14250 p->v_gr_restart);
14251 vty_out(vty,
14252 " Address families by peer:\n ");
14253
14254 FOREACH_AFI_SAFI (afi, safi)
14255 if (CHECK_FLAG(
14256 p->af_cap[afi]
14257 [safi],
14258 PEER_CAP_RESTART_AF_RCV)) {
14259 vty_out(vty, "%s%s(%s)",
14260 restart_af_count
14261 ? ", "
14262 : "",
14263 get_afi_safi_str(
14264 afi,
14265 safi,
14266 false),
14267 CHECK_FLAG(
14268 p->af_cap
14269 [afi]
14270 [safi],
14271 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14272 ? "preserved"
14273 : "not preserved");
14274 restart_af_count++;
14275 }
14276 if (!restart_af_count)
14277 vty_out(vty, "none");
14278 vty_out(vty, "\n");
14279 }
14280 } /* Graceful Restart */
14281 }
14282 }
14283
14284 /* graceful restart information */
14285 json_object *json_grace = NULL;
14286 json_object *json_grace_send = NULL;
14287 json_object *json_grace_recv = NULL;
14288 int eor_send_af_count = 0;
14289 int eor_receive_af_count = 0;
14290
14291 if (use_json) {
14292 json_grace = json_object_new_object();
14293 json_grace_send = json_object_new_object();
14294 json_grace_recv = json_object_new_object();
14295
14296 if ((peer_established(p)) &&
14297 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14298 FOREACH_AFI_SAFI (afi, safi) {
14299 if (CHECK_FLAG(p->af_sflags[afi][safi],
14300 PEER_STATUS_EOR_SEND)) {
14301 json_object_boolean_true_add(
14302 json_grace_send,
14303 get_afi_safi_str(afi, safi,
14304 true));
14305 eor_send_af_count++;
14306 }
14307 }
14308 FOREACH_AFI_SAFI (afi, safi) {
14309 if (CHECK_FLAG(p->af_sflags[afi][safi],
14310 PEER_STATUS_EOR_RECEIVED)) {
14311 json_object_boolean_true_add(
14312 json_grace_recv,
14313 get_afi_safi_str(afi, safi,
14314 true));
14315 eor_receive_af_count++;
14316 }
14317 }
14318 }
14319 json_object_object_add(json_grace, "endOfRibSend",
14320 json_grace_send);
14321 json_object_object_add(json_grace, "endOfRibRecv",
14322 json_grace_recv);
14323
14324
14325 if (p->t_gr_restart)
14326 json_object_int_add(
14327 json_grace, "gracefulRestartTimerMsecs",
14328 thread_timer_remain_second(p->t_gr_restart) *
14329 1000);
14330
14331 if (p->t_gr_stale)
14332 json_object_int_add(
14333 json_grace, "gracefulStalepathTimerMsecs",
14334 thread_timer_remain_second(p->t_gr_stale) *
14335 1000);
14336 /* more gr info in new format */
14337 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14338 json_object_object_add(json_neigh, "gracefulRestartInfo",
14339 json_grace);
14340 } else {
14341 vty_out(vty, " Graceful restart information:\n");
14342 if ((peer_established(p)) &&
14343 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14344
14345 vty_out(vty, " End-of-RIB send: ");
14346 FOREACH_AFI_SAFI (afi, safi) {
14347 if (CHECK_FLAG(p->af_sflags[afi][safi],
14348 PEER_STATUS_EOR_SEND)) {
14349 vty_out(vty, "%s%s",
14350 eor_send_af_count ? ", " : "",
14351 get_afi_safi_str(afi, safi,
14352 false));
14353 eor_send_af_count++;
14354 }
14355 }
14356 vty_out(vty, "\n");
14357 vty_out(vty, " End-of-RIB received: ");
14358 FOREACH_AFI_SAFI (afi, safi) {
14359 if (CHECK_FLAG(p->af_sflags[afi][safi],
14360 PEER_STATUS_EOR_RECEIVED)) {
14361 vty_out(vty, "%s%s",
14362 eor_receive_af_count ? ", "
14363 : "",
14364 get_afi_safi_str(afi, safi,
14365 false));
14366 eor_receive_af_count++;
14367 }
14368 }
14369 vty_out(vty, "\n");
14370 }
14371
14372 if (p->t_gr_restart)
14373 vty_out(vty,
14374 " The remaining time of restart timer is %ld\n",
14375 thread_timer_remain_second(p->t_gr_restart));
14376
14377 if (p->t_gr_stale)
14378 vty_out(vty,
14379 " The remaining time of stalepath timer is %ld\n",
14380 thread_timer_remain_second(p->t_gr_stale));
14381
14382 /* more gr info in new format */
14383 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14384 }
14385
14386 if (use_json) {
14387 json_object *json_stat = NULL;
14388 json_stat = json_object_new_object();
14389 /* Packet counts. */
14390
14391 atomic_size_t outq_count, inq_count;
14392 outq_count = atomic_load_explicit(&p->obuf->count,
14393 memory_order_relaxed);
14394 inq_count = atomic_load_explicit(&p->ibuf->count,
14395 memory_order_relaxed);
14396
14397 json_object_int_add(json_stat, "depthInq",
14398 (unsigned long)inq_count);
14399 json_object_int_add(json_stat, "depthOutq",
14400 (unsigned long)outq_count);
14401 json_object_int_add(json_stat, "opensSent",
14402 atomic_load_explicit(&p->open_out,
14403 memory_order_relaxed));
14404 json_object_int_add(json_stat, "opensRecv",
14405 atomic_load_explicit(&p->open_in,
14406 memory_order_relaxed));
14407 json_object_int_add(json_stat, "notificationsSent",
14408 atomic_load_explicit(&p->notify_out,
14409 memory_order_relaxed));
14410 json_object_int_add(json_stat, "notificationsRecv",
14411 atomic_load_explicit(&p->notify_in,
14412 memory_order_relaxed));
14413 json_object_int_add(json_stat, "updatesSent",
14414 atomic_load_explicit(&p->update_out,
14415 memory_order_relaxed));
14416 json_object_int_add(json_stat, "updatesRecv",
14417 atomic_load_explicit(&p->update_in,
14418 memory_order_relaxed));
14419 json_object_int_add(json_stat, "keepalivesSent",
14420 atomic_load_explicit(&p->keepalive_out,
14421 memory_order_relaxed));
14422 json_object_int_add(json_stat, "keepalivesRecv",
14423 atomic_load_explicit(&p->keepalive_in,
14424 memory_order_relaxed));
14425 json_object_int_add(json_stat, "routeRefreshSent",
14426 atomic_load_explicit(&p->refresh_out,
14427 memory_order_relaxed));
14428 json_object_int_add(json_stat, "routeRefreshRecv",
14429 atomic_load_explicit(&p->refresh_in,
14430 memory_order_relaxed));
14431 json_object_int_add(json_stat, "capabilitySent",
14432 atomic_load_explicit(&p->dynamic_cap_out,
14433 memory_order_relaxed));
14434 json_object_int_add(json_stat, "capabilityRecv",
14435 atomic_load_explicit(&p->dynamic_cap_in,
14436 memory_order_relaxed));
14437 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14438 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14439 json_object_object_add(json_neigh, "messageStats", json_stat);
14440 } else {
14441 atomic_size_t outq_count, inq_count, open_out, open_in,
14442 notify_out, notify_in, update_out, update_in,
14443 keepalive_out, keepalive_in, refresh_out, refresh_in,
14444 dynamic_cap_out, dynamic_cap_in;
14445 outq_count = atomic_load_explicit(&p->obuf->count,
14446 memory_order_relaxed);
14447 inq_count = atomic_load_explicit(&p->ibuf->count,
14448 memory_order_relaxed);
14449 open_out = atomic_load_explicit(&p->open_out,
14450 memory_order_relaxed);
14451 open_in =
14452 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14453 notify_out = atomic_load_explicit(&p->notify_out,
14454 memory_order_relaxed);
14455 notify_in = atomic_load_explicit(&p->notify_in,
14456 memory_order_relaxed);
14457 update_out = atomic_load_explicit(&p->update_out,
14458 memory_order_relaxed);
14459 update_in = atomic_load_explicit(&p->update_in,
14460 memory_order_relaxed);
14461 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14462 memory_order_relaxed);
14463 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14464 memory_order_relaxed);
14465 refresh_out = atomic_load_explicit(&p->refresh_out,
14466 memory_order_relaxed);
14467 refresh_in = atomic_load_explicit(&p->refresh_in,
14468 memory_order_relaxed);
14469 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14470 memory_order_relaxed);
14471 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14472 memory_order_relaxed);
14473
14474 /* Packet counts. */
14475 vty_out(vty, " Message statistics:\n");
14476 vty_out(vty, " Inq depth is %zu\n", inq_count);
14477 vty_out(vty, " Outq depth is %zu\n", outq_count);
14478 vty_out(vty, " Sent Rcvd\n");
14479 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14480 open_in);
14481 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14482 notify_in);
14483 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14484 update_in);
14485 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14486 keepalive_in);
14487 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14488 refresh_in);
14489 vty_out(vty, " Capability: %10zu %10zu\n",
14490 dynamic_cap_out, dynamic_cap_in);
14491 vty_out(vty, " Total: %10u %10u\n",
14492 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14493 }
14494
14495 if (use_json) {
14496 /* advertisement-interval */
14497 json_object_int_add(json_neigh,
14498 "minBtwnAdvertisementRunsTimerMsecs",
14499 p->v_routeadv * 1000);
14500
14501 /* Update-source. */
14502 if (p->update_if || p->update_source) {
14503 if (p->update_if)
14504 json_object_string_add(json_neigh,
14505 "updateSource",
14506 p->update_if);
14507 else if (p->update_source)
14508 json_object_string_addf(json_neigh,
14509 "updateSource", "%pSU",
14510 p->update_source);
14511 }
14512 } else {
14513 /* advertisement-interval */
14514 vty_out(vty,
14515 " Minimum time between advertisement runs is %d seconds\n",
14516 p->v_routeadv);
14517
14518 /* Update-source. */
14519 if (p->update_if || p->update_source) {
14520 vty_out(vty, " Update source is ");
14521 if (p->update_if)
14522 vty_out(vty, "%s", p->update_if);
14523 else if (p->update_source)
14524 vty_out(vty, "%pSU", p->update_source);
14525 vty_out(vty, "\n");
14526 }
14527
14528 vty_out(vty, "\n");
14529 }
14530
14531 /* Address Family Information */
14532 json_object *json_hold = NULL;
14533
14534 if (use_json)
14535 json_hold = json_object_new_object();
14536
14537 FOREACH_AFI_SAFI (afi, safi)
14538 if (p->afc[afi][safi])
14539 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14540 json_hold);
14541
14542 if (use_json) {
14543 json_object_object_add(json_neigh, "addressFamilyInfo",
14544 json_hold);
14545 json_object_int_add(json_neigh, "connectionsEstablished",
14546 p->established);
14547 json_object_int_add(json_neigh, "connectionsDropped",
14548 p->dropped);
14549 } else
14550 vty_out(vty, " Connections established %d; dropped %d\n",
14551 p->established, p->dropped);
14552
14553 if (!p->last_reset) {
14554 if (use_json)
14555 json_object_string_add(json_neigh, "lastReset",
14556 "never");
14557 else
14558 vty_out(vty, " Last reset never\n");
14559 } else {
14560 if (use_json) {
14561 time_t uptime;
14562 struct tm tm;
14563
14564 uptime = monotime(NULL);
14565 uptime -= p->resettime;
14566 gmtime_r(&uptime, &tm);
14567
14568 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14569 (tm.tm_sec * 1000)
14570 + (tm.tm_min * 60000)
14571 + (tm.tm_hour * 3600000));
14572 bgp_show_peer_reset(NULL, p, json_neigh, true);
14573 } else {
14574 vty_out(vty, " Last reset %s, ",
14575 peer_uptime(p->resettime, timebuf,
14576 BGP_UPTIME_LEN, 0, NULL));
14577
14578 bgp_show_peer_reset(vty, p, NULL, false);
14579 if (p->last_reset_cause_size) {
14580 msg = p->last_reset_cause;
14581 vty_out(vty,
14582 " Message received that caused BGP to send a NOTIFICATION:\n ");
14583 for (i = 1; i <= p->last_reset_cause_size;
14584 i++) {
14585 vty_out(vty, "%02X", *msg++);
14586
14587 if (i != p->last_reset_cause_size) {
14588 if (i % 16 == 0) {
14589 vty_out(vty, "\n ");
14590 } else if (i % 4 == 0) {
14591 vty_out(vty, " ");
14592 }
14593 }
14594 }
14595 vty_out(vty, "\n");
14596 }
14597 }
14598 }
14599
14600 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14601 if (use_json)
14602 json_object_boolean_true_add(json_neigh,
14603 "prefixesConfigExceedMax");
14604 else
14605 vty_out(vty,
14606 " Peer had exceeded the max. no. of prefixes configured.\n");
14607
14608 if (p->t_pmax_restart) {
14609 if (use_json) {
14610 json_object_boolean_true_add(
14611 json_neigh, "reducePrefixNumFrom");
14612 json_object_int_add(json_neigh,
14613 "restartInTimerMsec",
14614 thread_timer_remain_second(
14615 p->t_pmax_restart)
14616 * 1000);
14617 } else
14618 vty_out(vty,
14619 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14620 p->host, thread_timer_remain_second(
14621 p->t_pmax_restart));
14622 } else {
14623 if (use_json)
14624 json_object_boolean_true_add(
14625 json_neigh,
14626 "reducePrefixNumAndClearIpBgp");
14627 else
14628 vty_out(vty,
14629 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14630 p->host);
14631 }
14632 }
14633
14634 /* EBGP Multihop and GTSM */
14635 if (p->sort != BGP_PEER_IBGP) {
14636 if (use_json) {
14637 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14638 json_object_int_add(json_neigh,
14639 "externalBgpNbrMaxHopsAway",
14640 p->gtsm_hops);
14641 else
14642 json_object_int_add(json_neigh,
14643 "externalBgpNbrMaxHopsAway",
14644 p->ttl);
14645 } else {
14646 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14647 vty_out(vty,
14648 " External BGP neighbor may be up to %d hops away.\n",
14649 p->gtsm_hops);
14650 else
14651 vty_out(vty,
14652 " External BGP neighbor may be up to %d hops away.\n",
14653 p->ttl);
14654 }
14655 } else {
14656 if (use_json) {
14657 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14658 json_object_int_add(json_neigh,
14659 "internalBgpNbrMaxHopsAway",
14660 p->gtsm_hops);
14661 else
14662 json_object_int_add(json_neigh,
14663 "internalBgpNbrMaxHopsAway",
14664 p->ttl);
14665 } else {
14666 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14667 vty_out(vty,
14668 " Internal BGP neighbor may be up to %d hops away.\n",
14669 p->gtsm_hops);
14670 else
14671 vty_out(vty,
14672 " Internal BGP neighbor may be up to %d hops away.\n",
14673 p->ttl);
14674 }
14675 }
14676
14677 /* Local address. */
14678 if (p->su_local) {
14679 if (use_json) {
14680 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14681 p->su_local);
14682 json_object_int_add(json_neigh, "portLocal",
14683 ntohs(p->su_local->sin.sin_port));
14684 } else
14685 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14686 p->su_local, ntohs(p->su_local->sin.sin_port));
14687 } else {
14688 if (use_json) {
14689 json_object_string_add(json_neigh, "hostLocal",
14690 "Unknown");
14691 json_object_int_add(json_neigh, "portLocal", -1);
14692 }
14693 }
14694
14695 /* Remote address. */
14696 if (p->su_remote) {
14697 if (use_json) {
14698 json_object_string_addf(json_neigh, "hostForeign",
14699 "%pSU", p->su_remote);
14700 json_object_int_add(json_neigh, "portForeign",
14701 ntohs(p->su_remote->sin.sin_port));
14702 } else
14703 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14704 p->su_remote,
14705 ntohs(p->su_remote->sin.sin_port));
14706 } else {
14707 if (use_json) {
14708 json_object_string_add(json_neigh, "hostForeign",
14709 "Unknown");
14710 json_object_int_add(json_neigh, "portForeign", -1);
14711 }
14712 }
14713
14714 /* Nexthop display. */
14715 if (p->su_local) {
14716 if (use_json) {
14717 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14718 &p->nexthop.v4);
14719 json_object_string_addf(json_neigh, "nexthopGlobal",
14720 "%pI6", &p->nexthop.v6_global);
14721 json_object_string_addf(json_neigh, "nexthopLocal",
14722 "%pI6", &p->nexthop.v6_local);
14723 if (p->shared_network)
14724 json_object_string_add(json_neigh,
14725 "bgpConnection",
14726 "sharedNetwork");
14727 else
14728 json_object_string_add(json_neigh,
14729 "bgpConnection",
14730 "nonSharedNetwork");
14731 } else {
14732 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14733 vty_out(vty, "Nexthop global: %pI6\n",
14734 &p->nexthop.v6_global);
14735 vty_out(vty, "Nexthop local: %pI6\n",
14736 &p->nexthop.v6_local);
14737 vty_out(vty, "BGP connection: %s\n",
14738 p->shared_network ? "shared network"
14739 : "non shared network");
14740 }
14741 } else {
14742 if (use_json) {
14743 json_object_string_add(json_neigh, "nexthop",
14744 "Unknown");
14745 json_object_string_add(json_neigh, "nexthopGlobal",
14746 "Unknown");
14747 json_object_string_add(json_neigh, "nexthopLocal",
14748 "Unknown");
14749 json_object_string_add(json_neigh, "bgpConnection",
14750 "Unknown");
14751 }
14752 }
14753
14754 /* Timer information. */
14755 if (use_json) {
14756 json_object_int_add(json_neigh, "connectRetryTimer",
14757 p->v_connect);
14758 if (peer_established(p)) {
14759 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14760 p->rtt);
14761 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14762 json_object_int_add(json_neigh,
14763 "shutdownRttInMsecs",
14764 p->rtt_expected);
14765 json_object_int_add(json_neigh,
14766 "shutdownRttAfterCount",
14767 p->rtt_keepalive_rcv);
14768 }
14769 }
14770 if (p->t_start)
14771 json_object_int_add(
14772 json_neigh, "nextStartTimerDueInMsecs",
14773 thread_timer_remain_second(p->t_start) * 1000);
14774 if (p->t_connect)
14775 json_object_int_add(
14776 json_neigh, "nextConnectTimerDueInMsecs",
14777 thread_timer_remain_second(p->t_connect)
14778 * 1000);
14779 if (p->t_routeadv) {
14780 json_object_int_add(json_neigh, "mraiInterval",
14781 p->v_routeadv);
14782 json_object_int_add(
14783 json_neigh, "mraiTimerExpireInMsecs",
14784 thread_timer_remain_second(p->t_routeadv)
14785 * 1000);
14786 }
14787 if (p->password)
14788 json_object_int_add(json_neigh, "authenticationEnabled",
14789 1);
14790
14791 if (p->t_read)
14792 json_object_string_add(json_neigh, "readThread", "on");
14793 else
14794 json_object_string_add(json_neigh, "readThread", "off");
14795
14796 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14797 json_object_string_add(json_neigh, "writeThread", "on");
14798 else
14799 json_object_string_add(json_neigh, "writeThread",
14800 "off");
14801 } else {
14802 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14803 p->v_connect);
14804 if (peer_established(p)) {
14805 vty_out(vty, "Estimated round trip time: %d ms\n",
14806 p->rtt);
14807 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14808 vty_out(vty,
14809 "Shutdown when RTT > %dms, count > %u\n",
14810 p->rtt_expected, p->rtt_keepalive_rcv);
14811 }
14812 if (p->t_start)
14813 vty_out(vty, "Next start timer due in %ld seconds\n",
14814 thread_timer_remain_second(p->t_start));
14815 if (p->t_connect)
14816 vty_out(vty, "Next connect timer due in %ld seconds\n",
14817 thread_timer_remain_second(p->t_connect));
14818 if (p->t_routeadv)
14819 vty_out(vty,
14820 "MRAI (interval %u) timer expires in %ld seconds\n",
14821 p->v_routeadv,
14822 thread_timer_remain_second(p->t_routeadv));
14823 if (p->password)
14824 vty_out(vty, "Peer Authentication Enabled\n");
14825
14826 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14827 p->t_read ? "on" : "off",
14828 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14829 ? "on"
14830 : "off", p->fd);
14831 }
14832
14833 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14834 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14835 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14836
14837 if (!use_json)
14838 vty_out(vty, "\n");
14839
14840 /* BFD information. */
14841 if (p->bfd_config)
14842 bgp_bfd_show_info(vty, p, json_neigh);
14843
14844 if (use_json) {
14845 if (p->conf_if) /* Configured interface name. */
14846 json_object_object_add(json, p->conf_if, json_neigh);
14847 else /* Configured IP address. */
14848 json_object_object_add(json, p->host, json_neigh);
14849 }
14850 }
14851
14852 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14853 enum show_type type,
14854 union sockunion *su,
14855 const char *conf_if, afi_t afi,
14856 json_object *json)
14857 {
14858 struct listnode *node, *nnode;
14859 struct peer *peer;
14860 bool found = false;
14861 safi_t safi = SAFI_UNICAST;
14862 json_object *json_neighbor = NULL;
14863
14864 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14865
14866 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14867 continue;
14868
14869 if ((peer->afc[afi][safi]) == 0)
14870 continue;
14871
14872 if (json)
14873 json_neighbor = json_object_new_object();
14874
14875 if (type == show_all) {
14876 bgp_show_peer_gr_status(vty, peer, json_neighbor);
14877
14878 if (json)
14879 json_object_object_add(json, peer->host,
14880 json_neighbor);
14881
14882 } else if (type == show_peer) {
14883 if (conf_if) {
14884 if ((peer->conf_if
14885 && !strcmp(peer->conf_if, conf_if))
14886 || (peer->hostname
14887 && !strcmp(peer->hostname, conf_if))) {
14888 found = true;
14889 bgp_show_peer_gr_status(vty, peer,
14890 json_neighbor);
14891 }
14892 } else {
14893 if (sockunion_same(&peer->su, su)) {
14894 found = true;
14895 bgp_show_peer_gr_status(vty, peer,
14896 json_neighbor);
14897 }
14898 }
14899 if (json) {
14900 if (found)
14901 json_object_object_add(json, peer->host,
14902 json_neighbor);
14903 else
14904 json_object_free(json_neighbor);
14905 }
14906 }
14907
14908 if (found)
14909 break;
14910 }
14911
14912 if (type == show_peer && !found) {
14913 if (json)
14914 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14915 else
14916 vty_out(vty, "%% No such neighbor\n");
14917 }
14918
14919 if (!json)
14920 vty_out(vty, "\n");
14921
14922 return CMD_SUCCESS;
14923 }
14924
14925 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14926 enum show_type type, union sockunion *su,
14927 const char *conf_if, bool use_json,
14928 json_object *json)
14929 {
14930 struct listnode *node, *nnode;
14931 struct peer *peer;
14932 int find = 0;
14933 bool nbr_output = false;
14934 afi_t afi = AFI_MAX;
14935 safi_t safi = SAFI_MAX;
14936
14937 if (type == show_ipv4_peer || type == show_ipv4_all) {
14938 afi = AFI_IP;
14939 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14940 afi = AFI_IP6;
14941 }
14942
14943 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14944 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14945 continue;
14946
14947 switch (type) {
14948 case show_all:
14949 bgp_show_peer(vty, peer, use_json, json);
14950 nbr_output = true;
14951 break;
14952 case show_peer:
14953 if (conf_if) {
14954 if ((peer->conf_if
14955 && !strcmp(peer->conf_if, conf_if))
14956 || (peer->hostname
14957 && !strcmp(peer->hostname, conf_if))) {
14958 find = 1;
14959 bgp_show_peer(vty, peer, use_json,
14960 json);
14961 }
14962 } else {
14963 if (sockunion_same(&peer->su, su)) {
14964 find = 1;
14965 bgp_show_peer(vty, peer, use_json,
14966 json);
14967 }
14968 }
14969 break;
14970 case show_ipv4_peer:
14971 case show_ipv6_peer:
14972 FOREACH_SAFI (safi) {
14973 if (peer->afc[afi][safi]) {
14974 if (conf_if) {
14975 if ((peer->conf_if
14976 && !strcmp(peer->conf_if, conf_if))
14977 || (peer->hostname
14978 && !strcmp(peer->hostname, conf_if))) {
14979 find = 1;
14980 bgp_show_peer(vty, peer, use_json,
14981 json);
14982 break;
14983 }
14984 } else {
14985 if (sockunion_same(&peer->su, su)) {
14986 find = 1;
14987 bgp_show_peer(vty, peer, use_json,
14988 json);
14989 break;
14990 }
14991 }
14992 }
14993 }
14994 break;
14995 case show_ipv4_all:
14996 case show_ipv6_all:
14997 FOREACH_SAFI (safi) {
14998 if (peer->afc[afi][safi]) {
14999 bgp_show_peer(vty, peer, use_json, json);
15000 nbr_output = true;
15001 break;
15002 }
15003 }
15004 break;
15005 }
15006 }
15007
15008 if ((type == show_peer || type == show_ipv4_peer ||
15009 type == show_ipv6_peer) && !find) {
15010 if (use_json)
15011 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15012 else
15013 vty_out(vty, "%% No such neighbor in this view/vrf\n");
15014 }
15015
15016 if (type != show_peer && type != show_ipv4_peer &&
15017 type != show_ipv6_peer && !nbr_output && !use_json)
15018 vty_out(vty, "%% No BGP neighbors found\n");
15019
15020 if (use_json) {
15021 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15022 json, JSON_C_TO_STRING_PRETTY));
15023 } else {
15024 vty_out(vty, "\n");
15025 }
15026
15027 return CMD_SUCCESS;
15028 }
15029
15030 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15031 enum show_type type,
15032 const char *ip_str,
15033 afi_t afi, json_object *json)
15034 {
15035
15036 int ret;
15037 struct bgp *bgp;
15038 union sockunion su;
15039
15040 bgp = bgp_get_default();
15041
15042 if (!bgp)
15043 return;
15044
15045 if (!json)
15046 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
15047
15048 if (ip_str) {
15049 ret = str2sockunion(ip_str, &su);
15050 if (ret < 0)
15051 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
15052 ip_str, afi, json);
15053 else
15054 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15055 NULL, afi, json);
15056 } else
15057 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
15058 afi, json);
15059 }
15060
15061 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
15062 enum show_type type,
15063 const char *ip_str,
15064 bool use_json)
15065 {
15066 struct listnode *node, *nnode;
15067 struct bgp *bgp;
15068 union sockunion su;
15069 json_object *json = NULL;
15070 int ret, is_first = 1;
15071 bool nbr_output = false;
15072
15073 if (use_json)
15074 vty_out(vty, "{\n");
15075
15076 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15077 nbr_output = true;
15078 if (use_json) {
15079 if (!(json = json_object_new_object())) {
15080 flog_err(
15081 EC_BGP_JSON_MEM_ERROR,
15082 "Unable to allocate memory for JSON object");
15083 vty_out(vty,
15084 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15085 return;
15086 }
15087
15088 json_object_int_add(json, "vrfId",
15089 (bgp->vrf_id == VRF_UNKNOWN)
15090 ? -1
15091 : (int64_t)bgp->vrf_id);
15092 json_object_string_add(
15093 json, "vrfName",
15094 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15095 ? VRF_DEFAULT_NAME
15096 : bgp->name);
15097
15098 if (!is_first)
15099 vty_out(vty, ",\n");
15100 else
15101 is_first = 0;
15102
15103 vty_out(vty, "\"%s\":",
15104 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15105 ? VRF_DEFAULT_NAME
15106 : bgp->name);
15107 } else {
15108 vty_out(vty, "\nInstance %s:\n",
15109 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15110 ? VRF_DEFAULT_NAME
15111 : bgp->name);
15112 }
15113
15114 if (type == show_peer || type == show_ipv4_peer ||
15115 type == show_ipv6_peer) {
15116 ret = str2sockunion(ip_str, &su);
15117 if (ret < 0)
15118 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15119 use_json, json);
15120 else
15121 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15122 use_json, json);
15123 } else {
15124 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15125 use_json, json);
15126 }
15127 json_object_free(json);
15128 json = NULL;
15129 }
15130
15131 if (use_json)
15132 vty_out(vty, "}\n");
15133 else if (!nbr_output)
15134 vty_out(vty, "%% BGP instance not found\n");
15135 }
15136
15137 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15138 enum show_type type, const char *ip_str,
15139 bool use_json)
15140 {
15141 int ret;
15142 struct bgp *bgp;
15143 union sockunion su;
15144 json_object *json = NULL;
15145
15146 if (name) {
15147 if (strmatch(name, "all")) {
15148 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15149 use_json);
15150 return CMD_SUCCESS;
15151 } else {
15152 bgp = bgp_lookup_by_name(name);
15153 if (!bgp) {
15154 if (use_json) {
15155 json = json_object_new_object();
15156 vty_json(vty, json);
15157 } else
15158 vty_out(vty,
15159 "%% BGP instance not found\n");
15160
15161 return CMD_WARNING;
15162 }
15163 }
15164 } else {
15165 bgp = bgp_get_default();
15166 }
15167
15168 if (bgp) {
15169 json = json_object_new_object();
15170 if (ip_str) {
15171 ret = str2sockunion(ip_str, &su);
15172 if (ret < 0)
15173 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15174 use_json, json);
15175 else
15176 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15177 use_json, json);
15178 } else {
15179 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15180 json);
15181 }
15182 json_object_free(json);
15183 } else {
15184 if (use_json)
15185 vty_out(vty, "{}\n");
15186 else
15187 vty_out(vty, "%% BGP instance not found\n");
15188 }
15189
15190 return CMD_SUCCESS;
15191 }
15192
15193
15194
15195 /* "show [ip] bgp neighbors graceful-restart" commands. */
15196 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15197 show_ip_bgp_neighbors_graceful_restart_cmd,
15198 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15199 SHOW_STR
15200 BGP_STR
15201 IP_STR
15202 IPV6_STR
15203 NEIGHBOR_STR
15204 "Neighbor to display information about\n"
15205 "Neighbor to display information about\n"
15206 "Neighbor on BGP configured interface\n"
15207 GR_SHOW
15208 JSON_STR)
15209 {
15210 char *sh_arg = NULL;
15211 enum show_type sh_type;
15212 int idx = 0;
15213 afi_t afi = AFI_MAX;
15214 bool uj = use_json(argc, argv);
15215
15216 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15217 afi = AFI_MAX;
15218
15219 idx++;
15220
15221 if (argv_find(argv, argc, "A.B.C.D", &idx)
15222 || argv_find(argv, argc, "X:X::X:X", &idx)
15223 || argv_find(argv, argc, "WORD", &idx)) {
15224 sh_type = show_peer;
15225 sh_arg = argv[idx]->arg;
15226 } else
15227 sh_type = show_all;
15228
15229 if (!argv_find(argv, argc, "graceful-restart", &idx))
15230 return CMD_SUCCESS;
15231
15232
15233 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15234 afi, uj);
15235 }
15236
15237 /* "show [ip] bgp neighbors" commands. */
15238 DEFUN (show_ip_bgp_neighbors,
15239 show_ip_bgp_neighbors_cmd,
15240 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15241 SHOW_STR
15242 IP_STR
15243 BGP_STR
15244 BGP_INSTANCE_HELP_STR
15245 BGP_AF_STR
15246 BGP_AF_STR
15247 "Detailed information on TCP and BGP neighbor connections\n"
15248 "Neighbor to display information about\n"
15249 "Neighbor to display information about\n"
15250 "Neighbor on BGP configured interface\n"
15251 JSON_STR)
15252 {
15253 char *vrf = NULL;
15254 char *sh_arg = NULL;
15255 enum show_type sh_type;
15256 afi_t afi = AFI_MAX;
15257
15258 bool uj = use_json(argc, argv);
15259
15260 int idx = 0;
15261
15262 /* [<vrf> VIEWVRFNAME] */
15263 if (argv_find(argv, argc, "vrf", &idx)) {
15264 vrf = argv[idx + 1]->arg;
15265 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15266 vrf = NULL;
15267 } else if (argv_find(argv, argc, "view", &idx))
15268 /* [<view> VIEWVRFNAME] */
15269 vrf = argv[idx + 1]->arg;
15270
15271 idx++;
15272
15273 if (argv_find(argv, argc, "ipv4", &idx)) {
15274 sh_type = show_ipv4_all;
15275 afi = AFI_IP;
15276 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15277 sh_type = show_ipv6_all;
15278 afi = AFI_IP6;
15279 } else {
15280 sh_type = show_all;
15281 }
15282
15283 if (argv_find(argv, argc, "A.B.C.D", &idx)
15284 || argv_find(argv, argc, "X:X::X:X", &idx)
15285 || argv_find(argv, argc, "WORD", &idx)) {
15286 sh_type = show_peer;
15287 sh_arg = argv[idx]->arg;
15288 }
15289
15290 if (sh_type == show_peer && afi == AFI_IP) {
15291 sh_type = show_ipv4_peer;
15292 } else if (sh_type == show_peer && afi == AFI_IP6) {
15293 sh_type = show_ipv6_peer;
15294 }
15295
15296 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15297 }
15298
15299 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15300 paths' and `show ip mbgp paths'. Those functions results are the
15301 same.*/
15302 DEFUN (show_ip_bgp_paths,
15303 show_ip_bgp_paths_cmd,
15304 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15305 SHOW_STR
15306 IP_STR
15307 BGP_STR
15308 BGP_SAFI_HELP_STR
15309 "Path information\n")
15310 {
15311 vty_out(vty, "Address Refcnt Path\n");
15312 aspath_print_all_vty(vty);
15313 return CMD_SUCCESS;
15314 }
15315
15316 #include "hash.h"
15317
15318 static void community_show_all_iterator(struct hash_bucket *bucket,
15319 struct vty *vty)
15320 {
15321 struct community *com;
15322
15323 com = (struct community *)bucket->data;
15324 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15325 community_str(com, false, false));
15326 }
15327
15328 /* Show BGP's community internal data. */
15329 DEFUN (show_ip_bgp_community_info,
15330 show_ip_bgp_community_info_cmd,
15331 "show [ip] bgp community-info",
15332 SHOW_STR
15333 IP_STR
15334 BGP_STR
15335 "List all bgp community information\n")
15336 {
15337 vty_out(vty, "Address Refcnt Community\n");
15338
15339 hash_iterate(community_hash(),
15340 (void (*)(struct hash_bucket *,
15341 void *))community_show_all_iterator,
15342 vty);
15343
15344 return CMD_SUCCESS;
15345 }
15346
15347 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15348 struct vty *vty)
15349 {
15350 struct lcommunity *lcom;
15351
15352 lcom = (struct lcommunity *)bucket->data;
15353 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15354 lcommunity_str(lcom, false, false));
15355 }
15356
15357 /* Show BGP's community internal data. */
15358 DEFUN (show_ip_bgp_lcommunity_info,
15359 show_ip_bgp_lcommunity_info_cmd,
15360 "show ip bgp large-community-info",
15361 SHOW_STR
15362 IP_STR
15363 BGP_STR
15364 "List all bgp large-community information\n")
15365 {
15366 vty_out(vty, "Address Refcnt Large-community\n");
15367
15368 hash_iterate(lcommunity_hash(),
15369 (void (*)(struct hash_bucket *,
15370 void *))lcommunity_show_all_iterator,
15371 vty);
15372
15373 return CMD_SUCCESS;
15374 }
15375 /* Graceful Restart */
15376
15377 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15378 struct bgp *bgp)
15379 {
15380
15381
15382 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15383
15384 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15385
15386 switch (bgp_global_gr_mode) {
15387
15388 case GLOBAL_HELPER:
15389 vty_out(vty, "Global BGP GR Mode : Helper\n");
15390 break;
15391
15392 case GLOBAL_GR:
15393 vty_out(vty, "Global BGP GR Mode : Restart\n");
15394 break;
15395
15396 case GLOBAL_DISABLE:
15397 vty_out(vty, "Global BGP GR Mode : Disable\n");
15398 break;
15399
15400 case GLOBAL_INVALID:
15401 vty_out(vty,
15402 "Global BGP GR Mode Invalid\n");
15403 break;
15404 }
15405 vty_out(vty, "\n");
15406 }
15407
15408 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15409 enum show_type type,
15410 const char *ip_str,
15411 afi_t afi, bool use_json)
15412 {
15413 json_object *json = NULL;
15414
15415 if (use_json)
15416 json = json_object_new_object();
15417
15418 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15419 afi = AFI_IP;
15420
15421 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15422
15423 bgp_show_neighbor_graceful_restart_vty(
15424 vty, type, ip_str, afi, json);
15425 afi++;
15426 }
15427 } else if (afi != AFI_MAX) {
15428 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15429 json);
15430 } else {
15431 if (json)
15432 json_object_free(json);
15433 return CMD_ERR_INCOMPLETE;
15434 }
15435
15436 if (json)
15437 vty_json(vty, json);
15438
15439 return CMD_SUCCESS;
15440 }
15441 /* Graceful Restart */
15442
15443 DEFUN (show_ip_bgp_attr_info,
15444 show_ip_bgp_attr_info_cmd,
15445 "show [ip] bgp attribute-info",
15446 SHOW_STR
15447 IP_STR
15448 BGP_STR
15449 "List all bgp attribute information\n")
15450 {
15451 attr_show_all(vty);
15452 return CMD_SUCCESS;
15453 }
15454
15455 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15456 afi_t afi, safi_t safi,
15457 bool use_json, json_object *json)
15458 {
15459 struct bgp *bgp;
15460 struct listnode *node;
15461 char *vname;
15462 char *ecom_str;
15463 enum vpn_policy_direction dir;
15464
15465 if (json) {
15466 json_object *json_import_vrfs = NULL;
15467 json_object *json_export_vrfs = NULL;
15468
15469 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15470
15471 if (!bgp) {
15472 vty_json(vty, json);
15473
15474 return CMD_WARNING;
15475 }
15476
15477 /* Provide context for the block */
15478 json_object_string_add(json, "vrf", name ? name : "default");
15479 json_object_string_add(json, "afiSafi",
15480 get_afi_safi_str(afi, safi, true));
15481
15482 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15483 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15484 json_object_string_add(json, "importFromVrfs", "none");
15485 json_object_string_add(json, "importRts", "none");
15486 } else {
15487 json_import_vrfs = json_object_new_array();
15488
15489 for (ALL_LIST_ELEMENTS_RO(
15490 bgp->vpn_policy[afi].import_vrf,
15491 node, vname))
15492 json_object_array_add(json_import_vrfs,
15493 json_object_new_string(vname));
15494
15495 json_object_object_add(json, "importFromVrfs",
15496 json_import_vrfs);
15497 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15498 if (bgp->vpn_policy[afi].rtlist[dir]) {
15499 ecom_str = ecommunity_ecom2str(
15500 bgp->vpn_policy[afi].rtlist[dir],
15501 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15502 json_object_string_add(json, "importRts",
15503 ecom_str);
15504 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15505 } else
15506 json_object_string_add(json, "importRts",
15507 "none");
15508 }
15509
15510 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15511 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15512 json_object_string_add(json, "exportToVrfs", "none");
15513 json_object_string_add(json, "routeDistinguisher",
15514 "none");
15515 json_object_string_add(json, "exportRts", "none");
15516 } else {
15517 json_export_vrfs = json_object_new_array();
15518
15519 for (ALL_LIST_ELEMENTS_RO(
15520 bgp->vpn_policy[afi].export_vrf,
15521 node, vname))
15522 json_object_array_add(json_export_vrfs,
15523 json_object_new_string(vname));
15524 json_object_object_add(json, "exportToVrfs",
15525 json_export_vrfs);
15526 json_object_string_addf(json, "routeDistinguisher",
15527 "%pRD",
15528 &bgp->vpn_policy[afi].tovpn_rd);
15529
15530 dir = BGP_VPN_POLICY_DIR_TOVPN;
15531 if (bgp->vpn_policy[afi].rtlist[dir]) {
15532 ecom_str = ecommunity_ecom2str(
15533 bgp->vpn_policy[afi].rtlist[dir],
15534 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15535 json_object_string_add(json, "exportRts",
15536 ecom_str);
15537 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15538 } else
15539 json_object_string_add(json, "exportRts",
15540 "none");
15541 }
15542
15543 if (use_json) {
15544 vty_json(vty, json);
15545 }
15546 } else {
15547 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15548
15549 if (!bgp) {
15550 vty_out(vty, "%% No such BGP instance exist\n");
15551 return CMD_WARNING;
15552 }
15553
15554 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15555 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15556 vty_out(vty,
15557 "This VRF is not importing %s routes from any other VRF\n",
15558 get_afi_safi_str(afi, safi, false));
15559 else {
15560 vty_out(vty,
15561 "This VRF is importing %s routes from the following VRFs:\n",
15562 get_afi_safi_str(afi, safi, false));
15563
15564 for (ALL_LIST_ELEMENTS_RO(
15565 bgp->vpn_policy[afi].import_vrf,
15566 node, vname))
15567 vty_out(vty, " %s\n", vname);
15568
15569 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15570 ecom_str = NULL;
15571 if (bgp->vpn_policy[afi].rtlist[dir]) {
15572 ecom_str = ecommunity_ecom2str(
15573 bgp->vpn_policy[afi].rtlist[dir],
15574 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15575 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15576
15577 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15578 } else
15579 vty_out(vty, "Import RT(s):\n");
15580 }
15581
15582 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15583 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15584 vty_out(vty,
15585 "This VRF is not exporting %s routes to any other VRF\n",
15586 get_afi_safi_str(afi, safi, false));
15587 else {
15588 vty_out(vty,
15589 "This VRF is exporting %s routes to the following VRFs:\n",
15590 get_afi_safi_str(afi, safi, false));
15591
15592 for (ALL_LIST_ELEMENTS_RO(
15593 bgp->vpn_policy[afi].export_vrf,
15594 node, vname))
15595 vty_out(vty, " %s\n", vname);
15596
15597 vty_out(vty, "RD: %pRD\n",
15598 &bgp->vpn_policy[afi].tovpn_rd);
15599
15600 dir = BGP_VPN_POLICY_DIR_TOVPN;
15601 if (bgp->vpn_policy[afi].rtlist[dir]) {
15602 ecom_str = ecommunity_ecom2str(
15603 bgp->vpn_policy[afi].rtlist[dir],
15604 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15605 vty_out(vty, "Export RT: %s\n", ecom_str);
15606 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15607 } else
15608 vty_out(vty, "Import RT(s):\n");
15609 }
15610 }
15611
15612 return CMD_SUCCESS;
15613 }
15614
15615 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15616 safi_t safi, bool use_json)
15617 {
15618 struct listnode *node, *nnode;
15619 struct bgp *bgp;
15620 char *vrf_name = NULL;
15621 json_object *json = NULL;
15622 json_object *json_vrf = NULL;
15623 json_object *json_vrfs = NULL;
15624
15625 if (use_json) {
15626 json = json_object_new_object();
15627 json_vrfs = json_object_new_object();
15628 }
15629
15630 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15631
15632 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15633 vrf_name = bgp->name;
15634
15635 if (use_json) {
15636 json_vrf = json_object_new_object();
15637 } else {
15638 vty_out(vty, "\nInstance %s:\n",
15639 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15640 ? VRF_DEFAULT_NAME : bgp->name);
15641 }
15642 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15643 if (use_json) {
15644 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15645 json_object_object_add(json_vrfs,
15646 VRF_DEFAULT_NAME, json_vrf);
15647 else
15648 json_object_object_add(json_vrfs, vrf_name,
15649 json_vrf);
15650 }
15651 }
15652
15653 if (use_json) {
15654 json_object_object_add(json, "vrfs", json_vrfs);
15655 vty_json(vty, json);
15656 }
15657
15658 return CMD_SUCCESS;
15659 }
15660
15661 /* "show [ip] bgp route-leak" command. */
15662 DEFUN (show_ip_bgp_route_leak,
15663 show_ip_bgp_route_leak_cmd,
15664 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15665 SHOW_STR
15666 IP_STR
15667 BGP_STR
15668 BGP_INSTANCE_HELP_STR
15669 BGP_AFI_HELP_STR
15670 BGP_SAFI_HELP_STR
15671 "Route leaking information\n"
15672 JSON_STR)
15673 {
15674 char *vrf = NULL;
15675 afi_t afi = AFI_MAX;
15676 safi_t safi = SAFI_MAX;
15677
15678 bool uj = use_json(argc, argv);
15679 int idx = 0;
15680 json_object *json = NULL;
15681
15682 /* show [ip] bgp */
15683 if (argv_find(argv, argc, "ip", &idx)) {
15684 afi = AFI_IP;
15685 safi = SAFI_UNICAST;
15686 }
15687 /* [vrf VIEWVRFNAME] */
15688 if (argv_find(argv, argc, "view", &idx)) {
15689 vty_out(vty,
15690 "%% This command is not applicable to BGP views\n");
15691 return CMD_WARNING;
15692 }
15693
15694 if (argv_find(argv, argc, "vrf", &idx)) {
15695 vrf = argv[idx + 1]->arg;
15696 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15697 vrf = NULL;
15698 }
15699 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15700 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15701 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15702
15703 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15704 vty_out(vty,
15705 "%% This command is applicable only for unicast ipv4|ipv6\n");
15706 return CMD_WARNING;
15707 }
15708
15709 if (vrf && strmatch(vrf, "all"))
15710 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15711
15712 if (uj)
15713 json = json_object_new_object();
15714
15715 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15716 }
15717
15718 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15719 safi_t safi, bool uj)
15720 {
15721 struct listnode *node, *nnode;
15722 struct bgp *bgp;
15723
15724 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15725 if (!uj)
15726 vty_out(vty, "\nInstance %s:\n",
15727 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15728 ? VRF_DEFAULT_NAME
15729 : bgp->name);
15730
15731 update_group_show(bgp, afi, safi, vty, 0, uj);
15732 }
15733 }
15734
15735 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15736 int safi, uint64_t subgrp_id, bool uj)
15737 {
15738 struct bgp *bgp;
15739
15740 if (name) {
15741 if (strmatch(name, "all")) {
15742 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15743 return CMD_SUCCESS;
15744 } else {
15745 bgp = bgp_lookup_by_name(name);
15746 }
15747 } else {
15748 bgp = bgp_get_default();
15749 }
15750
15751 if (bgp)
15752 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15753 return CMD_SUCCESS;
15754 }
15755
15756 DEFUN (show_ip_bgp_updgrps,
15757 show_ip_bgp_updgrps_cmd,
15758 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15759 SHOW_STR
15760 IP_STR
15761 BGP_STR
15762 BGP_INSTANCE_HELP_STR
15763 BGP_AFI_HELP_STR
15764 BGP_SAFI_WITH_LABEL_HELP_STR
15765 "Detailed info about dynamic update groups\n"
15766 "Specific subgroup to display detailed info for\n"
15767 JSON_STR)
15768 {
15769 char *vrf = NULL;
15770 afi_t afi = AFI_IP6;
15771 safi_t safi = SAFI_UNICAST;
15772 uint64_t subgrp_id = 0;
15773
15774 int idx = 0;
15775
15776 bool uj = use_json(argc, argv);
15777
15778 /* show [ip] bgp */
15779 if (argv_find(argv, argc, "ip", &idx))
15780 afi = AFI_IP;
15781 /* [<vrf> VIEWVRFNAME] */
15782 if (argv_find(argv, argc, "vrf", &idx)) {
15783 vrf = argv[idx + 1]->arg;
15784 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15785 vrf = NULL;
15786 } else if (argv_find(argv, argc, "view", &idx))
15787 /* [<view> VIEWVRFNAME] */
15788 vrf = argv[idx + 1]->arg;
15789 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15790 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15791 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15792 }
15793
15794 /* get subgroup id, if provided */
15795 idx = argc - 1;
15796 if (argv[idx]->type == VARIABLE_TKN)
15797 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15798
15799 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15800 }
15801
15802 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15803 show_bgp_instance_all_ipv6_updgrps_cmd,
15804 "show [ip] bgp <view|vrf> all update-groups [json]",
15805 SHOW_STR
15806 IP_STR
15807 BGP_STR
15808 BGP_INSTANCE_ALL_HELP_STR
15809 "Detailed info about dynamic update groups\n"
15810 JSON_STR)
15811 {
15812 bool uj = use_json(argc, argv);
15813
15814 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15815 return CMD_SUCCESS;
15816 }
15817
15818 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15819 show_bgp_l2vpn_evpn_updgrps_cmd,
15820 "show [ip] bgp l2vpn evpn update-groups",
15821 SHOW_STR
15822 IP_STR
15823 BGP_STR
15824 "l2vpn address family\n"
15825 "evpn sub-address family\n"
15826 "Detailed info about dynamic update groups\n")
15827 {
15828 char *vrf = NULL;
15829 uint64_t subgrp_id = 0;
15830
15831 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
15832 return CMD_SUCCESS;
15833 }
15834
15835 DEFUN (show_bgp_updgrps_stats,
15836 show_bgp_updgrps_stats_cmd,
15837 "show [ip] bgp update-groups statistics",
15838 SHOW_STR
15839 IP_STR
15840 BGP_STR
15841 "Detailed info about dynamic update groups\n"
15842 "Statistics\n")
15843 {
15844 struct bgp *bgp;
15845
15846 bgp = bgp_get_default();
15847 if (bgp)
15848 update_group_show_stats(bgp, vty);
15849
15850 return CMD_SUCCESS;
15851 }
15852
15853 DEFUN (show_bgp_instance_updgrps_stats,
15854 show_bgp_instance_updgrps_stats_cmd,
15855 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15856 SHOW_STR
15857 IP_STR
15858 BGP_STR
15859 BGP_INSTANCE_HELP_STR
15860 "Detailed info about dynamic update groups\n"
15861 "Statistics\n")
15862 {
15863 int idx_word = 3;
15864 struct bgp *bgp;
15865
15866 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15867 if (bgp)
15868 update_group_show_stats(bgp, vty);
15869
15870 return CMD_SUCCESS;
15871 }
15872
15873 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15874 afi_t afi, safi_t safi,
15875 const char *what, uint64_t subgrp_id)
15876 {
15877 struct bgp *bgp;
15878
15879 if (name)
15880 bgp = bgp_lookup_by_name(name);
15881 else
15882 bgp = bgp_get_default();
15883
15884 if (bgp) {
15885 if (!strcmp(what, "advertise-queue"))
15886 update_group_show_adj_queue(bgp, afi, safi, vty,
15887 subgrp_id);
15888 else if (!strcmp(what, "advertised-routes"))
15889 update_group_show_advertised(bgp, afi, safi, vty,
15890 subgrp_id);
15891 else if (!strcmp(what, "packet-queue"))
15892 update_group_show_packet_queue(bgp, afi, safi, vty,
15893 subgrp_id);
15894 }
15895 }
15896
15897 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15898 show_ip_bgp_instance_updgrps_adj_s_cmd,
15899 "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",
15900 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15901 BGP_SAFI_HELP_STR
15902 "Detailed info about dynamic update groups\n"
15903 "Specific subgroup to display info for\n"
15904 "Advertisement queue\n"
15905 "Announced routes\n"
15906 "Packet queue\n")
15907 {
15908 uint64_t subgrp_id = 0;
15909 afi_t afiz;
15910 safi_t safiz;
15911 if (sgid)
15912 subgrp_id = strtoull(sgid, NULL, 10);
15913
15914 if (!ip && !afi)
15915 afiz = AFI_IP6;
15916 if (!ip && afi)
15917 afiz = bgp_vty_afi_from_str(afi);
15918 if (ip && !afi)
15919 afiz = AFI_IP;
15920 if (ip && afi) {
15921 afiz = bgp_vty_afi_from_str(afi);
15922 if (afiz != AFI_IP)
15923 vty_out(vty,
15924 "%% Cannot specify both 'ip' and 'ipv6'\n");
15925 return CMD_WARNING;
15926 }
15927
15928 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15929
15930 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15931 return CMD_SUCCESS;
15932 }
15933
15934 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15935 json_object *json)
15936 {
15937 struct listnode *node, *nnode;
15938 struct prefix *range;
15939 struct peer *conf;
15940 struct peer *peer;
15941 afi_t afi;
15942 safi_t safi;
15943 const char *peer_status;
15944 int lr_count;
15945 int dynamic;
15946 bool af_cfgd;
15947 json_object *json_peer_group = NULL;
15948 json_object *json_peer_group_afc = NULL;
15949 json_object *json_peer_group_members = NULL;
15950 json_object *json_peer_group_dynamic = NULL;
15951 json_object *json_peer_group_dynamic_af = NULL;
15952 json_object *json_peer_group_ranges = NULL;
15953
15954 conf = group->conf;
15955
15956 if (json) {
15957 json_peer_group = json_object_new_object();
15958 json_peer_group_afc = json_object_new_array();
15959 }
15960
15961 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15962 if (json)
15963 json_object_int_add(json_peer_group, "remoteAs",
15964 conf->as);
15965 else
15966 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15967 group->name, conf->as);
15968 } else if (conf->as_type == AS_INTERNAL) {
15969 if (json)
15970 json_object_int_add(json_peer_group, "remoteAs",
15971 group->bgp->as);
15972 else
15973 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15974 group->name, group->bgp->as);
15975 } else {
15976 if (!json)
15977 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15978 }
15979
15980 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15981 if (json)
15982 json_object_string_add(json_peer_group, "type",
15983 "internal");
15984 else
15985 vty_out(vty, " Peer-group type is internal\n");
15986 } else {
15987 if (json)
15988 json_object_string_add(json_peer_group, "type",
15989 "external");
15990 else
15991 vty_out(vty, " Peer-group type is external\n");
15992 }
15993
15994 /* Display AFs configured. */
15995 if (!json)
15996 vty_out(vty, " Configured address-families:");
15997
15998 FOREACH_AFI_SAFI (afi, safi) {
15999 if (conf->afc[afi][safi]) {
16000 af_cfgd = true;
16001 if (json)
16002 json_object_array_add(
16003 json_peer_group_afc,
16004 json_object_new_string(get_afi_safi_str(
16005 afi, safi, false)));
16006 else
16007 vty_out(vty, " %s;",
16008 get_afi_safi_str(afi, safi, false));
16009 }
16010 }
16011
16012 if (json) {
16013 json_object_object_add(json_peer_group,
16014 "addressFamiliesConfigured",
16015 json_peer_group_afc);
16016 } else {
16017 if (!af_cfgd)
16018 vty_out(vty, " none\n");
16019 else
16020 vty_out(vty, "\n");
16021 }
16022
16023 /* Display listen ranges (for dynamic neighbors), if any */
16024 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
16025 lr_count = listcount(group->listen_range[afi]);
16026 if (lr_count) {
16027 if (json) {
16028 if (!json_peer_group_dynamic)
16029 json_peer_group_dynamic =
16030 json_object_new_object();
16031
16032 json_peer_group_dynamic_af =
16033 json_object_new_object();
16034 json_peer_group_ranges =
16035 json_object_new_array();
16036 json_object_int_add(json_peer_group_dynamic_af,
16037 "count", lr_count);
16038 } else {
16039 vty_out(vty, " %d %s listen range(s)\n",
16040 lr_count, afi2str(afi));
16041 }
16042
16043 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
16044 nnode, range)) {
16045 if (json) {
16046 char buf[BUFSIZ];
16047
16048 snprintfrr(buf, sizeof(buf), "%pFX",
16049 range);
16050
16051 json_object_array_add(
16052 json_peer_group_ranges,
16053 json_object_new_string(buf));
16054 } else {
16055 vty_out(vty, " %pFX\n", range);
16056 }
16057 }
16058
16059 if (json) {
16060 json_object_object_add(
16061 json_peer_group_dynamic_af, "ranges",
16062 json_peer_group_ranges);
16063
16064 json_object_object_add(
16065 json_peer_group_dynamic, afi2str(afi),
16066 json_peer_group_dynamic_af);
16067 }
16068 }
16069 }
16070
16071 if (json_peer_group_dynamic)
16072 json_object_object_add(json_peer_group, "dynamicRanges",
16073 json_peer_group_dynamic);
16074
16075 /* Display group members and their status */
16076 if (listcount(group->peer)) {
16077 if (json)
16078 json_peer_group_members = json_object_new_object();
16079 else
16080 vty_out(vty, " Peer-group members:\n");
16081 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16082 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16083 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16084 peer_status = "Idle (Admin)";
16085 else if (CHECK_FLAG(peer->sflags,
16086 PEER_STATUS_PREFIX_OVERFLOW))
16087 peer_status = "Idle (PfxCt)";
16088 else
16089 peer_status = lookup_msg(bgp_status_msg,
16090 peer->status, NULL);
16091
16092 dynamic = peer_dynamic_neighbor(peer);
16093
16094 if (json) {
16095 json_object *json_peer_group_member =
16096 json_object_new_object();
16097
16098 json_object_string_add(json_peer_group_member,
16099 "status", peer_status);
16100
16101 if (dynamic)
16102 json_object_boolean_true_add(
16103 json_peer_group_member,
16104 "dynamic");
16105
16106 json_object_object_add(json_peer_group_members,
16107 peer->host,
16108 json_peer_group_member);
16109 } else {
16110 vty_out(vty, " %s %s %s \n", peer->host,
16111 dynamic ? "(dynamic)" : "",
16112 peer_status);
16113 }
16114 }
16115 if (json)
16116 json_object_object_add(json_peer_group, "members",
16117 json_peer_group_members);
16118 }
16119
16120 if (json)
16121 json_object_object_add(json, group->name, json_peer_group);
16122
16123 return CMD_SUCCESS;
16124 }
16125
16126 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16127 const char *group_name, bool uj)
16128 {
16129 struct bgp *bgp;
16130 struct listnode *node, *nnode;
16131 struct peer_group *group;
16132 bool found = false;
16133 json_object *json = NULL;
16134
16135 if (uj)
16136 json = json_object_new_object();
16137
16138 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16139
16140 if (!bgp) {
16141 if (uj)
16142 vty_json(vty, json);
16143 else
16144 vty_out(vty, "%% BGP instance not found\n");
16145
16146 return CMD_WARNING;
16147 }
16148
16149 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16150 if (group_name) {
16151 if (strmatch(group->name, group_name)) {
16152 bgp_show_one_peer_group(vty, group, json);
16153 found = true;
16154 break;
16155 }
16156 } else {
16157 bgp_show_one_peer_group(vty, group, json);
16158 }
16159 }
16160
16161 if (group_name && !found && !uj)
16162 vty_out(vty, "%% No such peer-group\n");
16163
16164 if (uj)
16165 vty_json(vty, json);
16166
16167 return CMD_SUCCESS;
16168 }
16169
16170 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16171 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16172 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16173 "Detailed information on BGP peer groups\n"
16174 "Peer group name\n" JSON_STR)
16175 {
16176 char *vrf, *pg;
16177 int idx = 0;
16178 bool uj = use_json(argc, argv);
16179
16180 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16181 : NULL;
16182 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16183
16184 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16185 }
16186
16187
16188 /* Redistribute VTY commands. */
16189
16190 DEFUN (bgp_redistribute_ipv4,
16191 bgp_redistribute_ipv4_cmd,
16192 "redistribute " FRR_IP_REDIST_STR_BGPD,
16193 "Redistribute information from another routing protocol\n"
16194 FRR_IP_REDIST_HELP_STR_BGPD)
16195 {
16196 VTY_DECLVAR_CONTEXT(bgp, bgp);
16197 int idx_protocol = 1;
16198 int type;
16199
16200 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16201 if (type < 0) {
16202 vty_out(vty, "%% Invalid route type\n");
16203 return CMD_WARNING_CONFIG_FAILED;
16204 }
16205
16206 bgp_redist_add(bgp, AFI_IP, type, 0);
16207 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16208 }
16209
16210 ALIAS_HIDDEN(
16211 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16212 "redistribute " FRR_IP_REDIST_STR_BGPD,
16213 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16214
16215 DEFUN (bgp_redistribute_ipv4_rmap,
16216 bgp_redistribute_ipv4_rmap_cmd,
16217 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16218 "Redistribute information from another routing protocol\n"
16219 FRR_IP_REDIST_HELP_STR_BGPD
16220 "Route map reference\n"
16221 "Pointer to route-map entries\n")
16222 {
16223 VTY_DECLVAR_CONTEXT(bgp, bgp);
16224 int idx_protocol = 1;
16225 int idx_word = 3;
16226 int type;
16227 struct bgp_redist *red;
16228 bool changed;
16229 struct route_map *route_map = route_map_lookup_warn_noexist(
16230 vty, argv[idx_word]->arg);
16231
16232 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16233 if (type < 0) {
16234 vty_out(vty, "%% Invalid route type\n");
16235 return CMD_WARNING_CONFIG_FAILED;
16236 }
16237
16238 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16239 changed =
16240 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16241 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16242 }
16243
16244 ALIAS_HIDDEN(
16245 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16246 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16247 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16248 "Route map reference\n"
16249 "Pointer to route-map entries\n")
16250
16251 DEFUN (bgp_redistribute_ipv4_metric,
16252 bgp_redistribute_ipv4_metric_cmd,
16253 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16254 "Redistribute information from another routing protocol\n"
16255 FRR_IP_REDIST_HELP_STR_BGPD
16256 "Metric for redistributed routes\n"
16257 "Default metric\n")
16258 {
16259 VTY_DECLVAR_CONTEXT(bgp, bgp);
16260 int idx_protocol = 1;
16261 int idx_number = 3;
16262 int type;
16263 uint32_t metric;
16264 struct bgp_redist *red;
16265 bool changed;
16266
16267 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16268 if (type < 0) {
16269 vty_out(vty, "%% Invalid route type\n");
16270 return CMD_WARNING_CONFIG_FAILED;
16271 }
16272 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16273
16274 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16275 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16276 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16277 }
16278
16279 ALIAS_HIDDEN(
16280 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16281 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16282 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16283 "Metric for redistributed routes\n"
16284 "Default metric\n")
16285
16286 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16287 bgp_redistribute_ipv4_rmap_metric_cmd,
16288 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16289 "Redistribute information from another routing protocol\n"
16290 FRR_IP_REDIST_HELP_STR_BGPD
16291 "Route map reference\n"
16292 "Pointer to route-map entries\n"
16293 "Metric for redistributed routes\n"
16294 "Default metric\n")
16295 {
16296 VTY_DECLVAR_CONTEXT(bgp, bgp);
16297 int idx_protocol = 1;
16298 int idx_word = 3;
16299 int idx_number = 5;
16300 int type;
16301 uint32_t metric;
16302 struct bgp_redist *red;
16303 bool changed;
16304 struct route_map *route_map =
16305 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16306
16307 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16308 if (type < 0) {
16309 vty_out(vty, "%% Invalid route type\n");
16310 return CMD_WARNING_CONFIG_FAILED;
16311 }
16312 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16313
16314 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16315 changed =
16316 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16317 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16318 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16319 }
16320
16321 ALIAS_HIDDEN(
16322 bgp_redistribute_ipv4_rmap_metric,
16323 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16324 "redistribute " FRR_IP_REDIST_STR_BGPD
16325 " route-map RMAP_NAME metric (0-4294967295)",
16326 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16327 "Route map reference\n"
16328 "Pointer to route-map entries\n"
16329 "Metric for redistributed routes\n"
16330 "Default metric\n")
16331
16332 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16333 bgp_redistribute_ipv4_metric_rmap_cmd,
16334 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16335 "Redistribute information from another routing protocol\n"
16336 FRR_IP_REDIST_HELP_STR_BGPD
16337 "Metric for redistributed routes\n"
16338 "Default metric\n"
16339 "Route map reference\n"
16340 "Pointer to route-map entries\n")
16341 {
16342 VTY_DECLVAR_CONTEXT(bgp, bgp);
16343 int idx_protocol = 1;
16344 int idx_number = 3;
16345 int idx_word = 5;
16346 int type;
16347 uint32_t metric;
16348 struct bgp_redist *red;
16349 bool changed;
16350 struct route_map *route_map =
16351 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16352
16353 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16354 if (type < 0) {
16355 vty_out(vty, "%% Invalid route type\n");
16356 return CMD_WARNING_CONFIG_FAILED;
16357 }
16358 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16359
16360 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16361 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16362 changed |=
16363 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16364 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16365 }
16366
16367 ALIAS_HIDDEN(
16368 bgp_redistribute_ipv4_metric_rmap,
16369 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16370 "redistribute " FRR_IP_REDIST_STR_BGPD
16371 " metric (0-4294967295) route-map RMAP_NAME",
16372 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16373 "Metric for redistributed routes\n"
16374 "Default metric\n"
16375 "Route map reference\n"
16376 "Pointer to route-map entries\n")
16377
16378 DEFUN (bgp_redistribute_ipv4_ospf,
16379 bgp_redistribute_ipv4_ospf_cmd,
16380 "redistribute <ospf|table> (1-65535)",
16381 "Redistribute information from another routing protocol\n"
16382 "Open Shortest Path First (OSPFv2)\n"
16383 "Non-main Kernel Routing Table\n"
16384 "Instance ID/Table ID\n")
16385 {
16386 VTY_DECLVAR_CONTEXT(bgp, bgp);
16387 int idx_ospf_table = 1;
16388 int idx_number = 2;
16389 unsigned short instance;
16390 unsigned short protocol;
16391
16392 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16393
16394 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16395 protocol = ZEBRA_ROUTE_OSPF;
16396 else
16397 protocol = ZEBRA_ROUTE_TABLE;
16398
16399 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16400 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16401 }
16402
16403 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16404 "redistribute <ospf|table> (1-65535)",
16405 "Redistribute information from another routing protocol\n"
16406 "Open Shortest Path First (OSPFv2)\n"
16407 "Non-main Kernel Routing Table\n"
16408 "Instance ID/Table ID\n")
16409
16410 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16411 bgp_redistribute_ipv4_ospf_rmap_cmd,
16412 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16413 "Redistribute information from another routing protocol\n"
16414 "Open Shortest Path First (OSPFv2)\n"
16415 "Non-main Kernel Routing Table\n"
16416 "Instance ID/Table ID\n"
16417 "Route map reference\n"
16418 "Pointer to route-map entries\n")
16419 {
16420 VTY_DECLVAR_CONTEXT(bgp, bgp);
16421 int idx_ospf_table = 1;
16422 int idx_number = 2;
16423 int idx_word = 4;
16424 struct bgp_redist *red;
16425 unsigned short instance;
16426 int protocol;
16427 bool changed;
16428 struct route_map *route_map =
16429 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16430
16431 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16432 protocol = ZEBRA_ROUTE_OSPF;
16433 else
16434 protocol = ZEBRA_ROUTE_TABLE;
16435
16436 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16437 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16438 changed =
16439 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16440 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16441 }
16442
16443 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16444 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16445 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16446 "Redistribute information from another routing protocol\n"
16447 "Open Shortest Path First (OSPFv2)\n"
16448 "Non-main Kernel Routing Table\n"
16449 "Instance ID/Table ID\n"
16450 "Route map reference\n"
16451 "Pointer to route-map entries\n")
16452
16453 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16454 bgp_redistribute_ipv4_ospf_metric_cmd,
16455 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16456 "Redistribute information from another routing protocol\n"
16457 "Open Shortest Path First (OSPFv2)\n"
16458 "Non-main Kernel Routing Table\n"
16459 "Instance ID/Table ID\n"
16460 "Metric for redistributed routes\n"
16461 "Default metric\n")
16462 {
16463 VTY_DECLVAR_CONTEXT(bgp, bgp);
16464 int idx_ospf_table = 1;
16465 int idx_number = 2;
16466 int idx_number_2 = 4;
16467 uint32_t metric;
16468 struct bgp_redist *red;
16469 unsigned short instance;
16470 int protocol;
16471 bool changed;
16472
16473 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16474 protocol = ZEBRA_ROUTE_OSPF;
16475 else
16476 protocol = ZEBRA_ROUTE_TABLE;
16477
16478 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16479 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16480
16481 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16482 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16483 metric);
16484 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16485 }
16486
16487 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16488 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16489 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16490 "Redistribute information from another routing protocol\n"
16491 "Open Shortest Path First (OSPFv2)\n"
16492 "Non-main Kernel Routing Table\n"
16493 "Instance ID/Table ID\n"
16494 "Metric for redistributed routes\n"
16495 "Default metric\n")
16496
16497 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16498 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16499 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16500 "Redistribute information from another routing protocol\n"
16501 "Open Shortest Path First (OSPFv2)\n"
16502 "Non-main Kernel Routing Table\n"
16503 "Instance ID/Table ID\n"
16504 "Route map reference\n"
16505 "Pointer to route-map entries\n"
16506 "Metric for redistributed routes\n"
16507 "Default metric\n")
16508 {
16509 VTY_DECLVAR_CONTEXT(bgp, bgp);
16510 int idx_ospf_table = 1;
16511 int idx_number = 2;
16512 int idx_word = 4;
16513 int idx_number_2 = 6;
16514 uint32_t metric;
16515 struct bgp_redist *red;
16516 unsigned short instance;
16517 int protocol;
16518 bool changed;
16519 struct route_map *route_map =
16520 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16521
16522 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16523 protocol = ZEBRA_ROUTE_OSPF;
16524 else
16525 protocol = ZEBRA_ROUTE_TABLE;
16526
16527 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16528 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16529
16530 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16531 changed =
16532 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16533 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16534 metric);
16535 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16536 }
16537
16538 ALIAS_HIDDEN(
16539 bgp_redistribute_ipv4_ospf_rmap_metric,
16540 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16541 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16542 "Redistribute information from another routing protocol\n"
16543 "Open Shortest Path First (OSPFv2)\n"
16544 "Non-main Kernel Routing Table\n"
16545 "Instance ID/Table ID\n"
16546 "Route map reference\n"
16547 "Pointer to route-map entries\n"
16548 "Metric for redistributed routes\n"
16549 "Default metric\n")
16550
16551 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16552 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16553 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16554 "Redistribute information from another routing protocol\n"
16555 "Open Shortest Path First (OSPFv2)\n"
16556 "Non-main Kernel Routing Table\n"
16557 "Instance ID/Table ID\n"
16558 "Metric for redistributed routes\n"
16559 "Default metric\n"
16560 "Route map reference\n"
16561 "Pointer to route-map entries\n")
16562 {
16563 VTY_DECLVAR_CONTEXT(bgp, bgp);
16564 int idx_ospf_table = 1;
16565 int idx_number = 2;
16566 int idx_number_2 = 4;
16567 int idx_word = 6;
16568 uint32_t metric;
16569 struct bgp_redist *red;
16570 unsigned short instance;
16571 int protocol;
16572 bool changed;
16573 struct route_map *route_map =
16574 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16575
16576 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16577 protocol = ZEBRA_ROUTE_OSPF;
16578 else
16579 protocol = ZEBRA_ROUTE_TABLE;
16580
16581 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16582 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16583
16584 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16585 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16586 metric);
16587 changed |=
16588 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16589 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16590 }
16591
16592 ALIAS_HIDDEN(
16593 bgp_redistribute_ipv4_ospf_metric_rmap,
16594 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16595 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16596 "Redistribute information from another routing protocol\n"
16597 "Open Shortest Path First (OSPFv2)\n"
16598 "Non-main Kernel Routing Table\n"
16599 "Instance ID/Table ID\n"
16600 "Metric for redistributed routes\n"
16601 "Default metric\n"
16602 "Route map reference\n"
16603 "Pointer to route-map entries\n")
16604
16605 DEFUN (no_bgp_redistribute_ipv4_ospf,
16606 no_bgp_redistribute_ipv4_ospf_cmd,
16607 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16608 NO_STR
16609 "Redistribute information from another routing protocol\n"
16610 "Open Shortest Path First (OSPFv2)\n"
16611 "Non-main Kernel Routing Table\n"
16612 "Instance ID/Table ID\n"
16613 "Metric for redistributed routes\n"
16614 "Default metric\n"
16615 "Route map reference\n"
16616 "Pointer to route-map entries\n")
16617 {
16618 VTY_DECLVAR_CONTEXT(bgp, bgp);
16619 int idx_ospf_table = 2;
16620 int idx_number = 3;
16621 unsigned short instance;
16622 int protocol;
16623
16624 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16625 protocol = ZEBRA_ROUTE_OSPF;
16626 else
16627 protocol = ZEBRA_ROUTE_TABLE;
16628
16629 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16630 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16631 }
16632
16633 ALIAS_HIDDEN(
16634 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16635 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16636 NO_STR
16637 "Redistribute information from another routing protocol\n"
16638 "Open Shortest Path First (OSPFv2)\n"
16639 "Non-main Kernel Routing Table\n"
16640 "Instance ID/Table ID\n"
16641 "Metric for redistributed routes\n"
16642 "Default metric\n"
16643 "Route map reference\n"
16644 "Pointer to route-map entries\n")
16645
16646 DEFUN (no_bgp_redistribute_ipv4,
16647 no_bgp_redistribute_ipv4_cmd,
16648 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16649 NO_STR
16650 "Redistribute information from another routing protocol\n"
16651 FRR_IP_REDIST_HELP_STR_BGPD
16652 "Metric for redistributed routes\n"
16653 "Default metric\n"
16654 "Route map reference\n"
16655 "Pointer to route-map entries\n")
16656 {
16657 VTY_DECLVAR_CONTEXT(bgp, bgp);
16658 int idx_protocol = 2;
16659 int type;
16660
16661 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16662 if (type < 0) {
16663 vty_out(vty, "%% Invalid route type\n");
16664 return CMD_WARNING_CONFIG_FAILED;
16665 }
16666 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16667 }
16668
16669 ALIAS_HIDDEN(
16670 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16671 "no redistribute " FRR_IP_REDIST_STR_BGPD
16672 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16673 NO_STR
16674 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16675 "Metric for redistributed routes\n"
16676 "Default metric\n"
16677 "Route map reference\n"
16678 "Pointer to route-map entries\n")
16679
16680 DEFUN (bgp_redistribute_ipv6,
16681 bgp_redistribute_ipv6_cmd,
16682 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16683 "Redistribute information from another routing protocol\n"
16684 FRR_IP6_REDIST_HELP_STR_BGPD)
16685 {
16686 VTY_DECLVAR_CONTEXT(bgp, bgp);
16687 int idx_protocol = 1;
16688 int type;
16689
16690 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16691 if (type < 0) {
16692 vty_out(vty, "%% Invalid route type\n");
16693 return CMD_WARNING_CONFIG_FAILED;
16694 }
16695
16696 bgp_redist_add(bgp, AFI_IP6, type, 0);
16697 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16698 }
16699
16700 DEFUN (bgp_redistribute_ipv6_rmap,
16701 bgp_redistribute_ipv6_rmap_cmd,
16702 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16703 "Redistribute information from another routing protocol\n"
16704 FRR_IP6_REDIST_HELP_STR_BGPD
16705 "Route map reference\n"
16706 "Pointer to route-map entries\n")
16707 {
16708 VTY_DECLVAR_CONTEXT(bgp, bgp);
16709 int idx_protocol = 1;
16710 int idx_word = 3;
16711 int type;
16712 struct bgp_redist *red;
16713 bool changed;
16714 struct route_map *route_map =
16715 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16716
16717 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16718 if (type < 0) {
16719 vty_out(vty, "%% Invalid route type\n");
16720 return CMD_WARNING_CONFIG_FAILED;
16721 }
16722
16723 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16724 changed =
16725 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16726 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16727 }
16728
16729 DEFUN (bgp_redistribute_ipv6_metric,
16730 bgp_redistribute_ipv6_metric_cmd,
16731 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16732 "Redistribute information from another routing protocol\n"
16733 FRR_IP6_REDIST_HELP_STR_BGPD
16734 "Metric for redistributed routes\n"
16735 "Default metric\n")
16736 {
16737 VTY_DECLVAR_CONTEXT(bgp, bgp);
16738 int idx_protocol = 1;
16739 int idx_number = 3;
16740 int type;
16741 uint32_t metric;
16742 struct bgp_redist *red;
16743 bool changed;
16744
16745 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16746 if (type < 0) {
16747 vty_out(vty, "%% Invalid route type\n");
16748 return CMD_WARNING_CONFIG_FAILED;
16749 }
16750 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16751
16752 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16753 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16754 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16755 }
16756
16757 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16758 bgp_redistribute_ipv6_rmap_metric_cmd,
16759 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16760 "Redistribute information from another routing protocol\n"
16761 FRR_IP6_REDIST_HELP_STR_BGPD
16762 "Route map reference\n"
16763 "Pointer to route-map entries\n"
16764 "Metric for redistributed routes\n"
16765 "Default metric\n")
16766 {
16767 VTY_DECLVAR_CONTEXT(bgp, bgp);
16768 int idx_protocol = 1;
16769 int idx_word = 3;
16770 int idx_number = 5;
16771 int type;
16772 uint32_t metric;
16773 struct bgp_redist *red;
16774 bool changed;
16775 struct route_map *route_map =
16776 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16777
16778 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16779 if (type < 0) {
16780 vty_out(vty, "%% Invalid route type\n");
16781 return CMD_WARNING_CONFIG_FAILED;
16782 }
16783 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16784
16785 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16786 changed =
16787 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16788 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16789 metric);
16790 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16791 }
16792
16793 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16794 bgp_redistribute_ipv6_metric_rmap_cmd,
16795 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16796 "Redistribute information from another routing protocol\n"
16797 FRR_IP6_REDIST_HELP_STR_BGPD
16798 "Metric for redistributed routes\n"
16799 "Default metric\n"
16800 "Route map reference\n"
16801 "Pointer to route-map entries\n")
16802 {
16803 VTY_DECLVAR_CONTEXT(bgp, bgp);
16804 int idx_protocol = 1;
16805 int idx_number = 3;
16806 int idx_word = 5;
16807 int type;
16808 uint32_t metric;
16809 struct bgp_redist *red;
16810 bool changed;
16811 struct route_map *route_map =
16812 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16813
16814 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16815 if (type < 0) {
16816 vty_out(vty, "%% Invalid route type\n");
16817 return CMD_WARNING_CONFIG_FAILED;
16818 }
16819 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16820
16821 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16822 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16823 metric);
16824 changed |=
16825 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16826 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16827 }
16828
16829 DEFUN (no_bgp_redistribute_ipv6,
16830 no_bgp_redistribute_ipv6_cmd,
16831 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16832 NO_STR
16833 "Redistribute information from another routing protocol\n"
16834 FRR_IP6_REDIST_HELP_STR_BGPD
16835 "Metric for redistributed routes\n"
16836 "Default metric\n"
16837 "Route map reference\n"
16838 "Pointer to route-map entries\n")
16839 {
16840 VTY_DECLVAR_CONTEXT(bgp, bgp);
16841 int idx_protocol = 2;
16842 int type;
16843
16844 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16845 if (type < 0) {
16846 vty_out(vty, "%% Invalid route type\n");
16847 return CMD_WARNING_CONFIG_FAILED;
16848 }
16849
16850 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16851 }
16852
16853 /* Neighbor update tcp-mss. */
16854 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16855 const char *tcp_mss_str)
16856 {
16857 struct peer *peer;
16858 uint32_t tcp_mss_val = 0;
16859
16860 peer = peer_and_group_lookup_vty(vty, peer_str);
16861 if (!peer)
16862 return CMD_WARNING_CONFIG_FAILED;
16863
16864 if (tcp_mss_str) {
16865 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16866 peer_tcp_mss_set(peer, tcp_mss_val);
16867 } else {
16868 peer_tcp_mss_unset(peer);
16869 }
16870
16871 return CMD_SUCCESS;
16872 }
16873
16874 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16875 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16876 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16877 "TCP max segment size\n"
16878 "TCP MSS value\n")
16879 {
16880 int peer_index = 1;
16881 int mss_index = 3;
16882
16883 vty_out(vty,
16884 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16885 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16886 argv[mss_index]->arg);
16887 }
16888
16889 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16890 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16891 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16892 "TCP max segment size\n"
16893 "TCP MSS value\n")
16894 {
16895 int peer_index = 2;
16896
16897 vty_out(vty,
16898 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16899 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16900 }
16901
16902 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16903 "[no$no] bgp retain route-target all",
16904 NO_STR BGP_STR
16905 "Retain BGP updates\n"
16906 "Retain BGP updates based on route-target values\n"
16907 "Retain all BGP updates\n")
16908 {
16909 bool check;
16910 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16911
16912 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16913 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16914 if (check != !no) {
16915 if (!no)
16916 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16917 [bgp_node_safi(vty)],
16918 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16919 else
16920 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16921 [bgp_node_safi(vty)],
16922 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16923 /* trigger a flush to re-sync with ADJ-RIB-in */
16924 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16925 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16926 }
16927 return CMD_SUCCESS;
16928 }
16929
16930 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16931 afi_t afi, safi_t safi)
16932 {
16933 int i;
16934
16935 /* Unicast redistribution only. */
16936 if (safi != SAFI_UNICAST)
16937 return;
16938
16939 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16940 /* Redistribute BGP does not make sense. */
16941 if (i != ZEBRA_ROUTE_BGP) {
16942 struct list *red_list;
16943 struct listnode *node;
16944 struct bgp_redist *red;
16945
16946 red_list = bgp->redist[afi][i];
16947 if (!red_list)
16948 continue;
16949
16950 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16951 /* "redistribute" configuration. */
16952 vty_out(vty, " redistribute %s",
16953 zebra_route_string(i));
16954 if (red->instance)
16955 vty_out(vty, " %d", red->instance);
16956 if (red->redist_metric_flag)
16957 vty_out(vty, " metric %u",
16958 red->redist_metric);
16959 if (red->rmap.name)
16960 vty_out(vty, " route-map %s",
16961 red->rmap.name);
16962 vty_out(vty, "\n");
16963 }
16964 }
16965 }
16966 }
16967
16968 /* peer-group helpers for config-write */
16969
16970 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16971 {
16972 if (!peer_group_active(peer)) {
16973 if (CHECK_FLAG(peer->flags_invert, flag))
16974 return !CHECK_FLAG(peer->flags, flag);
16975 else
16976 return !!CHECK_FLAG(peer->flags, flag);
16977 }
16978
16979 return !!CHECK_FLAG(peer->flags_override, flag);
16980 }
16981
16982 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16983 uint64_t flag)
16984 {
16985 if (!peer_group_active(peer)) {
16986 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16987 return !peer_af_flag_check(peer, afi, safi, flag);
16988 else
16989 return !!peer_af_flag_check(peer, afi, safi, flag);
16990 }
16991
16992 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16993 }
16994
16995 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16996 uint8_t type, int direct)
16997 {
16998 struct bgp_filter *filter;
16999
17000 if (peer_group_active(peer))
17001 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
17002 type);
17003
17004 filter = &peer->filter[afi][safi];
17005 switch (type) {
17006 case PEER_FT_DISTRIBUTE_LIST:
17007 return !!(filter->dlist[direct].name);
17008 case PEER_FT_FILTER_LIST:
17009 return !!(filter->aslist[direct].name);
17010 case PEER_FT_PREFIX_LIST:
17011 return !!(filter->plist[direct].name);
17012 case PEER_FT_ROUTE_MAP:
17013 return !!(filter->map[direct].name);
17014 case PEER_FT_UNSUPPRESS_MAP:
17015 return !!(filter->usmap.name);
17016 case PEER_FT_ADVERTISE_MAP:
17017 return !!(filter->advmap.aname
17018 && ((filter->advmap.condition == direct)
17019 && filter->advmap.cname));
17020 default:
17021 return false;
17022 }
17023 }
17024
17025 /* Return true if the addpath type is set for peer and different from
17026 * peer-group.
17027 */
17028 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
17029 safi_t safi)
17030 {
17031 enum bgp_addpath_strat type, g_type;
17032
17033 type = peer->addpath_type[afi][safi];
17034
17035 if (type != BGP_ADDPATH_NONE) {
17036 if (peer_group_active(peer)) {
17037 g_type = peer->group->conf->addpath_type[afi][safi];
17038
17039 if (type != g_type)
17040 return true;
17041 else
17042 return false;
17043 }
17044
17045 return true;
17046 }
17047
17048 return false;
17049 }
17050
17051 /* This is part of the address-family block (unicast only) */
17052 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
17053 afi_t afi)
17054 {
17055 int indent = 2;
17056 uint32_t tovpn_sid_index = 0;
17057
17058 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
17059 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17060 BGP_CONFIG_VRF_TO_VRF_IMPORT))
17061 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17062 bgp->vpn_policy[afi]
17063 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17064 else
17065 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17066 bgp->vpn_policy[afi]
17067 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17068 }
17069 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17070 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17071 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17072 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17073 return;
17074
17075 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17076 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17077
17078 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17079
17080 } else {
17081 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17082 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17083 bgp->vpn_policy[afi].tovpn_label);
17084 }
17085 }
17086
17087 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17088 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17089 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17090 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17091 } else if (tovpn_sid_index != 0) {
17092 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17093 tovpn_sid_index);
17094 }
17095
17096 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17097 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
17098 &bgp->vpn_policy[afi].tovpn_rd);
17099
17100 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17101 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17102
17103 char buf[PREFIX_STRLEN];
17104 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17105 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17106 sizeof(buf))) {
17107
17108 vty_out(vty, "%*snexthop vpn export %s\n",
17109 indent, "", buf);
17110 }
17111 }
17112 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17113 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17114 && ecommunity_cmp(
17115 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17116 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17117
17118 char *b = ecommunity_ecom2str(
17119 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17120 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17121 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17122 XFREE(MTYPE_ECOMMUNITY_STR, b);
17123 } else {
17124 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17125 char *b = ecommunity_ecom2str(
17126 bgp->vpn_policy[afi]
17127 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17128 ECOMMUNITY_FORMAT_ROUTE_MAP,
17129 ECOMMUNITY_ROUTE_TARGET);
17130 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17131 XFREE(MTYPE_ECOMMUNITY_STR, b);
17132 }
17133 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17134 char *b = ecommunity_ecom2str(
17135 bgp->vpn_policy[afi]
17136 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17137 ECOMMUNITY_FORMAT_ROUTE_MAP,
17138 ECOMMUNITY_ROUTE_TARGET);
17139 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17140 XFREE(MTYPE_ECOMMUNITY_STR, b);
17141 }
17142 }
17143
17144 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17145 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17146 bgp->vpn_policy[afi]
17147 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17148
17149 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17150 char *b = ecommunity_ecom2str(
17151 bgp->vpn_policy[afi]
17152 .import_redirect_rtlist,
17153 ECOMMUNITY_FORMAT_ROUTE_MAP,
17154 ECOMMUNITY_ROUTE_TARGET);
17155
17156 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17157 != ECOMMUNITY_SIZE)
17158 vty_out(vty, "%*srt6 redirect import %s\n",
17159 indent, "", b);
17160 else
17161 vty_out(vty, "%*srt redirect import %s\n",
17162 indent, "", b);
17163 XFREE(MTYPE_ECOMMUNITY_STR, b);
17164 }
17165 }
17166
17167 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17168 afi_t afi, safi_t safi)
17169 {
17170 struct bgp_filter *filter;
17171 char *addr;
17172
17173 addr = peer->host;
17174 filter = &peer->filter[afi][safi];
17175
17176 /* distribute-list. */
17177 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17178 FILTER_IN))
17179 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17180 filter->dlist[FILTER_IN].name);
17181
17182 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17183 FILTER_OUT))
17184 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17185 filter->dlist[FILTER_OUT].name);
17186
17187 /* prefix-list. */
17188 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17189 FILTER_IN))
17190 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17191 filter->plist[FILTER_IN].name);
17192
17193 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17194 FILTER_OUT))
17195 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17196 filter->plist[FILTER_OUT].name);
17197
17198 /* route-map. */
17199 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17200 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17201 filter->map[RMAP_IN].name);
17202
17203 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17204 RMAP_OUT))
17205 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17206 filter->map[RMAP_OUT].name);
17207
17208 /* unsuppress-map */
17209 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17210 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17211 filter->usmap.name);
17212
17213 /* advertise-map : always applied in OUT direction*/
17214 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17215 CONDITION_NON_EXIST))
17216 vty_out(vty,
17217 " neighbor %s advertise-map %s non-exist-map %s\n",
17218 addr, filter->advmap.aname, filter->advmap.cname);
17219
17220 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17221 CONDITION_EXIST))
17222 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17223 addr, filter->advmap.aname, filter->advmap.cname);
17224
17225 /* filter-list. */
17226 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17227 FILTER_IN))
17228 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17229 filter->aslist[FILTER_IN].name);
17230
17231 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17232 FILTER_OUT))
17233 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17234 filter->aslist[FILTER_OUT].name);
17235 }
17236
17237 /* BGP peer configuration display function. */
17238 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17239 struct peer *peer)
17240 {
17241 struct peer *g_peer = NULL;
17242 char *addr;
17243 int if_pg_printed = false;
17244 int if_ras_printed = false;
17245
17246 /* Skip dynamic neighbors. */
17247 if (peer_dynamic_neighbor(peer))
17248 return;
17249
17250 if (peer->conf_if)
17251 addr = peer->conf_if;
17252 else
17253 addr = peer->host;
17254
17255 /************************************
17256 ****** Global to the neighbor ******
17257 ************************************/
17258 if (peer->conf_if) {
17259 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17260 vty_out(vty, " neighbor %s interface v6only", addr);
17261 else
17262 vty_out(vty, " neighbor %s interface", addr);
17263
17264 if (peer_group_active(peer)) {
17265 vty_out(vty, " peer-group %s", peer->group->name);
17266 if_pg_printed = true;
17267 } else if (peer->as_type == AS_SPECIFIED) {
17268 vty_out(vty, " remote-as %u", peer->as);
17269 if_ras_printed = true;
17270 } else if (peer->as_type == AS_INTERNAL) {
17271 vty_out(vty, " remote-as internal");
17272 if_ras_printed = true;
17273 } else if (peer->as_type == AS_EXTERNAL) {
17274 vty_out(vty, " remote-as external");
17275 if_ras_printed = true;
17276 }
17277
17278 vty_out(vty, "\n");
17279 }
17280
17281 /* remote-as and peer-group */
17282 /* peer is a member of a peer-group */
17283 if (peer_group_active(peer)) {
17284 g_peer = peer->group->conf;
17285
17286 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17287 if (peer->as_type == AS_SPECIFIED) {
17288 vty_out(vty, " neighbor %s remote-as %u\n",
17289 addr, peer->as);
17290 } else if (peer->as_type == AS_INTERNAL) {
17291 vty_out(vty,
17292 " neighbor %s remote-as internal\n",
17293 addr);
17294 } else if (peer->as_type == AS_EXTERNAL) {
17295 vty_out(vty,
17296 " neighbor %s remote-as external\n",
17297 addr);
17298 }
17299 }
17300
17301 /* For swpX peers we displayed the peer-group
17302 * via 'neighbor swpX interface peer-group PGNAME' */
17303 if (!if_pg_printed)
17304 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17305 peer->group->name);
17306 }
17307
17308 /* peer is NOT a member of a peer-group */
17309 else {
17310 /* peer is a peer-group, declare the peer-group */
17311 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17312 vty_out(vty, " neighbor %s peer-group\n", addr);
17313 }
17314
17315 if (!if_ras_printed) {
17316 if (peer->as_type == AS_SPECIFIED) {
17317 vty_out(vty, " neighbor %s remote-as %u\n",
17318 addr, peer->as);
17319 } else if (peer->as_type == AS_INTERNAL) {
17320 vty_out(vty,
17321 " neighbor %s remote-as internal\n",
17322 addr);
17323 } else if (peer->as_type == AS_EXTERNAL) {
17324 vty_out(vty,
17325 " neighbor %s remote-as external\n",
17326 addr);
17327 }
17328 }
17329 }
17330
17331 /* local-as */
17332 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17333 vty_out(vty, " neighbor %s local-as %u", addr,
17334 peer->change_local_as);
17335 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17336 vty_out(vty, " no-prepend");
17337 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17338 vty_out(vty, " replace-as");
17339 vty_out(vty, "\n");
17340 }
17341
17342 /* description */
17343 if (peer->desc) {
17344 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17345 }
17346
17347 /* shutdown */
17348 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17349 if (peer->tx_shutdown_message)
17350 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17351 peer->tx_shutdown_message);
17352 else
17353 vty_out(vty, " neighbor %s shutdown\n", addr);
17354 }
17355
17356 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17357 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17358 peer->rtt_expected, peer->rtt_keepalive_conf);
17359
17360 /* bfd */
17361 if (peer->bfd_config)
17362 bgp_bfd_peer_config_write(vty, peer, addr);
17363
17364 /* password */
17365 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17366 vty_out(vty, " neighbor %s password %s\n", addr,
17367 peer->password);
17368
17369 /* neighbor solo */
17370 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17371 if (!peer_group_active(peer)) {
17372 vty_out(vty, " neighbor %s solo\n", addr);
17373 }
17374 }
17375
17376 /* BGP port */
17377 if (peer->port != BGP_PORT_DEFAULT) {
17378 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17379 }
17380
17381 /* Local interface name */
17382 if (peer->ifname) {
17383 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17384 }
17385
17386 /* TCP max segment size */
17387 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17388 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17389
17390 /* passive */
17391 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17392 vty_out(vty, " neighbor %s passive\n", addr);
17393
17394 /* ebgp-multihop */
17395 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17396 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17397 && peer->ttl == MAXTTL)) {
17398 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17399 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17400 peer->ttl);
17401 }
17402 }
17403
17404 /* aigp */
17405 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17406 vty_out(vty, " neighbor %s aigp\n", addr);
17407
17408 /* graceful-shutdown */
17409 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17410 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17411
17412 /* role */
17413 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17414 peer->local_role != ROLE_UNDEFINED)
17415 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17416 bgp_get_name_by_role(peer->local_role),
17417 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17418 ? " strict-mode"
17419 : "");
17420
17421 /* ttl-security hops */
17422 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17423 if (!peer_group_active(peer)
17424 || g_peer->gtsm_hops != peer->gtsm_hops) {
17425 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17426 addr, peer->gtsm_hops);
17427 }
17428 }
17429
17430 /* disable-connected-check */
17431 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17432 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17433
17434 /* link-bw-encoding-ieee */
17435 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17436 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17437 addr);
17438
17439 /* extended-optional-parameters */
17440 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17441 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17442 addr);
17443
17444 /* enforce-first-as */
17445 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17446 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17447
17448 /* update-source */
17449 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17450 if (peer->update_source)
17451 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17452 peer->update_source);
17453 else if (peer->update_if)
17454 vty_out(vty, " neighbor %s update-source %s\n", addr,
17455 peer->update_if);
17456 }
17457
17458 /* advertisement-interval */
17459 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17460 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17461 peer->routeadv);
17462
17463 /* timers */
17464 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17465 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17466 peer->keepalive, peer->holdtime);
17467
17468 /* timers connect */
17469 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17470 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17471 peer->connect);
17472 /* need special-case handling for changed default values due to
17473 * config profile / version (because there is no "timers bgp connect"
17474 * command, we need to save this per-peer :/)
17475 */
17476 else if (!peer_group_active(peer) && !peer->connect &&
17477 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17478 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17479 peer->bgp->default_connect_retry);
17480
17481 /* timers delayopen */
17482 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17483 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17484 peer->delayopen);
17485 /* Save config even though flag is not set if default values have been
17486 * changed
17487 */
17488 else if (!peer_group_active(peer) && !peer->delayopen
17489 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17490 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17491 peer->bgp->default_delayopen);
17492
17493 /* capability dynamic */
17494 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17495 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17496
17497 /* capability extended-nexthop */
17498 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17499 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17500 !peer->conf_if)
17501 vty_out(vty,
17502 " no neighbor %s capability extended-nexthop\n",
17503 addr);
17504 else if (!peer->conf_if)
17505 vty_out(vty,
17506 " neighbor %s capability extended-nexthop\n",
17507 addr);
17508 }
17509
17510 /* dont-capability-negotiation */
17511 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17512 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17513
17514 /* override-capability */
17515 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17516 vty_out(vty, " neighbor %s override-capability\n", addr);
17517
17518 /* strict-capability-match */
17519 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17520 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17521
17522 /* Sender side AS path loop detection. */
17523 if (peer->as_path_loop_detection)
17524 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17525 addr);
17526
17527 /* path-attribute discard */
17528 char discard_attrs_str[BUFSIZ] = {0};
17529 bool discard_attrs = bgp_path_attribute_discard(
17530 peer, discard_attrs_str, sizeof(discard_attrs_str));
17531
17532 if (discard_attrs)
17533 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17534 discard_attrs_str);
17535
17536 /* path-attribute treat-as-withdraw */
17537 char withdraw_attrs_str[BUFSIZ] = {0};
17538 bool withdraw_attrs = bgp_path_attribute_treat_as_withdraw(
17539 peer, withdraw_attrs_str, sizeof(withdraw_attrs_str));
17540
17541 if (withdraw_attrs)
17542 vty_out(vty,
17543 " neighbor %s path-attribute treat-as-withdraw %s\n",
17544 addr, withdraw_attrs_str);
17545
17546 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17547 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17548
17549 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17550 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17551 vty_out(vty,
17552 " neighbor %s graceful-restart-helper\n", addr);
17553 } else if (CHECK_FLAG(
17554 peer->peer_gr_new_status_flag,
17555 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17556 vty_out(vty,
17557 " neighbor %s graceful-restart\n", addr);
17558 } else if (
17559 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17560 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17561 && !(CHECK_FLAG(
17562 peer->peer_gr_new_status_flag,
17563 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17564 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17565 addr);
17566 }
17567 }
17568 }
17569
17570 /* BGP peer configuration display function. */
17571 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17572 struct peer *peer, afi_t afi, safi_t safi)
17573 {
17574 struct peer *g_peer = NULL;
17575 char *addr;
17576 bool flag_scomm, flag_secomm, flag_slcomm;
17577
17578 /* Skip dynamic neighbors. */
17579 if (peer_dynamic_neighbor(peer))
17580 return;
17581
17582 if (peer->conf_if)
17583 addr = peer->conf_if;
17584 else
17585 addr = peer->host;
17586
17587 /************************************
17588 ****** Per AF to the neighbor ******
17589 ************************************/
17590 if (peer_group_active(peer)) {
17591 g_peer = peer->group->conf;
17592
17593 /* If the peer-group is active but peer is not, print a 'no
17594 * activate' */
17595 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17596 vty_out(vty, " no neighbor %s activate\n", addr);
17597 }
17598
17599 /* If the peer-group is not active but peer is, print an
17600 'activate' */
17601 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17602 vty_out(vty, " neighbor %s activate\n", addr);
17603 }
17604 } else {
17605 if (peer->afc[afi][safi]) {
17606 if (safi == SAFI_ENCAP)
17607 vty_out(vty, " neighbor %s activate\n", addr);
17608 else if (!bgp->default_af[afi][safi])
17609 vty_out(vty, " neighbor %s activate\n", addr);
17610 } else {
17611 if (bgp->default_af[afi][safi])
17612 vty_out(vty, " no neighbor %s activate\n",
17613 addr);
17614 }
17615 }
17616
17617 /* addpath TX knobs */
17618 if (peergroup_af_addpath_check(peer, afi, safi)) {
17619 switch (peer->addpath_type[afi][safi]) {
17620 case BGP_ADDPATH_ALL:
17621 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17622 addr);
17623 break;
17624 case BGP_ADDPATH_BEST_PER_AS:
17625 vty_out(vty,
17626 " neighbor %s addpath-tx-bestpath-per-AS\n",
17627 addr);
17628 break;
17629 case BGP_ADDPATH_MAX:
17630 case BGP_ADDPATH_NONE:
17631 break;
17632 }
17633 }
17634
17635 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17636 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17637
17638 /* ORF capability. */
17639 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17640 || peergroup_af_flag_check(peer, afi, safi,
17641 PEER_FLAG_ORF_PREFIX_RM)) {
17642 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17643
17644 if (peergroup_af_flag_check(peer, afi, safi,
17645 PEER_FLAG_ORF_PREFIX_SM)
17646 && peergroup_af_flag_check(peer, afi, safi,
17647 PEER_FLAG_ORF_PREFIX_RM))
17648 vty_out(vty, " both");
17649 else if (peergroup_af_flag_check(peer, afi, safi,
17650 PEER_FLAG_ORF_PREFIX_SM))
17651 vty_out(vty, " send");
17652 else
17653 vty_out(vty, " receive");
17654 vty_out(vty, "\n");
17655 }
17656
17657 /* Route reflector client. */
17658 if (peergroup_af_flag_check(peer, afi, safi,
17659 PEER_FLAG_REFLECTOR_CLIENT)) {
17660 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17661 }
17662
17663 /* next-hop-self force */
17664 if (peergroup_af_flag_check(peer, afi, safi,
17665 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17666 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17667 }
17668
17669 /* next-hop-self */
17670 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17671 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17672 }
17673
17674 /* remove-private-AS */
17675 if (peergroup_af_flag_check(peer, afi, safi,
17676 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17677 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17678 addr);
17679 }
17680
17681 else if (peergroup_af_flag_check(peer, afi, safi,
17682 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17683 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17684 addr);
17685 }
17686
17687 else if (peergroup_af_flag_check(peer, afi, safi,
17688 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17689 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17690 }
17691
17692 else if (peergroup_af_flag_check(peer, afi, safi,
17693 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17694 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17695 }
17696
17697 /* as-override */
17698 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17699 vty_out(vty, " neighbor %s as-override\n", addr);
17700 }
17701
17702 /* send-community print. */
17703 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17704 PEER_FLAG_SEND_COMMUNITY);
17705 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17706 PEER_FLAG_SEND_EXT_COMMUNITY);
17707 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17708 PEER_FLAG_SEND_LARGE_COMMUNITY);
17709
17710 if (flag_scomm && flag_secomm && flag_slcomm) {
17711 vty_out(vty, " no neighbor %s send-community all\n", addr);
17712 } else {
17713 if (flag_scomm)
17714 vty_out(vty, " no neighbor %s send-community\n", addr);
17715 if (flag_secomm)
17716 vty_out(vty,
17717 " no neighbor %s send-community extended\n",
17718 addr);
17719
17720 if (flag_slcomm)
17721 vty_out(vty, " no neighbor %s send-community large\n",
17722 addr);
17723 }
17724
17725 /* Default information */
17726 if (peergroup_af_flag_check(peer, afi, safi,
17727 PEER_FLAG_DEFAULT_ORIGINATE)) {
17728 vty_out(vty, " neighbor %s default-originate", addr);
17729
17730 if (peer->default_rmap[afi][safi].name)
17731 vty_out(vty, " route-map %s",
17732 peer->default_rmap[afi][safi].name);
17733
17734 vty_out(vty, "\n");
17735 }
17736
17737 /* Soft reconfiguration inbound. */
17738 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17739 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17740 addr);
17741 }
17742
17743 /* maximum-prefix. */
17744 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17745 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17746 peer->pmax[afi][safi]);
17747
17748 if (peer->pmax_threshold[afi][safi]
17749 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17750 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17751 if (peer_af_flag_check(peer, afi, safi,
17752 PEER_FLAG_MAX_PREFIX_WARNING))
17753 vty_out(vty, " warning-only");
17754 if (peer->pmax_restart[afi][safi])
17755 vty_out(vty, " restart %u",
17756 peer->pmax_restart[afi][safi]);
17757 if (peer_af_flag_check(peer, afi, safi,
17758 PEER_FLAG_MAX_PREFIX_FORCE))
17759 vty_out(vty, " force");
17760
17761 vty_out(vty, "\n");
17762 }
17763
17764 /* maximum-prefix-out */
17765 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17766 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17767 addr, peer->pmax_out[afi][safi]);
17768
17769 /* Route server client. */
17770 if (peergroup_af_flag_check(peer, afi, safi,
17771 PEER_FLAG_RSERVER_CLIENT)) {
17772 vty_out(vty, " neighbor %s route-server-client\n", addr);
17773 }
17774
17775 /* Nexthop-local unchanged. */
17776 if (peergroup_af_flag_check(peer, afi, safi,
17777 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17778 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17779 }
17780
17781 /* allowas-in <1-10> */
17782 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17783 if (peer_af_flag_check(peer, afi, safi,
17784 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17785 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17786 } else if (peer->allowas_in[afi][safi] == 3) {
17787 vty_out(vty, " neighbor %s allowas-in\n", addr);
17788 } else {
17789 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17790 peer->allowas_in[afi][safi]);
17791 }
17792 }
17793
17794 /* accept-own */
17795 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17796 vty_out(vty, " neighbor %s accept-own\n", addr);
17797
17798 /* soo */
17799 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17800 char *soo_str = ecommunity_ecom2str(
17801 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17802
17803 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17804 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17805 }
17806
17807 /* weight */
17808 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17809 vty_out(vty, " neighbor %s weight %lu\n", addr,
17810 peer->weight[afi][safi]);
17811
17812 /* Filter. */
17813 bgp_config_write_filter(vty, peer, afi, safi);
17814
17815 /* atribute-unchanged. */
17816 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17817 || (safi != SAFI_EVPN
17818 && peer_af_flag_check(peer, afi, safi,
17819 PEER_FLAG_NEXTHOP_UNCHANGED))
17820 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17821
17822 if (!peer_group_active(peer)
17823 || peergroup_af_flag_check(peer, afi, safi,
17824 PEER_FLAG_AS_PATH_UNCHANGED)
17825 || peergroup_af_flag_check(peer, afi, safi,
17826 PEER_FLAG_NEXTHOP_UNCHANGED)
17827 || peergroup_af_flag_check(peer, afi, safi,
17828 PEER_FLAG_MED_UNCHANGED)) {
17829
17830 vty_out(vty,
17831 " neighbor %s attribute-unchanged%s%s%s\n",
17832 addr,
17833 peer_af_flag_check(peer, afi, safi,
17834 PEER_FLAG_AS_PATH_UNCHANGED)
17835 ? " as-path"
17836 : "",
17837 peer_af_flag_check(peer, afi, safi,
17838 PEER_FLAG_NEXTHOP_UNCHANGED)
17839 ? " next-hop"
17840 : "",
17841 peer_af_flag_check(peer, afi, safi,
17842 PEER_FLAG_MED_UNCHANGED)
17843 ? " med"
17844 : "");
17845 }
17846 }
17847 }
17848
17849 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17850 safi_t safi)
17851 {
17852 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17853 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17854 vty_out(vty, " no bgp retain route-target all\n");
17855 }
17856
17857 /* Address family based peer configuration display. */
17858 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17859 safi_t safi)
17860 {
17861 struct peer *peer;
17862 struct peer_group *group;
17863 struct listnode *node, *nnode;
17864
17865
17866 vty_frame(vty, " !\n address-family ");
17867 if (afi == AFI_IP) {
17868 if (safi == SAFI_UNICAST)
17869 vty_frame(vty, "ipv4 unicast");
17870 else if (safi == SAFI_LABELED_UNICAST)
17871 vty_frame(vty, "ipv4 labeled-unicast");
17872 else if (safi == SAFI_MULTICAST)
17873 vty_frame(vty, "ipv4 multicast");
17874 else if (safi == SAFI_MPLS_VPN)
17875 vty_frame(vty, "ipv4 vpn");
17876 else if (safi == SAFI_ENCAP)
17877 vty_frame(vty, "ipv4 encap");
17878 else if (safi == SAFI_FLOWSPEC)
17879 vty_frame(vty, "ipv4 flowspec");
17880 } else if (afi == AFI_IP6) {
17881 if (safi == SAFI_UNICAST)
17882 vty_frame(vty, "ipv6 unicast");
17883 else if (safi == SAFI_LABELED_UNICAST)
17884 vty_frame(vty, "ipv6 labeled-unicast");
17885 else if (safi == SAFI_MULTICAST)
17886 vty_frame(vty, "ipv6 multicast");
17887 else if (safi == SAFI_MPLS_VPN)
17888 vty_frame(vty, "ipv6 vpn");
17889 else if (safi == SAFI_ENCAP)
17890 vty_frame(vty, "ipv6 encap");
17891 else if (safi == SAFI_FLOWSPEC)
17892 vty_frame(vty, "ipv6 flowspec");
17893 } else if (afi == AFI_L2VPN) {
17894 if (safi == SAFI_EVPN)
17895 vty_frame(vty, "l2vpn evpn");
17896 }
17897 vty_frame(vty, "\n");
17898
17899 bgp_config_write_distance(vty, bgp, afi, safi);
17900
17901 bgp_config_write_network(vty, bgp, afi, safi);
17902
17903 bgp_config_write_redistribute(vty, bgp, afi, safi);
17904
17905 /* BGP flag dampening. */
17906 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17907 bgp_config_write_damp(vty, afi, safi);
17908
17909 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17910 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17911
17912 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17913 /* Do not display doppelganger peers */
17914 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17915 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17916 }
17917
17918 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17919 bgp_config_write_table_map(vty, bgp, afi, safi);
17920
17921 if (safi == SAFI_EVPN)
17922 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17923
17924 if (safi == SAFI_FLOWSPEC)
17925 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17926
17927 if (safi == SAFI_MPLS_VPN)
17928 bgp_vpn_config_write(vty, bgp, afi, safi);
17929
17930 if (safi == SAFI_UNICAST) {
17931 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17932 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17933 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17934
17935 vty_out(vty, " export vpn\n");
17936 }
17937 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17938 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17939
17940 vty_out(vty, " import vpn\n");
17941 }
17942 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17943 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17944 char *name;
17945
17946 for (ALL_LIST_ELEMENTS_RO(
17947 bgp->vpn_policy[afi].import_vrf, node,
17948 name))
17949 vty_out(vty, " import vrf %s\n", name);
17950 }
17951 }
17952
17953 vty_endframe(vty, " exit-address-family\n");
17954 }
17955
17956 int bgp_config_write(struct vty *vty)
17957 {
17958 struct bgp *bgp;
17959 struct peer_group *group;
17960 struct peer *peer;
17961 struct listnode *node, *nnode;
17962 struct listnode *mnode, *mnnode;
17963 afi_t afi;
17964 safi_t safi;
17965 uint32_t tovpn_sid_index = 0;
17966
17967 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17968 vty_out(vty, "bgp route-map delay-timer %u\n",
17969 bm->rmap_update_timer);
17970
17971 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17972 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17973 if (bm->v_update_delay != bm->v_establish_wait)
17974 vty_out(vty, " %d", bm->v_establish_wait);
17975 vty_out(vty, "\n");
17976 }
17977
17978 if (bm->wait_for_fib)
17979 vty_out(vty, "bgp suppress-fib-pending\n");
17980
17981 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17982 vty_out(vty, "bgp graceful-shutdown\n");
17983
17984 /* No-RIB (Zebra) option flag configuration */
17985 if (bgp_option_check(BGP_OPT_NO_FIB))
17986 vty_out(vty, "bgp no-rib\n");
17987
17988 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17989 vty_out(vty, "bgp send-extra-data zebra\n");
17990
17991 /* BGP session DSCP value */
17992 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17993 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17994
17995 /* BGP InQ limit */
17996 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
17997 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17998
17999 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
18000 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
18001
18002 /* BGP configuration. */
18003 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
18004
18005 /* skip all auto created vrf as they dont have user config */
18006 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
18007 continue;
18008
18009 /* Router bgp ASN */
18010 vty_out(vty, "router bgp %u", bgp->as);
18011
18012 if (bgp->name)
18013 vty_out(vty, " %s %s",
18014 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
18015 ? "view" : "vrf", bgp->name);
18016 vty_out(vty, "\n");
18017
18018 /* BGP fast-external-failover. */
18019 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
18020 vty_out(vty, " no bgp fast-external-failover\n");
18021
18022 /* BGP router ID. */
18023 if (bgp->router_id_static.s_addr != INADDR_ANY)
18024 vty_out(vty, " bgp router-id %pI4\n",
18025 &bgp->router_id_static);
18026
18027 /* Suppress fib pending */
18028 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
18029 vty_out(vty, " bgp suppress-fib-pending\n");
18030
18031 /* BGP log-neighbor-changes. */
18032 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
18033 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
18034 vty_out(vty, " %sbgp log-neighbor-changes\n",
18035 CHECK_FLAG(bgp->flags,
18036 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
18037 ? ""
18038 : "no ");
18039
18040 /* BGP configuration. */
18041 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
18042 vty_out(vty, " bgp always-compare-med\n");
18043
18044 /* RFC8212 default eBGP policy. */
18045 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
18046 != SAVE_BGP_EBGP_REQUIRES_POLICY)
18047 vty_out(vty, " %sbgp ebgp-requires-policy\n",
18048 CHECK_FLAG(bgp->flags,
18049 BGP_FLAG_EBGP_REQUIRES_POLICY)
18050 ? ""
18051 : "no ");
18052
18053 /* draft-ietf-idr-deprecate-as-set-confed-set */
18054 if (bgp->reject_as_sets)
18055 vty_out(vty, " bgp reject-as-sets\n");
18056
18057 /* Suppress duplicate updates if the route actually not changed
18058 */
18059 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
18060 != SAVE_BGP_SUPPRESS_DUPLICATES)
18061 vty_out(vty, " %sbgp suppress-duplicates\n",
18062 CHECK_FLAG(bgp->flags,
18063 BGP_FLAG_SUPPRESS_DUPLICATES)
18064 ? ""
18065 : "no ");
18066
18067 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18068 */
18069 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18070 SAVE_BGP_HARD_ADMIN_RESET)
18071 vty_out(vty, " %sbgp hard-administrative-reset\n",
18072 CHECK_FLAG(bgp->flags,
18073 BGP_FLAG_HARD_ADMIN_RESET)
18074 ? ""
18075 : "no ");
18076
18077 /* BGP default <afi>-<safi> */
18078 FOREACH_AFI_SAFI (afi, safi) {
18079 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18080 if (!bgp->default_af[afi][safi])
18081 vty_out(vty, " no bgp default %s\n",
18082 get_bgp_default_af_flag(afi,
18083 safi));
18084 } else if (bgp->default_af[afi][safi])
18085 vty_out(vty, " bgp default %s\n",
18086 get_bgp_default_af_flag(afi, safi));
18087 }
18088
18089 /* BGP default local-preference. */
18090 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18091 vty_out(vty, " bgp default local-preference %u\n",
18092 bgp->default_local_pref);
18093
18094 /* BGP default show-hostname */
18095 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18096 != SAVE_BGP_SHOW_HOSTNAME)
18097 vty_out(vty, " %sbgp default show-hostname\n",
18098 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18099 ? ""
18100 : "no ");
18101
18102 /* BGP default show-nexthop-hostname */
18103 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18104 != SAVE_BGP_SHOW_HOSTNAME)
18105 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18106 CHECK_FLAG(bgp->flags,
18107 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18108 ? ""
18109 : "no ");
18110
18111 /* BGP default subgroup-pkt-queue-max. */
18112 if (bgp->default_subgroup_pkt_queue_max
18113 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18114 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18115 bgp->default_subgroup_pkt_queue_max);
18116
18117 /* BGP client-to-client reflection. */
18118 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
18119 vty_out(vty, " no bgp client-to-client reflection\n");
18120
18121 /* BGP cluster ID. */
18122 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
18123 vty_out(vty, " bgp cluster-id %pI4\n",
18124 &bgp->cluster_id);
18125
18126 /* Disable ebgp connected nexthop check */
18127 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
18128 vty_out(vty,
18129 " bgp disable-ebgp-connected-route-check\n");
18130
18131 /* Confederation identifier*/
18132 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18133 vty_out(vty, " bgp confederation identifier %u\n",
18134 bgp->confed_id);
18135
18136 /* Confederation peer */
18137 if (bgp->confed_peers_cnt > 0) {
18138 int i;
18139
18140 vty_out(vty, " bgp confederation peers");
18141
18142 for (i = 0; i < bgp->confed_peers_cnt; i++)
18143 vty_out(vty, " %u", bgp->confed_peers[i]);
18144
18145 vty_out(vty, "\n");
18146 }
18147
18148 /* BGP deterministic-med. */
18149 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18150 != SAVE_BGP_DETERMINISTIC_MED)
18151 vty_out(vty, " %sbgp deterministic-med\n",
18152 CHECK_FLAG(bgp->flags,
18153 BGP_FLAG_DETERMINISTIC_MED)
18154 ? ""
18155 : "no ");
18156
18157 /* BGP update-delay. */
18158 bgp_config_write_update_delay(vty, bgp);
18159
18160 if (bgp->v_maxmed_onstartup
18161 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18162 vty_out(vty, " bgp max-med on-startup %u",
18163 bgp->v_maxmed_onstartup);
18164 if (bgp->maxmed_onstartup_value
18165 != BGP_MAXMED_VALUE_DEFAULT)
18166 vty_out(vty, " %u",
18167 bgp->maxmed_onstartup_value);
18168 vty_out(vty, "\n");
18169 }
18170 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18171 vty_out(vty, " bgp max-med administrative");
18172 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18173 vty_out(vty, " %u", bgp->maxmed_admin_value);
18174 vty_out(vty, "\n");
18175 }
18176
18177 /* write quanta */
18178 bgp_config_write_wpkt_quanta(vty, bgp);
18179 /* read quanta */
18180 bgp_config_write_rpkt_quanta(vty, bgp);
18181
18182 /* coalesce time */
18183 bgp_config_write_coalesce_time(vty, bgp);
18184
18185 /* BGP per-instance graceful-shutdown */
18186 /* BGP-wide settings and per-instance settings are mutually
18187 * exclusive.
18188 */
18189 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18190 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18191 vty_out(vty, " bgp graceful-shutdown\n");
18192
18193 /* Long-lived Graceful Restart */
18194 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18195 vty_out(vty,
18196 " bgp long-lived-graceful-restart stale-time %u\n",
18197 bgp->llgr_stale_time);
18198
18199 /* BGP graceful-restart. */
18200 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18201 vty_out(vty,
18202 " bgp graceful-restart stalepath-time %u\n",
18203 bgp->stalepath_time);
18204
18205 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18206 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18207 bgp->restart_time);
18208
18209 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18210 SAVE_BGP_GRACEFUL_NOTIFICATION)
18211 vty_out(vty, " %sbgp graceful-restart notification\n",
18212 CHECK_FLAG(bgp->flags,
18213 BGP_FLAG_GRACEFUL_NOTIFICATION)
18214 ? ""
18215 : "no ");
18216
18217 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18218 vty_out(vty,
18219 " bgp graceful-restart select-defer-time %u\n",
18220 bgp->select_defer_time);
18221
18222 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18223 vty_out(vty, " bgp graceful-restart\n");
18224
18225 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18226 vty_out(vty, " bgp graceful-restart-disable\n");
18227
18228 /* BGP graceful-restart Preserve State F bit. */
18229 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18230 vty_out(vty,
18231 " bgp graceful-restart preserve-fw-state\n");
18232
18233 /* BGP TCP keepalive */
18234 bgp_config_tcp_keepalive(vty, bgp);
18235
18236 /* Stale timer for RIB */
18237 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18238 vty_out(vty,
18239 " bgp graceful-restart rib-stale-time %u\n",
18240 bgp->rib_stale_time);
18241
18242 /* BGP bestpath method. */
18243 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18244 vty_out(vty, " bgp bestpath as-path ignore\n");
18245 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18246 vty_out(vty, " bgp bestpath as-path confed\n");
18247
18248 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18249 if (CHECK_FLAG(bgp->flags,
18250 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18251 vty_out(vty,
18252 " bgp bestpath as-path multipath-relax as-set\n");
18253 } else {
18254 vty_out(vty,
18255 " bgp bestpath as-path multipath-relax\n");
18256 }
18257 }
18258
18259 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18260 vty_out(vty,
18261 " bgp route-reflector allow-outbound-policy\n");
18262 }
18263 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18264 vty_out(vty, " bgp bestpath compare-routerid\n");
18265 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18266 vty_out(vty, " bgp bestpath aigp\n");
18267 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18268 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18269 vty_out(vty, " bgp bestpath med");
18270 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18271 vty_out(vty, " confed");
18272 if (CHECK_FLAG(bgp->flags,
18273 BGP_FLAG_MED_MISSING_AS_WORST))
18274 vty_out(vty, " missing-as-worst");
18275 vty_out(vty, "\n");
18276 }
18277
18278 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18279 vty_out(vty,
18280 " bgp bestpath peer-type multipath-relax\n");
18281
18282 /* Link bandwidth handling. */
18283 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18284 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18285 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18286 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18287 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18288 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18289
18290 /* BGP network import check. */
18291 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18292 != SAVE_BGP_IMPORT_CHECK)
18293 vty_out(vty, " %sbgp network import-check\n",
18294 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18295 ? ""
18296 : "no ");
18297
18298 /* BGP timers configuration. */
18299 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18300 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18301 vty_out(vty, " timers bgp %u %u\n",
18302 bgp->default_keepalive, bgp->default_holdtime);
18303
18304 /* BGP minimum holdtime configuration. */
18305 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18306 && bgp->default_min_holdtime != 0)
18307 vty_out(vty, " bgp minimum-holdtime %u\n",
18308 bgp->default_min_holdtime);
18309
18310 /* Conditional advertisement timer configuration */
18311 if (bgp->condition_check_period
18312 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18313 vty_out(vty,
18314 " bgp conditional-advertisement timer %u\n",
18315 bgp->condition_check_period);
18316
18317 /* peer-group */
18318 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18319 bgp_config_write_peer_global(vty, bgp, group->conf);
18320 }
18321
18322 /* Normal neighbor configuration. */
18323 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18324 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18325 bgp_config_write_peer_global(vty, bgp, peer);
18326 }
18327
18328 /* listen range and limit for dynamic BGP neighbors */
18329 bgp_config_write_listen(vty, bgp);
18330
18331 /*
18332 * BGP default autoshutdown neighbors
18333 *
18334 * This must be placed after any peer and peer-group
18335 * configuration, to avoid setting all peers to shutdown after
18336 * a daemon restart, which is undesired behavior. (see #2286)
18337 */
18338 if (bgp->autoshutdown)
18339 vty_out(vty, " bgp default shutdown\n");
18340
18341 /* BGP instance administrative shutdown */
18342 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18343 vty_out(vty, " bgp shutdown\n");
18344
18345 if (bgp->allow_martian)
18346 vty_out(vty, " bgp allow-martian-nexthop\n");
18347
18348 if (bgp->fast_convergence)
18349 vty_out(vty, " bgp fast-convergence\n");
18350
18351 if (bgp->srv6_enabled) {
18352 vty_frame(vty, " !\n segment-routing srv6\n");
18353 if (strlen(bgp->srv6_locator_name))
18354 vty_out(vty, " locator %s\n",
18355 bgp->srv6_locator_name);
18356 vty_endframe(vty, " exit\n");
18357 }
18358
18359 tovpn_sid_index = bgp->tovpn_sid_index;
18360 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18361 vty_out(vty, " sid vpn per-vrf export auto\n");
18362 } else if (tovpn_sid_index != 0) {
18363 vty_out(vty, " sid vpn per-vrf export %d\n",
18364 tovpn_sid_index);
18365 }
18366
18367 /* IPv4 unicast configuration. */
18368 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18369
18370 /* IPv4 multicast configuration. */
18371 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18372
18373 /* IPv4 labeled-unicast configuration. */
18374 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18375
18376 /* IPv4 VPN configuration. */
18377 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18378
18379 /* ENCAPv4 configuration. */
18380 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18381
18382 /* FLOWSPEC v4 configuration. */
18383 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18384
18385 /* IPv6 unicast configuration. */
18386 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18387
18388 /* IPv6 multicast configuration. */
18389 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18390
18391 /* IPv6 labeled-unicast configuration. */
18392 bgp_config_write_family(vty, bgp, AFI_IP6,
18393 SAFI_LABELED_UNICAST);
18394
18395 /* IPv6 VPN configuration. */
18396 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18397
18398 /* ENCAPv6 configuration. */
18399 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18400
18401 /* FLOWSPEC v6 configuration. */
18402 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18403
18404 /* EVPN configuration. */
18405 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18406
18407 hook_call(bgp_inst_config_write, bgp, vty);
18408
18409 #ifdef ENABLE_BGP_VNC
18410 bgp_rfapi_cfg_write(vty, bgp);
18411 #endif
18412
18413 vty_out(vty, "exit\n");
18414 vty_out(vty, "!\n");
18415 }
18416 return 0;
18417 }
18418
18419
18420 /* BGP node structure. */
18421 static struct cmd_node bgp_node = {
18422 .name = "bgp",
18423 .node = BGP_NODE,
18424 .parent_node = CONFIG_NODE,
18425 .prompt = "%s(config-router)# ",
18426 .config_write = bgp_config_write,
18427 };
18428
18429 static struct cmd_node bgp_ipv4_unicast_node = {
18430 .name = "bgp ipv4 unicast",
18431 .node = BGP_IPV4_NODE,
18432 .parent_node = BGP_NODE,
18433 .prompt = "%s(config-router-af)# ",
18434 .no_xpath = true,
18435 };
18436
18437 static struct cmd_node bgp_ipv4_multicast_node = {
18438 .name = "bgp ipv4 multicast",
18439 .node = BGP_IPV4M_NODE,
18440 .parent_node = BGP_NODE,
18441 .prompt = "%s(config-router-af)# ",
18442 .no_xpath = true,
18443 };
18444
18445 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18446 .name = "bgp ipv4 labeled unicast",
18447 .node = BGP_IPV4L_NODE,
18448 .parent_node = BGP_NODE,
18449 .prompt = "%s(config-router-af)# ",
18450 .no_xpath = true,
18451 };
18452
18453 static struct cmd_node bgp_ipv6_unicast_node = {
18454 .name = "bgp ipv6 unicast",
18455 .node = BGP_IPV6_NODE,
18456 .parent_node = BGP_NODE,
18457 .prompt = "%s(config-router-af)# ",
18458 .no_xpath = true,
18459 };
18460
18461 static struct cmd_node bgp_ipv6_multicast_node = {
18462 .name = "bgp ipv6 multicast",
18463 .node = BGP_IPV6M_NODE,
18464 .parent_node = BGP_NODE,
18465 .prompt = "%s(config-router-af)# ",
18466 .no_xpath = true,
18467 };
18468
18469 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18470 .name = "bgp ipv6 labeled unicast",
18471 .node = BGP_IPV6L_NODE,
18472 .parent_node = BGP_NODE,
18473 .prompt = "%s(config-router-af)# ",
18474 .no_xpath = true,
18475 };
18476
18477 static struct cmd_node bgp_vpnv4_node = {
18478 .name = "bgp vpnv4",
18479 .node = BGP_VPNV4_NODE,
18480 .parent_node = BGP_NODE,
18481 .prompt = "%s(config-router-af)# ",
18482 .no_xpath = true,
18483 };
18484
18485 static struct cmd_node bgp_vpnv6_node = {
18486 .name = "bgp vpnv6",
18487 .node = BGP_VPNV6_NODE,
18488 .parent_node = BGP_NODE,
18489 .prompt = "%s(config-router-af-vpnv6)# ",
18490 .no_xpath = true,
18491 };
18492
18493 static struct cmd_node bgp_evpn_node = {
18494 .name = "bgp evpn",
18495 .node = BGP_EVPN_NODE,
18496 .parent_node = BGP_NODE,
18497 .prompt = "%s(config-router-evpn)# ",
18498 .no_xpath = true,
18499 };
18500
18501 static struct cmd_node bgp_evpn_vni_node = {
18502 .name = "bgp evpn vni",
18503 .node = BGP_EVPN_VNI_NODE,
18504 .parent_node = BGP_EVPN_NODE,
18505 .prompt = "%s(config-router-af-vni)# ",
18506 };
18507
18508 static struct cmd_node bgp_flowspecv4_node = {
18509 .name = "bgp ipv4 flowspec",
18510 .node = BGP_FLOWSPECV4_NODE,
18511 .parent_node = BGP_NODE,
18512 .prompt = "%s(config-router-af)# ",
18513 .no_xpath = true,
18514 };
18515
18516 static struct cmd_node bgp_flowspecv6_node = {
18517 .name = "bgp ipv6 flowspec",
18518 .node = BGP_FLOWSPECV6_NODE,
18519 .parent_node = BGP_NODE,
18520 .prompt = "%s(config-router-af-vpnv6)# ",
18521 .no_xpath = true,
18522 };
18523
18524 static struct cmd_node bgp_srv6_node = {
18525 .name = "bgp srv6",
18526 .node = BGP_SRV6_NODE,
18527 .parent_node = BGP_NODE,
18528 .prompt = "%s(config-router-srv6)# ",
18529 };
18530
18531 static void community_list_vty(void);
18532
18533 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18534 {
18535 struct bgp *bgp;
18536 struct peer_group *group;
18537 struct listnode *lnbgp, *lnpeer;
18538
18539 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18540 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18541 vector_set(comps,
18542 XSTRDUP(MTYPE_COMPLETION, group->name));
18543 }
18544 }
18545
18546 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18547 {
18548 struct bgp *bgp;
18549 struct peer *peer;
18550 struct listnode *lnbgp, *lnpeer;
18551
18552 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18553 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18554 /* only provide suggestions on the appropriate input
18555 * token type,
18556 * they'll otherwise show up multiple times */
18557 enum cmd_token_type match_type;
18558 char *name = peer->host;
18559
18560 if (peer->conf_if) {
18561 match_type = VARIABLE_TKN;
18562 name = peer->conf_if;
18563 } else if (strchr(peer->host, ':'))
18564 match_type = IPV6_TKN;
18565 else
18566 match_type = IPV4_TKN;
18567
18568 if (token->type != match_type)
18569 continue;
18570
18571 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18572 }
18573 }
18574 }
18575
18576 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18577 {
18578 bgp_ac_peer(comps, token);
18579
18580 if (token->type == VARIABLE_TKN)
18581 bgp_ac_peergroup(comps, token);
18582 }
18583
18584 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18585 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18586 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18587 {.varname = "peer", .completions = bgp_ac_neighbor},
18588 {.completions = NULL}};
18589
18590 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18591 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18592 {.completions = NULL} };
18593
18594 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18595
18596 static struct thread *t_bgp_cfg;
18597
18598 bool bgp_config_inprocess(void)
18599 {
18600 return thread_is_scheduled(t_bgp_cfg);
18601 }
18602
18603 static void bgp_config_finish(struct thread *t)
18604 {
18605 struct listnode *node;
18606 struct bgp *bgp;
18607
18608 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18609 hook_call(bgp_config_end, bgp);
18610 }
18611
18612 static void bgp_config_start(void)
18613 {
18614 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18615 THREAD_OFF(t_bgp_cfg);
18616 thread_add_timer(bm->master, bgp_config_finish, NULL,
18617 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18618 }
18619
18620 /* When we receive a hook the configuration is read,
18621 * we start a timer to make sure we postpone sending
18622 * EoR before route-maps are processed.
18623 * This is especially valid if using `bgp route-map delay-timer`.
18624 */
18625 static void bgp_config_end(void)
18626 {
18627 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18628 uint32_t bgp_post_config_delay =
18629 thread_is_scheduled(bm->t_rmap_update)
18630 ? thread_timer_remain_second(bm->t_rmap_update)
18631 : BGP_POST_CONFIG_DELAY_SECONDS;
18632
18633 /* If BGP config processing thread isn't running, then
18634 * we can return and rely it's properly handled.
18635 */
18636 if (!bgp_config_inprocess())
18637 return;
18638
18639 THREAD_OFF(t_bgp_cfg);
18640
18641 /* Start a new timer to make sure we don't send EoR
18642 * before route-maps are processed.
18643 */
18644 thread_add_timer(bm->master, bgp_config_finish, NULL,
18645 bgp_post_config_delay, &t_bgp_cfg);
18646 }
18647
18648 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18649 {
18650 int write = 0;
18651 struct interface *ifp;
18652 struct bgp_interface *iifp;
18653
18654 FOR_ALL_INTERFACES (vrf, ifp) {
18655 iifp = ifp->info;
18656 if (!iifp)
18657 continue;
18658
18659 if_vty_config_start(vty, ifp);
18660
18661 if (CHECK_FLAG(iifp->flags,
18662 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18663 vty_out(vty, " mpls bgp forwarding\n");
18664 write++;
18665 }
18666
18667 if_vty_config_end(vty);
18668 }
18669
18670 return write;
18671 }
18672
18673 /* Configuration write function for bgpd. */
18674 static int config_write_interface(struct vty *vty)
18675 {
18676 int write = 0;
18677 struct vrf *vrf = NULL;
18678
18679 /* Display all VRF aware OSPF interface configuration */
18680 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18681 write += config_write_interface_one(vty, vrf);
18682 }
18683
18684 return write;
18685 }
18686
18687 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18688 "[no$no] mpls bgp forwarding",
18689 NO_STR MPLS_STR BGP_STR
18690 "Enable MPLS forwarding for eBGP directly connected peers\n")
18691 {
18692 bool check;
18693 struct bgp_interface *iifp;
18694
18695 VTY_DECLVAR_CONTEXT(interface, ifp);
18696 iifp = ifp->info;
18697 if (!iifp) {
18698 vty_out(vty, "Interface %s not available\n", ifp->name);
18699 return CMD_WARNING_CONFIG_FAILED;
18700 }
18701 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18702 if (check != !no) {
18703 if (no)
18704 UNSET_FLAG(iifp->flags,
18705 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18706 else
18707 SET_FLAG(iifp->flags,
18708 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18709 /* trigger a nht update on eBGP sessions */
18710 if (if_is_operative(ifp))
18711 bgp_nht_ifp_up(ifp);
18712 }
18713 return CMD_SUCCESS;
18714 }
18715
18716 DEFPY (bgp_inq_limit,
18717 bgp_inq_limit_cmd,
18718 "bgp input-queue-limit (1-4294967295)$limit",
18719 BGP_STR
18720 "Set the BGP Input Queue limit for all peers when message parsing\n"
18721 "Input-Queue limit\n")
18722 {
18723 bm->inq_limit = limit;
18724
18725 return CMD_SUCCESS;
18726 }
18727
18728 DEFPY (no_bgp_inq_limit,
18729 no_bgp_inq_limit_cmd,
18730 "no bgp input-queue-limit [(1-4294967295)$limit]",
18731 NO_STR
18732 BGP_STR
18733 "Set the BGP Input Queue limit for all peers when message parsing\n"
18734 "Input-Queue limit\n")
18735 {
18736 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18737
18738 return CMD_SUCCESS;
18739 }
18740
18741 DEFPY (bgp_outq_limit,
18742 bgp_outq_limit_cmd,
18743 "bgp output-queue-limit (1-4294967295)$limit",
18744 BGP_STR
18745 "Set the BGP Output Queue limit for all peers when message parsing\n"
18746 "Output-Queue limit\n")
18747 {
18748 bm->outq_limit = limit;
18749
18750 return CMD_SUCCESS;
18751 }
18752
18753 DEFPY (no_bgp_outq_limit,
18754 no_bgp_outq_limit_cmd,
18755 "no bgp output-queue-limit [(1-4294967295)$limit]",
18756 NO_STR
18757 BGP_STR
18758 "Set the BGP Output Queue limit for all peers when message parsing\n"
18759 "Output-Queue limit\n")
18760 {
18761 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
18762
18763 return CMD_SUCCESS;
18764 }
18765
18766
18767 /* Initialization of BGP interface. */
18768 static void bgp_vty_if_init(void)
18769 {
18770 /* Install interface node. */
18771 if_cmd_init(config_write_interface);
18772
18773 /* "mpls bgp forwarding" commands. */
18774 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18775 }
18776
18777 void bgp_vty_init(void)
18778 {
18779 cmd_variable_handler_register(bgp_var_neighbor);
18780 cmd_variable_handler_register(bgp_var_peergroup);
18781
18782 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18783
18784 /* Install bgp top node. */
18785 install_node(&bgp_node);
18786 install_node(&bgp_ipv4_unicast_node);
18787 install_node(&bgp_ipv4_multicast_node);
18788 install_node(&bgp_ipv4_labeled_unicast_node);
18789 install_node(&bgp_ipv6_unicast_node);
18790 install_node(&bgp_ipv6_multicast_node);
18791 install_node(&bgp_ipv6_labeled_unicast_node);
18792 install_node(&bgp_vpnv4_node);
18793 install_node(&bgp_vpnv6_node);
18794 install_node(&bgp_evpn_node);
18795 install_node(&bgp_evpn_vni_node);
18796 install_node(&bgp_flowspecv4_node);
18797 install_node(&bgp_flowspecv6_node);
18798 install_node(&bgp_srv6_node);
18799
18800 /* Install default VTY commands to new nodes. */
18801 install_default(BGP_NODE);
18802 install_default(BGP_IPV4_NODE);
18803 install_default(BGP_IPV4M_NODE);
18804 install_default(BGP_IPV4L_NODE);
18805 install_default(BGP_IPV6_NODE);
18806 install_default(BGP_IPV6M_NODE);
18807 install_default(BGP_IPV6L_NODE);
18808 install_default(BGP_VPNV4_NODE);
18809 install_default(BGP_VPNV6_NODE);
18810 install_default(BGP_FLOWSPECV4_NODE);
18811 install_default(BGP_FLOWSPECV6_NODE);
18812 install_default(BGP_EVPN_NODE);
18813 install_default(BGP_EVPN_VNI_NODE);
18814 install_default(BGP_SRV6_NODE);
18815
18816 /* "global bgp inq-limit command */
18817 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18818 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18819 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18820 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
18821
18822 /* "bgp local-mac" hidden commands. */
18823 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18824 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18825
18826 /* "bgp suppress-fib-pending" global */
18827 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18828
18829 /* bgp route-map delay-timer commands. */
18830 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18831 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18832
18833 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18834
18835 /* bgp fast-convergence command */
18836 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18837 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18838
18839 /* global bgp update-delay command */
18840 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18841 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18842
18843 /* global bgp graceful-shutdown command */
18844 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18845 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18846
18847 /* Dummy commands (Currently not supported) */
18848 install_element(BGP_NODE, &no_synchronization_cmd);
18849 install_element(BGP_NODE, &no_auto_summary_cmd);
18850
18851 /* "router bgp" commands. */
18852 install_element(CONFIG_NODE, &router_bgp_cmd);
18853
18854 /* "no router bgp" commands. */
18855 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18856
18857 /* "bgp session-dscp command */
18858 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18859 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18860
18861 /* "bgp router-id" commands. */
18862 install_element(BGP_NODE, &bgp_router_id_cmd);
18863 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18864
18865 /* "bgp suppress-fib-pending" command */
18866 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18867
18868 /* "bgp cluster-id" commands. */
18869 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18870 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18871
18872 /* "bgp no-rib" commands. */
18873 install_element(CONFIG_NODE, &bgp_norib_cmd);
18874 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18875
18876 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18877
18878 /* "bgp confederation" commands. */
18879 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18880 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18881
18882 /* "bgp confederation peers" commands. */
18883 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18884 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18885
18886 /* bgp max-med command */
18887 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18888 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18889 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18890 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18891 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18892
18893 /* "neighbor role" commands. */
18894 install_element(BGP_NODE, &neighbor_role_cmd);
18895 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18896 install_element(BGP_NODE, &no_neighbor_role_cmd);
18897
18898 /* "neighbor aigp" commands. */
18899 install_element(BGP_NODE, &neighbor_aigp_cmd);
18900
18901 /* "neighbor graceful-shutdown" command */
18902 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18903
18904 /* bgp disable-ebgp-connected-nh-check */
18905 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18906 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18907
18908 /* bgp update-delay command */
18909 install_element(BGP_NODE, &bgp_update_delay_cmd);
18910 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18911
18912 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18913 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18914
18915 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18916 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18917
18918 /* "maximum-paths" commands. */
18919 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18920 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18921 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18922 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18923 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18924 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18925 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18926 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18927 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18928 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18929 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18930 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18931 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18932 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18933 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18934
18935 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18936 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18937 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18938 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18939 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18940 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18941 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18942 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18943 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18944 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18945
18946 /* "timers bgp" commands. */
18947 install_element(BGP_NODE, &bgp_timers_cmd);
18948 install_element(BGP_NODE, &no_bgp_timers_cmd);
18949
18950 /* "minimum-holdtime" commands. */
18951 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18952 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18953
18954 /* route-map delay-timer commands - per instance for backwards compat.
18955 */
18956 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18957 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18958
18959 /* "bgp client-to-client reflection" commands */
18960 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18961 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18962
18963 /* "bgp always-compare-med" commands */
18964 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18965 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18966
18967 /* bgp ebgp-requires-policy */
18968 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18969 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18970
18971 /* bgp suppress-duplicates */
18972 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18973 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18974
18975 /* bgp reject-as-sets */
18976 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18977 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18978
18979 /* "bgp deterministic-med" commands */
18980 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18981 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18982
18983 /* "bgp graceful-restart" command */
18984 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18985 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18986
18987 /* "bgp graceful-restart-disable" command */
18988 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18989 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18990
18991 /* "neighbor a:b:c:d graceful-restart" command */
18992 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18993 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18994
18995 /* "neighbor a:b:c:d graceful-restart-disable" command */
18996 install_element(BGP_NODE,
18997 &bgp_neighbor_graceful_restart_disable_set_cmd);
18998 install_element(BGP_NODE,
18999 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
19000
19001 /* "neighbor a:b:c:d graceful-restart-helper" command */
19002 install_element(BGP_NODE,
19003 &bgp_neighbor_graceful_restart_helper_set_cmd);
19004 install_element(BGP_NODE,
19005 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
19006
19007 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
19008 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
19009 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
19010 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
19011 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
19012 install_element(BGP_NODE,
19013 &no_bgp_graceful_restart_select_defer_time_cmd);
19014 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
19015 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
19016 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
19017
19018 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
19019 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
19020 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
19021 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
19022
19023 /* "bgp graceful-shutdown" commands */
19024 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
19025 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
19026
19027 /* "bgp hard-administrative-reset" commands */
19028 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
19029
19030 /* "bgp long-lived-graceful-restart" commands */
19031 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
19032 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
19033
19034 /* "bgp fast-external-failover" commands */
19035 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
19036 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
19037
19038 /* "bgp bestpath aigp" commands */
19039 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
19040
19041 /* "bgp bestpath compare-routerid" commands */
19042 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
19043 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
19044
19045 /* "bgp bestpath as-path ignore" commands */
19046 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
19047 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
19048
19049 /* "bgp bestpath as-path confed" commands */
19050 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
19051 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
19052
19053 /* "bgp bestpath as-path multipath-relax" commands */
19054 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
19055 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
19056
19057 /* "bgp bestpath peer-type multipath-relax" commands */
19058 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
19059 install_element(BGP_NODE,
19060 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
19061
19062 /* "bgp log-neighbor-changes" commands */
19063 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19064 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19065
19066 /* "bgp bestpath med" commands */
19067 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19068 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19069
19070 /* "bgp bestpath bandwidth" commands */
19071 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
19072 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
19073
19074 /* "no bgp default <afi>-<safi>" commands. */
19075 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
19076
19077 /* "bgp network import-check" commands. */
19078 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19079 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19080 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19081
19082 /* "bgp default local-preference" commands. */
19083 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19084 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19085
19086 /* bgp default show-hostname */
19087 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19088 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19089
19090 /* bgp default show-nexthop-hostname */
19091 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19092 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19093
19094 /* "bgp default subgroup-pkt-queue-max" commands. */
19095 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19096 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19097
19098 /* bgp ibgp-allow-policy-mods command */
19099 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19100 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19101
19102 /* "bgp listen limit" commands. */
19103 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19104 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19105
19106 /* "bgp listen range" commands. */
19107 install_element(BGP_NODE, &bgp_listen_range_cmd);
19108 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19109
19110 /* "bgp default shutdown" command */
19111 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
19112
19113 /* "bgp shutdown" commands */
19114 install_element(BGP_NODE, &bgp_shutdown_cmd);
19115 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
19116 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
19117 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
19118
19119 /* "neighbor remote-as" commands. */
19120 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19121 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19122 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19123 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19124 install_element(BGP_NODE,
19125 &neighbor_interface_v6only_config_remote_as_cmd);
19126 install_element(BGP_NODE, &no_neighbor_cmd);
19127 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19128
19129 /* "neighbor peer-group" commands. */
19130 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19131 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19132 install_element(BGP_NODE,
19133 &no_neighbor_interface_peer_group_remote_as_cmd);
19134
19135 /* "neighbor local-as" commands. */
19136 install_element(BGP_NODE, &neighbor_local_as_cmd);
19137 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19138 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19139 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19140
19141 /* "neighbor solo" commands. */
19142 install_element(BGP_NODE, &neighbor_solo_cmd);
19143 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19144
19145 /* "neighbor password" commands. */
19146 install_element(BGP_NODE, &neighbor_password_cmd);
19147 install_element(BGP_NODE, &no_neighbor_password_cmd);
19148
19149 /* "neighbor activate" commands. */
19150 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19151 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19152 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19153 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19154 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19155 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19156 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19157 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19158 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
19159 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19160 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
19161 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19162
19163 /* "no neighbor activate" commands. */
19164 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19165 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19166 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19167 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19168 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19169 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19170 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19171 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19172 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
19173 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19174 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
19175 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19176
19177 /* "neighbor peer-group" set commands. */
19178 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19179 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19180 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19181 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19182 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19183 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19184 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19185 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19186 install_element(BGP_FLOWSPECV4_NODE,
19187 &neighbor_set_peer_group_hidden_cmd);
19188 install_element(BGP_FLOWSPECV6_NODE,
19189 &neighbor_set_peer_group_hidden_cmd);
19190
19191 /* "no neighbor peer-group unset" commands. */
19192 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19193 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19194 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19195 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19196 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19197 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19198 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19199 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19200 install_element(BGP_FLOWSPECV4_NODE,
19201 &no_neighbor_set_peer_group_hidden_cmd);
19202 install_element(BGP_FLOWSPECV6_NODE,
19203 &no_neighbor_set_peer_group_hidden_cmd);
19204
19205 /* "neighbor softreconfiguration inbound" commands.*/
19206 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19207 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19208 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19209 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19210 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19211 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19212 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19213 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19214 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19215 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19216 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19217 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19218 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19219 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19220 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19221 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19222 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19223 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19224 install_element(BGP_FLOWSPECV4_NODE,
19225 &neighbor_soft_reconfiguration_cmd);
19226 install_element(BGP_FLOWSPECV4_NODE,
19227 &no_neighbor_soft_reconfiguration_cmd);
19228 install_element(BGP_FLOWSPECV6_NODE,
19229 &neighbor_soft_reconfiguration_cmd);
19230 install_element(BGP_FLOWSPECV6_NODE,
19231 &no_neighbor_soft_reconfiguration_cmd);
19232 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19233 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19234
19235 /* "neighbor attribute-unchanged" commands. */
19236 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19237 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19238 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19239 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19240 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19241 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19242 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19243 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19244 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19245 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19246 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19247 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19248 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19249 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19250 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19251 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19252 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19253 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19254
19255 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19256 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19257
19258 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19259 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19260 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19261 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19262
19263 /* "nexthop-local unchanged" commands */
19264 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19265 install_element(BGP_IPV6_NODE,
19266 &no_neighbor_nexthop_local_unchanged_cmd);
19267
19268 /* "neighbor next-hop-self" commands. */
19269 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19270 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19271 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19272 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19273 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19274 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19275 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19276 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19277 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19278 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19279 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19280 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19281 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19282 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19283 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19284 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19285 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19286 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19287 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19288 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19289
19290 /* "neighbor next-hop-self force" commands. */
19291 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19292 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19293 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19294 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19295 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19296 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19297 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19298 install_element(BGP_IPV4_NODE,
19299 &no_neighbor_nexthop_self_all_hidden_cmd);
19300 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19301 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19302 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19303 install_element(BGP_IPV4M_NODE,
19304 &no_neighbor_nexthop_self_all_hidden_cmd);
19305 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19306 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19307 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19308 install_element(BGP_IPV4L_NODE,
19309 &no_neighbor_nexthop_self_all_hidden_cmd);
19310 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19311 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19312 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19313 install_element(BGP_IPV6_NODE,
19314 &no_neighbor_nexthop_self_all_hidden_cmd);
19315 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19316 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19317 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19318 install_element(BGP_IPV6M_NODE,
19319 &no_neighbor_nexthop_self_all_hidden_cmd);
19320 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19321 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19322 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19323 install_element(BGP_IPV6L_NODE,
19324 &no_neighbor_nexthop_self_all_hidden_cmd);
19325 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19326 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19327 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19328 install_element(BGP_VPNV4_NODE,
19329 &no_neighbor_nexthop_self_all_hidden_cmd);
19330 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19331 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19332 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19333 install_element(BGP_VPNV6_NODE,
19334 &no_neighbor_nexthop_self_all_hidden_cmd);
19335 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19336 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19337
19338 /* "neighbor as-override" commands. */
19339 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19340 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19341 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19342 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19343 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19344 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19345 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19346 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19347 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19348 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19349 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19350 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19351 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19352 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19353 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19354 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19355 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19356 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19357
19358 /* "neighbor remove-private-AS" commands. */
19359 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19360 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19361 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19362 install_element(BGP_NODE,
19363 &no_neighbor_remove_private_as_all_hidden_cmd);
19364 install_element(BGP_NODE,
19365 &neighbor_remove_private_as_replace_as_hidden_cmd);
19366 install_element(BGP_NODE,
19367 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19368 install_element(BGP_NODE,
19369 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19370 install_element(
19371 BGP_NODE,
19372 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19373 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19374 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19375 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19376 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19377 install_element(BGP_IPV4_NODE,
19378 &neighbor_remove_private_as_replace_as_cmd);
19379 install_element(BGP_IPV4_NODE,
19380 &no_neighbor_remove_private_as_replace_as_cmd);
19381 install_element(BGP_IPV4_NODE,
19382 &neighbor_remove_private_as_all_replace_as_cmd);
19383 install_element(BGP_IPV4_NODE,
19384 &no_neighbor_remove_private_as_all_replace_as_cmd);
19385 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19386 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19387 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19388 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19389 install_element(BGP_IPV4M_NODE,
19390 &neighbor_remove_private_as_replace_as_cmd);
19391 install_element(BGP_IPV4M_NODE,
19392 &no_neighbor_remove_private_as_replace_as_cmd);
19393 install_element(BGP_IPV4M_NODE,
19394 &neighbor_remove_private_as_all_replace_as_cmd);
19395 install_element(BGP_IPV4M_NODE,
19396 &no_neighbor_remove_private_as_all_replace_as_cmd);
19397 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19398 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19399 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19400 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19401 install_element(BGP_IPV4L_NODE,
19402 &neighbor_remove_private_as_replace_as_cmd);
19403 install_element(BGP_IPV4L_NODE,
19404 &no_neighbor_remove_private_as_replace_as_cmd);
19405 install_element(BGP_IPV4L_NODE,
19406 &neighbor_remove_private_as_all_replace_as_cmd);
19407 install_element(BGP_IPV4L_NODE,
19408 &no_neighbor_remove_private_as_all_replace_as_cmd);
19409 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19410 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19411 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19412 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19413 install_element(BGP_IPV6_NODE,
19414 &neighbor_remove_private_as_replace_as_cmd);
19415 install_element(BGP_IPV6_NODE,
19416 &no_neighbor_remove_private_as_replace_as_cmd);
19417 install_element(BGP_IPV6_NODE,
19418 &neighbor_remove_private_as_all_replace_as_cmd);
19419 install_element(BGP_IPV6_NODE,
19420 &no_neighbor_remove_private_as_all_replace_as_cmd);
19421 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19422 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19423 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19424 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19425 install_element(BGP_IPV6M_NODE,
19426 &neighbor_remove_private_as_replace_as_cmd);
19427 install_element(BGP_IPV6M_NODE,
19428 &no_neighbor_remove_private_as_replace_as_cmd);
19429 install_element(BGP_IPV6M_NODE,
19430 &neighbor_remove_private_as_all_replace_as_cmd);
19431 install_element(BGP_IPV6M_NODE,
19432 &no_neighbor_remove_private_as_all_replace_as_cmd);
19433 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19434 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19435 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19436 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19437 install_element(BGP_IPV6L_NODE,
19438 &neighbor_remove_private_as_replace_as_cmd);
19439 install_element(BGP_IPV6L_NODE,
19440 &no_neighbor_remove_private_as_replace_as_cmd);
19441 install_element(BGP_IPV6L_NODE,
19442 &neighbor_remove_private_as_all_replace_as_cmd);
19443 install_element(BGP_IPV6L_NODE,
19444 &no_neighbor_remove_private_as_all_replace_as_cmd);
19445 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19446 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19447 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19448 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19449 install_element(BGP_VPNV4_NODE,
19450 &neighbor_remove_private_as_replace_as_cmd);
19451 install_element(BGP_VPNV4_NODE,
19452 &no_neighbor_remove_private_as_replace_as_cmd);
19453 install_element(BGP_VPNV4_NODE,
19454 &neighbor_remove_private_as_all_replace_as_cmd);
19455 install_element(BGP_VPNV4_NODE,
19456 &no_neighbor_remove_private_as_all_replace_as_cmd);
19457 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19458 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19459 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19460 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19461 install_element(BGP_VPNV6_NODE,
19462 &neighbor_remove_private_as_replace_as_cmd);
19463 install_element(BGP_VPNV6_NODE,
19464 &no_neighbor_remove_private_as_replace_as_cmd);
19465 install_element(BGP_VPNV6_NODE,
19466 &neighbor_remove_private_as_all_replace_as_cmd);
19467 install_element(BGP_VPNV6_NODE,
19468 &no_neighbor_remove_private_as_all_replace_as_cmd);
19469
19470 /* "neighbor send-community" commands.*/
19471 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19472 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19473 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19474 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19475 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19476 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19477 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19478 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19479 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19480 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19481 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19482 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19483 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19484 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19485 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19486 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19487 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19488 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19489 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19490 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19491 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19492 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19493 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19494 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19495 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19496 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19497 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19498 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19499 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19500 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19501 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19502 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19503 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19504 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19505 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19506 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19507
19508 /* "neighbor route-reflector" commands.*/
19509 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19510 install_element(BGP_NODE,
19511 &no_neighbor_route_reflector_client_hidden_cmd);
19512 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19513 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19514 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19515 install_element(BGP_IPV4M_NODE,
19516 &no_neighbor_route_reflector_client_cmd);
19517 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19518 install_element(BGP_IPV4L_NODE,
19519 &no_neighbor_route_reflector_client_cmd);
19520 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19521 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19522 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19523 install_element(BGP_IPV6M_NODE,
19524 &no_neighbor_route_reflector_client_cmd);
19525 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19526 install_element(BGP_IPV6L_NODE,
19527 &no_neighbor_route_reflector_client_cmd);
19528 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19529 install_element(BGP_VPNV4_NODE,
19530 &no_neighbor_route_reflector_client_cmd);
19531 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19532 install_element(BGP_VPNV6_NODE,
19533 &no_neighbor_route_reflector_client_cmd);
19534 install_element(BGP_FLOWSPECV4_NODE,
19535 &neighbor_route_reflector_client_cmd);
19536 install_element(BGP_FLOWSPECV4_NODE,
19537 &no_neighbor_route_reflector_client_cmd);
19538 install_element(BGP_FLOWSPECV6_NODE,
19539 &neighbor_route_reflector_client_cmd);
19540 install_element(BGP_FLOWSPECV6_NODE,
19541 &no_neighbor_route_reflector_client_cmd);
19542 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19543 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19544
19545 /* "neighbor route-server" commands.*/
19546 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19547 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19548 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19549 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19550 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19551 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19552 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19553 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19554 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19555 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19556 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19557 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19558 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19559 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19560 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19561 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19562 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19563 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19564 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19565 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19566 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19567 install_element(BGP_FLOWSPECV4_NODE,
19568 &no_neighbor_route_server_client_cmd);
19569 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19570 install_element(BGP_FLOWSPECV6_NODE,
19571 &no_neighbor_route_server_client_cmd);
19572
19573 /* "neighbor disable-addpath-rx" commands. */
19574 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19575 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19576 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19577 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19578 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19579 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19580 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19581 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19582 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19583 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19584 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19585 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19586 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19587 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19588 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19589 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19590
19591 /* "neighbor addpath-tx-all-paths" commands.*/
19592 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19593 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19594 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19595 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19596 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19597 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19598 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19599 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19600 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19601 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19602 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19603 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19604 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19605 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19606 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19607 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19608 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19609 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19610
19611 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19612 install_element(BGP_NODE,
19613 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19614 install_element(BGP_NODE,
19615 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19616 install_element(BGP_IPV4_NODE,
19617 &neighbor_addpath_tx_bestpath_per_as_cmd);
19618 install_element(BGP_IPV4_NODE,
19619 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19620 install_element(BGP_IPV4M_NODE,
19621 &neighbor_addpath_tx_bestpath_per_as_cmd);
19622 install_element(BGP_IPV4M_NODE,
19623 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19624 install_element(BGP_IPV4L_NODE,
19625 &neighbor_addpath_tx_bestpath_per_as_cmd);
19626 install_element(BGP_IPV4L_NODE,
19627 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19628 install_element(BGP_IPV6_NODE,
19629 &neighbor_addpath_tx_bestpath_per_as_cmd);
19630 install_element(BGP_IPV6_NODE,
19631 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19632 install_element(BGP_IPV6M_NODE,
19633 &neighbor_addpath_tx_bestpath_per_as_cmd);
19634 install_element(BGP_IPV6M_NODE,
19635 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19636 install_element(BGP_IPV6L_NODE,
19637 &neighbor_addpath_tx_bestpath_per_as_cmd);
19638 install_element(BGP_IPV6L_NODE,
19639 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19640 install_element(BGP_VPNV4_NODE,
19641 &neighbor_addpath_tx_bestpath_per_as_cmd);
19642 install_element(BGP_VPNV4_NODE,
19643 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19644 install_element(BGP_VPNV6_NODE,
19645 &neighbor_addpath_tx_bestpath_per_as_cmd);
19646 install_element(BGP_VPNV6_NODE,
19647 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19648
19649 /* "neighbor sender-as-path-loop-detection" commands. */
19650 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19651 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19652
19653 /* "neighbor path-attribute discard" commands. */
19654 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
19655 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
19656
19657 /* "neighbor path-attribute treat-as-withdraw" commands. */
19658 install_element(BGP_NODE,
19659 &neighbor_path_attribute_treat_as_withdraw_cmd);
19660 install_element(BGP_NODE,
19661 &no_neighbor_path_attribute_treat_as_withdraw_cmd);
19662
19663 /* "neighbor passive" commands. */
19664 install_element(BGP_NODE, &neighbor_passive_cmd);
19665 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19666
19667
19668 /* "neighbor shutdown" commands. */
19669 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19670 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19671 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19672 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19673 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19674 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19675
19676 /* "neighbor capability extended-nexthop" commands.*/
19677 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19678 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19679
19680 /* "neighbor capability orf prefix-list" commands.*/
19681 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19682 install_element(BGP_NODE,
19683 &no_neighbor_capability_orf_prefix_hidden_cmd);
19684 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19685 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19686 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19687 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19688 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19689 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19690 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19691 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19692 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19693 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19694 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19695 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19696
19697 /* "neighbor capability dynamic" commands.*/
19698 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19699 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19700
19701 /* "neighbor dont-capability-negotiate" commands. */
19702 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19703 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19704
19705 /* "neighbor ebgp-multihop" commands. */
19706 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19707 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19708 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19709
19710 /* "neighbor disable-connected-check" commands. */
19711 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19712 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19713
19714 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19715 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19716 install_element(BGP_NODE,
19717 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19718
19719 /* "neighbor extended-optional-parameters" commands. */
19720 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19721 install_element(BGP_NODE,
19722 &no_neighbor_extended_optional_parameters_cmd);
19723
19724 /* "neighbor enforce-first-as" commands. */
19725 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19726 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19727
19728 /* "neighbor description" commands. */
19729 install_element(BGP_NODE, &neighbor_description_cmd);
19730 install_element(BGP_NODE, &no_neighbor_description_cmd);
19731 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19732
19733 /* "neighbor update-source" commands. "*/
19734 install_element(BGP_NODE, &neighbor_update_source_cmd);
19735 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19736
19737 /* "neighbor default-originate" commands. */
19738 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19739 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19740 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19741 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19742 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19743 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19744 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19745 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19746 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19747 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19748 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19749 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19750 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19751 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19752 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19753 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19754 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19755 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19756 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19757 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19758 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19759
19760 /* "neighbor port" commands. */
19761 install_element(BGP_NODE, &neighbor_port_cmd);
19762 install_element(BGP_NODE, &no_neighbor_port_cmd);
19763
19764 /* "neighbor weight" commands. */
19765 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19766 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19767
19768 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19769 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19770 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19771 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19772 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19773 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19774 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19775 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19776 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19777 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19778 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19779 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19780 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19781 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19782 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19783 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19784
19785 /* "neighbor override-capability" commands. */
19786 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19787 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19788
19789 /* "neighbor strict-capability-match" commands. */
19790 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19791 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19792
19793 /* "neighbor timers" commands. */
19794 install_element(BGP_NODE, &neighbor_timers_cmd);
19795 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19796
19797 /* "neighbor timers connect" commands. */
19798 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19799 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19800
19801 /* "neighbor timers delayopen" commands. */
19802 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19803 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19804
19805 /* "neighbor advertisement-interval" commands. */
19806 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19807 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19808
19809 /* "neighbor interface" commands. */
19810 install_element(BGP_NODE, &neighbor_interface_cmd);
19811 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19812
19813 /* "neighbor distribute" commands. */
19814 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19815 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19816 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19817 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19818 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19819 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19820 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19821 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19822 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19823 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19824 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19825 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19826 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19827 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19828 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19829 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19830 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19831 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19832
19833 /* "neighbor prefix-list" commands. */
19834 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19835 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19836 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19837 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19838 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19839 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19840 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19841 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19842 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19843 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19844 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19845 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19846 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19847 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19848 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19849 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19850 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19851 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19852 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19853 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19854 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19855 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19856
19857 /* "neighbor filter-list" commands. */
19858 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19859 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19860 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19861 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19862 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19863 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19864 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19865 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19866 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19867 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19868 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19869 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19870 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19871 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19872 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19873 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19874 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19875 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19876 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19877 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19878 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19879 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19880
19881 /* "neighbor route-map" commands. */
19882 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19883 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19884 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19885 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19886 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19887 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19888 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19889 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19890 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19891 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19892 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19893 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19894 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19895 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19896 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19897 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19898 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19899 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19900 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19901 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19902 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19903 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19904 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19905 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19906
19907 /* "neighbor unsuppress-map" commands. */
19908 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19909 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19910 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19911 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19912 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19913 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19914 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19915 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19916 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19917 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19918 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19919 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19920 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19921 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19922 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19923 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19924 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19925 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19926
19927 /* "neighbor advertise-map" commands. */
19928 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19929 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19930 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19931 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19932 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19933 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19934 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19935 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19936 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19937 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19938
19939 /* neighbor maximum-prefix-out commands. */
19940 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19941 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19942 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19943 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19944 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19945 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19946 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19947 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19948 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19949 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19950 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19951 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19952 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19953 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19954 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19955 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19956 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19957 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19958
19959 /* "neighbor maximum-prefix" commands. */
19960 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19961 install_element(BGP_NODE,
19962 &neighbor_maximum_prefix_threshold_hidden_cmd);
19963 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19964 install_element(BGP_NODE,
19965 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19966 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19967 install_element(BGP_NODE,
19968 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19969 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19970 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19971 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19972 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19973 install_element(BGP_IPV4_NODE,
19974 &neighbor_maximum_prefix_threshold_warning_cmd);
19975 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19976 install_element(BGP_IPV4_NODE,
19977 &neighbor_maximum_prefix_threshold_restart_cmd);
19978 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19979 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19980 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19981 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19982 install_element(BGP_IPV4M_NODE,
19983 &neighbor_maximum_prefix_threshold_warning_cmd);
19984 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19985 install_element(BGP_IPV4M_NODE,
19986 &neighbor_maximum_prefix_threshold_restart_cmd);
19987 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19988 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19989 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19990 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19991 install_element(BGP_IPV4L_NODE,
19992 &neighbor_maximum_prefix_threshold_warning_cmd);
19993 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19994 install_element(BGP_IPV4L_NODE,
19995 &neighbor_maximum_prefix_threshold_restart_cmd);
19996 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19997 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19998 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19999 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20000 install_element(BGP_IPV6_NODE,
20001 &neighbor_maximum_prefix_threshold_warning_cmd);
20002 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20003 install_element(BGP_IPV6_NODE,
20004 &neighbor_maximum_prefix_threshold_restart_cmd);
20005 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
20006 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
20007 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20008 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
20009 install_element(BGP_IPV6M_NODE,
20010 &neighbor_maximum_prefix_threshold_warning_cmd);
20011 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
20012 install_element(BGP_IPV6M_NODE,
20013 &neighbor_maximum_prefix_threshold_restart_cmd);
20014 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
20015 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
20016 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20017 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
20018 install_element(BGP_IPV6L_NODE,
20019 &neighbor_maximum_prefix_threshold_warning_cmd);
20020 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
20021 install_element(BGP_IPV6L_NODE,
20022 &neighbor_maximum_prefix_threshold_restart_cmd);
20023 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
20024 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
20025 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20026 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20027 install_element(BGP_VPNV4_NODE,
20028 &neighbor_maximum_prefix_threshold_warning_cmd);
20029 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20030 install_element(BGP_VPNV4_NODE,
20031 &neighbor_maximum_prefix_threshold_restart_cmd);
20032 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
20033 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
20034 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20035 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20036 install_element(BGP_VPNV6_NODE,
20037 &neighbor_maximum_prefix_threshold_warning_cmd);
20038 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20039 install_element(BGP_VPNV6_NODE,
20040 &neighbor_maximum_prefix_threshold_restart_cmd);
20041 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
20042
20043 /* "neighbor allowas-in" */
20044 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
20045 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
20046 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
20047 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
20048 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
20049 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
20050 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
20051 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
20052 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
20053 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
20054 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
20055 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
20056 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
20057 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
20058 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
20059 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
20060 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
20061 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
20062 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
20063 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
20064
20065 /* neighbor accept-own */
20066 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
20067 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
20068
20069 /* "neighbor soo" */
20070 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20071 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20072 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20073 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20074 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20075 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20076 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20077 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20078 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20079 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20080 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20081 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20082 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20083 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20084 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20085 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20086 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20087 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20088
20089 /* address-family commands. */
20090 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20091 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
20092 #ifdef KEEP_OLD_VPN_COMMANDS
20093 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20094 install_element(BGP_NODE, &address_family_vpnv6_cmd);
20095 #endif /* KEEP_OLD_VPN_COMMANDS */
20096
20097 install_element(BGP_NODE, &address_family_evpn_cmd);
20098
20099 /* "exit-address-family" command. */
20100 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20101 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20102 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20103 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20104 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20105 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20106 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20107 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
20108 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20109 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
20110 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20111
20112 /* BGP retain all route-target */
20113 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20114 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20115
20116 /* "clear ip bgp commands" */
20117 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20118
20119 /* clear ip bgp prefix */
20120 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20121 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20122 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20123
20124 /* "show [ip] bgp summary" commands. */
20125 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
20126 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
20127 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
20128 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
20129 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20130 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
20131 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20132
20133 /* "show [ip] bgp neighbors" commands. */
20134 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20135
20136 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
20137
20138 /* "show [ip] bgp peer-group" commands. */
20139 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20140
20141 /* "show [ip] bgp paths" commands. */
20142 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20143
20144 /* "show [ip] bgp community" commands. */
20145 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20146
20147 /* "show ip bgp large-community" commands. */
20148 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20149 /* "show [ip] bgp attribute-info" commands. */
20150 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
20151 /* "show [ip] bgp route-leak" command */
20152 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
20153
20154 /* "redistribute" commands. */
20155 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20156 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20157 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20158 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20159 install_element(BGP_NODE,
20160 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20161 install_element(BGP_NODE,
20162 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20163 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20164 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20165 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20166 install_element(BGP_NODE,
20167 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20168 install_element(BGP_NODE,
20169 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20170 install_element(BGP_NODE,
20171 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20172 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20173 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20174 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20175 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20176 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20177 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20178 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20179 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20180 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20181 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20182 install_element(BGP_IPV4_NODE,
20183 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20184 install_element(BGP_IPV4_NODE,
20185 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20186 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20187 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20188 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20189 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20190 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20191 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20192
20193 /* import|export vpn [route-map RMAP_NAME] */
20194 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20195 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20196
20197 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20198 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20199
20200 /* ttl_security commands */
20201 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20202 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20203
20204 /* "bgp tcp-keepalive" commands */
20205 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20206 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20207
20208 /* "show [ip] bgp memory" commands. */
20209 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20210
20211 /* "show bgp martian next-hop" */
20212 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20213
20214 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20215
20216 /* "show [ip] bgp views" commands. */
20217 install_element(VIEW_NODE, &show_bgp_views_cmd);
20218
20219 /* "show [ip] bgp vrfs" commands. */
20220 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20221
20222 /* Community-list. */
20223 community_list_vty();
20224
20225 community_alias_vty();
20226
20227 /* vpn-policy commands */
20228 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20229 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20230 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20231 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20232 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20233 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20234 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20235 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20236 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20237 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20238 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20239 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20240
20241 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20242 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20243
20244 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20245 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20246 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20247 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20248 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20249 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20250 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20251 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20252 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20253 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20254
20255 /* tcp-mss command */
20256 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20257 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20258
20259 /* srv6 commands */
20260 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20261 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20262 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20263 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20264 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20265 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20266 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20267 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20268 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20269
20270 bgp_vty_if_init();
20271 }
20272
20273 #include "memory.h"
20274 #include "bgp_regex.h"
20275 #include "bgp_clist.h"
20276 #include "bgp_ecommunity.h"
20277
20278 /* VTY functions. */
20279
20280 /* Direction value to string conversion. */
20281 static const char *community_direct_str(int direct)
20282 {
20283 switch (direct) {
20284 case COMMUNITY_DENY:
20285 return "deny";
20286 case COMMUNITY_PERMIT:
20287 return "permit";
20288 default:
20289 return "unknown";
20290 }
20291 }
20292
20293 /* Display error string. */
20294 static void community_list_perror(struct vty *vty, int ret)
20295 {
20296 switch (ret) {
20297 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20298 vty_out(vty, "%% Can't find community-list\n");
20299 break;
20300 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20301 vty_out(vty, "%% Malformed community-list value\n");
20302 break;
20303 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20304 vty_out(vty,
20305 "%% Community name conflict, previously defined as standard community\n");
20306 break;
20307 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20308 vty_out(vty,
20309 "%% Community name conflict, previously defined as expanded community\n");
20310 break;
20311 }
20312 }
20313
20314 /* "community-list" keyword help string. */
20315 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20316
20317 /*community-list standard */
20318 DEFUN (community_list_standard,
20319 bgp_community_list_standard_cmd,
20320 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20321 BGP_STR
20322 COMMUNITY_LIST_STR
20323 "Community list number (standard)\n"
20324 "Add an standard community-list entry\n"
20325 "Community list name\n"
20326 "Sequence number of an entry\n"
20327 "Sequence number\n"
20328 "Specify community to reject\n"
20329 "Specify community to accept\n"
20330 COMMUNITY_VAL_STR)
20331 {
20332 char *cl_name_or_number = NULL;
20333 char *seq = NULL;
20334 int direct = 0;
20335 int style = COMMUNITY_LIST_STANDARD;
20336 int idx = 0;
20337
20338 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20339 seq = argv[idx]->arg;
20340
20341 idx = 0;
20342 argv_find(argv, argc, "(1-99)", &idx);
20343 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20344 cl_name_or_number = argv[idx]->arg;
20345 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20346 : COMMUNITY_DENY;
20347 argv_find(argv, argc, "AA:NN", &idx);
20348 char *str = argv_concat(argv, argc, idx);
20349
20350 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20351 direct, style);
20352
20353 XFREE(MTYPE_TMP, str);
20354
20355 if (ret < 0) {
20356 /* Display error string. */
20357 community_list_perror(vty, ret);
20358 return CMD_WARNING_CONFIG_FAILED;
20359 }
20360
20361 return CMD_SUCCESS;
20362 }
20363
20364 DEFUN (no_community_list_standard_all,
20365 no_bgp_community_list_standard_all_cmd,
20366 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20367 NO_STR
20368 BGP_STR
20369 COMMUNITY_LIST_STR
20370 "Community list number (standard)\n"
20371 "Add an standard community-list entry\n"
20372 "Community list name\n"
20373 "Sequence number of an entry\n"
20374 "Sequence number\n"
20375 "Specify community to reject\n"
20376 "Specify community to accept\n"
20377 COMMUNITY_VAL_STR)
20378 {
20379 char *cl_name_or_number = NULL;
20380 char *str = NULL;
20381 int direct = 0;
20382 int style = COMMUNITY_LIST_STANDARD;
20383 char *seq = NULL;
20384 int idx = 0;
20385
20386 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20387 seq = argv[idx]->arg;
20388
20389 idx = 0;
20390 argv_find(argv, argc, "permit", &idx);
20391 argv_find(argv, argc, "deny", &idx);
20392
20393 if (idx) {
20394 direct = argv_find(argv, argc, "permit", &idx)
20395 ? COMMUNITY_PERMIT
20396 : COMMUNITY_DENY;
20397
20398 idx = 0;
20399 argv_find(argv, argc, "AA:NN", &idx);
20400 str = argv_concat(argv, argc, idx);
20401 }
20402
20403 idx = 0;
20404 argv_find(argv, argc, "(1-99)", &idx);
20405 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20406 cl_name_or_number = argv[idx]->arg;
20407
20408 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20409 direct, style);
20410
20411 XFREE(MTYPE_TMP, str);
20412
20413 if (ret < 0) {
20414 community_list_perror(vty, ret);
20415 return CMD_WARNING_CONFIG_FAILED;
20416 }
20417
20418 return CMD_SUCCESS;
20419 }
20420
20421 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20422 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20423 NO_STR BGP_STR COMMUNITY_LIST_STR
20424 "Community list number (standard)\n"
20425 "Add an standard community-list entry\n"
20426 "Community list name\n")
20427
20428 /*community-list expanded */
20429 DEFUN (community_list_expanded_all,
20430 bgp_community_list_expanded_all_cmd,
20431 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20432 BGP_STR
20433 COMMUNITY_LIST_STR
20434 "Community list number (expanded)\n"
20435 "Add an expanded community-list entry\n"
20436 "Community list name\n"
20437 "Sequence number of an entry\n"
20438 "Sequence number\n"
20439 "Specify community to reject\n"
20440 "Specify community to accept\n"
20441 COMMUNITY_VAL_STR)
20442 {
20443 char *cl_name_or_number = NULL;
20444 char *seq = NULL;
20445 int direct = 0;
20446 int style = COMMUNITY_LIST_EXPANDED;
20447 int idx = 0;
20448
20449 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20450 seq = argv[idx]->arg;
20451
20452 idx = 0;
20453
20454 argv_find(argv, argc, "(100-500)", &idx);
20455 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20456 cl_name_or_number = argv[idx]->arg;
20457 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20458 : COMMUNITY_DENY;
20459 argv_find(argv, argc, "AA:NN", &idx);
20460 char *str = argv_concat(argv, argc, idx);
20461
20462 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20463 direct, style);
20464
20465 XFREE(MTYPE_TMP, str);
20466
20467 if (ret < 0) {
20468 /* Display error string. */
20469 community_list_perror(vty, ret);
20470 return CMD_WARNING_CONFIG_FAILED;
20471 }
20472
20473 return CMD_SUCCESS;
20474 }
20475
20476 DEFUN (no_community_list_expanded_all,
20477 no_bgp_community_list_expanded_all_cmd,
20478 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20479 NO_STR
20480 BGP_STR
20481 COMMUNITY_LIST_STR
20482 "Community list number (expanded)\n"
20483 "Add an expanded community-list entry\n"
20484 "Community list name\n"
20485 "Sequence number of an entry\n"
20486 "Sequence number\n"
20487 "Specify community to reject\n"
20488 "Specify community to accept\n"
20489 COMMUNITY_VAL_STR)
20490 {
20491 char *cl_name_or_number = NULL;
20492 char *seq = NULL;
20493 char *str = NULL;
20494 int direct = 0;
20495 int style = COMMUNITY_LIST_EXPANDED;
20496 int idx = 0;
20497
20498 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20499 seq = argv[idx]->arg;
20500
20501 idx = 0;
20502 argv_find(argv, argc, "permit", &idx);
20503 argv_find(argv, argc, "deny", &idx);
20504
20505 if (idx) {
20506 direct = argv_find(argv, argc, "permit", &idx)
20507 ? COMMUNITY_PERMIT
20508 : COMMUNITY_DENY;
20509
20510 idx = 0;
20511 argv_find(argv, argc, "AA:NN", &idx);
20512 str = argv_concat(argv, argc, idx);
20513 }
20514
20515 idx = 0;
20516 argv_find(argv, argc, "(100-500)", &idx);
20517 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20518 cl_name_or_number = argv[idx]->arg;
20519
20520 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20521 direct, style);
20522
20523 XFREE(MTYPE_TMP, str);
20524
20525 if (ret < 0) {
20526 community_list_perror(vty, ret);
20527 return CMD_WARNING_CONFIG_FAILED;
20528 }
20529
20530 return CMD_SUCCESS;
20531 }
20532
20533 ALIAS(no_community_list_expanded_all,
20534 no_bgp_community_list_expanded_all_list_cmd,
20535 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20536 NO_STR BGP_STR COMMUNITY_LIST_STR
20537 "Community list number (expanded)\n"
20538 "Add an expanded community-list entry\n"
20539 "Community list name\n")
20540
20541 /* Return configuration string of community-list entry. */
20542 static const char *community_list_config_str(struct community_entry *entry)
20543 {
20544 const char *str;
20545
20546 if (entry->any)
20547 str = "";
20548 else {
20549 if (entry->style == COMMUNITY_LIST_STANDARD)
20550 str = community_str(entry->u.com, false, false);
20551 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20552 str = lcommunity_str(entry->u.lcom, false, false);
20553 else
20554 str = entry->config;
20555 }
20556 return str;
20557 }
20558
20559 static void community_list_show(struct vty *vty, struct community_list *list)
20560 {
20561 struct community_entry *entry;
20562
20563 for (entry = list->head; entry; entry = entry->next) {
20564 if (entry == list->head) {
20565 if (all_digit(list->name))
20566 vty_out(vty, "Community %s list %s\n",
20567 entry->style == COMMUNITY_LIST_STANDARD
20568 ? "standard"
20569 : "(expanded) access",
20570 list->name);
20571 else
20572 vty_out(vty, "Named Community %s list %s\n",
20573 entry->style == COMMUNITY_LIST_STANDARD
20574 ? "standard"
20575 : "expanded",
20576 list->name);
20577 }
20578 if (entry->any)
20579 vty_out(vty, " %s\n",
20580 community_direct_str(entry->direct));
20581 else
20582 vty_out(vty, " %s %s\n",
20583 community_direct_str(entry->direct),
20584 community_list_config_str(entry));
20585 }
20586 }
20587
20588 DEFUN (show_community_list,
20589 show_bgp_community_list_cmd,
20590 "show bgp community-list",
20591 SHOW_STR
20592 BGP_STR
20593 "List community-list\n")
20594 {
20595 struct community_list *list;
20596 struct community_list_master *cm;
20597
20598 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20599 if (!cm)
20600 return CMD_SUCCESS;
20601
20602 for (list = cm->num.head; list; list = list->next)
20603 community_list_show(vty, list);
20604
20605 for (list = cm->str.head; list; list = list->next)
20606 community_list_show(vty, list);
20607
20608 return CMD_SUCCESS;
20609 }
20610
20611 DEFUN (show_community_list_arg,
20612 show_bgp_community_list_arg_cmd,
20613 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20614 SHOW_STR
20615 BGP_STR
20616 "List community-list\n"
20617 "Community-list number\n"
20618 "Community-list name\n"
20619 "Detailed information on community-list\n")
20620 {
20621 int idx_comm_list = 3;
20622 struct community_list *list;
20623
20624 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20625 COMMUNITY_LIST_MASTER);
20626 if (!list) {
20627 vty_out(vty, "%% Can't find community-list\n");
20628 return CMD_WARNING;
20629 }
20630
20631 community_list_show(vty, list);
20632
20633 return CMD_SUCCESS;
20634 }
20635
20636 /*
20637 * Large Community code.
20638 */
20639 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20640 struct cmd_token **argv, int style,
20641 int reject_all_digit_name)
20642 {
20643 int ret;
20644 int direct;
20645 char *str;
20646 int idx = 0;
20647 char *cl_name;
20648 char *seq = NULL;
20649
20650 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20651 seq = argv[idx]->arg;
20652
20653 idx = 0;
20654 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20655 : COMMUNITY_DENY;
20656
20657 /* All digit name check. */
20658 idx = 0;
20659 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20660 argv_find(argv, argc, "(1-99)", &idx);
20661 argv_find(argv, argc, "(100-500)", &idx);
20662 cl_name = argv[idx]->arg;
20663 if (reject_all_digit_name && all_digit(cl_name)) {
20664 vty_out(vty, "%% Community name cannot have all digits\n");
20665 return CMD_WARNING_CONFIG_FAILED;
20666 }
20667
20668 idx = 0;
20669 argv_find(argv, argc, "AA:BB:CC", &idx);
20670 argv_find(argv, argc, "LINE", &idx);
20671 /* Concat community string argument. */
20672 if (idx)
20673 str = argv_concat(argv, argc, idx);
20674 else
20675 str = NULL;
20676
20677 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20678
20679 /* Free temporary community list string allocated by
20680 argv_concat(). */
20681 XFREE(MTYPE_TMP, str);
20682
20683 if (ret < 0) {
20684 community_list_perror(vty, ret);
20685 return CMD_WARNING_CONFIG_FAILED;
20686 }
20687 return CMD_SUCCESS;
20688 }
20689
20690 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20691 struct cmd_token **argv, int style)
20692 {
20693 int ret;
20694 int direct = 0;
20695 char *str = NULL;
20696 int idx = 0;
20697 char *seq = NULL;
20698
20699 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20700 seq = argv[idx]->arg;
20701
20702 idx = 0;
20703 argv_find(argv, argc, "permit", &idx);
20704 argv_find(argv, argc, "deny", &idx);
20705
20706 if (idx) {
20707 /* Check the list direct. */
20708 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20709 direct = COMMUNITY_PERMIT;
20710 else
20711 direct = COMMUNITY_DENY;
20712
20713 idx = 0;
20714 argv_find(argv, argc, "LINE", &idx);
20715 argv_find(argv, argc, "AA:AA:NN", &idx);
20716 /* Concat community string argument. */
20717 str = argv_concat(argv, argc, idx);
20718 }
20719
20720 idx = 0;
20721 argv_find(argv, argc, "(1-99)", &idx);
20722 argv_find(argv, argc, "(100-500)", &idx);
20723 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20724
20725 /* Unset community list. */
20726 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20727 style);
20728
20729 /* Free temporary community list string allocated by
20730 argv_concat(). */
20731 XFREE(MTYPE_TMP, str);
20732
20733 if (ret < 0) {
20734 community_list_perror(vty, ret);
20735 return CMD_WARNING_CONFIG_FAILED;
20736 }
20737
20738 return CMD_SUCCESS;
20739 }
20740
20741 /* "large-community-list" keyword help string. */
20742 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20743 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20744
20745 DEFUN (lcommunity_list_standard,
20746 bgp_lcommunity_list_standard_cmd,
20747 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20748 BGP_STR
20749 LCOMMUNITY_LIST_STR
20750 "Large Community list number (standard)\n"
20751 "Sequence number of an entry\n"
20752 "Sequence number\n"
20753 "Specify large community to reject\n"
20754 "Specify large community to accept\n"
20755 LCOMMUNITY_VAL_STR)
20756 {
20757 return lcommunity_list_set_vty(vty, argc, argv,
20758 LARGE_COMMUNITY_LIST_STANDARD, 0);
20759 }
20760
20761 DEFUN (lcommunity_list_expanded,
20762 bgp_lcommunity_list_expanded_cmd,
20763 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20764 BGP_STR
20765 LCOMMUNITY_LIST_STR
20766 "Large Community list number (expanded)\n"
20767 "Sequence number of an entry\n"
20768 "Sequence number\n"
20769 "Specify large community to reject\n"
20770 "Specify large community to accept\n"
20771 "An ordered list as a regular-expression\n")
20772 {
20773 return lcommunity_list_set_vty(vty, argc, argv,
20774 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20775 }
20776
20777 DEFUN (lcommunity_list_name_standard,
20778 bgp_lcommunity_list_name_standard_cmd,
20779 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20780 BGP_STR
20781 LCOMMUNITY_LIST_STR
20782 "Specify standard large-community-list\n"
20783 "Large Community list name\n"
20784 "Sequence number of an entry\n"
20785 "Sequence number\n"
20786 "Specify large community to reject\n"
20787 "Specify large community to accept\n"
20788 LCOMMUNITY_VAL_STR)
20789 {
20790 return lcommunity_list_set_vty(vty, argc, argv,
20791 LARGE_COMMUNITY_LIST_STANDARD, 1);
20792 }
20793
20794 DEFUN (lcommunity_list_name_expanded,
20795 bgp_lcommunity_list_name_expanded_cmd,
20796 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20797 BGP_STR
20798 LCOMMUNITY_LIST_STR
20799 "Specify expanded large-community-list\n"
20800 "Large Community list name\n"
20801 "Sequence number of an entry\n"
20802 "Sequence number\n"
20803 "Specify large community to reject\n"
20804 "Specify large community to accept\n"
20805 "An ordered list as a regular-expression\n")
20806 {
20807 return lcommunity_list_set_vty(vty, argc, argv,
20808 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20809 }
20810
20811 DEFUN (no_lcommunity_list_all,
20812 no_bgp_lcommunity_list_all_cmd,
20813 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20814 NO_STR
20815 BGP_STR
20816 LCOMMUNITY_LIST_STR
20817 "Large Community list number (standard)\n"
20818 "Large Community list number (expanded)\n"
20819 "Large Community list name\n")
20820 {
20821 return lcommunity_list_unset_vty(vty, argc, argv,
20822 LARGE_COMMUNITY_LIST_STANDARD);
20823 }
20824
20825 DEFUN (no_lcommunity_list_name_standard_all,
20826 no_bgp_lcommunity_list_name_standard_all_cmd,
20827 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20828 NO_STR
20829 BGP_STR
20830 LCOMMUNITY_LIST_STR
20831 "Specify standard large-community-list\n"
20832 "Large Community list name\n")
20833 {
20834 return lcommunity_list_unset_vty(vty, argc, argv,
20835 LARGE_COMMUNITY_LIST_STANDARD);
20836 }
20837
20838 DEFUN (no_lcommunity_list_name_expanded_all,
20839 no_bgp_lcommunity_list_name_expanded_all_cmd,
20840 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20841 NO_STR
20842 BGP_STR
20843 LCOMMUNITY_LIST_STR
20844 "Specify expanded large-community-list\n"
20845 "Large Community list name\n")
20846 {
20847 return lcommunity_list_unset_vty(vty, argc, argv,
20848 LARGE_COMMUNITY_LIST_EXPANDED);
20849 }
20850
20851 DEFUN (no_lcommunity_list_standard,
20852 no_bgp_lcommunity_list_standard_cmd,
20853 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20854 NO_STR
20855 BGP_STR
20856 LCOMMUNITY_LIST_STR
20857 "Large Community list number (standard)\n"
20858 "Sequence number of an entry\n"
20859 "Sequence number\n"
20860 "Specify large community to reject\n"
20861 "Specify large community to accept\n"
20862 LCOMMUNITY_VAL_STR)
20863 {
20864 return lcommunity_list_unset_vty(vty, argc, argv,
20865 LARGE_COMMUNITY_LIST_STANDARD);
20866 }
20867
20868 DEFUN (no_lcommunity_list_expanded,
20869 no_bgp_lcommunity_list_expanded_cmd,
20870 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20871 NO_STR
20872 BGP_STR
20873 LCOMMUNITY_LIST_STR
20874 "Large Community list number (expanded)\n"
20875 "Sequence number of an entry\n"
20876 "Sequence number\n"
20877 "Specify large community to reject\n"
20878 "Specify large community to accept\n"
20879 "An ordered list as a regular-expression\n")
20880 {
20881 return lcommunity_list_unset_vty(vty, argc, argv,
20882 LARGE_COMMUNITY_LIST_EXPANDED);
20883 }
20884
20885 DEFUN (no_lcommunity_list_name_standard,
20886 no_bgp_lcommunity_list_name_standard_cmd,
20887 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20888 NO_STR
20889 BGP_STR
20890 LCOMMUNITY_LIST_STR
20891 "Specify standard large-community-list\n"
20892 "Large Community list name\n"
20893 "Sequence number of an entry\n"
20894 "Sequence number\n"
20895 "Specify large community to reject\n"
20896 "Specify large community to accept\n"
20897 LCOMMUNITY_VAL_STR)
20898 {
20899 return lcommunity_list_unset_vty(vty, argc, argv,
20900 LARGE_COMMUNITY_LIST_STANDARD);
20901 }
20902
20903 DEFUN (no_lcommunity_list_name_expanded,
20904 no_bgp_lcommunity_list_name_expanded_cmd,
20905 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20906 NO_STR
20907 BGP_STR
20908 LCOMMUNITY_LIST_STR
20909 "Specify expanded large-community-list\n"
20910 "Large community list name\n"
20911 "Sequence number of an entry\n"
20912 "Sequence number\n"
20913 "Specify large community to reject\n"
20914 "Specify large community to accept\n"
20915 "An ordered list as a regular-expression\n")
20916 {
20917 return lcommunity_list_unset_vty(vty, argc, argv,
20918 LARGE_COMMUNITY_LIST_EXPANDED);
20919 }
20920
20921 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20922 {
20923 struct community_entry *entry;
20924
20925 for (entry = list->head; entry; entry = entry->next) {
20926 if (entry == list->head) {
20927 if (all_digit(list->name))
20928 vty_out(vty, "Large community %s list %s\n",
20929 entry->style ==
20930 LARGE_COMMUNITY_LIST_STANDARD
20931 ? "standard"
20932 : "(expanded) access",
20933 list->name);
20934 else
20935 vty_out(vty,
20936 "Named large community %s list %s\n",
20937 entry->style ==
20938 LARGE_COMMUNITY_LIST_STANDARD
20939 ? "standard"
20940 : "expanded",
20941 list->name);
20942 }
20943 if (entry->any)
20944 vty_out(vty, " %s\n",
20945 community_direct_str(entry->direct));
20946 else
20947 vty_out(vty, " %s %s\n",
20948 community_direct_str(entry->direct),
20949 community_list_config_str(entry));
20950 }
20951 }
20952
20953 DEFUN (show_lcommunity_list,
20954 show_bgp_lcommunity_list_cmd,
20955 "show bgp large-community-list",
20956 SHOW_STR
20957 BGP_STR
20958 "List large-community list\n")
20959 {
20960 struct community_list *list;
20961 struct community_list_master *cm;
20962
20963 cm = community_list_master_lookup(bgp_clist,
20964 LARGE_COMMUNITY_LIST_MASTER);
20965 if (!cm)
20966 return CMD_SUCCESS;
20967
20968 for (list = cm->num.head; list; list = list->next)
20969 lcommunity_list_show(vty, list);
20970
20971 for (list = cm->str.head; list; list = list->next)
20972 lcommunity_list_show(vty, list);
20973
20974 return CMD_SUCCESS;
20975 }
20976
20977 DEFUN (show_lcommunity_list_arg,
20978 show_bgp_lcommunity_list_arg_cmd,
20979 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20980 SHOW_STR
20981 BGP_STR
20982 "List large-community list\n"
20983 "Large-community-list number\n"
20984 "Large-community-list name\n"
20985 "Detailed information on large-community-list\n")
20986 {
20987 struct community_list *list;
20988
20989 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20990 LARGE_COMMUNITY_LIST_MASTER);
20991 if (!list) {
20992 vty_out(vty, "%% Can't find large-community-list\n");
20993 return CMD_WARNING;
20994 }
20995
20996 lcommunity_list_show(vty, list);
20997
20998 return CMD_SUCCESS;
20999 }
21000
21001 /* "extcommunity-list" keyword help string. */
21002 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
21003 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
21004
21005 DEFUN (extcommunity_list_standard,
21006 bgp_extcommunity_list_standard_cmd,
21007 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21008 BGP_STR
21009 EXTCOMMUNITY_LIST_STR
21010 "Extended Community list number (standard)\n"
21011 "Specify standard extcommunity-list\n"
21012 "Community list name\n"
21013 "Sequence number of an entry\n"
21014 "Sequence number\n"
21015 "Specify community to reject\n"
21016 "Specify community to accept\n"
21017 EXTCOMMUNITY_VAL_STR)
21018 {
21019 int style = EXTCOMMUNITY_LIST_STANDARD;
21020 int direct = 0;
21021 char *cl_number_or_name = NULL;
21022 char *seq = NULL;
21023
21024 int idx = 0;
21025
21026 argv_find(argv, argc, "(1-99)", &idx);
21027 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21028 cl_number_or_name = argv[idx]->arg;
21029
21030 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21031 seq = argv[idx]->arg;
21032
21033 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21034 : COMMUNITY_DENY;
21035 argv_find(argv, argc, "AA:NN", &idx);
21036 char *str = argv_concat(argv, argc, idx);
21037
21038 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21039 direct, style);
21040
21041 XFREE(MTYPE_TMP, str);
21042
21043 if (ret < 0) {
21044 community_list_perror(vty, ret);
21045 return CMD_WARNING_CONFIG_FAILED;
21046 }
21047
21048 return CMD_SUCCESS;
21049 }
21050
21051 DEFUN (extcommunity_list_name_expanded,
21052 bgp_extcommunity_list_name_expanded_cmd,
21053 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21054 BGP_STR
21055 EXTCOMMUNITY_LIST_STR
21056 "Extended Community list number (expanded)\n"
21057 "Specify expanded extcommunity-list\n"
21058 "Extended Community list name\n"
21059 "Sequence number of an entry\n"
21060 "Sequence number\n"
21061 "Specify community to reject\n"
21062 "Specify community to accept\n"
21063 "An ordered list as a regular-expression\n")
21064 {
21065 int style = EXTCOMMUNITY_LIST_EXPANDED;
21066 int direct = 0;
21067 char *cl_number_or_name = NULL;
21068 char *seq = NULL;
21069 int idx = 0;
21070
21071 argv_find(argv, argc, "(100-500)", &idx);
21072 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21073 cl_number_or_name = argv[idx]->arg;
21074
21075 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21076 seq = argv[idx]->arg;
21077
21078 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21079 : COMMUNITY_DENY;
21080 argv_find(argv, argc, "LINE", &idx);
21081 char *str = argv_concat(argv, argc, idx);
21082
21083 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21084 direct, style);
21085
21086 XFREE(MTYPE_TMP, str);
21087
21088 if (ret < 0) {
21089 community_list_perror(vty, ret);
21090 return CMD_WARNING_CONFIG_FAILED;
21091 }
21092
21093 return CMD_SUCCESS;
21094 }
21095
21096 DEFUN (no_extcommunity_list_standard_all,
21097 no_bgp_extcommunity_list_standard_all_cmd,
21098 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21099 NO_STR
21100 BGP_STR
21101 EXTCOMMUNITY_LIST_STR
21102 "Extended Community list number (standard)\n"
21103 "Specify standard extcommunity-list\n"
21104 "Community list name\n"
21105 "Sequence number of an entry\n"
21106 "Sequence number\n"
21107 "Specify community to reject\n"
21108 "Specify community to accept\n"
21109 EXTCOMMUNITY_VAL_STR)
21110 {
21111 int style = EXTCOMMUNITY_LIST_STANDARD;
21112 int direct = 0;
21113 char *cl_number_or_name = NULL;
21114 char *str = NULL;
21115 char *seq = NULL;
21116 int idx = 0;
21117
21118 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21119 seq = argv[idx]->arg;
21120
21121 idx = 0;
21122 argv_find(argv, argc, "permit", &idx);
21123 argv_find(argv, argc, "deny", &idx);
21124 if (idx) {
21125 direct = argv_find(argv, argc, "permit", &idx)
21126 ? COMMUNITY_PERMIT
21127 : COMMUNITY_DENY;
21128
21129 idx = 0;
21130 argv_find(argv, argc, "AA:NN", &idx);
21131 str = argv_concat(argv, argc, idx);
21132 }
21133
21134 idx = 0;
21135 argv_find(argv, argc, "(1-99)", &idx);
21136 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21137 cl_number_or_name = argv[idx]->arg;
21138
21139 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21140 seq, direct, style);
21141
21142 XFREE(MTYPE_TMP, str);
21143
21144 if (ret < 0) {
21145 community_list_perror(vty, ret);
21146 return CMD_WARNING_CONFIG_FAILED;
21147 }
21148
21149 return CMD_SUCCESS;
21150 }
21151
21152 ALIAS(no_extcommunity_list_standard_all,
21153 no_bgp_extcommunity_list_standard_all_list_cmd,
21154 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
21155 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21156 "Extended Community list number (standard)\n"
21157 "Specify standard extcommunity-list\n"
21158 "Community list name\n")
21159
21160 DEFUN (no_extcommunity_list_expanded_all,
21161 no_bgp_extcommunity_list_expanded_all_cmd,
21162 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21163 NO_STR
21164 BGP_STR
21165 EXTCOMMUNITY_LIST_STR
21166 "Extended Community list number (expanded)\n"
21167 "Specify expanded extcommunity-list\n"
21168 "Extended Community list name\n"
21169 "Sequence number of an entry\n"
21170 "Sequence number\n"
21171 "Specify community to reject\n"
21172 "Specify community to accept\n"
21173 "An ordered list as a regular-expression\n")
21174 {
21175 int style = EXTCOMMUNITY_LIST_EXPANDED;
21176 int direct = 0;
21177 char *cl_number_or_name = NULL;
21178 char *str = NULL;
21179 char *seq = NULL;
21180 int idx = 0;
21181
21182 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21183 seq = argv[idx]->arg;
21184
21185 idx = 0;
21186 argv_find(argv, argc, "permit", &idx);
21187 argv_find(argv, argc, "deny", &idx);
21188
21189 if (idx) {
21190 direct = argv_find(argv, argc, "permit", &idx)
21191 ? COMMUNITY_PERMIT
21192 : COMMUNITY_DENY;
21193
21194 idx = 0;
21195 argv_find(argv, argc, "LINE", &idx);
21196 str = argv_concat(argv, argc, idx);
21197 }
21198
21199 idx = 0;
21200 argv_find(argv, argc, "(100-500)", &idx);
21201 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21202 cl_number_or_name = argv[idx]->arg;
21203
21204 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21205 seq, direct, style);
21206
21207 XFREE(MTYPE_TMP, str);
21208
21209 if (ret < 0) {
21210 community_list_perror(vty, ret);
21211 return CMD_WARNING_CONFIG_FAILED;
21212 }
21213
21214 return CMD_SUCCESS;
21215 }
21216
21217 ALIAS(no_extcommunity_list_expanded_all,
21218 no_bgp_extcommunity_list_expanded_all_list_cmd,
21219 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21220 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21221 "Extended Community list number (expanded)\n"
21222 "Specify expanded extcommunity-list\n"
21223 "Extended Community list name\n")
21224
21225 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21226 {
21227 struct community_entry *entry;
21228
21229 for (entry = list->head; entry; entry = entry->next) {
21230 if (entry == list->head) {
21231 if (all_digit(list->name))
21232 vty_out(vty, "Extended community %s list %s\n",
21233 entry->style == EXTCOMMUNITY_LIST_STANDARD
21234 ? "standard"
21235 : "(expanded) access",
21236 list->name);
21237 else
21238 vty_out(vty,
21239 "Named extended community %s list %s\n",
21240 entry->style == EXTCOMMUNITY_LIST_STANDARD
21241 ? "standard"
21242 : "expanded",
21243 list->name);
21244 }
21245 if (entry->any)
21246 vty_out(vty, " %s\n",
21247 community_direct_str(entry->direct));
21248 else
21249 vty_out(vty, " %s %s\n",
21250 community_direct_str(entry->direct),
21251 community_list_config_str(entry));
21252 }
21253 }
21254
21255 DEFUN (show_extcommunity_list,
21256 show_bgp_extcommunity_list_cmd,
21257 "show bgp extcommunity-list",
21258 SHOW_STR
21259 BGP_STR
21260 "List extended-community list\n")
21261 {
21262 struct community_list *list;
21263 struct community_list_master *cm;
21264
21265 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21266 if (!cm)
21267 return CMD_SUCCESS;
21268
21269 for (list = cm->num.head; list; list = list->next)
21270 extcommunity_list_show(vty, list);
21271
21272 for (list = cm->str.head; list; list = list->next)
21273 extcommunity_list_show(vty, list);
21274
21275 return CMD_SUCCESS;
21276 }
21277
21278 DEFUN (show_extcommunity_list_arg,
21279 show_bgp_extcommunity_list_arg_cmd,
21280 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21281 SHOW_STR
21282 BGP_STR
21283 "List extended-community list\n"
21284 "Extcommunity-list number\n"
21285 "Extcommunity-list name\n"
21286 "Detailed information on extcommunity-list\n")
21287 {
21288 int idx_comm_list = 3;
21289 struct community_list *list;
21290
21291 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21292 EXTCOMMUNITY_LIST_MASTER);
21293 if (!list) {
21294 vty_out(vty, "%% Can't find extcommunity-list\n");
21295 return CMD_WARNING;
21296 }
21297
21298 extcommunity_list_show(vty, list);
21299
21300 return CMD_SUCCESS;
21301 }
21302
21303 /* Display community-list and extcommunity-list configuration. */
21304 static int community_list_config_write(struct vty *vty)
21305 {
21306 struct community_list *list;
21307 struct community_entry *entry;
21308 struct community_list_master *cm;
21309 int write = 0;
21310
21311 /* Community-list. */
21312 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21313
21314 for (list = cm->num.head; list; list = list->next)
21315 for (entry = list->head; entry; entry = entry->next) {
21316 vty_out(vty,
21317 "bgp community-list %s seq %" PRId64 " %s %s\n",
21318 list->name, entry->seq,
21319 community_direct_str(entry->direct),
21320 community_list_config_str(entry));
21321 write++;
21322 }
21323 for (list = cm->str.head; list; list = list->next)
21324 for (entry = list->head; entry; entry = entry->next) {
21325 vty_out(vty,
21326 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21327 entry->style == COMMUNITY_LIST_STANDARD
21328 ? "standard"
21329 : "expanded",
21330 list->name, entry->seq,
21331 community_direct_str(entry->direct),
21332 community_list_config_str(entry));
21333 write++;
21334 }
21335
21336 /* Extcommunity-list. */
21337 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21338
21339 for (list = cm->num.head; list; list = list->next)
21340 for (entry = list->head; entry; entry = entry->next) {
21341 vty_out(vty,
21342 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21343 list->name, entry->seq,
21344 community_direct_str(entry->direct),
21345 community_list_config_str(entry));
21346 write++;
21347 }
21348 for (list = cm->str.head; list; list = list->next)
21349 for (entry = list->head; entry; entry = entry->next) {
21350 vty_out(vty,
21351 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21352 entry->style == EXTCOMMUNITY_LIST_STANDARD
21353 ? "standard"
21354 : "expanded",
21355 list->name, entry->seq,
21356 community_direct_str(entry->direct),
21357 community_list_config_str(entry));
21358 write++;
21359 }
21360
21361
21362 /* lcommunity-list. */
21363 cm = community_list_master_lookup(bgp_clist,
21364 LARGE_COMMUNITY_LIST_MASTER);
21365
21366 for (list = cm->num.head; list; list = list->next)
21367 for (entry = list->head; entry; entry = entry->next) {
21368 vty_out(vty,
21369 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21370 list->name, entry->seq,
21371 community_direct_str(entry->direct),
21372 community_list_config_str(entry));
21373 write++;
21374 }
21375 for (list = cm->str.head; list; list = list->next)
21376 for (entry = list->head; entry; entry = entry->next) {
21377 vty_out(vty,
21378 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21379
21380 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21381 ? "standard"
21382 : "expanded",
21383 list->name, entry->seq, community_direct_str(entry->direct),
21384 community_list_config_str(entry));
21385 write++;
21386 }
21387
21388 return write;
21389 }
21390
21391 static int community_list_config_write(struct vty *vty);
21392 static struct cmd_node community_list_node = {
21393 .name = "community list",
21394 .node = COMMUNITY_LIST_NODE,
21395 .prompt = "",
21396 .config_write = community_list_config_write,
21397 };
21398
21399 static void community_list_vty(void)
21400 {
21401 install_node(&community_list_node);
21402
21403 /* Community-list. */
21404 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21405 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21406 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21407 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21408 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21409 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21410 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21411 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21412
21413 /* Extcommunity-list. */
21414 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21415 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21416 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21417 install_element(CONFIG_NODE,
21418 &no_bgp_extcommunity_list_standard_all_list_cmd);
21419 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21420 install_element(CONFIG_NODE,
21421 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21422 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21423 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21424
21425 /* Large Community List */
21426 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21427 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21428 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21429 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21430 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21431 install_element(CONFIG_NODE,
21432 &no_bgp_lcommunity_list_name_standard_all_cmd);
21433 install_element(CONFIG_NODE,
21434 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21435 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21436 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21437 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21438 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21439 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21440 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21441
21442 bgp_community_list_command_completion_setup();
21443 }
21444
21445 static struct cmd_node community_alias_node = {
21446 .name = "community alias",
21447 .node = COMMUNITY_ALIAS_NODE,
21448 .prompt = "",
21449 .config_write = bgp_community_alias_write,
21450 };
21451
21452 void community_alias_vty(void)
21453 {
21454 install_node(&community_alias_node);
21455
21456 /* Community-list. */
21457 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21458
21459 bgp_community_alias_command_completion_setup();
21460 }