]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
zebra: clang-format style fixes
[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 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8844 struct ecommunity **list, bool is_rt6)
8845 {
8846 struct ecommunity *ecom = NULL;
8847 struct ecommunity *ecomadd;
8848
8849 for (; argc; --argc, ++argv) {
8850 if (is_rt6)
8851 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8852 ECOMMUNITY_ROUTE_TARGET,
8853 0);
8854 else
8855 ecomadd = ecommunity_str2com(argv[0]->arg,
8856 ECOMMUNITY_ROUTE_TARGET,
8857 0);
8858 if (!ecomadd) {
8859 vty_out(vty, "Malformed community-list value\n");
8860 if (ecom)
8861 ecommunity_free(&ecom);
8862 return CMD_WARNING_CONFIG_FAILED;
8863 }
8864
8865 if (ecom) {
8866 ecommunity_merge(ecom, ecomadd);
8867 ecommunity_free(&ecomadd);
8868 } else {
8869 ecom = ecomadd;
8870 }
8871 }
8872
8873 if (*list) {
8874 ecommunity_free(&*list);
8875 }
8876 *list = ecom;
8877
8878 return CMD_SUCCESS;
8879 }
8880
8881 /*
8882 * v2vimport is true if we are handling a `import vrf ...` command
8883 */
8884 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8885 {
8886 afi_t afi;
8887
8888 switch (vty->node) {
8889 case BGP_IPV4_NODE:
8890 afi = AFI_IP;
8891 break;
8892 case BGP_IPV6_NODE:
8893 afi = AFI_IP6;
8894 break;
8895 default:
8896 vty_out(vty,
8897 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8898 return AFI_MAX;
8899 }
8900
8901 if (!v2vimport) {
8902 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8903 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8904 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8905 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8906 vty_out(vty,
8907 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8908 return AFI_MAX;
8909 }
8910 } else {
8911 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8912 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8913 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8914 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8915 vty_out(vty,
8916 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8917 return AFI_MAX;
8918 }
8919 }
8920 return afi;
8921 }
8922
8923 DEFPY (af_rd_vpn_export,
8924 af_rd_vpn_export_cmd,
8925 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8926 NO_STR
8927 "Specify route distinguisher\n"
8928 "Between current address-family and vpn\n"
8929 "For routes leaked from current address-family to vpn\n"
8930 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8931 {
8932 VTY_DECLVAR_CONTEXT(bgp, bgp);
8933 struct prefix_rd prd;
8934 int ret;
8935 afi_t afi;
8936 int idx = 0;
8937 bool yes = true;
8938
8939 if (argv_find(argv, argc, "no", &idx))
8940 yes = false;
8941
8942 if (yes) {
8943 ret = str2prefix_rd(rd_str, &prd);
8944 if (!ret) {
8945 vty_out(vty, "%% Malformed rd\n");
8946 return CMD_WARNING_CONFIG_FAILED;
8947 }
8948 }
8949
8950 afi = vpn_policy_getafi(vty, bgp, false);
8951 if (afi == AFI_MAX)
8952 return CMD_WARNING_CONFIG_FAILED;
8953
8954 /*
8955 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8956 */
8957 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8958 bgp_get_default(), bgp);
8959
8960 if (yes) {
8961 bgp->vpn_policy[afi].tovpn_rd = prd;
8962 SET_FLAG(bgp->vpn_policy[afi].flags,
8963 BGP_VPN_POLICY_TOVPN_RD_SET);
8964 } else {
8965 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8966 BGP_VPN_POLICY_TOVPN_RD_SET);
8967 }
8968
8969 /* post-change: re-export vpn routes */
8970 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8971 bgp_get_default(), bgp);
8972
8973 return CMD_SUCCESS;
8974 }
8975
8976 ALIAS (af_rd_vpn_export,
8977 af_no_rd_vpn_export_cmd,
8978 "no rd vpn export",
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
8984 DEFPY (af_label_vpn_export,
8985 af_label_vpn_export_cmd,
8986 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8987 NO_STR
8988 "label value for VRF\n"
8989 "Between current address-family and vpn\n"
8990 "For routes leaked from current address-family to vpn\n"
8991 "Label Value <0-1048575>\n"
8992 "Automatically assign a label\n")
8993 {
8994 VTY_DECLVAR_CONTEXT(bgp, bgp);
8995 mpls_label_t label = MPLS_LABEL_NONE;
8996 afi_t afi;
8997 int idx = 0;
8998 bool yes = true;
8999
9000 if (argv_find(argv, argc, "no", &idx))
9001 yes = false;
9002
9003 /* If "no ...", squash trailing parameter */
9004 if (!yes)
9005 label_auto = NULL;
9006
9007 if (yes) {
9008 if (!label_auto)
9009 label = label_val; /* parser should force unsigned */
9010 }
9011
9012 afi = vpn_policy_getafi(vty, bgp, false);
9013 if (afi == AFI_MAX)
9014 return CMD_WARNING_CONFIG_FAILED;
9015
9016
9017 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9018 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9019 /* no change */
9020 return CMD_SUCCESS;
9021
9022 /*
9023 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9024 */
9025 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9026 bgp_get_default(), bgp);
9027
9028 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9029 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9030
9031 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9032
9033 /*
9034 * label has previously been automatically
9035 * assigned by labelpool: release it
9036 *
9037 * NB if tovpn_label == MPLS_LABEL_NONE it
9038 * means the automatic assignment is in flight
9039 * and therefore the labelpool callback must
9040 * detect that the auto label is not needed.
9041 */
9042
9043 bgp_lp_release(LP_TYPE_VRF,
9044 &bgp->vpn_policy[afi],
9045 bgp->vpn_policy[afi].tovpn_label);
9046 }
9047 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9048 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9049 }
9050
9051 bgp->vpn_policy[afi].tovpn_label = label;
9052 if (label_auto) {
9053 SET_FLAG(bgp->vpn_policy[afi].flags,
9054 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9055 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9056 vpn_leak_label_callback);
9057 }
9058
9059 /* post-change: re-export vpn routes */
9060 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9061 bgp_get_default(), bgp);
9062
9063 hook_call(bgp_snmp_update_last_changed, bgp);
9064 return CMD_SUCCESS;
9065 }
9066
9067 DEFPY (af_sid_vpn_export,
9068 af_sid_vpn_export_cmd,
9069 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9070 NO_STR
9071 "sid value for VRF\n"
9072 "Between current address-family and vpn\n"
9073 "For routes leaked from current address-family to vpn\n"
9074 "Sid allocation index\n"
9075 "Automatically assign a label\n")
9076 {
9077 VTY_DECLVAR_CONTEXT(bgp, bgp);
9078 afi_t afi;
9079 int debug = 0;
9080 int idx = 0;
9081 bool yes = true;
9082
9083 if (argv_find(argv, argc, "no", &idx))
9084 yes = false;
9085 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9086 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9087
9088 afi = vpn_policy_getafi(vty, bgp, false);
9089 if (afi == AFI_MAX)
9090 return CMD_WARNING_CONFIG_FAILED;
9091
9092 if (!yes) {
9093 /* implement me */
9094 vty_out(vty, "It's not implemented\n");
9095 return CMD_WARNING_CONFIG_FAILED;
9096 }
9097
9098 if (bgp->tovpn_sid_index != 0 ||
9099 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9100 vty_out(vty,
9101 "per-vrf sid and per-af sid are mutually exclusive\n"
9102 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9103 return CMD_WARNING_CONFIG_FAILED;
9104 }
9105
9106 /* skip when it's already configured */
9107 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9108 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9109 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9110 return CMD_SUCCESS;
9111
9112 /*
9113 * mode change between sid_idx and sid_auto isn't supported.
9114 * user must negate sid vpn export when they want to change the mode
9115 */
9116 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9117 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9118 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9119 vty_out(vty, "it's already configured as %s.\n",
9120 sid_auto ? "auto-mode" : "idx-mode");
9121 return CMD_WARNING_CONFIG_FAILED;
9122 }
9123
9124 /* pre-change */
9125 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9126 bgp_get_default(), bgp);
9127
9128 if (sid_auto) {
9129 /* SID allocation auto-mode */
9130 if (debug)
9131 zlog_debug("%s: auto sid alloc.", __func__);
9132 SET_FLAG(bgp->vpn_policy[afi].flags,
9133 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9134 } else {
9135 /* SID allocation index-mode */
9136 if (debug)
9137 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9138 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9139 }
9140
9141 /* post-change */
9142 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9143 bgp_get_default(), bgp);
9144 return CMD_SUCCESS;
9145 }
9146
9147 DEFPY (bgp_sid_vpn_export,
9148 bgp_sid_vpn_export_cmd,
9149 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9150 NO_STR
9151 "sid value for VRF\n"
9152 "Between current vrf and vpn\n"
9153 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9154 "For routes leaked from current vrf to vpn\n"
9155 "Sid allocation index\n"
9156 "Automatically assign a label\n")
9157 {
9158 VTY_DECLVAR_CONTEXT(bgp, bgp);
9159 int debug;
9160
9161 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9162 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9163
9164 if (no) {
9165 /* when per-VRF SID is not set, do nothing */
9166 if (bgp->tovpn_sid_index == 0 &&
9167 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9168 return CMD_SUCCESS;
9169
9170 sid_idx = 0;
9171 sid_auto = false;
9172 bgp->tovpn_sid_index = 0;
9173 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9174 }
9175
9176 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9177 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9178 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9179 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9180 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9181 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9182 vty_out(vty,
9183 "per-vrf sid and per-af sid are mutually exclusive\n"
9184 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9185 return CMD_WARNING_CONFIG_FAILED;
9186 }
9187
9188 /* skip when it's already configured */
9189 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9190 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9191 return CMD_SUCCESS;
9192
9193 /*
9194 * mode change between sid_idx and sid_auto isn't supported.
9195 * user must negate sid vpn export when they want to change the mode
9196 */
9197 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9198 (sid_idx != 0 &&
9199 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9200 vty_out(vty, "it's already configured as %s.\n",
9201 sid_auto ? "auto-mode" : "idx-mode");
9202 return CMD_WARNING_CONFIG_FAILED;
9203 }
9204
9205 /* pre-change */
9206 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9207 bgp);
9208 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9209 bgp);
9210
9211 if (sid_auto) {
9212 /* SID allocation auto-mode */
9213 if (debug)
9214 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9215 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9216 } else if (sid_idx != 0) {
9217 /* SID allocation index-mode */
9218 if (debug)
9219 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9220 sid_idx);
9221 bgp->tovpn_sid_index = sid_idx;
9222 }
9223
9224 /* post-change */
9225 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9226 bgp);
9227 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9228 bgp_get_default(), bgp);
9229
9230 return CMD_SUCCESS;
9231 }
9232
9233 ALIAS (af_label_vpn_export,
9234 af_no_label_vpn_export_cmd,
9235 "no label vpn export",
9236 NO_STR
9237 "label value for VRF\n"
9238 "Between current address-family and vpn\n"
9239 "For routes leaked from current address-family to vpn\n")
9240
9241 ALIAS (bgp_sid_vpn_export,
9242 no_bgp_sid_vpn_export_cmd,
9243 "no$no sid vpn per-vrf export",
9244 NO_STR
9245 "sid value for VRF\n"
9246 "Between current vrf and vpn\n"
9247 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9248 "For routes leaked from current vrf to vpn\n")
9249
9250 DEFPY (af_nexthop_vpn_export,
9251 af_nexthop_vpn_export_cmd,
9252 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9253 NO_STR
9254 "Specify next hop to use for VRF advertised prefixes\n"
9255 "Between current address-family and vpn\n"
9256 "For routes leaked from current address-family to vpn\n"
9257 "IPv4 prefix\n"
9258 "IPv6 prefix\n")
9259 {
9260 VTY_DECLVAR_CONTEXT(bgp, bgp);
9261 afi_t afi;
9262 struct prefix p;
9263
9264 if (!no) {
9265 if (!nexthop_su) {
9266 vty_out(vty, "%% Nexthop required\n");
9267 return CMD_WARNING_CONFIG_FAILED;
9268 }
9269 if (!sockunion2hostprefix(nexthop_su, &p))
9270 return CMD_WARNING_CONFIG_FAILED;
9271 }
9272
9273 afi = vpn_policy_getafi(vty, bgp, false);
9274 if (afi == AFI_MAX)
9275 return CMD_WARNING_CONFIG_FAILED;
9276
9277 /*
9278 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9279 */
9280 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9281 bgp_get_default(), bgp);
9282
9283 if (!no) {
9284 bgp->vpn_policy[afi].tovpn_nexthop = p;
9285 SET_FLAG(bgp->vpn_policy[afi].flags,
9286 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9287 } else {
9288 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9289 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9290 }
9291
9292 /* post-change: re-export vpn routes */
9293 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9294 bgp_get_default(), bgp);
9295
9296 return CMD_SUCCESS;
9297 }
9298
9299 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9300 {
9301 if (!strcmp(dstr, "import")) {
9302 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9303 } else if (!strcmp(dstr, "export")) {
9304 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9305 } else if (!strcmp(dstr, "both")) {
9306 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9307 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9308 } else {
9309 vty_out(vty, "%% direction parse error\n");
9310 return CMD_WARNING_CONFIG_FAILED;
9311 }
9312 return CMD_SUCCESS;
9313 }
9314
9315 DEFPY (af_rt_vpn_imexport,
9316 af_rt_vpn_imexport_cmd,
9317 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9318 NO_STR
9319 "Specify route target list\n"
9320 "Specify route target list\n"
9321 "Between current address-family and vpn\n"
9322 "For routes leaked from vpn to current address-family: match any\n"
9323 "For routes leaked from current address-family to vpn: set\n"
9324 "both import: match any and export: set\n"
9325 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9326 {
9327 VTY_DECLVAR_CONTEXT(bgp, bgp);
9328 int ret;
9329 struct ecommunity *ecom = NULL;
9330 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9331 enum vpn_policy_direction dir;
9332 afi_t afi;
9333 int idx = 0;
9334 bool yes = true;
9335
9336 if (argv_find(argv, argc, "no", &idx))
9337 yes = false;
9338
9339 afi = vpn_policy_getafi(vty, bgp, false);
9340 if (afi == AFI_MAX)
9341 return CMD_WARNING_CONFIG_FAILED;
9342
9343 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9344 if (ret != CMD_SUCCESS)
9345 return ret;
9346
9347 if (yes) {
9348 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9349 vty_out(vty, "%% Missing RTLIST\n");
9350 return CMD_WARNING_CONFIG_FAILED;
9351 }
9352 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9353 if (ret != CMD_SUCCESS) {
9354 return ret;
9355 }
9356 }
9357
9358 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9359 if (!dodir[dir])
9360 continue;
9361
9362 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9363
9364 if (yes) {
9365 if (bgp->vpn_policy[afi].rtlist[dir])
9366 ecommunity_free(
9367 &bgp->vpn_policy[afi].rtlist[dir]);
9368 bgp->vpn_policy[afi].rtlist[dir] =
9369 ecommunity_dup(ecom);
9370 } else {
9371 if (bgp->vpn_policy[afi].rtlist[dir])
9372 ecommunity_free(
9373 &bgp->vpn_policy[afi].rtlist[dir]);
9374 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9375 }
9376
9377 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9378 }
9379
9380 if (ecom)
9381 ecommunity_free(&ecom);
9382
9383 return CMD_SUCCESS;
9384 }
9385
9386 ALIAS (af_rt_vpn_imexport,
9387 af_no_rt_vpn_imexport_cmd,
9388 "no <rt|route-target> vpn <import|export|both>$direction_str",
9389 NO_STR
9390 "Specify route target list\n"
9391 "Specify route target list\n"
9392 "Between current address-family and vpn\n"
9393 "For routes leaked from vpn to current address-family\n"
9394 "For routes leaked from current address-family to vpn\n"
9395 "both import and export\n")
9396
9397 DEFPY (af_route_map_vpn_imexport,
9398 af_route_map_vpn_imexport_cmd,
9399 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9400 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9401 NO_STR
9402 "Specify route map\n"
9403 "Between current address-family and vpn\n"
9404 "For routes leaked from vpn to current address-family\n"
9405 "For routes leaked from current address-family to vpn\n"
9406 "name of route-map\n")
9407 {
9408 VTY_DECLVAR_CONTEXT(bgp, bgp);
9409 int ret;
9410 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9411 enum vpn_policy_direction dir;
9412 afi_t afi;
9413 int idx = 0;
9414 bool yes = true;
9415
9416 if (argv_find(argv, argc, "no", &idx))
9417 yes = false;
9418
9419 afi = vpn_policy_getafi(vty, bgp, false);
9420 if (afi == AFI_MAX)
9421 return CMD_WARNING_CONFIG_FAILED;
9422
9423 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9424 if (ret != CMD_SUCCESS)
9425 return ret;
9426
9427 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9428 if (!dodir[dir])
9429 continue;
9430
9431 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9432
9433 if (yes) {
9434 if (bgp->vpn_policy[afi].rmap_name[dir])
9435 XFREE(MTYPE_ROUTE_MAP_NAME,
9436 bgp->vpn_policy[afi].rmap_name[dir]);
9437 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9438 MTYPE_ROUTE_MAP_NAME, rmap_str);
9439 bgp->vpn_policy[afi].rmap[dir] =
9440 route_map_lookup_warn_noexist(vty, rmap_str);
9441 if (!bgp->vpn_policy[afi].rmap[dir])
9442 return CMD_SUCCESS;
9443 } else {
9444 if (bgp->vpn_policy[afi].rmap_name[dir])
9445 XFREE(MTYPE_ROUTE_MAP_NAME,
9446 bgp->vpn_policy[afi].rmap_name[dir]);
9447 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9448 bgp->vpn_policy[afi].rmap[dir] = NULL;
9449 }
9450
9451 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9452 }
9453
9454 return CMD_SUCCESS;
9455 }
9456
9457 ALIAS (af_route_map_vpn_imexport,
9458 af_no_route_map_vpn_imexport_cmd,
9459 "no route-map vpn <import|export>$direction_str",
9460 NO_STR
9461 "Specify route map\n"
9462 "Between current address-family and vpn\n"
9463 "For routes leaked from vpn to current address-family\n"
9464 "For routes leaked from current address-family to vpn\n")
9465
9466 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9467 "import vrf route-map RMAP$rmap_str",
9468 "Import routes from another VRF\n"
9469 "Vrf routes being filtered\n"
9470 "Specify route map\n"
9471 "name of route-map\n")
9472 {
9473 VTY_DECLVAR_CONTEXT(bgp, bgp);
9474 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9475 afi_t afi;
9476 struct bgp *bgp_default;
9477
9478 afi = vpn_policy_getafi(vty, bgp, true);
9479 if (afi == AFI_MAX)
9480 return CMD_WARNING_CONFIG_FAILED;
9481
9482 bgp_default = bgp_get_default();
9483 if (!bgp_default) {
9484 int32_t ret;
9485 as_t as = bgp->as;
9486
9487 /* Auto-create assuming the same AS */
9488 ret = bgp_get_vty(&bgp_default, &as, NULL,
9489 BGP_INSTANCE_TYPE_DEFAULT);
9490
9491 if (ret) {
9492 vty_out(vty,
9493 "VRF default is not configured as a bgp instance\n");
9494 return CMD_WARNING;
9495 }
9496 }
9497
9498 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9499
9500 if (bgp->vpn_policy[afi].rmap_name[dir])
9501 XFREE(MTYPE_ROUTE_MAP_NAME,
9502 bgp->vpn_policy[afi].rmap_name[dir]);
9503 bgp->vpn_policy[afi].rmap_name[dir] =
9504 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9505 bgp->vpn_policy[afi].rmap[dir] =
9506 route_map_lookup_warn_noexist(vty, rmap_str);
9507 if (!bgp->vpn_policy[afi].rmap[dir])
9508 return CMD_SUCCESS;
9509
9510 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9511 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9512
9513 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9514
9515 return CMD_SUCCESS;
9516 }
9517
9518 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9519 "no import vrf route-map [RMAP$rmap_str]",
9520 NO_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
9530 afi = vpn_policy_getafi(vty, bgp, true);
9531 if (afi == AFI_MAX)
9532 return CMD_WARNING_CONFIG_FAILED;
9533
9534 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9535
9536 if (bgp->vpn_policy[afi].rmap_name[dir])
9537 XFREE(MTYPE_ROUTE_MAP_NAME,
9538 bgp->vpn_policy[afi].rmap_name[dir]);
9539 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9540 bgp->vpn_policy[afi].rmap[dir] = NULL;
9541
9542 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9543 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9544 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9545
9546 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9547
9548 return CMD_SUCCESS;
9549 }
9550
9551 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9552 "[no] import vrf VIEWVRFNAME$import_name",
9553 NO_STR
9554 "Import routes from another VRF\n"
9555 "VRF to import from\n"
9556 "The name of the VRF\n")
9557 {
9558 VTY_DECLVAR_CONTEXT(bgp, bgp);
9559 struct listnode *node;
9560 struct bgp *vrf_bgp, *bgp_default;
9561 int32_t ret = 0;
9562 as_t as = bgp->as;
9563 bool remove = false;
9564 int32_t idx = 0;
9565 char *vname;
9566 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9567 safi_t safi;
9568 afi_t afi;
9569
9570 if (import_name == NULL) {
9571 vty_out(vty, "%% Missing import name\n");
9572 return CMD_WARNING;
9573 }
9574
9575 if (strcmp(import_name, "route-map") == 0) {
9576 vty_out(vty, "%% Must include route-map name\n");
9577 return CMD_WARNING;
9578 }
9579
9580 if (argv_find(argv, argc, "no", &idx))
9581 remove = true;
9582
9583 afi = vpn_policy_getafi(vty, bgp, true);
9584 if (afi == AFI_MAX)
9585 return CMD_WARNING_CONFIG_FAILED;
9586
9587 safi = bgp_node_safi(vty);
9588
9589 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9590 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9591 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9592 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9593 remove ? "unimport" : "import", import_name);
9594 return CMD_WARNING;
9595 }
9596
9597 bgp_default = bgp_get_default();
9598 if (!bgp_default) {
9599 /* Auto-create assuming the same AS */
9600 ret = bgp_get_vty(&bgp_default, &as, NULL,
9601 BGP_INSTANCE_TYPE_DEFAULT);
9602
9603 if (ret) {
9604 vty_out(vty,
9605 "VRF default is not configured as a bgp instance\n");
9606 return CMD_WARNING;
9607 }
9608 }
9609
9610 vrf_bgp = bgp_lookup_by_name(import_name);
9611 if (!vrf_bgp) {
9612 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9613 vrf_bgp = bgp_default;
9614 else
9615 /* Auto-create assuming the same AS */
9616 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9617
9618 if (ret) {
9619 vty_out(vty,
9620 "VRF %s is not configured as a bgp instance\n",
9621 import_name);
9622 return CMD_WARNING;
9623 }
9624 }
9625
9626 if (remove) {
9627 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9628 } else {
9629 /* Already importing from "import_vrf"? */
9630 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9631 vname)) {
9632 if (strcmp(vname, import_name) == 0)
9633 return CMD_WARNING;
9634 }
9635
9636 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9637 }
9638
9639 return CMD_SUCCESS;
9640 }
9641
9642 /* This command is valid only in a bgp vrf instance or the default instance */
9643 DEFPY (bgp_imexport_vpn,
9644 bgp_imexport_vpn_cmd,
9645 "[no] <import|export>$direction_str vpn",
9646 NO_STR
9647 "Import routes to this address-family\n"
9648 "Export routes from this address-family\n"
9649 "to/from default instance VPN RIB\n")
9650 {
9651 VTY_DECLVAR_CONTEXT(bgp, bgp);
9652 int previous_state;
9653 afi_t afi;
9654 safi_t safi;
9655 int idx = 0;
9656 bool yes = true;
9657 int flag;
9658 enum vpn_policy_direction dir;
9659
9660 if (argv_find(argv, argc, "no", &idx))
9661 yes = false;
9662
9663 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9664 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9665
9666 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9667 return CMD_WARNING_CONFIG_FAILED;
9668 }
9669
9670 afi = bgp_node_afi(vty);
9671 safi = bgp_node_safi(vty);
9672 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9673 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9674 return CMD_WARNING_CONFIG_FAILED;
9675 }
9676
9677 if (!strcmp(direction_str, "import")) {
9678 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9679 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9680 } else if (!strcmp(direction_str, "export")) {
9681 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9682 dir = BGP_VPN_POLICY_DIR_TOVPN;
9683 } else {
9684 vty_out(vty, "%% unknown direction %s\n", direction_str);
9685 return CMD_WARNING_CONFIG_FAILED;
9686 }
9687
9688 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9689
9690 if (yes) {
9691 SET_FLAG(bgp->af_flags[afi][safi], flag);
9692 if (!previous_state) {
9693 /* trigger export current vrf */
9694 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9695 }
9696 } else {
9697 if (previous_state) {
9698 /* trigger un-export current vrf */
9699 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9700 }
9701 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9702 }
9703
9704 hook_call(bgp_snmp_init_stats, bgp);
9705
9706 return CMD_SUCCESS;
9707 }
9708
9709 DEFPY (af_routetarget_import,
9710 af_routetarget_import_cmd,
9711 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9712 NO_STR
9713 "Specify route target list\n"
9714 "Specify route target list\n"
9715 "Specify route target list\n"
9716 "Specify route target list\n"
9717 "Flow-spec redirect type route target\n"
9718 "Import routes to this address-family\n"
9719 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9720 {
9721 VTY_DECLVAR_CONTEXT(bgp, bgp);
9722 int ret;
9723 struct ecommunity *ecom = NULL;
9724 afi_t afi;
9725 int idx = 0, idx_unused = 0;
9726 bool yes = true;
9727 bool rt6 = false;
9728
9729 if (argv_find(argv, argc, "no", &idx))
9730 yes = false;
9731
9732 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9733 argv_find(argv, argc, "route-target6", &idx_unused))
9734 rt6 = true;
9735
9736 afi = vpn_policy_getafi(vty, bgp, false);
9737 if (afi == AFI_MAX)
9738 return CMD_WARNING_CONFIG_FAILED;
9739
9740 if (rt6 && afi != AFI_IP6)
9741 return CMD_WARNING_CONFIG_FAILED;
9742
9743 if (yes) {
9744 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9745 vty_out(vty, "%% Missing RTLIST\n");
9746 return CMD_WARNING_CONFIG_FAILED;
9747 }
9748 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9749 if (ret != CMD_SUCCESS)
9750 return ret;
9751 }
9752
9753 if (yes) {
9754 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9755 ecommunity_free(&bgp->vpn_policy[afi]
9756 .import_redirect_rtlist);
9757 bgp->vpn_policy[afi].import_redirect_rtlist =
9758 ecommunity_dup(ecom);
9759 } else {
9760 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9761 ecommunity_free(&bgp->vpn_policy[afi]
9762 .import_redirect_rtlist);
9763 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9764 }
9765
9766 if (ecom)
9767 ecommunity_free(&ecom);
9768
9769 return CMD_SUCCESS;
9770 }
9771
9772 DEFUN_NOSH (address_family_ipv4_safi,
9773 address_family_ipv4_safi_cmd,
9774 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9775 "Enter Address Family command mode\n"
9776 BGP_AF_STR
9777 BGP_SAFI_WITH_LABEL_HELP_STR)
9778 {
9779
9780 if (argc == 3) {
9781 VTY_DECLVAR_CONTEXT(bgp, bgp);
9782 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9783 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9784 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9785 && safi != SAFI_EVPN) {
9786 vty_out(vty,
9787 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9788 return CMD_WARNING_CONFIG_FAILED;
9789 }
9790 vty->node = bgp_node_type(AFI_IP, safi);
9791 } else
9792 vty->node = BGP_IPV4_NODE;
9793
9794 return CMD_SUCCESS;
9795 }
9796
9797 DEFUN_NOSH (address_family_ipv6_safi,
9798 address_family_ipv6_safi_cmd,
9799 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9800 "Enter Address Family command mode\n"
9801 BGP_AF_STR
9802 BGP_SAFI_WITH_LABEL_HELP_STR)
9803 {
9804 if (argc == 3) {
9805 VTY_DECLVAR_CONTEXT(bgp, bgp);
9806 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9807 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9808 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9809 && safi != SAFI_EVPN) {
9810 vty_out(vty,
9811 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9812 return CMD_WARNING_CONFIG_FAILED;
9813 }
9814 vty->node = bgp_node_type(AFI_IP6, safi);
9815 } else
9816 vty->node = BGP_IPV6_NODE;
9817
9818 return CMD_SUCCESS;
9819 }
9820
9821 #ifdef KEEP_OLD_VPN_COMMANDS
9822 DEFUN_NOSH (address_family_vpnv4,
9823 address_family_vpnv4_cmd,
9824 "address-family vpnv4 [unicast]",
9825 "Enter Address Family command mode\n"
9826 BGP_AF_STR
9827 BGP_AF_MODIFIER_STR)
9828 {
9829 vty->node = BGP_VPNV4_NODE;
9830 return CMD_SUCCESS;
9831 }
9832
9833 DEFUN_NOSH (address_family_vpnv6,
9834 address_family_vpnv6_cmd,
9835 "address-family vpnv6 [unicast]",
9836 "Enter Address Family command mode\n"
9837 BGP_AF_STR
9838 BGP_AF_MODIFIER_STR)
9839 {
9840 vty->node = BGP_VPNV6_NODE;
9841 return CMD_SUCCESS;
9842 }
9843 #endif /* KEEP_OLD_VPN_COMMANDS */
9844
9845 DEFUN_NOSH (address_family_evpn,
9846 address_family_evpn_cmd,
9847 "address-family l2vpn evpn",
9848 "Enter Address Family command mode\n"
9849 BGP_AF_STR
9850 BGP_AF_MODIFIER_STR)
9851 {
9852 VTY_DECLVAR_CONTEXT(bgp, bgp);
9853 vty->node = BGP_EVPN_NODE;
9854 return CMD_SUCCESS;
9855 }
9856
9857 DEFUN_NOSH (bgp_segment_routing_srv6,
9858 bgp_segment_routing_srv6_cmd,
9859 "segment-routing srv6",
9860 "Segment-Routing configuration\n"
9861 "Segment-Routing SRv6 configuration\n")
9862 {
9863 VTY_DECLVAR_CONTEXT(bgp, bgp);
9864 bgp->srv6_enabled = true;
9865 vty->node = BGP_SRV6_NODE;
9866 return CMD_SUCCESS;
9867 }
9868
9869 DEFUN (no_bgp_segment_routing_srv6,
9870 no_bgp_segment_routing_srv6_cmd,
9871 "no segment-routing srv6",
9872 NO_STR
9873 "Segment-Routing configuration\n"
9874 "Segment-Routing SRv6 configuration\n")
9875 {
9876 VTY_DECLVAR_CONTEXT(bgp, bgp);
9877
9878 if (strlen(bgp->srv6_locator_name) > 0)
9879 if (bgp_srv6_locator_unset(bgp) < 0)
9880 return CMD_WARNING_CONFIG_FAILED;
9881
9882 bgp->srv6_enabled = false;
9883 return CMD_SUCCESS;
9884 }
9885
9886 DEFPY (bgp_srv6_locator,
9887 bgp_srv6_locator_cmd,
9888 "locator NAME$name",
9889 "Specify SRv6 locator\n"
9890 "Specify SRv6 locator\n")
9891 {
9892 VTY_DECLVAR_CONTEXT(bgp, bgp);
9893 int ret;
9894
9895 if (strlen(bgp->srv6_locator_name) > 0
9896 && strcmp(name, bgp->srv6_locator_name) != 0) {
9897 vty_out(vty, "srv6 locator is already configured\n");
9898 return CMD_WARNING_CONFIG_FAILED;
9899 }
9900
9901 snprintf(bgp->srv6_locator_name,
9902 sizeof(bgp->srv6_locator_name), "%s", name);
9903
9904 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9905 if (ret < 0)
9906 return CMD_WARNING_CONFIG_FAILED;
9907
9908 return CMD_SUCCESS;
9909 }
9910
9911 DEFPY (no_bgp_srv6_locator,
9912 no_bgp_srv6_locator_cmd,
9913 "no locator NAME$name",
9914 NO_STR
9915 "Specify SRv6 locator\n"
9916 "Specify SRv6 locator\n")
9917 {
9918 VTY_DECLVAR_CONTEXT(bgp, bgp);
9919
9920 /* when locator isn't configured, do nothing */
9921 if (strlen(bgp->srv6_locator_name) < 1)
9922 return CMD_SUCCESS;
9923
9924 /* name validation */
9925 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9926 vty_out(vty, "%% No srv6 locator is configured\n");
9927 return CMD_WARNING_CONFIG_FAILED;
9928 }
9929
9930 /* unset locator */
9931 if (bgp_srv6_locator_unset(bgp) < 0)
9932 return CMD_WARNING_CONFIG_FAILED;
9933
9934 return CMD_SUCCESS;
9935 }
9936
9937 DEFPY (show_bgp_srv6,
9938 show_bgp_srv6_cmd,
9939 "show bgp segment-routing srv6",
9940 SHOW_STR
9941 BGP_STR
9942 "BGP Segment Routing\n"
9943 "BGP Segment Routing SRv6\n")
9944 {
9945 struct bgp *bgp;
9946 struct listnode *node;
9947 struct srv6_locator_chunk *chunk;
9948 struct bgp_srv6_function *func;
9949
9950 bgp = bgp_get_default();
9951 if (!bgp)
9952 return CMD_SUCCESS;
9953
9954 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9955 vty_out(vty, "locator_chunks:\n");
9956 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9957 vty_out(vty, "- %pFX\n", &chunk->prefix);
9958 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9959 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9960 vty_out(vty, " func-length: %d\n",
9961 chunk->function_bits_length);
9962 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9963 }
9964
9965 vty_out(vty, "functions:\n");
9966 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9967 vty_out(vty, "- sid: %pI6\n", &func->sid);
9968 vty_out(vty, " locator: %s\n", func->locator_name);
9969 }
9970
9971 vty_out(vty, "bgps:\n");
9972 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9973 vty_out(vty, "- name: %s\n",
9974 bgp->name ? bgp->name : "default");
9975
9976 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9977 bgp->vpn_policy[AFI_IP].tovpn_sid);
9978 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9979 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9980 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
9981 }
9982
9983 return CMD_SUCCESS;
9984 }
9985
9986 DEFUN_NOSH (exit_address_family,
9987 exit_address_family_cmd,
9988 "exit-address-family",
9989 "Exit from Address Family configuration mode\n")
9990 {
9991 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9992 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9993 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9994 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9995 || vty->node == BGP_EVPN_NODE
9996 || vty->node == BGP_FLOWSPECV4_NODE
9997 || vty->node == BGP_FLOWSPECV6_NODE)
9998 vty->node = BGP_NODE;
9999 return CMD_SUCCESS;
10000 }
10001
10002 /* Recalculate bestpath and re-advertise a prefix */
10003 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10004 const char *ip_str, afi_t afi, safi_t safi,
10005 struct prefix_rd *prd)
10006 {
10007 int ret;
10008 struct prefix match;
10009 struct bgp_dest *dest;
10010 struct bgp_dest *rm;
10011 struct bgp *bgp;
10012 struct bgp_table *table;
10013 struct bgp_table *rib;
10014
10015 /* BGP structure lookup. */
10016 if (view_name) {
10017 bgp = bgp_lookup_by_name(view_name);
10018 if (bgp == NULL) {
10019 vty_out(vty, "%% Can't find BGP instance %s\n",
10020 view_name);
10021 return CMD_WARNING;
10022 }
10023 } else {
10024 bgp = bgp_get_default();
10025 if (bgp == NULL) {
10026 vty_out(vty, "%% No BGP process is configured\n");
10027 return CMD_WARNING;
10028 }
10029 }
10030
10031 /* Check IP address argument. */
10032 ret = str2prefix(ip_str, &match);
10033 if (!ret) {
10034 vty_out(vty, "%% address is malformed\n");
10035 return CMD_WARNING;
10036 }
10037
10038 match.family = afi2family(afi);
10039 rib = bgp->rib[afi][safi];
10040
10041 if (safi == SAFI_MPLS_VPN) {
10042 for (dest = bgp_table_top(rib); dest;
10043 dest = bgp_route_next(dest)) {
10044 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10045
10046 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10047 continue;
10048
10049 table = bgp_dest_get_bgp_table_info(dest);
10050 if (table == NULL)
10051 continue;
10052
10053 rm = bgp_node_match(table, &match);
10054 if (rm != NULL) {
10055 const struct prefix *rm_p =
10056 bgp_dest_get_prefix(rm);
10057
10058 if (rm_p->prefixlen == match.prefixlen) {
10059 SET_FLAG(rm->flags,
10060 BGP_NODE_USER_CLEAR);
10061 bgp_process(bgp, rm, afi, safi);
10062 }
10063 bgp_dest_unlock_node(rm);
10064 }
10065 }
10066 } else {
10067 dest = bgp_node_match(rib, &match);
10068 if (dest != NULL) {
10069 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10070
10071 if (dest_p->prefixlen == match.prefixlen) {
10072 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10073 bgp_process(bgp, dest, afi, safi);
10074 }
10075 bgp_dest_unlock_node(dest);
10076 }
10077 }
10078
10079 return CMD_SUCCESS;
10080 }
10081
10082 /* one clear bgp command to rule them all */
10083 DEFUN (clear_ip_bgp_all,
10084 clear_ip_bgp_all_cmd,
10085 "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>]",
10086 CLEAR_STR
10087 IP_STR
10088 BGP_STR
10089 BGP_INSTANCE_HELP_STR
10090 BGP_AFI_HELP_STR
10091 BGP_AF_STR
10092 BGP_SAFI_WITH_LABEL_HELP_STR
10093 BGP_AF_MODIFIER_STR
10094 "Clear all peers\n"
10095 "BGP IPv4 neighbor to clear\n"
10096 "BGP IPv6 neighbor to clear\n"
10097 "BGP neighbor on interface to clear\n"
10098 "Clear peers with the AS number\n"
10099 "Clear all external peers\n"
10100 "Clear all members of peer-group\n"
10101 "BGP peer-group name\n"
10102 BGP_SOFT_STR
10103 BGP_SOFT_IN_STR
10104 BGP_SOFT_OUT_STR
10105 BGP_SOFT_IN_STR
10106 "Push out prefix-list ORF and do inbound soft reconfig\n"
10107 BGP_SOFT_OUT_STR
10108 "Reset message statistics\n")
10109 {
10110 char *vrf = NULL;
10111
10112 afi_t afi = AFI_UNSPEC;
10113 safi_t safi = SAFI_UNSPEC;
10114 enum clear_sort clr_sort = clear_peer;
10115 enum bgp_clear_type clr_type;
10116 char *clr_arg = NULL;
10117
10118 int idx = 0;
10119
10120 /* clear [ip] bgp */
10121 if (argv_find(argv, argc, "ip", &idx))
10122 afi = AFI_IP;
10123
10124 /* [<vrf> VIEWVRFNAME] */
10125 if (argv_find(argv, argc, "vrf", &idx)) {
10126 vrf = argv[idx + 1]->arg;
10127 idx += 2;
10128 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10129 vrf = NULL;
10130 } else if (argv_find(argv, argc, "view", &idx)) {
10131 /* [<view> VIEWVRFNAME] */
10132 vrf = argv[idx + 1]->arg;
10133 idx += 2;
10134 }
10135 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10136 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10137 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10138
10139 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10140 if (argv_find(argv, argc, "*", &idx)) {
10141 clr_sort = clear_all;
10142 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10143 clr_sort = clear_peer;
10144 clr_arg = argv[idx]->arg;
10145 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10146 clr_sort = clear_peer;
10147 clr_arg = argv[idx]->arg;
10148 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10149 clr_sort = clear_group;
10150 idx++;
10151 clr_arg = argv[idx]->arg;
10152 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10153 clr_sort = clear_peer;
10154 clr_arg = argv[idx]->arg;
10155 } else if (argv_find(argv, argc, "WORD", &idx)) {
10156 clr_sort = clear_peer;
10157 clr_arg = argv[idx]->arg;
10158 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10159 clr_sort = clear_as;
10160 clr_arg = argv[idx]->arg;
10161 } else if (argv_find(argv, argc, "external", &idx)) {
10162 clr_sort = clear_external;
10163 }
10164
10165 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10166 if (argv_find(argv, argc, "soft", &idx)) {
10167 if (argv_find(argv, argc, "in", &idx)
10168 || argv_find(argv, argc, "out", &idx))
10169 clr_type = strmatch(argv[idx]->text, "in")
10170 ? BGP_CLEAR_SOFT_IN
10171 : BGP_CLEAR_SOFT_OUT;
10172 else
10173 clr_type = BGP_CLEAR_SOFT_BOTH;
10174 } else if (argv_find(argv, argc, "in", &idx)) {
10175 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10176 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10177 : BGP_CLEAR_SOFT_IN;
10178 } else if (argv_find(argv, argc, "out", &idx)) {
10179 clr_type = BGP_CLEAR_SOFT_OUT;
10180 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10181 clr_type = BGP_CLEAR_MESSAGE_STATS;
10182 } else
10183 clr_type = BGP_CLEAR_SOFT_NONE;
10184
10185 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10186 }
10187
10188 DEFUN (clear_ip_bgp_prefix,
10189 clear_ip_bgp_prefix_cmd,
10190 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10191 CLEAR_STR
10192 IP_STR
10193 BGP_STR
10194 BGP_INSTANCE_HELP_STR
10195 "Clear bestpath and re-advertise\n"
10196 "IPv4 prefix\n")
10197 {
10198 char *vrf = NULL;
10199 char *prefix = NULL;
10200
10201 int idx = 0;
10202
10203 /* [<view|vrf> VIEWVRFNAME] */
10204 if (argv_find(argv, argc, "vrf", &idx)) {
10205 vrf = argv[idx + 1]->arg;
10206 idx += 2;
10207 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10208 vrf = NULL;
10209 } else if (argv_find(argv, argc, "view", &idx)) {
10210 /* [<view> VIEWVRFNAME] */
10211 vrf = argv[idx + 1]->arg;
10212 idx += 2;
10213 }
10214
10215 prefix = argv[argc - 1]->arg;
10216
10217 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10218 }
10219
10220 DEFUN (clear_bgp_ipv6_safi_prefix,
10221 clear_bgp_ipv6_safi_prefix_cmd,
10222 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10223 CLEAR_STR
10224 IP_STR
10225 BGP_STR
10226 BGP_AF_STR
10227 BGP_SAFI_HELP_STR
10228 "Clear bestpath and re-advertise\n"
10229 "IPv6 prefix\n")
10230 {
10231 int idx_safi = 0;
10232 int idx_ipv6_prefix = 0;
10233 safi_t safi = SAFI_UNICAST;
10234 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10235 argv[idx_ipv6_prefix]->arg : NULL;
10236
10237 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10238 return bgp_clear_prefix(
10239 vty, NULL, prefix, AFI_IP6,
10240 safi, NULL);
10241 }
10242
10243 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10244 clear_bgp_instance_ipv6_safi_prefix_cmd,
10245 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10246 CLEAR_STR
10247 IP_STR
10248 BGP_STR
10249 BGP_INSTANCE_HELP_STR
10250 BGP_AF_STR
10251 BGP_SAFI_HELP_STR
10252 "Clear bestpath and re-advertise\n"
10253 "IPv6 prefix\n")
10254 {
10255 int idx_safi = 0;
10256 int idx_vrfview = 0;
10257 int idx_ipv6_prefix = 0;
10258 safi_t safi = SAFI_UNICAST;
10259 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10260 argv[idx_ipv6_prefix]->arg : NULL;
10261 char *vrfview = NULL;
10262
10263 /* [<view|vrf> VIEWVRFNAME] */
10264 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10265 vrfview = argv[idx_vrfview + 1]->arg;
10266 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10267 vrfview = NULL;
10268 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10269 /* [<view> VIEWVRFNAME] */
10270 vrfview = argv[idx_vrfview + 1]->arg;
10271 }
10272 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10273
10274 return bgp_clear_prefix(
10275 vty, vrfview, prefix,
10276 AFI_IP6, safi, NULL);
10277 }
10278
10279 DEFUN (show_bgp_views,
10280 show_bgp_views_cmd,
10281 "show [ip] bgp views",
10282 SHOW_STR
10283 IP_STR
10284 BGP_STR
10285 "Show the defined BGP views\n")
10286 {
10287 struct list *inst = bm->bgp;
10288 struct listnode *node;
10289 struct bgp *bgp;
10290
10291 vty_out(vty, "Defined BGP views:\n");
10292 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10293 /* Skip VRFs. */
10294 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10295 continue;
10296 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10297 bgp->as);
10298 }
10299
10300 return CMD_SUCCESS;
10301 }
10302
10303 static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10304 int *peers_estbd)
10305 {
10306 struct peer *peer;
10307 struct listnode *node;
10308
10309 *peers_cfgd = *peers_estbd = 0;
10310 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10311 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10312 continue;
10313 (*peers_cfgd)++;
10314 if (peer_established(peer))
10315 (*peers_estbd)++;
10316 }
10317 }
10318
10319 static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10320 const char *type)
10321 {
10322 int peers_cfg, peers_estb;
10323
10324 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10325
10326 if (json) {
10327 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10328 ? -1
10329 : (int64_t)bgp->vrf_id;
10330 json_object_string_add(json, "type", type);
10331 json_object_int_add(json, "vrfId", vrf_id_ui);
10332 json_object_string_addf(json, "routerId", "%pI4",
10333 &bgp->router_id);
10334 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10335 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10336 json_object_int_add(json, "l3vni", bgp->l3vni);
10337 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10338 json_object_string_add(
10339 json, "interface",
10340 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10341 }
10342 }
10343
10344 static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10345 json_object *json, const char *name,
10346 const char *type, bool use_vrf)
10347 {
10348 int peers_cfg, peers_estb;
10349
10350 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10351
10352 if (use_vrf) {
10353 if (json) {
10354 print_bgp_vrfs(bgp, vty, json, type);
10355 } else {
10356 vty_out(vty, "BGP instance %s VRF id %d\n",
10357 bgp->name_pretty,
10358 bgp->vrf_id == VRF_UNKNOWN ? -1
10359 : (int)bgp->vrf_id);
10360 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10361 vty_out(vty,
10362 "Num Configured Peers %d, Established %d\n",
10363 peers_cfg, peers_estb);
10364 if (bgp->l3vni) {
10365 vty_out(vty,
10366 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10367 bgp->l3vni,
10368 ifindex2ifname(bgp->l3vni_svi_ifindex,
10369 bgp->vrf_id),
10370 &bgp->rmac);
10371 }
10372 }
10373 } else {
10374 if (json) {
10375 print_bgp_vrfs(bgp, vty, json, type);
10376 } else {
10377 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10378 type,
10379 bgp->vrf_id == VRF_UNKNOWN ? -1
10380 : (int)bgp->vrf_id,
10381 &bgp->router_id, peers_cfg, peers_estb, name);
10382 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10383 bgp->l3vni, &bgp->rmac,
10384 ifindex2ifname(bgp->l3vni_svi_ifindex,
10385 bgp->vrf_id));
10386 }
10387 }
10388
10389 return CMD_SUCCESS;
10390 }
10391
10392 DEFPY (show_bgp_vrfs,
10393 show_bgp_vrfs_cmd,
10394 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
10395 SHOW_STR
10396 IP_STR
10397 BGP_STR
10398 "Show BGP VRFs\n"
10399 "Specific VRF name\n"
10400 JSON_STR)
10401 {
10402 struct list *inst = bm->bgp;
10403 struct listnode *node;
10404 struct bgp *bgp;
10405 bool uj = use_json(argc, argv);
10406 json_object *json = NULL;
10407 json_object *json_vrfs = NULL;
10408 json_object *json_vrf = NULL;
10409 int count = 0;
10410 const char *name = vrf_name;
10411 const char *type;
10412
10413 if (uj)
10414 json = json_object_new_object();
10415
10416 if (name) {
10417 if (strmatch(name, VRF_DEFAULT_NAME)) {
10418 bgp = bgp_get_default();
10419 type = "DFLT";
10420 } else {
10421 bgp = bgp_lookup_by_name(name);
10422 type = "VRF";
10423 }
10424 if (!bgp) {
10425 if (uj)
10426 vty_json(vty, json);
10427 else
10428 vty_out(vty,
10429 "%% Specified BGP instance not found\n");
10430
10431 return CMD_WARNING;
10432 }
10433 }
10434
10435 if (vrf_name) {
10436 if (uj)
10437 json_vrf = json_object_new_object();
10438
10439 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10440 true);
10441
10442 if (uj) {
10443 json_object_object_add(json, name, json_vrf);
10444 vty_json(vty, json);
10445 }
10446
10447 return CMD_SUCCESS;
10448 }
10449
10450 if (uj)
10451 json_vrfs = json_object_new_object();
10452
10453 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10454 const char *name;
10455
10456 /* Skip Views. */
10457 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10458 continue;
10459
10460 count++;
10461 if (!uj && count == 1) {
10462 vty_out(vty,
10463 "%4s %-5s %-16s %9s %10s %-37s\n",
10464 "Type", "Id", "routerId", "#PeersCfg",
10465 "#PeersEstb", "Name");
10466 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10467 "L3-VNI", "RouterMAC", "Interface");
10468 }
10469 if (uj)
10470 json_vrf = json_object_new_object();
10471
10472 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10473 name = VRF_DEFAULT_NAME;
10474 type = "DFLT";
10475 } else {
10476 name = bgp->name;
10477 type = "VRF";
10478 }
10479
10480 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10481 false);
10482
10483 if (uj)
10484 json_object_object_add(json_vrfs, name, json_vrf);
10485 }
10486
10487 if (uj) {
10488 json_object_object_add(json, "vrfs", json_vrfs);
10489 json_object_int_add(json, "totalVrfs", count);
10490 vty_json(vty, json);
10491 } else {
10492 if (count)
10493 vty_out(vty,
10494 "\nTotal number of VRFs (including default): %d\n",
10495 count);
10496 }
10497
10498 return CMD_SUCCESS;
10499 }
10500
10501 DEFUN (show_bgp_mac_hash,
10502 show_bgp_mac_hash_cmd,
10503 "show bgp mac hash",
10504 SHOW_STR
10505 BGP_STR
10506 "Mac Address\n"
10507 "Mac Address database\n")
10508 {
10509 bgp_mac_dump_table(vty);
10510
10511 return CMD_SUCCESS;
10512 }
10513
10514 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10515 {
10516 struct vty *vty = (struct vty *)args;
10517 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10518
10519 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10520 }
10521
10522 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10523 {
10524 vty_out(vty, "self nexthop database:\n");
10525 bgp_nexthop_show_address_hash(vty, bgp);
10526
10527 vty_out(vty, "Tunnel-ip database:\n");
10528 hash_iterate(bgp->tip_hash,
10529 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10530 vty);
10531 }
10532
10533 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10534 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10535 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10536 "martian next-hops\n"
10537 "martian next-hop database\n")
10538 {
10539 struct bgp *bgp = NULL;
10540 int idx = 0;
10541 char *name = NULL;
10542
10543 /* [<vrf> VIEWVRFNAME] */
10544 if (argv_find(argv, argc, "vrf", &idx)) {
10545 name = argv[idx + 1]->arg;
10546 if (name && strmatch(name, VRF_DEFAULT_NAME))
10547 name = NULL;
10548 } else if (argv_find(argv, argc, "view", &idx))
10549 /* [<view> VIEWVRFNAME] */
10550 name = argv[idx + 1]->arg;
10551 if (name)
10552 bgp = bgp_lookup_by_name(name);
10553 else
10554 bgp = bgp_get_default();
10555
10556 if (!bgp) {
10557 vty_out(vty, "%% No BGP process is configured\n");
10558 return CMD_WARNING;
10559 }
10560 bgp_show_martian_nexthops(vty, bgp);
10561
10562 return CMD_SUCCESS;
10563 }
10564
10565 DEFUN (show_bgp_memory,
10566 show_bgp_memory_cmd,
10567 "show [ip] bgp memory",
10568 SHOW_STR
10569 IP_STR
10570 BGP_STR
10571 "Global BGP memory statistics\n")
10572 {
10573 char memstrbuf[MTYPE_MEMSTR_LEN];
10574 unsigned long count;
10575
10576 /* RIB related usage stats */
10577 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10578 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10579 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10580 count * sizeof(struct bgp_dest)));
10581
10582 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10583 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10584 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10585 count * sizeof(struct bgp_path_info)));
10586 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10587 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10588 count,
10589 mtype_memstr(
10590 memstrbuf, sizeof(memstrbuf),
10591 count * sizeof(struct bgp_path_info_extra)));
10592
10593 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10594 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10595 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10596 count * sizeof(struct bgp_static)));
10597
10598 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10599 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10600 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10601 count * sizeof(struct bpacket)));
10602
10603 /* Adj-In/Out */
10604 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10605 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10606 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10607 count * sizeof(struct bgp_adj_in)));
10608 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10609 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10610 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10611 count * sizeof(struct bgp_adj_out)));
10612
10613 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10614 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10615 count,
10616 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10617 count * sizeof(struct bgp_nexthop_cache)));
10618
10619 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10620 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10621 count,
10622 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10623 count * sizeof(struct bgp_damp_info)));
10624
10625 /* Attributes */
10626 count = attr_count();
10627 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10628 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10629 count * sizeof(struct attr)));
10630
10631 if ((count = attr_unknown_count()))
10632 vty_out(vty, "%ld unknown attributes\n", count);
10633
10634 /* AS_PATH attributes */
10635 count = aspath_count();
10636 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10637 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10638 count * sizeof(struct aspath)));
10639
10640 count = mtype_stats_alloc(MTYPE_AS_SEG);
10641 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10642 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10643 count * sizeof(struct assegment)));
10644
10645 /* Other attributes */
10646 if ((count = community_count()))
10647 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10648 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10649 count * sizeof(struct community)));
10650 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10651 vty_out(vty,
10652 "%ld BGP ext-community entries, using %s of memory\n",
10653 count,
10654 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10655 count * sizeof(struct ecommunity)));
10656 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10657 vty_out(vty,
10658 "%ld BGP large-community entries, using %s of memory\n",
10659 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10660 count * sizeof(struct lcommunity)));
10661
10662 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10663 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10664 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10665 count * sizeof(struct cluster_list)));
10666
10667 /* Peer related usage */
10668 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10669 vty_out(vty, "%ld peers, using %s of memory\n", count,
10670 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10671 count * sizeof(struct peer)));
10672
10673 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10674 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10675 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10676 count * sizeof(struct peer_group)));
10677
10678 /* Other */
10679 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10680 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10681 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10682 count * sizeof(regex_t)));
10683 return CMD_SUCCESS;
10684 }
10685
10686 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10687 {
10688 json_object *bestpath = json_object_new_object();
10689
10690 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10691 json_object_string_add(bestpath, "asPath", "ignore");
10692
10693 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10694 json_object_string_add(bestpath, "asPath", "confed");
10695
10696 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10697 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10698 json_object_string_add(bestpath, "multiPathRelax",
10699 "as-set");
10700 else
10701 json_object_string_add(bestpath, "multiPathRelax",
10702 "true");
10703 } else
10704 json_object_string_add(bestpath, "multiPathRelax", "false");
10705
10706 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10707 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10708
10709 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10710 json_object_string_add(bestpath, "compareRouterId", "true");
10711 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10712 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10713 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10714 json_object_string_add(bestpath, "med", "confed");
10715 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10716 json_object_string_add(bestpath, "med",
10717 "missing-as-worst");
10718 else
10719 json_object_string_add(bestpath, "med", "true");
10720 }
10721
10722 json_object_object_add(json, "bestPath", bestpath);
10723 }
10724
10725 /* Print the error code/subcode for why the peer is down */
10726 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10727 json_object *json_peer, bool use_json)
10728 {
10729 const char *code_str;
10730 const char *subcode_str;
10731
10732 if (use_json) {
10733 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10734 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10735 char errorcodesubcode_hexstr[5];
10736 char errorcodesubcode_str[256];
10737
10738 code_str = bgp_notify_code_str(peer->notify.code);
10739 subcode_str = bgp_notify_subcode_str(
10740 peer->notify.code,
10741 peer->notify.subcode);
10742
10743 snprintf(errorcodesubcode_hexstr,
10744 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10745 peer->notify.code, peer->notify.subcode);
10746 json_object_string_add(json_peer,
10747 "lastErrorCodeSubcode",
10748 errorcodesubcode_hexstr);
10749 snprintf(errorcodesubcode_str, 255, "%s%s",
10750 code_str, subcode_str);
10751 json_object_string_add(json_peer,
10752 "lastNotificationReason",
10753 errorcodesubcode_str);
10754 json_object_boolean_add(json_peer,
10755 "lastNotificationHardReset",
10756 peer->notify.hard_reset);
10757 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10758 && peer->notify.code == BGP_NOTIFY_CEASE
10759 && (peer->notify.subcode
10760 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10761 || peer->notify.subcode
10762 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10763 && peer->notify.length) {
10764 char msgbuf[1024];
10765 const char *msg_str;
10766
10767 msg_str = bgp_notify_admin_message(
10768 msgbuf, sizeof(msgbuf),
10769 (uint8_t *)peer->notify.data,
10770 peer->notify.length);
10771 if (msg_str)
10772 json_object_string_add(
10773 json_peer,
10774 "lastShutdownDescription",
10775 msg_str);
10776 }
10777
10778 }
10779 json_object_string_add(json_peer, "lastResetDueTo",
10780 peer_down_str[(int)peer->last_reset]);
10781 json_object_int_add(json_peer, "lastResetCode",
10782 peer->last_reset);
10783 } else {
10784 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10785 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10786 code_str = bgp_notify_code_str(peer->notify.code);
10787 subcode_str =
10788 bgp_notify_subcode_str(peer->notify.code,
10789 peer->notify.subcode);
10790 vty_out(vty, " Notification %s (%s%s%s)\n",
10791 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10792 ? "sent"
10793 : "received",
10794 code_str, subcode_str,
10795 peer->notify.hard_reset
10796 ? bgp_notify_subcode_str(
10797 BGP_NOTIFY_CEASE,
10798 BGP_NOTIFY_CEASE_HARD_RESET)
10799 : "");
10800 } else {
10801 vty_out(vty, " %s\n",
10802 peer_down_str[(int)peer->last_reset]);
10803 }
10804 }
10805 }
10806
10807 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10808 safi_t safi)
10809 {
10810 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10811 }
10812
10813 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10814 struct peer *peer, json_object *json_peer,
10815 int max_neighbor_width, bool use_json)
10816 {
10817 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10818 int len;
10819
10820 if (use_json) {
10821 if (peer_dynamic_neighbor(peer))
10822 json_object_boolean_true_add(json_peer,
10823 "dynamicPeer");
10824 if (peer->hostname)
10825 json_object_string_add(json_peer, "hostname",
10826 peer->hostname);
10827
10828 if (peer->domainname)
10829 json_object_string_add(json_peer, "domainname",
10830 peer->domainname);
10831 json_object_int_add(json_peer, "connectionsEstablished",
10832 peer->established);
10833 json_object_int_add(json_peer, "connectionsDropped",
10834 peer->dropped);
10835 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10836 use_json, json_peer);
10837 if (peer_established(peer))
10838 json_object_string_add(json_peer, "lastResetDueTo",
10839 "AFI/SAFI Not Negotiated");
10840 else
10841 bgp_show_peer_reset(NULL, peer, json_peer, true);
10842 } else {
10843 dn_flag[1] = '\0';
10844 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10845 if (peer->hostname
10846 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10847 len = vty_out(vty, "%s%s(%s)", dn_flag,
10848 peer->hostname, peer->host);
10849 else
10850 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10851
10852 /* pad the neighbor column with spaces */
10853 if (len < max_neighbor_width)
10854 vty_out(vty, "%*s", max_neighbor_width - len,
10855 " ");
10856 vty_out(vty, "%7d %7d %9s", peer->established,
10857 peer->dropped,
10858 peer_uptime(peer->uptime, timebuf,
10859 BGP_UPTIME_LEN, 0, NULL));
10860 if (peer_established(peer))
10861 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10862 else
10863 bgp_show_peer_reset(vty, peer, NULL,
10864 false);
10865 }
10866 }
10867
10868 /* Strip peer's description to the given size. */
10869 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10870 {
10871 static char stripped[BUFSIZ];
10872 uint32_t i = 0;
10873 uint32_t last_space = 0;
10874
10875 while (i < size) {
10876 if (*(desc + i) == 0) {
10877 stripped[i] = '\0';
10878 return stripped;
10879 }
10880 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10881 last_space = i;
10882 stripped[i] = *(desc + i);
10883 i++;
10884 }
10885
10886 if (last_space > size)
10887 stripped[size + 1] = '\0';
10888 else
10889 stripped[last_space] = '\0';
10890
10891 return stripped;
10892 }
10893
10894 /* Determine whether var peer should be filtered out of the summary. */
10895 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10896 struct peer *fpeer, int as_type,
10897 as_t as)
10898 {
10899
10900 /* filter neighbor XXXX */
10901 if (fpeer && fpeer != peer)
10902 return true;
10903
10904 /* filter remote-as (internal|external) */
10905 if (as_type != AS_UNSPECIFIED) {
10906 if (peer->as_type == AS_SPECIFIED) {
10907 if (as_type == AS_INTERNAL) {
10908 if (peer->as != peer->local_as)
10909 return true;
10910 } else if (peer->as == peer->local_as)
10911 return true;
10912 } else if (as_type != peer->as_type)
10913 return true;
10914 } else if (as && as != peer->as) /* filter remote-as XXX */
10915 return true;
10916
10917 return false;
10918 }
10919
10920 /* Show BGP peer's summary information.
10921 *
10922 * Peer's description is stripped according to if `wide` option is given
10923 * or not.
10924 *
10925 * When adding new columns to `show bgp summary` output, please make
10926 * sure `Desc` is the lastest column to show because it can contain
10927 * whitespaces and the whole output will be tricky.
10928 */
10929 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10930 struct peer *fpeer, int as_type, as_t as,
10931 uint16_t show_flags)
10932 {
10933 struct peer *peer;
10934 struct listnode *node, *nnode;
10935 unsigned int count = 0, dn_count = 0;
10936 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10937 char neighbor_buf[VTY_BUFSIZ];
10938 int neighbor_col_default_width = 16;
10939 int len, failed_count = 0;
10940 unsigned int filtered_count = 0;
10941 int max_neighbor_width = 0;
10942 int pfx_rcd_safi;
10943 json_object *json = NULL;
10944 json_object *json_peer = NULL;
10945 json_object *json_peers = NULL;
10946 struct peer_af *paf;
10947 struct bgp_filter *filter;
10948 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10949 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10950 bool show_established =
10951 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10952 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10953 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10954
10955 /* labeled-unicast routes are installed in the unicast table so in order
10956 * to
10957 * display the correct PfxRcd value we must look at SAFI_UNICAST
10958 */
10959
10960 if (safi == SAFI_LABELED_UNICAST)
10961 pfx_rcd_safi = SAFI_UNICAST;
10962 else
10963 pfx_rcd_safi = safi;
10964
10965 if (use_json) {
10966 json = json_object_new_object();
10967 json_peers = json_object_new_object();
10968 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10969 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10970 as_type, as)) {
10971 filtered_count++;
10972 count++;
10973 continue;
10974 }
10975
10976 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10977 continue;
10978
10979 if (peer->afc[afi][safi]) {
10980 /* See if we have at least a single failed peer */
10981 if (bgp_has_peer_failed(peer, afi, safi))
10982 failed_count++;
10983 count++;
10984 }
10985 if (peer_dynamic_neighbor(peer))
10986 dn_count++;
10987 }
10988
10989 } else {
10990 /* Loop over all neighbors that will be displayed to determine
10991 * how many
10992 * characters are needed for the Neighbor column
10993 */
10994 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10995 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10996 as_type, as)) {
10997 filtered_count++;
10998 count++;
10999 continue;
11000 }
11001
11002 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11003 continue;
11004
11005 if (peer->afc[afi][safi]) {
11006 memset(dn_flag, '\0', sizeof(dn_flag));
11007 if (peer_dynamic_neighbor(peer))
11008 dn_flag[0] = '*';
11009
11010 if (peer->hostname
11011 && CHECK_FLAG(bgp->flags,
11012 BGP_FLAG_SHOW_HOSTNAME))
11013 snprintf(neighbor_buf,
11014 sizeof(neighbor_buf),
11015 "%s%s(%s) ", dn_flag,
11016 peer->hostname, peer->host);
11017 else
11018 snprintf(neighbor_buf,
11019 sizeof(neighbor_buf), "%s%s ",
11020 dn_flag, peer->host);
11021
11022 len = strlen(neighbor_buf);
11023
11024 if (len > max_neighbor_width)
11025 max_neighbor_width = len;
11026
11027 /* See if we have at least a single failed peer */
11028 if (bgp_has_peer_failed(peer, afi, safi))
11029 failed_count++;
11030 count++;
11031 }
11032 }
11033
11034 /* Originally we displayed the Neighbor column as 16
11035 * characters wide so make that the default
11036 */
11037 if (max_neighbor_width < neighbor_col_default_width)
11038 max_neighbor_width = neighbor_col_default_width;
11039 }
11040
11041 if (show_failed && !failed_count) {
11042 if (use_json) {
11043 json_object_int_add(json, "failedPeersCount", 0);
11044 json_object_int_add(json, "dynamicPeers", dn_count);
11045 json_object_int_add(json, "totalPeers", count);
11046
11047 vty_json(vty, json);
11048 } else {
11049 vty_out(vty, "%% No failed BGP neighbors found\n");
11050 }
11051 return CMD_SUCCESS;
11052 }
11053
11054 count = 0; /* Reset the value as its used again */
11055 filtered_count = 0;
11056 dn_count = 0;
11057 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11058 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11059 continue;
11060
11061 if (!peer->afc[afi][safi])
11062 continue;
11063
11064 if (!count) {
11065 unsigned long ents;
11066 char memstrbuf[MTYPE_MEMSTR_LEN];
11067 int64_t vrf_id_ui;
11068
11069 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11070 ? -1
11071 : (int64_t)bgp->vrf_id;
11072
11073 /* Usage summary and header */
11074 if (use_json) {
11075 json_object_string_addf(json, "routerId",
11076 "%pI4",
11077 &bgp->router_id);
11078 json_object_int_add(json, "as", bgp->as);
11079 json_object_int_add(json, "vrfId", vrf_id_ui);
11080 json_object_string_add(
11081 json, "vrfName",
11082 (bgp->inst_type
11083 == BGP_INSTANCE_TYPE_DEFAULT)
11084 ? VRF_DEFAULT_NAME
11085 : bgp->name);
11086 } else {
11087 vty_out(vty,
11088 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11089 &bgp->router_id, bgp->as,
11090 bgp->vrf_id == VRF_UNKNOWN
11091 ? -1
11092 : (int)bgp->vrf_id);
11093 vty_out(vty, "\n");
11094 }
11095
11096 if (bgp_update_delay_configured(bgp)) {
11097 if (use_json) {
11098 json_object_int_add(
11099 json, "updateDelayLimit",
11100 bgp->v_update_delay);
11101
11102 if (bgp->v_update_delay
11103 != bgp->v_establish_wait)
11104 json_object_int_add(
11105 json,
11106 "updateDelayEstablishWait",
11107 bgp->v_establish_wait);
11108
11109 if (bgp_update_delay_active(bgp)) {
11110 json_object_string_add(
11111 json,
11112 "updateDelayFirstNeighbor",
11113 bgp->update_delay_begin_time);
11114 json_object_boolean_true_add(
11115 json,
11116 "updateDelayInProgress");
11117 } else {
11118 if (bgp->update_delay_over) {
11119 json_object_string_add(
11120 json,
11121 "updateDelayFirstNeighbor",
11122 bgp->update_delay_begin_time);
11123 json_object_string_add(
11124 json,
11125 "updateDelayBestpathResumed",
11126 bgp->update_delay_end_time);
11127 json_object_string_add(
11128 json,
11129 "updateDelayZebraUpdateResume",
11130 bgp->update_delay_zebra_resume_time);
11131 json_object_string_add(
11132 json,
11133 "updateDelayPeerUpdateResume",
11134 bgp->update_delay_peers_resume_time);
11135 }
11136 }
11137 } else {
11138 vty_out(vty,
11139 "Read-only mode update-delay limit: %d seconds\n",
11140 bgp->v_update_delay);
11141 if (bgp->v_update_delay
11142 != bgp->v_establish_wait)
11143 vty_out(vty,
11144 " Establish wait: %d seconds\n",
11145 bgp->v_establish_wait);
11146
11147 if (bgp_update_delay_active(bgp)) {
11148 vty_out(vty,
11149 " First neighbor established: %s\n",
11150 bgp->update_delay_begin_time);
11151 vty_out(vty,
11152 " Delay in progress\n");
11153 } else {
11154 if (bgp->update_delay_over) {
11155 vty_out(vty,
11156 " First neighbor established: %s\n",
11157 bgp->update_delay_begin_time);
11158 vty_out(vty,
11159 " Best-paths resumed: %s\n",
11160 bgp->update_delay_end_time);
11161 vty_out(vty,
11162 " zebra update resumed: %s\n",
11163 bgp->update_delay_zebra_resume_time);
11164 vty_out(vty,
11165 " peers update resumed: %s\n",
11166 bgp->update_delay_peers_resume_time);
11167 }
11168 }
11169 }
11170 }
11171
11172 if (use_json) {
11173 if (bgp_maxmed_onstartup_configured(bgp)
11174 && bgp->maxmed_active)
11175 json_object_boolean_true_add(
11176 json, "maxMedOnStartup");
11177 if (bgp->v_maxmed_admin)
11178 json_object_boolean_true_add(
11179 json, "maxMedAdministrative");
11180
11181 json_object_int_add(
11182 json, "tableVersion",
11183 bgp_table_version(bgp->rib[afi][safi]));
11184
11185 ents = bgp_table_count(bgp->rib[afi][safi]);
11186 json_object_int_add(json, "ribCount", ents);
11187 json_object_int_add(
11188 json, "ribMemory",
11189 ents * sizeof(struct bgp_dest));
11190
11191 ents = bgp->af_peer_count[afi][safi];
11192 json_object_int_add(json, "peerCount", ents);
11193 json_object_int_add(json, "peerMemory",
11194 ents * sizeof(struct peer));
11195
11196 if ((ents = listcount(bgp->group))) {
11197 json_object_int_add(
11198 json, "peerGroupCount", ents);
11199 json_object_int_add(
11200 json, "peerGroupMemory",
11201 ents * sizeof(struct
11202 peer_group));
11203 }
11204
11205 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11206 BGP_CONFIG_DAMPENING))
11207 json_object_boolean_true_add(
11208 json, "dampeningEnabled");
11209 } else {
11210 if (!show_terse) {
11211 if (bgp_maxmed_onstartup_configured(bgp)
11212 && bgp->maxmed_active)
11213 vty_out(vty,
11214 "Max-med on-startup active\n");
11215 if (bgp->v_maxmed_admin)
11216 vty_out(vty,
11217 "Max-med administrative active\n");
11218
11219 vty_out(vty,
11220 "BGP table version %" PRIu64
11221 "\n",
11222 bgp_table_version(
11223 bgp->rib[afi][safi]));
11224
11225 ents = bgp_table_count(
11226 bgp->rib[afi][safi]);
11227 vty_out(vty,
11228 "RIB entries %ld, using %s of memory\n",
11229 ents,
11230 mtype_memstr(
11231 memstrbuf,
11232 sizeof(memstrbuf),
11233 ents
11234 * sizeof(
11235 struct
11236 bgp_dest)));
11237
11238 /* Peer related usage */
11239 ents = bgp->af_peer_count[afi][safi];
11240 vty_out(vty,
11241 "Peers %ld, using %s of memory\n",
11242 ents,
11243 mtype_memstr(
11244 memstrbuf,
11245 sizeof(memstrbuf),
11246 ents
11247 * sizeof(
11248 struct
11249 peer)));
11250
11251 if ((ents = listcount(bgp->group)))
11252 vty_out(vty,
11253 "Peer groups %ld, using %s of memory\n",
11254 ents,
11255 mtype_memstr(
11256 memstrbuf,
11257 sizeof(memstrbuf),
11258 ents
11259 * sizeof(
11260 struct
11261 peer_group)));
11262
11263 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11264 BGP_CONFIG_DAMPENING))
11265 vty_out(vty,
11266 "Dampening enabled.\n");
11267 }
11268 if (show_failed) {
11269 vty_out(vty, "\n");
11270
11271 /* Subtract 8 here because 'Neighbor' is
11272 * 8 characters */
11273 vty_out(vty, "Neighbor");
11274 vty_out(vty, "%*s",
11275 max_neighbor_width - 8, " ");
11276 vty_out(vty,
11277 BGP_SHOW_SUMMARY_HEADER_FAILED);
11278 }
11279 }
11280 }
11281
11282 paf = peer_af_find(peer, afi, safi);
11283 filter = &peer->filter[afi][safi];
11284
11285 count++;
11286 /* Works for both failed & successful cases */
11287 if (peer_dynamic_neighbor(peer))
11288 dn_count++;
11289
11290 if (use_json) {
11291 json_peer = NULL;
11292 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11293 as_type, as)) {
11294 filtered_count++;
11295 continue;
11296 }
11297 if (show_failed &&
11298 bgp_has_peer_failed(peer, afi, safi)) {
11299 json_peer = json_object_new_object();
11300 bgp_show_failed_summary(vty, bgp, peer,
11301 json_peer, 0, use_json);
11302 } else if (!show_failed) {
11303 if (show_established
11304 && bgp_has_peer_failed(peer, afi, safi)) {
11305 filtered_count++;
11306 continue;
11307 }
11308
11309 json_peer = json_object_new_object();
11310 if (peer_dynamic_neighbor(peer)) {
11311 json_object_boolean_true_add(json_peer,
11312 "dynamicPeer");
11313 }
11314
11315 if (peer->hostname)
11316 json_object_string_add(json_peer, "hostname",
11317 peer->hostname);
11318
11319 if (peer->domainname)
11320 json_object_string_add(json_peer, "domainname",
11321 peer->domainname);
11322
11323 json_object_int_add(json_peer, "remoteAs", peer->as);
11324 json_object_int_add(
11325 json_peer, "localAs",
11326 peer->change_local_as
11327 ? peer->change_local_as
11328 : peer->local_as);
11329 json_object_int_add(json_peer, "version", 4);
11330 json_object_int_add(json_peer, "msgRcvd",
11331 PEER_TOTAL_RX(peer));
11332 json_object_int_add(json_peer, "msgSent",
11333 PEER_TOTAL_TX(peer));
11334
11335 atomic_size_t outq_count, inq_count;
11336 outq_count = atomic_load_explicit(
11337 &peer->obuf->count,
11338 memory_order_relaxed);
11339 inq_count = atomic_load_explicit(
11340 &peer->ibuf->count,
11341 memory_order_relaxed);
11342
11343 json_object_int_add(json_peer, "tableVersion",
11344 peer->version[afi][safi]);
11345 json_object_int_add(json_peer, "outq",
11346 outq_count);
11347 json_object_int_add(json_peer, "inq",
11348 inq_count);
11349 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11350 use_json, json_peer);
11351
11352 json_object_int_add(json_peer, "pfxRcd",
11353 peer->pcount[afi][pfx_rcd_safi]);
11354
11355 if (paf && PAF_SUBGRP(paf))
11356 json_object_int_add(
11357 json_peer, "pfxSnt",
11358 (PAF_SUBGRP(paf))->scount);
11359 else
11360 json_object_int_add(json_peer, "pfxSnt",
11361 0);
11362
11363 /* BGP FSM state */
11364 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11365 || CHECK_FLAG(peer->bgp->flags,
11366 BGP_FLAG_SHUTDOWN))
11367 json_object_string_add(json_peer,
11368 "state",
11369 "Idle (Admin)");
11370 else if (peer->afc_recv[afi][safi])
11371 json_object_string_add(
11372 json_peer, "state",
11373 lookup_msg(bgp_status_msg,
11374 peer->status, NULL));
11375 else if (CHECK_FLAG(
11376 peer->sflags,
11377 PEER_STATUS_PREFIX_OVERFLOW))
11378 json_object_string_add(json_peer,
11379 "state",
11380 "Idle (PfxCt)");
11381 else
11382 json_object_string_add(
11383 json_peer, "state",
11384 lookup_msg(bgp_status_msg,
11385 peer->status, NULL));
11386
11387 /* BGP peer state */
11388 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11389 || CHECK_FLAG(peer->bgp->flags,
11390 BGP_FLAG_SHUTDOWN))
11391 json_object_string_add(json_peer,
11392 "peerState",
11393 "Admin");
11394 else if (CHECK_FLAG(
11395 peer->sflags,
11396 PEER_STATUS_PREFIX_OVERFLOW))
11397 json_object_string_add(json_peer,
11398 "peerState",
11399 "PfxCt");
11400 else if (CHECK_FLAG(peer->flags,
11401 PEER_FLAG_PASSIVE))
11402 json_object_string_add(json_peer,
11403 "peerState",
11404 "Passive");
11405 else if (CHECK_FLAG(peer->sflags,
11406 PEER_STATUS_NSF_WAIT))
11407 json_object_string_add(json_peer,
11408 "peerState",
11409 "NSF passive");
11410 else if (CHECK_FLAG(
11411 peer->bgp->flags,
11412 BGP_FLAG_EBGP_REQUIRES_POLICY)
11413 && (!bgp_inbound_policy_exists(peer,
11414 filter)
11415 || !bgp_outbound_policy_exists(
11416 peer, filter)))
11417 json_object_string_add(json_peer,
11418 "peerState",
11419 "Policy");
11420 else
11421 json_object_string_add(
11422 json_peer, "peerState", "OK");
11423
11424 json_object_int_add(json_peer, "connectionsEstablished",
11425 peer->established);
11426 json_object_int_add(json_peer, "connectionsDropped",
11427 peer->dropped);
11428 if (peer->desc)
11429 json_object_string_add(
11430 json_peer, "desc", peer->desc);
11431 }
11432 /* Avoid creating empty peer dicts in JSON */
11433 if (json_peer == NULL)
11434 continue;
11435
11436 if (peer->conf_if)
11437 json_object_string_add(json_peer, "idType",
11438 "interface");
11439 else if (peer->su.sa.sa_family == AF_INET)
11440 json_object_string_add(json_peer, "idType",
11441 "ipv4");
11442 else if (peer->su.sa.sa_family == AF_INET6)
11443 json_object_string_add(json_peer, "idType",
11444 "ipv6");
11445 json_object_object_add(json_peers, peer->host,
11446 json_peer);
11447 } else {
11448 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11449 as_type, as)) {
11450 filtered_count++;
11451 continue;
11452 }
11453 if (show_failed &&
11454 bgp_has_peer_failed(peer, afi, safi)) {
11455 bgp_show_failed_summary(vty, bgp, peer, NULL,
11456 max_neighbor_width,
11457 use_json);
11458 } else if (!show_failed) {
11459 if (show_established
11460 && bgp_has_peer_failed(peer, afi, safi)) {
11461 filtered_count++;
11462 continue;
11463 }
11464
11465 if ((count - filtered_count) == 1) {
11466 /* display headline before the first
11467 * neighbor line */
11468 vty_out(vty, "\n");
11469
11470 /* Subtract 8 here because 'Neighbor' is
11471 * 8 characters */
11472 vty_out(vty, "Neighbor");
11473 vty_out(vty, "%*s",
11474 max_neighbor_width - 8, " ");
11475 vty_out(vty,
11476 show_wide
11477 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11478 : BGP_SHOW_SUMMARY_HEADER_ALL);
11479 }
11480
11481 memset(dn_flag, '\0', sizeof(dn_flag));
11482 if (peer_dynamic_neighbor(peer)) {
11483 dn_flag[0] = '*';
11484 }
11485
11486 if (peer->hostname
11487 && CHECK_FLAG(bgp->flags,
11488 BGP_FLAG_SHOW_HOSTNAME))
11489 len = vty_out(vty, "%s%s(%s)", dn_flag,
11490 peer->hostname,
11491 peer->host);
11492 else
11493 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11494
11495 /* pad the neighbor column with spaces */
11496 if (len < max_neighbor_width)
11497 vty_out(vty, "%*s", max_neighbor_width - len,
11498 " ");
11499
11500 atomic_size_t outq_count, inq_count;
11501 outq_count = atomic_load_explicit(
11502 &peer->obuf->count,
11503 memory_order_relaxed);
11504 inq_count = atomic_load_explicit(
11505 &peer->ibuf->count,
11506 memory_order_relaxed);
11507
11508 if (show_wide)
11509 vty_out(vty,
11510 "4 %10u %10u %9u %9u %8" PRIu64
11511 " %4zu %4zu %8s",
11512 peer->as,
11513 peer->change_local_as
11514 ? peer->change_local_as
11515 : peer->local_as,
11516 PEER_TOTAL_RX(peer),
11517 PEER_TOTAL_TX(peer),
11518 peer->version[afi][safi],
11519 inq_count, outq_count,
11520 peer_uptime(peer->uptime,
11521 timebuf,
11522 BGP_UPTIME_LEN, 0,
11523 NULL));
11524 else
11525 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11526 " %4zu %4zu %8s",
11527 peer->as, PEER_TOTAL_RX(peer),
11528 PEER_TOTAL_TX(peer),
11529 peer->version[afi][safi],
11530 inq_count, outq_count,
11531 peer_uptime(peer->uptime,
11532 timebuf,
11533 BGP_UPTIME_LEN, 0,
11534 NULL));
11535
11536 if (peer_established(peer)) {
11537 if (peer->afc_recv[afi][safi]) {
11538 if (CHECK_FLAG(
11539 bgp->flags,
11540 BGP_FLAG_EBGP_REQUIRES_POLICY)
11541 && !bgp_inbound_policy_exists(
11542 peer, filter))
11543 vty_out(vty, " %12s",
11544 "(Policy)");
11545 else
11546 vty_out(vty,
11547 " %12u",
11548 peer->pcount
11549 [afi]
11550 [pfx_rcd_safi]);
11551 } else {
11552 vty_out(vty, " NoNeg");
11553 }
11554
11555 if (paf && PAF_SUBGRP(paf)) {
11556 if (CHECK_FLAG(
11557 bgp->flags,
11558 BGP_FLAG_EBGP_REQUIRES_POLICY)
11559 && !bgp_outbound_policy_exists(
11560 peer, filter))
11561 vty_out(vty, " %8s",
11562 "(Policy)");
11563 else
11564 vty_out(vty,
11565 " %8u",
11566 (PAF_SUBGRP(
11567 paf))
11568 ->scount);
11569 } else {
11570 vty_out(vty, " NoNeg");
11571 }
11572 } else {
11573 if (CHECK_FLAG(peer->flags,
11574 PEER_FLAG_SHUTDOWN)
11575 || CHECK_FLAG(peer->bgp->flags,
11576 BGP_FLAG_SHUTDOWN))
11577 vty_out(vty, " Idle (Admin)");
11578 else if (CHECK_FLAG(
11579 peer->sflags,
11580 PEER_STATUS_PREFIX_OVERFLOW))
11581 vty_out(vty, " Idle (PfxCt)");
11582 else
11583 vty_out(vty, " %12s",
11584 lookup_msg(bgp_status_msg,
11585 peer->status, NULL));
11586
11587 vty_out(vty, " %8u", 0);
11588 }
11589 /* Make sure `Desc` column is the lastest in
11590 * the output.
11591 */
11592 if (peer->desc)
11593 vty_out(vty, " %s",
11594 bgp_peer_description_stripped(
11595 peer->desc,
11596 show_wide ? 64 : 20));
11597 else
11598 vty_out(vty, " N/A");
11599 vty_out(vty, "\n");
11600 }
11601
11602 }
11603 }
11604
11605 if (use_json) {
11606 json_object_object_add(json, "peers", json_peers);
11607 json_object_int_add(json, "failedPeers", failed_count);
11608 json_object_int_add(json, "displayedPeers",
11609 count - filtered_count);
11610 json_object_int_add(json, "totalPeers", count);
11611 json_object_int_add(json, "dynamicPeers", dn_count);
11612
11613 if (!show_failed)
11614 bgp_show_bestpath_json(bgp, json);
11615
11616 vty_json(vty, json);
11617 } else {
11618 if (count) {
11619 if (filtered_count == count)
11620 vty_out(vty, "\n%% No matching neighbor\n");
11621 else {
11622 if (show_failed)
11623 vty_out(vty, "\nDisplayed neighbors %d",
11624 failed_count);
11625 else if (as_type != AS_UNSPECIFIED || as
11626 || fpeer || show_established)
11627 vty_out(vty, "\nDisplayed neighbors %d",
11628 count - filtered_count);
11629
11630 vty_out(vty, "\nTotal number of neighbors %d\n",
11631 count);
11632 }
11633 } else {
11634 vty_out(vty, "No %s neighbor is configured\n",
11635 get_afi_safi_str(afi, safi, false));
11636 }
11637
11638 if (dn_count) {
11639 vty_out(vty, "* - dynamic neighbor\n");
11640 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11641 dn_count, bgp->dynamic_neighbors_limit);
11642 }
11643 }
11644
11645 return CMD_SUCCESS;
11646 }
11647
11648 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11649 int safi, struct peer *fpeer, int as_type,
11650 as_t as, uint16_t show_flags)
11651 {
11652 int is_first = 1;
11653 int afi_wildcard = (afi == AFI_MAX);
11654 int safi_wildcard = (safi == SAFI_MAX);
11655 int is_wildcard = (afi_wildcard || safi_wildcard);
11656 bool nbr_output = false;
11657 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11658
11659 if (use_json && is_wildcard)
11660 vty_out(vty, "{\n");
11661 if (afi_wildcard)
11662 afi = 1; /* AFI_IP */
11663 while (afi < AFI_MAX) {
11664 if (safi_wildcard)
11665 safi = 1; /* SAFI_UNICAST */
11666 while (safi < SAFI_MAX) {
11667 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11668 nbr_output = true;
11669
11670 if (is_wildcard) {
11671 /*
11672 * So limit output to those afi/safi
11673 * pairs that
11674 * actualy have something interesting in
11675 * them
11676 */
11677 if (use_json) {
11678 if (!is_first)
11679 vty_out(vty, ",\n");
11680 else
11681 is_first = 0;
11682
11683 vty_out(vty, "\"%s\":",
11684 get_afi_safi_str(afi,
11685 safi,
11686 true));
11687 } else {
11688 vty_out(vty,
11689 "\n%s Summary (%s):\n",
11690 get_afi_safi_str(afi,
11691 safi,
11692 false),
11693 bgp->name_pretty);
11694 }
11695 }
11696 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11697 as_type, as, show_flags);
11698 }
11699 safi++;
11700 if (!safi_wildcard)
11701 safi = SAFI_MAX;
11702 }
11703 afi++;
11704 if (!afi_wildcard)
11705 afi = AFI_MAX;
11706 }
11707
11708 if (use_json && is_wildcard)
11709 vty_out(vty, "}\n");
11710 else if (!nbr_output) {
11711 if (use_json)
11712 vty_out(vty, "{}\n");
11713 else
11714 vty_out(vty, "%% No BGP neighbors found in %s\n",
11715 bgp->name_pretty);
11716 }
11717 }
11718
11719 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11720 safi_t safi,
11721 const char *neighbor,
11722 int as_type, as_t as,
11723 uint16_t show_flags)
11724 {
11725 struct listnode *node, *nnode;
11726 struct bgp *bgp;
11727 struct peer *fpeer = NULL;
11728 int is_first = 1;
11729 bool nbr_output = false;
11730 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11731
11732 if (use_json)
11733 vty_out(vty, "{\n");
11734
11735 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11736 nbr_output = true;
11737 if (use_json) {
11738 if (!is_first)
11739 vty_out(vty, ",\n");
11740 else
11741 is_first = 0;
11742
11743 vty_out(vty, "\"%s\":",
11744 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11745 ? VRF_DEFAULT_NAME
11746 : bgp->name);
11747 }
11748 if (neighbor) {
11749 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11750 use_json);
11751 if (!fpeer)
11752 continue;
11753 }
11754 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11755 as, show_flags);
11756 }
11757
11758 if (use_json)
11759 vty_out(vty, "}\n");
11760 else if (!nbr_output)
11761 vty_out(vty, "%% BGP instance not found\n");
11762 }
11763
11764 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11765 safi_t safi, const char *neighbor, int as_type,
11766 as_t as, uint16_t show_flags)
11767 {
11768 struct bgp *bgp;
11769 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11770 struct peer *fpeer = NULL;
11771
11772 if (name) {
11773 if (strmatch(name, "all")) {
11774 bgp_show_all_instances_summary_vty(vty, afi, safi,
11775 neighbor, as_type,
11776 as, show_flags);
11777 return CMD_SUCCESS;
11778 } else {
11779 bgp = bgp_lookup_by_name(name);
11780
11781 if (!bgp) {
11782 if (use_json)
11783 vty_out(vty, "{}\n");
11784 else
11785 vty_out(vty,
11786 "%% BGP instance not found\n");
11787 return CMD_WARNING;
11788 }
11789
11790 if (neighbor) {
11791 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11792 use_json);
11793 if (!fpeer)
11794 return CMD_WARNING;
11795 }
11796 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11797 as_type, as, show_flags);
11798 return CMD_SUCCESS;
11799 }
11800 }
11801
11802 bgp = bgp_get_default();
11803
11804 if (bgp) {
11805 if (neighbor) {
11806 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11807 use_json);
11808 if (!fpeer)
11809 return CMD_WARNING;
11810 }
11811 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11812 as, show_flags);
11813 } else {
11814 if (use_json)
11815 vty_out(vty, "{}\n");
11816 else
11817 vty_out(vty, "%% BGP instance not found\n");
11818 return CMD_WARNING;
11819 }
11820
11821 return CMD_SUCCESS;
11822 }
11823
11824 /* `show [ip] bgp summary' commands. */
11825 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11826 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11827 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11828 "]] [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]",
11829 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11830 BGP_SAFI_WITH_LABEL_HELP_STR
11831 "Display the entries for all address families\n"
11832 "Summary of BGP neighbor status\n"
11833 "Show only sessions in Established state\n"
11834 "Show only sessions not in Established state\n"
11835 "Show only the specified neighbor session\n"
11836 "Neighbor to display information about\n"
11837 "Neighbor to display information about\n"
11838 "Neighbor on BGP configured interface\n"
11839 "Show only the specified remote AS sessions\n"
11840 "AS number\n"
11841 "Internal (iBGP) AS sessions\n"
11842 "External (eBGP) AS sessions\n"
11843 "Shorten the information on BGP instances\n"
11844 "Increase table width for longer output\n" JSON_STR)
11845 {
11846 char *vrf = NULL;
11847 afi_t afi = AFI_MAX;
11848 safi_t safi = SAFI_MAX;
11849 as_t as = 0; /* 0 means AS filter not set */
11850 int as_type = AS_UNSPECIFIED;
11851 uint16_t show_flags = 0;
11852
11853 int idx = 0;
11854
11855 /* show [ip] bgp */
11856 if (!all && argv_find(argv, argc, "ip", &idx))
11857 afi = AFI_IP;
11858 /* [<vrf> VIEWVRFNAME] */
11859 if (argv_find(argv, argc, "vrf", &idx)) {
11860 vrf = argv[idx + 1]->arg;
11861 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11862 vrf = NULL;
11863 } else if (argv_find(argv, argc, "view", &idx))
11864 /* [<view> VIEWVRFNAME] */
11865 vrf = argv[idx + 1]->arg;
11866 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11867 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11868 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11869 }
11870
11871 if (argv_find(argv, argc, "failed", &idx))
11872 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11873
11874 if (argv_find(argv, argc, "established", &idx))
11875 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11876
11877 if (argv_find(argv, argc, "remote-as", &idx)) {
11878 if (argv[idx + 1]->arg[0] == 'i')
11879 as_type = AS_INTERNAL;
11880 else if (argv[idx + 1]->arg[0] == 'e')
11881 as_type = AS_EXTERNAL;
11882 else
11883 as = (as_t)atoi(argv[idx + 1]->arg);
11884 }
11885
11886 if (argv_find(argv, argc, "terse", &idx))
11887 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11888
11889 if (argv_find(argv, argc, "wide", &idx))
11890 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11891
11892 if (argv_find(argv, argc, "json", &idx))
11893 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11894
11895 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11896 show_flags);
11897 }
11898
11899 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11900 {
11901 if (for_json)
11902 return get_afi_safi_json_str(afi, safi);
11903 else
11904 return get_afi_safi_vty_str(afi, safi);
11905 }
11906
11907
11908 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11909 afi_t afi, safi_t safi,
11910 uint16_t adv_smcap, uint16_t adv_rmcap,
11911 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11912 bool use_json, json_object *json_pref)
11913 {
11914 /* Send-Mode */
11915 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11916 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11917 if (use_json) {
11918 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11919 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11920 json_object_string_add(json_pref, "sendMode",
11921 "advertisedAndReceived");
11922 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11923 json_object_string_add(json_pref, "sendMode",
11924 "advertised");
11925 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11926 json_object_string_add(json_pref, "sendMode",
11927 "received");
11928 } else {
11929 vty_out(vty, " Send-mode: ");
11930 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11931 vty_out(vty, "advertised");
11932 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11933 vty_out(vty, "%sreceived",
11934 CHECK_FLAG(p->af_cap[afi][safi],
11935 adv_smcap)
11936 ? ", "
11937 : "");
11938 vty_out(vty, "\n");
11939 }
11940 }
11941
11942 /* Receive-Mode */
11943 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11944 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11945 if (use_json) {
11946 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11947 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11948 json_object_string_add(json_pref, "recvMode",
11949 "advertisedAndReceived");
11950 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11951 json_object_string_add(json_pref, "recvMode",
11952 "advertised");
11953 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11954 json_object_string_add(json_pref, "recvMode",
11955 "received");
11956 } else {
11957 vty_out(vty, " Receive-mode: ");
11958 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11959 vty_out(vty, "advertised");
11960 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11961 vty_out(vty, "%sreceived",
11962 CHECK_FLAG(p->af_cap[afi][safi],
11963 adv_rmcap)
11964 ? ", "
11965 : "");
11966 vty_out(vty, "\n");
11967 }
11968 }
11969 }
11970
11971 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11972 struct peer *p,
11973 json_object *json)
11974 {
11975 bool rbit = false;
11976 bool nbit = false;
11977
11978 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11979 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11980 && (peer_established(p))) {
11981 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11982 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11983 }
11984
11985 if (json) {
11986 json_object_boolean_add(json, "rBit", rbit);
11987 json_object_boolean_add(json, "nBit", nbit);
11988 } else {
11989 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11990 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11991 }
11992 }
11993
11994 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11995 struct peer *peer,
11996 json_object *json)
11997 {
11998 const char *mode = "NotApplicable";
11999
12000 if (!json)
12001 vty_out(vty, "\n Remote GR Mode: ");
12002
12003 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12004 && (peer_established(peer))) {
12005
12006 if ((peer->nsf_af_count == 0)
12007 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12008
12009 mode = "Disable";
12010
12011 } else if (peer->nsf_af_count == 0
12012 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12013
12014 mode = "Helper";
12015
12016 } else if (peer->nsf_af_count != 0
12017 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12018
12019 mode = "Restart";
12020 }
12021 }
12022
12023 if (json)
12024 json_object_string_add(json, "remoteGrMode", mode);
12025 else
12026 vty_out(vty, "%s\n", mode);
12027 }
12028
12029 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12030 struct peer *p,
12031 json_object *json)
12032 {
12033 const char *mode = "Invalid";
12034
12035 if (!json)
12036 vty_out(vty, " Local GR Mode: ");
12037
12038 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12039 mode = "Helper";
12040 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12041 mode = "Restart";
12042 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12043 mode = "Disable";
12044 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12045 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12046 mode = "Helper*";
12047 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12048 mode = "Restart*";
12049 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12050 mode = "Disable*";
12051 else
12052 mode = "Invalid*";
12053 }
12054
12055 if (json)
12056 json_object_string_add(json, "localGrMode", mode);
12057 else
12058 vty_out(vty, "%s\n", mode);
12059 }
12060
12061 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12062 struct vty *vty, struct peer *peer, json_object *json)
12063 {
12064 afi_t afi;
12065 safi_t safi;
12066 json_object *json_afi_safi = NULL;
12067 json_object *json_timer = NULL;
12068 json_object *json_endofrib_status = NULL;
12069 bool eor_flag = false;
12070
12071 FOREACH_AFI_SAFI_NSF (afi, safi) {
12072 if (!peer->afc[afi][safi])
12073 continue;
12074
12075 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12076 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12077 continue;
12078
12079 if (json) {
12080 json_afi_safi = json_object_new_object();
12081 json_endofrib_status = json_object_new_object();
12082 json_timer = json_object_new_object();
12083 }
12084
12085 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12086 eor_flag = true;
12087 else
12088 eor_flag = false;
12089
12090 if (!json) {
12091 vty_out(vty, " %s:\n",
12092 get_afi_safi_str(afi, safi, false));
12093
12094 vty_out(vty, " F bit: ");
12095 }
12096
12097 if (peer->nsf[afi][safi] &&
12098 CHECK_FLAG(peer->af_cap[afi][safi],
12099 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12100
12101 if (json) {
12102 json_object_boolean_true_add(json_afi_safi,
12103 "fBit");
12104 } else
12105 vty_out(vty, "True\n");
12106 } else {
12107 if (json)
12108 json_object_boolean_false_add(json_afi_safi,
12109 "fBit");
12110 else
12111 vty_out(vty, "False\n");
12112 }
12113
12114 if (!json)
12115 vty_out(vty, " End-of-RIB sent: ");
12116
12117 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12118 PEER_STATUS_EOR_SEND)) {
12119 if (json) {
12120 json_object_boolean_true_add(
12121 json_endofrib_status, "endOfRibSend");
12122
12123 PRINT_EOR_JSON(eor_flag);
12124 } else {
12125 vty_out(vty, "Yes\n");
12126 vty_out(vty,
12127 " End-of-RIB sent after update: ");
12128
12129 PRINT_EOR(eor_flag);
12130 }
12131 } else {
12132 if (json) {
12133 json_object_boolean_false_add(
12134 json_endofrib_status, "endOfRibSend");
12135 json_object_boolean_false_add(
12136 json_endofrib_status,
12137 "endOfRibSentAfterUpdate");
12138 } else {
12139 vty_out(vty, "No\n");
12140 vty_out(vty,
12141 " End-of-RIB sent after update: ");
12142 vty_out(vty, "No\n");
12143 }
12144 }
12145
12146 if (!json)
12147 vty_out(vty, " End-of-RIB received: ");
12148
12149 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12150 PEER_STATUS_EOR_RECEIVED)) {
12151 if (json)
12152 json_object_boolean_true_add(
12153 json_endofrib_status, "endOfRibRecv");
12154 else
12155 vty_out(vty, "Yes\n");
12156 } else {
12157 if (json)
12158 json_object_boolean_false_add(
12159 json_endofrib_status, "endOfRibRecv");
12160 else
12161 vty_out(vty, "No\n");
12162 }
12163
12164 if (json) {
12165 json_object_int_add(json_timer, "stalePathTimer",
12166 peer->bgp->stalepath_time);
12167
12168 if (peer->t_gr_stale != NULL) {
12169 json_object_int_add(json_timer,
12170 "stalePathTimerRemaining",
12171 thread_timer_remain_second(
12172 peer->t_gr_stale));
12173 }
12174
12175 /* Display Configured Selection
12176 * Deferral only when when
12177 * Gr mode is enabled.
12178 */
12179 if (CHECK_FLAG(peer->flags,
12180 PEER_FLAG_GRACEFUL_RESTART)) {
12181 json_object_int_add(json_timer,
12182 "selectionDeferralTimer",
12183 peer->bgp->stalepath_time);
12184 }
12185
12186 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12187 NULL) {
12188
12189 json_object_int_add(
12190 json_timer,
12191 "selectionDeferralTimerRemaining",
12192 thread_timer_remain_second(
12193 peer->bgp->gr_info[afi][safi]
12194 .t_select_deferral));
12195 }
12196 } else {
12197 vty_out(vty, " Timers:\n");
12198 vty_out(vty,
12199 " Configured Stale Path Time(sec): %u\n",
12200 peer->bgp->stalepath_time);
12201
12202 if (peer->t_gr_stale != NULL)
12203 vty_out(vty,
12204 " Stale Path Remaining(sec): %ld\n",
12205 thread_timer_remain_second(
12206 peer->t_gr_stale));
12207 /* Display Configured Selection
12208 * Deferral only when when
12209 * Gr mode is enabled.
12210 */
12211 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12212 vty_out(vty,
12213 " Configured Selection Deferral Time(sec): %u\n",
12214 peer->bgp->select_defer_time);
12215
12216 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12217 NULL)
12218 vty_out(vty,
12219 " Selection Deferral Time Remaining(sec): %ld\n",
12220 thread_timer_remain_second(
12221 peer->bgp->gr_info[afi][safi]
12222 .t_select_deferral));
12223 }
12224 if (json) {
12225 json_object_object_add(json_afi_safi, "endOfRibStatus",
12226 json_endofrib_status);
12227 json_object_object_add(json_afi_safi, "timers",
12228 json_timer);
12229 json_object_object_add(
12230 json, get_afi_safi_str(afi, safi, true),
12231 json_afi_safi);
12232 }
12233 }
12234 }
12235
12236 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12237 struct peer *p,
12238 json_object *json)
12239 {
12240 if (json) {
12241 json_object *json_timer = NULL;
12242
12243 json_timer = json_object_new_object();
12244
12245 json_object_int_add(json_timer, "configuredRestartTimer",
12246 p->bgp->restart_time);
12247
12248 json_object_int_add(json_timer, "receivedRestartTimer",
12249 p->v_gr_restart);
12250
12251 if (p->t_gr_restart != NULL)
12252 json_object_int_add(
12253 json_timer, "restartTimerRemaining",
12254 thread_timer_remain_second(p->t_gr_restart));
12255
12256 json_object_object_add(json, "timers", json_timer);
12257 } else {
12258
12259 vty_out(vty, " Timers:\n");
12260 vty_out(vty, " Configured Restart Time(sec): %u\n",
12261 p->bgp->restart_time);
12262
12263 vty_out(vty, " Received Restart Time(sec): %u\n",
12264 p->v_gr_restart);
12265 if (p->t_gr_restart != NULL)
12266 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12267 thread_timer_remain_second(p->t_gr_restart));
12268 if (p->t_gr_restart != NULL) {
12269 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12270 thread_timer_remain_second(p->t_gr_restart));
12271 }
12272 }
12273 }
12274
12275 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12276 json_object *json)
12277 {
12278 char dn_flag[2] = {0};
12279 /* '*' + v6 address of neighbor */
12280 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12281
12282 if (!p->conf_if && peer_dynamic_neighbor(p))
12283 dn_flag[0] = '*';
12284
12285 if (p->conf_if) {
12286 if (json)
12287 json_object_string_addf(json, "neighborAddr", "%pSU",
12288 &p->su);
12289 else
12290 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12291 &p->su);
12292 } else {
12293 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12294 p->host);
12295
12296 if (json)
12297 json_object_string_add(json, "neighborAddr",
12298 neighborAddr);
12299 else
12300 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12301 }
12302
12303 /* more gr info in new format */
12304 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12305 }
12306
12307 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12308 safi_t safi, bool use_json,
12309 json_object *json_neigh)
12310 {
12311 struct bgp_filter *filter;
12312 struct peer_af *paf;
12313 char orf_pfx_name[BUFSIZ];
12314 int orf_pfx_count;
12315 json_object *json_af = NULL;
12316 json_object *json_prefA = NULL;
12317 json_object *json_prefB = NULL;
12318 json_object *json_addr = NULL;
12319 json_object *json_advmap = NULL;
12320
12321 if (use_json) {
12322 json_addr = json_object_new_object();
12323 json_af = json_object_new_object();
12324 filter = &p->filter[afi][safi];
12325
12326 if (peer_group_active(p))
12327 json_object_string_add(json_addr, "peerGroupMember",
12328 p->group->name);
12329
12330 paf = peer_af_find(p, afi, safi);
12331 if (paf && PAF_SUBGRP(paf)) {
12332 json_object_int_add(json_addr, "updateGroupId",
12333 PAF_UPDGRP(paf)->id);
12334 json_object_int_add(json_addr, "subGroupId",
12335 PAF_SUBGRP(paf)->id);
12336 json_object_int_add(json_addr, "packetQueueLength",
12337 bpacket_queue_virtual_length(paf));
12338 }
12339
12340 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12341 || CHECK_FLAG(p->af_cap[afi][safi],
12342 PEER_CAP_ORF_PREFIX_SM_RCV)
12343 || CHECK_FLAG(p->af_cap[afi][safi],
12344 PEER_CAP_ORF_PREFIX_RM_ADV)
12345 || CHECK_FLAG(p->af_cap[afi][safi],
12346 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12347 json_object_int_add(json_af, "orfType",
12348 ORF_TYPE_PREFIX);
12349 json_prefA = json_object_new_object();
12350 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12351 PEER_CAP_ORF_PREFIX_SM_ADV,
12352 PEER_CAP_ORF_PREFIX_RM_ADV,
12353 PEER_CAP_ORF_PREFIX_SM_RCV,
12354 PEER_CAP_ORF_PREFIX_RM_RCV,
12355 use_json, json_prefA);
12356 json_object_object_add(json_af, "orfPrefixList",
12357 json_prefA);
12358 }
12359
12360 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12361 || CHECK_FLAG(p->af_cap[afi][safi],
12362 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12363 || CHECK_FLAG(p->af_cap[afi][safi],
12364 PEER_CAP_ORF_PREFIX_RM_ADV)
12365 || CHECK_FLAG(p->af_cap[afi][safi],
12366 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12367 json_object_int_add(json_af, "orfOldType",
12368 ORF_TYPE_PREFIX_OLD);
12369 json_prefB = json_object_new_object();
12370 bgp_show_peer_afi_orf_cap(
12371 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12372 PEER_CAP_ORF_PREFIX_RM_ADV,
12373 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12374 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12375 json_prefB);
12376 json_object_object_add(json_af, "orfOldPrefixList",
12377 json_prefB);
12378 }
12379
12380 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12381 || CHECK_FLAG(p->af_cap[afi][safi],
12382 PEER_CAP_ORF_PREFIX_SM_RCV)
12383 || CHECK_FLAG(p->af_cap[afi][safi],
12384 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12385 || CHECK_FLAG(p->af_cap[afi][safi],
12386 PEER_CAP_ORF_PREFIX_RM_ADV)
12387 || CHECK_FLAG(p->af_cap[afi][safi],
12388 PEER_CAP_ORF_PREFIX_RM_RCV)
12389 || CHECK_FLAG(p->af_cap[afi][safi],
12390 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12391 json_object_object_add(json_addr, "afDependentCap",
12392 json_af);
12393 else
12394 json_object_free(json_af);
12395
12396 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12397 p->host, afi, safi);
12398 orf_pfx_count = prefix_bgp_show_prefix_list(
12399 NULL, afi, orf_pfx_name, use_json);
12400
12401 if (CHECK_FLAG(p->af_sflags[afi][safi],
12402 PEER_STATUS_ORF_PREFIX_SEND)
12403 || orf_pfx_count) {
12404 if (CHECK_FLAG(p->af_sflags[afi][safi],
12405 PEER_STATUS_ORF_PREFIX_SEND))
12406 json_object_boolean_true_add(json_neigh,
12407 "orfSent");
12408 if (orf_pfx_count)
12409 json_object_int_add(json_addr, "orfRecvCounter",
12410 orf_pfx_count);
12411 }
12412 if (CHECK_FLAG(p->af_sflags[afi][safi],
12413 PEER_STATUS_ORF_WAIT_REFRESH))
12414 json_object_string_add(
12415 json_addr, "orfFirstUpdate",
12416 "deferredUntilORFOrRouteRefreshRecvd");
12417
12418 if (CHECK_FLAG(p->af_flags[afi][safi],
12419 PEER_FLAG_REFLECTOR_CLIENT))
12420 json_object_boolean_true_add(json_addr,
12421 "routeReflectorClient");
12422 if (CHECK_FLAG(p->af_flags[afi][safi],
12423 PEER_FLAG_RSERVER_CLIENT))
12424 json_object_boolean_true_add(json_addr,
12425 "routeServerClient");
12426 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12427 json_object_boolean_true_add(json_addr,
12428 "inboundSoftConfigPermit");
12429
12430 if (CHECK_FLAG(p->af_flags[afi][safi],
12431 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12432 json_object_boolean_true_add(
12433 json_addr,
12434 "privateAsNumsAllReplacedInUpdatesToNbr");
12435 else if (CHECK_FLAG(p->af_flags[afi][safi],
12436 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12437 json_object_boolean_true_add(
12438 json_addr,
12439 "privateAsNumsReplacedInUpdatesToNbr");
12440 else if (CHECK_FLAG(p->af_flags[afi][safi],
12441 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12442 json_object_boolean_true_add(
12443 json_addr,
12444 "privateAsNumsAllRemovedInUpdatesToNbr");
12445 else if (CHECK_FLAG(p->af_flags[afi][safi],
12446 PEER_FLAG_REMOVE_PRIVATE_AS))
12447 json_object_boolean_true_add(
12448 json_addr,
12449 "privateAsNumsRemovedInUpdatesToNbr");
12450
12451 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12452 if (CHECK_FLAG(p->af_flags[afi][safi],
12453 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12454 json_object_boolean_true_add(json_addr,
12455 "allowAsInOrigin");
12456 else
12457 json_object_int_add(json_addr, "allowAsInCount",
12458 p->allowas_in[afi][safi]);
12459 }
12460
12461 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12462 json_object_boolean_true_add(
12463 json_addr,
12464 bgp_addpath_names(p->addpath_type[afi][safi])
12465 ->type_json_name);
12466
12467 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12468 json_object_string_add(json_addr,
12469 "overrideASNsInOutboundUpdates",
12470 "ifAspathEqualRemoteAs");
12471
12472 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12473 || CHECK_FLAG(p->af_flags[afi][safi],
12474 PEER_FLAG_FORCE_NEXTHOP_SELF))
12475 json_object_boolean_true_add(json_addr,
12476 "routerAlwaysNextHop");
12477 if (CHECK_FLAG(p->af_flags[afi][safi],
12478 PEER_FLAG_AS_PATH_UNCHANGED))
12479 json_object_boolean_true_add(
12480 json_addr, "unchangedAsPathPropogatedToNbr");
12481 if (CHECK_FLAG(p->af_flags[afi][safi],
12482 PEER_FLAG_NEXTHOP_UNCHANGED))
12483 json_object_boolean_true_add(
12484 json_addr, "unchangedNextHopPropogatedToNbr");
12485 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12486 json_object_boolean_true_add(
12487 json_addr, "unchangedMedPropogatedToNbr");
12488 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12489 || CHECK_FLAG(p->af_flags[afi][safi],
12490 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12491 if (CHECK_FLAG(p->af_flags[afi][safi],
12492 PEER_FLAG_SEND_COMMUNITY)
12493 && CHECK_FLAG(p->af_flags[afi][safi],
12494 PEER_FLAG_SEND_EXT_COMMUNITY))
12495 json_object_string_add(json_addr,
12496 "commAttriSentToNbr",
12497 "extendedAndStandard");
12498 else if (CHECK_FLAG(p->af_flags[afi][safi],
12499 PEER_FLAG_SEND_EXT_COMMUNITY))
12500 json_object_string_add(json_addr,
12501 "commAttriSentToNbr",
12502 "extended");
12503 else
12504 json_object_string_add(json_addr,
12505 "commAttriSentToNbr",
12506 "standard");
12507 }
12508 if (CHECK_FLAG(p->af_flags[afi][safi],
12509 PEER_FLAG_DEFAULT_ORIGINATE)) {
12510 if (p->default_rmap[afi][safi].name)
12511 json_object_string_add(
12512 json_addr, "defaultRouteMap",
12513 p->default_rmap[afi][safi].name);
12514
12515 if (paf && PAF_SUBGRP(paf)
12516 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12517 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12518 json_object_boolean_true_add(json_addr,
12519 "defaultSent");
12520 else
12521 json_object_boolean_true_add(json_addr,
12522 "defaultNotSent");
12523 }
12524
12525 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12526 if (is_evpn_enabled())
12527 json_object_boolean_true_add(
12528 json_addr, "advertiseAllVnis");
12529 }
12530
12531 if (filter->plist[FILTER_IN].name
12532 || filter->dlist[FILTER_IN].name
12533 || filter->aslist[FILTER_IN].name
12534 || filter->map[RMAP_IN].name)
12535 json_object_boolean_true_add(json_addr,
12536 "inboundPathPolicyConfig");
12537 if (filter->plist[FILTER_OUT].name
12538 || filter->dlist[FILTER_OUT].name
12539 || filter->aslist[FILTER_OUT].name
12540 || filter->map[RMAP_OUT].name || filter->usmap.name)
12541 json_object_boolean_true_add(
12542 json_addr, "outboundPathPolicyConfig");
12543
12544 /* prefix-list */
12545 if (filter->plist[FILTER_IN].name)
12546 json_object_string_add(json_addr,
12547 "incomingUpdatePrefixFilterList",
12548 filter->plist[FILTER_IN].name);
12549 if (filter->plist[FILTER_OUT].name)
12550 json_object_string_add(json_addr,
12551 "outgoingUpdatePrefixFilterList",
12552 filter->plist[FILTER_OUT].name);
12553
12554 /* distribute-list */
12555 if (filter->dlist[FILTER_IN].name)
12556 json_object_string_add(
12557 json_addr, "incomingUpdateNetworkFilterList",
12558 filter->dlist[FILTER_IN].name);
12559 if (filter->dlist[FILTER_OUT].name)
12560 json_object_string_add(
12561 json_addr, "outgoingUpdateNetworkFilterList",
12562 filter->dlist[FILTER_OUT].name);
12563
12564 /* filter-list. */
12565 if (filter->aslist[FILTER_IN].name)
12566 json_object_string_add(json_addr,
12567 "incomingUpdateAsPathFilterList",
12568 filter->aslist[FILTER_IN].name);
12569 if (filter->aslist[FILTER_OUT].name)
12570 json_object_string_add(json_addr,
12571 "outgoingUpdateAsPathFilterList",
12572 filter->aslist[FILTER_OUT].name);
12573
12574 /* route-map. */
12575 if (filter->map[RMAP_IN].name)
12576 json_object_string_add(
12577 json_addr, "routeMapForIncomingAdvertisements",
12578 filter->map[RMAP_IN].name);
12579 if (filter->map[RMAP_OUT].name)
12580 json_object_string_add(
12581 json_addr, "routeMapForOutgoingAdvertisements",
12582 filter->map[RMAP_OUT].name);
12583
12584 /* ebgp-requires-policy (inbound) */
12585 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12586 && !bgp_inbound_policy_exists(p, filter))
12587 json_object_string_add(
12588 json_addr, "inboundEbgpRequiresPolicy",
12589 "Inbound updates discarded due to missing policy");
12590
12591 /* ebgp-requires-policy (outbound) */
12592 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12593 && (!bgp_outbound_policy_exists(p, filter)))
12594 json_object_string_add(
12595 json_addr, "outboundEbgpRequiresPolicy",
12596 "Outbound updates discarded due to missing policy");
12597
12598 /* unsuppress-map */
12599 if (filter->usmap.name)
12600 json_object_string_add(json_addr,
12601 "selectiveUnsuppressRouteMap",
12602 filter->usmap.name);
12603
12604 /* advertise-map */
12605 if (filter->advmap.aname) {
12606 json_advmap = json_object_new_object();
12607 json_object_string_add(json_advmap, "condition",
12608 filter->advmap.condition
12609 ? "EXIST"
12610 : "NON_EXIST");
12611 json_object_string_add(json_advmap, "conditionMap",
12612 filter->advmap.cname);
12613 json_object_string_add(json_advmap, "advertiseMap",
12614 filter->advmap.aname);
12615 json_object_string_add(
12616 json_advmap, "advertiseStatus",
12617 filter->advmap.update_type ==
12618 UPDATE_TYPE_ADVERTISE
12619 ? "Advertise"
12620 : "Withdraw");
12621 json_object_object_add(json_addr, "advertiseMap",
12622 json_advmap);
12623 }
12624
12625 /* Receive prefix count */
12626 json_object_int_add(json_addr, "acceptedPrefixCounter",
12627 p->pcount[afi][safi]);
12628 if (paf && PAF_SUBGRP(paf))
12629 json_object_int_add(json_addr, "sentPrefixCounter",
12630 (PAF_SUBGRP(paf))->scount);
12631
12632 /* Maximum prefix */
12633 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12634 json_object_int_add(json_addr, "prefixOutAllowedMax",
12635 p->pmax_out[afi][safi]);
12636
12637 /* Maximum prefix */
12638 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12639 json_object_int_add(json_addr, "prefixAllowedMax",
12640 p->pmax[afi][safi]);
12641 if (CHECK_FLAG(p->af_flags[afi][safi],
12642 PEER_FLAG_MAX_PREFIX_WARNING))
12643 json_object_boolean_true_add(
12644 json_addr, "prefixAllowedMaxWarning");
12645 json_object_int_add(json_addr,
12646 "prefixAllowedWarningThresh",
12647 p->pmax_threshold[afi][safi]);
12648 if (p->pmax_restart[afi][safi])
12649 json_object_int_add(
12650 json_addr,
12651 "prefixAllowedRestartIntervalMsecs",
12652 p->pmax_restart[afi][safi] * 60000);
12653 }
12654 json_object_object_add(json_neigh,
12655 get_afi_safi_str(afi, safi, true),
12656 json_addr);
12657
12658 } else {
12659 filter = &p->filter[afi][safi];
12660
12661 vty_out(vty, " For address family: %s\n",
12662 get_afi_safi_str(afi, safi, false));
12663
12664 if (peer_group_active(p))
12665 vty_out(vty, " %s peer-group member\n",
12666 p->group->name);
12667
12668 paf = peer_af_find(p, afi, safi);
12669 if (paf && PAF_SUBGRP(paf)) {
12670 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12671 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12672 vty_out(vty, " Packet Queue length %d\n",
12673 bpacket_queue_virtual_length(paf));
12674 } else {
12675 vty_out(vty, " Not part of any update group\n");
12676 }
12677 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12678 || CHECK_FLAG(p->af_cap[afi][safi],
12679 PEER_CAP_ORF_PREFIX_SM_RCV)
12680 || CHECK_FLAG(p->af_cap[afi][safi],
12681 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12682 || CHECK_FLAG(p->af_cap[afi][safi],
12683 PEER_CAP_ORF_PREFIX_RM_ADV)
12684 || CHECK_FLAG(p->af_cap[afi][safi],
12685 PEER_CAP_ORF_PREFIX_RM_RCV)
12686 || CHECK_FLAG(p->af_cap[afi][safi],
12687 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12688 vty_out(vty, " AF-dependant capabilities:\n");
12689
12690 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12691 || CHECK_FLAG(p->af_cap[afi][safi],
12692 PEER_CAP_ORF_PREFIX_SM_RCV)
12693 || CHECK_FLAG(p->af_cap[afi][safi],
12694 PEER_CAP_ORF_PREFIX_RM_ADV)
12695 || CHECK_FLAG(p->af_cap[afi][safi],
12696 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12697 vty_out(vty,
12698 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12699 ORF_TYPE_PREFIX);
12700 bgp_show_peer_afi_orf_cap(
12701 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12702 PEER_CAP_ORF_PREFIX_RM_ADV,
12703 PEER_CAP_ORF_PREFIX_SM_RCV,
12704 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12705 }
12706 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12707 || CHECK_FLAG(p->af_cap[afi][safi],
12708 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12709 || CHECK_FLAG(p->af_cap[afi][safi],
12710 PEER_CAP_ORF_PREFIX_RM_ADV)
12711 || CHECK_FLAG(p->af_cap[afi][safi],
12712 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12713 vty_out(vty,
12714 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12715 ORF_TYPE_PREFIX_OLD);
12716 bgp_show_peer_afi_orf_cap(
12717 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12718 PEER_CAP_ORF_PREFIX_RM_ADV,
12719 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12720 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12721 }
12722
12723 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12724 p->host, afi, safi);
12725 orf_pfx_count = prefix_bgp_show_prefix_list(
12726 NULL, afi, orf_pfx_name, use_json);
12727
12728 if (CHECK_FLAG(p->af_sflags[afi][safi],
12729 PEER_STATUS_ORF_PREFIX_SEND)
12730 || orf_pfx_count) {
12731 vty_out(vty, " Outbound Route Filter (ORF):");
12732 if (CHECK_FLAG(p->af_sflags[afi][safi],
12733 PEER_STATUS_ORF_PREFIX_SEND))
12734 vty_out(vty, " sent;");
12735 if (orf_pfx_count)
12736 vty_out(vty, " received (%d entries)",
12737 orf_pfx_count);
12738 vty_out(vty, "\n");
12739 }
12740 if (CHECK_FLAG(p->af_sflags[afi][safi],
12741 PEER_STATUS_ORF_WAIT_REFRESH))
12742 vty_out(vty,
12743 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12744
12745 if (CHECK_FLAG(p->af_flags[afi][safi],
12746 PEER_FLAG_REFLECTOR_CLIENT))
12747 vty_out(vty, " Route-Reflector Client\n");
12748 if (CHECK_FLAG(p->af_flags[afi][safi],
12749 PEER_FLAG_RSERVER_CLIENT))
12750 vty_out(vty, " Route-Server Client\n");
12751 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12752 vty_out(vty,
12753 " Inbound soft reconfiguration allowed\n");
12754
12755 if (CHECK_FLAG(p->af_flags[afi][safi],
12756 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12757 vty_out(vty,
12758 " Private AS numbers (all) replaced in updates to this neighbor\n");
12759 else if (CHECK_FLAG(p->af_flags[afi][safi],
12760 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12761 vty_out(vty,
12762 " Private AS numbers replaced in updates to this neighbor\n");
12763 else if (CHECK_FLAG(p->af_flags[afi][safi],
12764 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12765 vty_out(vty,
12766 " Private AS numbers (all) removed in updates to this neighbor\n");
12767 else if (CHECK_FLAG(p->af_flags[afi][safi],
12768 PEER_FLAG_REMOVE_PRIVATE_AS))
12769 vty_out(vty,
12770 " Private AS numbers removed in updates to this neighbor\n");
12771
12772 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12773 if (CHECK_FLAG(p->af_flags[afi][safi],
12774 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12775 vty_out(vty,
12776 " Local AS allowed as path origin\n");
12777 else
12778 vty_out(vty,
12779 " Local AS allowed in path, %d occurrences\n",
12780 p->allowas_in[afi][safi]);
12781 }
12782
12783 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12784 vty_out(vty, " %s\n",
12785 bgp_addpath_names(p->addpath_type[afi][safi])
12786 ->human_description);
12787
12788 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12789 vty_out(vty,
12790 " Override ASNs in outbound updates if aspath equals remote-as\n");
12791
12792 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12793 || CHECK_FLAG(p->af_flags[afi][safi],
12794 PEER_FLAG_FORCE_NEXTHOP_SELF))
12795 vty_out(vty, " NEXT_HOP is always this router\n");
12796 if (CHECK_FLAG(p->af_flags[afi][safi],
12797 PEER_FLAG_AS_PATH_UNCHANGED))
12798 vty_out(vty,
12799 " AS_PATH is propagated unchanged to this neighbor\n");
12800 if (CHECK_FLAG(p->af_flags[afi][safi],
12801 PEER_FLAG_NEXTHOP_UNCHANGED))
12802 vty_out(vty,
12803 " NEXT_HOP is propagated unchanged to this neighbor\n");
12804 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12805 vty_out(vty,
12806 " MED is propagated unchanged to this neighbor\n");
12807 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12808 || CHECK_FLAG(p->af_flags[afi][safi],
12809 PEER_FLAG_SEND_EXT_COMMUNITY)
12810 || CHECK_FLAG(p->af_flags[afi][safi],
12811 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12812 vty_out(vty,
12813 " Community attribute sent to this neighbor");
12814 if (CHECK_FLAG(p->af_flags[afi][safi],
12815 PEER_FLAG_SEND_COMMUNITY)
12816 && CHECK_FLAG(p->af_flags[afi][safi],
12817 PEER_FLAG_SEND_EXT_COMMUNITY)
12818 && CHECK_FLAG(p->af_flags[afi][safi],
12819 PEER_FLAG_SEND_LARGE_COMMUNITY))
12820 vty_out(vty, "(all)\n");
12821 else if (CHECK_FLAG(p->af_flags[afi][safi],
12822 PEER_FLAG_SEND_LARGE_COMMUNITY))
12823 vty_out(vty, "(large)\n");
12824 else if (CHECK_FLAG(p->af_flags[afi][safi],
12825 PEER_FLAG_SEND_EXT_COMMUNITY))
12826 vty_out(vty, "(extended)\n");
12827 else
12828 vty_out(vty, "(standard)\n");
12829 }
12830 if (CHECK_FLAG(p->af_flags[afi][safi],
12831 PEER_FLAG_DEFAULT_ORIGINATE)) {
12832 vty_out(vty, " Default information originate,");
12833
12834 if (p->default_rmap[afi][safi].name)
12835 vty_out(vty, " default route-map %s%s,",
12836 p->default_rmap[afi][safi].map ? "*"
12837 : "",
12838 p->default_rmap[afi][safi].name);
12839 if (paf && PAF_SUBGRP(paf)
12840 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12841 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12842 vty_out(vty, " default sent\n");
12843 else
12844 vty_out(vty, " default not sent\n");
12845 }
12846
12847 /* advertise-vni-all */
12848 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12849 if (is_evpn_enabled())
12850 vty_out(vty, " advertise-all-vni\n");
12851 }
12852
12853 if (filter->plist[FILTER_IN].name
12854 || filter->dlist[FILTER_IN].name
12855 || filter->aslist[FILTER_IN].name
12856 || filter->map[RMAP_IN].name)
12857 vty_out(vty, " Inbound path policy configured\n");
12858 if (filter->plist[FILTER_OUT].name
12859 || filter->dlist[FILTER_OUT].name
12860 || filter->aslist[FILTER_OUT].name
12861 || filter->map[RMAP_OUT].name || filter->usmap.name)
12862 vty_out(vty, " Outbound path policy configured\n");
12863
12864 /* prefix-list */
12865 if (filter->plist[FILTER_IN].name)
12866 vty_out(vty,
12867 " Incoming update prefix filter list is %s%s\n",
12868 filter->plist[FILTER_IN].plist ? "*" : "",
12869 filter->plist[FILTER_IN].name);
12870 if (filter->plist[FILTER_OUT].name)
12871 vty_out(vty,
12872 " Outgoing update prefix filter list is %s%s\n",
12873 filter->plist[FILTER_OUT].plist ? "*" : "",
12874 filter->plist[FILTER_OUT].name);
12875
12876 /* distribute-list */
12877 if (filter->dlist[FILTER_IN].name)
12878 vty_out(vty,
12879 " Incoming update network filter list is %s%s\n",
12880 filter->dlist[FILTER_IN].alist ? "*" : "",
12881 filter->dlist[FILTER_IN].name);
12882 if (filter->dlist[FILTER_OUT].name)
12883 vty_out(vty,
12884 " Outgoing update network filter list is %s%s\n",
12885 filter->dlist[FILTER_OUT].alist ? "*" : "",
12886 filter->dlist[FILTER_OUT].name);
12887
12888 /* filter-list. */
12889 if (filter->aslist[FILTER_IN].name)
12890 vty_out(vty,
12891 " Incoming update AS path filter list is %s%s\n",
12892 filter->aslist[FILTER_IN].aslist ? "*" : "",
12893 filter->aslist[FILTER_IN].name);
12894 if (filter->aslist[FILTER_OUT].name)
12895 vty_out(vty,
12896 " Outgoing update AS path filter list is %s%s\n",
12897 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12898 filter->aslist[FILTER_OUT].name);
12899
12900 /* route-map. */
12901 if (filter->map[RMAP_IN].name)
12902 vty_out(vty,
12903 " Route map for incoming advertisements is %s%s\n",
12904 filter->map[RMAP_IN].map ? "*" : "",
12905 filter->map[RMAP_IN].name);
12906 if (filter->map[RMAP_OUT].name)
12907 vty_out(vty,
12908 " Route map for outgoing advertisements is %s%s\n",
12909 filter->map[RMAP_OUT].map ? "*" : "",
12910 filter->map[RMAP_OUT].name);
12911
12912 /* ebgp-requires-policy (inbound) */
12913 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12914 && !bgp_inbound_policy_exists(p, filter))
12915 vty_out(vty,
12916 " Inbound updates discarded due to missing policy\n");
12917
12918 /* ebgp-requires-policy (outbound) */
12919 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12920 && !bgp_outbound_policy_exists(p, filter))
12921 vty_out(vty,
12922 " Outbound updates discarded due to missing policy\n");
12923
12924 /* unsuppress-map */
12925 if (filter->usmap.name)
12926 vty_out(vty,
12927 " Route map for selective unsuppress is %s%s\n",
12928 filter->usmap.map ? "*" : "",
12929 filter->usmap.name);
12930
12931 /* advertise-map */
12932 if (filter->advmap.aname && filter->advmap.cname)
12933 vty_out(vty,
12934 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12935 filter->advmap.condition ? "EXIST"
12936 : "NON_EXIST",
12937 filter->advmap.cmap ? "*" : "",
12938 filter->advmap.cname,
12939 filter->advmap.amap ? "*" : "",
12940 filter->advmap.aname,
12941 filter->advmap.update_type ==
12942 UPDATE_TYPE_ADVERTISE
12943 ? "Advertise"
12944 : "Withdraw");
12945
12946 /* Receive prefix count */
12947 vty_out(vty, " %u accepted prefixes\n",
12948 p->pcount[afi][safi]);
12949
12950 /* maximum-prefix-out */
12951 if (CHECK_FLAG(p->af_flags[afi][safi],
12952 PEER_FLAG_MAX_PREFIX_OUT))
12953 vty_out(vty,
12954 " Maximum allowed prefixes sent %u\n",
12955 p->pmax_out[afi][safi]);
12956
12957 /* Maximum prefix */
12958 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12959 vty_out(vty,
12960 " Maximum prefixes allowed %u%s\n",
12961 p->pmax[afi][safi],
12962 CHECK_FLAG(p->af_flags[afi][safi],
12963 PEER_FLAG_MAX_PREFIX_WARNING)
12964 ? " (warning-only)"
12965 : "");
12966 vty_out(vty, " Threshold for warning message %d%%",
12967 p->pmax_threshold[afi][safi]);
12968 if (p->pmax_restart[afi][safi])
12969 vty_out(vty, ", restart interval %d min",
12970 p->pmax_restart[afi][safi]);
12971 vty_out(vty, "\n");
12972 }
12973
12974 vty_out(vty, "\n");
12975 }
12976 }
12977
12978 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12979 json_object *json)
12980 {
12981 struct bgp *bgp;
12982 char timebuf[BGP_UPTIME_LEN];
12983 char dn_flag[2];
12984 afi_t afi;
12985 safi_t safi;
12986 uint16_t i;
12987 uint8_t *msg;
12988 json_object *json_neigh = NULL;
12989 time_t epoch_tbuf;
12990 uint32_t sync_tcp_mss;
12991
12992 bgp = p->bgp;
12993
12994 if (use_json)
12995 json_neigh = json_object_new_object();
12996
12997 memset(dn_flag, '\0', sizeof(dn_flag));
12998 if (!p->conf_if && peer_dynamic_neighbor(p))
12999 dn_flag[0] = '*';
13000
13001 if (!use_json) {
13002 if (p->conf_if) /* Configured interface name. */
13003 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13004 &p->su);
13005 else /* Configured IP address. */
13006 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13007 p->host);
13008 }
13009
13010 if (use_json) {
13011 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13012 json_object_string_add(json_neigh, "bgpNeighborAddr",
13013 "none");
13014 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13015 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13016 "%pSU", &p->su);
13017
13018 json_object_int_add(json_neigh, "remoteAs", p->as);
13019
13020 if (p->change_local_as)
13021 json_object_int_add(json_neigh, "localAs",
13022 p->change_local_as);
13023 else
13024 json_object_int_add(json_neigh, "localAs", p->local_as);
13025
13026 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13027 json_object_boolean_true_add(json_neigh,
13028 "localAsNoPrepend");
13029
13030 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13031 json_object_boolean_true_add(json_neigh,
13032 "localAsReplaceAs");
13033 } else {
13034 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13035 || (p->as_type == AS_INTERNAL))
13036 vty_out(vty, "remote AS %u, ", p->as);
13037 else
13038 vty_out(vty, "remote AS Unspecified, ");
13039 vty_out(vty, "local AS %u%s%s, ",
13040 p->change_local_as ? p->change_local_as : p->local_as,
13041 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13042 ? " no-prepend"
13043 : "",
13044 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13045 ? " replace-as"
13046 : "");
13047 }
13048 /* peer type internal or confed-internal */
13049 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13050 if (use_json) {
13051 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13052 json_object_boolean_true_add(
13053 json_neigh, "nbrConfedInternalLink");
13054 else
13055 json_object_boolean_true_add(json_neigh,
13056 "nbrInternalLink");
13057 } else {
13058 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13059 vty_out(vty, "confed-internal link\n");
13060 else
13061 vty_out(vty, "internal link\n");
13062 }
13063 /* peer type external or confed-external */
13064 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13065 if (use_json) {
13066 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13067 json_object_boolean_true_add(
13068 json_neigh, "nbrConfedExternalLink");
13069 else
13070 json_object_boolean_true_add(json_neigh,
13071 "nbrExternalLink");
13072 } else {
13073 if (bgp_confederation_peers_check(bgp, p->as))
13074 vty_out(vty, "confed-external link\n");
13075 else
13076 vty_out(vty, "external link\n");
13077 }
13078 } else {
13079 if (use_json)
13080 json_object_boolean_true_add(json_neigh,
13081 "nbrUnspecifiedLink");
13082 else
13083 vty_out(vty, "unspecified link\n");
13084 }
13085
13086 /* Roles */
13087 if (use_json) {
13088 json_object_string_add(json_neigh, "localRole",
13089 bgp_get_name_by_role(p->local_role));
13090 json_object_string_add(json_neigh, "remoteRole",
13091 bgp_get_name_by_role(p->remote_role));
13092 } else {
13093 vty_out(vty, " Local Role: %s\n",
13094 bgp_get_name_by_role(p->local_role));
13095 vty_out(vty, " Remote Role: %s\n",
13096 bgp_get_name_by_role(p->remote_role));
13097 }
13098
13099
13100 /* Description. */
13101 if (p->desc) {
13102 if (use_json)
13103 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13104 else
13105 vty_out(vty, " Description: %s\n", p->desc);
13106 }
13107
13108 if (p->hostname) {
13109 if (use_json) {
13110 json_object_string_add(json_neigh, "hostname",
13111 p->hostname);
13112
13113 if (p->domainname)
13114 json_object_string_add(json_neigh, "domainname",
13115 p->domainname);
13116 } else {
13117 if (p->domainname && (p->domainname[0] != '\0'))
13118 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13119 p->domainname);
13120 else
13121 vty_out(vty, "Hostname: %s\n", p->hostname);
13122 }
13123 } else {
13124 if (use_json)
13125 json_object_string_add(json_neigh, "hostname",
13126 "Unknown");
13127 }
13128
13129 /* Peer-group */
13130 if (p->group) {
13131 if (use_json) {
13132 json_object_string_add(json_neigh, "peerGroup",
13133 p->group->name);
13134
13135 if (dn_flag[0]) {
13136 struct prefix prefix, *range = NULL;
13137
13138 if (sockunion2hostprefix(&(p->su), &prefix))
13139 range = peer_group_lookup_dynamic_neighbor_range(
13140 p->group, &prefix);
13141
13142 if (range) {
13143 json_object_string_addf(
13144 json_neigh,
13145 "peerSubnetRangeGroup", "%pFX",
13146 range);
13147 }
13148 }
13149 } else {
13150 vty_out(vty,
13151 " Member of peer-group %s for session parameters\n",
13152 p->group->name);
13153
13154 if (dn_flag[0]) {
13155 struct prefix prefix, *range = NULL;
13156
13157 if (sockunion2hostprefix(&(p->su), &prefix))
13158 range = peer_group_lookup_dynamic_neighbor_range(
13159 p->group, &prefix);
13160
13161 if (range) {
13162 vty_out(vty,
13163 " Belongs to the subnet range group: %pFX\n",
13164 range);
13165 }
13166 }
13167 }
13168 }
13169
13170 if (use_json) {
13171 /* Administrative shutdown. */
13172 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13173 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13174 json_object_boolean_true_add(json_neigh,
13175 "adminShutDown");
13176
13177 /* BGP Version. */
13178 json_object_int_add(json_neigh, "bgpVersion", 4);
13179 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13180 &p->remote_id);
13181 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13182 &bgp->router_id);
13183
13184 /* Confederation */
13185 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13186 && bgp_confederation_peers_check(bgp, p->as))
13187 json_object_boolean_true_add(json_neigh,
13188 "nbrCommonAdmin");
13189
13190 /* Status. */
13191 json_object_string_add(
13192 json_neigh, "bgpState",
13193 lookup_msg(bgp_status_msg, p->status, NULL));
13194
13195 if (peer_established(p)) {
13196 time_t uptime;
13197
13198 uptime = monotime(NULL);
13199 uptime -= p->uptime;
13200 epoch_tbuf = time(NULL) - uptime;
13201
13202 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13203 uptime * 1000);
13204 json_object_string_add(json_neigh, "bgpTimerUpString",
13205 peer_uptime(p->uptime, timebuf,
13206 BGP_UPTIME_LEN, 0,
13207 NULL));
13208 json_object_int_add(json_neigh,
13209 "bgpTimerUpEstablishedEpoch",
13210 epoch_tbuf);
13211 }
13212
13213 else if (p->status == Active) {
13214 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13215 json_object_string_add(json_neigh, "bgpStateIs",
13216 "passive");
13217 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13218 json_object_string_add(json_neigh, "bgpStateIs",
13219 "passiveNSF");
13220 }
13221
13222 /* read timer */
13223 time_t uptime;
13224 struct tm tm;
13225
13226 uptime = monotime(NULL);
13227 uptime -= p->readtime;
13228 gmtime_r(&uptime, &tm);
13229
13230 json_object_int_add(json_neigh, "bgpTimerLastRead",
13231 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13232 + (tm.tm_hour * 3600000));
13233
13234 uptime = monotime(NULL);
13235 uptime -= p->last_write;
13236 gmtime_r(&uptime, &tm);
13237
13238 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13239 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13240 + (tm.tm_hour * 3600000));
13241
13242 uptime = monotime(NULL);
13243 uptime -= p->update_time;
13244 gmtime_r(&uptime, &tm);
13245
13246 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13247 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13248 + (tm.tm_hour * 3600000));
13249
13250 /* Configured timer values. */
13251 json_object_int_add(json_neigh,
13252 "bgpTimerConfiguredHoldTimeMsecs",
13253 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13254 ? p->holdtime * 1000
13255 : bgp->default_holdtime * 1000);
13256 json_object_int_add(json_neigh,
13257 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13258 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13259 ? p->keepalive * 1000
13260 : bgp->default_keepalive * 1000);
13261 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13262 p->v_holdtime * 1000);
13263 json_object_int_add(json_neigh,
13264 "bgpTimerKeepAliveIntervalMsecs",
13265 p->v_keepalive * 1000);
13266 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13267 json_object_int_add(json_neigh,
13268 "bgpTimerDelayOpenTimeMsecs",
13269 p->v_delayopen * 1000);
13270 }
13271
13272 /* Configured and Synced tcp-mss value for peer */
13273 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13274 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13275 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13276 p->tcp_mss);
13277 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13278 sync_tcp_mss);
13279 }
13280
13281 /* Extended Optional Parameters Length for BGP OPEN Message */
13282 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13283 json_object_boolean_true_add(
13284 json_neigh, "extendedOptionalParametersLength");
13285 else
13286 json_object_boolean_false_add(
13287 json_neigh, "extendedOptionalParametersLength");
13288
13289 /* Conditional advertisements */
13290 json_object_int_add(
13291 json_neigh,
13292 "bgpTimerConfiguredConditionalAdvertisementsSec",
13293 bgp->condition_check_period);
13294 if (thread_is_scheduled(bgp->t_condition_check))
13295 json_object_int_add(
13296 json_neigh,
13297 "bgpTimerUntilConditionalAdvertisementsSec",
13298 thread_timer_remain_second(
13299 bgp->t_condition_check));
13300 } else {
13301 /* Administrative shutdown. */
13302 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13303 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13304 vty_out(vty, " Administratively shut down\n");
13305
13306 /* BGP Version. */
13307 vty_out(vty, " BGP version 4");
13308 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13309 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13310
13311 /* Confederation */
13312 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13313 && bgp_confederation_peers_check(bgp, p->as))
13314 vty_out(vty,
13315 " Neighbor under common administration\n");
13316
13317 /* Status. */
13318 vty_out(vty, " BGP state = %s",
13319 lookup_msg(bgp_status_msg, p->status, NULL));
13320
13321 if (peer_established(p))
13322 vty_out(vty, ", up for %8s",
13323 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13324 0, NULL));
13325
13326 else if (p->status == Active) {
13327 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13328 vty_out(vty, " (passive)");
13329 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13330 vty_out(vty, " (NSF passive)");
13331 }
13332 vty_out(vty, "\n");
13333
13334 /* read timer */
13335 vty_out(vty, " Last read %s",
13336 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13337 NULL));
13338 vty_out(vty, ", Last write %s\n",
13339 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13340 NULL));
13341
13342 /* Configured timer values. */
13343 vty_out(vty,
13344 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13345 p->v_holdtime, p->v_keepalive);
13346 vty_out(vty, " Configured hold time is %d seconds",
13347 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13348 ? p->holdtime
13349 : bgp->default_holdtime);
13350 vty_out(vty, ", keepalive interval is %d seconds\n",
13351 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13352 ? p->keepalive
13353 : bgp->default_keepalive);
13354 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13355 vty_out(vty,
13356 " Configured DelayOpenTime is %d seconds\n",
13357 p->delayopen);
13358
13359 /* Configured and synced tcp-mss value for peer */
13360 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13361 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13362 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13363 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13364 }
13365
13366 /* Extended Optional Parameters Length for BGP OPEN Message */
13367 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13368 vty_out(vty,
13369 " Extended Optional Parameters Length is enabled\n");
13370
13371 /* Conditional advertisements */
13372 vty_out(vty,
13373 " Configured conditional advertisements interval is %d seconds\n",
13374 bgp->condition_check_period);
13375 if (thread_is_scheduled(bgp->t_condition_check))
13376 vty_out(vty,
13377 " Time until conditional advertisements begin is %lu seconds\n",
13378 thread_timer_remain_second(
13379 bgp->t_condition_check));
13380 }
13381 /* Capability. */
13382 if (peer_established(p) &&
13383 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13384 if (use_json) {
13385 json_object *json_cap = NULL;
13386
13387 json_cap = json_object_new_object();
13388
13389 /* AS4 */
13390 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13391 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13392 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13393 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13394 json_object_string_add(
13395 json_cap, "4byteAs",
13396 "advertisedAndReceived");
13397 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13398 json_object_string_add(json_cap,
13399 "4byteAs",
13400 "advertised");
13401 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13402 json_object_string_add(json_cap,
13403 "4byteAs",
13404 "received");
13405 }
13406
13407 /* Extended Message Support */
13408 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13409 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13410 json_object_string_add(json_cap,
13411 "extendedMessage",
13412 "advertisedAndReceived");
13413 else if (CHECK_FLAG(p->cap,
13414 PEER_CAP_EXTENDED_MESSAGE_ADV))
13415 json_object_string_add(json_cap,
13416 "extendedMessage",
13417 "advertised");
13418 else if (CHECK_FLAG(p->cap,
13419 PEER_CAP_EXTENDED_MESSAGE_RCV))
13420 json_object_string_add(json_cap,
13421 "extendedMessage",
13422 "received");
13423
13424 /* AddPath */
13425 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13426 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13427 json_object *json_add = NULL;
13428 const char *print_store;
13429
13430 json_add = json_object_new_object();
13431
13432 FOREACH_AFI_SAFI (afi, safi) {
13433 json_object *json_sub = NULL;
13434 json_sub = json_object_new_object();
13435 print_store = get_afi_safi_str(
13436 afi, safi, true);
13437
13438 if (CHECK_FLAG(
13439 p->af_cap[afi][safi],
13440 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13441 CHECK_FLAG(
13442 p->af_cap[afi][safi],
13443 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13444 if (CHECK_FLAG(
13445 p->af_cap[afi]
13446 [safi],
13447 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13448 CHECK_FLAG(
13449 p->af_cap[afi]
13450 [safi],
13451 PEER_CAP_ADDPATH_AF_TX_RCV))
13452 json_object_boolean_true_add(
13453 json_sub,
13454 "txAdvertisedAndReceived");
13455 else if (
13456 CHECK_FLAG(
13457 p->af_cap[afi]
13458 [safi],
13459 PEER_CAP_ADDPATH_AF_TX_ADV))
13460 json_object_boolean_true_add(
13461 json_sub,
13462 "txAdvertised");
13463 else if (
13464 CHECK_FLAG(
13465 p->af_cap[afi]
13466 [safi],
13467 PEER_CAP_ADDPATH_AF_TX_RCV))
13468 json_object_boolean_true_add(
13469 json_sub,
13470 "txReceived");
13471 }
13472
13473 if (CHECK_FLAG(
13474 p->af_cap[afi][safi],
13475 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13476 CHECK_FLAG(
13477 p->af_cap[afi][safi],
13478 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13479 if (CHECK_FLAG(
13480 p->af_cap[afi]
13481 [safi],
13482 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13483 CHECK_FLAG(
13484 p->af_cap[afi]
13485 [safi],
13486 PEER_CAP_ADDPATH_AF_RX_RCV))
13487 json_object_boolean_true_add(
13488 json_sub,
13489 "rxAdvertisedAndReceived");
13490 else if (
13491 CHECK_FLAG(
13492 p->af_cap[afi]
13493 [safi],
13494 PEER_CAP_ADDPATH_AF_RX_ADV))
13495 json_object_boolean_true_add(
13496 json_sub,
13497 "rxAdvertised");
13498 else if (
13499 CHECK_FLAG(
13500 p->af_cap[afi]
13501 [safi],
13502 PEER_CAP_ADDPATH_AF_RX_RCV))
13503 json_object_boolean_true_add(
13504 json_sub,
13505 "rxReceived");
13506 }
13507
13508 if (CHECK_FLAG(
13509 p->af_cap[afi][safi],
13510 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13511 CHECK_FLAG(
13512 p->af_cap[afi][safi],
13513 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13514 CHECK_FLAG(
13515 p->af_cap[afi][safi],
13516 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13517 CHECK_FLAG(
13518 p->af_cap[afi][safi],
13519 PEER_CAP_ADDPATH_AF_RX_RCV))
13520 json_object_object_add(
13521 json_add, print_store,
13522 json_sub);
13523 else
13524 json_object_free(json_sub);
13525 }
13526
13527 json_object_object_add(json_cap, "addPath",
13528 json_add);
13529 }
13530
13531 /* Dynamic */
13532 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13533 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13534 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13535 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13536 json_object_string_add(
13537 json_cap, "dynamic",
13538 "advertisedAndReceived");
13539 else if (CHECK_FLAG(p->cap,
13540 PEER_CAP_DYNAMIC_ADV))
13541 json_object_string_add(json_cap,
13542 "dynamic",
13543 "advertised");
13544 else if (CHECK_FLAG(p->cap,
13545 PEER_CAP_DYNAMIC_RCV))
13546 json_object_string_add(json_cap,
13547 "dynamic",
13548 "received");
13549 }
13550
13551 /* Role */
13552 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13553 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13554 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13555 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13556 json_object_string_add(
13557 json_cap, "role",
13558 "advertisedAndReceived");
13559 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13560 json_object_string_add(json_cap, "role",
13561 "advertised");
13562 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13563 json_object_string_add(json_cap, "role",
13564 "received");
13565 }
13566
13567 /* Extended nexthop */
13568 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13569 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13570 json_object *json_nxt = NULL;
13571 const char *print_store;
13572
13573
13574 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13575 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13576 json_object_string_add(
13577 json_cap, "extendedNexthop",
13578 "advertisedAndReceived");
13579 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13580 json_object_string_add(
13581 json_cap, "extendedNexthop",
13582 "advertised");
13583 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13584 json_object_string_add(
13585 json_cap, "extendedNexthop",
13586 "received");
13587
13588 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13589 json_nxt = json_object_new_object();
13590
13591 for (safi = SAFI_UNICAST;
13592 safi < SAFI_MAX; safi++) {
13593 if (CHECK_FLAG(
13594 p->af_cap[AFI_IP]
13595 [safi],
13596 PEER_CAP_ENHE_AF_RCV)) {
13597 print_store =
13598 get_afi_safi_str(
13599 AFI_IP,
13600 safi,
13601 true);
13602 json_object_string_add(
13603 json_nxt,
13604 print_store,
13605 "recieved"); /* misspelled for compatibility */
13606 }
13607 }
13608 json_object_object_add(
13609 json_cap,
13610 "extendedNexthopFamililesByPeer",
13611 json_nxt);
13612 }
13613 }
13614
13615 /* Long-lived Graceful Restart */
13616 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13617 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13618 json_object *json_llgr = NULL;
13619 const char *afi_safi_str;
13620
13621 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13622 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13623 json_object_string_add(
13624 json_cap,
13625 "longLivedGracefulRestart",
13626 "advertisedAndReceived");
13627 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13628 json_object_string_add(
13629 json_cap,
13630 "longLivedGracefulRestart",
13631 "advertised");
13632 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13633 json_object_string_add(
13634 json_cap,
13635 "longLivedGracefulRestart",
13636 "received");
13637
13638 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13639 json_llgr = json_object_new_object();
13640
13641 FOREACH_AFI_SAFI (afi, safi) {
13642 if (CHECK_FLAG(
13643 p->af_cap[afi]
13644 [safi],
13645 PEER_CAP_ENHE_AF_RCV)) {
13646 afi_safi_str =
13647 get_afi_safi_str(
13648 afi,
13649 safi,
13650 true);
13651 json_object_string_add(
13652 json_llgr,
13653 afi_safi_str,
13654 "received");
13655 }
13656 }
13657 json_object_object_add(
13658 json_cap,
13659 "longLivedGracefulRestartByPeer",
13660 json_llgr);
13661 }
13662 }
13663
13664 /* Route Refresh */
13665 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13666 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13667 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13668 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13669 (CHECK_FLAG(p->cap,
13670 PEER_CAP_REFRESH_NEW_RCV) ||
13671 CHECK_FLAG(p->cap,
13672 PEER_CAP_REFRESH_OLD_RCV))) {
13673 if (CHECK_FLAG(
13674 p->cap,
13675 PEER_CAP_REFRESH_OLD_RCV) &&
13676 CHECK_FLAG(
13677 p->cap,
13678 PEER_CAP_REFRESH_NEW_RCV))
13679 json_object_string_add(
13680 json_cap,
13681 "routeRefresh",
13682 "advertisedAndReceivedOldNew");
13683 else {
13684 if (CHECK_FLAG(
13685 p->cap,
13686 PEER_CAP_REFRESH_OLD_RCV))
13687 json_object_string_add(
13688 json_cap,
13689 "routeRefresh",
13690 "advertisedAndReceivedOld");
13691 else
13692 json_object_string_add(
13693 json_cap,
13694 "routeRefresh",
13695 "advertisedAndReceivedNew");
13696 }
13697 } else if (CHECK_FLAG(p->cap,
13698 PEER_CAP_REFRESH_ADV))
13699 json_object_string_add(json_cap,
13700 "routeRefresh",
13701 "advertised");
13702 else if (CHECK_FLAG(p->cap,
13703 PEER_CAP_REFRESH_NEW_RCV) ||
13704 CHECK_FLAG(p->cap,
13705 PEER_CAP_REFRESH_OLD_RCV))
13706 json_object_string_add(json_cap,
13707 "routeRefresh",
13708 "received");
13709 }
13710
13711 /* Enhanced Route Refresh */
13712 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13713 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13714 if (CHECK_FLAG(p->cap,
13715 PEER_CAP_ENHANCED_RR_ADV) &&
13716 CHECK_FLAG(p->cap,
13717 PEER_CAP_ENHANCED_RR_RCV))
13718 json_object_string_add(
13719 json_cap,
13720 "enhancedRouteRefresh",
13721 "advertisedAndReceived");
13722 else if (CHECK_FLAG(p->cap,
13723 PEER_CAP_ENHANCED_RR_ADV))
13724 json_object_string_add(
13725 json_cap,
13726 "enhancedRouteRefresh",
13727 "advertised");
13728 else if (CHECK_FLAG(p->cap,
13729 PEER_CAP_ENHANCED_RR_RCV))
13730 json_object_string_add(
13731 json_cap,
13732 "enhancedRouteRefresh",
13733 "received");
13734 }
13735
13736 /* Multiprotocol Extensions */
13737 json_object *json_multi = NULL;
13738
13739 json_multi = json_object_new_object();
13740
13741 FOREACH_AFI_SAFI (afi, safi) {
13742 if (p->afc_adv[afi][safi] ||
13743 p->afc_recv[afi][safi]) {
13744 json_object *json_exten = NULL;
13745 json_exten = json_object_new_object();
13746
13747 if (p->afc_adv[afi][safi] &&
13748 p->afc_recv[afi][safi])
13749 json_object_boolean_true_add(
13750 json_exten,
13751 "advertisedAndReceived");
13752 else if (p->afc_adv[afi][safi])
13753 json_object_boolean_true_add(
13754 json_exten,
13755 "advertised");
13756 else if (p->afc_recv[afi][safi])
13757 json_object_boolean_true_add(
13758 json_exten, "received");
13759
13760 json_object_object_add(
13761 json_multi,
13762 get_afi_safi_str(afi, safi,
13763 true),
13764 json_exten);
13765 }
13766 }
13767 json_object_object_add(json_cap,
13768 "multiprotocolExtensions",
13769 json_multi);
13770
13771 /* Hostname capabilities */
13772 json_object *json_hname = NULL;
13773
13774 json_hname = json_object_new_object();
13775
13776 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13777 json_object_string_add(
13778 json_hname, "advHostName",
13779 bgp->peer_self->hostname
13780 ? bgp->peer_self->hostname
13781 : "n/a");
13782 json_object_string_add(
13783 json_hname, "advDomainName",
13784 bgp->peer_self->domainname
13785 ? bgp->peer_self->domainname
13786 : "n/a");
13787 }
13788
13789
13790 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13791 json_object_string_add(
13792 json_hname, "rcvHostName",
13793 p->hostname ? p->hostname : "n/a");
13794 json_object_string_add(
13795 json_hname, "rcvDomainName",
13796 p->domainname ? p->domainname : "n/a");
13797 }
13798
13799 json_object_object_add(json_cap, "hostName",
13800 json_hname);
13801
13802 /* Graceful Restart */
13803 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13804 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13805 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13806 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13807 json_object_string_add(
13808 json_cap, "gracefulRestart",
13809 "advertisedAndReceived");
13810 else if (CHECK_FLAG(p->cap,
13811 PEER_CAP_RESTART_ADV))
13812 json_object_string_add(
13813 json_cap,
13814 "gracefulRestartCapability",
13815 "advertised");
13816 else if (CHECK_FLAG(p->cap,
13817 PEER_CAP_RESTART_RCV))
13818 json_object_string_add(
13819 json_cap,
13820 "gracefulRestartCapability",
13821 "received");
13822
13823 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13824 int restart_af_count = 0;
13825 json_object *json_restart = NULL;
13826 json_restart = json_object_new_object();
13827
13828 json_object_int_add(
13829 json_cap,
13830 "gracefulRestartRemoteTimerMsecs",
13831 p->v_gr_restart * 1000);
13832
13833 FOREACH_AFI_SAFI (afi, safi) {
13834 if (CHECK_FLAG(
13835 p->af_cap[afi]
13836 [safi],
13837 PEER_CAP_RESTART_AF_RCV)) {
13838 json_object *json_sub =
13839 NULL;
13840 json_sub =
13841 json_object_new_object();
13842
13843 if (CHECK_FLAG(
13844 p->af_cap
13845 [afi]
13846 [safi],
13847 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13848 json_object_boolean_true_add(
13849 json_sub,
13850 "preserved");
13851 restart_af_count++;
13852 json_object_object_add(
13853 json_restart,
13854 get_afi_safi_str(
13855 afi,
13856 safi,
13857 true),
13858 json_sub);
13859 }
13860 }
13861 if (!restart_af_count) {
13862 json_object_string_add(
13863 json_cap,
13864 "addressFamiliesByPeer",
13865 "none");
13866 json_object_free(json_restart);
13867 } else
13868 json_object_object_add(
13869 json_cap,
13870 "addressFamiliesByPeer",
13871 json_restart);
13872 }
13873 }
13874 json_object_object_add(
13875 json_neigh, "neighborCapabilities", json_cap);
13876 } else {
13877 vty_out(vty, " Neighbor capabilities:\n");
13878
13879 /* AS4 */
13880 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13881 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13882 vty_out(vty, " 4 Byte AS:");
13883 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13884 vty_out(vty, " advertised");
13885 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13886 vty_out(vty, " %sreceived",
13887 CHECK_FLAG(p->cap,
13888 PEER_CAP_AS4_ADV)
13889 ? "and "
13890 : "");
13891 vty_out(vty, "\n");
13892 }
13893
13894 /* Extended Message Support */
13895 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13896 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13897 vty_out(vty, " Extended Message:");
13898 if (CHECK_FLAG(p->cap,
13899 PEER_CAP_EXTENDED_MESSAGE_ADV))
13900 vty_out(vty, " advertised");
13901 if (CHECK_FLAG(p->cap,
13902 PEER_CAP_EXTENDED_MESSAGE_RCV))
13903 vty_out(vty, " %sreceived",
13904 CHECK_FLAG(
13905 p->cap,
13906 PEER_CAP_EXTENDED_MESSAGE_ADV)
13907 ? "and "
13908 : "");
13909 vty_out(vty, "\n");
13910 }
13911
13912 /* AddPath */
13913 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13914 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13915 vty_out(vty, " AddPath:\n");
13916
13917 FOREACH_AFI_SAFI (afi, safi) {
13918 if (CHECK_FLAG(
13919 p->af_cap[afi][safi],
13920 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13921 CHECK_FLAG(
13922 p->af_cap[afi][safi],
13923 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13924 vty_out(vty, " %s: TX ",
13925 get_afi_safi_str(
13926 afi, safi,
13927 false));
13928
13929 if (CHECK_FLAG(
13930 p->af_cap[afi]
13931 [safi],
13932 PEER_CAP_ADDPATH_AF_TX_ADV))
13933 vty_out(vty,
13934 "advertised");
13935
13936 if (CHECK_FLAG(
13937 p->af_cap[afi]
13938 [safi],
13939 PEER_CAP_ADDPATH_AF_TX_RCV))
13940 vty_out(vty,
13941 "%sreceived",
13942 CHECK_FLAG(
13943 p->af_cap
13944 [afi]
13945 [safi],
13946 PEER_CAP_ADDPATH_AF_TX_ADV)
13947 ? " and "
13948 : "");
13949
13950 vty_out(vty, "\n");
13951 }
13952
13953 if (CHECK_FLAG(
13954 p->af_cap[afi][safi],
13955 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13956 CHECK_FLAG(
13957 p->af_cap[afi][safi],
13958 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13959 vty_out(vty, " %s: RX ",
13960 get_afi_safi_str(
13961 afi, safi,
13962 false));
13963
13964 if (CHECK_FLAG(
13965 p->af_cap[afi]
13966 [safi],
13967 PEER_CAP_ADDPATH_AF_RX_ADV))
13968 vty_out(vty,
13969 "advertised");
13970
13971 if (CHECK_FLAG(
13972 p->af_cap[afi]
13973 [safi],
13974 PEER_CAP_ADDPATH_AF_RX_RCV))
13975 vty_out(vty,
13976 "%sreceived",
13977 CHECK_FLAG(
13978 p->af_cap
13979 [afi]
13980 [safi],
13981 PEER_CAP_ADDPATH_AF_RX_ADV)
13982 ? " and "
13983 : "");
13984
13985 vty_out(vty, "\n");
13986 }
13987 }
13988 }
13989
13990 /* Dynamic */
13991 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13992 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13993 vty_out(vty, " Dynamic:");
13994 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13995 vty_out(vty, " advertised");
13996 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13997 vty_out(vty, " %sreceived",
13998 CHECK_FLAG(p->cap,
13999 PEER_CAP_DYNAMIC_ADV)
14000 ? "and "
14001 : "");
14002 vty_out(vty, "\n");
14003 }
14004
14005 /* Role */
14006 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14007 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14008 vty_out(vty, " Role:");
14009 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14010 vty_out(vty, " advertised");
14011 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14012 vty_out(vty, " %sreceived",
14013 CHECK_FLAG(p->cap,
14014 PEER_CAP_ROLE_ADV)
14015 ? "and "
14016 : "");
14017 vty_out(vty, "\n");
14018 }
14019
14020 /* Extended nexthop */
14021 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14022 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14023 vty_out(vty, " Extended nexthop:");
14024 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14025 vty_out(vty, " advertised");
14026 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14027 vty_out(vty, " %sreceived",
14028 CHECK_FLAG(p->cap,
14029 PEER_CAP_ENHE_ADV)
14030 ? "and "
14031 : "");
14032 vty_out(vty, "\n");
14033
14034 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
14035 vty_out(vty,
14036 " Address families by peer:\n ");
14037 for (safi = SAFI_UNICAST;
14038 safi < SAFI_MAX; safi++)
14039 if (CHECK_FLAG(
14040 p->af_cap[AFI_IP]
14041 [safi],
14042 PEER_CAP_ENHE_AF_RCV))
14043 vty_out(vty,
14044 " %s\n",
14045 get_afi_safi_str(
14046 AFI_IP,
14047 safi,
14048 false));
14049 }
14050 }
14051
14052 /* Long-lived Graceful Restart */
14053 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14054 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14055 vty_out(vty,
14056 " Long-lived Graceful Restart:");
14057 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14058 vty_out(vty, " advertised");
14059 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14060 vty_out(vty, " %sreceived",
14061 CHECK_FLAG(p->cap,
14062 PEER_CAP_LLGR_ADV)
14063 ? "and "
14064 : "");
14065 vty_out(vty, "\n");
14066
14067 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
14068 vty_out(vty,
14069 " Address families by peer:\n");
14070 FOREACH_AFI_SAFI (afi, safi)
14071 if (CHECK_FLAG(
14072 p->af_cap[afi]
14073 [safi],
14074 PEER_CAP_LLGR_AF_RCV))
14075 vty_out(vty,
14076 " %s\n",
14077 get_afi_safi_str(
14078 afi,
14079 safi,
14080 false));
14081 }
14082 }
14083
14084 /* Route Refresh */
14085 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14086 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14087 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14088 vty_out(vty, " Route refresh:");
14089 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14090 vty_out(vty, " advertised");
14091 if (CHECK_FLAG(p->cap,
14092 PEER_CAP_REFRESH_NEW_RCV) ||
14093 CHECK_FLAG(p->cap,
14094 PEER_CAP_REFRESH_OLD_RCV))
14095 vty_out(vty, " %sreceived(%s)",
14096 CHECK_FLAG(p->cap,
14097 PEER_CAP_REFRESH_ADV)
14098 ? "and "
14099 : "",
14100 (CHECK_FLAG(
14101 p->cap,
14102 PEER_CAP_REFRESH_OLD_RCV) &&
14103 CHECK_FLAG(
14104 p->cap,
14105 PEER_CAP_REFRESH_NEW_RCV))
14106 ? "old & new"
14107 : CHECK_FLAG(
14108 p->cap,
14109 PEER_CAP_REFRESH_OLD_RCV)
14110 ? "old"
14111 : "new");
14112
14113 vty_out(vty, "\n");
14114 }
14115
14116 /* Enhanced Route Refresh */
14117 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14118 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14119 vty_out(vty, " Enhanced Route Refresh:");
14120 if (CHECK_FLAG(p->cap,
14121 PEER_CAP_ENHANCED_RR_ADV))
14122 vty_out(vty, " advertised");
14123 if (CHECK_FLAG(p->cap,
14124 PEER_CAP_ENHANCED_RR_RCV))
14125 vty_out(vty, " %sreceived",
14126 CHECK_FLAG(p->cap,
14127 PEER_CAP_REFRESH_ADV)
14128 ? "and "
14129 : "");
14130 vty_out(vty, "\n");
14131 }
14132
14133 /* Multiprotocol Extensions */
14134 FOREACH_AFI_SAFI (afi, safi)
14135 if (p->afc_adv[afi][safi] ||
14136 p->afc_recv[afi][safi]) {
14137 vty_out(vty, " Address Family %s:",
14138 get_afi_safi_str(afi, safi,
14139 false));
14140 if (p->afc_adv[afi][safi])
14141 vty_out(vty, " advertised");
14142 if (p->afc_recv[afi][safi])
14143 vty_out(vty, " %sreceived",
14144 p->afc_adv[afi][safi]
14145 ? "and "
14146 : "");
14147 vty_out(vty, "\n");
14148 }
14149
14150 /* Hostname capability */
14151 vty_out(vty, " Hostname Capability:");
14152
14153 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14154 vty_out(vty,
14155 " advertised (name: %s,domain name: %s)",
14156 bgp->peer_self->hostname
14157 ? bgp->peer_self->hostname
14158 : "n/a",
14159 bgp->peer_self->domainname
14160 ? bgp->peer_self->domainname
14161 : "n/a");
14162 } else {
14163 vty_out(vty, " not advertised");
14164 }
14165
14166 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14167 vty_out(vty,
14168 " received (name: %s,domain name: %s)",
14169 p->hostname ? p->hostname : "n/a",
14170 p->domainname ? p->domainname : "n/a");
14171 } else {
14172 vty_out(vty, " not received");
14173 }
14174
14175 vty_out(vty, "\n");
14176
14177 /* Graceful Restart */
14178 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14179 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14180 vty_out(vty,
14181 " Graceful Restart Capability:");
14182 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14183 vty_out(vty, " advertised");
14184 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14185 vty_out(vty, " %sreceived",
14186 CHECK_FLAG(p->cap,
14187 PEER_CAP_RESTART_ADV)
14188 ? "and "
14189 : "");
14190 vty_out(vty, "\n");
14191
14192 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14193 int restart_af_count = 0;
14194
14195 vty_out(vty,
14196 " Remote Restart timer is %d seconds\n",
14197 p->v_gr_restart);
14198 vty_out(vty,
14199 " Address families by peer:\n ");
14200
14201 FOREACH_AFI_SAFI (afi, safi)
14202 if (CHECK_FLAG(
14203 p->af_cap[afi]
14204 [safi],
14205 PEER_CAP_RESTART_AF_RCV)) {
14206 vty_out(vty, "%s%s(%s)",
14207 restart_af_count
14208 ? ", "
14209 : "",
14210 get_afi_safi_str(
14211 afi,
14212 safi,
14213 false),
14214 CHECK_FLAG(
14215 p->af_cap
14216 [afi]
14217 [safi],
14218 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14219 ? "preserved"
14220 : "not preserved");
14221 restart_af_count++;
14222 }
14223 if (!restart_af_count)
14224 vty_out(vty, "none");
14225 vty_out(vty, "\n");
14226 }
14227 } /* Graceful Restart */
14228 }
14229 }
14230
14231 /* graceful restart information */
14232 json_object *json_grace = NULL;
14233 json_object *json_grace_send = NULL;
14234 json_object *json_grace_recv = NULL;
14235 int eor_send_af_count = 0;
14236 int eor_receive_af_count = 0;
14237
14238 if (use_json) {
14239 json_grace = json_object_new_object();
14240 json_grace_send = json_object_new_object();
14241 json_grace_recv = json_object_new_object();
14242
14243 if ((peer_established(p)) &&
14244 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14245 FOREACH_AFI_SAFI (afi, safi) {
14246 if (CHECK_FLAG(p->af_sflags[afi][safi],
14247 PEER_STATUS_EOR_SEND)) {
14248 json_object_boolean_true_add(
14249 json_grace_send,
14250 get_afi_safi_str(afi, safi,
14251 true));
14252 eor_send_af_count++;
14253 }
14254 }
14255 FOREACH_AFI_SAFI (afi, safi) {
14256 if (CHECK_FLAG(p->af_sflags[afi][safi],
14257 PEER_STATUS_EOR_RECEIVED)) {
14258 json_object_boolean_true_add(
14259 json_grace_recv,
14260 get_afi_safi_str(afi, safi,
14261 true));
14262 eor_receive_af_count++;
14263 }
14264 }
14265 }
14266 json_object_object_add(json_grace, "endOfRibSend",
14267 json_grace_send);
14268 json_object_object_add(json_grace, "endOfRibRecv",
14269 json_grace_recv);
14270
14271
14272 if (p->t_gr_restart)
14273 json_object_int_add(
14274 json_grace, "gracefulRestartTimerMsecs",
14275 thread_timer_remain_second(p->t_gr_restart) *
14276 1000);
14277
14278 if (p->t_gr_stale)
14279 json_object_int_add(
14280 json_grace, "gracefulStalepathTimerMsecs",
14281 thread_timer_remain_second(p->t_gr_stale) *
14282 1000);
14283 /* more gr info in new format */
14284 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14285 json_object_object_add(json_neigh, "gracefulRestartInfo",
14286 json_grace);
14287 } else {
14288 vty_out(vty, " Graceful restart information:\n");
14289 if ((peer_established(p)) &&
14290 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14291
14292 vty_out(vty, " End-of-RIB send: ");
14293 FOREACH_AFI_SAFI (afi, safi) {
14294 if (CHECK_FLAG(p->af_sflags[afi][safi],
14295 PEER_STATUS_EOR_SEND)) {
14296 vty_out(vty, "%s%s",
14297 eor_send_af_count ? ", " : "",
14298 get_afi_safi_str(afi, safi,
14299 false));
14300 eor_send_af_count++;
14301 }
14302 }
14303 vty_out(vty, "\n");
14304 vty_out(vty, " End-of-RIB received: ");
14305 FOREACH_AFI_SAFI (afi, safi) {
14306 if (CHECK_FLAG(p->af_sflags[afi][safi],
14307 PEER_STATUS_EOR_RECEIVED)) {
14308 vty_out(vty, "%s%s",
14309 eor_receive_af_count ? ", "
14310 : "",
14311 get_afi_safi_str(afi, safi,
14312 false));
14313 eor_receive_af_count++;
14314 }
14315 }
14316 vty_out(vty, "\n");
14317 }
14318
14319 if (p->t_gr_restart)
14320 vty_out(vty,
14321 " The remaining time of restart timer is %ld\n",
14322 thread_timer_remain_second(p->t_gr_restart));
14323
14324 if (p->t_gr_stale)
14325 vty_out(vty,
14326 " The remaining time of stalepath timer is %ld\n",
14327 thread_timer_remain_second(p->t_gr_stale));
14328
14329 /* more gr info in new format */
14330 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14331 }
14332
14333 if (use_json) {
14334 json_object *json_stat = NULL;
14335 json_stat = json_object_new_object();
14336 /* Packet counts. */
14337
14338 atomic_size_t outq_count, inq_count;
14339 outq_count = atomic_load_explicit(&p->obuf->count,
14340 memory_order_relaxed);
14341 inq_count = atomic_load_explicit(&p->ibuf->count,
14342 memory_order_relaxed);
14343
14344 json_object_int_add(json_stat, "depthInq",
14345 (unsigned long)inq_count);
14346 json_object_int_add(json_stat, "depthOutq",
14347 (unsigned long)outq_count);
14348 json_object_int_add(json_stat, "opensSent",
14349 atomic_load_explicit(&p->open_out,
14350 memory_order_relaxed));
14351 json_object_int_add(json_stat, "opensRecv",
14352 atomic_load_explicit(&p->open_in,
14353 memory_order_relaxed));
14354 json_object_int_add(json_stat, "notificationsSent",
14355 atomic_load_explicit(&p->notify_out,
14356 memory_order_relaxed));
14357 json_object_int_add(json_stat, "notificationsRecv",
14358 atomic_load_explicit(&p->notify_in,
14359 memory_order_relaxed));
14360 json_object_int_add(json_stat, "updatesSent",
14361 atomic_load_explicit(&p->update_out,
14362 memory_order_relaxed));
14363 json_object_int_add(json_stat, "updatesRecv",
14364 atomic_load_explicit(&p->update_in,
14365 memory_order_relaxed));
14366 json_object_int_add(json_stat, "keepalivesSent",
14367 atomic_load_explicit(&p->keepalive_out,
14368 memory_order_relaxed));
14369 json_object_int_add(json_stat, "keepalivesRecv",
14370 atomic_load_explicit(&p->keepalive_in,
14371 memory_order_relaxed));
14372 json_object_int_add(json_stat, "routeRefreshSent",
14373 atomic_load_explicit(&p->refresh_out,
14374 memory_order_relaxed));
14375 json_object_int_add(json_stat, "routeRefreshRecv",
14376 atomic_load_explicit(&p->refresh_in,
14377 memory_order_relaxed));
14378 json_object_int_add(json_stat, "capabilitySent",
14379 atomic_load_explicit(&p->dynamic_cap_out,
14380 memory_order_relaxed));
14381 json_object_int_add(json_stat, "capabilityRecv",
14382 atomic_load_explicit(&p->dynamic_cap_in,
14383 memory_order_relaxed));
14384 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14385 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14386 json_object_object_add(json_neigh, "messageStats", json_stat);
14387 } else {
14388 atomic_size_t outq_count, inq_count, open_out, open_in,
14389 notify_out, notify_in, update_out, update_in,
14390 keepalive_out, keepalive_in, refresh_out, refresh_in,
14391 dynamic_cap_out, dynamic_cap_in;
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 open_out = atomic_load_explicit(&p->open_out,
14397 memory_order_relaxed);
14398 open_in =
14399 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14400 notify_out = atomic_load_explicit(&p->notify_out,
14401 memory_order_relaxed);
14402 notify_in = atomic_load_explicit(&p->notify_in,
14403 memory_order_relaxed);
14404 update_out = atomic_load_explicit(&p->update_out,
14405 memory_order_relaxed);
14406 update_in = atomic_load_explicit(&p->update_in,
14407 memory_order_relaxed);
14408 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14409 memory_order_relaxed);
14410 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14411 memory_order_relaxed);
14412 refresh_out = atomic_load_explicit(&p->refresh_out,
14413 memory_order_relaxed);
14414 refresh_in = atomic_load_explicit(&p->refresh_in,
14415 memory_order_relaxed);
14416 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14417 memory_order_relaxed);
14418 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14419 memory_order_relaxed);
14420
14421 /* Packet counts. */
14422 vty_out(vty, " Message statistics:\n");
14423 vty_out(vty, " Inq depth is %zu\n", inq_count);
14424 vty_out(vty, " Outq depth is %zu\n", outq_count);
14425 vty_out(vty, " Sent Rcvd\n");
14426 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14427 open_in);
14428 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14429 notify_in);
14430 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14431 update_in);
14432 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14433 keepalive_in);
14434 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14435 refresh_in);
14436 vty_out(vty, " Capability: %10zu %10zu\n",
14437 dynamic_cap_out, dynamic_cap_in);
14438 vty_out(vty, " Total: %10u %10u\n",
14439 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14440 }
14441
14442 if (use_json) {
14443 /* advertisement-interval */
14444 json_object_int_add(json_neigh,
14445 "minBtwnAdvertisementRunsTimerMsecs",
14446 p->v_routeadv * 1000);
14447
14448 /* Update-source. */
14449 if (p->update_if || p->update_source) {
14450 if (p->update_if)
14451 json_object_string_add(json_neigh,
14452 "updateSource",
14453 p->update_if);
14454 else if (p->update_source)
14455 json_object_string_addf(json_neigh,
14456 "updateSource", "%pSU",
14457 p->update_source);
14458 }
14459 } else {
14460 /* advertisement-interval */
14461 vty_out(vty,
14462 " Minimum time between advertisement runs is %d seconds\n",
14463 p->v_routeadv);
14464
14465 /* Update-source. */
14466 if (p->update_if || p->update_source) {
14467 vty_out(vty, " Update source is ");
14468 if (p->update_if)
14469 vty_out(vty, "%s", p->update_if);
14470 else if (p->update_source)
14471 vty_out(vty, "%pSU", p->update_source);
14472 vty_out(vty, "\n");
14473 }
14474
14475 vty_out(vty, "\n");
14476 }
14477
14478 /* Address Family Information */
14479 json_object *json_hold = NULL;
14480
14481 if (use_json)
14482 json_hold = json_object_new_object();
14483
14484 FOREACH_AFI_SAFI (afi, safi)
14485 if (p->afc[afi][safi])
14486 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14487 json_hold);
14488
14489 if (use_json) {
14490 json_object_object_add(json_neigh, "addressFamilyInfo",
14491 json_hold);
14492 json_object_int_add(json_neigh, "connectionsEstablished",
14493 p->established);
14494 json_object_int_add(json_neigh, "connectionsDropped",
14495 p->dropped);
14496 } else
14497 vty_out(vty, " Connections established %d; dropped %d\n",
14498 p->established, p->dropped);
14499
14500 if (!p->last_reset) {
14501 if (use_json)
14502 json_object_string_add(json_neigh, "lastReset",
14503 "never");
14504 else
14505 vty_out(vty, " Last reset never\n");
14506 } else {
14507 if (use_json) {
14508 time_t uptime;
14509 struct tm tm;
14510
14511 uptime = monotime(NULL);
14512 uptime -= p->resettime;
14513 gmtime_r(&uptime, &tm);
14514
14515 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14516 (tm.tm_sec * 1000)
14517 + (tm.tm_min * 60000)
14518 + (tm.tm_hour * 3600000));
14519 bgp_show_peer_reset(NULL, p, json_neigh, true);
14520 } else {
14521 vty_out(vty, " Last reset %s, ",
14522 peer_uptime(p->resettime, timebuf,
14523 BGP_UPTIME_LEN, 0, NULL));
14524
14525 bgp_show_peer_reset(vty, p, NULL, false);
14526 if (p->last_reset_cause_size) {
14527 msg = p->last_reset_cause;
14528 vty_out(vty,
14529 " Message received that caused BGP to send a NOTIFICATION:\n ");
14530 for (i = 1; i <= p->last_reset_cause_size;
14531 i++) {
14532 vty_out(vty, "%02X", *msg++);
14533
14534 if (i != p->last_reset_cause_size) {
14535 if (i % 16 == 0) {
14536 vty_out(vty, "\n ");
14537 } else if (i % 4 == 0) {
14538 vty_out(vty, " ");
14539 }
14540 }
14541 }
14542 vty_out(vty, "\n");
14543 }
14544 }
14545 }
14546
14547 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14548 if (use_json)
14549 json_object_boolean_true_add(json_neigh,
14550 "prefixesConfigExceedMax");
14551 else
14552 vty_out(vty,
14553 " Peer had exceeded the max. no. of prefixes configured.\n");
14554
14555 if (p->t_pmax_restart) {
14556 if (use_json) {
14557 json_object_boolean_true_add(
14558 json_neigh, "reducePrefixNumFrom");
14559 json_object_int_add(json_neigh,
14560 "restartInTimerMsec",
14561 thread_timer_remain_second(
14562 p->t_pmax_restart)
14563 * 1000);
14564 } else
14565 vty_out(vty,
14566 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14567 p->host, thread_timer_remain_second(
14568 p->t_pmax_restart));
14569 } else {
14570 if (use_json)
14571 json_object_boolean_true_add(
14572 json_neigh,
14573 "reducePrefixNumAndClearIpBgp");
14574 else
14575 vty_out(vty,
14576 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14577 p->host);
14578 }
14579 }
14580
14581 /* EBGP Multihop and GTSM */
14582 if (p->sort != BGP_PEER_IBGP) {
14583 if (use_json) {
14584 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14585 json_object_int_add(json_neigh,
14586 "externalBgpNbrMaxHopsAway",
14587 p->gtsm_hops);
14588 else
14589 json_object_int_add(json_neigh,
14590 "externalBgpNbrMaxHopsAway",
14591 p->ttl);
14592 } else {
14593 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14594 vty_out(vty,
14595 " External BGP neighbor may be up to %d hops away.\n",
14596 p->gtsm_hops);
14597 else
14598 vty_out(vty,
14599 " External BGP neighbor may be up to %d hops away.\n",
14600 p->ttl);
14601 }
14602 } else {
14603 if (use_json) {
14604 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14605 json_object_int_add(json_neigh,
14606 "internalBgpNbrMaxHopsAway",
14607 p->gtsm_hops);
14608 else
14609 json_object_int_add(json_neigh,
14610 "internalBgpNbrMaxHopsAway",
14611 p->ttl);
14612 } else {
14613 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14614 vty_out(vty,
14615 " Internal BGP neighbor may be up to %d hops away.\n",
14616 p->gtsm_hops);
14617 else
14618 vty_out(vty,
14619 " Internal BGP neighbor may be up to %d hops away.\n",
14620 p->ttl);
14621 }
14622 }
14623
14624 /* Local address. */
14625 if (p->su_local) {
14626 if (use_json) {
14627 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14628 p->su_local);
14629 json_object_int_add(json_neigh, "portLocal",
14630 ntohs(p->su_local->sin.sin_port));
14631 } else
14632 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14633 p->su_local, ntohs(p->su_local->sin.sin_port));
14634 } else {
14635 if (use_json) {
14636 json_object_string_add(json_neigh, "hostLocal",
14637 "Unknown");
14638 json_object_int_add(json_neigh, "portLocal", -1);
14639 }
14640 }
14641
14642 /* Remote address. */
14643 if (p->su_remote) {
14644 if (use_json) {
14645 json_object_string_addf(json_neigh, "hostForeign",
14646 "%pSU", p->su_remote);
14647 json_object_int_add(json_neigh, "portForeign",
14648 ntohs(p->su_remote->sin.sin_port));
14649 } else
14650 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14651 p->su_remote,
14652 ntohs(p->su_remote->sin.sin_port));
14653 } else {
14654 if (use_json) {
14655 json_object_string_add(json_neigh, "hostForeign",
14656 "Unknown");
14657 json_object_int_add(json_neigh, "portForeign", -1);
14658 }
14659 }
14660
14661 /* Nexthop display. */
14662 if (p->su_local) {
14663 if (use_json) {
14664 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14665 &p->nexthop.v4);
14666 json_object_string_addf(json_neigh, "nexthopGlobal",
14667 "%pI6", &p->nexthop.v6_global);
14668 json_object_string_addf(json_neigh, "nexthopLocal",
14669 "%pI6", &p->nexthop.v6_local);
14670 if (p->shared_network)
14671 json_object_string_add(json_neigh,
14672 "bgpConnection",
14673 "sharedNetwork");
14674 else
14675 json_object_string_add(json_neigh,
14676 "bgpConnection",
14677 "nonSharedNetwork");
14678 } else {
14679 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14680 vty_out(vty, "Nexthop global: %pI6\n",
14681 &p->nexthop.v6_global);
14682 vty_out(vty, "Nexthop local: %pI6\n",
14683 &p->nexthop.v6_local);
14684 vty_out(vty, "BGP connection: %s\n",
14685 p->shared_network ? "shared network"
14686 : "non shared network");
14687 }
14688 } else {
14689 if (use_json) {
14690 json_object_string_add(json_neigh, "nexthop",
14691 "Unknown");
14692 json_object_string_add(json_neigh, "nexthopGlobal",
14693 "Unknown");
14694 json_object_string_add(json_neigh, "nexthopLocal",
14695 "Unknown");
14696 json_object_string_add(json_neigh, "bgpConnection",
14697 "Unknown");
14698 }
14699 }
14700
14701 /* Timer information. */
14702 if (use_json) {
14703 json_object_int_add(json_neigh, "connectRetryTimer",
14704 p->v_connect);
14705 if (peer_established(p)) {
14706 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14707 p->rtt);
14708 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14709 json_object_int_add(json_neigh,
14710 "shutdownRttInMsecs",
14711 p->rtt_expected);
14712 json_object_int_add(json_neigh,
14713 "shutdownRttAfterCount",
14714 p->rtt_keepalive_rcv);
14715 }
14716 }
14717 if (p->t_start)
14718 json_object_int_add(
14719 json_neigh, "nextStartTimerDueInMsecs",
14720 thread_timer_remain_second(p->t_start) * 1000);
14721 if (p->t_connect)
14722 json_object_int_add(
14723 json_neigh, "nextConnectTimerDueInMsecs",
14724 thread_timer_remain_second(p->t_connect)
14725 * 1000);
14726 if (p->t_routeadv) {
14727 json_object_int_add(json_neigh, "mraiInterval",
14728 p->v_routeadv);
14729 json_object_int_add(
14730 json_neigh, "mraiTimerExpireInMsecs",
14731 thread_timer_remain_second(p->t_routeadv)
14732 * 1000);
14733 }
14734 if (p->password)
14735 json_object_int_add(json_neigh, "authenticationEnabled",
14736 1);
14737
14738 if (p->t_read)
14739 json_object_string_add(json_neigh, "readThread", "on");
14740 else
14741 json_object_string_add(json_neigh, "readThread", "off");
14742
14743 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14744 json_object_string_add(json_neigh, "writeThread", "on");
14745 else
14746 json_object_string_add(json_neigh, "writeThread",
14747 "off");
14748 } else {
14749 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14750 p->v_connect);
14751 if (peer_established(p)) {
14752 vty_out(vty, "Estimated round trip time: %d ms\n",
14753 p->rtt);
14754 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14755 vty_out(vty,
14756 "Shutdown when RTT > %dms, count > %u\n",
14757 p->rtt_expected, p->rtt_keepalive_rcv);
14758 }
14759 if (p->t_start)
14760 vty_out(vty, "Next start timer due in %ld seconds\n",
14761 thread_timer_remain_second(p->t_start));
14762 if (p->t_connect)
14763 vty_out(vty, "Next connect timer due in %ld seconds\n",
14764 thread_timer_remain_second(p->t_connect));
14765 if (p->t_routeadv)
14766 vty_out(vty,
14767 "MRAI (interval %u) timer expires in %ld seconds\n",
14768 p->v_routeadv,
14769 thread_timer_remain_second(p->t_routeadv));
14770 if (p->password)
14771 vty_out(vty, "Peer Authentication Enabled\n");
14772
14773 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14774 p->t_read ? "on" : "off",
14775 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14776 ? "on"
14777 : "off", p->fd);
14778 }
14779
14780 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14781 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14782 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14783
14784 if (!use_json)
14785 vty_out(vty, "\n");
14786
14787 /* BFD information. */
14788 if (p->bfd_config)
14789 bgp_bfd_show_info(vty, p, json_neigh);
14790
14791 if (use_json) {
14792 if (p->conf_if) /* Configured interface name. */
14793 json_object_object_add(json, p->conf_if, json_neigh);
14794 else /* Configured IP address. */
14795 json_object_object_add(json, p->host, json_neigh);
14796 }
14797 }
14798
14799 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14800 enum show_type type,
14801 union sockunion *su,
14802 const char *conf_if, afi_t afi,
14803 json_object *json)
14804 {
14805 struct listnode *node, *nnode;
14806 struct peer *peer;
14807 bool found = false;
14808 safi_t safi = SAFI_UNICAST;
14809 json_object *json_neighbor = NULL;
14810
14811 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14812
14813 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14814 continue;
14815
14816 if ((peer->afc[afi][safi]) == 0)
14817 continue;
14818
14819 if (json)
14820 json_neighbor = json_object_new_object();
14821
14822 if (type == show_all) {
14823 bgp_show_peer_gr_status(vty, peer, json_neighbor);
14824
14825 if (json)
14826 json_object_object_add(json, peer->host,
14827 json_neighbor);
14828
14829 } else if (type == show_peer) {
14830 if (conf_if) {
14831 if ((peer->conf_if
14832 && !strcmp(peer->conf_if, conf_if))
14833 || (peer->hostname
14834 && !strcmp(peer->hostname, conf_if))) {
14835 found = true;
14836 bgp_show_peer_gr_status(vty, peer,
14837 json_neighbor);
14838 }
14839 } else {
14840 if (sockunion_same(&peer->su, su)) {
14841 found = true;
14842 bgp_show_peer_gr_status(vty, peer,
14843 json_neighbor);
14844 }
14845 }
14846 if (json) {
14847 if (found)
14848 json_object_object_add(json, peer->host,
14849 json_neighbor);
14850 else
14851 json_object_free(json_neighbor);
14852 }
14853 }
14854
14855 if (found)
14856 break;
14857 }
14858
14859 if (type == show_peer && !found) {
14860 if (json)
14861 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14862 else
14863 vty_out(vty, "%% No such neighbor\n");
14864 }
14865
14866 if (!json)
14867 vty_out(vty, "\n");
14868
14869 return CMD_SUCCESS;
14870 }
14871
14872 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14873 enum show_type type, union sockunion *su,
14874 const char *conf_if, bool use_json,
14875 json_object *json)
14876 {
14877 struct listnode *node, *nnode;
14878 struct peer *peer;
14879 int find = 0;
14880 bool nbr_output = false;
14881 afi_t afi = AFI_MAX;
14882 safi_t safi = SAFI_MAX;
14883
14884 if (type == show_ipv4_peer || type == show_ipv4_all) {
14885 afi = AFI_IP;
14886 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14887 afi = AFI_IP6;
14888 }
14889
14890 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14891 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14892 continue;
14893
14894 switch (type) {
14895 case show_all:
14896 bgp_show_peer(vty, peer, use_json, json);
14897 nbr_output = true;
14898 break;
14899 case show_peer:
14900 if (conf_if) {
14901 if ((peer->conf_if
14902 && !strcmp(peer->conf_if, conf_if))
14903 || (peer->hostname
14904 && !strcmp(peer->hostname, conf_if))) {
14905 find = 1;
14906 bgp_show_peer(vty, peer, use_json,
14907 json);
14908 }
14909 } else {
14910 if (sockunion_same(&peer->su, su)) {
14911 find = 1;
14912 bgp_show_peer(vty, peer, use_json,
14913 json);
14914 }
14915 }
14916 break;
14917 case show_ipv4_peer:
14918 case show_ipv6_peer:
14919 FOREACH_SAFI (safi) {
14920 if (peer->afc[afi][safi]) {
14921 if (conf_if) {
14922 if ((peer->conf_if
14923 && !strcmp(peer->conf_if, conf_if))
14924 || (peer->hostname
14925 && !strcmp(peer->hostname, conf_if))) {
14926 find = 1;
14927 bgp_show_peer(vty, peer, use_json,
14928 json);
14929 break;
14930 }
14931 } else {
14932 if (sockunion_same(&peer->su, su)) {
14933 find = 1;
14934 bgp_show_peer(vty, peer, use_json,
14935 json);
14936 break;
14937 }
14938 }
14939 }
14940 }
14941 break;
14942 case show_ipv4_all:
14943 case show_ipv6_all:
14944 FOREACH_SAFI (safi) {
14945 if (peer->afc[afi][safi]) {
14946 bgp_show_peer(vty, peer, use_json, json);
14947 nbr_output = true;
14948 break;
14949 }
14950 }
14951 break;
14952 }
14953 }
14954
14955 if ((type == show_peer || type == show_ipv4_peer ||
14956 type == show_ipv6_peer) && !find) {
14957 if (use_json)
14958 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14959 else
14960 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14961 }
14962
14963 if (type != show_peer && type != show_ipv4_peer &&
14964 type != show_ipv6_peer && !nbr_output && !use_json)
14965 vty_out(vty, "%% No BGP neighbors found\n");
14966
14967 if (use_json) {
14968 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14969 json, JSON_C_TO_STRING_PRETTY));
14970 } else {
14971 vty_out(vty, "\n");
14972 }
14973
14974 return CMD_SUCCESS;
14975 }
14976
14977 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14978 enum show_type type,
14979 const char *ip_str,
14980 afi_t afi, json_object *json)
14981 {
14982
14983 int ret;
14984 struct bgp *bgp;
14985 union sockunion su;
14986
14987 bgp = bgp_get_default();
14988
14989 if (!bgp)
14990 return;
14991
14992 if (!json)
14993 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
14994
14995 if (ip_str) {
14996 ret = str2sockunion(ip_str, &su);
14997 if (ret < 0)
14998 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
14999 ip_str, afi, json);
15000 else
15001 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15002 NULL, afi, json);
15003 } else
15004 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
15005 afi, json);
15006 }
15007
15008 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
15009 enum show_type type,
15010 const char *ip_str,
15011 bool use_json)
15012 {
15013 struct listnode *node, *nnode;
15014 struct bgp *bgp;
15015 union sockunion su;
15016 json_object *json = NULL;
15017 int ret, is_first = 1;
15018 bool nbr_output = false;
15019
15020 if (use_json)
15021 vty_out(vty, "{\n");
15022
15023 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15024 nbr_output = true;
15025 if (use_json) {
15026 if (!(json = json_object_new_object())) {
15027 flog_err(
15028 EC_BGP_JSON_MEM_ERROR,
15029 "Unable to allocate memory for JSON object");
15030 vty_out(vty,
15031 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15032 return;
15033 }
15034
15035 json_object_int_add(json, "vrfId",
15036 (bgp->vrf_id == VRF_UNKNOWN)
15037 ? -1
15038 : (int64_t)bgp->vrf_id);
15039 json_object_string_add(
15040 json, "vrfName",
15041 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15042 ? VRF_DEFAULT_NAME
15043 : bgp->name);
15044
15045 if (!is_first)
15046 vty_out(vty, ",\n");
15047 else
15048 is_first = 0;
15049
15050 vty_out(vty, "\"%s\":",
15051 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15052 ? VRF_DEFAULT_NAME
15053 : bgp->name);
15054 } else {
15055 vty_out(vty, "\nInstance %s:\n",
15056 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15057 ? VRF_DEFAULT_NAME
15058 : bgp->name);
15059 }
15060
15061 if (type == show_peer || type == show_ipv4_peer ||
15062 type == show_ipv6_peer) {
15063 ret = str2sockunion(ip_str, &su);
15064 if (ret < 0)
15065 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15066 use_json, json);
15067 else
15068 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15069 use_json, json);
15070 } else {
15071 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15072 use_json, json);
15073 }
15074 json_object_free(json);
15075 json = NULL;
15076 }
15077
15078 if (use_json)
15079 vty_out(vty, "}\n");
15080 else if (!nbr_output)
15081 vty_out(vty, "%% BGP instance not found\n");
15082 }
15083
15084 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15085 enum show_type type, const char *ip_str,
15086 bool use_json)
15087 {
15088 int ret;
15089 struct bgp *bgp;
15090 union sockunion su;
15091 json_object *json = NULL;
15092
15093 if (name) {
15094 if (strmatch(name, "all")) {
15095 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15096 use_json);
15097 return CMD_SUCCESS;
15098 } else {
15099 bgp = bgp_lookup_by_name(name);
15100 if (!bgp) {
15101 if (use_json) {
15102 json = json_object_new_object();
15103 vty_json(vty, json);
15104 } else
15105 vty_out(vty,
15106 "%% BGP instance not found\n");
15107
15108 return CMD_WARNING;
15109 }
15110 }
15111 } else {
15112 bgp = bgp_get_default();
15113 }
15114
15115 if (bgp) {
15116 json = json_object_new_object();
15117 if (ip_str) {
15118 ret = str2sockunion(ip_str, &su);
15119 if (ret < 0)
15120 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15121 use_json, json);
15122 else
15123 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15124 use_json, json);
15125 } else {
15126 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15127 json);
15128 }
15129 json_object_free(json);
15130 } else {
15131 if (use_json)
15132 vty_out(vty, "{}\n");
15133 else
15134 vty_out(vty, "%% BGP instance not found\n");
15135 }
15136
15137 return CMD_SUCCESS;
15138 }
15139
15140
15141
15142 /* "show [ip] bgp neighbors graceful-restart" commands. */
15143 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15144 show_ip_bgp_neighbors_graceful_restart_cmd,
15145 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15146 SHOW_STR
15147 BGP_STR
15148 IP_STR
15149 IPV6_STR
15150 NEIGHBOR_STR
15151 "Neighbor to display information about\n"
15152 "Neighbor to display information about\n"
15153 "Neighbor on BGP configured interface\n"
15154 GR_SHOW
15155 JSON_STR)
15156 {
15157 char *sh_arg = NULL;
15158 enum show_type sh_type;
15159 int idx = 0;
15160 afi_t afi = AFI_MAX;
15161 bool uj = use_json(argc, argv);
15162
15163 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15164 afi = AFI_MAX;
15165
15166 idx++;
15167
15168 if (argv_find(argv, argc, "A.B.C.D", &idx)
15169 || argv_find(argv, argc, "X:X::X:X", &idx)
15170 || argv_find(argv, argc, "WORD", &idx)) {
15171 sh_type = show_peer;
15172 sh_arg = argv[idx]->arg;
15173 } else
15174 sh_type = show_all;
15175
15176 if (!argv_find(argv, argc, "graceful-restart", &idx))
15177 return CMD_SUCCESS;
15178
15179
15180 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15181 afi, uj);
15182 }
15183
15184 /* "show [ip] bgp neighbors" commands. */
15185 DEFUN (show_ip_bgp_neighbors,
15186 show_ip_bgp_neighbors_cmd,
15187 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15188 SHOW_STR
15189 IP_STR
15190 BGP_STR
15191 BGP_INSTANCE_HELP_STR
15192 BGP_AF_STR
15193 BGP_AF_STR
15194 "Detailed information on TCP and BGP neighbor connections\n"
15195 "Neighbor to display information about\n"
15196 "Neighbor to display information about\n"
15197 "Neighbor on BGP configured interface\n"
15198 JSON_STR)
15199 {
15200 char *vrf = NULL;
15201 char *sh_arg = NULL;
15202 enum show_type sh_type;
15203 afi_t afi = AFI_MAX;
15204
15205 bool uj = use_json(argc, argv);
15206
15207 int idx = 0;
15208
15209 /* [<vrf> VIEWVRFNAME] */
15210 if (argv_find(argv, argc, "vrf", &idx)) {
15211 vrf = argv[idx + 1]->arg;
15212 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15213 vrf = NULL;
15214 } else if (argv_find(argv, argc, "view", &idx))
15215 /* [<view> VIEWVRFNAME] */
15216 vrf = argv[idx + 1]->arg;
15217
15218 idx++;
15219
15220 if (argv_find(argv, argc, "ipv4", &idx)) {
15221 sh_type = show_ipv4_all;
15222 afi = AFI_IP;
15223 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15224 sh_type = show_ipv6_all;
15225 afi = AFI_IP6;
15226 } else {
15227 sh_type = show_all;
15228 }
15229
15230 if (argv_find(argv, argc, "A.B.C.D", &idx)
15231 || argv_find(argv, argc, "X:X::X:X", &idx)
15232 || argv_find(argv, argc, "WORD", &idx)) {
15233 sh_type = show_peer;
15234 sh_arg = argv[idx]->arg;
15235 }
15236
15237 if (sh_type == show_peer && afi == AFI_IP) {
15238 sh_type = show_ipv4_peer;
15239 } else if (sh_type == show_peer && afi == AFI_IP6) {
15240 sh_type = show_ipv6_peer;
15241 }
15242
15243 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15244 }
15245
15246 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15247 paths' and `show ip mbgp paths'. Those functions results are the
15248 same.*/
15249 DEFUN (show_ip_bgp_paths,
15250 show_ip_bgp_paths_cmd,
15251 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15252 SHOW_STR
15253 IP_STR
15254 BGP_STR
15255 BGP_SAFI_HELP_STR
15256 "Path information\n")
15257 {
15258 vty_out(vty, "Address Refcnt Path\n");
15259 aspath_print_all_vty(vty);
15260 return CMD_SUCCESS;
15261 }
15262
15263 #include "hash.h"
15264
15265 static void community_show_all_iterator(struct hash_bucket *bucket,
15266 struct vty *vty)
15267 {
15268 struct community *com;
15269
15270 com = (struct community *)bucket->data;
15271 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15272 community_str(com, false, false));
15273 }
15274
15275 /* Show BGP's community internal data. */
15276 DEFUN (show_ip_bgp_community_info,
15277 show_ip_bgp_community_info_cmd,
15278 "show [ip] bgp community-info",
15279 SHOW_STR
15280 IP_STR
15281 BGP_STR
15282 "List all bgp community information\n")
15283 {
15284 vty_out(vty, "Address Refcnt Community\n");
15285
15286 hash_iterate(community_hash(),
15287 (void (*)(struct hash_bucket *,
15288 void *))community_show_all_iterator,
15289 vty);
15290
15291 return CMD_SUCCESS;
15292 }
15293
15294 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15295 struct vty *vty)
15296 {
15297 struct lcommunity *lcom;
15298
15299 lcom = (struct lcommunity *)bucket->data;
15300 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15301 lcommunity_str(lcom, false, false));
15302 }
15303
15304 /* Show BGP's community internal data. */
15305 DEFUN (show_ip_bgp_lcommunity_info,
15306 show_ip_bgp_lcommunity_info_cmd,
15307 "show ip bgp large-community-info",
15308 SHOW_STR
15309 IP_STR
15310 BGP_STR
15311 "List all bgp large-community information\n")
15312 {
15313 vty_out(vty, "Address Refcnt Large-community\n");
15314
15315 hash_iterate(lcommunity_hash(),
15316 (void (*)(struct hash_bucket *,
15317 void *))lcommunity_show_all_iterator,
15318 vty);
15319
15320 return CMD_SUCCESS;
15321 }
15322 /* Graceful Restart */
15323
15324 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15325 struct bgp *bgp)
15326 {
15327
15328
15329 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15330
15331 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15332
15333 switch (bgp_global_gr_mode) {
15334
15335 case GLOBAL_HELPER:
15336 vty_out(vty, "Global BGP GR Mode : Helper\n");
15337 break;
15338
15339 case GLOBAL_GR:
15340 vty_out(vty, "Global BGP GR Mode : Restart\n");
15341 break;
15342
15343 case GLOBAL_DISABLE:
15344 vty_out(vty, "Global BGP GR Mode : Disable\n");
15345 break;
15346
15347 case GLOBAL_INVALID:
15348 vty_out(vty,
15349 "Global BGP GR Mode Invalid\n");
15350 break;
15351 }
15352 vty_out(vty, "\n");
15353 }
15354
15355 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15356 enum show_type type,
15357 const char *ip_str,
15358 afi_t afi, bool use_json)
15359 {
15360 json_object *json = NULL;
15361
15362 if (use_json)
15363 json = json_object_new_object();
15364
15365 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15366 afi = AFI_IP;
15367
15368 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15369
15370 bgp_show_neighbor_graceful_restart_vty(
15371 vty, type, ip_str, afi, json);
15372 afi++;
15373 }
15374 } else if (afi != AFI_MAX) {
15375 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15376 json);
15377 } else {
15378 if (json)
15379 json_object_free(json);
15380 return CMD_ERR_INCOMPLETE;
15381 }
15382
15383 if (json)
15384 vty_json(vty, json);
15385
15386 return CMD_SUCCESS;
15387 }
15388 /* Graceful Restart */
15389
15390 DEFUN (show_ip_bgp_attr_info,
15391 show_ip_bgp_attr_info_cmd,
15392 "show [ip] bgp attribute-info",
15393 SHOW_STR
15394 IP_STR
15395 BGP_STR
15396 "List all bgp attribute information\n")
15397 {
15398 attr_show_all(vty);
15399 return CMD_SUCCESS;
15400 }
15401
15402 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15403 afi_t afi, safi_t safi,
15404 bool use_json, json_object *json)
15405 {
15406 struct bgp *bgp;
15407 struct listnode *node;
15408 char *vname;
15409 char *ecom_str;
15410 enum vpn_policy_direction dir;
15411
15412 if (json) {
15413 json_object *json_import_vrfs = NULL;
15414 json_object *json_export_vrfs = NULL;
15415
15416 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15417
15418 if (!bgp) {
15419 vty_json(vty, json);
15420
15421 return CMD_WARNING;
15422 }
15423
15424 /* Provide context for the block */
15425 json_object_string_add(json, "vrf", name ? name : "default");
15426 json_object_string_add(json, "afiSafi",
15427 get_afi_safi_str(afi, safi, true));
15428
15429 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15430 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15431 json_object_string_add(json, "importFromVrfs", "none");
15432 json_object_string_add(json, "importRts", "none");
15433 } else {
15434 json_import_vrfs = json_object_new_array();
15435
15436 for (ALL_LIST_ELEMENTS_RO(
15437 bgp->vpn_policy[afi].import_vrf,
15438 node, vname))
15439 json_object_array_add(json_import_vrfs,
15440 json_object_new_string(vname));
15441
15442 json_object_object_add(json, "importFromVrfs",
15443 json_import_vrfs);
15444 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15445 if (bgp->vpn_policy[afi].rtlist[dir]) {
15446 ecom_str = ecommunity_ecom2str(
15447 bgp->vpn_policy[afi].rtlist[dir],
15448 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15449 json_object_string_add(json, "importRts",
15450 ecom_str);
15451 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15452 } else
15453 json_object_string_add(json, "importRts",
15454 "none");
15455 }
15456
15457 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15458 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15459 json_object_string_add(json, "exportToVrfs", "none");
15460 json_object_string_add(json, "routeDistinguisher",
15461 "none");
15462 json_object_string_add(json, "exportRts", "none");
15463 } else {
15464 json_export_vrfs = json_object_new_array();
15465
15466 for (ALL_LIST_ELEMENTS_RO(
15467 bgp->vpn_policy[afi].export_vrf,
15468 node, vname))
15469 json_object_array_add(json_export_vrfs,
15470 json_object_new_string(vname));
15471 json_object_object_add(json, "exportToVrfs",
15472 json_export_vrfs);
15473 json_object_string_addf(json, "routeDistinguisher",
15474 "%pRD",
15475 &bgp->vpn_policy[afi].tovpn_rd);
15476
15477 dir = BGP_VPN_POLICY_DIR_TOVPN;
15478 if (bgp->vpn_policy[afi].rtlist[dir]) {
15479 ecom_str = ecommunity_ecom2str(
15480 bgp->vpn_policy[afi].rtlist[dir],
15481 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15482 json_object_string_add(json, "exportRts",
15483 ecom_str);
15484 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15485 } else
15486 json_object_string_add(json, "exportRts",
15487 "none");
15488 }
15489
15490 if (use_json) {
15491 vty_json(vty, json);
15492 }
15493 } else {
15494 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15495
15496 if (!bgp) {
15497 vty_out(vty, "%% No such BGP instance exist\n");
15498 return CMD_WARNING;
15499 }
15500
15501 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15502 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15503 vty_out(vty,
15504 "This VRF is not importing %s routes from any other VRF\n",
15505 get_afi_safi_str(afi, safi, false));
15506 else {
15507 vty_out(vty,
15508 "This VRF is importing %s routes from the following VRFs:\n",
15509 get_afi_safi_str(afi, safi, false));
15510
15511 for (ALL_LIST_ELEMENTS_RO(
15512 bgp->vpn_policy[afi].import_vrf,
15513 node, vname))
15514 vty_out(vty, " %s\n", vname);
15515
15516 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15517 ecom_str = NULL;
15518 if (bgp->vpn_policy[afi].rtlist[dir]) {
15519 ecom_str = ecommunity_ecom2str(
15520 bgp->vpn_policy[afi].rtlist[dir],
15521 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15522 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15523
15524 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15525 } else
15526 vty_out(vty, "Import RT(s):\n");
15527 }
15528
15529 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15530 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15531 vty_out(vty,
15532 "This VRF is not exporting %s routes to any other VRF\n",
15533 get_afi_safi_str(afi, safi, false));
15534 else {
15535 vty_out(vty,
15536 "This VRF is exporting %s routes to the following VRFs:\n",
15537 get_afi_safi_str(afi, safi, false));
15538
15539 for (ALL_LIST_ELEMENTS_RO(
15540 bgp->vpn_policy[afi].export_vrf,
15541 node, vname))
15542 vty_out(vty, " %s\n", vname);
15543
15544 vty_out(vty, "RD: %pRD\n",
15545 &bgp->vpn_policy[afi].tovpn_rd);
15546
15547 dir = BGP_VPN_POLICY_DIR_TOVPN;
15548 if (bgp->vpn_policy[afi].rtlist[dir]) {
15549 ecom_str = ecommunity_ecom2str(
15550 bgp->vpn_policy[afi].rtlist[dir],
15551 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15552 vty_out(vty, "Export RT: %s\n", ecom_str);
15553 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15554 } else
15555 vty_out(vty, "Import RT(s):\n");
15556 }
15557 }
15558
15559 return CMD_SUCCESS;
15560 }
15561
15562 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15563 safi_t safi, bool use_json)
15564 {
15565 struct listnode *node, *nnode;
15566 struct bgp *bgp;
15567 char *vrf_name = NULL;
15568 json_object *json = NULL;
15569 json_object *json_vrf = NULL;
15570 json_object *json_vrfs = NULL;
15571
15572 if (use_json) {
15573 json = json_object_new_object();
15574 json_vrfs = json_object_new_object();
15575 }
15576
15577 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15578
15579 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15580 vrf_name = bgp->name;
15581
15582 if (use_json) {
15583 json_vrf = json_object_new_object();
15584 } else {
15585 vty_out(vty, "\nInstance %s:\n",
15586 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15587 ? VRF_DEFAULT_NAME : bgp->name);
15588 }
15589 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15590 if (use_json) {
15591 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15592 json_object_object_add(json_vrfs,
15593 VRF_DEFAULT_NAME, json_vrf);
15594 else
15595 json_object_object_add(json_vrfs, vrf_name,
15596 json_vrf);
15597 }
15598 }
15599
15600 if (use_json) {
15601 json_object_object_add(json, "vrfs", json_vrfs);
15602 vty_json(vty, json);
15603 }
15604
15605 return CMD_SUCCESS;
15606 }
15607
15608 /* "show [ip] bgp route-leak" command. */
15609 DEFUN (show_ip_bgp_route_leak,
15610 show_ip_bgp_route_leak_cmd,
15611 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15612 SHOW_STR
15613 IP_STR
15614 BGP_STR
15615 BGP_INSTANCE_HELP_STR
15616 BGP_AFI_HELP_STR
15617 BGP_SAFI_HELP_STR
15618 "Route leaking information\n"
15619 JSON_STR)
15620 {
15621 char *vrf = NULL;
15622 afi_t afi = AFI_MAX;
15623 safi_t safi = SAFI_MAX;
15624
15625 bool uj = use_json(argc, argv);
15626 int idx = 0;
15627 json_object *json = NULL;
15628
15629 /* show [ip] bgp */
15630 if (argv_find(argv, argc, "ip", &idx)) {
15631 afi = AFI_IP;
15632 safi = SAFI_UNICAST;
15633 }
15634 /* [vrf VIEWVRFNAME] */
15635 if (argv_find(argv, argc, "view", &idx)) {
15636 vty_out(vty,
15637 "%% This command is not applicable to BGP views\n");
15638 return CMD_WARNING;
15639 }
15640
15641 if (argv_find(argv, argc, "vrf", &idx)) {
15642 vrf = argv[idx + 1]->arg;
15643 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15644 vrf = NULL;
15645 }
15646 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15647 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15648 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15649
15650 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15651 vty_out(vty,
15652 "%% This command is applicable only for unicast ipv4|ipv6\n");
15653 return CMD_WARNING;
15654 }
15655
15656 if (vrf && strmatch(vrf, "all"))
15657 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15658
15659 if (uj)
15660 json = json_object_new_object();
15661
15662 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15663 }
15664
15665 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15666 safi_t safi, bool uj)
15667 {
15668 struct listnode *node, *nnode;
15669 struct bgp *bgp;
15670
15671 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15672 if (!uj)
15673 vty_out(vty, "\nInstance %s:\n",
15674 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15675 ? VRF_DEFAULT_NAME
15676 : bgp->name);
15677
15678 update_group_show(bgp, afi, safi, vty, 0, uj);
15679 }
15680 }
15681
15682 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15683 int safi, uint64_t subgrp_id, bool uj)
15684 {
15685 struct bgp *bgp;
15686
15687 if (name) {
15688 if (strmatch(name, "all")) {
15689 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15690 return CMD_SUCCESS;
15691 } else {
15692 bgp = bgp_lookup_by_name(name);
15693 }
15694 } else {
15695 bgp = bgp_get_default();
15696 }
15697
15698 if (bgp)
15699 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15700 return CMD_SUCCESS;
15701 }
15702
15703 DEFUN (show_ip_bgp_updgrps,
15704 show_ip_bgp_updgrps_cmd,
15705 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15706 SHOW_STR
15707 IP_STR
15708 BGP_STR
15709 BGP_INSTANCE_HELP_STR
15710 BGP_AFI_HELP_STR
15711 BGP_SAFI_WITH_LABEL_HELP_STR
15712 "Detailed info about dynamic update groups\n"
15713 "Specific subgroup to display detailed info for\n"
15714 JSON_STR)
15715 {
15716 char *vrf = NULL;
15717 afi_t afi = AFI_IP6;
15718 safi_t safi = SAFI_UNICAST;
15719 uint64_t subgrp_id = 0;
15720
15721 int idx = 0;
15722
15723 bool uj = use_json(argc, argv);
15724
15725 /* show [ip] bgp */
15726 if (argv_find(argv, argc, "ip", &idx))
15727 afi = AFI_IP;
15728 /* [<vrf> VIEWVRFNAME] */
15729 if (argv_find(argv, argc, "vrf", &idx)) {
15730 vrf = argv[idx + 1]->arg;
15731 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15732 vrf = NULL;
15733 } else if (argv_find(argv, argc, "view", &idx))
15734 /* [<view> VIEWVRFNAME] */
15735 vrf = argv[idx + 1]->arg;
15736 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15737 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15738 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15739 }
15740
15741 /* get subgroup id, if provided */
15742 idx = argc - 1;
15743 if (argv[idx]->type == VARIABLE_TKN)
15744 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15745
15746 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15747 }
15748
15749 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15750 show_bgp_instance_all_ipv6_updgrps_cmd,
15751 "show [ip] bgp <view|vrf> all update-groups [json]",
15752 SHOW_STR
15753 IP_STR
15754 BGP_STR
15755 BGP_INSTANCE_ALL_HELP_STR
15756 "Detailed info about dynamic update groups\n"
15757 JSON_STR)
15758 {
15759 bool uj = use_json(argc, argv);
15760
15761 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15762 return CMD_SUCCESS;
15763 }
15764
15765 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15766 show_bgp_l2vpn_evpn_updgrps_cmd,
15767 "show [ip] bgp l2vpn evpn update-groups",
15768 SHOW_STR
15769 IP_STR
15770 BGP_STR
15771 "l2vpn address family\n"
15772 "evpn sub-address family\n"
15773 "Detailed info about dynamic update groups\n")
15774 {
15775 char *vrf = NULL;
15776 uint64_t subgrp_id = 0;
15777
15778 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
15779 return CMD_SUCCESS;
15780 }
15781
15782 DEFUN (show_bgp_updgrps_stats,
15783 show_bgp_updgrps_stats_cmd,
15784 "show [ip] bgp update-groups statistics",
15785 SHOW_STR
15786 IP_STR
15787 BGP_STR
15788 "Detailed info about dynamic update groups\n"
15789 "Statistics\n")
15790 {
15791 struct bgp *bgp;
15792
15793 bgp = bgp_get_default();
15794 if (bgp)
15795 update_group_show_stats(bgp, vty);
15796
15797 return CMD_SUCCESS;
15798 }
15799
15800 DEFUN (show_bgp_instance_updgrps_stats,
15801 show_bgp_instance_updgrps_stats_cmd,
15802 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15803 SHOW_STR
15804 IP_STR
15805 BGP_STR
15806 BGP_INSTANCE_HELP_STR
15807 "Detailed info about dynamic update groups\n"
15808 "Statistics\n")
15809 {
15810 int idx_word = 3;
15811 struct bgp *bgp;
15812
15813 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15814 if (bgp)
15815 update_group_show_stats(bgp, vty);
15816
15817 return CMD_SUCCESS;
15818 }
15819
15820 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15821 afi_t afi, safi_t safi,
15822 const char *what, uint64_t subgrp_id)
15823 {
15824 struct bgp *bgp;
15825
15826 if (name)
15827 bgp = bgp_lookup_by_name(name);
15828 else
15829 bgp = bgp_get_default();
15830
15831 if (bgp) {
15832 if (!strcmp(what, "advertise-queue"))
15833 update_group_show_adj_queue(bgp, afi, safi, vty,
15834 subgrp_id);
15835 else if (!strcmp(what, "advertised-routes"))
15836 update_group_show_advertised(bgp, afi, safi, vty,
15837 subgrp_id);
15838 else if (!strcmp(what, "packet-queue"))
15839 update_group_show_packet_queue(bgp, afi, safi, vty,
15840 subgrp_id);
15841 }
15842 }
15843
15844 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15845 show_ip_bgp_instance_updgrps_adj_s_cmd,
15846 "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",
15847 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15848 BGP_SAFI_HELP_STR
15849 "Detailed info about dynamic update groups\n"
15850 "Specific subgroup to display info for\n"
15851 "Advertisement queue\n"
15852 "Announced routes\n"
15853 "Packet queue\n")
15854 {
15855 uint64_t subgrp_id = 0;
15856 afi_t afiz;
15857 safi_t safiz;
15858 if (sgid)
15859 subgrp_id = strtoull(sgid, NULL, 10);
15860
15861 if (!ip && !afi)
15862 afiz = AFI_IP6;
15863 if (!ip && afi)
15864 afiz = bgp_vty_afi_from_str(afi);
15865 if (ip && !afi)
15866 afiz = AFI_IP;
15867 if (ip && afi) {
15868 afiz = bgp_vty_afi_from_str(afi);
15869 if (afiz != AFI_IP)
15870 vty_out(vty,
15871 "%% Cannot specify both 'ip' and 'ipv6'\n");
15872 return CMD_WARNING;
15873 }
15874
15875 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15876
15877 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15878 return CMD_SUCCESS;
15879 }
15880
15881 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15882 json_object *json)
15883 {
15884 struct listnode *node, *nnode;
15885 struct prefix *range;
15886 struct peer *conf;
15887 struct peer *peer;
15888 afi_t afi;
15889 safi_t safi;
15890 const char *peer_status;
15891 int lr_count;
15892 int dynamic;
15893 bool af_cfgd;
15894 json_object *json_peer_group = NULL;
15895 json_object *json_peer_group_afc = NULL;
15896 json_object *json_peer_group_members = NULL;
15897 json_object *json_peer_group_dynamic = NULL;
15898 json_object *json_peer_group_dynamic_af = NULL;
15899 json_object *json_peer_group_ranges = NULL;
15900
15901 conf = group->conf;
15902
15903 if (json) {
15904 json_peer_group = json_object_new_object();
15905 json_peer_group_afc = json_object_new_array();
15906 }
15907
15908 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15909 if (json)
15910 json_object_int_add(json_peer_group, "remoteAs",
15911 conf->as);
15912 else
15913 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15914 group->name, conf->as);
15915 } else if (conf->as_type == AS_INTERNAL) {
15916 if (json)
15917 json_object_int_add(json_peer_group, "remoteAs",
15918 group->bgp->as);
15919 else
15920 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15921 group->name, group->bgp->as);
15922 } else {
15923 if (!json)
15924 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15925 }
15926
15927 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15928 if (json)
15929 json_object_string_add(json_peer_group, "type",
15930 "internal");
15931 else
15932 vty_out(vty, " Peer-group type is internal\n");
15933 } else {
15934 if (json)
15935 json_object_string_add(json_peer_group, "type",
15936 "external");
15937 else
15938 vty_out(vty, " Peer-group type is external\n");
15939 }
15940
15941 /* Display AFs configured. */
15942 if (!json)
15943 vty_out(vty, " Configured address-families:");
15944
15945 FOREACH_AFI_SAFI (afi, safi) {
15946 if (conf->afc[afi][safi]) {
15947 af_cfgd = true;
15948 if (json)
15949 json_object_array_add(
15950 json_peer_group_afc,
15951 json_object_new_string(get_afi_safi_str(
15952 afi, safi, false)));
15953 else
15954 vty_out(vty, " %s;",
15955 get_afi_safi_str(afi, safi, false));
15956 }
15957 }
15958
15959 if (json) {
15960 json_object_object_add(json_peer_group,
15961 "addressFamiliesConfigured",
15962 json_peer_group_afc);
15963 } else {
15964 if (!af_cfgd)
15965 vty_out(vty, " none\n");
15966 else
15967 vty_out(vty, "\n");
15968 }
15969
15970 /* Display listen ranges (for dynamic neighbors), if any */
15971 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15972 lr_count = listcount(group->listen_range[afi]);
15973 if (lr_count) {
15974 if (json) {
15975 if (!json_peer_group_dynamic)
15976 json_peer_group_dynamic =
15977 json_object_new_object();
15978
15979 json_peer_group_dynamic_af =
15980 json_object_new_object();
15981 json_peer_group_ranges =
15982 json_object_new_array();
15983 json_object_int_add(json_peer_group_dynamic_af,
15984 "count", lr_count);
15985 } else {
15986 vty_out(vty, " %d %s listen range(s)\n",
15987 lr_count, afi2str(afi));
15988 }
15989
15990 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15991 nnode, range)) {
15992 if (json) {
15993 char buf[BUFSIZ];
15994
15995 snprintfrr(buf, sizeof(buf), "%pFX",
15996 range);
15997
15998 json_object_array_add(
15999 json_peer_group_ranges,
16000 json_object_new_string(buf));
16001 } else {
16002 vty_out(vty, " %pFX\n", range);
16003 }
16004 }
16005
16006 if (json) {
16007 json_object_object_add(
16008 json_peer_group_dynamic_af, "ranges",
16009 json_peer_group_ranges);
16010
16011 json_object_object_add(
16012 json_peer_group_dynamic, afi2str(afi),
16013 json_peer_group_dynamic_af);
16014 }
16015 }
16016 }
16017
16018 if (json_peer_group_dynamic)
16019 json_object_object_add(json_peer_group, "dynamicRanges",
16020 json_peer_group_dynamic);
16021
16022 /* Display group members and their status */
16023 if (listcount(group->peer)) {
16024 if (json)
16025 json_peer_group_members = json_object_new_object();
16026 else
16027 vty_out(vty, " Peer-group members:\n");
16028 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16029 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16030 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16031 peer_status = "Idle (Admin)";
16032 else if (CHECK_FLAG(peer->sflags,
16033 PEER_STATUS_PREFIX_OVERFLOW))
16034 peer_status = "Idle (PfxCt)";
16035 else
16036 peer_status = lookup_msg(bgp_status_msg,
16037 peer->status, NULL);
16038
16039 dynamic = peer_dynamic_neighbor(peer);
16040
16041 if (json) {
16042 json_object *json_peer_group_member =
16043 json_object_new_object();
16044
16045 json_object_string_add(json_peer_group_member,
16046 "status", peer_status);
16047
16048 if (dynamic)
16049 json_object_boolean_true_add(
16050 json_peer_group_member,
16051 "dynamic");
16052
16053 json_object_object_add(json_peer_group_members,
16054 peer->host,
16055 json_peer_group_member);
16056 } else {
16057 vty_out(vty, " %s %s %s \n", peer->host,
16058 dynamic ? "(dynamic)" : "",
16059 peer_status);
16060 }
16061 }
16062 if (json)
16063 json_object_object_add(json_peer_group, "members",
16064 json_peer_group_members);
16065 }
16066
16067 if (json)
16068 json_object_object_add(json, group->name, json_peer_group);
16069
16070 return CMD_SUCCESS;
16071 }
16072
16073 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16074 const char *group_name, bool uj)
16075 {
16076 struct bgp *bgp;
16077 struct listnode *node, *nnode;
16078 struct peer_group *group;
16079 bool found = false;
16080 json_object *json = NULL;
16081
16082 if (uj)
16083 json = json_object_new_object();
16084
16085 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16086
16087 if (!bgp) {
16088 if (uj)
16089 vty_json(vty, json);
16090 else
16091 vty_out(vty, "%% BGP instance not found\n");
16092
16093 return CMD_WARNING;
16094 }
16095
16096 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16097 if (group_name) {
16098 if (strmatch(group->name, group_name)) {
16099 bgp_show_one_peer_group(vty, group, json);
16100 found = true;
16101 break;
16102 }
16103 } else {
16104 bgp_show_one_peer_group(vty, group, json);
16105 }
16106 }
16107
16108 if (group_name && !found && !uj)
16109 vty_out(vty, "%% No such peer-group\n");
16110
16111 if (uj)
16112 vty_json(vty, json);
16113
16114 return CMD_SUCCESS;
16115 }
16116
16117 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16118 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16119 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16120 "Detailed information on BGP peer groups\n"
16121 "Peer group name\n" JSON_STR)
16122 {
16123 char *vrf, *pg;
16124 int idx = 0;
16125 bool uj = use_json(argc, argv);
16126
16127 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16128 : NULL;
16129 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16130
16131 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16132 }
16133
16134
16135 /* Redistribute VTY commands. */
16136
16137 DEFUN (bgp_redistribute_ipv4,
16138 bgp_redistribute_ipv4_cmd,
16139 "redistribute " FRR_IP_REDIST_STR_BGPD,
16140 "Redistribute information from another routing protocol\n"
16141 FRR_IP_REDIST_HELP_STR_BGPD)
16142 {
16143 VTY_DECLVAR_CONTEXT(bgp, bgp);
16144 int idx_protocol = 1;
16145 int type;
16146
16147 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16148 if (type < 0) {
16149 vty_out(vty, "%% Invalid route type\n");
16150 return CMD_WARNING_CONFIG_FAILED;
16151 }
16152
16153 bgp_redist_add(bgp, AFI_IP, type, 0);
16154 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16155 }
16156
16157 ALIAS_HIDDEN(
16158 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16159 "redistribute " FRR_IP_REDIST_STR_BGPD,
16160 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16161
16162 DEFUN (bgp_redistribute_ipv4_rmap,
16163 bgp_redistribute_ipv4_rmap_cmd,
16164 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16165 "Redistribute information from another routing protocol\n"
16166 FRR_IP_REDIST_HELP_STR_BGPD
16167 "Route map reference\n"
16168 "Pointer to route-map entries\n")
16169 {
16170 VTY_DECLVAR_CONTEXT(bgp, bgp);
16171 int idx_protocol = 1;
16172 int idx_word = 3;
16173 int type;
16174 struct bgp_redist *red;
16175 bool changed;
16176 struct route_map *route_map = route_map_lookup_warn_noexist(
16177 vty, argv[idx_word]->arg);
16178
16179 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16180 if (type < 0) {
16181 vty_out(vty, "%% Invalid route type\n");
16182 return CMD_WARNING_CONFIG_FAILED;
16183 }
16184
16185 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16186 changed =
16187 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16188 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16189 }
16190
16191 ALIAS_HIDDEN(
16192 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16193 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16194 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16195 "Route map reference\n"
16196 "Pointer to route-map entries\n")
16197
16198 DEFUN (bgp_redistribute_ipv4_metric,
16199 bgp_redistribute_ipv4_metric_cmd,
16200 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16201 "Redistribute information from another routing protocol\n"
16202 FRR_IP_REDIST_HELP_STR_BGPD
16203 "Metric for redistributed routes\n"
16204 "Default metric\n")
16205 {
16206 VTY_DECLVAR_CONTEXT(bgp, bgp);
16207 int idx_protocol = 1;
16208 int idx_number = 3;
16209 int type;
16210 uint32_t metric;
16211 struct bgp_redist *red;
16212 bool changed;
16213
16214 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16215 if (type < 0) {
16216 vty_out(vty, "%% Invalid route type\n");
16217 return CMD_WARNING_CONFIG_FAILED;
16218 }
16219 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16220
16221 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16222 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16223 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16224 }
16225
16226 ALIAS_HIDDEN(
16227 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16228 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16229 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16230 "Metric for redistributed routes\n"
16231 "Default metric\n")
16232
16233 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16234 bgp_redistribute_ipv4_rmap_metric_cmd,
16235 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16236 "Redistribute information from another routing protocol\n"
16237 FRR_IP_REDIST_HELP_STR_BGPD
16238 "Route map reference\n"
16239 "Pointer to route-map entries\n"
16240 "Metric for redistributed routes\n"
16241 "Default metric\n")
16242 {
16243 VTY_DECLVAR_CONTEXT(bgp, bgp);
16244 int idx_protocol = 1;
16245 int idx_word = 3;
16246 int idx_number = 5;
16247 int type;
16248 uint32_t metric;
16249 struct bgp_redist *red;
16250 bool changed;
16251 struct route_map *route_map =
16252 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16253
16254 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16255 if (type < 0) {
16256 vty_out(vty, "%% Invalid route type\n");
16257 return CMD_WARNING_CONFIG_FAILED;
16258 }
16259 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16260
16261 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16262 changed =
16263 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16264 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16265 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16266 }
16267
16268 ALIAS_HIDDEN(
16269 bgp_redistribute_ipv4_rmap_metric,
16270 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16271 "redistribute " FRR_IP_REDIST_STR_BGPD
16272 " route-map RMAP_NAME metric (0-4294967295)",
16273 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16274 "Route map reference\n"
16275 "Pointer to route-map entries\n"
16276 "Metric for redistributed routes\n"
16277 "Default metric\n")
16278
16279 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16280 bgp_redistribute_ipv4_metric_rmap_cmd,
16281 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16282 "Redistribute information from another routing protocol\n"
16283 FRR_IP_REDIST_HELP_STR_BGPD
16284 "Metric for redistributed routes\n"
16285 "Default metric\n"
16286 "Route map reference\n"
16287 "Pointer to route-map entries\n")
16288 {
16289 VTY_DECLVAR_CONTEXT(bgp, bgp);
16290 int idx_protocol = 1;
16291 int idx_number = 3;
16292 int idx_word = 5;
16293 int type;
16294 uint32_t metric;
16295 struct bgp_redist *red;
16296 bool changed;
16297 struct route_map *route_map =
16298 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16299
16300 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16301 if (type < 0) {
16302 vty_out(vty, "%% Invalid route type\n");
16303 return CMD_WARNING_CONFIG_FAILED;
16304 }
16305 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16306
16307 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16308 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16309 changed |=
16310 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16311 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16312 }
16313
16314 ALIAS_HIDDEN(
16315 bgp_redistribute_ipv4_metric_rmap,
16316 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16317 "redistribute " FRR_IP_REDIST_STR_BGPD
16318 " metric (0-4294967295) route-map RMAP_NAME",
16319 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16320 "Metric for redistributed routes\n"
16321 "Default metric\n"
16322 "Route map reference\n"
16323 "Pointer to route-map entries\n")
16324
16325 DEFUN (bgp_redistribute_ipv4_ospf,
16326 bgp_redistribute_ipv4_ospf_cmd,
16327 "redistribute <ospf|table> (1-65535)",
16328 "Redistribute information from another routing protocol\n"
16329 "Open Shortest Path First (OSPFv2)\n"
16330 "Non-main Kernel Routing Table\n"
16331 "Instance ID/Table ID\n")
16332 {
16333 VTY_DECLVAR_CONTEXT(bgp, bgp);
16334 int idx_ospf_table = 1;
16335 int idx_number = 2;
16336 unsigned short instance;
16337 unsigned short protocol;
16338
16339 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16340
16341 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16342 protocol = ZEBRA_ROUTE_OSPF;
16343 else
16344 protocol = ZEBRA_ROUTE_TABLE;
16345
16346 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16347 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16348 }
16349
16350 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16351 "redistribute <ospf|table> (1-65535)",
16352 "Redistribute information from another routing protocol\n"
16353 "Open Shortest Path First (OSPFv2)\n"
16354 "Non-main Kernel Routing Table\n"
16355 "Instance ID/Table ID\n")
16356
16357 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16358 bgp_redistribute_ipv4_ospf_rmap_cmd,
16359 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16360 "Redistribute information from another routing protocol\n"
16361 "Open Shortest Path First (OSPFv2)\n"
16362 "Non-main Kernel Routing Table\n"
16363 "Instance ID/Table ID\n"
16364 "Route map reference\n"
16365 "Pointer to route-map entries\n")
16366 {
16367 VTY_DECLVAR_CONTEXT(bgp, bgp);
16368 int idx_ospf_table = 1;
16369 int idx_number = 2;
16370 int idx_word = 4;
16371 struct bgp_redist *red;
16372 unsigned short instance;
16373 int protocol;
16374 bool changed;
16375 struct route_map *route_map =
16376 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16377
16378 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16379 protocol = ZEBRA_ROUTE_OSPF;
16380 else
16381 protocol = ZEBRA_ROUTE_TABLE;
16382
16383 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16384 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16385 changed =
16386 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16387 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16388 }
16389
16390 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16391 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16392 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16393 "Redistribute information from another routing protocol\n"
16394 "Open Shortest Path First (OSPFv2)\n"
16395 "Non-main Kernel Routing Table\n"
16396 "Instance ID/Table ID\n"
16397 "Route map reference\n"
16398 "Pointer to route-map entries\n")
16399
16400 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16401 bgp_redistribute_ipv4_ospf_metric_cmd,
16402 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16403 "Redistribute information from another routing protocol\n"
16404 "Open Shortest Path First (OSPFv2)\n"
16405 "Non-main Kernel Routing Table\n"
16406 "Instance ID/Table ID\n"
16407 "Metric for redistributed routes\n"
16408 "Default metric\n")
16409 {
16410 VTY_DECLVAR_CONTEXT(bgp, bgp);
16411 int idx_ospf_table = 1;
16412 int idx_number = 2;
16413 int idx_number_2 = 4;
16414 uint32_t metric;
16415 struct bgp_redist *red;
16416 unsigned short instance;
16417 int protocol;
16418 bool changed;
16419
16420 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16421 protocol = ZEBRA_ROUTE_OSPF;
16422 else
16423 protocol = ZEBRA_ROUTE_TABLE;
16424
16425 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16426 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16427
16428 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16429 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16430 metric);
16431 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16432 }
16433
16434 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16435 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16436 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16437 "Redistribute information from another routing protocol\n"
16438 "Open Shortest Path First (OSPFv2)\n"
16439 "Non-main Kernel Routing Table\n"
16440 "Instance ID/Table ID\n"
16441 "Metric for redistributed routes\n"
16442 "Default metric\n")
16443
16444 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16445 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16446 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16447 "Redistribute information from another routing protocol\n"
16448 "Open Shortest Path First (OSPFv2)\n"
16449 "Non-main Kernel Routing Table\n"
16450 "Instance ID/Table ID\n"
16451 "Route map reference\n"
16452 "Pointer to route-map entries\n"
16453 "Metric for redistributed routes\n"
16454 "Default metric\n")
16455 {
16456 VTY_DECLVAR_CONTEXT(bgp, bgp);
16457 int idx_ospf_table = 1;
16458 int idx_number = 2;
16459 int idx_word = 4;
16460 int idx_number_2 = 6;
16461 uint32_t metric;
16462 struct bgp_redist *red;
16463 unsigned short instance;
16464 int protocol;
16465 bool changed;
16466 struct route_map *route_map =
16467 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16468
16469 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16470 protocol = ZEBRA_ROUTE_OSPF;
16471 else
16472 protocol = ZEBRA_ROUTE_TABLE;
16473
16474 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16475 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16476
16477 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16478 changed =
16479 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16480 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16481 metric);
16482 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16483 }
16484
16485 ALIAS_HIDDEN(
16486 bgp_redistribute_ipv4_ospf_rmap_metric,
16487 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16488 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16489 "Redistribute information from another routing protocol\n"
16490 "Open Shortest Path First (OSPFv2)\n"
16491 "Non-main Kernel Routing Table\n"
16492 "Instance ID/Table ID\n"
16493 "Route map reference\n"
16494 "Pointer to route-map entries\n"
16495 "Metric for redistributed routes\n"
16496 "Default metric\n")
16497
16498 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16499 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16500 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16501 "Redistribute information from another routing protocol\n"
16502 "Open Shortest Path First (OSPFv2)\n"
16503 "Non-main Kernel Routing Table\n"
16504 "Instance ID/Table ID\n"
16505 "Metric for redistributed routes\n"
16506 "Default metric\n"
16507 "Route map reference\n"
16508 "Pointer to route-map entries\n")
16509 {
16510 VTY_DECLVAR_CONTEXT(bgp, bgp);
16511 int idx_ospf_table = 1;
16512 int idx_number = 2;
16513 int idx_number_2 = 4;
16514 int idx_word = 6;
16515 uint32_t metric;
16516 struct bgp_redist *red;
16517 unsigned short instance;
16518 int protocol;
16519 bool changed;
16520 struct route_map *route_map =
16521 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16522
16523 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16524 protocol = ZEBRA_ROUTE_OSPF;
16525 else
16526 protocol = ZEBRA_ROUTE_TABLE;
16527
16528 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16529 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16530
16531 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16532 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16533 metric);
16534 changed |=
16535 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16536 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16537 }
16538
16539 ALIAS_HIDDEN(
16540 bgp_redistribute_ipv4_ospf_metric_rmap,
16541 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16542 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16543 "Redistribute information from another routing protocol\n"
16544 "Open Shortest Path First (OSPFv2)\n"
16545 "Non-main Kernel Routing Table\n"
16546 "Instance ID/Table ID\n"
16547 "Metric for redistributed routes\n"
16548 "Default metric\n"
16549 "Route map reference\n"
16550 "Pointer to route-map entries\n")
16551
16552 DEFUN (no_bgp_redistribute_ipv4_ospf,
16553 no_bgp_redistribute_ipv4_ospf_cmd,
16554 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16555 NO_STR
16556 "Redistribute information from another routing protocol\n"
16557 "Open Shortest Path First (OSPFv2)\n"
16558 "Non-main Kernel Routing Table\n"
16559 "Instance ID/Table ID\n"
16560 "Metric for redistributed routes\n"
16561 "Default metric\n"
16562 "Route map reference\n"
16563 "Pointer to route-map entries\n")
16564 {
16565 VTY_DECLVAR_CONTEXT(bgp, bgp);
16566 int idx_ospf_table = 2;
16567 int idx_number = 3;
16568 unsigned short instance;
16569 int protocol;
16570
16571 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16572 protocol = ZEBRA_ROUTE_OSPF;
16573 else
16574 protocol = ZEBRA_ROUTE_TABLE;
16575
16576 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16577 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16578 }
16579
16580 ALIAS_HIDDEN(
16581 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16582 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16583 NO_STR
16584 "Redistribute information from another routing protocol\n"
16585 "Open Shortest Path First (OSPFv2)\n"
16586 "Non-main Kernel Routing Table\n"
16587 "Instance ID/Table ID\n"
16588 "Metric for redistributed routes\n"
16589 "Default metric\n"
16590 "Route map reference\n"
16591 "Pointer to route-map entries\n")
16592
16593 DEFUN (no_bgp_redistribute_ipv4,
16594 no_bgp_redistribute_ipv4_cmd,
16595 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16596 NO_STR
16597 "Redistribute information from another routing protocol\n"
16598 FRR_IP_REDIST_HELP_STR_BGPD
16599 "Metric for redistributed routes\n"
16600 "Default metric\n"
16601 "Route map reference\n"
16602 "Pointer to route-map entries\n")
16603 {
16604 VTY_DECLVAR_CONTEXT(bgp, bgp);
16605 int idx_protocol = 2;
16606 int type;
16607
16608 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16609 if (type < 0) {
16610 vty_out(vty, "%% Invalid route type\n");
16611 return CMD_WARNING_CONFIG_FAILED;
16612 }
16613 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16614 }
16615
16616 ALIAS_HIDDEN(
16617 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16618 "no redistribute " FRR_IP_REDIST_STR_BGPD
16619 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16620 NO_STR
16621 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16622 "Metric for redistributed routes\n"
16623 "Default metric\n"
16624 "Route map reference\n"
16625 "Pointer to route-map entries\n")
16626
16627 DEFUN (bgp_redistribute_ipv6,
16628 bgp_redistribute_ipv6_cmd,
16629 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16630 "Redistribute information from another routing protocol\n"
16631 FRR_IP6_REDIST_HELP_STR_BGPD)
16632 {
16633 VTY_DECLVAR_CONTEXT(bgp, bgp);
16634 int idx_protocol = 1;
16635 int type;
16636
16637 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16638 if (type < 0) {
16639 vty_out(vty, "%% Invalid route type\n");
16640 return CMD_WARNING_CONFIG_FAILED;
16641 }
16642
16643 bgp_redist_add(bgp, AFI_IP6, type, 0);
16644 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16645 }
16646
16647 DEFUN (bgp_redistribute_ipv6_rmap,
16648 bgp_redistribute_ipv6_rmap_cmd,
16649 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16650 "Redistribute information from another routing protocol\n"
16651 FRR_IP6_REDIST_HELP_STR_BGPD
16652 "Route map reference\n"
16653 "Pointer to route-map entries\n")
16654 {
16655 VTY_DECLVAR_CONTEXT(bgp, bgp);
16656 int idx_protocol = 1;
16657 int idx_word = 3;
16658 int type;
16659 struct bgp_redist *red;
16660 bool changed;
16661 struct route_map *route_map =
16662 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16663
16664 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16665 if (type < 0) {
16666 vty_out(vty, "%% Invalid route type\n");
16667 return CMD_WARNING_CONFIG_FAILED;
16668 }
16669
16670 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16671 changed =
16672 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16673 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16674 }
16675
16676 DEFUN (bgp_redistribute_ipv6_metric,
16677 bgp_redistribute_ipv6_metric_cmd,
16678 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16679 "Redistribute information from another routing protocol\n"
16680 FRR_IP6_REDIST_HELP_STR_BGPD
16681 "Metric for redistributed routes\n"
16682 "Default metric\n")
16683 {
16684 VTY_DECLVAR_CONTEXT(bgp, bgp);
16685 int idx_protocol = 1;
16686 int idx_number = 3;
16687 int type;
16688 uint32_t metric;
16689 struct bgp_redist *red;
16690 bool changed;
16691
16692 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16693 if (type < 0) {
16694 vty_out(vty, "%% Invalid route type\n");
16695 return CMD_WARNING_CONFIG_FAILED;
16696 }
16697 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16698
16699 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16700 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16701 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16702 }
16703
16704 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16705 bgp_redistribute_ipv6_rmap_metric_cmd,
16706 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16707 "Redistribute information from another routing protocol\n"
16708 FRR_IP6_REDIST_HELP_STR_BGPD
16709 "Route map reference\n"
16710 "Pointer to route-map entries\n"
16711 "Metric for redistributed routes\n"
16712 "Default metric\n")
16713 {
16714 VTY_DECLVAR_CONTEXT(bgp, bgp);
16715 int idx_protocol = 1;
16716 int idx_word = 3;
16717 int idx_number = 5;
16718 int type;
16719 uint32_t metric;
16720 struct bgp_redist *red;
16721 bool changed;
16722 struct route_map *route_map =
16723 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16724
16725 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16726 if (type < 0) {
16727 vty_out(vty, "%% Invalid route type\n");
16728 return CMD_WARNING_CONFIG_FAILED;
16729 }
16730 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16731
16732 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16733 changed =
16734 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16735 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16736 metric);
16737 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16738 }
16739
16740 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16741 bgp_redistribute_ipv6_metric_rmap_cmd,
16742 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16743 "Redistribute information from another routing protocol\n"
16744 FRR_IP6_REDIST_HELP_STR_BGPD
16745 "Metric for redistributed routes\n"
16746 "Default metric\n"
16747 "Route map reference\n"
16748 "Pointer to route-map entries\n")
16749 {
16750 VTY_DECLVAR_CONTEXT(bgp, bgp);
16751 int idx_protocol = 1;
16752 int idx_number = 3;
16753 int idx_word = 5;
16754 int type;
16755 uint32_t metric;
16756 struct bgp_redist *red;
16757 bool changed;
16758 struct route_map *route_map =
16759 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16760
16761 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16762 if (type < 0) {
16763 vty_out(vty, "%% Invalid route type\n");
16764 return CMD_WARNING_CONFIG_FAILED;
16765 }
16766 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16767
16768 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16769 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16770 metric);
16771 changed |=
16772 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16773 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16774 }
16775
16776 DEFUN (no_bgp_redistribute_ipv6,
16777 no_bgp_redistribute_ipv6_cmd,
16778 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16779 NO_STR
16780 "Redistribute information from another routing protocol\n"
16781 FRR_IP6_REDIST_HELP_STR_BGPD
16782 "Metric for redistributed routes\n"
16783 "Default metric\n"
16784 "Route map reference\n"
16785 "Pointer to route-map entries\n")
16786 {
16787 VTY_DECLVAR_CONTEXT(bgp, bgp);
16788 int idx_protocol = 2;
16789 int type;
16790
16791 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16792 if (type < 0) {
16793 vty_out(vty, "%% Invalid route type\n");
16794 return CMD_WARNING_CONFIG_FAILED;
16795 }
16796
16797 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16798 }
16799
16800 /* Neighbor update tcp-mss. */
16801 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16802 const char *tcp_mss_str)
16803 {
16804 struct peer *peer;
16805 uint32_t tcp_mss_val = 0;
16806
16807 peer = peer_and_group_lookup_vty(vty, peer_str);
16808 if (!peer)
16809 return CMD_WARNING_CONFIG_FAILED;
16810
16811 if (tcp_mss_str) {
16812 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16813 peer_tcp_mss_set(peer, tcp_mss_val);
16814 } else {
16815 peer_tcp_mss_unset(peer);
16816 }
16817
16818 return CMD_SUCCESS;
16819 }
16820
16821 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16822 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16823 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16824 "TCP max segment size\n"
16825 "TCP MSS value\n")
16826 {
16827 int peer_index = 1;
16828 int mss_index = 3;
16829
16830 vty_out(vty,
16831 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16832 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16833 argv[mss_index]->arg);
16834 }
16835
16836 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16837 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16838 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16839 "TCP max segment size\n"
16840 "TCP MSS value\n")
16841 {
16842 int peer_index = 2;
16843
16844 vty_out(vty,
16845 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16846 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16847 }
16848
16849 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16850 "[no$no] bgp retain route-target all",
16851 NO_STR BGP_STR
16852 "Retain BGP updates\n"
16853 "Retain BGP updates based on route-target values\n"
16854 "Retain all BGP updates\n")
16855 {
16856 bool check;
16857 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16858
16859 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16860 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16861 if (check != !no) {
16862 if (!no)
16863 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16864 [bgp_node_safi(vty)],
16865 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16866 else
16867 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16868 [bgp_node_safi(vty)],
16869 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16870 /* trigger a flush to re-sync with ADJ-RIB-in */
16871 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16872 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16873 }
16874 return CMD_SUCCESS;
16875 }
16876
16877 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16878 afi_t afi, safi_t safi)
16879 {
16880 int i;
16881
16882 /* Unicast redistribution only. */
16883 if (safi != SAFI_UNICAST)
16884 return;
16885
16886 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16887 /* Redistribute BGP does not make sense. */
16888 if (i != ZEBRA_ROUTE_BGP) {
16889 struct list *red_list;
16890 struct listnode *node;
16891 struct bgp_redist *red;
16892
16893 red_list = bgp->redist[afi][i];
16894 if (!red_list)
16895 continue;
16896
16897 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16898 /* "redistribute" configuration. */
16899 vty_out(vty, " redistribute %s",
16900 zebra_route_string(i));
16901 if (red->instance)
16902 vty_out(vty, " %d", red->instance);
16903 if (red->redist_metric_flag)
16904 vty_out(vty, " metric %u",
16905 red->redist_metric);
16906 if (red->rmap.name)
16907 vty_out(vty, " route-map %s",
16908 red->rmap.name);
16909 vty_out(vty, "\n");
16910 }
16911 }
16912 }
16913 }
16914
16915 /* peer-group helpers for config-write */
16916
16917 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16918 {
16919 if (!peer_group_active(peer)) {
16920 if (CHECK_FLAG(peer->flags_invert, flag))
16921 return !CHECK_FLAG(peer->flags, flag);
16922 else
16923 return !!CHECK_FLAG(peer->flags, flag);
16924 }
16925
16926 return !!CHECK_FLAG(peer->flags_override, flag);
16927 }
16928
16929 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16930 uint64_t flag)
16931 {
16932 if (!peer_group_active(peer)) {
16933 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16934 return !peer_af_flag_check(peer, afi, safi, flag);
16935 else
16936 return !!peer_af_flag_check(peer, afi, safi, flag);
16937 }
16938
16939 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16940 }
16941
16942 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16943 uint8_t type, int direct)
16944 {
16945 struct bgp_filter *filter;
16946
16947 if (peer_group_active(peer))
16948 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16949 type);
16950
16951 filter = &peer->filter[afi][safi];
16952 switch (type) {
16953 case PEER_FT_DISTRIBUTE_LIST:
16954 return !!(filter->dlist[direct].name);
16955 case PEER_FT_FILTER_LIST:
16956 return !!(filter->aslist[direct].name);
16957 case PEER_FT_PREFIX_LIST:
16958 return !!(filter->plist[direct].name);
16959 case PEER_FT_ROUTE_MAP:
16960 return !!(filter->map[direct].name);
16961 case PEER_FT_UNSUPPRESS_MAP:
16962 return !!(filter->usmap.name);
16963 case PEER_FT_ADVERTISE_MAP:
16964 return !!(filter->advmap.aname
16965 && ((filter->advmap.condition == direct)
16966 && filter->advmap.cname));
16967 default:
16968 return false;
16969 }
16970 }
16971
16972 /* Return true if the addpath type is set for peer and different from
16973 * peer-group.
16974 */
16975 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16976 safi_t safi)
16977 {
16978 enum bgp_addpath_strat type, g_type;
16979
16980 type = peer->addpath_type[afi][safi];
16981
16982 if (type != BGP_ADDPATH_NONE) {
16983 if (peer_group_active(peer)) {
16984 g_type = peer->group->conf->addpath_type[afi][safi];
16985
16986 if (type != g_type)
16987 return true;
16988 else
16989 return false;
16990 }
16991
16992 return true;
16993 }
16994
16995 return false;
16996 }
16997
16998 /* This is part of the address-family block (unicast only) */
16999 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
17000 afi_t afi)
17001 {
17002 int indent = 2;
17003 uint32_t tovpn_sid_index = 0;
17004
17005 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
17006 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17007 BGP_CONFIG_VRF_TO_VRF_IMPORT))
17008 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17009 bgp->vpn_policy[afi]
17010 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17011 else
17012 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17013 bgp->vpn_policy[afi]
17014 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17015 }
17016 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17017 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17018 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17019 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17020 return;
17021
17022 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17023 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17024
17025 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17026
17027 } else {
17028 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17029 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17030 bgp->vpn_policy[afi].tovpn_label);
17031 }
17032 }
17033
17034 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17035 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17036 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17037 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17038 } else if (tovpn_sid_index != 0) {
17039 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17040 tovpn_sid_index);
17041 }
17042
17043 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17044 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
17045 &bgp->vpn_policy[afi].tovpn_rd);
17046
17047 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17048 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17049
17050 char buf[PREFIX_STRLEN];
17051 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17052 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17053 sizeof(buf))) {
17054
17055 vty_out(vty, "%*snexthop vpn export %s\n",
17056 indent, "", buf);
17057 }
17058 }
17059 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17060 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17061 && ecommunity_cmp(
17062 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17063 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17064
17065 char *b = ecommunity_ecom2str(
17066 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17067 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17068 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17069 XFREE(MTYPE_ECOMMUNITY_STR, b);
17070 } else {
17071 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17072 char *b = ecommunity_ecom2str(
17073 bgp->vpn_policy[afi]
17074 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17075 ECOMMUNITY_FORMAT_ROUTE_MAP,
17076 ECOMMUNITY_ROUTE_TARGET);
17077 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17078 XFREE(MTYPE_ECOMMUNITY_STR, b);
17079 }
17080 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17081 char *b = ecommunity_ecom2str(
17082 bgp->vpn_policy[afi]
17083 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17084 ECOMMUNITY_FORMAT_ROUTE_MAP,
17085 ECOMMUNITY_ROUTE_TARGET);
17086 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17087 XFREE(MTYPE_ECOMMUNITY_STR, b);
17088 }
17089 }
17090
17091 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17092 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17093 bgp->vpn_policy[afi]
17094 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17095
17096 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17097 char *b = ecommunity_ecom2str(
17098 bgp->vpn_policy[afi]
17099 .import_redirect_rtlist,
17100 ECOMMUNITY_FORMAT_ROUTE_MAP,
17101 ECOMMUNITY_ROUTE_TARGET);
17102
17103 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17104 != ECOMMUNITY_SIZE)
17105 vty_out(vty, "%*srt6 redirect import %s\n",
17106 indent, "", b);
17107 else
17108 vty_out(vty, "%*srt redirect import %s\n",
17109 indent, "", b);
17110 XFREE(MTYPE_ECOMMUNITY_STR, b);
17111 }
17112 }
17113
17114 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17115 afi_t afi, safi_t safi)
17116 {
17117 struct bgp_filter *filter;
17118 char *addr;
17119
17120 addr = peer->host;
17121 filter = &peer->filter[afi][safi];
17122
17123 /* distribute-list. */
17124 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17125 FILTER_IN))
17126 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17127 filter->dlist[FILTER_IN].name);
17128
17129 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17130 FILTER_OUT))
17131 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17132 filter->dlist[FILTER_OUT].name);
17133
17134 /* prefix-list. */
17135 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17136 FILTER_IN))
17137 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17138 filter->plist[FILTER_IN].name);
17139
17140 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17141 FILTER_OUT))
17142 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17143 filter->plist[FILTER_OUT].name);
17144
17145 /* route-map. */
17146 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17147 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17148 filter->map[RMAP_IN].name);
17149
17150 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17151 RMAP_OUT))
17152 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17153 filter->map[RMAP_OUT].name);
17154
17155 /* unsuppress-map */
17156 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17157 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17158 filter->usmap.name);
17159
17160 /* advertise-map : always applied in OUT direction*/
17161 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17162 CONDITION_NON_EXIST))
17163 vty_out(vty,
17164 " neighbor %s advertise-map %s non-exist-map %s\n",
17165 addr, filter->advmap.aname, filter->advmap.cname);
17166
17167 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17168 CONDITION_EXIST))
17169 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17170 addr, filter->advmap.aname, filter->advmap.cname);
17171
17172 /* filter-list. */
17173 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17174 FILTER_IN))
17175 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17176 filter->aslist[FILTER_IN].name);
17177
17178 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17179 FILTER_OUT))
17180 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17181 filter->aslist[FILTER_OUT].name);
17182 }
17183
17184 /* BGP peer configuration display function. */
17185 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17186 struct peer *peer)
17187 {
17188 struct peer *g_peer = NULL;
17189 char *addr;
17190 int if_pg_printed = false;
17191 int if_ras_printed = false;
17192
17193 /* Skip dynamic neighbors. */
17194 if (peer_dynamic_neighbor(peer))
17195 return;
17196
17197 if (peer->conf_if)
17198 addr = peer->conf_if;
17199 else
17200 addr = peer->host;
17201
17202 /************************************
17203 ****** Global to the neighbor ******
17204 ************************************/
17205 if (peer->conf_if) {
17206 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17207 vty_out(vty, " neighbor %s interface v6only", addr);
17208 else
17209 vty_out(vty, " neighbor %s interface", addr);
17210
17211 if (peer_group_active(peer)) {
17212 vty_out(vty, " peer-group %s", peer->group->name);
17213 if_pg_printed = true;
17214 } else if (peer->as_type == AS_SPECIFIED) {
17215 vty_out(vty, " remote-as %u", peer->as);
17216 if_ras_printed = true;
17217 } else if (peer->as_type == AS_INTERNAL) {
17218 vty_out(vty, " remote-as internal");
17219 if_ras_printed = true;
17220 } else if (peer->as_type == AS_EXTERNAL) {
17221 vty_out(vty, " remote-as external");
17222 if_ras_printed = true;
17223 }
17224
17225 vty_out(vty, "\n");
17226 }
17227
17228 /* remote-as and peer-group */
17229 /* peer is a member of a peer-group */
17230 if (peer_group_active(peer)) {
17231 g_peer = peer->group->conf;
17232
17233 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17234 if (peer->as_type == AS_SPECIFIED) {
17235 vty_out(vty, " neighbor %s remote-as %u\n",
17236 addr, peer->as);
17237 } else if (peer->as_type == AS_INTERNAL) {
17238 vty_out(vty,
17239 " neighbor %s remote-as internal\n",
17240 addr);
17241 } else if (peer->as_type == AS_EXTERNAL) {
17242 vty_out(vty,
17243 " neighbor %s remote-as external\n",
17244 addr);
17245 }
17246 }
17247
17248 /* For swpX peers we displayed the peer-group
17249 * via 'neighbor swpX interface peer-group PGNAME' */
17250 if (!if_pg_printed)
17251 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17252 peer->group->name);
17253 }
17254
17255 /* peer is NOT a member of a peer-group */
17256 else {
17257 /* peer is a peer-group, declare the peer-group */
17258 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17259 vty_out(vty, " neighbor %s peer-group\n", addr);
17260 }
17261
17262 if (!if_ras_printed) {
17263 if (peer->as_type == AS_SPECIFIED) {
17264 vty_out(vty, " neighbor %s remote-as %u\n",
17265 addr, peer->as);
17266 } else if (peer->as_type == AS_INTERNAL) {
17267 vty_out(vty,
17268 " neighbor %s remote-as internal\n",
17269 addr);
17270 } else if (peer->as_type == AS_EXTERNAL) {
17271 vty_out(vty,
17272 " neighbor %s remote-as external\n",
17273 addr);
17274 }
17275 }
17276 }
17277
17278 /* local-as */
17279 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17280 vty_out(vty, " neighbor %s local-as %u", addr,
17281 peer->change_local_as);
17282 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17283 vty_out(vty, " no-prepend");
17284 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17285 vty_out(vty, " replace-as");
17286 vty_out(vty, "\n");
17287 }
17288
17289 /* description */
17290 if (peer->desc) {
17291 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17292 }
17293
17294 /* shutdown */
17295 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17296 if (peer->tx_shutdown_message)
17297 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17298 peer->tx_shutdown_message);
17299 else
17300 vty_out(vty, " neighbor %s shutdown\n", addr);
17301 }
17302
17303 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17304 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17305 peer->rtt_expected, peer->rtt_keepalive_conf);
17306
17307 /* bfd */
17308 if (peer->bfd_config)
17309 bgp_bfd_peer_config_write(vty, peer, addr);
17310
17311 /* password */
17312 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17313 vty_out(vty, " neighbor %s password %s\n", addr,
17314 peer->password);
17315
17316 /* neighbor solo */
17317 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17318 if (!peer_group_active(peer)) {
17319 vty_out(vty, " neighbor %s solo\n", addr);
17320 }
17321 }
17322
17323 /* BGP port */
17324 if (peer->port != BGP_PORT_DEFAULT) {
17325 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17326 }
17327
17328 /* Local interface name */
17329 if (peer->ifname) {
17330 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17331 }
17332
17333 /* TCP max segment size */
17334 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17335 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17336
17337 /* passive */
17338 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17339 vty_out(vty, " neighbor %s passive\n", addr);
17340
17341 /* ebgp-multihop */
17342 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17343 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17344 && peer->ttl == MAXTTL)) {
17345 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17346 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17347 peer->ttl);
17348 }
17349 }
17350
17351 /* aigp */
17352 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17353 vty_out(vty, " neighbor %s aigp\n", addr);
17354
17355 /* graceful-shutdown */
17356 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17357 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17358
17359 /* role */
17360 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17361 peer->local_role != ROLE_UNDEFINED)
17362 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17363 bgp_get_name_by_role(peer->local_role),
17364 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17365 ? " strict-mode"
17366 : "");
17367
17368 /* ttl-security hops */
17369 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17370 if (!peer_group_active(peer)
17371 || g_peer->gtsm_hops != peer->gtsm_hops) {
17372 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17373 addr, peer->gtsm_hops);
17374 }
17375 }
17376
17377 /* disable-connected-check */
17378 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17379 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17380
17381 /* link-bw-encoding-ieee */
17382 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17383 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17384 addr);
17385
17386 /* extended-optional-parameters */
17387 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17388 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17389 addr);
17390
17391 /* enforce-first-as */
17392 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17393 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17394
17395 /* update-source */
17396 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17397 if (peer->update_source)
17398 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17399 peer->update_source);
17400 else if (peer->update_if)
17401 vty_out(vty, " neighbor %s update-source %s\n", addr,
17402 peer->update_if);
17403 }
17404
17405 /* advertisement-interval */
17406 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17407 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17408 peer->routeadv);
17409
17410 /* timers */
17411 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17412 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17413 peer->keepalive, peer->holdtime);
17414
17415 /* timers connect */
17416 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17417 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17418 peer->connect);
17419 /* need special-case handling for changed default values due to
17420 * config profile / version (because there is no "timers bgp connect"
17421 * command, we need to save this per-peer :/)
17422 */
17423 else if (!peer_group_active(peer) && !peer->connect &&
17424 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17425 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17426 peer->bgp->default_connect_retry);
17427
17428 /* timers delayopen */
17429 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17430 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17431 peer->delayopen);
17432 /* Save config even though flag is not set if default values have been
17433 * changed
17434 */
17435 else if (!peer_group_active(peer) && !peer->delayopen
17436 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17437 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17438 peer->bgp->default_delayopen);
17439
17440 /* capability dynamic */
17441 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17442 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17443
17444 /* capability extended-nexthop */
17445 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17446 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17447 !peer->conf_if)
17448 vty_out(vty,
17449 " no neighbor %s capability extended-nexthop\n",
17450 addr);
17451 else if (!peer->conf_if)
17452 vty_out(vty,
17453 " neighbor %s capability extended-nexthop\n",
17454 addr);
17455 }
17456
17457 /* dont-capability-negotiation */
17458 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17459 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17460
17461 /* override-capability */
17462 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17463 vty_out(vty, " neighbor %s override-capability\n", addr);
17464
17465 /* strict-capability-match */
17466 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17467 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17468
17469 /* Sender side AS path loop detection. */
17470 if (peer->as_path_loop_detection)
17471 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17472 addr);
17473
17474 /* path-attribute discard */
17475 char discard_attrs_str[BUFSIZ] = {0};
17476 bool discard_attrs = bgp_path_attribute_discard(
17477 peer, discard_attrs_str, sizeof(discard_attrs_str));
17478
17479 if (discard_attrs)
17480 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17481 discard_attrs_str);
17482
17483 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17484 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17485
17486 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17487 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17488 vty_out(vty,
17489 " neighbor %s graceful-restart-helper\n", addr);
17490 } else if (CHECK_FLAG(
17491 peer->peer_gr_new_status_flag,
17492 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17493 vty_out(vty,
17494 " neighbor %s graceful-restart\n", addr);
17495 } else if (
17496 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17497 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17498 && !(CHECK_FLAG(
17499 peer->peer_gr_new_status_flag,
17500 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17501 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17502 addr);
17503 }
17504 }
17505 }
17506
17507 /* BGP peer configuration display function. */
17508 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17509 struct peer *peer, afi_t afi, safi_t safi)
17510 {
17511 struct peer *g_peer = NULL;
17512 char *addr;
17513 bool flag_scomm, flag_secomm, flag_slcomm;
17514
17515 /* Skip dynamic neighbors. */
17516 if (peer_dynamic_neighbor(peer))
17517 return;
17518
17519 if (peer->conf_if)
17520 addr = peer->conf_if;
17521 else
17522 addr = peer->host;
17523
17524 /************************************
17525 ****** Per AF to the neighbor ******
17526 ************************************/
17527 if (peer_group_active(peer)) {
17528 g_peer = peer->group->conf;
17529
17530 /* If the peer-group is active but peer is not, print a 'no
17531 * activate' */
17532 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17533 vty_out(vty, " no neighbor %s activate\n", addr);
17534 }
17535
17536 /* If the peer-group is not active but peer is, print an
17537 'activate' */
17538 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17539 vty_out(vty, " neighbor %s activate\n", addr);
17540 }
17541 } else {
17542 if (peer->afc[afi][safi]) {
17543 if (safi == SAFI_ENCAP)
17544 vty_out(vty, " neighbor %s activate\n", addr);
17545 else if (!bgp->default_af[afi][safi])
17546 vty_out(vty, " neighbor %s activate\n", addr);
17547 } else {
17548 if (bgp->default_af[afi][safi])
17549 vty_out(vty, " no neighbor %s activate\n",
17550 addr);
17551 }
17552 }
17553
17554 /* addpath TX knobs */
17555 if (peergroup_af_addpath_check(peer, afi, safi)) {
17556 switch (peer->addpath_type[afi][safi]) {
17557 case BGP_ADDPATH_ALL:
17558 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17559 addr);
17560 break;
17561 case BGP_ADDPATH_BEST_PER_AS:
17562 vty_out(vty,
17563 " neighbor %s addpath-tx-bestpath-per-AS\n",
17564 addr);
17565 break;
17566 case BGP_ADDPATH_MAX:
17567 case BGP_ADDPATH_NONE:
17568 break;
17569 }
17570 }
17571
17572 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17573 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17574
17575 /* ORF capability. */
17576 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17577 || peergroup_af_flag_check(peer, afi, safi,
17578 PEER_FLAG_ORF_PREFIX_RM)) {
17579 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17580
17581 if (peergroup_af_flag_check(peer, afi, safi,
17582 PEER_FLAG_ORF_PREFIX_SM)
17583 && peergroup_af_flag_check(peer, afi, safi,
17584 PEER_FLAG_ORF_PREFIX_RM))
17585 vty_out(vty, " both");
17586 else if (peergroup_af_flag_check(peer, afi, safi,
17587 PEER_FLAG_ORF_PREFIX_SM))
17588 vty_out(vty, " send");
17589 else
17590 vty_out(vty, " receive");
17591 vty_out(vty, "\n");
17592 }
17593
17594 /* Route reflector client. */
17595 if (peergroup_af_flag_check(peer, afi, safi,
17596 PEER_FLAG_REFLECTOR_CLIENT)) {
17597 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17598 }
17599
17600 /* next-hop-self force */
17601 if (peergroup_af_flag_check(peer, afi, safi,
17602 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17603 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17604 }
17605
17606 /* next-hop-self */
17607 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17608 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17609 }
17610
17611 /* remove-private-AS */
17612 if (peergroup_af_flag_check(peer, afi, safi,
17613 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17614 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17615 addr);
17616 }
17617
17618 else if (peergroup_af_flag_check(peer, afi, safi,
17619 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17620 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17621 addr);
17622 }
17623
17624 else if (peergroup_af_flag_check(peer, afi, safi,
17625 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17626 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17627 }
17628
17629 else if (peergroup_af_flag_check(peer, afi, safi,
17630 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17631 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17632 }
17633
17634 /* as-override */
17635 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17636 vty_out(vty, " neighbor %s as-override\n", addr);
17637 }
17638
17639 /* send-community print. */
17640 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17641 PEER_FLAG_SEND_COMMUNITY);
17642 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17643 PEER_FLAG_SEND_EXT_COMMUNITY);
17644 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17645 PEER_FLAG_SEND_LARGE_COMMUNITY);
17646
17647 if (flag_scomm && flag_secomm && flag_slcomm) {
17648 vty_out(vty, " no neighbor %s send-community all\n", addr);
17649 } else {
17650 if (flag_scomm)
17651 vty_out(vty, " no neighbor %s send-community\n", addr);
17652 if (flag_secomm)
17653 vty_out(vty,
17654 " no neighbor %s send-community extended\n",
17655 addr);
17656
17657 if (flag_slcomm)
17658 vty_out(vty, " no neighbor %s send-community large\n",
17659 addr);
17660 }
17661
17662 /* Default information */
17663 if (peergroup_af_flag_check(peer, afi, safi,
17664 PEER_FLAG_DEFAULT_ORIGINATE)) {
17665 vty_out(vty, " neighbor %s default-originate", addr);
17666
17667 if (peer->default_rmap[afi][safi].name)
17668 vty_out(vty, " route-map %s",
17669 peer->default_rmap[afi][safi].name);
17670
17671 vty_out(vty, "\n");
17672 }
17673
17674 /* Soft reconfiguration inbound. */
17675 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17676 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17677 addr);
17678 }
17679
17680 /* maximum-prefix. */
17681 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17682 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17683 peer->pmax[afi][safi]);
17684
17685 if (peer->pmax_threshold[afi][safi]
17686 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17687 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17688 if (peer_af_flag_check(peer, afi, safi,
17689 PEER_FLAG_MAX_PREFIX_WARNING))
17690 vty_out(vty, " warning-only");
17691 if (peer->pmax_restart[afi][safi])
17692 vty_out(vty, " restart %u",
17693 peer->pmax_restart[afi][safi]);
17694 if (peer_af_flag_check(peer, afi, safi,
17695 PEER_FLAG_MAX_PREFIX_FORCE))
17696 vty_out(vty, " force");
17697
17698 vty_out(vty, "\n");
17699 }
17700
17701 /* maximum-prefix-out */
17702 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17703 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17704 addr, peer->pmax_out[afi][safi]);
17705
17706 /* Route server client. */
17707 if (peergroup_af_flag_check(peer, afi, safi,
17708 PEER_FLAG_RSERVER_CLIENT)) {
17709 vty_out(vty, " neighbor %s route-server-client\n", addr);
17710 }
17711
17712 /* Nexthop-local unchanged. */
17713 if (peergroup_af_flag_check(peer, afi, safi,
17714 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17715 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17716 }
17717
17718 /* allowas-in <1-10> */
17719 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17720 if (peer_af_flag_check(peer, afi, safi,
17721 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17722 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17723 } else if (peer->allowas_in[afi][safi] == 3) {
17724 vty_out(vty, " neighbor %s allowas-in\n", addr);
17725 } else {
17726 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17727 peer->allowas_in[afi][safi]);
17728 }
17729 }
17730
17731 /* accept-own */
17732 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17733 vty_out(vty, " neighbor %s accept-own\n", addr);
17734
17735 /* soo */
17736 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17737 char *soo_str = ecommunity_ecom2str(
17738 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17739
17740 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17741 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17742 }
17743
17744 /* weight */
17745 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17746 vty_out(vty, " neighbor %s weight %lu\n", addr,
17747 peer->weight[afi][safi]);
17748
17749 /* Filter. */
17750 bgp_config_write_filter(vty, peer, afi, safi);
17751
17752 /* atribute-unchanged. */
17753 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17754 || (safi != SAFI_EVPN
17755 && peer_af_flag_check(peer, afi, safi,
17756 PEER_FLAG_NEXTHOP_UNCHANGED))
17757 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17758
17759 if (!peer_group_active(peer)
17760 || peergroup_af_flag_check(peer, afi, safi,
17761 PEER_FLAG_AS_PATH_UNCHANGED)
17762 || peergroup_af_flag_check(peer, afi, safi,
17763 PEER_FLAG_NEXTHOP_UNCHANGED)
17764 || peergroup_af_flag_check(peer, afi, safi,
17765 PEER_FLAG_MED_UNCHANGED)) {
17766
17767 vty_out(vty,
17768 " neighbor %s attribute-unchanged%s%s%s\n",
17769 addr,
17770 peer_af_flag_check(peer, afi, safi,
17771 PEER_FLAG_AS_PATH_UNCHANGED)
17772 ? " as-path"
17773 : "",
17774 peer_af_flag_check(peer, afi, safi,
17775 PEER_FLAG_NEXTHOP_UNCHANGED)
17776 ? " next-hop"
17777 : "",
17778 peer_af_flag_check(peer, afi, safi,
17779 PEER_FLAG_MED_UNCHANGED)
17780 ? " med"
17781 : "");
17782 }
17783 }
17784 }
17785
17786 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17787 safi_t safi)
17788 {
17789 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17790 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17791 vty_out(vty, " no bgp retain route-target all\n");
17792 }
17793
17794 /* Address family based peer configuration display. */
17795 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17796 safi_t safi)
17797 {
17798 struct peer *peer;
17799 struct peer_group *group;
17800 struct listnode *node, *nnode;
17801
17802
17803 vty_frame(vty, " !\n address-family ");
17804 if (afi == AFI_IP) {
17805 if (safi == SAFI_UNICAST)
17806 vty_frame(vty, "ipv4 unicast");
17807 else if (safi == SAFI_LABELED_UNICAST)
17808 vty_frame(vty, "ipv4 labeled-unicast");
17809 else if (safi == SAFI_MULTICAST)
17810 vty_frame(vty, "ipv4 multicast");
17811 else if (safi == SAFI_MPLS_VPN)
17812 vty_frame(vty, "ipv4 vpn");
17813 else if (safi == SAFI_ENCAP)
17814 vty_frame(vty, "ipv4 encap");
17815 else if (safi == SAFI_FLOWSPEC)
17816 vty_frame(vty, "ipv4 flowspec");
17817 } else if (afi == AFI_IP6) {
17818 if (safi == SAFI_UNICAST)
17819 vty_frame(vty, "ipv6 unicast");
17820 else if (safi == SAFI_LABELED_UNICAST)
17821 vty_frame(vty, "ipv6 labeled-unicast");
17822 else if (safi == SAFI_MULTICAST)
17823 vty_frame(vty, "ipv6 multicast");
17824 else if (safi == SAFI_MPLS_VPN)
17825 vty_frame(vty, "ipv6 vpn");
17826 else if (safi == SAFI_ENCAP)
17827 vty_frame(vty, "ipv6 encap");
17828 else if (safi == SAFI_FLOWSPEC)
17829 vty_frame(vty, "ipv6 flowspec");
17830 } else if (afi == AFI_L2VPN) {
17831 if (safi == SAFI_EVPN)
17832 vty_frame(vty, "l2vpn evpn");
17833 }
17834 vty_frame(vty, "\n");
17835
17836 bgp_config_write_distance(vty, bgp, afi, safi);
17837
17838 bgp_config_write_network(vty, bgp, afi, safi);
17839
17840 bgp_config_write_redistribute(vty, bgp, afi, safi);
17841
17842 /* BGP flag dampening. */
17843 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17844 bgp_config_write_damp(vty, afi, safi);
17845
17846 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17847 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17848
17849 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17850 /* Do not display doppelganger peers */
17851 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17852 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17853 }
17854
17855 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17856 bgp_config_write_table_map(vty, bgp, afi, safi);
17857
17858 if (safi == SAFI_EVPN)
17859 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17860
17861 if (safi == SAFI_FLOWSPEC)
17862 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17863
17864 if (safi == SAFI_MPLS_VPN)
17865 bgp_vpn_config_write(vty, bgp, afi, safi);
17866
17867 if (safi == SAFI_UNICAST) {
17868 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17869 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17870 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17871
17872 vty_out(vty, " export vpn\n");
17873 }
17874 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17875 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17876
17877 vty_out(vty, " import vpn\n");
17878 }
17879 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17880 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17881 char *name;
17882
17883 for (ALL_LIST_ELEMENTS_RO(
17884 bgp->vpn_policy[afi].import_vrf, node,
17885 name))
17886 vty_out(vty, " import vrf %s\n", name);
17887 }
17888 }
17889
17890 vty_endframe(vty, " exit-address-family\n");
17891 }
17892
17893 int bgp_config_write(struct vty *vty)
17894 {
17895 struct bgp *bgp;
17896 struct peer_group *group;
17897 struct peer *peer;
17898 struct listnode *node, *nnode;
17899 struct listnode *mnode, *mnnode;
17900 afi_t afi;
17901 safi_t safi;
17902 uint32_t tovpn_sid_index = 0;
17903
17904 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17905 vty_out(vty, "bgp route-map delay-timer %u\n",
17906 bm->rmap_update_timer);
17907
17908 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17909 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17910 if (bm->v_update_delay != bm->v_establish_wait)
17911 vty_out(vty, " %d", bm->v_establish_wait);
17912 vty_out(vty, "\n");
17913 }
17914
17915 if (bm->wait_for_fib)
17916 vty_out(vty, "bgp suppress-fib-pending\n");
17917
17918 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17919 vty_out(vty, "bgp graceful-shutdown\n");
17920
17921 /* No-RIB (Zebra) option flag configuration */
17922 if (bgp_option_check(BGP_OPT_NO_FIB))
17923 vty_out(vty, "bgp no-rib\n");
17924
17925 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17926 vty_out(vty, "bgp send-extra-data zebra\n");
17927
17928 /* BGP session DSCP value */
17929 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17930 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17931
17932 /* BGP InQ limit */
17933 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
17934 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17935
17936 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
17937 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
17938
17939 /* BGP configuration. */
17940 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17941
17942 /* skip all auto created vrf as they dont have user config */
17943 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17944 continue;
17945
17946 /* Router bgp ASN */
17947 vty_out(vty, "router bgp %u", bgp->as);
17948
17949 if (bgp->name)
17950 vty_out(vty, " %s %s",
17951 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17952 ? "view" : "vrf", bgp->name);
17953 vty_out(vty, "\n");
17954
17955 /* BGP fast-external-failover. */
17956 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17957 vty_out(vty, " no bgp fast-external-failover\n");
17958
17959 /* BGP router ID. */
17960 if (bgp->router_id_static.s_addr != INADDR_ANY)
17961 vty_out(vty, " bgp router-id %pI4\n",
17962 &bgp->router_id_static);
17963
17964 /* Suppress fib pending */
17965 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17966 vty_out(vty, " bgp suppress-fib-pending\n");
17967
17968 /* BGP log-neighbor-changes. */
17969 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17970 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17971 vty_out(vty, " %sbgp log-neighbor-changes\n",
17972 CHECK_FLAG(bgp->flags,
17973 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17974 ? ""
17975 : "no ");
17976
17977 /* BGP configuration. */
17978 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17979 vty_out(vty, " bgp always-compare-med\n");
17980
17981 /* RFC8212 default eBGP policy. */
17982 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17983 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17984 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17985 CHECK_FLAG(bgp->flags,
17986 BGP_FLAG_EBGP_REQUIRES_POLICY)
17987 ? ""
17988 : "no ");
17989
17990 /* draft-ietf-idr-deprecate-as-set-confed-set */
17991 if (bgp->reject_as_sets)
17992 vty_out(vty, " bgp reject-as-sets\n");
17993
17994 /* Suppress duplicate updates if the route actually not changed
17995 */
17996 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17997 != SAVE_BGP_SUPPRESS_DUPLICATES)
17998 vty_out(vty, " %sbgp suppress-duplicates\n",
17999 CHECK_FLAG(bgp->flags,
18000 BGP_FLAG_SUPPRESS_DUPLICATES)
18001 ? ""
18002 : "no ");
18003
18004 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18005 */
18006 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18007 SAVE_BGP_HARD_ADMIN_RESET)
18008 vty_out(vty, " %sbgp hard-administrative-reset\n",
18009 CHECK_FLAG(bgp->flags,
18010 BGP_FLAG_HARD_ADMIN_RESET)
18011 ? ""
18012 : "no ");
18013
18014 /* BGP default <afi>-<safi> */
18015 FOREACH_AFI_SAFI (afi, safi) {
18016 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18017 if (!bgp->default_af[afi][safi])
18018 vty_out(vty, " no bgp default %s\n",
18019 get_bgp_default_af_flag(afi,
18020 safi));
18021 } else if (bgp->default_af[afi][safi])
18022 vty_out(vty, " bgp default %s\n",
18023 get_bgp_default_af_flag(afi, safi));
18024 }
18025
18026 /* BGP default local-preference. */
18027 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18028 vty_out(vty, " bgp default local-preference %u\n",
18029 bgp->default_local_pref);
18030
18031 /* BGP default show-hostname */
18032 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18033 != SAVE_BGP_SHOW_HOSTNAME)
18034 vty_out(vty, " %sbgp default show-hostname\n",
18035 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18036 ? ""
18037 : "no ");
18038
18039 /* BGP default show-nexthop-hostname */
18040 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18041 != SAVE_BGP_SHOW_HOSTNAME)
18042 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18043 CHECK_FLAG(bgp->flags,
18044 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18045 ? ""
18046 : "no ");
18047
18048 /* BGP default subgroup-pkt-queue-max. */
18049 if (bgp->default_subgroup_pkt_queue_max
18050 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18051 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18052 bgp->default_subgroup_pkt_queue_max);
18053
18054 /* BGP client-to-client reflection. */
18055 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
18056 vty_out(vty, " no bgp client-to-client reflection\n");
18057
18058 /* BGP cluster ID. */
18059 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
18060 vty_out(vty, " bgp cluster-id %pI4\n",
18061 &bgp->cluster_id);
18062
18063 /* Disable ebgp connected nexthop check */
18064 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
18065 vty_out(vty,
18066 " bgp disable-ebgp-connected-route-check\n");
18067
18068 /* Confederation identifier*/
18069 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18070 vty_out(vty, " bgp confederation identifier %u\n",
18071 bgp->confed_id);
18072
18073 /* Confederation peer */
18074 if (bgp->confed_peers_cnt > 0) {
18075 int i;
18076
18077 vty_out(vty, " bgp confederation peers");
18078
18079 for (i = 0; i < bgp->confed_peers_cnt; i++)
18080 vty_out(vty, " %u", bgp->confed_peers[i]);
18081
18082 vty_out(vty, "\n");
18083 }
18084
18085 /* BGP deterministic-med. */
18086 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18087 != SAVE_BGP_DETERMINISTIC_MED)
18088 vty_out(vty, " %sbgp deterministic-med\n",
18089 CHECK_FLAG(bgp->flags,
18090 BGP_FLAG_DETERMINISTIC_MED)
18091 ? ""
18092 : "no ");
18093
18094 /* BGP update-delay. */
18095 bgp_config_write_update_delay(vty, bgp);
18096
18097 if (bgp->v_maxmed_onstartup
18098 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18099 vty_out(vty, " bgp max-med on-startup %u",
18100 bgp->v_maxmed_onstartup);
18101 if (bgp->maxmed_onstartup_value
18102 != BGP_MAXMED_VALUE_DEFAULT)
18103 vty_out(vty, " %u",
18104 bgp->maxmed_onstartup_value);
18105 vty_out(vty, "\n");
18106 }
18107 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18108 vty_out(vty, " bgp max-med administrative");
18109 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18110 vty_out(vty, " %u", bgp->maxmed_admin_value);
18111 vty_out(vty, "\n");
18112 }
18113
18114 /* write quanta */
18115 bgp_config_write_wpkt_quanta(vty, bgp);
18116 /* read quanta */
18117 bgp_config_write_rpkt_quanta(vty, bgp);
18118
18119 /* coalesce time */
18120 bgp_config_write_coalesce_time(vty, bgp);
18121
18122 /* BGP per-instance graceful-shutdown */
18123 /* BGP-wide settings and per-instance settings are mutually
18124 * exclusive.
18125 */
18126 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18127 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18128 vty_out(vty, " bgp graceful-shutdown\n");
18129
18130 /* Long-lived Graceful Restart */
18131 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18132 vty_out(vty,
18133 " bgp long-lived-graceful-restart stale-time %u\n",
18134 bgp->llgr_stale_time);
18135
18136 /* BGP graceful-restart. */
18137 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18138 vty_out(vty,
18139 " bgp graceful-restart stalepath-time %u\n",
18140 bgp->stalepath_time);
18141
18142 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18143 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18144 bgp->restart_time);
18145
18146 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18147 SAVE_BGP_GRACEFUL_NOTIFICATION)
18148 vty_out(vty, " %sbgp graceful-restart notification\n",
18149 CHECK_FLAG(bgp->flags,
18150 BGP_FLAG_GRACEFUL_NOTIFICATION)
18151 ? ""
18152 : "no ");
18153
18154 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18155 vty_out(vty,
18156 " bgp graceful-restart select-defer-time %u\n",
18157 bgp->select_defer_time);
18158
18159 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18160 vty_out(vty, " bgp graceful-restart\n");
18161
18162 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18163 vty_out(vty, " bgp graceful-restart-disable\n");
18164
18165 /* BGP graceful-restart Preserve State F bit. */
18166 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18167 vty_out(vty,
18168 " bgp graceful-restart preserve-fw-state\n");
18169
18170 /* BGP TCP keepalive */
18171 bgp_config_tcp_keepalive(vty, bgp);
18172
18173 /* Stale timer for RIB */
18174 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18175 vty_out(vty,
18176 " bgp graceful-restart rib-stale-time %u\n",
18177 bgp->rib_stale_time);
18178
18179 /* BGP bestpath method. */
18180 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18181 vty_out(vty, " bgp bestpath as-path ignore\n");
18182 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18183 vty_out(vty, " bgp bestpath as-path confed\n");
18184
18185 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18186 if (CHECK_FLAG(bgp->flags,
18187 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18188 vty_out(vty,
18189 " bgp bestpath as-path multipath-relax as-set\n");
18190 } else {
18191 vty_out(vty,
18192 " bgp bestpath as-path multipath-relax\n");
18193 }
18194 }
18195
18196 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18197 vty_out(vty,
18198 " bgp route-reflector allow-outbound-policy\n");
18199 }
18200 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18201 vty_out(vty, " bgp bestpath compare-routerid\n");
18202 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18203 vty_out(vty, " bgp bestpath aigp\n");
18204 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18205 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18206 vty_out(vty, " bgp bestpath med");
18207 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18208 vty_out(vty, " confed");
18209 if (CHECK_FLAG(bgp->flags,
18210 BGP_FLAG_MED_MISSING_AS_WORST))
18211 vty_out(vty, " missing-as-worst");
18212 vty_out(vty, "\n");
18213 }
18214
18215 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18216 vty_out(vty,
18217 " bgp bestpath peer-type multipath-relax\n");
18218
18219 /* Link bandwidth handling. */
18220 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18221 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18222 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18223 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18224 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18225 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18226
18227 /* BGP network import check. */
18228 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18229 != SAVE_BGP_IMPORT_CHECK)
18230 vty_out(vty, " %sbgp network import-check\n",
18231 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18232 ? ""
18233 : "no ");
18234
18235 /* BGP timers configuration. */
18236 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18237 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18238 vty_out(vty, " timers bgp %u %u\n",
18239 bgp->default_keepalive, bgp->default_holdtime);
18240
18241 /* BGP minimum holdtime configuration. */
18242 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18243 && bgp->default_min_holdtime != 0)
18244 vty_out(vty, " bgp minimum-holdtime %u\n",
18245 bgp->default_min_holdtime);
18246
18247 /* Conditional advertisement timer configuration */
18248 if (bgp->condition_check_period
18249 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18250 vty_out(vty,
18251 " bgp conditional-advertisement timer %u\n",
18252 bgp->condition_check_period);
18253
18254 /* peer-group */
18255 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18256 bgp_config_write_peer_global(vty, bgp, group->conf);
18257 }
18258
18259 /* Normal neighbor configuration. */
18260 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18261 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18262 bgp_config_write_peer_global(vty, bgp, peer);
18263 }
18264
18265 /* listen range and limit for dynamic BGP neighbors */
18266 bgp_config_write_listen(vty, bgp);
18267
18268 /*
18269 * BGP default autoshutdown neighbors
18270 *
18271 * This must be placed after any peer and peer-group
18272 * configuration, to avoid setting all peers to shutdown after
18273 * a daemon restart, which is undesired behavior. (see #2286)
18274 */
18275 if (bgp->autoshutdown)
18276 vty_out(vty, " bgp default shutdown\n");
18277
18278 /* BGP instance administrative shutdown */
18279 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18280 vty_out(vty, " bgp shutdown\n");
18281
18282 if (bgp->allow_martian)
18283 vty_out(vty, " bgp allow-martian-nexthop\n");
18284
18285 if (bgp->fast_convergence)
18286 vty_out(vty, " bgp fast-convergence\n");
18287
18288 if (bgp->srv6_enabled) {
18289 vty_frame(vty, " !\n segment-routing srv6\n");
18290 if (strlen(bgp->srv6_locator_name))
18291 vty_out(vty, " locator %s\n",
18292 bgp->srv6_locator_name);
18293 vty_endframe(vty, " exit\n");
18294 }
18295
18296 tovpn_sid_index = bgp->tovpn_sid_index;
18297 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18298 vty_out(vty, " sid vpn per-vrf export auto\n");
18299 } else if (tovpn_sid_index != 0) {
18300 vty_out(vty, " sid vpn per-vrf export %d\n",
18301 tovpn_sid_index);
18302 }
18303
18304 /* IPv4 unicast configuration. */
18305 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18306
18307 /* IPv4 multicast configuration. */
18308 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18309
18310 /* IPv4 labeled-unicast configuration. */
18311 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18312
18313 /* IPv4 VPN configuration. */
18314 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18315
18316 /* ENCAPv4 configuration. */
18317 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18318
18319 /* FLOWSPEC v4 configuration. */
18320 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18321
18322 /* IPv6 unicast configuration. */
18323 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18324
18325 /* IPv6 multicast configuration. */
18326 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18327
18328 /* IPv6 labeled-unicast configuration. */
18329 bgp_config_write_family(vty, bgp, AFI_IP6,
18330 SAFI_LABELED_UNICAST);
18331
18332 /* IPv6 VPN configuration. */
18333 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18334
18335 /* ENCAPv6 configuration. */
18336 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18337
18338 /* FLOWSPEC v6 configuration. */
18339 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18340
18341 /* EVPN configuration. */
18342 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18343
18344 hook_call(bgp_inst_config_write, bgp, vty);
18345
18346 #ifdef ENABLE_BGP_VNC
18347 bgp_rfapi_cfg_write(vty, bgp);
18348 #endif
18349
18350 vty_out(vty, "exit\n");
18351 vty_out(vty, "!\n");
18352 }
18353 return 0;
18354 }
18355
18356
18357 /* BGP node structure. */
18358 static struct cmd_node bgp_node = {
18359 .name = "bgp",
18360 .node = BGP_NODE,
18361 .parent_node = CONFIG_NODE,
18362 .prompt = "%s(config-router)# ",
18363 .config_write = bgp_config_write,
18364 };
18365
18366 static struct cmd_node bgp_ipv4_unicast_node = {
18367 .name = "bgp ipv4 unicast",
18368 .node = BGP_IPV4_NODE,
18369 .parent_node = BGP_NODE,
18370 .prompt = "%s(config-router-af)# ",
18371 .no_xpath = true,
18372 };
18373
18374 static struct cmd_node bgp_ipv4_multicast_node = {
18375 .name = "bgp ipv4 multicast",
18376 .node = BGP_IPV4M_NODE,
18377 .parent_node = BGP_NODE,
18378 .prompt = "%s(config-router-af)# ",
18379 .no_xpath = true,
18380 };
18381
18382 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18383 .name = "bgp ipv4 labeled unicast",
18384 .node = BGP_IPV4L_NODE,
18385 .parent_node = BGP_NODE,
18386 .prompt = "%s(config-router-af)# ",
18387 .no_xpath = true,
18388 };
18389
18390 static struct cmd_node bgp_ipv6_unicast_node = {
18391 .name = "bgp ipv6 unicast",
18392 .node = BGP_IPV6_NODE,
18393 .parent_node = BGP_NODE,
18394 .prompt = "%s(config-router-af)# ",
18395 .no_xpath = true,
18396 };
18397
18398 static struct cmd_node bgp_ipv6_multicast_node = {
18399 .name = "bgp ipv6 multicast",
18400 .node = BGP_IPV6M_NODE,
18401 .parent_node = BGP_NODE,
18402 .prompt = "%s(config-router-af)# ",
18403 .no_xpath = true,
18404 };
18405
18406 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18407 .name = "bgp ipv6 labeled unicast",
18408 .node = BGP_IPV6L_NODE,
18409 .parent_node = BGP_NODE,
18410 .prompt = "%s(config-router-af)# ",
18411 .no_xpath = true,
18412 };
18413
18414 static struct cmd_node bgp_vpnv4_node = {
18415 .name = "bgp vpnv4",
18416 .node = BGP_VPNV4_NODE,
18417 .parent_node = BGP_NODE,
18418 .prompt = "%s(config-router-af)# ",
18419 .no_xpath = true,
18420 };
18421
18422 static struct cmd_node bgp_vpnv6_node = {
18423 .name = "bgp vpnv6",
18424 .node = BGP_VPNV6_NODE,
18425 .parent_node = BGP_NODE,
18426 .prompt = "%s(config-router-af-vpnv6)# ",
18427 .no_xpath = true,
18428 };
18429
18430 static struct cmd_node bgp_evpn_node = {
18431 .name = "bgp evpn",
18432 .node = BGP_EVPN_NODE,
18433 .parent_node = BGP_NODE,
18434 .prompt = "%s(config-router-evpn)# ",
18435 .no_xpath = true,
18436 };
18437
18438 static struct cmd_node bgp_evpn_vni_node = {
18439 .name = "bgp evpn vni",
18440 .node = BGP_EVPN_VNI_NODE,
18441 .parent_node = BGP_EVPN_NODE,
18442 .prompt = "%s(config-router-af-vni)# ",
18443 };
18444
18445 static struct cmd_node bgp_flowspecv4_node = {
18446 .name = "bgp ipv4 flowspec",
18447 .node = BGP_FLOWSPECV4_NODE,
18448 .parent_node = BGP_NODE,
18449 .prompt = "%s(config-router-af)# ",
18450 .no_xpath = true,
18451 };
18452
18453 static struct cmd_node bgp_flowspecv6_node = {
18454 .name = "bgp ipv6 flowspec",
18455 .node = BGP_FLOWSPECV6_NODE,
18456 .parent_node = BGP_NODE,
18457 .prompt = "%s(config-router-af-vpnv6)# ",
18458 .no_xpath = true,
18459 };
18460
18461 static struct cmd_node bgp_srv6_node = {
18462 .name = "bgp srv6",
18463 .node = BGP_SRV6_NODE,
18464 .parent_node = BGP_NODE,
18465 .prompt = "%s(config-router-srv6)# ",
18466 };
18467
18468 static void community_list_vty(void);
18469
18470 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18471 {
18472 struct bgp *bgp;
18473 struct peer_group *group;
18474 struct listnode *lnbgp, *lnpeer;
18475
18476 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18477 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18478 vector_set(comps,
18479 XSTRDUP(MTYPE_COMPLETION, group->name));
18480 }
18481 }
18482
18483 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18484 {
18485 struct bgp *bgp;
18486 struct peer *peer;
18487 struct listnode *lnbgp, *lnpeer;
18488
18489 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18490 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18491 /* only provide suggestions on the appropriate input
18492 * token type,
18493 * they'll otherwise show up multiple times */
18494 enum cmd_token_type match_type;
18495 char *name = peer->host;
18496
18497 if (peer->conf_if) {
18498 match_type = VARIABLE_TKN;
18499 name = peer->conf_if;
18500 } else if (strchr(peer->host, ':'))
18501 match_type = IPV6_TKN;
18502 else
18503 match_type = IPV4_TKN;
18504
18505 if (token->type != match_type)
18506 continue;
18507
18508 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18509 }
18510 }
18511 }
18512
18513 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18514 {
18515 bgp_ac_peer(comps, token);
18516
18517 if (token->type == VARIABLE_TKN)
18518 bgp_ac_peergroup(comps, token);
18519 }
18520
18521 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18522 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18523 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18524 {.varname = "peer", .completions = bgp_ac_neighbor},
18525 {.completions = NULL}};
18526
18527 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18528 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18529 {.completions = NULL} };
18530
18531 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18532
18533 static struct thread *t_bgp_cfg;
18534
18535 bool bgp_config_inprocess(void)
18536 {
18537 return thread_is_scheduled(t_bgp_cfg);
18538 }
18539
18540 static void bgp_config_finish(struct thread *t)
18541 {
18542 struct listnode *node;
18543 struct bgp *bgp;
18544
18545 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18546 hook_call(bgp_config_end, bgp);
18547 }
18548
18549 static void bgp_config_start(void)
18550 {
18551 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18552 THREAD_OFF(t_bgp_cfg);
18553 thread_add_timer(bm->master, bgp_config_finish, NULL,
18554 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18555 }
18556
18557 /* When we receive a hook the configuration is read,
18558 * we start a timer to make sure we postpone sending
18559 * EoR before route-maps are processed.
18560 * This is especially valid if using `bgp route-map delay-timer`.
18561 */
18562 static void bgp_config_end(void)
18563 {
18564 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18565 uint32_t bgp_post_config_delay =
18566 thread_is_scheduled(bm->t_rmap_update)
18567 ? thread_timer_remain_second(bm->t_rmap_update)
18568 : BGP_POST_CONFIG_DELAY_SECONDS;
18569
18570 /* If BGP config processing thread isn't running, then
18571 * we can return and rely it's properly handled.
18572 */
18573 if (!bgp_config_inprocess())
18574 return;
18575
18576 THREAD_OFF(t_bgp_cfg);
18577
18578 /* Start a new timer to make sure we don't send EoR
18579 * before route-maps are processed.
18580 */
18581 thread_add_timer(bm->master, bgp_config_finish, NULL,
18582 bgp_post_config_delay, &t_bgp_cfg);
18583 }
18584
18585 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18586 {
18587 int write = 0;
18588 struct interface *ifp;
18589 struct bgp_interface *iifp;
18590
18591 FOR_ALL_INTERFACES (vrf, ifp) {
18592 iifp = ifp->info;
18593 if (!iifp)
18594 continue;
18595
18596 if_vty_config_start(vty, ifp);
18597
18598 if (CHECK_FLAG(iifp->flags,
18599 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18600 vty_out(vty, " mpls bgp forwarding\n");
18601 write++;
18602 }
18603
18604 if_vty_config_end(vty);
18605 }
18606
18607 return write;
18608 }
18609
18610 /* Configuration write function for bgpd. */
18611 static int config_write_interface(struct vty *vty)
18612 {
18613 int write = 0;
18614 struct vrf *vrf = NULL;
18615
18616 /* Display all VRF aware OSPF interface configuration */
18617 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18618 write += config_write_interface_one(vty, vrf);
18619 }
18620
18621 return write;
18622 }
18623
18624 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18625 "[no$no] mpls bgp forwarding",
18626 NO_STR MPLS_STR BGP_STR
18627 "Enable MPLS forwarding for eBGP directly connected peers\n")
18628 {
18629 bool check;
18630 struct bgp_interface *iifp;
18631
18632 VTY_DECLVAR_CONTEXT(interface, ifp);
18633 iifp = ifp->info;
18634 if (!iifp) {
18635 vty_out(vty, "Interface %s not available\n", ifp->name);
18636 return CMD_WARNING_CONFIG_FAILED;
18637 }
18638 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18639 if (check != !no) {
18640 if (no)
18641 UNSET_FLAG(iifp->flags,
18642 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18643 else
18644 SET_FLAG(iifp->flags,
18645 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18646 /* trigger a nht update on eBGP sessions */
18647 if (if_is_operative(ifp))
18648 bgp_nht_ifp_up(ifp);
18649 }
18650 return CMD_SUCCESS;
18651 }
18652
18653 DEFPY (bgp_inq_limit,
18654 bgp_inq_limit_cmd,
18655 "bgp input-queue-limit (1-4294967295)$limit",
18656 BGP_STR
18657 "Set the BGP Input Queue limit for all peers when message parsing\n"
18658 "Input-Queue limit\n")
18659 {
18660 bm->inq_limit = limit;
18661
18662 return CMD_SUCCESS;
18663 }
18664
18665 DEFPY (no_bgp_inq_limit,
18666 no_bgp_inq_limit_cmd,
18667 "no bgp input-queue-limit [(1-4294967295)$limit]",
18668 NO_STR
18669 BGP_STR
18670 "Set the BGP Input Queue limit for all peers when message parsing\n"
18671 "Input-Queue limit\n")
18672 {
18673 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18674
18675 return CMD_SUCCESS;
18676 }
18677
18678 DEFPY (bgp_outq_limit,
18679 bgp_outq_limit_cmd,
18680 "bgp output-queue-limit (1-4294967295)$limit",
18681 BGP_STR
18682 "Set the BGP Output Queue limit for all peers when message parsing\n"
18683 "Output-Queue limit\n")
18684 {
18685 bm->outq_limit = limit;
18686
18687 return CMD_SUCCESS;
18688 }
18689
18690 DEFPY (no_bgp_outq_limit,
18691 no_bgp_outq_limit_cmd,
18692 "no bgp output-queue-limit [(1-4294967295)$limit]",
18693 NO_STR
18694 BGP_STR
18695 "Set the BGP Output Queue limit for all peers when message parsing\n"
18696 "Output-Queue limit\n")
18697 {
18698 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
18699
18700 return CMD_SUCCESS;
18701 }
18702
18703
18704 /* Initialization of BGP interface. */
18705 static void bgp_vty_if_init(void)
18706 {
18707 /* Install interface node. */
18708 if_cmd_init(config_write_interface);
18709
18710 /* "mpls bgp forwarding" commands. */
18711 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18712 }
18713
18714 void bgp_vty_init(void)
18715 {
18716 cmd_variable_handler_register(bgp_var_neighbor);
18717 cmd_variable_handler_register(bgp_var_peergroup);
18718
18719 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18720
18721 /* Install bgp top node. */
18722 install_node(&bgp_node);
18723 install_node(&bgp_ipv4_unicast_node);
18724 install_node(&bgp_ipv4_multicast_node);
18725 install_node(&bgp_ipv4_labeled_unicast_node);
18726 install_node(&bgp_ipv6_unicast_node);
18727 install_node(&bgp_ipv6_multicast_node);
18728 install_node(&bgp_ipv6_labeled_unicast_node);
18729 install_node(&bgp_vpnv4_node);
18730 install_node(&bgp_vpnv6_node);
18731 install_node(&bgp_evpn_node);
18732 install_node(&bgp_evpn_vni_node);
18733 install_node(&bgp_flowspecv4_node);
18734 install_node(&bgp_flowspecv6_node);
18735 install_node(&bgp_srv6_node);
18736
18737 /* Install default VTY commands to new nodes. */
18738 install_default(BGP_NODE);
18739 install_default(BGP_IPV4_NODE);
18740 install_default(BGP_IPV4M_NODE);
18741 install_default(BGP_IPV4L_NODE);
18742 install_default(BGP_IPV6_NODE);
18743 install_default(BGP_IPV6M_NODE);
18744 install_default(BGP_IPV6L_NODE);
18745 install_default(BGP_VPNV4_NODE);
18746 install_default(BGP_VPNV6_NODE);
18747 install_default(BGP_FLOWSPECV4_NODE);
18748 install_default(BGP_FLOWSPECV6_NODE);
18749 install_default(BGP_EVPN_NODE);
18750 install_default(BGP_EVPN_VNI_NODE);
18751 install_default(BGP_SRV6_NODE);
18752
18753 /* "global bgp inq-limit command */
18754 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18755 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18756 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18757 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
18758
18759 /* "bgp local-mac" hidden commands. */
18760 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18761 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18762
18763 /* "bgp suppress-fib-pending" global */
18764 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18765
18766 /* bgp route-map delay-timer commands. */
18767 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18768 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18769
18770 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18771
18772 /* bgp fast-convergence command */
18773 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18774 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18775
18776 /* global bgp update-delay command */
18777 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18778 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18779
18780 /* global bgp graceful-shutdown command */
18781 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18782 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18783
18784 /* Dummy commands (Currently not supported) */
18785 install_element(BGP_NODE, &no_synchronization_cmd);
18786 install_element(BGP_NODE, &no_auto_summary_cmd);
18787
18788 /* "router bgp" commands. */
18789 install_element(CONFIG_NODE, &router_bgp_cmd);
18790
18791 /* "no router bgp" commands. */
18792 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18793
18794 /* "bgp session-dscp command */
18795 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18796 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18797
18798 /* "bgp router-id" commands. */
18799 install_element(BGP_NODE, &bgp_router_id_cmd);
18800 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18801
18802 /* "bgp suppress-fib-pending" command */
18803 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18804
18805 /* "bgp cluster-id" commands. */
18806 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18807 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18808
18809 /* "bgp no-rib" commands. */
18810 install_element(CONFIG_NODE, &bgp_norib_cmd);
18811 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18812
18813 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18814
18815 /* "bgp confederation" commands. */
18816 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18817 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18818
18819 /* "bgp confederation peers" commands. */
18820 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18821 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18822
18823 /* bgp max-med command */
18824 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18825 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18826 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18827 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18828 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18829
18830 /* "neighbor role" commands. */
18831 install_element(BGP_NODE, &neighbor_role_cmd);
18832 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18833 install_element(BGP_NODE, &no_neighbor_role_cmd);
18834
18835 /* "neighbor aigp" commands. */
18836 install_element(BGP_NODE, &neighbor_aigp_cmd);
18837
18838 /* "neighbor graceful-shutdown" command */
18839 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18840
18841 /* bgp disable-ebgp-connected-nh-check */
18842 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18843 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18844
18845 /* bgp update-delay command */
18846 install_element(BGP_NODE, &bgp_update_delay_cmd);
18847 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18848
18849 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18850 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18851
18852 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18853 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18854
18855 /* "maximum-paths" commands. */
18856 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18857 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18858 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18859 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18860 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18861 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18862 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18863 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18864 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18865 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18866 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18867 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18868 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18869 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18870 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18871
18872 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18873 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18874 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18875 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18876 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18877 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18878 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18879 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18880 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18881 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18882
18883 /* "timers bgp" commands. */
18884 install_element(BGP_NODE, &bgp_timers_cmd);
18885 install_element(BGP_NODE, &no_bgp_timers_cmd);
18886
18887 /* "minimum-holdtime" commands. */
18888 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18889 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18890
18891 /* route-map delay-timer commands - per instance for backwards compat.
18892 */
18893 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18894 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18895
18896 /* "bgp client-to-client reflection" commands */
18897 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18898 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18899
18900 /* "bgp always-compare-med" commands */
18901 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18902 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18903
18904 /* bgp ebgp-requires-policy */
18905 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18906 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18907
18908 /* bgp suppress-duplicates */
18909 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18910 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18911
18912 /* bgp reject-as-sets */
18913 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18914 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18915
18916 /* "bgp deterministic-med" commands */
18917 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18918 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18919
18920 /* "bgp graceful-restart" command */
18921 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18922 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18923
18924 /* "bgp graceful-restart-disable" command */
18925 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18926 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18927
18928 /* "neighbor a:b:c:d graceful-restart" command */
18929 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18930 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18931
18932 /* "neighbor a:b:c:d graceful-restart-disable" command */
18933 install_element(BGP_NODE,
18934 &bgp_neighbor_graceful_restart_disable_set_cmd);
18935 install_element(BGP_NODE,
18936 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18937
18938 /* "neighbor a:b:c:d graceful-restart-helper" command */
18939 install_element(BGP_NODE,
18940 &bgp_neighbor_graceful_restart_helper_set_cmd);
18941 install_element(BGP_NODE,
18942 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18943
18944 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18945 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18946 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18947 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18948 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18949 install_element(BGP_NODE,
18950 &no_bgp_graceful_restart_select_defer_time_cmd);
18951 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18952 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18953 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18954
18955 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18956 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18957 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18958 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18959
18960 /* "bgp graceful-shutdown" commands */
18961 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18962 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18963
18964 /* "bgp hard-administrative-reset" commands */
18965 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18966
18967 /* "bgp long-lived-graceful-restart" commands */
18968 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18969 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18970
18971 /* "bgp fast-external-failover" commands */
18972 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18973 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18974
18975 /* "bgp bestpath aigp" commands */
18976 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
18977
18978 /* "bgp bestpath compare-routerid" commands */
18979 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18980 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18981
18982 /* "bgp bestpath as-path ignore" commands */
18983 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18984 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18985
18986 /* "bgp bestpath as-path confed" commands */
18987 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18988 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18989
18990 /* "bgp bestpath as-path multipath-relax" commands */
18991 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18992 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18993
18994 /* "bgp bestpath peer-type multipath-relax" commands */
18995 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18996 install_element(BGP_NODE,
18997 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18998
18999 /* "bgp log-neighbor-changes" commands */
19000 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19001 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19002
19003 /* "bgp bestpath med" commands */
19004 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19005 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19006
19007 /* "bgp bestpath bandwidth" commands */
19008 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
19009 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
19010
19011 /* "no bgp default <afi>-<safi>" commands. */
19012 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
19013
19014 /* "bgp network import-check" commands. */
19015 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19016 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19017 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19018
19019 /* "bgp default local-preference" commands. */
19020 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19021 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19022
19023 /* bgp default show-hostname */
19024 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19025 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19026
19027 /* bgp default show-nexthop-hostname */
19028 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19029 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19030
19031 /* "bgp default subgroup-pkt-queue-max" commands. */
19032 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19033 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19034
19035 /* bgp ibgp-allow-policy-mods command */
19036 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19037 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19038
19039 /* "bgp listen limit" commands. */
19040 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19041 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19042
19043 /* "bgp listen range" commands. */
19044 install_element(BGP_NODE, &bgp_listen_range_cmd);
19045 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19046
19047 /* "bgp default shutdown" command */
19048 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
19049
19050 /* "bgp shutdown" commands */
19051 install_element(BGP_NODE, &bgp_shutdown_cmd);
19052 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
19053 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
19054 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
19055
19056 /* "neighbor remote-as" commands. */
19057 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19058 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19059 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19060 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19061 install_element(BGP_NODE,
19062 &neighbor_interface_v6only_config_remote_as_cmd);
19063 install_element(BGP_NODE, &no_neighbor_cmd);
19064 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19065
19066 /* "neighbor peer-group" commands. */
19067 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19068 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19069 install_element(BGP_NODE,
19070 &no_neighbor_interface_peer_group_remote_as_cmd);
19071
19072 /* "neighbor local-as" commands. */
19073 install_element(BGP_NODE, &neighbor_local_as_cmd);
19074 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19075 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19076 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19077
19078 /* "neighbor solo" commands. */
19079 install_element(BGP_NODE, &neighbor_solo_cmd);
19080 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19081
19082 /* "neighbor password" commands. */
19083 install_element(BGP_NODE, &neighbor_password_cmd);
19084 install_element(BGP_NODE, &no_neighbor_password_cmd);
19085
19086 /* "neighbor activate" commands. */
19087 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19088 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19089 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19090 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19091 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19092 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19093 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19094 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19095 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
19096 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19097 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
19098 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19099
19100 /* "no neighbor activate" commands. */
19101 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19102 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19103 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19104 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19105 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19106 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19107 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19108 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19109 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
19110 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19111 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
19112 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19113
19114 /* "neighbor peer-group" set commands. */
19115 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19116 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19117 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19118 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19119 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19120 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19121 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19122 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19123 install_element(BGP_FLOWSPECV4_NODE,
19124 &neighbor_set_peer_group_hidden_cmd);
19125 install_element(BGP_FLOWSPECV6_NODE,
19126 &neighbor_set_peer_group_hidden_cmd);
19127
19128 /* "no neighbor peer-group unset" commands. */
19129 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19130 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19131 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19132 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19133 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19134 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19135 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19136 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19137 install_element(BGP_FLOWSPECV4_NODE,
19138 &no_neighbor_set_peer_group_hidden_cmd);
19139 install_element(BGP_FLOWSPECV6_NODE,
19140 &no_neighbor_set_peer_group_hidden_cmd);
19141
19142 /* "neighbor softreconfiguration inbound" commands.*/
19143 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19144 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19145 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19146 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19147 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19148 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19149 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19150 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19151 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19152 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19153 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19154 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19155 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19156 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19157 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19158 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19159 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19160 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19161 install_element(BGP_FLOWSPECV4_NODE,
19162 &neighbor_soft_reconfiguration_cmd);
19163 install_element(BGP_FLOWSPECV4_NODE,
19164 &no_neighbor_soft_reconfiguration_cmd);
19165 install_element(BGP_FLOWSPECV6_NODE,
19166 &neighbor_soft_reconfiguration_cmd);
19167 install_element(BGP_FLOWSPECV6_NODE,
19168 &no_neighbor_soft_reconfiguration_cmd);
19169 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19170 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19171
19172 /* "neighbor attribute-unchanged" commands. */
19173 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19174 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19175 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19176 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19177 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19178 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19179 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19180 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19181 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19182 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19183 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19184 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19185 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19186 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19187 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19188 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19189 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19190 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19191
19192 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19193 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19194
19195 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19196 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19197 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19198 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19199
19200 /* "nexthop-local unchanged" commands */
19201 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19202 install_element(BGP_IPV6_NODE,
19203 &no_neighbor_nexthop_local_unchanged_cmd);
19204
19205 /* "neighbor next-hop-self" commands. */
19206 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19207 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19208 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19209 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19210 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19211 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19212 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19213 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19214 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19215 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19216 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19217 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19218 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19219 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19220 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19221 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19222 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19223 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19224 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19225 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19226
19227 /* "neighbor next-hop-self force" commands. */
19228 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19229 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19230 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19231 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19232 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19233 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19234 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19235 install_element(BGP_IPV4_NODE,
19236 &no_neighbor_nexthop_self_all_hidden_cmd);
19237 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19238 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19239 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19240 install_element(BGP_IPV4M_NODE,
19241 &no_neighbor_nexthop_self_all_hidden_cmd);
19242 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19243 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19244 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19245 install_element(BGP_IPV4L_NODE,
19246 &no_neighbor_nexthop_self_all_hidden_cmd);
19247 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19248 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19249 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19250 install_element(BGP_IPV6_NODE,
19251 &no_neighbor_nexthop_self_all_hidden_cmd);
19252 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19253 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19254 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19255 install_element(BGP_IPV6M_NODE,
19256 &no_neighbor_nexthop_self_all_hidden_cmd);
19257 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19258 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19259 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19260 install_element(BGP_IPV6L_NODE,
19261 &no_neighbor_nexthop_self_all_hidden_cmd);
19262 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19263 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19264 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19265 install_element(BGP_VPNV4_NODE,
19266 &no_neighbor_nexthop_self_all_hidden_cmd);
19267 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19268 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19269 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19270 install_element(BGP_VPNV6_NODE,
19271 &no_neighbor_nexthop_self_all_hidden_cmd);
19272 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19273 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19274
19275 /* "neighbor as-override" commands. */
19276 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19277 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19278 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19279 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19280 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19281 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19282 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19283 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19284 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19285 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19286 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19287 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19288 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19289 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19290 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19291 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19292 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19293 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19294
19295 /* "neighbor remove-private-AS" commands. */
19296 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19297 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19298 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19299 install_element(BGP_NODE,
19300 &no_neighbor_remove_private_as_all_hidden_cmd);
19301 install_element(BGP_NODE,
19302 &neighbor_remove_private_as_replace_as_hidden_cmd);
19303 install_element(BGP_NODE,
19304 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19305 install_element(BGP_NODE,
19306 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19307 install_element(
19308 BGP_NODE,
19309 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19310 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19311 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19312 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19313 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19314 install_element(BGP_IPV4_NODE,
19315 &neighbor_remove_private_as_replace_as_cmd);
19316 install_element(BGP_IPV4_NODE,
19317 &no_neighbor_remove_private_as_replace_as_cmd);
19318 install_element(BGP_IPV4_NODE,
19319 &neighbor_remove_private_as_all_replace_as_cmd);
19320 install_element(BGP_IPV4_NODE,
19321 &no_neighbor_remove_private_as_all_replace_as_cmd);
19322 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19323 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19324 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19325 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19326 install_element(BGP_IPV4M_NODE,
19327 &neighbor_remove_private_as_replace_as_cmd);
19328 install_element(BGP_IPV4M_NODE,
19329 &no_neighbor_remove_private_as_replace_as_cmd);
19330 install_element(BGP_IPV4M_NODE,
19331 &neighbor_remove_private_as_all_replace_as_cmd);
19332 install_element(BGP_IPV4M_NODE,
19333 &no_neighbor_remove_private_as_all_replace_as_cmd);
19334 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19335 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19336 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19337 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19338 install_element(BGP_IPV4L_NODE,
19339 &neighbor_remove_private_as_replace_as_cmd);
19340 install_element(BGP_IPV4L_NODE,
19341 &no_neighbor_remove_private_as_replace_as_cmd);
19342 install_element(BGP_IPV4L_NODE,
19343 &neighbor_remove_private_as_all_replace_as_cmd);
19344 install_element(BGP_IPV4L_NODE,
19345 &no_neighbor_remove_private_as_all_replace_as_cmd);
19346 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19347 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19348 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19349 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19350 install_element(BGP_IPV6_NODE,
19351 &neighbor_remove_private_as_replace_as_cmd);
19352 install_element(BGP_IPV6_NODE,
19353 &no_neighbor_remove_private_as_replace_as_cmd);
19354 install_element(BGP_IPV6_NODE,
19355 &neighbor_remove_private_as_all_replace_as_cmd);
19356 install_element(BGP_IPV6_NODE,
19357 &no_neighbor_remove_private_as_all_replace_as_cmd);
19358 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19359 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19360 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19361 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19362 install_element(BGP_IPV6M_NODE,
19363 &neighbor_remove_private_as_replace_as_cmd);
19364 install_element(BGP_IPV6M_NODE,
19365 &no_neighbor_remove_private_as_replace_as_cmd);
19366 install_element(BGP_IPV6M_NODE,
19367 &neighbor_remove_private_as_all_replace_as_cmd);
19368 install_element(BGP_IPV6M_NODE,
19369 &no_neighbor_remove_private_as_all_replace_as_cmd);
19370 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19371 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19372 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19373 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19374 install_element(BGP_IPV6L_NODE,
19375 &neighbor_remove_private_as_replace_as_cmd);
19376 install_element(BGP_IPV6L_NODE,
19377 &no_neighbor_remove_private_as_replace_as_cmd);
19378 install_element(BGP_IPV6L_NODE,
19379 &neighbor_remove_private_as_all_replace_as_cmd);
19380 install_element(BGP_IPV6L_NODE,
19381 &no_neighbor_remove_private_as_all_replace_as_cmd);
19382 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19383 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19384 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19385 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19386 install_element(BGP_VPNV4_NODE,
19387 &neighbor_remove_private_as_replace_as_cmd);
19388 install_element(BGP_VPNV4_NODE,
19389 &no_neighbor_remove_private_as_replace_as_cmd);
19390 install_element(BGP_VPNV4_NODE,
19391 &neighbor_remove_private_as_all_replace_as_cmd);
19392 install_element(BGP_VPNV4_NODE,
19393 &no_neighbor_remove_private_as_all_replace_as_cmd);
19394 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19395 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19396 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19397 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19398 install_element(BGP_VPNV6_NODE,
19399 &neighbor_remove_private_as_replace_as_cmd);
19400 install_element(BGP_VPNV6_NODE,
19401 &no_neighbor_remove_private_as_replace_as_cmd);
19402 install_element(BGP_VPNV6_NODE,
19403 &neighbor_remove_private_as_all_replace_as_cmd);
19404 install_element(BGP_VPNV6_NODE,
19405 &no_neighbor_remove_private_as_all_replace_as_cmd);
19406
19407 /* "neighbor send-community" commands.*/
19408 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19409 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19410 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19411 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19412 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19413 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19414 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19415 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19416 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19417 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19418 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19419 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19420 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19421 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19422 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19423 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19424 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19425 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19426 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19427 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19428 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19429 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19430 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19431 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19432 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19433 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19434 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19435 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19436 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19437 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19438 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19439 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19440 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19441 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19442 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19443 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19444
19445 /* "neighbor route-reflector" commands.*/
19446 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19447 install_element(BGP_NODE,
19448 &no_neighbor_route_reflector_client_hidden_cmd);
19449 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19450 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19451 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19452 install_element(BGP_IPV4M_NODE,
19453 &no_neighbor_route_reflector_client_cmd);
19454 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19455 install_element(BGP_IPV4L_NODE,
19456 &no_neighbor_route_reflector_client_cmd);
19457 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19458 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19459 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19460 install_element(BGP_IPV6M_NODE,
19461 &no_neighbor_route_reflector_client_cmd);
19462 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19463 install_element(BGP_IPV6L_NODE,
19464 &no_neighbor_route_reflector_client_cmd);
19465 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19466 install_element(BGP_VPNV4_NODE,
19467 &no_neighbor_route_reflector_client_cmd);
19468 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19469 install_element(BGP_VPNV6_NODE,
19470 &no_neighbor_route_reflector_client_cmd);
19471 install_element(BGP_FLOWSPECV4_NODE,
19472 &neighbor_route_reflector_client_cmd);
19473 install_element(BGP_FLOWSPECV4_NODE,
19474 &no_neighbor_route_reflector_client_cmd);
19475 install_element(BGP_FLOWSPECV6_NODE,
19476 &neighbor_route_reflector_client_cmd);
19477 install_element(BGP_FLOWSPECV6_NODE,
19478 &no_neighbor_route_reflector_client_cmd);
19479 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19480 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19481
19482 /* "neighbor route-server" commands.*/
19483 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19484 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19485 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19486 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19487 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19488 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19489 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19490 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19491 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19492 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19493 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19494 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19495 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19496 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19497 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19498 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19499 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19500 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19501 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19502 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19503 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19504 install_element(BGP_FLOWSPECV4_NODE,
19505 &no_neighbor_route_server_client_cmd);
19506 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19507 install_element(BGP_FLOWSPECV6_NODE,
19508 &no_neighbor_route_server_client_cmd);
19509
19510 /* "neighbor disable-addpath-rx" commands. */
19511 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19512 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19513 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19514 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19515 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19516 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19517 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19518 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19519 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19520 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19521 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19522 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19523 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19524 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19525 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19526 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19527
19528 /* "neighbor addpath-tx-all-paths" commands.*/
19529 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19530 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19531 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19532 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19533 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19534 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19535 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19536 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19537 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19538 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19539 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19540 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19541 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19542 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19543 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19544 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19545 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19546 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19547
19548 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19549 install_element(BGP_NODE,
19550 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19551 install_element(BGP_NODE,
19552 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19553 install_element(BGP_IPV4_NODE,
19554 &neighbor_addpath_tx_bestpath_per_as_cmd);
19555 install_element(BGP_IPV4_NODE,
19556 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19557 install_element(BGP_IPV4M_NODE,
19558 &neighbor_addpath_tx_bestpath_per_as_cmd);
19559 install_element(BGP_IPV4M_NODE,
19560 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19561 install_element(BGP_IPV4L_NODE,
19562 &neighbor_addpath_tx_bestpath_per_as_cmd);
19563 install_element(BGP_IPV4L_NODE,
19564 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19565 install_element(BGP_IPV6_NODE,
19566 &neighbor_addpath_tx_bestpath_per_as_cmd);
19567 install_element(BGP_IPV6_NODE,
19568 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19569 install_element(BGP_IPV6M_NODE,
19570 &neighbor_addpath_tx_bestpath_per_as_cmd);
19571 install_element(BGP_IPV6M_NODE,
19572 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19573 install_element(BGP_IPV6L_NODE,
19574 &neighbor_addpath_tx_bestpath_per_as_cmd);
19575 install_element(BGP_IPV6L_NODE,
19576 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19577 install_element(BGP_VPNV4_NODE,
19578 &neighbor_addpath_tx_bestpath_per_as_cmd);
19579 install_element(BGP_VPNV4_NODE,
19580 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19581 install_element(BGP_VPNV6_NODE,
19582 &neighbor_addpath_tx_bestpath_per_as_cmd);
19583 install_element(BGP_VPNV6_NODE,
19584 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19585
19586 /* "neighbor sender-as-path-loop-detection" commands. */
19587 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19588 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19589
19590 /* "neighbor path-attribute discard" commands. */
19591 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
19592 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
19593
19594 /* "neighbor passive" commands. */
19595 install_element(BGP_NODE, &neighbor_passive_cmd);
19596 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19597
19598
19599 /* "neighbor shutdown" commands. */
19600 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19601 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19602 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19603 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19604 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19605 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19606
19607 /* "neighbor capability extended-nexthop" commands.*/
19608 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19609 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19610
19611 /* "neighbor capability orf prefix-list" commands.*/
19612 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19613 install_element(BGP_NODE,
19614 &no_neighbor_capability_orf_prefix_hidden_cmd);
19615 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19616 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19617 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19618 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19619 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19620 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19621 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19622 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19623 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19624 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19625 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19626 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19627
19628 /* "neighbor capability dynamic" commands.*/
19629 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19630 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19631
19632 /* "neighbor dont-capability-negotiate" commands. */
19633 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19634 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19635
19636 /* "neighbor ebgp-multihop" commands. */
19637 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19638 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19639 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19640
19641 /* "neighbor disable-connected-check" commands. */
19642 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19643 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19644
19645 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19646 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19647 install_element(BGP_NODE,
19648 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19649
19650 /* "neighbor extended-optional-parameters" commands. */
19651 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19652 install_element(BGP_NODE,
19653 &no_neighbor_extended_optional_parameters_cmd);
19654
19655 /* "neighbor enforce-first-as" commands. */
19656 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19657 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19658
19659 /* "neighbor description" commands. */
19660 install_element(BGP_NODE, &neighbor_description_cmd);
19661 install_element(BGP_NODE, &no_neighbor_description_cmd);
19662 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19663
19664 /* "neighbor update-source" commands. "*/
19665 install_element(BGP_NODE, &neighbor_update_source_cmd);
19666 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19667
19668 /* "neighbor default-originate" commands. */
19669 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19670 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19671 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19672 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19673 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19674 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19675 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19676 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19677 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19678 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19679 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19680 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19681 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19682 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19683 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19684 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19685 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19686 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19687 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19688 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19689 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19690
19691 /* "neighbor port" commands. */
19692 install_element(BGP_NODE, &neighbor_port_cmd);
19693 install_element(BGP_NODE, &no_neighbor_port_cmd);
19694
19695 /* "neighbor weight" commands. */
19696 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19697 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19698
19699 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19700 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19701 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19702 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19703 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19704 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19705 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19706 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19707 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19708 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19709 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19710 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19711 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19712 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19713 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19714 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19715
19716 /* "neighbor override-capability" commands. */
19717 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19718 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19719
19720 /* "neighbor strict-capability-match" commands. */
19721 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19722 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19723
19724 /* "neighbor timers" commands. */
19725 install_element(BGP_NODE, &neighbor_timers_cmd);
19726 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19727
19728 /* "neighbor timers connect" commands. */
19729 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19730 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19731
19732 /* "neighbor timers delayopen" commands. */
19733 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19734 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19735
19736 /* "neighbor advertisement-interval" commands. */
19737 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19738 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19739
19740 /* "neighbor interface" commands. */
19741 install_element(BGP_NODE, &neighbor_interface_cmd);
19742 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19743
19744 /* "neighbor distribute" commands. */
19745 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19746 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19747 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19748 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19749 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19750 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19751 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19752 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19753 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19754 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19755 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19756 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19757 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19758 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19759 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19760 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19761 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19762 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19763
19764 /* "neighbor prefix-list" commands. */
19765 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19766 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19767 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19768 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19769 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19770 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19771 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19772 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19773 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19774 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19775 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19776 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19777 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19778 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19779 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19780 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19781 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19782 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19783 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19784 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19785 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19786 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19787
19788 /* "neighbor filter-list" commands. */
19789 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19790 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19791 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19792 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19793 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19794 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19795 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19796 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19797 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19798 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19799 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19800 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19801 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19802 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19803 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19804 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19805 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19806 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19807 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19808 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19809 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19810 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19811
19812 /* "neighbor route-map" commands. */
19813 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19814 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19815 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19816 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19817 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19818 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19819 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19820 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19821 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19822 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19823 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19824 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19825 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19826 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19827 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19828 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19829 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19830 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19831 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19832 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19833 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19834 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19835 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19836 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19837
19838 /* "neighbor unsuppress-map" commands. */
19839 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19840 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19841 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19842 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19843 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19844 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19845 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19846 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19847 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19848 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19849 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19850 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19851 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19852 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19853 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19854 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19855 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19856 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19857
19858 /* "neighbor advertise-map" commands. */
19859 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19860 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19861 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19862 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19863 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19864 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19865 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19866 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19867 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19868 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19869
19870 /* neighbor maximum-prefix-out commands. */
19871 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19872 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19873 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19874 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19875 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19876 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19877 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19878 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19879 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19880 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19881 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19882 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19883 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19884 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19885 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19886 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19887 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19888 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19889
19890 /* "neighbor maximum-prefix" commands. */
19891 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19892 install_element(BGP_NODE,
19893 &neighbor_maximum_prefix_threshold_hidden_cmd);
19894 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19895 install_element(BGP_NODE,
19896 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19897 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19898 install_element(BGP_NODE,
19899 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19900 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19901 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19902 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19903 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19904 install_element(BGP_IPV4_NODE,
19905 &neighbor_maximum_prefix_threshold_warning_cmd);
19906 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19907 install_element(BGP_IPV4_NODE,
19908 &neighbor_maximum_prefix_threshold_restart_cmd);
19909 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19910 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19911 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19912 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19913 install_element(BGP_IPV4M_NODE,
19914 &neighbor_maximum_prefix_threshold_warning_cmd);
19915 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19916 install_element(BGP_IPV4M_NODE,
19917 &neighbor_maximum_prefix_threshold_restart_cmd);
19918 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19919 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19920 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19921 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19922 install_element(BGP_IPV4L_NODE,
19923 &neighbor_maximum_prefix_threshold_warning_cmd);
19924 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19925 install_element(BGP_IPV4L_NODE,
19926 &neighbor_maximum_prefix_threshold_restart_cmd);
19927 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19928 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19929 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19930 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19931 install_element(BGP_IPV6_NODE,
19932 &neighbor_maximum_prefix_threshold_warning_cmd);
19933 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19934 install_element(BGP_IPV6_NODE,
19935 &neighbor_maximum_prefix_threshold_restart_cmd);
19936 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19937 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19938 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19939 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19940 install_element(BGP_IPV6M_NODE,
19941 &neighbor_maximum_prefix_threshold_warning_cmd);
19942 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19943 install_element(BGP_IPV6M_NODE,
19944 &neighbor_maximum_prefix_threshold_restart_cmd);
19945 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19946 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19947 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19948 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19949 install_element(BGP_IPV6L_NODE,
19950 &neighbor_maximum_prefix_threshold_warning_cmd);
19951 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19952 install_element(BGP_IPV6L_NODE,
19953 &neighbor_maximum_prefix_threshold_restart_cmd);
19954 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19955 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19956 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19957 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19958 install_element(BGP_VPNV4_NODE,
19959 &neighbor_maximum_prefix_threshold_warning_cmd);
19960 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19961 install_element(BGP_VPNV4_NODE,
19962 &neighbor_maximum_prefix_threshold_restart_cmd);
19963 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19964 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19965 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19966 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19967 install_element(BGP_VPNV6_NODE,
19968 &neighbor_maximum_prefix_threshold_warning_cmd);
19969 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19970 install_element(BGP_VPNV6_NODE,
19971 &neighbor_maximum_prefix_threshold_restart_cmd);
19972 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19973
19974 /* "neighbor allowas-in" */
19975 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19976 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19977 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19978 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19979 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19980 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19981 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19982 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19983 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19984 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19985 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19986 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19987 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19988 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19989 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19990 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19991 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19992 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19993 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19994 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19995
19996 /* neighbor accept-own */
19997 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19998 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19999
20000 /* "neighbor soo" */
20001 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20002 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20003 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20004 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20005 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20006 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20007 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20008 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20009 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20010 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20011 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20012 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20013 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20014 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20015 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20016 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20017 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20018 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20019
20020 /* address-family commands. */
20021 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20022 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
20023 #ifdef KEEP_OLD_VPN_COMMANDS
20024 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20025 install_element(BGP_NODE, &address_family_vpnv6_cmd);
20026 #endif /* KEEP_OLD_VPN_COMMANDS */
20027
20028 install_element(BGP_NODE, &address_family_evpn_cmd);
20029
20030 /* "exit-address-family" command. */
20031 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20032 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20033 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20034 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20035 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20036 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20037 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20038 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
20039 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20040 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
20041 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20042
20043 /* BGP retain all route-target */
20044 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20045 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20046
20047 /* "clear ip bgp commands" */
20048 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20049
20050 /* clear ip bgp prefix */
20051 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20052 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20053 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20054
20055 /* "show [ip] bgp summary" commands. */
20056 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
20057 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
20058 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
20059 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
20060 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20061 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
20062 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20063
20064 /* "show [ip] bgp neighbors" commands. */
20065 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20066
20067 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
20068
20069 /* "show [ip] bgp peer-group" commands. */
20070 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20071
20072 /* "show [ip] bgp paths" commands. */
20073 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20074
20075 /* "show [ip] bgp community" commands. */
20076 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20077
20078 /* "show ip bgp large-community" commands. */
20079 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20080 /* "show [ip] bgp attribute-info" commands. */
20081 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
20082 /* "show [ip] bgp route-leak" command */
20083 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
20084
20085 /* "redistribute" commands. */
20086 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20087 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20088 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20089 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20090 install_element(BGP_NODE,
20091 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20092 install_element(BGP_NODE,
20093 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20094 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20095 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20096 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20097 install_element(BGP_NODE,
20098 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20099 install_element(BGP_NODE,
20100 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20101 install_element(BGP_NODE,
20102 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20103 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20104 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20105 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20106 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20107 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20108 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20109 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20110 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20111 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20112 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20113 install_element(BGP_IPV4_NODE,
20114 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20115 install_element(BGP_IPV4_NODE,
20116 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20117 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20118 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20119 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20120 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20121 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20122 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20123
20124 /* import|export vpn [route-map RMAP_NAME] */
20125 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20126 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20127
20128 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20129 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20130
20131 /* ttl_security commands */
20132 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20133 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20134
20135 /* "bgp tcp-keepalive" commands */
20136 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20137 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20138
20139 /* "show [ip] bgp memory" commands. */
20140 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20141
20142 /* "show bgp martian next-hop" */
20143 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20144
20145 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20146
20147 /* "show [ip] bgp views" commands. */
20148 install_element(VIEW_NODE, &show_bgp_views_cmd);
20149
20150 /* "show [ip] bgp vrfs" commands. */
20151 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20152
20153 /* Community-list. */
20154 community_list_vty();
20155
20156 community_alias_vty();
20157
20158 /* vpn-policy commands */
20159 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20160 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20161 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20162 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20163 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20164 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20165 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20166 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20167 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20168 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20169 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20170 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20171
20172 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20173 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20174
20175 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20176 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20177 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20178 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20179 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20180 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20181 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20182 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20183 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20184 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20185
20186 /* tcp-mss command */
20187 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20188 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20189
20190 /* srv6 commands */
20191 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20192 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20193 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20194 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20195 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20196 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20197 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20198 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20199 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20200
20201 bgp_vty_if_init();
20202 }
20203
20204 #include "memory.h"
20205 #include "bgp_regex.h"
20206 #include "bgp_clist.h"
20207 #include "bgp_ecommunity.h"
20208
20209 /* VTY functions. */
20210
20211 /* Direction value to string conversion. */
20212 static const char *community_direct_str(int direct)
20213 {
20214 switch (direct) {
20215 case COMMUNITY_DENY:
20216 return "deny";
20217 case COMMUNITY_PERMIT:
20218 return "permit";
20219 default:
20220 return "unknown";
20221 }
20222 }
20223
20224 /* Display error string. */
20225 static void community_list_perror(struct vty *vty, int ret)
20226 {
20227 switch (ret) {
20228 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20229 vty_out(vty, "%% Can't find community-list\n");
20230 break;
20231 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20232 vty_out(vty, "%% Malformed community-list value\n");
20233 break;
20234 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20235 vty_out(vty,
20236 "%% Community name conflict, previously defined as standard community\n");
20237 break;
20238 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20239 vty_out(vty,
20240 "%% Community name conflict, previously defined as expanded community\n");
20241 break;
20242 }
20243 }
20244
20245 /* "community-list" keyword help string. */
20246 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20247
20248 /*community-list standard */
20249 DEFUN (community_list_standard,
20250 bgp_community_list_standard_cmd,
20251 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20252 BGP_STR
20253 COMMUNITY_LIST_STR
20254 "Community list number (standard)\n"
20255 "Add an standard community-list entry\n"
20256 "Community list name\n"
20257 "Sequence number of an entry\n"
20258 "Sequence number\n"
20259 "Specify community to reject\n"
20260 "Specify community to accept\n"
20261 COMMUNITY_VAL_STR)
20262 {
20263 char *cl_name_or_number = NULL;
20264 char *seq = NULL;
20265 int direct = 0;
20266 int style = COMMUNITY_LIST_STANDARD;
20267 int idx = 0;
20268
20269 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20270 seq = argv[idx]->arg;
20271
20272 idx = 0;
20273 argv_find(argv, argc, "(1-99)", &idx);
20274 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20275 cl_name_or_number = argv[idx]->arg;
20276 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20277 : COMMUNITY_DENY;
20278 argv_find(argv, argc, "AA:NN", &idx);
20279 char *str = argv_concat(argv, argc, idx);
20280
20281 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20282 direct, style);
20283
20284 XFREE(MTYPE_TMP, str);
20285
20286 if (ret < 0) {
20287 /* Display error string. */
20288 community_list_perror(vty, ret);
20289 return CMD_WARNING_CONFIG_FAILED;
20290 }
20291
20292 return CMD_SUCCESS;
20293 }
20294
20295 DEFUN (no_community_list_standard_all,
20296 no_bgp_community_list_standard_all_cmd,
20297 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20298 NO_STR
20299 BGP_STR
20300 COMMUNITY_LIST_STR
20301 "Community list number (standard)\n"
20302 "Add an standard community-list entry\n"
20303 "Community list name\n"
20304 "Sequence number of an entry\n"
20305 "Sequence number\n"
20306 "Specify community to reject\n"
20307 "Specify community to accept\n"
20308 COMMUNITY_VAL_STR)
20309 {
20310 char *cl_name_or_number = NULL;
20311 char *str = NULL;
20312 int direct = 0;
20313 int style = COMMUNITY_LIST_STANDARD;
20314 char *seq = NULL;
20315 int idx = 0;
20316
20317 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20318 seq = argv[idx]->arg;
20319
20320 idx = 0;
20321 argv_find(argv, argc, "permit", &idx);
20322 argv_find(argv, argc, "deny", &idx);
20323
20324 if (idx) {
20325 direct = argv_find(argv, argc, "permit", &idx)
20326 ? COMMUNITY_PERMIT
20327 : COMMUNITY_DENY;
20328
20329 idx = 0;
20330 argv_find(argv, argc, "AA:NN", &idx);
20331 str = argv_concat(argv, argc, idx);
20332 }
20333
20334 idx = 0;
20335 argv_find(argv, argc, "(1-99)", &idx);
20336 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20337 cl_name_or_number = argv[idx]->arg;
20338
20339 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20340 direct, style);
20341
20342 XFREE(MTYPE_TMP, str);
20343
20344 if (ret < 0) {
20345 community_list_perror(vty, ret);
20346 return CMD_WARNING_CONFIG_FAILED;
20347 }
20348
20349 return CMD_SUCCESS;
20350 }
20351
20352 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20353 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20354 NO_STR BGP_STR COMMUNITY_LIST_STR
20355 "Community list number (standard)\n"
20356 "Add an standard community-list entry\n"
20357 "Community list name\n")
20358
20359 /*community-list expanded */
20360 DEFUN (community_list_expanded_all,
20361 bgp_community_list_expanded_all_cmd,
20362 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20363 BGP_STR
20364 COMMUNITY_LIST_STR
20365 "Community list number (expanded)\n"
20366 "Add an expanded community-list entry\n"
20367 "Community list name\n"
20368 "Sequence number of an entry\n"
20369 "Sequence number\n"
20370 "Specify community to reject\n"
20371 "Specify community to accept\n"
20372 COMMUNITY_VAL_STR)
20373 {
20374 char *cl_name_or_number = NULL;
20375 char *seq = NULL;
20376 int direct = 0;
20377 int style = COMMUNITY_LIST_EXPANDED;
20378 int idx = 0;
20379
20380 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20381 seq = argv[idx]->arg;
20382
20383 idx = 0;
20384
20385 argv_find(argv, argc, "(100-500)", &idx);
20386 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20387 cl_name_or_number = argv[idx]->arg;
20388 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20389 : COMMUNITY_DENY;
20390 argv_find(argv, argc, "AA:NN", &idx);
20391 char *str = argv_concat(argv, argc, idx);
20392
20393 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20394 direct, style);
20395
20396 XFREE(MTYPE_TMP, str);
20397
20398 if (ret < 0) {
20399 /* Display error string. */
20400 community_list_perror(vty, ret);
20401 return CMD_WARNING_CONFIG_FAILED;
20402 }
20403
20404 return CMD_SUCCESS;
20405 }
20406
20407 DEFUN (no_community_list_expanded_all,
20408 no_bgp_community_list_expanded_all_cmd,
20409 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20410 NO_STR
20411 BGP_STR
20412 COMMUNITY_LIST_STR
20413 "Community list number (expanded)\n"
20414 "Add an expanded community-list entry\n"
20415 "Community list name\n"
20416 "Sequence number of an entry\n"
20417 "Sequence number\n"
20418 "Specify community to reject\n"
20419 "Specify community to accept\n"
20420 COMMUNITY_VAL_STR)
20421 {
20422 char *cl_name_or_number = NULL;
20423 char *seq = NULL;
20424 char *str = NULL;
20425 int direct = 0;
20426 int style = COMMUNITY_LIST_EXPANDED;
20427 int idx = 0;
20428
20429 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20430 seq = argv[idx]->arg;
20431
20432 idx = 0;
20433 argv_find(argv, argc, "permit", &idx);
20434 argv_find(argv, argc, "deny", &idx);
20435
20436 if (idx) {
20437 direct = argv_find(argv, argc, "permit", &idx)
20438 ? COMMUNITY_PERMIT
20439 : COMMUNITY_DENY;
20440
20441 idx = 0;
20442 argv_find(argv, argc, "AA:NN", &idx);
20443 str = argv_concat(argv, argc, idx);
20444 }
20445
20446 idx = 0;
20447 argv_find(argv, argc, "(100-500)", &idx);
20448 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20449 cl_name_or_number = argv[idx]->arg;
20450
20451 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20452 direct, style);
20453
20454 XFREE(MTYPE_TMP, str);
20455
20456 if (ret < 0) {
20457 community_list_perror(vty, ret);
20458 return CMD_WARNING_CONFIG_FAILED;
20459 }
20460
20461 return CMD_SUCCESS;
20462 }
20463
20464 ALIAS(no_community_list_expanded_all,
20465 no_bgp_community_list_expanded_all_list_cmd,
20466 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20467 NO_STR BGP_STR COMMUNITY_LIST_STR
20468 "Community list number (expanded)\n"
20469 "Add an expanded community-list entry\n"
20470 "Community list name\n")
20471
20472 /* Return configuration string of community-list entry. */
20473 static const char *community_list_config_str(struct community_entry *entry)
20474 {
20475 const char *str;
20476
20477 if (entry->any)
20478 str = "";
20479 else {
20480 if (entry->style == COMMUNITY_LIST_STANDARD)
20481 str = community_str(entry->u.com, false, false);
20482 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20483 str = lcommunity_str(entry->u.lcom, false, false);
20484 else
20485 str = entry->config;
20486 }
20487 return str;
20488 }
20489
20490 static void community_list_show(struct vty *vty, struct community_list *list)
20491 {
20492 struct community_entry *entry;
20493
20494 for (entry = list->head; entry; entry = entry->next) {
20495 if (entry == list->head) {
20496 if (all_digit(list->name))
20497 vty_out(vty, "Community %s list %s\n",
20498 entry->style == COMMUNITY_LIST_STANDARD
20499 ? "standard"
20500 : "(expanded) access",
20501 list->name);
20502 else
20503 vty_out(vty, "Named Community %s list %s\n",
20504 entry->style == COMMUNITY_LIST_STANDARD
20505 ? "standard"
20506 : "expanded",
20507 list->name);
20508 }
20509 if (entry->any)
20510 vty_out(vty, " %s\n",
20511 community_direct_str(entry->direct));
20512 else
20513 vty_out(vty, " %s %s\n",
20514 community_direct_str(entry->direct),
20515 community_list_config_str(entry));
20516 }
20517 }
20518
20519 DEFUN (show_community_list,
20520 show_bgp_community_list_cmd,
20521 "show bgp community-list",
20522 SHOW_STR
20523 BGP_STR
20524 "List community-list\n")
20525 {
20526 struct community_list *list;
20527 struct community_list_master *cm;
20528
20529 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20530 if (!cm)
20531 return CMD_SUCCESS;
20532
20533 for (list = cm->num.head; list; list = list->next)
20534 community_list_show(vty, list);
20535
20536 for (list = cm->str.head; list; list = list->next)
20537 community_list_show(vty, list);
20538
20539 return CMD_SUCCESS;
20540 }
20541
20542 DEFUN (show_community_list_arg,
20543 show_bgp_community_list_arg_cmd,
20544 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20545 SHOW_STR
20546 BGP_STR
20547 "List community-list\n"
20548 "Community-list number\n"
20549 "Community-list name\n"
20550 "Detailed information on community-list\n")
20551 {
20552 int idx_comm_list = 3;
20553 struct community_list *list;
20554
20555 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20556 COMMUNITY_LIST_MASTER);
20557 if (!list) {
20558 vty_out(vty, "%% Can't find community-list\n");
20559 return CMD_WARNING;
20560 }
20561
20562 community_list_show(vty, list);
20563
20564 return CMD_SUCCESS;
20565 }
20566
20567 /*
20568 * Large Community code.
20569 */
20570 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20571 struct cmd_token **argv, int style,
20572 int reject_all_digit_name)
20573 {
20574 int ret;
20575 int direct;
20576 char *str;
20577 int idx = 0;
20578 char *cl_name;
20579 char *seq = NULL;
20580
20581 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20582 seq = argv[idx]->arg;
20583
20584 idx = 0;
20585 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20586 : COMMUNITY_DENY;
20587
20588 /* All digit name check. */
20589 idx = 0;
20590 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20591 argv_find(argv, argc, "(1-99)", &idx);
20592 argv_find(argv, argc, "(100-500)", &idx);
20593 cl_name = argv[idx]->arg;
20594 if (reject_all_digit_name && all_digit(cl_name)) {
20595 vty_out(vty, "%% Community name cannot have all digits\n");
20596 return CMD_WARNING_CONFIG_FAILED;
20597 }
20598
20599 idx = 0;
20600 argv_find(argv, argc, "AA:BB:CC", &idx);
20601 argv_find(argv, argc, "LINE", &idx);
20602 /* Concat community string argument. */
20603 if (idx)
20604 str = argv_concat(argv, argc, idx);
20605 else
20606 str = NULL;
20607
20608 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20609
20610 /* Free temporary community list string allocated by
20611 argv_concat(). */
20612 XFREE(MTYPE_TMP, str);
20613
20614 if (ret < 0) {
20615 community_list_perror(vty, ret);
20616 return CMD_WARNING_CONFIG_FAILED;
20617 }
20618 return CMD_SUCCESS;
20619 }
20620
20621 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20622 struct cmd_token **argv, int style)
20623 {
20624 int ret;
20625 int direct = 0;
20626 char *str = NULL;
20627 int idx = 0;
20628 char *seq = NULL;
20629
20630 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20631 seq = argv[idx]->arg;
20632
20633 idx = 0;
20634 argv_find(argv, argc, "permit", &idx);
20635 argv_find(argv, argc, "deny", &idx);
20636
20637 if (idx) {
20638 /* Check the list direct. */
20639 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20640 direct = COMMUNITY_PERMIT;
20641 else
20642 direct = COMMUNITY_DENY;
20643
20644 idx = 0;
20645 argv_find(argv, argc, "LINE", &idx);
20646 argv_find(argv, argc, "AA:AA:NN", &idx);
20647 /* Concat community string argument. */
20648 str = argv_concat(argv, argc, idx);
20649 }
20650
20651 idx = 0;
20652 argv_find(argv, argc, "(1-99)", &idx);
20653 argv_find(argv, argc, "(100-500)", &idx);
20654 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20655
20656 /* Unset community list. */
20657 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20658 style);
20659
20660 /* Free temporary community list string allocated by
20661 argv_concat(). */
20662 XFREE(MTYPE_TMP, str);
20663
20664 if (ret < 0) {
20665 community_list_perror(vty, ret);
20666 return CMD_WARNING_CONFIG_FAILED;
20667 }
20668
20669 return CMD_SUCCESS;
20670 }
20671
20672 /* "large-community-list" keyword help string. */
20673 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20674 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20675
20676 DEFUN (lcommunity_list_standard,
20677 bgp_lcommunity_list_standard_cmd,
20678 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20679 BGP_STR
20680 LCOMMUNITY_LIST_STR
20681 "Large Community list number (standard)\n"
20682 "Sequence number of an entry\n"
20683 "Sequence number\n"
20684 "Specify large community to reject\n"
20685 "Specify large community to accept\n"
20686 LCOMMUNITY_VAL_STR)
20687 {
20688 return lcommunity_list_set_vty(vty, argc, argv,
20689 LARGE_COMMUNITY_LIST_STANDARD, 0);
20690 }
20691
20692 DEFUN (lcommunity_list_expanded,
20693 bgp_lcommunity_list_expanded_cmd,
20694 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20695 BGP_STR
20696 LCOMMUNITY_LIST_STR
20697 "Large Community list number (expanded)\n"
20698 "Sequence number of an entry\n"
20699 "Sequence number\n"
20700 "Specify large community to reject\n"
20701 "Specify large community to accept\n"
20702 "An ordered list as a regular-expression\n")
20703 {
20704 return lcommunity_list_set_vty(vty, argc, argv,
20705 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20706 }
20707
20708 DEFUN (lcommunity_list_name_standard,
20709 bgp_lcommunity_list_name_standard_cmd,
20710 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20711 BGP_STR
20712 LCOMMUNITY_LIST_STR
20713 "Specify standard large-community-list\n"
20714 "Large Community list name\n"
20715 "Sequence number of an entry\n"
20716 "Sequence number\n"
20717 "Specify large community to reject\n"
20718 "Specify large community to accept\n"
20719 LCOMMUNITY_VAL_STR)
20720 {
20721 return lcommunity_list_set_vty(vty, argc, argv,
20722 LARGE_COMMUNITY_LIST_STANDARD, 1);
20723 }
20724
20725 DEFUN (lcommunity_list_name_expanded,
20726 bgp_lcommunity_list_name_expanded_cmd,
20727 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20728 BGP_STR
20729 LCOMMUNITY_LIST_STR
20730 "Specify expanded large-community-list\n"
20731 "Large Community list name\n"
20732 "Sequence number of an entry\n"
20733 "Sequence number\n"
20734 "Specify large community to reject\n"
20735 "Specify large community to accept\n"
20736 "An ordered list as a regular-expression\n")
20737 {
20738 return lcommunity_list_set_vty(vty, argc, argv,
20739 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20740 }
20741
20742 DEFUN (no_lcommunity_list_all,
20743 no_bgp_lcommunity_list_all_cmd,
20744 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20745 NO_STR
20746 BGP_STR
20747 LCOMMUNITY_LIST_STR
20748 "Large Community list number (standard)\n"
20749 "Large Community list number (expanded)\n"
20750 "Large Community list name\n")
20751 {
20752 return lcommunity_list_unset_vty(vty, argc, argv,
20753 LARGE_COMMUNITY_LIST_STANDARD);
20754 }
20755
20756 DEFUN (no_lcommunity_list_name_standard_all,
20757 no_bgp_lcommunity_list_name_standard_all_cmd,
20758 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20759 NO_STR
20760 BGP_STR
20761 LCOMMUNITY_LIST_STR
20762 "Specify standard large-community-list\n"
20763 "Large Community list name\n")
20764 {
20765 return lcommunity_list_unset_vty(vty, argc, argv,
20766 LARGE_COMMUNITY_LIST_STANDARD);
20767 }
20768
20769 DEFUN (no_lcommunity_list_name_expanded_all,
20770 no_bgp_lcommunity_list_name_expanded_all_cmd,
20771 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20772 NO_STR
20773 BGP_STR
20774 LCOMMUNITY_LIST_STR
20775 "Specify expanded large-community-list\n"
20776 "Large Community list name\n")
20777 {
20778 return lcommunity_list_unset_vty(vty, argc, argv,
20779 LARGE_COMMUNITY_LIST_EXPANDED);
20780 }
20781
20782 DEFUN (no_lcommunity_list_standard,
20783 no_bgp_lcommunity_list_standard_cmd,
20784 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20785 NO_STR
20786 BGP_STR
20787 LCOMMUNITY_LIST_STR
20788 "Large Community list number (standard)\n"
20789 "Sequence number of an entry\n"
20790 "Sequence number\n"
20791 "Specify large community to reject\n"
20792 "Specify large community to accept\n"
20793 LCOMMUNITY_VAL_STR)
20794 {
20795 return lcommunity_list_unset_vty(vty, argc, argv,
20796 LARGE_COMMUNITY_LIST_STANDARD);
20797 }
20798
20799 DEFUN (no_lcommunity_list_expanded,
20800 no_bgp_lcommunity_list_expanded_cmd,
20801 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20802 NO_STR
20803 BGP_STR
20804 LCOMMUNITY_LIST_STR
20805 "Large Community list number (expanded)\n"
20806 "Sequence number of an entry\n"
20807 "Sequence number\n"
20808 "Specify large community to reject\n"
20809 "Specify large community to accept\n"
20810 "An ordered list as a regular-expression\n")
20811 {
20812 return lcommunity_list_unset_vty(vty, argc, argv,
20813 LARGE_COMMUNITY_LIST_EXPANDED);
20814 }
20815
20816 DEFUN (no_lcommunity_list_name_standard,
20817 no_bgp_lcommunity_list_name_standard_cmd,
20818 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20819 NO_STR
20820 BGP_STR
20821 LCOMMUNITY_LIST_STR
20822 "Specify standard large-community-list\n"
20823 "Large Community list name\n"
20824 "Sequence number of an entry\n"
20825 "Sequence number\n"
20826 "Specify large community to reject\n"
20827 "Specify large community to accept\n"
20828 LCOMMUNITY_VAL_STR)
20829 {
20830 return lcommunity_list_unset_vty(vty, argc, argv,
20831 LARGE_COMMUNITY_LIST_STANDARD);
20832 }
20833
20834 DEFUN (no_lcommunity_list_name_expanded,
20835 no_bgp_lcommunity_list_name_expanded_cmd,
20836 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20837 NO_STR
20838 BGP_STR
20839 LCOMMUNITY_LIST_STR
20840 "Specify expanded large-community-list\n"
20841 "Large community list name\n"
20842 "Sequence number of an entry\n"
20843 "Sequence number\n"
20844 "Specify large community to reject\n"
20845 "Specify large community to accept\n"
20846 "An ordered list as a regular-expression\n")
20847 {
20848 return lcommunity_list_unset_vty(vty, argc, argv,
20849 LARGE_COMMUNITY_LIST_EXPANDED);
20850 }
20851
20852 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20853 {
20854 struct community_entry *entry;
20855
20856 for (entry = list->head; entry; entry = entry->next) {
20857 if (entry == list->head) {
20858 if (all_digit(list->name))
20859 vty_out(vty, "Large community %s list %s\n",
20860 entry->style ==
20861 LARGE_COMMUNITY_LIST_STANDARD
20862 ? "standard"
20863 : "(expanded) access",
20864 list->name);
20865 else
20866 vty_out(vty,
20867 "Named large community %s list %s\n",
20868 entry->style ==
20869 LARGE_COMMUNITY_LIST_STANDARD
20870 ? "standard"
20871 : "expanded",
20872 list->name);
20873 }
20874 if (entry->any)
20875 vty_out(vty, " %s\n",
20876 community_direct_str(entry->direct));
20877 else
20878 vty_out(vty, " %s %s\n",
20879 community_direct_str(entry->direct),
20880 community_list_config_str(entry));
20881 }
20882 }
20883
20884 DEFUN (show_lcommunity_list,
20885 show_bgp_lcommunity_list_cmd,
20886 "show bgp large-community-list",
20887 SHOW_STR
20888 BGP_STR
20889 "List large-community list\n")
20890 {
20891 struct community_list *list;
20892 struct community_list_master *cm;
20893
20894 cm = community_list_master_lookup(bgp_clist,
20895 LARGE_COMMUNITY_LIST_MASTER);
20896 if (!cm)
20897 return CMD_SUCCESS;
20898
20899 for (list = cm->num.head; list; list = list->next)
20900 lcommunity_list_show(vty, list);
20901
20902 for (list = cm->str.head; list; list = list->next)
20903 lcommunity_list_show(vty, list);
20904
20905 return CMD_SUCCESS;
20906 }
20907
20908 DEFUN (show_lcommunity_list_arg,
20909 show_bgp_lcommunity_list_arg_cmd,
20910 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20911 SHOW_STR
20912 BGP_STR
20913 "List large-community list\n"
20914 "Large-community-list number\n"
20915 "Large-community-list name\n"
20916 "Detailed information on large-community-list\n")
20917 {
20918 struct community_list *list;
20919
20920 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20921 LARGE_COMMUNITY_LIST_MASTER);
20922 if (!list) {
20923 vty_out(vty, "%% Can't find large-community-list\n");
20924 return CMD_WARNING;
20925 }
20926
20927 lcommunity_list_show(vty, list);
20928
20929 return CMD_SUCCESS;
20930 }
20931
20932 /* "extcommunity-list" keyword help string. */
20933 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20934 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20935
20936 DEFUN (extcommunity_list_standard,
20937 bgp_extcommunity_list_standard_cmd,
20938 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20939 BGP_STR
20940 EXTCOMMUNITY_LIST_STR
20941 "Extended Community list number (standard)\n"
20942 "Specify standard extcommunity-list\n"
20943 "Community list name\n"
20944 "Sequence number of an entry\n"
20945 "Sequence number\n"
20946 "Specify community to reject\n"
20947 "Specify community to accept\n"
20948 EXTCOMMUNITY_VAL_STR)
20949 {
20950 int style = EXTCOMMUNITY_LIST_STANDARD;
20951 int direct = 0;
20952 char *cl_number_or_name = NULL;
20953 char *seq = NULL;
20954
20955 int idx = 0;
20956
20957 argv_find(argv, argc, "(1-99)", &idx);
20958 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20959 cl_number_or_name = argv[idx]->arg;
20960
20961 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20962 seq = argv[idx]->arg;
20963
20964 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20965 : COMMUNITY_DENY;
20966 argv_find(argv, argc, "AA:NN", &idx);
20967 char *str = argv_concat(argv, argc, idx);
20968
20969 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20970 direct, style);
20971
20972 XFREE(MTYPE_TMP, str);
20973
20974 if (ret < 0) {
20975 community_list_perror(vty, ret);
20976 return CMD_WARNING_CONFIG_FAILED;
20977 }
20978
20979 return CMD_SUCCESS;
20980 }
20981
20982 DEFUN (extcommunity_list_name_expanded,
20983 bgp_extcommunity_list_name_expanded_cmd,
20984 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20985 BGP_STR
20986 EXTCOMMUNITY_LIST_STR
20987 "Extended Community list number (expanded)\n"
20988 "Specify expanded extcommunity-list\n"
20989 "Extended Community list name\n"
20990 "Sequence number of an entry\n"
20991 "Sequence number\n"
20992 "Specify community to reject\n"
20993 "Specify community to accept\n"
20994 "An ordered list as a regular-expression\n")
20995 {
20996 int style = EXTCOMMUNITY_LIST_EXPANDED;
20997 int direct = 0;
20998 char *cl_number_or_name = NULL;
20999 char *seq = NULL;
21000 int idx = 0;
21001
21002 argv_find(argv, argc, "(100-500)", &idx);
21003 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21004 cl_number_or_name = argv[idx]->arg;
21005
21006 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21007 seq = argv[idx]->arg;
21008
21009 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21010 : COMMUNITY_DENY;
21011 argv_find(argv, argc, "LINE", &idx);
21012 char *str = argv_concat(argv, argc, idx);
21013
21014 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21015 direct, style);
21016
21017 XFREE(MTYPE_TMP, str);
21018
21019 if (ret < 0) {
21020 community_list_perror(vty, ret);
21021 return CMD_WARNING_CONFIG_FAILED;
21022 }
21023
21024 return CMD_SUCCESS;
21025 }
21026
21027 DEFUN (no_extcommunity_list_standard_all,
21028 no_bgp_extcommunity_list_standard_all_cmd,
21029 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21030 NO_STR
21031 BGP_STR
21032 EXTCOMMUNITY_LIST_STR
21033 "Extended Community list number (standard)\n"
21034 "Specify standard extcommunity-list\n"
21035 "Community list name\n"
21036 "Sequence number of an entry\n"
21037 "Sequence number\n"
21038 "Specify community to reject\n"
21039 "Specify community to accept\n"
21040 EXTCOMMUNITY_VAL_STR)
21041 {
21042 int style = EXTCOMMUNITY_LIST_STANDARD;
21043 int direct = 0;
21044 char *cl_number_or_name = NULL;
21045 char *str = NULL;
21046 char *seq = NULL;
21047 int idx = 0;
21048
21049 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21050 seq = argv[idx]->arg;
21051
21052 idx = 0;
21053 argv_find(argv, argc, "permit", &idx);
21054 argv_find(argv, argc, "deny", &idx);
21055 if (idx) {
21056 direct = argv_find(argv, argc, "permit", &idx)
21057 ? COMMUNITY_PERMIT
21058 : COMMUNITY_DENY;
21059
21060 idx = 0;
21061 argv_find(argv, argc, "AA:NN", &idx);
21062 str = argv_concat(argv, argc, idx);
21063 }
21064
21065 idx = 0;
21066 argv_find(argv, argc, "(1-99)", &idx);
21067 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21068 cl_number_or_name = argv[idx]->arg;
21069
21070 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21071 seq, direct, style);
21072
21073 XFREE(MTYPE_TMP, str);
21074
21075 if (ret < 0) {
21076 community_list_perror(vty, ret);
21077 return CMD_WARNING_CONFIG_FAILED;
21078 }
21079
21080 return CMD_SUCCESS;
21081 }
21082
21083 ALIAS(no_extcommunity_list_standard_all,
21084 no_bgp_extcommunity_list_standard_all_list_cmd,
21085 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
21086 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21087 "Extended Community list number (standard)\n"
21088 "Specify standard extcommunity-list\n"
21089 "Community list name\n")
21090
21091 DEFUN (no_extcommunity_list_expanded_all,
21092 no_bgp_extcommunity_list_expanded_all_cmd,
21093 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21094 NO_STR
21095 BGP_STR
21096 EXTCOMMUNITY_LIST_STR
21097 "Extended Community list number (expanded)\n"
21098 "Specify expanded extcommunity-list\n"
21099 "Extended Community list name\n"
21100 "Sequence number of an entry\n"
21101 "Sequence number\n"
21102 "Specify community to reject\n"
21103 "Specify community to accept\n"
21104 "An ordered list as a regular-expression\n")
21105 {
21106 int style = EXTCOMMUNITY_LIST_EXPANDED;
21107 int direct = 0;
21108 char *cl_number_or_name = NULL;
21109 char *str = NULL;
21110 char *seq = NULL;
21111 int idx = 0;
21112
21113 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21114 seq = argv[idx]->arg;
21115
21116 idx = 0;
21117 argv_find(argv, argc, "permit", &idx);
21118 argv_find(argv, argc, "deny", &idx);
21119
21120 if (idx) {
21121 direct = argv_find(argv, argc, "permit", &idx)
21122 ? COMMUNITY_PERMIT
21123 : COMMUNITY_DENY;
21124
21125 idx = 0;
21126 argv_find(argv, argc, "LINE", &idx);
21127 str = argv_concat(argv, argc, idx);
21128 }
21129
21130 idx = 0;
21131 argv_find(argv, argc, "(100-500)", &idx);
21132 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21133 cl_number_or_name = argv[idx]->arg;
21134
21135 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21136 seq, direct, style);
21137
21138 XFREE(MTYPE_TMP, str);
21139
21140 if (ret < 0) {
21141 community_list_perror(vty, ret);
21142 return CMD_WARNING_CONFIG_FAILED;
21143 }
21144
21145 return CMD_SUCCESS;
21146 }
21147
21148 ALIAS(no_extcommunity_list_expanded_all,
21149 no_bgp_extcommunity_list_expanded_all_list_cmd,
21150 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21151 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21152 "Extended Community list number (expanded)\n"
21153 "Specify expanded extcommunity-list\n"
21154 "Extended Community list name\n")
21155
21156 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21157 {
21158 struct community_entry *entry;
21159
21160 for (entry = list->head; entry; entry = entry->next) {
21161 if (entry == list->head) {
21162 if (all_digit(list->name))
21163 vty_out(vty, "Extended community %s list %s\n",
21164 entry->style == EXTCOMMUNITY_LIST_STANDARD
21165 ? "standard"
21166 : "(expanded) access",
21167 list->name);
21168 else
21169 vty_out(vty,
21170 "Named extended community %s list %s\n",
21171 entry->style == EXTCOMMUNITY_LIST_STANDARD
21172 ? "standard"
21173 : "expanded",
21174 list->name);
21175 }
21176 if (entry->any)
21177 vty_out(vty, " %s\n",
21178 community_direct_str(entry->direct));
21179 else
21180 vty_out(vty, " %s %s\n",
21181 community_direct_str(entry->direct),
21182 community_list_config_str(entry));
21183 }
21184 }
21185
21186 DEFUN (show_extcommunity_list,
21187 show_bgp_extcommunity_list_cmd,
21188 "show bgp extcommunity-list",
21189 SHOW_STR
21190 BGP_STR
21191 "List extended-community list\n")
21192 {
21193 struct community_list *list;
21194 struct community_list_master *cm;
21195
21196 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21197 if (!cm)
21198 return CMD_SUCCESS;
21199
21200 for (list = cm->num.head; list; list = list->next)
21201 extcommunity_list_show(vty, list);
21202
21203 for (list = cm->str.head; list; list = list->next)
21204 extcommunity_list_show(vty, list);
21205
21206 return CMD_SUCCESS;
21207 }
21208
21209 DEFUN (show_extcommunity_list_arg,
21210 show_bgp_extcommunity_list_arg_cmd,
21211 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21212 SHOW_STR
21213 BGP_STR
21214 "List extended-community list\n"
21215 "Extcommunity-list number\n"
21216 "Extcommunity-list name\n"
21217 "Detailed information on extcommunity-list\n")
21218 {
21219 int idx_comm_list = 3;
21220 struct community_list *list;
21221
21222 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21223 EXTCOMMUNITY_LIST_MASTER);
21224 if (!list) {
21225 vty_out(vty, "%% Can't find extcommunity-list\n");
21226 return CMD_WARNING;
21227 }
21228
21229 extcommunity_list_show(vty, list);
21230
21231 return CMD_SUCCESS;
21232 }
21233
21234 /* Display community-list and extcommunity-list configuration. */
21235 static int community_list_config_write(struct vty *vty)
21236 {
21237 struct community_list *list;
21238 struct community_entry *entry;
21239 struct community_list_master *cm;
21240 int write = 0;
21241
21242 /* Community-list. */
21243 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21244
21245 for (list = cm->num.head; list; list = list->next)
21246 for (entry = list->head; entry; entry = entry->next) {
21247 vty_out(vty,
21248 "bgp community-list %s seq %" PRId64 " %s %s\n",
21249 list->name, entry->seq,
21250 community_direct_str(entry->direct),
21251 community_list_config_str(entry));
21252 write++;
21253 }
21254 for (list = cm->str.head; list; list = list->next)
21255 for (entry = list->head; entry; entry = entry->next) {
21256 vty_out(vty,
21257 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21258 entry->style == COMMUNITY_LIST_STANDARD
21259 ? "standard"
21260 : "expanded",
21261 list->name, entry->seq,
21262 community_direct_str(entry->direct),
21263 community_list_config_str(entry));
21264 write++;
21265 }
21266
21267 /* Extcommunity-list. */
21268 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21269
21270 for (list = cm->num.head; list; list = list->next)
21271 for (entry = list->head; entry; entry = entry->next) {
21272 vty_out(vty,
21273 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21274 list->name, entry->seq,
21275 community_direct_str(entry->direct),
21276 community_list_config_str(entry));
21277 write++;
21278 }
21279 for (list = cm->str.head; list; list = list->next)
21280 for (entry = list->head; entry; entry = entry->next) {
21281 vty_out(vty,
21282 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21283 entry->style == EXTCOMMUNITY_LIST_STANDARD
21284 ? "standard"
21285 : "expanded",
21286 list->name, entry->seq,
21287 community_direct_str(entry->direct),
21288 community_list_config_str(entry));
21289 write++;
21290 }
21291
21292
21293 /* lcommunity-list. */
21294 cm = community_list_master_lookup(bgp_clist,
21295 LARGE_COMMUNITY_LIST_MASTER);
21296
21297 for (list = cm->num.head; list; list = list->next)
21298 for (entry = list->head; entry; entry = entry->next) {
21299 vty_out(vty,
21300 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21301 list->name, entry->seq,
21302 community_direct_str(entry->direct),
21303 community_list_config_str(entry));
21304 write++;
21305 }
21306 for (list = cm->str.head; list; list = list->next)
21307 for (entry = list->head; entry; entry = entry->next) {
21308 vty_out(vty,
21309 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21310
21311 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21312 ? "standard"
21313 : "expanded",
21314 list->name, entry->seq, community_direct_str(entry->direct),
21315 community_list_config_str(entry));
21316 write++;
21317 }
21318
21319 return write;
21320 }
21321
21322 static int community_list_config_write(struct vty *vty);
21323 static struct cmd_node community_list_node = {
21324 .name = "community list",
21325 .node = COMMUNITY_LIST_NODE,
21326 .prompt = "",
21327 .config_write = community_list_config_write,
21328 };
21329
21330 static void community_list_vty(void)
21331 {
21332 install_node(&community_list_node);
21333
21334 /* Community-list. */
21335 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21336 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21337 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21338 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21339 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21340 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21341 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21342 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21343
21344 /* Extcommunity-list. */
21345 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21346 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21347 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21348 install_element(CONFIG_NODE,
21349 &no_bgp_extcommunity_list_standard_all_list_cmd);
21350 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21351 install_element(CONFIG_NODE,
21352 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21353 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21354 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21355
21356 /* Large Community List */
21357 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21358 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21359 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21360 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21361 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21362 install_element(CONFIG_NODE,
21363 &no_bgp_lcommunity_list_name_standard_all_cmd);
21364 install_element(CONFIG_NODE,
21365 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21366 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21367 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21368 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21369 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21370 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21371 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21372
21373 bgp_community_list_command_completion_setup();
21374 }
21375
21376 static struct cmd_node community_alias_node = {
21377 .name = "community alias",
21378 .node = COMMUNITY_ALIAS_NODE,
21379 .prompt = "",
21380 .config_write = bgp_community_alias_write,
21381 };
21382
21383 void community_alias_vty(void)
21384 {
21385 install_node(&community_alias_node);
21386
21387 /* Community-list. */
21388 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21389
21390 bgp_community_alias_command_completion_setup();
21391 }